[clang] c5f9a2a - [clang][bytecode] Don't emit checkNull for function pointers (#164376)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 21 05:49:07 PDT 2025
Author: Timm Baeder
Date: 2025-10-21T14:49:03+02:00
New Revision: c5f9a2a2b21b4625598524aedbf32c1ea2b78528
URL: https://github.com/llvm/llvm-project/commit/c5f9a2a2b21b4625598524aedbf32c1ea2b78528
DIFF: https://github.com/llvm/llvm-project/commit/c5f9a2a2b21b4625598524aedbf32c1ea2b78528.diff
LOG: [clang][bytecode] Don't emit checkNull for function pointers (#164376)
Diagnose them later when we try to call the function pointer.
Added:
clang/test/AST/ByteCode/cxx14.cpp
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 74cae030bb9bb..28b9d84f6a76d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6633,7 +6633,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
if (!this->visit(SubExpr))
return false;
- if (!this->emitCheckNull(E))
+ if (!SubExpr->getType()->isFunctionPointerType() && !this->emitCheckNull(E))
return false;
if (classifyPrim(SubExpr) == PT_Ptr)
diff --git a/clang/test/AST/ByteCode/cxx14.cpp b/clang/test/AST/ByteCode/cxx14.cpp
new file mode 100644
index 0000000000000..9622311e100cb
--- /dev/null
+++ b/clang/test/AST/ByteCode/cxx14.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++14 -verify=both,expected %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++14 -verify=both,ref %s
+
+
+
+constexpr int(*null_ptr)() = nullptr;
+constexpr int test4 = (*null_ptr)(); // both-error {{must be initialized by a constant expression}} \
+ // both-note {{evaluates to a null function pointer}}
+
More information about the cfe-commits
mailing list