[cfe-commits] [patch] (Was: Assertion failure on invalid code.)

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Jan 8 10:28:30 PST 2013


On Jan 8, 2013, at 5:26 AM, Enea Zaffanella <zaffanella at cs.unipr.it> wrote:

> On 01/06/2013 06:49 PM, Enea Zaffanella wrote:
>> Hello.
>> 
>> clang is crashing, in debug mode, on invalid code such as the following
>> (distilled from a gcc testcase):
>> ======================
>> template <class>
>> void foo() {
>>   (struct S {}*) 0;
>> }
>> 
>> void bar() {
>>   foo<int>();
>> }
>> ======================
>> 
>> $ clang++ -c bug.cc
>> bug.cc:3:11: error: 'S' can not be defined in a type specifier
>>   (struct S {}*) 0;
>>           ^
>> clang: SemaTemplateInstantiate.cpp:2691:
>> llvm::PointerUnion<clang::Decl*, llvm::SmallVector<clang::Decl*, 4u>*>*
>> clang::LocalInstantiationScope::findInstantiationOf(const clang::Decl*):
>> Assertion `isa<LabelDecl>(D) && "declaration not instantiated in this
>> scope"' failed.
>> 
>> The problem seems to be that, after emitting the error diagnostics for
>> the template, the code is kept as valid code in the AST; hence it later
>> causes a crash when instantiating the template.
> 
> Please find attached a patch fixing the crash mentioned above.
> The patch includes minor changes to 3 tests, where (as expected) we no longer get further diagnostics on the code already marked as invalid.

Could you also add a test case for the crash ?

> 
> OK to commit?
> 
> Enea.
> 
> <CrashFix.patch>_______________________________________________
> 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