[clang] [clang][bytecode] Implement Pointer::getType() for function pointers (PR #154788)

via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 21 09:12:31 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Fixes #<!-- -->152920

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Pointer.h (+2) 
- (modified) clang/test/AST/ByteCode/functions.cpp (+5) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index f310c8a7b66be..0ce54ab0a17df 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -341,6 +341,8 @@ class Pointer {
   QualType getType() const {
     if (isTypeidPointer())
       return QualType(Typeid.TypeInfoType, 0);
+    if (isFunctionPointer())
+      return asFunctionPointer().getFunction()->getDecl()->getType();
 
     if (inPrimitiveArray() && Offset != asBlockPointer().Base) {
       // Unfortunately, complex and vector types are not array types in clang,
diff --git a/clang/test/AST/ByteCode/functions.cpp b/clang/test/AST/ByteCode/functions.cpp
index 4f090842510e0..01bf0a55bd19a 100644
--- a/clang/test/AST/ByteCode/functions.cpp
+++ b/clang/test/AST/ByteCode/functions.cpp
@@ -732,3 +732,8 @@ namespace LocalVarForParmVarDecl {
   }
   static_assert(foo(), "");
 }
+
+namespace PtrPtrCast {
+  void foo() { ; }
+  void bar(int *a) { a = (int *)(void *)(foo); }
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/154788


More information about the cfe-commits mailing list