llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28k stars 11.56k forks source link

llvm-gcc doesn't support nested functions #1287

Closed llvmbot closed 14 years ago

llvmbot commented 18 years ago
Bugzilla Link 915
Resolution FIXED
Resolved on Feb 22, 2010 12:48
Version 1.8
OS All
Blocks llvm/llvm-bugzilla-archive#1166
Reporter LLVM Bugzilla Contributor
CC @nlewycky

Extended Description

$ /usr/local/llvm/cfrontend/install/bin/llvm-gcc --emit-llvm -S foo.i -fnested-functions foo.i: In function ?b?: foo.i:3: internal compiler error: in lhd_set_decl_assembler_name, at langhooks.c:193 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://llvm.org/bugs> for instructions. $ cat foo.i static void a() { int foo; inline void b() { foo = -1; } b(); }

lattner commented 16 years ago

Done! It is bug 2283

llvmbot commented 16 years ago

Incidentally, many tests from the gcc testsuite fail at -O0, e.g. gcc.c-torture/20010605-1.c

This fires an assertion I have here locally that checks that CreateTemporary is not used when the gcc type has variable size. So at first glance it looks to me like this isn't really a problem with nested functions as such. Can you please open a new PR for this.

lattner commented 16 years ago

Incidentally, many tests from the gcc testsuite fail at -O0, e.g. gcc.c-torture/20010605-1.c

lattner commented 17 years ago

Actually, this looks like an unrelated bug. I've filed it as Bug 1274.

-Chris

lattner commented 17 years ago

Verified, this example doesn't use trampolines, but causes infinite recursion in the FE.

llvmbot commented 17 years ago

I'm still getting a segfault: /tmp/delta$ /usr/local/code/llvm/llvm-gcc4/install/bin/gcc --emit-llvm -S foo.i -fnested-functions gcc: Internal error: Segmentation fault (program cc1) Please submit a full bug report. See <URL:http://llvm.org/bugs> for instructions. /tmp/delta$ cat foo.i static void foo(void *a){ inline void foo_bar() { a += 1; } }

llvmbot commented 17 years ago

Nested subroutines as used in the examples in this PR are now supported. However there is no support yet for trampolines, i.e. taking the address of a nested subroutine, nor for non-local gotos. I've opened llvm/llvm-bugzilla-archive#1190 for tracking progress on trampolines. I didn't bother for non-local gotos because it's less clear that anyone is interested in that. By the way, the testcase in attachment 625 still fails to compile, because tree-nested.c goes into an infinite loop, i.e. this seems to be a gcc bug not an LLVM one.

asl commented 17 years ago

Another testcase from gcc.c-torture

asl commented 17 years ago

Another testcase from gcc.c-torture

asl commented 17 years ago

Another testcase from gcc.c-torture

asl commented 17 years ago

Testcase from gcc.c-torture

lattner commented 17 years ago

This is dying when trying to codegen the static chain. This would be easy to add support for in llvm- gcc, but would require intrinsics to represent this and code generator work to implement these. This is all possible, but not something I have time for. I'll leave this for someone else to pick up.

As a consolation prize, I checked in a patch that causes this to be emitted:

/Users/sabre/asm.c: In function 'b': /Users/sabre/asm.c:3: sorry, unimplemented: nested functions not supported by LLVM

instead of ICE'ing.

-Chris

lattner commented 18 years ago

I'm not shocked, we don't support nested functions properly.  I will see if there is something easy we can do, but we won't supported taking the address of a nested function in the near future.

-Chris