[PATCH] Only allow builtin/runtime builtins to be forgotten upon seeing a declaration with the same name.

Michael Gottesman mgottesman at apple.com
Thu Oct 31 16:27:20 PDT 2013


Hey dgregor!

The attached patch ensures that clang only allows the user to respecify declarations for library/runtime builtins instead of generic builtins.

Background:
In r122351, clang began to allow users to override the prototype of
builtins if the user declared a function with the same name. The idea
behind this was to give implementors of common library/runtime functions
clang knows about the flexiblity to use different prototypes than what
clang has been taught to expect.

This patch restricts such behavior in order to prevent the users from
overriding general compiler builtins since said builtins via the "t"
specifier allow one to do (essentially) what ever one wants by specifying
that the builtin has custom type checking/special implementation.

The example inspiring this change is the following:

namespace test {
  int __sync_add_and_fetch_4(int *p, int n) { return 0; }                                                                                                                             
  int syncAddAndFetch(volatile int *p, int n) {
    return __sync_add_and_fetch(p, n);                                                                                                                                                
  }
}

What occurs here is that clang sees __sync_add_and_fetch_4 and more
importantly that the prototype differs from the prototype that clang has
from Builtins.def:

  int __sync_add_and_fetch_4(volatile int *p, int n, ...)

Then clang erase its original builtin definition under the impression
that we are overriding said builtin.

Then when clang processes __sync_add_and_fetch, it generates calls to
__sync_add_and_fetch_4 as if it was still a builtin. This then causes an
unreachable to be hit in CodeGen when CodeGen attempts to process an
ImplicitCast of the DeclRef of the function call as if it is not a
builtin only to find that the ImplicitCast is of BuiltinFnToFnPtr.

Please review,
Michael

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Ensure-that-clang-only-allows-the-user-to-respecify-.patch
Type: application/octet-stream
Size: 3634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131031/474ff133/attachment.obj>


More information about the cfe-commits mailing list