r223852 - AST: Don't assume two zero sized objects live at different addresses
David Majnemer
david.majnemer at gmail.com
Thu Dec 11 11:37:55 PST 2014
Should be fixed with r224040.
On Thu, Dec 11, 2014 at 3:34 AM, Will Wilson <will at indefiant.com> wrote:
> Hi David,
>
> Looks like r223852 might be responsible for the following failure I just
> ran into:
>
> Assertion failed: (D && "Cannot get layout of forward declarations!"),
> function getASTRecordLayout, file clang/lib/AST/RecordLayoutBuilder.cpp,
> line 2806.
>
> 0 clang 0x0000000102d14bee
> llvm::sys::PrintStackTrace(__sFILE*) + 46
> 1 clang 0x0000000102d15f9b
> PrintStackTraceSignalHandler(void*) + 27
> 2 clang 0x0000000102d163e5 SignalHandler(int) + 565
> 3 libsystem_platform.dylib 0x00007fff8e013f1a _sigtramp + 26
> 4 clang 0x00000001061d3dff guard variable for
> isAllowedIDChar(unsigned int, clang::LangOptions const&)::C99AllowedIDChars
> + 144135
> 5 clang 0x0000000102d15fcb raise + 27
> 6 clang 0x0000000102d16082 abort + 18
> 7 clang 0x0000000102d16061 __assert_rtn + 129
> 8 clang 0x000000010558eecd
> clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const + 285
> 9 clang 0x00000001052345e7
> clang::ASTContext::getTypeInfoImpl(clang::Type const*) const + 4951
> 10 clang 0x00000001052331b5
> clang::ASTContext::getTypeInfo(clang::Type const*) const + 165
> 11 clang 0x00000001052a504c
> clang::ASTContext::getTypeInfo(clang::QualType) const + 44
> 12 clang 0x00000001052acfe5
> clang::ASTContext::getTypeSize(clang::QualType) const + 37
> *13 clang 0x0000000105519b51 isZeroSized((anonymous
> namespace)::LValue const&) + 113*
> 14 clang 0x00000001054d610e (anonymous
> namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator
> const*) + 4590
> 15 clang 0x00000001054d3f08
> clang::StmtVisitorBase<clang::make_const_ptr, (anonymous
> namespace)::IntExprEvaluator, bool>::VisitBinNE(clang::BinaryOperator
> const*) + 40
> 16 clang 0x00000001054d2240
> clang::StmtVisitorBase<clang::make_const_ptr, (anonymous
> namespace)::IntExprEvaluator, bool>::Visit(clang::Stmt const*) + 528
> 17 clang 0x00000001054cc232 Evaluate(clang::APValue&,
> (anonymous namespace)::EvalInfo&, clang::Expr const*) + 450
> 18 clang 0x00000001054c81b1 EvaluateAsRValue((anonymous
> namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) + 177
> 19 clang 0x00000001054c7e1e
> clang::Expr::EvaluateAsRValue(clang::Expr::EvalResult&, clang::ASTContext
> const&) const + 190
> 20 clang 0x0000000104844cf3
> clang::Sema::VerifyIntegerConstantExpression(clang::Expr*, llvm::APSInt*,
> clang::Sema::VerifyICEDiagnoser&, bool) + 931
> 21 clang 0x00000001048425c8
> clang::Sema::VerifyIntegerConstantExpression(clang::Expr*, llvm::APSInt*,
> unsigned int, bool) + 120
> 22 clang 0x0000000104737c01
> clang::Sema::BuildStaticAssertDeclaration(clang::SourceLocation,
> clang::Expr*, clang::StringLiteral*, clang::SourceLocation, bool) + 369
> 23 clang 0x0000000104737a74
> clang::Sema::ActOnStaticAssertDeclaration(clang::SourceLocation,
> clang::Expr*, clang::Expr*, clang::SourceLocation) + 180
> 24 clang 0x00000001042dcb5c
> clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&) + 1564
> 25 clang 0x00000001042c0614
> clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&,
> clang::Parser::ParsedAttributesWithRange&) + 852
> 26 clang 0x000000010435b003
> clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
> clang::ParsingDeclSpec*) + 2403
> 27 clang 0x000000010435a655
> clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) +
> 773
> 28 clang 0x00000001042b1d8c
> clang::ParseAST(clang::Sema&, bool, bool) + 988
> 29 clang 0x00000001031db9fa
> clang::ASTFrontendAction::ExecuteAction() + 522
> 30 clang 0x00000001037b80d3
> clang::CodeGenAction::ExecuteAction() + 3939
> 31 clang 0x00000001031daf78
> clang::FrontendAction::Execute() + 120
> 32 clang 0x000000010316cbf9
> clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1017
> 33 clang 0x000000010324c5f1
> clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3201
> 34 clang 0x0000000101373930
> cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2496
>
> Repro:
>
> struct Foo;
> struct Bar
> {
> static const Foo ms_struct;
> };
> static_assert(&Bar:: ms_struct != nullptr, "fail");
>
> Will.
>
> On 10 December 2014 at 09:32, David Majnemer <david.majnemer at gmail.com>
> wrote:
>
>> Author: majnemer
>> Date: Tue Dec 9 17:32:34 2014
>> New Revision: 223852
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=223852&view=rev
>> Log:
>> AST: Don't assume two zero sized objects live at different addresses
>>
>> Zero sized objects may overlap with each other or any other object.
>>
>> This fixes PR21786.
>>
>> Modified:
>> cfe/trunk/lib/AST/ExprConstant.cpp
>> cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
>>
>> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=223852&r1=223851&r2=223852&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
>> +++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Dec 9 17:32:34 2014
>> @@ -1422,6 +1422,12 @@ static bool IsWeakLValue(const LValue &V
>> return Decl && Decl->isWeak();
>> }
>>
>> +static bool isZeroSized(const LValue &Value) {
>> + const ValueDecl *Decl = GetLValueBaseDecl(Value);
>> + return Decl && isa<VarDecl>(Decl) &&
>> + Decl->getASTContext().getTypeSize(Decl->getType()) == 0;
>> +}
>> +
>> static bool EvalPointerValueAsBool(const APValue &Value, bool &Result) {
>> // A null base expression indicates a null pointer. These are always
>> // evaluatable, and they are false unless the offset is zero.
>> @@ -6979,6 +6985,10 @@ bool IntExprEvaluator::VisitBinaryOperat
>> (RHSValue.Base && RHSValue.Offset.isZero() &&
>> isOnePastTheEndOfCompleteObject(Info.Ctx, LHSValue)))
>> return Error(E);
>> + // We can't tell whether an object is at the same address as
>> another
>> + // zero sized object.
>> + if (isZeroSized(LHSValue) || isZeroSized(RHSValue))
>> + return Error(E);
>> // Pointers with different bases cannot represent the same
>> object.
>> // (Note that clang defaults to -fmerge-all-constants, which can
>> // lead to inconsistent results for comparisons involving the
>> address
>>
>> Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=223852&r1=223851&r2=223852&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Tue Dec 9
>> 17:32:34 2014
>> @@ -1955,3 +1955,9 @@ namespace EmptyClass {
>> constexpr E2 e2b(e2); // expected-error {{constant expression}}
>> expected-note{{read of non-const}} expected-note {{in call}}
>> constexpr E3 e3b(e3);
>> }
>> +
>> +namespace PR21786 {
>> + extern void (*start[])();
>> + extern void (*end[])();
>> + static_assert(&start != &end, ""); // expected-error {{constant
>> expression}}
>> +}
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
>
> --
> *Indefiant *: http://www.indefiant.com
> Home of Recode : Runtime C++ Editing for VS
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141211/bdeea43b/attachment.html>
More information about the cfe-commits
mailing list