[PATCH] D87981: [X86] AMX programming model prototype.

2020-11-06 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke updated this revision to Diff 303345.
LuoYuanke added a comment.

Fix lit test failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87981

Files:
  clang/include/clang/Basic/BuiltinsX86_64.def
  clang/lib/Headers/amxintrin.h
  clang/test/CodeGen/X86/amx_api.c
  llvm/include/llvm/CodeGen/LiveIntervalUnion.h
  llvm/include/llvm/CodeGen/LiveRegMatrix.h
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/CodeGen/TileShapeInfo.h
  llvm/include/llvm/CodeGen/VirtRegMap.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/lib/CodeGen/InlineSpiller.cpp
  llvm/lib/CodeGen/LiveIntervalUnion.cpp
  llvm/lib/CodeGen/LiveRegMatrix.cpp
  llvm/lib/CodeGen/VirtRegMap.cpp
  llvm/lib/Target/X86/CMakeLists.txt
  llvm/lib/Target/X86/X86.h
  llvm/lib/Target/X86/X86ExpandPseudo.cpp
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86InstrAMX.td
  llvm/lib/Target/X86/X86InstrInfo.cpp
  llvm/lib/Target/X86/X86LowerAMXType.cpp
  llvm/lib/Target/X86/X86PreTileConfig.cpp
  llvm/lib/Target/X86/X86RegisterInfo.cpp
  llvm/lib/Target/X86/X86RegisterInfo.h
  llvm/lib/Target/X86/X86RegisterInfo.td
  llvm/lib/Target/X86/X86Subtarget.h
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Target/X86/X86TileConfig.cpp
  llvm/test/CodeGen/X86/AMX/amx-across-func.ll
  llvm/test/CodeGen/X86/AMX/amx-config.ll
  llvm/test/CodeGen/X86/AMX/amx-spill.ll
  llvm/test/CodeGen/X86/AMX/amx-type.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/ipra-reg-usage.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll
  llvm/test/CodeGen/X86/statepoint-fixup-invoke.mir
  llvm/test/CodeGen/X86/statepoint-fixup-shared-ehpad.mir

Index: llvm/test/CodeGen/X86/statepoint-fixup-shared-ehpad.mir
===
--- llvm/test/CodeGen/X86/statepoint-fixup-shared-ehpad.mir
+++ llvm/test/CodeGen/X86/statepoint-fixup-shared-ehpad.mir
@@ -108,7 +108,7 @@
   ; CHECK:   ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
   ; CHECK:   MOV64mr [[STACK0:%stack.[0-9]+]], 1, $noreg, 0, $noreg, killed $rbx :: (store 8 into [[STACK0]])
   ; CHECK:   MOV64mr [[STACK1:%stack.[0-9]+]], 1, $noreg, 0, $noreg, killed $r14 :: (store 8 into [[STACK1]])
-  ; CHECK:   STATEPOINT 0, 0, 0, @foo, 2, 0, 2, 0, 2, 0, 2, 2, 1, 8, [[STACK0]], 0, 1, 8, [[STACK1]], 0, 2, 0, 2, 2, 0, 0, 1, 1, csr_64, implicit-def $rsp, implicit-def $ssp :: (load store 8 on [[STACK0]]), (load store 8 on [[STACK1]])
+  ; CHECK:   STATEPOINT 0, 0, 0, @foo, 2, 0, 2, 0, 2, 0, 2, 2, 1, 8, [[STACK0]], 0, 1, 8, [[STACK1]], 0, 2, 0, 2, 2, 0, 0, 1, 1, csr_64, implicit-def $rsp, implicit-def $ssp :: (load store 8 on [[STACK1]]), (load store 8 on [[STACK0]])
   ; CHECK-DAG:   $rbx = MOV64rm [[STACK0]], 1, $noreg, 0, $noreg :: (load 8 from [[STACK0]])
   ; CHECK-DAG:   $r14 = MOV64rm [[STACK1]], 1, $noreg, 0, $noreg :: (load 8 from [[STACK1]])
   ; CHECK:   ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
@@ -121,7 +121,7 @@
   ; CHECK:   ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
   ; CHECK-DAG:   MOV64mr [[STACK0]], 1, $noreg, 0, $noreg, killed $rbx :: (store 8 into [[STACK0]])
   ; CHECK-DAG:   MOV64mr [[STACK1]], 1, $noreg, 0, $noreg, killed $r14 :: (store 8 into [[STACK1]])
-  ; CHECK:   STATEPOINT 0, 0, 0, @bar, 2, 0, 2, 0, 2, 0, 2, 2, 1, 8, %stack.0, 0, 1, 8, [[STACK1]], 0, 2, 0, 2, 2, 0, 0, 1, 1, csr_64, implicit-def $rsp, implicit-def $ssp :: (load store 8 on [[STACK0]]), (load store 8 on [[STACK1]])
+  ; CHECK:   STATEPOINT 0, 0, 0, @bar, 2, 0, 2, 0, 2, 0, 2, 2, 1, 8, %stack.0, 0, 1, 8, [[STACK1]], 0, 2, 0, 2, 2, 0, 0, 1, 1, csr_64, implicit-def $rsp, implicit-def $ssp :: (load store 8 on [[STACK1]]), (load store 8 on [[STACK0]])
   ; CHECK-DAG:   $rbx = MOV64rm [[STACK0]], 1, $noreg, 0, $noreg :: (load 8 from [[STACK0]])
   ; CHECK-DAG:   $r14 = MOV64rm [[STACK1]], 1, $noreg, 0, $noreg :: (load 8 from [[STACK1]])
   ; CHECK:   ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
Index: llvm/test/CodeGen/X86/statepoint-fixup-invoke.mir
===
--- llvm/test/CodeGen/X86/statepoint-fixup-invoke.mir
+++ llvm/test/CodeGen/X86/statepoint-fixup-invoke.mir
@@ -91,7 +91,7 @@
   ; CHECK-DAG:   MOV64mr %stack.1, 1, $noreg, 0, $noreg, $rdi :: (store 8 into %stack.1)
   ; CHECK:   EH_LABEL 
   ; CHECK:   ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
-  ; CHECK:   STATEPOINT 0, 0, 1, @some_call, $rdi, 2, 0, 2, 0, 2, 5, 2, 0, 2, -1, 

[PATCH] D90822: [X86] use macros to split GFNI intrinsics into different kinds

2020-11-06 Thread Freddy, Ye via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5e312e004197: [X86] use macros to split GFNI intrinsics into 
different kinds (authored by FreddyYe).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90822

Files:
  clang/lib/Headers/gfniintrin.h

Index: clang/lib/Headers/gfniintrin.h
===
--- clang/lib/Headers/gfniintrin.h
+++ clang/lib/Headers/gfniintrin.h
@@ -14,38 +14,56 @@
 #ifndef __GFNIINTRIN_H
 #define __GFNIINTRIN_H
 
+/* Default attributes for simple form (no masking). */
+#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("gfni"), __min_vector_width__(128)))
+
+/* Default attributes for YMM unmasked form. */
+#define __DEFAULT_FN_ATTRS_Y __attribute__((__always_inline__, __nodebug__, __target__("avx,gfni"), __min_vector_width__(256)))
+
+/* Default attributes for ZMM forms. */
+#define __DEFAULT_FN_ATTRS_Z __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,gfni"), __min_vector_width__(512)))
+
+/* Default attributes for VLX forms. */
+#define __DEFAULT_FN_ATTRS_VL128 __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,avx512vl,gfni"), __min_vector_width__(128)))
+#define __DEFAULT_FN_ATTRS_VL256 __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,avx512vl,gfni"), __min_vector_width__(256)))
 
 #define _mm_gf2p8affineinv_epi64_epi8(A, B, I) \
   (__m128i)__builtin_ia32_vgf2p8affineinvqb_v16qi((__v16qi)(__m128i)(A),  \
   (__v16qi)(__m128i)(B),  \
   (char)(I))
 
-#define _mm_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \
-  (__m128i)__builtin_ia32_selectb_128((__mmask16)(U), \
-(__v16qi)_mm_gf2p8affineinv_epi64_epi8(A, B, I),  \
-(__v16qi)(__m128i)(S))
-
-
-#define _mm_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \
-  (__m128i)_mm_mask_gf2p8affineinv_epi64_epi8((__m128i)_mm_setzero_si128(),   \
-U, A, B, I)
+#define _mm_gf2p8affine_epi64_epi8(A, B, I) \
+  (__m128i)__builtin_ia32_vgf2p8affineqb_v16qi((__v16qi)(__m128i)(A), \
+  (__v16qi)(__m128i)(B),  \
+  (char)(I))
 
+static __inline__ __m128i __DEFAULT_FN_ATTRS
+_mm_gf2p8mul_epi8(__m128i __A, __m128i __B)
+{
+  return (__m128i) __builtin_ia32_vgf2p8mulb_v16qi((__v16qi) __A,
+  (__v16qi) __B);
+}
 
+#ifdef __AVXINTRIN_H
 #define _mm256_gf2p8affineinv_epi64_epi8(A, B, I) \
   (__m256i)__builtin_ia32_vgf2p8affineinvqb_v32qi((__v32qi)(__m256i)(A),  \
   (__v32qi)(__m256i)(B),  \
   (char)(I))
 
-#define _mm256_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \
-   (__m256i)__builtin_ia32_selectb_256((__mmask32)(U),\
-(__v32qi)_mm256_gf2p8affineinv_epi64_epi8(A, B, I),   \
-(__v32qi)(__m256i)(S))
-
-#define _mm256_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \
-  (__m256i)_mm256_mask_gf2p8affineinv_epi64_epi8((__m256i)_mm256_setzero_si256(), \
-U, A, B, I)
+#define _mm256_gf2p8affine_epi64_epi8(A, B, I) \
+  (__m256i)__builtin_ia32_vgf2p8affineqb_v32qi((__v32qi)(__m256i)(A), \
+  (__v32qi)(__m256i)(B),  \
+  (char)(I))
 
+static __inline__ __m256i __DEFAULT_FN_ATTRS_Y
+_mm256_gf2p8mul_epi8(__m256i __A, __m256i __B)
+{
+  return (__m256i) __builtin_ia32_vgf2p8mulb_v32qi((__v32qi) __A,
+  (__v32qi) __B);
+}
+#endif /* __AVXINTRIN_H */
 
+#ifdef __AVX512BWINTRIN_H
 #define _mm512_gf2p8affineinv_epi64_epi8(A, B, I) \
   (__m512i)__builtin_ia32_vgf2p8affineinvqb_v64qi((__v64qi)(__m512i)(A),  \
   (__v64qi)(__m512i)(B),  \
@@ -60,27 +78,71 @@
   (__m512i)_mm512_mask_gf2p8affineinv_epi64_epi8((__m512i)_mm512_setzero_si512(),\
 U, A, B, I)
 
-#define _mm_gf2p8affine_epi64_epi8(A, B, I) \
-  (__m128i)__builtin_ia32_vgf2p8affineqb_v16qi((__v16qi)(__m128i)(A), \
-  (__v16qi)(__m128i)(B),  \
+#define _mm512_gf2p8affine_epi64_epi8(A, B, I) \
+  (__m512i)__builtin_ia32_vgf2p8affineqb_v64qi((__v64qi)(__m512i)(A), \
+  (__v64qi)(__m512i)(B),  \
   (char)(I))
 
+#define _mm512_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) \
+   (__m512i)__builtin_ia32_selectb_512((__mmask64)

[clang] 5e312e0 - [X86] use macros to split GFNI intrinsics into different kinds

2020-11-06 Thread Freddy Ye via cfe-commits

Author: Freddy Ye
Date: 2020-11-06T16:03:38+08:00
New Revision: 5e312e0041972668f1bd67ff9ed0f16a594795a3

URL: 
https://github.com/llvm/llvm-project/commit/5e312e0041972668f1bd67ff9ed0f16a594795a3
DIFF: 
https://github.com/llvm/llvm-project/commit/5e312e0041972668f1bd67ff9ed0f16a594795a3.diff

LOG: [X86] use macros to split GFNI intrinsics into different kinds

Tremont microarchitecture only has GFNI(SSE) version, not AVX and
AVX512 version. This patch is to avoid compiling fail on Windows when
using -march=tremont to invoke one of GFNI(SSE) intrinsic.

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

Added: 


Modified: 
clang/lib/Headers/gfniintrin.h

Removed: 




diff  --git a/clang/lib/Headers/gfniintrin.h b/clang/lib/Headers/gfniintrin.h
index 9bff0fcb603e..11a321b7c919 100644
--- a/clang/lib/Headers/gfniintrin.h
+++ b/clang/lib/Headers/gfniintrin.h
@@ -14,38 +14,56 @@
 #ifndef __GFNIINTRIN_H
 #define __GFNIINTRIN_H
 
+/* Default attributes for simple form (no masking). */
+#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("gfni"), __min_vector_width__(128)))
+
+/* Default attributes for YMM unmasked form. */
+#define __DEFAULT_FN_ATTRS_Y __attribute__((__always_inline__, __nodebug__, 
__target__("avx,gfni"), __min_vector_width__(256)))
+
+/* Default attributes for ZMM forms. */
+#define __DEFAULT_FN_ATTRS_Z __attribute__((__always_inline__, __nodebug__, 
__target__("avx512bw,gfni"), __min_vector_width__(512)))
+
+/* Default attributes for VLX forms. */
+#define __DEFAULT_FN_ATTRS_VL128 __attribute__((__always_inline__, 
__nodebug__, __target__("avx512bw,avx512vl,gfni"), __min_vector_width__(128)))
+#define __DEFAULT_FN_ATTRS_VL256 __attribute__((__always_inline__, 
__nodebug__, __target__("avx512bw,avx512vl,gfni"), __min_vector_width__(256)))
 
 #define _mm_gf2p8affineinv_epi64_epi8(A, B, I) \
   (__m128i)__builtin_ia32_vgf2p8affineinvqb_v16qi((__v16qi)(__m128i)(A),   
   \
   (__v16qi)(__m128i)(B),   
   \
   (char)(I))
 
-#define _mm_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \
-  (__m128i)__builtin_ia32_selectb_128((__mmask16)(U),  
   \
-(__v16qi)_mm_gf2p8affineinv_epi64_epi8(A, B, I),   
   \
-(__v16qi)(__m128i)(S))
-
-
-#define _mm_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \
-  (__m128i)_mm_mask_gf2p8affineinv_epi64_epi8((__m128i)_mm_setzero_si128(),
   \
-U, A, B, I)
+#define _mm_gf2p8affine_epi64_epi8(A, B, I) \
+  (__m128i)__builtin_ia32_vgf2p8affineqb_v16qi((__v16qi)(__m128i)(A),  
   \
+  (__v16qi)(__m128i)(B),   
   \
+  (char)(I))
 
+static __inline__ __m128i __DEFAULT_FN_ATTRS
+_mm_gf2p8mul_epi8(__m128i __A, __m128i __B)
+{
+  return (__m128i) __builtin_ia32_vgf2p8mulb_v16qi((__v16qi) __A,
+  (__v16qi) __B);
+}
 
+#ifdef __AVXINTRIN_H
 #define _mm256_gf2p8affineinv_epi64_epi8(A, B, I) \
   (__m256i)__builtin_ia32_vgf2p8affineinvqb_v32qi((__v32qi)(__m256i)(A),   
   \
   (__v32qi)(__m256i)(B),   
   \
   (char)(I))
 
-#define _mm256_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \
-   (__m256i)__builtin_ia32_selectb_256((__mmask32)(U), 
   \
-(__v32qi)_mm256_gf2p8affineinv_epi64_epi8(A, B, I),
   \
-(__v32qi)(__m256i)(S))
-
-#define _mm256_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \
-  
(__m256i)_mm256_mask_gf2p8affineinv_epi64_epi8((__m256i)_mm256_setzero_si256(), 
\
-U, A, B, I)
+#define _mm256_gf2p8affine_epi64_epi8(A, B, I) \
+  (__m256i)__builtin_ia32_vgf2p8affineqb_v32qi((__v32qi)(__m256i)(A),  
   \
+  (__v32qi)(__m256i)(B),   
   \
+  (char)(I))
 
+static __inline__ __m256i __DEFAULT_FN_ATTRS_Y
+_mm256_gf2p8mul_epi8(__m256i __A, __m256i __B)
+{
+  return (__m256i) __builtin_ia32_vgf2p8mulb_v32qi((__v32qi) __A,
+  (__v32qi) __B);
+}
+#endif /* __AVXINTRIN_H */
 
+#ifdef __AVX512BWINTRIN_H
 #define _mm512_gf2p8affineinv_epi64_epi8(A, B, I) \
   (__m512i)__builtin_ia32_vgf2p8affineinvqb_v64qi((__v64qi)(__m512i)(A),   
   \
   (__v64qi)(__m512i)(B),   
   \
@@ -60,27 +78,71 @@
   
(__m512i)_mm512_mask_gf2p8affineinv_epi64_epi8((__m512i)_mm512_setzero_si512(), 
   \
 U, A, B, I)
 
-#define _mm_gf2p8affine_epi64_epi8(A, B, I) \
-  (__m128i)__builtin_ia32_vgf2p8affineqb_v16qi((__v16qi)(__m128i)(A),  
   \
-  (__v16qi)(__m128i)(B),   
   \
+#define 

[PATCH] D90908: [clang-format] do not break before { in JS comments

2020-11-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
krasimir requested review of this revision.

In JavaScript some @tags can be followed by `{`, and machinery that parses
these comments will fail to understand the comment if followed by a line break.

clang-format already handles this case by not breaking before `{` in comments.
However this was not working in cases when the column limit falls within `@tag`
or between `@tag` and `{`. This adapts clang-format for this case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90908

Files:
  clang/lib/Format/BreakableToken.cpp
  clang/unittests/Format/FormatTestJS.cpp


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2184,6 +2184,16 @@
" * @lala {lala {lalala\n"
" */\n",
getGoogleJSStyleWithColumns(20));
+  // cases where '{' is around the column limit
+  for (int ColumnLimit = 6; ColumnLimit < 10; ++ColumnLimit) {
+verifyFormat("/**\n"
+ " * @param {type}\n"
+ " */",
+ "/**\n"
+ " * @param {type}\n"
+ " */",
+ getGoogleJSStyleWithColumns(ColumnLimit));
+  }
   verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n";
" */",
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -86,6 +86,18 @@
 MaxSplitBytes += BytesInChar;
   }
 
+  // In JavaScript, some @tags can be followed by {, and machinery that parses
+  // these comments will fail to understand the comment if followed by a line
+  // break. So avoid ever breaking before a {.
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+StringRef::size_type SpaceOffset =
+Text.find_first_of(Blanks, MaxSplitBytes);
+if (SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
+Text[SpaceOffset + 1] == '{') {
+  MaxSplitBytes = SpaceOffset + 1;
+}
+  }
+
   StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
 
   static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
@@ -94,9 +106,7 @@
 // as a numbered list, which would prevent re-flowing in subsequent passes.
 if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks)))
   SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
-// In JavaScript, some @tags can be followed by {, and machinery that 
parses
-// these comments will fail to understand the comment if followed by a line
-// break. So avoid ever breaking before a {.
+// Avoid ever breaking before a { in JavaScript.
 else if (Style.Language == FormatStyle::LK_JavaScript &&
  SpaceOffset + 1 < Text.size() && Text[SpaceOffset + 1] == '{')
   SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2184,6 +2184,16 @@
" * @lala {lala {lalala\n"
" */\n",
getGoogleJSStyleWithColumns(20));
+  // cases where '{' is around the column limit
+  for (int ColumnLimit = 6; ColumnLimit < 10; ++ColumnLimit) {
+verifyFormat("/**\n"
+ " * @param {type}\n"
+ " */",
+ "/**\n"
+ " * @param {type}\n"
+ " */",
+ getGoogleJSStyleWithColumns(ColumnLimit));
+  }
   verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n";
" */",
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -86,6 +86,18 @@
 MaxSplitBytes += BytesInChar;
   }
 
+  // In JavaScript, some @tags can be followed by {, and machinery that parses
+  // these comments will fail to understand the comment if followed by a line
+  // break. So avoid ever breaking before a {.
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+StringRef::size_type SpaceOffset =
+Text.find_first_of(Blanks, MaxSplitBytes);
+if (SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
+Text[SpaceOffset + 1] == '{') {
+  MaxSplitBytes = SpaceOffset + 1;
+}
+  }
+
   StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
 
   static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
@@ -94,9 +106,7 @@
 // as a numbered list, which would prevent re-flowing in subsequent passes.
 

[PATCH] D90908: [clang-format] do not break before { in JS comments

2020-11-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 303354.
krasimir added a comment.

update test case range


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90908

Files:
  clang/unittests/Format/FormatTestJS.cpp


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2185,7 +2185,7 @@
" */\n",
getGoogleJSStyleWithColumns(20));
   // cases where '{' is around the column limit
-  for (int ColumnLimit = 6; ColumnLimit < 10; ++ColumnLimit) {
+  for (int ColumnLimit = 6; ColumnLimit < 13; ++ColumnLimit) {
 verifyFormat("/**\n"
  " * @param {type}\n"
  " */",


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2185,7 +2185,7 @@
" */\n",
getGoogleJSStyleWithColumns(20));
   // cases where '{' is around the column limit
-  for (int ColumnLimit = 6; ColumnLimit < 10; ++ColumnLimit) {
+  for (int ColumnLimit = 6; ColumnLimit < 13; ++ColumnLimit) {
 verifyFormat("/**\n"
  " * @param {type}\n"
  " */",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90908: [clang-format] do not break before { in JS comments

2020-11-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 303355.
krasimir added a comment.

collect commits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90908

Files:
  clang/lib/Format/BreakableToken.cpp
  clang/unittests/Format/FormatTestJS.cpp


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2184,6 +2184,16 @@
" * @lala {lala {lalala\n"
" */\n",
getGoogleJSStyleWithColumns(20));
+  // cases where '{' is around the column limit
+  for (int ColumnLimit = 6; ColumnLimit < 13; ++ColumnLimit) {
+verifyFormat("/**\n"
+ " * @param {type}\n"
+ " */",
+ "/**\n"
+ " * @param {type}\n"
+ " */",
+ getGoogleJSStyleWithColumns(ColumnLimit));
+  }
   verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n";
" */",
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -86,6 +86,18 @@
 MaxSplitBytes += BytesInChar;
   }
 
+  // In JavaScript, some @tags can be followed by {, and machinery that parses
+  // these comments will fail to understand the comment if followed by a line
+  // break. So avoid ever breaking before a {.
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+StringRef::size_type SpaceOffset =
+Text.find_first_of(Blanks, MaxSplitBytes);
+if (SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
+Text[SpaceOffset + 1] == '{') {
+  MaxSplitBytes = SpaceOffset + 1;
+}
+  }
+
   StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
 
   static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
@@ -94,9 +106,7 @@
 // as a numbered list, which would prevent re-flowing in subsequent passes.
 if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks)))
   SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
-// In JavaScript, some @tags can be followed by {, and machinery that 
parses
-// these comments will fail to understand the comment if followed by a line
-// break. So avoid ever breaking before a {.
+// Avoid ever breaking before a { in JavaScript.
 else if (Style.Language == FormatStyle::LK_JavaScript &&
  SpaceOffset + 1 < Text.size() && Text[SpaceOffset + 1] == '{')
   SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2184,6 +2184,16 @@
" * @lala {lala {lalala\n"
" */\n",
getGoogleJSStyleWithColumns(20));
+  // cases where '{' is around the column limit
+  for (int ColumnLimit = 6; ColumnLimit < 13; ++ColumnLimit) {
+verifyFormat("/**\n"
+ " * @param {type}\n"
+ " */",
+ "/**\n"
+ " * @param {type}\n"
+ " */",
+ getGoogleJSStyleWithColumns(ColumnLimit));
+  }
   verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n";
" */",
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -86,6 +86,18 @@
 MaxSplitBytes += BytesInChar;
   }
 
+  // In JavaScript, some @tags can be followed by {, and machinery that parses
+  // these comments will fail to understand the comment if followed by a line
+  // break. So avoid ever breaking before a {.
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+StringRef::size_type SpaceOffset =
+Text.find_first_of(Blanks, MaxSplitBytes);
+if (SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
+Text[SpaceOffset + 1] == '{') {
+  MaxSplitBytes = SpaceOffset + 1;
+}
+  }
+
   StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
 
   static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
@@ -94,9 +106,7 @@
 // as a numbered list, which would prevent re-flowing in subsequent passes.
 if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks)))
   SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
-// In JavaScript, some @tags can be followed by {, and machinery that parses
-// these comments will fail to understand the comment if followed by a line
-// break. So avoid ever breaking before a {.
+// Avoid ever breaking b

[PATCH] D90851: [clang-tidy] Extending bugprone-signal-handler with POSIX functions.

2020-11-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 303356.
balazske added a comment.

Small fixes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90851

Files:
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
  clang-tools-extra/docs/clang-tidy/checks/bugprone-signal-handler.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-posix-api.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-minimal.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
@@ -1,8 +1,8 @@
-// RUN: %check_clang_tidy %s cert-sig30-c %t -- -- -isystem %S/Inputs/Headers
+// RUN: %check_clang_tidy %s bugprone-signal-handler %t -- -- -isystem %S/Inputs/Headers
 
-#include "signal.h"
 #include "stdio.h"
-#include "stdlib.h"
+#include "system-header-posix-api.h"
+#include "system-other.h"
 
 // The function should be classified as system call even if there is
 // declaration the in source file.
@@ -16,17 +16,9 @@
   abort();
 }
 
-void handler__Exit(int) {
-  _Exit(0);
-}
-
-void handler_quick_exit(int) {
-  quick_exit(0);
-}
-
 void handler_other(int) {
   printf("1234");
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void handler_signal(int) {
@@ -40,7 +32,7 @@
 
 void f_bad() {
   printf("1234");
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void f_extern();
@@ -55,13 +47,11 @@
 
 void handler_extern(int) {
   f_extern();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void test() {
   signal(SIGINT, handler_abort);
-  signal(SIGINT, handler__Exit);
-  signal(SIGINT, handler_quick_exit);
   signal(SIGINT, handler_signal);
   signal(SIGINT, handler_other);
 
@@ -69,9 +59,9 @@
   signal(SIGINT, handler_bad);
   signal(SIGINT, handler_extern);
 
-  signal(SIGINT, quick_exit);
+  signal(SIGINT, _Exit);
   signal(SIGINT, other_call);
-  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 
   signal(SIGINT, SIG_IGN);
   signal(SIGINT, SIG_DFL);
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s bugprone-signal-handler %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: bugprone-signal-handler.AsyncSafeFunctionSet, value: "POSIX"}]}' \
+// RUN: -- -isystem %S/Inputs/Headers
+
+#include "stdio.h"
+#include "system-header-posix-api.h"
+
+void handler_bad1(int) {
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+}
+
+void handler_bad2(int) {
+  quick_exit(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'quick_exit' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+}
+
+void handler_good1(int) {
+  _exit(0);
+  accept(1, 0, 0);
+  write(0, 0, 0);
+}
+
+void handler_good2(int) {
+  abort();
+  _Exit(0);
+  signal(0, SIG_DFL);
+}
+
+void test() {
+  signal(SIGINT, handler_good1);
+  signal(SIGINT, handler_good2);
+  signal(SIGINT, handler_bad1);
+  signal(SIGINT, handler_bad

[PATCH] D90809: [amdgpu] Add `llvm.amdgcn.endpgm` support.

2020-11-06 Thread Jay Foad via Phabricator via cfe-commits
foad added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsAMDGPU.td:1580
 
+def int_amdgcn_endpgm : GCCBuiltin<"__builtin_amdgcn_endpgm">,
+  Intrinsic<[], [], [IntrNoReturn, IntrCold, IntrNoMem, IntrHasSideEffects]

The intrinsic def needs a comment. Is it supposed to literally just generate an 
s_endpgm instruction, or is it something more high-level?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90809

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


[PATCH] D90552: [clangd] Set the User option for clang-tidy to mimick its behaviour

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

Still LG




Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:812
+EmptyDefaults.User = llvm::sys::Process::GetEnv("USER");
+if (!EmptyDefaults.User)
+  EmptyDefaults.User = llvm::sys::Process::GetEnv("USEUSERNAMER");

njames93 wrote:
> sammccall wrote:
> > do you think we should #ifdef this for windows?
> > 
> > maybe like
> > ```
> > User = llvm::sys::Process::GetEnv(
> > #ifdef _WIN32
> > "USERNAME"
> > #else
> > "USER"
> > )
> > ```
> > 
> > (or maybe always query USER but only query USERNAME on windows, or 
> > something else?)
> I'm not too sure how nicely that would play when using clang with mingw. 
> given there is no harm in calling both I'd rather ere on the safe side.
OK. I'd still suggest #ifdefing the USERNAME part, since that's not meaningful 
in any sense outside windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90552

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


[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-06 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

> I guess targets like SPIR will be supporting all features by default?

It sounds confusing for me: can you please elaborate about why does SPIR-V 
target should support all features/extension by default? If we are compiling 
OpenCL C 3.0 with optional functionality we most likely want to get an error in 
FE level if some functionality is not supported by the target, but not in BE 
after SPIR-V translation.




Comment at: clang/include/clang/Basic/OpenCLExtensions.def:110
+OPENCLFEAT_INTERNAL(__opencl_c_generic_address_space, 200, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_work_group_collective_functions, 200, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_atomic_order_acq_rel, 200, ~0U)

Anastasia wrote:
> Does this need to be in the frontend?
I can remove features which affect only header from this file. But in this case 
we need to extend '-cl-ext' to register unknown features/extensions 
(http://lists.llvm.org/pipermail/cfe-dev/2020-October/066932.html). I think 
this option functionality extending should be done in a separate commit, so we 
can keep this kind of features here at least for now. What do you think?



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:121
+OPENCLFEAT_INTERNAL(__opencl_c_fp64, 120, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_int64, 100, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_images, 100, ~0U)

Anastasia wrote:
> if we are not going to change clang to make int64 conditional I would suggest 
> we don't add this here for now.
Yes, that sounds reasonable to be.



Comment at: clang/include/clang/Basic/OpenCLOptions.h:105
 }
 OptMap[Ext].Supported = V;
   }

Anastasia wrote:
> I guess we need to make sure that targets can't conditionally support 
> features in OpenCL 2.0 or earlier standards.
This can be done by adding a new method 
//TargetInfo::setSupportedOpenCL30Features()// which can be called in 
//::adjust//, does this make sense? I believe now current  options setting 
(//TargetInfo::setSupportedOpenCLOpts()//) knows nothing about OpenCL version 
which.



Comment at: clang/lib/Frontend/CompilerInstance.cpp:950
+  if (getLangOpts().OpenCL)
+getTarget().getSupportedOpenCLOpts().adjustFeatures(getLangOpts());
+

Anastasia wrote:
> Would it be possible to move this into `getTarget().adjust(getLangOpts())` 
> just below. There is a FIXME that explains that we should be doing such 
> adjustment differently but we haven't solved it with time so let's keep the 
> flow as is for now. 
Yeah, this can be moved there. Btw a lot of OpenCL C 3.0 options setting will 
take place in //::adjust//...



Comment at: clang/test/Preprocessor/opencl-feature-extension-simult.cl:15
+
+// RUN: %clang_cc1 %s -E -cl-std=CL3.0 -cl-ext=-all__opencl_c_fp64
+// RUN: %clang_cc1 %s -E -cl-std=CL3.0 -cl-ext=+__opencl_c_fp64

Anastasia wrote:
> Is this a typo?
> 
> `all__opencl_c_fp64`
Ah, yeah, thanks, Will definitely change that.


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

https://reviews.llvm.org/D89869

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


[PATCH] D90908: [clang-format] do not break before { in JS comments

2020-11-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2dbcbd357d1d: [clang-format] do not break before { in JS 
comments (authored by krasimir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90908

Files:
  clang/lib/Format/BreakableToken.cpp
  clang/unittests/Format/FormatTestJS.cpp


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2184,6 +2184,16 @@
" * @lala {lala {lalala\n"
" */\n",
getGoogleJSStyleWithColumns(20));
+  // cases where '{' is around the column limit
+  for (int ColumnLimit = 6; ColumnLimit < 13; ++ColumnLimit) {
+verifyFormat("/**\n"
+ " * @param {type}\n"
+ " */",
+ "/**\n"
+ " * @param {type}\n"
+ " */",
+ getGoogleJSStyleWithColumns(ColumnLimit));
+  }
   verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n";
" */",
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -86,6 +86,18 @@
 MaxSplitBytes += BytesInChar;
   }
 
+  // In JavaScript, some @tags can be followed by {, and machinery that parses
+  // these comments will fail to understand the comment if followed by a line
+  // break. So avoid ever breaking before a {.
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+StringRef::size_type SpaceOffset =
+Text.find_first_of(Blanks, MaxSplitBytes);
+if (SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
+Text[SpaceOffset + 1] == '{') {
+  MaxSplitBytes = SpaceOffset + 1;
+}
+  }
+
   StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
 
   static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
@@ -94,9 +106,7 @@
 // as a numbered list, which would prevent re-flowing in subsequent passes.
 if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks)))
   SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
-// In JavaScript, some @tags can be followed by {, and machinery that 
parses
-// these comments will fail to understand the comment if followed by a line
-// break. So avoid ever breaking before a {.
+// Avoid ever breaking before a { in JavaScript.
 else if (Style.Language == FormatStyle::LK_JavaScript &&
  SpaceOffset + 1 < Text.size() && Text[SpaceOffset + 1] == '{')
   SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2184,6 +2184,16 @@
" * @lala {lala {lalala\n"
" */\n",
getGoogleJSStyleWithColumns(20));
+  // cases where '{' is around the column limit
+  for (int ColumnLimit = 6; ColumnLimit < 13; ++ColumnLimit) {
+verifyFormat("/**\n"
+ " * @param {type}\n"
+ " */",
+ "/**\n"
+ " * @param {type}\n"
+ " */",
+ getGoogleJSStyleWithColumns(ColumnLimit));
+  }
   verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n";
" */",
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -86,6 +86,18 @@
 MaxSplitBytes += BytesInChar;
   }
 
+  // In JavaScript, some @tags can be followed by {, and machinery that parses
+  // these comments will fail to understand the comment if followed by a line
+  // break. So avoid ever breaking before a {.
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+StringRef::size_type SpaceOffset =
+Text.find_first_of(Blanks, MaxSplitBytes);
+if (SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
+Text[SpaceOffset + 1] == '{') {
+  MaxSplitBytes = SpaceOffset + 1;
+}
+  }
+
   StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
 
   static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
@@ -94,9 +106,7 @@
 // as a numbered list, which would prevent re-flowing in subsequent passes.
 if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks)))
   SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
-// In JavaScript, some @tags can be followed by {, and machinery that parses
-// the

[clang] 2dbcbd3 - [clang-format] do not break before { in JS comments

2020-11-06 Thread Krasimir Georgiev via cfe-commits

Author: Krasimir Georgiev
Date: 2020-11-06T10:34:10+01:00
New Revision: 2dbcbd357d1da1adf9c512d150e68424faa46d75

URL: 
https://github.com/llvm/llvm-project/commit/2dbcbd357d1da1adf9c512d150e68424faa46d75
DIFF: 
https://github.com/llvm/llvm-project/commit/2dbcbd357d1da1adf9c512d150e68424faa46d75.diff

LOG: [clang-format] do not break before { in JS comments

In JavaScript some @tags can be followed by `{`, and machinery that parses
these comments will fail to understand the comment if followed by a line break.

clang-format already handles this case by not breaking before `{` in comments.
However this was not working in cases when the column limit falls within `@tag`
or between `@tag` and `{`. This adapts clang-format for this case.

Reviewed By: mprobst

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

Added: 


Modified: 
clang/lib/Format/BreakableToken.cpp
clang/unittests/Format/FormatTestJS.cpp

Removed: 




diff  --git a/clang/lib/Format/BreakableToken.cpp 
b/clang/lib/Format/BreakableToken.cpp
index 15fbe3b6515d..2ef1540a7f82 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -86,6 +86,18 @@ getCommentSplit(StringRef Text, unsigned ContentStartColumn,
 MaxSplitBytes += BytesInChar;
   }
 
+  // In JavaScript, some @tags can be followed by {, and machinery that parses
+  // these comments will fail to understand the comment if followed by a line
+  // break. So avoid ever breaking before a {.
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+StringRef::size_type SpaceOffset =
+Text.find_first_of(Blanks, MaxSplitBytes);
+if (SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
+Text[SpaceOffset + 1] == '{') {
+  MaxSplitBytes = SpaceOffset + 1;
+}
+  }
+
   StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
 
   static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
@@ -94,9 +106,7 @@ getCommentSplit(StringRef Text, unsigned ContentStartColumn,
 // as a numbered list, which would prevent re-flowing in subsequent passes.
 if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks)))
   SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
-// In JavaScript, some @tags can be followed by {, and machinery that 
parses
-// these comments will fail to understand the comment if followed by a line
-// break. So avoid ever breaking before a {.
+// Avoid ever breaking before a { in JavaScript.
 else if (Style.Language == FormatStyle::LK_JavaScript &&
  SpaceOffset + 1 < Text.size() && Text[SpaceOffset + 1] == '{')
   SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);

diff  --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index da26a9b67278..d140fe581f2a 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -2184,6 +2184,16 @@ TEST_F(FormatTestJS, JSDocAnnotations) {
" * @lala {lala {lalala\n"
" */\n",
getGoogleJSStyleWithColumns(20));
+  // cases where '{' is around the column limit
+  for (int ColumnLimit = 6; ColumnLimit < 13; ++ColumnLimit) {
+verifyFormat("/**\n"
+ " * @param {type}\n"
+ " */",
+ "/**\n"
+ " * @param {type}\n"
+ " */",
+ getGoogleJSStyleWithColumns(ColumnLimit));
+  }
   verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n";
" */",



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


[PATCH] D90531: [clangd] Add clang-tidy options to config

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks! Just some simplifications and doc nits left, then please go ahead and 
land




Comment at: clang-tools-extra/clangd/Config.h:74
+
+  // Configures what clang-tidy checks to run and options to use with them.
+  struct {

nit: we're using triple slash comments for these...



Comment at: clang-tools-extra/clangd/Config.h:77
+bool Enable = true;
+std::string Checks;
+std::vector> CheckOptions;

`Enable` is trivial enough to go without documentation, but the format of 
`Checks` certainly needs to be documented.



Comment at: clang-tools-extra/clangd/Config.h:78
+std::string Checks;
+std::vector> CheckOptions;
+  } ClangTidy;

I think this should be a StringMap

It makes sense to use a vector-of-pairs in ConfigFragment to preserve the 
Located information for keys, but we don't need to do that in Config.



Comment at: clang-tools-extra/clangd/ConfigFragment.h:183
+  struct ClangTidyBlock {
+llvm::Optional> Enable;
+/// List of checks to enable or disable, can use wildcards.

njames93 wrote:
> sammccall wrote:
> > I wonder if it's worth having this when we support `Remove: *`.
> > 
> > technically this does something slightly different:
> >  - it still runs the machinery just with no actual checks
> >  - you can enable: true later to override it, without losing the previously 
> > configured list of checks
> > 
> > Is one of these important? Is there some other benefit?
> > (I'm not opposed to having this if you want it, but I'm curious)
> I'm not 100% sure what you are asking here.
I'm asking whether we really need `Enable`, or whether we should remove it and 
recommend `Remove: *` to disable the checks.

If there isn't a clear reason we need it, my preference is to omit it for 
simplicity (we can add more setting later, but it's harder to remove them).

I don't feel strongly though, this is up to you.



Comment at: clang-tools-extra/clangd/ConfigYAML.cpp:188
 
+  class DynamicDictParser {
+  public:

njames93 wrote:
> sammccall wrote:
> > instead of adding a second class for this, can we reuse DictParser, and 
> > change `unrecognized()` so:
> >  - the callback gets access to the key location and the value
> >  - the callback is responsible for emitting the "unknown key" error if it 
> > wants one
> > 
> > i.e. the default `unrecognized` handler is:
> > 
> > ```
> > [this](Located Key, Node &Value) { Outer->warning("Unknown " + 
> > Description + " key " + *Key); }
> > ```
> > 
> > and we replace it for parsing CheckOptions
> Not sure I'm a huge fan of that approach. I can't imagine a use case where 
> the 2 dictionary modes will be used at the same time so there isn't a need 
> for it to support both. 
> By that I mean you wont have a dictionary where its expected to have both 
> known and unknown keys.
> 
> `DictParser` could well be implemented as a a specialisation of 
> `DynamicDictParser` but not much would be gained from that.
Yes, they're being used for different purposes, so using the same class isn't 
the most expressive.
But this isn't a public API, it's a local helper. The implementation is 
nontrivial and almost identical. This is just about reducing the implementation 
complexity.



Comment at: clang-tools-extra/clangd/ConfigYAML.cpp:235
+  // Try to parse a single boolean value from the node, warn on failure.
+  llvm::Optional> scalarBool(Node &N, llvm::StringRef Desc) {
+llvm::SmallString<256> Buf;

sammccall wrote:
> can we implement this on top of scalarValue? seems like it would avoid a 
> bunch of repetition and the efficiency doesn't seem that important
You've extracted a common getScalar function here instead, I think to avoid 
scalarValue copying the string?
But this isn't a hot path, and all the legal values for this string are in SSO 
range anyway - can we avoid this extra complexity?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90531

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


[PATCH] D90921: [Clang][AArch64] Remove unused prefix in constrained rounding test

2020-11-06 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett created this revision.
Herald added subscribers: cfe-commits, danielkiss, kristof.beyls.
Herald added a project: clang.
DavidSpickett requested review of this revision.

This test was added in 7f38812d5b7e0fd5145e44d5ae831a67d782dca6 

and all the other tests make use of the COMMONIR check. So I think
this was left in by mistake for this particular test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90921

Files:
  clang/test/CodeGen/arm64-vrnd-constrained.c


Index: clang/test/CodeGen/arm64-vrnd-constrained.c
===
--- clang/test/CodeGen/arm64-vrnd-constrained.c
+++ clang/test/CodeGen/arm64-vrnd-constrained.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none 
-fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm 
-o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=CONSTRAINED %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s | llc -o=- - \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none 
-fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm 
-o - %s | llc -o=- - \


Index: clang/test/CodeGen/arm64-vrnd-constrained.c
===
--- clang/test/CodeGen/arm64-vrnd-constrained.c
+++ clang/test/CodeGen/arm64-vrnd-constrained.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s | llc -o=- - \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm -o - %s | llc -o=- - \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90921: [Clang][AArch64] Remove unused prefix in constrained rounding test

2020-11-06 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a reviewer: kpn.
DavidSpickett added a comment.

In case this looks like a spammy change, this is for 
http://llvm.1065342.n5.nabble.com/llvm-dev-RFC-FileCheck-dis-allowing-unused-prefixes-td142255.html

AFAICT there is no common IR to check for in this test, unlike the others.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90921

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


[PATCH] D71880: [clangd] Implement Decl canonicalization rules for rename

2020-11-06 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 303397.
kbobyrev added a comment.

Continue implementation, integrate more tests from clang-rename.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71880

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -91,10 +91,86 @@
 }
 
 TEST(RenameTest, WithinFileRename) {
-  // rename is runnning on all "^" points, and "[[]]" ranges point to the
-  // identifier that is being renamed.
+  // For each "^" this test moves cursor to its location and applies renaming
+  // while checking that all identifiers enclosed in [[]] ranges are handled
+  // correctly.
   llvm::StringRef Tests[] = {
-  // Function.
+  // Templated static method instantiation.
+  R"cpp(
+template
+class Foo {
+public:
+  static T [[f^oo]]() {}
+};
+
+void bar() {
+  Foo::[[f^oo]]();
+}
+  )cpp",
+
+  // Templated method instantiation.
+  R"cpp(
+template
+class Foo {
+public:
+  T [[f^oo]]() {}
+};
+
+void bar() {
+  Foo().[[f^oo]]();
+}
+  )cpp",
+
+  // Class template (partial) specialization forward declarations.
+  R"cpp(
+template
+class [[Foo^]];
+
+template
+class [[Foo^]] {};
+
+template
+class [[Foo^]];
+  )cpp",
+
+  // Class template (full) specialization forward declaration.
+  R"cpp(
+template
+class [[Foo^]];
+
+template
+class [[Foo^]] {};
+  )cpp",
+
+  // Function template specialization forward declaration.
+  R"cpp(
+template
+U [[foo^]]();
+
+template
+U [[foo^]]() {};
+  )cpp",
+
+  // Function template specialization forward declaration.
+  R"cpp(
+template
+U [[foo^]]() {};
+
+template
+U [[foo^]]();
+  )cpp",
+
+  // Function template specialization forward declaration without function
+  // definition.
+  R"cpp(
+template
+U [[foo^]]();
+
+template
+U [[foo^]]();
+  )cpp",
+
+  // Simple recursive function.
   R"cpp(
 void [[foo^]]() {
   [[fo^o]]();
@@ -104,7 +180,7 @@
   // Type.
   R"cpp(
 struct [[foo^]] {};
-[[foo]] test() {
+[[foo^]] test() {
[[f^oo]] x;
return x;
 }
@@ -114,20 +190,21 @@
   R"cpp(
 void bar() {
   if (auto [[^foo]] = 5) {
-[[foo]] = 3;
+[[fo^o]] = 3;
   }
 }
   )cpp",
 
-  // Rename class, including constructor/destructor.
+  // Class, its constructor and destructor.
   R"cpp(
 class [[F^oo]] {
+public:
   [[F^oo]]();
-  ~[[Foo]]();
+  ~[[Fo^o]]();
   void foo(int x);
 };
-[[Foo]]::[[Fo^o]]() {}
-void [[Foo]]::foo(int x) {}
+[[Fo^o]]::[[Fo^o]]() {}
+void [[Fo^o]]::foo(int x) {}
   )cpp",
 
   // Rename template class, including constructor/destructor.
@@ -199,9 +276,9 @@
 class [[F^oo]] {};
 
 void test() {
-  [[Foo]] x;
-  [[Foo]] y;
-  [[Foo]] z;
+  [[F^oo]] x;
+  [[Fo^o]] y;
+  [[Foo^]] z;
 }
   )cpp",
 
@@ -361,7 +438,7 @@
 
 void qoo() {
   [[foo]]();
-  boo([[foo]]());
+  boo([[fo^o]]());
   M1();
   boo(M1());
   M2([[foo]]());
@@ -454,7 +531,7 @@
 }
   )cpp",
 
-  // template class in template argument list.
+  // Template class in template argument list.
   R"cpp(
 template
 class [[Fo^o]] {};
@@ -510,6 +587,151 @@
   }
 }
 
+TEST(RenameTest, Alias) {
+  // For each "^" this test moves cursor to its location and applies renaming
+  // while checking that all identifiers enclosed in [[]] ranges are handled
+  // correctly.
+  llvm::StringRef Tests[] = {
+  R"cpp(
+class X {};
+typedef X [[Fo^o]];
+  )cpp",
+
+  R"cpp(
+class X {};
+using [[U^Old]] = X;
+  )cpp",
+
+  R"cpp(
+template 
+class X { T t; };
+
+template 
+using [[O^ld]] = X;
+  )cpp",
+
+  R"cpp(
+namespace x { class X {}; }
+namespace ns {
+using [[F^oo]] = x::X;
+}
+  )cpp",
+
+  R"cpp(
+namespace x { class Old {}; }
+namespace ns {
+#define REF(alias) alias alias_var;
+
+#define ALIAS(old) \
+  using old##Alias = x::old; \
+   

[PATCH] D90691: [analyzer] Add new checker for unchecked return value.

2020-11-06 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/UncheckedReturnValueChecker.cpp:41
+BugReporter &BR) const {
+auto FoundCall = callExpr().bind("call");
+auto CallInCompound = compoundStmt(forEach(FoundCall));

Please note that the `CallExpr` does not necessarily stands alone. It may be 
wrapped into an `ExprWithCleanUps`. We should consider these `CallExpr`s as 
unchecked too.



Comment at: clang/lib/StaticAnalyzer/Checkers/UncheckedReturnValueChecker.cpp:85
+private:
+  llvm::StringMap FunctionsToCheck = {
+  {"aligned_alloc", 2}, {"asctime_s", 3}, {"at_quick_exit", 1},

Hmm, why `StringMap<>`? Why not `CallDescriptionMap<>`?



Comment at: clang/test/Analysis/unchecked-return-value.cpp:10
+int f1(int X) {
+  scanf(""); // expected-warning {{Return value is not checked in call to 
'scanf' [security.UncheckedReturnValue]}}
+  std::scanf(""); // expected-warning {{Return value is not checked in call to 
'scanf' [security.UncheckedReturnValue]}}

Please use some valid format here. E.g. `scanf("%*c");`



Comment at: clang/test/Analysis/unchecked-return-value.cpp:16
+scanf(""); // expected-warning {{Return value is not checked in call to 
'scanf' [security.UncheckedReturnValue]}}
+  }
+

Please add such simple test case for all the functions we try to check. (One 
call is enough for every such function, either in `std::` or on the top 
namespace.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90691

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


[PATCH] D90928: [OpenCL] Add assertions to extension lookup

2020-11-06 Thread Erik Tomusk via Phabricator via cfe-commits
erik2020 created this revision.
erik2020 added a reviewer: ldrumm.
erik2020 added a project: clang.
Herald added subscribers: cfe-commits, dexonsmith, Anastasia, yaxunl.
erik2020 requested review of this revision.

Calling any of the `OpenCLOptions::is*()` functions (except `isKnown()`) with 
an unknown extension string results in a seg fault. This patch adds assertions 
to catch these conditions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90928

Files:
  clang/include/clang/Basic/OpenCLOptions.h


Index: clang/include/clang/Basic/OpenCLOptions.h
===
--- clang/include/clang/Basic/OpenCLOptions.h
+++ clang/include/clang/Basic/OpenCLOptions.h
@@ -37,12 +37,14 @@
   }
 
   bool isEnabled(llvm::StringRef Ext) const {
+assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension.");
 return OptMap.find(Ext)->second.Enabled;
   }
 
   // Is supported as either an extension or an (optional) core feature for
   // OpenCL version \p CLVer.
   bool isSupported(llvm::StringRef Ext, const LangOptions &LO) const {
+assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension.");
 // In C++ mode all extensions should work at least as in v2.0.
 auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
 auto I = OptMap.find(Ext)->getValue();
@@ -52,6 +54,7 @@
   // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
   // For supported extension, return false.
   bool isSupportedCore(llvm::StringRef Ext, const LangOptions &LO) const {
+assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension.");
 // In C++ mode all extensions should work at least as in v2.0.
 auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
 auto I = OptMap.find(Ext)->getValue();
@@ -61,6 +64,7 @@
   // Is supported OpenCL extension for OpenCL version \p CLVer.
   // For supported (optional) core feature, return false.
   bool isSupportedExtension(llvm::StringRef Ext, const LangOptions &LO) const {
+assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension.");
 // In C++ mode all extensions should work at least as in v2.0.
 auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
 auto I = OptMap.find(Ext)->getValue();


Index: clang/include/clang/Basic/OpenCLOptions.h
===
--- clang/include/clang/Basic/OpenCLOptions.h
+++ clang/include/clang/Basic/OpenCLOptions.h
@@ -37,12 +37,14 @@
   }
 
   bool isEnabled(llvm::StringRef Ext) const {
+assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension.");
 return OptMap.find(Ext)->second.Enabled;
   }
 
   // Is supported as either an extension or an (optional) core feature for
   // OpenCL version \p CLVer.
   bool isSupported(llvm::StringRef Ext, const LangOptions &LO) const {
+assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension.");
 // In C++ mode all extensions should work at least as in v2.0.
 auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
 auto I = OptMap.find(Ext)->getValue();
@@ -52,6 +54,7 @@
   // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
   // For supported extension, return false.
   bool isSupportedCore(llvm::StringRef Ext, const LangOptions &LO) const {
+assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension.");
 // In C++ mode all extensions should work at least as in v2.0.
 auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
 auto I = OptMap.find(Ext)->getValue();
@@ -61,6 +64,7 @@
   // Is supported OpenCL extension for OpenCL version \p CLVer.
   // For supported (optional) core feature, return false.
   bool isSupportedExtension(llvm::StringRef Ext, const LangOptions &LO) const {
+assert(OptMap.find(Ext) != OptMap.end() && "Unknown extension.");
 // In C++ mode all extensions should work at least as in v2.0.
 auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
 auto I = OptMap.find(Ext)->getValue();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89031: [SVE] Add support to vectorize_width loop pragma for scalable vectors

2020-11-06 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added a comment.

Hi @david-arm I just found that two uses of `llvm.loop.vectorize.width` are not 
yet updated.

- WarnMissedTransforms.cpp in `warnAboutLeftoverTransformations`.
- LoopUtils.cpp in `llvm::hasVectorizeTransformation`.

The cases seem quite trivial to fix up, can you include those changes in this 
patch?


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

https://reviews.llvm.org/D89031

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


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-06 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

In D90448#2376710 , @dblaikie wrote:

> How's this compare to the similar checks for variable templates? Is there 
> some code/checking we could share here?

The code of checks for variable templates is just before the additional code. 
But the conditions of if statement and the format of diagnostics are different, 
so it may be better to do the check for static member instantiation separately. 
And I have reused the type comparing function (with an argument different).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90448

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


[PATCH] D90891: [clang] ns_error_domain attribute also supports CFString typed variables

2020-11-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM


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

https://reviews.llvm.org/D90891

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


[PATCH] D90763: Traverse-ignore explicit template instantiations

2020-11-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a tiny commenting request.




Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:506
+if (const auto *CTSD = Node.get()) {
+  auto SK = CTSD->getSpecializationKind();
+  if (SK == TSK_ExplicitInstantiationDeclaration ||

steveire wrote:
> aaron.ballman wrote:
> > Same here, though this could also be simplified to:
> > ```
> > ScopedTraversal = (SK == TSK_ExplicitInstantiationDeclaration || SK == 
> > TSK_ExplicitInstantiationDefinition);
> > ```
> If `ScopedTraversal` is set to `true` above, this could wrongly set it to 
> `false`.
> If ScopedTraversal is set to true above, this could wrongly set it to false.

Good catch!



Comment at: clang/unittests/AST/ASTTraverserTest.cpp:1092
+
+// Explicit instantiation of template functions do not appear in the AST
+template float timesTwo(float);

steveire wrote:
> aaron.ballman wrote:
> > Huh, do you have any idea if that's a bug? We have 
> > `ClassTemplateSpecializationDecl` and `VarTemplateSpecializationDecl`, but 
> > we have `FunctionTemplateSpecializationInfo` that doesn't generate an AST 
> > node and no mention of why in the comments that I've spotted yet.
> I don't know why, but this is part of the confusion in the test in the 
> discussion below.
> 
> I can look into it after this is merged if you don't beat me to it.
> I don't know why, but this is part of the confusion in the test in the 
> discussion below.

Okay, I kind of thought that might be the case, thank you for confirming.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:2280
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }

steveire wrote:
> aaron.ballman wrote:
> > Explicitly instantiating a function template in ignore mode returns false, 
> > but explicitly instantiating a class template returns true? Is this 
> > intentional or just fallout from the lack of explicit instantiation 
> > information in the AST for functions?
> I've added some more tests and comments to try to clarify this.
> 
> We should be able to match on the template arguments of explicit 
> instantiations, but not the contents of the instantiations.
> 
> Lack of representation of explicit function instantiations makes the expected 
> test results confusing, but hopefully the comments now clarify.
Thanks for the new comment, that clarifies nicely! Can you add a full stop to 
the end of the comment though?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90763

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


[PATCH] D90767: Add new matchers for dependent names in templates

2020-11-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2859
+AST_MATCHER_P(CXXDependentScopeMemberExpr, hasMemberName, std::string, N) {
+  return Node.getMember().getAsString() == N;
+}

steveire wrote:
> aaron.ballman wrote:
> > This will allow users to match on members that don't have identifiers -- is 
> > that intentional? If not, my recommendation is to use something like:
> > ```
> > if (const IdentifierInfo *II = Node.getMember().getAsIdentifierInfo())
> >   return II->isStr(N);
> > return false;
> > ```
> > Either way, we should document and test what the expected behavior is for 
> > things like constructors/destructors, overloaded operators, and the likes. 
> > (But we don't have to test every kind of odd declaration name.)
> I was not able to demonstrate the problem with a test: 
> https://godbolt.org/z/3Grd1b
> 
> Can you be more specific?
I was thinking of something along these lines: https://godbolt.org/z/K8serj


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90767

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


[PATCH] D89790: [clangd] Add basic conflict detection for the rename.

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks! Just style nits.




Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:266
+  switch (DC->getDeclKind()) {
+  // The enclosing DeclContext may not be the enclosing scope, it might have
+  // false positives and negatives, so we only choose the DeclContexts that

this comment is missing the *reason*.

FunctionDecl is a good example, but the fundamental reason is again not given.
Maybe change that paragraph to:

```
Notably, FunctionDecl is excluded, because local variables are not scoped to 
the function, but rather to the CompoundStmt that is its body.
Lookup will not find function-local variables.
```



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:268
+  // false positives and negatives, so we only choose the DeclContexts that
+  // we have confidence.
+  // (!) FunctionDecl is excluded, becase it is not the enclosing scope for

confidence in what?

I think the condition is: don't have any subscopes that are neither 
DeclContexts nor transparent.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:320
+return llvm::None;
+  // Perform a lookup in the decl context of the RenameDecl, to find out any
+  // conflicts if we perform the rename.

This is still a bit confusing: *here* you seem to decide which scope to look up 
in, but then inside the lookup() function you may change your mind.
I'd suggest moving the `getDeclContext()` inside the function and renaming the 
function to "findSiblingWithName" or something.

Also while early-exit is often good, I find early-exit in the *success* case 
confusing.
Consider:

```
// Name conflict detection.
// Function conflicts are subtle (overloading), so ignore them.
if (RenameDecl.getKind() != Decl::Function) {
  if (lookupSiblingWithName(ASTCtx, RenameDecl, NewName))
return InvalidName{...};
}
return llvm::None;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89790

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


[PATCH] D90555: [clangd] Handle duplicate enum constants in PopulateSwitch tweak

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks!
This makes sense to me, I assumed at first that the expr could be something 
complicated that we'd have to const-evaluate, thought clearly this already 
happens (and we do assume it's a ConstantExpr).




Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:115
 
-  // We trigger if there are fewer cases than enum values (and no case covers
-  // multiple values). This guarantees we'll have at least one case to insert.

It would still be nice to keep a high-level comment about the strategy.
(Not *this* comment of course, as this patch changes the strategy!)



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:117
 
-  // We trigger if there are fewer cases than enum values (and no case covers
-  // multiple values). This guarantees we'll have at least one case to insert.
-  // We don't yet determine what the cases are, as that means evaluating
-  // expressions.
-  auto I = EnumD->enumerator_begin();
-  auto E = EnumD->enumerator_end();
+  // Special case of the empty enum
+  if (EnumD->enumerator_begin() == EnumD->enumerator_end())

why is the special case needed?



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:126
+
+  llvm::SmallMapVector EnumConstants;
+  for (auto *EnumConstant : EnumD->enumerators()) {

It looks as if we're now doing (via prepare + apply combined):

1. Collect all constants into a `SmallMapVector`.
2. Iterate over cases, marking covered constants
3. Prepare returns true if there are unmarked constants
4. Collect all cases into a `SmallSet`
5. Iterate over the constants, inserting text for those not in the set.

This seems equivalent, but less redundant:
1. Collect all constants into a `MapVector` (e.g. 
`MissingEnumerators`)
2. Iterate over cases, deleting covered constants
3. Prepare returns true if any constant remains
4. Iterate over the map, inserting text for every element in the map



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:141
 const CaseStmt *CS = cast(CaseList);
 // Case statement covers multiple values, so just counting doesn't work.
 if (CS->caseStmtIsGNURange())

this comment no longer holds (we're not counting anymore).

Could just say // GNU range cases are rare, we don't support them



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:151
+
+if (CE->getResultStorageKind() != ConstantExpr::RSK_Int64)
+  return false;

why can we not hit the APValue case?



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:191
   for (EnumConstantDecl *Enumerator : EnumD->enumerators()) {
-if (ExistingEnumerators.contains(Enumerator->getInitVal()))
+// Try to insert this Enumerator into the set. If this fails, the value was
+// either already there to begin with or we have already added it using a

Maybe just "Skip if value already covered (possibly under a different name)"?
("try to insert... if this fails" is just echoing the code)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90555

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


[PATCH] D90892: [AIX][FE] Support constructor/destructor attribute

2020-11-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:276
   // extern "C" int atexit(void (*f)(void));
-  assert(cast(dtorStub)->getFunctionType() ==
- llvm::FunctionType::get(CGM.VoidTy, false) &&
+  llvm::PointerType *Expected =
+  llvm::PointerType::get(llvm::FunctionType::get(CGM.VoidTy, false),

This will likely cause unused variable warnings in release builds due to the 
`assert` macro.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:303
   // extern "C" int unatexit(void (*f)(void));
-  assert(dtorStub->getFunctionType() ==
- llvm::FunctionType::get(CGM.VoidTy, false) &&
+  llvm::PointerType *Expected =
+  llvm::PointerType::get(llvm::FunctionType::get(CGM.VoidTy, false),

Same here.



Comment at: clang/lib/CodeGen/CodeGenModule.h:1482
+  void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535,
+ bool IsDtorAttrFunc = false);
 

There's a fixme comment a few lines up about hardcoding priority being gross 
and this sort of extends the grossness a bit. Perhaps these functions should 
accept a `DestructorAttr *`/`ConstructorAttr *` that can be null?



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2537
+  // priority.
+  CodeGenFunction CGF(CGM);
+

Do you need this? I think you can get `VoidTy` off `CGM` already which seems to 
be the only use of `CGF`.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2584
+  // We're assuming that the destructor function is something we can
+  // reasonably call with the default CC.  Go ahead and cast it to the
+  // right prototype.

Is this assumption safe though given that there are calling convention 
attributes that can be written on the function?



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2648
+// We're assuming that the destructor function is something we can
+// reasonably call with the default CC.  Go ahead and cast it to the
+// right prototype.

Same question here as above.


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

https://reviews.llvm.org/D90892

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


[PATCH] D90921: [Clang][AArch64] Remove unused prefix in constrained rounding test

2020-11-06 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn accepted this revision.
kpn added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90921

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


[PATCH] D88913: [FPEnv] Use strictfp metadata in casting nodes

2020-11-06 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff accepted this revision.
sepavloff added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D88913

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


[clang] aecd52b - [Clang][AArch64] Remove unused prefix in constrained rounding test

2020-11-06 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2020-11-06T14:13:46Z
New Revision: aecd52b97bb457aaecb0bcb658e6ea684e869de9

URL: 
https://github.com/llvm/llvm-project/commit/aecd52b97bb457aaecb0bcb658e6ea684e869de9
DIFF: 
https://github.com/llvm/llvm-project/commit/aecd52b97bb457aaecb0bcb658e6ea684e869de9.diff

LOG: [Clang][AArch64] Remove unused prefix in constrained rounding test

This test was added in 7f38812d5b7e0fd5145e44d5ae831a67d782dca6
and all the other tests make use of the COMMONIR check. So I think
this was left in by mistake for this particular test.

Reviewed By: kpn

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

Added: 


Modified: 
clang/test/CodeGen/arm64-vrnd-constrained.c

Removed: 




diff  --git a/clang/test/CodeGen/arm64-vrnd-constrained.c 
b/clang/test/CodeGen/arm64-vrnd-constrained.c
index ee2edbcbd096..bcd2affa7c62 100644
--- a/clang/test/CodeGen/arm64-vrnd-constrained.c
+++ b/clang/test/CodeGen/arm64-vrnd-constrained.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none 
-fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm 
-o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=CONSTRAINED %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s | llc -o=- - \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none 
-fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm 
-o - %s | llc -o=- - \



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


[PATCH] D90921: [Clang][AArch64] Remove unused prefix in constrained rounding test

2020-11-06 Thread David Spickett via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaecd52b97bb4: [Clang][AArch64] Remove unused prefix in 
constrained rounding test (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90921

Files:
  clang/test/CodeGen/arm64-vrnd-constrained.c


Index: clang/test/CodeGen/arm64-vrnd-constrained.c
===
--- clang/test/CodeGen/arm64-vrnd-constrained.c
+++ clang/test/CodeGen/arm64-vrnd-constrained.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none 
-fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm 
-o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=CONSTRAINED %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s | llc -o=- - \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon 
-ffreestanding -flax-vector-conversions=none 
-fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm 
-o - %s | llc -o=- - \


Index: clang/test/CodeGen/arm64-vrnd-constrained.c
===
--- clang/test/CodeGen/arm64-vrnd-constrained.c
+++ clang/test/CodeGen/arm64-vrnd-constrained.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s | llc -o=- - \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm -o - %s | llc -o=- - \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90750: [clangd] Introduce ProjectAwareIndex

2020-11-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 303442.
kadircet added a comment.

The index has the following query semantics:

- Lookup: it only queries the associated index. This is to not regress

latency for operations like Hover and Go-To.

- FuzzyFind only queries the associated index when

RestrictForCodeCompletion is set, it queries all otherwise. Again this
is to prevent latency regression for code completion, but make sure we
provide complete results for search operations like WorkspaceSymbol.

- Refs, queries all. As incomplete results for such operations might

result in bad UX for opeartions like rename. Also having an incomplete
set of references might result in bad impressions.

- Relations, queries all. Again this is used by operations like type and

call hierarchy and having incomplete results are useless for such
operations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90750

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/ProjectAware.cpp
  clang-tools-extra/clangd/index/ProjectAware.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp
@@ -0,0 +1,7 @@
+//===-- ProjectAwareIndexTests.cpp  ---*- C++ -*---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -73,6 +73,7 @@
   PathMappingTests.cpp
   PreambleTests.cpp
   PrintASTTests.cpp
+  ProjectAwareIndexTests.cpp
   QualityTests.cpp
   RenameTests.cpp
   RIFFTests.cpp
Index: clang-tools-extra/clangd/index/ProjectAware.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/ProjectAware.h
@@ -0,0 +1,76 @@
+//===--- ProjectAware.h --*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_PROJECT_AWARE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_PROJECT_AWARE_H
+
+#include "Config.h"
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "index/Merge.h"
+#include "index/Serialization.h"
+#include "index/remote/Client.h"
+#include "support/Threading.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+namespace clang {
+namespace clangd {
+
+class ProjectAwareIndex : public SymbolIndex {
+public:
+  size_t estimateMemoryUsage() const override;
+
+  /// Only queries the associated index with the current context.
+  void lookup(const LookupRequest &Req,
+  llvm::function_ref Callback) const override;
+
+  /// Query all indexes while prioritizing the associated one (if any).
+  bool refs(const RefsRequest &Req,
+llvm::function_ref Callback) const override;
+
+  /// Queries only the associates index when Req.RestrictForCodeCompletion is
+  /// set, otherwise queries all.
+  bool
+  fuzzyFind(const FuzzyFindRequest &Req,
+llvm::function_ref Callback) const override;
+
+  /// Query all indexes while prioritizing the associated one (if any).
+  void relations(const RelationsRequest &Req,
+ llvm::function_ref
+ Callback) const override;
+
+private:
+  // Returns the index associated with current context, if any.
+  SymbolIndex *getIndex() const;
+  // Adds the Idx into IndexStorage and adjusts the MergedIdx view. Returns a
+  // pointer to the Idx.
+  SymbolIndex *addIndex(std::unique_ptr Idx) const;
+
+  // Storage for all the external indexes.
+  Memoize> IndexForProject;
+  mutable std::mutex Mu;
+  mutable std::vector> IndexStorage;
+  AsyncTaskRunner Tasks;
+
+  // Used for creating a merged view over all the indexes seen so far to ease
+  // querying them all at once.
+  mutable std::mutex MergedIdxMu;
+  mutable std::vector> MergedIdxStorage;
+  // Points at root of merged view of all smybols.
+  mutable SymbolIndex *MergedIdx = nullptr;
+};
+} // namespace clangd
+} // names

[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-06 Thread Vasily Kulikov via Phabricator via cfe-commits
segoon created this revision.
segoon added a reviewer: alexfh.
Herald added subscribers: cfe-commits, lxfind, modocache, xazax.hun, mgorny.
Herald added a project: clang.
segoon requested review of this revision.

Checks for some thread-unsafe functions against a black list of 
known-to-be-unsafe functions. Usually they access static variables without 
synchronization (e.g. gmtime(3)) or utilize signals in a racy way (e.g. 
sleep(3)).

The patch adds a check instead of auto-fix as thread-safe alternatives usually 
have API with an additional argument (e.g. gmtime(3) v.s. gmtime_r(3)) or have 
a different semantics (e.g. exit(3) v.s. __exit(3)), so it is a rather tricky 
or non-expected fix.

The check is used in Yandex Taxi backend and has caught many unpleasant bugs. A 
similar patch for coroutine-unsafe API is coming next.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90944

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp
  clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp
@@ -0,0 +1,18 @@
+// RUN: %check_clang_tidy %s misc-mt-unsafe %t
+
+#include 
+#include 
+
+void foo() {
+  sleep(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+
+  ::sleep(2);
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: function is not thread safe [misc-mt-unsafe]
+
+  time_t tt{};
+  auto tm = gmtime(&tt);
+  // CHECK-MESSAGES: :[[@LINE-3]]:13: warning: function is not thread safe [misc-mt-unsafe]
+  tm = ::gmtime(&tt);
+  // CHECK-MESSAGES: :[[@LINE-4]]:8: warning: function is not thread safe [misc-mt-unsafe]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - misc-mt-unsafe
+
+misc-mt-unsafe
+==
+
+Checks for some thread-unsafe functions against a black list of
+known-to-be-unsafe functions. Usually they access static variables without
+synchronization (e.g. gmtime(3)) or utilize signals in a racy way.
+
+Examples:
+
+.. code-block:: c++
+
+tm = gmtime(timep); // uses a global buffer
+
+sleep(1); // implementation may use SIGALRM
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -30,7 +30,7 @@
`abseil-time-comparison `_, "Yes"
`abseil-time-subtraction `_, "Yes"
`abseil-upgrade-duration-conversions `_, "Yes"
-   `altera-struct-pack-align `_,
+   `altera-struct-pack-align `_, "Yes"
`android-cloexec-accept `_, "Yes"
`android-cloexec-accept4 `_,
`android-cloexec-creat `_, "Yes"
@@ -143,6 +143,7 @@
`cppcoreguidelines-narrowing-conversions `_,
`cppcoreguidelines-no-malloc `_,
`cppcoreguidelines-owning-memory `_,
+   `cppcoreguidelines-prefer-member-initializer `_, "Yes"
`cppcoreguidelines-pro-bounds-array-to-pointer-decay `_,
`cppcoreguidelines-pro-bounds-constant-array-index `_, "Yes"
`cppcoreguidelines-pro-bounds-pointer-arithmetic `_,
@@ -179,7 +180,6 @@
`google-readability-todo `_,
`google-runtime-int `_,
`google-runtime-operator `_,
-   `google-runtime-references `_,
`google-upgrade-googletest-case `_, "Yes"
`hicpp-avoid-goto `_,
`hicpp-exception-baseclass `_,
@@ -198,6 +198,7 @@
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
+   `misc-mt-unsafe `_, "Yes"
`misc-new-delete-overloads `_,
`misc-no-recursion `_,
`misc-non-copyable-objects `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -106,6 +106,10 @@
   Finds condition variables in nested ``if`` statements that were also checked
   in the outer ``if`` statement and were not changed.
 
+- New :doc:`misc-mt-unsafe ` check.
+
+  Finds thread-unsafe functions usage.
+
 - New :doc:`readability-function-cognitive-complexity
   ` check.
 
Index: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.h
@@ -0,0 +1,34 @@
+//=

[PATCH] D90691: [analyzer] Add new checker for unchecked return value.

2020-11-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 303444.
balazske added a comment.

Small fixes in test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90691

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/UncheckedReturnValueChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/unchecked-return-value.cpp

Index: clang/test/Analysis/unchecked-return-value.cpp
===
--- /dev/null
+++ clang/test/Analysis/unchecked-return-value.cpp
@@ -0,0 +1,76 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=security.UncheckedReturnValue -verify %s
+
+#include "Inputs/system-header-simulator-cxx.h"
+#include "Inputs/system-header-simulator.h"
+
+extern void extern_f(int);
+int btowc(int);
+
+struct S {
+  int getInt() const;
+};
+
+int f1(int X) {
+  scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+  std::scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+  other_ns::scanf("%*d");
+  {
+scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+  }
+
+  if (X) {
+scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+  }
+
+  if (X)
+scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+  if (scanf("%*d")) {
+  }
+  if (scanf("%*d") > 1) {
+  }
+
+  while (true)
+scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+  while (scanf("%*d")) {
+  }
+
+  do
+scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+  while (true);
+  do {
+  } while (scanf("%*d"));
+
+  for (int Y = 1; Y < 10; ++Y)
+scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+  for (int Y = 1; Y < 10; scanf("%*d")) { // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+  }
+  for (int Y = 1; scanf("%*d"); ++Y) {
+  }
+  int Y = 0;
+  for (scanf("%*d"); Y < 10; ++Y) { // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+  }
+
+  std::vector Vec;
+  for (int I : Vec)
+scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+
+  switch (scanf("%*d")) {
+  }
+  switch (X) {
+  case 1:
+scanf("%*d"); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+break;
+  }
+
+  // This call is wrapped in an ExprWithCleanups.
+  scanf("", S().getInt()); // expected-warning {{Return value is not checked in call to 'scanf' [security.UncheckedReturnValue]}}
+
+  int Z1 = scanf("%*d");
+  Z1 = scanf("%*d");
+  extern_f(scanf("%*d"));
+
+  btowc(22); // no warning for non-system function
+
+  return scanf("%*d"); // no warning if value is returned
+}
Index: clang/test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -1139,4 +1139,10 @@
   // TODO: Add some actual implementation.
 };
 
+int scanf(const char *format, ...);
+
 } // namespace std
+
+namespace other_ns {
+int scanf(const char *format, ...);
+}
Index: clang/lib/StaticAnalyzer/Checkers/UncheckedReturnValueChecker.cpp
===
--- /dev/null
+++ clang/lib/StaticAnalyzer/Checkers/UncheckedReturnValueChecker.cpp
@@ -0,0 +1,178 @@
+//===- ReturnValueChecker - Applies guaranteed return values *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This defines UncheckedReturnValueChecker, which checks for calls to functions
+// whose return value has to be observed by the program but is ignored.
+//
+//===--===//
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/StaticAnalyzer/Checkers/

[PATCH] D90691: [analyzer] Add new checker for unchecked return value.

2020-11-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 2 inline comments as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/UncheckedReturnValueChecker.cpp:41
+BugReporter &BR) const {
+auto FoundCall = callExpr().bind("call");
+auto CallInCompound = compoundStmt(forEach(FoundCall));

baloghadamsoftware wrote:
> Please note that the `CallExpr` does not necessarily stands alone. It may be 
> wrapped into an `ExprWithCleanUps`. We should consider these `CallExpr`s as 
> unchecked too.
It looks like that the matcher finds these occurrences too. A test was added 
for it.



Comment at: clang/lib/StaticAnalyzer/Checkers/UncheckedReturnValueChecker.cpp:85
+private:
+  llvm::StringMap FunctionsToCheck = {
+  {"aligned_alloc", 2}, {"asctime_s", 3}, {"at_quick_exit", 1},

baloghadamsoftware wrote:
> Hmm, why `StringMap<>`? Why not `CallDescriptionMap<>`?
`CallDescriptionMap` is only usable with `CallEvent` that is not used in this 
checker. Or it can be extended with lookup from `FunctionDecl`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90691

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


[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-06 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp:3-4
+
+#include 
+#include 
+

Tests should be hermetic, they can not use headers from system


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90944

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


[PATCH] D90748: [clangd] Introduce config parsing for External blocks

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

LG (comment nits) thanks!
(Meta-point: not sure how useful splitting this patch out from the compile step 
is...)




Comment at: clang-tools-extra/clangd/ConfigFragment.h:165
 llvm::Optional> Background;
+/// Configuration information for an external index. If both File and 
Server
+/// are set, Server will be ignored. This will be used by index

I'd move the file-take-precedence-over-server part to server.

Or even just say only one source (file/server) should be configured, leave the 
behavior unspecified, and report an error when compiling the fragment.



Comment at: clang-tools-extra/clangd/ConfigFragment.h:165
 llvm::Optional> Background;
+/// Configuration information for an external index. If both File and 
Server
+/// are set, Server will be ignored. This will be used by index

sammccall wrote:
> I'd move the file-take-precedence-over-server part to server.
> 
> Or even just say only one source (file/server) should be configured, leave 
> the behavior unspecified, and report an error when compiling the fragment.
"Configuration information for" is redundant here.

maybe just

/// An external index uses data source outside of clangd itself.
/// This is usually prepared using clangd-indexer.



Comment at: clang-tools-extra/clangd/ConfigFragment.h:170
+struct ExternalBlock {
+  /// Path to a monolithic index on disk. Absolute in case of a global
+  /// config, relative to location the config file containing the fragment

nit: I'm not sure "monolithic" is a useful qualifier to the audience here.
Path to an index file generated by clangd-indexer?



Comment at: clang-tools-extra/clangd/ConfigFragment.h:171
+  /// Path to a monolithic index on disk. Absolute in case of a global
+  /// config, relative to location the config file containing the fragment
+  /// otherwise.

Generalize this as "Relative paths may be used, if the config fragment is 
associated with a directory."?



Comment at: clang-tools-extra/clangd/ConfigFragment.h:173
+  /// otherwise.
+  llvm::Optional> File;
+  /// Address and port number for a remote-index. e.g. `123.1.1.1:13337`.

Should we mention slashes here too? :-\

Maybe we should just lift "all paths use forward-slashes" to a top-level 
comment.



Comment at: clang-tools-extra/clangd/ConfigFragment.h:174
+  llvm::Optional> File;
+  /// Address and port number for a remote-index. e.g. `123.1.1.1:13337`.
+  llvm::Optional> Server;

nit: for a clangd-index-server



Comment at: clang-tools-extra/clangd/ConfigFragment.h:176
+  llvm::Optional> Server;
+  /// Source root governed by this index. None implies current config file
+  /// location. Absolute in case of user config and relative otherwise.

Again: "Default is the directory associated with the config frament".

(Repeating this makes me wonder if we should have defined a more specific name 
like "Home"...)



Comment at: clang-tools-extra/clangd/ConfigYAML.cpp:103
+#else
+  warning("Remote index support isn't enabled for this clangd.", N);
+#endif

nit: this sort of validation would normally live in ConfigCompile, since it's 
not to do with serialization


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90748

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


[PATCH] D90763: Traverse-ignore explicit template instantiations

2020-11-06 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7efe07a12b69: Traverse-ignore explicit template 
instantiations (authored by stephenkelly).

Changed prior to commit:
  https://reviews.llvm.org/D90763?vs=303268&id=303451#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90763

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2214,6 +2214,23 @@
   (void)timesTwo(2);
 }
 
+template class TemplStruct;
+
+extern template class TemplStruct;
+
+template<> class TemplStruct {
+  TemplStruct() {}
+  ~TemplStruct() {}
+
+  void boolSpecializationMethodOnly() {}
+private:
+  bool m_t;
+};
+
+template float timesTwo(float);
+template<> bool timesTwo(bool){
+  return true;
+}
 )cpp";
   {
 auto M = cxxRecordDecl(hasName("TemplStruct"),
@@ -2241,6 +2258,77 @@
 EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
 EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
   }
+  {
+// Match on the integer literal in the explicit instantiation:
+auto MDef =
+functionDecl(hasName("timesTwo"),
+ hasParameter(0, parmVarDecl(hasType(asString("float",
+ hasDescendant(integerLiteral(equals(2;
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, MDef)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, MDef)));
+
+auto MTempl =
+functionDecl(hasName("timesTwo"),
+ hasTemplateArgument(0, refersToType(asString("float";
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, MTempl)));
+// TODO: If we could match on explicit instantiations of function templates,
+// this would be EXPECT_TRUE.
+EXPECT_FALSE(
+matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, MTempl)));
+  }
+  {
+auto M = functionDecl(hasName("timesTwo"),
+  hasParameter(0, parmVarDecl(hasType(booleanType();
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+// Match on the field within the explicit instantiation:
+auto MRecord = cxxRecordDecl(hasName("TemplStruct"),
+ has(fieldDecl(hasType(asString("float");
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, MRecord)));
+EXPECT_FALSE(
+matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, MRecord)));
+
+// Match on the explicit template instantiation itself:
+auto MTempl = classTemplateSpecializationDecl(
+hasName("TemplStruct"),
+hasTemplateArgument(0,
+templateArgument(refersToType(asString("float");
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, MTempl)));
+EXPECT_TRUE(
+matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, MTempl)));
+  }
+  {
+// The template argument is matchable, but the instantiation is not:
+auto M = classTemplateSpecializationDecl(
+hasName("TemplStruct"),
+hasTemplateArgument(0,
+templateArgument(refersToType(asString("float",
+has(cxxConstructorDecl(hasName("TemplStruct";
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+// The template argument is matchable, but the instantiation is not:
+auto M = classTemplateSpecializationDecl(
+hasName("TemplStruct"),
+hasTemplateArgument(0,
+templateArgument(refersToType(asString("long",
+has(cxxConstructorDecl(hasName("TemplStruct";
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+// Explicit specialization is written in source and it matches:
+auto M = classTemplateSpecializationDecl(
+hasName("TemplStruct"),
+hasTemplateArgument(0, templateArgument(refersToType(booleanType(,
+has(cxxConstructorDecl(hasName("TemplStruct"))),
+has(cxxMethodDecl(hasName("boolSpecializationMethodOnly";
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
 }
 
 template 
@@ -3249,10 +3337,9 @@
   EXPECT_TRUE(matches(
 cod

[clang] 7efe07a - Traverse-ignore explicit template instantiations

2020-11-06 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2020-11-06T15:25:59Z
New Revision: 7efe07a12b6967bc358678adf75dffd238a00250

URL: 
https://github.com/llvm/llvm-project/commit/7efe07a12b6967bc358678adf75dffd238a00250
DIFF: 
https://github.com/llvm/llvm-project/commit/7efe07a12b6967bc358678adf75dffd238a00250.diff

LOG: Traverse-ignore explicit template instantiations

Continue to dump and match on explicit template specializations, but
omit explicit instantiation declarations and definitions.

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

Added: 


Modified: 
clang/include/clang/AST/ASTNodeTraverser.h
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/unittests/AST/ASTTraverserTest.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index 1141f514d795..c3c06bf37f3d 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -101,6 +101,8 @@ class ASTNodeTraverser
 
   // Decls within functions are visited by the body.
   if (!isa(*D) && !isa(*D)) {
+if (isa(*D) && Traversal != TK_AsIs)
+  return;
 if (const auto *DC = dyn_cast(D))
   dumpDeclContext(DC);
   }

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 1f5951877f24..bd8174110910 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1060,7 +1060,7 @@ class ASTMatchFinder {
 
   virtual ASTContext &getASTContext() const = 0;
 
-  virtual bool isMatchingInImplicitTemplateInstantiation() const = 0;
+  virtual bool IsMatchingInTemplateInstantiationNotSpelledInSource() const = 0;
 
 protected:
   virtual bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx,

diff  --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp 
b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index 2fa1a3f71eb5..67de0e14d18c 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -500,6 +500,17 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
   const DynTypedMatcher &Matcher,
   BoundNodesTreeBuilder *Builder, int MaxDepth,
   TraversalKind Traversal, BindKind Bind) {
+bool ScopedTraversal = TraversingTemplateInstantiationNotSpelledInSource;
+
+if (const auto *CTSD = Node.get()) {
+  int SK = CTSD->getSpecializationKind();
+  if (SK == TSK_ExplicitInstantiationDeclaration ||
+  SK == TSK_ExplicitInstantiationDefinition)
+ScopedTraversal = true;
+}
+
+TemplateInstantiationNotSpelledInSourceScope RAII(this, ScopedTraversal);
+
 MatchChildASTVisitor Visitor(
   &Matcher, this, Builder, MaxDepth, Traversal, Bind);
 return Visitor.findMatch(Node);
@@ -584,38 +595,38 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return true; }
 
-  bool isMatchingInImplicitTemplateInstantiation() const override {
-return TraversingImplicitTemplateInstantiation;
+  bool IsMatchingInTemplateInstantiationNotSpelledInSource() const override {
+return TraversingTemplateInstantiationNotSpelledInSource;
   }
 
   bool TraverseTemplateInstantiations(ClassTemplateDecl *D) {
-ImplicitTemplateInstantiationScope RAII(this, true);
+TemplateInstantiationNotSpelledInSourceScope RAII(this, true);
 return 
RecursiveASTVisitor::TraverseTemplateInstantiations(
 D);
   }
 
   bool TraverseTemplateInstantiations(VarTemplateDecl *D) {
-ImplicitTemplateInstantiationScope RAII(this, true);
+TemplateInstantiationNotSpelledInSourceScope RAII(this, true);
 return 
RecursiveASTVisitor::TraverseTemplateInstantiations(
 D);
   }
 
   bool TraverseTemplateInstantiations(FunctionTemplateDecl *D) {
-ImplicitTemplateInstantiationScope RAII(this, true);
+TemplateInstantiationNotSpelledInSourceScope RAII(this, true);
 return 
RecursiveASTVisitor::TraverseTemplateInstantiations(
 D);
   }
 
 private:
-  bool TraversingImplicitTemplateInstantiation = false;
+  bool TraversingTemplateInstantiationNotSpelledInSource = false;
 
-  struct ImplicitTemplateInstantiationScope {
-ImplicitTemplateInstantiationScope(MatchASTVisitor *V, bool B)
-: MV(V), MB(V->TraversingImplicitTemplateInstantiation) {
-  V->TraversingImplicitTemplateInstantiation = B;
+  struct TemplateInstantiationNotSpelledInSourceScope {
+TemplateInstantiationNotSpelledInSourceScope(MatchASTVisitor *V, bool B)
+: MV(V), MB(V->Travers

[PATCH] D68997: Allow searching for prebuilt implicit modules.

2020-11-06 Thread Alexandre Rames via Phabricator via cfe-commits
arames added a comment.

In D68997#2377641 , @stella.stamenova 
wrote:

> This change broke the windows lldb bot:
>
> http://lab.llvm.org:8011/#/builders/83/builds/570
>
> Can you please fix this or revert?

Looking at this now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68997

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


[PATCH] D88645: [Annotation] Allows annotation to carry some additional constant arguments.

2020-11-06 Thread Victor Campos via Phabricator via cfe-commits
vhscampos added a comment.

@Tyker This is causing another build failure in another example:

  [2858/4034] Building CXX object 
tools/clang/examples/Attribute/CMakeFiles/Attribute.dir/Attribute.cpp.o
  FAILED: 
tools/clang/examples/Attribute/CMakeFiles/Attribute.dir/Attribute.cpp.o 
  CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/lib/ccache/clang++ 
-DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/examples/Attribute 
-I/home/vicspe01/workspace/upstream/llvm-project/clang/examples/Attribute 
-I/home/vicspe01/workspace/upstream/llvm-project/clang/include 
-Itools/clang/include -Iinclude 
-I/home/vicspe01/workspace/upstream/llvm-project/llvm/include -fPIC 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default 
-Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor 
-Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections 
-fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3  -fPIC  
-fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT 
tools/clang/examples/Attribute/CMakeFiles/Attribute.dir/Attribute.cpp.o -MF 
tools/clang/examples/Attribute/CMakeFiles/Attribute.dir/Attribute.cpp.o.d -o 
tools/clang/examples/Attribute/CMakeFiles/Attribute.dir/Attribute.cpp.o -c 
/home/vicspe01/workspace/upstream/llvm-project/clang/examples/Attribute/Attribute.cpp
  
/home/vicspe01/workspace/upstream/llvm-project/clang/examples/Attribute/Attribute.cpp:73:16:
 error: no matching function for call to 'Create'
  D->addAttr(AnnotateAttr::Create(S.Context, "example(" + Str.str() + ")",
 ^~~~
  tools/clang/include/clang/AST/Attrs.inc:885:24: note: candidate function not 
viable: requires at least 4 arguments, but 3 were provided
static AnnotateAttr *Create(ASTContext &Ctx, llvm::StringRef Annotation, 
Expr * *Args, unsigned ArgsSize, const AttributeCommonInfo &CommonInfo = 
{SourceRange{}});
 ^
  tools/clang/include/clang/AST/Attrs.inc:887:24: note: candidate function not 
viable: requires 6 arguments, but 3 were provided
static AnnotateAttr *Create(ASTContext &Ctx, llvm::StringRef Annotation, 
Expr * *Args, unsigned ArgsSize, SourceRange Range, AttributeCommonInfo::Syntax 
Syntax);
 ^
  1 error generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88645

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


[clang] aa0dc1c - [analyzer][NFCi] Mark CallEvent::getOriginExpr virtual, some cleanup

2020-11-06 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2020-11-06T16:51:34+01:00
New Revision: aa0dc1c3b8628bed8c8b91a75258d13eefa88dfe

URL: 
https://github.com/llvm/llvm-project/commit/aa0dc1c3b8628bed8c8b91a75258d13eefa88dfe
DIFF: 
https://github.com/llvm/llvm-project/commit/aa0dc1c3b8628bed8c8b91a75258d13eefa88dfe.diff

LOG: [analyzer][NFCi] Mark CallEvent::getOriginExpr virtual, some cleanup

Previously we just shadowed the original implementation with a virtual
declaration - which is really bugprone in a long run.

This patch marks `CallEvent::getOriginExpr` virtual to let subclasses
override it's behavior.
At the same time, I checked all virtual functions of this class hierarchy
to make sure we don't suffer from this elsewhere.
Removes redundant declarations of `virtual` if `override` is already present.

In theory, this patch is a functional change, but no tests were broken.
I suspect that there were no meaningful changes in behavior in the
subclasses compared to the shadowed `CallEvent::getOriginExpr`.

That being said, I had a hard time coming up with unit-tests covering this.
Motivation: https://reviews.llvm.org/D74735#2370909

Reviewed By: NoQ

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index a2a98c558a4b..060fff1a7407 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -225,7 +225,7 @@ class CallEvent {
 
   /// Returns the expression whose value will be the result of this call.
   /// May be null.
-  const Expr *getOriginExpr() const {
+  virtual const Expr *getOriginExpr() const {
 return Origin.dyn_cast();
   }
 
@@ -530,7 +530,7 @@ class SimpleFunctionCall : public AnyFunctionCall {
   }
 
 public:
-  virtual const CallExpr *getOriginExpr() const {
+  const CallExpr *getOriginExpr() const override {
 return cast(AnyFunctionCall::getOriginExpr());
   }
 
@@ -543,9 +543,7 @@ class SimpleFunctionCall : public AnyFunctionCall {
   }
 
   Kind getKind() const override { return CE_Function; }
-  virtual StringRef getKindAsString() const override {
-return "SimpleFunctionCall";
-  }
+  StringRef getKindAsString() const override { return "SimpleFunctionCall"; }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_Function;
@@ -570,7 +568,7 @@ class BlockCall : public CallEvent {
  RegionAndSymbolInvalidationTraits *ETraits) const override;
 
 public:
-  virtual const CallExpr *getOriginExpr() const {
+  const CallExpr *getOriginExpr() const override {
 return cast(CallEvent::getOriginExpr());
   }
 
@@ -653,7 +651,7 @@ class BlockCall : public CallEvent {
   ArrayRef parameters() const override;
 
   Kind getKind() const override { return CE_Block; }
-  virtual StringRef getKindAsString() const override { return "BlockCall"; }
+  StringRef getKindAsString() const override { return "BlockCall"; }
 
   static bool classof(const CallEvent *CA) { return CA->getKind() == CE_Block; 
}
 };
@@ -708,7 +706,7 @@ class CXXMemberCall : public CXXInstanceCall {
   void cloneTo(void *Dest) const override { new (Dest) CXXMemberCall(*this); }
 
 public:
-  virtual const CXXMemberCallExpr *getOriginExpr() const {
+  const CXXMemberCallExpr *getOriginExpr() const override {
 return cast(CXXInstanceCall::getOriginExpr());
   }
 
@@ -727,7 +725,7 @@ class CXXMemberCall : public CXXInstanceCall {
   RuntimeDefinition getRuntimeDefinition() const override;
 
   Kind getKind() const override { return CE_CXXMember; }
-  virtual StringRef getKindAsString() const override { return "CXXMemberCall"; 
}
+  StringRef getKindAsString() const override { return "CXXMemberCall"; }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXMember;
@@ -752,7 +750,7 @@ class CXXMemberOperatorCall : public CXXInstanceCall {
   }
 
 public:
-  virtual const CXXOperatorCallExpr *getOriginExpr() const {
+  const CXXOperatorCallExpr *getOriginExpr() const override {
 return cast(CXXInstanceCall::getOriginExpr());
   }
 
@@ -767,9 +765,7 @@ class CXXMemberOperatorCall : public CXXInstanceCall {
   const Expr *getCXXThisExpr() const override;
 
   Kind getKind() const override { return CE_CXXMemberOperator; }
-  virtual StringRef getKindAsString() const override {
-return "CXXMemberOperatorCall";
-  }
+  StringRef getKindAsString() const override { return "CXXMemberOperatorCall"; 
}
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXMemberOperator;
@@ -838,9 +834,7 @@ class CXXDestructorCall : public CXXInstanceCall {
   }
 
   Kind getKind() const override { return CE_CXXDestructor; }
-  virtual Str

[PATCH] D90754: [analyzer][NFCi] Mark CallEvent::getOriginExpr virtual, some cleanup

2020-11-06 Thread Balázs Benics via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa0dc1c3b862: [analyzer][NFCi] Mark CallEvent::getOriginExpr 
virtual, some cleanup (authored by steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90754

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h

Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -225,7 +225,7 @@
 
   /// Returns the expression whose value will be the result of this call.
   /// May be null.
-  const Expr *getOriginExpr() const {
+  virtual const Expr *getOriginExpr() const {
 return Origin.dyn_cast();
   }
 
@@ -530,7 +530,7 @@
   }
 
 public:
-  virtual const CallExpr *getOriginExpr() const {
+  const CallExpr *getOriginExpr() const override {
 return cast(AnyFunctionCall::getOriginExpr());
   }
 
@@ -543,9 +543,7 @@
   }
 
   Kind getKind() const override { return CE_Function; }
-  virtual StringRef getKindAsString() const override {
-return "SimpleFunctionCall";
-  }
+  StringRef getKindAsString() const override { return "SimpleFunctionCall"; }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_Function;
@@ -570,7 +568,7 @@
  RegionAndSymbolInvalidationTraits *ETraits) const override;
 
 public:
-  virtual const CallExpr *getOriginExpr() const {
+  const CallExpr *getOriginExpr() const override {
 return cast(CallEvent::getOriginExpr());
   }
 
@@ -653,7 +651,7 @@
   ArrayRef parameters() const override;
 
   Kind getKind() const override { return CE_Block; }
-  virtual StringRef getKindAsString() const override { return "BlockCall"; }
+  StringRef getKindAsString() const override { return "BlockCall"; }
 
   static bool classof(const CallEvent *CA) { return CA->getKind() == CE_Block; }
 };
@@ -708,7 +706,7 @@
   void cloneTo(void *Dest) const override { new (Dest) CXXMemberCall(*this); }
 
 public:
-  virtual const CXXMemberCallExpr *getOriginExpr() const {
+  const CXXMemberCallExpr *getOriginExpr() const override {
 return cast(CXXInstanceCall::getOriginExpr());
   }
 
@@ -727,7 +725,7 @@
   RuntimeDefinition getRuntimeDefinition() const override;
 
   Kind getKind() const override { return CE_CXXMember; }
-  virtual StringRef getKindAsString() const override { return "CXXMemberCall"; }
+  StringRef getKindAsString() const override { return "CXXMemberCall"; }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXMember;
@@ -752,7 +750,7 @@
   }
 
 public:
-  virtual const CXXOperatorCallExpr *getOriginExpr() const {
+  const CXXOperatorCallExpr *getOriginExpr() const override {
 return cast(CXXInstanceCall::getOriginExpr());
   }
 
@@ -767,9 +765,7 @@
   const Expr *getCXXThisExpr() const override;
 
   Kind getKind() const override { return CE_CXXMemberOperator; }
-  virtual StringRef getKindAsString() const override {
-return "CXXMemberOperatorCall";
-  }
+  StringRef getKindAsString() const override { return "CXXMemberOperatorCall"; }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXMemberOperator;
@@ -838,9 +834,7 @@
   }
 
   Kind getKind() const override { return CE_CXXDestructor; }
-  virtual StringRef getKindAsString() const override {
-return "CXXDestructorCall";
-  }
+  StringRef getKindAsString() const override { return "CXXDestructorCall"; }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXDestructor;
@@ -898,7 +892,7 @@
   void cloneTo(void *Dest) const override { new (Dest) CXXConstructorCall(*this); }
 
 public:
-  virtual const CXXConstructExpr *getOriginExpr() const {
+  const CXXConstructExpr *getOriginExpr() const override {
 return cast(AnyFunctionCall::getOriginExpr());
   }
 
@@ -913,9 +907,7 @@
   }
 
   Kind getKind() const override { return CE_CXXConstructor; }
-  virtual StringRef getKindAsString() const override {
-return "CXXConstructorCall";
-  }
+  StringRef getKindAsString() const override { return "CXXConstructorCall"; }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXConstructor;
@@ -959,7 +951,7 @@
   }
 
 public:
-  virtual const CXXInheritedCtorInitExpr *getOriginExpr() const {
+  const CXXInheritedCtorInitExpr *getOriginExpr() const override {
 return cast(AnyFunctionCall::getOriginExpr());
   }
 
@@ -986,14 +978,14 @@
 return getInheritingConstructor()->getArg(Index);
   }
 
-  virtual SVal getArgSVal(unsigned Index) const override {
+  SVal getArgSVal(unsigned Index) const override {
 return getState()->getSVal(
 getArgExpr(Index),
 getInheritingStackFrame()->get

[PATCH] D90767: Add new matchers for dependent names in templates

2020-11-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 303462.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90767

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -17,7 +17,6 @@
 
 namespace clang {
 namespace ast_matchers {
-
 TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesInFile) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
@@ -1629,6 +1628,95 @@
  Constructor1Arg));
 }
 
+TEST(ASTMatchersTest, NamesMember_CXXDependentScopeMemberExpr) {
+
+  // Member functions:
+  {
+auto Code = "template  struct S{ void mem(); }; template "
+" void x() { S s; s.mem(); }";
+
+EXPECT_TRUE(matches(
+Code,
+cxxDependentScopeMemberExpr(
+hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
+hasDeclaration(classTemplateDecl(has(cxxRecordDecl(
+has(cxxMethodDecl(hasName("mem")).bind("templMem")),
+memberHasSameNameAsBoundNode("templMem";
+
+EXPECT_TRUE(
+matches(Code, cxxDependentScopeMemberExpr(hasMemberName("mem";
+  }
+
+  // Member variables:
+  {
+auto Code = "template  struct S{ int mem; }; template "
+" void x() { S s; s.mem; }";
+
+EXPECT_TRUE(
+matches(Code, cxxDependentScopeMemberExpr(hasMemberName("mem";
+
+EXPECT_TRUE(matches(
+Code,
+cxxDependentScopeMemberExpr(
+hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
+hasDeclaration(classTemplateDecl(has(cxxRecordDecl(
+has(fieldDecl(hasName("mem")).bind("templMem")),
+memberHasSameNameAsBoundNode("templMem";
+  }
+
+  // static member variables:
+  {
+auto Code = "template  struct S{ static int mem; }; template "
+" void x() { S s; s.mem; }";
+
+EXPECT_TRUE(
+matches(Code, cxxDependentScopeMemberExpr(hasMemberName("mem";
+
+EXPECT_TRUE(matches(
+Code,
+cxxDependentScopeMemberExpr(
+hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
+hasDeclaration(classTemplateDecl(has(cxxRecordDecl(
+has(varDecl(hasName("mem")).bind("templMem")),
+memberHasSameNameAsBoundNode("templMem";
+  }
+  {
+auto Code = R"cpp(
+template 
+struct S {
+  bool operator==(int) const { return true; }
+};
+
+template 
+void func(T t) {
+  S s;
+  s.operator==(1);
+}
+)cpp";
+
+EXPECT_TRUE(matches(
+Code, cxxDependentScopeMemberExpr(hasMemberName("operator==";
+  }
+
+  // other named decl:
+  {
+auto Code = "template  struct S{ static int mem; }; struct "
+"mem{}; template "
+" void x() { S s; s.mem; }";
+
+EXPECT_TRUE(matches(
+Code,
+translationUnitDecl(has(cxxRecordDecl(hasName("mem"))),
+hasDescendant(cxxDependentScopeMemberExpr();
+
+EXPECT_FALSE(matches(
+Code,
+translationUnitDecl(has(cxxRecordDecl(hasName("mem")).bind("templMem")),
+hasDescendant(cxxDependentScopeMemberExpr(
+memberHasSameNameAsBoundNode("templMem"));
+  }
+}
+
 TEST(ASTMatchersTest, ArgumentCountIs_CXXUnresolvedConstructExpr) {
   const auto *Code =
   "template  struct S{}; template  void "
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -302,6 +302,7 @@
   REGISTER_MATCHER(hasLocalStorage);
   REGISTER_MATCHER(hasLoopInit);
   REGISTER_MATCHER(hasLoopVariable);
+  REGISTER_MATCHER(hasMemberName);
   REGISTER_MATCHER(hasMethod);
   REGISTER_MATCHER(hasName);
   REGISTER_MATCHER(hasNullSelector);
@@ -443,6 +444,7 @@
   REGISTER_MATCHER(materializeTemporaryExpr);
   REGISTER_MATCHER(member);
   REGISTER_MATCHER(memberExpr);
+  REGISTER_MATCHER(memberHasSameNameAsBoundNode);
   REGISTER_MATCHER(memberPointerType);
   REGISTER_MATCHER(namedDecl);
   REGISTER_MATCHER(namesType);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2835,6 +2835,80 @@
 StringRef, internal::hasAnyOverloadedOperatorNameFunc>
 hasAnyOverloadedOperat

[PATCH] D52957: [analyzer] Teach CallEvent about C++17 aligned new.

2020-11-06 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D52957#2377914 , @NoQ wrote:

> Everything looks good to me here. The new-expression `new int;` has 1 
> implicit argument (allocation size passed to the implementation of operator 
> new, the value is probably 4) and 0 placement arguments (the ones that are 
> explicitly written down after `new` and before `int`). See also 
> https://en.cppreference.com/w/cpp/language/new#Placement_new.

I'm still confused.

  alloc->getNumImplicitArgs(): 1
  alloc->getNumArgs(): 1
  alloc->getArgExpr(0): nullptr

I would expect `alloc->getArgExpr(0)` to return the //implicit// parameter, 
aka. the size of the placement new.
I can not see any other `getXX` function which seems applicable. My best bet 
was the `getPlacementArgExpr` thus I raised this issue here.

How can I access the placement new's allocation size of an `CXXAllocatorCall` 
if not via `getArgExpr()`?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D52957

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


[PATCH] D90886: [AMDGPU] Simplify amdgpu-macros.cl test. NFC.

2020-11-06 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4fcdfc4398bd: [AMDGPU] Simplify amdgpu-macros.cl test. NFC. 
(authored by rampitec).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90886

Files:
  clang/test/Driver/amdgpu-macros.cl

Index: clang/test/Driver/amdgpu-macros.cl
===
--- clang/test/Driver/amdgpu-macros.cl
+++ clang/test/Driver/amdgpu-macros.cl
@@ -5,66 +5,35 @@
 // R600-based processors.
 //
 
-// RUN: %clang -E -dM -target r600 -mcpu=r600 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,R600 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rv630 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,R600 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rv635 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,R600 %s
-// RUN: %clang -E -dM -target r600 -mcpu=r630 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,R630 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rs780 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,RS880 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rs880 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,RS880 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rv610 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,RS880 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rv620 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,RS880 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rv670 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,RV670 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rv710 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,RV710 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rv730 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,RV730 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rv740 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,RV770 %s
-// RUN: %clang -E -dM -target r600 -mcpu=rv770 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,RV770 %s
-// RUN: %clang -E -dM -target r600 -mcpu=cedar %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,CEDAR %s
-// RUN: %clang -E -dM -target r600 -mcpu=palm %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,CEDAR %s
-// RUN: %clang -E -dM -target r600 -mcpu=cypress %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,CYPRESS %s
-// RUN: %clang -E -dM -target r600 -mcpu=hemlock %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,CYPRESS %s
-// RUN: %clang -E -dM -target r600 -mcpu=juniper %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,JUNIPER %s
-// RUN: %clang -E -dM -target r600 -mcpu=redwood %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,REDWOOD %s
-// RUN: %clang -E -dM -target r600 -mcpu=sumo %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,SUMO %s
-// RUN: %clang -E -dM -target r600 -mcpu=sumo2 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,SUMO %s
-// RUN: %clang -E -dM -target r600 -mcpu=barts %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,BARTS %s
-// RUN: %clang -E -dM -target r600 -mcpu=caicos %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,CAICOS %s
-// RUN: %clang -E -dM -target r600 -mcpu=aruba %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,CAYMAN %s
-// RUN: %clang -E -dM -target r600 -mcpu=cayman %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,CAYMAN %s
-// RUN: %clang -E -dM -target r600 -mcpu=turks %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,TURKS %s
-
-// R600-NOT:#define FP_FAST_FMA 1
-// R630-NOT:#define FP_FAST_FMA 1
-// RS880-NOT:   #define FP_FAST_FMA 1
-// RV670-NOT:   #define FP_FAST_FMA 1
-// RV710-NOT:   #define FP_FAST_FMA 1
-// RV730-NOT:   #define FP_FAST_FMA 1
-// RV770-NOT:   #define FP_FAST_FMA 1
-// CEDAR-NOT:   #define FP_FAST_FMA 1
-// CYPRESS-NOT: #define FP_FAST_FMA 1
-// JUNIPER-NOT: #define FP_FAST_FMA 1
-// REDWOOD-NOT: #define FP_FAST_FMA 1
-// SUMO-NOT:#define FP_FAST_FMA 1
-// BARTS-NOT:   #define FP_FAST_FMA 1
-// CAICOS-NOT:  #define FP_FAST_FMA 1
-// CAYMAN-NOT:  #define FP_FAST_FMA 1
-// TURKS-NOT:   #define FP_FAST_FMA 1
-
-// R600-NOT:#define FP_FAST_FMAF 1
-// R630-NOT:#define FP_FAST_FMAF 1
-// RS880-NOT:   #define FP_FAST_FMAF 1
-// RV670-NOT:   #define FP_FAST_FMAF 1
-// RV710-NOT:   #define FP_FAST_FMAF 1
-// RV730-NOT:   #define FP_FAST_FMAF 1
-// RV770-NOT:   #define FP_FAST_FMAF 1
-// CEDAR-NOT:   #define FP_FAST_FMAF 1
-// CYPRESS-NOT: #define FP_FAST_FMAF 1
-// JUNIPER-NOT: #define FP_FAST_FMAF 1
-// REDWOOD-NOT: #define FP_FAST_FMAF 1
-// SUMO-NOT:#define FP_FAST_FMAF 1
-// BARTS-NOT:   #define FP_FAST_FMAF 1
-// CAICOS-NOT:  #define FP_FAST_FMAF 1
-// CAYMAN-NOT:  #define FP_FAST_FMAF 1
-// TURKS-NOT:   #define FP_FAST_FMAF 1
+// RUN: %clang -E -dM -target r600 -mcpu=r600 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,R600 %s -DCPU=r600
+// RUN: %clang -E -dM -target r600 -mcpu=rv630 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,R600 %s -DCPU=r600
+// RUN: %clang -E -dM -target r600 -mcpu=rv635 %s 2>&1 | FileCheck --check-prefixes=ARCH-R600,R600 %s -DCPU=r600
+//

[PATCH] D90949: [clang-format] avoid introducing multiline comments

2020-11-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
krasimir requested review of this revision.

In C++ with -Werror=comment, multiline comments are not allowed.
clang-format could accidentally introduce multiline comments when reflowing.
This adapts clang-format to not introduce multiline comments by not allowing a
break after `\`. Note that this does not apply to comment lines that already are
multiline comments, such as comments in macros.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90949

Files:
  clang/lib/Format/BreakableToken.cpp
  clang/unittests/Format/FormatTestComments.cpp


Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -745,6 +745,20 @@
getLLVMStyleWithColumns(49)));
 }
 
+TEST_F(FormatTestComments, DontIntroduceMultilineComments) {
+  // Avoid introducing a multiline comment by breaking after `\`.
+  for (int ColumnLimit = 15; ColumnLimit <= 17; ++ColumnLimit) {
+EXPECT_EQ(
+"// aa\n"
+"// \\ bb",
+format("// aa \\ bb", getLLVMStyleWithColumns(ColumnLimit)));
+EXPECT_EQ(
+"// a\n"
+"// \\  bb",
+format("// a \\  bb", getLLVMStyleWithColumns(ColumnLimit)));
+  }
+}
+
 TEST_F(FormatTestComments, DontSplitLineCommentsWithPragmas) {
   FormatStyle Pragmas = getLLVMStyleWithColumns(30);
   Pragmas.CommentPragmas = "^ IWYU pragma:";
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -102,6 +102,17 @@
 
   static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
   while (SpaceOffset != StringRef::npos) {
+// In C++ with the -Werror=comment option, having multiline comments (
+// two consecutive comment lines, the first ending in `\`) is an
+// error. Avoid introducing multiline comments by not allowing a break 
right
+// after '\'.
+if (Style.isCpp()) {
+  StringRef::size_type LastNonBlank =
+  Text.find_last_not_of(Blanks, SpaceOffset);
+  if (LastNonBlank != StringRef::npos && Text[LastNonBlank] == '\\')
+SpaceOffset = Text.find_last_of(Blanks, LastNonBlank);
+}
+
 // Do not split before a number followed by a dot: this would be 
interpreted
 // as a numbered list, which would prevent re-flowing in subsequent passes.
 if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks)))


Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -745,6 +745,20 @@
getLLVMStyleWithColumns(49)));
 }
 
+TEST_F(FormatTestComments, DontIntroduceMultilineComments) {
+  // Avoid introducing a multiline comment by breaking after `\`.
+  for (int ColumnLimit = 15; ColumnLimit <= 17; ++ColumnLimit) {
+EXPECT_EQ(
+"// aa\n"
+"// \\ bb",
+format("// aa \\ bb", getLLVMStyleWithColumns(ColumnLimit)));
+EXPECT_EQ(
+"// a\n"
+"// \\  bb",
+format("// a \\  bb", getLLVMStyleWithColumns(ColumnLimit)));
+  }
+}
+
 TEST_F(FormatTestComments, DontSplitLineCommentsWithPragmas) {
   FormatStyle Pragmas = getLLVMStyleWithColumns(30);
   Pragmas.CommentPragmas = "^ IWYU pragma:";
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -102,6 +102,17 @@
 
   static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
   while (SpaceOffset != StringRef::npos) {
+// In C++ with the -Werror=comment option, having multiline comments (
+// two consecutive comment lines, the first ending in `\`) is an
+// error. Avoid introducing multiline comments by not allowing a break right
+// after '\'.
+if (Style.isCpp()) {
+  StringRef::size_type LastNonBlank =
+  Text.find_last_not_of(Blanks, SpaceOffset);
+  if (LastNonBlank != StringRef::npos && Text[LastNonBlank] == '\\')
+SpaceOffset = Text.find_last_of(Blanks, LastNonBlank);
+}
+
 // Do not split before a number followed by a dot: this would be interpreted
 // as a numbered list, which would prevent re-flowing in subsequent passes.
 if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks)))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90767: Add new matchers for dependent names in templates

2020-11-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2859
+AST_MATCHER_P(CXXDependentScopeMemberExpr, hasMemberName, std::string, N) {
+  return Node.getMember().getAsString() == N;
+}

aaron.ballman wrote:
> steveire wrote:
> > aaron.ballman wrote:
> > > This will allow users to match on members that don't have identifiers -- 
> > > is that intentional? If not, my recommendation is to use something like:
> > > ```
> > > if (const IdentifierInfo *II = Node.getMember().getAsIdentifierInfo())
> > >   return II->isStr(N);
> > > return false;
> > > ```
> > > Either way, we should document and test what the expected behavior is for 
> > > things like constructors/destructors, overloaded operators, and the 
> > > likes. (But we don't have to test every kind of odd declaration name.)
> > I was not able to demonstrate the problem with a test: 
> > https://godbolt.org/z/3Grd1b
> > 
> > Can you be more specific?
> I was thinking of something along these lines: https://godbolt.org/z/K8serj
Added a test for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90767

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


[PATCH] D90749: [clangd] Introduce config compilation for External blocks

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/ConfigCompile.cpp:254
+// native path.
+if (!External.File && !External.Server) {
+  diag(Error, "At least one of File or Server must be specified.",

My math friends would call this "case bashing" :-)
In particular I'm cringing at the thought of adding a third option here (it's 
not likely, but I think the code would be easier to understand if it was clear 
that two is an arbitrary number).

What about:
```
unsigned SourceCount = External.File.hasValue() + External.Server.hasValue();
if (SourceCount != 1)
  return diag(Error, "Exactly one of File and Server must be set");
```
(I don't think separate error messages for missing/multiple, or any particular 
behavior for multiple, is particularly useful)



Comment at: clang-tools-extra/clangd/ConfigCompile.cpp:256
+  diag(Error, "At least one of File or Server must be specified.",
+   llvm::SMRange());
+  return;

these missing ranges are potentially pretty difficult for users - they won't 
know e.g. which file the error occurred in.

Do you think we can `Located<>` the whole `ExternalBlock`?



Comment at: clang-tools-extra/clangd/ConfigCompile.cpp:270
+  AbsPath.clear();
+  llvm::sys::path::append(AbsPath, FragmentDirectory, **External.File);
+  External.File.emplace(AbsPath.str().str());

somewhere we should be converting the paths to native slashes, I think.



Comment at: clang-tools-extra/clangd/ConfigCompile.cpp:283
+  if (FragmentDirectory.empty()) {
+diag(Error, "MountPoint must be an absolute path.",
+ External.MountPoint->Range);

pull out a method like `Optional makeAbsolute(StringRef Path, StringRef 
Description)`?



Comment at: clang-tools-extra/clangd/ConfigCompile.cpp:283
+  if (FragmentDirectory.empty()) {
+diag(Error, "MountPoint must be an absolute path.",
+ External.MountPoint->Range);

sammccall wrote:
> pull out a method like `Optional makeAbsolute(StringRef Path, 
> StringRef Description)`?
would also be good to include "Because this configuration is not associated 
with a directory"



Comment at: clang-tools-extra/clangd/ConfigCompile.cpp:300
+  C.Index.External.MountPoint = std::move(**External.MountPoint);
+  if (External.File)
+C.Index.External.File.emplace(std::move(**External.File));

we do all this validation and wind up writing back into the same data structure 
that can't represent it.
We don't actually have to validate again later, because now our invariants are 
rules, not suggestions. Still, it seems fragile, and violates a maxim that got 
stuck in my head: 
https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/

Can we have an type for this spec in config, and have only a single slot for it?
It could be as simple as:
```
struct ExternalIndexSpec { 
  enum {File, Remote} Kind;
  std::string Location; // specific to kind, hack this up later if need be
  std::string MountPoint;
};
```

I think the single biggest improvement is that we'd model "replacing the index 
for this config" as a single assignment rather than 5 coordinated ones. So if 
you want something less different, putting the `Optional` around the config 
struct instead of individual fields would be fine too. (though that would 
require it to be named)



Comment at: clang-tools-extra/clangd/ConfigCompile.cpp:305
+
+  // Disable background indexing for the files under the mountpoint.
+  // Note that this will overwrite statements in any previous fragments

hang on, you say "under the mountpoint", but... that's not what's happening.

If we want that behavior, we need to use SourceInfo::Directory as the 
mountpoint (and so probably give users a way to set that in the global config 
fragment).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90749

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


[PATCH] D87981: [X86] AMX programming model prototype.

2020-11-06 Thread akas...@illinois.edu via Phabricator via cfe-commits
akashk4 requested changes to this revision.
akashk4 added a comment.
This revision now requires changes to proceed.

It would be great if TILE_RELEASE is supported in the backend, so the scope of 
transaction is known and the configurations are at least stored to memory 
properly.




Comment at: llvm/lib/Target/X86/X86TileConfig.cpp:101
+  unsigned SubIdx = (BitSize == 8) ? X86::sub_8bit : X86::sub_16bit;
+  unsigned Opc = (BitSize == 8) ? X86::MOV8mr : X86::MOV16mr;
+  MachineInstr *NewMI =

I do not understand why wasn't PSTTILECFG used to store config to memory.  I 
guess it will be difficult to do that because we do not know the scope of a 
transaction since the TILE_RELEASE is not supported.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87981

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


[PATCH] D90434: [CodeGen] Correct codegen for self-capturing __block var

2020-11-06 Thread ille via Phabricator via cfe-commits
ille added a comment.

Ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90434

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


[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-06 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D89869#2378235 , @azabaznov wrote:

>> I guess targets like SPIR will be supporting all features by default?
>
> It sounds confusing for me: can you please elaborate about why does SPIR-V 
> target should support all features/extension by default? If we are compiling 
> OpenCL C 3.0 with optional functionality we most likely want to get an error 
> in FE level if some functionality is not supported by the target, but not in 
> BE after SPIR-V translation.

SPIR is a special abstract target that doesn't bind to any specific 
architecture. It is used in different ways but primarily to generate portable 
IR that can be loaded in toolchains for different vendors. It therefore 
normally allows all extensions and features to be compiled because the 
limitations of actualy target are not known at the point of compilation for 
SPIR. As a matter of fact if you check how extensions are implemented they are 
typically supported for SPIR.

FYI SPIR is being reused for SPIR-V translation but it is not the only use case.

What did you think in mind regarding activation of features for SPIR?


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

https://reviews.llvm.org/D89869

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


[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-06 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:110
+OPENCLFEAT_INTERNAL(__opencl_c_generic_address_space, 200, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_work_group_collective_functions, 200, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_atomic_order_acq_rel, 200, ~0U)

azabaznov wrote:
> Anastasia wrote:
> > Does this need to be in the frontend?
> I can remove features which affect only header from this file. But in this 
> case we need to extend '-cl-ext' to register unknown features/extensions 
> (http://lists.llvm.org/pipermail/cfe-dev/2020-October/066932.html). I think 
> this option functionality extending should be done in a separate commit, so 
> we can keep this kind of features here at least for now. What do you think?
Yes, absolutely let's focus on frontend only features for now. I hope we will 
clarify what we do with the rest in the next few weeks.



Comment at: clang/include/clang/Basic/OpenCLOptions.h:105
 }
 OptMap[Ext].Supported = V;
   }

azabaznov wrote:
> Anastasia wrote:
> > I guess we need to make sure that targets can't conditionally support 
> > features in OpenCL 2.0 or earlier standards.
> This can be done by adding a new method 
> //TargetInfo::setSupportedOpenCL30Features()// which can be called in 
> //::adjust//, does this make sense? I believe now current  options setting 
> (//TargetInfo::setSupportedOpenCLOpts()//) knows nothing about OpenCL version 
> which.
I would prefer to use one method for both. We could check the OpenCL version 
before invoking this or extend it with LangOpts param? Although on second 
thought since we are going this route of adding features into earlier standards 
we could just allow targets to configure in a way they like. i.e. with no extra 
checking per version allowing more flexibility if they don't need to worry 
about being stricktly conformant... as soon as it doesn't generate an integrity 
issue for old standards...


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

https://reviews.llvm.org/D89869

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


[PATCH] D52957: [analyzer] Teach CallEvent about C++17 aligned new.

2020-11-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

You cannot have an argument expression because there's no argument expression 
anywhere in the AST. There's an argument, but it's not computed as a value of 
any syntactic expression. If there was no argument, `getArgExpr(0)` would have 
crashed; but it returns a `nullptr` which indicates that there's no expression 
to return.

The argument value can be computed by taking the size of the type (and aligning 
to the requested alignment, i guess(?)) and multiplying it by array size (for 
which there is an expression) in case of array new. It'd be great to write down 
these computations once in the `CallEvent` class and then re-use them.

I guess the actual shocking truth here is that we've never performed these 
computations when inlining the allocators; the size argument that's bound to 
the size parameter in the Store while the allocator body is inlined ended up 
being a fresh symbol, which is not correct.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D52957

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


[PATCH] D90928: [OpenCL] Add assertions to extension lookup

2020-11-06 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Ok, it would still segfault but perhaps it is acceptable as this is an internal 
frontend only option for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90928

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


[PATCH] D90949: [clang-format] avoid introducing multiline comments

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

One concern about looping, otherwise just style nits.




Comment at: clang/lib/Format/BreakableToken.cpp:104
   static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
   while (SpaceOffset != StringRef::npos) {
+// In C++ with the -Werror=comment option, having multiline comments (

Can you add a high-level comment to this loop?

I guess the idea is "Some spaces are unacceptable to break on, rewind past 
them."



Comment at: clang/lib/Format/BreakableToken.cpp:105
   while (SpaceOffset != StringRef::npos) {
+// In C++ with the -Werror=comment option, having multiline comments (
+// two consecutive comment lines, the first ending in `\`) is an

The warning is worth mentioning, but fundamentally we have the warning because 
such code is confusing, and we shouldn't produce confusing code.

maybe:

```
// If a line-comment ends with `\`, the next line continues the comment,
// whether or not it starts with `//`. This is confusing and triggers -Wcomment.
// Avoid introducing multiline comments by not allowing a break after '\'.
```



Comment at: clang/lib/Format/BreakableToken.cpp:109
+// after '\'.
+if (Style.isCpp()) {
+  StringRef::size_type LastNonBlank =

Do we really want to predicate this on isCpp()? `//` comments are allowed by 
C99.
Even if the warning only applies to C++ for some reason, the reasons for 
confusion do not.



Comment at: clang/lib/Format/BreakableToken.cpp:125
 else
   break;
   }

doesn't this mean that we won't loop? if Text ends with "blah \ \" then you'll 
split between "blah" and the first "\"?

I guess this could be structured:

```
while () {
  if (special case 1) {
// adjust pos
continue;
  }
  if (special case 2) {
// adjust pos
continue;
  }
  break;
}
```

(This is equivalent to the old if/elseif/break which is too hard to add complex 
conditions to)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90949

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


[PATCH] D90714: [clang]Fix length threshold for MicrosoftMangle md5 hash

2020-11-06 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 303477.
mibintc added a comment.

Fixed test case according to @dblaikie 's suggestion and input, thanks a lot 
David, the test case is certainly a lot easier to read and understand now.  
Anything else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90714

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  clang/test/CodeGenCXX/mangle-ms-md5.cpp

Index: clang/test/CodeGenCXX/mangle-ms-md5.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-md5.cpp
+++ clang/test/CodeGenCXX/mangle-ms-md5.cpp
@@ -1,12 +1,38 @@
 // RUN: %clang_cc1 -emit-llvm -o - -triple i686-pc-win32 %s | FileCheck %s
-int xxx;
+// Define macros, using token pasting, to build up an identifier of any length
+#define C_(P1, P2) P1##P2
+#define C2(P1, P2) C_(P1

[PATCH] D90747: [clangd] Mark AsyncTaskRunner::runAsync as const

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

AsyncTaskRunner is definitely threadsafe, but const doesn't exactly mean 
threadsafe...

This might be OK or maybe we should put `mutable` at the callsite - can you 
show the real example?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90747

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


[PATCH] D90956: [clang][SVE] Additional macros implied by `-msve-vector-bits=`.

2020-11-06 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli created this revision.
fpetrogalli added reviewers: peterwaller-arm, paulwalker-arm, efriedma, 
c-rhodes.
Herald added subscribers: cfe-commits, psnobl, kristof.beyls, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: clang.
fpetrogalli requested review of this revision.

The following macros are activated when the compiler is targeting SVE
with the option `-msve-vector-bits=`:

1. __ARM_FEATURE_SVE_VECTOR_OPERATORS
2. __ARM_FEATURE_SVE_PREDICATE_OPERATORS

The behavior implied by the macros is described in sections 3.7.3.3
and 3.7.3.4 respectively of the SVE ACLE (Version 00bet6) that can be
found at https://developer.arm.com/documentation/100987/latest


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90956

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_PREDICATE_OPERATORS.c
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_PREDICATE_OPERATORS.cpp
  
clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS-expected-error-on-address.c
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp
  clang/test/Preprocessor/aarch64-target-features.c

Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -440,14 +440,11 @@
 // CHECK-BFLOAT: __ARM_FEATURE_BF16_VECTOR_ARITHMETIC 1
 
 // == Check sve-vector-bits flag.
-// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=128 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS-128 %s
-// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=256 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS-256 %s
-// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=512 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS-512 %s
-// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=1024 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS-1024 %s
-// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=2048 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS-2048 %s
-// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=2048 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS-2048 %s
-// CHECK-SVE-VECTOR-BITS-128: __ARM_FEATURE_SVE_BITS 128
-// CHECK-SVE-VECTOR-BITS-256: __ARM_FEATURE_SVE_BITS 256
-// CHECK-SVE-VECTOR-BITS-512: __ARM_FEATURE_SVE_BITS 512
-// CHECK-SVE-VECTOR-BITS-1024: __ARM_FEATURE_SVE_BITS 1024
-// CHECK-SVE-VECTOR-BITS-2048: __ARM_FEATURE_SVE_BITS 2048
+// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=128  -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS -D#VBITS=128  %s
+// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=256  -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS -D#VBITS=256  %s
+// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=512  -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS -D#VBITS=512  %s
+// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=1024 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS -D#VBITS=1024 %s
+// RUN: %clang -target aarch64-arm-none-eabi -march=armv8-a+sve -msve-vector-bits=2048 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-SVE-VECTOR-BITS -D#VBITS=2048 %s
+// CHECK-SVE-VECTOR-BITS: __ARM_FEATURE_SVE_BITS [[#VBITS:]]
+// CHECK-SVE-VECTOR-BITS: __ARM_FEATURE_SVE_PREDICATE_OPERATORS 1
+// CHECK-SVE-VECTOR-BITS: __ARM_FEATURE_SVE_VECTOR_OPERATORS 1
Index: clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -x c++ -S -emit-llvm -c -O1 -o - %s -target aarch64-gnu-linux \
+// RUN: -march=armv8-a+sve -msve-vector-bits=256 | FileCheck %s
+// RUN: %clang -x c++ -S -emit-llvm -c -O1 -o - %s -target aarch64-gnu-linux \
+// RUN: -march=armv8-a+sve -msve-vector-bits=512 | FileCheck %s --check-prefix=CHECK512
+// REQUIRES: aarch64-registered-target
+
+// Examples taken from section 3.7.3.3 of the SVE ACLE (Version
+// 00bet6) that can be found at
+// https://developer.arm.com/documentation/100987/latest
+
+#include 
+
+// Page 27, item 1.
+#if __ARM_FEATURE_SVE_BITS == 512 && __ARM_FEATURE_SVE_VECTOR_OPERATORS
+// CHECK512-LABEL: define {{.*}}  @_Z1f9__SVE_VLSIu11__SVInt32_tLj512EES_( %x.coerce,  %y

[PATCH] D90775: [clangd] ExternalIndex turns off BackgroundIndex only if it isn't set

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I'm not sure we should do this - it complicates the model substantially (I 
don't think I could explain it to a user), and it still leaves surprising cases.

I'm not sure config is the place for a lot of magic do-what-I-mean behavior - 
it's the place where the user overrides such behaviors.

(If you think the combinations are too confusing, we could consider *not* 
disabling background index implicitly for external indexes, and simply warning 
instead)




Comment at: clang-tools-extra/clangd/ConfigCompile.cpp:306
+  // Disable background indexing for the files under the mountpoint. If
+  // user didn't take any explicit actions.
+  if (C.Index.Background == Config::BackgroundPolicy::Auto)

This is vague and hard to specify more precisely.



Comment at: clang-tools-extra/clangd/ConfigCompile.cpp:308
+  if (C.Index.Background == Config::BackgroundPolicy::Auto)
+C.Index.Background = Config::BackgroundPolicy::Skip;
 });

doesn't this mean that if a user has explicit `Background: Build` at a higher 
scope, then a more narrowly scoped external index won't disable it?

This seems at least as confusing as the problems this is trying to solve.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90775

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


[PATCH] D82699: [driver][arm64] Set target CPU to A12 for compiler invocations that target Apple Silicon

2020-11-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Testing this out: `--target=arm64-apple-macos` now does the right thing, but 
`-march arm64` sets the target triple to iOS (and hence doesn't pass the a12 
cpu either). That's different from what Xcode clang does. Could you upstream 
whatever causes that difference too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82699

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


[PATCH] D82699: [driver][arm64] Set target CPU to A12 for compiler invocations that target Apple Silicon

2020-11-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

(If `-mmacosx-version-min` is passed too, open-source clang does the right 
thing, but for quick command-line testing it'd be nice if both clangs behaved 
consistently.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82699

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


[PATCH] D90765: [ARM][AArch64] Adding Neoverse V1 CPU support

2020-11-06 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas updated this revision to Diff 303486.
pratlucas added a comment.

Updating default extensions in target parser to match tablegen features.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90765

Files:
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arm-cortex-cpus.c
  llvm/include/llvm/MC/SubtargetFeature.h
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMSubtarget.cpp
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/test/CodeGen/AArch64/cpus.ll
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -8,7 +8,9 @@
 
 #include "llvm/Support/TargetParser.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/ARMBuildAttributes.h"
+#include "llvm/Support/ARMTargetParser.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -280,6 +282,12 @@
 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_FP16 |
 ARM::AEK_RAS | ARM::AEK_DOTPROD,
 "8.2-A"));
+  EXPECT_TRUE(testARMCPU("neoverse-v1", "armv8.4-a", "crypto-neon-fp-armv8",
+ ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
+ ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
+ ARM::AEK_DSP | ARM::AEK_CRC | ARM::AEK_RAS |
+ ARM::AEK_FP16 | ARM::AEK_BF16 | ARM::AEK_DOTPROD,
+ "8.4-A"));
   EXPECT_TRUE(testARMCPU("cyclone", "armv8-a", "crypto-neon-fp-armv8",
  ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
  ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
@@ -322,7 +330,7 @@
  "7-S"));
 }
 
-static constexpr unsigned NumARMCPUArchs = 89;
+static constexpr unsigned NumARMCPUArchs = 90;
 
 TEST(TargetParserTest, testARMCPUArchList) {
   SmallVector List;
@@ -881,6 +889,14 @@
   AArch64::AEK_LSE | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
   AArch64::AEK_RCPC | AArch64::AEK_SSBS,
   "8.2-A"));
+  EXPECT_TRUE(testAArch64CPU(
+  "neoverse-v1", "armv8.4-a", "crypto-neon-fp-armv8",
+  AArch64::AEK_RAS | AArch64::AEK_SVE | AArch64::AEK_SSBS |
+  AArch64::AEK_RCPC | AArch64::AEK_CRC | AArch64::AEK_FP |
+  AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
+  AArch64::AEK_RDM | AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+  AArch64::AEK_CRYPTO | AArch64::AEK_FP16 | AArch64::AEK_BF16,
+  "8.4-A"));
   EXPECT_TRUE(testAArch64CPU(
  "cortex-r82", "armv8-r", "crypto-neon-fp-armv8",
   AArch64::AEK_CRC | AArch64::AEK_RDM  | AArch64::AEK_SSBS|
@@ -1034,7 +1050,7 @@
   "8.2-A"));
 }
 
-static constexpr unsigned NumAArch64CPUArchs = 43;
+static constexpr unsigned NumAArch64CPUArchs = 44;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/test/CodeGen/AArch64/cpus.ll
===
--- llvm/test/CodeGen/AArch64/cpus.ll
+++ llvm/test/CodeGen/AArch64/cpus.ll
@@ -20,6 +20,7 @@
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=cortex-x1 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=neoverse-e1 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=neoverse-n1 2>&1 | FileCheck %s
+; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=neoverse-v1 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=exynos-m3 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=exynos-m4 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=exynos-m5 2>&1 | FileCheck %s
Index: llvm/lib/Target/ARM/ARMSubtarget.h
===
--- llvm/lib/Target/ARM/ARMSubtarget.h
+++ llvm/lib/Target/ARM/ARMSubtarget.h
@@ -76,6 +76,7 @@
 Krait,
 Kryo,
 NeoverseN1,
+NeoverseV1,
 Swift
   };
   enum ARMProcClassEnum {
Index: llvm/lib/Target/ARM/ARMSubtarget.cpp
===
--- llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -314,6 +314,7 @@
 PreISelOperandLatencyAdjustment = 1;
 break;
   case NeoverseN1:
+  case NeoverseV1:
 break;
   case Swift:
 MaxInterleaveFactor = 2;
Index: llvm/lib/Target/ARM/ARM.td
===
--- llvm/lib/Target/ARM/ARM.td
+++ llvm/lib/Target/ARM/ARM.td
@@ -601,6 +601,9 @@
 def ProcX1  : SubtargetFeature<

[PATCH] D90957: Frontend: Skip namespace around createVFSFromCompilerInvocation definition, NFC

2020-11-06 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added reviewers: arphaman, jansvoboda11, JDevlieghere.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

Qualify definitions with `clang::` rather than opening/closing a namespace.


https://reviews.llvm.org/D90957

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4072,16 +4072,15 @@
 #undef OPTION_WITH_MARSHALLING_FLAG
 }
 
-namespace clang {
-
 IntrusiveRefCntPtr
-createVFSFromCompilerInvocation(const CompilerInvocation &CI,
-DiagnosticsEngine &Diags) {
+clang::createVFSFromCompilerInvocation(const CompilerInvocation &CI,
+   DiagnosticsEngine &Diags) {
   return createVFSFromCompilerInvocation(CI, Diags,
  llvm::vfs::getRealFileSystem());
 }
 
-IntrusiveRefCntPtr createVFSFromCompilerInvocation(
+IntrusiveRefCntPtr
+clang::createVFSFromCompilerInvocation(
 const CompilerInvocation &CI, DiagnosticsEngine &Diags,
 IntrusiveRefCntPtr BaseFS) {
   if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty())
@@ -4109,5 +4108,3 @@
   }
   return Result;
 }
-
-} // namespace clang


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4072,16 +4072,15 @@
 #undef OPTION_WITH_MARSHALLING_FLAG
 }
 
-namespace clang {
-
 IntrusiveRefCntPtr
-createVFSFromCompilerInvocation(const CompilerInvocation &CI,
-DiagnosticsEngine &Diags) {
+clang::createVFSFromCompilerInvocation(const CompilerInvocation &CI,
+   DiagnosticsEngine &Diags) {
   return createVFSFromCompilerInvocation(CI, Diags,
  llvm::vfs::getRealFileSystem());
 }
 
-IntrusiveRefCntPtr createVFSFromCompilerInvocation(
+IntrusiveRefCntPtr
+clang::createVFSFromCompilerInvocation(
 const CompilerInvocation &CI, DiagnosticsEngine &Diags,
 IntrusiveRefCntPtr BaseFS) {
   if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty())
@@ -4109,5 +4108,3 @@
   }
   return Result;
 }
-
-} // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90956: [clang][SVE] Additional macros implied by `-msve-vector-bits=`.

2020-11-06 Thread Renato Golin via Phabricator via cfe-commits
rengolin accepted this revision.
rengolin added a comment.
This revision is now accepted and ready to land.

Simple and straightforward, with documentation! :)

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90956

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


[PATCH] D90765: [ARM][AArch64] Adding Neoverse V1 CPU support

2020-11-06 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

Thanks. LGTM




Comment at: llvm/unittests/Support/TargetParserTest.cpp:10-11
 #include "llvm/Support/TargetParser.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/ARMBuildAttributes.h"

Are these needed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90765

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


[PATCH] D84192: [OpenMP5.0] map item can be non-contiguous for target update

2020-11-06 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen updated this revision to Diff 303495.
cchen added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84192

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/target_update_ast_print.cpp
  clang/test/OpenMP/target_update_codegen.cpp
  clang/test/OpenMP/target_update_messages.cpp
  clang/test/OpenMP/target_update_to_messages.cpp

Index: clang/test/OpenMP/target_update_to_messages.cpp
===
--- clang/test/OpenMP/target_update_to_messages.cpp
+++ clang/test/OpenMP/target_update_to_messages.cpp
@@ -79,6 +79,10 @@
 #pragma omp target update to(*(*(this->ptr)+a+this->ptr)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
 #pragma omp target update to(*(this+this)) // expected-error {{invalid operands to binary expression ('S8 *' and 'S8 *')}}
 {}
+
+double marr[10][5][10];
+#pragma omp target update to(marr [0:1][2:4][1:2]) // le45-error {{array section does not specify contiguous storage}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
+{}
   }
 };
 
Index: clang/test/OpenMP/target_update_messages.cpp
===
--- clang/test/OpenMP/target_update_messages.cpp
+++ clang/test/OpenMP/target_update_messages.cpp
@@ -136,6 +136,25 @@
 foo();
   }
 
+  double marr[10][5][10];
+#pragma omp target update to(marr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
+  {}
+#pragma omp target update from(marr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
+
+#pragma omp target update to(marr[0:][1:2:2][1:2]) // ge50-error {{array section does not specify length for outermost dimension}} lt50-error {{expected ']'}} lt50-note {{to match this '['}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
+  {}
+#pragma omp target update from(marr[0:][1:2:2][1:2]) // ge50-error {{array section does not specify length for outermost dimension}} lt50-error {{expected ']'}} lt50-note {{to match this '['}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
+
+  int arr[4][3][2][1];
+#pragma omp target update to(arr[0:2][2:4][:2][1]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
+  {}
+#pragma omp target update from(arr[0:2][2:4][:2][1]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
+
+  double ***dptr;
+#pragma omp target update to(dptr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} ge50-error 2 {{section length is unspecified and cannot be inferred because subscripted value is an array of unknown bound}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
+  {}
+#pragma omp target update from(dptr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} ge50-error 2 {{section length is unspecified and cannot be inferred because subscripted value is an array of unknown bound}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
+
   int iarr[5][5];
 // ge50-error@+4 {{section stride is evaluated to a non-positive value -1}}
 // lt50-error@+3 {{expected ']'}}
@@ -148,6 +167,21 @@
 // lt50-note@+2 {{to match this '['}}
 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
 #pragma omp target update from(iarr[0:][1:2:-1])
+  {}
+// lt50-error@+5 {{expected expression}}
+// ge50-error@+4 {{array section does not specify length for outermost dimension}}
+// lt50-error@+3 {{expected ']'}}
+// lt50-note@+2 {{to match this '['}}
+// lt50-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
+#pragma omp target update to(iarr[0: :2][1:2])
+  {}
+// lt50-error@+5 {{expected expression}}
+// ge50-error@+4 {{array section does not specify len

[PATCH] D90767: Add new matchers for dependent names in templates

2020-11-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2859
+AST_MATCHER_P(CXXDependentScopeMemberExpr, hasMemberName, std::string, N) {
+  return Node.getMember().getAsString() == N;
+}

steveire wrote:
> aaron.ballman wrote:
> > steveire wrote:
> > > aaron.ballman wrote:
> > > > This will allow users to match on members that don't have identifiers 
> > > > -- is that intentional? If not, my recommendation is to use something 
> > > > like:
> > > > ```
> > > > if (const IdentifierInfo *II = Node.getMember().getAsIdentifierInfo())
> > > >   return II->isStr(N);
> > > > return false;
> > > > ```
> > > > Either way, we should document and test what the expected behavior is 
> > > > for things like constructors/destructors, overloaded operators, and the 
> > > > likes. (But we don't have to test every kind of odd declaration name.)
> > > I was not able to demonstrate the problem with a test: 
> > > https://godbolt.org/z/3Grd1b
> > > 
> > > Can you be more specific?
> > I was thinking of something along these lines: https://godbolt.org/z/K8serj
> Added a test for that.
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90767

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


[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-06 Thread Vasily Kulikov via Phabricator via cfe-commits
segoon updated this revision to Diff 303499.
segoon added a comment.

don't include any system headers in tests


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

https://reviews.llvm.org/D90944

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp
  clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s misc-mt-unsafe %t
+
+extern unsigned int sleep (unsigned int __seconds);
+extern int *gmtime (const int *__timer);
+
+void foo() {
+  sleep(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+
+  ::sleep(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+
+  auto tm = gmtime(nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function is not thread safe [misc-mt-unsafe]
+  tm = ::gmtime(nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: function is not thread safe [misc-mt-unsafe]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - misc-mt-unsafe
+
+misc-mt-unsafe
+==
+
+Checks for some thread-unsafe functions against a black list of
+known-to-be-unsafe functions. Usually they access static variables without
+synchronization (e.g. gmtime(3)) or utilize signals in a racy way.
+
+Examples:
+
+.. code-block:: c++
+
+tm = gmtime(timep); // uses a global buffer
+
+sleep(1); // implementation may use SIGALRM
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -30,7 +30,7 @@
`abseil-time-comparison `_, "Yes"
`abseil-time-subtraction `_, "Yes"
`abseil-upgrade-duration-conversions `_, "Yes"
-   `altera-struct-pack-align `_,
+   `altera-struct-pack-align `_, "Yes"
`android-cloexec-accept `_, "Yes"
`android-cloexec-accept4 `_,
`android-cloexec-creat `_, "Yes"
@@ -143,6 +143,7 @@
`cppcoreguidelines-narrowing-conversions `_,
`cppcoreguidelines-no-malloc `_,
`cppcoreguidelines-owning-memory `_,
+   `cppcoreguidelines-prefer-member-initializer `_, "Yes"
`cppcoreguidelines-pro-bounds-array-to-pointer-decay `_,
`cppcoreguidelines-pro-bounds-constant-array-index `_, "Yes"
`cppcoreguidelines-pro-bounds-pointer-arithmetic `_,
@@ -179,7 +180,6 @@
`google-readability-todo `_,
`google-runtime-int `_,
`google-runtime-operator `_,
-   `google-runtime-references `_,
`google-upgrade-googletest-case `_, "Yes"
`hicpp-avoid-goto `_,
`hicpp-exception-baseclass `_,
@@ -198,6 +198,7 @@
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
+   `misc-mt-unsafe `_, "Yes"
`misc-new-delete-overloads `_,
`misc-no-recursion `_,
`misc-non-copyable-objects `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -106,6 +106,10 @@
   Finds condition variables in nested ``if`` statements that were also checked
   in the outer ``if`` statement and were not changed.
 
+- New :doc:`misc-mt-unsafe ` check.
+
+  Finds thread-unsafe functions usage.
+
 - New :doc:`readability-function-cognitive-complexity
   ` check.
 
Index: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.h
@@ -0,0 +1,34 @@
+//===--- MtUnsafeCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MTUNSAFECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MTUNSAFECHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+/// Checks that non-thread-safe funct

[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-06 Thread Vasily Kulikov via Phabricator via cfe-commits
segoon marked an inline comment as done.
segoon added inline comments.



Comment at: clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp:3-4
+
+#include 
+#include 
+

lebedev.ri wrote:
> Tests should be hermetic, they can not use headers from system
fixed


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

https://reviews.llvm.org/D90944

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


[PATCH] D90714: [clang]Fix length threshold for MicrosoftMangle md5 hash

2020-11-06 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.

Generally looks good, thanks!

The inline comment trying to understand the `4095 - 4088 == 7` math I think 
should be answered (possibly in the form of the test/CHECK rephrasing I 
mentioned to clarify what the extra 7 characters are, and maybe some more 
detail in the comment too, if needed) - the rest of the suggestions are 
minor/optional.
It might also be good to split up the patch and commit the new macros/cleanup 
of the existing tests in one patch, then the fix+new tests in another. This way 
if there's a problem with one of the patches it'd be easier to 
identify/separate from the other.




Comment at: clang/test/CodeGenCXX/mangle-ms-md5.cpp:26-28
+int X4095(x);
+#define Y4096 X4096(y)
+#define Y4095 X4095(y)

After I wrote a few of these and realized the test needs different names (so 
parameterizing the macro on the character to duplicate helps that), but then 
the X became ambiguous/confusing with the literal 'x' in the names. To 
avoid/reduce that confusion it might make sense to use some other letter (I had 
used X for the macro then a, b, c, etc for the real identifiers - but maybe 
that's still a bit confusing because "X" does tend to get used in x, y, z 
example names too, even if this test file was changed to avoid that) - R for 
Repeated?

Then probably the Z4089 and Z4089 could be removed (since they're only defined 
on one line and used once immediately after) and the macros used directly like 
on line 26 above. Though I can appreciate Y4095 being kept because it's used 
several times (I could go either way on that one)




Comment at: clang/test/CodeGenCXX/mangle-ms-md5.cpp:27
+int X4095(x);
+#define Y4096 X4096(y)
+#define Y4095 X4095(y)

This one's unused & could be removed, I think?



Comment at: clang/test/CodeGenCXX/mangle-ms-md5.cpp:55
+// Verify the threshold where md5 mangling kicks in
+// Create an ident with 4088 characters, pre-hash, MangleName.size() is 4095
+#define X4088(X)\

Might be worth some more words to describe what the 7 other characters are? (to 
help explain the "magic" number 4088)

Oh, one way might be to change the `CHECK-DAG` on 63 to verify the full name. 
You could use a regex to match all the `z`s compactly but precisely (eg: 
`@"{{\?z{4088}@@3HA}}"`)*, rather than what I guess is a sample of 4 `z`s 
currently? That way it's clear what the other 7 characters are? (though I only 
count 6 other characters in my small examples - so I'd expect 4088 `z` plus 
those six to reach 4094, not 4095?)

* might have to muck with the regex syntax a smidge - I always forget which 
things need escaping and which things don't





Comment at: clang/test/CodeGenCXX/mangle-ms-md5.cpp:61-62
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+#define Z4088 X4088(z) // pre-hash, MangleName.size() is 4095
+int Z4088 = 1515;
+// CHECK-DAG: {{.*}}{{.*}} = dso_local global i32 1515, align 4

As on line 26, it's probably simple enough to skip the extra macro and write 
this as `int X4088(z) = 1515;`

(& as on line 26, probably skip the "= 1515" unless that adds some value (no 
pun intended) to the test? I'm guessing it's not important what value, if any, 
the variable is initialized with?)



Comment at: clang/test/CodeGenCXX/mangle-ms-md5.cpp:66-70
+#define X4089(X)\
+C2(C2(  \
+  C4(X2(X),   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),  X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))

Could you align the commas and trailing backslashes here and in the X4088 one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90714

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


[PATCH] D90555: [clangd] Handle duplicate enum constants in PopulateSwitch tweak

2020-11-06 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 303502.
njames93 added a comment.

Addressed comments.
Now using a MapVector to collect all uncovered cases in prepare, then just loop 
over that in apply.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90555

Files:
  clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  llvm/include/llvm/ADT/DenseMapInfo.h

Index: llvm/include/llvm/ADT/DenseMapInfo.h
===
--- llvm/include/llvm/ADT/DenseMapInfo.h
+++ llvm/include/llvm/ADT/DenseMapInfo.h
@@ -14,6 +14,7 @@
 #define LLVM_ADT_DENSEMAPINFO_H
 
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringRef.h"
@@ -371,6 +372,26 @@
   }
 };
 
+/// Provide DenseMapInfo for APSInt, using the DenseMapInfo for APInt.
+template <> struct DenseMapInfo {
+  static inline APSInt getEmptyKey() {
+return APSInt(DenseMapInfo::getEmptyKey());
+  }
+
+  static inline APSInt getTombstoneKey() {
+return APSInt(DenseMapInfo::getTombstoneKey());
+  }
+
+  static unsigned getHashValue(const APSInt &Key) {
+return static_cast(hash_value(Key));
+  }
+
+  static bool isEqual(const APSInt &LHS, const APSInt &RHS) {
+return LHS.getBitWidth() == RHS.getBitWidth() &&
+   LHS.isUnsigned() == RHS.isUnsigned() && LHS == RHS;
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_ADT_DENSEMAPINFO_H
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2980,6 +2980,18 @@
 void function() { switch (ns::A) {case ns::A:break;} }
   )"",
   },
+  {
+  // Duplicated constant names
+  Function,
+  R""(enum Enum {A,B,b=B}; ^switch (A) {})"",
+  R""(enum Enum {A,B,b=B}; switch (A) {case A:case B:break;})"",
+  },
+  {
+  // Duplicated constant names all in switch
+  Function,
+  R""(enum Enum {A,B,b=B}; ^switch (A) {case A:case B:break;})"",
+  "unavailable",
+  },
   };
 
   for (const auto &Case : Cases) {
Index: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -40,6 +40,8 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallSet.h"
 #include 
 #include 
@@ -62,6 +64,10 @@
   const CompoundStmt *Body = nullptr;
   const EnumType *EnumT = nullptr;
   const EnumDecl *EnumD = nullptr;
+  // Maps the Enum values to the EnumConstantDecl and a bool signifying if its
+  // covered in the switch.
+  llvm::MapVector>
+  EnumConstants;
 };
 
 REGISTER_TWEAK(PopulateSwitch)
@@ -112,21 +118,33 @@
   if (!EnumD)
 return false;
 
-  // We trigger if there are fewer cases than enum values (and no case covers
-  // multiple values). This guarantees we'll have at least one case to insert.
-  // We don't yet determine what the cases are, as that means evaluating
-  // expressions.
-  auto I = EnumD->enumerator_begin();
-  auto E = EnumD->enumerator_end();
+  // We trigger if there are any values in the enum that aren't covered by the
+  // switch.
 
-  for (const SwitchCase *CaseList = Switch->getSwitchCaseList();
-   CaseList && I != E; CaseList = CaseList->getNextSwitchCase(), I++) {
+  ASTContext &Ctx = Sel.AST->getASTContext();
+
+  unsigned EnumIntWidth = Ctx.getIntWidth(QualType(EnumT, 0));
+  bool EnumIsSigned = EnumT->isSignedIntegerOrEnumerationType();
+
+  EnumConstants.clear();
+
+  for (auto *EnumConstant : EnumD->enumerators()) {
+llvm::APSInt Val = EnumConstant->getInitVal();
+Val = Val.extOrTrunc(EnumIntWidth);
+Val.setIsSigned(EnumIsSigned);
+EnumConstants.insert(
+std::make_pair(Val, std::make_pair(EnumConstant, false)));
+  }
+
+  for (const SwitchCase *CaseList = Switch->getSwitchCaseList(); CaseList;
+   CaseList = CaseList->getNextSwitchCase()) {
 // Default likely intends to cover cases we'd insert.
 if (isa(CaseList))
   return false;
 
 const CaseStmt *CS = cast(CaseList);
-// Case statement covers multiple values, so just counting doesn't work.
+
+// GNU range cases are rare, we don't support them.
 if (CS->caseStmtIsGNURange())
   return false;
 
@@ -135,48 +153,45 @@
 const ConstantExpr *CE = dyn_cast(CS->getLHS());
 if (!CE || CE->isValueDependent())
   return false;
+
+// Unsure if this case could 

[PATCH] D90555: [clangd] Handle duplicate enum constants in PopulateSwitch tweak

2020-11-06 Thread Nathan James via Phabricator via cfe-commits
njames93 marked 6 inline comments as done.
njames93 added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:117
 
-  // We trigger if there are fewer cases than enum values (and no case covers
-  // multiple values). This guarantees we'll have at least one case to insert.
-  // We don't yet determine what the cases are, as that means evaluating
-  // expressions.
-  auto I = EnumD->enumerator_begin();
-  auto E = EnumD->enumerator_end();
+  // Special case of the empty enum
+  if (EnumD->enumerator_begin() == EnumD->enumerator_end())

sammccall wrote:
> why is the special case needed?
It wasn't was causing a bug early on then i fixed it and it was no longer needed



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:126
+
+  llvm::SmallMapVector EnumConstants;
+  for (auto *EnumConstant : EnumD->enumerators()) {

sammccall wrote:
> It looks as if we're now doing (via prepare + apply combined):
> 
> 1. Collect all constants into a `SmallMapVector`.
> 2. Iterate over cases, marking covered constants
> 3. Prepare returns true if there are unmarked constants
> 4. Collect all cases into a `SmallSet`
> 5. Iterate over the constants, inserting text for those not in the set.
> 
> This seems equivalent, but less redundant:
> 1. Collect all constants into a `MapVector` (e.g. 
> `MissingEnumerators`)
> 2. Iterate over cases, deleting covered constants
> 3. Prepare returns true if any constant remains
> 4. Iterate over the map, inserting text for every element in the map
Thats a great suggestion. I did alter it slightly using a 
`std::pair` for the value. This is because it would be 
nice to catch the case where the switch has a duplicated case value. The other 
reason is its linear time to call erase on a MapVector, so its potentially 
O(N^2) when looping through all the cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90555

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


[PATCH] D90531: [clangd] Add clang-tidy options to config

2020-11-06 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clangd/Config.h:78
+std::string Checks;
+std::vector> CheckOptions;
+  } ClangTidy;

sammccall wrote:
> I think this should be a StringMap
> 
> It makes sense to use a vector-of-pairs in ConfigFragment to preserve the 
> Located information for keys, but we don't need to do that in Config.
If we do use a `StringMap`, whats the policy when multiple fragments 
specify the same option.
Currently at the Fragment level there is logic that ignores duplicated keys, 
but when compiling the fragments, should we give priority to keys declared in 
earlier or later fragments. In any case would it also be wise to warn about 
that.



Comment at: clang-tools-extra/clangd/ConfigFragment.h:183
+  struct ClangTidyBlock {
+llvm::Optional> Enable;
+/// List of checks to enable or disable, can use wildcards.

sammccall wrote:
> njames93 wrote:
> > sammccall wrote:
> > > I wonder if it's worth having this when we support `Remove: *`.
> > > 
> > > technically this does something slightly different:
> > >  - it still runs the machinery just with no actual checks
> > >  - you can enable: true later to override it, without losing the 
> > > previously configured list of checks
> > > 
> > > Is one of these important? Is there some other benefit?
> > > (I'm not opposed to having this if you want it, but I'm curious)
> > I'm not 100% sure what you are asking here.
> I'm asking whether we really need `Enable`, or whether we should remove it 
> and recommend `Remove: *` to disable the checks.
> 
> If there isn't a clear reason we need it, my preference is to omit it for 
> simplicity (we can add more setting later, but it's harder to remove them).
> 
> I don't feel strongly though, this is up to you.
If we use `Remove: *` when it comes to actually implementing this, it would be 
wise to disable running clang-tidy if there are no checks enabled. But yes, I 
do agree that it could be removed at first, then added at a later date if needs 
must.



Comment at: clang-tools-extra/clangd/ConfigYAML.cpp:188
 
+  class DynamicDictParser {
+  public:

sammccall wrote:
> njames93 wrote:
> > sammccall wrote:
> > > instead of adding a second class for this, can we reuse DictParser, and 
> > > change `unrecognized()` so:
> > >  - the callback gets access to the key location and the value
> > >  - the callback is responsible for emitting the "unknown key" error if it 
> > > wants one
> > > 
> > > i.e. the default `unrecognized` handler is:
> > > 
> > > ```
> > > [this](Located Key, Node &Value) { Outer->warning("Unknown " 
> > > + Description + " key " + *Key); }
> > > ```
> > > 
> > > and we replace it for parsing CheckOptions
> > Not sure I'm a huge fan of that approach. I can't imagine a use case where 
> > the 2 dictionary modes will be used at the same time so there isn't a need 
> > for it to support both. 
> > By that I mean you wont have a dictionary where its expected to have both 
> > known and unknown keys.
> > 
> > `DictParser` could well be implemented as a a specialisation of 
> > `DynamicDictParser` but not much would be gained from that.
> Yes, they're being used for different purposes, so using the same class isn't 
> the most expressive.
> But this isn't a public API, it's a local helper. The implementation is 
> nontrivial and almost identical. This is just about reducing the 
> implementation complexity.
Ok I'll update it.



Comment at: clang-tools-extra/clangd/ConfigYAML.cpp:235
+  // Try to parse a single boolean value from the node, warn on failure.
+  llvm::Optional> scalarBool(Node &N, llvm::StringRef Desc) {
+llvm::SmallString<256> Buf;

sammccall wrote:
> sammccall wrote:
> > can we implement this on top of scalarValue? seems like it would avoid a 
> > bunch of repetition and the efficiency doesn't seem that important
> You've extracted a common getScalar function here instead, I think to avoid 
> scalarValue copying the string?
> But this isn't a hot path, and all the legal values for this string are in 
> SSO range anyway - can we avoid this extra complexity?
It's not about that, I'd prefer the warning message to explicitly say it needs 
a boolean even if they pass something that's not a scalar. Reusing 
`scalarValue` will give a warning saying `SomeKey should be scalar`. What we 
actually want is a warning saying `SomeKey should be a boolean`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90531

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


[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-06 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

It appears to not check for signs that the code is running in a multi threaded 
manner, This will result in many false positives in code that is known to be 
single threaded.




Comment at: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp:19
+
+namespace {
+

Don't use an anonymous namespace, just make the decls contained static.



Comment at: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp:199
+  diag(Call->getBeginLoc(), "function is not thread safe")
+  << SourceRange(Call->getBeginLoc(), Call->getEndLoc());
+}

I don't think this range needs appending onto the diagnostic.



Comment at: clang-tools-extra/docs/clang-tidy/checks/list.rst:33
`abseil-upgrade-duration-conversions 
`_, "Yes"
-   `altera-struct-pack-align `_,
+   `altera-struct-pack-align `_, "Yes"
`android-cloexec-accept `_, "Yes"

Can you undo this change and all other unrelated changes to this file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90944

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


[PATCH] D90963: Allow searching for prebuilt implicit modules.

2020-11-06 Thread Alexandre Rames via Phabricator via cfe-commits
arames created this revision.
arames added a reviewer: stella.stamenova.
Herald added subscribers: cfe-commits, dang.
Herald added a project: clang.
arames requested review of this revision.

This reverts commit c67656b994c87224e0b33e2c4b09093986a5cfa6 
, and 
addresses the
build issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90963

Files:
  clang/docs/Modules.rst
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/CompilerInstance.h
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/HeaderSearchOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/prebuilt-implicit-module/a.h
  clang/test/Modules/Inputs/prebuilt-implicit-module/module.modulemap
  clang/test/Modules/prebuilt-implicit-modules.m

Index: clang/test/Modules/prebuilt-implicit-modules.m
===
--- /dev/null
+++ clang/test/Modules/prebuilt-implicit-modules.m
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x objective-c -fmodules %S/Inputs/prebuilt-implicit-module/module.modulemap -emit-module -fmodule-name=module_a -fmodules-cache-path=%t
+// RUN: find %t -name "module_a*.pcm" | grep module_a
+
+// Check we use a prebuilt module when available, and do not build an implicit module.
+// RUN: rm -rf %t1
+// RUN: mkdir -p %t1
+// RUN: %clang_cc1 -x objective-c %s -I%S/Inputs/prebuilt-implicit-module -fmodules -fmodule-map-file=%S/Inputs/prebuilt-implicit-module/module.modulemap -fprebuilt-implicit-modules -fprebuilt-module-path=%t -fmodules-cache-path=%t1
+// RUN: find %t1 -name "module_a*.pcm" | not grep module_a
+
+// Check a module cache path is not required when all modules resolve to
+// prebuilt implicit modules.
+// RUN: rm -rf %t1
+// RUN: mkdir -p %t1
+// RUN: %clang_cc1 -x objective-c %s -I%S/Inputs/prebuilt-implicit-module -fmodules -fmodule-map-file=%S/Inputs/prebuilt-implicit-module/module.modulemap -fprebuilt-implicit-modules -fprebuilt-module-path=%t
+
+// Check that we correctly fall back to implicit modules if the prebuilt implicit module is not found.
+// RUN: rm -rf %t1
+// RUN: mkdir -p %t1
+// RUN: %clang_cc1 -x objective-c %s -I%S/Inputs/prebuilt-implicit-module -fmodules -fmodule-map-file=%S/Inputs/prebuilt-implicit-module/module.modulemap -fprebuilt-implicit-modules -fprebuilt-module-path=%t -fmodules-cache-path=%t1 -fno-signed-char
+// RUN: find %t1 -name "module_a*.pcm" | grep module_a
+
+// Check that non-implicit prebuilt modules are always preferred to prebuilt implicit modules.
+// RUN: rm -rf %t2
+// RUN: mkdir -p %t2
+// RUN: %clang_cc1 -x objective-c -fmodules %S/Inputs/prebuilt-implicit-module/module.modulemap -emit-module -fmodule-name=module_a -fmodules-cache-path=%t
+// RUN: %clang_cc1 -x objective-c -fmodules %S/Inputs/prebuilt-implicit-module/module.modulemap -emit-module -fmodule-name=module_a -o %t/module_a.pcm -fno-signed-char
+// RUN: not %clang_cc1 -x objective-c %s -I%S/Inputs/prebuilt-implicit-module -fmodules -fmodule-map-file=%S/Inputs/prebuilt-implicit-module/module.modulemap -fprebuilt-implicit-modules -fprebuilt-module-path=%t -fmodules-cache-path=%t2
+// RUN: find %t2 -name "module_a*.pcm" | not grep module_a
+
+// expected-no-diagnostics
+@import module_a;
+int test() {
+  return a;
+}
Index: clang/test/Modules/Inputs/prebuilt-implicit-module/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/prebuilt-implicit-module/module.modulemap
@@ -0,0 +1 @@
+module module_a { header "a.h" }
Index: clang/test/Modules/Inputs/prebuilt-implicit-module/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/prebuilt-implicit-module/a.h
@@ -0,0 +1 @@
+const int a = 1;
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1320,6 +1320,7 @@
   Record.push_back(HSOpts.DisableModuleHash);
   Record.push_back(HSOpts.ImplicitModuleMaps);
   Record.push_back(HSOpts.ModuleMapFileHomeIsCwd);
+  Record.push_back(HSOpts.EnablePrebuiltImplicitModules);
   Record.push_back(HSOpts.UseBuiltinIncludes);
   Record.push_back(HSOpts.UseStandardSystemIncludes);
   Record.push_back(HSOpts.UseStandardCXXIncludes);
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -5844,6 +5844,7 @@
   HSOpts.DisableModuleHash = Record[Idx++];
   HSOpts.ImplicitModuleMaps = Record[Idx++];
   HSOpts.ModuleMapFil

[clang-tools-extra] 062b5c5 - [clangd] Set the User option for clang-tidy to mimick its behaviour

2020-11-06 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-11-06T19:58:21Z
New Revision: 062b5c598f21c1591b10362219e3c89e934367b0

URL: 
https://github.com/llvm/llvm-project/commit/062b5c598f21c1591b10362219e3c89e934367b0
DIFF: 
https://github.com/llvm/llvm-project/commit/062b5c598f21c1591b10362219e3c89e934367b0.diff

LOG: [clangd] Set the User option for clang-tidy to mimick its behaviour

Probably not essential as afaik only one check uses this field. but still good 
to have consistent behaviour.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/tool/ClangdMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index ae5b16ebce7f..08d498f30873 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -809,6 +809,11 @@ clangd accepts flags on the commandline, and in the 
CLANGD_FLAGS environment var
   if (EnableClangTidy) {
 auto EmptyDefaults = tidy::ClangTidyOptions::getDefaults();
 EmptyDefaults.Checks.reset(); // So we can tell if checks were ever set.
+EmptyDefaults.User = llvm::sys::Process::GetEnv("USER");
+#ifdef _WIN32
+if (!EmptyDefaults.User)
+  EmptyDefaults.User = llvm::sys::Process::GetEnv("USERNAME");
+#endif
 tidy::ClangTidyOptions OverrideClangTidyOptions;
 if (!ClangTidyChecks.empty())
   OverrideClangTidyOptions.Checks = ClangTidyChecks;



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


[PATCH] D90552: [clangd] Set the User option for clang-tidy to mimick its behaviour

2020-11-06 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG062b5c598f21: [clangd] Set the User option for clang-tidy to 
mimick its behaviour (authored by njames93).

Changed prior to commit:
  https://reviews.llvm.org/D90552?vs=302871&id=303519#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90552

Files:
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -809,6 +809,11 @@
   if (EnableClangTidy) {
 auto EmptyDefaults = tidy::ClangTidyOptions::getDefaults();
 EmptyDefaults.Checks.reset(); // So we can tell if checks were ever set.
+EmptyDefaults.User = llvm::sys::Process::GetEnv("USER");
+#ifdef _WIN32
+if (!EmptyDefaults.User)
+  EmptyDefaults.User = llvm::sys::Process::GetEnv("USERNAME");
+#endif
 tidy::ClangTidyOptions OverrideClangTidyOptions;
 if (!ClangTidyChecks.empty())
   OverrideClangTidyOptions.Checks = ClangTidyChecks;


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -809,6 +809,11 @@
   if (EnableClangTidy) {
 auto EmptyDefaults = tidy::ClangTidyOptions::getDefaults();
 EmptyDefaults.Checks.reset(); // So we can tell if checks were ever set.
+EmptyDefaults.User = llvm::sys::Process::GetEnv("USER");
+#ifdef _WIN32
+if (!EmptyDefaults.User)
+  EmptyDefaults.User = llvm::sys::Process::GetEnv("USERNAME");
+#endif
 tidy::ClangTidyOptions OverrideClangTidyOptions;
 if (!ClangTidyChecks.empty())
   OverrideClangTidyOptions.Checks = ClangTidyChecks;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-06 Thread Vasily Kulikov via Phabricator via cfe-commits
segoon marked an inline comment as done.
segoon added inline comments.



Comment at: clang-tools-extra/docs/clang-tidy/checks/list.rst:33
`abseil-upgrade-duration-conversions 
`_, "Yes"
-   `altera-struct-pack-align `_,
+   `altera-struct-pack-align `_, "Yes"
`android-cloexec-accept `_, "Yes"

njames93 wrote:
> Can you undo this change and all other unrelated changes to this file.
These changes are added by ./add_new_check.py. I guess the file was altered by 
hands w/o using the script the last time(s).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90944

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


[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-06 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/docs/clang-tidy/checks/list.rst:33
`abseil-upgrade-duration-conversions 
`_, "Yes"
-   `altera-struct-pack-align `_,
+   `altera-struct-pack-align `_, "Yes"
`android-cloexec-accept `_, "Yes"

segoon wrote:
> njames93 wrote:
> > Can you undo this change and all other unrelated changes to this file.
> These changes are added by ./add_new_check.py. I guess the file was altered 
> by hands w/o using the script the last time(s).
I'm aware of that. but these changes are unrelated and shouldn't be a part of 
the PR.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90944

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


[PATCH] D90714: [clang]Fix length threshold for MicrosoftMangle md5 hash

2020-11-06 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

you're right about the regex syntax. i think the 4088 is over the max 
repetition count and there's also a problem with balanced. not sure what i did 
wrong here. if you have a chance to look at this otherwise i'll toil over the 
weekend, i'm off for the day--cheers.  here's what i'm trying now just to see 
if it would work.  can i nest repetition counts?

63:20: error: invalid regex: braces not balanced
// CHECK-DAG: @"?{{\(z\){255}}}@@3HA" = dso_local global i32 1515, align 4

i also tried it without the parens around z or with parens around z but not 
backslash.

  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90714

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


[PATCH] D90221: Include more attribute details when dumping AST in JSON

2020-11-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D90221#2374344 , @aronsky wrote:

>> It seems surprising to me that you'd have to add those declarations; I think 
>> that's a layering violation. There's something somewhat strange going on 
>> here that I think is related. Given:
>> [...]
>> Notice how the annotate attribute has an `inner` array with the argument 
>> inside of it while the visibility attribute does not? Ideally, we'd either 
>> use `args` or `inner` but not a mixture of the two.
>
> Good point. I'm actually not an expert on the inner workings of clang 
> structures (this is my first foray into LLVM), so I am not sure what causes 
> this discrepancy.

I think the issue is that ASTNodeTraverser is visiting all of the attribute 
arguments (around ASTNodeTraverse.h:726) and your patch also visits them (as 
part of what's emitted from ClangAttrEmitter.cpp).

> For some context - I'm working on a static analysis engine, and using clang 
> to parse C/C++. The changes I'm proposing here are due to the fact I was 
> missing attribute details in JSON, that are present in standard dumping 
> (which, of course, isn't very consumable, compared to JSON).

Yup, this is a great use for `-ast-dump=json`!

>> I was imagining the design here to be that the JSON node dumper for 
>> attributes would open a new JSON attribute named "args" whose value is an 
>> array of arguments, then you'd loop over the arguments and `Visit` each one 
>> in turn as the arguments are children of the attribute AST node in some 
>> respects. For instance, consider dumping the arguments for the `enable_if` 
>> attribute, which accepts arbitrary expressions -- dumping a type or a bare 
>> decl ref is insufficient.
>
> I concur that from a design standpoint, my solution is pretty lacking - it's 
> more of a patch (no pun intended), rather than a fundamental fix to the issue 
> at hand. That's also the reason for the extra whitespace you mentioned... I 
> was trying to get the missing arguments with minimal changes, so I used 
> existing code where available (in this case, code that dumped those arguments 
> in TextNodeDumper). My hope was that the patch would be approved (since it 
> does improve the output in a way, and doesn't break it), and someone more 
> knowledgable in LLVM/clang internals would improve it further :). I would 
> gladly take the responsibility, but it's not up to me - as far as my company 
> is concerned, the changes are sufficient for the product, and further time 
> spent on improvements is unwarranted. Maybe I can work on it in my free time, 
> but I can't commit to it.

Unfortunately, I don't think we can accept the patch as-is -- it's incomplete 
(misses some kinds of attribute arguments), has correctness issues (duplicates 
some kinds of attribute arguments), and would make it harder to maintain the 
code moving forward (with the layering issue). I can definitely understand not 
having a lot of time to investigate the right way to do this, so I spent a bit 
of time this afternoon working on a patch that gets partway to what I think 
needs to happen. I put up a pastebin for it here: 
https://pastebin.com/6ybrPVu6. It does not solve the issue of duplicate 
traversal, however, and I'm not certain I have more time to put into the patch 
right now. Perhaps one of us will have the time to take this the last mile -- I 
think the functionality is needed for JSON dumping.


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

https://reviews.llvm.org/D90221

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


[PATCH] D90180: [clang-tidy] find/fix unneeded semicolon after switch

2020-11-06 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D90180#2375878 , @aaron.ballman 
wrote:

> In D90180#2374839 , @nickdesaulniers 
> wrote:
>
>> In D90180#2357247 , @aaron.ballman 
>> wrote:
>>
>>> This will reduce the amount of compilation overhead for the clang-tidy 
>>> project over time by not needing to introduce a new check (with new 
>>> boilerplate) for each scenario but should hopefully still allow you to do 
>>> what you need (with config files perhaps) in your CI. WDYT?
>>
>> I don't see how renaming the check changes "compilation overhead" or why we 
>> think "compilation overhead" of clang tidy is a concern in this case?
>
> I meant that if we had distinct checks `linuxkernel-switch-semi`, 
> `linuxkernel-for-loop-semi`, `linuxkernel-middle-of-nowhere-semi`, etc that 
> each one of those checks would require their own header file, source file, 
> test files, documentation, etc. whereas if we had a single check, we'd reduce 
> that overhead by only having one header, one source, one documentation, etc 
> using config options, which makes fetching or building clang-tidy go 
> ever-so-slightly faster.

Ah, so you're recommending that future checks related to additional/extraneous 
semicolons also be placed in this check, rather than their own?  I don't have a 
problem with that.

>> Maybe clarifying what you would prefer to see the check called and whether 
>> it would be in the linuxkernel namespace of checks or something else would 
>> help, @aaron.ballman ?
>
> I definitely think the check should live in the `linuxkernel` module. How 
> about `linuxkernel-spurious-semi`, `linuxkernel-extra-semi`, 
> `linuxkernel-remove-useless-semi-colons`, or anything that makes you happy 
> and sounds similarly generic?

It's currently called `"linuxkernel-switch-semi"`, so if you'd like it to be 
slightly more generic, @trixirt would you mind renaming this check to something 
slightly more generic like one of the above (or something similar)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90180

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


[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-06 Thread Vasily Kulikov via Phabricator via cfe-commits
segoon added a comment.

In D90944#2379688 , @njames93 wrote:

> It appears to not check for signs that the code is running in a multi 
> threaded manner, This will result in many false positives in code that is 
> known to be single threaded.

I'm not sure there is a trustworthy check whether a source is going to be used 
in MT environment. A program can be linked with threads libraries but still use 
a single thread and use MT-unsafe API with no problem. I'd rather disable the 
check by default and let the user explicitly enable the check. I'm not sure 
what's clang-tidy policy for such case - should I create a new module instead 
of "misc"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90944

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


[PATCH] D90767: Add new matchers for dependent names in templates

2020-11-06 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0d6e1251d79d: Add new matchers for dependent names in 
templates (authored by stephenkelly).

Changed prior to commit:
  https://reviews.llvm.org/D90767?vs=303462&id=303531#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90767

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1629,6 +1629,95 @@
  Constructor1Arg));
 }
 
+TEST(ASTMatchersTest, NamesMember_CXXDependentScopeMemberExpr) {
+
+  // Member functions:
+  {
+auto Code = "template  struct S{ void mem(); }; template "
+" void x() { S s; s.mem(); }";
+
+EXPECT_TRUE(matches(
+Code,
+cxxDependentScopeMemberExpr(
+hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
+hasDeclaration(classTemplateDecl(has(cxxRecordDecl(
+has(cxxMethodDecl(hasName("mem")).bind("templMem")),
+memberHasSameNameAsBoundNode("templMem";
+
+EXPECT_TRUE(
+matches(Code, cxxDependentScopeMemberExpr(hasMemberName("mem";
+  }
+
+  // Member variables:
+  {
+auto Code = "template  struct S{ int mem; }; template "
+" void x() { S s; s.mem; }";
+
+EXPECT_TRUE(
+matches(Code, cxxDependentScopeMemberExpr(hasMemberName("mem";
+
+EXPECT_TRUE(matches(
+Code,
+cxxDependentScopeMemberExpr(
+hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
+hasDeclaration(classTemplateDecl(has(cxxRecordDecl(
+has(fieldDecl(hasName("mem")).bind("templMem")),
+memberHasSameNameAsBoundNode("templMem";
+  }
+
+  // static member variables:
+  {
+auto Code = "template  struct S{ static int mem; }; template "
+" void x() { S s; s.mem; }";
+
+EXPECT_TRUE(
+matches(Code, cxxDependentScopeMemberExpr(hasMemberName("mem";
+
+EXPECT_TRUE(matches(
+Code,
+cxxDependentScopeMemberExpr(
+hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
+hasDeclaration(classTemplateDecl(has(cxxRecordDecl(
+has(varDecl(hasName("mem")).bind("templMem")),
+memberHasSameNameAsBoundNode("templMem";
+  }
+  {
+auto Code = R"cpp(
+template 
+struct S {
+  bool operator==(int) const { return true; }
+};
+
+template 
+void func(T t) {
+  S s;
+  s.operator==(1);
+}
+)cpp";
+
+EXPECT_TRUE(matches(
+Code, cxxDependentScopeMemberExpr(hasMemberName("operator==";
+  }
+
+  // other named decl:
+  {
+auto Code = "template  struct S{ static int mem; }; struct "
+"mem{}; template "
+" void x() { S s; s.mem; }";
+
+EXPECT_TRUE(matches(
+Code,
+translationUnitDecl(has(cxxRecordDecl(hasName("mem"))),
+hasDescendant(cxxDependentScopeMemberExpr();
+
+EXPECT_FALSE(matches(
+Code,
+translationUnitDecl(has(cxxRecordDecl(hasName("mem")).bind("templMem")),
+hasDescendant(cxxDependentScopeMemberExpr(
+memberHasSameNameAsBoundNode("templMem"));
+  }
+}
+
 TEST(ASTMatchersTest, ArgumentCountIs_CXXUnresolvedConstructExpr) {
   const auto *Code =
   "template  struct S{}; template  void "
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -302,6 +302,7 @@
   REGISTER_MATCHER(hasLocalStorage);
   REGISTER_MATCHER(hasLoopInit);
   REGISTER_MATCHER(hasLoopVariable);
+  REGISTER_MATCHER(hasMemberName);
   REGISTER_MATCHER(hasMethod);
   REGISTER_MATCHER(hasName);
   REGISTER_MATCHER(hasNullSelector);
@@ -443,6 +444,7 @@
   REGISTER_MATCHER(materializeTemporaryExpr);
   REGISTER_MATCHER(member);
   REGISTER_MATCHER(memberExpr);
+  REGISTER_MATCHER(memberHasSameNameAsBoundNode);
   REGISTER_MATCHER(memberPointerType);
   REGISTER_MATCHER(namedDecl);
   REGISTER_MATCHER(namesType);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2835,6 +2835,80 @@
 StringRef, internal::hasA

[clang] 0d6e125 - Add new matchers for dependent names in templates

2020-11-06 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2020-11-06T21:03:20Z
New Revision: 0d6e1251d79d07a03d8cf528e3537d41d4285680

URL: 
https://github.com/llvm/llvm-project/commit/0d6e1251d79d07a03d8cf528e3537d41d4285680
DIFF: 
https://github.com/llvm/llvm-project/commit/0d6e1251d79d07a03d8cf528e3537d41d4285680.diff

LOG: Add new matchers for dependent names in templates

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 14dec7d972b3..d348bc80e792 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -2543,6 +2543,28 @@ Narrowing Matchers
 
 
 
+MatcherCXXDependentScopeMemberExpr>hasMemberNamestd::string N
+Matches 
template-dependent, but known, member names
+
+In template declarations, dependent members are not resolved and so can
+not be matched to particular named declarations.
+
+This matcher allows to match on the known name of members.
+
+Given
+  template 
+  struct S {
+  void mem();
+  };
+  template 
+  void x() {
+  S s;
+  s.mem();
+  }
+cxxDependentScopeMemberExpr(hasMemberName("mem")) matches `s.mem()`
+
+
+
 MatcherCXXDependentScopeMemberExpr>isArrow
 Matches member expressions 
that are called with '->' as opposed
 to '.'.
@@ -2569,6 +2591,42 @@ Narrowing Matchers
 
 
 
+MatcherCXXDependentScopeMemberExpr>memberHasSameNameAsBoundNodestd::string
 BindingID
+Matches template-dependent, but known, 
member names against an already-bound
+node
+
+In template declarations, dependent members are not resolved and so can
+not be matched to particular named declarations.
+
+This matcher allows to match on the name of already-bound VarDecl, FieldDecl
+and CXXMethodDecl nodes.
+
+Given
+  template 
+  struct S {
+  void mem();
+  };
+  template 
+  void x() {
+  S s;
+  s.mem();
+  }
+The matcher
+@code
+cxxDependentScopeMemberExpr(
+  hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
+  hasDeclaration(classTemplateDecl(has(cxxRecordDecl(has(
+  cxxMethodDecl(hasName("mem")).bind("templMem")
+  )
+  ,
+  memberHasSameNameAsBoundNode("templMem")
+  )
+@endcode
+first matches and binds the @c mem member of the @c S template, then
+compares its name to the usage in @c s.mem() in the @c x function template
+
+
+
 MatcherCXXMethodDecl>isConst
 Matches if the given method 
declaration is const.
 
@@ -2866,6 +2924,16 @@ Narrowing Matchers
 
 
 
+MatcherCXXUnresolvedConstructExpr>argumentCountIsunsigned N
+Checks that a call 
expression or a constructor call expression has
+a specific number of arguments (including absent default arguments).
+
+Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
+  void f(int x, int y);
+  f(0, 0);
+
+
+
 MatcherCallExpr>argumentCountIsunsigned N
 Checks that a call 
expression or a constructor call expression has
 a specific number of arguments (including absent default arguments).
@@ -3923,8 +3991,8 @@ Narrowing Matchers
 
 
 
-MatcherObjCMessageExpr>argumentCountIsunsigned N
-Checks that a call 
expression or a constructor call expression has
+MatcherObjCMessageExpr>argumentCountIsunsigned N
+Checks that a call 
expression or a constructor call expression has
 a specific number of arguments (including absent default arguments).
 
 Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
@@ -5865,6 +5933,16 @@ AST Traversal Matchers
 
 
 
+MatcherCXXUnresolvedConstructExpr>hasArgumentunsigned N, MatcherExpr> 
InnerMatcher
+Matches the n'th 
argument of a call expression or a constructor
+call expression.
+
+Example matches y in x(y)
+(matcher = callExpr(hasArgument(0, declRefExpr(
+  void x(int) { int y; x(y); }
+
+
+
 MatcherCallExpr>calleeMatcher

[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-06 Thread Vasily Kulikov via Phabricator via cfe-commits
segoon updated this revision to Diff 303532.
segoon added a comment.

- use static instead of namespace {}
- don't use SourceRange()
- revert unrelated changes to .rst


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

https://reviews.llvm.org/D90944

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp
  clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s misc-mt-unsafe %t
+
+extern unsigned int sleep (unsigned int __seconds);
+extern int *gmtime (const int *__timer);
+
+void foo() {
+  sleep(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+
+  ::sleep(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+
+  auto tm = gmtime(nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function is not thread safe [misc-mt-unsafe]
+  tm = ::gmtime(nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: function is not thread safe [misc-mt-unsafe]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - misc-mt-unsafe
+
+misc-mt-unsafe
+==
+
+Checks for some thread-unsafe functions against a black list of
+known-to-be-unsafe functions. Usually they access static variables without
+synchronization (e.g. gmtime(3)) or utilize signals in a racy way.
+
+Examples:
+
+.. code-block:: c++
+
+tm = gmtime(timep); // uses a global buffer
+
+sleep(1); // implementation may use SIGALRM
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -198,6 +198,7 @@
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
+   `misc-mt-unsafe `_,
`misc-new-delete-overloads `_,
`misc-no-recursion `_,
`misc-non-copyable-objects `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -106,6 +106,10 @@
   Finds condition variables in nested ``if`` statements that were also checked
   in the outer ``if`` statement and were not changed.
 
+- New :doc:`misc-mt-unsafe ` check.
+
+  Finds thread-unsafe functions usage.
+
 - New :doc:`readability-function-cognitive-complexity
   ` check.
 
Index: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.h
@@ -0,0 +1,34 @@
+//===--- MtUnsafeCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MTUNSAFECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MTUNSAFECHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+/// Checks that non-thread-safe functions are not used.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/misc-mt-unsafe.html
+class MtUnsafeCheck : public ClangTidyCheck {
+public:
+  MtUnsafeCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace misc
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MTUNSAFECHECK_H
Index: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp
@@ -0,0 +1,199 @@
+//===--- MtUnsafeCheck.cpp - clang-tidy ---===//
+//
+// Part of the LLVM Project, under the Apache Lice

Re: [clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-11-06 Thread Alex L via cfe-commits
Hi Rchard,

Some of our code started triggering the warning you added in this code, but
I'm not sure if the warning is actually valid or not in this case:

https://godbolt.org/z/9fxs3K

namespace geo {
  template
class optional {
optional() { }
~optional();
};
}
template
geo::optional::~optional() // Triggers  ISO C++ requires the name after
'::~' to be found in the same scope as the name before '::~'
{
}

Could you confirm whether or not this warning is valid for our code?

Thanks,
Alex


On Thu, 13 Feb 2020 at 00:52, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Thanks, yes, fixed in llvmorg-11-init-3043-gc1394afb8df.
>
> On Thu, 13 Feb 2020 at 02:58, Kostya Serebryany via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Could this have caused a new ubsan failure?
>>
>> clang/lib/AST/NestedNameSpecifier.cpp:485:23: runtime error: null pointer 
>> passed as argument 2, which is declared to never be null
>>
>>
>> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/38698/steps/check-clang%20ubsan/logs/stdio
>>
>> On Fri, Feb 7, 2020 at 6:41 PM Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Richard Smith
>>> Date: 2020-02-07T18:40:41-08:00
>>> New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff
>>>
>>> LOG: PR12350: Handle remaining cases permitted by CWG DR 244.
>>>
>>> Also add extension warnings for the cases that are disallowed by the
>>> current rules for destructor name lookup, refactor and simplify the
>>> lookup code, and improve the diagnostic quality when lookup fails.
>>>
>>> The special case we previously supported for converting
>>> p->N::S::~S() from naming a class template into naming a
>>> specialization thereof is subsumed by a more general rule here (which is
>>> also consistent with Clang's historical behavior and that of other
>>> compilers): if we can't find a suitable S in N, also look in N::S.
>>>
>>> The extension warnings are off by default, except for a warning when
>>> lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
>>> That seems sufficiently heinous to warn on by default, especially since
>>> we can't support it for a dependent nested-name-specifier.
>>>
>>> Added:
>>>
>>>
>>> Modified:
>>> clang/include/clang/Basic/DiagnosticGroups.td
>>> clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> clang/lib/AST/NestedNameSpecifier.cpp
>>> clang/lib/Sema/DeclSpec.cpp
>>> clang/lib/Sema/SemaExprCXX.cpp
>>> clang/test/CXX/class/class.mem/p13.cpp
>>> clang/test/CXX/drs/dr2xx.cpp
>>> clang/test/CXX/drs/dr3xx.cpp
>>> clang/test/FixIt/fixit.cpp
>>> clang/test/Parser/cxx-decl.cpp
>>> clang/test/SemaCXX/constructor.cpp
>>> clang/test/SemaCXX/destructor.cpp
>>> clang/test/SemaCXX/pseudo-destructors.cpp
>>>
>>> Removed:
>>>
>>>
>>>
>>>
>>> 
>>> diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td
>>> b/clang/include/clang/Basic/DiagnosticGroups.td
>>> index a2bc29986a07..8c54723cdbab 100644
>>> --- a/clang/include/clang/Basic/DiagnosticGroups.td
>>> +++ b/clang/include/clang/Basic/DiagnosticGroups.td
>>> @@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
>>>  // designators (including the warning controlled by -Wc++2a-designator).
>>>  def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
>>>  def GNUDesignator : DiagGroup<"gnu-designator">;
>>> +def DtorName : DiagGroup<"dtor-name">;
>>>
>>>  def DynamicExceptionSpec
>>>  : DiagGroup<"dynamic-exception-spec",
>>> [DeprecatedDynamicExceptionSpec]>;
>>>
>>> diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> index 9de60d3a8d27..82861f0d5d72 100644
>>> --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> @@ -1911,17 +1911,33 @@ def err_destructor_with_params :
>>> Error<"destructor cannot have any parameters">;
>>>  def err_destructor_variadic : Error<"destructor cannot be variadic">;
>>>  def err_destructor_typedef_name : Error<
>>>"destructor cannot be declared using a %select{typedef|type alias}1
>>> %0 of the class name">;
>>> +def err_undeclared_destructor_name : Error<
>>> +  "undeclared identifier %0 in destructor name">;
>>>  def err_destructor_name : Error<
>>>"expected the class name after '~' to name the enclosing class">;
>>> -def err_destructor_class_name : Error<
>>> -  "expected the class name after '~' to name a destructor">;
>>> -def err_ident_in_dtor_not_a_type : Error<
>>> +def err_destructor_name_nontype : Error<
>>> +  "identifier %0 after '~' in destructor name does not name a type">;
>>> 

[PATCH] D87163: [DSE] Switch to MemorySSA-backed DSE by default.

2020-11-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Very belated update: We've been running with this on our clang/tot bots for a 
few weeks now and turned this on (or, more accurately stopped turning it off) 
for "normal" builds today. All tests pass and so far everything's happy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87163

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


[PATCH] D90799: [PowerPC] Add paired vector load and store builtins and intrinsics

2020-11-06 Thread Baptiste Saleil via Phabricator via cfe-commits
bsaleil updated this revision to Diff 303540.
bsaleil added a comment.

Fix unaligned load/store select


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90799

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-mma.c
  clang/test/Sema/ppc-mma-types.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
  llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
  llvm/test/CodeGen/PowerPC/dform-pair-load-store.ll
  llvm/test/CodeGen/PowerPC/loop-p10-pair-prepare.ll
  llvm/test/CodeGen/PowerPC/mma-intrinsics.ll

Index: llvm/test/CodeGen/PowerPC/mma-intrinsics.ll
===
--- llvm/test/CodeGen/PowerPC/mma-intrinsics.ll
+++ llvm/test/CodeGen/PowerPC/mma-intrinsics.ll
@@ -698,3 +698,315 @@
 
 declare <512 x i1> @llvm.ppc.mma.pmxvf64gernn(<512 x i1>, <256 x i1>, <16 x i8>, i32, i32)
 declare <512 x i1> @llvm.ppc.mma.xvf64gernp(<512 x i1>, <256 x i1>, <16 x i8>)
+
+; Function Attrs: nounwind
+define void @test_ldst_1(<256 x i1>* %vpp, <256 x i1>* %vp2) {
+; CHECK-LABEL: test_ldst_1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:lxvp vsp0, 0(r3)
+; CHECK-NEXT:stxvp vsp0, 0(r4)
+; CHECK-NEXT:blr
+;
+; CHECK-BE-LABEL: test_ldst_1:
+; CHECK-BE:   # %bb.0: # %entry
+; CHECK-BE-NEXT:lxvp vsp0, 0(r3)
+; CHECK-BE-NEXT:stxvp vsp0, 0(r4)
+; CHECK-BE-NEXT:blr
+entry:
+  %0 = bitcast <256 x i1>* %vpp to i8*
+  %1 = tail call <256 x i1> @llvm.ppc.mma.lxvp(i8* %0)
+  %2 = bitcast <256 x i1>* %vp2 to i8*
+  tail call void @llvm.ppc.mma.stxvp(<256 x i1> %1, i8* %2)
+  ret void
+}
+
+; Function Attrs: argmemonly nounwind readonly
+declare <256 x i1> @llvm.ppc.mma.lxvp(i8*)
+
+; Function Attrs: argmemonly nounwind writeonly
+declare void @llvm.ppc.mma.stxvp(<256 x i1>, i8*)
+
+; Function Attrs: nounwind
+define void @test_ldst_2(<256 x i1>* %vpp, i64 %offset, <256 x i1>* %vp2)  {
+; CHECK-LABEL: test_ldst_2:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:lxvpx vsp0, r3, r4
+; CHECK-NEXT:stxvpx vsp0, r5, r4
+; CHECK-NEXT:blr
+;
+; CHECK-BE-LABEL: test_ldst_2:
+; CHECK-BE:   # %bb.0: # %entry
+; CHECK-BE-NEXT:lxvpx vsp0, r3, r4
+; CHECK-BE-NEXT:stxvpx vsp0, r5, r4
+; CHECK-BE-NEXT:blr
+entry:
+  %0 = bitcast <256 x i1>* %vpp to i8*
+  %1 = getelementptr i8, i8* %0, i64 %offset
+  %2 = tail call <256 x i1> @llvm.ppc.mma.lxvp(i8* %1)
+  %3 = bitcast <256 x i1>* %vp2 to i8*
+  %4 = getelementptr i8, i8* %3, i64 %offset
+  tail call void @llvm.ppc.mma.stxvp(<256 x i1> %2, i8* %4)
+  ret void
+}
+
+; Function Attrs: nounwind
+define void @test_ldst_3(<256 x i1>* %vpp, <256 x i1>* %vp2)  {
+; CHECK-LABEL: test_ldst_3:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:li r5, 18
+; CHECK-NEXT:lxvpx vsp0, r3, r5
+; CHECK-NEXT:stxvpx vsp0, r4, r5
+; CHECK-NEXT:blr
+;
+; CHECK-BE-LABEL: test_ldst_3:
+; CHECK-BE:   # %bb.0: # %entry
+; CHECK-BE-NEXT:li r5, 18
+; CHECK-BE-NEXT:lxvpx vsp0, r3, r5
+; CHECK-BE-NEXT:stxvpx vsp0, r4, r5
+; CHECK-BE-NEXT:blr
+entry:
+  %0 = bitcast <256 x i1>* %vpp to i8*
+  %1 = getelementptr i8, i8* %0, i64 18
+  %2 = tail call <256 x i1> @llvm.ppc.mma.lxvp(i8* %1)
+  %3 = bitcast <256 x i1>* %vp2 to i8*
+  %4 = getelementptr i8, i8* %3, i64 18
+  tail call void @llvm.ppc.mma.stxvp(<256 x i1> %2, i8* %4)
+  ret void
+}
+
+; Function Attrs: nounwind
+define void @test_ldst_4(<256 x i1>* %vpp, <256 x i1>* %vp2)  {
+; CHECK-LABEL: test_ldst_4:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:li r5, 1
+; CHECK-NEXT:lxvpx vsp0, r3, r5
+; CHECK-NEXT:stxvpx vsp0, r4, r5
+; CHECK-NEXT:blr
+;
+; CHECK-BE-LABEL: test_ldst_4:
+; CHECK-BE:   # %bb.0: # %entry
+; CHECK-BE-NEXT:li r5, 1
+; CHECK-BE-NEXT:lxvpx vsp0, r3, r5
+; CHECK-BE-NEXT:stxvpx vsp0, r4, r5
+; CHECK-BE-NEXT:blr
+entry:
+  %0 = bitcast <256 x i1>* %vpp to i8*
+  %1 = getelementptr i8, i8* %0, i64 1
+  %2 = tail call <256 x i1> @llvm.ppc.mma.lxvp(i8* %1)
+  %3 = bitcast <256 x i1>* %vp2 to i8*
+  %4 = getelementptr i8, i8* %3, i64 1
+  tail call void @llvm.ppc.mma.stxvp(<256 x i1> %2, i8* %4)
+  ret void
+}
+
+; Function Attrs: nounwind
+define void @test_ldst_5(<256 x i1>* %vpp, <256 x i1>* %vp2)  {
+; CHECK-LABEL: test_ldst_5:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:li r5, 42
+; CHECK-NEXT:lxvpx vsp0, r3, r5
+; CHECK-NEXT:stxvpx vsp0, r4, r5
+; CHECK-NEXT:blr
+;
+; CHECK-BE-LABEL: test_ldst_5:
+; CHECK-BE:   # %bb.0: # %entry
+; CHECK-BE-NEXT:li r5, 42
+; CHECK-BE-NEXT:lxvpx vsp0, r3, r5
+; CHECK-BE-NEXT:stxvpx vsp0, r4, r5
+; CHECK-BE-N

[PATCH] D87163: [DSE] Switch to MemorySSA-backed DSE by default.

2020-11-06 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D87163#2379892 , @thakis wrote:

> Very belated update: We've been running with this on our clang/tot bots for a 
> few weeks now and turned this on (or, more accurately stopped turning it off) 
> for "normal" builds today. All tests pass and so far everything's happy.

That's great, thanks for letting us know! There might be a few more features 
down the road, so it's good to know that you were able to make the initial 
switch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87163

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


[PATCH] D90972: [clang-tidy] Install run-clang-tidy.py in bin/ not in share/clang/

2020-11-06 Thread Florian Schmaus via Phabricator via cfe-commits
Flow created this revision.
Flow added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun, mgorny.
Herald added a project: clang.
Flow requested review of this revision.

The run-clang-tidy.py helper script is supposed to be used by the
user, hence it should be placed in the user's PATH. Some
distributions, like Gentoo [1], won't have it in PATH unless it is
installed in bin/.

1: https://bugs.gentoo.org/753380


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90972

Files:
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt


Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -55,5 +55,5 @@
   DESTINATION share/clang
   COMPONENT clang-tidy)
 install(PROGRAMS run-clang-tidy.py
-  DESTINATION share/clang
+  DESTINATION bin
   COMPONENT clang-tidy)


Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -55,5 +55,5 @@
   DESTINATION share/clang
   COMPONENT clang-tidy)
 install(PROGRAMS run-clang-tidy.py
-  DESTINATION share/clang
+  DESTINATION bin
   COMPONENT clang-tidy)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90531: [clangd] Add clang-tidy options to config

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/Config.h:78
+std::string Checks;
+std::vector> CheckOptions;
+  } ClangTidy;

njames93 wrote:
> sammccall wrote:
> > I think this should be a StringMap
> > 
> > It makes sense to use a vector-of-pairs in ConfigFragment to preserve the 
> > Located information for keys, but we don't need to do that in Config.
> If we do use a `StringMap`, whats the policy when multiple fragments 
> specify the same option.
> Currently at the Fragment level there is logic that ignores duplicated keys, 
> but when compiling the fragments, should we give priority to keys declared in 
> earlier or later fragments. In any case would it also be wise to warn about 
> that.
We merge with the later fragments taking priority. So in this case each 
fragment writes its keys into the single stringmap, replacing whatever is there.

(Most common case of later fragments is subdirectory overriding parent, or user 
config overriding in-tree).

I don't think we need to warn for this - does clang-tidy warn if there are 
multiple options sources configured and one overrides a setting from another? 
This is the same thing.



Comment at: clang-tools-extra/clangd/ConfigFragment.h:183
+  struct ClangTidyBlock {
+llvm::Optional> Enable;
+/// List of checks to enable or disable, can use wildcards.

njames93 wrote:
> sammccall wrote:
> > njames93 wrote:
> > > sammccall wrote:
> > > > I wonder if it's worth having this when we support `Remove: *`.
> > > > 
> > > > technically this does something slightly different:
> > > >  - it still runs the machinery just with no actual checks
> > > >  - you can enable: true later to override it, without losing the 
> > > > previously configured list of checks
> > > > 
> > > > Is one of these important? Is there some other benefit?
> > > > (I'm not opposed to having this if you want it, but I'm curious)
> > > I'm not 100% sure what you are asking here.
> > I'm asking whether we really need `Enable`, or whether we should remove it 
> > and recommend `Remove: *` to disable the checks.
> > 
> > If there isn't a clear reason we need it, my preference is to omit it for 
> > simplicity (we can add more setting later, but it's harder to remove them).
> > 
> > I don't feel strongly though, this is up to you.
> If we use `Remove: *` when it comes to actually implementing this, it would 
> be wise to disable running clang-tidy if there are no checks enabled. But 
> yes, I do agree that it could be removed at first, then added at a later date 
> if needs must.
This sounds like a good idea to me. This would happen in `ParsedAST::build`.
If the loop through CTChecks never actually manages to call 
registerPPCallbacks/Matchers, then we can skip the `matchAST` call.

I'll send a patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90531

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


[PATCH] D89972: Add pipeline model for HiSilicon's TSV110

2020-11-06 Thread Elvina Yakubova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG93b99728b167: [AArch64] Add pipeline model for 
HiSilicon's TSV110 (authored by Elvina).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89972

Files:
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64SchedTSV110.td
  llvm/test/CodeGen/AArch64/machine-combiner-madd.ll
  llvm/test/CodeGen/AArch64/preferred-function-alignment.ll

Index: llvm/test/CodeGen/AArch64/preferred-function-alignment.ll
===
--- llvm/test/CodeGen/AArch64/preferred-function-alignment.ll
+++ llvm/test/CodeGen/AArch64/preferred-function-alignment.ll
@@ -20,6 +20,7 @@
 ; RUN: llc -mtriple=aarch64-unknown-linux -mcpu=thunderxt88 < %s | FileCheck --check-prefixes=ALIGN3,CHECK %s
 ; RUN: llc -mtriple=aarch64-unknown-linux -mcpu=thunderx2t99 < %s | FileCheck --check-prefixes=ALIGN3,CHECK %s
 ; RUN: llc -mtriple=aarch64-unknown-linux -mcpu=thunderx3t110 < %s | FileCheck --check-prefixes=ALIGN4,CHECK %s
+; RUN: llc -mtriple=aarch64-unknown-linux -mcpu=tsv110 < %s | FileCheck --check-prefixes=ALIGN4,CHECK %s
 ; RUN: llc -mtriple=aarch64-unknown-linux -mcpu=exynos-m3 < %s | FileCheck --check-prefixes=ALIGN5,CHECK %s
 
 define void @test() {
Index: llvm/test/CodeGen/AArch64/machine-combiner-madd.ll
===
--- llvm/test/CodeGen/AArch64/machine-combiner-madd.ll
+++ llvm/test/CodeGen/AArch64/machine-combiner-madd.ll
@@ -7,6 +7,7 @@
 ; RUN: llc -mtriple=aarch64-linux-gnu -mcpu=kryo   < %s | FileCheck %s
 ; RUN: llc -mtriple=aarch64-linux-gnu -mcpu=thunderx2t99 < %s | FileCheck %s
 ; RUN: llc -mtriple=aarch64-linux-gnu -mcpu=thunderx3t110 < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mcpu=tsv110 < %s | FileCheck %s
 
 ; Make sure that inst-combine fuses the multiply add in the addressing mode of
 ; the load.
Index: llvm/lib/Target/AArch64/AArch64SchedTSV110.td
===
--- /dev/null
+++ llvm/lib/Target/AArch64/AArch64SchedTSV110.td
@@ -0,0 +1,745 @@
+//==- AArch64SchedTSV110.td - Huawei TSV110 Scheduling Definitions -*- tablegen -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the machine model for Huawei TSV110 to support
+// instruction scheduling and other instruction cost heuristics.
+//
+//===--===//
+
+// ===-===//
+// The following definitions describe the simpler per-operand machine model.
+// This works with MachineScheduler. See llvm/MC/MCSchedule.h for details.
+
+// Huawei TSV110 scheduling machine model.
+def TSV110Model : SchedMachineModel {
+  let IssueWidth=   4; // 4 micro-ops dispatched  per cycle. 
+  let MicroOpBufferSize = 128; // 128 micro-op re-order buffer
+  let LoopMicroOpBufferSize =  16; 
+  let LoadLatency   =   4; // Optimistic load latency.
+  let MispredictPenalty =  14; // Fetch + Decode/Rename/Dispatch + Branch
+  let CompleteModel =   1;
+
+  list UnsupportedFeatures = !listconcat(SVEUnsupported.F,
+PAUnsupported.F);
+}
+
+// Define each kind of processor resource and number available on the TSV110,
+// which has 8 pipelines, each with its own queue where micro-ops wait for
+// their operands and issue out-of-order to one of eight execution pipelines.
+let SchedModel = TSV110Model in {
+  def TSV110UnitALU  : ProcResource<1>; // Int ALU
+  def TSV110UnitAB   : ProcResource<2>; // Int ALU/BRU
+  def TSV110UnitMDU  : ProcResource<1>; // Multi-Cycle
+  def TSV110UnitFSU1 : ProcResource<1>; // FP/ASIMD
+  def TSV110UnitFSU2 : ProcResource<1>; // FP/ASIMD
+  def TSV110UnitLdSt : ProcResource<2>; // Load/Store
+
+  def TSV110UnitF : ProcResGroup<[TSV110UnitFSU1, TSV110UnitFSU2]>;
+  def TSV110UnitALUAB : ProcResGroup<[TSV110UnitALU, TSV110UnitAB]>;
+  def TSV110UnitFLdSt : ProcResGroup<[TSV110UnitFSU1, TSV110UnitFSU2, TSV110UnitLdSt]>;
+}
+
+let SchedModel = TSV110Model in {
+
+//===--===//
+// Map the target-defined scheduler read/write resources and latency for 
+// TSV110
+
+// Integer ALU
+def : WriteRes { let Latency = 1; }
+def : WriteRes { let Latency = 1; }
+def : WriteRes   { let Latency = 2; } 
+def : WriteRes   { let Latency = 2; } 
+def : WriteRes { let Latency = 1; }
+def : WriteRes { let Latency = 1; }
+
+// Integer Mul/MAC/Div
+def : WriteRes { let Latency

[libunwind] c1887e3 - Revert "Allow running back-deployment testing against libc++abi"

2020-11-06 Thread Louis Dionne via cfe-commits

Author: Louis Dionne
Date: 2020-11-06T17:26:42-05:00
New Revision: c1887e3f15aeac7037b88b066b33d142c6bb1321

URL: 
https://github.com/llvm/llvm-project/commit/c1887e3f15aeac7037b88b066b33d142c6bb1321
DIFF: 
https://github.com/llvm/llvm-project/commit/c1887e3f15aeac7037b88b066b33d142c6bb1321.diff

LOG: Revert "Allow running back-deployment testing against libc++abi"

This reverts commit 4d79ef814aedb63, which broke a few build bots.
I'm reverting until I have time to investigate.

Added: 


Modified: 
libcxx/test/configs/legacy.cfg.in
libcxx/utils/ci/macos-backdeployment.sh
libcxx/utils/ci/run-buildbot
libcxx/utils/libcxx/compiler.py
libcxx/utils/libcxx/test/config.py
libcxxabi/test/catch_function_01.pass.cpp
libcxxabi/test/catch_member_data_pointer_01.pass.cpp
libcxxabi/test/catch_member_pointer_nullptr.pass.cpp
libcxxabi/test/catch_multi_level_pointer.pass.cpp
libcxxabi/test/catch_pointer_nullptr.pass.cpp
libcxxabi/test/catch_ptr_02.pass.cpp
libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp
libcxxabi/test/dynamic_cast.pass.cpp
libcxxabi/test/exception_object_alignment.pass.cpp
libcxxabi/test/incomplete_type.sh.cpp
libcxxabi/test/libcxxabi/test/config.py
libcxxabi/test/lit.site.cfg.in
libcxxabi/test/test_aux_runtime_op_array_new.pass.cpp
libcxxabi/test/test_demangle.pass.cpp
libcxxabi/test/test_exception_address_alignment.pass.cpp
libcxxabi/test/thread_local_destruction_order.pass.cpp
libcxxabi/test/uncaught_exceptions.pass.cpp
libunwind/test/libunwind/test/config.py
libunwind/test/lit.site.cfg.in

Removed: 




diff  --git a/libcxx/test/configs/legacy.cfg.in 
b/libcxx/test/configs/legacy.cfg.in
index 60591c0e424b..f0a4e8a73e09 100644
--- a/libcxx/test/configs/legacy.cfg.in
+++ b/libcxx/test/configs/legacy.cfg.in
@@ -8,7 +8,6 @@ config.project_obj_root = "@CMAKE_BINARY_DIR@"
 config.libcxx_src_root  = "@LIBCXX_SOURCE_DIR@"
 config.libcxx_obj_root  = "@LIBCXX_BINARY_DIR@"
 config.cxx_library_root = "@LIBCXX_LIBRARY_DIR@"
-config.abi_library_root = "@LIBCXX_CXX_ABI_LIBRARY_PATH@"
 config.enable_exceptions= @LIBCXX_ENABLE_EXCEPTIONS@
 config.enable_debug_tests   = @LIBCXX_ENABLE_DEBUG_MODE_SUPPORT@
 config.enable_experimental  = @LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY@
@@ -19,6 +18,7 @@ config.enable_32bit = @LIBCXX_BUILD_32_BITS@
 config.cxx_abi  = "@LIBCXX_CXX_ABI_LIBNAME@"
 config.use_sanitizer= "@LLVM_USE_SANITIZER@"
 config.sanitizer_library= "@LIBCXX_SANITIZER_LIBRARY@"
+config.abi_library_path = "@LIBCXX_CXX_ABI_LIBRARY_PATH@"
 config.configuration_variant= "@LIBCXX_LIT_VARIANT@"
 config.host_triple  = "@LLVM_HOST_TRIPLE@"
 config.target_triple= "@TARGET_TRIPLE@"

diff  --git a/libcxx/utils/ci/macos-backdeployment.sh 
b/libcxx/utils/ci/macos-backdeployment.sh
index 281b6e561aeb..f91d7197e9e5 100755
--- a/libcxx/utils/ci/macos-backdeployment.sh
+++ b/libcxx/utils/ci/macos-backdeployment.sh
@@ -120,10 +120,6 @@ fi
 
LIBCXX_ROOT_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/libc++/${DEPLOYMENT_TARGET}"
 
LIBCXXABI_ROOT_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/libc++abi/${DEPLOYMENT_TARGET}"
 
-# TODO: On Apple platforms, we never produce libc++abi.1.dylib, always 
libc++abi.dylib.
-#   Fix that in the build so that the tests stop searching for 
@rpath/libc++abi.1.dylib.
-cp "${LIBCXXABI_ROOT_ON_DEPLOYMENT_TARGET}/libc++abi.dylib" 
"${LIBCXXABI_ROOT_ON_DEPLOYMENT_TARGET}/libc++abi.1.dylib"
-
 # Filesystem is supported on Apple platforms starting with macosx10.15.
 if [[ ${DEPLOYMENT_TARGET} =~ ^10.9|10.10|10.11|10.12|10.13|10.14$ ]]; then
 ENABLE_FILESYSTEM="--param enable_filesystem=false"
@@ -131,8 +127,9 @@ else
 ENABLE_FILESYSTEM="--param enable_filesystem=true"
 fi
 
-echo "@@@ Running tests for libc++ and libc++abi @@@"
-"${LLVM_BUILD_DIR}/bin/llvm-lit" -sv "${MONOREPO_ROOT}/libcxx/test" 
"${MONOREPO_ROOT}/libcxxabi/test" \
+# TODO: We need to also run the tests for libc++abi.
+echo "@@@ Running tests for libc++ @@@"
+"${LLVM_BUILD_DIR}/bin/llvm-lit" -sv "${MONOREPO_ROOT}/libcxx/test" \
  --param=enable_experimental=false \
  --param=enable_debug_tests=false \
  ${ENABLE_FILESYSTEM} \
@@ -141,8 +138,7 @@ echo "@@@ Running tests for libc++ and libc++abi @@@"
  
--param=target_triple="x86_64-apple-macosx${DEPLOYMENT_TARGET}" \
  
--param=cxx_library_root="${LLVM_INSTALL_DIR}/lib" \
  
--param=cxx_runtime_root="${LIBCXX_ROOT_ON_DEPLOYMENT_TARGET}" \
- 
--param=abi_library_root="${LLVM_INSTALL_DIR}/lib" \
- 

[PATCH] D90975: [clangd] Don't run clang-tidy AST traversal if there are no checks.

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: njames93.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added a project: clang.
sammccall requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

While here, clean up ParsedAST::build a bit:

- remove FIXMEs that were fixed long ago by ReplayPreamble
- remove redundant if, ClangTidyContext is not actually optional


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90975

Files:
  clang-tools-extra/clangd/ParsedAST.cpp


Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -303,9 +303,18 @@
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
 CTChecks = CTFactories.createChecks(CTContext.getPointer());
-ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
-   const clang::Diagnostic &Info) {
-  if (CTContext) {
+llvm::erase_if(CTChecks, [&](const auto &Check) {
+  return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
+});
+Preprocessor *PP = &Clang->getPreprocessor();
+for (const auto &Check : CTChecks) {
+  Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
+  Check->registerMatchers(&CTFinder);
+}
+
+if (!CTChecks.empty()) {
+  ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level 
DiagLevel,
+ const clang::Diagnostic &Info) {
 std::string CheckName = CTContext->getCheckName(Info.getID());
 bool IsClangTidyDiag = !CheckName.empty();
 if (IsClangTidyDiag) {
@@ -330,17 +339,8 @@
 return DiagnosticsEngine::Error;
   }
 }
-  }
-  return DiagLevel;
-});
-Preprocessor *PP = &Clang->getPreprocessor();
-for (const auto &Check : CTChecks) {
-  if (!Check->isLanguageVersionSupported(CTContext->getLangOpts()))
-continue;
-  // FIXME: the PP callbacks skip the entire preamble.
-  // Checks that want to see #includes in the main file do not see them.
-  Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
-  Check->registerMatchers(&CTFinder);
+return DiagLevel;
+  });
 }
   }
 
@@ -415,7 +415,7 @@
   std::vector ParsedDecls = Action->takeTopLevelDecls();
   // AST traversals should exclude the preamble, to avoid performance cliffs.
   Clang->getASTContext().setTraversalScope(ParsedDecls);
-  {
+  if (!CTChecks.empty()) {
 // Run the AST-dependent part of the clang-tidy checks.
 // (The preprocessor part ran already, via PPCallbacks).
 trace::Span Tracer("ClangTidyMatch");


Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -303,9 +303,18 @@
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
 CTChecks = CTFactories.createChecks(CTContext.getPointer());
-ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
-   const clang::Diagnostic &Info) {
-  if (CTContext) {
+llvm::erase_if(CTChecks, [&](const auto &Check) {
+  return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
+});
+Preprocessor *PP = &Clang->getPreprocessor();
+for (const auto &Check : CTChecks) {
+  Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
+  Check->registerMatchers(&CTFinder);
+}
+
+if (!CTChecks.empty()) {
+  ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
+ const clang::Diagnostic &Info) {
 std::string CheckName = CTContext->getCheckName(Info.getID());
 bool IsClangTidyDiag = !CheckName.empty();
 if (IsClangTidyDiag) {
@@ -330,17 +339,8 @@
 return DiagnosticsEngine::Error;
   }
 }
-  }
-  return DiagLevel;
-});
-Preprocessor *PP = &Clang->getPreprocessor();
-for (const auto &Check : CTChecks) {
-  if (!Check->isLanguageVersionSupported(CTContext->getLangOpts()))
-continue;
-  // FIXME: the PP callbacks skip the entire preamble.
-  // Checks that want to see #includes in the main file do not see them.
-  Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
-  Check->registerMatchers(&CTFinder);
+return DiagLevel;
+  });
 }
   }
 
@@ -415,7 +415,7 @@
   std::vector ParsedDecls = Action->takeTopLevelDecls();
   // AST traversals should exclude the preamble, to avoid performance cliffs.
   Clang->getASTContext().setTraversalScope(ParsedDecls);
-  {
+  if (!CTChecks.emp

[clang] c9ca3a3 - [AArch64] Add driver tests for HiSilicon's TSV110

2020-11-06 Thread Elvina Yakubova via cfe-commits

Author: Elvina Yakubova
Date: 2020-11-07T01:51:37+03:00
New Revision: c9ca3a3c66a493d72cf7afc7ee975e2de399f2e5

URL: 
https://github.com/llvm/llvm-project/commit/c9ca3a3c66a493d72cf7afc7ee975e2de399f2e5
DIFF: 
https://github.com/llvm/llvm-project/commit/c9ca3a3c66a493d72cf7afc7ee975e2de399f2e5.diff

LOG: [AArch64] Add driver tests for HiSilicon's TSV110

Added: 


Modified: 
clang/test/Driver/aarch64-cpus.c

Removed: 




diff  --git a/clang/test/Driver/aarch64-cpus.c 
b/clang/test/Driver/aarch64-cpus.c
index 356674e7a707..9cdf346148c3 100644
--- a/clang/test/Driver/aarch64-cpus.c
+++ b/clang/test/Driver/aarch64-cpus.c
@@ -295,6 +295,20 @@
 // ARM64-THUNDERX3T110: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" 
"thunderx3t110" "-target-feature" "+v8.3a"
 // ARM64-THUNDERX3T110-TUNE: "-cc1"{{.*}} "-triple" "arm64{{.*}}" 
"-target-cpu" "generic"
 
+// RUN: %clang -target aarch64 -mcpu=tsv110 -### -c %s 2>&1 | FileCheck 
-check-prefix=TSV110 %s
+// RUN: %clang -target aarch64 -mlittle-endian -mcpu=tsv110 -### -c %s 2>&1 | 
FileCheck -check-prefix=TSV110 %s
+// RUN: %clang -target aarch64 -mtune=tsv110 -### -c %s 2>&1 | FileCheck 
-check-prefix=TSV110-TUNE %s
+// RUN: %clang -target aarch64 -mlittle-endian -mtune=tsv110 -### -c %s 2>&1 | 
FileCheck -check-prefix=TSV110-TUNE %s
+// TSV110: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "tsv110"
+// TSV110-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic"
+
+// RUN: %clang -target arm64 -mcpu=tsv110 -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-TSV110 %s
+// RUN: %clang -target arm64 -mlittle-endian -mcpu=tsv110 -### -c %s 2>&1 | 
FileCheck -check-prefix=ARM64-TSV110 %s
+// RUN: %clang -target arm64 -mtune=tsv110 -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-TSV110-TUNE %s
+// RUN: %clang -target arm64 -mlittle-endian -mtune=tsv110 -### -c %s 2>&1 | 
FileCheck -check-prefix=ARM64-TSV110-TUNE %s
+// ARM64-TSV110: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "tsv110"
+// ARM64-TSV110-TUNE: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" 
"generic"
+
 // RUN: %clang -target aarch64 -mcpu=a64fx -### -c %s 2>&1 | FileCheck 
-check-prefix=A64FX %s
 // RUN: %clang -target aarch64 -mlittle-endian -mcpu=a64fx -### -c %s 2>&1 | 
FileCheck -check-prefix=A64FX %s
 // RUN: %clang -target aarch64 -mtune=a64fx -### -c %s 2>&1 | FileCheck 
-check-prefix=A64FX-TUNE %s



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


[PATCH] D90976: Fixed an issue where diagnostics printed expressions in a roundabout way

2020-11-06 Thread Wyatt Childers via Phabricator via cfe-commits
wchilders created this revision.
wchilders added reviewers: yaxunl, hans, rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
wchilders requested review of this revision.

Previously expressions were being printed in diagnostics via an implicit 
conversion to an expression template argument -- which would then be printed 
via some code with a comment suggesting the code path was only for completeness 
and rarely/never used; this was both roundabout, and subtle. This patch 
provides a more direct overload, though the patch is still imperfect, as it 
does not solve the associated LangOpts issue.

Additionally, to prevent similar issues in the future, this patch makes 
conversions from expressions to template arguments explicit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90976

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h

Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3542,7 +3542,7 @@
   if (Result.isInvalid())
 return TemplateArgumentLoc();
 
-  return TemplateArgumentLoc(Result.get(), Result.get());
+  return TemplateArgumentLoc(TemplateArgument(Result.get()), Result.get());
 }
 
 case TemplateArgument::Template:
@@ -3822,7 +3822,8 @@
   Expr *Pattern = Expansion->getPattern();
 
   SmallVector Unexpanded;
-  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
+  getSema().collectUnexpandedParameterPacks(
+  TemplateArgument(Pattern), Unexpanded);
   assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
 
   // Determine whether the set of unexpanded parameter packs can and should
@@ -12420,7 +12421,8 @@
  ->getTypeLoc()
  .castAs();
   SmallVector Unexpanded;
-  SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
+  SemaRef.collectUnexpandedParameterPacks(
+  TemplateArgument(OldVD->getInit()), Unexpanded);
 
   // Determine whether the set of unexpanded parameter packs can and should
   // be expanded.
@@ -13016,8 +13018,8 @@
 E->getPackLoc());
 if (DRE.isInvalid())
   return ExprError();
-ArgStorage = new (getSema().Context) PackExpansionExpr(
-getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
+ArgStorage = TemplateArgument(new (getSema().Context) PackExpansionExpr(
+getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None));
   }
   PackArgs = ArgStorage;
 }
@@ -13155,7 +13157,8 @@
   Expr *Pattern = E->getPattern();
 
   SmallVector Unexpanded;
-  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
+  getSema().collectUnexpandedParameterPacks(
+  TemplateArgument(Pattern), Unexpanded);
   assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
 
   // Determine whether the set of unexpanded parameter packs can and should
@@ -13351,8 +13354,10 @@
 if (OrigElement.isPackExpansion()) {
   // This key/value element is a pack expansion.
   SmallVector Unexpanded;
-  getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
-  getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
+  getSema().collectUnexpandedParameterPacks(
+  TemplateArgument(OrigElement.Key), Unexpanded);
+  getSema().collectUnexpandedParameterPacks(
+  TemplateArgument(OrigElement.Value), Unexpanded);
   assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
 
   // Determine whether the set of unexpanded parameter packs can
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1089,7 +1089,7 @@
 Expr *Pattern = Expansion->getPattern();
 Ellipsis = Expansion->getEllipsisLoc();
 NumExpansions = Expansion->getNumExpansions();
-return TemplateArgumentLoc(Pattern, Pattern);
+return TemplateArgumentLoc(TemplateArgument(Pattern), Pattern);
   }
 
   case TemplateArgument::TemplateExpansion:
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -109,8 +109,8 @@
 
   SmallVector Unexpanded;
   if

[PATCH] D90555: [clangd] Handle duplicate enum constants in PopulateSwitch tweak

2020-11-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:68
+  // Maps the Enum values to the EnumConstantDecl and a bool signifying if its
+  // covered in the switch.
+  llvm::MapVector>

I'd make the values here a struct with named fields for readability, but up to 
you.



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:127
+  unsigned EnumIntWidth = Ctx.getIntWidth(QualType(EnumT, 0));
+  bool EnumIsSigned = EnumT->isSignedIntegerOrEnumerationType();
+

nit: I'd add a lambda here like

```
auto Normalize(llvm::APSInt Val) {
  Val = Val.extOrTrunc(EnumIntWidth);
  Val.setIsSigned(EnumIsSigned);
  return Val;
};
```

you'll use it twice, and the callsites will be more readable



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:129
+
+  EnumConstants.clear();
+

it's already clear at this point.



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:165
+auto Iter = EnumConstants.find(Val);
+if (Iter == EnumConstants.end())
+  return false;

this says if you ever have a case statement that doesn't match an enum value, 
then we don't offer the tweak. Why?



Comment at: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp:170
+// we encounter it.
+if (IsCovered)
+  return false;

Do we really need to specially detect or handle this?

Seems like a blind
```
if (Iter != EnumConstants.end())
  Iter->second.second = true; // mark as covered
```
would be enough here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90555

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


[PATCH] D89177: [cmake] Add support for multiple distributions

2020-11-06 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM with a few nits.




Comment at: clang/cmake/modules/AddClang.cmake:121
+  set(export_to_clangtargets EXPORT Clang${distribution}Targets)
+  set_property(GLOBAL PROPERTY CLANG${distribution}_HAS_EXPORTS True)
 endif()

Should we make this uppercase and join it with `_` to match the existing 
conventions? For example, you'd have `ClangToolchainTargets` and 
`CLANG_TOOLCHAIN_HAS_EXPORTS`. With the change as is, we would end up with 
`CLANGToolchain_HAS_EXPORT` which is a bit unusual.



Comment at: lld/cmake/modules/LLDConfig.cmake.in:13
 # Provide all our library targets to users.
-include("@LLD_CONFIG_EXPORTS_FILE@")
+@lld_config_include_exports@

We use upper-case variables for the `*_CONFIG_CODE` so using lower case here is 
a bit unfortunate, could we use upper case for these variables?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89177

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


[PATCH] D87928: Provide -fsource-dir flag in Clang

2020-11-06 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 303567.

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

https://reviews.llvm.org/D87928

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/lib/CodeGen/CoverageMappingGen.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/CoverageMapping/source_dir.c
  clang/test/Preprocessor/file_test.c
  llvm/include/llvm/Support/Path.h
  llvm/lib/Support/Path.cpp
  llvm/unittests/Support/Path.cpp

Index: llvm/unittests/Support/Path.cpp
===
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -1547,6 +1547,35 @@
   EXPECT_EQ(Path, "C:\\old/foo\\bar");
 }
 
+static std::string make_relative(StringRef from, StringRef to,
+ path::Style style) {
+  SmallString<256> buffer;
+  path::make_relative(from, to, buffer, style);
+  return std::string(buffer.str());
+}
+
+TEST(Support, MakeRelative) {
+  EXPECT_EQ("", make_relative("/a/b/c/d", "/a/b/c/d", path::Style::posix));
+  EXPECT_EQ("d", make_relative("/a/b/c/d", "/a/b/c", path::Style::posix));
+  EXPECT_EQ("c/d", make_relative("/a/b/c/d", "/a/b", path::Style::posix));
+  EXPECT_EQ("../../c/d",
+make_relative("/a/b/c/d", "/a/b/e/f", path::Style::posix));
+  EXPECT_EQ("../../../../a/b/c/d",
+make_relative("/a/b/c/d", "/e/f/g/h", path::Style::posix));
+
+  EXPECT_EQ("", make_relative("C:\\a\\b\\c\\d", "C:\\a\\b\\c\\d",
+  path::Style::windows));
+  EXPECT_EQ("d", make_relative("C:\\a\\b\\c\\d", "C:\\a\\b\\c",
+   path::Style::windows));
+  EXPECT_EQ("c\\d",
+make_relative("C:\\a\\b\\c\\d", "C:\\a\\b", path::Style::windows));
+  EXPECT_EQ("..\\..\\c\\d", make_relative("C:\\a\\b\\c\\d", "C:\\a\\b\\e\\f",
+  path::Style::windows));
+  EXPECT_EQ(
+  "..\\..\\..\\..\\a\\b\\c\\d",
+  make_relative("C:\\a\\b\\c\\d", "C:\\e\\f\\g\\h", path::Style::windows));
+}
+
 TEST_F(FileSystemTest, OpenFileForRead) {
   // Create a temp file.
   int FileDescriptor;
Index: llvm/lib/Support/Path.cpp
===
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -775,6 +775,22 @@
   return true;
 }
 
+void make_relative(StringRef from, StringRef to, SmallVectorImpl &result,
+   Style style) {
+  SmallString<256> buffer;
+  auto fromIt = begin(from, style), fromE = end(from);
+  auto toIt = begin(to, style), toE = end(to);
+  // Find a common base.
+  for (; fromIt != fromE && toIt != toE && *fromIt == *toIt; ++fromIt, ++toIt)
+;
+  // Navigate backwards to the base.
+  for (; toIt != toE; ++toIt)
+if (*toIt != ".")
+  append(buffer, style, "..");
+  append(buffer, fromIt, fromE, style);
+  result.swap(buffer);
+}
+
 } // end namespace path
 
 namespace fs {
Index: llvm/include/llvm/Support/Path.h
===
--- llvm/include/llvm/Support/Path.h
+++ llvm/include/llvm/Support/Path.h
@@ -514,6 +514,10 @@
 bool remove_dots(SmallVectorImpl &path, bool remove_dot_dot = false,
  Style style = Style::native);
 
+/// Return a path that when appeneded to from resolves to the same as to.
+void make_relative(StringRef from, StringRef to, SmallVectorImpl &result,
+   Style style = Style::native);
+
 } // end namespace path
 } // end namespace sys
 } // end namespace llvm
Index: clang/test/Preprocessor/file_test.c
===
--- clang/test/Preprocessor/file_test.c
+++ clang/test/Preprocessor/file_test.c
@@ -3,6 +3,7 @@
 // RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
 // RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
 // RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
+// RUN: %clang -E -fsource-dir %S -c -o - %s | FileCheck %s --check-prefix CHECK-RELATIVE
 
 filename: __FILE__
 #include "Inputs/include-file-test/file_test.h"
@@ -21,3 +22,8 @@
 // CHECK-REMOVE: filename: "Inputs/include-file-test/file_test.h"
 // CHECK-REMOVE: basefile: "file_test.c"
 // CHECK-REMOVE-NOT: filename:
+
+// CHECK-RELATIVE: filename: "file_test.c"
+// CHECK-RELATIVE: filename: "Inputs/include-file-test/file_test.h"
+// CHECK-RELATIVE: basefile: "file_test.c"
+// CHECK-RELATIVE-NOT: filename:
Index: clang/test/CoverageMapping/source_dir.c
===
--- /dev/null
+++ clang/test/CoverageMapping/source_dir.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -f

  1   2   >