Skip to content

Commit 4e919fb

Browse files
committed
Allow function conversions to @convention(c) in @section expressions
1 parent a93595e commit 4e919fb

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/Sema/LegalConstExprVerifier.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,18 @@ checkSupportedWithSectionAttribute(const Expr *expr,
216216
if (isa<AbstractClosureExpr>(expr))
217217
return std::make_pair(expr, Closure);
218218

219-
// Function conversions are not allowed in constant expressions
220-
if (isa<FunctionConversionExpr>(expr))
219+
// Function conversions are allowed if the conversion is to '@convention(c)'
220+
if (auto functionConvExpr = dyn_cast<FunctionConversionExpr>(expr)) {
221+
if (auto targetFnTy =
222+
functionConvExpr->getType()->getAs<AnyFunctionType>()) {
223+
if (targetFnTy->getExtInfo().getRepresentation() ==
224+
FunctionTypeRepresentation::CFunctionPointer) {
225+
expressionsToCheck.push_back(functionConvExpr->getSubExpr());
226+
continue;
227+
}
228+
}
221229
return std::make_pair(expr, Default);
230+
}
222231

223232
// Direct references to non-generic functions are allowed
224233
if (const DeclRefExpr *declRef = dyn_cast<DeclRefExpr>(expr)) {

test/ConstValues/SectionSyntactic.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func bar(x: Int) -> String { return "test" }
4646
// function references
4747
@section("mysection") let funcRef1 = foo // ok
4848
@section("mysection") let funcRef2 = bar // ok
49+
@section("mysection") let funcRef3: ()->Int = foo // ok
50+
@section("mysection") let funcRef4: @convention(c) ()->Int = foo // ok
4951

5052
// invalid function references (should be rejected)
5153
@section("mysection") let invalidFuncRef1 = foo()

0 commit comments

Comments
 (0)