[PATCH] D38656: [CGExprScalar] In EmitCompare trunc the result if it has different type as E->getType()

David Majnemer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 9 09:23:37 PDT 2017


majnemer added inline comments.


================
Comment at: lib/CodeGen/CGExprScalar.cpp:3223-3224
+      // crash later.
+      llvm::IntegerType *ResultTy =
+                         dyn_cast<llvm::IntegerType>(Result->getType());
+      if ((ResultTy->getBitWidth() > 1) &&
----------------
Is this clang-format'd ?


================
Comment at: lib/CodeGen/CGExprScalar.cpp:3224
+      llvm::IntegerType *ResultTy =
+                         dyn_cast<llvm::IntegerType>(Result->getType());
+      if ((ResultTy->getBitWidth() > 1) &&
----------------
You are unconditionally dereferencing the result of a dyn_cast. You are either missing a null-check or this should be a cast<>


================
Comment at: lib/CodeGen/CGExprScalar.cpp:3225-3226
+                         dyn_cast<llvm::IntegerType>(Result->getType());
+      if ((ResultTy->getBitWidth() > 1) &&
+          (E->getType() == CGF.getContext().BoolTy))
+        Result = Builder.CreateTrunc(Result, Builder.getInt1Ty());
----------------
Extra parens.


https://reviews.llvm.org/D38656





More information about the cfe-commits mailing list