regression with function pointers

Hi,

There was some kind of regression in function pointers handling. Attached is a file that triggers an assert failure (when run with e.g. -ast-dump):

clang: /cvs/llvm/include/llvm/Support/Casting.h:199: typename llvm::cast_retty<To, From>::ret_type llvm::cast(const Y&) [with X = clang::FunctionTypeProto, Y = clang::Type*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
(...)
/lib/libc.so.6(__assert_fail+0xf5)[0xb7d287a5]
../../Debug/bin/clang(llvm::cast_retty<clang::FunctionTypeProto, clang::Type*>::ret_type llvm::cast<clang::FunctionTypeProto, clang::Type*>(clang::Type* const&)+0x4b)[0x831125d]
../../Debug/bin/clang(clang::FunctionDecl::getNumParams() const+0x3a)[0x831f92a]
../../Debug/bin/clang((anonymous namespace)::DeclPrinter::PrintFunctionDeclStart(clang::FunctionDecl*)+0x169)[0x826cd33]
../../Debug/bin/clang((anonymous namespace)::ASTDumper::HandleTopLevelDecl(clang::Decl*)+0x30)[0x826fc80]
../../Debug/bin/clang(clang::ParseAST(clang::Preprocessor&, unsigned int, clang::ASTConsumer*, bool)+0x107)[0x82dc1c7]

Sorry for the big file, but I didn't have the time to strip it.

Regards,
Nuno

php_example.c (217 KB)

Here is a two line test case that exposes the bug (which appears specific to -ast-print/-ast-dump)...

snaroff% cat nuno.c

typedef void func_typedef();

func_typedef xxx;

I'll investigate later. Thanks for the bug,

snaroff

Fixed,

-Chris

There was some kind of regression in function pointers handling.
Attached is a file that triggers an assert failure (when run with
e.g. -ast-dump):

Sorry for the big file, but I didn't have the time to strip it.

Here is a two line test case that exposes the bug (which appears
specific to -ast-print/-ast-dump)...

snaroff% cat nuno.c

typedef void func_typedef();

func_typedef xxx;

I'll investigate later. Thanks for the bug,

Fixed,

-Chris

Thank you Chris! However it seems my example file now triggers another assert().
I'm putting it on-line, as it seems to be a good case-study: http://web.ist.utl.pt/nuno.lopes/php_example.c :stuck_out_tongue:
It fails with 'assert(isa<X>(Val) && "cast<Ty>() argument of incompatible type!"', triggered by FunctionDecl::getNumParams().

Nuno

There was some kind of regression in function pointers handling.
Attached is a file that triggers an assert failure (when run with
e.g. -ast-dump):

Sorry for the big file, but I didn't have the time to strip it.

Here is a two line test case that exposes the bug (which appears
specific to -ast-print/-ast-dump)...

snaroff% cat nuno.c

typedef void func_typedef();

func_typedef xxx;

I'll investigate later. Thanks for the bug,

Fixed,

-Chris

Thank you Chris! However it seems my example file now triggers another
assert().
I'm putting it on-line, as it seems to be a good case-study:
http://web.ist.utl.pt/nuno.lopes/php_example.c :stuck_out_tongue:
It fails with 'assert(isa<X>(Val) && "cast<Ty>() argument of
incompatible type!"', triggered by FunctionDecl::getNumParams().

OK, so today I had a few minutes to track down the bug. The problem is triggered with the following:
typedef void func_t(int x);
func_t a;

The patch to fix it is attached.

Nuno

diff.txt (557 Bytes)

OK, so today I had a few minutes to track down the bug. The problem is triggered with the following:
typedef void func_t(int x);
func_t a;

The patch to fix it is attached.

Applied, thanks!

-Chris