Skip to content

Conversation

@tbaederr
Copy link
Contributor

Diagnose them later when we try to call the function pointer.

Diagnose them later when we try to call the function pointer.
@tbaederr tbaederr added clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Oct 21, 2025
@tbaederr tbaederr marked this pull request as ready for review October 21, 2025 08:33
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Oct 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Diagnose them later when we try to call the function pointer.


Full diff: https://github.com/llvm/llvm-project/pull/164376.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Compiler.cpp (+1-1)
  • (added) clang/test/AST/ByteCode/cxx14.cpp (+9)
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}} + 
@tbaederr tbaederr merged commit c5f9a2a into llvm:main Oct 21, 2025
16 checks passed
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
…4376) Diagnose them later when we try to call the function pointer.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
…4376) Diagnose them later when we try to call the function pointer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

2 participants