[LLVMbugs] [Bug 20558] New: [AArch64] Assertion when lowering LOAD_STACK_GUARD

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Aug 5 18:19:40 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20558

            Bug ID: 20558
           Summary: [AArch64] Assertion when lowering LOAD_STACK_GUARD
           Product: tools
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: llvmc
          Assignee: unassignedbugs at nondot.org
          Reporter: apazos at codeaurora.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 12859
  --> http://llvm.org/bugs/attachment.cgi?id=12859&action=edit
Fix assertion when lowering LOAD-STACK-GUARD

Hi Akira,

We hit an assertion in expandPostRAPseudo when lowering LOAD_STACK_GUARD.

The call to cast<GlobalValue> asserts with

/llvm/include/llvm/Support/Casting.h:237: typename llvm::cast_retty<X,
Y*>::ret_type llvm::cast(Y*) [with X = llvm::GlobalValue; Y = const
llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type = const
llvm::GlobalValue*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of
incompatible type!"' failed.

The memory operand expected in the exapandPostRAPseudo is a GlobalValue but
instead in the failing test case we have a ConstantExpr.

I tried to get a simplified test case that reproduces the issue. Here it is:

define i32  @test_stack_guard_remat2() {
entry:
  %StackGuardSlot = alloca i8*
  %StackGuard = load i8** bitcast ([0 x i32]* @__stack_chk_guard to i8**)
  call void @llvm.stackprotector(i8* %StackGuard, i8** %StackGuardSlot)
  %container = alloca [32 x i8], align 1
  call void @llvm.stackprotectorcheck(i8** bitcast ([0 x i32]*
@__stack_chk_guard to i8**))
  ret i32 -1
}

I also tried to fix the issue. See the patch below.

--- a/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -901,8 +901,12 @@
AArch64InstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const {
   MachineBasicBlock &MBB = *MI->getParent();
   DebugLoc DL = MI->getDebugLoc();
   unsigned Reg = MI->getOperand(0).getReg();
-  const GlobalValue *GV =
-      cast<GlobalValue>((*MI->memoperands_begin())->getValue());
+  const GlobalValue *GV = nullptr;
+
+  const Value *Val = (*MI->memoperands_begin())->getValue();
+  if (const ConstantExpr *CE = dyn_cast<const ConstantExpr>(Val))
+    Val = CE->getOperand(0);
+  GV = cast<GlobalValue>(Val);
   const TargetMachine &TM = MBB.getParent()->getTarget();
   unsigned char OpFlags = Subtarget.ClassifyGlobalReference(GV, TM);
   const unsigned char MO_NC = AArch64II::MO_NC;


Let me know what you think.

Thanks,
Ana.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140806/9bef0761/attachment.html>


More information about the llvm-bugs mailing list