[PATCH] D46834: [Sema][Cxx17] Error message for C++17 static_assert(pred) without string literal

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

The code looks correct to me, although I have a few suggestions inline.  When 
you resubmit, please include full context (e.g., `git diff -U99`).

Jan and I discussed this ahead of time and I agree with adding the assertion as 
the message.  However, I'd rather hear from others before signing off.




Comment at: lib/Sema/SemaDeclCXX.cpp:13739-13740
   SmallString<256> MsgBuffer;
-  llvm::raw_svector_ostream Msg(MsgBuffer);
-  if (AssertMessage)
-AssertMessage->printPretty(Msg, nullptr, getPrintingPolicy());
+  {
+llvm::raw_svector_ostream Msg(MsgBuffer);
+if (AssertMessage)

Is this extra nesting necessary?



Comment at: lib/Sema/SemaDeclCXX.cpp:13744-13746
+  AssertExpr->printPretty(Msg, nullptr, getPrintingPolicy());
+  MsgBuffer.insert(MsgBuffer.begin(), '\"');
+  MsgBuffer.append(1, '\"');

Inserting to the beginning of the buffer seems a bit weird, especially since 
you're jumping between `Msg` and `MsgBuffer`.

This feels more natural to me:

```
Msg << '"';
AssertExpr->printPretty(Msg, nullptr, getPrintingPolicy());
Msg << '"';
```



Comment at: lib/Sema/SemaDeclCXX.cpp:13761
 Diag(StaticAssertLoc, diag::err_static_assert_failed)
-  << !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
+  << MsgBuffer.empty() << MsgBuffer.str()
+  << AssertExpr->getSourceRange();

Is there always a message now?  If so, can you just assert that before the `if` 
statement and simplify this code?


Repository:
  rC Clang

https://reviews.llvm.org/D46834



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


[libclc] r332324 - rootn: Use denormal path only

2018-05-14 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Mon May 14 21:22:43 2018
New Revision: 332324

URL: http://llvm.org/viewvc/llvm-project?rev=332324=rev
Log:
rootn: Use denormal path only

It's OK to either flush to 0 or return denormal result if the device
does not support denormals. See sec 7.2 and 7.5.3 of OCL specs
Use 0.0f explicitly intead of relying on GPU to flush it.
Fixes CTS on carrizo and turks

Signed-off-by: Jan Vesely 
Acked-by: Aaron Watry 
Tested-by: Aaron Watry 

Modified:
libclc/trunk/generic/lib/math/clc_rootn.cl

Modified: libclc/trunk/generic/lib/math/clc_rootn.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_rootn.cl?rev=332324=332323=332324=diff
==
--- libclc/trunk/generic/lib/math/clc_rootn.cl (original)
+++ libclc/trunk/generic/lib/math/clc_rootn.cl Mon May 14 21:22:43 2018
@@ -170,16 +170,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_rootn
 tv = USE_TABLE(exp_tbl_ep, j);
 
 float expylogx = mad(tv.s0, poly, mad(tv.s1, poly, tv.s1)) + tv.s0;
-float sexpylogx;
-if (!__clc_fp32_subnormals_supported()) {
-   int explg = ((as_uint(expylogx) & EXPBITS_SP32 >> 23) - 127);
-   m = (23-(m + 149)) == 0 ? 1: m;
-   uint mantissa =  ((as_uint(expylogx) & 
MANTBITS_SP32)|IMPBIT_SP32) >> (23-(m + 149));
-   sexpylogx = as_float(mantissa);
-} else {
-   sexpylogx = expylogx * as_float(0x1 << (m + 149));
-}
-
+float sexpylogx = __clc_fp32_subnormals_supported() ? expylogx * 
as_float(0x1 << (m + 149)) : 0.0f;
 
 float texpylogx = as_float(as_int(expylogx) + m2);
 expylogx = m < -125 ? sexpylogx : texpylogx;


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


r332322 - [X86] Revert part of r332266: Use __builtin_convertvector to replace some of the avx512 truncate builtins.

2018-05-14 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Mon May 14 20:17:52 2018
New Revision: 332322

URL: http://llvm.org/viewvc/llvm-project?rev=332322=rev
Log:
[X86] Revert part of r332266: Use __builtin_convertvector to replace some of 
the avx512 truncate builtins.

The masking doesn't work right in the backend for the ones that produce byte or 
word elements without avx512bw.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/lib/Headers/avx512vlintrin.h
cfe/trunk/test/CodeGen/avx512f-builtins.c
cfe/trunk/test/CodeGen/avx512vl-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=332322=332321=332322=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Mon May 14 20:17:52 2018
@@ -1717,12 +1717,15 @@ TARGET_BUILTIN(__builtin_ia32_pmovusqw12
 TARGET_BUILTIN(__builtin_ia32_pmovusqw128mem_mask, "vV8s*V2LLiUc", "n", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusqw256_mask, "V8sV4LLiV8sUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusqw256mem_mask, "vV8s*V4LLiUc", "n", 
"avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovdb512_mask, "V16cV16iV16cUs", "nc", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovdb512mem_mask, "vV16c*V16iUs", "n", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovwb512mem_mask, "vV32c*V32sUi", "n", 
"avx512bw")
+TARGET_BUILTIN(__builtin_ia32_pmovdw512_mask, "V16sV16iV16sUs", "nc", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovdw512mem_mask, "vV16s*V16iUs", "n", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqb512_mask, "V16cV8LLiV16cUc", "nc", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqb512mem_mask, "vV16c*V8LLiUc", "n", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqd512mem_mask, "vV8i*V8LLiUc", "n", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmovqw512_mask, "V8sV8LLiV8sUc", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqw512mem_mask, "vV8s*V8LLiUc", "n", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovdb128_mask, "V16cV4iV16cUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovwb128mem_mask, "vV16c*V8sUc", "n", 
"avx512vl,avx512bw")
@@ -1732,6 +1735,7 @@ TARGET_BUILTIN(__builtin_ia32_pmovdb256m
 TARGET_BUILTIN(__builtin_ia32_pmovwb256mem_mask, "vV16c*V16sUs", "n", 
"avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_pmovdw128_mask, "V8sV4iV8sUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovdw128mem_mask, "vV8s*V4iUc", "n", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovdw256_mask, "V8sV8iV8sUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovdw256mem_mask, "vV8s*V8iUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqb128_mask, "V16cV2LLiV16cUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqb128mem_mask, "vV16c*V2LLiUc", "n", 
"avx512vl")

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=332322=332321=332322=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Mon May 14 20:17:52 2018
@@ -7607,17 +7607,16 @@ _mm512_cvtepi32_epi8 (__m512i __A)
 static __inline__ __m128i __DEFAULT_FN_ATTRS
 _mm512_mask_cvtepi32_epi8 (__m128i __O, __mmask16 __M, __m512i __A)
 {
-  return (__m128i)__builtin_ia32_selectb_128((__mmask8)__M,
- 
(__v16qi)_mm512_cvtepi32_epi8(__A),
- (__v16qi)__O);
+  return (__m128i) __builtin_ia32_pmovdb512_mask ((__v16si) __A,
+  (__v16qi) __O, __M);
 }
 
 static __inline__ __m128i __DEFAULT_FN_ATTRS
 _mm512_maskz_cvtepi32_epi8 (__mmask16 __M, __m512i __A)
 {
-  return (__m128i)__builtin_ia32_selectb_128((__mmask8)__M,
- 
(__v16qi)_mm512_cvtepi32_epi8(__A),
- (__v16qi)_mm_setzero_si128());
+  return (__m128i) __builtin_ia32_pmovdb512_mask ((__v16si) __A,
+  (__v16qi) _mm_setzero_si128 (),
+  __M);
 }
 
 static __inline__ void __DEFAULT_FN_ATTRS
@@ -7635,17 +7634,16 @@ _mm512_cvtepi32_epi16 (__m512i __A)
 static __inline__ __m256i __DEFAULT_FN_ATTRS
 _mm512_mask_cvtepi32_epi16 (__m256i __O, __mmask16 __M, __m512i __A)
 {
-  return (__m256i)__builtin_ia32_selectw_256((__mmask16)__M,
- 
(__v16hi)_mm512_cvtepi32_epi16(__A),
- (__v16hi)__O);
+  return (__m256i) __builtin_ia32_pmovdw512_mask ((__v16si) __A,
+  (__v16hi) __O, __M);
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS
 _mm512_maskz_cvtepi32_epi16 (__mmask16 __M, __m512i __A)
 {
-  return (__m256i)__builtin_ia32_selectw_256((__mmask16)__M,
-   

[PATCH] D44888: [RISCV] Default enable linker relaxation and add -mrelax, -mno-relax flags

2018-05-14 Thread Shiva Chen via Phabricator via cfe-commits
shiva0217 added inline comments.



Comment at: lib/Driver/ToolChains/Arch/RISCV.cpp:130
+  // which may override the defaults.
+  handleTargetFeaturesGroup(Args, Features, 
options::OPT_m_riscv_Features_Group);
 }

kito-cheng wrote:
> This part should  move to the begin of the function, otherwise it never 
> executed if `Exts` is empty string.
> 
Hi Kito. I have rebased the patch to D45465. Could you help me to check when 
you download raw diff and apply with `patch -p0<` does it still patch to the 
wrong function?


Repository:
  rL LLVM

https://reviews.llvm.org/D44888



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


[PATCH] D44888: [RISCV] Default enable linker relaxation and add -mrelax, -mno-relax flags

2018-05-14 Thread Shiva Chen via Phabricator via cfe-commits
shiva0217 updated this revision to Diff 146737.
shiva0217 added a comment.

Rebase patch to https://reviews.llvm.org/D45465


Repository:
  rL LLVM

https://reviews.llvm.org/D44888

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Arch/RISCV.cpp
  test/Driver/riscv-features.c


Index: test/Driver/riscv-features.c
===
--- test/Driver/riscv-features.c
+++ test/Driver/riscv-features.c
@@ -2,3 +2,9 @@
 // RUN: %clang -target riscv64-unknown-elf -### %s -fsyntax-only 2>&1 | 
FileCheck %s
 
 // CHECK: fno-signed-char
+
+// RUN: %clang -target riscv32-unknown-elf -### %s -mrelax 2>&1 | FileCheck %s 
-check-prefix=RELAX
+// RUN: %clang -target riscv32-unknown-elf -### %s -mno-relax 2>&1 | FileCheck 
%s -check-prefix=NO-RELAX
+
+// RELAX: "-target-feature" "+relax"
+// NO-RELAX: "-target-feature" "-relax"
Index: lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- lib/Driver/ToolChains/Arch/RISCV.cpp
+++ lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -15,6 +15,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
+#include "ToolChains/CommonArgs.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -363,6 +364,21 @@
 // Handle all other types of extensions.
 getExtensionFeatures(D, Args, Features, MArch, OtherExts);
   }
+
+  // -mrelax is default, unless -mno-relax is specified.
+  bool Relax = true;
+  if (auto *A = Args.getLastArg(options::OPT_mrelax, options::OPT_mno_relax))
+if (A->getOption().matches(options::OPT_mno_relax)) {
+  Relax = false;
+  Features.push_back("-relax");
+}
+
+  if (Relax)
+Features.push_back("+relax");
+
+  // Now add any that the user explicitly requested on the command line,
+  // which may override the defaults.
+  handleTargetFeaturesGroup(Args, Features, 
options::OPT_m_riscv_Features_Group);
 }
 
 StringRef riscv::getRISCVABI(const ArgList , const llvm::Triple ) {
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -151,6 +151,8 @@
 Group, DocName<"WebAssembly">;
 def m_x86_Features_Group : OptionGroup<"">,
Group, Flags<[CoreOption]>, DocName<"X86">;
+def m_riscv_Features_Group : OptionGroup<"">,
+ Group, DocName<"RISCV">;
 
 def m_libc_Group : OptionGroup<"">, Group,
Flags<[HelpHidden]>;
@@ -1950,6 +1952,11 @@
 def mno_soft_float : Flag<["-"], "mno-soft-float">, Group;
 def mno_stackrealign : Flag<["-"], "mno-stackrealign">, Group;
 
+def mrelax : Flag<["-"], "mrelax">, Group,
+  HelpText<"Enable linker relaxation">;
+def mno_relax : Flag<["-"], "mno-relax">, Group,
+  HelpText<"Disable linker relaxation">;
+
 def munaligned_access : Flag<["-"], "munaligned-access">, 
Group,
   HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64 only)">;
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, 
Group,


Index: test/Driver/riscv-features.c
===
--- test/Driver/riscv-features.c
+++ test/Driver/riscv-features.c
@@ -2,3 +2,9 @@
 // RUN: %clang -target riscv64-unknown-elf -### %s -fsyntax-only 2>&1 | FileCheck %s
 
 // CHECK: fno-signed-char
+
+// RUN: %clang -target riscv32-unknown-elf -### %s -mrelax 2>&1 | FileCheck %s -check-prefix=RELAX
+// RUN: %clang -target riscv32-unknown-elf -### %s -mno-relax 2>&1 | FileCheck %s -check-prefix=NO-RELAX
+
+// RELAX: "-target-feature" "+relax"
+// NO-RELAX: "-target-feature" "-relax"
Index: lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- lib/Driver/ToolChains/Arch/RISCV.cpp
+++ lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -15,6 +15,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
+#include "ToolChains/CommonArgs.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -363,6 +364,21 @@
 // Handle all other types of extensions.
 getExtensionFeatures(D, Args, Features, MArch, OtherExts);
   }
+
+  // -mrelax is default, unless -mno-relax is specified.
+  bool Relax = true;
+  if (auto *A = Args.getLastArg(options::OPT_mrelax, options::OPT_mno_relax))
+if (A->getOption().matches(options::OPT_mno_relax)) {
+  Relax = false;
+  Features.push_back("-relax");
+}
+
+  if (Relax)
+Features.push_back("+relax");
+
+  // Now add any that the user explicitly requested on the command line,
+  // which may override the defaults.
+  handleTargetFeaturesGroup(Args, Features, options::OPT_m_riscv_Features_Group);
 }
 
 StringRef riscv::getRISCVABI(const ArgList , const llvm::Triple ) {
Index: include/clang/Driver/Options.td

[PATCH] D45766: [Sema] Add -Wno-self-assign-overloaded

2018-05-14 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

In https://reviews.llvm.org/D45766#1097797, @ksu.shadura wrote:

> Thank you for the test example! I got your point, but I wanted to ask if it 
> should be like this for commutative operations?
>  In our case it is actually matrix, and subtraction of matrices is not 
> commutative operation..


Mathematical commutativity has nothing to do with this diagnostic. The 
diagnostic is complaining that `m1 -= m1` produces a trivial effect (in this 
case `m1.clear()`) via a syntax that might indicate that the programmer made a 
typo (i.e. the compiler suspects that you meant `m -= m1` or something).
From the function name `stress_...`, I infer that this is a unit-test. This 
warning is known to give "false positives" in unit-test code, where one often 
actually wants to achieve trivial effects through complicated code. The current 
recommendation there, AFAIK, is either to write something like

  m1 -= static_cast(m1);  // hide the self-subtraction from the 
compiler

or else to add `-Wno-self-assign-overloaded` to your compiler flags. (libc++'s 
test suite already passes `-Wno-unused-command-line-argument -Wno-attributes 
-Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals 
-Wno-conversion -Wno-unused-local-typedef -Wno-#warnings`, for example.)
(That said, I continue to think that this diagnostic produces more noise than 
signal, and wish it weren't in `-Wall`...)


Repository:
  rL LLVM

https://reviews.llvm.org/D45766



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


[PATCH] D10833: Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface

2018-05-14 Thread Ian Sunamura via Phabricator via cfe-commits
kent08ian added a comment.

In https://reviews.llvm.org/D10833#970906, @milianw wrote:

> still looks good to me. can someone else please review and commit this?


Any updates on this? This feature will be very helpful. :)


Repository:
  rC Clang

https://reviews.llvm.org/D10833



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


[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332314: [AST] Fix printing tag decl groups in decl contexts 
(authored by jdenny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45465?vs=146709=146727#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45465

Files:
  cfe/trunk/lib/AST/DeclPrinter.cpp
  cfe/trunk/test/Misc/ast-print-enum-decl.c
  cfe/trunk/test/Misc/ast-print-record-decl.c
  cfe/trunk/test/Sema/ast-print.c
  cfe/trunk/test/SemaCXX/ast-print.cpp

Index: cfe/trunk/test/Misc/ast-print-enum-decl.c
===
--- cfe/trunk/test/Misc/ast-print-enum-decl.c
+++ cfe/trunk/test/Misc/ast-print-enum-decl.c
@@ -83,3 +83,23 @@
   // PRINT-NEXT: enum T *p4;
   enum T *p4;
 }
+
+// Check that tag decl groups stay together in decl contexts.
+
+// PRINT-LABEL: enum DeclGroupAtFileScope {
+// PRINT-NEXT:DeclGroupAtFileScope0
+// PRINT-NEXT:  } *DeclGroupAtFileScopePtr;
+enum DeclGroupAtFileScope { DeclGroupAtFileScope0 } *DeclGroupAtFileScopePtr;
+
+// PRINT-LABEL: struct DeclGroupInMemberList
+struct DeclGroupInMemberList {
+  // PRINT-NEXT:  enum T1 {
+  // PRINT-NEXT:T10
+  // PRINT-NEXT:  } *p0;
+  enum T1 { T10 } *p0;
+  // PRINT-NEXT:  enum T2 {
+  // PRINT-NEXT:T20
+  // PRINT-NEXT:  } *p1, *p2;
+  enum T2 { T20 } *p1, *p2;
+  // PRINT-NEXT: };
+};
Index: cfe/trunk/test/Misc/ast-print-record-decl.c
===
--- cfe/trunk/test/Misc/ast-print-record-decl.c
+++ cfe/trunk/test/Misc/ast-print-record-decl.c
@@ -7,8 +7,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -19,7 +19,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \
+//   RUN: -DBASES= %s
 
 // Repeat for union:
 //
@@ -30,8 +31,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -42,7 +43,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \
+//   RUN: -DBASES= %s
 
 // Repeat for C++ (BASES helps ensure we're printing as C++ not as C):
 //
@@ -54,7 +56,7 @@
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
 //   RUN: > %t.cpp
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN:   -DBASES=' : B' %s --input-file %t.cpp
 //
 //   Now check compiling and printing of the printed file.
@@ -66,7 +68,7 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.cpp \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN: -DBASES=' : B' %s
 
 // END.
@@ -155,25 +157,33 @@
   // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}}
   KW __attribute__((deprecated(""))) T *p0;
 
-  // PRINT-NEXT: [[KW]] __attribute__((aligned(16))) T[[BASES]] {
-  // PRINT-NEXT:   int i;
-  // PRINT-NEXT:   [[KW]] T *p2;
-  // PRINT-NEXT: } *p1;
-  KW __attribute__((aligned(16))) T BASES { // expected-warning {{'T' is deprecated}}
+  // PRINT-NEXT:  [[KW]] __attribute__((aligned(64))) T[[BASES]] {
+  // PRINT-NEXT:int i;
+  // PRINT-NEXT:[[KW]] T *p2;
+  // PRINT-NEXT:[[KW]] __attribute__((may_alias)) T *p3;
+  // PRINT-NEXT:[[KW]] T *p4;
+  // PRINT-NEXT:  } *p1;
+  KW __attribute__((aligned(64))) T BASES { // expected-warning {{'T' is deprecated}}
 int i;
 KW T *p2;
+// FIXME: For C++, T at p3 loses aligned and deprecated, perhaps because
+// that RecordDecl isn't in the same redecl list.  Perhaps the redecl lists
+// are split here but not in C due to the different scoping rules in C++
+

r332314 - [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Joel E. Denny via cfe-commits
Author: jdenny
Date: Mon May 14 17:44:14 2018
New Revision: 332314

URL: http://llvm.org/viewvc/llvm-project?rev=332314=rev
Log:
[AST] Fix printing tag decl groups in decl contexts

For example, given:

  struct T1 {
struct T2 *p0;
  };

-ast-print produced:

  struct T1 {
struct T2;
struct T2 *p0;
  };

Compiling that produces a warning that the first struct T2 declaration
does not declare anything.

Details:

A tag decl group is one or more decls that share a type specifier that
is a tag decl (that is, a struct/union/class/enum decl).  Within
functions, the parser builds such a tag decl group as part of a
DeclStmt.  However, in decl contexts, such as file scope or a member
list, the parser does not group together the members of a tag decl
group.  Previously, detection of tag decl groups during printing was
implemented but only if the tag decl was unnamed.  Otherwise, as in
the above example, the members of the group did not print together and
so sometimes introduced warnings.

This patch extends detection of tag decl groups in decl contexts to
any tag decl that is recorded in the AST as not free-standing.

Reviewed by: rsmith

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

Modified:
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/test/Misc/ast-print-enum-decl.c
cfe/trunk/test/Misc/ast-print-record-decl.c
cfe/trunk/test/Sema/ast-print.c
cfe/trunk/test/SemaCXX/ast-print.cpp

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=332314=332313=332314=diff
==
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Mon May 14 17:44:14 2018
@@ -375,21 +375,23 @@ void DeclPrinter::VisitDeclContext(DeclC
   !isa(DC))
 continue;
 
-// The next bits of code handles stuff like "struct {int x;} a,b"; we're
+// The next bits of code handle stuff like "struct {int x;} a,b"; we're
 // forced to merge the declarations because there's no other way to
-// refer to the struct in question.  This limited merging is safe without
-// a bunch of other checks because it only merges declarations directly
-// referring to the tag, not typedefs.
+// refer to the struct in question.  When that struct is named instead, we
+// also need to merge to avoid splitting off a stand-alone struct
+// declaration that produces the warning ext_no_declarators in some
+// contexts.
+//
+// This limited merging is safe without a bunch of other checks because it
+// only merges declarations directly referring to the tag, not typedefs.
 //
 // Check whether the current declaration should be grouped with a previous
-// unnamed struct.
+// non-free-standing tag declaration.
 QualType CurDeclType = getDeclType(*D);
 if (!Decls.empty() && !CurDeclType.isNull()) {
   QualType BaseType = GetBaseType(CurDeclType);
-  if (!BaseType.isNull() && isa(BaseType))
-BaseType = cast(BaseType)->getNamedType();
-  if (!BaseType.isNull() && isa(BaseType) &&
-  cast(BaseType)->getDecl() == Decls[0]) {
+  if (!BaseType.isNull() && isa(BaseType) &&
+  cast(BaseType)->getOwnedTagDecl() == Decls[0]) {
 Decls.push_back(*D);
 continue;
   }
@@ -399,9 +401,9 @@ void DeclPrinter::VisitDeclContext(DeclC
 if (!Decls.empty())
   ProcessDeclGroup(Decls);
 
-// If the current declaration is an unnamed tag type, save it
+// If the current declaration is not a free standing declaration, save it
 // so we can merge it with the subsequent declaration(s) using it.
-if (isa(*D) && !cast(*D)->getIdentifier()) {
+if (isa(*D) && !cast(*D)->isFreeStanding()) {
   Decls.push_back(*D);
   continue;
 }

Modified: cfe/trunk/test/Misc/ast-print-enum-decl.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-print-enum-decl.c?rev=332314=332313=332314=diff
==
--- cfe/trunk/test/Misc/ast-print-enum-decl.c (original)
+++ cfe/trunk/test/Misc/ast-print-enum-decl.c Mon May 14 17:44:14 2018
@@ -83,3 +83,23 @@ void declsOnly() {
   // PRINT-NEXT: enum T *p4;
   enum T *p4;
 }
+
+// Check that tag decl groups stay together in decl contexts.
+
+// PRINT-LABEL: enum DeclGroupAtFileScope {
+// PRINT-NEXT:DeclGroupAtFileScope0
+// PRINT-NEXT:  } *DeclGroupAtFileScopePtr;
+enum DeclGroupAtFileScope { DeclGroupAtFileScope0 } *DeclGroupAtFileScopePtr;
+
+// PRINT-LABEL: struct DeclGroupInMemberList
+struct DeclGroupInMemberList {
+  // PRINT-NEXT:  enum T1 {
+  // PRINT-NEXT:T10
+  // PRINT-NEXT:  } *p0;
+  enum T1 { T10 } *p0;
+  // PRINT-NEXT:  enum T2 {
+  // PRINT-NEXT:T20
+  // PRINT-NEXT:  } *p1, *p2;
+  enum T2 { T20 } *p1, *p2;
+  // PRINT-NEXT: };
+};

Modified: cfe/trunk/test/Misc/ast-print-record-decl.c

[PATCH] D46485: Add python tool to dump and construct header maps

2018-05-14 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Ping


Repository:
  rC Clang

https://reviews.llvm.org/D46485



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


[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D45465#1098710, @rsmith wrote:

> Looks good, thanks.


Thanks.

> It strikes me that this will still lead to inconsistencies. For example, I 
> expect this:
> 
>   struct A { struct B *a, *b; struct B *c, *d; };
> 
> 
> ... to print as:
> 
>   struct A {
> struct B *a, *b;
> struct B *c;
> struct B *d;
>   };
> 
> 
> ... where the first two are joined because their type owns a declaration of 
> `struct B`, and the second two are not joined because their type does not own 
> a declaration (it just has a reference to the already-existing declaration of 
> `struct B`). One (somewhat hacky) way to address this would be to compare the 
> starting source locations of a sequence of `DeclaratorDecl`s and group them 
> if it's the same.

While it would be nice to fix that, I'm not as concerned because, AFAICT, that 
doesn't ever change the semantics.


https://reviews.llvm.org/D45465



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


[PATCH] D46822: [RISCV] Add driver for riscv32-unknown-elf baremetal target

2018-05-14 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Could you include some documentation for how to construct a baremetal 
environment like the one this code expects?  It's not clear what exactly you 
expect to be installed where.


Repository:
  rC Clang

https://reviews.llvm.org/D46822



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


[PATCH] D46823: [analyzer] const init: handle non-explicit cases more accurately

2018-05-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Yay thanks!

I think some cornercases would need to be dealt with.




Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1650
+
+// If there is a list, but no init, it must be zero.
+if (i >= InitList->getNumInits())

NoQ wrote:
> Would this work correctly if the element is not of an integral or enumeration 
> type? I think this needs an explicit check.
What if we have an out-of-bounds access to a variable-length array? I don't 
think it'd yield zero.



Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1650-1652
+// If there is a list, but no init, it must be zero.
+if (i >= InitList->getNumInits())
+  return svalBuilder.makeZeroVal(R->getElementType());

Would this work correctly if the element is not of an integral or enumeration 
type? I think this needs an explicit check.



Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1733
+  } else {
+return svalBuilder.makeZeroVal(Ty);
+  }

Same: would this work correctly if the field is not of an integral or 
enumeration type?



Comment at: test/Analysis/initialization.c:3
+
+void clang_analyzer_dump(int);
 

We try to avoid using `dump()` on tests because it makes tests test the dump 
syntax, which isn't the point.

For checking constants, it's easier to do something like 
`clang_analyzer_eval(parr[i] == 2); // expected-warning{{TRUE}}`.

For finding undefined values, you can enable `core.uninitialized` checkers and 
receive warnings when the argument of `clang_analyzer_eval` is an uninitialized 
value. Or just increment the value.


Repository:
  rC Clang

https://reviews.llvm.org/D46823



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


r332310 - Enable control flow pruning of float overflow warnings.

2018-05-14 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Mon May 14 16:21:48 2018
New Revision: 332310

URL: http://llvm.org/viewvc/llvm-project?rev=332310=rev
Log:
Enable control flow pruning of float overflow warnings.

Like other conversion warnings, allow float overflow warnings to be disabled
in known dead paths of template instantiation.  This often occurs when a
template template type is a numeric type and the template will check the
range of the numeric type before performing the conversion.

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/warn-float-conversion.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=332310=332309=332310=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon May 14 16:21:48 2018
@@ -9673,7 +9673,8 @@ static void DiagnoseFloatingImpCast(Sema
 return DiagnoseImpCast(
 S, E, T, CContext,
 IsLiteral ? diag::warn_impcast_literal_float_to_integer_out_of_range
-  : diag::warn_impcast_float_to_integer_out_of_range);
+  : diag::warn_impcast_float_to_integer_out_of_range,
+PruneWarnings);
 
   unsigned DiagID = 0;
   if (IsLiteral) {

Modified: cfe/trunk/test/SemaCXX/warn-float-conversion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-float-conversion.cpp?rev=332310=332309=332310=diff
==
--- cfe/trunk/test/SemaCXX/warn-float-conversion.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-float-conversion.cpp Mon May 14 16:21:48 2018
@@ -89,4 +89,38 @@ void TestOverflow() {
 
   char e = 1.0 / 0.0;  // expected-warning{{implicit conversion of out of 
range value from 'double' to 'char' is undefined}}
 }
+
+
+template 
+class Check {
+ public:
+  static constexpr bool Safe();
+};
+
+template<>
+constexpr bool Check::Safe() { return false; }
+
+template<>
+constexpr bool Check::Safe() { return true; }
+
+template 
+T run1(T t) {
+  const float ret = 800;
+  return ret;  // expected-warning {{implicit conversion of out of range value 
from 'const float' to 'char' is undefined}}
+}
+
+template 
+T run2(T t) {
+  const float ret = 800;
+  if (Check::Safe())
+return ret;
+  else
+return t;
+}
+
+void test() {
+  float a = run1(a) + run2(a);
+  char b = run1(b) + run2(b);  // expected-note {{in instantiation of function 
template specialization 'run1' requested here}}
+}
+
 #endif  // OVERFLOW


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


[PATCH] D46834: [Sema][Cxx17] Error message for C++17 static_assert(pred) without string literal

2018-05-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

This would violate our guidelines for diagnostic messages; see 
https://clang.llvm.org/docs/InternalsManual.html#the-format-string

In particular: "Take advantage of location information. The user will be able 
to see the line and location of the caret, so you don’t need to tell them that 
the problem is with the 4th argument to the function: just point to it."

> Reasons why printing assert expression in absence of string literal is useful 
> are:
> 
> 1. Serialized diagnostics (--serialize-diagnostics) don't contain code 
> snippet and thus error message lack context.
> 2. Not all tools scraping clang diagnostics use caret snippet provided by 
> -fcaret-diagnostics.

This seems like an excellent reason to fix those tools -- per our 
documentation, Clang's diagnostics are not designed to be used without the 
caret and snippet.

If you want to change our diagnostic policy from "the diagnostic text plus the 
line and location of the caret should be enough to identify the problem; do not 
repeat information in the diagnostic that the caret portion shows" to "the 
diagnostic text alone should be sufficient", that's certainly something we can 
discuss, but you'll need to make the case for why that's a good change of 
policy.


Repository:
  rC Clang

https://reviews.llvm.org/D46834



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


[PATCH] D46159: [clang-tidy] Add a flag to enable alpha checkers

2018-05-14 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 updated this revision to Diff 146719.
pfultz2 added a comment.

Rebased


https://reviews.llvm.org/D46159

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidy.h
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tidy/tool/ClangTidyMain.cpp
  test/clang-tidy/enable-alpha-checks.cpp

Index: test/clang-tidy/enable-alpha-checks.cpp
===
--- /dev/null
+++ test/clang-tidy/enable-alpha-checks.cpp
@@ -0,0 +1,6 @@
+// Check if '-allow-enabling-analyzer-alpha-checkers' is visible for users.
+// RUN: clang-tidy -help | not grep 'allow-enabling-analyzer-alpha-checkers'
+
+// Check if '-allow-enabling-analyzer-alpha-checkers' enables alpha checks.
+// RUN: clang-tidy -checks=* -list-checks | not grep 'clang-analyzer-alpha'
+// RUN: clang-tidy -checks=* -list-checks -allow-enabling-analyzer-alpha-checkers | grep 'clang-analyzer-alpha'
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -181,6 +181,14 @@
 cl::init(false),
 cl::cat(ClangTidyCategory));
 
+/// This option allows enabling the experimental alpha checkers from the static
+/// analyzer. This option is set to false and not visible in help, because it is
+/// highly not recommended for users.
+static cl::opt
+AllowEnablingAnalyzerAlphaCheckers("allow-enabling-analyzer-alpha-checkers",
+   cl::init(false), cl::Hidden,
+   cl::cat(ClangTidyCategory));
+
 static cl::opt ExportFixes("export-fixes", cl::desc(R"(
 YAML file to store suggested fixes in. The
 stored fixes can be applied to the input source
@@ -335,7 +343,8 @@
  << EC.message() << "\n";
   }
   ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
-  std::vector EnabledChecks = getCheckNames(EffectiveOptions);
+  std::vector EnabledChecks =
+  getCheckNames(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers);
 
   if (ExplainConfig) {
 // FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
@@ -366,7 +375,8 @@
   }
 
   if (DumpConfig) {
-EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions);
+EffectiveOptions.CheckOptions =
+getCheckOptions(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers);
 llvm::outs() << configurationAsText(
 ClangTidyOptions::getDefaults().mergeWith(
 EffectiveOptions))
@@ -390,7 +400,8 @@
   llvm::InitializeAllTargetMCs();
   llvm::InitializeAllAsmParsers();
 
-  ClangTidyContext Context(std::move(OwningOptionsProvider));
+  ClangTidyContext Context(std::move(OwningOptionsProvider),
+   AllowEnablingAnalyzerAlphaCheckers);
   runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS,
EnableCheckProfile);
   ArrayRef Errors = Context.getErrors();
Index: clang-tidy/ClangTidyDiagnosticConsumer.h
===
--- clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -99,7 +99,8 @@
 class ClangTidyContext {
 public:
   /// \brief Initializes \c ClangTidyContext instance.
-  ClangTidyContext(std::unique_ptr OptionsProvider);
+  ClangTidyContext(std::unique_ptr OptionsProvider,
+   bool AllowEnablingAnalyzerAlphaCheckers = false);
 
   ~ClangTidyContext();
 
@@ -178,6 +179,12 @@
 return CurrentBuildDirectory;
   }
 
+  /// \brief If the experimental alpha checkers from the static analyzer can be
+  /// enabled.
+  bool canEnableAnalyzerAlphaCheckers() const {
+return AllowEnablingAnalyzerAlphaCheckers;
+  }
+
 private:
   // Calls setDiagnosticsEngine() and storeError().
   friend class ClangTidyDiagnosticConsumer;
@@ -209,6 +216,8 @@
   llvm::DenseMap CheckNamesByDiagnosticID;
 
   bool Profile;
+
+  bool AllowEnablingAnalyzerAlphaCheckers;
 };
 
 /// \brief A diagnostic consumer that turns each \c Diagnostic into a
Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -177,9 +177,11 @@
 };
 
 ClangTidyContext::ClangTidyContext(
-std::unique_ptr OptionsProvider)
+std::unique_ptr OptionsProvider,
+bool AllowEnablingAnalyzerAlphaCheckers)
 : DiagEngine(nullptr), OptionsProvider(std::move(OptionsProvider)),
-  Profile(false) {
+  Profile(false),
+  AllowEnablingAnalyzerAlphaCheckers(AllowEnablingAnalyzerAlphaCheckers) {
   // Before the first translation unit we can get errors related to command-line
   // parsing, use empty string for the file name in this case.
   

[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Looks good, thanks.

It strikes me that this will still lead to inconsistencies. For example, I 
expect this:

  struct A { struct B *a, *b; struct B *c, *d; };

... to print as:

  struct A {
struct B *a, *b;
struct B *c;
struct B *d;
  };

... where the first two are joined because their type owns a declaration of 
`struct B`, and the second two are not joined because their type does not own a 
declaration (it just has a reference to the already-existing declaration of 
`struct B`). One (somewhat hacky) way to address this would be to compare the 
starting source locations of a sequence of `DeclaratorDecl`s and group them if 
it's the same.


https://reviews.llvm.org/D45465



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


[PATCH] D46446: [c++17] Fix assertion on synthesizing deduction guides after a fatal error.

2018-05-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Thanks for the review.


Repository:
  rL LLVM

https://reviews.llvm.org/D46446



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


[PATCH] D46446: [c++17] Fix assertion on synthesizing deduction guides after a fatal error.

2018-05-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332307: [c++17] Fix assertion on synthesizing deduction 
guides after a fatal error. (authored by vsapsai, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46446?vs=145251=146713#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46446

Files:
  cfe/trunk/lib/Sema/SemaTemplate.cpp
  cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp


Index: cfe/trunk/lib/Sema/SemaTemplate.cpp
===
--- cfe/trunk/lib/Sema/SemaTemplate.cpp
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp
@@ -1976,6 +1976,8 @@
   // FIXME: Add a kind for this to give more meaningful diagnostics. But can
   // this substitution process actually fail?
   InstantiatingTemplate BuildingDeductionGuides(*this, Loc, Template);
+  if (BuildingDeductionGuides.isInvalid())
+return;
 
   // Convert declared constructors into deduction guide templates.
   // FIXME: Skip constructors for which deduction must necessarily fail (those
Index: cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp
===
--- cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp
+++ cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp
@@ -0,0 +1,16 @@
+// RUN: not %clang_cc1 -std=c++17 -fsyntax-only -ferror-limit 1 %s 2>&1 | 
FileCheck %s
+
+#error Error 1
+#error Error 2
+// CHECK: fatal error: too many errors emitted, stopping now
+
+namespace rdar39051732 {
+
+  template struct A {
+template  A(T&, ...);
+  };
+  // Deduction guide triggers constructor instantiation.
+  template A(const T&, const T&) -> A;
+
+}
+


Index: cfe/trunk/lib/Sema/SemaTemplate.cpp
===
--- cfe/trunk/lib/Sema/SemaTemplate.cpp
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp
@@ -1976,6 +1976,8 @@
   // FIXME: Add a kind for this to give more meaningful diagnostics. But can
   // this substitution process actually fail?
   InstantiatingTemplate BuildingDeductionGuides(*this, Loc, Template);
+  if (BuildingDeductionGuides.isInvalid())
+return;
 
   // Convert declared constructors into deduction guide templates.
   // FIXME: Skip constructors for which deduction must necessarily fail (those
Index: cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp
===
--- cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp
+++ cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp
@@ -0,0 +1,16 @@
+// RUN: not %clang_cc1 -std=c++17 -fsyntax-only -ferror-limit 1 %s 2>&1 | FileCheck %s
+
+#error Error 1
+#error Error 2
+// CHECK: fatal error: too many errors emitted, stopping now
+
+namespace rdar39051732 {
+
+  template struct A {
+template  A(T&, ...);
+  };
+  // Deduction guide triggers constructor instantiation.
+  template A(const T&, const T&) -> A;
+
+}
+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r332307 - [c++17] Fix assertion on synthesizing deduction guides after a fatal error.

2018-05-14 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon May 14 15:49:44 2018
New Revision: 332307

URL: http://llvm.org/viewvc/llvm-project?rev=332307=rev
Log:
[c++17] Fix assertion on synthesizing deduction guides after a fatal error.

After a fatal error Sema::InstantiatingTemplate doesn't allow further
instantiation and doesn't push a CodeSynthesisContext. When we tried to
synthesize implicit deduction guides from constructors we hit the
assertion

> Assertion failed: (!CodeSynthesisContexts.empty() && "Cannot perform an 
> instantiation without some context on the " "instantiation stack"), function 
> SubstType, file clang/lib/Sema/SemaTemplateInstantiate.cpp, line 1580.

Fix by avoiding deduction guide synthesis if InstantiatingTemplate is invalid.

rdar://problem/39051732

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=332307=332306=332307=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon May 14 15:49:44 2018
@@ -1976,6 +1976,8 @@ void Sema::DeclareImplicitDeductionGuide
   // FIXME: Add a kind for this to give more meaningful diagnostics. But can
   // this substitution process actually fail?
   InstantiatingTemplate BuildingDeductionGuides(*this, Loc, Template);
+  if (BuildingDeductionGuides.isInvalid())
+return;
 
   // Convert declared constructors into deduction guide templates.
   // FIXME: Skip constructors for which deduction must necessarily fail (those

Added: cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp?rev=332307=auto
==
--- cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp Mon May 14 
15:49:44 2018
@@ -0,0 +1,16 @@
+// RUN: not %clang_cc1 -std=c++17 -fsyntax-only -ferror-limit 1 %s 2>&1 | 
FileCheck %s
+
+#error Error 1
+#error Error 2
+// CHECK: fatal error: too many errors emitted, stopping now
+
+namespace rdar39051732 {
+
+  template struct A {
+template  A(T&, ...);
+  };
+  // Deduction guide triggers constructor instantiation.
+  template A(const T&, const T&) -> A;
+
+}
+


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


[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 146709.
jdenny marked 2 inline comments as done.
jdenny added a comment.

Made the suggested change.  Thanks!


https://reviews.llvm.org/D45465

Files:
  lib/AST/DeclPrinter.cpp
  test/Misc/ast-print-enum-decl.c
  test/Misc/ast-print-record-decl.c
  test/Sema/ast-print.c
  test/SemaCXX/ast-print.cpp

Index: test/SemaCXX/ast-print.cpp
===
--- test/SemaCXX/ast-print.cpp
+++ test/SemaCXX/ast-print.cpp
@@ -214,10 +214,13 @@
 struct [[gnu::visibility("hidden")]] S;
 }
 
-// CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{};
+// CHECK:  struct CXXFunctionalCastExprPrint {
+// CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
 struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{};
 
-// CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{};
+// CHECK:  struct CXXTemporaryObjectExprPrint {
+// CHECK-NEXT:   CXXTemporaryObjectExprPrint();
+// CHECK-NEXT: } toe = CXXTemporaryObjectExprPrint{};
 struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{};
 
 namespace PR24872 {
Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -83,8 +83,7 @@
   EnumWithAttributesFoo __attribute__((deprecated)),
   // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50
   EnumWithAttributesBar __attribute__((unavailable)) = 50
-  // CHECK-NEXT: };
-  // CHECK-NEXT: enum EnumWithAttributes *EnumWithAttributesPtr;
+  // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
 // FIXME: If enum is forward-declared at file scope, attributes are lost.
Index: test/Misc/ast-print-record-decl.c
===
--- test/Misc/ast-print-record-decl.c
+++ test/Misc/ast-print-record-decl.c
@@ -7,8 +7,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -19,7 +19,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \
+//   RUN: -DBASES= %s
 
 // Repeat for union:
 //
@@ -30,8 +31,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -42,7 +43,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \
+//   RUN: -DBASES= %s
 
 // Repeat for C++ (BASES helps ensure we're printing as C++ not as C):
 //
@@ -54,7 +56,7 @@
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
 //   RUN: > %t.cpp
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN:   -DBASES=' : B' %s --input-file %t.cpp
 //
 //   Now check compiling and printing of the printed file.
@@ -66,7 +68,7 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.cpp \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN: -DBASES=' : B' %s
 
 // END.
@@ -155,25 +157,33 @@
   // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}}
   KW __attribute__((deprecated(""))) T *p0;
 
-  // PRINT-NEXT: [[KW]] __attribute__((aligned(16))) T[[BASES]] {
-  // PRINT-NEXT:   int i;
-  // PRINT-NEXT:   [[KW]] T *p2;
-  // PRINT-NEXT: } *p1;
-  KW __attribute__((aligned(16))) T BASES { // expected-warning {{'T' is deprecated}}
+  // PRINT-NEXT:  [[KW]] __attribute__((aligned(64))) T[[BASES]] {
+  // PRINT-NEXT:int i;
+  // PRINT-NEXT:[[KW]] T *p2;
+  // PRINT-NEXT:[[KW]] 

[PATCH] D46845: [libcxx][c++17] P0083R5: Splicing Maps and Sets

2018-05-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

How do you deal with the fact that node handles for map-like types need to be 
able to mutate a const member of a `pair` in-place? Are you assuming/hoping the 
compiler won't do bad things to the program as a result, or is there some 
reason why it would be unlikely to do so / disallowed from doing so? If you're 
just casting `pair` to / from `pair` (and I think that's 
what's happening), there is a very real risk that struct-path-sensitive TBAA 
will decide that `pair::first` and `pair::first` cannot alias 
(and likewise for `::second`) and then miscompile code using libc++'s node 
pointers.

One way we could deal with this is by adding an attribute to the compiler to 
indicate "the const is a lie", that we can apply to `std::pair::first`, with 
the semantics being that a top-level `const` is ignored when determining the 
"real" type of the member (and so mutating the member after a `const_cast` has 
defined behavior).  This would apply to //all// `std::pair`s, not just the 
`node_handle` case, but in practice we don't optimize on the basis of a member 
being declared `const` *anyway*, so this isn't such a big deal right now.

Another possibility would be a compiler intrinsic to change the type of the 
pair, in-place, from a `std::pair` to a `std::pair`, without 
changing anything about the members -- except that the `first` member changes 
type.

Yet another possibility would be to only ever access the `key` field through a 
type annotated with `__attribute__((may_alias))`, and then launder the node 
pointer when we're ready to insert it back into the container (to "pick up" the 
new value of the const member). That's formally breaking the rules (a `launder` 
isn't enough, because we didn't actually create a new object, and in any case 
we still mutated the value of a `const` subobject), but it'll probably work 
fine across compilers that support the attribute.




Comment at: libcxx/include/__node_handle:148
+typedef __node_handle_base<_NodeType, _Alloc> __base;
+using __base::__node_handle_base;
+

`using __base::__base;` would be a much more reasonable way to write an 
inheriting constructor declaration here.


Repository:
  rCXX libc++

https://reviews.llvm.org/D46845



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


[PATCH] D45177: CStringChecker, check strlcpy/strlcat

2018-05-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332303: [analyzer] Re-apply r331096 CStringChecker: 
Add support for BSD strlcpy() (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D45177

Files:
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  test/Analysis/bsd-string.c

Index: test/Analysis/bsd-string.c
===
--- test/Analysis/bsd-string.c
+++ test/Analysis/bsd-string.c
@@ -0,0 +1,40 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -verify %s
+
+#define NULL ((void *)0)
+
+typedef __typeof(sizeof(int)) size_t;
+size_t strlcpy(char *dst, const char *src, size_t n);
+size_t strlcat(char *dst, const char *src, size_t n);
+void clang_analyzer_eval(int);
+
+void f1() {
+  char overlap[] = "123456789";
+  strlcpy(overlap, overlap + 1, 3); // expected-warning{{Arguments must not be overlapping buffers}}
+}
+
+void f2() {
+  char buf[5];
+  strlcpy(buf, "abcd", sizeof(buf)); // expected-no-warning
+  strlcat(buf, "efgh", sizeof(buf)); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
+}
+
+void f3() {
+  char dst[2];
+  const char *src = "abdef";
+  strlcpy(dst, src, 5); // expected-warning{{Size argument is greater than the length of the destination buffer}}
+}
+
+void f4() {
+  strlcpy(NULL, "abcdef", 6); // expected-warning{{Null pointer argument in call to string copy function}}
+}
+
+void f5() {
+  strlcat(NULL, "abcdef", 6); // expected-warning{{Null pointer argument in call to string copy function}}
+}
+
+void f6() {
+  char buf[8];
+  strlcpy(buf, "abc", 3);
+  size_t len = strlcat(buf, "defg", 4);
+  clang_analyzer_eval(len == 7); // expected-warning{{TRUE}}
+}
Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -97,14 +97,17 @@
   void evalStrcpy(CheckerContext , const CallExpr *CE) const;
   void evalStrncpy(CheckerContext , const CallExpr *CE) const;
   void evalStpcpy(CheckerContext , const CallExpr *CE) const;
+  void evalStrlcpy(CheckerContext , const CallExpr *CE) const;
   void evalStrcpyCommon(CheckerContext ,
 const CallExpr *CE,
 bool returnEnd,
 bool isBounded,
-bool isAppending) const;
+bool isAppending,
+bool returnPtr = true) const;
 
   void evalStrcat(CheckerContext , const CallExpr *CE) const;
   void evalStrncat(CheckerContext , const CallExpr *CE) const;
+  void evalStrlcat(CheckerContext , const CallExpr *CE) const;
 
   void evalStrcmp(CheckerContext , const CallExpr *CE) const;
   void evalStrncmp(CheckerContext , const CallExpr *CE) const;
@@ -1393,6 +1396,18 @@
/* isAppending = */ false);
 }
 
+void CStringChecker::evalStrlcpy(CheckerContext , const CallExpr *CE) const {
+  if (CE->getNumArgs() < 3)
+return;
+
+  // char *strlcpy(char *dst, const char *src, size_t n);
+  evalStrcpyCommon(C, CE,
+   /* returnEnd = */ true,
+   /* isBounded = */ true,
+   /* isAppending = */ false,
+   /* returnPtr = */ false);
+}
+
 void CStringChecker::evalStrcat(CheckerContext , const CallExpr *CE) const {
   if (CE->getNumArgs() < 2)
 return;
@@ -1415,9 +1430,21 @@
/* isAppending = */ true);
 }
 
+void CStringChecker::evalStrlcat(CheckerContext , const CallExpr *CE) const {
+  if (CE->getNumArgs() < 3)
+return;
+
+  //char *strlcat(char *s1, const char *s2, size_t n);
+  evalStrcpyCommon(C, CE,
+   /* returnEnd = */ false,
+   /* isBounded = */ true,
+   /* isAppending = */ true,
+   /* returnPtr = */ false);
+}
+
 void CStringChecker::evalStrcpyCommon(CheckerContext , const CallExpr *CE,
   bool returnEnd, bool isBounded,
-  bool isAppending) const {
+  bool isAppending, bool returnPtr) const {
   CurrentFunctionDescription = "string copy function";
   ProgramStateRef state = C.getState();
   const LocationContext *LCtx = C.getLocationContext();
@@ -1455,6 +1482,11 @@
   SVal maxLastElementIndex = UnknownVal();
   const char *boundWarning = nullptr;
 
+  state = CheckOverlap(C, state, isBounded ? CE->getArg(2) : CE->getArg(1), Dst, srcExpr);
+
+  if (!state)
+return;
+
   // If the function is strncpy, strncat, etc... it is bounded.
   if (isBounded) {
 // Get the max number of characters to copy.
@@ -1658,35 +1690,41 @@
 finalStrLength = amountCopied;
   }
 
-  // The final result of the function will either be 

r332303 - [analyzer] Re-apply r331096 "CStringChecker: Add support for BSD strlcpy()...".

2018-05-14 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon May 14 15:32:24 2018
New Revision: 332303

URL: http://llvm.org/viewvc/llvm-project?rev=332303=rev
Log:
[analyzer] Re-apply r331096 "CStringChecker: Add support for BSD strlcpy()...".

Fixed after revert in r331401.

Patch by David Carlier!

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

Added:
cfe/trunk/test/Analysis/bsd-string.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=332303=332302=332303=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Mon May 14 
15:32:24 2018
@@ -97,14 +97,17 @@ public:
   void evalStrcpy(CheckerContext , const CallExpr *CE) const;
   void evalStrncpy(CheckerContext , const CallExpr *CE) const;
   void evalStpcpy(CheckerContext , const CallExpr *CE) const;
+  void evalStrlcpy(CheckerContext , const CallExpr *CE) const;
   void evalStrcpyCommon(CheckerContext ,
 const CallExpr *CE,
 bool returnEnd,
 bool isBounded,
-bool isAppending) const;
+bool isAppending,
+bool returnPtr = true) const;
 
   void evalStrcat(CheckerContext , const CallExpr *CE) const;
   void evalStrncat(CheckerContext , const CallExpr *CE) const;
+  void evalStrlcat(CheckerContext , const CallExpr *CE) const;
 
   void evalStrcmp(CheckerContext , const CallExpr *CE) const;
   void evalStrncmp(CheckerContext , const CallExpr *CE) const;
@@ -1393,6 +1396,18 @@ void CStringChecker::evalStpcpy(CheckerC
/* isAppending = */ false);
 }
 
+void CStringChecker::evalStrlcpy(CheckerContext , const CallExpr *CE) const {
+  if (CE->getNumArgs() < 3)
+return;
+
+  // char *strlcpy(char *dst, const char *src, size_t n);
+  evalStrcpyCommon(C, CE,
+   /* returnEnd = */ true,
+   /* isBounded = */ true,
+   /* isAppending = */ false,
+   /* returnPtr = */ false);
+}
+
 void CStringChecker::evalStrcat(CheckerContext , const CallExpr *CE) const {
   if (CE->getNumArgs() < 2)
 return;
@@ -1415,9 +1430,21 @@ void CStringChecker::evalStrncat(Checker
/* isAppending = */ true);
 }
 
+void CStringChecker::evalStrlcat(CheckerContext , const CallExpr *CE) const {
+  if (CE->getNumArgs() < 3)
+return;
+
+  //char *strlcat(char *s1, const char *s2, size_t n);
+  evalStrcpyCommon(C, CE,
+   /* returnEnd = */ false,
+   /* isBounded = */ true,
+   /* isAppending = */ true,
+   /* returnPtr = */ false);
+}
+
 void CStringChecker::evalStrcpyCommon(CheckerContext , const CallExpr *CE,
   bool returnEnd, bool isBounded,
-  bool isAppending) const {
+  bool isAppending, bool returnPtr) const {
   CurrentFunctionDescription = "string copy function";
   ProgramStateRef state = C.getState();
   const LocationContext *LCtx = C.getLocationContext();
@@ -1455,6 +1482,11 @@ void CStringChecker::evalStrcpyCommon(Ch
   SVal maxLastElementIndex = UnknownVal();
   const char *boundWarning = nullptr;
 
+  state = CheckOverlap(C, state, isBounded ? CE->getArg(2) : CE->getArg(1), 
Dst, srcExpr);
+
+  if (!state)
+return;
+
   // If the function is strncpy, strncat, etc... it is bounded.
   if (isBounded) {
 // Get the max number of characters to copy.
@@ -1658,16 +1690,22 @@ void CStringChecker::evalStrcpyCommon(Ch
 finalStrLength = amountCopied;
   }
 
-  // The final result of the function will either be a pointer past the last
-  // copied element, or a pointer to the start of the destination buffer.
-  SVal Result = (returnEnd ? UnknownVal() : DstVal);
+  SVal Result;
+
+  if (returnPtr) {
+// The final result of the function will either be a pointer past the last
+// copied element, or a pointer to the start of the destination buffer.
+Result = (returnEnd ? UnknownVal() : DstVal);
+  } else {
+Result = finalStrLength;
+  }
 
   assert(state);
 
   // If the destination is a MemRegion, try to check for a buffer overflow and
   // record the new string length.
   if (Optional dstRegVal =
-  DstVal.getAs()) {
+  DstVal.getAs()) {
 QualType ptrTy = Dst->getType();
 
 // If we have an exact value on a bounded copy, use that to check for
@@ -1675,9 +1713,9 @@ void CStringChecker::evalStrcpyCommon(Ch
 if (boundWarning) {
   if (Optional maxLastNL = maxLastElementIndex.getAs()) {
 SVal maxLastElement = svalBuilder.evalBinOpLN(state, BO_Add, 
*dstRegVal,
-

[PATCH] D45177: CStringChecker, check strlcpy/strlcat

2018-05-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Thanks! I'll commit again.


https://reviews.llvm.org/D45177



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


[PATCH] D44934: [analyzer] Improve the modeling of `memset()`.

2018-05-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Thank you! Looks good overall.




Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1013-1014
+
+  // Get the offset and the base region to figure out whether the offset of
+  // buffer is 0.
+  RegionOffset Offset = MR->getAsOffset();

Please say something here (or above) about why do we want our offset to be 0:
> We're about to model memset by producing a "default binding" in the Store. 
> Our current implementation - RegionStore - doesn't support default bindings 
> that don't cover the whole base region.



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1037
+
+if (StateWholeReg && !StateNotWholeReg && CharVal.isZeroConstant()) {
+  // If the 'memset()' acts on the whole region of destination buffer and

I think we should use `StateNonNullChar` (that's computed below) instead of 
`CharVal.isZeroConstant()` because the Environment doesn't provide a guarantee 
that all symbols within it are collapsed to constants where applicable.



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1055
+std::tie(StateNullChar, StateNonNullChar) =
+assumeZero(C, State, CharVal, Ctx.UnsignedCharTy);
+

I think this should use `IntTy` here. Because that's the type of the `memset`'s 
argument, and that's what `assumeZero()` expects.



Comment at: test/Analysis/string.c:1412
+  clang_analyzer_eval(strlen(str) >= 10); // expected-warning{{TRUE}}
+  // FIXME: This shoule be TRUE.
+  clang_analyzer_eval(str[1] == '0'); // expected-warning{{UNKNOWN}}

Typo: `should` :)


Repository:
  rC Clang

https://reviews.llvm.org/D44934



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


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

2018-05-14 Thread Yunlian Jiang via Phabricator via cfe-commits
yunlian updated this revision to Diff 146698.
yunlian edited the summary of this revision.
yunlian added a comment.
Herald added subscribers: JDevlieghere, aprantl.

Use the option -gsplit-dwarf to make it more consistent.


https://reviews.llvm.org/D44788

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/lto-dwo.c


Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -417,6 +417,27 @@
   if (IsThinLTO)
 CmdArgs.push_back("-plugin-opt=thinlto");
 
+  if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ)) {
+const char *Objcopy =
+Args.MakeArgString(ToolChain.GetProgramPath(CLANG_DEFAULT_OBJCOPY));
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-plugin-opt=objcopy=") + Objcopy));
+StringRef DWO_Dir = A->getValue();
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-plugin-opt=dwo_dir=") + DWO_Dir));
+  }
+
+  if (Args.hasArg(options::OPT_gsplit_dwarf)) {
+if (!Args.getLastArg(options::OPT_gsplit_dwarf_EQ)) {
+  const char *Objcopy =
+  Args.MakeArgString(ToolChain.GetProgramPath(CLANG_DEFAULT_OBJCOPY));
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine("-plugin-opt=objcopy=") + Objcopy));
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine("-plugin-opt=dwo_dir=.")));
+}
+  }
+
   if (unsigned Parallelism = getLTOParallelism(Args, ToolChain.getDriver()))
 CmdArgs.push_back(
 Args.MakeArgString("-plugin-opt=jobs=" + Twine(Parallelism)));
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1762,6 +1762,7 @@
 def gcolumn_info : Flag<["-"], "gcolumn-info">, Group, 
Flags<[CoreOption]>;
 def gno_column_info : Flag<["-"], "gno-column-info">, Group, 
Flags<[CoreOption]>;
 def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group;
+def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, Group;
 def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, 
Flags<[CC1Option]>;
 def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group;
 def gmodules : Flag <["-"], "gmodules">, Group,
Index: test/Driver/lto-dwo.c
===
--- /dev/null
+++ test/Driver/lto-dwo.c
@@ -0,0 +1,16 @@
+// Confirm that -gsplit-dwarf=DIR is passed to linker
+
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin 
-gsplit-dwarf=DIR 2> %t
+// RUN: FileCheck -check-prefix=CHECK-LINK-DWO-DIR < %t %s
+// RUN: FileCheck -check-prefix=CHECK-LINK-OBJCOPY < %t %s
+//
+// CHECK-LINK-DWO-DIR: "-plugin-opt=dwo_dir=DIR"
+// CHECK-LINK-OBJCOPY: "-plugin-opt=objcopy={{.*}}objcopy"
+//
+
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -gsplit-dwarf 
2> %t
+// RUN: FileCheck -check-prefix=CHECK-LINK-DWO-DIR-DEFAULT < %t %s
+// RUN: FileCheck -check-prefix=CHECK-LINK-OBJCOPY-DEFAULT < %t %s
+//
+// CHECK-LINK-DWO-DIR-DEFAULT: "-plugin-opt=dwo_dir=."
+// CHECK-LINK-OBJCOPY-DEFAULT: "-plugin-opt=objcopy={{.*}}objcopy"


Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -417,6 +417,27 @@
   if (IsThinLTO)
 CmdArgs.push_back("-plugin-opt=thinlto");
 
+  if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ)) {
+const char *Objcopy =
+Args.MakeArgString(ToolChain.GetProgramPath(CLANG_DEFAULT_OBJCOPY));
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-plugin-opt=objcopy=") + Objcopy));
+StringRef DWO_Dir = A->getValue();
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-plugin-opt=dwo_dir=") + DWO_Dir));
+  }
+
+  if (Args.hasArg(options::OPT_gsplit_dwarf)) {
+if (!Args.getLastArg(options::OPT_gsplit_dwarf_EQ)) {
+  const char *Objcopy =
+  Args.MakeArgString(ToolChain.GetProgramPath(CLANG_DEFAULT_OBJCOPY));
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine("-plugin-opt=objcopy=") + Objcopy));
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine("-plugin-opt=dwo_dir=.")));
+}
+  }
+
   if (unsigned Parallelism = getLTOParallelism(Args, ToolChain.getDriver()))
 CmdArgs.push_back(
 Args.MakeArgString("-plugin-opt=jobs=" + Twine(Parallelism)));
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1762,6 +1762,7 @@
 def gcolumn_info : Flag<["-"], "gcolumn-info">, Group, Flags<[CoreOption]>;
 def gno_column_info : Flag<["-"], "gno-column-info">, Group, Flags<[CoreOption]>;
 def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group;
+def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, Group;
 def ggnu_pubnames : 

[PATCH] D46187: [Analyzer] getRegisteredCheckers(): handle debug checkers too.

2018-05-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In https://reviews.llvm.org/D46187#1089087, @lebedev.ri wrote:

> > I believe we could also benefit from a method of extracting the analyzer's 
> > `clang -cc1` run-line from clang-tidy. This would allow arbitrary debugging 
> > over a single analyzer invocation.
>
> I'm not really following, sorry.




In https://reviews.llvm.org/D46187#1091309, @alexfh wrote:

> In https://reviews.llvm.org/D46187#1088722, @NoQ wrote:
>
> > I believe we could also benefit from a method of extracting the analyzer's 
> > `clang -cc1` run-line from clang-tidy.
>
>
> It should be possible now using `clang-tidy -extra-arg=-v some/file.cpp` (or 
> `clang-check -extra-arg=-v ...`).


Nice!

So essentially @lebedev.ri could do `clang-check -analyze -extra-arg=-v 
../llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp`, then copy the printed `clang 
Invocation:` and append `-analyzer-checker debug.ViewCallGraph` to it.

Or maybe even something as horrible as

  clang-check -analyze -extra-arg=-Xclang -extra-arg=-analyzer-checker 
-extra-arg=-Xclang -extra-arg=debug.ViewCallGraph 
../llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

And it sounds like the roughly right level of verbosity for discriminating 
between a user-facing feature and a definitely-not-user-facing feature.

I don't mind having a separate flag specifically for enabling debug checkers, 
but when it comes to actual debugging of the analyzer, debug checkers are 
usually not sufficient. Playing with other flags and `-analyzer-config` options 
is very often necessary, so if i was to debug the analyzer from clang-tidy, 
most of the time i'd have preferred to do the `-v` trick.


Repository:
  rC Clang

https://reviews.llvm.org/D46187



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


[PATCH] D46772: [analyzer] Extend the ObjCAutoreleaseWriteChecker to warn on captures as well

2018-05-14 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332300: [analyzer] Extend the ObjCAutoreleaseWriteChecker to 
warn on captures as well (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D46772

Files:
  lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp
  test/Analysis/autoreleasewritechecker_test.m

Index: lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp
+++ lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp
@@ -8,7 +8,7 @@
 //===--===//
 //
 // This file defines ObjCAutoreleaseWriteChecker which warns against writes
-// into autoreleased out parameters which are likely to cause crashes.
+// into autoreleased out parameters which cause crashes.
 // An example of a problematic write is a write to {@code error} in the example
 // below:
 //
@@ -21,8 +21,9 @@
 // return false;
 // }
 //
-// Such code is very likely to crash due to the other queue autorelease pool
-// begin able to free the error object.
+// Such code will crash on read from `*error` due to the autorelease pool
+// in `enumerateObjectsUsingBlock` implementation freeing the error object
+// on exit from the function.
 //
 //===--===//
 
@@ -41,8 +42,9 @@
 namespace {
 
 const char *ProblematicWriteBind = "problematicwrite";
+const char *CapturedBind = "capturedbind";
 const char *ParamBind = "parambind";
-const char *MethodBind = "methodbind";
+const char *IsMethodBind = "ismethodbind";
 
 class ObjCAutoreleaseWriteChecker : public Checker {
 public:
@@ -110,67 +112,87 @@
   AnalysisDeclContext *ADC = AM.getAnalysisDeclContext(D);
 
   const auto *PVD = Match.getNodeAs(ParamBind);
-  assert(PVD);
   QualType Ty = PVD->getType();
   if (Ty->getPointeeType().getObjCLifetime() != Qualifiers::OCL_Autoreleasing)
 return;
-  const auto *SW = Match.getNodeAs(ProblematicWriteBind);
-  bool IsMethod = Match.getNodeAs(MethodBind) != nullptr;
+  const char *WarningMsg = "Write to";
+  const auto *MarkedStmt = Match.getNodeAs(ProblematicWriteBind);
+
+  // Prefer to warn on write, but if not available, warn on capture.
+  if (!MarkedStmt) {
+MarkedStmt = Match.getNodeAs(CapturedBind);
+assert(MarkedStmt);
+WarningMsg = "Capture of";
+  }
+
+  SourceRange Range = MarkedStmt->getSourceRange();
+  PathDiagnosticLocation Location = PathDiagnosticLocation::createBegin(
+  MarkedStmt, BR.getSourceManager(), ADC);
+  bool IsMethod = Match.getNodeAs(IsMethodBind) != nullptr;
   const char *Name = IsMethod ? "method" : "function";
-  assert(SW);
   BR.EmitBasicReport(
   ADC->getDecl(), Checker,
-  /*Name=*/"Write to autoreleasing out parameter inside autorelease pool",
+  /*Name=*/(llvm::Twine(WarningMsg)
++ " autoreleasing out parameter inside autorelease pool").str(),
   /*Category=*/"Memory",
-  (llvm::Twine("Write to autoreleasing out parameter inside ") +
+  (llvm::Twine(WarningMsg) + " autoreleasing out parameter inside " +
"autorelease pool that may exit before " + Name + " returns; consider "
"writing first to a strong local variable declared outside of the block")
   .str(),
-  PathDiagnosticLocation::createBegin(SW, BR.getSourceManager(), ADC),
-  SW->getSourceRange());
+  Location,
+  Range);
 }
 
 void ObjCAutoreleaseWriteChecker::checkASTCodeBody(const Decl *D,
   AnalysisManager ,
   BugReporter ) const {
 
+  auto DoublePointerParamM =
+  parmVarDecl(hasType(hasCanonicalType(pointerType(
+  pointee(hasCanonicalType(objcObjectPointerType()))
+  .bind(ParamBind);
+
+  auto ReferencedParamM =
+  declRefExpr(to(parmVarDecl(DoublePointerParamM)));
+
   // Write into a binded object, e.g. *ParamBind = X.
   auto WritesIntoM = binaryOperator(
 hasLHS(unaryOperator(
 hasOperatorName("*"),
 hasUnaryOperand(
-  ignoringParenImpCasts(
-declRefExpr(to(parmVarDecl(equalsBoundNode(ParamBind))
+  ignoringParenImpCasts(ReferencedParamM))
 )),
 hasOperatorName("=")
   ).bind(ProblematicWriteBind);
 
+  auto ArgumentCaptureM = hasAnyArgument(
+ignoringParenImpCasts(ReferencedParamM));
+  auto CapturedInParamM = stmt(anyOf(
+  callExpr(ArgumentCaptureM),
+  objcMessageExpr(ArgumentCaptureM))).bind(CapturedBind);
+
   // WritesIntoM happens inside a block passed as an argument.
-  auto WritesInBlockM = hasAnyArgument(allOf(
+  auto WritesOrCapturesInBlockM = hasAnyArgument(allOf(
   hasType(hasCanonicalType(blockPointerType())),
-  

[PATCH] D46446: [c++17] Fix assertion on synthesizing deduction guides after a fatal error.

2018-05-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


https://reviews.llvm.org/D46446



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


r332300 - [analyzer] Extend the ObjCAutoreleaseWriteChecker to warn on captures as well

2018-05-14 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon May 14 14:39:54 2018
New Revision: 332300

URL: http://llvm.org/viewvc/llvm-project?rev=332300=rev
Log:
[analyzer] Extend the ObjCAutoreleaseWriteChecker to warn on captures as well

A common pattern is that the code in the block does not write into the
variable explicitly, but instead passes it to a helper function which
performs the write.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp
cfe/trunk/test/Analysis/autoreleasewritechecker_test.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp?rev=332300=332299=332300=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp Mon 
May 14 14:39:54 2018
@@ -8,7 +8,7 @@
 
//===--===//
 //
 // This file defines ObjCAutoreleaseWriteChecker which warns against writes
-// into autoreleased out parameters which are likely to cause crashes.
+// into autoreleased out parameters which cause crashes.
 // An example of a problematic write is a write to {@code error} in the example
 // below:
 //
@@ -21,8 +21,9 @@
 // return false;
 // }
 //
-// Such code is very likely to crash due to the other queue autorelease pool
-// begin able to free the error object.
+// Such code will crash on read from `*error` due to the autorelease pool
+// in `enumerateObjectsUsingBlock` implementation freeing the error object
+// on exit from the function.
 //
 
//===--===//
 
@@ -41,8 +42,9 @@ using namespace ast_matchers;
 namespace {
 
 const char *ProblematicWriteBind = "problematicwrite";
+const char *CapturedBind = "capturedbind";
 const char *ParamBind = "parambind";
-const char *MethodBind = "methodbind";
+const char *IsMethodBind = "ismethodbind";
 
 class ObjCAutoreleaseWriteChecker : public Checker {
 public:
@@ -110,67 +112,87 @@ static void emitDiagnostics(BoundNodes &
   AnalysisDeclContext *ADC = AM.getAnalysisDeclContext(D);
 
   const auto *PVD = Match.getNodeAs(ParamBind);
-  assert(PVD);
   QualType Ty = PVD->getType();
   if (Ty->getPointeeType().getObjCLifetime() != Qualifiers::OCL_Autoreleasing)
 return;
-  const auto *SW = Match.getNodeAs(ProblematicWriteBind);
-  bool IsMethod = Match.getNodeAs(MethodBind) != nullptr;
+  const char *WarningMsg = "Write to";
+  const auto *MarkedStmt = Match.getNodeAs(ProblematicWriteBind);
+
+  // Prefer to warn on write, but if not available, warn on capture.
+  if (!MarkedStmt) {
+MarkedStmt = Match.getNodeAs(CapturedBind);
+assert(MarkedStmt);
+WarningMsg = "Capture of";
+  }
+
+  SourceRange Range = MarkedStmt->getSourceRange();
+  PathDiagnosticLocation Location = PathDiagnosticLocation::createBegin(
+  MarkedStmt, BR.getSourceManager(), ADC);
+  bool IsMethod = Match.getNodeAs(IsMethodBind) != nullptr;
   const char *Name = IsMethod ? "method" : "function";
-  assert(SW);
   BR.EmitBasicReport(
   ADC->getDecl(), Checker,
-  /*Name=*/"Write to autoreleasing out parameter inside autorelease pool",
+  /*Name=*/(llvm::Twine(WarningMsg)
++ " autoreleasing out parameter inside autorelease 
pool").str(),
   /*Category=*/"Memory",
-  (llvm::Twine("Write to autoreleasing out parameter inside ") +
+  (llvm::Twine(WarningMsg) + " autoreleasing out parameter inside " +
"autorelease pool that may exit before " + Name + " returns; consider "
"writing first to a strong local variable declared outside of the 
block")
   .str(),
-  PathDiagnosticLocation::createBegin(SW, BR.getSourceManager(), ADC),
-  SW->getSourceRange());
+  Location,
+  Range);
 }
 
 void ObjCAutoreleaseWriteChecker::checkASTCodeBody(const Decl *D,
   AnalysisManager ,
   BugReporter ) const {
 
+  auto DoublePointerParamM =
+  parmVarDecl(hasType(hasCanonicalType(pointerType(
+  pointee(hasCanonicalType(objcObjectPointerType()))
+  .bind(ParamBind);
+
+  auto ReferencedParamM =
+  declRefExpr(to(parmVarDecl(DoublePointerParamM)));
+
   // Write into a binded object, e.g. *ParamBind = X.
   auto WritesIntoM = binaryOperator(
 hasLHS(unaryOperator(
 hasOperatorName("*"),
 hasUnaryOperand(
-  ignoringParenImpCasts(
-declRefExpr(to(parmVarDecl(equalsBoundNode(ParamBind))
+  ignoringParenImpCasts(ReferencedParamM))
 )),
 hasOperatorName("=")
   ).bind(ProblematicWriteBind);
 
+  auto 

[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/AST/DeclPrinter.cpp:393-397
   if (!BaseType.isNull() && isa(BaseType))
 BaseType = cast(BaseType)->getNamedType();
   if (!BaseType.isNull() && isa(BaseType) &&
-  cast(BaseType)->getDecl() == Decls[0]) {
+  cast(BaseType) ==
+  cast(Decls[0])->getTypeForDecl()) {

I would think the right thing to check here is that the `ElaboratedType`'s 
`OwnedTagDecl` is `Decls[0]`. Currently, you also allow cases where it's merely 
a redeclaration of that same `TagDecl`, which will combine together 
declarations too often...



Comment at: test/Misc/ast-print-record-decl.c:161-171
+  // PRINT-NEXT:[[KW]] __attribute__((may_alias)) T *p3, *p4;
+  // PRINT-NEXT:  } *p1;
+  KW __attribute__((aligned(64))) T BASES { // expected-warning {{'T' is 
deprecated}}
 int i;
 KW T *p2;
+// FIXME: For C++, T at p3 loses aligned and deprecated, perhaps because
+// that RecordDecl isn't in the same redecl list.  Perhaps the redecl lists

... such as here, for example. Because the two `KW T` declarations redeclare 
the same `TagDecl`, they will get merged by `-ast-print`.


https://reviews.llvm.org/D45465



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


[PATCH] D46846: [Attr] Fix printing attrs for enum forward decl at file scope

2018-05-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Clang's current behavior is observably wrong in MS compatibility mode. For 
example:

  namespace N {
enum E *p;
exterm E e; // ok, finds E injected into scope by previous declaration
  }
  N::E e; // error, no E in N!
  namespace N {
extern E e; // error, no E in N!
  }

Please add something like the above to the test suite, to make sure we don't 
regress this (in some existing `-fms-compatibility` test for enum forward 
declarations).


https://reviews.llvm.org/D46846



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


[PATCH] D46446: [c++17] Fix assertion on synthesizing deduction guides after a fatal error.

2018-05-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Ping.


https://reviews.llvm.org/D46446



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


r332294 - Fix test fail on some buildbots, caused by r332281.

2018-05-14 Thread Joel E. Denny via cfe-commits
Author: jdenny
Date: Mon May 14 14:06:04 2018
New Revision: 332294

URL: http://llvm.org/viewvc/llvm-project?rev=332294=rev
Log:
Fix test fail on some buildbots, caused by r332281.

Modified:
cfe/trunk/test/Misc/ast-print-record-decl.c

Modified: cfe/trunk/test/Misc/ast-print-record-decl.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-print-record-decl.c?rev=332294=332293=332294=diff
==
--- cfe/trunk/test/Misc/ast-print-record-decl.c (original)
+++ cfe/trunk/test/Misc/ast-print-record-decl.c Mon May 14 14:06:04 2018
@@ -2,7 +2,8 @@
 //
 //   First check compiling and printing of this file.
 //
-//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=struct -DBASES= -o - %s \
+//   RUN: %clang -target x86_64-linux -Xclang -verify -S -emit-llvm \
+//   RUN:-DKW=struct -DBASES= -o - %s \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c
@@ -14,7 +15,7 @@
 //   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.c
 //   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked 
deprecated here}}" >> %t.c
 //
-//   RUN: %clang -Xclang -verify -S -emit-llvm -o - %t.c \
+//   RUN: %clang -target x86_64-linux -Xclang -verify -S -emit-llvm -o - %t.c \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
@@ -24,7 +25,8 @@
 //
 //   First check compiling and printing of this file.
 //
-//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=union -DBASES= -o - %s \
+//   RUN: %clang -target x86_64-linux -Xclang -verify -S -emit-llvm \
+//   RUN:-DKW=union -DBASES= -o - %s \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c
@@ -36,7 +38,7 @@
 //   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.c
 //   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked 
deprecated here}}" >> %t.c
 //
-//   RUN: %clang -Xclang -verify -S -emit-llvm -o - %t.c \
+//   RUN: %clang -target x86_64-linux -Xclang -verify -S -emit-llvm -o - %t.c \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
@@ -46,8 +48,8 @@
 //
 //   First check compiling and printing of this file.
 //
-//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=struct -DBASES=' : B' -o - 
\
-//   RUN:-xc++ %s \
+//   RUN: %clang -target x86_64-linux -Xclang -verify -S -emit-llvm \
+//   RUN:-DKW=struct -DBASES=' : B' -o - -xc++ %s \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
@@ -60,7 +62,7 @@
 //   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.cpp
 //   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked 
deprecated here}}" >> %t.cpp
 //
-//   RUN: %clang -Xclang -verify -S -emit-llvm -o - %t.cpp \
+//   RUN: %clang -target x86_64-linux -Xclang -verify -S -emit-llvm -o - 
%t.cpp \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.cpp \


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


r332291 - Fix regression in r332076.

2018-05-14 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon May 14 13:52:48 2018
New Revision: 332291

URL: http://llvm.org/viewvc/llvm-project?rev=332291=rev
Log:
Fix regression in r332076.

If the name after 'template' is an unresolved using declaration (not containing
'typename'), then we don't yet know if it's a valid template-name, so don't
reject it prior to instantiation. Instead, treat it as naming a dependent
member of the current instantiation.

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CXX/drs/dr1xx.cpp
cfe/trunk/test/SemaTemplate/dependent-names.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=332291=332290=332291=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon May 14 13:52:48 2018
@@ -105,6 +105,12 @@ static NamedDecl *isAcceptableTemplateNa
 return nullptr;
   }
 
+  // 'using Dependent::foo;' can resolve to a template name.
+  // 'using typename Dependent::foo;' cannot (not even if 'foo' is an
+  // injected-class-name).
+  if (isa(D))
+return D;
+
   return nullptr;
 }
 
@@ -214,6 +220,10 @@ TemplateNameKind Sema::isTemplateName(Sc
 
 // We'll do this lookup again later.
 R.suppressDiagnostics();
+  } else if (isa((*R.begin())->getUnderlyingDecl())) 
{
+// We don't yet know whether this is a template-name or not.
+MemberOfUnknownSpecialization = true;
+return TNK_Non_template;
   } else {
 TemplateDecl *TD = cast((*R.begin())->getUnderlyingDecl());
 
@@ -429,7 +439,7 @@ bool Sema::LookupTemplateName(LookupResu
 if (ExampleLookupResult && TemplateKWLoc.isValid()) {
   Diag(Found.getNameLoc(), diag::err_template_kw_refers_to_non_template)
 << Found.getLookupName() << SS.getRange();
-  Diag(ExampleLookupResult->getLocation(),
+  Diag(ExampleLookupResult->getUnderlyingDecl()->getLocation(),
diag::note_template_kw_refers_to_non_template)
   << Found.getLookupName();
   return true;

Modified: cfe/trunk/test/CXX/drs/dr1xx.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr1xx.cpp?rev=332291=332290=332291=diff
==
--- cfe/trunk/test/CXX/drs/dr1xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr1xx.cpp Mon May 14 13:52:48 2018
@@ -71,8 +71,7 @@ namespace dr109 { // dr109: yes
 using T::template f; // expected-error {{'template' keyword not 
permitted here}} expected-error {{using declaration cannot refer to a template 
specialization}}
 // FIXME: We shouldn't suggest using the 'template' keyword in a location 
where it's not valid.
 using T::f; // expected-error {{use 'template' keyword}} 
expected-error {{using declaration cannot refer to a template specialization}}
-// FIXME: The first 'using' above introduces 'f' as a non-template member 
of 'B', leading to bad recovery:
-void g() { this->f(123); } // expected-error {{expected '('}}
+void g() { this->f(123); } // expected-error {{use 'template' 
keyword}}
   };
 }
 

Modified: cfe/trunk/test/SemaTemplate/dependent-names.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-names.cpp?rev=332291=332290=332291=diff
==
--- cfe/trunk/test/SemaTemplate/dependent-names.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-names.cpp Mon May 14 13:52:48 2018
@@ -427,3 +427,23 @@ namespace DependentTemplateIdWithNoArgs
   };
   void g() { f(); }
 }
+
+namespace DependentUnresolvedUsingTemplate {
+  template
+  struct X : T {
+using T::foo;
+void f() { this->template foo(); } // expected-error {{does not refer to a 
template}}
+void g() { this->template foo<>(); } // expected-error {{does not refer to 
a template}}
+void h() { this->template foo(); } // expected-error {{does not refer 
to a template}}
+  };
+  struct A { template int foo(); };
+  struct B { int foo(); }; // expected-note 3{{non-template here}}
+  void test(X xa, X xb) {
+xa.f();
+xa.g();
+xa.h();
+xb.f(); // expected-note {{instantiation of}}
+xb.g(); // expected-note {{instantiation of}}
+xb.h(); // expected-note {{instantiation of}}
+  }
+}


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


[PATCH] D45927: [clang-tidy] [modernize-use-auto] Correct way to calculate a type name length for multi-token types

2018-05-14 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 146677.
zinovy.nis added a comment.

- Fix for templated type names. Thanks AlexanderK for pointing.


https://reviews.llvm.org/D45927

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-min-type-name-length.cpp

Index: test/clang-tidy/modernize-use-auto-min-type-name-length.cpp
===
--- test/clang-tidy/modernize-use-auto-min-type-name-length.cpp
+++ test/clang-tidy/modernize-use-auto-min-type-name-length.cpp
@@ -1,30 +1,85 @@
-// RUN: %check_clang_tidy %s modernize-use-auto %t -- \
-// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.MinTypeNameLength, value: '5'}]}" \
-// RUN:   -- -std=c++11 -frtti
-
-extern int foo();
-
-using VeryVeryVeryLongTypeName = int;
+// RUN: %check_clang_tidy -check-suffix=0-0 %s modernize-use-auto %t  -- -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: 0}, {key: modernize-use-auto.MinTypeNameLength, value: 0}]}" -- --std=c++11 -frtti
+// RUN: %check_clang_tidy -check-suffix=0-8 %s modernize-use-auto %t  -- -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: 0}, {key: modernize-use-auto.MinTypeNameLength, value: 8}]}" -- --std=c++11 -frtti
+// RUN: %check_clang_tidy -check-suffix=1-0 %s modernize-use-auto %t  -- -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: 1}, {key: modernize-use-auto.MinTypeNameLength, value: 0}]}" -- --std=c++11 -frtti
+// RUN: %check_clang_tidy -check-suffix=1-8 %s modernize-use-auto %t  -- -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: 1}, {key: modernize-use-auto.MinTypeNameLength, value: 8}]}" -- --std=c++11 -frtti
+
+template  extern T foo();
+template  struct P {  explicit P(T t) : t_(t) {}  T t_;};
+template  P *foo_ptr();
+template  P _ref();
 
 int bar() {
-  int a = static_cast(foo());
-  // strlen('int') = 4 <  5, so skip it,
-  // even strlen('VeryVeryVeryLongTypeName') > 5.
-
-  unsigned b = static_cast(foo());
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
-  // CHECK-FIXES: auto b = static_cast(foo());
-
-  bool c = static_cast(foo());
-  // strlen('bool') = 4 <  5, so skip it.
-
-  const bool c1 = static_cast(foo());
-  // strlen('bool') = 4 <  5, so skip it, even there's a 'const'.
-
-  unsigned long long ull = static_cast(foo());
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
-  // CHECK-FIXES: auto ull = static_cast(foo());
+  {
+// Lenth(long) = 4
+long i = static_cast(foo());
+// CHECK-FIXES-0-0: auto i = {{.*}}
+// CHECK-FIXES-0-8: long i = {{.*}}
+// CHECK-FIXES-1-0: auto  i = {{.*}}
+// CHECK-FIXES-1-8: long i = {{.*}}
+const long ci = static_cast(foo());
+// CHECK-FIXES-0-0: auto ci = {{.*}}
+// CHECK-FIXES-0-8: long ci = {{.*}}
+// CHECK-FIXES-1-0: auto  ci = {{.*}}
+// CHECK-FIXES-1-8: long ci = {{.*}}
+long *pi = static_cast(foo());
+// CHECK-FIXES-0-0: auto *pi = {{.*}}
+// CHECK-FIXES-0-8: long *pi = {{.*}}
+// CHECK-FIXES-1-0: auto pi = {{.*}}
+// CHECK-FIXES-1-8: long *pi = {{.*}}
+
+// Length(long   *) is still 5
+long  * pi2 = static_cast(foo());
+// CHECK-FIXES-0-0: auto  * pi2 = {{.*}}
+// CHECK-FIXES-0-8: long  * pi2 = {{.*}}
+// CHECK-FIXES-1-0: auto  pi2 = {{.*}}
+// CHECK-FIXES-1-8: long  * pi2 = {{.*}}
+ 
+// Length(long **) = 6
+long **ppi = static_cast(foo());
+// CHECK-FIXES-0-0: auto **ppi = {{.*}}
+// CHECK-FIXES-0-8: long **ppi = {{.*}}
+// CHECK-FIXES-1-0: auto ppi = {{.*}}
+// CHECK-FIXES-1-8: long **ppi = {{.*}}
+  }
+
+  {
+// Lenth(long int) = 4 + 1 + 3 = 8
+// Lenth(longint) is still 8
+long int i = static_cast(foo());
+// CHECK-FIXES-0-0: auto i = {{.*}}
+// CHECK-FIXES-0-8: auto i = {{.*}}
+// CHECK-FIXES-1-0: auto  i = {{.*}}
+// CHECK-FIXES-1-8: auto  i = {{.*}}
+
+long int *pi = static_cast(foo());
+// CHECK-FIXES-0-0: auto *pi = {{.*}}
+// CHECK-FIXES-0-8: auto *pi = {{.*}}
+// CHECK-FIXES-1-0: auto pi = {{.*}}
+// CHECK-FIXES-1-8: auto pi = {{.*}}
+  }
+
+  // Templates
+  {
+// Length(P) = 7
+P& i = static_cast(foo_ref());
+// CHECK-FIXES-0-0: auto& i = {{.*}}
+// CHECK-FIXES-0-8: P& i = {{.*}}
+// CHECK-FIXES-1-0: auto & i = {{.*}}
+// CHECK-FIXES-1-8: P& i = {{.*}}
+
+// Length(P) = 8
+P& pi = static_cast &>(foo_ref());
+// CHECK-FIXES-0-0: auto& pi = {{.*}}
+// CHECK-FIXES-0-8: auto& pi = {{.*}}
+// CHECK-FIXES-1-0: auto & pi = {{.*}}
+// CHECK-FIXES-1-8: auto & pi = {{.*}}
+
+P* pi2 = static_cast(foo_ptr());
+// CHECK-FIXES-0-0: auto* 

[PATCH] D46497: [clangd] Populate #include insertions as additional edits in completion items.

2018-05-14 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 146675.
ioeric marked 7 inline comments as done.
ioeric added a comment.

- Addressed review comments.
- Merged with origin/master


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46497

Files:
  clangd/ClangdServer.cpp
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/Headers.cpp
  clangd/Headers.h
  clangd/Protocol.h
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/HeadersTests.cpp

Index: unittests/clangd/HeadersTests.cpp
===
--- unittests/clangd/HeadersTests.cpp
+++ unittests/clangd/HeadersTests.cpp
@@ -8,38 +8,97 @@
 //===--===//
 
 #include "Headers.h"
+
+#include "Compiler.h"
 #include "TestFS.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
+using ::testing::UnorderedElementsAre;
+
 class HeadersTest : public ::testing::Test {
 public:
   HeadersTest() {
 CDB.ExtraClangFlags = {SearchDirArg.c_str()};
 FS.Files[MainFile] = "";
+// Make sure directory sub/ exists.
+FS.Files[testPath("sub/EMPTY")] = "";
+  }
+
+private:
+  std::unique_ptr setupClang() {
+auto Cmd = CDB.getCompileCommand(MainFile);
+assert(static_cast(Cmd));
+auto VFS = FS.getFileSystem();
+VFS->setCurrentWorkingDirectory(Cmd->Directory);
+
+std::vector Argv;
+for (const auto  : Cmd->CommandLine)
+  Argv.push_back(S.c_str());
+auto CI = clang::createInvocationFromCommandLine(
+Argv,
+CompilerInstance::createDiagnostics(new DiagnosticOptions(),
+, false),
+VFS);
+EXPECT_TRUE(static_cast(CI));
+CI->getFrontendOpts().DisableFree = false;
+
+// The diagnostic options must be set before creating a CompilerInstance.
+CI->getDiagnosticOpts().IgnoreWarnings = true;
+auto Clang = prepareCompilerInstance(
+std::move(CI), /*Preamble=*/nullptr,
+llvm::MemoryBuffer::getMemBuffer(FS.Files[MainFile], MainFile),
+std::make_shared(), VFS, IgnoreDiags);
+
+EXPECT_FALSE(Clang->getFrontendOpts().Inputs.empty());
+return Clang;
   }
 
 protected:
+  std::vector collectIncludes() {
+auto Clang = setupClang();
+PreprocessOnlyAction Action;
+EXPECT_TRUE(
+Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]));
+std::vector Inclusions;
+Clang->getPreprocessor().addPPCallbacks(collectInclusionsInMainFileCallback(
+Clang->getSourceManager(),
+[&](Inclusion Inc) { Inclusions.push_back(std::move(Inc)); }));
+EXPECT_TRUE(Action.Execute());
+Action.EndSourceFile();
+return Inclusions;
+  }
+
   // Calculates the include path, or returns "" on error.
   std::string calculate(PathRef Original, PathRef Preferred = "",
+const std::vector  = {},
 bool ExpectError = false) {
+auto Clang = setupClang();
+PreprocessOnlyAction Action;
+EXPECT_TRUE(
+Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]));
+
 if (Preferred.empty())
   Preferred = Original;
-auto VFS = FS.getFileSystem();
-auto Cmd = CDB.getCompileCommand(MainFile);
-assert(static_cast(Cmd));
-VFS->setCurrentWorkingDirectory(Cmd->Directory);
 auto ToHeaderFile = [](llvm::StringRef Header) {
   return HeaderFile{Header,
 /*Verbatim=*/!llvm::sys::path::is_absolute(Header)};
 };
-auto Path = calculateIncludePath(MainFile, FS.Files[MainFile],
- ToHeaderFile(Original),
- ToHeaderFile(Preferred), *Cmd, VFS);
+
+auto Path = calculateIncludePath(
+MainFile, CDB.getCompileCommand(MainFile)->Directory,
+Clang->getPreprocessor().getHeaderSearchInfo(), Inclusions,
+ToHeaderFile(Original), ToHeaderFile(Preferred));
+Action.EndSourceFile();
 if (!Path) {
   llvm::consumeError(Path.takeError());
   EXPECT_TRUE(ExpectError);
@@ -49,52 +108,50 @@
 }
 return std::move(*Path);
   }
+
+  Expected
+  insert(const HeaderFile , const HeaderFile ,
+ const std::vector  = {}) {
+auto Clang = setupClang();
+PreprocessOnlyAction Action;
+EXPECT_TRUE(
+Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]));
+
+IncludeInserter Inserter(MainFile, /*Code=*/"", format::getLLVMStyle(),
+ CDB.getCompileCommand(MainFile)->Directory,
+ Clang->getPreprocessor().getHeaderSearchInfo());
+for (const auto  : ExistingInclusions)
+  Inserter.addExisting(Inc);
+
+auto 

[PATCH] D46846: [Attr] Fix printing attrs for enum forward decl at file scope

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: aaron.ballman, rsmith, hfinkel.

For example, given:

  enum __attribute__((deprecated)) T *p;

-ast-print produced:

  enum T *p;

The trouble was that the EnumDecl node was suppressed, as revealed by
-ast-dump.  The suppression of the EnumDecl was intentional in
r116122, but I don't understand why.  The suppression isn't needed for
the test suite to behave.


https://reviews.llvm.org/D46846

Files:
  lib/Sema/SemaDecl.cpp
  test/Sema/ast-print.c


Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field 
designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been 
explicitly marked deprecated here}}"
+// RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is 
deprecated}}"
+// RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes2' has been 
explicitly marked deprecated here}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes3' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been 
explicitly marked deprecated here}}"
 // RUN: %clang_cc1 -fsyntax-only %t.c -verify
@@ -86,8 +88,7 @@
   // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note 
{{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
-// FIXME: If enum is forward-declared at file scope, attributes are lost.
-// CHECK-LABEL: enum EnumWithAttributes2 *EnumWithAttributes2Ptr;
+// CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 
*EnumWithAttributes2Ptr;
 // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
 // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked 
deprecated here}}
 enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -14273,7 +14273,6 @@
   // PrevDecl.
   TagDecl *New;
 
-  bool IsForwardReference = false;
   if (Kind == TTK_Enum) {
 // FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
 // enum X { A, B, C } D;D should chain to X.
@@ -14303,12 +14302,6 @@
 else if (getLangOpts().CPlusPlus)
   DiagID = diag::err_forward_ref_enum;
 Diag(Loc, DiagID);
-
-// If this is a forward-declared reference to an enumeration, make a
-// note of it; we won't actually be introducing the declaration into
-// the declaration context.
-if (TUK == TUK_Reference)
-  IsForwardReference = true;
   }
 }
 
@@ -14466,9 +14459,7 @@
 PushOnScopeChains(New, EnclosingScope, /* AddToContext = */ false);
   } else if (Name) {
 S = getNonFieldDeclScope(S);
-PushOnScopeChains(New, S, !IsForwardReference);
-if (IsForwardReference)
-  SearchDC->makeDeclVisibleInContext(New);
+PushOnScopeChains(New, S, true);
   } else {
 CurContext->addDecl(New);
   }


Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been explicitly marked deprecated here}}"
+// RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is deprecated}}"
+// RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes2' has been explicitly marked deprecated here}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes3' is deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been explicitly marked deprecated here}}"
 // RUN: %clang_cc1 -fsyntax-only %t.c -verify
@@ -86,8 +88,7 @@
   // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
-// FIXME: If enum is forward-declared at file scope, attributes are lost.
-// CHECK-LABEL: enum EnumWithAttributes2 *EnumWithAttributes2Ptr;
+// CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 *EnumWithAttributes2Ptr;
 // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
 // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked deprecated here}}
 enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
Index: lib/Sema/SemaDecl.cpp

r332288 - Remove the fixit for the diagnostics regarding capturing autoreleasing variables in a block

2018-05-14 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon May 14 13:29:16 2018
New Revision: 332288

URL: http://llvm.org/viewvc/llvm-project?rev=332288=rev
Log:
Remove the fixit for the diagnostics regarding capturing autoreleasing 
variables in a block

The fixit is actively harmful, as it encourages developers to ignore the
warning and to write unsafe code.
It is almost impossible to write safe code while capturing autoreleasing
variables in the block, as in order to check that the block is never
called in the autoreleasing pool the developer has to check the
transitive closure of all potential callers of the block.

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/arc.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=332288=332287=332288=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon May 14 13:29:16 
2018
@@ -5435,8 +5435,6 @@ def warn_block_capture_autoreleasing : W
   "block captures an autoreleasing out-parameter, which may result in "
   "use-after-free bugs">,
   InGroup;
-def note_declare_parameter_autoreleasing : Note<
-  "declare the parameter __autoreleasing explicitly to suppress this warning">;
 def note_declare_parameter_strong : Note<
   "declare the parameter __strong or capture a __block __strong variable to "
   "keep values alive across autorelease pools">;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=332288=332287=332288=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon May 14 13:29:16 2018
@@ -14579,30 +14579,6 @@ static bool captureInBlock(BlockScopeInf
   if (BuildAndDiagnose) {
 SourceLocation VarLoc = Var->getLocation();
 S.Diag(Loc, diag::warn_block_capture_autoreleasing);
-{
-  auto AddAutoreleaseNote =
-  S.Diag(VarLoc, diag::note_declare_parameter_autoreleasing);
-  // Provide a fix-it for the '__autoreleasing' keyword at the
-  // appropriate location in the variable's type.
-  if (const auto *TSI = Var->getTypeSourceInfo()) {
-PointerTypeLoc PTL =
-TSI->getTypeLoc().getAsAdjusted();
-if (PTL) {
-  SourceLocation Loc = PTL.getPointeeLoc().getEndLoc();
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, S.getSourceManager(),
-   S.getLangOpts());
-  if (Loc.isValid()) {
-StringRef CharAtLoc = Lexer::getSourceText(
-CharSourceRange::getCharRange(Loc, 
Loc.getLocWithOffset(1)),
-S.getSourceManager(), S.getLangOpts());
-AddAutoreleaseNote << FixItHint::CreateInsertion(
-Loc, CharAtLoc.empty() || !isWhitespace(CharAtLoc[0])
- ? " __autoreleasing "
- : " __autoreleasing");
-  }
-}
-  }
-}
 S.Diag(VarLoc, diag::note_declare_parameter_strong);
   }
 }

Modified: cfe/trunk/test/SemaObjC/arc.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc.m?rev=332288=332287=332288=diff
==
--- cfe/trunk/test/SemaObjC/arc.m (original)
+++ cfe/trunk/test/SemaObjC/arc.m Mon May 14 13:29:16 2018
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak 
-fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s
-// RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak 
-fsyntax-only -fobjc-arc -fblocks -Wno-objc-root-class 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak 
-fsyntax-only -fobjc-arc -fblocks -Wno-objc-root-class 
-fdiagnostics-parseable-fixits %s 2>&1
 
 typedef unsigned long NSUInteger;
 typedef const void * CFTypeRef;
@@ -811,23 +811,17 @@ int garf() {
 }
 
 void block_capture_autoreleasing(A * __autoreleasing *a,
- A **b, // expected-note {{declare the 
parameter __autoreleasing explicitly to suppress this warning}} expected-note 
{{declare the parameter __strong or capture a __block __strong variable to keep 
values alive across autorelease pools}}
- A * _Nullable *c, // expected-note {{declare 
the parameter __autoreleasing explicitly to suppress this warning}} 
expected-note {{declare the parameter __strong or capture a 

r332287 - [Tooling] Pull #include manipulation code from clangFormat into libToolingCore.

2018-05-14 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Mon May 14 13:17:53 2018
New Revision: 332287

URL: http://llvm.org/viewvc/llvm-project?rev=332287=rev
Log:
[Tooling] Pull #include manipulation code from clangFormat into libToolingCore.

Summary: Also pull #include related style out of FormatStyle as 
tooling::IncludeStyle.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, mgorny, cfe-commits, djasper

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

Added:
cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h
cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp
cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp
Modified:
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Tooling/Core/CMakeLists.txt
cfe/trunk/unittests/Format/CleanupTest.cpp
cfe/trunk/unittests/Tooling/CMakeLists.txt

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332287=332286=332287=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Mon May 14 13:17:53 2018
@@ -19,6 +19,7 @@
 #include "clang/Tooling/Core/IncludeStyle.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Regex.h"
 #include 
 
 namespace clang {
@@ -1810,17 +1811,13 @@ formatReplacements(StringRef Code, const
 /// This also supports inserting/deleting C++ #include directives:
 /// - If a replacement has offset UINT_MAX, length 0, and a replacement text
 ///   that is an #include directive, this will insert the #include into the
-///   correct block in the \p Code. When searching for points to insert new
-///   header, this ignores #include's after the #include block(s) in the
-///   beginning of a file to avoid inserting headers into code sections where
-///   new #include's should not be added by default. These code sections
-///   include:
-/// - raw string literals (containing #include).
-/// - #if blocks.
-/// - Special #include's among declarations (e.g. functions).
+///   correct block in the \p Code.
 /// - If a replacement has offset UINT_MAX, length 1, and a replacement text
 ///   that is the name of the header to be removed, the header will be removed
 ///   from \p Code if it exists.
+/// The include manipulation is done via `tooling::HeaderInclude`, see its
+/// documentation for more details on how include insertion points are found 
and
+/// what edits are produced.
 llvm::Expected
 cleanupAroundReplacements(StringRef Code, const tooling::Replacements 
,
   const FormatStyle );

Added: cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h?rev=332287=auto
==
--- cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h (added)
+++ cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h Mon May 14 13:17:53 
2018
@@ -0,0 +1,137 @@
+//===--- HeaderIncludes.h - Insert/Delete #includes for C++ code--*- 
C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H
+#define LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H
+
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "clang/Tooling/Core/IncludeStyle.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Regex.h"
+#include 
+
+namespace clang {
+namespace tooling {
+
+/// This class manages priorities of C++ #include categories and calculates
+/// priorities for headers.
+/// FIXME(ioeric): move this class into implementation file when clang-format's
+/// include sorting functions are also moved here.
+class IncludeCategoryManager {
+public:
+  IncludeCategoryManager(const IncludeStyle , StringRef FileName);
+
+  /// Returns the priority of the category which \p IncludeName belongs to.
+  /// If \p CheckMainHeader is true and \p IncludeName is a main header, 
returns
+  /// 0. Otherwise, returns the priority of the matching category or INT_MAX.
+  /// NOTE: this API is not thread-safe!
+  int getIncludePriority(StringRef IncludeName, bool CheckMainHeader) const;
+
+private:
+  bool isMainHeader(StringRef IncludeName) const;
+
+  const IncludeStyle Style;
+  bool IsMainFile;
+  std::string FileName;
+  // This refers to a substring in FileName.
+  StringRef FileStem;
+  // Regex is not thread-safe.
+  mutable SmallVector CategoryRegexs;
+};
+
+/// Generates replacements for inserting or deleting #include directives in a
+/// file.
+class HeaderIncludes {
+public:

[PATCH] D46496: [Tooling] Pull #include manipulation code from clangFormat into libToolingCore.

2018-05-14 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332287: [Tooling] Pull #include manipulation code from 
clangFormat into libToolingCore. (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D46496

Files:
  cfe/trunk/include/clang/Format/Format.h
  cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Tooling/Core/CMakeLists.txt
  cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp
  cfe/trunk/unittests/Format/CleanupTest.cpp
  cfe/trunk/unittests/Tooling/CMakeLists.txt
  cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp

Index: cfe/trunk/include/clang/Format/Format.h
===
--- cfe/trunk/include/clang/Format/Format.h
+++ cfe/trunk/include/clang/Format/Format.h
@@ -19,6 +19,7 @@
 #include "clang/Tooling/Core/IncludeStyle.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Regex.h"
 #include 
 
 namespace clang {
@@ -1810,17 +1811,13 @@
 /// This also supports inserting/deleting C++ #include directives:
 /// - If a replacement has offset UINT_MAX, length 0, and a replacement text
 ///   that is an #include directive, this will insert the #include into the
-///   correct block in the \p Code. When searching for points to insert new
-///   header, this ignores #include's after the #include block(s) in the
-///   beginning of a file to avoid inserting headers into code sections where
-///   new #include's should not be added by default. These code sections
-///   include:
-/// - raw string literals (containing #include).
-/// - #if blocks.
-/// - Special #include's among declarations (e.g. functions).
+///   correct block in the \p Code.
 /// - If a replacement has offset UINT_MAX, length 1, and a replacement text
 ///   that is the name of the header to be removed, the header will be removed
 ///   from \p Code if it exists.
+/// The include manipulation is done via `tooling::HeaderInclude`, see its
+/// documentation for more details on how include insertion points are found and
+/// what edits are produced.
 llvm::Expected
 cleanupAroundReplacements(StringRef Code, const tooling::Replacements ,
   const FormatStyle );
Index: cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h
===
--- cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h
+++ cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h
@@ -0,0 +1,137 @@
+//===--- HeaderIncludes.h - Insert/Delete #includes for C++ code--*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H
+#define LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H
+
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "clang/Tooling/Core/IncludeStyle.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Regex.h"
+#include 
+
+namespace clang {
+namespace tooling {
+
+/// This class manages priorities of C++ #include categories and calculates
+/// priorities for headers.
+/// FIXME(ioeric): move this class into implementation file when clang-format's
+/// include sorting functions are also moved here.
+class IncludeCategoryManager {
+public:
+  IncludeCategoryManager(const IncludeStyle , StringRef FileName);
+
+  /// Returns the priority of the category which \p IncludeName belongs to.
+  /// If \p CheckMainHeader is true and \p IncludeName is a main header, returns
+  /// 0. Otherwise, returns the priority of the matching category or INT_MAX.
+  /// NOTE: this API is not thread-safe!
+  int getIncludePriority(StringRef IncludeName, bool CheckMainHeader) const;
+
+private:
+  bool isMainHeader(StringRef IncludeName) const;
+
+  const IncludeStyle Style;
+  bool IsMainFile;
+  std::string FileName;
+  // This refers to a substring in FileName.
+  StringRef FileStem;
+  // Regex is not thread-safe.
+  mutable SmallVector CategoryRegexs;
+};
+
+/// Generates replacements for inserting or deleting #include directives in a
+/// file.
+class HeaderIncludes {
+public:
+  HeaderIncludes(llvm::StringRef FileName, llvm::StringRef Code,
+ const IncludeStyle );
+
+  /// Inserts an #include directive of \p Header into the code. If \p IsAngled
+  /// is true, \p Header will be quoted with <> in the directive; otherwise, it
+  /// will be quoted with "".
+  ///
+  /// When searching for points to insert new header, this ignores #include's
+  /// after the #include block(s) in the beginning of a file to avoid inserting
+  /// headers into code sections where new #include's should not 

r332286 - PR37450: Fix bug that disabled some type checks for variables with deduced types.

2018-05-14 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon May 14 13:15:04 2018
New Revision: 332286

URL: http://llvm.org/viewvc/llvm-project?rev=332286=rev
Log:
PR37450: Fix bug that disabled some type checks for variables with deduced 
types.

Also improve diagnostic for the case where a type is non-literal because it's a 
lambda.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp
cfe/trunk/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
cfe/trunk/test/SemaCXX/for-range-examples.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=332286=332285=332286=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon May 14 13:15:04 
2018
@@ -2381,6 +2381,8 @@ def note_non_literal_user_provided_dtor
   "%0 is not literal because it has a user-provided destructor">;
 def note_non_literal_nontrivial_dtor : Note<
   "%0 is not literal because it has a non-trivial destructor">;
+def note_non_literal_lambda : Note<
+  "lambda closure types are non-literal types before C++17">;
 def warn_private_extern : Warning<
   "use of __private_extern__ on a declaration may not produce external symbol "
   "private to the linkage unit and is deprecated">, InGroup;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=332286=332285=332286=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon May 14 13:15:04 2018
@@ -7293,8 +7293,7 @@ void Sema::CheckVariableDeclarationType(
   if (NewVD->isInvalidDecl())
 return;
 
-  TypeSourceInfo *TInfo = NewVD->getTypeSourceInfo();
-  QualType T = TInfo->getType();
+  QualType T = NewVD->getType();
 
   // Defer checking an 'auto' type until its initializer is attached.
   if (T->isUndeducedType())
@@ -7438,10 +7437,18 @@ void Sema::CheckVariableDeclarationType(
   (T->isVariableArrayType() && NewVD->hasGlobalStorage())) {
 bool SizeIsNegative;
 llvm::APSInt Oversized;
-TypeSourceInfo *FixedTInfo =
-  TryToFixInvalidVariablyModifiedTypeSourceInfo(TInfo, Context,
-SizeIsNegative, Oversized);
-if (!FixedTInfo && T->isVariableArrayType()) {
+TypeSourceInfo *FixedTInfo = TryToFixInvalidVariablyModifiedTypeSourceInfo(
+NewVD->getTypeSourceInfo(), Context, SizeIsNegative, Oversized);
+QualType FixedT;
+if (FixedTInfo &&  T == NewVD->getTypeSourceInfo()->getType())
+  FixedT = FixedTInfo->getType();
+else if (FixedTInfo) {
+  // Type and type-as-written are canonically different. We need to fix up
+  // both types separately.
+  FixedT = TryToFixInvalidVariablyModifiedType(T, Context, SizeIsNegative,
+   Oversized);
+}
+if ((!FixedTInfo || FixedT.isNull()) && T->isVariableArrayType()) {
   const VariableArrayType *VAT = Context.getAsVariableArrayType(T);
   // FIXME: This won't give the correct result for
   // int a[10][n];
@@ -7470,7 +7477,7 @@ void Sema::CheckVariableDeclarationType(
 }
 
 Diag(NewVD->getLocation(), diag::warn_illegal_constant_array_size);
-NewVD->setType(FixedTInfo->getType());
+NewVD->setType(FixedT);
 NewVD->setTypeSourceInfo(FixedTInfo);
   }
 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=332286=332285=332286=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon May 14 13:15:04 2018
@@ -7809,6 +7809,13 @@ bool Sema::RequireLiteralType(SourceLoca
   if (RequireCompleteType(Loc, ElemType, diag::note_non_literal_incomplete, T))
 return true;
 
+  // [expr.prim.lambda]p3:
+  //   This class type is [not] a literal type.
+  if (RD->isLambda() && !getLangOpts().CPlusPlus17) {
+Diag(RD->getLocation(), diag::note_non_literal_lambda);
+return true;
+  }
+
   // If the class has virtual base classes, then it's not an aggregate, and
   // cannot have any constexpr constructors or a trivial default constructor,
   // so is non-literal. This is better to diagnose than the resulting absence

Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp?rev=332286=332285=332286=diff
==
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp 

[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 146668.
jdenny added a comment.

Rebased.  Ping.


https://reviews.llvm.org/D45465

Files:
  lib/AST/DeclPrinter.cpp
  test/Misc/ast-print-enum-decl.c
  test/Misc/ast-print-record-decl.c
  test/Sema/ast-print.c
  test/SemaCXX/ast-print.cpp

Index: test/SemaCXX/ast-print.cpp
===
--- test/SemaCXX/ast-print.cpp
+++ test/SemaCXX/ast-print.cpp
@@ -214,10 +214,13 @@
 struct [[gnu::visibility("hidden")]] S;
 }
 
-// CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{};
+// CHECK:  struct CXXFunctionalCastExprPrint {
+// CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
 struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{};
 
-// CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{};
+// CHECK:  struct CXXTemporaryObjectExprPrint {
+// CHECK-NEXT:   CXXTemporaryObjectExprPrint();
+// CHECK-NEXT: } toe = CXXTemporaryObjectExprPrint{};
 struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{};
 
 namespace PR24872 {
Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -83,8 +83,7 @@
   EnumWithAttributesFoo __attribute__((deprecated)),
   // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50
   EnumWithAttributesBar __attribute__((unavailable)) = 50
-  // CHECK-NEXT: };
-  // CHECK-NEXT: enum EnumWithAttributes *EnumWithAttributesPtr;
+  // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
 // FIXME: If enum is forward-declared at file scope, attributes are lost.
Index: test/Misc/ast-print-record-decl.c
===
--- test/Misc/ast-print-record-decl.c
+++ test/Misc/ast-print-record-decl.c
@@ -6,8 +6,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -18,7 +18,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \
+//   RUN: -DBASES= %s
 
 // Repeat for union:
 //
@@ -28,8 +29,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -40,7 +41,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \
+//   RUN: -DBASES= %s
 
 // Repeat for C++ (BASES helps ensure we're printing as C++ not as C):
 //
@@ -52,7 +54,7 @@
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
 //   RUN: > %t.cpp
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN:   -DBASES=' : B' %s --input-file %t.cpp
 //
 //   Now check compiling and printing of the printed file.
@@ -64,7 +66,7 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.cpp \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN: -DBASES=' : B' %s
 
 // END.
@@ -153,25 +155,32 @@
   // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}}
   KW __attribute__((deprecated(""))) T *p0;
 
-  // PRINT-NEXT: [[KW]] __attribute__((aligned(16))) T[[BASES]] {
-  // PRINT-NEXT:   int i;
-  // PRINT-NEXT:   [[KW]] T *p2;
-  // PRINT-NEXT: } *p1;
-  KW __attribute__((aligned(16))) T BASES { // expected-warning {{'T' is deprecated}}
+  // PRINT-NEXT:  [[KW]] __attribute__((aligned(64))) T[[BASES]] {
+  // PRINT-NEXT:int i;
+  // PRINT-NEXT:[[KW]] T *p2;
+  // PRINT-NEXT:[[KW]] __attribute__((may_alias)) T *p3, *p4;
+  // PRINT-NEXT:  } *p1;
+  KW 

[PATCH] D46496: [Tooling] Pull #include manipulation code from clangFormat into libToolingCore.

2018-05-14 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 14.
ioeric added a comment.

- Merged with origin/master
- Make copy instead of taking references to ensure lifetime.


Repository:
  rC Clang

https://reviews.llvm.org/D46496

Files:
  include/clang/Format/Format.h
  include/clang/Tooling/Core/HeaderIncludes.h
  lib/Format/Format.cpp
  lib/Tooling/Core/CMakeLists.txt
  lib/Tooling/Core/HeaderIncludes.cpp
  unittests/Format/CleanupTest.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/HeaderIncludesTest.cpp

Index: unittests/Tooling/HeaderIncludesTest.cpp
===
--- /dev/null
+++ unittests/Tooling/HeaderIncludesTest.cpp
@@ -0,0 +1,527 @@
+//===- unittest/Tooling/CleanupTest.cpp - Include insertion/deletion tests ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Tooling/Core/HeaderIncludes.h"
+#include "../Tooling/ReplacementTest.h"
+#include "../Tooling/RewriterTestContext.h"
+#include "clang/Format/Format.h"
+#include "clang/Tooling/Core/Replacement.h"
+
+#include "gtest/gtest.h"
+
+using clang::tooling::ReplacementTest;
+using clang::tooling::toReplacements;
+
+namespace clang {
+namespace tooling {
+namespace {
+
+class HeaderIncludesTest : public ::testing::Test {
+protected:
+  std::string insert(llvm::StringRef Code, llvm::StringRef Header) {
+HeaderIncludes Includes(FileName, Code, Style);
+assert(Header.startswith("\"") || Header.startswith("<"));
+auto R = Includes.insert(Header.trim("\"<>"), Header.startswith("<"));
+if (!R)
+  return Code;
+auto Result = applyAllReplacements(Code, Replacements(*R));
+EXPECT_TRUE(static_cast(Result));
+return *Result;
+  }
+
+  std::string remove(llvm::StringRef Code, llvm::StringRef Header) {
+HeaderIncludes Includes(FileName, Code, Style);
+assert(Header.startswith("\"") || Header.startswith("<"));
+auto Replaces = Includes.remove(Header.trim("\"<>"), Header.startswith("<"));
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+return *Result;
+  }
+
+  const std::string FileName = "fix.cpp";
+  IncludeStyle Style = format::getLLVMStyle().IncludeStyle;
+};
+
+TEST_F(HeaderIncludesTest, NoExistingIncludeWithoutDefine) {
+  std::string Code = "int main() {}";
+  std::string Expected = "#include \"a.h\"\n"
+ "int main() {}";
+  EXPECT_EQ(Expected, insert(Code, "\"a.h\""));
+}
+
+TEST_F(HeaderIncludesTest, NoExistingIncludeWithDefine) {
+  std::string Code = "#ifndef A_H\n"
+ "#define A_H\n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+  std::string Expected = "#ifndef A_H\n"
+ "#define A_H\n"
+ "#include \"b.h\"\n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+
+  EXPECT_EQ(Expected, insert(Code, "\"b.h\""));
+}
+
+TEST_F(HeaderIncludesTest, InsertBeforeCategoryWithLowerPriority) {
+  std::string Code = "#ifndef A_H\n"
+ "#define A_H\n"
+ "\n"
+ "\n"
+ "\n"
+ "#include \n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+  std::string Expected = "#ifndef A_H\n"
+ "#define A_H\n"
+ "\n"
+ "\n"
+ "\n"
+ "#include \"a.h\"\n"
+ "#include \n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+
+  EXPECT_EQ(Expected, insert(Code, "\"a.h\""));
+}
+
+TEST_F(HeaderIncludesTest, InsertAfterMainHeader) {
+  std::string Code = "#include \"fix.h\"\n"
+ "\n"
+ "int main() {}";
+  std::string Expected = "#include \"fix.h\"\n"
+ "#include \n"
+ "\n"
+ "int main() {}";
+  Style = format::getGoogleStyle(format::FormatStyle::LanguageKind::LK_Cpp)
+  .IncludeStyle;
+  EXPECT_EQ(Expected, insert(Code, ""));
+}
+
+TEST_F(HeaderIncludesTest, InsertBeforeSystemHeaderLLVM) {
+  std::string Code = "#include \n"
+ "\n"
+ "int main() {}";
+  std::string Expected = "#include \"z.h\"\n"
+ "#include \n"
+ "\n"
+ "int main() {}";
+  EXPECT_EQ(Expected, insert(Code, "\"z.h\""));
+}
+
+TEST_F(HeaderIncludesTest, InsertAfterSystemHeaderGoogle) {
+  std::string Code = 

[PATCH] D46758: [clang-format] Move #include related style to libToolingCore

2018-05-14 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332284: [clang-format] Move #include related style to 
libToolingCore (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D46758

Files:
  cfe/trunk/include/clang/Format/Format.h
  cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Tooling/Core/CMakeLists.txt
  cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp
  cfe/trunk/unittests/Format/SortIncludesTest.cpp

Index: cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp
===
--- cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp
+++ cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp
@@ -0,0 +1,32 @@
+//===--- IncludeStyle.cpp - Style of C++ #include directives -*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Tooling/Core/IncludeStyle.h"
+
+
+using clang::tooling::IncludeStyle;
+
+namespace llvm {
+namespace yaml {
+
+void MappingTraits::mapping(
+IO , IncludeStyle::IncludeCategory ) {
+  IO.mapOptional("Regex", Category.Regex);
+  IO.mapOptional("Priority", Category.Priority);
+}
+
+void ScalarEnumerationTraits::enumeration(
+IO , IncludeStyle::IncludeBlocksStyle ) {
+  IO.enumCase(Value, "Preserve", IncludeStyle::IBS_Preserve);
+  IO.enumCase(Value, "Merge", IncludeStyle::IBS_Merge);
+  IO.enumCase(Value, "Regroup", IncludeStyle::IBS_Regroup);
+}
+
+} // namespace yaml
+} // namespace llvm
Index: cfe/trunk/lib/Tooling/Core/CMakeLists.txt
===
--- cfe/trunk/lib/Tooling/Core/CMakeLists.txt
+++ cfe/trunk/lib/Tooling/Core/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangToolingCore
+  IncludeStyle.cpp
   Lookup.cpp
   Replacement.cpp
   Diagnostic.cpp
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -48,7 +48,6 @@
 
 using clang::format::FormatStyle;
 
-LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory)
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::RawStringFormat)
 
 namespace llvm {
@@ -372,9 +371,9 @@
Style.ExperimentalAutoDetectBinPacking);
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
-IO.mapOptional("IncludeBlocks", Style.IncludeBlocks);
-IO.mapOptional("IncludeCategories", Style.IncludeCategories);
-IO.mapOptional("IncludeIsMainRegex", Style.IncludeIsMainRegex);
+IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
+IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
+IO.mapOptional("IncludeIsMainRegex", Style.IncludeStyle.IncludeIsMainRegex);
 IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
 IO.mapOptional("IndentPPDirectives", Style.IndentPPDirectives);
 IO.mapOptional("IndentWidth", Style.IndentWidth);
@@ -456,21 +455,6 @@
   }
 };
 
-template <> struct MappingTraits {
-  static void mapping(IO , FormatStyle::IncludeCategory ) {
-IO.mapOptional("Regex", Category.Regex);
-IO.mapOptional("Priority", Category.Priority);
-  }
-};
-
-template <> struct ScalarEnumerationTraits {
-  static void enumeration(IO , FormatStyle::IncludeBlocksStyle ) {
-IO.enumCase(Value, "Preserve", FormatStyle::IBS_Preserve);
-IO.enumCase(Value, "Merge", FormatStyle::IBS_Merge);
-IO.enumCase(Value, "Regroup", FormatStyle::IBS_Regroup);
-  }
-};
-
 template <> struct MappingTraits {
   static void mapping(IO , FormatStyle::RawStringFormat ) {
 IO.mapOptional("Language", Format.Language);
@@ -639,11 +623,12 @@
   LLVMStyle.ForEachMacros.push_back("foreach");
   LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
   LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
-  LLVMStyle.IncludeCategories = {{"^\"(llvm|llvm-c|clang|clang-c)/", 2},
- {"^(<|\"(gtest|gmock|isl|json)/)", 3},
- {".*", 1}};
-  LLVMStyle.IncludeIsMainRegex = "(Test)?$";
-  LLVMStyle.IncludeBlocks = FormatStyle::IBS_Preserve;
+  LLVMStyle.IncludeStyle.IncludeCategories = {
+  {"^\"(llvm|llvm-c|clang|clang-c)/", 2},
+  {"^(<|\"(gtest|gmock|isl|json)/)", 3},
+  {".*", 1}};
+  LLVMStyle.IncludeStyle.IncludeIsMainRegex = "(Test)?$";
+  LLVMStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
   LLVMStyle.IndentCaseLabels = false;
   LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
   

r332284 - [clang-format] Move #include related style to libToolingCore

2018-05-14 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Mon May 14 12:51:33 2018
New Revision: 332284

URL: http://llvm.org/viewvc/llvm-project?rev=332284=rev
Log:
[clang-format] Move #include related style to libToolingCore

Summary: This will be shared by include insertion/deletion library.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: mgorny, klimek, cfe-commits

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

Added:
cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h
cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp
Modified:
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Tooling/Core/CMakeLists.txt
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/SortIncludesTest.cpp

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332284=332283=332284=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Mon May 14 12:51:33 2018
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_FORMAT_FORMAT_H
 
 #include "clang/Basic/LangOptions.h"
+#include "clang/Tooling/Core/IncludeStyle.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
 #include 
@@ -998,91 +999,7 @@ struct FormatStyle {
   /// For example: BOOST_FOREACH.
   std::vector ForEachMacros;
 
-  /// Styles for sorting multiple ``#include`` blocks.
-  enum IncludeBlocksStyle {
-/// Sort each ``#include`` block separately.
-/// \code
-///#include "b.h"   into  #include "b.h"
-///
-///#include   #include "a.h"
-///#include "a.h" #include 
-/// \endcode
-IBS_Preserve,
-/// Merge multiple ``#include`` blocks together and sort as one.
-/// \code
-///#include "b.h"   into  #include "a.h"
-///   #include "b.h"
-///#include   #include 
-///#include "a.h"
-/// \endcode
-IBS_Merge,
-/// Merge multiple ``#include`` blocks together and sort as one.
-/// Then split into groups based on category priority. See
-/// ``IncludeCategories``.
-/// \code
-///#include "b.h"   into  #include "a.h"
-///   #include "b.h"
-///#include 
-///#include "a.h" #include 
-/// \endcode
-IBS_Regroup,
-  };
-
-  /// Dependent on the value, multiple ``#include`` blocks can be sorted
-  /// as one and divided based on category.
-  IncludeBlocksStyle IncludeBlocks;
-
-  /// See documentation of ``IncludeCategories``.
-  struct IncludeCategory {
-/// The regular expression that this category matches.
-std::string Regex;
-/// The priority to assign to this category.
-int Priority;
-bool operator==(const IncludeCategory ) const {
-  return Regex == Other.Regex && Priority == Other.Priority;
-}
-  };
-
-  /// Regular expressions denoting the different ``#include`` categories
-  /// used for ordering ``#includes``.
-  ///
-  /// These regular expressions are matched against the filename of an include
-  /// (including the <> or "") in order. The value belonging to the first
-  /// matching regular expression is assigned and ``#includes`` are sorted 
first
-  /// according to increasing category number and then alphabetically within
-  /// each category.
-  ///
-  /// If none of the regular expressions match, INT_MAX is assigned as
-  /// category. The main header for a source file automatically gets category 
0.
-  /// so that it is generally kept at the beginning of the ``#includes``
-  /// (http://llvm.org/docs/CodingStandards.html#include-style). However, you
-  /// can also assign negative priorities if you have certain headers that
-  /// always need to be first.
-  ///
-  /// To configure this in the .clang-format file, use:
-  /// \code{.yaml}
-  ///   IncludeCategories:
-  /// - Regex:   '^"(llvm|llvm-c|clang|clang-c)/'
-  ///   Priority:2
-  /// - Regex:   '^(<|"(gtest|gmock|isl|json)/)'
-  ///   Priority:3
-  /// - Regex:   '.*'
-  ///   Priority:1
-  /// \endcode
-  std::vector IncludeCategories;
-
-  /// Specify a regular expression of suffixes that are allowed in the
-  /// file-to-main-include mapping.
-  ///
-  /// When guessing whether a #include is the "main" include (to assign
-  /// category 0, see above), use this regex of allowed suffixes to the header
-  /// stem. A partial match is done, so that:
-  /// - "" means "arbitrary suffix"
-  /// - "$" means "no suffix"
-  ///
-  /// For example, if configured to "(_test)?$", then a header a.h would be 
seen
-  /// as the "main" include in both a.cc and a_test.cc.
-  std::string IncludeIsMainRegex;
+  

[PATCH] D46050: [Frontend] Avoid running plugins during code completion parse

2018-05-14 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added inline comments.
This revision is now accepted and ready to land.



Comment at: test/Index/complete-and-plugins.c:3
+
+// RUN: c-index-test -code-completion-at=%s:6:1 -load 
%llvmshlibdir/PrintFunctionNames%pluginext -add-plugin print-fns %s | FileCheck 
%s
+// REQUIRES: plugins, examples

nit: usually the RUN lines go above the C code, not below it.


https://reviews.llvm.org/D46050



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


[libcxx] r332282 - Update XFAIL so apple-clang-9.0 is the last version not implementing Core 2094.

2018-05-14 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon May 14 12:45:24 2018
New Revision: 332282

URL: http://llvm.org/viewvc/llvm-project?rev=332282=rev
Log:
Update XFAIL so apple-clang-9.0 is the last version not implementing Core 2094.

The test is passing with apple-clang-9.1. rdar://problem/40222003

Modified:

libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp?rev=332282=332281=332282=diff
==
--- 
libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp
 Mon May 14 12:45:24 2018
@@ -13,7 +13,7 @@
 
 // These compilers have not implemented Core 2094 which makes volatile
 // qualified types trivially copyable.
-// XFAIL: clang-3, clang-4, apple-clang, gcc
+// XFAIL: clang-3, clang-4, apple-clang-6, apple-clang-7, apple-clang-8, 
apple-clang-9.0, gcc
 
 #include 
 #include 


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


[PATCH] D45463: [AST] Print correct tag decl for tag specifier

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jdenny marked an inline comment as done.
Closed by commit rL332281: [AST] Print correct tag decl for tag specifier 
(authored by jdenny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45463?vs=146351=146657#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45463

Files:
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/lib/AST/DeclPrinter.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/test/Misc/ast-print-enum-decl.c
  cfe/trunk/test/Misc/ast-print-record-decl.c

Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -1419,8 +1419,8 @@
   QualType getParenType(QualType NamedType) const;
 
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
- NestedNameSpecifier *NNS,
- QualType NamedType) const;
+ NestedNameSpecifier *NNS, QualType NamedType,
+ TagDecl *OwnedTagDecl = nullptr) const;
   QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
 NestedNameSpecifier *NNS,
 const IdentifierInfo *Name,
Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -56,6 +56,7 @@
 
 class ExtQuals;
 class QualType;
+class TagDecl;
 class Type;
 
 enum {
@@ -4865,14 +4866,18 @@
   /// The type that this qualified name refers to.
   QualType NamedType;
 
+  /// The (re)declaration of this tag type owned by this occurrence, or nullptr
+  /// if none.
+  TagDecl *OwnedTagDecl;
+
   ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
- QualType NamedType, QualType CanonType)
+ QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
 : TypeWithKeyword(Keyword, Elaborated, CanonType,
   NamedType->isDependentType(),
   NamedType->isInstantiationDependentType(),
   NamedType->isVariablyModifiedType(),
   NamedType->containsUnexpandedParameterPack()),
-  NNS(NNS), NamedType(NamedType) {
+  NNS(NNS), NamedType(NamedType), OwnedTagDecl(OwnedTagDecl) {
 assert(!(Keyword == ETK_None && NNS == nullptr) &&
"ElaboratedType cannot have elaborated type keyword "
"and name qualifier both null.");
@@ -4893,15 +4898,21 @@
   /// Returns whether this type directly provides sugar.
   bool isSugared() const { return true; }
 
+  /// Return the (re)declaration of this type owned by this occurrence of this
+  /// type, or nullptr if none.
+  TagDecl *getOwnedTagDecl() const { return OwnedTagDecl; }
+
   void Profile(llvm::FoldingSetNodeID ) {
-Profile(ID, getKeyword(), NNS, NamedType);
+Profile(ID, getKeyword(), NNS, NamedType, OwnedTagDecl);
   }
 
   static void Profile(llvm::FoldingSetNodeID , ElaboratedTypeKeyword Keyword,
-  NestedNameSpecifier *NNS, QualType NamedType) {
+  NestedNameSpecifier *NNS, QualType NamedType,
+  TagDecl *OwnedTagDecl) {
 ID.AddInteger(Keyword);
 ID.AddPointer(NNS);
 NamedType.Profile(ID);
+ID.AddPointer(OwnedTagDecl);
   }
 
   static bool classof(const Type *T) {
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -1638,7 +1638,8 @@
   }
 
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
- const CXXScopeSpec , QualType T);
+ const CXXScopeSpec , QualType T,
+ TagDecl *OwnedTagDecl = nullptr);
 
   QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
   /// If AsUnevaluated is false, E is treated as though it were an evaluated
Index: cfe/trunk/test/Misc/ast-print-record-decl.c
===
--- cfe/trunk/test/Misc/ast-print-record-decl.c
+++ cfe/trunk/test/Misc/ast-print-record-decl.c
@@ -0,0 +1,235 @@
+// Check struct:
+//
+//   First check compiling and printing of this file.
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=struct -DBASES= -o - %s \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > 

[PATCH] D45463: [AST] Print correct tag decl for tag specifier

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332281: [AST] Print correct tag decl for tag specifier 
(authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45463?vs=146351=146658#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45463

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Sema/Sema.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/DeclPrinter.cpp
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/Misc/ast-print-enum-decl.c
  test/Misc/ast-print-record-decl.c

Index: include/clang/AST/ASTContext.h
===
--- include/clang/AST/ASTContext.h
+++ include/clang/AST/ASTContext.h
@@ -1419,8 +1419,8 @@
   QualType getParenType(QualType NamedType) const;
 
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
- NestedNameSpecifier *NNS,
- QualType NamedType) const;
+ NestedNameSpecifier *NNS, QualType NamedType,
+ TagDecl *OwnedTagDecl = nullptr) const;
   QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
 NestedNameSpecifier *NNS,
 const IdentifierInfo *Name,
Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -56,6 +56,7 @@
 
 class ExtQuals;
 class QualType;
+class TagDecl;
 class Type;
 
 enum {
@@ -4865,14 +4866,18 @@
   /// The type that this qualified name refers to.
   QualType NamedType;
 
+  /// The (re)declaration of this tag type owned by this occurrence, or nullptr
+  /// if none.
+  TagDecl *OwnedTagDecl;
+
   ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
- QualType NamedType, QualType CanonType)
+ QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
 : TypeWithKeyword(Keyword, Elaborated, CanonType,
   NamedType->isDependentType(),
   NamedType->isInstantiationDependentType(),
   NamedType->isVariablyModifiedType(),
   NamedType->containsUnexpandedParameterPack()),
-  NNS(NNS), NamedType(NamedType) {
+  NNS(NNS), NamedType(NamedType), OwnedTagDecl(OwnedTagDecl) {
 assert(!(Keyword == ETK_None && NNS == nullptr) &&
"ElaboratedType cannot have elaborated type keyword "
"and name qualifier both null.");
@@ -4893,15 +4898,21 @@
   /// Returns whether this type directly provides sugar.
   bool isSugared() const { return true; }
 
+  /// Return the (re)declaration of this type owned by this occurrence of this
+  /// type, or nullptr if none.
+  TagDecl *getOwnedTagDecl() const { return OwnedTagDecl; }
+
   void Profile(llvm::FoldingSetNodeID ) {
-Profile(ID, getKeyword(), NNS, NamedType);
+Profile(ID, getKeyword(), NNS, NamedType, OwnedTagDecl);
   }
 
   static void Profile(llvm::FoldingSetNodeID , ElaboratedTypeKeyword Keyword,
-  NestedNameSpecifier *NNS, QualType NamedType) {
+  NestedNameSpecifier *NNS, QualType NamedType,
+  TagDecl *OwnedTagDecl) {
 ID.AddInteger(Keyword);
 ID.AddPointer(NNS);
 NamedType.Profile(ID);
+ID.AddPointer(OwnedTagDecl);
   }
 
   static bool classof(const Type *T) {
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -1638,7 +1638,8 @@
   }
 
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
- const CXXScopeSpec , QualType T);
+ const CXXScopeSpec , QualType T,
+ TagDecl *OwnedTagDecl = nullptr);
 
   QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
   /// If AsUnevaluated is false, E is treated as though it were an evaluated
Index: test/Misc/ast-print-enum-decl.c
===
--- test/Misc/ast-print-enum-decl.c
+++ test/Misc/ast-print-enum-decl.c
@@ -0,0 +1,85 @@
+// First check compiling and printing of this file.
+//
+// RUN: %clang_cc1 -verify -ast-print %s > %t.c
+// RUN: FileCheck --check-prefixes=CHECK,PRINT %s --input-file %t.c
+//
+// Now check compiling and printing of the printed file.
+//
+// RUN: echo "// expected""-warning@* 6 {{'T' is deprecated}}" >> %t.c
+// RUN: echo "// expected""-note@* 6 {{'T' has been explicitly marked deprecated here}}" >> %t.c
+//
+// RUN: %clang_cc1 -verify -ast-print %t.c \
+// RUN: | FileCheck --check-prefixes=CHECK,PRINT %s
+
+// END.
+
+// CHECK-LABEL: defFirst
+void defFirst() {
+  // PRINT-NEXT: enum
+  // PRINT-DAG:  

r332281 - [AST] Print correct tag decl for tag specifier

2018-05-14 Thread Joel E. Denny via cfe-commits
Author: jdenny
Date: Mon May 14 12:36:45 2018
New Revision: 332281

URL: http://llvm.org/viewvc/llvm-project?rev=332281=rev
Log:
[AST] Print correct tag decl for tag specifier

For example, given:

  void fn() {
struct T *p0;
struct T { int i; } *p1;
  }

-ast-print produced:

  void fn() {
struct T { int i; } *p0;
struct T { int i; } *p1;
  }

Compiling that fails with a redefinition error.

Given:

  void fn() {
struct T *p0;
struct __attribute__((deprecated)) T *p1;
  }

-ast-print dropped the attribute.

Details:

For a tag specifier (that is, struct/union/class/enum used as a type
specifier in a declaration) that was also a tag declaration (that is,
first occurrence of the tag) or tag redeclaration (that is, later
occurrence that specifies attributes or a member list), clang printed
the tag specifier as either (1) the full tag definition if one
existed, or (2) the first tag declaration otherwise.  Redefinition
errors were sometimes introduced, as in the first example above.  Even
when that was impossible because no member list was ever specified,
attributes were sometimes lost, thus changing semantics and
diagnostics, as in the second example above.

This patch fixes a major culprit for these problems.  It does so by
creating an ElaboratedType with a new OwnedDecl member wherever an
occurrence of a tag type is a (re)declaration of that tag type.
PrintingPolicy's IncludeTagDefinition used to trigger printing of the
member list, attributes, etc. for a tag specifier by using a tag
(re)declaration selected as described above.  Now, it triggers the
same thing except it uses the tag (re)declaration stored in the
OwnedDecl.  Of course, other tooling can now make use of the new
OwnedDecl as well.

Also, to be more faithful to the original source, this patch
suppresses printing of attributes inherited from previous
declarations.

Reviewed by: rsmith, aaron.ballman

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

Added:
cfe/trunk/test/Misc/ast-print-enum-decl.c
cfe/trunk/test/Misc/ast-print-record-decl.c
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=332281=332280=332281=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon May 14 12:36:45 2018
@@ -1419,8 +1419,8 @@ public:
   QualType getParenType(QualType NamedType) const;
 
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
- NestedNameSpecifier *NNS,
- QualType NamedType) const;
+ NestedNameSpecifier *NNS, QualType NamedType,
+ TagDecl *OwnedTagDecl = nullptr) const;
   QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
 NestedNameSpecifier *NNS,
 const IdentifierInfo *Name,

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=332281=332280=332281=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon May 14 12:36:45 2018
@@ -56,6 +56,7 @@ namespace clang {
 
 class ExtQuals;
 class QualType;
+class TagDecl;
 class Type;
 
 enum {
@@ -4865,14 +4866,18 @@ class ElaboratedType : public TypeWithKe
   /// The type that this qualified name refers to.
   QualType NamedType;
 
+  /// The (re)declaration of this tag type owned by this occurrence, or nullptr
+  /// if none.
+  TagDecl *OwnedTagDecl;
+
   ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
- QualType NamedType, QualType CanonType)
+ QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
 : TypeWithKeyword(Keyword, Elaborated, CanonType,
   NamedType->isDependentType(),
   NamedType->isInstantiationDependentType(),
   NamedType->isVariablyModifiedType(),
   NamedType->containsUnexpandedParameterPack()),
-  NNS(NNS), NamedType(NamedType) {
+  NNS(NNS), NamedType(NamedType), OwnedTagDecl(OwnedTagDecl) {
 assert(!(Keyword == ETK_None && NNS == nullptr) &&
"ElaboratedType cannot have elaborated type keyword "
"and name qualifier both null.");
@@ -4893,15 +4898,21 @@ public:
   

[PATCH] D40218: [Clang] Add __builtin_launder

2018-05-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Also we probably want to hold off on landing this until PR37458 is fixed, 
otherwise `std::launder` will start miscompiling code.


https://reviews.llvm.org/D40218



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


[PATCH] D46643: CodeGen: Emit string literal in constant address space

2018-05-14 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332279: CodeGen: Emit string literal in constant address 
space (authored by yaxunl, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D46643

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/amdgcn-string-literal.cpp

Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -3044,6 +3044,39 @@
   return getTargetCodeGenInfo().getGlobalVarAddressSpace(*this, D);
 }
 
+LangAS CodeGenModule::getStringLiteralAddressSpace() const {
+  // OpenCL v1.2 s6.5.3: a string literal is in the constant address space.
+  if (LangOpts.OpenCL)
+return LangAS::opencl_constant;
+  if (auto AS = getTarget().getConstantAddressSpace())
+return AS.getValue();
+  return LangAS::Default;
+}
+
+// In address space agnostic languages, string literals are in default address
+// space in AST. However, certain targets (e.g. amdgcn) request them to be
+// emitted in constant address space in LLVM IR. To be consistent with other
+// parts of AST, string literal global variables in constant address space
+// need to be casted to default address space before being put into address
+// map and referenced by other part of CodeGen.
+// In OpenCL, string literals are in constant address space in AST, therefore
+// they should not be casted to default address space.
+static llvm::Constant *
+castStringLiteralToDefaultAddressSpace(CodeGenModule ,
+   llvm::GlobalVariable *GV) {
+  llvm::Constant *Cast = GV;
+  if (!CGM.getLangOpts().OpenCL) {
+if (auto AS = CGM.getTarget().getConstantAddressSpace()) {
+  if (AS != LangAS::Default)
+Cast = CGM.getTargetCodeGenInfo().performAddrSpaceCast(
+CGM, GV, AS.getValue(), LangAS::Default,
+GV->getValueType()->getPointerTo(
+CGM.getContext().getTargetAddressSpace(LangAS::Default)));
+}
+  }
+  return Cast;
+}
+
 template
 void CodeGenModule::MaybeHandleStaticInExternC(const SomeDecl *D,
llvm::GlobalValue *GV) {
@@ -4039,10 +4072,8 @@
 GenerateStringLiteral(llvm::Constant *C, llvm::GlobalValue::LinkageTypes LT,
   CodeGenModule , StringRef GlobalName,
   CharUnits Alignment) {
-  // OpenCL v1.2 s6.5.3: a string literal is in the constant address space.
-  unsigned AddrSpace = 0;
-  if (CGM.getLangOpts().OpenCL)
-AddrSpace = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
+  unsigned AddrSpace = CGM.getContext().getTargetAddressSpace(
+  CGM.getStringLiteralAddressSpace());
 
   llvm::Module  = CGM.getModule();
   // Create a global variable for this string
@@ -4104,7 +4135,9 @@
 
   SanitizerMD->reportGlobalToASan(GV, S->getStrTokenLoc(0), "",
   QualType());
-  return ConstantAddress(GV, Alignment);
+
+  return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
+ Alignment);
 }
 
 /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant
@@ -4148,7 +4181,9 @@
   GlobalName, Alignment);
   if (Entry)
 *Entry = GV;
-  return ConstantAddress(GV, Alignment);
+
+  return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
+ Alignment);
 }
 
 ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1374,7 +1374,7 @@
 llvm::ConstantInt::get(IntPtrTy,
getContext().getTypeSizeInChars(type).getQuantity());
 
-  llvm::Type *BP = AllocaInt8PtrTy;
+  llvm::Type *BP = CGM.Int8Ty->getPointerTo(Loc.getAddressSpace());
   if (Loc.getType() != BP)
 Loc = Builder.CreateBitCast(Loc, BP);
 
@@ -1395,11 +1395,10 @@
 // Otherwise, create a temporary global with the initializer then
 // memcpy from the global to the alloca.
 std::string Name = getStaticDeclName(CGM, D);
-unsigned AS = 0;
-if (getLangOpts().OpenCL) {
-  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
-  BP = llvm::PointerType::getInt8PtrTy(getLLVMContext(), AS);
-}
+unsigned AS = CGM.getContext().getTargetAddressSpace(
+CGM.getStringLiteralAddressSpace());
+BP = llvm::PointerType::getInt8PtrTy(getLLVMContext(), AS);
+
 llvm::GlobalVariable *GV =
   new llvm::GlobalVariable(CGM.getModule(), constant->getType(), true,
llvm::GlobalValue::PrivateLinkage,
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ 

r332279 - CodeGen: Emit string literal in constant address space

2018-05-14 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Mon May 14 12:20:12 2018
New Revision: 332279

URL: http://llvm.org/viewvc/llvm-project?rev=332279=rev
Log:
CodeGen: Emit string literal in constant address space

Some targets have constant address space (e.g. amdgcn). For them string literal 
should be
emitted in constant address space then casted to default address space.

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

Added:
cfe/trunk/test/CodeGenCXX/amdgcn-string-literal.cpp
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=332279=332278=332279=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon May 14 12:20:12 2018
@@ -1374,7 +1374,7 @@ void CodeGenFunction::EmitAutoVarInit(co
 llvm::ConstantInt::get(IntPtrTy,

getContext().getTypeSizeInChars(type).getQuantity());
 
-  llvm::Type *BP = AllocaInt8PtrTy;
+  llvm::Type *BP = CGM.Int8Ty->getPointerTo(Loc.getAddressSpace());
   if (Loc.getType() != BP)
 Loc = Builder.CreateBitCast(Loc, BP);
 
@@ -1395,11 +1395,10 @@ void CodeGenFunction::EmitAutoVarInit(co
 // Otherwise, create a temporary global with the initializer then
 // memcpy from the global to the alloca.
 std::string Name = getStaticDeclName(CGM, D);
-unsigned AS = 0;
-if (getLangOpts().OpenCL) {
-  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
-  BP = llvm::PointerType::getInt8PtrTy(getLLVMContext(), AS);
-}
+unsigned AS = CGM.getContext().getTargetAddressSpace(
+CGM.getStringLiteralAddressSpace());
+BP = llvm::PointerType::getInt8PtrTy(getLLVMContext(), AS);
+
 llvm::GlobalVariable *GV =
   new llvm::GlobalVariable(CGM.getModule(), constant->getType(), true,
llvm::GlobalValue::PrivateLinkage,

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=332279=332278=332279=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon May 14 12:20:12 2018
@@ -3044,6 +3044,39 @@ LangAS CodeGenModule::GetGlobalVarAddres
   return getTargetCodeGenInfo().getGlobalVarAddressSpace(*this, D);
 }
 
+LangAS CodeGenModule::getStringLiteralAddressSpace() const {
+  // OpenCL v1.2 s6.5.3: a string literal is in the constant address space.
+  if (LangOpts.OpenCL)
+return LangAS::opencl_constant;
+  if (auto AS = getTarget().getConstantAddressSpace())
+return AS.getValue();
+  return LangAS::Default;
+}
+
+// In address space agnostic languages, string literals are in default address
+// space in AST. However, certain targets (e.g. amdgcn) request them to be
+// emitted in constant address space in LLVM IR. To be consistent with other
+// parts of AST, string literal global variables in constant address space
+// need to be casted to default address space before being put into address
+// map and referenced by other part of CodeGen.
+// In OpenCL, string literals are in constant address space in AST, therefore
+// they should not be casted to default address space.
+static llvm::Constant *
+castStringLiteralToDefaultAddressSpace(CodeGenModule ,
+   llvm::GlobalVariable *GV) {
+  llvm::Constant *Cast = GV;
+  if (!CGM.getLangOpts().OpenCL) {
+if (auto AS = CGM.getTarget().getConstantAddressSpace()) {
+  if (AS != LangAS::Default)
+Cast = CGM.getTargetCodeGenInfo().performAddrSpaceCast(
+CGM, GV, AS.getValue(), LangAS::Default,
+GV->getValueType()->getPointerTo(
+CGM.getContext().getTargetAddressSpace(LangAS::Default)));
+}
+  }
+  return Cast;
+}
+
 template
 void CodeGenModule::MaybeHandleStaticInExternC(const SomeDecl *D,
llvm::GlobalValue *GV) {
@@ -4039,10 +4072,8 @@ static llvm::GlobalVariable *
 GenerateStringLiteral(llvm::Constant *C, llvm::GlobalValue::LinkageTypes LT,
   CodeGenModule , StringRef GlobalName,
   CharUnits Alignment) {
-  // OpenCL v1.2 s6.5.3: a string literal is in the constant address space.
-  unsigned AddrSpace = 0;
-  if (CGM.getLangOpts().OpenCL)
-AddrSpace = 
CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
+  unsigned AddrSpace = CGM.getContext().getTargetAddressSpace(
+  CGM.getStringLiteralAddressSpace());
 
   llvm::Module  = CGM.getModule();
   // Create a global variable for this string
@@ -4104,7 +4135,9 @@ CodeGenModule::GetAddrOfConstantStringFr
 
   SanitizerMD->reportGlobalToASan(GV, S->getStrTokenLoc(0), "",

[clang-tools-extra] r332277 - [Documentation] Alphabetical order of new checks in Release Notes.

2018-05-14 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Mon May 14 12:12:40 2018
New Revision: 332277

URL: http://llvm.org/viewvc/llvm-project?rev=332277=rev
Log:
[Documentation] Alphabetical order of new checks in Release Notes.

Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=332277=332276=332277=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Mon May 14 12:12:40 2018
@@ -76,6 +76,11 @@ Improvements to clang-tidy
   Detects and fixes calls to grand-...parent virtual methods instead of calls
   to overridden parent's virtual methods.
 
+- New :doc:`bugprone-terminating-continue
+  ` check
+
+  Checks if a ``continue`` statement terminates the loop.
+
 - New :doc:`bugprone-throw-keyword-missing
   ` check.
 
@@ -146,11 +151,6 @@ Improvements to clang-tidy
   Warns or suggests alternatives if SIMD intrinsics are used which can be 
replaced by
   ``std::experimental::simd`` operations.
 
-- New :doc:`bugprone-terminating-continue
-  ` check
-
-  Checks if a ``continue`` statement terminates the loop.
-
 - New :doc:`zircon-temporary-objects
   ` check.
 


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


[PATCH] D46112: Allow _Atomic to be specified on incomplete types

2018-05-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D46112#1096893, @aaron.ballman wrote:

> In https://reviews.llvm.org/D46112#1091981, @efriedma wrote:
>
> > Also needs some test coverage for atomic operations which aren't calls, 
> > like "typedef struct S S; void f(_Atomic S *s, _Atomic S *s2) { *s = *s2; 
> > };".
>
>
> Thank you for pointing this out -- that uncovered an issue where we were not 
> properly diagnosing the types as being incomplete. I've added a new test case 
> and rolled the contents of Sema\atomic-type.cpp (which I added in an earlier 
> patch) into SemaCXX\atomic-type.cpp (which already existed and I missed it).


I don't think this has sufficiently addressed the comment. Specifically, for a 
case like:

  struct NotTriviallyCopyable { NotTriviallyCopyable(const 
NotTriviallyCopyable&); };
  void f(_Atomic NotTriviallyCopyable *p) { *p = *p; }

... we should reject the assignment, because it would perform an atomic 
operation on a non-trivially-copyable type. It would probably suffice to check 
the places where we form an `AtomicToNonAtomic` or `NonAtomicToAtomic` 
conversion.

In passing, I noticed that this crashes Clang (because we fail to create an 
lvalue-to-rvalue conversion for `x`):

  struct X {};  
  void f(_Atomic X *p, X x) { *p = x; }

This will likely get in the way of your test cases unless you fix it :)




Comment at: lib/Sema/SemaChecking.cpp:3202
 
-  if (!IsC11 && !AtomTy.isTriviallyCopyableType(Context) &&
-  !AtomTy->isScalarType()) {
-// For GNU atomics, require a trivially-copyable type. This is not part of
-// the GNU atomics specification, but we enforce it for sanity.
+  if (!ValType.isTriviallyCopyableType(Context) && !ValType->isScalarType()) {
+// Always require a trivially-copyable type. This is not part of the GNU

The (pre-existing) `isScalarType()` check here looks wrong to me. If we had a 
non-trivially-copyable scalar type (which I think do not currently exist in our 
type system), I think we should reject it here.



Comment at: lib/Sema/SemaType.cpp:7662
   // try to instantiate it.
-  QualType MaybeTemplate = T;
-  while (const ConstantArrayType *Array
-   = Context.getAsConstantArrayType(MaybeTemplate))
-MaybeTemplate = Array->getElementType();
-  if (const RecordType *Record = MaybeTemplate->getAs()) {
+  if (auto *RD = dyn_cast_or_null(Def)) {
 bool Instantiated = false;

May as well cast directly to `CXXRecordDecl` here; none of the code controlled 
by this `if` does anything in C.


https://reviews.llvm.org/D46112



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


[PATCH] D45093: [AST] Fix -ast-print for _Bool when have diagnostics

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332275: [AST] Fix -ast-print for _Bool when have diagnostics 
(authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45093?vs=145711=146650#toc

Repository:
  rC Clang

https://reviews.llvm.org/D45093

Files:
  include/clang/Sema/Sema.h
  lib/Frontend/ASTConsumers.cpp
  lib/Sema/Sema.cpp
  test/Misc/ast-print-bool.c

Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -2113,12 +2113,12 @@
   void checkPartialSpecializationVisibility(SourceLocation Loc,
 NamedDecl *Spec);
 
-  /// Retrieve a suitable printing policy.
+  /// Retrieve a suitable printing policy for diagnostics.
   PrintingPolicy getPrintingPolicy() const {
 return getPrintingPolicy(Context, PP);
   }
 
-  /// Retrieve a suitable printing policy.
+  /// Retrieve a suitable printing policy for diagnostics.
   static PrintingPolicy getPrintingPolicy(const ASTContext ,
   const Preprocessor );
 
Index: test/Misc/ast-print-bool.c
===
--- test/Misc/ast-print-bool.c
+++ test/Misc/ast-print-bool.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_CBOOL \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-CBOOL,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_CBOOL -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-CBOOL,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_INT \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-INT,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_INT -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-INT,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc++ \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-BOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc++ -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-BOOL
+
+#if DEF_BOOL_CBOOL
+# define bool _Bool
+#elif DEF_BOOL_INT
+# define bool int
+#endif
+
+// BOOL-AS-CBOOL: _Bool i;
+// BOOL-AS-INT:   int i;
+// BOOL-AS-BOOL:  bool i;
+bool i;
+
+#ifndef __cplusplus
+// CBOOL: _Bool j;
+_Bool j;
+#endif
+
+// Induce a diagnostic (and verify we actually managed to do so), which used to
+// permanently alter the -ast-print printing policy for _Bool.  How bool is
+// defined by the preprocessor is examined only once per compilation, when the
+// diagnostic is emitted, and it used to affect the entirety of -ast-print, so
+// test only one definition of bool per compilation.
+#if DIAG
+void fn() { 1; } // expected-warning {{expression result unused}}
+#else
+// expected-no-diagnostics
+#endif
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -52,8 +52,8 @@
 PrintingPolicy Sema::getPrintingPolicy(const ASTContext ,
const Preprocessor ) {
   PrintingPolicy Policy = Context.getPrintingPolicy();
-  // Our printing policy is copied over the ASTContext printing policy whenever
-  // a diagnostic is emitted, so recompute it.
+  // In diagnostics, we print _Bool as bool if the latter is defined as the
+  // former.
   Policy.Bool = Context.getLangOpts().Bool;
   if (!Policy.Bool) {
 if (const MacroInfo *BoolMacro = PP.getMacroInfo(Context.getBoolName())) {
@@ -1287,7 +1287,8 @@
 }
   }
 
-  // Set up the context's printing policy based on our current state.
+  // Copy the diagnostic printing policy over the ASTContext printing policy.
+  // TODO: Stop doing that.  See: https://reviews.llvm.org/D45093#1090292
   Context.setPrintingPolicy(getPrintingPolicy());
 
   // Emit the diagnostic.
Index: lib/Frontend/ASTConsumers.cpp
===
--- lib/Frontend/ASTConsumers.cpp
+++ lib/Frontend/ASTConsumers.cpp
@@ -87,9 +87,10 @@
 << DC->getPrimaryContext() << "\n";
 } else
   Out << "Not a DeclContext\n";
-  } else if (OutputKind == Print)
-D->print(Out, /*Indentation=*/0, /*PrintInstantiation=*/true);
-  else if (OutputKind != None)
+  } else if (OutputKind == Print) {
+PrintingPolicy Policy(D->getASTContext().getLangOpts());
+D->print(Out, Policy, /*Indentation=*/0, /*PrintInstantiation=*/true);
+  } else if (OutputKind != None)
 D->dump(Out, OutputKind == DumpFull);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46643: CodeGen: Emit string literal in constant address space

2018-05-14 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM.


https://reviews.llvm.org/D46643



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


r332275 - [AST] Fix -ast-print for _Bool when have diagnostics

2018-05-14 Thread Joel E. Denny via cfe-commits
Author: jdenny
Date: Mon May 14 11:41:44 2018
New Revision: 332275

URL: http://llvm.org/viewvc/llvm-project?rev=332275=rev
Log:
[AST] Fix -ast-print for _Bool when have diagnostics

For example, given:

  #define bool _Bool
  _Bool i;
  void fn() { 1; }

-ast-print produced:

  tmp.c:3:13: warning: expression result unused
  void fn() { 1; }
  ^
  bool i;
  void fn() {
  1;
  }

That fails to compile because bool is undefined.

Details:

Diagnostics print _Bool as bool when the latter is defined as the
former.  However, diagnostics were altering the printing policy for
-ast-print as well.  The printed source was then invalid because the
preprocessor eats the bool definition.

Problematic diagnostics included suppressed warnings (e.g., add
-Wno-unused-value to the above example), including those that are
suppressed by default.

This patch fixes this bug and cleans up some related comments.

Reviewed by: aaron.ballman, rsmith

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

Added:
cfe/trunk/test/Misc/ast-print-bool.c
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/lib/Sema/Sema.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=332275=332274=332275=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon May 14 11:41:44 2018
@@ -2113,12 +2113,12 @@ public:
   void checkPartialSpecializationVisibility(SourceLocation Loc,
 NamedDecl *Spec);
 
-  /// Retrieve a suitable printing policy.
+  /// Retrieve a suitable printing policy for diagnostics.
   PrintingPolicy getPrintingPolicy() const {
 return getPrintingPolicy(Context, PP);
   }
 
-  /// Retrieve a suitable printing policy.
+  /// Retrieve a suitable printing policy for diagnostics.
   static PrintingPolicy getPrintingPolicy(const ASTContext ,
   const Preprocessor );
 

Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=332275=332274=332275=diff
==
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Mon May 14 11:41:44 2018
@@ -87,9 +87,10 @@ namespace {
 << DC->getPrimaryContext() << "\n";
 } else
   Out << "Not a DeclContext\n";
-  } else if (OutputKind == Print)
-D->print(Out, /*Indentation=*/0, /*PrintInstantiation=*/true);
-  else if (OutputKind != None)
+  } else if (OutputKind == Print) {
+PrintingPolicy Policy(D->getASTContext().getLangOpts());
+D->print(Out, Policy, /*Indentation=*/0, /*PrintInstantiation=*/true);
+  } else if (OutputKind != None)
 D->dump(Out, OutputKind == DumpFull);
 }
 

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=332275=332274=332275=diff
==
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Mon May 14 11:41:44 2018
@@ -52,8 +52,8 @@ ModuleLoader ::getModuleLoader() co
 PrintingPolicy Sema::getPrintingPolicy(const ASTContext ,
const Preprocessor ) {
   PrintingPolicy Policy = Context.getPrintingPolicy();
-  // Our printing policy is copied over the ASTContext printing policy whenever
-  // a diagnostic is emitted, so recompute it.
+  // In diagnostics, we print _Bool as bool if the latter is defined as the
+  // former.
   Policy.Bool = Context.getLangOpts().Bool;
   if (!Policy.Bool) {
 if (const MacroInfo *BoolMacro = PP.getMacroInfo(Context.getBoolName())) {
@@ -1287,7 +1287,8 @@ void Sema::EmitCurrentDiagnostic(unsigne
 }
   }
 
-  // Set up the context's printing policy based on our current state.
+  // Copy the diagnostic printing policy over the ASTContext printing policy.
+  // TODO: Stop doing that.  See: https://reviews.llvm.org/D45093#1090292
   Context.setPrintingPolicy(getPrintingPolicy());
 
   // Emit the diagnostic.

Added: cfe/trunk/test/Misc/ast-print-bool.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-print-bool.c?rev=332275=auto
==
--- cfe/trunk/test/Misc/ast-print-bool.c (added)
+++ cfe/trunk/test/Misc/ast-print-bool.c Mon May 14 11:41:44 2018
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_CBOOL \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-CBOOL,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_CBOOL -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-CBOOL,CBOOL
+//
+// RUN: 

[PATCH] D40218: [Clang] Add __builtin_launder

2018-05-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM with a fix (and test) for pointer-to-array-of-dynamic-class-type handling.




Comment at: lib/CodeGen/CGBuiltin.cpp:936-938
+  const auto *Record = Ty->getAsCXXRecordDecl();
+  if (!Record || !Seen.insert(Record).second)
+return false;

I think you also need to recurse through array types (use 
`Ty->getBaseElementTypeUnsafe()->getAsCXXRecordDecl()` or similar).


https://reviews.llvm.org/D40218



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


[PATCH] D46694: [diagtool] Install diagtool

2018-05-14 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Sgtm. I think it would be worthwhile to release-note this.


Repository:
  rC Clang

https://reviews.llvm.org/D46694



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


[PATCH] D46643: CodeGen: Emit string literal in constant address space

2018-05-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 146647.
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

Revised by John's comments.


https://reviews.llvm.org/D46643

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/amdgcn-string-literal.cpp

Index: test/CodeGenCXX/amdgcn-string-literal.cpp
===
--- /dev/null
+++ test/CodeGenCXX/amdgcn-string-literal.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: @.str = private unnamed_addr addrspace(4) constant [6 x i8] c"g_str\00", align 1
+// CHECK: @g_str = addrspace(1) global i8* addrspacecast (i8 addrspace(4)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(4)* @.str, i32 0, i32 0) to i8*), align 8
+// CHECK: @g_array = addrspace(1) global [8 x i8] c"g_array\00", align 1
+// CHECK: @.str.1 = private unnamed_addr addrspace(4) constant [6 x i8] c"l_str\00", align 1
+// CHECK: @_ZZ1fvE7l_array = private unnamed_addr addrspace(4) constant [8 x i8] c"l_array\00", align 1
+
+const char* g_str = "g_str";
+char g_array[] = "g_array";
+
+void g(const char* p);
+
+// CHECK-LABEL: define void @_Z1fv()
+void f() {
+  const char* l_str = "l_str";
+  
+  // CHECK: call void @llvm.memcpy.p0i8.p4i8.i64
+  char l_array[] = "l_array";
+
+  g(g_str);
+  g(g_array);
+  g(l_str);
+  g(l_array);
+
+  const char* p = g_str;
+  g(p);
+}
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -785,6 +785,13 @@
  ForDefinition_t IsForDefinition
= NotForDefinition);
 
+  /// Return the AST address space of string literal, which is used to emit
+  /// the string literal as global variable in LLVM IR.
+  /// Note: This is not necessarily the address space of the string literal
+  /// in AST. For address space agnostic language, e.g. C++, string literal
+  /// in AST is always in default address space.
+  LangAS getStringLiteralAddressSpace() const;
+
   /// Return the address of the given function. If Ty is non-null, then this
   /// function will use the specified type if it has to create it.
   llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -3044,6 +3044,39 @@
   return getTargetCodeGenInfo().getGlobalVarAddressSpace(*this, D);
 }
 
+LangAS CodeGenModule::getStringLiteralAddressSpace() const {
+  // OpenCL v1.2 s6.5.3: a string literal is in the constant address space.
+  if (LangOpts.OpenCL)
+return LangAS::opencl_constant;
+  if (auto AS = getTarget().getConstantAddressSpace())
+return AS.getValue();
+  return LangAS::Default;
+}
+
+// In address space agnostic languages, string literals are in default address
+// space in AST. However, certain targets (e.g. amdgcn) request them to be
+// emitted in constant address space in LLVM IR. To be consistent with other
+// parts of AST, string literal global variables in constant address space
+// need to be casted to default address space before being put into address
+// map and referenced by other part of CodeGen.
+// In OpenCL, string literals are in constant address space in AST, therefore
+// they should not be casted to default address space.
+static llvm::Constant *
+castStringLiteralToDefaultAddressSpace(CodeGenModule ,
+   llvm::GlobalVariable *GV) {
+  llvm::Constant *Cast = GV;
+  if (!CGM.getLangOpts().OpenCL) {
+if (auto AS = CGM.getTarget().getConstantAddressSpace()) {
+  if (AS != LangAS::Default)
+Cast = CGM.getTargetCodeGenInfo().performAddrSpaceCast(
+CGM, GV, AS.getValue(), LangAS::Default,
+GV->getValueType()->getPointerTo(
+CGM.getContext().getTargetAddressSpace(LangAS::Default)));
+}
+  }
+  return Cast;
+}
+
 template
 void CodeGenModule::MaybeHandleStaticInExternC(const SomeDecl *D,
llvm::GlobalValue *GV) {
@@ -4039,10 +4072,8 @@
 GenerateStringLiteral(llvm::Constant *C, llvm::GlobalValue::LinkageTypes LT,
   CodeGenModule , StringRef GlobalName,
   CharUnits Alignment) {
-  // OpenCL v1.2 s6.5.3: a string literal is in the constant address space.
-  unsigned AddrSpace = 0;
-  if (CGM.getLangOpts().OpenCL)
-AddrSpace = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
+  unsigned AddrSpace = CGM.getContext().getTargetAddressSpace(
+  CGM.getStringLiteralAddressSpace());
 
   llvm::Module  = CGM.getModule();
   // Create a global variable for this string
@@ -4104,7 +4135,9 @@
 
   SanitizerMD->reportGlobalToASan(GV, 

[PATCH] D46767: Force the PS4 clang ABI version to 6, and add a warning if this is attempted to be overridden

2018-05-14 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

In https://reviews.llvm.org/D46767#1096746, @rsmith wrote:

> Everything old is new again.


If only that were true about my brain. :-P

> This was discussed when `-fclang-abi-compat` was introduced; see 
> https://reviews.llvm.org/D36501 for the argument why this patch is the wrong 
> way of modeling an ABI. Forcing the `ClangABICompat` language option as a way 
> of "tricking" Clang into producing the PS4 ABI is a hack. The various ABI 
> changes that `-fclang-abi-compat=` controls are simply part of the PS4 ABI, 
> and that knowledge should idealistically be carried by the CodeGen (etc) code 
> that knows about PS4, rather than by imagining that there is some other PS4 
> ABI that Clang would produces at version `Latest`, and that we're asking for 
> a compatibility version of it.

Muchas gracias for the reminder of the previous discussion; it's quite true 
that on our side we have not done our due diligence in making sure that 
upstream Clang fully supports the PS4 ABI, and that `-fclang-abi-compat` is the 
wrong way to do this.  It needs to become part of my team's consciousness and 
collective memory that these sorts of expedient hacks are the wrong approach.

> This will go wrong if we ever release (or have ever released) a Clang version 
> that fails to properly implement the PS4 ABI.

Yeah, we crossed that bridge years ago, but nobody has been brave enough to try 
to deliver that patch upstream.  Actually I think there are two, but as they 
typically don't cause any merge conflicts they're not at top-of-mind for 
anybody, even me.

> However, we should not issue a warning for use of the flag. Remember that the 
> flag means "please be ABI-compatible with Clang version X.Y". Because all 
> versions of Clang that target PS4 use the same ABI, the flag is a no-op on 
> that target (at least for now, until we accidentally introduce an ABI break). 
> So we should not be warning on it, just silently accepting it and doing what 
> it says -- which for now is nothing.

Got it.  I'll take an action to straighten this one out.


Repository:
  rC Clang

https://reviews.llvm.org/D46767



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


[PATCH] D46602: [clang-tidy] Store checks profiling info as YAML files

2018-05-14 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a project: clang-tools-extra.
lebedev.ri added a comment.

In https://reviews.llvm.org/D46602#1098092, @alexfh wrote:

> In https://reviews.llvm.org/D46602#1097954, @lebedev.ri wrote:
>
> > How do i reflect that in tests? The output name will basically be random.
>
>
> Why random?


I was obviously talking about the FileCheck stuff, how to specify such a 
dynamic filename there..


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46602



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


[PATCH] D46742: [X86] Use __builtin_convertvector to replace some of the avx512 truncate builtins.

2018-05-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332266: [X86] Use __builtin_convertvector to replace some of 
the avx512 truncate… (authored by ctopper, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46742?vs=146286=146645#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46742

Files:
  include/clang/Basic/BuiltinsX86.def
  lib/Headers/avx512bwintrin.h
  lib/Headers/avx512fintrin.h
  lib/Headers/avx512vlbwintrin.h
  lib/Headers/avx512vlintrin.h
  test/CodeGen/avx512bw-builtins.c
  test/CodeGen/avx512f-builtins.c
  test/CodeGen/avx512vl-builtins.c
  test/CodeGen/avx512vlbw-builtins.c

Index: include/clang/Basic/BuiltinsX86.def
===
--- include/clang/Basic/BuiltinsX86.def
+++ include/clang/Basic/BuiltinsX86.def
@@ -1355,7 +1355,6 @@
 
 TARGET_BUILTIN(__builtin_ia32_pmovswb512_mask, "V32cV32sV32cUi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_pmovuswb512_mask, "V32cV32sV32cUi", "nc", "avx512bw")
-TARGET_BUILTIN(__builtin_ia32_pmovwb512_mask, "V32cV32sV32cUi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2qq128_mask, "V2LLiV2dV2LLiUc", "nc", "avx512vl,avx512dq")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2qq256_mask, "V4LLiV4dV4LLiUc", "nc", "avx512vl,avx512dq")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2uqq128_mask, "V2LLiV2dV2LLiUc", "nc", "avx512vl,avx512dq")
@@ -1397,7 +1396,6 @@
 TARGET_BUILTIN(__builtin_ia32_pmovuswb128_mask, "V16cV8sV16cUc", "nc", "avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_pmovuswb256_mask, "V16cV16sV16cUs", "nc", "avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_pmovwb128_mask, "V16cV8sV16cUc", "nc", "avx512vl,avx512bw")
-TARGET_BUILTIN(__builtin_ia32_pmovwb256_mask, "V16cV16sV16cUs", "nc", "avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2qq512_mask, "V8LLiV8dV8LLiUcIi", "nc", "avx512dq")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2uqq512_mask, "V8LLiV8dV8LLiUcIi", "nc", "avx512dq")
 TARGET_BUILTIN(__builtin_ia32_cvtps2qq512_mask, "V8LLiV8fV8LLiUcIi", "nc", "avx512dq")
@@ -1719,16 +1717,12 @@
 TARGET_BUILTIN(__builtin_ia32_pmovusqw128mem_mask, "vV8s*V2LLiUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusqw256_mask, "V8sV4LLiV8sUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusqw256mem_mask, "vV8s*V4LLiUc", "n", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_pmovdb512_mask, "V16cV16iV16cUs", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovdb512mem_mask, "vV16c*V16iUs", "n", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovwb512mem_mask, "vV32c*V32sUi", "n", "avx512bw")
-TARGET_BUILTIN(__builtin_ia32_pmovdw512_mask, "V16sV16iV16sUs", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovdw512mem_mask, "vV16s*V16iUs", "n", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqb512_mask, "V16cV8LLiV16cUc", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqb512mem_mask, "vV16c*V8LLiUc", "n", "avx512f")
-TARGET_BUILTIN(__builtin_ia32_pmovqd512_mask, "V8iV8LLiV8iUc", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqd512mem_mask, "vV8i*V8LLiUc", "n", "avx512f")
-TARGET_BUILTIN(__builtin_ia32_pmovqw512_mask, "V8sV8LLiV8sUc", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqw512mem_mask, "vV8s*V8LLiUc", "n", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovdb128_mask, "V16cV4iV16cUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovwb128mem_mask, "vV16c*V8sUc", "n", "avx512vl,avx512bw")
@@ -1738,15 +1732,13 @@
 TARGET_BUILTIN(__builtin_ia32_pmovwb256mem_mask, "vV16c*V16sUs", "n", "avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_pmovdw128_mask, "V8sV4iV8sUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovdw128mem_mask, "vV8s*V4iUc", "n", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_pmovdw256_mask, "V8sV8iV8sUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovdw256mem_mask, "vV8s*V8iUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqb128_mask, "V16cV2LLiV16cUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqb128mem_mask, "vV16c*V2LLiUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqb256_mask, "V16cV4LLiV16cUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqb256mem_mask, "vV16c*V4LLiUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqd128_mask, "V4iV2LLiV4iUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqd128mem_mask, "vV4i*V2LLiUc", "n", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_pmovqd256_mask, "V4iV4LLiV4iUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqd256mem_mask, "vV4i*V4LLiUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqw128_mask, "V8sV2LLiV8sUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqw128mem_mask, "vV8s*V2LLiUc", "n", "avx512vl")
Index: test/CodeGen/avx512bw-builtins.c
===
--- test/CodeGen/avx512bw-builtins.c
+++ test/CodeGen/avx512bw-builtins.c
@@ -1107,19 +1107,21 @@
 
 __m256i test_mm512_cvtepi16_epi8(__m512i __A) {
   // CHECK-LABEL: 

r332266 - [X86] Use __builtin_convertvector to replace some of the avx512 truncate builtins.

2018-05-14 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Mon May 14 10:50:40 2018
New Revision: 332266

URL: http://llvm.org/viewvc/llvm-project?rev=332266=rev
Log:
[X86] Use __builtin_convertvector to replace some of the avx512 truncate 
builtins.

As long as the destination type is a 256 or 128 bit vector with the same number 
of elements we can use __builtin_convertvector to directly generate trunc IR 
instruction which will be handled natively by the backend.

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx512bwintrin.h
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/lib/Headers/avx512vlbwintrin.h
cfe/trunk/lib/Headers/avx512vlintrin.h
cfe/trunk/test/CodeGen/avx512bw-builtins.c
cfe/trunk/test/CodeGen/avx512f-builtins.c
cfe/trunk/test/CodeGen/avx512vl-builtins.c
cfe/trunk/test/CodeGen/avx512vlbw-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=332266=332265=332266=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Mon May 14 10:50:40 2018
@@ -1355,7 +1355,6 @@ TARGET_BUILTIN(__builtin_ia32_vpshrdw512
 
 TARGET_BUILTIN(__builtin_ia32_pmovswb512_mask, "V32cV32sV32cUi", "nc", 
"avx512bw")
 TARGET_BUILTIN(__builtin_ia32_pmovuswb512_mask, "V32cV32sV32cUi", "nc", 
"avx512bw")
-TARGET_BUILTIN(__builtin_ia32_pmovwb512_mask, "V32cV32sV32cUi", "nc", 
"avx512bw")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2qq128_mask, "V2LLiV2dV2LLiUc", "nc", 
"avx512vl,avx512dq")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2qq256_mask, "V4LLiV4dV4LLiUc", "nc", 
"avx512vl,avx512dq")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2uqq128_mask, "V2LLiV2dV2LLiUc", "nc", 
"avx512vl,avx512dq")
@@ -1397,7 +1396,6 @@ TARGET_BUILTIN(__builtin_ia32_pmovswb256
 TARGET_BUILTIN(__builtin_ia32_pmovuswb128_mask, "V16cV8sV16cUc", "nc", 
"avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_pmovuswb256_mask, "V16cV16sV16cUs", "nc", 
"avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_pmovwb128_mask, "V16cV8sV16cUc", "nc", 
"avx512vl,avx512bw")
-TARGET_BUILTIN(__builtin_ia32_pmovwb256_mask, "V16cV16sV16cUs", "nc", 
"avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2qq512_mask, "V8LLiV8dV8LLiUcIi", "nc", 
"avx512dq")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2uqq512_mask, "V8LLiV8dV8LLiUcIi", "nc", 
"avx512dq")
 TARGET_BUILTIN(__builtin_ia32_cvtps2qq512_mask, "V8LLiV8fV8LLiUcIi", "nc", 
"avx512dq")
@@ -1719,16 +1717,12 @@ TARGET_BUILTIN(__builtin_ia32_pmovusqw12
 TARGET_BUILTIN(__builtin_ia32_pmovusqw128mem_mask, "vV8s*V2LLiUc", "n", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusqw256_mask, "V8sV4LLiV8sUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusqw256mem_mask, "vV8s*V4LLiUc", "n", 
"avx512vl")
-TARGET_BUILTIN(__builtin_ia32_pmovdb512_mask, "V16cV16iV16cUs", "nc", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovdb512mem_mask, "vV16c*V16iUs", "n", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovwb512mem_mask, "vV32c*V32sUi", "n", 
"avx512bw")
-TARGET_BUILTIN(__builtin_ia32_pmovdw512_mask, "V16sV16iV16sUs", "nc", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovdw512mem_mask, "vV16s*V16iUs", "n", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqb512_mask, "V16cV8LLiV16cUc", "nc", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqb512mem_mask, "vV16c*V8LLiUc", "n", 
"avx512f")
-TARGET_BUILTIN(__builtin_ia32_pmovqd512_mask, "V8iV8LLiV8iUc", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqd512mem_mask, "vV8i*V8LLiUc", "n", 
"avx512f")
-TARGET_BUILTIN(__builtin_ia32_pmovqw512_mask, "V8sV8LLiV8sUc", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqw512mem_mask, "vV8s*V8LLiUc", "n", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovdb128_mask, "V16cV4iV16cUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovwb128mem_mask, "vV16c*V8sUc", "n", 
"avx512vl,avx512bw")
@@ -1738,7 +1732,6 @@ TARGET_BUILTIN(__builtin_ia32_pmovdb256m
 TARGET_BUILTIN(__builtin_ia32_pmovwb256mem_mask, "vV16c*V16sUs", "n", 
"avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_pmovdw128_mask, "V8sV4iV8sUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovdw128mem_mask, "vV8s*V4iUc", "n", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_pmovdw256_mask, "V8sV8iV8sUc", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovdw256mem_mask, "vV8s*V8iUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqb128_mask, "V16cV2LLiV16cUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqb128mem_mask, "vV16c*V2LLiUc", "n", 
"avx512vl")
@@ -1746,7 +1739,6 @@ TARGET_BUILTIN(__builtin_ia32_pmovqb256_
 TARGET_BUILTIN(__builtin_ia32_pmovqb256mem_mask, "vV16c*V4LLiUc", "n", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqd128_mask, "V4iV2LLiV4iUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqd128mem_mask, "vV4i*V2LLiUc", "n", 
"avx512vl")

[PATCH] D46602: [clang-tidy] Store checks profiling info as YAML files

2018-05-14 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 146644.
lebedev.ri edited the summary of this revision.
lebedev.ri added subscribers: aaron.ballman, JonasToth.
lebedev.ri added a comment.

- Get rid of 'prefix elision'
- Don't use full source file name, only the filename
- Prefix that filename with ISO8601-like timestamp of the profile creation.

I think this is worse than before, horrible and ugly, but hey, i'm not the code 
owner.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46602

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidy.h
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tidy/ClangTidyProfiling.cpp
  clang-tidy/ClangTidyProfiling.h
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/clang-tidy-enable-check-profile-one-tu.cpp
  test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp
  test/clang-tidy/clang-tidy-store-check-profile-one-tu.cpp

Index: test/clang-tidy/clang-tidy-store-check-profile-one-tu.cpp
===
--- /dev/null
+++ test/clang-tidy/clang-tidy-store-check-profile-one-tu.cpp
@@ -0,0 +1,35 @@
+// RUN: rm -rf %T/out
+// RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' -store-check-profile=%T/out %s 2>&1 | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-CONSOLE %s
+// RUN: cat %T/out/*-clang-tidy-store-check-profile-one-tu.cpp.yaml | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-FILE %s
+// RUN: rm -rf %T/out
+// RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' -store-check-profile=%T/out %s 2>&1 | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-CONSOLE %s
+// RUN: cat %T/out/*-clang-tidy-store-check-profile-one-tu.cpp.yaml | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-FILE %s
+
+// CHECK-CONSOLE-NOT: ===-===
+// CHECK-CONSOLE-NOT: {{.*}}  --- Name ---
+// CHECK-CONSOLE-NOT: {{.*}}  readability-function-size
+// CHECK-CONSOLE-NOT: {{.*}}  Total
+// CHECK-CONSOLE-NOT: ===-===
+
+// CHECK-FILE: {
+// CHECK-FILE-NEXT:"file": "{{.*}}clang-tidy-store-check-profile-one-tu.cpp",
+// CHECK-FILE-NEXT:"profile": {
+// CHECK-FILE-NEXT:	"time.clang-tidy.readability-function-size.wall": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
+// CHECK-FILE-NEXT:	"time.clang-tidy.readability-function-size.user": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
+// CHECK-FILE-NEXT:	"time.clang-tidy.readability-function-size.sys": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}}
+// CHECK-FILE-NEXT: }
+// CHECK-FILE-NEXT: }
+
+// CHECK-FILE-NOT: {
+// CHECK-FILE-NOT: "file": {{.*}}clang-tidy-store-check-profile-one-tu.cpp{{.*}},
+// CHECK-FILE-NOT: "profile": {
+// CHECK-FILE-NOT:	"time.clang-tidy.readability-function-size.wall": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
+// CHECK-FILE-NOT:	"time.clang-tidy.readability-function-size.user": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
+// CHECK-FILE-NOT:	"time.clang-tidy.readability-function-size.sys": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}}
+// CHECK-FILE-NOT: }
+// CHECK-FILE-NOT: }
+
+class A {
+  A() {}
+  ~A() {}
+};
Index: test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp
===
--- test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp
+++ test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp
@@ -1,22 +1,31 @@
 // RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' %s %s 2>&1 | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' %s
 
 // CHECK: ===-===
-// CHECK-NEXT: {{.*}}  --- Name ---
+// CHECK-NEXT:  clang-tidy checks profiling
+// CHECK-NEXT: ===-===
+// CHECK-NEXT: Total Execution Time: {{.*}} seconds ({{.*}} wall clock)
+
+// CHECK: {{.*}}  --- Name ---
 // CHECK-NEXT: {{.*}}  readability-function-size
 // CHECK-NEXT: {{.*}}  Total
-// CHECK-NEXT: ===-===
 
 // CHECK: ===-===
-// CHECK-NEXT: {{.*}}  --- Name ---
+// CHECK-NEXT:  clang-tidy checks profiling
+// CHECK-NEXT: ===-===
+// CHECK-NEXT: Total Execution Time: {{.*}} seconds ({{.*}} wall clock)
+
+// CHECK: {{.*}}  --- Name ---
 // CHECK-NEXT: {{.*}}  

[PATCH] D43576: Solution to fix PR27066 - Redefinition with same mangled name as another definition (dllexport and uuid)

2018-05-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 146642.

https://reviews.llvm.org/D43576

Files:
  include/clang/AST/Decl.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DeclNodes.td
  include/clang/Sema/AttributeList.h
  include/clang/Sema/Sema.h
  lib/AST/Decl.cpp
  lib/AST/DeclBase.cpp
  lib/AST/DeclCXX.cpp
  lib/CodeGen/CGDecl.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTCommon.cpp
  test/SemaCXX/ms-uuid-1.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -322,12 +322,15 @@
 OS << "\" << get" << getUpperName() << "().getAsString() << \"";
   else if (type == "ParamIdx")
 OS << "\" << get" << getUpperName() << "().getSourceIndex() << \"";
-  else
+  else if (type == "DeclSpecUuidDecl *") {
+OS << "\" << get" << getUpperName() << "() << \"";
+	} else
 OS << "\" << get" << getUpperName() << "() << \"";
 }
 
 void writeDump(raw_ostream ) const override {
-  if (type == "FunctionDecl *" || type == "NamedDecl *") {
+  if (type == "FunctionDecl *" || type == "NamedDecl *" ||
+	  (type == "DeclSpecUuidDecl *")) {
 OS << "OS << \" \";\n";
 OS << "dumpBareDeclRef(SA->get" << getUpperName() << "());\n"; 
   } else if (type == "IdentifierInfo *") {
@@ -1280,6 +1283,8 @@
 Ptr = llvm::make_unique(Arg, Attr, "ParamIdx");
   else if (ArgName == "VersionArgument")
 Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "DeclSpecUuidDeclArgument")
+Ptr = llvm::make_unique(Arg, Attr, "DeclSpecUuidDecl *");
 
   if (!Ptr) {
 // Search in reverse order so that the most-derived type is handled first.
Index: test/SemaCXX/ms-uuid-1.cpp
===
--- /dev/null
+++ test/SemaCXX/ms-uuid-1.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fms-extensions -fms-compatibility -std=c++14 -emit-obj -fdiagnostics-show-option %s
+// expected-no-diagnostics
+typedef struct _GUID {
+  int i;
+} IID;
+template 
+class A {};
+
+struct
+__declspec(uuid("{DDB47A6A-0F23-11D5-9109-00E0296B75D3}"))
+S1 {};
+
+struct
+__declspec(uuid("{DDB47A6A-0F23-11D5-9109-00E0296B75D3}"))
+S2 {};
+
+struct __declspec(dllexport)
+C1 : public A<&__uuidof(S1)> {};
+
+struct __declspec(dllexport)
+C2 : public A<&__uuidof(S2)> {};
+int printf(const char *, ...);
+int main() {
+
+  if (&__uuidof(S1) == &__uuidof(S2))
+printf("OK\n");
+  else
+printf("ERROR\n");
+
+  return 0;
+}
Index: lib/Serialization/ASTCommon.cpp
===
--- lib/Serialization/ASTCommon.cpp
+++ lib/Serialization/ASTCommon.cpp
@@ -272,6 +272,7 @@
   case Decl::ObjCProtocol:
   case Decl::ObjCInterface:
   case Decl::Empty:
+  case Decl::DeclSpecUuid:
 return true;
 
   // Never redeclarable.
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -535,6 +535,15 @@
   return Inst;
 }
 
+Decl *
+TemplateDeclInstantiator::VisitDeclSpecUuidDecl(DeclSpecUuidDecl *D) {
+  DeclSpecUuidDecl *Inst = DeclSpecUuidDecl::Create(SemaRef.Context, Owner,
+D->getLocation(),
+D->getStrUuid());
+  Owner->addDecl(Inst);
+  return Inst;
+}
+
 Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
bool IsTypeAlias) {
   bool Invalid = false;
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -566,20 +566,66 @@
   }
 }
 
+/// Find the uuid of a type.
+static void
+FindStrUuid(Sema , QualType QT,
+	llvm::SmallVector ) {
+  const Type *Ty = QT.getTypePtr();
+  if (QT->isPointerType() || QT->isReferenceType())
+Ty = QT->getPointeeType().getTypePtr();
+  else if (QT->isArrayType())
+Ty = Ty->getBaseElementTypeUnsafe();
+
+  const auto *TD = Ty->getAsTagDecl();
+  if (!TD) {
+return;
+  }
+  const Decl* dd =
+TD->getPreviousDecl() ? TD->getPreviousDecl() :
+TD->getMostRecentDecl();
+  auto str = SemaRef.DeclSpecToStrUuid.find(dd);
+  if (str != SemaRef.DeclSpecToStrUuid.end()) {
+StrUuid.push_back(str->second);
+return;
+  }
+
+  if (const auto *CTSD = dyn_cast(TD)) {
+const TemplateArgumentList  = CTSD->getTemplateArgs();
+for (const TemplateArgument  : TAL.asArray()) {
+  if (TA.getKind() == 

[PATCH] D46791: Make -gsplit-dwarf generally available

2018-05-14 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

I'm generally ok with this but I think some important checks need to occur 
first. Namely I think I'd like to check that Chromium still builds with this 
option since I'd imagine they'd be affected by this.


Repository:
  rC Clang

https://reviews.llvm.org/D46791



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


[PATCH] D46791: Make -gsplit-dwarf generally available

2018-05-14 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:4818
   // Handle the debug info splitting at object creation time if we're
   // creating an object.
   if (SplitDWARF && Output.getType() == types::TY_Object)

Maybe re-add a TODO to point out that *some* objcopy is needed be it GNU 
objcopy or llvm-objcopy? Ideally this would be done by the compiler and not by 
an external tool.



Comment at: test/Driver/split-debug.c:7
 //
 // CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo"
 // CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o"

I think I may have missed something here. I thought this would change all of 
clang's objcopy invocations regardless of the target triple. What chooses 
"objcopy" if the target system is linux or linux-gnu? I think this might be 
passing because that line still matches "llvm-objcopy ..."



Comment at: test/Driver/split-debug.c:14
+//
+// FREEBSD-NOIA-CHECK-ACTIONS: 
llvm-objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo"
+// FREEBSD-NOIA-CHECK-ACTIONS: 
llvm-objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o"

When I wrote this I wanted this test to pass regardless of which objcopy was 
used so I just left it as "objcopy" because that would still pass if 
"llvm-objcopy" or "objcopy" was used. For instance my team builds the toolchain 
and we consider a build a fail of all tests don't pass. If someone wanted to 
use a GNU objcopy and built and tested toolchains the same way they would run 
into this issue.


Repository:
  rC Clang

https://reviews.llvm.org/D46791



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-05-14 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

Pingany more thoughts?


https://reviews.llvm.org/D43341



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


[PATCH] D42966: Fix USR generation in the presence of #line directives or linemarkes

2018-05-14 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho added a comment.

> Could you provide a minimal example where USRs are not generated? It might
>  be the case that there are other ways to fix it.

Sure, I'll try to reduce our testcase, but basically we have an
ASTFrontendAction [0] that adds a set of intrinsics [1] to the preprocessor
[2].

[0]
https://github.com/esbmc/esbmc/blob/master/src/clang-c-frontend/AST/esbmc_action.h
[1]
https://github.com/esbmc/esbmc/blob/master/src/clang-c-frontend/clang_c_language.cpp#L206
[2]
https://github.com/esbmc/esbmc/blob/master/src/clang-c-frontend/AST/esbmc_action.h#L31


Repository:
  rC Clang

https://reviews.llvm.org/D42966



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


[PATCH] D46643: CodeGen: Emit string literal in constant address space

2018-05-14 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1373
+  llvm::Type *BP = llvm::Type::getInt8Ty(CGM.getLLVMContext())
+   ->getPointerTo(Loc.getAddressSpace());
   if (Loc.getType() != BP)

`CGM.Int8Ty` exists.



Comment at: lib/CodeGen/CodeGenModule.cpp:3077
+  return Cast;
+}
+

This should really just be a `static` function in this file.


https://reviews.llvm.org/D46643



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


[PATCH] D46836: Fix some rtti-options tests

2018-05-14 Thread Sunil Srivastava via Phabricator via cfe-commits
Sunil_Srivastava created this revision.
Herald added a subscriber: cfe-commits.

Certain tests in rtti-options.cpp are not really testing anything because they 
are testing for the absence of -frtti option to the cc1 process. Since the cc1 
process does not take -frtti option, these tests are passing tautologically.

The RTTI mode is enabled by default in cc1, and -fno-rtti disables it. 
Therefore the correct way to check for enabling of RTTI is to check for the 
absence of -fno-rtti to cc1, and the correct way to check for disabling of RTTI 
is to check for the presence of -fno-rtti to cc1.

This patch fixes those tests.


Repository:
  rC Clang

https://reviews.llvm.org/D46836

Files:
  test/Driver/rtti-options.cpp


Index: test/Driver/rtti-options.cpp
===
--- test/Driver/rtti-options.cpp
+++ test/Driver/rtti-options.cpp
@@ -5,12 +5,12 @@
 
 // Special cases: -fcxx-exceptions in C code should warn about unused arguments
 // We should also not have any rtti-related arguments
-// RUN: %clang -x c -### -target x86_64-scei-ps4 -c -fcxx-exceptions %s 2>&1 | 
FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI 
-check-prefix=CHECK-NO-RTTI %s
-// RUN: %clang -x c -### -target x86_64-unknown-unknown -c -fcxx-exceptions %s 
2>&1 | FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI 
-check-prefix=CHECK-NO-RTTI %s
+// RUN: %clang -x c -### -target x86_64-scei-ps4 -c -fcxx-exceptions %s 2>&1 | 
FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI %s
+// RUN: %clang -x c -### -target x86_64-unknown-unknown -c -fcxx-exceptions %s 
2>&1 | FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI %s
 
 // Make sure we keep the last -frtti/-fno-rtti argument
 // RUN: %clang -### -c -fno-rtti -frtti %s 2>&1 | FileCheck 
-check-prefix=CHECK-RTTI %s
-// RUN: %clang -### -c -frtti -fno-rtti %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-RTTI %s
+// RUN: %clang -### -c -frtti -fno-rtti %s 2>&1 | FileCheck 
-check-prefix=CHECK-RTTI-NOT %s
 
 // -fsanitize=vptr
 // Make sure we only error/warn once, when trying to enable vptr and
@@ -43,10 +43,10 @@
 
 // -f{no-,}rtti/default
 // RUN: %clang -### -c -target x86_64-scei-ps4 -frtti %s 2>&1 | FileCheck 
-check-prefix=CHECK-RTTI %s
-// RUN: %clang -### -c -target x86_64-scei-ps4 -fno-rtti %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-RTTI %s
-// RUN: %clang -### -c -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-RTTI %s
+// RUN: %clang -### -c -target x86_64-scei-ps4 -fno-rtti %s 2>&1 | FileCheck 
-check-prefix=CHECK-RTTI-NOT %s
+// RUN: %clang -### -c -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=CHECK-RTTI-NOT %s
 // RUN: %clang -### -c -target x86_64-unknown-unknown -frtti %s 2>&1 | 
FileCheck -check-prefix=CHECK-RTTI %s
-// RUN: %clang -### -c -target x86_64-unknown-unknown -fno-rtti %s 2>&1 | 
FileCheck -check-prefix=CHECK-NO-RTTI %s
+// RUN: %clang -### -c -target x86_64-unknown-unknown -fno-rtti %s 2>&1 | 
FileCheck -check-prefix=CHECK-RTTI-NOT %s
 // RUN: %clang -### -c -target x86_64-unknown-unknown %s 2>&1 | FileCheck 
-check-prefix=CHECK-RTTI %s
 
 // CHECK-UNUSED: warning: argument unused during compilation: 
'-fcxx-exceptions'
@@ -56,6 +56,5 @@
 // CHECK-EXC-ERROR: invalid argument '-fno-rtti' not allowed with 
'-fexceptions'
 // CHECK-EXC-ERROR-CXX: invalid argument '-fno-rtti' not allowed with 
'-fcxx-exceptions'
 // CHECK-RTTI-NOT: "-fno-rtti"
-// CHECK-NO-RTTI-NOT: "-frtti"
 
 // CHECK-OK-NOT: {{warning:|error:}}


Index: test/Driver/rtti-options.cpp
===
--- test/Driver/rtti-options.cpp
+++ test/Driver/rtti-options.cpp
@@ -5,12 +5,12 @@
 
 // Special cases: -fcxx-exceptions in C code should warn about unused arguments
 // We should also not have any rtti-related arguments
-// RUN: %clang -x c -### -target x86_64-scei-ps4 -c -fcxx-exceptions %s 2>&1 | FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI -check-prefix=CHECK-NO-RTTI %s
-// RUN: %clang -x c -### -target x86_64-unknown-unknown -c -fcxx-exceptions %s 2>&1 | FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI -check-prefix=CHECK-NO-RTTI %s
+// RUN: %clang -x c -### -target x86_64-scei-ps4 -c -fcxx-exceptions %s 2>&1 | FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI %s
+// RUN: %clang -x c -### -target x86_64-unknown-unknown -c -fcxx-exceptions %s 2>&1 | FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI %s
 
 // Make sure we keep the last -frtti/-fno-rtti argument
 // RUN: %clang -### -c -fno-rtti -frtti %s 2>&1 | FileCheck -check-prefix=CHECK-RTTI %s
-// RUN: %clang -### -c -frtti -fno-rtti %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RTTI %s
+// RUN: %clang -### -c -frtti -fno-rtti %s 2>&1 | FileCheck -check-prefix=CHECK-RTTI-NOT %s
 
 // -fsanitize=vptr
 // Make sure we only error/warn once, when trying to enable vptr and
@@ -43,10 +43,10 @@
 
 // -f{no-,}rtti/default
 // 

[PATCH] D46835: [ASTImporter] Do not try to remove invisible Decls from DeclContext

2018-05-14 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: xazax.hun, a.sidorin.
Herald added subscribers: cfe-commits, dkrupp, rnkovacs.

`DeclContext` is essentially a list of `Decl`s and a lookup table (`LookupPtr`) 
but these are encapsulated.
E.g. `LookupPtr` is private. `DeclContext::removeDecl` has the responsibility 
to remove the given decl from the list and from the table too.
Template specializations cannot participate in normal (qualified) lookup.
Consequently no template specialization can be in the lookup table, but they 
will be in the list. When the lookup table is built or when a new `Decl` is 
added, then it is checked whether it is a template specialization and if so it 
is skipped from the lookup table.
Thus, whenever we want to remove a `Decl` from a `DeclContext` we must not 
reach the point to remove that from the lookup table (and that is what this 
patch do).

With respect to ASTImporter: At some point probably we will be reordering 
`FriendDecl`s and possibly `CXXMethodDecl`s in a `RecordDecl` at 
`importDeclContext` to be able to structurally compare two `RecordDecl`s.
When that happens we most probably want to remove all `Decls` from a 
`RecordDecl` and then we would add them in the proper order.


Repository:
  rC Clang

https://reviews.llvm.org/D46835

Files:
  lib/AST/DeclBase.cpp
  unittests/AST/ASTImporterTest.cpp
  unittests/AST/MatchVerifier.h

Index: unittests/AST/MatchVerifier.h
===
--- unittests/AST/MatchVerifier.h
+++ unittests/AST/MatchVerifier.h
@@ -28,11 +28,12 @@
 namespace clang {
 namespace ast_matchers {
 
-enum Language { 
+enum Language {
 Lang_C,
 Lang_C89,
 Lang_CXX,
 Lang_CXX11,
+Lang_CXX14,
 Lang_OpenCL,
 Lang_OBJCXX
 };
@@ -113,6 +114,10 @@
 Args.push_back("-std=c++11");
 FileName = "input.cc";
 break;
+  case Lang_CXX14:
+Args.push_back("-std=c++14");
+FileName = "input.cc";
+break;
   case Lang_OpenCL:
 FileName = "input.cl";
 break;
Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -52,6 +52,9 @@
   case Lang_CXX11:
 BasicArgs = {"-std=c++11", "-frtti"};
 break;
+  case Lang_CXX14:
+BasicArgs = {"-std=c++14", "-frtti"};
+break;
   case Lang_OpenCL:
   case Lang_OBJCXX:
 llvm_unreachable("Not implemented yet!");
@@ -1764,5 +1767,86 @@
  compoundStmt(has(callExpr(has(unresolvedMemberExpr());
 }
 
+TEST(ImportExpr, ImportClassTemplatePartialSpecialization) {
+  MatchVerifier Verifier;
+  auto Code =
+R"s(
+struct declToImport {
+  template 
+  struct X {};
+  template 
+  struct X {};
+  X x0;
+};
+)s";
+
+  testImport(Code, Lang_CXX, "", Lang_CXX, Verifier, recordDecl());
+}
+
+TEST(ImportExpr, ImportSpecializationsOfFriendClassTemplate) {
+  MatchVerifier Verifier;
+  auto Code =
+R"(
+namespace declToImport {
+
+template 
+struct F{};
+
+class X {
+  friend struct F;
+  friend struct F;
+};
+
+} // namespace
+)";
+
+  testImport(Code, Lang_CXX11, "", Lang_CXX11, Verifier, namespaceDecl());
+}
+
+TEST(ImportExpr, ImportSpecializationsOfVariableTemplate) {
+  MatchVerifier Verifier;
+  auto Code =
+R"(
+namespace declToImport {
+
+struct limits {
+  template
+  static const T min; // declaration of a static data member template
+};
+template
+const T limits::min = { }; // definition of a static data member template
+
+template const int limits::min; // explicit instantiation
+
+} // namespace
+)";
+
+  testImport(Code, Lang_CXX14, "", Lang_CXX14, Verifier, namespaceDecl());
+}
+
+TEST_P(ASTImporterTestBase, DISABLED_ImportOfRecordWithDifferentFriends) {
+  Decl *ToR1;
+  {
+Decl *FromTU = getTuDecl("struct A { friend class F0; friend class F1; };",
+ Lang_CXX, "input0.cc");
+auto *FromR = FirstDeclMatcher().match(
+FromTU, cxxRecordDecl(hasName("A")));
+
+ToR1 = Import(FromR, Lang_CXX);
+  }
+
+  Decl *ToR2;
+  {
+Decl *FromTU =
+getTuDecl("struct A { friend class F0; };", Lang_CXX, "input1.cc");
+auto *FromR = FirstDeclMatcher().match(
+FromTU, cxxRecordDecl(hasName("A")));
+
+ToR2 = Import(FromR, Lang_CXX);
+  }
+
+  EXPECT_NE(ToR1, ToR2);
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/DeclBase.cpp
===
--- lib/AST/DeclBase.cpp
+++ lib/AST/DeclBase.cpp
@@ -1350,6 +1350,8 @@
   (D->NextInContextAndBits.getPointer() || D == LastDecl));
 }
 
+static bool shouldBeHidden(NamedDecl *D);
+
 void DeclContext::removeDecl(Decl *D) {
   assert(D->getLexicalDeclContext() == this &&
  "decl being removed from non-lexical context");
@@ -1372,14 +1374,18 

[PATCH] D46602: [clang-tidy] Store checks profiling info as YAML files

2018-05-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D46602#1097954, @lebedev.ri wrote:

> In https://reviews.llvm.org/D46602#1097902, @alexfh wrote:
>
> > In https://reviews.llvm.org/D46602#1095980, @lebedev.ri wrote:
> >
> > > In https://reviews.llvm.org/D46602#1095960, @alexfh wrote:
> > >
> > > > In https://reviews.llvm.org/D46602#1092902, @lebedev.ri wrote:
> > > >
> > > > > In https://reviews.llvm.org/D46602#1092890, @alexfh wrote:
> > > > >
> > > > > > Roman, it looks to me that a simpler storage scheme would be 
> > > > > > sufficient. For example, MMDDhhmmss-InputFileName.cpp.csv.
> > > > > >  Main things are:
> > > > > >
> > > > > > 1. include a timestamp, so there's no need to overwrite old results,
> > > > >
> > > > >
> > > > > Of the input source file?
> > > >
> > > >
> > > > No, current timestamp, when each profile gets dumped.
> > >
> > >
> > > Ah.
> > >  Then i don't understand this at all. Why would we want to do that, 
> > > exactly?
> > >  Just so that we can avoid creating directory structure? Why do we want 
> > > to avoid that?
> >
> >
> > If clang-tidy is invoked manually, a simpler naming scheme with less 
> > configuration options would be easier to use, in particular:
> >
> > 1. no the need to specify the `-store-check-profile-elide-prefix=` option;
> > 2. it's easier to see all results (no need to use `find`, just `ls 
> > /output/directory` or `ls /output/directory/20180514*` to see today's 
> > results, for example);
> > 3. no chance of filename collision, and thus no chance of losing older 
> > results by just running clang-tidy again.
>
>
> How do i reflect that in tests? The output name will basically be random.


Why random? It will follow a certain rule that can be verified. If we decide to 
name the file `MMDD_InputFileName.cpp.yaml`, for example, then the test can 
verify the file matching `_InputFileName.cpp.yaml` exists and contains 
whatever it should contain. If we want the test to be stricter, it could verify 
that the `` part matches a certain pattern (say, 
`20\d\d[0-1][0-9][0-3][0-9]`). Additionally, it could verify that after a short 
sleep a file with a different `` part is generated.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46602



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


r332256 - [ASTImporter] Turn StringRefs back to std::strings to avoid use-after-free

2018-05-14 Thread Aleksei Sidorin via cfe-commits
Author: a.sidorin
Date: Mon May 14 09:12:31 2018
New Revision: 332256

URL: http://llvm.org/viewvc/llvm-project?rev=332256=rev
Log:
[ASTImporter] Turn StringRefs back to std::strings to avoid use-after-free

This is a workaround for the issue in buildASTFromCodeWithArgs()
where a local buffer can be used to store the program text
referred by SourceManager.
FIXME: Fix the root issue in buildASTFromCodeWithArgs().


Modified:
cfe/trunk/unittests/AST/ASTImporterTest.cpp

Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=332256=332255=332256=diff
==
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Mon May 14 09:12:31 2018
@@ -207,8 +207,8 @@ class ASTImporterTestBase : public ::tes
 
   struct TU {
 // Buffer for the context, must live in the test scope.
-StringRef Code;
-StringRef FileName;
+std::string Code;
+std::string FileName;
 std::unique_ptr Unit;
 TranslationUnitDecl *TUDecl = nullptr;
 TU(StringRef Code, StringRef FileName, ArgVector Args)


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


[PATCH] D46834: [Sema][Cxx17] Error message for C++17 static_assert(pred) without string literal

2018-05-14 Thread Jan Korous via Phabricator via cfe-commits
jkorous created this revision.
jkorous added reviewers: arphaman, dexonsmith, rsmith, doug.gregor.
jkorous added a project: clang.
Herald added a subscriber: cfe-commits.

C++17 adds form of static_assert without string literal.

  static_assert ( bool_constexpr )

Currently clang produces diagnostics like this:

  assert.cpp:1:1: error: static_assert failed
  static_assert(false);
  ^ ~
  1 error generated.

This patch adds assert expression to error message in case string literal is 
missing:

  /Users/jkorous/assert.cpp:1:1: error: static_assert failed "false"
  static_assert(false);
  ^ ~
  1 error generated.

Reasons why printing assert expression in absence of string literal is useful 
are:

1. Serialized diagnostics (--serialize-diagnostics) don't contain code snippet 
and thus error message lack context.
2. No all tools scraping clang diagnostics use caret snippet provided by 
-f-caret-diagnostics.

This patch doesn't address message length limit as currently clang doesn't 
truncate messages anyway but it might be subject of another patch.

rdar://problem/38931241


Repository:
  rC Clang

https://reviews.llvm.org/D46834

Files:
  lib/Parse/ParseDeclCXX.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/static-assert-cxx17.cpp
  test/SemaCXX/static-assert.cpp


Index: test/SemaCXX/static-assert.cpp
===
--- test/SemaCXX/static-assert.cpp
+++ test/SemaCXX/static-assert.cpp
@@ -50,7 +50,7 @@
 StaticAssertProtected sap2; // expected-note {{instantiation}}
 
 static_assert(true); // expected-warning {{C++17 extension}}
-static_assert(false); // expected-error-re {{failed{{$ expected-warning 
{{extension}}
+static_assert(false); // expected-error {{static_assert failed "false"}} 
expected-warning {{C++17 extension}}
 
 
 // Diagnostics for static_assert with multiple conditions
Index: test/SemaCXX/static-assert-cxx17.cpp
===
--- /dev/null
+++ test/SemaCXX/static-assert-cxx17.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+static_assert(false, "foo"); // expected-error {{static_assert failed "foo"}}
+static_assert(false == true); // expected-error {{static_assert failed "false 
== true"}}
+static_assert(false, "foo \"bar\" baz"); // expected-error {{static_assert 
failed "foo \"bar\" baz"}}
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -13736,9 +13736,16 @@
 
 if (!Failed && !Cond) {
   SmallString<256> MsgBuffer;
-  llvm::raw_svector_ostream Msg(MsgBuffer);
-  if (AssertMessage)
-AssertMessage->printPretty(Msg, nullptr, getPrintingPolicy());
+  {
+llvm::raw_svector_ostream Msg(MsgBuffer);
+if (AssertMessage)
+  AssertMessage->printPretty(Msg, nullptr, getPrintingPolicy());
+else {
+  AssertExpr->printPretty(Msg, nullptr, getPrintingPolicy());
+  MsgBuffer.insert(MsgBuffer.begin(), '\"');
+  MsgBuffer.append(1, '\"');
+}
+  }
 
   Expr *InnerCond = nullptr;
   std::string InnerCondDescription;
@@ -13747,11 +13754,12 @@
/*AllowTopLevelCond=*/false);
   if (InnerCond) {
 Diag(StaticAssertLoc, diag::err_static_assert_requirement_failed)
-  << InnerCondDescription << !AssertMessage
-  << Msg.str() << InnerCond->getSourceRange();
+  << InnerCondDescription << MsgBuffer.empty() << MsgBuffer.str()
+  << InnerCond->getSourceRange();
   } else {
 Diag(StaticAssertLoc, diag::err_static_assert_failed)
-  << !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
+  << MsgBuffer.empty() << MsgBuffer.str()
+  << AssertExpr->getSourceRange();
   }
   Failed = true;
 }
Index: lib/Parse/ParseDeclCXX.cpp
===
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -819,7 +819,10 @@
 
 /// ParseStaticAssertDeclaration - Parse C++0x or C11 
static_assert-declaration.
 ///
-/// [C++0x] static_assert-declaration:
+/// [C++17] static_assert-declaration:
+///   static_assert ( constant-expression  ) ;
+///
+/// [C++11] static_assert-declaration:
 ///   static_assert ( constant-expression  ,  string-literal  ) ;
 ///
 /// [C11]   static_assert-declaration:


Index: test/SemaCXX/static-assert.cpp
===
--- test/SemaCXX/static-assert.cpp
+++ test/SemaCXX/static-assert.cpp
@@ -50,7 +50,7 @@
 StaticAssertProtected sap2; // expected-note {{instantiation}}
 
 static_assert(true); // expected-warning {{C++17 extension}}
-static_assert(false); // expected-error-re {{failed{{$ expected-warning {{extension}}
+static_assert(false); // expected-error 

[PATCH] D46421: [analyzer][CrossTU] Extend CTU to VarDecls with initializer

2018-05-14 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

The analyzer can only reason about const variables this way, right? Maybe we 
should only import the initializers for such variables to have better 
performance? What do you think?

Also, I wonder what happens with user-defined classes. Will the analyzer 
evaluate the constructor if the variable is imported?




Comment at: include/clang/CrossTU/CrossTranslationUnit.h:114
+  llvm::Expected
+  getCrossTUDefinition(const VarDecl *VD, StringRef CrossTUDir,
+   StringRef IndexName);

I wonder if we need these overloads. Maybe having only the templated version 
and having a static assert for the supported types is better? Asking the other 
reviewers as well.



Comment at: include/clang/CrossTU/CrossTranslationUnit.h:138
   llvm::Expected importDefinition(const FunctionDecl 
*FD);
+  llvm::Expected importDefinition(const VarDecl *VD);
 

Same question as above.



Comment at: lib/CrossTU/CrossTranslationUnit.cpp:114
 
+bool HasDefinition(const FunctionDecl *D, const FunctionDecl *) {
+  return D->hasBody(DefD);

Functions should start with lowercase letter. Maybe these could be static?



Comment at: lib/CrossTU/CrossTranslationUnit.cpp:143
+CrossTranslationUnitContext::findDefInDeclContext(const DeclContext *DC,
+  StringRef LookupFnName) {
   assert(DC && "Declaration Context must not be null");

Fn in the name refers to a function, maybe that could be changed as well.



Comment at: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:354
+if (!VD->hasExternalStorage() ||
+VD->getAnyInitializer() != nullptr)
+  return true;

Will this work for zero initialized globals (i.e. not having an initializer 
expression) that are defined in the current translation unit? It would be great 
to have a test case for that.


https://reviews.llvm.org/D46421



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


[PATCH] D46496: [Tooling] Pull #include manipulation code from clangFormat into libToolingCore.

2018-05-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: lib/Format/Format.cpp:1702
   // cases where the first #include is unlikely to be the main header.
-  IncludeCategoryManager Categories(Style, FileName);
+  tooling::IncludeCategoryManager Categories(Style.IncludeStyle, FileName);
   bool FirstIncludeBlock = true;

ilya-biryukov wrote:
> It seems `Style.IncludeStyle` should be in the other change that pulls out 
> `IncludeStyle` from `FormatStyle`.
> Or am I missing something?
As chatted offline, we need this to pull out `IncludeCategoryManager` out of 
Format.cpp.
That should be the only change in this commit, other than moving the code 
around, so there's no need to pull it into a separate commit.


Repository:
  rC Clang

https://reviews.llvm.org/D46496



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


[PATCH] D46159: [clang-tidy] Add a flag to enable alpha checkers

2018-05-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D46159#1098018, @alexfh wrote:

> In https://reviews.llvm.org/D46159#1098000, @pfultz2 wrote:
>
> > Is someone able to merge in my changes?
>
>
> Will do.


Please rebase the patch, it doesn't apply cleanly.


https://reviews.llvm.org/D46159



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


[PATCH] D46159: [clang-tidy] Add a flag to enable alpha checkers

2018-05-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D46159#1098000, @pfultz2 wrote:

> Is someone able to merge in my changes?


Will do.


https://reviews.llvm.org/D46159



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


[PATCH] D46353: [ASTImporter] Extend lookup logic in class templates

2018-05-14 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin accepted this revision.
a.sidorin added a comment.
This revision is now accepted and ready to land.

In https://reviews.llvm.org/D46353#1086456, @martong wrote:

> > should we add this new declaration to the redeclaration chain like we do it 
> > for RecordDecls?
>
> I think, on a long term we should. Otherwise we could loose e.g. C++11 
> attributes which are attached to the forward declaration only.
>  However, I'd do that as a separate commit, because that would require some 
> independent changes and tests, also other decl kinds like 
> ClassTemplateSepcializationDecl may be affected as well by that.


I'm fine with this. But a FIXME would be very appreciated.


Repository:
  rC Clang

https://reviews.llvm.org/D46353



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


[PATCH] D46496: [Tooling] Pull #include manipulation code from clangFormat into libToolingCore.

2018-05-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

This LG, presuming there are no semantic changes here, just moving the code 
around.
Also see the nits about `IncludeStyle` that seems to be in the wrong change...




Comment at: include/clang/Tooling/Core/HeaderIncludes.h:112
+/// priorities for headers.
+/// FIXME(ioeric): move this class into implementation file when clang-format's
+/// include sorting functions are also moved here.

ioeric wrote:
> ilya-biryukov wrote:
> > Can we move them in the current commit too?
> > `IncludeCategoryManager` does look like something that should not be in the 
> > public header.
> Not yet... include sorting logics would also require refactoring in order to 
> be moved from clang-format.
Ok, a FIXME mentioning that this class should be removed seems good enough. 
Thanks.



Comment at: lib/Format/Format.cpp:1702
   // cases where the first #include is unlikely to be the main header.
-  IncludeCategoryManager Categories(Style, FileName);
+  tooling::IncludeCategoryManager Categories(Style.IncludeStyle, FileName);
   bool FirstIncludeBlock = true;

It seems `Style.IncludeStyle` should be in the other change that pulls out 
`IncludeStyle` from `FormatStyle`.
Or am I missing something?



Comment at: lib/Format/Format.cpp:1862
   StringRef FileName = Replaces.begin()->getFilePath();
-  HeaderIncludes Includes(FileName, Code, Style);
+  tooling::HeaderIncludes Includes(FileName, Code, Style.IncludeStyle);
 

Here too. Shouldn't it be part of the other change?


Repository:
  rC Clang

https://reviews.llvm.org/D46496



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


[PATCH] D46758: [clang-format] Move #include related style to libToolingCore

2018-05-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D46758



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


[PATCH] D46747: [Sema] Use dotted form of macOS version for unguarded availability FixIts

2018-05-14 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington accepted this revision.
erik.pilkington added a comment.
This revision is now accepted and ready to land.

Thanks for the explanation, LGTM.


https://reviews.llvm.org/D46747



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


[PATCH] D46159: [clang-tidy] Add a flag to enable alpha checkers

2018-05-14 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added a comment.

Is someone able to merge in my changes?


https://reviews.llvm.org/D46159



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


[PATCH] D43281: [AMDGPU] fixes for lds f32 builtins

2018-05-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D43281



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


[PATCH] D46398: [ASTImporterTest] Fix potential use-after-free

2018-05-14 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rC Clang

https://reviews.llvm.org/D46398



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


[PATCH] D46805: If some platforms do not support an attribute, we should exclude the platform

2018-05-14 Thread Li Jia He via Phabricator via cfe-commits
HLJ2009 added inline comments.



Comment at: include/clang/Basic/Attr.td:566-567
 
-def Alias : Attr {
+// We do not support alias attribute on Apple platform, so we exclude the 
platform.
+def Alias : Attr, TargetSpecificAttr {
   let Spellings = [GCC<"alias">];

rsmith wrote:
> Is this really specific to Darwin? I would expect it instead to be specific 
> to the `ObjectFormat`. And I think listing the object formats that *do* 
> support aliases seems reasonable (as there's only three of them to list -- 
> assuming that WAsm actually supports aliases, which I don't know -- and we'd 
> probably want future object file formats to opt in rather than opting out).
Hi,
   If using this program, we need to define a support alias platform, is not 
it? This platform needs to include the ArchType in the Triple.h file for the 
most part, and we need to set the ObjectFormatType to COFF, ELF, and Wasm. But 
we only want to exclude the few unsupported platforms. If my understanding is 
not right, please told me.


Repository:
  rC Clang

https://reviews.llvm.org/D46805



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


[PATCH] D46685: [CodeGen] Disable structor optimizations at -O0

2018-05-14 Thread Pavel Labath via Phabricator via cfe-commits
labath added a comment.

I've reverted the patch as it has caused miscompiles on non-trivial inputs. 
I'll update the patch when I gain a better understanding of what is going on.


Repository:
  rC Clang

https://reviews.llvm.org/D46685



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


[PATCH] D46602: [clang-tidy] Store checks profiling info as YAML files

2018-05-14 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D46602#1097902, @alexfh wrote:

> In https://reviews.llvm.org/D46602#1095980, @lebedev.ri wrote:
>
> > In https://reviews.llvm.org/D46602#1095960, @alexfh wrote:
> >
> > > In https://reviews.llvm.org/D46602#1092902, @lebedev.ri wrote:
> > >
> > > > In https://reviews.llvm.org/D46602#1092890, @alexfh wrote:
> > > >
> > > > > Roman, it looks to me that a simpler storage scheme would be 
> > > > > sufficient. For example, MMDDhhmmss-InputFileName.cpp.csv.
> > > > >  Main things are:
> > > > >
> > > > > 1. include a timestamp, so there's no need to overwrite old results,
> > > >
> > > >
> > > > Of the input source file?
> > >
> > >
> > > No, current timestamp, when each profile gets dumped.
> >
> >
> > Ah.
> >  Then i don't understand this at all. Why would we want to do that, exactly?
> >  Just so that we can avoid creating directory structure? Why do we want to 
> > avoid that?
>
>
> If clang-tidy is invoked manually, a simpler naming scheme with less 
> configuration options would be easier to use, in particular:
>
> 1. no the need to specify the `-store-check-profile-elide-prefix=` option;
> 2. it's easier to see all results (no need to use `find`, just `ls 
> /output/directory` or `ls /output/directory/20180514*` to see today's 
> results, for example);
> 3. no chance of filename collision, and thus no chance of losing older 
> results by just running clang-tidy again.


How do i reflect that in tests? The output name will basically be random.

> If clang-tidy is started by a script (e.g. run-clang-tidy.py or a 
> modification of it specialized on profiling), then a specific naming scheme 
> doesn't matter much, since the script can create a separate directory for 
> each run or for each shard. I don't yet see how repeating the directory 
> structure of the input files would make profiling results easier or more 
> convenient to use. A relation between the input file and the result file can 
> still be maintained in some other form (for example, by specifying the whole 
> invocation inside the results file - if we want to use YAML).




Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46602



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


[PATCH] D46421: [analyzer][CrossTU] Extend CTU to VarDecls with initializer

2018-05-14 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl updated this revision to Diff 146609.
r.stahl marked an inline comment as done.
r.stahl added a comment.

- added tests
- updated doc and var naming
- addressed review comment


https://reviews.llvm.org/D46421

Files:
  include/clang/CrossTU/CrossTranslationUnit.h
  lib/CrossTU/CrossTranslationUnit.cpp
  lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  test/Analysis/Inputs/ctu-other.cpp
  test/Analysis/Inputs/externalFnMap.txt
  test/Analysis/ctu-main.cpp
  test/Analysis/func-mapping-test.cpp

Index: test/Analysis/func-mapping-test.cpp
===
--- test/Analysis/func-mapping-test.cpp
+++ test/Analysis/func-mapping-test.cpp
@@ -3,5 +3,16 @@
 int f(int) {
   return 0;
 }
+// CHECK-DAG: c:@F@f#I#
 
-// CHECK: c:@F@f#I#
+int x = 5;
+// CHECK-DAG: c:@x
+
+struct S {
+  int a;
+};
+S s = {.a = 2};
+// CHECK-DAG: c:@s
+
+int arr[5] = { 0, 1 };
+// CHECK-DAG: c:@arr
Index: test/Analysis/ctu-main.cpp
===
--- test/Analysis/ctu-main.cpp
+++ test/Analysis/ctu-main.cpp
@@ -42,6 +42,15 @@
 
 int fun_using_anon_struct(int);
 
+extern const int extInt;
+namespace intns {
+extern const int extInt;
+}
+struct S {
+  int a;
+};
+extern const S extS;
+
 int main() {
   clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
   clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}
@@ -58,4 +67,8 @@
 
   clang_analyzer_eval(chns::chf1(4) == 12); // expected-warning{{TRUE}}
   clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}}
+
+  clang_analyzer_eval(extInt == 2); // expected-warning{{TRUE}}
+  clang_analyzer_eval(intns::extInt == 3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(extS.a == 4); // expected-warning{{TRUE}}
 }
Index: test/Analysis/Inputs/externalFnMap.txt
===
--- test/Analysis/Inputs/externalFnMap.txt
+++ test/Analysis/Inputs/externalFnMap.txt
@@ -12,3 +12,6 @@
 c:@N@chns@S@chcls@F@chf4#I# ctu-chain.cpp.ast
 c:@N@chns@F@chf2#I# ctu-chain.cpp.ast
 c:@F@fun_using_anon_struct#I# ctu-other.cpp.ast
+c:@extInt ctu-other.cpp.ast
+c:@N@intns@extInt ctu-other.cpp.ast
+c:@extS ctu-other.cpp.ast
Index: test/Analysis/Inputs/ctu-other.cpp
===
--- test/Analysis/Inputs/ctu-other.cpp
+++ test/Analysis/Inputs/ctu-other.cpp
@@ -68,3 +68,12 @@
 
 typedef struct { int n; } Anonymous;
 int fun_using_anon_struct(int n) { Anonymous anon; anon.n = n; return anon.n; }
+
+extern const int extInt = 2;
+namespace intns {
+extern const int extInt = 3;
+}
+struct S {
+  int a;
+};
+extern const S extS = {.a = 4};
Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -346,6 +346,27 @@
 return true;
   }
 
+  bool VisitVarDecl(VarDecl *VD) {
+if (!Opts->naiveCTUEnabled())
+  return true;
+
+if (!VD->hasExternalStorage() ||
+VD->getAnyInitializer() != nullptr)
+  return true;
+
+llvm::Expected CTUDeclOrError =
+  CTU.getCrossTUDefinition(VD, Opts->getCTUDir(), Opts->getCTUIndexName());
+
+if (!CTUDeclOrError) {
+  handleAllErrors(CTUDeclOrError.takeError(),
+  [&](const cross_tu::IndexError ) {
+CTU.emitCrossTUDiagnostics(IE);
+  });
+}
+
+return true;
+  }
+
   bool VisitFunctionDecl(FunctionDecl *FD) {
 IdentifierInfo *II = FD->getIdentifier();
 if (II && II->getName().startswith("__inline"))
Index: lib/CrossTU/CrossTranslationUnit.cpp
===
--- lib/CrossTU/CrossTranslationUnit.cpp
+++ lib/CrossTU/CrossTranslationUnit.cpp
@@ -87,14 +87,14 @@
 const size_t Pos = Line.find(" ");
 if (Pos > 0 && Pos != std::string::npos) {
   StringRef LineRef{Line};
-  StringRef FunctionLookupName = LineRef.substr(0, Pos);
-  if (Result.count(FunctionLookupName))
+  StringRef LookupName = LineRef.substr(0, Pos);
+  if (Result.count(LookupName))
 return llvm::make_error(
 index_error_code::multiple_definitions, IndexPath.str(), LineNo);
   StringRef FileName = LineRef.substr(Pos + 1);
   SmallString<256> FilePath = CrossTUDir;
   llvm::sys::path::append(FilePath, FileName);
-  Result[FunctionLookupName] = FilePath.str().str();
+  Result[LookupName] = FilePath.str().str();
 } else
   return llvm::make_error(
   index_error_code::invalid_index_format, IndexPath.str(), LineNo);
@@ -111,52 +111,65 @@
   return Result.str();
 }
 
+bool HasDefinition(const FunctionDecl *D, const FunctionDecl *) {
+  return D->hasBody(DefD);
+}
+bool HasDefinition(const VarDecl *D, const VarDecl *) {
+  return D->getAnyInitializer(DefD) != 

[PATCH] D46747: [Sema] Use dotted form of macOS version for unguarded availability FixIts

2018-05-14 Thread Jan Korous via Phabricator via cfe-commits
jkorous added a comment.

I am not 100% sure it's the best thing to set printing style at the point of 
parsing version tuples but I am not sure it's bad either. Unless someone 
convinces me otherwise I would rather not do any major changes.


https://reviews.llvm.org/D46747



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


[PATCH] D46747: [Sema] Use dotted form of macOS version for unguarded availability FixIts

2018-05-14 Thread Jan Korous via Phabricator via cfe-commits
jkorous updated this revision to Diff 146605.
jkorous added a comment.

Fixed the test. It turned out that version component separator for availability 
is set during parsing which is why all other tests (including my bad one) are 
passing.

The only way how to set underscore as a separator is through VersionTuple 
constructor...

https://clang.llvm.org/doxygen/classclang_1_1VersionTuple.html#a71e5354ccb617494136bdcb4d208a573

  clang::VersionTuple::VersionTuple (   unsignedMajor,
unsignedMinor,
unsignedSubminor,
unsignedBuild,
boolUsesUnderscores = false 
  )

...which is exactly what is happening during parsing version tuple...

  VersionTuple Parser::ParseVersionTuple(SourceRange ) {
// ...
return VersionTuple(Major, Minor, Subminor, (AfterMajorSeparator == '_'));
  }

...which function is called when parsing availability attribute:

  void Parser::ParseAvailabilityAttribute(IdentifierInfo ,
// ...
VersionTuple Version = ParseVersionTuple(VersionRange);
// ...
  }


https://reviews.llvm.org/D46747

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/FixIt/fixit-availability-method.mm


Index: test/FixIt/fixit-availability-method.mm
===
--- /dev/null
+++ test/FixIt/fixit-availability-method.mm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.11 -Wunguarded-availability 
-fdiagnostics-parseable-fixits -fsyntax-only -verify %s
+
+@interface foo
+- (void) method_bar __attribute__((availability(macosx, introduced = 10_12))); 
// expected-note {{'method_bar' has been explicitly marked partial here}}
+@end
+
+int main() {
+[foo method_bar]; // \
+// expected-warning {{'method_bar' is only available on macOS 10.12 or 
newer}} \
+// expected-note {{enclose 'method_bar' in an @available check to silence 
this warning}} \
+// CHECK: "fix-it:.*if (@available(macOS 10.12, *))"
+return 0;
+}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -7467,6 +7467,7 @@
 const AvailabilityAttr *AA =
   getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
 VersionTuple Introduced = AA->getIntroduced();
+Introduced.UseDotAsSeparator();
 
 if (AvailabilityStack.back() >= Introduced)
   return;


Index: test/FixIt/fixit-availability-method.mm
===
--- /dev/null
+++ test/FixIt/fixit-availability-method.mm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.11 -Wunguarded-availability -fdiagnostics-parseable-fixits -fsyntax-only -verify %s
+
+@interface foo
+- (void) method_bar __attribute__((availability(macosx, introduced = 10_12))); // expected-note {{'method_bar' has been explicitly marked partial here}}
+@end
+
+int main() {
+[foo method_bar]; // \
+// expected-warning {{'method_bar' is only available on macOS 10.12 or newer}} \
+// expected-note {{enclose 'method_bar' in an @available check to silence this warning}} \
+// CHECK: "fix-it:.*if (@available(macOS 10.12, *))"
+return 0;
+}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -7467,6 +7467,7 @@
 const AvailabilityAttr *AA =
   getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
 VersionTuple Introduced = AA->getIntroduced();
+Introduced.UseDotAsSeparator();
 
 if (AvailabilityStack.back() >= Introduced)
   return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46602: [clang-tidy] Store checks profiling info as YAML files

2018-05-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

In https://reviews.llvm.org/D46602#1095980, @lebedev.ri wrote:

> In https://reviews.llvm.org/D46602#1095960, @alexfh wrote:
>
> > In https://reviews.llvm.org/D46602#1092902, @lebedev.ri wrote:
> >
> > > In https://reviews.llvm.org/D46602#1092890, @alexfh wrote:
> > >
> > > > Roman, it looks to me that a simpler storage scheme would be 
> > > > sufficient. For example, MMDDhhmmss-InputFileName.cpp.csv.
> > > >  Main things are:
> > > >
> > > > 1. include a timestamp, so there's no need to overwrite old results,
> > >
> > >
> > > Of the input source file?
> >
> >
> > No, current timestamp, when each profile gets dumped.
>
>
> Ah.
>  Then i don't understand this at all. Why would we want to do that, exactly?
>  Just so that we can avoid creating directory structure? Why do we want to 
> avoid that?


If clang-tidy is invoked manually, a simpler naming scheme with less 
configuration options would be easier to use, in particular:

1. no the need to specify the `-store-check-profile-elide-prefix=` option;
2. it's easier to see all results (no need to use `find`, just `ls 
/output/directory` or `ls /output/directory/20180514*` to see today's results, 
for example);
3. no chance of filename collision, and thus no chance of losing older results 
by just running clang-tidy again.

If clang-tidy is started by a script (e.g. run-clang-tidy.py or a modification 
of it specialized on profiling), then a specific naming scheme doesn't matter 
much, since the script can create a separate directory for each run or for each 
shard. I don't yet see how repeating the directory structure of the input files 
would make profiling results easier or more convenient to use. A relation 
between the input file and the result file can still be maintained in some 
other form (for example, by specifying the whole invocation inside the results 
file - if we want to use YAML).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46602



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


[PATCH] D45416: [AST, analyzer] Transform rvalue cast outputs to lvalues (fheinous-gnu-extensions)

2018-05-14 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Gentle ping.


Repository:
  rC Clang

https://reviews.llvm.org/D45416



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


[PATCH] D46758: [clang-format] Move #include related style to libToolingCore

2018-05-14 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 146598.
ioeric marked an inline comment as done.
ioeric added a comment.

- Remove an unintended change.


Repository:
  rC Clang

https://reviews.llvm.org/D46758

Files:
  include/clang/Format/Format.h
  include/clang/Tooling/Core/IncludeStyle.h
  lib/Format/Format.cpp
  lib/Tooling/Core/CMakeLists.txt
  lib/Tooling/Core/IncludeStyle.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -26,12 +26,12 @@
 
   std::string sort(StringRef Code, std::vector Ranges,
StringRef FileName = "input.cc") {
-auto Replaces = sortIncludes(Style, Code, Ranges, FileName);
+auto Replaces = sortIncludes(FmtStyle, Code, Ranges, FileName);
 Ranges = tooling::calculateRangesAfterReplacements(Replaces, Ranges);
 auto Sorted = applyAllReplacements(Code, Replaces);
 EXPECT_TRUE(static_cast(Sorted));
 auto Result = applyAllReplacements(
-*Sorted, reformat(Style, *Sorted, Ranges, FileName));
+*Sorted, reformat(FmtStyle, *Sorted, Ranges, FileName));
 EXPECT_TRUE(static_cast(Result));
 return *Result;
   }
@@ -41,12 +41,12 @@
   }
 
   unsigned newCursor(llvm::StringRef Code, unsigned Cursor) {
-sortIncludes(Style, Code, GetCodeRange(Code), "input.cpp", );
+sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.cpp", );
 return Cursor;
   }
 
-  FormatStyle Style = getLLVMStyle();
-
+  FormatStyle FmtStyle = getLLVMStyle();
+  tooling::IncludeStyle  = FmtStyle.IncludeStyle;
 };
 
 TEST_F(SortIncludesTest, BasicSorting) {
@@ -74,11 +74,11 @@
  "#include \n"
  "#include \n"
  "#include \n";
-  EXPECT_TRUE(sortIncludes(Style, Code, GetCodeRange(Code), "a.cc").empty());
+  EXPECT_TRUE(sortIncludes(FmtStyle, Code, GetCodeRange(Code), "a.cc").empty());
 }
 
 TEST_F(SortIncludesTest, SortedIncludesInMultipleBlocksAreMerged) {
-  Style.IncludeBlocks = FormatStyle::IBS_Merge;
+  Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
   EXPECT_EQ("#include \"a.h\"\n"
 "#include \"b.h\"\n"
 "#include \"c.h\"\n",
@@ -88,7 +88,7 @@
  "\n"
  "#include \"b.h\"\n"));
 
-  Style.IncludeBlocks = FormatStyle::IBS_Regroup;
+  Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
   EXPECT_EQ("#include \"a.h\"\n"
 "#include \"b.h\"\n"
 "#include \"c.h\"\n",
@@ -119,7 +119,7 @@
 }
 
 TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) {
-  Style.SortIncludes = false;
+  FmtStyle.SortIncludes = false;
   EXPECT_EQ("#include \"a.h\"\n"
 "#include \"c.h\"\n"
 "#include \"b.h\"\n",
@@ -182,7 +182,7 @@
 }
 
 TEST_F(SortIncludesTest, SortsAllBlocksWhenMerging) {
-  Style.IncludeBlocks = FormatStyle::IBS_Merge;
+  Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
   EXPECT_EQ("#include \"a.h\"\n"
 "#include \"b.h\"\n"
 "#include \"c.h\"\n",
@@ -202,7 +202,7 @@
  "// comment\n"
  "#include \"b.h\"\n"));
 
-  Style.IncludeBlocks = FormatStyle::IBS_Merge;
+  Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
   EXPECT_EQ("#include \"a.h\"\n"
 "#include \"c.h\"\n"
 "// comment\n"
@@ -212,7 +212,7 @@
  "// comment\n"
  "#include \"b.h\"\n"));
 
-  Style.IncludeBlocks = FormatStyle::IBS_Regroup;
+  Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
   EXPECT_EQ("#include \"a.h\"\n"
 "#include \"c.h\"\n"
 "// comment\n"
@@ -233,7 +233,7 @@
  "#include \"c.h\"\n"
  "#include \"a.h\"\n"));
 
-  Style = getGoogleStyle(FormatStyle::LK_Cpp);
+  FmtStyle = getGoogleStyle(FormatStyle::LK_Cpp);
   EXPECT_EQ("#include \n"
 "#include \n"
 "#include \"a.h\"\n"
@@ -245,7 +245,7 @@
 }
 
 TEST_F(SortIncludesTest, RegroupsAngledIncludesInSeparateBlocks) {
-  Style.IncludeBlocks = FormatStyle::IBS_Regroup;
+  Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
   EXPECT_EQ("#include \"a.h\"\n"
 "#include \"c.h\"\n"
 "\n"
@@ -345,7 +345,7 @@
 
 TEST_F(SortIncludesTest, RecognizeMainHeaderInAllGroups) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
-  Style.IncludeBlocks = FormatStyle::IBS_Merge;
+  Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
 
   EXPECT_EQ("#include \"c.h\"\n"
 "#include \"a.h\"\n"
@@ -359,7 +359,7 @@
 
 TEST_F(SortIncludesTest, MainHeaderIsSeparatedWhenRegroupping) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
-  Style.IncludeBlocks = FormatStyle::IBS_Regroup;
+  Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
 
   EXPECT_EQ("#include \"a.h\"\n"
 "\n"
@@ 

[PATCH] D46758: [clang-format] Move #include related style to libToolingCore

2018-05-14 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: lib/Format/Format.cpp:2277
 auto Replace =
-Includes.insert(trimInclude(IncludeName), IncludeName.startswith("<"));
+Includes.insert(IncludeName.trim("\"<>"), IncludeName.startswith("<"));
 if (Replace) {

ilya-biryukov wrote:
> This change seems unrelated. Is this patch a proper place for it?
Indeed this was unrelated. I forgot to revert this when splitting from a 
previous patch.


Repository:
  rC Clang

https://reviews.llvm.org/D46758



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


  1   2   >