[clang] [clang-tools-extra] [libcxx] [clang] fix diagnostic printing of expressions ignoring LangOpts (PR #134693)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 8 07:25:01 PDT 2025
================
@@ -7379,6 +7379,14 @@ class RecoveryExpr final : public Expr,
friend class ASTStmtWriter;
};
+/// Insertion operator for diagnostics. This allows sending
+/// Expr into a diagnostic with <<.
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ const Expr *E) {
+ DB.AddTaggedVal(reinterpret_cast<uint64_t>(E), DiagnosticsEngine::ak_expr);
----------------
erichkeane wrote:
As far as correctness: we need to smuggle pointers through a `uintptr_t`. Beyond that, there is no harm then again casting that immediately to the `uint64_t`.
So the 'fixit' suggestion is:
```suggestion
DB.AddTaggedVal(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(E)), DiagnosticsEngine::ak_expr);
```
The underlying type here is fine, and SHOULD stay `uint64_t`. But the `reinterpret_cast` of pointer-to-int itself is the problematic part. If you'd like, you can put a static-assert that `sizeof(uintptr_t)` is <= `sizeof(uint64_t)`, but I'm not horribly worried about 128 bit pointers
https://github.com/llvm/llvm-project/pull/134693
More information about the cfe-commits
mailing list