llvm-project/clang/test/Preprocessor
Nico Weber b2348f4ced Add -Wexpansion-to-undefined: warn when using `defined` in a macro definition.
[cpp.cond]p4:
  Prior to evaluation, macro invocations in the list of preprocessing
  tokens that will become the controlling constant expression are replaced
  (except for those macro names modified by the 'defined' unary operator),
  just as in normal text. If the token 'defined' is generated as a result
  of this replacement process or use of the 'defined' unary operator does
  not match one of the two specified forms prior to macro replacement, the
  behavior is undefined.

This isn't an idle threat, consider this program:
  #define FOO
  #define BAR defined(FOO)
  #if BAR
  ...
  #else
  ...
  #endif
clang and gcc will pick the #if branch while Visual Studio will take the
#else branch.  Emit a warning about this undefined behavior.

One problem is that this also applies to function-like macros. While the
example above can be written like

    #if defined(FOO) && defined(BAR)
    #defined HAVE_FOO 1
    #else
    #define HAVE_FOO 0
    #endif

there is no easy way to rewrite a function-like macro like `#define FOO(x)
(defined __foo_##x && __foo_##x)`.  Function-like macros like this are used in
practice, and compilers seem to not have differing behavior in that case. So
this a default-on warning only for object-like macros. For function-like
macros, it is an extension warning that only shows up with `-pedantic`.
(But it's undefined behavior in both cases.)

llvm-svn: 258128
2016-01-19 15:15:31 +00:00
..
Inputs Rename -Wmsvc-include to -Wmicrosoft-include, now that -Wmicrosoft is split up. 2015-07-28 16:48:12 +00:00
_Pragma-dependency.c FileCheck'ize tests 2013-01-28 21:43:46 +00:00
_Pragma-dependency2.c
_Pragma-in-macro-arg.c [preprocessor] In Preprocessor::CachingLex() check whether there were more tokens 2012-04-04 02:57:01 +00:00
_Pragma-location.c Add -fuse-line-directive flag to control usage of #line with -E 2015-02-26 00:17:25 +00:00
_Pragma-physloc.c FileCheck'ize tests 2013-01-28 21:43:46 +00:00
_Pragma.c Improved error recovery for _Pragma 2015-07-30 21:30:00 +00:00
aarch64-target-features.c [AArch64] Teaches clang about Samsung Exynos-M1 2016-01-05 12:53:24 +00:00
annotate_in_macro_arg.c Lex: Don't call getIdentifierInfo on annotation tokens 2015-03-18 07:53:20 +00:00
arm-acle-6.4.c Implement ACLE 2.0 macros of chapters 6.4 and 6.5 for [ARM] and [Aarch64] targets. 2015-09-03 14:40:57 +00:00
arm-acle-6.5.c Fix __ARM_FP value for sp-only FPUs with Half-precision 2015-10-21 10:03:55 +00:00
arm-target-features.c ARM v8.1a adds Advanced SIMD instructions for Rounding Double Multiply 2015-11-29 10:43:59 +00:00
assembler-with-cpp.c Lex: Don't restrict legal UCNs when preprocessing assembly 2013-10-21 05:02:28 +00:00
builtin_line.c FileCheck'ize a test 2013-01-28 21:04:29 +00:00
c90.c Preprocessor: don't consider // to be a line comment in -E -std=c89 mode. 2013-03-05 22:51:04 +00:00
c99-6_10_3_3_p4.c
c99-6_10_3_4_p5.c
c99-6_10_3_4_p6.c
c99-6_10_3_4_p7.c
c99-6_10_3_4_p9.c
clang_headers.c
comment_save.c [-E] Emit a rewritten _Pragma on its own line. 2012-06-15 23:33:51 +00:00
comment_save_if.c Prior to adding the new "expected-no-diagnostics" directive to VerifyDiagnosticConsumer, make the necessary adjustment to 580 test-cases which will henceforth require this new directive. 2012-10-19 12:44:48 +00:00
comment_save_macro.c
cuda-preprocess.cu [CUDA] Add tests for compiling CUDA files with -E. 2016-01-14 21:41:18 +00:00
cxx_and.cpp
cxx_bitand.cpp
cxx_bitor.cpp
cxx_compl.cpp
cxx_not.cpp
cxx_not_eq.cpp
cxx_oper_keyword.cpp Preprocessor: recover gracefully when C++ operator names are used as macro identifiers 2014-05-31 03:38:17 +00:00
cxx_oper_keyword_ms_compat.cpp Emit warning if define or undef reserved identifier or keyword. 2014-12-11 12:18:08 +00:00
cxx_oper_spelling.cpp FileCheck-ify some clang grep tests that use double quotes 2013-04-10 21:10:39 +00:00
cxx_or.cpp
cxx_true.cpp Avoid false positive/negative test results from line directive interference.NFC. 2015-06-26 17:49:10 +00:00
cxx_xor.cpp
dependencies-and-pp.c Fix failing dependencies-and-pp.c test 2013-04-11 13:43:19 +00:00
directive-invalid.c
disabled-cond-diags.c Migrate tests to -verify 2013-01-26 17:11:39 +00:00
disabled-cond-diags2.c Do not complain about junk on the end of a #endif in a skipped block. Such junk 2012-06-21 00:35:03 +00:00
dump-macros-spacing.c
dump-macros-undef.c
dump-options.c
dump_macros.c
dumptokens_phyloc.c
elfiamcu-predefines.c Correct setting of UserLabelPrefix for MCU target. 2016-01-14 10:59:36 +00:00
expr_comma.c
expr_define_expansion.c Add -Wexpansion-to-undefined: warn when using `defined` in a macro definition. 2016-01-19 15:15:31 +00:00
expr_invalid_tok.c
expr_liveness.c
expr_multichar.c Prior to adding the new "expected-no-diagnostics" directive to VerifyDiagnosticConsumer, make the necessary adjustment to 580 test-cases which will henceforth require this new directive. 2012-10-19 12:44:48 +00:00
expr_usual_conversions.c
extension-warning.c
feature_tests.c Preprocessor: Recover instead of mutating a token in ExpandBuiltinMacro 2014-12-15 09:03:58 +00:00
file_to_include.h
first-line-indent.c Fix the indentation of the first line of preprocessor output 2013-01-28 04:37:37 +00:00
function_macro_file.c
function_macro_file.h
has_attribute.c Disable __has_cpp_attribute when not compiling in C++ mode. As this feature test macro only supports C++ style attributes, it doesn't apply to code compiled as C code, and can lead to diagnostics when given a scoped attribute. 2015-05-11 14:09:50 +00:00
has_attribute.cpp Added a new preprocessor macro: __has_declspec_attribute. This can be used as a way to determine whether Clang supports a __declspec spelling for a given attribute, similar to __has_attribute and __has_cpp_attribute. 2014-12-05 15:05:29 +00:00
has_include.c [lex] Don't create a garbage token if parsing of __has_include fails. 2015-03-29 15:33:29 +00:00
hash_line.c Make Preprocessor::Lex non-recursive. 2013-09-19 00:41:32 +00:00
hash_space.c
header_lookup1.c Move a bunch of tests to directly use the CC1 layer. This at least saves 2014-01-15 09:08:07 +00:00
headermap-rel.c [HeaderSearch] Fix issue where if a headermap entry maps the filename to a framework import (non-absolute path) 2014-03-11 06:21:28 +00:00
headermap-rel2.c test: Disable standard system includes in %clang_cc1 2014-10-03 22:18:49 +00:00
if_warning.c Only ignore extra tokens after #else if we skip it, otherwise warn. Fixes rdar://9475098. 2011-05-21 04:26:04 +00:00
ifdef-recover.c Preprocessor: support defined() with operator names for MS compatibility 2014-05-21 06:13:51 +00:00
ignore-pragmas.c Revert "clang/test/Driver/crash-report.c: This requires rewriter for -frewrite-includes. [PR20321]" 2014-07-16 15:12:48 +00:00
import_self.c [clang-tests] Changed relative paths to absolute paths in run command for annotate-macro-args.m, get-cursor-macro-args.m, import_self.c. 2012-10-01 23:39:44 +00:00
include-directive1.c
include-directive2.c test/Preprocessor/include-directive2.c: Get rid of using <float.h> to avoid #include_next on mingw. 2011-07-11 14:53:27 +00:00
include-directive3.c
include-macros.c
include-pth.c
indent_macro.c
init-v7k-compat.c ARMv7k: implement ABI changes for watchOS from standard iOS. 2015-10-30 16:30:45 +00:00
init.c [WebAssembly] Change long double to be quadruple-precision floating point. 2015-11-10 21:01:46 +00:00
invalid-__has_warning1.c Refactored duplicate string literal lexing code within Preprocessor, into a 2012-11-17 19:15:38 +00:00
invalid-__has_warning2.c Refactored duplicate string literal lexing code within Preprocessor, into a 2012-11-17 19:15:38 +00:00
iwithprefix.c [multilib] Teach Clang's code about multilib by threading 2014-12-29 12:09:08 +00:00
line-directive-output.c Properly escape filenames in line directives. 2013-08-29 01:42:42 +00:00
line-directive.c Switch C compilations to C11 by default. 2014-10-20 23:26:58 +00:00
macho-embedded-predefines.c ARM: Correctly identify cortex-m4 as v7em. 2014-06-26 17:24:16 +00:00
macro-multiline.c Enable passing test on Windows + MSYS. 2015-08-16 19:02:49 +00:00
macro-reserved-cxx11.cpp [Tests] Add explicit -std=lang option to a number of tests. 2015-08-01 02:55:59 +00:00
macro-reserved-ms.c Fixed warnings on redefine keywords and reserved ids. 2014-12-18 11:14:21 +00:00
macro-reserved.c Fixed warnings on redefine keywords and reserved ids. 2014-12-18 11:14:21 +00:00
macro-reserved.cpp [Tests] Add explicit -std=lang option to a number of tests. 2015-08-01 02:55:59 +00:00
macro_arg_directive.c Lex: Don't let annotation tokens get into macro expansion 2014-12-28 07:42:49 +00:00
macro_arg_directive.h Don't allow #include (and its friends #import, #include_next and 2011-12-16 22:50:01 +00:00
macro_arg_empty.c Fix whitespace handling in empty macro arguments 2014-02-04 19:18:32 +00:00
macro_arg_keyword.c
macro_arg_slocentry_merge.c Stop printing macro backtraces that don't help diagnostics. 2015-08-12 18:24:59 +00:00
macro_arg_slocentry_merge.h [preprocessor] When "merging" macro argument tokens into one SLocEntry chunk, 2012-12-19 23:55:44 +00:00
macro_backslash.c Handle -D arguments ending in a backslash. 2013-08-28 20:35:38 +00:00
macro_disable.c
macro_expand.c FileCheck'ize tests 2013-01-25 20:34:08 +00:00
macro_expand_empty.c If preprocessing results in a token with leading whitespace that was expanded 2014-02-24 20:50:36 +00:00
macro_expandloc.c Migrate tests to -verify and merge them 2013-01-25 20:33:53 +00:00
macro_fn.c Add new diagnostic messages when too many arguments are presented to a 2013-07-23 18:01:49 +00:00
macro_fn_comma_swallow.c
macro_fn_comma_swallow2.c Improved support for removing the comma preceding __VA_ARGS__ where __VA_ARGS__ 2012-11-09 13:24:30 +00:00
macro_fn_disable_expand.c
macro_fn_lparen_scan.c
macro_fn_lparen_scan2.c
macro_fn_placemarker.c
macro_fn_preexpand.c
macro_fn_varargs_iso.c
macro_fn_varargs_named.c
macro_misc.c [preprocessor] Allow comparing two macro definitions syntactically instead of only lexically. 2013-04-03 17:39:30 +00:00
macro_not_define.c
macro_paste_bad.c Lex: Fix an invalid access into a SmallString 2014-10-25 11:40:40 +00:00
macro_paste_bcpl_comment.c Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
macro_paste_c_block_comment.c Allow -verify directives to be filtered by preprocessing. 2012-07-11 19:58:23 +00:00
macro_paste_commaext.c Fix whitespace handling in ## operator 2014-02-04 19:18:28 +00:00
macro_paste_empty.c [Preprocessor] Prevent expansion of y in x ## y when x is empty 2013-05-25 01:35:18 +00:00
macro_paste_hard.c
macro_paste_hashhash.c When expanding macro arguments, treat '##' coming from an argument as a normal token. 2011-07-07 03:40:37 +00:00
macro_paste_identifier_error.c Prior to adding the new "expected-no-diagnostics" directive to VerifyDiagnosticConsumer, make the necessary adjustment to 580 test-cases which will henceforth require this new directive. 2012-10-19 12:44:48 +00:00
macro_paste_msextensions.c Emit a -Wmicrosoft warning when pasting /##/ into a comment token in MS mode. 2015-12-29 23:06:17 +00:00
macro_paste_none.c
macro_paste_simple.c revert r133003 and fix the bug properly: the issue was that ## in a token 2011-06-14 18:19:37 +00:00
macro_paste_spacing.c Fix whitespace handling in ## operator 2014-02-04 19:18:28 +00:00
macro_paste_spacing2.c
macro_redefined.c Put macro redefinition warnings under -Wmacro-redefined 2014-04-04 00:17:16 +00:00
macro_rescan.c FileCheck'ize tests 2013-02-09 16:41:47 +00:00
macro_rescan2.c
macro_rescan_varargs.c
macro_rparen_scan.c
macro_rparen_scan2.c
macro_space.c Fix whitespace handling in empty macro expansions 2014-02-04 19:18:35 +00:00
macro_undef.c
macro_variadic.cl Add some semantic checks for OpenCL. Variadic macros, VLAs and bitfields are not supported. 2013-01-17 17:35:00 +00:00
macro_with_initializer_list.cpp Add not to a command that is expected to fail. 2013-07-24 18:45:44 +00:00
mi_opt.c
mi_opt.h
mi_opt2.c
mi_opt2.h
microsoft-ext.c Revert "Move -fms-extensions predefined macros into InitPreprocessor" 2014-04-16 20:10:16 +00:00
microsoft-header-search.c Rename -Wmsvc-include to -Wmicrosoft-include, now that -Wmicrosoft is split up. 2015-07-28 16:48:12 +00:00
microsoft-import.c Migrate a test to -verify 2013-01-28 20:55:54 +00:00
missing-system-header.c Change err_pp_file_not_found back to an Error; when it's a Warning, we suppress it in system headers. And it is not a good idea to suppress it in system headers. (This was originally changed in r134996 to implement -MG.) 2011-08-30 23:07:51 +00:00
missing-system-header.h Change err_pp_file_not_found back to an Error; when it's a Warning, we suppress it in system headers. And it is not a good idea to suppress it in system headers. (This was originally changed in r134996 to implement -MG.) 2011-08-30 23:07:51 +00:00
mmx.c Pass a target triple explicitly to check platform specific macros definitions. 2012-05-09 18:49:52 +00:00
non_fragile_feature.m Make -fobjc-nonfragile-abi the -cc1 default, since it's the 2011-10-02 01:16:38 +00:00
non_fragile_feature1.m Rename the GCC Objective-C runtime to gcc from gnu-fragile and the GNUstep 2012-07-03 20:49:52 +00:00
objc-pp.m Prior to adding the new "expected-no-diagnostics" directive to VerifyDiagnosticConsumer, make the necessary adjustment to 580 test-cases which will henceforth require this new directive. 2012-10-19 12:44:48 +00:00
openmp-macro-expansion.c According to the OpenMP spec, all the preprocessor macros should be 2015-06-15 23:44:27 +00:00
optimize.c Don't pass -O0 to clang_cc1, it is the default. 2013-09-04 04:12:25 +00:00
output_paste_avoid.cpp Simplify logic for avoiding concatenation after numeric constants. 2013-02-08 22:30:31 +00:00
overflow.c
pic.c Teach Clang about PIE compilations. This is the first step of PR12380. 2012-04-08 16:40:35 +00:00
pp-modules.c Commit some test changes somehow missed in r239789. 2015-06-16 00:19:29 +00:00
pp-modules.h [test] add missing header for the test. 2013-04-29 17:31:48 +00:00
pp-record.c [preprocessing record] Have the MacroDefinitions map point to the MacroDefinition object instead 2013-02-22 18:35:59 +00:00
pp-record.h [preprocessor] Handle correctly inclusion directives that have macro expansions, e.g 2012-03-27 18:47:48 +00:00
pr2086.c
pr2086.h
pr13851.c Allow -MF to be used in combination with -E -M or -E -MM. 2012-09-26 19:01:49 +00:00
pr19649-signed-wchar_t.c Commit patch for PR19649. Set the correct sign of wide character for literals based on underlying type of wchar_t. 2015-02-24 13:34:20 +00:00
pr19649-unsigned-wchar_t.c Commit patch for PR19649. Set the correct sign of wide character for literals based on underlying type of wchar_t. 2015-02-24 13:34:20 +00:00
pragma-captured.c Parser support for #pragma clang __debug captured 2013-04-16 18:41:26 +00:00
pragma-pushpop-macro.c Fixed a problem with #pragma push_macro/pop_macro implementation. 2012-08-29 16:56:24 +00:00
pragma_diagnostic.c Made the "expected string literal" diagnostic more expressive 2012-11-17 19:16:52 +00:00
pragma_diagnostic_output.c Copy diagnostic pragmas to the preprocessed output, from Richard Osborne! 2011-06-22 19:41:48 +00:00
pragma_diagnostic_sections.cpp
pragma_microsoft.c Parse and ignore #pragma runtime_checks in MS extensions mode (PR25138) 2015-10-12 20:47:58 +00:00
pragma_microsoft.cpp Accept #pragma warning(push, 0) without warning 2013-10-02 15:19:23 +00:00
pragma_poison.c
pragma_ps4.c Adds a warning for unrecognized argument to #pragma comment() on PS4. 2015-03-23 20:41:42 +00:00
pragma_sysheader.c Fix off-by-one error in #pragma clang system_header. 2013-04-17 19:09:18 +00:00
pragma_sysheader.h
pragma_unknown.c FileCheck'ize a test 2013-02-09 16:25:38 +00:00
predefined-arch-macros.c Add the variant of __sparc_v9__ with five underscores, not just four. 2015-11-10 19:28:17 +00:00
predefined-exceptions.m Frontend: Define __EXCEPTIONS if -fexceptions is passed 2014-10-27 20:02:19 +00:00
predefined-macros.c [mips] Add _GCC_HAVE_SYNC_COMPARE_AND_SWAP macros. 2015-12-22 12:59:30 +00:00
predefined-nullability.c Add __nonnull/__nullable/__null_unspecified predefines for Darwin. 2015-06-24 22:02:16 +00:00
print-pragma-microsoft.c Expand macros in pragmas with -fms-extensions and -E 2014-02-20 22:59:51 +00:00
print_line_count.c FileCheck'ize tests 2013-02-09 16:41:47 +00:00
print_line_empty_file.c
print_line_include.c Make sure clang puts tokens from different files on separate lines in "-E -P" mode. <rdar://problem/12774044> 2013-01-09 03:16:42 +00:00
print_line_include.h Make sure clang puts tokens from different files on separate lines in "-E -P" mode. <rdar://problem/12774044> 2013-01-09 03:16:42 +00:00
print_line_track.c
pushable-diagnostics.c
skipping_unclean.c FileCheck'ize tests 2013-02-09 16:41:47 +00:00
stdint.c [SystemZ] Fix definition of IntMaxType / Int64Type 2015-03-30 13:50:21 +00:00
stringize_misc.c
stringize_space.c When copying whitespace flags from the token naming a macro argument onto the 2016-01-15 03:24:18 +00:00
traditional-cpp.c Fix CHECK directives that weren't checking. 2015-08-31 21:48:52 +00:00
ucn-allowed-chars.c Fix the range for Malayam UCNs in C99. 2014-02-05 15:32:23 +00:00
ucn-pp-identifier.c Preprocessor: support defined() with operator names for MS compatibility 2014-05-21 06:13:51 +00:00
undef-error.c Add pedantic warning -Wempty-translation-unit (C11 6.9p1). 2012-06-06 17:25:21 +00:00
unterminated.c
user_defined_system_framework.c Correct test inovocations to use %clang_cc1 rather than direct invocation (so that it can have additional options set when trying to debug issues causing regressions). 2012-10-25 13:56:30 +00:00
utf8-allowed-chars.c Properly validate UCNs for C99 and C++03 (both more restrictive than C(++)11). 2013-02-09 01:10:25 +00:00
warn-disabled-macro-expansion.c Reinstate r173952, this time limiting it to exactly the form 2013-01-30 23:10:17 +00:00
warn-macro-unused.c Split isFromMainFile into two functions. 2013-08-22 00:27:10 +00:00
warn-macro-unused.h Add missing header file for the test. 2011-07-11 21:58:44 +00:00
warning_tests.c Made the "expected string literal" diagnostic more expressive 2012-11-17 19:16:52 +00:00
wasm-target-features.c [WebAssembly] Initial WebAssembly support in clang 2015-09-03 22:51:53 +00:00
woa-defaults.c Driver: add target definition for Windows on ARM 2014-04-04 20:31:19 +00:00
woa-wchar_t.c Target: fix wchar_t definition for Windows on ARM 2014-05-04 01:56:04 +00:00
x86_target_features.c [X86] Add command line switches for xsave/xsaveopt/xsavec/xsaves. Macro defines for the same. And add the flags to correct CPU names. 2015-10-15 05:23:38 +00:00