[PATCH] D63518: BitStream reader: propagate errors

2019-06-24 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

I did a build of all LLVM monorepo projects, and only LLVM / clang / 
clang-tools-extra are impacted. I therefore ran tests as follows, and they all 
pass:

  rm -rf debug ; mkdir debug && (cd debug && cmake -G Ninja ../llvm 
-DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=Debug 
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" && ninja check-all )

I haven't run `clang-format` yet so ignore formatting. Otherwise, this patch is 
ready for review and getting committed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63518



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


[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists marked an inline comment as done.
mclow.lists added inline comments.



Comment at: libcxx/include/bit:378
+   const unsigned __retVal = 1u << (__n + __extra);
+   return (_Tp) (__retVal >> __extra);
+}

mclow.lists wrote:
> mclow.lists wrote:
> > Quuxplusone wrote:
> > > mclow.lists wrote:
> > > > mclow.lists wrote:
> > > > > Quuxplusone wrote:
> > > > > > Why so complicated? Is there a unit test that demonstrates why you 
> > > > > > can't just use `return _Tp{1} << __n;` in this case as well?
> > > > > > 
> > > > > > Also, is this a kosher use of `sizeof(X) * 8` as a stand-in for 
> > > > > > `numeric_limits::digits`?
> > > > > > 
> > > > > > Also, speaking of unit tests, I don't see any unit tests for e.g. 
> > > > > > `std::ceil2(256)` or `std::ceil2(65536)`. Shouldn't there be some?
> > > > > Yes. I want to generate some UB here, so that this is not a "core 
> > > > > constant expression" as per P1355.
> > > > Yes, the `ceil2.fail.cpp` test will not fail (for short types) if I 
> > > > just return `_Tp{1} << __n;` - because of integer promotion.
> > > > 
> > > Yikes. Sounds like there's some "library maintainer"ship going on here, 
> > > then. Naively, I would have thought that the Working Draft had left the 
> > > behavior of such constructs undefined in order to make the library 
> > > vendor's life **easier** and the code **more efficient**. But you're 
> > > saying that you need to pessimize the code here in order to make it 
> > > "sufficiently undefined" so that its behavior at compile time will be 
> > > well-defined and produce a diagnostic instead of being undefined and 
> > > producing garbage?
> > > 
> > > Maybe WG21 needs to invent a "really actually undefined behavior" that 
> > > does not have unwanted interactions with constexpr, so that library 
> > > writers can go back to generating fast clean code!
> > > 
> > > Rant aside, why don't you just do `_LIBCPP_ASSERT(__n < 
> > > numeric_limits<_Tp>::digits);` and leave it at that?  An assertion 
> > > failure isn't a compile-time constant, is it?
> > > Also, is this a kosher use of sizeof(X) * 8 as a stand-in for 
> > > numeric_limits::digits?
> > 
> > Good catch.
> that's exactly what P1355 says.
There are three things that I'd like this code to do in the case of bad inputs:
* Produce a diagnostic if called at constexpr time (required by P1355)
* Cause UBSAN to catch it at runtime
* Cause a libc++ assertion to go off if they are enabled.

Note that these are all more or less independent.


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

https://reviews.llvm.org/D51262



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


[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists marked an inline comment as done.
mclow.lists added inline comments.



Comment at: libcxx/include/bit:378
+   const unsigned __retVal = 1u << (__n + __extra);
+   return (_Tp) (__retVal >> __extra);
+}

mclow.lists wrote:
> Quuxplusone wrote:
> > mclow.lists wrote:
> > > mclow.lists wrote:
> > > > Quuxplusone wrote:
> > > > > Why so complicated? Is there a unit test that demonstrates why you 
> > > > > can't just use `return _Tp{1} << __n;` in this case as well?
> > > > > 
> > > > > Also, is this a kosher use of `sizeof(X) * 8` as a stand-in for 
> > > > > `numeric_limits::digits`?
> > > > > 
> > > > > Also, speaking of unit tests, I don't see any unit tests for e.g. 
> > > > > `std::ceil2(256)` or `std::ceil2(65536)`. Shouldn't there be some?
> > > > Yes. I want to generate some UB here, so that this is not a "core 
> > > > constant expression" as per P1355.
> > > Yes, the `ceil2.fail.cpp` test will not fail (for short types) if I just 
> > > return `_Tp{1} << __n;` - because of integer promotion.
> > > 
> > Yikes. Sounds like there's some "library maintainer"ship going on here, 
> > then. Naively, I would have thought that the Working Draft had left the 
> > behavior of such constructs undefined in order to make the library vendor's 
> > life **easier** and the code **more efficient**. But you're saying that you 
> > need to pessimize the code here in order to make it "sufficiently 
> > undefined" so that its behavior at compile time will be well-defined and 
> > produce a diagnostic instead of being undefined and producing garbage?
> > 
> > Maybe WG21 needs to invent a "really actually undefined behavior" that does 
> > not have unwanted interactions with constexpr, so that library writers can 
> > go back to generating fast clean code!
> > 
> > Rant aside, why don't you just do `_LIBCPP_ASSERT(__n < 
> > numeric_limits<_Tp>::digits);` and leave it at that?  An assertion failure 
> > isn't a compile-time constant, is it?
> > Also, is this a kosher use of sizeof(X) * 8 as a stand-in for 
> > numeric_limits::digits?
> 
> Good catch.
that's exactly what P1355 says.


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

https://reviews.llvm.org/D51262



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


[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists marked 4 inline comments as done.
mclow.lists added inline comments.



Comment at: libcxx/include/bit:252
+while (true) {
+__t = rotr<_Tp>(__t, __ulldigits);
+if ((__iter = countl_zero(static_cast(__t))) 
!= __ulldigits)

Quuxplusone wrote:
> Since `__t` is already of type `_Tp`, the explicit template argument `<_Tp>` 
> is unnecessary here.
> Also, is the ADL here intentional?
Right about the `<_Tp>`



Comment at: libcxx/include/bit:253
+__t = rotr<_Tp>(__t, __ulldigits);
+if ((__iter = countl_zero(static_cast(__t))) 
!= __ulldigits)
+break;

Quuxplusone wrote:
> I forget the rules of name hiding; is this `countl_zero` also an ADL call? 
> (My experimentation implies it's not? but it would still be clearer to use 
> `_VSTD::countl_zero` if that's what you mean.)
> 
> As a general rule, I strongly recommend writing side-effects //outside// of 
> `if` conditions; like, on the previous line or something; unless writing it 
> all on a single line has some concrete benefit.
Not an ADL call, because `_Tp` is always a built-in type.



Comment at: libcxx/include/bit:365
+if (__t < 2) return 1;
+const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 
1u));
+

Quuxplusone wrote:
> Incidentally, why `(_Tp)(__t - 1u)` instead of the formula `__t - _Tp{1}` 
> used elsewhere in this header?
Because I want to end up with a value of type `_Tp`, and (for short types), 
`__t - _Tp{1}` doesn't get me that. (Integer promotion).  `((char) 23) - 
((char) 1)` is not type `char`



Comment at: libcxx/include/bit:378
+   const unsigned __retVal = 1u << (__n + __extra);
+   return (_Tp) (__retVal >> __extra);
+}

Quuxplusone wrote:
> mclow.lists wrote:
> > mclow.lists wrote:
> > > Quuxplusone wrote:
> > > > Why so complicated? Is there a unit test that demonstrates why you 
> > > > can't just use `return _Tp{1} << __n;` in this case as well?
> > > > 
> > > > Also, is this a kosher use of `sizeof(X) * 8` as a stand-in for 
> > > > `numeric_limits::digits`?
> > > > 
> > > > Also, speaking of unit tests, I don't see any unit tests for e.g. 
> > > > `std::ceil2(256)` or `std::ceil2(65536)`. Shouldn't there be some?
> > > Yes. I want to generate some UB here, so that this is not a "core 
> > > constant expression" as per P1355.
> > Yes, the `ceil2.fail.cpp` test will not fail (for short types) if I just 
> > return `_Tp{1} << __n;` - because of integer promotion.
> > 
> Yikes. Sounds like there's some "library maintainer"ship going on here, then. 
> Naively, I would have thought that the Working Draft had left the behavior of 
> such constructs undefined in order to make the library vendor's life 
> **easier** and the code **more efficient**. But you're saying that you need 
> to pessimize the code here in order to make it "sufficiently undefined" so 
> that its behavior at compile time will be well-defined and produce a 
> diagnostic instead of being undefined and producing garbage?
> 
> Maybe WG21 needs to invent a "really actually undefined behavior" that does 
> not have unwanted interactions with constexpr, so that library writers can go 
> back to generating fast clean code!
> 
> Rant aside, why don't you just do `_LIBCPP_ASSERT(__n < 
> numeric_limits<_Tp>::digits);` and leave it at that?  An assertion failure 
> isn't a compile-time constant, is it?
> Also, is this a kosher use of sizeof(X) * 8 as a stand-in for 
> numeric_limits::digits?

Good catch.


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

https://reviews.llvm.org/D51262



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


[PATCH] D63726: [analyzer] print() JSONify: Create pointers

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364271: [analyzer] print() JSONify: Create pointers 
(authored by Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63726?vs=206249=206359#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63726

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
  cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot
  cfe/trunk/test/Analysis/expr-inspection.c
  cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Index: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
@@ -204,13 +204,13 @@
 const LocationContext *LCtx, const char *NL,
 unsigned int Space, bool IsDot) const {
   Indent(Out, Space, IsDot) << "\"environment\": ";
-  ++Space;
 
   if (ExprBindings.isEmpty()) {
 Out << "null," << NL;
 return;
   }
 
+  ++Space;
   if (!LCtx) {
 // Find the freshest location context.
 llvm::SmallPtrSet FoundContexts;
@@ -227,7 +227,8 @@
 
   assert(LCtx);
 
-  Out << '[' << NL; // Start of Environment.
+  Out << "{ \"pointer\": \"" << (const void *)LCtx->getStackFrame()
+  << "\", \"items\": [" << NL;
   PrintingPolicy PP = Ctx.getPrintingPolicy();
 
   LCtx->printJson(Out, NL, Space, IsDot, [&](const LocationContext *LC) {
@@ -280,5 +281,5 @@
   Out << "null ";
   });
 
-  Indent(Out, --Space, IsDot) << "]," << NL; // End of Environment.
+  Indent(Out, --Space, IsDot) << "]}," << NL;
 }
Index: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2640,7 +2640,7 @@
 return;
   }
 
-  Out << '[' << NL;
-  Bindings.printJson(Out, NL, ++Space, IsDot);
-  Indent(Out, --Space, IsDot) << "]," << NL;
+  Out << "{ \"pointer\": \"" << Bindings.asStore() << "\", \"items\": [" << NL;
+  Bindings.printJson(Out, NL, Space + 1, IsDot);
+  Indent(Out, Space, IsDot) << "]}," << NL;
 }
Index: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
===
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
@@ -126,7 +126,8 @@
 class Environment(object):
 def __init__(self, json_e):
 super(Environment, self).__init__()
-self.frames = [EnvironmentFrame(f) for f in json_e]
+self.ptr = json_e['pointer']
+self.frames = [EnvironmentFrame(f) for f in json_e['items']]
 
 def diff_frames(self, prev):
 # TODO: It's difficult to display a good diff when frame numbers shift.
@@ -190,8 +191,9 @@
 class Store(object):
 def __init__(self, json_s):
 super(Store, self).__init__()
+self.ptr = json_s['pointer']
 self.clusters = collections.OrderedDict(
-[(c['pointer'], StoreCluster(c)) for c in json_s])
+[(c['pointer'], StoreCluster(c)) for c in json_s['items']])
 
 def diff_clusters(self, prev):
 removed = [k for k in prev.clusters if k not in self.clusters]
Index: cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
===
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
@@ -29,19 +29,22 @@
   "program_state": {
 "environment": null,
 "constraints": null,
-"store": [
-  {
-"cluster": "x",
-"pointer": "0x3",
-"items": [
-  {
-"kind": "Default",
-"offset": 0,
-"value": "Undefined"
-  }
-]
-  }
-]
+"store": {
+  "pointer": "0x2",
+  "items": [
+{
+  "cluster": "x",
+  "pointer": "0x3",
+  "items": [
+{
+  "kind": "Default",
+  "offset": 0,
+  "value": "Undefined"
+}
+  ]
+}
+  ]
+}
   }
 }
 \l}"];
Index: cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
===
--- 

r364271 - [analyzer] print() JSONify: Create pointers

2019-06-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Mon Jun 24 20:17:55 2019
New Revision: 364271

URL: http://llvm.org/viewvc/llvm-project?rev=364271=rev
Log:
[analyzer] print() JSONify: Create pointers

Summary: -

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot
cfe/trunk/test/Analysis/expr-inspection.c
cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp?rev=364271=364270=364271=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp Mon Jun 24 20:17:55 2019
@@ -204,13 +204,13 @@ void Environment::printJson(raw_ostream
 const LocationContext *LCtx, const char *NL,
 unsigned int Space, bool IsDot) const {
   Indent(Out, Space, IsDot) << "\"environment\": ";
-  ++Space;
 
   if (ExprBindings.isEmpty()) {
 Out << "null," << NL;
 return;
   }
 
+  ++Space;
   if (!LCtx) {
 // Find the freshest location context.
 llvm::SmallPtrSet FoundContexts;
@@ -227,7 +227,8 @@ void Environment::printJson(raw_ostream
 
   assert(LCtx);
 
-  Out << '[' << NL; // Start of Environment.
+  Out << "{ \"pointer\": \"" << (const void *)LCtx->getStackFrame()
+  << "\", \"items\": [" << NL;
   PrintingPolicy PP = Ctx.getPrintingPolicy();
 
   LCtx->printJson(Out, NL, Space, IsDot, [&](const LocationContext *LC) {
@@ -280,5 +281,5 @@ void Environment::printJson(raw_ostream
   Out << "null ";
   });
 
-  Indent(Out, --Space, IsDot) << "]," << NL; // End of Environment.
+  Indent(Out, --Space, IsDot) << "]}," << NL;
 }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=364271=364270=364271=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Mon Jun 24 20:17:55 2019
@@ -2640,7 +2640,7 @@ void RegionStoreManager::printJson(raw_o
 return;
   }
 
-  Out << '[' << NL;
-  Bindings.printJson(Out, NL, ++Space, IsDot);
-  Indent(Out, --Space, IsDot) << "]," << NL;
+  Out << "{ \"pointer\": \"" << Bindings.asStore() << "\", \"items\": [" << NL;
+  Bindings.printJson(Out, NL, Space + 1, IsDot);
+  Indent(Out, Space, IsDot) << "]}," << NL;
 }

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot?rev=364271=364270=364271=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot Mon Jun 24 
20:17:55 2019
@@ -34,21 +34,24 @@ Node0x1 [shape=record,label=
   "program_state": {
 "store": null,
 "constraints": null,
-"environment": [
-  {
-"location_context": "#0 Call",
-"lctx_id": 3,
-"calling": "foo",
-"call_line": 4,
-"items": [
-  {
-"stmt_id": 5,
-"pretty": "bar()",
-"value": "Unknown"
-  }
-]
-  }
-]
+"environment": {
+  "pointer": "0x2",
+  "items": [
+{
+  "location_context": "#0 Call",
+  "lctx_id": 3,
+  "calling": "foo",
+  "call_line": 4,
+  "items": [
+{
+  "stmt_id": 5,
+  "pretty": "bar()",
+  "value": "Unknown"
+}
+  ]
+}
+  ]
+}
   }
 }
 \l}"];

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot?rev=364271=364270=364271=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot 
(original)
+++ 

[PATCH] D63462: [analyzer] JsonSupport: Escape escapes

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 206357.
Charusso added a comment.

- A working one.


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

https://reviews.llvm.org/D63462

Files:
  clang/include/clang/Basic/JsonSupport.h
  clang/test/Analysis/dump_egraph.c
  clang/test/Analysis/exploded-graph-rewriter/escapes.c


Index: clang/test/Analysis/exploded-graph-rewriter/escapes.c
===
--- clang/test/Analysis/exploded-graph-rewriter/escapes.c
+++ clang/test/Analysis/exploded-graph-rewriter/escapes.c
@@ -15,7 +15,7 @@
   // CHECK: Environment: 
   // CHECK-SAME: "foo"
   // CHECK-SAME: Element\{"foo",0 S64b,char\}
-  const char *const foo = "foo";
+  const char *const foo = "\x66\x6f\x6f";
 
   // CHECK: BinaryOperator
   // CHECK-SAME: 1 \| 2
Index: clang/test/Analysis/dump_egraph.c
===
--- clang/test/Analysis/dump_egraph.c
+++ clang/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 
Index: clang/include/clang/Basic/JsonSupport.h
===
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
   ++Pos; // As we insert the escape-character move plus one.
 }


Index: clang/test/Analysis/exploded-graph-rewriter/escapes.c
===
--- clang/test/Analysis/exploded-graph-rewriter/escapes.c
+++ clang/test/Analysis/exploded-graph-rewriter/escapes.c
@@ -15,7 +15,7 @@
   // CHECK: Environment: 
   // CHECK-SAME: "foo"
   // CHECK-SAME: Element\{"foo",0 S64b,char\}
-  const char *const foo = "foo";
+  const char *const foo = "\x66\x6f\x6f";
 
   // CHECK: BinaryOperator
   // CHECK-SAME: 1 \| 2
Index: clang/test/Analysis/dump_egraph.c
===
--- clang/test/Analysis/dump_egraph.c
+++ clang/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 
Index: clang/include/clang/Basic/JsonSupport.h
===
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
 

[PATCH] D63462: [analyzer] JsonSupport: Escape escapes

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364270: [analyzer] JsonSupport: Escape escapes (authored by 
Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63462?vs=206357=206358#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63462

Files:
  cfe/trunk/include/clang/Basic/JsonSupport.h
  cfe/trunk/test/Analysis/dump_egraph.c
  cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c


Index: cfe/trunk/include/clang/Basic/JsonSupport.h
===
--- cfe/trunk/include/clang/Basic/JsonSupport.h
+++ cfe/trunk/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
   ++Pos; // As we insert the escape-character move plus one.
 }
Index: cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
===
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
@@ -15,7 +15,7 @@
   // CHECK: Environment: 
   // CHECK-SAME: "foo"
   // CHECK-SAME: Element\{"foo",0 S64b,char\}
-  const char *const foo = "foo";
+  const char *const foo = "\x66\x6f\x6f";
 
   // CHECK: BinaryOperator
   // CHECK-SAME: 1 \| 2
Index: cfe/trunk/test/Analysis/dump_egraph.c
===
--- cfe/trunk/test/Analysis/dump_egraph.c
+++ cfe/trunk/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 


Index: cfe/trunk/include/clang/Basic/JsonSupport.h
===
--- cfe/trunk/include/clang/Basic/JsonSupport.h
+++ cfe/trunk/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
   ++Pos; // As we insert the escape-character move plus one.
 }
Index: cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
===
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
@@ -15,7 +15,7 @@
   // CHECK: Environment: 
   // CHECK-SAME: "foo"
   // CHECK-SAME: Element\{"foo",0 S64b,char\}
-  const char *const foo = "foo";
+  const char *const foo = "\x66\x6f\x6f";
 
   // CHECK: BinaryOperator
   // CHECK-SAME: 1 \| 2
Index: cfe/trunk/test/Analysis/dump_egraph.c
===
--- cfe/trunk/test/Analysis/dump_egraph.c
+++ cfe/trunk/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 

r364270 - [analyzer] JsonSupport: Escape escapes

2019-06-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Mon Jun 24 20:08:32 2019
New Revision: 364270

URL: http://llvm.org/viewvc/llvm-project?rev=364270=rev
Log:
[analyzer] JsonSupport: Escape escapes

Summary: -

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Basic/JsonSupport.h
cfe/trunk/test/Analysis/dump_egraph.c
cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c

Modified: cfe/trunk/include/clang/Basic/JsonSupport.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/JsonSupport.h?rev=364270=364269=364270=diff
==
--- cfe/trunk/include/clang/Basic/JsonSupport.h (original)
+++ cfe/trunk/include/clang/Basic/JsonSupport.h Mon Jun 24 20:08:32 2019
@@ -31,7 +31,26 @@ inline std::string JsonFormat(StringRef
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@ inline std::string JsonFormat(StringRef
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
   ++Pos; // As we insert the escape-character move plus one.
 }

Modified: cfe/trunk/test/Analysis/dump_egraph.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.c?rev=364270=364269=364270=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.c (original)
+++ cfe/trunk/test/Analysis/dump_egraph.c Mon Jun 24 20:08:32 2019
@@ -13,6 +13,8 @@ int getJ();
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@ int foo() {
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c?rev=364270=364269=364270=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c Mon Jun 24 
20:08:32 2019
@@ -15,7 +15,7 @@ void escapes() {
   // CHECK: Environment: 
   // CHECK-SAME: "foo"
   // CHECK-SAME: Element\{"foo",0 S64b,char\}
-  const char *const foo = "foo";
+  const char *const foo = "\x66\x6f\x6f";
 
   // CHECK: BinaryOperator
   // CHECK-SAME: 1 \| 2


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


[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: libcxx/include/bit:378
+   const unsigned __retVal = 1u << (__n + __extra);
+   return (_Tp) (__retVal >> __extra);
+}

mclow.lists wrote:
> mclow.lists wrote:
> > Quuxplusone wrote:
> > > Why so complicated? Is there a unit test that demonstrates why you can't 
> > > just use `return _Tp{1} << __n;` in this case as well?
> > > 
> > > Also, is this a kosher use of `sizeof(X) * 8` as a stand-in for 
> > > `numeric_limits::digits`?
> > > 
> > > Also, speaking of unit tests, I don't see any unit tests for e.g. 
> > > `std::ceil2(256)` or `std::ceil2(65536)`. Shouldn't there be some?
> > Yes. I want to generate some UB here, so that this is not a "core constant 
> > expression" as per P1355.
> Yes, the `ceil2.fail.cpp` test will not fail (for short types) if I just 
> return `_Tp{1} << __n;` - because of integer promotion.
> 
Yikes. Sounds like there's some "library maintainer"ship going on here, then. 
Naively, I would have thought that the Working Draft had left the behavior of 
such constructs undefined in order to make the library vendor's life **easier** 
and the code **more efficient**. But you're saying that you need to pessimize 
the code here in order to make it "sufficiently undefined" so that its behavior 
at compile time will be well-defined and produce a diagnostic instead of being 
undefined and producing garbage?

Maybe WG21 needs to invent a "really actually undefined behavior" that does not 
have unwanted interactions with constexpr, so that library writers can go back 
to generating fast clean code!

Rant aside, why don't you just do `_LIBCPP_ASSERT(__n < 
numeric_limits<_Tp>::digits);` and leave it at that?  An assertion failure 
isn't a compile-time constant, is it?


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

https://reviews.llvm.org/D51262



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


[PATCH] D63462: [analyzer] JsonSupport: Escape escapes

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 206356.
Charusso added a comment.

- More test.


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

https://reviews.llvm.org/D63462

Files:
  clang/include/clang/Basic/JsonSupport.h
  clang/test/Analysis/dump_egraph.c
  clang/test/Analysis/exploded-graph-rewriter/escapes.c


Index: clang/test/Analysis/exploded-graph-rewriter/escapes.c
===
--- clang/test/Analysis/exploded-graph-rewriter/escapes.c
+++ clang/test/Analysis/exploded-graph-rewriter/escapes.c
@@ -11,9 +11,9 @@
 void string_region_escapes() {
   // CHECK: Store: 
   // CHECK-SAME: foo0
-  // CHECK-SAME: Element\{"foo",0 S64b,char\}
+  // CHECK-SAME: Element\{"B",0 S64b,char\}
   // CHECK: Environment: 
-  // CHECK-SAME: "foo"
-  // CHECK-SAME: Element\{"foo",0 S64b,char\}
-  const char *const foo = "foo";
+  // CHECK-SAME: "B"
+  // CHECK-SAME: Element\{"B",0 S64b,char\}
+  const char *const foo = "\x42";
 }
Index: clang/test/Analysis/dump_egraph.c
===
--- clang/test/Analysis/dump_egraph.c
+++ clang/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 
Index: clang/include/clang/Basic/JsonSupport.h
===
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
   ++Pos; // As we insert the escape-character move plus one.
 }


Index: clang/test/Analysis/exploded-graph-rewriter/escapes.c
===
--- clang/test/Analysis/exploded-graph-rewriter/escapes.c
+++ clang/test/Analysis/exploded-graph-rewriter/escapes.c
@@ -11,9 +11,9 @@
 void string_region_escapes() {
   // CHECK: Store: 
   // CHECK-SAME: foo0
-  // CHECK-SAME: Element\{"foo",0 S64b,char\}
+  // CHECK-SAME: Element\{"B",0 S64b,char\}
   // CHECK: Environment: 
-  // CHECK-SAME: "foo"
-  // CHECK-SAME: Element\{"foo",0 S64b,char\}
-  const char *const foo = "foo";
+  // CHECK-SAME: "B"
+  // CHECK-SAME: Element\{"B",0 S64b,char\}
+  const char *const foo = "\x42";
 }
Index: clang/test/Analysis/dump_egraph.c
===
--- clang/test/Analysis/dump_egraph.c
+++ clang/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 
Index: clang/include/clang/Basic/JsonSupport.h
===
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)

[PATCH] D63462: [analyzer] JsonSupport: Escape escapes

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D63462#1556831 , @NoQ wrote:

> See also https://xkcd.com/1638/


Well, after a month of escaping we are still have problems, so it is truly 
comes to your brain.


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

https://reviews.llvm.org/D63462



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


[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists marked an inline comment as done.
mclow.lists added inline comments.



Comment at: libcxx/include/bit:378
+   const unsigned __retVal = 1u << (__n + __extra);
+   return (_Tp) (__retVal >> __extra);
+}

mclow.lists wrote:
> Quuxplusone wrote:
> > Why so complicated? Is there a unit test that demonstrates why you can't 
> > just use `return _Tp{1} << __n;` in this case as well?
> > 
> > Also, is this a kosher use of `sizeof(X) * 8` as a stand-in for 
> > `numeric_limits::digits`?
> > 
> > Also, speaking of unit tests, I don't see any unit tests for e.g. 
> > `std::ceil2(256)` or `std::ceil2(65536)`. Shouldn't there be some?
> Yes. I want to generate some UB here, so that this is not a "core constant 
> expression" as per P1355.
Yes, the `ceil2.fail.cpp` test will not fail (for short types) if I just return 
`_Tp{1} << __n;` - because of integer promotion.



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

https://reviews.llvm.org/D51262



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


[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists marked 2 inline comments as done.
mclow.lists added inline comments.



Comment at: libcxx/include/bit:199
+!is_same_v, char32_t>
+ > {};
+

Quuxplusone wrote:
> Given how heavily the code controlled by this trait depends on 
> `numeric_limits<_Tp>`, would it make sense to add something in here about how 
> that specialization should exist?
> 
> I agree with @EricWF's earlier comment: I can't think of any types that would 
> satisfy `(!is_integral_v<_Tp>) && is_unsigned_v<_Tp>`.  (But just TIL that 
> the signedness of `wchar_t` is implementation-defined.)
 `is_unsigned_v` could be true, but `is_integral_v` is not ever 
true.



Comment at: libcxx/include/bit:211
+? __t
+: (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig)));
+}

Quuxplusone wrote:
> No sane compiler would actually generate three `mod` operations for the three 
> instances of repeated subexpression `__cnt % __dig`, would they?
At `-O0`? Sure it would.


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

https://reviews.llvm.org/D51262



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


[PATCH] D63727: [analyzer] print() JSONify: Stable LocationContext IDs

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso abandoned this revision.
Charusso added a comment.

In D63727#1556821 , @NoQ wrote:

> I think i'd rather remove it entirely.


I have seen a TODO in the differentiation of such indices, just why I made it. 
Okai.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63727



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


[PATCH] D63462: [analyzer] JsonSupport: Escape escapes

2019-06-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

See also https://xkcd.com/1638/


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

https://reviews.llvm.org/D63462



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


[PATCH] D63726: [analyzer] print() JSONify: Create pointers

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D63726#1556825 , @NoQ wrote:

> Yay thx!
>
> For Environment they aren't that useful, but it definitely doesn't hurt.


It is pretty interesting when you could track the call among the entire graph, 
it is could be our first `Explorer`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63726



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


[PATCH] D63462: [analyzer] JsonSupport: Escape escapes

2019-06-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Thx!

I guess it makes sense to add a test into 
`test/Analysis/exploded-graph-rewriter/escapes.c` as well, so that to learn if 
we can actually parse it later.


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

https://reviews.llvm.org/D63462



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


[PATCH] D63727: [analyzer] print() JSONify: Stable LocationContext IDs

2019-06-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I think i'd rather remove it entirely.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63727



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


[PATCH] D63726: [analyzer] print() JSONify: Create pointers

2019-06-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Yay thx!

For Environment they aren't that useful, but it definitely doesn't hurt.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63726



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


[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists marked an inline comment as done.
mclow.lists added inline comments.



Comment at: libcxx/include/bit:378
+   const unsigned __retVal = 1u << (__n + __extra);
+   return (_Tp) (__retVal >> __extra);
+}

Quuxplusone wrote:
> Why so complicated? Is there a unit test that demonstrates why you can't just 
> use `return _Tp{1} << __n;` in this case as well?
> 
> Also, is this a kosher use of `sizeof(X) * 8` as a stand-in for 
> `numeric_limits::digits`?
> 
> Also, speaking of unit tests, I don't see any unit tests for e.g. 
> `std::ceil2(256)` or `std::ceil2(65536)`. Shouldn't there be some?
Yes. I want to generate some UB here, so that this is not a "core constant 
expression" as per P1355.


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

https://reviews.llvm.org/D51262



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


[PATCH] D63727: [analyzer] print() JSONify: Stable LocationContext IDs

2019-06-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In normal dumps i'd rather have it the old way because it's similar to how 
stack frames are displayed in the debugger.

And in exploded graph rewriter we can always reverse our lists if we want; this 
number isn't really telling us much.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63727



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


[PATCH] D63227: [analyzer] Better timers.

2019-06-24 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364266: [analyzer] Add more timers for performance 
profiling. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63227?vs=204353=206352#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63227

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -225,10 +225,6 @@
   }
 }
 
-ExprEngine::~ExprEngine() {
-  BR.FlushReports();
-}
-
 //===--===//
 // Utility methods.
 //===--===//
Index: cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -196,7 +196,9 @@
 
   /// Time the analyzes time of each translation unit.
   std::unique_ptr AnalyzerTimers;
-  std::unique_ptr TUTotalTimer;
+  std::unique_ptr SyntaxCheckTimer;
+  std::unique_ptr ExprEngineTimer;
+  std::unique_ptr BugReporterTimer;
 
   /// The information about analyzed functions shared throughout the
   /// translation unit.
@@ -212,8 +214,13 @@
 if (Opts->PrintStats || Opts->ShouldSerializeStats) {
   AnalyzerTimers = llvm::make_unique(
   "analyzer", "Analyzer timers");
-  TUTotalTimer = llvm::make_unique(
-  "time", "Analyzer total time", *AnalyzerTimers);
+  SyntaxCheckTimer = llvm::make_unique(
+  "syntaxchecks", "Syntax-based analysis time", *AnalyzerTimers);
+  ExprEngineTimer = llvm::make_unique(
+  "exprengine", "Path exploration time", *AnalyzerTimers);
+  BugReporterTimer = llvm::make_unique(
+  "bugreporter", "Path-sensitive report post-processing time",
+  *AnalyzerTimers);
   llvm::EnableStatistics(/* PrintOnExit= */ false);
 }
   }
@@ -346,8 +353,13 @@
   /// Handle callbacks for arbitrary Decls.
   bool VisitDecl(Decl *D) {
 AnalysisMode Mode = getModeForDecl(D, RecVisitorMode);
-if (Mode & AM_Syntax)
+if (Mode & AM_Syntax) {
+  if (SyntaxCheckTimer)
+SyntaxCheckTimer->startTimer();
   checkerMgr->runCheckersOnASTDecl(D, *Mgr, *RecVisitorBR);
+  if (SyntaxCheckTimer)
+SyntaxCheckTimer->stopTimer();
+}
 return true;
   }
 
@@ -566,7 +578,11 @@
 void AnalysisConsumer::runAnalysisOnTranslationUnit(ASTContext ) {
   BugReporter BR(*Mgr);
   TranslationUnitDecl *TU = C.getTranslationUnitDecl();
+  if (SyntaxCheckTimer)
+SyntaxCheckTimer->startTimer();
   checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
+  if (SyntaxCheckTimer)
+SyntaxCheckTimer->stopTimer();
 
   // Run the AST-only checks using the order in which functions are defined.
   // If inlining is not turned on, use the simplest function order for path
@@ -608,8 +624,6 @@
   if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred())
 return;
 
-  if (TUTotalTimer) TUTotalTimer->startTimer();
-
   if (isBisonFile(C)) {
 reportAnalyzerProgress("Skipping bison-generated file\n");
   } else if (Opts->DisableAllChecks) {
@@ -622,8 +636,6 @@
 runAnalysisOnTranslationUnit(C);
   }
 
-  if (TUTotalTimer) TUTotalTimer->stopTimer();
-
   // Count how many basic blocks we have not covered.
   NumBlocksInAnalyzedFunctions = FunctionSummaries.getTotalNumBasicBlocks();
   NumVisitedBlocksInAnalyzedFunctions =
@@ -747,8 +759,13 @@
 
   BugReporter BR(*Mgr);
 
-  if (Mode & AM_Syntax)
+  if (Mode & AM_Syntax) {
+if (SyntaxCheckTimer)
+  SyntaxCheckTimer->startTimer();
 checkerMgr->runCheckersOnASTBody(D, *Mgr, BR);
+if (SyntaxCheckTimer)
+  SyntaxCheckTimer->stopTimer();
+  }
   if ((Mode & AM_Path) && checkerMgr->hasPathSensitiveCheckers()) {
 RunPathSensitiveChecks(D, IMode, VisitedCallees);
 if (IMode != ExprEngine::Inline_Minimal)
@@ -775,8 +792,12 @@
   ExprEngine Eng(CTU, *Mgr, VisitedCallees, , IMode);
 
   // Execute the worklist algorithm.
+  if (ExprEngineTimer)
+ExprEngineTimer->startTimer();
   Eng.ExecuteWorkList(Mgr->getAnalysisDeclContextManager().getStackFrame(D),
   Mgr->options.MaxNodesPerTopLevelFunction);
+  if (ExprEngineTimer)
+ExprEngineTimer->stopTimer();
 
   if (!Mgr->options.DumpExplodedGraphTo.empty())
 Eng.DumpGraph(Mgr->options.TrimGraph, Mgr->options.DumpExplodedGraphTo);
@@ -786,7 +807,11 

[PATCH] D63685: [analyzer] exploded-graph-rewriter: Add support for range constraints.

2019-06-24 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364268: [analyzer] exploded-graph-rewriter: Add support for 
range constraints. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63685?vs=206115=206354#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63685

Files:
  cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot
  cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Index: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
===
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
@@ -25,6 +25,19 @@
 return (removed, added)
 
 
+# Represents any program state trait that is a dictionary of key-value pairs.
+class GenericMap(object):
+def __init__(self, generic_map):
+self.generic_map = generic_map
+
+def diff(self, prev):
+return diff_dicts(self.generic_map, prev.generic_map)
+
+def is_different(self, prev):
+removed, added = self.diff(prev)
+return len(removed) != 0 or len(added) != 0
+
+
 # A deserialized source location.
 class SourceLocation(object):
 def __init__(self, json_loc):
@@ -203,8 +216,10 @@
 if json_ps['store'] is not None else None
 self.environment = Environment(json_ps['environment']) \
 if json_ps['environment'] is not None else None
+self.constraints = GenericMap(collections.OrderedDict([
+(c['symbol'], c['range']) for c in json_ps['constraints']
+])) if json_ps['constraints'] is not None else None
 # TODO: Objects under construction.
-# TODO: Constraint ranges.
 # TODO: Dynamic types of objects.
 # TODO: Checker messages.
 
@@ -479,11 +494,57 @@
 else:
 self._dump('')
 self.visit_store(s.store)
-self._dump('')
+self._dump('')
+
+def visit_generic_map(self, m, prev_m=None):
+self._dump('')
+
+def dump_pair(m, k, is_added=None):
+self._dump('%s'
+   '%s'
+   '%s'
+   % (self._diff_plus_minus(is_added),
+  k, m.generic_map[k]))
+
+if prev_m is not None:
+removed, added = m.diff(prev_m)
+for k in removed:
+dump_pair(prev_m, k, False)
+for k in added:
+dump_pair(m, k, True)
+else:
+for k in m.generic_map:
+dump_pair(m, k, None)
+
+self._dump('')
+
+def visit_generic_map_in_state(self, selector, s, prev_s=None):
+self._dump(''
+   'Ranges: ')
+m = getattr(s, selector)
+if m is None:
+self._dump(' Nothing!')
+else:
+prev_m = None
+if prev_s is not None:
+prev_m = getattr(prev_s, selector)
+if prev_m is not None:
+if m.is_different(prev_m):
+self._dump('')
+self.visit_generic_map(m, prev_m)
+else:
+self._dump(' No changes!')
+if prev_m is None:
+self._dump('')
+self.visit_generic_map(m)
+self._dump('')
 
 def visit_state(self, s, prev_s):
 self.visit_store_in_state(s, prev_s)
+self._dump('')
 self.visit_environment_in_state(s, prev_s)
+self._dump('')
+self.visit_generic_map_in_state('constraints', s, prev_s)
 
 def visit_node(self, node):
 self._dump('%s [shape=record,label=<'
Index: cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot
===
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot
@@ -0,0 +1,27 @@
+// RUN: %exploded_graph_rewriter %s | FileCheck %s
+
+// FIXME: Substitution doesn't seem to work on Windows.
+// UNSUPPORTED: system-windows
+
+// CHECK: Ranges: 
+// CHECK-SAME: 
+// CHECK-SAME:   
+// CHECK-SAME: reg_$0
+// CHECK-SAME: \{ [0, 0] \}
+// CHECK-SAME:   
+// CHECK-SAME: 
+Node0x1 [shape=record,label=
+ "{
+{ "node_id": 1,
+  "pointer": "0x1",
+  "state_id": 2,
+  "program_points": [],
+  "program_state": {
+"store": null,
+   

[PATCH] D63684: [analyzer] exploded-graph-rewriter: NFC: Extract some code into functions.

2019-06-24 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364267: [analyzer] NFC: exploded-graph-rewriter: Extract 
some code into functions. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63684?vs=206112=206353#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63684

Files:
  cfe/trunk/utils/analyzer/exploded-graph-rewriter.py


Index: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
===
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
@@ -409,6 +409,24 @@
 
 self._dump('')
 
+def visit_environment_in_state(self, s, prev_s=None):
+self._dump(''
+   'Environment: ')
+if s.environment is None:
+self._dump(' Nothing!')
+else:
+if prev_s is not None and prev_s.environment is not None:
+if s.environment.is_different(prev_s.environment):
+self._dump('')
+self.visit_environment(s.environment, prev_s.environment)
+else:
+self._dump(' No changes!')
+else:
+self._dump('')
+self.visit_environment(s.environment)
+
+self._dump('')
+
 def visit_store(self, s, prev_s=None):
 self._dump('')
 
@@ -447,8 +465,7 @@
 
 self._dump('')
 
-def visit_state(self, s, prev_s):
-# == Store ==
+def visit_store_in_state(self, s, prev_s=None):
 self._dump('Store: ')
 if s.store is None:
 self._dump(' Nothing!')
@@ -464,23 +481,9 @@
 self.visit_store(s.store)
 self._dump('')
 
-# == Environment ==
-self._dump(''
-   'Environment: ')
-if s.environment is None:
-self._dump(' Nothing!')
-else:
-if prev_s is not None and prev_s.environment is not None:
-if s.environment.is_different(prev_s.environment):
-self._dump('')
-self.visit_environment(s.environment, prev_s.environment)
-else:
-self._dump(' No changes!')
-else:
-self._dump('')
-self.visit_environment(s.environment)
-
-self._dump('')
+def visit_state(self, s, prev_s):
+self.visit_store_in_state(s, prev_s)
+self.visit_environment_in_state(s, prev_s)
 
 def visit_node(self, node):
 self._dump('%s [shape=record,label=<'


Index: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
===
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
@@ -409,6 +409,24 @@
 
 self._dump('')
 
+def visit_environment_in_state(self, s, prev_s=None):
+self._dump(''
+   'Environment: ')
+if s.environment is None:
+self._dump(' Nothing!')
+else:
+if prev_s is not None and prev_s.environment is not None:
+if s.environment.is_different(prev_s.environment):
+self._dump('')
+self.visit_environment(s.environment, prev_s.environment)
+else:
+self._dump(' No changes!')
+else:
+self._dump('')
+self.visit_environment(s.environment)
+
+self._dump('')
+
 def visit_store(self, s, prev_s=None):
 self._dump('')
 
@@ -447,8 +465,7 @@
 
 self._dump('')
 
-def visit_state(self, s, prev_s):
-# == Store ==
+def visit_store_in_state(self, s, prev_s=None):
 self._dump('Store: ')
 if s.store is None:
 self._dump(' Nothing!')
@@ -464,23 +481,9 @@
 self.visit_store(s.store)
 self._dump('')
 
-# == Environment ==
-self._dump(''
-   'Environment: ')
-if s.environment is None:
-self._dump(' Nothing!')
-else:
-if prev_s is not None and prev_s.environment is not None:
-if s.environment.is_different(prev_s.environment):
-self._dump('')
-self.visit_environment(s.environment, prev_s.environment)
-else:
-self._dump(' No changes!')
-else:
-self._dump('')
-self.visit_environment(s.environment)
-
-self._dump('')
+def visit_state(self, s, prev_s):
+self.visit_store_in_state(s, prev_s)
+self.visit_environment_in_state(s, prev_s)
 
 def visit_node(self, node):
 self._dump('%s 

r364269 - [analyzer] exploded-graph-rewriter: Fix escaping for bitwise-or.

2019-06-24 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Jun 24 19:16:56 2019
New Revision: 364269

URL: http://llvm.org/viewvc/llvm-project?rev=364269=rev
Log:
[analyzer] exploded-graph-rewriter: Fix escaping for bitwise-or.

'|' is a special character in graphviz, so it needs to be properly
escaped and unescaped.

Modified:
cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c?rev=364269=364268=364269=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c Mon Jun 24 
19:16:56 2019
@@ -8,7 +8,7 @@
 // FIXME: Substitution doesn't seem to work on Windows.
 // UNSUPPORTED: system-windows
 
-void string_region_escapes() {
+void escapes() {
   // CHECK: Store: 
   // CHECK-SAME: foo0
   // CHECK-SAME: Element\{"foo",0 S64b,char\}
@@ -16,4 +16,9 @@ void string_region_escapes() {
   // CHECK-SAME: "foo"
   // CHECK-SAME: Element\{"foo",0 S64b,char\}
   const char *const foo = "foo";
+
+  // CHECK: BinaryOperator
+  // CHECK-SAME: 1 \| 2
+  // CHECK-SAME: 3 S32b
+  int x = 1 | 2;
 }

Modified: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/exploded-graph-rewriter.py?rev=364269=364268=364269=diff
==
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py (original)
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py Mon Jun 24 19:16:56 2019
@@ -300,6 +300,7 @@ class ExplodedGraph(object):
 .replace('\\{', '{') \
 .replace('\\}', '}') \
 .replace('', '\\') \
+.replace('\\|', '|') \
 .replace('\\<', '<') \
 .replace('\\>', '>') \
 .rstrip(',')
@@ -329,7 +330,7 @@ class DotDumpVisitor(object):
.replace('\\<', '')
.replace('\\>', '')
.replace('\\l', '')
-   .replace('|', ''), end='')
+   .replace('|', '\\|'), end='')
 
 @staticmethod
 def _diff_plus_minus(is_added):


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


r364266 - [analyzer] Add more timers for performance profiling.

2019-06-24 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Jun 24 19:16:47 2019
New Revision: 364266

URL: http://llvm.org/viewvc/llvm-project?rev=364266=rev
Log:
[analyzer] Add more timers for performance profiling.

The -analyzer-stats flag now allows you to find out how much time was spent
on AST-based analysis and on path-sensitive analysis and, separately,
on bug visitors, as they're occasionally a performance problem on their own.

The total timer wasn't useful because there's anyway a total time printed out.
Remove it.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h?rev=364266=364265=364266=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h Mon 
Jun 24 19:16:47 2019
@@ -161,7 +161,7 @@ public:
  SetOfConstDecls *VisitedCalleesIn,
  FunctionSummariesTy *FS, InliningModes HowToInlineIn);
 
-  ~ExprEngine() override;
+  ~ExprEngine() override = default;
 
   /// Returns true if there is still simulation state on the worklist.
   bool ExecuteWorkList(const LocationContext *L, unsigned Steps = 15) {

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=364266=364265=364266=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Mon Jun 24 19:16:47 2019
@@ -225,10 +225,6 @@ ExprEngine::ExprEngine(cross_tu::CrossTr
   }
 }
 
-ExprEngine::~ExprEngine() {
-  BR.FlushReports();
-}
-
 
//===--===//
 // Utility methods.
 
//===--===//

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp?rev=364266=364265=364266=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp Mon Jun 24 
19:16:47 2019
@@ -196,7 +196,9 @@ public:
 
   /// Time the analyzes time of each translation unit.
   std::unique_ptr AnalyzerTimers;
-  std::unique_ptr TUTotalTimer;
+  std::unique_ptr SyntaxCheckTimer;
+  std::unique_ptr ExprEngineTimer;
+  std::unique_ptr BugReporterTimer;
 
   /// The information about analyzed functions shared throughout the
   /// translation unit.
@@ -212,8 +214,13 @@ public:
 if (Opts->PrintStats || Opts->ShouldSerializeStats) {
   AnalyzerTimers = llvm::make_unique(
   "analyzer", "Analyzer timers");
-  TUTotalTimer = llvm::make_unique(
-  "time", "Analyzer total time", *AnalyzerTimers);
+  SyntaxCheckTimer = llvm::make_unique(
+  "syntaxchecks", "Syntax-based analysis time", *AnalyzerTimers);
+  ExprEngineTimer = llvm::make_unique(
+  "exprengine", "Path exploration time", *AnalyzerTimers);
+  BugReporterTimer = llvm::make_unique(
+  "bugreporter", "Path-sensitive report post-processing time",
+  *AnalyzerTimers);
   llvm::EnableStatistics(/* PrintOnExit= */ false);
 }
   }
@@ -346,8 +353,13 @@ public:
   /// Handle callbacks for arbitrary Decls.
   bool VisitDecl(Decl *D) {
 AnalysisMode Mode = getModeForDecl(D, RecVisitorMode);
-if (Mode & AM_Syntax)
+if (Mode & AM_Syntax) {
+  if (SyntaxCheckTimer)
+SyntaxCheckTimer->startTimer();
   checkerMgr->runCheckersOnASTDecl(D, *Mgr, *RecVisitorBR);
+  if (SyntaxCheckTimer)
+SyntaxCheckTimer->stopTimer();
+}
 return true;
   }
 
@@ -566,7 +578,11 @@ static bool isBisonFile(ASTContext ) {
 void AnalysisConsumer::runAnalysisOnTranslationUnit(ASTContext ) {
   BugReporter BR(*Mgr);
   TranslationUnitDecl *TU = C.getTranslationUnitDecl();
+  if (SyntaxCheckTimer)
+SyntaxCheckTimer->startTimer();
   checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
+  if (SyntaxCheckTimer)
+SyntaxCheckTimer->stopTimer();
 
   // Run the AST-only checks using the order in which functions are defined.
   // If inlining is not turned on, use the simplest function order for path
@@ -608,8 +624,6 @@ void AnalysisConsumer::HandleTranslation
   if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred())
 return;
 
-  

r364267 - [analyzer] NFC: exploded-graph-rewriter: Extract some code into functions.

2019-06-24 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Jun 24 19:16:50 2019
New Revision: 364267

URL: http://llvm.org/viewvc/llvm-project?rev=364267=rev
Log:
[analyzer] NFC: exploded-graph-rewriter: Extract some code into functions.

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

Modified:
cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Modified: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/exploded-graph-rewriter.py?rev=364267=364266=364267=diff
==
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py (original)
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py Mon Jun 24 19:16:50 2019
@@ -409,6 +409,24 @@ class DotDumpVisitor(object):
 
 self._dump('')
 
+def visit_environment_in_state(self, s, prev_s=None):
+self._dump(''
+   'Environment: ')
+if s.environment is None:
+self._dump(' Nothing!')
+else:
+if prev_s is not None and prev_s.environment is not None:
+if s.environment.is_different(prev_s.environment):
+self._dump('')
+self.visit_environment(s.environment, prev_s.environment)
+else:
+self._dump(' No changes!')
+else:
+self._dump('')
+self.visit_environment(s.environment)
+
+self._dump('')
+
 def visit_store(self, s, prev_s=None):
 self._dump('')
 
@@ -447,8 +465,7 @@ class DotDumpVisitor(object):
 
 self._dump('')
 
-def visit_state(self, s, prev_s):
-# == Store ==
+def visit_store_in_state(self, s, prev_s=None):
 self._dump('Store: ')
 if s.store is None:
 self._dump(' Nothing!')
@@ -464,23 +481,9 @@ class DotDumpVisitor(object):
 self.visit_store(s.store)
 self._dump('')
 
-# == Environment ==
-self._dump(''
-   'Environment: ')
-if s.environment is None:
-self._dump(' Nothing!')
-else:
-if prev_s is not None and prev_s.environment is not None:
-if s.environment.is_different(prev_s.environment):
-self._dump('')
-self.visit_environment(s.environment, prev_s.environment)
-else:
-self._dump(' No changes!')
-else:
-self._dump('')
-self.visit_environment(s.environment)
-
-self._dump('')
+def visit_state(self, s, prev_s):
+self.visit_store_in_state(s, prev_s)
+self.visit_environment_in_state(s, prev_s)
 
 def visit_node(self, node):
 self._dump('%s [shape=record,label=<'


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


r364268 - [analyzer] exploded-graph-rewriter: Add support for range constraints.

2019-06-24 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Jun 24 19:16:53 2019
New Revision: 364268

URL: http://llvm.org/viewvc/llvm-project?rev=364268=rev
Log:
[analyzer] exploded-graph-rewriter: Add support for range constraints.

Diff support included.

A cheap solution is implemented that treats range constraints as
"some sort of key-value map", so it's going to be trivial
to add support for other such maps later, such as dynamic type info.

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

Added:
cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot
Modified:
cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot
cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Added: cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot?rev=364268=auto
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot (added)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints.dot Mon Jun 24 
19:16:53 2019
@@ -0,0 +1,27 @@
+// RUN: %exploded_graph_rewriter %s | FileCheck %s
+
+// FIXME: Substitution doesn't seem to work on Windows.
+// UNSUPPORTED: system-windows
+
+// CHECK: Ranges: 
+// CHECK-SAME: 
+// CHECK-SAME:   
+// CHECK-SAME: reg_$0
+// CHECK-SAME: \{ [0, 0] \}
+// CHECK-SAME:   
+// CHECK-SAME: 
+Node0x1 [shape=record,label=
+ "{
+{ "node_id": 1,
+  "pointer": "0x1",
+  "state_id": 2,
+  "program_points": [],
+  "program_state": {
+"store": null,
+"environment": null,
+"constraints": [
+  { "symbol": "reg_$0", "range": "{ [0, 0] }" }
+]
+  }
+}
+\l}"];

Added: cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot?rev=364268=auto
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot (added)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/constraints_diff.dot Mon 
Jun 24 19:16:53 2019
@@ -0,0 +1,65 @@
+// RUN: %exploded_graph_rewriter -d %s | FileCheck %s
+
+// FIXME: Substitution doesn't seem to work on Windows.
+// UNSUPPORTED: system-windows
+
+Node0x1 [shape=record,label=
+ "{
+{ "node_id": 1,
+  "pointer": "0x1",
+  "state_id": 2,
+  "program_points": [],
+  "program_state": {
+"store": null,
+"environment": null,
+"constraints": [
+  { "symbol": "reg_$0", "range": "{ [0, 10] }" }
+]
+  }
+}
+\l}"];
+
+Node0x1 -> Node0x3;
+
+// CHECK: Node0x3 [
+// CHECK-SAME: 
+// CHECK-SAME:   -
+// CHECK-SAME:   reg_$0
+// CHECK-SAME:   \{ [0, 10] \}
+// CHECK-SAME: 
+// CHECK-SAME: 
+// CHECK-SAME:   +
+// CHECK-SAME:   reg_$0
+// CHECK-SAME:   \{ [0, 5] \}
+// CHECK-SAME: 
+Node0x3 [shape=record,label=
+ "{
+{ "node_id": 3,
+  "pointer": "0x3",
+  "state_id": 4,
+  "program_points": [],
+  "program_state": {
+"store": null,
+"environment": null,
+"constraints": [
+  { "symbol": "reg_$0", "range": "{ [0, 5] }" }
+]
+  }
+}
+\l}"];
+
+Node0x3 -> Node0x5;
+
+Node0x5 [shape=record,label=
+ "{
+{ "node_id": 5,
+  "pointer": "0x5",
+  "state_id": 6,
+  "program_points": [],
+  "program_state": {
+"store": null,
+"environment": null,
+"constraints": null
+  }
+}
+\l}"];

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot?rev=364268=364267=364268=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot Mon Jun 24 
19:16:53 2019
@@ -33,6 +33,7 @@ Node0x1 [shape=record,label=
   "program_points": [],
   "program_state": {
 "store": null,
+"constraints": null,
 "environment": [
   {
 "location_context": "#0 Call",

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot?rev=364268=364267=364268=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot 
(original)
+++ 

[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: libcxx/include/bit:199
+!is_same_v, char32_t>
+ > {};
+

Given how heavily the code controlled by this trait depends on 
`numeric_limits<_Tp>`, would it make sense to add something in here about how 
that specialization should exist?

I agree with @EricWF's earlier comment: I can't think of any types that would 
satisfy `(!is_integral_v<_Tp>) && is_unsigned_v<_Tp>`.  (But just TIL that the 
signedness of `wchar_t` is implementation-defined.)



Comment at: libcxx/include/bit:211
+? __t
+: (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig)));
+}

No sane compiler would actually generate three `mod` operations for the three 
instances of repeated subexpression `__cnt % __dig`, would they?



Comment at: libcxx/include/bit:252
+while (true) {
+__t = rotr<_Tp>(__t, __ulldigits);
+if ((__iter = countl_zero(static_cast(__t))) 
!= __ulldigits)

Since `__t` is already of type `_Tp`, the explicit template argument `<_Tp>` is 
unnecessary here.
Also, is the ADL here intentional?



Comment at: libcxx/include/bit:253
+__t = rotr<_Tp>(__t, __ulldigits);
+if ((__iter = countl_zero(static_cast(__t))) 
!= __ulldigits)
+break;

I forget the rules of name hiding; is this `countl_zero` also an ADL call? (My 
experimentation implies it's not? but it would still be clearer to use 
`_VSTD::countl_zero` if that's what you mean.)

As a general rule, I strongly recommend writing side-effects //outside// of 
`if` conditions; like, on the previous line or something; unless writing it all 
on a single line has some concrete benefit.



Comment at: libcxx/include/bit:255
+break;
+__ret += __iter;
+}

clang-format?



Comment at: libcxx/include/bit:331
+int __ret = 0;
+while (__t != 0) // not a fixed loop here b/c we can exit early
+{

FWIW, this comment seems tautological.



Comment at: libcxx/include/bit:365
+if (__t < 2) return 1;
+const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 
1u));
+

Incidentally, why `(_Tp)(__t - 1u)` instead of the formula `__t - _Tp{1}` used 
elsewhere in this header?



Comment at: libcxx/include/bit:378
+   const unsigned __retVal = 1u << (__n + __extra);
+   return (_Tp) (__retVal >> __extra);
+}

Why so complicated? Is there a unit test that demonstrates why you can't just 
use `return _Tp{1} << __n;` in this case as well?

Also, is this a kosher use of `sizeof(X) * 8` as a stand-in for 
`numeric_limits::digits`?

Also, speaking of unit tests, I don't see any unit tests for e.g. 
`std::ceil2(256)` or `std::ceil2(65536)`. Shouldn't there be some?


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

https://reviews.llvm.org/D51262



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


r364265 - [cxx2a] P1236R1: the validity of a left shift does not depend on the

2019-06-24 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Jun 24 18:45:26 2019
New Revision: 364265

URL: http://llvm.org/viewvc/llvm-project?rev=364265=rev
Log:
[cxx2a] P1236R1: the validity of a left shift does not depend on the
value of the LHS operand.

Added:
cfe/trunk/test/Analysis/left-shift-cxx2a.cpp
cfe/trunk/test/CodeGenCXX/cxx2a-left-shift.cpp
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp
cfe/trunk/test/SemaCXX/shift.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=364265=364264=364265=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jun 24 18:45:26 2019
@@ -2388,9 +2388,11 @@ static bool handleIntIntBinOp(EvalInfo &
 if (SA != RHS) {
   Info.CCEDiag(E, diag::note_constexpr_large_shift)
 << RHS << E->getType() << LHS.getBitWidth();
-} else if (LHS.isSigned()) {
+} else if (LHS.isSigned() && !Info.getLangOpts().CPlusPlus2a) {
   // C++11 [expr.shift]p2: A signed left shift must have a non-negative
   // operand, and must not overflow the corresponding unsigned type.
+  // C++2a [expr.shift]p2: E1 << E2 is the unique value congruent to
+  // E1 x 2^E2 module 2^N.
   if (LHS.isNegative())
 Info.CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS;
   else if (LHS.countLeadingZeros() < SA)

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=364265=364264=364265=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Mon Jun 24 18:45:26 2019
@@ -3640,7 +3640,8 @@ Value *ScalarExprEmitter::EmitShl(const
 
   bool SanitizeBase = CGF.SanOpts.has(SanitizerKind::ShiftBase) &&
   Ops.Ty->hasSignedIntegerRepresentation() &&
-  !CGF.getLangOpts().isSignedOverflowDefined();
+  !CGF.getLangOpts().isSignedOverflowDefined() &&
+  !CGF.getLangOpts().CPlusPlus2a;
   bool SanitizeExponent = CGF.SanOpts.has(SanitizerKind::ShiftExponent);
   // OpenCL 6.3j: shift values are effectively % word size of LHS.
   if (CGF.getLangOpts().OpenCL)

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=364265=364264=364265=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jun 24 18:45:26 2019
@@ -9645,9 +9645,11 @@ static void DiagnoseBadShiftValues(Sema&
 return;
 
   // When left shifting an ICE which is signed, we can check for overflow which
-  // according to C++ has undefined behavior ([expr.shift] 5.8/2). Unsigned
-  // integers have defined behavior modulo one more than the maximum value
-  // representable in the result type, so never warn for those.
+  // according to C++ standards prior to C++2a has undefined behavior
+  // ([expr.shift] 5.8/2). Unsigned integers have defined behavior modulo one
+  // more than the maximum value representable in the result type, so never
+  // warn for those. (FIXME: Unsigned left-shift overflow in a constant
+  // expression is still probably a bug.)
   Expr::EvalResult LHSResult;
   if (LHS.get()->isValueDependent() ||
   LHSType->hasUnsignedIntegerRepresentation() ||
@@ -9656,8 +9658,9 @@ static void DiagnoseBadShiftValues(Sema&
   llvm::APSInt Left = LHSResult.Val.getInt();
 
   // If LHS does not have a signed type and non-negative value
-  // then, the behavior is undefined. Warn about it.
-  if (Left.isNegative() && !S.getLangOpts().isSignedOverflowDefined()) {
+  // then, the behavior is undefined before C++2a. Warn about it.
+  if (Left.isNegative() && !S.getLangOpts().isSignedOverflowDefined() &&
+  !S.getLangOpts().CPlusPlus2a) {
 S.DiagRuntimeBehavior(Loc, LHS.get(),
   S.PDiag(diag::warn_shift_lhs_negative)
 << LHS.get()->getSourceRange());

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BasicValueFactory.cpp?rev=364265=364264=364265=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BasicValueFactory.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BasicValueFactory.cpp Mon Jun 24 18:45:26 
2019
@@ -231,9 +231,6 @@ BasicValueFactory::evalAPSInt(BinaryOper
   // FIXME: This logic should 

[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

> Also are the unsigned types that aren't integral?

I believe that people are allowed to specialize `is_unsigned` for their own 
(bignum, say) types.
However, `is_integral` is not extensible. It refers to the types in 
`[basic.fundamental]`

> Type `bool` is a distinct type that has the same object representation, value 
> representation, and alignment requirements as an implementation-defined 
> unsigned integer type.


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

https://reviews.llvm.org/D51262



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


[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists marked 4 inline comments as done.
mclow.lists added inline comments.



Comment at: include/bit:254
+
+if  constexpr (sizeof(_Tp) <= sizeof(unsigned int))
+   return __clz(static_cast(__t))

EricWF wrote:
> Cool use of `if constexpr`.
> 
> Please clang-format these changes.
I really like this formatting; it reflects the structure of the code.



Comment at: include/bit:405
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY constexpr

EricWF wrote:
> Please write the SFINAE using a default template parameter.
> 
> See 
> http://libcxx.llvm.org/docs/DesignDocs/ExtendedCXX03Support.html#use-default-template-parameters-for-sfinae
I think that document is misguided in cases like this; the `enable_if` on the 
return type cannot be "interfered with" by the caller the way an extra template 
parameter can be.




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

https://reviews.llvm.org/D51262



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


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Thanks for the review ! That was the largest-work three lines of code of the 
history because I was blind.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63720



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


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364259: [analyzer] ExprEngine: Escape pointers in bitwise 
operations (authored by Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63720?vs=206344=206345#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63720

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  cfe/trunk/test/Analysis/symbol-escape.cpp


Index: cfe/trunk/test/Analysis/symbol-escape.cpp
===
--- cfe/trunk/test/Analysis/symbol-escape.cpp
+++ cfe/trunk/test/Analysis/symbol-escape.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,cplusplus.NewDeleteLeaks \
+// RUN:  -verify %s
+
+// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape
+//  the operands. After the evaluation it would be an
+//  Unknown value and the tracking would be lost.
+
+typedef unsigned __INTPTR_TYPE__ uintptr_t;
+
+class C {};
+
+C *simple_escape_in_bitwise_op(C *Foo) {
+  C *Bar = new C();
+  Bar = reinterpret_cast(reinterpret_cast(Bar) & 0x1);
+  (void)Bar;
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here.
+
+  return Bar;
+}
+
+C **indirect_escape_in_bitwise_op() {
+  C *Qux = new C();
+  C **Baz = 
+  Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
+  Baz = reinterpret_cast(reinterpret_cast(Baz) &
+  ~static_cast(0x1));
+  // no-warning: "Potential leak of memory pointed to by 'Qux'" was here.
+
+  delete *Baz;
+  return Baz;
+}
+
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -100,6 +100,10 @@
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
   if (!Result.isUnknown()) {
 state = state->BindExpr(B, LCtx, Result);
+  } else {
+// If we cannot evaluate the operation escape the operands.
+state = escapeValue(state, LeftV, PSK_EscapeOther);
+state = escapeValue(state, RightV, PSK_EscapeOther);
   }
 
   Bldr.generateNode(B, *it, state);


Index: cfe/trunk/test/Analysis/symbol-escape.cpp
===
--- cfe/trunk/test/Analysis/symbol-escape.cpp
+++ cfe/trunk/test/Analysis/symbol-escape.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,cplusplus.NewDeleteLeaks \
+// RUN:  -verify %s
+
+// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape
+//  the operands. After the evaluation it would be an
+//  Unknown value and the tracking would be lost.
+
+typedef unsigned __INTPTR_TYPE__ uintptr_t;
+
+class C {};
+
+C *simple_escape_in_bitwise_op(C *Foo) {
+  C *Bar = new C();
+  Bar = reinterpret_cast(reinterpret_cast(Bar) & 0x1);
+  (void)Bar;
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here.
+
+  return Bar;
+}
+
+C **indirect_escape_in_bitwise_op() {
+  C *Qux = new C();
+  C **Baz = 
+  Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
+  Baz = reinterpret_cast(reinterpret_cast(Baz) &
+		   ~static_cast(0x1));
+  // no-warning: "Potential leak of memory pointed to by 'Qux'" was here.
+
+  delete *Baz;
+  return Baz;
+}
+
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -100,6 +100,10 @@
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
   if (!Result.isUnknown()) {
 state = state->BindExpr(B, LCtx, Result);
+  } else {
+// If we cannot evaluate the operation escape the operands.
+state = escapeValue(state, LeftV, PSK_EscapeOther);
+state = escapeValue(state, RightV, PSK_EscapeOther);
   }
 
   Bldr.generateNode(B, *it, state);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 206344.
Charusso marked an inline comment as done.
Charusso added a comment.

- Better comment.


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

https://reviews.llvm.org/D63720

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/Analysis/symbol-escape.cpp


Index: clang/test/Analysis/symbol-escape.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-escape.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,cplusplus.NewDeleteLeaks \
+// RUN:  -verify %s
+
+// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape
+//  the operands. After the evaluation it would be an
+//  Unknown value and the tracking would be lost.
+
+typedef unsigned __INTPTR_TYPE__ uintptr_t;
+
+class C {};
+
+C *simple_escape_in_bitwise_op(C *Foo) {
+  C *Bar = new C();
+  Bar = reinterpret_cast(reinterpret_cast(Bar) & 0x1);
+  (void)Bar;
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here.
+
+  return Bar;
+}
+
+C **indirect_escape_in_bitwise_op() {
+  C *Qux = new C();
+  C **Baz = 
+  Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
+  Baz = reinterpret_cast(reinterpret_cast(Baz) &
+  ~static_cast(0x1));
+  // no-warning: "Potential leak of memory pointed to by 'Qux'" was here.
+
+  delete *Baz;
+  return Baz;
+}
+
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -100,6 +100,10 @@
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
   if (!Result.isUnknown()) {
 state = state->BindExpr(B, LCtx, Result);
+  } else {
+// If we cannot evaluate the operation escape the operands.
+state = escapeValue(state, LeftV, PSK_EscapeOther);
+state = escapeValue(state, RightV, PSK_EscapeOther);
   }
 
   Bldr.generateNode(B, *it, state);


Index: clang/test/Analysis/symbol-escape.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-escape.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,cplusplus.NewDeleteLeaks \
+// RUN:  -verify %s
+
+// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape
+//  the operands. After the evaluation it would be an
+//  Unknown value and the tracking would be lost.
+
+typedef unsigned __INTPTR_TYPE__ uintptr_t;
+
+class C {};
+
+C *simple_escape_in_bitwise_op(C *Foo) {
+  C *Bar = new C();
+  Bar = reinterpret_cast(reinterpret_cast(Bar) & 0x1);
+  (void)Bar;
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here.
+
+  return Bar;
+}
+
+C **indirect_escape_in_bitwise_op() {
+  C *Qux = new C();
+  C **Baz = 
+  Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
+  Baz = reinterpret_cast(reinterpret_cast(Baz) &
+		   ~static_cast(0x1));
+  // no-warning: "Potential leak of memory pointed to by 'Qux'" was here.
+
+  delete *Baz;
+  return Baz;
+}
+
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -100,6 +100,10 @@
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
   if (!Result.isUnknown()) {
 state = state->BindExpr(B, LCtx, Result);
+  } else {
+// If we cannot evaluate the operation escape the operands.
+state = escapeValue(state, LeftV, PSK_EscapeOther);
+state = escapeValue(state, RightV, PSK_EscapeOther);
   }
 
   Bldr.generateNode(B, *it, state);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r364259 - [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Mon Jun 24 17:44:33 2019
New Revision: 364259

URL: http://llvm.org/viewvc/llvm-project?rev=364259=rev
Log:
[analyzer] ExprEngine: Escape pointers in bitwise operations

Summary:
After evaluation it would be an Unknown value and tracking would be lost.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Analysis/symbol-escape.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=364259=364258=364259=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp Mon Jun 24 17:44:33 2019
@@ -100,6 +100,10 @@ void ExprEngine::VisitBinaryOperator(con
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
   if (!Result.isUnknown()) {
 state = state->BindExpr(B, LCtx, Result);
+  } else {
+// If we cannot evaluate the operation escape the operands.
+state = escapeValue(state, LeftV, PSK_EscapeOther);
+state = escapeValue(state, RightV, PSK_EscapeOther);
   }
 
   Bldr.generateNode(B, *it, state);

Added: cfe/trunk/test/Analysis/symbol-escape.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/symbol-escape.cpp?rev=364259=auto
==
--- cfe/trunk/test/Analysis/symbol-escape.cpp (added)
+++ cfe/trunk/test/Analysis/symbol-escape.cpp Mon Jun 24 17:44:33 2019
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,cplusplus.NewDeleteLeaks \
+// RUN:  -verify %s
+
+// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape
+//  the operands. After the evaluation it would be an
+//  Unknown value and the tracking would be lost.
+
+typedef unsigned __INTPTR_TYPE__ uintptr_t;
+
+class C {};
+
+C *simple_escape_in_bitwise_op(C *Foo) {
+  C *Bar = new C();
+  Bar = reinterpret_cast(reinterpret_cast(Bar) & 0x1);
+  (void)Bar;
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here.
+
+  return Bar;
+}
+
+C **indirect_escape_in_bitwise_op() {
+  C *Qux = new C();
+  C **Baz = 
+  Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
+  Baz = reinterpret_cast(reinterpret_cast(Baz) &
+  ~static_cast(0x1));
+  // no-warning: "Potential leak of memory pointed to by 'Qux'" was here.
+
+  delete *Baz;
+  return Baz;
+}
+


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


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Great, thanks!




Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:104
+
+  // If we cannot evaluate the operation escape the operands.
+  } else {

Pls put the comment inside `else`.


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

https://reviews.llvm.org/D63720



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


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 206341.
Charusso marked 8 inline comments as done.

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

https://reviews.llvm.org/D63720

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/Analysis/symbol-escape.cpp


Index: clang/test/Analysis/symbol-escape.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-escape.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,cplusplus.NewDeleteLeaks \
+// RUN:  -verify %s
+
+// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape
+//  the operands. After the evaluation it would be an
+//  Unknown value and the tracking would be lost.
+
+typedef unsigned __INTPTR_TYPE__ uintptr_t;
+
+class C {};
+
+C *simple_escape_in_bitwise_op(C *Foo) {
+  C *Bar = new C();
+  Bar = reinterpret_cast(reinterpret_cast(Bar) & 0x1);
+  (void)Bar;
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here.
+
+  return Bar;
+}
+
+C **indirect_escape_in_bitwise_op() {
+  C *Qux = new C();
+  C **Baz = 
+  Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
+  Baz = reinterpret_cast(reinterpret_cast(Baz) &
+  ~static_cast(0x1));
+  // no-warning: "Potential leak of memory pointed to by 'Qux'" was here.
+
+  delete *Baz;
+  return Baz;
+}
+
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -100,6 +100,11 @@
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
   if (!Result.isUnknown()) {
 state = state->BindExpr(B, LCtx, Result);
+
+  // If we cannot evaluate the operation escape the operands.
+  } else {
+state = escapeValue(state, LeftV, PSK_EscapeOther);
+state = escapeValue(state, RightV, PSK_EscapeOther);
   }
 
   Bldr.generateNode(B, *it, state);


Index: clang/test/Analysis/symbol-escape.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-escape.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,cplusplus.NewDeleteLeaks \
+// RUN:  -verify %s
+
+// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape
+//  the operands. After the evaluation it would be an
+//  Unknown value and the tracking would be lost.
+
+typedef unsigned __INTPTR_TYPE__ uintptr_t;
+
+class C {};
+
+C *simple_escape_in_bitwise_op(C *Foo) {
+  C *Bar = new C();
+  Bar = reinterpret_cast(reinterpret_cast(Bar) & 0x1);
+  (void)Bar;
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here.
+
+  return Bar;
+}
+
+C **indirect_escape_in_bitwise_op() {
+  C *Qux = new C();
+  C **Baz = 
+  Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
+  Baz = reinterpret_cast(reinterpret_cast(Baz) &
+		   ~static_cast(0x1));
+  // no-warning: "Potential leak of memory pointed to by 'Qux'" was here.
+
+  delete *Baz;
+  return Baz;
+}
+
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -100,6 +100,11 @@
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
   if (!Result.isUnknown()) {
 state = state->BindExpr(B, LCtx, Result);
+
+  // If we cannot evaluate the operation escape the operands.
+  } else {
+state = escapeValue(state, LeftV, PSK_EscapeOther);
+state = escapeValue(state, RightV, PSK_EscapeOther);
   }
 
   Bldr.generateNode(B, *it, state);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:123
 state = state->BindExpr(B, LCtx, Result);
   }
 

NoQ wrote:
> Charusso wrote:
> > I have seen we are producing tons of Unknowns and I am still not sure where 
> > they go, but even if I remove that condition these Unknowns will not shown 
> > up in the ExplodedGraph. I believe that should be the correct behavior.
> Unknowns don't show up in the Environment, but they do show up in the Store.
Oh, I really wanted to see them in the Environment. Thanks for the 
clarification!



Comment at: clang/test/Analysis/symbol-escape.cpp:5-6
 
+// expected-no-diagnostics
+
 #include 

NoQ wrote:
> Charusso wrote:
> > NoQ wrote:
> > > I think something went wrong while uploading the patch. This diff should 
> > > add this whole test file, not update it.
> > This is a test-driven-development-driven patch, first make the test fail, 
> > then make it pass.
> Sounds nice in your local git but for phabricator it's definitely better to 
> upload the exact thing that you're going to commit. It is assumed that the 
> tests would fail without the patch and will pass with the patch, and the 
> information on how exactly did the tests fail previously would look nice in 
> the description. Sometimes some (but usually not all) of the tests are added 
> just because they were discovered to be nice tests related to the patch but 
> not because they failed before the patch, which is also fine and should 
> ideally be mentioned in the description.
Lesson learned, thanks for the idea!



Comment at: clang/test/Analysis/symbol-escape.cpp:7
+
 #include 
 

NoQ wrote:
> Charusso wrote:
> > NoQ wrote:
> > > Relying on everybody's system headers is super flaky, don't do this in 
> > > tests.
> > > 
> > > Please define stuff that you use directly like other tests do:
> > > ```lang=c++
> > > typedef unsigned __INTPTR_TYPE__ uintptr_t;
> > > ```
> > It is a predefined header in Modules so Windows will not break.
> > 
> > Please note that only one of the test files (malloc.c) use that definition, 
> > most of them using that I have used in D62926, so I believe this header is 
> > the correct one as it is in four tests and Windows-approved by D62926.
> Mmm, ok, if it's an internal file then i guess it might be non-flaky. But 
> even then, if it's something more complicated than the definition of 
> `uintptr_t`, then your test will be affected by the contents of this file, 
> which may change. I'd slightly prefer to reduce the amount of such stuff in 
> our tests simply for keeping them minimal.
Hm, I hope that `malloc.c` one works.


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

https://reviews.llvm.org/D63720



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


[PATCH] D51262: Implement P0553 and P0556

2019-06-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists updated this revision to Diff 206339.
mclow.lists added a comment.

Update this patch to implement P1355R2  which makes 
out-of-bound inputs for `ceil2`UB. This was easy for integer types that are at 
least as big as `int`, but harder for smaller ones.


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

https://reviews.llvm.org/D51262

Files:
  libcxx/include/bit
  libcxx/test/std/numerics/bit/bit.pow.two/ceil2.fail.cpp
  libcxx/test/std/numerics/bit/bit.pow.two/ceil2.pass.cpp
  libcxx/test/std/numerics/bit/bit.pow.two/floor2.fail.cpp
  libcxx/test/std/numerics/bit/bit.pow.two/floor2.pass.cpp
  libcxx/test/std/numerics/bit/bit.pow.two/ispow2.fail.cpp
  libcxx/test/std/numerics/bit/bit.pow.two/ispow2.pass.cpp
  libcxx/test/std/numerics/bit/bit.pow.two/log2p1.fail.cpp
  libcxx/test/std/numerics/bit/bit.pow.two/log2p1.pass.cpp
  libcxx/test/std/numerics/bit/bitops.count/countl_one.fail.cpp
  libcxx/test/std/numerics/bit/bitops.count/countl_one.pass.cpp
  libcxx/test/std/numerics/bit/bitops.count/countl_zero.fail.cpp
  libcxx/test/std/numerics/bit/bitops.count/countl_zero.pass.cpp
  libcxx/test/std/numerics/bit/bitops.count/countr_one.fail.cpp
  libcxx/test/std/numerics/bit/bitops.count/countr_one.pass.cpp
  libcxx/test/std/numerics/bit/bitops.count/countr_zero.fail.cpp
  libcxx/test/std/numerics/bit/bitops.count/countr_zero.pass.cpp
  libcxx/test/std/numerics/bit/bitops.count/popcount.fail.cpp
  libcxx/test/std/numerics/bit/bitops.count/popcount.pass.cpp
  libcxx/test/std/numerics/bit/bitops.rot/rotl.fail.cpp
  libcxx/test/std/numerics/bit/bitops.rot/rotl.pass.cpp
  libcxx/test/std/numerics/bit/bitops.rot/rotr.fail.cpp
  libcxx/test/std/numerics/bit/bitops.rot/rotr.pass.cpp
  libcxx/test/std/numerics/bit/nothing_to_do.pass.cpp

Index: libcxx/test/std/numerics/bit/nothing_to_do.pass.cpp
===
--- /dev/null
+++ libcxx/test/std/numerics/bit/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+int main()
+{
+}
Index: libcxx/test/std/numerics/bit/bitops.rot/rotr.pass.cpp
===
--- /dev/null
+++ libcxx/test/std/numerics/bit/bitops.rot/rotr.pass.cpp
@@ -0,0 +1,118 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 
+
+// template 
+//   constexpr int rotr(T x, unsigned int s) noexcept;
+
+// Remarks: This function shall not participate in overload resolution unless 
+//	T is an unsigned integer type
+
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+template 
+constexpr bool constexpr_test()
+{
+	const T max = std::numeric_limits::max();
+
+	return std::rotr(T(128), 0) == T(128)
+	   &&  std::rotr(T(128), 1) == T( 64)
+	   &&  std::rotr(T(128), 2) == T( 32)
+	   &&  std::rotr(T(128), 3) == T( 16)
+	   &&  std::rotr(T(128), 4) == T(  8)
+	   &&  std::rotr(T(128), 5) == T(  4)
+	   &&  std::rotr(T(128), 6) == T(  2)
+	   &&  std::rotr(T(128), 7) == T(  1)
+	   &&  std::rotr(max, 0)  == max
+	   &&  std::rotr(max, 1)  == max
+	   &&  std::rotr(max, 2)  == max
+	   &&  std::rotr(max, 3)  == max
+	   &&  std::rotr(max, 4)  == max
+	   &&  std::rotr(max, 5)  == max
+	   &&  std::rotr(max, 6)  == max
+	   &&  std::rotr(max, 7)  == max
+	  ;
+}
+
+
+template 
+void runtime_test()
+{
+	ASSERT_SAME_TYPE(T, decltype(std::rotr(T(0), 0)));
+	ASSERT_NOEXCEPT( std::rotr(T(0), 0));
+	const T max = std::numeric_limits::max();
+	const T val = std::numeric_limits::max() - 1;
+
+	const T uppers [] = {
+		max,	  // not used
+		max - max,	  // 000 .. 0
+		max - (max >> 1), // 800 .. 0
+		max - (max >> 2), // C00 .. 0
+		max - (max >> 3), // E00 .. 0
+		max - (max >> 4), // F00 .. 0
+		max - (max >> 5), // F80 .. 0
+		max - (max >> 6), // FC0 .. 0
+		max - (max >> 7), // FE0 .. 0
+		};
+	
+	assert( std::rotr(val, 0) == val);
+	assert( std::rotr(val, 1) == T((val >> 1) +  uppers[1]));
+	assert( std::rotr(val, 2) == T((val >> 2) +  uppers[2]));
+	assert( std::rotr(val, 3) == T((val >> 3) +  uppers[3]));
+	assert( std::rotr(val, 4) == T((val >> 4) +  uppers[4]));
+	assert( std::rotr(val, 5) == T((val >> 5) +  uppers[5]));
+	assert( std::rotr(val, 6) == T((val >> 6) +  uppers[6]));
+	assert( std::rotr(val, 7) == T((val 

[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:123
 state = state->BindExpr(B, LCtx, Result);
   }
 

Charusso wrote:
> I have seen we are producing tons of Unknowns and I am still not sure where 
> they go, but even if I remove that condition these Unknowns will not shown up 
> in the ExplodedGraph. I believe that should be the correct behavior.
Unknowns don't show up in the Environment, but they do show up in the Store.



Comment at: clang/test/Analysis/symbol-escape.cpp:5-6
 
+// expected-no-diagnostics
+
 #include 

Charusso wrote:
> NoQ wrote:
> > I think something went wrong while uploading the patch. This diff should 
> > add this whole test file, not update it.
> This is a test-driven-development-driven patch, first make the test fail, 
> then make it pass.
Sounds nice in your local git but for phabricator it's definitely better to 
upload the exact thing that you're going to commit. It is assumed that the 
tests would fail without the patch and will pass with the patch, and the 
information on how exactly did the tests fail previously would look nice in the 
description. Sometimes some (but usually not all) of the tests are added just 
because they were discovered to be nice tests related to the patch but not 
because they failed before the patch, which is also fine and should ideally be 
mentioned in the description.



Comment at: clang/test/Analysis/symbol-escape.cpp:7
+
 #include 
 

Charusso wrote:
> NoQ wrote:
> > Relying on everybody's system headers is super flaky, don't do this in 
> > tests.
> > 
> > Please define stuff that you use directly like other tests do:
> > ```lang=c++
> > typedef unsigned __INTPTR_TYPE__ uintptr_t;
> > ```
> It is a predefined header in Modules so Windows will not break.
> 
> Please note that only one of the test files (malloc.c) use that definition, 
> most of them using that I have used in D62926, so I believe this header is 
> the correct one as it is in four tests and Windows-approved by D62926.
Mmm, ok, if it's an internal file then i guess it might be non-flaky. But even 
then, if it's something more complicated than the definition of `uintptr_t`, 
then your test will be affected by the contents of this file, which may change. 
I'd slightly prefer to reduce the amount of such stuff in our tests simply for 
keeping them minimal.



Comment at: clang/test/Analysis/symbol-escape.cpp:15
~static_cast(0x1)) |
   (reinterpret_cast(Bar) & 0x1));
   (void)Bar;

Charusso wrote:
> NoQ wrote:
> > `Bar` is reduced to one bit here. It's a legit leak. I think you meant to 
> > swap `Foo` and `Bar`.
> I assumed that we are doing our low-bits magic, where we have two identical 
> objects. The SymRegion sets up the HeapSymRegion's property, where no leak 
> happen. We just could change the first low-bit and set up some crazy flag, 
> like `isChecked()`, so we do not lost the tracking. Also we have four bits to 
> change, so there is no edge case going on.
I guess just flip a single bit like i did in my test?



Comment at: clang/test/Analysis/symbol-escape.cpp:12
 
 C *payload(C *Foo) {
   C *Bar = new C();

Let's make fancier names, like, dunno, `test_escape_into_bitwise_ops` and 
`test_indirect_escape_into_bitwise_ops`.


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

https://reviews.llvm.org/D63720



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


[PATCH] D63663: [clang-doc] Add html links to the parents of a RecordInfo

2019-06-24 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:21
 
 namespace {
 

Eugene.Zelenko wrote:
> Anonymous namespace is used for functions when LLVM Coding Guidelines tells 
> using static for same purpose.
Actually, since these aren't used outside of this file, please use the `static` 
keyword instead of wrapping them in a namespace.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:58
+if (!R.Path.empty()) {
+  Stream << genLink(R.Name, R.Path + "/" + R.Name + ".html");
+} else {

Use llvm::sys::path to allow for other platforms that use a different separator.



Comment at: clang-tools-extra/clang-doc/MDGenerator.cpp:21
 
-namespace {
+namespace md_generator {
 

Same here, just use static.



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:31
+// Example: Given the below, the  path for class C will be <
+// root>/A/B/C
+//

/A/B/C.



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:230
   if (const auto *N = dyn_cast(T)) {
 I.Members.emplace_back(getUSRForDecl(T), N->getNameAsString(),
InfoType::IT_enum, F->getNameAsString(),

Also for members



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:255
   if (const auto *N = dyn_cast(T)) {
 I.Params.emplace_back(getUSRForDecl(N), N->getNameAsString(),
   InfoType::IT_enum, P->getNameAsString());

Also for param references, if applicable



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:308-310
+if (const auto *P = getDeclForType(B.getType()))
+  I.VirtualParents.emplace_back(getUSRForDecl(P), P->getNameAsString(),
+InfoType::IT_record);

Can we do the path construction for virtual bases as well, so they can be 
linked too?



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:341-350
   if (const auto *T = getDeclForType(D->getReturnType())) {
 if (dyn_cast(T))
   I.ReturnType =
   TypeInfo(getUSRForDecl(T), T->getNameAsString(), InfoType::IT_enum);
 else if (dyn_cast(T))
   I.ReturnType =
   TypeInfo(getUSRForDecl(T), T->getNameAsString(), 
InfoType::IT_record);

Add path information to these references as well



Comment at: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp:145-146
   void ProtectedMethod();
-};)raw", 3, /*Public=*/false, Infos);
+};)raw",
+   3, /*Public=*/false, Infos);
 

formatting change?


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

https://reviews.llvm.org/D63663



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


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked an inline comment as done.
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:103
+if (const MemRegion *LeftMR = LeftV.getAsRegion())
+  IsLhsPtr = LeftMR->getSymbolicBase();
+if (const MemRegion *RightMR = RightV.getAsRegion())

NoQ wrote:
> How about the following test case in which not `Bar` but `` gets 
> bitwise-operated upon?
> 
> ```lang=c++
> C **test() {
>   C *Bar = new C;
>   C **Baz = 
>   Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
>   Baz = reinterpret_cast(reinterpret_cast(Baz) & 
> ~static_cast(0x1));
>   delete *Baz;
> }
> ```
> 
> The difference is that in this case the escaping region doesn't have a 
> symbolic base. And i believe that symbolic regions aren't special here in any 
> way.
> 
> I suggest doing an escape when the resulting value is unknown after 
> `evalBinOp` but regardless of any other conditions that you mentioned. Simply 
> because there's a loss of information.
That is a great idea! I wanted to make it more generic. Thanks you!



Comment at: clang/test/Analysis/symbol-escape.cpp:5-6
 
+// expected-no-diagnostics
+
 #include 

NoQ wrote:
> I think something went wrong while uploading the patch. This diff should add 
> this whole test file, not update it.
This is a test-driven-development-driven patch, first make the test fail, then 
make it pass.



Comment at: clang/test/Analysis/symbol-escape.cpp:7
+
 #include 
 

NoQ wrote:
> Relying on everybody's system headers is super flaky, don't do this in tests.
> 
> Please define stuff that you use directly like other tests do:
> ```lang=c++
> typedef unsigned __INTPTR_TYPE__ uintptr_t;
> ```
It is a predefined header in Modules so Windows will not break.

Please note that only one of the test files (malloc.c) use that definition, 
most of them using that I have used in D62926, so I believe this header is the 
correct one as it is in four tests and Windows-approved by D62926.



Comment at: clang/test/Analysis/symbol-escape.cpp:15
~static_cast(0x1)) |
   (reinterpret_cast(Bar) & 0x1));
   (void)Bar;

NoQ wrote:
> `Bar` is reduced to one bit here. It's a legit leak. I think you meant to 
> swap `Foo` and `Bar`.
I assumed that we are doing our low-bits magic, where we have two identical 
objects. The SymRegion sets up the HeapSymRegion's property, where no leak 
happen. We just could change the first low-bit and set up some crazy flag, like 
`isChecked()`, so we do not lost the tracking. Also we have four bits to 
change, so there is no edge case going on.



Comment at: clang/test/Analysis/symbol-escape.cpp:20
 
   delete Bar;
 }

NoQ wrote:
> In any case, passing a pointer to `delete` that wasn't obtained from `new` is 
> undefined behavior. In order to produce a test that's also a correct code, i 
> think we should either undo our bitwise operations, or perform an escape in a 
> different manner (say, return the pointer to the caller).
Whoops! I really wanted to make the test look great.



Comment at: clang/test/Analysis/symbol-escape.cpp:26
   ~static_cast(0x1));
-  // expected-warning@-2 {{Potential leak of memory pointed to by 'Qux'}}
 

I have made it fail on master.


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

https://reviews.llvm.org/D63720



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


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 206332.
Charusso marked 11 inline comments as done.
Charusso added a comment.

- Fix.


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

https://reviews.llvm.org/D63720

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/Analysis/symbol-escape.cpp


Index: clang/test/Analysis/symbol-escape.cpp
===
--- clang/test/Analysis/symbol-escape.cpp
+++ clang/test/Analysis/symbol-escape.cpp
@@ -2,6 +2,9 @@
 // RUN:  -analyzer-checker=core,cplusplus.NewDeleteLeaks \
 // RUN:  -verify %s
 
+// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape
+//  the operands.
+
 #include 
 
 class C {};
@@ -12,7 +15,7 @@
~static_cast(0x1)) |
   (reinterpret_cast(Bar) & 0x1));
   (void)Bar;
-  // expected-warning@-1 {{Potential leak of memory pointed to by 'Bar'}}
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here.
 
   return Bar;
 }
@@ -23,7 +26,7 @@
   Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
   Baz = reinterpret_cast(reinterpret_cast(Baz) &
   ~static_cast(0x1));
-  // expected-warning@-2 {{Potential leak of memory pointed to by 'Qux'}}
+  // no-warning: "Potential leak of memory pointed to by 'Qux'" was here.
 
   delete *Baz;
   return Baz;
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -100,6 +100,11 @@
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
   if (!Result.isUnknown()) {
 state = state->BindExpr(B, LCtx, Result);
+
+  // If we cannot evaluate the operation escape the operands.
+  } else {
+state = escapeValue(state, LeftV, PSK_EscapeOther);
+state = escapeValue(state, RightV, PSK_EscapeOther);
   }
 
   Bldr.generateNode(B, *it, state);


Index: clang/test/Analysis/symbol-escape.cpp
===
--- clang/test/Analysis/symbol-escape.cpp
+++ clang/test/Analysis/symbol-escape.cpp
@@ -2,6 +2,9 @@
 // RUN:  -analyzer-checker=core,cplusplus.NewDeleteLeaks \
 // RUN:  -verify %s
 
+// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape
+//  the operands.
+
 #include 
 
 class C {};
@@ -12,7 +15,7 @@
~static_cast(0x1)) |
   (reinterpret_cast(Bar) & 0x1));
   (void)Bar;
-  // expected-warning@-1 {{Potential leak of memory pointed to by 'Bar'}}
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here.
 
   return Bar;
 }
@@ -23,7 +26,7 @@
   Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
   Baz = reinterpret_cast(reinterpret_cast(Baz) &
 		   ~static_cast(0x1));
-  // expected-warning@-2 {{Potential leak of memory pointed to by 'Qux'}}
+  // no-warning: "Potential leak of memory pointed to by 'Qux'" was here.
 
   delete *Baz;
   return Baz;
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -100,6 +100,11 @@
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
   if (!Result.isUnknown()) {
 state = state->BindExpr(B, LCtx, Result);
+
+  // If we cannot evaluate the operation escape the operands.
+  } else {
+state = escapeValue(state, LeftV, PSK_EscapeOther);
+state = escapeValue(state, RightV, PSK_EscapeOther);
   }
 
   Bldr.generateNode(B, *it, state);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r364251 - AMDGPU: Fix missing declaration for mbcnt builtins

2019-06-24 Thread Matt Arsenault via cfe-commits
Author: arsenm
Date: Mon Jun 24 16:34:06 2019
New Revision: 364251

URL: http://llvm.org/viewvc/llvm-project?rev=364251=rev
Log:
AMDGPU: Fix missing declaration for mbcnt builtins

Modified:
cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl

Modified: cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def?rev=364251=364250=364251=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def Mon Jun 24 16:34:06 2019
@@ -33,6 +33,9 @@ BUILTIN(__builtin_amdgcn_workitem_id_x,
 BUILTIN(__builtin_amdgcn_workitem_id_y, "Ui", "nc")
 BUILTIN(__builtin_amdgcn_workitem_id_z, "Ui", "nc")
 
+BUILTIN(__builtin_amdgcn_mbcnt_hi, "UiUiUi", "nc")
+BUILTIN(__builtin_amdgcn_mbcnt_lo, "UiUiUi", "nc")
+
 
//===--===//
 // Instruction builtins.
 
//===--===//

Modified: cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl?rev=364251=364250=364251=diff
==
--- cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl Mon Jun 24 16:34:06 2019
@@ -578,6 +578,18 @@ kernel void test_gws_sema_p(uint id) {
   __builtin_amdgcn_ds_gws_sema_p(id);
 }
 
+// CHECK-LABEL: @test_mbcnt_lo(
+// CHECK: call i32 @llvm.amdgcn.mbcnt.lo(i32 %src0, i32 %src1)
+kernel void test_mbcnt_lo(global uint* out, uint src0, uint src1) {
+  *out = __builtin_amdgcn_mbcnt_lo(src0, src1);
+}
+
+// CHECK-LABEL: @test_mbcnt_hi(
+// CHECK: call i32 @llvm.amdgcn.mbcnt.hi(i32 %src0, i32 %src1)
+kernel void test_mbcnt_hi(global uint* out, uint src0, uint src1) {
+  *out = __builtin_amdgcn_mbcnt_hi(src0, src1);
+}
+
 // CHECK-DAG: [[$WI_RANGE]] = !{i32 0, i32 1024}
 // CHECK-DAG: attributes #[[$NOUNWIND_READONLY:[0-9]+]] = { nounwind readonly }
 // CHECK-DAG: attributes #[[$READ_EXEC_ATTRS]] = { convergent }


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


[PATCH] D63663: [clang-doc] Add html links to the parents of a RecordInfo

2019-06-24 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 206317.
DiegoAstiazaran edited the summary of this revision.
DiegoAstiazaran added a comment.
Herald added a subscriber: ormris.

Path name generation was moved to serialization phase as @juliehockett 
suggested.
Empty string declaration fixed.
Removed anonymous namespaces.


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

https://reviews.llvm.org/D63663

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.h
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Mapper.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/Serialize.h
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -37,7 +37,7 @@
 
   bool VisitNamespaceDecl(const NamespaceDecl *D) {
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", Public, "");
 if (I)
   EmittedInfos.emplace_back(std::move(I));
 return true;
@@ -48,7 +48,7 @@
 if (dyn_cast(D))
   return true;
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", Public, "");
 if (I)
   EmittedInfos.emplace_back(std::move(I));
 return true;
@@ -56,7 +56,7 @@
 
   bool VisitCXXMethodDecl(const CXXMethodDecl *D) {
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", Public, "");
 if (I)
   EmittedInfos.emplace_back(std::move(I));
 return true;
@@ -64,7 +64,7 @@
 
   bool VisitRecordDecl(const RecordDecl *D) {
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", Public, "");
 if (I)
   EmittedInfos.emplace_back(std::move(I));
 return true;
@@ -72,7 +72,7 @@
 
   bool VisitEnumDecl(const EnumDecl *D) {
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", Public, "");
 if (I)
   EmittedInfos.emplace_back(std::move(I));
 return true;
@@ -142,7 +142,8 @@
   E() {}
 protected:
   void ProtectedMethod();
-};)raw", 3, /*Public=*/false, Infos);
+};)raw",
+   3, /*Public=*/false, Infos);
 
   RecordInfo *E = InfoAsRecord(Infos[0].get());
   RecordInfo ExpectedE(EmptySID, "E");
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -72,7 +72,8 @@
 
   I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
-  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record,
+ llvm::SmallString<128>("/path/to"));
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
 
   I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
@@ -89,7 +90,7 @@
   assert(!Err);
   std::string Expected = R"raw(class r
 Defined at line 10 of test.cpp
-Inherits from F, G
+Inherits from F, G
 
 Members
 private int X
Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -110,30 +110,8 @@
   return false;
 }
 
-// A function to extract the appropriate path name for a given info's
-// documentation. The path returned is a composite of the parent namespaces as
-// directories plus the decl name as the filename.
-//
-// Example: Given the below, the  path for class C will be <
-// root>/A/B/C.
-//
-// namespace A {
-// namesapce B {
-//
-// class C {};
-//
-// }
-// }
 llvm::Expected>
-getInfoOutputFile(StringRef Root,
-  

[PATCH] D63742: [WebAssembly] Implement Address Sanitizer for Emscripten

2019-06-24 Thread Guanzhong Chen via Phabricator via cfe-commits
quantum created this revision.
quantum added reviewers: tlively, aheejin.
Herald added subscribers: llvm-commits, cfe-commits, sunfish, hiraditya, 
jgravelle-google, sbc100, dschuff.
Herald added projects: clang, LLVM.

This diff enables address sanitizer on Emscripten.

On Emscripten, real memory starts at the value passed to --global-base.

All memory before this is used as shadow memory, and thus the shadow mapping
function is simply dividing by 8.

A symbol __global_base is added so that code may know where the shadow
memory ends and real memory begins.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63742

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c
  lld/test/wasm/global-base.ll
  lld/wasm/Driver.cpp
  lld/wasm/Symbols.cpp
  lld/wasm/Symbols.h
  lld/wasm/Writer.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -112,6 +112,7 @@
 static const uint64_t kNetBSDKasan_ShadowOffset64 = 0xdfff9000;
 static const uint64_t kPS4CPU_ShadowOffset64 = 1ULL << 40;
 static const uint64_t kWindowsShadowOffset32 = 3ULL << 28;
+static const uint64_t kEmscriptenShadowOffset = 0;
 
 static const uint64_t kMyriadShadowScale = 5;
 static const uint64_t kMyriadMemoryOffset32 = 0x8000ULL;
@@ -437,6 +438,7 @@
   bool IsWindows = TargetTriple.isOSWindows();
   bool IsFuchsia = TargetTriple.isOSFuchsia();
   bool IsMyriad = TargetTriple.getVendor() == llvm::Triple::Myriad;
+  bool IsEmscripten = TargetTriple.isOSEmscripten();
 
   ShadowMapping Mapping;
 
@@ -459,6 +461,8 @@
   Mapping.Offset = IsX86 ? kIOSSimShadowOffset32 : kIOSShadowOffset32;
 else if (IsWindows)
   Mapping.Offset = kWindowsShadowOffset32;
+else if (IsEmscripten)
+  Mapping.Offset = kEmscriptenShadowOffset;
 else if (IsMyriad) {
   uint64_t ShadowOffset = (kMyriadMemoryOffset32 + kMyriadMemorySize32 -
(kMyriadMemorySize32 >> Mapping.Scale));
Index: lld/wasm/Writer.cpp
===
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -224,6 +224,9 @@
 log("mem: global base = " + Twine(Config->GlobalBase));
   }
 
+  if (WasmSym::GlobalBase)
+WasmSym::GlobalBase->setVirtualAddress(Config->GlobalBase);
+
   uint32_t DataStart = MemoryPtr;
 
   // Arbitrarily set __dso_handle handle to point to the start of the data
Index: lld/wasm/Symbols.h
===
--- lld/wasm/Symbols.h
+++ lld/wasm/Symbols.h
@@ -415,6 +415,10 @@
 
 // linker-generated symbols
 struct WasmSym {
+  // __global_base
+  // Symbol marking the start of the global section.
+  static DefinedData *GlobalBase;
+
   // __stack_pointer
   // Global that holds the address of the top of the explicit value stack in
   // linear memory.
Index: lld/wasm/Symbols.cpp
===
--- lld/wasm/Symbols.cpp
+++ lld/wasm/Symbols.cpp
@@ -28,6 +28,7 @@
 DefinedFunction *WasmSym::ApplyRelocs;
 DefinedData *WasmSym::DsoHandle;
 DefinedData *WasmSym::DataEnd;
+DefinedData *WasmSym::GlobalBase;
 DefinedData *WasmSym::HeapBase;
 GlobalSymbol *WasmSym::StackPointer;
 UndefinedGlobal *WasmSym::TableBase;
Index: lld/wasm/Driver.cpp
===
--- lld/wasm/Driver.cpp
+++ lld/wasm/Driver.cpp
@@ -482,6 +482,7 @@
 WasmSym::StackPointer = Symtab->addSyntheticGlobal(
 "__stack_pointer", WASM_SYMBOL_VISIBILITY_HIDDEN, StackPointer);
 WasmSym::DataEnd = Symtab->addOptionalDataSymbol("__data_end");
+WasmSym::GlobalBase = Symtab->addOptionalDataSymbol("__global_base");
 WasmSym::HeapBase = Symtab->addOptionalDataSymbol("__heap_base");
   }
 
Index: lld/test/wasm/global-base.ll
===
--- /dev/null
+++ lld/test/wasm/global-base.ll
@@ -0,0 +1,73 @@
+; RUN: llc -filetype=obj %s -o %t.o
+
+target triple = "wasm32-unknown-unknown"
+
+; RUN: wasm-ld -no-gc-sections --export=__global_base --export=__data_end --allow-undefined --no-entry -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s  -check-prefix=CHECK-1024
+; CHECK-1024:   - Type:GLOBAL
+; CHECK-1024-NEXT:Globals: 
+; CHECK-1024-NEXT:  - Index:   0
+; CHECK-1024-NEXT:Type:I32
+; CHECK-1024-NEXT:Mutable: true
+; CHECK-1024-NEXT:InitExpr:
+; CHECK-1024-NEXT:  Opcode:  I32_CONST
+; CHECK-1024-NEXT:  Value:   66560
+; CHECK-1024-NEXT:  - Index:   1
+; CHECK-1024-NEXT:Type:I32
+; CHECK-1024-NEXT:Mutable: 

[PATCH] D63678: Fix test Clang :: Driver/cl-response-file.c for Solaris

2019-06-24 Thread Douglas Yung via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364245: Fix test cl-response-file.c to work on all platforms 
including Windows/Solaris. (authored by dyung, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63678?vs=206093=206311#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63678

Files:
  cfe/trunk/test/Driver/cl-response-file.c


Index: cfe/trunk/test/Driver/cl-response-file.c
===
--- cfe/trunk/test/Driver/cl-response-file.c
+++ cfe/trunk/test/Driver/cl-response-file.c
@@ -4,7 +4,7 @@
 
 
 
-// RUN: echo '/I%S\Inputs\cl-response-file\ /DFOO=2' > %t.rsp
+// RUN: printf '%%s\n' '/I%S\Inputs\cl-response-file\ /DFOO=2' > %t.rsp
 // RUN: %clang_cl /c -### @%t.rsp -- %s 2>&1 | FileCheck %s
 
 // CHECK: "-I" "{{.*}}\\Inputs\\cl-response-file\\" "-D" "FOO=2"


Index: cfe/trunk/test/Driver/cl-response-file.c
===
--- cfe/trunk/test/Driver/cl-response-file.c
+++ cfe/trunk/test/Driver/cl-response-file.c
@@ -4,7 +4,7 @@
 
 
 
-// RUN: echo '/I%S\Inputs\cl-response-file\ /DFOO=2' > %t.rsp
+// RUN: printf '%%s\n' '/I%S\Inputs\cl-response-file\ /DFOO=2' > %t.rsp
 // RUN: %clang_cl /c -### @%t.rsp -- %s 2>&1 | FileCheck %s
 
 // CHECK: "-I" "{{.*}}\\Inputs\\cl-response-file\\" "-D" "FOO=2"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r364245 - Fix test cl-response-file.c to work on all platforms including Windows/Solaris.

2019-06-24 Thread Douglas Yung via cfe-commits
Author: dyung
Date: Mon Jun 24 15:26:08 2019
New Revision: 364245

URL: http://llvm.org/viewvc/llvm-project?rev=364245=rev
Log:
Fix test cl-response-file.c to work on all platforms including Windows/Solaris.

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

Modified:
cfe/trunk/test/Driver/cl-response-file.c

Modified: cfe/trunk/test/Driver/cl-response-file.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-response-file.c?rev=364245=364244=364245=diff
==
--- cfe/trunk/test/Driver/cl-response-file.c (original)
+++ cfe/trunk/test/Driver/cl-response-file.c Mon Jun 24 15:26:08 2019
@@ -4,7 +4,7 @@
 
 
 
-// RUN: echo '/I%S\Inputs\cl-response-file\ /DFOO=2' > %t.rsp
+// RUN: printf '%%s\n' '/I%S\Inputs\cl-response-file\ /DFOO=2' > %t.rsp
 // RUN: %clang_cl /c -### @%t.rsp -- %s 2>&1 | FileCheck %s
 
 // CHECK: "-I" "{{.*}}\\Inputs\\cl-response-file\\" "-D" "FOO=2"


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


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Nice!~ I'm glad this is getting sorted out.




Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:103
+if (const MemRegion *LeftMR = LeftV.getAsRegion())
+  IsLhsPtr = LeftMR->getSymbolicBase();
+if (const MemRegion *RightMR = RightV.getAsRegion())

How about the following test case in which not `Bar` but `` gets 
bitwise-operated upon?

```lang=c++
C **test() {
  C *Bar = new C;
  C **Baz = 
  Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
  Baz = reinterpret_cast(reinterpret_cast(Baz) & 
~static_cast(0x1));
  delete *Baz;
}
```

The difference is that in this case the escaping region doesn't have a symbolic 
base. And i believe that symbolic regions aren't special here in any way.

I suggest doing an escape when the resulting value is unknown after `evalBinOp` 
but regardless of any other conditions that you mentioned. Simply because 
there's a loss of information.



Comment at: clang/test/Analysis/symbol-escape.cpp:2
 // RUN: %clang_analyze_cc1 \
 // RUN:  -analyzer-checker=cplusplus.NewDeleteLeaks \
 // RUN:  -verify %s

Pls include `core` as well, just in case, because running path-sensitive 
analysis without `core` checkers is unsupported.



Comment at: clang/test/Analysis/symbol-escape.cpp:5-6
 
+// expected-no-diagnostics
+
 #include 

I think something went wrong while uploading the patch. This diff should add 
this whole test file, not update it.



Comment at: clang/test/Analysis/symbol-escape.cpp:7
+
 #include 
 

Relying on everybody's system headers is super flaky, don't do this in tests.

Please define stuff that you use directly like other tests do:
```lang=c++
typedef unsigned __INTPTR_TYPE__ uintptr_t;
```



Comment at: clang/test/Analysis/symbol-escape.cpp:15
~static_cast(0x1)) |
   (reinterpret_cast(Bar) & 0x1));
   (void)Bar;

`Bar` is reduced to one bit here. It's a legit leak. I think you meant to swap 
`Foo` and `Bar`.



Comment at: clang/test/Analysis/symbol-escape.cpp:20
 
   delete Bar;
 }

In any case, passing a pointer to `delete` that wasn't obtained from `new` is 
undefined behavior. In order to produce a test that's also a correct code, i 
think we should either undo our bitwise operations, or perform an escape in a 
different manner (say, return the pointer to the caller).


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

https://reviews.llvm.org/D63720



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


[PATCH] D63616: Implement `-fsanitize-coverage-whitelist` and `-fsanitize-coverage-blacklist` for clang

2019-06-24 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

Thanks for the patch!  Seems like a useful feature for targeted fuzzing.




Comment at: clang/docs/SanitizerCoverage.rst:310
+
+In most cases, the whitelist will list the folders or source files for which 
you want
+instrumentation and allow all function names, while the blacklist will opt out 
some specific

The wording makes it sound like there may be exceptions to the expected 
whitelist/blacklist behavior.  But IIUC the paragraph is meant to explain the 
typical use case.  Can we make this more explicit?

e.g.,
```
A common use case is to have the whitelist list folders and source files ... 
while the blacklist ...
```

Or maybe we don't need this paragraph at all...



Comment at: clang/include/clang/Driver/Options.td:978
+def fsanitize_coverage_blacklist : Separate<["-"], 
"fsanitize-coverage-blacklist">,
+Group, Flags<[CoreOption, DriverOption]>, 
Alias;
 def fsanitize_memory_track_origins_EQ : Joined<["-"], 
"fsanitize-memory-track-origins=">,

For `fsanitize_blacklist` we only support `-fsanitize-blacklist=`.  Let's do 
the same for these lists to keep things simple.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:218
   Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
-  PM.add(createSanitizerCoverageModulePass(Opts));
+  PM.add(createSanitizerCoverageModulePass(Opts, 
CGOpts.SanitizeCoverageWhitelistFiles, CGOpts.SanitizeCoverageBlacklistFiles));
 }

Please run `clang-format --style=LLVM` on the patch.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:743
+  }
+}
+  }

The two cases have lots of overlapping code.  Let's try to coalesce.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:759
+  D.Diag(clang::diag::err_drv_malformed_sanitizer_coverage_blacklist) << 
BLError;
+  }
+

Let's try to coalesce here too.  Maybe a helper function?  Then we could also 
use it for the sanitizer blacklist.



Comment at: 
compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_whitelist_blacklist.cc:60
+// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=trace-pc 
-fsanitize-coverage-whitelist=wl_bar.txt  
-fsanitize-coverage-blacklist=bl_bar.txt   2>&1 | not grep "call void 
@__sanitizer_cov_trace_pc"
+
+// RUN: rm wl_*.txt

Can we also test with `-fsanitize=inline-8bit-counters`, since that is what 
libFuzzer uses by default?



Comment at: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp:192
+  Blacklist = SpecialCaseList::createOrDie(BlacklistFiles);
+}
 initializeSanitizerCoverageModulePass(*PassRegistry::getPassRegistry());

Nit:  Preferred style is no curly braces for one-statement ifs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63616



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


[PATCH] D62825: [C++2a] Add __builtin_bit_cast, used to implement std::bit_cast

2019-06-24 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticASTKinds.td:223
+def note_constexpr_bit_cast_invalid_type : Note<
+  "cannot constexpr evaluate a bit_cast with a "
+  "%select{union|pointer|member pointer|volatile|struct with a reference 
member}0"

Quuxplusone wrote:
> rsmith wrote:
> > "constexpr evaluate" doesn't really mean anything. Also, the "struct with a 
> > reference member type X" case seems a bit strangely phrased (and it need 
> > not be a struct anyway...).
> > 
> > Maybe "cannot bit_cast {from|to}0 a {|type with a}1 {union|pointer|member 
> > pointer|volatile|reference}2 {type|member}1 in a constant expression"?
> Peanut gallery says: Surely wherever this message comes from should use the 
> same wording as other similar messages: `"(this construction) is not allowed 
> in a constant expression"`. That is, the diagnostics for
> ```
> constexpr int *foo(void *p) { return reinterpret_cast(p); }
> constexpr int *bar(void *p) { return std::bit_cast(p); }
> ```
> should be word-for-word identical except for the kind of cast they're 
> complaining about.
> 
> (And if I had my pedantic druthers, every such message would say "...does not 
> produce a constant expression" instead of "...is not allowed in a constant 
> expression." But that's way out of scope for this patch.)
Sure, that seems more consistent. 



Comment at: clang/lib/AST/ExprConstant.cpp:5454-5457
+case APValue::Indeterminate:
+  Info.FFDiag(BCE->getExprLoc(), diag::note_constexpr_access_uninit)
+  << 0 << 1;
+  return false;

rsmith wrote:
> I've checked the intent on the reflectors, and we should drop both this and 
> the `APValue::None` check here. Bits corresponding to uninitialized or 
> out-of-lifetime subobjects should just be left uninitialized (exactly like 
> padding bits).
> 
> Example:
> 
> ```
> struct X { char c; int n; };
> struct Y { char data[sizeof(X)]; };
> constexpr bool test() {
>   X x = {1, 2};
>   Y y = __builtin_bit_cast(Y, x); // OK, y.data[1] - y.data[3] are 
> APValue::Indeterminate
>   X z = __builtin_bit_cast(X, y); // OK, both members are initialized
>   return x.c == z.c && x.n == z.n;
> }
> static_assert(test());
> ```
You mean:
```
- struct Y { char data[sizeof(X)]; };
+ struct Y { unsigned char data[sizeof(X)]; };
```
...right? I added this test to the constexpr-builtin-bit-cast.cpp (as well of 
some of your other cases from the reflector).


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

https://reviews.llvm.org/D62825



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


[PATCH] D62825: [C++2a] Add __builtin_bit_cast, used to implement std::bit_cast

2019-06-24 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 206304.
erik.pilkington marked 10 inline comments as done.
erik.pilkington added a comment.

Address review comments.


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

https://reviews.llvm.org/D62825

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGenCXX/builtin-bit-cast-no-tbaa.cpp
  clang/test/CodeGenCXX/builtin-bit-cast.cpp
  clang/test/SemaCXX/builtin-bit-cast.cpp
  clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  llvm/include/llvm/ADT/APInt.h
  llvm/lib/ExecutionEngine/ExecutionEngine.cpp
  llvm/lib/Support/APInt.cpp

Index: llvm/lib/Support/APInt.cpp
===
--- llvm/lib/Support/APInt.cpp
+++ llvm/lib/Support/APInt.cpp
@@ -2929,3 +2929,56 @@
   LLVM_DEBUG(dbgs() << __func__ << ": solution (wrap): " << X << '\n');
   return X;
 }
+
+/// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst
+/// with the integer held in IntVal.
+void llvm::StoreIntToMemory(const APInt , uint8_t *Dst,
+unsigned StoreBytes) {
+  assert((IntVal.getBitWidth()+7)/8 >= StoreBytes && "Integer too small!");
+  const uint8_t *Src = (const uint8_t *)IntVal.getRawData();
+
+  if (sys::IsLittleEndianHost) {
+// Little-endian host - the source is ordered from LSB to MSB.  Order the
+// destination from LSB to MSB: Do a straight copy.
+memcpy(Dst, Src, StoreBytes);
+  } else {
+// Big-endian host - the source is an array of 64 bit words ordered from
+// LSW to MSW.  Each word is ordered from MSB to LSB.  Order the destination
+// from MSB to LSB: Reverse the word order, but not the bytes in a word.
+while (StoreBytes > sizeof(uint64_t)) {
+  StoreBytes -= sizeof(uint64_t);
+  // May not be aligned so use memcpy.
+  memcpy(Dst + StoreBytes, Src, sizeof(uint64_t));
+  Src += sizeof(uint64_t);
+}
+
+memcpy(Dst, Src + sizeof(uint64_t) - StoreBytes, StoreBytes);
+  }
+}
+
+/// LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting
+/// from Src into IntVal, which is assumed to be wide enough and to hold zero.
+void llvm::LoadIntFromMemory(APInt , uint8_t *Src, unsigned LoadBytes) {
+  assert((IntVal.getBitWidth()+7)/8 >= LoadBytes && "Integer too small!");
+  uint8_t *Dst = reinterpret_cast(
+   const_cast(IntVal.getRawData()));
+
+  if (sys::IsLittleEndianHost)
+// Little-endian host - the destination must be ordered from LSB to MSB.
+// The source is ordered from LSB to MSB: Do a straight copy.
+memcpy(Dst, Src, LoadBytes);
+  else {
+// Big-endian - the destination is an array of 64 bit words ordered from
+// LSW to MSW.  Each word must be ordered from MSB to LSB.  The source is
+// ordered from MSB to LSB: Reverse the word order, but not the bytes in
+// a word.
+while (LoadBytes > sizeof(uint64_t)) {
+  LoadBytes -= sizeof(uint64_t);
+  // May not be aligned so use memcpy.
+  memcpy(Dst, Src + LoadBytes, sizeof(uint64_t));
+  Dst += sizeof(uint64_t);
+}
+
+memcpy(Dst + sizeof(uint64_t) - LoadBytes, Src, LoadBytes);
+  }
+}
Index: llvm/lib/ExecutionEngine/ExecutionEngine.cpp
===
--- llvm/lib/ExecutionEngine/ExecutionEngine.cpp
+++ llvm/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -1019,32 +1019,6 @@
   return Result;
 }
 
-/// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst
-/// with the integer held in IntVal.
-static void StoreIntToMemory(const APInt , uint8_t *Dst,
- unsigned StoreBytes) {
-  assert((IntVal.getBitWidth()+7)/8 >= StoreBytes && "Integer 

[PATCH] D63518: WIP BitStream reader: propagate errors

2019-06-24 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

All of `check-llvm` now passes. I'll look at other users of this stuff in the 
monorepo, compile and run their tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63518



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


[PATCH] D62953: [Syntax] Do not glue multiple empty PP expansions to a single mapping

2019-06-24 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364236: [Syntax] Do not glue multiple empty PP expansions to 
a single mapping (authored by ibiryukov, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62953?vs=206246=206303#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62953

Files:
  cfe/trunk/include/clang/Tooling/Syntax/Tokens.h
  cfe/trunk/lib/Tooling/Syntax/Tokens.cpp
  cfe/trunk/unittests/Tooling/Syntax/TokensTest.cpp

Index: cfe/trunk/include/clang/Tooling/Syntax/Tokens.h
===
--- cfe/trunk/include/clang/Tooling/Syntax/Tokens.h
+++ cfe/trunk/include/clang/Tooling/Syntax/Tokens.h
@@ -160,6 +160,7 @@
 /// the spelled tokens of a file using the tokenize() helper.
 ///
 /// FIXME: allow to map from spelled to expanded tokens when use-case shows up.
+/// FIXME: allow mappings into macro arguments.
 class TokenBuffer {
 public:
   TokenBuffer(const SourceManager ) : SourceMgr() {}
@@ -227,6 +228,8 @@
   ///#pragma, etc.
   llvm::ArrayRef spelledTokens(FileID FID) const;
 
+  const SourceManager () const { return *SourceMgr; }
+
   std::string dumpForTests() const;
 
 private:
@@ -310,9 +313,32 @@
   LLVM_NODISCARD TokenBuffer consume() &&;
 
 private:
+  /// Maps from a start to an end spelling location of transformations
+  /// performed by the preprocessor. These include:
+  ///   1. range from '#' to the last token in the line for PP directives,
+  ///   2. macro name and arguments for macro expansions.
+  /// Note that we record only top-level macro expansions, intermediate
+  /// expansions (e.g. inside macro arguments) are ignored.
+  ///
+  /// Used to find correct boundaries of macro calls and directives when
+  /// building mappings from spelled to expanded tokens.
+  ///
+  /// Logically, at each point of the preprocessor execution there is a stack of
+  /// macro expansions being processed and we could use it to recover the
+  /// location information we need. However, the public preprocessor API only
+  /// exposes the points when macro expansions start (when we push a macro onto
+  /// the stack) and not when they end (when we pop a macro from the stack).
+  /// To workaround this limitation, we rely on source location information
+  /// stored in this map.
+  using PPExpansions = llvm::DenseMap;
   class Builder;
+  class CollectPPExpansions;
+
   std::vector Expanded;
+  // FIXME: we only store macro expansions, also add directives(#pragma, etc.)
+  PPExpansions Expansions;
   Preprocessor 
+  CollectPPExpansions *Collector;
 };
 
 } // namespace syntax
Index: cfe/trunk/lib/Tooling/Syntax/Tokens.cpp
===
--- cfe/trunk/lib/Tooling/Syntax/Tokens.cpp
+++ cfe/trunk/lib/Tooling/Syntax/Tokens.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -70,8 +71,8 @@
 
 FileRange::FileRange(FileID File, unsigned BeginOffset, unsigned EndOffset)
 : File(File), Begin(BeginOffset), End(EndOffset) {
-  assert(File.isValid());
-  assert(BeginOffset <= EndOffset);
+  assert(File.isValid());
+  assert(BeginOffset <= EndOffset);
 }
 
 FileRange::FileRange(const SourceManager , SourceLocation BeginLoc,
@@ -252,6 +253,39 @@
   return Tokens;
 }
 
+/// Records information reqired to construct mappings for the token buffer that
+/// we are collecting.
+class TokenCollector::CollectPPExpansions : public PPCallbacks {
+public:
+  CollectPPExpansions(TokenCollector ) : Collector() {}
+
+  /// Disabled instance will stop reporting anything to TokenCollector.
+  /// This ensures that uses of the preprocessor after TokenCollector::consume()
+  /// is called do not access the (possibly invalid) collector instance.
+  void disable() { Collector = nullptr; }
+
+  void MacroExpands(const clang::Token , const MacroDefinition ,
+SourceRange Range, const MacroArgs *Args) override {
+if (!Collector)
+  return;
+// Only record top-level expansions, not those where:
+//   - the macro use is inside a macro body,
+//   - the macro appears in an argument to another macro.
+if (!MacroNameTok.getLocation().isFileID() ||
+(LastExpansionEnd.isValid() &&
+ Collector->PP.getSourceManager().isBeforeInTranslationUnit(
+ Range.getBegin(), LastExpansionEnd)))
+  return;
+Collector->Expansions[Range.getBegin().getRawEncoding()] = Range.getEnd();
+LastExpansionEnd = Range.getEnd();
+  }
+  // FIXME: handle directives like #pragma, #include, etc.
+private:
+  TokenCollector *Collector;
+  /// 

r364236 - [Syntax] Do not glue multiple empty PP expansions to a single mapping

2019-06-24 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Jun 24 14:39:51 2019
New Revision: 364236

URL: http://llvm.org/viewvc/llvm-project?rev=364236=rev
Log:
[Syntax] Do not glue multiple empty PP expansions to a single mapping

Summary:
This change makes sure we have a single mapping for each macro expansion,
even if the result of expansion was empty.

To achieve that, we take information from PPCallbacks::MacroExpands into
account. Previously we relied only on source locations of expanded tokens.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Tooling/Syntax/Tokens.h
cfe/trunk/lib/Tooling/Syntax/Tokens.cpp
cfe/trunk/unittests/Tooling/Syntax/TokensTest.cpp

Modified: cfe/trunk/include/clang/Tooling/Syntax/Tokens.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Syntax/Tokens.h?rev=364236=364235=364236=diff
==
--- cfe/trunk/include/clang/Tooling/Syntax/Tokens.h (original)
+++ cfe/trunk/include/clang/Tooling/Syntax/Tokens.h Mon Jun 24 14:39:51 2019
@@ -160,6 +160,7 @@ llvm::raw_ostream <<(llvm::raw_
 /// the spelled tokens of a file using the tokenize() helper.
 ///
 /// FIXME: allow to map from spelled to expanded tokens when use-case shows up.
+/// FIXME: allow mappings into macro arguments.
 class TokenBuffer {
 public:
   TokenBuffer(const SourceManager ) : SourceMgr() {}
@@ -227,6 +228,8 @@ public:
   ///#pragma, etc.
   llvm::ArrayRef spelledTokens(FileID FID) const;
 
+  const SourceManager () const { return *SourceMgr; }
+
   std::string dumpForTests() const;
 
 private:
@@ -310,9 +313,32 @@ public:
   LLVM_NODISCARD TokenBuffer consume() &&;
 
 private:
+  /// Maps from a start to an end spelling location of transformations
+  /// performed by the preprocessor. These include:
+  ///   1. range from '#' to the last token in the line for PP directives,
+  ///   2. macro name and arguments for macro expansions.
+  /// Note that we record only top-level macro expansions, intermediate
+  /// expansions (e.g. inside macro arguments) are ignored.
+  ///
+  /// Used to find correct boundaries of macro calls and directives when
+  /// building mappings from spelled to expanded tokens.
+  ///
+  /// Logically, at each point of the preprocessor execution there is a stack 
of
+  /// macro expansions being processed and we could use it to recover the
+  /// location information we need. However, the public preprocessor API only
+  /// exposes the points when macro expansions start (when we push a macro onto
+  /// the stack) and not when they end (when we pop a macro from the stack).
+  /// To workaround this limitation, we rely on source location information
+  /// stored in this map.
+  using PPExpansions = llvm::DenseMap;
   class Builder;
+  class CollectPPExpansions;
+
   std::vector Expanded;
+  // FIXME: we only store macro expansions, also add directives(#pragma, etc.)
+  PPExpansions Expansions;
   Preprocessor 
+  CollectPPExpansions *Collector;
 };
 
 } // namespace syntax

Modified: cfe/trunk/lib/Tooling/Syntax/Tokens.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Syntax/Tokens.cpp?rev=364236=364235=364236=diff
==
--- cfe/trunk/lib/Tooling/Syntax/Tokens.cpp (original)
+++ cfe/trunk/lib/Tooling/Syntax/Tokens.cpp Mon Jun 24 14:39:51 2019
@@ -14,6 +14,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -70,8 +71,8 @@ llvm::raw_ostream ::operator<<(ll
 
 FileRange::FileRange(FileID File, unsigned BeginOffset, unsigned EndOffset)
 : File(File), Begin(BeginOffset), End(EndOffset) {
-  assert(File.isValid());
-  assert(BeginOffset <= EndOffset);
+  assert(File.isValid());
+  assert(BeginOffset <= EndOffset);
 }
 
 FileRange::FileRange(const SourceManager , SourceLocation BeginLoc,
@@ -252,6 +253,39 @@ std::vector syntax::token
   return Tokens;
 }
 
+/// Records information reqired to construct mappings for the token buffer that
+/// we are collecting.
+class TokenCollector::CollectPPExpansions : public PPCallbacks {
+public:
+  CollectPPExpansions(TokenCollector ) : Collector() {}
+
+  /// Disabled instance will stop reporting anything to TokenCollector.
+  /// This ensures that uses of the preprocessor after 
TokenCollector::consume()
+  /// is called do not access the (possibly invalid) collector instance.
+  void disable() { Collector = nullptr; }
+
+  void MacroExpands(const clang::Token , const MacroDefinition 
,
+SourceRange Range, const MacroArgs *Args) override {
+if (!Collector)
+  return;
+// Only record top-level expansions, not 

[PATCH] D62739: AMDGPU: Always emit amdgpu-flat-work-group-size

2019-06-24 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

ping


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

https://reviews.llvm.org/D62739



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


[PATCH] D62977: [clang-tidy]: Google: new check 'google-upgrade-googletest-case'

2019-06-24 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp:30
 #include "UnnamedNamespaceInHeaderCheck.h"
 #include "UsingNamespaceDirectiveCheck.h"
 

Just tried building this. I think you're missing an include for 
`UpgradeGoogletestCaseCheck`.


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

https://reviews.llvm.org/D62977



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


[PATCH] D63623: [clang-tidy] Add a check on expected return values of posix functions (except posix_openpt) in Android module.

2019-06-24 Thread Jian Cai via Phabricator via cfe-commits
jcai19 added a comment.

In D63623#1556161 , @lebedev.ri wrote:

> In D63623#1552716 , @jcai19 wrote:
>
> > In D63623#1552679 , @lebedev.ri 
> > wrote:
> >
> > > Why is this in android module?
> > >  Is that android-specific behavior, or posix?
> >
> >
> > I implemented it for Andriod as requested, but it would be completely fine 
> > to move it if it is better to place the check at a different location. 
> > Where do you suggest we should move this check to? Thanks.
>
>
> Either `misc` or `bugprone` or a new `posix` module.


Sounds good. Thanks for the clarification.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63623



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


[PATCH] D62977: [clang-tidy]: Google: new check 'google-upgrade-googletest-case'

2019-06-24 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

In D62977#1540184 , @lebedev.ri wrote:

> Without seeing the tests - what version checks does this have?
>  It shouldn't fire if the googletest version is the one before that rename.


I don't believe this question was answered.


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

https://reviews.llvm.org/D62977



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


[PATCH] D62977: [clang-tidy]: Google: new check 'google-upgrade-googletest-case'

2019-06-24 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

Generally this LGTM.
I'll take another pass after the comments are addressed.




Comment at: 
clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp:19
+
+static const llvm::StringRef CheckMessage =
+"Googletest APIs named with 'case' are deprecated; use equivalent APIs "

Could you rename this to better represent what the diagnostic text is saying, 
rather than just being diagnostic text?
I think it'll help readability below.

Why not put this inside the unnamed namespace instead?

Same with the function below.



Comment at: 
clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp:201
+ const MatchFinder::MatchResult ) {
+  internal::Matcher IsInsideTemplate =
+  hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl(;

Instead of walking the tree, can't you ask if the Node is dependent in some way?



Comment at: 
clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp:294
+  } else {
+// This is a match for `TestCase` to `TestSuite` refactoring.
+ReplacementText = "TestSuite";

Maybe add an assertion for this comment?



Comment at: clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.h:23
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/google-upgrade-googletest-case.html
+class UpgradeGoogletestCaseCheck : public ClangTidyCheck {

`https` all the things!



Comment at: 
clang-tools-extra/test/clang-tidy/google-upgrade-googletest-case.cpp:9
+TYPED_TEST_CASE(FooTest, FooTypes);
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: Googletest APIs named with 'case' 
are deprecated; use equivalent APIs named with 'suite'
+// CHECK-FIXES: TYPED_TEST_SUITE(FooTest, FooTypes);

You probably don't have to test for the full message every time. but I don't 
know it matters either way.


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

https://reviews.llvm.org/D62977



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


[PATCH] D60455: [SYCL] Implement SYCL device code outlining

2019-06-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/SemaSYCL/device-attributes.cpp:3
+
+[[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' 
attribute only applies to functions}}
+__attribute((sycl_kernel)) int gv3 = 0; // expected-warning {{'sycl_kernel' 
attribute only applies to functions}}

keryell wrote:
> bader wrote:
> > aaron.ballman wrote:
> > > Fznamznon wrote:
> > > > aaron.ballman wrote:
> > > > > I'd like to see some more tests covering less obvious scenarios. Can 
> > > > > I add this attribute to a lambda? What about a member function? How 
> > > > > does it work with virtual functions? That sort of thing.
> > > > Actually there is no restrictions for adding this attribute to any 
> > > > function to outline device code so I just checked the simplest variant.
> > > > 
> > > > But I'm working on new patch which will put some requirements on 
> > > > function which is marked with `sycl_kernel` attribute. 
> > > > This new patch will add generation of OpenCL kernel from function 
> > > > marked with `sycl_kernel` attribute. The main idea of this approach is 
> > > > described in this [[ 
> > > > https://github.com/intel/llvm/blob/sycl/sycl/doc/SYCL_compiler_and_runtime_design.md#lowering-of-lambda-function-objects-and-named-function-objects
> > > >  | document ]] (in this document generated kernel is called "kernel 
> > > > wrapper").
> > > > And to be able to generate OpenCL kernel using function marked with 
> > > > `sycl_kernel` attribute we put some requirements on this function, for 
> > > > example it must be a template function. You can find these requirements 
> > > > and example of proper function which can be marked with `sycl_kernel` 
> > > > in this [[ https://github.com/intel/llvm/pull/177#discussion_r290451286 
> > > > | comment ]] .
> > > > 
> > > > 
> > > > Actually there is no restrictions for adding this attribute to any 
> > > > function to outline device code so I just checked the simplest variant.
> > > 
> > > So there are no concerns about code like:
> > > ```
> > > struct Base {
> > >   __attribute__((sycl_kernel)) virtual void foo();
> > >   virtual void bar();
> > > };
> > > 
> > > struct Derived : Base {
> > >   void foo() override;
> > >   __attribute__((sycl_kernel)) void bar() override;
> > > };
> > > 
> > > void f(Base *B, Derived *D) {
> > >   // Will all of these "do the right thing"?
> > >   B->foo();
> > >   B->bar();
> > > 
> > >   D->foo();
> > >   D->bar();
> > > }
> > > ```
> > > Actually there is no restrictions for adding this attribute to any 
> > > function to outline device code so I just checked the simplest variant.
> > > But I'm working on new patch which will put some requirements on function 
> > > which is marked with sycl_kernel attribute.
> > 
> > @aaron.ballman, sorry for confusing. The  usage scenarios should have been 
> > articulated more accurately.
> > We have only four uses of this attribute in our implementation:
> > https://github.com/intel/llvm/blob/sycl/sycl/include/CL/sycl/handler.hpp#L538
> >  (lines 538-605).
> > All four uses are applied to member functions of `cl::sycl::handler` class 
> > and all of them have similar prototype (which is mentioned by Mariya in the 
> > previous 
> > [comment](https://github.com/intel/llvm/pull/177#discussion_r290451286):
> > 
> > ```
> > namespace cl { namespace sycl {
> > class handler {
> >   template 
> >   __attribute__((sycl_kernel)) void sycl_kernel_function(KernelType 
> > KernelFuncObj) {
> > KernelFuncObj();
> >   }
> > };
> > }}
> > ```
> > 
> > Here is the list of SYCL device compiler expectations with regard to the 
> > function marked with `sycl_kernel` attribute.
> > - Function template with at least one parameter is expected. The 
> > compiler generates OpenCL kernel and uses first template parameter as 
> > unique name to the generated OpenCL kernel. Host application uses this 
> > unique name to invoke the OpenCL kernel generated for the 
> > `sycl_kernel_function` specialized by this name and KernelType (which might 
> > be a lambda type).
> > - Function must have at least one parameter. First parameter expected 
> > to be a function object type (named or unnamed i.e. lambda). Compiler uses 
> > function object type field to generate OpenCL kernel parameters.
> > 
> > Aaron, I hope it makes more sense now.
> > 
> > We don't plan in any use cases other than in SYCL standard library 
> > implementation mentioned above.
> > If I understand you concerns correctly, you want to be sure that clang 
> > prohibits other uses of this attribute, which are not intended. Right?
> > What is the best way to do this? Add more negative tests cases and make 
> > sure that clang generate error diagnostic messages?
> > 
> > If I understand you concerns correctly, you want to be sure that clang 
> > prohibits other uses of this attribute, which are not intended. Right?
> 
> But since it is an attribute to be used by SYCL 

[PATCH] D48680: Add missing visibility annotation for __base

2019-06-24 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

@ldionne Does Peter's example answer your questions?


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D48680



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


[PATCH] D63678: Fix test Clang :: Driver/cl-response-file.c for Solaris

2019-06-24 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


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

https://reviews.llvm.org/D63678



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


[PATCH] D63367: [clang-doc] Add basic support for templates and typedef

2019-06-24 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364222: [clang-doc] Add basic support for templates and 
typedef (authored by juliehockett, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63367?vs=205169=206282#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63367

Files:
  clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/Serialize.cpp
  clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
@@ -151,6 +151,8 @@
 
   EXPECT_EQ(Expected->TagType, Actual->TagType);
 
+  EXPECT_EQ(Expected->IsTypeDef, Actual->IsTypeDef);
+
   ASSERT_EQ(Expected->Members.size(), Actual->Members.size());
   for (size_t Idx = 0; Idx < Actual->Members.size(); ++Idx)
 EXPECT_EQ(Expected->Members[Idx], Actual->Members[Idx]);
Index: clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
@@ -80,6 +80,7 @@
 
   I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
+  I.IsTypeDef = true;
   I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
 
Index: clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
@@ -142,7 +142,15 @@
   E() {}
 protected:
   void ProtectedMethod();
-};)raw", 3, /*Public=*/false, Infos);
+};
+template 
+struct F {
+  void TemplateMethod();
+};
+template <>
+void F::TemplateMethod();
+typedef struct {} G;)raw",
+   7, /*Public=*/false, Infos);
 
   RecordInfo *E = InfoAsRecord(Infos[0].get());
   RecordInfo ExpectedE(EmptySID, "E");
@@ -176,6 +184,51 @@
   Method.IsMethod = true;
   ExpectedRecordWithMethod.ChildFunctions.emplace_back(std::move(Method));
   CheckRecordInfo(, RecordWithMethod);
+
+  RecordInfo *F = InfoAsRecord(Infos[3].get());
+  RecordInfo ExpectedF(EmptySID, "F");
+  ExpectedF.TagType = TagTypeKind::TTK_Struct;
+  ExpectedF.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+  CheckRecordInfo(, F);
+
+  RecordInfo *RecordWithTemplateMethod = InfoAsRecord(Infos[4].get());
+  RecordInfo ExpectedRecordWithTemplateMethod(EmptySID);
+  FunctionInfo TemplateMethod;
+  TemplateMethod.Name = "TemplateMethod";
+  TemplateMethod.Parent = Reference(EmptySID, "F", InfoType::IT_record);
+  TemplateMethod.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  TemplateMethod.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
+  TemplateMethod.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record);
+  TemplateMethod.Access = AccessSpecifier::AS_public;
+  TemplateMethod.IsMethod = true;
+  ExpectedRecordWithTemplateMethod.ChildFunctions.emplace_back(
+  std::move(TemplateMethod));
+  CheckRecordInfo(, RecordWithTemplateMethod);
+
+  RecordInfo *TemplatedRecord = InfoAsRecord(Infos[5].get());
+  RecordInfo ExpectedTemplatedRecord(EmptySID);
+  FunctionInfo SpecializedTemplateMethod;
+  SpecializedTemplateMethod.Name = "TemplateMethod";
+  SpecializedTemplateMethod.Parent =
+  Reference(EmptySID, "F", InfoType::IT_record);
+  SpecializedTemplateMethod.ReturnType =
+  TypeInfo(EmptySID, "void", InfoType::IT_default);
+  SpecializedTemplateMethod.Loc.emplace_back(0,
+ llvm::SmallString<16>{"test.cpp"});
+  SpecializedTemplateMethod.Namespace.emplace_back(EmptySID, "F",
+   InfoType::IT_record);
+  SpecializedTemplateMethod.Access = AccessSpecifier::AS_public;
+  SpecializedTemplateMethod.IsMethod = true;
+  ExpectedTemplatedRecord.ChildFunctions.emplace_back(
+  std::move(SpecializedTemplateMethod));
+  CheckRecordInfo(, TemplatedRecord);
+
+  RecordInfo *G = InfoAsRecord(Infos[6].get());
+  RecordInfo ExpectedG(EmptySID, "G");
+  ExpectedG.TagType = TagTypeKind::TTK_Struct;
+  ExpectedG.DefLoc = Location(0, 

[clang-tools-extra] r364222 - [clang-doc] Add basic support for templates and typedef

2019-06-24 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Mon Jun 24 12:31:02 2019
New Revision: 364222

URL: http://llvm.org/viewvc/llvm-project?rev=364222=rev
Log:
[clang-doc] Add basic support for templates and typedef

In serialize::parseBases(...), when a base record is a template
specialization, the specialization was used as the parent. It should be
the base template so there is only one file generated for this record.
When the specialized template is implicitly declared the reference USR
corresponded to the GlobalNamespace's USR, this will now be the base
template's USR.

More information about templates will be added later.

In serialize::emiInfo(RecorDecl*, ...), typedef records were not handled
and the name was empty. This is now handled and a IsTypeDef attribute is
added to RecordInfo struct.

In serialize::emitInfo(CXXMethodDecl*, ...), template specialization is
handled like in serialize::parseBases(...).

Bitcode writer and reader are modified to handle the new attribute of
RecordInfo.

Submitted on behalf of Diego Astiazarán (diegoaa...@gmail.com)
Differential Revision: https://reviews.llvm.org/D63367

Modified:
clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp

Modified: clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp?rev=364222=364221=364222=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp Mon Jun 24 12:31:02 2019
@@ -167,6 +167,8 @@ llvm::Error parseRecord(Record R, unsign
 return decodeRecord(R, I->Loc, Blob);
   case RECORD_TAG_TYPE:
 return decodeRecord(R, I->TagType, Blob);
+  case RECORD_IS_TYPE_DEF:
+return decodeRecord(R, I->IsTypeDef, Blob);
   default:
 return llvm::make_error(
 "Invalid field for RecordInfo.\n", llvm::inconvertibleErrorCode());

Modified: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=364222=364221=364222=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Mon Jun 24 12:31:02 2019
@@ -159,6 +159,7 @@ static const llvm::IndexedMaphttp://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.h?rev=364222=364221=364222=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.h (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.h Mon Jun 24 12:31:02 2019
@@ -102,6 +102,7 @@ enum RecordId {
   RECORD_DEFLOCATION,
   RECORD_LOCATION,
   RECORD_TAG_TYPE,
+  RECORD_IS_TYPE_DEF,
   REFERENCE_USR,
   REFERENCE_NAME,
   REFERENCE_TYPE,

Modified: clang-tools-extra/trunk/clang-doc/Representation.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Representation.h?rev=364222=364221=364222=diff
==
--- clang-tools-extra/trunk/clang-doc/Representation.h (original)
+++ clang-tools-extra/trunk/clang-doc/Representation.h Mon Jun 24 12:31:02 2019
@@ -241,6 +241,7 @@ struct RecordInfo : public SymbolInfo {
   TagTypeKind TagType = TagTypeKind::TTK_Struct; // Type of this record
  // (struct, class, union,
  // interface).
+  bool IsTypeDef = false; // Indicates if record was declared using typedef
   llvm::SmallVector
   Members; // List of info about record 
members.
   llvm::SmallVector Parents; // List of base/parent records

Modified: clang-tools-extra/trunk/clang-doc/Serialize.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Serialize.cpp?rev=364222=364221=364222=diff
==
--- clang-tools-extra/trunk/clang-doc/Serialize.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Serialize.cpp Mon Jun 24 12:31:02 2019
@@ -179,10 +179,9 @@ static SymbolID getUSRForDecl(const Decl
 }
 
 static RecordDecl *getDeclForType(const QualType ) {
-  auto *Ty = T->getAs();
-  if (!Ty)
-return nullptr;
-  return Ty->getDecl()->getDefinition();
+  if (const RecordDecl *D = T->getAsRecordDecl())
+return D->getDefinition();
+  return nullptr;
 

[PATCH] D63734: Update CODE_OWNERS.txt for clang-doc

2019-06-24 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added a reviewer: klimek.
juliehockett added a project: clang-tools-extra.

https://reviews.llvm.org/D63734

Files:
  clang-tools-extra/CODE_OWNERS.TXT


Index: clang-tools-extra/CODE_OWNERS.TXT
===
--- clang-tools-extra/CODE_OWNERS.TXT
+++ clang-tools-extra/CODE_OWNERS.TXT
@@ -19,3 +19,7 @@
 N: Alexander Kornienko
 E: ale...@google.com
 D: clang-tidy
+
+N: Julie Hockett
+E: juliehock...@google.com
+D: clang-doc


Index: clang-tools-extra/CODE_OWNERS.TXT
===
--- clang-tools-extra/CODE_OWNERS.TXT
+++ clang-tools-extra/CODE_OWNERS.TXT
@@ -19,3 +19,7 @@
 N: Alexander Kornienko
 E: ale...@google.com
 D: clang-tidy
+
+N: Julie Hockett
+E: juliehock...@google.com
+D: clang-doc
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63180: [clang-doc] Adds HTML generator

2019-06-24 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

I got to the 'genHTML' functions and I decided that this general approach is 
not great.

What if we have a baby internal representation of an HTML tree, generate 
instances of that, and then implement a render method on that (preferably one 
that handles indentation or would have the ability to do so soon).

I also think we could split this up and support only a subset of the comment 
types at first to reduce the review load.




Comment at: clang-tools-extra/clang-doc/Generators.cpp:60-71
+std::string genReferenceList(const llvm::SmallVectorImpl ) {
+  std::string Buffer;
+  llvm::raw_string_ostream Stream(Buffer);
+  bool First = true;
+  for (const auto  : Refs) {
+if (!First)
+  Stream << ", ";

This seems to be displaying a list in a particular way. Mind adding a comment 
about where this is used?



Comment at: clang-tools-extra/clang-doc/Generators.cpp:65
+  for (const auto  : Refs) {
+if (!First)
+  Stream << ", ";

You can just use ` != Refs.begin()` or ` != ()` and then you 
don't have to keep any local state and its clear when that condition would be 
true/false.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:25
+
+std::string genTag(const Twine , const Twine ) {
+  return "<" + Tag.str() + ">" + Text.str() + "";

This can also be a Twine



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:33-35
+void writeLine(const Twine , raw_ostream ) {
+  OS << genTag(Text, "p") << "\n";
+}

I'm not familiar with HTML.  What does this '' do?



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:66
+OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+  } else if (I.Kind == "TParamCommandComment") {
+std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";

Instead of repeating code add an "||" case to the above.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:67-68
+  } else if (I.Kind == "TParamCommandComment") {
+std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
+OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+  } else if (I.Kind == "VerbatimBlockComment") {

Instead of making a local `std::string` you can first write the emphasis then 
decide wheater or not to output the direction, and then output the newlines 
unconditionally.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:72-77
+  } else if (I.Kind == "VerbatimBlockLineComment") {
+OS << I.Text;
+writeNewLine(OS);
+  } else if (I.Kind == "VerbatimLineComment") {
+OS << I.Text;
+writeNewLine(OS);

Dedup these.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:81-84
+std::string Buffer;
+llvm::raw_string_ostream Attrs(Buffer);
+for (unsigned Idx = 0; Idx < I.AttrKeys.size(); ++Idx)
+  Attrs << " \"" << I.AttrKeys[Idx] << "=" << I.AttrValues[Idx] << "\"";

I don't see the need for an intermediete ostream. 

```
OS << "<" << I.Name;
for (...)
  OS << ...;
writeLine(I.SelfClosing ? ..., OS);
```

would work fine and be more efficient.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:86
+
+std::string CloseTag = I.SelfClosing ? "/>" : ">";
+writeLine("<" + I.Name + Attrs.str() + CloseTag, OS);

This can be a StringRef



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:106-107
+
+  std::string Buffer;
+  llvm::raw_string_ostream Members(Buffer);
+  if (!I.Members.empty())

This is a generally bad pattern.


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

https://reviews.llvm.org/D63180



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


[PATCH] D61809: [BPF] Preserve debuginfo array/union/struct type/access index

2019-06-24 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song marked an inline comment as not done.
yonghong-song added a comment.

@eli.friedman I removed the usage of astcontext getParents() stuff. Instead, I 
mark the region upfront. I also added the intrinsic 
__builtin_preserve_access_index() into clang
lang extention doc. Could you take a look at new patch? Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D61809



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


[PATCH] D61809: [BPF] Preserve debuginfo array/union/struct type/access index

2019-06-24 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 206274.
yonghong-song added a comment.

do not use ctx.getParents() to check whether a GEP candidate inside a 
preserve_access_index. instead, mark the region upfront. Add the new clang 
intrinsic into the language doc.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61809

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/Builtins.def
  lib/CodeGen/CGBuilder.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaChecking.cpp
  test/CodeGen/bpf-preserve-access-index-2.c
  test/CodeGen/bpf-preserve-access-index.c

Index: test/CodeGen/bpf-preserve-access-index.c
===
--- /dev/null
+++ test/CodeGen/bpf-preserve-access-index.c
@@ -0,0 +1,28 @@
+// RUN: %clang %s -target bpfeb -x c -emit-llvm -S -g -O2 -o - | FileCheck --check-prefix=CHECK %s
+// RUN: %clang %s -target bpfel -x c -emit-llvm -S -g -O2 -o - | FileCheck --check-prefix=CHECK %s
+// RUN: %clang %s -target bpfeb -x c -emit-llvm -S -O2 -o - | FileCheck --check-prefix=CHECK-NODBG %s
+// RUN: %clang %s -target bpfel -x c -emit-llvm -S -O2 -o - | FileCheck --check-prefix=CHECK-NODBG %s
+
+struct t {
+  int i:1;
+  int j:2;
+  union {
+   int a;
+   int b;
+  } c[4];
+};
+
+#define _(x) (__builtin_preserve_access_index(x))
+
+void *test(struct t *arg) {
+  return _(>c[3].b);
+}
+
+// CHECK: llvm.preserve.struct.access.index
+// CHECK: llvm.preserve.array.access.index
+// CHECK: llvm.preserve.union.access.index
+// CHECK-NOT: __builtin_preserve_access_index
+// CHECK-NODBG-NOT: llvm.preserve.struct.access.index
+// CHECK-NODBG-NOT: llvm.preserve.array.access.index
+// CHECK-NODBG-NOT: llvm.preserve.union.access.index
+// CHECK-NODBG-NOT: __builtin_preserve_access_index
Index: test/CodeGen/bpf-preserve-access-index-2.c
===
--- /dev/null
+++ test/CodeGen/bpf-preserve-access-index-2.c
@@ -0,0 +1,22 @@
+// RUN: %clang %s -target bpfeb -x c -emit-llvm -S -g -O2 -o - | FileCheck %s
+// RUN: %clang %s -target bpfel -x c -emit-llvm -S -g -O2 -o - | FileCheck %s
+
+struct t {
+  int i:1;
+  int j:2;
+  union {
+   int a;
+   int b;
+  } c[4];
+};
+
+#define _(x) (x)
+
+void *test(struct t *arg) {
+  return _(>c[3].b);
+}
+
+// CHECK-NOT: llvm.preserve.struct.access.index
+// CHECK-NOT: llvm.preserve.array.access.index
+// CHECK-NOT: llvm.preserve.union.access.index
+// CHECK-NOT: __builtin_preserve_access_index
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -191,6 +191,16 @@
   return false;
 }
 
+/// Check the number of arguments, and set the result type to
+/// the argument type.
+static bool SemaBuiltinPreserveAI(Sema , CallExpr *TheCall) {
+  if (checkArgCount(S, TheCall, 1))
+return true;
+
+  TheCall->setType(TheCall->getArg(0)->getType());
+  return false;
+}
+
 static bool SemaBuiltinOverflow(Sema , CallExpr *TheCall) {
   if (checkArgCount(S, TheCall, 3))
 return true;
@@ -1409,6 +1419,10 @@
 TheCall->setType(Context.IntTy);
 break;
   }
+  case Builtin::BI__builtin_preserve_access_index:
+if (SemaBuiltinPreserveAI(*this, TheCall))
+  return ExprError();
+break;
   case Builtin::BI__builtin_call_with_static_chain:
 if (SemaBuiltinCallWithStaticChain(*this, TheCall))
   return ExprError();
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -480,6 +480,10 @@
   /// finally block or filter expression.
   bool IsOutlinedSEHHelper = false;
 
+  /// True if CodeGen currently emits code inside presereved access index
+  /// region.
+  bool IsInPreservedAIRegion = false;
+
   const CodeGen::CGBlockInfo *BlockInfo = nullptr;
   llvm::Value *BlockPointer = nullptr;
 
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -25,6 +25,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/NSAPI.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringExtras.h"
@@ -3418,8 +3419,20 @@
   CharUnits eltAlign =
 getArrayElementAlign(addr.getAlignment(), indices.back(), eltSize);
 
-  llvm::Value *eltPtr = emitArraySubscriptGEP(
-  CGF, addr.getPointer(), indices, inbounds, signedIndices, loc, name);
+  llvm::Value *eltPtr;
+  auto LastIndex = dyn_cast(indices.back());
+  if (!CGF.IsInPreservedAIRegion || !LastIndex) {
+eltPtr = emitArraySubscriptGEP(
+CGF, addr.getPointer(), indices, inbounds, signedIndices,
+loc, name);
+  } else {
+// Remember the original array 

[PATCH] D62738: [HIP] Support device_shadow variable

2019-06-24 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: include/clang/Basic/Attr.td:955
+def CUDADeviceShadow : InheritableAttr {
+  let Spellings = [GNU<"device_shadow">, Declspec<"__device_shadow__">];
+  let Subjects = SubjectList<[Var]>;

tra wrote:
> In light of the details you've provided below, perhaps this needs a better 
> name. I've suggested `__device_shadow__` without being aware of what exactly 
> it's supposed to do in HIP.  
> Perhaps something like `__hip_device_shadow__` or `__hip_pinned_shadow` ? 
> Naming is hard. :-)
I think `__hip_pinned_shadow__` best describes such variables. I will update 
the patch to adopt it.


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

https://reviews.llvm.org/D62738



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


[PATCH] D63623: [clang-tidy] Add a check on expected return values of posix functions (except posix_openpt) in Android module.

2019-06-24 Thread Jian Cai via Phabricator via cfe-commits
jcai19 marked 10 inline comments as done.
jcai19 added inline comments.



Comment at: clang-tools-extra/clang-tidy/android/PosixReturnCheck.cpp:23
+  binaryOperator(
+  hasOperatorName("<"),
+  hasLHS(callExpr(callee(functionDecl(matchesName("^::posix_"), 
unless(hasName("posix_openpt")),

george.burgess.iv wrote:
> should we also try to catch `<= ${negative_value}` (or `< ${negative_value}`)?
Sounds good. Will update the patch to catch these two cases as well.



Comment at: clang-tools-extra/clang-tidy/android/PosixReturnCheck.cpp:29
+  binaryOperator(
+  hasOperatorName("=="),
+  hasLHS(callExpr(callee(functionDecl(matchesName("^::posix_"), 
unless(hasName("posix_openpt")),

george.burgess.iv wrote:
> similarly, should we complain about `!= ${negative_value}`?
Sounds good. Will update the patch to catch these additional cases as well.



Comment at: clang-tools-extra/clang-tidy/android/PosixReturnCheck.cpp:39
+  const auto  = *Result.Nodes.getNodeAs("binop");
+  diag(BinOp.getOperatorLoc(), "posix functions (except posix_openpt) never 
return negative values");
+}

george.burgess.iv wrote:
> would it be helpful to add fixits for simple cases? e.g. we can probably 
> offer to replace `posix_whatever() < 0` with `posix_whatever() > 0` or `!= 0`
While this fix is handy, I am not sure whether it will be safe enough under all 
circumstances. For example, is it possible in the code block following the 
check, the program calls another POSIX function and alter the errno before its 
value it checked? In that case, maybe the proper fix should be something as 
follows and fixing it by changing the binary operator may obscure it:

int ret = posix_whatever();
if (ret != 0)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63623



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


[PATCH] D63623: [clang-tidy] Add a check on expected return values of posix functions (except posix_openpt) in Android module.

2019-06-24 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D63623#1552716 , @jcai19 wrote:

> In D63623#1552679 , @lebedev.ri 
> wrote:
>
> > Why is this in android module?
> >  Is that android-specific behavior, or posix?
>
>
> I implemented it for Andriod as requested, but it would be completely fine to 
> move it if it is better to place the check at a different location. Where do 
> you suggest we should move this check to? Thanks.


Either `misc` or `bugprone` or a new `posix` module.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63623



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


[libunwind] r364217 - Merging r360861:

2019-06-24 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Mon Jun 24 11:40:58 2019
New Revision: 364217

URL: http://llvm.org/viewvc/llvm-project?rev=364217=rev
Log:
Merging r360861:


r360861 | mstorsjo | 2019-05-15 23:49:13 -0700 (Wed, 15 May 2019) | 13 lines

[PPC64][libunwind] Fix r2 not properly restored

This change makes each unwind step inspect the instruction at the
return address and, if needed, read r2 from its saved location and
modify the context appropriately.

The unwind logic is able to handle both ELFv1 and ELFv2 stacks.

Reported by Bug 41050

Patch by Leandro Lupori!

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


Modified:
libunwind/branches/release_80/src/DwarfInstructions.hpp
libunwind/branches/release_80/src/assembly.h
libunwind/branches/release_80/test/lit.cfg

Modified: libunwind/branches/release_80/src/DwarfInstructions.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/branches/release_80/src/DwarfInstructions.hpp?rev=364217=364216=364217=diff
==
--- libunwind/branches/release_80/src/DwarfInstructions.hpp (original)
+++ libunwind/branches/release_80/src/DwarfInstructions.hpp Mon Jun 24 11:40:58 
2019
@@ -234,6 +234,31 @@ int DwarfInstructions::stepWithDwa
   }
 #endif
 
+#if defined(_LIBUNWIND_TARGET_PPC64)
+#define PPC64_ELFV1_R2_LOAD_INST_ENCODING 0xe8410028u // ld r2,40(r1)
+#define PPC64_ELFV1_R2_OFFSET 40
+#define PPC64_ELFV2_R2_LOAD_INST_ENCODING 0xe8410018u // ld r2,24(r1)
+#define PPC64_ELFV2_R2_OFFSET 24
+  // If the instruction at return address is a TOC (r2) restore,
+  // then r2 was saved and needs to be restored.
+  // ELFv2 ABI specifies that the TOC Pointer must be saved at SP + 24,
+  // while in ELFv1 ABI it is saved at SP + 40.
+  if (R::getArch() == REGISTERS_PPC64 && returnAddress != 0) {
+pint_t sp = newRegisters.getRegister(UNW_REG_SP);
+pint_t r2 = 0;
+switch (addressSpace.get32(returnAddress)) {
+case PPC64_ELFV1_R2_LOAD_INST_ENCODING:
+  r2 = addressSpace.get64(sp + PPC64_ELFV1_R2_OFFSET);
+  break;
+case PPC64_ELFV2_R2_LOAD_INST_ENCODING:
+  r2 = addressSpace.get64(sp + PPC64_ELFV2_R2_OFFSET);
+  break;
+}
+if (r2)
+  newRegisters.setRegister(UNW_PPC64_R2, r2);
+  }
+#endif
+
   // Return address is address after call site instruction, so setting IP 
to
   // that does simualates a return.
   newRegisters.setIP(returnAddress);

Modified: libunwind/branches/release_80/src/assembly.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/branches/release_80/src/assembly.h?rev=364217=364216=364217=diff
==
--- libunwind/branches/release_80/src/assembly.h (original)
+++ libunwind/branches/release_80/src/assembly.h Mon Jun 24 11:40:58 2019
@@ -35,6 +35,20 @@
 #define SEPARATOR ;
 #endif
 
+#if defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1)
+#define PPC64_OPD1 .section .opd,"aw",@progbits SEPARATOR
+#define PPC64_OPD2 SEPARATOR \
+  .p2align 3 SEPARATOR \
+  .quad .Lfunc_begin0 SEPARATOR \
+  .quad .TOC.@tocbase SEPARATOR \
+  .quad 0 SEPARATOR \
+  .text SEPARATOR \
+.Lfunc_begin0:
+#else
+#define PPC64_OPD1
+#define PPC64_OPD2
+#endif
+
 #define GLUE2(a, b) a ## b
 #define GLUE(a, b) GLUE2(a, b)
 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
@@ -95,7 +109,9 @@
   .globl SYMBOL_NAME(name) SEPARATOR  \
   EXPORT_SYMBOL(name) SEPARATOR   \
   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
-  SYMBOL_NAME(name):
+  PPC64_OPD1  \
+  SYMBOL_NAME(name):  \
+  PPC64_OPD2
 
 #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name)   \
   .globl SYMBOL_NAME(name) SEPARATOR  \

Modified: libunwind/branches/release_80/test/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/branches/release_80/test/lit.cfg?rev=364217=364216=364217=diff
==
--- libunwind/branches/release_80/test/lit.cfg (original)
+++ libunwind/branches/release_80/test/lit.cfg Mon Jun 24 11:40:58 2019
@@ -23,6 +23,9 @@ config.suffixes = ['.cpp', '.s']
 # test_source_root: The root path where tests are located.
 config.test_source_root = os.path.dirname(__file__)
 
+# needed to test libunwind with code that throws exceptions
+config.enable_exceptions = True
+
 # Infer the libcxx_test_source_root for configuration import.
 # If libcxx_source_root isn't specified in the config, assume that the libcxx
 # and libunwind source directories are sibling directories.


___
cfe-commits mailing 

[PATCH] D63623: [clang-tidy] Add a check on expected return values of posix functions (except posix_openpt) in Android module.

2019-06-24 Thread Jian Cai via Phabricator via cfe-commits
jcai19 updated this revision to Diff 206273.
jcai19 added a comment.

Fix typos and formatting issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63623

Files:
  clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/clang-tidy/android/PosixReturnCheck.cpp
  clang-tools-extra/clang-tidy/android/PosixReturnCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/android-posix-return.rst
  clang-tools-extra/test/clang-tidy/android-posix-return.cpp

Index: clang-tools-extra/test/clang-tidy/android-posix-return.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/android-posix-return.cpp
@@ -0,0 +1,89 @@
+// RUN: %check_clang_tidy %s android-posix-return %t
+
+#define NULL nullptr
+#define ZERO 0
+#define NEGATIVE_ONE -1
+
+typedef long off_t;
+typedef int size_t;
+typedef int pid_t;
+typedef struct __posix_spawn_file_actions* posix_spawn_file_actions_t;
+typedef struct __posix_spawnattr* posix_spawnattr_t;
+
+extern "C" int posix_fadvise(int fd, off_t offset, off_t len, int advice);
+extern "C" int posix_fallocate(int fd, off_t offset, off_t len);
+extern "C" int posix_madvise(void *addr, size_t len, int advice);
+extern "C" int posix_memalign(void **memptr, size_t alignment, size_t size);
+extern "C" int posix_openpt(int flags);
+extern "C" int posix_spawn(pid_t *pid, const char *path,
+const posix_spawn_file_actions_t *file_actions,
+const posix_spawnattr_t *attrp,
+char *const argv[], char *const envp[]);
+extern "C" int posix_spawnp(pid_t *pid, const char *file,
+ const posix_spawn_file_actions_t *file_actions,
+ const posix_spawnattr_t *attrp,
+ char *const argv[], char *const envp[]);
+
+void warningLtZero() {
+  if (posix_fadvise(0, 0, 0, 0) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (posix_fallocate(0, 0, 0) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning:
+  if (posix_madvise(NULL, 0, 0) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (posix_memalign(NULL, 0, 0) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning:
+  if (posix_spawn(NULL, NULL, NULL, NULL, {NULL}, {NULL}) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:59: warning:
+  if (posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:60: warning:
+}
+
+void warningEqualsNegative() {
+  if (posix_fadvise(0, 0, 0, 0) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (posix_fallocate(0, 0, 0) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning:
+  if (posix_madvise(NULL, 0, 0) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (posix_memalign(NULL, 0, 0) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning:
+  if (posix_spawn(NULL, NULL, NULL, NULL, {NULL}, {NULL}) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:59: warning:
+  if (posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:60: warning:
+}
+
+void WarningWithMacro() {
+  if (posix_fadvise(0, 0, 0, 0) < ZERO) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (posix_fadvise(0, 0, 0, 0) == NEGATIVE_ONE) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+}
+
+void noWarning() {
+  if (posix_openpt(0) < 0) {}
+  if (posix_openpt(0) == -1) {}
+  if (posix_fadvise(0, 0, 0, 0) >= 0) {}
+  if (posix_fadvise(0, 0, 0, 0) == 1) {}
+}
+
+namespace i {
+int posix_fadvise(int fd, off_t offset, off_t len, int advice);
+
+void noWarning() {
+  if (posix_fadvise(0, 0, 0, 0) < 0) {}
+  if (posix_fadvise(0, 0, 0, 0) == -1) {}
+}
+
+} // namespace i
+
+class G {
+ public:
+  int posix_fadvise(int fd, off_t offset, off_t len, int advice);
+
+  void noWarning() {
+if (posix_fadvise(0, 0, 0, 0) < 0) {}
+if (posix_fadvise(0, 0, 0, 0) == -1) {}
+  }
+};
Index: clang-tools-extra/docs/clang-tidy/checks/android-posix-return.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/android-posix-return.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - android-posix-return
+
+android-posix-return
+
+
+Checks if any calls to POSIX functions (except ``posix_openpt``) expect negative
+return values. These functions return either ``0`` on success or an ``errno`` on failure,
+which is positive only.
+
+Example buggy usage looks like:
+
+.. code-block:: c
+
+  if (posix_fadvise(...) < 0) {
+
+This will never happen as the return value is always non-negative. A simple fix could be:
+
+.. code-block:: c
+
+  int ret = posix_fadvise(...);
+  if (ret != 0) ...
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- 

[PATCH] D63276: [AST] Add FunctionDecl::getParametersSourceRange()

2019-06-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/Decl.h:2331
+  /// Attempt to compute an informative source range covering the
+  /// function parameters. This omits the ellipsis of a variadic function.
+  SourceRange getParametersSourceRange() const;

Why does this omit the ellipsis? It's part of the parameter list and it seems 
like a strange design decision to leave that out of the source range for the 
parameter list.



Comment at: clang/lib/AST/Decl.cpp:3305
+SourceRange FunctionDecl::getParametersSourceRange() const {
+  auto NP = getNumParams();
+  if (NP == 0)

Please don't use `auto` here (or below); the type is not spelled out in the 
initialization.



Comment at: clang/unittests/AST/SourceLocationTest.cpp:676
+}
+
 TEST(CXXMethodDecl, CXXMethodDeclWithThrowSpecification) {

I'd like to see tests that include an ellipsis, as well as tests that use the 
preprocessor in creative ways. e.g.,
```
#define FOO  int a, int b

void func(FOO);
void bar(float f, FOO, float g);
void baz(FOO, float f);
void quux(float f, FOO);
```
Also, tests for member functions (both static and instance functions) and 
parameters with leading attributes would be useful. e.g.,
```
void func([[]] int *i);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63276



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


[PATCH] D63518: WIP BitStream reader: propagate errors

2019-06-24 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

`check-clang` now passes all tests, so the patch is pretty much ready to 
review. I'll get started on the other parts of LLVM that use this API.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63518



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


[PATCH] D62970: [clang-doc] De-duplicate comments and locations

2019-06-24 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

LGTM




Comment at: clang-tools-extra/clang-doc/Representation.h:66
+
+  bool operator<(const CommentInfo ) const {
+auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,

We should be explicit about what we intend to happen here. Do we just want a 
total ordering of any kind? Do we want some things to be "more important" than 
others? For instance because the ordering is lexicographical here Kind is more 
important than Text which is more important than Name etc...

If the intent is just to have any total order state so at the top and why we 
need a total ordering (for instance to have an std::set/std::map of these 
things or we need to sort them, etc...)



Comment at: clang-tools-extra/clang-doc/Representation.h:186
 
+  bool operator<(const Location ) const {
+return std::tie(LineNumber, Filename) <

Same comment here.


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

https://reviews.llvm.org/D62970



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


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked an inline comment as done.
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:123
 state = state->BindExpr(B, LCtx, Result);
   }
 

I have seen we are producing tons of Unknowns and I am still not sure where 
they go, but even if I remove that condition these Unknowns will not shown up 
in the ExplodedGraph. I believe that should be the correct behavior.


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

https://reviews.llvm.org/D63720



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


[PATCH] D62738: [HIP] Support device_shadow variable

2019-06-24 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: include/clang/Basic/Attr.td:954
 
+def CUDADeviceShadow : InheritableAttr {
+  let Spellings = [GNU<"device_shadow">, Declspec<"__device_shadow__">];

`HIPDeviceShadow` ?



Comment at: include/clang/Basic/Attr.td:955
+def CUDADeviceShadow : InheritableAttr {
+  let Spellings = [GNU<"device_shadow">, Declspec<"__device_shadow__">];
+  let Subjects = SubjectList<[Var]>;

In light of the details you've provided below, perhaps this needs a better 
name. I've suggested `__device_shadow__` without being aware of what exactly 
it's supposed to do in HIP.  
Perhaps something like `__hip_device_shadow__` or `__hip_pinned_shadow` ? 
Naming is hard. :-)



Comment at: include/clang/Basic/Attr.td:957
+  let Subjects = SubjectList<[Var]>;
+  let LangOpts = [CUDA];
+  let Documentation = [DeviceShadowDocs];

Shis should probably be `[HIP]` now, too.



Comment at: include/clang/Basic/AttrDocs.td:4164-4171
+The GNU style attribute __attribute__((device_shadow)) or MSVC style attribute
+__declspec(device_shadow) can be added to the definition of a global variable
+to indicate it is a HIP device shadow variable. A device shadow variable can
+be accessed on both device side and host side. It has external linkage and is
+not initialized on device side. It has internal linkage and is initialized by
+the initializer on host side.
+

yaxunl wrote:
> tra wrote:
> > just `device shadow variable` would do. It's no longer, generally speaking, 
> > HIP-specific. :-)
> > 
> > Only address and size of such variables should be used on device side.
> > 
> > I'd rephrase the use constraint. Currently it's `!(CUDA || !CUDA)` which is 
> > always false.
> > `Currently enabled for HIP only.` would be closer to reality.
> > 
> If only address and size of such variables should be used on device side, 
> such variables will not be very useful.
> 
> To implement texture reference, we need to be able to load the device side 
> shadow variable. In general, it is desirable to load and store device side 
> shadow variables, since users have no other way to synch with the 
> corresponding host variable in device code.
> 
> This is different from host side shadow variable. On host side, users can use 
> hipMemcpyToSymbol and hipMemcpyFromSymbol to force synchronization between 
> the host side shadow variable and the corresponding device variable.
> 
> Therefore the implementation of the device side shadow variable requires 
> special handling in HIP runtime. Basically HIP runtime needs to pin the host 
> variable and use it to resolve the device side shadow variable (as an 
> undefined elf symbol). This way, the host variable and device side shadow 
> variable are sharing the same memory. This is also why it is HIP specific 
> since CUDA runtime may not have such handling.
> 
> 
Thank you for providing the details. This use case is sufficiently different 
from the more general purpose reverse-shadow-var I had in mind.




Comment at: lib/CodeGen/CodeGenModule.cpp:3775
+  // left undefined.
+  bool IsHIPDeviceShadowVar = getLangOpts().HIP && getLangOpts().CUDAIsDevice 
&&
+  D->hasAttr();

yaxunl wrote:
> tra wrote:
> > `IsDeviceShadowVar`. We may want to rename `IsCUDAShadowVar` to 
> > `IsHostShadowVar` to be consistent.
> > 
> > This got me thinking. Conceptually we have two different things going on 
> > here.
> > * where do we place the real variable
> > * whether we need to create a shadow on the other end.
> > 
> > Currently `__device__`, `__constant__` and `__shared__` act as both.
> > This patch implements the same `make a shadow on the other side`, only in 
> > the opposite direction.
> > 
> > Perhaps the right thing to do is to push the patch even further and make it 
> > into a `__shadow_variable__` which will be responsible for creating the 
> > other side shadow and would work in both directions.
> > 
> > We can then assign implicit `__shadow_variable__` attribute to the 
> > device-side vars to preserve current behavior and it will work for your 
> > purposes two. We will also gain ability to create device-side variables w/o 
> > host-side shadows, if we need to.
> > 
> > I guess in the end it would be this patch + a bit of refactoring/collapsing 
> > of `IsCUDAShadowVar` logic.
> Do we really want to introduce a generic `__shadow_variable__` for device 
> variables? It has little use but complicates AST of device variables 
> unnecessarily. First it bring no new functionality since device variables are 
> already shadowed by default. Second since unused shadow variable is 
> eliminated automatically due to their internal linkage, disable shadowing 
> will not save memory in host binary.
There's currently no specific use case for it in CUDA and HIP's use case also 
does not quite fit this, so 

[PATCH] D63288: [clang-tidy] Generalize TransformerClangTidyCheck to take a rule generator.

2019-06-24 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp:33
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)) {
+  assert(llvm::all_of(Rule.Cases, [](const RewriteRule::Case ) {

gribozavr wrote:
> ymandel wrote:
> > gribozavr wrote:
> > > Can we dispatch to the other constructor?
> > I think not, but please correct me if I'm wrong (and clearly I should add a 
> > comment explaining this): in order to get meaningful results from 
> > `getLangOpts` and `Options`, we need the `ClangTidyCheck()` constructor to 
> > have been called. If we were to dispatch, it would look like:
> > ```
> >  : TransformerClangTidyCheck(MakeRule(getLangOpts(), Options), Name, 
> > Context) {}
> > ```
> > 
> > which, if I understand correctly, means that `MakeRule` will access that 
> > data _before_ the check object is properly initialized.
> > 
> > That said, I can factor out the assertion into a method to avoid the 
> > redundancy.  WDYT?
> You're right. I don't think it is necessary to factor out the assertion -- up 
> to you.
Decided not to factor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63288



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


[PATCH] D63288: [clang-tidy] Generalize TransformerClangTidyCheck to take a rule generator.

2019-06-24 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 206258.
ymandel marked 4 inline comments as done.
ymandel added a comment.

Adjust comments in test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63288

Files:
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
  clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
@@ -18,16 +18,16 @@
 namespace tidy {
 namespace utils {
 namespace {
+using tooling::change;
 using tooling::RewriteRule;
+using tooling::text;
+using tooling::stencil::cat;
 
 // Invert the code of an if-statement, while maintaining its semantics.
 RewriteRule invertIf() {
   using namespace ::clang::ast_matchers;
-  using tooling::change;
   using tooling::node;
   using tooling::statement;
-  using tooling::text;
-  using tooling::stencil::cat;
 
   StringRef C = "C", T = "T", E = "E";
   RewriteRule Rule = tooling::makeRule(
@@ -65,6 +65,63 @@
   )";
   EXPECT_EQ(Expected, test::runCheckOnCode(Input));
 }
+
+// A trivial rewrite rule generator that requires C99 code to operate.
+Optional needsC99(const LangOptions ,
+   const ClangTidyCheck::OptionsView ) {
+  if (!LangOpts.C99)
+return None;
+  return tooling::makeRule(clang::ast_matchers::functionDecl(),
+   change(cat("void nothing()")), text("no message"));
+}
+
+class NeedsC99Check : public TransformerClangTidyCheck {
+public:
+  NeedsC99Check(StringRef Name, ClangTidyContext *Context)
+  : TransformerClangTidyCheck(needsC99, Name, Context) {}
+};
+
+// Pass a C++ source file and expect no change, since the check requires `C99`
+// support to fire.
+TEST(TransformerClangTidyCheckTest, DisableByLang) {
+  // FIXME: We should be testing both the positive and negative case. However,
+  // as far as I can tell, all of the LangOpts are always set to false, so I
+  // have been unable to test the positive case (that is, where the
+  // `LangOpts.C99` is true).
+  const std::string Input = "void log(int);";
+  EXPECT_EQ(Input, test::runCheckOnCode(Input));
+}
+
+// A trivial rewrite rule generator that checks config options.
+Optional noSkip(const LangOptions ,
+ const ClangTidyCheck::OptionsView ) {
+  if (Options.get("Skip", "false") == "true")
+return None;
+  return tooling::makeRule(clang::ast_matchers::functionDecl(),
+   change(cat("void nothing()")), text("no message"));
+}
+
+class ConfigurableCheck : public TransformerClangTidyCheck {
+public:
+  ConfigurableCheck(StringRef Name, ClangTidyContext *Context)
+  : TransformerClangTidyCheck(noSkip, Name, Context) {}
+};
+
+// Tests operation with config option "Skip" set to true and false.
+TEST(TransformerClangTidyCheckTest, DisableByConfig) {
+  const std::string Input = "void log(int);";
+  const std::string Expected = "void nothing();";
+  ClangTidyOptions Options;
+
+  Options.CheckOptions["test-check-0.Skip"] = "true";
+  EXPECT_EQ(Input, test::runCheckOnCode(
+   Input, nullptr, "input.cc", None, Options));
+
+  Options.CheckOptions["test-check-0.Skip"] = "false";
+  EXPECT_EQ(Expected, test::runCheckOnCode(
+  Input, nullptr, "input.cc", None, Options));
+}
+
 } // namespace
 } // namespace utils
 } // namespace tidy
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -31,19 +31,32 @@
 // };
 class TransformerClangTidyCheck : public ClangTidyCheck {
 public:
-  // All cases in \p R must have a non-null \c Explanation, even though \c
-  // Explanation is optional for RewriteRule in general. Because the primary
-  // purpose of clang-tidy checks is to provide users with diagnostics, we
-  // assume that a missing explanation is a bug.  If no explanation is desired,
-  // indicate that explicitly (for example, by passing `text("no explanation")`
-  //  to `makeRule` as the `Explanation` argument).
+  // \p MakeRule generates the rewrite rule to be used by the check, based on
+  // the given language and clang-tidy options. It can return \c None to handle
+  // cases where the options disable the check.
+  //
+  // All cases in the rule generated by \p MakeRule must have a non-null \c
+  // Explanation, even though \c Explanation is optional for RewriteRule in
+  // general. Because the primary purpose of clang-tidy checks is to 

[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:8668
+
+bool ASTImporter::ImportPathTy::hasCycleAtBack() {
+  return Aux[Nodes.back()] > 1;

a_sidorin wrote:
> const?
Thanks! I made to be const.



Comment at: clang/lib/AST/ASTImporter.cpp:7840
+  // Push FromD to the stack, and remove that when we return.
+  ImportPathBuilder PathRAII(ImportPath, FromD);
 

balazske wrote:
> It is possible to use the `make_scope_exit` instead, this results in less 
> written code.
Thanks! Changed to use that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375



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


[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:7892
 
-// Error encountered for the first time.
-assert(!getImportDeclErrorIfAny(FromD) &&

We may set up an error multiple times now, but the error should be the same, 
this is handled in `setImportDeclError`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375



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


[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 206254.
martong marked 5 inline comments as done.
martong added a comment.

- Use make_scope_exit
- Make hasCycleAtBack const


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -358,6 +358,106 @@
   EXPECT_EQ(0U, count);
 }
 
+struct ImportPath : ASTImporterOptionSpecificTestBase {
+  Decl *FromTU;
+  FunctionDecl *D0, *D1, *D2;
+  ImportPath() {
+FromTU = getTuDecl("void f(); void f(); void f();", Lang_CXX);
+auto Pattern = functionDecl(hasName("f"));
+D0 = FirstDeclMatcher().match(FromTU, Pattern);
+D2 = LastDeclMatcher().match(FromTU, Pattern);
+D1 = D2->getPreviousDecl();
+  }
+};
+
+TEST_P(ImportPath, Push) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  EXPECT_FALSE(path.hasCycleAtBack());
+}
+
+TEST_P(ImportPath, SmallCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  path.pop();
+  EXPECT_FALSE(path.hasCycleAtBack());
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+}
+
+TEST_P(ImportPath, GetSmallCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 2);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D0);
+}
+
+TEST_P(ImportPath, GetCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D1);
+  path.push(D2);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 4);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D2);
+  EXPECT_EQ(Res[2], D1);
+  EXPECT_EQ(Res[3], D0);
+}
+
+TEST_P(ImportPath, CycleAfterCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D1);
+  path.push(D0);
+  path.push(D1);
+  path.push(D2);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 4);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D2);
+  EXPECT_EQ(Res[2], D1);
+  EXPECT_EQ(Res[3], D0);
+
+  path.pop();
+  path.pop();
+  path.pop();
+  EXPECT_TRUE(path.hasCycleAtBack());
+  i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 3);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D1);
+  EXPECT_EQ(Res[2], D0);
+
+  path.pop();
+  EXPECT_FALSE(path.hasCycleAtBack());
+}
+
 TEST_P(ImportExpr, ImportStringLiteral) {
   MatchVerifier Verifier;
   testImport(
@@ -4547,12 +4647,6 @@
   EXPECT_EQ(*Res.begin(), A);
 }
 
-INSTANTIATE_TEST_CASE_P(ParameterizedTests, DeclContextTest,
-::testing::Values(ArgVector()), );
-
-INSTANTIATE_TEST_CASE_P(
-ParameterizedTests, CanonicalRedeclChain,
-::testing::Values(ArgVector()),);
 
 // FIXME This test is disabled currently, upcoming patches will make it
 // possible to enable.
@@ -4770,19 +4864,99 @@
   CXXMethodDecl *ImportedF = Import(FromF, Lang_CXX);
   EXPECT_FALSE(ImportedF);
 
-  // There is no error set for ok().
+  // There is an error set for the other member too.
   auto *FromOK = FirstDeclMatcher().match(
   FromTU, cxxMethodDecl(hasName("ok")));
   OptErr = Importer->getImportDeclErrorIfAny(FromOK);
-  EXPECT_FALSE(OptErr);
-  // And we should be able to import.
+  EXPECT_TRUE(OptErr);
+  // Cannot import the other member.
   CXXMethodDecl *ImportedOK = Import(FromOK, Lang_CXX);
-  EXPECT_TRUE(ImportedOK);
+  EXPECT_FALSE(ImportedOK);
+}
+
+// Check that an error propagates to the dependent AST nodes.
+// In the below code it means that an error in X should propagate to A.
+// And even to F since the containing A is erroneous.
+// And to all AST nodes which we visit during the import process which finally
+// ends up in a failure (in the error() function).
+TEST_P(ErrorHandlingTest, ErrorPropagatesThroughImportCycles) {
+  Decl *FromTU = getTuDecl(
+  std::string(R"(
+  namespace NS {
+class A {
+  template  class F {};
+  class X {
+template  friend class F;
+void error() { )") + ErroneousStmt + R"( }
+  };
+};
+
+class B {};
+  } // NS
+  )",
+  Lang_CXX, "input0.cc");
+
+  auto *FromFRD = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("F"), isDefinition()));
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A"), isDefinition()));
+  auto *FromB = 

[PATCH] D63288: [clang-tidy] Generalize TransformerClangTidyCheck to take a rule generator.

2019-06-24 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 206253.
ymandel marked an inline comment as done.
ymandel added a comment.

Added tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63288

Files:
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
  clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
@@ -18,16 +18,16 @@
 namespace tidy {
 namespace utils {
 namespace {
+using tooling::change;
 using tooling::RewriteRule;
+using tooling::text;
+using tooling::stencil::cat;
 
 // Invert the code of an if-statement, while maintaining its semantics.
 RewriteRule invertIf() {
   using namespace ::clang::ast_matchers;
-  using tooling::change;
   using tooling::node;
   using tooling::statement;
-  using tooling::text;
-  using tooling::stencil::cat;
 
   StringRef C = "C", T = "T", E = "E";
   RewriteRule Rule = tooling::makeRule(
@@ -65,6 +65,64 @@
   )";
   EXPECT_EQ(Expected, test::runCheckOnCode(Input));
 }
+
+// A trivial rewrite rule generator that requires C99 code to operate.
+Optional needsC99(const LangOptions ,
+   const ClangTidyCheck::OptionsView ) {
+  if (!LangOpts.C99)
+return None;
+  return tooling::makeRule(clang::ast_matchers::functionDecl(),
+   change(cat("void nothing()")), text("no message"));
+}
+
+class NeedsC99Check : public TransformerClangTidyCheck {
+public:
+  NeedsC99Check(StringRef Name, ClangTidyContext *Context)
+  : TransformerClangTidyCheck(needsC99, Name, Context) {}
+};
+
+// Pass a C++ source file and expect no change, since the check requires `C99`
+// support to fire.
+TEST(TransformerClangTidyCheckTest, DisableByLang) {
+  // FIXME: We should be testing both the positive and negative case. However,
+  // as far as I can tell, all of the LangOpts are always set to false, so I
+  // have been unable to test the positive case (that is, where the
+  // `LangOpts.C99` is true).
+  const std::string Input = "void log(int);";
+  EXPECT_EQ(Input, test::runCheckOnCode(Input));
+}
+
+// A trivial rewrite rule generator that checks config options.
+Optional noSkip(const LangOptions ,
+ const ClangTidyCheck::OptionsView ) {
+  if (Options.get("Skip", "false") == "true")
+return None;
+  return tooling::makeRule(clang::ast_matchers::functionDecl(),
+   change(cat("void nothing()")), text("no message"));
+}
+
+class ConfigurableCheck : public TransformerClangTidyCheck {
+public:
+  ConfigurableCheck(StringRef Name, ClangTidyContext *Context)
+  : TransformerClangTidyCheck(noSkip, Name, Context) {}
+};
+
+// Pass a C source file and expect no change, since the check requires `Bool`
+// support to fire.
+TEST(TransformerClangTidyCheckTest, DisableByConfig) {
+  const std::string Input = "void log(int);";
+  const std::string Expected = "void nothing();";
+  ClangTidyOptions Options;
+
+  Options.CheckOptions["test-check-0.Skip"] = "true";
+  EXPECT_EQ(Input, test::runCheckOnCode(
+   Input, nullptr, "input.cc", None, Options));
+
+  Options.CheckOptions["test-check-0.Skip"] = "false";
+  EXPECT_EQ(Expected, test::runCheckOnCode(
+  Input, nullptr, "input.cc", None, Options));
+}
+
 } // namespace
 } // namespace utils
 } // namespace tidy
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -31,19 +31,32 @@
 // };
 class TransformerClangTidyCheck : public ClangTidyCheck {
 public:
-  // All cases in \p R must have a non-null \c Explanation, even though \c
-  // Explanation is optional for RewriteRule in general. Because the primary
-  // purpose of clang-tidy checks is to provide users with diagnostics, we
-  // assume that a missing explanation is a bug.  If no explanation is desired,
-  // indicate that explicitly (for example, by passing `text("no explanation")`
-  //  to `makeRule` as the `Explanation` argument).
+  // \p MakeRule generates the rewrite rule to be used by the check, based on
+  // the given language and clang-tidy options. It can return \c None to handle
+  // cases where the options disable the check.
+  //
+  // All cases in the rule generated by \p MakeRule must have a non-null \c
+  // Explanation, even though \c Explanation is optional for RewriteRule in
+  // general. Because the primary purpose of 

[PATCH] D63093: [analyzer] WIP: MallocChecker: Release temporary CXXNewExpr

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso abandoned this revision.
Charusso added a comment.

The seen error solved by D63720 .


Repository:
  rC Clang

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

https://reviews.llvm.org/D63093



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


[PATCH] D63727: [analyzer] print() JSONify: Stable LocationContext IDs

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso created this revision.
Charusso added a reviewer: NoQ.
Charusso added a project: clang.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.

-


Repository:
  rC Clang

https://reviews.llvm.org/D63727

Files:
  clang/lib/Analysis/AnalysisDeclContext.cpp
  clang/test/Analysis/dump_egraph.cpp
  clang/test/Analysis/expr-inspection.c


Index: clang/test/Analysis/expr-inspection.c
===
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -30,7 +30,7 @@
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ]},
 // CHECK-NEXT:   "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
-// CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": 
"foo", "call_line": null, "items": [
+// CHECK-NEXT: { "lctx_id": 1, "location_context": "#1 Call", "calling": 
"foo", "call_line": null, "items": [
 // CHECK-NEXT:   { "stmt_id": {{[0-9]+}}, "pretty": 
"clang_analyzer_printState", "value": "{clang_analyzer_printState}" }
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ]},
Index: clang/test/Analysis/dump_egraph.cpp
===
--- clang/test/Analysis/dump_egraph.cpp
+++ clang/test/Analysis/dump_egraph.cpp
@@ -18,9 +18,9 @@
   new S;
 }
 
-// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"stmt_id\": {{[0-9]+}}, 
\"kind\": \"construct into local variable\", \"argument_index\": null, 
\"pretty\": \"T t;\", \"value\": \"\"
+// CHECK: \"location_context\": \"#1 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"stmt_id\": {{[0-9]+}}, 
\"kind\": \"construct into local variable\", \"argument_index\": null, 
\"pretty\": \"T t;\", \"value\": \"\"
 
-// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"init_id\": {{[0-9]+}}, 
\"kind\": \"construct into member variable\", \"argument_index\": null, 
\"pretty\": \"s\", \"value\": \"\>s\"
+// CHECK: \"location_context\": \"#2 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"init_id\": {{[0-9]+}}, 
\"kind\": \"construct into member variable\", \"argument_index\": null, 
\"pretty\": \"s\", \"value\": \"\>s\"
 
 // CHECK: \"cluster\": \"t\", \"pointer\": \"{{0x[0-9a-f]+}}\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
Index: clang/lib/Analysis/AnalysisDeclContext.cpp
===
--- clang/lib/Analysis/AnalysisDeclContext.cpp
+++ clang/lib/Analysis/AnalysisDeclContext.cpp
@@ -525,14 +525,17 @@
   const SourceManager  =
   getAnalysisDeclContext()->getASTContext().getSourceManager();
 
-  unsigned Frame = 0;
+  unsigned LCtxCount = 0;
+  for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent())
+++LCtxCount;
+
   for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
 Indent(Out, Space, IsDot)
 << "{ \"lctx_id\": " << LCtx->getID() << ", \"location_context\": \"";
 switch (LCtx->getKind()) {
 case StackFrame:
-  Out << '#' << Frame << " Call\", \"calling\": \"";
-  ++Frame;
+  Out << '#' << LCtxCount << " Call\", \"calling\": \"";
+  --LCtxCount;
   if (const auto *D = dyn_cast(LCtx->getDecl()))
 Out << D->getQualifiedNameAsString();
   else


Index: clang/test/Analysis/expr-inspection.c
===
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -30,7 +30,7 @@
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ]},
 // CHECK-NEXT:   "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
-// CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [
+// CHECK-NEXT: { "lctx_id": 1, "location_context": "#1 Call", "calling": "foo", "call_line": null, "items": [
 // CHECK-NEXT:   { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "{clang_analyzer_printState}" }
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ]},
Index: clang/test/Analysis/dump_egraph.cpp
===
--- clang/test/Analysis/dump_egraph.cpp
+++ clang/test/Analysis/dump_egraph.cpp
@@ -18,9 +18,9 @@
   new S;
 }
 
-// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l\{ \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
+// CHECK: \"location_context\": \"#1 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l\{ \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
 
-// 

[PATCH] D63726: [analyzer] print() JSONify: Create pointers

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso created this revision.
Charusso added a reviewer: NoQ.
Charusso added a project: clang.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Charusso added a parent revision: D63462: [analyzer] JsonSupport: Escape 
escapes.

-


Repository:
  rC Clang

https://reviews.llvm.org/D63726

Files:
  clang/lib/StaticAnalyzer/Core/Environment.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/exploded-graph-rewriter/environment.dot
  clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot
  clang/test/Analysis/exploded-graph-rewriter/store.dot
  clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
  clang/test/Analysis/expr-inspection.c
  clang/utils/analyzer/exploded-graph-rewriter.py

Index: clang/utils/analyzer/exploded-graph-rewriter.py
===
--- clang/utils/analyzer/exploded-graph-rewriter.py
+++ clang/utils/analyzer/exploded-graph-rewriter.py
@@ -113,7 +113,8 @@
 class Environment(object):
 def __init__(self, json_e):
 super(Environment, self).__init__()
-self.frames = [EnvironmentFrame(f) for f in json_e]
+self.ptr = json_e['pointer']
+self.frames = [EnvironmentFrame(f) for f in json_e['items']]
 
 def diff_frames(self, prev):
 # TODO: It's difficult to display a good diff when frame numbers shift.
@@ -177,8 +178,9 @@
 class Store(object):
 def __init__(self, json_s):
 super(Store, self).__init__()
+self.ptr = json_s['pointer']
 self.clusters = collections.OrderedDict(
-[(c['pointer'], StoreCluster(c)) for c in json_s])
+[(c['pointer'], StoreCluster(c)) for c in json_s['items']])
 
 def diff_clusters(self, prev):
 removed = [k for k in prev.clusters if k not in self.clusters]
Index: clang/test/Analysis/expr-inspection.c
===
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -24,16 +24,16 @@
 }
 
 // CHECK:  "program_state": {
-// CHECK-NEXT:   "store": [
+// CHECK-NEXT:   "store": { "pointer": "{{0x[0-9a-f]+}}", "items": [
 // CHECK-NEXT: { "cluster": "y", "pointer": "{{0x[0-9a-f]+}}", "items": [
 // CHECK-NEXT:   { "kind": "Direct", "offset": 0, "value": "2 S32b" }
 // CHECK-NEXT: ]}
-// CHECK-NEXT:   ],
-// CHECK-NEXT:   "environment": [
+// CHECK-NEXT:   ]},
+// CHECK-NEXT:   "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
 // CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [
 // CHECK-NEXT:   { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "{clang_analyzer_printState}" }
 // CHECK-NEXT: ]}
-// CHECK-NEXT:   ],
+// CHECK-NEXT:   ]},
 // CHECK-NEXT:   "constraints": [
 // CHECK-NEXT: { "symbol": "reg_$0", "range": "{ [-2147483648, 13] }" }
 // CHECK-NEXT:   ],
Index: clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
===
--- clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
+++ clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
@@ -11,19 +11,22 @@
   "program_points": [],
   "program_state": {
 "environment": null,
-"store": [
-  {
-"cluster": "x",
-"pointer": "0x3",
-"items": [
-  {
-"kind": "Default",
-"offset": 0,
-"value": "Undefined"
-  }
-]
-  }
-]
+"store": {
+  "pointer": "0x2",
+  "items": [
+{
+  "cluster": "x",
+  "pointer": "0x3",
+  "items": [
+{
+  "kind": "Default",
+  "offset": 0,
+  "value": "Undefined"
+}
+  ]
+}
+  ]
+}
   }
 }
 \l}"];
@@ -52,19 +55,22 @@
   "program_points": [],
   "program_state": {
 "environment": null,
-"store": [
-  {
-"cluster": "x",
-"pointer": "0x3",
-"items": [
-  {
-"kind": "Default",
-"offset": 0,
-"value": "Unknown"
-  }
-]
-  }
-]
+"store": {
+  "pointer": "0x5",
+  "items": [
+{
+  "cluster": "x",
+  "pointer": "0x3",
+  "items": [
+{
+  "kind": "Default",
+  "offset": 0,
+  "value": "Unknown"
+}
+  ]
+}
+  ]
+}
   }
 }
 \l}"];
Index: clang/test/Analysis/exploded-graph-rewriter/store.dot

[PATCH] D63603: [ASTImporter] Propagate error from ImportDeclContext

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 206250.
martong marked 2 inline comments as done.
martong added a comment.

- Use make_scope_exit
- Add test ErrorIsNotPropagatedFromMemberToNamespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63603

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4738,6 +4738,93 @@
   EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
 }
 
+// An error should be set for a class if we cannot import one member.
+TEST_P(ErrorHandlingTest, ErrorIsPropagatedFromMemberToClass) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  std::string(R"(
+  class X {
+void f() { )") + ErroneousStmt + R"( } // This member has the error
+   // during import.
+void ok();// The error should not prevent importing this.
+  };  // An error will be set for X too.
+  )",
+  Lang_CXX);
+  auto *FromX = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("X")));
+  CXXRecordDecl *ImportedX = Import(FromX, Lang_CXX);
+
+  // An error is set for X.
+  EXPECT_FALSE(ImportedX);
+  ASTImporter *Importer = findFromTU(FromX)->Importer.get();
+  Optional OptErr = Importer->getImportDeclErrorIfAny(FromX);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+
+  // An error is set for f().
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, cxxMethodDecl(hasName("f")));
+  OptErr = Importer->getImportDeclErrorIfAny(FromF);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+  // And any subsequent import should fail.
+  CXXMethodDecl *ImportedF = Import(FromF, Lang_CXX);
+  EXPECT_FALSE(ImportedF);
+
+  // There is no error set for ok().
+  auto *FromOK = FirstDeclMatcher().match(
+  FromTU, cxxMethodDecl(hasName("ok")));
+  OptErr = Importer->getImportDeclErrorIfAny(FromOK);
+  EXPECT_FALSE(OptErr);
+  // And we should be able to import.
+  CXXMethodDecl *ImportedOK = Import(FromOK, Lang_CXX);
+  EXPECT_TRUE(ImportedOK);
+
+  // Unwary clients may access X even if the error is set, so, at least make
+  // sure the class is set to be complete.
+  CXXRecordDecl *ToX = cast(ImportedOK->getDeclContext());
+  EXPECT_TRUE(ToX->isCompleteDefinition());
+}
+
+TEST_P(ErrorHandlingTest, ErrorIsNotPropagatedFromMemberToNamespace) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  std::string(R"(
+  namespace X {
+void f() { )") + ErroneousStmt + R"( } // This member has the error
+   // during import.
+void ok();// The error should not prevent importing this.
+  };  // An error will be set for X too.
+  )",
+  Lang_CXX);
+  auto *FromX = FirstDeclMatcher().match(
+  FromTU, namespaceDecl(hasName("X")));
+  NamespaceDecl *ImportedX = Import(FromX, Lang_CXX);
+
+  // There is no error set for X.
+  EXPECT_TRUE(ImportedX);
+  ASTImporter *Importer = findFromTU(FromX)->Importer.get();
+  Optional OptErr = Importer->getImportDeclErrorIfAny(FromX);
+  ASSERT_FALSE(OptErr);
+
+  // An error is set for f().
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("f")));
+  OptErr = Importer->getImportDeclErrorIfAny(FromF);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+  // And any subsequent import should fail.
+  FunctionDecl *ImportedF = Import(FromF, Lang_CXX);
+  EXPECT_FALSE(ImportedF);
+
+  // There is no error set for ok().
+  auto *FromOK = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("ok")));
+  OptErr = Importer->getImportDeclErrorIfAny(FromOK);
+  EXPECT_FALSE(OptErr);
+  // And we should be able to import.
+  FunctionDecl *ImportedOK = Import(FromOK, Lang_CXX);
+  EXPECT_TRUE(ImportedOK);
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ErrorHandlingTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -57,6 +57,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
@@ -1631,16 +1632,32 @@
 auto ToDCOrErr = Importer.ImportContext(FromDC);
 return ToDCOrErr.takeError();
   }
+
+  // We use strict error handling in case of records and enums, but not
+  // with e.g. namespaces.
+  //
+  // FIXME Clients of the ASTImporter should be able to choose 

[PATCH] D63603: [ASTImporter] Propagate error from ImportDeclContext

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 4 inline comments as done.
martong added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:1724
+  };
+  DefinitionCompleter CompleterRAII(To);
 

jkorous wrote:
> You might consider using just a lambda with `llvm::make_scope_exit`.
> 
> https://llvm.org/doxygen/namespacellvm.html#a4896534f3c6278be56967444daf38e3f
> 
> For example:
> ```
> To->startDefinition();
> auto DefinitionCompleter = llvm::make_scope_exit( 
> [To](){To->completeDefinition();} );
> ```
Thanks! I have changed to make_scope_exit.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4743
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ErrorHandlingTest,

balazske wrote:
> Maybe add a similar test for namespace and check that the error is not 
> propagated?
Ok, I have added that test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63603



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


[PATCH] D63462: [analyzer] JsonSupport: Escape escapes

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 206248.
Charusso added a comment.

- Test case added.


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

https://reviews.llvm.org/D63462

Files:
  clang/include/clang/Basic/JsonSupport.h
  clang/test/Analysis/dump_egraph.c


Index: clang/test/Analysis/dump_egraph.c
===
--- clang/test/Analysis/dump_egraph.c
+++ clang/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 
Index: clang/include/clang/Basic/JsonSupport.h
===
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
   ++Pos; // As we insert the escape-character move plus one.
 }


Index: clang/test/Analysis/dump_egraph.c
===
--- clang/test/Analysis/dump_egraph.c
+++ clang/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 
Index: clang/include/clang/Basic/JsonSupport.h
===
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
   ++Pos; // As we insert the escape-character move plus one.
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63559: [clang-tidy] Added functionality for getting semantic highlights for variable and function declarations

2019-06-24 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlight.cpp:75
+  SemanticSymbolASTCollector Collector(Ctx);
+  Collector.TraverseAST(Ctx);
+  return Collector.getSymbols();

hokein wrote:
> let's move the above lines into `SemanticSymbolASTCollector`, we can define a 
> new method "collectTokens()".
Should I expose the entire class or keep the getSemanticHighlights function?  
(I'm just thinking that RecursiveASTVisitor contains a lot of public functions 
which makes it not super obvious which function to call to get semantic 
highlight things when looking at autocomplete)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63559



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


[PATCH] D63559: [clang-tidy] Added functionality for getting semantic highlights for variable and function declarations

2019-06-24 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 206247.
jvikstrom marked 7 inline comments as done.
jvikstrom added a comment.

Fixed tests and edge case with function declarations without names for 
parameters.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63559

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/SemanticHighlight.cpp
  clang-tools-extra/clangd/SemanticHighlight.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/SemanticHighlightTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/SemanticHighlightTests.cpp
@@ -0,0 +1,63 @@
+//===- SemanticHighlightTest.cpp - SemanticHighlightTest tests-*- 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 "Annotations.h"
+#include "ClangdUnit.h"
+#include "Protocol.h"
+#include "SemanticHighlight.h"
+#include "SourceCode.h"
+#include "TestTU.h"
+#include "llvm/Support/ScopedPrinter.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+void checkTokensExists(std::vector Tokens,
+   std::vector ExpectedRanges,
+   SemanticHighlightKind Kind) {
+  std::vector ActualRanges;
+  for (SemanticToken Token : Tokens) {
+if (Token.Kind == Kind) {
+  ActualRanges.push_back(Token.R);
+}
+  }
+
+  EXPECT_THAT(ActualRanges, testing::UnorderedElementsAreArray(ExpectedRanges));
+}
+
+TEST(SemanticSymbolASTCollector, GetBeginningOfIdentifier) {
+  std::string Preamble = R"cpp(
+void $Function[[foo]](int);
+struct A {
+  double SomeMember;
+};
+void $Function[[foo]](int $Variable[[a]]) {
+  SOMEDECL( );
+  auto $Variable[[VeryLongVariableName]] = 12312;
+  A $Variable[[aa]];
+}
+  )cpp";
+
+  Annotations Test(Preamble);
+  auto Variables = Test.ranges("Variable");
+  auto Function = Test.ranges("Function");
+
+  auto AST = TestTU::withCode(Test.code()).build();
+  auto Tokens = getSemanticHighlights(AST);
+
+  checkTokensExists(Tokens, Variables, SemanticHighlightKind::Variable);
+  checkTokensExists(Tokens, Function, SemanticHighlightKind::Function);
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -53,6 +53,7 @@
   RenameTests.cpp
   RIFFTests.cpp
   SelectionTests.cpp
+  SemanticHighlightTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
   SymbolCollectorTests.cpp
Index: clang-tools-extra/clangd/SemanticHighlight.h
===
--- /dev/null
+++ clang-tools-extra/clangd/SemanticHighlight.h
@@ -0,0 +1,37 @@
+//==-- SemanticHighlight.h - Generating highlights from the AST--*- 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
+//
+//===--===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHT_H
+
+#include "ClangdUnit.h"
+#include "Protocol.h"
+
+namespace clang {
+namespace clangd {
+
+enum class SemanticHighlightKind : int {
+  Variable = 0,
+  Function = 1,
+};
+
+// Contains all information needed for the highlighting a token.
+struct SemanticToken {
+  SemanticHighlightKind Kind;
+  Range R;
+};
+
+bool operator==(const SemanticToken , const SemanticToken );
+bool operator!=(const SemanticToken , const SemanticToken );
+
+// Returns semantic highlights for the AST. 
+std::vector getSemanticHighlights(ParsedAST );
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: clang-tools-extra/clangd/SemanticHighlight.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/SemanticHighlight.cpp
@@ -0,0 +1,82 @@
+#include "SemanticHighlight.h"
+#include "SourceCode.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Lex/Lexer.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+// Collects all semantic tokens in an ASTContext.
+class SemanticSymbolASTCollector
+: public RecursiveASTVisitor {
+  std::vector 

r364202 - [clang][NewPM] Add RUNS for tests that produce slightly different IR under new PM

2019-06-24 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Mon Jun 24 09:49:18 2019
New Revision: 364202

URL: http://llvm.org/viewvc/llvm-project?rev=364202=rev
Log:
[clang][NewPM] Add RUNS for tests that produce slightly different IR under new 
PM

For CodeGenOpenCL/convergent.cl, the new PM produced a slightly different for
loop, but this still checks for no loop unrolling as intended. This is
committed separately from D63174.

Modified:
cfe/trunk/test/CodeGenOpenCL/convergent.cl

Modified: cfe/trunk/test/CodeGenOpenCL/convergent.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/convergent.cl?rev=364202=364201=364202=diff
==
--- cfe/trunk/test/CodeGenOpenCL/convergent.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/convergent.cl Mon Jun 24 09:49:18 2019
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - | opt 
-instnamer -S | FileCheck -enable-var-scope %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - 
-fno-experimental-new-pass-manager | opt -instnamer -S | FileCheck 
-enable-var-scope %s --check-prefixes=CHECK,CHECK-LEGACY
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - 
-fexperimental-new-pass-manager | opt -instnamer -S | FileCheck 
-enable-var-scope %s --check-prefixes=CHECK,CHECK-NEWPM
 
 // This is initially assumed convergent, but can be deduced to not require it.
 
@@ -117,7 +118,12 @@ void test_unroll() {
 // CHECK: [[for_body]]:
 // CHECK:  tail call spir_func void @nodupfun() #[[attr5:[0-9]+]]
 // CHECK-NOT: call spir_func void @nodupfun()
-// CHECK:  br i1 %{{.+}}, label %[[for_body]], label %[[for_cond_cleanup]]
+
+// The new PM produces a slightly different IR for the loop from the legacy PM,
+// but the test still checks that the loop is not unrolled.
+// CHECK-LEGACY:  br i1 %{{.+}}, label %[[for_body]], label 
%[[for_cond_cleanup]]
+// CHECK-NEW: br i1 %{{.+}}, label %[[for_body_crit_edge:.+]], label 
%[[for_cond_cleanup]]
+// CHECK-NEW: [[for_body_crit_edge]]:
 
 void test_not_unroll() {
   for (int i = 0; i < 10; i++)


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


[PATCH] D62953: [Syntax] Do not glue multiple empty PP expansions to a single mapping

2019-06-24 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:319
+  ///   2. macro name and arguments for macro expansions.
+  using PPExpansions = llvm::DenseMap;
   class Builder;

sammccall wrote:
> do I understand right that this is logically a stack, but it's hard to know 
> when to pop or just less hassle to do this way?
> if so, maybe worth mentioning
That's exactly the case, but preprocessor only exposes the point at which we 
push macros to the stack (`PPCallbacks::MacroExpands`, etc) and not points when 
we pop from the stack. This map is an attempt to recover the pop positions 
(e.g. to detect intermediate expansions in the macro arguments).

Added a comment



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:269
+  return;
+// Do not record recursive expansions.
+if (!MacroNameTok.getLocation().isFileID() ||

sammccall wrote:
> This doesn't seem like a particularly standard use of the word "recursive", 
> and the code isn't totally obvious either.
> 
> Could this be "only record top-level expansions, not those where:
>  - the macro use is inside a macro body
>  - the macro appears in an argument to another macro
> 
> Because the top level macros are treated as opaque atoms. (We probably need a 
> FIXME for tracking arg locations somewhere)
Added a comment and a FIXME at the declaration site of `TokenBuffer`



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:522
   llvm::DenseMap NextSpelled;
+  PPExpansions Expansions;
   const SourceManager 

sammccall wrote:
> maybe RecordedExpansions? to make the link with the recorder
SG, I've renamed to `CollectedExpansions`. (Assuming 'recorder' stands for 
'collector', happy to update if I misinterpreted your comment)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62953



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


[PATCH] D62953: [Syntax] Do not glue multiple empty PP expansions to a single mapping

2019-06-24 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 206246.
ilya-biryukov marked 10 inline comments as done.
ilya-biryukov added a comment.

- Address comments, document code.
- s/Expansion/CollectedExpansions.
- Added FIXMEs for macro arguments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62953

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -424,6 +424,7 @@
"['#'_0, 'int'_22) => ['int'_0, 'int'_0)\n"
"['ADD'_25, ';'_46) => ['1'_3, ';'_12)\n"},
   // Empty macro replacement.
+  // FIXME: the #define directives should not be glued together.
   {R"cpp(
 #define EMPTY
 #define EMPTY_FUNC(X)
@@ -436,7 +437,9 @@
   spelled tokens:
 # define EMPTY # define EMPTY_FUNC ( X ) EMPTY EMPTY_FUNC ( 1 + 2 + 3 )
   mappings:
-['#'_0, ''_18) => [''_0, ''_0)
+['#'_0, 'EMPTY'_9) => [''_0, ''_0)
+['EMPTY'_9, 'EMPTY_FUNC'_10) => [''_0, ''_0)
+['EMPTY_FUNC'_10, ''_18) => [''_0, ''_0)
 )"},
   // File ends with a macro replacement.
   {R"cpp(
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -70,8 +71,8 @@
 
 FileRange::FileRange(FileID File, unsigned BeginOffset, unsigned EndOffset)
 : File(File), Begin(BeginOffset), End(EndOffset) {
-  assert(File.isValid());
-  assert(BeginOffset <= EndOffset);
+  assert(File.isValid());
+  assert(BeginOffset <= EndOffset);
 }
 
 FileRange::FileRange(const SourceManager , SourceLocation BeginLoc,
@@ -252,6 +253,39 @@
   return Tokens;
 }
 
+/// Records information reqired to construct mappings for the token buffer that
+/// we are collecting.
+class TokenCollector::CollectPPExpansions : public PPCallbacks {
+public:
+  CollectPPExpansions(TokenCollector ) : Collector() {}
+
+  /// Disabled instance will stop reporting anything to TokenCollector.
+  /// This ensures that uses of the preprocessor after TokenCollector::consume()
+  /// is called do not access the (possibly invalid) collector instance.
+  void disable() { Collector = nullptr; }
+
+  void MacroExpands(const clang::Token , const MacroDefinition ,
+SourceRange Range, const MacroArgs *Args) override {
+if (!Collector)
+  return;
+// Only record top-level expansions, not those where:
+//   - the macro use is inside a macro body,
+//   - the macro appears in an argument to another macro.
+if (!MacroNameTok.getLocation().isFileID() ||
+(LastExpansionEnd.isValid() &&
+ Collector->PP.getSourceManager().isBeforeInTranslationUnit(
+ Range.getBegin(), LastExpansionEnd)))
+  return;
+Collector->Expansions[Range.getBegin().getRawEncoding()] = Range.getEnd();
+LastExpansionEnd = Range.getEnd();
+  }
+  // FIXME: handle directives like #pragma, #include, etc.
+private:
+  TokenCollector *Collector;
+  /// Used to detect recursive macro expansions.
+  SourceLocation LastExpansionEnd;
+};
+
 /// Fills in the TokenBuffer by tracing the run of a preprocessor. The
 /// implementation tracks the tokens, macro expansions and directives coming
 /// from the preprocessor and:
@@ -279,15 +313,21 @@
 );
 Expanded.push_back(syntax::Token(T));
   });
+  // And locations of macro calls, to properly recover boundaries of those in
+  // case of empty expansions.
+  auto CB = llvm::make_unique(*this);
+  this->Collector = CB.get();
+  PP.addPPCallbacks(std::move(CB));
 }
 
 /// Builds mappings and spelled tokens in the TokenBuffer based on the expanded
 /// token stream.
 class TokenCollector::Builder {
 public:
-  Builder(std::vector Expanded, const SourceManager ,
-  const LangOptions )
-  : Result(SM), SM(SM), LangOpts(LangOpts) {
+  Builder(std::vector Expanded, PPExpansions CollectedExpansions,
+  const SourceManager , const LangOptions )
+  : Result(SM), CollectedExpansions(std::move(CollectedExpansions)), SM(SM),
+LangOpts(LangOpts) {
 Result.ExpandedTokens = std::move(Expanded);
   }
 
@@ -296,6 +336,9 @@
 
 // Walk over expanded tokens and spelled tokens in parallel, building the
 // mappings between those using source locations.
+// To correctly recover empty macro expansions, we also take locations
+// reported to 

[PATCH] D63626: [clang][NewPM] Remove exception handling before loading pgo sample profile data

2019-06-24 Thread Leonard Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364201: [clang][NewPM] Remove exception handling before 
loading pgo sample profile data (authored by leonardchan, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D63626?vs=206065=206245#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63626

Files:
  cfe/trunk/test/CodeGen/pgo-sample.c


Index: cfe/trunk/test/CodeGen/pgo-sample.c
===
--- cfe/trunk/test/CodeGen/pgo-sample.c
+++ cfe/trunk/test/CodeGen/pgo-sample.c
@@ -1,6 +1,13 @@
 // Test if PGO sample use passes are invoked.
 //
 // Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
-// CHECK: Remove unused exception handling info
-// CHECK: Sample profile pass
+// RUN: %clang_cc1 -O2 -fno-experimental-new-pass-manager 
-fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure 
-emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=LEGACY
+// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager 
-fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -fdebug-pass-manager 
-emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=NEWPM
+
+// LEGACY: Remove unused exception handling info
+// LEGACY: Sample profile pass
+
+// NEWPM: SimplifyCFGPass
+// NEWPM: SampleProfileLoaderPass
+
+int func(int a) { return a; }


Index: cfe/trunk/test/CodeGen/pgo-sample.c
===
--- cfe/trunk/test/CodeGen/pgo-sample.c
+++ cfe/trunk/test/CodeGen/pgo-sample.c
@@ -1,6 +1,13 @@
 // Test if PGO sample use passes are invoked.
 //
 // Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
-// CHECK: Remove unused exception handling info
-// CHECK: Sample profile pass
+// RUN: %clang_cc1 -O2 -fno-experimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=LEGACY
+// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=NEWPM
+
+// LEGACY: Remove unused exception handling info
+// LEGACY: Sample profile pass
+
+// NEWPM: SimplifyCFGPass
+// NEWPM: SampleProfileLoaderPass
+
+int func(int a) { return a; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r364201 - [clang][NewPM] Remove exception handling before loading pgo sample profile data

2019-06-24 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Mon Jun 24 09:44:27 2019
New Revision: 364201

URL: http://llvm.org/viewvc/llvm-project?rev=364201=rev
Log:
[clang][NewPM] Remove exception handling before loading pgo sample profile data

This patch ensures that SimplifyCFGPass comes before SampleProfileLoaderPass
on PGO runs in the new PM and fixes clang/test/CodeGen/pgo-sample.c.

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

Modified:
cfe/trunk/test/CodeGen/pgo-sample.c

Modified: cfe/trunk/test/CodeGen/pgo-sample.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pgo-sample.c?rev=364201=364200=364201=diff
==
--- cfe/trunk/test/CodeGen/pgo-sample.c (original)
+++ cfe/trunk/test/CodeGen/pgo-sample.c Mon Jun 24 09:44:27 2019
@@ -1,6 +1,13 @@
 // Test if PGO sample use passes are invoked.
 //
 // Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
-// CHECK: Remove unused exception handling info
-// CHECK: Sample profile pass
+// RUN: %clang_cc1 -O2 -fno-experimental-new-pass-manager 
-fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure 
-emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=LEGACY
+// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager 
-fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -fdebug-pass-manager 
-emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=NEWPM
+
+// LEGACY: Remove unused exception handling info
+// LEGACY: Sample profile pass
+
+// NEWPM: SimplifyCFGPass
+// NEWPM: SampleProfileLoaderPass
+
+int func(int a) { return a; }


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


  1   2   >