r300391 - Revert "[ObjC] Use empty Objective-C collection literal constants when"

2017-04-14 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Sat Apr 15 00:44:27 2017
New Revision: 300391

URL: http://llvm.org/viewvc/llvm-project?rev=300391=rev
Log:
Revert "[ObjC] Use empty Objective-C collection literal constants when"

This reverts commit r300389. There were mistakes in the changes I made
to CodeGen.

Removed:
cfe/trunk/test/CodeGenObjC/empty-collection-literals.m
Modified:
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/include/clang/Basic/ObjCRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ObjCRuntime.h?rev=300391=300390=300391=diff
==
--- cfe/trunk/include/clang/Basic/ObjCRuntime.h (original)
+++ cfe/trunk/include/clang/Basic/ObjCRuntime.h Sat Apr 15 00:44:27 2017
@@ -326,20 +326,6 @@ public:
 }
   }
 
-  /// Are the empty collection symbols available?
-  bool hasEmptyCollections() const {
-switch (getKind()) {
-default:
-  return false;
-case MacOSX:
-  return getVersion() >= VersionTuple(10, 11);
-case iOS:
-  return getVersion() >= VersionTuple(9);
-case WatchOS:
-  return getVersion() >= VersionTuple(2);
-}
-  }
-
   /// \brief Try to parse an Objective-C runtime specification from the given
   /// string.
   ///

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=300391=300390=300391=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Sat Apr 15 00:44:27 2017
@@ -117,22 +117,10 @@ llvm::Value *CodeGenFunction::EmitObjCCo
   const ObjCArrayLiteral *ALE = dyn_cast(E);
   if (!ALE)
 DLE = cast(E);
-
-  // Optimize empty collections by referencing constants, when available.
+  
+  // Compute the type of the array we're initializing.
   uint64_t NumElements = 
 ALE ? ALE->getNumElements() : DLE->getNumElements();
-  if (NumElements == 0 && CGM.getLangOpts().ObjCRuntime.hasEmptyCollections()) 
{
-StringRef ConstantName = ALE ? "__NSArray0__" : "__NSDictionary0__";
-QualType IdTy(CGM.getContext().getObjCIdType());
-llvm::Constant *Constant =
-CGM.CreateRuntimeVariable(ConvertType(IdTy), ConstantName);
-LValue LV = LValue::MakeAddr(Constant, IdTy,
- Context.getTypeAlignInChars(IdTy), Context);
-return Builder.CreateBitCast(EmitLoadOfScalar(LV, E->getLocStart()),
- ConvertType(E->getType()));
-  }
-
-  // Compute the type of the array we're initializing.
   llvm::APInt APNumElements(Context.getTypeSize(Context.getSizeType()),
 NumElements);
   QualType ElementType = Context.getObjCIdType().withConst();

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=300391=300390=300391=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat Apr 15 00:44:27 2017
@@ -5980,21 +5980,9 @@ ExprResult Sema::MaybeBindToTemporary(Ex
   } else if (ObjCBoxedExpr *BoxedExpr = dyn_cast(E)) {
 D = BoxedExpr->getBoxingMethod();
   } else if (ObjCArrayLiteral *ArrayLit = dyn_cast(E)) {
-// Don't do reclaims if we're using the zero-element array
-// constant.
-if (ArrayLit->getNumElements() == 0 &&
-Context.getLangOpts().ObjCRuntime.hasEmptyCollections())
-  return E;
-
 D = ArrayLit->getArrayWithObjectsMethod();
   } else if (ObjCDictionaryLiteral *DictLit
 = dyn_cast(E)) {
-// Don't do reclaims if we're using the zero-element dictionary
-// constant.
-if (DictLit->getNumElements() == 0 &&
-Context.getLangOpts().ObjCRuntime.hasEmptyCollections())
-  return E;
-
 D = DictLit->getDictWithObjectsMethod();
   }
 

Removed: cfe/trunk/test/CodeGenObjC/empty-collection-literals.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/empty-collection-literals.m?rev=300390=auto
==
--- cfe/trunk/test/CodeGenObjC/empty-collection-literals.m (original)
+++ cfe/trunk/test/CodeGenObjC/empty-collection-literals.m (removed)
@@ -1,51 +0,0 @@
-// RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-macosx10.10.0 
-fobjc-runtime=macosx-10.10.0 -emit-llvm -fblocks -fobjc-arc 
-fobjc-runtime-has-weak -o - %s | FileCheck 
-check-prefix=CHECK-WITHOUT-EMPTY-COLLECTIONS %s
-// RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-macosx10.11.0 
-fobjc-runtime=macosx-10.11.0 -emit-llvm -fblocks -fobjc-arc 
-fobjc-runtime-has-weak -o - %s | FileCheck 

[libcxx] r300390 - [libcxx] Fix check-cxx-abilist on OS X

2017-04-14 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sat Apr 15 00:41:45 2017
New Revision: 300390

URL: http://llvm.org/viewvc/llvm-project?rev=300390=rev
Log:
[libcxx] Fix check-cxx-abilist on OS X

Summary:
Recent commits broke the check-cxx-abilist by changing the default OS X to use 
`-rexport_library` instead of `-reexport_symbol_list`. Apparently 
`-reexport_library` doesn't export the symbols into `libc++.dylib`s symbol 
table, whereas `-reexport_symbol_list` does.

This means the change removed ~500 symbols from the symbol table. I've been 
told this change is non ABI breaking, but it does make it harder to maintain 
the ABI lists, and hence the ABI.

This patch fixes the issue by switching back to `-reexport_symbol_list`. It 
still avoid the issues fixed in r299052 by putting the new/delete symbols in a 
different symbol list file, which is only exported when 
LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS in OFF.


Reviewers: mehdi_amini, smeenai, dexonsmith

Reviewed By: smeenai

Subscribers: mgorny, cfe-commits

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

Added:
libcxx/trunk/lib/libc++abi-new-delete.exp
Modified:
libcxx/trunk/lib/CMakeLists.txt
libcxx/trunk/lib/libc++abi2.exp

Modified: libcxx/trunk/lib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=300390=300389=300390=diff
==
--- libcxx/trunk/lib/CMakeLists.txt (original)
+++ libcxx/trunk/lib/CMakeLists.txt Sat Apr 15 00:41:45 2017
@@ -155,11 +155,7 @@ if (LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRA
   
"-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp"
   "/usr/lib/libSystem.B.dylib")
   else()
-if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
-# We can't use the "-reexported_symbols_list" when we build the
-# new/delete operators as part of the dylib: the linker would fail.
-set(OSX_RE_EXPORT_LINE 
"-Wl,-reexport_library,${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib")
-   elseif (DEFINED CMAKE_OSX_SYSROOT AND NOT CMAKE_OSX_SYSROOT STREQUAL "")
+ if (DEFINED CMAKE_OSX_SYSROOT AND NOT CMAKE_OSX_SYSROOT STREQUAL "")
   list(FIND CMAKE_OSX_ARCHITECTURES "armv7" OSX_HAS_ARMV7)
   if (NOT OSX_HAS_ARMV7 EQUAL -1)
 set(OSX_RE_EXPORT_LINE
@@ -171,8 +167,10 @@ if (LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRA
   endif()
 else()
   set(OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib 
-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp")
+  if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
+add_link_flags("/usr/lib/libc++abi.dylib 
-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi-new-delete.exp")
+  endif()
 endif()
-
 add_link_flags(
   "-compatibility_version 1"
   "-install_name /usr/lib/libc++.1.dylib"

Added: libcxx/trunk/lib/libc++abi-new-delete.exp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/libc%2B%2Babi-new-delete.exp?rev=300390=auto
==
--- libcxx/trunk/lib/libc++abi-new-delete.exp (added)
+++ libcxx/trunk/lib/libc++abi-new-delete.exp Sat Apr 15 00:41:45 2017
@@ -0,0 +1,8 @@
+__ZdaPv
+__ZdlPv
+__ZdlPvRKSt9nothrow_t
+__Znam
+__ZdaPvRKSt9nothrow_t
+__Znwm
+__ZnwmRKSt9nothrow_t
+__ZnamRKSt9nothrow_t

Modified: libcxx/trunk/lib/libc++abi2.exp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/libc%2B%2Babi2.exp?rev=300390=300389=300390=diff
==
--- libcxx/trunk/lib/libc++abi2.exp (original)
+++ libcxx/trunk/lib/libc++abi2.exp Sat Apr 15 00:41:45 2017
@@ -209,14 +209,6 @@ __ZNSt20bad_array_new_lengthC2Ev
 __ZNSt20bad_array_new_lengthD0Ev
 __ZNSt20bad_array_new_lengthD2Ev
 __ZSt10unexpectedv
-__ZdaPv
-__ZdlPv
-__ZdlPvRKSt9nothrow_t
-__Znam
-__ZdaPvRKSt9nothrow_t
-__Znwm
-__ZnwmRKSt9nothrow_t
-__ZnamRKSt9nothrow_t
 __ZTISt10bad_typeid
 __ZTISt8bad_cast
 ___cxa_bad_typeid


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


r300389 - [ObjC] Use empty Objective-C collection literal constants when

2017-04-14 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Sat Apr 15 00:31:35 2017
New Revision: 300389

URL: http://llvm.org/viewvc/llvm-project?rev=300389=rev
Log:
[ObjC] Use empty Objective-C collection literal constants when
available.

Original patch by Douglas Gregor with minor modifications.

rdar://problem/20689633

Added:
cfe/trunk/test/CodeGenObjC/empty-collection-literals.m
Modified:
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/include/clang/Basic/ObjCRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ObjCRuntime.h?rev=300389=300388=300389=diff
==
--- cfe/trunk/include/clang/Basic/ObjCRuntime.h (original)
+++ cfe/trunk/include/clang/Basic/ObjCRuntime.h Sat Apr 15 00:31:35 2017
@@ -326,6 +326,20 @@ public:
 }
   }
 
+  /// Are the empty collection symbols available?
+  bool hasEmptyCollections() const {
+switch (getKind()) {
+default:
+  return false;
+case MacOSX:
+  return getVersion() >= VersionTuple(10, 11);
+case iOS:
+  return getVersion() >= VersionTuple(9);
+case WatchOS:
+  return getVersion() >= VersionTuple(2);
+}
+  }
+
   /// \brief Try to parse an Objective-C runtime specification from the given
   /// string.
   ///

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=300389=300388=300389=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Sat Apr 15 00:31:35 2017
@@ -117,10 +117,22 @@ llvm::Value *CodeGenFunction::EmitObjCCo
   const ObjCArrayLiteral *ALE = dyn_cast(E);
   if (!ALE)
 DLE = cast(E);
-  
-  // Compute the type of the array we're initializing.
+
+  // Optimize empty collections by referencing constants, when available.
   uint64_t NumElements = 
 ALE ? ALE->getNumElements() : DLE->getNumElements();
+  if (NumElements == 0 && CGM.getLangOpts().ObjCRuntime.hasEmptyCollections()) 
{
+StringRef ConstantName = ALE ? "__NSArray0__" : "__NSDictionary0__";
+QualType IdTy(CGM.getContext().getObjCIdType());
+llvm::Constant *Constant =
+CGM.CreateRuntimeVariable(ConvertType(IdTy), ConstantName);
+LValue LV = LValue::MakeAddr(Constant, IdTy,
+ Context.getTypeAlignInChars(IdTy), Context);
+return Builder.CreateBitCast(EmitLoadOfScalar(LV, E->getLocStart()),
+ ConvertType(E->getType()));
+  }
+
+  // Compute the type of the array we're initializing.
   llvm::APInt APNumElements(Context.getTypeSize(Context.getSizeType()),
 NumElements);
   QualType ElementType = Context.getObjCIdType().withConst();

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=300389=300388=300389=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat Apr 15 00:31:35 2017
@@ -5980,9 +5980,21 @@ ExprResult Sema::MaybeBindToTemporary(Ex
   } else if (ObjCBoxedExpr *BoxedExpr = dyn_cast(E)) {
 D = BoxedExpr->getBoxingMethod();
   } else if (ObjCArrayLiteral *ArrayLit = dyn_cast(E)) {
+// Don't do reclaims if we're using the zero-element array
+// constant.
+if (ArrayLit->getNumElements() == 0 &&
+Context.getLangOpts().ObjCRuntime.hasEmptyCollections())
+  return E;
+
 D = ArrayLit->getArrayWithObjectsMethod();
   } else if (ObjCDictionaryLiteral *DictLit
 = dyn_cast(E)) {
+// Don't do reclaims if we're using the zero-element dictionary
+// constant.
+if (DictLit->getNumElements() == 0 &&
+Context.getLangOpts().ObjCRuntime.hasEmptyCollections())
+  return E;
+
 D = DictLit->getDictWithObjectsMethod();
   }
 

Added: cfe/trunk/test/CodeGenObjC/empty-collection-literals.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/empty-collection-literals.m?rev=300389=auto
==
--- cfe/trunk/test/CodeGenObjC/empty-collection-literals.m (added)
+++ cfe/trunk/test/CodeGenObjC/empty-collection-literals.m Sat Apr 15 00:31:35 
2017
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-macosx10.10.0 
-fobjc-runtime=macosx-10.10.0 -emit-llvm -fblocks -fobjc-arc 
-fobjc-runtime-has-weak -o - %s | FileCheck 
-check-prefix=CHECK-WITHOUT-EMPTY-COLLECTIONS %s
+// RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-macosx10.11.0 
-fobjc-runtime=macosx-10.11.0 -emit-llvm -fblocks -fobjc-arc 
-fobjc-runtime-has-weak -o - %s | FileCheck 

[PATCH] D32107: [libc++][test] LWG2857 test coverage for variant

2017-04-14 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter added a comment.

In https://reviews.llvm.org/D32107#727751, @EricWF wrote:

> Give me a day to implement this in variant and then this should be ready to 
> land.


No rush; the patch isn't going anywhere ;)


https://reviews.llvm.org/D32107



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


[PATCH] D32107: [libc++][test] LWG2857 test coverage for variant

2017-04-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

Give me a day to implement this in variant and then this should be ready to 
land.


https://reviews.llvm.org/D32107



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


[PATCH] D32107: [libc++][test] LWG2857 test coverage for variant

2017-04-14 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter created this revision.

As the saying goes, "works on my machine."

NOTE: libc++ variant does not yet implement LWG2857 and will not pass these 
tests; MSVC variant does.

Changes under `TEST_VARIANT_HAS_NO_REFERENCES` are dry-coded; I figure that's 
better than nothing.


https://reviews.llvm.org/D32107

Files:
  
test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp
  
test/std/utilities/variant/variant.variant/variant.mod/emplace_index_init_list_args.pass.cpp
  
test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp
  
test/std/utilities/variant/variant.variant/variant.mod/emplace_type_init_list_args.pass.cpp

Index: test/std/utilities/variant/variant.variant/variant.mod/emplace_type_init_list_args.pass.cpp
===
--- test/std/utilities/variant/variant.variant/variant.mod/emplace_type_init_list_args.pass.cpp
+++ test/std/utilities/variant/variant.variant/variant.mod/emplace_type_init_list_args.pass.cpp
@@ -15,7 +15,7 @@
 // template  class variant;
 
 // template 
-// void emplace(initializer_list il,Args&&... args);
+//   T& emplace(initializer_list il,Args&&... args);
 
 #include 
 #include 
@@ -70,13 +70,19 @@
 void test_basic() {
   using V = std::variant;
   V v;
-  v.emplace({1, 2, 3});
+  auto& ref1 = v.emplace({1, 2, 3});
+  static_assert(std::is_same_v, "");
   assert(std::get(v).size == 3);
-  v.emplace({1, 2, 3, 4}, 42);
+  assert( == ::get(v));
+  auto& ref2 = v.emplace({1, 2, 3, 4}, 42);
+  static_assert(std::is_same_v, "");
   assert(std::get(v).size == 4);
   assert(std::get(v).value == 42);
-  v.emplace({1});
+  assert( == ::get(v));
+  auto& ref3 = v.emplace({1});
+  static_assert(std::is_same_v, "");
   assert(std::get(v).size == 1);
+  assert( == ::get(v));
 }
 
 int main() {
Index: test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp
===
--- test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp
+++ test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp
@@ -14,7 +14,7 @@
 
 // template  class variant;
 
-// template  void emplace(Args&&... args);
+// template  T& emplace(Args&&... args);
 
 #include 
 #include 
@@ -86,24 +86,34 @@
   {
 using V = std::variant;
 V v(42);
-v.emplace();
+auto& ref1 = v.emplace();
+static_assert(std::is_same_v, "");
 assert(std::get<0>(v) == 0);
-v.emplace(42);
+assert( == ::get<0>(v));
+auto& ref2 = v.emplace(42);
+static_assert(std::is_same_v, "");
 assert(std::get<0>(v) == 42);
+assert( == ::get<0>(v));
   }
   {
 using V =
 std::variant;
 const int x = 100;
 V v(std::in_place_type, -1);
 // default emplace a value
-v.emplace();
+auto& ref1 = v.emplace();
+static_assert(std::is_same_v, "");
 assert(std::get<1>(v) == 0);
-v.emplace();
+assert( == ::get<1>(v));
+auto& ref2 = v.emplace();
+static_assert(std::is_same_v, "");
 assert(std::get<2>(v) == );
+assert( == ::get<2>(v));
 // emplace with multiple args
-v.emplace(3, 'a');
+auto& ref3 = v.emplace(3, 'a');
+static_assert(std::is_same_v, "");
 assert(std::get<4>(v) == "aaa");
+assert( == ::get<4>(v));
   }
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {
@@ -114,20 +124,30 @@
 int z = 43;
 V v(std::in_place_index<0>, -1);
 // default emplace a value
-v.emplace();
+auto& ref1 = v.emplace();
+static_assert(std::is_same_v, "");
 assert(std::get(v) == 0);
+assert( == ::get(v));
 // emplace a reference
-v.emplace(x);
+auto& ref2 = v.emplace(x);
+static_assert(std::is_same_v, "");
 assert(::get(v) == );
+assert( == ::get(v));
 // emplace an rvalue reference
-v.emplace(std::move(y));
+auto& ref3 = v.emplace(std::move(y));
+static_assert(std::is_same_v, "");
 assert(::get(v) == );
+assert( == ::get(v));
 // re-emplace a new reference over the active member
-v.emplace(std::move(z));
+auto& ref4 = v.emplace(std::move(z));
+static_assert(std::is_same_v, "");
 assert(::get(v) == );
+assert( == ::get(v));
 // emplace with multiple args
-v.emplace(3, 'a');
+auto& ref5 = v.emplace(3, 'a');
+static_assert(std::is_same_v, "");
 assert(std::get(v) == "aaa");
+assert( == ::get(v));
   }
 #endif
 }
Index: test/std/utilities/variant/variant.variant/variant.mod/emplace_index_init_list_args.pass.cpp

[libcxx] r300387 - Make clang-format use C++03 syntax

2017-04-14 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Fri Apr 14 21:45:43 2017
New Revision: 300387

URL: http://llvm.org/viewvc/llvm-project?rev=300387=rev
Log:
Make clang-format use C++03 syntax

Modified:
libcxx/trunk/.clang-format

Modified: libcxx/trunk/.clang-format
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/.clang-format?rev=300387=300386=300387=diff
==
--- libcxx/trunk/.clang-format (original)
+++ libcxx/trunk/.clang-format Fri Apr 14 21:45:43 2017
@@ -2,6 +2,7 @@ BasedOnStyle: LLVM
 
 ---
 Language: Cpp
+Standard: Cpp03
 
 AlwaysBreakTemplateDeclarations: true
 PointerAlignment: Left


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


[PATCH] D28832: Improve redefinition errors pointing to the same header.

2017-04-14 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

@v.g.vassilev your testcase is interesting but it's unrelated to this specific 
improvement. The error message it's triggered by (a) the decl name not being 
found because `kROOTD_OPEN` is hidden, (b) type transforms looks for an 
alternative (c) `Sema::diagnoseMissingImport` is called and produces the error 
you're seeing. I can fix this one too once we decide what we consider a good 
diagnostic here, let's iterate in http://bugs.llvm.org/show_bug.cgi?id=32670


https://reviews.llvm.org/D28832



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


[PATCH] D28832: Improve redefinition errors pointing to the same header.

2017-04-14 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno updated this revision to Diff 95369.
bruno marked 2 inline comments as done.
bruno added a comment.

Updated the patch after Richard's comments:

Before
--

  In file included from x.c:2:
  Inputs4/C.h:3:5: error: redefinition of 'c'
  int c = 1;
  ^
  In module 'X' imported from x.c:1:
  Inputs4/C.h:3:5: note: previous definition is here
  int c = 1;
  ^
  1 error generated.

After
-

  In file included from x.c:2:
  Inputs4/C.h:3:5: error: redefinition of 'c'
  int c = 1;
  ^
  In module 'X' imported from x.c:1:
  Inputs4/B.h:3:10: note: 'Inputs4/C.h' included multiple times, additional 
include site in header from module 'X.B'
  #include "C.h"
   ^
  Inputs4/module.modulemap:6:10: note: X.B defined here
module B {
   ^
  x.c:2:10: note: 'Inputs4/C.h' included multiple times, additional include 
site here
  #include "C.h" // textual include
   ^
  1 error generated.


https://reviews.llvm.org/D28832

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaDecl.cpp
  test/Modules/Inputs/SameHeader/A.h
  test/Modules/Inputs/SameHeader/B.h
  test/Modules/Inputs/SameHeader/C.h
  test/Modules/Inputs/SameHeader/module.modulemap
  test/Modules/redefinition-same-header.m
  test/Sema/redefinition-same-header.c

Index: test/Sema/redefinition-same-header.c
===
--- /dev/null
+++ test/Sema/redefinition-same-header.c
@@ -0,0 +1,14 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: echo 'int yyy = 42;' > %t/a.h
+// RUN: %clang_cc1 -fsyntax-only %s -I%t  -verify
+
+// expected-error@a.h:1 {{redefinition of 'yyy'}}
+// expected-note@a.h:1 {{unguarded header; consider using #ifdef guards or #pragma once}}
+// expected-note-re@redefinition-same-header.c:11 {{'{{.*}}/a.h' included multiple times, additional include site here}}
+// expected-note-re@redefinition-same-header.c:12 {{'{{.*}}/a.h' included multiple times, additional include site here}}
+
+#include "a.h"
+#include "a.h"
+
+int foo() { return yyy; }
Index: test/Modules/redefinition-same-header.m
===
--- /dev/null
+++ test/Modules/redefinition-same-header.m
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t.tmp
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SameHeader -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-cache-path=%t.tmp %s -verify
+
+// expected-error@Inputs/SameHeader/C.h:3 {{redefinition of 'c'}}
+// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}/C.h' included multiple times, additional include site in header from module 'X.B'}}
+// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}}
+// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}/C.h' included multiple times, additional include site here}}
+
+// expected-error@Inputs/SameHeader/C.h:5 {{redefinition of 'aaa'}}
+// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}/C.h' included multiple times, additional include site in header from module 'X.B'}}
+// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}}
+// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}/C.h' included multiple times, additional include site here}}
+
+// expected-error@Inputs/SameHeader/C.h:9 {{redefinition of 'fd_set'}}
+// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}/C.h' included multiple times, additional include site in header from module 'X.B'}}
+// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}}
+// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}/C.h' included multiple times, additional include site here}}
+#include "A.h" // maps to a modular
+#include "C.h" // textual include
Index: test/Modules/Inputs/SameHeader/module.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/SameHeader/module.modulemap
@@ -0,0 +1,11 @@
+module X {
+  module A {
+header "A.h"
+export *
+  }
+  module B {
+header "B.h"
+export *
+  }
+  export *
+}
Index: test/Modules/Inputs/SameHeader/C.h
===
--- /dev/null
+++ test/Modules/Inputs/SameHeader/C.h
@@ -0,0 +1,12 @@
+#ifndef __C_h__
+#define __C_h__
+int c = 1;
+
+struct aaa {
+  int b;
+};
+
+typedef struct fd_set {
+  char c;
+};
+#endif
Index: test/Modules/Inputs/SameHeader/B.h
===
--- /dev/null
+++ test/Modules/Inputs/SameHeader/B.h
@@ -0,0 +1,4 @@
+#ifndef __B_h__
+#define __B_h__
+#include "C.h"
+#endif
Index: test/Modules/Inputs/SameHeader/A.h
===
--- /dev/null
+++ test/Modules/Inputs/SameHeader/A.h
@@ -0,0 +1,3 @@
+#ifndef __A_h__
+#define __A_h__
+#endif
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -1969,7 

[PATCH] D28832: Improve redefinition errors pointing to the same header.

2017-04-14 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno marked 5 inline comments as done.
bruno added inline comments.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:8708
+def note_redefinition_modules_same_file : Note<
+   "'%0' included multiple times, additional (likely non-modular) include 
site in module '%1'">;
+def note_redefinition_modules_same_file_modulemap : Note<

rsmith wrote:
> If we can't be sure whether or not the other include side was a modular 
> include, making a guess is probably not helpful. (In fact, I've seen this 
> issue show up a lot more where the header is a modular header in both 
> modules.)
After thinking more about this I agree: if used together with 
"-Wnon-modular-include-in-module" and similars, it should become more evident 
to the user what this is about.



Comment at: lib/Sema/SemaDecl.cpp:3747
+  // is confusing, try to get better diagnostics when modules is on.
+  auto OldModLoc = SrcMgr.getModuleImportLoc(Old);
+  if (!OldModLoc.first.isInvalid()) {

rsmith wrote:
> Rather than listing where the module was first imported (which could be 
> unrelated to the problem), it would make more sense to list the location at 
> which the previous declaration was made visible. You can get that by querying 
> the `VisibleModuleSet` for the owning module of the definition and every 
> other module in its merged definitions set (see 
> `Sema::hasVisibleMergedDefinition`).
I tried this, but AFAIU the Decls coming from non-modular headers are usually 
hidden, and since it has not been merged, which happens in the testcase because 
it's a var redefinition error, then we have no import location to get 
information from. Do you have a synthetic testcase in mind that I can use? I'm 
happy to follow up with that (here or in a next patch).



Comment at: lib/Sema/SemaDecl.cpp:3755-3759
+  if (!Mod->DefinitionLoc.isInvalid())
+Diag(Mod->DefinitionLoc,
+ diag::note_redefinition_modules_same_file_modulemap)
+<< SrcMgr.getFilename(SrcMgr.getSpellingLoc(Old)).str()
+<< Mod->getFullModuleName();

rsmith wrote:
> Is this ("add the header to the module map for some other module that 
> happened to include it first") really generally good advice? People have a 
> tendency to follow such guidance blindly.
Indeed, going to remove that.


https://reviews.llvm.org/D28832



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


[PATCH] D32106: [libcxx][test] Expand LWG2857 coverage

2017-04-14 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter created this revision.

- Cover `optional`'s emplace-from-`initializer_list` overload
- Verify that `any::emplace` and `optional::emplace` return a reference to the 
correct type even for throwing cases


https://reviews.llvm.org/D32106

Files:
  test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
  
test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
  
test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp

Index: test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp
===
--- test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp
+++ test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp
@@ -11,7 +11,7 @@
 // 
 
 // template 
-//   void optional::emplace(initializer_list il, Args&&... args);
+//   T& optional::emplace(initializer_list il, Args&&... args);
 
 #include 
 #include 
@@ -76,21 +76,27 @@
 X x;
 optional opt(x);
 assert(X::dtor_called == false);
-opt.emplace({1, 2});
+auto  = opt.emplace({1, 2});
+static_assert( std::is_same_v, "" );
 assert(X::dtor_called == true);
 assert(*opt == X({1, 2}));
+assert( == &*opt);
 }
 {
 optional opt;
-opt.emplace({1, 2, 3}, std::allocator());
+auto  = opt.emplace({1, 2, 3}, std::allocator());
+static_assert( std::is_same_v, "" );
 assert(static_cast(opt) == true);
 assert(*opt == std::vector({1, 2, 3}));
+assert( == &*opt);
 }
 {
 optional opt;
-opt.emplace({1, 2});
+auto  = opt.emplace({1, 2});
+static_assert( std::is_same_v, "" );
 assert(static_cast(opt) == true);
 assert(*opt == Y({1, 2}));
+assert( == &*opt);
 }
 #ifndef TEST_HAS_NO_EXCEPTIONS
 {
@@ -100,7 +106,9 @@
 {
 assert(static_cast(opt) == true);
 assert(Z::dtor_called == false);
-opt.emplace({1, 2});
+auto  = opt.emplace({1, 2});
+static_assert( std::is_same_v, "" );
+assert(false);
 }
 catch (int i)
 {
Index: test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
===
--- test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
+++ test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
@@ -254,7 +254,9 @@
 {
 assert(static_cast(opt) == true);
 assert(Y::dtor_called == false);
-opt.emplace(1);
+auto  = opt.emplace(1);
+static_assert( std::is_same_v, "" );
+assert(false);
 }
 catch (int i)
 {
Index: test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
===
--- test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
+++ test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
@@ -44,7 +44,7 @@
 
 auto  = a.emplace();
 static_assert( std::is_same_v, "" );
-		assert( == std::any_cast());
+assert( == std::any_cast());
 
 assert(Tracked::count == 0);
 assert(Type::count == 1);
@@ -60,7 +60,7 @@
 
 auto  = a.emplace(101);
 static_assert( std::is_same_v, "" );
-		assert( == std::any_cast());
+assert( == std::any_cast());
 
 assert(Tracked::count == 0);
 assert(Type::count == 1);
@@ -76,7 +76,7 @@
 
 auto  = a.emplace(-1, 42, -1);
 static_assert( std::is_same_v, "" );
-		assert( == std::any_cast());
+assert( == std::any_cast());
 
 assert(Tracked::count == 0);
 assert(Type::count == 1);
@@ -97,7 +97,7 @@
 assert(Tracked::count == 1);
 auto  = a.emplace();
 static_assert( std::is_same_v, "" );
-		assert( == std::any_cast());
+assert( == std::any_cast());
 
 assert(Tracked::count == 0);
 assertArgsMatch(a);
@@ -107,7 +107,7 @@
 assert(Tracked::count == 1);
 auto  = a.emplace(-1, 42, -1);
 static_assert( std::is_same_v, "" );
-		assert( == std::any_cast());
+assert( == std::any_cast());
 
 assert(Tracked::count == 0);
 assertArgsMatch(a);
@@ -118,7 +118,7 @@
 assert(Tracked::count == 1);
 auto  = a.emplace({-1, 42, -1});
 static_assert( std::is_same_v, "" );
-		assert( == std::any_cast());
+ 

Re: r299226 - [Modules][PCH] Serialize #pragma pack

2017-04-14 Thread Duncan P. N. Exon Smith via cfe-commits
FYI, I reverted the modules side of this in r300380.  For details, see the 
commit message.  TL;DR: this didn't actually make modules builds closer to 
matching non-modules builds, thanks to how submodules work; on the contrary, it 
made them diverge.

> On 2017-Mar-31, at 08:36, Alex Lorenz via cfe-commits 
>  wrote:
> 
> Author: arphaman
> Date: Fri Mar 31 10:36:21 2017
> New Revision: 299226
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=299226=rev
> Log:
> [Modules][PCH] Serialize #pragma pack
> 
> This patch serializes the state of #pragma pack. It preserves the state of the
> pragma from a PCH/from modules in a file that uses that PCH/those modules.
> 

> rdar://21359084
> 
> Differential Revision: https://reviews.llvm.org/D31241
> 
> Added:
>cfe/trunk/test/Modules/Inputs/pragma_pack_push.h
>cfe/trunk/test/Modules/Inputs/pragma_pack_reset_push.h
>cfe/trunk/test/Modules/Inputs/pragma_pack_set.h
>cfe/trunk/test/Modules/pragma-pack.c
>cfe/trunk/test/PCH/pragma-pack.c
> Modified:
>cfe/trunk/include/clang/Serialization/ASTBitCodes.h
>cfe/trunk/include/clang/Serialization/ASTReader.h
>cfe/trunk/include/clang/Serialization/ASTWriter.h
>cfe/trunk/lib/Sema/SemaAttr.cpp
>cfe/trunk/lib/Serialization/ASTReader.cpp
>cfe/trunk/lib/Serialization/ASTWriter.cpp
>cfe/trunk/test/Modules/Inputs/module.map
> 
> Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=299226=299225=299226=diff
> ==
> --- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
> +++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Fri Mar 31 10:36:21 
> 2017
> @@ -604,6 +604,9 @@ namespace clang {
>   OPENCL_EXTENSION_DECLS = 59,
> 
>   MODULAR_CODEGEN_DECLS = 60,
> +
> +  /// \brief Record code for \#pragma pack options.
> +  PACK_PRAGMA_OPTIONS = 61,
> };
> 
> /// \brief Record types used within a source manager block.
> 
> Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=299226=299225=299226=diff
> ==
> --- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
> +++ cfe/trunk/include/clang/Serialization/ASTReader.h Fri Mar 31 10:36:21 2017
> @@ -811,6 +811,17 @@ private:
>   int PragmaMSPointersToMembersState = -1;
>   SourceLocation PointersToMembersPragmaLocation;
> 
> +  /// \brief The pragma pack state.
> +  Optional PragmaPackCurrentValue;
> +  SourceLocation PragmaPackCurrentLocation;
> +  struct PragmaPackStackEntry {
> +unsigned Value;
> +SourceLocation Location;
> +StringRef SlotLabel;
> +  };
> +  llvm::SmallVector PragmaPackStack;
> +  llvm::SmallVector PragmaPackStrings;
> +
>   /// \brief The OpenCL extension settings.
>   OpenCLOptions OpenCLExtensions;
> 
> 
> Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=299226=299225=299226=diff
> ==
> --- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
> +++ cfe/trunk/include/clang/Serialization/ASTWriter.h Fri Mar 31 10:36:21 2017
> @@ -485,6 +485,7 @@ private:
>   void WriteOptimizePragmaOptions(Sema );
>   void WriteMSStructPragmaOptions(Sema );
>   void WriteMSPointersToMembersPragmaOptions(Sema );
> +  void WritePackPragmaOptions(Sema );
>   void WriteModuleFileExtension(Sema ,
> ModuleFileExtensionWriter );
> 
> 
> Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=299226=299225=299226=diff
> ==
> --- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaAttr.cpp Fri Mar 31 10:36:21 2017
> @@ -215,6 +215,7 @@ void Sema::PragmaStack::Act(S
>ValueType Value) {
>   if (Action == PSK_Reset) {
> CurrentValue = DefaultValue;
> +CurrentPragmaLocation = PragmaLocation;
> return;
>   }
>   if (Action & PSK_Push)
> 
> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=299226=299225=299226=diff
> ==
> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Mar 31 10:36:21 2017
> @@ -3298,6 +3298,28 @@ ASTReader::ReadASTBlock(ModuleFile , u
>   }
>   ForceCUDAHostDeviceDepth = Record[0];

r300382 - [Coverage] Use the new getInstrProfSectionName API (NFC)

2017-04-14 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Apr 14 19:10:05 2017
New Revision: 300382

URL: http://llvm.org/viewvc/llvm-project?rev=300382=rev
Log:
[Coverage] Use the new getInstrProfSectionName API (NFC)

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

Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=300382=300381=300382=diff
==
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Fri Apr 14 19:10:05 2017
@@ -962,7 +962,9 @@ struct CounterCoverageMappingBuilder
 };
 
 std::string getCoverageSection(const CodeGenModule ) {
-  return llvm::getInstrProfCoverageSectionName(());
+  return llvm::getInstrProfSectionName(
+  llvm::IPSK_covmap,
+  CGM.getContext().getTargetInfo().getTriple().getObjectFormat());
 }
 
 std::string normalizeFilename(StringRef Filename) {


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


r300380 - Modules: Do not serialize #pragma pack state

2017-04-14 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Fri Apr 14 19:07:57 2017
New Revision: 300380

URL: http://llvm.org/viewvc/llvm-project?rev=300380=rev
Log:
Modules: Do not serialize #pragma pack state

The modules side of r299226, which serializes #pragma pack state,
doesn't work well.

The main purpose was to make -include and -include-pch match semantics
(the PCH side).  We also started serializing #pragma pack in PCMs, in
the hopes of making modules and non-modules builds more consistent.  But
consider:

$ cat a.h
$ cat b.h
#pragma pack(push, 2)
$ cat module.modulemap
module M {
module a { header "a.h" }
module b { header "b.h" }
}
$ cat t.cpp
#include "a.h"
#pragma pack(show)

As of r299226, the #pragma pack(show) gives "2", even though we've only
included "a.h".

- With -fmodules-local-submodule-visibility, this is clearly wrong.  We
  should get the default state (8 on x86_64).

- Without -fmodules-local-submodule-visibility, this kind of matches how
  other things work (as if include-the-whole-module), but it's still
  really terrible, and it doesn't actually make modules and non-modules
  builds more consistent.

This commit disables the serialization for modules, essentially a
partial revert of r299226.

Going forward:

 1. Having this #pragma pack stuff escape is terrible design (or, more
often, a horrible bug).  We should prioritize adding warnings (maybe
-Werror by default?).

 2. If we eventually reintroduce this for modules, it should only apply
to -fmodules-local-submodule-visibility, and it should be tracked on
a per-submodule basis.

Added:
cfe/trunk/test/Modules/pragma-pack.cpp
Removed:
cfe/trunk/test/Modules/Inputs/pragma_pack_push.h
cfe/trunk/test/Modules/Inputs/pragma_pack_reset_push.h
cfe/trunk/test/Modules/pragma-pack.c
Modified:
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/Modules/Inputs/module.map

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=300380=300379=300380=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Apr 14 19:07:57 2017
@@ -4186,6 +4186,11 @@ void ASTWriter::WriteMSPointersToMembers
 
 /// \brief Write the state of 'pragma pack' at the end of the module.
 void ASTWriter::WritePackPragmaOptions(Sema ) {
+  // Don't serialize pragma pack state for modules, since it should only take
+  // effect on a per-submodule basis.
+  if (WritingModule)
+return;
+
   RecordData Record;
   Record.push_back(SemaRef.PackStack.CurrentValue);
   AddSourceLocation(SemaRef.PackStack.CurrentPragmaLocation, Record);

Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=300380=300379=300380=diff
==
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Fri Apr 14 19:07:57 2017
@@ -265,20 +265,9 @@ module diag_pragma {
   header "diag_pragma.h"
 }
 
-module pragma_pack_set {
-  header "pragma_pack_set.h"
-}
-
-module pragma_pack_push {
-  header "pragma_pack_push.h"
-}
-
-module pragma_pack_empty {
-  header "empty.h"
-}
-
-module pragma_pack_reset_push {
-  header "pragma_pack_reset_push.h"
+module pragma_pack {
+  module set { header "pragma_pack_set.h" }
+  module empty { header "empty.h" }
 }
 
 module dummy {

Removed: cfe/trunk/test/Modules/Inputs/pragma_pack_push.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/pragma_pack_push.h?rev=300379=auto
==
--- cfe/trunk/test/Modules/Inputs/pragma_pack_push.h (original)
+++ cfe/trunk/test/Modules/Inputs/pragma_pack_push.h (removed)
@@ -1,6 +0,0 @@
-
-#pragma pack (push, 4)
-#pragma pack (push, 2)
-#pragma pack (push, 1)
-#pragma pack (pop)
-

Removed: cfe/trunk/test/Modules/Inputs/pragma_pack_reset_push.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/pragma_pack_reset_push.h?rev=300379=auto
==
--- cfe/trunk/test/Modules/Inputs/pragma_pack_reset_push.h (original)
+++ cfe/trunk/test/Modules/Inputs/pragma_pack_reset_push.h (removed)
@@ -1,4 +0,0 @@
-
-#pragma pack ()
-#pragma pack (push, 4)
-

Removed: cfe/trunk/test/Modules/pragma-pack.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/pragma-pack.c?rev=300379=auto
==
--- cfe/trunk/test/Modules/pragma-pack.c (original)
+++ cfe/trunk/test/Modules/pragma-pack.c (removed)
@@ -1,35 +0,0 @@
-// RUN: rm -rf %t
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fmodules 
-fimplicit-module-maps -x 

LLVM buildmaster will go off-line today after 5PM for short time

2017-04-14 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be off-line today for about half hour after 5PM
Pacific time for maintenance.
Thank you for understanding.

Thanks

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


[PATCH] D30285: [ubsan] Don't check alignment if the alignment is 1

2017-04-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL300371: [ubsan] Don't check alignment if the alignment is 1 
(authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D30285?vs=89458=95353#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30285

Files:
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
  cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp


Index: cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
===
--- cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
+++ cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
@@ -133,7 +133,7 @@
 // CHECK: call void @__ubsan_handle_type_mismatch
 //
 // Check the result of the conversion before using it.
-// CHECK: call void @__ubsan_handle_type_mismatch
+// NULL: call void @__ubsan_handle_type_mismatch
 //
 // CHECK-NOT: call void @__ubsan_handle_type_mismatch
 B b;
Index: cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
===
--- cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
+++ cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
@@ -5,16 +5,32 @@
 struct A {
   // COMMON-LABEL: define linkonce_odr void @_ZN1A10do_nothingEv
   void do_nothing() {
-// ALIGN: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
-// ALIGN: and i64 %{{.*}}, 0, !nosanitize
+// ALIGN-NOT: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
  
 // NULL: icmp ne %struct.A* %{{.*}}, null, !nosanitize
  
 // OBJSIZE-NOT: call i64 @llvm.objectsize
   }
 };
 
+struct B {
+  int x;
+
+  // COMMON-LABEL: define linkonce_odr void @_ZN1B10do_nothingEv
+  void do_nothing() {
+// ALIGN: ptrtoint %struct.B* %{{.*}} to i64, !nosanitize
+// ALIGN: and i64 %{{.*}}, 3, !nosanitize
+
+// NULL: icmp ne %struct.B* %{{.*}}, null, !nosanitize
+
+// OBJSIZE-NOT: call i64 @llvm.objectsize
+  }
+};
+
 void force_irgen() {
   A a;
   a.do_nothing();
+
+  B b;
+  b.do_nothing();
 }
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -599,7 +599,7 @@
   AlignVal = getContext().getTypeAlignInChars(Ty).getQuantity();
 
 // The glvalue must be suitably aligned.
-if (AlignVal) {
+if (AlignVal > 1) {
   llvm::Value *Align =
   Builder.CreateAnd(Builder.CreatePtrToInt(Ptr, IntPtrTy),
 llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));


Index: cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
===
--- cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
+++ cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
@@ -133,7 +133,7 @@
 // CHECK: call void @__ubsan_handle_type_mismatch
 //
 // Check the result of the conversion before using it.
-// CHECK: call void @__ubsan_handle_type_mismatch
+// NULL: call void @__ubsan_handle_type_mismatch
 //
 // CHECK-NOT: call void @__ubsan_handle_type_mismatch
 B b;
Index: cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
===
--- cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
+++ cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
@@ -5,16 +5,32 @@
 struct A {
   // COMMON-LABEL: define linkonce_odr void @_ZN1A10do_nothingEv
   void do_nothing() {
-// ALIGN: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
-// ALIGN: and i64 %{{.*}}, 0, !nosanitize
+// ALIGN-NOT: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
  
 // NULL: icmp ne %struct.A* %{{.*}}, null, !nosanitize
  
 // OBJSIZE-NOT: call i64 @llvm.objectsize
   }
 };
 
+struct B {
+  int x;
+
+  // COMMON-LABEL: define linkonce_odr void @_ZN1B10do_nothingEv
+  void do_nothing() {
+// ALIGN: ptrtoint %struct.B* %{{.*}} to i64, !nosanitize
+// ALIGN: and i64 %{{.*}}, 3, !nosanitize
+
+// NULL: icmp ne %struct.B* %{{.*}}, null, !nosanitize
+
+// OBJSIZE-NOT: call i64 @llvm.objectsize
+  }
+};
+
 void force_irgen() {
   A a;
   a.do_nothing();
+
+  B b;
+  b.do_nothing();
 }
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -599,7 +599,7 @@
   AlignVal = getContext().getTypeAlignInChars(Ty).getQuantity();
 
 // The glvalue must be suitably aligned.
-if (AlignVal) {
+if (AlignVal > 1) {
   llvm::Value *Align =
   Builder.CreateAnd(Builder.CreatePtrToInt(Ptr, IntPtrTy),
 llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30283: [ubsan] Reduce alignment checking of C++ object pointers

2017-04-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL300370: [ubsan] Reduce alignment checking of C++ object 
pointers (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D30283?vs=95053=95352#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30283

Files:
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGExprCXX.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/test/CodeGenCXX/ubsan-global-alignment.cpp
  cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
  cfe/trunk/test/CodeGenCXX/ubsan-suppress-null-checks.cpp
  cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp

Index: cfe/trunk/test/CodeGenCXX/ubsan-global-alignment.cpp
===
--- cfe/trunk/test/CodeGenCXX/ubsan-global-alignment.cpp
+++ cfe/trunk/test/CodeGenCXX/ubsan-global-alignment.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=alignment | FileCheck %s
+
+struct S {
+  int I;
+};
+
+extern S g_S;
+extern S array_S[];
+
+// CHECK-LABEL: define i32 @_Z18load_extern_global
+int load_extern_global() {
+  // FIXME: The IR builder constant-folds the alignment check away to 'true'
+  // here, so we never call the diagnostic. This is PR32630.
+  // CHECK-NOT: ptrtoint i32* {{.*}} to i32, !nosanitize
+  // CHECK: [[I:%.*]] = load i32, i32* getelementptr inbounds (%struct.S, %struct.S* @g_S, i32 0, i32 0), align 4
+  // CHECK-NEXT: ret i32 [[I]]
+  return g_S.I;
+}
+
+// CHECK-LABEL: define i32 @_Z22load_from_extern_array
+int load_from_extern_array(int I) {
+  // CHECK: [[I:%.*]] = getelementptr inbounds %struct.S, %struct.S* {{.*}}, i32 0, i32 0
+  // CHECK-NEXT: [[PTRTOINT:%.*]] = ptrtoint i32* [[I]] to i64, !nosanitize
+  // CHECK-NEXT: [[AND:%.*]] = and i64 [[PTRTOINT]], 3, !nosanitize
+  // CHECK-NEXT: [[ICMP:%.*]] = icmp eq i64 [[AND]], 0, !nosanitize
+  // CHECK-NEXT: br i1 [[ICMP]]
+  // CHECK: call void @__ubsan_handle_type_mismatch
+  return array_S[I].I;
+}
Index: cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
===
--- cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
+++ cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
@@ -5,8 +5,8 @@
 struct A {
   // COMMON-LABEL: define linkonce_odr void @_ZN1A10do_nothingEv
   void do_nothing() {
-// ALIGN-NOT: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
-// ALIGN-NOT: and i64 %{{.*}}, 7, !nosanitize
+// ALIGN: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
+// ALIGN: and i64 %{{.*}}, 0, !nosanitize
  
 // NULL: icmp ne %struct.A* %{{.*}}, null, !nosanitize
  
Index: cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
===
--- cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
+++ cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
@@ -0,0 +1,221 @@
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=alignment | FileCheck %s --check-prefixes=CHECK,ALIGN
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=null | FileCheck %s --check-prefixes=CHECK,NULL
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=alignment,null -DCHECK_LAMBDA | FileCheck %s --check-prefixes=LAMBDA
+
+struct A {
+  int foo;
+
+  // CHECK-LABEL: define linkonce_odr void @_ZN1A10do_nothingEv
+  void do_nothing() {
+// ALIGN: %[[THISINT1:[0-9]+]] = ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
+// ALIGN: and i64 %[[THISINT1]], 3, !nosanitize
+// NULL: icmp ne %struct.A* %[[THIS1:[a-z0-9]+]], null, !nosanitize
+// NULL: ptrtoint %struct.A* %[[THIS1]] to i64, !nosanitize
+// CHECK: call void @__ubsan_handle_type_mismatch
+// CHECK-NOT: call void @__ubsan_handle_type_mismatch
+// CHECK: ret void
+  }
+
+#ifdef CHECK_LAMBDA
+  // LAMBDA-LABEL: define linkonce_odr void @_ZN1A22do_nothing_with_lambdaEv
+  void do_nothing_with_lambda() {
+// LAMBDA: icmp ne %struct.A* %[[THIS2:[a-z0-9]+]], null, !nosanitize
+// LAMBDA: %[[THISINT2:[0-9]+]] = ptrtoint %struct.A* %[[THIS2]] to i64, !nosanitize
+// LAMBDA: and i64 %[[THISINT2]], 3, !nosanitize
+// LAMBDA: call void @__ubsan_handle_type_mismatch
+
+auto f = [&] {
+  foo = 0;
+};
+f();
+
+// LAMBDA: icmp ne %class.anon* %[[FUNCVAR:.*]], null, !nosanitize
+// LAMBDA: %[[LAMBDAINT:[0-9]+]] = ptrtoint %class.anon* %[[FUNCVAR]] to i64, !nosanitize
+// LAMBDA: and i64 %[[LAMBDAINT]], 7, !nosanitize
+// LAMBDA: call void @__ubsan_handle_type_mismatch
+
+// LAMBDA-NOT: call void @__ubsan_handle_type_mismatch
+// LAMBDA: ret void
+  }
+
+// Check the IR for the lambda:
+//
+// LAMBDA-LABEL: define linkonce_odr void @_ZZN1A22do_nothing_with_lambdaEvENKUlvE_clEv
+// LAMBDA: call void @__ubsan_handle_type_mismatch

r300370 - [ubsan] Reduce alignment checking of C++ object pointers

2017-04-14 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Apr 14 17:03:34 2017
New Revision: 300370

URL: http://llvm.org/viewvc/llvm-project?rev=300370=rev
Log:
[ubsan] Reduce alignment checking of C++ object pointers

This patch teaches ubsan to insert an alignment check for the 'this'
pointer at the start of each method/lambda. This allows clang to emit
significantly fewer alignment checks overall, because if 'this' is
aligned, so are its fields.

This is essentially the same thing r295515 does, but for the alignment
check instead of the null check. One difference is that we keep the
alignment checks on member expressions where the base is a DeclRefExpr.
There's an opportunity to diagnose unaligned accesses in this situation
(as pointed out by Eli, see PR32630).

Testing: check-clang, check-ubsan, and a stage2 ubsan build.

Along with the patch from D30285, this roughly halves the amount of
alignment checks we emit when compiling X86FastISel.cpp. Here are the
numbers from patched/unpatched clangs based on r298160.

  --
  | Setup  | # of alignment checks |
  --
  | unpatched, -O0 | 24326 |
  | patched, -O0   | 12717 | (-47.7%)
  --

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

Added:
cfe/trunk/test/CodeGenCXX/ubsan-global-alignment.cpp
cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
Removed:
cfe/trunk/test/CodeGenCXX/ubsan-suppress-null-checks.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=300370=300369=300370=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Apr 14 17:03:34 2017
@@ -954,10 +954,7 @@ LValue CodeGenFunction::EmitUnsupportedL
 E->getType());
 }
 
-bool CodeGenFunction::IsDeclRefOrWrappedCXXThis(const Expr *Obj) {
-  if (isa(Obj))
-return true;
-
+bool CodeGenFunction::IsWrappedCXXThis(const Expr *Obj) {
   const Expr *Base = Obj;
   while (!isa(Base)) {
 // The result of a dynamic_cast can be null.
@@ -988,9 +985,13 @@ LValue CodeGenFunction::EmitCheckedLValu
 LV = EmitLValue(E);
   if (!isa(E) && !LV.isBitField() && LV.isSimple()) {
 SanitizerSet SkippedChecks;
-if (const auto *ME = dyn_cast(E))
-  if (IsDeclRefOrWrappedCXXThis(ME->getBase()))
+if (const auto *ME = dyn_cast(E)) {
+  bool IsBaseCXXThis = IsWrappedCXXThis(ME->getBase());
+  if (IsBaseCXXThis)
+SkippedChecks.set(SanitizerKind::Alignment, true);
+  if (IsBaseCXXThis || isa(ME->getBase()))
 SkippedChecks.set(SanitizerKind::Null, true);
+}
 EmitTypeCheck(TCK, E->getExprLoc(), LV.getPointer(),
   E->getType(), LV.getAlignment(), SkippedChecks);
   }
@@ -3429,7 +3430,10 @@ LValue CodeGenFunction::EmitMemberExpr(c
 Address Addr = EmitPointerWithAlignment(BaseExpr, );
 QualType PtrTy = BaseExpr->getType()->getPointeeType();
 SanitizerSet SkippedChecks;
-if (IsDeclRefOrWrappedCXXThis(BaseExpr))
+bool IsBaseCXXThis = IsWrappedCXXThis(BaseExpr);
+if (IsBaseCXXThis)
+  SkippedChecks.set(SanitizerKind::Alignment, true);
+if (IsBaseCXXThis || isa(BaseExpr))
   SkippedChecks.set(SanitizerKind::Null, true);
 EmitTypeCheck(TCK_MemberAccess, E->getExprLoc(), Addr.getPointer(), PtrTy,
   /*Alignment=*/CharUnits::Zero(), SkippedChecks);

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=300370=300369=300370=diff
==
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Fri Apr 14 17:03:34 2017
@@ -301,9 +301,14 @@ RValue CodeGenFunction::EmitCXXMemberOrO
 CallLoc = CE->getExprLoc();
 
   SanitizerSet SkippedChecks;
-  if (const auto *CMCE = dyn_cast(CE))
-if (IsDeclRefOrWrappedCXXThis(CMCE->getImplicitObjectArgument()))
+  if (const auto *CMCE = dyn_cast(CE)) {
+auto *IOA = CMCE->getImplicitObjectArgument();
+bool IsImplicitObjectCXXThis = IsWrappedCXXThis(IOA);
+if (IsImplicitObjectCXXThis)
+  SkippedChecks.set(SanitizerKind::Alignment, true);
+if (IsImplicitObjectCXXThis || isa(IOA))
   SkippedChecks.set(SanitizerKind::Null, true);
+  }
   EmitTypeCheck(
   isa(CalleeDecl) ? 
CodeGenFunction::TCK_ConstructorCall
   : CodeGenFunction::TCK_MemberCall,

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 

r300371 - [ubsan] Don't check alignment if the alignment is 1

2017-04-14 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Apr 14 17:03:37 2017
New Revision: 300371

URL: http://llvm.org/viewvc/llvm-project?rev=300371=rev
Log:
[ubsan] Don't check alignment if the alignment is 1

If a pointer is 1-byte aligned, there's no use in checking its
alignment. Somewhat surprisingly, ubsan can spend a significant amount
of time doing just that!

This loosely depends on D30283.

Testing: check-clang, check-ubsan, and a stage2 ubsan build.

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

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=300371=300370=300371=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Apr 14 17:03:37 2017
@@ -599,7 +599,7 @@ void CodeGenFunction::EmitTypeCheck(Type
   AlignVal = getContext().getTypeAlignInChars(Ty).getQuantity();
 
 // The glvalue must be suitably aligned.
-if (AlignVal) {
+if (AlignVal > 1) {
   llvm::Value *Align =
   Builder.CreateAnd(Builder.CreatePtrToInt(Ptr, IntPtrTy),
 llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));

Modified: cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp?rev=300371=300370=300371=diff
==
--- cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp Fri Apr 14 17:03:37 2017
@@ -133,7 +133,7 @@ struct B {
 // CHECK: call void @__ubsan_handle_type_mismatch
 //
 // Check the result of the conversion before using it.
-// CHECK: call void @__ubsan_handle_type_mismatch
+// NULL: call void @__ubsan_handle_type_mismatch
 //
 // CHECK-NOT: call void @__ubsan_handle_type_mismatch
 B b;

Modified: cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp?rev=300371=300370=300371=diff
==
--- cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp Fri Apr 14 17:03:37 2017
@@ -5,8 +5,7 @@
 struct A {
   // COMMON-LABEL: define linkonce_odr void @_ZN1A10do_nothingEv
   void do_nothing() {
-// ALIGN: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
-// ALIGN: and i64 %{{.*}}, 0, !nosanitize
+// ALIGN-NOT: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
  
 // NULL: icmp ne %struct.A* %{{.*}}, null, !nosanitize
  
@@ -14,7 +13,24 @@ struct A {
   }
 };
 
+struct B {
+  int x;
+
+  // COMMON-LABEL: define linkonce_odr void @_ZN1B10do_nothingEv
+  void do_nothing() {
+// ALIGN: ptrtoint %struct.B* %{{.*}} to i64, !nosanitize
+// ALIGN: and i64 %{{.*}}, 3, !nosanitize
+
+// NULL: icmp ne %struct.B* %{{.*}}, null, !nosanitize
+
+// OBJSIZE-NOT: call i64 @llvm.objectsize
+  }
+};
+
 void force_irgen() {
   A a;
   a.do_nothing();
+
+  B b;
+  b.do_nothing();
 }


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


[PATCH] D30283: [ubsan] Reduce alignment checking of C++ object pointers

2017-04-14 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Thanks for the review!




Comment at: test/CodeGenCXX/ubsan-suppress-checks.cpp:25
+// LAMBDA: and i64 %[[THISINT2]], 3, !nosanitize
+// LAMBDA: call void @__ubsan_handle_type_mismatch
+

efriedma wrote:
> LAMBDA-NOT: call void @__ubsan_handle_type_mismatch ?
I'll tighten up this test. This method contains two calls to 
__ubsan_handle_type_mismatch. The first is due to a null+alignment check for 
"this" at the start of "do_nothing_with_lambda". The second occurs because we 
have the same checks for the anonymous object backing "f". Before this patch, 
the first check on "this" did not perform an alignment check. The second check 
has always been present.


https://reviews.llvm.org/D30283



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


[PATCH] D32081: Add support for editor placeholders to Clang's lexer

2017-04-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 95349.
arphaman added a comment.

Check if `IdentifierInfo` is nil in `ActOnIdExpression` to prevent crash.


Repository:
  rL LLVM

https://reviews.llvm.org/D32081

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Basic/IdentifierTable.h
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Lex/Lexer.h
  include/clang/Lex/Token.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/Lexer.cpp
  lib/Parse/Parser.cpp
  lib/Sema/SemaCXXScopeSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  test/Driver/clang_f_opts.c
  test/Parser/editor-placeholder-recovery.cpp
  test/Parser/placeholder-recovery.m

Index: test/Parser/placeholder-recovery.m
===
--- test/Parser/placeholder-recovery.m
+++ test/Parser/placeholder-recovery.m
@@ -1,11 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
+@protocol NSObject
+@end
+
+@protocol <#protocol name#>  // expected-error {{editor placeholder in source file}}
+// expected-note@-1 {{protocol started here}}
+
 // FIXME: We could do much better with this, if we recognized
 // placeholders somehow. However, we're content with not generating
 // bogus 'archaic' warnings with bad location info.
-@protocol <#protocol name#>  // expected-error {{expected identifier or '('}} \
-// expected-error 2{{expected identifier}} \
-// expected-warning{{protocol has no object type specified; defaults to qualified 'id'}}
-<#methods#>
+<#methods#> // expected-error {{editor placeholder in source file}}
 
-@end
+@end // expected-error {{prefix attribute must be followed by an interface or protocol}} expected-error {{missing '@end'}}
Index: test/Parser/editor-placeholder-recovery.cpp
===
--- /dev/null
+++ test/Parser/editor-placeholder-recovery.cpp
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -fallow-editor-placeholders -DSUPPRESS -verify %s
+
+struct Struct {
+public:
+void method(Struct );
+};
+
+struct <#struct name#> {
+  int <#field-name#>;
+#ifndef SUPPRESS
+  // expected-error@-3 {{editor placeholder in source file}}
+  // expected-error@-3 {{editor placeholder in source file}}
+#endif
+};
+
+typename <#typename#>::<#name#>;
+decltype(<#expression#>) foobar;
+typedef <#type#> <#name#>;
+#ifndef SUPPRESS
+  // expected-error@-4 2 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+  // expected-error@-4 2 {{editor placeholder in source file}}
+#endif
+
+namespace <#identifier#> {
+  <#declarations#>
+#ifndef SUPPRESS
+  // expected-error@-3 {{editor placeholder in source file}}
+  // expected-error@-3 {{editor placeholder in source file}}
+#endif
+
+}
+
+using <#qualifier#>::<#name#>;
+#ifndef SUPPRESS
+  // expected-error@-2 2 {{editor placeholder in source file}}
+#endif
+
+void avoidPlaceholderErrors(Struct ) {
+static_cast< <#type#> >(<#expression#>);
+while (<#condition#>) {
+<#statements#>
+}
+obj.method(<#Struct #>);
+#ifndef SUPPRESS
+  // expected-error@-6 2 {{editor placeholder in source file}}
+  // expected-error@-6 {{editor placeholder in source file}}
+  // expected-error@-6 {{editor placeholder in source file}}
+  // expected-error@-5 {{editor placeholder in source file}}
+#endif
+switch (<#expression#>) {
+case <#constant#>:
+<#statements#>
+#ifndef SUPPRESS
+  // expected-error@-4 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+#endif
+break;
+
+default:
+break;
+}
+}
+
+void Struct::method(<#Struct #>, noSupressionHere) { // expected-error {{unknown type name 'noSupressionHere'}} expected-error {{C++ requires a type specifier for all declarations}}
+#ifndef SUPPRESS
+  // expected-error@-2 {{editor placeholder in source file}}
+#endif
+}
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -494,3 +494,8 @@
 // RUN: %clang -### -S -fdebug-info-for-profiling -fno-debug-info-for-profiling %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-DEBUG %s
 // CHECK-PROFILE-DEBUG: -fdebug-info-for-profiling
 // CHECK-NO-PROFILE-DEBUG-NOT: -fdebug-info-for-profiling
+
+// RUN: %clang -### -S -fallow-editor-placeholders %s 2>&1 | FileCheck -check-prefix=CHECK-ALLOW-PLACEHOLDERS %s
+// RUN: %clang -### -S -fno-allow-editor-placeholders %s 2>&1 | FileCheck -check-prefix=CHECK-NO-ALLOW-PLACEHOLDERS %s
+// CHECK-ALLOW-PLACEHOLDERS: -fallow-editor-placeholders
+// CHECK-NO-ALLOW-PLACEHOLDERS-NOT: -fallow-editor-placeholders
Index: lib/Sema/SemaExpr.cpp

[PATCH] D32081: Add support for editor placeholders to Clang's lexer

2017-04-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 95348.
arphaman marked an inline comment as done.
arphaman added a comment.

- Don't use the diagnostic engine suppression ranges, but rely on changes to 
parser/sema for diagnostic suppression.
- Rename the compiler flag to '-fallow-editor-placeholders'.


Repository:
  rL LLVM

https://reviews.llvm.org/D32081

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Basic/IdentifierTable.h
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Lex/Lexer.h
  include/clang/Lex/Token.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/Lexer.cpp
  lib/Parse/Parser.cpp
  lib/Sema/SemaCXXScopeSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  test/Driver/clang_f_opts.c
  test/Parser/editor-placeholder-recovery.cpp
  test/Parser/placeholder-recovery.m

Index: test/Parser/placeholder-recovery.m
===
--- test/Parser/placeholder-recovery.m
+++ test/Parser/placeholder-recovery.m
@@ -1,11 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
+@protocol NSObject
+@end
+
+@protocol <#protocol name#>  // expected-error {{editor placeholder in source file}}
+// expected-note@-1 {{protocol started here}}
+
 // FIXME: We could do much better with this, if we recognized
 // placeholders somehow. However, we're content with not generating
 // bogus 'archaic' warnings with bad location info.
-@protocol <#protocol name#>  // expected-error {{expected identifier or '('}} \
-// expected-error 2{{expected identifier}} \
-// expected-warning{{protocol has no object type specified; defaults to qualified 'id'}}
-<#methods#>
+<#methods#> // expected-error {{editor placeholder in source file}}
 
-@end
+@end // expected-error {{prefix attribute must be followed by an interface or protocol}} expected-error {{missing '@end'}}
Index: test/Parser/editor-placeholder-recovery.cpp
===
--- /dev/null
+++ test/Parser/editor-placeholder-recovery.cpp
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -fallow-editor-placeholders -DSUPPRESS -verify %s
+
+struct Struct {
+public:
+void method(Struct );
+};
+
+struct <#struct name#> {
+  int <#field-name#>;
+#ifndef SUPPRESS
+  // expected-error@-3 {{editor placeholder in source file}}
+  // expected-error@-3 {{editor placeholder in source file}}
+#endif
+};
+
+typename <#typename#>::<#name#>;
+decltype(<#expression#>) foobar;
+typedef <#type#> <#name#>;
+#ifndef SUPPRESS
+  // expected-error@-4 2 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+  // expected-error@-4 2 {{editor placeholder in source file}}
+#endif
+
+namespace <#identifier#> {
+  <#declarations#>
+#ifndef SUPPRESS
+  // expected-error@-3 {{editor placeholder in source file}}
+  // expected-error@-3 {{editor placeholder in source file}}
+#endif
+
+}
+
+using <#qualifier#>::<#name#>;
+#ifndef SUPPRESS
+  // expected-error@-2 2 {{editor placeholder in source file}}
+#endif
+
+void avoidPlaceholderErrors(Struct ) {
+static_cast< <#type#> >(<#expression#>);
+while (<#condition#>) {
+<#statements#>
+}
+obj.method(<#Struct #>);
+#ifndef SUPPRESS
+  // expected-error@-6 2 {{editor placeholder in source file}}
+  // expected-error@-6 {{editor placeholder in source file}}
+  // expected-error@-6 {{editor placeholder in source file}}
+  // expected-error@-5 {{editor placeholder in source file}}
+#endif
+switch (<#expression#>) {
+case <#constant#>:
+<#statements#>
+#ifndef SUPPRESS
+  // expected-error@-4 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+#endif
+break;
+
+default:
+break;
+}
+}
+
+void Struct::method(<#Struct #>, noSupressionHere) { // expected-error {{unknown type name 'noSupressionHere'}} expected-error {{C++ requires a type specifier for all declarations}}
+#ifndef SUPPRESS
+  // expected-error@-2 {{editor placeholder in source file}}
+#endif
+}
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -494,3 +494,8 @@
 // RUN: %clang -### -S -fdebug-info-for-profiling -fno-debug-info-for-profiling %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-DEBUG %s
 // CHECK-PROFILE-DEBUG: -fdebug-info-for-profiling
 // CHECK-NO-PROFILE-DEBUG-NOT: -fdebug-info-for-profiling
+
+// RUN: %clang -### -S -fallow-editor-placeholders %s 2>&1 | FileCheck -check-prefix=CHECK-ALLOW-PLACEHOLDERS %s
+// RUN: %clang -### -S -fno-allow-editor-placeholders %s 2>&1 | FileCheck -check-prefix=CHECK-NO-ALLOW-PLACEHOLDERS %s
+// CHECK-ALLOW-PLACEHOLDERS: -fallow-editor-placeholders

[PATCH] D31996: Make Gentoo GNU GCC Config override whitespace tolerant

2017-04-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane closed this revision.
erichkeane added a comment.

Forgot the "DifferentialRevision" in the commit message, but added it as 
related here.


https://reviews.llvm.org/D31996



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Richard Smith via Phabricator via cfe-commits
rsmith added a comment.

From some very superficial testing, it looks like CL treats 
`__declspec(inline)` exactly like a synonym for `inline` (it even rejects them 
both appearing on the same declaration, complaining about a duplicate `inline` 
specifier). So modeling this as `GNUInlineAttr` is definitely wrong, and this 
should probably be setting the `inline` flag on the function. But I agree with 
Aaron: we need some evidence that implementing this in Clang is worthwhile 
(rather than changing the codebase to use the `inline` keyword instead). We aim 
to be CL-compatible for common code patterns, not to be 100% compatible with 
all code that CL accepts.


https://reviews.llvm.org/D32092



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D32092#727559, @zahiraam wrote:

> Yes I did compare "inline" with "declspec(inline)" and not with 
> "__attribute((gnu_inline))" and didn't test it whit different specifiers. I 
> can do that. 
>  If  behavior is different we probably have to add an additional attribute?


It's not that it needs an additional attribute, but that your patch will 
require additional work. However, my question remains unanswered: can you fix 
your project? Is this in a header file of some well-used library? We typically 
do not implement undocumented compiler features of other compilers unless 
there's a compelling reason to do so.


https://reviews.llvm.org/D32092



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


[PATCH] D32081: Add support for editor placeholders to Clang's lexer

2017-04-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

It's more about handling all of the cases, e.g. the completion results for 
declaration patterns with placeholders, as those can't be caught with a check 
at an expression/typename level.

I guess then I can catch all of the most common cases now and we can improve 
the suppression for the remaining cases later on.


Repository:
  rL LLVM

https://reviews.llvm.org/D32081



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

Yes I did compare "inline" with "declspec(inline)" and not with 
"__attribute((gnu_inline))" and didn't test it whit different specifiers. I can 
do that. 
If  behavior is different we probably have to add an additional attribute?


https://reviews.llvm.org/D32092



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


[PATCH] D32081: Add support for editor placeholders to Clang's lexer

2017-04-14 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

> What do you think about a hybrid approach: Don't suppress diagnostics in the 
> placeholder range when we handle the placeholders in parser/sema, but do 
> suppress the range when the placeholder isn't explicitly handled?

I'd really rather not plumb this into the diagnostics engine at all if we can 
avoid it.  Are there cases we somehow cannot handle using the explicit checks, 
or is it just a question of finding all the cases?


Repository:
  rL LLVM

https://reviews.llvm.org/D32081



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


[PATCH] D32081: Add support for editor placeholders to Clang's lexer

2017-04-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

In https://reviews.llvm.org/D32081#727511, @arphaman wrote:

> In https://reviews.llvm.org/D32081#727450, @benlangmuir wrote:
>
> > Rather than stick ranges into the diagnostic engine, I think it would be 
> > cleaner to have the identifier have a method like `isEditorPlaceholder()` 
> > that can be used to avoid situations like this in a principled way, or to 
> > customize behaviour for placeholders in the parser, etc.  That's how we are 
> > handling it in Swift.  Using an API on the placeholder is also better for 
> > handling errors that could be caused by the placeholder but not have it as 
> > the primary location.
> >
> > What do you think?
>
>
> I thought about this as well. I'm not sure which way is better though. The 
> current way is simple in the sense that we automatically suppress all 
> diagnostics in the placeholder, so we don't have to modify the parser at all. 
> Clang generates placeholders in a bunch of different places so I reckon 
> there'll have to be a lot of modifications to suppress all problematic cases. 
> Although I suppose that if we teach the parser about the most common places 
> where placeholders could occur (e.g. expressions), that would probably 
> suppress the majority of diagnostics that we care about. I'll try out the 
> parser changes right now.


It seems that suppressing placeholders in expressions and type names would 
cover the a lot of the common problematic cases. What do you think about a 
hybrid approach: Don't suppress diagnostics in the placeholder range when we 
handle the placeholders in parser/sema, but do suppress the range when the 
placeholder isn't explicitly handled?


Repository:
  rL LLVM

https://reviews.llvm.org/D32081



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Richard Smith via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D32092#727543, @zahiraam wrote:

> Pushed the submit too fast ...
>  Before I submitted this review, I have done some experiments and inline and 
> declspec(inline) have the same behavior. Compiling with /Ob0 disables 
> inlining. With -O1 or -O2, inline happens.


What do you mean, "inline and declspec(inline) have the same behavior"? What 
exactly did you test? The `inline` keyword means quite different things in 
different language modes, and none of them are the same as the meaning of 
`__attribute__((gnu_inline))` (which is what you aliased this to). Some of 
these differences are quite subtle (for instance, the precise behavior of 
`extern inline` and `static inline`, and what happens if you redeclare a 
function with a different set of specifiers).


https://reviews.llvm.org/D32092



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

Pushed the submit too fast ...
Before I submitted this review, I have done some experiments and inline and 
declspec(inline) have the same behavior. Compiling with /Ob0 disables inlining. 
With -O1 or -O2, inline happens.


https://reviews.llvm.org/D32092



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


[PATCH] D31757: [clang-tidy] Add a clang-tidy check for possible inefficient vector operations

2017-04-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 95338.
hokein marked 2 inline comments as done.
hokein added a comment.

Address remaining comments.


https://reviews.llvm.org/D31757

Files:
  clang-tidy/performance/CMakeLists.txt
  clang-tidy/performance/InefficientVectorOperationCheck.cpp
  clang-tidy/performance/InefficientVectorOperationCheck.h
  clang-tidy/performance/PerformanceTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
  test/clang-tidy/performance-inefficient-vector-operation.cpp

Index: test/clang-tidy/performance-inefficient-vector-operation.cpp
===
--- /dev/null
+++ test/clang-tidy/performance-inefficient-vector-operation.cpp
@@ -0,0 +1,183 @@
+// RUN: %check_clang_tidy %s performance-inefficient-vector-operation %t -- -format-style=llvm --
+
+typedef int size_t;
+
+namespace std {
+template 
+class vector {
+ public:
+  typedef T* iterator;
+  typedef const T* const_iterator;
+  typedef T& reference;
+  typedef const T& const_reference;
+  typedef size_t size_type;
+
+  explicit vector();
+  explicit vector(size_type n);
+
+  void push_back(const T& val);
+  void reserve(size_t n);
+  void resize(size_t n);
+
+  size_t size();
+  const_reference operator[] (size_type) const;
+  reference operator[] (size_type);
+};
+} // namespace std
+
+void f(std::vector& t) {
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(10);
+for (int i = 0; i < 10; ++i)
+  v.push_back(i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the vector capacity before the loop
+  }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(10);
+for (int i = 0; i < 10; i++)
+  v.push_back(i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+  }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(10);
+for (int i = 0; i < 10; ++i)
+  v.push_back(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+  }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(5);
+for (int i = 0; i < 5; ++i) {
+  v.push_back(i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+}
+// CHECK-FIXES-NOT: v.reserve(10);
+for (int i = 0; i < 10; ++i) {
+  // No fix for this loop as we encounter the prior loops.
+  v.push_back(i);
+}
+  }
+  {
+std::vector v;
+std::vector v2;
+v2.reserve(3);
+// CHECK-FIXES: v.reserve(10);
+for (int i = 0; i < 10; ++i)
+  v.push_back(i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+  }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size());
+for (size_t i = 0; i < t.size(); ++i) {
+  v.push_back(t[i]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+}
+  }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size() - 1);
+for (size_t i = 0; i < t.size() - 1; ++i) {
+  v.push_back(t[i]);
+} // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+  }
+
+  //  Non-fixed Cases 
+  {
+std::vector v;
+v.reserve(20);
+// CHECK-FIXES-NOT: v.reserve(10);
+// There is a "reserve" call already.
+for (int i = 0; i < 10; ++i) {
+  v.push_back(i);
+}
+  }
+  {
+std::vector v;
+v.reserve(5);
+// CHECK-FIXES-NOT: v.reserve(10);
+// There is a "reserve" call already.
+for (int i = 0; i < 10; ++i) {
+  v.push_back(i);
+}
+  }
+  {
+std::vector v;
+v.resize(5);
+// CHECK-FIXES-NOT: v.reserve(10);
+// There is a ref usage of v before the loop.
+for (int i = 0; i < 10; ++i) {
+  v.push_back(i);
+}
+  }
+  {
+std::vector v;
+v.push_back(0);
+// CHECK-FIXES-NOT: v.reserve(10);
+// There is a ref usage of v before the loop.
+for (int i = 0; i < 10; ++i) {
+  v.push_back(i);
+}
+  }
+  {
+std::vector v;
+f(v);
+// CHECK-FIXES-NOT: v.reserve(10);
+// There is a ref usage of v before the loop.
+for (int i = 0; i < 10; ++i) {
+  v.push_back(i);
+}
+  }
+  {
+std::vector v(20);
+// CHECK-FIXES-NOT: v.reserve(10);
+// v is not constructed with default constructor.
+for (int i = 0; i < 10; ++i) {
+  v.push_back(i);
+}
+  }
+  {
+std::vector v;
+// CHECK-FIXES-NOT: v.reserve(10);
+// For-loop is not started with 0.
+for (int i = 1; i < 10; ++i) {
+  v.push_back(i);
+}
+  }
+  {
+std::vector v;
+// CHECK-FIXES-NOT: v.reserve(t.size());
+// v isn't referenced in for-loop body.
+for (size_t i = 0; i < t.size(); ++i) {
+  t.push_back(i);
+}
+  }
+  {
+std::vector v;
+int k;
+// CHECK-FIXES-NOT: v.reserve(10);
+// For-loop isn't a fixable loop.
+for (size_t i = 0; k < 10; ++i) {
+  v.push_back(t[i]);
+}
+  }
+  {
+std::vector v;
+   

[PATCH] D27546: [ASTReader] Sort RawComments before merging

2017-04-14 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

> Does this cause us to deserialize the SLocEntry for every FileID referenced 
> by a RawComment? That would seem pretty bad.

I don't recall because It's been a while, but I'm gonna take a look and get 
back to you. Thanks


https://reviews.llvm.org/D27546



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

Yes it behaves the same way than the Gnu inline.


https://reviews.llvm.org/D32092



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Richard Smith via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/Basic/Attr.td:869
 def GNUInline : InheritableAttr {
-  let Spellings = [GCC<"gnu_inline">];
+  let Spellings = [GCC<"gnu_inline">, Declspec<"inline">];
   let Subjects = SubjectList<[Function]>;

aaron.ballman wrote:
> I cannot see any documentation on MSDN for this spelling of the attribute, 
> and MSVC 2015 rejects it. What is the motivating use case for this spelling?
Also, it seems rather unlikely that MSVC would implement the GNU inline 
semantics. Have you investigated the actual semantic effects of this 
`__declspec` attribute and checked they match the GNU semantics?


https://reviews.llvm.org/D32092



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Daniel Berlin via Phabricator via cfe-commits
dberlin added a comment.

In https://reviews.llvm.org/D31885#727529, @efriedma wrote:

> > Such an effective type change must be more explicit than "i allocated 
> > typeless memory, and so i can do what i want with it".
>
> How can you change the effective type of malloc'ed memory in C, if storing a 
> value of a new type doesn't have any effect?  memset?  A new C language 
> feature?  Something else?


memcpy is the traditional way, but in some sense it doesn't matter.
What you've pointed out is a clear standards bug in the sense that there *is no 
way* to implement it without removing TBAA from the standard.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Daniel Berlin via Phabricator via cfe-commits
dberlin added a comment.

In https://reviews.llvm.org/D31885#727519, @dberlin wrote:

> In https://reviews.llvm.org/D31885#727499, @hfinkel wrote:
>
> > In https://reviews.llvm.org/D31885#727371, @efriedma wrote:
> >
> > > In https://reviews.llvm.org/D31885#727167, @hfinkel wrote:
> > >
> > > > I'm not sure this is the right way to do this; I suspect we're lumping 
> > > > together a bunch of different bugs:
> > > >
> > > > 1. vector types need to have tbaa which makes them alias with their 
> > > > element types [to be clear, as vector types are an implementation 
> > > > extension, this is our choice; I believe most users expect this to be 
> > > > true, but I'm certainly open to leaving this as-is (i.e. the vector 
> > > > types and scalar types as independent/non-aliasing)].
> > > > 2. tbaa can't be used for write <-> write queries (only read <-> write 
> > > > queries) because the writes can change the effective type
> > > > 3. our 'struct' path TBAA for unions is broken (and to fix this we need 
> > > > to invert the tree structure, etc. as discussed on the list)
> > >
> > >
> > > See https://bugs.llvm.org/show_bug.cgi?id=28189 for a testcase for (2) 
> > > for this which doesn't involve unions.
> >
> >
> > Yes, this is what I had in mind. However, we may just want to not handle 
> > this at all. The demonstration you provide:
> >
> >   #include 
> >   #include 
> >   #include 
> >   int f(int* x, int *y) {
> > *x = 10;
> > int z = *y;
> > *(float*)x = 1.0;
> > return z;
> >   }
> >   int (*ff)(int*,int*) = f;
> >   int main() {
> > void* x = malloc(4);
> > printf("%d\n", ff(x, x));
> >   }
> >   
> >
> > shows that the problem is more than I implied. To support this, we not only 
> > need to ignore the TBAA between the two writes (*x and *(float*)x), but 
> > also between the float write and the preceding int read. I wonder how much 
> > of TBAA we could keep at all and still support this. Thoughts?
>
>
> The standard is just kind of broken here, 
>  It assumes that you can assign effective types at object creation points, 
> and track them for all time.
>  But you can't.  f() could be in a different translation unit, but it still 
> needs to be allowed to assume that the int *and the float *can't possible 
> conflict.  Otherwise, tbaa is useless.  This is even now codified for unions 
> after many years.
>  What is being demonstrated is just another way to achieve the same problem 
> was fixed by requiring union accesses to be explicit, and so i'd say it 
> should have the same resolution:
>  Such an effective type change must be more explicit than "i allocated 
> typeless memory, and so i can do what i want with it".
>  Because we can't *ever* make that work.


In particular, i could have:

foo.c:

  #include 
  #include 
  #include 
  int f(int* x, int *y) {
*x = 10;
int z = *y;
*(float*)x = 1.0;
return z;
  }

bar.c:

  extern int f(int *, int *)
  
  int (*ff)(int*,int*) = f;
  int main() {
void* x = malloc(4);
printf("%d\n", ff(x, x));
  }

In foo.c, there is no information you could ever use to tell you the *(float*) 
is legal or illegal.  That is just a normal function :)

Thus, GCC, et all have taken the position that if you change the effective 
type, it must be completely visible in all cases.
Anything else would have rules that change when you inline, do LTO, etc
This where the "must make union accesses visible" came from.  I'm not sure what 
we would do for malloc+memcpy'd memory, but i assume something similar: It must 
be completely visible that it came from typeless memory, in all cases, and then 
we could tag it properly.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> Such an effective type change must be more explicit than "i allocated 
> typeless memory, and so i can do what i want with it".

How can you change the effective type of malloc'ed memory in C, if storing a 
value of a new type doesn't have any effect?  memset?  A new C language 
feature?  Something else?


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D32092#727518, @zahiraam wrote:

> Forgot to mention that this is for C only. CL doesn't compile this 
> declaration in a C++ context.
>  Please see:
>  https://godbolt.org/g/WRhyjL


Oh, that's fun.

It's not at all clear that this isn't simply an MSVC bug. Can you work around 
this in your project rather than introduce an undocumented MSVC attribute?


https://reviews.llvm.org/D32092



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Daniel Berlin via Phabricator via cfe-commits
dberlin added a comment.

In https://reviews.llvm.org/D31885#727499, @hfinkel wrote:

> In https://reviews.llvm.org/D31885#727371, @efriedma wrote:
>
> > In https://reviews.llvm.org/D31885#727167, @hfinkel wrote:
> >
> > > I'm not sure this is the right way to do this; I suspect we're lumping 
> > > together a bunch of different bugs:
> > >
> > > 1. vector types need to have tbaa which makes them alias with their 
> > > element types [to be clear, as vector types are an implementation 
> > > extension, this is our choice; I believe most users expect this to be 
> > > true, but I'm certainly open to leaving this as-is (i.e. the vector types 
> > > and scalar types as independent/non-aliasing)].
> > > 2. tbaa can't be used for write <-> write queries (only read <-> write 
> > > queries) because the writes can change the effective type
> > > 3. our 'struct' path TBAA for unions is broken (and to fix this we need 
> > > to invert the tree structure, etc. as discussed on the list)
> >
> >
> > See https://bugs.llvm.org/show_bug.cgi?id=28189 for a testcase for (2) for 
> > this which doesn't involve unions.
>
>
> Yes, this is what I had in mind. However, we may just want to not handle this 
> at all. The demonstration you provide:
>
>   #include 
>   #include 
>   #include 
>   int f(int* x, int *y) {
> *x = 10;
> int z = *y;
> *(float*)x = 1.0;
> return z;
>   }
>   int (*ff)(int*,int*) = f;
>   int main() {
> void* x = malloc(4);
> printf("%d\n", ff(x, x));
>   }
>   
>
> shows that the problem is more than I implied. To support this, we not only 
> need to ignore the TBAA between the two writes (*x and *(float*)x), but also 
> between the float write and the preceding int read. I wonder how much of TBAA 
> we could keep at all and still support this. Thoughts?


The standard is just kind of broken here, 
It assumes that you can assign effective types at object creation points, and 
track them for all time.
But you can't.  f() could be in a different translation unit, but it still 
needs to be allowed to assume that the int *and the float *can't possible 
conflict.  Otherwise, tbaa is useless.  This is even now codified for unions 
after many years.
What is being demonstrated is just another way to achieve the same problem was 
fixed by requiring union accesses to be explicit, and so i'd say it should have 
the same resolution:
Such an effective type change must be more explicit than "i allocated typeless 
memory, and so i can do what i want with it".
Because we can't *ever* make that work.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

Forgot to mention that this is for C only. CL doesn't compile this declaration 
in a C++ context.
Please see:
https://godbolt.org/g/WRhyjL


https://reviews.llvm.org/D32092



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


[PATCH] D32081: Add support for editor placeholders to Clang's lexer

2017-04-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

In https://reviews.llvm.org/D32081#727450, @benlangmuir wrote:

> Rather than stick ranges into the diagnostic engine, I think it would be 
> cleaner to have the identifier have a method like `isEditorPlaceholder()` 
> that can be used to avoid situations like this in a principled way, or to 
> customize behaviour for placeholders in the parser, etc.  That's how we are 
> handling it in Swift.  Using an API on the placeholder is also better for 
> handling errors that could be caused by the placeholder but not have it as 
> the primary location.
>
> What do you think?


I thought about this as well. I'm not sure which way is better though. The 
current way is simple in the sense that we automatically suppress all 
diagnostics in the placeholder, so we don't have to modify the parser at all. 
Clang generates placeholders in a bunch of different places so I reckon 
there'll have to be a lot of modifications to suppress all problematic cases. 
Although I suppose that if we teach the parser about the most common places 
where placeholders could occur (e.g. expressions), that would probably suppress 
the majority of diagnostics that we care about. I'll try out the parser changes 
right now.


Repository:
  rL LLVM

https://reviews.llvm.org/D32081



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D32092#727507, @zahiraam wrote:

> ksh-3.2$ cat test3.c
>  static void __declspec(inline) foo() {
>  }
>
> int main()
>  {
>
>   foo();
>
> }
>
> ksh-3.2$ cl test3.c
>  Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x64
>  Copyright (C) Microsoft Corporation.  All rights reserved.
>
> test3.c
>  Microsoft (R) Incremental Linker Version 14.00.24215.1
>  Copyright (C) Microsoft Corporation.  All rights reserved.
>
> /out:test3.exe
>  test3.obj
>  ksh-3.2$
>
> This is for an application that we are running here that is failing.


I just tested this on 19.10.25017, 19.10.25206.0 and 14.0.25431.01 and none of 
them accept your code.

https://godbolt.org/g/xk1ciG


https://reviews.llvm.org/D32092



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

ksh-3.2$ cat test3.c
static void __declspec(inline) foo() {
}

int main()
{

  foo();

}

ksh-3.2$ cl test3.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

test3.c
Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test3.exe
test3.obj
ksh-3.2$

This is for an application that we are running here that is failing.


https://reviews.llvm.org/D32092



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In https://reviews.llvm.org/D31885#727371, @efriedma wrote:

> In https://reviews.llvm.org/D31885#727167, @hfinkel wrote:
>
> > I'm not sure this is the right way to do this; I suspect we're lumping 
> > together a bunch of different bugs:
> >
> > 1. vector types need to have tbaa which makes them alias with their element 
> > types [to be clear, as vector types are an implementation extension, this 
> > is our choice; I believe most users expect this to be true, but I'm 
> > certainly open to leaving this as-is (i.e. the vector types and scalar 
> > types as independent/non-aliasing)].
> > 2. tbaa can't be used for write <-> write queries (only read <-> write 
> > queries) because the writes can change the effective type
> > 3. our 'struct' path TBAA for unions is broken (and to fix this we need to 
> > invert the tree structure, etc. as discussed on the list)
>
>
> See https://bugs.llvm.org/show_bug.cgi?id=28189 for a testcase for (2) for 
> this which doesn't involve unions.


Yes, this is what I had in mind. However, we may just want to not handle this 
at all. The demonstration you provide:

  #include 
  #include 
  #include 
  int f(int* x, int *y) {
*x = 10;
int z = *y;
*(float*)x = 1.0;
return z;
  }
  int (*ff)(int*,int*) = f;
  int main() {
void* x = malloc(4);
printf("%d\n", ff(x, x));
  }

shows that the problem is more than I implied. To support this, we not only 
need to ignore the TBAA between the two writes (*x and *(float*)x), but also 
between the float write and the preceding int read. I wonder how much of TBAA 
we could keep at all and still support this. Thoughts?


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/Basic/Attr.td:869
 def GNUInline : InheritableAttr {
-  let Spellings = [GCC<"gnu_inline">];
+  let Spellings = [GCC<"gnu_inline">, Declspec<"inline">];
   let Subjects = SubjectList<[Function]>;

I cannot see any documentation on MSDN for this spelling of the attribute, and 
MSVC 2015 rejects it. What is the motivating use case for this spelling?


https://reviews.llvm.org/D32092



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


[PATCH] D31757: [clang-tidy] Add a clang-tidy check for possible inefficient vector operations

2017-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:109-111
+  auto AllVectorVarRefs = utils::decl_ref_expr::allDeclRefExprs(
+  *VectorVarDecl, *LoopParent, *Result.Context);
+  for (const auto *Ref : AllVectorVarRefs) {

hokein wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > I'm not certain what types are being used here. Can you turn 
> > > `AllVectorVarRefs` into something with an explicit type so that I can 
> > > know what `Ref`'s type is?
> > I may not have been clear -- I don't mean that the variable name should 
> > contain type information, I mean that the type should not be automatically 
> > deduced. We only use `auto` when the type is spelled explicitly in the 
> > initialization or is otherwise obvious from context (like range-based for 
> > loops).
> I'd prefer to use `auto` to initialize `AllVectorVarRefExprs`, as its type is 
> `SmallPtrSet`, which is a long and noisy name. Using 
> `auto` can increases readability here.
It doesn't increase readability when someone reviewing the code has no idea 
what types are involved and has to ask you for clarification. `auto` should 
only be used when the type is obvious from the context or spelling the type is 
*really* noisy. A single level of template goop is a very small amount of noise.



Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:116
+  *VectorVarDecl, *LoopParent, *Result.Context);
+  for (const DeclRefExpr* RefExpr : AllVectorVarRefExprs) {
+// Skip cases where there are usages (defined as DeclRefExpr that refers to

Formatting (and you can use `auto` here once you correct the type above).


https://reviews.llvm.org/D31757



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


[PATCH] D32092: Attribute inline

2017-04-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam created this revision.

Added support for attribute inline for a __declspec declaration.


https://reviews.llvm.org/D32092

Files:
  include/clang/Basic/Attr.td
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/declspec-inline.c
  test\Sema\declspec-inline.c


Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -639,7 +639,10 @@
   // else is a malformed declspec.
   bool IsString = Tok.getKind() == tok::string_literal;
   if (!IsString && Tok.getKind() != tok::identifier &&
-  Tok.getKind() != tok::kw_restrict) {
+  Tok.getKind() != tok::kw_restrict &&
+ (Tok.getKind() != tok::kw_inline ||
+  (Tok.getKind() == tok::kw_inline  &&
+   getLangOpts().CPlusPlus) ) ){
 Diag(Tok, diag::err_ms_declspec_type);
 T.skipToEnd();
 return;
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4377,7 +4377,7 @@
 
 static void handleGNUInlineAttr(Sema , Decl *D, const AttributeList ) {
   FunctionDecl *Fn = cast(D);
-  if (!Fn->isInlineSpecified()) {
+   if (!Fn->isInlineSpecified() && !Attr.isDeclspecAttribute()) {
 S.Diag(Attr.getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
 return;
   }
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -866,7 +866,7 @@
 }
 
 def GNUInline : InheritableAttr {
-  let Spellings = [GCC<"gnu_inline">];
+  let Spellings = [GCC<"gnu_inline">, Declspec<"inline">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [Undocumented];
 }
Index: test/Sema/declspec-inline.c
===
--- test/Sema/declspec-inline.c
+++ test/Sema/declspec-inline.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -verify -fms-compatibility %s
+// expected-no-diagnostics
+
+static int __declspec(inline) foo(int i) {
+  int k;
+  int a[1];
+  for (k=0; k<=i; k++)
+{
+  a[k] = a[k]*k;
+}
+  return a[k];
+}
+
+int main()
+{
+  int i=20;
+  return foo(2000);
+}


Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -639,7 +639,10 @@
   // else is a malformed declspec.
   bool IsString = Tok.getKind() == tok::string_literal;
   if (!IsString && Tok.getKind() != tok::identifier &&
-  Tok.getKind() != tok::kw_restrict) {
+  Tok.getKind() != tok::kw_restrict &&
+	  (Tok.getKind() != tok::kw_inline ||
+		   (Tok.getKind() == tok::kw_inline  &&
+			getLangOpts().CPlusPlus) ) ){
 Diag(Tok, diag::err_ms_declspec_type);
 T.skipToEnd();
 return;
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4377,7 +4377,7 @@
 
 static void handleGNUInlineAttr(Sema , Decl *D, const AttributeList ) {
   FunctionDecl *Fn = cast(D);
-  if (!Fn->isInlineSpecified()) {
+   if (!Fn->isInlineSpecified() && !Attr.isDeclspecAttribute()) {
 S.Diag(Attr.getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
 return;
   }
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -866,7 +866,7 @@
 }
 
 def GNUInline : InheritableAttr {
-  let Spellings = [GCC<"gnu_inline">];
+  let Spellings = [GCC<"gnu_inline">, Declspec<"inline">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [Undocumented];
 }
Index: test/Sema/declspec-inline.c
===
--- test/Sema/declspec-inline.c
+++ test/Sema/declspec-inline.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -verify -fms-compatibility %s
+// expected-no-diagnostics
+
+static int __declspec(inline) foo(int i) {
+  int k;
+  int a[1];
+  for (k=0; k<=i; k++)
+{
+  a[k] = a[k]*k;
+}
+  return a[k];
+}
+
+int main()
+{
+  int i=20;
+  return foo(2000);
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31440: PR32382: Adapt to LLVM changes in DIExpression.

2017-04-14 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl updated this revision to Diff 95318.
aprantl edited the summary of this revision.
Herald added a subscriber: nhaehnle.

https://reviews.llvm.org/D31440

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGen/debug-info-vla.c
  test/CodeGenCXX/debug-info.cpp
  test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl

Index: test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
===
--- test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
+++ test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
@@ -1,6 +1,5 @@
 // RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s
 
-// CHECK-DAG: ![[NONE:[0-9]+]] = !DIExpression()
 // CHECK-DAG: ![[LOCAL:[0-9]+]] = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
 // CHECK-DAG: ![[PRIVATE:[0-9]+]] = !DIExpression(DW_OP_constu, 1, DW_OP_swap, DW_OP_xderef)
 
@@ -82,7 +81,7 @@
   int *FuncVar4 = Tmp1;
 
   // CHECK-DAG: ![[FUNCVAR5:[0-9]+]] = !DILocalVariable(name: "FuncVar5", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
-  // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(1)** {{.*}}, metadata ![[FUNCVAR5]], metadata ![[NONE]]), !dbg !{{[0-9]+}}
+  // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(1)** {{.*}}, metadata ![[FUNCVAR5]], metadata ![[NONE:[0-9]+]]), !dbg !{{[0-9]+}}
   global int *constant FuncVar5 = KernelArg0;
   // CHECK-DAG: ![[FUNCVAR6:[0-9]+]] = !DILocalVariable(name: "FuncVar6", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
   // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(2)** {{.*}}, metadata ![[FUNCVAR6]], metadata ![[NONE]]), !dbg !{{[0-9]+}}
Index: test/CodeGenCXX/debug-info.cpp
===
--- test/CodeGenCXX/debug-info.cpp
+++ test/CodeGenCXX/debug-info.cpp
@@ -21,6 +21,7 @@
 
 // CHECK: ![[INCTYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "incomplete"
 // CHECK-SAME:   DIFlagFwdDecl
+// CHECK: ![[EXPR]] = !DIExpression()
 
 template struct Identity {
   typedef T Type;
@@ -117,7 +118,6 @@
 // For some reason function arguments ended up down here
 // CHECK: ![[F]] = !DILocalVariable(name: "f", arg: 1, scope: ![[FUNC]]
 // CHECK-SAME:  type: ![[FOO]]
-// CHECK: ![[EXPR]] = !DIExpression(DW_OP_deref)
 foo func(foo f) {
   return f; // reference 'f' for now because otherwise we hit another bug
 }
Index: test/CodeGen/debug-info-vla.c
===
--- test/CodeGen/debug-info-vla.c
+++ test/CodeGen/debug-info-vla.c
@@ -4,8 +4,8 @@
 {
 // CHECK: dbg.declare
 // CHECK: dbg.declare({{.*}}, metadata ![[VAR:.*]], metadata ![[EXPR:.*]])
-// CHECK: ![[VAR]] = !DILocalVariable(name: "vla",{{.*}} line: [[@LINE+2]]
-// CHECK: ![[EXPR]] = !DIExpression(DW_OP_deref)
+// CHECK: ![[EXPR]] = !DIExpression()
+// CHECK: ![[VAR]] = !DILocalVariable(name: "vla",{{.*}} line: [[@LINE+1]]
   int vla[s];
   int i;
   for (i = 0; i < s; i++) {
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3466,17 +3466,17 @@
   // functions there won't be an implicit param at arg1 and
   // otherwise it is 'self' or 'this'.
   if (isa(VD) && ArgNo && *ArgNo == 1)
-Flags |= llvm::DINode::FlagObjectPointer;
-  if (auto *Arg = dyn_cast(Storage))
-if (Arg->getType()->isPointerTy() && !Arg->hasByValAttr() &&
-!VD->getType()->isPointerType())
-  Expr.push_back(llvm::dwarf::DW_OP_deref);
+  Flags |= llvm::DINode::FlagObjectPointer;
 
+  // Note: Older versions of clang used to emit byval references with an extra
+  // DW_OP_deref, because they referenced the IR arg directly instead of
+  // referencing an alloca. Newer versions of LLVM don't treat allocas
+  // differently from other function arguments when used in a dbg.declare.
   auto *Scope = cast(LexicalBlockStack.back());
-
   StringRef Name = VD->getName();
   if (!Name.empty()) {
 if (VD->hasAttr()) {
+  // Here, we need an offset *into* the alloca.
   CharUnits offset = CharUnits::fromQuantity(32);
   Expr.push_back(llvm::dwarf::DW_OP_plus);
   // offset of __forwarding field
@@ -3488,22 +3488,7 @@
   // offset of x field
   offset = CGM.getContext().toCharUnitsFromBits(XOffset);
   Expr.push_back(offset.getQuantity());
-
-  // Create the descriptor for the variable.
-  auto *D = ArgNo
-? DBuilder.createParameterVariable(Scope, VD->getName(),
-   *ArgNo, Unit, Line, Ty)
-: DBuilder.createAutoVariable(Scope, VD->getName(), Unit,
-  Line, Ty, Align);
-
-  // Insert an llvm.dbg.declare into 

[PATCH] D32010: [indexer] Record class template specializations using a new 'SpecializationOf' relationship

2017-04-14 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D32010



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


[PATCH] D32081: Add support for editor placeholders to Clang's lexer

2017-04-14 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

Rather than stick ranges into the diagnostic engine, I think it would be 
cleaner to have the identifier have a method like `isEditorPlaceholder()` that 
can be used to avoid situations like this in a principled way, or to customize 
behaviour for placeholders in the parser, etc.  That's how we are handling it 
in Swift.  Using an API on the placeholder is also better for handling errors 
that could be caused by the placeholder but not have it as the primary location.

What do you think?




Comment at: include/clang/Driver/Options.td:1473
 
+def fsuppress_editor_placeholder_error : Flag<["-"], 
"fsuppress-editor-placeholder-error">, Group,
+  Flags<[CC1Option]>,

How about -fallow-editor-placeholder?  It's a little shorter, and not specific 
to a single error.


Repository:
  rL LLVM

https://reviews.llvm.org/D32081



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


[PATCH] D32063: [clang-move] cleanup: create ClangMoveActionFactory on the stack

2017-04-14 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL300356: [clang-move] Create ClangMoveActionFactory on stack 
(authored by alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D32063?vs=95233=95326#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32063

Files:
  clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp


Index: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
===
--- clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
+++ clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
@@ -127,10 +127,9 @@
   move::ClangMoveContext Context{Spec, Tool.getReplacements(),
  InitialDirectory.str(), Style, DumpDecls};
   move::DeclarationReporter Reporter;
-  auto Factory = llvm::make_unique(
-  , );
-
-  int CodeStatus = Tool.run(Factory.get());
+  move::ClangMoveActionFactory Factory(, );
+  
+  int CodeStatus = Tool.run();
   if (CodeStatus)
 return CodeStatus;
 


Index: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
===
--- clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
+++ clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
@@ -127,10 +127,9 @@
   move::ClangMoveContext Context{Spec, Tool.getReplacements(),
  InitialDirectory.str(), Style, DumpDecls};
   move::DeclarationReporter Reporter;
-  auto Factory = llvm::make_unique(
-  , );
-
-  int CodeStatus = Tool.run(Factory.get());
+  move::ClangMoveActionFactory Factory(, );
+  
+  int CodeStatus = Tool.run();
   if (CodeStatus)
 return CodeStatus;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r300356 - [clang-move] Create ClangMoveActionFactory on stack

2017-04-14 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Fri Apr 14 13:12:11 2017
New Revision: 300356

URL: http://llvm.org/viewvc/llvm-project?rev=300356=rev
Log:
[clang-move] Create ClangMoveActionFactory on stack

This diff removes unnecessary using of unique_ptr with ClangMoveActionFactory 
(pico cleanup).
NFC

Test plan: make check-clang-tools

Differential revision: https://reviews.llvm.org/D32063

Modified:
clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp

Modified: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp?rev=300356=300355=300356=diff
==
--- clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp (original)
+++ clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp Fri Apr 14 
13:12:11 2017
@@ -127,10 +127,9 @@ int main(int argc, const char **argv) {
   move::ClangMoveContext Context{Spec, Tool.getReplacements(),
  InitialDirectory.str(), Style, DumpDecls};
   move::DeclarationReporter Reporter;
-  auto Factory = llvm::make_unique(
-  , );
-
-  int CodeStatus = Tool.run(Factory.get());
+  move::ClangMoveActionFactory Factory(, );
+  
+  int CodeStatus = Tool.run();
   if (CodeStatus)
 return CodeStatus;
 


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


Re: r300295 - [docs] UBSan: Mention that print_stacktrace=1 is unsupported on Darwin

2017-04-14 Thread Vedant Kumar via cfe-commits
I hacked the UBSan runtime locally to use the fast unwinder. I thought this 
"worked", but it seems to only print one frame. This explains why:


 67 void BufferedStackTrace::FastUnwindStack(uptr pc, uptr bp, uptr stack_top,  


  
 68  uptr stack_bottom, u32 max_depth) 
{   

   
 69   const uptr kPageSize = GetPageSizeCached();   


 
 70   CHECK_GE(max_depth, 2);   


 
 71   trace_buffer[0] = pc; 


 
 72   size = 1; 


 
 73   if (stack_top < 4096) return;  // Sanity check for stack top.  


There is a comment by Alexey Samsonov giving a warning about this:



   
 34   // We can only use slow unwind, as we don't have any information about 
stack   


 
 35   // top/bottom.


  
 36   // FIXME: It's better to respect "fast_unwind_on_fatal" runtime flag and  


  
 37   // fetch stack top/bottom information if we have it (e.g. if we're 
running 


 
 38   // under ASan).   


 
 39   if (StackTrace::WillUseFastUnwind(false)) 


 
 40 return;  

So, in the absence of stack top/bottom info, we'd need to add support for the 
slow unwinder.

vedant


> On Apr 14, 2017, at 10:19 AM, Kuba Mracek  wrote:
> 
> What exactly is wrong with the fast unwinder?  It's used in ASan and TSan and 
> besides not knowing about inlined frames, it works great.  But we're almost 
> always dealing with code that has frame pointers (and the sanitizer runtimes 
> themselves are built with frame pointers).
> 
> Kuba
> 
>> On 13 Apr 2017, at 19:18, Vedant Kumar via 

[PATCH] D30283: [ubsan] Reduce alignment checking of C++ object pointers

2017-04-14 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: test/CodeGenCXX/ubsan-suppress-checks.cpp:25
+// LAMBDA: and i64 %[[THISINT2]], 3, !nosanitize
+// LAMBDA: call void @__ubsan_handle_type_mismatch
+

LAMBDA-NOT: call void @__ubsan_handle_type_mismatch ?


https://reviews.llvm.org/D30283



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


r300347 - Removing a redundant, but harmless, %s; NFC.

2017-04-14 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Apr 14 12:37:29 2017
New Revision: 300347

URL: http://llvm.org/viewvc/llvm-project?rev=300347=rev
Log:
Removing a redundant, but harmless, %s; NFC.

Modified:
cfe/trunk/test/Modules/ExtDebugInfo.cpp

Modified: cfe/trunk/test/Modules/ExtDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ExtDebugInfo.cpp?rev=300347=300346=300347=diff
==
--- cfe/trunk/test/Modules/ExtDebugInfo.cpp (original)
+++ cfe/trunk/test/Modules/ExtDebugInfo.cpp Fri Apr 14 12:37:29 2017
@@ -16,7 +16,7 @@
 // RUN: %clang_cc1 -std=c++11 -debug-info-kind=standalone \
 // RUN: -dwarf-ext-refs -fmodule-format=obj \
 // RUN: -triple %itanium_abi_triple \
-// RUN: -include-pch %t.pch %s -emit-llvm -o %t-pch.ll %s
+// RUN: -include-pch %t.pch %s -emit-llvm -o %t-pch.ll
 // RUN: cat %t-pch.ll |  FileCheck %s
 // RUN: cat %t-pch.ll |  FileCheck %s --check-prefix=CHECK-PCH
 


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


[PATCH] D31126: Do not run tests for crash recovery if libstdc++ safe mode is enabled

2017-04-14 Thread Galina via Phabricator via cfe-commits
gkistanova accepted this revision.
gkistanova added a comment.
This revision is now accepted and ready to land.

LGTM

Thanks

Galina


https://reviews.llvm.org/D31126



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

In https://reviews.llvm.org/D31885#727167, @hfinkel wrote:

> I'm not sure this is the right way to do this; I suspect we're lumping 
> together a bunch of different bugs:
>
> 1. vector types need to have tbaa which makes them alias with their element 
> types [to be clear, as vector types are an implementation extension, this is 
> our choice; I believe most users expect this to be true, but I'm certainly 
> open to leaving this as-is (i.e. the vector types and scalar types as 
> independent/non-aliasing)].
> 2. tbaa can't be used for write <-> write queries (only read <-> write 
> queries) because the writes can change the effective type
> 3. our 'struct' path TBAA for unions is broken (and to fix this we need to 
> invert the tree structure, etc. as discussed on the list)


See https://bugs.llvm.org/show_bug.cgi?id=28189 for a testcase for (2) for this 
which doesn't involve unions.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Daniel Berlin via Phabricator via cfe-commits
dberlin added a comment.

In https://reviews.llvm.org/D31885#727370, @dberlin wrote:

> In https://reviews.llvm.org/D31885#727352, @hfinkel wrote:
>
> > > I'm not sure about the solution to #2, because i thought there were very 
> > > specific points in time at which the effective type could change.
> >
> > I think this is a key point. I'm not sure that there are specific points 
> > that the frontend can deduce:
> >
> >   union U {
> > int i;
> > float f;
> >   };
> >   
> >   void bar1(int *i) {
> > *i = 0; // we just reset the type here
> >   }
> >   
> >   void bar2(float *f) {
> > *f = 0.0f; // we just reset the type here too
> >   }
> >   
> >   void foo(U *u) {
> > bar1(>i);
> > bar2(>f);
> >   }
> >   
> >
> > Even if the union has structs instead of scalar types, I'm not sure that 
> > changes the situation. There certainly are situation where you can't 
> > silently change the types of objects in C++ just by starting to write a to 
> > differently-typed object at the same location, but I think that using this 
> > property relies on having some lifetime information for the objects in 
> > question, and so AA would need to be able to use this lifetime information 
> > to do more. This seems like an orthogonal issue (i.e. we can always add 
> > TBAA write <-> write ability in the presence of such lifetime information 
> > as an additional feature). Maybe I'm missing something...
>
>
> Union type accesses must explicitly be made through a union if you want the 
> effective type to change.
>  This is now actually codified in either c11 or c++14 (i can't remember 
> which), but even before that, it's the only thing gcc/llvm have *ever*  
> guaranteed.
>
> If you don't make it an explicitly visible union access at each point, you 
> will get wrong code, and this is pretty much unsolvable in general if you 
> want tbaa to work at all.
>
> Because otherwise foo, bar1, and bar2 could all be in different translation 
> units, in which case, you just destroyed all usefulness of tbaa because it 
> has to assume all pointers can conflict with all pointers :)


To expand a bit:
It's trivial to make the fact that they are in a union invisible.

In the above example, assuming you make the union accesses explicit, the union 
accesses themselves have to *always* conflict with all types in the union , and 
now you can do that if you know it's a union access., but you couldn't 
otherwise.
IE this is the precise reason that gcc/llvm have required the union accesses be 
explicit - to associate them with the right tbaa type.

Past that, you aren't going to be able to usefully differentiate between the 
current effective type of a union.

There are a few other points where the effective type may change, but i believe 
the frontend does know about them (IE placement new, etc).


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Daniel Berlin via Phabricator via cfe-commits
dberlin added a comment.

In https://reviews.llvm.org/D31885#727352, @hfinkel wrote:

> > I'm not sure about the solution to #2, because i thought there were very 
> > specific points in time at which the effective type could change.
>
> I think this is a key point. I'm not sure that there are specific points that 
> the frontend can deduce:
>
>   union U {
> int i;
> float f;
>   };
>   
>   void bar1(int *i) {
> *i = 0; // we just reset the type here
>   }
>   
>   void bar2(float *f) {
> *f = 0.0f; // we just reset the type here too
>   }
>   
>   void foo(U *u) {
> bar1(>i);
> bar2(>f);
>   }
>   
>
> Even if the union has structs instead of scalar types, I'm not sure that 
> changes the situation. There certainly are situation where you can't silently 
> change the types of objects in C++ just by starting to write a to 
> differently-typed object at the same location, but I think that using this 
> property relies on having some lifetime information for the objects in 
> question, and so AA would need to be able to use this lifetime information to 
> do more. This seems like an orthogonal issue (i.e. we can always add TBAA 
> write <-> write ability in the presence of such lifetime information as an 
> additional feature). Maybe I'm missing something...


Union type accesses must explicitly be made through a union if you want the 
effective type to change.
This is now actually codified in either c11 or c++14 (i can't remember which), 
but even before that, it's the only thing gcc/llvm have *ever*  guaranteed.

If you don't make it an explicitly visible union access at each point, you will 
get wrong code, and this is pretty much unsolvable in general if you want tbaa 
to work at all.

Because otherwise foo, bar1, and bar2 could all be in different translation 
units, in which case, you just destroyed all usefulness of tbaa because it has 
to assume all pointers can conflict with all pointers :)


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


Re: r300295 - [docs] UBSan: Mention that print_stacktrace=1 is unsupported on Darwin

2017-04-14 Thread Kuba Mracek via cfe-commits
What exactly is wrong with the fast unwinder?  It's used in ASan and TSan and 
besides not knowing about inlined frames, it works great.  But we're almost 
always dealing with code that has frame pointers (and the sanitizer runtimes 
themselves are built with frame pointers).

Kuba

> On 13 Apr 2017, at 19:18, Vedant Kumar via cfe-commits 
>  wrote:
> 
> Does anyone know what it would take to get the slow unwinder to work on 
> Darwin?
> 
> thanks,
> vedant
> 
>> On Apr 13, 2017, at 6:59 PM, Vedant Kumar via cfe-commits 
>>  wrote:
>> 
>> Author: vedantk
>> Date: Thu Apr 13 20:59:44 2017
>> New Revision: 300295
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=300295=rev
>> Log:
>> [docs] UBSan: Mention that print_stacktrace=1 is unsupported on Darwin
>> 
>> Printing out stack traces along with UBSan diagnostics is unsupported on
>> Darwin. That's because it isn't possible to use the fast unwinder or the
>> slow unwinder.
>> 
>> Apparently, it's inappropriate to use the fast unwinder for UBSan
>> issues. I'm not exactly sure why (see the comment in ubsan_diag.cc).
>> Forcing use of the fast unwinder produces decent results, AFAICT.
>> 
>> Darwin also does not appear to have a slow unwinder suitable for use
>> with the sanitizers. Apparently that's because of PR20800 [1][2]. But
>> that bug has been fixed. I'm not sure if there is anything preventing
>> use of the slow unwinder now.
>> 
>> Currently, passing UBSAN_OPTIONS=print_stacktrace=1 does nothing on
>> Darwin. This isn't good, but it might be a while before we can fix the
>> situation, so we should at least document it.
>> 
>> [1] https://github.com/google/sanitizers/issues/137
>> "We can't use the slow unwinder on OSX now, because Clang produces
>> incorrect unwind info for the ASan runtime functions on OSX
>> (http://llvm.org/PR20800)."
>> 
>> [2] https://bugs.llvm.org/show_bug.cgi?id=20800
>> Bug 20800 - Invalid compact unwind info generated for a function without
>> frame pointers on OSX
>> 
>> Modified:
>>   cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
>> 
>> Modified: cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UndefinedBehaviorSanitizer.rst?rev=300295=300294=300295=diff
>> ==
>> --- cfe/trunk/docs/UndefinedBehaviorSanitizer.rst (original)
>> +++ cfe/trunk/docs/UndefinedBehaviorSanitizer.rst Thu Apr 13 20:59:44 2017
>> @@ -157,6 +157,8 @@ will need to:
>>   ``UBSAN_OPTIONS=print_stacktrace=1``.
>> #. Make sure ``llvm-symbolizer`` binary is in ``PATH``.
>> 
>> +Stacktrace printing for UBSan issues is currently not supported on Darwin.
>> +
>> Issue Suppression
>> =
>> 
>> 
>> 
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

I'm not really concerned about the approach here---I can abandon this patch if 
you have something better.  You have two testcases.  One is based on an issue 
that our customer encountered.  As long as TBAA doesn't produce false 
negatives, it's all good.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

> I'm not sure about the solution to #2, because i thought there were very 
> specific points in time at which the effective type could change.

I think this is a key point. I'm not sure that there are specific points that 
the frontend can deduce:

  union U {
int i;
float f;
  };
  
  void bar1(int *i) {
*i = 0; // we just reset the type here
  }
  
  void bar2(float *f) {
*f = 0.0f; // we just reset the type here too
  }
  
  void foo(U *u) {
bar1(>i);
bar2(>f);
  }

Even if the union has structs instead of scalar types, I'm not sure that 
changes the situation. There certainly are situation where you can't silently 
change the types of objects in C++ just by starting to write a to 
differently-typed object at the same location, but I think that using this 
property relies on having some lifetime information for the objects in 
question, and so AA would need to be able to use this lifetime information to 
do more. This seems like an orthogonal issue (i.e. we can always add TBAA write 
<-> write ability in the presence of such lifetime information as an additional 
feature). Maybe I'm missing something...

> As we've repeatedly said, memory locations and pointers don't really have 
> tbaa info, instructions do.

I agree (and I think we'll need to do this in order to handle such lifetime 
information (and there are also issues around noalias handling that are 
relevant)).


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D32029: [ObjC] Fix lifetime markers of loop variable in EmitObjCForCollectionStmt

2017-04-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL300340: [ObjC] Fix lifetime markers of loop variable in 
EmitObjCForCollectionStmt [take… (authored by kuba.brecka).

Changed prior to commit:
  https://reviews.llvm.org/D32029?vs=95271=95313#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32029

Files:
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/lib/CodeGen/CGObjC.cpp
  cfe/trunk/test/CodeGenObjC/arc-blocks.m
  cfe/trunk/test/CodeGenObjCXX/arc-references.mm

Index: cfe/trunk/lib/CodeGen/CGObjC.cpp
===
--- cfe/trunk/lib/CodeGen/CGObjC.cpp
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp
@@ -1469,6 +1469,8 @@
   if (DI)
 DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin());
 
+  RunCleanupsScope ForScope(*this);
+
   // The local variable comes into scope immediately.
   AutoVarEmission variable = AutoVarEmission::invalid();
   if (const DeclStmt *SD = dyn_cast(S.getElement()))
@@ -1499,8 +1501,6 @@
   ArrayType::Normal, 0);
   Address ItemsPtr = CreateMemTemp(ItemsTy, "items.ptr");
 
-  RunCleanupsScope ForScope(*this);
-
   // Emit the collection pointer.  In ARC, we do a retain.
   llvm::Value *Collection;
   if (getLangOpts().ObjCAutoRefCount) {
Index: cfe/trunk/lib/CodeGen/CGDecl.cpp
===
--- cfe/trunk/lib/CodeGen/CGDecl.cpp
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp
@@ -1118,6 +1118,12 @@
   if (D.hasAttr())
 EmitVarAnnotations(, address.getPointer());
 
+  // Make sure we call @llvm.lifetime.end.
+  if (emission.useLifetimeMarkers())
+EHStack.pushCleanup(NormalEHLifetimeMarker,
+ emission.getAllocatedAddress(),
+ emission.getSizeForLifetimeMarkers());
+
   return emission;
 }
 
@@ -1408,13 +1414,6 @@
 
   const VarDecl  = *emission.Variable;
 
-  // Make sure we call @llvm.lifetime.end.  This needs to happen
-  // *last*, so the cleanup needs to be pushed *first*.
-  if (emission.useLifetimeMarkers())
-EHStack.pushCleanup(NormalEHLifetimeMarker,
- emission.getAllocatedAddress(),
- emission.getSizeForLifetimeMarkers());
-
   // Check the type for a cleanup.
   if (QualType::DestructionKind dtorKind = D.getType().isDestructedType())
 emitAutoVarTypeCleanup(emission, dtorKind);
Index: cfe/trunk/test/CodeGenObjC/arc-blocks.m
===
--- cfe/trunk/test/CodeGenObjC/arc-blocks.m
+++ cfe/trunk/test/CodeGenObjC/arc-blocks.m
@@ -532,16 +532,16 @@
   // CHECK-NEXT: [[T0:%.*]] = load void ()*, void ()** [[B]]
   // CHECK-NEXT: [[T1:%.*]] = bitcast void ()* [[T0]] to i8*
   // CHECK-NEXT: call void @objc_release(i8* [[T1]])
-  // CHECK-NEXT: [[BPTR2:%.*]] = bitcast void ()** [[B]] to i8*
-  // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[BPTR2]])
 
   // CHECK-NEXT: [[T0:%.*]] = load i1, i1* [[CLEANUP_ACTIVE]]
   // CHECK-NEXT: br i1 [[T0]]
   // CHECK:  [[T0:%.*]] = load i8*, i8** [[CLEANUP_ADDR]]
   // CHECK-NEXT: call void @objc_release(i8* [[T0]])
   // CHECK-NEXT: br label
 
-  // CHECK:  [[T0:%.*]] = load i8*, i8** [[X]]
+  // CHECK:  [[BPTR2:%.*]] = bitcast void ()** [[B]] to i8*
+  // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[BPTR2]])
+  // CHECK-NEXT:  [[T0:%.*]] = load i8*, i8** [[X]]
   // CHECK-NEXT: call void @objc_release(i8* [[T0]])
   // CHECK-NEXT: ret void
 }
Index: cfe/trunk/test/CodeGenObjCXX/arc-references.mm
===
--- cfe/trunk/test/CodeGenObjCXX/arc-references.mm
+++ cfe/trunk/test/CodeGenObjCXX/arc-references.mm
@@ -21,7 +21,7 @@
   // CHECK: call void @_Z6calleev
   callee();
   // CHECK: call void @objc_release
-  // CHECK-NEXT: ret
+  // CHECK: ret
 }
 
 // No lifetime extension when we're binding a reference to an lvalue.
@@ -44,9 +44,9 @@
   const __weak id  = strong_id();
   // CHECK-NEXT: call void @_Z6calleev()
   callee();
+  // CHECK-NEXT: call void @objc_destroyWeak
   // CHECK-NEXT: [[PTR:%.*]] = bitcast i8*** [[REF]] to i8*
   // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[PTR]])
-  // CHECK-NEXT: call void @objc_destroyWeak
   // CHECK-NEXT: ret void
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r300340 - [ObjC] Fix lifetime markers of loop variable in EmitObjCForCollectionStmt [take 2]

2017-04-14 Thread Kuba Mracek via cfe-commits
Author: kuba.brecka
Date: Fri Apr 14 11:53:25 2017
New Revision: 300340

URL: http://llvm.org/viewvc/llvm-project?rev=300340=rev
Log:
[ObjC] Fix lifetime markers of loop variable in EmitObjCForCollectionStmt [take 
2]

CodeGenFunction::EmitObjCForCollectionStmt currently emits lifetime markers for 
the loop variable in an inconsistent way:  lifetime.start is emitted before the 
loop is entered, but lifetime.end is emitted inside the loop. AddressSanitizer 
uses these markers to track out-of-scope accesses to local variables, and we 
get false positives in Obj-C foreach loops (in the 2nd iteration of the loop). 
This patch keeps the loop variable alive for the whole loop by extending 
ForScope and registering the cleanup function inside EmitAutoVarAlloca.

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


Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjC/arc-blocks.m
cfe/trunk/test/CodeGenObjCXX/arc-references.mm

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=300340=300339=300340=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Apr 14 11:53:25 2017
@@ -1118,6 +1118,12 @@ CodeGenFunction::EmitAutoVarAlloca(const
   if (D.hasAttr())
 EmitVarAnnotations(, address.getPointer());
 
+  // Make sure we call @llvm.lifetime.end.
+  if (emission.useLifetimeMarkers())
+EHStack.pushCleanup(NormalEHLifetimeMarker,
+ emission.getAllocatedAddress(),
+ emission.getSizeForLifetimeMarkers());
+
   return emission;
 }
 
@@ -1408,13 +1414,6 @@ void CodeGenFunction::EmitAutoVarCleanup
 
   const VarDecl  = *emission.Variable;
 
-  // Make sure we call @llvm.lifetime.end.  This needs to happen
-  // *last*, so the cleanup needs to be pushed *first*.
-  if (emission.useLifetimeMarkers())
-EHStack.pushCleanup(NormalEHLifetimeMarker,
- emission.getAllocatedAddress(),
- emission.getSizeForLifetimeMarkers());
-
   // Check the type for a cleanup.
   if (QualType::DestructionKind dtorKind = D.getType().isDestructedType())
 emitAutoVarTypeCleanup(emission, dtorKind);

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=300340=300339=300340=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Fri Apr 14 11:53:25 2017
@@ -1469,6 +1469,8 @@ void CodeGenFunction::EmitObjCForCollect
   if (DI)
 DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin());
 
+  RunCleanupsScope ForScope(*this);
+
   // The local variable comes into scope immediately.
   AutoVarEmission variable = AutoVarEmission::invalid();
   if (const DeclStmt *SD = dyn_cast(S.getElement()))
@@ -1499,8 +1501,6 @@ void CodeGenFunction::EmitObjCForCollect
   ArrayType::Normal, 0);
   Address ItemsPtr = CreateMemTemp(ItemsTy, "items.ptr");
 
-  RunCleanupsScope ForScope(*this);
-
   // Emit the collection pointer.  In ARC, we do a retain.
   llvm::Value *Collection;
   if (getLangOpts().ObjCAutoRefCount) {

Modified: cfe/trunk/test/CodeGenObjC/arc-blocks.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-blocks.m?rev=300340=300339=300340=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-blocks.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-blocks.m Fri Apr 14 11:53:25 2017
@@ -532,8 +532,6 @@ void test13(id x) {
   // CHECK-NEXT: [[T0:%.*]] = load void ()*, void ()** [[B]]
   // CHECK-NEXT: [[T1:%.*]] = bitcast void ()* [[T0]] to i8*
   // CHECK-NEXT: call void @objc_release(i8* [[T1]])
-  // CHECK-NEXT: [[BPTR2:%.*]] = bitcast void ()** [[B]] to i8*
-  // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[BPTR2]])
 
   // CHECK-NEXT: [[T0:%.*]] = load i1, i1* [[CLEANUP_ACTIVE]]
   // CHECK-NEXT: br i1 [[T0]]
@@ -541,7 +539,9 @@ void test13(id x) {
   // CHECK-NEXT: call void @objc_release(i8* [[T0]])
   // CHECK-NEXT: br label
 
-  // CHECK:  [[T0:%.*]] = load i8*, i8** [[X]]
+  // CHECK:  [[BPTR2:%.*]] = bitcast void ()** [[B]] to i8*
+  // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[BPTR2]])
+  // CHECK-NEXT:  [[T0:%.*]] = load i8*, i8** [[X]]
   // CHECK-NEXT: call void @objc_release(i8* [[T0]])
   // CHECK-NEXT: ret void
 }

Modified: cfe/trunk/test/CodeGenObjCXX/arc-references.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-references.mm?rev=300340=300339=300340=diff

[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Daniel Berlin via Phabricator via cfe-commits
dberlin added a comment.

In https://reviews.llvm.org/D31885#727167, @hfinkel wrote:

> I'm not sure this is the right way to do this; I suspect we're lumping 
> together a bunch of different bugs:
>
> 1. vector types need to have tbaa which makes them alias with their element 
> types [to be clear, as vector types are an implementation extension, this is 
> our choice; I believe most users expect this to be true, but I'm certainly 
> open to leaving this as-is (i.e. the vector types and scalar types as 
> independent/non-aliasing)].
> 2. tbaa can't be used for write <-> write queries (only read <-> write 
> queries) because the writes can change the effective type
> 3. our 'struct' path TBAA for unions is broken (and to fix this we need to 
> invert the tree structure, etc. as discussed on the list)
>
>   (1) and (3) are independent bugs. (1) if desired, should just be fixed (the 
> vector type should be a child of the scalar element type in the current 
> representation). (2) needs to be fixed too, is not strictly related to 
> unions, and needs to be fixed in the backend. Doing this does not seem hard 
> (we just need to record a Write Boolean in MemoryLocation and then check them 
> in TypeBasedAAResult (TBAA can't be used if both locations are writes). (3) 
> is what this should address. What we should do here is only generate the 
> scalar TBAA for the union accesses. As I recall, the only reason that the 
> scalar TBAA for union accesses is a problem is because of (2), but that's 
> easy to fix in the backend (and we need to do that anyway).
>
>   @dberlin , do you agree?


I pretty strongly agree that these are different bugs, and at the least, 
deserving of different patches as they have different tradeoffs/solutions.
Ii think what should probably happen here is that we fix #1 and #3 in separate 
patches, and discuss #2 a bit until we come to consensus about what should be 
done.

I'm not sure about the solution to #2, because i thought there were very 
specific points in time at which the effective type could change.
It seems like it should be possible to generate a correct tree that represents 
this rather than try to hack up the backend, since the frontend knows when this 
has happened.
(IE if the effective type has changed from double to int, it should have double 
and int parents to make sure it conflicts with both.  Though i guess maybe 
that's impossible in the current rep until we fix it).
I generally think it should be the responsibility of the frontend to generate 
metadata that is correct for all types of queries, and if we have to extend 
that, i'd extend it, rather than try to special case it in the backend, 
*especially* by changing a core structure like MemoryLocation.

In fact, i mostly believe tbaa doesn't belong in memory location, and that it 
should be looked up separately by the TBAA AA impl since that's the thing that 
should care about it.  As we've repeatedly said, memory locations and pointers 
don't really have tbaa info, instructions do.  We're really just trying to pass 
that along.
This would require changing it from including the tbaa tag to including the 
instruction the location came from, which may actually be useful for other 
reasons anyway (we'd be able to look up instruction-specific aa info, in the aa 
impls that have that info, instead of having to shove it all in memory location 
as we do now, and the impl tries to recreate apples from applesauce).  The cost 
of doing this is that if we include the instruction in operator==, we'll end up 
with more queries in things like memoryssa, uses memorylocation as a 
discriminator.IE it expects everything with the same memorylocation to have 
the same aliasing results, so it cuts down on queries by using it as a key.  
This will still work, it just won't do anything useful if the instruction is 
the discriminator.This seems solvable by saying two memorylocations are 
equal if the pointers and sizes are equal, and  instructions are the same kind 
(read/write/kill) and have equal metadata (IE not just tbaa).  Which is really 
likely what we want anyway, rather than "pointer, size, tbaa info implies alias 
equality".  Maybe i'm wrong.
We'd definitely have to benchmark.
(and yes, i realize this is more involved than we may want to do right now, i'd 
actually be willing to sign up to do it if we come to consensus and the numbers 
look good).


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In https://reviews.llvm.org/D31885#727307, @kparzysz wrote:

> This is not meant as a fine-grained solution to the TBAA problem, but a 
> temporary fix for generating wrong information.  Just yesterday I helped 
> diagnose yet another problem related to this, so this issue is causing 
> trouble out there.


I understand. But temporary solutions have a tendency to become fairly long 
lived and I'd like to make sure we're not removing correct information (i.e. 
the scalar type information) along with the incorrect information. This has 
been broken for a long time, if it takes another few days to get a better fix 
then that's worthwhile.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

This is not meant as a fine-grained solution to the TBAA problem, but a 
temporary fix for generating wrong information.  Just yesterday I helped 
diagnose yet another problem related to this, so this issue is causing trouble 
out there.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D31996: Make Gentoo GNU GCC Config override whitespace tolerant

2017-04-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Well, I've just checked gcc-config sources and it seems that it sources the 
file through bash, and gets the resulting `${CURRENT}`. While I don't think we 
ought to do complete bash support here, I guess allowing the same degree of 
whitespace bash does makes sense.


https://reviews.llvm.org/D31996



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


[PATCH] D31996: Make Gentoo GNU GCC Config override whitespace tolerant

2017-04-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In https://reviews.llvm.org/D31996#727229, @mgorny wrote:

> Is there any specific reason you need this? Since the file is autogenerated, 
> I don't think it matters very much to allow extra whiespace. But then, I do 
> not think it hurts, so feel free to do it. The code LGTM; note that I haven't 
> tested it, however.


In my case, a misbehaving copy of SVN caused the test for this to have a '\r\n' 
line ending on Windows.  I fixed my SVN, but also realized that tolerance for 
whitespace might be valuable, particularly since a human might decide to change 
this without the gcc-config tool and neglect a trailing space.  It scared me 
that this was a condition where it would APPEAR to work well (ie, configure it 
to the 'latest', but not realize it is being ignored), then be surprised later.


https://reviews.llvm.org/D31996



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


r300328 - Make Gentoo GNU GCC Config override whitespace tolerant

2017-04-14 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Apr 14 10:21:18 2017
New Revision: 300328

URL: http://llvm.org/viewvc/llvm-project?rev=300328=rev
Log:
Make Gentoo GNU GCC Config override whitespace tolerant

The config-*triple* file handling isn't tolerant of 
leading/trailing whitespace, making it not terribly 
obvious when a single extraneous tab/space/etc will 
cause the override to be ignored. This patch simply 
trims the lines to ensure that it is tolerant of 
whitespace.

Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=300328=300327=300328=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Fri Apr 14 10:21:18 2017
@@ -2173,6 +2173,7 @@ bool Generic_GCC::GCCInstallationDetecto
 SmallVector Lines;
 File.get()->getBuffer().split(Lines, "\n");
 for (StringRef Line : Lines) {
+  Line = Line.trim();
   // CURRENT=triple-version
   if (Line.consume_front("CURRENT=")) {
 const std::pair ActiveVersion =


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


[PATCH] D31766: [Clang][X86][SSE] Update MOVNTDQA non-temporal loads to generic implementation

2017-04-14 Thread Simon Pilgrim via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL300326: [X86][SSE] Update MOVNTDQA non-temporal loads to 
generic implementation (clang) (authored by RKSimon).

Changed prior to commit:
  https://reviews.llvm.org/D31766?vs=94379=95303#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31766

Files:
  cfe/trunk/include/clang/Basic/BuiltinsX86.def
  cfe/trunk/lib/Headers/avx2intrin.h
  cfe/trunk/lib/Headers/avx512fintrin.h
  cfe/trunk/lib/Headers/smmintrin.h
  cfe/trunk/test/CodeGen/avx2-builtins.c
  cfe/trunk/test/CodeGen/avx512f-builtins.c
  cfe/trunk/test/CodeGen/sse41-builtins.c

Index: cfe/trunk/test/CodeGen/avx512f-builtins.c
===
--- cfe/trunk/test/CodeGen/avx512f-builtins.c
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c
@@ -6251,7 +6251,7 @@
 
 __m512i test_mm512_stream_load_si512(void *__P) {
   // CHECK-LABEL: @test_mm512_stream_load_si512
-  // CHECK: @llvm.x86.avx512.movntdqa
+  // CHECK: load <8 x i64>, <8 x i64>* %{{.*}}, align 64, !nontemporal
   return _mm512_stream_load_si512(__P); 
 }
 
Index: cfe/trunk/test/CodeGen/avx2-builtins.c
===
--- cfe/trunk/test/CodeGen/avx2-builtins.c
+++ cfe/trunk/test/CodeGen/avx2-builtins.c
@@ -1117,7 +1117,7 @@
 
 __m256i test_mm256_stream_load_si256(__m256i const *a) {
   // CHECK-LABEL: test_mm256_stream_load_si256
-  // CHECK: call <4 x i64> @llvm.x86.avx2.movntdqa(i8* %{{.*}})
+  // CHECK: load <4 x i64>, <4 x i64>* %{{.*}}, align 32, !nontemporal
   return _mm256_stream_load_si256(a);
 }
 
Index: cfe/trunk/test/CodeGen/sse41-builtins.c
===
--- cfe/trunk/test/CodeGen/sse41-builtins.c
+++ cfe/trunk/test/CodeGen/sse41-builtins.c
@@ -354,7 +354,7 @@
 
 __m128i test_mm_stream_load_si128(__m128i const *a) {
   // CHECK-LABEL: test_mm_stream_load_si128
-  // CHECK: call <2 x i64> @llvm.x86.sse41.movntdqa(i8* %{{.*}})
+  // CHECK: load <2 x i64>, <2 x i64>* %{{.*}}, align 16, !nontemporal
   return _mm_stream_load_si128(a);
 }
 
Index: cfe/trunk/lib/Headers/smmintrin.h
===
--- cfe/trunk/lib/Headers/smmintrin.h
+++ cfe/trunk/lib/Headers/smmintrin.h
@@ -691,7 +691,7 @@
 static __inline__  __m128i __DEFAULT_FN_ATTRS
 _mm_stream_load_si128 (__m128i const *__V)
 {
-  return (__m128i) __builtin_ia32_movntdqa ((const __v2di *) __V);
+  return (__m128i) __builtin_nontemporal_load ((const __v2di *) __V);
 }
 
 /* SSE4 Packed Integer Min/Max Instructions.  */
Index: cfe/trunk/lib/Headers/avx512fintrin.h
===
--- cfe/trunk/lib/Headers/avx512fintrin.h
+++ cfe/trunk/lib/Headers/avx512fintrin.h
@@ -8931,7 +8931,7 @@
 static __inline__ __m512i __DEFAULT_FN_ATTRS
 _mm512_stream_load_si512 (void *__P)
 {
-  return __builtin_ia32_movntdqa512 ((__v8di *)__P);
+  return (__m512i) __builtin_nontemporal_load((const __v8di *)__P);
 }
 
 static __inline__ void __DEFAULT_FN_ATTRS
Index: cfe/trunk/lib/Headers/avx2intrin.h
===
--- cfe/trunk/lib/Headers/avx2intrin.h
+++ cfe/trunk/lib/Headers/avx2intrin.h
@@ -832,7 +832,7 @@
 static __inline__ __m256i __DEFAULT_FN_ATTRS
 _mm256_stream_load_si256(__m256i const *__V)
 {
-  return (__m256i)__builtin_ia32_movntdqa256((const __v4di *)__V);
+  return (__m256i)__builtin_nontemporal_load((const __v4di *)__V);
 }
 
 static __inline__ __m128 __DEFAULT_FN_ATTRS
Index: cfe/trunk/include/clang/Basic/BuiltinsX86.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def
@@ -391,7 +391,6 @@
 TARGET_BUILTIN(__builtin_ia32_roundpd, "V2dV2dIi", "", "sse4.1")
 TARGET_BUILTIN(__builtin_ia32_dpps, "V4fV4fV4fIc", "", "sse4.1")
 TARGET_BUILTIN(__builtin_ia32_dppd, "V2dV2dV2dIc", "", "sse4.1")
-TARGET_BUILTIN(__builtin_ia32_movntdqa, "V2LLiV2LLiC*", "", "sse4.1")
 TARGET_BUILTIN(__builtin_ia32_ptestz128, "iV2LLiV2LLi", "", "sse4.1")
 TARGET_BUILTIN(__builtin_ia32_ptestc128, "iV2LLiV2LLi", "", "sse4.1")
 TARGET_BUILTIN(__builtin_ia32_ptestnzc128, "iV2LLiV2LLi", "", "sse4.1")
@@ -576,7 +575,6 @@
 TARGET_BUILTIN(__builtin_ia32_psrld256, "V8iV8iV4i", "", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psrlqi256, "V4LLiV4LLii", "", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psrlq256, "V4LLiV4LLiV2LLi", "", "avx2")
-TARGET_BUILTIN(__builtin_ia32_movntdqa256, "V4LLiV4LLiC*", "", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permvarsi256, "V8iV8iV8i", "", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permvarsf256, "V8fV8fV8i", "", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permti256, "V4LLiV4LLiV4LLiIc", "", "avx2")
@@ -1747,7 +1745,6 @@
 TARGET_BUILTIN(__builtin_ia32_kunpckhi, "UsUsUs","","avx512f")
 TARGET_BUILTIN(__builtin_ia32_kxnorhi, "UsUsUs","","avx512f")
 

r300326 - [X86][SSE] Update MOVNTDQA non-temporal loads to generic implementation (clang)

2017-04-14 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Fri Apr 14 10:05:57 2017
New Revision: 300326

URL: http://llvm.org/viewvc/llvm-project?rev=300326=rev
Log:
[X86][SSE] Update MOVNTDQA non-temporal loads to generic implementation (clang)

MOVNTDQA non-temporal aligned vector loads can be correctly represented using 
generic builtin loads, allowing us to remove the existing x86 intrinsics.

LLVM companion patch: D31767.

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx2intrin.h
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/lib/Headers/smmintrin.h
cfe/trunk/test/CodeGen/avx2-builtins.c
cfe/trunk/test/CodeGen/avx512f-builtins.c
cfe/trunk/test/CodeGen/sse41-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=300326=300325=300326=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Apr 14 10:05:57 2017
@@ -391,7 +391,6 @@ TARGET_BUILTIN(__builtin_ia32_roundsd, "
 TARGET_BUILTIN(__builtin_ia32_roundpd, "V2dV2dIi", "", "sse4.1")
 TARGET_BUILTIN(__builtin_ia32_dpps, "V4fV4fV4fIc", "", "sse4.1")
 TARGET_BUILTIN(__builtin_ia32_dppd, "V2dV2dV2dIc", "", "sse4.1")
-TARGET_BUILTIN(__builtin_ia32_movntdqa, "V2LLiV2LLiC*", "", "sse4.1")
 TARGET_BUILTIN(__builtin_ia32_ptestz128, "iV2LLiV2LLi", "", "sse4.1")
 TARGET_BUILTIN(__builtin_ia32_ptestc128, "iV2LLiV2LLi", "", "sse4.1")
 TARGET_BUILTIN(__builtin_ia32_ptestnzc128, "iV2LLiV2LLi", "", "sse4.1")
@@ -576,7 +575,6 @@ TARGET_BUILTIN(__builtin_ia32_psrldi256,
 TARGET_BUILTIN(__builtin_ia32_psrld256, "V8iV8iV4i", "", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psrlqi256, "V4LLiV4LLii", "", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psrlq256, "V4LLiV4LLiV2LLi", "", "avx2")
-TARGET_BUILTIN(__builtin_ia32_movntdqa256, "V4LLiV4LLiC*", "", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permvarsi256, "V8iV8iV8i", "", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permvarsf256, "V8fV8fV8i", "", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permti256, "V4LLiV4LLiV4LLiIc", "", "avx2")
@@ -1747,7 +1745,6 @@ TARGET_BUILTIN(__builtin_ia32_kortestzhi
 TARGET_BUILTIN(__builtin_ia32_kunpckhi, "UsUsUs","","avx512f")
 TARGET_BUILTIN(__builtin_ia32_kxnorhi, "UsUsUs","","avx512f")
 TARGET_BUILTIN(__builtin_ia32_kxorhi, "UsUsUs","","avx512f")
-TARGET_BUILTIN(__builtin_ia32_movntdqa512, "V8LLiV8LLi*","","avx512f")
 TARGET_BUILTIN(__builtin_ia32_palignr512_mask, 
"V64cV64cV64cIiV64cULLi","","avx512bw")
 TARGET_BUILTIN(__builtin_ia32_dbpsadbw128_mask, 
"V8sV16cV16cIiV8sUc","","avx512bw,avx512vl")
 TARGET_BUILTIN(__builtin_ia32_dbpsadbw256_mask, 
"V16sV32cV32cIiV16sUs","","avx512bw,avx512vl")

Modified: cfe/trunk/lib/Headers/avx2intrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx2intrin.h?rev=300326=300325=300326=diff
==
--- cfe/trunk/lib/Headers/avx2intrin.h (original)
+++ cfe/trunk/lib/Headers/avx2intrin.h Fri Apr 14 10:05:57 2017
@@ -832,7 +832,7 @@ _mm256_xor_si256(__m256i __a, __m256i __
 static __inline__ __m256i __DEFAULT_FN_ATTRS
 _mm256_stream_load_si256(__m256i const *__V)
 {
-  return (__m256i)__builtin_ia32_movntdqa256((const __v4di *)__V);
+  return (__m256i)__builtin_nontemporal_load((const __v4di *)__V);
 }
 
 static __inline__ __m128 __DEFAULT_FN_ATTRS

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=300326=300325=300326=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Fri Apr 14 10:05:57 2017
@@ -8931,7 +8931,7 @@ _mm512_stream_si512 (__m512i * __P, __m5
 static __inline__ __m512i __DEFAULT_FN_ATTRS
 _mm512_stream_load_si512 (void *__P)
 {
-  return __builtin_ia32_movntdqa512 ((__v8di *)__P);
+  return (__m512i) __builtin_nontemporal_load((const __v8di *)__P);
 }
 
 static __inline__ void __DEFAULT_FN_ATTRS

Modified: cfe/trunk/lib/Headers/smmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/smmintrin.h?rev=300326=300325=300326=diff
==
--- cfe/trunk/lib/Headers/smmintrin.h (original)
+++ cfe/trunk/lib/Headers/smmintrin.h Fri Apr 14 10:05:57 2017
@@ -691,7 +691,7 @@ _mm_mul_epi32 (__m128i __V1, __m128i __V
 static __inline__  __m128i __DEFAULT_FN_ATTRS
 _mm_stream_load_si128 (__m128i const *__V)
 {
-  return (__m128i) __builtin_ia32_movntdqa ((const __v2di *) __V);
+  return (__m128i) __builtin_nontemporal_load ((const __v2di *) __V);
 }
 
 /* SSE4 Packed Integer Min/Max Instructions.  */

Modified: cfe/trunk/test/CodeGen/avx2-builtins.c
URL: 

[PATCH] D15006: Driver: Better detection of mingw-gcc

2017-04-14 Thread Yaron Keren via Phabricator via cfe-commits
yaron.keren added reviewers: mati865, rnk.
yaron.keren added a comment.

Adding Mateusz and Reid.


Repository:
  rL LLVM

https://reviews.llvm.org/D15006



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


[PATCH] D32084: AMDGPU/GFX9: Set +fast-fmaf for >=gfx900 unless -cl-denorms-are-zero is set

2017-04-14 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl updated this revision to Diff 95299.
kzhuravl added a comment.

Add \n to test file.


https://reviews.llvm.org/D32084

Files:
  lib/Basic/Targets.cpp
  test/CodeGenOpenCL/gfx9-fast-fmaf.cl


Index: test/CodeGenOpenCL/gfx9-fast-fmaf.cl
===
--- test/CodeGenOpenCL/gfx9-fast-fmaf.cl
+++ test/CodeGenOpenCL/gfx9-fast-fmaf.cl
@@ -0,0 +1,13 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S 
-emit-llvm -o - %s | FileCheck --check-prefix=DEFAULT %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S 
-emit-llvm -o - -target-feature +fast-fmaf %s | FileCheck 
--check-prefix=FEATURE_FP32_DENORMALS_ON %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S 
-emit-llvm -o - -target-feature -fast-fmaf %s | FileCheck 
--check-prefix=FEATURE_FP32_DENORMALS_OFF %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S 
-emit-llvm -o - -cl-denorms-are-zero %s | FileCheck 
--check-prefix=OPT_DENORMS_ARE_ZERO %s
+
+// DEFAULT: +fast-fmaf
+// FEATURE_FP32_DENORMALS_ON: +fast-fmaf
+// FEATURE_FP32_DENORMALS_OFF: -fast-fmaf
+// OPT_DENORMS_ARE_ZERO: -fast-fmaf
+
+kernel void gfx9_fast_fmaf() {}
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2201,10 +2201,14 @@
   if (I == "+fp64-fp16-denormals" || I == "-fp64-fp16-denormals")
 hasFP64Denormals = true;
 }
-if (!hasFP32Denormals)
+if (!hasFP32Denormals) {
   TargetOpts.Features.push_back(
   (Twine(hasFullSpeedFMAF32(TargetOpts.CPU) &&
   !CGOpts.FlushDenorm ? '+' : '-') + Twine("fp32-denormals")).str());
+  TargetOpts.Features.push_back(
+  (Twine(hasFullSpeedFMAF32(TargetOpts.CPU) &&
+  !CGOpts.FlushDenorm ? '+' : '-') + Twine("fast-fmaf")).str());
+}
 // Always do not flush fp64 or fp16 denorms.
 if (!hasFP64Denormals && hasFP64)
   TargetOpts.Features.push_back("+fp64-fp16-denormals");


Index: test/CodeGenOpenCL/gfx9-fast-fmaf.cl
===
--- test/CodeGenOpenCL/gfx9-fast-fmaf.cl
+++ test/CodeGenOpenCL/gfx9-fast-fmaf.cl
@@ -0,0 +1,13 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S -emit-llvm -o - %s | FileCheck --check-prefix=DEFAULT %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S -emit-llvm -o - -target-feature +fast-fmaf %s | FileCheck --check-prefix=FEATURE_FP32_DENORMALS_ON %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S -emit-llvm -o - -target-feature -fast-fmaf %s | FileCheck --check-prefix=FEATURE_FP32_DENORMALS_OFF %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S -emit-llvm -o - -cl-denorms-are-zero %s | FileCheck --check-prefix=OPT_DENORMS_ARE_ZERO %s
+
+// DEFAULT: +fast-fmaf
+// FEATURE_FP32_DENORMALS_ON: +fast-fmaf
+// FEATURE_FP32_DENORMALS_OFF: -fast-fmaf
+// OPT_DENORMS_ARE_ZERO: -fast-fmaf
+
+kernel void gfx9_fast_fmaf() {}
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2201,10 +2201,14 @@
   if (I == "+fp64-fp16-denormals" || I == "-fp64-fp16-denormals")
 hasFP64Denormals = true;
 }
-if (!hasFP32Denormals)
+if (!hasFP32Denormals) {
   TargetOpts.Features.push_back(
   (Twine(hasFullSpeedFMAF32(TargetOpts.CPU) &&
   !CGOpts.FlushDenorm ? '+' : '-') + Twine("fp32-denormals")).str());
+  TargetOpts.Features.push_back(
+  (Twine(hasFullSpeedFMAF32(TargetOpts.CPU) &&
+  !CGOpts.FlushDenorm ? '+' : '-') + Twine("fast-fmaf")).str());
+}
 // Always do not flush fp64 or fp16 denorms.
 if (!hasFP64Denormals && hasFP64)
   TargetOpts.Features.push_back("+fp64-fp16-denormals");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32084: AMDGPU/GFX9: Set +fast-fmaf for >=gfx900 unless -cl-denorms-are-zero is set

2017-04-14 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl created this revision.
Herald added subscribers: t-tye, tpr, dstuttard, yaxunl, wdng.

https://reviews.llvm.org/D32084

Files:
  lib/Basic/Targets.cpp
  test/CodeGenOpenCL/gfx9-fast-fmaf.cl


Index: test/CodeGenOpenCL/gfx9-fast-fmaf.cl
===
--- test/CodeGenOpenCL/gfx9-fast-fmaf.cl
+++ test/CodeGenOpenCL/gfx9-fast-fmaf.cl
@@ -0,0 +1,13 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S 
-emit-llvm -o - %s | FileCheck --check-prefix=DEFAULT %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S 
-emit-llvm -o - -target-feature +fast-fmaf %s | FileCheck 
--check-prefix=FEATURE_FP32_DENORMALS_ON %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S 
-emit-llvm -o - -target-feature -fast-fmaf %s | FileCheck 
--check-prefix=FEATURE_FP32_DENORMALS_OFF %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S 
-emit-llvm -o - -cl-denorms-are-zero %s | FileCheck 
--check-prefix=OPT_DENORMS_ARE_ZERO %s
+
+// DEFAULT: +fast-fmaf
+// FEATURE_FP32_DENORMALS_ON: +fast-fmaf
+// FEATURE_FP32_DENORMALS_OFF: -fast-fmaf
+// OPT_DENORMS_ARE_ZERO: -fast-fmaf
+
+kernel void gfx9_fast_fmaf() {}
\ No newline at end of file
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2201,10 +2201,14 @@
   if (I == "+fp64-fp16-denormals" || I == "-fp64-fp16-denormals")
 hasFP64Denormals = true;
 }
-if (!hasFP32Denormals)
+if (!hasFP32Denormals) {
   TargetOpts.Features.push_back(
   (Twine(hasFullSpeedFMAF32(TargetOpts.CPU) &&
   !CGOpts.FlushDenorm ? '+' : '-') + Twine("fp32-denormals")).str());
+  TargetOpts.Features.push_back(
+  (Twine(hasFullSpeedFMAF32(TargetOpts.CPU) &&
+  !CGOpts.FlushDenorm ? '+' : '-') + Twine("fast-fmaf")).str());
+}
 // Always do not flush fp64 or fp16 denorms.
 if (!hasFP64Denormals && hasFP64)
   TargetOpts.Features.push_back("+fp64-fp16-denormals");


Index: test/CodeGenOpenCL/gfx9-fast-fmaf.cl
===
--- test/CodeGenOpenCL/gfx9-fast-fmaf.cl
+++ test/CodeGenOpenCL/gfx9-fast-fmaf.cl
@@ -0,0 +1,13 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S -emit-llvm -o - %s | FileCheck --check-prefix=DEFAULT %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S -emit-llvm -o - -target-feature +fast-fmaf %s | FileCheck --check-prefix=FEATURE_FP32_DENORMALS_ON %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S -emit-llvm -o - -target-feature -fast-fmaf %s | FileCheck --check-prefix=FEATURE_FP32_DENORMALS_OFF %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S -emit-llvm -o - -cl-denorms-are-zero %s | FileCheck --check-prefix=OPT_DENORMS_ARE_ZERO %s
+
+// DEFAULT: +fast-fmaf
+// FEATURE_FP32_DENORMALS_ON: +fast-fmaf
+// FEATURE_FP32_DENORMALS_OFF: -fast-fmaf
+// OPT_DENORMS_ARE_ZERO: -fast-fmaf
+
+kernel void gfx9_fast_fmaf() {}
\ No newline at end of file
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2201,10 +2201,14 @@
   if (I == "+fp64-fp16-denormals" || I == "-fp64-fp16-denormals")
 hasFP64Denormals = true;
 }
-if (!hasFP32Denormals)
+if (!hasFP32Denormals) {
   TargetOpts.Features.push_back(
   (Twine(hasFullSpeedFMAF32(TargetOpts.CPU) &&
   !CGOpts.FlushDenorm ? '+' : '-') + Twine("fp32-denormals")).str());
+  TargetOpts.Features.push_back(
+  (Twine(hasFullSpeedFMAF32(TargetOpts.CPU) &&
+  !CGOpts.FlushDenorm ? '+' : '-') + Twine("fast-fmaf")).str());
+}
 // Always do not flush fp64 or fp16 denorms.
 if (!hasFP64Denormals && hasFP64)
   TargetOpts.Features.push_back("+fp64-fp16-denormals");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31869: Register isStaticStorageClass matcher

2017-04-14 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added a comment.

Thanks! I don't have commit access, so if anyone wants to commit this, that 
would be great.


https://reviews.llvm.org/D31869



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


[clang-tools-extra] r300324 - Silence -Wlogical-op-parentheses warning NFC

2017-04-14 Thread Nirav Dave via cfe-commits
Author: niravd
Date: Fri Apr 14 09:36:45 2017
New Revision: 300324

URL: http://llvm.org/viewvc/llvm-project?rev=300324=rev
Log:
Silence -Wlogical-op-parentheses warning NFC

Modified:
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp?rev=300324=300323=300324=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp 
Fri Apr 14 09:36:45 2017
@@ -123,7 +123,7 @@ void ForwardingReferenceOverloadCheck::c
 (OtherCtor->isCopyConstructor() ? EnabledCopy : EnabledMove) = true;
 }
   }
-  bool Copy = !EnabledMove && !DisabledMove && !DisabledCopy || EnabledCopy;
+  bool Copy = (!EnabledMove && !DisabledMove && !DisabledCopy) || EnabledCopy;
   bool Move = !DisabledMove || EnabledMove;
   if (!Copy && !Move)
 return;


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


[PATCH] D32081: Add support for editor placeholders to Clang's lexer

2017-04-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 95297.
arphaman added a comment.

I've decided to treat each placeholder as an identifier token (like Swift) 
instead of just lexing the contents. This will prevent spurious errors for 
declaration name placeholders that have spaces or hyphens inside.


Repository:
  rL LLVM

https://reviews.llvm.org/D32081

Files:
  include/clang/Basic/Diagnostic.h
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Basic/DiagnosticOptions.def
  include/clang/Driver/Options.td
  include/clang/Lex/Lexer.h
  lib/Basic/Diagnostic.cpp
  lib/Basic/DiagnosticIDs.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/Lexer.cpp
  test/Driver/clang_f_opts.c
  test/Lexer/editor-placeholder.cpp
  test/Parser/placeholder-recovery.m

Index: test/Parser/placeholder-recovery.m
===
--- test/Parser/placeholder-recovery.m
+++ test/Parser/placeholder-recovery.m
@@ -1,11 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
+@protocol NSObject
+@end
+
+@protocol <#protocol name#>  // expected-error {{editor placeholder in source file}}
+// expected-note@-1 {{protocol started here}}
+
 // FIXME: We could do much better with this, if we recognized
 // placeholders somehow. However, we're content with not generating
 // bogus 'archaic' warnings with bad location info.
-@protocol <#protocol name#>  // expected-error {{expected identifier or '('}} \
-// expected-error 2{{expected identifier}} \
-// expected-warning{{protocol has no object type specified; defaults to qualified 'id'}}
-<#methods#>
+<#methods#> // expected-error {{editor placeholder in source file}}
 
-@end
+@end // expected-error {{prefix attribute must be followed by an interface or protocol}} expected-error {{missing '@end'}}
Index: test/Lexer/editor-placeholder.cpp
===
--- /dev/null
+++ test/Lexer/editor-placeholder.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only  -fsuppress-editor-placeholder-error -DSUPPRESS -verify %s
+
+struct Struct {
+public:
+void method(Struct );
+};
+
+struct <#struct name#> {
+  int <#field-name#>;
+#ifndef SUPPRESS
+  // expected-error@-3 {{editor placeholder in source file}}
+  // expected-error@-3 {{editor placeholder in source file}}
+#endif
+};
+
+void avoidPlaceholderErrors(Struct ) {
+while (<#condition#>) {
+<#statements#>
+}
+obj.method(<#Struct #>);
+#ifndef SUPPRESS
+  // expected-error@-5 {{editor placeholder in source file}}
+  // expected-error@-5 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+#endif
+switch (<#expression#>) {
+case <#constant#>:
+<#statements#>
+#ifndef SUPPRESS
+  // expected-error@-4 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+#endif
+break;
+
+default:
+break;
+}
+}
+
+void Struct::method(<#Struct #>, noSupressionHere) { // expected-error {{unknown type name 'noSupressionHere'}}
+#ifndef SUPPRESS
+  // expected-error@-2 {{editor placeholder in source file}}
+#endif
+}
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -494,3 +494,8 @@
 // RUN: %clang -### -S -fdebug-info-for-profiling -fno-debug-info-for-profiling %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-DEBUG %s
 // CHECK-PROFILE-DEBUG: -fdebug-info-for-profiling
 // CHECK-NO-PROFILE-DEBUG-NOT: -fdebug-info-for-profiling
+
+// RUN: %clang -### -S -fsuppress-editor-placeholder-error %s 2>&1 | FileCheck -check-prefix=CHECK-SUPPRESS-PLACEHOLDER-ERROR %s
+// RUN: %clang -### -S -fno-suppress-editor-placeholder-error %s 2>&1 | FileCheck -check-prefix=CHECK-NO-SUPPRESS-PLACEHOLDER-ERROR %s
+// CHECK-SUPPRESS-PLACEHOLDER-ERROR: -fsuppress-editor-placeholder-error
+// CHECK-NO-SUPPRESS-PLACEHOLDER-ERROR-NOT: -fsuppress-editor-placeholder-error
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -2722,6 +2722,43 @@
   return false;
 }
 
+static const char *findPlaceholderEnd(const char *CurPtr,
+  const char *BufferEnd) {
+  if (CurPtr == BufferEnd)
+return nullptr;
+  BufferEnd -= 1; // Scan until the second last character.
+  for (; CurPtr != BufferEnd; ++CurPtr) {
+if (CurPtr[0] == '#' && CurPtr[1] == '>')
+  return CurPtr + 2;
+  }
+  return nullptr;
+}
+
+bool Lexer::lexEditorPlaceholder(Token , const char *CurPtr) {
+  assert(CurPtr[-1] == '<' && CurPtr[0] == '#' && "Not a placeholder!");
+  if (!PP || LexingRawMode)
+return false;
+  const char *End = findPlaceholderEnd(CurPtr + 1, BufferEnd);
+  if 

[PATCH] D31996: Make Gentoo GNU GCC Config override whitespace tolerant

2017-04-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny accepted this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

Is there any specific reason you need this? Since the file is autogenerated, I 
don't think it matters very much to allow extra whiespace. But then, I do not 
think it hurts, so feel free to do it. The code LGTM; note that I haven't 
tested it, however.


https://reviews.llvm.org/D31996



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


[PATCH] D15006: Driver: Better detection of mingw-gcc

2017-04-14 Thread Martell Malone via Phabricator via cfe-commits
martell added a comment.

To clarify the most import part about actually being able to test this is the 
being able to modify the PATH variable for windows and unix hosts in the test 
case.
The program prefix is less of a problem because I can double down with the same 
empty file one with .exe and one without.
Just thought that I would note it incase someone has ran into this already.


Repository:
  rL LLVM

https://reviews.llvm.org/D15006



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


[PATCH] D32081: Add support for editor placeholders to Clang's lexer

2017-04-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

This patch is based on the RFC that I've sent out earlier 
(http://lists.llvm.org/pipermail/cfe-dev/2017-April/053394.html).
It teaches Clang's Lexer to recognize the editor placeholders that are produced 
by some editors like Xcode when expanding code-completion results that include 
placeholders. When the Lexer sees a placeholder, it emits an error 'editor 
placeholder in source file', suppresses all diagnostics in the placeholder 
range and lexes the tokens in the placeholder.

This patch also includes a new compiler option called 
'-fsuppress-editor-placeholder-error' that surpasses the 'editor placeholder in 
source file' error. This option is useful for an IDE like Xcode as we don't 
want to display those errors as live diagnostics in the editor.

There are still certain things that can be improved. For example, in the future 
we may want to add support for different kinds of placeholders (e.g. typed, it 
would produce special typed expressions) that would actually produce a special 
token instead of lexing the contents of the placeholder in order to improve the 
parser's recovery. But they will require changes to the code-completion code as 
well, so I left them for later to keep this patch small.


Repository:
  rL LLVM

https://reviews.llvm.org/D32081

Files:
  include/clang/Basic/Diagnostic.h
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Basic/DiagnosticOptions.def
  include/clang/Driver/Options.td
  include/clang/Lex/Lexer.h
  lib/Basic/Diagnostic.cpp
  lib/Basic/DiagnosticIDs.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/Lexer.cpp
  test/Driver/clang_f_opts.c
  test/Lexer/editor-placeholder.cpp
  test/Parser/placeholder-recovery.m

Index: test/Parser/placeholder-recovery.m
===
--- test/Parser/placeholder-recovery.m
+++ test/Parser/placeholder-recovery.m
@@ -3,9 +3,9 @@
 // FIXME: We could do much better with this, if we recognized
 // placeholders somehow. However, we're content with not generating
 // bogus 'archaic' warnings with bad location info.
-@protocol <#protocol name#>  // expected-error {{expected identifier or '('}} \
-// expected-error 2{{expected identifier}} \
-// expected-warning{{protocol has no object type specified; defaults to qualified 'id'}}
-<#methods#>
+@protocol <#protocol name#>  // expected-error {{editor placeholder in source file}}
+// expected-error@-1 {{expected identifier or '('}}
+
+<#methods#> // expected-error {{editor placeholder in source file}}
 
 @end
Index: test/Lexer/editor-placeholder.cpp
===
--- /dev/null
+++ test/Lexer/editor-placeholder.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only  -fsuppress-editor-placeholder-error -DSUPPRESS -verify %s
+
+struct Struct {
+public:
+void method(Struct );
+};
+
+void avoidPlaceholderErrors(Struct ) {
+while (<#condition#>) {
+<#statements#>
+}
+obj.method(<#Struct #>);
+#ifndef SUPPRESS
+  // expected-error@-5 {{editor placeholder in source file}}
+  // expected-error@-5 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+#endif
+switch (<#expression#>) {
+case <#constant#>:
+<#statements#>
+#ifndef SUPPRESS
+  // expected-error@-4 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+  // expected-error@-4 {{editor placeholder in source file}}
+#endif
+break;
+
+default:
+break;
+}
+}
+
+void Struct::method(<#Struct #>, noSupressionHere) { // expected-error {{unknown type name 'noSupressionHere'}}
+#ifndef SUPPRESS
+  // expected-error@-2 {{editor placeholder in source file}}
+#endif
+}
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -494,3 +494,8 @@
 // RUN: %clang -### -S -fdebug-info-for-profiling -fno-debug-info-for-profiling %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-DEBUG %s
 // CHECK-PROFILE-DEBUG: -fdebug-info-for-profiling
 // CHECK-NO-PROFILE-DEBUG-NOT: -fdebug-info-for-profiling
+
+// RUN: %clang -### -S -fsuppress-editor-placeholder-error %s 2>&1 | FileCheck -check-prefix=CHECK-SUPPRESS-PLACEHOLDER-ERROR %s
+// RUN: %clang -### -S -fno-suppress-editor-placeholder-error %s 2>&1 | FileCheck -check-prefix=CHECK-NO-SUPPRESS-PLACEHOLDER-ERROR %s
+// CHECK-SUPPRESS-PLACEHOLDER-ERROR: -fsuppress-editor-placeholder-error
+// CHECK-NO-SUPPRESS-PLACEHOLDER-ERROR-NOT: -fsuppress-editor-placeholder-error
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -108,6 +108,8 @@
 
   // Default to not keeping comments.
   ExtendedTokenMode = 0;
+
+  

[PATCH] D15006: Driver: Better detection of mingw-gcc

2017-04-14 Thread Martell Malone via Phabricator via cfe-commits
martell updated this revision to Diff 95292.
martell edited the summary of this revision.
martell added a reviewer: yaron.keren.
martell added a subscriber: yaron.keren.
martell added a comment.

After the revert I left this patch go to pick up some other patch work.
Seen as we are not anywhere near the next release this seem like a good time to 
pick it up again.
Also got a reminder when yaron resigned

Updated to master.
@ismail can you confirm this update works for your custom opensuse setup on 
master.
@yaron.keren I can't do a non flaky test case for this it seems because on 
windows we need .exe extension and not on unix.
Also we need the test case to be able to set the PATH variable to be able to 
test this fully.

I would like to consider this as working because it passes all the existing 
Driver testcases in `test/Driver/mingw.cpp`


Repository:
  rL LLVM

https://reviews.llvm.org/D15006

Files:
  lib/Driver/ToolChains/MinGW.cpp
  lib/Driver/ToolChains/MinGW.h


Index: lib/Driver/ToolChains/MinGW.h
===
--- lib/Driver/ToolChains/MinGW.h
+++ lib/Driver/ToolChains/MinGW.h
@@ -93,6 +93,7 @@
   mutable std::unique_ptr Preprocessor;
   mutable std::unique_ptr Compiler;
   void findGccLibDir();
+  llvm::ErrorOr findGcc();
 };
 
 } // end namespace toolchains
Index: lib/Driver/ToolChains/MinGW.cpp
===
--- lib/Driver/ToolChains/MinGW.cpp
+++ lib/Driver/ToolChains/MinGW.cpp
@@ -285,28 +285,30 @@
   }
 }
 
+llvm::ErrorOr toolchains::MinGW::findGcc() {
+  llvm::SmallVector, 2> Gccs;
+  Gccs.emplace_back(getTriple().getArchName());
+  Gccs[0] += "-w64-mingw32-gcc";
+  Gccs.emplace_back("mingw32-gcc");
+  // Please do not add "gcc" here
+  for (StringRef CandidateGcc : Gccs)
+if (llvm::ErrorOr GPPName = 
llvm::sys::findProgramByName(CandidateGcc))
+  return GPPName;
+  return make_error_code(std::errc::no_such_file_or_directory);
+}
+
 toolchains::MinGW::MinGW(const Driver , const llvm::Triple ,
  const ArgList )
 : ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args) {
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
-// In Windows there aren't any standard install locations, we search
-// for gcc on the PATH. In Linux the base is always /usr.
-#ifdef LLVM_ON_WIN32
   if (getDriver().SysRoot.size())
 Base = getDriver().SysRoot;
-  else if (llvm::ErrorOr GPPName =
-   llvm::sys::findProgramByName("gcc"))
+  else if (llvm::ErrorOr GPPName = findGcc())
 Base = llvm::sys::path::parent_path(
 llvm::sys::path::parent_path(GPPName.get()));
   else
 Base = llvm::sys::path::parent_path(getDriver().getInstalledDir());
-#else
-  if (getDriver().SysRoot.size())
-Base = getDriver().SysRoot;
-  else
-Base = "/usr";
-#endif
 
   Base += llvm::sys::path::get_separator();
   findGccLibDir();


Index: lib/Driver/ToolChains/MinGW.h
===
--- lib/Driver/ToolChains/MinGW.h
+++ lib/Driver/ToolChains/MinGW.h
@@ -93,6 +93,7 @@
   mutable std::unique_ptr Preprocessor;
   mutable std::unique_ptr Compiler;
   void findGccLibDir();
+  llvm::ErrorOr findGcc();
 };
 
 } // end namespace toolchains
Index: lib/Driver/ToolChains/MinGW.cpp
===
--- lib/Driver/ToolChains/MinGW.cpp
+++ lib/Driver/ToolChains/MinGW.cpp
@@ -285,28 +285,30 @@
   }
 }
 
+llvm::ErrorOr toolchains::MinGW::findGcc() {
+  llvm::SmallVector, 2> Gccs;
+  Gccs.emplace_back(getTriple().getArchName());
+  Gccs[0] += "-w64-mingw32-gcc";
+  Gccs.emplace_back("mingw32-gcc");
+  // Please do not add "gcc" here
+  for (StringRef CandidateGcc : Gccs)
+if (llvm::ErrorOr GPPName = llvm::sys::findProgramByName(CandidateGcc))
+  return GPPName;
+  return make_error_code(std::errc::no_such_file_or_directory);
+}
+
 toolchains::MinGW::MinGW(const Driver , const llvm::Triple ,
  const ArgList )
 : ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args) {
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
-// In Windows there aren't any standard install locations, we search
-// for gcc on the PATH. In Linux the base is always /usr.
-#ifdef LLVM_ON_WIN32
   if (getDriver().SysRoot.size())
 Base = getDriver().SysRoot;
-  else if (llvm::ErrorOr GPPName =
-   llvm::sys::findProgramByName("gcc"))
+  else if (llvm::ErrorOr GPPName = findGcc())
 Base = llvm::sys::path::parent_path(
 llvm::sys::path::parent_path(GPPName.get()));
   else
 Base = llvm::sys::path::parent_path(getDriver().getInstalledDir());
-#else
-  if (getDriver().SysRoot.size())
-Base = getDriver().SysRoot;
-  else
-Base = "/usr";
-#endif
 
   Base += llvm::sys::path::get_separator();
   findGccLibDir();

[PATCH] D32035: [OpenMP] Error when trying to offload to an unsupported architecture

2017-04-14 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/Frontend/CompilerInvocation.cpp:2242-2253
+  if (!(TT.getArch() == llvm::Triple::ppc ||
+TT.getArch() == llvm::Triple::ppc64 ||
+TT.getArch() == llvm::Triple::ppc64le ||
+TT.getArch() == llvm::Triple::nvptx ||
+TT.getArch() == llvm::Triple::nvptx64 ||
+TT.getArch() == llvm::Triple::x86 ||
+TT.getArch() == llvm::Triple::x86_64))

I think you can join these 2 if statements into one.


Repository:
  rL LLVM

https://reviews.llvm.org/D32035



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


[PATCH] D31167: Use FPContractModeKind universally

2017-04-14 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added inline comments.



Comment at: cfe/trunk/include/clang/Basic/LangOptions.def:220
+/// \brief FP_CONTRACT mode (on/off/fast).
+ENUM_LANGOPT(DefaultFPContractMode, FPContractModeKind, 2, FPC_Off, "FP 
contraction type")
 LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment")

anemet wrote:
> hfinkel wrote:
> > anemet wrote:
> > > hfinkel wrote:
> > > > yaxunl wrote:
> > > > > hfinkel wrote:
> > > > > > yaxunl wrote:
> > > > > > > anemet wrote:
> > > > > > > > yaxunl wrote:
> > > > > > > > > anemet wrote:
> > > > > > > > > > yaxunl wrote:
> > > > > > > > > > > This change seemed to cause some performance degradations 
> > > > > > > > > > > in some OpenCL applications.
> > > > > > > > > > > 
> > > > > > > > > > > This option used to be on by default. Now it is off by 
> > > > > > > > > > > default.
> > > > > > > > > > > 
> > > > > > > > > > > There are applications do separated compile/link/codegen 
> > > > > > > > > > > stages. In the codegen stage, clang is invoked with .bc 
> > > > > > > > > > > as input, therefore this option is off by default, 
> > > > > > > > > > > whereas it was on by default before this change.
> > > > > > > > > > > 
> > > > > > > > > > > Is there any reason not to keep the original behavior?
> > > > > > > > > > > 
> > > > > > > > > > > Thanks.
> > > > > > > > > > > This change seemed to cause some performance degradations 
> > > > > > > > > > > in some OpenCL applications.
> > > > > > > > > > > 
> > > > > > > > > > > This option used to be on by default. Now it is off by 
> > > > > > > > > > > default.
> > > > > > > > > > 
> > > > > > > > > > It's always been off.  It was set to fast for CUDA which 
> > > > > > > > > > should still be the case.  See the changes further down on 
> > > > > > > > > > the patch.
> > > > > > > > > > 
> > > > > > > > > > > 
> > > > > > > > > > > There are applications do separated compile/link/codegen 
> > > > > > > > > > > stages. In the codegen stage, clang is invoked with .bc 
> > > > > > > > > > > as input, therefore this option is off by default, 
> > > > > > > > > > > whereas it was on by default before this change.
> > > > > > > > > > > 
> > > > > > > > > > > Is there any reason not to keep the original behavior?
> > > > > > > > > > 
> > > > > > > > > > Sorry but I am not sure what changed, can you elaborate on 
> > > > > > > > > > what you're doing and how things used to work for you?
> > > > > > > > > Before your change, -ffp-contract was a codegen option 
> > > > > > > > > defined as
> > > > > > > > > 
> > > > > > > > > 
> > > > > > > > > ```
> > > > > > > > > ENUM_CODEGENOPT(FPContractMode, FPContractModeKind, 2, FPC_On)
> > > > > > > > > ```
> > > > > > > > > 
> > > > > > > > > therefore the default value as on. After your change, it 
> > > > > > > > > becomes off by default.
> > > > > > > > No. -ffp-contract=on was a FE option and -ffp-contract=fast was 
> > > > > > > > a backend option.  I still don't understand your use-case.  Can 
> > > > > > > > you include a small testcase how this used to work before?
> > > > > > > -ffp-contract=on used to be a codegen option before this change. 
> > > > > > > In CodeGen/BackendUtil.cpp, before this change:
> > > > > > > 
> > > > > > > ```
> > > > > > > switch (CodeGenOpts.getFPContractMode()) {
> > > > > > >   switch (LangOpts.getDefaultFPContractMode()) {
> > > > > > >   case LangOptions::FPC_Off:
> > > > > > > Options.AllowFPOpFusion = llvm::FPOpFusion::Strict;
> > > > > > > break;
> > > > > > >   case LangOptions::FPC_On:
> > > > > > > Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
> > > > > > > break;
> > > > > > >   case LangOptions::FPC_Fast:
> > > > > > > Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
> > > > > > > break;
> > > > > > >   }
> > > > > > > ```
> > > > > > > By default, -fp-contract=on, which results in 
> > > > > > > llvm::FPOpFusion::Standard in the backend. This options allows 
> > > > > > > backend to translate llvm.fmuladd to FMA machine instructions.
> > > > > > > 
> > > > > > > After this change, it becomes:
> > > > > > > 
> > > > > > > ```
> > > > > > > switch (LangOpts.getDefaultFPContractMode()) {
> > > > > > >   case LangOptions::FPC_Off:
> > > > > > > Options.AllowFPOpFusion = llvm::FPOpFusion::Strict;
> > > > > > > break;
> > > > > > >   case LangOptions::FPC_On:
> > > > > > > Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
> > > > > > > break;
> > > > > > >   case LangOptions::FPC_Fast:
> > > > > > > Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
> > > > > > > break;
> > > > > > >   }
> > > > > > > ```
> > > > > > > now by default -ffp-contract=off, which results in  
> > > > > > > llvm::FPOpFusion::Strict in the backend. This option disables 
> > > > > > > backend translating llvm.fmuladd to FMA machine instructions in 
> > > > > > > certain situations.
> > > > > > > 
> > > > > > > A simple lit test is as follows:
> > > > > > > 
> > > > > > > 
> > 

[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

I'm not sure this is the right way to do this; I suspect we're lumping together 
a bunch of different bugs:

1. vector types need to have tbaa which makes them alias with their element 
types [to be clear, as vector types are an implementation extension, this is 
our choice; I believe most users expect this to be true, but I'm certainly open 
to leaving this as-is (i.e. the vector types and scalar types as 
independent/non-aliasing)].
2. tbaa can't be used for write <-> write queries (only read <-> write queries) 
because the writes can change the effective type
3. our 'struct' path TBAA for unions is broken (and to fix this we need to 
invert the tree structure, etc. as discussed on the list)

(1) and (3) are independent bugs. (1) if desired, should just be fixed (the 
vector type should be a child of the scalar element type in the current 
representation). (2) needs to be fixed too, is not strictly related to unions, 
and needs to be fixed in the backend. Doing this does not seem hard (we just 
need to record a Write Boolean in MemoryLocation and then check them in 
TypeBasedAAResult (TBAA can't be used if both locations are writes). (3) is 
what this should address. What we should do here is only generate the scalar 
TBAA for the union accesses. As I recall, the only reason that the scalar TBAA 
for union accesses is a problem is because of (2), but that's easy to fix in 
the backend (and we need to do that anyway).

@dberlin , do you agree?


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[clang-tools-extra] r300320 - [clang-tidy] Fixes to misc-forwarding-reference-overload check.

2017-04-14 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Apr 14 07:31:36 2017
New Revision: 300320

URL: http://llvm.org/viewvc/llvm-project?rev=300320=rev
Log:
[clang-tidy] Fixes to misc-forwarding-reference-overload check.

* Style fixes to tests
* Make it work consistently on all platforms

Patch by András Leitereg!

Modified:
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp?rev=300320=300319=300320=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp 
Fri Apr 14 07:31:36 2017
@@ -56,7 +56,7 @@ AST_MATCHER_P(TemplateTypeParmDecl, hasD
   return Node.hasDefaultArgument() &&
  TypeMatcher.matches(Node.getDefaultArgument(), Finder, Builder);
 }
-}
+} // namespace
 
 void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
   // Forwarding references require C++11 or later.
@@ -123,7 +123,8 @@ void ForwardingReferenceOverloadCheck::c
 (OtherCtor->isCopyConstructor() ? EnabledCopy : EnabledMove) = true;
 }
   }
-  bool Copy = !DisabledCopy || EnabledCopy, Move = !DisabledMove || 
EnabledMove;
+  bool Copy = !EnabledMove && !DisabledMove && !DisabledCopy || EnabledCopy;
+  bool Move = !DisabledMove || EnabledMove;
   if (!Copy && !Move)
 return;
   diag(Ctor->getLocation(),

Modified: 
clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp?rev=300320=300319=300320=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp 
Fri Apr 14 07:31:36 2017
@@ -1,44 +1,37 @@
 // RUN: %check_clang_tidy %s misc-forwarding-reference-overload %t -- -- 
-std=c++14
 
 namespace std {
-template 
-struct enable_if { typedef T type; };
+template  struct enable_if { typedef T type; };
 
-template 
-struct enable_if { typedef T type; };
+template  struct enable_if { typedef T type; };
 
 template 
 using enable_if_t = typename enable_if::type;
 
-template 
-struct enable_if_nice { typedef T type; };
-}
+template  struct enable_if_nice { typedef T type; };
+} // namespace std
 
 namespace foo {
-template 
-struct enable_if { typedef T type; };
-}
+template  struct enable_if { typedef T type; };
+} // namespace foo
 
-template 
-constexpr bool just_true = true;
+template  constexpr bool just_true = true;
 
 class Test1 {
 public:
-  template 
-  Test1(T &);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors 
[misc-forwarding-reference-overload]
+  template  Test1(T &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors 
[misc-forwarding-reference-overload]
 
-  template 
-  Test1(T &, int i = 5, ...);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors 
[misc-forwarding-reference-overload]
+  template  Test1(T &, int i = 5, ...);
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
 
   template ::type>
   Test1(T &);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors 
[misc-forwarding-reference-overload]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
 
   template 
   Test1(T &, typename foo::enable_if::type i = 5, ...);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors 
[misc-forwarding-reference-overload]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
 
   Test1(const Test1 ) {}
   // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
@@ -50,19 +43,19 @@ public:
   // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
 };
 
-template 
-class Test2 {
+template  class Test2 {
 public:
   // Two parameters without default value, can't act as copy / move 
constructor.
-  template 
-  Test2(T &, V &, int i = 5, ...);
+  template  Test2(T &, V &, 

r300313 - PR32280: Do not crash on nested initializers.

2017-04-14 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Fri Apr 14 03:48:08 2017
New Revision: 300313

URL: http://llvm.org/viewvc/llvm-project?rev=300313=rev
Log:
PR32280: Do not crash on nested initializers.

Patch by Yuka Takahashi (D31591)!

Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/designated-initializers.c

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=300313=300312=300313=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Apr 14 03:48:08 2017
@@ -2270,15 +2270,17 @@ InitListChecker::CheckDesignatedInitiali
   assert(StructuredList->getNumInits() == 1
  && "A union should never have more than one initializer!");
 
-  // We're about to throw away an initializer, emit warning.
-  SemaRef.Diag(D->getFieldLoc(),
-   diag::warn_initializer_overrides)
-<< D->getSourceRange();
   Expr *ExistingInit = StructuredList->getInit(0);
-  SemaRef.Diag(ExistingInit->getLocStart(),
-   diag::note_previous_initializer)
-<< /*FIXME:has side effects=*/0
-<< ExistingInit->getSourceRange();
+  if (ExistingInit) {
+// We're about to throw away an initializer, emit warning.
+SemaRef.Diag(D->getFieldLoc(),
+ diag::warn_initializer_overrides)
+  << D->getSourceRange();
+SemaRef.Diag(ExistingInit->getLocStart(),
+ diag::note_previous_initializer)
+  << /*FIXME:has side effects=*/0
+  << ExistingInit->getSourceRange();
+  }
 
   // remove existing initializer
   StructuredList->resizeInits(SemaRef.Context, 0);

Modified: cfe/trunk/test/Sema/designated-initializers.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/designated-initializers.c?rev=300313=300312=300313=diff
==
--- cfe/trunk/test/Sema/designated-initializers.c (original)
+++ cfe/trunk/test/Sema/designated-initializers.c Fri Apr 14 03:48:08 2017
@@ -351,3 +351,20 @@ overwrite_string4[] = {
   { { 'f', 'o', 'o' }, 1 },
   [0].L[4] = 'x' // no-warning
 };
+
+struct {
+  struct { } s1;
+  union {
+int a;
+int b;
+  } u1;
+} s = {
+  .s1 = {
+.x = 0, // expected-error{{field designator}}
+  },
+
+  .u1 = {
+.a = 0,
+.b = 0,
+  },
+};


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


[PATCH] D31591: Fix a bug which access nullptr and cause segmentation fault

2017-04-14 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

Landed in r300313.


https://reviews.llvm.org/D31591



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


[PATCH] D31745: [OpenCL] Added diagnostic for implicit declaration of function in OpenCL

2017-04-14 Thread Egor Churaev via Phabricator via cfe-commits
echuraev added inline comments.



Comment at: test/SemaOpenCL/clang-builtin-version.cl:32
+  work_group_reserve_write_pipe(tmp, tmp); // expected-error{{implicit 
declaration of function 'work_group_reserve_write_pipe' is invalid in OpenCL}}
+  // expected-note@-1{{did you mean 'work_group_reserve_read_pipe'?}}
+  // expected-note@-2{{'work_group_reserve_write_pipe' declared here}}

Anastasia wrote:
> Anastasia wrote:
> > echuraev wrote:
> > > Anastasia wrote:
> > > > Why do we get this note now? I believe work_group_reserve_read_pipe 
> > > > shouldn't be available either?
> > > May be I don't understand something but I think that it is the right 
> > > diagnostic message. We called work_group_reserve_read_pipe in line 29. So 
> > > for this case we will get the following message: 
> > > //clang-builtin-version.cl: 31 error: implicit declaration of function 
> > > 'work_group_reserve_write_pipe' is invalid in OpenCL
> > > clang-builtin-version.cl: 31 note: did you mean 
> > > 'work_group_reserve_read_pipe'?
> > > clang-builtin-version.cl: 29 note: 'work_group_reserve_read_pipe' 
> > > declared here//
> > But there is an error now given for the call to 
> > 'work_group_reserve_read_pipe'. Why is it still added to the declarations? 
> > I think we should prevent this.
> Also do you know why we didn't have these notes before? I don't see anything 
> related in your change.
I run this test and got a log with errors. The full log you can find in the end 
of the message.
I think that the diagnostic messages are right. First error we get for implicit 
declaration of **//work_group_reserve_read_pipe//**. After that we call 
function **//work_group_reserve_write_pipe//** and get the same error about 
implicit declaration of function. But also we get two diagnostic messages. 
Compiler already know about **//work_group_reserve_read_pipe//** and make a 
hypothesis: "//note: did you mean 'work_group_reserve_read_pipe'?//" and 
"//note: 'work_group_reserve_read_pipe' declared here//".
As well, next we have declaration of **//work_group_commit_read_pipe//**. And 
we get an error about implicit declaration of this function and also get a note 
messages: "//note: did you mean 'work_group_reserve_read_pipe'?//" and "//note: 
'work_group_reserve_read_pipe' declared here//".


> Also do you know why we didn't have these notes before? I don't see anything 
> related in your change.

Unfortunately, I don't know why we get these notes. They have appeared when I 
changed the status of diagnostic message for implicit declaration from warning 
to error. If we had only warning messages then we wouldn't have these notes.




```
clang-builtin-version.cl:35:3: error: implicit declaration of function 
'work_group_reserve_read_pipe' is invalid in OpenCL
  work_group_reserve_read_pipe(tmp, tmp);
  ^

clang-builtin-version.cl:37:3: error: implicit declaration of function 
'work_group_reserve_write_pipe' is invalid in OpenCL
  work_group_reserve_write_pipe(tmp, tmp);
  ^
clang-builtin-version.cl:37:3: note: did you mean 
'work_group_reserve_read_pipe'?
clang-builtin-version.cl:35:3: note: 'work_group_reserve_read_pipe' declared 
here
  work_group_reserve_read_pipe(tmp, tmp);
  ^

clang-builtin-version.cl:50:3: error: implicit declaration of function 
'work_group_commit_read_pipe' is invalid in OpenCL
  work_group_commit_read_pipe(tmp, tmp);
  ^
clang-builtin-version.cl:50:3: note: did you mean 
'work_group_reserve_read_pipe'?
clang-builtin-version.cl:35:3: note: 'work_group_reserve_read_pipe' declared 
here
  work_group_reserve_read_pipe(tmp, tmp);
  ^
```


https://reviews.llvm.org/D31745



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


[PATCH] D31868: [analyzer] Check NULL pointer dereference issue for memset function

2017-04-14 Thread Leslie Zhai via Phabricator via cfe-commits
xiangzhai updated this revision to Diff 95273.
xiangzhai added a comment.

Hi All,

I have updated my patch as your suggestion, please review it, thanks a lot!

Regards,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D31868

Files:
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  test/Analysis/null-deref-ps-region.c

Index: test/Analysis/null-deref-ps-region.c
===
--- test/Analysis/null-deref-ps-region.c
+++ test/Analysis/null-deref-ps-region.c
@@ -1,6 +1,11 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core -std=gnu99 -analyzer-store=region -verify %s
-// expected-no-diagnostics
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,unix,alpha.unix -std=gnu99 -analyzer-store=region -verify %s
 
+#include "Inputs/system-header-simulator.h"
+
+typedef __typeof(sizeof(int)) size_t;
+void *memset(void *__s, int __c, size_t __n);
+void *malloc(size_t __size);
+void free(void *__ptr);
 
 // The store for 'a[1]' should not be removed mistakenly. SymbolicRegions may
 // also be live roots.
@@ -13,3 +18,41 @@
 i = *p; // no-warning
   }
 }
+
+void f531() {
+  int *x = 0;
+  memset(x, 0, 1); // expected-warning {{Null pointer argument in call to memory set function}}
+}
+
+void f61() {
+  char buf[13];
+  memset(buf, 0, 1); // no-warning
+}
+
+void f611() {
+  char *buf = (char *)malloc(13);
+  memset(buf, 0, 1); // no-warning
+  free(buf);
+}
+
+void f66() {
+  char buf[1];
+  memset(buf, 0, 1024); // expected-warning {{Memory set function accesses out-of-bound array element}}
+}
+
+void f666() {
+  char *buf = (char *)malloc(1);
+  memset(buf, 0, 1024); // expected-warning {{Memory set function accesses out-of-bound array element}}
+  free(buf);
+}
+
+void f77() {
+  char buf[1];
+  memset(buf, 0, sizeof(buf)); // no-warning
+}
+
+void f777() {
+  char *buf = (char *)malloc(1);
+  memset(buf, 0, 1); // no-warning
+  free(buf);
+}
Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -120,6 +120,7 @@
   void evalStdCopy(CheckerContext , const CallExpr *CE) const;
   void evalStdCopyBackward(CheckerContext , const CallExpr *CE) const;
   void evalStdCopyCommon(CheckerContext , const CallExpr *CE) const;
+  void evalMemset(CheckerContext , const CallExpr *CE) const;
 
   // Utility methods
   std::pair
@@ -1999,6 +2000,80 @@
   C.addTransition(State);
 }
 
+void CStringChecker::evalMemset(CheckerContext , const CallExpr *CE) const {
+  if (CE->getNumArgs() != 3)
+return;
+
+  CurrentFunctionDescription = "memory set function";
+
+  const Expr *Mem = CE->getArg(0);
+  const Expr *Const = CE->getArg(1);
+  const Expr *Size = CE->getArg(2);
+  ProgramStateRef State = C.getState();
+
+  // See if the size argument is zero.
+  const LocationContext *LCtx = C.getLocationContext();
+  SVal SizeVal = State->getSVal(Size, LCtx);
+  QualType SizeTy = Size->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+assumeZero(C, State, SizeVal, SizeTy);
+
+  // Get the value of the memory area.
+  SVal MemVal = State->getSVal(Mem, LCtx);
+
+  // If the size is zero, there won't be any actual memory access, so
+  // just bind the return value to the Mem buffer and return.
+  if (StateZeroSize && !StateNonZeroSize) {
+StateZeroSize = StateZeroSize->BindExpr(CE, LCtx, MemVal);
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  if (!StateNonZeroSize)
+return;
+
+  // If the size can be nonzero, we have to check the other arguments.
+  if (StateNonZeroSize) {
+State = StateNonZeroSize;
+
+// Ensure the memory area is not null.
+// If it is NULL there will be a NULL pointer dereference.
+State = checkNonNull(C, State, Mem, MemVal);
+if (!State)
+  return;
+
+SValBuilder  = C.getSValBuilder();
+// Check the region's extent is equal to the Size parameter.
+SVal RetVal = SB.conjureSymbolVal(nullptr, CE, LCtx, C.blockCount());
+const SymbolicRegion *R =
+dyn_cast_or_null(RetVal.getAsRegion());
+if (!R)
+  return;
+if (Optional DefinedSize =
+SizeVal.getAs()) {
+  DefinedOrUnknownSVal Extent = R->getExtent(SB);
+  ProgramStateRef StateSameSize, StateNotSameSize;
+  std::tie(StateSameSize, StateNotSameSize) =
+  State->assume(SB.evalEQ(State, Extent, *DefinedSize));
+  if (StateNotSameSize) {
+State = CheckBufferAccess(C, State, Size, Mem);
+if (!State)
+return;
+  }
+
+  if (StateSameSize) {
+SVal ConstVal = State->getSVal(Const, LCtx);
+State = State->BindExpr(CE, LCtx, RetVal);
+// Actually bind the second argument value to the buffer.
+State = State->bindDefault(RetVal, ConstVal, LCtx);
+C.addTransition(State);
+  

[PATCH] D32014: Remove unused varible

2017-04-14 Thread Wei-Ren Chen via Phabricator via cfe-commits
chenwj added a comment.

Ping? :-)


https://reviews.llvm.org/D32014



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


[PATCH] D32029: [ObjC] Fix lifetime markers of loop variable in EmitObjCForCollectionStmt

2017-04-14 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Those test changes are smaller than I thought they might be; great.


https://reviews.llvm.org/D32029



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