[LLVMbugs] [Bug 20313] New: incorrect determination of compatible function types

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jul 15 16:43:08 PDT 2014


            Bug ID: 20313
           Summary: incorrect determination of compatible function types
           Product: clang
           Version: 3.4
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: siegel at udel.edu
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Consider the following C program:

    int f() { return 9; }
    int main() {
      int (*h1)(int);
      h1 = f; // why is this allowed?                                           
      return h1(7);

According to the C11 Standard, Sec., in a simple assignment, "one of
the following shall hold", and the only relevant one in the list is the

"the left operand has atomic, qualified, or unqualified pointer type, and ...
both operands are pointers to qualified or unqualified versions of compatible

Moreover, this is a "constraint", meaning, a conforming implementation must
report a diagnostic message if it is violated.

It seems to me that this constraint is violated in the assignment in the
program above.  Both sides of the assignments are function pointers.  So the
question is, are the two function types compatible?  This is answered in Sec.

"For two function types to be compatible, both shall specify compatible return
types.... If one type has a parameter type list and the other type is specified
by a function definition that contains a (possibly empty) identifier list, both
shall agree in the number of parameters, and the type of each prototype
parameter shall be compatible with the type that results from the application
of the default argument promotions to the type of the corresponding

In this case, one of the types, that of h1, has a parameter type list; the
other, f, does not.  Hence the last sentence in the quote above applies: in
particular, "both shall agree in the number of parameters".  Clearly h1 takes
one parameter.   What about f?  The following point occurs in the C11 Standard
just before the one quoted above:

"An empty list in a function declarator that is part of a definition of that
function specifies that the function has no parameters."

So f takes 0 parameters.  So the two types do not agree in the number of
parameters, the two functions types are incompatible, and the assignment
violates a constraint, and a diagnostic should be issued.

However Clang/LLVM issues no diagnostic message when compiling the program:

    tmp$ cc -std=c11 -Wall tmp4.c 

See also:

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140715/d16999d3/attachment.html>

More information about the llvm-bugs mailing list