[cfe-dev] interesting clang issue with "floor"

Cameron McInally cameron.mcinally at nyu.edu
Fri Jul 26 18:57:32 PDT 2013


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