[PATCH] D141591: [clang][Interp] Properly identify not-yet-defined functions

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 13 08:05:07 PST 2023


tbaeder updated this revision to Diff 489020.
tbaeder added a comment.

Just get the information whether the `Function` has a body directly from the `FunctionDecl`. This fixes referencing member functions that are defined later.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141591/new/

https://reviews.llvm.org/D141591

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Function.h
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===================================================================
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -154,3 +154,21 @@
 }
 
 }
+
+struct F {
+  constexpr bool ok() const {
+    return okRecurse();
+  }
+  constexpr bool okRecurse() const {
+    return true;
+  }
+};
+
+struct BodylessMemberFunction {
+  constexpr int first() const {
+    return second();
+  }
+  constexpr int second() const {
+    return 1;
+  }
+};
Index: clang/lib/AST/Interp/Function.h
===================================================================
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -150,14 +150,15 @@
            bool HasThisPointer, bool HasRVO);
 
   /// Sets the code of a function.
-  void setCode(unsigned NewFrameSize, std::vector<char> &&NewCode, SourceMap &&NewSrcMap,
-               llvm::SmallVector<Scope, 2> &&NewScopes) {
+  void setCode(unsigned NewFrameSize, std::vector<char> &&NewCode,
+               SourceMap &&NewSrcMap, llvm::SmallVector<Scope, 2> &&NewScopes,
+               bool NewHasBody) {
     FrameSize = NewFrameSize;
     Code = std::move(NewCode);
     SrcMap = std::move(NewSrcMap);
     Scopes = std::move(NewScopes);
     IsValid = true;
-    HasBody = true;
+    HasBody = NewHasBody;
   }
 
   void setIsFullyCompiled(bool FC) { IsFullyCompiled = FC; }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1483,7 +1483,7 @@
   assert(FD);
   const Function *Func = P.getFunction(FD);
   bool IsBeingCompiled = Func && !Func->isFullyCompiled();
-  bool WasNotDefined = Func && !Func->hasBody();
+  bool WasNotDefined = Func && !Func->isConstexpr() && !Func->hasBody();
 
   if (IsBeingCompiled)
     return Func;
Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -91,7 +91,7 @@
 
     // Set the function's code.
     Func->setCode(NextLocalOffset, std::move(Code), std::move(SrcMap),
-                  std::move(Scopes));
+                  std::move(Scopes), FuncDecl->hasBody());
     Func->setIsFullyCompiled(true);
     return Func;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141591.489020.patch
Type: text/x-patch
Size: 2411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230113/0505843a/attachment.bin>


More information about the cfe-commits mailing list