SILGen: ban getSILArgumentConvention

This function will give the wrong convention in SILGen when
using -enable-sil-opaque-values. In particular, it will say
arguments are indirect when they are not.
This commit is contained in:
Kavon Farvardin
2025-11-19 14:24:49 -08:00
parent 5e9fba115a
commit 199156b307
8 changed files with 34 additions and 9 deletions

View File

@@ -31,6 +31,7 @@
#define SWIFT_SIL_FUNCTIONCONVENTIONS_H
#include "swift/AST/Types.h"
#include "swift/Basic/AccessControls.h"
#include "swift/SIL/SILArgumentConvention.h"
#include "swift/SIL/SILType.h"
#include "llvm/Support/ErrorHandling.h"
@@ -526,11 +527,9 @@ public:
- getNumIndirectSILErrorResults()];
}
/// WARNING: Do not use this from SILGen!
/// Use methods such as `isSILIndirect` or query the ParameterInfo instead.
///
/// Return the SIL argument convention of apply/entry argument at
/// the given argument index.
SWIFT_UNAVAILABLE_IN_SILGEN_MSG("Use methods such as `isSILIndirect` or query the ParameterInfo instead.")
SILArgumentConvention getSILArgumentConvention(unsigned index) const;
/// Return the SIL type of the apply/entry argument at the given index.

View File

@@ -0,0 +1,17 @@
//
// Created by Kavon Farvardin on 11/19/25.
//
#ifndef SWIFT_SILGENUTILS_H
#define SWIFT_SILGENUTILS_H
#include "swift/SIL/SILValue.h"
namespace swift {
// Unsafe access may have invalid storage (e.g. a RawPointer).
bool isPossibleUnsafeAccessInvalidStorage(SILValue access, SILFunction *F);
} // namespace swift
#endif // SWIFT_SILGENUTILS_H

View File

@@ -87,8 +87,6 @@ SILParameterInfo SILFunctionArgument::getKnownParameterInfo() const {
return getFunction()->getConventions().getParamInfoForSILArg(getIndex());
}
/// WARNING: Do not use this from SILGen!
/// Use methods such as `isSILIndirect` or query the ParameterInfo instead.
SILArgumentConvention
SILFunctionConventions::getSILArgumentConvention(unsigned index) const {
assert(index < getNumSILArguments());

View File

@@ -22,6 +22,7 @@
#include "swift/SIL/SILBridging.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILGenUtils.h"
#include "swift/SIL/SILUndef.h"
#include "swift/SIL/Test.h"
#include "llvm/Support/Debug.h"
@@ -2485,6 +2486,12 @@ void swift::checkSwitchEnumBlockArg(SILPhiArgument *arg) {
}
}
bool swift::isPossibleUnsafeAccessInvalidStorage(SILValue address,
SILFunction *F) {
auto storage = AccessStorage::compute(address);
return storage && !isPossibleFormalAccessStorage(storage, F);
}
bool swift::isPossibleFormalAccessStorage(const AccessStorage &storage,
SILFunction *F) {
switch (storage.getKind()) {

View File

@@ -17,6 +17,8 @@
#ifndef SWIFT_SILGEN_CLEANUP_H
#define SWIFT_SILGEN_CLEANUP_H
#define SWIFT_INCLUDED_IN_SILGEN_SOURCES
#include "swift/Basic/Assertions.h"
#include "swift/Basic/Debug.h"
#include "swift/Basic/DiverseStack.h"

View File

@@ -20,6 +20,8 @@
#ifndef SWIFT_LOWERING_MANAGEDVALUE_H
#define SWIFT_LOWERING_MANAGEDVALUE_H
#define SWIFT_INCLUDED_IN_SILGEN_SOURCES
#include "Cleanup.h"
#include "llvm/ADT/PointerIntPair.h"
#include "swift/Basic/Assertions.h"

View File

@@ -13,6 +13,8 @@
#ifndef SILGEN_H
#define SILGEN_H
#define SWIFT_INCLUDED_IN_SILGEN_SOURCES
#include "ASTVisitor.h"
#include "Cleanup.h"
#include "swift/AST/ASTContext.h"

View File

@@ -35,7 +35,7 @@
#include "swift/Basic/Assertions.h"
#include "swift/SIL/Consumption.h"
#include "swift/SIL/InstructionUtils.h"
#include "swift/SIL/MemAccessUtils.h"
#include "swift/SIL/SILGenUtils.h"
#include "swift/SIL/PrettyStackTrace.h"
#include "swift/SIL/SILArgument.h"
#include "swift/SIL/SILInstruction.h"
@@ -708,9 +708,7 @@ SILValue UnenforcedAccess::beginAccess(SILGenFunction &SGF, SILLocation loc,
if (!SGF.getOptions().VerifyExclusivity)
return address;
auto storage = AccessStorage::compute(address);
// Unsafe access may have invalid storage (e.g. a RawPointer).
if (storage && !isPossibleFormalAccessStorage(storage, &SGF.F))
if (isPossibleUnsafeAccessInvalidStorage(address, &SGF.F))
return address;
auto BAI =