Skip to content

Commit 3c85b46

Browse files
tbaederraokblast
authored andcommitted
[clang][bytecode] Don't emit checkNull for function pointers (llvm#164376)
Diagnose them later when we try to call the function pointer.
1 parent 47baff8 commit 3c85b46

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6633,7 +6633,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
66336633
if (!this->visit(SubExpr))
66346634
return false;
66356635

6636-
if (!this->emitCheckNull(E))
6636+
if (!SubExpr->getType()->isFunctionPointerType() && !this->emitCheckNull(E))
66376637
return false;
66386638

66396639
if (classifyPrim(SubExpr) == PT_Ptr)

clang/test/AST/ByteCode/cxx14.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -std=c++14 -verify=both,expected %s -fexperimental-new-constant-interpreter
2+
// RUN: %clang_cc1 -std=c++14 -verify=both,ref %s
3+
4+
5+
6+
constexpr int(*null_ptr)() = nullptr;
7+
constexpr int test4 = (*null_ptr)(); // both-error {{must be initialized by a constant expression}} \
8+
// both-note {{evaluates to a null function pointer}}
9+

0 commit comments

Comments
 (0)