[clang] b44763c - [clang][Interp] Fix scalar inits of void type (#69868)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 24 00:18:45 PDT 2023


Author: Timm Baeder
Date: 2023-10-24T09:18:39+02:00
New Revision: b44763c5e690ddb61941ad56fb12f46e723b8071

URL: https://github.com/llvm/llvm-project/commit/b44763c5e690ddb61941ad56fb12f46e723b8071
DIFF: https://github.com/llvm/llvm-project/commit/b44763c5e690ddb61941ad56fb12f46e723b8071.diff

LOG: [clang][Interp] Fix scalar inits of void type (#69868)

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/AST/Interp/literals.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d3e0d1112935a98..eb96f021258b114 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1597,8 +1597,12 @@ bool ByteCodeExprGen<Emitter>::VisitOffsetOfExpr(const OffsetOfExpr *E) {
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitCXXScalarValueInitExpr(
     const CXXScalarValueInitExpr *E) {
-  return this->visitZeroInitializer(classifyPrim(E->getType()), E->getType(),
-                                    E);
+  QualType Ty = E->getType();
+
+  if (Ty->isVoidType())
+    return true;
+
+  return this->visitZeroInitializer(classifyPrim(Ty), Ty, E);
 }
 
 template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {

diff  --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index 6e8927518355dae..ba24955d14503be 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -56,6 +56,15 @@ namespace ScalarTypes {
   };
   static_assert(getScalar<E>() == First, "");
   /// FIXME: Member pointers.
+
+#if __cplusplus >= 201402L
+  constexpr void Void(int n) {
+    void(n + 1);
+    void();
+  }
+  constexpr int void_test = (Void(0), 1);
+  static_assert(void_test == 1, "");
+#endif
 }
 
 namespace IntegralCasts {


        


More information about the cfe-commits mailing list