Skip to content

Commit a29b0d7

Browse files
authored
[clang][bytecode] Fix base cast of nullptr without descriptor (#132909)
The missing descriptor should only happen if the pointer is null pointer.
1 parent d4304d8 commit a29b0d7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,10 @@ IntPointer IntPointer::atOffset(const ASTContext &ASTCtx,
720720

721721
IntPointer IntPointer::baseCast(const ASTContext &ASTCtx,
722722
unsigned BaseOffset) const {
723+
if (!Desc) {
724+
assert(Value == 0);
725+
return *this;
726+
}
723727
const Record *R = Desc->ElemRecord;
724728
const Descriptor *BaseDesc = nullptr;
725729

clang/test/AST/ByteCode/records.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,3 +1771,19 @@ namespace RedeclaredCtor {
17711771
constexpr __sp_mut::__sp_mut(void *p) noexcept : __lx_(p) {}
17721772
constexpr __sp_mut muts = &mut_back[0];
17731773
}
1774+
1775+
namespace IntegralBaseCast {
1776+
class A {};
1777+
class B : public A {};
1778+
struct S {
1779+
B *a;
1780+
};
1781+
1782+
constexpr int f() {
1783+
S s{};
1784+
A *a = s.a;
1785+
return 0;
1786+
}
1787+
1788+
static_assert(f() == 0, "");
1789+
}

0 commit comments

Comments
 (0)