[clang] e8674af - [clang][bytecode] Diagnose IntegralToPointer casts to non-void (#123619)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 20 08:41:22 PST 2025
Author: Timm Baeder
Date: 2025-01-20T17:41:18+01:00
New Revision: e8674af6f41b2e78ceebabb23e40588c41da5a23
URL: https://github.com/llvm/llvm-project/commit/e8674af6f41b2e78ceebabb23e40588c41da5a23
DIFF: https://github.com/llvm/llvm-project/commit/e8674af6f41b2e78ceebabb23e40588c41da5a23.diff
LOG: [clang][bytecode] Diagnose IntegralToPointer casts to non-void (#123619)
But keep evaluating. This is what the current interpreter does as well.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.h
clang/test/AST/ByteCode/constexpr.c
clang/test/SemaCXX/builtin-assume-aligned.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 510ff88e07f938..063970afec9e35 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;
More information about the cfe-commits
mailing list