Skip to content

Commit 5dcda94

Browse files
authored
[clang][bytecode] Handle missing DynamicDecl in CallVirt (llvm#187980)
Don't return true from getDynamicDecl() if the returned DynamicDecl is null.
1 parent 4b084f2 commit 5dcda94

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
17711771
return true;
17721772
}
17731773

1774-
static bool GetDynamicDecl(InterpState &S, CodePtr OpPC, Pointer TypePtr,
1774+
static bool getDynamicDecl(InterpState &S, CodePtr OpPC, Pointer TypePtr,
17751775
const CXXRecordDecl *&DynamicDecl) {
17761776
TypePtr = TypePtr.stripBaseCasts();
17771777

@@ -1797,7 +1797,7 @@ static bool GetDynamicDecl(InterpState &S, CodePtr OpPC, Pointer TypePtr,
17971797
} else {
17981798
DynamicDecl = DynamicType->getAsCXXRecordDecl();
17991799
}
1800-
return true;
1800+
return DynamicDecl != nullptr;
18011801
}
18021802

18031803
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
@@ -1810,7 +1810,7 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
18101810
const FunctionDecl *Callee = Func->getDecl();
18111811

18121812
const CXXRecordDecl *DynamicDecl = nullptr;
1813-
if (!GetDynamicDecl(S, OpPC, ThisPtr, DynamicDecl))
1813+
if (!getDynamicDecl(S, OpPC, ThisPtr, DynamicDecl))
18141814
return false;
18151815
assert(DynamicDecl);
18161816

clang/test/AST/ByteCode/records.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,3 +1902,11 @@ namespace StaticRedecl {
19021902
constexpr T t;
19031903
static_assert(t.p == &T::tt, "");
19041904
}
1905+
1906+
namespace VirtCallNoRecord {
1907+
struct S {
1908+
virtual int foo();
1909+
};
1910+
int bar(int{((S *const)0)->foo()});
1911+
}
1912+

0 commit comments

Comments
 (0)