Skip to content

Commit 3b93122

Browse files
authored
[clang][bytecode] Do not diagnose volatile reads in CPCE mode (#140546)
This matches the diagnostic output of the current interpreter.
1 parent bb92c80 commit 3b93122

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,13 +2936,14 @@ inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
29362936
<< static_cast<unsigned>(Kind) << S.Current->getRange(OpPC);
29372937
return !Fatal;
29382938
} else if (Kind == CastKind::Volatile) {
2939-
// FIXME: Technically not a cast.
2940-
const auto *E = cast<CastExpr>(S.Current->getExpr(OpPC));
2941-
if (S.getLangOpts().CPlusPlus)
2942-
S.FFDiag(E, diag::note_constexpr_access_volatile_type)
2943-
<< AK_Read << E->getSubExpr()->getType();
2944-
else
2945-
S.FFDiag(E);
2939+
if (!S.checkingPotentialConstantExpression()) {
2940+
const auto *E = cast<CastExpr>(S.Current->getExpr(OpPC));
2941+
if (S.getLangOpts().CPlusPlus)
2942+
S.FFDiag(E, diag::note_constexpr_access_volatile_type)
2943+
<< AK_Read << E->getSubExpr()->getType();
2944+
else
2945+
S.FFDiag(E);
2946+
}
29462947

29472948
return false;
29482949
} else if (Kind == CastKind::Dynamic) {

clang/test/AST/ByteCode/cxx11.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,13 @@ namespace IntToPtrCast {
233233
constexpr intptr_t i = f((intptr_t)&foo - 10); // both-error{{constexpr variable 'i' must be initialized by a constant expression}} \
234234
// both-note{{reinterpret_cast}}
235235
}
236+
237+
namespace Volatile {
238+
constexpr int f(volatile int &&r) {
239+
return r; // both-note {{read of volatile-qualified type 'volatile int'}}
240+
}
241+
struct S {
242+
int j : f(0); // both-error {{constant expression}} \
243+
// both-note {{in call to 'f(0)'}}
244+
};
245+
}

0 commit comments

Comments
 (0)