https://bugs.llvm.org/show_bug.cgi?id=33224

            Bug ID: 33224
           Summary: clang places implicitly declared C functions at
                    compile unit scope
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangb...@nondot.org
          Reporter: momchil.veli...@arm.com
                CC: llvm-bugs@lists.llvm.org

Created attachment 18537
  --> https://bugs.llvm.org/attachment.cgi?id=18537&action=edit
testcase

Compiling the following testcase with `clang -std=c90 -c x.c`

> int f() {
>        g();
>        return 0;
> }
> 
>  int (*p)() = g;

completes successfully.

The identifier `g` is not declared at the place, where it appears in the
context of the function call expression. In that case, the C90 Standard says
(6.3.3.2 Function calls):

>     If the expression that precedes the parenthesized argument list in a 
> function
>     call consists solely by an identifier, and if no declaration is visible 
> for this
>     identifier, the identifier is implicitly declared as if, in the innermost 
> block
>     containing the function call, the declaration
> 
>     extern int identifier();
> 
>     appeared.

Therefore, the above program should be equivalent to:

> int f() {
>        extern int g();
>        g();
>        return 0;
> }
> 
>  int (*p)() = g;

for which clang terminates with an error. The C90 Standard (6.1.2.1 Scopes of
identifiers), says:

> If the declarator or type specifier that declared the identifier appears 
> inside a block [...],
> the identifier has block scope, which terminates at the } that closes the 
> associated block.

so, this should be the correct behavior in both testcases.

However, clang places the implicitly declared function at translation
unit scope, which causes the identifier to be visible in the initializer
in the original testcase, in effect accepting an invalid program.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to