[PATCH] D25263: [Driver] Allow setting the default linker during build

2016-11-30 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: lib/Driver/ToolChain.cpp:721-724
+
+const char *ToolChain::getDefaultLinker() const {
+  return CLANG_DEFAULT_LINKER;
+}

sfertile wrote:
> Hahnfeld wrote:
> > I think this could go into the header
> The CLANG_DEFAULT_LINKER macro is getting defined in "clang/Config/config.h" 
> which isn't meant to be included in other headers.
Right, that does not work for the current version of the patch.

It was meant in conjunction with this comment:
> `CLANG_DEFAULT_LINKER` should override whatever the platform default is. So 
> `ToolChain::getDefaultLinker()` should return `ld` as the variable 
> `DefaultLinker` currently says and the logic should be in 
> `ToolChain::GetLinkerPath()`.


Repository:
  rL LLVM

https://reviews.llvm.org/D25263



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


[PATCH] D26691: [analyzer] Run clang-format and fix style

2016-11-30 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

I am not a big fan of loosing svn blame only to fix formatting, but since you 
are modifying this code anyway, it's fine by me.

Artem and Devin, what is your opinion on this?




Comment at: lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:459
   // Notice that the lower bound is greater than the upper bound.
-  RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Upper, Lower);
+  RangeSet New = getRange(St, Sym).Intersect(getBasicVals(), F, Upper, Lower);
   return New.isEmpty() ? nullptr : St->set(Sym, New);

We should use lower case function names.



Comment at: lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:228
 static void computeAdjustment(SymbolRef , llvm::APSInt ) {
-  // Is it a "($sym+constant1)" expression?
+  // Is it a "($Sym+constant1)" expression?
   if (const SymIntExpr *SE = dyn_cast(Sym)) {

I don't think we should change the case in the comment.



Comment at: lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:255
 
-  // We only handle simple comparisons of the form "$sym == constant"
-  // or "($sym+constant1) == constant2".
+  // We only handle simple comparisons of the form "$Sym == constant"
+  // or "($Sym+constant1) == constant2".

Not sure the comment needs to change.


https://reviews.llvm.org/D26691



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


[PATCH] D26694: [analyzer] Drop explicit mention of range constraint solver

2016-11-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Approve! And probably `-analyzer-store=region` is worth dropping as well 
eventually.


https://reviews.llvm.org/D26694



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


[PATCH] D26694: [analyzer] Drop explicit mention of range constraint solver

2016-11-30 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.
This revision is now accepted and ready to land.

Awesome!!! Thanks for the cleanup!


https://reviews.llvm.org/D26694



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


[PATCH] D26762: Add a method to obtain this SVal of a method that created given StackFrameCtx

2016-11-30 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

I see. You are handling more types of calls with this API! However, Similarly 
to the comment in the related patch, I think we should reuse the logic from 
CallEvent.


https://reviews.llvm.org/D26762



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


[PATCH] D26837: [analyzer] Litter the SVal/SymExpr/MemRegion class hierarchy with asserts.

2016-11-30 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h:737
 ///  either a real region, a NULL pointer, etc.  It essentially is used to
 ///  map the concept of symbolic values into the domain of regions.  Symbolic
 ///  regions do not need to be typed.

zaks.anna wrote:
> This comment states that SymbolicRegions do not need to be typed and the 
> assert states that it has to be a pointer type.
> 
> Also, what about nullPointerType, isMemberPointerType? I am afraid that our 
> test coverage is not very good and might not catch all cases.
> 
> I guess isArrayType() and void types are not expected here?
> 
Ah, right, we would not create a SymbolicRegion for nullPointerType.

This assertion feels a bit a bit superficial as if we are adding the known 
existing uses here, instead of asserting the capabilities/assumptions of the 
data structure itself. (But I can be convinced otherwise.)


https://reviews.llvm.org/D26837



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


r288313 - Teach ConstantBuilder how to emit a reference to the current position

2016-11-30 Thread John McCall via cfe-commits
Author: rjmccall
Date: Wed Nov 30 23:33:30 2016
New Revision: 288313

URL: http://llvm.org/viewvc/llvm-project?rev=288313=rev
Log:
Teach ConstantBuilder how to emit a reference to the current position
that will be filled in when the initializer is set.

Modified:
cfe/trunk/lib/CodeGen/ConstantBuilder.h

Modified: cfe/trunk/lib/CodeGen/ConstantBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ConstantBuilder.h?rev=288313=288312=288313=diff
==
--- cfe/trunk/lib/CodeGen/ConstantBuilder.h (original)
+++ cfe/trunk/lib/CodeGen/ConstantBuilder.h Wed Nov 30 23:33:30 2016
@@ -21,6 +21,8 @@
 
 #include "CodeGenModule.h"
 
+#include 
+
 namespace clang {
 namespace CodeGen {
 
@@ -47,8 +49,15 @@ class ConstantArrayBuilder;
 ///auto global = toplevel.finishAndCreateGlobal("WIDGET_LIST", Align,
 /// /*constant*/ true);
 class ConstantInitBuilder {
+  struct SelfReference {
+llvm::GlobalVariable *Dummy;
+llvm::SmallVector Indices;
+
+SelfReference(llvm::GlobalVariable *dummy) : Dummy(dummy) {}
+  };
   CodeGenModule 
   llvm::SmallVector Buffer;
+  std::vector SelfReferences;
   bool Frozen = false;
 
 public:
@@ -201,6 +210,25 @@ public:
   slot = value;
 }
 
+/// Produce an address which will eventually point to the the next
+/// position to be filled.  This is computed with an indexed
+/// getelementptr rather than by computing offsets.
+///
+/// The returned pointer will have type T*, where T is the given
+/// position.
+llvm::Constant *getAddrOfCurrentPosition(llvm::Type *type) {
+  // Make a global variable.  We will replace this with a GEP to this
+  // position after installing the initializer.
+  auto dummy =
+new llvm::GlobalVariable(Builder.CGM.getModule(), type, true,
+ llvm::GlobalVariable::PrivateLinkage,
+ nullptr, "");
+  Builder.SelfReferences.emplace_back(dummy);
+  auto  = Builder.SelfReferences.back();
+  (void) getGEPIndicesToCurrentPosition(entry.Indices);
+  return dummy;
+}
+
 ArrayRef getGEPIndicesToCurrentPosition(
  llvm::SmallVectorImpl ) {
   getGEPIndicesTo(indices, Builder.Buffer.size());
@@ -294,12 +322,24 @@ private:
llvm::GlobalValue::NotThreadLocal,
addressSpace);
 GV->setAlignment(alignment.getQuantity());
+resolveSelfReferences(GV);
 return GV;
   }
 
   void setGlobalInitializer(llvm::GlobalVariable *GV,
 llvm::Constant *initializer) {
 GV->setInitializer(initializer);
+resolveSelfReferences(GV);
+  }
+
+  void resolveSelfReferences(llvm::GlobalVariable *GV) {
+for (auto  : SelfReferences) {
+  llvm::Constant *resolvedReference =
+llvm::ConstantExpr::getInBoundsGetElementPtr(
+  GV->getValueType(), GV, entry.Indices);
+  entry.Dummy->replaceAllUsesWith(resolvedReference);
+  entry.Dummy->eraseFromParent();
+}
   }
 };
 


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


[PATCH] D26546: [PPC] Add vec_insert4b/vec_extract4b to altivec.h

2016-11-30 Thread Sean Fertile via Phabricator via cfe-commits
sfertile updated this revision to Diff 79860.
sfertile marked an inline comment as done.
sfertile added a comment.

Changed all variable names to start with capitals, added description strings to 
the assertions, changed uses of '12' to MaxIndex and initialized the arrays in 
their definition.


Repository:
  rL LLVM

https://reviews.llvm.org/D26546

Files:
  include/clang/Basic/BuiltinsPPC.def
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/altivec.h
  test/CodeGen/builtins-ppc-error.c
  test/CodeGen/builtins-ppc-extractword-error.c
  test/CodeGen/builtins-ppc-insertword-error.c
  test/CodeGen/builtins-ppc-p9vector.c

Index: test/CodeGen/builtins-ppc-p9vector.c
===
--- test/CodeGen/builtins-ppc-p9vector.c
+++ test/CodeGen/builtins-ppc-p9vector.c
@@ -1166,17 +1166,41 @@
 // CHECK-BE: shufflevector <8 x i16> {{.+}}, <8 x i16> {{.+}}, <8 x i32> 
 // CHECK-BE: @llvm.ppc.vsx.xvcvhpsp(<8 x i16> {{.+}})
 // CHECK-BE-NEXT: ret <4 x float>
-// CHECK-LE: shufflevector <8 x i16> {{.+}}, <8 x i16> {{.+}}, <8 x i32> 
-// CHECK-LE: @llvm.ppc.vsx.xvcvhpsp(<8 x i16> {{.+}})
-// CHECK-LE-NEXT: ret <4 x float>
+// CHECK: shufflevector <8 x i16> {{.+}}, <8 x i16> {{.+}}, <8 x i32> 
+// CHECK: @llvm.ppc.vsx.xvcvhpsp(<8 x i16> {{.+}})
+// CHECK-NEXT: ret <4 x float>
   return vec_extract_fp32_from_shorth(vusa);
 }
 vector float test115(void) {
 // CHECK-BE: shufflevector <8 x i16> {{.+}}, <8 x i16> {{.+}}, <8 x i32> 
 // CHECK-BE: @llvm.ppc.vsx.xvcvhpsp(<8 x i16> {{.+}})
 // CHECK-BE-NEXT: ret <4 x float>
-// CHECK-LE: shufflevector <8 x i16> {{.+}}, <8 x i16> {{.+}}, <8 x i32> 
-// CHECK-LE: @llvm.ppc.vsx.xvcvhpsp(<8 x i16> {{.+}})
-// CHECK-LE-NEXT: ret <4 x float>
+// CHECK: shufflevector <8 x i16> {{.+}}, <8 x i16> {{.+}}, <8 x i32> 
+// CHECK: @llvm.ppc.vsx.xvcvhpsp(<8 x i16> {{.+}})
+// CHECK-NEXT: ret <4 x float>
   return vec_extract_fp32_from_shortl(vusa);
 }
+vector unsigned char test116(void) {
+// CHECK-BE: [[T1:%.+]] = call <4 x i32> @llvm.ppc.vsx.xxinsertw(<4 x i32> {{.+}}, <2 x i64> {{.+}}, i32 7)
+// CHECK-BE-NEXT: bitcast <4 x i32> [[T1]] to <16 x i8>
+// CHECK: [[T1:%.+]] = shufflevector <2 x i64> {{.+}}, <2 x i64> {{.+}}, <2 x i32> 
+// CHECK-NEXT: [[T2:%.+]] = call <4 x i32> @llvm.ppc.vsx.xxinsertw(<4 x i32> {{.+}}, <2 x i64> [[T1]], i32 5)
+// CHECK-NEXT: bitcast <4 x i32> [[T2]] to <16 x i8>
+  return vec_insert4b(vuia, vuca, 7);
+}
+vector unsigned char test117(void) {
+// CHECK-BE: [[T1:%.+]] = call <4 x i32> @llvm.ppc.vsx.xxinsertw(<4 x i32> {{.+}}, <2 x i64> {{.+}}, i32 5)
+// CHECK-BE-NEXT: bitcast <4 x i32> [[T1]] to <16 x i8>
+// CHECK: [[T1:%.+]] = shufflevector <2 x i64> {{.+}}, <2 x i64> {{.+}}, <2 x i32> 
+// CHECK-NEXT: [[T2:%.+]] = call <4 x i32> @llvm.ppc.vsx.xxinsertw(<4 x i32> {{.+}}, <2 x i64> [[T1]], i32 7)
+// CHECK-NEXT: bitcast <4 x i32> [[T2]] to <16 x i8>
+  return vec_insert4b(vsia, vuca, 5);
+}
+vector unsigned long long test118(void) {
+// CHECK-BE: call <2 x i64> @llvm.ppc.vsx.xxextractuw(<2 x i64> {{.+}}, i32 11)
+// CHECK-BE-NEXT: ret <2 x i64>
+// CHECK: [[T1:%.+]] = call <2 x i64> @llvm.ppc.vsx.xxextractuw(<2 x i64> {{.+}}, i32 1)
+// CHECK-NEXT: shufflevector <2 x i64> [[T1]], <2 x i64> [[T1]], <2 x i32> 
+// CHECK-NEXT: ret <2 x i64>
+  return vec_extract4b(vuca, 11);
+}
Index: test/CodeGen/builtins-ppc-insertword-error.c
===
--- /dev/null
+++ test/CodeGen/builtins-ppc-insertword-error.c
@@ -0,0 +1,16 @@
+// REQUIRES: powerpc-registered-target
+// XFAIL: powerpc
+
+// RUN: %clang -faltivec -target powerpc64le-unknown-unknown -mcpu=power8 \
+// RUN: -Wall -Werror -c %s
+
+// RUN: %clang -faltivec -target powerpc64-unknown-unknown -mcpu=power8 \
+// RUN: -Wall -Werror -c %s
+
+// expect to fail  with diagnostic: "cannot compile this builtin function yet"
+extern vector signed int vsi;
+extern vector unsigned char vuc;
+
+vector  unsigned char testInsertWord(void) {
+  return __builtin_vsx_insertword(vsi, vuc, 0);
+}
Index: test/CodeGen/builtins-ppc-extractword-error.c
===
--- /dev/null
+++ test/CodeGen/builtins-ppc-extractword-error.c
@@ -0,0 +1,15 @@
+// REQUIRES: powerpc-registered-target
+// XFAIL: powerpc
+
+// RUN: %clang -faltivec -target powerpc64le-unknown-unknown  -mcpu=power8 \
+// RUN: -Wall -Wextra -c %s
+// RUN: %clang -faltivec -target powerpc64-unknown-unknown  -mcpu=power8 \
+// RUN: -Wall -Wextra -c %s
+
+// Expect the compile to fail ith "cannot compile this builtin function yet"
+extern vector signed int vsi;
+extern vector unsigned char vuc;
+
+vector unsigned long long testExtractWord(void) {
+  return  __builtin_vsx_extractuword(vuc, 12);
+}
Index: test/CodeGen/builtins-ppc-error.c
===
--- /dev/null
+++ test/CodeGen/builtins-ppc-error.c
@@ -0,0 +1,20 @@
+// REQUIRES: powerpc-registered-target
+
+// RUN: 

[PATCH] D27251: [PPC] some bugs mainly about sign problem fixed in altivec.h

2016-11-30 Thread ZiXuan Wu via Phabricator via cfe-commits
Zeson updated this revision to Diff 79856.
Zeson added a comment.

Make vec_xst_be and vec_xl_be test cases put together seperately in 
`builtins-ppc-vsx.c`
Move up macro `__VSX__` to make all vec_xst_be functions included


https://reviews.llvm.org/D27251

Files:
  lib/Headers/altivec.h
  test/CodeGen/builtins-ppc-altivec.c
  test/CodeGen/builtins-ppc-p8vector.c
  test/CodeGen/builtins-ppc-vsx.c

Index: test/CodeGen/builtins-ppc-vsx.c
===
--- test/CodeGen/builtins-ppc-vsx.c
+++ test/CodeGen/builtins-ppc-vsx.c
@@ -1592,11 +1592,11 @@
 // CHECK: @llvm.ppc.altivec.vsl
 // CHECK-LE: @llvm.ppc.altivec.vsl
 
-res_vull = vec_sll(vull, vuc);
+  res_vull = vec_sll(vull, vuc);
 // CHECK: @llvm.ppc.altivec.vsl
 // CHECK-LE: @llvm.ppc.altivec.vsl
 
-res_vsll = vec_slo(vsll, vsc);
+  res_vsll = vec_slo(vsll, vsc);
 // CHECK: @llvm.ppc.altivec.vslo
 // CHECK-LE: @llvm.ppc.altivec.vslo
 
@@ -1636,59 +1636,134 @@
 // CHECK: @llvm.ppc.altivec.vsro
 // CHECK-LE: @llvm.ppc.altivec.vsro
 
-res_vsll = vec_xl(sll, asll);
+  res_vsll = vec_xl(sll, asll);
 // CHECK: load <2 x i64>, <2 x i64>* %{{[0-9]+}}, align 16
 // CHECK-LE: load <2 x i64>, <2 x i64>* %{{[0-9]+}}, align 16
 
-res_vull = vec_xl(sll, aull);
+  res_vull = vec_xl(sll, aull);
 // CHECK: load <2 x i64>, <2 x i64>* %{{[0-9]+}}, align 16
 // CHECK-LE: load <2 x i64>, <2 x i64>* %{{[0-9]+}}, align 16
 
-res_vd = vec_xl(sll, ad);
+  res_vd = vec_xl(sll, ad);
 // CHECK: load <2 x double>, <2 x double>* %{{[0-9]+}}, align 16
 // CHECK-LE: load <2 x double>, <2 x double>* %{{[0-9]+}}, align 16
 
-vec_xst(vsll, sll, asll);
+  vec_xst(vsll, sll, asll);
 // CHECK: store <2 x i64> %{{[0-9]+}}, <2 x i64>* %{{[0-9]+}}, align 16
 // CHECK-LE: store <2 x i64> %{{[0-9]+}}, <2 x i64>* %{{[0-9]+}}, align 16
 
-vec_xst(vull, sll, aull);
+  vec_xst(vull, sll, aull);
 // CHECK: store <2 x i64> %{{[0-9]+}}, <2 x i64>* %{{[0-9]+}}, align 16
 // CHECK-LE: store <2 x i64> %{{[0-9]+}}, <2 x i64>* %{{[0-9]+}}, align 16
 
-vec_xst(vd, sll, ad);
+  vec_xst(vd, sll, ad);
 // CHECK: store <2 x double> %{{[0-9]+}}, <2 x double>* %{{[0-9]+}}, align 16
 // CHECK-LE: store <2 x double> %{{[0-9]+}}, <2 x double>* %{{[0-9]+}}, align 16
 
-res_vsll = vec_xl_be(sll, asll);
-// CHECK: load <2 x i64>, <2 x i64>* %{{[0-9]+}}, align 16
-// CHECK-LE: call <2 x double> @llvm.ppc.vsx.lxvd2x.be(i8* %{{[0-9]+}})
-
-res_vull = vec_xl_be(sll, aull);
-// CHECK: load <2 x i64>, <2 x i64>* %{{[0-9]+}}, align 16
-// CHECK-LE: call <2 x double> @llvm.ppc.vsx.lxvd2x.be(i8* %{{[0-9]+}})
-
-res_vd = vec_xl_be(sll, ad);
-// CHECK: load <2 x double>, <2 x double>* %{{[0-9]+}}, align 16
-// CHECK-LE: call <2 x double> @llvm.ppc.vsx.lxvd2x.be(i8* %{{[0-9]+}})
-
-vec_xst_be(vsll, sll, asll);
-// CHECK: store <2 x i64> %{{[0-9]+}}, <2 x i64>* %{{[0-9]+}}, align 16
-// CHECK-LE: call void @llvm.ppc.vsx.stxvd2x.be(<2 x double> %{{[0-9]+}}, i8* %{{[0-9]+}})
-
-vec_xst_be(vull, sll, aull);
-// CHECK: store <2 x i64> %{{[0-9]+}}, <2 x i64>* %{{[0-9]+}}, align 16
-// CHECK-LE: call void @llvm.ppc.vsx.stxvd2x.be(<2 x double> %{{[0-9]+}}, i8* %{{[0-9]+}})
-
-vec_xst_be(vd, sll, ad);
-// CHECK: store <2 x double> %{{[0-9]+}}, <2 x double>* %{{[0-9]+}}, align 16
-// CHECK-LE: call void @llvm.ppc.vsx.stxvd2x.be(<2 x double> %{{[0-9]+}}, i8* %{{[0-9]+}})
-
   res_vf = vec_neg(vf);
 // CHECK: fsub <4 x float> , {{%[0-9]+}}
 // CHECK-LE: fsub <4 x float> , {{%[0-9]+}}
 
   res_vd = vec_neg(vd);
 // CHECK: fsub <2 x double> , {{%[0-9]+}}
 // CHECK-LE: fsub <2 x double> , {{%[0-9]+}}
 }
+
+
+/* - vec_xl_be -- */
+void test2() {
+  // CHECK-LABEL: define void @test2
+  // CHECK-LE-LABEL: define void @test2
+  vec_xl_be(sll, asc);
+  // CHECK: load <16 x i8>, <16 x i8>* %{{[0-9]+}}, align 16
+  // CHECK-LE: call <2 x double> @llvm.ppc.vsx.lxvd2x.be(i8* %{{[0-9]+}})
+  // CHECK-LE: shufflevector <16 x i8> %{{[0-9]+}}, <16 x i8> %{{[0-9]+}}, <16 x i32> 
+
+  vec_xl_be(sll, auc);
+  // CHECK: load <16 x i8>, <16 x i8>* %{{[0-9]+}}, align 16
+  // CHECK-LE: call <2 x double> @llvm.ppc.vsx.lxvd2x.be(i8* %{{[0-9]+}})
+  // CHECK-LE: shufflevector <16 x i8> %{{[0-9]+}}, <16 x i8> %{{[0-9]+}}, <16 x i32> 
+
+  vec_xl_be(sll, ass);
+  // CHECK: load <8 x i16>, <8 x i16>* %{{[0-9]+}}, align 16
+  // CHECK-LE: call <2 x double> @llvm.ppc.vsx.lxvd2x.be(i8* %{{[0-9]+}})
+  // CHECK-LE: shufflevector <8 x i16> %{{[0-9]+}}, <8 x i16> %{{[0-9]+}}, <8 x i32> 
+
+  vec_xl_be(sll, aus);
+  // CHECK: load <8 x i16>, <8 x i16>* %{{[0-9]+}}, align 16
+  // CHECK-LE: call <2 x double> @llvm.ppc.vsx.lxvd2x.be(i8* %{{[0-9]+}})
+  // CHECK-LE: shufflevector <8 x i16> %{{[0-9]+}}, <8 x i16> %{{[0-9]+}}, <8 x i32> 
+
+  vec_xl_be(sll, asi);
+  // CHECK: load <4 x i32>, <4 x i32>* %{{[0-9]+}}, align 16
+  // CHECK-LE: call <4 x i32> @llvm.ppc.vsx.lxvw4x.be(i8* %{{[0-9]+}})
+
+  vec_xl_be(sll, aui);
+  // CHECK: load <4 x i32>, <4 x i32>* %{{[0-9]+}}, 

r288305 - P0012R1: add Itanium ABI support for throwing non-noexcept function pointers and catching as noexcept.

2016-11-30 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Nov 30 21:32:42 2016
New Revision: 288305

URL: http://llvm.org/viewvc/llvm-project?rev=288305=rev
Log:
P0012R1: add Itanium ABI support for throwing non-noexcept function pointers 
and catching as noexcept.

Added:
cfe/trunk/test/CodeGenCXX/rtti-qualfn.cpp
Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=288305=288304=288305=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Nov 30 21:32:42 2016
@@ -2474,7 +2474,13 @@ public:
 
 /// PTI_ContainingClassIncomplete - Containing class is incomplete.
 /// (in pointer to member).
-PTI_ContainingClassIncomplete = 0x10
+PTI_ContainingClassIncomplete = 0x10,
+
+/// PTI_TransactionSafe - Pointee is transaction_safe function (C++ TM TS).
+//PTI_TransactionSafe = 0x20,
+
+/// PTI_Noexcept - Pointee is noexcept function (C++1z).
+PTI_Noexcept = 0x40,
   };
 
   // VMI type info flags.
@@ -3124,21 +3130,6 @@ llvm::Constant *ItaniumRTTIBuilder::Buil
   return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
 }
 
-/// ComputeQualifierFlags - Compute the pointer type info flags from the
-/// given qualifier.
-static unsigned ComputeQualifierFlags(Qualifiers Quals) {
-  unsigned Flags = 0;
-
-  if (Quals.hasConst())
-Flags |= ItaniumRTTIBuilder::PTI_Const;
-  if (Quals.hasVolatile())
-Flags |= ItaniumRTTIBuilder::PTI_Volatile;
-  if (Quals.hasRestrict())
-Flags |= ItaniumRTTIBuilder::PTI_Restrict;
-
-  return Flags;
-}
-
 /// BuildObjCObjectTypeInfo - Build the appropriate kind of type_info
 /// for the given Objective-C object type.
 void ItaniumRTTIBuilder::BuildObjCObjectTypeInfo(const ObjCObjectType *OT) {
@@ -3322,23 +3313,44 @@ void ItaniumRTTIBuilder::BuildVMIClassTy
   }
 }
 
+/// Compute the flags for a __pbase_type_info, and remove the corresponding
+/// pieces from \p Type.
+static unsigned extractPBaseFlags(ASTContext , QualType ) {
+  unsigned Flags = 0;
+
+  if (Type.isConstQualified())
+Flags |= ItaniumRTTIBuilder::PTI_Const;
+  if (Type.isVolatileQualified())
+Flags |= ItaniumRTTIBuilder::PTI_Volatile;
+  if (Type.isRestrictQualified())
+Flags |= ItaniumRTTIBuilder::PTI_Restrict;
+  Type = Type.getUnqualifiedType();
+
+  // Itanium C++ ABI 2.9.5p7:
+  //   When the abi::__pbase_type_info is for a direct or indirect pointer to 
an
+  //   incomplete class type, the incomplete target type flag is set.
+  if (ContainsIncompleteClassType(Type))
+Flags |= ItaniumRTTIBuilder::PTI_Incomplete;
+
+  if (auto *Proto = Type->getAs()) {
+if (Proto->isNothrow(Ctx)) {
+  Flags |= ItaniumRTTIBuilder::PTI_Noexcept;
+  Type = Ctx.getFunctionType(
+  Proto->getReturnType(), Proto->getParamTypes(),
+  Proto->getExtProtoInfo().withExceptionSpec(EST_None));
+}
+  }
+
+  return Flags;
+}
+
 /// BuildPointerTypeInfo - Build an abi::__pointer_type_info struct,
 /// used for pointer types.
 void ItaniumRTTIBuilder::BuildPointerTypeInfo(QualType PointeeTy) {
-  Qualifiers Quals;
-  QualType UnqualifiedPointeeTy =
-CGM.getContext().getUnqualifiedArrayType(PointeeTy, Quals);
-
   // Itanium C++ ABI 2.9.5p7:
   //   __flags is a flag word describing the cv-qualification and other
   //   attributes of the type pointed to
-  unsigned Flags = ComputeQualifierFlags(Quals);
-
-  // Itanium C++ ABI 2.9.5p7:
-  //   When the abi::__pbase_type_info is for a direct or indirect pointer to 
an
-  //   incomplete class type, the incomplete target type flag is set.
-  if (ContainsIncompleteClassType(UnqualifiedPointeeTy))
-Flags |= PTI_Incomplete;
+  unsigned Flags = extractPBaseFlags(CGM.getContext(), PointeeTy);
 
   llvm::Type *UnsignedIntLTy =
 CGM.getTypes().ConvertType(CGM.getContext().UnsignedIntTy);
@@ -3348,7 +3360,7 @@ void ItaniumRTTIBuilder::BuildPointerTyp
   //  __pointee is a pointer to the std::type_info derivation for the
   //  unqualified type being pointed to.
   llvm::Constant *PointeeTypeInfo =
-ItaniumRTTIBuilder(CXXABI).BuildTypeInfo(UnqualifiedPointeeTy);
+  ItaniumRTTIBuilder(CXXABI).BuildTypeInfo(PointeeTy);
   Fields.push_back(PointeeTypeInfo);
 }
 
@@ -3358,23 +3370,12 @@ void
 ItaniumRTTIBuilder::BuildPointerToMemberTypeInfo(const MemberPointerType *Ty) {
   QualType PointeeTy = Ty->getPointeeType();
 
-  Qualifiers Quals;
-  QualType UnqualifiedPointeeTy =
-CGM.getContext().getUnqualifiedArrayType(PointeeTy, Quals);
-
   // Itanium C++ ABI 2.9.5p7:
   //   __flags is a flag word describing the cv-qualification and other
   //   attributes of the type pointed to.
-  unsigned Flags = ComputeQualifierFlags(Quals);
+  unsigned Flags = extractPBaseFlags(CGM.getContext(), PointeeTy);
 
   const RecordType *ClassType = 

r288304 - Revert r285664, cxx-abi-dev chose to go in a different direction for the ABI here.

2016-11-30 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Nov 30 21:04:07 2016
New Revision: 288304

URL: http://llvm.org/viewvc/llvm-project?rev=288304=rev
Log:
Revert r285664, cxx-abi-dev chose to go in a different direction for the ABI 
here.

Removed:
cfe/trunk/test/CodeGenCXX/rtti-qualfn.cpp
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=288304=288303=288304=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Wed Nov 30 21:04:07 2016
@@ -251,8 +251,6 @@ def munwind_tables : Flag<["-"], "munwin
   HelpText<"Generate unwinding tables for all functions">;
 def mconstructor_aliases : Flag<["-"], "mconstructor-aliases">,
   HelpText<"Emit complete constructors and destructors as aliases when 
possible">;
-def mqualified_function_type_info : Flag<["-"], 
"mqualified-function-type-info">,
-  HelpText<"Emit __qualified_function_type_info for qualified function types">;
 def mlink_bitcode_file : Separate<["-"], "mlink-bitcode-file">,
   HelpText<"Link the given bitcode file before performing optimizations.">;
 def mlink_cuda_bitcode : Separate<["-"], "mlink-cuda-bitcode">,

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=288304=288303=288304=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Wed Nov 30 21:04:07 2016
@@ -133,7 +133,6 @@ CODEGENOPT(DumpCoverageMapping , 1, 0) /
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
 
-CODEGENOPT(QualifiedFunctionTypeInfo, 1, 0) ///< Use 
__qualified_function_type_info.
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
 CODEGENOPT(StructPathTBAA, 1, 0) ///< Whether or not to use struct-path 
TBAA.

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=288304=288303=288304=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Nov 30 21:04:07 2016
@@ -47,7 +47,6 @@ protected:
   bool UseARMMethodPtrABI;
   bool UseARMGuardVarABI;
   bool Use32BitVTableOffsetABI;
-  bool UseQualifiedFunctionTypeInfoABI;
 
   ItaniumMangleContext () {
 return cast(CodeGen::CGCXXABI::getMangleContext());
@@ -59,8 +58,7 @@ public:
 bool UseARMGuardVarABI = false) :
 CGCXXABI(CGM), UseARMMethodPtrABI(UseARMMethodPtrABI),
 UseARMGuardVarABI(UseARMGuardVarABI),
-Use32BitVTableOffsetABI(false),
-
UseQualifiedFunctionTypeInfoABI(CGM.getCodeGenOpts().QualifiedFunctionTypeInfo) 
{ }
+Use32BitVTableOffsetABI(false) { }
 
   bool classifyReturnType(CGFunctionInfo ) const override;
 
@@ -2432,9 +2430,6 @@ class ItaniumRTTIBuilder {
   /// descriptor of the given type.
   llvm::Constant *GetAddrOfExternalRTTIDescriptor(QualType Ty);
 
-  /// Determine whether FnTy should be emitted as a qualified function type.
-  bool EmitAsQualifiedFunctionType(const FunctionType *FnTy);
-
   /// BuildVTablePointer - Build the vtable pointer for the given type.
   void BuildVTablePointer(const Type *Ty);
 
@@ -2447,10 +2442,6 @@ class ItaniumRTTIBuilder {
   /// constraints, according ti the Itanium C++ ABI, 2.9.5p5c.
   void BuildVMIClassTypeInfo(const CXXRecordDecl *RD);
 
-  /// Build an abi::__qualified_function_type_info struct, used for function
-  /// types with various kinds of qualifiers.
-  void BuildQualifiedFunctionTypeInfo(const FunctionType *FnTy);
-
   /// BuildPointerTypeInfo - Build an abi::__pointer_type_info struct, used
   /// for pointer types.
   void BuildPointerTypeInfo(QualType PointeeTy);
@@ -2467,27 +2458,6 @@ public:
   ItaniumRTTIBuilder(const ItaniumCXXABI )
   : CGM(ABI.CGM), VMContext(CGM.getModule().getContext()), CXXABI(ABI) {}
 
-  // Function type info flags.
-  enum {
-/// Qualifiers for 'this' pointer of member function type.
-//@{
-QFTI_Const = 0x1,
-QFTI_Volatile = 0x2,
-QFTI_Restrict = 0x4,
-QFTI_LValRef = 0x8,
-QFTI_RValRef = 0x10,
-//@}
-
-/// Noexcept function qualifier (C++17 onwards).
-QFTI_Noexcept = 0x20,
-
-// Transaction-safe function 

[PATCH] D26837: [analyzer] Litter the SVal/SymExpr/MemRegion class hierarchy with asserts.

2016-11-30 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added inline comments.



Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:23
 #include "clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
 

It's a bit sad to see a header added to another header just for the sake of the 
asserts.. Maybe we could move the constructors into a cpp file...



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h:737
 ///  either a real region, a NULL pointer, etc.  It essentially is used to
 ///  map the concept of symbolic values into the domain of regions.  Symbolic
 ///  regions do not need to be typed.

This comment states that SymbolicRegions do not need to be typed and the assert 
states that it has to be a pointer type.

Also, what about nullPointerType, isMemberPointerType? I am afraid that our 
test coverage is not very good and might not catch all cases.

I guess isArrayType() and void types are not expected here?




Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h:48
+// this may become much stricter.
+return !T.isNull() && !T->isVoidType();
+  }

This function seems to promise more than it does. Maybe it should be renamed 
into something like isNotNullNorVoidType?



Comment at: lib/StaticAnalyzer/Core/SVals.cpp:32
 
-bool SVal::hasConjuredSymbol() const {
-  if (Optional SV = getAs()) {

This dead code should be removed in a separate patch.


https://reviews.llvm.org/D26837



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


r288301 - PR31081: ignore exception specifications when deducing function template

2016-11-30 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Nov 30 20:11:49 2016
New Revision: 288301

URL: http://llvm.org/viewvc/llvm-project?rev=288301=rev
Log:
PR31081: ignore exception specifications when deducing function template
arguments from a declaration; despite what the standard says, this form of
deduction should not be considering exception specifications.

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=288301=288300=288301=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Nov 30 20:11:49 2016
@@ -6515,7 +6515,12 @@ public:
   // C++ Template Argument Deduction (C++ [temp.deduct])
   
//======//
 
-  QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType 
FunctionType);
+  /// Adjust the type \p ArgFunctionType to match the calling convention,
+  /// noreturn, and optionally the exception specification of \p FunctionType.
+  /// Deduction often wants to ignore these properties when matching function
+  /// types.
+  QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType,
+   bool AdjustExceptionSpec = false);
 
   /// \brief Describes the result of template argument deduction.
   ///
@@ -6624,7 +6629,7 @@ public:
   QualType ArgFunctionType,
   FunctionDecl *,
   sema::TemplateDeductionInfo ,
-  bool InOverloadResolution = false);
+  bool IsAddressOfFunction = false);
 
   TemplateDeductionResult
   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
@@ -6637,7 +6642,7 @@ public:
   TemplateArgumentListInfo *ExplicitTemplateArgs,
   FunctionDecl *,
   sema::TemplateDeductionInfo ,
-  bool InOverloadResolution = false);
+  bool IsAddressOfFunction = false);
 
   /// \brief Substitute Replacement for \p auto in \p TypeWithAuto
   QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement);

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=288301=288300=288301=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Nov 30 20:11:49 2016
@@ -2319,8 +2319,6 @@ bool Sema::FindAllocationFunctions(Sourc
 // To perform this comparison, we compute the function type that
 // the deallocation function should have, and use that type both
 // for template argument deduction and for comparison purposes.
-//
-// FIXME: this comparison should ignore CC and the like.
 QualType ExpectedFunctionType;
 {
   const FunctionProtoType *Proto
@@ -2334,7 +2332,6 @@ bool Sema::FindAllocationFunctions(Sourc
   FunctionProtoType::ExtProtoInfo EPI;
   // FIXME: This is not part of the standard's rule.
   EPI.Variadic = Proto->isVariadic();
-  EPI.ExceptionSpec.Type = EST_BasicNoexcept;
 
   ExpectedFunctionType
 = Context.getFunctionType(Context.VoidTy, ArgTypes, EPI);
@@ -2344,8 +2341,8 @@ bool Sema::FindAllocationFunctions(Sourc
  DEnd = FoundDelete.end();
  D != DEnd; ++D) {
   FunctionDecl *Fn = nullptr;
-  if (FunctionTemplateDecl *FnTmpl
-= dyn_cast((*D)->getUnderlyingDecl())) {
+  if (FunctionTemplateDecl *FnTmpl =
+  dyn_cast((*D)->getUnderlyingDecl())) {
 // Perform template argument deduction to try to match the
 // expected function type.
 TemplateDeductionInfo Info(StartLoc);
@@ -2355,7 +2352,10 @@ bool Sema::FindAllocationFunctions(Sourc
   } else
 Fn = cast((*D)->getUnderlyingDecl());
 
-  if (Context.hasSameType(Fn->getType(), ExpectedFunctionType))
+  if (Context.hasSameType(adjustCCAndNoReturn(Fn->getType(),
+  ExpectedFunctionType,
+  /*AdjustExcpetionSpec*/true),
+  ExpectedFunctionType))
 Matches.push_back(std::make_pair(D.getPair(), Fn));
 }
 

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=288301=288300=288301=diff
==
--- 

Re: Crash in MallocChecker

2016-11-30 Thread Devin Coughlin via cfe-commits
+ Artem and Daniel,

Thanks for the patch! This fix seems reasonable to me, although it would good 
to add the reproducer as test case! (tests/Analysis/malloc.cpp would be a fine 
place for it).

Devin

Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp   (revisione 285953)
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp   (copia locale)
@@ -1026,8 +1026,7 @@
   ASTContext  = C.getASTContext();
   CharUnits TypeSize = AstContext.getTypeSizeInChars(ElementType);
 
-  if (Optional DefinedSize =
-  ElementCount.getAs()) {
+  if (ElementCount.getAs()) {
 DefinedOrUnknownSVal Extent = Region->getExtent(svalBuilder);
 // size in Bytes = ElementCount*TypeSize
 SVal SizeInBytes = svalBuilder.evalBinOpNN(


> On Nov 30, 2016, at 4:10 PM, Abramo Bagnara  wrote:
> 
> Please consider to review and apply the attached patch.
> 
> This is how to reproduce the bug:
> 
> abramo@tester:~$ cat bug.cpp
> void f(int a, int b)
> {
>new char[a * b];
> }
> abramo@tester:~$ ~/llvm-build/bin/clang -cc1 -analyze
> -analyzer-checker=cplusplus.NewDeleteLeaks bug.cpp
> clang:
> /home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h:76:
> T clang::ento::SVal::castAs() const [with T = clang::ento::NonLoc]:
> Assertion `T::isKind(*this)' failed.
> #0 0x03689a0f llvm::sys::PrintStackTrace(llvm::raw_ostream&)
> /home/abramo/llvm/lib/Support/Unix/Signals.inc:402:0
> #1 0x03689d6a PrintStackTraceSignalHandler(void*)
> /home/abramo/llvm/lib/Support/Unix/Signals.inc:466:0
> #2 0x03687f30 llvm::sys::RunSignalHandlers()
> /home/abramo/llvm/lib/Support/Signals.cpp:44:0
> #3 0x036893a1 SignalHandler(int)
> /home/abramo/llvm/lib/Support/Unix/Signals.inc:256:0
> #4 0x7f7833b31330 __restore_rt
> (/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
> #5 0x7f783291dc37 gsignal
> /build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
> #6 0x7f7832921028 abort
> /build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
> #7 0x7f7832916bf6 __assert_fail_base
> /build/eglibc-oGUzwX/eglibc-2.19/assert/assert.c:92:0
> #8 0x7f7832916ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
> #9 0x05b1769d clang::ento::NonLoc
> clang::ento::SVal::castAs() const
> /home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h:77:0
> #10 0x05bf5a20 (anonymous
> namespace)::MallocChecker::addExtentSize(clang::ento::CheckerContext&,
> clang::CXXNewExpr const*,
> llvm::IntrusiveRefCntPtr)
> /home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1036:0
> #11 0x05bf5601 (anonymous
> namespace)::MallocChecker::checkPostStmt(clang::CXXNewExpr const*,
> clang::ento::CheckerContext&) const
> /home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:991:0
> #12 0x05c0aa29 void
> clang::ento::check::PostStmt::_checkStmt<(anonymous
> namespace)::MallocChecker>(void*, clang::Stmt const*,
> clang::ento::CheckerContext&)
> /home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/Checker.h:105:0
> #13 0x05f0d9a8 clang::ento::CheckerFn clang::ento::CheckerContext&)>::operator()(clang::Stmt const*,
> clang::ento::CheckerContext&) const
> /home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h:60:0
> #14 0x05f08002 (anonymous
> namespace)::CheckStmtContext::runChecker(clang::ento::CheckerFn (clang::Stmt const*, clang::ento::CheckerContext&)>,
> clang::ento::NodeBuilder&, clang::ento::ExplodedNode*)
> /home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:161:0
> #15 0x05f0a761 void expandGraphWithCheckers<(anonymous
> namespace)::CheckStmtContext>((anonymous namespace)::CheckStmtContext,
> clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&)
> /home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:121:0
> #16 0x05f080b2
> clang::ento::CheckerManager::runCheckersForStmt(bool,
> clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&,
> clang::Stmt const*, clang::ento::ExprEngine&, bool)
> /home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:175:0
> #17 0x05f40184
> clang::ento::CheckerManager::runCheckersForPostStmt(clang::ento::ExplodedNodeSet&,
> clang::ento::ExplodedNodeSet const&, clang::Stmt const*,
> clang::ento::ExprEngine&, bool)
> /home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h:206:0
> #18 0x05f3770a clang::ento::ExprEngine::Visit(clang::Stmt
> const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&)
> /home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:1151:0
> #19 0x05f341e4
> clang::ento::ExprEngine::ProcessStmt(clang::CFGStmt,
> clang::ento::ExplodedNode*)
> 

[PATCH] D27226: [MS ABI] Implement more of the Itanium mangling rules

2016-11-30 Thread David Majnemer via Phabricator via cfe-commits
majnemer updated this revision to Diff 79848.
majnemer marked an inline comment as done.
majnemer added a comment.

- Address review comments


https://reviews.llvm.org/D27226

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

Index: test/CodeGenCXX/mangle-ms-cxx11.cpp
===
--- test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -318,3 +318,28 @@
 
 // CHECK-DAG: @"\01?unaligned_foo8@unaligned_foo8_S@@QFCEXXZ"
 
+namespace PR31197 {
+struct A {
+  // CHECK-DAG: define linkonce_odr x86_thiscallcc i32* @"\01??R@x@A@PR31197@@QBE@XZ"(
+  int *x = []() {
+static int white;
+// CHECK-DAG: @"\01?white@?1???R@x@A@PR31197@@QBE@XZ@4HA"
+return 
+  }();
+  // CHECK-DAG: define linkonce_odr x86_thiscallcc i32* @"\01??R@y@A@PR31197@@QBE@XZ"(
+  int *y = []() {
+static int black;
+// CHECK-DAG: @"\01?black@?1???R@y@A@PR31197@@QBE@XZ@4HA"
+return 
+  }();
+  using FPtrTy = void(void);
+  static void default_args(FPtrTy x = [] {}, FPtrTy y = [] {}, int z = [] { return 1; }() + [] { return 2; }()) {}
+  // CHECK-DAG: @"\01??R@?A@??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: @"\01??R@?A@??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: @"\01??R@?A@??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: @"\01??R@?A@??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+};
+A a;
+
+int call_it = (A::default_args(), 1);
+}
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -66,6 +66,16 @@
   }
 };
 
+static const DeclContext *
+getLambdaDefaultArgumentDeclContext(const Decl *D) {
+  if (const auto *RD = dyn_cast(D))
+if (RD->isLambda())
+  if (const auto *Parm =
+  dyn_cast_or_null(RD->getLambdaContextDecl()))
+return Parm->getDeclContext();
+  return nullptr;
+}
+
 /// \brief Retrieve the declaration context that should be used when mangling
 /// the given declaration.
 static const DeclContext *getEffectiveDeclContext(const Decl *D) {
@@ -75,12 +85,8 @@
   // not the case: the lambda closure type ends up living in the context
   // where the function itself resides, because the function declaration itself
   // had not yet been created. Fix the context here.
-  if (const CXXRecordDecl *RD = dyn_cast(D)) {
-if (RD->isLambda())
-  if (ParmVarDecl *ContextParam =
-  dyn_cast_or_null(RD->getLambdaContextDecl()))
-return ContextParam->getDeclContext();
-  }
+  if (const auto *LDADC = getLambdaDefaultArgumentDeclContext(D))
+return LDADC;
 
   // Perform the same check for block literals.
   if (const BlockDecl *BD = dyn_cast(D)) {
@@ -112,14 +118,6 @@
   return FD;
 }
 
-static bool isLambda(const NamedDecl *ND) {
-  const CXXRecordDecl *Record = dyn_cast(ND);
-  if (!Record)
-return false;
-
-  return Record->isLambda();
-}
-
 /// MicrosoftMangleContextImpl - Overrides the default MangleContext for the
 /// Microsoft Visual C++ ABI.
 class MicrosoftMangleContextImpl : public MicrosoftMangleContext {
@@ -200,9 +198,12 @@
 
 // Lambda closure types are already numbered, give out a phony number so
 // that they demangle nicely.
-if (isLambda(ND)) {
-  disc = 1;
-  return true;
+// Use scope zero for lambdas in default arguments, one for all other lambdas.
+if (const auto *RD = dyn_cast(ND)) {
+  if (RD->isLambda()) {
+disc = getLambdaDefaultArgumentDeclContext(RD) ? 0 : 1;
+return true;
+  }
 }
 
 // Use the canonical number for externally visible decls.
@@ -824,16 +825,41 @@
   if (const CXXRecordDecl *Record = dyn_cast(TD)) {
 if (Record->isLambda()) {
   llvm::SmallString<10> Name("getLambdaContextDecl();
+  unsigned LambdaManglingNumber = Record->getLambdaManglingNumber();
   unsigned LambdaId;
-  if (Record->getLambdaManglingNumber())
-LambdaId = Record->getLambdaManglingNumber();
+  const ParmVarDecl *Parm =
+  dyn_cast_or_null(LambdaContextDecl);
+  const FunctionDecl *Func =
+  Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
+
+  if (Func) {
+unsigned DefaultArgNo =
+Func->getNumParams() - Parm->getFunctionScopeIndex();
+Name += llvm::utostr(DefaultArgNo);
+Name += "_";
+  }
+
+  if (LambdaManglingNumber)
+LambdaId = LambdaManglingNumber;
   else
 LambdaId = Context.getLambdaId(Record);
 
   Name += llvm::utostr(LambdaId);
   Name += ">";
 
   mangleSourceName(Name);
+
+  // If the context of a closure type is an initializer for a class
+  // member (static or nonstatic), it is encoded in a qualified name.

[PATCH] D22862: [analyzer] Fix for PR15623: eliminate unwanted ProgramState checker data propagation.

2016-11-30 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.

Overall, this looks good to me. Thanks for tackling this!

One request, though. Could you move the tests into already existing test files? 
We're trying to avoid test files that only test a single issue. This makes it 
easier for people who are new to the project to determine where a new test 
should go. I think test1 could go in perhaps malloc.c and test2 could go in 
misc-ps.c. It would also be good to have both test functions mention the PR so 
a future maintainer can tell they are related even though they are in different 
files.


https://reviews.llvm.org/D22862



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


[PATCH] D27214: [ObjC] Encode type arguments in property information string constants

2016-11-30 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Do you know whether this patch would have any effect on the objective-c 
runtime? I suspect it wouldn't cause the runtime to crash, but I don't know how 
the runtime uses the encoded type information.

Other than that, the changes made in this patch look good to me.


Repository:
  rL LLVM

https://reviews.llvm.org/D27214



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


Re: r288269 - Finish adopting ConstantInitBuilder in CGObjCGNU. NFC.

2016-11-30 Thread John McCall via cfe-commits

> On Nov 30, 2016, at 3:27 PM, Reid Kleckner  wrote:
> 
> So, I always push for leading upper case variable names. Over time we've 
> gotten to the point where the majority of the code that I read in clang 
> follows this convention. You seem to be pushing the other direction. What do 
> you think we should be doing?

IRGen has always been inconsistent about this, and my goal in IRGen is to make 
it consistently use leading lowercase.  I have always been up-front about this 
goal; the pervasive LLVM style where literally everything is uppercased is, as 
you say, dumb and unreadable, as well as creating massive spurious conflicts 
between types and variables.  IRGen already has enough readability problems 
from working with different layers with a ton of similarly-named types and 
concepts (and trust me, it's somehow worse in Swift's IRGen), as well as the 
monotonous verbosity of having a thing and lowering it to a different thing, 
over and over and over; it really does not need any extra disadvantages.  So 
while I won't reformat existing code for no reason, when I do find myself 
rewriting it substantially, I usually try to make that function use lowercase, 
at least for spelled-out names.

If someone wrote a tool to mass-reformat IRGen to use consistent uppercase, I 
would complain — we'd be enforcing a convention that it seems everyone who 
contributes to LLVM has independently decided is bad but which nobody has the 
energy to fight for (but who would they be fighting?) — but in the end I'd 
apply it and endeavor to follow the rule consistently thenceforth.  But since 
significant amounts of IRGen do not use that convention already, I am not going 
to follow it.

John.

> 
> I'll admit the LLVM naming conventions are dumb, but I just don't care 
> anymore, and would rather have it all look the same.
> http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly
>  
> 
> 
> I only mention it because you're modifying code that was clearly in the 
> leading uppercase camp to leading lower case, so you weren't fitting into an 
> existing style common to some local source file.
> 
> On Wed, Nov 30, 2016 at 12:19 PM, John McCall via cfe-commits 
> > wrote:
> Author: rjmccall
> Date: Wed Nov 30 14:19:46 2016
> New Revision: 288269
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=288269=rev 
> 
> Log:
> Finish adopting ConstantInitBuilder in CGObjCGNU.  NFC.
> 
> Modified:
> cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> cfe/trunk/lib/CodeGen/ConstantBuilder.h
> 
> Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=288269=288268=288269=diff
>  
> 
> ==
> --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Nov 30 14:19:46 2016
> @@ -164,9 +164,8 @@ protected:
>/// Helper function that generates a constant string and returns a pointer 
> to
>/// the start of the string.  The result of this function can be used 
> anywhere
>/// where the C code specifies const char*.
> -  llvm::Constant *MakeConstantString(const std::string ,
> - const std::string ="") {
> -ConstantAddress Array = CGM.GetAddrOfConstantCString(Str, Name.c_str());
> +  llvm::Constant *MakeConstantString(StringRef Str, const char *Name = "") {
> +ConstantAddress Array = CGM.GetAddrOfConstantCString(Str, Name);
>  return llvm::ConstantExpr::getGetElementPtr(Array.getElementType(),
>  Array.getPointer(), Zeros);
>}
> @@ -1530,23 +1529,24 @@ GenerateMethodList(StringRef ClassName,
>MethodList.addInt(Int32Ty, MethodTypes.size());
> 
>// Get the method structure type.
> -  llvm::StructType *ObjCMethodTy = llvm::StructType::get(
> -PtrToInt8Ty, // Really a selector, but the runtime creates it us.
> -PtrToInt8Ty, // Method types
> -IMPTy, //Method pointer
> -nullptr);
> +  llvm::StructType *ObjCMethodTy =
> +llvm::StructType::get(CGM.getLLVMContext(), {
> +  PtrToInt8Ty, // Really a selector, but the runtime creates it us.
> +  PtrToInt8Ty, // Method types
> +  IMPTy// Method pointer
> +});
>auto Methods = MethodList.beginArray();
>for (unsigned int i = 0, e = MethodTypes.size(); i < e; ++i) {
> -llvm::Constant *Method =
> +llvm::Constant *FnPtr =
>TheModule.getFunction(SymbolNameForMethod(ClassName, CategoryName,
>  MethodSels[i],
>   

r288297 - [TableGen] Minor clean-ups. NFC.

2016-11-30 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Wed Nov 30 18:13:18 2016
New Revision: 288297

URL: http://llvm.org/viewvc/llvm-project?rev=288297=rev
Log:
[TableGen] Minor clean-ups. NFC.

Primarily: try to use DenseSet instead of
std::set, and use pretty range algos where we can.

Small sizes were arbitrarily chosen.

Modified:
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=288297=288296=288297=diff
==
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Wed Nov 30 18:13:18 2016
@@ -12,6 +12,7 @@
 
//===--===//
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/STLExtras.h"
@@ -120,12 +121,8 @@ static std::string WritePCHRecord(String
 // underscores. For example, __foo, foo__, __foo__ would
 // become foo.
 static StringRef NormalizeAttrName(StringRef AttrName) {
-  if (AttrName.startswith("__"))
-AttrName = AttrName.substr(2, AttrName.size());
-
-  if (AttrName.endswith("__"))
-AttrName = AttrName.substr(0, AttrName.size() - 2);
-
+  AttrName.consume_front("__");
+  AttrName.consume_back("__");
   return AttrName;
 }
 
@@ -723,13 +720,10 @@ namespace {
   std::vector
   uniqueEnumsInOrder(const std::vector ) {
 std::vector uniques;
-std::set unique_set(enums.begin(), enums.end());
+SmallDenseSet unique_set;
 for (const auto  : enums) {
-  auto set_i = unique_set.find(i);
-  if (set_i != unique_set.end()) {
+  if (unique_set.insert(i).second)
 uniques.push_back(i);
-unique_set.erase(set_i);
-  }
 }
 return uniques;
   }
@@ -841,7 +835,7 @@ namespace {
   OS << "  static const char *Convert" << type << "ToStr("
  << type << " Val) {\n"
  << "switch(Val) {\n";
-  std::set Uniques;
+  SmallDenseSet Uniques;
   for (size_t I = 0; I < enums.size(); ++I) {
 if (Uniques.insert(enums[I]).second)
   OS << "case " << getAttrName() << "Attr::" << enums[I]
@@ -949,7 +943,7 @@ namespace {
   OS << "  static const char *Convert" << type << "ToStr("
 << type << " Val) {\n"
 << "switch(Val) {\n";
-  std::set Uniques;
+  SmallDenseSet Uniques;
   for (size_t I = 0; I < enums.size(); ++I) {
 if (Uniques.insert(enums[I]).second)
   OS << "case " << getAttrName() << "Attr::" << enums[I]
@@ -1353,11 +1347,8 @@ writePrettyPrintFunction(Record ,
 
 // Fake arguments aren't part of the parsed form and should not be
 // pretty-printed.
-bool hasNonFakeArgs = false;
-for (const auto  : Args) {
-  if (arg->isFake()) continue;
-  hasNonFakeArgs = true;
-}
+bool hasNonFakeArgs = llvm::any_of(
+Args, [](const std::unique_ptr ) { return !A->isFake(); });
 
 // FIXME: always printing the parenthesis isn't the correct behavior for
 // attributes which have optional arguments that were not provided. For
@@ -1417,18 +1408,20 @@ getSpellingListIndex(const std::vector Accessors = R.getValueAsListOfDefs("Accessors");
+  if (Accessors.empty())
+return;
+
+  const std::vector SpellingList = GetFlattenedSpellings(R);
+  assert(!SpellingList.empty() &&
+ "Attribute with empty spelling list can't have accessors!");
   for (const auto *Accessor : Accessors) {
 std::string Name = Accessor->getValueAsString("Name");
-std::vector Spellings = 
-  GetFlattenedSpellings(*Accessor);
-std::vector SpellingList = GetFlattenedSpellings(R);
-assert(!SpellingList.empty() &&
-   "Attribute with empty spelling list can't have accessors!");
+std::vector Spellings = 
GetFlattenedSpellings(*Accessor);
 
 OS << "  bool " << Name << "() const { return SpellingListIndex == ";
 for (unsigned Index = 0; Index < Spellings.size(); ++Index) {
   OS << getSpellingListIndex(SpellingList, Spellings[Index]);
-  if (Index != Spellings.size() -1)
+  if (Index != Spellings.size() - 1)
 OS << " ||\nSpellingListIndex == ";
   else
 OS << "; }\n";
@@ -1530,6 +1523,16 @@ static void emitClangAttrLateParsedList(
   OS << "#endif // CLANG_ATTR_LATE_PARSED_LIST\n\n";
 }
 
+template 
+static void forEachUniqueSpelling(const Record , Fn &) {
+  std::vector Spellings = GetFlattenedSpellings(Attr);
+  SmallDenseSet Seen;
+  for (const FlattenedSpelling  : Spellings) {
+if (Seen.insert(S.name()).second)
+  F(S);
+  }
+}
+
 /// \brief Emits the first-argument-is-type property for attributes.
 static void emitClangAttrTypeArgList(RecordKeeper , raw_ostream ) {
   OS << "#if 

[PATCH] D27226: [MS ABI] Implement more of the Itanium mangling rules

2016-11-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:838
+  if (Func)
+LambdaId = Func->getNumParams() - Parm->getFunctionScopeIndex();
+  else if (LambdaManglingNumber)

Isn't this no good if I have two lambdas in one default arg?
  inline int f(int x = [] { return 1; }() + [] { return 2; }()) { return x; }
  int main() { return f(); }
We probably need . =/


https://reviews.llvm.org/D27226



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


[PATCH] D25216: Improve error message when referencing a non-tag type with a tag

2016-11-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:4556-4558
+  "%0 is a %select{non-tag type|typedef|type alias|template|type alias "
+  "template|template template argument}1 that cannot be referenced with a "
+  "%select{struct|interface|union|class|enum}2 tag">;

rsmith wrote:
> "tag" is C terminology that C++ doesn't share;  "specifier" would be correct 
> in both languages.
> 
> Also, this wording suggests that *some* templates / template template 
> arguments / ... can be referenced by, say, a `struct` specifier. How about:
> 
>   %select{non-struct type|non-class type|non-union type|non-enum 
> type|typedef|type alias|template|[...]}1 %0 cannot be referenced with 
> %select{struct|interface|union|class|enum}2 specifier
> 
> (where we use "non-enum type" when the tag is `enum`, "non-union type" when 
> the tag is `union`, and otherwise use "non-struct type" in C and "non-class 
> type" in C++)?
OK, sounds good.


https://reviews.llvm.org/D25216



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


Crash in MallocChecker

2016-11-30 Thread Abramo Bagnara via cfe-commits
Please consider to review and apply the attached patch.

This is how to reproduce the bug:

abramo@tester:~$ cat bug.cpp
void f(int a, int b)
{
new char[a * b];
}
abramo@tester:~$ ~/llvm-build/bin/clang -cc1 -analyze
-analyzer-checker=cplusplus.NewDeleteLeaks bug.cpp
clang:
/home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h:76:
T clang::ento::SVal::castAs() const [with T = clang::ento::NonLoc]:
Assertion `T::isKind(*this)' failed.
#0 0x03689a0f llvm::sys::PrintStackTrace(llvm::raw_ostream&)
/home/abramo/llvm/lib/Support/Unix/Signals.inc:402:0
#1 0x03689d6a PrintStackTraceSignalHandler(void*)
/home/abramo/llvm/lib/Support/Unix/Signals.inc:466:0
#2 0x03687f30 llvm::sys::RunSignalHandlers()
/home/abramo/llvm/lib/Support/Signals.cpp:44:0
#3 0x036893a1 SignalHandler(int)
/home/abramo/llvm/lib/Support/Unix/Signals.inc:256:0
#4 0x7f7833b31330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#5 0x7f783291dc37 gsignal
/build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#6 0x7f7832921028 abort
/build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
#7 0x7f7832916bf6 __assert_fail_base
/build/eglibc-oGUzwX/eglibc-2.19/assert/assert.c:92:0
#8 0x7f7832916ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#9 0x05b1769d clang::ento::NonLoc
clang::ento::SVal::castAs() const
/home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h:77:0
#10 0x05bf5a20 (anonymous
namespace)::MallocChecker::addExtentSize(clang::ento::CheckerContext&,
clang::CXXNewExpr const*,
llvm::IntrusiveRefCntPtr)
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1036:0
#11 0x05bf5601 (anonymous
namespace)::MallocChecker::checkPostStmt(clang::CXXNewExpr const*,
clang::ento::CheckerContext&) const
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:991:0
#12 0x05c0aa29 void
clang::ento::check::PostStmt::_checkStmt<(anonymous
namespace)::MallocChecker>(void*, clang::Stmt const*,
clang::ento::CheckerContext&)
/home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/Checker.h:105:0
#13 0x05f0d9a8 clang::ento::CheckerFn::operator()(clang::Stmt const*,
clang::ento::CheckerContext&) const
/home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h:60:0
#14 0x05f08002 (anonymous
namespace)::CheckStmtContext::runChecker(clang::ento::CheckerFn,
clang::ento::NodeBuilder&, clang::ento::ExplodedNode*)
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:161:0
#15 0x05f0a761 void expandGraphWithCheckers<(anonymous
namespace)::CheckStmtContext>((anonymous namespace)::CheckStmtContext,
clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&)
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:121:0
#16 0x05f080b2
clang::ento::CheckerManager::runCheckersForStmt(bool,
clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&,
clang::Stmt const*, clang::ento::ExprEngine&, bool)
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:175:0
#17 0x05f40184
clang::ento::CheckerManager::runCheckersForPostStmt(clang::ento::ExplodedNodeSet&,
clang::ento::ExplodedNodeSet const&, clang::Stmt const*,
clang::ento::ExprEngine&, bool)
/home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h:206:0
#18 0x05f3770a clang::ento::ExprEngine::Visit(clang::Stmt
const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&)
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:1151:0
#19 0x05f341e4
clang::ento::ExprEngine::ProcessStmt(clang::CFGStmt,
clang::ento::ExplodedNode*)
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:463:0
#20 0x05f334e4
clang::ento::ExprEngine::processCFGElement(clang::CFGElement,
clang::ento::ExplodedNode*, unsigned int,
clang::ento::NodeBuilderContext*)
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:311:0
#21 0x05f228db
clang::ento::CoreEngine::HandlePostStmt(clang::CFGBlock const*, unsigned
int, clang::ento::ExplodedNode*)
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:532:0
#22 0x05f217ea
clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*,
clang::ProgramPoint, clang::ento::WorkListUnit const&)
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:279:0
#23 0x05f213ca
clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*,
unsigned int, llvm::IntrusiveRefCntPtr)
/home/abramo/llvm/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:216:0
#24 0x04e7ee6a
clang::ento::ExprEngine::ExecuteWorkList(clang::LocationContext const*,
unsigned int)
/home/abramo/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h:109:0
#25 0x04e388be (anonymous

[PATCH] D27226: [MS ABI] Implement more of the Itanium mangling rules

2016-11-30 Thread David Majnemer via Phabricator via cfe-commits
majnemer updated this revision to Diff 79837.
majnemer added a comment.

- Address review comments


https://reviews.llvm.org/D27226

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

Index: test/CodeGenCXX/mangle-ms-cxx11.cpp
===
--- test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -318,3 +318,26 @@
 
 // CHECK-DAG: @"\01?unaligned_foo8@unaligned_foo8_S@@QFCEXXZ"
 
+namespace PR31197 {
+struct A {
+  // CHECK-DAG: define linkonce_odr x86_thiscallcc i32* @"\01??R@x@A@PR31197@@QBE@XZ"(
+  int *x = []() {
+static int white;
+// CHECK-DAG: @"\01?white@?1???R@x@A@PR31197@@QBE@XZ@4HA"
+return 
+  }();
+  // CHECK-DAG: define linkonce_odr x86_thiscallcc i32* @"\01??R@y@A@PR31197@@QBE@XZ"(
+  int *y = []() {
+static int black;
+// CHECK-DAG: @"\01?black@?1???R@y@A@PR31197@@QBE@XZ@4HA"
+return 
+  }();
+  using FPtrTy = void(void);
+  static void default_args(FPtrTy x = [] {}, FPtrTy y = [] {}) {}
+  // CHECK-DAG: @"\01??R@?A@??default_args@A@PR31197@@SAXP6AXXZ0@Z@QBE@XZ"(
+  // CHECK-DAG: @"\01??R@?A@??default_args@A@PR31197@@SAXP6AXXZ0@Z@QBE@XZ"(
+};
+A a;
+
+int call_it = (A::default_args(), 1);
+}
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -66,6 +66,16 @@
   }
 };
 
+static const DeclContext *
+getLambdaDefaultArgumentDeclContext(const Decl *D) {
+  if (const auto *RD = dyn_cast(D))
+if (RD->isLambda())
+  if (const auto *Parm =
+  dyn_cast_or_null(RD->getLambdaContextDecl()))
+return Parm->getDeclContext();
+  return nullptr;
+}
+
 /// \brief Retrieve the declaration context that should be used when mangling
 /// the given declaration.
 static const DeclContext *getEffectiveDeclContext(const Decl *D) {
@@ -75,12 +85,8 @@
   // not the case: the lambda closure type ends up living in the context
   // where the function itself resides, because the function declaration itself
   // had not yet been created. Fix the context here.
-  if (const CXXRecordDecl *RD = dyn_cast(D)) {
-if (RD->isLambda())
-  if (ParmVarDecl *ContextParam =
-  dyn_cast_or_null(RD->getLambdaContextDecl()))
-return ContextParam->getDeclContext();
-  }
+  if (const auto *LDADC = getLambdaDefaultArgumentDeclContext(D))
+return LDADC;
 
   // Perform the same check for block literals.
   if (const BlockDecl *BD = dyn_cast(D)) {
@@ -112,14 +118,6 @@
   return FD;
 }
 
-static bool isLambda(const NamedDecl *ND) {
-  const CXXRecordDecl *Record = dyn_cast(ND);
-  if (!Record)
-return false;
-
-  return Record->isLambda();
-}
-
 /// MicrosoftMangleContextImpl - Overrides the default MangleContext for the
 /// Microsoft Visual C++ ABI.
 class MicrosoftMangleContextImpl : public MicrosoftMangleContext {
@@ -200,9 +198,12 @@
 
 // Lambda closure types are already numbered, give out a phony number so
 // that they demangle nicely.
-if (isLambda(ND)) {
-  disc = 1;
-  return true;
+// Use scope zero for lambdas in default arguments, one for all other lambdas.
+if (const auto *RD = dyn_cast(ND)) {
+  if (RD->isLambda()) {
+disc = getLambdaDefaultArgumentDeclContext(RD) ? 0 : 1;
+return true;
+  }
 }
 
 // Use the canonical number for externally visible decls.
@@ -824,16 +825,36 @@
   if (const CXXRecordDecl *Record = dyn_cast(TD)) {
 if (Record->isLambda()) {
   llvm::SmallString<10> Name("getLambdaContextDecl();
+  unsigned LambdaManglingNumber = Record->getLambdaManglingNumber();
   unsigned LambdaId;
-  if (Record->getLambdaManglingNumber())
-LambdaId = Record->getLambdaManglingNumber();
+  const ParmVarDecl *Parm =
+  dyn_cast_or_null(LambdaContextDecl);
+  const FunctionDecl *Func =
+  Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
+
+  if (Func)
+LambdaId = Func->getNumParams() - Parm->getFunctionScopeIndex();
+  else if (LambdaManglingNumber)
+LambdaId = LambdaManglingNumber;
   else
 LambdaId = Context.getLambdaId(Record);
 
   Name += llvm::utostr(LambdaId);
   Name += ">";
 
   mangleSourceName(Name);
+
+  // If the context of a closure type is an initializer for a class
+  // member (static or nonstatic), it is encoded in a qualified name.
+  if (LambdaManglingNumber && LambdaContextDecl) {
+if ((isa(LambdaContextDecl) ||
+ isa(LambdaContextDecl)) &&
+LambdaContextDecl->getDeclContext()->isRecord()) {
+  mangleUnqualifiedName(cast(LambdaContextDecl));
+}
+  }
   break;
 }
   }
@@ -937,16 +958,22 @@

r288295 - Clean up CGObjCMac's APIs for deriving class references. NFC.

2016-11-30 Thread John McCall via cfe-commits
Author: rjmccall
Date: Wed Nov 30 17:54:50 2016
New Revision: 288295

URL: http://llvm.org/viewvc/llvm-project?rev=288295=rev
Log:
Clean up CGObjCMac's APIs for deriving class references.  NFC.

Modified:
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.h

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=288295=288294=288295=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Nov 30 17:54:50 2016
@@ -560,11 +560,6 @@ public:
   llvm::Constant *BuildByrefLayout(CodeGenModule , QualType T) override {
 return NULLPtr;
   }
-
-  llvm::GlobalVariable *GetClassGlobal(StringRef Name,
-   bool Weak = false) override {
-return nullptr;
-  }
 };
 
 /// Class representing the legacy GCC Objective-C ABI.  This is the default 
when

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=288295=288294=288295=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Nov 30 17:54:50 2016
@@ -1360,13 +1360,6 @@ public:
   llvm::Value *EmitIvarOffset(CodeGen::CodeGenFunction ,
   const ObjCInterfaceDecl *Interface,
   const ObjCIvarDecl *Ivar) override;
-
-  /// GetClassGlobal - Return the global variable for the Objective-C
-  /// class of the given name.
-  llvm::GlobalVariable *GetClassGlobal(StringRef Name,
-   bool Weak = false) override {
-llvm_unreachable("CGObjCMac::GetClassGlobal");
-  }
 };
 
 class CGObjCNonFragileABIMac : public CGObjCCommonMac {
@@ -1409,12 +1402,12 @@ private:
   unsigned InstanceStart,
   unsigned InstanceSize,
   const ObjCImplementationDecl 
*ID);
-  llvm::GlobalVariable * BuildClassMetaData(const std::string ,
-llvm::Constant *IsAGV,
-llvm::Constant *SuperClassGV,
-llvm::Constant *ClassRoGV,
-bool HiddenVisibility,
-bool Weak);
+  llvm::GlobalVariable *BuildClassObject(const ObjCInterfaceDecl *CI,
+ bool isMetaclass,
+ llvm::Constant *IsAGV,
+ llvm::Constant *SuperClassGV,
+ llvm::Constant *ClassRoGV,
+ bool HiddenVisibility);
 
   void emitMethodConstant(ConstantArrayBuilder ,
 const ObjCMethodDecl *MD,
@@ -1465,8 +1458,12 @@ private:
   
   /// GetClassGlobal - Return the global variable for the Objective-C
   /// class of the given name.
-  llvm::GlobalVariable *GetClassGlobal(StringRef Name,
-   bool Weak = false) override;
+  llvm::Constant *GetClassGlobal(StringRef Name,
+ ForDefinition_t IsForDefinition,
+ bool Weak = false, bool DLLImport = false);
+  llvm::Constant *GetClassGlobal(const ObjCInterfaceDecl *ID,
+ bool isMetaclass,
+ ForDefinition_t isForDefinition);
 
   /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
   /// for the given class reference.
@@ -1474,7 +1471,7 @@ private:
 const ObjCInterfaceDecl *ID);
   
   llvm::Value *EmitClassRefFromId(CodeGenFunction ,
-  IdentifierInfo *II, bool Weak,
+  IdentifierInfo *II,
   const ObjCInterfaceDecl *ID);
 
   llvm::Value *EmitNSAutoreleasePoolClassRef(CodeGenFunction ) override;
@@ -1504,7 +1501,7 @@ private:
   /// GetInterfaceEHType - Get the cached ehtype for the given Objective-C
   /// interface. The return value has type EHTypePtrTy.
   llvm::Constant *GetInterfaceEHType(const ObjCInterfaceDecl *ID,
-  bool ForDefinition);
+ ForDefinition_t IsForDefinition);
 
   StringRef getMetaclassSymbolPrefix() const { return "OBJC_METACLASS_$_"; }
 
@@ -1902,7 +1899,7 @@ llvm::Constant *CGObjCNonFragileABIMac::
   std::string str = 
 StringClass.empty() ? "OBJC_CLASS_$_NSConstantString" 
 : "OBJC_CLASS_$_" + StringClass;
-  auto GV = GetClassGlobal(str);
+  auto GV = 

[PATCH] D27284: [ClangTidy] Add new performance-type-promotion-in-math-fn check.

2016-11-30 Thread Justin Lebar via Phabricator via cfe-commits
jlebar updated this revision to Diff 79835.
jlebar marked an inline comment as done.
jlebar added a comment.

Note that the relevant functions may come from .


https://reviews.llvm.org/D27284

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst
  clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp

Index: clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
@@ -0,0 +1,321 @@
+// RUN: %check_clang_tidy %s performance-type-promotion-in-math-fn %t
+
+double acos(double);
+double acosh(double);
+double asin(double);
+double asinh(double);
+double atan2(double);
+double atan(double);
+double atanh(double);
+double cbrt(double);
+double ceil(double);
+double copysign(double, double);
+double cos(double);
+double cosh(double);
+double erfc(double);
+double erf(double);
+double exp2(double);
+double exp(double);
+double expm1(double);
+double fabs(double);
+double fdim(double, double);
+double floor(double);
+double fma(double, double, double);
+double fmax(double, double);
+double fmin(double, double);
+double fmod(double, double);
+double frexp(double, int *);
+double hypot(double, double);
+double ilogb(double);
+double ldexp(double, double);
+double lgamma(double);
+long long llrint(double);
+double log10(double);
+double log1p(double);
+double log2(double);
+double logb(double);
+double log(double);
+long lrint(double);
+double modf(double);
+double nearbyint(double);
+double nextafter(double, double);
+double nexttoward(double, long double);
+double pow(double, double);
+double remainder(double, double);
+double remquo(double, double, int *);
+double rint(double);
+double round(double);
+double scalbln(double, long);
+double scalbn(double, int);
+double sin(double);
+double sinh(double);
+double sqrt(double);
+double tan(double);
+double tanh(double);
+double tgamma(double);
+double trunc(double);
+long long llround(double);
+long lround(double);
+
+void check_all_fns() {
+  float a, b, c;
+  int i;
+  long l;
+  int *int_ptr;
+
+  acos(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'acos' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  acosf(a);{{$}}
+  acosh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'acosh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  acoshf(a);{{$}}
+  asin(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'asin' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  asinf(a);{{$}}
+  asinh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'asinh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  asinhf(a);{{$}}
+  atan2(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atan2' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  atan2f(a);{{$}}
+  atan(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atan' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  atanf(a);{{$}}
+  atanh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atanh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  atanhf(a);{{$}}
+  cbrt(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cbrt' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  cbrtf(a);{{$}}
+  ceil(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'ceil' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  ceilf(a);{{$}}
+  copysign(a, b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'copysign' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  copysignf(a, b);{{$}}
+  cos(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cos' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  cosf(a);{{$}}
+  cosh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cosh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  coshf(a);{{$}}
+  erf(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'erf' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  erff(a);{{$}}
+  erfc(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'erfc' promotes float to 

[PATCH] D27284: [ClangTidy] Add new performance-type-promotion-in-math-fn check.

2016-11-30 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst:6
+
+Finds calls to math.h functions with implicit float to double promotions.
+

jlebar wrote:
> Eugene.Zelenko wrote:
> > Please enclose math.h, float and double into ``.
> > 
> > Will be good idea to mention cmath too.
> > Please enclose math.h, float and double into ``.
> 
> Done.  I used two backticks, I hope that's the right thing.
> 
> > Will be good idea to mention cmath too.
> 
> What about cmath, exactly?
cmath is proper C++ header for math functions prototypes.


https://reviews.llvm.org/D27284



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


[PATCH] D27284: [ClangTidy] Add new performance-type-promotion-in-math-fn check.

2016-11-30 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst:6
+
+Finds calls to math.h functions with implicit float to double promotions.
+

Eugene.Zelenko wrote:
> Please enclose math.h, float and double into ``.
> 
> Will be good idea to mention cmath too.
> Please enclose math.h, float and double into ``.

Done.  I used two backticks, I hope that's the right thing.

> Will be good idea to mention cmath too.

What about cmath, exactly?


https://reviews.llvm.org/D27284



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


[PATCH] D27284: [ClangTidy] Add new performance-type-promotion-in-math-fn check.

2016-11-30 Thread Justin Lebar via Phabricator via cfe-commits
jlebar updated this revision to Diff 79829.
jlebar marked 3 inline comments as done.
jlebar added a comment.

Formatting fixes in documentation.


https://reviews.llvm.org/D27284

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst
  clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp

Index: clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
@@ -0,0 +1,321 @@
+// RUN: %check_clang_tidy %s performance-type-promotion-in-math-fn %t
+
+double acos(double);
+double acosh(double);
+double asin(double);
+double asinh(double);
+double atan2(double);
+double atan(double);
+double atanh(double);
+double cbrt(double);
+double ceil(double);
+double copysign(double, double);
+double cos(double);
+double cosh(double);
+double erfc(double);
+double erf(double);
+double exp2(double);
+double exp(double);
+double expm1(double);
+double fabs(double);
+double fdim(double, double);
+double floor(double);
+double fma(double, double, double);
+double fmax(double, double);
+double fmin(double, double);
+double fmod(double, double);
+double frexp(double, int *);
+double hypot(double, double);
+double ilogb(double);
+double ldexp(double, double);
+double lgamma(double);
+long long llrint(double);
+double log10(double);
+double log1p(double);
+double log2(double);
+double logb(double);
+double log(double);
+long lrint(double);
+double modf(double);
+double nearbyint(double);
+double nextafter(double, double);
+double nexttoward(double, long double);
+double pow(double, double);
+double remainder(double, double);
+double remquo(double, double, int *);
+double rint(double);
+double round(double);
+double scalbln(double, long);
+double scalbn(double, int);
+double sin(double);
+double sinh(double);
+double sqrt(double);
+double tan(double);
+double tanh(double);
+double tgamma(double);
+double trunc(double);
+long long llround(double);
+long lround(double);
+
+void check_all_fns() {
+  float a, b, c;
+  int i;
+  long l;
+  int *int_ptr;
+
+  acos(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'acos' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  acosf(a);{{$}}
+  acosh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'acosh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  acoshf(a);{{$}}
+  asin(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'asin' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  asinf(a);{{$}}
+  asinh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'asinh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  asinhf(a);{{$}}
+  atan2(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atan2' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  atan2f(a);{{$}}
+  atan(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atan' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  atanf(a);{{$}}
+  atanh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atanh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  atanhf(a);{{$}}
+  cbrt(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cbrt' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  cbrtf(a);{{$}}
+  ceil(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'ceil' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  ceilf(a);{{$}}
+  copysign(a, b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'copysign' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  copysignf(a, b);{{$}}
+  cos(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cos' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  cosf(a);{{$}}
+  cosh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cosh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  coshf(a);{{$}}
+  erf(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'erf' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  erff(a);{{$}}
+  erfc(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'erfc' promotes float to double 

[PATCH] D27284: [ClangTidy] Add new performance-type-promotion-in-math-fn check.

2016-11-30 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please mention this check in docs/ReleaseNotes.rst (in alphabetical order).




Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst:6
+
+Finds calls to math.h functions with implicit float to double promotions.
+

Please enclose math.h, float and double into ``.

Will be good idea to mention cmath too.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst:8
+
+For example, warns on `::sin(0.f)`, because this funciton's parameter is a
+double.  You probably meant to call `::sinf(0.f)`, or maybe `std::sin(0.f)`.

Please enclose functions into ``. Same in other places.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst:9
+For example, warns on `::sin(0.f)`, because this funciton's parameter is a
+double.  You probably meant to call `::sinf(0.f)`, or maybe `std::sin(0.f)`.

Please fix double space.


https://reviews.llvm.org/D27284



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


r288289 - Introduce a type-safe enum for ForDefinition.

2016-11-30 Thread John McCall via cfe-commits
Author: rjmccall
Date: Wed Nov 30 17:25:13 2016
New Revision: 288289

URL: http://llvm.org/viewvc/llvm-project?rev=288289=rev
Log:
Introduce a type-safe enum for ForDefinition.

Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ModuleBuilder.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=288289=288288=288289=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Wed Nov 30 17:25:13 2016
@@ -218,7 +218,7 @@ llvm::Function *CodeGenModule::codegenCX
   getTypes().arrangeCXXStructorDeclaration(MD, Type);
   auto *Fn = cast(
   getAddrOfCXXStructor(MD, Type, , /*FnType=*/nullptr,
-   /*DontDefer=*/true, /*IsForDefinition=*/true));
+   /*DontDefer=*/true, ForDefinition));
 
   GlobalDecl GD;
   if (const auto *DD = dyn_cast(MD)) {
@@ -239,7 +239,8 @@ llvm::Function *CodeGenModule::codegenCX
 
 llvm::Constant *CodeGenModule::getAddrOfCXXStructor(
 const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo,
-llvm::FunctionType *FnType, bool DontDefer, bool IsForDefinition) {
+llvm::FunctionType *FnType, bool DontDefer,
+ForDefinition_t IsForDefinition) {
   GlobalDecl GD;
   if (auto *CD = dyn_cast(MD)) {
 GD = GlobalDecl(CD, toCXXCtorType(Type));

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=288289=288288=288289=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Nov 30 17:25:13 2016
@@ -1296,7 +1296,7 @@ void CodeGenModule::EmitDeferred() {
 // might had been created for another decl with the same mangled name but
 // different type.
 llvm::GlobalValue *GV = dyn_cast(
-GetAddrOfGlobal(D, /*IsForDefinition=*/true));
+GetAddrOfGlobal(D, ForDefinition));
 
 // In case of different address spaces, we may still get a cast, even with
 // IsForDefinition equal to true. Query mangled names table to get
@@ -1864,7 +1864,7 @@ CodeGenModule::GetOrCreateLLVMFunction(S
GlobalDecl GD, bool ForVTable,
bool DontDefer, bool IsThunk,
llvm::AttributeSet ExtraAttrs,
-   bool IsForDefinition) {
+   ForDefinition_t IsForDefinition) {
   const Decl *D = GD.getDecl();
 
   // Lookup the entry, lazily creating it if necessary.
@@ -2024,7 +2024,7 @@ llvm::Constant *CodeGenModule::GetAddrOf
  llvm::Type *Ty,
  bool ForVTable,
  bool DontDefer,
- bool IsForDefinition) {
+  ForDefinition_t IsForDefinition) 
{
   // If there was no specific requested type, just convert it now.
   if (!Ty) {
 const auto *FD = cast(GD.getDecl());
@@ -2103,7 +2103,7 @@ llvm::Constant *
 CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
  llvm::PointerType *Ty,
  const VarDecl *D,
- bool IsForDefinition) {
+ ForDefinition_t IsForDefinition) {
   // Lookup the entry, lazily creating it if necessary.
   llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
   if (Entry) {
@@ -2218,7 +2218,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str
 
 llvm::Constant *
 CodeGenModule::GetAddrOfGlobal(GlobalDecl GD,
-   bool IsForDefinition) {
+   ForDefinition_t IsForDefinition) {
   if (isa(GD.getDecl()))
 return getAddrOfCXXStructor(cast(GD.getDecl()),
 getFromCtorType(GD.getCtorType()),
@@ -2295,7 +2295,7 @@ CodeGenModule::CreateOrReplaceCXXRuntime
 /// variable with the same mangled name but some other type.
 llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D,
   llvm::Type *Ty,
-  bool IsForDefinition) {
+   ForDefinition_t IsForDefinition) {
   assert(D->hasGlobalStorage() && "Not a global variable");
   QualType ASTTy = D->getType();
   if (!Ty)
@@ -2485,7 +2485,7 @@ void CodeGenModule::EmitGlobalVarDefinit
 
   llvm::Type* InitType = Init->getType();
   llvm::Constant *Entry =
-  GetAddrOfGlobalVar(D, InitType, 

[PATCH] D27066: Fix crash with unsupported architectures in Linux/Gnu target triples.

2016-11-30 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg accepted this revision.
joerg added a reviewer: joerg.
joerg added a comment.

LGTM with a small cleanup.




Comment at: lib/Driver/Tools.cpp:10018
+  const char *LDMOption = getLDMOption(ToolChain.getTriple(), Args);
+  if (!LDMOption) {
+D.Diag(diag::err_target_unknown_triple) << Triple.str();

Please write this as
```
   if (const char *LDMOption = ...) {
 ...
  } else {
 D.Diag(...);
 return;
  }
```


https://reviews.llvm.org/D27066



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


Re: r288269 - Finish adopting ConstantInitBuilder in CGObjCGNU. NFC.

2016-11-30 Thread Reid Kleckner via cfe-commits
So, I always push for leading upper case variable names. Over time we've
gotten to the point where the majority of the code that I read in clang
follows this convention. You seem to be pushing the other direction. What
do you think we should be doing?

I'll admit the LLVM naming conventions are dumb, but I just don't care
anymore, and would rather have it all look the same.
http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

I only mention it because you're modifying code that was clearly in the
leading uppercase camp to leading lower case, so you weren't fitting into
an existing style common to some local source file.

On Wed, Nov 30, 2016 at 12:19 PM, John McCall via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rjmccall
> Date: Wed Nov 30 14:19:46 2016
> New Revision: 288269
>
> URL: http://llvm.org/viewvc/llvm-project?rev=288269=rev
> Log:
> Finish adopting ConstantInitBuilder in CGObjCGNU.  NFC.
>
> Modified:
> cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> cfe/trunk/lib/CodeGen/ConstantBuilder.h
>
> Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
> CGObjCGNU.cpp?rev=288269=288268=288269=diff
> 
> ==
> --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Nov 30 14:19:46 2016
> @@ -164,9 +164,8 @@ protected:
>/// Helper function that generates a constant string and returns a
> pointer to
>/// the start of the string.  The result of this function can be used
> anywhere
>/// where the C code specifies const char*.
> -  llvm::Constant *MakeConstantString(const std::string ,
> - const std::string ="") {
> -ConstantAddress Array = CGM.GetAddrOfConstantCString(Str,
> Name.c_str());
> +  llvm::Constant *MakeConstantString(StringRef Str, const char *Name =
> "") {
> +ConstantAddress Array = CGM.GetAddrOfConstantCString(Str, Name);
>  return llvm::ConstantExpr::getGetElementPtr(Array.getElementType(),
>  Array.getPointer(),
> Zeros);
>}
> @@ -1530,23 +1529,24 @@ GenerateMethodList(StringRef ClassName,
>MethodList.addInt(Int32Ty, MethodTypes.size());
>
>// Get the method structure type.
> -  llvm::StructType *ObjCMethodTy = llvm::StructType::get(
> -PtrToInt8Ty, // Really a selector, but the runtime creates it us.
> -PtrToInt8Ty, // Method types
> -IMPTy, //Method pointer
> -nullptr);
> +  llvm::StructType *ObjCMethodTy =
> +llvm::StructType::get(CGM.getLLVMContext(), {
> +  PtrToInt8Ty, // Really a selector, but the runtime creates it us.
> +  PtrToInt8Ty, // Method types
> +  IMPTy// Method pointer
> +});
>auto Methods = MethodList.beginArray();
>for (unsigned int i = 0, e = MethodTypes.size(); i < e; ++i) {
> -llvm::Constant *Method =
> +llvm::Constant *FnPtr =
>TheModule.getFunction(SymbolNameForMethod(ClassName, CategoryName,
>  MethodSels[i],
>  isClassMethodList));
> -assert(Method && "Can't generate metadata for method that doesn't
> exist");
> -llvm::Constant *C = MakeConstantString(MethodSels[i].getAsString());
> -Method = llvm::ConstantExpr::getBitCast(Method,
> -IMPTy);
> -Methods.add(
> -llvm::ConstantStruct::get(ObjCMethodTy, {C, MethodTypes[i],
> Method}));
> +assert(FnPtr && "Can't generate metadata for method that doesn't
> exist");
> +auto Method = Methods.beginStruct(ObjCMethodTy);
> +Method.add(MakeConstantString(MethodSels[i].getAsString()));
> +Method.add(MethodTypes[i]);
> +Method.addBitCast(FnPtr, IMPTy);
> +Method.finishAndAddTo(Methods);
>}
>Methods.finishAndAddTo(MethodList);
>
> @@ -1644,7 +1644,7 @@ llvm::Constant *CGObjCGNU::GenerateClass
>// Fill in the structure
>
>// isa
> -  Elements.add(llvm::ConstantExpr::getBitCast(MetaClass, PtrToInt8Ty));
> +  Elements.addBitCast(MetaClass, PtrToInt8Ty);
>// super_class
>Elements.add(SuperClass);
>// name
> @@ -1673,7 +1673,7 @@ llvm::Constant *CGObjCGNU::GenerateClass
>// sibling_class
>Elements.add(NULLPtr);
>// protocols
> -  Elements.add(llvm::ConstantExpr::getBitCast(Protocols, PtrTy));
> +  Elements.addBitCast(Protocols, PtrTy);
>// gc_object_type
>Elements.add(NULLPtr);
>// abi_version
> @@ -1746,9 +1746,7 @@ CGObjCGNU::GenerateProtocolList(ArrayRef
>  } else {
>protocol = value->getValue();
>  }
> -llvm::Constant *Ptr = llvm::ConstantExpr::getBitCast(protocol,
> -   PtrToInt8Ty);
> -Elements.add(Ptr);
> +Elements.addBitCast(protocol, PtrToInt8Ty);
>}
>Elements.finishAndAddTo(ProtocolList);
>return 

r288287 - Fix some layering violations where CGObjCMac's NSString emission was

2016-11-30 Thread John McCall via cfe-commits
Author: rjmccall
Date: Wed Nov 30 17:15:55 2016
New Revision: 288287

URL: http://llvm.org/viewvc/llvm-project?rev=288287=rev
Log:
Fix some layering violations where CGObjCMac's NSString emission was
performed at the CodeGenModule level.

Would be NFC except we now also use a different uniquing structure so
that we don't get spurious conflicts if you ask for both an NSString
and a CFString for the same content (which is possible with builtins).

Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=288287=288286=288287=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Nov 30 17:15:55 2016
@@ -888,6 +888,15 @@ protected:
   /// DefinedNonLazyCategories - List of defined "non-lazy" categories.
   SmallVector DefinedNonLazyCategories;
 
+  /// Cached reference to the class for constant strings. This value has type
+  /// int * but is actually an Obj-C class pointer.
+  llvm::WeakVH ConstantStringClassRef;
+
+  /// \brief The LLVM type corresponding to NSConstantString.
+  llvm::StructType *NSConstantStringType = nullptr;
+
+  llvm::StringMap NSConstantStringMap;
+
   /// GetNameForMethod - Return a name for the given method.
   /// \param[out] NameOut - The return value.
   void GetNameForMethod(const ObjCMethodDecl *OMD,
@@ -1054,6 +1063,7 @@ public:
   }
 
   ConstantAddress GenerateConstantString(const StringLiteral *SL) override;
+  ConstantAddress GenerateConstantNSString(const StringLiteral *SL);
 
   llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
  const ObjCContainerDecl *CD=nullptr) override;
@@ -1070,6 +1080,9 @@ public:
   /// forward references will be filled in with empty bodies if no
   /// definition is seen. The return value has type ProtocolPtrTy.
   virtual llvm::Constant *GetOrEmitProtocolRef(const ObjCProtocolDecl *PD)=0;
+
+  virtual llvm::Constant *getNSConstantStringClassRef() = 0;
+
   llvm::Constant *BuildGCBlockLayout(CodeGen::CodeGenModule ,
  const CGBlockInfo ) override;
   llvm::Constant *BuildRCBlockLayout(CodeGen::CodeGenModule ,
@@ -1266,6 +1279,8 @@ private:
 public:
   CGObjCMac(CodeGen::CodeGenModule );
 
+  llvm::Constant *getNSConstantStringClassRef() override;
+
   llvm::Function *ModuleInitFunction() override;
 
   CodeGen::RValue GenerateMessageSend(CodeGen::CodeGenFunction ,
@@ -1536,7 +1551,9 @@ private:
 
 public:
   CGObjCNonFragileABIMac(CodeGen::CodeGenModule );
-  // FIXME. All stubs for now!
+
+  llvm::Constant *getNSConstantStringClassRef() override;
+
   llvm::Function *ModuleInitFunction() override;
 
   CodeGen::RValue GenerateMessageSend(CodeGen::CodeGenFunction ,
@@ -1846,11 +1863,115 @@ llvm::Constant *CGObjCMac::GetEHType(Qua
};
 */
 
-ConstantAddress CGObjCCommonMac::GenerateConstantString(
-  const StringLiteral *SL) {
-  return (CGM.getLangOpts().NoConstantCFStrings == 0 ? 
-  CGM.GetAddrOfConstantCFString(SL) :
-  CGM.GetAddrOfConstantString(SL));
+ConstantAddress
+CGObjCCommonMac::GenerateConstantString(const StringLiteral *SL) {
+  return (!CGM.getLangOpts().NoConstantCFStrings
+? CGM.GetAddrOfConstantCFString(SL)
+: GenerateConstantNSString(SL));
+}
+
+static llvm::StringMapEntry &
+GetConstantStringEntry(llvm::StringMap ,
+   const StringLiteral *Literal, unsigned ) {
+  StringRef String = Literal->getString();
+  StringLength = String.size();
+  return *Map.insert(std::make_pair(String, nullptr)).first;
+}
+
+llvm::Constant *CGObjCMac::getNSConstantStringClassRef() {
+  if (llvm::Value *V = ConstantStringClassRef)
+return cast(V);
+
+  auto  = CGM.getLangOpts().ObjCConstantStringClass;
+  std::string str =
+StringClass.empty() ? "_NSConstantStringClassReference"
+: "_" + StringClass + "ClassReference";
+
+  llvm::Type *PTy = llvm::ArrayType::get(CGM.IntTy, 0);
+  auto GV = CGM.CreateRuntimeVariable(PTy, str);
+  auto V = llvm::ConstantExpr::getBitCast(GV, CGM.IntTy->getPointerTo());
+  ConstantStringClassRef = V;
+  return V;
+}
+
+llvm::Constant *CGObjCNonFragileABIMac::getNSConstantStringClassRef() {
+  if (llvm::Value *V = ConstantStringClassRef)
+return cast(V);
+
+  auto  = CGM.getLangOpts().ObjCConstantStringClass;
+  std::string str = 
+StringClass.empty() ? "OBJC_CLASS_$_NSConstantString" 
+: "OBJC_CLASS_$_" + StringClass;
+  auto GV = GetClassGlobal(str);
+
+  // Make sure the result is of the correct type.
+  auto V = llvm::ConstantExpr::getBitCast(GV, CGM.IntTy->getPointerTo());
+
+  ConstantStringClassRef = V;
+  return V;
+}
+
+ConstantAddress

[PATCH] D27066: Fix crash with unsupported architectures in Linux/Gnu target triples.

2016-11-30 Thread Eric Christopher via Phabricator via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

LGTM.

Thanks!


https://reviews.llvm.org/D27066



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


[PATCH] D27284: [ClangTidy] Add new performance-type-promotion-in-math-fn check.

2016-11-30 Thread Justin Lebar via Phabricator via cfe-commits
jlebar created this revision.
jlebar added a subscriber: cfe-commits.
Herald added a subscriber: mgorny.

This checks for calls to double-precision math.h with single-precision
arguments.  For example, it suggests replacing ::sin(0.f) with
::sinf(0.f).


https://reviews.llvm.org/D27284

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst
  clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp

Index: clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
@@ -0,0 +1,321 @@
+// RUN: %check_clang_tidy %s performance-type-promotion-in-math-fn %t
+
+double acos(double);
+double acosh(double);
+double asin(double);
+double asinh(double);
+double atan2(double);
+double atan(double);
+double atanh(double);
+double cbrt(double);
+double ceil(double);
+double copysign(double, double);
+double cos(double);
+double cosh(double);
+double erfc(double);
+double erf(double);
+double exp2(double);
+double exp(double);
+double expm1(double);
+double fabs(double);
+double fdim(double, double);
+double floor(double);
+double fma(double, double, double);
+double fmax(double, double);
+double fmin(double, double);
+double fmod(double, double);
+double frexp(double, int *);
+double hypot(double, double);
+double ilogb(double);
+double ldexp(double, double);
+double lgamma(double);
+long long llrint(double);
+double log10(double);
+double log1p(double);
+double log2(double);
+double logb(double);
+double log(double);
+long lrint(double);
+double modf(double);
+double nearbyint(double);
+double nextafter(double, double);
+double nexttoward(double, long double);
+double pow(double, double);
+double remainder(double, double);
+double remquo(double, double, int *);
+double rint(double);
+double round(double);
+double scalbln(double, long);
+double scalbn(double, int);
+double sin(double);
+double sinh(double);
+double sqrt(double);
+double tan(double);
+double tanh(double);
+double tgamma(double);
+double trunc(double);
+long long llround(double);
+long lround(double);
+
+void check_all_fns() {
+  float a, b, c;
+  int i;
+  long l;
+  int *int_ptr;
+
+  acos(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'acos' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  acosf(a);{{$}}
+  acosh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'acosh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  acoshf(a);{{$}}
+  asin(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'asin' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  asinf(a);{{$}}
+  asinh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'asinh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  asinhf(a);{{$}}
+  atan2(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atan2' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  atan2f(a);{{$}}
+  atan(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atan' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  atanf(a);{{$}}
+  atanh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atanh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  atanhf(a);{{$}}
+  cbrt(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cbrt' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  cbrtf(a);{{$}}
+  ceil(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'ceil' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  ceilf(a);{{$}}
+  copysign(a, b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'copysign' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  copysignf(a, b);{{$}}
+  cos(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cos' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  cosf(a);{{$}}
+  cosh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cosh' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  coshf(a);{{$}}
+  erf(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'erf' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  erff(a);{{$}}
+  

Request for review/commit

2016-11-30 Thread Eric van Gyzen via cfe-commits
I recently posted a few libc++ patches in Phabricator.  I'm fairly new
here, so I would be grateful if someone would review and eventually
commit them.

[libc++] Add validation to Stage 2 of num_get
https://reviews.llvm.org/D26920

[libc++] Do not hard-code locale data in unit tests: get it from the OS
instead
https://reviews.llvm.org/D26979

[libc++] Support multibyte decimal_point and thousands_sep
https://reviews.llvm.org/D27167

Kind regards,

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


[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-30 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Looks good. Apart from some nitpicks, I'm happy with this. This isn't really my 
area so it'd be good to get an explicit lgtm from one of the reviewers.




Comment at: tools/clang-import-test/CMakeLists.txt:7
+  clang-import-test.cpp
+  )
+

@beanz recently went on a crusade to add dependencies to intrinsics_gen to a 
bunch of stuff. Chances are, this tool probably depends on intrinsics_gen, so 
I'd look into that and add the dep if needed.



Comment at: tools/clang-import-test/clang-import-test.cpp:306
+  std::transform(ImportCIs.begin(), ImportCIs.end(), UnownedCIs.begin(),
+ std::mem_fn(::unique_ptr::get));
+  llvm::Expected ExpressionCI =

This transform smells a little strange. I'd rather see 
`ArrayRef>` used everywhere, through a typedef/using-decl 
if necessary.



Comment at: tools/clang-import-test/clang-import-test.cpp:310
+  if (auto E = ExpressionCI.takeError()) {
+llvm::errs() << (llvm::toString(std::move(E)));
+exit(-1);

There are redundant parens around your calls to toString(): I think these 
should be dropped.


Repository:
  rL LLVM

https://reviews.llvm.org/D27180



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


[PATCH] D25216: Improve error message when referencing a non-tag type with a tag

2016-11-30 Thread Richard Smith via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:4556-4558
+  "%0 is a %select{non-tag type|typedef|type alias|template|type alias "
+  "template|template template argument}1 that cannot be referenced with a "
+  "%select{struct|interface|union|class|enum}2 tag">;

"tag" is C terminology that C++ doesn't share;  "specifier" would be correct in 
both languages.

Also, this wording suggests that *some* templates / template template arguments 
/ ... can be referenced by, say, a `struct` specifier. How about:

  %select{non-struct type|non-class type|non-union type|non-enum 
type|typedef|type alias|template|[...]}1 %0 cannot be referenced with 
%select{struct|interface|union|class|enum}2 specifier

(where we use "non-enum type" when the tag is `enum`, "non-union type" when the 
tag is `union`, and otherwise use "non-struct type" in C and "non-class type" 
in C++)?


https://reviews.llvm.org/D25216



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


[PATCH] D25475: [analyzer] Add a new SVal to support pointer-to-member operations.

2016-11-30 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin added a comment.

PointerToMemberData looks like it is on the right track! One thing that is 
still missing is using the base specifier list to figure out the correct 
subobject field to read and write from. This is important when there is 
non-virtual multiple inheritance, as there will be multiple copies of the same 
field in the same object.

Here are is an example where the current patch is not quite right; both of 
these should evaluate to true:

  void clang_analyzer_eval(int);
  
  struct B {
int f;
  };
  struct L1 : public B { };
  struct R1 : public B { };
  struct M : public L1, R1 { };
  struct L2 : public M { };
  struct R2 : public M { };
  struct D2 : public L2, R2 { };
  
  
  void diamond() {
M m;
  
static_cast()->f = 7;
static_cast()->f = 16;
  
int L1::* pl1 = ::f;
int M::* pm_via_l1 = pl1;
  
int R1::* pr1 = ::f;
int M::* pm_via_r1 = pr1;
  
clang_analyzer_eval(m.*(pm_via_l1) == 7); // expected-warning {{TRUE}}
clang_analyzer_eval(m.*(pm_via_r1) == 16); // expected-warning {{TRUE}}
  }

I suspect you'll need to do something similar to what 
StoreManager::evalDerivedToBase() does (or maybe just use that function) to 
figure out the correct location to read and write from when accessing via a 
pointer to member.

It would also be good to add some tests for the double diamond scenario to 
ensure the list of path specifiers is constructed in the right order. For 
example:

  void double_diamond() {
D2 d2;
  
static_cast(static_cast())->f = 1;
static_cast(static_cast())->f = 2;
static_cast(static_cast())->f = 3;
static_cast(static_cast())->f = 4;
  
clang_analyzer_eval(d2.*(static_cast(static_cast(static_cast(::f == 1); // expected-warning {{TRUE}}
clang_analyzer_eval(d2.*(static_cast(static_cast(static_cast(::f == 2); // expected-warning {{TRUE}}
clang_analyzer_eval(d2.*(static_cast(static_cast(static_cast(::f == 3); // expected-warning {{TRUE}}
clang_analyzer_eval(d2.*(static_cast(static_cast(static_cast(::f == 4); // expected-warning {{TRUE}}
  }




Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:217
+
+  llvm::ImmutableList consCXXBase(
+  const CXXBaseSpecifier *CBS,

NoQ wrote:
> Hmm, is it "construct"? Or "constrain"? I think a verbose name wouldn't hurt.
> In fact, i suspect that `consVals` are rather `conSVals`, where `con` stands 
> for "concatenate".
In functional paradigms, 'cons' is used to mean prepending an item the the 
beginning of a linked list. https://en.wikipedia.org/wiki/Cons

In my opinion, 'prepend' is better than 'cons', which I find super-confusing. I 
don't think 'concatenate' is quite right, since typically that operation 
combines two (or more) lists. 



Comment at: lib/StaticAnalyzer/Core/ExprEngineC.cpp:322
+  Bldr.generateNode(CastE, Pred, state);
+  continue;
+}

These conditional fallthroughs make me very, very uncomfortable because they 
will broken if any of the intervening cases get special handling in the future.

I think it would safer to factor out code in the "destination" case (here 
'CK_LValueBitCast') into a function, call it directly, and then continue 
regardless of the branch.

Another possibility is to use gotos to directly jump to the default 
'destination' case.



Comment at: lib/StaticAnalyzer/Core/ExprEngineC.cpp:472
+}
+// If getAs failed just fall through to default behaviour.
+  }

I think it would be good to be explicit about this fallthrough behavior, as 
well.



Comment at: lib/StaticAnalyzer/Core/ExprEngineC.cpp:899
+case UO_AddrOf: {
+  // Process pointer-to-member address operation
+  const Expr *Ex = U->getSubExpr()->IgnoreParens();

Just sticking this in the middle of a fallthrough cascade seems quite brittle. 
For example, it relies on the sub expression of a unary deref never being a 
DeclRefExpr to a field. This may be guaranteed by Sema (?) but if so it is 
quite a non-obvious invariant to rely upon.

I think it would be better the restructure this so that the AddrOf case doesn't 
fall in the the middle of a fallthrough cascade. You could either factor out 
the default behavior into a function or use a goto.



Comment at: lib/StaticAnalyzer/Core/SValBuilder.cpp:298
 
+  case Stmt::UnaryOperatorClass: {
+const UnaryOperator *UO = dyn_cast(E);

Can this be removed? There are no tests for it.


https://reviews.llvm.org/D25475



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


[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-30 Thread Sean Callanan via Phabricator via cfe-commits
spyffe updated this revision to Diff 79807.
spyffe marked an inline comment as done.
spyffe added a comment.

Updated to reflect Vedant's comments.  
Also ensured 100% test coverage, by removing handling for errors that will 
never happen and by adding a few new tests.


Repository:
  rL LLVM

https://reviews.llvm.org/D27180

Files:
  test/Import/clang-flags/Inputs/S.c
  test/Import/clang-flags/test.c
  test/Import/empty-struct/Inputs/S.c
  test/Import/empty-struct/test.c
  test/Import/error-in-expression/Inputs/S.c
  test/Import/error-in-expression/test.c
  test/Import/error-in-import/Inputs/S.c
  test/Import/error-in-import/test.c
  test/Import/missing-import/test.c
  tools/CMakeLists.txt
  tools/clang-import-test/CMakeLists.txt
  tools/clang-import-test/clang-import-test.cpp

Index: tools/clang-import-test/clang-import-test.cpp
===
--- tools/clang-import-test/clang-import-test.cpp
+++ tools/clang-import-test/clang-import-test.cpp
@@ -0,0 +1,315 @@
+//===-- import-test.cpp - ASTImporter/ExternalASTSource testbed ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTImporter.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/ParseAST.h"
+
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/Signals.h"
+
+#include 
+#include 
+
+using namespace clang;
+
+static llvm::cl::opt Expression(
+"expression", llvm::cl::Required,
+llvm::cl::desc("Path to a file containing the expression to parse"));
+
+static llvm::cl::list
+Imports("import", llvm::cl::ZeroOrMore,
+llvm::cl::desc("Path to a file containing declarations to import"));
+
+static llvm::cl::list
+ClangArgs("Xcc", llvm::cl::ZeroOrMore,
+  llvm::cl::desc("Argument to pass to the CompilerInvocation"),
+  llvm::cl::CommaSeparated);
+
+namespace {
+
+class TestDiagnosticConsumer : public DiagnosticConsumer {
+private:
+  std::unique_ptr Passthrough;
+  const LangOptions *LangOpts = nullptr;
+
+public:
+  TestDiagnosticConsumer()
+  : Passthrough(llvm::make_unique()) {}
+
+  virtual void BeginSourceFile(const LangOptions ,
+   const Preprocessor *PP = nullptr) override {
+this->LangOpts = 
+return Passthrough->BeginSourceFile(LangOpts, PP);
+  }
+
+  virtual void EndSourceFile() override {
+this->LangOpts = nullptr;
+Passthrough->EndSourceFile();
+  }
+
+  virtual bool IncludeInDiagnosticCounts() const override {
+return Passthrough->IncludeInDiagnosticCounts();
+  }
+
+private:
+  static void PrintSourceForLocation(const SourceLocation ,
+ SourceManager ) {
+const char *LocData = SM.getCharacterData(Loc, /*Invalid=*/nullptr);
+unsigned LocColumn = SM.getSpellingColumnNumber(Loc, /*Invalid=*/nullptr) - 1;
+FileID FID = SM.getFileID(Loc);
+llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, Loc, /*Invalid=*/nullptr);
+
+assert(LocData >= Buffer->getBufferStart() &&
+   LocData < Buffer->getBufferEnd());
+
+const char *LineBegin = LocData - LocColumn;
+
+assert(LineBegin >= Buffer->getBufferStart());
+
+const char *LineEnd = nullptr;
+
+for (LineEnd = LineBegin; *LineEnd != '\n' && *LineEnd != '\r' &&
+  LineEnd < Buffer->getBufferEnd();
+ ++LineEnd)
+  ;
+
+llvm::StringRef LineString(LineBegin, LineEnd - LineBegin);
+
+llvm::errs() << LineString << '\n';
+std::string Space(LocColumn, ' ');
+llvm::errs() << Space.c_str() << '\n';
+  }
+
+  virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic ) override {
+if (Info.hasSourceManager() && LangOpts) {
+  SourceManager  = Info.getSourceManager();
+
+  if (Info.getLocation().isValid()) {
+Info.getLocation().print(llvm::errs(), SM);
+llvm::errs() << ": ";
+  }
+
+  SmallString<16> DiagText;
+  Info.FormatDiagnostic(DiagText);
+  llvm::errs() << DiagText << '\n';
+
+  if (Info.getLocation().isValid()) {
+PrintSourceForLocation(Info.getLocation(), SM);
+  }
+
+  for (const CharSourceRange  : Info.getRanges()) {
+bool Invalid = true;

[PATCH] D25216: Improve error message when referencing a non-tag type with a tag

2016-11-30 Thread Bob Haarman via Phabricator via cfe-commits
inglorion added a comment.

I like it. I'll give others a little time to respond, but if no objections are 
raised and nobody else accepts first, I'll accept it tomorrow.


https://reviews.llvm.org/D25216



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


[PATCH] D25581: Implement __builtin_alloca_with_align for GCC compatibility

2016-11-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk abandoned this revision.
rnk added a subscriber: majnemer.
rnk added a comment.

@majnemer did this in https://reviews.llvm.org/rL285544


https://reviews.llvm.org/D25581



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


[PATCH] D25216: Improve error message when referencing a non-tag type with a tag

2016-11-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 79805.
rnk added a comment.

- rebase


https://reviews.llvm.org/D25216

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/TreeTransform.h
  test/CXX/basic/basic.lookup/basic.lookup.elab/p2.cpp
  test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp
  test/CXX/drs/dr2xx.cpp
  test/CXX/drs/dr4xx.cpp
  test/CXX/temp/temp.decls/temp.friend/p1.cpp
  test/CXX/temp/temp.spec/no-body.cpp
  test/SemaCXX/PR8755.cpp
  test/SemaCXX/using-decl-templates.cpp
  test/SemaTemplate/template-id-expr.cpp

Index: test/SemaTemplate/template-id-expr.cpp
===
--- test/SemaTemplate/template-id-expr.cpp
+++ test/SemaTemplate/template-id-expr.cpp
@@ -100,5 +100,5 @@
 class C {};
 template  class D>  // expected-note{{previous use is here}}
 class E {
-  template class D;  // expected-error {{elaborated type refers to a template template argument}}
+  template class D;  // expected-error {{'D' is a template template argument that cannot be referenced with a class tag}}
 };
Index: test/SemaCXX/using-decl-templates.cpp
===
--- test/SemaCXX/using-decl-templates.cpp
+++ test/SemaCXX/using-decl-templates.cpp
@@ -90,7 +90,7 @@
   template struct A { };
   template using APtr = A; // expected-note{{previous use is here}}
 
-  template struct APtr; // expected-error{{elaborated type refers to a type alias template}}
+  template struct APtr; // expected-error{{'APtr' is a type alias template that cannot be referenced with a struct tag}}
 }
 
 namespace DontDiagnoseInvalidTest {
Index: test/SemaCXX/PR8755.cpp
===
--- test/SemaCXX/PR8755.cpp
+++ test/SemaCXX/PR8755.cpp
@@ -7,7 +7,7 @@
 
 template 
 void f() {
-  class A  ::iterator foo;  // expected-error{{elaborated type refers to a typedef}}
+  class A  ::iterator foo;  // expected-error{{'iterator' is a typedef that cannot be referenced with a class tag}}
 }
 
 void g() {
Index: test/CXX/temp/temp.spec/no-body.cpp
===
--- test/CXX/temp/temp.spec/no-body.cpp
+++ test/CXX/temp/temp.spec/no-body.cpp
@@ -43,7 +43,7 @@
 
 namespace unsupported {
 #ifndef FIXING
- template struct y; // expected-error {{elaborated type refers to a template}}
+ template struct y; // expected-error {{'y' is a template that cannot be referenced with a struct tag}}
 #endif
 }
 
Index: test/CXX/temp/temp.decls/temp.friend/p1.cpp
===
--- test/CXX/temp/temp.decls/temp.friend/p1.cpp
+++ test/CXX/temp/temp.decls/temp.friend/p1.cpp
@@ -174,7 +174,7 @@
 
   // This shouldn't crash.
   template  class D {
-friend class A; // expected-error {{elaborated type refers to a template}}
+friend class A; // expected-error {{'A' is a template that cannot be referenced with a class tag}}
   };
   template class D;
 }
Index: test/CXX/drs/dr4xx.cpp
===
--- test/CXX/drs/dr4xx.cpp
+++ test/CXX/drs/dr4xx.cpp
@@ -90,7 +90,7 @@
 struct S *p;
 {
   typedef struct S S; // expected-note {{here}}
-  struct S *p; // expected-error {{refers to a typedef}}
+  struct S *p; // expected-error {{'S' is a typedef}}
 }
   }
   struct S {};
Index: test/CXX/drs/dr2xx.cpp
===
--- test/CXX/drs/dr2xx.cpp
+++ test/CXX/drs/dr2xx.cpp
@@ -620,7 +620,7 @@
   template struct A {
 typedef typename T::type type; // ok even if this is a typedef-name, because
// it's not an elaborated-type-specifier
-typedef struct T::type foo; // expected-error {{elaborated type refers to a typedef}}
+typedef struct T::type foo; // expected-error {{'type' is a typedef that cannot be referenced with a struct tag}}
   };
   struct B { struct type {}; };
   struct C { typedef struct {} type; }; // expected-note {{here}}
@@ -1037,8 +1037,8 @@
   C::type i3;
 
   struct A a;
-  struct B b; // expected-error {{refers to a typedef}}
-  struct C c; // expected-error {{refers to a typedef}}
+  struct B b; // expected-error {{'B' is a typedef}}
+  struct C c; // expected-error {{'C' is a typedef}}
 
   B::B() {} // expected-error {{requires a type specifier}}
   B::A() {} // ok
Index: test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp
===
--- test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp
+++ test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp
@@ -2,18 +2,18 @@
 
 struct A { typedef int type; };
 template using X = A; // expected-note {{declared here}}
-struct X* p2; // expected-error {{elaborated type refers to a type alias template}}
+struct X* p2; // expected-error {{'X' 

[PATCH] D25216: Improve error message when referencing a non-tag type with a tag

2016-11-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Ping, found this in my tree. Maybe you weren't that excited about the wording 
change.


https://reviews.llvm.org/D25216



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


[PATCH] D27279: Store decls in prototypes on the declarator instead of in the AST

2016-11-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk created this revision.
rnk added a reviewer: rsmith.
rnk added subscribers: cfe-commits, jmolloy.

This saves two pointers (!) from FunctionDecl that were being used for
some rare and questionable C-only functionality.  The
DeclsInPrototypeScope ArrayRef was added in r151712 in order to parse
this kind of C code:

  enum e {x, y};
  int f(enum {y, x} n) {
   return x; // should return 1, not 0
  }

The challenge is that we parse 'int f(enum {y, x} n)' it its own
function prototype scope that gets popped before we build the
FunctionDecl for 'f'. The original change was doing two questionable
things:

1. Saving all tag decls introduced in prototype scope on a TU-global

Sema variable. This is problematic when you have cases like this, where
'x' and 'y' shouldn't be visible in 'f':

  void f(void (*fp)(enum { x, y } e)) { /* no x */ }

This patch fixes that, so now 'f' can't see 'x', which is consistent
with GCC.

2. Storing the decls in FunctionDecl in ActOnFunctionDeclarator so that

they could be used in ActOnStartOfFunctionDef. This is just an
inefficient way to move information around. The AST lives forever, but
the list of non-parameter decls in prototype scope is short lived. By
moving this stuff to the Declarator, we get the right (short) lifetime.

As the original change was the author's first major Clang patch, they
can be forgiven.


https://reviews.llvm.org/D27279

Files:
  include/clang/AST/Decl.h
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/Sema.h
  lib/AST/ASTDumper.cpp
  lib/AST/Decl.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/Misc/ast-dump-decl.c
  test/PCH/decl-in-prototype.c
  test/Sema/decl-in-prototype.c

Index: test/Sema/decl-in-prototype.c
===
--- test/Sema/decl-in-prototype.c
+++ test/Sema/decl-in-prototype.c
@@ -1,13 +1,19 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
+#define SA(n, c) int arr##n[(c) ? 1 : -1] = {}
+
 const int AA = 5;
 
 int f1(enum {AA,BB} E) { // expected-warning {{will not be visible outside of this function}}
-return BB;
+  SA(1, AA == 0);
+  SA(2, BB == 1);
+  return BB;
 }
 
 int f2(enum {AA=7,BB} E) { // expected-warning {{will not be visible outside of this function}}
-return AA;
+  SA(1, AA == 7);
+  SA(2, BB == 8);
+  return AA;
 }
 
 struct a {
@@ -38,3 +44,11 @@
 
 // Only warn once, even if we create two declarations.
 void f(struct q *, struct __attribute__((aligned(4))) q *); // expected-warning {{will not be visible outside}}
+
+// This enum inside the function pointer parameter shouldn't leak into the
+// function.
+enum { BB = 0 };
+void enum_in_fun_in_fun(void (*fp)(enum { AA, BB } e)) { // expected-warning {{will not be visible}}
+  SA(1, AA == 5);
+  SA(2, BB == 0);
+}
Index: test/PCH/decl-in-prototype.c
===
--- /dev/null
+++ test/PCH/decl-in-prototype.c
@@ -0,0 +1,27 @@
+// Test that we serialize the enum decl in the function prototype somehow.
+// These decls aren't serialized quite the same way as parameters.
+
+// Test this without pch.
+// RUN: %clang_cc1 -include %s -emit-llvm -o - %s | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_cc1 -include-pch %t -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: define i32 @main()
+// CHECK:   ret i32 1
+
+#ifndef HEADER
+#define HEADER
+
+static inline __attribute__((always_inline)) f(enum { x, y } p) {
+  return y;
+}
+
+#else
+
+int main() {
+  return f(0);
+}
+
+#endif
Index: test/Misc/ast-dump-decl.c
===
--- test/Misc/ast-dump-decl.c
+++ test/Misc/ast-dump-decl.c
@@ -106,8 +106,6 @@
   return x;
 }
 // CHECK:  FunctionDecl{{.*}} TestFunctionDecl 'int (int, enum {{.*}})'
-// CHECK-NEXT:   EnumDecl
-// CHECK-NEXT: EnumConstantDecl{{.*}} e
 // CHECK-NEXT:   ParmVarDecl{{.*}} x
 // CHECK-NEXT:   ParmVarDecl{{.*}} y
 // CHECK-NEXT:   CompoundStmt
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -718,6 +718,7 @@
   /*NumExceptions=*/0,
   /*NoexceptExpr=*/nullptr,
   /*ExceptionSpecTokens=*/nullptr,
+  /*DeclsInPrototype=*/None,
   loc, loc, declarator));
 
   // For consistency, make sure the state still has us as processing
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -8222,8 +8222,9 @@
   // Copy the parameter declarations from the declarator D to the function
   // declaration NewFD, if they are available.  First scavenge them into Params.
   SmallVector Params;
-  if (D.isFunctionDeclarator()) {
-DeclaratorChunk::FunctionTypeInfo  = D.getFunctionTypeInfo();
+  

r288272 - Prospective MSVC workaround.

2016-11-30 Thread John McCall via cfe-commits
Author: rjmccall
Date: Wed Nov 30 14:46:55 2016
New Revision: 288272

URL: http://llvm.org/viewvc/llvm-project?rev=288272=rev
Log:
Prospective MSVC workaround.

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

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=288272=288271=288272=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Nov 30 14:46:55 2016
@@ -2450,7 +2450,8 @@ llvm::Function *CGObjCGNU::ModuleInitFun
   llvm::GlobalVariable *selectorList = [&] {
 ConstantInitBuilder builder(CGM);
 auto selectors = builder.beginArray(selStructTy);
-for (auto  : SelectorTable) {
+auto  = SelectorTable; // MSVC workaround
+for (auto  : table) {
 
   std::string selNameStr = entry.first.getAsString();
   llvm::Constant *selName = ExportUniqueString(selNameStr, 
".objc_sel_name");


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


[PATCH] D14274: Add alloc_size attribute to clang

2016-11-30 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv added a comment.

Ping


https://reviews.llvm.org/D14274



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


r288269 - Finish adopting ConstantInitBuilder in CGObjCGNU. NFC.

2016-11-30 Thread John McCall via cfe-commits
Author: rjmccall
Date: Wed Nov 30 14:19:46 2016
New Revision: 288269

URL: http://llvm.org/viewvc/llvm-project?rev=288269=rev
Log:
Finish adopting ConstantInitBuilder in CGObjCGNU.  NFC.

Modified:
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/ConstantBuilder.h

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=288269=288268=288269=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Nov 30 14:19:46 2016
@@ -164,9 +164,8 @@ protected:
   /// Helper function that generates a constant string and returns a pointer to
   /// the start of the string.  The result of this function can be used 
anywhere
   /// where the C code specifies const char*.  
-  llvm::Constant *MakeConstantString(const std::string ,
- const std::string ="") {
-ConstantAddress Array = CGM.GetAddrOfConstantCString(Str, Name.c_str());
+  llvm::Constant *MakeConstantString(StringRef Str, const char *Name = "") {
+ConstantAddress Array = CGM.GetAddrOfConstantCString(Str, Name);
 return llvm::ConstantExpr::getGetElementPtr(Array.getElementType(),
 Array.getPointer(), Zeros);
   }
@@ -1530,23 +1529,24 @@ GenerateMethodList(StringRef ClassName,
   MethodList.addInt(Int32Ty, MethodTypes.size());
 
   // Get the method structure type.
-  llvm::StructType *ObjCMethodTy = llvm::StructType::get(
-PtrToInt8Ty, // Really a selector, but the runtime creates it us.
-PtrToInt8Ty, // Method types
-IMPTy, //Method pointer
-nullptr);
+  llvm::StructType *ObjCMethodTy =
+llvm::StructType::get(CGM.getLLVMContext(), {
+  PtrToInt8Ty, // Really a selector, but the runtime creates it us.
+  PtrToInt8Ty, // Method types
+  IMPTy// Method pointer
+});
   auto Methods = MethodList.beginArray();
   for (unsigned int i = 0, e = MethodTypes.size(); i < e; ++i) {
-llvm::Constant *Method =
+llvm::Constant *FnPtr =
   TheModule.getFunction(SymbolNameForMethod(ClassName, CategoryName,
 MethodSels[i],
 isClassMethodList));
-assert(Method && "Can't generate metadata for method that doesn't exist");
-llvm::Constant *C = MakeConstantString(MethodSels[i].getAsString());
-Method = llvm::ConstantExpr::getBitCast(Method,
-IMPTy);
-Methods.add(
-llvm::ConstantStruct::get(ObjCMethodTy, {C, MethodTypes[i], Method}));
+assert(FnPtr && "Can't generate metadata for method that doesn't exist");
+auto Method = Methods.beginStruct(ObjCMethodTy);
+Method.add(MakeConstantString(MethodSels[i].getAsString()));
+Method.add(MethodTypes[i]);
+Method.addBitCast(FnPtr, IMPTy);
+Method.finishAndAddTo(Methods);
   }
   Methods.finishAndAddTo(MethodList);
 
@@ -1644,7 +1644,7 @@ llvm::Constant *CGObjCGNU::GenerateClass
   // Fill in the structure
 
   // isa 
-  Elements.add(llvm::ConstantExpr::getBitCast(MetaClass, PtrToInt8Ty));
+  Elements.addBitCast(MetaClass, PtrToInt8Ty);
   // super_class
   Elements.add(SuperClass);
   // name
@@ -1673,7 +1673,7 @@ llvm::Constant *CGObjCGNU::GenerateClass
   // sibling_class
   Elements.add(NULLPtr);
   // protocols
-  Elements.add(llvm::ConstantExpr::getBitCast(Protocols, PtrTy));
+  Elements.addBitCast(Protocols, PtrTy);
   // gc_object_type
   Elements.add(NULLPtr);
   // abi_version
@@ -1746,9 +1746,7 @@ CGObjCGNU::GenerateProtocolList(ArrayRef
 } else {
   protocol = value->getValue();
 }
-llvm::Constant *Ptr = llvm::ConstantExpr::getBitCast(protocol,
-   PtrToInt8Ty);
-Elements.add(Ptr);
+Elements.addBitCast(protocol, PtrToInt8Ty);
   }
   Elements.finishAndAddTo(ProtocolList);
   return ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
@@ -1959,11 +1957,11 @@ void CGObjCGNU::GenerateProtocolHolderCa
   Elements.add(MakeConstantString(CategoryName));
   Elements.add(MakeConstantString(ClassName));
   // Instance method list
-  Elements.add(llvm::ConstantExpr::getBitCast(GenerateMethodList(
-  ClassName, CategoryName, MethodSels, MethodTypes, false), PtrTy));
+  Elements.addBitCast(GenerateMethodList(
+  ClassName, CategoryName, MethodSels, MethodTypes, false), PtrTy);
   // Class method list
-  Elements.add(llvm::ConstantExpr::getBitCast(GenerateMethodList(
-  ClassName, CategoryName, MethodSels, MethodTypes, true), PtrTy));
+  Elements.addBitCast(GenerateMethodList(
+  ClassName, CategoryName, MethodSels, MethodTypes, true), PtrTy);
 
   // Protocol list
   ConstantInitBuilder ProtocolListBuilder(CGM);
@@ -1973,15 +1971,13 @@ void CGObjCGNU::GenerateProtocolHolderCa
   auto ProtocolElements = 

[PATCH] D27254: Protect optional test under libcpp-no-exceptions

2016-11-30 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.
This revision is now accepted and ready to land.

Looks good now - thanks.


https://reviews.llvm.org/D27254



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


[PATCH] D26454: Implement no_sanitize_address for global vars

2016-11-30 Thread Douglas Katzman via Phabricator via cfe-commits
dougk added a comment.

Suppression of sanitizing is necessary if the variable is magically a 
memory-mapped device I/O address.
The linker can arrange for this to be the case using fancy scripts, or even 
just as simple as a section attribute that requires that you take up exactly a 
certain number of bytes in the section.
There was some thought that any non-default section should preclude 
sanitization, but Kostya said that, no, it would make sense to require explicit 
no-sanitize.  I (mistakenly) took that to mean "just do it", for which I 
apologize.




Comment at: lib/Sema/SemaDeclAttr.cpp:5316
 
-  D->addAttr(::new (S.Context) DeprecatedAttr(Attr.getRange(), S.Context, Str,
-   Replacement,
-   Attr.getAttributeSpellingListIndex()));
+  D->addAttr(::new (S.Context)
+ DeprecatedAttr(Attr.getRange(), S.Context, Str, Replacement,

aaron.ballman wrote:
> This formatting change is unrelated.
reverted. (clang-format-diff did that on account of proximity to the added 
lines)



Comment at: lib/Sema/SemaDeclAttr.cpp:5343
+else if (isGlobalVar(D) && SanitizerName != "address")
+  S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
+  << Attr.getName() << ExpectedFunctionOrMethod;

aaron.ballman wrote:
> You diagnose this as an error, but don't early return if the attribute is 
> invalid. Is that intentional?
not intentional. fixed



Comment at: lib/Sema/SemaDeclAttr.cpp:5364
+S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
+<< Attr.getName() << ExpectedFunction;
   D->addAttr(::new (S.Context)

aaron.ballman wrote:
> You diagnose it as an error, but then add the attribute anyway. Is that 
> intentional?
not intentional. fixed



Comment at: test/SemaCXX/attr-no-sanitize-address.cpp:24
 
-int noanal_test_var NO_SANITIZE_ADDRESS; // \
-  // expected-error {{'no_sanitize_address' attribute only applies to 
functions}}

aaron.ballman wrote:
> Please add a new test case to replace this one, showing that the attribute is 
> properly diagnosed when applied to something the attribute cannot appertain 
> to.
that's already tested by noanal_testfn which has no_sanitize_address on 'int x 
= y';


https://reviews.llvm.org/D26454



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


[PATCH] D27277: Make _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR user-settable

2016-11-30 Thread Dimitry Andric via Phabricator via cfe-commits
dim created this revision.
dim added reviewers: EricWF, emaste, mclow.lists, theraven.
dim added a subscriber: cfe-commits.

In https://reviews.llvm.org/rL275749 the old _LIBCPP_TRIVIAL_PAIR_COPY_CTOR 
define was replaced
by _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR, which is also
auto-detected.

However, it is not overridable by the user, since you cannot use -U or
#undef to get rid of the define after __config was included, at least
not without gross hacks.

In the FreeBSD ports tree we have at least one libc++ consumer that
really needs to turn on the trivial constructor (chromium), see
https://bugs.freebsd.org/214654 for the details.  So I would like to
propose making _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
user-settable (to either zero, or nonzero).


https://reviews.llvm.org/D27277

Files:
  include/__config
  include/utility
  
test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp
  test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp
  test/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp

Index: test/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp
@@ -32,23 +32,23 @@
 typedef std::pair P;
 {
 static_assert(std::is_copy_constructible::value, "");
-#if !defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
+#if _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR == 0
 static_assert(std::is_trivially_copy_constructible::value, "");
 #endif
 }
 #if TEST_STD_VER >= 11
 {
 static_assert(std::is_move_constructible::value, "");
-#if !defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
+#if _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR == 0
 static_assert(std::is_trivially_move_constructible::value, "");
 #endif
 }
 {
 using P1 = std::pair;
 static_assert(!std::is_copy_constructible::value, "");
 static_assert(!std::is_trivially_copy_constructible::value, "");
 static_assert(std::is_move_constructible::value, "");
-#if !defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
+#if _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR == 0
 static_assert(std::is_trivially_move_constructible::value, "");
 #endif
 }
Index: test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp
===
--- test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp
+++ test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp
@@ -29,7 +29,7 @@
 
 #include "test_macros.h"
 
-#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
+#if _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR != 0
 #error Non-trivial ctor ABI macro defined
 #endif
 
Index: test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp
===
--- test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp
+++ test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp
@@ -21,16 +21,16 @@
 #undef _LIBCPP_ABI_UNSTABLE
 #undef _LIBCPP_ABI_VERSION
 #define _LIBCPP_ABI_VERSION 1
-#define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
+#define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR 1
 
 #include 
 #include 
 #include 
 #include 
 
 #include "test_macros.h"
 
-#if !defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
+#if _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR == 0
 #error trivial ctor ABI macro defined
 #endif
 
Index: include/utility
===
--- include/utility
+++ include/utility
@@ -296,7 +296,7 @@
 constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
 #endif
 
-#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
+#if _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR != 0
 struct __non_trivially_copyable_base {
   _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
   __non_trivially_copyable_base() _NOEXCEPT {}
@@ -307,7 +307,7 @@
 
 template 
 struct _LIBCPP_TYPE_VIS_ONLY pair
-#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
+#if _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR != 0
 : private __non_trivially_copyable_base
 #endif
 {
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -51,9 +51,13 @@
 #elif _LIBCPP_ABI_VERSION == 1
 // Feature macros for disabling pre ABI v1 features. All of these options
 // are deprecated.
-#if defined(__FreeBSD__)
-#define 

r288267 - [Sema] Teach -Wcast-align to look at the aligned attribute of the

2016-11-30 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Nov 30 13:42:03 2016
New Revision: 288267

URL: http://llvm.org/viewvc/llvm-project?rev=288267=rev
Log:
[Sema] Teach -Wcast-align to look at the aligned attribute of the
declared variables.

Teach Sema to check the aligned attribute attached to variable
declarations so that it doesn't issue spurious warnings.

rdar://problem/26517471

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

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/warn-cast-align.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=288267=288266=288267=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Nov 30 13:42:03 2016
@@ -10264,6 +10264,19 @@ bool Sema::CheckParmsForFunctionDef(Arra
   return HasInvalidParm;
 }
 
+/// A helper function to get the alignment of a Decl referred to by DeclRefExpr
+/// or MemberExpr.
+static CharUnits getDeclAlign(Expr *E, CharUnits TypeAlign,
+  ASTContext ) {
+  if (const auto *DRE = dyn_cast(E))
+return Context.getDeclAlign(DRE->getDecl());
+
+  if (const auto *ME = dyn_cast(E))
+return Context.getDeclAlign(ME->getMemberDecl());
+
+  return TypeAlign;
+}
+
 /// CheckCastAlign - Implements -Wcast-align, which warns when a
 /// pointer cast increases the alignment requirements.
 void Sema::CheckCastAlign(Expr *Op, QualType T, SourceRange TRange) {
@@ -10298,6 +10311,15 @@ void Sema::CheckCastAlign(Expr *Op, Qual
   if (SrcPointee->isIncompleteType()) return;
 
   CharUnits SrcAlign = Context.getTypeAlignInChars(SrcPointee);
+
+  if (auto *CE = dyn_cast(Op)) {
+if (CE->getCastKind() == CK_ArrayToPointerDecay)
+  SrcAlign = getDeclAlign(CE->getSubExpr(), SrcAlign, Context);
+  } else if (auto *UO = dyn_cast(Op)) {
+if (UO->getOpcode() == UO_AddrOf)
+  SrcAlign = getDeclAlign(UO->getSubExpr(), SrcAlign, Context);
+  }
+
   if (SrcAlign >= DestAlign) return;
 
   Diag(TRange.getBegin(), diag::warn_cast_align)

Modified: cfe/trunk/test/Sema/warn-cast-align.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-cast-align.c?rev=288267=288266=288267=diff
==
--- cfe/trunk/test/Sema/warn-cast-align.c (original)
+++ cfe/trunk/test/Sema/warn-cast-align.c Wed Nov 30 13:42:03 2016
@@ -39,3 +39,23 @@ void test2(char *P) {
 void test3(char *P) {
   struct B *b = (struct B*) P;
 }
+
+// Do not issue a warning. The aligned attribute changes the alignment of the
+// variables and fields.
+char __attribute__((aligned(4))) a[16];
+
+struct S0 {
+  char a[16];
+};
+
+struct S {
+  char __attribute__((aligned(4))) a[16];
+  struct S0 __attribute__((aligned(4))) s0;
+};
+
+void test4() {
+  struct S s;
+  int *i = (int *)s.a;
+  i = (int *)
+  i = (int *)a;
+}


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


[PATCH] D21099: [Sema] Teach -Wcast-align to look at the aligned attribute of the declared variables

2016-11-30 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288267: [Sema] Teach -Wcast-align to look at the aligned 
attribute of the (authored by ahatanak).

Changed prior to commit:
  https://reviews.llvm.org/D21099?vs=78594=79792#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D21099

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/Sema/warn-cast-align.c


Index: cfe/trunk/test/Sema/warn-cast-align.c
===
--- cfe/trunk/test/Sema/warn-cast-align.c
+++ cfe/trunk/test/Sema/warn-cast-align.c
@@ -39,3 +39,23 @@
 void test3(char *P) {
   struct B *b = (struct B*) P;
 }
+
+// Do not issue a warning. The aligned attribute changes the alignment of the
+// variables and fields.
+char __attribute__((aligned(4))) a[16];
+
+struct S0 {
+  char a[16];
+};
+
+struct S {
+  char __attribute__((aligned(4))) a[16];
+  struct S0 __attribute__((aligned(4))) s0;
+};
+
+void test4() {
+  struct S s;
+  int *i = (int *)s.a;
+  i = (int *)
+  i = (int *)a;
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -10264,6 +10264,19 @@
   return HasInvalidParm;
 }
 
+/// A helper function to get the alignment of a Decl referred to by DeclRefExpr
+/// or MemberExpr.
+static CharUnits getDeclAlign(Expr *E, CharUnits TypeAlign,
+  ASTContext ) {
+  if (const auto *DRE = dyn_cast(E))
+return Context.getDeclAlign(DRE->getDecl());
+
+  if (const auto *ME = dyn_cast(E))
+return Context.getDeclAlign(ME->getMemberDecl());
+
+  return TypeAlign;
+}
+
 /// CheckCastAlign - Implements -Wcast-align, which warns when a
 /// pointer cast increases the alignment requirements.
 void Sema::CheckCastAlign(Expr *Op, QualType T, SourceRange TRange) {
@@ -10298,6 +10311,15 @@
   if (SrcPointee->isIncompleteType()) return;
 
   CharUnits SrcAlign = Context.getTypeAlignInChars(SrcPointee);
+
+  if (auto *CE = dyn_cast(Op)) {
+if (CE->getCastKind() == CK_ArrayToPointerDecay)
+  SrcAlign = getDeclAlign(CE->getSubExpr(), SrcAlign, Context);
+  } else if (auto *UO = dyn_cast(Op)) {
+if (UO->getOpcode() == UO_AddrOf)
+  SrcAlign = getDeclAlign(UO->getSubExpr(), SrcAlign, Context);
+  }
+
   if (SrcAlign >= DestAlign) return;
 
   Diag(TRange.getBegin(), diag::warn_cast_align)


Index: cfe/trunk/test/Sema/warn-cast-align.c
===
--- cfe/trunk/test/Sema/warn-cast-align.c
+++ cfe/trunk/test/Sema/warn-cast-align.c
@@ -39,3 +39,23 @@
 void test3(char *P) {
   struct B *b = (struct B*) P;
 }
+
+// Do not issue a warning. The aligned attribute changes the alignment of the
+// variables and fields.
+char __attribute__((aligned(4))) a[16];
+
+struct S0 {
+  char a[16];
+};
+
+struct S {
+  char __attribute__((aligned(4))) a[16];
+  struct S0 __attribute__((aligned(4))) s0;
+};
+
+void test4() {
+  struct S s;
+  int *i = (int *)s.a;
+  i = (int *)
+  i = (int *)a;
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -10264,6 +10264,19 @@
   return HasInvalidParm;
 }
 
+/// A helper function to get the alignment of a Decl referred to by DeclRefExpr
+/// or MemberExpr.
+static CharUnits getDeclAlign(Expr *E, CharUnits TypeAlign,
+  ASTContext ) {
+  if (const auto *DRE = dyn_cast(E))
+return Context.getDeclAlign(DRE->getDecl());
+
+  if (const auto *ME = dyn_cast(E))
+return Context.getDeclAlign(ME->getMemberDecl());
+
+  return TypeAlign;
+}
+
 /// CheckCastAlign - Implements -Wcast-align, which warns when a
 /// pointer cast increases the alignment requirements.
 void Sema::CheckCastAlign(Expr *Op, QualType T, SourceRange TRange) {
@@ -10298,6 +10311,15 @@
   if (SrcPointee->isIncompleteType()) return;
 
   CharUnits SrcAlign = Context.getTypeAlignInChars(SrcPointee);
+
+  if (auto *CE = dyn_cast(Op)) {
+if (CE->getCastKind() == CK_ArrayToPointerDecay)
+  SrcAlign = getDeclAlign(CE->getSubExpr(), SrcAlign, Context);
+  } else if (auto *UO = dyn_cast(Op)) {
+if (UO->getOpcode() == UO_AddrOf)
+  SrcAlign = getDeclAlign(UO->getSubExpr(), SrcAlign, Context);
+  }
+
   if (SrcAlign >= DestAlign) return;
 
   Diag(TRange.getBegin(), diag::warn_cast_align)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D26267: [Modules] Include builtins with #include instead of #import for ObjC

2016-11-30 Thread Richard Smith via cfe-commits
On 30 November 2016 at 11:08, Bruno Cardoso Lopes via Phabricator via
cfe-commits  wrote:

> > I suspect the problem is instead that #import just doesn't work properly
> with modules
>
> (specifically, either with local submodule visibility or with modules
> that do not export *),
> > because it doesn't care whether the previous inclusion is visible or
> not, and as a result it assumes
> > "I've heard about someone #including this ever" means the same thing as
> "the contents of this file
> > are visible right now". I know that #pragma once has this issue, so I'd
> expect #import to also suffer from it.
>
> Taking a look at this, any ideas on what's the right approach with the
> #import's here? So instead of entering the header, is there a way to make
> the contents for the module matching the built-in header to become
> available/visible at that point?


The right thing to do would be to track the set of headers whose #import /
#include-with-#pragma-once is visible, and only skip inclusions if there is
a *visible* #import / #include-with-#pragma-once of that header. (Much like
we only skip an include due to an include guard if there is a visible
definition of the include guard macro.) For instance, instead of a single
`isImport` bit on `HeaderFileInfo`, we could store a list of IDs of
submodules that have imported the header, and check whether any of those
are visible when deciding whether to skip an inclusion, but there's
probably a cheaper way (in common cases) to get the same effect.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25263: [Driver] Allow setting the default linker during build

2016-11-30 Thread Sean Fertile via Phabricator via cfe-commits
sfertile added inline comments.



Comment at: lib/Driver/ToolChain.cpp:721-724
+
+const char *ToolChain::getDefaultLinker() const {
+  return CLANG_DEFAULT_LINKER;
+}

Hahnfeld wrote:
> I think this could go into the header
The CLANG_DEFAULT_LINKER macro is getting defined in "clang/Config/config.h" 
which isn't meant to be included in other headers.


Repository:
  rL LLVM

https://reviews.llvm.org/D25263



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-30 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 79788.
madsravn added a comment.

Trimmed down the ast matcher a little.


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringCompareCheck.cpp
  clang-tidy/misc/StringCompareCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,56 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template , typename A = std::allocator >
+struct basic_string {
+  basic_string();
+  basic_string(const C*, unsigned int size);
+  int compare(const basic_string& str);
+  bool empty();
+};
+  bool operator==(const basic_string lhs, const basic_string rhs);
+  bool operator!=(const basic_string lhs, const basic_string rhs);
+typedef basic_string string;
+}
+
+void func(bool b);
+
+void Test() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+
+  if(str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:6: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(!str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) == 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:6: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) != 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:6: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(0 == str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:6: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(0 != str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:6: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  func(str1.compare(str2));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str2.empty() || str1.compare(str2) != 0) { }
+  // CHECK-MESSAGES: [[@LINE-1]]:22: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+
+
+}
+
+void Valid() {
+std::string str1("a", 1);
+std::string str2("b", 1);
+if(str1 == str2) {}
+if(str1 != str2) {}
+if(str1.compare(str2) == 1) {}
+if(str1.compare(str2) == str1.compare(str2)) {}
+if(0 == 0) {}
+if(1 == str1.compare(str2)) {}
+if(str1.compare(str2) > 0) {}
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
===
--- docs/clang-tidy/checks/misc-string-compare.rst
+++ docs/clang-tidy/checks/misc-string-compare.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - misc-string-compare
+
+misc-string-compare
+===
+
+Finds string comparisons using the compare method.
+
+A common mistake is to use the string's ``compare`` method instead of using the 
+equality or inequality operators. The compare method is intended for sorting
+functions and thus returns ``-1``, ``0`` or ``1`` depending on the lexicographical 
+relationship between the strings compared. If an equality or inequality check
+can suffice, that is recommended.
+
+Examples:
+
+.. code-block:: c++
+
+  std::string str1{"a"};
+  std::string str2{"b"};
+  
+  if(str1.compare(str2)) {} // use str1 != str2 instead
+  
+  if(!str1.compare(str2)) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) == 0) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) != 0) {} // use str1 != str2 instead
+
+  if(0 == str1.compare(str2)) {} // use str1 == str2 instead
+
+  if(0 != str1.compare(str2)) {} // use str1 != str2 instead
+
+The above code examples shows the list of if-statements that this check will
+give a warning for. All of them uses ``compare`` to check if equality or 
+inequality of two strings instead of using the correct operators.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -80,6 +80,7 @@
misc-sizeof-container
misc-sizeof-expression
misc-static-assert
+   misc-string-compare
misc-string-constructor
misc-string-integer-assignment
misc-string-literal-with-embedded-nul
Index: 

[PATCH] D26267: [Modules] Include builtins with #include instead of #import for ObjC

2016-11-30 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added inline comments.



Comment at: lib/Frontend/FrontendActions.cpp:227
+IsBuiltin = true;
+  addHeaderInclude(H.NameAsWritten, Includes, LangOpts, Module->IsExternC,
+   IsBuiltin /*AlwaysInclude*/);

rsmith wrote:
> I don't understand why this would be necessary. If these headers are in fact 
> textual headers, they won't be in the `HK_Normal` or `HK_Private` lists at 
> all (they'll be in the `HK_Private` or `HK_PrivateTextual` lists instead), so 
> your `IsBuiltin = true;` line should be unreachable. (Checking for an 
> absolute path also seems suspicious here.)
> 
> I suspect the problem is instead that `#import` just doesn't work properly 
> with modules (specifically, either with local submodule visibility or with 
> modules that do not `export *`), because it doesn't care whether the previous 
> inclusion is visible or not, and as a result it assumes "I've heard about 
> someone #including this ever" means the same thing as "the contents of this 
> file are visible right now". I know that `#pragma once` has this issue, so 
> I'd expect `#import` to also suffer from it.
In fact, I can achieve the same desired result by changing libcxx modulemap to:

  @@ -161,11 +161,15 @@ module std [system] {
   module cstddef {
 header "cstddef"
 export *
  +  // FIXME: #import on Darwin requires explicit re-export
  +  export Darwin.POSIX.sys.types
   }
   module cstdint {
 header "cstdint"
 export depr.stdint_h
 export *
  +  // FIXME: #import on Darwin requires explicit re-export
  +  export Darwin.C.stdint
   }

But I would like to avoid adding darwin specific stuff there. 

> I don't understand why this would be necessary. If these headers are in fact 
> textual headers,
> they won't be in the HK_Normal or HK_Private lists at all (they'll be in the 
> HK_Private or
> HK_PrivateTextual lists instead), so your IsBuiltin = true; line should be 
> unreachable.

AFAIU, builtins are added twice (1) with the full path with 
`//bin/../lib/clang/4.0.0/include/.h`, as 
`NormalHeader`, which maps to `HK_Normal` and (2) `.h` as 
`TextualHeader`, mapping to `HK_Textual`. This happens in the snippet 
(lib/Lex/ModuleMap.cpp:1882) below:

  if (BuiltinFile) {
// FIXME: Taking the name from the FileEntry is unstable and can give
// different results depending on how we've previously named that file
// in this build.
Module::Header H = { BuiltinFile->getName(), BuiltinFile };
Map.addHeader(ActiveModule, H, Role); <- (1)

// If we have both a builtin and system version of the file, the
// builtin version may want to inject macros into the system header, so
// force the system header to be treated as a textual header in this
// case.
Role = ModuleMap::ModuleHeaderRole(Role | ModuleMap::TextualHeader);
  }

  // Record this header.
  Module::Header H = { RelativePathName.str(), File };
  Map.addHeader(ActiveModule, H, Role); <- (2)
  
As an experiment, I changed `collectModuleHeaderIncludes` to skip 
`addHeaderInclude` for builtin headers with `HK_Normal`, but it caused 
regressions while compiling Darwin SDK even for non local submodule visibility.

> (Checking for an absolute path also seems suspicious here.)

Right, this was done to speedup checking for built-ins, since they are expanded 
to absolute paths. But this isn't necessary for the logic to work and can be 
removed.

> I suspect the problem is instead that #import just doesn't work properly with 
> modules
> (specifically, either with local submodule visibility or with modules that do 
> not export *),
> because it doesn't care whether the previous inclusion is visible or not, and 
> as a result it assumes
> "I've heard about someone #including this ever" means the same thing as "the 
> contents of this file
> are visible right now". I know that #pragma once has this issue, so I'd 
> expect #import to also suffer from it.

Taking a look at this, any ideas on what's the right approach with the 
#import's here? So instead of entering the header, is there a way to make the 
contents for the module matching the built-in header to become 
available/visible at that point?


https://reviews.llvm.org/D26267



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


[PATCH] D26836: [analyzer] SValExplainer: Support ObjC ivars and __block variables.

2016-11-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ abandoned this revision.
NoQ added a comment.

Decided to go ahead and commit as r288260.


https://reviews.llvm.org/D26836



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


[PATCH] D26839: [analyzer] An attempt to fix pr19539 - crashes on temporaries life-extended via members

2016-11-30 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288263: [analyzer] Construct temporary objects of correct 
types, destroy them properly. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D26839?vs=79540=79783#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26839

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/test/Analysis/lifetime-extension.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -202,51 +202,70 @@
   MemRegionManager  = StateMgr.getRegionManager();
   StoreManager  = StateMgr.getStoreManager();
 
-  // We need to be careful about treating a derived type's value as
-  // bindings for a base type. Unless we're creating a temporary pointer region,
-  // start by stripping and recording base casts.
-  SmallVector Casts;
-  const Expr *Inner = Ex->IgnoreParens();
-  if (!Loc::isLocType(Result->getType())) {
-while (const CastExpr *CE = dyn_cast(Inner)) {
-  if (CE->getCastKind() == CK_DerivedToBase ||
-  CE->getCastKind() == CK_UncheckedDerivedToBase)
-Casts.push_back(CE);
-  else if (CE->getCastKind() != CK_NoOp)
-break;
+  // MaterializeTemporaryExpr may appear out of place, after a few field and
+  // base-class accesses have been made to the object, even though semantically
+  // it is the whole object that gets materialized and lifetime-extended.
+  //
+  // For example:
+  //
+  //   `-MaterializeTemporaryExpr
+  // `-MemberExpr
+  //   `-CXXTemporaryObjectExpr
+  //
+  // instead of the more natural
+  //
+  //   `-MemberExpr
+  // `-MaterializeTemporaryExpr
+  //   `-CXXTemporaryObjectExpr
+  //
+  // Use the usual methods for obtaining the expression of the base object,
+  // and record the adjustments that we need to make to obtain the sub-object
+  // that the whole expression 'Ex' refers to. This trick is usual,
+  // in the sense that CodeGen takes a similar route.
 
-  Inner = CE->getSubExpr()->IgnoreParens();
-}
-  }
+  SmallVector CommaLHSs;
+  SmallVector Adjustments;
+
+  const Expr *Init = Ex->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
 
-  // Create a temporary object region for the inner expression (which may have
-  // a more derived type) and bind the value into it.
   const TypedValueRegion *TR = nullptr;
   if (const MaterializeTemporaryExpr *MT =
   dyn_cast(Result)) {
 StorageDuration SD = MT->getStorageDuration();
 // If this object is bound to a reference with static storage duration, we
 // put it in a different region to prevent "address leakage" warnings.
 if (SD == SD_Static || SD == SD_Thread)
-TR = MRMgr.getCXXStaticTempObjectRegion(Inner);
+  TR = MRMgr.getCXXStaticTempObjectRegion(Init);
   }
   if (!TR)
-TR = MRMgr.getCXXTempObjectRegion(Inner, LC);
+TR = MRMgr.getCXXTempObjectRegion(Init, LC);
 
   SVal Reg = loc::MemRegionVal(TR);
 
+  // Make the necessary adjustments to obtain the sub-object.
+  for (auto I = Adjustments.rbegin(), E = Adjustments.rend(); I != E; ++I) {
+const SubobjectAdjustment  = *I;
+switch (Adj.Kind) {
+case SubobjectAdjustment::DerivedToBaseAdjustment:
+  Reg = StoreMgr.evalDerivedToBase(Reg, Adj.DerivedToBase.BasePath);
+  break;
+case SubobjectAdjustment::FieldAdjustment:
+  Reg = StoreMgr.getLValueField(Adj.Field, Reg);
+  break;
+case SubobjectAdjustment::MemberPointerAdjustment:
+  // FIXME: Unimplemented.
+  State->bindDefault(Reg, UnknownVal());
+  return State;
+}
+  }
+
+  // Try to recover some path sensitivity in case we couldn't compute the value.
   if (V.isUnknown())
 V = getSValBuilder().conjureSymbolVal(Result, LC, TR->getValueType(),
   currBldrCtx->blockCount());
+  // Bind the value of the expression to the sub-object region, and then bind
+  // the sub-object region to our expression.
   State = State->bindLoc(Reg, V);
-
-  // Re-apply the casts (from innermost to outermost) for type sanity.
-  for (SmallVectorImpl::reverse_iterator I = Casts.rbegin(),
-   E = Casts.rend();
-   I != E; ++I) {
-Reg = StoreMgr.evalDerivedToBase(Reg, *I);
-  }
-
   State = State->BindExpr(Result, LC, Reg);
   return State;
 }
@@ -592,9 +611,9 @@
   SVal dest = state->getLValue(varDecl, Pred->getLocationContext());
   const MemRegion *Region = dest.castAs().getRegion();
 
-  if (const ReferenceType *refType = varType->getAs()) {
-varType = refType->getPointeeType();
-Region = state->getSVal(Region).getAsRegion();
+  if (varType->isReferenceType()) {
+Region = state->getSVal(Region).getAsRegion()->getBaseRegion();
+varType = 

r288263 - [analyzer] Construct temporary objects of correct types, destroy them properly.

2016-11-30 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Nov 30 13:02:44 2016
New Revision: 288263

URL: http://llvm.org/viewvc/llvm-project?rev=288263=rev
Log:
[analyzer] Construct temporary objects of correct types, destroy them properly.

When constructing a temporary object region, which represents the result of
MaterializeTemporaryExpr, track down the sub-expression for which the temporary
is necessary with a trick similar to the approach used in CodeGen, namely
by using Expr::skipRValueSubobjectAdjustments().

Then, create the temporary object region with type of that sub-expression.
That type would propagate further in a path-sensitive manner.

During destruction of lifetime-extened temporaries, consult the type of
the temporary object region, rather than the type of the lifetime-extending
variable, in order to call the correct destructor (fixes pr17001) and,
at least, not to crash by trying to call a destructor of a plain type
(fixes pr19539).

rdar://problem/29131302
rdar://problem/29131576

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

Added:
cfe/trunk/test/Analysis/lifetime-extension.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=288263=288262=288263=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Nov 30 13:02:44 2016
@@ -202,25 +202,32 @@ ExprEngine::createTemporaryRegionIfNeede
   MemRegionManager  = StateMgr.getRegionManager();
   StoreManager  = StateMgr.getStoreManager();
 
-  // We need to be careful about treating a derived type's value as
-  // bindings for a base type. Unless we're creating a temporary pointer 
region,
-  // start by stripping and recording base casts.
-  SmallVector Casts;
-  const Expr *Inner = Ex->IgnoreParens();
-  if (!Loc::isLocType(Result->getType())) {
-while (const CastExpr *CE = dyn_cast(Inner)) {
-  if (CE->getCastKind() == CK_DerivedToBase ||
-  CE->getCastKind() == CK_UncheckedDerivedToBase)
-Casts.push_back(CE);
-  else if (CE->getCastKind() != CK_NoOp)
-break;
+  // MaterializeTemporaryExpr may appear out of place, after a few field and
+  // base-class accesses have been made to the object, even though semantically
+  // it is the whole object that gets materialized and lifetime-extended.
+  //
+  // For example:
+  //
+  //   `-MaterializeTemporaryExpr
+  // `-MemberExpr
+  //   `-CXXTemporaryObjectExpr
+  //
+  // instead of the more natural
+  //
+  //   `-MemberExpr
+  // `-MaterializeTemporaryExpr
+  //   `-CXXTemporaryObjectExpr
+  //
+  // Use the usual methods for obtaining the expression of the base object,
+  // and record the adjustments that we need to make to obtain the sub-object
+  // that the whole expression 'Ex' refers to. This trick is usual,
+  // in the sense that CodeGen takes a similar route.
 
-  Inner = CE->getSubExpr()->IgnoreParens();
-}
-  }
+  SmallVector CommaLHSs;
+  SmallVector Adjustments;
+
+  const Expr *Init = Ex->skipRValueSubobjectAdjustments(CommaLHSs, 
Adjustments);
 
-  // Create a temporary object region for the inner expression (which may have
-  // a more derived type) and bind the value into it.
   const TypedValueRegion *TR = nullptr;
   if (const MaterializeTemporaryExpr *MT =
   dyn_cast(Result)) {
@@ -228,25 +235,37 @@ ExprEngine::createTemporaryRegionIfNeede
 // If this object is bound to a reference with static storage duration, we
 // put it in a different region to prevent "address leakage" warnings.
 if (SD == SD_Static || SD == SD_Thread)
-TR = MRMgr.getCXXStaticTempObjectRegion(Inner);
+  TR = MRMgr.getCXXStaticTempObjectRegion(Init);
   }
   if (!TR)
-TR = MRMgr.getCXXTempObjectRegion(Inner, LC);
+TR = MRMgr.getCXXTempObjectRegion(Init, LC);
 
   SVal Reg = loc::MemRegionVal(TR);
 
+  // Make the necessary adjustments to obtain the sub-object.
+  for (auto I = Adjustments.rbegin(), E = Adjustments.rend(); I != E; ++I) {
+const SubobjectAdjustment  = *I;
+switch (Adj.Kind) {
+case SubobjectAdjustment::DerivedToBaseAdjustment:
+  Reg = StoreMgr.evalDerivedToBase(Reg, Adj.DerivedToBase.BasePath);
+  break;
+case SubobjectAdjustment::FieldAdjustment:
+  Reg = StoreMgr.getLValueField(Adj.Field, Reg);
+  break;
+case SubobjectAdjustment::MemberPointerAdjustment:
+  // FIXME: Unimplemented.
+  State->bindDefault(Reg, UnknownVal());
+  return State;
+}
+  }
+
+  // Try to recover some path sensitivity in case we couldn't compute the 
value.
   if (V.isUnknown())
 V = getSValBuilder().conjureSymbolVal(Result, LC, TR->getValueType(),
   currBldrCtx->blockCount());
+  // Bind the 

[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-30 Thread Sean Callanan via Phabricator via cfe-commits
spyffe marked 3 inline comments as done.
spyffe added a comment.

Thank you for your review, Vedant!  I will update the patch to reflect your 
comments in a moment.

> I'm concerned about the amount of covered-but-untested code this patch 
> introduces. Since there are no CHECK lines, it's hard for me to verify that 
> this tool is doing the right thing.

What you're observing is that this is very much a skeleton.  What it can do 
right now is let the parser know that a `struct S` exists, but not what its 
contents are.  That's why the test is so simple, too.  As soon as the lexical 
lookup machinery exists, we'll be able to add tests accessing fields etc. and 
make sure everything is copacetic.

> Along with this change, I suggest stripping out a fair amount of code for the 
> initial commit (probably PrintSourceForLocation, and maybe anything related 
> to LogLookups).

That's fair.  As a low-level testing tool I'd like to make sure that I have a 
logging mechanism later on that allows tests to verify that the compiler made 
the right queries during a parse; that said, I can add these functions back in 
when tests require them.




Comment at: tools/clang-import-test/clang-import-test.cpp:302
+bool Parse(const std::string , std::unique_ptr ,
+   llvm::ArrayRef Imports) {
+  CI = BuildCompilerInstance();

vsk wrote:
> I suggest making this `Expected Parse(..., 
> ArrayRef)`. This way, there's no way to 
> mistake CI for an input param, there's no need for an extra step to convert 
> std::unique_ptr to CompilerInstance *, and it's harder to 
> drop an error from Parse without logging/handling it.
Ah yes, this is a pattern I hadn't internalized yet.  Thanks for the reminder.


Repository:
  rL LLVM

https://reviews.llvm.org/D27180



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


[PATCH] D26753: ASTImporter: improve support for C++ templates

2016-11-30 Thread Kareem Khazem via Phabricator via cfe-commits
khazem added a comment.

Sorry for the late comment, but one of the tests that this introduces is 
breaking on my end:

  
/usr/local/google/home/khazem/doc/llvm/tools/clang/test/ASTMerge/class-template-partial-spec.cpp:9:11:
 error: expected string not found in input
  // CHECK: 
/media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec2.cpp:21:32:
 error: external variable 'X1' declared with incompatible types in different 
translation units ('TwoOptionTemplate' vs. 'TwoOptionTemplate')
^
  :1:1: note: scanning from here
  
/usr/local/google/home/khazem/doc/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec1.cpp:20:30:
 error: external variable 'X0' defined in multiple translation units
  ^
  :7:15: note: possible intended match here
  
/usr/local/google/home/khazem/doc/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec2.cpp:21:32:
 error: external variable 'X1' declared with incompatible types in different 
translation units ('TwoOptionTemplate' vs. 'TwoOptionTemplate')
^

Is this expected?


https://reviews.llvm.org/D26753



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


[PATCH] D27090: Add LocationContext as a parameter to checkRegionChanges

2016-11-30 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Thank you for doing this!!!

Artem, do you want to disallow the creation of successors from 
checkRegionChanges callback or can this go in as is?

Anna.




Comment at: lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp:240
-  /// #checkRegionChanges when no checkers are tracking any state.
-  bool wantsRegionChangeUpdate(ProgramStateRef St) const { return true; }
-

You should mention that you are deleting this in the commit message or split 
into a separate commit that could go in before this commit.



Comment at: lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp:255
   ///
-  /// Note that this callback will not be invoked unless
-  /// #wantsRegionChangeUpdate returns \c true.
+  /// Note: wantsRegionChangeUpdate has recently been removed as
+  ///   it's been unused since checkPointerEscape was added

Please, remove this comment altogether.


https://reviews.llvm.org/D27090



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


r288260 - [analyzer] SValExplainer: Support ObjC ivars and __block variables.

2016-11-30 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Nov 30 12:26:43 2016
New Revision: 288260

URL: http://llvm.org/viewvc/llvm-project?rev=288260=rev
Log:
[analyzer] SValExplainer: Support ObjC ivars and __block variables.

Additionally, explain the difference between normal and heap-based
symbolic regions.

Added:
cfe/trunk/test/Analysis/explain-svals.m
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
cfe/trunk/test/Analysis/explain-svals.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h?rev=288260=288259=288260=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h Wed Nov 30 
12:26:43 2016
@@ -142,6 +142,14 @@ public:
 // TODO: Explain CXXThisRegion itself, find a way to test it.
 if (isThisObject(R))
   return "'this' object";
+// Objective-C objects are not normal symbolic regions. At least,
+// they're always on the heap.
+if (R->getSymbol()->getType()
+.getCanonicalType()->getAs())
+  return "object at " + Visit(R->getSymbol());
+// Other heap-based symbolic regions are also special.
+if (isa(R->getMemorySpace()))
+  return "heap segment that starts at " + Visit(R->getSymbol());
 return "pointee of " + Visit(R->getSymbol());
   }
 
@@ -176,6 +184,8 @@ public:
 std::string Name = VD->getQualifiedNameAsString();
 if (isa(VD))
   return "parameter '" + Name + "'";
+else if (VD->hasAttr())
+  return "block variable '" + Name + "'";
 else if (VD->hasLocalStorage())
   return "local variable '" + Name + "'";
 else if (VD->isStaticLocal())
@@ -186,6 +196,11 @@ public:
   llvm_unreachable("A variable is either local or global");
   }
 
+  std::string VisitObjCIvarRegion(const ObjCIvarRegion *R) {
+return "instance variable '" + R->getDecl()->getNameAsString() + "' of " +
+   Visit(R->getSuperRegion());
+  }
+
   std::string VisitFieldRegion(const FieldRegion *R) {
 return "field '" + R->getDecl()->getNameAsString() + "' of " +
Visit(R->getSuperRegion());

Modified: cfe/trunk/test/Analysis/explain-svals.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/explain-svals.cpp?rev=288260=288259=288260=diff
==
--- cfe/trunk/test/Analysis/explain-svals.cpp (original)
+++ cfe/trunk/test/Analysis/explain-svals.cpp Wed Nov 30 12:26:43 2016
@@ -47,7 +47,7 @@ void test_2(char *ptr, int ext) {
   clang_analyzer_explain(glob_ptr); // expected-warning-re^value derived 
from \(symbol of type 'int' conjured at statement 'conjure\(\)'\) for global 
variable 'glob_ptr'$
   clang_analyzer_explain(clang_analyzer_getExtent(ptr)); // 
expected-warning-re^extent of pointee of argument 'ptr'$
   int *x = new int[ext];
-  clang_analyzer_explain(x); // expected-warning-re^pointer to element of 
type 'int' with index 0 of pointee of symbol of type 'int \*' conjured at 
statement 'new int \[ext\]'$
+  clang_analyzer_explain(x); // expected-warning-re^pointer to element of 
type 'int' with index 0 of heap segment that starts at symbol of type 'int \*' 
conjured at statement 'new int \[ext\]'$
   // Sic! What gets computed is the extent of the element-region.
   clang_analyzer_explain(clang_analyzer_getExtent(x)); // 
expected-warning-re^signed 32-bit integer '4'$
   delete[] x;

Added: cfe/trunk/test/Analysis/explain-svals.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/explain-svals.m?rev=288260=auto
==
--- cfe/trunk/test/Analysis/explain-svals.m (added)
+++ cfe/trunk/test/Analysis/explain-svals.m Wed Nov 30 12:26:43 2016
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -w -triple i386-apple-darwin10 -fblocks -analyze 
-analyzer-checker=core.builtin,debug.ExprInspection -verify %s
+
+#include "Inputs/system-header-simulator-objc.h"
+
+void clang_analyzer_explain(void *);
+
+@interface Object : NSObject {
+@public
+  Object *x;
+}
+@end
+
+void test_1(Object *p) {
+  clang_analyzer_explain(p); // expected-warning-re^argument 'p'$
+  clang_analyzer_explain(p->x); // expected-warning-re^initial value of 
instance variable 'x' of object at argument 'p'$
+  Object *q = [[Object alloc] init];
+  clang_analyzer_explain(q); // expected-warning-re^symbol of type 'Object 
\*' conjured at statement '\[\[Object alloc\] init\]'$
+  clang_analyzer_explain(q->x); // expected-warning-re^initial value of 
instance variable 'x' of object at symbol of type 'Object \*' conjured at 
statement '\[\[Object alloc\] init\]'$
+}
+
+void test_2() {
+  __block int x;
+  ^{
+

[PATCH] D27091: Add the way to extract SVals of arguments used in a call for a given StackFrameCtx

2016-11-30 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Artem just pointed out that I have "Smalls" instead of "SVals" in my first 
comment.


https://reviews.llvm.org/D27091



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


[PATCH] D26657: [Sema] Respect DLL attributes more faithfully

2016-11-30 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: lib/Sema/SemaTemplate.cpp:7439
+void Sema::ActOnDLLAttr(ClassTemplateSpecializationDecl *Def,
+InheritableAttr *Attr) {
+  // We reject explicit instantiations in class scope, so there should

smeenai wrote:
> hans wrote:
> > This function only applies to dllexport, not dllimport, so it would be good 
> > if the name reflected that, and maybe we could also add an assert to check 
> > for it.
> It's called in two places (the refactored original call for explicit 
> instantiation declaration followed by explicit instantiation definition, and 
> my new call for implicit instantiation followed by explicit instantiation 
> definition). The dllexport guarantee only applies to the second one, right? 
> I'll come up with a better name based on your suggestions in the other 
> comment.
You're right, my mistake.



Comment at: lib/Sema/SemaTemplate.cpp:7710
+(Context.getTargetInfo().getCXXABI().isMicrosoft() ||
+ Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment())) {
+  // In the MS ABI, an explicit instantiation definition can add a dll

smeenai wrote:
> hans wrote:
> > Why the isWindowsItaniumEnvironment check? I'd expect checking for the MS 
> > ABI is sufficient?
> windows-itanium in general tries to stick to MSVC semantics for 
> dllexport/import annotations (unlike Cygwin and MinGW which kinda do their 
> own thing). This is consistent with the conditional for the previous case 
> (lines 7691 to 7693 in this diff).
Oh I see, this seems to be a new thing, starting with e.g. r284288.

Seems fine then, but I'm a little worried that we're adding another variable 
into the matrix here. IIRC, we key dll attribute behaviour off 
`getCXXABI().isMicrosoft()` in lots of places.


https://reviews.llvm.org/D26657



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


[clang-tools-extra] r288258 - [clang-tidy] Make format style customizable

2016-11-30 Thread Jonas Devlieghere via cfe-commits
Author: jdevlieghere
Date: Wed Nov 30 12:06:42 2016
New Revision: 288258

URL: http://llvm.org/viewvc/llvm-project?rev=288258=rev
Log:
[clang-tidy] Make format style customizable

Summary: I came across an outstanding FIXME to make the format style 
customizable. Inspired by the include fixer, I added an new option `-style` to 
configure the fallback style in case no clang-format configuration file is 
found. The default remains "llvm". 

Reviewers: Prazek, aaron.ballman, hokein, alexfh

Subscribers: cfe-commits, malcolm.parsons

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidy.h
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/docs/clang-tidy/index.rst

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=288258=288257=288258=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Wed Nov 30 12:06:42 2016
@@ -88,13 +88,13 @@ private:
 
 class ErrorReporter {
 public:
-  ErrorReporter(bool ApplyFixes)
+  ErrorReporter(bool ApplyFixes, StringRef FormatStyle)
   : Files(FileSystemOptions()), DiagOpts(new DiagnosticOptions()),
 DiagPrinter(new TextDiagnosticPrinter(llvm::outs(), &*DiagOpts)),
 Diags(IntrusiveRefCntPtr(new DiagnosticIDs), &*DiagOpts,
   DiagPrinter),
 SourceMgr(Diags, Files), ApplyFixes(ApplyFixes), TotalFixes(0),
-AppliedFixes(0), WarningsAsErrors(0) {
+AppliedFixes(0), WarningsAsErrors(0), FormatStyle(FormatStyle) {
 DiagOpts->ShowColors = llvm::sys::Process::StandardOutHasColors();
 DiagPrinter->BeginSourceFile(LangOpts);
   }
@@ -196,8 +196,7 @@ public:
   continue;
 }
 StringRef Code = Buffer.get()->getBuffer();
-// FIXME: Make the style customizable.
-format::FormatStyle Style = format::getStyle("file", File, "LLVM");
+format::FormatStyle Style = format::getStyle("file", File, 
FormatStyle);
 llvm::Expected CleanReplacements =
 format::cleanupAroundReplacements(Code, FileAndReplacements.second,
   Style);
@@ -248,6 +247,7 @@ private:
   unsigned TotalFixes;
   unsigned AppliedFixes;
   unsigned WarningsAsErrors;
+  StringRef FormatStyle;
 };
 
 class ClangTidyASTConsumer : public MultiplexConsumer {
@@ -538,8 +538,8 @@ runClangTidy(std::unique_ptr , bool Fix,
-  unsigned ) {
-  ErrorReporter Reporter(Fix);
+  StringRef FormatStyle, unsigned ) {
+  ErrorReporter Reporter(Fix, FormatStyle);
   vfs::FileSystem  =
   *Reporter.getSourceManager().getFileManager().getVirtualFileSystem();
   auto InitialWorkingDir = FileSystem.getCurrentWorkingDirectory();

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.h?rev=288258=288257=288258=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.h Wed Nov 30 12:06:42 2016
@@ -235,9 +235,10 @@ runClangTidy(std::unique_ptr , bool Fix,
-  unsigned );
+  StringRef FormatStyle, unsigned );
 
 /// \brief Serializes replacements into YAML and writes them to the specified
 /// output stream.

Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=288258=288257=288258=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Wed Nov 30 
12:06:42 2016
@@ -49,9 +49,9 @@ Configuration files:
 
 )");
 
-const char DefaultChecks[] =  // Enable these checks by default:
-"clang-diagnostic-*," //   * compiler diagnostics
-"clang-analyzer-*";   //   * Static Analyzer checks
+const char DefaultChecks[] = // Enable these checks by default:
+"clang-diagnostic-*,"//   * compiler diagnostics
+"clang-analyzer-*";  //   * Static Analyzer checks
 
 static cl::opt Checks("checks", cl::desc(R"(
 Comma-separated list of globs with optional '-'
@@ -120,6 +120,13 @@ well.
 )"),
cl::init(false), cl::cat(ClangTidyCategory));
 
+static cl::opt FormatStyle("style", cl::desc(R"(
+Fallback style for reformatting after inserting fixes
+if there is no clang-format config file found.
+)"),
+cl::init("llvm"),
+

Re: [PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-30 Thread Mads Ravn via cfe-commits
I think I got it. I will throw a new diff up within the hour.

Thanks for the ideas :)

On Wed, Nov 30, 2016 at 6:48 PM Malcolm Parsons 
wrote:

> On 30 November 2016 at 17:18, Mads Ravn  wrote:
> > So remove the ifStmt from the third and fourth case?
>
> I was thinking all cases.
> Can the first case be restricted to casts to bool?
> If not, keep the cast to int case with an ifStmt and add a cast to bool
> case.
> Does it matter whether the cast is implicit?
>
> --
> Malcolm Parsons
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26835: [analyzer] Minor fixes and improvements to debug.ExprInspection

2016-11-30 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288257: [analyzer] Minor fixes and improvements to 
debug.ExprInspection (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D26835?vs=78468=79776#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26835

Files:
  cfe/trunk/docs/analyzer/DebugChecks.rst
  cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  cfe/trunk/test/Analysis/expr-inspection.c
  cfe/trunk/test/Analysis/symbol-reaper.c

Index: cfe/trunk/docs/analyzer/DebugChecks.rst
===
--- cfe/trunk/docs/analyzer/DebugChecks.rst
+++ cfe/trunk/docs/analyzer/DebugChecks.rst
@@ -138,6 +138,17 @@
   clang_analyzer_warnIfReached();  // no-warning
 }
 
+- void clang_analyzer_numTimesReached();
+
+  Same as above, but include the number of times this call expression
+  gets reached by the analyzer during the current analysis.
+
+  Example usage::
+
+for (int x = 0; x < 3; ++x) {
+  clang_analyzer_numTimesReached(); // expected-warning{{3}}
+}
+
 - void clang_analyzer_warnOnDeadSymbol(int);
 
   Subscribe for a delayed warning when the symbol that represents the value of
@@ -180,6 +191,18 @@
 clang_analyzer_explain(ptr); // expected-warning{{memory address '0'}}
 }
 
+- void clang_analyzer_dump(a single argument of any type);
+
+  Similar to clang_analyzer_explain, but produces a raw dump of the value,
+  same as SVal::dump().
+
+  Example usage::
+
+void clang_analyzer_dump(int);
+void foo(int x) {
+  clang_analyzer_dump(x); // expected-warning{{reg_$0}}
+}
+
 - size_t clang_analyzer_getExtent(void *);
 
   This function returns the value that represents the extent of a memory region
@@ -197,6 +220,22 @@
   clang_analyzer_explain(ys); // expected-warning{{'8'}}
 }
 
+- void clang_analyzer_printState();
+
+  Dumps the current ProgramState to the stderr. Quickly lookup the program state
+  at any execution point without ViewExplodedGraph or re-compiling the program.
+  This is not very useful for writing tests (apart from testing how ProgramState
+  gets printed), but useful for debugging tests. Also, this method doesn't
+  produce a warning, so it gets printed on the console before all other
+  ExprInspection warnings.
+
+  Example usage::
+
+void foo() {
+  int x = 1;
+  clang_analyzer_printState(); // Read the stderr!
+}
+
 Statistics
 ==
 
Index: cfe/trunk/test/Analysis/expr-inspection.c
===
--- cfe/trunk/test/Analysis/expr-inspection.c
+++ cfe/trunk/test/Analysis/expr-inspection.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=debug.ExprInspection -verify %s 2>&1 | FileCheck %s
+
+// Self-tests for the debug.ExprInspection checker.
+
+void clang_analyzer_dump(int x);
+void clang_analyzer_printState();
+void clang_analyzer_numTimesReached();
+
+void foo(int x) {
+  clang_analyzer_dump(x); // expected-warning{{reg_$0}}
+  int y = 1;
+  clang_analyzer_printState();
+  for (; y < 3; ++y)
+clang_analyzer_numTimesReached(); // expected-warning{{2}}
+}
+
+// CHECK: Store (direct and default bindings)
+// CHECK-NEXT: (y,0,direct) : 1 S32b
+
+// CHECK: Expressions:
+// CHECK-NEXT: clang_analyzer_printState : {clang_analyzer_printState}
+// CHECK-NEXT: Ranges are empty.
Index: cfe/trunk/test/Analysis/symbol-reaper.c
===
--- cfe/trunk/test/Analysis/symbol-reaper.c
+++ cfe/trunk/test/Analysis/symbol-reaper.c
@@ -2,14 +2,18 @@
 
 void clang_analyzer_eval(int);
 void clang_analyzer_warnOnDeadSymbol(int);
+void clang_analyzer_numTimesReached();
 
 int conjure_index();
 
 void test_that_expr_inspection_works() {
   do {
 int x = conjure_index();
 clang_analyzer_warnOnDeadSymbol(x);
   } while(0); // expected-warning{{SYMBOL DEAD}}
+
+  // Make sure we don't accidentally split state in ExprInspection.
+  clang_analyzer_numTimesReached(); // expected-warning{{1}}
 }
 
 // These tests verify the reaping of symbols that are only referenced as
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -18,25 +18,41 @@
 using namespace ento;
 
 namespace {
-class ExprInspectionChecker : public Checker {
+class ExprInspectionChecker : public Checker {
   mutable std::unique_ptr BT;
 
+  // These stats are per-analysis, not per-branch, hence they shouldn't
+  // stay inside the program state.
+  struct ReachedStat {
+ExplodedNode *ExampleNode;
+unsigned NumTimesReached;
+  };
+  mutable 

r288257 - [analyzer] Minor fixes and improvements to debug.ExprInspection

2016-11-30 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Nov 30 11:57:18 2016
New Revision: 288257

URL: http://llvm.org/viewvc/llvm-project?rev=288257=rev
Log:
[analyzer] Minor fixes and improvements to debug.ExprInspection

- Fix the bug with transition handling in ExprInspectionChecker's
  checkDeadSymbols implementation.

- Test this bug by adding a new function clang_analyzer_numTimesReached() to
  catch number of passes through the code, which should be handy for testing
  against unintended state splits.

- Add two more functions should help debugging issues quickly without running
  the debugger or dumping exploded graphs - clang_analyzer_dump() which dump()s
  an SVal argument to a warning message, and clang_analyzer_printState(), which
  dump()s the current program state to stderr.

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

Added:
cfe/trunk/test/Analysis/expr-inspection.c
Modified:
cfe/trunk/docs/analyzer/DebugChecks.rst
cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
cfe/trunk/test/Analysis/symbol-reaper.c

Modified: cfe/trunk/docs/analyzer/DebugChecks.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/analyzer/DebugChecks.rst?rev=288257=288256=288257=diff
==
--- cfe/trunk/docs/analyzer/DebugChecks.rst (original)
+++ cfe/trunk/docs/analyzer/DebugChecks.rst Wed Nov 30 11:57:18 2016
@@ -138,6 +138,17 @@ ExprInspection checks
   clang_analyzer_warnIfReached();  // no-warning
 }
 
+- void clang_analyzer_numTimesReached();
+
+  Same as above, but include the number of times this call expression
+  gets reached by the analyzer during the current analysis.
+
+  Example usage::
+
+for (int x = 0; x < 3; ++x) {
+  clang_analyzer_numTimesReached(); // expected-warning{{3}}
+}
+
 - void clang_analyzer_warnOnDeadSymbol(int);
 
   Subscribe for a delayed warning when the symbol that represents the value of
@@ -180,6 +191,18 @@ ExprInspection checks
 clang_analyzer_explain(ptr); // expected-warning{{memory address '0'}}
 }
 
+- void clang_analyzer_dump(a single argument of any type);
+
+  Similar to clang_analyzer_explain, but produces a raw dump of the value,
+  same as SVal::dump().
+
+  Example usage::
+
+void clang_analyzer_dump(int);
+void foo(int x) {
+  clang_analyzer_dump(x); // expected-warning{{reg_$0}}
+}
+
 - size_t clang_analyzer_getExtent(void *);
 
   This function returns the value that represents the extent of a memory region
@@ -197,6 +220,22 @@ ExprInspection checks
   clang_analyzer_explain(ys); // expected-warning{{'8'}}
 }
 
+- void clang_analyzer_printState();
+
+  Dumps the current ProgramState to the stderr. Quickly lookup the program 
state
+  at any execution point without ViewExplodedGraph or re-compiling the program.
+  This is not very useful for writing tests (apart from testing how 
ProgramState
+  gets printed), but useful for debugging tests. Also, this method doesn't
+  produce a warning, so it gets printed on the console before all other
+  ExprInspection warnings.
+
+  Example usage::
+
+void foo() {
+  int x = 1;
+  clang_analyzer_printState(); // Read the stderr!
+}
+
 Statistics
 ==
 

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp?rev=288257=288256=288257=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp Wed Nov 30 
11:57:18 2016
@@ -18,25 +18,41 @@ using namespace clang;
 using namespace ento;
 
 namespace {
-class ExprInspectionChecker : public Checker {
+class ExprInspectionChecker : public Checker {
   mutable std::unique_ptr BT;
 
+  // These stats are per-analysis, not per-branch, hence they shouldn't
+  // stay inside the program state.
+  struct ReachedStat {
+ExplodedNode *ExampleNode;
+unsigned NumTimesReached;
+  };
+  mutable llvm::DenseMap ReachedStats;
+
   void analyzerEval(const CallExpr *CE, CheckerContext ) const;
   void analyzerCheckInlined(const CallExpr *CE, CheckerContext ) const;
   void analyzerWarnIfReached(const CallExpr *CE, CheckerContext ) const;
+  void analyzerNumTimesReached(const CallExpr *CE, CheckerContext ) const;
   void analyzerCrash(const CallExpr *CE, CheckerContext ) const;
   void analyzerWarnOnDeadSymbol(const CallExpr *CE, CheckerContext ) const;
+  void analyzerDump(const CallExpr *CE, CheckerContext ) const;
   void analyzerExplain(const CallExpr *CE, CheckerContext ) const;
+  void analyzerPrintState(const CallExpr *CE, CheckerContext ) const;
   void analyzerGetExtent(const CallExpr *CE, 

[PATCH] D27270: [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 4/4.

2016-11-30 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

[libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' 
[or 'unsigned int'], possible loss of data", part 4/4.

Change a few allocators' size_type/difference_type from unsigned/int to 
std::size_t/std::ptrdiff_t.

This avoids truncation warnings on x64 when unsigned/int are 32-bit but 
std::size_t/std::ptrdiff_t are 64-bit.


https://reviews.llvm.org/D27270

Files:
  test/std/utilities/allocator.adaptor/types.pass.cpp
  test/support/allocators.h
  test/support/test_allocator.h


Index: test/support/test_allocator.h
===
--- test/support/test_allocator.h
+++ test/support/test_allocator.h
@@ -51,8 +51,8 @@
 template  friend class test_allocator;
 public:
 
-typedef unsigned   
size_type;
-typedef int
difference_type;
+typedef std::size_t
size_type;
+typedef std::ptrdiff_t 
difference_type;
 typedef T  
value_type;
 typedef value_type*pointer;
 typedef const value_type*  
const_pointer;
@@ -112,8 +112,8 @@
 template  friend class non_default_test_allocator;
 public:
 
-typedef unsigned   
size_type;
-typedef int
difference_type;
+typedef std::size_t
size_type;
+typedef std::ptrdiff_t 
difference_type;
 typedef T  
value_type;
 typedef value_type*pointer;
 typedef const value_type*  
const_pointer;
@@ -173,8 +173,8 @@
 template  friend class test_allocator;
 public:
 
-typedef unsigned   
size_type;
-typedef int
difference_type;
+typedef std::size_t
size_type;
+typedef std::ptrdiff_t 
difference_type;
 typedef void   
value_type;
 typedef value_type*pointer;
 typedef const value_type*  
const_pointer;
Index: test/support/allocators.h
===
--- test/support/allocators.h
+++ test/support/allocators.h
@@ -12,6 +12,7 @@
 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 
@@ -85,8 +86,8 @@
 
 typedef T value_type;
 
-typedef unsigned size_type;
-typedef int difference_type;
+typedef std::size_t size_type;
+typedef std::ptrdiff_t difference_type;
 
 typedef std::true_type propagate_on_container_move_assignment;
 
Index: test/std/utilities/allocator.adaptor/types.pass.cpp
===
--- test/std/utilities/allocator.adaptor/types.pass.cpp
+++ test/std/utilities/allocator.adaptor/types.pass.cpp
@@ -27,6 +27,7 @@
 
 #include 
 #include 
+#include 
 
 #include "allocators.h"
 
@@ -76,11 +77,11 @@
 
 static_assert((std::is_same<
 std::scoped_allocator_adaptor::size_type,
-unsigned>::value), "");
+std::size_t>::value), "");
 
 static_assert((std::is_same<
 std::scoped_allocator_adaptor::difference_type,
-int>::value), "");
+std::ptrdiff_t>::value), "");
 
 static_assert((std::is_same<
 std::scoped_allocator_adaptor::pointer,


Index: test/support/test_allocator.h
===
--- test/support/test_allocator.h
+++ test/support/test_allocator.h
@@ -51,8 +51,8 @@
 template  friend class test_allocator;
 public:
 
-typedef unsigned   size_type;
-typedef intdifference_type;
+typedef std::size_tsize_type;
+typedef std::ptrdiff_t difference_type;
 typedef T  value_type;
 typedef value_type*pointer;
 typedef const value_type*  const_pointer;
@@ -112,8 +112,8 @@
 

[PATCH] D27269: [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 3/4.

2016-11-30 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

[libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' 
[or 'unsigned int'], possible loss of data", part 3/4.

test/std/containers/sequences/vector.bool/copy.pass.cpp
test/std/containers/sequences/vector.bool/copy_alloc.pass.cpp
test/std/containers/sequences/vector/vector.cons/copy.pass.cpp
test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp
Change "unsigned s = x.size();" to "typename C::size_type s = x.size();"
because that's what it returns.

test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
Include , then change "unsigned n = T::length(s);"
to "std::size_t n = T::length(s);" because that's what char_traits returns.

test/std/strings/basic.string/string.cons/substr.pass.cpp
Change unsigned to typename S::size_type because that's what str.size() returns.

test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
This was needlessly truncating std::size_t to unsigned.
It's being used to compare and initialize std::size_t.


https://reviews.llvm.org/D27269

Files:
  test/std/containers/sequences/vector.bool/copy.pass.cpp
  test/std/containers/sequences/vector.bool/copy_alloc.pass.cpp
  test/std/containers/sequences/vector/vector.cons/copy.pass.cpp
  test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp
  test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
  test/std/strings/basic.string/string.cons/substr.pass.cpp
  test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp

Index: test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
===
--- test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
+++ test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
@@ -22,7 +22,7 @@
 {
 TEST_CONSTEXPR std::bitset v(0xULL);
 assert(v.size() == N);
-unsigned M = std::min(N, 64);
+std::size_t M = std::min(N, 64);
 for (std::size_t i = 0; i < M; ++i)
 assert(v[i] == ((i & 1) != 0));
 for (std::size_t i = M; i < N; ++i)
Index: test/std/strings/basic.string/string.cons/substr.pass.cpp
===
--- test/std/strings/basic.string/string.cons/substr.pass.cpp
+++ test/std/strings/basic.string/string.cons/substr.pass.cpp
@@ -39,7 +39,7 @@
 {
 S s2(str, pos);
 LIBCPP_ASSERT(s2.__invariants());
-unsigned rlen = str.size() - pos;
+typename S::size_type rlen = str.size() - pos;
 assert(s2.size() == rlen);
 assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
 assert(s2.get_allocator() == A());
@@ -71,7 +71,7 @@
 {
 S s2(str, pos, n);
 LIBCPP_ASSERT(s2.__invariants());
-unsigned rlen = std::min(str.size() - pos, n);
+typename S::size_type rlen = std::min(str.size() - pos, n);
 assert(s2.size() == rlen);
 assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
 assert(s2.get_allocator() == A());
@@ -104,7 +104,7 @@
 {
 S s2(str, pos, n, a);
 LIBCPP_ASSERT(s2.__invariants());
-unsigned rlen = std::min(str.size() - pos, n);
+typename S::size_type rlen = std::min(str.size() - pos, n);
 assert(s2.size() == rlen);
 assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
 assert(s2.get_allocator() == a);
Index: test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
===
--- test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
+++ test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 #include "test_allocator.h"
@@ -27,7 +28,7 @@
 typedef std::basic_string S;
 typedef typename S::traits_type T;
 typedef typename S::allocator_type A;
-unsigned n = T::length(s);
+std::size_t n = T::length(s);
 S s2(s);
 LIBCPP_ASSERT(s2.__invariants());
 assert(s2.size() == n);
@@ -42,7 +43,7 @@
 {
 typedef std::basic_string S;
 typedef typename S::traits_type T;
-unsigned n = T::length(s);
+std::size_t n = T::length(s);
 S s2(s, a);
 LIBCPP_ASSERT(s2.__invariants());
 assert(s2.size() == n);
Index: test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp
===
--- test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp
+++ test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp
@@ -23,7 +23,7 @@
 void
 test(const C& x, const typename C::allocator_type& a)
 {
-unsigned s = x.size();
+typename C::size_type s 

[PATCH] D27268: [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 2/4.

2016-11-30 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

[libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' 
[or 'unsigned int'], possible loss of data", part 2/4.

Use static_cast when storing size_t in int (or passing size_t to int).

Also, remove a spurious semicolon in test/support/archetypes.hpp.


https://reviews.llvm.org/D27268

Files:
  
test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp
  test/support/archetypes.hpp
  test/support/count_new.hpp


Index: test/support/count_new.hpp
===
--- test/support/count_new.hpp
+++ test/support/count_new.hpp
@@ -79,7 +79,7 @@
 }
 ++new_called;
 ++outstanding_new;
-last_new_size = s;
+last_new_size = static_cast(s);
 }
 
 void deleteCalled(void * p)
@@ -101,7 +101,7 @@
 }
 ++outstanding_array_new;
 ++new_array_called;
-last_new_array_size = s;
+last_new_array_size = static_cast(s);
 }
 
 void deleteArrayCalled(void * p)
@@ -304,10 +304,10 @@
 void requireExactly(std::size_t N) { m_req_alloc = N; m_exactly = true; }
 
 ~RequireAllocationGuard() {
-
assert(globalMemCounter.checkOutstandingNewEq(m_outstanding_new_on_init));
+
assert(globalMemCounter.checkOutstandingNewEq(static_cast(m_outstanding_new_on_init)));
 std::size_t Expect = m_new_count_on_init + m_req_alloc;
-assert(globalMemCounter.checkNewCalledEq(Expect) ||
-   (!m_exactly && 
globalMemCounter.checkNewCalledGreaterThan(Expect)));
+assert(globalMemCounter.checkNewCalledEq(static_cast(Expect)) ||
+   (!m_exactly && 
globalMemCounter.checkNewCalledGreaterThan(static_cast(Expect;
 }
 
 private:
Index: test/support/archetypes.hpp
===
--- test/support/archetypes.hpp
+++ test/support/archetypes.hpp
@@ -69,11 +69,11 @@
 }
 template ::type = true>
 explicit TestBase(std::initializer_list& il, int = 0) noexcept
-  : value(il.size()) {
+  : value(static_cast(il.size())) {
 ++alive; ++constructed; ++value_constructed;
 }
 template ::type = true>
-explicit TestBase(std::initializer_list& il, int = 0) noexcept : 
value(il.size()) {
+explicit TestBase(std::initializer_list& il, int = 0) noexcept : 
value(static_cast(il.size())) {
 ++alive; ++constructed; ++value_constructed;
 }
 TestBase& operator=(int xvalue) noexcept {
@@ -135,9 +135,9 @@
 template ::type = true>
 constexpr ValueBase(int, int y) : value(y) {}
 template ::type = true>
-explicit constexpr ValueBase(std::initializer_list& il, int = 0) : 
value(il.size()) {}
+explicit constexpr ValueBase(std::initializer_list& il, int = 0) : 
value(static_cast(il.size())) {}
 template ::type = true>
-constexpr ValueBase(std::initializer_list& il, int = 0) : 
value(il.size()) {}
+constexpr ValueBase(std::initializer_list& il, int = 0) : 
value(static_cast(il.size())) {}
 TEST_CONSTEXPR_CXX14 ValueBase& operator=(int xvalue) noexcept {
 value = xvalue;
 return *this;
@@ -193,9 +193,9 @@
 template ::type = true>
 constexpr TrivialValueBase(int, int y) : value(y) {}
 template ::type = true>
-explicit constexpr TrivialValueBase(std::initializer_list& il, int = 
0) : value(il.size()) {}
+explicit constexpr TrivialValueBase(std::initializer_list& il, int = 
0) : value(static_cast(il.size())) {}
 template ::type = true>
-constexpr TrivialValueBase(std::initializer_list& il, int = 0) : 
value(il.size()) {};
+constexpr TrivialValueBase(std::initializer_list& il, int = 0) : 
value(static_cast(il.size())) {}
 int value;
 protected:
 constexpr TrivialValueBase() noexcept : value(0) {}
Index: 
test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp
===
--- 
test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp
+++ 
test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp
@@ -23,9 +23,9 @@
 struct TestT {
   int x;
   int size;
-  constexpr TestT(std::initializer_list il) : x(*il.begin()), 
size(il.size()) {}
+  constexpr TestT(std::initializer_list il) : x(*il.begin()), 
size(static_cast(il.size())) {}
   constexpr TestT(std::initializer_list il, const int*)
-  : x(*il.begin()), size(il.size()) {}
+  : x(*il.begin()), size(static_cast(il.size())) {}
 };
 
 int main()


Index: test/support/count_new.hpp
===
--- test/support/count_new.hpp
+++ test/support/count_new.hpp
@@ -79,7 +79,7 @@
 }
 ++new_called;
 ++outstanding_new;
-

[PATCH] D27267: [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 1/4.

2016-11-30 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

[libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' 
[or 'unsigned int'], possible loss of data", part 1/4.

Replace "int n = str_.size();" with "int n = static_cast(str_.size());".

int is the correct type to use, because we're eventually calling
"base::pbump(n+1);" where base is std::basic_streambuf.
N4606 27.6.3.3.3 [streambuf.put.area]/4 declares: "void pbump(int n);"


https://reviews.llvm.org/D27267

Files:
  test/std/input.output/iostream.format/ext.manip/put_time.pass.cpp
  
test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf.pass.cpp
  
test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf_chart.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/bool.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/double.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/float.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/int.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_double.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_long.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/short.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_int.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long_long.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_short.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/CharT.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/CharT_pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_to_wide.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_to_wide_pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char_pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char_pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/basic_ios.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ios_base.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ostream.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.manip/endl.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.manip/ends.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.rvalue/CharT_pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.unformatted/put.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp

Index: test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp
===
--- test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp
+++ test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp
@@ -38,7 +38,7 @@
 {
 if (__c != base::traits_type::eof())
 {
-

[PATCH] D27266: [libcxx] [test] Remove spurious semicolons.

2016-11-30 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

[libcxx] [test] Remove spurious semicolons.


https://reviews.llvm.org/D27266

Files:
  
test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash_equal_allocator.pass.cpp
  
test/std/input.output/string.streams/ostringstream/ostringstream.assign/member_swap.pass.cpp
  
test/std/input.output/string.streams/ostringstream/ostringstream.assign/move.pass.cpp
  
test/std/input.output/string.streams/ostringstream/ostringstream.assign/nonmember_swap.pass.cpp
  
test/std/input.output/string.streams/ostringstream/ostringstream.cons/move.pass.cpp
  
test/std/input.output/string.streams/ostringstream/ostringstream.cons/string.pass.cpp
  
test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/overflow.pass.cpp
  
test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/pbackfail.pass.cpp
  test/std/utilities/template.bitset/bitset.operators/op_and.pass.cpp
  test/std/utilities/template.bitset/bitset.operators/op_not.pass.cpp
  test/std/utilities/template.bitset/bitset.operators/op_or.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp
  test/support/uses_alloc_types.hpp

Index: test/support/uses_alloc_types.hpp
===
--- test/support/uses_alloc_types.hpp
+++ test/support/uses_alloc_types.hpp
@@ -214,7 +214,7 @@
 : Base(()) {}
 // Non-Uses Allocator Ctor
 template  = false>
-UsesAllocatorV1(Args&&... args) : Base(()) {};
+UsesAllocatorV1(Args&&... args) : Base(()) {}
 
 // Uses Allocator Arg Ctor
 template 
@@ -248,7 +248,7 @@
 
 // Non-Uses Allocator Ctor
 template  = false>
-UsesAllocatorV2(Args&&... args) : Base(()) {};
+UsesAllocatorV2(Args&&... args) : Base(()) {}
 
 // Uses Allocator Last Ctor
 template  = false>
@@ -274,7 +274,7 @@
 
 // Non-Uses Allocator Ctor
 template  = false>
-UsesAllocatorV3(Args&&... args) : Base(()) {};
+UsesAllocatorV3(Args&&... args) : Base(()) {}
 
 // Uses Allocator Arg Ctor
 template 
@@ -305,7 +305,7 @@
 : Base(()) {}
 // Non-Uses Allocator Ctor
 template  = false>
-NotUsesAllocator(Args&&... args) : Base(()) {};
+NotUsesAllocator(Args&&... args) : Base(()) {}
 
 // Uses Allocator Arg Ctor
 template 
Index: test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp
===
--- test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp
@@ -19,7 +19,7 @@
 
 #include 
 
-template  void cref(T const&) {};
+template  void cref(T const&) {}
 template  void cref(T const&&) = delete;
 
 std::tuple const tup4() { return std::make_tuple(4); }
Index: test/std/utilities/template.bitset/bitset.operators/op_or.pass.cpp
===
--- test/std/utilities/template.bitset/bitset.operators/op_or.pass.cpp
+++ test/std/utilities/template.bitset/bitset.operators/op_or.pass.cpp
@@ -33,7 +33,7 @@
 std::bitset v1 = make_bitset();
 std::bitset v2 = make_bitset();
 std::bitset v3 = v1;
-assert((v1 | v2) == (v3 |= v2));;
+assert((v1 | v2) == (v3 |= v2));
 }
 
 int main()
Index: test/std/utilities/template.bitset/bitset.operators/op_not.pass.cpp
===
--- test/std/utilities/template.bitset/bitset.operators/op_not.pass.cpp
+++ test/std/utilities/template.bitset/bitset.operators/op_not.pass.cpp
@@ -33,7 +33,7 @@
 std::bitset v1 = make_bitset();
 std::bitset v2 = make_bitset();
 std::bitset v3 = v1;
-assert((v1 ^ v2) == (v3 ^= v2));;
+assert((v1 ^ v2) == (v3 ^= v2));
 }
 
 int main()
Index: test/std/utilities/template.bitset/bitset.operators/op_and.pass.cpp
===
--- test/std/utilities/template.bitset/bitset.operators/op_and.pass.cpp
+++ test/std/utilities/template.bitset/bitset.operators/op_and.pass.cpp
@@ -33,7 +33,7 @@
 std::bitset v1 = make_bitset();
 std::bitset v2 = make_bitset();
 std::bitset v3 = v1;
-assert((v1 & v2) == (v3 &= v2));;
+assert((v1 & v2) == (v3 &= v2));
 }
 
 int main()
Index: test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/pbackfail.pass.cpp
===
--- test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/pbackfail.pass.cpp
+++ test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/pbackfail.pass.cpp
@@ -36,7 +36,7 @@
 int main()
 {
 {  // sanity check
-testbuf tb("");;
+testbuf tb("");
 tb.pbackfail();
 }
 {
Index: 

[PATCH] D27091: Add the way to extract SVals of arguments used in a call for a given StackFrameCtx

2016-11-30 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

> Hmm, i'm thinking of just the opposite - refactor the CallEvent methods to 
> use the respective new  ProgramState methods.
> 
> This way we'd avoid touching the CallEvent allocator for a simple Environment 
> lookup, while still avoiding code duplication.

I see what you are suggesting, but I still have the concerns I've mentioned in 
my first comment. **The whole purpose of CallEvent is to allow an easy and 
lightweight way of dealing with all the different types of calls**, which is 
exactly what we are doing in this checker. CallEvent is used for this exact 
purpose elsewhere throughout the analyzer. What do you mean by "touching  the 
CallEvent allocator" and why would you want to discourage that?

CallEventManager::getCaller contains logic to dispatch to different CallEvent 
types depending on what call we are dealing with. The argument lookup will 
depend on type of the call. The method added in this PR does not deal with all 
call types, but only with CallExpr, so you'd need to duplicate the code from 
CallEvent construction to here.

As I've mentioned before, I do not think that Call dispatch logic and API for 
looking up arguments SVals should belong to ProgramState as it is a higher 
abstraction and should not reason about LocationContexts or Calls (which are 
part of Program Location and AST respectively). In addition, using CallEven to 
look up argument values is much simpler to understand for API users.


https://reviews.llvm.org/D27091



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


[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection

2016-11-30 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh updated this revision to Diff 79770.
danielcdh added a comment.

change the flag name to -fprofile-debug


https://reviews.llvm.org/D25435

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/clang_f_opts.c


Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -469,3 +469,8 @@
 // CHECK-WCHAR2: -fshort-wchar
 // CHECK-WCHAR2-NOT: -fno-short-wchar
 // DELIMITERS: {{^ *"}}
+
+// RUN: %clang -### -S -fno-profile-debug -fprofile-debug %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-DEBUG %s
+// RUN: %clang -### -S -fprofile-debug -fno-profile-debug %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-PROFILE-DEBUG %s
+// CHECK-PROFILE-DEBUG: -fprofile-debug
+// CHECK-NO-PROFILE-DEBUG-NOT: -fprofile-debug
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -538,6 +538,8 @@
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
+  Opts.ProfileDebug = Args.hasFlag(OPT_fprofile_debug,
+OPT_fno_profile_debug, false);
 
   setPGOInstrumentor(Opts, Args, Diags);
   Opts.InstrProfileOutput =
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5508,6 +5508,10 @@
   A->render(Args, CmdArgs);
   }
 
+  if (Args.hasFlag(options::OPT_fprofile_debug,
+   options::OPT_fno_profile_debug, false))
+CmdArgs.push_back("-fprofile-debug");
+
   // -fbuiltin is default unless -mkernel is used.
   bool UseBuiltins =
   Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -2739,9 +2739,10 @@
   }
   // No need to replicate the linkage name if it isn't different from the
   // subprogram name, no need to have it at all unless coverage is enabled or
-  // debug is set to more than just line tables.
+  // debug is set to more than just line tables or extra debug info is needed.
   if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs &&
   !CGM.getCodeGenOpts().EmitGcovNotes &&
+  !CGM.getCodeGenOpts().ProfileDebug &&
   DebugKind <= 
codegenoptions::DebugLineTablesOnly))
 LinkageName = StringRef();
 
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -576,6 +576,7 @@
   Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
   Options.CompressDebugSections = CodeGenOpts.CompressDebugSections;
   Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
+  Options.ProfileDebug = CodeGenOpts.ProfileDebug;
 
   // Set EABI version.
   Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion)
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -256,6 +256,9 @@
 /// Whether copy relocations support is available when building as PIE.
 CODEGENOPT(PIECopyRelocations, 1, 0)
 
+/// Whether emit extra debug info for sample pgo profile collection.
+CODEGENOPT(ProfileDebug, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -509,6 +509,12 @@
 HelpText<"Enable sample-based profile guided optimizations">;
 def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,
 Alias;
+def fprofile_debug : Flag<["-"], "fprofile-debug">, Group,
+Flags<[CC1Option]>,
+HelpText<"Emit extra debug info to make sample profile more accurate.">;
+def fno_profile_debug : Flag<["-"], "fno-profile-debug">, Group,
+Flags<[DriverOption]>,
+HelpText<"Do not emit extra debug info for sample profiler.">;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Flags<[DriverOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overriden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: test/Driver/clang_f_opts.c
===
--- 

Re: [PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-30 Thread Malcolm Parsons via cfe-commits
On 30 November 2016 at 17:18, Mads Ravn  wrote:
> So remove the ifStmt from the third and fourth case?

I was thinking all cases.
Can the first case be restricted to casts to bool?
If not, keep the cast to int case with an ifStmt and add a cast to bool case.
Does it matter whether the cast is implicit?

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


Re: [RFC] Embedded bitcode and related upstream (Part II)

2016-11-30 Thread Alex L via cfe-commits
On 30 November 2016 at 15:46, Nico Weber via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hi Steven,
>
> On Fri, Jun 3, 2016 at 2:36 PM, Steven Wu via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Hi everyone
>>
>> I am still in the process of upstreaming some improvements to the embed
>> bitcode option. If you want more background, you can read the previous RFC (
>> http://lists.llvm.org/pipermail/llvm-dev/2016-February/094851.html).
>> This is part II of the discussion.
>>
>> Current Status:
>> A basic version of -fembed-bitcode option is upstreamed and functioning.
>> You can use -fembed-bitcode={off, all, bitcode, marker} option to control
>> what gets embedded in the final object file output:
>> off: default, nothing gets embedded.
>> all: optimized bitcode and command line options gets embedded in the
>> object file.
>> bitcode: only optimized bitcode is embedded
>> marker: only put a marker in the object file
>>
>> What needs to be improved:
>> 1. Whitelist for command line options that can be used with bitcode:
>> Current trunk implementation embeds all the cc1 command line options
>> (that includes header include paths, warning flags and other front-end
>> options) in the command line section. That is lot of redundant information.
>> To re-create the object file from the embedded optimized bitcode, most of
>> these options are useless. On the other hand, they can leak information of
>> the source code. One solution will be keeping a list of all the options
>> that can affect code generation but not encoded in the bitcode. I have
>> internally prototyped with disallowing these options explicitly and allowed
>> only the reminder of the  options to be embedded (
>> http://reviews.llvm.org/D17394). A better solution might be encoding
>> that information in "Options.td" as specific group.
>>
>> 2. Assembly input handling:
>> This is a workaround to allow source code written in assembly to work
>> with "-fembed-bitcode" options. When compiling assembly source code with
>> "-fembed-bitcode", clang-as creates an empty section "__LLVM, __asm" in the
>> object file. That is just a way to distinguish object files compiled from
>> assembly source from those compiled from higher level source code but
>> forgot to use "-fembed-bitcode" options. Linker can use this section to
>> diagnose if "-fembed-bitcode" is consistently used on all the object files
>> participated in the linking.
>>
>
> It looks like shipping Xcode's clang has this behavior, but open-source
> clang still doesn't. Can you contribute it? It's very useful to us if
> open-source clang has the same features as the clang shipping in Xcode.
> (That last sentence is true in general, not just for this specific feature.)
>

Just FYI, Steven is away on vacation for a month. I think he should be back
in January.


>
>
>>
>> 3. Bitcode symbol hiding:
>> There was some concerns for leaking source code information when using
>> bitcode feature. One approach to avoid the leak is to add a pass which
>> renames all the globals and metadata strings. The also keeps a reverse map
>> in case the original name needs to be recovered. The final bitcode should
>> contain no more symbols or debug info than a stripped binary. To make sure
>> modified bitcode can still be linked correctly, the renaming need to be
>> consistent across all bitcode participated in the linking and everything
>> that is external of the linkage unit need to be preserved. This means the
>> pass can only be run during the linking and requires some LTO api.
>>
>> 4. Debug info strip to line-tables pass:
>> As the name suggested, this pass strip down the full debug info to
>> line-tables only. This is also one of the steps we took to prevent the leak
>> of source code information in bitcode.
>>
>> Please let me know what do you think about the pieces above or if you
>> have any concerns about the methodology. I will put up patches for review
>> soon.
>>
>> Thanks
>>
>> Steven
>>
>> ___
>> 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] D27263: Address of bitfield in anonymous struct doesn't error.

2016-11-30 Thread Jacob Young via Phabricator via cfe-commits
jacobly created this revision.
jacobly added a subscriber: cfe-commits.

  struct A {
struct {
  int B : 1;
}
  }
  int A::*addr_anon_bitfield() {
  return ::B;
  }

This code does not error, but instead returns a member pointer to a full int 
that starts at the beginning of the byte the bitfield starts on.


https://reviews.llvm.org/D27263

Files:
  /home/jacob/Source/llvm/tools/clang/lib/Sema/SemaExpr.cpp
  /home/jacob/Source/llvm/tools/clang/test/Sema/expr-address-of.c
  /home/jacob/Source/llvm/tools/clang/test/SemaCXX/anonymous-struct.cpp
  /home/jacob/Source/llvm/tools/clang/test/SemaCXX/ptrtomember.cpp


Index: /home/jacob/Source/llvm/tools/clang/test/SemaCXX/ptrtomember.cpp
===
--- /home/jacob/Source/llvm/tools/clang/test/SemaCXX/ptrtomember.cpp
+++ /home/jacob/Source/llvm/tools/clang/test/SemaCXX/ptrtomember.cpp
@@ -13,9 +13,13 @@
 
 struct S2 {
   int bitfield : 1;
+  struct {
+int anon_bitfield : 1;
+  };
 };
 
 int S2::*pf = ::bitfield; // expected-error {{address of bit-field 
requested}}
+int S2::*anon_pf = ::anon_bitfield; // expected-error {{address of 
bit-field requested}}
 
 struct S3 {
   void m();
Index: /home/jacob/Source/llvm/tools/clang/test/SemaCXX/anonymous-struct.cpp
===
--- /home/jacob/Source/llvm/tools/clang/test/SemaCXX/anonymous-struct.cpp
+++ /home/jacob/Source/llvm/tools/clang/test/SemaCXX/anonymous-struct.cpp
@@ -21,6 +21,9 @@
   };
   static struct {
   };
+  class {
+int anon_priv_field; // expected-error {{anonymous struct cannot contain a 
private data member}}
+  };
 };
 
 template  void foo(T);
Index: /home/jacob/Source/llvm/tools/clang/test/Sema/expr-address-of.c
===
--- /home/jacob/Source/llvm/tools/clang/test/Sema/expr-address-of.c
+++ /home/jacob/Source/llvm/tools/clang/test/Sema/expr-address-of.c
@@ -102,8 +102,9 @@
   register struct {char* x;} t1 = {"Hello"};
   char* dummy1 = &(t1.x[0]);
 
-  struct {int a : 10;} t2;
+  struct {int a : 10; struct{int b : 10;};} t2;
   int* dummy2 = &(t2.a); // expected-error {{address of bit-field requested}}
+  int* dummy3 = &(t2.b); // expected-error {{address of bit-field requested}}
 
   void* t3 = &(*(void*)0);
 }
Index: /home/jacob/Source/llvm/tools/clang/lib/Sema/SemaExpr.cpp
===
--- /home/jacob/Source/llvm/tools/clang/lib/Sema/SemaExpr.cpp
+++ /home/jacob/Source/llvm/tools/clang/lib/Sema/SemaExpr.cpp
@@ -1762,7 +1762,10 @@
   !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->getLocStart()))
   recordUseOfEvaluatedWeak(E);
 
-  if (FieldDecl *FD = dyn_cast(D)) {
+  FieldDecl *FD = dyn_cast(D);
+  if (IndirectFieldDecl *IFD = dyn_cast(D))
+FD = IFD->getAnonField();
+  if (FD) {
 UnusedPrivateFields.remove(FD);
 // Just in case we're building an illegal pointer-to-member.
 if (FD->isBitField())


Index: /home/jacob/Source/llvm/tools/clang/test/SemaCXX/ptrtomember.cpp
===
--- /home/jacob/Source/llvm/tools/clang/test/SemaCXX/ptrtomember.cpp
+++ /home/jacob/Source/llvm/tools/clang/test/SemaCXX/ptrtomember.cpp
@@ -13,9 +13,13 @@
 
 struct S2 {
   int bitfield : 1;
+  struct {
+int anon_bitfield : 1;
+  };
 };
 
 int S2::*pf = ::bitfield; // expected-error {{address of bit-field requested}}
+int S2::*anon_pf = ::anon_bitfield; // expected-error {{address of bit-field requested}}
 
 struct S3 {
   void m();
Index: /home/jacob/Source/llvm/tools/clang/test/SemaCXX/anonymous-struct.cpp
===
--- /home/jacob/Source/llvm/tools/clang/test/SemaCXX/anonymous-struct.cpp
+++ /home/jacob/Source/llvm/tools/clang/test/SemaCXX/anonymous-struct.cpp
@@ -21,6 +21,9 @@
   };
   static struct {
   };
+  class {
+int anon_priv_field; // expected-error {{anonymous struct cannot contain a private data member}}
+  };
 };
 
 template  void foo(T);
Index: /home/jacob/Source/llvm/tools/clang/test/Sema/expr-address-of.c
===
--- /home/jacob/Source/llvm/tools/clang/test/Sema/expr-address-of.c
+++ /home/jacob/Source/llvm/tools/clang/test/Sema/expr-address-of.c
@@ -102,8 +102,9 @@
   register struct {char* x;} t1 = {"Hello"};
   char* dummy1 = &(t1.x[0]);
 
-  struct {int a : 10;} t2;
+  struct {int a : 10; struct{int b : 10;};} t2;
   int* dummy2 = &(t2.a); // expected-error {{address of bit-field requested}}
+  int* dummy3 = &(t2.b); // expected-error {{address of bit-field requested}}
 
   void* t3 = &(*(void*)0);
 }
Index: /home/jacob/Source/llvm/tools/clang/lib/Sema/SemaExpr.cpp
===
--- /home/jacob/Source/llvm/tools/clang/lib/Sema/SemaExpr.cpp
+++ 

[PATCH] D27254: Protect optional test under libcpp-no-exceptions

2016-11-30 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 updated this revision to Diff 79765.
rogfer01 added a comment.

Protect the right set of tests.


https://reviews.llvm.org/D27254

Files:
  test/std/experimental/optional/optional.specalg/swap.pass.cpp


Index: test/std/experimental/optional/optional.specalg/swap.pass.cpp
===
--- test/std/experimental/optional/optional.specalg/swap.pass.cpp
+++ test/std/experimental/optional/optional.specalg/swap.pass.cpp
@@ -8,7 +8,6 @@
 
//===--===//
 
 // UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template  void swap(optional& x, optional& y)
@@ -18,6 +17,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 using std::experimental::optional;
 
 class X
@@ -55,10 +56,10 @@
 int i_;
 public:
 Z(int i) : i_(i) {}
-Z(Z&&) {throw 7;}
+Z(Z&&) {TEST_THROW(7);}
 
 friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == 
y.i_;}
-friend void swap(Z& x, Z& y) {throw 6;}
+friend void swap(Z& x, Z& y) {TEST_THROW(6);}
 };
 
 int main()
@@ -231,6 +232,7 @@
 assert(static_cast(opt1) == false);
 assert(static_cast(opt2) == false);
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 optional opt1;
 opt1.emplace(1);
@@ -297,4 +299,5 @@
 assert(static_cast(opt2) == true);
 assert(*opt2 == 2);
 }
+#endif  // TEST_HAS_NO_EXCEPTIONS
 }


Index: test/std/experimental/optional/optional.specalg/swap.pass.cpp
===
--- test/std/experimental/optional/optional.specalg/swap.pass.cpp
+++ test/std/experimental/optional/optional.specalg/swap.pass.cpp
@@ -8,7 +8,6 @@
 //===--===//
 
 // UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template  void swap(optional& x, optional& y)
@@ -18,6 +17,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 using std::experimental::optional;
 
 class X
@@ -55,10 +56,10 @@
 int i_;
 public:
 Z(int i) : i_(i) {}
-Z(Z&&) {throw 7;}
+Z(Z&&) {TEST_THROW(7);}
 
 friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}
-friend void swap(Z& x, Z& y) {throw 6;}
+friend void swap(Z& x, Z& y) {TEST_THROW(6);}
 };
 
 int main()
@@ -231,6 +232,7 @@
 assert(static_cast(opt1) == false);
 assert(static_cast(opt2) == false);
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 optional opt1;
 opt1.emplace(1);
@@ -297,4 +299,5 @@
 assert(static_cast(opt2) == true);
 assert(*opt2 == 2);
 }
+#endif  // TEST_HAS_NO_EXCEPTIONS
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27254: Protect optional test under libcpp-no-exceptions

2016-11-30 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added inline comments.



Comment at: test/std/experimental/optional/optional.specalg/swap.pass.cpp:225
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {

mclow.lists wrote:
> Why is this here, and not before line L#236?
Yep, I'm wrong here. Probably a fallout of an early version where I protected 
the definition of Z instead before using TEST_THROW. 


https://reviews.llvm.org/D27254



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


Re: [PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-30 Thread Mads Ravn via cfe-commits
So remove the ifStmt from the third and fourth case?

So that I keep if(str1.compare(str2)) and if(!str1.compare(str2)), and
change the other two to str1.compare(str2) == 0 and str1.compare(str2) != 0
?

That makes good sense. Then I could also add some of the test cases you
mentioned earlier.

On Wed, Nov 30, 2016 at 5:59 PM Malcolm Parsons via Phabricator <
revi...@reviews.llvm.org> wrote:

> malcolm.parsons added a comment.
>
> I don't know why you're restricting this check to only match within the
> condition of an if statement.
>
>
> https://reviews.llvm.org/D27210
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27251: [PPC] some bugs mainly about sign problem fixed in altivec.h

2016-11-30 Thread Tony Jiang via Phabricator via cfe-commits
jtony added inline comments.



Comment at: lib/Headers/altivec.h:16456
 
 #ifdef __VSX__
 static __inline__ vector signed long long __ATTRS_o_ai

Thanks  a lot for your good catch for the macro issue in vec_xst_be, that's a 
good catch. BTW, Can you move this up also like vec_xst_be?



Comment at: test/CodeGen/builtins-ppc-vsx.c:1696
+
+signed char param_sc;
+unsigned char param_uc;

I would prefer these definitions occur at the beginning of the file like 
before. 



Comment at: test/CodeGen/builtins-ppc-vsx.c:1706
+/* - vec_xl_be -- 
*/
+void test2() {
+  // CHECK-LABEL: define void @test2

These test cases should be grouped together with the test  cases from 1663 - 
1683. Put the vec_xl_be overloads together,  and the vec_xst_be together (maybe 
after vec_xl_be). I am OK with either put these test2 and test3 into test 1, or 
make them stand-alone, as long as these overloaded test cases for vec_xst_be 
and vec_xl_be are put together seperately. Thanks for you good catch, this 
problem is not found in our previous code review.


https://reviews.llvm.org/D27251



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-30 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

I don't know why you're restricting this check to only match within the 
condition of an if statement.


https://reviews.llvm.org/D27210



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


[PATCH] D27199: [libcxx] Make std::ignore constexpr

2016-11-30 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.
This revision is now accepted and ready to land.

This looks good to me.


https://reviews.llvm.org/D27199



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-30 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 79747.
madsravn marked 2 inline comments as done.
madsravn added a comment.

Added integerLiteral on both sides of the == operator.


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringCompareCheck.cpp
  clang-tidy/misc/StringCompareCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,49 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template , typename A = std::allocator >
+struct basic_string {
+  basic_string();
+  basic_string(const C*, unsigned int size);
+  int compare(const basic_string& str);
+};
+  bool operator==(const basic_string lhs, const basic_string rhs);
+  bool operator!=(const basic_string lhs, const basic_string rhs);
+typedef basic_string string;
+}
+
+
+
+void Test() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+
+  if(str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(!str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) == 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) != 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(0 == str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(0 != str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+
+}
+
+void Valid() {
+std::string str1("a", 1);
+std::string str2("b", 1);
+if(str1 == str2) {}
+if(str1 != str2) {}
+if(str1.compare(str2) == 1) {}
+if(str1.compare(str2) == str1.compare(str2)) {}
+if(0 == 0) {}
+if(1 == str1.compare(str2)) {}
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
===
--- docs/clang-tidy/checks/misc-string-compare.rst
+++ docs/clang-tidy/checks/misc-string-compare.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - misc-string-compare
+
+misc-string-compare
+===
+
+Finds string comparisons using the compare method.
+
+A common mistake is to use the string's ``compare`` method instead of using the 
+equality or inequality operators. The compare method is intended for sorting
+functions and thus returns ``-1``, ``0`` or ``1`` depending on the lexicographical 
+relationship between the strings compared. If an equality or inequality check
+can suffice, that is recommended.
+
+Examples:
+
+.. code-block:: c++
+
+  std::string str1{"a"};
+  std::string str2{"b"};
+  
+  if(str1.compare(str2)) {} // use str1 != str2 instead
+  
+  if(!str1.compare(str2)) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) == 0) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) != 0) {} // use str1 != str2 instead
+
+  if(0 == str1.compare(str2)) {} // use str1 == str2 instead
+
+  if(0 != str1.compare(str2)) {} // use str1 != str2 instead
+
+The above code examples shows the list of if-statements that this check will
+give a warning for. All of them uses ``compare`` to check if equality or 
+inequality of two strings instead of using the correct operators.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -80,6 +80,7 @@
misc-sizeof-container
misc-sizeof-expression
misc-static-assert
+   misc-string-compare
misc-string-constructor
misc-string-integer-assignment
misc-string-literal-with-embedded-nul
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -75,6 +75,11 @@
 
 - `misc-pointer-and-integral-operation` check was removed.
 
+- New `misc-string-compare
+  `_ check
+
+  Warns about using ``compare`` to test for string equality or ineqaulity.
+
 

[PATCH] D26137: [clang-tidy] Add check name to YAML export

2016-11-30 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

Looks mostly good. A few more nits.




Comment at: include/clang/Tooling/Core/Diagnostic.h:68-71
+  /// A freeform chunk of text to describe the context of the replacements.
+  /// Will be printed, for example, when detecting conflicts during replacement
+  /// deduplication.
+  std::string Context;

Alpha wrote:
> alexfh wrote:
> > That's too vague. Are you intending to use it only for reporting problems 
> > with replacement deduplication? Should it be in this structure at all?
> This was actually left to keep compatibility with 
> `TranslationUnitReplacements` which was used for the export.
> But it seems that even for that structure, there is in all likelihood no 
> reference to any use of the `Context` field, except in test cases and in the 
> Yaml IO mapping, where it is marked as an optional entry.
> Should it be discarded instead (here, and thus also in 
> `TranslationUnitReplacements`)?
Yes, it seems we can just remove the `Context` field.



Comment at: include/clang/Tooling/Core/Diagnostic.h:36
+  /// \brief Constructs a diagnostic message with anoffset to the diagnostic
+  /// within the file where the problem occured
+  ///

nit: Add a trailing period.



Comment at: include/clang/Tooling/DiagnosticsYaml.h:35
+NormalizedDiagnostic(const IO &)
+: DiagnosticName(""), Message(), Fix(), Notes(), DiagLevel() {}
+

Initializers for non-trivial members are superfluous. Looks like only 
`DiagLevel` initializer makes sense, but I'd use an explicit value for it. 



Comment at: include/clang/Tooling/DiagnosticsYaml.h:58
+std::vector Fixes;
+for (auto & Replacements : Keys->Fix) {
+   for (auto & Replacement : Replacements.second) {

clang-format, please



Comment at: include/clang/Tooling/DiagnosticsYaml.h:79
+  for (auto  : Doc.Diagnostics) {
+if (Diagnostic.Fix.size() > 0) {
+  Diagnostics.push_back(Diagnostic);

Should we copy all diagnostics instead?



Comment at: 
tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp:42
+ TUDiagnostics ,
+ TUDiagnosticFiles & TURFiles,
  clang::DiagnosticsEngine ) {

clang-format, please



Comment at: tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h:56
   // Note: it is empty in unittest.
   std::string BuildDirectory;
 

It might make sense to move BuildDirectory to clang::Tooling::Diagnostic as 
well.


Repository:
  rL LLVM

https://reviews.llvm.org/D26137



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


[PATCH] D27066: Fix crash with unsupported architectures in Linux/Gnu target triples.

2016-11-30 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

Ping.


https://reviews.llvm.org/D27066



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


[PATCH] D27142: [clang-tidy] Make format style customizable

2016-11-30 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG. Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D27142



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


[PATCH] D26979: Do not hard-code locale data in unit tests: get it from the OS instead

2016-11-30 Thread Eric van Gyzen via Phabricator via cfe-commits
vangyzen added a comment.

> @EricWF Do you have time and interest to review this again?

I should ask, do you have time and interest to //commit// this?


https://reviews.llvm.org/D26979



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


[PATCH] D27109: [OpenCL] Prevent generation of globals in non-constant address space for OpenCL

2016-11-30 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia closed this revision.
Anastasia added a comment.

Committed in r288163.


https://reviews.llvm.org/D27109



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


Re: [RFC] Embedded bitcode and related upstream (Part II)

2016-11-30 Thread Nico Weber via cfe-commits
Hi Steven,

On Fri, Jun 3, 2016 at 2:36 PM, Steven Wu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hi everyone
>
> I am still in the process of upstreaming some improvements to the embed
> bitcode option. If you want more background, you can read the previous RFC (
> http://lists.llvm.org/pipermail/llvm-dev/2016-February/094851.html). This
> is part II of the discussion.
>
> Current Status:
> A basic version of -fembed-bitcode option is upstreamed and functioning.
> You can use -fembed-bitcode={off, all, bitcode, marker} option to control
> what gets embedded in the final object file output:
> off: default, nothing gets embedded.
> all: optimized bitcode and command line options gets embedded in the
> object file.
> bitcode: only optimized bitcode is embedded
> marker: only put a marker in the object file
>
> What needs to be improved:
> 1. Whitelist for command line options that can be used with bitcode:
> Current trunk implementation embeds all the cc1 command line options (that
> includes header include paths, warning flags and other front-end options)
> in the command line section. That is lot of redundant information. To
> re-create the object file from the embedded optimized bitcode, most of
> these options are useless. On the other hand, they can leak information of
> the source code. One solution will be keeping a list of all the options
> that can affect code generation but not encoded in the bitcode. I have
> internally prototyped with disallowing these options explicitly and allowed
> only the reminder of the  options to be embedded (http://reviews.llvm.org/
> D17394). A better solution might be encoding that information in
> "Options.td" as specific group.
>
> 2. Assembly input handling:
> This is a workaround to allow source code written in assembly to work with
> "-fembed-bitcode" options. When compiling assembly source code with
> "-fembed-bitcode", clang-as creates an empty section "__LLVM, __asm" in the
> object file. That is just a way to distinguish object files compiled from
> assembly source from those compiled from higher level source code but
> forgot to use "-fembed-bitcode" options. Linker can use this section to
> diagnose if "-fembed-bitcode" is consistently used on all the object files
> participated in the linking.
>

It looks like shipping Xcode's clang has this behavior, but open-source
clang still doesn't. Can you contribute it? It's very useful to us if
open-source clang has the same features as the clang shipping in Xcode.
(That last sentence is true in general, not just for this specific feature.)


>
> 3. Bitcode symbol hiding:
> There was some concerns for leaking source code information when using
> bitcode feature. One approach to avoid the leak is to add a pass which
> renames all the globals and metadata strings. The also keeps a reverse map
> in case the original name needs to be recovered. The final bitcode should
> contain no more symbols or debug info than a stripped binary. To make sure
> modified bitcode can still be linked correctly, the renaming need to be
> consistent across all bitcode participated in the linking and everything
> that is external of the linkage unit need to be preserved. This means the
> pass can only be run during the linking and requires some LTO api.
>
> 4. Debug info strip to line-tables pass:
> As the name suggested, this pass strip down the full debug info to
> line-tables only. This is also one of the steps we took to prevent the leak
> of source code information in bitcode.
>
> Please let me know what do you think about the pieces above or if you have
> any concerns about the methodology. I will put up patches for review soon.
>
> Thanks
>
> Steven
>
> ___
> 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] D27250: [OpenMP] TargetLibraryInfo from "declare simd".

2016-11-30 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

In https://reviews.llvm.org/D27250#609063, @ABataev wrote:

> You did just some minor changes. The main questions are still unanswered.


Hopefully now they are! :)

Francesco


https://reviews.llvm.org/D27250



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


[PATCH] D27250: [OpenMP] TargetLibraryInfo from "declare simd".

2016-11-30 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

In https://reviews.llvm.org/D27250#609006, @ABataev wrote:

>


Hi! Thanks for your review!

> 1. Please provide full context for your changes (check this document how to 
> do this http://llvm.org/docs/Phabricator.html).

I missed that out, should be done now.

> 2. Use clang-format for all your changes.

Done.

> 3. Do not use backed infrastructure to mangle the name of the new function. 
> Instead, you should build clang-based declaration and use clang 
> infrastructure to ge

The second part of the sentence is missing. I guess you are saying I should use 
the infrastructure for name mangling in clang in llvm? Is that what you mean? I 
think that the right place to keep something that need to be shared between 
LLVM and clang is the LLVM codebase, not conversely. Can we wait for other 
people feedback before deciding here?

> Also, I don't like the idea of the generation of real function profiles in 
> the frontend. It was decided, that the frontend only provides a list of 
> mangled names for vector functions, which must be generated in the backend.

I am just generating  a set of global variable with external linkage that are 
deleted by LLVM before any code generation happens. The globals are used just 
to populate the TargetLibraryInfoImpl class instance created in 
BackendUtils.cpp. See the high level description of the functionality I have 
provided in the RFC mail (see [1] below).I see this mechanisms being easier 
rather than getting a name, de-mangle it, interpret the parameters section, and 
then generate whatever information the vectorizer need to vectorize a 
particular scalar function in a loop. Instead of introducing new structures for 
matching what the vectorizer need swith what the TLI provides,  I just use what 
llvm already has, the FunctionType class.

This also avoid the complications of having to write a demangle function for 
the vector names for each architecture, which might have completely different 
names across architectures and ABI versions. With this FunctionType mechanisms, 
ABI changes are transparent to vectorizer.

> But you're trying something different. If you're going to change the whole 
> solution you should send an RFC to the community

I've sent out an email, apologies for not specifying RFC in the subject. You 
can find a copy of it with the RFC in the mailing list now [1].

[1] http://lists.llvm.org/pipermail/llvm-dev/2016-November/107677.html


https://reviews.llvm.org/D27250



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


[PATCH] D27054: Introducing clang::tooling::EditList for refactoring tools.

2016-11-30 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 79736.
ioeric added a comment.

- Added replace() and insert() to replace current replacement interfaces.


https://reviews.llvm.org/D27054

Files:
  include/clang/Tooling/Refactoring/EditList.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/Refactoring/CMakeLists.txt
  lib/Tooling/Refactoring/EditList.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/RefactoringTest.cpp

Index: unittests/Tooling/RefactoringTest.cpp
===
--- unittests/Tooling/RefactoringTest.cpp
+++ unittests/Tooling/RefactoringTest.cpp
@@ -26,6 +26,7 @@
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/Refactoring/EditList.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/SmallString.h"
 #include "gtest/gtest.h"
@@ -102,10 +103,10 @@
 
 // Checks that an llvm::Error instance contains a ReplacementError with expected
 // error code, expected new replacement, and expected existing replacement.
-static bool checkReplacementError(
-llvm::Error&& Error, replacement_error ExpectedErr,
-llvm::Optional ExpectedExisting,
-llvm::Optional ExpectedNew) {
+static bool checkReplacementError(llvm::Error &,
+  replacement_error ExpectedErr,
+  llvm::Optional ExpectedExisting,
+  llvm::Optional ExpectedNew) {
   if (!Error) {
 llvm::errs() << "Error is a success.";
 return false;
@@ -1089,5 +1090,187 @@
   EXPECT_TRUE(FileToReplaces.empty());
 }
 
+class EditListTest : public ::testing::Test {
+  protected:
+void setUp() {
+  DefaultFileID = Context.createInMemoryFile("input.cpp", DefaultCode);
+  DefaultLoc = Context.Sources.getLocForStartOfFile(DefaultFileID)
+   .getLocWithOffset(20);
+  assert(DefaultLoc.isValid() && "Default location must be valid.");
+}
+
+RewriterTestContext Context;
+std::string DefaultCode = std::string(100, 'a');
+unsigned DefaultOffset = 20;
+SourceLocation DefaultLoc;
+FileID DefaultFileID;
+};
+
+TEST_F(EditListTest, EditListToYAML) {
+  setUp();
+  EditList Edit(Context.Sources, DefaultLoc);
+  llvm::Error Err =
+  Edit.insert(Context.Sources, DefaultLoc, "aa", /*InsertAfter=*/false);
+  ASSERT_TRUE(!Err);
+  Err = Edit.insert(Context.Sources, DefaultLoc.getLocWithOffset(10), "bb",
+/*InsertAfter=*/false);
+  ASSERT_TRUE(!Err);
+  Edit.addHeader("a.h");
+  Edit.removeHeader("b.h");
+  std::string YAMLString = Edit.toYAMLString();
+
+  // NOTE: If this test starts to fail for no obvious reason, check whitespace.
+  ASSERT_STREQ("---\n"
+   "Key: 'input.cpp:20'\n"
+   "FilePath:input.cpp\n"
+   "Error:   ''\n"
+   "InsertedHeaders: [ a.h ]\n"
+   "RemovedHeaders:  [ b.h ]\n"
+   "Replacements:\n" // Extra whitespace here!
+   "  - FilePath:input.cpp\n"
+   "Offset:  20\n"
+   "Length:  0\n"
+   "ReplacementText: aa\n"
+   "  - FilePath:input.cpp\n"
+   "Offset:  30\n"
+   "Length:  0\n"
+   "ReplacementText: bb\n"
+   "...\n",
+   YAMLString.c_str());
+}
+
+TEST_F(EditListTest, YAMLToEditList) {
+  setUp();
+  std::string YamlContent = "---\n"
+"Key: 'input.cpp:20'\n"
+"FilePath:input.cpp\n"
+"Error:   'ok'\n"
+"InsertedHeaders: [ a.h ]\n"
+"RemovedHeaders:  [ b.h ]\n"
+"Replacements:\n" // Extra whitespace here!
+"  - FilePath:input.cpp\n"
+"Offset:  20\n"
+"Length:  0\n"
+"ReplacementText: aa\n"
+"  - FilePath:input.cpp\n"
+"Offset:  30\n"
+"Length:  0\n"
+"ReplacementText: bb\n"
+"...\n";
+  EditList ExpectedEdit(Context.Sources, DefaultLoc);
+  llvm::Error Err = ExpectedEdit.insert(Context.Sources, DefaultLoc, "aa",
+/*InsertAfter=*/false);
+  ASSERT_TRUE(!Err);
+  Err = ExpectedEdit.insert(Context.Sources, DefaultLoc.getLocWithOffset(10),
+"bb", /*InsertAfter=*/false);
+  ASSERT_TRUE(!Err);
+
+  ExpectedEdit.addHeader("a.h");
+  ExpectedEdit.removeHeader("b.h");
+  ExpectedEdit.setError("ok");
+
+  EditList ActualEdit = 

[PATCH] D27253: Protect futures test under libcpp-no-exceptions

2016-11-30 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D27253



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


[PATCH] D27254: Protect optional test under libcpp-no-exceptions

2016-11-30 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added inline comments.



Comment at: test/std/experimental/optional/optional.specalg/swap.pass.cpp:225
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {

Why is this here, and not before line L#236?


https://reviews.llvm.org/D27254



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


[PATCH] D27255: Protect std::ostream::sentry test under libcpp-no-exceptions

2016-11-30 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D27255



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


[PATCH] D27252: Protect sequences test under libcpp-no-exceptions

2016-11-30 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.
This revision is now accepted and ready to land.

LGTM>


https://reviews.llvm.org/D27252



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


  1   2   >