[PATCH] D92001: [ubsan] Fix crash on __builtin_assume_aligned

2020-12-02 Thread Orivej Desh via Phabricator via cfe-commits
orivej added a comment.

Could somebody review this?


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

https://reviews.llvm.org/D92001

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


[PATCH] D92001: [ubsan] Fix crash on __builtin_assume_aligned

2020-11-23 Thread Orivej Desh via Phabricator via cfe-commits
orivej added a comment.

Sorry, I don't understand the issue and can't write a better description.
Since this test triggers an assert in getCommonPtr that it "Cannot retrieve a 
NULL type pointer" of Ty->getPointeeType(), the fix just checks that the 
pointee is not null before using isVolatileQualified.


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

https://reviews.llvm.org/D92001

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


[PATCH] D92001: [ubsan] Fix crash on __builtin_assume_aligned

2020-11-23 Thread Orivej Desh via Phabricator via cfe-commits
orivej updated this revision to Diff 307239.

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

https://reviews.llvm.org/D92001

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/ubsan-assume-aligned-crash.c


Index: clang/test/CodeGen/ubsan-assume-aligned-crash.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-assume-aligned-crash.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsanitize=alignment -emit-llvm %s -o /dev/null
+
+/* Testcase for PR45813 - clang crashes checking isVolatileQualified of isNull 
pointee. */
+
+__attribute__((aligned(8))) int data[2];
+
+int* test() {
+return __builtin_assume_aligned(data, 8);
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2521,7 +2521,7 @@
 
   // Don't check pointers to volatile data. The behavior here is 
implementation-
   // defined.
-  if (Ty->getPointeeType().isVolatileQualified())
+  if (!Ty->getPointeeType().isNull() && 
Ty->getPointeeType().isVolatileQualified())
 return;
 
   // We need to temorairly remove the assumption so we can insert the


Index: clang/test/CodeGen/ubsan-assume-aligned-crash.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-assume-aligned-crash.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsanitize=alignment -emit-llvm %s -o /dev/null
+
+/* Testcase for PR45813 - clang crashes checking isVolatileQualified of isNull pointee. */
+
+__attribute__((aligned(8))) int data[2];
+
+int* test() {
+return __builtin_assume_aligned(data, 8);
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2521,7 +2521,7 @@
 
   // Don't check pointers to volatile data. The behavior here is implementation-
   // defined.
-  if (Ty->getPointeeType().isVolatileQualified())
+  if (!Ty->getPointeeType().isNull() && Ty->getPointeeType().isVolatileQualified())
 return;
 
   // We need to temorairly remove the assumption so we can insert the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92001: [ubsan] Fix crash on __builtin_assume_aligned

2020-11-23 Thread Orivej Desh via Phabricator via cfe-commits
orivej created this revision.
orivej added reviewers: lebedev.ri, Tyker, rsmith.
orivej added projects: clang, Sanitizers.
Herald added a subscriber: cfe-commits.
orivej requested review of this revision.

Fixes PR45813


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92001

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/ubsan-assume-aligned-crash.c


Index: clang/test/CodeGen/ubsan-assume-aligned-crash.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-assume-aligned-crash.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsanitize=alignment -emit-llvm %s -o /dev/null
+
+/* Testcase for PR - clang crashes checking isVolatileQualified of isNull 
pointee. */
+
+__attribute__((aligned(8))) int data[2];
+
+int* test() {
+return __builtin_assume_aligned(data, 8);
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2521,7 +2521,7 @@
 
   // Don't check pointers to volatile data. The behavior here is 
implementation-
   // defined.
-  if (Ty->getPointeeType().isVolatileQualified())
+  if (!Ty->getPointeeType().isNull() && 
Ty->getPointeeType().isVolatileQualified())
 return;
 
   // We need to temorairly remove the assumption so we can insert the


Index: clang/test/CodeGen/ubsan-assume-aligned-crash.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-assume-aligned-crash.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsanitize=alignment -emit-llvm %s -o /dev/null
+
+/* Testcase for PR - clang crashes checking isVolatileQualified of isNull pointee. */
+
+__attribute__((aligned(8))) int data[2];
+
+int* test() {
+return __builtin_assume_aligned(data, 8);
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2521,7 +2521,7 @@
 
   // Don't check pointers to volatile data. The behavior here is implementation-
   // defined.
-  if (Ty->getPointeeType().isVolatileQualified())
+  if (!Ty->getPointeeType().isNull() && Ty->getPointeeType().isVolatileQualified())
 return;
 
   // We need to temorairly remove the assumption so we can insert the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65988: [Clang Tablegen] Fix build when std::string::end() is not assignable

2019-08-08 Thread Orivej Desh via Phabricator via cfe-commits
orivej created this revision.
orivej added a reviewer: clang.
orivej added a project: clang.
Herald added subscribers: cfe-commits, kadircet, arphaman.

This fixes Clang error: expression is not assignable:

  Result.erase(--Result.end()); 
   
   ^    
   


Repository:
  rC Clang

https://reviews.llvm.org/D65988

Files:
  utils/TableGen/ClangDiagnosticsEmitter.cpp


Index: utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -950,7 +950,7 @@
 Result += '|';
   }
   if (!P->Options.empty())
-Result.erase(--Result.end());
+Result.pop_back();
   Result += '}';
 }
 addInt(mapIndex(P->Index));
@@ -966,7 +966,7 @@
   Result += "|";
 }
 if (!P->Options.empty())
-  Result.erase(--Result.end());
+  Result.pop_back();
 Result += '}';
 addInt(mapIndex(P->Index));
   }


Index: utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -950,7 +950,7 @@
 Result += '|';
   }
   if (!P->Options.empty())
-Result.erase(--Result.end());
+Result.pop_back();
   Result += '}';
 }
 addInt(mapIndex(P->Index));
@@ -966,7 +966,7 @@
   Result += "|";
 }
 if (!P->Options.empty())
-  Result.erase(--Result.end());
+  Result.pop_back();
 Result += '}';
 addInt(mapIndex(P->Index));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45898: [SemaCXX] Mark destructor as referenced

2018-12-09 Thread Orivej Desh via Phabricator via cfe-commits
orivej added a comment.

I have noticed that this change breaks seemingly valid code:

  class A { protected: ~A(); };
  struct B : A {};
  B f() { return B(); }
  B g() { return {}; }

`f` compiles, but `g` fails with `temporary of type 'A' has protected 
destructor`. (g++ 8.2 compiles this file.)


Repository:
  rC Clang

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

https://reviews.llvm.org/D45898



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


[PATCH] D45898: [SemaCXX] Mark destructor as referenced

2018-12-08 Thread Orivej Desh via Phabricator via cfe-commits
orivej added a comment.

Actually, `arc-list-init-destruct.mm` crashes Clang 7 with the same backtrace 
as this test case, and Clang trunk generates similar assembly (to the the point 
that I could essentially copy the `// CHECK` comments from the .mm test to a 
.cpp test), so I'm not sure if adding a .cpp test is valuableā€¦


Repository:
  rC Clang

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

https://reviews.llvm.org/D45898



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


[PATCH] D45898: [SemaCXX] Mark destructor as referenced

2018-12-08 Thread Orivej Desh via Phabricator via cfe-commits
orivej added a comment.
Herald added a subscriber: jkorous.

The committed test does not crash Clang 7, but the following test does, yet it 
compiles without any warnings by the current Clang trunk thanks to this fix.

  struct A { ~A(); };
  struct B : A {};
  struct C { C();  B b; };
  struct D { C c, d; };
  D f() { return {}; }


Repository:
  rC Clang

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

https://reviews.llvm.org/D45898



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


[PATCH] D53244: [Coverage] Fix PR39258: support coverage regions that start deeper than they end

2018-11-19 Thread Orivej Desh via Phabricator via cfe-commits
orivej added a comment.

@vsk, I think this is ready, but I don't have the merge rights. Could you 
commit it and https://reviews.llvm.org/D53231 for me?


Repository:
  rC Clang

https://reviews.llvm.org/D53244



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


[PATCH] D53231: [Sema] Fix PR38987: keep end location of a direct initializer list

2018-10-31 Thread Orivej Desh via Phabricator via cfe-commits
orivej added a comment.

https://reviews.llvm.org/D41921 was the last big change necessary to fix clang 
crashes on code coverage, but without the fixup in this review clang crashes on 
about 1.5 times more projects that I maintain than before. It seems useful to 
include this in the 7.0.1 release. (After the fixup the only crasher is scipy, 
being dealt with in https://reviews.llvm.org/D53244.)


Repository:
  rC Clang

https://reviews.llvm.org/D53231



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


[PATCH] D53244: [Coverage] Fix PR39258: support coverage regions that start deeper than they end

2018-10-31 Thread Orivej Desh via Phabricator via cfe-commits
orivej updated this revision to Diff 172042.
orivej added a comment.

Remove unrelated change.


Repository:
  rC Clang

https://reviews.llvm.org/D53244

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/macros.c

Index: test/CoverageMapping/macros.c
===
--- test/CoverageMapping/macros.c
+++ test/CoverageMapping/macros.c
@@ -4,6 +4,7 @@
 #define MACRO_2 bar()
 #define MACRO_1 return; MACRO_2
 #define MACRO_3 MACRO_2
+#define GOTO goto
 
 void bar() {}
 
@@ -56,6 +57,15 @@
 // CHECK-NEXT: Expansion,File 1, 6:17 -> 6:24 = #1
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #1
 
+// CHECK-NEXT: func6
+void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> [[@LINE+4]]:2 = #0
+begin:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #1
+if (count--) // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:16 = #1
+GOTO begin;  // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:19 = #2
+}
+// CHECK-NEXT: Expansion,File 0, [[@LINE-2]]:9 -> [[@LINE-2]]:13 = #2
+// CHECK-NEXT: File 1, 7:14 -> 7:18 = #2
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -552,6 +552,15 @@
 completeDeferred(Count, DeferredEndLoc);
   }
 
+  size_t locationDepth(SourceLocation Loc) {
+size_t Depth = 0;
+while (Loc.isValid()) {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  Depth++;
+}
+return Depth;
+  }
+
   /// Pop regions from the stack into the function's list of regions.
   ///
   /// Adds all regions from \c ParentIndex to the top of the stack to the
@@ -566,19 +575,41 @@
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
 : RegionStack[ParentIndex].getEndLoc();
+size_t StartDepth = locationDepth(StartLoc);
+size_t EndDepth = locationDepth(EndLoc);
 while (!SM.isWrittenInSameFile(StartLoc, EndLoc)) {
-  // The region ends in a nested file or macro expansion. Create a
-  // separate region for each expansion.
-  SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
-  assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
-
-  if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
-SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
-
-  EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
-  if (EndLoc.isInvalid())
-llvm::report_fatal_error("File exit not handled before popRegions");
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+// The region ends in a nested file or macro expansion. Create a
+// separate region for each expansion.
+SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
+assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
+
+if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
+  SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
+
+EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
+if (EndLoc.isInvalid())
+  llvm::report_fatal_error("File exit not handled before popRegions");
+EndDepth--;
+  }
+  if (UnnestStart) {
+// The region begins in a nested file or macro expansion. Create a
+// separate region for each expansion.
+SourceLocation NestedLoc = getEndOfFileOrMacro(StartLoc);
+assert(SM.isWrittenInSameFile(StartLoc, NestedLoc));
+
+if (!isRegionAlreadyAdded(StartLoc, NestedLoc))
+  SourceRegions.emplace_back(Region.getCounter(), StartLoc, NestedLoc);
+
+StartLoc = getIncludeOrExpansionLoc(StartLoc);
+if (StartLoc.isInvalid())
+  llvm::report_fatal_error("File exit not handled before popRegions");
+StartDepth--;
+  }
 }
+Region.setStartLoc(StartLoc);
 Region.setEndLoc(EndLoc);
 
 MostRecentLocation = EndLoc;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53244: [Coverage] Fix PR39258: support coverage regions that start deeper than they end

2018-10-31 Thread Orivej Desh via Phabricator via cfe-commits
orivej updated this revision to Diff 172041.
orivej added a comment.
Herald added a subscriber: mgorny.

Use relative line offset.


Repository:
  rC Clang

https://reviews.llvm.org/D53244

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/macros.c
  tools/CMakeLists.txt

Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -35,3 +35,4 @@
 
 # libclang may require clang-tidy in clang-tools-extra.
 add_clang_subdirectory(libclang)
+add_clang_subdirectory(templight)
Index: test/CoverageMapping/macros.c
===
--- test/CoverageMapping/macros.c
+++ test/CoverageMapping/macros.c
@@ -4,6 +4,7 @@
 #define MACRO_2 bar()
 #define MACRO_1 return; MACRO_2
 #define MACRO_3 MACRO_2
+#define GOTO goto
 
 void bar() {}
 
@@ -56,6 +57,15 @@
 // CHECK-NEXT: Expansion,File 1, 6:17 -> 6:24 = #1
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #1
 
+// CHECK-NEXT: func6
+void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> [[@LINE+4]]:2 = #0
+begin:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #1
+if (count--) // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:16 = #1
+GOTO begin;  // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:19 = #2
+}
+// CHECK-NEXT: Expansion,File 0, [[@LINE-2]]:9 -> [[@LINE-2]]:13 = #2
+// CHECK-NEXT: File 1, 7:14 -> 7:18 = #2
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -552,6 +552,15 @@
 completeDeferred(Count, DeferredEndLoc);
   }
 
+  size_t locationDepth(SourceLocation Loc) {
+size_t Depth = 0;
+while (Loc.isValid()) {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  Depth++;
+}
+return Depth;
+  }
+
   /// Pop regions from the stack into the function's list of regions.
   ///
   /// Adds all regions from \c ParentIndex to the top of the stack to the
@@ -566,19 +575,41 @@
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
 : RegionStack[ParentIndex].getEndLoc();
+size_t StartDepth = locationDepth(StartLoc);
+size_t EndDepth = locationDepth(EndLoc);
 while (!SM.isWrittenInSameFile(StartLoc, EndLoc)) {
-  // The region ends in a nested file or macro expansion. Create a
-  // separate region for each expansion.
-  SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
-  assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
-
-  if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
-SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
-
-  EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
-  if (EndLoc.isInvalid())
-llvm::report_fatal_error("File exit not handled before popRegions");
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+// The region ends in a nested file or macro expansion. Create a
+// separate region for each expansion.
+SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
+assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
+
+if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
+  SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
+
+EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
+if (EndLoc.isInvalid())
+  llvm::report_fatal_error("File exit not handled before popRegions");
+EndDepth--;
+  }
+  if (UnnestStart) {
+// The region begins in a nested file or macro expansion. Create a
+// separate region for each expansion.
+SourceLocation NestedLoc = getEndOfFileOrMacro(StartLoc);
+assert(SM.isWrittenInSameFile(StartLoc, NestedLoc));
+
+if (!isRegionAlreadyAdded(StartLoc, NestedLoc))
+  SourceRegions.emplace_back(Region.getCounter(), StartLoc, NestedLoc);
+
+StartLoc = getIncludeOrExpansionLoc(StartLoc);
+if (StartLoc.isInvalid())
+  llvm::report_fatal_error("File exit not handled before popRegions");
+StartDepth--;
+  }
 }
+Region.setStartLoc(StartLoc);
 Region.setEndLoc(EndLoc);
 
 MostRecentLocation = EndLoc;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53244: [Coverage] Fix PR39258: support coverage regions that start deeper than they end

2018-10-15 Thread Orivej Desh via Phabricator via cfe-commits
orivej added a comment.

Thanks! Could you merge this (after a while to let others review)?




Comment at: test/CoverageMapping/macros.c:60
 
+// CHECK-NEXT: func6
+void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> 
[[@LINE+4]]:2 = #0

vsk wrote:
> Please use CHECK-LABEL here.
`CHECK-LABEL` would accept unchecked output between the previous `CHECK-NEXT` 
and `func6`. It seems that the intention of this test is to check all lines of 
output, so I used `CHECK-NEXT` as in other tests in this file.


Repository:
  rC Clang

https://reviews.llvm.org/D53244



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


[PATCH] D53231: [Sema] Fix PR38987: keep end location of a direct initializer list

2018-10-14 Thread Orivej Desh via Phabricator via cfe-commits
orivej added a comment.

I don't have the complete picture yet. (This is why the summary is so short.)
I have looked up that `IK_DirectList` `Kind` was known not to carry a valid 
`ParenRange` since 
https://github.com/llvm-mirror/clang/commit/188158db29f50443b6e412f2a40c800b2669c957,
 and that `PerformConstructorInitialization` acquired `BraceLoc` arguments 
specifically to support `CXXTemporaryObjectExpr`: 
https://github.com/llvm-mirror/clang/commit/1245a54ca6e9c5b14196461dc3f84b24ea6594b1#diff-d7cc8293491a9fdddee7ba857c028256R5921
 , but then it appears that `CXXTemporaryObjectExpr` `Kind` has acquired a 
valid `ParenRange`, except when it is instantiated from a templateā€¦


Repository:
  rC Clang

https://reviews.llvm.org/D53231



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


[PATCH] D53244: [Coverage] Fix PR39258: support coverage regions that start deeper than they end

2018-10-13 Thread Orivej Desh via Phabricator via cfe-commits
orivej updated this revision to Diff 169568.
orivej added a comment.

Fix typo


Repository:
  rC Clang

https://reviews.llvm.org/D53244

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/macros.c

Index: test/CoverageMapping/macros.c
===
--- test/CoverageMapping/macros.c
+++ test/CoverageMapping/macros.c
@@ -4,6 +4,7 @@
 #define MACRO_2 bar()
 #define MACRO_1 return; MACRO_2
 #define MACRO_3 MACRO_2
+#define GOTO goto
 
 void bar() {}
 
@@ -56,6 +57,15 @@
 // CHECK-NEXT: Expansion,File 1, 6:17 -> 6:24 = #1
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #1
 
+// CHECK-NEXT: func6
+void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> [[@LINE+4]]:2 = #0
+begin:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #1
+if (count--) // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:16 = #1
+GOTO begin;  // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:19 = #2
+}
+// CHECK-NEXT: Expansion,File 0, 64:9 -> 64:13 = #2
+// CHECK-NEXT: File 1, 7:14 -> 7:18 = #2
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -552,6 +552,15 @@
 completeDeferred(Count, DeferredEndLoc);
   }
 
+  size_t locationDepth(SourceLocation Loc) {
+size_t Depth = 0;
+while (Loc.isValid()) {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  Depth++;
+}
+return Depth;
+  }
+
   /// Pop regions from the stack into the function's list of regions.
   ///
   /// Adds all regions from \c ParentIndex to the top of the stack to the
@@ -566,19 +575,41 @@
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
 : RegionStack[ParentIndex].getEndLoc();
+size_t StartDepth = locationDepth(StartLoc);
+size_t EndDepth = locationDepth(EndLoc);
 while (!SM.isWrittenInSameFile(StartLoc, EndLoc)) {
-  // The region ends in a nested file or macro expansion. Create a
-  // separate region for each expansion.
-  SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
-  assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
-
-  if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
-SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
-
-  EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
-  if (EndLoc.isInvalid())
-llvm::report_fatal_error("File exit not handled before popRegions");
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+// The region ends in a nested file or macro expansion. Create a
+// separate region for each expansion.
+SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
+assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
+
+if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
+  SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
+
+EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
+if (EndLoc.isInvalid())
+  llvm::report_fatal_error("File exit not handled before popRegions");
+EndDepth--;
+  }
+  if (UnnestStart) {
+// The region begins in a nested file or macro expansion. Create a
+// separate region for each expansion.
+SourceLocation NestedLoc = getEndOfFileOrMacro(StartLoc);
+assert(SM.isWrittenInSameFile(StartLoc, NestedLoc));
+
+if (!isRegionAlreadyAdded(StartLoc, NestedLoc))
+  SourceRegions.emplace_back(Region.getCounter(), StartLoc, NestedLoc);
+
+StartLoc = getIncludeOrExpansionLoc(StartLoc);
+if (StartLoc.isInvalid())
+  llvm::report_fatal_error("File exit not handled before popRegions");
+StartDepth--;
+  }
 }
+Region.setStartLoc(StartLoc);
 Region.setEndLoc(EndLoc);
 
 MostRecentLocation = EndLoc;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53244: [Coverage] Fix PR39258: support coverage regions that start deeper than they end

2018-10-13 Thread Orivej Desh via Phabricator via cfe-commits
orivej updated this revision to Diff 169562.
orivej added a comment.

This looks better to me. (There is no difference in check-clang test results.)


Repository:
  rC Clang

https://reviews.llvm.org/D53244

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/macros.c

Index: test/CoverageMapping/macros.c
===
--- test/CoverageMapping/macros.c
+++ test/CoverageMapping/macros.c
@@ -4,6 +4,7 @@
 #define MACRO_2 bar()
 #define MACRO_1 return; MACRO_2
 #define MACRO_3 MACRO_2
+#define GOTO goto
 
 void bar() {}
 
@@ -56,6 +57,15 @@
 // CHECK-NEXT: Expansion,File 1, 6:17 -> 6:24 = #1
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #1
 
+// CHECK-NEXT: func6
+void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> [[@LINE+4]]:2 = #0
+begin:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #1
+if (count--) // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:16 = #1
+GOTO begin;  // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:19 = #2
+}
+// CHECK-NEXT: Expansion,File 0, 64:9 -> 64:13 = #2
+// CHECK-NEXT: File 1, 7:14 -> 7:18 = #2
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -552,6 +552,15 @@
 completeDeferred(Count, DeferredEndLoc);
   }
 
+  size_t locactionDepth(SourceLocation Loc) {
+size_t Depth = 0;
+while (Loc.isValid()) {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  Depth++;
+}
+return Depth;
+  }
+
   /// Pop regions from the stack into the function's list of regions.
   ///
   /// Adds all regions from \c ParentIndex to the top of the stack to the
@@ -566,19 +575,41 @@
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
 : RegionStack[ParentIndex].getEndLoc();
+size_t StartDepth = locactionDepth(StartLoc);
+size_t EndDepth = locactionDepth(EndLoc);
 while (!SM.isWrittenInSameFile(StartLoc, EndLoc)) {
-  // The region ends in a nested file or macro expansion. Create a
-  // separate region for each expansion.
-  SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
-  assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
-
-  if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
-SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
-
-  EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
-  if (EndLoc.isInvalid())
-llvm::report_fatal_error("File exit not handled before popRegions");
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+// The region ends in a nested file or macro expansion. Create a
+// separate region for each expansion.
+SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
+assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
+
+if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
+  SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
+
+EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
+if (EndLoc.isInvalid())
+  llvm::report_fatal_error("File exit not handled before popRegions");
+EndDepth--;
+  }
+  if (UnnestStart) {
+// The region begins in a nested file or macro expansion. Create a
+// separate region for each expansion.
+SourceLocation NestedLoc = getEndOfFileOrMacro(StartLoc);
+assert(SM.isWrittenInSameFile(StartLoc, NestedLoc));
+
+if (!isRegionAlreadyAdded(StartLoc, NestedLoc))
+  SourceRegions.emplace_back(Region.getCounter(), StartLoc, NestedLoc);
+
+StartLoc = getIncludeOrExpansionLoc(StartLoc);
+if (StartLoc.isInvalid())
+  llvm::report_fatal_error("File exit not handled before popRegions");
+StartDepth--;
+  }
 }
+Region.setStartLoc(StartLoc);
 Region.setEndLoc(EndLoc);
 
 MostRecentLocation = EndLoc;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53244: [Coverage] Fix PR39258: support coverage regions that start deeper than they end

2018-10-13 Thread Orivej Desh via Phabricator via cfe-commits
orivej created this revision.
orivej added reviewers: bogner, rsmith, vsk, aaron.ballman.
Herald added a subscriber: cfe-commits.

popRegions used to assume that the start location of a region can't be nested 
deeper than the end location, which is not always true.


Repository:
  rC Clang

https://reviews.llvm.org/D53244

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/macros.c


Index: test/CoverageMapping/macros.c
===
--- test/CoverageMapping/macros.c
+++ test/CoverageMapping/macros.c
@@ -4,6 +4,7 @@
 #define MACRO_2 bar()
 #define MACRO_1 return; MACRO_2
 #define MACRO_3 MACRO_2
+#define GOTO goto
 
 void bar() {}
 
@@ -56,6 +57,15 @@
 // CHECK-NEXT: Expansion,File 1, 6:17 -> 6:24 = #1
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #1
 
+// CHECK-NEXT: func6
+void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> 
[[@LINE+4]]:2 = #0
+begin:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> 
[[@LINE+3]]:2 = #1
+if (count--) // CHECK-NEXT: File 0, [[@LINE]]:9 -> 
[[@LINE]]:16 = #1
+GOTO begin;  // CHECK-NEXT: File 0, [[@LINE]]:9 -> 
[[@LINE]]:19 = #2
+}
+// CHECK-NEXT: Expansion,File 0, 64:9 -> 64:13 = #2
+// CHECK-NEXT: File 1, 7:14 -> 7:18 = #2
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -552,6 +552,15 @@
 completeDeferred(Count, DeferredEndLoc);
   }
 
+  size_t locactionDepth(SourceLocation Loc) {
+size_t Depth = 0;
+while (Loc.isValid()) {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  Depth++;
+}
+return Depth;
+  }
+
   /// Pop regions from the stack into the function's list of regions.
   ///
   /// Adds all regions from \c ParentIndex to the top of the stack to the
@@ -566,19 +575,35 @@
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
 : RegionStack[ParentIndex].getEndLoc();
+bool UnnestEnd = locactionDepth(EndLoc) > locactionDepth(StartLoc);
 while (!SM.isWrittenInSameFile(StartLoc, EndLoc)) {
-  // The region ends in a nested file or macro expansion. Create a
-  // separate region for each expansion.
-  SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
-  assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
-
-  if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
-SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
-
-  EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
-  if (EndLoc.isInvalid())
-llvm::report_fatal_error("File exit not handled before 
popRegions");
+  if (UnnestEnd) {
+// The region ends in a nested file or macro expansion. Create a
+// separate region for each expansion.
+SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
+assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
+
+if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
+  SourceRegions.emplace_back(Region.getCounter(), NestedLoc, 
EndLoc);
+
+EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
+if (EndLoc.isInvalid())
+  llvm::report_fatal_error("File exit not handled before 
popRegions");
+  } else {
+// The region begins in a nested file or macro expansion. Create a
+// separate region for each expansion.
+SourceLocation NestedLoc = getEndOfFileOrMacro(StartLoc);
+assert(SM.isWrittenInSameFile(StartLoc, NestedLoc));
+
+if (!isRegionAlreadyAdded(StartLoc, NestedLoc))
+  SourceRegions.emplace_back(Region.getCounter(), StartLoc, 
NestedLoc);
+
+StartLoc = getIncludeOrExpansionLoc(StartLoc);
+if (StartLoc.isInvalid())
+  llvm::report_fatal_error("File exit not handled before 
popRegions");
+  }
 }
+Region.setStartLoc(StartLoc);
 Region.setEndLoc(EndLoc);
 
 MostRecentLocation = EndLoc;


Index: test/CoverageMapping/macros.c
===
--- test/CoverageMapping/macros.c
+++ test/CoverageMapping/macros.c
@@ -4,6 +4,7 @@
 #define MACRO_2 bar()
 #define MACRO_1 return; MACRO_2
 #define MACRO_3 MACRO_2
+#define GOTO goto
 
 void bar() {}
 
@@ -56,6 +57,15 @@
 // CHECK-NEXT: Expansion,File 1, 6:17 -> 6:24 = #1
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #1
 
+// CHECK-NEXT: func6
+void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> [[@LINE+4]]:2 = #0
+begin:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #1
+if (count--) // CHECK-NEXT: File 0, 

[PATCH] D53231: [Sema] Fix PR38987: keep end location of a direct initializer list

2018-10-12 Thread Orivej Desh via Phabricator via cfe-commits
orivej created this revision.
orivej added reviewers: rsmith, vsk, aaron.ballman.
Herald added a subscriber: cfe-commits.

If PerformConstructorInitialization of a direct initializer list constructor is 
called while instantiating a template, it has brace locations in its BraceLoc 
arguments but not in the Kind argument.

This reverts the hunk https://reviews.llvm.org/D41921#inline-468844.


Repository:
  rC Clang

https://reviews.llvm.org/D53231

Files:
  lib/Sema/SemaInit.cpp
  test/SemaCXX/sourceranges.cpp


Index: test/SemaCXX/sourceranges.cpp
===
--- test/SemaCXX/sourceranges.cpp
+++ test/SemaCXX/sourceranges.cpp
@@ -52,6 +52,13 @@
   // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}}  'D' 'void 
(int){{( __attribute__\(\(thiscall\)\))?}}'
 }
 
+namespace PR38987 {
+struct A { A(); };
+template  void f() { T{}; }
+template void f();
+// CHECK: CXXTemporaryObjectExpr {{.*}}  
'PR38987::A':'PR38987::A'
+}
+
 void abort() __attribute__((noreturn));
 
 namespace std {
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -6180,7 +6180,10 @@
 TypeSourceInfo *TSInfo = Entity.getTypeSourceInfo();
 if (!TSInfo)
   TSInfo = S.Context.getTrivialTypeSourceInfo(Entity.getType(), Loc);
-SourceRange ParenOrBraceRange = Kind.getParenOrBraceRange();
+SourceRange ParenOrBraceRange =
+(Kind.getKind() == InitializationKind::IK_DirectList)
+? SourceRange(LBraceLoc, RBraceLoc)
+: Kind.getParenOrBraceRange();
 
 if (auto *Shadow = dyn_cast(
 Step.Function.FoundDecl.getDecl())) {


Index: test/SemaCXX/sourceranges.cpp
===
--- test/SemaCXX/sourceranges.cpp
+++ test/SemaCXX/sourceranges.cpp
@@ -52,6 +52,13 @@
   // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}}  'D' 'void (int){{( __attribute__\(\(thiscall\)\))?}}'
 }
 
+namespace PR38987 {
+struct A { A(); };
+template  void f() { T{}; }
+template void f();
+// CHECK: CXXTemporaryObjectExpr {{.*}}  'PR38987::A':'PR38987::A'
+}
+
 void abort() __attribute__((noreturn));
 
 namespace std {
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -6180,7 +6180,10 @@
 TypeSourceInfo *TSInfo = Entity.getTypeSourceInfo();
 if (!TSInfo)
   TSInfo = S.Context.getTrivialTypeSourceInfo(Entity.getType(), Loc);
-SourceRange ParenOrBraceRange = Kind.getParenOrBraceRange();
+SourceRange ParenOrBraceRange =
+(Kind.getKind() == InitializationKind::IK_DirectList)
+? SourceRange(LBraceLoc, RBraceLoc)
+: Kind.getParenOrBraceRange();
 
 if (auto *Shadow = dyn_cast(
 Step.Function.FoundDecl.getDecl())) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41921: [Parse] Forward brace locations to TypeConstructExpr

2018-10-12 Thread Orivej Desh via Phabricator via cfe-commits
orivej added inline comments.



Comment at: lib/Sema/SemaInit.cpp:6034
   TSInfo = S.Context.getTrivialTypeSourceInfo(Entity.getType(), Loc);
-SourceRange ParenOrBraceRange =
-  (Kind.getKind() == InitializationKind::IK_DirectList)
-  ? SourceRange(LBraceLoc, RBraceLoc)
-  : Kind.getParenRange();
+SourceRange ParenOrBraceRange = Kind.getParenOrBraceRange();
 

(Anchor for https://bugs.llvm.org/show_bug.cgi?id=38987)


Repository:
  rC Clang

https://reviews.llvm.org/D41921



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


[PATCH] D32146: PR32476: __nop_locale_mgmt.h not needed with newlib 2.5+

2017-05-15 Thread Orivej Desh via Phabricator via cfe-commits
orivej added inline comments.



Comment at: include/support/newlib/xlocale.h:20
+#if defined(__NEWLIB__) && (__NEWLIB__ == 2) \
+&& defined(__NEWLIB_MINOR__) && (__NEWLIB_MINOR__ >= 5) \
+&& (!defined(__POSIX_VISIBLE) || (__POSIX_VISIBLE < 200809))

You meant `__NEWLIB_MINOR__ < 5`.
Could not this be just the following?
```
#if __NEWLIB__ < 2 || __NEWLIB__ == 2 && __NEWLIB_MINOR__ < 5
#include 
#endif
```


https://reviews.llvm.org/D32146



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