[PATCH] D49114: [clang-tidy] Add a check for "magic numbers"

2018-07-13 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- updated this revision to Diff 155549.
0x8000- added a comment.

Accept magic values arbitrarily deep in a constant initialization


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/MagicNumbersCheck.cpp
  clang-tidy/readability/MagicNumbersCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-magic-numbers.rst
  test/clang-tidy/readability-magic-numbers.cpp

Index: test/clang-tidy/readability-magic-numbers.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-magic-numbers.cpp
@@ -0,0 +1,151 @@
+// RUN: %check_clang_tidy %s readability-magic-numbers %t
+
+template 
+struct ValueBucket {
+  T value[V];
+};
+
+int BadGlobalInt = 5;
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: magic number integer literal 5 [readability-magic-numbers]
+
+int IntSquarer(int param) {
+  return param * param;
+}
+
+void BuggyFunction() {
+  int BadLocalInt = 6;
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: magic number integer literal 6 [readability-magic-numbers]
+
+  (void)IntSquarer(7);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: magic number integer literal 7 [readability-magic-numbers]
+
+  int LocalArray[8];
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: magic number integer literal 8 [readability-magic-numbers]
+
+  for (int ii = 0; ii < 8; ++ii)
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: magic number integer literal 8 [readability-magic-numbers]
+  {
+LocalArray[ii] = 3 * ii;
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: magic number integer literal 3 [readability-magic-numbers]
+  }
+
+  ValueBucket Bucket;
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: magic number integer literal 4 [readability-magic-numbers]
+}
+
+class TwoIntContainer {
+public:
+  TwoIntContainer(int val) : anotherMember(val * val), yetAnotherMember(6), anotherConstant(val + val) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:73: warning: magic number integer literal 6 [readability-magic-numbers]
+
+  int getValue() const;
+
+private:
+  int oneMember = 9;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: magic number integer literal 9 [readability-magic-numbers]
+
+  int anotherMember;
+
+  int yetAnotherMember;
+
+  const int oneConstant = 2;
+
+  const int anotherConstant;
+};
+
+int ValueArray[] = {3, 5};
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: magic number integer literal 3 [readability-magic-numbers]
+// CHECK-MESSAGES: :[[@LINE-2]]:24: warning: magic number integer literal 5 [readability-magic-numbers]
+
+float FloatPiVariable = 3.1415926535f;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: magic number float literal 3.141592741 [readability-magic-numbers]
+double DoublePiVariable = 6.283185307;
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: magic number float literal 6.283185307 [readability-magic-numbers]
+
+int getAnswer() {
+  if (ValueArray[0] < ValueArray[1])
+return ValueArray[1];
+
+  return -3; // FILENOTFOUND
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: magic number integer literal 3 [readability-magic-numbers]
+}
+
+/*
+ * Clean code
+ */
+
+#define INT_MACRO 5
+
+const int GoodGlobalIntContant = 42;
+
+constexpr int AlsoGoodGlobalIntContant = 42;
+
+void SolidFunction() {
+  const int GoodLocalIntContant = 43;
+
+  (void)IntSquarer(GoodLocalIntContant);
+
+  int LocalArray[INT_MACRO];
+
+  ValueBucket Bucket;
+}
+
+const int ConstValueArray[] = {7, 9};
+
+const int ConstValueArray2D[2][2] = {{7, 9}, {13, 15}};
+
+/*
+ * no warnings for grandfathered values
+ */
+int GrandfatheredValues[] = {0, 1, 2, 10, 100, -1, -10, -100};
+
+/*
+ * no warnings for enums
+ */
+enum Smorgasbord {
+  STARTER,
+  ALPHA = 3,
+  BETA = 1 << 5,
+};
+
+const float FloatPiConstant = 3.1415926535f;
+const double DoublePiConstant = 6.283185307;
+
+double DoubleZeroIsAccepted = 0.0;
+float FloatZeroIsAccepted = 0.0f;
+
+namespace geometry {
+
+template 
+struct Point {
+  T x;
+  T y;
+
+  explicit Point(T xval, T yval) noexcept : x{xval}, y{yval} {
+  }
+};
+
+template 
+struct Dimension {
+  T x;
+  T y;
+
+  explicit Dimension(T xval, T yval) noexcept : x{xval}, y{yval} {
+  }
+};
+
+template 
+struct Rectangle {
+  Point origin;
+  Dimension size;
+  T rotation; // angle of rotation around origin
+
+  Rectangle(Point origin_, Dimension size_, T rotation_ = 0) noexcept : origin{origin_}, size{size_}, rotation{rotation_} {
+  }
+
+  bool contains(Point point) const;
+};
+
+} // namespace geometry
+
+const geometry::Rectangle mandelbrotCanvas{geometry::Point{-2.5, -1}, geometry::Dimension{3.5, 2}};
Index: docs/clang-tidy/checks/readability-magic-numbers.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-magic-numbers.rst
@@ -0,0 +1,51 @@
+.. title:: clang-tidy - readability-magic-numbers
+

[libcxx] r337087 - Mark __equal_to 's operations as constexpr.

2018-07-13 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Fri Jul 13 21:15:19 2018
New Revision: 337087

URL: http://llvm.org/viewvc/llvm-project?rev=337087=rev
Log:
Mark __equal_to 's operations as constexpr.

Modified:
libcxx/trunk/include/algorithm

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=337087=337086=337087=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Fri Jul 13 21:15:19 2018
@@ -671,10 +671,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 template 
 struct __equal_to
 {
-_LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) 
const {return __x == __y;}
-_LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) 
const {return __x == __y;}
-_LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T1& __y) 
const {return __x == __y;}
-_LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T2& __y) 
const {return __x == __y;}
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool 
operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool 
operator()(const _T1& __x, const _T2& __y) const {return __x == __y;}
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool 
operator()(const _T2& __x, const _T1& __y) const {return __x == __y;}
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool 
operator()(const _T2& __x, const _T2& __y) const {return __x == __y;}
 };
 
 template 


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


[libcxx] r337085 - Mark one more __wrap_iter operation as constexpr.

2018-07-13 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Fri Jul 13 20:06:11 2018
New Revision: 337085

URL: http://llvm.org/viewvc/llvm-project?rev=337085=rev
Log:
Mark one more __wrap_iter operation as constexpr.


Modified:
libcxx/trunk/include/iterator

Modified: libcxx/trunk/include/iterator
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=337085=337084=337085=diff
==
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Fri Jul 13 20:06:11 2018
@@ -1374,7 +1374,8 @@ public:
 }
 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  
operator++(int) _NOEXCEPT_DEBUG
 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
-_LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT_DEBUG
+
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& 
operator--() _NOEXCEPT_DEBUG
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),


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


[PATCH] D49227: Override a bit fields layout from an external source

2018-07-13 Thread Aleksandr Urakov via Phabricator via cfe-commits
aleksandr.urakov added a comment.

Thank you!


Repository:
  rL LLVM

https://reviews.llvm.org/D49227



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


[PATCH] D48287: [HIP] Support -fcuda-flush-denormals-to-zero for amdgcn

2018-07-13 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D48287#1138262, @tra wrote:

> Using OpenCL's flag for the purpose adds a *third* way we handle denormals 
> flushing in clang. Now it would be HIP (which is CUDA-like) using OpenCL's 
> flag for denormals instead of CUDA's one.
>  You could change AMDGPUTargetInfo::adjustTargetOptions() to use 
> CGOpts.getLangOpts().CUDADeviceFlushDenormalsToZero instead. That would at 
> least make HIP and CUDA do the same thing.
>
> I think it would work better if we could coalesce 
> CUDADeviceFlushDenormalsToZero and CodeGenOpts.FlushDenorm and, maybe move 
> the flag to LangOpts , so we could use LangOpts.CUDAIsDevice.


Sorry for the delay.

CGOpts does not have member function getLangOpts(). It seems whereever we need 
to refer to LangOpts.CUDADeviceFlushDenormalsToZero, we can use 
Opts.FlushDenorm, but not true vice versa. Therefore if we want a unified 
option, Opts.FlushDenorm is a better choice.


https://reviews.llvm.org/D48287



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


r337082 - Revert "[ThinLTO] Ensure we always select the same function copy to import"

2018-07-13 Thread Teresa Johnson via cfe-commits
Author: tejohnson
Date: Fri Jul 13 18:50:14 2018
New Revision: 337082

URL: http://llvm.org/viewvc/llvm-project?rev=337082=rev
Log:
Revert "[ThinLTO] Ensure we always select the same function copy to import"

This reverts commit r337051.

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=337082=337081=337082=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Fri Jul 13 18:50:14 2018
@@ -1127,8 +1127,9 @@ static void runThinLTOBackend(ModuleSumm
 // e.g. record required linkage changes.
 if (Summary->modulePath() == M->getModuleIdentifier())
   continue;
-// Add an entry to provoke importing by thinBackend.
-ImportList[Summary->modulePath()].insert(GUID);
+// Doesn't matter what value we plug in to the map, just needs an entry
+// to provoke importing by thinBackend.
+ImportList[Summary->modulePath()][GUID] = 1;
   }
 
   std::vector> OwnedImports;


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


[PATCH] D49330: [compiler-rt] Include -lm when using compiler-rt, due to dependencies in some __div methods.

2018-07-13 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht created this revision.
rupprecht added a reviewer: saugustine.
Herald added subscribers: cfe-commits, aheejin, sbc100, dberris, srhines.

Some methods in compiler-rt builtins have dependencies on libm. Therefore 
building with -rtlib=compiler-rt is completely broken if those symbols are used 
and users don't include -lm themselves.

Fixes PR32279 and PR28652.


Repository:
  rC Clang

https://reviews.llvm.org/D49330

Files:
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/linux-ld.c
  test/Driver/wasm-toolchain.c
  test/Driver/wasm-toolchain.cpp


Index: test/Driver/wasm-toolchain.cpp
===
--- test/Driver/wasm-toolchain.cpp
+++ test/Driver/wasm-toolchain.cpp
@@ -14,10 +14,10 @@
 
 // RUN: %clangxx -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" 
"-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" 
"-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-lm" "-o" "a.out"
 
 // A basic C++ link command-line with optimization.
 
 // RUN: %clangxx -### -O2 -no-canonical-prefixes -target 
wasm32-unknown-unknown --sysroot=/foo %s --stdlib=c++ 2>&1 | FileCheck 
-check-prefix=LINK_OPT %s
 // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" 
"-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" 
"-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-lm" "-o" 
"a.out"
Index: test/Driver/wasm-toolchain.c
===
--- test/Driver/wasm-toolchain.c
+++ test/Driver/wasm-toolchain.c
@@ -14,10 +14,10 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-lm" "-o" "a.out"
 
 // A basic C link command-line with optimization.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s
 // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" 
"-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" 
"-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-lm" "-o" "a.out"
Index: test/Driver/linux-ld.c
===
--- test/Driver/linux-ld.c
+++ test/Driver/linux-ld.c
@@ -67,8 +67,10 @@
 // CHECK-LD-RT: "-L[[SYSROOT]]/lib"
 // CHECK-LD-RT: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD-RT: libclang_rt.builtins-x86_64.a"
+// CHECK-LD-RT: "-lm"
 // CHECK-LD-RT: "-lc"
 // CHECK-LD-RT: libclang_rt.builtins-x86_64.a"
+// CHECK-LD-RT: "-lm"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: --target=i686-unknown-linux \
@@ -88,8 +90,10 @@
 // CHECK-LD-RT-I686: "-L[[SYSROOT]]/lib"
 // CHECK-LD-RT-I686: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD-RT-I686: libclang_rt.builtins-i386.a"
+// CHECK-LD-RT-I686: "-lm"
 // CHECK-LD-RT-I686: "-lc"
 // CHECK-LD-RT-I686: libclang_rt.builtins-i386.a"
+// CHECK-LD-RT-I686: "-lm"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: --target=arm-linux-androideabi \
@@ -103,8 +107,10 @@
 // CHECK-LD-RT-ANDROID: "-m" "armelf_linux_eabi"
 // CHECK-LD-RT-ANDROID: "-dynamic-linker"
 // CHECK-LD-RT-ANDROID: libclang_rt.builtins-arm-android.a"
+// CHECK-LD-RT-ANDROID: "-lm"
 // CHECK-LD-RT-ANDROID: "-lc"
 // CHECK-LD-RT-ANDROID: libclang_rt.builtins-arm-android.a"
+// CHECK-LD-RT-ANDROID: "-lm"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: --target=x86_64-unknown-linux -rtlib=platform \
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -1162,6 +1162,8 @@
   switch (RLT) {
   case ToolChain::RLT_CompilerRT:
 CmdArgs.push_back(TC.getCompilerRTArgString(Args, "builtins"));
+// Some methods such as __divdc3, __divsc3, and __divxc3 rely on libm
+CmdArgs.push_back("-lm");
 break;
   case ToolChain::RLT_Libgcc:
 // Make sure libgcc is not used under 

[clang-tools-extra] r337069 - [Documentation] Add missing description for bugprone-exception-escape in Release Notes.

2018-07-13 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Fri Jul 13 15:53:05 2018
New Revision: 337069

URL: http://llvm.org/viewvc/llvm-project?rev=337069=rev
Log:
[Documentation] Add missing description for bugprone-exception-escape in 
Release Notes.

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

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=337069=337068=337069=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Fri Jul 13 15:53:05 2018
@@ -82,6 +82,9 @@ Improvements to clang-tidy
 - New :doc:`bugprone-exception-escape
   ` check
 
+  Finds functions which may throw an exception directly or indirectly, but they
+  should not.
+
 - New :doc:`bugprone-parent-virtual-call
   ` check.
 


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


[PATCH] D48661: [Fixed Point Arithmetic] Fixed Point Constant

2018-07-13 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

@ebevhan Any followup on the patch/my previous comments?


Repository:
  rC Clang

https://reviews.llvm.org/D48661



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


[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-07-13 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

@erichkeane I created a patch at https://reviews.llvm.org/D49327 with the fix 
for this and added you as a reviewer.


Repository:
  rC Clang

https://reviews.llvm.org/D46915



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


[PATCH] D49327: [Fixed Point Arithmetic] Fix for bug where integer literals could be treated as fixed point literals

2018-07-13 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: erichkeane, ebevhan, rjmccall, rsmith, 
jakehehrlich, mcgrathr, phosek.
leonardchan added a project: clang.

This addresses a bug brought up in https://bugs.llvm.org/show_bug.cgi?id=38161 
where integer literals could be treated as fixed point types and throw errors 
related to fixed point types when the 'k' or 'r' suffix used. The fix also 
addresses the second issue brought up with the assertion by not treating 
integers as fixed point types in the first place.

Integers that have suffixes 'k' and 'r' now throw the error 'cannot use k/r in 
integer literal'.

A few more tests were also added to ensure that fixed point types, and any 
errors/warnings related to them, are limited to C for now.

Prior discussion also at https://reviews.llvm.org/D46915.


Repository:
  rC Clang

https://reviews.llvm.org/D49327

Files:
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Frontend/fixed_point_errors.c
  clang/test/Frontend/fixed_point_errors.cpp
  clang/test/Frontend/fixed_point_not_enabled.c

Index: clang/test/Frontend/fixed_point_not_enabled.c
===
--- clang/test/Frontend/fixed_point_not_enabled.c
+++ clang/test/Frontend/fixed_point_not_enabled.c
@@ -13,3 +13,9 @@
 _Accum accum; // expected-error{{compile with '-ffixed-point' to enable fixed point types}}
   // expected-warning@-1{{type specifier missing, defaults to 'int'}}
 long _Accum long_accum;   // expected-error{{compile with '-ffixed-point' to enable fixed point types}}
+
+// Cannot use fixed point suffixes
+int accum_int = 10k; // expected-error{{invalid suffix 'k' on integer constant}}
+int fract_int = 10r; // expected-error{{invalid suffix 'r' on integer constant}}
+float accum_flt = 10.0k; // expected-error{{invalid suffix 'k' on floating constant}}
+float fract_flt = 10.0r; // expected-error{{invalid suffix 'r' on floating constant}}
Index: clang/test/Frontend/fixed_point_errors.cpp
===
--- clang/test/Frontend/fixed_point_errors.cpp
+++ clang/test/Frontend/fixed_point_errors.cpp
@@ -7,3 +7,8 @@
 _Fract fract;   // expected-error{{unknown type name '_Fract'}}
 _Sat _Accum sat_accum;  // expected-error{{unknown type name '_Sat'}}
 // expected-error@-1{{expected ';' after top level declarator}}
+
+int accum_int = 10k; // expected-error{{invalid suffix 'k' on integer constant}}
+int fract_int = 10r; // expected-error{{invalid suffix 'r' on integer constant}}
+float accum_flt = 10.0k; // expected-error{{invalid suffix 'k' on floating constant}}
+float fract_flt = 10.0r; // expected-error{{invalid suffix 'r' on floating constant}}
Index: clang/test/Frontend/fixed_point_errors.c
===
--- clang/test/Frontend/fixed_point_errors.c
+++ clang/test/Frontend/fixed_point_errors.c
@@ -148,3 +148,87 @@
 _Accum dec_with_hex_exp2 = 0.1P10k;// expected-error{{invalid suffix 'P10k' on integer constant}}
 _Accum hex_with_dex_exp1 = 0x0.1e10k;  // expected-error{{hexadecimal floating constant requires an exponent}}
 _Accum hex_with_dex_exp2 = 0x0.1E10k;  // expected-error{{hexadecimal floating constant requires an exponent}}
+
+void CheckSuffixOnIntegerLiterals() {
+  _Accum short_acc_int;
+  _Accum acc_int;
+  _Accum long_acc_int;
+
+  _Accum u_short_acc_int;
+  _Accum u_acc_int;
+  _Accum u_long_acc_int;
+
+  _Fract short_fract_int;
+  _Fract fract_int;
+  _Fract long_fract_int;
+
+  _Fract u_short_fract_int;
+  _Fract u_fract_int;
+  _Fract u_long_fract_int;
+
+  // Decimal integer literals (non-zero)
+  short_acc_int = 10hk; // expected-error{{invalid suffix 'hk' on integer constant}}
+  acc_int = 10k;// expected-error{{invalid suffix 'k' on integer constant}}
+  long_acc_int = 10lk;  // expected-error{{invalid suffix 'lk' on integer constant}}
+
+  u_short_acc_int = 10uhk; // expected-error{{invalid suffix 'uhk' on integer constant}}
+  u_acc_int = 10uk;// expected-error{{invalid suffix 'uk' on integer constant}}
+  u_long_acc_int = 10ulk;  // expected-error{{invalid suffix 'ulk' on integer constant}}
+
+  short_fract_int = 10hr; // expected-error{{invalid suffix 'hr' on integer constant}}
+  fract_int = 10r;// expected-error{{invalid suffix 'r' on integer constant}}
+  long_fract_int = 10lr;  // expected-error{{invalid suffix 'lr' on integer constant}}
+
+  u_short_fract_int = 10uhr; // expected-error{{invalid suffix 'uhr' on integer constant}}
+  u_fract_int = 10ur;// expected-error{{invalid suffix 'ur' on integer constant}}
+  u_long_fract_int = 10ulr;  // expected-error{{invalid suffix 'ulr' on integer constant}}
+
+  // Decimal integer literals (0)
+  short_acc_int = 0hk; // expected-error{{invalid suffix 'hk' on 

[PATCH] D47196: [Time-report ](2): Recursive timers in Clang

2018-07-13 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Adding startFrontendTimer/stopFrontendTimer helps a little, but it's still 
difficult to match a given startFrontendTimer to the corresponding 
stopFrontendTimer because they're in completely different functions in some 
cases.  Do they really need to be scattered like that?  If they do, please add 
comments so someone reading the code can match them up.

Does getFrontendFunctionTimeCtx need to be a template, given it's always 
instantiated with `const FunctionDecl *`?




Comment at: include/clang/Frontend/Utils.h:338
+  }
+  if (isFirstValid(Result.first) && Result.second > 0.1) {
+FrontendTimes.push_back(Result);

Why 0.1? Should it be configurable?



Comment at: include/clang/Frontend/Utils.h:385
+  range.first++;
+}
+FinalTimes.push_back({E, dist});

This is merging together the times for functions with the same name? Why is 
that necessary?

This function could use a few comments describing what it's doing.



Comment at: include/clang/Frontend/Utils.h:462
+if (Ctx && Ctx->IsValid) {
+  //  Ctx->stopFrontendTimer(true, {T(), -1.0});
+  Ctx->stopFrontendTimer();

Commented-out code?


https://reviews.llvm.org/D47196



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


r337051 - [ThinLTO] Ensure we always select the same function copy to import

2018-07-13 Thread Teresa Johnson via cfe-commits
Author: tejohnson
Date: Fri Jul 13 14:35:58 2018
New Revision: 337051

URL: http://llvm.org/viewvc/llvm-project?rev=337051=rev
Log:
[ThinLTO] Ensure we always select the same function copy to import

Clang change to reflect the FunctionsToImportTy type change
in the llvm changes for D48670.

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=337051=337050=337051=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Fri Jul 13 14:35:58 2018
@@ -1127,9 +1127,8 @@ static void runThinLTOBackend(ModuleSumm
 // e.g. record required linkage changes.
 if (Summary->modulePath() == M->getModuleIdentifier())
   continue;
-// Doesn't matter what value we plug in to the map, just needs an entry
-// to provoke importing by thinBackend.
-ImportList[Summary->modulePath()][GUID] = 1;
+// Add an entry to provoke importing by thinBackend.
+ImportList[Summary->modulePath()].insert(GUID);
   }
 
   std::vector> OwnedImports;


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


[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-13 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap accepted this revision.
alexshap added a comment.
This revision is now accepted and ready to land.

to me LG


Repository:
  rC Clang

https://reviews.llvm.org/D48845



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


r337049 - [Hexagon] Fix hvx-length feature name in testcases

2018-07-13 Thread Krzysztof Parzyszek via cfe-commits
Author: kparzysz
Date: Fri Jul 13 14:32:33 2018
New Revision: 337049

URL: http://llvm.org/viewvc/llvm-project?rev=337049=rev
Log:
[Hexagon] Fix hvx-length feature name in testcases

Modified:
cfe/trunk/test/CodeGen/builtins-hvx128.c
cfe/trunk/test/CodeGen/builtins-hvx64.c

Modified: cfe/trunk/test/CodeGen/builtins-hvx128.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-hvx128.c?rev=337049=337048=337049=diff
==
--- cfe/trunk/test/CodeGen/builtins-hvx128.c (original)
+++ cfe/trunk/test/CodeGen/builtins-hvx128.c Fri Jul 13 14:32:33 2018
@@ -1,5 +1,5 @@
 // REQUIRES: hexagon-registered-target
-// RUN: %clang_cc1 -triple hexagon-unknown-elf -target-cpu hexagonv65 
-target-feature +hvxv65 -target-feature +hvx-length128 -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple hexagon-unknown-elf -target-cpu hexagonv65 
-target-feature +hvxv65 -target-feature +hvx-length128b -emit-llvm %s -o - | 
FileCheck %s
 
 void test() {
   int v128 __attribute__((__vector_size__(128)));

Modified: cfe/trunk/test/CodeGen/builtins-hvx64.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-hvx64.c?rev=337049=337048=337049=diff
==
--- cfe/trunk/test/CodeGen/builtins-hvx64.c (original)
+++ cfe/trunk/test/CodeGen/builtins-hvx64.c Fri Jul 13 14:32:33 2018
@@ -1,5 +1,5 @@
 // REQUIRES: hexagon-registered-target
-// RUN: %clang_cc1 -triple hexagon-unknown-elf -target-cpu hexagonv65 
-target-feature +hvxv65 -target-feature +hvx-length64 -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple hexagon-unknown-elf -target-cpu hexagonv65 
-target-feature +hvxv65 -target-feature +hvx-length64b -emit-llvm %s -o - | 
FileCheck %s
 
 void test() {
   int v64 __attribute__((__vector_size__(64)));


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


r337048 - Make BuiltinType constructor private, and befriend ASTContext.

2018-07-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Jul 13 14:29:31 2018
New Revision: 337048

URL: http://llvm.org/viewvc/llvm-project?rev=337048=rev
Log:
Make BuiltinType constructor private, and befriend ASTContext.

This reflects the fact that only ASTContext should ever create an
instance of BuiltinType, and matches what we do for all the other Type
subclasses.

Modified:
cfe/trunk/include/clang/AST/Type.h

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=337048=337047=337048=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Jul 13 14:29:31 2018
@@ -2253,7 +2253,9 @@ public:
 #include "clang/AST/BuiltinTypes.def"
   };
 
-public:
+private:
+  friend class ASTContext; // ASTContext creates these.
+
   BuiltinType(Kind K)
   : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
  /*InstantiationDependent=*/(K == Dependent),
@@ -2262,6 +2264,7 @@ public:
 BuiltinTypeBits.Kind = K;
   }
 
+public:
   Kind getKind() const { return static_cast(BuiltinTypeBits.Kind); }
   StringRef getName(const PrintingPolicy ) const;
 


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


[PATCH] D48562: [clangd] XPC transport layer

2018-07-13 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.
Herald added a subscriber: dexonsmith.



Comment at: xpc/test-client/ClangdXPCTestClient.cpp:51
+  dlHandle, "clangd_xpc_get_bundle_identifier");
+  xpc_connection_t conn =
+  xpc_connection_create(clangd_xpc_get_bundle_identifier(), NULL);

jkorous wrote:
> arphaman wrote:
> > We should probably use the main queue here too to ensure that we don't get 
> > bit by concurrent handler invocations. 
> As far as I understand it this is taken care of by calling dispatch_main().
> 
> Per man dispatch_main:
> "MAIN QUEUE
> [...]
>  Programs must call dispatch_main() at the end of main() in order to 
> process blocks submitted to the main queue."
> 
Not really. The documentation for the parameter states the following: 

The GCD queue to which the event handler block will be submitted. This 
parameter may be NULL, in which case the connection's target queue will be 
libdispatch's default target queue, defined as DISPATCH_TARGET_QUEUE_DEFAULT. 
The target queue may be changed later with a call to 
xpc_connection_set_target_queue(). 

So the handler blocks will be submitted to the concurrent queue 
(DISPATCH_TARGET_QUEUE_DEFAULT) which means that they might end up running 
concurrently.


https://reviews.llvm.org/D48562



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


[PATCH] D49227: Override a bit fields layout from an external source

2018-07-13 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC337047: Use external layout information to layout bit-fields 
for MS ABI. (authored by rsmith, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D49227

Files:
  lib/AST/RecordLayoutBuilder.cpp
  test/CodeGenCXX/Inputs/override-bit-field-layout.layout
  test/CodeGenCXX/override-bit-field-layout.cpp


Index: test/CodeGenCXX/Inputs/override-bit-field-layout.layout
===
--- test/CodeGenCXX/Inputs/override-bit-field-layout.layout
+++ test/CodeGenCXX/Inputs/override-bit-field-layout.layout
@@ -0,0 +1,16 @@
+
+*** Dumping AST Record Layout
+Type: struct S1
+
+Layout: 
+
+*** Dumping AST Record Layout
+Type: struct S2
+
+Layout: 
Index: test/CodeGenCXX/override-bit-field-layout.cpp
===
--- test/CodeGenCXX/override-bit-field-layout.cpp
+++ test/CodeGenCXX/override-bit-field-layout.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -w -fdump-record-layouts-simple 
-foverride-record-layout=%S/Inputs/override-bit-field-layout.layout %s | 
FileCheck %s
+
+// CHECK: Type: struct S1
+// CHECK:   FieldOffsets: [0, 11]
+struct S1 {
+  short a : 3;
+  short b : 5;
+};
+
+// CHECK: Type: struct S2
+// CHECK:   FieldOffsets: [64]
+struct S2 {
+  virtual ~S2() = default;
+  short a : 3;
+};
+
+void use_structs() {
+  S1 s1s[sizeof(S1)];
+  S2 s2s[sizeof(S2)];
+}
Index: lib/AST/RecordLayoutBuilder.cpp
===
--- lib/AST/RecordLayoutBuilder.cpp
+++ lib/AST/RecordLayoutBuilder.cpp
@@ -2677,7 +2677,7 @@
   // Check to see if this bitfield fits into an existing allocation.  Note:
   // MSVC refuses to pack bitfields of formal types with different sizes
   // into the same allocation.
-  if (!IsUnion && LastFieldIsNonZeroWidthBitfield &&
+  if (!UseExternalLayout && !IsUnion && LastFieldIsNonZeroWidthBitfield &&
   CurrentBitfieldSize == Info.Size && Width <= RemainingBitsInField) {
 placeFieldAtBitOffset(Context.toBits(Size) - RemainingBitsInField);
 RemainingBitsInField -= Width;
@@ -2689,6 +2689,14 @@
 placeFieldAtOffset(CharUnits::Zero());
 Size = std::max(Size, Info.Size);
 // TODO: Add a Sema warning that MS ignores bitfield alignment in unions.
+  } else if (UseExternalLayout) {
+auto FieldBitOffset = External.getExternalFieldOffset(FD);
+placeFieldAtBitOffset(FieldBitOffset);
+auto NewSize = Context.toCharUnitsFromBits(
+llvm::alignTo(FieldBitOffset + Width, Context.getCharWidth()));
+assert(NewSize >= Size && "bit field offset already allocated");
+Size = NewSize;
+Alignment = std::max(Alignment, Info.Alignment);
   } else {
 // Allocate a new block of memory and place the bitfield in it.
 CharUnits FieldOffset = Size.alignTo(Info.Alignment);


Index: test/CodeGenCXX/Inputs/override-bit-field-layout.layout
===
--- test/CodeGenCXX/Inputs/override-bit-field-layout.layout
+++ test/CodeGenCXX/Inputs/override-bit-field-layout.layout
@@ -0,0 +1,16 @@
+
+*** Dumping AST Record Layout
+Type: struct S1
+
+Layout: 
+
+*** Dumping AST Record Layout
+Type: struct S2
+
+Layout: 
Index: test/CodeGenCXX/override-bit-field-layout.cpp
===
--- test/CodeGenCXX/override-bit-field-layout.cpp
+++ test/CodeGenCXX/override-bit-field-layout.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -w -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-bit-field-layout.layout %s | FileCheck %s
+
+// CHECK: Type: struct S1
+// CHECK:   FieldOffsets: [0, 11]
+struct S1 {
+  short a : 3;
+  short b : 5;
+};
+
+// CHECK: Type: struct S2
+// CHECK:   FieldOffsets: [64]
+struct S2 {
+  virtual ~S2() = default;
+  short a : 3;
+};
+
+void use_structs() {
+  S1 s1s[sizeof(S1)];
+  S2 s2s[sizeof(S2)];
+}
Index: lib/AST/RecordLayoutBuilder.cpp
===
--- lib/AST/RecordLayoutBuilder.cpp
+++ lib/AST/RecordLayoutBuilder.cpp
@@ -2677,7 +2677,7 @@
   // Check to see if this bitfield fits into an existing allocation.  Note:
   // MSVC refuses to pack bitfields of formal types with different sizes
   // into the same allocation.
-  if (!IsUnion && LastFieldIsNonZeroWidthBitfield &&
+  if (!UseExternalLayout && !IsUnion && LastFieldIsNonZeroWidthBitfield &&
   CurrentBitfieldSize == Info.Size && Width <= RemainingBitsInField) {
 placeFieldAtBitOffset(Context.toBits(Size) - RemainingBitsInField);
 RemainingBitsInField -= Width;
@@ -2689,6 +2689,14 @@
 placeFieldAtOffset(CharUnits::Zero());
 Size = std::max(Size, Info.Size);
 // TODO: Add a Sema warning that MS ignores bitfield alignment in unions.
+  } else if (UseExternalLayout) {
+auto FieldBitOffset = External.getExternalFieldOffset(FD);
+

r337047 - Use external layout information to layout bit-fields for MS ABI.

2018-07-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Jul 13 14:07:42 2018
New Revision: 337047

URL: http://llvm.org/viewvc/llvm-project?rev=337047=rev
Log:
Use external layout information to layout bit-fields for MS ABI.

Patch by Aleksandr Urakov!

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

Added:
cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout
cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=337047=337046=337047=diff
==
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Fri Jul 13 14:07:42 2018
@@ -2677,7 +2677,7 @@ void MicrosoftRecordLayoutBuilder::layou
   // Check to see if this bitfield fits into an existing allocation.  Note:
   // MSVC refuses to pack bitfields of formal types with different sizes
   // into the same allocation.
-  if (!IsUnion && LastFieldIsNonZeroWidthBitfield &&
+  if (!UseExternalLayout && !IsUnion && LastFieldIsNonZeroWidthBitfield &&
   CurrentBitfieldSize == Info.Size && Width <= RemainingBitsInField) {
 placeFieldAtBitOffset(Context.toBits(Size) - RemainingBitsInField);
 RemainingBitsInField -= Width;
@@ -2689,6 +2689,14 @@ void MicrosoftRecordLayoutBuilder::layou
 placeFieldAtOffset(CharUnits::Zero());
 Size = std::max(Size, Info.Size);
 // TODO: Add a Sema warning that MS ignores bitfield alignment in unions.
+  } else if (UseExternalLayout) {
+auto FieldBitOffset = External.getExternalFieldOffset(FD);
+placeFieldAtBitOffset(FieldBitOffset);
+auto NewSize = Context.toCharUnitsFromBits(
+llvm::alignTo(FieldBitOffset + Width, Context.getCharWidth()));
+assert(NewSize >= Size && "bit field offset already allocated");
+Size = NewSize;
+Alignment = std::max(Alignment, Info.Alignment);
   } else {
 // Allocate a new block of memory and place the bitfield in it.
 CharUnits FieldOffset = Size.alignTo(Info.Alignment);

Added: cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout?rev=337047=auto
==
--- cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout (added)
+++ cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout Fri Jul 
13 14:07:42 2018
@@ -0,0 +1,16 @@
+
+*** Dumping AST Record Layout
+Type: struct S1
+
+Layout: 
+
+*** Dumping AST Record Layout
+Type: struct S2
+
+Layout: 

Added: cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp?rev=337047=auto
==
--- cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp Fri Jul 13 14:07:42 
2018
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -w -fdump-record-layouts-simple 
-foverride-record-layout=%S/Inputs/override-bit-field-layout.layout %s | 
FileCheck %s
+
+// CHECK: Type: struct S1
+// CHECK:   FieldOffsets: [0, 11]
+struct S1 {
+  short a : 3;
+  short b : 5;
+};
+
+// CHECK: Type: struct S2
+// CHECK:   FieldOffsets: [64]
+struct S2 {
+  virtual ~S2() = default;
+  short a : 3;
+};
+
+void use_structs() {
+  S1 s1s[sizeof(S1)];
+  S2 s2s[sizeof(S2)];
+}


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


[PATCH] D49227: Override a bit fields layout from an external source

2018-07-13 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337047: Use external layout information to layout bit-fields 
for MS ABI. (authored by rsmith, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49227?vs=155324=155490#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49227

Files:
  cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
  cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout
  cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp


Index: cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout
===
--- cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout
+++ cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout
@@ -0,0 +1,16 @@
+
+*** Dumping AST Record Layout
+Type: struct S1
+
+Layout: 
+
+*** Dumping AST Record Layout
+Type: struct S2
+
+Layout: 
Index: cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp
===
--- cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp
+++ cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -w -fdump-record-layouts-simple 
-foverride-record-layout=%S/Inputs/override-bit-field-layout.layout %s | 
FileCheck %s
+
+// CHECK: Type: struct S1
+// CHECK:   FieldOffsets: [0, 11]
+struct S1 {
+  short a : 3;
+  short b : 5;
+};
+
+// CHECK: Type: struct S2
+// CHECK:   FieldOffsets: [64]
+struct S2 {
+  virtual ~S2() = default;
+  short a : 3;
+};
+
+void use_structs() {
+  S1 s1s[sizeof(S1)];
+  S2 s2s[sizeof(S2)];
+}
Index: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
===
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
@@ -2677,7 +2677,7 @@
   // Check to see if this bitfield fits into an existing allocation.  Note:
   // MSVC refuses to pack bitfields of formal types with different sizes
   // into the same allocation.
-  if (!IsUnion && LastFieldIsNonZeroWidthBitfield &&
+  if (!UseExternalLayout && !IsUnion && LastFieldIsNonZeroWidthBitfield &&
   CurrentBitfieldSize == Info.Size && Width <= RemainingBitsInField) {
 placeFieldAtBitOffset(Context.toBits(Size) - RemainingBitsInField);
 RemainingBitsInField -= Width;
@@ -2689,6 +2689,14 @@
 placeFieldAtOffset(CharUnits::Zero());
 Size = std::max(Size, Info.Size);
 // TODO: Add a Sema warning that MS ignores bitfield alignment in unions.
+  } else if (UseExternalLayout) {
+auto FieldBitOffset = External.getExternalFieldOffset(FD);
+placeFieldAtBitOffset(FieldBitOffset);
+auto NewSize = Context.toCharUnitsFromBits(
+llvm::alignTo(FieldBitOffset + Width, Context.getCharWidth()));
+assert(NewSize >= Size && "bit field offset already allocated");
+Size = NewSize;
+Alignment = std::max(Alignment, Info.Alignment);
   } else {
 // Allocate a new block of memory and place the bitfield in it.
 CharUnits FieldOffset = Size.alignTo(Info.Alignment);


Index: cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout
===
--- cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout
+++ cfe/trunk/test/CodeGenCXX/Inputs/override-bit-field-layout.layout
@@ -0,0 +1,16 @@
+
+*** Dumping AST Record Layout
+Type: struct S1
+
+Layout: 
+
+*** Dumping AST Record Layout
+Type: struct S2
+
+Layout: 
Index: cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp
===
--- cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp
+++ cfe/trunk/test/CodeGenCXX/override-bit-field-layout.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -w -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-bit-field-layout.layout %s | FileCheck %s
+
+// CHECK: Type: struct S1
+// CHECK:   FieldOffsets: [0, 11]
+struct S1 {
+  short a : 3;
+  short b : 5;
+};
+
+// CHECK: Type: struct S2
+// CHECK:   FieldOffsets: [64]
+struct S2 {
+  virtual ~S2() = default;
+  short a : 3;
+};
+
+void use_structs() {
+  S1 s1s[sizeof(S1)];
+  S2 s2s[sizeof(S2)];
+}
Index: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
===
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
@@ -2677,7 +2677,7 @@
   // Check to see if this bitfield fits into an existing allocation.  Note:
   // MSVC refuses to pack bitfields of formal types with different sizes
   // into the same allocation.
-  if (!IsUnion && LastFieldIsNonZeroWidthBitfield &&
+  if (!UseExternalLayout && !IsUnion && LastFieldIsNonZeroWidthBitfield &&
   CurrentBitfieldSize == Info.Size && Width <= RemainingBitsInField) {
 placeFieldAtBitOffset(Context.toBits(Size) - RemainingBitsInField);

[PATCH] D49275: Thread safety: Run tests with both lock and capability attributes

2018-07-13 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Thanks for the review. Could you commit this as `Aaron Puchert 
https://reviews.llvm.org/D49275



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


[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-13 Thread JF Bastien via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337041: CodeGen: specify alignment + inbounds for automatic 
variable initialization (authored by jfb, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D49209

Files:
  cfe/trunk/lib/CodeGen/CGBuilder.h
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/test/CodeGen/init.c
  cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl

Index: cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl
===
--- cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl
+++ cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl
@@ -38,11 +38,11 @@
   // CHECK: %[[v0:.*]] = bitcast [6 x [6 x float]]* %A to i8*
   // CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %[[v0]], i8 0, i32 144, i1 false)
   // CHECK: %[[v1:.*]] = bitcast i8* %[[v0]] to [6 x [6 x float]]*
-  // CHECK: %[[v2:.*]] = getelementptr [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
-  // CHECK: %[[v3:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
-  // CHECK: store float 1.00e+00, float* %[[v3]]
-  // CHECK: %[[v4:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
-  // CHECK: store float 2.00e+00, float* %[[v4]]
+  // CHECK: %[[v2:.*]] = getelementptr inbounds [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
+  // CHECK: %[[v3:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
+  // CHECK: store float 1.00e+00, float* %[[v3]], align 4
+  // CHECK: %[[v4:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
+  // CHECK: store float 2.00e+00, float* %[[v4]], align 4
   float A[6][6]  = {1.0f, 2.0f};
 
   // CHECK: %[[v5:.*]] = bitcast %struct.StrucTy* %S to i8*
Index: cfe/trunk/test/CodeGen/init.c
===
--- cfe/trunk/test/CodeGen/init.c
+++ cfe/trunk/test/CodeGen/init.c
@@ -86,25 +86,25 @@
 char test8(int X) {
   char str[10] = "abc"; // tail should be memset.
   return str[X];
-// CHECK: @test8(
-// CHECK: call void @llvm.memset
-// CHECK: store i8 97
-// CHECK: store i8 98
-// CHECK: store i8 99
-// CHECK-NOT: getelementptr
-// CHECK: load
+  // CHECK-LABEL: @test8(
+  // CHECK: call void @llvm.memset
+  // CHECK: store i8 97, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 98, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 99, i8* %{{[0-9]*}}, align 1
+  // CHECK-NOT: getelementptr
+  // CHECK: load
 }
 
 void bar(void*);
 
 // PR279
-int test9(int X) {
+void test9(int X) {
   int Arr[100] = { X }; // Should use memset
   bar(Arr);
-// CHECK: @test9
-// CHECK: call void @llvm.memset
-// CHECK-NOT: store i32 0
-// CHECK: call void @bar
+  // CHECK-LABEL: @test9(
+  // CHECK: call void @llvm.memset
+  // CHECK-NOT: store i32 0
+  // CHECK: call void @bar
 }
 
 struct a {
@@ -115,11 +115,11 @@
   struct a a,b,c,d,e,f,g;
 };
 
-int test10(int X) {
+void test10(int X) {
   struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 };
   bar();
 
-  // CHECK: @test10
+  // CHECK-LABEL: @test10(
   // CHECK: call void @llvm.memset
   // CHECK-NOT: store i32 0
   // CHECK: call void @bar
@@ -132,11 +132,11 @@
 };
 void test11(struct test11S *P) {
   *P = (struct test11S) { .A = { [0 ... 3] = 4 } };
-  // CHECK: @test11
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
+  // CHECK-LABEL: @test11(
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
   // CHECK: ret void
 }
 
@@ -151,11 +151,11 @@
 void test13(int x) {
   struct X { int a; int b : 10; int c; };
   struct X y = {.c = x};
-  // CHECK: @test13
+  // CHECK-LABEL: @test13(
   // CHECK: and i16 {{.*}}, -1024
 }
 
-// CHECK-LABEL: @PR20473
+// CHECK-LABEL: @PR20473(
 void PR20473() {
   // CHECK: memcpy{{.*}}getelementptr inbounds ([2 x i8], [2 x i8]* @
   bar((char[2]) {""});
@@ -168,9 +168,9 @@
 struct S14 { int a[16]; };
 
 void test14(struct S14 *s14) {
-// CHECK-LABEL: @test14
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
-// CHECK-NOT: store
-// CHECK: ret void
+  // CHECK-LABEL: @test14(
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
+  // CHECK-NOT: store
+  // CHECK: ret void
   *s14 = (struct S14) { { [5 ... 11] = 17 } };
 }
Index: cfe/trunk/lib/CodeGen/CGDecl.cpp
===
--- cfe/trunk/lib/CodeGen/CGDecl.cpp
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp
@@ -888,15 +888,17 @@
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// 

r337041 - CodeGen: specify alignment + inbounds for automatic variable initialization

2018-07-13 Thread JF Bastien via cfe-commits
Author: jfb
Date: Fri Jul 13 13:33:23 2018
New Revision: 337041

URL: http://llvm.org/viewvc/llvm-project?rev=337041=rev
Log:
CodeGen: specify alignment + inbounds for automatic variable initialization

Summary: Automatic variable initialization was generating default-aligned 
stores (which are deprecated) instead of using the known alignment from the 
alloca. Further, they didn't specify inbounds.

Subscribers: dexonsmith, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGBuilder.h
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGen/init.c
cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl

Modified: cfe/trunk/lib/CodeGen/CGBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuilder.h?rev=337041=337040=337041=diff
==
--- cfe/trunk/lib/CodeGen/CGBuilder.h (original)
+++ cfe/trunk/lib/CodeGen/CGBuilder.h Fri Jul 13 13:33:23 2018
@@ -244,6 +244,21 @@ public:
Addr.getAlignment().alignmentAtOffset(Offset));
   }
 
+  using CGBuilderBaseTy::CreateConstInBoundsGEP2_32;
+  Address CreateConstInBoundsGEP2_32(Address Addr, unsigned Idx0,
+  unsigned Idx1, const llvm::DataLayout 
,
+  const llvm::Twine  = "") {
+auto *GEP = cast(CreateConstInBoundsGEP2_32(
+Addr.getElementType(), Addr.getPointer(), Idx0, Idx1, Name));
+llvm::APInt Offset(
+DL.getIndexSizeInBits(Addr.getType()->getPointerAddressSpace()), 0,
+/*IsSigned=*/true);
+if (!GEP->accumulateConstantOffset(DL, Offset))
+  llvm_unreachable("offset of GEP with constants is always computable");
+return Address(GEP, Addr.getAlignment().alignmentAtOffset(
+CharUnits::fromQuantity(Offset.getSExtValue(;
+  }
+
   llvm::Value *CreateConstInBoundsByteGEP(llvm::Value *Ptr, CharUnits Offset,
   const llvm::Twine  = "") {
 assert(Ptr->getType()->getPointerElementType() == TypeCache.Int8Ty);

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=337041=337040=337041=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Jul 13 13:33:23 2018
@@ -888,15 +888,17 @@ static bool canEmitInitWithFewStoresAfte
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// stores that would be required.
-static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value 
*Loc,
- bool isVolatile, CGBuilderTy 
) {
+static void emitStoresForInitAfterMemset(CodeGenModule ,
+ llvm::Constant *Init, Address Loc,
+ bool isVolatile,
+ CGBuilderTy ) {
   assert(!Init->isNullValue() && !isa(Init) &&
  "called emitStoresForInitAfterMemset for zero or undef value.");
 
   if (isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||
   isa(Init)) {
-Builder.CreateDefaultAlignedStore(Init, Loc, isVolatile);
+Builder.CreateStore(Init, Loc, isVolatile);
 return;
   }
 
@@ -908,7 +910,8 @@ static void emitStoresForInitAfterMemset
   // If necessary, get a pointer to the element and emit it.
   if (!Elt->isNullValue() && !isa(Elt))
 emitStoresForInitAfterMemset(
-Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
+CGM, Elt,
+Builder.CreateConstInBoundsGEP2_32(Loc, 0, i, CGM.getDataLayout()),
 isVolatile, Builder);
 }
 return;
@@ -923,7 +926,8 @@ static void emitStoresForInitAfterMemset
 // If necessary, get a pointer to the element and emit it.
 if (!Elt->isNullValue() && !isa(Elt))
   emitStoresForInitAfterMemset(
-  Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
+  CGM, Elt,
+  Builder.CreateConstInBoundsGEP2_32(Loc, 0, i, CGM.getDataLayout()),
   isVolatile, Builder);
   }
 }
@@ -1411,8 +1415,7 @@ void CodeGenFunction::EmitAutoVarInit(co
 if (!constant->isNullValue() && !isa(constant)) {
   Loc = Builder.CreateBitCast(Loc,
 constant->getType()->getPointerTo(Loc.getAddressSpace()));
-  emitStoresForInitAfterMemset(constant, Loc.getPointer(),
-   isVolatile, Builder);
+  emitStoresForInitAfterMemset(CGM, constant, Loc, isVolatile, Builder);
 }
   } else {
 // Otherwise, create a temporary global with the initializer then

Modified: cfe/trunk/test/CodeGen/init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/init.c?rev=337041=337040=337041=diff

[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-07-13 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Ping!


Repository:
  rC Clang

https://reviews.llvm.org/D47894



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


[PATCH] D49317: Move __construct_forward (etc.) out of std::allocator_traits.

2018-07-13 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone updated this revision to Diff 155473.
Quuxplusone added a comment.

Move the functions from `` to ``, since that's their only 
caller.
Uniform treatment of the pointer/iterator parameters; discover that the 
difference between "copy_forward" and "copy_range_forward" was that the former 
did moves and the latter did copies. Rename accordingly.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49317

Files:
  include/memory
  include/vector
  test/libcxx/containers/sequences/vector/specialized_allocator_traits.pass.cpp

Index: test/libcxx/containers/sequences/vector/specialized_allocator_traits.pass.cpp
===
--- /dev/null
+++ test/libcxx/containers/sequences/vector/specialized_allocator_traits.pass.cpp
@@ -0,0 +1,100 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03
+
+// 
+
+// Test that vector does not use non-standard members of std::allocator_traits.
+// Specializing std::allocator_traits is arguably non-conforming, but libc++'s
+// support for specialized std::allocator_traits is a feature, not a bug.
+// Breaking (and subsequently deleting) this unit test should be done as a
+// conscious decision.
+
+#include 
+
+template 
+class A1
+{
+public:
+using value_type = T;
+
+A1() = default;
+
+template 
+A1(const A1&) {}
+
+T *allocate(std::size_t n)
+{
+return (T *)std::malloc(n * sizeof (T));
+}
+
+void deallocate(T* p, std::size_t)
+{
+std::free(p);
+}
+};
+
+template
+struct std::allocator_traits> {
+using allocator_type = A1;
+using value_type = T;
+using pointer = T*;
+using const_pointer = const T*;
+using void_pointer = void*;
+using const_void_pointer = const void*;
+using difference_type = std::ptrdiff_t;
+using size_type = std::size_t;
+using propagate_on_container_copy_assignment = std::true_type;
+using propagate_on_container_move_assignment = std::true_type;
+using propagate_on_container_swap = std::true_type;
+using is_always_equal = std::true_type;
+
+template using rebind_alloc = A1;
+template using rebind_traits = std::allocator_traits>;
+
+static T *allocate(A1& a, size_t n) {
+return a.allocate(n);
+}
+
+static void deallocate(A1& a, T *p, size_t n) {
+return a.deallocate(p, n);
+}
+
+template
+static void construct(A1&, U *p, Args&&... args) {
+::new ((void*)p) U(std::forward(args)...);
+}
+
+template
+static void destroy(A1&, U *p) {
+p->~U();
+}
+
+static A1 select_on_container_copy_construction(const A1& a) {
+return a.select_on_container_copy_construction();
+}
+
+static size_type max_size(const A1&) {
+return size_t(-1);
+}
+};
+
+int main()
+{
+std::vector> v = {1, 2, 3};
+v.resize(10);
+v.insert(v.begin() + 4, 4);
+assert(v[0] == 1);
+assert(v[1] == 2);
+assert(v[2] == 3);
+assert(v[3] == 0);
+assert(v[4] == 4);
+assert(v[5] == 0);
+}
Index: include/vector
===
--- include/vector
+++ include/vector
@@ -291,6 +291,84 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+template 
+_LIBCPP_INLINE_VISIBILITY
+inline void
+__copy_construct_forward(_Alloc& __a, _Iter __begin1, _Iter __end1,
+ _Ptr& __begin2, _CopyViaMemcpy)
+{
+using _Alloc_traits = allocator_traits<_Alloc>;
+for (; __begin1 != __end1; ++__begin1, (void)++__begin2)
+_Alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
+}
+
+template 
+_LIBCPP_INLINE_VISIBILITY
+inline void
+__copy_construct_forward(_Alloc&, _Iter __begin1, _Iter __end1,
+ _Ptr& __begin2, true_type)
+{
+typedef typename iterator_traits<_Iter>::value_type _Tp;
+typedef typename remove_const<_Tp>::type _Vp;
+ptrdiff_t _Np = __end1 - __begin1;
+if (_Np > 0) {
+_VSTD::memcpy(const_cast<_Vp*>(_VSTD::__to_raw_pointer(__begin2)), _VSTD::__to_raw_pointer(__begin1), _Np * sizeof(_Tp));
+__begin2 += _Np;
+}
+}
+
+template 
+_LIBCPP_INLINE_VISIBILITY
+inline void
+__move_construct_forward(_Alloc& __a, _Ptr __begin1, _Ptr __end1,
+ _Ptr& __begin2, false_type)
+{
+using _Alloc_traits = allocator_traits<_Alloc>;
+for (; __begin1 != __end1; ++__begin1, ++__begin2)
+_Alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
+}
+
+template 
+_LIBCPP_INLINE_VISIBILITY
+inline void
+__move_construct_forward(_Alloc&, _Ptr __begin1, _Ptr __end1,
+ 

[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-13 Thread Andrew Comminos via Phabricator via cfe-commits
acomminos updated this revision to Diff 155472.
acomminos marked an inline comment as done.
acomminos added a comment.

Use source ranges instead of a pair of source locations for explicit lambda 
captures.


Repository:
  rC Clang

https://reviews.llvm.org/D48845

Files:
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaLambda.cpp
  test/FixIt/fixit-unused-lambda-capture.cpp

Index: test/FixIt/fixit-unused-lambda-capture.cpp
===
--- /dev/null
+++ test/FixIt/fixit-unused-lambda-capture.cpp
@@ -0,0 +1,94 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -fsyntax-only -Wunused-lambda-capture -Wno-unused-value -std=c++1z -fixit %t
+// RUN: grep -v CHECK %t | FileCheck %s
+
+void test() {
+  int i = 0;
+  int j = 0;
+  int k = 0;
+  int c = 10;
+  int a[c];
+
+  [i,j] { return i; };
+  // CHECK: [i] { return i; };
+  [i,j] { return j; };
+  // CHECK: [j] { return j; };
+  [,j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,] { return j; };
+  // CHECK: [j] { return j; };
+  [i,j,k] {};
+  // CHECK: [] {};
+  [i,j,k] { return i + j; };
+  // CHECK: [i,j] { return i + j; };
+  [i,j,k] { return j + k; };
+  // CHECK: [j,k] { return j + k; };
+  [i,j,k] { return i + k; };
+  // CHECK: [i,k] { return i + k; };
+  [i,j,k] { return i + j + k; };
+  // CHECK: [i,j,k] { return i + j + k; };
+  [&,i] { return k; };
+  // CHECK: [&] { return k; };
+  [=,] { return k; };
+  // CHECK: [=] { return k; };
+  [=,,] { return j; };
+  // CHECK: [=,] { return j; };
+  [=,,] { return i; };
+  // CHECK: [=,] { return i; };
+  [z = i] {};
+  // CHECK: [] {};
+  [i,z = i] { return z; };
+  // CHECK: [z = i] { return z; };
+  [z = i,i] { return z; };
+  // CHECK: [z = i] { return z; };
+  [] {};
+  // CHECK: [] {};
+  [i,] { return i; };
+  // CHECK: [i] { return i; };
+  [,i] { return i; };
+  // CHECK: [i] { return i; };
+
+  #define I_MACRO() i
+  #define I_REF_MACRO() 
+  [I_MACRO()] {};
+  // CHECK: [] {};
+  [I_MACRO(),j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,I_MACRO()] { return j; };
+  // CHECK: [j] { return j; };
+  [I_REF_MACRO(),j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,I_REF_MACRO()] { return j; };
+  // CHECK: [j] { return j; };
+
+  int n = 0;
+  [z = (n = i),j] {};
+  // CHECK: [z = (n = i)] {};
+  [j,z = (n = i)] {};
+  // CHECK: [z = (n = i)] {};
+}
+
+class ThisTest {
+  void test() {
+int i = 0;
+
+[this] {};
+// CHECK: [] {};
+[i,this] { return i; };
+// CHECK: [i] { return i; };
+[this,i] { return i; };
+// CHECK: [i] { return i; };
+[*this] {};
+// CHECK: [] {};
+[*this,i] { return i; };
+// CHECK: [i] { return i; };
+[i,*this] { return i; };
+// CHECK: [i] { return i; };
+[*this] { return this; };
+// CHECK: [*this] { return this; };
+[*this,i] { return this; };
+// CHECK: [*this] { return this; };
+[i,*this] { return this; };
+// CHECK: [*this] { return this; };
+  }
+};
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -993,6 +993,7 @@
   CheckCXXThisCapture(C->Loc, /*Explicit=*/true, /*BuildAndDiagnose*/ true,
   /*FunctionScopeIndexToStopAtPtr*/ nullptr,
   C->Kind == LCK_StarThis);
+  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = C->ExplicitRange;
   continue;
 }
 
@@ -1139,6 +1140,7 @@
TryCapture_ExplicitByVal;
   tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
 }
+LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = C->ExplicitRange;
   }
   finishLambdaExplicitCaptures(LSI);
 
@@ -1478,19 +1480,22 @@
   return false;
 }
 
-void Sema::DiagnoseUnusedLambdaCapture(const Capture ) {
+bool Sema::DiagnoseUnusedLambdaCapture(const SourceRange CaptureRange,
+   const Capture ) {
   if (CaptureHasSideEffects(From))
-return;
+return false;
 
   if (From.isVLATypeCapture())
-return;
+return false;
 
   auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
   if (From.isThisCapture())
 diag << "'this'";
   else
 diag << From.getVariable();
   diag << From.isNonODRUsed();
+  diag << FixItHint::CreateRemoval(CaptureRange);
+  return true;
 }
 
 ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
@@ -1532,18 +1537,49 @@
 
 // Translate captures.
 auto CurField = Class->field_begin();
+// True if the current capture has a used capture or default before it.
+bool CurHasPreviousCapture = CaptureDefault != LCD_None;
+SourceLocation PrevCaptureLoc = CurHasPreviousCapture ?
+CaptureDefaultLoc : IntroducerRange.getBegin();
+
 for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I, 

r337040 - [X86] Change the rounding mode used when testing the sqrt_round intrinsics.

2018-07-13 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Jul 13 13:16:38 2018
New Revision: 337040

URL: http://llvm.org/viewvc/llvm-project?rev=337040=rev
Log:
[X86] Change the rounding mode used when testing the sqrt_round intrinsics.

Using CUR_DIRECTION is not a realistic scenario. That is equivalent to the 
intrinsic without rounding.

Modified:
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/test/CodeGen/avx512f-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512f-builtins.c?rev=337040=337039=337040=diff
==
--- cfe/trunk/test/CodeGen/avx512f-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c Fri Jul 13 13:16:38 2018
@@ -5971,11 +5971,8 @@ __m512 test_mm512_maskz_shuffle_ps(__mma
 
 __m128d test_mm_sqrt_round_sd(__m128d __A, __m128d __B) {
   // CHECK-LABEL: @test_mm_sqrt_round_sd
-  // CHECK: extractelement <2 x double> %{{.*}}, i64 0
-  // CHECK-NEXT: call double @llvm.sqrt.f64(double %{{.*}})
-  // CHECK-NEXT: extractelement <2 x double> %{{.*}}, i64 0
-  // CHECK-NEXT: insertelement <2 x double> %{{.*}}, double {{.*}}, i64 0
-  return _mm_sqrt_round_sd(__A, __B, 4); 
+  // CHECK: call <2 x double> @llvm.x86.avx512.mask.sqrt.sd(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}}, i8 -1, i32 8)
+  return _mm_sqrt_round_sd(__A, __B, _MM_FROUND_TO_NEAREST_INT | 
_MM_FROUND_NO_EXC); 
 }
 
 __m128d test_mm_mask_sqrt_sd(__m128d __W, __mmask8 __U, __m128d __A, __m128d 
__B){
@@ -5992,14 +5989,8 @@ __m128d test_mm_mask_sqrt_sd(__m128d __W
 
 __m128d test_mm_mask_sqrt_round_sd(__m128d __W, __mmask8 __U, __m128d __A, 
__m128d __B){
   // CHECK-LABEL: @test_mm_mask_sqrt_round_sd
-  // CHECK: extractelement <2 x double> %{{.*}}, i64 0
-  // CHECK-NEXT: call double @llvm.sqrt.f64(double %{{.*}})
-  // CHECK-NEXT: extractelement <2 x double> %{{.*}}, i64 0
-  // CHECK-NEXT: bitcast i8 %{{.*}} to <8 x i1>
-  // CHECK-NEXT: extractelement <8 x i1> %{{.*}}, i64 0
-  // CHECK-NEXT: select i1 {{.*}}, double {{.*}}, double {{.*}}
-  // CHECK-NEXT: insertelement <2 x double> %{{.*}}, double {{.*}}, i64 0
-  return _mm_mask_sqrt_round_sd(__W,__U,__A,__B,_MM_FROUND_CUR_DIRECTION);
+  // CHECK: call <2 x double> @llvm.x86.avx512.mask.sqrt.sd(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}}, i8 %{{.*}}, i32 8)
+  return _mm_mask_sqrt_round_sd(__W,__U,__A,__B,_MM_FROUND_TO_NEAREST_INT | 
_MM_FROUND_NO_EXC);
 }
 
 __m128d test_mm_maskz_sqrt_sd(__mmask8 __U, __m128d __A, __m128d __B){
@@ -6016,23 +6007,14 @@ __m128d test_mm_maskz_sqrt_sd(__mmask8 _
 
 __m128d test_mm_maskz_sqrt_round_sd(__mmask8 __U, __m128d __A, __m128d __B){
   // CHECK-LABEL: @test_mm_maskz_sqrt_round_sd
-  // CHECK: extractelement <2 x double> %{{.*}}, i64 0
-  // CHECK-NEXT: call double @llvm.sqrt.f64(double %{{.*}})
-  // CHECK-NEXT: extractelement <2 x double> %{{.*}}, i64 0
-  // CHECK-NEXT: bitcast i8 %{{.*}} to <8 x i1>
-  // CHECK-NEXT: extractelement <8 x i1> %{{.*}}, i64 0
-  // CHECK-NEXT: select i1 {{.*}}, double {{.*}}, double {{.*}}
-  // CHECK-NEXT: insertelement <2 x double> %{{.*}}, double {{.*}}, i64 0
-  return _mm_maskz_sqrt_round_sd(__U,__A,__B,_MM_FROUND_CUR_DIRECTION);
+  // CHECK: call <2 x double> @llvm.x86.avx512.mask.sqrt.sd(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}}, i8 %{{.*}}, i32 8)
+  return _mm_maskz_sqrt_round_sd(__U,__A,__B,_MM_FROUND_TO_NEAREST_INT | 
_MM_FROUND_NO_EXC);
 }
 
 __m128 test_mm_sqrt_round_ss(__m128 __A, __m128 __B) {
   // CHECK-LABEL: @test_mm_sqrt_round_ss
-  // CHECK: extractelement <4 x float> %{{.*}}, i64 0
-  // CHECK-NEXT: call float @llvm.sqrt.f32(float %{{.*}})
-  // CHECK-NEXT: extractelement <4 x float> %{{.*}}, i64 0
-  // CHECK-NEXT: insertelement <4 x float> %{{.*}}, float {{.*}}, i64 0
-  return _mm_sqrt_round_ss(__A, __B, 4); 
+  // CHECK: call <4 x float> @llvm.x86.avx512.mask.sqrt.ss(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}, i8 -1, i32 8)
+  return _mm_sqrt_round_ss(__A, __B, _MM_FROUND_TO_NEAREST_INT | 
_MM_FROUND_NO_EXC); 
 }
 
 __m128 test_mm_mask_sqrt_ss(__m128 __W, __mmask8 __U, __m128 __A, __m128 __B){
@@ -6049,14 +6031,8 @@ __m128 test_mm_mask_sqrt_ss(__m128 __W,
 
 __m128 test_mm_mask_sqrt_round_ss(__m128 __W, __mmask8 __U, __m128 __A, __m128 
__B){
   // CHECK-LABEL: @test_mm_mask_sqrt_round_ss
-  // CHECK: extractelement <4 x float> %{{.*}}, i64 0
-  // CHECK-NEXT: call float @llvm.sqrt.f32(float %{{.*}})
-  // CHECK-NEXT: extractelement <4 x float> %{{.*}}, i64 0
-  // CHECK-NEXT: bitcast i8 %{{.*}} to <8 x i1>
-  // CHECK-NEXT: extractelement <8 x i1> %{{.*}}, i64 0
-  // CHECK-NEXT: select i1 {{.*}}, float {{.*}}, float {{.*}}
-  // CHECK-NEXT: insertelement <4 x float> %{{.*}}, float {{.*}}, i64 0
-  return _mm_mask_sqrt_round_ss(__W,__U,__A,__B,_MM_FROUND_CUR_DIRECTION);
+  // CHECK: call <4 x float> @llvm.x86.avx512.mask.sqrt.ss(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> 

[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-13 Thread Andrew Comminos via Phabricator via cfe-commits
acomminos marked an inline comment as done.
acomminos added inline comments.



Comment at: include/clang/Sema/DeclSpec.h:2552-2553
 ParsedType InitCaptureType;
+SourceLocation LocStart;
+SourceLocation LocEnd;
+

aaron.ballman wrote:
> aaron.ballman wrote:
> > How does `LocStart` relate to the existing source location `Loc`? I think 
> > this should have a more descriptive name of what location is involved.
> Now that I think about this more, I wonder if this is better expressed as 
> `SourceRange CaptureRange;` given that there's always a start and end and 
> they should never be equal?
Sure, makes sense to me. Many other classes with attached range data appear to 
use explicit start/end locations, but in this case I think it's fine.


Repository:
  rC Clang

https://reviews.llvm.org/D48845



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


[PATCH] D49317: Move __construct_forward (etc.) out of std::allocator_traits.

2018-07-13 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone created this revision.
Quuxplusone added reviewers: EricWF, mclow.lists, erik.pilkington, vsapsai.
Herald added subscribers: cfe-commits, ldionne, christof.

Inspired by Volodymyr's work on https://reviews.llvm.org/D48753, I've taken it 
upon myself to refactor the static member functions 
`std::allocator_traits::__construct_forward`, `__construct_backward`, and 
`__construct_range_forward` into non-member functions. I think this is 
reasonable just in terms of code-cleanliness — they don't *have* to be member 
functions for any reason I can think of — and then it also permits a suitably 
sadomasochistic programmer to define his own specialization of 
`std::allocator_traits` without causing compiler errors in ``.

I have added a test case in `test/libcxx/` for the sadomasochistic case, which 
I describe as "arguably ill-formed." I would be very very happy to see WG21 
agree that specializing traits classes (pointer_traits, allocator_traits, 
iterator_traits) *is* ill-formed; I believe there's some disagreement on the 
subject at the moment.  In the meantime, I think this would be a nice patch 
just on code-cleanliness grounds.

This patch is also groundwork for the "trivially relocatable" fork that I'm 
building on my GitHub 
; we'd need an 
architecture something like this in order to easily drop in support for trivial 
relocatability.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49317

Files:
  include/memory
  include/vector
  test/libcxx/containers/sequences/vector/specialized_allocator_traits.pass.cpp

Index: test/libcxx/containers/sequences/vector/specialized_allocator_traits.pass.cpp
===
--- /dev/null
+++ test/libcxx/containers/sequences/vector/specialized_allocator_traits.pass.cpp
@@ -0,0 +1,100 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03
+
+// 
+
+// Test that vector does not use non-standard members of std::allocator_traits.
+// Specializing std::allocator_traits is arguably non-conforming, but libc++'s
+// support for specialized std::allocator_traits is a feature, not a bug.
+// Breaking (and subsequently deleting) this unit test should be done as a
+// conscious decision.
+
+#include 
+
+template 
+class A1
+{
+public:
+using value_type = T;
+
+A1() = default;
+
+template 
+A1(const A1&) {}
+
+T *allocate(std::size_t n)
+{
+return (T *)std::malloc(n * sizeof (T));
+}
+
+void deallocate(T* p, std::size_t)
+{
+std::free(p);
+}
+};
+
+template
+struct std::allocator_traits> {
+using allocator_type = A1;
+using value_type = T;
+using pointer = T*;
+using const_pointer = const T*;
+using void_pointer = void*;
+using const_void_pointer = const void*;
+using difference_type = std::ptrdiff_t;
+using size_type = std::size_t;
+using propagate_on_container_copy_assignment = std::true_type;
+using propagate_on_container_move_assignment = std::true_type;
+using propagate_on_container_swap = std::true_type;
+using is_always_equal = std::true_type;
+
+template using rebind_alloc = A1;
+template using rebind_traits = std::allocator_traits>;
+
+static T *allocate(A1& a, size_t n) {
+return a.allocate(n);
+}
+
+static void deallocate(A1& a, T *p, size_t n) {
+return a.deallocate(p, n);
+}
+
+template
+static void construct(A1&, U *p, Args&&... args) {
+::new ((void*)p) U(std::forward(args)...);
+}
+
+template
+static void destroy(A1&, U *p) {
+p->~U();
+}
+
+static A1 select_on_container_copy_construction(const A1& a) {
+return a.select_on_container_copy_construction();
+}
+
+static size_type max_size(const A1&) {
+return size_t(-1);
+}
+};
+
+int main()
+{
+std::vector> v = {1, 2, 3};
+v.resize(10);
+v.insert(v.begin() + 4, 4);
+assert(v[0] == 1);
+assert(v[1] == 2);
+assert(v[2] == 3);
+assert(v[3] == 0);
+assert(v[4] == 4);
+assert(v[5] == 0);
+}
Index: include/vector
===
--- include/vector
+++ include/vector
@@ -460,13 +460,20 @@
 }
 }
 
+template
+struct __vector_copy_via_memcpy : integral_constant >::value || !__has_construct<_Allocator, _Tp*, _Tp>::value) &&
+is_trivially_move_constructible<_Tp>::value
+> {};
+
 template  */>
 class _LIBCPP_TEMPLATE_VIS vector
 : private __vector_base<_Tp, _Allocator>
 {
 private:
 typedef __vector_base<_Tp, _Allocator>   __base;
 

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

2018-07-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne accepted this revision.
ldionne added a comment.
This revision is now accepted and ready to land.

LGTM -- great! Just make sure the commit message does not pretend the change 
includes `merge`.

This may be obvious, but my LGTM alone should probably not be enough to submit.


https://reviews.llvm.org/D46845



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


r337037 - SafeStack: Add builtins to read unsafe stack top/bottom

2018-07-13 Thread Vlad Tsyrklevich via cfe-commits
Author: vlad.tsyrklevich
Date: Fri Jul 13 12:48:35 2018
New Revision: 337037

URL: http://llvm.org/viewvc/llvm-project?rev=337037=rev
Log:
SafeStack: Add builtins to read unsafe stack top/bottom

Summary:
Introduce built-ins to read the unsafe stack top and bottom. The unsafe
stack top is required to implement garbage collection scanning for
Oilpan. Currently there is already a built-in 'get_unsafe_stack_start'
to read the bottom of the unsafe stack, but I chose to duplicate this
API because 'start' is ambiguous (e.g. Oilpan uses WTF::GetStackStart to
read the safe stack top.)

Reviewers: pcc

Reviewed By: pcc

Subscribers: llvm-commits, kcc

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

Modified:
cfe/trunk/docs/SafeStack.rst
cfe/trunk/include/clang/Basic/Builtins.def

Modified: cfe/trunk/docs/SafeStack.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/SafeStack.rst?rev=337037=337036=337037=diff
==
--- cfe/trunk/docs/SafeStack.rst (original)
+++ cfe/trunk/docs/SafeStack.rst Fri Jul 13 12:48:35 2018
@@ -165,11 +165,23 @@ never be stored on the heap, as it would
 This builtin function returns current unsafe stack pointer of the current
 thread.
 
+``__builtin___get_unsafe_stack_bottom()``
+~
+
+This builtin function returns a pointer to the bottom of the unsafe stack of 
the
+current thread.
+
+``__builtin___get_unsafe_stack_top()``
+~~
+
+This builtin function returns a pointer to the top of the unsafe stack of the
+current thread.
+
 ``__builtin___get_unsafe_stack_start()``
 
 
-This builtin function returns a pointer to the start of the unsafe stack of the
-current thread.
+Deprecated: This builtin function is an alias for
+``__builtin___get_unsafe_stack_bottom()``.
 
 Design
 ==

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=337037=337036=337037=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Fri Jul 13 12:48:35 2018
@@ -1412,6 +1412,8 @@ BUILTIN(__builtin_dump_struct, "ivC*v*",
 
 // Safestack builtins
 BUILTIN(__builtin___get_unsafe_stack_start, "v*", "Fn")
+BUILTIN(__builtin___get_unsafe_stack_bottom, "v*", "Fn")
+BUILTIN(__builtin___get_unsafe_stack_top, "v*", "Fn")
 BUILTIN(__builtin___get_unsafe_stack_ptr, "v*", "Fn")
 
 // Nontemporal loads/stores builtins


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


[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.

2018-07-13 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337036: PR15730/PR16986 Allow dependently typed vector_size 
types. (authored by erichkeane, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49045?vs=155419=155462#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49045

Files:
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/AST/TypeLoc.h
  cfe/trunk/include/clang/AST/TypeNodes.def
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/include/clang/Serialization/ASTBitCodes.h
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
  cfe/trunk/lib/AST/ItaniumMangle.cpp
  cfe/trunk/lib/AST/MicrosoftMangle.cpp
  cfe/trunk/lib/AST/Type.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/lib/Lex/LiteralSupport.cpp
  cfe/trunk/lib/Sema/SemaTemplate.cpp
  cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/lib/Sema/TreeTransform.h
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/test/SemaCXX/vector.cpp
  cfe/trunk/tools/libclang/CIndex.cpp

Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
===
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
@@ -993,6 +993,12 @@
   TRY_TO(TraverseType(T->getPointeeType()));
 })
 
+DEF_TRAVERSE_TYPE(DependentVectorType, {
+  if (T->getSizeExpr())
+TRY_TO(TraverseStmt(T->getSizeExpr()));
+  TRY_TO(TraverseType(T->getElementType()));
+})
+
 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
   if (T->getSizeExpr())
 TRY_TO(TraverseStmt(T->getSizeExpr()));
@@ -1221,6 +1227,12 @@
   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
 })
 
+DEF_TRAVERSE_TYPELOC(DependentVectorType, {
+  if (TL.getTypePtr()->getSizeExpr())
+TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
+  TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
+})
+
 // FIXME: size and attributes
 // FIXME: base VectorTypeLoc is unfinished
 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -168,6 +168,7 @@
   mutable llvm::FoldingSet
   DependentAddressSpaceTypes;
   mutable llvm::FoldingSet VectorTypes;
+  mutable llvm::FoldingSet DependentVectorTypes;
   mutable llvm::FoldingSet FunctionNoProtoTypes;
   mutable llvm::ContextualFoldingSet
 FunctionProtoTypes;
@@ -1321,6 +1322,11 @@
   /// \pre \p VectorType must be a built-in type.
   QualType getVectorType(QualType VectorType, unsigned NumElts,
  VectorType::VectorKind VecKind) const;
+  /// Return the unique reference to the type for a dependently sized vector of
+  /// the specified element type.
+  QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr,
+  SourceLocation AttrLoc,
+  VectorType::VectorKind VecKind) const;
 
   /// Return the unique reference to an extended vector type
   /// of the specified element type and size.
Index: cfe/trunk/include/clang/AST/TypeNodes.def
===
--- cfe/trunk/include/clang/AST/TypeNodes.def
+++ cfe/trunk/include/clang/AST/TypeNodes.def
@@ -75,6 +75,7 @@
 DEPENDENT_TYPE(DependentSizedExtVector, Type)
 DEPENDENT_TYPE(DependentAddressSpace, Type)
 TYPE(Vector, Type)
+DEPENDENT_TYPE(DependentVector, Type)
 TYPE(ExtVector, VectorType)
 ABSTRACT_TYPE(Function, Type)
 TYPE(FunctionProto, FunctionType)
Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -1590,6 +1590,7 @@
 
   class VectorTypeBitfields {
 friend class VectorType;
+friend class DependentVectorType;
 
 unsigned : NumTypeBits;
 
@@ -3079,6 +3080,51 @@
   }
 };
 
+/// Represents a vector type where either the type or size is dependent.
+
+/// For example:
+/// \code
+/// template
+/// class vector {
+///   typedef T __attribute__((vector_size(Size))) type;
+/// }
+/// \endcode
+class DependentVectorType : public Type, public llvm::FoldingSetNode {
+  friend class ASTContext;
+
+  const ASTContext 
+  QualType ElementType;
+  Expr *SizeExpr;
+  SourceLocation Loc;
+
+  DependentVectorType(const ASTContext , QualType ElementType,
+   QualType CanonType, Expr *SizeExpr,
+   SourceLocation Loc, VectorType::VectorKind vecKind);
+
+public:
+  Expr *getSizeExpr() const { return SizeExpr; }
+  QualType getElementType() const { return 

r337036 - PR15730/PR16986 Allow dependently typed vector_size types.

2018-07-13 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Jul 13 12:46:04 2018
New Revision: 337036

URL: http://llvm.org/viewvc/llvm-project?rev=337036=rev
Log:
PR15730/PR16986 Allow dependently typed vector_size types.

As listed in the above PRs, vector_size doesn't allow
dependent types/values. This patch introduces a new
DependentVectorType to handle a VectorType that has a dependent
size or type.

In the future, ALL the vector-types should be able to create one
of these to handle dependent types/sizes as well. For example,
DependentSizedExtVectorType could likely be switched to just use
this instead, though that is left as an exercise for the future.


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

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/AST/TypeNodes.def
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/Lex/LiteralSupport.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/SemaCXX/vector.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=337036=337035=337036=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Jul 13 12:46:04 2018
@@ -168,6 +168,7 @@ class ASTContext : public RefCountedBase
   mutable llvm::FoldingSet
   DependentAddressSpaceTypes;
   mutable llvm::FoldingSet VectorTypes;
+  mutable llvm::FoldingSet DependentVectorTypes;
   mutable llvm::FoldingSet FunctionNoProtoTypes;
   mutable llvm::ContextualFoldingSet
 FunctionProtoTypes;
@@ -1321,6 +1322,11 @@ public:
   /// \pre \p VectorType must be a built-in type.
   QualType getVectorType(QualType VectorType, unsigned NumElts,
  VectorType::VectorKind VecKind) const;
+  /// Return the unique reference to the type for a dependently sized vector of
+  /// the specified element type.
+  QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr,
+  SourceLocation AttrLoc,
+  VectorType::VectorKind VecKind) const;
 
   /// Return the unique reference to an extended vector type
   /// of the specified element type and size.

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=337036=337035=337036=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Fri Jul 13 12:46:04 2018
@@ -993,6 +993,12 @@ DEF_TRAVERSE_TYPE(DependentAddressSpaceT
   TRY_TO(TraverseType(T->getPointeeType()));
 })
 
+DEF_TRAVERSE_TYPE(DependentVectorType, {
+  if (T->getSizeExpr())
+TRY_TO(TraverseStmt(T->getSizeExpr()));
+  TRY_TO(TraverseType(T->getElementType()));
+})
+
 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
   if (T->getSizeExpr())
 TRY_TO(TraverseStmt(T->getSizeExpr()));
@@ -1221,6 +1227,12 @@ DEF_TRAVERSE_TYPELOC(VectorType, {
   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
 })
 
+DEF_TRAVERSE_TYPELOC(DependentVectorType, {
+  if (TL.getTypePtr()->getSizeExpr())
+TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
+  TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
+})
+
 // FIXME: size and attributes
 // FIXME: base VectorTypeLoc is unfinished
 DEF_TRAVERSE_TYPELOC(ExtVectorType, {

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=337036=337035=337036=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Jul 13 12:46:04 2018
@@ -1590,6 +1590,7 @@ protected:
 
   class VectorTypeBitfields {
 friend class VectorType;
+friend class DependentVectorType;
 
 unsigned : NumTypeBits;
 
@@ -3079,6 +3080,51 @@ public:
   }
 };
 
+/// Represents a vector type where either the type or size is dependent.
+
+/// For example:
+/// \code
+/// template
+/// class vector {
+///   typedef T __attribute__((vector_size(Size))) type;
+/// }

[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-07-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In https://reviews.llvm.org/D46915#1162095, @leonardchan wrote:

> In https://reviews.llvm.org/D46915#1162038, @erichkeane wrote:
>
> > See this bug here: https://bugs.llvm.org/show_bug.cgi?id=38161
> >
> > This patch doesn't seem to properly consider integers, and ignores octals, 
> > which I suspect shouldn't be the case.
>
>
> I just requested an account on bugs.llvm.org and will respond here for now 
> until I can comment on the thread there.
>
> So the syntax for fixed point literals should be the same as that for 
> floating point constants according to clause 6.4.4.2a in the embedded C spec 
> (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf). Integers and 
> octal literals should not be supported since floating point literals can only 
> be declared in decimal or hexadecimal notation.


Then it seems you've missed that part... These literals are allowing integers 
without issue at the moment.

> I can see how the error messages don't seem clear and portray this, and 
> should eventually change it so if the user does provide an integer/octal 
> literal an error along the lines of `"fixed point literals cannot be declared 
> as integers"` should be thrown instead.

Seems like that could work.

> The assertion is also something that I will address since this should not be 
> thrown.
> 
> To sidetrack a bit also, we are limiting fixed point types to just C for now 
> (https://reviews.llvm.org/D46084) so using `auto` to complete the type is not 
> supported. This is until we come up with an itanium mangling for fixed point 
> types (https://github.com/itanium-cxx-abi/cxx-abi/issues/56).

At the moment you are NOT limiting to C.  You'll have to add quite a view 
checks at the moment in order to make that limitation.  That said `auto' was 
for convienience, it had nothign to do with the bug itself.


Repository:
  rC Clang

https://reviews.llvm.org/D46915



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


[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-07-13 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In https://reviews.llvm.org/D46915#1162038, @erichkeane wrote:

> See this bug here: https://bugs.llvm.org/show_bug.cgi?id=38161
>
> This patch doesn't seem to properly consider integers, and ignores octals, 
> which I suspect shouldn't be the case.


I just requested an account on bugs.llvm.org and will respond here for now 
until I can comment on the thread there.

So the syntax for fixed point literals should be the same as that for floating 
point constants according to clause 6.4.4.2a in the embedded C spec 
(http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf). Integers and octal 
literals should not be supported since floating point literals can only be 
declared in decimal or hexadecimal notation.

I can see how the error messages don't seem clear and portray this, and should 
eventually change it so if the user does provide an integer/octal literal an 
error along the lines of `"fixed point literals cannot be declared as 
integers"` should be thrown instead.

The assertion is also something that I will address since this should not be 
thrown.

To sidetrack a bit also, we are limiting fixed point types to just C for now 
(https://reviews.llvm.org/D46084) so using `auto` to complete the type is not 
supported. This is until we come up with an itanium mangling for fixed point 
types (https://github.com/itanium-cxx-abi/cxx-abi/issues/56).


Repository:
  rC Clang

https://reviews.llvm.org/D46915



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


[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/Sema/DeclSpec.h:2552-2553
 ParsedType InitCaptureType;
+SourceLocation LocStart;
+SourceLocation LocEnd;
+

aaron.ballman wrote:
> How does `LocStart` relate to the existing source location `Loc`? I think 
> this should have a more descriptive name of what location is involved.
Now that I think about this more, I wonder if this is better expressed as 
`SourceRange CaptureRange;` given that there's always a start and end and they 
should never be equal?


Repository:
  rC Clang

https://reviews.llvm.org/D48845



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


[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.

2018-07-13 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, though it's your call on the const_cast stuff whether you want to revert 
or keep it.




Comment at: include/clang/AST/Type.h:3105
+public:
+  Expr *getSizeExpr() const { return SizeExpr; }
+  QualType getElementType() const { return ElementType; }

erichkeane wrote:
> aaron.ballman wrote:
> > Can this return `const Expr *` and have a non-const overload to return the 
> > non-const `Expr *`?
> Done, but unfortunately, TypeLoc visitation (RecursiveASTVisitor) lacks const 
> correctness in a bunch of places so a cast was required there :/  
> Additionally, TreeTransform has similar issues, so a const-cast was required 
> as well.  Both end up being a bit of a cleanup, perhaps more than I can 
> tackle at the moment.
Oye, now that I see how many const_cast's get added, I'm starting to regret 
asking for this. :-P Your call as to whether you want to leave it in this state 
or revert back the const-correctness attempt.


https://reviews.llvm.org/D49045



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


[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-07-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

See this bug here: https://bugs.llvm.org/show_bug.cgi?id=38161

This patch doesn't seem to properly consider integers, and ignores octals, 
which I suspect shouldn't be the case.


Repository:
  rC Clang

https://reviews.llvm.org/D46915



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


[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-13 Thread Andrew Comminos via Phabricator via cfe-commits
acomminos updated this revision to Diff 155446.
acomminos marked 2 inline comments as done.
acomminos added a comment.

Add test for stateful initializer expressions not being removed, propagate 
whether or not a diagnostic actually get emitted.


Repository:
  rC Clang

https://reviews.llvm.org/D48845

Files:
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaLambda.cpp
  test/FixIt/fixit-unused-lambda-capture.cpp

Index: test/FixIt/fixit-unused-lambda-capture.cpp
===
--- /dev/null
+++ test/FixIt/fixit-unused-lambda-capture.cpp
@@ -0,0 +1,94 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -fsyntax-only -Wunused-lambda-capture -Wno-unused-value -std=c++1z -fixit %t
+// RUN: grep -v CHECK %t | FileCheck %s
+
+void test() {
+  int i = 0;
+  int j = 0;
+  int k = 0;
+  int c = 10;
+  int a[c];
+
+  [i,j] { return i; };
+  // CHECK: [i] { return i; };
+  [i,j] { return j; };
+  // CHECK: [j] { return j; };
+  [,j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,] { return j; };
+  // CHECK: [j] { return j; };
+  [i,j,k] {};
+  // CHECK: [] {};
+  [i,j,k] { return i + j; };
+  // CHECK: [i,j] { return i + j; };
+  [i,j,k] { return j + k; };
+  // CHECK: [j,k] { return j + k; };
+  [i,j,k] { return i + k; };
+  // CHECK: [i,k] { return i + k; };
+  [i,j,k] { return i + j + k; };
+  // CHECK: [i,j,k] { return i + j + k; };
+  [&,i] { return k; };
+  // CHECK: [&] { return k; };
+  [=,] { return k; };
+  // CHECK: [=] { return k; };
+  [=,,] { return j; };
+  // CHECK: [=,] { return j; };
+  [=,,] { return i; };
+  // CHECK: [=,] { return i; };
+  [z = i] {};
+  // CHECK: [] {};
+  [i,z = i] { return z; };
+  // CHECK: [z = i] { return z; };
+  [z = i,i] { return z; };
+  // CHECK: [z = i] { return z; };
+  [] {};
+  // CHECK: [] {};
+  [i,] { return i; };
+  // CHECK: [i] { return i; };
+  [,i] { return i; };
+  // CHECK: [i] { return i; };
+
+  #define I_MACRO() i
+  #define I_REF_MACRO() 
+  [I_MACRO()] {};
+  // CHECK: [] {};
+  [I_MACRO(),j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,I_MACRO()] { return j; };
+  // CHECK: [j] { return j; };
+  [I_REF_MACRO(),j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,I_REF_MACRO()] { return j; };
+  // CHECK: [j] { return j; };
+
+  int n = 0;
+  [z = (n = i),j] {};
+  // CHECK: [z = (n = i)] {};
+  [j,z = (n = i)] {};
+  // CHECK: [z = (n = i)] {};
+}
+
+class ThisTest {
+  void test() {
+int i = 0;
+
+[this] {};
+// CHECK: [] {};
+[i,this] { return i; };
+// CHECK: [i] { return i; };
+[this,i] { return i; };
+// CHECK: [i] { return i; };
+[*this] {};
+// CHECK: [] {};
+[*this,i] { return i; };
+// CHECK: [i] { return i; };
+[i,*this] { return i; };
+// CHECK: [i] { return i; };
+[*this] { return this; };
+// CHECK: [*this] { return this; };
+[*this,i] { return this; };
+// CHECK: [*this] { return this; };
+[i,*this] { return this; };
+// CHECK: [*this] { return this; };
+  }
+};
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -993,6 +993,8 @@
   CheckCXXThisCapture(C->Loc, /*Explicit=*/true, /*BuildAndDiagnose*/ true,
   /*FunctionScopeIndexToStopAtPtr*/ nullptr,
   C->Kind == LCK_StarThis);
+  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] =
+  SourceRange(C->ExplicitLocStart, C->ExplicitLocEnd);
   continue;
 }
 
@@ -1139,6 +1141,8 @@
TryCapture_ExplicitByVal;
   tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
 }
+LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] =
+SourceRange(C->ExplicitLocStart, C->ExplicitLocEnd);
   }
   finishLambdaExplicitCaptures(LSI);
 
@@ -1478,19 +1482,22 @@
   return false;
 }
 
-void Sema::DiagnoseUnusedLambdaCapture(const Capture ) {
+bool Sema::DiagnoseUnusedLambdaCapture(const SourceRange CaptureRange,
+   const Capture ) {
   if (CaptureHasSideEffects(From))
-return;
+return false;
 
   if (From.isVLATypeCapture())
-return;
+return false;
 
   auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
   if (From.isThisCapture())
 diag << "'this'";
   else
 diag << From.getVariable();
   diag << From.isNonODRUsed();
+  diag << FixItHint::CreateRemoval(CaptureRange);
+  return true;
 }
 
 ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
@@ -1532,18 +1539,49 @@
 
 // Translate captures.
 auto CurField = Class->field_begin();
+// True if the current capture has a used capture or default before it.
+bool CurHasPreviousCapture = CaptureDefault != LCD_None;
+SourceLocation PrevCaptureLoc = 

[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-13 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: lib/CodeGen/CGBuilder.h:260
+CharUnits::fromQuantity(Offset.getSExtValue(;
+  }
+

jfb wrote:
> efriedma wrote:
> > Not sure about the new helper.  We already have CreateStructGEP and 
> > CreateConstArrayGEP which do approximately what you want.
> It's close to doing what we want, but not quite? It seems like the original 
> code would have used them otherwise.
> 
> To use them we'd have to:
> 
>   - branch on struct / array
> - for struct calculate the offset there (which the new helper does)
> - for array get the element size
> 
> Seems simpler to use GEP2_32 and more fool-proof to (internal to the helper) 
> use GEP's own idea of what the offset is, no?
Okay.

(Actually, I think this ends up conservatively underestimating the alignment in 
some cases involving nested structs, but it's unlikely to matter.)


Repository:
  rC Clang

https://reviews.llvm.org/D49209



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


[libcxx] r337028 - wrap _LIBCPP_HAS_NO_CXX14_CONSTEXPR in defined(...)

2018-07-13 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Fri Jul 13 10:31:36 2018
New Revision: 337028

URL: http://llvm.org/viewvc/llvm-project?rev=337028=rev
Log:
wrap _LIBCPP_HAS_NO_CXX14_CONSTEXPR in defined(...)


Modified:
libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=337028=337027=337028=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri Jul 13 10:31:36 2018
@@ -1024,7 +1024,7 @@ template  struct __static_asse
 #endif
 
 #ifndef _LIBCPP_CONSTEXPR_IF_NODEBUG
-#if defined(_LIBCPP_DEBUG) || _LIBCPP_HAS_NO_CXX14_CONSTEXPR
+#if defined(_LIBCPP_DEBUG) || defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
 #define _LIBCPP_CONSTEXPR_IF_NODEBUG
 #else
 #define _LIBCPP_CONSTEXPR_IF_NODEBUG constexpr


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


[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-13 Thread Andrew Comminos via Phabricator via cfe-commits
acomminos updated this revision to Diff 155430.
acomminos marked 2 inline comments as done.
acomminos added a comment.

Elide braces in single-line conditional.


Repository:
  rC Clang

https://reviews.llvm.org/D48845

Files:
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaLambda.cpp
  test/FixIt/fixit-unused-lambda-capture.cpp

Index: test/FixIt/fixit-unused-lambda-capture.cpp
===
--- /dev/null
+++ test/FixIt/fixit-unused-lambda-capture.cpp
@@ -0,0 +1,88 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -fsyntax-only -Wunused-lambda-capture -Wno-unused-value -std=c++1z -fixit %t
+// RUN: grep -v CHECK %t | FileCheck %s
+
+void test() {
+  int i = 0;
+  int j = 0;
+  int k = 0;
+  int c = 10;
+  int a[c];
+
+  [i,j] { return i; };
+  // CHECK: [i] { return i; };
+  [i,j] { return j; };
+  // CHECK: [j] { return j; };
+  [,j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,] { return j; };
+  // CHECK: [j] { return j; };
+  [i,j,k] {};
+  // CHECK: [] {};
+  [i,j,k] { return i + j; };
+  // CHECK: [i,j] { return i + j; };
+  [i,j,k] { return j + k; };
+  // CHECK: [j,k] { return j + k; };
+  [i,j,k] { return i + k; };
+  // CHECK: [i,k] { return i + k; };
+  [i,j,k] { return i + j + k; };
+  // CHECK: [i,j,k] { return i + j + k; };
+  [&,i] { return k; };
+  // CHECK: [&] { return k; };
+  [=,] { return k; };
+  // CHECK: [=] { return k; };
+  [=,,] { return j; };
+  // CHECK: [=,] { return j; };
+  [=,,] { return i; };
+  // CHECK: [=,] { return i; };
+  [z = i] {};
+  // CHECK: [] {};
+  [i,z = i] { return z; };
+  // CHECK: [z = i] { return z; };
+  [z = i,i] { return z; };
+  // CHECK: [z = i] { return z; };
+  [] {};
+  // CHECK: [] {};
+  [i,] { return i; };
+  // CHECK: [i] { return i; };
+  [,i] { return i; };
+  // CHECK: [i] { return i; };
+
+  #define I_MACRO() i
+  #define I_REF_MACRO() 
+  [I_MACRO()] {};
+  // CHECK: [] {};
+  [I_MACRO(),j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,I_MACRO()] { return j; };
+  // CHECK: [j] { return j; };
+  [I_REF_MACRO(),j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,I_REF_MACRO()] { return j; };
+  // CHECK: [j] { return j; };
+}
+
+class ThisTest {
+  void test() {
+int i = 0;
+
+[this] {};
+// CHECK: [] {};
+[i,this] { return i; };
+// CHECK: [i] { return i; };
+[this,i] { return i; };
+// CHECK: [i] { return i; };
+[*this] {};
+// CHECK: [] {};
+[*this,i] { return i; };
+// CHECK: [i] { return i; };
+[i,*this] { return i; };
+// CHECK: [i] { return i; };
+[*this] { return this; };
+// CHECK: [*this] { return this; };
+[*this,i] { return this; };
+// CHECK: [*this] { return this; };
+[i,*this] { return this; };
+// CHECK: [*this] { return this; };
+  }
+};
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -993,6 +993,8 @@
   CheckCXXThisCapture(C->Loc, /*Explicit=*/true, /*BuildAndDiagnose*/ true,
   /*FunctionScopeIndexToStopAtPtr*/ nullptr,
   C->Kind == LCK_StarThis);
+  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] =
+  SourceRange(C->ExplicitLocStart, C->ExplicitLocEnd);
   continue;
 }
 
@@ -1139,6 +1141,8 @@
TryCapture_ExplicitByVal;
   tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
 }
+LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] =
+SourceRange(C->ExplicitLocStart, C->ExplicitLocEnd);
   }
   finishLambdaExplicitCaptures(LSI);
 
@@ -1478,7 +1482,8 @@
   return false;
 }
 
-void Sema::DiagnoseUnusedLambdaCapture(const Capture ) {
+void Sema::DiagnoseUnusedLambdaCapture(const SourceRange CaptureRange,
+   const Capture ) {
   if (CaptureHasSideEffects(From))
 return;
 
@@ -1491,6 +1496,7 @@
   else
 diag << From.getVariable();
   diag << From.isNonODRUsed();
+  diag << FixItHint::CreateRemoval(CaptureRange);
 }
 
 ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
@@ -1532,20 +1538,51 @@
 
 // Translate captures.
 auto CurField = Class->field_begin();
+// True if the current capture has a used capture or default before it.
+bool CurHasPreviousCapture = CaptureDefault != LCD_None;
+SourceLocation PrevCaptureLoc = CurHasPreviousCapture ?
+CaptureDefaultLoc : IntroducerRange.getBegin();
+
 for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I, ++CurField) {
   const Capture  = LSI->Captures[I];
+
   assert(!From.isBlockCapture() && "Cannot capture __block variables");
   bool IsImplicit = I >= LSI->NumExplicitCaptures;
 
+  // Use source ranges of explicit captures for fixits where available.
+  SourceRange 

[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-13 Thread Andrew Comminos via Phabricator via cfe-commits
acomminos updated this revision to Diff 155428.
acomminos marked 2 inline comments as done.
acomminos added a comment.

Thanks! Updated to be more explicit about location names, add more tests for 
VLA and *this captures, and fix an issue with VLA range captures invalidating 
the capture range tracking.


Repository:
  rC Clang

https://reviews.llvm.org/D48845

Files:
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaLambda.cpp
  test/FixIt/fixit-unused-lambda-capture.cpp

Index: test/FixIt/fixit-unused-lambda-capture.cpp
===
--- /dev/null
+++ test/FixIt/fixit-unused-lambda-capture.cpp
@@ -0,0 +1,88 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -fsyntax-only -Wunused-lambda-capture -Wno-unused-value -std=c++1z -fixit %t
+// RUN: grep -v CHECK %t | FileCheck %s
+
+void test() {
+  int i = 0;
+  int j = 0;
+  int k = 0;
+  int c = 10;
+  int a[c];
+
+  [i,j] { return i; };
+  // CHECK: [i] { return i; };
+  [i,j] { return j; };
+  // CHECK: [j] { return j; };
+  [,j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,] { return j; };
+  // CHECK: [j] { return j; };
+  [i,j,k] {};
+  // CHECK: [] {};
+  [i,j,k] { return i + j; };
+  // CHECK: [i,j] { return i + j; };
+  [i,j,k] { return j + k; };
+  // CHECK: [j,k] { return j + k; };
+  [i,j,k] { return i + k; };
+  // CHECK: [i,k] { return i + k; };
+  [i,j,k] { return i + j + k; };
+  // CHECK: [i,j,k] { return i + j + k; };
+  [&,i] { return k; };
+  // CHECK: [&] { return k; };
+  [=,] { return k; };
+  // CHECK: [=] { return k; };
+  [=,,] { return j; };
+  // CHECK: [=,] { return j; };
+  [=,,] { return i; };
+  // CHECK: [=,] { return i; };
+  [z = i] {};
+  // CHECK: [] {};
+  [i,z = i] { return z; };
+  // CHECK: [z = i] { return z; };
+  [z = i,i] { return z; };
+  // CHECK: [z = i] { return z; };
+  [] {};
+  // CHECK: [] {};
+  [i,] { return i; };
+  // CHECK: [i] { return i; };
+  [,i] { return i; };
+  // CHECK: [i] { return i; };
+
+  #define I_MACRO() i
+  #define I_REF_MACRO() 
+  [I_MACRO()] {};
+  // CHECK: [] {};
+  [I_MACRO(),j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,I_MACRO()] { return j; };
+  // CHECK: [j] { return j; };
+  [I_REF_MACRO(),j] { return j; };
+  // CHECK: [j] { return j; };
+  [j,I_REF_MACRO()] { return j; };
+  // CHECK: [j] { return j; };
+}
+
+class ThisTest {
+  void test() {
+int i = 0;
+
+[this] {};
+// CHECK: [] {};
+[i,this] { return i; };
+// CHECK: [i] { return i; };
+[this,i] { return i; };
+// CHECK: [i] { return i; };
+[*this] {};
+// CHECK: [] {};
+[*this,i] { return i; };
+// CHECK: [i] { return i; };
+[i,*this] { return i; };
+// CHECK: [i] { return i; };
+[*this] { return this; };
+// CHECK: [*this] { return this; };
+[*this,i] { return this; };
+// CHECK: [*this] { return this; };
+[i,*this] { return this; };
+// CHECK: [*this] { return this; };
+  }
+};
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -993,6 +993,8 @@
   CheckCXXThisCapture(C->Loc, /*Explicit=*/true, /*BuildAndDiagnose*/ true,
   /*FunctionScopeIndexToStopAtPtr*/ nullptr,
   C->Kind == LCK_StarThis);
+  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] =
+  SourceRange(C->ExplicitLocStart, C->ExplicitLocEnd);
   continue;
 }
 
@@ -1139,6 +1141,8 @@
TryCapture_ExplicitByVal;
   tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
 }
+LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] =
+SourceRange(C->ExplicitLocStart, C->ExplicitLocEnd);
   }
   finishLambdaExplicitCaptures(LSI);
 
@@ -1478,7 +1482,8 @@
   return false;
 }
 
-void Sema::DiagnoseUnusedLambdaCapture(const Capture ) {
+void Sema::DiagnoseUnusedLambdaCapture(const SourceRange CaptureRange,
+   const Capture ) {
   if (CaptureHasSideEffects(From))
 return;
 
@@ -1491,6 +1496,7 @@
   else
 diag << From.getVariable();
   diag << From.isNonODRUsed();
+  diag << FixItHint::CreateRemoval(CaptureRange);
 }
 
 ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
@@ -1532,18 +1538,50 @@
 
 // Translate captures.
 auto CurField = Class->field_begin();
+// True if the current capture has a used capture or default before it.
+bool CurHasPreviousCapture = CaptureDefault != LCD_None;
+SourceLocation PrevCaptureLoc = CurHasPreviousCapture ?
+CaptureDefaultLoc : IntroducerRange.getBegin();
+
 for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I, ++CurField) {
   const Capture  = LSI->Captures[I];
+
   assert(!From.isBlockCapture() && "Cannot capture __block variables");
   

[libcxx] r337027 - Shot in the dark to fix gcc 4.9 / c++11 build

2018-07-13 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Fri Jul 13 10:24:59 2018
New Revision: 337027

URL: http://llvm.org/viewvc/llvm-project?rev=337027=rev
Log:
Shot in the dark to fix gcc 4.9 / c++11 build


Modified:
libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=337027=337026=337027=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri Jul 13 10:24:59 2018
@@ -1024,10 +1024,10 @@ template  struct __static_asse
 #endif
 
 #ifndef _LIBCPP_CONSTEXPR_IF_NODEBUG
-#if !defined(_LIBCPP_DEBUG) && _LIBCPP_STD_VER >= 14
-#define _LIBCPP_CONSTEXPR_IF_NODEBUG constexpr
-#else
+#if defined(_LIBCPP_DEBUG) || _LIBCPP_HAS_NO_CXX14_CONSTEXPR
 #define _LIBCPP_CONSTEXPR_IF_NODEBUG
+#else
+#define _LIBCPP_CONSTEXPR_IF_NODEBUG constexpr
 #endif
 #endif
 


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


[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-13 Thread JF Bastien via Phabricator via cfe-commits
jfb marked an inline comment as done.
jfb added inline comments.



Comment at: lib/CodeGen/CGBuilder.h:260
+CharUnits::fromQuantity(Offset.getSExtValue(;
+  }
+

efriedma wrote:
> Not sure about the new helper.  We already have CreateStructGEP and 
> CreateConstArrayGEP which do approximately what you want.
It's close to doing what we want, but not quite? It seems like the original 
code would have used them otherwise.

To use them we'd have to:

  - branch on struct / array
- for struct calculate the offset there (which the new helper does)
- for array get the element size

Seems simpler to use GEP2_32 and more fool-proof to (internal to the helper) 
use GEP's own idea of what the offset is, no?


Repository:
  rC Clang

https://reviews.llvm.org/D49209



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


[PATCH] D48981: Add caching when looking up coroutine_traits

2018-07-13 Thread Tanoy Sinha via Phabricator via cfe-commits
tks2103 added a comment.

ping @modocache @GorNishanov


Repository:
  rC Clang

https://reviews.llvm.org/D48981



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


[PATCH] D49209: CodeGen: specify alignment for automatic variable initialization

2018-07-13 Thread JF Bastien via Phabricator via cfe-commits
jfb updated this revision to Diff 155424.
jfb added a comment.

- Simplify CreateStore.


Repository:
  rC Clang

https://reviews.llvm.org/D49209

Files:
  lib/CodeGen/CGBuilder.h
  lib/CodeGen/CGDecl.cpp
  test/CodeGen/init.c
  test/CodeGenOpenCL/partial_initializer.cl

Index: test/CodeGenOpenCL/partial_initializer.cl
===
--- test/CodeGenOpenCL/partial_initializer.cl
+++ test/CodeGenOpenCL/partial_initializer.cl
@@ -38,11 +38,11 @@
   // CHECK: %[[v0:.*]] = bitcast [6 x [6 x float]]* %A to i8*
   // CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %[[v0]], i8 0, i32 144, i1 false)
   // CHECK: %[[v1:.*]] = bitcast i8* %[[v0]] to [6 x [6 x float]]*
-  // CHECK: %[[v2:.*]] = getelementptr [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
-  // CHECK: %[[v3:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
-  // CHECK: store float 1.00e+00, float* %[[v3]]
-  // CHECK: %[[v4:.*]] = getelementptr [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
-  // CHECK: store float 2.00e+00, float* %[[v4]]
+  // CHECK: %[[v2:.*]] = getelementptr inbounds [6 x [6 x float]], [6 x [6 x float]]* %[[v1]], i32 0, i32 0
+  // CHECK: %[[v3:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 0
+  // CHECK: store float 1.00e+00, float* %[[v3]], align 4
+  // CHECK: %[[v4:.*]] = getelementptr inbounds [6 x float], [6 x float]* %[[v2]], i32 0, i32 1
+  // CHECK: store float 2.00e+00, float* %[[v4]], align 4
   float A[6][6]  = {1.0f, 2.0f};
 
   // CHECK: %[[v5:.*]] = bitcast %struct.StrucTy* %S to i8*
Index: test/CodeGen/init.c
===
--- test/CodeGen/init.c
+++ test/CodeGen/init.c
@@ -86,25 +86,25 @@
 char test8(int X) {
   char str[10] = "abc"; // tail should be memset.
   return str[X];
-// CHECK: @test8(
-// CHECK: call void @llvm.memset
-// CHECK: store i8 97
-// CHECK: store i8 98
-// CHECK: store i8 99
-// CHECK-NOT: getelementptr
-// CHECK: load
+  // CHECK-LABEL: @test8(
+  // CHECK: call void @llvm.memset
+  // CHECK: store i8 97, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 98, i8* %{{[0-9]*}}, align 1
+  // CHECK: store i8 99, i8* %{{[0-9]*}}, align 1
+  // CHECK-NOT: getelementptr
+  // CHECK: load
 }
 
 void bar(void*);
 
 // PR279
-int test9(int X) {
+void test9(int X) {
   int Arr[100] = { X }; // Should use memset
   bar(Arr);
-// CHECK: @test9
-// CHECK: call void @llvm.memset
-// CHECK-NOT: store i32 0
-// CHECK: call void @bar
+  // CHECK-LABEL: @test9(
+  // CHECK: call void @llvm.memset
+  // CHECK-NOT: store i32 0
+  // CHECK: call void @bar
 }
 
 struct a {
@@ -115,11 +115,11 @@
   struct a a,b,c,d,e,f,g;
 };
 
-int test10(int X) {
+void test10(int X) {
   struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 };
   bar();
 
-  // CHECK: @test10
+  // CHECK-LABEL: @test10(
   // CHECK: call void @llvm.memset
   // CHECK-NOT: store i32 0
   // CHECK: call void @bar
@@ -132,11 +132,11 @@
 };
 void test11(struct test11S *P) {
   *P = (struct test11S) { .A = { [0 ... 3] = 4 } };
-  // CHECK: @test11
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
-  // CHECK: store i32 4
+  // CHECK-LABEL: @test11(
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
+  // CHECK: store i32 4, i32* %{{.*}}, align 4
   // CHECK: ret void
 }
 
@@ -151,11 +151,11 @@
 void test13(int x) {
   struct X { int a; int b : 10; int c; };
   struct X y = {.c = x};
-  // CHECK: @test13
+  // CHECK-LABEL: @test13(
   // CHECK: and i16 {{.*}}, -1024
 }
 
-// CHECK-LABEL: @PR20473
+// CHECK-LABEL: @PR20473(
 void PR20473() {
   // CHECK: memcpy{{.*}}getelementptr inbounds ([2 x i8], [2 x i8]* @
   bar((char[2]) {""});
@@ -168,9 +168,9 @@
 struct S14 { int a[16]; };
 
 void test14(struct S14 *s14) {
-// CHECK-LABEL: @test14
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
-// CHECK-NOT: store
-// CHECK: ret void
+  // CHECK-LABEL: @test14(
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false)
+  // CHECK-NOT: store
+  // CHECK: ret void
   *s14 = (struct S14) { { [5 ... 11] = 17 } };
 }
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -888,15 +888,17 @@
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// stores that would be required.
-static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc,
- bool isVolatile, CGBuilderTy ) {
+static void emitStoresForInitAfterMemset(CodeGenModule ,
+ 

[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.

2018-07-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: include/clang/AST/ASTContext.h:1327-1329
+  QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr,
+   SourceLocation AttrLoc,
+   VectorType::VectorKind VecKind) const;

aaron.ballman wrote:
> The formatting looks off here. Did clang-format do this?
It DID, then I renamed it and forgot to rerun :/



Comment at: include/clang/AST/Type.h:3105
+public:
+  Expr *getSizeExpr() const { return SizeExpr; }
+  QualType getElementType() const { return ElementType; }

aaron.ballman wrote:
> Can this return `const Expr *` and have a non-const overload to return the 
> non-const `Expr *`?
Done, but unfortunately, TypeLoc visitation (RecursiveASTVisitor) lacks const 
correctness in a bunch of places so a cast was required there :/  Additionally, 
TreeTransform has similar issues, so a const-cast was required as well.  Both 
end up being a bit of a cleanup, perhaps more than I can tackle at the moment.



Comment at: lib/AST/ItaniumMangle.cpp:3007-3008
+void CXXNameMangler::mangleNeonVectorType(const DependentVectorType *T) {
+  llvm_unreachable(
+  "Mangling for Dependent Sized Neon Vector not yet implemented");
+}

aaron.ballman wrote:
> This seems reachable.
I don't think it IS actually (since we never create one of these), but point 
made :)


https://reviews.llvm.org/D49045



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


[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.

2018-07-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 155419.
erichkeane marked 12 inline comments as done.

https://reviews.llvm.org/D49045

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Type.h
  include/clang/AST/TypeLoc.h
  include/clang/AST/TypeNodes.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTStructuralEquivalence.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaType.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/SemaCXX/vector.cpp
  tools/libclang/CIndex.cpp

Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -455,6 +455,14 @@
   Code = TYPE_DEPENDENT_SIZED_EXT_VECTOR;
 }
 
+void ASTTypeWriter::VisitDependentVectorType(const DependentVectorType *T) {
+  Record.AddTypeRef(T->getElementType());
+  Record.AddStmt(const_cast(T->getSizeExpr()));
+  Record.AddSourceLocation(T->getAttributeLoc());
+  Record.push_back(T->getVectorKind());
+  Code = TYPE_DEPENDENT_SIZED_VECTOR;
+}
+
 void
 ASTTypeWriter::VisitDependentAddressSpaceType(
 const DependentAddressSpaceType *T) {
@@ -676,6 +684,11 @@
   Record.AddSourceLocation(TL.getNameLoc());
 }
 
+void TypeLocWriter::VisitDependentVectorTypeLoc(
+DependentVectorTypeLoc TL) {
+  Record.AddSourceLocation(TL.getNameLoc());
+}
+
 void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
   Record.AddSourceLocation(TL.getNameLoc());
 }
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -6369,6 +6369,17 @@
 return Context.getPipeType(ElementType, ReadOnly);
   }
 
+  case TYPE_DEPENDENT_SIZED_VECTOR: {
+unsigned Idx = 0;
+QualType ElementType = readType(*Loc.F, Record, Idx);
+Expr *SizeExpr = ReadExpr(*Loc.F);
+SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx);
+unsigned VecKind = Record[Idx];
+
+return Context.getDependentVectorType(ElementType, SizeExpr, AttrLoc,
+   (VectorType::VectorKind)VecKind);
+  }
+
   case TYPE_DEPENDENT_SIZED_EXT_VECTOR: {
 unsigned Idx = 0;
 
@@ -6549,6 +6560,11 @@
   TL.setNameLoc(ReadSourceLocation());
 }
 
+void TypeLocReader::VisitDependentVectorTypeLoc(
+DependentVectorTypeLoc TL) {
+  TL.setNameLoc(ReadSourceLocation());
+}
+
 void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
   TL.setNameLoc(ReadSourceLocation());
 }
Index: lib/AST/ASTStructuralEquivalence.cpp
===
--- lib/AST/ASTStructuralEquivalence.cpp
+++ lib/AST/ASTStructuralEquivalence.cpp
@@ -51,7 +51,7 @@
 
 /// Determine structural equivalence of two expressions.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext ,
- Expr *E1, Expr *E2) {
+ const Expr *E1, const Expr *E2) {
   if (!E1 || !E2)
 return E1 == E2;
 
@@ -408,6 +408,20 @@
 break;
   }
 
+  case Type::DependentVector: {
+const auto *Vec1 = cast(T1);
+const auto *Vec2 = cast(T2);
+if (Vec1->getVectorKind() != Vec2->getVectorKind())
+  return false;
+if (!IsStructurallyEquivalent(Context, Vec1->getSizeExpr(),
+  Vec2->getSizeExpr()))
+  return false;
+if (!IsStructurallyEquivalent(Context, Vec1->getElementType(),
+  Vec2->getElementType()))
+  return false;
+break;
+  }
+
   case Type::Vector:
   case Type::ExtVector: {
 const auto *Vec1 = cast(T1);
Index: lib/AST/ItaniumMangle.cpp
===
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -539,7 +539,9 @@
   void mangleBareFunctionType(const FunctionProtoType *T, bool MangleReturnType,
   const FunctionDecl *FD = nullptr);
   void mangleNeonVectorType(const VectorType *T);
+  void mangleNeonVectorType(const DependentVectorType *T);
   void mangleAArch64NeonVectorType(const VectorType *T);
+  void mangleAArch64NeonVectorType(const DependentVectorType *T);
 
   void mangleIntegerLiteral(QualType T, const llvm::APSInt );
   void mangleMemberExprBase(const Expr *base, bool isArrow);
@@ -1930,6 +1932,7 @@
   case Type::VariableArray:
   case Type::DependentSizedArray:
   case Type::DependentAddressSpace:
+  case Type::DependentVector:
   case Type::DependentSizedExtVector:
   case Type::Vector:
   case Type::ExtVector:
@@ -3000,6 +3003,14 @@
   Out << BaseName << EltName;
 }
 
+void CXXNameMangler::mangleNeonVectorType(const 

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-13 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:662
+def note_suspicious_sizeof_memset_silence : Note<
+  "%select{parenthesize the third argument|cast the second argument to 'int'}0 
to silence">;
+

aaron.ballman wrote:
> erik.pilkington wrote:
> > Quuxplusone wrote:
> > > If it were my codebase, I'd rather see a cast to `(unsigned char)` than a 
> > > cast to `(int)`. (The second argument to memset is supposed to be a 
> > > single byte.) Why did you pick `(int)` specifically?
> > I chose `int` because that's the actual type of the second parameter to 
> > `memset`, it just gets casted down to `unsigned char` internally. FWIW, 
> > either type will suppress the warning. I'm fine with recommending `unsigned 
> > char` if you have a strong preference for it.
> My preference is for `int` as well.
Personally I have a strong preference for "any 8-bit type" — the important 
thing is that it needs to indicate to the reader that it's intended to be the 
single-byte value that `memset` expects. I even want my compiler to diagnose 
`memset(x, 0x1234, z)` as a bug!
But I'm not inclined to fight hard, because this is all about the mechanism of 
*suppressing* of the warning, and I don't imagine we'll see too many people 
trying to suppress it.


https://reviews.llvm.org/D49112



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


[libcxx] r337019 - Make internal class __wrap_iter constexpr when not using libc++'s debugging mode. Introduce a new macro _LIBCPP_CONSTEXPR_IF_NODEBUG to mark this.

2018-07-13 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Fri Jul 13 09:35:26 2018
New Revision: 337019

URL: http://llvm.org/viewvc/llvm-project?rev=337019=rev
Log:
Make internal class __wrap_iter constexpr when not using libc++'s debugging 
mode. Introduce a new macro _LIBCPP_CONSTEXPR_IF_NODEBUG to mark this.

Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/algorithm
libcxx/trunk/include/iterator

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=337019=337018=337019=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri Jul 13 09:35:26 2018
@@ -1023,6 +1023,14 @@ template  struct __static_asse
 #  define _LIBCPP_EXPLICIT_MOVE(x) (x)
 #endif
 
+#ifndef _LIBCPP_CONSTEXPR_IF_NODEBUG
+#if !defined(_LIBCPP_DEBUG) && _LIBCPP_STD_VER >= 14
+#define _LIBCPP_CONSTEXPR_IF_NODEBUG constexpr
+#else
+#define _LIBCPP_CONSTEXPR_IF_NODEBUG
+#endif
+#endif
+
 #ifndef _LIBCPP_HAS_NO_ASAN
 _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
   const void *, const void *, const void *, const void *);

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=337019=337018=337019=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Fri Jul 13 09:35:26 2018
@@ -1708,7 +1708,7 @@ __unwrap_iter(move_iterator<_Tp*> __i)
 #if _LIBCPP_DEBUG_LEVEL < 2
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 typename enable_if
 <
 is_trivially_copy_assignable<_Tp>::value,
@@ -1722,7 +1722,7 @@ __unwrap_iter(__wrap_iter<_Tp*> __i)
 #else
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 typename enable_if
 <
 is_trivially_copy_assignable<_Tp>::value,

Modified: libcxx/trunk/include/iterator
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=337019=337018=337019=diff
==
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Fri Jul 13 09:35:26 2018
@@ -1217,38 +1217,38 @@ make_move_iterator(_Iter __i)
 template  class __wrap_iter;
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 bool
 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) 
_NOEXCEPT_DEBUG;
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 bool
 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) 
_NOEXCEPT_DEBUG;
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 bool
 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) 
_NOEXCEPT_DEBUG;
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 bool
 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) 
_NOEXCEPT_DEBUG;
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 bool
 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) 
_NOEXCEPT_DEBUG;
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 bool
 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) 
_NOEXCEPT_DEBUG;
 
 #ifndef _LIBCPP_CXX03_LANG
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 auto
 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) 
_NOEXCEPT_DEBUG
 -> decltype(__x.base() - __y.base());
@@ -1260,7 +1260,7 @@ operator-(const __wrap_iter<_Iter1>&, co
 #endif
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 __wrap_iter<_Iter>
 operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) 
_NOEXCEPT_DEBUG;
 
@@ -1272,7 +1272,7 @@ template  _B2 _LIB
 #if _LIBCPP_DEBUG_LEVEL < 2
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 typename enable_if
 <
 is_trivially_copy_assignable<_Tp>::value,
@@ -1283,7 +1283,7 @@ __unwrap_iter(__wrap_iter<_Tp*>);
 #else
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
 typename enable_if
 <
 is_trivially_copy_assignable<_Tp>::value,
@@ -1306,7 +1306,7 @@ public:
 private:
 iterator_type __i;
 public:
-_LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT_DEBUG
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() 
_NOEXCEPT_DEBUG
 #if _LIBCPP_STD_VER > 11
 : __i{}
 #endif
@@ -1315,22 +1315,23 @@ public:
 __get_db()->__insert_i(this);
 #endif
 }
-template  

[PATCH] D49303: [CodeGen][ObjC] Treat non-escaping blocks as global blocks to make copy/dispose a no-op

2018-07-13 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added a reviewer: rjmccall.
Herald added a subscriber: dexonsmith.

Copying or disposing of a non-escaping block can be a no-op. A non-escaping 
block on the stack doesn't have to be copied to the heap as we know it won't be 
called after its lifetime ends.

rdar://problem/39352313


Repository:
  rC Clang

https://reviews.llvm.org/D49303

Files:
  docs/Block-ABI-Apple.rst
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGBlocks.h
  test/CodeGenObjC/noescape.m

Index: test/CodeGenObjC/noescape.m
===
--- test/CodeGenObjC/noescape.m
+++ test/CodeGenObjC/noescape.m
@@ -12,6 +12,12 @@
 void noescapeFunc2(__attribute__((noescape)) id);
 void noescapeFunc3(__attribute__((noescape)) union U);
 
+// Block descriptors of non-escaping blocks don't need pointers to copy/dispose
+// helper functions.
+
+// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
+// CHECK: @[[BLOCK_DESCIPTOR_TMP_2:.*]] = internal constant { i64, i64, i8*, i64 } { i64 0, i64 40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
+
 // CHECK-LABEL: define void @test0(
 // CHECK: call void @noescapeFunc0({{.*}}, {{.*}} nocapture {{.*}})
 // CHECK: declare void @noescapeFunc0(i8*, {{.*}} nocapture)
@@ -69,3 +75,26 @@
   ^(int *__attribute__((noescape)) p0){}(p);
   b(p);
 }
+
+// If the block is non-escaping, set the BLOCK_IS_NOESCAPE and BLOCK_IS_GLOBAL
+// bits of field 'flags' and set the 'isa' field to 'NSConcreteGlobalBlock'.
+
+// CHECK-LABEL: define void @test6(
+// CHECK: %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, align 8
+// CHECK: %[[BLOCK_ISA:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]], i32 0, i32 0
+// CHECK: store i8* bitcast (i8** @_NSConcreteGlobalBlock to i8*), i8** %[[BLOCK_ISA]], align 8
+// CHECK: %[[BLOCK_FLAGS:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]], i32 0, i32 1
+// CHECK: store i32 -796917760, i32* %[[BLOCK_FLAGS]], align 8
+// CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]], i32 0, i32 4
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i64 }* @[[BLOCK_DESCIPTOR_TMP_2]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8
+
+// Non-escaping blocks don't need copy/dispose helper functions.
+
+// CHECK-NOT: define internal void @__copy_helper_block_
+// CHECK-NOT: define internal void @__destroy_helper_block_
+
+void func(id);
+
+void test6(id a, id b) {
+  noescapeFunc0(a, ^{ func(b); });
+}
Index: lib/CodeGen/CGBlocks.h
===
--- lib/CodeGen/CGBlocks.h
+++ lib/CodeGen/CGBlocks.h
@@ -54,6 +54,7 @@
 };
 
 enum BlockLiteralFlags {
+  BLOCK_IS_NOESCAPE  =  (1 << 23),
   BLOCK_HAS_COPY_DISPOSE =  (1 << 25),
   BLOCK_HAS_CXX_OBJ =   (1 << 26),
   BLOCK_IS_GLOBAL = (1 << 28),
Index: lib/CodeGen/CGBlocks.cpp
===
--- lib/CodeGen/CGBlocks.cpp
+++ lib/CodeGen/CGBlocks.cpp
@@ -159,6 +159,7 @@
 
 /// These are the flags (with corresponding bit number) that the
 /// compiler is actually supposed to know about.
+///  23. BLOCK_IS_NOESCAPE - indicates that the block is non-escaping
 ///  25. BLOCK_HAS_COPY_DISPOSE - indicates that the block
 ///   descriptor provides copy and dispose helper functions
 ///  26. BLOCK_HAS_CXX_OBJ - indicates that there's a captured
@@ -496,6 +497,9 @@
 BlockLayoutChunk(align, size, lifetime, , llvmType, VT));
   }
 
+  if (info.getBlockDecl()->doesNotEscape())
+info.NeedsCopyDispose = false;
+
   // If that was everything, we're done here.
   if (layout.empty()) {
 info.StructureType =
@@ -778,8 +782,14 @@
   llvm::Constant *descriptor;
   BlockFlags flags;
   if (!IsOpenCL) {
-isa = llvm::ConstantExpr::getBitCast(CGM.getNSConcreteStackBlock(),
- VoidPtrTy);
+// If the block is non-escaping, set field 'isa 'to NSConcreteGlobalBlock
+// and set the BLOCK_IS_GLOBAL bit of field 'flags' so that copying and
+// disposing of blocks become no-ops.
+
+llvm::Constant *blockISA = blockInfo.getBlockDecl()->doesNotEscape()
+   ? CGM.getNSConcreteGlobalBlock()
+   : CGM.getNSConcreteStackBlock();
+isa = llvm::ConstantExpr::getBitCast(blockISA, VoidPtrTy);
 
 // Build the block descriptor.
 descriptor = buildBlockDescriptor(CGM, blockInfo);
@@ -794,6 +804,8 @@
   flags 

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

2018-07-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: libcxx/include/map:43
 typedef std::reverse_iteratorconst_reverse_iterator;
+typedef unspecified  node_type;
+typedef INSERT_RETURN_TYPE  insert_return_type;

You are missing `// since C++17` comments here and elsewhere.


https://reviews.llvm.org/D46845



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


[PATCH] D38075: Fix PR34668 - P0704R1 implementation is too permissive

2018-07-13 Thread Nicolas Lesser via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC337017: Fix PR34668 - P0704R1 implementation is too 
permissive (authored by Rakete, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D38075?vs=155410=155412#toc

Repository:
  rC Clang

https://reviews.llvm.org/D38075

Files:
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp


Index: test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
===
--- test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
+++ test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
@@ -3,12 +3,15 @@
 struct X {
   void ref() & {} // expected-note{{'ref' declared here}}
   void cref() const& {}
+  void cvref() const volatile & {} // expected-note{{'cvref' declared here}}
 };
 
 void test() {
   X{}.ref(); // expected-error{{'this' argument to member function 'ref' is an 
rvalue, but function has non-const lvalue ref-qualifier}}
   X{}.cref(); // expected-no-error
+  X{}.cvref(); // expected-error{{'this' argument to member function 'cvref' 
is an rvalue, but function has non-const lvalue ref-qualifier}}
 
   (X{}.*::ref)(); // expected-error-re{{pointer-to-member function type 
'void (X::*)() {{.*}}&' can only be called on an lvalue}}
   (X{}.*::cref)(); // expected-no-error
+  (X{}.*::cvref)(); // expected-error-re{{pointer-to-member function type 
'void (X::*)() {{.*}}&' can only be called on an lvalue}}
 }
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -5472,8 +5472,9 @@
 
 case RQ_LValue:
   if (!isIndirect && !LHS.get()->Classify(Context).isLValue()) {
-// C++2a allows functions with ref-qualifier & if they are also 
'const'.
-if (Proto->isConst())
+// C++2a allows functions with ref-qualifier & if their 
cv-qualifier-seq
+// is (exactly) 'const'.
+if (Proto->isConst() && !Proto->isVolatile())
   Diag(Loc, getLangOpts().CPlusPlus2a
 ? 
diag::warn_cxx17_compat_pointer_to_const_ref_member_on_rvalue
 : diag::ext_pointer_to_const_ref_member_on_rvalue);


Index: test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
===
--- test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
+++ test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
@@ -3,12 +3,15 @@
 struct X {
   void ref() & {} // expected-note{{'ref' declared here}}
   void cref() const& {}
+  void cvref() const volatile & {} // expected-note{{'cvref' declared here}}
 };
 
 void test() {
   X{}.ref(); // expected-error{{'this' argument to member function 'ref' is an rvalue, but function has non-const lvalue ref-qualifier}}
   X{}.cref(); // expected-no-error
+  X{}.cvref(); // expected-error{{'this' argument to member function 'cvref' is an rvalue, but function has non-const lvalue ref-qualifier}}
 
   (X{}.*::ref)(); // expected-error-re{{pointer-to-member function type 'void (X::*)() {{.*}}&' can only be called on an lvalue}}
   (X{}.*::cref)(); // expected-no-error
+  (X{}.*::cvref)(); // expected-error-re{{pointer-to-member function type 'void (X::*)() {{.*}}&' can only be called on an lvalue}}
 }
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -5472,8 +5472,9 @@
 
 case RQ_LValue:
   if (!isIndirect && !LHS.get()->Classify(Context).isLValue()) {
-// C++2a allows functions with ref-qualifier & if they are also 'const'.
-if (Proto->isConst())
+// C++2a allows functions with ref-qualifier & if their cv-qualifier-seq
+// is (exactly) 'const'.
+if (Proto->isConst() && !Proto->isVolatile())
   Diag(Loc, getLangOpts().CPlusPlus2a
 ? diag::warn_cxx17_compat_pointer_to_const_ref_member_on_rvalue
 : diag::ext_pointer_to_const_ref_member_on_rvalue);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r337017 - Fix PR34668 - P0704R1 implementation is too permissive

2018-07-13 Thread Nicolas Lesser via cfe-commits
Author: rakete
Date: Fri Jul 13 09:27:45 2018
New Revision: 337017

URL: http://llvm.org/viewvc/llvm-project?rev=337017=rev
Log:
Fix PR34668 - P0704R1 implementation is too permissive

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

Pretty straightforward.

Reviewers: rsmith, Rakete

Reviewed By: Rakete

Subscribers: Rakete, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=337017=337016=337017=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Jul 13 09:27:45 2018
@@ -5472,8 +5472,9 @@ QualType Sema::CheckPointerToMemberOpera
 
 case RQ_LValue:
   if (!isIndirect && !LHS.get()->Classify(Context).isLValue()) {
-// C++2a allows functions with ref-qualifier & if they are also 
'const'.
-if (Proto->isConst())
+// C++2a allows functions with ref-qualifier & if their 
cv-qualifier-seq
+// is (exactly) 'const'.
+if (Proto->isConst() && !Proto->isVolatile())
   Diag(Loc, getLangOpts().CPlusPlus2a
 ? 
diag::warn_cxx17_compat_pointer_to_const_ref_member_on_rvalue
 : diag::ext_pointer_to_const_ref_member_on_rvalue);

Modified: cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp?rev=337017=337016=337017=diff
==
--- cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp Fri Jul 13 
09:27:45 2018
@@ -3,12 +3,15 @@
 struct X {
   void ref() & {} // expected-note{{'ref' declared here}}
   void cref() const& {}
+  void cvref() const volatile & {} // expected-note{{'cvref' declared here}}
 };
 
 void test() {
   X{}.ref(); // expected-error{{'this' argument to member function 'ref' is an 
rvalue, but function has non-const lvalue ref-qualifier}}
   X{}.cref(); // expected-no-error
+  X{}.cvref(); // expected-error{{'this' argument to member function 'cvref' 
is an rvalue, but function has non-const lvalue ref-qualifier}}
 
   (X{}.*::ref)(); // expected-error-re{{pointer-to-member function type 
'void (X::*)() {{.*}}&' can only be called on an lvalue}}
   (X{}.*::cref)(); // expected-no-error
+  (X{}.*::cvref)(); // expected-error-re{{pointer-to-member function type 
'void (X::*)() {{.*}}&' can only be called on an lvalue}}
 }


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


[PATCH] D38075: Fix PR34668 - P0704R1 implementation is too permissive

2018-07-13 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete updated this revision to Diff 155410.
Rakete added a comment.

Change error message to reflect the new update error message since the last 
revision.


Repository:
  rC Clang

https://reviews.llvm.org/D38075

Files:
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp


Index: test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
===
--- test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
+++ test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
@@ -3,12 +3,15 @@
 struct X {
   void ref() & {} // expected-note{{'ref' declared here}}
   void cref() const& {}
+  void cvref() const volatile & {} // expected-note{{'cvref' declared here}}
 };
 
 void test() {
   X{}.ref(); // expected-error{{'this' argument to member function 'ref' is an 
rvalue, but function has non-const lvalue ref-qualifier}}
   X{}.cref(); // expected-no-error
+  X{}.cvref(); // expected-error{{'this' argument to member function 'cvref' 
is an rvalue, but function has non-const lvalue ref-qualifier}}
 
   (X{}.*::ref)(); // expected-error-re{{pointer-to-member function type 
'void (X::*)() {{.*}}&' can only be called on an lvalue}}
   (X{}.*::cref)(); // expected-no-error
+  (X{}.*::cvref)(); // expected-error-re{{pointer-to-member function type 
'void (X::*)() {{.*}}&' can only be called on an lvalue}}
 }
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -5472,8 +5472,9 @@
 
 case RQ_LValue:
   if (!isIndirect && !LHS.get()->Classify(Context).isLValue()) {
-// C++2a allows functions with ref-qualifier & if they are also 
'const'.
-if (Proto->isConst())
+// C++2a allows functions with ref-qualifier & if their 
cv-qualifier-seq
+// is (exactly) 'const'.
+if (Proto->isConst() && !Proto->isVolatile())
   Diag(Loc, getLangOpts().CPlusPlus2a
 ? 
diag::warn_cxx17_compat_pointer_to_const_ref_member_on_rvalue
 : diag::ext_pointer_to_const_ref_member_on_rvalue);


Index: test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
===
--- test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
+++ test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
@@ -3,12 +3,15 @@
 struct X {
   void ref() & {} // expected-note{{'ref' declared here}}
   void cref() const& {}
+  void cvref() const volatile & {} // expected-note{{'cvref' declared here}}
 };
 
 void test() {
   X{}.ref(); // expected-error{{'this' argument to member function 'ref' is an rvalue, but function has non-const lvalue ref-qualifier}}
   X{}.cref(); // expected-no-error
+  X{}.cvref(); // expected-error{{'this' argument to member function 'cvref' is an rvalue, but function has non-const lvalue ref-qualifier}}
 
   (X{}.*::ref)(); // expected-error-re{{pointer-to-member function type 'void (X::*)() {{.*}}&' can only be called on an lvalue}}
   (X{}.*::cref)(); // expected-no-error
+  (X{}.*::cvref)(); // expected-error-re{{pointer-to-member function type 'void (X::*)() {{.*}}&' can only be called on an lvalue}}
 }
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -5472,8 +5472,9 @@
 
 case RQ_LValue:
   if (!isIndirect && !LHS.get()->Classify(Context).isLValue()) {
-// C++2a allows functions with ref-qualifier & if they are also 'const'.
-if (Proto->isConst())
+// C++2a allows functions with ref-qualifier & if their cv-qualifier-seq
+// is (exactly) 'const'.
+if (Proto->isConst() && !Proto->isVolatile())
   Diag(Loc, getLangOpts().CPlusPlus2a
 ? diag::warn_cxx17_compat_pointer_to_const_ref_member_on_rvalue
 : diag::ext_pointer_to_const_ref_member_on_rvalue);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r337016 - Fix a couple of 'unused variable' warnings in a vector test. NFC.

2018-07-13 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Fri Jul 13 09:26:16 2018
New Revision: 337016

URL: http://llvm.org/viewvc/llvm-project?rev=337016=rev
Log:
Fix a couple of 'unused variable' warnings in a vector test. NFC.


Modified:
libcxx/trunk/test/std/containers/sequences/vector/iterators.pass.cpp

Modified: libcxx/trunk/test/std/containers/sequences/vector/iterators.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/iterators.pass.cpp?rev=337016=337015=337016=diff
==
--- libcxx/trunk/test/std/containers/sequences/vector/iterators.pass.cpp 
(original)
+++ libcxx/trunk/test/std/containers/sequences/vector/iterators.pass.cpp Fri 
Jul 13 09:26:16 2018
@@ -77,6 +77,8 @@ int main()
 typedef std::vector C;
 C::iterator i;
 C::const_iterator j;
+(void) i;
+(void) j;
 }
 #if TEST_STD_VER >= 11
 {
@@ -125,6 +127,8 @@ int main()
 typedef std::vector> C;
 C::iterator i;
 C::const_iterator j;
+(void) i;
+(void) j;
 }
 {
 typedef A T;


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


[PATCH] D49268: [clang-doc] Create a script to generate tests

2018-07-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri accepted this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

I have no further comments here.
I assume this works as intended; if not, since it is mainly a developer-only 
tool, further issues could be addressed later on.

Maybe wait a bit just in case someone else wants to comment, too.


https://reviews.llvm.org/D49268



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


[PATCH] D49302: [AST] Various micro-optimizations in CXXInheritance

2018-07-13 Thread Bruno Ricci via Phabricator via cfe-commits
bricci created this revision.
bricci added reviewers: arphaman, bkramer, rsmith.
bricci added a project: clang.
Herald added a subscriber: cfe-commits.

1. Pack std::pair in CXXBasePaths::ClassSubobjects.
2. Use a SmallPtrSet instead of a SmallDenseSet for 
CXXBasePaths::VisitedDependentRecords.
3. Reorder some members of CXXBasePaths to save 8 bytes.
4. Use a SmallSetVector instead of a SetVector in 
CXXBasePaths::ComputeDeclsFound to avoid some allocations.

This speeds up an -fsyntax-only on all of Boost by approx 0.15%,
mainly by speeding up CXXBasePaths::lookupInBases by
approx 10%. No functional changes.


Repository:
  rC Clang

https://reviews.llvm.org/D49302

Files:
  include/clang/AST/CXXInheritance.h
  lib/AST/CXXInheritance.cpp

Index: lib/AST/CXXInheritance.cpp
===
--- lib/AST/CXXInheritance.cpp
+++ lib/AST/CXXInheritance.cpp
@@ -40,7 +40,7 @@
   assert(NumDeclsFound == 0 && !DeclsFound &&
  "Already computed the set of declarations");
 
-  llvm::SetVector> Decls;
+  llvm::SmallSetVector Decls;
   for (paths_iterator Path = begin(), PathEnd = end(); Path != PathEnd; ++Path)
 Decls.insert(Path->Decls.front());
 
@@ -63,8 +63,8 @@
 /// an unqualified, canonical class type.
 bool CXXBasePaths::isAmbiguous(CanQualType BaseType) {
   BaseType = BaseType.getUnqualifiedType();
-  std::pair& Subobjects = ClassSubobjects[BaseType];
-  return Subobjects.second + (Subobjects.first? 1 : 0) > 1;
+  IsVirtBaseAndNumberNonVirtBases Subobjects = ClassSubobjects[BaseType];
+  return Subobjects.NumberOfNonVirtBases + (Subobjects.IsVirtBase? 1 : 0) > 1;
 }
 
 /// clear - Clear out all prior path information.
@@ -217,30 +217,31 @@
 
 // Determine whether we need to visit this base class at all,
 // updating the count of subobjects appropriately.
-std::pair& Subobjects = ClassSubobjects[BaseType];
+IsVirtBaseAndNumberNonVirtBases  = ClassSubobjects[BaseType];
 bool VisitBase = true;
 bool SetVirtual = false;
 if (BaseSpec.isVirtual()) {
-  VisitBase = !Subobjects.first;
-  Subobjects.first = true;
+  VisitBase = !Subobjects.IsVirtBase;
+  Subobjects.IsVirtBase = true;
   if (isDetectingVirtual() && DetectedVirtual == nullptr) {
 // If this is the first virtual we find, remember it. If it turns out
 // there is no base path here, we'll reset it later.
 DetectedVirtual = BaseType->getAs();
 SetVirtual = true;
   }
-} else
-  ++Subobjects.second;
-
+}
+else {
+  ++Subobjects.NumberOfNonVirtBases;
+}
 if (isRecordingPaths()) {
   // Add this base specifier to the current path.
   CXXBasePathElement Element;
   Element.Base = 
   Element.Class = Record;
   if (BaseSpec.isVirtual())
 Element.SubobjectNumber = 0;
   else
-Element.SubobjectNumber = Subobjects.second;
+Element.SubobjectNumber = Subobjects.NumberOfNonVirtBases;
   ScratchPath.push_back(Element);
 
   // Calculate the "top-down" access to this base class.
Index: include/clang/AST/CXXInheritance.h
===
--- include/clang/AST/CXXInheritance.h
+++ include/clang/AST/CXXInheritance.h
@@ -127,16 +127,34 @@
   std::list Paths;
   
   /// ClassSubobjects - Records the class subobjects for each class
-  /// type that we've seen. The first element in the pair says
+  /// type that we've seen. The first element IsVirtBase says
   /// whether we found a path to a virtual base for that class type,
-  /// while the element contains the number of non-virtual base
+  /// while NumberOfNonVirtBases contains the number of non-virtual base
   /// class subobjects for that class type. The key of the map is
   /// the cv-unqualified canonical type of the base class subobject.
-  llvm::SmallDenseMap, 8> ClassSubobjects;
+  struct IsVirtBaseAndNumberNonVirtBases {
+unsigned IsVirtBase : 1;
+unsigned NumberOfNonVirtBases : 31;
+  };
+  llvm::SmallDenseMap ClassSubobjects;
 
   /// VisitedDependentRecords - Records the dependent records that have been
   /// already visited.
-  llvm::SmallDenseSet VisitedDependentRecords;
+  llvm::SmallPtrSet VisitedDependentRecords;
+
+  /// DetectedVirtual - The base class that is virtual.
+  const RecordType *DetectedVirtual = nullptr;
+
+  /// ScratchPath - A BasePath that is used by Sema::lookupInBases
+  /// to help build the set of paths.
+  CXXBasePath ScratchPath;
+
+  /// Array of the declarations that have been found. This
+  /// array is constructed only if needed, e.g., to iterate over the
+  /// results within LookupResult.
+  std::unique_ptr DeclsFound;
+  unsigned NumDeclsFound = 0;
 
   /// FindAmbiguities - Whether Sema::IsDerivedFrom should try find
   /// ambiguous paths while it is looking for a path from a derived
@@ -152,20 +170,7 @@
   /// if it finds a path that goes across a virtual base. The virtual class
 

r337015 - [OpenMP] Initialize data sharing stack for SPMD case

2018-07-13 Thread Gheorghe-Teodor Bercea via cfe-commits
Author: gbercea
Date: Fri Jul 13 09:18:24 2018
New Revision: 337015

URL: http://llvm.org/viewvc/llvm-project?rev=337015=rev
Log:
[OpenMP] Initialize data sharing stack for SPMD case

Summary: In the SPMD case, we need to initialize the data sharing and 
globalization infrastructure. This covers the case when an SPMD region calls a 
function in a different compilation unit.

Reviewers: ABataev, carlo.bertolli, caomhin

Reviewed By: ABataev

Subscribers: Hahnfeld, jholewinski, guansong, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp
cfe/trunk/test/OpenMP/nvptx_target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp

cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=337015=337014=337015=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Fri Jul 13 09:18:24 2018
@@ -81,6 +81,8 @@ enum OpenMPRTLFunctionNVPTX {
   OMPRTL_NVPTX__kmpc_end_reduce_nowait,
   /// Call to void __kmpc_data_sharing_init_stack();
   OMPRTL_NVPTX__kmpc_data_sharing_init_stack,
+  /// Call to void __kmpc_data_sharing_init_stack_spmd();
+  OMPRTL_NVPTX__kmpc_data_sharing_init_stack_spmd,
   /// Call to void* __kmpc_data_sharing_push_stack(size_t size,
   /// int16_t UseSharedMemory);
   OMPRTL_NVPTX__kmpc_data_sharing_push_stack,
@@ -1025,6 +1027,12 @@ void CGOpenMPRuntimeNVPTX::emitSPMDEntry
  /*RequiresDataSharing=*/Bld.getInt16(1)};
   CGF.EmitRuntimeCall(
   createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_spmd_kernel_init), Args);
+
+  // For data sharing, we need to initialize the stack.
+  CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(
+  OMPRTL_NVPTX__kmpc_data_sharing_init_stack_spmd));
+
   CGF.EmitBranch(ExecuteBB);
 
   CGF.EmitBlock(ExecuteBB);
@@ -1107,11 +1115,6 @@ void CGOpenMPRuntimeNVPTX::emitWorkerLoo
   // Wait for parallel work
   syncCTAThreads(CGF);
 
-  // For data sharing, we need to initialize the stack for workers.
-  CGF.EmitRuntimeCall(
-  createNVPTXRuntimeFunction(
-  OMPRTL_NVPTX__kmpc_data_sharing_init_stack));
-
   Address WorkFn =
   CGF.CreateDefaultAlignTempAlloca(CGF.Int8PtrTy, /*Name=*/"work_fn");
   Address ExecStatus =
@@ -1417,6 +1420,13 @@ CGOpenMPRuntimeNVPTX::createNVPTXRuntime
 RTLFn = CGM.CreateRuntimeFunction(FnTy, "__kmpc_data_sharing_init_stack");
 break;
   }
+  case OMPRTL_NVPTX__kmpc_data_sharing_init_stack_spmd: {
+/// Build void __kmpc_data_sharing_init_stack_spmd();
+auto *FnTy =
+llvm::FunctionType::get(CGM.VoidTy, llvm::None, /*isVarArg*/ false);
+RTLFn = CGM.CreateRuntimeFunction(FnTy, 
"__kmpc_data_sharing_init_stack_spmd");
+break;
+  }
   case OMPRTL_NVPTX__kmpc_data_sharing_push_stack: {
 // Build void *__kmpc_data_sharing_push_stack(size_t size,
 // int16_t UseSharedMemory);

Modified: cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp?rev=337015=337014=337015=diff
==
--- cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp Fri Jul 13 09:18:24 2018
@@ -30,7 +30,7 @@ void test_ds(){
 /// = In the worker function = ///
 // CK1: {{.*}}define internal void 
@__omp_offloading{{.*}}test_ds{{.*}}_worker()
 // CK1: call void @llvm.nvvm.barrier0()
-// CK1: call void @__kmpc_data_sharing_init_stack
+// CK1-NOT: call void @__kmpc_data_sharing_init_stack
 
 /// = In the kernel function = ///
 

Modified: cfe/trunk/test/OpenMP/nvptx_target_parallel_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_parallel_codegen.cpp?rev=337015=337014=337015=diff
==
--- cfe/trunk/test/OpenMP/nvptx_target_parallel_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_parallel_codegen.cpp Fri Jul 13 09:18:24 
2018
@@ -60,6 +60,7 @@ int bar(int n){
   // CHECK: [[AA:%.+]] = load i16*, i16** [[AA_ADDR]], align
   // CHECK: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
   // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+  // CHECK: call void @__kmpc_data_sharing_init_stack_spmd
   // CHECK: br label 

[PATCH] D49188: [OpenMP] Initialize data sharing stack for SPMD case

2018-07-13 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337015: [OpenMP] Initialize data sharing stack for SPMD case 
(authored by gbercea, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D49188

Files:
  cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp
  cfe/trunk/test/OpenMP/nvptx_target_parallel_codegen.cpp
  cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp
  cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp

Index: cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
===
--- cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
+++ cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
@@ -22,7 +22,7 @@
   tx a[N];
   short aa[N];
   tx b[10];
-  tx c[M][M];  
+  tx c[M][M];
   tx f = n;
   tx l;
   int k;
@@ -47,7 +47,7 @@
   for(int i = 0; i < M; i++) {
 for(int j = 0; j < M; j++) {
   k = M;
-  c[i][j] = i+j*f+k;  
+  c[i][j] = i+j*f+k;
 }
   }
 
@@ -65,6 +65,7 @@
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}(
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 91,
 // CHECK: {{call|invoke}} void [[OUTL1:@.+]](
 // CHECK: call void @__kmpc_for_static_fini(
@@ -79,6 +80,7 @@
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}(
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 92,
 // CHECK: {{call|invoke}} void [[OUTL2:@.+]](
 // CHECK: call void @__kmpc_for_static_fini(
@@ -93,6 +95,7 @@
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}(
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 92,
 // CHECK: {{call|invoke}} void [[OUTL3:@.+]](
 // CHECK: call void @__kmpc_for_static_fini(
@@ -108,6 +111,7 @@
 // CHECK: store {{.+}} [[F_IN]], {{.+}}* {{.+}},
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: store {{.+}} 99, {{.+}}* [[COMB_UB:%.+]], align
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 92, {{.+}}, {{.+}}, {{.+}}* [[COMB_UB]],
 // CHECK: {{call|invoke}} void [[OUTL4:@.+]](
Index: cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp
===
--- cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp
+++ cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp
@@ -228,6 +228,7 @@
 
 // CHECK: define weak void @__omp_offloading_{{.*}}ftemplate{{.*}}_l37(
 // CHECK: call void @__kmpc_spmd_kernel_init(
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: call i8* @__kmpc_data_sharing_push_stack(
 // CHECK-NOT: call void @__kmpc_serialized_parallel(
 // CHECK: call void [[L0:@.+]](i32* %{{.+}}, i32* %{{.+}}, i16* %{{.*}})
Index: cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
===
--- cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
+++ cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
@@ -48,6 +48,7 @@
 
   // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l22}}(
   // CHECK: call void @__kmpc_spmd_kernel_init(
+  // CHECK: call void @__kmpc_data_sharing_init_stack_spmd
   // CHECK: br label {{%?}}[[EXEC:.+]]
   //
   // CHECK: [[EXEC]]
@@ -69,6 +70,7 @@
 
   // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l26}}(
   // CHECK: call void @__kmpc_spmd_kernel_init(
+  // CHECK: call void @__kmpc_data_sharing_init_stack_spmd
   // CHECK: br label {{%?}}[[EXEC:.+]]
   //
   // CHECK: [[EXEC]]
@@ -89,6 +91,7 @@
 
   // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l31}}(
   // CHECK: call void @__kmpc_spmd_kernel_init(
+  // CHECK: call void @__kmpc_data_sharing_init_stack_spmd
   // CHECK: br label {{%?}}[[EXEC:.+]]
   //
   // CHECK: 

[PATCH] D49268: [clang-doc] Create a script to generate tests

2018-07-13 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

In https://reviews.llvm.org/D49268#1161268, @lebedev.ri wrote:

> Did you meant to commit `clang-tools-extra/clang-doc/test_cases/` ?
>  I can't tell whether it is a temporary directory or not.


It is, it's the code for the actual test cases that are generated (so that if 
anyone not me is working on this, they can easily generate the same test code, 
with only minor adjustments, for their changes if necessary). Maybe it would 
make more sense to move this to the `test` dir.




Comment at: clang-tools-extra/clang-doc/gen_tests.py:62
+  test_file = os.path.join(test_cases_path, 'test.cpp')
+  shutil.copyfile(test_case_path, test_file)
+  return test_file

lebedev.ri wrote:
> Ah, i see, so this happens sequentially, using the same source location for 
> each test.
Yup, so that the resulting file has the right USR for the one that depends on 
the filename (n.b. that particular issue should go away after D48908, since 
afaik the only USRs that depend on filename are function-internals)



Comment at: clang-tools-extra/clang-doc/gen_tests.py:131-133
+  clang_doc_path = os.path.dirname(__file__)
+  test_cases_path = os.path.join(clang_doc_path, 'test_cases')
+  tests_path = os.path.join(clang_doc_path, '..', 'test', 'clang-doc')

lebedev.ri wrote:
> Will the script work regardless of the `pwd` it is called from?
Yup, `__file__` is the location of this script, i.e. `/clang-doc/gen_tests.py`



Comment at: clang-tools-extra/clang-doc/gen_tests.py:138
+  for test_case_path in glob.glob(os.path.join(test_cases_path, '*')):
+if test_case_path.endswith('compile_flags.txt'):
+  continue

lebedev.ri wrote:
> Probably also `compile_commands.json`
See note on the test_cases above, since the `test_cases` file only has 
`compile_flags.txt`, but I'll add it in case that changes in the future


https://reviews.llvm.org/D49268



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


[PATCH] D38075: Fix PR34668 - P0704R1 implementation is too permissive

2018-07-13 Thread Tim Song via Phabricator via cfe-commits
tcanens added a comment.

In https://reviews.llvm.org/D38075#1161325, @Rakete wrote:

> Do you need someone to commit it?


Yes, please.


https://reviews.llvm.org/D38075



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


[PATCH] D49300: [ASTImporter] Fix poisonous structural equivalence cache

2018-07-13 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: a.sidorin, a_sidorin, r.stahl.
Herald added subscribers: cfe-commits, dkrupp, rnkovacs.

Implementation functions call into the member functions of
ASTStructuralEquivalence, thus they can falsely alter the DeclsToCheck state
(they add decls).  This results that some leaf declarations can be stated as
inequivalent as a side effect of one inequivalent element in the DeclsToCheck
list.  And since we store the non-equivalencies, any (otherwise independent)
decls will be rendered as non-equivalent.  Solution: I tried to clearly
separate the implementation functions (the static ones) and the public
interface.  From now on, the implementation functions do not call any public
member functions, only other implementation functions.


Repository:
  rC Clang

https://reviews.llvm.org/D49300

Files:
  include/clang/AST/ASTStructuralEquivalence.h
  lib/AST/ASTImporter.cpp
  lib/AST/ASTStructuralEquivalence.cpp
  lib/Sema/SemaType.cpp
  unittests/AST/StructuralEquivalenceTest.cpp

Index: unittests/AST/StructuralEquivalenceTest.cpp
===
--- unittests/AST/StructuralEquivalenceTest.cpp
+++ unittests/AST/StructuralEquivalenceTest.cpp
@@ -67,7 +67,7 @@
 StructuralEquivalenceContext Ctx(
 D0->getASTContext(), D1->getASTContext(), NonEquivalentDecls,
 StructuralEquivalenceKind::Default, false, false);
-return Ctx.IsStructurallyEquivalent(D0, D1);
+return Ctx.IsEquivalent(D0, D1);
   }
 
   bool testStructuralMatch(std::tuple t) {
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7540,7 +7540,7 @@
   StructuralEquivalenceKind::Default,
   false /*StrictTypeSpelling*/, true /*Complain*/,
   true /*ErrorOnTagTypeMismatch*/);
-  return Ctx.IsStructurallyEquivalent(D, Suggested);
+  return Ctx.IsEquivalent(D, Suggested);
 }
 
 /// Determine whether there is any declaration of \p D that was ever a
Index: lib/AST/ASTStructuralEquivalence.cpp
===
--- lib/AST/ASTStructuralEquivalence.cpp
+++ lib/AST/ASTStructuralEquivalence.cpp
@@ -184,18 +184,18 @@
 return true;
 
   case TemplateArgument::Type:
-return Context.IsStructurallyEquivalent(Arg1.getAsType(), Arg2.getAsType());
+return IsStructurallyEquivalent(Context, Arg1.getAsType(), Arg2.getAsType());
 
   case TemplateArgument::Integral:
-if (!Context.IsStructurallyEquivalent(Arg1.getIntegralType(),
+if (!IsStructurallyEquivalent(Context, Arg1.getIntegralType(),
   Arg2.getIntegralType()))
   return false;
 
 return llvm::APSInt::isSameValue(Arg1.getAsIntegral(),
  Arg2.getAsIntegral());
 
   case TemplateArgument::Declaration:
-return Context.IsStructurallyEquivalent(Arg1.getAsDecl(), Arg2.getAsDecl());
+return IsStructurallyEquivalent(Context, Arg1.getAsDecl(), Arg2.getAsDecl());
 
   case TemplateArgument::NullPtr:
 return true; // FIXME: Is this correct?
@@ -1191,8 +1191,8 @@
   return false;
 }
 
-if (!Context.IsStructurallyEquivalent(Params1->getParam(I),
-  Params2->getParam(I)))
+if (!IsStructurallyEquivalent(Context, Params1->getParam(I),
+  Params2->getParam(I)))
   return false;
   }
 
@@ -1229,7 +1229,7 @@
   }
 
   // Check types.
-  if (!Context.IsStructurallyEquivalent(D1->getType(), D2->getType())) {
+  if (!IsStructurallyEquivalent(Context, D1->getType(), D2->getType())) {
 if (Context.Complain) {
   Context.Diag2(D2->getLocation(),
 diag::err_odr_non_type_parameter_type_inconsistent)
@@ -1280,8 +1280,8 @@
 return false;
 
   // Check the templated declaration.
-  return Context.IsStructurallyEquivalent(D1->getTemplatedDecl(),
-  D2->getTemplatedDecl());
+  return IsStructurallyEquivalent(Context, D1->getTemplatedDecl(),
+  D2->getTemplatedDecl());
 }
 
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext ,
@@ -1292,8 +1292,8 @@
 return false;
 
   // Check the templated declaration.
-  return Context.IsStructurallyEquivalent(D1->getTemplatedDecl()->getType(),
-  D2->getTemplatedDecl()->getType());
+  return IsStructurallyEquivalent(Context, D1->getTemplatedDecl()->getType(),
+  D2->getTemplatedDecl()->getType());
 }
 
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext ,
@@ -1404,16 +1404,26 @@
   return Index;
 }
 
-bool StructuralEquivalenceContext::IsStructurallyEquivalent(Decl *D1,
-Decl *D2) {
+bool StructuralEquivalenceContext::IsEquivalent(Decl *D1, Decl *D2) {
+
+  // 

[PATCH] D49188: [OpenMP] Initialize data sharing stack for SPMD case

2018-07-13 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rC Clang

https://reviews.llvm.org/D49188



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


[PATCH] D49188: [OpenMP] Initialize data sharing stack for SPMD case

2018-07-13 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 155391.
gtbercea added a comment.

Fix tests.


Repository:
  rC Clang

https://reviews.llvm.org/D49188

Files:
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  test/OpenMP/nvptx_data_sharing.cpp
  test/OpenMP/nvptx_target_parallel_codegen.cpp
  test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  test/OpenMP/nvptx_target_teams_codegen.cpp
  test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp

Index: test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
===
--- test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
+++ test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
@@ -22,7 +22,7 @@
   tx a[N];
   short aa[N];
   tx b[10];
-  tx c[M][M];  
+  tx c[M][M];
   tx f = n;
   tx l;
   int k;
@@ -47,7 +47,7 @@
   for(int i = 0; i < M; i++) {
 for(int j = 0; j < M; j++) {
   k = M;
-  c[i][j] = i+j*f+k;  
+  c[i][j] = i+j*f+k;
 }
   }
 
@@ -65,6 +65,7 @@
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}(
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 91,
 // CHECK: {{call|invoke}} void [[OUTL1:@.+]](
 // CHECK: call void @__kmpc_for_static_fini(
@@ -79,6 +80,7 @@
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}(
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 92,
 // CHECK: {{call|invoke}} void [[OUTL2:@.+]](
 // CHECK: call void @__kmpc_for_static_fini(
@@ -93,6 +95,7 @@
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}(
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 92,
 // CHECK: {{call|invoke}} void [[OUTL3:@.+]](
 // CHECK: call void @__kmpc_for_static_fini(
@@ -108,6 +111,7 @@
 // CHECK: store {{.+}} [[F_IN]], {{.+}}* {{.+}},
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: store {{.+}} 99, {{.+}}* [[COMB_UB:%.+]], align
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 92, {{.+}}, {{.+}}, {{.+}}* [[COMB_UB]],
 // CHECK: {{call|invoke}} void [[OUTL4:@.+]](
Index: test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
===
--- test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
+++ test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
@@ -70,6 +70,7 @@
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}(
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 91,
 // CHECK: {{call|invoke}} void [[OUTL1:@.+]](
 // CHECK: call void @__kmpc_for_static_fini(
@@ -84,6 +85,7 @@
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}(
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 92,
 // CHECK: {{call|invoke}} void [[OUTL2:@.+]](
 // CHECK: call void @__kmpc_for_static_fini(
@@ -98,6 +100,7 @@
 // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}(
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 92,
 // CHECK: {{call|invoke}} void [[OUTL3:@.+]](
 // CHECK: call void @__kmpc_for_static_fini(
@@ -113,6 +116,7 @@
 // CHECK: store {{.+}} [[F_IN]], {{.+}}* {{.+}},
 // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
+// CHECK: call void @__kmpc_data_sharing_init_stack_spmd
 // CHECK: store {{.+}} 99, {{.+}}* [[COMB_UB:%.+]], 

[PATCH] D49296: [ASTImporter] Fix import of unnamed structs

2018-07-13 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: a.sidorin, a_sidorin, balazske, gerazo.
Herald added subscribers: cfe-commits, dkrupp, rnkovacs.

https://reviews.llvm.org/D48773 simplified ASTImporter nicely, but it 
introduced a new error: Unnamed
structs are not imported correctly, if they appear in a recursive context.
This patch provides a fix for structural equivalency.


Repository:
  rC Clang

https://reviews.llvm.org/D49296

Files:
  lib/AST/ASTStructuralEquivalence.cpp
  unittests/AST/ASTImporterTest.cpp
  unittests/AST/StructuralEquivalenceTest.cpp

Index: unittests/AST/StructuralEquivalenceTest.cpp
===
--- unittests/AST/StructuralEquivalenceTest.cpp
+++ unittests/AST/StructuralEquivalenceTest.cpp
@@ -42,6 +42,21 @@
 return std::make_tuple(D0, D1);
   }
 
+  std::tuple makeTuDecls(
+  const std::string , const std::string , Language Lang) {
+this->Code0 = SrcCode0;
+this->Code1 = SrcCode1;
+ArgVector Args = getBasicRunOptionsForLanguage(Lang);
+
+const char *const InputFileName = "input.cc";
+
+AST0 = tooling::buildASTFromCodeWithArgs(Code0, Args, InputFileName);
+AST1 = tooling::buildASTFromCodeWithArgs(Code1, Args, InputFileName);
+
+return std::make_tuple(AST0->getASTContext().getTranslationUnitDecl(),
+   AST1->getASTContext().getTranslationUnitDecl());
+  }
+
   // Get a pair of node pointers into the synthesized AST from the given code
   // snippets. The same matcher is used for both snippets.
   template 
@@ -62,15 +77,15 @@
 return makeDecls(SrcCode0, SrcCode1, Lang, Matcher);
   }
 
-  bool testStructuralMatch(NamedDecl *D0, NamedDecl *D1) {
+  bool testStructuralMatch(Decl *D0, Decl *D1) {
 llvm::DenseSet> NonEquivalentDecls;
 StructuralEquivalenceContext Ctx(
 D0->getASTContext(), D1->getASTContext(), NonEquivalentDecls,
 StructuralEquivalenceKind::Default, false, false);
 return Ctx.IsStructurallyEquivalent(D0, D1);
   }
 
-  bool testStructuralMatch(std::tuple t) {
+  bool testStructuralMatch(std::tuple t) {
 return testStructuralMatch(get<0>(t), get<1>(t));
   }
 };
@@ -468,6 +483,10 @@
 }
 
 struct StructuralEquivalenceRecordTest : StructuralEquivalenceTest {
+  RecordDecl* getRecordDecl(FieldDecl *FD) {
+auto *ET = cast(FD->getType().getTypePtr());
+return cast(ET->getNamedType().getTypePtr())->getDecl();
+  };
 };
 
 TEST_F(StructuralEquivalenceRecordTest, Name) {
@@ -535,6 +554,73 @@
   EXPECT_TRUE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceRecordTest, UnnamedRecordsShouldBeInequivalent) {
+  auto t = makeTuDecls(
+  R"(
+  struct A {
+struct {
+  struct A *next;
+} entry0;
+struct {
+  struct A *next;
+} entry1;
+  };
+  )",
+  "", Lang_C);
+  auto *TU = get<0>(t);
+  auto *Entry0 =
+  FirstDeclMatcher().match(TU, fieldDecl(hasName("entry0")));
+  auto *Entry1 =
+  FirstDeclMatcher().match(TU, fieldDecl(hasName("entry1")));
+  auto *R0 = getRecordDecl(Entry0);
+  auto *R1 = getRecordDecl(Entry1);
+
+  ASSERT_TRUE(R0);
+  ASSERT_TRUE(R1);
+  ASSERT_NE(R0, R1);
+  EXPECT_TRUE(testStructuralMatch(R0, R0));
+  EXPECT_TRUE(testStructuralMatch(R1, R1));
+  EXPECT_FALSE(testStructuralMatch(R0, R1));
+}
+
+TEST_F(StructuralEquivalenceRecordTest,
+   UnnamedRecordsShouldBeInequivalentEvenIfTheSecondIsBeingDefined) {
+  auto Code =
+  R"(
+  struct A {
+struct {
+  struct A *next;
+} entry0;
+struct {
+  struct A *next;
+} entry1;
+  };
+  )";
+  auto t = makeTuDecls(Code, Code, Lang_C);
+
+  auto *FromTU = get<0>(t);
+  auto *Entry1 =
+  FirstDeclMatcher().match(FromTU, fieldDecl(hasName("entry1")));
+
+  auto *ToTU = get<1>(t);
+  auto *Entry0 =
+  FirstDeclMatcher().match(ToTU, fieldDecl(hasName("entry0")));
+  auto *A =
+  FirstDeclMatcher().match(ToTU, recordDecl(hasName("A")));
+  A->startDefinition(); // Set isBeingDefined, getDefinition() will return a
+// nullptr. This may be the case during ASTImport.
+
+  auto *R0 = getRecordDecl(Entry0);
+  auto *R1 = getRecordDecl(Entry1);
+  ASSERT_TRUE(R0);
+  ASSERT_TRUE(R1);
+  ASSERT_NE(R0, R1);
+  EXPECT_TRUE(testStructuralMatch(R0, R0));
+  EXPECT_TRUE(testStructuralMatch(R1, R1));
+  EXPECT_FALSE(testStructuralMatch(R0, R1));
+}
+
+
 TEST_F(StructuralEquivalenceTest, CompareSameDeclWithMultiple) {
   auto t = makeNamedDecls(
   "struct A{ }; struct B{ }; void foo(A a, A b);",
Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -2469,6 +2469,44 @@
   EXPECT_NE(ToM1, ToM2);
 }
 
+TEST_P(ASTImporterTestBase, ImportUnnamedStructsWithRecursingField) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct A {
+struct {
+

[PATCH] D48958: [clang][ubsan] Implicit Cast Sanitizer - integer truncation - clang part

2018-07-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Well, that's just great, with `isCastPartOfExplictCast()`, the 
`ASTContext::getParents()`
also does not return `CXXStaticCastExpr` as parent for such cases.
I don't know how to proceed.


Repository:
  rC Clang

https://reviews.llvm.org/D48958



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


[PATCH] D49294: Sema: Fix explicit address space cast in C++

2018-07-13 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: rjmccall.

Currently clang does not allow implicit cast of a pointer to a pointer type in 
different address space but allows C-style cast of a pointer to a pointer type 
in different address space. However, there is a bug in Sema causing incorrect 
Cast Expr in AST for the latter case, which in turn results in invalid LLVM IR 
in codegen.

This is because Sema::IsQualificationConversion returns true for a cast of 
pointer to a pointer type in different address space, which in turn allows a 
standard conversion and results in a cast expression with no op in AST.

This patch fixes that by let  Sema::IsQualificationConversion returns false for 
a cast of pointer to a pointer type in different address space, which in turn 
disallows standard conversion, implicit cast, and static cast. Finally it 
results in an reinterpret cast and correct conversion kind is set.


https://reviews.llvm.org/D49294

Files:
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaOverload.cpp
  test/CodeGenCXX/address-space-cast.cpp


Index: test/CodeGenCXX/address-space-cast.cpp
===
--- /dev/null
+++ test/CodeGenCXX/address-space-cast.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s
+
+#define __private__ __attribute__((address_space(5)))
+
+void func_pchar(__private__ char* x);
+
+void test(char *gen_ptr) {
+  // CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
+  // CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
+  __private__ char* priv_ptr = (__private__ char*)gen_ptr;
+  
+  // CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
+  // CHECK-NEXT: call void @_Z10func_pcharPU3AS5c(i8 addrspace(5)* %[[cast]])
+  func_pchar((__private__ char*)gen_ptr);
+}
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -3143,6 +3143,12 @@
   = PreviousToQualsIncludeConst && ToQuals.hasConst();
   }
 
+  // ToDo: Add more detailed control for implicit address space casting for
+  // OpenCL C++.
+  if (FromType.getAddressSpace() != ToType.getAddressSpace() &&
+  !getLangOpts().OpenCLCPlusPlus)
+return false;
+
   // We are left with FromType and ToType being the pointee types
   // after unwrapping the original FromType and ToType the same number
   // of types. If we unwrapped any pointers, and if FromType and
Index: lib/Sema/SemaCast.cpp
===
--- lib/Sema/SemaCast.cpp
+++ lib/Sema/SemaCast.cpp
@@ -2163,6 +2163,13 @@
 } else {
   Kind = CK_BitCast;
 }
+  } else if (SrcType->isPointerType() && DestType->isPointerType() &&
+ SrcType->getAs()
+ ->getPointeeType()
+ .getAddressSpace() != DestType->getAs()
+   ->getPointeeType()
+   .getAddressSpace()) {
+Kind = CK_AddressSpaceConversion;
   } else {
 Kind = CK_BitCast;
   }


Index: test/CodeGenCXX/address-space-cast.cpp
===
--- /dev/null
+++ test/CodeGenCXX/address-space-cast.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s
+
+#define __private__ __attribute__((address_space(5)))
+
+void func_pchar(__private__ char* x);
+
+void test(char *gen_ptr) {
+  // CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
+  // CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
+  __private__ char* priv_ptr = (__private__ char*)gen_ptr;
+  
+  // CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
+  // CHECK-NEXT: call void @_Z10func_pcharPU3AS5c(i8 addrspace(5)* %[[cast]])
+  func_pchar((__private__ char*)gen_ptr);
+}
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -3143,6 +3143,12 @@
   = PreviousToQualsIncludeConst && ToQuals.hasConst();
   }
 
+  // ToDo: Add more detailed control for implicit address space casting for
+  // OpenCL C++.
+  if (FromType.getAddressSpace() != ToType.getAddressSpace() &&
+  !getLangOpts().OpenCLCPlusPlus)
+return false;
+
   // We are left with FromType and ToType being the pointee types
   // after unwrapping the original FromType and ToType the same number
   // of types. If we unwrapped any pointers, and if FromType and
Index: lib/Sema/SemaCast.cpp
===
--- lib/Sema/SemaCast.cpp
+++ lib/Sema/SemaCast.cpp
@@ -2163,6 +2163,13 @@
 } else {
   Kind = CK_BitCast;
 }
+  } else if (SrcType->isPointerType() && DestType->isPointerType() &&
+ SrcType->getAs()
+ ->getPointeeType()
+ 

[PATCH] D49293: [ASTImporter] Add support for import of CXXInheritedCtorInitExpr.

2018-07-13 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, martong.
Herald added a reviewer: a.sidorin.

Repository:
  rC Clang

https://reviews.llvm.org/D49293

Files:
  lib/AST/ASTImporter.cpp
  test/Import/inherited-ctor-init-expr/Inputs/A.cpp
  test/Import/inherited-ctor-init-expr/test.cpp


Index: test/Import/inherited-ctor-init-expr/test.cpp
===
--- /dev/null
+++ test/Import/inherited-ctor-init-expr/test.cpp
@@ -0,0 +1,6 @@
+// RUN: clang-import-test -dump-ast -expression=%s -import=%S/Inputs/A.cpp | 
FileCheck %s
+// CHECK: | | | `-CXXInheritedCtorInitExpr
+
+void foo() {
+  C c;
+}
Index: test/Import/inherited-ctor-init-expr/Inputs/A.cpp
===
--- /dev/null
+++ test/Import/inherited-ctor-init-expr/Inputs/A.cpp
@@ -0,0 +1,11 @@
+class A {
+public:
+  A(int a) : a(a) {}
+  int a;
+};
+class B : public A {
+  using A::A;
+};
+class C : public B {
+  C() : B(1) {}
+};
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -458,6 +458,7 @@
 Expr *VisitLambdaExpr(LambdaExpr *LE);
 Expr *VisitInitListExpr(InitListExpr *E);
 Expr *VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
+Expr *VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E);
 Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E);
 Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E);
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
@@ -6731,6 +6732,22 @@
   return new (Importer.getToContext()) CXXStdInitializerListExpr(T, SE);
 }
 
+Expr *ASTNodeImporter::VisitCXXInheritedCtorInitExpr(
+CXXInheritedCtorInitExpr *E) {
+  QualType T = Importer.Import(E->getType());
+  if (T.isNull())
+return nullptr;
+
+  auto *Ctor = dyn_cast(Importer.Import(
+  E->getConstructor()));
+  if (!Ctor)
+return nullptr;
+  
+  return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
+  Importer.Import(E->getLocation()), T, Ctor,
+  E->constructsVBase(), E->inheritedFromVBase());
+}
+
 Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
   QualType ToType = Importer.Import(E->getType());
   if (ToType.isNull())


Index: test/Import/inherited-ctor-init-expr/test.cpp
===
--- /dev/null
+++ test/Import/inherited-ctor-init-expr/test.cpp
@@ -0,0 +1,6 @@
+// RUN: clang-import-test -dump-ast -expression=%s -import=%S/Inputs/A.cpp | FileCheck %s
+// CHECK: | | | `-CXXInheritedCtorInitExpr
+
+void foo() {
+  C c;
+}
Index: test/Import/inherited-ctor-init-expr/Inputs/A.cpp
===
--- /dev/null
+++ test/Import/inherited-ctor-init-expr/Inputs/A.cpp
@@ -0,0 +1,11 @@
+class A {
+public:
+  A(int a) : a(a) {}
+  int a;
+};
+class B : public A {
+  using A::A;
+};
+class C : public B {
+  C() : B(1) {}
+};
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -458,6 +458,7 @@
 Expr *VisitLambdaExpr(LambdaExpr *LE);
 Expr *VisitInitListExpr(InitListExpr *E);
 Expr *VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
+Expr *VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E);
 Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E);
 Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E);
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
@@ -6731,6 +6732,22 @@
   return new (Importer.getToContext()) CXXStdInitializerListExpr(T, SE);
 }
 
+Expr *ASTNodeImporter::VisitCXXInheritedCtorInitExpr(
+CXXInheritedCtorInitExpr *E) {
+  QualType T = Importer.Import(E->getType());
+  if (T.isNull())
+return nullptr;
+
+  auto *Ctor = dyn_cast(Importer.Import(
+  E->getConstructor()));
+  if (!Ctor)
+return nullptr;
+  
+  return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
+  Importer.Import(E->getLocation()), T, Ctor,
+  E->constructsVBase(), E->inheritedFromVBase());
+}
+
 Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
   QualType ToType = Importer.Import(E->getType());
   if (ToType.isNull())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48831: alpha.unix.cstring.OutOfBounds checker enable/disable fix

2018-07-13 Thread Balogh , Ádám via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC337000: [Analyzer] alpha.unix.cstring.OutOfBounds checker 
enable/disable fix (authored by baloghadamsoftware, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D48831

Files:
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  test/Analysis/cstring-plist.c
  test/Analysis/malloc.c
  test/Analysis/string.c

Index: test/Analysis/malloc.c
===
--- test/Analysis/malloc.c
+++ test/Analysis/malloc.c
@@ -375,16 +375,16 @@
 // or inter-procedural analysis, this is a conservative answer.
 int *f3() {
   static int *p = 0;
-  p = malloc(12); 
+  p = malloc(12);
   return p; // no-warning
 }
 
 // This case tests that storing malloc'ed memory to a static global variable
 // which is then returned is not leaked.  In the absence of known contracts for
 // functions or inter-procedural analysis, this is a conservative answer.
 static int *p_f4 = 0;
 int *f4() {
-  p_f4 = malloc(12); 
+  p_f4 = malloc(12);
   return p_f4; // no-warning
 }
 
@@ -1232,7 +1232,7 @@
 
   if (myValueSize <= sizeof(stackBuffer))
 buffer = stackBuffer;
-  else 
+  else
 buffer = malloc(myValueSize);
 
   // do stuff with the buffer
@@ -1246,15 +1246,15 @@
 
   if (myValueSize <= sizeof(stackBuffer))
 buffer = stackBuffer;
-  else 
+  else
 buffer = malloc(myValueSize);
 
   // do stuff with the buffer
   if (buffer == stackBuffer)
 return;
   else
 return; // expected-warning {{leak}}
-}
+}
 //  Previously this triggered a false positive
 // because malloc() is known to return uninitialized memory and the binding
 // of 'o' to 'p->n' was not getting propertly handled.  Now we report a leak.
@@ -1698,7 +1698,7 @@
 void *smallocNoWarn(size_t size) {
   if (size == 0) {
 return malloc(1); // this branch is never called
-  } 
+  }
   else {
 return malloc(size);
   }
@@ -1777,21 +1777,12 @@
   free((void *)fnptr); // expected-warning {{Argument to free() is a function pointer}}
 }
 
-// Enabling the malloc checker enables some of the buffer-checking portions
-// of the C-string checker.
-void cstringchecker_bounds_nocrash() {
-  char *p = malloc(2);
-  strncpy(p, "AAA", sizeof("AAA")); // expected-warning {{Size argument is greater than the length of the destination buffer}}
-
-  free(p);
-}
-
 void allocateSomeMemory(void *offendingParameter, void **ptr) {
   *ptr = malloc(1);
 }
 
 void testNoCrashOnOffendingParameter() {
-  // "extern" is necessary to avoid unrelated warnings 
+  // "extern" is necessary to avoid unrelated warnings
   // on passing uninitialized value.
   extern void *offendingParameter;
   void* ptr;
Index: test/Analysis/cstring-plist.c
===
--- test/Analysis/cstring-plist.c
+++ test/Analysis/cstring-plist.c
@@ -0,0 +1,22 @@
+// RUN: rm -f %t
+// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=core,unix.Malloc,unix.cstring.NullArg -analyzer-disable-checker=alpha.unix.cstring.OutOfBounds -analyzer-output=plist -analyzer-config path-diagnostics-alternate=false -o %t %s
+// RUN: FileCheck -input-file %t %s
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void free(void *);
+char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
+
+
+
+void cstringchecker_bounds_nocrash() {
+  char *p = malloc(2);
+  strncpy(p, "AAA", sizeof("AAA")); // we don't expect warning as the checker is disabled
+  free(p);
+}
+
+// CHECK: diagnostics
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
Index: test/Analysis/string.c
===
--- test/Analysis/string.c
+++ test/Analysis/string.c
@@ -31,6 +31,8 @@
 void clang_analyzer_eval(int);
 
 int scanf(const char *restrict format, ...);
+void *malloc(size_t);
+void free(void *);
 
 //===--===
 // strlen()
@@ -110,7 +112,7 @@
   if (a == 0) {
 clang_analyzer_eval(b == 0); // expected-warning{{TRUE}}
 // Make sure clang_analyzer_eval does not invalidate globals.
-clang_analyzer_eval(strlen(global_str) == 0); // expected-warning{{TRUE}}
+clang_analyzer_eval(strlen(global_str) == 0); // expected-warning{{TRUE}}
   }
 
   // Call a function with unknown effects, which should invalidate globals.
@@ -309,11 +311,13 @@
   clang_analyzer_eval(globalInt == 42); // expected-warning{{TRUE}}
 }
 
+#ifndef SUPPRESS_OUT_OF_BOUND
 void strcpy_overflow(char *y) {
   char x[4];
   if (strlen(y) == 4)
 strcpy(x, y); // expected-warning{{String copy function overflows destination buffer}}
 }
+#endif
 
 void strcpy_no_overflow(char *y) {
   char x[4];
@@ -348,11 +352,13 @@
   clang_analyzer_eval(a == x[0]); // expected-warning{{UNKNOWN}}
 }
 
+#ifndef SUPPRESS_OUT_OF_BOUND
 void stpcpy_overflow(char *y) {
   char x[4];
   if (strlen(y) == 4)
 stpcpy(x, y); // 

r337000 - [Analyzer] alpha.unix.cstring.OutOfBounds checker enable/disable fix

2018-07-13 Thread Adam Balogh via cfe-commits
Author: baloghadamsoftware
Date: Fri Jul 13 06:44:44 2018
New Revision: 337000

URL: http://llvm.org/viewvc/llvm-project?rev=337000=rev
Log:
[Analyzer] alpha.unix.cstring.OutOfBounds checker enable/disable fix

It was not possible to disable alpha.unix.cstring.OutOfBounds checker's reports
since unix.Malloc checker always implicitly enabled the filter. Moreover if the
checker was disabled from command line (-analyzer-disable-checker ..) the out
of bounds warnings were nevertheless emitted under different checker names such
as unix.cstring.NullArg, or unix.Malloc.

This patch fixes the case sot that Malloc checker only enables implicitly the
underlying modeling of strcpy, memcpy etc. but not the warning messages that
would have been emmitted by alpha.unix.cstring.OutOfBounds

Patch by: Dániel Krupp

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


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

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=337000=336999=337000=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Fri Jul 13 
06:44:44 2018
@@ -305,10 +305,10 @@ ProgramStateRef CStringChecker::CheckLoc
   ProgramStateRef StOutBound = state->assumeInBound(Idx, Size, false);
   if (StOutBound && !StInBound) {
 // These checks are either enabled by the CString out-of-bounds checker
-// explicitly or the "basic" CStringNullArg checker support that Malloc
-// checker enables.
-assert(Filter.CheckCStringOutOfBounds || Filter.CheckCStringNullArg);
-
+// explicitly or implicitly by the Malloc checker.
+// In the latter case we only do modeling but do not emit warning.
+if (!Filter.CheckCStringOutOfBounds)
+  return nullptr;
 // Emit a bug report.
 if (warningMsg) {
   emitOutOfBoundsBug(C, StOutBound, S, warningMsg);
@@ -1039,7 +1039,7 @@ bool CStringChecker::memsetAux(const Exp
 std::tie(StateWholeReg, StateNotWholeReg) =
 State->assume(svalBuilder.evalEQ(State, Extent, *SizeNL));
 
-// With the semantic of 'memset()', we should convert the CharVal to 
+// With the semantic of 'memset()', we should convert the CharVal to
 // unsigned char.
 CharVal = svalBuilder.evalCast(CharVal, Ctx.UnsignedCharTy, Ctx.IntTy);
 
@@ -2418,5 +2418,5 @@ void CStringChecker::checkDeadSymbols(Sy
 REGISTER_CHECKER(CStringNotNullTerm)
 
   void ento::registerCStringCheckerBasic(CheckerManager ) {
-registerCStringNullArg(Mgr);
+Mgr.registerChecker();
   }

Added: cfe/trunk/test/Analysis/cstring-plist.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cstring-plist.c?rev=337000=auto
==
--- cfe/trunk/test/Analysis/cstring-plist.c (added)
+++ cfe/trunk/test/Analysis/cstring-plist.c Fri Jul 13 06:44:44 2018
@@ -0,0 +1,22 @@
+// RUN: rm -f %t
+// RUN: %clang_analyze_cc1 -fblocks 
-analyzer-checker=core,unix.Malloc,unix.cstring.NullArg 
-analyzer-disable-checker=alpha.unix.cstring.OutOfBounds -analyzer-output=plist 
-analyzer-config path-diagnostics-alternate=false -o %t %s
+// RUN: FileCheck -input-file %t %s
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void free(void *);
+char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
+
+
+
+void cstringchecker_bounds_nocrash() {
+  char *p = malloc(2);
+  strncpy(p, "AAA", sizeof("AAA")); // we don't expect warning as the checker 
is disabled
+  free(p);
+}
+
+// CHECK: diagnostics
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 

Modified: cfe/trunk/test/Analysis/malloc.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc.c?rev=337000=336999=337000=diff
==
--- cfe/trunk/test/Analysis/malloc.c (original)
+++ cfe/trunk/test/Analysis/malloc.c Fri Jul 13 06:44:44 2018
@@ -375,7 +375,7 @@ void CheckUseZeroReallocatedPathWarn(_Bo
 // or inter-procedural analysis, this is a conservative answer.
 int *f3() {
   static int *p = 0;
-  p = malloc(12); 
+  p = malloc(12);
   return p; // no-warning
 }
 
@@ -384,7 +384,7 @@ int *f3() {
 // functions or inter-procedural analysis, this is a conservative answer.
 static int *p_f4 = 0;
 int *f4() {
-  p_f4 = malloc(12); 
+  p_f4 = malloc(12);
   return p_f4; // no-warning
 }
 
@@ -1232,7 +1232,7 @@ void radar10978247(int myValueSize) {
 
   if (myValueSize <= sizeof(stackBuffer))
 buffer = stackBuffer;
-  else 
+  else
 buffer = malloc(myValueSize);
 
   // do stuff with the buffer
@@ -1246,7 +1246,7 @@ 

[PATCH] D48831: alpha.unix.cstring.OutOfBounds checker enable/disable fix

2018-07-13 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

Whoops, sry, yeah, looks good, please commit!


https://reviews.llvm.org/D48831



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


[PATCH] D48436: [analyzer][UninitializedObjectChecker] Fixed a false negative by no longer filtering out certain constructor calls

2018-07-13 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

> I'll think about that a bit more; it might be worth it to track such deferred 
> subregions in a state trait and drain it whenever we pop back to an explicit 
> constructor.

There are so many things to consider, like the following case:

  struct DynTBase {};
  struct DynTDerived : DynTBase {
// TODO: we'd expect the note: {{uninitialized field 'this->x'}}
int x; // no-note
  };
  
  struct DynamicTypeTest {
DynTBase *bptr;
int i = 0;
  
// TODO: we'd expect the warning: {{1 uninitialized field}}
DynamicTypeTest(DynTBase *bptr) : bptr(bptr) {} // no-warning
  };
  
  void f() {
DynTDerived d;
DynamicTypeTest t();
  };

As of now, the checker misses this one.
We talked about two approaches so far, the one already in the checker and the 
one I proposed now. I think the current implementation solves this issue a lot 
more naturally -- `isNonUnionUninit` has to be changed so that the fields 
dynamic type is checked rather then its static type.
The proposed method would have a tough time dealing with this -- we don't want 
an error for `DynTDerived::DynTDerived()`, since it's a compiler generated 
ctor, but ideally we wouldn't like to have a warning for an object (`t`) and a 
separate warning for it's field (`t.bptr.x`), but I'm afraid this new approach 
would make this a necessity.

So, bottom line, there are a bunch of `TODO`s in the code to make sure this 
issue is not forgotten, I strongly believe that we need a separate discussion 
for this, if you'd agree :)




Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:674
+  const LocationContext *LC = Context.getLocationContext();
+  while ((LC = LC->getParent())) {
+

NoQ wrote:
> george.karpenkov wrote:
> > nit: could we have `while (LC)` followed by `LC = LC->getParent()` ? Do you 
> > intentionally skip the first location context?
> I guess the predicate we're checking is trivially true for the current 
> location context.
Completely missed this inline, sorry!

As @NoQ said, since this checker only fires after a constructor call, the first 
location context will surely be that, and I'm only checking whether the current 
ctor was called by another.


https://reviews.llvm.org/D48436



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


[PATCH] D33537: [clang-tidy] Exception Escape Checker

2018-07-13 Thread Balogh , Ádám via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL336997: [clang-tidy] Exception Escape Checker (authored by 
baloghadamsoftware, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D33537?vs=151876=155366#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33537

Files:
  clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-exception-escape.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/bugprone-exception-escape.cpp

Index: clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -0,0 +1,214 @@
+//===--- ExceptionEscapeCheck.cpp - clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ExceptionEscapeCheck.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace {
+typedef llvm::SmallVector TypeVec;
+} // namespace
+
+namespace clang {
+
+static bool isBaseOf(const Type *DerivedType, const Type *BaseType) {
+  const auto *DerivedClass = DerivedType->getAsCXXRecordDecl();
+  const auto *BaseClass = BaseType->getAsCXXRecordDecl();
+  if (!DerivedClass || !BaseClass)
+return false;
+
+  return !DerivedClass->forallBases(
+  [BaseClass](const CXXRecordDecl *Cur) { return Cur != BaseClass; });
+}
+
+static const TypeVec
+throwsException(const Stmt *St, const TypeVec ,
+llvm::SmallSet );
+
+static const TypeVec
+throwsException(const FunctionDecl *Func,
+llvm::SmallSet ) {
+  if (CallStack.count(Func))
+return TypeVec();
+
+  if (const Stmt *Body = Func->getBody()) {
+CallStack.insert(Func);
+const TypeVec Result = throwsException(Body, TypeVec(), CallStack);
+CallStack.erase(Func);
+return Result;
+  }
+
+  TypeVec Result;
+  if (const auto *FPT = Func->getType()->getAs()) {
+for (const QualType Ex : FPT->exceptions()) {
+  Result.push_back(Ex.getTypePtr());
+}
+  }
+  return Result;
+}
+
+static const TypeVec
+throwsException(const Stmt *St, const TypeVec ,
+llvm::SmallSet ) {
+  TypeVec Results;
+
+  if (!St)
+return Results;
+
+  if (const auto *Throw = dyn_cast(St)) {
+if (const auto *ThrownExpr = Throw->getSubExpr()) {
+  const auto *ThrownType =
+  ThrownExpr->getType()->getUnqualifiedDesugaredType();
+  if (ThrownType->isReferenceType()) {
+ThrownType = ThrownType->castAs()
+ ->getPointeeType()
+ ->getUnqualifiedDesugaredType();
+  }
+  if (const auto *TD = ThrownType->getAsTagDecl()) {
+if (TD->getDeclName().isIdentifier() && TD->getName() == "bad_alloc"
+&& TD->isInStdNamespace())
+  return Results;
+  }
+  Results.push_back(ThrownExpr->getType()->getUnqualifiedDesugaredType());
+} else {
+  Results.append(Caught.begin(), Caught.end());
+}
+  } else if (const auto *Try = dyn_cast(St)) {
+TypeVec Uncaught = throwsException(Try->getTryBlock(), Caught, CallStack);
+for (unsigned i = 0; i < Try->getNumHandlers(); ++i) {
+  const CXXCatchStmt *Catch = Try->getHandler(i);
+  if (!Catch->getExceptionDecl()) {
+const TypeVec Rethrown =
+throwsException(Catch->getHandlerBlock(), Uncaught, CallStack);
+Results.append(Rethrown.begin(), Rethrown.end());
+Uncaught.clear();
+  } else {
+const auto *CaughtType =
+Catch->getCaughtType()->getUnqualifiedDesugaredType();
+if (CaughtType->isReferenceType()) {
+  CaughtType = CaughtType->castAs()
+   ->getPointeeType()
+   ->getUnqualifiedDesugaredType();
+}
+auto NewEnd =
+llvm::remove_if(Uncaught, [](const Type *ThrownType) {
+  return ThrownType == CaughtType ||
+ isBaseOf(ThrownType, CaughtType);
+});
+if (NewEnd != Uncaught.end()) {
+  Uncaught.erase(NewEnd, Uncaught.end());
+  const TypeVec Rethrown = 

[clang-tools-extra] r336997 - [clang-tidy] Exception Escape Checker

2018-07-13 Thread Adam Balogh via cfe-commits
Author: baloghadamsoftware
Date: Fri Jul 13 06:09:40 2018
New Revision: 336997

URL: http://llvm.org/viewvc/llvm-project?rev=336997=rev
Log:
[clang-tidy] Exception Escape Checker

Finds functions which may throw an exception directly or indirectly, but they
should not: Destructors, move constructors, move assignment operators, the
main() function, swap() functions, functions marked with throw() or noexcept
and functions given as option to the checker.

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


Added:
clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-exception-escape.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-exception-escape.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=336997=336996=336997=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Fri Jul 
13 06:09:40 2018
@@ -16,6 +16,7 @@
 #include "BoolPointerImplicitConversionCheck.h"
 #include "CopyConstructorInitCheck.h"
 #include "DanglingHandleCheck.h"
+#include "ExceptionEscapeCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
 #include "ForwardingReferenceOverloadCheck.h"
@@ -67,6 +68,8 @@ public:
 "bugprone-copy-constructor-init");
 CheckFactories.registerCheck(
 "bugprone-dangling-handle");
+CheckFactories.registerCheck(
+"bugprone-exception-escape");
 CheckFactories.registerCheck(
 "bugprone-fold-init-type");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=336997=336996=336997=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Fri Jul 13 
06:09:40 2018
@@ -7,6 +7,7 @@ add_clang_library(clangTidyBugproneModul
   BugproneTidyModule.cpp
   CopyConstructorInitCheck.cpp
   DanglingHandleCheck.cpp
+  ExceptionEscapeCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   ForwardingReferenceOverloadCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp?rev=336997=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp Fri 
Jul 13 06:09:40 2018
@@ -0,0 +1,214 @@
+//===--- ExceptionEscapeCheck.cpp - 
clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ExceptionEscapeCheck.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace {
+typedef llvm::SmallVector TypeVec;
+} // namespace
+
+namespace clang {
+
+static bool isBaseOf(const Type *DerivedType, const Type *BaseType) {
+  const auto *DerivedClass = DerivedType->getAsCXXRecordDecl();
+  const auto *BaseClass = BaseType->getAsCXXRecordDecl();
+  if (!DerivedClass || !BaseClass)
+return false;
+
+  return !DerivedClass->forallBases(
+  [BaseClass](const CXXRecordDecl *Cur) { return Cur != BaseClass; });
+}
+
+static const TypeVec
+throwsException(const Stmt *St, const TypeVec ,
+llvm::SmallSet );
+
+static const TypeVec
+throwsException(const FunctionDecl *Func,
+llvm::SmallSet ) {
+  if (CallStack.count(Func))
+return TypeVec();
+
+  if (const Stmt *Body = Func->getBody()) {
+CallStack.insert(Func);
+const TypeVec Result = throwsException(Body, TypeVec(), CallStack);
+CallStack.erase(Func);
+return Result;
+  }
+
+  TypeVec Result;
+  if (const auto *FPT = Func->getType()->getAs()) {
+for (const QualType Ex : 

[PATCH] D48958: [clang][ubsan] Implicit Cast Sanitizer - integer truncation - clang part

2018-07-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 155363.
lebedev.ri marked 3 inline comments as done.
lebedev.ri added a comment.

Address @vsk review notes, although this will be revered by the next update 
dropping the faulty 'stack' optimization.


Repository:
  rC Clang

https://reviews.llvm.org/D48958

Files:
  docs/ReleaseNotes.rst
  docs/UndefinedBehaviorSanitizer.rst
  include/clang/Basic/Sanitizers.def
  include/clang/Basic/Sanitizers.h
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChain.cpp
  test/CodeGen/catch-implicit-integer-truncations.c
  test/CodeGenCXX/catch-implicit-integer-truncations.cpp
  test/Driver/fsanitize.c

Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -31,6 +31,21 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=integer %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-INTEGER -implicit-check-not="-fsanitize-address-use-after-scope"
 // CHECK-INTEGER: "-fsanitize={{((signed-integer-overflow|unsigned-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent),?){5}"}}
 
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-cast %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-IMPLICIT-CAST,CHECK-IMPLICIT-CAST-RECOVER
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-cast -fsanitize-recover=implicit-cast %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-IMPLICIT-CAST,CHECK-IMPLICIT-CAST-RECOVER
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-cast -fno-sanitize-recover=implicit-cast %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-IMPLICIT-CAST,CHECK-IMPLICIT-CAST-NORECOVER
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-cast -fsanitize-trap=implicit-cast %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-IMPLICIT-CAST,CHECK-IMPLICIT-CAST-TRAP
+// CHECK-IMPLICIT-CAST: "-fsanitize={{((implicit-integer-truncation),?){1}"}}
+// CHECK-IMPLICIT-CAST-RECOVER: "-fsanitize-recover={{((implicit-integer-truncation),?){1}"}}
+// CHECK-IMPLICIT-CAST-RECOVER-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation),?){1}"}}
+// CHECK-IMPLICIT-CAST-RECOVER-NOT: "-fsanitize-trap={{((implicit-integer-truncation),?){1}"}}
+// CHECK-IMPLICIT-CAST-NORECOVER-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation),?){1}"}} // ???
+// CHECK-IMPLICIT-CAST-NORECOVER-NOT: "-fsanitize-recover={{((implicit-integer-truncation),?){1}"}}
+// CHECK-IMPLICIT-CAST-NORECOVER-NOT: "-fsanitize-trap={{((implicit-integer-truncation),?){1}"}}
+// CHECK-IMPLICIT-CAST-TRAP: "-fsanitize-trap={{((implicit-integer-truncation),?){1}"}}
+// CHECK-IMPLICIT-CAST-TRAP-NOT: "-fsanitize-recover={{((implicit-integer-truncation),?){1}"}}
+// CHECK-IMPLICIT-CAST-TRAP-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation),?){1}"}}
+
 // RUN: %clang -fsanitize=bounds -### -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOUNDS
 // CHECK-BOUNDS: "-fsanitize={{((array-bounds|local-bounds),?){2}"}}
 
Index: test/CodeGenCXX/catch-implicit-integer-truncations.cpp
===
--- /dev/null
+++ test/CodeGenCXX/catch-implicit-integer-truncations.cpp
@@ -0,0 +1,255 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER
+// RUN: %clang_cc1 -fsanitize=implicit-integer-truncation -fsanitize-recover=implicit-integer-truncation -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
+// RUN: %clang_cc1 -fsanitize=implicit-integer-truncation -fsanitize-trap=implicit-integer-truncation -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP
+
+extern "C" { // Disable name mangling.
+
+// == //
+// Check that explicit cast does not interfere with implicit cast
+// == //
+// These contain one implicit truncating cast, and one explicit truncating cast.
+// We want to make sure that we still diagnose the implicit cast.
+
+// Implicit truncation after explicit truncation.
+// CHECK-LABEL: @explicit_cast_interference0
+unsigned char explicit_cast_interference0(unsigned int c) {
+  // CHECK-SANITIZE: %[[ANYEXT:.*]] = zext i8 %[[DST:.*]] to i16, !nosanitize
+  // CHECK-SANITIZE: call
+  // CHECK-SANITIZE-NOT: call
+  // CHECK: }
+  return (unsigned short)c;
+}
+
+// Implicit truncation before explicit truncation.
+// CHECK-LABEL: @explicit_cast_interference1
+unsigned 

[PATCH] D48958: [clang][ubsan] Implicit Cast Sanitizer - integer truncation - clang part

2018-07-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri marked 5 inline comments as done.
lebedev.ri added a comment.

@vsk so yeah, no wonder that doesn't work.
Somehow in that test case `ScalarExprEmitter::VisitExplicitCastExpr()` 
**never** gets called.
(I'm pretty sure this worked with the naive implementation, so worst case i'll 
just revert the 'stack' code)
Trying to assess the issue..




Comment at: lib/CodeGen/CGExprScalar.cpp:351
+ScalarConversionOpts()
+: TreatBooleanAsSigned(false),
+  EmitImplicitIntegerTruncationChecks(false) {}

lebedev.ri wrote:
> vsk wrote:
> > Why not use default member initializers here (e.g, "bool a = false")?
> I'll double-check, but i'm pretty sure then there were some warnings when i 
> did that,
> Or, the default needs to be defined in the actual declaration of 
> `EmitScalarConversion()`, i think.
```
[2/14 0.3/sec] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGExprScalar.cpp.o
FAILED: tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGExprScalar.cpp.o 
/usr/bin/clang++-6.0  -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-Itools/clang/lib/CodeGen -I/build/clang/lib/CodeGen -I/build/clang/include 
-Itools/clang/include -I/usr/include/libxml2 -Iinclude -I/build/llvm/include 
-g0 -fPIC -fvisibility-inlines-hidden -Werror -Werror=date-time 
-Werror=unguarded-availability-new -std=c++11 -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -g0  -fPIC   -UNDEBUG  -fno-exceptions -fno-rtti -MD 
-MT tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGExprScalar.cpp.o -MF 
tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGExprScalar.cpp.o.d -o 
tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGExprScalar.cpp.o -c 
/build/clang/lib/CodeGen/CGExprScalar.cpp
/build/clang/lib/CodeGen/CGExprScalar.cpp:355:52: error: default member 
initializer for 'TreatBooleanAsSigned' needed within definition of enclosing 
class 'ScalarExprEmitter' outside of member functions
   ScalarConversionOpts Opts = ScalarConversionOpts());
   ^
/build/clang/lib/CodeGen/CGExprScalar.cpp:349:10: note: default member 
initializer declared here
bool TreatBooleanAsSigned = false;
 ^
/build/clang/lib/CodeGen/CGExprScalar.cpp:355:52: error: default member 
initializer for 'EmitImplicitIntegerTruncationChecks' needed within definition 
of enclosing class 'ScalarExprEmitter' outside of member functions
   ScalarConversionOpts Opts = ScalarConversionOpts());
   ^
/build/clang/lib/CodeGen/CGExprScalar.cpp:350:10: note: default member 
initializer declared here
bool EmitImplicitIntegerTruncationChecks = false;
 ^
2 errors generated.
```



Repository:
  rC Clang

https://reviews.llvm.org/D48958



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


[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.

2018-07-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/AST/ASTContext.h:1327-1329
+  QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr,
+   SourceLocation AttrLoc,
+   VectorType::VectorKind VecKind) const;

The formatting looks off here. Did clang-format do this?



Comment at: include/clang/AST/Type.h:3083
 
+/// Represents a vector type where either the type or sizeis dependent.
+

sizeis -> size is



Comment at: include/clang/AST/Type.h:3105
+public:
+  Expr *getSizeExpr() const { return SizeExpr; }
+  QualType getElementType() const { return ElementType; }

Can this return `const Expr *` and have a non-const overload to return the 
non-const `Expr *`?



Comment at: lib/AST/ASTContext.cpp:3316
 }
+QualType
+ASTContext::getDependentVectorType(QualType VecType, Expr *SizeExpr,

Insert a newline above, and reformat.



Comment at: lib/AST/ItaniumMangle.cpp:3007-3008
+void CXXNameMangler::mangleNeonVectorType(const DependentVectorType *T) {
+  llvm_unreachable(
+  "Mangling for Dependent Sized Neon Vector not yet implemented");
+}

This seems reachable.



Comment at: lib/AST/ItaniumMangle.cpp:3080
+const DependentVectorType *T) {
+  llvm_unreachable(
+  "Mangling for Dependent Sized AArch64 Neon Vector not yet implemented");

As does this.



Comment at: lib/AST/Type.cpp:192
+
+void DependentVectorType::Profile(llvm::FoldingSetNodeID ,
+   const ASTContext ,

Formatting? Also, does this need to take the `VecKind`?



Comment at: lib/Sema/SemaTemplateDeduction.cpp:1841
+case Type::DependentVector: {
+  const DependentVectorType *VectorParam =
+  cast(Param);

Can use `const auto *` here.



Comment at: lib/Sema/SemaTemplateDeduction.cpp:1844
+
+  if (const VectorType *VectorArg = dyn_cast(Arg)) {
+// Perform deduction on the element types.

Here too.



Comment at: lib/Sema/SemaTemplateDeduction.cpp:1864
+return DeduceNonTypeTemplateArgument(S, TemplateParams, NTTP, ArgSize,
+ S.Context.IntTy, true, Info,
+ Deduced);

Can the size ever be negative? Perhaps an unsigned type would be better than a 
signed type?



Comment at: lib/Sema/SemaTemplateDeduction.cpp:1868
+
+  if (const DependentVectorType *VectorArg =
+  dyn_cast(Arg)) {

`const auto *`



Comment at: lib/Sema/SemaTemplateDeduction.cpp:5281
+  case Type::DependentVector: {
+const DependentVectorType *VecType = cast(T);
+MarkUsedTemplateParameters(Ctx, VecType->getElementType(), OnlyDeduced,

`const auto *`


https://reviews.llvm.org/D49045



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


[PATCH] D48831: alpha.unix.cstring.OutOfBounds checker enable/disable fix

2018-07-13 Thread Daniel Krupp via Phabricator via cfe-commits
dkrupp marked an inline comment as done.
dkrupp added a comment.

@NoQ do we need any more update to this patch? Thanks.


https://reviews.llvm.org/D48831



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


[PATCH] D48291: [analyzer][UninitializedObjectChecker] Fixed captured lambda variable name

2018-07-13 Thread Umann Kristóf via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC336995: [analyzer][UninitializedObjectChecker] Fixed 
captured lambda variable name (authored by Szelethus, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D48291

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object.cpp

Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -232,6 +232,10 @@
 static void printNoteMessage(llvm::raw_ostream ,
  const FieldChainInfo );
 
+/// Returns with Field's name. This is a helper function to get the correct name
+/// even if Field is a captured lambda variable.
+static StringRef getVariableName(const FieldDecl *Field);
+
 //===--===//
 //  Methods for UninitializedObjectChecker.
 //===--===//
@@ -581,30 +585,14 @@
 // "uninitialized field 'this->x'", but we can't refer to 'x' directly,
 // we need an explicit namespace resolution whether the uninit field was
 // 'D1::x' or 'D2::x'.
-//
-// TODO: If a field in the fieldchain is a captured lambda parameter, this
-// function constructs an empty string for it:
-//
-//   template  struct A {
-// Callable c;
-// A(const Callable , int) : c(c) {}
-//   };
-//
-//   int b; // say that this isn't zero initialized
-//   auto alwaysTrue = [](int a) { return true; };
-//
-// A call with these parameters: A::A(alwaysTrue, int())
-// will emit a note with the message "uninitialized field: 'this->c.'". If
-// possible, the lambda parameter name should be retrieved or be replaced with a
-// "" or something similar.
 void FieldChainInfo::print(llvm::raw_ostream ) const {
   if (Chain.isEmpty())
 return;
 
   const llvm::ImmutableListImpl *L =
   Chain.getInternalPointer();
   printTail(Out, L->getTail());
-  Out << L->getHead()->getDecl()->getNameAsString();
+  Out << getVariableName(L->getHead()->getDecl());
 }
 
 void FieldChainInfo::printTail(
@@ -615,7 +603,7 @@
 
   printTail(Out, L->getTail());
   const FieldDecl *Field = L->getHead()->getDecl();
-  Out << Field->getNameAsString();
+  Out << getVariableName(Field);
   Out << (Field->getType()->isPointerType() ? "->" : ".");
 }
 
@@ -676,6 +664,21 @@
   Out << "'";
 }
 
+static StringRef getVariableName(const FieldDecl *Field) {
+  // If Field is a captured lambda variable, Field->getName() will return with
+  // an empty string. We can however acquire it's name from the lambda's
+  // captures.
+  const auto *CXXParent = dyn_cast(Field->getParent());
+
+  if (CXXParent && CXXParent->isLambda()) {
+assert(CXXParent->captures_begin());
+auto It = CXXParent->captures_begin() + Field->getFieldIndex();
+return It->getCapturedVar()->getName();
+  }
+
+  return Field->getName();
+}
+
 void ento::registerUninitializedObjectChecker(CheckerManager ) {
   auto Chk = Mgr.registerChecker();
   Chk->IsPedantic = Mgr.getAnalyzerOptions().getBooleanOption(
Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- test/Analysis/cxx-uninitialized-object.cpp
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -737,6 +737,22 @@
 //===--===//
 
 template 
+struct LambdaThisTest {
+  Callable functor;
+
+  LambdaThisTest(const Callable , int) : functor(functor) {
+// All good!
+  }
+};
+
+struct HasCapturableThis {
+  void fLambdaThisTest() {
+auto isEven = [this](int a) { return a % 2 == 0; }; // no-crash
+LambdaThisTest(isEven, int());
+  }
+};
+
+template 
 struct LambdaTest1 {
   Callable functor;
 
@@ -760,7 +776,7 @@
 
 void fLambdaTest2() {
   int b;
-  auto equals = [](int a) { return a == b; }; // expected-note{{uninitialized field 'this->functor.'}}
+  auto equals = [](int a) { return a == b; }; // expected-note{{uninitialized field 'this->functor.b'}}
   LambdaTest2(equals, int());
 }
 #else
@@ -782,8 +798,8 @@
 namespace LT3Detail {
 
 struct RecordType {
-  int x; // expected-note{{uninitialized field 'this->functor..x'}}
-  int y; // expected-note{{uninitialized field 'this->functor..y'}}
+  int x; // expected-note{{uninitialized field 'this->functor.rec1.x'}}
+  int y; // expected-note{{uninitialized field 'this->functor.rec1.y'}}
 };
 
 } // namespace LT3Detail
@@ -826,6 +842,35 @@
 }
 #endif //PEDANTIC
 
+template 
+struct MultipleLambdaCapturesTest1 {
+  Callable functor;
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  MultipleLambdaCapturesTest1(const Callable , int) : functor(functor) 

r336995 - [analyzer][UninitializedObjectChecker] Fixed captured lambda variable name

2018-07-13 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Fri Jul 13 05:54:47 2018
New Revision: 336995

URL: http://llvm.org/viewvc/llvm-project?rev=336995=rev
Log:
[analyzer][UninitializedObjectChecker] Fixed captured lambda variable name

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp?rev=336995=336994=336995=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp Fri 
Jul 13 05:54:47 2018
@@ -232,6 +232,10 @@ static bool isPrimitiveType(const QualTy
 static void printNoteMessage(llvm::raw_ostream ,
  const FieldChainInfo );
 
+/// Returns with Field's name. This is a helper function to get the correct 
name
+/// even if Field is a captured lambda variable.
+static StringRef getVariableName(const FieldDecl *Field);
+
 
//===--===//
 //  Methods for UninitializedObjectChecker.
 
//===--===//
@@ -581,22 +585,6 @@ const FieldDecl *FieldChainInfo::getEndO
 // "uninitialized field 'this->x'", but we can't refer to 'x' directly,
 // we need an explicit namespace resolution whether the uninit field was
 // 'D1::x' or 'D2::x'.
-//
-// TODO: If a field in the fieldchain is a captured lambda parameter, this
-// function constructs an empty string for it:
-//
-//   template  struct A {
-// Callable c;
-// A(const Callable , int) : c(c) {}
-//   };
-//
-//   int b; // say that this isn't zero initialized
-//   auto alwaysTrue = [](int a) { return true; };
-//
-// A call with these parameters: A::A(alwaysTrue, int())
-// will emit a note with the message "uninitialized field: 'this->c.'". If
-// possible, the lambda parameter name should be retrieved or be replaced with 
a
-// "" or something similar.
 void FieldChainInfo::print(llvm::raw_ostream ) const {
   if (Chain.isEmpty())
 return;
@@ -604,7 +592,7 @@ void FieldChainInfo::print(llvm::raw_ost
   const llvm::ImmutableListImpl *L =
   Chain.getInternalPointer();
   printTail(Out, L->getTail());
-  Out << L->getHead()->getDecl()->getNameAsString();
+  Out << getVariableName(L->getHead()->getDecl());
 }
 
 void FieldChainInfo::printTail(
@@ -615,7 +603,7 @@ void FieldChainInfo::printTail(
 
   printTail(Out, L->getTail());
   const FieldDecl *Field = L->getHead()->getDecl();
-  Out << Field->getNameAsString();
+  Out << getVariableName(Field);
   Out << (Field->getType()->isPointerType() ? "->" : ".");
 }
 
@@ -676,6 +664,21 @@ static void printNoteMessage(llvm::raw_o
   Out << "'";
 }
 
+static StringRef getVariableName(const FieldDecl *Field) {
+  // If Field is a captured lambda variable, Field->getName() will return with
+  // an empty string. We can however acquire it's name from the lambda's
+  // captures.
+  const auto *CXXParent = dyn_cast(Field->getParent());
+
+  if (CXXParent && CXXParent->isLambda()) {
+assert(CXXParent->captures_begin());
+auto It = CXXParent->captures_begin() + Field->getFieldIndex();
+return It->getCapturedVar()->getName();
+  }
+
+  return Field->getName();
+}
+
 void ento::registerUninitializedObjectChecker(CheckerManager ) {
   auto Chk = Mgr.registerChecker();
   Chk->IsPedantic = Mgr.getAnalyzerOptions().getBooleanOption(

Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp?rev=336995=336994=336995=diff
==
--- cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp (original)
+++ cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp Fri Jul 13 05:54:47 
2018
@@ -737,6 +737,22 @@ void fMemsetTest2() {
 
//===--===//
 
 template 
+struct LambdaThisTest {
+  Callable functor;
+
+  LambdaThisTest(const Callable , int) : functor(functor) {
+// All good!
+  }
+};
+
+struct HasCapturableThis {
+  void fLambdaThisTest() {
+auto isEven = [this](int a) { return a % 2 == 0; }; // no-crash
+LambdaThisTest(isEven, int());
+  }
+};
+
+template 
 struct LambdaTest1 {
   Callable functor;
 
@@ -760,7 +776,7 @@ struct LambdaTest2 {
 
 void fLambdaTest2() {
   int b;
-  auto equals = [](int a) { return a == b; }; // 
expected-note{{uninitialized field 'this->functor.'}}
+  auto equals = [](int a) { return a == b; }; // 
expected-note{{uninitialized field 'this->functor.b'}}
   LambdaTest2(equals, int());

[PATCH] D48764: [Analyzer] Hotfix for iterator checkers: Mark left-hand side of `SymIntExpr` objects as live in the program state maps.

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

Looks good otherwise, please commit.


https://reviews.llvm.org/D48764



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


[PATCH] D48291: [analyzer][UninitializedObjectChecker] Fixed captured lambda variable name

2018-07-13 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 155361.
Szelethus marked an inline comment as done.
Szelethus added a comment.

Thanks! :)

Rebased to https://reviews.llvm.org/rC336994.


https://reviews.llvm.org/D48291

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object.cpp

Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- test/Analysis/cxx-uninitialized-object.cpp
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -737,6 +737,22 @@
 //===--===//
 
 template 
+struct LambdaThisTest {
+  Callable functor;
+
+  LambdaThisTest(const Callable , int) : functor(functor) {
+// All good!
+  }
+};
+
+struct HasCapturableThis {
+  void fLambdaThisTest() {
+auto isEven = [this](int a) { return a % 2 == 0; }; // no-crash
+LambdaThisTest(isEven, int());
+  }
+};
+
+template 
 struct LambdaTest1 {
   Callable functor;
 
@@ -760,7 +776,7 @@
 
 void fLambdaTest2() {
   int b;
-  auto equals = [](int a) { return a == b; }; // expected-note{{uninitialized field 'this->functor.'}}
+  auto equals = [](int a) { return a == b; }; // expected-note{{uninitialized field 'this->functor.b'}}
   LambdaTest2(equals, int());
 }
 #else
@@ -782,8 +798,8 @@
 namespace LT3Detail {
 
 struct RecordType {
-  int x; // expected-note{{uninitialized field 'this->functor..x'}}
-  int y; // expected-note{{uninitialized field 'this->functor..y'}}
+  int x; // expected-note{{uninitialized field 'this->functor.rec1.x'}}
+  int y; // expected-note{{uninitialized field 'this->functor.rec1.y'}}
 };
 
 } // namespace LT3Detail
@@ -826,6 +842,35 @@
 }
 #endif //PEDANTIC
 
+template 
+struct MultipleLambdaCapturesTest1 {
+  Callable functor;
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  MultipleLambdaCapturesTest1(const Callable , int) : functor(functor) {} // expected-warning{{2 uninitialized field}}
+};
+
+void fMultipleLambdaCapturesTest1() {
+  int b1, b2 = 3, b3;
+  auto equals = [, , ](int a) { return a == b1 == b2 == b3; }; // expected-note{{uninitialized field 'this->functor.b1'}}
+  // expected-note@-1{{uninitialized field 'this->functor.b3'}}
+  MultipleLambdaCapturesTest1(equals, int());
+}
+
+template 
+struct MultipleLambdaCapturesTest2 {
+  Callable functor;
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  MultipleLambdaCapturesTest2(const Callable , int) : functor(functor) {} // expected-warning{{1 uninitialized field}}
+};
+
+void fMultipleLambdaCapturesTest2() {
+  int b1, b2 = 3, b3;
+  auto equals = [b1, , ](int a) { return a == b1 == b2 == b3; }; // expected-note{{uninitialized field 'this->functor.b3'}}
+  MultipleLambdaCapturesTest2(equals, int());
+}
+
 //===--===//
 // System header tests.
 //===--===//
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -232,6 +232,10 @@
 static void printNoteMessage(llvm::raw_ostream ,
  const FieldChainInfo );
 
+/// Returns with Field's name. This is a helper function to get the correct name
+/// even if Field is a captured lambda variable.
+static StringRef getVariableName(const FieldDecl *Field);
+
 //===--===//
 //  Methods for UninitializedObjectChecker.
 //===--===//
@@ -581,30 +585,14 @@
 // "uninitialized field 'this->x'", but we can't refer to 'x' directly,
 // we need an explicit namespace resolution whether the uninit field was
 // 'D1::x' or 'D2::x'.
-//
-// TODO: If a field in the fieldchain is a captured lambda parameter, this
-// function constructs an empty string for it:
-//
-//   template  struct A {
-// Callable c;
-// A(const Callable , int) : c(c) {}
-//   };
-//
-//   int b; // say that this isn't zero initialized
-//   auto alwaysTrue = [](int a) { return true; };
-//
-// A call with these parameters: A::A(alwaysTrue, int())
-// will emit a note with the message "uninitialized field: 'this->c.'". If
-// possible, the lambda parameter name should be retrieved or be replaced with a
-// "" or something similar.
 void FieldChainInfo::print(llvm::raw_ostream ) const {
   if (Chain.isEmpty())
 return;
 
   const llvm::ImmutableListImpl *L =
   Chain.getInternalPointer();
   printTail(Out, L->getTail());
-  Out << L->getHead()->getDecl()->getNameAsString();
+  Out << getVariableName(L->getHead()->getDecl());
 }
 
 void FieldChainInfo::printTail(
@@ -615,7 +603,7 @@
 
   printTail(Out, L->getTail());
   const FieldDecl *Field = 

[PATCH] D49275: Thread safety: Run tests with both lock and capability attributes

2018-07-13 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! Thank you for this!


Repository:
  rC Clang

https://reviews.llvm.org/D49275



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


[PATCH] D48325: [analyzer][UninitializedObjectChecker] Support for MemberPointerTypes

2018-07-13 Thread Umann Kristóf via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL336994: [analyzer][UninitializedObjectChecker] Support for 
MemberPointerTypes (authored by Szelethus, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48325?vs=155356=155357#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48325

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp

Index: cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -416,14 +416,12 @@
 
 #ifdef PEDANTIC
 struct PointerToMemberFunctionTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  void (UsefulFunctions::*f)(void); // no-note
+  void (UsefulFunctions::*f)(void); // expected-note{{uninitialized field 'this->f'}}
   PointerToMemberFunctionTest1() {}
 };
 
 void fPointerToMemberFunctionTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberFunctionTest1(); // no-warning
+  PointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberFunctionTest2 {
@@ -460,14 +458,12 @@
 }
 
 struct PointerToMemberDataTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  int UsefulFunctions::*d; // no-note
+  int UsefulFunctions::*d; // expected-note{{uninitialized field 'this->d'}}
   PointerToMemberDataTest1() {}
 };
 
 void fPointerToMemberDataTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberDataTest1(); // no-warning
+  PointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberDataTest2 {
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -131,12 +131,10 @@
   // - a non-union record
   // - a pointer/reference
   // - an array
-  // - of a member pointer type
-  // - of a primitive type, which we'll define as either a BuiltinType or
-  //   EnumeralType.
+  // - of a primitive type, which we'll define later in a helper function.
   //   * the parent of each node is the object that contains it
-  //   * every leaf is an array, a primitive object, a member pointer, a nullptr
-  // or an undefined pointer.
+  //   * every leaf is an array, a primitive object, a nullptr or an undefined
+  //   pointer.
   //
   // Example:
   //
@@ -163,8 +161,8 @@
   //
   // From this we'll construct a vector of fieldchains, where each fieldchain
   // represents an uninitialized field. An uninitialized field may be a
-  // primitive object, a member pointer, a pointer, a pointee or a union without
-  // a single initialized field.
+  // primitive object, a pointer, a pointee or a union without a single
+  // initialized field.
   // In the above example, for the default constructor call we'll end up with
   // these fieldchains:
   //
@@ -189,10 +187,6 @@
   bool isPointerOrReferenceUninit(const FieldRegion *FR,
   FieldChainInfo LocalChain);
 
-  /// This method checks a region of MemberPointerType, and returns true if the
-  /// the pointer is uninitialized.
-  bool isMemberPointerUninit(const FieldRegion *FR, FieldChainInfo LocalChain);
-
   /// This method returns true if the value of a primitive object is
   /// uninitialized.
   bool isPrimitiveUninit(const SVal );
@@ -225,10 +219,13 @@
 /// known, and thus FD can not be analyzed.
 static bool isVoidPointer(const FieldDecl *FD);
 
-/// Returns true if T is a primitive type. We'll call a type primitive if it's
-/// either a BuiltinType or an EnumeralType.
+/// Returns true if T is a primitive type. We defined this type so that for
+/// objects that we'd only like analyze as much as checking whether their
+/// value is undefined or not, such as ints and doubles, can be analyzed with
+/// ease. This also helps ensuring that every special field type is handled
+/// correctly.
 static bool isPrimitiveType(const QualType ) {
-  return T->isBuiltinType() || T->isEnumeralType();
+  return T->isBuiltinType() || T->isEnumeralType() || T->isMemberPointerType();
 }
 
 /// Constructs a note message for a given FieldChainInfo object.
@@ -392,13 +389,6 @@
   continue;
 }
 
-if (T->isMemberPointerType()) {
-  if (isMemberPointerUninit(FR, LocalChain))
-ContainsUninitField = true;
-  continue;
-}
-
-// If this is a pointer or reference type.

r336994 - [analyzer][UninitializedObjectChecker] Support for MemberPointerTypes

2018-07-13 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Fri Jul 13 05:21:38 2018
New Revision: 336994

URL: http://llvm.org/viewvc/llvm-project?rev=336994=rev
Log:
[analyzer][UninitializedObjectChecker] Support for MemberPointerTypes

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp?rev=336994=336993=336994=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp Fri 
Jul 13 05:21:38 2018
@@ -131,12 +131,10 @@ private:
   // - a non-union record
   // - a pointer/reference
   // - an array
-  // - of a member pointer type
-  // - of a primitive type, which we'll define as either a BuiltinType or
-  //   EnumeralType.
+  // - of a primitive type, which we'll define later in a helper function.
   //   * the parent of each node is the object that contains it
-  //   * every leaf is an array, a primitive object, a member pointer, a 
nullptr
-  // or an undefined pointer.
+  //   * every leaf is an array, a primitive object, a nullptr or an undefined
+  //   pointer.
   //
   // Example:
   //
@@ -163,8 +161,8 @@ private:
   //
   // From this we'll construct a vector of fieldchains, where each fieldchain
   // represents an uninitialized field. An uninitialized field may be a
-  // primitive object, a member pointer, a pointer, a pointee or a union 
without
-  // a single initialized field.
+  // primitive object, a pointer, a pointee or a union without a single
+  // initialized field.
   // In the above example, for the default constructor call we'll end up with
   // these fieldchains:
   //
@@ -189,10 +187,6 @@ private:
   bool isPointerOrReferenceUninit(const FieldRegion *FR,
   FieldChainInfo LocalChain);
 
-  /// This method checks a region of MemberPointerType, and returns true if the
-  /// the pointer is uninitialized.
-  bool isMemberPointerUninit(const FieldRegion *FR, FieldChainInfo LocalChain);
-
   /// This method returns true if the value of a primitive object is
   /// uninitialized.
   bool isPrimitiveUninit(const SVal );
@@ -225,10 +219,13 @@ static bool isCalledByConstructor(const
 /// known, and thus FD can not be analyzed.
 static bool isVoidPointer(const FieldDecl *FD);
 
-/// Returns true if T is a primitive type. We'll call a type primitive if it's
-/// either a BuiltinType or an EnumeralType.
+/// Returns true if T is a primitive type. We defined this type so that for
+/// objects that we'd only like analyze as much as checking whether their
+/// value is undefined or not, such as ints and doubles, can be analyzed with
+/// ease. This also helps ensuring that every special field type is handled
+/// correctly.
 static bool isPrimitiveType(const QualType ) {
-  return T->isBuiltinType() || T->isEnumeralType();
+  return T->isBuiltinType() || T->isEnumeralType() || T->isMemberPointerType();
 }
 
 /// Constructs a note message for a given FieldChainInfo object.
@@ -392,13 +389,6 @@ bool FindUninitializedFields::isNonUnion
   continue;
 }
 
-if (T->isMemberPointerType()) {
-  if (isMemberPointerUninit(FR, LocalChain))
-ContainsUninitField = true;
-  continue;
-}
-
-// If this is a pointer or reference type.
 if (T->isPointerType() || T->isReferenceType()) {
   if (isPointerOrReferenceUninit(FR, LocalChain))
 ContainsUninitField = true;
@@ -542,14 +532,6 @@ bool FindUninitializedFields::isPointerO
   return false;
 }
 
-bool FindUninitializedFields::isMemberPointerUninit(const FieldRegion *FR,
-FieldChainInfo LocalChain) 
{
-  assert(FR->getDecl()->getType()->isMemberPointerType() &&
- "This function only checks regions that hold MemberPointerTypes!");
-  // TODO: Implement support for MemberPointerTypes.
-  return false;
-}
-
 bool FindUninitializedFields::isPrimitiveUninit(const SVal ) {
   if (V.isUndef())
 return true;

Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp?rev=336994=336993=336994=diff
==
--- cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp (original)
+++ cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp Fri Jul 13 
05:21:38 2018
@@ -416,14 +416,12 @@ struct UsefulFunctions {
 
 #ifdef PEDANTIC
 struct PointerToMemberFunctionTest1 {
-  // TODO: we'd expect the note {{uninitialized field 

[PATCH] D48325: [analyzer][UninitializedObjectChecker] Support for MemberPointerTypes

2018-07-13 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 155356.
Szelethus added a comment.

Thank you! ^-^

Rebased to https://reviews.llvm.org/rC336901.


https://reviews.llvm.org/D48325

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp

Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -416,14 +416,12 @@
 
 #ifdef PEDANTIC
 struct PointerToMemberFunctionTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  void (UsefulFunctions::*f)(void); // no-note
+  void (UsefulFunctions::*f)(void); // expected-note{{uninitialized field 'this->f'}}
   PointerToMemberFunctionTest1() {}
 };
 
 void fPointerToMemberFunctionTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberFunctionTest1(); // no-warning
+  PointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberFunctionTest2 {
@@ -460,14 +458,12 @@
 }
 
 struct PointerToMemberDataTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  int UsefulFunctions::*d; // no-note
+  int UsefulFunctions::*d; // expected-note{{uninitialized field 'this->d'}}
   PointerToMemberDataTest1() {}
 };
 
 void fPointerToMemberDataTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberDataTest1(); // no-warning
+  PointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberDataTest2 {
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -131,12 +131,10 @@
   // - a non-union record
   // - a pointer/reference
   // - an array
-  // - of a member pointer type
-  // - of a primitive type, which we'll define as either a BuiltinType or
-  //   EnumeralType.
+  // - of a primitive type, which we'll define later in a helper function.
   //   * the parent of each node is the object that contains it
-  //   * every leaf is an array, a primitive object, a member pointer, a nullptr
-  // or an undefined pointer.
+  //   * every leaf is an array, a primitive object, a nullptr or an undefined
+  //   pointer.
   //
   // Example:
   //
@@ -163,8 +161,8 @@
   //
   // From this we'll construct a vector of fieldchains, where each fieldchain
   // represents an uninitialized field. An uninitialized field may be a
-  // primitive object, a member pointer, a pointer, a pointee or a union without
-  // a single initialized field.
+  // primitive object, a pointer, a pointee or a union without a single
+  // initialized field.
   // In the above example, for the default constructor call we'll end up with
   // these fieldchains:
   //
@@ -189,10 +187,6 @@
   bool isPointerOrReferenceUninit(const FieldRegion *FR,
   FieldChainInfo LocalChain);
 
-  /// This method checks a region of MemberPointerType, and returns true if the
-  /// the pointer is uninitialized.
-  bool isMemberPointerUninit(const FieldRegion *FR, FieldChainInfo LocalChain);
-
   /// This method returns true if the value of a primitive object is
   /// uninitialized.
   bool isPrimitiveUninit(const SVal );
@@ -225,10 +219,13 @@
 /// known, and thus FD can not be analyzed.
 static bool isVoidPointer(const FieldDecl *FD);
 
-/// Returns true if T is a primitive type. We'll call a type primitive if it's
-/// either a BuiltinType or an EnumeralType.
+/// Returns true if T is a primitive type. We defined this type so that for
+/// objects that we'd only like analyze as much as checking whether their
+/// value is undefined or not, such as ints and doubles, can be analyzed with
+/// ease. This also helps ensuring that every special field type is handled
+/// correctly.
 static bool isPrimitiveType(const QualType ) {
-  return T->isBuiltinType() || T->isEnumeralType();
+  return T->isBuiltinType() || T->isEnumeralType() || T->isMemberPointerType();
 }
 
 /// Constructs a note message for a given FieldChainInfo object.
@@ -392,13 +389,6 @@
   continue;
 }
 
-if (T->isMemberPointerType()) {
-  if (isMemberPointerUninit(FR, LocalChain))
-ContainsUninitField = true;
-  continue;
-}
-
-// If this is a pointer or reference type.
 if (T->isPointerType() || T->isReferenceType()) {
   if (isPointerOrReferenceUninit(FR, LocalChain))
 ContainsUninitField = true;
@@ -542,14 +532,6 @@
   return false;
 }
 
-bool FindUninitializedFields::isMemberPointerUninit(const FieldRegion *FR,
-FieldChainInfo LocalChain) {
-  

[PATCH] D47632: [ASTImporter] Refactor Decl creation

2018-07-13 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

> I apologize for the delay in reviewing patches.

There is no need to apologize. On the contrary, we (me and my colleges at 
Ericsson) would like to thank you for the effort you had put into reviewing 
these patches. This period was hard, we provided so many patches lately, 
because we had the time to open source a lot of our work only from May. We 
still have a few minor patches, but all the major patches are in the llvm tree 
already (If you are interested, here you can track which patches we still plan 
to create: https://github.com/Ericsson/clang/projects/2 ). We always received 
very useful comments from you, which I think greatly increased the quality of 
the patches. Thanks again.


Repository:
  rL LLVM

https://reviews.llvm.org/D47632



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


[PATCH] D49289: [mips64][clang] Provide the signext attribute for i32 return values

2018-07-13 Thread Stefan Maksimovic via Phabricator via cfe-commits
smaksimovic created this revision.
smaksimovic added a reviewer: atanasyan.
Herald added subscribers: arichardson, sdardis.

Patch for the backend part of the problem here: https://reviews.llvm.org/D48374


https://reviews.llvm.org/D49289

Files:
  lib/CodeGen/TargetInfo.cpp


Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -6985,8 +6985,14 @@
   if (const EnumType *EnumTy = RetTy->getAs())
 RetTy = EnumTy->getDecl()->getIntegerType();
 
-  return (RetTy->isPromotableIntegerType() ? ABIArgInfo::getExtend(RetTy)
-   : ABIArgInfo::getDirect());
+  if (RetTy->isPromotableIntegerType())
+return ABIArgInfo::getExtend(RetTy);
+
+  if ((RetTy->isUnsignedIntegerOrEnumerationType() ||
+  RetTy->isSignedIntegerOrEnumerationType()) && Size == 32 && !IsO32)
+return ABIArgInfo::getSignExtend(RetTy);
+
+  return ABIArgInfo::getDirect();
 }
 
 void MipsABIInfo::computeInfo(CGFunctionInfo ) const {


Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -6985,8 +6985,14 @@
   if (const EnumType *EnumTy = RetTy->getAs())
 RetTy = EnumTy->getDecl()->getIntegerType();
 
-  return (RetTy->isPromotableIntegerType() ? ABIArgInfo::getExtend(RetTy)
-   : ABIArgInfo::getDirect());
+  if (RetTy->isPromotableIntegerType())
+return ABIArgInfo::getExtend(RetTy);
+
+  if ((RetTy->isUnsignedIntegerOrEnumerationType() ||
+  RetTy->isSignedIntegerOrEnumerationType()) && Size == 32 && !IsO32)
+return ABIArgInfo::getSignExtend(RetTy);
+
+  return ABIArgInfo::getDirect();
 }
 
 void MipsABIInfo::computeInfo(CGFunctionInfo ) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:662
+def note_suspicious_sizeof_memset_silence : Note<
+  "%select{parenthesize the third argument|cast the second argument to 'int'}0 
to silence">;
+

erik.pilkington wrote:
> Quuxplusone wrote:
> > If it were my codebase, I'd rather see a cast to `(unsigned char)` than a 
> > cast to `(int)`. (The second argument to memset is supposed to be a single 
> > byte.) Why did you pick `(int)` specifically?
> I chose `int` because that's the actual type of the second parameter to 
> `memset`, it just gets casted down to `unsigned char` internally. FWIW, 
> either type will suppress the warning. I'm fine with recommending `unsigned 
> char` if you have a strong preference for it.
My preference is for `int` as well.



Comment at: clang/lib/Sema/SemaChecking.cpp:7975-7976
+static void CheckMemsetSizeof(Sema , unsigned BId, const CallExpr *Call) {
+  if (BId != Builtin::BImemset)
+return;
+

This functionality should apply equally to `wmemset()` as well, should it not? 
The only difference I can think of would be that the type should be cast to 
`wchar_t` instead of `int` to silence the warning.



Comment at: clang/lib/Sema/SemaChecking.cpp:7997
+
+
+  // If the function is defined as a builtin macro, do not show macro 
expansion.

Spurious whitespace.


https://reviews.llvm.org/D49112



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


[PATCH] D49285: [clang-tidy] readability-inconsistent-declaration-parameter-name: accept approximate name matches.

2018-07-13 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL336992: [clang-tidy] 
readability-inconsistent-declaration-parameter-name: accept… (authored by 
sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D49285

Files:
  
clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
  
clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
  
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-inconsistent-declaration-parameter-name.rst
  
clang-tools-extra/trunk/test/clang-tidy/readability-inconsistent-declaration-parameter-name-strict.cpp
  
clang-tools-extra/trunk/test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp

Index: clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
@@ -90,10 +90,20 @@
   return true;
 }
 
+bool nameMatch(StringRef L, StringRef R, bool Strict) {
+  if (Strict)
+return L.empty() || R.empty() || L == R;
+  // We allow two names if one is a prefix/suffix of the other, ignoring case.
+  // Important special case: this is true if either parameter has no name!
+  return L.startswith_lower(R) || R.startswith_lower(L) ||
+ L.endswith_lower(R) || R.endswith_lower(L);
+}
+
 DifferingParamsContainer
 findDifferingParamsInDeclaration(const FunctionDecl *ParameterSourceDeclaration,
  const FunctionDecl *OtherDeclaration,
- const FunctionDecl *OriginalDeclaration) {
+ const FunctionDecl *OriginalDeclaration,
+ bool Strict) {
   DifferingParamsContainer DifferingParams;
 
   auto SourceParamIt = ParameterSourceDeclaration->param_begin();
@@ -106,8 +116,7 @@
 
 // FIXME: Provide a way to extract commented out parameter name from comment
 // next to it.
-if (!SourceParamName.empty() && !OtherParamName.empty() &&
-SourceParamName != OtherParamName) {
+if (!nameMatch(SourceParamName, OtherParamName, Strict)) {
   SourceRange OtherParamNameRange =
   DeclarationNameInfo((*OtherParamIt)->getDeclName(),
   (*OtherParamIt)->getLocation())
@@ -128,9 +137,9 @@
 }
 
 InconsistentDeclarationsContainer
-findInconsitentDeclarations(const FunctionDecl *OriginalDeclaration,
+findInconsistentDeclarations(const FunctionDecl *OriginalDeclaration,
 const FunctionDecl *ParameterSourceDeclaration,
-SourceManager ) {
+SourceManager , bool Strict) {
   InconsistentDeclarationsContainer InconsistentDeclarations;
   SourceLocation ParameterSourceLocation =
   ParameterSourceDeclaration->getLocation();
@@ -141,7 +150,7 @@
   DifferingParamsContainer DifferingParams =
   findDifferingParamsInDeclaration(ParameterSourceDeclaration,
OtherDeclaration,
-   OriginalDeclaration);
+   OriginalDeclaration, Strict);
   if (!DifferingParams.empty()) {
 InconsistentDeclarations.emplace_back(OtherDeclaration->getLocation(),
   std::move(DifferingParams));
@@ -284,6 +293,7 @@
 void InconsistentDeclarationParameterNameCheck::storeOptions(
 ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "IgnoreMacros", IgnoreMacros);
+  Options.store(Opts, "Strict", Strict);
 }
 
 void InconsistentDeclarationParameterNameCheck::registerMatchers(
@@ -305,9 +315,9 @@
   getParameterSourceDeclaration(OriginalDeclaration);
 
   InconsistentDeclarationsContainer InconsistentDeclarations =
-  findInconsitentDeclarations(OriginalDeclaration,
-  ParameterSourceDeclaration,
-  *Result.SourceManager);
+  findInconsistentDeclarations(OriginalDeclaration,
+   ParameterSourceDeclaration,
+   *Result.SourceManager, Strict);
   if (InconsistentDeclarations.empty()) {
 // Avoid unnecessary further visits.
 markRedeclarationsAsVisited(OriginalDeclaration);
Index: clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
+++ clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
@@ -28,7 +28,8 @@
   

[clang-tools-extra] r336992 - [clang-tidy] readability-inconsistent-declaration-parameter-name: accept approximate name matches.

2018-07-13 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri Jul 13 04:41:56 2018
New Revision: 336992

URL: http://llvm.org/viewvc/llvm-project?rev=336992=rev
Log:
[clang-tidy] readability-inconsistent-declaration-parameter-name: accept 
approximate name matches.

Summary:
The goal is to reduce false positives when the difference is intentional, like:

foo(StringRef name);
foo(StringRef name_ref) {
  string name = cleanup(name_ref);
  ...
}

Or semantically unimportant, like:
foo(StringRef full_name);
foo(StringRef name) { ... }

There are other matching names we won't recognise (e.g. syns vs synonyms) but
this catches many that we see in practice, and gives people a systematic
workaround.

The old behavior is available as a 'Strict' option.

Subscribers: xazax.hun, cfe-commits

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

Added:

clang-tools-extra/trunk/test/clang-tidy/readability-inconsistent-declaration-parameter-name-strict.cpp
Modified:

clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp

clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-inconsistent-declaration-parameter-name.rst

clang-tools-extra/trunk/test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp?rev=336992=336991=336992=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
 Fri Jul 13 04:41:56 2018
@@ -90,10 +90,20 @@ bool checkIfFixItHintIsApplicable(
   return true;
 }
 
+bool nameMatch(StringRef L, StringRef R, bool Strict) {
+  if (Strict)
+return L.empty() || R.empty() || L == R;
+  // We allow two names if one is a prefix/suffix of the other, ignoring case.
+  // Important special case: this is true if either parameter has no name!
+  return L.startswith_lower(R) || R.startswith_lower(L) ||
+ L.endswith_lower(R) || R.endswith_lower(L);
+}
+
 DifferingParamsContainer
 findDifferingParamsInDeclaration(const FunctionDecl 
*ParameterSourceDeclaration,
  const FunctionDecl *OtherDeclaration,
- const FunctionDecl *OriginalDeclaration) {
+ const FunctionDecl *OriginalDeclaration,
+ bool Strict) {
   DifferingParamsContainer DifferingParams;
 
   auto SourceParamIt = ParameterSourceDeclaration->param_begin();
@@ -106,8 +116,7 @@ findDifferingParamsInDeclaration(const F
 
 // FIXME: Provide a way to extract commented out parameter name from 
comment
 // next to it.
-if (!SourceParamName.empty() && !OtherParamName.empty() &&
-SourceParamName != OtherParamName) {
+if (!nameMatch(SourceParamName, OtherParamName, Strict)) {
   SourceRange OtherParamNameRange =
   DeclarationNameInfo((*OtherParamIt)->getDeclName(),
   (*OtherParamIt)->getLocation())
@@ -128,9 +137,9 @@ findDifferingParamsInDeclaration(const F
 }
 
 InconsistentDeclarationsContainer
-findInconsitentDeclarations(const FunctionDecl *OriginalDeclaration,
+findInconsistentDeclarations(const FunctionDecl *OriginalDeclaration,
 const FunctionDecl *ParameterSourceDeclaration,
-SourceManager ) {
+SourceManager , bool Strict) {
   InconsistentDeclarationsContainer InconsistentDeclarations;
   SourceLocation ParameterSourceLocation =
   ParameterSourceDeclaration->getLocation();
@@ -141,7 +150,7 @@ findInconsitentDeclarations(const Functi
   DifferingParamsContainer DifferingParams =
   findDifferingParamsInDeclaration(ParameterSourceDeclaration,
OtherDeclaration,
-   OriginalDeclaration);
+   OriginalDeclaration, Strict);
   if (!DifferingParams.empty()) {
 InconsistentDeclarations.emplace_back(OtherDeclaration->getLocation(),
   std::move(DifferingParams));
@@ -284,6 +293,7 @@ void formatDiagnostics(
 void InconsistentDeclarationParameterNameCheck::storeOptions(
 ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "IgnoreMacros", IgnoreMacros);
+  Options.store(Opts, "Strict", Strict);
 }
 
 void InconsistentDeclarationParameterNameCheck::registerMatchers(
@@ -305,9 +315,9 @@ void InconsistentDeclarationParameterNam
   getParameterSourceDeclaration(OriginalDeclaration);
 
   

[PATCH] D49285: [clang-tidy] readability-inconsistent-declaration-parameter-name: accept approximate name matches.

2018-07-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49285



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


[PATCH] D48958: [clang][ubsan] Implicit Cast Sanitizer - integer truncation - clang part

2018-07-13 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In https://reviews.llvm.org/D48958#1160494, @lebedev.ri wrote:

> In https://reviews.llvm.org/D48958#1160479, @vsk wrote:
>
> > In https://reviews.llvm.org/D48958#1160435, @lebedev.ri wrote:
> >
> > > Thank you for taking a look!
> > >
> > > In https://reviews.llvm.org/D48958#1160381, @vsk wrote:
> > >
> > > > I have some minor comments but overall I think this is in good shape. 
> > > > It would be great to see some compile-time numbers just to make sure 
> > > > this is tractable. I'm pretty sure -fsanitize=null would fire more 
> > > > often across a codebase than this check, so I don't anticipate a big 
> > > > surprise here.
> > >
> > >
> > > Could you please clarify, which numbers are you looking for, specifically?
> > >  The time it takes to build llvm stage2 with `-fsanitize=implicit-cast`?
> > >  Or the time it takes to build llvm stage3 with compiler built with 
> > > `-fsanitize=implicit-cast`?
> >
> >
> > I had in mind measuring the difference between -fsanitize=undefined and 
> > -fsanitize=undefined,implicit-cast, with a stage2 compiler. I think that 
> > captures the expected use case: existing ubsan users enabling this new 
> > check.
>
>
> FWIW, i'm trying to look into optimizing these new IR patterns right now 
> https://reviews.llvm.org/D49179 https://reviews.llvm.org/D49247.
>
> >> (The numbers won't be too representable, whole stage-1 takes ~40 minutes 
> >> here...)
> > 
> > Ah I see, I'll run a few builds and take a stab at it, then.
>
> Yes, please, thank you!


The stage2 build traps before it finishes:

  FAILED: lib/IR/AttributesCompatFunc.inc.tmp
  cd /Users/vsk/src/builds/llvm.org-lldbsan-stage2-R/tools/clang/stage2-bins && 
/Users/vsk/src/builds/llvm.org-lldbsan-stage2-R/tools/clang/stage2-bins/bin/llvm-tblgen
 -gen-attrs -I /Users/vsk/src/llvm.org-lldbsan/llvm/lib/IR -I 
/Users/vsk/src/llvm.org-lldbsan/llvm/include 
/Users/vsk/src/llvm.org-lldbsan/llvm/lib/IR/AttributesCompatFunc.td -o 
lib/IR/AttributesCompatFunc.inc.tmp -d lib/IR/AttributesCompatFunc.inc.d
  /Users/vsk/src/llvm.org-lldbsan/llvm/include/llvm/ADT/DenseMap.h:732:66: 
runtime error: implicit cast from type 'uint64_t' (aka 'unsigned long long') of 
value 4294967296 (64-bit, unsigned) to type 'unsigned int' changed the value to 
0 (32-bit, unsigned)
  /bin/sh: line 1: 96848 Abort trap: 6

This looks like a false positive to me. It's complaining about 
`static_cast(NextPowerOf2(...))`, but the static_cast is explicit.


Repository:
  rC Clang

https://reviews.llvm.org/D48958



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


[PATCH] D48958: [clang][ubsan] Implicit Cast Sanitizer - integer truncation - clang part

2018-07-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D48958#1160848, @vsk wrote:

> In https://reviews.llvm.org/D48958#1160494, @lebedev.ri wrote:
>
> > In https://reviews.llvm.org/D48958#1160479, @vsk wrote:
> >
> > > In https://reviews.llvm.org/D48958#1160435, @lebedev.ri wrote:
> > >
> > > > Thank you for taking a look!
> > > >
> > > > In https://reviews.llvm.org/D48958#1160381, @vsk wrote:
> > > >
> > > > > I have some minor comments but overall I think this is in good shape. 
> > > > > It would be great to see some compile-time numbers just to make sure 
> > > > > this is tractable. I'm pretty sure -fsanitize=null would fire more 
> > > > > often across a codebase than this check, so I don't anticipate a big 
> > > > > surprise here.
> > > >
> > > >
> > > > Could you please clarify, which numbers are you looking for, 
> > > > specifically?
> > > >  The time it takes to build llvm stage2 with `-fsanitize=implicit-cast`?
> > > >  Or the time it takes to build llvm stage3 with compiler built with 
> > > > `-fsanitize=implicit-cast`?
> > >
> > >
> > > I had in mind measuring the difference between -fsanitize=undefined and 
> > > -fsanitize=undefined,implicit-cast, with a stage2 compiler. I think that 
> > > captures the expected use case: existing ubsan users enabling this new 
> > > check.
> >
> >
> > FWIW, i'm trying to look into optimizing these new IR patterns right now 
> > https://reviews.llvm.org/D49179 https://reviews.llvm.org/D49247.
> >
> > >> (The numbers won't be too representable, whole stage-1 takes ~40 minutes 
> > >> here...)
> > > 
> > > Ah I see, I'll run a few builds and take a stab at it, then.
> >
> > Yes, please, thank you!
>
>
> The stage2 build traps before it finishes:
>
>   FAILED: lib/IR/AttributesCompatFunc.inc.tmp
>   cd /Users/vsk/src/builds/llvm.org-lldbsan-stage2-R/tools/clang/stage2-bins 
> && 
> /Users/vsk/src/builds/llvm.org-lldbsan-stage2-R/tools/clang/stage2-bins/bin/llvm-tblgen
>  -gen-attrs -I /Users/vsk/src/llvm.org-lldbsan/llvm/lib/IR -I 
> /Users/vsk/src/llvm.org-lldbsan/llvm/include 
> /Users/vsk/src/llvm.org-lldbsan/llvm/lib/IR/AttributesCompatFunc.td -o 
> lib/IR/AttributesCompatFunc.inc.tmp -d lib/IR/AttributesCompatFunc.inc.d
>   /Users/vsk/src/llvm.org-lldbsan/llvm/include/llvm/ADT/DenseMap.h:732:66: 
> runtime error: implicit cast from type 'uint64_t' (aka 'unsigned long long') 
> of value 4294967296 (64-bit, unsigned) to type 'unsigned int' changed the 
> value to 0 (32-bit, unsigned)
>   /bin/sh: line 1: 96848 Abort trap: 6
>
>
> This looks like a false positive to me. It's complaining about 
> `static_cast(NextPowerOf2(...))`, but the static_cast is explicit.


Good to know, so the stack-based logic for `ExplicitCastExpr` detection needs 
further tests/refinements..


Repository:
  rC Clang

https://reviews.llvm.org/D48958



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


[PATCH] D48958: [clang][ubsan] Implicit Cast Sanitizer - integer truncation - clang part

2018-07-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D48958#1160853, @lebedev.ri wrote:

> In https://reviews.llvm.org/D48958#1160848, @vsk wrote:
>
> > <...>
> >  The stage2 build traps before it finishes:
> >
> >   FAILED: lib/IR/AttributesCompatFunc.inc.tmp
> >   cd 
> > /Users/vsk/src/builds/llvm.org-lldbsan-stage2-R/tools/clang/stage2-bins && 
> > /Users/vsk/src/builds/llvm.org-lldbsan-stage2-R/tools/clang/stage2-bins/bin/llvm-tblgen
> >  -gen-attrs -I /Users/vsk/src/llvm.org-lldbsan/llvm/lib/IR -I 
> > /Users/vsk/src/llvm.org-lldbsan/llvm/include 
> > /Users/vsk/src/llvm.org-lldbsan/llvm/lib/IR/AttributesCompatFunc.td -o 
> > lib/IR/AttributesCompatFunc.inc.tmp -d lib/IR/AttributesCompatFunc.inc.d
> >   /Users/vsk/src/llvm.org-lldbsan/llvm/include/llvm/ADT/DenseMap.h:732:66: 
> > runtime error: implicit cast from type 'uint64_t' (aka 'unsigned long 
> > long') of value 4294967296 (64-bit, unsigned) to type 'unsigned int' 
> > changed the value to 0 (32-bit, unsigned)
> >   /bin/sh: line 1: 96848 Abort trap: 6
> >
> >
> > This looks like a false positive to me. It's complaining about 
> > `static_cast(NextPowerOf2(...))`, but the static_cast is explicit.
>
>
> Good to know, so the stack-based logic for `ExplicitCastExpr` detection needs 
> further tests/refinements..


creduced down to:

  template  a b(a c, const a ) {
if (d)
  ;
return c;
  }
  int e = b(4, static_cast(4294967296));
  int main() {}

https://godbolt.org/g/1kwGk9

  $ ./a.out 
  test.cpp:6:46: runtime error: implicit cast from type 'long' of value 
4294967296 (64-bit, signed) to type 'unsigned int' changed the value to 0 
(32-bit, unsigned)
  #0 0x232f56 in _GLOBAL__sub_I_test.cpp 
(/home/lebedevri/CREDUCE/a.out+0x232f56)
  #1 0x232fbc in __libc_csu_init (/home/lebedevri/CREDUCE/a.out+0x232fbc)
  #2 0x7fa8c113aaa7 in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x22aa7)
  #3 0x212029 in _start (/home/lebedevri/CREDUCE/a.out+0x212029)


Repository:
  rC Clang

https://reviews.llvm.org/D48958



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


[PATCH] D49285: [clang-tidy] readability-inconsistent-declaration-parameter-name: accept approximate name matches.

2018-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 155343.
sammccall added a comment.

Restrict matches to prefix/suffix, not substring.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49285

Files:
  clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
  clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
  docs/clang-tidy/checks/readability-inconsistent-declaration-parameter-name.rst
  test/clang-tidy/readability-inconsistent-declaration-parameter-name-strict.cpp
  test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp

Index: test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp
===
--- test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp
+++ test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp
@@ -2,6 +2,8 @@
 
 void consistentFunction(int a, int b, int c);
 void consistentFunction(int a, int b, int c);
+void consistentFunction(int prefixA, int b, int cSuffix);
+void consistentFunction(int a, int b, int c);
 void consistentFunction(int a, int b, int /*c*/);
 void consistentFunction(int /*c*/, int /*c*/, int /*c*/);
 
Index: test/clang-tidy/readability-inconsistent-declaration-parameter-name-strict.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-inconsistent-declaration-parameter-name-strict.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s readability-inconsistent-declaration-parameter-name %t -- \
+// RUN:   -config="{CheckOptions: [{key: readability-inconsistent-declaration-parameter-name.Strict, value: 1}]}" \
+// RUN:   -- -std=c++11
+
+void inconsistentFunction(int a, int b, int c);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'inconsistentFunction' has 1 other declaration with different parameter names
+void inconsistentFunction(int prefixA, int b, int cSuffix);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: note: the 1st inconsistent declaration seen here
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: differing parameters are named here: ('prefixA', 'cSuffix'), in the other declaration: ('a', 'c')
+void inconsistentFunction(int a, int b, int c);
+void inconsistentFunction(int /*c*/, int /*c*/, int /*c*/);
Index: docs/clang-tidy/checks/readability-inconsistent-declaration-parameter-name.rst
===
--- docs/clang-tidy/checks/readability-inconsistent-declaration-parameter-name.rst
+++ docs/clang-tidy/checks/readability-inconsistent-declaration-parameter-name.rst
@@ -29,6 +29,15 @@
   void foo(int a);
   void foo(int); // no warning
 
+One name is also allowed to be a case-insensitive prefix/suffix of the other:
+
+.. code-block:: c++
+
+  void foo(int count);
+  void foo(int count_input) { // no warning
+int count = adjustCount(count_input);
+  }
+
 To help with refactoring, in some cases fix-it hints are generated to align
 parameter names to a single naming convention. This works with the assumption
 that the function definition is the most up-to-date version, as it directly
@@ -47,3 +56,8 @@
 
If this option is set to non-zero (default is `1`), the check will not warn
about names declared inside macros.
+
+.. option:: Strict
+
+   If this option is set to non-zero (default is `0`), then names must match
+   exactly (or be absent).
Index: clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
===
--- clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
+++ clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
@@ -28,7 +28,8 @@
   InconsistentDeclarationParameterNameCheck(StringRef Name,
 ClangTidyContext *Context)
   : ClangTidyCheck(Name, Context),
-IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", 1) != 0) {}
+IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", 1) != 0),
+Strict(Options.getLocalOrGlobal("Strict", 0) != 0) {}
 
   void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
@@ -39,6 +40,7 @@
 
   llvm::DenseSet VisitedDeclarations;
   const bool IgnoreMacros;
+  const bool Strict;
 };
 
 } // namespace readability
Index: clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
===
--- clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
+++ clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
@@ -90,10 +90,20 @@
   return true;
 }
 
+bool nameMatch(StringRef L, StringRef R, bool Strict) {
+  if (Strict)
+return L.empty() || R.empty() || L == R;
+  // We allow two names if one is a prefix/suffix of the other, ignoring case.
+  // Important special case: this is true if either parameter has no name!
+  return 

[PATCH] D49285: [clang-tidy] readability-inconsistent-declaration-parameter-name: accept approximate name matches.

2018-07-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: 
clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp:96
+bool nameMatch(StringRef L, StringRef R) {
+  return L.contains_lower(R) || R.contains_lower(L);
+}

I have a concern that this is too general -- it will cover the middle case like 
`inBFix` in you test, which seems not happen often in the real world.

Two important cases are prefix and suffix, maybe just restrict to these two 
cases?  


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49285



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


[PATCH] D38075: Fix PR34668 - P0704R1 implementation is too permissive

2018-07-13 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete accepted this revision.
Rakete added a comment.
This revision is now accepted and ready to land.

LGTM with a small change in the error message that needs fixing.

Do you need someone to commit it?


https://reviews.llvm.org/D38075



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


  1   2   >