From: Richard Smith Date: Thu, 7 Apr 2016 20:47:37 +0000 (+0000) Subject: [modules] Allow differences in flags that only affect preprocessor predefines X-Git-Tag: llvmorg-3.9.0-rc1~9695 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a1ddf5e74433b9fbe99d9d26a3297c2f90b1da5e;p=platform%2Fupstream%2Fllvm.git [modules] Allow differences in flags that only affect preprocessor predefines (and __has_feature checks) between explicitly-specified module files and the current compilation. llvm-svn: 265718 --- diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 43e96d1..13aa595 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -24,11 +24,15 @@ // // VALUE_LANGOPT: for options that describe a value rather than a flag. // -// BENIGN_ENUM_LANGOPT, COMPATIBLE_ENUM_LANGOPT: combinations of the above. +// BENIGN_ENUM_LANGOPT, COMPATIBLE_ENUM_LANGOPT, +// BENIGN_VALUE_LANGOPT, COMPATIBLE_VALUE_LANGOPT: combinations of the above. // // FIXME: Clients should be able to more easily select whether they want // different levels of compatibility versus how to handle different kinds // of option. +// +// The Description field should be a noun phrase, for instance "frobbing all +// widgets" or "C's implicit blintz feature". //===----------------------------------------------------------------------===// #ifndef LANGOPT @@ -65,6 +69,16 @@ LANGOPT(Name, Bits, Default, Description) #endif +#ifndef COMPATIBLE_VALUE_LANGOPT +# define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) \ + VALUE_LANGOPT(Name, Bits, Default, Description) +#endif + +#ifndef BENIGN_VALUE_LANGOPT +# define BENIGN_VALUE_LANGOPT(Name, Bits, Default, Description) \ + COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) +#endif + // FIXME: A lot of the BENIGN_ options should be COMPATIBLE_ instead. LANGOPT(C99 , 1, 0, "C99") LANGOPT(C11 , 1, 0, "C11") @@ -124,32 +138,32 @@ LANGOPT(Coroutines , 1, 0, "C++ coroutines") BENIGN_LANGOPT(ThreadsafeStatics , 1, 1, "thread-safe static initializers") LANGOPT(POSIXThreads , 1, 0, "POSIX thread support") LANGOPT(Blocks , 1, 0, "blocks extension to C") -BENIGN_LANGOPT(EmitAllDecls , 1, 0, "support for emitting all declarations") -LANGOPT(MathErrno , 1, 1, "errno support for math functions") -BENIGN_LANGOPT(HeinousExtensions , 1, 0, "Extensions that we really don't like and may be ripped out at any time") +BENIGN_LANGOPT(EmitAllDecls , 1, 0, "emitting all declarations") +LANGOPT(MathErrno , 1, 1, "errno in math functions") +BENIGN_LANGOPT(HeinousExtensions , 1, 0, "extensions that we really don't like and may be ripped out at any time") LANGOPT(Modules , 1, 0, "modules extension to C") BENIGN_LANGOPT(CompilingModule, 1, 0, "compiling a module interface") COMPATIBLE_LANGOPT(ModulesDeclUse , 1, 0, "require declaration of module uses") -LANGOPT(ModulesSearchAll , 1, 1, "search even non-imported modules to find unresolved references") -COMPATIBLE_LANGOPT(ModulesStrictDeclUse, 1, 0, "require declaration of module uses and all headers to be in modules") -BENIGN_LANGOPT(ModulesErrorRecovery, 1, 1, "automatically import modules as needed when performing error recovery") -BENIGN_LANGOPT(ImplicitModules, 1, 1, "build modules that are not specified via -fmodule-file") +BENIGN_LANGOPT(ModulesSearchAll , 1, 1, "searching even non-imported modules to find unresolved references") +COMPATIBLE_LANGOPT(ModulesStrictDeclUse, 1, 0, "requiring declaration of module uses and all headers to be in modules") +BENIGN_LANGOPT(ModulesErrorRecovery, 1, 1, "automatically importing modules as needed when performing error recovery") +BENIGN_LANGOPT(ImplicitModules, 1, 1, "building modules that are not specified via -fmodule-file") COMPATIBLE_LANGOPT(ModulesLocalVisibility, 1, 0, "local submodule visibility") COMPATIBLE_LANGOPT(Optimize , 1, 0, "__OPTIMIZE__ predefined macro") COMPATIBLE_LANGOPT(OptimizeSize , 1, 0, "__OPTIMIZE_SIZE__ predefined macro") -LANGOPT(Static , 1, 0, "__STATIC__ predefined macro (as opposed to __DYNAMIC__)") +COMPATIBLE_LANGOPT(Static , 1, 0, "__STATIC__ predefined macro (as opposed to __DYNAMIC__)") VALUE_LANGOPT(PackStruct , 32, 0, "default struct packing maximum alignment") VALUE_LANGOPT(MaxTypeAlign , 32, 0, "default maximum alignment for types") -VALUE_LANGOPT(PICLevel , 2, 0, "__PIC__ level") -VALUE_LANGOPT(PIELevel , 2, 0, "__PIE__ level") -LANGOPT(GNUInline , 1, 0, "GNU inline semantics") +COMPATIBLE_VALUE_LANGOPT(PICLevel , 2, 0, "__PIC__ level") +COMPATIBLE_VALUE_LANGOPT(PIELevel , 2, 0, "__PIE__ level") +COMPATIBLE_LANGOPT(GNUInline , 1, 0, "GNU inline semantics") COMPATIBLE_LANGOPT(NoInlineDefine , 1, 0, "__NO_INLINE__ predefined macro") COMPATIBLE_LANGOPT(Deprecated , 1, 0, "__DEPRECATED predefined macro") -LANGOPT(FastMath , 1, 0, "__FAST_MATH__ predefined macro") -LANGOPT(FiniteMathOnly , 1, 0, "__FINITE_MATH_ONLY__ predefined macro") -LANGOPT(UnsafeFPMath , 1, 0, "Unsafe Floating Point Math") +COMPATIBLE_LANGOPT(FastMath , 1, 0, "__FAST_MATH__ predefined macro") +COMPATIBLE_LANGOPT(FiniteMathOnly , 1, 0, "__FINITE_MATH_ONLY__ predefined macro") +COMPATIBLE_LANGOPT(UnsafeFPMath , 1, 0, "Unsafe Floating Point Math") BENIGN_LANGOPT(ObjCGCBitmapPrint , 1, 0, "printing of GC's bitmap layout for __weak/__strong ivars") @@ -246,4 +260,6 @@ LANGOPT(SanitizeAddressFieldPadding, 2, 0, "controls how aggressive is ASan " #undef COMPATIBLE_ENUM_LANGOPT #undef BENIGN_ENUM_LANGOPT #undef VALUE_LANGOPT +#undef COMPATIBLE_VALUE_LANGOPT +#undef BENIGN_VALUE_LANGOPT diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index c0517e7..0ca6c0f 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -217,8 +217,13 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, if (!AllowCompatibleDifferences) \ ENUM_LANGOPT(Name, Bits, Default, Description) +#define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) \ + if (!AllowCompatibleDifferences) \ + VALUE_LANGOPT(Name, Bits, Default, Description) + #define BENIGN_LANGOPT(Name, Bits, Default, Description) #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) +#define BENIGN_VALUE_LANGOPT(Name, Type, Bits, Default, Description) #include "clang/Basic/LangOptions.def" if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) { diff --git a/clang/test/Modules/explicit-build-flags.cpp b/clang/test/Modules/explicit-build-flags.cpp index 6ced215..12523fa 100644 --- a/clang/test/Modules/explicit-build-flags.cpp +++ b/clang/test/Modules/explicit-build-flags.cpp @@ -7,8 +7,7 @@ // Can use the module. // RUN: %clang_cc1 -fmodules -DFOO=1 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s -// Can use the module if an input file is newer. (This happens on -// remote file systems.) +// Can use the module if an input file is newer. (This happens on remote file systems.) // RUN: sleep 1 // RUN: touch %t/tmp.h // RUN: %clang_cc1 -fmodules -DFOO=1 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s @@ -23,6 +22,19 @@ // Can use the module if -I flags change. // RUN: %clang_cc1 -fmodules -DBAR=2 -I. -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s +// Can use the module if -fPIC/-fPIE flags change. +// RUN: %clang_cc1 -fmodules -DBAR=2 -pic-level 2 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s +// RUN: %clang_cc1 -fmodules -DBAR=2 -pie-level 1 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s + +// Can use the module if -static flag changes. +// RUN: %clang_cc1 -fmodules -DBAR=2 -static-define -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s + +// Can use the module if -fsanitize= flags change. +// RUN: %clang_cc1 -fmodules -DBAR=2 -fsanitize=address -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s +// +// RUN: %clang_cc1 -fmodules -DFOO=1 -fsanitize=address -x c++ -fmodule-name=tmp %t/map -emit-module -o %t/tmp-san.pcm +// RUN: %clang_cc1 -fmodules -DBAR=2 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp-san.pcm -verify -I%t %s + // Can use the module if -O flags change. // RUN: %clang_cc1 -fmodules -DBAR=2 -Os -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s //