[llvm] 9cbab13 - [ConstantsTest] Avoid crash with opaque pointers

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 13 06:23:20 PST 2021


Author: Nikita Popov
Date: 2021-12-13T15:23:12+01:00
New Revision: 9cbab13282fe59885b6f9c2411eddbdd452c36e7

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

LOG: [ConstantsTest] Avoid crash with opaque pointers

With opaque pointers there will be no bitcast, so don't assume
that.

Added: 
    

Modified: 
    llvm/unittests/IR/ConstantsTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp
index 061b633c32e21..155383d5a0c63 100644
--- a/llvm/unittests/IR/ConstantsTest.cpp
+++ b/llvm/unittests/IR/ConstantsTest.cpp
@@ -482,7 +482,12 @@ TEST(ConstantsTest, BitcastToGEP) {
       new GlobalVariable(*M, S, false, GlobalValue::ExternalLinkage, nullptr);
   auto *PtrTy = PointerType::get(i32, 0);
   auto *C = ConstantExpr::getBitCast(G, PtrTy);
-  ASSERT_EQ(cast<ConstantExpr>(C)->getOpcode(), Instruction::BitCast);
+  if (Context.supportsTypedPointers()) {
+    EXPECT_EQ(cast<ConstantExpr>(C)->getOpcode(), Instruction::BitCast);
+  } else {
+    /* With opaque pointers, no cast is necessary. */
+    EXPECT_EQ(C, G);
+  }
 }
 
 bool foldFuncPtrAndConstToNull(LLVMContext &Context, Module *TheModule,


        


More information about the llvm-commits mailing list