-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang][bytecode] Fix two small builtin_constant_p cases #137587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Only accept string literals if we're pointing to the first index and do accept complex literals.
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesOnly accept string literals if we're pointing to the first index and do accept complex literals. Full diff: https://github.com/llvm/llvm-project/pull/137587.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 37111343178dd..dfc00ffc297e1 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -321,8 +321,11 @@ bool CheckBCPResult(InterpState &S, const Pointer &Ptr) {
if (Ptr.isTypeidPointer())
return true;
+ if (Ptr.getType()->isAnyComplexType())
+ return true;
+
if (const Expr *Base = Ptr.getDeclDesc()->asExpr())
- return isa<StringLiteral>(Base);
+ return isa<StringLiteral>(Base) && Ptr.getIndex() == 0;
return false;
}
diff --git a/clang/test/AST/ByteCode/builtin-constant-p.cpp b/clang/test/AST/ByteCode/builtin-constant-p.cpp
index f5b16761bfdc9..9f5521590833d 100644
--- a/clang/test/AST/ByteCode/builtin-constant-p.cpp
+++ b/clang/test/AST/ByteCode/builtin-constant-p.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter -verify=expected,both %s
-// RUN: %clang_cc1 -std=c++20 -verify=ref,both %s
+// RUN: %clang_cc1 -std=c++20 -verify=expected,both %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++20 -verify=ref,both %s
using intptr_t = __INTPTR_TYPE__;
@@ -129,3 +129,14 @@ void g() {
const float f = __builtin_is_constant_evaluated();
static_assert(fold(f == 0.0f));
}
+
+void test17(void) {
+#define ASSERT(...) { enum { folded = (__VA_ARGS__) }; int arr[folded ? 1 : -1]; }
+#define T(...) ASSERT(__builtin_constant_p(__VA_ARGS__))
+#define F(...) ASSERT(!__builtin_constant_p(__VA_ARGS__))
+
+ T(3i + 5);
+ T("string literal");
+ F("string literal" + 1); // both-warning {{adding}} \
+ // both-note {{use array indexing}}
+}
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/4271 Here is the relevant piece of the build log for the reference
|
Only accept string literals if we're pointing to the first index and do accept complex literals.
Only accept string literals if we're pointing to the first index and do accept complex literals.
Only accept string literals if we're pointing to the first index and do accept complex literals.
Only accept string literals if we're pointing to the first index and do accept complex literals.
Only accept string literals if we're pointing to the first index and do accept complex literals.
Only accept string literals if we're pointing to the first index and do accept complex literals.