[clang] 51b54ff - [clang][bytecode] Fix discarded dynamic casts (#200723)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 1 01:41:05 PDT 2026
Author: Timm Baeder
Date: 2026-06-01T10:41:01+02:00
New Revision: 51b54fffee8c4b3440a03b3affceba3690754115
URL: https://github.com/llvm/llvm-project/commit/51b54fffee8c4b3440a03b3affceba3690754115
DIFF: https://github.com/llvm/llvm-project/commit/51b54fffee8c4b3440a03b3affceba3690754115.diff
LOG: [clang][bytecode] Fix discarded dynamic casts (#200723)
If they are checked.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/cxx23.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 774a853950837..322c1f827223b 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -3570,6 +3570,8 @@ bool Compiler<Emitter>::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E) {
if (!this->emitCheckDynamicCast(E))
return false;
+ if (DiscardResult)
+ return this->emitPopPtr(E);
return true;
}
diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp
index 7b2d1c6e7e1e1..4619023af83e6 100644
--- a/clang/test/AST/ByteCode/cxx23.cpp
+++ b/clang/test/AST/ByteCode/cxx23.cpp
@@ -641,4 +641,8 @@ namespace DynamicCast {
// all23-note {{dynamic_cast applied to object 'a' whose dynamic type is not constant}} \
// all20-note {{function parameter 'a' with unknown value cannot be used in a constant expression}}
}
+
+ struct S {};
+ constexpr S s;
+ constexpr int foo = (dynamic_cast<const S &>(s), 0);
}
More information about the cfe-commits
mailing list