This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG744a968f91f7: [clang][Interp] Fix return statements with 
expresssion in void functions (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D153649?vs=534021&id=544274#toc

Repository:
  rG LLVM Github Monorepo

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

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
@@ -291,3 +291,12 @@
                                  // ref-note {{read of variable whose lifetime 
has ended}} \
                                  // expected-error {{not an integral constant 
expression}}
 }
+
+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))


Index: clang/test/AST/Interp/functions.cpp
===================================================================
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -291,3 +291,12 @@
                                  // ref-note {{read of variable whose lifetime has ended}} \
                                  // expected-error {{not an integral constant expression}}
 }
+
+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))
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to