Bug 78665 - macros in builtin_functions.cpp make invalid assumptions about M_PI definitions
Summary: macros in builtin_functions.cpp make invalid assumptions about M_PI definitions
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: git
Hardware: Other OpenBSD
: medium normal
Assignee: Matt Turner
QA Contact: Intel 3D Bugs Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-13 15:03 UTC by Jonathan Gray
Modified: 2014-05-14 05:41 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Jonathan Gray 2014-05-13 15:03:23 UTC
After the following commit:

commit d877c643bea7a40e37d13d8a967c06fd006d1622
Author: Matt Turner <mattst88@gmail.com>
Date:   Sat Apr 5 22:03:04 2014 -0700

    glsl: Use M_PI_* macros.
    
    Notice our multiple values for M_PI_2, which rounded ...32 up to
    ...4 and ...5.

Mesa no longer builds on OpenBSD.  Apparently the M_PI macros in glibc are not defined with any brackets/casts like they are in OpenBSD (and perhaps elsewhere?).

From the OpenBSD math.h:

#define M_PI            ((double)3.14159265358979323846) /* pi */
#define M_PI_2          ((double)1.57079632679489661923) /* pi/2 */
#define M_PI_4          ((double)0.78539816339744830962) /* pi/4 */

libtool: compile:  g++ -DPACKAGE_NAME=\"Mesa\" -DPACKAGE_TARNAME=\"mesa\" -DPACKAGE_VERSION=\"10.3.0-devel\" "-DPACKAGE_STRING=\"Mesa 10.3.0-devel\"" "-DPACKAGE_BUGREPORT=\"https://bugs.freedesktop.org/enter_bug.cgi?pro
duct=Mesa\"" -DPACKAGE_URL=\"\" -DPACKAGE=\"mesa\" -DVERSION=\"10.3.0-devel\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INT
TYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DYYTEXT_POINTER=1 -DHAVE_DLADDR=1 -DHAVE_CLOCK_GETTIME=1 -DHAVE_PTHREAD_PRIO_INHERIT=1 -DHAVE_PTHREAD=1 -I. -I../../include -I../../
src/mapi -I../../src/mesa/ -I../../src/glsl/glcpp -I../../src/gtest/include -DDEBUG -DUSE_X86_64_ASM -DHAVE_DLOPEN -DHAVE_POSIX_MEMALIGN -DHAVE_LIBDRM -DGLX_INDIRECT_RENDERING -DGLX_DIRECT_RENDERING -DHAVE_PTHREAD -DUSE
_EXTERNAL_DXTN_LIB=1 -DHAVE_ALIAS -DHAVE_MINCORE -DHAVE_LLVM=0x0305 -DLLVM_VERSION_PATCH=0 -I/usr/local/include -I/usr/local/include/libelf -fvisibility=hidden -g -O2 -Wall -fno-strict-aliasing -fno-builtin-memcmp -g -O
0 -MT builtin_functions.lo -MD -MP -MF .deps/builtin_functions.Tpo -c ../../src/glsl/builtin_functions.cpp  -fPIC -DPIC -o .libs/builtin_functions.o
../../src/glsl/builtin_functions.cpp:2547:1: error: pasting ")" and "f" does not give a valid preprocessing token
../../src/glsl/builtin_functions.cpp:2549:1: error: pasting ")" and "f" does not give a valid preprocessing token
../../src/glsl/builtin_functions.cpp:2551:1: error: pasting ")" and "f" does not give a valid preprocessing token
../../src/glsl/builtin_functions.cpp:2595:1: error: pasting ")" and "f" does not give a valid preprocessing token
../../src/glsl/builtin_functions.cpp:2632:1: error: pasting ")" and "f" does not give a valid preprocessing token
../../src/glsl/builtin_functions.cpp:2633:1: error: pasting ")" and "f" does not give a valid preprocessing token
../../src/glsl/builtin_functions.cpp:2638:1: error: pasting ")" and "f" does not give a valid preprocessing token
../../src/glsl/builtin_functions.cpp: In member function 'ir_expression*<unnamed>::builtin_builder::asin_expr(ir_variable*)':
../../src/glsl/builtin_functions.cpp:2547: error: expected `)' before 'f'
../../src/glsl/builtin_functions.cpp:2547: error: call of overloaded 'imm(double)' is ambiguous
../../src/glsl/builtin_functions.cpp:2388: note: candidates are: ir_constant*<unnamed>::builtin_builder::imm(float, unsigned int)
../../src/glsl/builtin_functions.cpp:2394: note:                 ir_constant*<unnamed>::builtin_builder::imm(int, unsigned int)
../../src/glsl/builtin_functions.cpp:2400: note:                 ir_constant*<unnamed>::builtin_builder::imm(unsigned int, unsigned int)
../../src/glsl/builtin_functions.cpp:2549: error: expected `)' before 'f'
../../src/glsl/builtin_functions.cpp:2549: error: call of overloaded 'imm(double)' is ambiguous
../../src/glsl/builtin_functions.cpp:2388: note: candidates are: ir_constant*<unnamed>::builtin_builder::imm(float, unsigned int)
../../src/glsl/builtin_functions.cpp:2394: note:                 ir_constant*<unnamed>::builtin_builder::imm(int, unsigned int)
../../src/glsl/builtin_functions.cpp:2400: note:                 ir_constant*<unnamed>::builtin_builder::imm(unsigned int, unsigned int)
../../src/glsl/builtin_functions.cpp:2551: error: expected `)' before 'f'
../../src/glsl/builtin_functions.cpp:2551: error: call of overloaded 'imm(double)' is ambiguous
../../src/glsl/builtin_functions.cpp:2388: note: candidates are: ir_constant*<unnamed>::builtin_builder::imm(float, unsigned int)
../../src/glsl/builtin_functions.cpp:2394: note:                 ir_constant*<unnamed>::builtin_builder::imm(int, unsigned int)
../../src/glsl/builtin_functions.cpp:2400: note:                 ir_constant*<unnamed>::builtin_builder::imm(unsigned int, unsigned int)
../../src/glsl/builtin_functions.cpp: In member function 'ir_function_signature*<unnamed>::builtin_builder::_acos(const glsl_type*)':
../../src/glsl/builtin_functions.cpp:2595: error: expected `)' before 'f'
../../src/glsl/builtin_functions.cpp:2595: error: call of overloaded 'imm(double)' is ambiguous
../../src/glsl/builtin_functions.cpp:2388: note: candidates are: ir_constant*<unnamed>::builtin_builder::imm(float, unsigned int)
../../src/glsl/builtin_functions.cpp:2394: note:                 ir_constant*<unnamed>::builtin_builder::imm(int, unsigned int)
../../src/glsl/builtin_functions.cpp:2400: note:                 ir_constant*<unnamed>::builtin_builder::imm(unsigned int, unsigned int)
../../src/glsl/builtin_functions.cpp: In member function 'ir_function_signature*<unnamed>::builtin_builder::_atan2(const glsl_type*)':
../../src/glsl/builtin_functions.cpp:2632: error: expected `)' before 'f'
../../src/glsl/builtin_functions.cpp:2632: error: call of overloaded 'imm(double)' is ambiguous
../../src/glsl/builtin_functions.cpp:2388: note: candidates are: ir_constant*<unnamed>::builtin_builder::imm(float, unsigned int)
../../src/glsl/builtin_functions.cpp:2394: note:                 ir_constant*<unnamed>::builtin_builder::imm(int, unsigned int)
../../src/glsl/builtin_functions.cpp:2400: note:                 ir_constant*<unnamed>::builtin_builder::imm(unsigned int, unsigned int)
../../src/glsl/builtin_functions.cpp:2633: error: expected `)' before 'f'
../../src/glsl/builtin_functions.cpp:2633: error: call of overloaded 'imm(double)' is ambiguous
../../src/glsl/builtin_functions.cpp:2388: note: candidates are: ir_constant*<unnamed>::builtin_builder::imm(float, unsigned int)
../../src/glsl/builtin_functions.cpp:2394: note:                 ir_constant*<unnamed>::builtin_builder::imm(int, unsigned int)
../../src/glsl/builtin_functions.cpp:2400: note:                 ir_constant*<unnamed>::builtin_builder::imm(unsigned int, unsigned int)
../../src/glsl/builtin_functions.cpp:2638: error: expected `)' before 'f'
../../src/glsl/builtin_functions.cpp:2638: error: call of overloaded 'imm(double)' is ambiguous
../../src/glsl/builtin_functions.cpp:2388: note: candidates are: ir_constant*<unnamed>::builtin_builder::imm(float, unsigned int)
../../src/glsl/builtin_functions.cpp:2394: note:                 ir_constant*<unnamed>::builtin_builder::imm(int, unsigned int)
../../src/glsl/builtin_functions.cpp:2400: note:                 ir_constant*<unnamed>::builtin_builder::imm(unsigned int, unsigned int)
Makefile:1449: recipe for target 'builtin_functions.lo' failed

/bin/sh ../../libtool  --tag=CXX   --mode=compile /usr/local/bin/clang++ -DPACKAGE_NAME=\"Mesa\" -DPACKAGE_TARNAME=\"mesa\" -DPACKAGE_VERSION=\"10.3.0-devel\" -DPACKAGE_STRING=\"Mesa\ 10.3.0-devel\" -DPACKAGE_BUGREPORT=\"https://bugs.freedesktop.org/enter_bug.cgi\?product=Mesa\" -DPACKAGE_URL=\"\" -DPACKAGE=\"mesa\" -DVERSION=\"10.3.0-devel\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DYYTEXT_POINTER=1 -DHAVE_DLADDR=1 -DHAVE_CLOCK_GETTIME=1 -DHAVE_PTHREAD_PRIO_INHERIT=1 -DHAVE_PTHREAD=1 -I.  -I../../include -I../../src/mapi -I../../src/mesa/ -I../../src/glsl/glcpp -I../../src/gtest/include -DDEBUG -DUSE_X86_64_ASM -DHAVE_DLOPEN -DHAVE_POSIX_MEMALIGN -DHAVE_LIBDRM -DGLX_INDIRECT_RENDERING -DGLX_DIRECT_RENDERING -DHAVE_PTHREAD -DUSE_EXTERNAL_DXTN_LIB=1 -DHAVE_ALIAS -DHAVE_MINCORE -DHAVE_LLVM=0x0305 -DLLVM_VERSION_PATCH=0 -I/usr/local/include -I/usr/local/include/libelf -fvisibility=hidden -g -O2 -Wall -fno-strict-aliasing -fno-builtin-memcmp -g -O0  -MT builtin_functions.lo -MD -MP -MF .deps/builtin_functions.Tpo -c -o builtin_functions.lo `test -f '../../src/glsl/builtin_functions.cpp' || echo './'`../../src/glsl/builtin_functions.cpp
libtool: compile:  /usr/local/bin/clang++ -DPACKAGE_NAME=\"Mesa\" -DPACKAGE_TARNAME=\"mesa\" -DPACKAGE_VERSION=\"10.3.0-devel\" "-DPACKAGE_STRING=\"Mesa 10.3.0-devel\"" "-DPACKAGE_BUGREPORT=\"https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa\"" -DPACKAGE_URL=\"\" -DPACKAGE=\"mesa\" -DVERSION=\"10.3.0-devel\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DYYTEXT_POINTER=1 -DHAVE_DLADDR=1 -DHAVE_CLOCK_GETTIME=1 -DHAVE_PTHREAD_PRIO_INHERIT=1 -DHAVE_PTHREAD=1 -I. -I../../include -I../../src/mapi -I../../src/mesa/ -I../../src/glsl/glcpp -I../../src/gtest/include -DDEBUG -DUSE_X86_64_ASM -DHAVE_DLOPEN -DHAVE_POSIX_MEMALIGN -DHAVE_LIBDRM -DGLX_INDIRECT_RENDERING -DGLX_DIRECT_RENDERING -DHAVE_PTHREAD -DUSE_EXTERNAL_DXTN_LIB=1 -DHAVE_ALIAS -DHAVE_MINCORE -DHAVE_LLVM=0x0305 -DLLVM_VERSION_PATCH=0 -I/usr/local/include -I/usr/local/include/libelf -fvisibility=hidden -g -O2 -Wall -fno-strict-aliasing -fno-builtin-memcmp -g -O0 -MT builtin_functions.lo -MD -MP -MF .deps/builtin_functions.Tpo -c ../../src/glsl/builtin_functions.cpp  -fPIC -DPIC -o .libs/builtin_functions.o
../../src/glsl/builtin_functions.cpp:2547:23: error: pasting formed ')f', an invalid preprocessing token
              sub(imm(M_PI_2f),
                      ^
../../src/glsl/builtin_functions.cpp:68:17: note: expanded from macro 'M_PI_2f'
#define M_PI_2f f(M_PI_2)
                ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:19: note: expanded from macro 'join'
#define join(x) x ## f
                  ^
../../src/glsl/builtin_functions.cpp:2547:23: error: expected ')'
../../src/glsl/builtin_functions.cpp:68:17: note: expanded from macro 'M_PI_2f'
#define M_PI_2f f(M_PI_2)
                ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:22: note: expanded from macro 'join'
#define join(x) x ## f
                     ^
../../src/glsl/builtin_functions.cpp:2547:22: note: to match this '('
              sub(imm(M_PI_2f),
                     ^
../../src/glsl/builtin_functions.cpp:2549:31: error: pasting formed ')f', an invalid preprocessing token
                      add(imm(M_PI_2f),
                              ^
../../src/glsl/builtin_functions.cpp:68:17: note: expanded from macro 'M_PI_2f'
#define M_PI_2f f(M_PI_2)
                ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:19: note: expanded from macro 'join'
#define join(x) x ## f
                  ^
../../src/glsl/builtin_functions.cpp:2551:39: error: pasting formed ')f', an invalid preprocessing token
                              add(imm(M_PI_4f - 1.0f),
                                      ^
../../src/glsl/builtin_functions.cpp:69:17: note: expanded from macro 'M_PI_4f'
#define M_PI_4f f(M_PI_4)
                ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:19: note: expanded from macro 'join'
#define join(x) x ## f
                  ^
../../src/glsl/builtin_functions.cpp:2595:26: error: pasting formed ')f', an invalid preprocessing token
   body.emit(ret(sub(imm(M_PI_2f), asin_expr(x))));
                         ^
../../src/glsl/builtin_functions.cpp:68:17: note: expanded from macro 'M_PI_2f'
#define M_PI_2f f(M_PI_2)
                ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:19: note: expanded from macro 'join'
#define join(x) x ## f
                  ^
../../src/glsl/builtin_functions.cpp:2595:26: error: expected ')'
../../src/glsl/builtin_functions.cpp:68:17: note: expanded from macro 'M_PI_2f'
#define M_PI_2f f(M_PI_2)
                ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:22: note: expanded from macro 'join'
#define join(x) x ## f
                     ^
../../src/glsl/builtin_functions.cpp:2595:25: note: to match this '('
   body.emit(ret(sub(imm(M_PI_2f), asin_expr(x))));
                        ^
../../src/glsl/builtin_functions.cpp:2632:39: error: pasting formed ')f', an invalid preprocessing token
                 assign(r, add(r, imm(M_PIf))),
                                      ^
../../src/glsl/builtin_functions.cpp:67:15: note: expanded from macro 'M_PIf'
#define M_PIf f(M_PI)
              ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:19: note: expanded from macro 'join'
#define join(x) x ## f
                  ^
../../src/glsl/builtin_functions.cpp:2632:39: error: expected ')'
../../src/glsl/builtin_functions.cpp:67:15: note: expanded from macro 'M_PIf'
#define M_PIf f(M_PI)
              ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:22: note: expanded from macro 'join'
#define join(x) x ## f
                     ^
../../src/glsl/builtin_functions.cpp:2632:38: note: to match this '('
                 assign(r, add(r, imm(M_PIf))),
                                     ^
../../src/glsl/builtin_functions.cpp:2633:39: error: pasting formed ')f', an invalid preprocessing token
                 assign(r, sub(r, imm(M_PIf)))));
                                      ^
../../src/glsl/builtin_functions.cpp:67:15: note: expanded from macro 'M_PIf'
#define M_PIf f(M_PI)
              ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:19: note: expanded from macro 'join'
#define join(x) x ## f
                  ^
../../src/glsl/builtin_functions.cpp:2638:37: error: pasting formed ')f', an invalid preprocessing token
         assign(r, mul(sign(y), imm(M_PI_2f))));
                                    ^
../../src/glsl/builtin_functions.cpp:68:17: note: expanded from macro 'M_PI_2f'
#define M_PI_2f f(M_PI_2)
                ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:19: note: expanded from macro 'join'
#define join(x) x ## f
                  ^
../../src/glsl/builtin_functions.cpp:2638:37: error: expected ')'
../../src/glsl/builtin_functions.cpp:68:17: note: expanded from macro 'M_PI_2f'
#define M_PI_2f f(M_PI_2)
                ^
../../src/glsl/builtin_functions.cpp:65:14: note: expanded from macro 'f'
#define f(x) join(x)
             ^
../../src/glsl/builtin_functions.cpp:66:22: note: expanded from macro 'join'
#define join(x) x ## f
                     ^
../../src/glsl/builtin_functions.cpp:2638:36: note: to match this '('
         assign(r, mul(sign(y), imm(M_PI_2f))));
                                   ^
11 errors generated.
Makefile:1449: recipe for target 'builtin_functions.lo' failed
Comment 1 Jonathan Gray 2014-05-13 15:13:04 UTC
The casting was introduced in OpenBSD math.h rev 1.33 apparently a change required by POSIX?

revision 1.33
date: 2014/05/03 16:13:03;  author: martynas;  state: Exp;  lines: +30 -14;
- Provide extended-precision math constants req'd by POSIX
- Explicitly cast double-precision constants as needed for
FLT_EVAL_METHOD = 2 archs
OK guenther@, ratchov@

http://www.openbsd.org/cgi-bin/cvsweb/src/include/math.h.diff?r1=1.32;r2=1.33;f=h
Comment 2 Kenneth Graunke 2014-05-13 15:40:53 UTC
This does seem really dodgy.  It seems like we ought to just do:

#define M_PIf   ((float) M_PI)
#define M_PI_2f ((float) M_PI_2)
#define M_PI_4f ((float) M_PI_4)
Comment 3 Matt Turner 2014-05-13 17:45:54 UTC
Fine by me. Jonathan, want to send a patch?
Comment 4 Jonathan Gray 2014-05-14 05:41:09 UTC
I sent out a patch based on Kenneths' suggestion that Matt has since merged.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.