[clang] [clang][bytecode] Diagnose IntegralToPointer casts to non-void (PR #123619)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 20 06:16:54 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
But keep evaluating. This is what the current interpreter does as well.
---
Full diff: https://github.com/llvm/llvm-project/pull/123619.diff
3 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.h (+4)
- (modified) clang/test/AST/ByteCode/constexpr.c (+2-2)
- (modified) clang/test/SemaCXX/builtin-assume-aligned.cpp (-1)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 58c0256c7d7df8..11e9738eff5dcd 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2693,6 +2693,10 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
inline bool GetIntPtr(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
const T &IntVal = S.Stk.pop<T>();
+ if (Desc)
+ S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
+ << 2 << S.getLangOpts().CPlusPlus;
+
S.Stk.push<Pointer>(static_cast<uint64_t>(IntVal), Desc);
return true;
}
diff --git a/clang/test/AST/ByteCode/constexpr.c b/clang/test/AST/ByteCode/constexpr.c
index fed24fa72b2541..af96bf3a06f375 100644
--- a/clang/test/AST/ByteCode/constexpr.c
+++ b/clang/test/AST/ByteCode/constexpr.c
@@ -309,8 +309,8 @@ constexpr const int *V81 = &V80;
constexpr int *V82 = 0;
constexpr int *V83 = V82;
constexpr int *V84 = 42;
-// ref-error at -1 {{constexpr variable 'V84' must be initialized by a constant expression}}
-// ref-note at -2 {{this conversion is not allowed in a constant expression}}
+// both-error at -1 {{constexpr variable 'V84' must be initialized by a constant expression}}
+// both-note at -2 {{this conversion is not allowed in a constant expression}}
// both-error at -3 {{constexpr pointer initializer is not null}}
constexpr int *V85 = nullptr;
diff --git a/clang/test/SemaCXX/builtin-assume-aligned.cpp b/clang/test/SemaCXX/builtin-assume-aligned.cpp
index 85a7faee916181..48bd8414fc50a1 100644
--- a/clang/test/SemaCXX/builtin-assume-aligned.cpp
+++ b/clang/test/SemaCXX/builtin-assume-aligned.cpp
@@ -1,5 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s -fexperimental-new-constant-interpreter
int n;
constexpr int *p = 0;
``````````
</details>
https://github.com/llvm/llvm-project/pull/123619
More information about the cfe-commits
mailing list