Skip to content

Commit a038f97

Browse files
committed
[clang][Interp] Fix virtual calls with reference instance pointers
getCXXRecordType() on those types does not return the type we need. Use getPointeeCXXRecordType() instead in those cases.
1 parent b0181be commit a038f97

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,8 +2074,12 @@ inline bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
20742074
size_t ThisOffset = ArgSize - (Func->hasRVO() ? primSize(PT_Ptr) : 0);
20752075
Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset);
20762076

2077-
const CXXRecordDecl *DynamicDecl =
2078-
ThisPtr.getDeclDesc()->getType()->getAsCXXRecordDecl();
2077+
QualType DynamicType = ThisPtr.getDeclDesc()->getType();
2078+
const CXXRecordDecl *DynamicDecl;
2079+
if (DynamicType->isPointerType() || DynamicType->isReferenceType())
2080+
DynamicDecl = DynamicType->getPointeeCXXRecordDecl();
2081+
else
2082+
DynamicDecl = ThisPtr.getDeclDesc()->getType()->getAsCXXRecordDecl();
20792083
const auto *StaticDecl = cast<CXXRecordDecl>(Func->getParentDecl());
20802084
const auto *InitialFunction = cast<CXXMethodDecl>(Func->getDecl());
20812085
const CXXMethodDecl *Overrider = S.getContext().getOverridingFunction(

clang/test/SemaCXX/undefined-internal.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22
// RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy -std=c++98 %s
33
// RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy -std=c++11 %s
44

5+
// RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy %s -fexperimental-new-constant-interpreter
6+
// RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy -std=c++98 %s -fexperimental-new-constant-interpreter
7+
// RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy -std=c++11 %s -fexperimental-new-constant-interpreter
8+
9+
510
// Make sure we don't produce invalid IR.
611
// RUN: %clang_cc1 -emit-llvm-only %s
712
// RUN: %clang_cc1 -emit-llvm-only -std=c++98 %s
813
// RUN: %clang_cc1 -emit-llvm-only -std=c++11 %s
914

15+
// RUN: %clang_cc1 -emit-llvm-only %s -fexperimental-new-constant-interpreter
16+
// RUN: %clang_cc1 -emit-llvm-only -std=c++98 %s -fexperimental-new-constant-interpreter
17+
// RUN: %clang_cc1 -emit-llvm-only -std=c++11 %s -fexperimental-new-constant-interpreter
18+
19+
1020
namespace test1 {
1121
static void foo(); // expected-warning {{function 'test1::foo' has internal linkage but is not defined}}
1222
template <class T> static void bar(); // expected-warning {{function 'test1::bar<int>' has internal linkage but is not defined}}

0 commit comments

Comments
 (0)