Skip to content

Commit d6fa036

Browse files
committed
[SYCL][clang] Always lift SYCL device code restrictions in constexpr contexts
Earlier a mechanism to lift SYCL device code restrictions in C++ manifestly constant-evaluated expressions was implemented in the front-end. It was enabled under an option since it wasn't specified. Since then it has been decided to make this behavior default for SYCL 2020. This PR removes the option that was enabling the new behavior and enables it by default.
1 parent 48f0e93 commit d6fa036

File tree

7 files changed

+10
-23
lines changed

7 files changed

+10
-23
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ LANGOPT(SYCLAllowFuncPtr , 1, 0, "Allow function pointers in SYCL device code")
307307
LANGOPT(SYCLStdLayoutKernelParams, 1, 0, "Enable standard layout requirement for SYCL kernel parameters")
308308
LANGOPT(SYCLUnnamedLambda , 1, 0, "Allow unnamed lambda SYCL kernels")
309309
LANGOPT(SYCLForceInlineKernelLambda , 1, 0, "Force inline SYCL kernel lambdas in entry point")
310-
LANGOPT(SYCLAllowAllFeaturesInConstexpr, 1, 0, "Allow all C++ features in SYCL device code in manifestly constant-evaluated expressions")
311310
LANGOPT(SYCLESIMDForceStatelessMem, 1, 0, "Make accessors use USM memory in ESIMD kernels")
312311
LANGOPT(SYCLESIMDBuildHostCode, 1, 1, "Build the host implementation of ESIMD functions")
313312
ENUM_LANGOPT(SYCLVersion , SYCLMajorVersion, 2, SYCL_None, "Version of the SYCL standard used")

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8628,11 +8628,6 @@ def fsycl_is_native_cpu : Flag<["-"], "fsycl-is-native-cpu">,
86288628
HelpText<"Perform device compilation for Native CPU.">,
86298629
Visibility<[CC1Option]>,
86308630
MarshallingInfoFlag<LangOpts<"SYCLIsNativeCPU">>;
8631-
defm sycl_allow_all_features_in_constexpr
8632-
: BoolFOption<
8633-
"sycl-allow-all-features-in-constexpr", LangOpts<"SYCLAllowAllFeaturesInConstexpr">,
8634-
DefaultFalse,
8635-
PosFlag<SetTrue, [], [CC1Option], "Allow all C++ features in SYCL device code in manifestly constant-evaluated expressions">, NegFlag<SetFalse>>;
86368631

86378632
} // let Visibility = [CC1Option]
86388633

clang/lib/Sema/Sema.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ class DeferredDiagnosticsEmitter
18291829
}
18301830

18311831
void VisitDeclStmt(DeclStmt *DS) {
1832-
if (S.getLangOpts().SYCLAllowAllFeaturesInConstexpr) {
1832+
if (S.getLangOpts().SYCLIsDevice) {
18331833
if (DS->isSingleDecl()) {
18341834
Decl *D = DS->getSingleDecl();
18351835
if (auto *VD = dyn_cast<VarDecl>(D))
@@ -1850,7 +1850,7 @@ class DeferredDiagnosticsEmitter
18501850
}
18511851

18521852
void VisitConstantExpr(ConstantExpr *E) {
1853-
if (S.getLangOpts().SYCLAllowAllFeaturesInConstexpr)
1853+
if (S.getLangOpts().SYCLIsDevice)
18541854
return;
18551855
this->VisitStmt(E);
18561856
}
@@ -2264,7 +2264,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
22642264

22652265
CheckType(Ty);
22662266
if (const auto *FD = dyn_cast_if_present<FunctionDecl>(D)) {
2267-
if (LangOpts.SYCLAllowAllFeaturesInConstexpr && FD->isConsteval())
2267+
if (LangOpts.SYCLIsDevice && FD->isConsteval())
22682268
return;
22692269
if (const auto *FPTy = dyn_cast<FunctionProtoType>(Ty)) {
22702270
for (const auto &ParamTy : FPTy->param_types())

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18418,7 +18418,7 @@ void Sema::ActOnCXXEnterDeclInitializer(Scope *S, Decl *D) {
1841818418

1841918419
if (auto *VD = dyn_cast<VarDecl>(D);
1842018420
VD && (VD->mightBeUsableInConstantExpressions(Context)))
18421-
InConstexprVarInit = LangOpts.SYCLAllowAllFeaturesInConstexpr;
18421+
InConstexprVarInit = true;
1842218422
PushExpressionEvaluationContext(
1842318423
ExpressionEvaluationContext::PotentiallyEvaluated, D);
1842418424
}

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,7 @@ class DeviceFunctionTracker {
782782

783783
public:
784784
DeviceFunctionTracker(SemaSYCL &S) : SemaSYCLRef(S) {
785-
if (S.getLangOpts().SYCLAllowAllFeaturesInConstexpr)
786-
CG.setSkipConstantExpressions(S.getASTContext());
785+
CG.setSkipConstantExpressions(S.getASTContext());
787786
CG.addToCallGraph(S.getASTContext().getTranslationUnitDecl());
788787
CollectSyclExternalFuncs();
789788
}
@@ -5594,14 +5593,12 @@ SemaSYCL::DiagIfDeviceCode(SourceLocation Loc, unsigned DiagID,
55945593
return SemaDiagnosticBuilder::K_ImmediateWithCallStack;
55955594
if (!FD)
55965595
return SemaDiagnosticBuilder::K_Nop;
5597-
if (SemaRef.getLangOpts().SYCLAllowAllFeaturesInConstexpr &&
5598-
(SemaRef.isConstantEvaluatedContext() ||
5599-
SemaRef.currentEvaluationContext().isDiscardedStatementContext()))
5596+
if (SemaRef.isConstantEvaluatedContext() ||
5597+
SemaRef.currentEvaluationContext().isDiscardedStatementContext())
56005598
return SemaDiagnosticBuilder::K_Nop;
56015599
// Defer until we know that the variable's intializer is actually a
56025600
// manifestly constant-evaluated expression.
5603-
if (SemaRef.getLangOpts().SYCLAllowAllFeaturesInConstexpr &&
5604-
SemaRef.InConstexprVarInit)
5601+
if (SemaRef.InConstexprVarInit)
56055602
return SemaDiagnosticBuilder::K_Deferred;
56065603
if (SemaRef.getEmissionStatus(FD) ==
56075604
Sema::FunctionEmissionStatus::Emitted) {

clang/test/SemaSYCL/allow-all-features-in-constexpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -fcxx-exceptions -verify -fsyntax-only -std=c++23 -triple spir64 -aux-triple x86_64 -fsycl-allow-all-features-in-constexpr %s
1+
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -fcxx-exceptions -verify -fsyntax-only -std=c++23 -triple spir64 -aux-triple x86_64 %s
22

33
// The test checks that all SYCL device code limitations are lifted in
44
// manifestly constant-evaluated expressions under an option.

clang/test/SemaSYCL/wrong-address-taking.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ template <typename T> void templatedContext() {
5050
// expected-error@+1 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
5151
auto p1 = &ForMembers::badMember;
5252

53-
// expected-error@+2 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
5453
// expected-note@+1 {{called by 'templatedContext<int>'}}
5554
templateCaller1<badFoo>(1);
5655
}
@@ -84,9 +83,7 @@ int main() {
8483
a = goodFoo;
8584
a = &goodFoo;
8685

87-
// expected-error@+1 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
8886
constexpr auto b = badFoo;
89-
// expected-error@+1 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
9087
constexpr auto c = &badFoo;
9188
// expected-note@+1 {{called by 'operator()'}}
9289
basicUsage();
@@ -125,8 +122,7 @@ int main() {
125122

126123
templateCaller1<goodFoo>(1);
127124

128-
// expected-note@+2 {{called by 'operator()'}}
129-
// expected-error@+1 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
125+
// expected-note@+1 {{called by 'operator()'}}
130126
templateCaller1<badFoo>(1);
131127
});
132128
});

0 commit comments

Comments
 (0)