Author: Timm Bäder Date: 2024-03-01T16:19:45+01:00 New Revision: a038f9758e02812803b7efce10ecf784f9842bbb
URL: https://github.com/llvm/llvm-project/commit/a038f9758e02812803b7efce10ecf784f9842bbb DIFF: https://github.com/llvm/llvm-project/commit/a038f9758e02812803b7efce10ecf784f9842bbb.diff LOG: [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. Added: Modified: clang/lib/AST/Interp/Interp.h clang/test/SemaCXX/undefined-internal.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 677c699efc2ab2..84f65a33bef361 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -2074,8 +2074,12 @@ inline bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func, size_t ThisOffset = ArgSize - (Func->hasRVO() ? primSize(PT_Ptr) : 0); Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset); - const CXXRecordDecl *DynamicDecl = - ThisPtr.getDeclDesc()->getType()->getAsCXXRecordDecl(); + QualType DynamicType = ThisPtr.getDeclDesc()->getType(); + const CXXRecordDecl *DynamicDecl; + if (DynamicType->isPointerType() || DynamicType->isReferenceType()) + DynamicDecl = DynamicType->getPointeeCXXRecordDecl(); + else + DynamicDecl = ThisPtr.getDeclDesc()->getType()->getAsCXXRecordDecl(); const auto *StaticDecl = cast<CXXRecordDecl>(Func->getParentDecl()); const auto *InitialFunction = cast<CXXMethodDecl>(Func->getDecl()); const CXXMethodDecl *Overrider = S.getContext().getOverridingFunction( diff --git a/clang/test/SemaCXX/undefined-internal.cpp b/clang/test/SemaCXX/undefined-internal.cpp index 790c96c9fe4514..054e71b92f93d2 100644 --- a/clang/test/SemaCXX/undefined-internal.cpp +++ b/clang/test/SemaCXX/undefined-internal.cpp @@ -2,11 +2,21 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy -std=c++98 %s // RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy -std=c++98 %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy -std=c++11 %s -fexperimental-new-constant-interpreter + + // Make sure we don't produce invalid IR. // RUN: %clang_cc1 -emit-llvm-only %s // RUN: %clang_cc1 -emit-llvm-only -std=c++98 %s // RUN: %clang_cc1 -emit-llvm-only -std=c++11 %s +// RUN: %clang_cc1 -emit-llvm-only %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -emit-llvm-only -std=c++98 %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -emit-llvm-only -std=c++11 %s -fexperimental-new-constant-interpreter + + namespace test1 { static void foo(); // expected-warning {{function 'test1::foo' has internal linkage but is not defined}} template <class T> static void bar(); // expected-warning {{function 'test1::bar<int>' has internal linkage but is not defined}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits