[PATCH] D86671: [clang-tidy] Add new case type to check variables with Hungarian notation

2020-08-30 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

As Hungarian notation enforces prefixes as well as casing styles it would be 
wise to warn on cases where the style is Hungarian but a prefix has also been 
set.

Another issue is this current set up will let you define any decls style as 
hungarian, this doesn't make sense for most decl types. 
Potentially some validation should happen for that too,




Comment at: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h:127
   virtual llvm::Optional
-  GetDeclFailureInfo(const NamedDecl *Decl, const SourceManager &SM) const = 0;
+  GetDeclFailureInfo(const StringRef &Type, const NamedDecl *Decl,
+ const SourceManager &SM) const = 0;

I'm not a fan of changing the base class for this support. The Type paramater 
can be inferred using the Decl. 
You can `dyn_cast` the Decl to a `ValueDecl` and then get its type from that.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D86671

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


[PATCH] D85031: [builtins] Unify the softfloat division implementation

2020-08-30 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko updated this revision to Diff 288850.
atrosinenko added a comment.
Herald added a subscriber: danielkiss.

Add more clarifications, fix explanation for "why it is enough to adjust only 
once in case of overflow".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85031

Files:
  compiler-rt/lib/builtins/divdf3.c
  compiler-rt/lib/builtins/divsf3.c
  compiler-rt/lib/builtins/divtf3.c
  compiler-rt/lib/builtins/fp_div_impl.inc
  compiler-rt/lib/builtins/fp_lib.h
  compiler-rt/lib/builtins/int_util.h
  compiler-rt/test/builtins/Unit/divdf3_test.c

Index: compiler-rt/test/builtins/Unit/divdf3_test.c
===
--- compiler-rt/test/builtins/Unit/divdf3_test.c
+++ compiler-rt/test/builtins/Unit/divdf3_test.c
@@ -92,5 +92,13 @@
 if (test__divdf3(0x1.0p+0, 0x1.0001p+0, UINT64_C(0x3fefffe0)))
   return 1;
 
+// some misc test cases obtained by fuzzing against h/w implementation
+if (test__divdf3(0x1.fdc239dd64735p-658, -0x1.fff9364c0843fp-948, UINT64_C(0xd20fdc8fc0ceffb1)))
+  return 1;
+if (test__divdf3(-0x1.78abb261d47c8p+794, 0x1.fb01d537cc5aep+266, UINT64_C(0xe0e7c6148ffc23e3)))
+  return 1;
+if (test__divdf3(-0x1.da7dfe6048b8bp-875, 0x1.ffc7ea3ff60a4p-610, UINT64_C(0xaf5dab1fe0269e2a)))
+  return 1;
+
 return 0;
 }
Index: compiler-rt/lib/builtins/int_util.h
===
--- compiler-rt/lib/builtins/int_util.h
+++ compiler-rt/lib/builtins/int_util.h
@@ -28,4 +28,20 @@
 #define COMPILE_TIME_ASSERT2(expr, cnt)\
   typedef char ct_assert_##cnt[(expr) ? 1 : -1] UNUSED
 
+// Force unrolling the code specified to be repeated N times.
+#define REPEAT_0_TIMES(code_to_repeat) /* do nothing */
+#define REPEAT_1_TIMES(code_to_repeat) code_to_repeat
+#define REPEAT_2_TIMES(code_to_repeat) \
+  REPEAT_1_TIMES(code_to_repeat)   \
+  code_to_repeat
+#define REPEAT_3_TIMES(code_to_repeat) \
+  REPEAT_2_TIMES(code_to_repeat)   \
+  code_to_repeat
+#define REPEAT_4_TIMES(code_to_repeat) \
+  REPEAT_3_TIMES(code_to_repeat)   \
+  code_to_repeat
+
+#define REPEAT_N_TIMES_(N, code_to_repeat) REPEAT_##N##_TIMES(code_to_repeat)
+#define REPEAT_N_TIMES(N, code_to_repeat) REPEAT_N_TIMES_(N, code_to_repeat)
+
 #endif // INT_UTIL_H
Index: compiler-rt/lib/builtins/fp_lib.h
===
--- compiler-rt/lib/builtins/fp_lib.h
+++ compiler-rt/lib/builtins/fp_lib.h
@@ -40,9 +40,12 @@
 
 #if defined SINGLE_PRECISION
 
+typedef uint16_t half_rep_t;
 typedef uint32_t rep_t;
+typedef uint64_t twice_rep_t;
 typedef int32_t srep_t;
 typedef float fp_t;
+#define HALF_REP_C UINT16_C
 #define REP_C UINT32_C
 #define significandBits 23
 
@@ -58,9 +61,11 @@
 
 #elif defined DOUBLE_PRECISION
 
+typedef uint32_t half_rep_t;
 typedef uint64_t rep_t;
 typedef int64_t srep_t;
 typedef double fp_t;
+#define HALF_REP_C UINT32_C
 #define REP_C UINT64_C
 #define significandBits 52
 
@@ -102,9 +107,11 @@
 #elif defined QUAD_PRECISION
 #if __LDBL_MANT_DIG__ == 113 && defined(__SIZEOF_INT128__)
 #define CRT_LDBL_128BIT
+typedef uint64_t half_rep_t;
 typedef __uint128_t rep_t;
 typedef __int128_t srep_t;
 typedef long double fp_t;
+#define HALF_REP_C UINT64_C
 #define REP_C (__uint128_t)
 // Note: Since there is no explicit way to tell compiler the constant is a
 // 128-bit integer, we let the constant be casted to 128-bit integer
Index: compiler-rt/lib/builtins/fp_div_impl.inc
===
--- /dev/null
+++ compiler-rt/lib/builtins/fp_div_impl.inc
@@ -0,0 +1,405 @@
+//===-- fp_div_impl.inc - Floating point division -*- 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 file implements soft-float division with the IEEE-754 default
+// rounding (to nearest, ties to even).
+//
+//===--===//
+
+#include "fp_lib.h"
+
+// The __divXf3__ function implements Newton-Raphson floating point division.
+// It uses 3 iterations for float32, 4 for float64 and 5 for float128,
+// respectively. Due to number of significant bits being roughly doubled
+// every iteration, the two modes are supported: N full-width iterations (as
+// it is done for float32 by default) and (N-1) half-width iterat

[PATCH] D85032: [builtins] Make divXf3 handle denormal results

2020-08-30 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko updated this revision to Diff 288851.
atrosinenko added a comment.
Herald added a subscriber: danielkiss.

Re-upload after amending parent diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85032

Files:
  compiler-rt/lib/builtins/fp_div_impl.inc
  compiler-rt/test/builtins/Unit/divdf3_test.c
  compiler-rt/test/builtins/Unit/divsf3_test.c
  compiler-rt/test/builtins/Unit/divtf3_test.c

Index: compiler-rt/test/builtins/Unit/divtf3_test.c
===
--- compiler-rt/test/builtins/Unit/divtf3_test.c
+++ compiler-rt/test/builtins/Unit/divtf3_test.c
@@ -146,6 +146,13 @@
  UINT64_C(0xfffe)))
 return 1;
 
+// smallest normal value divided by 2.0
+if (test__divtf3(0x1.0p-16382L, 2.L, UINT64_C(0x8000), UINT64_C(0x0)))
+  return 1;
+// smallest subnormal result
+if (test__divtf3(0x1.0p-1022L, 0x1p+52L, UINT64_C(0x0), UINT64_C(0x1)))
+  return 1;
+
 // any / any
 if (test__divtf3(0x1.a23b45362464523375893ab4cdefp+5L,
  0x1.eedcbaba3a94546558237654321fp-1L,
Index: compiler-rt/test/builtins/Unit/divsf3_test.c
===
--- compiler-rt/test/builtins/Unit/divsf3_test.c
+++ compiler-rt/test/builtins/Unit/divsf3_test.c
@@ -92,5 +92,20 @@
 if (test__divsf3(0x1.0p+0F, 0x1.0001p+0F, UINT32_C(0x3f7fff00)))
   return 1;
 
+// smallest normal value divided by 2.0
+if (test__divsf3(0x1.0p-126F, 2.0F, UINT32_C(0x0040)))
+  return 1;
+// smallest subnormal result
+if (test__divsf3(0x1.0p-126F, 0x1p+23F, UINT32_C(0x0001)))
+  return 1;
+
+// some misc test cases obtained by fuzzing against h/w implementation
+if (test__divsf3(-0x1.3e75e6p-108F, -0x1.cf372p+38F, UINT32_C(0x0006)))
+  return 1;
+if (test__divsf3(0x1.e77c54p+81F, -0x1.e77c52p-47F, UINT32_C(0xff80)))
+  return 1;
+if (test__divsf3(0x1.fep-126F, 2.F, UINT32_C(0x0080)))
+  return 1;
+
 return 0;
 }
Index: compiler-rt/test/builtins/Unit/divdf3_test.c
===
--- compiler-rt/test/builtins/Unit/divdf3_test.c
+++ compiler-rt/test/builtins/Unit/divdf3_test.c
@@ -92,6 +92,13 @@
 if (test__divdf3(0x1.0p+0, 0x1.0001p+0, UINT64_C(0x3fefffe0)))
   return 1;
 
+// smallest normal value divided by 2.0
+if (test__divdf3(0x1.0p-1022, 2., UINT64_C(0x0008)))
+  return 1;
+// smallest subnormal result
+if (test__divdf3(0x1.0p-1022, 0x1.0p+52, UINT64_C(0x0001)))
+  return 1;
+
 // some misc test cases obtained by fuzzing against h/w implementation
 if (test__divdf3(0x1.fdc239dd64735p-658, -0x1.fff9364c0843fp-948, UINT64_C(0xd20fdc8fc0ceffb1)))
   return 1;
@@ -99,6 +106,12 @@
   return 1;
 if (test__divdf3(-0x1.da7dfe6048b8bp-875, 0x1.ffc7ea3ff60a4p-610, UINT64_C(0xaf5dab1fe0269e2a)))
   return 1;
+if (test__divdf3(0x1.0p-1022, 0x1.9p+5, UINT64_C(0x51eb851eb852)))
+  return 1;
+if (test__divdf3(0x1.0p-1022, 0x1.0028p+41, UINT64_C(0x07ff)))
+  return 1;
+if (test__divdf3(0x1.0p-1022, 0x1.0028p+52, UINT64_C(0x1)))
+  return 1;
 
 return 0;
 }
Index: compiler-rt/lib/builtins/fp_div_impl.inc
===
--- compiler-rt/lib/builtins/fp_div_impl.inc
+++ compiler-rt/lib/builtins/fp_div_impl.inc
@@ -344,6 +344,7 @@
   if (quotient_UQ1 < (implicitBit << 1)) {
 residualLo = (aSignificand << (significandBits + 1)) - quotient_UQ1 * bSignificand;
 writtenExponent -= 1;
+aSignificand <<= 1;
 
 // the error is doubled
   } else {
@@ -373,19 +374,25 @@
   // Now, quotient_UQ1_SB <= the correctly-rounded result
   // and may need taking NextAfter() up to 3 times (see error estimates above)
   // r = a - b * q
+  rep_t absResult;
+  if (writtenExponent > 0) {
+// Clear the implicit bit
+absResult = quotient_UQ1 & significandMask;
+// Insert the exponent
+absResult |= (rep_t)writtenExponent << significandBits;
+residualLo <<= 1;
+  } else {
+// Prevent shift amount from being negative
+if (significandBits + writtenExponent < 0)
+  return fromRep(quotientSign);
 
-  if (writtenExponent < 0) {
-// Result is definitely subnormal, flushing to zero
-return fromRep(quotientSign);
-  }
+absResult = quotient_UQ1 >> (-writtenExponent + 1);
 
-  // Clear the implicit bit
-  rep_t absResult = quotient_UQ1 & significandMask;
-  // Insert the exponent
-  absResult |= (rep_t)writtenExponent << significandBits;
+// multiplied by two to prevent shift amount to be negative
+residualLo = (aSignificand << (significandBits + writtenExponent)) - (absResult * bSignificand << 1);
+  }
 
   // Round
-  residualLo <<= 1;

[PATCH] D86780: Copy blocks in variadic methods

2020-08-30 Thread 酷酷的哀殿 via Phabricator via cfe-commits
sunbohong updated this revision to Diff 288853.
sunbohong added a comment.
Herald added a subscriber: danielkiss.

Update copy blocks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86780

Files:
  clang/lib/Sema/SemaExprObjC.cpp


Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -1776,6 +1776,18 @@
  Args.back()->getEndLoc());
 }
   }
+  if (!IsError) {
+for (unsigned i = NumNamedArgs, e = Args.size(); i < e; ++i) {
+  if (Args[i]->isTypeDependent())
+continue;
+  // copy blocks [NSArray arrayWithObjects:^(){NSLog(@"blk0:%d", 
val);},^(){NSLog(@"blk1:%d", val);}, nil];
+  if (Args[i]->getType()->isBlockPointerType()) {
+ExprResult arg = Args[i];
+maybeExtendBlockObject(arg);
+Args[i] = arg.get();
+  }
+}
+  }
 
   DiagnoseSentinelCalls(Method, SelLoc, Args);
 


Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -1776,6 +1776,18 @@
  Args.back()->getEndLoc());
 }
   }
+  if (!IsError) {
+for (unsigned i = NumNamedArgs, e = Args.size(); i < e; ++i) {
+  if (Args[i]->isTypeDependent())
+continue;
+  // copy blocks [NSArray arrayWithObjects:^(){NSLog(@"blk0:%d", val);},^(){NSLog(@"blk1:%d", val);}, nil];
+  if (Args[i]->getType()->isBlockPointerType()) {
+ExprResult arg = Args[i];
+maybeExtendBlockObject(arg);
+Args[i] = arg.get();
+  }
+}
+  }
 
   DiagnoseSentinelCalls(Method, SelLoc, Args);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86400: [NFC][compiler-rt] Factor out __div[sdt]i3 and __mod[dt]i3 implementations

2020-08-30 Thread Anatoly Trosinenko 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 rG11cf6346fd49: [NFC][compiler-rt] Factor out __div[sdt]i3 and 
__mod[dt]i3 implementations (authored by atrosinenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86400

Files:
  compiler-rt/lib/builtins/divdi3.c
  compiler-rt/lib/builtins/divsi3.c
  compiler-rt/lib/builtins/divti3.c
  compiler-rt/lib/builtins/int_div_impl.inc
  compiler-rt/lib/builtins/moddi3.c
  compiler-rt/lib/builtins/modti3.c

Index: compiler-rt/lib/builtins/modti3.c
===
--- compiler-rt/lib/builtins/modti3.c
+++ compiler-rt/lib/builtins/modti3.c
@@ -16,15 +16,11 @@
 
 // Returns: a % b
 
-COMPILER_RT_ABI ti_int __modti3(ti_int a, ti_int b) {
-  const int bits_in_tword_m1 = (int)(sizeof(ti_int) * CHAR_BIT) - 1;
-  ti_int s = b >> bits_in_tword_m1; // s = b < 0 ? -1 : 0
-  b = (b ^ s) - s;  // negate if s == -1
-  s = a >> bits_in_tword_m1;// s = a < 0 ? -1 : 0
-  a = (a ^ s) - s;  // negate if s == -1
-  tu_int r;
-  __udivmodti4(a, b, &r);
-  return ((ti_int)r ^ s) - s; // negate if s == -1
-}
+#define fixint_t ti_int
+#define fixuint_t tu_int
+#define ASSIGN_UMOD(res, a, b) __udivmodti4((a), (b), &(res))
+#include "int_div_impl.inc"
+
+COMPILER_RT_ABI ti_int __modti3(ti_int a, ti_int b) { return __modXi3(a, b); }
 
 #endif // CRT_HAS_128BIT
Index: compiler-rt/lib/builtins/moddi3.c
===
--- compiler-rt/lib/builtins/moddi3.c
+++ compiler-rt/lib/builtins/moddi3.c
@@ -14,13 +14,9 @@
 
 // Returns: a % b
 
-COMPILER_RT_ABI di_int __moddi3(di_int a, di_int b) {
-  const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1;
-  di_int s = b >> bits_in_dword_m1; // s = b < 0 ? -1 : 0
-  b = (b ^ s) - s;  // negate if s == -1
-  s = a >> bits_in_dword_m1;// s = a < 0 ? -1 : 0
-  a = (a ^ s) - s;  // negate if s == -1
-  du_int r;
-  __udivmoddi4(a, b, &r);
-  return ((di_int)r ^ s) - s; // negate if s == -1
-}
+#define fixint_t di_int
+#define fixuint_t du_int
+#define ASSIGN_UMOD(res, a, b) __udivmoddi4((a), (b), &(res))
+#include "int_div_impl.inc"
+
+COMPILER_RT_ABI di_int __moddi3(di_int a, di_int b) { return __modXi3(a, b); }
Index: compiler-rt/lib/builtins/int_div_impl.inc
===
--- compiler-rt/lib/builtins/int_div_impl.inc
+++ compiler-rt/lib/builtins/int_div_impl.inc
@@ -68,3 +68,28 @@
   }
   return r;
 }
+
+#ifdef COMPUTE_UDIV
+static __inline fixint_t __divXi3(fixint_t a, fixint_t b) {
+  const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1;
+  fixint_t s_a = a >> N;   // s_a = a < 0 ? -1 : 0
+  fixint_t s_b = b >> N;   // s_b = b < 0 ? -1 : 0
+  a = (a ^ s_a) - s_a; // negate if s_a == -1
+  b = (b ^ s_b) - s_b; // negate if s_b == -1
+  s_a ^= s_b;  // sign of quotient
+  return (COMPUTE_UDIV(a, b) ^ s_a) - s_a; // negate if s_a == -1
+}
+#endif // COMPUTE_UDIV
+
+#ifdef ASSIGN_UMOD
+static __inline fixint_t __modXi3(fixint_t a, fixint_t b) {
+  const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1;
+  fixint_t s = b >> N;// s = b < 0 ? -1 : 0
+  b = (b ^ s) - s;// negate if s == -1
+  s = a >> N; // s = a < 0 ? -1 : 0
+  a = (a ^ s) - s;// negate if s == -1
+  fixuint_t res;
+  ASSIGN_UMOD(res, a, b);
+  return (res ^ s) - s;   // negate if s == -1
+}
+#endif // ASSIGN_UMOD
Index: compiler-rt/lib/builtins/divti3.c
===
--- compiler-rt/lib/builtins/divti3.c
+++ compiler-rt/lib/builtins/divti3.c
@@ -16,14 +16,11 @@
 
 // Returns: a / b
 
-COMPILER_RT_ABI ti_int __divti3(ti_int a, ti_int b) {
-  const int bits_in_tword_m1 = (int)(sizeof(ti_int) * CHAR_BIT) - 1;
-  ti_int s_a = a >> bits_in_tword_m1;   // s_a = a < 0 ? -1 : 0
-  ti_int s_b = b >> bits_in_tword_m1;   // s_b = b < 0 ? -1 : 0
-  a = (a ^ s_a) - s_a;  // negate if s_a == -1
-  b = (b ^ s_b) - s_b;  // negate if s_b == -1
-  s_a ^= s_b;   // sign of quotient
-  return (__udivmodti4(a, b, (tu_int *)0) ^ s_a) - s_a; // negate if s_a == -1
-}
+#define fixint_t ti_int
+#define fixuint_t tu_int
+#define COMPUTE_UDIV(a, b) __udivmodti4((a), (b), (tu_int *)0)
+#include "int_div_impl.inc"
+
+COMPILER_RT_ABI ti_int __divti3(ti_int a, ti_int b) { return __divXi3(a, b); }
 
 #endif // CRT_HAS_128BIT
Index: compiler-rt/lib/builtins/divsi3.c
===
--- compiler-rt/lib/builtins/divsi3.c
+++ compiler-r

[PATCH] D86853: [modules] Repro for pure virtual base class method crash

2020-08-30 Thread Andrew Gallagher via Phabricator via cfe-commits
andrewjcg created this revision.
Herald added subscribers: cfe-commits, danielkiss.
Herald added a project: clang.
andrewjcg requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86853

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/set-pure-crash/a.h
  clang/test/Modules/Inputs/set-pure-crash/b.h
  clang/test/Modules/Inputs/set-pure-crash/c.h
  clang/test/Modules/Inputs/set-pure-crash/module.modulemap
  clang/test/Modules/set-pure-crash.cpp

Index: clang/test/Modules/set-pure-crash.cpp
===
--- /dev/null
+++ clang/test/Modules/set-pure-crash.cpp
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -O0 -emit-llvm -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I %S/Inputs/set-pure-crash -verify %s -o %t
+
+// expected-no-diagnostics
+
+#include "b.h"
+#include "c.h"
+
+auto t = simple();
Index: clang/test/Modules/Inputs/set-pure-crash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/set-pure-crash/module.modulemap
@@ -0,0 +1,11 @@
+module a {
+  header "a.h"
+}
+
+module b {
+  header "b.h"
+}
+
+module c {
+  header "c.h"
+}
Index: clang/test/Modules/Inputs/set-pure-crash/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/set-pure-crash/c.h
@@ -0,0 +1,5 @@
+#pragma once
+
+template 
+struct simple {
+};
Index: clang/test/Modules/Inputs/set-pure-crash/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/set-pure-crash/b.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "a.h"
+#include "c.h"
+
+template >
+void foo(Fun) {}
+
+class Child : public Base {
+public:
+  void func() {
+foo([]() {});
+  }
+};
Index: clang/test/Modules/Inputs/set-pure-crash/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/set-pure-crash/a.h
@@ -0,0 +1,11 @@
+#pragma once
+
+struct Tag {};
+
+template 
+class Base {
+public:
+  virtual void func() = 0;
+};
+
+Base bar();
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -864,7 +864,10 @@
   FD->setInlineSpecified(Record.readInt());
   FD->setImplicitlyInline(Record.readInt());
   FD->setVirtualAsWritten(Record.readInt());
-  FD->setPure(Record.readInt());
+  // We defer calling `FunctionDecl::setPure()` here as for methods of
+  // `CXXTemplateSpecializationDecl`s, we may not have connected up the
+  // definition (which is required for `setPure`).
+  const bool pure = Record.readInt();
   FD->setHasInheritedPrototype(Record.readInt());
   FD->setHasWrittenPrototype(Record.readInt());
   FD->setDeletedAsWritten(Record.readInt());
@@ -1012,6 +1015,10 @@
   }
   }
 
+  // Defer calling `setPure` until merging above has guaranteed we've set
+  // `DefinitionData` (as this will need to access it).
+  FD->setPure(pure);
+
   // Read in the parameters.
   unsigned NumParams = Record.readInt();
   SmallVector Params;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86854: [CodeGen] Make sure the EH cleanup for block captures is conditional when the block literal is in a conditional context

2020-08-30 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
erik.pilkington added reviewers: ahatanak, rjmccall.
Herald added subscribers: danielkiss, ributzka, dexonsmith, jkorous.
erik.pilkington requested review of this revision.

Previously, clang was crashing on the attached test because the EH cleanup for 
the block capture was incorrectly emitted under the assumption that the 
expression wasn't conditionally evaluated. This was because before D81624 
, `pushLifetimeExtendedDestroy` was mainly 
used with C++ automatic lifetime extension (i.e. `const T &x = tmp();`), where 
a conditionally evaluated expression wasn't possible. Now that we're using this 
path for block captures, we need to handle this case.

rdar://66250047


https://reviews.llvm.org/D86854

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGenObjC/arc-blocks-exceptions.m

Index: clang/test/CodeGenObjC/arc-blocks-exceptions.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/arc-blocks-exceptions.m
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -fexceptions -disable-llvm-passes -o - %s | FileCheck %s
+
+void test1(_Bool c) {
+  void test1_fn(void (^blk)());
+  __weak id weakId = 0;
+  test1_fn(c ? ^{ (void)weakId; } : 0);
+
+  // CHECK: [[CLEANUP_COND:%.*]] = alloca i1
+  // CHECK-NEXT: [[CLEANUP_SAVE:%.*]] = alloca i8**
+
+  // CHECK: store i1 true, i1* [[CLEANUP_COND]]
+  // CHECK-NEXT: store i8** {{.*}}, i8*** [[CLEANUP_SAVE]]
+
+  // CHECK: invoke void @test1_fn(
+  // CHECK-NEXT: to label %[[INVOKE_CONT:.*]] unwind label %[[LANDING_PAD_LAB:.*]]
+
+  // CHECK: [[INVOKE_CONT]]:
+  // CHECK-NEXT: [[LOAD:%.*]] = load i1, i1* [[CLEANUP_COND]]
+  // CHECK-NEXT: br i1 [[LOAD]], label %[[END_OF_SCOPE_LAB:.*]], label
+
+  // CHECK: [[END_OF_SCOPE_LAB]]:
+  // CHECK-NEXT: [[LOAD:%.*]] = load i8**, i8*** [[CLEANUP_SAVE]]
+  // CHECK-NEXT: call void @llvm.objc.destroyWeak(i8** [[LOAD]])
+  // CHECK-NEXT: br label
+
+  // CHECK: [[LANDING_PAD_LAB]]:
+  //   /* some EH stuff */
+  // CHECK:  [[LOAD:%.*]] = load i1, i1* [[CLEANUP_COND]]
+  // CHECK-NEXT: br i1 [[LOAD]], label %[[EH_CLEANUP_LAB:.*]], label
+
+  // CHECK: [[EH_CLEANUP_LAB]]:
+  // CHECK-NEXT: [[LOAD:%.*]] = load i8**, i8*** [[CLEANUP_SAVE]]
+  // CHECK-NEXT: call void @llvm.objc.destroyWeak(i8** [[LOAD]])
+  // CHECK-NEXT: br label
+}
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -672,12 +672,13 @@
 initFullExprCleanup();
   }
 
-  /// Queue a cleanup to be pushed after finishing the current
-  /// full-expression.
+  /// Queue a cleanup to be pushed after finishing the current full-expression,
+  /// potentially with an active flag.
   template 
   void pushCleanupAfterFullExpr(CleanupKind Kind, As... A) {
 if (!isInConditionalBranch())
-  return pushCleanupAfterFullExprImpl(Kind, Address::invalid(), A...);
+  return pushCleanupAfterFullExprWithActiveFlag(Kind, Address::invalid(),
+   A...);
 
 Address ActiveFlag = createCleanupActiveFlag();
 assert(!DominatingValue::needsSaving(ActiveFlag) &&
@@ -687,12 +688,12 @@
 SavedTuple Saved{saveValueInCond(A)...};
 
 typedef EHScopeStack::ConditionalCleanup CleanupType;
-pushCleanupAfterFullExprImpl(Kind, ActiveFlag, Saved);
+pushCleanupAfterFullExprWithActiveFlag(Kind, ActiveFlag, Saved);
   }
 
   template 
-  void pushCleanupAfterFullExprImpl(CleanupKind Kind, Address ActiveFlag,
-As... A) {
+  void pushCleanupAfterFullExprWithActiveFlag(CleanupKind Kind,
+  Address ActiveFlag, As... A) {
 LifetimeExtendedCleanupHeader Header = {sizeof(T), Kind,
 ActiveFlag.isValid()};
 
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2095,21 +2095,47 @@
   EHStack.pushCleanup(Kind, SPMem);
 }
 
-void CodeGenFunction::pushLifetimeExtendedDestroy(
-CleanupKind cleanupKind, Address addr, QualType type,
-Destroyer *destroyer, bool useEHCleanupForArray) {
-  // Push an EH-only cleanup for the object now.
-  // FIXME: When popping normal cleanups, we need to keep this EH cleanup
-  // around in case a temporary's destructor throws an exception.
-  if (cleanupKind & EHCleanup)
-EHStack.pushCleanup(
-static_cast(cleanupKind & ~NormalCleanup), addr, type,
+void CodeGenFunction::pushLifetimeExtendedDestroy(CleanupKind cleanupKind,
+  Address addr, QualType type,
+  Destroy

[PATCH] D86855: Convert __m64 intrinsics to unconditionally use SSE2 instead of MMX instructions.

2020-08-30 Thread James Y Knight via Phabricator via cfe-commits
jyknight created this revision.
jyknight added reviewers: craig.topper, spatel, RKSimon.
Herald added subscribers: cfe-commits, danielkiss.
Herald added a project: clang.
jyknight requested review of this revision.

Preliminary patch, posted to go along with discussion on llvm-dev.

3DNow! intrinsics are not converted, as of yet.

Tests have not been updated to match new expected IR output. Currently failing:
 Clang :: CodeGen/attr-target-x86-mmx.c
 Clang :: CodeGen/mmx-builtins.c
 Clang :: CodeGen/mmx-shift-with-immediate.c
 Clang :: Headers/xmmintrin.c


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86855

Files:
  clang/lib/Headers/emmintrin.h
  clang/lib/Headers/mmintrin.h
  clang/lib/Headers/tmmintrin.h
  clang/lib/Headers/xmmintrin.h
  clang/test/Sema/x86-builtin-palignr.c

Index: clang/test/Sema/x86-builtin-palignr.c
===
--- clang/test/Sema/x86-builtin-palignr.c
+++ clang/test/Sema/x86-builtin-palignr.c
@@ -4,5 +4,5 @@
 #include 
 
 __m64 test1(__m64 a, __m64 b, int c) {
-   return _mm_alignr_pi8(a, b, c); // expected-error {{argument to '__builtin_ia32_palignr' must be a constant integer}}
+   return _mm_alignr_pi8(a, b, c); // expected-error {{argument to '__builtin_ia32_psrldqi128_byteshift' must be a constant integer}}
 }
Index: clang/lib/Headers/xmmintrin.h
===
--- clang/lib/Headers/xmmintrin.h
+++ clang/lib/Headers/xmmintrin.h
@@ -29,7 +29,12 @@
 
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sse"), __min_vector_width__(128)))
-#define __DEFAULT_FN_ATTRS_MMX __attribute__((__always_inline__, __nodebug__, __target__("mmx,sse"), __min_vector_width__(64)))
+#define __DEFAULT_FN_ATTRS_SSE2 __attribute__((__always_inline__, __nodebug__, __target__("sse2"), __min_vector_width__(64)))
+
+#define __trunc64(x) (__m64)__builtin_shufflevector((__v2di)(x), __extension__ (__v2di){}, 0)
+#define __zext128(x) (__m128i)__builtin_shufflevector((__v1di)(x), __extension__ (__v1di){}, 0, 1)
+#define __anyext128(x) (__m128i)__builtin_shufflevector((__v1di)(x), __extension__ (__v1di){}, 0, -1)
+#define __zeroupper64(x) (__m128i)__builtin_shufflevector((__v2di)(x), __extension__ (__v2di){}, 0, 2)
 
 /// Adds the 32-bit float values in the low-order bits of the operands.
 ///
@@ -1354,10 +1359,10 @@
 /// \param __a
 ///A 128-bit vector of [4 x float].
 /// \returns A 64-bit integer vector containing the converted values.
-static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
+static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2
 _mm_cvtps_pi32(__m128 __a)
 {
-  return (__m64)__builtin_ia32_cvtps2pi((__v4sf)__a);
+  return __trunc64(__builtin_ia32_cvtps2dq((__v4sf)__zeroupper64(__a)));
 }
 
 /// Converts two low-order float values in a 128-bit vector of
@@ -1370,7 +1375,7 @@
 /// \param __a
 ///A 128-bit vector of [4 x float].
 /// \returns A 64-bit integer vector containing the converted values.
-static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
+static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2
 _mm_cvt_ps2pi(__m128 __a)
 {
   return _mm_cvtps_pi32(__a);
@@ -1447,10 +1452,10 @@
 /// \param __a
 ///A 128-bit vector of [4 x float].
 /// \returns A 64-bit integer vector containing the converted values.
-static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
+static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2
 _mm_cvttps_pi32(__m128 __a)
 {
-  return (__m64)__builtin_ia32_cvttps2pi((__v4sf)__a);
+  return __trunc64(__builtin_ia32_cvttps2dq((__v4sf)__zeroupper64(__a)));
 }
 
 /// Converts two low-order float values in a 128-bit vector of [4 x
@@ -1464,7 +1469,7 @@
 /// \param __a
 ///A 128-bit vector of [4 x float].
 /// \returns A 64-bit integer vector containing the converted values.
-static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
+static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2
 _mm_cvtt_ps2pi(__m128 __a)
 {
   return _mm_cvttps_pi32(__a);
@@ -1559,10 +1564,13 @@
 /// \returns A 128-bit vector of [4 x float] whose lower 64 bits contain the
 ///converted value of the second operand. The upper 64 bits are copied from
 ///the upper 64 bits of the first operand.
-static __inline__ __m128 __DEFAULT_FN_ATTRS_MMX
+static __inline__ __m128 __DEFAULT_FN_ATTRS_SSE2
 _mm_cvtpi32_ps(__m128 __a, __m64 __b)
 {
-  return __builtin_ia32_cvtpi2ps((__v4sf)__a, (__v2si)__b);
+  return (__m128)__builtin_shufflevector(
+  (__v4sf)__a,
+  __builtin_convertvector((__v4si)__zext128(__b), __v4sf),
+  4, 5, 2, 3);
 }
 
 /// Converts two elements of a 64-bit vector of [2 x i32] into two
@@ -1582,7 +1590,7 @@
 /// \returns A 128-bit vector of [4 x float] whose lower 64 bits contain the
 ///converted value from the second operand. The upper 64 bits are copied
 ///from the upper 64 bits of the first operand.
-static __inline__ __m128 __DEFAULT_FN_ATTRS_MMX
+static __inline__ __m1

[PATCH] D86424: [clang] Do not consider the template arguments of bases to be bases themselves

2020-08-30 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 21.
nridge marked 4 inline comments as done.
nridge added a comment.
Herald added a subscriber: danielkiss.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86424

Files:
  clang/lib/Index/IndexTypeSourceInfo.cpp
  clang/test/Index/Core/index-source.cpp
  clang/unittests/Index/IndexTests.cpp


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -334,6 +334,20 @@
  WrittenAt(Position(3, 20);
 }
 
+TEST(IndexTest, RelationBaseOf) {
+  std::string Code = R"cpp(
+class A {};
+template  class B {};
+class C : B {};
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  // A should not be the base of anything.
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("A"), HasRole(SymbolRole::Reference),
+ Not(HasRole(SymbolRole::RelationBaseOf);
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/test/Index/Core/index-source.cpp
===
--- clang/test/Index/Core/index-source.cpp
+++ clang/test/Index/Core/index-source.cpp
@@ -560,3 +560,11 @@
 };
 
 }
+
+namespace clangd_issue_504 {
+  class A {};
+  template  class B {};
+  class C : B {};
+// CHECK: [[@LINE-1]]:15 | class/C++ | A | c:@N@clangd_issue_504@S@A | 
 | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | C | c:@N@clangd_issue_504@S@C
+}
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -8,6 +8,7 @@
 
 #include "IndexingContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
 using namespace index;
@@ -160,6 +161,26 @@
 return true;
   }
 
+  bool TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) 
{
+if (!WalkUpFromTemplateSpecializationTypeLoc(TL))
+  return false;
+if (!TraverseTemplateName(TL.getTypePtr()->getTemplateName()))
+  return false;
+
+// The relations we have to `Parent` do not apply to our template 
arguments,
+// so clear them while visiting the args.
+SmallVector SavedRelations = Relations;
+Relations.clear();
+auto ResetSavedRelations =
+llvm::make_scope_exit([&] { this->Relations = SavedRelations; });
+for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
+  if (!TraverseTemplateArgumentLoc(TL.getArgLoc(I)))
+return false;
+}
+
+return true;
+  }
+
   bool 
VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc 
TL) {
 auto *T = TL.getTypePtr();
 if (!T)


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -334,6 +334,20 @@
  WrittenAt(Position(3, 20);
 }
 
+TEST(IndexTest, RelationBaseOf) {
+  std::string Code = R"cpp(
+class A {};
+template  class B {};
+class C : B {};
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  // A should not be the base of anything.
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("A"), HasRole(SymbolRole::Reference),
+ Not(HasRole(SymbolRole::RelationBaseOf);
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/test/Index/Core/index-source.cpp
===
--- clang/test/Index/Core/index-source.cpp
+++ clang/test/Index/Core/index-source.cpp
@@ -560,3 +560,11 @@
 };
 
 }
+
+namespace clangd_issue_504 {
+  class A {};
+  template  class B {};
+  class C : B {};
+// CHECK: [[@LINE-1]]:15 | class/C++ | A | c:@N@clangd_issue_504@S@A |  | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | C | c:@N@clangd_issue_504@S@C
+}
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -8,6 +8,7 @@
 
 #include "IndexingContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
 using namespace index;
@@ -160,6 +161,26 @@
 return true;
   }
 
+  bool TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
+if (!WalkUpFromTemplateSpecializationTypeLoc(TL))
+  return false;
+if (!TraverseTemplateName(TL.getTypePtr()->getTemplateName()))
+  return false;
+
+// The relations w

[PATCH] D86424: [clang] Do not consider the template arguments of bases to be bases themselves

2020-08-30 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 22.
nridge added a comment.

format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86424

Files:
  clang/lib/Index/IndexTypeSourceInfo.cpp
  clang/test/Index/Core/index-source.cpp
  clang/unittests/Index/IndexTests.cpp


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -334,6 +334,20 @@
  WrittenAt(Position(3, 20);
 }
 
+TEST(IndexTest, RelationBaseOf) {
+  std::string Code = R"cpp(
+class A {};
+template  class B {};
+class C : B {};
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  // A should not be the base of anything.
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("A"), HasRole(SymbolRole::Reference),
+ Not(HasRole(SymbolRole::RelationBaseOf);
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/test/Index/Core/index-source.cpp
===
--- clang/test/Index/Core/index-source.cpp
+++ clang/test/Index/Core/index-source.cpp
@@ -560,3 +560,11 @@
 };
 
 }
+
+namespace clangd_issue_504 {
+class A {};
+template  class B {};
+class C : B {};
+// CHECK: [[@LINE-1]]:13 | class/C++ | A | c:@N@clangd_issue_504@S@A | 
 | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | C | c:@N@clangd_issue_504@S@C
+} // namespace clangd_issue_504
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -8,6 +8,7 @@
 
 #include "IndexingContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
 using namespace index;
@@ -160,6 +161,26 @@
 return true;
   }
 
+  bool TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) 
{
+if (!WalkUpFromTemplateSpecializationTypeLoc(TL))
+  return false;
+if (!TraverseTemplateName(TL.getTypePtr()->getTemplateName()))
+  return false;
+
+// The relations we have to `Parent` do not apply to our template 
arguments,
+// so clear them while visiting the args.
+SmallVector SavedRelations = Relations;
+Relations.clear();
+auto ResetSavedRelations =
+llvm::make_scope_exit([&] { this->Relations = SavedRelations; });
+for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
+  if (!TraverseTemplateArgumentLoc(TL.getArgLoc(I)))
+return false;
+}
+
+return true;
+  }
+
   bool 
VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc 
TL) {
 auto *T = TL.getTypePtr();
 if (!T)


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -334,6 +334,20 @@
  WrittenAt(Position(3, 20);
 }
 
+TEST(IndexTest, RelationBaseOf) {
+  std::string Code = R"cpp(
+class A {};
+template  class B {};
+class C : B {};
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  // A should not be the base of anything.
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("A"), HasRole(SymbolRole::Reference),
+ Not(HasRole(SymbolRole::RelationBaseOf);
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/test/Index/Core/index-source.cpp
===
--- clang/test/Index/Core/index-source.cpp
+++ clang/test/Index/Core/index-source.cpp
@@ -560,3 +560,11 @@
 };
 
 }
+
+namespace clangd_issue_504 {
+class A {};
+template  class B {};
+class C : B {};
+// CHECK: [[@LINE-1]]:13 | class/C++ | A | c:@N@clangd_issue_504@S@A |  | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | C | c:@N@clangd_issue_504@S@C
+} // namespace clangd_issue_504
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -8,6 +8,7 @@
 
 #include "IndexingContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
 using namespace index;
@@ -160,6 +161,26 @@
 return true;
   }
 
+  bool TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
+if (!WalkUpFromTemplateSpecializationTypeLoc(TL))
+  return false;
+if (!TraverseTemplateName(TL.getTypePtr()->getTemplateName()))
+  return false;
+
+// The relations we have to `Parent` do not apply to our template a

[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-08-30 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

FYI: PR45410, which this fixes, has been marked as a release blocker for 11.0.0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491

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


[PATCH] D86858: [OpenMP] Fix infinite loop in Sema::isOpenMPGlobalCapturedDecl()

2020-08-30 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp added a reviewer: ABataev.
Herald added subscribers: cfe-commits, danielkiss, guansong, yaxunl.
Herald added a project: clang.
nullptr.cpp requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Function Sema::isOpenMPGlobalCapturedDecl() has a parameter `unsigned Level`,
but use `Level >= 0` as the condition of `while`, thus cause an infinite loop.
Fix by changing the type of `Level` to `int`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86858

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2410,7 +2410,7 @@
  Regions[CaptureLevel] != OMPD_task;
 }
 
-bool Sema::isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
+bool Sema::isOpenMPGlobalCapturedDecl(ValueDecl *D, int Level,
   unsigned CaptureLevel) const {
   assert(LangOpts.OpenMP && "OpenMP is not allowed");
   // Return true if the current level is no longer enclosed in a target region.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10114,7 +10114,7 @@
   /// regions.
   /// \param Level Relative level of nested OpenMP construct for that
   /// the check is performed.
-  bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
+  bool isOpenMPGlobalCapturedDecl(ValueDecl *D, int Level,
   unsigned CaptureLevel) const;
 
   ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc,


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2410,7 +2410,7 @@
  Regions[CaptureLevel] != OMPD_task;
 }
 
-bool Sema::isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
+bool Sema::isOpenMPGlobalCapturedDecl(ValueDecl *D, int Level,
   unsigned CaptureLevel) const {
   assert(LangOpts.OpenMP && "OpenMP is not allowed");
   // Return true if the current level is no longer enclosed in a target region.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10114,7 +10114,7 @@
   /// regions.
   /// \param Level Relative level of nested OpenMP construct for that
   /// the check is performed.
-  bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
+  bool isOpenMPGlobalCapturedDecl(ValueDecl *D, int Level,
   unsigned CaptureLevel) const;
 
   ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86858: [OpenMP] Fix infinite loop in Sema::isOpenMPGlobalCapturedDecl()

2020-08-30 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Can you add the test that exposed this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86858

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


[PATCH] D86671: [clang-tidy] Add new case type to check variables with Hungarian notation

2020-08-30 Thread Douglas Chen via Phabricator via cfe-commits
dougpuob added a comment.

In D86671#2246570 , @njames93 wrote:

> As Hungarian notation enforces prefixes as well as casing styles it would be 
> wise to warn on cases where the style is Hungarian but a prefix has also been 
> set.
>
> Another issue is this current set up will let you define any decls style as 
> hungarian, this doesn't make sense for most decl types. 
> Potentially some validation should happen for that too,

Hi @njames93:
If decl types were not in the `HungarianNotationTable` table, current 
implementation will treat it as `CamelCase`(UpperCamel), because the prefix is 
empty.




Comment at: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h:127
   virtual llvm::Optional
-  GetDeclFailureInfo(const NamedDecl *Decl, const SourceManager &SM) const = 0;
+  GetDeclFailureInfo(const StringRef &Type, const NamedDecl *Decl,
+ const SourceManager &SM) const = 0;

njames93 wrote:
> I'm not a fan of changing the base class for this support. The Type paramater 
> can be inferred using the Decl. 
> You can `dyn_cast` the Decl to a `ValueDecl` and then get its type from that.
Agree with you. This change is possible to make it without changing the 
interface of function. Improve it in next patch. Thank you.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:73
 
+- Added: Support variables could be checked with Hungarian Notation which the
+  prefix encodes the actual data type of the variable.

Eugene.Zelenko wrote:
> dougpuob wrote:
> > Eugene.Zelenko wrote:
> > > See examples for entry format below.
> > Make it like the following ?
> > 
> > ```
> > Changes in existing checks
> > ^^
> > 
> > - Improved :doc:`readability-identifier-naming
> >   ` check.
> > 
> >   Added an option `GetConfigPerFile` to support including files which use
> >   different naming styles.
> > 
> > - Improved :doc:`readability-identifier-naming
> >   
> > ` 
> > check.  
> > 
> >   Support variables could be checked with Hungarian Notation which the 
> > prefix
> >   encodes the actual data type of the variable.
> > ```
> Yes, but link must be `clang-tidy/checks/readability-identifier-naming`, 
> because it refer to documentation file, not regression test.
 OK~ Fix it in the next patch. Thank you.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D86671

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


[PATCH] D86855: Convert __m64 intrinsics to unconditionally use SSE2 instead of MMX instructions.

2020-08-30 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Headers/mmintrin.h:367
 {
-return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
+return (__m64)(((__v8qi)__m1) + ((__v8qi)__m2));
 }

I think you we should use __v8qu to match what we do in emmintrin.h. We don't 
currently set nsw on signed vector arithmetic, but we should be careful in case 
that changes in the future.



Comment at: clang/lib/Headers/mmintrin.h:1097
 {
-return __builtin_ia32_pand((__v1di)__m1, (__v1di)__m2);
+return (__m64)(((__v1di)__m1) & ((__v1di)__m2));
 }

I think we probably want to use a v2su or v2si here. Using v1di scalarizes and 
splits on 32-bit targets. On 64-bit targets it emits GPR code.



Comment at: clang/lib/Headers/mmintrin.h:1242
 {
-return (__m64)__builtin_ia32_pcmpgtb((__v8qi)__m1, (__v8qi)__m2);
+return (__m64)((__v8qi)__m1 > (__v8qi)__m2);
 }

Need to use __v8qs here to force "signed char" elements. __v8qi uses "char" 
which has platform dependent signedness or can be changed with a command line.



Comment at: clang/lib/Headers/mmintrin.h:1264
 {
-return (__m64)__builtin_ia32_pcmpgtw((__v4hi)__m1, (__v4hi)__m2);
+return (__m64)((__v4hi)__m1 > (__v4hi)__m2);
 }

Same here



Comment at: clang/lib/Headers/mmintrin.h:1394
 {
-return _mm_set_pi32(__i, __i);
+return __extension__ (__m64)(__v2si){__i, __i};
 }

Is this needed?



Comment at: clang/lib/Headers/mmintrin.h:1452
 {
-return _mm_set_pi32(__i1, __i0);
+return __extension__ (__m64)(__v2si){__i1, __i0};
 }

I don't think this change is needed. And I think the operands are in the wrong 
order.



Comment at: clang/lib/Headers/tmmintrin.h:17
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("ssse3"), __min_vector_width__(64)))
-#define __DEFAULT_FN_ATTRS_MMX __attribute__((__always_inline__, __nodebug__, 
__target__("mmx,ssse3"), __min_vector_width__(64)))
+#define __trunc64(x) (__m64)__builtin_shufflevector((__v2di)(x), __extension__ 
(__v2di){}, 0)
+#define __anyext128(x) (__m128i)__builtin_shufflevector((__v1di)(x), 
__extension__ (__v1di){}, 0, -1)

I'm worried that using v1di with the shuffles will lead to scalarization in the 
type legalizer. Should we use v2si instead?



Comment at: clang/lib/Headers/xmmintrin.h:2316
 {
-  return __builtin_ia32_pmovmskb((__v8qi)__a);
+  return __builtin_ia32_pmovmskb128((__v16qi)__anyext128(__a));
 }

This doesn't guarantee zeroes in bits 15:8 does it?



Comment at: clang/lib/Headers/xmmintrin.h:2404
+  __m128i __n128  = __zext128(__n);
+  if (((__SIZE_TYPE__)__p & 0xfff) > 4096-15 && ((__SIZE_TYPE__)__p & 0xfff) < 
4096-8) {
+__p -= 8;

Does this work with large pages?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86855

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


[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-08-30 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I'd still like @rsmith to sign off here as code owner.




Comment at: clang/include/clang/Basic/IdentifierTable.h:231
 return ObjCOrBuiltinID == tok::NUM_OBJC_KEYWORDS;
   }
 

Do we need to support reverting builtins anymore?



Comment at: clang/test/CodeGen/callback_pthread_create.c:3
+// RUN: false
+// XFAIL: *
+

I guess the problem with pthread_create is that the types are not really 
reasonable to synthesize.  I wonder if we can use an approach more like what we 
do with C++, where we don't magically synthesize a declaration but where we do 
recognize that a particular declaration is compatible with the builtin 
signature.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491

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


[PATCH] D86854: [CodeGen] Make sure the EH cleanup for block captures is conditional when the block literal is in a conditional context

2020-08-30 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM modulo the minor fix




Comment at: clang/lib/CodeGen/CGDecl.cpp:2107
+// FIXME: When popping normal cleanups, we need to keep this EH cleanup
+// around in case a temporary's destructor throws an exception.
+if (cleanupKind & EHCleanup)

Oh, yuck, that's unfortunate.



Comment at: clang/lib/CodeGen/CGDecl.cpp:2117
+
+  // Otherwise, we should only destroy the object if its been initialized.
+  // Re-use the active flag and saved address across both the EH and end of

"it's"


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

https://reviews.llvm.org/D86854

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


[PATCH] D86858: [OpenMP] Fix infinite loop in Sema::isOpenMPGlobalCapturedDecl()

2020-08-30 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 288894.
nullptr.cpp added a comment.

Fix by changing the loop condition to `Level > 0`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86858

Files:
  clang/lib/Sema/SemaOpenMP.cpp


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2430,7 +2430,7 @@
 DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(D, Level);
 if (DVar.CKind != OMPC_shared)
   return true;
-  } while (Level >= 0);
+  } while (Level > 0);
 }
   }
   return true;


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2430,7 +2430,7 @@
 DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(D, Level);
 if (DVar.CKind != OMPC_shared)
   return true;
-  } while (Level >= 0);
+  } while (Level > 0);
 }
   }
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86858: [OpenMP] Fix infinite loop in Sema::isOpenMPGlobalCapturedDecl()

2020-08-30 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

In D86858#2246925 , @jdoerfert wrote:

> Can you add the test that exposed this?

Sorry, this was discovered by a static analyzer checker.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86858

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