-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][bytecode] Only emit literal_comparison for string literals #129691
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
This is what the current interpreter does as well.
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesThis is what the current interpreter does as well. Full diff: https://github.com/llvm/llvm-project/pull/129691.diff 3 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index db35208a02941..2cf7ae2dd6f96 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1065,7 +1065,8 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
for (const auto &P : {LHS, RHS}) {
if (P.isZero())
continue;
- if (BothNonNull && P.pointsToLiteral()) {
+ if (BothNonNull && P.pointsToLiteral() &&
+ isa<StringLiteral>(P.getDeclDesc()->asExpr())) {
const SourceInfo &Loc = S.Current->getSource(OpPC);
S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
return false;
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index d51b039d40043..0c26d40ec5cd5 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1008,9 +1008,9 @@ namespace shufflevector {
namespace FunctionStart {
void a(void) {}
- static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an integral constant expression}} \
+ static_assert(__builtin_function_start(a) == a, ""); // ref-error {{not an integral constant expression}} \
// ref-note {{comparison against opaque constant address '&__builtin_function_start(a)'}} \
- // expected-note {{comparison of addresses of potentially overlapping literals has unspecified value}}
+ // expected-error {{static assertion failed}}
}
namespace BuiltinInImplicitCtor {
diff --git a/clang/test/AST/ByteCode/functions.cpp b/clang/test/AST/ByteCode/functions.cpp
index 66693a1fd7e32..a7c8836eac6b8 100644
--- a/clang/test/AST/ByteCode/functions.cpp
+++ b/clang/test/AST/ByteCode/functions.cpp
@@ -484,6 +484,18 @@ namespace AddressOf {
void testAddressof(int x) {
static_assert(&x == __builtin_addressof(x), "");
}
+
+ struct TS {
+ constexpr bool f(TS s) const {
+ /// The addressof call has a CXXConstructExpr as a parameter.
+ return this != __builtin_addressof(s);
+ }
+ };
+ constexpr bool exprAddressOf() {
+ TS s;
+ return s.f(s);
+ }
+ static_assert(exprAddressOf(), "");
}
namespace std {
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/186/builds/7028 Here is the relevant piece of the build log for the reference |
This is what the current interpreter does as well.