[cfe-commits] r151879 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/const-init-cxx11.cpp

Daniel Dunbar daniel at zuster.org
Fri Mar 2 08:24:18 PST 2012


Testcase here:
  http://minormatter.com/~ddunbar/files/t.ii)
if you need it (may be darwin specific).

Repro:
--
ddunbar at lordcrumb:tmp$ curl -s -O http://minormatter.com/~ddunbar/files/t.ii
ddunbar at lordcrumb:tmp$ ~/llvm.obj.64/Debug+Asserts/bin/clang -c t.ii
Assertion failed: (CastInst::castIsValid(opc, C, Ty) && "Invalid
constantexpr cast!"), function getCast, file
/Volumes/Data/ddunbar/llvm/lib/VMCore/Constants.cpp, line 1366.
0  clang             0x000000010213aa3e PrintStackTrace(void*) + 46
1  clang             0x000000010213afe9 SignalHandler(int) + 297
2  libSystem.B.dylib 0x00007fff8a3091ba _sigtramp + 26
3  libSystem.B.dylib 0x0000000106591c80 _sigtramp + 2083031776
4  clang             0x000000010213ad0b raise + 27
5  clang             0x000000010213adc2 abort + 18
6  clang             0x000000010213ada1 __assert_rtn + 129
7  clang             0x0000000101f9ffaf
llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*,
llvm::Type*) + 303
8  clang             0x0000000101bcc227
llvm::ConstantFolder::CreateCast(llvm::Instruction::CastOps,
llvm::Constant*, llvm::Type*) const + 39
9  clang             0x0000000101bcc17b llvm::IRBuilder<true,
llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true>
>::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*,
llvm::Twine const&) + 123
10 clang             0x0000000101c6d3a4 llvm::IRBuilder<true,
llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true>
>::CreateBitCast(llvm::Value*, llvm::Type*, llvm::Twine const&) + 52
11 clang             0x000000010023d688
clang::CodeGen::CodeGenFunction::EmitCall(clang::CodeGen::CGFunctionInfo
const&, llvm::Value*, clang::CodeGen::ReturnValueSlot,
clang::CodeGen::CallArgList const&, clang::Decl const*,
llvm::Instruction**) + 2360
12 clang             0x00000001002a2e92
clang::CodeGen::CodeGenFunction::EmitCXXMemberCall(clang::CXXMethodDecl
const*, llvm::Value*, clang::CodeGen::ReturnValueSlot, llvm::Value*,
llvm::Value*, clang::ConstExprIterator, clang::ConstExprIterator) +
786
13 clang             0x0000000100247b40
clang::CodeGen::CodeGenFunction::EmitCXXConstructorCall(clang::CXXConstructorDecl
const*, clang::CXXCtorType, bool, llvm::Value*,
clang::ConstExprIterator, clang::ConstExprIterator) + 960
14 clang             0x00000001002a4635
clang::CodeGen::CodeGenFunction::EmitCXXConstructExpr(clang::CXXConstructExpr
const*, clang::CodeGen::AggValueSlot) + 1253
15 clang             0x000000010029c5a0 (anonymous
namespace)::AggExprEmitter::VisitCXXConstructExpr(clang::CXXConstructExpr
const*) + 96
16 clang             0x0000000100299782
clang::StmtVisitorBase<clang::make_ptr, (anonymous
namespace)::AggExprEmitter, void>::Visit(clang::Stmt*) + 1954
17 clang             0x0000000100298c30
clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*,
clang::CodeGen::AggValueSlot, bool) + 352
18 clang             0x0000000100244831
EmitAggMemberInitializer(clang::CodeGen::CodeGenFunction&,
clang::CodeGen::LValue, clang::Expr*, llvm::Value*, clang::QualType,
llvm::ArrayRef<clang::VarDecl*>, unsigned int) + 1265
19 clang             0x0000000100244249
clang::CodeGen::CodeGenFunction::EmitInitializerForField(clang::FieldDecl*,
clang::CodeGen::LValue, clang::Expr*, llvm::ArrayRef<clang::VarDecl*>)
+ 1449
20 clang             0x00000001002463b9
EmitMemberInitializer(clang::CodeGen::CodeGenFunction&,
clang::CXXRecordDecl const*, clang::CXXCtorInitializer*,
clang::CXXConstructorDecl const*, clang::CodeGen::FunctionArgList&) +
1369
21 clang             0x00000001002458a1
clang::CodeGen::CodeGenFunction::EmitCtorPrologue(clang::CXXConstructorDecl
const*, clang::CXXCtorType, clang::CodeGen::FunctionArgList&) + 513
22 clang             0x000000010024510f
clang::CodeGen::CodeGenFunction::EmitConstructorBody(clang::CodeGen::FunctionArgList&)
+ 367
23 clang             0x000000010034b5ae
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&) + 734
24 clang             0x00000001002323c4
clang::CodeGen::CodeGenModule::EmitCXXConstructor(clang::CXXConstructorDecl
const*, clang::CXXCtorType) + 308
25 clang             0x00000001003547d0
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl)
+ 288
26 clang             0x0000000100351e80
clang::CodeGen::CodeGenModule::EmitDeferred() + 464
27 clang             0x0000000100351b59
clang::CodeGen::CodeGenModule::Release() + 25
28 clang             0x0000000100398788 (anonymous
namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&)
+ 136
29 clang             0x00000001003470bf
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) +
143
30 clang             0x00000001003a9b44 clang::ParseAST(clang::Sema&,
bool) + 692
31 clang             0x000000010007b2c8
clang::ASTFrontendAction::ExecuteAction() + 264
32 clang             0x000000010034625b
clang::CodeGenAction::ExecuteAction() + 1051
33 clang             0x000000010007af17 clang::FrontendAction::Execute() + 231
34 clang             0x0000000100045105
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 821
35 clang             0x0000000100017ddf
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 943
36 clang             0x0000000100001a29 cc1_main(char const**, char
const**, char const*, void*) + 969
37 clang             0x0000000100011d09 main + 473
38 clang             0x0000000100001634 start + 52
Stack dump:
0.	Program arguments:
/Volumes/Data/ddunbar/llvm.obj.64/Debug+Asserts/bin/clang -cc1 -triple
x86_64-apple-macosx10.6.0 -emit-obj -mrelax-all -disable-free
-main-file-name t.ii -pic-level 1 -mdisable-fp-elim -masm-verbose
-munwind-tables -target-cpu core2 -coverage-file t.o -resource-dir
/Volumes/Data/ddunbar/llvm.obj.64/Debug+Asserts/bin/../lib/clang/3.1
-fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19
-fmessage-length 203 -stack-protector 1 -mstackrealign -fblocks
-fobjc-dispatch-method=mixed -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o t.o -x c++-cpp-output
t.ii
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
3.	/Volumes/Data/ddunbar/llvm/lib/Support/Debug.cpp:106:5: Generating
code for declaration 'llvm::dbgs()::dbgstream::dbgstream'
clang: error: unable to execute command: Illegal instruction
clang: error: clang frontend command failed due to signal (use -v to
see invocation)
clang: note: diagnostic msg: Please submit a bug report to
http://llvm.org/bugs/ and include command line arguments and all
diagnostic information.
clang: note: diagnostic msg: Error generating preprocessed source(s) -
no preprocessable inputs.
ddunbar at lordcrumb:tmp$
--

 - Daniel


On Fri, Mar 2, 2012 at 7:58 AM, Daniel Dunbar <daniel at zuster.org> wrote:
> Hi Richard,
>
> This broke bootstrap when building Debug.cpp. Can you investigate please?
>
> I will revert shortly...
>
>  - Daniel
>
> On Thu, Mar 1, 2012 at 7:16 PM, Richard Smith
> <richard-llvm at metafoo.co.uk> wrote:
>> Author: rsmith
>> Date: Thu Mar  1 21:16:32 2012
>> New Revision: 151879
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=151879&view=rev
>> Log:
>> PR12145: Avoid emitting loads of constexpr variables in contexts where there
>> is no odr-use of the variable. Go slightly beyond what the standard requires
>> for variables of reference type.
>>
>> Modified:
>>    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>>    cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=151879&r1=151878&r2=151879&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Mar  1 21:16:32 2012
>> @@ -212,18 +212,21 @@
>>   // l-values.
>>   Value *VisitDeclRefExpr(DeclRefExpr *E) {
>>     Expr::EvalResult Result;
>> -    if (!E->EvaluateAsRValue(Result, CGF.getContext()))
>> -      return EmitLoadOfLValue(E);
>> +    bool IsReferenceConstant = false;
>> +    QualType EvalTy = E->getType();
>> +    if (!E->EvaluateAsRValue(Result, CGF.getContext())) {
>> +      // If this is a reference, try to determine what it is bound to.
>> +      if (!E->getDecl()->getType()->isReferenceType() ||
>> +          !E->EvaluateAsLValue(Result, CGF.getContext()))
>> +        return EmitLoadOfLValue(E);
>> +
>> +      IsReferenceConstant = true;
>> +      EvalTy = E->getDecl()->getType();
>> +    }
>>
>>     assert(!Result.HasSideEffects && "Constant declref with side-effect?!");
>>
>> -    llvm::Constant *C;
>> -    if (Result.Val.isInt())
>> -      C = Builder.getInt(Result.Val.getInt());
>> -    else if (Result.Val.isFloat())
>> -      C = llvm::ConstantFP::get(VMContext, Result.Val.getFloat());
>> -    else
>> -      return EmitLoadOfLValue(E);
>> +    llvm::Constant *C = CGF.CGM.EmitConstantValue(Result.Val, EvalTy, &CGF);
>>
>>     // Make sure we emit a debug reference to the global variable.
>>     if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) {
>> @@ -233,6 +236,9 @@
>>       CGF.EmitDeclRefExprDbgValue(E, C);
>>     }
>>
>> +    if (IsReferenceConstant)
>> +      return EmitLoadOfLValue(CGF.MakeNaturalAlignAddrLValue(C, E->getType()));
>> +
>>     return C;
>>   }
>>   Value *VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
>>
>> Modified: cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp?rev=151879&r1=151878&r2=151879&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp Thu Mar  1 21:16:32 2012
>> @@ -337,3 +337,30 @@
>>   X<D> x;
>>   // CHECK: call {{.*}}@_ZN11VirtualBase1XINS_1DEEC1Ev
>>  }
>> +
>> +// PR12145
>> +namespace Unreferenced {
>> +  int n;
>> +  constexpr int *p = &n;
>> +  // We must not emit a load of 'p' here, since it's not odr-used.
>> +  int q = *p;
>> +  // CHECK-NOT: _ZN12Unreferenced1pE
>> +  // CHECK: %0 = load i32* @_ZN12Unreferenced1nE
>> +  // CHECK-NEXT: store i32 %0, i32* @_ZN12Unreferenced1qE
>> +  // CHECK-NOT: _ZN12Unreferenced1pE
>> +
>> +  // Technically, we are not required to substitute variables of reference types
>> +  // initialized by constant expressions, because the special case for odr-use
>> +  // of variables in [basic.def.odr]p2 only applies to objects. But we do so
>> +  // anyway.
>> +
>> +  constexpr int &r = n;
>> +  // CHECK-NOT: _ZN12Unreferenced1rE
>> +  int s = r;
>> +
>> +  const int t = 1;
>> +  const int &rt = t;
>> +  int f(int);
>> +  int u = f(rt);
>> +  // CHECK: call i32 @_ZN12Unreferenced1fEi(i32 1)
>> +}
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list