Problems compiling with CLToolkit 15.3

I got this error when compiling a fortran code using the new version of CLToolkit 15.3 (with 15.1 I have no problems at all):

In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/_stdio.h:68, from /usr/local/lib/gcc/aarch64-apple-darwin22.2.0/13.0.0/include-fixed/stdio.h:78, from /Users/meanapanedar2/programming/SIMPLE/src/jpg/stb_image.h:307, from /Users/meanapanedar2/programming/SIMPLE/src/jpg/stb_image_write.c:14: /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/cdefs.h:554:30: error: missing ')' after "__has_attribute" 554 | #if __has_cpp_attribute(clang::unsafe_buffer_usage) | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/cdefs.h:554:31: error: ':' without preceding '?' 554 | #if __has_cpp_attribute(clang::unsafe_buffer_usage) | ^ In file included from /usr/local/lib/gcc/aarch64-apple-darwin22.2.0/13.0.0/include-fixed/math.h:45, from /Users/meanapanedar2/programming/SIMPLE/src/ops/simple_kbinterpol_memo.c:2: /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/cdefs.h:554:30: error: missing ')' after "__has_attribute" 554 | #if __has_cpp_attribute(clang::unsafe_buffer_usage) | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/cdefs.h:554:31: error: ':' without preceding '?' 554 | #if __has_cpp_attribute(clang::unsafe_buffer_usage) | ^ In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/ConditionalMacros.h:61, from /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/MacTypes.h:41, from /Users/meanapanedar2/programming/SIMPLE/src/fileio/simple_posix.c:15: /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/TargetConditionals.h:140:50: error: missing binary operator before token "(" 140 | #if !defined(__has_extension) || !__has_extension(define_target_os_macros) | ^ In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/types.h:75, from /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/MacTypes.h:48: /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/cdefs.h:554:30: error: missing ')' after "__has_attribute" 554 | #if __has_cpp_attribute(clang::unsafe_buffer_usage) | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/cdefs.h:554:31: error: ':' without preceding '?' 554 | #if __has_cpp_attribute(clang::unsafe_buffer_usage) | ^ [ 7%] Building Fortran object lib/CMakeFiles/SIMPLE3.0.0.dir/defs/simple_defs.f90.o [ 7%] Building Fortran object lib/CMakeFiles/SIMPLE3.0.0.dir/xml/fsys/fox_m_fsys_parse_input.F90.o make[2]: *** [lib/CMakeFiles/SIMPLE3.0.0.dir/ops/simple_kbinterpol_memo.c.o] Error 1 make[2]: *** Waiting for unfinished jobs.... [ 7%] Building Fortran object lib/CMakeFiles/SIMPLE3.0.0.dir/ops/json_parameters.f90.o [ 7%] Building Fortran object lib/CMakeFiles/SIMPLE3.0.0.dir/xml/fsys/fox_m_fsys_count_parse_input.F90.o [ 7%] Building Fortran object lib/CMakeFiles/SIMPLE3.0.0.dir/xml/fsys/fox_m_fsys_format.F90.o make[2]: *** [lib/CMakeFiles/SIMPLE3.0.0.dir/jpg/stb_image_write.c.o] Error 1 make[2]: *** [lib/CMakeFiles/SIMPLE3.0.0.dir/fileio/simple_posix.c.o] Error 1 make[1]: *** [lib/CMakeFiles/SIMPLE3.0.0.dir/all] Error 2 make: *** [all] Error 2

What is CLToolkit?

I mean, I can search the ’net for that phrase, but it’s not obvious which of the many hits are relevant to your setup.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I encountered this error while compiling code with a gcc compiler that worked with sdk's prior to 14.4 (like 14.2):

/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/cdefs.h:554:30: error: missing ')' after "__has_attribute"
  554 | #if __has_cpp_attribute(clang::unsafe_buffer_usage)
      |                              ^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/cdefs.h:554:31: error:  ':' without preceding '?'
  554 | #if __has_cpp_attribute(clang::unsafe_buffer_usage)
      |                               ^

In the /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/cdefs.h file at line 554 (flagged by the compiler), the __has_cpp_attribute macro is using some apparent clang-centric input in this block (line 554-563

#if __has_cpp_attribute(clang::unsafe_buffer_usage)
#define __has_safe_buffers 1
#define __unsafe_buffer_usage [[clang::unsafe_buffer_usage]]
#elif __has_attribute(unsafe_buffer_usage)
#define __has_safe_buffers 1
#define __unsafe_buffer_usage __attribute__((__unsafe_buffer_usage__))
#else
#define __has_safe_buffers 0
#define __unsafe_buffer_usage
#endif

I was able to workaround the compilation issue by adding in guards based on whether __clang__ was defined, wrapping lines 554-570 Workaround change:

#if defined(__clang__) // hacked in guard
#if __has_cpp_attribute(clang::unsafe_buffer_usage)
#define __has_safe_buffers 1
#define __unsafe_buffer_usage [[clang::unsafe_buffer_usage]]
#elif __has_attribute(unsafe_buffer_usage)
#define __has_safe_buffers 1
#define __unsafe_buffer_usage __attribute__((__unsafe_buffer_usage__))
#else
#define __has_safe_buffers 0
#define __unsafe_buffer_usage
#endif
#if __has_safe_buffers
#define __unsafe_buffer_usage_begin _Pragma("clang unsafe_buffer_usage begin")
#define __unsafe_buffer_usage_end   _Pragma("clang unsafe_buffer_usage end")
#else
#define __unsafe_buffer_usage_begin
#define __unsafe_buffer_usage_end
#endif
#endif // hacked in endif

I assumed a simple reproducer would just involve including cdefs.h and attempting to compile with gcc or g++, but that compiled fine for me in isolation. Attempted reproducer that compiled fine:

// compile as: g++ cdfefs-issue-sdx144.c -I /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/sys
#include <cdefs.h>
int main () {
  return 0;
}

In any case, is it possible that the __has_cpp_attribute stuff as-is should be guarded based on whether clang is being used?

The problem previously reported with CLTookit 15.3 is still present in CLT version 16.0 beta. We hope that Apple is able to find the bug because we cannot compiler our code in our Mac machines.

Problems compiling with CLToolkit 15.3
 
 
Q