Skip to content

Commit e8674af

Browse files
authored
[clang][bytecode] Diagnose IntegralToPointer casts to non-void (#123619)
But keep evaluating. This is what the current interpreter does as well.
1 parent f33e3d4 commit e8674af

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,10 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
26932693
inline bool GetIntPtr(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
26942694
const T &IntVal = S.Stk.pop<T>();
26952695

2696+
if (Desc)
2697+
S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
2698+
<< 2 << S.getLangOpts().CPlusPlus;
2699+
26962700
S.Stk.push<Pointer>(static_cast<uint64_t>(IntVal), Desc);
26972701
return true;
26982702
}

clang/test/AST/ByteCode/constexpr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ constexpr const int *V81 = &V80;
309309
constexpr int *V82 = 0;
310310
constexpr int *V83 = V82;
311311
constexpr int *V84 = 42;
312-
// ref-error@-1 {{constexpr variable 'V84' must be initialized by a constant expression}}
313-
// ref-note@-2 {{this conversion is not allowed in a constant expression}}
312+
// both-error@-1 {{constexpr variable 'V84' must be initialized by a constant expression}}
313+
// both-note@-2 {{this conversion is not allowed in a constant expression}}
314314
// both-error@-3 {{constexpr pointer initializer is not null}}
315315
constexpr int *V85 = nullptr;
316316

clang/test/SemaCXX/builtin-assume-aligned.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s
2-
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s -fexperimental-new-constant-interpreter
32

43
int n;
54
constexpr int *p = 0;

0 commit comments

Comments
 (0)