[llvm] r186044 - Don't assert if we can't constant fold extract/insertvalue

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 16:03:57 PDT 2015


Ping

On Fri, Aug 21, 2015 at 1:51 PM, David Blaikie <dblaikie at gmail.com> wrote:

> Ping
>
> On Wed, May 20, 2015 at 11:35 AM, David Blaikie <dblaikie at gmail.com>
> wrote:
>
>>
>>
>> On Wed, Jul 10, 2013 at 3:51 PM, Hal Finkel <hfinkel at anl.gov> wrote:
>>
>>> Author: hfinkel
>>> Date: Wed Jul 10 17:51:01 2013
>>> New Revision: 186044
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=186044&view=rev
>>> Log:
>>> Don't assert if we can't constant fold extract/insertvalue
>>>
>>> A non-constant-foldable static initializer expression containing
>>> insertvalue or
>>> extractvalue had been causing an assert:
>>>
>>>   Constants.cpp:1971: Assertion `FC && "ExtractValue constant expr
>>> couldn't be
>>>                                  folded!"' failed.
>>>
>>> Now we report a more-sensible "Unsupported expression in static
>>> initializer"
>>> error instead.
>>>
>>> Fixes PR15417.
>>>
>>> Added:
>>>     llvm/trunk/test/Other/nonconst-static-ev.ll
>>>     llvm/trunk/test/Other/nonconst-static-iv.ll
>>>
>>
>> *casts Necromancy*
>>
>> So in case it interests you, these .ll files crash llvm-as.
>>
>> $ ninja llvm-as && ./bin/llvm-as
>> ../../../../../../src/test/CodeGen/X86/nonconst-static-iv.ll -o /dev/null
>> ninja: no work to do.
>> Unknown binary instruction!
>> UNREACHABLE executed at lib/Bitcode/Writer/BitcodeWriter.cpp:84!
>> #0 0x7cce3e llvm::sys::PrintStackTrace(llvm::raw_ostream&)
>> lib/Support/Unix/Signals.inc:436:15
>> #1 0x7cdd89 PrintStackTraceSignalHandler(void*)
>> lib/Support/Unix/Signals.inc:495:1
>> #2 0x7ce069 SignalHandler(int) lib/Support/Unix/Signals.inc:210:62
>> #3 0x7fc2ba2e6340 __restore_rt
>> (/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)
>> #4 0x7fc2b9a28cc9 gsignal
>> /build/buildd/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
>> #5 0x7fc2b9a2c0d8 abort /build/buildd/eglibc-2.19/stdlib/abort.c:91:0
>> #6 0x78dad0 LLVMInstallFatalErrorHandler
>> lib/Support/ErrorHandling.cpp:132:0
>> #7 0x4725cc GetEncodedBinaryOpcode(unsigned int)
>> lib/Bitcode/Writer/BitcodeWriter.cpp:86:27
>> #8 0x47184b WriteConstants(unsigned int, unsigned int,
>> llvm::ValueEnumerator const&, llvm::BitstreamWriter&, bool)
>> lib/Bitcode/Writer/BitcodeWriter.cpp:1530:28
>> #9 0x46e3db WriteModuleConstants(llvm::ValueEnumerator const&,
>> llvm::BitstreamWriter&) lib/Bitcode/Writer/BitcodeWriter.cpp:1621:7
>> #10 0x469ecf WriteModule(llvm::Module const*, llvm::BitstreamWriter&,
>> bool) lib/Bitcode/Writer/BitcodeWriter.cpp:2360:3
>> #11 0x469d37 llvm::WriteBitcodeToFile(llvm::Module const*,
>> llvm::raw_ostream&, bool) lib/Bitcode/Writer/BitcodeWriter.cpp:2482:5
>> #12 0x406a27 WriteOutputFile(llvm::Module const*)
>> llvm/src/tools/llvm-as/llvm-as.cpp:80:5
>> #13 0x406752 main llvm/src/tools/llvm-as/llvm-as.cpp:118:3
>> #14 0x7fc2b9a13ec5 __libc_start_main
>> /build/buildd/eglibc-2.19/csu/libc-start.c:321:0
>> #15 0x4063e4 _start
>> (/mnt/fast/dev/llvm/build/clang/debug/split/notypes/nostandalone/bin/llvm-as+0x4063e4)
>> Stack dump:
>> 0.      Program arguments: ./bin/llvm-as
>> ../../../../../../src/test/CodeGen/X86/nonconst-static-iv.ll -o /dev/null
>> Aborted
>>
>>
>>> Modified:
>>>     llvm/trunk/lib/IR/Constants.cpp
>>>
>>> Modified: llvm/trunk/lib/IR/Constants.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=186044&r1=186043&r2=186044&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/lib/IR/Constants.cpp (original)
>>> +++ llvm/trunk/lib/IR/Constants.cpp Wed Jul 10 17:51:01 2013
>>> @@ -1954,14 +1954,22 @@ Constant *ConstantExpr::getShuffleVector
>>>
>>>  Constant *ConstantExpr::getInsertValue(Constant *Agg, Constant *Val,
>>>                                         ArrayRef<unsigned> Idxs) {
>>> +  assert(Agg->getType()->isFirstClassType() &&
>>> +         "Non-first-class type for constant insertvalue expression");
>>> +
>>>    assert(ExtractValueInst::getIndexedType(Agg->getType(),
>>>                                            Idxs) == Val->getType() &&
>>>           "insertvalue indices invalid!");
>>> -  assert(Agg->getType()->isFirstClassType() &&
>>> -         "Non-first-class type for constant insertvalue expression");
>>> -  Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs);
>>> -  assert(FC && "insertvalue constant expr couldn't be folded!");
>>> -  return FC;
>>> +  Type *ReqTy = Val->getType();
>>> +
>>> +  if (Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs))
>>> +    return FC;
>>> +
>>> +  Constant *ArgVec[] = { Agg, Val };
>>> +  const ExprMapKeyType Key(Instruction::InsertValue, ArgVec, 0, 0,
>>> Idxs);
>>> +
>>> +  LLVMContextImpl *pImpl = Agg->getContext().pImpl;
>>> +  return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
>>>  }
>>>
>>>  Constant *ConstantExpr::getExtractValue(Constant *Agg,
>>> @@ -1975,9 +1983,14 @@ Constant *ConstantExpr::getExtractValue(
>>>
>>>    assert(Agg->getType()->isFirstClassType() &&
>>>           "Non-first-class type for constant extractvalue expression");
>>> -  Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs);
>>> -  assert(FC && "ExtractValue constant expr couldn't be folded!");
>>> -  return FC;
>>> +  if (Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs))
>>> +    return FC;
>>> +
>>> +  Constant *ArgVec[] = { Agg };
>>> +  const ExprMapKeyType Key(Instruction::ExtractValue, ArgVec, 0, 0,
>>> Idxs);
>>> +
>>> +  LLVMContextImpl *pImpl = Agg->getContext().pImpl;
>>> +  return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
>>>  }
>>>
>>>  Constant *ConstantExpr::getNeg(Constant *C, bool HasNUW, bool HasNSW) {
>>>
>>> Added: llvm/trunk/test/Other/nonconst-static-ev.ll
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/nonconst-static-ev.ll?rev=186044&view=auto
>>>
>>> ==============================================================================
>>> --- llvm/trunk/test/Other/nonconst-static-ev.ll (added)
>>> +++ llvm/trunk/test/Other/nonconst-static-ev.ll Wed Jul 10 17:51:01 2013
>>> @@ -0,0 +1,8 @@
>>> +; RUN: not llc < %s 2> %t
>>> +; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s
>>> +
>>> + at 0 = global i8 extractvalue ([1 x i8] select (i1 ptrtoint (i32* @1 to
>>> i1), [1 x i8] [ i8 1 ], [1 x i8] [ i8 2 ]), 0)
>>> + at 1 = external global i32
>>> +
>>> +; CHECK-ERRORS: Unsupported expression in static initializer:
>>> extractvalue
>>> +
>>>
>>> Added: llvm/trunk/test/Other/nonconst-static-iv.ll
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/nonconst-static-iv.ll?rev=186044&view=auto
>>>
>>> ==============================================================================
>>> --- llvm/trunk/test/Other/nonconst-static-iv.ll (added)
>>> +++ llvm/trunk/test/Other/nonconst-static-iv.ll Wed Jul 10 17:51:01 2013
>>> @@ -0,0 +1,8 @@
>>> +; RUN: not llc < %s 2> %t
>>> +; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s
>>> +
>>> + at 0 = global i8 insertvalue( { i8 } select (i1 ptrtoint (i32* @1 to i1),
>>> { i8 } { i8 1 }, { i8 } { i8 2 }), i8 0, 0)
>>> + at 1 = external global i32
>>> +
>>> +; CHECK-ERRORS: Unsupported expression in static initializer:
>>> insertvalue
>>> +
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150917/1c3f019e/attachment.html>


More information about the llvm-commits mailing list