[clang] [clang][bytecode] Fix base cast of nullptr without descriptor (PR #132909)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 25 03:17:41 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
The missing descriptor should only happen if the pointer is null pointer.
---
Full diff: https://github.com/llvm/llvm-project/pull/132909.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Pointer.cpp (+4)
- (modified) clang/test/AST/ByteCode/records.cpp (+16)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp
index 8abdc54b64677..79b47c26992ae 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -720,6 +720,10 @@ IntPointer IntPointer::atOffset(const ASTContext &ASTCtx,
IntPointer IntPointer::baseCast(const ASTContext &ASTCtx,
unsigned BaseOffset) const {
+ if (!Desc) {
+ assert(Value == 0);
+ return *this;
+ }
const Record *R = Desc->ElemRecord;
const Descriptor *BaseDesc = nullptr;
diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp
index 5d9f1044f206b..da851785323a5 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1771,3 +1771,19 @@ namespace RedeclaredCtor {
constexpr __sp_mut::__sp_mut(void *p) noexcept : __lx_(p) {}
constexpr __sp_mut muts = &mut_back[0];
}
+
+namespace IntegralBaseCast {
+ class A {};
+ class B : public A {};
+ struct S {
+ B *a;
+ };
+
+ constexpr int f() {
+ S s{};
+ A *a = s.a;
+ return 0;
+ }
+
+ static_assert(f() == 0, "");
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/132909
More information about the cfe-commits
mailing list