-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang] Convert second arg of __builtin_assume_aligned to ConstantExpr #161314
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
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesSince the second argument must be a constant integer, we can as well convert it to a Fixes #161272 Full diff: https://github.com/llvm/llvm-project/pull/161314.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 39c3aa2243338..7b37e0b8d5430 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5954,6 +5954,9 @@ bool Sema::BuiltinAssumeAligned(CallExpr *TheCall) {
if (Result > Sema::MaximumAlignment)
Diag(TheCall->getBeginLoc(), diag::warn_assume_aligned_too_great)
<< SecondArg->getSourceRange() << Sema::MaximumAlignment;
+
+ TheCall->setArg(1,
+ ConstantExpr::Create(Context, SecondArg, APValue(Result)));
}
if (NumArgs > 2) {
diff --git a/clang/test/SemaCXX/builtin-assume-aligned.cpp b/clang/test/SemaCXX/builtin-assume-aligned.cpp
index 48bd8414fc50a..afc11cc694705 100644
--- a/clang/test/SemaCXX/builtin-assume-aligned.cpp
+++ b/clang/test/SemaCXX/builtin-assume-aligned.cpp
@@ -47,3 +47,9 @@ constexpr void *s1 = __builtin_assume_aligned(x, 32);
constexpr void *s2 = __builtin_assume_aligned(x, 32, 5);
constexpr void *s3 = __builtin_assume_aligned(x, 32, -1);
+
+constexpr int add(int a, int b) {
+ return a+b;
+}
+constexpr void *c1 = __builtin_assume_aligned(p, add(1,1));
+constexpr void *c2 = __builtin_assume_aligned(p, add(2,1)); // expected-error {{not a power of 2}}
|
Can you add a changelog entry? Thanks |
607da57
to
b442ffb
Compare
Heads up - this PR is causing us to hit the following assertion in https://github.com/google/highway. I'm currently running cvise to get a minimal reproducer.
|
The repro file is 2.5M, so cvise will take forever. This will take a while, so I apologize in advance. |
Reduced repro: constexpr long kAlignment = 128;
long AllocateAlignedBytes_payload;
void AllocateAlignedBytes() {
__builtin_assume_aligned(
reinterpret_cast<void *>(AllocateAlignedBytes_payload), kAlignment);
} |
…stantExpr (llvm#161314)" This reverts commit 8f77621.
Since this is a crash and it's blocking us from finding any other issues at chromium, let's revert this for now. |
That sounds unfortunate but reasonable. Thanks for handling the revert. |
@Fznamznon : Your patch 9ad72df seems at least closely related here: in CGExprScalar.cpp in VisitConstantExpr. This patch is unfortunately just revealing a bug there, where the type of the constant expression is a L value constant but isn't getting the 'pointer' type for the It isn't clear to me what SHOULD happen, but that at least seems wrong. |
…stantExpr (#161314)" (#161719) This reverts commit 8f77621 (#161314). Reason: Causing crashes when building https://github.com/google/highway. See the original PR for details.
llvm#161314) Since the second argument must be a constant integer, we can as well convert it to a `ConstantExpr` in Sema. Fixes llvm#161272
…stantExpr (llvm#161314)" (llvm#161719) This reverts commit 8f77621 (llvm#161314). Reason: Causing crashes when building https://github.com/google/highway. See the original PR for details.
Since the second argument must be a constant integer, we can as well convert it to a
ConstantExpr
in Sema.Fixes #161272