[PATCH] D153649: [clang][Interp] Fix return statements with expresssion in void functions

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 23 10:48:26 PDT 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  If the return type of a function is void, ReturnType is not set, but we
  used to emit a RVOPtr instruction, which doesn't make sense for a
  function returning void.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153649

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  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
@@ -265,3 +265,12 @@
     g(0);
   }
 }
+
+namespace VoidReturn {
+  /// ReturnStmt with an expression in a void function used to cause problems.
+  constexpr void bar() {}
+  constexpr void foo() {
+    return bar();
+  }
+  static_assert((foo(),1) == 1);
+}
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -309,6 +309,9 @@
         return false;
       this->emitCleanup();
       return this->emitRet(*ReturnType, RS);
+    } else if (RE->getType()->isVoidType()) {
+      if (!this->visit(RE))
+        return false;
     } else {
       // RVO - construct the value in the return location.
       if (!this->emitRVOPtr(RE))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153649.534014.patch
Type: text/x-patch
Size: 981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230623/ace4de88/attachment.bin>


More information about the cfe-commits mailing list