How to silence warnings from system headers

Hi clang people,

I’m using clang as a frontend for the LLVM ORC JIT on Windows.
When I include system headers I get long error messages. For example, with stdlib.h I get a lot of: “warning: macro expansion producing ‘defined’ has undefined behavior”

Is there a way to prevent these warnings? Preferably only for the system libraries.
The documentation I read suggested that system libraries shouldn’t throw up these errors.

I tried -Wno-expansion-to-defined, -fms-extensions, -fms-compatibility-fms, -compatibility-version=14.16.27023. I also tried to reference the system library folder by -isystem, -internal-isystem and -c-isystem

None of these seemed to work. Do you have any suggestions?

Thanks,
Andrew

Use `-isystem` instead of `-I` ?

Chris

Hi Chris,

Thanks for the response.
I double-checked my arguments and tried -isystem and -internal-isystem again, but no change.

Is there anything else I can try?

This is the array of arguments I’m handing to clang:

char const *args[] = {
"-triple", // target triple
/**/ "TRIPLE", // overriden later

"-disable-free", // Disable freeing of memory on exit
"-main-file-name", // Main file name to use for debug info
/* */ "INPUT_FILE",
"-target-cpu", "x86-64", // Target a specific cpu type
"-dwarf-column-info", // Turn on column location information

"-masm-verbose", // Generate verbose assembly output
"-mconstructor-aliases", // Emit complete constructors and destructors as aliases when possible
"-mthread-model", "posix", // The thread model to use, e.g. posix, single (posix by default)
"-momit-leaf-frame-pointer", // Omit frame pointer setup for leaf functions
"-mrelocation-model", "pic", // The relocation model to use
"-munwind-tables", // Generate unwinding tables for all functions
"-pic-level", "2", // Value for __PIC__

"-fms-extensions", // Accept some non-standard constructs supported by the Microsoft compiler
"-fms-compatibility", // Enable full Microsoft Visual C++ compatibility
"-fms-compatibility-version=14.16.27023", // Dot-separated value representing the Microsoft compiler version number to report in _MSC_VER (0 = don't define it (default))

"-resource-dir", // The directory which holds the compiler resource files
"E:\\Program Files\\LLVM\\lib\\clang\\9.0.0",

"-isystem",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\ATLMFC\\include",
"-isystem",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include",

"-isystem",
"C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\shared",
"-isystem",
"C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\ucrt",
"-isystem",
"C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\um",

"-fdebug-compilation-dir", // The compilation directory to embed in the debug info
"E:\\Documents\\Coding\\debug",
"-ferror-limit", "19", // Set the maximum number of errors to emit before stopping (0 = no limit).
// Emit an error if a C++ static local initializer would need a guard variable
"-fmessage-length", "120", // Format message diagnostics so that they fit within N columns or fewer, when possible
"-fno-use-cxa-atexit", // Don't use __cxa_atexit for calling destructors
"-fdelayed-template-parsing", // Parse templated function definitions at the end of the translation unit
"-fobjc-runtime=gcc", // Specify the target Objective-C runtime kind and version
"-fdiagnostics-show-option", // Print option name with mappable diagnostics
"-fcolor-diagnostics",
"-fmath-errno", // Require math functions to indicate errors by setting errno
"-faddrsig", // Emit an address-significance table
/**/"-femit-all-decls", // Emit all declarations, even if unused [verified to work - AZMR]

/**/"-x", "c", // Treat subsequent input files as having type <language>
input_file,
};

Cheers,
Andrew