Skip to content

Commit 199156b

Browse files
committed
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.
1 parent 5e9fba1 commit 199156b

File tree

8 files changed

+34
-9
lines changed

8 files changed

+34
-9
lines changed

include/swift/SIL/SILFunctionConventions.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define SWIFT_SIL_FUNCTIONCONVENTIONS_H
3232

3333
#include "swift/AST/Types.h"
34+
#include "swift/Basic/AccessControls.h"
3435
#include "swift/SIL/SILArgumentConvention.h"
3536
#include "swift/SIL/SILType.h"
3637
#include "llvm/Support/ErrorHandling.h"
@@ -526,11 +527,9 @@ class SILFunctionConventions {
526527
- getNumIndirectSILErrorResults()];
527528
}
528529

529-
/// WARNING: Do not use this from SILGen!
530-
/// Use methods such as `isSILIndirect` or query the ParameterInfo instead.
531-
///
532530
/// Return the SIL argument convention of apply/entry argument at
533531
/// the given argument index.
532+
SWIFT_UNAVAILABLE_IN_SILGEN_MSG("Use methods such as `isSILIndirect` or query the ParameterInfo instead.")
534533
SILArgumentConvention getSILArgumentConvention(unsigned index) const;
535534

536535
/// Return the SIL type of the apply/entry argument at the given index.

include/swift/SIL/SILGenUtils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Created by Kavon Farvardin on 11/19/25.
3+
//
4+
5+
#ifndef SWIFT_SILGENUTILS_H
6+
#define SWIFT_SILGENUTILS_H
7+
8+
#include "swift/SIL/SILValue.h"
9+
10+
namespace swift {
11+
12+
// Unsafe access may have invalid storage (e.g. a RawPointer).
13+
bool isPossibleUnsafeAccessInvalidStorage(SILValue access, SILFunction *F);
14+
15+
} // namespace swift
16+
17+
#endif // SWIFT_SILGENUTILS_H

lib/SIL/IR/SILArgument.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ SILParameterInfo SILFunctionArgument::getKnownParameterInfo() const {
8787
return getFunction()->getConventions().getParamInfoForSILArg(getIndex());
8888
}
8989

90-
/// WARNING: Do not use this from SILGen!
91-
/// Use methods such as `isSILIndirect` or query the ParameterInfo instead.
9290
SILArgumentConvention
9391
SILFunctionConventions::getSILArgumentConvention(unsigned index) const {
9492
assert(index < getNumSILArguments());

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/SIL/SILBridging.h"
2323
#include "swift/SIL/SILInstruction.h"
2424
#include "swift/SIL/SILModule.h"
25+
#include "swift/SIL/SILGenUtils.h"
2526
#include "swift/SIL/SILUndef.h"
2627
#include "swift/SIL/Test.h"
2728
#include "llvm/Support/Debug.h"
@@ -2485,6 +2486,12 @@ void swift::checkSwitchEnumBlockArg(SILPhiArgument *arg) {
24852486
}
24862487
}
24872488

2489+
bool swift::isPossibleUnsafeAccessInvalidStorage(SILValue address,
2490+
SILFunction *F) {
2491+
auto storage = AccessStorage::compute(address);
2492+
return storage && !isPossibleFormalAccessStorage(storage, F);
2493+
}
2494+
24882495
bool swift::isPossibleFormalAccessStorage(const AccessStorage &storage,
24892496
SILFunction *F) {
24902497
switch (storage.getKind()) {

lib/SILGen/Cleanup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef SWIFT_SILGEN_CLEANUP_H
1818
#define SWIFT_SILGEN_CLEANUP_H
1919

20+
#define SWIFT_INCLUDED_IN_SILGEN_SOURCES
21+
2022
#include "swift/Basic/Assertions.h"
2123
#include "swift/Basic/Debug.h"
2224
#include "swift/Basic/DiverseStack.h"

lib/SILGen/ManagedValue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#ifndef SWIFT_LOWERING_MANAGEDVALUE_H
2121
#define SWIFT_LOWERING_MANAGEDVALUE_H
2222

23+
#define SWIFT_INCLUDED_IN_SILGEN_SOURCES
24+
2325
#include "Cleanup.h"
2426
#include "llvm/ADT/PointerIntPair.h"
2527
#include "swift/Basic/Assertions.h"

lib/SILGen/SILGen.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef SILGEN_H
1414
#define SILGEN_H
1515

16+
#define SWIFT_INCLUDED_IN_SILGEN_SOURCES
17+
1618
#include "ASTVisitor.h"
1719
#include "Cleanup.h"
1820
#include "swift/AST/ASTContext.h"

lib/SILGen/SILGenLValue.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "swift/Basic/Assertions.h"
3636
#include "swift/SIL/Consumption.h"
3737
#include "swift/SIL/InstructionUtils.h"
38-
#include "swift/SIL/MemAccessUtils.h"
38+
#include "swift/SIL/SILGenUtils.h"
3939
#include "swift/SIL/PrettyStackTrace.h"
4040
#include "swift/SIL/SILArgument.h"
4141
#include "swift/SIL/SILInstruction.h"
@@ -708,9 +708,7 @@ SILValue UnenforcedAccess::beginAccess(SILGenFunction &SGF, SILLocation loc,
708708
if (!SGF.getOptions().VerifyExclusivity)
709709
return address;
710710

711-
auto storage = AccessStorage::compute(address);
712-
// Unsafe access may have invalid storage (e.g. a RawPointer).
713-
if (storage && !isPossibleFormalAccessStorage(storage, &SGF.F))
711+
if (isPossibleUnsafeAccessInvalidStorage(address, &SGF.F))
714712
return address;
715713

716714
auto BAI =

0 commit comments

Comments
 (0)