Re: r364102 - Fix __has_cpp_attribute expansion to produce trailing L and (where

2019-06-21 Thread Reid Kleckner via cfe-commits
I added -P to remove the line markers which were introducing the colons.

On Fri, Jun 21, 2019 at 2:58 PM Galina Kistanova via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hello Richard,
>
> This commit added broken test to the builder:
>
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/26522
> . . .
> Failing Tests (2):
> Clang :: Preprocessor/has_attribute.cpp
>  . . .
>
> Please have a look?
> The builder was already red and did not send notifications.
>
> Thanks
>
> Galina
>
> On Fri, Jun 21, 2019 at 1:20 PM Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: rsmith
>> Date: Fri Jun 21 13:20:21 2019
>> New Revision: 364102
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=364102=rev
>> Log:
>> Fix __has_cpp_attribute expansion to produce trailing L and (where
>> necessary) leading whitespace.
>>
>> Simplify unit test and extend to cover no_unique_address attribute.
>>
>> Modified:
>> cfe/trunk/lib/Lex/PPMacroExpansion.cpp
>> cfe/trunk/test/Preprocessor/has_attribute.cpp
>>
>> Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=364102=364101=364102=diff
>>
>> ==
>> --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
>> +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Fri Jun 21 13:20:21 2019
>> @@ -1330,9 +1330,13 @@ already_lexed:
>>
>>  // The last ')' has been reached; return the value if one found
>> or
>>  // a diagnostic and a dummy value.
>> -if (Result.hasValue())
>> +if (Result.hasValue()) {
>>OS << Result.getValue();
>> -else {
>> +  // For strict conformance to __has_cpp_attribute rules, use 'L'
>> +  // suffix for dated literals.
>> +  if (Result.getValue() > 1)
>> +OS << 'L';
>> +} else {
>>OS << 0;
>>if (!SuppressDiagnostic)
>>  PP.Diag(Tok.getLocation(),
>> diag::err_too_few_args_in_macro_invoc);
>> @@ -1454,6 +1458,8 @@ void Preprocessor::ExpandBuiltinMacro(To
>>// Set up the return result.
>>Tok.setIdentifierInfo(nullptr);
>>Tok.clearFlag(Token::NeedsCleaning);
>> +  bool IsAtStartOfLine = Tok.isAtStartOfLine();
>> +  bool HasLeadingSpace = Tok.hasLeadingSpace();
>>
>>if (II == Ident__LINE__) {
>>  // C99 6.10.8: "__LINE__: The presumed line number (within the
>> current
>> @@ -1807,6 +1813,8 @@ void Preprocessor::ExpandBuiltinMacro(To
>>  llvm_unreachable("Unknown identifier!");
>>}
>>CreateString(OS.str(), Tok, Tok.getLocation(), Tok.getLocation());
>> +  Tok.setFlagValue(Token::StartOfLine, IsAtStartOfLine);
>> +  Tok.setFlagValue(Token::LeadingSpace, HasLeadingSpace);
>>  }
>>
>>  void Preprocessor::markMacroAsUsed(MacroInfo *MI) {
>>
>> Modified: cfe/trunk/test/Preprocessor/has_attribute.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_attribute.cpp?rev=364102=364101=364102=diff
>>
>> ==
>> --- cfe/trunk/test/Preprocessor/has_attribute.cpp (original)
>> +++ cfe/trunk/test/Preprocessor/has_attribute.cpp Fri Jun 21 13:20:21 2019
>> @@ -1,98 +1,80 @@
>> -// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility
>> -std=c++11 -E %s -o - | FileCheck %s
>> +// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility
>> -std=c++11 -E %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM
>> --implicit-check-not=:
>> +// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E
>> %s -o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
>>
>> -// CHECK: has_cxx11_carries_dep
>> -#if __has_cpp_attribute(carries_dependency)
>> -  int has_cxx11_carries_dep();
>> -#endif
>> -
>> -// CHECK: has_clang_fallthrough_1
>> -#if __has_cpp_attribute(clang::fallthrough)
>> -  int has_clang_fallthrough_1();
>> -#endif
>> -
>> -// CHECK: does_not_have_selectany
>> -#if !__has_cpp_attribute(selectany)
>> -  int does_not_have_selectany();
>> -#endif
>> +#define CXX11(x) x: __has_cpp_attribute(x)
>> +
>> +// CHECK: clang::fallthrough: 201603L
>> +CXX11(clang::fallthrough)
>> +
>> +// CHECK: selectany: 0
>> +CXX11(selectany)
>>
>>  // The attribute name can be bracketed with double underscores.
>> -// CHECK: has_clang_fallthrough_2
>> -#if __has_cpp_attribute(clang::__fallthrough__)
>> -  int has_clang_fallthrough_2();
>> -#endif
>> +// CHECK: clang::__fallthrough__: 201603L
>> +CXX11(clang::__fallthrough__)
>>
>>  // The scope cannot be bracketed with double underscores unless it is
>>  // for gnu or clang.
>> -// CHECK: does_not_have___gsl___suppress
>> -#if !__has_cpp_attribute(__gsl__::suppress)
>> -  int does_not_have___gsl___suppress();
>> -#endif
>> +// CHECK: __gsl__::suppress: 0
>> +CXX11(__gsl__::suppress)
>>
>>  // We do somewhat 

Re: r364102 - Fix __has_cpp_attribute expansion to produce trailing L and (where

2019-06-21 Thread Galina Kistanova via cfe-commits
Hello Richard,

This commit added broken test to the builder:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/26522
. . .
Failing Tests (2):
Clang :: Preprocessor/has_attribute.cpp
 . . .

Please have a look?
The builder was already red and did not send notifications.

Thanks

Galina

On Fri, Jun 21, 2019 at 1:20 PM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Fri Jun 21 13:20:21 2019
> New Revision: 364102
>
> URL: http://llvm.org/viewvc/llvm-project?rev=364102=rev
> Log:
> Fix __has_cpp_attribute expansion to produce trailing L and (where
> necessary) leading whitespace.
>
> Simplify unit test and extend to cover no_unique_address attribute.
>
> Modified:
> cfe/trunk/lib/Lex/PPMacroExpansion.cpp
> cfe/trunk/test/Preprocessor/has_attribute.cpp
>
> Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=364102=364101=364102=diff
>
> ==
> --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
> +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Fri Jun 21 13:20:21 2019
> @@ -1330,9 +1330,13 @@ already_lexed:
>
>  // The last ')' has been reached; return the value if one found or
>  // a diagnostic and a dummy value.
> -if (Result.hasValue())
> +if (Result.hasValue()) {
>OS << Result.getValue();
> -else {
> +  // For strict conformance to __has_cpp_attribute rules, use 'L'
> +  // suffix for dated literals.
> +  if (Result.getValue() > 1)
> +OS << 'L';
> +} else {
>OS << 0;
>if (!SuppressDiagnostic)
>  PP.Diag(Tok.getLocation(),
> diag::err_too_few_args_in_macro_invoc);
> @@ -1454,6 +1458,8 @@ void Preprocessor::ExpandBuiltinMacro(To
>// Set up the return result.
>Tok.setIdentifierInfo(nullptr);
>Tok.clearFlag(Token::NeedsCleaning);
> +  bool IsAtStartOfLine = Tok.isAtStartOfLine();
> +  bool HasLeadingSpace = Tok.hasLeadingSpace();
>
>if (II == Ident__LINE__) {
>  // C99 6.10.8: "__LINE__: The presumed line number (within the current
> @@ -1807,6 +1813,8 @@ void Preprocessor::ExpandBuiltinMacro(To
>  llvm_unreachable("Unknown identifier!");
>}
>CreateString(OS.str(), Tok, Tok.getLocation(), Tok.getLocation());
> +  Tok.setFlagValue(Token::StartOfLine, IsAtStartOfLine);
> +  Tok.setFlagValue(Token::LeadingSpace, HasLeadingSpace);
>  }
>
>  void Preprocessor::markMacroAsUsed(MacroInfo *MI) {
>
> Modified: cfe/trunk/test/Preprocessor/has_attribute.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_attribute.cpp?rev=364102=364101=364102=diff
>
> ==
> --- cfe/trunk/test/Preprocessor/has_attribute.cpp (original)
> +++ cfe/trunk/test/Preprocessor/has_attribute.cpp Fri Jun 21 13:20:21 2019
> @@ -1,98 +1,80 @@
> -// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility
> -std=c++11 -E %s -o - | FileCheck %s
> +// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility
> -std=c++11 -E %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM
> --implicit-check-not=:
> +// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E
> %s -o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
>
> -// CHECK: has_cxx11_carries_dep
> -#if __has_cpp_attribute(carries_dependency)
> -  int has_cxx11_carries_dep();
> -#endif
> -
> -// CHECK: has_clang_fallthrough_1
> -#if __has_cpp_attribute(clang::fallthrough)
> -  int has_clang_fallthrough_1();
> -#endif
> -
> -// CHECK: does_not_have_selectany
> -#if !__has_cpp_attribute(selectany)
> -  int does_not_have_selectany();
> -#endif
> +#define CXX11(x) x: __has_cpp_attribute(x)
> +
> +// CHECK: clang::fallthrough: 201603L
> +CXX11(clang::fallthrough)
> +
> +// CHECK: selectany: 0
> +CXX11(selectany)
>
>  // The attribute name can be bracketed with double underscores.
> -// CHECK: has_clang_fallthrough_2
> -#if __has_cpp_attribute(clang::__fallthrough__)
> -  int has_clang_fallthrough_2();
> -#endif
> +// CHECK: clang::__fallthrough__: 201603L
> +CXX11(clang::__fallthrough__)
>
>  // The scope cannot be bracketed with double underscores unless it is
>  // for gnu or clang.
> -// CHECK: does_not_have___gsl___suppress
> -#if !__has_cpp_attribute(__gsl__::suppress)
> -  int does_not_have___gsl___suppress();
> -#endif
> +// CHECK: __gsl__::suppress: 0
> +CXX11(__gsl__::suppress)
>
>  // We do somewhat support the __clang__ vendor namespace, but it is a
>  // predefined macro and thus we encourage users to use _Clang instead.
>  // Because of this, we do not support __has_cpp_attribute for that
>  // vendor namespace.
> -// CHECK: does_not_have___clang___fallthrough
> -#if !__has_cpp_attribute(__clang__::fallthrough)
> -  int 

r364102 - Fix __has_cpp_attribute expansion to produce trailing L and (where

2019-06-21 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Jun 21 13:20:21 2019
New Revision: 364102

URL: http://llvm.org/viewvc/llvm-project?rev=364102=rev
Log:
Fix __has_cpp_attribute expansion to produce trailing L and (where
necessary) leading whitespace.

Simplify unit test and extend to cover no_unique_address attribute.

Modified:
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/test/Preprocessor/has_attribute.cpp

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=364102=364101=364102=diff
==
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Fri Jun 21 13:20:21 2019
@@ -1330,9 +1330,13 @@ already_lexed:
 
 // The last ')' has been reached; return the value if one found or
 // a diagnostic and a dummy value.
-if (Result.hasValue())
+if (Result.hasValue()) {
   OS << Result.getValue();
-else {
+  // For strict conformance to __has_cpp_attribute rules, use 'L'
+  // suffix for dated literals.
+  if (Result.getValue() > 1)
+OS << 'L';
+} else {
   OS << 0;
   if (!SuppressDiagnostic)
 PP.Diag(Tok.getLocation(), diag::err_too_few_args_in_macro_invoc);
@@ -1454,6 +1458,8 @@ void Preprocessor::ExpandBuiltinMacro(To
   // Set up the return result.
   Tok.setIdentifierInfo(nullptr);
   Tok.clearFlag(Token::NeedsCleaning);
+  bool IsAtStartOfLine = Tok.isAtStartOfLine();
+  bool HasLeadingSpace = Tok.hasLeadingSpace();
 
   if (II == Ident__LINE__) {
 // C99 6.10.8: "__LINE__: The presumed line number (within the current
@@ -1807,6 +1813,8 @@ void Preprocessor::ExpandBuiltinMacro(To
 llvm_unreachable("Unknown identifier!");
   }
   CreateString(OS.str(), Tok, Tok.getLocation(), Tok.getLocation());
+  Tok.setFlagValue(Token::StartOfLine, IsAtStartOfLine);
+  Tok.setFlagValue(Token::LeadingSpace, HasLeadingSpace);
 }
 
 void Preprocessor::markMacroAsUsed(MacroInfo *MI) {

Modified: cfe/trunk/test/Preprocessor/has_attribute.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_attribute.cpp?rev=364102=364101=364102=diff
==
--- cfe/trunk/test/Preprocessor/has_attribute.cpp (original)
+++ cfe/trunk/test/Preprocessor/has_attribute.cpp Fri Jun 21 13:20:21 2019
@@ -1,98 +1,80 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 
-E %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 
-E %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM --implicit-check-not=:
+// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E %s -o 
- | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 
-// CHECK: has_cxx11_carries_dep
-#if __has_cpp_attribute(carries_dependency)
-  int has_cxx11_carries_dep();
-#endif
-
-// CHECK: has_clang_fallthrough_1
-#if __has_cpp_attribute(clang::fallthrough)
-  int has_clang_fallthrough_1();
-#endif
-
-// CHECK: does_not_have_selectany
-#if !__has_cpp_attribute(selectany)
-  int does_not_have_selectany();
-#endif
+#define CXX11(x) x: __has_cpp_attribute(x)
+
+// CHECK: clang::fallthrough: 201603L
+CXX11(clang::fallthrough)
+
+// CHECK: selectany: 0
+CXX11(selectany)
 
 // The attribute name can be bracketed with double underscores.
-// CHECK: has_clang_fallthrough_2
-#if __has_cpp_attribute(clang::__fallthrough__)
-  int has_clang_fallthrough_2();
-#endif
+// CHECK: clang::__fallthrough__: 201603L
+CXX11(clang::__fallthrough__)
 
 // The scope cannot be bracketed with double underscores unless it is
 // for gnu or clang.
-// CHECK: does_not_have___gsl___suppress
-#if !__has_cpp_attribute(__gsl__::suppress)
-  int does_not_have___gsl___suppress();
-#endif
+// CHECK: __gsl__::suppress: 0
+CXX11(__gsl__::suppress)
 
 // We do somewhat support the __clang__ vendor namespace, but it is a
 // predefined macro and thus we encourage users to use _Clang instead.
 // Because of this, we do not support __has_cpp_attribute for that
 // vendor namespace.
-// CHECK: does_not_have___clang___fallthrough
-#if !__has_cpp_attribute(__clang__::fallthrough)
-  int does_not_have___clang___fallthrough();
-#endif
-
-// CHECK: does_have_Clang_fallthrough
-#if __has_cpp_attribute(_Clang::fallthrough)
-  int does_have_Clang_fallthrough();
-#endif
-
-// CHECK: has_gnu_const
-#if __has_cpp_attribute(__gnu__::__const__)
-  int has_gnu_const();
-#endif
-
-// Test that C++11, target-specific attributes behave properly.
-
-// CHECK: does_not_have_mips16
-#if !__has_cpp_attribute(gnu::mips16)
-  int does_not_have_mips16();
-#endif
-
-// Test that the version numbers of attributes listed in SD-6 are supported
-// correctly.
-
-// CHECK: has_cxx11_carries_dep_vers
-#if __has_cpp_attribute(carries_dependency) == 200809
-