[clang] 3b93122 - [clang][bytecode] Do not diagnose volatile reads in CPCE mode (#140546)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 19 08:15:40 PDT 2025
Author: Timm Baeder
Date: 2025-05-19T17:15:37+02:00
New Revision: 3b93122907ec9d7c283398332051943964df8c9a
URL: https://github.com/llvm/llvm-project/commit/3b93122907ec9d7c283398332051943964df8c9a
DIFF: https://github.com/llvm/llvm-project/commit/3b93122907ec9d7c283398332051943964df8c9a.diff
LOG: [clang][bytecode] Do not diagnose volatile reads in CPCE mode (#140546)
This matches the diagnostic output of the current interpreter.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.h
clang/test/AST/ByteCode/cxx11.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 9f1a6302eb856..bfc6797d13412 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2936,13 +2936,14 @@ inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
<< static_cast<unsigned>(Kind) << S.Current->getRange(OpPC);
return !Fatal;
} else if (Kind == CastKind::Volatile) {
- // FIXME: Technically not a cast.
- const auto *E = cast<CastExpr>(S.Current->getExpr(OpPC));
- if (S.getLangOpts().CPlusPlus)
- S.FFDiag(E, diag::note_constexpr_access_volatile_type)
- << AK_Read << E->getSubExpr()->getType();
- else
- S.FFDiag(E);
+ if (!S.checkingPotentialConstantExpression()) {
+ const auto *E = cast<CastExpr>(S.Current->getExpr(OpPC));
+ if (S.getLangOpts().CPlusPlus)
+ S.FFDiag(E, diag::note_constexpr_access_volatile_type)
+ << AK_Read << E->getSubExpr()->getType();
+ else
+ S.FFDiag(E);
+ }
return false;
} else if (Kind == CastKind::Dynamic) {
diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp
index 88e195c36b583..2a1bda675075c 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -233,3 +233,13 @@ namespace IntToPtrCast {
constexpr intptr_t i = f((intptr_t)&foo - 10); // both-error{{constexpr variable 'i' must be initialized by a constant expression}} \
// both-note{{reinterpret_cast}}
}
+
+namespace Volatile {
+ constexpr int f(volatile int &&r) {
+ return r; // both-note {{read of volatile-qualified type 'volatile int'}}
+ }
+ struct S {
+ int j : f(0); // both-error {{constant expression}} \
+ // both-note {{in call to 'f(0)'}}
+ };
+}
More information about the cfe-commits
mailing list