llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

parser crash involving isConstantExpr() on incorrect code

Open tkremenek opened this issue 18 years ago • 1 comments

Bugzilla Link 1863
Resolution FIXED
Resolved on Mar 12, 2010 00:56
Version unspecified
OS MacOS X

Extended Description

The following (incorrect) code breaks the parser:

int foo();

int test() {} typedef int x[foo()]; int y = sizeof(x); int z = sizeof(int[foo()]); return y + z; }

from gdb:

(gdb) r Starting program: /Volumes/Data/Users/kremenek/llvm/Debug/bin/clang /tmp/t4.c Reading symbols for shared libraries ++++. done /tmp/t4.c:4:15: error: variable length array declared outside of any function typedef int x[foo()]; ^ ~~~~~ Assertion failed: (loc.isValid() && "isConstantExpr didn't return a loc!"), function CheckSingleInitializer, file SemaDecl.cpp, line 362.

Program received signal SIGABRT, Aborted.

Notice the extra "}" on the line "int test() {}". I'm not certain what the correct behavior should be in this case, but it certainly shouldn't be a crash.

tkremenek avatar Dec 14 '07 23:12 tkremenek

Fixed, we now emit:

t3.c:4:14: error: variable length array declared outside of any function typedef int x[foo()]; ^ ~~~~~ t3.c:4:16: error: initializer element is not constant typedef int x[foo()]; ^ t3.c:6:21: error: initializer element is not constant int z = sizeof(int[foo()]); ~~~~~~~~~~~^~~~~~~ t3.c:7:2: error: expected identifier or '(' return y + z; ^ t3.c:8:1: error: expected identifier or '(' } ^

The second error looks bogus though.

-Chris

lattner avatar Dec 18 '07 09:12 lattner