aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Interp.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-04-23 18:52:35 +0200
committerGitHub <noreply@github.com>2025-04-23 18:52:35 +0200
commit1b6cbaa7b64f54b127d139d653468e213bae007e (patch)
tree056125775fc6227d03bee4e84841b1e7fda2871e /clang/lib/AST/ByteCode/Interp.cpp
parent83c309b90550aa768ff9aa11b70898ee2c56b71e (diff)
downloadllvm-1b6cbaa7b64f54b127d139d653468e213bae007e.zip
llvm-1b6cbaa7b64f54b127d139d653468e213bae007e.tar.gz
llvm-1b6cbaa7b64f54b127d139d653468e213bae007e.tar.bz2
[clang][bytecode] Refine diagnostics for volatile reads (#136857)
Differentiate between a volarile read via a lvalue-to-rvalue cast of a volatile qualified subexpression and a read from a pointer with a volatile base object.
Diffstat (limited to 'clang/lib/AST/ByteCode/Interp.cpp')
-rw-r--r--clang/lib/AST/ByteCode/Interp.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index b755a07..6f277a7 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -641,11 +641,30 @@ static bool CheckVolatile(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
if (!PtrType.isVolatileQualified())
return true;
- const SourceInfo &Loc = S.Current->getSource(OpPC);
- if (S.getLangOpts().CPlusPlus)
- S.FFDiag(Loc, diag::note_constexpr_access_volatile_type) << AK << PtrType;
- else
- S.FFDiag(Loc);
+ if (!S.getLangOpts().CPlusPlus)
+ return Invalid(S, OpPC);
+
+ const NamedDecl *ND = nullptr;
+ int DiagKind;
+ SourceLocation Loc;
+ if (const auto *F = Ptr.getField()) {
+ DiagKind = 2;
+ Loc = F->getLocation();
+ ND = F;
+ } else if (auto *VD = Ptr.getFieldDesc()->asValueDecl()) {
+ DiagKind = 1;
+ Loc = VD->getLocation();
+ ND = VD;
+ } else {
+ DiagKind = 0;
+ if (const auto *E = Ptr.getFieldDesc()->asExpr())
+ Loc = E->getExprLoc();
+ }
+
+ S.FFDiag(S.Current->getLocation(OpPC),
+ diag::note_constexpr_access_volatile_obj, 1)
+ << AK << DiagKind << ND;
+ S.Note(Loc, diag::note_constexpr_volatile_here) << DiagKind;
return false;
}