[PATCH] D85528: [analyzer] Fix cast evaluation on scoped enums in ExprEngine

2020-08-09 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Looks reasonable to me, but I am not very familiar with the impacts of the 
additional casts. Do we lose some modeling power when we are using the regular 
constraint solver?

For example, when we have constraints both on the original and the cased symbol 
can the analyzer "merge" them?

Something like:

  ScopedPrimitive sym = conjure();
  if (sym == ScopedPrimitive::Max)
return;
  int sym2 = static_cast(sym);
  if (sym2 == 0)
return;
  // Do we know here that both sym and sym2 has the same range?
  // Is there a change in the behavior compared to before the patch?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85528/new/

https://reviews.llvm.org/D85528

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77598: Integral template argument suffix and cast printing

2020-08-09 Thread Pratyush Das via Phabricator via cfe-commits
reikdas updated this revision to Diff 284181.
reikdas edited the summary of this revision.
reikdas added a comment.

Addresses inline comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77598/new/

https://reviews.llvm.org/D77598

Files:
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -459,3 +459,13 @@
   X y;
   int n = y.call(); // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'void *'}}
 }
+
+namespace PR9227 {
+  template  struct S {};
+  template <> struct S<1> { using type = int; }; // expected-note {{'S<1>::type' declared here}}
+  S<1L>::type t; // expected-error {{no type named 'type' in 'PR9227::S<1L>'; did you mean 'S<1>::type'?}}
+
+  template  struct A {};
+  template <> struct A<1> { using type = int; }; // expected-note {{'A<1>::type' declared here}}
+  A<2>::type x; // expected-error {{no type named 'type' in 'PR9227::A<2>'; did you mean 'A<1>::type'?}}
+}
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -270,6 +270,23 @@
   void test_char_possibly_negative() { enable_if_char<'\x02'>::type i; } // expected-error{{enable_if_char<'\x02'>'; did you mean 'enable_if_char<'a'>::type'?}}
   void test_char_single_quote() { enable_if_char<'\''>::type i; } // expected-error{{enable_if_char<'\''>'; did you mean 'enable_if_char<'a'>::type'?}}
   void test_char_backslash() { enable_if_char<'\\'>::type i; } // expected-error{{enable_if_char<'\\'>'; did you mean 'enable_if_char<'a'>::type'?}}
+
+  template  struct enable_if_int {};
+  template <> struct enable_if_int<1> { typedef int type; }; // expected-note{{'enable_if_int<1>::type' declared here}}
+  void test_int() { enable_if_int<2>::type i; } // expected-error{{enable_if_int<2>'; did you mean 'enable_if_int<1>::type'?}}
+
+  template  struct enable_if_unsigned_int {};
+  template <> struct enable_if_unsigned_int<1> { typedef int type; }; // expected-note{{'enable_if_unsigned_int<1>::type' declared here}}
+  void test_unsigned_int() { enable_if_unsigned_int<2>::type i; } // expected-error{{enable_if_unsigned_int<2>'; did you mean 'enable_if_unsigned_int<1>::type'?}}
+
+  template  struct enable_if_unsigned_long_long {};
+  template <> struct enable_if_unsigned_long_long<1> { typedef int type; }; // expected-note{{'enable_if_unsigned_long_long<1>::type' declared here}}
+  void test_unsigned_long_long() { enable_if_unsigned_long_long<2>::type i; } // expected-error{{enable_if_unsigned_long_long<2>'; did you mean 'enable_if_unsigned_long_long<1>::type'?}}
+
+  template  struct enable_if_long_long {};
+  template <> struct enable_if_long_long<1> { typedef int type; }; // expected-note{{'enable_if_long_long<1>::type' declared here}}
+  void test_long_long() { enable_if_long_long<2>::type i; } // expected-error{{enable_if_long_long<2>'; did you mean 'enable_if_long_long<1>::type'?}}
+
 }
 
 namespace PR10579 {
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -6820,7 +6820,7 @@
   return ArgResult;
 }
 
-QualType CanonParamType = Context.getCanonicalType(ParamType);
+QualType CanonParamType = ParamType;
 
 // Convert the APValue to a TemplateArgument.
 switch (Value.getKind()) {
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -70,13 +70,51 @@
 
   if (T->isBooleanType() && !Policy.MSVCFormatting) {
 Out << (Val.getBoolValue() ? "true" : "false");
+  } else if (T->isBooleanType()) {
+Out << Val;
   } else if (T->isCharType()) {
 const char Ch = Val.getZExtValue();
 Out << ((Ch == '\'') ? "'\\" : "'");
 Out.write_escaped(StringRef(&Ch, 1), /*UseHexEscapes=*/ true);
 Out << "'";
   } else {
-Out << Val;
+bool flag = false;
+if (auto *autoT = T->getAs()) {
+  if (autoT->getAs()) {
+flag = true;
+  }
+} else if (T->getAs()) {
+  flag = true;
+}
+if (flag) {
+  if (auto *BT = T->getAs()) {
+switch (BT->getKind()) {
+case BuiltinType::ULongLong:
+  Out << Val << "ULL";
+  break;
+case BuiltinType::LongLong:
+  Out << Val << "LL";
+  break;
+case BuiltinType::ULong:
+  Out << Val << "UL";
+  break;
+case BuiltinType::Long:
+  Out << Val << "L";
+ 

[PATCH] D77598: Integral template argument suffix and cast printing

2020-08-09 Thread Pratyush Das via Phabricator via cfe-commits
reikdas added inline comments.



Comment at: clang/lib/AST/TemplateBase.cpp:71-72
 
   if (T->isBooleanType() && !Policy.MSVCFormatting) {
 Out << (Val.getBoolValue() ? "true" : "false");
   } else if (T->isCharType()) {

rsmith wrote:
> rsmith wrote:
> > It looks like `MSVCFormatting` wants `bool` values to be printed as `0` and 
> > `1`, and this patch presumably changes that (along with the printing of 
> > other builtin types). I wonder if this is a problem in practice (eg, if 
> > such things are used as keys for debug info or similar)...
> Do we need to suppress printing the suffixes below in `MSVCFormatting` mode 
> too?
@rsmith The tests pass, so that is reassuring at least. Is there any other way 
to find out whether we need to suppress printing the suffixes for other types 
in MSVCFormatting mode?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77598/new/

https://reviews.llvm.org/D77598

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 04a23f1 - [Diagnostics] Turn string concat warning to avoid false positives

2020-08-09 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-09T12:22:29+02:00
New Revision: 04a23f1fe08a6ad0baf1305d7308231d2cb4843b

URL: 
https://github.com/llvm/llvm-project/commit/04a23f1fe08a6ad0baf1305d7308231d2cb4843b
DIFF: 
https://github.com/llvm/llvm-project/commit/04a23f1fe08a6ad0baf1305d7308231d2cb4843b.diff

LOG: [Diagnostics] Turn string concat warning to avoid false positives

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/string-concat.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 7560dc996b15..35047a7b2b14 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6911,7 +6911,7 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
   // Diagnose missing comma in string array initialization.
   // Do not warn when all the elements in the initializer are concatenated 
together.
   // Do not warn for macros too.
-  if (NumConcat > 1 && E > 1 && !SL->getBeginLoc().isMacroID()) {
+  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID()) {
 SmallVector Hints;
 for (unsigned i = 0; i < NumConcat - 1; ++i)
   Hints.push_back(FixItHint::CreateInsertion(

diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index 8f087e37d953..c93bbd4eaa00 100644
--- a/clang/test/Sema/string-concat.c
+++ b/clang/test/Sema/string-concat.c
@@ -19,14 +19,16 @@ typedef __WCHAR_TYPE__ wchar_t;
 const wchar_t *missing_comma_wchar[] = {
 L"basic_filebuf",
 L"packaged_task" // expected-note{{place parentheses around the string 
literal to silence warning}}
-L"promise"  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
+L"promise",  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
+L"shared_future"
 };
 
 #if __cplusplus >= 201103L
 const char *missing_comma_u8[] = {
 u8"basic_filebuf",
 u8"packaged_task" // expected-note{{place parentheses around the string 
literal to silence warning}}
-u8"promise"  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
+u8"promise",  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
+u8"shared_future"
 };
 #endif
 
@@ -47,10 +49,11 @@ const char *missing_comma_
diff erent_lines[] = {"basic_filebuf", "basic_ios" // e
 const char *missing_comma_same_line_all_literals[] = {"basic_filebuf", 
"future" "optional", "packaged_task"}; // expected-note{{place parentheses 
around the string literal to silence warning}}

// expected-warning@-1{{suspicious concatenation of string literals in an array 
initialization; did you mean to separate the elements with a comma?}}
 
-char missing_comma_inner[][4] = {
+char missing_comma_inner[][5] = {
 "a",
-"b" // expected-note{{place parentheses around the string literal to 
silence warning}}
-"c" // expected-warning{{suspicious concatenation of string literals in an 
array initialization; did you mean to separate the elements with a comma?}}
+"b",
+"c" // expected-note{{place parentheses around the string literal to 
silence warning}}
+"d" // expected-warning{{suspicious concatenation of string literals in an 
array initialization; did you mean to separate the elements with a comma?}}
 };
 
 
@@ -89,6 +92,18 @@ const char *macro_test4[] = {"basic_filebuf",
 #define SUPPRESS(x) x
 const char *macro_test5[] = { SUPPRESS("foo" "bar"), "baz" };
 
+typedef struct {
+int i;
+const char s[11];
+} S;
+
+S s = {1, "hello" "world"};
+
+const char *not_warn[] = {
+"hello"
+"world", "test"
+};
+
 // Do not warn when all the elements in the initializer are concatenated 
together.
 const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85528: [analyzer] Fix cast evaluation on scoped enums in ExprEngine

2020-08-09 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D85528#2205094 , @xazax.hun wrote:

> Looks reasonable to me, but I am not very familiar with the impacts of the 
> additional casts. Do we lose some modeling power when we are using the 
> regular constraint solver?
>
> For example, when we have constraints both on the original and the cased 
> symbol can the analyzer "merge" them?
>
> Something like:
>
>   ScopedPrimitive sym = conjure();
>   if (sym == ScopedPrimitive::Max)
> return;
>   int sym2 = static_cast(sym);
>   if (sym2 == 0)
> return;
>   // Do we know here that both sym and sym2 has the same range?
>   // Is there a change in the behavior compared to before the patch?

Huh, it's a really interesting question.
Here is the result:

---

Here is the test code:

  enum class ScopedPrimitive : unsigned char { Min = 2, Max = 8 };
  void foo() {
auto sym = conjure();
if (sym == ScopedPrimitive::Max)
  return;
  
int sym2 = static_cast(sym);
if (sym2 == 0)
  return;
  
// Do we know here that both sym and sym2 has the same range?
// Is there a change in the behavior compared to before the patch?
clang_analyzer_printState();
(void)sym;
(void)sym2;
  }

Before the patch:

  "constraints": [
  { "symbol": "conj_$2{enum ScopedPrimitive, LC1, S1083, #1}", "range": "{ 
[1, 7], [9, 255] }" }
]

After the patch:

  "constraints": [
  { "symbol": "conj_$2{enum ScopedPrimitive, LC1, S1881, #1}", "range": "{ 
[0, 7], [9, 255] }" },
  { "symbol": "(unsigned char) (conj_$2{enum ScopedPrimitive, LC1, S1881, 
#1})", "range": "{ [1, 255] }" }
]



---

> For example, when we have constraints both on the original and the cased 
> symbol can the analyzer "merge" them?

Apparently, not xD.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85528/new/

https://reviews.llvm.org/D85528

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85600: [clang-format] use spaces for alignment of binary/ternary expressions with UT_AlignWithSpaces

2020-08-09 Thread Maximilian Fickert via Phabricator via cfe-commits
fickert created this revision.
fickert added reviewers: clang-format, MyDeveloperDay.
fickert added projects: clang-format, clang-tools-extra.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
fickert requested review of this revision.

Use spaces to align binary and ternary expressions when using AlignOperands and 
UT_AlignWithSpaces.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85600

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11259,6 +11259,23 @@
"\t}\n"
"};",
Tab);
+  Tab.AlignOperands = FormatStyle::OAS_Align;
+  verifyFormat("int aa =  +\n"
+   " ;",
+   Tab);
+  // no alignment
+  verifyFormat("int aa =\n"
+   "\t;",
+   Tab);
+  verifyFormat("return  ? 111\n"
+   "   : bb ? 222\n"
+   ": 333;",
+   Tab);
+  Tab.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+  Tab.AlignOperands = FormatStyle::OAS_AlignAfterOperator;
+  verifyFormat("int aa = \n"
+   "   + ;",
+   Tab);
 }
 
 TEST_F(FormatTest, ZeroTabWidth) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1359,6 +1359,14 @@
 !Newline)
   NewParenState.UnindentOperator = true;
 
+if (Style.AlignOperands != FormatStyle::OAS_DontAlign && Previous &&
+(Previous->getPrecedence() == prec::Assignment ||
+ Previous->is(tok::kw_return) ||
+ (*I == prec::Conditional && Previous->is(tok::question) &&
+  Previous->is(TT_ConditionalExpr))) &&
+!Newline)
+  NewParenState.IsAligned = true;
+
 // Do not indent relative to the fake parentheses inserted for "." or "->".
 // This is a special case to make the following to statements consistent:
 //   OuterFunction(InnerFunctionCall( // break


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11259,6 +11259,23 @@
"\t}\n"
"};",
Tab);
+  Tab.AlignOperands = FormatStyle::OAS_Align;
+  verifyFormat("int aa =  +\n"
+   " ;",
+   Tab);
+  // no alignment
+  verifyFormat("int aa =\n"
+   "\t;",
+   Tab);
+  verifyFormat("return  ? 111\n"
+   "   : bb ? 222\n"
+   ": 333;",
+   Tab);
+  Tab.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+  Tab.AlignOperands = FormatStyle::OAS_AlignAfterOperator;
+  verifyFormat("int aa = \n"
+   "   + ;",
+   Tab);
 }
 
 TEST_F(FormatTest, ZeroTabWidth) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1359,6 +1359,14 @@
 !Newline)
   NewParenState.UnindentOperator = true;
 
+if (Style.AlignOperands != FormatStyle::OAS_DontAlign && Previous &&
+(Previous->getPrecedence() == prec::Assignment ||
+ Previous->is(tok::kw_return) ||
+ (*I == prec::Conditional && Previous->is(tok::question) &&
+  Previous->is(TT_ConditionalExpr))) &&
+!Newline)
+  NewParenState.IsAligned = true;
+
 // Do not indent relative to the fake parentheses inserted for "." or "->".
 // This is a special case to make the following to statements consistent:
 //   OuterFunction(InnerFunctionCall( // break
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85600: [clang-format] use spaces for alignment of binary/ternary expressions with UT_AlignWithSpaces

2020-08-09 Thread Maximilian Fickert via Phabricator via cfe-commits
fickert added a comment.

This fixes an oversight in the new `UT_AlignWithSpaces` option (see D75034 
), which did not correctly identify the 
alignment of binary/ternary expressions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85600/new/

https://reviews.llvm.org/D85600

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85528: [analyzer] Fix cast evaluation on scoped enums in ExprEngine

2020-08-09 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I mean, this shouldn't be an issue. Since we already omitted the 'unnecessary' 
cast expressions... That decision is the root cause of this, we should have 
expected that.

IMO we do the right thing here. If we want to treat sym and sym2 to refer to 
the same symbol, we should patch the CM to canonize, and remove such casts 
before storing the constraint.
But the cast symbols should exist for casting scoped enums.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85528/new/

https://reviews.llvm.org/D85528

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77598: Integral template argument suffix and cast printing

2020-08-09 Thread Pratyush Das via Phabricator via cfe-commits
reikdas updated this revision to Diff 284186.
reikdas added a comment.

Can completely replace CanonParamType.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77598/new/

https://reviews.llvm.org/D77598

Files:
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -459,3 +459,13 @@
   X y;
   int n = y.call(); // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'void *'}}
 }
+
+namespace PR9227 {
+  template  struct S {};
+  template <> struct S<1> { using type = int; }; // expected-note {{'S<1>::type' declared here}}
+  S<1L>::type t; // expected-error {{no type named 'type' in 'PR9227::S<1L>'; did you mean 'S<1>::type'?}}
+
+  template  struct A {};
+  template <> struct A<1> { using type = int; }; // expected-note {{'A<1>::type' declared here}}
+  A<2>::type x; // expected-error {{no type named 'type' in 'PR9227::A<2>'; did you mean 'A<1>::type'?}}
+}
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -270,6 +270,23 @@
   void test_char_possibly_negative() { enable_if_char<'\x02'>::type i; } // expected-error{{enable_if_char<'\x02'>'; did you mean 'enable_if_char<'a'>::type'?}}
   void test_char_single_quote() { enable_if_char<'\''>::type i; } // expected-error{{enable_if_char<'\''>'; did you mean 'enable_if_char<'a'>::type'?}}
   void test_char_backslash() { enable_if_char<'\\'>::type i; } // expected-error{{enable_if_char<'\\'>'; did you mean 'enable_if_char<'a'>::type'?}}
+
+  template  struct enable_if_int {};
+  template <> struct enable_if_int<1> { typedef int type; }; // expected-note{{'enable_if_int<1>::type' declared here}}
+  void test_int() { enable_if_int<2>::type i; } // expected-error{{enable_if_int<2>'; did you mean 'enable_if_int<1>::type'?}}
+
+  template  struct enable_if_unsigned_int {};
+  template <> struct enable_if_unsigned_int<1> { typedef int type; }; // expected-note{{'enable_if_unsigned_int<1>::type' declared here}}
+  void test_unsigned_int() { enable_if_unsigned_int<2>::type i; } // expected-error{{enable_if_unsigned_int<2>'; did you mean 'enable_if_unsigned_int<1>::type'?}}
+
+  template  struct enable_if_unsigned_long_long {};
+  template <> struct enable_if_unsigned_long_long<1> { typedef int type; }; // expected-note{{'enable_if_unsigned_long_long<1>::type' declared here}}
+  void test_unsigned_long_long() { enable_if_unsigned_long_long<2>::type i; } // expected-error{{enable_if_unsigned_long_long<2>'; did you mean 'enable_if_unsigned_long_long<1>::type'?}}
+
+  template  struct enable_if_long_long {};
+  template <> struct enable_if_long_long<1> { typedef int type; }; // expected-note{{'enable_if_long_long<1>::type' declared here}}
+  void test_long_long() { enable_if_long_long<2>::type i; } // expected-error{{enable_if_long_long<2>'; did you mean 'enable_if_long_long<1>::type'?}}
+
 }
 
 namespace PR10579 {
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -6820,20 +6820,18 @@
   return ArgResult;
 }
 
-QualType CanonParamType = Context.getCanonicalType(ParamType);
-
 // Convert the APValue to a TemplateArgument.
 switch (Value.getKind()) {
 case APValue::None:
   assert(ParamType->isNullPtrType());
-  Converted = TemplateArgument(CanonParamType, /*isNullPtr*/true);
+  Converted = TemplateArgument(ParamType, /*isNullPtr*/true);
   break;
 case APValue::Indeterminate:
   llvm_unreachable("result of constant evaluation should be initialized");
   break;
 case APValue::Int:
   assert(ParamType->isIntegralOrEnumerationType());
-  Converted = TemplateArgument(Context, Value.getInt(), CanonParamType);
+  Converted = TemplateArgument(Context, Value.getInt(), ParamType);
   break;
 case APValue::MemberPointer: {
   assert(ParamType->isMemberPointerType());
@@ -6848,8 +6846,8 @@
   }
 
   auto *VD = const_cast(Value.getMemberPointerDecl());
-  Converted = VD ? TemplateArgument(VD, CanonParamType)
- : TemplateArgument(CanonParamType, /*isNullPtr*/true);
+  Converted = VD ? TemplateArgument(VD, ParamType)
+ : TemplateArgument(ParamType, /*isNullPtr*/true);
   break;
 }
 case APValue::LValue: {
@@ -6886,8 +6884,8 @@
  "null reference should not be a constant expression");
   assert((!VD || !ParamType->isNullPtrType()) &&
  "

[PATCH] D85601: Fixes an assertion when IntRange processes a throw expression

2020-08-09 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: rsmith, rjmccall.
Mordante added a project: clang.
Mordante requested review of this revision.

Fixes PR46484: Clang crash in clang/lib/Sema/SemaChecking.cpp:10028


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85601

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/conditional-expr.cpp


Index: clang/test/SemaCXX/conditional-expr.cpp
===
--- clang/test/SemaCXX/conditional-expr.cpp
+++ clang/test/SemaCXX/conditional-expr.cpp
@@ -409,3 +409,17 @@
 D d = b ? D{B()} : D{C()};
   }
 }
+
+namespace PR46484 {
+// expected-error@+4{{expected ':'}}
+// expected-note@+3{{to match this '?'}}
+// expected-warning@+2{{variable 'b' is uninitialized}}
+// expected-error@+1 2 {{expected ';' after top level declarator}}
+int a long b = a = b ? throw 0 1
+
+void g() {
+  extern int a;
+  extern long b;
+  long c = a = b ? throw 0 : 1;
+}
+} // namespace PR46484
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10161,7 +10161,13 @@
   return IntRange(EIT->getNumBits(), EIT->isUnsigned());
 
 const BuiltinType *BT = cast(T);
-assert(BT->isInteger());
+if (!BT->isInteger()) {
+  // This can happen in a conditional expression with a throw statement
+  // C++11 [expr.cond]p2
+  //   If either the second or the third operand has type (cv) void, ...
+  assert(BT->isVoidType());
+  IntRange(1, true /*NonNegative*/);
+}
 
 return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
   }


Index: clang/test/SemaCXX/conditional-expr.cpp
===
--- clang/test/SemaCXX/conditional-expr.cpp
+++ clang/test/SemaCXX/conditional-expr.cpp
@@ -409,3 +409,17 @@
 D d = b ? D{B()} : D{C()};
   }
 }
+
+namespace PR46484 {
+// expected-error@+4{{expected ':'}}
+// expected-note@+3{{to match this '?'}}
+// expected-warning@+2{{variable 'b' is uninitialized}}
+// expected-error@+1 2 {{expected ';' after top level declarator}}
+int a long b = a = b ? throw 0 1
+
+void g() {
+  extern int a;
+  extern long b;
+  long c = a = b ? throw 0 : 1;
+}
+} // namespace PR46484
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10161,7 +10161,13 @@
   return IntRange(EIT->getNumBits(), EIT->isUnsigned());
 
 const BuiltinType *BT = cast(T);
-assert(BT->isInteger());
+if (!BT->isInteger()) {
+  // This can happen in a conditional expression with a throw statement
+  // C++11 [expr.cond]p2
+  //   If either the second or the third operand has type (cv) void, ...
+  assert(BT->isVoidType());
+  IntRange(1, true /*NonNegative*/);
+}
 
 return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-09 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

I have finally managed to reproduce the issue on my Windows machine, the latest 
version of the patch should address the issue. The previous logic would fail to 
find zlib altogether on Windows, which is why this issue haven't manifested 
before. `find_package` locates the zlib correctly, but we need to ensure that 
the library that was found can be used.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79219/new/

https://reviews.llvm.org/D79219

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-09 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 284161.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79219/new/

https://reviews.llvm.org/D79219

Files:
  clang/test/CMakeLists.txt
  clang/test/lit.site.cfg.py.in
  compiler-rt/test/lit.common.configured.in
  lld/test/CMakeLists.txt
  lld/test/lit.site.cfg.py.in
  lldb/cmake/modules/LLDBStandalone.cmake
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/config.h.cmake
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CRC.cpp
  llvm/lib/Support/Compression.cpp
  llvm/test/CMakeLists.txt
  llvm/test/lit.site.cfg.py.in
  llvm/unittests/Support/CompressionTest.cpp
  llvm/utils/gn/secondary/clang/test/BUILD.gn
  llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
  llvm/utils/gn/secondary/lld/test/BUILD.gn
  llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
  llvm/utils/gn/secondary/llvm/test/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/test/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/test/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/test/BUILD.gn
@@ -174,9 +174,9 @@
   }
 
   if (llvm_enable_zlib) {
-extra_values += [ "HAVE_LIBZ=1" ]
+extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
+extra_values += [ "LLVM_ENABLE_ZLIB=0" ]  # Must be 0.
   }
 }
 
Index: llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
@@ -295,20 +295,10 @@
 values += [ "LLVM_ENABLE_DIA_SDK=" ]
   }
 
-  # FIXME: Once https://reviews.llvm.org/D79219 is in, remove the two
-  # redundant HAVE_ variables.
   if (llvm_enable_zlib) {
-values += [
-  "HAVE_LIBZ=1",
-  "HAVE_ZLIB_H=1",
-  "LLVM_ENABLE_ZLIB=1",
-]
+values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-values += [
-  "HAVE_LIBZ=",
-  "HAVE_ZLIB_H=",
-  "LLVM_ENABLE_ZLIB=",
-]
+values += [ "LLVM_ENABLE_ZLIB=" ]
   }
 
   if (llvm_enable_libxml2) {
Index: llvm/utils/gn/secondary/lld/test/BUILD.gn
===
--- llvm/utils/gn/secondary/lld/test/BUILD.gn
+++ llvm/utils/gn/secondary/lld/test/BUILD.gn
@@ -49,9 +49,9 @@
   }
 
   if (llvm_enable_zlib) {
-extra_values += [ "HAVE_LIBZ=1" ]
+extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
+extra_values += [ "LLVM_ENABLE_ZLIB=0" ]  # Must be 0.
   }
 
   if (current_cpu == "x64" || current_cpu == "arm64" ||
Index: llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
===
--- llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
+++ llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
@@ -86,8 +86,8 @@
   }
 
   if (llvm_enable_zlib) {
-values += [ "HAVE_LIBZ=1" ]
+values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-values += [ "HAVE_LIBZ=0" ]
+values += [ "LLVM_ENABLE_ZLIB=0" ]
   }
 }
Index: llvm/utils/gn/secondary/clang/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang/test/BUILD.gn
@@ -79,9 +79,9 @@
   }
 
   if (llvm_enable_zlib) {
-extra_values += [ "HAVE_LIBZ=1" ]
+extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
+extra_values += [ "LLVM_ENABLE_ZLIB=0" ]  # Must be 0.
   }
 
   if (host_cpu == "x64") {
Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -21,7 +21,7 @@
 
 namespace {
 
-#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ
+#if LLVM_ENABLE_ZLIB
 
 void TestZlibCompression(StringRef Input, int Level) {
   SmallString<32> Compressed;
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -33,7 +33,7 @@
 config.host_ldflags = '@HOST_LDFLAGS@'
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
-config.have_zlib = @HAVE_LIBZ@
+config.have_zlib = @LLVM_ENABLE_ZLIB@
 config.have_libxar = @HAVE_LIBXAR@
 config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@
 config.enable_ffi = @LLVM_ENABLE_FFI@
Index: llvm/test/CMakeLists.txt
===
--- llvm/test/CMakeLists.txt
+++ llvm/test/CMakeLists.txt
@@ -1,12 +1,12 @@
 llvm_canonicalize_cmake_booleans(
   BUILD_SHARED_LIBS
   HAVE_LIBXAR
-

[PATCH] D85599: [Clang] Consider __builtin_trap() and __builtin_debugtrap() as terminator

2020-08-09 Thread Zhang Kang via Phabricator via cfe-commits
ZhangKang created this revision.
ZhangKang added reviewers: PowerPC, nemanjai, ahatanak, vitalybuka, dblaikie.
ZhangKang added a project: LLVM.
Herald added subscribers: Sanitizers, cfe-commits, steven.zhang, wuzish, 
dexonsmith, kristof.beyls.
Herald added projects: clang, Sanitizers.
ZhangKang requested review of this revision.

In some backend like ARM, PowerPC, TRAP instrcution is as a terminator. 
But in clang, we didn't as __builtin_trap() and  __builtin_debugtrap()  as 
terminator.
This bug has caused 6 lit cases error on PPC.

For below case,

  void test_builtin_trap() {
volatile int i = 0;
__builtin_trap();
volatile int j = i;
  }

we use `clang sim.c -target powerpc-unknown-unknown  -c` to build it, we will 
get below error:

  *** Bad machine code: Non-terminator instruction after the first terminator 
***
  - function:test_builtin_trap
  - basic block: %bb.0 entry (0x1002c61f1f8)
  - instruction: %1:gprc = LWZ 0, %stack.0.i :: (volatile dereferenceable load 
4 from %ir.i)
  First terminator was: TRAP
  
  *** Bad machine code: Non-terminator instruction after the first terminator 
***
  - function:test_builtin_trap
  - basic block: %bb.0 entry (0x1002c61f1f8)
  - instruction: STW killed %1:gprc, 0, %stack.1.j :: (volatile store 4 into 
%ir.j)
  First terminator was: TRAP
  fatal error: error in backend: Found 2 machine code errors.

This patch is to fix above bug.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85599

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc.c
  compiler-rt/test/profile/gcov-__gcov_flush-terminate.c


Index: compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
===
--- compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
+++ compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
@@ -19,6 +19,6 @@
   __gcov_reset();  // CHECK-NEXT: 1: [[#@LINE]]:
   i = 42;  // CHECK-NEXT: 1: [[#@LINE]]:
   __builtin_trap();// CHECK-NEXT: 1: [[#@LINE]]:
-  i = 84;  // CHECK-NEXT: 1: [[#@LINE]]:
-  return 0;// CHECK-NEXT: 1: [[#@LINE]]:
+  i = 84;  // CHECK-NEXT: -: [[#@LINE]]:
+  return 0;// CHECK-NEXT: -: [[#@LINE]]:
 }
Index: clang/test/CodeGen/builtins-ppc.c
===
--- clang/test/CodeGen/builtins-ppc.c
+++ clang/test/CodeGen/builtins-ppc.c
@@ -27,3 +27,23 @@
   // CHECK: call double @llvm.ppc.setrnd(i32 %2)
   res = __builtin_setrnd(x);
 }
+
+void test_builtin_trap() {
+  volatile int i = 0;
+  __builtin_trap();
+  volatile int j = i;
+
+  // CHECK-LABEL: test_builtin_trap
+  // CHECK: call void @llvm.trap()
+  // CHECK: unreachable
+}
+
+void test_builtin_debugtrap() {
+  volatile int i = 0;
+  __builtin_debugtrap();
+  volatile int j = i;
+
+  // CHECK-LABEL: test_builtin_debugtrap
+  // CHECK: call void @llvm.debugtrap()
+  // CHECK: unreachable
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -2351,8 +2351,24 @@
 Function *F = CGM.getIntrinsic(Intrinsic::clear_cache);
 return RValue::get(Builder.CreateCall(F, {Begin, End}));
   }
-  case Builtin::BI__builtin_trap:
-return RValue::get(EmitTrapCall(Intrinsic::trap));
+  case Builtin::BI__builtin_trap: {
+Builder.CreateCall(CGM.getIntrinsic(Intrinsic::trap));
+Builder.CreateUnreachable();
+
+// We do need to preserve an insertion point.
+EmitBlock(createBasicBlock("trap.cont"));
+
+return RValue::get(nullptr);
+  }
+  case Builtin::BI__builtin_debugtrap: {
+Builder.CreateCall(CGM.getIntrinsic(Intrinsic::debugtrap));
+Builder.CreateUnreachable();
+
+// We do need to preserve an insertion point.
+EmitBlock(createBasicBlock("debugtrap.cont"));
+
+return RValue::get(nullptr);
+  }
   case Builtin::BI__debugbreak:
 return RValue::get(EmitTrapCall(Intrinsic::debugtrap));
   case Builtin::BI__builtin_unreachable: {


Index: compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
===
--- compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
+++ compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
@@ -19,6 +19,6 @@
   __gcov_reset();  // CHECK-NEXT: 1: [[#@LINE]]:
   i = 42;  // CHECK-NEXT: 1: [[#@LINE]]:
   __builtin_trap();// CHECK-NEXT: 1: [[#@LINE]]:
-  i = 84;  // CHECK-NEXT: 1: [[#@LINE]]:
-  return 0;// CHECK-NEXT: 1: [[#@LINE]]:
+  i = 84;  // CHECK-NEXT: -: [[#@LINE]]:
+  return 0;// CHECK-NEXT: -: [[#@LINE]]:
 }
Index: clang/test/CodeGen/builtins-ppc.c
===

[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-09 Thread Petr Hosek via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGccbc1485b55f: [CMake] Simplify CMake handling for zlib 
(authored by phosek).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79219/new/

https://reviews.llvm.org/D79219

Files:
  clang/test/CMakeLists.txt
  clang/test/lit.site.cfg.py.in
  compiler-rt/test/lit.common.configured.in
  lld/test/CMakeLists.txt
  lld/test/lit.site.cfg.py.in
  lldb/cmake/modules/LLDBStandalone.cmake
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/config.h.cmake
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CRC.cpp
  llvm/lib/Support/Compression.cpp
  llvm/test/CMakeLists.txt
  llvm/test/lit.site.cfg.py.in
  llvm/unittests/Support/CompressionTest.cpp
  llvm/utils/gn/secondary/clang/test/BUILD.gn
  llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
  llvm/utils/gn/secondary/lld/test/BUILD.gn
  llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
  llvm/utils/gn/secondary/llvm/test/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/test/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/test/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/test/BUILD.gn
@@ -174,9 +174,9 @@
   }
 
   if (llvm_enable_zlib) {
-extra_values += [ "HAVE_LIBZ=1" ]
+extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
+extra_values += [ "LLVM_ENABLE_ZLIB=0" ]  # Must be 0.
   }
 }
 
Index: llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
@@ -295,20 +295,10 @@
 values += [ "LLVM_ENABLE_DIA_SDK=" ]
   }
 
-  # FIXME: Once https://reviews.llvm.org/D79219 is in, remove the two
-  # redundant HAVE_ variables.
   if (llvm_enable_zlib) {
-values += [
-  "HAVE_LIBZ=1",
-  "HAVE_ZLIB_H=1",
-  "LLVM_ENABLE_ZLIB=1",
-]
+values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-values += [
-  "HAVE_LIBZ=",
-  "HAVE_ZLIB_H=",
-  "LLVM_ENABLE_ZLIB=",
-]
+values += [ "LLVM_ENABLE_ZLIB=" ]
   }
 
   if (llvm_enable_libxml2) {
Index: llvm/utils/gn/secondary/lld/test/BUILD.gn
===
--- llvm/utils/gn/secondary/lld/test/BUILD.gn
+++ llvm/utils/gn/secondary/lld/test/BUILD.gn
@@ -49,9 +49,9 @@
   }
 
   if (llvm_enable_zlib) {
-extra_values += [ "HAVE_LIBZ=1" ]
+extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
+extra_values += [ "LLVM_ENABLE_ZLIB=0" ]  # Must be 0.
   }
 
   if (current_cpu == "x64" || current_cpu == "arm64" ||
Index: llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
===
--- llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
+++ llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
@@ -86,8 +86,8 @@
   }
 
   if (llvm_enable_zlib) {
-values += [ "HAVE_LIBZ=1" ]
+values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-values += [ "HAVE_LIBZ=0" ]
+values += [ "LLVM_ENABLE_ZLIB=0" ]
   }
 }
Index: llvm/utils/gn/secondary/clang/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang/test/BUILD.gn
@@ -79,9 +79,9 @@
   }
 
   if (llvm_enable_zlib) {
-extra_values += [ "HAVE_LIBZ=1" ]
+extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
+extra_values += [ "LLVM_ENABLE_ZLIB=0" ]  # Must be 0.
   }
 
   if (host_cpu == "x64") {
Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -21,7 +21,7 @@
 
 namespace {
 
-#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ
+#if LLVM_ENABLE_ZLIB
 
 void TestZlibCompression(StringRef Input, int Level) {
   SmallString<32> Compressed;
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -33,7 +33,7 @@
 config.host_ldflags = '@HOST_LDFLAGS@'
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
-config.have_zlib = @HAVE_LIBZ@
+config.have_zlib = @LLVM_ENABLE_ZLIB@
 config.have_libxar = @HAVE_LIBXAR@
 config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@
 config.enable_ffi = @LLVM_ENABLE_FFI@

[clang] 975467e - [Diagnostics] Handle string concat pattern and avoid false positives

2020-08-09 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-09T16:02:41+02:00
New Revision: 975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e

URL: 
https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e
DIFF: 
https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e.diff

LOG: [Diagnostics] Handle string concat pattern and avoid false positives

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/string-concat.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 35047a7b2b14..74427f8cd7ae 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6908,10 +6908,13 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
 << InitArgList[I]->getSourceRange();
 } else if (const auto *SL = dyn_cast(InitArgList[I])) {
   unsigned NumConcat = SL->getNumConcatenated();
+  const auto *SLNext =
+  dyn_cast(InitArgList[I + 1 < E ? I + 1 : 0]);
   // Diagnose missing comma in string array initialization.
-  // Do not warn when all the elements in the initializer are concatenated 
together.
-  // Do not warn for macros too.
-  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID()) {
+  // Do not warn when all the elements in the initializer are concatenated
+  // together. Do not warn for macros too.
+  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() && SLNext &&
+  NumConcat != SLNext->getNumConcatenated()) {
 SmallVector Hints;
 for (unsigned i = 0; i < NumConcat - 1; ++i)
   Hints.push_back(FixItHint::CreateInsertion(

diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index c93bbd4eaa00..13e9656d2536 100644
--- a/clang/test/Sema/string-concat.c
+++ b/clang/test/Sema/string-concat.c
@@ -61,7 +61,7 @@ char missing_comma_inner[][5] = {
 #define TWO "foo"
 const char *macro_test[] = { ONE("foo") "bar", 
  TWO "bar", 
- "foo" TWO // expected-note{{place parentheses 
around the string literal to silence warning}}
+ "foo" "bar" TWO // expected-note{{place 
parentheses around the string literal to silence warning}}
};  // expected-warning@-1{{suspicious 
concatenation of string literals in an array initialization; did you mean to 
separate the elements with a comma?}}
 
 // Do not warn for macros.
@@ -104,6 +104,12 @@ const char *not_warn[] = {
 "world", "test"
 };
 
+const char *not_warn2[] = {
+"// Aaa\\\n"   " Bbb\\ \n"   " Ccc?" "?/\n",
+"// Aaa\\\r\n" " Bbb\\ \r\n" " Ccc?" "?/\r\n",
+"// Aaa\\\r"   " Bbb\\ \r"   " Ccc?" "?/\r"
+  };
+
 // Do not warn when all the elements in the initializer are concatenated 
together.
 const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83088: Introduce CfgTraits abstraction

2020-08-09 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle updated this revision to Diff 284195.
nhaehnle marked 2 inline comments as done.
nhaehnle added a comment.

  v7:
  - std::forward fix in wrapping_iterator
  - fix typos


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83088/new/

https://reviews.llvm.org/D83088

Files:
  clang/include/clang/Analysis/Analyses/Dominators.h
  llvm/include/llvm/CodeGen/MachineCfgTraits.h
  llvm/include/llvm/IR/CFG.h
  llvm/include/llvm/Support/CfgTraits.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/MachineCfgTraits.cpp
  llvm/lib/IR/CFG.cpp
  llvm/lib/IR/CMakeLists.txt
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CfgTraits.cpp
  llvm/lib/Transforms/Vectorize/VPlanDominatorTree.h
  mlir/include/mlir/IR/Dominance.h

Index: mlir/include/mlir/IR/Dominance.h
===
--- mlir/include/mlir/IR/Dominance.h
+++ mlir/include/mlir/IR/Dominance.h
@@ -10,8 +10,46 @@
 #define MLIR_IR_DOMINANCE_H
 
 #include "mlir/IR/RegionGraphTraits.h"
+#include "llvm/Support/CfgTraits.h"
 #include "llvm/Support/GenericDomTree.h"
 
+namespace mlir {
+
+/// Partial CFG traits for MLIR's CFG, without a value type.
+class CfgTraitsBase : public llvm::CfgTraitsBase {
+public:
+  using ParentType = Region;
+  using BlockRef = Block *;
+  using ValueRef = void;
+
+  static llvm::CfgBlockRef wrapRef(BlockRef block) {
+return makeOpaque(block);
+  }
+  static BlockRef unwrapRef(llvm::CfgBlockRef block) {
+return static_cast(getOpaque(block));
+  }
+};
+
+class CfgTraits : public llvm::CfgTraits {
+public:
+  static Region *getBlockParent(Block *block) { return block->getParent(); }
+
+  static auto predecessors(Block *block) {
+return llvm::inverse_children(block);
+  }
+
+  static auto successors(Block *block) {
+return llvm::children(block);
+  }
+};
+
+} // namespace mlir
+
+template <>
+struct llvm::CfgTraitsFor {
+  using CfgTraits = mlir::CfgTraits;
+};
+
 extern template class llvm::DominatorTreeBase;
 extern template class llvm::DominatorTreeBase;
 
Index: llvm/lib/Transforms/Vectorize/VPlanDominatorTree.h
===
--- llvm/lib/Transforms/Vectorize/VPlanDominatorTree.h
+++ llvm/lib/Transforms/Vectorize/VPlanDominatorTree.h
@@ -18,9 +18,42 @@
 #include "VPlan.h"
 #include "llvm/ADT/GraphTraits.h"
 #include "llvm/IR/Dominators.h"
+#include "llvm/Support/CfgTraits.h"
 
 namespace llvm {
 
+/// Partial CFG traits for VPlan's CFG, without a value type.
+class VPCfgTraitsBase : public CfgTraitsBase {
+public:
+  using ParentType = VPRegionBlock;
+  using BlockRef = VPBlockBase *;
+  using ValueRef = void;
+
+  static CfgBlockRef wrapRef(BlockRef block) {
+return makeOpaque(block);
+  }
+  static BlockRef unwrapRef(CfgBlockRef block) {
+return static_cast(getOpaque(block));
+  }
+};
+
+class VPCfgTraits : public CfgTraits {
+public:
+  static VPRegionBlock *getBlockParent(VPBlockBase *block) {
+return block->getParent();
+  }
+
+  static auto predecessors(VPBlockBase *block) {
+return llvm::inverse_children(block);
+  }
+
+  static auto successors(VPBlockBase *block) {
+return llvm::children(block);
+  }
+};
+
+template <> struct CfgTraitsFor { using CfgTraits = VPCfgTraits; };
+
 /// Template specialization of the standard LLVM dominator tree utility for
 /// VPBlockBases.
 using VPDominatorTree = DomTreeBase;
Index: llvm/lib/Support/CfgTraits.cpp
===
--- /dev/null
+++ llvm/lib/Support/CfgTraits.cpp
@@ -0,0 +1,14 @@
+//===- CfgTraits.cpp - Traits for generically working on CFGs ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/CfgTraits.h"
+
+using namespace llvm;
+
+void CfgInterface::anchor() {}
+void CfgPrinter::anchor() {}
Index: llvm/lib/Support/CMakeLists.txt
===
--- llvm/lib/Support/CMakeLists.txt
+++ llvm/lib/Support/CMakeLists.txt
@@ -71,6 +71,7 @@
   BranchProbability.cpp
   BuryPointer.cpp
   CachePruning.cpp
+  CfgTraits.cpp
   circular_raw_ostream.cpp
   Chrono.cpp
   COM.cpp
Index: llvm/lib/IR/CMakeLists.txt
===
--- llvm/lib/IR/CMakeLists.txt
+++ llvm/lib/IR/CMakeLists.txt
@@ -4,6 +4,7 @@
   Attributes.cpp
   AutoUpgrade.cpp
   BasicBlock.cpp
+  CFG.cpp
   Comdat.cpp
   ConstantFold.cpp
   ConstantRange.cpp
Index: llvm/lib/IR/CFG.cpp
===
--- /dev/null
+++ llvm/lib/IR/CFG.cpp
@@ -0,0 +1,56 @@
+//===- CFG.cpp --*- C++ -*-===//
+//
+// Part of the

[PATCH] D85607: CfgTraits: add CfgInstructionRef

2020-08-09 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle created this revision.
nhaehnle added reviewers: arsenm, foad, sameerds.
Herald added subscribers: cfe-commits, msifontes, jurahul, Kayjukh, grosul1, 
Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, antiagainst, 
shauheen, jpienaar, rriddle, mehdi_amini, rogfer01, kuhar, hiraditya.
Herald added a reviewer: rriddle.
Herald added a reviewer: aartbik.
Herald added projects: clang, MLIR, LLVM.
nhaehnle requested review of this revision.
Herald added subscribers: vkmr, stephenneuendorffer, nicolasvasilache, wdng.

In CFGs where a single instruction can define multiple values, the
distinction is significant.

Change-Id: Ic15e8e34428ea71023cd644739b1114cebab9594


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85607

Files:
  clang/include/clang/Analysis/Analyses/Dominators.h
  llvm/include/llvm/CodeGen/MachineCfgTraits.h
  llvm/include/llvm/IR/CFG.h
  llvm/include/llvm/Support/CfgTraits.h
  llvm/lib/CodeGen/MachineCfgTraits.cpp
  llvm/lib/IR/CFG.cpp
  llvm/lib/Transforms/Vectorize/VPlanDominatorTree.h
  mlir/include/mlir/IR/Dominance.h

Index: mlir/include/mlir/IR/Dominance.h
===
--- mlir/include/mlir/IR/Dominance.h
+++ mlir/include/mlir/IR/Dominance.h
@@ -20,6 +20,7 @@
 public:
   using ParentType = Region;
   using BlockRef = Block *;
+  using InstructionRef = void;
   using ValueRef = void;
 
   static llvm::CfgBlockRef wrapRef(BlockRef block) {
Index: llvm/lib/Transforms/Vectorize/VPlanDominatorTree.h
===
--- llvm/lib/Transforms/Vectorize/VPlanDominatorTree.h
+++ llvm/lib/Transforms/Vectorize/VPlanDominatorTree.h
@@ -27,6 +27,7 @@
 public:
   using ParentType = VPRegionBlock;
   using BlockRef = VPBlockBase *;
+  using InstructionRef = void;
   using ValueRef = void;
 
   static CfgBlockRef wrapRef(BlockRef block) {
Index: llvm/lib/IR/CFG.cpp
===
--- llvm/lib/IR/CFG.cpp
+++ llvm/lib/IR/CFG.cpp
@@ -36,6 +36,11 @@
   }
 }
 
+void IrCfgTraits::Printer::printInstruction(raw_ostream &out,
+InstructionRef instruction) const {
+  printValue(out, instruction);
+}
+
 void IrCfgTraits::Printer::printBlockName(raw_ostream &out,
   BlockRef block) const {
   if (block->hasName()) {
Index: llvm/lib/CodeGen/MachineCfgTraits.cpp
===
--- llvm/lib/CodeGen/MachineCfgTraits.cpp
+++ llvm/lib/CodeGen/MachineCfgTraits.cpp
@@ -24,6 +24,11 @@
   }
 }
 
+void MachineCfgTraits::Printer::printInstruction(
+raw_ostream &out, MachineInstr *instruction) const {
+  instruction->print(out);
+}
+
 void MachineCfgTraits::Printer::printBlockName(raw_ostream &out,
MachineBasicBlock *block) const {
   block->printName(out);
Index: llvm/include/llvm/Support/CfgTraits.h
===
--- llvm/include/llvm/Support/CfgTraits.h
+++ llvm/include/llvm/Support/CfgTraits.h
@@ -79,6 +79,9 @@
 class CfgBlockRefTag;
 using CfgBlockRef = CfgOpaqueType;
 
+class CfgInstructionRefTag;
+using CfgInstructionRef = CfgOpaqueType;
+
 class CfgValueRefTag;
 using CfgValueRef = CfgOpaqueType;
 
@@ -113,8 +116,10 @@
   //
   // - Static methods for converting BlockRef and ValueRef to and from
   //   static CfgBlockRef wrapRef(BlockRef);
+  //   static CfgInstructionRef wrapRef(InstructionRef);
   //   static CfgValueRef wrapRef(ValueRef);
   //   static BlockRef unwrapRef(CfgBlockRef);
+  //   static InstructionRef unwrapRef(CfgInstructionRef);
   //   static ValueRef unwrapRef(CfgValueRef);
 };
 
@@ -133,6 +138,7 @@
 class CfgTraits : public BaseTraits {
 public:
   using typename BaseTraits::BlockRef;
+  using typename BaseTraits::InstructionRef;
   using typename BaseTraits::ParentType;
   using typename BaseTraits::ValueRef;
 
@@ -159,6 +165,10 @@
   // a range of iterators dereferencing to ValueRef):
   //   static auto blockdefs(BlockRef block);
 
+  // Given two instructions in the same block, this returns true if lhs is
+  // strictly before rhs.
+  //   static bool comesBefore(InstructionRef lhs, InstructionRef rhs);
+
   // Get the block in which a given value is defined. Returns a null-like
   // BlockRef if the value is not defined in a block (e.g. it is a constant or
   // function argument).
@@ -168,6 +178,8 @@
   //   explicit Printer(const CfgTraits &traits);
   //   void printBlockName(raw_ostream &out, BlockRef block) const;
   //   void printValue(raw_ostream &out, ValueRef value) const;
+  //   void printInstruction(raw_ostream &out,
+  // InstructionRef instruction) const;
   // };
 
   ///@}
@@ -295,6 +307,9 @@
   virtual void appendBlocks(CfgParentRef parent,
 SmallVectorImpl &list) const = 0;
 
+  virtual bool com

[PATCH] D85611: Improve dynamic AST matching diagnostics for conversion errors

2020-08-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: steveire, sbenza, klimek, sammccall.
aaron.ballman requested review of this revision.

Currently, when marshaling a dynamic AST matchers, we check for the type and 
value validity of matcher arguments at the same time for some matchers. For 
instance, when marshaling `hasAttr("foo")`, the argument is first type checked 
to ensure it's a string and then checked to see if that string can locate an 
attribute with that name. Similar happens for other enumeration conversions 
like cast kinds or unary operator kinds. If the type is correct but the value 
cannot be looked up, we make a best-effort attempt to find a nearby name that 
the user might have meant, but if one cannot be found, we throw our hands up 
and claim the types don't match.

This has an unfortunate behavior that when the user enters something of the 
correct type but a best guess cannot be located, you get confusing error 
messages like: `Incorrect type for arg 1. (Expected = string) != (Actual = 
String)`.

This patch splits the argument check into two parts: if the types don't match, 
give a type diagnostic. If the type matches but the value cannot be converted, 
give a best guess diagnostic or a value could not be located diagnostic:

  clang-query> m hasAttr("cool")
  1:1: Error building matcher hasAttr.
  1:9: Value not found: cool
  clang-query> m hasAttr("attr::cool")
  1:1: Error building matcher hasAttr.
  1:9: Unknown value 'attr::cool' for arg 1; did you mean 'attr::Cold'

This addresses PR47057.


https://reviews.llvm.org/D85611

Files:
  clang/lib/ASTMatchers/Dynamic/Marshallers.h
  clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Index: clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -354,8 +354,7 @@
 ParseMatcherWithError(R"query(decl(hasAttr("Final")))query"));
   EXPECT_EQ("1:1: Error parsing argument 1 for matcher decl.\n"
 "1:6: Error building matcher hasAttr.\n"
-"1:14: Incorrect type for arg 1. (Expected = string) != (Actual = "
-"String)",
+"1:14: Value not found: unrelated",
 ParseMatcherWithError(R"query(decl(hasAttr("unrelated")))query"));
   EXPECT_EQ(
   "1:1: Error parsing argument 1 for matcher namedDecl.\n"
@@ -366,8 +365,7 @@
   EXPECT_EQ(
   "1:1: Error parsing argument 1 for matcher namedDecl.\n"
   "1:11: Error building matcher matchesName.\n"
-  "1:33: Incorrect type for arg 2. (Expected = string) != (Actual = "
-  "String)",
+  "1:33: Value not found: IgnoreCase & BasicRegex",
   ParseMatcherWithError(
   R"query(namedDecl(matchesName("[ABC]*", "IgnoreCase & BasicRegex")))query"));
   EXPECT_EQ(
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -58,7 +58,10 @@
 };
 
 template <> struct ArgTypeTraits {
-  static bool is(const VariantValue &Value) { return Value.isString(); }
+  static bool hasCorrectType(const VariantValue &Value) {
+return Value.isString();
+  }
+  static bool hasCorrectValue(const VariantValue &Value) { return true; }
 
   static const std::string &get(const VariantValue &Value) {
 return Value.getString();
@@ -78,8 +81,11 @@
 };
 
 template  struct ArgTypeTraits> {
-  static bool is(const VariantValue &Value) {
-return Value.isMatcher() && Value.getMatcher().hasTypedMatcher();
+  static bool hasCorrectType(const VariantValue& Value) {
+return Value.isMatcher();
+  }
+  static bool hasCorrectValue(const VariantValue &Value) {
+return Value.getMatcher().hasTypedMatcher();
   }
 
   static ast_matchers::internal::Matcher get(const VariantValue &Value) {
@@ -96,7 +102,10 @@
 };
 
 template <> struct ArgTypeTraits {
-  static bool is(const VariantValue &Value) { return Value.isBoolean(); }
+  static bool hasCorrectType(const VariantValue &Value) {
+return Value.isBoolean();
+  }
+  static bool hasCorrectValue(const VariantValue &Value) { return true; }
 
   static bool get(const VariantValue &Value) {
 return Value.getBoolean();
@@ -112,7 +121,10 @@
 };
 
 template <> struct ArgTypeTraits {
-  static bool is(const VariantValue &Value) { return Value.isDouble(); }
+  static bool hasCorrectType(const VariantValue &Value) {
+return Value.isDouble();
+  }
+  static bool hasCorrectValue(const VariantValue &Value) { return true; }
 
   static double get(const VariantValue &Value) {
 return Value.getDouble();
@@ -128,7 +140,10 @@
 };
 
 template <> struct ArgTypeTraits {
-  static bool is(const VariantValue &Value) { return Value.isUnsigned(); }
+  static bool hasCorrectType(const VariantValue &Value) {
+return Value.isUnsigned();
+  }
+  sta

Re: [clang] 975467e - [Diagnostics] Handle string concat pattern and avoid false positives

2020-08-09 Thread Arthur O'Dwyer via cfe-commits
Hi Dávid,
Does this part of the patch imply that we *don't *want to warn on
"foo" TWO
? and if so, why not?
Anyway, I think at least
"foo" TWO
should be kept in the test suite, as a test-for-absence-of-warning.

  TWO "bar",
- "foo" TWO // expected-note{{place parentheses
around the string literal to silence warning}}
+ "foo" "bar" TWO // expected-note{{place
parentheses around the string literal to silence warning}}

my $.02,
Arthur

On Sun, Aug 9, 2020 at 10:03 AM Dávid Bolvanský via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Dávid Bolvanský
> Date: 2020-08-09T16:02:41+02:00
> New Revision: 975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e
>
> URL:
> https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e
> DIFF:
> https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e.diff
>
> LOG: [Diagnostics] Handle string concat pattern and avoid false positives
>
> Added:
>
>
> Modified:
> clang/lib/Sema/SemaExpr.cpp
> clang/test/Sema/string-concat.c
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
> index 35047a7b2b14..74427f8cd7ae 100644
> --- a/clang/lib/Sema/SemaExpr.cpp
> +++ b/clang/lib/Sema/SemaExpr.cpp
> @@ -6908,10 +6908,13 @@ Sema::ActOnInitList(SourceLocation LBraceLoc,
> MultiExprArg InitArgList,
>  << InitArgList[I]->getSourceRange();
>  } else if (const auto *SL = dyn_cast(InitArgList[I])) {
>unsigned NumConcat = SL->getNumConcatenated();
> +  const auto *SLNext =
> +  dyn_cast(InitArgList[I + 1 < E ? I + 1 : 0]);
>// Diagnose missing comma in string array initialization.
> -  // Do not warn when all the elements in the initializer are
> concatenated together.
> -  // Do not warn for macros too.
> -  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID()) {
> +  // Do not warn when all the elements in the initializer are
> concatenated
> +  // together. Do not warn for macros too.
> +  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() &&
> SLNext &&
> +  NumConcat != SLNext->getNumConcatenated()) {
>  SmallVector Hints;
>  for (unsigned i = 0; i < NumConcat - 1; ++i)
>Hints.push_back(FixItHint::CreateInsertion(
>
> diff  --git a/clang/test/Sema/string-concat.c
> b/clang/test/Sema/string-concat.c
> index c93bbd4eaa00..13e9656d2536 100644
> --- a/clang/test/Sema/string-concat.c
> +++ b/clang/test/Sema/string-concat.c
> @@ -61,7 +61,7 @@ char missing_comma_inner[][5] = {
>  #define TWO "foo"
>  const char *macro_test[] = { ONE("foo") "bar",
>   TWO "bar",
> - "foo" TWO // expected-note{{place
> parentheses around the string literal to silence warning}}
> + "foo" "bar" TWO // expected-note{{place
> parentheses around the string literal to silence warning}}
> };  // expected-warning@-1{{suspicious
> concatenation of string literals in an array initialization; did you mean
> to separate the elements with a comma?}}
>
>  // Do not warn for macros.
> @@ -104,6 +104,12 @@ const char *not_warn[] = {
>  "world", "test"
>  };
>
> +const char *not_warn2[] = {
> +"// Aaa\\\n"   " Bbb\\ \n"   " Ccc?" "?/\n",
> +"// Aaa\\\r\n" " Bbb\\ \r\n" " Ccc?" "?/\r\n",
> +"// Aaa\\\r"   " Bbb\\ \r"   " Ccc?" "?/\r"
> +  };
> +
>  // Do not warn when all the elements in the initializer are concatenated
> together.
>  const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
>
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] 975467e - [Diagnostics] Handle string concat pattern and avoid false positives

2020-08-09 Thread Dávid Bolvanský via cfe-commits
We warn if it is just one occurance and next literal is not split too. I 
changed test to test other scenario. I could add that test back, but I think we 
have enough tests to cover code.

We should not warn for code pattern:
{
“a” “b”,
“c” “d”
}




> Dňa 9. 8. 2020 o 17:49 užívateľ Arthur O'Dwyer  
> napísal:
> 
> 
> Hi Dávid,
> Does this part of the patch imply that we don't want to warn on
> "foo" TWO
> ? and if so, why not?
> Anyway, I think at least
> "foo" TWO
> should be kept in the test suite, as a test-for-absence-of-warning.
> 
>   TWO "bar", 
> - "foo" TWO // expected-note{{place parentheses 
> around the string literal to silence warning}}
> + "foo" "bar" TWO // expected-note{{place 
> parentheses around the string literal to silence warning}}
> 
> my $.02,
> Arthur
> 
>> On Sun, Aug 9, 2020 at 10:03 AM Dávid Bolvanský via cfe-commits 
>>  wrote:
> 
>> 
>> Author: Dávid Bolvanský
>> Date: 2020-08-09T16:02:41+02:00
>> New Revision: 975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e
>> 
>> URL: 
>> https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e
>> DIFF: 
>> https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e.diff
>> 
>> LOG: [Diagnostics] Handle string concat pattern and avoid false positives
>> 
>> Added: 
>> 
>> 
>> Modified: 
>> clang/lib/Sema/SemaExpr.cpp
>> clang/test/Sema/string-concat.c
>> 
>> Removed: 
>> 
>> 
>> 
>> 
>> diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
>> index 35047a7b2b14..74427f8cd7ae 100644
>> --- a/clang/lib/Sema/SemaExpr.cpp
>> +++ b/clang/lib/Sema/SemaExpr.cpp
>> @@ -6908,10 +6908,13 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
>> MultiExprArg InitArgList,
>>  << InitArgList[I]->getSourceRange();
>>  } else if (const auto *SL = dyn_cast(InitArgList[I])) {
>>unsigned NumConcat = SL->getNumConcatenated();
>> +  const auto *SLNext =
>> +  dyn_cast(InitArgList[I + 1 < E ? I + 1 : 0]);
>>// Diagnose missing comma in string array initialization.
>> -  // Do not warn when all the elements in the initializer are 
>> concatenated together.
>> -  // Do not warn for macros too.
>> -  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID()) {
>> +  // Do not warn when all the elements in the initializer are 
>> concatenated
>> +  // together. Do not warn for macros too.
>> +  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() && 
>> SLNext &&
>> +  NumConcat != SLNext->getNumConcatenated()) {
>>  SmallVector Hints;
>>  for (unsigned i = 0; i < NumConcat - 1; ++i)
>>Hints.push_back(FixItHint::CreateInsertion(
>> 
>> diff  --git a/clang/test/Sema/string-concat.c 
>> b/clang/test/Sema/string-concat.c
>> index c93bbd4eaa00..13e9656d2536 100644
>> --- a/clang/test/Sema/string-concat.c
>> +++ b/clang/test/Sema/string-concat.c
>> @@ -61,7 +61,7 @@ char missing_comma_inner[][5] = {
>>  #define TWO "foo"
>>  const char *macro_test[] = { ONE("foo") "bar", 
>>   TWO "bar", 
>> - "foo" TWO // expected-note{{place parentheses 
>> around the string literal to silence warning}}
>> + "foo" "bar" TWO // expected-note{{place 
>> parentheses around the string literal to silence warning}}
>> };  // expected-warning@-1{{suspicious 
>> concatenation of string literals in an array initialization; did you mean to 
>> separate the elements with a comma?}}
>> 
>>  // Do not warn for macros.
>> @@ -104,6 +104,12 @@ const char *not_warn[] = {
>>  "world", "test"
>>  };
>> 
>> +const char *not_warn2[] = {
>> +"// Aaa\\\n"   " Bbb\\ \n"   " Ccc?" "?/\n",
>> +"// Aaa\\\r\n" " Bbb\\ \r\n" " Ccc?" "?/\r\n",
>> +"// Aaa\\\r"   " Bbb\\ \r"   " Ccc?" "?/\r"
>> +  };
>> +
>>  // Do not warn when all the elements in the initializer are concatenated 
>> together.
>>  const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
>> 
>> 
>> 
>> 
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85612: [Sema] Use proper integral cast for an enumerate with a fixed bool type

2020-08-09 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: aaron.ballman, dblaikie, rsmith.
Mordante added a project: clang.
Herald added a subscriber: dexonsmith.
Mordante requested review of this revision.

When casting an enumerate with a fixed bool type the casting should use an 
IntegralToBoolean instead of an IntegralCast.

Fixes PR47055: Incorrect codegen for enum with bool underlying type


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85612

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/AST/ast-dump-enum-bool.cpp

Index: clang/test/AST/ast-dump-enum-bool.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-enum-bool.cpp
@@ -0,0 +1,1291 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump=json %s | FileCheck %s
+
+namespace dr2338 { // dr2338: yes
+namespace A {
+enum E { Zero, One };
+E a(int x) { return static_cast(x); }
+} // namespace A
+namespace B {
+enum E : bool { Zero, One };
+E a(int x) { return static_cast(x); }
+} // namespace B
+namespace C {
+enum class E { Zero, One };
+E a(int x) { return static_cast(x); }
+} // namespace C
+namespace D {
+enum class E : bool { Zero, One };
+E a(int x) { return static_cast(x); }
+} // namespace D
+}
+
+// NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
+
+
+// CHECK:  "kind": "TranslationUnitDecl",
+// CHECK-NEXT:  "loc": {},
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {},
+// CHECK-NEXT:   "end": {}
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "TypedefDecl",
+// CHECK-NEXT:"loc": {},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {},
+// CHECK-NEXT: "end": {}
+// CHECK-NEXT:},
+// CHECK-NEXT:"isImplicit": true,
+// CHECK-NEXT:"name": "__int128_t",
+// CHECK-NEXT:"type": {
+// CHECK-NEXT: "qualType": "__int128"
+// CHECK-NEXT:},
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "BuiltinType",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "__int128"
+// CHECK-NEXT:  }
+// CHECK-NEXT: }
+// CHECK-NEXT:]
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "TypedefDecl",
+// CHECK-NEXT:"loc": {},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {},
+// CHECK-NEXT: "end": {}
+// CHECK-NEXT:},
+// CHECK-NEXT:"isImplicit": true,
+// CHECK-NEXT:"name": "__uint128_t",
+// CHECK-NEXT:"type": {
+// CHECK-NEXT: "qualType": "unsigned __int128"
+// CHECK-NEXT:},
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "BuiltinType",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "unsigned __int128"
+// CHECK-NEXT:  }
+// CHECK-NEXT: }
+// CHECK-NEXT:]
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "TypedefDecl",
+// CHECK-NEXT:"loc": {},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {},
+// CHECK-NEXT: "end": {}
+// CHECK-NEXT:},
+// CHECK-NEXT:"isImplicit": true,
+// CHECK-NEXT:"name": "__NSConstantString",
+// CHECK-NEXT:"type": {
+// CHECK-NEXT: "qualType": "__NSConstantString_tag"
+// CHECK-NEXT:},
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "RecordType",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "__NSConstantString_tag"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "decl": {
+// CHECK-NEXT:   "id": "0x{{.*}}",
+// CHECK-NEXT:   "kind": "CXXRecordDecl",
+// CHECK-NEXT:   "name": "__NSConstantString_tag"
+// CHECK-NEXT:  }
+// CHECK-NEXT: }
+// CHECK-NEXT:]
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "TypedefDecl",
+// CHECK-NEXT:"loc": {},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {},
+// CHECK-NEXT: "end": {}
+// CHECK-NEXT:},
+// CHECK-NEXT:"isImplicit": true,
+// CHECK-NEXT:"name": "__builtin_ms_va_list",
+// CHECK-NEXT:"type": {
+// CHECK-NEXT: "qualType": "char *"
+// CHECK-NEXT:},
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "PointerType",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "char *"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "BuiltinType",
+// CHECK-NEXT:"type": {
+// CHECK-NEXT: "qualType": "char"
+// CHECK-NEXT:}
+// CHECK-NEXT:   }
+// CHECK-NEXT:  ]
+// CHECK-NEXT: }
+// CHECK-NEXT:]
+// CHECK-NEXT:   },
+// CHECK-NEXT: 

[PATCH] D85613: [clang] Look through bindings when checking whether a default argument references a local entity.

2020-08-09 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno created this revision.
riccibruno added reviewers: rsmith, erichkeane, rjmccall.
riccibruno added a project: clang.
Herald added a subscriber: cfe-commits.
riccibruno requested review of this revision.

Currently clang accepts a default argument containing a structured binding 
which is a local entity:

  struct S { int i, j; };
  auto [x, y] = S();
  extern void h(int = x); // Should be rejected.

It was not entirely clear in C++17 that this was forbidden since `C++17 
[dcl.fct.default]p7` only used the term "local variable". However this is 
clearly forbidden in C++20 with the new wording in terms of odr-usable local 
entities.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85613

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp


Index: clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
===
--- clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
+++ clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
@@ -1,5 +1,20 @@
 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
 
+namespace std {
+using size_t = decltype(sizeof(int));
+template  struct tuple_size;
+template  struct tuple_element;
+} // namespace std
+using size_t = std::size_t;
+
+struct E {};
+template  int get(E);
+
+namespace std {
+template <> struct tuple_size { static constexpr size_t value = 2; };
+template  struct tuple_element { using type = int; };
+}; // namespace std
+
 void h() {
   int i1 = 0;
   extern void h1(int x = i1);
@@ -22,10 +37,21 @@
   };
 
   extern void h6(int = i5);
-  // expected-error-re@-1 {{default argument references local variable 
'(unnamed variable of type (anonymous union at {{.*}}:20:3))' of enclosing 
function}}
+  // expected-error-re@-1 {{default argument references local variable 
'(unnamed variable of type (anonymous union at {{.*}}:35:3))' of enclosing 
function}}
+
+  struct S {
+int i, j;
+  };
+  auto [x, y] = S();
+
+  extern void h7(int = x); // expected-error {{default argument references 
local variable '[x, y]'}}
 
-  struct S { int i; };
-  auto [x] = S();
+  auto [z, w] = E();
+  extern void h8a(int = sizeof(z)); // ok
+  extern void h8b(int = w); // expected-error {{default argument 
references local variable 'w'}}
 
-  extern void h7(int = x); // FIXME: reject
+  extern auto get_array()->int(&)[2];
+  auto [a0, a1] = get_array();
+  extern void h9a(int = sizeof(a0));
+  extern void h9b(int = a1); // expected-error {{default argument references 
local variable '[a0, a1]'}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -86,6 +86,34 @@
 /// argument expression.
 bool CheckDefaultArgumentVisitor::VisitDeclRefExpr(const DeclRefExpr *DRE) {
   const NamedDecl *Decl = DRE->getDecl();
+
+  // C++20 [basic.pre]p7:
+  //   A local entity is [...] a structured binding whose corresponding 
variable
+  //   is such an entity [...]
+  //
+  // C++20 [basic.def.odr]p9:
+  //   A local entity (6.1) is odr-usable in a declarative region if [...]
+  //
+  // Note that this was not entirely clear in C++17 since [dcl.fct.default]p7
+  // only prohibited local variables (a structured binding declaration
+  // introduces identifiers as names).
+  if (const auto *Binding = dyn_cast(Decl)) {
+if (const VarDecl *HoldingVar = Binding->getHoldingVar()) {
+  // C++20 [dcl.struct.bind]p4:
+  //   Each vi is the name [...] that refers to the object bound to ri 
[...]
+  Decl = HoldingVar;
+} else {
+  // C++20 [dcl.struct.bind]p3:
+  //   Each vi is the name of an lvalue that refers to the element i of
+  //   the array [...]
+  //
+  // C++20 [dcl.struct.bind]p5:
+  //   [...] each vi is the name of an lvalue that refers to the member mi
+  //   of e [...]
+  Decl = Binding->getDecomposedDecl();
+}
+  }
+
   if (const auto *Param = dyn_cast(Decl)) {
 // C++ [dcl.fct.default]p9:
 //   [...] parameters of a function shall not be used in default


Index: clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
===
--- clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
+++ clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
@@ -1,5 +1,20 @@
 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
 
+namespace std {
+using size_t = decltype(sizeof(int));
+template  struct tuple_size;
+template  struct tuple_element;
+} // namespace std
+using size_t = std::size_t;
+
+struct E {};
+template  int get(E);
+
+namespace std {
+template <> struct tuple_size { static constexpr size_t value = 2; };
+template  struct tuple_element { using type = int; };
+}; // namespace std
+
 void h() {
   int i1 = 0;
   extern void h1(int x = i1);
@@ -22,10 +37,21 @@
   };
 
   extern void h6

[PATCH] D85612: [Sema] Use proper integral cast for an enumerate with a fixed bool type

2020-08-09 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added inline comments.



Comment at: clang/test/AST/ast-dump-enum-bool.cpp:1
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump=json 
%s | FileCheck %s
+

Why a (pretty unreadable) json test? There is also `make-ast-dump-check.sh` to 
auto-generate an ast dump test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85612/new/

https://reviews.llvm.org/D85612

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85612: [Sema] Use proper integral cast for an enumerate with a fixed bool type

2020-08-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/AST/ast-dump-enum-bool.cpp:1
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump=json 
%s | FileCheck %s
+

riccibruno wrote:
> Why a (pretty unreadable) json test? There is also `make-ast-dump-check.sh` 
> to auto-generate an ast dump test.
I'd also like to see some CodeGen tests for various fixed underlying types that 
ensures the conversion to the underlying type happens before the conversion to 
the enumeration.

Also, at least one test showing this behaves properly with a C-style cast 
instead of a named cast.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85612/new/

https://reviews.llvm.org/D85612

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84600: [Analyzer] Support note tags for smart ptr checker

2020-08-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/test/Analysis/smart-ptr-text-output.cpp:79
+
+// TODO: Enabale this test when "std::swap" is modeled seperately.
+void derefOnStdSwappedNullPtr() {

vrnithinkumar wrote:
> vrnithinkumar wrote:
> > NoQ wrote:
> > > Instead of commenting out tests, i recommend testing the incorrect 
> > > behavior (with a FIXME comment telling us why it's incorrect). This way 
> > > we'll be notified when the test is fixed, accidentally or intentionally, 
> > > and also generally that's more testing for everybody.
> > I have commented out this since right now `std::swap` is using 
> > `unique_ptr.swap`.
> > So note tag for std::swap is added in header file  
> > `system-header-simulator-cxx.h`
> > eg:
> > `system-header-simulator-cxx.h Line 978: Swapped null smart pointer 'PNull' 
> > with smart pointer 'P'`
> - Is it okay to add a expected-note on `system-header-simulator-cxx.h`?
Aha, i see.

It's obviously not ok because the header is included by multiple tests but only 
some tests will have the note show up.

The usual solution is to put the expected-note comment in the current test file 
but make it refer to the header. Here's doc from 
https://clang.llvm.org/doxygen/classclang_1_1VerifyDiagnosticConsumer.html:
> If the diagnostic is generated in a separate file, for example in a shared 
> header file, it may be beneficial to be able to declare the file in which the 
> diagnostic will appear, rather than placing the expected-* directive in the 
> actual file itself. This can be done using the following syntax:
> ```// expected-error@path/include.h:15 {{error message}}```

It still is a bit of a problem that you have to hardcode the line number (so 
everybody who modifies the header above your note will have to update your 
test) but that's not a big deal.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84600/new/

https://reviews.llvm.org/D84600

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85144: [clang] Improve Dumping of APValues

2020-08-09 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

I agree with you that it's fine to use `printPretty`  for leaves (and 
additionally it would be annoying to duplicate the `LValue` case); that's what 
I was planning to do anyway.

What I am not sure I agree with is the additional complexity to handle the 
(debugger-only and easy to avoid) case where no context is given.




Comment at: clang/lib/AST/APValue.cpp:539
 Out << '[' << Path[I].getAsArrayIndex() << ']';
-ElemTy = Ctx.getAsArrayType(ElemTy)->getElementType();
+ElemTy = cast(ElemTy.getCanonicalType())->getElementType();
   }

riccibruno wrote:
> And also I don't think that this change is safe since 
> `ASTContext::getAsArrayType` applies qualifiers from the array type to the 
> element type.
This works because we only use `ElemTy` to distinguish between the array case 
and the base-or-member case right?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85144/new/

https://reviews.llvm.org/D85144

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 898880f - [clang] Fix typo in comment

2020-08-09 Thread Dávid Bolvanský via cfe-commits

Author: Gousemoodhin Nadaf
Date: 2020-08-09T21:04:00+02:00
New Revision: 898880fe4e329ce7fc6bbe30f309ef3b91535c21

URL: 
https://github.com/llvm/llvm-project/commit/898880fe4e329ce7fc6bbe30f309ef3b91535c21
DIFF: 
https://github.com/llvm/llvm-project/commit/898880fe4e329ce7fc6bbe30f309ef3b91535c21.diff

LOG: [clang] Fix typo in comment

In the handleIntToFloatConversion() function, 6th parameter is ConvertFloat, 
7th parameter is ConvertInt.

Reviewed By: njames93, xbolva00

Differential Revision: https://reviews.llvm.org/D85568

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 74427f8cd7ae..fe997e7719e7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1151,8 +1151,8 @@ static QualType handleFloatConversion(Sema &S, ExprResult 
&LHS,
   }
   assert(RHSFloat);
   return handleIntToFloatConversion(S, RHS, LHS, RHSType, LHSType,
-/*convertInt=*/ true,
-/*convertFloat=*/!IsCompAssign);
+/*ConvertFloat=*/ true,
+/*ConvertInt=*/!IsCompAssign);
 }
 
 /// Diagnose attempts to convert between __float128 and long double if



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85568: [clang] Fix typo in comment

2020-08-09 Thread Dávid Bolvanský via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG898880fe4e32: [clang] Fix typo in comment (authored by 
gousemoodhin, committed by xbolva00).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85568/new/

https://reviews.llvm.org/D85568

Files:
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -1151,8 +1151,8 @@
   }
   assert(RHSFloat);
   return handleIntToFloatConversion(S, RHS, LHS, RHSType, LHSType,
-/*convertInt=*/ true,
-/*convertFloat=*/!IsCompAssign);
+/*ConvertFloat=*/ true,
+/*ConvertInt=*/!IsCompAssign);
 }
 
 /// Diagnose attempts to convert between __float128 and long double if


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -1151,8 +1151,8 @@
   }
   assert(RHSFloat);
   return handleIntToFloatConversion(S, RHS, LHS, RHSType, LHSType,
-/*convertInt=*/ true,
-/*convertFloat=*/!IsCompAssign);
+/*ConvertFloat=*/ true,
+/*ConvertInt=*/!IsCompAssign);
 }
 
 /// Diagnose attempts to convert between __float128 and long double if
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85619: [clang][OpenMP][OMPBuilder] Use OMPBuilder to CG `omp single`

2020-08-09 Thread Fady Ghanim via Phabricator via cfe-commits
fghanim created this revision.
Herald added subscribers: cfe-commits, aaron.ballman, guansong, yaxunl.
Herald added a project: clang.
fghanim requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

ADD support to allow `omp single` to be CG-ed by the OMPBuilder. This
also uses the OMPBuilder to generate `__kmpc_copyprivate` calls.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85619

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/single_codegen.cpp

Index: clang/test/OpenMP/single_codegen.cpp
===
--- clang/test/OpenMP/single_codegen.cpp
+++ clang/test/OpenMP/single_codegen.cpp
@@ -1,11 +1,12 @@
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=OMP50,CHECK
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -fopenmp-version=45 -o - | FileCheck %s --check-prefixes=OMP45,CHECK
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=OMP50,ALL,CHECK
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -fopenmp-version=45 -o - | FileCheck %s --check-prefixes=OMP45,ALL,CHECK
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -fnoopenmp-use-tls -x c++ -std=c++11 -DOMPBUILDER -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,OMPBUILDER
 
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -fnoopenmp-use-tls -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=OMP50,CHECK
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -fnoopenmp-use-tls -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=OMP50,ALL,CHECK
 
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -fnoopenmp-use-tls -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=OMP45,CHECK
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -fnoopenmp-use-tls -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=OMP45,ALL,CHECK
 
 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -std=c++11 -fopenmp -fnoopenmp-use-tls -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG
 // RUN: %clang_cc1 -verify -fopenmp -fnoopenmp-use-tls -x c++ -std=c++11 -DARRAY -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=ARRAY %s
@@ -30,13 +31,13 @@
   ~TestClass(){};
 };
 
-// CHECK-DAG:   [[TEST_CLASS_TY:%.+]] = type { i{{[0-9]+}} }
+// ALL-DAG:   [[TEST_CLASS_TY:%.+]] = type { i{{[0-9]+}} }
 // CHECK-DAG:   [[SST_TY:%.+]] = type { double }
 // CHECK-DAG:   [[SS_TY:%.+]] = type { i32, i8, i32* }
-// CHECK-DAG:   [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
-// CHECK:   [[IMPLICIT_BARRIER_SINGLE_LOC:@.+]] = private unnamed_addr global %{{.+}} { i32 0, i32 322, i32 0, i32 0, i8*
+// ALL-DAG:   [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
+// ALL:   [[IMPLICIT_BARRIER_SINGLE_LOC:@.+]] = private unnamed_addr global %{{.+}} { i32 0, i32 322, i32 0, i32 0, i8*
 
-// CHECK:   define void [[FOO:@.+]]()
+// ALL:   define void [[FOO:@.+]]()
 
 TestClass tc;
 TestClass tc2[2];
@@ -44,6 +45,7 @@
 
 void foo() { extern void mayThrow(); mayThrow(); }
 
+#ifndef OMPBUILDER
 struct SS {
   int a;
   int b : 4;
@@ -76,129 +78,132 @@
 }();
   }
 };
+#endif
 
-// CHECK-LABEL: @main
+// ALL-LABEL: @main
 // TERM_DEBUG-LABEL: @main
 int main() {
-  // CHECK: alloca i32
-  // CHECK-DAG: [[A_ADDR:%.+]] = alloca i8
-  // CHECK-DAG: [[A2_ADDR:%.+]] = alloca [2 x i8]
-  // CHECK-DAG: [[C_ADDR:%.+]] = alloca [[TEST_CLASS_TY]]
-  // CHECK-DAG: [[DID_IT:%.+]] = alloca i32,
-  // CHECK-DAG: [[COPY_LIST:%.+]] = alloca [5 x i8*],
+  // ALL: alloca i32
+  // ALL-D

[PATCH] D85619: [clang][OpenMP][OMPBuilder] Use OMPBuilder to CG `omp single`

2020-08-09 Thread Fady Ghanim via Phabricator via cfe-commits
fghanim added a comment.

Feel free to add other reviewers. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85619/new/

https://reviews.llvm.org/D85619

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85502: [clangd] Add more error details on the remote index server side

2020-08-09 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 284230.
kbobyrev marked 2 inline comments as done.
kbobyrev added a comment.

Resolve post-LGTM comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85502/new/

https://reviews.llvm.org/D85502

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp


Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
===
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -23,6 +23,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 
@@ -303,7 +304,8 @@
   if (RelativePath.empty())
 return makeStringError("Empty relative path.");
   if (llvm::sys::path::is_absolute(RelativePath))
-return makeStringError("RelativePath is absolute.");
+return makeStringError(
+llvm::formatv("RelativePath '{0}' is absolute.", RelativePath).str());
   llvm::SmallString<256> FullPath = llvm::StringRef(*LocalIndexRoot);
   llvm::sys::path::append(FullPath, RelativePath);
   auto Result = URI::createFile(FullPath);
@@ -316,10 +318,16 @@
   if (!ParsedURI)
 return ParsedURI.takeError();
   if (ParsedURI->scheme() != "file")
-return makeStringError("Can not use URI schemes other than file.");
+return makeStringError(
+llvm::formatv("Can not use URI schemes other than file, given: '{0}'.",
+  URI)
+.str());
   llvm::SmallString<256> Result = ParsedURI->body();
   if (!llvm::sys::path::replace_path_prefix(Result, *RemoteIndexRoot, ""))
-return makeStringError("File path doesn't start with RemoteIndexRoot.");
+return makeStringError(
+llvm::formatv("File path '{0}' doesn't start with '{1}'.", 
Result.str(),
+  *RemoteIndexRoot)
+.str());
   // Make sure the result has UNIX slashes.
   return llvm::sys::path::convert_to_slash(Result,
llvm::sys::path::Style::posix);


Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
===
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -23,6 +23,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 
@@ -303,7 +304,8 @@
   if (RelativePath.empty())
 return makeStringError("Empty relative path.");
   if (llvm::sys::path::is_absolute(RelativePath))
-return makeStringError("RelativePath is absolute.");
+return makeStringError(
+llvm::formatv("RelativePath '{0}' is absolute.", RelativePath).str());
   llvm::SmallString<256> FullPath = llvm::StringRef(*LocalIndexRoot);
   llvm::sys::path::append(FullPath, RelativePath);
   auto Result = URI::createFile(FullPath);
@@ -316,10 +318,16 @@
   if (!ParsedURI)
 return ParsedURI.takeError();
   if (ParsedURI->scheme() != "file")
-return makeStringError("Can not use URI schemes other than file.");
+return makeStringError(
+llvm::formatv("Can not use URI schemes other than file, given: '{0}'.",
+  URI)
+.str());
   llvm::SmallString<256> Result = ParsedURI->body();
   if (!llvm::sys::path::replace_path_prefix(Result, *RemoteIndexRoot, ""))
-return makeStringError("File path doesn't start with RemoteIndexRoot.");
+return makeStringError(
+llvm::formatv("File path '{0}' doesn't start with '{1}'.", Result.str(),
+  *RemoteIndexRoot)
+.str());
   // Make sure the result has UNIX slashes.
   return llvm::sys::path::convert_to_slash(Result,
llvm::sys::path::Style::posix);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85601: Fixes an assertion when IntRange processes a throw expression

2020-08-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Did this only crash during error recovery before, or also for your `void g()` 
example? If we were only crashing in error recovery, that would suggest that 
error recovery was producing a bad AST, and perhaps we should be fixing this 
elsewhere.




Comment at: clang/lib/Sema/SemaChecking.cpp:10164
 const BuiltinType *BT = cast(T);
-assert(BT->isInteger());
+if (!BT->isInteger()) {
+  // This can happen in a conditional expression with a throw statement

Can we handle this in code that's specific to conditional expressions instead? 
Presumably somewhere higher up in the call graph, some code is assuming that it 
can recurse from a conditional expression to its subexpressions, and that 
assumption is wrong.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85601/new/

https://reviews.llvm.org/D85601

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85502: [clangd] Add more error details on the remote index server side

2020-08-09 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG836f937a1f11: [clangd] Add more error details on the remote 
index server side (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85502/new/

https://reviews.llvm.org/D85502

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp


Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
===
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -23,6 +23,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 
@@ -303,7 +304,8 @@
   if (RelativePath.empty())
 return makeStringError("Empty relative path.");
   if (llvm::sys::path::is_absolute(RelativePath))
-return makeStringError("RelativePath is absolute.");
+return makeStringError(
+llvm::formatv("RelativePath '{0}' is absolute.", RelativePath).str());
   llvm::SmallString<256> FullPath = llvm::StringRef(*LocalIndexRoot);
   llvm::sys::path::append(FullPath, RelativePath);
   auto Result = URI::createFile(FullPath);
@@ -316,10 +318,16 @@
   if (!ParsedURI)
 return ParsedURI.takeError();
   if (ParsedURI->scheme() != "file")
-return makeStringError("Can not use URI schemes other than file.");
+return makeStringError(
+llvm::formatv("Can not use URI schemes other than file, given: '{0}'.",
+  URI)
+.str());
   llvm::SmallString<256> Result = ParsedURI->body();
   if (!llvm::sys::path::replace_path_prefix(Result, *RemoteIndexRoot, ""))
-return makeStringError("File path doesn't start with RemoteIndexRoot.");
+return makeStringError(
+llvm::formatv("File path '{0}' doesn't start with '{1}'.", 
Result.str(),
+  *RemoteIndexRoot)
+.str());
   // Make sure the result has UNIX slashes.
   return llvm::sys::path::convert_to_slash(Result,
llvm::sys::path::Style::posix);


Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
===
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -23,6 +23,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 
@@ -303,7 +304,8 @@
   if (RelativePath.empty())
 return makeStringError("Empty relative path.");
   if (llvm::sys::path::is_absolute(RelativePath))
-return makeStringError("RelativePath is absolute.");
+return makeStringError(
+llvm::formatv("RelativePath '{0}' is absolute.", RelativePath).str());
   llvm::SmallString<256> FullPath = llvm::StringRef(*LocalIndexRoot);
   llvm::sys::path::append(FullPath, RelativePath);
   auto Result = URI::createFile(FullPath);
@@ -316,10 +318,16 @@
   if (!ParsedURI)
 return ParsedURI.takeError();
   if (ParsedURI->scheme() != "file")
-return makeStringError("Can not use URI schemes other than file.");
+return makeStringError(
+llvm::formatv("Can not use URI schemes other than file, given: '{0}'.",
+  URI)
+.str());
   llvm::SmallString<256> Result = ParsedURI->body();
   if (!llvm::sys::path::replace_path_prefix(Result, *RemoteIndexRoot, ""))
-return makeStringError("File path doesn't start with RemoteIndexRoot.");
+return makeStringError(
+llvm::formatv("File path '{0}' doesn't start with '{1}'.", Result.str(),
+  *RemoteIndexRoot)
+.str());
   // Make sure the result has UNIX slashes.
   return llvm::sys::path::convert_to_slash(Result,
llvm::sys::path::Style::posix);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 836f937 - [clangd] Add more error details on the remote index server side

2020-08-09 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2020-08-09T22:12:56+02:00
New Revision: 836f937a1f1150d81c0bf2b6a14872146da5b89e

URL: 
https://github.com/llvm/llvm-project/commit/836f937a1f1150d81c0bf2b6a14872146da5b89e
DIFF: 
https://github.com/llvm/llvm-project/commit/836f937a1f1150d81c0bf2b6a14872146da5b89e.diff

LOG: [clangd] Add more error details on the remote index server side

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D85502

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index bac5b7e6e958..dbda5bf24aa3 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -23,6 +23,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 
@@ -303,7 +304,8 @@ Marshaller::relativePathToURI(llvm::StringRef RelativePath) 
{
   if (RelativePath.empty())
 return makeStringError("Empty relative path.");
   if (llvm::sys::path::is_absolute(RelativePath))
-return makeStringError("RelativePath is absolute.");
+return makeStringError(
+llvm::formatv("RelativePath '{0}' is absolute.", RelativePath).str());
   llvm::SmallString<256> FullPath = llvm::StringRef(*LocalIndexRoot);
   llvm::sys::path::append(FullPath, RelativePath);
   auto Result = URI::createFile(FullPath);
@@ -316,10 +318,16 @@ llvm::Expected 
Marshaller::uriToRelativePath(llvm::StringRef URI) {
   if (!ParsedURI)
 return ParsedURI.takeError();
   if (ParsedURI->scheme() != "file")
-return makeStringError("Can not use URI schemes other than file.");
+return makeStringError(
+llvm::formatv("Can not use URI schemes other than file, given: '{0}'.",
+  URI)
+.str());
   llvm::SmallString<256> Result = ParsedURI->body();
   if (!llvm::sys::path::replace_path_prefix(Result, *RemoteIndexRoot, ""))
-return makeStringError("File path doesn't start with RemoteIndexRoot.");
+return makeStringError(
+llvm::formatv("File path '{0}' doesn't start with '{1}'.", 
Result.str(),
+  *RemoteIndexRoot)
+.str());
   // Make sure the result has UNIX slashes.
   return llvm::sys::path::convert_to_slash(Result,
llvm::sys::path::Style::posix);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9658647 - [AST] Fixed string concatenation warnings

2020-08-09 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-09T23:09:19+02:00
New Revision: 9658647d72d24f339f8b8129da9f116c358f30d5

URL: 
https://github.com/llvm/llvm-project/commit/9658647d72d24f339f8b8129da9f116c358f30d5
DIFF: 
https://github.com/llvm/llvm-project/commit/9658647d72d24f339f8b8129da9f116c358f30d5.diff

LOG: [AST] Fixed string concatenation warnings

Added: 


Modified: 
clang/unittests/AST/CommentParser.cpp

Removed: 




diff  --git a/clang/unittests/AST/CommentParser.cpp 
b/clang/unittests/AST/CommentParser.cpp
index ba8b34ebcd38..0be01a554f72 100644
--- a/clang/unittests/AST/CommentParser.cpp
+++ b/clang/unittests/AST/CommentParser.cpp
@@ -628,40 +628,40 @@ TEST_F(CommentParserTest, Basic3) {
 
 TEST_F(CommentParserTest, ParagraphSplitting1) {
   const char *Sources[] = {
-"// Aaa\n"
+("// Aaa\n"
 "//\n"
-"// Bbb",
+"// Bbb"),
 
-"// Aaa\n"
+("// Aaa\n"
 "// \n"
-"// Bbb",
+"// Bbb"),
 
-"// Aaa\n"
+("// Aaa\n"
 "//\t\n"
-"// Bbb",
+"// Bbb"),
 
-"// Aaa\n"
+("// Aaa\n"
 "//\n"
 "//\n"
-"// Bbb",
+"// Bbb"),
 
-"/**\n"
+("/**\n"
 " Aaa\n"
 "\n"
 " Bbb\n"
-"*/",
+"*/"),
 
-"/**\n"
+("/**\n"
 " Aaa\n"
 " \n"
 " Bbb\n"
-"*/",
+"*/"),
 
-"/**\n"
+("/**\n"
 " Aaa\n"
 "\t \n"
 " Bbb\n"
-"*/",
+"*/"),
   };
 
   for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
@@ -792,13 +792,13 @@ TEST_F(CommentParserTest, ParamCommand2) {
 
 TEST_F(CommentParserTest, ParamCommand3) {
   const char *Sources[] = {
-"// \\param aaa Bbb\n",
+("// \\param aaa Bbb\n",
 "// \\param\n"
-"// aaa Bbb\n",
-"// \\param \n"
-"// aaa Bbb\n",
-"// \\param aaa\n"
-"// Bbb\n"
+"// aaa Bbb\n"),
+("// \\param \n"
+"// aaa Bbb\n"),
+("// \\param aaa\n"
+"// Bbb\n")
   };
 
   for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
@@ -823,12 +823,12 @@ TEST_F(CommentParserTest, ParamCommand4) {
   const char *Sources[] = {
 "// \\param [in] aaa Bbb\n",
 "// \\param[in] aaa Bbb\n",
-"// \\param\n"
-"// [in] aaa Bbb\n",
-"// \\param [in]\n"
-"// aaa Bbb\n",
-"// \\param [in] aaa\n"
-"// Bbb\n",
+("// \\param\n"
+"// [in] aaa Bbb\n"),
+("// \\param [in]\n"
+"// aaa Bbb\n"),
+("// \\param [in] aaa\n"
+"// Bbb\n"),
   };
 
   for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
@@ -853,12 +853,12 @@ TEST_F(CommentParserTest, ParamCommand5) {
   const char *Sources[] = {
 "// \\param [out] aaa Bbb\n",
 "// \\param[out] aaa Bbb\n",
-"// \\param\n"
-"// [out] aaa Bbb\n",
-"// \\param [out]\n"
-"// aaa Bbb\n",
-"// \\param [out] aaa\n"
-"// Bbb\n",
+("// \\param\n"
+"// [out] aaa Bbb\n"),
+("// \\param [out]\n"
+"// aaa Bbb\n"),
+("// \\param [out] aaa\n"
+"// Bbb\n"),
   };
 
   for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] eeb7c49 - [AST] Fixed string list in test

2020-08-09 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-09T23:17:48+02:00
New Revision: eeb7c496e385d2a88c39a0e0ebfe8a9908762cc3

URL: 
https://github.com/llvm/llvm-project/commit/eeb7c496e385d2a88c39a0e0ebfe8a9908762cc3
DIFF: 
https://github.com/llvm/llvm-project/commit/eeb7c496e385d2a88c39a0e0ebfe8a9908762cc3.diff

LOG: [AST] Fixed string list in test

Added: 


Modified: 
clang/unittests/AST/CommentParser.cpp

Removed: 




diff  --git a/clang/unittests/AST/CommentParser.cpp 
b/clang/unittests/AST/CommentParser.cpp
index 0be01a554f72..62c461a00d16 100644
--- a/clang/unittests/AST/CommentParser.cpp
+++ b/clang/unittests/AST/CommentParser.cpp
@@ -792,8 +792,8 @@ TEST_F(CommentParserTest, ParamCommand2) {
 
 TEST_F(CommentParserTest, ParamCommand3) {
   const char *Sources[] = {
-("// \\param aaa Bbb\n",
-"// \\param\n"
+"// \\param aaa Bbb\n",
+("// \\param\n"
 "// aaa Bbb\n"),
 ("// \\param \n"
 "// aaa Bbb\n"),



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85474: Add -fbinutils-version= to gate ELF features on the specified binutils version

2020-08-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 284234.
MaskRay added a comment.

Add binutilsIsAtleast()


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85474/new/

https://reviews.llvm.org/D85474

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/Target/TargetMachine.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/LLVMTargetMachine.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/Target/TargetMachine.cpp
  llvm/test/CodeGen/X86/explicit-section-mergeable.ll
  llvm/tools/llc/llc.cpp

Index: llvm/tools/llc/llc.cpp
===
--- llvm/tools/llc/llc.cpp
+++ llvm/tools/llc/llc.cpp
@@ -81,6 +81,14 @@
  cl::value_desc("N"),
  cl::desc("Repeat compilation N times for timing"));
 
+static cl::opt BinutilsVersion(
+"binutils-version", cl::Hidden,
+cl::desc(
+"Used ELF features need to be supported by GNU ld "
+"from the specified binutils version. 'future' means that "
+"features not implemented by any known release can be used. If "
+"-no-integrated-as is specified, this also affects assembly output"));
+
 static cl::opt
 NoIntegratedAssembler("no-integrated-as", cl::Hidden,
   cl::desc("Disable integrated assembler"));
@@ -425,6 +433,8 @@
   }
 
   TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  Options.BinutilsVersion =
+  TargetMachine::parseBinutilsVersion(BinutilsVersion);
   Options.DisableIntegratedAS = NoIntegratedAssembler;
   Options.MCOptions.ShowMCEncoding = ShowMCEncoding;
   Options.MCOptions.MCUseDwarfDirectory = EnableDwarfDirectory;
Index: llvm/test/CodeGen/X86/explicit-section-mergeable.ll
===
--- llvm/test/CodeGen/X86/explicit-section-mergeable.ll
+++ llvm/test/CodeGen/X86/explicit-section-mergeable.ll
@@ -282,15 +282,19 @@
 ;; --no-integrated-as avoids the use of ",unique," for compatibility with older binutils.
 
 ;; Error if an incompatible symbol is explicitly placed into a mergeable section.
-; RUN: not llc < %s -mtriple=x86_64 --no-integrated-as 2>&1 \
+; RUN: not llc < %s -mtriple=x86_64 --no-integrated-as -binutils-version=2.34 2>&1 \
 ; RUN: | FileCheck %s --check-prefix=NO-I-AS-ERR
 ; NO-I-AS-ERR: error: Symbol 'explicit_default_1' from module '' required a section with entry-size=0 but was placed in section '.rodata.cst16' with entry-size=16: Explicit assignment by pragma or attribute of an incompatible symbol to this section?
 ; NO-I-AS-ERR: error: Symbol 'explicit_default_4' from module '' required a section with entry-size=0 but was placed in section '.debug_str' with entry-size=1: Explicit assignment by pragma or attribute of an incompatible symbol to this section?
 ; NO-I-AS-ERR: error: Symbol 'explicit_implicit_2' from module '' required a section with entry-size=0 but was placed in section '.rodata.str1.1' with entry-size=1: Explicit assignment by pragma or attribute of an incompatible symbol to this section?
 ; NO-I-AS-ERR: error: Symbol 'explicit_implicit_4' from module '' required a section with entry-size=0 but was placed in section '.rodata.str1.1' with entry-size=1: Explicit assignment by pragma or attribute of an incompatible symbol to this section?
 
+;; For GNU as before 2.35,
 ;; Don't create mergeable sections for globals with an explicit section name.
 ; RUN: echo '@explicit = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit"' > %t.no_i_as.ll
-; RUN: llc < %t.no_i_as.ll -mtriple=x86_64 --no-integrated-as 2>&1 \
-; RUN: | FileCheck %s --check-prefix=NO-I-AS
-; NO-I-AS: .section .explicit,"a",@progbits
+; RUN: llc < %t.no_i_as.ll -mtriple=x86_64 --no-integrated-as -binutils-version=2.34 2>&1 \
+; RUN: | FileCheck %s --check-prefix=NO-I-AS-OLD
+; NO-I-AS-OLD: .section .explicit,"a",@progbits
+; RUN: llc < %t.no_i_as.ll -mtriple=x86_64 --no-integrated-as -binutils-version=2.35 2>&1 \
+; RUN: | FileCheck %s --check-prefix=NO-I-AS-NEW
+; NO-I-AS-NEW: .section .explicit,"aM",@progbits,4,unique,1
Index: llvm/lib/Target/TargetMachine.cpp
===
--- llvm/lib/Target/TargetMachine.cpp
+++ llvm/lib/Target/TargetMachine.cpp
@@ -281,3 +281,12 @@
   return TargetIRAnalysis(
   [this](const Function &F) { return this->getTargetTransformInfo(F); });
 }
+
+std::pair TargetMachine::parseBinutilsVersion(StringRef Version) {
+  if (Version == "future")
+return {(int)TargetOptions::FutureBinutilsVersion, 0};
+  std::pair Ret;
+  if (!Version.consumeInteger(10, Ret.first) && Version.consume_front("."))
+Version.consumeInteger(10, Ret.second);
+  return Ret;
+}
Ind

[PATCH] D84600: [Analyzer] Support note tags for smart ptr checker

2020-08-09 Thread Nithin VR via Phabricator via cfe-commits
vrnithinkumar added inline comments.



Comment at: clang/test/Analysis/smart-ptr-text-output.cpp:79
+
+// TODO: Enabale this test when "std::swap" is modeled seperately.
+void derefOnStdSwappedNullPtr() {

NoQ wrote:
> vrnithinkumar wrote:
> > vrnithinkumar wrote:
> > > NoQ wrote:
> > > > Instead of commenting out tests, i recommend testing the incorrect 
> > > > behavior (with a FIXME comment telling us why it's incorrect). This way 
> > > > we'll be notified when the test is fixed, accidentally or 
> > > > intentionally, and also generally that's more testing for everybody.
> > > I have commented out this since right now `std::swap` is using 
> > > `unique_ptr.swap`.
> > > So note tag for std::swap is added in header file  
> > > `system-header-simulator-cxx.h`
> > > eg:
> > > `system-header-simulator-cxx.h Line 978: Swapped null smart pointer 
> > > 'PNull' with smart pointer 'P'`
> > - Is it okay to add a expected-note on `system-header-simulator-cxx.h`?
> Aha, i see.
> 
> It's obviously not ok because the header is included by multiple tests but 
> only some tests will have the note show up.
> 
> The usual solution is to put the expected-note comment in the current test 
> file but make it refer to the header. Here's doc from 
> https://clang.llvm.org/doxygen/classclang_1_1VerifyDiagnosticConsumer.html:
> > If the diagnostic is generated in a separate file, for example in a shared 
> > header file, it may be beneficial to be able to declare the file in which 
> > the diagnostic will appear, rather than placing the expected-* directive in 
> > the actual file itself. This can be done using the following syntax:
> > ```// expected-error@path/include.h:15 {{error message}}```
> 
> It still is a bit of a problem that you have to hardcode the line number (so 
> everybody who modifies the header above your note will have to update your 
> test) but that's not a big deal.
Thanks!
Added the tags for the line from header file.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84600/new/

https://reviews.llvm.org/D84600

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84600: [Analyzer] Support note tags for smart ptr checker

2020-08-09 Thread Nithin VR via Phabricator via cfe-commits
vrnithinkumar updated this revision to Diff 284237.
vrnithinkumar marked an inline comment as done.
vrnithinkumar added a comment.

- Updating test with tags from header file


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84600/new/

https://reviews.llvm.org/D84600

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp
  clang/test/Analysis/smart-ptr.cpp

Index: clang/test/Analysis/smart-ptr.cpp
===
--- clang/test/Analysis/smart-ptr.cpp
+++ clang/test/Analysis/smart-ptr.cpp
@@ -12,7 +12,7 @@
   std::unique_ptr Q = std::move(P);
   if (Q)
 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
-  *Q.get() = 1; // no-warning
+  *Q.get() = 1; // no-warning
   if (P)
 clang_analyzer_warnIfReached(); // no-warning
   // TODO: Report a null dereference (instead).
@@ -50,37 +50,38 @@
 
 void derefAfterDefaultCtr() {
   std::unique_ptr P;
-  P->foo(); // expected-warning {{Dereference of null smart pointer [alpha.cplusplus.SmartPtr]}}
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 }
 
 void derefAfterCtrWithNull() {
   std::unique_ptr P(nullptr);
-  *P; // expected-warning {{Dereference of null smart pointer [alpha.cplusplus.SmartPtr]}}
+  *P; // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 }
 
-void derefAfterCtrWithNullReturnMethod() {
-  std::unique_ptr P(return_null());
-  P->foo(); // expected-warning {{Dereference of null smart pointer [alpha.cplusplus.SmartPtr]}}
+void derefAfterCtrWithNullVariable() {
+  A *InnerPtr = nullptr;
+  std::unique_ptr P(InnerPtr);
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 }
 
 void derefAfterRelease() {
   std::unique_ptr P(new A());
   P.release();
   clang_analyzer_numTimesReached(); // expected-warning {{1}}
-  P->foo(); // expected-warning {{Dereference of null smart pointer [alpha.cplusplus.SmartPtr]}}
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 }
 
 void derefAfterReset() {
   std::unique_ptr P(new A());
   P.reset();
   clang_analyzer_numTimesReached(); // expected-warning {{1}}
-  P->foo(); // expected-warning {{Dereference of null smart pointer [alpha.cplusplus.SmartPtr]}}
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 }
 
 void derefAfterResetWithNull() {
   std::unique_ptr P(new A());
   P.reset(nullptr);
-  P->foo(); // expected-warning {{Dereference of null smart pointer [alpha.cplusplus.SmartPtr]}}
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 }
 
 void derefAfterResetWithNonNull() {
@@ -102,6 +103,12 @@
   AP->foo(); // expected-warning {{Called C++ object pointer is null [core.CallAndMessage]}}
 }
 
+void derefOnReleasedValidRawPtr() {
+  std::unique_ptr P(new A());
+  A *AP = P.release();
+  AP->foo(); // No warning.
+}
+
 void pass_smart_ptr_by_ref(std::unique_ptr &a);
 void pass_smart_ptr_by_const_ref(const std::unique_ptr &a);
 void pass_smart_ptr_by_rvalue_ref(std::unique_ptr &&a);
@@ -118,7 +125,7 @@
   {
 std::unique_ptr P;
 pass_smart_ptr_by_const_ref(P);
-P->foo(); // expected-warning {{Dereference of null smart pointer [alpha.cplusplus.SmartPtr]}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
   }
   {
 std::unique_ptr P;
@@ -128,7 +135,7 @@
   {
 std::unique_ptr P;
 pass_smart_ptr_by_const_rvalue_ref(std::move(P));
-P->foo(); // expected-warning {{Dereference of null smart pointer [alpha.cplusplus.SmartPtr]}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
   }
   {
 std::unique_ptr P;
@@ -138,7 +145,7 @@
   {
 std::unique_ptr P;
 pass_smart_ptr_by_const_ptr(&P);
-P->foo(); // expected-warning {{Dereference of null smart pointer [alpha.cplusplus.SmartPtr]}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
   }
 }
 
@@ -162,7 +169,7 @@
   {
 StructWithSmartPtr S;
 pass_struct_with_smart_ptr_by_const_ref(S);
-S.P->foo(); // expected-warning {{Dereference of null smart pointer [alpha.cplusplus.SmartPtr]}}
+S.P->foo(); // expected-warning {{Dereference of null smart pointer 'S.P' [alpha.cplusplus.SmartPtr]}}
   }
   {
 StructWithSmartPtr S;
@@ -172,7 +179,7 @@
   {
 StructWithSmartPtr S;
 pass_struct_with_smart_ptr_by_const_rvalue_ref(std::move(S));
-S.P->foo(); // ex

[clang] 92e82a2 - int64_t and intmax_t are always (signed) long long on OpenBSD.

2020-08-09 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2020-08-09T19:43:16-04:00
New Revision: 92e82a2890c38bbb158cbf9dd592328b4c383696

URL: 
https://github.com/llvm/llvm-project/commit/92e82a2890c38bbb158cbf9dd592328b4c383696
DIFF: 
https://github.com/llvm/llvm-project/commit/92e82a2890c38bbb158cbf9dd592328b4c383696.diff

LOG: int64_t and intmax_t are always (signed) long long on OpenBSD.

Added: 


Modified: 
clang/lib/Basic/Targets/OSTargets.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index cc726a92a7ca..f89eb0add553 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -465,6 +465,8 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public 
OSTargetInfo {
 public:
   OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : OSTargetInfo(Triple, Opts) {
+this->IntMaxType = TargetInfo::SignedLongLong;
+this->Int64Type = TargetInfo::SignedLongLong;
 switch (Triple.getArch()) {
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85621: [clang] Allow DynTypedNode to store a TemplateArgumentLoc

2020-08-09 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: hokein.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nridge requested review of this revision.

The patch also adds a templateArgumentLoc() AST matcher.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85621

Files:
  clang/include/clang/AST/ASTTypeTraits.h
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/AST/ASTTypeTraits.cpp
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2637,6 +2637,19 @@
 std::make_unique>("x", 1)));
 }
 
+TEST(TemplateArgumentLoc, Matches) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  R"cpp(
+template  class C> class X {};
+class A {};
+const int B = 42;
+template  class C {};
+X x;
+  )cpp",
+  templateArgumentLoc().bind("x"),
+  std::make_unique>("x", 3)));
+}
+
 TEST(LoopingMatchers, DoNotOverwritePreviousMatchResultOnFailure) {
   // Those matchers cover all the cases where an inner matcher is called
   // and there is not a 1:1 relationship between the match of the outer
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -734,6 +734,7 @@
 accessSpecDecl;
 const internal::VariadicAllOfMatcher cxxCtorInitializer;
 const internal::VariadicAllOfMatcher templateArgument;
+const internal::VariadicAllOfMatcher templateArgumentLoc;
 const internal::VariadicAllOfMatcher templateName;
 const internal::VariadicDynCastAllOfMatcher
 nonTypeTemplateParmDecl;
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -128,6 +128,9 @@
   traverse(*T);
 else if (const auto *C = DynNode.get())
   traverse(*C);
+else if (const TemplateArgumentLoc *TALoc =
+ DynNode.get())
+  traverse(*TALoc);
 // FIXME: Add other base types after adding tests.
 
 // It's OK to always overwrite the bound nodes, as if there was
@@ -224,6 +227,10 @@
 ScopedIncrement ScopedDepth(&CurrentDepth);
 return traverse(*CtorInit);
   }
+  bool TraverseTemplateArgumentLoc(TemplateArgumentLoc TAL) {
+ScopedIncrement ScopedDepth(&CurrentDepth);
+return traverse(TAL);
+  }
   bool TraverseLambdaExpr(LambdaExpr *Node) {
 if (Finder->getASTContext().getParentMapContext().getTraversalKind() !=
 TK_IgnoreUnlessSpelledInSource)
@@ -304,6 +311,9 @@
 return VisitorBase::TraverseConstructorInitializer(
 const_cast(&CtorInit));
   }
+  bool baseTraverse(TemplateArgumentLoc TAL) {
+return VisitorBase::TraverseTemplateArgumentLoc(TAL);
+  }
 
   // Sets 'Matched' to true if 'Matcher' matches 'Node' and:
   //   0 < CurrentDepth <= MaxDepth.
@@ -447,6 +457,7 @@
   bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
   bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit);
+  bool TraverseTemplateArgumentLoc(TemplateArgumentLoc TAL);
 
   // Matches children or descendants of 'Node' with 'BaseMatcher'.
   bool memoizedMatchesRecursively(const DynTypedNode &Node, ASTContext &Ctx,
@@ -557,6 +568,8 @@
   match(*N);
 } else if (auto *N = Node.get()) {
   match(*N);
+} else if (auto *N = Node.get()) {
+  match(*N);
 }
   }
 
@@ -680,6 +693,9 @@
   void matchDispatch(const CXXCtorInitializer *Node) {
 matchWithoutFilter(*Node, Matchers->CtorInit);
   }
+  void matchDispatch(const TemplateArgumentLoc *Node) {
+matchWithoutFilter(*Node, Matchers->TemplateArgumentLoc);
+  }
   void matchDispatch(const void *) { /* Do nothing. */ }
   /// @}
 
@@ -1035,6 +1051,11 @@
   CtorInit);
 }
 
+bool MatchASTVisitor::TraverseTemplateArgumentLoc(TemplateArgumentLoc Loc) {
+  match(Loc);
+  return RecursiveASTVisitor::TraverseTemplateArgumentLoc(Loc);
+}
+
 class MatchASTConsumer : public ASTConsumer {
 public:
   MatchASTConsumer(MatchFinder *Finder,
@@ -,6 +1132,12 @@
   Matchers.AllCallbacks.insert(Action);
 }
 
+void MatchFinder::addMatcher(const TemplateArgumentLocMatcher &NodeMatch,
+ MatchCallback *Action) {
+  Matchers.TemplateArgumentLoc.emplace_back(NodeMatch, Action);
+  Matchers.AllCallbacks.insert(Action);
+}
+
 bool MatchFinder::addDynamicMatcher(const internal

[PATCH] D85503: [clangd] Have template template arguments target their referenced template decl

2020-08-09 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 284245.
nridge added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85503/new/

https://reviews.llvm.org/D85503

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -376,6 +376,14 @@
{"template<> class Foo", Rel::TemplateInstantiation},
{"template  class Foo", Rel::TemplatePattern});
 
+  Code = R"cpp(
+// Default argument of template template parameter.
+template struct Vector {};
+template  class Container = [[Vector]]>
+struct A {};
+  )cpp";
+  EXPECT_DECLS("TemplateArgumentLoc", {"template  struct Vector"});
+
   Flags.push_back("-std=c++17"); // for CTAD tests
 
   Code = R"cpp(
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -479,6 +479,10 @@
   bool TraverseTypeLoc(TypeLoc X) {
 return traverseNode(&X, [&] { return Base::TraverseTypeLoc(X); });
   }
+  bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &X) {
+return traverseNode(&X,
+[&] { return Base::TraverseTemplateArgumentLoc(X); });
+  }
   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc X) {
 return traverseNode(
 &X, [&] { return Base::TraverseNestedNameSpecifierLoc(X); });
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -590,6 +590,19 @@
   add(CCI->getAnyMember(), Flags);
 // Constructor calls contain a TypeLoc node, so we don't handle them here.
   }
+
+  void add(const TemplateArgument &Arg, RelSet Flags) {
+// Only used for template template arguments.
+// For type and non-type template arguments, SelectionTree
+// will hit a more specific node (e.g. a TypeLoc or a
+// DeclRefExpr).
+if (Arg.getKind() == TemplateArgument::Template ||
+Arg.getKind() == TemplateArgument::TemplateExpansion) {
+  if (TemplateDecl *TD = Arg.getAsTemplate().getAsTemplateDecl()) {
+report(TD, Flags);
+  }
+}
+  }
 };
 
 } // namespace
@@ -613,6 +626,8 @@
 Finder.add(*QT, Flags);
   else if (const CXXCtorInitializer *CCI = N.get())
 Finder.add(CCI, Flags);
+  else if (const TemplateArgumentLoc *TAL = N.get())
+Finder.add(TAL->getArgument(), Flags);
 
   return Finder.takeDecls();
 }


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -376,6 +376,14 @@
{"template<> class Foo", Rel::TemplateInstantiation},
{"template  class Foo", Rel::TemplatePattern});
 
+  Code = R"cpp(
+// Default argument of template template parameter.
+template struct Vector {};
+template  class Container = [[Vector]]>
+struct A {};
+  )cpp";
+  EXPECT_DECLS("TemplateArgumentLoc", {"template  struct Vector"});
+
   Flags.push_back("-std=c++17"); // for CTAD tests
 
   Code = R"cpp(
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -479,6 +479,10 @@
   bool TraverseTypeLoc(TypeLoc X) {
 return traverseNode(&X, [&] { return Base::TraverseTypeLoc(X); });
   }
+  bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &X) {
+return traverseNode(&X,
+[&] { return Base::TraverseTemplateArgumentLoc(X); });
+  }
   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc X) {
 return traverseNode(
 &X, [&] { return Base::TraverseNestedNameSpecifierLoc(X); });
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -590,6 +590,19 @@
   add(CCI->getAnyMember(), Flags);
 // Constructor calls contain a TypeLoc node, so we don't handle them here.
   }
+
+  void add(const TemplateArgument &Arg, RelSet Flags) {
+// Only used for template template arguments.
+// For type and non-type template arguments, SelectionTree
+// will hit a more specific node (e.g. a TypeLoc or a
+// DeclRefExpr).
+if (Arg.getKind() == TemplateArgument::Template ||
+  

[PATCH] D85503: [clangd] Have template template arguments target their referenced template decl

2020-08-09 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

I've added the matcher and split the clang parts into D85621 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85503/new/

https://reviews.llvm.org/D85503

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f5fdb61 - Re-enable OpenBSD PowerPC64 tests.

2020-08-09 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2020-08-09T20:52:43-04:00
New Revision: f5fdb6141c5e7a76a10ea702d6fc046692827c43

URL: 
https://github.com/llvm/llvm-project/commit/f5fdb6141c5e7a76a10ea702d6fc046692827c43
DIFF: 
https://github.com/llvm/llvm-project/commit/f5fdb6141c5e7a76a10ea702d6fc046692827c43.diff

LOG: Re-enable OpenBSD PowerPC64 tests.

Added: 


Modified: 
clang/test/Preprocessor/init.c

Removed: 




diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index d6f3225bd04b..9e085a8f9fe8 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -7321,6 +7321,8 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding 
-triple=arm-unknown-openbsd6.1-gnueabi < /dev/null | FileCheck 
-match-full-lines -check-prefix OPENBSD %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-unknown-openbsd6.1 < 
/dev/null | FileCheck -match-full-lines -check-prefix OPENBSD %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-openbsd6.1 < 
/dev/null | FileCheck -match-full-lines -check-prefix OPENBSD %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-openbsd6.1 
< /dev/null | FileCheck -match-full-lines -check-prefix OPENBSD %s
+// RUN: %clang_cc1 -E -dM -ffreestanding 
-triple=powerpc64le-unknown-openbsd6.1 < /dev/null | FileCheck 
-match-full-lines -check-prefix OPENBSD %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-unknown-openbsd6.1 < 
/dev/null | FileCheck -match-full-lines -check-prefix OPENBSD %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64el-unknown-openbsd6.1 < 
/dev/null | FileCheck -match-full-lines -check-prefix OPENBSD %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc64-unknown-openbsd6.1 < 
/dev/null | FileCheck -match-full-lines -check-prefix OPENBSD %s



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85345: [BuildLibCalls] Add noundef to standard I/O functions

2020-08-09 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune updated this revision to Diff 284246.
aqjune added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update PR3589-freestanding-libcalls.c


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85345/new/

https://reviews.llvm.org/D85345

Files:
  clang/test/CodeGen/PR3589-freestanding-libcalls.c
  llvm/lib/Transforms/Utils/BuildLibCalls.cpp
  llvm/test/CodeGen/X86/no-plt-libcalls.ll
  llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Index: llvm/test/Transforms/InferFunctionAttrs/annotate.ll
===
--- llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ llvm/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -352,19 +352,19 @@
 ; CHECK: declare x86_fp80 @fabsl(x86_fp80) [[G0]]
 declare x86_fp80 @fabsl(x86_fp80)
 
-; CHECK: declare i32 @fclose(%opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fclose(%opaque* nocapture noundef) [[G1]]
 declare i32 @fclose(%opaque*)
 
-; CHECK: declare noalias %opaque* @fdopen(i32, i8* nocapture readonly) [[G1]]
+; CHECK: declare noalias noundef %opaque* @fdopen(i32 noundef, i8* nocapture noundef readonly) [[G1]]
 declare %opaque* @fdopen(i32, i8*)
 
-; CHECK: declare i32 @feof(%opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @feof(%opaque* nocapture noundef) [[G1]]
 declare i32 @feof(%opaque*)
 
-; CHECK: declare i32 @ferror(%opaque* nocapture) [[G2]]
+; CHECK: declare noundef i32 @ferror(%opaque* nocapture noundef) [[G2]]
 declare i32 @ferror(%opaque*)
 
-; CHECK: declare i32 @fflush(%opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fflush(%opaque* nocapture noundef) [[G1]]
 declare i32 @fflush(%opaque*)
 
 ; CHECK: declare i32 @ffs(i32) [[G0]]
@@ -376,19 +376,19 @@
 ; CHECK: declare i32 @ffsll(i64) [[G0]]
 declare i32 @ffsll(i64)
 
-; CHECK: declare i32 @fgetc(%opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fgetc(%opaque* nocapture noundef) [[G1]]
 declare i32 @fgetc(%opaque*)
 
-; CHECK: declare i32 @fgetpos(%opaque* nocapture, i64* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fgetpos(%opaque* nocapture noundef, i64* nocapture noundef) [[G1]]
 declare i32 @fgetpos(%opaque*, i64*)
 
-; CHECK: declare i8* @fgets(i8*, i32, %opaque* nocapture) [[G1]]
+; CHECK: declare noundef i8* @fgets(i8* noundef, i32 noundef, %opaque* nocapture noundef) [[G1]]
 declare i8* @fgets(i8*, i32, %opaque*)
 
-; CHECK: declare i32 @fileno(%opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fileno(%opaque* nocapture noundef) [[G1]]
 declare i32 @fileno(%opaque*)
 
-; CHECK: declare void @flockfile(%opaque* nocapture) [[G1]]
+; CHECK: declare void @flockfile(%opaque* nocapture noundef) [[G1]]
 declare void @flockfile(%opaque*)
 
 ; CHECK: declare double @floor(double) [[G0]]
@@ -436,19 +436,19 @@
 ; CHECK: declare x86_fp80 @fmodl(x86_fp80, x86_fp80) [[G0]]
 declare x86_fp80 @fmodl(x86_fp80, x86_fp80)
 
-; CHECK: declare noalias %opaque* @fopen(i8* nocapture readonly, i8* nocapture readonly) [[G1]]
+; CHECK: declare noalias noundef %opaque* @fopen(i8* nocapture noundef readonly, i8* nocapture noundef readonly) [[G1]]
 declare %opaque* @fopen(i8*, i8*)
 
-; CHECK: declare i32 @fprintf(%opaque* nocapture, i8* nocapture readonly, ...) [[G1]]
+; CHECK: declare noundef i32 @fprintf(%opaque* nocapture noundef, i8* nocapture noundef readonly, ...) [[G1]]
 declare i32 @fprintf(%opaque*, i8*, ...)
 
-; CHECK: declare i32 @fputc(i32, %opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fputc(i32 noundef, %opaque* nocapture noundef) [[G1]]
 declare i32 @fputc(i32, %opaque*)
 
-; CHECK: declare i32 @fputs(i8* nocapture readonly, %opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fputs(i8* nocapture noundef readonly, %opaque* nocapture noundef) [[G1]]
 declare i32 @fputs(i8*, %opaque*)
 
-; CHECK: declare i64 @fread(i8* nocapture, i64, i64, %opaque* nocapture) [[G1]]
+; CHECK: declare noundef i64 @fread(i8* nocapture noundef, i64 noundef, i64 noundef, %opaque* nocapture noundef) [[G1]]
 declare i64 @fread(i8*, i64, i64, %opaque*)
 
 ; CHECK: declare void @free(i8* nocapture) [[G3:#[0-9]+]]
@@ -463,61 +463,61 @@
 ; CHECK: declare x86_fp80 @frexpl(x86_fp80, i32* nocapture) [[G1]]
 declare x86_fp80 @frexpl(x86_fp80, i32*)
 
-; CHECK: declare i32 @fscanf(%opaque* nocapture, i8* nocapture readonly, ...) [[G1]]
+; CHECK: declare noundef i32 @fscanf(%opaque* nocapture noundef, i8* nocapture noundef readonly, ...) [[G1]]
 declare i32 @fscanf(%opaque*, i8*, ...)
 
-; CHECK: declare i32 @fseek(%opaque* nocapture, i64, i32) [[G1]]
+; CHECK: declare noundef i32 @fseek(%opaque* nocapture noundef, i64 noundef, i32 noundef) [[G1]]
 declare i32 @fseek(%opaque*, i64, i32)
 
-; CHECK: declare i32 @fseeko(%opaque* nocapture, i64, i32) [[G1]]
+; CHECK: declare noundef i32 @fseeko(%opaque* nocapture noundef, i64 noundef, i32 noundef) [[G1]]
 declare i32 @fseeko(%opaque*, i64, i32)
 
-; CHECK-LINUX: declare i32 @fseeko64(%opaque* noca

[PATCH] D85345: [BuildLibCalls] Add noundef to standard I/O functions

2020-08-09 Thread Juneyoung Lee via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGef018cb65c98: [BuildLibCalls] Add noundef to standard I/O 
functions (authored by aqjune).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85345/new/

https://reviews.llvm.org/D85345

Files:
  clang/test/CodeGen/PR3589-freestanding-libcalls.c
  llvm/lib/Transforms/Utils/BuildLibCalls.cpp
  llvm/test/CodeGen/X86/no-plt-libcalls.ll
  llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Index: llvm/test/Transforms/InferFunctionAttrs/annotate.ll
===
--- llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ llvm/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -352,19 +352,19 @@
 ; CHECK: declare x86_fp80 @fabsl(x86_fp80) [[G0]]
 declare x86_fp80 @fabsl(x86_fp80)
 
-; CHECK: declare i32 @fclose(%opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fclose(%opaque* nocapture noundef) [[G1]]
 declare i32 @fclose(%opaque*)
 
-; CHECK: declare noalias %opaque* @fdopen(i32, i8* nocapture readonly) [[G1]]
+; CHECK: declare noalias noundef %opaque* @fdopen(i32 noundef, i8* nocapture noundef readonly) [[G1]]
 declare %opaque* @fdopen(i32, i8*)
 
-; CHECK: declare i32 @feof(%opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @feof(%opaque* nocapture noundef) [[G1]]
 declare i32 @feof(%opaque*)
 
-; CHECK: declare i32 @ferror(%opaque* nocapture) [[G2]]
+; CHECK: declare noundef i32 @ferror(%opaque* nocapture noundef) [[G2]]
 declare i32 @ferror(%opaque*)
 
-; CHECK: declare i32 @fflush(%opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fflush(%opaque* nocapture noundef) [[G1]]
 declare i32 @fflush(%opaque*)
 
 ; CHECK: declare i32 @ffs(i32) [[G0]]
@@ -376,19 +376,19 @@
 ; CHECK: declare i32 @ffsll(i64) [[G0]]
 declare i32 @ffsll(i64)
 
-; CHECK: declare i32 @fgetc(%opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fgetc(%opaque* nocapture noundef) [[G1]]
 declare i32 @fgetc(%opaque*)
 
-; CHECK: declare i32 @fgetpos(%opaque* nocapture, i64* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fgetpos(%opaque* nocapture noundef, i64* nocapture noundef) [[G1]]
 declare i32 @fgetpos(%opaque*, i64*)
 
-; CHECK: declare i8* @fgets(i8*, i32, %opaque* nocapture) [[G1]]
+; CHECK: declare noundef i8* @fgets(i8* noundef, i32 noundef, %opaque* nocapture noundef) [[G1]]
 declare i8* @fgets(i8*, i32, %opaque*)
 
-; CHECK: declare i32 @fileno(%opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fileno(%opaque* nocapture noundef) [[G1]]
 declare i32 @fileno(%opaque*)
 
-; CHECK: declare void @flockfile(%opaque* nocapture) [[G1]]
+; CHECK: declare void @flockfile(%opaque* nocapture noundef) [[G1]]
 declare void @flockfile(%opaque*)
 
 ; CHECK: declare double @floor(double) [[G0]]
@@ -436,19 +436,19 @@
 ; CHECK: declare x86_fp80 @fmodl(x86_fp80, x86_fp80) [[G0]]
 declare x86_fp80 @fmodl(x86_fp80, x86_fp80)
 
-; CHECK: declare noalias %opaque* @fopen(i8* nocapture readonly, i8* nocapture readonly) [[G1]]
+; CHECK: declare noalias noundef %opaque* @fopen(i8* nocapture noundef readonly, i8* nocapture noundef readonly) [[G1]]
 declare %opaque* @fopen(i8*, i8*)
 
-; CHECK: declare i32 @fprintf(%opaque* nocapture, i8* nocapture readonly, ...) [[G1]]
+; CHECK: declare noundef i32 @fprintf(%opaque* nocapture noundef, i8* nocapture noundef readonly, ...) [[G1]]
 declare i32 @fprintf(%opaque*, i8*, ...)
 
-; CHECK: declare i32 @fputc(i32, %opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fputc(i32 noundef, %opaque* nocapture noundef) [[G1]]
 declare i32 @fputc(i32, %opaque*)
 
-; CHECK: declare i32 @fputs(i8* nocapture readonly, %opaque* nocapture) [[G1]]
+; CHECK: declare noundef i32 @fputs(i8* nocapture noundef readonly, %opaque* nocapture noundef) [[G1]]
 declare i32 @fputs(i8*, %opaque*)
 
-; CHECK: declare i64 @fread(i8* nocapture, i64, i64, %opaque* nocapture) [[G1]]
+; CHECK: declare noundef i64 @fread(i8* nocapture noundef, i64 noundef, i64 noundef, %opaque* nocapture noundef) [[G1]]
 declare i64 @fread(i8*, i64, i64, %opaque*)
 
 ; CHECK: declare void @free(i8* nocapture) [[G3:#[0-9]+]]
@@ -463,61 +463,61 @@
 ; CHECK: declare x86_fp80 @frexpl(x86_fp80, i32* nocapture) [[G1]]
 declare x86_fp80 @frexpl(x86_fp80, i32*)
 
-; CHECK: declare i32 @fscanf(%opaque* nocapture, i8* nocapture readonly, ...) [[G1]]
+; CHECK: declare noundef i32 @fscanf(%opaque* nocapture noundef, i8* nocapture noundef readonly, ...) [[G1]]
 declare i32 @fscanf(%opaque*, i8*, ...)
 
-; CHECK: declare i32 @fseek(%opaque* nocapture, i64, i32) [[G1]]
+; CHECK: declare noundef i32 @fseek(%opaque* nocapture noundef, i64 noundef, i32 noundef) [[G1]]
 declare i32 @fseek(%opaque*, i64, i32)
 
-; CHECK: declare i32 @fseeko(%opaque* nocapture, i64, i32) [[G1]]
+; CHECK: declare noundef i32 @fseeko(%opaque* nocapture noundef, i64 noundef, i32 noundef) [[G1]]
 declare i32 @fseeko(%opaque*, i64

[clang] ef018cb - [BuildLibCalls] Add noundef to standard I/O functions

2020-08-09 Thread Juneyoung Lee via cfe-commits

Author: Juneyoung Lee
Date: 2020-08-10T10:58:25+09:00
New Revision: ef018cb65c98fdb517930b762b3b3a3c0dd4dbdd

URL: 
https://github.com/llvm/llvm-project/commit/ef018cb65c98fdb517930b762b3b3a3c0dd4dbdd
DIFF: 
https://github.com/llvm/llvm-project/commit/ef018cb65c98fdb517930b762b3b3a3c0dd4dbdd.diff

LOG: [BuildLibCalls] Add noundef to standard I/O functions

This patch adds noundef to return value and arguments of standard I/O functions.
With this patch, passing undef or poison to the functions becomes undefined
behavior in LLVM IR. Since undef/poison is lowered from operations having UB in 
C/C++,
passing undef to them was already UB in source.

With this patch, the functions cannot return undef or poison anymore as well.
According to C17 standard, ungetc/ungetwc/fgetpos/ftell can generate unspecified
value; 3.19.3 says unspecified value is a valid value of the relevant type,
and using unspecified value is unspecified behavior, which is not UB, so it
cannot be undef (using undef is UB when e.g. it is used at branch condition).

— The value of the file position indicator after a successful call to the 
ungetc function for a text stream, or the ungetwc function for any stream, 
until all pushed-back characters are read or discarded (7.21.7.10, 7.29.3.10).
— The details of the value stored by the fgetpos function (7.21.9.1).
— The details of the value returned by the ftell function for a text stream 
(7.21.9.4).

In the long run, most of the functions listed in BuildLibCalls should have 
noundefs; to remove redundant diffs which will anyway disappear in the future, 
I added noundef to a few more non-I/O functions as well.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D85345

Added: 


Modified: 
clang/test/CodeGen/PR3589-freestanding-libcalls.c
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/test/CodeGen/X86/no-plt-libcalls.ll
llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Removed: 




diff  --git a/clang/test/CodeGen/PR3589-freestanding-libcalls.c 
b/clang/test/CodeGen/PR3589-freestanding-libcalls.c
index 5216e820411a..16c1b5e9348d 100644
--- a/clang/test/CodeGen/PR3589-freestanding-libcalls.c
+++ b/clang/test/CodeGen/PR3589-freestanding-libcalls.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | grep 
'declare i32 @printf' | count 1
-// RUN: %clang_cc1 -triple i386-unknown-unknown -O2 -emit-llvm %s -o - | grep 
'declare i32 @puts' | count 1
-// RUN: %clang_cc1 -triple i386-unknown-unknown -ffreestanding -O2 -emit-llvm 
%s -o - | not grep 'declare i32 @puts'
+// RUN: %clang_cc1 -triple i386-unknown-unknown -O2 -emit-llvm %s -o - | grep 
'declare noundef i32 @puts' | count 1
+// RUN: %clang_cc1 -triple i386-unknown-unknown -ffreestanding -O2 -emit-llvm 
%s -o - | not grep 'declare noundef i32 @puts'
 
 int printf(const char *, ...);
 

diff  --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp 
b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index c64ad147fdfe..563597beed06 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -37,6 +37,7 @@ STATISTIC(NumNoUnwind, "Number of functions inferred as 
nounwind");
 STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
 STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
 STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
+STATISTIC(NumNoUndef, "Number of function returns inferred as noundef 
returns");
 STATISTIC(NumNonNull, "Number of function returns inferred as nonnull 
returns");
 STATISTIC(NumReturnedArg, "Number of arguments inferred as returned");
 
@@ -104,6 +105,24 @@ static bool setOnlyReadsMemory(Function &F, unsigned 
ArgNo) {
   return true;
 }
 
+static bool setRetAndArgsNoUndef(Function &F) {
+  bool Changed = false;
+  if (!F.getReturnType()->isVoidTy() &&
+  !F.hasAttribute(AttributeList::ReturnIndex, Attribute::NoUndef)) {
+F.addAttribute(AttributeList::ReturnIndex, Attribute::NoUndef);
+++NumNoUndef;
+Changed = true;
+  }
+  for (unsigned ArgNo = 0; ArgNo < F.arg_size(); ++ArgNo) {
+if (!F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
+  F.addParamAttr(ArgNo, Attribute::NoUndef);
+  ++NumNoUndef;
+  Changed = true;
+}
+  }
+  return Changed;
+}
+
 static bool setRetNonNull(Function &F) {
   assert(F.getReturnType()->isPointerTy() &&
  "nonnull applies only to pointers");
@@ -227,6 +246,7 @@ bool llvm::inferLibFuncAttributes(Function &F, const 
TargetLibraryInfo &TLI) {
 Changed |= setOnlyReadsMemory(F, 1);
 return Changed;
   case LibFunc_scanf:
+Changed |= setRetAndArgsNoUndef(F);
 Changed |= setDoesNotThrow(F);
 Changed |= setDoesNotCapture(F, 0);
 Changed |= setOnlyReadsMemory(F, 0);
@@ -251,6 +271,7 @@ bool llvm::inferLibFuncAttributes(Function &F, const 
TargetLibraryInfo &TLI) {
 Change

[PATCH] D85345: [BuildLibCalls] Add noundef to standard I/O functions

2020-08-09 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune added a comment.

If things go well, I'll add noundef to other library functions such as utime, 
setenv, unsetenv,  as well.
For malloc/calloc/realloc/free, I'll think more about them. I guess it is safe 
to tag noundef to free's operand, but for malloc I'm not 100% sure...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85345/new/

https://reviews.llvm.org/D85345

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85345: [BuildLibCalls] Add noundef to standard I/O functions

2020-08-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D85345#2205691 , @aqjune wrote:

> If things go well, I'll add noundef to other library functions such as utime, 
> setenv, unsetenv,  as well.
> For malloc/calloc/realloc/free, I'll think more about them. I guess it is 
> safe to tag noundef to free's operand, but for malloc I'm not 100% sure...

What I think is helpful is the operand of a free and the return value of a 
{m,c,re}alloc. Arguably, you can give the latter anything but what falls out is 
better not undef or poison ;)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85345/new/

https://reviews.llvm.org/D85345

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85345: [BuildLibCalls] Add noundef to standard I/O functions

2020-08-09 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune added a comment.

What about undef or poison is given to malloc? If it should raise UB, the size 
argument and returned pointer should be noundef.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85345/new/

https://reviews.llvm.org/D85345

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83338: [PowerPC][Power10] Implemented Vector Shift Builtins

2020-08-09 Thread Amy Kwan via Phabricator via cfe-commits
amyk accepted this revision.
amyk added a comment.
This revision is now accepted and ready to land.

Thanks for addressing the comments. LGTM.




Comment at: llvm/test/CodeGen/PowerPC/p10-vector-shift.ll:10
+
+; These tests ensure that vector shift quadword builtins are correctly
+; exploited and selected for during codeGen.

nit: 
```
These test cases demonstrate that the vector shift quadword instructions 
introduced 
within Power10 are correctly exploited.
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83338/new/

https://reviews.llvm.org/D83338

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85612: [Sema] Use proper integral cast for an enumerate with a fixed bool type

2020-08-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/test/AST/ast-dump-enum-bool.cpp:1
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump=json 
%s | FileCheck %s
+

aaron.ballman wrote:
> riccibruno wrote:
> > Why a (pretty unreadable) json test? There is also `make-ast-dump-check.sh` 
> > to auto-generate an ast dump test.
> I'd also like to see some CodeGen tests for various fixed underlying types 
> that ensures the conversion to the underlying type happens before the 
> conversion to the enumeration.
> 
> Also, at least one test showing this behaves properly with a C-style cast 
> instead of a named cast.
In addition to CodeGen tests, we should also test that constant evaluation does 
the right thing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85612/new/

https://reviews.llvm.org/D85612

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85345: [BuildLibCalls] Add noundef to standard I/O functions

2020-08-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D85345#2205712 , @aqjune wrote:

> What about undef or poison is given to malloc? If it should raise UB, the 
> size argument and returned pointer should be noundef.

It is unclear to me if we want to forbid undef to be passed to malloc. It makes 
practical sense but not from a semantic perspective.
However, even if you pass undef you should not get undef back. So the return 
should never be undef for sure. If it doesn, how could you ever deal with it, 
given that a branch on the result would be UB :D


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85345/new/

https://reviews.llvm.org/D85345

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85424: [Analyzer] Crash fix for alpha.cplusplus.IteratorRange

2020-08-09 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In D85424#2203329 , @NoQ wrote:

> Tests? (edit: ok, i see, you have trouble reducing the test. yes, we 
> absolutely need a test, please finish with creduce/delta.)

I will not commit it without tests, even if someone accepts it. We are working 
on it using //creduce//.

> There should be no `UndefinedVal`s in function arguments unless you disable 
> `core` checkers (which isn't supported).

Hmm, then it means that instead of this patch we should investigate why the 
argument is `UndefinedVal` and fix the issue there. All the `core` checkers are 
enabled, of course.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85424/new/

https://reviews.llvm.org/D85424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85613: [clang] Look through bindings when checking whether a default argument references a local entity.

2020-08-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:101-105
+if (const VarDecl *HoldingVar = Binding->getHoldingVar()) {
+  // C++20 [dcl.struct.bind]p4:
+  //   Each vi is the name [...] that refers to the object bound to ri 
[...]
+  Decl = HoldingVar;
+} else {

Is there a reason to separate these two cases? (Could we just use the 
decomposed decl unconditionally?) Generally treating tuple-like decompositions 
differently from other kinds seems error-prone.



Comment at: clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp:51
+  extern void h8a(int = sizeof(z)); // ok
+  extern void h8b(int = w); // expected-error {{default argument 
references local variable 'w'}}
 

The diagnostic in this case is inconsistent with the non-tuple-like cases. I 
think this diagnostic is better; we should use the original `Decl` when 
producing the diagnostic, not the decomposed variable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85613/new/

https://reviews.llvm.org/D85613

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85523: [clang-tidy] Fix a crash in bugprone-not-null-terminated-result check when `__STDC_WANT_LIB_EXT1__` was undefined after definition.

2020-08-09 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX updated this revision to Diff 284257.
ArcsinX added a comment.

newline


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85523/new/

https://reviews.llvm.org/D85523

Files:
  clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-undef-stdc-want-lib-ext1.c


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-undef-stdc-want-lib-ext1.c
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-undef-stdc-want-lib-ext1.c
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
+// RUN: -- -std=c11 -I %S/Inputs/bugprone-not-null-terminated-result
+
+#include "not-null-terminated-result-c.h"
+
+#define __STDC_LIB_EXT1__ 1
+#define __STDC_WANT_LIB_EXT1__ 1
+#undef __STDC_WANT_LIB_EXT1__
+
+void f(const char *src) {
+  char dest[13];
+  memcpy_s(dest, 13, src, strlen(src) - 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 
'memcpy_s' is not null-terminated [bugprone-not-null-terminated-result]
+  // CHECK-FIXES: char dest[14];
+  // CHECK-FIXES-NEXT: strncpy_s(dest, 14, src, strlen(src) - 1);
+}
+
Index: clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -802,11 +802,14 @@
 while (It != PP->macro_end() && !AreSafeFunctionsWanted.hasValue()) {
   if (It->first->getName() == "__STDC_WANT_LIB_EXT1__") {
 const auto *MI = PP->getMacroInfo(It->first);
-const auto &T = MI->tokens().back();
-StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
-llvm::APInt IntValue;
-ValueStr.getAsInteger(10, IntValue);
-AreSafeFunctionsWanted = IntValue.getZExtValue();
+// PP->getMacroInfo() returns nullptr if macro has no definition.
+if (MI) {
+  const auto &T = MI->tokens().back();
+  StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
+  llvm::APInt IntValue;
+  ValueStr.getAsInteger(10, IntValue);
+  AreSafeFunctionsWanted = IntValue.getZExtValue();
+}
   }
 
   ++It;


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-undef-stdc-want-lib-ext1.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-undef-stdc-want-lib-ext1.c
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
+// RUN: -- -std=c11 -I %S/Inputs/bugprone-not-null-terminated-result
+
+#include "not-null-terminated-result-c.h"
+
+#define __STDC_LIB_EXT1__ 1
+#define __STDC_WANT_LIB_EXT1__ 1
+#undef __STDC_WANT_LIB_EXT1__
+
+void f(const char *src) {
+  char dest[13];
+  memcpy_s(dest, 13, src, strlen(src) - 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'memcpy_s' is not null-terminated [bugprone-not-null-terminated-result]
+  // CHECK-FIXES: char dest[14];
+  // CHECK-FIXES-NEXT: strncpy_s(dest, 14, src, strlen(src) - 1);
+}
+
Index: clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -802,11 +802,14 @@
 while (It != PP->macro_end() && !AreSafeFunctionsWanted.hasValue()) {
   if (It->first->getName() == "__STDC_WANT_LIB_EXT1__") {
 const auto *MI = PP->getMacroInfo(It->first);
-const auto &T = MI->tokens().back();
-StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
-llvm::APInt IntValue;
-ValueStr.getAsInteger(10, IntValue);
-AreSafeFunctionsWanted = IntValue.getZExtValue();
+// PP->getMacroInfo() returns nullptr if macro has no definition.
+if (MI) {
+  const auto &T = MI->tokens().back();
+  StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
+  llvm::APInt IntValue;
+  ValueStr.getAsInteger(10, IntValue);
+  AreSafeFunctionsWanted = IntValue.getZExtValue();
+}
   }
 
   ++It;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85590: [clang][HeaderInsert] Do not treat defines with values as header guards

2020-08-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Tooling/HeaderIncludesTest.cpp:532
 
+TEST_F(HeaderIncludesTest, FakeHeaderGuardIfnDef) {
+  std::string Code = "#ifndef A_H\n"

could you move this to the `HeaderGuard section` of this file (~Line 349)?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85590/new/

https://reviews.llvm.org/D85590

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6170072 - Improve modeling of variable template specializations with dependent

2020-08-09 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-08-09T23:22:26-07:00
New Revision: 617007240cbfb97c8ccf6d61b0c4ca0bb62d43c9

URL: 
https://github.com/llvm/llvm-project/commit/617007240cbfb97c8ccf6d61b0c4ca0bb62d43c9
DIFF: 
https://github.com/llvm/llvm-project/commit/617007240cbfb97c8ccf6d61b0c4ca0bb62d43c9.diff

LOG: Improve modeling of variable template specializations with dependent
arguments.

Don't build a variable template specialization declaration until its
scope and template arguments are non-dependent.

No functionality change intended, but the AST representation is now more
consistent with how we model other templates.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExprMember.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 7fe9396dbfc3..d0bddd80b8fe 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4957,6 +4957,8 @@ def err_mismatched_exception_spec_explicit_instantiation 
: Error<
 def ext_mismatched_exception_spec_explicit_instantiation : ExtWarn<
   err_mismatched_exception_spec_explicit_instantiation.Text>,
   InGroup;
+def err_explicit_instantiation_dependent : Error<
+  "explicit instantiation has dependent template arguments">;
 
 // C++ typename-specifiers
 def err_typename_nested_not_found : Error<"no type named %0 in %1">;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 09e4c6743efc..6965b3326388 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7342,11 +7342,17 @@ class Sema final {
   SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams,
   StorageClass SC, bool IsPartialSpecialization);
 
+  /// Get the specialization of the given variable template corresponding to
+  /// the specified argument list, or a null-but-valid result if the arguments
+  /// are dependent.
   DeclResult CheckVarTemplateId(VarTemplateDecl *Template,
 SourceLocation TemplateLoc,
 SourceLocation TemplateNameLoc,
 const TemplateArgumentListInfo &TemplateArgs);
 
+  /// Form a reference to the specialization of the given variable template
+  /// corresponding to the specified argument list, or a null-but-valid result
+  /// if the arguments are dependent.
   ExprResult CheckVarTemplateId(const CXXScopeSpec &SS,
 const DeclarationNameInfo &NameInfo,
 VarTemplateDecl *Template,
@@ -9169,10 +9175,6 @@ class Sema final {
  bool InstantiatingVarTemplate = false,
  VarTemplateSpecializationDecl *PrevVTSD = 
nullptr);
 
-  VarDecl *getVarTemplateSpecialization(
-  VarTemplateDecl *VarTempl, const TemplateArgumentListInfo *TemplateArgs,
-  const DeclarationNameInfo &MemberNameInfo, SourceLocation TemplateKWLoc);
-
   void InstantiateVariableInitializer(
   VarDecl *Var, VarDecl *OldVar,
   const MultiLevelTemplateArgumentList &TemplateArgs);

diff  --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 466d1fe59c71..93ed756e084b 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -944,28 +944,6 @@ static bool IsInFnTryBlockHandler(const Scope *S) {
   return false;
 }
 
-VarDecl *
-Sema::getVarTemplateSpecialization(VarTemplateDecl *VarTempl,
-  const TemplateArgumentListInfo *TemplateArgs,
-  const DeclarationNameInfo &MemberNameInfo,
-  SourceLocation TemplateKWLoc) {
-  if (!TemplateArgs) {
-diagnoseMissingTemplateArguments(TemplateName(VarTempl),
- MemberNameInfo.getBeginLoc());
-return nullptr;
-  }
-
-  DeclResult VDecl = CheckVarTemplateId(VarTempl, TemplateKWLoc,
-MemberNameInfo.getLoc(), 
*TemplateArgs);
-  if (VDecl.isInvalid())
-return nullptr;
-  VarDecl *Var = cast(VDecl.get());
-  if (!Var->getTemplateSpecializationKind())
-Var->setTemplateSpecializationKind(TSK_ImplicitInstantiation,
-   MemberNameInfo.getLoc());
-  return Var;
-}
-
 ExprResult
 Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
SourceLocation OpLoc, bool IsArrow,
@@ -1097,19 +1075,11 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType 
BaseExprType,
   if (!BaseExpr) {
 // If this is not an instance member, convert to a non-member access.
 if (!MemberDecl->isCXXInstanceMember()) {
-  // If t

[PATCH] D57265: [PM/CC1] Add -f[no-]split-cold-code CC1 options to toggle splitting

2020-08-09 Thread Ruijie Fang via Phabricator via cfe-commits
rjf added a comment.
Herald added subscribers: dang, nikic.

Would also really like to see this patch landed. Also, as of today (8/10/2020), 
the patch cannot be cleanly applied into trunk without inducing merge conflicts 
anymore.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57265/new/

https://reviews.llvm.org/D57265

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85528: [analyzer] Fix cast evaluation on scoped enums in ExprEngine

2020-08-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D85528#2204664 , @steakhal wrote:

> In D85528#2203325 , @NoQ wrote:
>
>> Because this patch changes the behavior of regular analysis (without Z3), i 
>> expect tests to reflect that.
>
> What do you expect exactly?
>
> `REQUIRES: z3` is necessary for the refutation.
> However, adding this requirement would not mean that this test will run if 
> you have Z3 installed though.
> You should add the extra `llvm-lit` param to enable such tests.
> I don't want to repeat myself too much but D83677 
>  describes all the details of this test 
> infra fiasco.
> I would appreciate some feedback there.

I expect at least one LIT test //without// `-analyzer-config 
crosscheck-with-z3=true` (i.e., tests the default behavior, not the Z3 
behavior) and works differently before and after the patch. Because you are 
introducing a change in the default behavior: an unknown value is now denoted 
by a different symbolic value. And the default behavior is much more important 
to cover with tests than the non-default behavior - simply because it's the 
default behavior, which means the vast majority of our users will notice the 
change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85528/new/

https://reviews.llvm.org/D85528

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85424: [Analyzer] Crash fix for alpha.cplusplus.IteratorRange

2020-08-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp:228
   if (auto ValAsLoc = RHS.getAs()) {
 Value = State->getRawSVal(*ValAsLoc);
   }

Well, it looks like your value is not necessarily a function argument. The 
undefined value checker only catches undefined values passed as arguments 
directly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85424/new/

https://reviews.llvm.org/D85424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a4ca710 - More cleanup after removing the ability to reference a dependent

2020-08-09 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-08-09T23:40:22-07:00
New Revision: a4ca710d9ca9a779a97050149a483f7a5b24dd02

URL: 
https://github.com/llvm/llvm-project/commit/a4ca710d9ca9a779a97050149a483f7a5b24dd02
DIFF: 
https://github.com/llvm/llvm-project/commit/a4ca710d9ca9a779a97050149a483f7a5b24dd02.diff

LOG: More cleanup after removing the ability to reference a dependent
VarTemplateSpecializationDecl.

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index fe997e7719e7..23b2fbd5cbbf 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17925,8 +17925,6 @@ static void DoMarkVarDeclReferenced(Sema &SemaRef, 
SourceLocation Loc,
   bool NeedDefinition =
   OdrUse == OdrUseContext::Used || NeededForConstantEvaluation;
 
-  VarTemplateSpecializationDecl *VarSpec =
-  dyn_cast(Var);
   assert(!isa(Var) &&
  "Can't instantiate a partial template specialization.");
 
@@ -17961,30 +17959,21 @@ static void DoMarkVarDeclReferenced(Sema &SemaRef, 
SourceLocation Loc,
   Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
   }
 
-  bool InstantiationDependent = false;
-  bool IsNonDependent =
-  VarSpec ? !TemplateSpecializationType::anyDependentTemplateArguments(
-VarSpec->getTemplateArgsInfo(), InstantiationDependent)
-  : true;
-
-  // Do not instantiate specializations that are still type-dependent.
-  if (IsNonDependent) {
-if (UsableInConstantExpr) {
-  // Do not defer instantiations of variables that could be used in a
-  // constant expression.
-  SemaRef.runWithSufficientStackSpace(PointOfInstantiation, [&] {
-SemaRef.InstantiateVariableDefinition(PointOfInstantiation, Var);
-  });
-} else if (FirstInstantiation ||
-   isa(Var)) {
-  // FIXME: For a specialization of a variable template, we don't
-  // distinguish between "declaration and type implicitly instantiated"
-  // and "implicit instantiation of definition requested", so we have
-  // no direct way to avoid enqueueing the pending instantiation
-  // multiple times.
-  SemaRef.PendingInstantiations
-  .push_back(std::make_pair(Var, PointOfInstantiation));
-}
+  if (UsableInConstantExpr) {
+// Do not defer instantiations of variables that could be used in a
+// constant expression.
+SemaRef.runWithSufficientStackSpace(PointOfInstantiation, [&] {
+  SemaRef.InstantiateVariableDefinition(PointOfInstantiation, Var);
+});
+  } else if (FirstInstantiation ||
+ isa(Var)) {
+// FIXME: For a specialization of a variable template, we don't
+// distinguish between "declaration and type implicitly instantiated"
+// and "implicit instantiation of definition requested", so we have
+// no direct way to avoid enqueueing the pending instantiation
+// multiple times.
+SemaRef.PendingInstantiations
+.push_back(std::make_pair(Var, PointOfInstantiation));
   }
 }
   }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85621: [clang] Allow DynTypedNode to store a TemplateArgumentLoc

2020-08-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks.

Please run `clang/docs/tools/dump_ast_matchers.py` script to update the 
`LibASTMatchersReference.html` file.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85621/new/

https://reviews.llvm.org/D85621

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85503: [clangd] Have template template arguments target their referenced template decl

2020-08-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/Selection.cpp:482
   }
+  bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &X) {
+return traverseNode(&X,

can we add a test for the `Selection`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85503/new/

https://reviews.llvm.org/D85503

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85525: [clang-tidy] Fix a crash in bugprone-not-null-terminated-result check when `__STDC_WANT_LIB_EXT1__` is not a literal.

2020-08-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp:806
 const auto &T = MI->tokens().back();
-StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
-llvm::APInt IntValue;
-ValueStr.getAsInteger(10, IntValue);
-AreSafeFunctionsWanted = IntValue.getZExtValue();
+if (T.isLiteral()) {
+  StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());

ArcsinX wrote:
> hokein wrote:
> > let's add the `getLiteralData` check here --  `if (T.isLiteral() && 
> > T.getLiteralData())`
> Could we also add clangd test here for that case (when `T.isLiteral() == 
> true` and `T.getLiteralData() == nullptr`)?
I think it is fine to just change it here without a clangd test.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c:3
+// RUN: -- -std=c11 -I %S/Inputs/bugprone-not-null-terminated-result
+
+#include "not-null-terminated-result-c.h"

ArcsinX wrote:
> hokein wrote:
> > I think you probably need a `// UNSUPPORTED: system-windows`, as the 
> > `bugprone-not-null-terminated-result-strlen.c` does.
> Seems we don't need this.  
> Problem with `bugprone-not-null-terminated-result-strlen.c` test on Windows 
> related with `strncmp`, according with comment.
> ```
> // FIXME: Something wrong with the APInt un/signed conversion on Windows:
> // in 'strncmp(str6, "string", 7);' it tries to inject '4294967302' as length.
> 
> // UNSUPPORTED: system-windows
> ```
> 
> E.g. `bugprone-not-null-terminated-result-memcpy-safe` also uses `strlen`
I see, good catch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85525/new/

https://reviews.llvm.org/D85525

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85625: Fix documentation URL in AvoidBindCheck.h

2020-08-09 Thread Christoph Bachhuber via Phabricator via cfe-commits
cbachhuber created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
cbachhuber requested review of this revision.

The URL on current master is a 404. This change fixes that and leads to the 
correct page.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85625

Files:
  clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h


Index: clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
+++ clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
@@ -20,7 +20,7 @@
 /// FIXME: Add support for function references and member function references.
 ///
 /// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/modernize-avoid-std-bind.html
+/// http://clang.llvm.org/extra/clang-tidy/checks/modernize-avoid-bind.html
 class AvoidBindCheck : public ClangTidyCheck {
 public:
   AvoidBindCheck(StringRef Name, ClangTidyContext *Context);


Index: clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
+++ clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
@@ -20,7 +20,7 @@
 /// FIXME: Add support for function references and member function references.
 ///
 /// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/modernize-avoid-std-bind.html
+/// http://clang.llvm.org/extra/clang-tidy/checks/modernize-avoid-bind.html
 class AvoidBindCheck : public ClangTidyCheck {
 public:
   AvoidBindCheck(StringRef Name, ClangTidyContext *Context);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83536: [clangd] Index refs to main-file symbols as well

2020-08-09 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 284262.
nridge added a comment.

Add the requested flag


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83536/new/

https://reviews.llvm.org/D83536

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/Background.h
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -613,6 +613,7 @@
   )");
   CollectorOpts.RefFilter = RefKind::All;
   CollectorOpts.CollectMacro = true;
+  CollectorOpts.CollectMainFileRefs = true;
   runSymbolCollector(Header.code(),
  (Main.code() + SymbolsOnlyInMainCode.code()).str());
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Foo").ID,
@@ -624,15 +625,13 @@
   EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "NS").ID, _;
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "MACRO").ID,
   HaveRanges(Main.ranges("macro");
-  // Symbols *only* in the main file:
-  // - (a, b) externally visible and should have refs.
-  // - (c, FUNC) externally invisible and had no refs collected.
-  auto MainSymbols =
-  TestTU::withHeaderCode(SymbolsOnlyInMainCode.code()).headerSymbols();
-  EXPECT_THAT(Refs, Contains(Pair(findSymbol(MainSymbols, "a").ID, _)));
-  EXPECT_THAT(Refs, Contains(Pair(findSymbol(MainSymbols, "b").ID, _)));
-  EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "c").ID, _;
-  EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "FUNC").ID, _;
+  // Symbols *only* in the main file (a, b, c) should have refs collected
+  // as well.
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "a").ID, _)));
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "b").ID, _)));
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "c").ID, _)));
+  // However, references to main-file macros are not collected.
+  EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "FUNC").ID, _;
 }
 
 TEST_F(SymbolCollectorTest, MacroRefInHeader) {
@@ -708,12 +707,12 @@
 llvm::StringRef Main;
 llvm::StringRef TargetSymbolName;
   } TestCases[] = {
-{
-  R"cpp(
+  {
+  R"cpp(
 struct Foo;
 #define MACRO Foo
   )cpp",
-  R"cpp(
+  R"cpp(
 struct $spelled[[Foo]] {
   $spelled[[Foo]]();
   ~$spelled[[Foo]]();
@@ -721,24 +720,24 @@
 $spelled[[Foo]] Variable1;
 $implicit[[MACRO]] Variable2;
   )cpp",
-  "Foo",
-},
-{
-  R"cpp(
+  "Foo",
+  },
+  {
+  R"cpp(
 class Foo {
 public:
   Foo() = default;
 };
   )cpp",
-  R"cpp(
+  R"cpp(
 void f() { Foo $implicit[[f]]; f = $spelled[[Foo]]();}
   )cpp",
-  "Foo::Foo" /// constructor.
-},
+  "Foo::Foo" /// constructor.
+  },
   };
   CollectorOpts.RefFilter = RefKind::All;
   CollectorOpts.RefsInHeaders = false;
-  for (const auto& T : TestCases) {
+  for (const auto &T : TestCases) {
 Annotations Header(T.Header);
 Annotations Main(T.Main);
 // Reset the file system.
@@ -818,8 +817,9 @@
 $Foo[[Foo]] fo;
   }
   )");
-  // The main file is normal .cpp file, we should collect the refs
-  // for externally visible symbols.
+  // We should collect refs to main-file symbols in all cases:
+
+  // 1. The main file is normal .cpp file.
   TestFileName = testPath("foo.cpp");
   runSymbolCollector("", Header.code());
   EXPECT_THAT(Refs,
@@ -828,7 +828,7 @@
Pair(findSymbol(Symbols, "Func").ID,
 HaveRanges(Header.ranges("Func");
 
-  // Run the .h file as main file, we should collect the refs.
+  // 2. Run the .h file as main file.
   TestFileName = testPath("foo.h");
   runSymbolCollector("", Header.code(),
  /*ExtraArgs=*/{"-xobjective-c++-header"});
@@ -839,8 +839,7 @@
Pair(findSymbol(Symbols, "Func").ID,
 HaveRanges(Header.ranges("Func");
 
-  // Run the .hh file as main file (without "-x c++-header"), we should collect
-  // the refs as well.
+  // 3. Run the .hh file as main file (without "-x c++-header").
   TestFileName = testPath("foo.hh");
   runSymbolCollector("", He

[PATCH] D57265: [PM/CC1] Add -f[no-]split-cold-code CC1 options to toggle splitting

2020-08-09 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D57265#2205797 , @rjf wrote:

> Would also really like to see this patch landed. Also, as of today 
> (8/10/2020), the patch cannot be cleanly applied into trunk without inducing 
> merge conflicts anymore.

You might have some luck merging from github.com/apple/llvm-project. You may 
also want to look at some of the upstreaming work some of the Apple folks are 
doing at https://github.com/llvm/llvm-project-staging


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57265/new/

https://reviews.llvm.org/D57265

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits