[PATCH] D32745: Correct debug info bit offset calculation for big-endian targets

2017-05-02 Thread Frej Drejhammar via Phabricator via cfe-commits
frej updated this revision to Diff 97544.
frej added a comment.

Added missing "REQUIRES: mips-registered-target".


https://reviews.llvm.org/D32745

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/mips-debug-info-bitfield.c


Index: clang/test/CodeGen/mips-debug-info-bitfield.c
===
--- /dev/null
+++ clang/test/CodeGen/mips-debug-info-bitfield.c
@@ -0,0 +1,18 @@
+// REQUIRES: mips-registered-target
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple mips-none-linux-gnu 
-emit-llvm -o - %s | FileCheck %s
+
+struct fields
+{
+  unsigned a : 4;
+  unsigned b : 4;
+} flags;
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "a"
+// CHECK-NOT: {{.*}}offset:
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "b"
+// CHECK-SAME: {{.*}}offset: 4
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1041,7 +1041,13 @@
   assert(SizeInBits > 0 && "found named 0-width bitfield");
   uint64_t StorageOffsetInBits =
   CGM.getContext().toBits(BitFieldInfo.StorageOffset);
-  uint64_t OffsetInBits = StorageOffsetInBits + BitFieldInfo.Offset;
+  uint64_t Offset = BitFieldInfo.Offset;
+  // The bit offsets for big endian machines are reversed for big
+  // endian target, compensate for that as the DIDerivedType requires
+  // un-reversed offsets.
+  if (CGM.getDataLayout().isBigEndian())
+Offset = BitFieldInfo.StorageSize - BitFieldInfo.Size - Offset;
+  uint64_t OffsetInBits = StorageOffsetInBits + Offset;
   llvm::DINode::DIFlags Flags = getAccessFlag(BitFieldDecl->getAccess(), RD);
   return DBuilder.createBitFieldMemberType(
   RecordTy, Name, File, Line, SizeInBits, OffsetInBits, 
StorageOffsetInBits,


Index: clang/test/CodeGen/mips-debug-info-bitfield.c
===
--- /dev/null
+++ clang/test/CodeGen/mips-debug-info-bitfield.c
@@ -0,0 +1,18 @@
+// REQUIRES: mips-registered-target
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple mips-none-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+struct fields
+{
+  unsigned a : 4;
+  unsigned b : 4;
+} flags;
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "a"
+// CHECK-NOT: {{.*}}offset:
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "b"
+// CHECK-SAME: {{.*}}offset: 4
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1041,7 +1041,13 @@
   assert(SizeInBits > 0 && "found named 0-width bitfield");
   uint64_t StorageOffsetInBits =
   CGM.getContext().toBits(BitFieldInfo.StorageOffset);
-  uint64_t OffsetInBits = StorageOffsetInBits + BitFieldInfo.Offset;
+  uint64_t Offset = BitFieldInfo.Offset;
+  // The bit offsets for big endian machines are reversed for big
+  // endian target, compensate for that as the DIDerivedType requires
+  // un-reversed offsets.
+  if (CGM.getDataLayout().isBigEndian())
+Offset = BitFieldInfo.StorageSize - BitFieldInfo.Size - Offset;
+  uint64_t OffsetInBits = StorageOffsetInBits + Offset;
   llvm::DINode::DIFlags Flags = getAccessFlag(BitFieldDecl->getAccess(), RD);
   return DBuilder.createBitFieldMemberType(
   RecordTy, Name, File, Line, SizeInBits, OffsetInBits, StorageOffsetInBits,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31495: Fix a bug that -isysroot is completely ignored on Unix

2017-05-02 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301998: Fix a bug that -isysroot is completely ignored on 
Unix (authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D31495?vs=95402=97543#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31495

Files:
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/Driver/sysroot-flags.c


Index: cfe/trunk/test/Driver/sysroot-flags.c
===
--- cfe/trunk/test/Driver/sysroot-flags.c
+++ cfe/trunk/test/Driver/sysroot-flags.c
@@ -26,3 +26,7 @@
 // RUN:   FileCheck %s -check-prefix=SYSROOT_SEPARATE
 // SYSROOT_SEPARATE: "-isysroot" "{{[^"]*}}/foo/bar"
 // SYSROOT_SEPARATE: "--sysroot{{" "|=}}{{[^"]*}}/foo/bar"
+
+// Check that -isysroot is handled properly
+// RUN: %clang -isysroot /foo/bar -c %s -v 2>&1 | \
+// RUN:   grep "/foo/bar"
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -1565,7 +1565,7 @@
 frontend::IncludeDirGroup Group = frontend::System;
 if (A->getOption().matches(OPT_internal_externc_isystem))
   Group = frontend::ExternCSystem;
-Opts.AddPath(A->getValue(), Group, false, true);
+Opts.AddPath(A->getValue(), Group, false, false);
   }
 
   // Add the path prefixes which are implicitly treated as being system 
headers.


Index: cfe/trunk/test/Driver/sysroot-flags.c
===
--- cfe/trunk/test/Driver/sysroot-flags.c
+++ cfe/trunk/test/Driver/sysroot-flags.c
@@ -26,3 +26,7 @@
 // RUN:   FileCheck %s -check-prefix=SYSROOT_SEPARATE
 // SYSROOT_SEPARATE: "-isysroot" "{{[^"]*}}/foo/bar"
 // SYSROOT_SEPARATE: "--sysroot{{" "|=}}{{[^"]*}}/foo/bar"
+
+// Check that -isysroot is handled properly
+// RUN: %clang -isysroot /foo/bar -c %s -v 2>&1 | \
+// RUN:   grep "/foo/bar"
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -1565,7 +1565,7 @@
 frontend::IncludeDirGroup Group = frontend::System;
 if (A->getOption().matches(OPT_internal_externc_isystem))
   Group = frontend::ExternCSystem;
-Opts.AddPath(A->getValue(), Group, false, true);
+Opts.AddPath(A->getValue(), Group, false, false);
   }
 
   // Add the path prefixes which are implicitly treated as being system headers.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r301994 - [sanitizer-coverage] add a deprecation warning to the old sanitizer-coverage flag combinations

2017-05-02 Thread Kostya Serebryany via cfe-commits
Author: kcc
Date: Tue May  2 20:27:28 2017
New Revision: 301994

URL: http://llvm.org/viewvc/llvm-project?rev=301994=rev
Log:
[sanitizer-coverage] add a deprecation warning to the old sanitizer-coverage 
flag combinations

Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize-coverage.c

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=301994=301993=301994=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue May  2 20:27:28 2017
@@ -511,7 +511,6 @@ SanitizerArgs::SanitizerArgs(const ToolC
 << "-fsanitize-coverage=edge";
   // Basic block tracing and 8-bit counters require some type of coverage
   // enabled.
-  int CoverageTypes = CoverageFunc | CoverageBB | CoverageEdge;
   if (CoverageFeatures & CoverageTraceBB)
 D.Diag(clang::diag::warn_drv_deprecated_arg)
 << "-fsanitize-coverage=trace-bb"
@@ -520,9 +519,18 @@ SanitizerArgs::SanitizerArgs(const ToolC
 D.Diag(clang::diag::warn_drv_deprecated_arg)
 << "-fsanitize-coverage=8bit-counters"
 << "-fsanitize-coverage=trace-pc-guard";
+
+  int InsertionPointTypes = CoverageFunc | CoverageBB | CoverageEdge;
+  if ((CoverageFeatures & InsertionPointTypes) &&
+  !(CoverageFeatures &(CoverageTracePC | CoverageTracePCGuard))) {
+D.Diag(clang::diag::warn_drv_deprecated_arg)
+<< "-fsanitize-coverage=[func|bb|edge]"
+<< "-fsanitize-coverage=[func|bb|edge],[trace-pc-guard|trace-pc]";
+  }
+
   // trace-pc w/o func/bb/edge implies edge.
   if ((CoverageFeatures & (CoverageTracePC | CoverageTracePCGuard)) &&
-  !(CoverageFeatures & CoverageTypes))
+  !(CoverageFeatures & InsertionPointTypes))
 CoverageFeatures |= CoverageEdge;
 
   if (AllAddedKinds & Address) {

Modified: cfe/trunk/test/Driver/fsanitize-coverage.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize-coverage.c?rev=301994=301993=301994=diff
==
--- cfe/trunk/test/Driver/fsanitize-coverage.c (original)
+++ cfe/trunk/test/Driver/fsanitize-coverage.c Tue May  2 20:27:28 2017
@@ -4,12 +4,13 @@
 // CHECK-SANITIZE-COVERAGE-0-NOT: fsanitize-coverage-type
 // CHECK-SANITIZE-COVERAGE-0: -fsanitize=address
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-coverage=func %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-coverage=func %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=leak 
-fsanitize-coverage=func %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined 
-fsanitize-coverage=func %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=bool 
-fsanitize-coverage=func %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=dataflow 
-fsanitize-coverage=func %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=leak 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=bool 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=dataflow 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
+// RUN: %clang -target x86_64-linux-gnu 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // CHECK-SANITIZE-COVERAGE-FUNC: fsanitize-coverage-type=1
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-coverage=bb %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-BB
@@ -25,13 +26,10 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-coverage=1 %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-1
 // 

First patch (Missing commas diagnostics)

2017-05-02 Thread Zaid Alkhishman via cfe-commits
This is my first patch. It's targeted at the parser/diagnostics.

The goal of the patch is to anticipate missing commas in initializer lists
and report them appropriately as errors, instead of the current "expected
'}' to match '}'" errors.

In summary, It detects missing commas only when successfully parsing the
next element in the list.

An example input/output pair are also attached for your convenience.

Please inform me of any requested changes.

Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td (revision 301985)
+++ include/clang/Basic/DiagnosticParseKinds.td (working copy)
@@ -164,6 +164,7 @@
 def err_at_defs_cxx : Error<"@defs is not supported in Objective-C++">;
 def err_at_in_class : Error<"unexpected '@' in member specification">;
 def err_unexpected_semi : Error<"unexpected ';' before %0">;
+def err_expected_comma : Error<"expected ',' before initializer">;

 def err_expected_fn_body : Error<
   "expected function body after function declarator">;
Index: include/clang/Parse/RAIIObjectsForParser.h
===
--- include/clang/Parse/RAIIObjectsForParser.h (revision 301985)
+++ include/clang/Parse/RAIIObjectsForParser.h (working copy)
@@ -440,6 +440,13 @@

   return diagnoseMissingClose();
 }
+
+bool willClose(){
+  if (P.Tok.is(Close))
+return false;
+  return true;
+}
+
 void skipToEnd();
   };

Index: lib/Parse/ParseInit.cpp
===
--- lib/Parse/ParseInit.cpp (revision 301985)
+++ lib/Parse/ParseInit.cpp (working copy)
@@ -409,6 +409,8 @@
   Actions, EnterExpressionEvaluationContext::InitList);

   bool InitExprsOk = true;
+  bool maybeMissingComma = false;
+  Token startOfNextIni;

   while (1) {
 // Handle Microsoft __if_exists/if_not_exists if necessary.
@@ -427,6 +429,8 @@
 // If we know that this cannot be a designation, just parse the nested
 // initializer directly.
 ExprResult SubElt;
+startOfNextIni = Tok;
+
 if (MayBeDesignationStart())
   SubElt = ParseInitializerWithPotentialDesignator();
 else
@@ -457,9 +461,25 @@
   }
 }

-// If we don't have a comma continued list, we're done.
-if (Tok.isNot(tok::comma)) break;
+if(maybeMissingComma){
+  //Here we would have checked if InitExprsOk is true,
+  //but it's implied to be ok because of the previous break
+  //Now we know the compilee  very likely forgot the comma
+  Diag(startOfNextIni.getLocation(), diag::err_expected_comma)
+   <<
FixItHint::CreateInsertion(startOfNextIni.getLocation().getLocWithOffset(-1),
",");
+  maybeMissingComma = false;
+}

+// If we don't have a comma continued list, we're done (maybe).
+if (Tok.isNot(tok::comma)){
+  if(!T.willClose()){
+//This is a ok list, no missing commas.
+break;
+  }
+  maybeMissingComma = true;
+  continue;
+}
+
 // TODO: save comma locations if some client cares.
 ConsumeToken();
Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td	(revision 301985)
+++ include/clang/Basic/DiagnosticParseKinds.td	(working copy)
@@ -164,6 +164,7 @@
 def err_at_defs_cxx : Error<"@defs is not supported in Objective-C++">;
 def err_at_in_class : Error<"unexpected '@' in member specification">;
 def err_unexpected_semi : Error<"unexpected ';' before %0">;
+def err_expected_comma : Error<"expected ',' before initializer">;
 
 def err_expected_fn_body : Error<
   "expected function body after function declarator">;
Index: include/clang/Parse/RAIIObjectsForParser.h
===
--- include/clang/Parse/RAIIObjectsForParser.h	(revision 301985)
+++ include/clang/Parse/RAIIObjectsForParser.h	(working copy)
@@ -440,6 +440,13 @@
   
   return diagnoseMissingClose();
 }
+
+bool willClose(){
+  if (P.Tok.is(Close))
+return false;
+  return true;
+}
+
 void skipToEnd();
   };
 
Index: lib/Parse/ParseInit.cpp
===
--- lib/Parse/ParseInit.cpp	(revision 301985)
+++ lib/Parse/ParseInit.cpp	(working copy)
@@ -409,6 +409,8 @@
   Actions, EnterExpressionEvaluationContext::InitList);
 
   bool InitExprsOk = true;
+  bool maybeMissingComma = false;
+  Token startOfNextIni;
 
   while (1) {
 // Handle Microsoft __if_exists/if_not_exists if necessary.
@@ -427,6 +429,8 @@
 // If we know that this cannot be a designation, just parse the nested
 // initializer directly.
 ExprResult SubElt;
+startOfNextIni = Tok;
+
 if (MayBeDesignationStart())
   SubElt = ParseInitializerWithPotentialDesignator();
 else
@@ -457,9 +461,25 @@
 

Re: [llvm-dev] Permissions for llvm-mirror - Setting up Libc++ Appveyor builders

2017-05-02 Thread Reid Kleckner via cfe-commits
I'm definitely in favor of efforts to defragment our many CI systems, but I
also don't want to stop people from doing more testing. :)

If AppVeyor is providing free testing resource to OSS projects, then great,
let's try using it and see how it goes.

On Fri, Apr 21, 2017 at 6:56 AM, Mike Edwards via llvm-dev <
llvm-...@lists.llvm.org> wrote:

> Hi,
> Fragmentation of the bots is not ideal.  While I totally understand Eric's
> reasoning for doing so, and am delighted to see  another Windows bot
> helping to ensure quality code, I think this is a bit of a slippery slope.
> We already have the main Buildbots, Green Dragon, Chapuni's Bots, a myriad
> of private bots and now this new bot.  I don't think it is reasonable to
> ask people to have to visit several different places to check if their
> commit broke something.  Anecdotally, I find many people will only look at
> lab.llvm.org:8011.  They will check Green Dragon if they get an email and
> then only if the email does not get lost in the noise.  Some folks are
> regular users of bb.pgr.jp but the actual number or regular visitors I
> don't know.
>
> Perhaps it would be a more beneficial discussion to talk about putting
> together some type of portal which displays results from all the CI systems
> in one place?  I for one would love an interface which would be able to
> show any given commit and how is has performed across the board.  Something
> like this could possibly allow for anyone to stand up a bot or CI
> infrastructure of their choosing and then have that system integrated in a
> common reporting platform so it is useful and accessible to everyone.
>
> Thoughts?
>
> -Mike
>
> On Thu, Apr 20, 2017 at 7:22 PM, Mehdi Amini via llvm-dev <
> llvm-...@lists.llvm.org> wrote:
>
>>
>> On Apr 20, 2017, at 7:03 PM, Eric Fiselier  wrote:
>>
>>
>>
>> On Thu, Apr 20, 2017 at 4:55 PM, Mehdi Amini 
>> wrote:
>>
>>>
>>> On Apr 20, 2017, at 12:30 PM, Eric Fiselier  wrote:
>>>
>>>
>>>
>>> On Thu, Apr 20, 2017 at 11:06 AM, Mehdi Amini 
>>> wrote:
>>>

 On Apr 20, 2017, at 12:39 AM, Eric Fiselier  wrote:



 On Wed, Apr 19, 2017 at 11:19 PM, Mehdi Amini 
 wrote:

> What would be the status of these buildbots? Is it for your private
> usage?
>

 I intend for them to be public Windows buildbots for libc++.



 I’m not sure it’d be OK to send blame email to contributors based on
 this though.

>>>
>>> I don't see why not (at least once the bot is stable). Can you elaborate?
>>>
>>>
>>> I don’t think there is a precedent for having a bot that does not
>>> checkout from SVN and email using the canonical SVN revision number.
>>>
>>
>> I understand share your concern about the emails using nonsensical git
>> hashes as opposed to SVN revision numbers.
>> Apart from that I have no idea why the version control used by the CI
>> matters. It should have to effect on the build or the results.
>>
>>
>> I don’t know, but other people may have other concern that I don’t
>> necessarily anticipate..
>>
>>
>>
>>>
>>> So it does not seems like a given to me  (not that I’m against it) and
>>> would require a discussion on the mailing-list first IMO.
>>>
>>
>> We might as well continue having it now since it's been started. I'll
>> re-raise the issue in a month or so when the bot is
>> actually stable enough to consider sending emails.
>>
>>
>> I think it deserve a separate thread to deal with this, so that the
>> thread title help making sure no-one miss the discussion.
>>
>> —
>> Mehdi
>>
>>
>> ___
>> LLVM Developers mailing list
>> llvm-...@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>
> ___
> LLVM Developers mailing list
> llvm-...@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32778: [libcxx] [test] Conditionally workaround C1XX/EDG bugs

2017-05-02 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter added inline comments.



Comment at: test/support/archetypes.hpp:20
 protected:
+#endif // !TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
   NullBase() = default;

STL_MSFT wrote:
> I think that this comment doesn't match the ifndef check, but it's a style 
> question.
I know which style *I* prefer, because I wrote it, and I know which style *you* 
prefer, because you commented. I'll change this when Marshall or Eric let me 
know what they prefer here.



Comment at: test/support/archetypes.ipp:10
+#ifdef TEST_WORKAROUND_EDG_EXPLICIT_CONSTEXPR
+#define DEFINE_CONSTEXPR
+#else // TEST_WORKAROUND_EDG_EXPLICIT_CONSTEXPR

STL_MSFT wrote:
> Should you define it to be `inline` instead of nothing?
This macro is typically defined to either `constexpr` or nothing - see the 
definitions in `archetypes.hpp` above.


https://reviews.llvm.org/D32778



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


[PATCH] D32778: [libcxx] [test] Conditionally workaround C1XX/EDG bugs

2017-05-02 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT accepted this revision.
STL_MSFT added inline comments.
This revision is now accepted and ready to land.



Comment at: test/support/archetypes.hpp:20
 protected:
+#endif // !TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
   NullBase() = default;

I think that this comment doesn't match the ifndef check, but it's a style 
question.



Comment at: test/support/archetypes.ipp:10
+#ifdef TEST_WORKAROUND_EDG_EXPLICIT_CONSTEXPR
+#define DEFINE_CONSTEXPR
+#else // TEST_WORKAROUND_EDG_EXPLICIT_CONSTEXPR

Should you define it to be `inline` instead of nothing?


https://reviews.llvm.org/D32778



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


[PATCH] D32778: [libcxx] [test] Conditionally workaround C1XX/EDG bugs

2017-05-02 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter created this revision.

Test support machinery changes needed to parse with EDG and compile with C1XX's 
/Za flag that disables MS extensions.

I try to make changes to `` and the `optional`/`variant` tests 
simultaneously in the MS STL and in libc++, which realistically requires that I 
keep the tests largely synchronized between libc++ and our internal test suite. 
As a first step toward automating that integration, I'd like to upstream this 
patch.

This change works around a couple of bugs:

1. EDG doesn't like explicit constexpr in a derived class. This program:

  struct Base {};
  
  struct Derived : Base {
  constexpr Derived() = default;
  };

triggers "error: defaulted default constructor cannot be constexpr."

2. C1XX with /Za has no idea which constructor needs to be valid for copy 
elision.

The change also conditionally disables parts of the 
msvc_stdlib_force_include.hpp header that conflict with external configuration 
when `_LIBCXX_IN_DEVCRT` is defined.


https://reviews.llvm.org/D32778

Files:
  test/support/archetypes.hpp
  test/support/archetypes.ipp
  test/support/msvc_stdlib_force_include.hpp
  test/support/test.workarounds/c1xx_broken_za_ctor_check.pass.cpp
  test/support/test_macros.h
  test/support/test_workarounds.h

Index: test/support/test_workarounds.h
===
--- test/support/test_workarounds.h
+++ test/support/test_workarounds.h
@@ -13,9 +13,16 @@
 
 #include "test_macros.h"
 
+#if defined(TEST_COMPILER_EDG)
+# define TEST_WORKAROUND_EDG_EXPLICIT_CONSTEXPR
+#endif
+
 #if defined(TEST_COMPILER_C1XX)
 # define TEST_WORKAROUND_C1XX_BROKEN_NULLPTR_CONVERSION_OPERATOR
 # define TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
+# ifndef _MSC_EXTENSIONS
+#  define TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
+# endif
 #endif
 
 #endif // SUPPORT_TEST_WORKAROUNDS_H
Index: test/support/test_macros.h
===
--- test/support/test_macros.h
+++ test/support/test_macros.h
@@ -52,10 +52,12 @@
 #define TEST_HAS_BUILTIN_IDENTIFIER(X) 0
 #endif
 
-#if defined(__clang__)
-#define TEST_COMPILER_CLANG
+#if defined(__EDG__)
+# define TEST_COMPILER_EDG
+#elif defined(__clang__)
+# define TEST_COMPILER_CLANG
 # if defined(__apple_build_version__)
-#   define TEST_COMPILER_APPLE_CLANG
+#  define TEST_COMPILER_APPLE_CLANG
 # endif
 #elif defined(_MSC_VER)
 # define TEST_COMPILER_C1XX
Index: test/support/test.workarounds/c1xx_broken_za_ctor_check.pass.cpp
===
--- /dev/null
+++ test/support/test.workarounds/c1xx_broken_za_ctor_check.pass.cpp
@@ -0,0 +1,41 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03
+
+// Verify TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK.
+
+#include 
+
+#include "test_workarounds.h"
+
+struct X {
+X(int) {}
+
+X(X&&) = default;
+X& operator=(X&&) = default;
+
+private:
+X(const X&) = default;
+X& operator=(const X&) = default;
+};
+
+void PushFront(X&&) {}
+
+template
+auto test(int) -> decltype(PushFront(std::declval()), std::true_type{});
+auto test(long) -> std::false_type;
+
+int main() {
+#if defined(TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK)
+static_assert(!decltype(test(0))::value, "");
+#else
+static_assert(decltype(test(0))::value, "");
+#endif
+}
Index: test/support/msvc_stdlib_force_include.hpp
===
--- test/support/msvc_stdlib_force_include.hpp
+++ test/support/msvc_stdlib_force_include.hpp
@@ -13,11 +13,13 @@
 // This header is force-included when running the libc++ tests against the
 // MSVC standard library.
 
-// Silence warnings about CRT machinery.
-#define _CRT_SECURE_NO_WARNINGS
+#ifndef _LIBCXX_IN_DEVCRT
+// Silence warnings about CRT machinery.
+#define _CRT_SECURE_NO_WARNINGS
 
-// Avoid assertion dialogs.
-#define _CRT_SECURE_INVALID_PARAMETER(EXPR) ::abort()
+// Avoid assertion dialogs.
+#define _CRT_SECURE_INVALID_PARAMETER(EXPR) ::abort()
+#endif // _LIBCXX_IN_DEVCRT
 
 #include 
 #include 
@@ -31,6 +33,7 @@
 #define _MSVC_STL_VER 42
 #endif
 
+#ifndef _LIBCXX_IN_DEVCRT
 struct AssertionDialogAvoider {
 AssertionDialogAvoider() {
 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
@@ -42,6 +45,7 @@
 };
 
 const AssertionDialogAvoider assertion_dialog_avoider{};
+#endif // _LIBCXX_IN_DEVCRT
 
 // MSVC frontend only configurations
 #if !defined(__clang__)
@@ -69,15 +73,17 @@
 // MSVC has quick_exit() and at_quick_exit().
 #define _LIBCPP_HAS_QUICK_EXIT
 
-// atomic_is_lock_free.pass.cpp needs this 

r301992 - [modules] Round-trip -Werror flag through explicit module build.

2017-05-02 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue May  2 19:28:49 2017
New Revision: 301992

URL: http://llvm.org/viewvc/llvm-project?rev=301992=rev
Log:
[modules] Round-trip -Werror flag through explicit module build.

The intent for an explicit module build is that the diagnostics produced within
the module are those that were configured when the module was built, not those
that are enabled within a user of the module. This includes diagnostics that
don't actually show up until the module is used (for instance, diagnostics
produced during template instantiation and weird cases like -Wpadded).

We serialized and restored the diagnostic state for individual warning groups,
but previously did not track the state for flags like -Werror and -Weverything,
which are implemented as separate bits rather than as part of the diagnostics
mapping information.

Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/include/clang/Basic/DiagnosticIDs.h
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/lib/Basic/DiagnosticIDs.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/Index/keep-going.cpp
cfe/trunk/test/Modules/diag-flags.cpp
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/unittests/Basic/DiagnosticTest.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=301992=301991=301992=diff
==
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Tue May  2 19:28:49 2017
@@ -178,12 +178,7 @@ public:
 
 private:
   unsigned char AllExtensionsSilenced; // Used by __extension__
-  bool IgnoreAllWarnings;// Ignore all warnings: -w
-  bool WarningsAsErrors; // Treat warnings like errors.
-  bool EnableAllWarnings;// Enable all warnings.
-  bool ErrorsAsFatal;// Treat errors like fatal errors.
-  bool FatalsAsError; // Treat fatal errors like errors.
-  bool SuppressSystemWarnings;   // Suppress warnings in system headers.
+  bool SuppressAfterFatalError;  // Suppress diagnostics after a fatal error?
   bool SuppressAllDiagnostics;   // Suppress all diagnostics.
   bool ElideType;// Elide common types of templates.
   bool PrintTemplateTree;// Print a tree when comparing templates.
@@ -194,7 +189,6 @@ private:
// 0 -> no limit.
   unsigned ConstexprBacktraceLimit; // Cap on depth of constexpr evaluation
 // backtrace stack, 0 -> no limit.
-  diag::Severity ExtBehavior;   // Map extensions to warnings or errors?
   IntrusiveRefCntPtr Diags;
   IntrusiveRefCntPtr DiagOpts;
   DiagnosticConsumer *Client;
@@ -216,6 +210,19 @@ private:
 llvm::DenseMap DiagMap;
 
   public:
+// "Global" configuration state that can actually vary between modules.
+unsigned IgnoreAllWarnings : 1;  // Ignore all warnings: -w
+unsigned EnableAllWarnings : 1;  // Enable all warnings.
+unsigned WarningsAsErrors : 1;   // Treat warnings like errors.
+unsigned ErrorsAsFatal : 1;  // Treat errors like fatal errors.
+unsigned SuppressSystemWarnings : 1; // Suppress warnings in system 
headers.
+diag::Severity ExtBehavior : 4; // Map extensions to warnings or 
errors?
+
+DiagState()
+: IgnoreAllWarnings(false), EnableAllWarnings(false),
+  WarningsAsErrors(false), ErrorsAsFatal(false),
+  SuppressSystemWarnings(false), ExtBehavior(diag::Severity::Ignored) 
{}
+
 typedef llvm::DenseMap::iterator iterator;
 typedef llvm::DenseMap::const_iterator
 const_iterator;
@@ -493,33 +500,47 @@ public:
   /// \brief When set to true, any unmapped warnings are ignored.
   ///
   /// If this and WarningsAsErrors are both set, then this one wins.
-  void setIgnoreAllWarnings(bool Val) { IgnoreAllWarnings = Val; }
-  bool getIgnoreAllWarnings() const { return IgnoreAllWarnings; }
+  void setIgnoreAllWarnings(bool Val) {
+GetCurDiagState()->IgnoreAllWarnings = Val;
+  }
+  bool getIgnoreAllWarnings() const {
+return GetCurDiagState()->IgnoreAllWarnings;
+  }
 
   /// \brief When set to true, any unmapped ignored warnings are no longer
   /// ignored.
   ///
   /// If this and IgnoreAllWarnings are both set, then that one wins.
-  void setEnableAllWarnings(bool Val) { EnableAllWarnings = Val; }
-  bool getEnableAllWarnings() const { return EnableAllWarnings; }
+  void setEnableAllWarnings(bool Val) {
+GetCurDiagState()->EnableAllWarnings = Val;
+  }
+  bool getEnableAllWarnings() const {
+return GetCurDiagState()->EnableAllWarnings;
+  }
 
   /// \brief When set to true, any warnings reported are issued as errors.
-  void setWarningsAsErrors(bool Val) { 

r301989 - [ODRHash] Add support for array and decayed types, and parameter names and types.

2017-05-02 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Tue May  2 18:58:52 2017
New Revision: 301989

URL: http://llvm.org/viewvc/llvm-project?rev=301989=rev
Log:
[ODRHash] Add support for array and decayed types, and parameter names and 
types.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=301989=301988=301989=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Tue May  2 
18:58:52 2017
@@ -146,7 +146,10 @@ def err_module_odr_violation_mismatch_de
   "method %4 is %select{not static|static}5|"
   "method %4 is %select{not volatile|volatile}5|"
   "method %4 is %select{not const|const}5|"
-  "method %4 is %select{not inline|inline}5}3">;
+  "method %4 is %select{not inline|inline}5|"
+  "method %4 that has %5 parameter%s5|"
+  "method %4 with %ordinal5 parameter of type %6%select{| decayed from %8}7|"
+  "method %4 with %ordinal5 parameter named %6}3">;
 
 def note_module_odr_violation_mismatch_decl_diff : Note<"but in '%0' found "
   "%select{"
@@ -166,7 +169,10 @@ def note_module_odr_violation_mismatch_d
   "method %2 is %select{not static|static}3|"
   "method %2 is %select{not volatile|volatile}3|"
   "method %2 is %select{not const|const}3|"
-  "method %2 is %select{not inline|inline}3}1">;
+  "method %2 is %select{not inline|inline}3|"
+  "method %2 that has %3 parameter%s3|"
+  "method %2 with %ordinal3 parameter of type %4%select{| decayed from %6}5|"
+  "method %2 with %ordinal3 parameter named %4}1">;
 
 def warn_module_uses_date_time : Warning<
   "%select{precompiled header|module}0 uses __DATE__ or __TIME__">,

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=301989=301988=301989=diff
==
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Tue May  2 18:58:52 2017
@@ -169,6 +169,11 @@ public:
 Inherited::VisitValueDecl(D);
   }
 
+  void VisitParmVarDecl(const ParmVarDecl *D) {
+// TODO: Handle default arguments.
+Inherited::VisitParmVarDecl(D);
+  }
+
   void VisitAccessSpecDecl(const AccessSpecDecl *D) {
 ID.AddInteger(D->getAccess());
 Inherited::VisitAccessSpecDecl(D);
@@ -202,6 +207,12 @@ public:
 Hash.AddBoolean(D->isPure());
 Hash.AddBoolean(D->isDeletedAsWritten());
 
+ID.AddInteger(D->param_size());
+
+for (auto *Param : D->parameters()) {
+  Hash.AddSubDecl(Param);
+}
+
 Inherited::VisitFunctionDecl(D);
   }
 
@@ -256,6 +267,11 @@ void ODRHash::AddSubDecl(const Decl *D)
 void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {
   assert(Record && Record->hasDefinition() &&
  "Expected non-null record to be a definition.");
+
+  if (isa(Record)) {
+return;
+  }
+
   AddDecl(Record);
 
   // Filter out sub-Decls which will not be processed in order to get an
@@ -315,6 +331,14 @@ public:
 }
   }
 
+  void AddQualType(QualType T) {
+Hash.AddQualType(T);
+  }
+
+  void VisitQualifiers(Qualifiers Quals) {
+ID.AddInteger(Quals.getAsOpaqueValue());
+  }
+
   void Visit(const Type *T) {
 ID.AddInteger(T->getTypeClass());
 Inherited::Visit(T);
@@ -322,11 +346,69 @@ public:
 
   void VisitType(const Type *T) {}
 
+  void VisitAdjustedType(const AdjustedType *T) {
+AddQualType(T->getOriginalType());
+AddQualType(T->getAdjustedType());
+VisitType(T);
+  }
+
+  void VisitDecayedType(const DecayedType *T) {
+AddQualType(T->getDecayedType());
+AddQualType(T->getPointeeType());
+VisitAdjustedType(T);
+  }
+
+  void VisitArrayType(const ArrayType *T) {
+AddQualType(T->getElementType());
+ID.AddInteger(T->getSizeModifier());
+VisitQualifiers(T->getIndexTypeQualifiers());
+VisitType(T);
+  }
+  void VisitConstantArrayType(const ConstantArrayType *T) {
+T->getSize().Profile(ID);
+VisitArrayType(T);
+  }
+
+  void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
+AddStmt(T->getSizeExpr());
+VisitArrayType(T);
+  }
+
+  void VisitIncompleteArrayType(const IncompleteArrayType *T) {
+VisitArrayType(T);
+  }
+
+  void VisitVariableArrayType(const VariableArrayType *T) {
+AddStmt(T->getSizeExpr());
+VisitArrayType(T);
+  }
+
   void VisitBuiltinType(const BuiltinType *T) {
 ID.AddInteger(T->getKind());
 VisitType(T);
   }
 
+  void VisitFunctionType(const FunctionType *T) {
+AddQualType(T->getReturnType());
+T->getExtInfo().Profile(ID);
+Hash.AddBoolean(T->isConst());
+

r301988 - [ubsan] Skip overflow checks on safe arithmetic (fixes PR32874)

2017-05-02 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Tue May  2 18:46:56 2017
New Revision: 301988

URL: http://llvm.org/viewvc/llvm-project?rev=301988=rev
Log:
[ubsan] Skip overflow checks on safe arithmetic (fixes PR32874)

Currently, ubsan emits overflow checks for arithmetic that is known to
be safe at compile-time, e.g:

  1 + 1 => CheckedAdd(1, 1)

This leads to breakage when using the __builtin_prefetch intrinsic. LLVM
expects the arguments to @llvm.prefetch to be constant integers, and
when ubsan inserts unnecessary checks on the operands to the intrinsic,
this contract is broken, leading to verifier failures (see PR32874).

Instead of special-casing __builtin_prefetch for ubsan, this patch fixes
the underlying problem, i.e that clang currently emits unnecessary
overflow checks.

Testing: I ran the check-clang and check-ubsan targets with a stage2,
ubsan-enabled build of clang. I added a regression test for PR32874, and
some extra checking to make sure we don't regress runtime checking for
unsafe arithmetic. The existing ubsan-promoted-arithmetic.cpp test also
provides coverage for this change.

Added:
cfe/trunk/test/CodeGen/PR32874.c
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=301988=301987=301988=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue May  2 18:46:56 2017
@@ -51,6 +51,64 @@ struct BinOpInfo {
   BinaryOperator::Opcode Opcode; // Opcode of BinOp to perform
   FPOptions FPFeatures;
   const Expr *E;  // Entire expr, for error unsupported.  May not be binop.
+
+  /// Check if the binop can result in integer overflow.
+  bool mayHaveIntegerOverflow() const {
+// Without constant input, we can't rule out overflow.
+const auto *LHSCI = dyn_cast(LHS);
+const auto *RHSCI = dyn_cast(RHS);
+if (!LHSCI || !RHSCI)
+  return true;
+
+// Assume overflow is possible, unless we can prove otherwise.
+bool Overflow = true;
+const auto  = LHSCI->getValue();
+const auto  = RHSCI->getValue();
+if (Opcode == BO_Add) {
+  if (Ty->hasSignedIntegerRepresentation())
+(void)LHSAP.sadd_ov(RHSAP, Overflow);
+  else
+(void)LHSAP.uadd_ov(RHSAP, Overflow);
+} else if (Opcode == BO_Sub) {
+  if (Ty->hasSignedIntegerRepresentation())
+(void)LHSAP.ssub_ov(RHSAP, Overflow);
+  else
+(void)LHSAP.usub_ov(RHSAP, Overflow);
+} else if (Opcode == BO_Mul) {
+  if (Ty->hasSignedIntegerRepresentation())
+(void)LHSAP.smul_ov(RHSAP, Overflow);
+  else
+(void)LHSAP.umul_ov(RHSAP, Overflow);
+} else if (Opcode == BO_Div || Opcode == BO_Rem) {
+  if (Ty->hasSignedIntegerRepresentation() && !RHSCI->isZero())
+(void)LHSAP.sdiv_ov(RHSAP, Overflow);
+  else
+return false;
+}
+return Overflow;
+  }
+
+  /// Check if the binop computes a division or a remainder.
+  bool isDivisionLikeOperation() const {
+return Opcode == BO_Div || Opcode == BO_Rem || Opcode == BO_DivAssign ||
+   Opcode == BO_RemAssign;
+  }
+
+  /// Check if the binop can result in an integer division by zero.
+  bool mayHaveIntegerDivisionByZero() const {
+if (isDivisionLikeOperation())
+  if (auto *CI = dyn_cast(RHS))
+return CI->isZero();
+return true;
+  }
+
+  /// Check if the binop can result in a float division by zero.
+  bool mayHaveFloatDivisionByZero() const {
+if (isDivisionLikeOperation())
+  if (auto *CFP = dyn_cast(RHS))
+return CFP->isZero();
+return true;
+  }
 };
 
 static bool MustVisitNullValue(const Expr *E) {
@@ -85,9 +143,17 @@ static bool CanElideOverflowCheck(const
   assert((isa(Op.E) || isa(Op.E)) &&
  "Expected a unary or binary operator");
 
+  // If the binop has constant inputs and we can prove there is no overflow,
+  // we can elide the overflow check.
+  if (!Op.mayHaveIntegerOverflow())
+return true;
+
+  // If a unary op has a widened operand, the op cannot overflow.
   if (const auto *UO = dyn_cast(Op.E))
 return IsWidenedIntegerOp(Ctx, UO->getSubExpr());
 
+  // We usually don't need overflow checks for binops with widened operands.
+  // Multiplication with promoted unsigned operands is a special case.
   const auto *BO = cast(Op.E);
   auto OptionalLHSTy = getUnwidenedIntegerType(Ctx, BO->getLHS());
   if (!OptionalLHSTy)
@@ -100,14 +166,14 @@ static bool CanElideOverflowCheck(const
   QualType LHSTy = *OptionalLHSTy;
   QualType RHSTy = *OptionalRHSTy;
 
-  // We usually don't need overflow checks for binary operations with widened
-  // operands. Multiplication with promoted unsigned operands is a special 
case.
+  // This is the simple case: binops without unsigned multiplication, and with
+  // widened operands. No overflow check is needed here.
   if 

[PATCH] D32770: [X86][LWP] Add clang support for LWP instructions.

2017-05-02 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

llvm patch: https://reviews.llvm.org/D32769


Repository:
  rL LLVM

https://reviews.llvm.org/D32770



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


[PATCH] D32770: [X86][LWP] Add clang support for LWP instructions.

2017-05-02 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon created this revision.
Herald added a subscriber: mgorny.

This patch adds support for the the LightWeight Profiling (LWP) instructions 
which are available on all AMD Bulldozer class CPUs (bdver1 to bdver4).


Repository:
  rL LLVM

https://reviews.llvm.org/D32770

Files:
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/BuiltinsX86_64.def
  include/clang/Driver/Options.td
  lib/Basic/Targets.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/lwpintrin.h
  lib/Headers/x86intrin.h
  test/CodeGen/lwp-builtins.c

Index: test/CodeGen/lwp-builtins.c
===
--- test/CodeGen/lwp-builtins.c
+++ test/CodeGen/lwp-builtins.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +lwp -emit-llvm -o - -Wall -Werror | FileCheck %s
+
+#include 
+
+void test_llwpcb(void *ptr) {
+  // CHECK-LABEL: @test_llwpcb
+  // CHECK: call void @llvm.x86.llwpcb(i8* %{{.*}})
+  __llwpcb(ptr);
+}
+
+void* test_slwpcb() {
+  // CHECK-LABEL: @test_slwpcb
+  // CHECK: call i8* @llvm.x86.slwpcb()
+  return __slwpcb();
+}
+
+unsigned char test_lwpins32(unsigned val2, unsigned val1) {
+  // CHECK-LABEL: @test_lwpins32
+  // CHECK: call i8 @llvm.x86.lwpins32(i32
+  return __lwpins32(val2, val1, 0x01234);
+}
+
+unsigned char test_lwpins64(unsigned long long val2, unsigned val1) {
+  // CHECK-LABEL: @test_lwpins64
+  // CHECK: call i8 @llvm.x86.lwpins64(i64
+  return __lwpins64(val2, val1, 0x56789);
+}
+
+void test_lwpval32(unsigned val2, unsigned val1) {
+  // CHECK-LABEL: @test_lwpval32
+  // CHECK: call void @llvm.x86.lwpval32(i32
+  __lwpval32(val2, val1, 0x01234);
+}
+
+void test_lwpval64(unsigned long long val2, unsigned val1) {
+  // CHECK-LABEL: @test_lwpval64
+  // CHECK: call void @llvm.x86.lwpval64(i64
+  __lwpval64(val2, val1, 0xABCDEF);
+}
Index: lib/Headers/x86intrin.h
===
--- lib/Headers/x86intrin.h
+++ lib/Headers/x86intrin.h
@@ -72,6 +72,10 @@
 #include 
 #endif
 
+#if !defined(_MSC_VER) || __has_feature(modules) || defined(__LWP__)
+#include 
+#endif
+
 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__F16C__)
 #include 
 #endif
Index: lib/Headers/lwpintrin.h
===
--- lib/Headers/lwpintrin.h
+++ lib/Headers/lwpintrin.h
@@ -0,0 +1,150 @@
+/*=== lwpintrin.h - LWP intrinsics -===
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ *===---===
+ */
+
+#ifndef __X86INTRIN_H
+#error "Never use  directly; include  instead."
+#endif
+
+#ifndef __LWPINTRIN_H
+#define __LWPINTRIN_H
+
+/* Define the default attributes for the functions in this file. */
+#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lwp")))
+
+/// \brief Parses the LWPCB at the specified address and enables
+///profiling if valid.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  LLWPCB  instruction.
+///
+/// \param __addr
+///Address to the new Lightweight Profiling Control Block (LWPCB). If the
+///LWPCB is valid, writes the address into the LWP_CBADDR MSR and enables
+///Lightweight Profiling.
+static __inline__ void __DEFAULT_FN_ATTRS
+__llwpcb (void *__addr)
+{
+  __builtin_ia32_llwpcb(__addr);
+}
+
+/// \brief Flushes the LWP state to memory and returns the address of the LWPCB.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  SLWPCB  instruction.
+///
+/// \return
+///Address to the current Lightweight Profiling Control Block (LWPCB).
+///If LWP is not currently enabled, returns NULL.
+static __inline__ void* __DEFAULT_FN_ATTRS
+__slwpcb ()
+{
+  return __builtin_ia32_slwpcb();
+}
+
+/// \brief Inserts programmed event record into the LWP event ring buffer
+///and 

[PATCH] D32767: [clang-tidy] Fix PR32896: detect initializer lists in modernize-use-empalce

2017-05-02 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar created this revision.
kuhar added a project: clang-tools-extra.
Herald added a subscriber: xazax.hun.

This patch fixes PR32896 .

The problem was that modernize-use-emplace incorrectly removed changed 
push_back into emplace_back, removing explicit constructor call with 
initializer list parameter, resulting in compiler error after applying fixits.
modernize-use-emplace used to check if matched constructor had InitListExpr, 
but didn't check against CXXStdInitializerListExpr.

Eg.

  std::vector v;
v.push_back(std::vector({1})); // --> v.emplace_back({1});


https://reviews.llvm.org/D32767

Files:
  clang-tidy/modernize/UseEmplaceCheck.cpp
  test/clang-tidy/modernize-use-emplace.cpp


Index: test/clang-tidy/modernize-use-emplace.cpp
===
--- test/clang-tidy/modernize-use-emplace.cpp
+++ test/clang-tidy/modernize-use-emplace.cpp
@@ -4,9 +4,19 @@
 // RUN:   value: '::std::vector; ::std::list; ::std::deque; 
llvm::LikeASmallVector'}]}" -- -std=c++11
 
 namespace std {
+template 
+class initializer_list
+{
+public:
+  initializer_list() noexcept {}
+};
+
 template 
 class vector {
 public:
+  vector() = default;
+  vector(initializer_list) {}
+
   void push_back(const T &) {}
   void push_back(T &&) {}
 
@@ -455,3 +465,16 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
   // CHECK-FIXES: v.emplace_back(42);
 }
+
+void testInitializerList() {
+  std::vector v;
+  v.push_back(std::vector({1}));
+  // Test against the bug reported in PR32896.
+
+  v.push_back({{2}});
+
+  using PairIntVector = std::pair;
+  std::vector x;
+  x.push_back(PairIntVector(3, {4}));
+  x.push_back({5, {6}});
+}
Index: clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -20,6 +20,10 @@
   return Node.hasExplicitTemplateArgs();
 }
 
+AST_MATCHER(CXXStdInitializerListExpr, cxxStdInitializerListExpr) {
+  return true;
+}
+
 const auto DefaultContainersWithPushBack =
 "::std::vector; ::std::list; ::std::deque";
 const auto DefaultSmartPointers =
@@ -74,7 +78,8 @@
   // emplace_back can't access private constructor.
   auto IsPrivateCtor = hasDeclaration(cxxConstructorDecl(isPrivate()));
 
-  auto HasInitList = has(ignoringImplicit(initListExpr()));
+  auto HasInitList = anyOf(has(ignoringImplicit(initListExpr())),
+   has(cxxStdInitializerListExpr()));
   // FIXME: Discard 0/NULL (as nullptr), static inline const data members,
   // overloaded functions and template names.
   auto SoughtConstructExpr =


Index: test/clang-tidy/modernize-use-emplace.cpp
===
--- test/clang-tidy/modernize-use-emplace.cpp
+++ test/clang-tidy/modernize-use-emplace.cpp
@@ -4,9 +4,19 @@
 // RUN:   value: '::std::vector; ::std::list; ::std::deque; llvm::LikeASmallVector'}]}" -- -std=c++11
 
 namespace std {
+template 
+class initializer_list
+{
+public:
+  initializer_list() noexcept {}
+};
+
 template 
 class vector {
 public:
+  vector() = default;
+  vector(initializer_list) {}
+
   void push_back(const T &) {}
   void push_back(T &&) {}
 
@@ -455,3 +465,16 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
   // CHECK-FIXES: v.emplace_back(42);
 }
+
+void testInitializerList() {
+  std::vector v;
+  v.push_back(std::vector({1}));
+  // Test against the bug reported in PR32896.
+
+  v.push_back({{2}});
+
+  using PairIntVector = std::pair;
+  std::vector x;
+  x.push_back(PairIntVector(3, {4}));
+  x.push_back({5, {6}});
+}
Index: clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -20,6 +20,10 @@
   return Node.hasExplicitTemplateArgs();
 }
 
+AST_MATCHER(CXXStdInitializerListExpr, cxxStdInitializerListExpr) {
+  return true;
+}
+
 const auto DefaultContainersWithPushBack =
 "::std::vector; ::std::list; ::std::deque";
 const auto DefaultSmartPointers =
@@ -74,7 +78,8 @@
   // emplace_back can't access private constructor.
   auto IsPrivateCtor = hasDeclaration(cxxConstructorDecl(isPrivate()));
 
-  auto HasInitList = has(ignoringImplicit(initListExpr()));
+  auto HasInitList = anyOf(has(ignoringImplicit(initListExpr())),
+   has(cxxStdInitializerListExpr()));
   // FIXME: Discard 0/NULL (as nullptr), static inline const data members,
   // overloaded functions and template names.
   auto SoughtConstructExpr =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r301981 - Re-land r301697 "[IR] Make add/remove Attributes use AttrBuilder instead of AttributeList"

2017-05-02 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue May  2 17:07:37 2017
New Revision: 301981

URL: http://llvm.org/viewvc/llvm-project?rev=301981=rev
Log:
Re-land r301697 "[IR] Make add/remove Attributes use AttrBuilder instead of 
AttributeList"

This time, I fixed, built, and tested clang.

This reverts r301712.

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=301981=301980=301981=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue May  2 17:07:37 2017
@@ -1756,9 +1756,7 @@ void CodeGenModule::AddDefaultFnAttrs(ll
   ConstructDefaultFnAttrList(F.getName(),
  F.hasFnAttribute(llvm::Attribute::OptimizeNone),
  /* AttrOnCallsite = */ false, FuncAttrs);
-  llvm::AttributeList AS = llvm::AttributeList::get(
-  getLLVMContext(), llvm::AttributeList::FunctionIndex, FuncAttrs);
-  F.addAttributes(llvm::AttributeList::FunctionIndex, AS);
+  F.addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs);
 }
 
 void CodeGenModule::ConstructAttributeList(

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=301981=301980=301981=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue May  2 17:07:37 2017
@@ -892,10 +892,7 @@ void CodeGenModule::SetLLVMFunctionAttri
 CodeGenOpts.getInlining() == CodeGenOptions::OnlyAlwaysInlining)
   B.addAttribute(llvm::Attribute::NoInline);
 
-F->addAttributes(
-llvm::AttributeList::FunctionIndex,
-llvm::AttributeList::get(F->getContext(),
- llvm::AttributeList::FunctionIndex, B));
+F->addAttributes(llvm::AttributeList::FunctionIndex, B);
 return;
   }
 
@@ -961,9 +958,7 @@ void CodeGenModule::SetLLVMFunctionAttri
   B.addAttribute(llvm::Attribute::MinSize);
   }
 
-  F->addAttributes(llvm::AttributeList::FunctionIndex,
-   llvm::AttributeList::get(
-   F->getContext(), llvm::AttributeList::FunctionIndex, 
B));
+  F->addAttributes(llvm::AttributeList::FunctionIndex, B);
 
   unsigned alignment = D->getMaxAlignment() / Context.getCharWidth();
   if (alignment)
@@ -2029,9 +2024,7 @@ llvm::Constant *CodeGenModule::GetOrCrea
 SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk);
   if (ExtraAttrs.hasAttributes(llvm::AttributeList::FunctionIndex)) {
 llvm::AttrBuilder B(ExtraAttrs, llvm::AttributeList::FunctionIndex);
-F->addAttributes(llvm::AttributeList::FunctionIndex,
- llvm::AttributeList::get(
- VMContext, llvm::AttributeList::FunctionIndex, B));
+F->addAttributes(llvm::AttributeList::FunctionIndex, B);
   }
 
   if (!DontDefer) {

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=301981=301980=301981=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Tue May  2 17:07:37 2017
@@ -1901,10 +1901,7 @@ void X86_32TargetCodeGenInfo::setTargetA
   // Now add the 'alignstack' attribute with a value of 16.
   llvm::AttrBuilder B;
   B.addStackAlignmentAttr(16);
-  Fn->addAttributes(
-  llvm::AttributeList::FunctionIndex,
-  llvm::AttributeList::get(CGM.getLLVMContext(),
-   llvm::AttributeList::FunctionIndex, B));
+  Fn->addAttributes(llvm::AttributeList::FunctionIndex, B);
 }
 if (FD->hasAttr()) {
   llvm::Function *Fn = cast(GV);
@@ -5449,10 +5446,7 @@ public:
 // the backend to perform a realignment as part of the function prologue.
 llvm::AttrBuilder B;
 B.addStackAlignmentAttr(8);
-Fn->addAttributes(
-llvm::AttributeList::FunctionIndex,
-llvm::AttributeList::get(CGM.getLLVMContext(),
- llvm::AttributeList::FunctionIndex, B));
+Fn->addAttributes(llvm::AttributeList::FunctionIndex, B);
   }
 };
 


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


[PATCH] D32759: Fix errored return value in CheckFunctionReturnType and add a fixit hint

2017-05-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In https://reviews.llvm.org/D32759#743860, @rnk wrote:

> On cfe-dev you said "There IS a case in our tests where it would hit such an 
> assertion". Does "our tests" here refer to the existing clang tests or Intel 
> tests? I just want to make sure we have coverage of this codepath in the test 
> suite. I don't care that much about crafting a test case that shows the 
> behavior difference of fixing the return value.


Ah, sorry.  "Our Tests" means the lit test SemaObjC/method-bad-param.m (line 
11).  I ran the lit tests initially with a breakpoint on this line and it never 
hit, though I must have set up the debugger wrong.  Once I replaced it with an 
assert, method-bad-param failed.


https://reviews.llvm.org/D32759



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


[PATCH] D32759: Fix errored return value in CheckFunctionReturnType and add a fixit hint

2017-05-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

On cfe-dev you said "There IS a case in our tests where it would hit such an 
assertion". Does "our tests" here refer to the existing clang tests or Intel 
tests? I just want to make sure we have coverage of this codepath in the test 
suite. I don't care that much about crafting a test case that shows the 
behavior difference of fixing the return value.


https://reviews.llvm.org/D32759



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


[PATCH] D32761: Fix bugs checking va_start in lambdas and erroneous contexts

2017-05-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk created this revision.

First, getCurFunction looks through blocks and lambdas, which is wrong.
Inside a lambda, va_start should refer to the lambda call operator
prototype. This fixes PR32737.

Second, we shouldn't use any of the getCur* methods, because they look
through contexts that we don't want to look through (EnumDecl,
CapturedStmtDecl). We can use CurContext directly as the calling
context.

Finally, this code assumed that CallExprs would never appear outside of
code contexts (block, function, obj-c method), which is wrong. Struct
member initializers are an easy way to create and parse exprs in a
non-code context.


https://reviews.llvm.org/D32761

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/OpenMP/varargs.cpp
  clang/test/SemaCXX/varargs.cpp

Index: clang/test/SemaCXX/varargs.cpp
===
--- clang/test/SemaCXX/varargs.cpp
+++ clang/test/SemaCXX/varargs.cpp
@@ -1,12 +1,59 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++03 -verify %s
+// RUN: %clang_cc1 -std=c++03 -verify %s
+// RUN: %clang_cc1 -std=c++11 -verify %s
+
+__builtin_va_list ap;
 
 class string;
 void f(const string& s, ...) {  // expected-note {{parameter of type 'const string &' is declared here}}
-  __builtin_va_list ap;
   __builtin_va_start(ap, s); // expected-warning {{passing an object of reference type to 'va_start' has undefined behavior}}
 }
 
 void g(register int i, ...) {
-  __builtin_va_list ap;
-  __builtin_va_start(ap, i); // okay
+  __builtin_va_start(ap, i); // UB in C, OK in C++
+}
+
+// Don't crash when there is no last parameter.
+void no_params(...) {
+  int a;
+  __builtin_va_start(ap, a); // expected-warning {{second argument to 'va_start' is not the last named parameter}}
+}
+
+// Reject this. The __builtin_va_start would execute in Foo's non-variadic
+// default ctor.
+void record_context(int a, ...) {
+  struct Foo {
+// expected-error@+1 {{'va_start' cannot be used outside a function}}
+void meth(int a, int b = (__builtin_va_start(ap, a), 0)) {}
+  };
+}
+
+#if __cplusplus >= 201103L
+// We used to have bugs identifying the correct enclosing function scope in a
+// lambda.
+
+void fixed_lambda_varargs_function(int a, ...) {
+  [](int b) {
+__builtin_va_start(ap, b); // expected-error {{'va_start' used in function with fixed args}}
+  }(42);
+}
+void varargs_lambda_fixed_function(int a) {
+  [](int b, ...) {
+__builtin_va_start(ap, b); // correct
+  }(42);
+}
+
+auto fixed_lambda_global = [](int f) {
+  __builtin_va_start(ap, f); // expected-error {{'va_start' used in function with fixed args}}
+};
+auto varargs_lambda_global = [](int f, ...) {
+  __builtin_va_start(ap, f); // correct
+};
+
+void record_member_init(int a, ...) {
+  struct Foo {
+int a = 0;
+// expected-error@+1 {{'va_start' cannot be used outside a function}}
+int b = (__builtin_va_start(ap, a), 0);
+  };
 }
+#endif
Index: clang/test/OpenMP/varargs.cpp
===
--- /dev/null
+++ clang/test/OpenMP/varargs.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify -fopenmp %s
+void f(int a, ...) {
+#pragma omp parallel for
+  for (int i = 0; i < 100; ++i) {
+__builtin_va_list ap;
+__builtin_va_start(ap, a); // expected-error {{'va_start' cannot be used in a captured statement}}
+  }
+};
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3652,22 +3652,29 @@
   // and get its parameter list.
   bool IsVariadic = false;
   ArrayRef Params;
-  if (BlockScopeInfo *CurBlock = S.getCurBlock()) {
-IsVariadic = CurBlock->TheDecl->isVariadic();
-Params = CurBlock->TheDecl->parameters();
-  } else if (FunctionDecl *FD = S.getCurFunctionDecl()) {
+  DeclContext *Caller = S.CurContext;
+  if (auto *Block = dyn_cast(Caller)) {
+IsVariadic = Block->isVariadic();
+Params = Block->parameters();
+  } else if (auto *FD = dyn_cast(Caller)) {
 IsVariadic = FD->isVariadic();
 Params = FD->parameters();
-  } else if (ObjCMethodDecl *MD = S.getCurMethodDecl()) {
+  } else if (auto *MD = dyn_cast(Caller)) {
 IsVariadic = MD->isVariadic();
 // FIXME: This isn't correct for methods (results in bogus warning).
 Params = MD->parameters();
+  } else if (isa(Caller)) {
+// We don't support va_start in a CapturedDecl.
+S.Diag(Fn->getLocStart(), diag::err_va_start_captured_stmt);
+return true;
   } else {
-llvm_unreachable("unknown va_start context");
+// This must be some other declcontext that parses exprs.
+S.Diag(Fn->getLocStart(), diag::err_va_start_outside_function);
+return true;
   }
 
   if (!IsVariadic) {
-S.Diag(Fn->getLocStart(), diag::err_va_start_used_in_non_variadic_function);
+S.Diag(Fn->getLocStart(), diag::err_va_start_fixed_function);
 return true;
   }

[PATCH] D32613: [Driver] Update Fuchsia driver path handling

2017-05-02 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr added a comment.

Perhaps use llvm::sys::path::parent_path instead of explicit "..".
Perhaps put the getDriver.Dir() + .. + getTriple().str() logic into a shared 
subroutine.

Use default rather that CST_Libstdcxx in the switches on GetCXXStdlibType.


Repository:
  rL LLVM

https://reviews.llvm.org/D32613



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


r301973 - [NFC] Add original test that triggered crash post r301735

2017-05-02 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Tue May  2 16:02:46 2017
New Revision: 301973

URL: http://llvm.org/viewvc/llvm-project?rev=301973=rev
Log:
[NFC] Add original test that triggered crash post r301735 
- this is added just for completeness sake (though the general case should be 
represented by the test added in the revision to that patch:  
https://reviews.llvm.org/rL301972 )

Modified:
cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp?rev=301973=301972=301973=diff
==
--- cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp Tue May  2 16:02:46 
2017
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety %s
 // RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++98 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++11 %s -D CPP11
 
 #define LOCKABLE__attribute__ ((lockable))
 #define SCOPED_LOCKABLE __attribute__ ((scoped_lockable))
@@ -1513,3 +1513,15 @@ public:
 
 }  // end namespace FunctionAttributesInsideClass_ICE_Test
 
+
+#ifdef CPP11
+namespace CRASH_POST_R301735 {
+  class SomeClass {
+   public:
+ void foo() {
+   auto l = [this] { auto l = [] () EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
+ }
+ Mutex mu_;
+   };
+}
+#endif
\ No newline at end of file


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


r301972 - Fix PR32831 (Try Again): 'this' capture while instantiating generic lambda call operator specialization

2017-05-02 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Tue May  2 15:56:34 2017
New Revision: 301972

URL: http://llvm.org/viewvc/llvm-project?rev=301972=rev
Log:
Fix PR32831 (Try Again): 'this' capture while instantiating generic lambda call 
operator specialization

When computing the appropriate cv-qualifiers for the 'this' capture, we have to 
examine each enclosing lambda - but when using the FunctionScopeInfo stack we 
have to ensure that the lambda below (outer) is the decl-context of the 
closure-class of the current lambda.

https://bugs.llvm.org/show_bug.cgi?id=32831

This patch was initially committed here: https://reviews.llvm.org/rL301735
Then reverted here: https://reviews.llvm.org/rL301916

The issue with the original patch was a failure to check that the closure type 
has been created within the LambdaScopeInfo before querying its DeclContext - 
instead of just assuming it has (silly!).  A reduced example such as this 
highlights the problem:
  struct X {
 int data;
 auto foo() { return [] { return [] -> decltype(data) { return 0; }; }; }
  };

When 'data' within decltype(data) tries to determine the type of 'this', none 
of the LambdaScopeInfo's have their closure types created at that point.

 

Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=301972=301971=301972=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue May  2 15:56:34 2017
@@ -901,17 +901,36 @@ static QualType adjustCVQualifiersForCXX
   // capturing lamdbda's call operator.
   //
 
-  // The issue is that we cannot rely entirely on the FunctionScopeInfo stack
-  // since ScopeInfos are pushed on during parsing and treetransforming. But
-  // since a generic lambda's call operator can be instantiated anywhere (even
-  // end of the TU) we need to be able to examine its enclosing lambdas and so
-  // we use the DeclContext to get a hold of the closure-class and query it for
-  // capture information.  The reason we don't just resort to always using the
-  // DeclContext chain is that it is only mature for lambda expressions
-  // enclosing generic lambda's call operators that are being instantiated.
+  // Since the FunctionScopeInfo stack is representative of the lexical
+  // nesting of the lambda expressions during initial parsing (and is the best
+  // place for querying information about captures about lambdas that are
+  // partially processed) and perhaps during instantiation of function 
templates
+  // that contain lambda expressions that need to be transformed BUT not
+  // necessarily during instantiation of a nested generic lambda's function 
call
+  // operator (which might even be instantiated at the end of the TU) - at 
which
+  // time the DeclContext tree is mature enough to query capture information
+  // reliably - we use a two pronged approach to walk through all the lexically
+  // enclosing lambda expressions:
+  //
+  //  1) Climb down the FunctionScopeInfo stack as long as each item represents
+  //  a Lambda (i.e. LambdaScopeInfo) AND each LSI's 'closure-type' is 
lexically
+  //  enclosed by the call-operator of the LSI below it on the stack (while
+  //  tracking the enclosing DC for step 2 if needed).  Note the topmost LSI on
+  //  the stack represents the innermost lambda.
+  //
+  //  2) If we run out of enclosing LSI's, check if the enclosing DeclContext
+  //  represents a lambda's call operator.  If it does, we must be 
instantiating
+  //  a generic lambda's call operator (represented by the Current LSI, and
+  //  should be the only scenario where an inconsistency between the LSI and 
the
+  //  DeclContext should occur), so climb out the DeclContexts if they
+  //  represent lambdas, while querying the corresponding closure types
+  //  regarding capture information.
 
+  // 1) Climb down the function scope info stack.
   for (int I = FunctionScopes.size();
-   I-- && isa(FunctionScopes[I]);
+   I-- && isa(FunctionScopes[I]) &&
+   (!CurLSI || !CurLSI->Lambda || CurLSI->Lambda->getDeclContext() ==
+   cast(FunctionScopes[I])->CallOperator);
CurDC = getLambdaAwareParentOfDeclContext(CurDC)) {
 CurLSI = cast(FunctionScopes[I]);
 
@@ -927,11 +946,17 @@ static QualType adjustCVQualifiersForCXX
   return ASTCtx.getPointerType(ClassType);
 }
   }
-  // We've run out of ScopeInfos but check if CurDC is a lambda (which can
-  // happen during instantiation of generic lambdas)
+
+  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
+  // happen during instantiation of its nested generic lambda call operator)
   if (isLambdaCallOperator(CurDC)) {
-assert(CurLSI);
-assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator));
+

[PATCH] D32759: Fix errored return value in CheckFunctionReturnType and add a

2017-05-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.

https://reviews.llvm.org/D32759

Files:
  lib/Sema/SemaType.cpp


Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2285,8 +2285,9 @@
   // Methods cannot return interface types. All ObjC objects are
   // passed by reference.
   if (T->isObjCObjectType()) {
-Diag(Loc, diag::err_object_cannot_be_passed_returned_by_value) << 0 << T;
-return 0;
+Diag(Loc, diag::err_object_cannot_be_passed_returned_by_value)
+<< 0 << T << FixItHint::CreateInsertion(Loc, "*");
+return true;
   }
 
   return false;


Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2285,8 +2285,9 @@
   // Methods cannot return interface types. All ObjC objects are
   // passed by reference.
   if (T->isObjCObjectType()) {
-Diag(Loc, diag::err_object_cannot_be_passed_returned_by_value) << 0 << T;
-return 0;
+Diag(Loc, diag::err_object_cannot_be_passed_returned_by_value)
+<< 0 << T << FixItHint::CreateInsertion(Loc, "*");
+return true;
   }
 
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r301963 - Revert r301822 (and dependent r301825), which tried to improve the

2017-05-02 Thread Richard Smith via cfe-commits
On 2 May 2017 at 12:21, Daniel Jasper via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: djasper
> Date: Tue May  2 14:21:42 2017
> New Revision: 301963
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301963=rev
> Log:
> Revert r301822 (and dependent r301825), which tried to improve the
> handling of constexprs with unknown bounds.
>
> This triggers a corner case of the language where it's not yet clear
> whether this should be an error:
>
>   struct A {
> static void *const a[];
> static void *const b[];
>   };
>   constexpr void *A::a[] = {[0]};
>   constexpr void *A::b[] = {[0]};
>
> When discovering the initializer for A::a, the bounds of A::b aren't known
> yet.
> It is unclear whether warning about errors should be deferred until the
> end of
> the translation unit, possibly resolving errors that can be resolved. In
> practice, the compiler can know the bounds of all arrays in this example.
>

I've started a discussion on the C++ core reflector about this.


> Credits for reproducers and explanation go to Richard Smith. Richard,
> please
> add more info in case my explanation is wrong.
>
> Removed:
> cfe/trunk/test/SemaCXX/constexpr-array-unknown-bound.cpp
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
> cfe/trunk/lib/AST/ExprConstant.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticASTKinds.td?rev=301963=301962=301963=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Tue May  2
> 14:21:42 2017
> @@ -154,14 +154,12 @@ def note_constexpr_baa_insufficient_alig
>  def note_constexpr_baa_value_insufficient_alignment : Note<
>"value of the aligned pointer (%0) is not a multiple of the asserted %1
> "
>"%plural{1:byte|:bytes}1">;
> -def note_constexpr_array_unknown_bound_arithmetic : Note<
> -  "cannot perform pointer arithmetic on pointer to array without constant
> bound">;
>
>  def warn_integer_constant_overflow : Warning<
>"overflow in expression; result is %0 with type %1">,
>InGroup>;
>
> -// This is a temporary diagnostic, and shall be removed once our
> +// This is a temporary diagnostic, and shall be removed once our
>  // implementation is complete, and like the preceding constexpr notes
> belongs
>  // in Sema.
>  def note_unimplemented_constexpr_lambda_feature_ast : Note<
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ExprConstant.cpp?rev=301963=301962=301963=diff
> 
> ==
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Tue May  2 14:21:42 2017
> @@ -148,8 +148,7 @@ namespace {
>static unsigned
>findMostDerivedSubobject(ASTContext , APValue::LValueBase Base,
> ArrayRef Path,
> -   uint64_t , QualType , bool
> ,
> -   bool ) {
> +   uint64_t , QualType , bool
> ) {
>  // This only accepts LValueBases from APValues, and APValues don't
> support
>  // arrays that lack size info.
>  assert(!isBaseAnAllocSizeCall(Base) &&
> @@ -158,34 +157,28 @@ namespace {
>  Type = getType(Base);
>
>  for (unsigned I = 0, N = Path.size(); I != N; ++I) {
> -  if (auto AT = Ctx.getAsArrayType(Type)) {
> +  if (Type->isArrayType()) {
> +const ConstantArrayType *CAT =
> +cast(Ctx.getAsArrayType(Type));
> +Type = CAT->getElementType();
> +ArraySize = CAT->getSize().getZExtValue();
>  MostDerivedLength = I + 1;
>  IsArray = true;
> -if (auto CAT = Ctx.getAsConstantArrayType(Type))
> -  ArraySize = CAT->getSize().getZExtValue();
> -else {
> -  ArraySize = 0;
> -  IsUnsizedArray = true;
> -}
> -Type = AT->getElementType();
>} else if (Type->isAnyComplexType()) {
>  const ComplexType *CT = Type->castAs();
>  Type = CT->getElementType();
>  ArraySize = 2;
>  MostDerivedLength = I + 1;
>  IsArray = true;
> -IsUnsizedArray = false;
>} else if (const FieldDecl *FD = getAsField(Path[I])) {
>  Type = FD->getType();
>  ArraySize = 0;
>  MostDerivedLength = I + 1;
>  IsArray = false;
> -IsUnsizedArray = false;
>} else {
>  // Path[I] describes a base class.
>  ArraySize = 0;
>  IsArray = false;
> -IsUnsizedArray = false;
>}
>  }
>  return MostDerivedLength;
> @@ -207,9 +200,8 @@ namespace {
>  /// Is this a pointer one past the end of an object?
>  unsigned IsOnePastTheEnd : 1;

r301970 - [Sema] Update function doc; NFC

2017-05-02 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Tue May  2 15:24:56 2017
New Revision: 301970

URL: http://llvm.org/viewvc/llvm-project?rev=301970=rev
Log:
[Sema] Update function doc; NFC

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=301970=301969=301970=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue May  2 15:24:56 2017
@@ -15372,7 +15372,7 @@ static ExprResult diagnoseUnknownAnyExpr
 }
 
 /// Check for operands with placeholder types and complain if found.
-/// Returns true if there was an error and no recovery was possible.
+/// Returns ExprError() if there was an error and no recovery was possible.
 ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
   if (!getLangOpts().CPlusPlus) {
 // C cannot handle TypoExpr nodes on either side of a binop because it


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


r301968 - Simplify some va_start checking logic

2017-05-02 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue May  2 15:10:03 2017
New Revision: 301968

URL: http://llvm.org/viewvc/llvm-project?rev=301968=rev
Log:
Simplify some va_start checking logic

Combine the logic doing the ms_abi/sysv_abi checks into one function so
that each check and its logical opposite are near each other. Now we
don't need two Sema entry points for MS va_start and regular va_start.

Refactor the code that checks if the va_start caller is a function,
block, or obj-c method. We do this in three places, and they are all
buggy for variadic lambdas (PR32737). After this change, I have one
place to apply the functional fix.

NFC

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/varargs.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=301968=301967=301968=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May  2 15:10:03 
2017
@@ -8048,7 +8048,7 @@ def err_64_bit_builtin_32_bit_tgt : Erro
   "this builtin is only available on 64-bit targets">;
 def err_ppc_builtin_only_on_pwr7 : Error<
   "this builtin is only valid on POWER7 or later CPUs">;
-def err_x86_builtin_32_bit_tgt : Error<
+def err_x86_builtin_64_only : Error<
   "this builtin is only available on x86-64 targets">;
 def err_x86_builtin_invalid_rounding : Error<
   "invalid rounding argument">;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=301968=301967=301968=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue May  2 15:10:03 2017
@@ -10068,9 +10068,7 @@ private:
   bool CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   bool CheckPPCBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
 
-  bool SemaBuiltinVAStartImpl(CallExpr *TheCall);
-  bool SemaBuiltinVAStart(CallExpr *TheCall);
-  bool SemaBuiltinMSVAStart(CallExpr *TheCall);
+  bool SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall);
   bool SemaBuiltinVAStartARM(CallExpr *Call);
   bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
   bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=301968=301967=301968=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue May  2 15:10:03 2017
@@ -759,7 +759,7 @@ Sema::CheckBuiltinFunctionCall(FunctionD
 break;
   case Builtin::BI__builtin_stdarg_start:
   case Builtin::BI__builtin_va_start:
-if (SemaBuiltinVAStart(TheCall))
+if (SemaBuiltinVAStart(BuiltinID, TheCall))
   return ExprError();
 break;
   case Builtin::BI__va_start: {
@@ -770,7 +770,7 @@ Sema::CheckBuiltinFunctionCall(FunctionD
 return ExprError();
   break;
 default:
-  if (SemaBuiltinVAStart(TheCall))
+  if (SemaBuiltinVAStart(BuiltinID, TheCall))
 return ExprError();
   break;
 }
@@ -2090,7 +2090,7 @@ bool Sema::CheckX86BuiltinFunctionCall(u
 return SemaBuiltinCpuSupports(*this, TheCall);
 
   if (BuiltinID == X86::BI__builtin_ms_va_start)
-return SemaBuiltinMSVAStart(TheCall);
+return SemaBuiltinVAStart(BuiltinID, TheCall);
 
   // If the intrinsic has rounding or SAE make sure its valid.
   if (CheckX86BuiltinRoundingOrSAE(BuiltinID, TheCall))
@@ -3611,11 +3611,81 @@ ExprResult Sema::CheckOSLogFormatStringA
   return Result;
 }
 
+/// Check that the user is calling the appropriate va_start builtin for the
+/// target and calling convention.
+static bool checkVAStartABI(Sema , unsigned BuiltinID, Expr *Fn) {
+  const llvm::Triple  = S.Context.getTargetInfo().getTriple();
+  bool IsX64 = TT.getArch() == llvm::Triple::x86_64;
+  bool IsWindows = TT.isOSWindows();
+  bool IsMSVAStart = BuiltinID == X86::BI__builtin_ms_va_start;
+  if (IsX64) {
+clang::CallingConv CC = CC_C;
+if (const FunctionDecl *FD = S.getCurFunctionDecl())
+  CC = FD->getType()->getAs()->getCallConv();
+if (IsMSVAStart) {
+  // Don't allow this in System V ABI functions.
+  if (CC == CC_X86_64SysV || (!IsWindows && CC != CC_X86_64Win64))
+return S.Diag(Fn->getLocStart(),
+  diag::err_ms_va_start_used_in_sysv_function);
+} else {
+  // On x86-64 Unix, don't allow this in Win64 ABI functions.
+  // On x64 Windows, don't allow this in System V ABI functions.
+  // (Yes, that means there's no 

r301963 - Revert r301822 (and dependent r301825), which tried to improve the

2017-05-02 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue May  2 14:21:42 2017
New Revision: 301963

URL: http://llvm.org/viewvc/llvm-project?rev=301963=rev
Log:
Revert r301822 (and dependent r301825), which tried to improve the
handling of constexprs with unknown bounds.

This triggers a corner case of the language where it's not yet clear
whether this should be an error:

  struct A {
static void *const a[];
static void *const b[];
  };
  constexpr void *A::a[] = {[0]};
  constexpr void *A::b[] = {[0]};

When discovering the initializer for A::a, the bounds of A::b aren't known yet.
It is unclear whether warning about errors should be deferred until the end of
the translation unit, possibly resolving errors that can be resolved. In
practice, the compiler can know the bounds of all arrays in this example.

Credits for reproducers and explanation go to Richard Smith. Richard, please
add more info in case my explanation is wrong.

Removed:
cfe/trunk/test/SemaCXX/constexpr-array-unknown-bound.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=301963=301962=301963=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Tue May  2 14:21:42 2017
@@ -154,14 +154,12 @@ def note_constexpr_baa_insufficient_alig
 def note_constexpr_baa_value_insufficient_alignment : Note<
   "value of the aligned pointer (%0) is not a multiple of the asserted %1 "
   "%plural{1:byte|:bytes}1">;
-def note_constexpr_array_unknown_bound_arithmetic : Note<
-  "cannot perform pointer arithmetic on pointer to array without constant 
bound">;
 
 def warn_integer_constant_overflow : Warning<
   "overflow in expression; result is %0 with type %1">,
   InGroup>;
 
-// This is a temporary diagnostic, and shall be removed once our
+// This is a temporary diagnostic, and shall be removed once our 
 // implementation is complete, and like the preceding constexpr notes belongs
 // in Sema.
 def note_unimplemented_constexpr_lambda_feature_ast : Note<

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=301963=301962=301963=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue May  2 14:21:42 2017
@@ -148,8 +148,7 @@ namespace {
   static unsigned
   findMostDerivedSubobject(ASTContext , APValue::LValueBase Base,
ArrayRef Path,
-   uint64_t , QualType , bool ,
-   bool ) {
+   uint64_t , QualType , bool ) 
{
 // This only accepts LValueBases from APValues, and APValues don't support
 // arrays that lack size info.
 assert(!isBaseAnAllocSizeCall(Base) &&
@@ -158,34 +157,28 @@ namespace {
 Type = getType(Base);
 
 for (unsigned I = 0, N = Path.size(); I != N; ++I) {
-  if (auto AT = Ctx.getAsArrayType(Type)) {
+  if (Type->isArrayType()) {
+const ConstantArrayType *CAT =
+cast(Ctx.getAsArrayType(Type));
+Type = CAT->getElementType();
+ArraySize = CAT->getSize().getZExtValue();
 MostDerivedLength = I + 1;
 IsArray = true;
-if (auto CAT = Ctx.getAsConstantArrayType(Type))
-  ArraySize = CAT->getSize().getZExtValue();
-else {
-  ArraySize = 0;
-  IsUnsizedArray = true;
-}
-Type = AT->getElementType();
   } else if (Type->isAnyComplexType()) {
 const ComplexType *CT = Type->castAs();
 Type = CT->getElementType();
 ArraySize = 2;
 MostDerivedLength = I + 1;
 IsArray = true;
-IsUnsizedArray = false;
   } else if (const FieldDecl *FD = getAsField(Path[I])) {
 Type = FD->getType();
 ArraySize = 0;
 MostDerivedLength = I + 1;
 IsArray = false;
-IsUnsizedArray = false;
   } else {
 // Path[I] describes a base class.
 ArraySize = 0;
 IsArray = false;
-IsUnsizedArray = false;
   }
 }
 return MostDerivedLength;
@@ -207,9 +200,8 @@ namespace {
 /// Is this a pointer one past the end of an object?
 unsigned IsOnePastTheEnd : 1;
 
-/// Indicator of whether the most-derived object is an unsized array (e.g.
-/// of unknown bound).
-unsigned MostDerivedIsAnUnsizedArray : 1;
+/// Indicator of whether the first entry is an unsized array.
+unsigned FirstEntryIsAnUnsizedArray : 1;
 
 /// Indicator of whether the most-derived object is an array element.
 unsigned MostDerivedIsArrayElement : 1;
@@ 

r301960 - Revert "[docs] UBSan: Mention that print_stacktrace=1 is unsupported on Darwin"

2017-05-02 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Tue May  2 13:51:41 2017
New Revision: 301960

URL: http://llvm.org/viewvc/llvm-project?rev=301960=rev
Log:
Revert "[docs] UBSan: Mention that print_stacktrace=1 is unsupported on Darwin"

This reverts commit r300295.

It's no longer true, print_stacktrace=1 is supported on Darwin/Windows
as of r301839.

Modified:
cfe/trunk/docs/UndefinedBehaviorSanitizer.rst

Modified: cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UndefinedBehaviorSanitizer.rst?rev=301960=301959=301960=diff
==
--- cfe/trunk/docs/UndefinedBehaviorSanitizer.rst (original)
+++ cfe/trunk/docs/UndefinedBehaviorSanitizer.rst Tue May  2 13:51:41 2017
@@ -157,8 +157,6 @@ will need to:
``UBSAN_OPTIONS=print_stacktrace=1``.
 #. Make sure ``llvm-symbolizer`` binary is in ``PATH``.
 
-Stacktrace printing for UBSan issues is currently not supported on Darwin.
-
 Issue Suppression
 =
 


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


[PATCH] D32690: [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

2017-05-02 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

i like the generalization.




Comment at: clang-tidy/modernize/UseEmplaceCheck.cpp:115
unless(isInTemplateInstantiation()))
  .bind("call"),
  this);

i think `this);` should move up a line. clang-format seems to make this all the 
time. 


https://reviews.llvm.org/D32690



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


[PATCH] D32743: [clang-tidy] Add new cert-dcl21-cpp check.

2017-05-02 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

We have misc-unconventional-assign-operator and google-runtime-operator checks 
already. Form user perspective, I think will be good idea to have single check 
for different operators.




Comment at: docs/ReleaseNotes.rst:63
+
+  Checks if the overloaded postfix ``++`` and ``--`` operator return a 
constant object.
+

JonasToth wrote:
> i think the use of `operator++/--` would be better, like in the doc page.
Either it should be operator return**s**, or operator**s** return


Repository:
  rL LLVM

https://reviews.llvm.org/D32743



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


[PATCH] D32743: [clang-tidy] Add new cert-dcl21-cpp check.

2017-05-02 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/cert/PostfixOperatorCheck.cpp:27
+hasOverloadedOperatorName("--")))
+ .bind("decl"),
+ this);

could the `,this);` be on this line? seems odd.



Comment at: clang-tidy/cert/PostfixOperatorCheck.cpp:43
+  SourceRange ReturnRange = FuncDecl->getReturnTypeSourceRange();
+  auto Location = ReturnRange.getBegin();
+  if (!Location.isValid() || Location.isMacroID())

`Location` may be `const`



Comment at: clang-tidy/cert/PostfixOperatorCheck.cpp:47
+
+  QualType ReturnType = FuncDecl->getReturnType();
+

`ReturnType` may be `const`



Comment at: clang-tidy/cert/PostfixOperatorCheck.cpp:49
+
+  // Warn when the opeators return a reference.
+  if (ReturnType->isReferenceType()) {

typo. s/opeators/operators/, s/return/returns/



Comment at: clang-tidy/cert/PostfixOperatorCheck.cpp:50
+  // Warn when the opeators return a reference.
+  if (ReturnType->isReferenceType()) {
+auto Diag = diag(Location,

just out of curiosity, why does `->` work here? In line 47 the `QualType 
ReturnType` is not a pointer.



Comment at: clang-tidy/cert/PostfixOperatorCheck.cpp:56
+QualType ReplaceType =
+ReturnType.getNonReferenceType().getLocalUnqualifiedType();
+// The getReturnTypeSourceRange omits the qualifiers. We do not want to

here `.` is used instead `->` iam confused :D



Comment at: clang-tidy/cert/PostfixOperatorCheck.cpp:69
+
+  if (ReturnType.isConstQualified())
+return;

same confusion like above.
this seems to be an `else if`. If not, what happens in the `else` path of the 
bigger if? is it unreachable or a case that would just be ignored.



Comment at: clang-tidy/cert/PostfixOperatorCheck.cpp:72
+
+  diag(Location, "return type of overloaded %0 is not a constant type")
+  << FuncDecl << FixItHint::CreateInsertion(Location, "const ");

for clarity, this could be an else path to the if in line 69.
The if could check on the negation as well, and fix only in that case. (kinda 
swap the logic). I think that would be clearer.



Comment at: docs/ReleaseNotes.rst:63
+
+  Checks if the overloaded postfix ``++`` and ``--`` operator return a 
constant object.
+

i think the use of `operator++/--` would be better, like in the doc page.


Repository:
  rL LLVM

https://reviews.llvm.org/D32743



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


[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)

2017-05-02 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin created this revision.
Herald added subscribers: rengolin, aemerson.

Support new  AST nodes:

- UnresolvedUsingType
- EmptyDecl
- NamespaceAliasDecl
- UsingDecl
- UsingShadowDecl
- UsingDirectiveDecl
- UnresolvedUsingValueDecl
- UnresolvedUsingTypenameDecl

Refactor error handling in ImportTemplateArgumentLoc() method.
Add a test for inline namespaces.

Please take a look at FIXMEs I left in some places where I'm not sure that I 
have chosen a correct solution.
Also, I have some doubts for duplicating NamespaceAliasDecls. I found presence 
of such decls harmless but maybe I'm not correct here. I left NOTE comments 
both in the patch and in the tests for it.


https://reviews.llvm.org/D32751

Files:
  lib/AST/ASTImporter.cpp
  test/ASTMerge/namespace/Inputs/namespace1.cpp
  test/ASTMerge/namespace/Inputs/namespace2.cpp
  test/ASTMerge/namespace/test.cpp

Index: test/ASTMerge/namespace/test.cpp
===
--- test/ASTMerge/namespace/test.cpp
+++ test/ASTMerge/namespace/test.cpp
@@ -1,6 +1,17 @@
-// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/namespace1.cpp
-// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/namespace2.cpp
-// RUN: not %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.1.ast %S/Inputs/namespace1.cpp
+// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.2.ast %S/Inputs/namespace2.cpp
+// RUN: not %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
+
+static_assert(TestAliasName::z == 4);
+static_assert(ContainsInline::z == 10);
+
+void testImport() {
+  typedef TestUnresolvedTypenameAndValueDecls::Derived Imported;
+  Imported a; // Successfull instantiation
+  static_assert(sizeof(Imported::foo) == sizeof(int));
+  static_assert(sizeof(TestUnresolvedTypenameAndValueDecls::Derived::NewUnresolvedUsingType) == sizeof(double));
+}
+
 
 // CHECK: namespace2.cpp:16:17: error: external variable 'z' declared with incompatible types in different translation units ('double' vs. 'float')
 // CHECK: namespace1.cpp:16:16: note: declared here with type 'float'
Index: test/ASTMerge/namespace/Inputs/namespace2.cpp
===
--- test/ASTMerge/namespace/Inputs/namespace2.cpp
+++ test/ASTMerge/namespace/Inputs/namespace2.cpp
@@ -15,3 +15,46 @@
 namespace N3 {
   extern double z;
 }
+
+namespace Enclosing {
+namespace Nested {
+  const int z = 4;
+}
+}
+
+namespace ContainsInline {
+  inline namespace Inline {
+const int z = 10;
+  }
+}
+
+namespace TestAliasName = Enclosing::Nested;
+// NOTE: There is no warning on this alias.
+namespace AliasWithSameName = Enclosing::Nested;
+
+namespace TestUsingDecls {
+
+namespace A {
+void foo();
+}
+namespace B {
+using A::foo; // <- a UsingDecl creating a UsingShadow
+}
+
+}// end namespace TestUsingDecls
+
+namespace TestUnresolvedTypenameAndValueDecls {
+
+template  class Base;
+template  class Derived : public Base {
+public:
+  using typename Base::foo;
+  using Base::bar;
+  typedef typename Derived::foo NewUnresolvedUsingType;
+};
+
+} // end namespace TestUnresolvedTypenameAndValueDecls
+
+namespace TestUsingNamespace {
+  using namespace Enclosing;
+}
Index: test/ASTMerge/namespace/Inputs/namespace1.cpp
===
--- test/ASTMerge/namespace/Inputs/namespace1.cpp
+++ test/ASTMerge/namespace/Inputs/namespace1.cpp
@@ -15,3 +15,13 @@
 namespace N3 {
   extern float z;
 }
+
+namespace AliasWithSameName = N3;
+
+namespace TestUnresolvedTypenameAndValueDecls {
+template  class Base {
+public:
+  typedef T foo;
+  void bar();
+};
+}
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -58,7 +58,7 @@
 QualType VisitExtVectorType(const ExtVectorType *T);
 QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
 QualType VisitFunctionProtoType(const FunctionProtoType *T);
-// FIXME: UnresolvedUsingType
+QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T);
 QualType VisitParenType(const ParenType *T);
 QualType VisitTypedefType(const TypedefType *T);
 QualType VisitTypeOfExprType(const TypeOfExprType *T);
@@ -128,8 +128,8 @@
 TemplateParameterList *ImportTemplateParameterList(
  TemplateParameterList *Params);
 TemplateArgument ImportTemplateArgument(const TemplateArgument );
-TemplateArgumentLoc ImportTemplateArgumentLoc(
-const TemplateArgumentLoc , bool );
+Optional ImportTemplateArgumentLoc(
+const TemplateArgumentLoc );
 bool ImportTemplateArguments(const TemplateArgument *FromArgs,
  unsigned NumFromArgs,
SmallVectorImpl );
@@ -142,10 +142,12 @@
 bool 

[PATCH] D32745: Correct debug info bit offset calculation for big-endian targets

2017-05-02 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

Doesn't the test need some kind of `REQUIRES: mips` line?
Otherwise looks fine.


https://reviews.llvm.org/D32745



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


Re: r301846 - Fix initial diagnostic state setup for an explicit module with no diagnostic pragmas.

2017-05-02 Thread Richard Smith via cfe-commits
On 1 May 2017 10:29 pm, "NAKAMURA Takumi"  wrote:

It didn't pass for targeting *-win32, since MicrosoftRecordLayoutBuilder
doesn't have ability of -Wpadded.
Tweaked in r301898.


Thank you!

I guess other diag would be available here but I have no good idea.

On Tue, May 2, 2017 at 7:23 AM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Mon May  1 17:10:47 2017
> New Revision: 301846
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301846=rev
> Log:
> Fix initial diagnostic state setup for an explicit module with no
> diagnostic pragmas.
>
> If a file has no diagnostic pragmas, we build its diagnostic state lazily,
> but
> in this case we never set up the root state to be the diagnostic state in
> which
> the module was originally built, so the diagnostic flags for files in the
> module with no diagnostic pragmas were incorrectly based on the user of the
> module rather than the diagnostic state when the module was built.
>
> Added:
> cfe/trunk/test/Modules/diag-flags.cpp
> Modified:
> cfe/trunk/lib/Serialization/ASTReader.cpp
> cfe/trunk/test/Modules/Inputs/module.map
>
> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> Serialization/ASTReader.cpp?rev=301846=301845=301846=diff
> 
> ==
> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon May  1 17:10:47 2017
> @@ -3765,6 +3765,13 @@ ASTReader::ASTReadResult ASTReader::Read
>SourceMgr.getLoadedSLocEntryByID(Index);
>  }
>
> +// Map the original source file ID into the ID space of the current
> +// compilation.
> +if (F.OriginalSourceFileID.isValid()) {
> +  F.OriginalSourceFileID = FileID::get(
> +  F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() -
> 1);
> +}
> +
>  // Preload all the pending interesting identifiers by marking them
> out of
>  // date.
>  for (auto Offset : F.PreloadIdentifierOffsets) {
> @@ -3873,10 +3880,6 @@ ASTReader::ASTReadResult ASTReader::Read
>
>ModuleFile  = ModuleMgr.getPrimaryModule();
>if (PrimaryModule.OriginalSourceFileID.isValid()) {
> -PrimaryModule.OriginalSourceFileID
> -  = FileID::get(PrimaryModule.SLocEntryBaseID
> -+ PrimaryModule.OriginalSourceFileID.getOpaqueValue()
> - 1);
> -
>  // If this AST file is a precompiled preamble, then set the
>  // preamble file ID of the source manager to the file source file
>  // from which the preamble was built.
> @@ -5575,6 +5578,13 @@ void ASTReader::ReadPragmaDiagnosticMapp
>FirstState = ReadDiagState(
>F.isModule() ? DiagState() : *Diag.DiagStatesByLoc.
> CurDiagState,
>SourceLocation(), F.isModule());
> +
> +  // For an explicit module, set up the root buffer of the module to
> start
> +  // with the initial diagnostic state of the module itself, to cover
> files
> +  // that contain no explicit transitions.
> +  if (F.isModule())
> +Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID]
> +.StateTransitions.push_back({FirstState, 0});
>  }
>
>  // Read the state transitions.
>
> Modified: cfe/trunk/test/Modules/Inputs/module.map
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> Modules/Inputs/module.map?rev=301846=301845=301846=diff
> 
> ==
> --- cfe/trunk/test/Modules/Inputs/module.map (original)
> +++ cfe/trunk/test/Modules/Inputs/module.map Mon May  1 17:10:47 2017
> @@ -261,6 +261,10 @@ module config {
>config_macros [exhaustive] WANT_FOO, WANT_BAR
>  }
>
> +module diag_flags {
> +  header "diag_flags.h"
> +}
> +
>  module diag_pragma {
>header "diag_pragma.h"
>  }
>
> Added: cfe/trunk/test/Modules/diag-flags.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> Modules/diag-flags.cpp?rev=301846=auto
> 
> ==
> --- cfe/trunk/test/Modules/diag-flags.cpp (added)
> +++ cfe/trunk/test/Modules/diag-flags.cpp Mon May  1 17:10:47 2017
> @@ -0,0 +1,22 @@
> +// RUN: rm -rf %t
> +//
> +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -emit-module
> -fmodules-cache-path=%t -fmodule-name=diag_flags -x c++
> %S/Inputs/module.map -fmodules-ts
> +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify
> -fmodules-cache-path=%t -I %S/Inputs %s -fmodules-ts
> +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify
> -fmodules-cache-path=%t -I %S/Inputs %s -fmodules-ts -DIMPLICIT_FLAG
> -Werror=padded
> +//
> +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -emit-module
> -fmodule-name=diag_flags -x c++ %S/Inputs/module.map -fmodules-ts -o
> %t/explicit.pcm -Werror=string-plus-int -Wpadded
> +// RUN: %clang_cc1 -fmodules 

r301928 - [CodeGen] remove/fix checks that will fail when r301923 is recommitted

2017-05-02 Thread Sanjay Patel via cfe-commits
Author: spatel
Date: Tue May  2 10:20:18 2017
New Revision: 301928

URL: http://llvm.org/viewvc/llvm-project?rev=301928=rev
Log:
[CodeGen] remove/fix checks that will fail when r301923 is recommitted

Don't test the optimizer as part of front-end verification.

Modified:
cfe/trunk/test/CodeGen/atomic-ops-libcall.c

Modified: cfe/trunk/test/CodeGen/atomic-ops-libcall.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/atomic-ops-libcall.c?rev=301928=301927=301928=diff
==
--- cfe/trunk/test/CodeGen/atomic-ops-libcall.c (original)
+++ cfe/trunk/test/CodeGen/atomic-ops-libcall.c Tue May  2 10:20:18 2017
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 < %s -triple armv5e-none-linux-gnueabi -emit-llvm -O1 | 
FileCheck %s
 
+// FIXME: This file should not be checking -O1 output.
+// Ie, it is testing many IR optimizer passes as part of front-end 
verification.
+
 enum memory_order {
   memory_order_relaxed, memory_order_consume, memory_order_acquire,
   memory_order_release, memory_order_acq_rel, memory_order_seq_cst
@@ -110,7 +113,8 @@ int test_atomic_xor_fetch(int *p) {
 int test_atomic_nand_fetch(int *p) {
   // CHECK: test_atomic_nand_fetch
   // CHECK: [[CALL:%[^ ]*]] = tail call i32 @__atomic_fetch_nand_4(i8* 
{{%[0-9]+}}, i32 55, i32 5)
-  // CHECK: [[OR:%[^ ]*]] = or i32 [[CALL]], -56
-  // CHECK: {{%[^ ]*}} = xor i32 [[OR]], 55
+  // FIXME: We should not be checking optimized IR. It changes independently 
of clang.
+  // FIXME-CHECK: [[AND:%[^ ]*]] = and i32 [[CALL]], 55
+  // FIXME-CHECK: {{%[^ ]*}} = xor i32 [[AND]], -1
   return __atomic_nand_fetch(p, 55, memory_order_seq_cst);
 }


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


[PATCH] D32745: Correct debug info bit offset calculation for big-endian targets

2017-05-02 Thread Frej Drejhammar via Phabricator via cfe-commits
frej created this revision.
Herald added subscribers: arichardson, aprantl.

The change "[CodeView] Implement support for bit fields in
Clang" (r274201, https://reviews.llvm.org/rL274201) broke the
calculation of bit offsets for the debug info describing bitfields on
big-endian targets.

Prior to commit r274201 the debug info for bitfields got their offsets
from the ASTRecordLayout in CGDebugInfo::CollectRecordFields(), the
current field offset was then passed on to
CGDebugInfo::CollectRecordNormalField() and used directly in the
DIDerivedType.

Since commit r274201, the bit offset ending up in the DIDerivedType no
longer comes directly from the ASTRecordLayout. Instead
CGDebugInfo::CollectRecordNormalField() calls the new method
CGDebugInfo::createBitFieldType(), which in turn calls
CodeGenTypes::getCGRecordLayout().getBitFieldInfo() to fetch a
CGBitFieldInfo describing the field. The 'Offset' member of
CGBitFieldInfo is then used to calculate the bit offset of the
DIDerivedType. Unfortunately the previous and current method of
calculating the bit offset are only equivalent for little endian
targets, as CGRecordLowering::setBitFieldInfo() reverses the bit
offsets for big endian targets as the last thing it does.

A simple reproducer for this error is the following module:

struct fields {

  unsigned a : 4;
  unsigned b : 4;

} flags = {0x0f, 0x1};

Compiled for Mips, with commit r274200 both the DIDerivedType bit
offsets on the IR-level and the DWARF information on the ELF-level
will have the expected values: the offsets of 'a' and 'b' are 0 and 4
respectively. With r274201 the offsets are switched to 4 and 0. By
noting that the static initialization of 'flags' in both cases is the
same, we can eliminate a change in record layout as the cause of the
change in the debug info. Also compiling this example with gcc,
produces the same record layout and debug info as commit r274200.

In order to restore the previous function we extend
CGDebugInfo::createBitFieldType() to compensate for the reversal done
in CGRecordLowering::setBitFieldInfo().


https://reviews.llvm.org/D32745

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/mips-debug-info-bitfield.c


Index: clang/test/CodeGen/mips-debug-info-bitfield.c
===
--- /dev/null
+++ clang/test/CodeGen/mips-debug-info-bitfield.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple mips-none-linux-gnu 
-emit-llvm -o - %s | FileCheck %s
+
+struct fields
+{
+  unsigned a : 4;
+  unsigned b : 4;
+} flags;
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "a"
+// CHECK-NOT: {{.*}}offset:
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "b"
+// CHECK-SAME: {{.*}}offset: 4
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1041,7 +1041,13 @@
   assert(SizeInBits > 0 && "found named 0-width bitfield");
   uint64_t StorageOffsetInBits =
   CGM.getContext().toBits(BitFieldInfo.StorageOffset);
-  uint64_t OffsetInBits = StorageOffsetInBits + BitFieldInfo.Offset;
+  uint64_t Offset = BitFieldInfo.Offset;
+  // The bit offsets for big endian machines are reversed for big
+  // endian target, compensate for that as the DIDerivedType requires
+  // un-reversed offsets.
+  if (CGM.getDataLayout().isBigEndian())
+Offset = BitFieldInfo.StorageSize - BitFieldInfo.Size - Offset;
+  uint64_t OffsetInBits = StorageOffsetInBits + Offset;
   llvm::DINode::DIFlags Flags = getAccessFlag(BitFieldDecl->getAccess(), RD);
   return DBuilder.createBitFieldMemberType(
   RecordTy, Name, File, Line, SizeInBits, OffsetInBits, 
StorageOffsetInBits,


Index: clang/test/CodeGen/mips-debug-info-bitfield.c
===
--- /dev/null
+++ clang/test/CodeGen/mips-debug-info-bitfield.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple mips-none-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+struct fields
+{
+  unsigned a : 4;
+  unsigned b : 4;
+} flags;
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "a"
+// CHECK-NOT: {{.*}}offset:
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "b"
+// CHECK-SAME: {{.*}}offset: 4
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1041,7 +1041,13 @@
   assert(SizeInBits > 0 && "found named 0-width bitfield");
   uint64_t StorageOffsetInBits =
   CGM.getContext().toBits(BitFieldInfo.StorageOffset);
-  uint64_t OffsetInBits = 

Re: r301916 - Revert r301735 (and subsequent r301786).

2017-05-02 Thread Daniel Jasper via cfe-commits
I forgot the () in the lambda definition, this should be:

  ..
  auto l = [this] { auto l = []() EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
  ..

Doesn't change the fact that clang segfaults without this revert, though.

On Tue, May 2, 2017 at 2:38 PM, Daniel Jasper via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: djasper
> Date: Tue May  2 07:38:27 2017
> New Revision: 301916
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301916=rev
> Log:
> Revert r301735 (and subsequent r301786).
>
> It leads to clang crashing, e.g. on this short code fragment (added to
> test/SemaCXX/warn-thread-safety-parsing.cpp):
>
>   class SomeClass {
>   public:
> void foo() {
>   auto l = [this] { auto l = [] EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
> }
> Mutex mu_;
>   };
>
> Modified:
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaExprCXX.cpp?rev=301916=301915=301916=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue May  2 07:38:27 2017
> @@ -901,35 +901,17 @@ static QualType adjustCVQualifiersForCXX
>// capturing lamdbda's call operator.
>//
>
> -  // Since the FunctionScopeInfo stack is representative of the lexical
> -  // nesting of the lambda expressions during initial parsing (and is the
> best
> -  // place for querying information about captures about lambdas that are
> -  // partially processed) and perhaps during instantiation of function
> templates
> -  // that contain lambda expressions that need to be transformed BUT not
> -  // necessarily during instantiation of a nested generic lambda's
> function call
> -  // operator (which might even be instantiated at the end of the TU) -
> at which
> -  // time the DeclContext tree is mature enough to query capture
> information
> -  // reliably - we use a two pronged approach to walk through all the
> lexically
> -  // enclosing lambda expressions:
> -  //
> -  //  1) Climb down the FunctionScopeInfo stack as long as each item
> represents
> -  //  a Lambda (i.e. LambdaScopeInfo) AND each LSI's 'closure-type' is
> lexically
> -  //  enclosed by the call-operator of the LSI below it on the stack
> (while
> -  //  tracking the enclosing DC for step 2 if needed).  Note the topmost
> LSI on
> -  //  the stack represents the innermost lambda.
> -  //
> -  //  2) Iterate out through the DeclContext chain (if it represents a
> lambda's
> -  //  call operator, and therefore must be a generic lambda's call
> operator,
> -  //  which is the only time an inconsistency between the LSI and the
> -  //  DeclContext should occur) querying closure types regarding capture
> -  //  information.
> +  // The issue is that we cannot rely entirely on the FunctionScopeInfo
> stack
> +  // since ScopeInfos are pushed on during parsing and treetransforming.
> But
> +  // since a generic lambda's call operator can be instantiated anywhere
> (even
> +  // end of the TU) we need to be able to examine its enclosing lambdas
> and so
> +  // we use the DeclContext to get a hold of the closure-class and query
> it for
> +  // capture information.  The reason we don't just resort to always
> using the
> +  // DeclContext chain is that it is only mature for lambda expressions
> +  // enclosing generic lambda's call operators that are being
> instantiated.
>
> -
> -  // 1) Climb down the function scope info stack.
>for (int I = FunctionScopes.size();
> -   I-- && isa(FunctionScopes[I]) &&
> -   (!CurLSI || CurLSI->Lambda->getDeclContext() ==
> -   cast(FunctionScopes[I])->
> CallOperator);
> +   I-- && isa(FunctionScopes[I]);
> CurDC = getLambdaAwareParentOfDeclContext(CurDC)) {
>  CurLSI = cast(FunctionScopes[I]);
>
> @@ -945,17 +927,11 @@ static QualType adjustCVQualifiersForCXX
>return ASTCtx.getPointerType(ClassType);
>  }
>}
> -
> -  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which
> can
> -  // happen during instantiation of its nested generic lambda call
> operator)
> +  // We've run out of ScopeInfos but check if CurDC is a lambda (which can
> +  // happen during instantiation of generic lambdas)
>if (isLambdaCallOperator(CurDC)) {
> -assert(CurLSI && "While computing 'this' capture-type for a generic "
> - "lambda, we must have a corresponding
> LambdaScopeInfo");
> -assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator)
> &&
> -   "While computing 'this' capture-type for a generic lambda,
> when we "
> -   "run out of enclosing LSI's, yet the enclosing DC is a "
> -   "lambda-call-operator we must be (i.e. Current LSI) in a
> generic "
> -   "lambda call oeprator");
> +assert(CurLSI);
> +

r301916 - Revert r301735 (and subsequent r301786).

2017-05-02 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue May  2 07:38:27 2017
New Revision: 301916

URL: http://llvm.org/viewvc/llvm-project?rev=301916=rev
Log:
Revert r301735 (and subsequent r301786).

It leads to clang crashing, e.g. on this short code fragment (added to
test/SemaCXX/warn-thread-safety-parsing.cpp):

  class SomeClass {
  public:
void foo() {
  auto l = [this] { auto l = [] EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
}
Mutex mu_;
  };

Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=301916=301915=301916=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue May  2 07:38:27 2017
@@ -901,35 +901,17 @@ static QualType adjustCVQualifiersForCXX
   // capturing lamdbda's call operator.
   //
 
-  // Since the FunctionScopeInfo stack is representative of the lexical
-  // nesting of the lambda expressions during initial parsing (and is the best
-  // place for querying information about captures about lambdas that are
-  // partially processed) and perhaps during instantiation of function 
templates
-  // that contain lambda expressions that need to be transformed BUT not
-  // necessarily during instantiation of a nested generic lambda's function 
call
-  // operator (which might even be instantiated at the end of the TU) - at 
which
-  // time the DeclContext tree is mature enough to query capture information
-  // reliably - we use a two pronged approach to walk through all the lexically
-  // enclosing lambda expressions:
-  //
-  //  1) Climb down the FunctionScopeInfo stack as long as each item represents
-  //  a Lambda (i.e. LambdaScopeInfo) AND each LSI's 'closure-type' is 
lexically
-  //  enclosed by the call-operator of the LSI below it on the stack (while
-  //  tracking the enclosing DC for step 2 if needed).  Note the topmost LSI on
-  //  the stack represents the innermost lambda.
-  //
-  //  2) Iterate out through the DeclContext chain (if it represents a lambda's
-  //  call operator, and therefore must be a generic lambda's call operator,
-  //  which is the only time an inconsistency between the LSI and the
-  //  DeclContext should occur) querying closure types regarding capture
-  //  information.
+  // The issue is that we cannot rely entirely on the FunctionScopeInfo stack
+  // since ScopeInfos are pushed on during parsing and treetransforming. But
+  // since a generic lambda's call operator can be instantiated anywhere (even
+  // end of the TU) we need to be able to examine its enclosing lambdas and so
+  // we use the DeclContext to get a hold of the closure-class and query it for
+  // capture information.  The reason we don't just resort to always using the
+  // DeclContext chain is that it is only mature for lambda expressions
+  // enclosing generic lambda's call operators that are being instantiated.
 
-
-  // 1) Climb down the function scope info stack.
   for (int I = FunctionScopes.size();
-   I-- && isa(FunctionScopes[I]) &&
-   (!CurLSI || CurLSI->Lambda->getDeclContext() ==
-   cast(FunctionScopes[I])->CallOperator);
+   I-- && isa(FunctionScopes[I]);
CurDC = getLambdaAwareParentOfDeclContext(CurDC)) {
 CurLSI = cast(FunctionScopes[I]);
 
@@ -945,17 +927,11 @@ static QualType adjustCVQualifiersForCXX
   return ASTCtx.getPointerType(ClassType);
 }
   }
-
-  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
-  // happen during instantiation of its nested generic lambda call operator)
+  // We've run out of ScopeInfos but check if CurDC is a lambda (which can
+  // happen during instantiation of generic lambdas)
   if (isLambdaCallOperator(CurDC)) {
-assert(CurLSI && "While computing 'this' capture-type for a generic "
- "lambda, we must have a corresponding LambdaScopeInfo");
-assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) &&
-   "While computing 'this' capture-type for a generic lambda, when we "
-   "run out of enclosing LSI's, yet the enclosing DC is a "
-   "lambda-call-operator we must be (i.e. Current LSI) in a generic "
-   "lambda call oeprator");
+assert(CurLSI);
+assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator));
 assert(CurDC == getLambdaAwareParentOfDeclContext(CurLSI->CallOperator));
 
 auto IsThisCaptured =

Modified: cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp?rev=301916=301915=301916=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp (original)
+++ 

Re: r301735 - Fix PR32831: 'this capture while instantiating generic lambda call operator specialization

2017-05-02 Thread Daniel Jasper via cfe-commits
I'll revert this as it makes the following snippet makes clang crash:

class SomeClass {
 public:
  void foo() {
auto l = [this] { auto l = [] EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
  }
  Mutex mu_;
};

(e.g. this can be added to test/SemaCXX/warn-thread-safety-parsing.cpp)
>From a brief look at the backtrace, it seems like
CurLSI->Lambda->getDeclContext() fails.

On Fri, Apr 28, 2017 at 8:49 PM, Faisal Vali via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: faisalv
> Date: Fri Apr 28 22:49:17 2017
> New Revision: 301735
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301735=rev
> Log:
> Fix PR32831: 'this capture while instantiating generic lambda call
> operator specialization
>
> When computing the appropriate cv-qualifiers for the 'this' capture, we
> have to examine each enclosing lambda - but when using the
> FunctionScopeInfo stack we have to ensure that the lambda below (outer) is
> the decl-context of the closure-class of the current lambda.
>
> https://bugs.llvm.org/show_bug.cgi?id=32831
>
> Modified:
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaExprCXX.cpp?rev=301735=301734=301735=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Apr 28 22:49:17 2017
> @@ -901,17 +901,35 @@ static QualType adjustCVQualifiersForCXX
>// capturing lamdbda's call operator.
>//
>
> -  // The issue is that we cannot rely entirely on the FunctionScopeInfo
> stack
> -  // since ScopeInfos are pushed on during parsing and treetransforming.
> But
> -  // since a generic lambda's call operator can be instantiated anywhere
> (even
> -  // end of the TU) we need to be able to examine its enclosing lambdas
> and so
> -  // we use the DeclContext to get a hold of the closure-class and query
> it for
> -  // capture information.  The reason we don't just resort to always
> using the
> -  // DeclContext chain is that it is only mature for lambda expressions
> -  // enclosing generic lambda's call operators that are being
> instantiated.
> +  // Since the FunctionScopeInfo stack is representative of the lexical
> +  // nesting of the lambda expressions during initial parsing (and is the
> best
> +  // place for querying information about captures about lambdas that are
> +  // partially processed) and perhaps during instantiation of function
> templates
> +  // that contain lambda expressions that need to be transformed BUT not
> +  // necessarily during instantiation of a nested generic lambda's
> function call
> +  // operator (which might even be instantiated at the end of the TU) -
> at which
> +  // time the DeclContext tree is mature enough to query capture
> information
> +  // reliably - we use a two pronged approach to walk through all the
> lexically
> +  // enclosing lambda expressions:
> +  //
> +  //  1) Climb down the FunctionScopeInfo stack as long as each item
> represents
> +  //  a Lambda (i.e. LambdaScopeInfo) AND each LSI's 'closure-type' is
> lexically
> +  //  enclosed by the call-operator of the LSI below it on the stack
> (while
> +  //  tracking the enclosing DC for step 2 if needed).  Note the topmost
> LSI on
> +  //  the stack represents the innermost lambda.
> +  //
> +  //  2) Iterate out through the DeclContext chain (if it represents a
> lambda's
> +  //  call operator, and therefore must be a generic lambda's call
> operator,
> +  //  which is the only time an inconsistency between the LSI and the
> +  //  DeclContext should occur) querying closure types regarding capture
> +  //  information.
>
> +
> +  // 1) Climb down the function scope info stack.
>for (int I = FunctionScopes.size();
> -   I-- && isa(FunctionScopes[I]);
> +   I-- && isa(FunctionScopes[I]) &&
> +   (!CurLSI || CurLSI->Lambda->getDeclContext() ==
> +   cast(FunctionScopes[I])->
> CallOperator);
> CurDC = getLambdaAwareParentOfDeclContext(CurDC)) {
>  CurLSI = cast(FunctionScopes[I]);
>
> @@ -927,11 +945,17 @@ static QualType adjustCVQualifiersForCXX
>return ASTCtx.getPointerType(ClassType);
>  }
>}
> -  // We've run out of ScopeInfos but check if CurDC is a lambda (which can
> -  // happen during instantiation of generic lambdas)
> +
> +  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which
> can
> +  // happen during instantiation of its nested generic lambda call
> operator)
>if (isLambdaCallOperator(CurDC)) {
> -assert(CurLSI);
> -assert(isGenericLambdaCallOperatorSpecialization(CurLSI->
> CallOperator));
> +assert(CurLSI && "While computing 'this' capture-type for a generic "
> + "lambda, we must have a corresponding
> LambdaScopeInfo");
> +

[PATCH] D32741: [clang-move] Find template class forward declarations more precisely.

2017-05-02 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301914: [clang-move] Find template class forward 
declarations more precisely. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D32741?vs=97427=97434#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32741

Files:
  clang-tools-extra/trunk/clang-move/ClangMove.cpp
  clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp


Index: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
===
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
@@ -531,13 +531,15 @@
 "void f2();\n"
 "} // namespace a\n"
 "\n"
+"class ForwardClass;\n"
 "namespace a {\n"
 "namespace b {\n"
 "class Move1 { public : void f(); };\n"
 "void f() {}\n"
 "enum E1 { Green };\n"
 "enum class E2 { Red };\n"
 "typedef int Int2;\n"
+"typedef A A_d;"
 "using Int = int;\n"
 "extern int kGlobalInt;\n"
 "extern const char* const kGlobalStr;\n"
@@ -552,11 +554,20 @@
   Spec.NewCC = "new_foo.cc";
   DeclarationReporter Reporter;
   std::set ExpectedDeclarations = {
-  {"A", "Class"}, {"B", "Class"},{"a::Move1", "Class"},
-  {"a::f1", "Function"},  {"a::f2", "Function"}, {"a::b::Move1", "Class"},
-  {"a::b::f", "Function"}, {"a::b::E1", "Enum"}, {"a::b::E2", "Enum"},
-  {"a::b::Int2", "TypeAlias"}, {"a::b::Int", "TypeAlias"},
-  {"a::b::kGlobalInt", "Variable"}, {"a::b::kGlobalStr", "Variable"}};
+  {"A", "Class"},
+  {"B", "Class"},
+  {"a::Move1", "Class"},
+  {"a::f1", "Function"},
+  {"a::f2", "Function"},
+  {"a::b::Move1", "Class"},
+  {"a::b::f", "Function"},
+  {"a::b::E1", "Enum"},
+  {"a::b::E2", "Enum"},
+  {"a::b::Int2", "TypeAlias"},
+  {"a::b::A_d", "TypeAlias"},
+  {"a::b::Int", "TypeAlias"},
+  {"a::b::kGlobalInt", "Variable"},
+  {"a::b::kGlobalStr", "Variable"}};
   runClangMoveOnCode(Spec, TestHeader, TestCode, );
   std::set Results;
   for (const auto& DelPair : Reporter.getDeclarationList())
Index: clang-tools-extra/trunk/clang-move/ClangMove.cpp
===
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp
@@ -504,8 +504,11 @@
   isExpansionInFile(makeAbsolutePath(Context->Spec.OldHeader));
   auto InOldCC = isExpansionInFile(makeAbsolutePath(Context->Spec.OldCC));
   auto InOldFiles = anyOf(InOldHeader, InOldCC);
-  auto ForwardDecls =
-  cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition(;
+  auto classTemplateForwardDecls =
+  classTemplateDecl(unless(has(cxxRecordDecl(isDefinition();
+  auto ForwardClassDecls = namedDecl(
+  anyOf(cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition(,
+classTemplateForwardDecls));
   auto TopLevelDecl =
   hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl()));
 
@@ -518,9 +521,8 @@
   // We consider declarations inside a class belongs to the class. So these
   // declarations will be ignored.
   auto AllDeclsInHeader = namedDecl(
-  unless(ForwardDecls), unless(namespaceDecl()),
-  unless(usingDirectiveDecl()), // using namespace decl.
-  unless(classTemplateDecl(has(ForwardDecls))), // template forward decl.
+  unless(ForwardClassDecls), unless(namespaceDecl()),
+  unless(usingDirectiveDecl()), // using namespace decl.
   InOldHeader,
   hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl(,
   hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl();
@@ -531,7 +533,7 @@
 return;
 
   // Match forward declarations in old header.
-  Finder->addMatcher(namedDecl(ForwardDecls, InOldHeader).bind("fwd_decl"),
+  Finder->addMatcher(namedDecl(ForwardClassDecls, 
InOldHeader).bind("fwd_decl"),
  this);
 
   
//


Index: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
===
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
@@ -531,13 +531,15 @@
 "void f2();\n"
 "} // namespace a\n"
 "\n"
+"class 

[clang-tools-extra] r301914 - [clang-move] Find template class forward declarations more precisely.

2017-05-02 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue May  2 07:15:11 2017
New Revision: 301914

URL: http://llvm.org/viewvc/llvm-project?rev=301914=rev
Log:
[clang-move] Find template class forward declarations more precisely.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=301914=301913=301914=diff
==
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Tue May  2 07:15:11 2017
@@ -504,8 +504,11 @@ void ClangMoveTool::registerMatchers(ast
   isExpansionInFile(makeAbsolutePath(Context->Spec.OldHeader));
   auto InOldCC = isExpansionInFile(makeAbsolutePath(Context->Spec.OldCC));
   auto InOldFiles = anyOf(InOldHeader, InOldCC);
-  auto ForwardDecls =
-  cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition(;
+  auto classTemplateForwardDecls =
+  classTemplateDecl(unless(has(cxxRecordDecl(isDefinition();
+  auto ForwardClassDecls = namedDecl(
+  anyOf(cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition(,
+classTemplateForwardDecls));
   auto TopLevelDecl =
   hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl()));
 
@@ -518,9 +521,8 @@ void ClangMoveTool::registerMatchers(ast
   // We consider declarations inside a class belongs to the class. So these
   // declarations will be ignored.
   auto AllDeclsInHeader = namedDecl(
-  unless(ForwardDecls), unless(namespaceDecl()),
-  unless(usingDirectiveDecl()), // using namespace decl.
-  unless(classTemplateDecl(has(ForwardDecls))), // template forward decl.
+  unless(ForwardClassDecls), unless(namespaceDecl()),
+  unless(usingDirectiveDecl()), // using namespace decl.
   InOldHeader,
   hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl(,
   hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl();
@@ -531,7 +533,7 @@ void ClangMoveTool::registerMatchers(ast
 return;
 
   // Match forward declarations in old header.
-  Finder->addMatcher(namedDecl(ForwardDecls, InOldHeader).bind("fwd_decl"),
+  Finder->addMatcher(namedDecl(ForwardClassDecls, 
InOldHeader).bind("fwd_decl"),
  this);
 
   
//

Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=301914=301913=301914=diff
==
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Tue May  2 
07:15:11 2017
@@ -531,6 +531,7 @@ TEST(ClangMove, DumpDecls) {
 "void f2();\n"
 "} // namespace a\n"
 "\n"
+"class ForwardClass;\n"
 "namespace a {\n"
 "namespace b {\n"
 "class Move1 { public : void f(); };\n"
@@ -538,6 +539,7 @@ TEST(ClangMove, DumpDecls) {
 "enum E1 { Green };\n"
 "enum class E2 { Red };\n"
 "typedef int Int2;\n"
+"typedef A A_d;"
 "using Int = int;\n"
 "extern int kGlobalInt;\n"
 "extern const char* const kGlobalStr;\n"
@@ -552,11 +554,20 @@ TEST(ClangMove, DumpDecls) {
   Spec.NewCC = "new_foo.cc";
   DeclarationReporter Reporter;
   std::set ExpectedDeclarations = {
-  {"A", "Class"}, {"B", "Class"},{"a::Move1", "Class"},
-  {"a::f1", "Function"},  {"a::f2", "Function"}, {"a::b::Move1", "Class"},
-  {"a::b::f", "Function"}, {"a::b::E1", "Enum"}, {"a::b::E2", "Enum"},
-  {"a::b::Int2", "TypeAlias"}, {"a::b::Int", "TypeAlias"},
-  {"a::b::kGlobalInt", "Variable"}, {"a::b::kGlobalStr", "Variable"}};
+  {"A", "Class"},
+  {"B", "Class"},
+  {"a::Move1", "Class"},
+  {"a::f1", "Function"},
+  {"a::f2", "Function"},
+  {"a::b::Move1", "Class"},
+  {"a::b::f", "Function"},
+  {"a::b::E1", "Enum"},
+  {"a::b::E2", "Enum"},
+  {"a::b::Int2", "TypeAlias"},
+  {"a::b::A_d", "TypeAlias"},
+  {"a::b::Int", "TypeAlias"},
+  {"a::b::kGlobalInt", "Variable"},
+  {"a::b::kGlobalStr", "Variable"}};
   runClangMoveOnCode(Spec, TestHeader, TestCode, );
   std::set Results;

Re: [PATCH] D32199: [TBAASan] A TBAA Sanitizer (Clang)

2017-05-02 Thread Krzysztof Parzyszek via cfe-commits

On 5/1/2017 6:17 PM, Hal Finkel wrote:

However, the example can also be written as:

   struct X { int a, b; };
   X x { 50, 100 };
   X *o = (X*) 

   int a_is_b = o->a; // This is UB (or so we say)?

and then the pointer arithmetic considerations don't seem to apply.


I know what you mean. There is a statement somewhere that makes this 
illegal, but it's really hard to find this kind of information in the 
standards so I'm not sure I can find any definite proof in a finite time...


There is this paragraph that may give some clue (pointer to a struct 
points to the first element):


6.7.2.1 Structure and union specifiers

13 Within a structure object, the non-bit-field members and the units in 
which bit-fields reside have addresses that increase in the order in 
which they are declared. A pointer to a structure object, suitably 
converted, points to its initial member (or if that member is a 
bit-field, then to the unit in which it resides), and vice versa. There 
may be unnamed padding within a structure object, but not at its beginning.



There are also some other relevant sections:


6.2.7 Compatible type and composite type

2 All declarations that refer to the same object or function shall have 
compatible type; otherwise, the behavior is undefined.



6.5 Expressions

7 An object shall have its stored value accessed only by an lvalue 
expression that has one of the following types:73)

— a type compatible with the effective type of the object,
— a qualified version of a type compatible with the effective type of 
the object,
— a type that is the signed or unsigned type corresponding to the 
effective type of the object,
— a type that is the signed or unsigned type corresponding to a 
qualified version of the effective type of the object,
— an aggregate or union type that includes one of the aforementioned 
types among its members (including, recursively, a member of a 
subaggregate or contained union), or

— a character type.

73) The intent of this list is to specify those circumstances in which 
an object may or may not be aliased.



-Krzysztof

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation

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


[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-05-02 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: lib/StaticAnalyzer/Core/CheckerHelpers.cpp:116
+return false;
+  ConstraintManager  = State->getConstraintManager();
+  ProgramStateRef StTrue, StFalse;

danielmarjamaki wrote:
> xazax.hun wrote:
> > Any reason why do you get the constraint manager and not using 
> > ProgramState::assume?
> Mostly that it's just 1 call instead of 2. assumeDual() has some extra logic 
> (early return , assertion). are there some special reason to use assume()?
Basically it would be a bit shorter, it also calls AssumeDual in the background.
See https://clang.llvm.org/doxygen/ProgramState_8h_source.html#l00652


Repository:
  rL LLVM

https://reviews.llvm.org/D30295



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


[PATCH] D31650: [Analyzer] Detect when function pointer is freed

2017-05-02 Thread Daniel Marjamäki via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301913: [analyzer] Detect bad free of function pointers 
(authored by danielmarjamaki).

Changed prior to commit:
  https://reviews.llvm.org/D31650?vs=95929=97432#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31650

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  cfe/trunk/test/Analysis/malloc.c


Index: cfe/trunk/test/Analysis/malloc.c
===
--- cfe/trunk/test/Analysis/malloc.c
+++ cfe/trunk/test/Analysis/malloc.c
@@ -1774,6 +1774,16 @@
return ok; // no warning
 }
 
+void (*fnptr)(int);
+void freeIndirectFunctionPtr() {
+  void *p = (void *)fnptr;
+  free(p); // expected-warning {{Argument to free() is a function pointer}}
+}
+
+void freeFunctionPtr() {
+  free((void *)fnptr); // expected-warning {{Argument to free() is a function 
pointer}}
+}
+
 // 
 // False negatives.
 
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -401,6 +401,9 @@
   void ReportUseZeroAllocated(CheckerContext , SourceRange Range,
   SymbolRef Sym) const;
 
+  void ReportFunctionPointerFree(CheckerContext , SVal ArgVal,
+ SourceRange Range, const Expr *FreeExpr) 
const;
+
   /// Find the location of the allocation for Sym on the path leading to the
   /// exploded node N.
   LeakInfo getAllocationSite(const ExplodedNode *N, SymbolRef Sym,
@@ -1564,6 +1567,11 @@
 }
   }
 
+  if (SymBase->getType()->isFunctionPointerType()) {
+ReportFunctionPointerFree(C, ArgVal, ArgExpr->getSourceRange(), 
ParentExpr);
+return nullptr;
+  }
+
   ReleasedAllocated = (RsBase != nullptr) && (RsBase->isAllocated() ||
   RsBase->isAllocatedOfSizeZero());
 
@@ -2024,10 +2032,45 @@
   }
 }
 
+void MallocChecker::ReportFunctionPointerFree(CheckerContext , SVal ArgVal,
+  SourceRange Range,
+  const Expr *FreeExpr) const {
+  if (!ChecksEnabled[CK_MallocChecker])
+return;
+
+  Optional CheckKind = getCheckIfTracked(C, 
FreeExpr);
+  if (!CheckKind.hasValue())
+return;
+
+  if (ExplodedNode *N = C.generateErrorNode()) {
+if (!BT_BadFree[*CheckKind])
+  BT_BadFree[*CheckKind].reset(
+  new BugType(CheckNames[*CheckKind], "Bad free", "Memory Error"));
+
+SmallString<100> Buf;
+llvm::raw_svector_ostream Os(Buf);
+
+const MemRegion *MR = ArgVal.getAsRegion();
+while (const ElementRegion *ER = dyn_cast_or_null(MR))
+  MR = ER->getSuperRegion();
+
+Os << "Argument to ";
+if (!printAllocDeallocName(Os, C, FreeExpr))
+  Os << "deallocator";
+
+Os << " is a function pointer";
+
+auto R = llvm::make_unique(*BT_BadFree[*CheckKind], Os.str(), 
N);
+R->markInteresting(MR);
+R->addRange(Range);
+C.emitReport(std::move(R));
+  }
+}
+
 ProgramStateRef MallocChecker::ReallocMemAux(CheckerContext ,
  const CallExpr *CE,
  bool FreesOnFail,
- ProgramStateRef State, 
+ ProgramStateRef State,
  bool SuffixWithN) const {
   if (!State)
 return nullptr;


Index: cfe/trunk/test/Analysis/malloc.c
===
--- cfe/trunk/test/Analysis/malloc.c
+++ cfe/trunk/test/Analysis/malloc.c
@@ -1774,6 +1774,16 @@
return ok; // no warning
 }
 
+void (*fnptr)(int);
+void freeIndirectFunctionPtr() {
+  void *p = (void *)fnptr;
+  free(p); // expected-warning {{Argument to free() is a function pointer}}
+}
+
+void freeFunctionPtr() {
+  free((void *)fnptr); // expected-warning {{Argument to free() is a function pointer}}
+}
+
 // 
 // False negatives.
 
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -401,6 +401,9 @@
   void ReportUseZeroAllocated(CheckerContext , SourceRange Range,
   SymbolRef Sym) const;
 
+  void ReportFunctionPointerFree(CheckerContext , SVal ArgVal,
+ SourceRange Range, const Expr *FreeExpr) const;
+
   /// Find the location of the allocation for Sym on the path leading to the
   /// exploded node N.
   LeakInfo 

r301913 - [analyzer] Detect bad free of function pointers

2017-05-02 Thread Daniel Marjamaki via cfe-commits
Author: danielmarjamaki
Date: Tue May  2 06:46:12 2017
New Revision: 301913

URL: http://llvm.org/viewvc/llvm-project?rev=301913=rev
Log:
[analyzer] Detect bad free of function pointers

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/test/Analysis/malloc.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=301913=301912=301913=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Tue May  2 06:46:12 
2017
@@ -401,6 +401,9 @@ private:
   void ReportUseZeroAllocated(CheckerContext , SourceRange Range,
   SymbolRef Sym) const;
 
+  void ReportFunctionPointerFree(CheckerContext , SVal ArgVal,
+ SourceRange Range, const Expr *FreeExpr) 
const;
+
   /// Find the location of the allocation for Sym on the path leading to the
   /// exploded node N.
   LeakInfo getAllocationSite(const ExplodedNode *N, SymbolRef Sym,
@@ -1564,6 +1567,11 @@ ProgramStateRef MallocChecker::FreeMemAu
 }
   }
 
+  if (SymBase->getType()->isFunctionPointerType()) {
+ReportFunctionPointerFree(C, ArgVal, ArgExpr->getSourceRange(), 
ParentExpr);
+return nullptr;
+  }
+
   ReleasedAllocated = (RsBase != nullptr) && (RsBase->isAllocated() ||
   RsBase->isAllocatedOfSizeZero());
 
@@ -2024,10 +2032,45 @@ void MallocChecker::ReportUseZeroAllocat
   }
 }
 
+void MallocChecker::ReportFunctionPointerFree(CheckerContext , SVal ArgVal,
+  SourceRange Range,
+  const Expr *FreeExpr) const {
+  if (!ChecksEnabled[CK_MallocChecker])
+return;
+
+  Optional CheckKind = getCheckIfTracked(C, 
FreeExpr);
+  if (!CheckKind.hasValue())
+return;
+
+  if (ExplodedNode *N = C.generateErrorNode()) {
+if (!BT_BadFree[*CheckKind])
+  BT_BadFree[*CheckKind].reset(
+  new BugType(CheckNames[*CheckKind], "Bad free", "Memory Error"));
+
+SmallString<100> Buf;
+llvm::raw_svector_ostream Os(Buf);
+
+const MemRegion *MR = ArgVal.getAsRegion();
+while (const ElementRegion *ER = dyn_cast_or_null(MR))
+  MR = ER->getSuperRegion();
+
+Os << "Argument to ";
+if (!printAllocDeallocName(Os, C, FreeExpr))
+  Os << "deallocator";
+
+Os << " is a function pointer";
+
+auto R = llvm::make_unique(*BT_BadFree[*CheckKind], Os.str(), 
N);
+R->markInteresting(MR);
+R->addRange(Range);
+C.emitReport(std::move(R));
+  }
+}
+
 ProgramStateRef MallocChecker::ReallocMemAux(CheckerContext ,
  const CallExpr *CE,
  bool FreesOnFail,
- ProgramStateRef State, 
+ ProgramStateRef State,
  bool SuffixWithN) const {
   if (!State)
 return nullptr;

Modified: cfe/trunk/test/Analysis/malloc.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc.c?rev=301913=301912=301913=diff
==
--- cfe/trunk/test/Analysis/malloc.c (original)
+++ cfe/trunk/test/Analysis/malloc.c Tue May  2 06:46:12 2017
@@ -1774,6 +1774,16 @@ int testNoCheckerDataPropogationFromLogi
return ok; // no warning
 }
 
+void (*fnptr)(int);
+void freeIndirectFunctionPtr() {
+  void *p = (void *)fnptr;
+  free(p); // expected-warning {{Argument to free() is a function pointer}}
+}
+
+void freeFunctionPtr() {
+  free((void *)fnptr); // expected-warning {{Argument to free() is a function 
pointer}}
+}
+
 // 
 // False negatives.
 


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


[PATCH] D32741: [clang-move] Find template class forward declarations more precisely.

2017-05-02 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

Lgtm. Looks like the test case should already be covered.


https://reviews.llvm.org/D32741



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


[PATCH] D32741: [clang-move] Find template class forward declarations more precisely.

2017-05-02 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Could you add the following test case for dumping all decls?

  template 
  class Foo {
   public:
Foo() {}
  };
  typedef Foo Foo_i;


https://reviews.llvm.org/D32741



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


[PATCH] D32743: [clang-tidy] Add new cert-dcl21-cpp check.

2017-05-02 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun created this revision.
xazax.hun added a project: clang-tools-extra.
Herald added subscribers: whisperity, mgorny.

This check flags postfix ``operator++`` and ``operator--`` declarations, where 
the return type is not a const value type. It also attempt to fix the error.

This rule is described by cert: 
https://www.securecoding.cert.org/confluence/display/cplusplus/DCL21-CPP.+Overloaded+postfix+increment+and+decrement+operators+should+return+a+const+object


Repository:
  rL LLVM

https://reviews.llvm.org/D32743

Files:
  clang-tidy/cert/CERTTidyModule.cpp
  clang-tidy/cert/CMakeLists.txt
  clang-tidy/cert/PostfixOperatorCheck.cpp
  clang-tidy/cert/PostfixOperatorCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cert-dcl21-cpp.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cert-dcl21-cpp.cpp

Index: test/clang-tidy/cert-dcl21-cpp.cpp
===
--- /dev/null
+++ test/clang-tidy/cert-dcl21-cpp.cpp
@@ -0,0 +1,78 @@
+// RUN: %check_clang_tidy %s cert-dcl21-cpp %t
+
+class A {};
+
+A operator++(A &, int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: return type of overloaded 'operator++' is not a constant type [cert-dcl21-cpp]
+// CHECK-FIXES: {{^}}const A operator++(A &, int);
+
+A operator--(A &, int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: return type of overloaded 'operator--'
+// CHECK-FIXES: {{^}}const A operator--(A &, int);
+
+class B {};
+
+B ++(B &);
+const B operator++(B &, int);
+
+B (B &);
+const B operator--(B &, int);
+
+
+class D {
+D ++();
+const D operator++(int);
+
+D ();
+const D operator--(int);
+};
+
+class C {
+C operator++(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: return type of overloaded 'operator++'
+// CHECK-FIXES: {{^}}const C operator++(int);
+
+C operator--(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: return type of overloaded 'operator--'
+// CHECK-FIXES: {{^}}const C operator--(int);
+};
+
+class E {};
+
+E ++(E &, int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a reference, instead of an object [cert-dcl21-cpp]
+// CHECK-FIXES: {{^}}const E operator++(E &, int);
+
+E (E &, int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator--' returns a re
+// CHECK-FIXES: {{^}}const E operator--(E &, int);
+
+class G {
+G ++(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a re
+// CHECK-FIXES: {{^}}const G operator++(int);
+
+G (int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator--' returns a re
+// CHECK-FIXES: {{^}}const G operator--(int);
+};
+
+class F {};
+
+const F ++(F &, int);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator++' returns a re
+// CHECK-FIXES: {{^}}const F operator++(F &, int);
+
+const F (F &, int);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator--' returns a re
+// CHECK-FIXES: {{^}}const F operator--(F &, int);
+
+class H {
+const H ++(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator++' returns a re
+// CHECK-FIXES: {{^}}const H operator++(int);
+
+const H (int);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator--' returns a re
+// CHECK-FIXES: {{^}}const H operator--(int);
+};
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -6,6 +6,7 @@
 .. toctree::
boost-use-to-string
cert-dcl03-c (redirects to misc-static-assert) 
+   cert-dcl21-cpp
cert-dcl50-cpp
cert-dcl54-cpp (redirects to misc-new-delete-overloads) 
cert-dcl58-cpp
Index: docs/clang-tidy/checks/cert-dcl21-cpp.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cert-dcl21-cpp.rst
@@ -0,0 +1,11 @@
+.. title:: clang-tidy - cert-dcl21-cpp
+
+cert-dcl21-cpp
+==
+
+This check flags postfix ``operator++`` and ``operator--`` declarations,
+where the return type is not a const type.
+
+This check corresponds to the CERT C++ Coding Standard rule
+`FLP21-CPP. Overloaded postfix increment and decrement operators should return a const object
+`_.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `cert-dcl21-cpp
+  `_ check
+
+  Checks if the overloaded postfix ``++`` and ``--`` operator return a constant object.
+
 - New `cert-dcl58-cpp
   `_ check
 
Index: clang-tidy/cert/PostfixOperatorCheck.h

[PATCH] D32741: [clang-move] Find template class forward declarations more precisely.

2017-05-02 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.

https://reviews.llvm.org/D32741

Files:
  clang-move/ClangMove.cpp
  unittests/clang-move/ClangMoveTests.cpp


Index: unittests/clang-move/ClangMoveTests.cpp
===
--- unittests/clang-move/ClangMoveTests.cpp
+++ unittests/clang-move/ClangMoveTests.cpp
@@ -531,13 +531,15 @@
 "void f2();\n"
 "} // namespace a\n"
 "\n"
+"class ForwardClass;\n"
 "namespace a {\n"
 "namespace b {\n"
 "class Move1 { public : void f(); };\n"
 "void f() {}\n"
 "enum E1 { Green };\n"
 "enum class E2 { Red };\n"
 "typedef int Int2;\n"
+"typedef A A_d;"
 "using Int = int;\n"
 "extern int kGlobalInt;\n"
 "extern const char* const kGlobalStr;\n"
@@ -552,11 +554,20 @@
   Spec.NewCC = "new_foo.cc";
   DeclarationReporter Reporter;
   std::set ExpectedDeclarations = {
-  {"A", "Class"}, {"B", "Class"},{"a::Move1", "Class"},
-  {"a::f1", "Function"},  {"a::f2", "Function"}, {"a::b::Move1", "Class"},
-  {"a::b::f", "Function"}, {"a::b::E1", "Enum"}, {"a::b::E2", "Enum"},
-  {"a::b::Int2", "TypeAlias"}, {"a::b::Int", "TypeAlias"},
-  {"a::b::kGlobalInt", "Variable"}, {"a::b::kGlobalStr", "Variable"}};
+  {"A", "Class"},
+  {"B", "Class"},
+  {"a::Move1", "Class"},
+  {"a::f1", "Function"},
+  {"a::f2", "Function"},
+  {"a::b::Move1", "Class"},
+  {"a::b::f", "Function"},
+  {"a::b::E1", "Enum"},
+  {"a::b::E2", "Enum"},
+  {"a::b::Int2", "TypeAlias"},
+  {"a::b::A_d", "TypeAlias"},
+  {"a::b::Int", "TypeAlias"},
+  {"a::b::kGlobalInt", "Variable"},
+  {"a::b::kGlobalStr", "Variable"}};
   runClangMoveOnCode(Spec, TestHeader, TestCode, );
   std::set Results;
   for (const auto& DelPair : Reporter.getDeclarationList())
Index: clang-move/ClangMove.cpp
===
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -504,8 +504,11 @@
   isExpansionInFile(makeAbsolutePath(Context->Spec.OldHeader));
   auto InOldCC = isExpansionInFile(makeAbsolutePath(Context->Spec.OldCC));
   auto InOldFiles = anyOf(InOldHeader, InOldCC);
-  auto ForwardDecls =
-  cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition(;
+  auto classTemplateForwardDecls =
+  classTemplateDecl(unless(has(cxxRecordDecl(isDefinition();
+  auto ForwardClassDecls = namedDecl(
+  anyOf(cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition(,
+classTemplateForwardDecls));
   auto TopLevelDecl =
   hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl()));
 
@@ -518,9 +521,8 @@
   // We consider declarations inside a class belongs to the class. So these
   // declarations will be ignored.
   auto AllDeclsInHeader = namedDecl(
-  unless(ForwardDecls), unless(namespaceDecl()),
-  unless(usingDirectiveDecl()), // using namespace decl.
-  unless(classTemplateDecl(has(ForwardDecls))), // template forward decl.
+  unless(ForwardClassDecls), unless(namespaceDecl()),
+  unless(usingDirectiveDecl()), // using namespace decl.
   InOldHeader,
   hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl(,
   hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl();
@@ -531,7 +533,7 @@
 return;
 
   // Match forward declarations in old header.
-  Finder->addMatcher(namedDecl(ForwardDecls, InOldHeader).bind("fwd_decl"),
+  Finder->addMatcher(namedDecl(ForwardClassDecls, 
InOldHeader).bind("fwd_decl"),
  this);
 
   
//


Index: unittests/clang-move/ClangMoveTests.cpp
===
--- unittests/clang-move/ClangMoveTests.cpp
+++ unittests/clang-move/ClangMoveTests.cpp
@@ -531,13 +531,15 @@
 "void f2();\n"
 "} // namespace a\n"
 "\n"
+"class ForwardClass;\n"
 "namespace a {\n"
 "namespace b {\n"
 "class Move1 { public : void f(); };\n"
 "void f() {}\n"
 "enum E1 { Green };\n"
 "enum class E2 { Red };\n"
 "typedef int Int2;\n"
+"typedef A A_d;"
 "using Int = int;\n"
 "extern int kGlobalInt;\n"
  

[PATCH] D32700: [clang-tidy] Add misc-suspicious-memset-usage check.

2017-05-02 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

> The destination is a this pointer within a class that has a virtual function. 
> It might reset the virtual pointer.

Can you change this to match any pointer to a class with a virtual function?

I'd also like a warning for a pointer to a class with a constructor or 
destructor.


Repository:
  rL LLVM

https://reviews.llvm.org/D32700



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


[PATCH] D32566: Revert rL301328 and add tests for the regressions introduced.

2017-05-02 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

I sent http://lists.llvm.org/pipermail/cfe-dev/2017-May/053703.html


Repository:
  rL LLVM

https://reviews.llvm.org/D32566



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


r301906 - Remove leftover test expectation from rL301902.

2017-05-02 Thread Emilio Cobos Alvarez via cfe-commits
Author: emilio
Date: Tue May  2 04:57:30 2017
New Revision: 301906

URL: http://llvm.org/viewvc/llvm-project?rev=301906=rev
Log:
Remove leftover test expectation from rL301902.

Modified:
cfe/trunk/test/Index/print-type.cpp

Modified: cfe/trunk/test/Index/print-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.cpp?rev=301906=301905=301906=diff
==
--- cfe/trunk/test/Index/print-type.cpp (original)
+++ cfe/trunk/test/Index/print-type.cpp Tue May  2 04:57:30 2017
@@ -181,5 +181,4 @@ using baz = C;
 // CHECK: VarDecl=autoTemplRefParam:72:6 (Definition) 
[type=Specialization] [typekind=Auto] [templateargs/1= 
[type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const 
Specialization] [typekind=Unexposed] const 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=const Specialization] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
-// CHECK: TypedefDecl=DefaultedTypeAlias:77:35 (Definition) 
[type=DefaultedTypeAlias] [typekind=Typedef] [templateargs/2= [type=int] 
[typekind=Int] [type=int] [typekind=Int]] 
[canonicaltype=DefaultedTypeExample] [canonicaltypekind=Record] 
[canonicaltemplateargs/2= [type=int] [typekind=Int] [type=int] [typekind=Int]] 
[isPOD=0]
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]


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


r301902 - [libclang] Revert rL301328 and add tests for the regressions introduced.

2017-05-02 Thread Emilio Cobos Alvarez via cfe-commits
Author: emilio
Date: Tue May  2 03:32:15 2017
New Revision: 301902

URL: http://llvm.org/viewvc/llvm-project?rev=301902=rev
Log:
[libclang] Revert rL301328 and add tests for the regressions introduced.

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


Modified:
cfe/trunk/test/Index/print-type.cpp
cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/test/Index/print-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.cpp?rev=301902=301901=301902=diff
==
--- cfe/trunk/test/Index/print-type.cpp (original)
+++ cfe/trunk/test/Index/print-type.cpp Tue May  2 03:32:15 2017
@@ -71,10 +71,9 @@ struct Specialization;
 Specialization templRefParam;
 auto autoTemplRefParam = templRefParam;
 
-template
-struct DefaultedTypeExample {};
-
-typedef DefaultedTypeExample DefaultedTypeAlias;
+template struct A {};
+template using C = T;
+using baz = C;
 
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -120,7 +119,7 @@ typedef DefaultedTypeExample Defaul
 // CHECK: TemplateRef=Baz:9:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] 
[typekind=Record] [type=int] [typekind=Int]] [canonicaltype=outer::Qux] [canonicaltypekind=Record] 
[canonicaltemplateargs/4= [type=int] [typekind=Int] [type=char *] 
[typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] 
[typekind=Int]] [isPOD=1]
+// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=Foo] 
[typekind=Unexposed] [type=outer::inner::Bar::FooType] [typekind=Typedef]] 
[canonicaltype=outer::Qux] 
[canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] 
[type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] 
[type=int] [typekind=Int]] [isPOD=1]
 // CHECK: TemplateRef=Qux:12:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: FunctionTemplate=tbar:36:3 [type=T (int)] [typekind=FunctionProto] 
[canonicaltype=type-parameter-0-0 (int)] [canonicaltypekind=FunctionProto] 
[resulttype=T] [resulttypekind=Unexposed] [isPOD=0]
@@ -183,3 +182,4 @@ typedef DefaultedTypeExample Defaul
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const 
Specialization] [typekind=Unexposed] const 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=const Specialization] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypedefDecl=DefaultedTypeAlias:77:35 (Definition) 
[type=DefaultedTypeAlias] [typekind=Typedef] [templateargs/2= [type=int] 
[typekind=Int] [type=int] [typekind=Int]] 
[canonicaltype=DefaultedTypeExample] [canonicaltypekind=Record] 
[canonicaltemplateargs/2= [type=int] [typekind=Int] [type=int] [typekind=Int]] 
[isPOD=0]
+// CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]

Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=301902=301901=301902=diff
==
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Tue May  2 03:32:15 2017
@@ -147,6 +147,9 @@ static inline CXTranslationUnit GetTU(CX
 static Optional
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
+  if (const auto *Specialization = Type->getAs())
+return Specialization->template_arguments();
+
   if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) {
 const auto *TemplateDecl =
   dyn_cast(RecordDecl);
@@ -154,9 +157,6 @@ GetTemplateArguments(QualType Type) {
   return TemplateDecl->getTemplateArgs().asArray();
   }
 
-  if (const 

[PATCH] D32566: Revert rL301328 and add tests for the regressions introduced.

2017-05-02 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301902: [libclang] Revert rL301328 and add tests for the 
regressions introduced. (authored by emilio).

Changed prior to commit:
  https://reviews.llvm.org/D32566?vs=96838=97407#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32566

Files:
  cfe/trunk/test/Index/print-type.cpp
  cfe/trunk/tools/libclang/CXType.cpp


Index: cfe/trunk/tools/libclang/CXType.cpp
===
--- cfe/trunk/tools/libclang/CXType.cpp
+++ cfe/trunk/tools/libclang/CXType.cpp
@@ -147,16 +147,16 @@
 static Optional
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
+  if (const auto *Specialization = Type->getAs())
+return Specialization->template_arguments();
+
   if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) {
 const auto *TemplateDecl =
   dyn_cast(RecordDecl);
 if (TemplateDecl)
   return TemplateDecl->getTemplateArgs().asArray();
   }
 
-  if (const auto *Specialization = Type->getAs())
-return Specialization->template_arguments();
-
   return None;
 }
 
Index: cfe/trunk/test/Index/print-type.cpp
===
--- cfe/trunk/test/Index/print-type.cpp
+++ cfe/trunk/test/Index/print-type.cpp
@@ -71,10 +71,9 @@
 Specialization templRefParam;
 auto autoTemplRefParam = templRefParam;
 
-template
-struct DefaultedTypeExample {};
-
-typedef DefaultedTypeExample DefaultedTypeAlias;
+template struct A {};
+template using C = T;
+using baz = C;
 
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -120,7 +119,7 @@
 // CHECK: TemplateRef=Baz:9:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] 
[typekind=Record] [type=int] [typekind=Int]] [canonicaltype=outer::Qux] [canonicaltypekind=Record] 
[canonicaltemplateargs/4= [type=int] [typekind=Int] [type=char *] 
[typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] 
[typekind=Int]] [isPOD=1]
+// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=Foo] 
[typekind=Unexposed] [type=outer::inner::Bar::FooType] [typekind=Typedef]] 
[canonicaltype=outer::Qux] 
[canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] 
[type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] 
[type=int] [typekind=Int]] [isPOD=1]
 // CHECK: TemplateRef=Qux:12:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: FunctionTemplate=tbar:36:3 [type=T (int)] [typekind=FunctionProto] 
[canonicaltype=type-parameter-0-0 (int)] [canonicaltypekind=FunctionProto] 
[resulttype=T] [resulttypekind=Unexposed] [isPOD=0]
@@ -183,3 +182,4 @@
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const 
Specialization] [typekind=Unexposed] const 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=const Specialization] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypedefDecl=DefaultedTypeAlias:77:35 (Definition) 
[type=DefaultedTypeAlias] [typekind=Typedef] [templateargs/2= [type=int] 
[typekind=Int] [type=int] [typekind=Int]] 
[canonicaltype=DefaultedTypeExample] [canonicaltypekind=Record] 
[canonicaltemplateargs/2= [type=int] [typekind=Int] [type=int] [typekind=Int]] 
[isPOD=0]
+// CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]


Index: cfe/trunk/tools/libclang/CXType.cpp
===
--- cfe/trunk/tools/libclang/CXType.cpp
+++ cfe/trunk/tools/libclang/CXType.cpp
@@ -147,16 +147,16 @@
 static Optional
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
+  

[PATCH] D32733: [clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding DontAlign

2017-05-02 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes added a comment.

In https://reviews.llvm.org/D32733#743116, @djasper wrote:

> This is an edge case in actual C++. An escaped newline literally gets 
> expanded to nothing. So what this reads is
>
> #define Onetwo \
>  ...


Yeah, I noticed that, but nonetheless it shouldn't break the alignment of \ in 
the subsequent lines...

Thanks for reviewing! I don't have permissions to commit code; could you do it 
for me?


https://reviews.llvm.org/D32733



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


[PATCH] D32733: [clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding DontAlign

2017-05-02 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.

This is an edge case in actual C++. An escaped newline literally gets expanded 
to nothing. So what this reads is

#define Onetwo \
...


https://reviews.llvm.org/D32733



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


[PATCH] D32733: [clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding DontAlign

2017-05-02 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes marked an inline comment as done.
jtbandes added a comment.

This seems to work fine.

Separately I noticed a strange edge case, which I think is an existing bug:

  #define One\
  two   \
three;  
 \
four;

The lack of space in `One\` seems to break the formatting on the next line. But 
as far as I can tell this isn't related to my change.


https://reviews.llvm.org/D32733



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


[PATCH] D32733: [clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding DontAlign

2017-05-02 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes updated this revision to Diff 97404.
jtbandes added a comment.

Modified `appendNewlineText` so we can simply `return` in the DontAlign case.


https://reviews.llvm.org/D32733

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/WhitespaceManager.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestSelective.cpp

Index: unittests/Format/FormatTestSelective.cpp
===
--- unittests/Format/FormatTestSelective.cpp
+++ unittests/Format/FormatTestSelective.cpp
@@ -325,7 +325,7 @@
 }
 
 TEST_F(FormatTestSelective, AlwaysFormatsEntireMacroDefinitions) {
-  Style.AlignEscapedNewlinesLeft = true;
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   EXPECT_EQ("int  i;\n"
 "#define A \\\n"
 "  int i;  \\\n"
@@ -467,7 +467,7 @@
 TEST_F(FormatTestSelective, UnderstandsTabs) {
   Style.IndentWidth = 8;
   Style.UseTab = FormatStyle::UT_Always;
-  Style.AlignEscapedNewlinesLeft = true;
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   EXPECT_EQ("void f() {\n"
 "\tf();\n"
 "\tg();\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -342,7 +342,7 @@
   verifyFormat("if (a)\n  if (b) {\nf();\n  }\ng();");
 
   FormatStyle AllowsMergedIf = getLLVMStyle();
-  AllowsMergedIf.AlignEscapedNewlinesLeft = true;
+  AllowsMergedIf.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
   verifyFormat("if (a)\n"
"  // comment\n"
@@ -6423,7 +6423,7 @@
   EXPECT_EQ("\"some text other\";", format("\"some text other\";", Style));
 
   FormatStyle AlignLeft = getLLVMStyleWithColumns(12);
-  AlignLeft.AlignEscapedNewlinesLeft = true;
+  AlignLeft.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   EXPECT_EQ("#define A \\\n"
 "  \"some \" \\\n"
 "  \"text \" \\\n"
@@ -6824,7 +6824,7 @@
   FormatStyle Tab = getLLVMStyleWithColumns(42);
   Tab.IndentWidth = 8;
   Tab.UseTab = FormatStyle::UT_Always;
-  Tab.AlignEscapedNewlinesLeft = true;
+  Tab.AlignEscapedNewlines = FormatStyle::ENAS_Left;
 
   EXPECT_EQ("if ( && // q\n"
 "bb)\t\t// w\n"
@@ -7605,14 +7605,21 @@
"int oneTwoThree = 123;\n"
"int oneTwo = 12;",
Alignment));
-  Alignment.AlignEscapedNewlinesLeft = true;
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
+  verifyFormat("#define A \\\n"
+   "  int    = 12; \\\n"
+   "  int b  = 23; \\\n"
+   "  int ccc= 234; \\\n"
+   "  int dd = 2345;",
+   Alignment);
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   verifyFormat("#define A   \\\n"
"  int    = 12;  \\\n"
"  int b  = 23;  \\\n"
"  int ccc= 234; \\\n"
"  int dd = 2345;",
Alignment);
-  Alignment.AlignEscapedNewlinesLeft = false;
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Right;
   verifyFormat("#define A  "
"\\\n"
"  int    = 12; "
@@ -7879,14 +7886,21 @@
"}",
Alignment));
   Alignment.AlignConsecutiveAssignments = false;
-  Alignment.AlignEscapedNewlinesLeft = true;
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
+  verifyFormat("#define A \\\n"
+   "  int    = 12; \\\n"
+   "  float b = 23; \\\n"
+   "  const int ccc = 234; \\\n"
+   "  unsigned  dd = 2345;",
+   Alignment);
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   verifyFormat("#define A  \\\n"
"  int    = 12; \\\n"
"  float b = 23;\\\n"
"  const int ccc = 234; \\\n"
"  unsigned  dd = 2345;",
Alignment);
-  Alignment.AlignEscapedNewlinesLeft = false;
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Right;
   Alignment.ColumnLimit = 30;
   verifyFormat("#define A\\\n"
"  int    = 12;   \\\n"
@@ -8671,7 +8685,6 @@
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};
   Style.Language = FormatStyle::LK_Cpp;
-  CHECK_PARSE_BOOL(AlignEscapedNewlinesLeft);
   CHECK_PARSE_BOOL(AlignOperands);
   CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(AlignConsecutiveAssignments);
@@ -8794,6 +8807,19 @@
   CHECK_PARSE("AlignAfterOpenBracket: true", AlignAfterOpenBracket,
   FormatStyle::BAS_Align);
 
+  

[PATCH] D32736: [libcxx][CMake] Set library dir when built under runtimes/

2017-05-02 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld created this revision.
Herald added a subscriber: mgorny.

This will put libraries into the build root's lib/ directory by default.


https://reviews.llvm.org/D32736

Files:
  CMakeLists.txt


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -344,7 +344,11 @@
 set(LIBCXX_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
 set(LIBCXX_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
 set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")
-set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
+if (LLVM_LIBRARY_OUTPUT_INTDIR)
+  set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
+else()
+  set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
+endif()
 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")
 
 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -344,7 +344,11 @@
 set(LIBCXX_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
 set(LIBCXX_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
 set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")
-set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
+if (LLVM_LIBRARY_OUTPUT_INTDIR)
+  set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
+else()
+  set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
+endif()
 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")
 
 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32735: [libcxxabi][CMake] Set library dir when built under runtimes/

2017-05-02 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld created this revision.
Herald added a subscriber: mgorny.
Herald added a reviewer: EricWF.

This will put libraries into the build root's lib/ directory by default.


https://reviews.llvm.org/D32735

Files:
  CMakeLists.txt


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -239,7 +239,11 @@
 set(LIBCXXABI_COMPILER${CMAKE_CXX_COMPILER})
 set(LIBCXXABI_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
 set(LIBCXXABI_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
-set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
+if (LLVM_LIBRARY_OUTPUT_INTDIR)
+  set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
+else()
+  set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
+endif()
 
 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -239,7 +239,11 @@
 set(LIBCXXABI_COMPILER${CMAKE_CXX_COMPILER})
 set(LIBCXXABI_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
 set(LIBCXXABI_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
-set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
+if (LLVM_LIBRARY_OUTPUT_INTDIR)
+  set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
+else()
+  set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
+endif()
 
 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32733: [clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding DontAlign

2017-05-02 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes added inline comments.



Comment at: lib/Format/WhitespaceManager.cpp:523
+  if (C.NewlinesBefore > 0 && C.ContinuesPPDirective)
+C.EscapedNewlineColumn = C.PreviousEndOfTokenColumn + 2;
+return;

djasper wrote:
> I think we should not duplicate this loop. Two alternatives:
> 1. Move this into the other loop. As long as you reset StartOfMacro in each 
> iteration, it should do the right thing.
> 2. Make this work if we just return here. In theory, the "\" should not need 
> any special-casing with this style.
> 
> I'd prefer #2.
I first tried returning here, but the backslashes were butting up against the 
content, as in `int x = foo;\`. I can look around to see if that's fixable.


https://reviews.llvm.org/D32733



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


[PATCH] D32733: [clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding DontAlign

2017-05-02 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added inline comments.



Comment at: lib/Format/WhitespaceManager.cpp:523
+  if (C.NewlinesBefore > 0 && C.ContinuesPPDirective)
+C.EscapedNewlineColumn = C.PreviousEndOfTokenColumn + 2;
+return;

I think we should not duplicate this loop. Two alternatives:
1. Move this into the other loop. As long as you reset StartOfMacro in each 
iteration, it should do the right thing.
2. Make this work if we just return here. In theory, the "\" should not need 
any special-casing with this style.

I'd prefer #2.


https://reviews.llvm.org/D32733



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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-05-02 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: lib/Sema/SemaInit.cpp:875
 
   if (!VerifyOnly) {
 StructuredSubobjectInitList->setType(T);

ruiu wrote:
> Is it intentional that you run the new code only when !VerifyOnly?
I think VerifyOnly is used to check if it is formal verification mode or not, 
and if VerifyOnly == 1, it is supposed to emit no diagnostics. So I think it is 
OK that this code is here, because this part of is code emits -Wmissing-braces 
if braces are not appropriate.


https://reviews.llvm.org/D32646



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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-05-02 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 97398.
yamaguchi marked 2 inline comments as done.
yamaguchi added a comment.

Fixed spaces and changed SpellingLoc from two lines to one line.


https://reviews.llvm.org/D32646

Files:
  lib/Sema/SemaInit.cpp
  test/Sema/warn-missing-braces.c


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} 
expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,8 +885,15 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
-if (T->isArrayType() || T->isRecordType()) {
+// Complain about missing braces when rhs is not a macro from system 
header.
+// getSpellingLoc() isn't cheap, so only call it if the warning is enabled.
+if ((T->isArrayType() || T->isRecordType()) &&
+!SemaRef.Diags.isIgnored(diag::warn_missing_braces,
+ StructuredSubobjectInitList->getLocStart())) {
+  SourceLocation SpellingLoc = 
SemaRef.getSourceManager().getSpellingLoc(StructuredSubobjectInitList->getLocStart());
+  if (SpellingLoc.isValid() &&
+  SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))
+return;
   SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
diag::warn_missing_braces)
   << StructuredSubobjectInitList->getSourceRange()


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,8 +885,15 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
-if (T->isArrayType() || T->isRecordType()) {
+// Complain about missing braces when rhs is not a macro from system header.
+// getSpellingLoc() isn't cheap, so only call it if the warning is enabled.
+if ((T->isArrayType() || T->isRecordType()) &&
+!SemaRef.Diags.isIgnored(diag::warn_missing_braces,
+ StructuredSubobjectInitList->getLocStart())) {
+  SourceLocation SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(StructuredSubobjectInitList->getLocStart());
+  if (SpellingLoc.isValid() &&
+  SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))
+return;
   SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
diag::warn_missing_braces)
   << StructuredSubobjectInitList->getSourceRange()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32733: [clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding DontAlign

2017-05-02 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes created this revision.
Herald added a subscriber: klimek.

This converts the clang-format option `AlignEscapedNewlinesLeft` from a boolean 
to an enum, named `AlignEscapedNewlines`, with options `Left` (prev. `true`), 
`Right` (prev. `false`), and a new option `DontAlign`.

When set to `DontAlign`, the backslashes are placed just after the last token 
in each line:

  #define EXAMPLE \
  do { \
  int x = a; \
  int b; \
  int dd; \
  } while (0)


https://reviews.llvm.org/D32733

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/WhitespaceManager.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestSelective.cpp

Index: unittests/Format/FormatTestSelective.cpp
===
--- unittests/Format/FormatTestSelective.cpp
+++ unittests/Format/FormatTestSelective.cpp
@@ -325,7 +325,7 @@
 }
 
 TEST_F(FormatTestSelective, AlwaysFormatsEntireMacroDefinitions) {
-  Style.AlignEscapedNewlinesLeft = true;
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   EXPECT_EQ("int  i;\n"
 "#define A \\\n"
 "  int i;  \\\n"
@@ -467,7 +467,7 @@
 TEST_F(FormatTestSelective, UnderstandsTabs) {
   Style.IndentWidth = 8;
   Style.UseTab = FormatStyle::UT_Always;
-  Style.AlignEscapedNewlinesLeft = true;
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   EXPECT_EQ("void f() {\n"
 "\tf();\n"
 "\tg();\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -342,7 +342,7 @@
   verifyFormat("if (a)\n  if (b) {\nf();\n  }\ng();");
 
   FormatStyle AllowsMergedIf = getLLVMStyle();
-  AllowsMergedIf.AlignEscapedNewlinesLeft = true;
+  AllowsMergedIf.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
   verifyFormat("if (a)\n"
"  // comment\n"
@@ -6423,7 +6423,7 @@
   EXPECT_EQ("\"some text other\";", format("\"some text other\";", Style));
 
   FormatStyle AlignLeft = getLLVMStyleWithColumns(12);
-  AlignLeft.AlignEscapedNewlinesLeft = true;
+  AlignLeft.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   EXPECT_EQ("#define A \\\n"
 "  \"some \" \\\n"
 "  \"text \" \\\n"
@@ -6824,7 +6824,7 @@
   FormatStyle Tab = getLLVMStyleWithColumns(42);
   Tab.IndentWidth = 8;
   Tab.UseTab = FormatStyle::UT_Always;
-  Tab.AlignEscapedNewlinesLeft = true;
+  Tab.AlignEscapedNewlines = FormatStyle::ENAS_Left;
 
   EXPECT_EQ("if ( && // q\n"
 "bb)\t\t// w\n"
@@ -7605,14 +7605,21 @@
"int oneTwoThree = 123;\n"
"int oneTwo = 12;",
Alignment));
-  Alignment.AlignEscapedNewlinesLeft = true;
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
+  verifyFormat("#define A \\\n"
+   "  int    = 12; \\\n"
+   "  int b  = 23; \\\n"
+   "  int ccc= 234; \\\n"
+   "  int dd = 2345;",
+   Alignment);
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   verifyFormat("#define A   \\\n"
"  int    = 12;  \\\n"
"  int b  = 23;  \\\n"
"  int ccc= 234; \\\n"
"  int dd = 2345;",
Alignment);
-  Alignment.AlignEscapedNewlinesLeft = false;
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Right;
   verifyFormat("#define A  "
"\\\n"
"  int    = 12; "
@@ -7879,14 +7886,21 @@
"}",
Alignment));
   Alignment.AlignConsecutiveAssignments = false;
-  Alignment.AlignEscapedNewlinesLeft = true;
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
+  verifyFormat("#define A \\\n"
+   "  int    = 12; \\\n"
+   "  float b = 23; \\\n"
+   "  const int ccc = 234; \\\n"
+   "  unsigned  dd = 2345;",
+   Alignment);
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   verifyFormat("#define A  \\\n"
"  int    = 12; \\\n"
"  float b = 23;\\\n"
"  const int ccc = 234; \\\n"
"  unsigned  dd = 2345;",
Alignment);
-  Alignment.AlignEscapedNewlinesLeft = false;
+  Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Right;
   Alignment.ColumnLimit = 30;
   verifyFormat("#define A\\\n"
"  int    = 12;   \\\n"
@@ -8671,7 +8685,6 @@
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};