[PATCH] D44801: Add the -fsanitize=shadow-call-stack flag

2018-03-22 Thread Kostya Serebryany via Phabricator via cfe-commits
kcc added a comment.

please also add a short comparison with Intel CET.


Repository:
  rC Clang

https://reviews.llvm.org/D44801



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


[PATCH] D44801: Add the -fsanitize=shadow-call-stack flag

2018-03-22 Thread Kostya Serebryany via Phabricator via cfe-commits
kcc added a comment.

[didn't look at the code yet, just at the docs]

Please add a docs section describing how to handle leaf functions. 
If they are not handled yet, no need to change the implementation in these 
pathches -- ok to do it later.




Comment at: docs/ShadowCallStack.rst:14
+buffer overflows. It works by saving a function's return address to a
+separately allocated 'shadow call stack' in the function prolog and checking 
the
+return address on the stack against the shadow call stack in the function

prologue/epilogue? 
(it's your native tongue, not mine, though)



Comment at: docs/ShadowCallStack.rst:20
+and trade-off consuming more memory for shorter function prologs and epilogs
+with fewer memory accesses.
+

Provide short comparison with RFG (more instructions, less memory, same racy 
attack)



Comment at: docs/ShadowCallStack.rst:38
+return address and bypass ShadowCallStack. Similarly, there is a time-of-check-
+to-time-of-use race in the function prolog where an attacker could overwrite 
the
+return address after it has been checked and before it has been returned to.

link to wikipedia maybe? 



Comment at: docs/ShadowCallStack.rst:41
+Modifying the call-return semantics to fix this on x86_64 would incur an
+unacceptable performance overhead.
+

... due to return branch predictor (or some such)



Comment at: docs/ShadowCallStack.rst:47
+not easily leak its address.
+
+Usage

Say something about attacks that first try to discover the secret location of 
the shadow call stack. 
side channels, thread spaying, whatever you have. 



Comment at: docs/ShadowCallStack.rst:74
+declaration to specify that the shadow call stack instrumentation should not be
+applied to that function, even if enabled globally.

Please add a section that shows the assembly for the following example: 

   int foo() {
  return bar() + 1;
   }


Repository:
  rC Clang

https://reviews.llvm.org/D44801



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


[PATCH] D44815: [AArch64]: Add support for parsing rN registers.

2018-03-22 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In https://reviews.llvm.org/D44815#1046451, @srhines wrote:

> Peter also requested that a test be added to make sure that rY was not 
> accepted by the Clang assembler as a true synonym for xY.


Yes, I am working on that. Wanted to send this out first.


Repository:
  rC Clang

https://reviews.llvm.org/D44815



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


[PATCH] D44815: [AArch64]: Add support for parsing rN registers.

2018-03-22 Thread Stephen Hines via Phabricator via cfe-commits
srhines added a comment.

Peter also requested that a test be added to make sure that rY was not accepted 
by the Clang assembler as a true synonym for xY.




Comment at: lib/Basic/Targets/AArch64.cpp:320
+{{"r24"}, "x24"}, {{"r25"}, "x25"}, {{"r26"}, "x26"}, {{"r27"}, "x27"},
+{{"r28"}, "x28"}, {{"r29"}, "fp"},  {{"r30"}, "lr"},
 // The S/D/Q and W/X registers overlap, but aren't really aliases; we

For x29, x30, you should really be grouping them together. For instance:

{{"r29", "fp"}, "x29}, {{"r30", "lr"}, "x30"}

This lets you remove the x29/fp and x30/lr from the first line.


Repository:
  rC Clang

https://reviews.llvm.org/D44815



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


[PATCH] D44816: [clang-format] Do not insert space before closing brace in ObjC dict literal

2018-03-22 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak, Wizard.
Herald added subscribers: cfe-commits, klimek.

Previously, `clang-format` would sometimes insert a space
before the closing brace in an Objective-C dictionary literal.

Unlike array literals (which obey `Style.SpacesInContainerLiterals`
to add a space after `[` and before `]`), Objective-C dictionary
literals currently are not meant to insert a space after `{` and before
`}`, regardless of `Style.SpacesInContainerLiterals`.

However, some constructs like `@{foo : @(bar)}` caused `clang-format`
to insert a space between `)` and `}`.

This fixes the issue and adds tests. (I understand the behavior is
not consistent between array literals and dictionary literals, but
that's existing behavior that's a much larger change.)

Test Plan: New tests added. Ran tests with:

  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D44816

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1000,6 +1000,21 @@
   "  ( id)a : ( id),\n"
   "  ( id)aa : ( id)aa,\n"
   "};");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{a12345 : a12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{(Foo *)a12345 : @(a12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{b12345: b12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{(Foo *)b12345: @(b12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   verifyFormat(
@@ -1055,6 +1070,21 @@
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @[ a12345, a12345 ];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a123 = @[ (Foo *)a12345, @(a12345) ];\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[b12345, b12345];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[(Foo *)b12345, @(b12345)];\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
   Style.ColumnLimit = 20;
   // We can't break string literals inside NSArray literals
   // (that raises -Wobjc-string-concatenation).
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2480,6 +2480,12 @@
 return false;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
 return false;
+  if (Right.is(tok::r_brace) && Right.MatchingParen &&
+  Right.MatchingParen->is(TT_DictLiteral) &&
+  Right.MatchingParen->Previous &&
+  Right.MatchingParen->Previous->is(tok::at))
+// Objective-C dictionary literal -> no space before closing brace.
+return false;
   return true;
 }
 


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1000,6 +1000,21 @@
   "  ( id)a : ( id),\n"
   "  ( id)aa : ( id)aa,\n"
   "};");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{a12345 : a12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{(Foo *)a12345 : @(a12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{b12345: b12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{(Foo *)b12345: @(b12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   verifyFormat(
@@ -1055,6 +1070,21 @@
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @[ a12345, a12345 ];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a123 = @[ (Foo *)a12345, @(a12345) ];\n"
+   "}");
+  

[PATCH] D44815: [AArch64]: Add support for parsing rN registers.

2018-03-22 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Add more context from the email communication with Peter Smith and Robin Murphy.

On 22/03/18 02:34, Manoj Gupta wrote:

> Hi Robin,
> 
> this is Manoj from Google. I was looking into implementing support for
>  parsing "r" registers in clang for AArch64 based on lkml thread
>  https://lkml.org/lkml/2018/3/1/186 ).
> 
> On the llvm bug(https://bugs.llvm.org/show_bug.cgi?id=36862#c2 ), Peter had
>  a comment that I think could be better clarified by you.
> 
> "
>  Can you be a bit more specific about where in GCC "rn" is acceptable? It is
>  certainly not true in the general case, for example:
>  ...
>  "
>  Further, my understanding is that binutils does not support "r" registers
>  in AArch64.
>  So is it correct that  GCC support limited to parsing "r" registers as "x"
>  registers and assembler will never see "r" registers?

There are two distinct things being conflated here: "r0" is not, and
never has been, a valid A64 assembly *operand*, thus indeed should never
be passed to AArch64 binutils since the latter only consumes A64
assembly syntax.

The "register ... asm("r0")" case, however, is an command to the
compiler's register allocator, not an operand to any individual assembly
instruction. GCC documents this syntax as "...the name of the register
that should be used.", and section https://reviews.llvm.org/B1.2.1 of the Armv8 
ARM[1] is quite
clear that the fundamental AArch64 registers are named R0-R30, SP, PC,
and V0-V31. It seems perfectly straightforward to me that the register
allocator would work in units of fundamental machine registers, while
access/element sizes only start to matter in the subsequent assembly
generation phase where actual instruction accesses to those registers
are emitted (and indeed where those sizes depend more on each specific
operation than the inherent size of the type being operated on).

I note that Clang *does* already understand references to SIMD "V"
registers in this context as expected[2] without demanding an explicit
access or element size.

Robin.

[1]
https://developer.arm.com/products/architecture/a-profile/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
[2]
http://lists.infradead.org/pipermail/linux-arm-kernel/2018-March/567872.html


Repository:
  rC Clang

https://reviews.llvm.org/D44815



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


[PATCH] D44815: [AArch64]: Add support for parsing rN registers.

2018-03-22 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 139556.
manojgupta added a comment.

Indenting and a minor fix.


Repository:
  rC Clang

https://reviews.llvm.org/D44815

Files:
  lib/Basic/Targets/AArch64.cpp
  test/CodeGen/aarch64-inline-asm.c


Index: test/CodeGen/aarch64-inline-asm.c
===
--- test/CodeGen/aarch64-inline-asm.c
+++ test/CodeGen/aarch64-inline-asm.c
@@ -54,3 +54,15 @@
 asm("ldxr %0, %1" : "=r"(val) : "Q"(var));
 // CHECK: call i32 asm "ldxr $0, $1", "=r,*Q"(i64* @var)
 }
+
+void test_r_registers(void) {
+register unsigned long reg0 asm("r0") = 0;
+register unsigned long reg1 asm("r1") = 1;
+register unsigned int  reg29 asm("r29") = 2;
+register unsigned int  reg30 asm("r30") = 3;
+
+asm volatile("hvc #0" : : "r" (reg0), "r" (reg1));
+asm volatile("hvc #0" : : "r" (reg29), "r" (reg30));
+// CHECK: call void asm sideeffect "hvc #0", "{x0},{x1}"
+// CHECK: call void asm sideeffect "hvc #0", "{fp},{lr}"
+}
Index: lib/Basic/Targets/AArch64.cpp
===
--- lib/Basic/Targets/AArch64.cpp
+++ lib/Basic/Targets/AArch64.cpp
@@ -309,6 +309,15 @@
 
 const TargetInfo::GCCRegAlias AArch64TargetInfo::GCCRegAliases[] = {
 {{"w31"}, "wsp"}, {{"x29"}, "fp"}, {{"x30"}, "lr"}, {{"x31"}, "sp"},
+// GCC rN registers are aliases of xN registers.
+{{"r0"}, "x0"},   {{"r1"}, "x1"},   {{"r2"}, "x2"},   {{"r3"}, "x3"},
+{{"r4"}, "x4"},   {{"r5"}, "x5"},   {{"r6"}, "x6"},   {{"r7"}, "x7"},
+{{"r8"}, "x8"},   {{"r9"}, "x9"},   {{"r10"}, "x10"}, {{"r11"}, "x11"},
+{{"r12"}, "x12"}, {{"r13"}, "x13"}, {{"r14"}, "x14"}, {{"r15"}, "x15"},
+{{"r16"}, "x16"}, {{"r17"}, "x17"}, {{"r18"}, "x18"}, {{"r19"}, "x19"},
+{{"r20"}, "x20"}, {{"r21"}, "x21"}, {{"r22"}, "x22"}, {{"r23"}, "x23"},
+{{"r24"}, "x24"}, {{"r25"}, "x25"}, {{"r26"}, "x26"}, {{"r27"}, "x27"},
+{{"r28"}, "x28"}, {{"r29"}, "fp"},  {{"r30"}, "lr"},
 // The S/D/Q and W/X registers overlap, but aren't really aliases; we
 // don't want to substitute one of these for a different-sized one.
 };


Index: test/CodeGen/aarch64-inline-asm.c
===
--- test/CodeGen/aarch64-inline-asm.c
+++ test/CodeGen/aarch64-inline-asm.c
@@ -54,3 +54,15 @@
 asm("ldxr %0, %1" : "=r"(val) : "Q"(var));
 // CHECK: call i32 asm "ldxr $0, $1", "=r,*Q"(i64* @var)
 }
+
+void test_r_registers(void) {
+register unsigned long reg0 asm("r0") = 0;
+register unsigned long reg1 asm("r1") = 1;
+register unsigned int  reg29 asm("r29") = 2;
+register unsigned int  reg30 asm("r30") = 3;
+
+asm volatile("hvc #0" : : "r" (reg0), "r" (reg1));
+asm volatile("hvc #0" : : "r" (reg29), "r" (reg30));
+// CHECK: call void asm sideeffect "hvc #0", "{x0},{x1}"
+// CHECK: call void asm sideeffect "hvc #0", "{fp},{lr}"
+}
Index: lib/Basic/Targets/AArch64.cpp
===
--- lib/Basic/Targets/AArch64.cpp
+++ lib/Basic/Targets/AArch64.cpp
@@ -309,6 +309,15 @@
 
 const TargetInfo::GCCRegAlias AArch64TargetInfo::GCCRegAliases[] = {
 {{"w31"}, "wsp"}, {{"x29"}, "fp"}, {{"x30"}, "lr"}, {{"x31"}, "sp"},
+// GCC rN registers are aliases of xN registers.
+{{"r0"}, "x0"},   {{"r1"}, "x1"},   {{"r2"}, "x2"},   {{"r3"}, "x3"},
+{{"r4"}, "x4"},   {{"r5"}, "x5"},   {{"r6"}, "x6"},   {{"r7"}, "x7"},
+{{"r8"}, "x8"},   {{"r9"}, "x9"},   {{"r10"}, "x10"}, {{"r11"}, "x11"},
+{{"r12"}, "x12"}, {{"r13"}, "x13"}, {{"r14"}, "x14"}, {{"r15"}, "x15"},
+{{"r16"}, "x16"}, {{"r17"}, "x17"}, {{"r18"}, "x18"}, {{"r19"}, "x19"},
+{{"r20"}, "x20"}, {{"r21"}, "x21"}, {{"r22"}, "x22"}, {{"r23"}, "x23"},
+{{"r24"}, "x24"}, {{"r25"}, "x25"}, {{"r26"}, "x26"}, {{"r27"}, "x27"},
+{{"r28"}, "x28"}, {{"r29"}, "fp"},  {{"r30"}, "lr"},
 // The S/D/Q and W/X registers overlap, but aren't really aliases; we
 // don't want to substitute one of these for a different-sized one.
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44815: [AArch64]: Add support for parsing rN registers.

2018-03-22 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added reviewers: kristof.beyls, rengolin, peter.smith, t.p.northover.
Herald added subscribers: eraman, javed.absar.

Allow rN registers to be simply parsed as correspoing xN registers.
The "register ... asm("rN")" is an command to the
compiler's register allocator, not an operand to any individual assembly
instruction. GCC documents this syntax as "...the name of the register
that should be used."

This is needed to support the changes in Linux kernel (see
https://lkml.org/lkml/2018/3/1/268 )

Note: This will add support only for the limited use case of
register ... asm("rN"). Any other uses that make rN leak into assembly
are not supported.


Repository:
  rC Clang

https://reviews.llvm.org/D44815

Files:
  lib/Basic/Targets/AArch64.cpp
  test/CodeGen/aarch64-inline-asm.c


Index: test/CodeGen/aarch64-inline-asm.c
===
--- test/CodeGen/aarch64-inline-asm.c
+++ test/CodeGen/aarch64-inline-asm.c
@@ -54,3 +54,15 @@
 asm("ldxr %0, %1" : "=r"(val) : "Q"(var));
 // CHECK: call i32 asm "ldxr $0, $1", "=r,*Q"(i64* @var)
 }
+
+void test_r_registers(void) {
+register unsigned long reg0 asm("r0") = 0;
+register unsigned long reg1 asm("r1") = 1;
+register unsigned int  reg29 asm("r29") = 2;
+register unsigned int  reg30 asm("r30") = 3;
+
+asm volatile("hvc #0" : : "r" (reg0), "r" (reg1));
+asm volatile("hvc #0" : : "r" (reg29), "r" (reg30));
+// CHECK: call void asm sideeffect "hvc #0", "{x0},{x1}"
+// CHECK: call void asm sideeffect "hvc #0", "{fp},{lr}"
+}
Index: lib/Basic/Targets/AArch64.cpp
===
--- lib/Basic/Targets/AArch64.cpp
+++ lib/Basic/Targets/AArch64.cpp
@@ -309,6 +309,15 @@
 
 const TargetInfo::GCCRegAlias AArch64TargetInfo::GCCRegAliases[] = {
 {{"w31"}, "wsp"}, {{"x29"}, "fp"}, {{"x30"}, "lr"}, {{"x31"}, "sp"},
+// GCC rN registers are aliases of xN registers.
+{{"r0"}, "x0"}, {{"r1"}, "x1"}, {{"r2"}, "x2"}, {{"r3"}, "x3"},
+{{"r4"}, "x4"}, {{"r5"}, "x5"}, {{"r6"}, "x6"}, {{"r7"}, "x7"},
+{{"r8"}, "x8"}, {{"r9"}, "x9"}, {{"r10"}, "x10"}, {{"r11"}, "x11"},
+{{"r12"}, "x12"}, {{"r13"}, "x13"}, {{"r14"}, "x15"}, {{"r16"}, "x16"},
+{{"r17"}, "x17"}, {{"r18"}, "x18"}, {{"r19"}, "x19"}, {{"r20"}, "x20"},
+{{"r21"}, "x21"}, {{"r22"}, "x22"}, {{"r23"}, "x23"}, {{"r24"}, "x24"},
+{{"r25"}, "x25"}, {{"r26"}, "x26"}, {{"r27"}, "x27"}, {{"r28"}, "x28"},
+{{"r29"}, "fp"}, {{"r30"}, "lr"},
 // The S/D/Q and W/X registers overlap, but aren't really aliases; we
 // don't want to substitute one of these for a different-sized one.
 };


Index: test/CodeGen/aarch64-inline-asm.c
===
--- test/CodeGen/aarch64-inline-asm.c
+++ test/CodeGen/aarch64-inline-asm.c
@@ -54,3 +54,15 @@
 asm("ldxr %0, %1" : "=r"(val) : "Q"(var));
 // CHECK: call i32 asm "ldxr $0, $1", "=r,*Q"(i64* @var)
 }
+
+void test_r_registers(void) {
+register unsigned long reg0 asm("r0") = 0;
+register unsigned long reg1 asm("r1") = 1;
+register unsigned int  reg29 asm("r29") = 2;
+register unsigned int  reg30 asm("r30") = 3;
+
+asm volatile("hvc #0" : : "r" (reg0), "r" (reg1));
+asm volatile("hvc #0" : : "r" (reg29), "r" (reg30));
+// CHECK: call void asm sideeffect "hvc #0", "{x0},{x1}"
+// CHECK: call void asm sideeffect "hvc #0", "{fp},{lr}"
+}
Index: lib/Basic/Targets/AArch64.cpp
===
--- lib/Basic/Targets/AArch64.cpp
+++ lib/Basic/Targets/AArch64.cpp
@@ -309,6 +309,15 @@
 
 const TargetInfo::GCCRegAlias AArch64TargetInfo::GCCRegAliases[] = {
 {{"w31"}, "wsp"}, {{"x29"}, "fp"}, {{"x30"}, "lr"}, {{"x31"}, "sp"},
+// GCC rN registers are aliases of xN registers.
+{{"r0"}, "x0"}, {{"r1"}, "x1"}, {{"r2"}, "x2"}, {{"r3"}, "x3"},
+{{"r4"}, "x4"}, {{"r5"}, "x5"}, {{"r6"}, "x6"}, {{"r7"}, "x7"},
+{{"r8"}, "x8"}, {{"r9"}, "x9"}, {{"r10"}, "x10"}, {{"r11"}, "x11"},
+{{"r12"}, "x12"}, {{"r13"}, "x13"}, {{"r14"}, "x15"}, {{"r16"}, "x16"},
+{{"r17"}, "x17"}, {{"r18"}, "x18"}, {{"r19"}, "x19"}, {{"r20"}, "x20"},
+{{"r21"}, "x21"}, {{"r22"}, "x22"}, {{"r23"}, "x23"}, {{"r24"}, "x24"},
+{{"r25"}, "x25"}, {{"r26"}, "x26"}, {{"r27"}, "x27"}, {{"r28"}, "x28"},
+{{"r29"}, "fp"}, {{"r30"}, "lr"},
 // The S/D/Q and W/X registers overlap, but aren't really aliases; we
 // don't want to substitute one of these for a different-sized one.
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44801: Add the -fsanitize=shadow-call-stack flag

2018-03-22 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich updated this revision to Diff 139554.
vlad.tsyrklevich added a comment.

- Add Driver tests


Repository:
  rC Clang

https://reviews.llvm.org/D44801

Files:
  docs/ShadowCallStack.rst
  docs/index.rst
  include/clang/Basic/Sanitizers.def
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChain.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/CodeGen/shadowcallstack-attr.c
  test/Driver/sanitizer-ld.c

Index: test/Driver/sanitizer-ld.c
===
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -557,6 +557,21 @@
 // CHECK-SAFESTACK-LINUX: "-lpthread"
 // CHECK-SAFESTACK-LINUX: "-ldl"
 
+// RUN: %clang -fsanitize=shadow-call-stack %s -### -o %t.o 2>&1 \
+// RUN: -target x86_64-unknown-linux -fuse-ld=ld \
+// RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-X86-64 %s
+// CHECK-SHADOWCALLSTACK-LINUX-X86-64-NOT: error:
+
+// RUN: %clang -fsanitize=shadow-call-stack %s -### -o %t.o 2>&1 \
+// RUN: -target x86-unknown-linux -fuse-ld=ld \
+// RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-X86 %s
+// CHECK-SHADOWCALLSTACK-LINUX-X86: error: unsupported option '-fsanitize=shadow-call-stack' for target 'x86-unknown-linux'
+
+// RUN: %clang -fsanitize=shadow-call-stack %s -### -o %t.o 2>&1 \
+// RUN: -fsanitize=safe-stack -target x86_64-unknown-linux -fuse-ld=ld \
+// RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-SAFESTACK %s
+// CHECK-SHADOWCALLSTACK-SAFESTACK: error: invalid argument '-fsanitize=shadow-call-stack' not allowed with '-fsanitize=safe-stack'
+
 // RUN: %clang -fsanitize=cfi -fsanitize-stats %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-linux -fuse-ld=ld \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
Index: test/CodeGen/shadowcallstack-attr.c
===
--- /dev/null
+++ test/CodeGen/shadowcallstack-attr.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-linux-unknown -emit-llvm -o - %s -fsanitize=shadow-call-stack | FileCheck %s
+
+__attribute__((no_sanitize("shadow-call-stack")))
+int foo(int *a) { return *a; }
+
+ int bar(int *a) { return *a; }
+
+// CHECK: define i32 @foo(i32* %a) #[[FOO_ATTR:[0-9]+]] {
+// CHECK: define i32 @bar(i32* %a) #[[BAR_ATTR:[0-9]+]] {
+
+// CHECK-NOT: attributes #[[FOO_ATTR]] = { {{.*}}shadowcallstack{{.*}} }
+// CHECK: attributes #[[BAR_ATTR]] = { {{.*}}shadowcallstack{{.*}} }
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -1275,6 +1275,8 @@
   .Case("is_union", LangOpts.CPlusPlus)
   .Case("modules", LangOpts.Modules)
   .Case("safe_stack", LangOpts.Sanitize.has(SanitizerKind::SafeStack))
+  .Case("shadow_call_stack",
+LangOpts.Sanitize.has(SanitizerKind::ShadowCallStack))
   .Case("tls", PP.getTargetInfo().isTLSSupported())
   .Case("underlying_type", LangOpts.CPlusPlus)
   .Default(false);
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -814,6 +814,8 @@
   getTriple().getArch() == llvm::Triple::wasm32 ||
   getTriple().getArch() == llvm::Triple::wasm64)
 Res |= CFIICall;
+  if (getTriple().getArch() == llvm::Triple::x86_64)
+Res |= ShadowCallStack;
   return Res;
 }
 
Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -343,7 +343,10 @@
   std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
 KernelAddress | Efficiency),
   std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency)};
+KernelAddress | Efficiency),
+  std::make_pair(ShadowCallStack, Address | HWAddress | Leak | Thread |
+  Memory | KernelAddress | Efficiency |
+  SafeStack)};
 
   // Enable toolchain specific default sanitizers if not explicitly disabled.
   SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -861,6 +861,8 @@
 Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
   if (SanOpts.has(SanitizerKind::SafeStack))
 Fn->addFnAttr(llvm::Attribute::SafeStack);
+  if (SanOpts.has(SanitizerKind::ShadowCallStack))
+Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
   // Ignore TSan memory acesses from within ObjC/ObjC++ dealloc, initialize,
   // .cxx_destruct, 

[PATCH] D44753: [Preprocessor] Rename __is_{target -> host}_* function-like builtin macros

2018-03-22 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith requested changes to this revision.
dexonsmith added a comment.
This revision now requires changes to proceed.

I agree with Saleem and Bob: `__is_target_*` is not confusing here and seems to 
be a straightforward spelling.  It has also already shipped in LLVM 6.0.0: it 
would be awkward to stop supporting this syntax.

Regardless, it's not clear that this patch is the right direction (i.e., we're 
not discussing the patch at all right now).  I suggest moving the discussion 
back to the wider audience on cfe-dev until we have consensus for a change.


Repository:
  rC Clang

https://reviews.llvm.org/D44753



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


r328288 - Bring r328238 back with a fix.

2018-03-22 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Thu Mar 22 18:36:23 2018
New Revision: 328288

URL: http://llvm.org/viewvc/llvm-project?rev=328288=rev
Log:
Bring r328238 back with a fix.

The issues was that we were setting hidden visibility if, when
processing a hidden class, we found out that we needed to emit a
reference to a vtable provided by the standard library.

Original message:

Set dso_local on vtables.

Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/dllexport.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=328288=328287=328288=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Thu Mar 22 18:36:23 2018
@@ -2948,6 +2948,7 @@ void ItaniumRTTIBuilder::BuildVTablePoin
 
   llvm::Constant *VTable =
 CGM.getModule().getOrInsertGlobal(VTableName, CGM.Int8PtrTy);
+  CGM.setDSOLocal(cast(VTable->stripPointerCasts()));
 
   llvm::Type *PtrDiffTy =
 CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType());

Modified: cfe/trunk/test/CodeGenCXX/dllexport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport.cpp?rev=328288=328287=328288=diff
==
--- cfe/trunk/test/CodeGenCXX/dllexport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllexport.cpp Thu Mar 22 18:36:23 2018
@@ -43,6 +43,8 @@ __declspec(dllexport) extern int ExternG
 
 // M64-DAG: @__ImageBase = external dso_local constant i8
 
+// GNU-DAG: @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global
+
 // dllexport implies a definition.
 // MSC-DAG: @"?GlobalDef@@3HA" = dso_local dllexport global i32 0, align 4
 // GNU-DAG: @GlobalDef= dso_local dllexport global i32 0, align 4


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


r328286 - Remove problematic PrettyStackTrace entry added in r328276

2018-03-22 Thread Jordan Rose via cfe-commits
Author: jrose
Date: Thu Mar 22 18:12:09 2018
New Revision: 328286

URL: http://llvm.org/viewvc/llvm-project?rev=328286=rev
Log:
Remove problematic PrettyStackTrace entry added in r328276

I'm not sure /why/ this is causing issues for libclang, but it is.
Unbreak the buildbots since it's already consumed an hour of my time.

Modified:
cfe/trunk/lib/Frontend/CompilerInstance.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=328286=328285=328286=diff
==
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Mar 22 18:12:09 2018
@@ -1170,11 +1170,6 @@ compileModuleImpl(CompilerInstance 
   llvm::CrashRecoveryContext CRC;
   CRC.RunSafelyOnThread(
   [&]() {
-SmallString<64> CrashInfoMessage("While building module for '");
-CrashInfoMessage += ModuleName;
-CrashInfoMessage += "'";
-llvm::PrettyStackTraceString CrashInfo(CrashInfoMessage.c_str());
-
 GenerateModuleFromModuleMapAction Action;
 Instance.ExecuteAction(Action);
   },


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


r328280 - [analyzer] [NFC] Move worklist implementation to WorkList.cpp

2018-03-22 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Mar 22 17:16:01 2018
New Revision: 328280

URL: http://llvm.org/viewvc/llvm-project?rev=328280=rev
Log:
[analyzer] [NFC] Move worklist implementation to WorkList.cpp

Current location is very confusing, especially because there is already
WorkList.h, and other code in CoreEngine.cpp is not related to work list
implementation.

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

Added:
cfe/trunk/lib/StaticAnalyzer/Core/WorkList.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt?rev=328280=328279=328280=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt Thu Mar 22 17:16:01 2018
@@ -51,6 +51,7 @@ add_clang_library(clangStaticAnalyzerCor
   Store.cpp
   SubEngine.cpp
   SymbolManager.cpp
+  WorkList.cpp
   Z3ConstraintManager.cpp
 
   LINK_LIBS

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp?rev=328280=328279=328280=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp Thu Mar 22 17:16:01 2018
@@ -27,21 +27,15 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/WorkList.h"
-#include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
-#include "llvm/ADT/PriorityQueue.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
 #include 
-#include 
 #include 
 #include 
-#include 
 
 using namespace clang;
 using namespace ento;
@@ -55,230 +49,6 @@ STATISTIC(NumReachedMaxSteps,
 STATISTIC(NumPathsExplored,
 "The # of paths explored by the analyzer.");
 
-STATISTIC(MaxQueueSize, "Maximum size of the worklist");
-STATISTIC(MaxReachableSize, "Maximum size of auxiliary worklist set");
-
-//===--===//
-// Worklist classes for exploration of reachable states.
-//===--===//
-
-namespace {
-
-class DFS : public WorkList {
-  SmallVector Stack;
-
-public:
-  bool hasWork() const override {
-return !Stack.empty();
-  }
-
-  void enqueue(const WorkListUnit& U) override {
-Stack.push_back(U);
-  }
-
-  WorkListUnit dequeue() override {
-assert(!Stack.empty());
-const WorkListUnit& U = Stack.back();
-Stack.pop_back(); // This technically "invalidates" U, but we are fine.
-return U;
-  }
-};
-
-class BFS : public WorkList {
-  std::deque Queue;
-
-public:
-  bool hasWork() const override {
-return !Queue.empty();
-  }
-
-  void enqueue(const WorkListUnit& U) override {
-Queue.push_back(U);
-  }
-
-  WorkListUnit dequeue() override {
-WorkListUnit U = Queue.front();
-Queue.pop_front();
-return U;
-  }
-};
-
-} // namespace
-
-// Place the dstor for WorkList here because it contains virtual member
-// functions, and we the code for the dstor generated in one compilation unit.
-WorkList::~WorkList() = default;
-
-std::unique_ptr WorkList::makeDFS() {
-  return llvm::make_unique();
-}
-
-std::unique_ptr WorkList::makeBFS() {
-  return llvm::make_unique();
-}
-
-namespace {
-
-  class BFSBlockDFSContents : public WorkList {
-std::deque Queue;
-SmallVector Stack;
-
-  public:
-bool hasWork() const override {
-  return !Queue.empty() || !Stack.empty();
-}
-
-void enqueue(const WorkListUnit& U) override {
-  if (U.getNode()->getLocation().getAs())
-Queue.push_front(U);
-  else
-Stack.push_back(U);
-}
-
-WorkListUnit dequeue() override {
-  // Process all basic blocks to completion.
-  if (!Stack.empty()) {
-const WorkListUnit& U = Stack.back();
-Stack.pop_back(); // This technically "invalidates" U, but we are fine.
-return U;
-  }
-
-  assert(!Queue.empty());
-  // Don't use const reference.  The subsequent pop_back() might make it
-  // unsafe.
-  WorkListUnit U = Queue.front();
-  Queue.pop_front();
-  return U;
-}
-  };
-
-} // namespace
-
-std::unique_ptr WorkList::makeBFSBlockDFSContents() {
-  return llvm::make_unique();
-}
-
-namespace {
-
-class UnexploredFirstStack : public WorkList {
-  /// Stack of nodes known to have statements we 

r328282 - [analyzer] Trust _Nonnull annotations for system framework

2018-03-22 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Mar 22 17:16:03 2018
New Revision: 328282

URL: http://llvm.org/viewvc/llvm-project?rev=328282=rev
Log:
[analyzer] Trust _Nonnull annotations for system framework

Changes the analyzer to believe that methods annotated with _Nonnull
from system frameworks indeed return non null objects.
Local methods with such annotation are still distrusted.
rdar://24291919

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

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/TrustNonnullChecker.cpp
cfe/trunk/test/Analysis/trustnonnullchecker_test.m
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-nullability.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=328282=328281=328282=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Thu Mar 22 
17:16:03 2018
@@ -218,6 +218,14 @@ def NullableReturnedFromNonnullChecker :
 
 } // end "nullability"
 
+let ParentPackage = APIModeling in {
+
+def TrustNonnullChecker : Checker<"TrustNonnull">,
+  HelpText<"Trust that returns from framework methods annotated with _Nonnull 
are not null">,
+  DescFile<"TrustNonnullChecker.cpp">;
+
+}
+
 
//===--===//
 // Evaluate "builtin" functions.
 
//===--===//

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h?rev=328282=328281=328282=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h 
Thu Mar 22 17:16:03 2018
@@ -21,6 +21,8 @@ namespace clang {
 
 class Expr;
 class VarDecl;
+class QualType;
+class AttributedType;
 
 namespace ento {
 
@@ -42,6 +44,25 @@ template  bool containsStmt(con
 std::pair
 parseAssignment(const Stmt *S);
 
+// Do not reorder! The getMostNullable method relies on the order.
+// Optimization: Most pointers expected to be unspecified. When a symbol has an
+// unspecified or nonnull type non of the rules would indicate any problem for
+// that symbol. For this reason only nullable and contradicted nullability are
+// stored for a symbol. When a symbol is already contradicted, it can not be
+// casted back to nullable.
+enum class Nullability : char {
+  Contradicted, // Tracked nullability is contradicted by an explicit cast. Do
+// not report any nullability related issue for this symbol.
+// This nullability is propagated aggressively to avoid false
+// positive results. See the comment on getMostNullable method.
+  Nullable,
+  Unspecified,
+  Nonnull
+};
+
+/// Get nullability annotation for a given type.
+Nullability getNullabilityAnnotation(QualType Type);
+
 } // end GR namespace
 
 } // end clang namespace

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=328282=328281=328282=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Thu Mar 22 17:16:03 
2018
@@ -84,6 +84,7 @@ add_clang_library(clangStaticAnalyzerChe
   TaintTesterChecker.cpp
   TestAfterDivZeroChecker.cpp
   TraversalChecker.cpp
+  TrustNonnullChecker.cpp
   UndefBranchChecker.cpp
   UndefCapturedBlockVarChecker.cpp
   UndefResultChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp?rev=328282=328281=328282=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp Thu Mar 22 
17:16:03 2018
@@ -30,6 +30,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include 

r328281 - [analyzer] Extend GCDAntipatternChecker to match group_enter/group_leave pattern

2018-03-22 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Mar 22 17:16:02 2018
New Revision: 328281

URL: http://llvm.org/viewvc/llvm-project?rev=328281=rev
Log:
[analyzer] Extend GCDAntipatternChecker to match group_enter/group_leave pattern

rdar://38480416

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp
cfe/trunk/test/Analysis/gcdantipatternchecker_test.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp?rev=328281=328280=328281=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp Thu Mar 22 
17:16:02 2018
@@ -43,7 +43,8 @@ using namespace ast_matchers;
 
 namespace {
 
-const char *WarningBinding = "semaphore_wait";
+// ID of a node at which the diagnostic would be emitted.
+const char *WarnAtNode = "waitcall";
 
 class GCDAntipatternChecker : public Checker {
 public:
@@ -52,19 +53,6 @@ public:
 BugReporter ) const;
 };
 
-class Callback : public MatchFinder::MatchCallback {
-  BugReporter 
-  const GCDAntipatternChecker *C;
-  AnalysisDeclContext *ADC;
-
-public:
-  Callback(BugReporter ,
-   AnalysisDeclContext *ADC,
-   const GCDAntipatternChecker *C) : BR(BR), C(C), ADC(ADC) {}
-
-  virtual void run(const MatchFinder::MatchResult ) override;
-};
-
 auto callsName(const char *FunctionName)
 -> decltype(callee(functionDecl())) {
   return callee(functionDecl(hasName(FunctionName)));
@@ -81,24 +69,28 @@ auto bindAssignmentToDecl(const char *De
  declRefExpr(to(varDecl().bind(DeclName);
 }
 
-void GCDAntipatternChecker::checkASTCodeBody(const Decl *D,
-   AnalysisManager ,
-   BugReporter ) const {
-
-  // The pattern is very common in tests, and it is OK to use it there.
+/// The pattern is very common in tests, and it is OK to use it there.
+/// We have to heuristics for detecting tests: method name starts with "test"
+/// (used in XCTest), and a class name contains "mock" or "test" (used in
+/// helpers which are not tests themselves, but used exclusively in tests).
+static bool isTest(const Decl *D) {
   if (const auto* ND = dyn_cast(D)) {
 std::string DeclName = ND->getNameAsString();
 if (StringRef(DeclName).startswith("test"))
-  return;
+  return true;
   }
   if (const auto *OD = dyn_cast(D)) {
 if (const auto *CD = dyn_cast(OD->getParent())) {
   std::string ContainerName = CD->getNameAsString();
   StringRef CN(ContainerName);
   if (CN.contains_lower("test") || CN.contains_lower("mock"))
-return;
+return true;
 }
   }
+  return false;
+}
+
+static auto findGCDAntiPatternWithSemaphore() -> decltype(compoundStmt()) {
 
   const char *SemaphoreBinding = "semaphore_name";
   auto SemaphoreCreateM = callExpr(callsName("dispatch_semaphore_create"));
@@ -109,13 +101,51 @@ void GCDAntipatternChecker::checkASTCode
   forEachDescendant(binaryOperator(bindAssignmentToDecl(SemaphoreBinding),
  hasRHS(SemaphoreCreateM;
 
+  auto HasBlockArgumentM = hasAnyArgument(hasType(
+hasCanonicalType(blockPointerType())
+));
+
+  auto ArgCallsSignalM = hasAnyArgument(stmt(hasDescendant(callExpr(
+  allOf(
+  callsName("dispatch_semaphore_signal"),
+  equalsBoundArgDecl(0, SemaphoreBinding)
+  );
+
+  auto HasBlockAndCallsSignalM = allOf(HasBlockArgumentM, ArgCallsSignalM);
+
+  auto HasBlockCallingSignalM =
+forEachDescendant(
+  stmt(anyOf(
+callExpr(HasBlockAndCallsSignalM),
+objcMessageExpr(HasBlockAndCallsSignalM)
+   )));
+
   auto SemaphoreWaitM = forEachDescendant(
 callExpr(
   allOf(
 callsName("dispatch_semaphore_wait"),
 equalsBoundArgDecl(0, SemaphoreBinding)
   )
-).bind(WarningBinding));
+).bind(WarnAtNode));
+
+  return compoundStmt(
+  SemaphoreBindingM, HasBlockCallingSignalM, SemaphoreWaitM);
+}
+
+static auto findGCDAntiPatternWithGroup() -> decltype(compoundStmt()) {
+
+  const char *GroupBinding = "group_name";
+  auto DispatchGroupCreateM = callExpr(callsName("dispatch_group_create"));
+
+  auto GroupBindingM = anyOf(
+  forEachDescendant(
+  varDecl(hasDescendant(DispatchGroupCreateM)).bind(GroupBinding)),
+  forEachDescendant(binaryOperator(bindAssignmentToDecl(GroupBinding),
+ hasRHS(DispatchGroupCreateM;
+
+  auto GroupEnterM = forEachDescendant(
+  stmt(callExpr(allOf(callsName("dispatch_group_enter"),
+  equalsBoundArgDecl(0, GroupBinding);
 
   auto HasBlockArgumentM 

r328283 - [Modules] Update test to mention it requires C++14.

2018-03-22 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Mar 22 17:16:06 2018
New Revision: 328283

URL: http://llvm.org/viewvc/llvm-project?rev=328283=rev
Log:
[Modules] Update test to mention it requires C++14.

Modified:
cfe/trunk/test/Modules/self-referencing-lambda.cpp

Modified: cfe/trunk/test/Modules/self-referencing-lambda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/self-referencing-lambda.cpp?rev=328283=328282=328283=diff
==
--- cfe/trunk/test/Modules/self-referencing-lambda.cpp (original)
+++ cfe/trunk/test/Modules/self-referencing-lambda.cpp Thu Mar 22 17:16:06 2018
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I 
%S/Inputs/self-referencing-lambda %s -verify -emit-obj -o %t2.o
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I 
%S/Inputs/self-referencing-lambda %s -verify -emit-obj -std=c++14 -o %t2.o
 // expected-no-diagnostics
 
 #include "a.h"


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


r328277 - [ARM] Add ARMv8.2-A FP16 vector intrinsic

2018-03-22 Thread Abderrazek Zaafrani via cfe-commits
Author: az
Date: Thu Mar 22 17:08:40 2018
New Revision: 328277

URL: http://llvm.org/viewvc/llvm-project?rev=328277=rev
Log:
[ARM] Add ARMv8.2-A FP16 vector intrinsic

Putting back the code in commit r327189 that was reverted in r322737. The code 
is being committed in three stages and this one is the last stage: 1) r327455 
fp16 feature flags, 2) r327836 pass half type or i16 based on FullFP16, and 3) 
the code here which the front-end fp16 vector intrinsic for ARM.

Differential revision https://reviews.llvm.org/D43650

Added:
cfe/trunk/test/CodeGen/arm-v8.2a-neon-intrinsics.c
Modified:
cfe/trunk/include/clang/Basic/arm_neon.td
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/include/clang/Basic/arm_neon.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/arm_neon.td?rev=328277=328276=328277=diff
==
--- cfe/trunk/include/clang/Basic/arm_neon.td (original)
+++ cfe/trunk/include/clang/Basic/arm_neon.td Thu Mar 22 17:08:40 2018
@@ -1363,8 +1363,8 @@ def SCALAR_VDUP_LANE : IInst<"vdup_lane"
 def SCALAR_VDUP_LANEQ : IInst<"vdup_laneq", "sji", 
"ScSsSiSlSfSdSUcSUsSUiSUlSPcSPs">;
 }
 
-// ARMv8.2-A FP16 intrinsics.
-let ArchGuard = "defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && 
defined(__aarch64__)" in {
+// ARMv8.2-A FP16 vector intrinsics for A32/A64.
+let ArchGuard = "defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)" in {
 
   // ARMv8.2-A FP16 one-operand vector intrinsics.
 
@@ -1395,14 +1395,12 @@ let ArchGuard = "defined(__ARM_FEATURE_F
   def FRINTPH  : SInst<"vrndp", "dd", "hQh">;
   def FRINTMH  : SInst<"vrndm", "dd", "hQh">;
   def FRINTXH  : SInst<"vrndx", "dd", "hQh">;
-  def FRINTIH  : SInst<"vrndi", "dd", "hQh">;
 
   // Misc.
   def VABSH: SInst<"vabs", "dd", "hQh">;
   def VNEGH: SOpInst<"vneg", "dd", "hQh", OP_NEG>;
   def VRECPEH  : SInst<"vrecpe", "dd", "hQh">;
   def FRSQRTEH : SInst<"vrsqrte", "dd", "hQh">;
-  def FSQRTH   : SInst<"vsqrt", "dd", "hQh">;
 
   // ARMv8.2-A FP16 two-operands vector intrinsics.
 
@@ -1443,18 +1441,13 @@ let ArchGuard = "defined(__ARM_FEATURE_F
 
   // Multiplication/Division
   def VMULH : SOpInst<"vmul", "ddd", "hQh", OP_MUL>;
-  def MULXH : SInst<"vmulx", "ddd", "hQh">;
-  def FDIVH : IOpInst<"vdiv", "ddd",  "hQh", OP_DIV>;
 
   // Pairwise addition
-  def VPADDH: SInst<"vpadd", "ddd", "hQh">;
+  def VPADDH: SInst<"vpadd", "ddd", "h">;
 
   // Pairwise Max/Min
-  def VPMAXH: SInst<"vpmax", "ddd", "hQh">;
-  def VPMINH: SInst<"vpmin", "ddd", "hQh">;
-  // Pairwise MaxNum/MinNum
-  def FMAXNMPH  : SInst<"vpmaxnm", "ddd", "hQh">;
-  def FMINNMPH  : SInst<"vpminnm", "ddd", "hQh">;
+  def VPMAXH: SInst<"vpmax", "ddd", "h">;
+  def VPMINH: SInst<"vpmin", "ddd", "h">;
 
   // Reciprocal/Sqrt
   def VRECPSH   : SInst<"vrecps", "ddd", "hQh">;
@@ -1468,6 +1461,63 @@ let ArchGuard = "defined(__ARM_FEATURE_F
 
   // ARMv8.2-A FP16 lane vector intrinsics.
 
+  // Mul lane
+  def VMUL_LANEH: IOpInst<"vmul_lane", "ddgi", "hQh", OP_MUL_LN>;
+  def VMUL_NH   : IOpInst<"vmul_n", "dds", "hQh", OP_MUL_N>;
+
+  // Data processing intrinsics - section 5
+
+  // Logical operations
+  let isHiddenLInst = 1 in
+  def VBSLH: SInst<"vbsl", "dudd", "hQh">;
+
+  // Transposition operations
+  def VZIPH: WInst<"vzip", "2dd", "hQh">;
+  def VUZPH: WInst<"vuzp", "2dd", "hQh">;
+  def VTRNH: WInst<"vtrn", "2dd", "hQh">;
+
+
+  let ArchGuard = "!defined(__aarch64__)" in {
+// Set all lanes to same value.
+// Already implemented prior to ARMv8.2-A.
+def VMOV_NH  : WOpInst<"vmov_n", "ds", "hQh", OP_DUP>;
+def VDUP_NH  : WOpInst<"vdup_n", "ds", "hQh", OP_DUP>;
+def VDUP_LANE1H : WOpInst<"vdup_lane", "dgi", "hQh", OP_DUP_LN>;
+  }
+
+  // Vector Extract
+  def VEXTH  : WInst<"vext", "dddi", "hQh">;
+
+  // Reverse vector elements
+  def VREV64H: WOpInst<"vrev64", "dd", "hQh", OP_REV64>;
+}
+
+// ARMv8.2-A FP16 vector intrinsics for A64 only.
+let ArchGuard = "defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && 
defined(__aarch64__)" in {
+
+  // Vector rounding
+  def FRINTIH  : SInst<"vrndi", "dd", "hQh">;
+
+  // Misc.
+  def FSQRTH   : SInst<"vsqrt", "dd", "hQh">;
+
+  // Multiplication/Division
+  def MULXH : SInst<"vmulx", "ddd", "hQh">;
+  def FDIVH : IOpInst<"vdiv", "ddd",  "hQh", OP_DIV>;
+
+  // Pairwise addition
+  def VPADDH1   : SInst<"vpadd", "ddd", "Qh">;
+
+  // Pairwise Max/Min
+  def VPMAXH1   : SInst<"vpmax", "ddd", "Qh">;
+  def VPMINH1   : SInst<"vpmin", "ddd", "Qh">;
+
+  // Pairwise MaxNum/MinNum
+  def FMAXNMPH  : SInst<"vpmaxnm", "ddd", "hQh">;
+  def FMINNMPH  : SInst<"vpminnm", "ddd", "hQh">;
+
+  // ARMv8.2-A FP16 lane vector intrinsics.
+
   // FMA lane
   def VFMA_LANEH   : IInst<"vfma_lane", "dddgi", "hQh">;
   def VFMA_LANEQH  : 

[PATCH] D44498: Sink PrettyDeclStackTrace down to the AST library

2018-03-22 Thread Jordan Rose via Phabricator via cfe-commits
jordan_rose closed this revision.
jordan_rose added a comment.

Committed in https://reviews.llvm.org/rL328276.


Repository:
  rC Clang

https://reviews.llvm.org/D44498



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


r328276 - Sink PrettyDeclStackTrace down to the AST library

2018-03-22 Thread Jordan Rose via cfe-commits
Author: jrose
Date: Thu Mar 22 17:07:18 2018
New Revision: 328276

URL: http://llvm.org/viewvc/llvm-project?rev=328276=rev
Log:
Sink PrettyDeclStackTrace down to the AST library

...and add some very basic stack trace entries for module building.
This would have helped track down rdar://problem/38434694 sooner.

Added:
cfe/trunk/include/clang/AST/PrettyDeclStackTrace.h
  - copied, changed from r328258, 
cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h
Removed:
cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Copied: cfe/trunk/include/clang/AST/PrettyDeclStackTrace.h (from r328258, 
cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyDeclStackTrace.h?p2=cfe/trunk/include/clang/AST/PrettyDeclStackTrace.h=cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h=328258=328276=328276=diff
==
--- cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h (original)
+++ cfe/trunk/include/clang/AST/PrettyDeclStackTrace.h Thu Mar 22 17:07:18 2018
@@ -13,31 +13,31 @@
 //
 
//===--===//
 
-#ifndef LLVM_CLANG_SEMA_PRETTYDECLSTACKTRACE_H
-#define LLVM_CLANG_SEMA_PRETTYDECLSTACKTRACE_H
+#ifndef LLVM_CLANG_AST_PRETTYDECLSTACKTRACE_H
+#define LLVM_CLANG_AST_PRETTYDECLSTACKTRACE_H
 
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/Support/PrettyStackTrace.h"
 
 namespace clang {
 
+class ASTContext;
 class Decl;
-class Sema;
 class SourceManager;
 
 /// PrettyDeclStackTraceEntry - If a crash occurs in the parser while
 /// parsing something related to a declaration, include that
 /// declaration in the stack trace.
 class PrettyDeclStackTraceEntry : public llvm::PrettyStackTraceEntry {
-  Sema 
+  ASTContext 
   Decl *TheDecl;
   SourceLocation Loc;
   const char *Message;
 
 public:
-  PrettyDeclStackTraceEntry(Sema , Decl *D, SourceLocation Loc,
+  PrettyDeclStackTraceEntry(ASTContext , Decl *D, SourceLocation Loc,
 const char *Msg)
-: S(S), TheDecl(D), Loc(Loc), Message(Msg) {}
+: Context(Ctx), TheDecl(D), Loc(Loc), Message(Msg) {}
 
   void print(raw_ostream ) const override;
 };

Removed: cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h?rev=328275=auto
==
--- cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h (original)
+++ cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h (removed)
@@ -1,47 +0,0 @@
-//===- PrettyDeclStackTrace.h - Stack trace for decl processing -*- C++ 
-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-//
-// This file defines an llvm::PrettyStackTraceEntry object for showing
-// that a particular declaration was being processed when a crash
-// occurred.
-//
-//===--===//
-
-#ifndef LLVM_CLANG_SEMA_PRETTYDECLSTACKTRACE_H
-#define LLVM_CLANG_SEMA_PRETTYDECLSTACKTRACE_H
-
-#include "clang/Basic/SourceLocation.h"
-#include "llvm/Support/PrettyStackTrace.h"
-
-namespace clang {
-
-class Decl;
-class Sema;
-class SourceManager;
-
-/// PrettyDeclStackTraceEntry - If a crash occurs in the parser while
-/// parsing something related to a declaration, include that
-/// declaration in the stack trace.
-class PrettyDeclStackTraceEntry : public llvm::PrettyStackTraceEntry {
-  Sema 
-  Decl *TheDecl;
-  SourceLocation Loc;
-  const char *Message;
-
-public:
-  PrettyDeclStackTraceEntry(Sema , Decl *D, SourceLocation Loc,
-const char *Msg)
-: S(S), TheDecl(D), Loc(Loc), Message(Msg) {}
-
-  void print(raw_ostream ) const override;
-};
-
-}
-
-#endif

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=328276=328275=328276=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Mar 22 17:07:18 2018
@@ -27,6 +27,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/ODRHash.h"
+#include "clang/AST/PrettyDeclStackTrace.h"
 

[PATCH] D44804: [StaticAnalyzer] Silence an unused variable warning. NFC.

2018-03-22 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang abandoned this revision.
mgrang added a comment.

This seems to already have been fixed in r327802. Abandoning this patch.


Repository:
  rC Clang

https://reviews.llvm.org/D44804



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


[PATCH] D44745: [HWASan] Port HWASan to Linux x86-64 (clang)

2018-03-22 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

OK, sure, If you feel so strongly about this.


Repository:
  rC Clang

https://reviews.llvm.org/D44745



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


[clang-tools-extra] r328270 - [clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework"

2018-03-22 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Thu Mar 22 16:34:46 2018
New Revision: 328270

URL: http://llvm.org/viewvc/llvm-project?rev=328270=rev
Log:
[clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework"

Fixed windows release build tests.

Added:
clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
clang-tools-extra/trunk/clang-doc/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
clang-tools-extra/trunk/clang-doc/ClangDoc.h
clang-tools-extra/trunk/clang-doc/Mapper.cpp
clang-tools-extra/trunk/clang-doc/Mapper.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/clang-doc/Serialize.h
clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-comments.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-enum.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-method.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-struct.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-union.cpp
Modified:
clang-tools-extra/trunk/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=328270=328269=328270=diff
==
--- clang-tools-extra/trunk/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/CMakeLists.txt Thu Mar 22 16:34:46 2018
@@ -7,6 +7,7 @@ add_subdirectory(clang-tidy-vs)
 endif()
 
 add_subdirectory(change-namespace)
+add_subdirectory(clang-doc)
 add_subdirectory(clang-query)
 add_subdirectory(clang-move)
 add_subdirectory(clangd)

Added: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=328270=auto
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (added)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Thu Mar 22 16:34:46 2018
@@ -0,0 +1,510 @@
+//===--  BitcodeWriter.cpp - ClangDoc Bitcode Writer *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "BitcodeWriter.h"
+#include "llvm/ADT/IndexedMap.h"
+#include 
+
+namespace clang {
+namespace doc {
+
+// Since id enums are not zero-indexed, we need to transform the given id into
+// its associated index.
+struct BlockIdToIndexFunctor {
+  using argument_type = unsigned;
+  unsigned operator()(unsigned ID) const { return ID - BI_FIRST; }
+};
+
+struct RecordIdToIndexFunctor {
+  using argument_type = unsigned;
+  unsigned operator()(unsigned ID) const { return ID - RI_FIRST; }
+};
+
+using AbbrevDsc = void (*)(std::shared_ptr );
+
+static void AbbrevGen(std::shared_ptr ,
+  const std::initializer_list Ops) {
+  for (const auto  : Ops)
+Abbrev->Add(Op);
+}
+
+static void BoolAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Boolean
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::BoolSize)});
+}
+
+static void IntAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::IntSize)});
+}
+
+static void SymbolIDAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer (length of the sha1'd USR)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::USRLengthSize),
+ // 1. Fixed-size array of Char6 (USR)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array),
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::USRBitLengthSize)});
+}
+
+static void StringAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer (length of the following string)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::StringLengthSize),
+ // 1. The string blob
+ 

[libcxx] r328268 - Add temporary printouts to test to help debug failures.

2018-03-22 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Mar 22 16:14:20 2018
New Revision: 328268

URL: http://llvm.org/viewvc/llvm-project?rev=328268=rev
Log:
Add temporary printouts to test to help debug failures.

Some debian libc++ bots started having failures in the locale
tests due to what I assume is a change in the locale data for fr_FR
in glibc.

This change prints the actual value from the test to help debugging.
It should be reverted once the bots cycle.

Modified:

libcxx/trunk/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/decimal_point.pass.cpp

libcxx/trunk/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp

Modified: 
libcxx/trunk/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/decimal_point.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/decimal_point.pass.cpp?rev=328268=328267=328268=diff
==
--- 
libcxx/trunk/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/decimal_point.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/decimal_point.pass.cpp
 Thu Mar 22 16:14:20 2018
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include  // FIXME: for debugging purposes only
 
 #include "test_macros.h"
 #include "platform_support.h" // locale name macros
@@ -119,6 +120,11 @@ int main()
 #endif
 {
 Fnf f(LOCALE_ru_RU_UTF_8, 1);
+if (f.decimal_point() != sep) {
+std::cout << "f.decimal_point() = '" << f.decimal_point() << "'\n";
+std::cout << "sep = '" << sep << "'\n";
+std::cout << std::endl;
+}
 assert(f.decimal_point() == sep);
 }
 {

Modified: 
libcxx/trunk/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp?rev=328268=328267=328268=diff
==
--- 
libcxx/trunk/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
 Thu Mar 22 16:14:20 2018
@@ -19,6 +19,7 @@
 
 #include 
 #include 
+#include  // FIXME: for debugging purposes only
 
 #include "test_macros.h"
 #include "platform_support.h" // locale name macros
@@ -63,6 +64,11 @@ int main()
 {
 typedef char C;
 const std::numpunct& np = std::use_facet(l);
+if (np.thousands_sep() != sep) {
+  std::cout << "np.thousands_sep() = '" << np.thousands_sep() << 
"'\n";
+  std::cout << "sep = '" << sep << "'\n";
+  std::cout << std::endl;
+}
 assert(np.thousands_sep() == sep);
 }
 {


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


[PATCH] D44778: [clang-format] Wildcard expansion on Windows.

2018-03-22 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D44778#1046301, @alexfh wrote:

> In https://reviews.llvm.org/D44778#1046251, @rnk wrote:
>
> > Use `llvm::sys::Process::GetArgumentVector`, which already does wildcard 
> > expansion from what I can see. It works with Unicode command lines and 
> > isn't affected by locale.
>
>
> I vaguely remember that windows console applications have to define wmain() 
> instead of main() in order to work with unicode. Does 
> `llvm::sys::Process::GetArgumentVector` allow to work around this?


Never mind. I looked at the windows implementation and see how =)

Thanks for the pointer. I'll update the patch.


Repository:
  rC Clang

https://reviews.llvm.org/D44778



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


[PATCH] D44805: Set dso_local on __ImageBase

2018-03-22 Thread Rafael Avila de Espindola via Phabricator via cfe-commits
espindola closed this revision.
espindola added a comment.

328266


https://reviews.llvm.org/D44805



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


r328266 - Set dso_local on __ImageBase.

2018-03-22 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Thu Mar 22 16:02:19 2018
New Revision: 328266

URL: http://llvm.org/viewvc/llvm-project?rev=328266=rev
Log:
Set dso_local on __ImageBase.

Modified:
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGenCXX/dllexport.cpp

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=328266=328265=328266=diff
==
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Thu Mar 22 16:02:19 2018
@@ -523,10 +523,12 @@ public:
 if (llvm::GlobalVariable *GV = CGM.getModule().getNamedGlobal(Name))
   return GV;
 
-return new llvm::GlobalVariable(CGM.getModule(), CGM.Int8Ty,
-/*isConstant=*/true,
-llvm::GlobalValue::ExternalLinkage,
-/*Initializer=*/nullptr, Name);
+auto *GV = new llvm::GlobalVariable(CGM.getModule(), CGM.Int8Ty,
+/*isConstant=*/true,
+llvm::GlobalValue::ExternalLinkage,
+/*Initializer=*/nullptr, Name);
+CGM.setDSOLocal(GV);
+return GV;
   }
 
   llvm::Constant *getImageRelativeConstant(llvm::Constant *PtrVal) {

Modified: cfe/trunk/test/CodeGenCXX/dllexport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport.cpp?rev=328266=328265=328266=diff
==
--- cfe/trunk/test/CodeGenCXX/dllexport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllexport.cpp Thu Mar 22 16:02:19 2018
@@ -41,6 +41,8 @@ struct External { int v; };
 // GNU-NOT: @ExternGlobalDecl
 __declspec(dllexport) extern int ExternGlobalDecl;
 
+// M64-DAG: @__ImageBase = external dso_local constant i8
+
 // dllexport implies a definition.
 // MSC-DAG: @"?GlobalDef@@3HA" = dso_local dllexport global i32 0, align 4
 // GNU-DAG: @GlobalDef= dso_local dllexport global i32 0, align 4


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


[libcxx] r328265 - Avoid Clang error about throwing _LIBCPP_ASSERT in noexcept function.

2018-03-22 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Mar 22 16:01:08 2018
New Revision: 328265

URL: http://llvm.org/viewvc/llvm-project?rev=328265=rev
Log:
Avoid Clang error about throwing _LIBCPP_ASSERT in noexcept function.

This fixes a couple of tests which produced a warning that a 'throw'
occurred in a noexcept function (by way of _LIBCPP_ASSERT). It does
so by hiding the 'throw' across an opaque function boundary.

This fix isn't ideal, since we still have _LIBCPP_ASSERT's in functions
marked noexcept -- and this problem should be addressed in the future.
However, throwing _LIBCPP_ASSERT is really only meant to allow testing
of the assertions, and is not yet ready for general use.

Modified:

libcxx/trunk/test/libcxx/experimental/filesystem/class.path/path.itr/iterator_db.pass.cpp

libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp

libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
libcxx/trunk/utils/libcxx/test/config.py

Modified: 
libcxx/trunk/test/libcxx/experimental/filesystem/class.path/path.itr/iterator_db.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/filesystem/class.path/path.itr/iterator_db.pass.cpp?rev=328265=328264=328265=diff
==
--- 
libcxx/trunk/test/libcxx/experimental/filesystem/class.path/path.itr/iterator_db.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/experimental/filesystem/class.path/path.itr/iterator_db.pass.cpp
 Thu Mar 22 16:01:08 2018
@@ -10,13 +10,15 @@
 // UNSUPPORTED: c++98, c++03
 // UNSUPPORTED: libcpp-no-exceptions
 
+// MODULES_DEFINES: _LIBCPP_DEBUG_USE_EXCEPTIONS
+// MODULES_DEFINES: _LIBCPP_DEBUG=0
+
 // 
 
 // class path
 
 #define _LIBCPP_DEBUG 0
-#define _LIBCPP_ASSERT(cond, msg) ((cond) ? ((void)0) : throw 42)
-
+#define _LIBCPP_DEBUG_USE_EXCEPTIONS
 #include 
 #include 
 #include 
@@ -29,17 +31,18 @@ namespace fs = std::experimental::filesy
 
 int main() {
   using namespace fs;
+  using ExType = std::__libcpp_debug_exception;
   // Test incrementing/decrementing a singular iterator
   {
 path::iterator singular;
 try {
   ++singular;
   assert(false);
-} catch (int) {}
+} catch (ExType const&) {}
 try {
   --singular;
   assert(false);
-} catch (int) {}
+} catch (ExType const&) {}
   }
   // Test decrementing the begin iterator
   {
@@ -48,13 +51,13 @@ int main() {
 try {
   --it;
   assert(false);
-} catch (int) {}
+} catch (ExType const&) {}
 ++it;
 ++it;
 try {
   ++it;
   assert(false);
-} catch (int) {}
+} catch (ExType const&) {}
   }
   // Test incrementing the end iterator
   {
@@ -63,12 +66,12 @@ int main() {
 try {
   ++it;
   assert(false);
-} catch (int) {}
+} catch (ExType const&) {}
 --it;
 --it;
 try {
   --it;
   assert(false);
-} catch (int) {}
+} catch (ExType const&) {}
   }
 }

Modified: 
libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp?rev=328265=328264=328265=diff
==
--- 
libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp 
(original)
+++ 
libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp 
Thu Mar 22 16:01:08 2018
@@ -11,6 +11,9 @@
 // UNSUPPORTED: libcpp-has-no-threads
 // UNSUPPORTED: c++98, c++03
 
+// MODULES_DEFINES: _LIBCPP_DEBUG_USE_EXCEPTIONS
+// MODULES_DEFINES: _LIBCPP_DEBUG=0
+
 // 
 
 // class promise
@@ -18,9 +21,8 @@
 // void set_exception(exception_ptr p);
 // Test that a null exception_ptr is diagnosed.
 
-#define _LIBCPP_ASSERT(x, m) ((x) ? ((void)0) : throw 42)
-
 #define _LIBCPP_DEBUG 0
+#define _LIBCPP_DEBUG_USE_EXCEPTIONS
 #include 
 #include 
 #include 
@@ -29,14 +31,14 @@
 
 int main()
 {
+typedef std::__libcpp_debug_exception ExType;
 {
 typedef int T;
 std::promise p;
 try {
 p.set_exception(std::exception_ptr());
 assert(false);
-} catch (int const& value) {
-assert(value == 42);
+} catch (ExType const&) {
 }
 }
 {
@@ -45,8 +47,7 @@ int main()
 try {
 p.set_exception(std::exception_ptr());
 assert(false);
-} catch (int const& value) {
-assert(value == 42);
+} catch (ExType const&) {
 }
 }
 }

Modified: 
libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp?rev=328265=328264=328265=diff
==
--- 

[PATCH] D44778: [clang-format] Wildcard expansion on Windows.

2018-03-22 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D44778#1046251, @rnk wrote:

> Use `llvm::sys::Process::GetArgumentVector`, which already does wildcard 
> expansion from what I can see. It works with Unicode command lines and isn't 
> affected by locale.


I vaguely remember that windows console applications have to define wmain() 
instead of main() in order to work with unicode. Does 
`llvm::sys::Process::GetArgumentVector` allow to work around this?


Repository:
  rC Clang

https://reviews.llvm.org/D44778



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


[libcxx] r328264 - [libcxx] [test] Strip trailing whitespace. NFC.

2018-03-22 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Thu Mar 22 15:59:02 2018
New Revision: 328264

URL: http://llvm.org/viewvc/llvm-project?rev=328264=rev
Log:
[libcxx] [test] Strip trailing whitespace. NFC.

Modified:

libcxx/trunk/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
libcxx/trunk/test/std/language.support/support.types/max_align_t.pass.cpp

libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp

Modified: 
libcxx/trunk/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp?rev=328264=328263=328264=diff
==
--- 
libcxx/trunk/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
 Thu Mar 22 15:59:02 2018
@@ -25,12 +25,12 @@ int main()
 
 assert(l.__invariants());
 assert(s.__invariants());
-
+
 s.__clear_and_shrink();
 assert(s.__invariants());
 assert(s.size() == 0);
 
-{ 
+{
 std::string::size_type cap = l.capacity();
 l.__clear_and_shrink();
 assert(l.__invariants());

Modified: 
libcxx/trunk/test/std/language.support/support.types/max_align_t.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/language.support/support.types/max_align_t.pass.cpp?rev=328264=328263=328264=diff
==
--- libcxx/trunk/test/std/language.support/support.types/max_align_t.pass.cpp 
(original)
+++ libcxx/trunk/test/std/language.support/support.types/max_align_t.pass.cpp 
Thu Mar 22 15:59:02 2018
@@ -10,7 +10,7 @@
 #include 
 #include 
 
-// max_align_t is a trivial standard-layout type whose alignment requirement 
+// max_align_t is a trivial standard-layout type whose alignment requirement
 //   is at least as great as that of every scalar type
 
 #include 

Modified: 
libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp?rev=328264=328263=328264=diff
==
--- 
libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp
 Thu Mar 22 15:59:02 2018
@@ -46,5 +46,5 @@ int main()
 constexpr AL a3{a2};
 (void) a3;
 }
-
+
 }


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


r328263 - Add a test.

2018-03-22 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Thu Mar 22 15:57:48 2018
New Revision: 328263

URL: http://llvm.org/viewvc/llvm-project?rev=328263=rev
Log:
Add a test.

This would have found the regression in r328238.

Added:
cfe/trunk/test/CodeGenCXX/rtti-hidden.cpp

Added: cfe/trunk/test/CodeGenCXX/rtti-hidden.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/rtti-hidden.cpp?rev=328263=auto
==
--- cfe/trunk/test/CodeGenCXX/rtti-hidden.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/rtti-hidden.cpp Thu Mar 22 15:57:48 2018
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -triple=x86_64-pc-linux -emit-llvm -o - | FileCheck %s
+
+// Test that this is not hidden.
+// CHECK: @_ZTVN10__cxxabiv120__si_class_type_infoE = external global
+
+class foo {
+  virtual void baz();
+};
+struct __attribute__((__visibility__("hidden"))) bar : public foo {};
+bar zed;


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


[libcxx] r328261 - Workaround GCC bug PR78489 - SFINAE order is not respected.

2018-03-22 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Mar 22 15:32:55 2018
New Revision: 328261

URL: http://llvm.org/viewvc/llvm-project?rev=328261=rev
Log:
Workaround GCC bug PR78489 - SFINAE order is not respected.

This patch works around variant test failures which are new to
GCC 8. GCC 8 either doesn't perform SFINAE in lexical order, or
it doesn't halt after encountering the first failure. This
causes hard error to occur instead of substitution failure.

See gcc.gnu.org/PR78489

Modified:
libcxx/trunk/include/variant

libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/in_place_index_init_list_args.pass.cpp

Modified: libcxx/trunk/include/variant
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/variant?rev=328261=328260=328261=diff
==
--- libcxx/trunk/include/variant (original)
+++ libcxx/trunk/include/variant Thu Mar 22 15:32:55 2018
@@ -1156,29 +1156,24 @@ public:
   : __impl(in_place_index<_Ip>, _VSTD::forward<_Arg>(__arg)) {}
 
   template ,
-class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
-enable_if_t, int> = 0>
+enable_if_t<(_Ip < sizeof...(_Types)), size_t> _Ip2 = _Ip,
+class _Tp = variant_alternative_t<_Ip2, variant<_Types...>>,
+enable_if_t::value, int> = 0>
   inline _LIBCPP_INLINE_VISIBILITY
-  explicit constexpr variant(
-  in_place_index_t<_Ip>,
-  _Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
+  explicit constexpr variant(in_place_index_t<_Ip>,
+ _Args&&... __args)
+noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
   : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {}
 
-  template <
-  size_t _Ip,
-  class _Up,
-  class... _Args,
-  enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
-  class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
+  template  _Ip2 = _Ip,
+  class _Tp = variant_alternative_t<_Ip2, variant<_Types...>>,
   enable_if_t&, _Args...>,
   int> = 0>
   inline _LIBCPP_INLINE_VISIBILITY
-  explicit constexpr variant(
-  in_place_index_t<_Ip>,
-  initializer_list<_Up> __il,
-  _Args&&... __args) noexcept(
-  is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>)
+  explicit constexpr variant(in_place_index_t<_Ip>, initializer_list<_Up> __il,
+ _Args&&... __args)
+noexcept(is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, 
_Args...>)
   : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {}
 
   template <

Modified: 
libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/in_place_index_init_list_args.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/in_place_index_init_list_args.pass.cpp?rev=328261=328260=328261=diff
==
--- 
libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/in_place_index_init_list_args.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/in_place_index_init_list_args.pass.cpp
 Thu Mar 22 15:32:55 2018
@@ -73,6 +73,12 @@ void test_ctor_sfinae() {
 !std::is_constructible, IL>::value, "");
 static_assert(!test_convertible, IL>(), "");
   }
+  { // index not in variant
+using V = std::variant;
+static_assert(
+!std::is_constructible, IL>::value, "");
+static_assert(!test_convertible, IL>(), "");
+  }
 }
 
 void test_ctor_basic() {


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


[PATCH] D44652: [vfs] Don't bail out after a missing -ivfsoverlay file

2018-03-22 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

One minor suggestion but otherwise LGTM




Comment at: lib/Frontend/CompilerInvocation.cpp:3083
+} else {
   Diags.Report(diag::err_invalid_vfs_overlay) << File;
 }

Can you take the opportunity and remove the curly braces here?


Repository:
  rC Clang

https://reviews.llvm.org/D44652



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


[PATCH] D44778: [clang-format] Wildcard expansion on Windows.

2018-03-22 Thread Reid Kleckner via Phabricator via cfe-commits
rnk requested changes to this revision.
rnk added a comment.
This revision now requires changes to proceed.

Use `llvm::sys::Process::GetArgumentVector`, which already does wildcard 
expansion from what I can see. It works with Unicode command lines and isn't 
affected by locale.


Repository:
  rC Clang

https://reviews.llvm.org/D44778



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


[PATCH] D44721: [analyzer] Enable c++-temp-dtor-inlining by default?

2018-03-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328258: [analyzer] Enable temporary object destructor 
inlining by default. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44721?vs=139237=139524#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44721

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  cfe/trunk/test/Analysis/analyzer-config.cpp


Index: cfe/trunk/test/Analysis/analyzer-config.cpp
===
--- cfe/trunk/test/Analysis/analyzer-config.cpp
+++ cfe/trunk/test/Analysis/analyzer-config.cpp
@@ -23,7 +23,7 @@
 // CHECK-NEXT: c++-inlining = destructors
 // CHECK-NEXT: c++-shared_ptr-inlining = false
 // CHECK-NEXT: c++-stdlib-inlining = true
-// CHECK-NEXT: c++-temp-dtor-inlining = false
+// CHECK-NEXT: c++-temp-dtor-inlining = true
 // CHECK-NEXT: c++-template-inlining = true
 // CHECK-NEXT: cfg-conditional-static-initializers = true
 // CHECK-NEXT: cfg-implicit-dtors = true
Index: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -263,7 +263,7 @@
 bool AnalyzerOptions::mayInlineCXXTemporaryDtors() {
   return getBooleanOption(InlineCXXTemporaryDtors,
   "c++-temp-dtor-inlining",
-  /*Default=*/false);
+  /*Default=*/true);
 }
 
 bool AnalyzerOptions::mayInlineObjCMethod() {


Index: cfe/trunk/test/Analysis/analyzer-config.cpp
===
--- cfe/trunk/test/Analysis/analyzer-config.cpp
+++ cfe/trunk/test/Analysis/analyzer-config.cpp
@@ -23,7 +23,7 @@
 // CHECK-NEXT: c++-inlining = destructors
 // CHECK-NEXT: c++-shared_ptr-inlining = false
 // CHECK-NEXT: c++-stdlib-inlining = true
-// CHECK-NEXT: c++-temp-dtor-inlining = false
+// CHECK-NEXT: c++-temp-dtor-inlining = true
 // CHECK-NEXT: c++-template-inlining = true
 // CHECK-NEXT: cfg-conditional-static-initializers = true
 // CHECK-NEXT: cfg-implicit-dtors = true
Index: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -263,7 +263,7 @@
 bool AnalyzerOptions::mayInlineCXXTemporaryDtors() {
   return getBooleanOption(InlineCXXTemporaryDtors,
   "c++-temp-dtor-inlining",
-  /*Default=*/false);
+  /*Default=*/true);
 }
 
 bool AnalyzerOptions::mayInlineObjCMethod() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r328258 - [analyzer] Enable temporary object destructor inlining by default.

2018-03-22 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Mar 22 15:05:53 2018
New Revision: 328258

URL: http://llvm.org/viewvc/llvm-project?rev=328258=rev
Log:
[analyzer] Enable temporary object destructor inlining by default.

When a temporary is constructed with a proper construction context, it should
be safe to inline the destructor. We have added suppressions for some of the
common false positives caused by such inlining, so there should be - and from my
observations there indeed is - more benefit than harm from enabling destructor
inlining.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/test/Analysis/analyzer-config.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=328258=328257=328258=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Thu Mar 22 15:05:53 
2018
@@ -263,7 +263,7 @@ bool AnalyzerOptions::mayInlineCXXShared
 bool AnalyzerOptions::mayInlineCXXTemporaryDtors() {
   return getBooleanOption(InlineCXXTemporaryDtors,
   "c++-temp-dtor-inlining",
-  /*Default=*/false);
+  /*Default=*/true);
 }
 
 bool AnalyzerOptions::mayInlineObjCMethod() {

Modified: cfe/trunk/test/Analysis/analyzer-config.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.cpp?rev=328258=328257=328258=diff
==
--- cfe/trunk/test/Analysis/analyzer-config.cpp (original)
+++ cfe/trunk/test/Analysis/analyzer-config.cpp Thu Mar 22 15:05:53 2018
@@ -23,7 +23,7 @@ public:
 // CHECK-NEXT: c++-inlining = destructors
 // CHECK-NEXT: c++-shared_ptr-inlining = false
 // CHECK-NEXT: c++-stdlib-inlining = true
-// CHECK-NEXT: c++-temp-dtor-inlining = false
+// CHECK-NEXT: c++-temp-dtor-inlining = true
 // CHECK-NEXT: c++-template-inlining = true
 // CHECK-NEXT: cfg-conditional-static-initializers = true
 // CHECK-NEXT: cfg-implicit-dtors = true


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


[PATCH] D44763: [CFG] [analyzer] Add C++17-specific constructor-initializer construction contexts.

2018-03-22 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328255: [CFG] [analyzer] Add C++17-specific ctor-initializer 
construction contexts. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44763

Files:
  include/clang/Analysis/CFG.h
  include/clang/Analysis/ConstructionContext.h
  lib/Analysis/CFG.cpp
  lib/Analysis/ConstructionContext.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/cfg-rich-constructors.cpp

Index: include/clang/Analysis/ConstructionContext.h
===
--- include/clang/Analysis/ConstructionContext.h
+++ include/clang/Analysis/ConstructionContext.h
@@ -102,7 +102,10 @@
 CXX17ElidedCopyVariableKind,
 VARIABLE_BEGIN = SimpleVariableKind,
 VARIABLE_END = CXX17ElidedCopyVariableKind,
-ConstructorInitializerKind,
+SimpleConstructorInitializerKind,
+CXX17ElidedCopyConstructorInitializerKind,
+INITIALIZER_BEGIN = SimpleConstructorInitializerKind,
+INITIALIZER_END = CXX17ElidedCopyConstructorInitializerKind,
 NewAllocatedObjectKind,
 TemporaryObjectKind,
 SimpleReturnedValueKind,
@@ -202,25 +205,73 @@
   }
 };
 
-/// Represents construction into a field or a base class within a bigger object
-/// via a constructor initializer, eg. T(): field(123) { ... }.
+// An abstract base class for constructor-initializer-based constructors.
 class ConstructorInitializerConstructionContext : public ConstructionContext {
   const CXXCtorInitializer *I;
 
-  friend class ConstructionContext; // Allows to create<>() itself.
-
+protected:
   explicit ConstructorInitializerConstructionContext(
-  const CXXCtorInitializer *I)
-  : ConstructionContext(ConstructionContext::ConstructorInitializerKind),
-I(I) {
+  ConstructionContext::Kind K, const CXXCtorInitializer *I)
+  : ConstructionContext(K), I(I) {
+assert(classof(this));
 assert(I);
   }
 
 public:
   const CXXCtorInitializer *getCXXCtorInitializer() const { return I; }
 
   static bool classof(const ConstructionContext *CC) {
-return CC->getKind() == ConstructorInitializerKind;
+return CC->getKind() >= INITIALIZER_BEGIN &&
+   CC->getKind() <= INITIALIZER_END;
+  }
+};
+
+/// Represents construction into a field or a base class within a bigger object
+/// via a constructor initializer, eg. T(): field(123) { ... }.
+class SimpleConstructorInitializerConstructionContext
+: public ConstructorInitializerConstructionContext {
+  friend class ConstructionContext; // Allows to create<>() itself.
+
+  explicit SimpleConstructorInitializerConstructionContext(
+  const CXXCtorInitializer *I)
+  : ConstructorInitializerConstructionContext(
+ConstructionContext::SimpleConstructorInitializerKind, I) {}
+
+public:
+  static bool classof(const ConstructionContext *CC) {
+return CC->getKind() == SimpleConstructorInitializerKind;
+  }
+};
+
+/// Represents construction into a field or a base class within a bigger object
+/// via a constructor initializer, with a single constructor, eg.
+/// T(): field(Field(123)) { ... }. Such construction context may only appear
+/// in C++17 because previously it was split into a temporary object constructor
+/// and an elidable simple constructor-initializer copy-constructor and we were
+/// producing separate construction contexts for these constructors. In C++17
+/// we have a single construction context that combines both. Note that if the
+/// object has trivial destructor, then this code is indistinguishable from
+/// a simple constructor-initializer constructor on the AST level; in this case
+/// we provide a simple constructor-initializer construction context.
+class CXX17ElidedCopyConstructorInitializerConstructionContext
+: public ConstructorInitializerConstructionContext {
+  const CXXBindTemporaryExpr *BTE;
+
+  friend class ConstructionContext; // Allows to create<>() itself.
+
+  explicit CXX17ElidedCopyConstructorInitializerConstructionContext(
+  const CXXCtorInitializer *I, const CXXBindTemporaryExpr *BTE)
+  : ConstructorInitializerConstructionContext(
+CXX17ElidedCopyConstructorInitializerKind, I),
+BTE(BTE) {
+assert(BTE);
+  }
+
+public:
+  const CXXBindTemporaryExpr *getCXXBindTemporaryExpr() const { return BTE; }
+
+  static bool classof(const ConstructionContext *CC) {
+return CC->getKind() == CXX17ElidedCopyConstructorInitializerKind;
   }
 };
 
Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -189,8 +189,10 @@
 // into the constructor. An assertion would require passing an ASTContext
 // which would mean paying for something we don't use.
 assert(C && (isa(C) ||
+ // These 

[PATCH] D44763: [CFG] [analyzer] Add C++17-specific constructor-initializer construction contexts.

2018-03-22 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328255: [CFG] [analyzer] Add C++17-specific ctor-initializer 
construction contexts. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44763?vs=139398=139521#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44763

Files:
  cfe/trunk/include/clang/Analysis/CFG.h
  cfe/trunk/include/clang/Analysis/ConstructionContext.h
  cfe/trunk/lib/Analysis/CFG.cpp
  cfe/trunk/lib/Analysis/ConstructionContext.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  cfe/trunk/test/Analysis/cfg-rich-constructors.cpp

Index: cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
===
--- cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
+++ cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
@@ -252,6 +252,34 @@
   D(double): C(C::get()), c1(new C(C::get())) {}
 };
 
+// Let's see if initializers work well for fields with destructors.
+class E {
+public:
+  static E get();
+  ~E();
+};
+
+class F {
+  E e;
+
+public:
+// FIXME: There should be no temporary destructor in C++17.
+// CHECK: F()
+// CHECK:  1: E::get
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class ctor_initializers::E (*)(
+// CXX11-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.4], [B1.6])
+// CXX11-NEXT: 4: [B1.3] (BindTemporary)
+// CXX11-NEXT: 5: [B1.4] (ImplicitCastExpr, NoOp, const class ctor_initializers::E)
+// CXX11-NEXT: 6: [B1.5]
+// CXX11-NEXT: 7: [B1.6] (CXXConstructExpr, e([B1.6]) (Member initializer), class ctor_initializers
+// CXX11-NEXT: 8: e([B1.7]) (Member initializer)
+// CXX11-NEXT: 9: ~ctor_initializers::E() (Temporary object destructor)
+// CXX17-NEXT: 3: [B1.2]() (CXXRecordTypedCall, e([B1.4]) (Member initializer), [B1.4])
+// CXX17-NEXT: 4: [B1.3] (BindTemporary)
+// CXX17-NEXT: 5: e([B1.4]) (Member initializer)
+// CXX17-NEXT: 6: ~ctor_initializers::E() (Temporary object destructor)
+  F(): e(E::get()) {}
+};
 } // end namespace ctor_initializers
 
 namespace return_stmt_without_dtor {
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -134,7 +134,7 @@
   makeZeroElementRegion(State, LValue, Ty, CallOpts.IsArrayCtorOrDtor);
   return LValue.getAsRegion();
 }
-case ConstructionContext::ConstructorInitializerKind: {
+case ConstructionContext::SimpleConstructorInitializerKind: {
   const auto *ICC = cast(CC);
   const auto *Init = ICC->getCXXCtorInitializer();
   assert(Init->isAnyMemberInitializer());
@@ -217,6 +217,7 @@
 }
 case ConstructionContext::CXX17ElidedCopyVariableKind:
 case ConstructionContext::CXX17ElidedCopyReturnedValueKind:
+case ConstructionContext::CXX17ElidedCopyConstructorInitializerKind:
   // Not implemented yet.
   break;
 }
Index: cfe/trunk/lib/Analysis/CFG.cpp
===
--- cfe/trunk/lib/Analysis/CFG.cpp
+++ cfe/trunk/lib/Analysis/CFG.cpp
@@ -4911,10 +4911,18 @@
const ConstructionContext *CC) {
   const Stmt *S1 = nullptr, *S2 = nullptr;
   switch (CC->getKind()) {
-  case ConstructionContext::ConstructorInitializerKind: {
+  case ConstructionContext::SimpleConstructorInitializerKind: {
 OS << ", ";
-const auto *ICC = cast(CC);
-print_initializer(OS, Helper, ICC->getCXXCtorInitializer());
+const auto *SICC = cast(CC);
+print_initializer(OS, Helper, SICC->getCXXCtorInitializer());
+break;
+  }
+  case ConstructionContext::CXX17ElidedCopyConstructorInitializerKind: {
+OS << ", ";
+const auto *CICC =
+cast(CC);
+print_initializer(OS, Helper, CICC->getCXXCtorInitializer());
+S2 = CICC->getCXXBindTemporaryExpr();
 break;
   }
   case ConstructionContext::SimpleVariableKind: {
Index: cfe/trunk/lib/Analysis/ConstructionContext.cpp
===
--- cfe/trunk/lib/Analysis/ConstructionContext.cpp
+++ cfe/trunk/lib/Analysis/ConstructionContext.cpp
@@ -62,21 +62,31 @@
   // lifetime extension on the parent layer.
   if (const ConstructionContextLayer *ParentLayer = TopLayer->getParent()) {
 assert(ParentLayer->isLast());
+// C++17 *requires* elision of the constructor at the return site
+// and at variable/member initialization site, while previous standards
+// were allowing an optional elidable constructor.
+// This is the C++17 copy-elided construction into a ctor initializer.
+if (const CXXCtorInitializer *I = 

r328255 - [CFG] [analyzer] Add C++17-specific ctor-initializer construction contexts.

2018-03-22 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Mar 22 15:02:38 2018
New Revision: 328255

URL: http://llvm.org/viewvc/llvm-project?rev=328255=rev
Log:
[CFG] [analyzer] Add C++17-specific ctor-initializer construction contexts.

CXXCtorInitializer-based constructors are also affected by the C++17 mandatory
copy elision, like variable constructors and return value constructors.
Extend r328248 to support those.

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

Modified:
cfe/trunk/include/clang/Analysis/CFG.h
cfe/trunk/include/clang/Analysis/ConstructionContext.h
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/Analysis/ConstructionContext.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/test/Analysis/cfg-rich-constructors.cpp

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=328255=328254=328255=diff
==
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Thu Mar 22 15:02:38 2018
@@ -189,8 +189,10 @@ public:
 // into the constructor. An assertion would require passing an ASTContext
 // which would mean paying for something we don't use.
 assert(C && (isa(C) ||
+ // These are possible in C++17 due to mandatory copy elision.
  isa(C) ||
- isa(C)));
+ isa(C) ||
+ isa(C)));
 Data2.setPointer(const_cast(C));
   }
 

Modified: cfe/trunk/include/clang/Analysis/ConstructionContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ConstructionContext.h?rev=328255=328254=328255=diff
==
--- cfe/trunk/include/clang/Analysis/ConstructionContext.h (original)
+++ cfe/trunk/include/clang/Analysis/ConstructionContext.h Thu Mar 22 15:02:38 
2018
@@ -102,7 +102,10 @@ public:
 CXX17ElidedCopyVariableKind,
 VARIABLE_BEGIN = SimpleVariableKind,
 VARIABLE_END = CXX17ElidedCopyVariableKind,
-ConstructorInitializerKind,
+SimpleConstructorInitializerKind,
+CXX17ElidedCopyConstructorInitializerKind,
+INITIALIZER_BEGIN = SimpleConstructorInitializerKind,
+INITIALIZER_END = CXX17ElidedCopyConstructorInitializerKind,
 NewAllocatedObjectKind,
 TemporaryObjectKind,
 SimpleReturnedValueKind,
@@ -202,17 +205,15 @@ public:
   }
 };
 
-/// Represents construction into a field or a base class within a bigger object
-/// via a constructor initializer, eg. T(): field(123) { ... }.
+// An abstract base class for constructor-initializer-based constructors.
 class ConstructorInitializerConstructionContext : public ConstructionContext {
   const CXXCtorInitializer *I;
 
-  friend class ConstructionContext; // Allows to create<>() itself.
-
+protected:
   explicit ConstructorInitializerConstructionContext(
-  const CXXCtorInitializer *I)
-  : ConstructionContext(ConstructionContext::ConstructorInitializerKind),
-I(I) {
+  ConstructionContext::Kind K, const CXXCtorInitializer *I)
+  : ConstructionContext(K), I(I) {
+assert(classof(this));
 assert(I);
   }
 
@@ -220,7 +221,57 @@ public:
   const CXXCtorInitializer *getCXXCtorInitializer() const { return I; }
 
   static bool classof(const ConstructionContext *CC) {
-return CC->getKind() == ConstructorInitializerKind;
+return CC->getKind() >= INITIALIZER_BEGIN &&
+   CC->getKind() <= INITIALIZER_END;
+  }
+};
+
+/// Represents construction into a field or a base class within a bigger object
+/// via a constructor initializer, eg. T(): field(123) { ... }.
+class SimpleConstructorInitializerConstructionContext
+: public ConstructorInitializerConstructionContext {
+  friend class ConstructionContext; // Allows to create<>() itself.
+
+  explicit SimpleConstructorInitializerConstructionContext(
+  const CXXCtorInitializer *I)
+  : ConstructorInitializerConstructionContext(
+ConstructionContext::SimpleConstructorInitializerKind, I) {}
+
+public:
+  static bool classof(const ConstructionContext *CC) {
+return CC->getKind() == SimpleConstructorInitializerKind;
+  }
+};
+
+/// Represents construction into a field or a base class within a bigger object
+/// via a constructor initializer, with a single constructor, eg.
+/// T(): field(Field(123)) { ... }. Such construction context may only appear
+/// in C++17 because previously it was split into a temporary object 
constructor
+/// and an elidable simple constructor-initializer copy-constructor and we were
+/// producing separate construction contexts for these constructors. In C++17
+/// we have a single construction context that combines both. Note that if the
+/// object has trivial destructor, then this code is indistinguishable from
+/// a simple constructor-initializer constructor on the AST level; in this case
+/// we 

r328253 - [analyzer] Remove an assertion that doesn't hold in C++17.

2018-03-22 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Mar 22 14:54:48 2018
New Revision: 328253

URL: http://llvm.org/viewvc/llvm-project?rev=328253=rev
Log:
[analyzer] Remove an assertion that doesn't hold in C++17.

Function return values can be constructed directly in variables or passed
directly into return statements, without even an elidable copy in between.
This is how the C++17 mandatory copy elision AST behaves. The behavior we'll
have in such cases is the "old" behavior that we've had before we've
implemented destructor inlining and proper lifetime extension support.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/test/Analysis/lifetime-extension.cpp
cfe/trunk/test/Analysis/temporaries.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=328253=328252=328253=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Thu Mar 22 14:54:48 2018
@@ -455,29 +455,51 @@ ProgramStateRef ExprEngine::addAllNecess
 const LocationContext *LC, const MemRegion *R) {
   const CXXBindTemporaryExpr *BTE = nullptr;
   const MaterializeTemporaryExpr *MTE = nullptr;
-  const LocationContext *TempLC = LC;
 
   if (CC) {
-// In case of temporary object construction, extract data necessary for
-// destruction and lifetime extension.
-const auto *TCC = dyn_cast(CC);
-
 // If the temporary is being returned from the function, it will be
 // destroyed or lifetime-extended in the caller stack frame.
 if (isa(CC)) {
   const StackFrameContext *SFC = LC->getCurrentStackFrame();
   assert(SFC);
-  if (SFC->getParent()) {
-TempLC = SFC->getParent();
-const CFGElement  =
-(*SFC->getCallSiteBlock())[SFC->getIndex()];
-if (auto RTCElem = CallElem.getAs()) {
-  TCC = cast(
-  RTCElem->getConstructionContext());
-}
+  LC = SFC->getParent();
+  if (!LC) {
+// We are on the top frame. We won't ever need any info
+// for this temporary, so don't set anything.
+return State;
+  }
+  const CFGElement  =
+  (*SFC->getCallSiteBlock())[SFC->getIndex()];
+  auto RTCElem = CallElem.getAs();
+  if (!RTCElem) {
+// We have a parent stack frame, but no construction context for the
+// return value. Give up until we provide the construction context
+// at the call site.
+return State;
   }
+  // We use the ReturnedValueConstructionContext as an indication that we
+  // need to look for the actual construction context on the parent stack
+  // frame. This purpose has been fulfilled, so now we replace CC with the
+  // actual construction context.
+  CC = RTCElem->getConstructionContext();
+  if (!isa(CC)) {
+// TODO: We are not returning an object into a temporary. There must
+// be copy elision happening at the call site. We still need to
+// explicitly support the situation when the return value is put
+// into another return statement, i.e.
+// ReturnedValueConstructionContexts are chained through multiple
+// stack frames before finally settling in a temporary.
+// We don't seem to need to explicitly support construction into
+// a variable after a return.
+return State;
+  }
+  // Proceed to deal with the temporary we've found on the parent
+  // stack frame.
 }
-if (TCC) {
+
+// In case of temporary object construction, extract data necessary for
+// destruction and lifetime extension.
+if (const auto *TCC = dyn_cast(CC)) {
   if (AMgr.getAnalyzerOptions().includeTemporaryDtorsInCFG()) {
 BTE = TCC->getCXXBindTemporaryExpr();
 MTE = TCC->getMaterializedTemporaryExpr();
@@ -496,12 +518,12 @@ ProgramStateRef ExprEngine::addAllNecess
 }
 
 if (BTE) {
-  State = addInitializedTemporary(State, BTE, TempLC,
+  State = addInitializedTemporary(State, BTE, LC,
   cast(R));
 }
 
 if (MTE) {
-  State = addTemporaryMaterialization(State, MTE, TempLC,
+  State = addTemporaryMaterialization(State, MTE, LC,
   cast(R));
 }
   }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=328253=328252=328253=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Thu Mar 22 14:54:48 2018
@@ -203,6 

[PATCH] D44755: [analyzer] Suppress more C++17-related crashes.

2018-03-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328253: [analyzer] Remove an assertion that doesnt 
hold in C++17. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44755?vs=139378=139518#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44755

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  cfe/trunk/test/Analysis/lifetime-extension.cpp
  cfe/trunk/test/Analysis/temporaries.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -203,6 +203,10 @@
   // TODO: What exactly happens when we are? Does the temporary object live
   // long enough in the region store in this case? Would checkers think
   // that this object immediately goes out of scope?
+  // TODO: We assume that the call site has a temporary object construction
+  // context. This is no longer true in C++17 or when copy elision is
+  // performed. We may need to unwrap multiple stack frames here and we
+  // won't necessarily end up with a temporary at the end.
   const LocationContext *TempLCtx = LCtx;
   if (const LocationContext *CallerLCtx =
   LCtx->getCurrentStackFrame()->getParent()) {
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -455,29 +455,51 @@
 const LocationContext *LC, const MemRegion *R) {
   const CXXBindTemporaryExpr *BTE = nullptr;
   const MaterializeTemporaryExpr *MTE = nullptr;
-  const LocationContext *TempLC = LC;
 
   if (CC) {
-// In case of temporary object construction, extract data necessary for
-// destruction and lifetime extension.
-const auto *TCC = dyn_cast(CC);
-
 // If the temporary is being returned from the function, it will be
 // destroyed or lifetime-extended in the caller stack frame.
 if (isa(CC)) {
   const StackFrameContext *SFC = LC->getCurrentStackFrame();
   assert(SFC);
-  if (SFC->getParent()) {
-TempLC = SFC->getParent();
-const CFGElement  =
-(*SFC->getCallSiteBlock())[SFC->getIndex()];
-if (auto RTCElem = CallElem.getAs()) {
-  TCC = cast(
-  RTCElem->getConstructionContext());
-}
+  LC = SFC->getParent();
+  if (!LC) {
+// We are on the top frame. We won't ever need any info
+// for this temporary, so don't set anything.
+return State;
+  }
+  const CFGElement  =
+  (*SFC->getCallSiteBlock())[SFC->getIndex()];
+  auto RTCElem = CallElem.getAs();
+  if (!RTCElem) {
+// We have a parent stack frame, but no construction context for the
+// return value. Give up until we provide the construction context
+// at the call site.
+return State;
+  }
+  // We use the ReturnedValueConstructionContext as an indication that we
+  // need to look for the actual construction context on the parent stack
+  // frame. This purpose has been fulfilled, so now we replace CC with the
+  // actual construction context.
+  CC = RTCElem->getConstructionContext();
+  if (!isa(CC)) {
+// TODO: We are not returning an object into a temporary. There must
+// be copy elision happening at the call site. We still need to
+// explicitly support the situation when the return value is put
+// into another return statement, i.e.
+// ReturnedValueConstructionContexts are chained through multiple
+// stack frames before finally settling in a temporary.
+// We don't seem to need to explicitly support construction into
+// a variable after a return.
+return State;
   }
+  // Proceed to deal with the temporary we've found on the parent
+  // stack frame.
 }
-if (TCC) {
+
+// In case of temporary object construction, extract data necessary for
+// destruction and lifetime extension.
+if (const auto *TCC = dyn_cast(CC)) {
   if (AMgr.getAnalyzerOptions().includeTemporaryDtorsInCFG()) {
 BTE = TCC->getCXXBindTemporaryExpr();
 MTE = TCC->getMaterializedTemporaryExpr();
@@ -496,12 +518,12 @@
 }
 
 if (BTE) {
-  State = addInitializedTemporary(State, BTE, TempLC,
+  State = addInitializedTemporary(State, BTE, LC,
   cast(R));
 }
 
 if (MTE) {
-  State = addTemporaryMaterialization(State, MTE, TempLC,
+  State = addTemporaryMaterialization(State, MTE, LC,
   cast(R));
 }
   }

[PATCH] D44498: Sink PrettyDeclStackTrace down to the AST library

2018-03-22 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Hi Jordan,

Thanks for improving this. LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D44498



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


[PATCH] D44725: [CFG] [analyzer] NFC: Move construction context allocation into a helper method.

2018-03-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328249: [CFG] [analyzer] NFC: Move construction context 
allocation into a helper method. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44725

Files:
  include/clang/Analysis/ConstructionContext.h
  lib/Analysis/ConstructionContext.cpp

Index: include/clang/Analysis/ConstructionContext.h
===
--- include/clang/Analysis/ConstructionContext.h
+++ include/clang/Analysis/ConstructionContext.h
@@ -118,6 +118,14 @@
   // via createFromLayers().
   explicit ConstructionContext(Kind K) : K(K) {}
 
+private:
+  // A helper function for constructing an instance into a bump vector context.
+  template 
+  static T *create(BumpVectorContext , ArgTypes... Args) {
+auto *CC = C.getAllocator().Allocate();
+return new (CC) T(Args...);
+  }
+
 public:
   /// Consume the construction context layer, together with its parent layers,
   /// and wrap it up into a complete construction context.
@@ -153,11 +161,13 @@
 /// elidable copy-constructor from makeT() into var would also be a simple
 /// variable constructor handled by this class.
 class SimpleVariableConstructionContext : public VariableConstructionContext {
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit SimpleVariableConstructionContext(const DeclStmt *DS)
   : VariableConstructionContext(ConstructionContext::SimpleVariableKind,
 DS) {}
 
+public:
   static bool classof(const ConstructionContext *CC) {
 return CC->getKind() == SimpleVariableKind;
   }
@@ -176,13 +186,15 @@
 : public VariableConstructionContext {
   const CXXBindTemporaryExpr *BTE;
 
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit CXX17ElidedCopyVariableConstructionContext(
   const DeclStmt *DS, const CXXBindTemporaryExpr *BTE)
   : VariableConstructionContext(CXX17ElidedCopyVariableKind, DS), BTE(BTE) {
 assert(BTE);
   }
 
+public:
   const CXXBindTemporaryExpr *getCXXBindTemporaryExpr() const { return BTE; }
 
   static bool classof(const ConstructionContext *CC) {
@@ -195,14 +207,16 @@
 class ConstructorInitializerConstructionContext : public ConstructionContext {
   const CXXCtorInitializer *I;
 
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit ConstructorInitializerConstructionContext(
   const CXXCtorInitializer *I)
   : ConstructionContext(ConstructionContext::ConstructorInitializerKind),
 I(I) {
 assert(I);
   }
 
+public:
   const CXXCtorInitializer *getCXXCtorInitializer() const { return I; }
 
   static bool classof(const ConstructionContext *CC) {
@@ -215,13 +229,15 @@
 class NewAllocatedObjectConstructionContext : public ConstructionContext {
   const CXXNewExpr *NE;
 
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit NewAllocatedObjectConstructionContext(const CXXNewExpr *NE)
   : ConstructionContext(ConstructionContext::NewAllocatedObjectKind),
 NE(NE) {
 assert(NE);
   }
 
+public:
   const CXXNewExpr *getCXXNewExpr() const { return NE; }
 
   static bool classof(const ConstructionContext *CC) {
@@ -237,7 +253,8 @@
   const CXXBindTemporaryExpr *BTE;
   const MaterializeTemporaryExpr *MTE;
 
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit TemporaryObjectConstructionContext(
   const CXXBindTemporaryExpr *BTE, const MaterializeTemporaryExpr *MTE)
   : ConstructionContext(ConstructionContext::TemporaryObjectKind),
@@ -248,6 +265,7 @@
 // nowhere that doesn't have a non-trivial destructor).
   }
 
+public:
   /// CXXBindTemporaryExpr here is non-null as long as the temporary has
   /// a non-trivial destructor.
   const CXXBindTemporaryExpr *getCXXBindTemporaryExpr() const {
@@ -295,11 +313,13 @@
 /// MaterializeTemporaryExpr) is normally located in the caller function's AST.
 class SimpleReturnedValueConstructionContext
 : public ReturnedValueConstructionContext {
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit SimpleReturnedValueConstructionContext(const ReturnStmt *RS)
   : ReturnedValueConstructionContext(
 ConstructionContext::SimpleReturnedValueKind, RS) {}
 
+public:
   static bool classof(const ConstructionContext *CC) {
 return CC->getKind() == SimpleReturnedValueKind;
   }
@@ -317,15 +337,17 @@
 : public ReturnedValueConstructionContext {
   const CXXBindTemporaryExpr *BTE;
 
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit CXX17ElidedCopyReturnedValueConstructionContext(
   const ReturnStmt *RS, const CXXBindTemporaryExpr *BTE)
   : ReturnedValueConstructionContext(
 

r328249 - [CFG] [analyzer] NFC: Move construction context allocation into a helper method.

2018-03-22 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Mar 22 14:40:24 2018
New Revision: 328249

URL: http://llvm.org/viewvc/llvm-project?rev=328249=rev
Log:
[CFG] [analyzer] NFC: Move construction context allocation into a helper method.

Improve readability of ConstructionContext::createFromLayers().

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

Modified:
cfe/trunk/include/clang/Analysis/ConstructionContext.h
cfe/trunk/lib/Analysis/ConstructionContext.cpp

Modified: cfe/trunk/include/clang/Analysis/ConstructionContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ConstructionContext.h?rev=328249=328248=328249=diff
==
--- cfe/trunk/include/clang/Analysis/ConstructionContext.h (original)
+++ cfe/trunk/include/clang/Analysis/ConstructionContext.h Thu Mar 22 14:40:24 
2018
@@ -118,6 +118,14 @@ protected:
   // via createFromLayers().
   explicit ConstructionContext(Kind K) : K(K) {}
 
+private:
+  // A helper function for constructing an instance into a bump vector context.
+  template 
+  static T *create(BumpVectorContext , ArgTypes... Args) {
+auto *CC = C.getAllocator().Allocate();
+return new (CC) T(Args...);
+  }
+
 public:
   /// Consume the construction context layer, together with its parent layers,
   /// and wrap it up into a complete construction context.
@@ -153,11 +161,13 @@ public:
 /// elidable copy-constructor from makeT() into var would also be a simple
 /// variable constructor handled by this class.
 class SimpleVariableConstructionContext : public VariableConstructionContext {
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit SimpleVariableConstructionContext(const DeclStmt *DS)
   : VariableConstructionContext(ConstructionContext::SimpleVariableKind,
 DS) {}
 
+public:
   static bool classof(const ConstructionContext *CC) {
 return CC->getKind() == SimpleVariableKind;
   }
@@ -176,13 +186,15 @@ class CXX17ElidedCopyVariableConstructio
 : public VariableConstructionContext {
   const CXXBindTemporaryExpr *BTE;
 
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit CXX17ElidedCopyVariableConstructionContext(
   const DeclStmt *DS, const CXXBindTemporaryExpr *BTE)
   : VariableConstructionContext(CXX17ElidedCopyVariableKind, DS), BTE(BTE) 
{
 assert(BTE);
   }
 
+public:
   const CXXBindTemporaryExpr *getCXXBindTemporaryExpr() const { return BTE; }
 
   static bool classof(const ConstructionContext *CC) {
@@ -195,7 +207,8 @@ public:
 class ConstructorInitializerConstructionContext : public ConstructionContext {
   const CXXCtorInitializer *I;
 
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit ConstructorInitializerConstructionContext(
   const CXXCtorInitializer *I)
   : ConstructionContext(ConstructionContext::ConstructorInitializerKind),
@@ -203,6 +216,7 @@ public:
 assert(I);
   }
 
+public:
   const CXXCtorInitializer *getCXXCtorInitializer() const { return I; }
 
   static bool classof(const ConstructionContext *CC) {
@@ -215,13 +229,15 @@ public:
 class NewAllocatedObjectConstructionContext : public ConstructionContext {
   const CXXNewExpr *NE;
 
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit NewAllocatedObjectConstructionContext(const CXXNewExpr *NE)
   : ConstructionContext(ConstructionContext::NewAllocatedObjectKind),
 NE(NE) {
 assert(NE);
   }
 
+public:
   const CXXNewExpr *getCXXNewExpr() const { return NE; }
 
   static bool classof(const ConstructionContext *CC) {
@@ -237,7 +253,8 @@ class TemporaryObjectConstructionContext
   const CXXBindTemporaryExpr *BTE;
   const MaterializeTemporaryExpr *MTE;
 
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit TemporaryObjectConstructionContext(
   const CXXBindTemporaryExpr *BTE, const MaterializeTemporaryExpr *MTE)
   : ConstructionContext(ConstructionContext::TemporaryObjectKind),
@@ -248,6 +265,7 @@ public:
 // nowhere that doesn't have a non-trivial destructor).
   }
 
+public:
   /// CXXBindTemporaryExpr here is non-null as long as the temporary has
   /// a non-trivial destructor.
   const CXXBindTemporaryExpr *getCXXBindTemporaryExpr() const {
@@ -295,11 +313,13 @@ public:
 /// MaterializeTemporaryExpr) is normally located in the caller function's AST.
 class SimpleReturnedValueConstructionContext
 : public ReturnedValueConstructionContext {
-public:
+  friend class ConstructionContext; // Allows to create<>() itself.
+
   explicit SimpleReturnedValueConstructionContext(const ReturnStmt *RS)
   : ReturnedValueConstructionContext(
 ConstructionContext::SimpleReturnedValueKind, RS) {}
 
+public:
   static bool classof(const ConstructionContext *CC) {
 return CC->getKind() == 

[PATCH] D44597: [CFG] [analyzer] Add C++17-specific variable and return value construction contexts.

2018-03-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328248: [CFG] [analyzer] Add C++17-specific variable and 
return construction contexts. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44597?vs=139245=139514#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44597

Files:
  cfe/trunk/include/clang/Analysis/CFG.h
  cfe/trunk/include/clang/Analysis/ConstructionContext.h
  cfe/trunk/lib/Analysis/CFG.cpp
  cfe/trunk/lib/Analysis/ConstructionContext.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  cfe/trunk/test/Analysis/cfg-rich-constructors.cpp

Index: cfe/trunk/include/clang/Analysis/ConstructionContext.h
===
--- cfe/trunk/include/clang/Analysis/ConstructionContext.h
+++ cfe/trunk/include/clang/Analysis/ConstructionContext.h
@@ -99,22 +99,26 @@
 public:
   enum Kind {
 SimpleVariableKind,
+CXX17ElidedCopyVariableKind,
+VARIABLE_BEGIN = SimpleVariableKind,
+VARIABLE_END = CXX17ElidedCopyVariableKind,
 ConstructorInitializerKind,
 NewAllocatedObjectKind,
 TemporaryObjectKind,
-ReturnedValueKind
+SimpleReturnedValueKind,
+CXX17ElidedCopyReturnedValueKind,
+RETURNED_VALUE_BEGIN = SimpleReturnedValueKind,
+RETURNED_VALUE_END = CXX17ElidedCopyReturnedValueKind
   };
 
 protected:
   Kind K;
 
-protected:
   // Do not make public! These need to only be constructed
   // via createFromLayers().
   explicit ConstructionContext(Kind K) : K(K) {}
 
 public:
-
   /// Consume the construction context layer, together with its parent layers,
   /// and wrap it up into a complete construction context.
   static const ConstructionContext *
@@ -124,23 +128,68 @@
   Kind getKind() const { return K; }
 };
 
-/// Represents construction into a simple local variable, eg. T var(123);.
-class SimpleVariableConstructionContext : public ConstructionContext {
+/// An abstract base class for local variable constructors.
+class VariableConstructionContext : public ConstructionContext {
   const DeclStmt *DS;
 
-public:
-  explicit SimpleVariableConstructionContext(const DeclStmt *DS)
-  : ConstructionContext(ConstructionContext::SimpleVariableKind), DS(DS) {
+protected:
+  VariableConstructionContext(ConstructionContext::Kind K, const DeclStmt *DS)
+  : ConstructionContext(K), DS(DS) {
+assert(classof(this));
 assert(DS);
   }
 
+public:
   const DeclStmt *getDeclStmt() const { return DS; }
 
   static bool classof(const ConstructionContext *CC) {
+return CC->getKind() >= VARIABLE_BEGIN &&
+   CC->getKind() <= VARIABLE_END;
+  }
+};
+
+/// Represents construction into a simple local variable, eg. T var(123);.
+/// If a variable has an initializer, eg. T var = makeT();, then the final
+/// elidable copy-constructor from makeT() into var would also be a simple
+/// variable constructor handled by this class.
+class SimpleVariableConstructionContext : public VariableConstructionContext {
+public:
+  explicit SimpleVariableConstructionContext(const DeclStmt *DS)
+  : VariableConstructionContext(ConstructionContext::SimpleVariableKind,
+DS) {}
+
+  static bool classof(const ConstructionContext *CC) {
 return CC->getKind() == SimpleVariableKind;
   }
 };
 
+/// Represents construction into a simple variable with an initializer syntax,
+/// with a single constructor, eg. T var = makeT();. Such construction context
+/// may only appear in C++17 because previously it was split into a temporary
+/// object constructor and an elidable simple variable copy-constructor and
+/// we were producing separate construction contexts for these constructors.
+/// In C++17 we have a single construction context that combines both.
+/// Note that if the object has trivial destructor, then this code is
+/// indistinguishable from a simple variable constructor on the AST level;
+/// in this case we provide a simple variable construction context.
+class CXX17ElidedCopyVariableConstructionContext
+: public VariableConstructionContext {
+  const CXXBindTemporaryExpr *BTE;
+
+public:
+  explicit CXX17ElidedCopyVariableConstructionContext(
+  const DeclStmt *DS, const CXXBindTemporaryExpr *BTE)
+  : VariableConstructionContext(CXX17ElidedCopyVariableKind, DS), BTE(BTE) {
+assert(BTE);
+  }
+
+  const CXXBindTemporaryExpr *getCXXBindTemporaryExpr() const { return BTE; }
+
+  static bool classof(const ConstructionContext *CC) {
+return CC->getKind() == CXX17ElidedCopyVariableKind;
+  }
+};
+
 /// Represents construction into a field or a base class within a bigger object
 /// via a constructor initializer, eg. T(): field(123) { ... }.
 class ConstructorInitializerConstructionContext : public ConstructionContext {
@@ -219,24 +268,68 @@
   }
 };
 
+class ReturnedValueConstructionContext : public ConstructionContext {
+  const 

r328248 - [CFG] [analyzer] Add C++17-specific variable and return construction contexts.

2018-03-22 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Mar 22 14:37:39 2018
New Revision: 328248

URL: http://llvm.org/viewvc/llvm-project?rev=328248=rev
Log:
[CFG] [analyzer] Add C++17-specific variable and return construction contexts.

In C++17 copy elision is mandatory for variable and return value constructors
(as long as it doesn't involve type conversion) which results in AST that does
not contain elidable constructors in their usual places. In order to provide
construction contexts in this scenario we need to cover more AST patterns.

This patch makes the CFG prepared for these scenarios by:

- Fork VariableConstructionContext and ReturnedValueConstructionContext into
  two different sub-classes (each) one of which indicates the C++17 case and
  contains a reference to an extra CXXBindTemporaryExpr.
- Allow CFGCXXRecordTypedCall element to accept VariableConstructionContext and
  ReturnedValueConstructionContext as its context.

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

Modified:
cfe/trunk/include/clang/Analysis/CFG.h
cfe/trunk/include/clang/Analysis/ConstructionContext.h
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/Analysis/ConstructionContext.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/test/Analysis/cfg-rich-constructors.cpp

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=328248=328247=328248=diff
==
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Thu Mar 22 14:37:39 2018
@@ -17,6 +17,7 @@
 
 #include "clang/AST/ExprCXX.h"
 #include "clang/Analysis/Support/BumpVector.h"
+#include "clang/Analysis/ConstructionContext.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/GraphTraits.h"
@@ -38,8 +39,6 @@ namespace clang {
 class ASTContext;
 class BinaryOperator;
 class CFG;
-class ConstructionContext;
-class TemporaryObjectConstructionContext;
 class CXXBaseSpecifier;
 class CXXBindTemporaryExpr;
 class CXXCtorInitializer;
@@ -171,14 +170,11 @@ private:
 };
 
 /// CFGCXXRecordTypedCall - Represents a function call that returns a C++ 
object
-/// by value. This, like constructor, requires a construction context, which
-/// will always be that of a temporary object - usually consumed by an elidable
-/// constructor. For such value-typed calls the 
ReturnedValueConstructionContext
-/// of their return value is naturally complemented by the
-/// TemporaryObjectConstructionContext at the call site (here). In C such
-/// tracking is not necessary because no additional effort is required for
-/// destroying the object or modeling copy elision. Like CFGConstructor, this 
is
-/// for now only used by the analyzer's CFG.
+/// by value. This, like constructor, requires a construction context in order
+/// to understand the storage of the returned object . In C such tracking is 
not
+/// necessary because no additional effort is required for destroying the 
object
+/// or modeling copy elision. Like CFGConstructor, this element is for now only
+/// used by the analyzer's CFG.
 class CFGCXXRecordTypedCall : public CFGStmt {
 public:
   /// Returns true when call expression \p CE needs to be represented
@@ -187,19 +183,19 @@ public:
 return 
CE->getCallReturnType(ACtx).getCanonicalType()->getAsCXXRecordDecl();
   }
 
-  explicit CFGCXXRecordTypedCall(CallExpr *CE,
- const TemporaryObjectConstructionContext *C)
+  explicit CFGCXXRecordTypedCall(CallExpr *CE, const ConstructionContext *C)
   : CFGStmt(CE, CXXRecordTypedCall) {
 // FIXME: This is not protected against squeezing a non-record-typed-call
 // into the constructor. An assertion would require passing an ASTContext
 // which would mean paying for something we don't use.
-assert(C);
-Data2.setPointer(const_cast(C));
+assert(C && (isa(C) ||
+ isa(C) ||
+ isa(C)));
+Data2.setPointer(const_cast(C));
   }
 
-  const TemporaryObjectConstructionContext *getConstructionContext() const {
-return static_cast(
-Data2.getPointer());
+  const ConstructionContext *getConstructionContext() const {
+return static_cast(Data2.getPointer());
   }
 
 private:
@@ -881,7 +877,7 @@ public:
   }
 
   void appendCXXRecordTypedCall(CallExpr *CE,
-const TemporaryObjectConstructionContext *CC,
+const ConstructionContext *CC,
 BumpVectorContext ) {
 Elements.push_back(CFGCXXRecordTypedCall(CE, CC), C);
   }

Modified: cfe/trunk/include/clang/Analysis/ConstructionContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ConstructionContext.h?rev=328248=328247=328248=diff
==
--- 

[PATCH] D44745: [HWASan] Port HWASan to Linux x86-64 (clang)

2018-03-22 Thread Aleksey Shlyapnikov via Phabricator via cfe-commits
alekseyshl updated this revision to Diff 139513.
alekseyshl added a comment.

- Revert triple change in asan.cc test


Repository:
  rC Clang

https://reviews.llvm.org/D44745

Files:
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChains/Linux.cpp
  test/Driver/Inputs/resource_dir/lib/linux/libclang_rt.hwasan-x86_64.a.syms
  test/Driver/fsanitize-blacklist.c
  test/Driver/fsanitize.c
  test/Driver/sanitizer-ld.c

Index: test/Driver/sanitizer-ld.c
===
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -696,54 +696,100 @@
 // CHECK-SCUDO-ANDROID-STATIC: "-lpthread"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -target aarch64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
+// RUN: -target x86_64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-HWASAN-LINUX %s
+// RUN:   | FileCheck --check-prefix=CHECK-HWASAN-X86-64-LINUX %s
 //
-// CHECK-HWASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-HWASAN-LINUX-NOT: "-lc"
-// CHECK-HWASAN-LINUX: libclang_rt.hwasan-aarch64.a"
-// CHECK-HWASAN-LINUX-NOT: "--export-dynamic"
-// CHECK-HWASAN-LINUX: "--dynamic-list={{.*}}libclang_rt.hwasan-aarch64.a.syms"
-// CHECK-HWASAN-LINUX-NOT: "--export-dynamic"
-// CHECK-HWASAN-LINUX: "-lpthread"
-// CHECK-HWASAN-LINUX: "-lrt"
-// CHECK-HWASAN-LINUX: "-ldl"
+// CHECK-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-HWASAN-X86-64-LINUX: "-pie"
+// CHECK-HWASAN-X86-64-LINUX-NOT: "-lc"
+// CHECK-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.a"
+// CHECK-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
+// CHECK-HWASAN-X86-64-LINUX: "--dynamic-list={{.*}}libclang_rt.hwasan-x86_64.a.syms"
+// CHECK-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
+// CHECK-HWASAN-X86-64-LINUX: "-lpthread"
+// CHECK-HWASAN-X86-64-LINUX: "-lrt"
+// CHECK-HWASAN-X86-64-LINUX: "-ldl"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -target aarch64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress -shared-libsan \
-// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: -target x86_64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
+// RUN: -shared-libsan -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-X86-64-LINUX %s
+//
+// CHECK-SHARED-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SHARED-HWASAN-X86-64-LINUX: "-pie"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lc"
+// CHECK-SHARED-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.so"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lpthread"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lrt"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-ldl"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
+// CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "--dynamic-list"
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.so -shared 2>&1 \
+// RUN: -target x86_64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
+// RUN: -shared-libsan -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-LINUX %s
+// RUN:   | FileCheck --check-prefix=CHECK-DSO-SHARED-HWASAN-X86-64-LINUX %s
+//
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-DSO_SHARED-HWASAN-X86-64-LINUX: "-pie"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lc"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.so"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lpthread"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lrt"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-ldl"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
+// CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "--dynamic-list"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target aarch64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
-// RUN: -shared-libsan \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-LINUX %s
+// RUN:   | FileCheck --check-prefix=CHECK-HWASAN-AARCH64-LINUX %s
 //
-// CHECK-SHARED-HWASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "-lc"
-// CHECK-SHARED-HWASAN-LINUX: libclang_rt.hwasan-aarch64.so"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "-lpthread"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "-lrt"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "-ldl"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "--export-dynamic"
-// CHECK-SHARED-HWASAN-LINUX-NOT: "--dynamic-list"
+// CHECK-HWASAN-AARCH64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-HWASAN-AARCH64-LINUX: "-pie"
+// CHECK-HWASAN-AARCH64-LINUX-NOT: "-lc"
+// 

[PATCH] D44745: [HWASan] Port HWASan to Linux x86-64 (clang)

2018-03-22 Thread Aleksey Shlyapnikov via Phabricator via cfe-commits
alekseyshl added inline comments.



Comment at: test/Driver/asan.c:12
-// RUN: %clang -O2 -target aarch64-unknown-linux -fsanitize=hwaddress %s -S 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-HWASAN
-// RUN: %clang -O3 -target aarch64-unknown-linux -fsanitize=hwaddress %s -S 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-HWASAN
 // Verify that -fsanitize={address,kernel-address} invoke ASan and KASan 
instrumentation.

eugenis wrote:
> alekseyshl wrote:
> > eugenis wrote:
> > > Don't replace existing tests!
> > > Add new ones.
> > > 
> > I am not replacing them, I am making it consistent with all other 
> > sanitizers, which also support many more platforms than just 
> > x86_64-linux-gnu or *-unknown-linux, but have tests for that one platform 
> > only.
> I don't think this is a good argument for changing existing tests. It does 
> not add any new coverage, and in this particular example it is not even 
> consistent with surrounding RUN lines - those use i386 triple. It simply adds 
> noise to code history.
> 
> If you want to test that hwasan supports x86_64 triple - add a new test case.
> 
Ok, this file, I'm ambivalent about, it is not consistent already, but the 
other ones I do feel quite strongly about, they are become more consistent and 
consistency is good.


Repository:
  rC Clang

https://reviews.llvm.org/D44745



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


[PATCH] D44347: [analyzer] symbol_iterator must iterate through the symbolic base.

2018-03-22 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328247: [analyzer] Make symbol_iterator iterate over 
SVals symbolic base. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44347

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  test/Analysis/symbol-reaper.c


Index: include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -195,7 +195,7 @@
   void dump() const;
 
   SymExpr::symbol_iterator symbol_begin() const {
-const SymExpr *SE = getAsSymbolicExpression();
+const SymExpr *SE = getAsSymbol(/*IncludeBaseRegions=*/true);
 if (SE)
   return SE->symbol_begin();
 else
Index: test/Analysis/symbol-reaper.c
===
--- test/Analysis/symbol-reaper.c
+++ test/Analysis/symbol-reaper.c
@@ -3,6 +3,9 @@
 void clang_analyzer_eval(int);
 void clang_analyzer_warnOnDeadSymbol(int);
 void clang_analyzer_numTimesReached();
+void clang_analyzer_warnIfReached();
+
+void exit(int);
 
 int conjure_index();
 
@@ -58,6 +61,12 @@
 struct S2 {
   struct S1 array[5];
 } s2;
+struct S3 {
+  void *field;
+};
+
+struct S1 *conjure_S1();
+struct S3 *conjure_S3();
 
 void test_element_index_lifetime_with_complicated_hierarchy_of_regions() {
   do {
@@ -68,6 +77,18 @@
   } while (0); // no-warning
 }
 
+void test_loc_as_integer_element_index_lifetime() {
+  do {
+int x;
+struct S3 *s = conjure_S3();
+clang_analyzer_warnOnDeadSymbol((int)s);
+x = (int)&(s->field);
+ptr = [x];
+if (s) {}
+  // FIXME: Should not warn. The symbol is still alive within the ptr's index.
+  } while (0); // expected-warning{{SYMBOL DEAD}}
+}
+
 // Test below checks lifetime of SymbolRegionValue in certain conditions.
 
 int **ptrptr;
@@ -78,3 +99,38 @@
   (void)0; // No-op; make sure the environment forgets things and the GC runs.
   clang_analyzer_eval(**ptrptr); // expected-warning{{TRUE}}
 } // no-warning
+
+int *produce_region_referenced_only_through_field_in_environment_value() {
+  struct S1 *s = conjure_S1();
+  clang_analyzer_warnOnDeadSymbol((int) s);
+  int *x = >field;
+  return x;
+}
+
+void test_region_referenced_only_through_field_in_environment_value() {
+  produce_region_referenced_only_through_field_in_environment_value();
+} // expected-warning{{SYMBOL DEAD}}
+
+void test_region_referenced_only_through_field_in_store_value() {
+  struct S1 *s = conjure_S1();
+  clang_analyzer_warnOnDeadSymbol((int) s);
+  ptr = >field; // Write the symbol into a global. It should live forever.
+  if (!s) {
+exit(0); // no-warning (symbol should not die here)
+// exit() is noreturn.
+clang_analyzer_warnIfReached(); // no-warning
+  }
+  if (!ptr) { // no-warning (symbol should not die here)
+// We exit()ed under these constraints earlier.
+clang_analyzer_warnIfReached(); // no-warning
+  }
+  // The exit() call invalidates globals. The symbol will die here because
+  // the exit() statement itself is already over and there's no better 
statement
+  // to put the diagnostic on.
+} // expected-warning{{SYMBOL DEAD}}
+
+void test_zombie_referenced_only_through_field_in_store_value() {
+  struct S1 *s = conjure_S1();
+  clang_analyzer_warnOnDeadSymbol((int) s);
+  int *x = >field;
+} // expected-warning{{SYMBOL DEAD}}


Index: include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -195,7 +195,7 @@
   void dump() const;
 
   SymExpr::symbol_iterator symbol_begin() const {
-const SymExpr *SE = getAsSymbolicExpression();
+const SymExpr *SE = getAsSymbol(/*IncludeBaseRegions=*/true);
 if (SE)
   return SE->symbol_begin();
 else
Index: test/Analysis/symbol-reaper.c
===
--- test/Analysis/symbol-reaper.c
+++ test/Analysis/symbol-reaper.c
@@ -3,6 +3,9 @@
 void clang_analyzer_eval(int);
 void clang_analyzer_warnOnDeadSymbol(int);
 void clang_analyzer_numTimesReached();
+void clang_analyzer_warnIfReached();
+
+void exit(int);
 
 int conjure_index();
 
@@ -58,6 +61,12 @@
 struct S2 {
   struct S1 array[5];
 } s2;
+struct S3 {
+  void *field;
+};
+
+struct S1 *conjure_S1();
+struct S3 *conjure_S3();
 
 void test_element_index_lifetime_with_complicated_hierarchy_of_regions() {
   do {
@@ -68,6 +77,18 @@
   } while (0); // no-warning
 }
 
+void test_loc_as_integer_element_index_lifetime() {
+  do {
+int x;
+struct S3 *s = conjure_S3();
+clang_analyzer_warnOnDeadSymbol((int)s);
+x = (int)&(s->field);
+ 

r328247 - [analyzer] Make symbol_iterator iterate over SVal's symbolic base.

2018-03-22 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Mar 22 14:30:58 2018
New Revision: 328247

URL: http://llvm.org/viewvc/llvm-project?rev=328247=rev
Log:
[analyzer] Make symbol_iterator iterate over SVal's symbolic base.

If a memory region (or an SVal that represents a pointer to that memory region)
is a (direct or indirect, not necessarily proper) sub-region of a SymbolicRegion
then it is said to have a symbolic base.

For now SVal::symbol_iterator explores the symbol within a symbolic region
only when the SVal represents a pointer to the symbolic region itself,
not to any of its sub-regions.

This behavior is not indended by any user of symbol_iterator; all users who
cared about such behavior were expecting the iterator to descend into the
symbolic base of an arbitrary region, find the parent symbol of the symbolic
base region, and iterate over that symbol. Lack of such behavior resulted in
bugs demonstarted by the test cases.

Hence the decision to change the API to behave more intuitively.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
cfe/trunk/test/Analysis/symbol-reaper.c

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h?rev=328247=328246=328247=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h Thu Mar 
22 14:30:58 2018
@@ -195,7 +195,7 @@ public:
   void dump() const;
 
   SymExpr::symbol_iterator symbol_begin() const {
-const SymExpr *SE = getAsSymbolicExpression();
+const SymExpr *SE = getAsSymbol(/*IncludeBaseRegions=*/true);
 if (SE)
   return SE->symbol_begin();
 else

Modified: cfe/trunk/test/Analysis/symbol-reaper.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/symbol-reaper.c?rev=328247=328246=328247=diff
==
--- cfe/trunk/test/Analysis/symbol-reaper.c (original)
+++ cfe/trunk/test/Analysis/symbol-reaper.c Thu Mar 22 14:30:58 2018
@@ -3,6 +3,9 @@
 void clang_analyzer_eval(int);
 void clang_analyzer_warnOnDeadSymbol(int);
 void clang_analyzer_numTimesReached();
+void clang_analyzer_warnIfReached();
+
+void exit(int);
 
 int conjure_index();
 
@@ -58,6 +61,12 @@ struct S1 {
 struct S2 {
   struct S1 array[5];
 } s2;
+struct S3 {
+  void *field;
+};
+
+struct S1 *conjure_S1();
+struct S3 *conjure_S3();
 
 void test_element_index_lifetime_with_complicated_hierarchy_of_regions() {
   do {
@@ -68,6 +77,18 @@ void test_element_index_lifetime_with_co
   } while (0); // no-warning
 }
 
+void test_loc_as_integer_element_index_lifetime() {
+  do {
+int x;
+struct S3 *s = conjure_S3();
+clang_analyzer_warnOnDeadSymbol((int)s);
+x = (int)&(s->field);
+ptr = [x];
+if (s) {}
+  // FIXME: Should not warn. The symbol is still alive within the ptr's index.
+  } while (0); // expected-warning{{SYMBOL DEAD}}
+}
+
 // Test below checks lifetime of SymbolRegionValue in certain conditions.
 
 int **ptrptr;
@@ -78,3 +99,38 @@ void test_region_lifetime_as_store_value
   (void)0; // No-op; make sure the environment forgets things and the GC runs.
   clang_analyzer_eval(**ptrptr); // expected-warning{{TRUE}}
 } // no-warning
+
+int *produce_region_referenced_only_through_field_in_environment_value() {
+  struct S1 *s = conjure_S1();
+  clang_analyzer_warnOnDeadSymbol((int) s);
+  int *x = >field;
+  return x;
+}
+
+void test_region_referenced_only_through_field_in_environment_value() {
+  produce_region_referenced_only_through_field_in_environment_value();
+} // expected-warning{{SYMBOL DEAD}}
+
+void test_region_referenced_only_through_field_in_store_value() {
+  struct S1 *s = conjure_S1();
+  clang_analyzer_warnOnDeadSymbol((int) s);
+  ptr = >field; // Write the symbol into a global. It should live forever.
+  if (!s) {
+exit(0); // no-warning (symbol should not die here)
+// exit() is noreturn.
+clang_analyzer_warnIfReached(); // no-warning
+  }
+  if (!ptr) { // no-warning (symbol should not die here)
+// We exit()ed under these constraints earlier.
+clang_analyzer_warnIfReached(); // no-warning
+  }
+  // The exit() call invalidates globals. The symbol will die here because
+  // the exit() statement itself is already over and there's no better 
statement
+  // to put the diagnostic on.
+} // expected-warning{{SYMBOL DEAD}}
+
+void test_zombie_referenced_only_through_field_in_store_value() {
+  struct S1 *s = conjure_S1();
+  clang_analyzer_warnOnDeadSymbol((int) s);
+  int *x = >field;
+} // expected-warning{{SYMBOL DEAD}}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[libcxx] r328245 - Use DoNotOptimize to prevent new/delete elision.

2018-03-22 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Mar 22 14:28:09 2018
New Revision: 328245

URL: http://llvm.org/viewvc/llvm-project?rev=328245=rev
Log:
Use DoNotOptimize to prevent new/delete elision.

The new/delete tests, in particular those which test replacement
functions, often fail when the optimizer is enabled because the
calls to new/delete may be optimized away, regardless of their side-effects.

This patch converts the tests to use DoNotOptimize in order to prevent
the elision.

Modified:

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_replace.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_calls_unsized_delete_array.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.single/delete_align_val_t_replace.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_replace.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete11.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_calls_unsized_delete.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_fsizeddeallocation.sh.cpp

libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
libcxx/trunk/test/support/test_macros.h

Modified: 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp?rev=328245=328244=328245=diff
==
--- 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp
 Thu Mar 22 14:28:09 2018
@@ -69,31 +69,32 @@ void operator delete [] (void* p, std::a
 struct alignas(OverAligned) A {};
 struct alignas(std::max_align_t) B {};
 
-B* volatile b; // Escape the memory
-A* volatile a;
-
 int main()
 {
 reset();
 {
-b = new B[2];
+B *b = new B[2];
+DoNotOptimize(b);
 assert(0 == unsized_delete_called);
 assert(0 == unsized_delete_nothrow_called);
 assert(0 == aligned_delete_called);
 
 delete [] b;
+DoNotOptimize(b);
 assert(1 == unsized_delete_called);
 assert(0 == unsized_delete_nothrow_called);
 assert(0 == aligned_delete_called);
 }
 reset();
 {
-a = new A[2];
+A *a = new A[2];
+DoNotOptimize(a);
 assert(0 == unsized_delete_called);
 assert(0 == unsized_delete_nothrow_called);
 assert(0 == aligned_delete_called);
 
 delete [] a;
+DoNotOptimize(a);
 assert(0 == unsized_delete_called);
 assert(0 == unsized_delete_nothrow_called);
 assert(1 == aligned_delete_called);

Modified: 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_replace.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_replace.pass.cpp?rev=328245=328244=328245=diff
==
--- 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_replace.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_replace.pass.cpp
 Thu Mar 22 14:28:09 2018
@@ -53,7 +53,9 @@ void* operator new[](std::size_t s, std:
 assert(s <= sizeof(DummyData));
 

r328243 - Fix test failure on Windows caused by different underlying enumeration type rules

2018-03-22 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Mar 22 14:17:07 2018
New Revision: 328243

URL: http://llvm.org/viewvc/llvm-project?rev=328243=rev
Log:
Fix test failure on Windows caused by different underlying enumeration type 
rules

Modified:
cfe/trunk/test/SemaCXX/builtin-operator-new-delete.cpp

Modified: cfe/trunk/test/SemaCXX/builtin-operator-new-delete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-operator-new-delete.cpp?rev=328243=328242=328243=diff
==
--- cfe/trunk/test/SemaCXX/builtin-operator-new-delete.cpp (original)
+++ cfe/trunk/test/SemaCXX/builtin-operator-new-delete.cpp Thu Mar 22 14:17:07 
2018
@@ -19,8 +19,12 @@ namespace std {
 #if __cplusplus >= 201103L
 enum class align_val_t : size_t {};
 #else
-  enum align_val_t { __zero = 0,
- __max = (size_t)-1 };
+  enum align_val_t {
+  // We can't force an underlying type when targeting windows.
+# ifndef _WIN32
+__zero = 0, __max = (size_t)-1
+# endif
+  };
 #endif
 }
 std::nothrow_t nothrow;


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


[PATCH] D44788: Add an option to support debug fission on implicit ThinLTO.

2018-03-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

The only data we have is that where .o files go, .dwo files go beside them.
How to generalize this to other situations isn't really obvious to me -
even for a.out (do you put all the .dwo files next to a.out? in the same
directory? if the names collide, where then? etc).

Interestingly GCC for "g++ foo.cpp" puts the foo.dwo file right where it
would go by default (next to foo.cpp, even though there's no foo.o).  Oh,
LLVM does that too. Huh. I'm not sure that's a terribly helpful default to
extrapolate to ThinLTO for, though.


Repository:
  rC Clang

https://reviews.llvm.org/D44788



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


Re: [PATCH] D44788: Add an option to support debug fission on implicit ThinLTO.

2018-03-22 Thread David Blaikie via cfe-commits
The only data we have is that where .o files go, .dwo files go beside them.
How to generalize this to other situations isn't really obvious to me -
even for a.out (do you put all the .dwo files next to a.out? in the same
directory? if the names collide, where then? etc).

Interestingly GCC for "g++ foo.cpp" puts the foo.dwo file right where it
would go by default (next to foo.cpp, even though there's no foo.o).  Oh,
LLVM does that too. Huh. I'm not sure that's a terribly helpful default to
extrapolate to ThinLTO for, though.



On Thu, Mar 22, 2018 at 1:57 PM Paul Robinson via Phabricator <
revi...@reviews.llvm.org> wrote:

> probinson added a comment.
>
> In https://reviews.llvm.org/D44788#1046093, @dblaikie wrote:
>
> > In implicit ThinLTO, the object files are only temporary.
> >
> > Sort of similar to using -gsplit-dwarf when compiling straight to an
> >  executable (without using -c): "clang++ x.cpp y.cpp -o a.out" - where
> >  should the .dwo files go then? If they go where the .o files go, then
> >  they'll be in /tmp/ and get deleted either when the ocmpiler ends after
> it
> >  runs the linker, or perhaps at some uncertain point in the future when
> the
> >  temp space is reclaimed.
>
>
> I think that the .dwo files generally go where the user-specified final
> output goes.  So in your example they would go where a.out goes, not where
> the intermediate/temporary .o files go.
> Being able to override that is fine, but being required to specify a
> directory in order to get fission in the first place is not.
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D44788
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r328242 - Revert "Set dso_local on vtables."

2018-03-22 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Thu Mar 22 14:14:16 2018
New Revision: 328242

URL: http://llvm.org/viewvc/llvm-project?rev=328242=rev
Log:
Revert "Set dso_local on vtables."

This reverts commit r328238.

Looks like it broke some buildbots.

Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/dllexport.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=328242=328241=328242=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Thu Mar 22 14:14:16 2018
@@ -2848,7 +2848,6 @@ void ItaniumRTTIBuilder::BuildVTablePoin
 
   const char *VTableName = nullptr;
 
-  const CXXRecordDecl *RD = nullptr;
   switch (Ty->getTypeClass()) {
 #define TYPE(Class, Base)
 #define ABSTRACT_TYPE(Class, Base)
@@ -2900,7 +2899,8 @@ void ItaniumRTTIBuilder::BuildVTablePoin
 break;
 
   case Type::Record: {
-RD = cast(cast(Ty)->getDecl());
+const CXXRecordDecl *RD =
+  cast(cast(Ty)->getDecl());
 
 if (!RD->hasDefinition() || !RD->getNumBases()) {
   VTableName = ClassTypeInfo;
@@ -2948,7 +2948,6 @@ void ItaniumRTTIBuilder::BuildVTablePoin
 
   llvm::Constant *VTable =
 CGM.getModule().getOrInsertGlobal(VTableName, CGM.Int8PtrTy);
-  CGM.setGVProperties(cast(VTable->stripPointerCasts()), 
RD);
 
   llvm::Type *PtrDiffTy =
 CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType());

Modified: cfe/trunk/test/CodeGenCXX/dllexport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport.cpp?rev=328242=328241=328242=diff
==
--- cfe/trunk/test/CodeGenCXX/dllexport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllexport.cpp Thu Mar 22 14:14:16 2018
@@ -41,8 +41,6 @@ struct External { int v; };
 // GNU-NOT: @ExternGlobalDecl
 __declspec(dllexport) extern int ExternGlobalDecl;
 
-// GNU-DAG: @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global
-
 // dllexport implies a definition.
 // MSC-DAG: @"?GlobalDef@@3HA" = dso_local dllexport global i32 0, align 4
 // GNU-DAG: @GlobalDef= dso_local dllexport global i32 0, align 4


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


[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

2018-03-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 139506.
vsapsai added a comment.

- Replace `function::operator=(nullptr);` with `*this = nullptr;`


https://reviews.llvm.org/D34331

Files:
  libcxx/include/__functional_03
  libcxx/include/functional
  
libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp
  
libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp

Index: libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp
@@ -0,0 +1,46 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// class function
+
+// function& operator=(nullptr_t);
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+struct A
+{
+  static std::function global;
+  static bool cancel;
+
+  ~A() {
+DoNotOptimize(cancel);
+if (cancel)
+  global = nullptr;
+  }
+  void operator()() {}
+};
+
+std::function A::global;
+bool A::cancel = false;
+
+int main()
+{
+  A::global = A();
+  assert(A::global.target());
+
+  // Check that we don't recurse in A::~A().
+  A::cancel = true;
+  A::global = nullptr;
+  assert(!A::global.target());
+}
Index: libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp
@@ -0,0 +1,46 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// class function
+
+// function& operator=(function &&);
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+struct A
+{
+  static std::function global;
+  static bool cancel;
+
+  ~A() {
+DoNotOptimize(cancel);
+if (cancel)
+  global = std::function(nullptr);
+  }
+  void operator()() {}
+};
+
+std::function A::global;
+bool A::cancel = false;
+
+int main()
+{
+  A::global = A();
+  assert(A::global.target());
+
+  // Check that we don't recurse in A::~A().
+  A::cancel = true;
+  A::global = std::function(nullptr);
+  assert(!A::global.target());
+}
Index: libcxx/include/functional
===
--- libcxx/include/functional
+++ libcxx/include/functional
@@ -1818,11 +1818,7 @@
 function<_Rp(_ArgTypes...)>&
 function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
 {
-if ((void *)__f_ == &__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
-__f_ = 0;
+*this = nullptr;
 if (__f.__f_ == 0)
 __f_ = 0;
 else if ((void *)__f.__f_ == &__f.__buf_)
@@ -1842,11 +1838,12 @@
 function<_Rp(_ArgTypes...)>&
 function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
 {
-if ((void *)__f_ == &__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
+__base* __t = __f_;
 __f_ = 0;
+if ((void *)__t == &__buf_)
+__t->destroy();
+else if (__t)
+__t->destroy_deallocate();
 return *this;
 }
 
Index: libcxx/include/__functional_03
===
--- libcxx/include/__functional_03
+++ libcxx/include/__functional_03
@@ -600,19 +600,23 @@
 function<_Rp()>&
 function<_Rp()>::operator=(const function& __f)
 {
-function(__f).swap(*this);
+if (__f)
+function(__f).swap(*this);
+else
+*this = nullptr;
 return *this;
 }
 
 template
 function<_Rp()>&
 function<_Rp()>::operator=(nullptr_t)
 {
-if (__f_ == (__base*)&__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
+__base* __t = __f_;
 __f_ = 0;
+if (__t == (__base*)&__buf_)
+__t->destroy();
+else if (__t)
+__t->destroy_deallocate();
 return *this;
 }
 
@@ -876,19 +880,23 @@
 function<_Rp(_A0)>&
 function<_Rp(_A0)>::operator=(const function& __f)
 {
-function(__f).swap(*this);
+if (__f)
+   

[PATCH] D44798: [libFuzzer] Use OptForFuzzing attribute with -fsanitize=fuzzer.

2018-03-22 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: compiler-rt/test/fuzzer/lit.cfg:88
+
+config.substitutions.append(('%no_opt_cpp_compiler',
+  generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, optimize=False)

Maybe instead of new substitutions, better just explicitly add -O0 into tests




https://reviews.llvm.org/D44798



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


[PATCH] D44805: Set dso_local on __ImageBase

2018-03-22 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


https://reviews.llvm.org/D44805



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


[PATCH] D44788: Add an option to support debug fission on implicit ThinLTO.

2018-03-22 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

In https://reviews.llvm.org/D44788#1046093, @dblaikie wrote:

> In implicit ThinLTO, the object files are only temporary.
>
> Sort of similar to using -gsplit-dwarf when compiling straight to an
>  executable (without using -c): "clang++ x.cpp y.cpp -o a.out" - where
>  should the .dwo files go then? If they go where the .o files go, then
>  they'll be in /tmp/ and get deleted either when the ocmpiler ends after it
>  runs the linker, or perhaps at some uncertain point in the future when the
>  temp space is reclaimed.


I think that the .dwo files generally go where the user-specified final output 
goes.  So in your example they would go where a.out goes, not where the 
intermediate/temporary .o files go.
Being able to override that is fine, but being required to specify a directory 
in order to get fission in the first place is not.


Repository:
  rC Clang

https://reviews.llvm.org/D44788



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


[PATCH] D44805: Set dso_local on __ImageBase

2018-03-22 Thread Rafael Avila de Espindola via Phabricator via cfe-commits
espindola created this revision.
espindola added reviewers: echristo, rnk.

https://reviews.llvm.org/D44805

Files:
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/dllexport.cpp


Index: test/CodeGenCXX/dllexport.cpp
===
--- test/CodeGenCXX/dllexport.cpp
+++ test/CodeGenCXX/dllexport.cpp
@@ -43,6 +43,8 @@
 
 // GNU-DAG: @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global
 
+// M64-DAG: @__ImageBase = external dso_local constant i8
+
 // dllexport implies a definition.
 // MSC-DAG: @"?GlobalDef@@3HA" = dso_local dllexport global i32 0, align 4
 // GNU-DAG: @GlobalDef= dso_local dllexport global i32 0, align 4
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -523,10 +523,12 @@
 if (llvm::GlobalVariable *GV = CGM.getModule().getNamedGlobal(Name))
   return GV;
 
-return new llvm::GlobalVariable(CGM.getModule(), CGM.Int8Ty,
-/*isConstant=*/true,
-llvm::GlobalValue::ExternalLinkage,
-/*Initializer=*/nullptr, Name);
+auto *GV = new llvm::GlobalVariable(CGM.getModule(), CGM.Int8Ty,
+/*isConstant=*/true,
+llvm::GlobalValue::ExternalLinkage,
+/*Initializer=*/nullptr, Name);
+CGM.setDSOLocal(GV);
+return GV;
   }
 
   llvm::Constant *getImageRelativeConstant(llvm::Constant *PtrVal) {


Index: test/CodeGenCXX/dllexport.cpp
===
--- test/CodeGenCXX/dllexport.cpp
+++ test/CodeGenCXX/dllexport.cpp
@@ -43,6 +43,8 @@
 
 // GNU-DAG: @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global
 
+// M64-DAG: @__ImageBase = external dso_local constant i8
+
 // dllexport implies a definition.
 // MSC-DAG: @"?GlobalDef@@3HA" = dso_local dllexport global i32 0, align 4
 // GNU-DAG: @GlobalDef= dso_local dllexport global i32 0, align 4
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -523,10 +523,12 @@
 if (llvm::GlobalVariable *GV = CGM.getModule().getNamedGlobal(Name))
   return GV;
 
-return new llvm::GlobalVariable(CGM.getModule(), CGM.Int8Ty,
-/*isConstant=*/true,
-llvm::GlobalValue::ExternalLinkage,
-/*Initializer=*/nullptr, Name);
+auto *GV = new llvm::GlobalVariable(CGM.getModule(), CGM.Int8Ty,
+/*isConstant=*/true,
+llvm::GlobalValue::ExternalLinkage,
+/*Initializer=*/nullptr, Name);
+CGM.setDSOLocal(GV);
+return GV;
   }
 
   llvm::Constant *getImageRelativeConstant(llvm::Constant *PtrVal) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44745: [HWASan] Port HWASan to Linux x86-64 (clang)

2018-03-22 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added inline comments.



Comment at: test/Driver/asan.c:12
-// RUN: %clang -O2 -target aarch64-unknown-linux -fsanitize=hwaddress %s -S 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-HWASAN
-// RUN: %clang -O3 -target aarch64-unknown-linux -fsanitize=hwaddress %s -S 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-HWASAN
 // Verify that -fsanitize={address,kernel-address} invoke ASan and KASan 
instrumentation.

alekseyshl wrote:
> eugenis wrote:
> > Don't replace existing tests!
> > Add new ones.
> > 
> I am not replacing them, I am making it consistent with all other sanitizers, 
> which also support many more platforms than just x86_64-linux-gnu or 
> *-unknown-linux, but have tests for that one platform only.
I don't think this is a good argument for changing existing tests. It does not 
add any new coverage, and in this particular example it is not even consistent 
with surrounding RUN lines - those use i386 triple. It simply adds noise to 
code history.

If you want to test that hwasan supports x86_64 triple - add a new test case.



Repository:
  rC Clang

https://reviews.llvm.org/D44745



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


[PATCH] D44801: Add the -fsanitize=shadow-call-stack flag

2018-03-22 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc accepted this revision.
pcc added a comment.
This revision is now accepted and ready to land.

LGTM

Please add a test for the driver functionality.


Repository:
  rC Clang

https://reviews.llvm.org/D44801



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


[PATCH] D44796: Set dso_local on vtables

2018-03-22 Thread Rafael Avila de Espindola via Phabricator via cfe-commits
espindola accepted this revision.
espindola added a comment.

328238


https://reviews.llvm.org/D44796



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


r328238 - Set dso_local on vtables.

2018-03-22 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Thu Mar 22 13:33:01 2018
New Revision: 328238

URL: http://llvm.org/viewvc/llvm-project?rev=328238=rev
Log:
Set dso_local on vtables.

Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/dllexport.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=328238=328237=328238=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Thu Mar 22 13:33:01 2018
@@ -2848,6 +2848,7 @@ void ItaniumRTTIBuilder::BuildVTablePoin
 
   const char *VTableName = nullptr;
 
+  const CXXRecordDecl *RD = nullptr;
   switch (Ty->getTypeClass()) {
 #define TYPE(Class, Base)
 #define ABSTRACT_TYPE(Class, Base)
@@ -2899,8 +2900,7 @@ void ItaniumRTTIBuilder::BuildVTablePoin
 break;
 
   case Type::Record: {
-const CXXRecordDecl *RD =
-  cast(cast(Ty)->getDecl());
+RD = cast(cast(Ty)->getDecl());
 
 if (!RD->hasDefinition() || !RD->getNumBases()) {
   VTableName = ClassTypeInfo;
@@ -2948,6 +2948,7 @@ void ItaniumRTTIBuilder::BuildVTablePoin
 
   llvm::Constant *VTable =
 CGM.getModule().getOrInsertGlobal(VTableName, CGM.Int8PtrTy);
+  CGM.setGVProperties(cast(VTable->stripPointerCasts()), 
RD);
 
   llvm::Type *PtrDiffTy =
 CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType());

Modified: cfe/trunk/test/CodeGenCXX/dllexport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport.cpp?rev=328238=328237=328238=diff
==
--- cfe/trunk/test/CodeGenCXX/dllexport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllexport.cpp Thu Mar 22 13:33:01 2018
@@ -41,6 +41,8 @@ struct External { int v; };
 // GNU-NOT: @ExternGlobalDecl
 __declspec(dllexport) extern int ExternGlobalDecl;
 
+// GNU-DAG: @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global
+
 // dllexport implies a definition.
 // MSC-DAG: @"?GlobalDef@@3HA" = dso_local dllexport global i32 0, align 4
 // GNU-DAG: @GlobalDef= dso_local dllexport global i32 0, align 4


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


[PATCH] D44804: [StaticAnalyzer] Silence an unused variable warning. NFC.

2018-03-22 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

In https://reviews.llvm.org/D44804#1046086, @george.karpenkov wrote:

> LGTM, provided it compiles and tests run (`ninja check-clang`)


Thanks! Yes, I have already verified it compiles and ninja check-clang is clean.


Repository:
  rC Clang

https://reviews.llvm.org/D44804



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


[PATCH] D44788: Add an option to support debug fission on implicit ThinLTO.

2018-03-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a subscriber: yunlian.
dblaikie added a comment.

In implicit ThinLTO, the object files are only temporary.

Sort of similar to using -gsplit-dwarf when compiling straight to an
executable (without using -c): "clang++ x.cpp y.cpp -o a.out" - where
should the .dwo files go then? If they go where the .o files go, then
they'll be in /tmp/ and get deleted either when the ocmpiler ends after it
runs the linker, or perhaps at some uncertain point in the future when the
temp space is reclaimed.
(granted, I'm not suggesting we support that actual case - it's not
terribly common for anyone who'd actually need -gsplit-dwarf - but the
implicit ThinLTO case looks quite similar for demonstration purposes)


Repository:
  rC Clang

https://reviews.llvm.org/D44788



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


Re: [PATCH] D44788: Add an option to support debug fission on implicit ThinLTO.

2018-03-22 Thread David Blaikie via cfe-commits
In implicit ThinLTO, the object files are only temporary.

Sort of similar to using -gsplit-dwarf when compiling straight to an
executable (without using -c): "clang++ x.cpp y.cpp -o a.out" - where
should the .dwo files go then? If they go where the .o files go, then
they'll be in /tmp/ and get deleted either when the ocmpiler ends after it
runs the linker, or perhaps at some uncertain point in the future when the
temp space is reclaimed.
(granted, I'm not suggesting we support that actual case - it's not
terribly common for anyone who'd actually need -gsplit-dwarf - but the
implicit ThinLTO case looks quite similar for demonstration purposes)


On Thu, Mar 22, 2018 at 1:22 PM Paul Robinson via Phabricator <
revi...@reviews.llvm.org> wrote:

> probinson added a comment.
>
> I don't think requiring a new option is a great user interface.  In
> existing use cases the location of the .dwo file matches the location of
> the output file.  Why is this one different?
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D44788
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44804: [StaticAnalyzer] Silence an unused variable warning. NFC.

2018-03-22 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov accepted this revision.
george.karpenkov added a comment.
This revision is now accepted and ready to land.

LGTM, provided it compiles and tests run (`ninja check-clang`)


Repository:
  rC Clang

https://reviews.llvm.org/D44804



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


[PATCH] D44788: Add an option to support debug fission on implicit ThinLTO.

2018-03-22 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

I don't think requiring a new option is a great user interface.  In existing 
use cases the location of the .dwo file matches the location of the output 
file.  Why is this one different?


Repository:
  rC Clang

https://reviews.llvm.org/D44788



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


[PATCH] D44804: [StaticAnalyzer] Silence an unused variable warning. NFC.

2018-03-22 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 139503.
mgrang added a comment.

Addressed comment.


Repository:
  rC Clang

https://reviews.llvm.org/D44804

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1931,7 +1931,7 @@
 
 static Optional describeRegion(const MemRegion *MR) {
   if (const auto *VR = dyn_cast_or_null(MR))
-return std::string(cast(MR)->getDecl()->getName());
+return std::string(VR->getDecl()->getName());
   // Once we support more storage locations for bindings,
   // this would need to be improved.
   return None;


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1931,7 +1931,7 @@
 
 static Optional describeRegion(const MemRegion *MR) {
   if (const auto *VR = dyn_cast_or_null(MR))
-return std::string(cast(MR)->getDecl()->getName());
+return std::string(VR->getDecl()->getName());
   // Once we support more storage locations for bindings,
   // this would need to be improved.
   return None;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r328134 - [Builtins] Overload __builtin_operator_new/delete to allow forwarding to usual allocation/deallocation functions.

2018-03-22 Thread Eric Fiselier via cfe-commits
Just waiting on a build. It should be fixed shortly.
Sorry about the breakage.

/Eric

On Thu, Mar 22, 2018 at 11:56 AM, Eric Fiselier  wrote:

> Sorry, I didn't see the failure yesterday.
>
> I'll get on it or revert it.
>
> On Thu, Mar 22, 2018 at 11:51 AM, Galina Kistanova 
> wrote:
>
>> Hello Eric,
>>
>> One of added tests fails on the next builder:
>> http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensiv
>> e-checks-win/builds/8624
>>
>> . . .
>> Failing Tests:
>>. . .
>> Clang :: SemaCXX/builtin-operator-new-delete.cpp
>>
>> Please have a look?
>>
>> It is not good idea to keep the bot red for too long. This hides new
>> problem which later hard to track down.
>>
>> Thanks
>>
>> Galina
>>
>>
>> On Wed, Mar 21, 2018 at 12:19 PM, Eric Fiselier via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: ericwf
>>> Date: Wed Mar 21 12:19:48 2018
>>> New Revision: 328134
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=328134=rev
>>> Log:
>>> [Builtins] Overload __builtin_operator_new/delete to allow forwarding to
>>> usual allocation/deallocation functions.
>>>
>>> Summary:
>>> Libc++'s default allocator uses `__builtin_operator_new` and
>>> `__builtin_operator_delete` in order to allow the calls to new/delete to be
>>> ellided. However, libc++ now needs to support over-aligned types in the
>>> default allocator. In order to support this without disabling the existing
>>> optimization Clang needs to support calling the aligned new overloads from
>>> the builtins.
>>>
>>> See llvm.org/PR22634 for more information about the libc++ bug.
>>>
>>> This patch changes `__builtin_operator_new`/`__builtin_operator_delete`
>>> to call any usual `operator new`/`operator delete` function. It does this
>>> by performing overload resolution with the arguments passed to the builtin
>>> to determine which allocation function to call. If the selected function is
>>> not a usual allocation function a diagnostic is issued.
>>>
>>> One open issue is if the `align_val_t` overloads should be considered
>>> "usual" when `LangOpts::AlignedAllocation` is disabled.
>>>
>>>
>>> In order to allow libc++ to detect this new behavior the value for
>>> `__has_builtin(__builtin_operator_new)` has been updated to `201802`.
>>>
>>> Reviewers: rsmith, majnemer, aaron.ballman, erik.pilkington, bogner,
>>> ahatanak
>>>
>>> Reviewed By: rsmith
>>>
>>> Subscribers: cfe-commits
>>>
>>> Differential Revision: https://reviews.llvm.org/D43047
>>>
>>> Added:
>>> cfe/trunk/test/CodeGenCXX/builtin-operator-new-delete.cpp
>>> cfe/trunk/test/SemaCXX/builtin-operator-new-delete.cpp
>>> Modified:
>>> cfe/trunk/include/clang/Basic/Builtins.def
>>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> cfe/trunk/include/clang/Sema/Sema.h
>>> cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>>> cfe/trunk/lib/CodeGen/CGExprCXX.cpp
>>> cfe/trunk/lib/CodeGen/CodeGenFunction.h
>>> cfe/trunk/lib/Lex/PPMacroExpansion.cpp
>>> cfe/trunk/lib/Sema/SemaChecking.cpp
>>> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>>>
>>> Modified: cfe/trunk/include/clang/Basic/Builtins.def
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>>> Basic/Builtins.def?rev=328134=328133=328134=diff
>>> 
>>> ==
>>> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
>>> +++ cfe/trunk/include/clang/Basic/Builtins.def Wed Mar 21 12:19:48 2018
>>> @@ -1371,8 +1371,8 @@ BUILTIN(__builtin_smulll_overflow, "bSLL
>>>
>>>  // Clang builtins (not available in GCC).
>>>  BUILTIN(__builtin_addressof, "v*v&", "nct")
>>> -BUILTIN(__builtin_operator_new, "v*z", "c")
>>> -BUILTIN(__builtin_operator_delete, "vv*", "n")
>>> +BUILTIN(__builtin_operator_new, "v*z", "tc")
>>> +BUILTIN(__builtin_operator_delete, "vv*", "tn")
>>>  BUILTIN(__builtin_char_memchr, "c*cC*iz", "n")
>>>
>>>  // Safestack builtins
>>>
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>>> Basic/DiagnosticSemaKinds.td?rev=328134=328133=328134=diff
>>> 
>>> ==
>>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 21
>>> 12:19:48 2018
>>> @@ -7627,6 +7627,11 @@ def err_destroying_operator_delete_not_u
>>>"alignment parameter">;
>>>  def note_implicit_delete_this_in_destructor_here : Note<
>>>"while checking implicit 'delete this' for virtual destructor">;
>>> +def err_builtin_operator_new_delete_not_usual : Error<
>>> +  "call to '%select{__builtin_operator_new|__builtin_operator_delete}0'
>>> "
>>> +  "selects non-usual %select{allocation|deallocation}0 function">;
>>> +def note_non_usual_function_declared_here : Note<
>>> +  "non-usual %0 declared here">;
>>>
>>>  // C++ literal operators
>>>  def 

[PATCH] D44804: [StaticAnalyzer] Silence an unused variable warning. NFC.

2018-03-22 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

Actually, a better change would be to simply change `cast(MR)` to 
`VR`


Repository:
  rC Clang

https://reviews.llvm.org/D44804



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


[PATCH] D44804: [StaticAnalyzer] Silence an unused variable warning. NFC.

2018-03-22 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang created this revision.
mgrang added reviewers: george.karpenkov, dcoughlin, dergachev.a.
Herald added subscribers: a.sidorin, szepet.

Repository:
  rC Clang

https://reviews.llvm.org/D44804

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1930,7 +1930,7 @@
 }
 
 static Optional describeRegion(const MemRegion *MR) {
-  if (const auto *VR = dyn_cast_or_null(MR))
+  if (dyn_cast_or_null(MR))
 return std::string(cast(MR)->getDecl()->getName());
   // Once we support more storage locations for bindings,
   // this would need to be improved.


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1930,7 +1930,7 @@
 }
 
 static Optional describeRegion(const MemRegion *MR) {
-  if (const auto *VR = dyn_cast_or_null(MR))
+  if (dyn_cast_or_null(MR))
 return std::string(cast(MR)->getDecl()->getName());
   // Once we support more storage locations for bindings,
   // this would need to be improved.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44295: [clang-tidy] Detects and fixes calls to grand-...parent virtual methods instead of calls to parent's virtual methods

2018-03-22 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

Please add a test where the parent class is in a differently named namespace.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44295



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


[PATCH] D44295: [clang-tidy] Detects and fixes calls to grand-...parent virtual methods instead of calls to parent's virtual methods

2018-03-22 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/ReleaseNotes.rst:73
 
+- New `bugprone-parent-virtual-call
+  
`_
 check

Please rebase from trunk and use //:doc:// for link.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44295



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


[PATCH] D44295: [clang-tidy] Detects and fixes calls to grand-...parent virtual methods instead of calls to parent's virtual methods

2018-03-22 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis marked 9 inline comments as done.
zinovy.nis added inline comments.



Comment at: docs/clang-tidy/checks/bugprone-parent-virtual-call.rst:6
+
+Detects and fixes calls to grand-...parent virtual methods instead of calls
+to parent's virtual methods.

aaron.ballman wrote:
> This formulation is a bit odd because of the `grand-...parent` part. I would 
> reword to be more along the lines of: detects calls to qualified function 
> names that refer to a function that is not explicitly declared by a direct 
> base class.
>  that is not explicitly declared by a direct base class.

In fact, it detects calls to qualified function names

> that explicitly overridden in subclasses.




Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44295



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


[PATCH] D44295: [clang-tidy] Detects and fixes calls to grand-...parent virtual methods instead of calls to parent's virtual methods

2018-03-22 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 139499.
zinovy.nis marked an inline comment as done.
zinovy.nis added a comment.

camelCase last minute fix.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44295

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/ParentVirtualCallCheck.cpp
  clang-tidy/bugprone/ParentVirtualCallCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-parent-virtual-call.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-parent-virtual-call.cpp

Index: test/clang-tidy/bugprone-parent-virtual-call.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-parent-virtual-call.cpp
@@ -0,0 +1,150 @@
+// RUN: %check_clang_tidy %s bugprone-parent-virtual-call %t
+
+extern int foo();
+
+class A {
+public:
+  A() = default;
+  virtual ~A() = default;
+
+  virtual int virt_1() { return foo() + 1; }
+  virtual int virt_2() { return foo() + 2; }
+
+  int non_virt() { return foo() + 3; }
+  static int stat() { return foo() + 4; }
+};
+
+class B : public A {
+public:
+  B() = default;
+
+  // Nothing to fix: calls to direct parent.
+  int virt_1() override { return A::virt_1() + 3; }
+  int virt_2() override { return A::virt_2() + 4; }
+};
+
+class C : public B {
+public:
+  int virt_1() override { return A::virt_1() + B::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'B' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_1() override { return B::virt_1() + B::virt_1(); }
+  int virt_2() override { return A::virt_1() + B::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'B' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_2() override { return B::virt_1() + B::virt_1(); }
+
+  // Test that non-virtual and static methods are not affected by this cherker.
+  int method_c() { return A::stat() + A::non_virt(); }
+};
+
+// Check aliased type names
+using A1 = A;
+typedef A A2;
+
+class C2 : public B {
+public:
+  int virt_1() override { return A1::virt_1() + A2::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'B' [bugprone-parent-virtual-call]
+  // CHECK-MESSAGES: :[[@LINE-2]]:49: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'B' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_1() override { return B::virt_1() + B::virt_1(); }
+};
+
+// Test that the check affects grand-grand..-parent calls too.
+class D : public C {
+public:
+  int virt_1() override { return A::virt_1() + B::virt_1() + D::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'C' [bugprone-parent-virtual-call]
+  // CHECK-MESSAGES: :[[@LINE-2]]:48: warning: qualified name 'B::virt_1' refers to a member which was overridden in subclass 'C' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_1() override { return C::virt_1() + C::virt_1() + D::virt_1(); }
+  int virt_2() override { return A::virt_1() + B::virt_1() + D::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'C' [bugprone-parent-virtual-call]
+  // CHECK-MESSAGES: :[[@LINE-2]]:48: warning: qualified name 'B::virt_1' refers to a member which was overridden in subclass 'C' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_2() override { return C::virt_1() + C::virt_1() + D::virt_1(); }
+};
+
+// Test classes in anonymous namespaces.
+namespace {
+class BN : public A {
+public:
+  int virt_1() override { return A::virt_1() + 3; }
+  int virt_2() override { return A::virt_2() + 4; }
+};
+} // namespace N
+
+class CN : public BN {
+public:
+  int virt_1() override { return A::virt_1() + BN::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'BN' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_1() override { return BN::virt_1() + BN::virt_1(); }
+  int virt_2() override { return A::virt_1() + BN::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'BN' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_2() override { return BN::virt_1() + BN::virt_1(); }
+};
+
+// Test multiple inheritance fixes
+class AA {
+public:
+  AA() = default;
+  virtual ~AA() = default;
+
+  virtual int virt_1() { return foo() + 1; }
+  virtual int virt_2() { return foo() + 2; }
+
+  int non_virt() { return foo() + 3; }
+  static int stat() { return foo() + 4; }
+};
+
+class BB_1 : virtual public AA {
+public:
+  BB_1() = 

[PATCH] D44272: [clangd] Support incremental document syncing

2018-03-22 Thread Simon Marchi via Phabricator via cfe-commits
simark added inline comments.



Comment at: clangd/DraftStore.h:36
   /// Replace contents of the draft for \p File with \p Contents.
-  void updateDraft(PathRef File, StringRef Contents);
+  void addDraft(PathRef File, StringRef Contents);
+

ilya-biryukov wrote:
> ilya-biryukov wrote:
> > simark wrote:
> > > ilya-biryukov wrote:
> > > > Could we add versions from LSP's `VersionedTextDocumentIdentifier` here 
> > > > and make the relevant sanity checks?
> > > > Applying diffs to the wrong version will cause everything to fall 
> > > > apart, so we should detect this error and signal it to the client as 
> > > > soon as possible.
> > > I agree that applying diffs to the wrong version will break basically 
> > > everything, but even if we detect a version mismatch, I don't see what we 
> > > could do, since we don't have a mean to report the error to the client.  
> > > The only thing we could do is log it (which we already do.
> > If we couldn't apply a diff, we should return errors from all future 
> > operations on this file until it gets closed and reopened. Otherwise clangd 
> > and the editor would see inconsistent contents for the file and results 
> > provided by clangd would be unreliable.
> > The errors from any actions on the invalid file would actually be visible 
> > to the users.
> > 
> > The simplest way to achieve that is to remove the file from `DraftStore` 
> > and `ClangdServer` on errors from `updateDraft`.
> > This will give "calling action on non-tracked file" errors for future 
> > operations and the actual root cause can be figured out from the logs.
> We still ignore version numbers from the LSP.
> Is this another change that didn't get in?
The more I think about it, the less sure I am that this is the intended usage 
of the version.  The spec doesn't even say what the initial version of a file 
should be, 0 or 1?  Then, it just says that the version optionally contained in 
the `VersionedTextDocumentIdentifier` reflects the version of the document 
after having applied the edit.  But I don't think we can predict and validate 
what that version should be.  Most clients will probably just use a sequence 
number, but I guess they don't have to...

Also, I initially assumed that having N changes in the `contentChanges` array 
would mean that the version number would be bumped by N.  But now that I 
re-read it, there's really nothing that says it should behave like this.

I think that we should just record the version number and treat it as opaque, 
so that we can use it later when sending text edits to the client, for example. 
 The client can then verify that the edit is for the same version of the 
document that it has at the moment.

Therefore, I don't think it would really be useful in this patch.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44272



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


[PATCH] D44295: [clang-tidy] Detects and fixes calls to grand-...parent virtual methods instead of calls to parent's virtual methods

2018-03-22 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 139496.
zinovy.nis added a comment.

Aaron, I applied the changes you suggest.

I also found and fixed a new case when grandparent method is called via 
'typedef'ed or 'using' type. There's also a new test (class C2) for it.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44295

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/ParentVirtualCallCheck.cpp
  clang-tidy/bugprone/ParentVirtualCallCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-parent-virtual-call.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-parent-virtual-call.cpp

Index: test/clang-tidy/bugprone-parent-virtual-call.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-parent-virtual-call.cpp
@@ -0,0 +1,150 @@
+// RUN: %check_clang_tidy %s bugprone-parent-virtual-call %t
+
+extern int foo();
+
+class A {
+public:
+  A() = default;
+  virtual ~A() = default;
+
+  virtual int virt_1() { return foo() + 1; }
+  virtual int virt_2() { return foo() + 2; }
+
+  int non_virt() { return foo() + 3; }
+  static int stat() { return foo() + 4; }
+};
+
+class B : public A {
+public:
+  B() = default;
+
+  // Nothing to fix: calls to direct parent.
+  int virt_1() override { return A::virt_1() + 3; }
+  int virt_2() override { return A::virt_2() + 4; }
+};
+
+class C : public B {
+public:
+  int virt_1() override { return A::virt_1() + B::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'B' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_1() override { return B::virt_1() + B::virt_1(); }
+  int virt_2() override { return A::virt_1() + B::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'B' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_2() override { return B::virt_1() + B::virt_1(); }
+
+  // Test that non-virtual and static methods are not affected by this cherker.
+  int method_c() { return A::stat() + A::non_virt(); }
+};
+
+// Check aliased type names
+using A1 = A;
+typedef A A2;
+
+class C2 : public B {
+public:
+  int virt_1() override { return A1::virt_1() + A2::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'B' [bugprone-parent-virtual-call]
+  // CHECK-MESSAGES: :[[@LINE-2]]:49: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'B' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_1() override { return B::virt_1() + B::virt_1(); }
+};
+
+// Test that the check affects grand-grand..-parent calls too.
+class D : public C {
+public:
+  int virt_1() override { return A::virt_1() + B::virt_1() + D::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'C' [bugprone-parent-virtual-call]
+  // CHECK-MESSAGES: :[[@LINE-2]]:48: warning: qualified name 'B::virt_1' refers to a member which was overridden in subclass 'C' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_1() override { return C::virt_1() + C::virt_1() + D::virt_1(); }
+  int virt_2() override { return A::virt_1() + B::virt_1() + D::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'C' [bugprone-parent-virtual-call]
+  // CHECK-MESSAGES: :[[@LINE-2]]:48: warning: qualified name 'B::virt_1' refers to a member which was overridden in subclass 'C' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_2() override { return C::virt_1() + C::virt_1() + D::virt_1(); }
+};
+
+// Test classes in anonymous namespaces.
+namespace {
+class BN : public A {
+public:
+  int virt_1() override { return A::virt_1() + 3; }
+  int virt_2() override { return A::virt_2() + 4; }
+};
+} // namespace N
+
+class CN : public BN {
+public:
+  int virt_1() override { return A::virt_1() + BN::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'BN' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_1() override { return BN::virt_1() + BN::virt_1(); }
+  int virt_2() override { return A::virt_1() + BN::virt_1(); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: qualified name 'A::virt_1' refers to a member which was overridden in subclass 'BN' [bugprone-parent-virtual-call]
+  // CHECK-FIXES:  int virt_2() override { return BN::virt_1() + BN::virt_1(); }
+};
+
+// Test multiple inheritance fixes
+class AA {
+public:
+  AA() = default;
+  virtual ~AA() = default;
+
+  virtual int virt_1() { return foo() + 1; }
+  virtual int virt_2() { return foo() + 2; }
+
+  int non_virt() { return foo() + 

[PATCH] D44801: Add the -fsanitize=shadow-call-stack flag

2018-03-22 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich created this revision.
vlad.tsyrklevich added a reviewer: pcc.
Herald added a subscriber: cfe-commits.

Add support for the -fsanitize=shadow-call-stack flag which causes clang
to add ShadowCallStack attribute to functions compiled with that flag
enabled.


Repository:
  rC Clang

https://reviews.llvm.org/D44801

Files:
  docs/ShadowCallStack.rst
  docs/index.rst
  include/clang/Basic/Sanitizers.def
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChain.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/CodeGen/shadowcallstack-attr.c

Index: test/CodeGen/shadowcallstack-attr.c
===
--- /dev/null
+++ test/CodeGen/shadowcallstack-attr.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-linux-unknown -emit-llvm -o - %s -fsanitize=shadow-call-stack | FileCheck %s
+
+__attribute__((no_sanitize("shadow-call-stack")))
+int foo(int *a) { return *a; }
+
+ int bar(int *a) { return *a; }
+
+// CHECK: define i32 @foo(i32* %a) #[[FOO_ATTR:[0-9]+]] {
+// CHECK: define i32 @bar(i32* %a) #[[BAR_ATTR:[0-9]+]] {
+
+// CHECK-NOT: attributes #[[FOO_ATTR]] = { {{.*}}shadowcallstack{{.*}} }
+// CHECK: attributes #[[BAR_ATTR]] = { {{.*}}shadowcallstack{{.*}} }
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -1275,6 +1275,8 @@
   .Case("is_union", LangOpts.CPlusPlus)
   .Case("modules", LangOpts.Modules)
   .Case("safe_stack", LangOpts.Sanitize.has(SanitizerKind::SafeStack))
+  .Case("shadow_call_stack",
+LangOpts.Sanitize.has(SanitizerKind::ShadowCallStack))
   .Case("tls", PP.getTargetInfo().isTLSSupported())
   .Case("underlying_type", LangOpts.CPlusPlus)
   .Default(false);
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -814,6 +814,8 @@
   getTriple().getArch() == llvm::Triple::wasm32 ||
   getTriple().getArch() == llvm::Triple::wasm64)
 Res |= CFIICall;
+  if (getTriple().getArch() == llvm::Triple::x86_64)
+Res |= ShadowCallStack;
   return Res;
 }
 
Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -343,7 +343,10 @@
   std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
 KernelAddress | Efficiency),
   std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency)};
+KernelAddress | Efficiency),
+  std::make_pair(ShadowCallStack, Address | HWAddress | Leak | Thread |
+  Memory | KernelAddress | Efficiency |
+  SafeStack)};
 
   // Enable toolchain specific default sanitizers if not explicitly disabled.
   SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -861,6 +861,8 @@
 Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
   if (SanOpts.has(SanitizerKind::SafeStack))
 Fn->addFnAttr(llvm::Attribute::SafeStack);
+  if (SanOpts.has(SanitizerKind::ShadowCallStack))
+Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
   // Ignore TSan memory acesses from within ObjC/ObjC++ dealloc, initialize,
   // .cxx_destruct, __destroy_helper_block_ and all of their calees at run time.
Index: lib/CodeGen/CGDeclCXX.cpp
===
--- lib/CodeGen/CGDeclCXX.cpp
+++ lib/CodeGen/CGDeclCXX.cpp
@@ -343,6 +343,10 @@
   !isInSanitizerBlacklist(SanitizerKind::SafeStack, Fn, Loc))
 Fn->addFnAttr(llvm::Attribute::SafeStack);
 
+  if (getLangOpts().Sanitize.has(SanitizerKind::ShadowCallStack) &&
+  !isInSanitizerBlacklist(SanitizerKind::ShadowCallStack, Fn, Loc))
+Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
+
   return Fn;
 }
 
Index: include/clang/Basic/Sanitizers.def
===
--- include/clang/Basic/Sanitizers.def
+++ include/clang/Basic/Sanitizers.def
@@ -110,6 +110,9 @@
 // Safe Stack
 SANITIZER("safe-stack", SafeStack)
 
+// Shadow Call Stack
+SANITIZER("shadow-call-stack", ShadowCallStack)
+
 // -fsanitize=undefined includes all the sanitizers which have low overhead, no
 // ABI or address space layout implications, and only catch undefined behavior.
 SANITIZER_GROUP("undefined", Undefined,
Index: docs/index.rst
===
--- docs/index.rst
+++ docs/index.rst
@@ 

[PATCH] D44796: Set dso_local on vtables

2018-03-22 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


https://reviews.llvm.org/D44796



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


Re: r328040 - Set dso_local on string literals.

2018-03-22 Thread Joerg Sonnenberger via cfe-commits
On Tue, Mar 20, 2018 at 05:01:24PM -0700, Rafael Avila de Espindola wrote:
> Joerg Sonnenberger via cfe-commits  writes:
> 
> > On Tue, Mar 20, 2018 at 08:42:55PM -, Rafael Espindola via cfe-commits 
> > wrote:
> >> Author: rafael
> >> Date: Tue Mar 20 13:42:55 2018
> >> New Revision: 328040
> >> 
> >> URL: http://llvm.org/viewvc/llvm-project?rev=328040=rev
> >> Log:
> >> Set dso_local on string literals.
> >
> > I wonder if unnamed_addr shouldn't imply that in general?
> 
> I don't think so. For example, a language where functions cannot be
> compared for equality could mark all functions unnamed_addr. It could
> still support interposition, which requires that they are not dso_local.

I don't think that argument makes sense. The address is not named, that
strongly implies that can't be interpositioned either.

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


[PATCH] D44764: [clangd] Move GTest printers to separate file

2018-03-22 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

In https://reviews.llvm.org/D44764#1045682, @ilya-biryukov wrote:

> In https://reviews.llvm.org/D44764#1045648, @simark wrote:
>
> > We could create a file `ClangdTesting.h" which includes everything tested 
> > related (gtest, gmock, printers, syncapi, etc). The convention would be 
> > that test files would just include that.
>
>
> Yeah, sounds good. I would exclude syncapi from the list, though. Not all 
> tests should necessarily depend on `ClangdServer`.
>  @sammccall , @ioeric , @hokein, @bkramer are you on board with the idea to 
> have an umbrella header for gtest+gmock+printers?


Sounds good to me too. I can update the patch once there is an agreement.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44764



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


[libcxx] r328229 - Un-XFAIL a test under new GCC version; the GCC bug has been fixed

2018-03-22 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Mar 22 12:18:08 2018
New Revision: 328229

URL: http://llvm.org/viewvc/llvm-project?rev=328229=rev
Log:
Un-XFAIL a test under new GCC version; the GCC bug has been fixed

Modified:

libcxx/trunk/test/std/utilities/function.objects/comparisons/constexpr_init.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/function.objects/comparisons/constexpr_init.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/comparisons/constexpr_init.pass.cpp?rev=328229=328228=328229=diff
==
--- 
libcxx/trunk/test/std/utilities/function.objects/comparisons/constexpr_init.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/function.objects/comparisons/constexpr_init.pass.cpp
 Thu Mar 22 12:18:08 2018
@@ -9,7 +9,7 @@
 
 // UNSUPPORTED: c++98, c++03, c++11
 
-// XFAIL: gcc-7, gcc-8
+// XFAIL: gcc-7
 
 // 
 


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


[PATCH] D44798: [libFuzzer] Use OptForFuzzing attribute with -fsanitize=fuzzer.

2018-03-22 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

16-bit variables are switched to 32-bit variables in SwapCmpTest.cpp and 
SimpleCmpTest.cpp.  This is because those tests rely on libFuzzer's TraceCMP 
heuristic to pass, but 16-bit compares are not considered for the heuristic.

The only reason the test used to pass was because under `-O0` 16-bit compares 
are promoted to 32-bit compares.


https://reviews.llvm.org/D44798



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


[PATCH] D44798: [libFuzzer] Use OptForFuzzing attribute with -fsanitize=fuzzer.

2018-03-22 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse created this revision.
morehouse added reviewers: kcc, vitalybuka.

Disables certain CMP optimizations to improve fuzzing signal under -O1
and -O2.

Switches all fuzzer tests to -O2 except for a few leak tests where the
leak is optimized out under -O2.


https://reviews.llvm.org/D44798

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  compiler-rt/test/fuzzer/SimpleCmpTest.cpp
  compiler-rt/test/fuzzer/SwapCmpTest.cpp
  compiler-rt/test/fuzzer/fuzzer-leak.test
  compiler-rt/test/fuzzer/lit.cfg
  compiler-rt/test/fuzzer/trace-malloc-threaded.test

Index: compiler-rt/test/fuzzer/trace-malloc-threaded.test
===
--- compiler-rt/test/fuzzer/trace-malloc-threaded.test
+++ compiler-rt/test/fuzzer/trace-malloc-threaded.test
@@ -2,7 +2,9 @@
 // printing a stack trace repeatedly
 UNSUPPORTED: darwin
 
-RUN: %cpp_compiler %S/TraceMallocThreadedTest.cpp -o %t-TraceMallocThreadedTest
+// Avoid optimizing since it causes the malloc to go away.
+RUN: %no_opt_cpp_compiler %S/TraceMallocThreadedTest.cpp -o \
+RUN:   %t-TraceMallocThreadedTest
 
 RUN: %t-TraceMallocThreadedTest -trace_malloc=2 -runs=1 2>&1 | FileCheck %s
 CHECK: {{MALLOC\[[0-9]+] +0x[0-9]+ 5639}}
Index: compiler-rt/test/fuzzer/lit.cfg
===
--- compiler-rt/test/fuzzer/lit.cfg
+++ compiler-rt/test/fuzzer/lit.cfg
@@ -49,23 +49,25 @@
 libfuzzer_src_root = os.path.join(config.compiler_rt_src_root, "lib", "fuzzer")
 config.substitutions.append(('%libfuzzer_src', libfuzzer_src_root))
 
-def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True):
+def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, optimize=True):
   compiler_cmd = config.c_compiler
   if config.clang and config.stdlib == 'libc++':
 link_cmd = '-stdlib=libc++ -Wl,-rpath=%s' % config.llvm_library_dir
   elif config.clang and config.stdlib == 'static-libc++':
 link_cmd = '-stdlib=libc++ -lc++abi -static-libstdc++ -Wl,-rpath=%s' % config.llvm_library_dir
   else:
 link_cmd = '-lc++' if any(x in config.target_triple for x in ('darwin', 'freebsd')) else '-lstdc++'
   std_cmd = '--driver-mode=g++ -std=c++11' if is_cpp else ''
+  opt_cmd = '-O2' if optimize else '-O0'
   sanitizers = ['address']
   if fuzzer_enabled:
 sanitizers.append('fuzzer')
   sanitizers_cmd = ('-fsanitize=%s' % ','.join(sanitizers))
   isysroot_cmd = config.osx_sysroot_flag if config.osx_sysroot_flag else ''
   include_cmd = '-I%s' % libfuzzer_src_root
-  return '%s %s %s -gline-tables-only %s %s %s' % (
-  compiler_cmd, std_cmd, link_cmd, isysroot_cmd, sanitizers_cmd, include_cmd)
+  return '%s %s %s %s -gline-tables-only %s %s %s' % (
+  compiler_cmd, std_cmd, opt_cmd, link_cmd, isysroot_cmd, sanitizers_cmd,
+  include_cmd)
 
 config.substitutions.append(('%cpp_compiler',
   generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True)
@@ -82,3 +84,11 @@
 config.substitutions.append(('%no_fuzzer_c_compiler',
   generate_compiler_cmd(is_cpp=False, fuzzer_enabled=False)
   ))
+
+config.substitutions.append(('%no_opt_cpp_compiler',
+  generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, optimize=False)
+  ))
+
+config.substitutions.append(('%no_opt_c_compiler',
+  generate_compiler_cmd(is_cpp=False, fuzzer_enabled=True, optimize=False)
+  ))
Index: compiler-rt/test/fuzzer/fuzzer-leak.test
===
--- compiler-rt/test/fuzzer/fuzzer-leak.test
+++ compiler-rt/test/fuzzer/fuzzer-leak.test
@@ -1,6 +1,9 @@
 REQUIRES: lsan
-RUN: %cpp_compiler %S/LeakTest.cpp -o %t-LeakTest
-RUN: %cpp_compiler %S/ThreadedLeakTest.cpp -o %t-ThreadedLeakTest
+
+// Avoid optimizing since it causes these leaks to go away.
+RUN: %no_opt_cpp_compiler %S/LeakTest.cpp -o %t-LeakTest
+RUN: %no_opt_cpp_compiler %S/ThreadedLeakTest.cpp -o %t-ThreadedLeakTest
+
 RUN: %cpp_compiler %S/LeakTimeoutTest.cpp -o %t-LeakTimeoutTest
 
 RUN: rm -rf %t-corpus && mkdir -p %t-corpus
Index: compiler-rt/test/fuzzer/SwapCmpTest.cpp
===
--- compiler-rt/test/fuzzer/SwapCmpTest.cpp
+++ compiler-rt/test/fuzzer/SwapCmpTest.cpp
@@ -11,22 +11,22 @@
   if (Size < 14) return 0;
   uint64_t x = 0;
   uint32_t y = 0;
-  uint16_t z = 0;
+  uint32_t z = 0;
   memcpy(, Data, sizeof(x));
   memcpy(, Data + Size / 2, sizeof(y));
   memcpy(, Data + Size - sizeof(z), sizeof(z));
 
   x = __builtin_bswap64(x);
   y = __builtin_bswap32(y);
-  z = __builtin_bswap16(z);
+  z = __builtin_bswap32(z);
   const bool k32bit = sizeof(void*) == 4;
 
   if ((k32bit || x == 0x46555A5A5A5A5546ULL) &&
   z == 0x4F4B &&
   y == 0x66757A7A &&
   true
   ) {
-if (Data[Size - 3] == 'z') {
+if (Data[Size - 5] == 'z') {
   fprintf(stderr, "BINGO; Found the target\n");
   exit(1);
 }
Index: compiler-rt/test/fuzzer/SimpleCmpTest.cpp

[PATCH] D44796: Set dso_local on vtables

2018-03-22 Thread Rafael Avila de Espindola via Phabricator via cfe-commits
espindola created this revision.
espindola added reviewers: rnk, echristo.

https://reviews.llvm.org/D44796

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/dllexport.cpp


Index: test/CodeGenCXX/dllexport.cpp
===
--- test/CodeGenCXX/dllexport.cpp
+++ test/CodeGenCXX/dllexport.cpp
@@ -41,6 +41,8 @@
 // GNU-NOT: @ExternGlobalDecl
 __declspec(dllexport) extern int ExternGlobalDecl;
 
+// GNU-DAG: @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global
+
 // dllexport implies a definition.
 // MSC-DAG: @"?GlobalDef@@3HA" = dso_local dllexport global i32 0, align 4
 // GNU-DAG: @GlobalDef= dso_local dllexport global i32 0, align 4
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -2848,6 +2848,7 @@
 
   const char *VTableName = nullptr;
 
+  const CXXRecordDecl *RD = nullptr;
   switch (Ty->getTypeClass()) {
 #define TYPE(Class, Base)
 #define ABSTRACT_TYPE(Class, Base)
@@ -2899,8 +2900,7 @@
 break;
 
   case Type::Record: {
-const CXXRecordDecl *RD =
-  cast(cast(Ty)->getDecl());
+RD = cast(cast(Ty)->getDecl());
 
 if (!RD->hasDefinition() || !RD->getNumBases()) {
   VTableName = ClassTypeInfo;
@@ -2948,6 +2948,7 @@
 
   llvm::Constant *VTable =
 CGM.getModule().getOrInsertGlobal(VTableName, CGM.Int8PtrTy);
+  CGM.setGVProperties(cast(VTable->stripPointerCasts()), 
RD);
 
   llvm::Type *PtrDiffTy =
 CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType());


Index: test/CodeGenCXX/dllexport.cpp
===
--- test/CodeGenCXX/dllexport.cpp
+++ test/CodeGenCXX/dllexport.cpp
@@ -41,6 +41,8 @@
 // GNU-NOT: @ExternGlobalDecl
 __declspec(dllexport) extern int ExternGlobalDecl;
 
+// GNU-DAG: @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global
+
 // dllexport implies a definition.
 // MSC-DAG: @"?GlobalDef@@3HA" = dso_local dllexport global i32 0, align 4
 // GNU-DAG: @GlobalDef= dso_local dllexport global i32 0, align 4
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -2848,6 +2848,7 @@
 
   const char *VTableName = nullptr;
 
+  const CXXRecordDecl *RD = nullptr;
   switch (Ty->getTypeClass()) {
 #define TYPE(Class, Base)
 #define ABSTRACT_TYPE(Class, Base)
@@ -2899,8 +2900,7 @@
 break;
 
   case Type::Record: {
-const CXXRecordDecl *RD =
-  cast(cast(Ty)->getDecl());
+RD = cast(cast(Ty)->getDecl());
 
 if (!RD->hasDefinition() || !RD->getNumBases()) {
   VTableName = ClassTypeInfo;
@@ -2948,6 +2948,7 @@
 
   llvm::Constant *VTable =
 CGM.getModule().getOrInsertGlobal(VTableName, CGM.Int8PtrTy);
+  CGM.setGVProperties(cast(VTable->stripPointerCasts()), RD);
 
   llvm::Type *PtrDiffTy =
 CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44539: [Sema][Objective-C] Add check to warn when property of objc type has assign attribute

2018-03-22 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

We added the `unsafe_unretained` property attribute as part of ARC because we 
were introducing `__unsafe_retained` as a type qualifier and we wanted all the 
type qualifiers to have corresponding attribute spellings.  `assign` is the 
much-older attribute, and its non-owning behavior was widely understood.  In 
fact, we briefly considered naming the qualifier `__assign`, but we quickly 
decided that that we wanted a more explicit name for the ARC age.

I like the idea of this warning, but I need to float it to our internal 
Objective-C language group before we can accept it.


Repository:
  rC Clang

https://reviews.llvm.org/D44539



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


[libcxx] r328225 - Fix improperly failing test - and the code it was testing. Thanks to Stephan Lavavej for the catch.

2018-03-22 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Mar 22 11:27:28 2018
New Revision: 328225

URL: http://llvm.org/viewvc/llvm-project?rev=328225=rev
Log:
Fix improperly failing test - and the code it was testing. Thanks to Stephan 
Lavavej for the catch.

Modified:
libcxx/trunk/include/ostream

libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp

Modified: libcxx/trunk/include/ostream
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ostream?rev=328225=328224=328225=diff
==
--- libcxx/trunk/include/ostream (original)
+++ libcxx/trunk/include/ostream Thu Mar 22 11:27:28 2018
@@ -1071,19 +1071,17 @@ operator<<(basic_ostream<_CharT, _Traits
 return __os << __p.get();
 }
 
-#ifndef _LIBCPP_HAS_NO_DECLTYPE
 template
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
-is_same&>() << declval<_Yp>())>::type>::value,
+is_same&>() << declval::pointer>()))>::type>::value,
 basic_ostream<_CharT, _Traits>&
 >::type
 operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& 
__p)
 {
 return __os << __p.get();
 }
-#endif
 
 template 
 basic_ostream<_CharT, _Traits>&

Modified: 
libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp?rev=328225=328224=328225=diff
==
--- 
libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp
 Thu Mar 22 11:27:28 2018
@@ -24,11 +24,12 @@
 #include 
 #include 
 
-class A {};
+#include "min_allocator.h"
+#include "deleter_types.h"
 
 int main()
 {
-std::unique_ptr p(new A);
+std::unique_ptr p;
 std::ostringstream os;
-os << p;
+os << p; // expected-error {{invalid operands to binary expression}}
 }


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


[PATCH] D44710: Set dso_local on builtin functions

2018-03-22 Thread Rafael Avila de Espindola via Phabricator via cfe-commits
espindola closed this revision.
espindola added a comment.

328224


https://reviews.llvm.org/D44710



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


r328224 - Set dso_local on builtin functions.

2018-03-22 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Thu Mar 22 11:03:13 2018
New Revision: 328224

URL: http://llvm.org/viewvc/llvm-project?rev=328224=rev
Log:
Set dso_local on builtin functions.

The difference between CreateRuntimeFunction and CreateBuiltinFunction
is that CreateBuiltinFunction would not set dllimport or dso_local.

To keep the current semantics, just forward to CreateRuntimeFunction
with Local=true so it doesn't add dllimport.

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/mingw-long-double.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=328224=328223=328224=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Mar 22 11:03:13 2018
@@ -2640,13 +2640,7 @@ CodeGenModule::CreateRuntimeFunction(llv
 llvm::Constant *
 CodeGenModule::CreateBuiltinFunction(llvm::FunctionType *FTy, StringRef Name,
  llvm::AttributeList ExtraAttrs) {
-  llvm::Constant *C =
-  GetOrCreateLLVMFunction(Name, FTy, GlobalDecl(), /*ForVTable=*/false,
-  /*DontDefer=*/false, /*IsThunk=*/false, 
ExtraAttrs);
-  if (auto *F = dyn_cast(C))
-if (F->empty())
-  F->setCallingConv(getRuntimeCC());
-  return C;
+  return CreateRuntimeFunction(FTy, Name, ExtraAttrs, true);
 }
 
 /// isTypeConstant - Determine whether an object of this type can be emitted

Modified: cfe/trunk/test/CodeGen/mingw-long-double.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mingw-long-double.c?rev=328224=328223=328224=diff
==
--- cfe/trunk/test/CodeGen/mingw-long-double.c (original)
+++ cfe/trunk/test/CodeGen/mingw-long-double.c Thu Mar 22 11:03:13 2018
@@ -42,6 +42,6 @@ long double _Complex TestLDC(long double
 // GNU64: define dso_local void @TestLDC({ x86_fp80, x86_fp80 }* noalias sret 
%agg.result, { x86_fp80, x86_fp80 }* %x)
 // MSC64: define dso_local void @TestLDC({ double, double }* noalias sret 
%agg.result, { double, double }* %x)
 
-// GNU32: declare void @__mulxc3
-// GNU64: declare void @__mulxc3
-// MSC64: declare void @__muldc3
+// GNU32: declare dso_local void @__mulxc3
+// GNU64: declare dso_local void @__mulxc3
+// MSC64: declare dso_local void @__muldc3


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


Re: r328134 - [Builtins] Overload __builtin_operator_new/delete to allow forwarding to usual allocation/deallocation functions.

2018-03-22 Thread Eric Fiselier via cfe-commits
Sorry, I didn't see the failure yesterday.

I'll get on it or revert it.

On Thu, Mar 22, 2018 at 11:51 AM, Galina Kistanova 
wrote:

> Hello Eric,
>
> One of added tests fails on the next builder:
> http://lab.llvm.org:8011/builders/llvm-clang-x86_64-
> expensive-checks-win/builds/8624
>
> . . .
> Failing Tests:
>. . .
> Clang :: SemaCXX/builtin-operator-new-delete.cpp
>
> Please have a look?
>
> It is not good idea to keep the bot red for too long. This hides new
> problem which later hard to track down.
>
> Thanks
>
> Galina
>
>
> On Wed, Mar 21, 2018 at 12:19 PM, Eric Fiselier via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: ericwf
>> Date: Wed Mar 21 12:19:48 2018
>> New Revision: 328134
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=328134=rev
>> Log:
>> [Builtins] Overload __builtin_operator_new/delete to allow forwarding to
>> usual allocation/deallocation functions.
>>
>> Summary:
>> Libc++'s default allocator uses `__builtin_operator_new` and
>> `__builtin_operator_delete` in order to allow the calls to new/delete to be
>> ellided. However, libc++ now needs to support over-aligned types in the
>> default allocator. In order to support this without disabling the existing
>> optimization Clang needs to support calling the aligned new overloads from
>> the builtins.
>>
>> See llvm.org/PR22634 for more information about the libc++ bug.
>>
>> This patch changes `__builtin_operator_new`/`__builtin_operator_delete`
>> to call any usual `operator new`/`operator delete` function. It does this
>> by performing overload resolution with the arguments passed to the builtin
>> to determine which allocation function to call. If the selected function is
>> not a usual allocation function a diagnostic is issued.
>>
>> One open issue is if the `align_val_t` overloads should be considered
>> "usual" when `LangOpts::AlignedAllocation` is disabled.
>>
>>
>> In order to allow libc++ to detect this new behavior the value for
>> `__has_builtin(__builtin_operator_new)` has been updated to `201802`.
>>
>> Reviewers: rsmith, majnemer, aaron.ballman, erik.pilkington, bogner,
>> ahatanak
>>
>> Reviewed By: rsmith
>>
>> Subscribers: cfe-commits
>>
>> Differential Revision: https://reviews.llvm.org/D43047
>>
>> Added:
>> cfe/trunk/test/CodeGenCXX/builtin-operator-new-delete.cpp
>> cfe/trunk/test/SemaCXX/builtin-operator-new-delete.cpp
>> Modified:
>> cfe/trunk/include/clang/Basic/Builtins.def
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/include/clang/Sema/Sema.h
>> cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>> cfe/trunk/lib/CodeGen/CGExprCXX.cpp
>> cfe/trunk/lib/CodeGen/CodeGenFunction.h
>> cfe/trunk/lib/Lex/PPMacroExpansion.cpp
>> cfe/trunk/lib/Sema/SemaChecking.cpp
>> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/Builtins.def
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/Builtins.def?rev=328134=328133=328134=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
>> +++ cfe/trunk/include/clang/Basic/Builtins.def Wed Mar 21 12:19:48 2018
>> @@ -1371,8 +1371,8 @@ BUILTIN(__builtin_smulll_overflow, "bSLL
>>
>>  // Clang builtins (not available in GCC).
>>  BUILTIN(__builtin_addressof, "v*v&", "nct")
>> -BUILTIN(__builtin_operator_new, "v*z", "c")
>> -BUILTIN(__builtin_operator_delete, "vv*", "n")
>> +BUILTIN(__builtin_operator_new, "v*z", "tc")
>> +BUILTIN(__builtin_operator_delete, "vv*", "tn")
>>  BUILTIN(__builtin_char_memchr, "c*cC*iz", "n")
>>
>>  // Safestack builtins
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/DiagnosticSemaKinds.td?rev=328134=328133=328134=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 21
>> 12:19:48 2018
>> @@ -7627,6 +7627,11 @@ def err_destroying_operator_delete_not_u
>>"alignment parameter">;
>>  def note_implicit_delete_this_in_destructor_here : Note<
>>"while checking implicit 'delete this' for virtual destructor">;
>> +def err_builtin_operator_new_delete_not_usual : Error<
>> +  "call to '%select{__builtin_operator_new|__builtin_operator_delete}0'
>> "
>> +  "selects non-usual %select{allocation|deallocation}0 function">;
>> +def note_non_usual_function_declared_here : Note<
>> +  "non-usual %0 declared here">;
>>
>>  // C++ literal operators
>>  def err_literal_operator_outside_namespace : Error<
>>
>> Modified: cfe/trunk/include/clang/Sema/Sema.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Sema/Sema.h?rev=328134=328133=328134=diff
>> 
>> 

Re: r328134 - [Builtins] Overload __builtin_operator_new/delete to allow forwarding to usual allocation/deallocation functions.

2018-03-22 Thread Galina Kistanova via cfe-commits
Hello Eric,

One of added tests fails on the next builder:
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/8624

. . .
Failing Tests:
   . . .
Clang :: SemaCXX/builtin-operator-new-delete.cpp

Please have a look?

It is not good idea to keep the bot red for too long. This hides new
problem which later hard to track down.

Thanks

Galina


On Wed, Mar 21, 2018 at 12:19 PM, Eric Fiselier via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ericwf
> Date: Wed Mar 21 12:19:48 2018
> New Revision: 328134
>
> URL: http://llvm.org/viewvc/llvm-project?rev=328134=rev
> Log:
> [Builtins] Overload __builtin_operator_new/delete to allow forwarding to
> usual allocation/deallocation functions.
>
> Summary:
> Libc++'s default allocator uses `__builtin_operator_new` and
> `__builtin_operator_delete` in order to allow the calls to new/delete to be
> ellided. However, libc++ now needs to support over-aligned types in the
> default allocator. In order to support this without disabling the existing
> optimization Clang needs to support calling the aligned new overloads from
> the builtins.
>
> See llvm.org/PR22634 for more information about the libc++ bug.
>
> This patch changes `__builtin_operator_new`/`__builtin_operator_delete`
> to call any usual `operator new`/`operator delete` function. It does this
> by performing overload resolution with the arguments passed to the builtin
> to determine which allocation function to call. If the selected function is
> not a usual allocation function a diagnostic is issued.
>
> One open issue is if the `align_val_t` overloads should be considered
> "usual" when `LangOpts::AlignedAllocation` is disabled.
>
>
> In order to allow libc++ to detect this new behavior the value for
> `__has_builtin(__builtin_operator_new)` has been updated to `201802`.
>
> Reviewers: rsmith, majnemer, aaron.ballman, erik.pilkington, bogner,
> ahatanak
>
> Reviewed By: rsmith
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D43047
>
> Added:
> cfe/trunk/test/CodeGenCXX/builtin-operator-new-delete.cpp
> cfe/trunk/test/SemaCXX/builtin-operator-new-delete.cpp
> Modified:
> cfe/trunk/include/clang/Basic/Builtins.def
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> cfe/trunk/lib/CodeGen/CGExprCXX.cpp
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/lib/Lex/PPMacroExpansion.cpp
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Builtins.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/Builtins.def?rev=328134=328133=328134=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> +++ cfe/trunk/include/clang/Basic/Builtins.def Wed Mar 21 12:19:48 2018
> @@ -1371,8 +1371,8 @@ BUILTIN(__builtin_smulll_overflow, "bSLL
>
>  // Clang builtins (not available in GCC).
>  BUILTIN(__builtin_addressof, "v*v&", "nct")
> -BUILTIN(__builtin_operator_new, "v*z", "c")
> -BUILTIN(__builtin_operator_delete, "vv*", "n")
> +BUILTIN(__builtin_operator_new, "v*z", "tc")
> +BUILTIN(__builtin_operator_delete, "vv*", "tn")
>  BUILTIN(__builtin_char_memchr, "c*cC*iz", "n")
>
>  // Safestack builtins
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticSemaKinds.td?rev=328134=328133=328134=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 21
> 12:19:48 2018
> @@ -7627,6 +7627,11 @@ def err_destroying_operator_delete_not_u
>"alignment parameter">;
>  def note_implicit_delete_this_in_destructor_here : Note<
>"while checking implicit 'delete this' for virtual destructor">;
> +def err_builtin_operator_new_delete_not_usual : Error<
> +  "call to '%select{__builtin_operator_new|__builtin_operator_delete}0' "
> +  "selects non-usual %select{allocation|deallocation}0 function">;
> +def note_non_usual_function_declared_here : Note<
> +  "non-usual %0 declared here">;
>
>  // C++ literal operators
>  def err_literal_operator_outside_namespace : Error<
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/Sema.h?rev=328134=328133=328134=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Wed Mar 21 12:19:48 2018
> @@ -10376,6 +10376,8 @@ private:
>ExprResult SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult);
>ExprResult SemaAtomicOpsOverloaded(ExprResult 

[PATCH] D44788: Add an option to support debug fission on implicit ThinLTO.

2018-03-22 Thread Yunlian Jiang via Phabricator via cfe-commits
yunlian added a comment.

I have another one https://reviews.llvm.org/D44792 on LLVM side.


Repository:
  rC Clang

https://reviews.llvm.org/D44788



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


[PATCH] D44790: [clang-format] Fix ObjC style guesser to also iterate over child lines

2018-03-22 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
benhamilton marked an inline comment as done.
Closed by commit rL328220: [clang-format] Fix ObjC style guesser to also 
iterate over child lines (authored by benhamilton, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D44790

Files:
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1514,8 +1514,8 @@
 "UIView",
 };
 
-for (auto  : AnnotatedLines) {
-  for (FormatToken *FormatTok = Line->First; FormatTok;
+auto LineContainsObjCCode = [](const AnnotatedLine ) {
+  for (const FormatToken *FormatTok = Line.First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1536,6 +1536,15 @@
   return true;
 }
   }
+  return false;
+};
+for (auto Line : AnnotatedLines) {
+  if (LineContainsObjCCode(*Line))
+return true;
+  for (auto ChildLine : Line->Children) {
+if (LineContainsObjCCode(*ChildLine))
+  return true;
+  }
 }
 return false;
   }
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -12166,6 +12166,13 @@
   guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithChildLines) {
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1514,8 +1514,8 @@
 "UIView",
 };
 
-for (auto  : AnnotatedLines) {
-  for (FormatToken *FormatTok = Line->First; FormatTok;
+auto LineContainsObjCCode = [](const AnnotatedLine ) {
+  for (const FormatToken *FormatTok = Line.First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1536,6 +1536,15 @@
   return true;
 }
   }
+  return false;
+};
+for (auto Line : AnnotatedLines) {
+  if (LineContainsObjCCode(*Line))
+return true;
+  for (auto ChildLine : Line->Children) {
+if (LineContainsObjCCode(*ChildLine))
+  return true;
+  }
 }
 return false;
   }
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -12166,6 +12166,13 @@
   guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithChildLines) {
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r328220 - [clang-format] Fix ObjC style guesser to also iterate over child lines

2018-03-22 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Thu Mar 22 10:37:19 2018
New Revision: 328220

URL: http://llvm.org/viewvc/llvm-project?rev=328220=rev
Log:
[clang-format] Fix ObjC style guesser to also iterate over child lines

Summary:
When I wrote `ObjCHeaderStyleGuesser`, I incorrectly assumed the
correct way to iterate over all tokens in `AnnotatedLine` was to
iterate over the linked list tokens starting with
`AnnotatedLine::First`.

However, `AnnotatedLine` also contains a vector
`AnnotedLine::Children` with child `AnnotedLine`s which have their own
tokens which we need to iterate over.

Because I didn't iterate over the tokens in the children lines, the
ObjC style guesser would fail on syntax like:

  #define FOO ({ NSString *s = ... })

as the statement(s) inside { ... } are child lines.

This fixes the bug and adds a test. I confirmed the test
failed before the fix, and passed after the fix.

Test Plan: New tests added. Ran tests with:
  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: djasper, jolesiak, Wizard

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=328220=328219=328220=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Mar 22 10:37:19 2018
@@ -1514,8 +1514,8 @@ private:
 "UIView",
 };
 
-for (auto  : AnnotatedLines) {
-  for (FormatToken *FormatTok = Line->First; FormatTok;
+auto LineContainsObjCCode = [](const AnnotatedLine ) {
+  for (const FormatToken *FormatTok = Line.First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1536,6 +1536,15 @@ private:
   return true;
 }
   }
+  return false;
+};
+for (auto Line : AnnotatedLines) {
+  if (LineContainsObjCCode(*Line))
+return true;
+  for (auto ChildLine : Line->Children) {
+if (LineContainsObjCCode(*ChildLine))
+  return true;
+  }
 }
 return false;
   }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=328220=328219=328220=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Mar 22 10:37:19 2018
@@ -12166,6 +12166,13 @@ TEST_F(FormatTest, GuessLanguageWithCare
   guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithChildLines) {
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


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


r328219 - [OpenMP][Clang] Add call to global data sharing stack initialization on the workers side

2018-03-22 Thread Gheorghe-Teodor Bercea via cfe-commits
Author: gbercea
Date: Thu Mar 22 10:33:27 2018
New Revision: 328219

URL: http://llvm.org/viewvc/llvm-project?rev=328219=rev
Log:
[OpenMP][Clang] Add call to global data sharing stack initialization on the 
workers side

Summary: The workers also need to initialize the global stack. The call to the 
initialization function needs to happen after the kernel_init() function is 
called by the master. This ensures that the per-team data structures of the 
runtime have been initialized.

Reviewers: ABataev, grokos, carlo.bertolli, caomhin

Reviewed By: ABataev

Subscribers: jholewinski, guansong, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=328219=328218=328219=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Thu Mar 22 10:33:27 2018
@@ -801,6 +801,11 @@ void CGOpenMPRuntimeNVPTX::emitWorkerLoo
   // Wait for parallel work
   syncCTAThreads(CGF);
 
+  // For data sharing, we need to initialize the stack for workers.
+  CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(
+  OMPRTL_NVPTX__kmpc_data_sharing_init_stack));
+
   Address WorkFn =
   CGF.CreateDefaultAlignTempAlloca(CGF.Int8PtrTy, /*Name=*/"work_fn");
   Address ExecStatus =

Modified: cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp?rev=328219=328218=328219=diff
==
--- cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp Thu Mar 22 10:33:27 2018
@@ -27,6 +27,11 @@ void test_ds(){
   }
 }
 
+/// = In the worker function = ///
+// CK1: {{.*}}define internal void 
@__omp_offloading{{.*}}test_ds{{.*}}_worker()
+// CK1: call void @llvm.nvvm.barrier0()
+// CK1: call void @__kmpc_data_sharing_init_stack
+
 /// = In the kernel function = ///
 
 // CK1: {{.*}}define void @__omp_offloading{{.*}}test_ds{{.*}}()


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


[PATCH] D44749: [OpenMP][Clang] Add call to global data sharing stack initialization on the workers side

2018-03-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328219: [OpenMP][Clang] Add call to global data sharing 
stack initialization on theā€¦ (authored by gbercea, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44749

Files:
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  test/OpenMP/nvptx_data_sharing.cpp


Index: test/OpenMP/nvptx_data_sharing.cpp
===
--- test/OpenMP/nvptx_data_sharing.cpp
+++ test/OpenMP/nvptx_data_sharing.cpp
@@ -27,6 +27,11 @@
   }
 }
 
+/// = In the worker function = ///
+// CK1: {{.*}}define internal void 
@__omp_offloading{{.*}}test_ds{{.*}}_worker()
+// CK1: call void @llvm.nvvm.barrier0()
+// CK1: call void @__kmpc_data_sharing_init_stack
+
 /// = In the kernel function = ///
 
 // CK1: {{.*}}define void @__omp_offloading{{.*}}test_ds{{.*}}()
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -801,6 +801,11 @@
   // Wait for parallel work
   syncCTAThreads(CGF);
 
+  // For data sharing, we need to initialize the stack for workers.
+  CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(
+  OMPRTL_NVPTX__kmpc_data_sharing_init_stack));
+
   Address WorkFn =
   CGF.CreateDefaultAlignTempAlloca(CGF.Int8PtrTy, /*Name=*/"work_fn");
   Address ExecStatus =


Index: test/OpenMP/nvptx_data_sharing.cpp
===
--- test/OpenMP/nvptx_data_sharing.cpp
+++ test/OpenMP/nvptx_data_sharing.cpp
@@ -27,6 +27,11 @@
   }
 }
 
+/// = In the worker function = ///
+// CK1: {{.*}}define internal void @__omp_offloading{{.*}}test_ds{{.*}}_worker()
+// CK1: call void @llvm.nvvm.barrier0()
+// CK1: call void @__kmpc_data_sharing_init_stack
+
 /// = In the kernel function = ///
 
 // CK1: {{.*}}define void @__omp_offloading{{.*}}test_ds{{.*}}()
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -801,6 +801,11 @@
   // Wait for parallel work
   syncCTAThreads(CGF);
 
+  // For data sharing, we need to initialize the stack for workers.
+  CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(
+  OMPRTL_NVPTX__kmpc_data_sharing_init_stack));
+
   Address WorkFn =
   CGF.CreateDefaultAlignTempAlloca(CGF.Int8PtrTy, /*Name=*/"work_fn");
   Address ExecStatus =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44790: [clang-format] Fix ObjC style guesser to also iterate over child lines

2018-03-22 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton marked an inline comment as done.
benhamilton added inline comments.



Comment at: lib/Format/Format.cpp:1517
 
-for (auto  : AnnotatedLines) {
-  for (FormatToken *FormatTok = Line->First; FormatTok;
+auto CheckLineTokens = [](const AnnotatedLine ) {
+  for (const FormatToken *FormatTok = Line.First; FormatTok;

djasper wrote:
> Maybe choose a name that indicates what the bool result value means, e.g. 
> LinesContainObjCCode or something.
Done, thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D44790



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


[PATCH] D44790: [clang-format] Fix ObjC style guesser to also iterate over child lines

2018-03-22 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 139471.
benhamilton added a comment.

CheckLineTokens -> LineContainsObjCCode


Repository:
  rC Clang

https://reviews.llvm.org/D44790

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12162,6 +12162,13 @@
   guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithChildLines) {
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1514,8 +1514,8 @@
 "UIView",
 };
 
-for (auto  : AnnotatedLines) {
-  for (FormatToken *FormatTok = Line->First; FormatTok;
+auto LineContainsObjCCode = [](const AnnotatedLine ) {
+  for (const FormatToken *FormatTok = Line.First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1536,6 +1536,15 @@
   return true;
 }
   }
+  return false;
+};
+for (auto Line : AnnotatedLines) {
+  if (LineContainsObjCCode(*Line))
+return true;
+  for (auto ChildLine : Line->Children) {
+if (LineContainsObjCCode(*ChildLine))
+  return true;
+  }
 }
 return false;
   }


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12162,6 +12162,13 @@
   guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithChildLines) {
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1514,8 +1514,8 @@
 "UIView",
 };
 
-for (auto  : AnnotatedLines) {
-  for (FormatToken *FormatTok = Line->First; FormatTok;
+auto LineContainsObjCCode = [](const AnnotatedLine ) {
+  for (const FormatToken *FormatTok = Line.First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1536,6 +1536,15 @@
   return true;
 }
   }
+  return false;
+};
+for (auto Line : AnnotatedLines) {
+  if (LineContainsObjCCode(*Line))
+return true;
+  for (auto ChildLine : Line->Children) {
+if (LineContainsObjCCode(*ChildLine))
+  return true;
+  }
 }
 return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44790: [clang-format] Fix ObjC style guesser to also iterate over child lines

2018-03-22 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good, thank you!




Comment at: lib/Format/Format.cpp:1517
 
-for (auto  : AnnotatedLines) {
-  for (FormatToken *FormatTok = Line->First; FormatTok;
+auto CheckLineTokens = [](const AnnotatedLine ) {
+  for (const FormatToken *FormatTok = Line.First; FormatTok;

Maybe choose a name that indicates what the bool result value means, e.g. 
LinesContainObjCCode or something.


Repository:
  rC Clang

https://reviews.llvm.org/D44790



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


  1   2   >