[cfe-dev] interesting clang issue with "floor"
reed kotler
rkotler at mips.com
Fri Jul 26 20:48:57 PDT 2013
My point was that the function attributes for floor and floor_ are
different, even though the definitions are the same.
This is a follow on email.
floor has nounwind and readnone whereas floor_ has neither of those.
But you can override them so how can it know that these attributes are
valid for the ones that I create?
On 07/26/2013 06:57 PM, Cameron McInally wrote:
> Hey Reed,
>
> On Fri, Jul 26, 2013 at 9:26 PM, reed kotler <rkotler at mips.com> wrote:
>> Maybe there is some special C rule here that I don't understand but I am
>> declaring floor and floor_.
>>
>> consider floor1.c
>>
>>
>> extern double floor(double);
>> extern double floor_(double);
>>
>> double x = 1.5;
>> double y, y_;
>>
>> void foo() {
>>
>> y = floor(x);
>> y_ = floor_(x);
>> }
>>
>>
>> and floor.c
>>
>> #include <stdio.h>
>>
>> extern double x, y, y_;
>>
>> double floor(double x) {
>> return 2*x;
>> }
>>
>> double floor_(double x) {
>> return 3*x;
>> }
>>
>> extern void foo();
>>
>> int main() {
>> foo();
>> printf("%e %e %e \n", x, y, y_);
>> return 0;
>> }
>>
>> /local/llvmpb_config/install/bin/clang floor1.c floor.c
>>
>> rkotler at ubuntu-rkotler:~/testmips16$ ./a.out
>> 1.500000e+00 3.000000e+00 4.500000e+00
> This behaviour looks correct to me. I think you're battling a linkage issue.
>
> When you define floor(...), you're creating a STRONG symbol. This
> symbol *should* be linked instead of the WEAK floor(...) symbol that
> is provided as a builtin.
>
> If you remove your definition of floor(...), you should fall back to
> the WEAK symbol.
>
> But, maybe I am missing the real problem?
>
> -Cameron
More information about the cfe-dev
mailing list