[clang] [clang-tools-extra] [libcxx] [clang] fix diagnostic printing of expressions ignoring LangOpts (PR #134693)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 8 07:17:27 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);
----------------
mizvekov wrote:

It's not just here though, this is the same for all other kinds, and the same for the parameter type, and the same for where we store this.

It wouldn't change much regarding potential UB if we wrote uintptr_t here, but then this would implicitly cast to uint64_t anyway.

Now if we change that to uintptr_t, then that would be bad in 32 bit platforms, as this is used to pack other things besides pointers. So presumably we want to change the parameter and structure types here to something that's at least as big as both types, which would be uintmax perhaps?

Or maybe just assert somewhere that uint64 is at least as big as uintptr?

https://github.com/llvm/llvm-project/pull/134693


More information about the cfe-commits mailing list