[PATCH] D84032: [clang] Make clear Sema::CheckForConstantInitializer is for C-only codepath.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 17 08:17:42 PDT 2020
hokein created this revision.
hokein added reviewers: sammccall, efriedma.
Herald added a project: clang.
- add an assertion;
- remove the changes introduced in https://github.com/llvm/llvm-project/commit/4a962f03bebef9e3c7d501580357a303638b2700, looks like clang can handle that well at the moment, the diagnostic seems better;
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84032
Files:
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/compound-literal.cpp
Index: clang/test/SemaCXX/compound-literal.cpp
===================================================================
--- clang/test/SemaCXX/compound-literal.cpp
+++ clang/test/SemaCXX/compound-literal.cpp
@@ -89,9 +89,7 @@
}
}
-// This doesn't necessarily need to be an error, but CodeGen can't handle it
-// at the moment.
-int PR17415 = (int){PR17415}; // expected-error {{initializer element is not a compile-time constant}}
+int PR17415 = (int){PR17415}; // expected-warning {{variable 'PR17415' is uninitialized when used within its own initialization}}
// Make sure we accept this. (Not sure if we actually should... but we do
// at the moment.)
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6816,12 +6816,9 @@
auto *E = new (Context) CompoundLiteralExpr(LParenLoc, TInfo, literalType,
VK, LiteralExpr, isFileScope);
- if (isFileScope) {
- if (!LiteralExpr->isTypeDependent() &&
- !LiteralExpr->isValueDependent() &&
- !literalType->isDependentType()) // C99 6.5.2.5p3
- if (CheckForConstantInitializer(LiteralExpr, literalType))
- return ExprError();
+ if (isFileScope && !getLangOpts().CPlusPlus) { // C99 6.5.2.5p3
+ if (CheckForConstantInitializer(LiteralExpr, literalType))
+ return ExprError();
} else if (literalType.getAddressSpace() != LangAS::opencl_private &&
literalType.getAddressSpace() != LangAS::Default) {
// Embedded-C extensions to C99 6.5.2.5:
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11069,6 +11069,7 @@
// "may accept other forms of constant expressions" exception.
// (We never end up here for C++, so the constant expression
// rules there don't matter.)
+ assert(!getLangOpts().CPlusPlus || getLangOpts().OpenCLCPlusPlus);
const Expr *Culprit;
if (Init->isConstantInitializer(Context, false, &Culprit))
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84032.278778.patch
Type: text/x-patch
Size: 2156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200717/5bcf149d/attachment.bin>
More information about the cfe-commits
mailing list