Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions clang/lib/AST/ByteCode/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,6 @@ Context::getOverridingFunction(const CXXRecordDecl *DynamicDecl,

const Function *Context::getOrCreateFunction(const FunctionDecl *FuncDecl) {
assert(FuncDecl);
FuncDecl = FuncDecl->getMostRecentDecl();

if (const Function *Func = P->getFunction(FuncDecl))
return Func;

Expand Down
13 changes: 10 additions & 3 deletions clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1750,9 +1750,8 @@ bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
const Pointer &Ptr = S.Stk.pop<Pointer>();

if (Ptr.isZero()) {
const auto *E = cast<CallExpr>(S.Current->getExpr(OpPC));
S.FFDiag(E, diag::note_constexpr_null_callee)
<< const_cast<Expr *>(E->getCallee()) << E->getSourceRange();
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_null_callee)
<< const_cast<Expr *>(CE->getCallee()) << CE->getSourceRange();
return false;
}

Expand All @@ -1778,6 +1777,14 @@ bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
return false;
}

// Can happen when casting function pointers around.
QualType CalleeType = CE->getCallee()->getType();
if (CalleeType->isPointerType() &&
!S.getASTContext().hasSameFunctionTypeIgnoringExceptionSpec(
F->getDecl()->getType(), CalleeType->getPointeeType())) {
return false;
}

assert(ArgSize >= F->getWrittenArgSize());
uint32_t VarArgSize = ArgSize - F->getWrittenArgSize();

Expand Down
18 changes: 8 additions & 10 deletions clang/test/AST/ByteCode/functions.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -pedantic -verify=expected,both %s
// RUN: %clang_cc1 -std=c++14 -fexperimental-new-constant-interpreter -pedantic -verify=expected,both %s
// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter -pedantic -verify=expected,both %s
// RUN: %clang_cc1 -pedantic -verify=ref,both %s
// RUN: %clang_cc1 -pedantic -std=c++14 -verify=ref,both %s
// RUN: %clang_cc1 -pedantic -std=c++20 -verify=ref,both %s
// RUN: %clang_cc1 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -std=c++14 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -std=c++20 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -pedantic -verify=ref,both %s
// RUN: %clang_cc1 -std=c++14 -pedantic -verify=ref,both %s
// RUN: %clang_cc1 -std=c++20 -pedantic -verify=ref,both %s

#define fold(x) (__builtin_constant_p(0) ? (x) : (x))

Expand Down Expand Up @@ -672,10 +672,8 @@ namespace FunctionCast {
constexpr int test4 = fold(IntFn(DoubleFn(f)))();
constexpr int test5 = IntFn(fold(DoubleFn(f)))(); // both-error {{constant expression}} \
// both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
// FIXME: Interpreter is less strict here.
constexpr int test6 = fold(IntPtrFn(f2))() == nullptr; // ref-error {{constant expression}}
// FIXME: The following crashes interpreter
// constexpr int test6 = fold(IntFn(f3)());
constexpr int test6 = fold(IntPtrFn(f2))() == nullptr; // both-error {{constant expression}}
constexpr int test7 = fold(IntFn(f3)()); // both-error {{must be initialized by a constant expression}}
}

#if __cplusplus >= 202002L
Expand Down