[clang] [clang][bytecode] Fix discarded dynamic casts (PR #200723)
via cfe-commits
cfe-commits at lists.llvm.org
Sun May 31 22:44:19 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
If they are checked.
---
Full diff: https://github.com/llvm/llvm-project/pull/200723.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2)
- (modified) clang/test/AST/ByteCode/cxx23.cpp (+4)
``````````diff
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);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/200723
More information about the cfe-commits
mailing list