[clang] 8aea6e0 - [clang][Interp][NFC] Take a QualType in visitZeroInitializer()

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 24 08:58:25 PDT 2023


Author: Timm Bäder
Date: 2023-04-24T17:58:15+02:00
New Revision: 8aea6e004fd2edafbdee2d3d13571ab5eace004e

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

LOG: [clang][Interp][NFC] Take a QualType in visitZeroInitializer()

The given expression is not necessarily usable to obtain a type for,
so we can't use it to get the floating point semantics. Pass a QualType
instead, which we can use--and classify() that here.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/lib/AST/Interp/ByteCodeExprGen.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a8e8b2997ddef..e28532b288871 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -390,7 +390,7 @@ bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueIni
   if (!T)
     return false;
 
-  return this->visitZeroInitializer(*T, E);
+  return this->visitZeroInitializer(E->getType(), E);
 }
 
 template <class Emitter>
@@ -929,7 +929,12 @@ bool ByteCodeExprGen<Emitter>::visitConditional(
 }
 
 template <class Emitter>
-bool ByteCodeExprGen<Emitter>::visitZeroInitializer(PrimType T, const Expr *E) {
+bool ByteCodeExprGen<Emitter>::visitZeroInitializer(QualType QT,
+                                                    const Expr *E) {
+  // FIXME: We need the QualType to get the float semantics, but that means we
+  //   classify it over and over again in array situations.
+  PrimType T = classifyPrim(QT);
+
   switch (T) {
   case PT_Bool:
     return this->emitZeroBool(E);
@@ -954,8 +959,7 @@ bool ByteCodeExprGen<Emitter>::visitZeroInitializer(PrimType T, const Expr *E) {
   case PT_FnPtr:
     return this->emitNullFnPtr(E);
   case PT_Float: {
-    return this->emitConstFloat(
-        APFloat::getZero(Ctx.getFloatSemantics(E->getType())), E);
+    return this->emitConstFloat(APFloat::getZero(Ctx.getFloatSemantics(QT)), E);
   }
   }
   llvm_unreachable("unknown primitive type");

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 85588c6ecd3c1..a3aab16c4a083 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -201,7 +201,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
   friend class ArrayIndexScope<Emitter>;
 
   /// Emits a zero initializer.
-  bool visitZeroInitializer(PrimType T, const Expr *E);
+  bool visitZeroInitializer(QualType QT, const Expr *E);
 
   enum class DerefKind {
     /// Value is read and pushed to stack.


        


More information about the cfe-commits mailing list