[PATCH] D26773: [analyzer] Refactor recursive symbol reachability check to use symbol_iterator

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

Yep, looks correct now :)


https://reviews.llvm.org/D26773



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


[PATCH] D26588: Add LocationContext to members of check::RegionChanges

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



Comment at: include/clang/StaticAnalyzer/Core/Checker.h:325
+  const CallEvent *Call,
+  const LocationContext *LCtx) {
+return ((const CHECKER *) checker)->checkRegionChanges(state, invalidated,

NoQ wrote:
> zaks.anna wrote:
> > k-wisniewski wrote:
> > > NoQ wrote:
> > > > zaks.anna wrote:
> > > > > LocationContext can be obtained by calling 
> > > > > CallEvent::getLocationContext(). I do not think that adding another 
> > > > > parameter here buys us much. Am I missing something?
> > > > CallEvent* is optional here - it's there only for invalidations through 
> > > > calls.
> > > How about the situation when this callback is triggered by something 
> > > other than a call, like variable assignment? I've tried using that 
> > > location context and had lots of segfaults as in such cases it appeared 
> > > to be null. Do you have some info that it should be non-null in such a 
> > > case?
> > Ok, makes sense. Have you looked into providing a checker context there? 
> > How much more difficult would that be? If that is too difficult, adding 
> > LocationContext is good as well.
> > 
> > If Call is optional and LocationContext is not, should the Call parameter 
> > be last.
> If we add a CheckerContext, then we may end up calling callbacks that split 
> states within callbacks that split states, and that'd be quite a mess to 
> support.
> 
> Right now a checker may trigger `checkRegionChanges()` within its callback by 
> manipulating the Store, which already leads to callbacks within callbacks, 
> but that's bearable as long as you can't add transitions within the inner 
> callbacks.
This argument by itself does not seem to be preventing us from providing 
CheckerContext. For example, we could disallow splitting states (ex: by setting 
some flag within the CheckerContext) but still provide most of the convenience 
APIs. 

The advantage of providing CheckerContext is that it is a class that provides 
access to different analyzer APIs that the checker writer might want to access. 
It is also familiar and somewhat expected as it is available in most other 
cases. It might be difficult to pipe enough information to construct it... I 
suspect that is the reason we do not provide it in this case.

I am OK with the patch as is but it would be good to explore if we could extend 
this API by providing the full CheckerContext.


https://reviews.llvm.org/D26588



___
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-17 Thread Artem Dergachev via cfe-commits
NoQ created this revision.
NoQ added reviewers: zaks.anna, dcoughlin, xazax.hun, a.sidorin.
NoQ added a subscriber: cfe-commits.

Put a lot of run-time checks on how our SVals are constructed, in order to 
maintain the existing status quo.
This should make understanding the hierarchy easier, and probably help us catch 
some bugs.

A couple of subtle bugs were exposed in the process, which were not addressed:

- SymbolConjured for invalidations caused by automatic destructors may possibly 
be reincarnated.
- GenericTaintChecker may produce symbolic expressions of void type.


https://reviews.llvm.org/D26837

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  lib/StaticAnalyzer/Core/MemRegion.cpp
  lib/StaticAnalyzer/Core/SVals.cpp

Index: lib/StaticAnalyzer/Core/SVals.cpp
===
--- lib/StaticAnalyzer/Core/SVals.cpp
+++ lib/StaticAnalyzer/Core/SVals.cpp
@@ -29,25 +29,6 @@
 // Utility methods.
 //===--===//
 
-bool SVal::hasConjuredSymbol() const {
-  if (Optional SV = getAs()) {
-SymbolRef sym = SV->getSymbol();
-if (isa(sym))
-  return true;
-  }
-
-  if (Optional RV = getAs()) {
-const MemRegion *R = RV->getRegion();
-if (const SymbolicRegion *SR = dyn_cast(R)) {
-  SymbolRef sym = SR->getSymbol();
-  if (isa(sym))
-return true;
-}
-  }
-
-  return false;
-}
-
 const FunctionDecl *SVal::getAsFunctionDecl() const {
   if (Optional X = getAs()) {
 const MemRegion* R = X->getRegion();
Index: lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- lib/StaticAnalyzer/Core/MemRegion.cpp
+++ lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -331,6 +331,7 @@
 }
 
 void BlockCodeRegion::Profile(llvm::FoldingSetNodeID& ID) const {
+  locTy->getTypePtr()->isBlockPointerType();
   BlockCodeRegion::ProfileRegion(ID, BD, locTy, AC, superRegion);
 }
 
@@ -379,10 +380,8 @@
 //===--===//
 
 void GlobalsSpaceRegion::anchor() { }
-void HeapSpaceRegion::anchor() { }
-void UnknownSpaceRegion::anchor() { }
-void StackLocalsSpaceRegion::anchor() { }
-void StackArgumentsSpaceRegion::anchor() { }
+void NonStaticGlobalSpaceRegion::anchor() { }
+void StackSpaceRegion::anchor() { }
 void TypedRegion::anchor() { }
 void TypedValueRegion::anchor() { }
 void CodeTextRegion::anchor() { }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -44,7 +44,10 @@
 
 public:
   SymbolRegionValue(SymbolID sym, const TypedValueRegion *r)
-: SymbolData(SymbolRegionValueKind, sym), R(r) {}
+  : SymbolData(SymbolRegionValueKind, sym), R(r) {
+assert(r);
+assert(isValidTypeForSymbol(r->getValueType()));
+  }
 
   const TypedValueRegion* getRegion() const { return R; }
 
@@ -81,7 +84,15 @@
   SymbolConjured(SymbolID sym, const Stmt *s, const LocationContext *lctx,
  QualType t, unsigned count, const void *symbolTag)
   : SymbolData(SymbolConjuredKind, sym), S(s), T(t), Count(count),
-LCtx(lctx), SymbolTag(symbolTag) {}
+LCtx(lctx), SymbolTag(symbolTag) {
+// FIXME: 's' might be a nullptr if we're conducting invalidation
+// that was caused by a destructor call on a temporary object,
+// which has no statement associated with it.
+// Due to this, we might be creating the same invalidation symbol for
+// two different invalidation passes (for two different temporaries).
+assert(lctx);
+assert(isValidTypeForSymbol(t));
+  }
 
   const Stmt *getStmt() const { return S; }
   unsigned getCount() const { return Count; }
@@ -120,7 +131,11 @@
 
 public:
   SymbolDerived(SymbolID sym, SymbolRef parent, const TypedValueRegion *r)
-: SymbolData(SymbolDerivedKind, sym), parentSymbol(parent), R(r) {}
+  : SymbolData(SymbolDerivedKind, sym), parentSymbol(parent), R(r) {
+assert(parent);
+assert(r);
+assert(isValidTypeForSymbol(r->getValueType()));
+  }
 
   SymbolRef getParentSymbol() const { return parentSymbol; }
   const TypedValueRegion *getRegion() const { return R; }
@@ -155,7 +170,9 @@
   
 public:
   SymbolExtent(SymbolID sym, const SubRegion *r)
-  : SymbolData(SymbolExtentKind, sym), R(r) {}
+  : SymbolData(SymbolExtentKind, sym), R(r) {
+assert(r);
+  }
 
   const SubRegion *getRegion() const { return R; }
 
@@ -193,7 +210,13 @@
   SymbolMetadata(SymbolID sym, const MemRegion* r, 

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

2016-11-17 Thread Artem Dergachev via cfe-commits
NoQ created this revision.
NoQ added reviewers: zaks.anna, dcoughlin, xazax.hun, a.sidorin.
NoQ added subscribers: nandor, cfe-commits.

1. Re-use approach used in codegen. `MaterializeTemporaryExpr` may be 
positioned in a strange manner, above the member access to the temporary, which 
makes it a bit tricky to find the expression that actually corresponds to the 
temporary object. FIXME: Hmm, probably we should re-use this approach in CFG as 
well (cf. https://reviews.llvm.org/D22419).
2. Create the temporary region that corresponds to the full temporary object, 
rather than to the sub-object. This was a bug.
3. If lifetime extension occurs, use the temporary object region's 
path-sensitive type, rather than reference variable type, in order to call the 
correct destructor.


https://reviews.llvm.org/D26839

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

Index: test/Analysis/lifetime-extension.cpp
===
--- /dev/null
+++ test/Analysis/lifetime-extension.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -Wno-unused -std=c++11 -analyze -analyzer-checker=debug.ExprInspection -verify %s
+
+struct S {
+  ~S() {
+  }
+};
+
+struct A {
+  int i;
+  int j[2];
+  S s;
+  A() : i(1) {
+j[0] = 2;
+j[1] = 3;
+  }
+};
+
+void clang_analyzer_eval(bool);
+
+void f() {
+  const int &x = A().i; // no-crash
+  const int &y = A().j[1]; // no-crash
+  const int &z = (A().j[1], A().j[0]); // no-crash
+
+  // FIXME: All of these should be TRUE, but constructors aren't inlined.
+  clang_analyzer_eval(x == 1); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(y == 3); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(z == 2); // expected-warning{{UNKNOWN}}
+}
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -202,51 +202,56 @@
   MemRegionManager &MRMgr = StateMgr.getRegionManager();
   StoreManager &StoreMgr = 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;
-
-  Inner = CE->getSubExpr()->IgnoreParens();
-}
-  }
+  // 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.
+  // 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.
+  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 &Adj = *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(),
   

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

2016-11-17 Thread Artem Dergachev via cfe-commits
NoQ created this revision.
NoQ added reviewers: zaks.anna, dcoughlin.
NoQ added a subscriber: cfe-commits.

This looked useful for https://reviews.llvm.org/D25909 at first, but i 
hesitated to rely on the explainer for composing the error messages. Still, i 
hope that with some work it might amount to something, so i decided to share 
the patch anyway.


https://reviews.llvm.org/D26836

Files:
  include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  test/Analysis/explain-svals.cpp
  test/Analysis/explain-svals.m


Index: test/Analysis/explain-svals.m
===
--- /dev/null
+++ test/Analysis/explain-svals.m
@@ -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;
+  ^{
+clang_analyzer_explain(&x); // expected-warning-re^pointer to block 
variable 'x'$
+  };
+  clang_analyzer_explain(&x); // expected-warning-re^pointer to block 
variable 'x'$
+}
Index: test/Analysis/explain-svals.cpp
===
--- test/Analysis/explain-svals.cpp
+++ test/Analysis/explain-svals.cpp
@@ -47,7 +47,7 @@
   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;
Index: include/clang/StaticAnalyzer/Checkers/SValExplainer.h
===
--- include/clang/StaticAnalyzer/Checkers/SValExplainer.h
+++ include/clang/StaticAnalyzer/Checkers/SValExplainer.h
@@ -142,6 +142,14 @@
 // 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 @@
 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 @@
   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());


Index: test/Analysis/explain-svals.m
===
--- /dev/null
+++ test/Analysis/explain-svals.m
@@ -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 Objec

[PATCH] D26838: [analyzer] Enforce super-region classes for various memory regions through compile-time and run-time type checks.

2016-11-17 Thread Artem Dergachev via cfe-commits
NoQ created this revision.
NoQ added reviewers: zaks.anna, dcoughlin, xazax.hun, a.sidorin.
NoQ added a subscriber: cfe-commits.

Put a lot of compile-time and run-time checks on classes of super regions of 
all `SubRegion` classes, in order to maintain the existing status quo.
This should make understanding the hierarchy easier, and probably help us catch 
some bugs.

This is an API-breaking change (we now require explicit casts to specific 
region sub-classes), but in practice very few checkers are affected.


https://reviews.llvm.org/D26838

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
  lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/MemRegion.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  lib/StaticAnalyzer/Core/Store.cpp

Index: lib/StaticAnalyzer/Core/Store.cpp
===
--- lib/StaticAnalyzer/Core/Store.cpp
+++ lib/StaticAnalyzer/Core/Store.cpp
@@ -42,17 +42,18 @@
   return Store;
 }
 
-const MemRegion *StoreManager::MakeElementRegion(const MemRegion *Base,
-  QualType EleTy, uint64_t index) {
+const MemRegion *StoreManager::MakeElementRegion(const SubRegion *Base,
+ QualType EleTy,
+ uint64_t index) {
   NonLoc idx = svalBuilder.makeArrayIndex(index);
   return MRMgr.getElementRegion(EleTy, idx, Base, svalBuilder.getContext());
 }
 
 StoreRef StoreManager::BindDefault(Store store, const MemRegion *R, SVal V) {
   return StoreRef(store, *this);
 }
 
-const ElementRegion *StoreManager::GetElementZeroRegion(const MemRegion *R,
+const ElementRegion *StoreManager::GetElementZeroRegion(const SubRegion *R,
 QualType T) {
   NonLoc idx = svalBuilder.makeZeroArrayIndex();
   assert(!T.isNull());
@@ -126,7 +127,7 @@
 case MemRegion::VarRegionKind:
 case MemRegion::CXXTempObjectRegionKind:
 case MemRegion::CXXBaseObjectRegionKind:
-  return MakeElementRegion(R, PointeeTy);
+  return MakeElementRegion(cast(R), PointeeTy);
 
 case MemRegion::ElementRegionKind: {
   // If we are casting from an ElementRegion to another type, the
@@ -171,7 +172,7 @@
 }
 
 // Otherwise, create a new ElementRegion at offset 0.
-return MakeElementRegion(baseR, PointeeTy);
+return MakeElementRegion(cast(baseR), PointeeTy);
   }
 
   // We have a non-zero offset from the base region.  We want to determine
@@ -202,10 +203,11 @@
   if (!newSuperR) {
 // Create an intermediate ElementRegion to represent the raw byte.
 // This will be the super region of the final ElementRegion.
-newSuperR = MakeElementRegion(baseR, Ctx.CharTy, off.getQuantity());
+newSuperR = MakeElementRegion(cast(baseR), Ctx.CharTy,
+  off.getQuantity());
   }
 
-  return MakeElementRegion(newSuperR, PointeeTy, newIndex);
+  return MakeElementRegion(cast(newSuperR), PointeeTy, newIndex);
 }
   }
 
@@ -271,9 +273,8 @@
 BaseDecl = BaseType->getAsCXXRecordDecl();
   assert(BaseDecl && "not a C++ object?");
 
-  const MemRegion *BaseReg =
-MRMgr.getCXXBaseObjectRegion(BaseDecl, DerivedRegVal->getRegion(),
- IsVirtual);
+  const MemRegion *BaseReg = MRMgr.getCXXBaseObjectRegion(
+  BaseDecl, cast(DerivedRegVal->getRegion()), IsVirtual);
 
   return loc::MemRegionVal(BaseReg);
 }
@@ -390,11 +391,11 @@
 return Base;
 
   Loc BaseL = Base.castAs();
-  const MemRegion* BaseR = nullptr;
+  const SubRegion* BaseR = nullptr;
 
   switch (BaseL.getSubKind()) {
   case loc::MemRegionValKind:
-BaseR = BaseL.castAs().getRegion();
+BaseR = cast(BaseL.castAs().getRegion());
 break;
 
   case loc::GotoLabelKind:
@@ -434,7 +435,8 @@
   if (Base.isUnknownOrUndef() || Base.getAs())
 return Base;
 
-  const MemRegion* BaseRegion = Base.castAs().getRegion();
+  const SubRegion *BaseRegion =
+  cast(Base.castAs().getRegion());
 
   // Pointer of any type can be cast and used as array base.
   const ElementRegion *ElemR = dyn_cast(BaseRegion);
@@ -471,9 +473,8 @@
 if (isa(BaseRegion->StripCasts()))
   return UnknownVal();
 
-return loc::MemRegionVal(MRMgr.getElementRegion(elementType, Offset,
-ElemR->getSuperRegion(),
-Ctx));
+return loc::MemRegionVal(MRMgr.getElementRegion(
+elementType, Offset, cast(ElemR->getSuperRegion()), Ctx));
   }
 
   const llvm::APSInt& OffI = Offset.castAs().getValue();
@@ -484,7 +485,7 @@
 OffI));
 

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

2016-11-17 Thread Artem Dergachev via cfe-commits
NoQ created this revision.
NoQ added reviewers: zaks.anna, dcoughlin, xazax.hun, a.sidorin.
NoQ added a subscriber: cfe-commits.

- Fix the bug with transition handling in `checkDeadSymbols`, that was noticed 
back in https://reviews.llvm.org/D18860, which never landed.
- 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.


https://reviews.llvm.org/D26835

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

Index: test/Analysis/symbol-reaper.c
===
--- test/Analysis/symbol-reaper.c
+++ 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: test/Analysis/expr-inspection.c
===
--- /dev/null
+++ 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 : &code{clang_analyzer_printState}
+// CHECK-NEXT: Ranges are empty.
Index: lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ 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 llvm::DenseMap ReachedStats;
+
   void analyzerEval(const CallExpr *CE, CheckerContext &C) const;
   void analyzerCheckInlined(const CallExpr *CE, CheckerContext &C) const;
   void analyzerWarnIfReached(const CallExpr *CE, CheckerContext &C) const;
+  void analyzerNumTimesReached(const CallExpr *CE, CheckerContext &C) const;
   void analyzerCrash(const CallExpr *CE, CheckerContext &C) const;
   void analyzerWarnOnDeadSymbol(const CallExpr *CE, CheckerContext &C) const;
+  void analyzerDump(const CallExpr *CE, CheckerContext &C) const;
   void analyzerExplain(const CallExpr *CE, CheckerContext &C) const;
+  void analyzerPrintState(const CallExpr *CE, CheckerContext &C) const;
   void analyzerGetExtent(const CallExpr *CE, CheckerContext &C) const;
 
   typedef void (ExprInspectionChecker::*FnCheck)(const CallExpr *,
  CheckerContext &C) const;
 
-  void reportBug(llvm::StringRef Msg, CheckerContext &C) const;
+  ExplodedNode *reportBug(llvm::StringRef Msg, CheckerContext &C) const;
+  ExplodedNode *reportBug(llvm::StringRef Msg, BugReporter &BR,
+  ExplodedNode *N) const;
 
 public:
   bool evalCall(const CallExpr *CE, CheckerContext &C) const;
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
+  void checkEndAnalysis(ExplodedGraph &G, BugReporter &BR,
+ExprEngine &Eng) const;
 };
 }
 
@@ -56,7 +72,12 @@
 .Case("clang_analyzer_warnOnDeadSymbol",
   &ExprInspectionChecker::analyzerWarnOnDeadSymbol)
 .Case("clang_analyzer_explain", &ExprInspectionChecker::analyzerExplain)
+.Case("clang_analyzer_dump", &ExprInspectionChecker::analyzerDump)
 .Case("clang_analyzer_getExtent", &ExprInspectionChecker::analyzerGetExtent)
+.Case("clang_analyz

[PATCH] D26814: [libcxx] [test] Change ifstream constructor tests to handle read-only files.

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

I really dislike this change. I'm afraid that these changes allow the tests to 
silently fail for reasons other than `test.dat` being read only.  For example 
if `test.dat` ever gets deleted, or if libc++'s remote test-harness fails to 
copy the input file to the remote host.

I'm not sure how to work around your read-only VCS issue though... Do you have 
any other ideas?


https://reviews.llvm.org/D26814



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


[PATCH] D26812: [libcxx] [test] In random tests, use real static_asserts and silence a warning.

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

Fun libc++ fact: We implement almost all of the C++11 library in C++03.

These tests use `assert` because `min()` is not constexpr in C++03. If you 
don't mind please change the tests to:

  #if TEST_STD_VER >= 11
  static_assert(...);
  #else
  assert(...);
  #endif

Feel free to commit after making those changes.




Comment at: test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp:44
+#pragma warning(push)
+#pragma warning(disable: 4310) // cast truncates constant value
+#endif // _MSC_VER

Warning "4310"? `#pragma GCC warning ignored "-Wwarning-name"` is so much 
better. Your compiler is bad and you should feel bad. :-P


https://reviews.llvm.org/D26812



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


[PATCH] D26816: [libcxx] [test] Fix non-Standard assumptions when testing sample().

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: 
test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.pass.cpp:74
   assert(end.base() - oa == std::min(os, is));
-  assert(std::equal(oa, oa + os, oa1));
+  LIBCPP_ASSERT(std::equal(oa, oa + os, oa1));
   end = std::sample(PopulationIterator(ia),

Please add a comment here explaining that the algorithm is non-reproducable.


https://reviews.llvm.org/D26816



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


[PATCH] D26829: [clang] Allow lexer to handle string_view literals

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

Please add tests to `cxx1y-user-defined-literals.cpp` (and probably rename it).

Other than that this LGTM, but I don't feel comfortable approving clang patches.


https://reviews.llvm.org/D26829



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


[libcxx] r287321 - Remove _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS

2016-11-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Fri Nov 18 00:42:17 2016
New Revision: 287321

URL: http://llvm.org/viewvc/llvm-project?rev=287321&view=rev
Log:
Remove _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS

libc++ no longer supports C++11 compilers that don't implement `= default`.
This patch removes all instances of the feature test macro
_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS as well as the potentially dead code it 
hides.

Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/__mutex_base
libcxx/trunk/include/atomic
libcxx/trunk/include/chrono
libcxx/trunk/include/functional
libcxx/trunk/include/memory

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=287321&r1=287320&r2=287321&view=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri Nov 18 00:42:17 2016
@@ -257,10 +257,6 @@ typedef __char32_t char32_t;
 #  define _LIBCPP_NORETURN __attribute__ ((noreturn))
 #endif
 
-#if !(__has_feature(cxx_defaulted_functions))
-#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-#endif  // !(__has_feature(cxx_defaulted_functions))
-
 #if !(__has_feature(cxx_deleted_functions))
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 #endif  // !(__has_feature(cxx_deleted_functions))
@@ -413,7 +409,6 @@ namespace std {
 
 #ifndef __GXX_EXPERIMENTAL_CXX0X__
 #define _LIBCPP_HAS_NO_DECLTYPE
-#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 #define _LIBCPP_HAS_NO_NULLPTR
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
@@ -442,10 +437,6 @@ namespace std {
 #define _LIBCPP_HAS_NO_NULLPTR
 #endif
 
-#if _GNUC_VER < 407
-#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-#endif
-
 #endif  // __GXX_EXPERIMENTAL_CXX0X__
 
 #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { namespace 
_LIBCPP_NAMESPACE {
@@ -469,7 +460,6 @@ using namespace _LIBCPP_NAMESPACE __attr
 #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
-#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
 #define _LIBCPP_HAS_NO_NOEXCEPT
 #define __alignof__ __alignof
 #define _LIBCPP_NORETURN __declspec(noreturn)
@@ -672,7 +662,7 @@ template  struct __static_asse
 #define _LIBCPP_CONSTEXPR constexpr
 #endif
 
-#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#ifdef _LIBCPP_CXX03_LANG
 #define _LIBCPP_DEFAULT {}
 #else
 #define _LIBCPP_DEFAULT = default;

Modified: libcxx/trunk/include/__mutex_base
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__mutex_base?rev=287321&r1=287320&r2=287321&view=diff
==
--- libcxx/trunk/include/__mutex_base (original)
+++ libcxx/trunk/include/__mutex_base Fri Nov 18 00:42:17 2016
@@ -43,7 +43,7 @@ class _LIBCPP_TYPE_VIS _LIBCPP_THREAD_SA
 public:
 _LIBCPP_INLINE_VISIBILITY
 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
-constexpr mutex() _NOEXCEPT _LIBCPP_DEFAULT
+constexpr mutex() _NOEXCEPT = default;
 #else
 mutex() _NOEXCEPT {__m_ = (__libcpp_mutex_t)_LIBCPP_MUTEX_INITIALIZER;}
 #endif
@@ -300,7 +300,7 @@ class _LIBCPP_TYPE_VIS condition_variabl
 public:
 _LIBCPP_INLINE_VISIBILITY
 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
-constexpr condition_variable() _NOEXCEPT _LIBCPP_DEFAULT
+constexpr condition_variable() _NOEXCEPT = default;
 #else
 condition_variable() _NOEXCEPT {__cv_ = 
(__libcpp_condvar_t)_LIBCPP_CONDVAR_INITIALIZER;}
 #endif

Modified: libcxx/trunk/include/atomic
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=287321&r1=287320&r2=287321&view=diff
==
--- libcxx/trunk/include/atomic (original)
+++ libcxx/trunk/include/atomic Fri Nov 18 00:42:17 2016
@@ -579,11 +579,11 @@ struct __gcc_atomic_t {
 #endif
 
   _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#ifndef _LIBCPP_CXX03_LANG
 __gcc_atomic_t() _NOEXCEPT = default;
 #else
 __gcc_atomic_t() _NOEXCEPT : __a_value() {}
-#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#endif // _LIBCPP_CXX03_LANG
   _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT
 : __a_value(value) {}
   _Tp __a_value;
@@ -935,11 +935,11 @@ struct __atomic_base  // false
 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, 
__m);}
 
 _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#ifndef _LIBCPP_CXX03_LANG
 __atomic_base() _NOEXCEPT = default;
 #else
 __atomic_base() _NOEXCEPT : __a_() {}
-#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#endif // _LIBCPP_CXX03_LANG
 
 _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
@@ -1690,11 +1690,11 @@ typedef struct atomic_flag
 {__c11_atomic_store(&__a_, false, __m);}
 
 _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#ifndef _LIBCPP_CXX03_LANG
  

[PATCH] D22334: Fix for Bug 28172 : clang crashes on invalid code (with too few arguments to __builtin_signbit) without any proper diagnostics.

2016-11-17 Thread Mayur Pandey via cfe-commits
mayurpandey updated this revision to Diff 78471.
mayurpandey added a comment.

Hi,

Updated the patch. Can you please commit it on my behalf as I don't have commit 
access.

Thanks,
Mayur


https://reviews.llvm.org/D22334

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/builtins.c
  test/SemaCXX/builtins.cpp


Index: test/SemaCXX/builtins.cpp
===
--- test/SemaCXX/builtins.cpp
+++ test/SemaCXX/builtins.cpp
@@ -44,3 +44,10 @@
   __noop(1); // expected-error {{use of undeclared}}
   __debugbreak(); // expected-error {{use of undeclared}}
 }
+
+template 
+int test_signbit(T t) { return __builtin_signbit(t); } // expected-error 
{{floating point type is required}}
+
+int test_signbit_call () {
+return test_signbit("1"); // expected-note {{instantiation of function 
template specialization}} 
+}
Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -248,3 +248,11 @@
 
 return buf;
 }
+
+int test21(double a) {
+  return __builtin_signbit();  // expected-error {{too few arguments}}
+}
+
+int test22(void) {
+  return __builtin_signbit("1");  // expected-error {{floating point type is 
required}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -98,6 +98,22 @@
   return false;
 }
 
+static bool SemaBuiltinSignbit(Sema &S, CallExpr *TheCall) {
+  if (checkArgCount(S, TheCall, 1))
+return true;
+
+  // Argument should be an float, double or long double.
+  Expr *ValArg = TheCall->getArg(0);
+  QualType Ty = ValArg->getType();
+  if (!Ty->isRealFloatingType()) {
+S.Diag(ValArg->getLocStart(), diag::err_typecheck_cond_expect_float)
+  << Ty << ValArg->getSourceRange();
+return true;
+  }
+
+  return false;
+}
+
 /// Check that the argument to __builtin_addressof is a glvalue, and set the
 /// result type to the corresponding pointer type.
 static bool SemaBuiltinAddressof(Sema &S, CallExpr *TheCall) {
@@ -762,6 +778,10 @@
 }
 break;
   }
+  case Builtin::BI__builtin_signbit:
+if (SemaBuiltinSignbit(*this, TheCall))
+  return ExprError();
+break;
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6845,6 +6845,8 @@
   "(passed in %0)">;
 def err_typecheck_cond_expect_int_float : Error<
   "used type %0 where integer or floating point type is required">;
+def err_typecheck_cond_expect_float : Error<
+  "used type %0 where floating point type is required">;
 def err_typecheck_cond_expect_scalar : Error<
   "used type %0 where arithmetic or pointer type is required">;
 def err_typecheck_cond_expect_nonfloat : Error<


Index: test/SemaCXX/builtins.cpp
===
--- test/SemaCXX/builtins.cpp
+++ test/SemaCXX/builtins.cpp
@@ -44,3 +44,10 @@
   __noop(1); // expected-error {{use of undeclared}}
   __debugbreak(); // expected-error {{use of undeclared}}
 }
+
+template 
+int test_signbit(T t) { return __builtin_signbit(t); } // expected-error {{floating point type is required}}
+
+int test_signbit_call () {
+return test_signbit("1"); // expected-note {{instantiation of function template specialization}} 
+}
Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -248,3 +248,11 @@
 
 return buf;
 }
+
+int test21(double a) {
+  return __builtin_signbit();  // expected-error {{too few arguments}}
+}
+
+int test22(void) {
+  return __builtin_signbit("1");  // expected-error {{floating point type is required}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -98,6 +98,22 @@
   return false;
 }
 
+static bool SemaBuiltinSignbit(Sema &S, CallExpr *TheCall) {
+  if (checkArgCount(S, TheCall, 1))
+return true;
+
+  // Argument should be an float, double or long double.
+  Expr *ValArg = TheCall->getArg(0);
+  QualType Ty = ValArg->getType();
+  if (!Ty->isRealFloatingType()) {
+S.Diag(ValArg->getLocStart(), diag::err_typecheck_cond_expect_float)
+  << Ty << ValArg->getSourceRange();
+return true;
+  }
+
+  return false;
+}
+
 /// Check that the argument to __builtin_addressof is a glvalue, and set the
 /// result type to the corresponding pointer type.
 static bool SemaBuiltinAddressof(Sema &S, CallExpr *TheCall) {
@@ -762,6 +778,10 @@
 }
 break;
   }
+  case Builtin::BI__builtin_signbit:
+if (SemaBuiltinSign

r287317 - Add doxygen comments for lzcntintrin.h's intrinsics.

2016-11-17 Thread Ekaterina Romanova via cfe-commits
Author: kromanova
Date: Fri Nov 18 00:26:01 2016
New Revision: 287317

URL: http://llvm.org/viewvc/llvm-project?rev=287317&view=rev
Log:
Add doxygen comments for lzcntintrin.h's intrinsics.

The doxygen comments are automatically generated based on Sony's intrinsics 
document.

I got an OK from Eric Christopher to commit doxygen comments without prior code
review upstream. This patch was internally reviewed by Charles Li.



Modified:
cfe/trunk/lib/Headers/lzcntintrin.h

Modified: cfe/trunk/lib/Headers/lzcntintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/lzcntintrin.h?rev=287317&r1=287316&r2=287317&view=diff
==
--- cfe/trunk/lib/Headers/lzcntintrin.h (original)
+++ cfe/trunk/lib/Headers/lzcntintrin.h Fri Nov 18 00:26:01 2016
@@ -31,18 +31,48 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("lzcnt")))
 
+/// \brief Counts the number of leading zero bits in the operand.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c LZCNT instruction.
+///
+/// \param __X
+///An unsigned 16-bit integer whose leading zeros are to be counted.
+/// \returns An unsigned 16-bit integer containing the number of leading zero
+///bits in the operand.
 static __inline__ unsigned short __DEFAULT_FN_ATTRS
 __lzcnt16(unsigned short __X)
 {
   return __X ? __builtin_clzs(__X) : 16;
 }
 
+/// \brief Counts the number of leading zero bits in the operand.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c LZCNT instruction.
+///
+/// \param __X
+///An unsigned 32-bit integer whose leading zeros are to be counted.
+/// \returns An unsigned 32-bit integer containing the number of leading zero
+///bits in the operand.
 static __inline__ unsigned int __DEFAULT_FN_ATTRS
 __lzcnt32(unsigned int __X)
 {
   return __X ? __builtin_clz(__X) : 32;
 }
 
+/// \brief Counts the number of leading zero bits in the operand.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c LZCNT instruction.
+///
+/// \param __X
+///An unsigned 32-bit integer whose leading zeros are to be counted.
+/// \returns An unsigned 32-bit integer containing the number of leading zero
+///bits in the operand.
 static __inline__ unsigned int __DEFAULT_FN_ATTRS
 _lzcnt_u32(unsigned int __X)
 {
@@ -50,12 +80,32 @@ _lzcnt_u32(unsigned int __X)
 }
 
 #ifdef __x86_64__
+/// \brief Counts the number of leading zero bits in the operand.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c LZCNT instruction.
+///
+/// \param __X
+///An unsigned 64-bit integer whose leading zeros are to be counted.
+/// \returns An unsigned 64-bit integer containing the number of leading zero
+///bits in the operand.
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
 __lzcnt64(unsigned long long __X)
 {
   return __X ? __builtin_clzll(__X) : 64;
 }
 
+/// \brief Counts the number of leading zero bits in the operand.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c LZCNT instruction.
+///
+/// \param __X
+///An unsigned 64-bit integer whose leading zeros are to be counted.
+/// \returns An unsigned 64-bit integer containing the number of leading zero
+///bits in the operand.
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
 _lzcnt_u64(unsigned long long __X)
 {


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


[PATCH] D26833: LTO support for -fsave-optimization-record on Darwin

2016-11-17 Thread Adam Nemet via cfe-commits
anemet added a comment.

Nothing strong, just trying to go step-by-step.  I haven't thought about it how 
this should map to ThinLTO.  We can discuss it tomorrow.


https://reviews.llvm.org/D26833



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


[PATCH] D26833: LTO support for -fsave-optimization-record on Darwin

2016-11-17 Thread Mehdi AMINI via cfe-commits
mehdi_amini added a comment.

I'm not incline to agree with this, unless you have very strong arguments.


https://reviews.llvm.org/D26833



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


[PATCH] D26833: LTO support for -fsave-optimization-record on Darwin

2016-11-17 Thread Adam Nemet via cfe-commits
anemet added a comment.

In https://reviews.llvm.org/D26833#599382, @mehdi_amini wrote:

> Well, maybe not entirely, what do you expect for output with ThinLTO?


For now, I'd like to just ignore it.  So I need to somehow restrict this to 
LTO-only...


https://reviews.llvm.org/D26833



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


[PATCH] D26833: LTO support for -fsave-optimization-record on Darwin

2016-11-17 Thread Mehdi AMINI via cfe-commits
mehdi_amini requested changes to this revision.
mehdi_amini added a comment.
This revision now requires changes to proceed.

Well, maybe not entirely, what do you expect for output with ThinLTO?


https://reviews.llvm.org/D26833



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


[PATCH] D26833: LTO support for -fsave-optimization-record on Darwin

2016-11-17 Thread Mehdi AMINI via cfe-commits
mehdi_amini accepted this revision.
mehdi_amini added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D26833



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


[PATCH] D26833: LTO support for -fsave-optimization-record on Darwin

2016-11-17 Thread Adam Nemet via cfe-commits
anemet created this revision.
anemet added reviewers: hfinkel, mehdi_amini.
anemet added a subscriber: cfe-commits.

I guess this would have to be added for each linker.


https://reviews.llvm.org/D26833

Files:
  lib/Driver/Tools.cpp
  test/Driver/darwin-ld.c


Index: test/Driver/darwin-ld.c
===
--- test/Driver/darwin-ld.c
+++ test/Driver/darwin-ld.c
@@ -327,3 +327,12 @@
 // LINK_VERSION_DIGITS: invalid version number in 
'-mlinker-version=133.3.0.1.2.6'
 // LINK_VERSION_DIGITS: invalid version number in 
'-mlinker-version=133.3.0.1.a'
 // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1a'
+
+// Check that we're passing -pass-remarks-output for LTO
+// RUN: %clang -target x86_64-apple-darwin12 %t.o -fsave-optimization-record 
-### -o foo/bar.out 2> %t.log
+// RUN: FileCheck -check-prefix=PASS_REMARKS_OUTPUT %s < %t.log
+// PASS_REMARKS_OUTPUT: "-mllvm" "-pass-remarks-output" "-mllvm" 
"foo/bar.out.opt.yaml"
+
+// RUN: %clang -target x86_64-apple-darwin12 %t.o -fsave-optimization-record 
-### 2> %t.log
+// RUN: FileCheck -check-prefix=PASS_REMARKS_OUTPUT_NO_O %s < %t.log
+// PASS_REMARKS_OUTPUT_NO_O: "-mllvm" "-pass-remarks-output" "-mllvm" 
"a.out.opt.yaml"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8416,6 +8416,19 @@
   // we follow suite for ease of comparison.
   AddLinkArgs(C, Args, CmdArgs, Inputs);
 
+  // For LTO, pass the name of the optimization record file.
+  if (Args.hasFlag(options::OPT_fsave_optimization_record,
+   options::OPT_fno_save_optimization_record, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-pass-remarks-output");
+CmdArgs.push_back("-mllvm");
+
+SmallString<128> F;
+F = Output.getFilename();
+F += ".opt.yaml";
+CmdArgs.push_back(Args.MakeArgString(F));
+  }
+
   // It seems that the 'e' option is completely ignored for dynamic executables
   // (the default), and with static executables, the last one wins, as 
expected.
   Args.AddAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, 
options::OPT_t,


Index: test/Driver/darwin-ld.c
===
--- test/Driver/darwin-ld.c
+++ test/Driver/darwin-ld.c
@@ -327,3 +327,12 @@
 // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1.2.6'
 // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1.a'
 // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1a'
+
+// Check that we're passing -pass-remarks-output for LTO
+// RUN: %clang -target x86_64-apple-darwin12 %t.o -fsave-optimization-record -### -o foo/bar.out 2> %t.log
+// RUN: FileCheck -check-prefix=PASS_REMARKS_OUTPUT %s < %t.log
+// PASS_REMARKS_OUTPUT: "-mllvm" "-pass-remarks-output" "-mllvm" "foo/bar.out.opt.yaml"
+
+// RUN: %clang -target x86_64-apple-darwin12 %t.o -fsave-optimization-record -### 2> %t.log
+// RUN: FileCheck -check-prefix=PASS_REMARKS_OUTPUT_NO_O %s < %t.log
+// PASS_REMARKS_OUTPUT_NO_O: "-mllvm" "-pass-remarks-output" "-mllvm" "a.out.opt.yaml"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8416,6 +8416,19 @@
   // we follow suite for ease of comparison.
   AddLinkArgs(C, Args, CmdArgs, Inputs);
 
+  // For LTO, pass the name of the optimization record file.
+  if (Args.hasFlag(options::OPT_fsave_optimization_record,
+   options::OPT_fno_save_optimization_record, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-pass-remarks-output");
+CmdArgs.push_back("-mllvm");
+
+SmallString<128> F;
+F = Output.getFilename();
+F += ".opt.yaml";
+CmdArgs.push_back(Args.MakeArgString(F));
+  }
+
   // It seems that the 'e' option is completely ignored for dynamic executables
   // (the default), and with static executables, the last one wins, as expected.
   Args.AddAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, options::OPT_t,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r287313 - [AVX-512] Replace masked 16-bit element variable shift builtins with new unmasked versions and selects.

2016-11-17 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Thu Nov 17 23:04:51 2016
New Revision: 287313

URL: http://llvm.org/viewvc/llvm-project?rev=287313&view=rev
Log:
[AVX-512] Replace masked 16-bit element variable shift builtins with new 
unmasked versions and selects.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx512bwintrin.h
cfe/trunk/lib/Headers/avx512vlbwintrin.h
cfe/trunk/test/CodeGen/avx512bw-builtins.c
cfe/trunk/test/CodeGen/avx512vlbw-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=287313&r1=287312&r2=287313&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Thu Nov 17 23:04:51 2016
@@ -1352,21 +1352,21 @@ TARGET_BUILTIN(__builtin_ia32_prorvd128_
 TARGET_BUILTIN(__builtin_ia32_prorvd256_mask, "V8iV8iV8iV8iUc","","avx512vl")
 TARGET_BUILTIN(__builtin_ia32_prorvq128_mask, 
"V2LLiV2LLiV2LLiV2LLiUc","","avx512vl")
 TARGET_BUILTIN(__builtin_ia32_prorvq256_mask, 
"V4LLiV4LLiV4LLiV4LLiUc","","avx512vl")
-TARGET_BUILTIN(__builtin_ia32_psllv32hi_mask, 
"V32sV32sV32sV32sUi","","avx512bw")
+TARGET_BUILTIN(__builtin_ia32_psllv32hi, "V32sV32sV32s","","avx512bw")
 TARGET_BUILTIN(__builtin_ia32_psllw512, "V32sV32sV8s","","avx512bw")
 TARGET_BUILTIN(__builtin_ia32_psllwi512, "V32sV32si","","avx512bw")
-TARGET_BUILTIN(__builtin_ia32_psllv16hi_mask, 
"V16sV16sV16sV16sUs","","avx512bw,avx512vl")
-TARGET_BUILTIN(__builtin_ia32_psllv8hi_mask, 
"V8sV8sV8sV8sUc","","avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_psllv16hi, "V16sV16sV16s","","avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_psllv8hi, "V8sV8sV8s","","avx512bw,avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pslldi512, "V16iV16ii","","avx512f")
 TARGET_BUILTIN(__builtin_ia32_psllqi512, "V8LLiV8LLii","","avx512f")
-TARGET_BUILTIN(__builtin_ia32_psrlv32hi_mask, 
"V32sV32sV32sV32sUi","","avx512bw")
-TARGET_BUILTIN(__builtin_ia32_psrlv16hi_mask, 
"V16sV16sV16sV16sUs","","avx512bw,avx512vl")
-TARGET_BUILTIN(__builtin_ia32_psrlv8hi_mask, 
"V8sV8sV8sV8sUc","","avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_psrlv32hi, "V32sV32sV32s","","avx512bw")
+TARGET_BUILTIN(__builtin_ia32_psrlv16hi, "V16sV16sV16s","","avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_psrlv8hi, "V8sV8sV8s","","avx512bw,avx512vl")
 TARGET_BUILTIN(__builtin_ia32_psrldi512, "V16iV16ii","","avx512f")
 TARGET_BUILTIN(__builtin_ia32_psrlqi512, "V8LLiV8LLii","","avx512f")
-TARGET_BUILTIN(__builtin_ia32_psrav32hi_mask, 
"V32sV32sV32sV32sUi","","avx512bw")
-TARGET_BUILTIN(__builtin_ia32_psrav16hi_mask, 
"V16sV16sV16sV16sUs","","avx512bw,avx512vl")
-TARGET_BUILTIN(__builtin_ia32_psrav8hi_mask, 
"V8sV8sV8sV8sUc","","avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_psrav32hi, "V32sV32sV32s","","avx512bw")
+TARGET_BUILTIN(__builtin_ia32_psrav16hi, "V16sV16sV16s","","avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_psrav8hi, "V8sV8sV8s","","avx512bw,avx512vl")
 TARGET_BUILTIN(__builtin_ia32_psravq128, "V2LLiV2LLiV2LLi","","avx512vl")
 TARGET_BUILTIN(__builtin_ia32_psravq256, "V4LLiV4LLiV4LLi","","avx512vl")
 TARGET_BUILTIN(__builtin_ia32_psraw512, "V32sV32sV8s","","avx512bw")

Modified: cfe/trunk/lib/Headers/avx512bwintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512bwintrin.h?rev=287313&r1=287312&r2=287313&view=diff
==
--- cfe/trunk/lib/Headers/avx512bwintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512bwintrin.h Thu Nov 17 23:04:51 2016
@@ -1688,33 +1688,25 @@ _mm512_maskz_cvtepu8_epi16(__mmask32 __U
   (__v32hi)_mm512_setzero_hi()); })
 
 static __inline__ __m512i __DEFAULT_FN_ATTRS
-_mm512_sllv_epi16 (__m512i __A, __m512i __B)
+_mm512_sllv_epi16(__m512i __A, __m512i __B)
 {
-  return (__m512i) __builtin_ia32_psllv32hi_mask ((__v32hi) __A,
-  (__v32hi) __B,
-  (__v32hi)
-  _mm512_setzero_hi (),
-  (__mmask32) -1);
+  return (__m512i)__builtin_ia32_psllv32hi((__v32hi) __A, (__v32hi) __B);
 }
 
 static __inline__ __m512i __DEFAULT_FN_ATTRS
-_mm512_mask_sllv_epi16 (__m512i __W, __mmask32 __U, __m512i __A,
-  __m512i __B)
+_mm512_mask_sllv_epi16 (__m512i __W, __mmask32 __U, __m512i __A, __m512i __B)
 {
-  return (__m512i) __builtin_ia32_psllv32hi_mask ((__v32hi) __A,
-  (__v32hi) __B,
-  (__v32hi) __W,
-  (__mmask32) __U);
+  return (__m512i)__builtin_ia32_selectw_512((__mmask32)__U,
+   (__v32hi)_mm512_sllv_epi16(__A, 
__B),
+   (__v32hi)__W);
 }
 
 static __inline__ __m512i __DEFAULT_FN_ATTRS
-_mm512_maskz_sllv_epi16 (__mmask32 __U, __m512i __A, __m512i __B)
+_mm512_maskz_sllv_epi16(__mmask32 __U, __m512i __A, __

[PATCH] D25949: [Driver] Refactor distro detection & classification as a separate API

2016-11-17 Thread Michał Górny via cfe-commits
mgorny updated this revision to Diff 78462.
mgorny added a comment.

Thanks for the review. I've rebased on top of current master (UbuntuZesty 
added), and now I will update the unit tests.


https://reviews.llvm.org/D25949

Files:
  include/clang/Driver/Distro.h
  lib/Driver/CMakeLists.txt
  lib/Driver/Distro.cpp
  lib/Driver/ToolChains.cpp

Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/VirtualFileSystem.h"
 #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX
 #include "clang/Driver/Compilation.h"
+#include "clang/Driver/Distro.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
@@ -3885,171 +3886,6 @@
   }
 }
 
-/// Distribution (very bare-bones at the moment).
-
-enum Distro {
-  // NB: Releases of a particular Linux distro should be kept together
-  // in this enum, because some tests are done by integer comparison against
-  // the first and last known member in the family, e.g. IsRedHat().
-  ArchLinux,
-  DebianLenny,
-  DebianSqueeze,
-  DebianWheezy,
-  DebianJessie,
-  DebianStretch,
-  Exherbo,
-  RHEL5,
-  RHEL6,
-  RHEL7,
-  Fedora,
-  OpenSUSE,
-  UbuntuHardy,
-  UbuntuIntrepid,
-  UbuntuJaunty,
-  UbuntuKarmic,
-  UbuntuLucid,
-  UbuntuMaverick,
-  UbuntuNatty,
-  UbuntuOneiric,
-  UbuntuPrecise,
-  UbuntuQuantal,
-  UbuntuRaring,
-  UbuntuSaucy,
-  UbuntuTrusty,
-  UbuntuUtopic,
-  UbuntuVivid,
-  UbuntuWily,
-  UbuntuXenial,
-  UbuntuYakkety,
-  UbuntuZesty,
-  UnknownDistro
-};
-
-static bool IsRedhat(enum Distro Distro) {
-  return Distro == Fedora || (Distro >= RHEL5 && Distro <= RHEL7);
-}
-
-static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; }
-
-static bool IsDebian(enum Distro Distro) {
-  return Distro >= DebianLenny && Distro <= DebianStretch;
-}
-
-static bool IsUbuntu(enum Distro Distro) {
-  return Distro >= UbuntuHardy && Distro <= UbuntuZesty;
-}
-
-static Distro DetectDistro(vfs::FileSystem &VFS) {
-  llvm::ErrorOr> File =
-  VFS.getBufferForFile("/etc/lsb-release");
-  if (File) {
-StringRef Data = File.get()->getBuffer();
-SmallVector Lines;
-Data.split(Lines, "\n");
-Distro Version = UnknownDistro;
-for (StringRef Line : Lines)
-  if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME="))
-Version = llvm::StringSwitch(Line.substr(17))
-  .Case("hardy", UbuntuHardy)
-  .Case("intrepid", UbuntuIntrepid)
-  .Case("jaunty", UbuntuJaunty)
-  .Case("karmic", UbuntuKarmic)
-  .Case("lucid", UbuntuLucid)
-  .Case("maverick", UbuntuMaverick)
-  .Case("natty", UbuntuNatty)
-  .Case("oneiric", UbuntuOneiric)
-  .Case("precise", UbuntuPrecise)
-  .Case("quantal", UbuntuQuantal)
-  .Case("raring", UbuntuRaring)
-  .Case("saucy", UbuntuSaucy)
-  .Case("trusty", UbuntuTrusty)
-  .Case("utopic", UbuntuUtopic)
-  .Case("vivid", UbuntuVivid)
-  .Case("wily", UbuntuWily)
-  .Case("xenial", UbuntuXenial)
-  .Case("yakkety", UbuntuYakkety)
-  .Case("zesty", UbuntuZesty)
-  .Default(UnknownDistro);
-if (Version != UnknownDistro)
-  return Version;
-  }
-
-  File = VFS.getBufferForFile("/etc/redhat-release");
-  if (File) {
-StringRef Data = File.get()->getBuffer();
-if (Data.startswith("Fedora release"))
-  return Fedora;
-if (Data.startswith("Red Hat Enterprise Linux") ||
-Data.startswith("CentOS") ||
-Data.startswith("Scientific Linux")) {
-  if (Data.find("release 7") != StringRef::npos)
-return RHEL7;
-  else if (Data.find("release 6") != StringRef::npos)
-return RHEL6;
-  else if (Data.find("release 5") != StringRef::npos)
-return RHEL5;
-}
-return UnknownDistro;
-  }
-
-  File = VFS.getBufferForFile("/etc/debian_version");
-  if (File) {
-StringRef Data = File.get()->getBuffer();
-// Contents: < major.minor > or < codename/sid >
-int MajorVersion;
-if (!Data.split('.').first.getAsInteger(10, MajorVersion)) {
-  switch (MajorVersion) {
-  case 5:
-return DebianLenny;
-  case 6:
-return DebianSqueeze;
-  case 7:
-return DebianWheezy;
-  case 8:
-return DebianJessie;
-  case 9:
-return DebianStretch;
-  default:
-return UnknownDistro;
-  }
-}
-return llvm::StringSwitch(Data.split("\n").first)
-.Case("squeeze/sid", DebianSqueeze)
-.Case("wheezy/sid", DebianWheezy)
-.Case("jessie/sid", DebianJessie)
-  

[PATCH] D26825: [libc++] Fix preprocessor guard for overload declaration

2016-11-17 Thread Shoaib Meenai via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287309: [libc++] Fix preprocessor guard for overload 
declaration (authored by smeenai).

Changed prior to commit:
  https://reviews.llvm.org/D26825?vs=78447&id=78461#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26825

Files:
  libcxx/trunk/include/new


Index: libcxx/trunk/include/new
===
--- libcxx/trunk/include/new
+++ libcxx/trunk/include/new
@@ -180,7 +180,7 @@
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const 
std::nothrow_t&) _NOEXCEPT _NOALIAS;
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p) _NOEXCEPT;
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, const 
std::nothrow_t&) _NOEXCEPT;
-#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
+#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, std::size_t 
__sz) _NOEXCEPT;
 #endif
 


Index: libcxx/trunk/include/new
===
--- libcxx/trunk/include/new
+++ libcxx/trunk/include/new
@@ -180,7 +180,7 @@
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p) _NOEXCEPT;
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
-#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
+#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r287309 - [libc++] Fix preprocessor guard for overload declaration

2016-11-17 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Thu Nov 17 22:31:09 2016
New Revision: 287309

URL: http://llvm.org/viewvc/llvm-project?rev=287309&view=rev
Log:
[libc++] Fix preprocessor guard for overload declaration

Fix a typo in the conditional.  Caught by going through list of removed
symbols when building with hidden visibility.

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

Modified:
libcxx/trunk/include/new

Modified: libcxx/trunk/include/new
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/new?rev=287309&r1=287308&r2=287309&view=diff
==
--- libcxx/trunk/include/new (original)
+++ libcxx/trunk/include/new Thu Nov 17 22:31:09 2016
@@ -180,7 +180,7 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS void* opera
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const 
std::nothrow_t&) _NOEXCEPT _NOALIAS;
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p) _NOEXCEPT;
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, const 
std::nothrow_t&) _NOEXCEPT;
-#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
+#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, std::size_t 
__sz) _NOEXCEPT;
 #endif
 


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


[PATCH] D26830: [libcxx] Add string_view literals

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

Which paper is this implementing?

Also please update the synopsis comment at the top of the header.




Comment at: include/string_view:749
 
+inline namespace literals
+{

If this is new to C++17 then the new declarations should be guarded by `#if 
_LIBCPP_VERSION > 14`.



Comment at: include/string_view:754
+_LIBCPP_CONSTEXPR
+string_view operator "" sv(const char* __str, size_t __len) _NOEXCEPT
+{

Please add `inline _LIBCPP_INLINE_VISIBILITY` to each of these declarations.


https://reviews.llvm.org/D26830



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


[PATCH] D25654: [Sema] Don't perform aggregate initialization for types with explicit constructors

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 78459.
EricWF added a comment.

Add tests that explicit default constructors are still allowed outside of 
copy-initialization.


https://reviews.llvm.org/D25654

Files:
  lib/AST/DeclCXX.cpp
  test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1.cpp
  test/CXX/dcl.decl/dcl.init/p7.cpp
  test/CXX/drs/dr15xx.cpp

Index: test/CXX/drs/dr15xx.cpp
===
--- test/CXX/drs/dr15xx.cpp
+++ test/CXX/drs/dr15xx.cpp
@@ -135,6 +135,53 @@
   }
 }
 
+namespace dr1518 { // dr1518: 4.0
+#if __cplusplus >= 201103L
+struct Z0 { // expected-note 0+ {{candidate}}
+  explicit Z0() = default; // expected-note 0+ {{here}}
+};
+struct Z { // expected-note 0+ {{candidate}}
+  explicit Z(); // expected-note 0+ {{here}}
+  explicit Z(int);
+  explicit Z(int, int); // expected-note 0+ {{here}}
+};
+template  int Eat(T); // expected-note 0+ {{candidate}}
+Z0 a;
+Z0 b{};
+Z0 c = {}; // expected-error {{explicit in copy-initialization}}
+int i = Eat({}); // expected-error {{no matching function for call to 'Eat'}}
+
+Z c2 = {}; // expected-error {{explicit in copy-initialization}}
+int i2 = Eat({}); // expected-error {{no matching function for call to 'Eat'}}
+Z a1 = 1; // expected-error {{no viable conversion}}
+Z a3 = Z(1);
+Z a2(1);
+Z *p = new Z(1);
+Z a4 = (Z)1;
+Z a5 = static_cast(1);
+Z a6 = {4, 3}; // expected-error {{explicit in copy-initialization}}
+
+struct UserProvidedBaseCtor { // expected-note 0+ {{candidate}}
+  UserProvidedBaseCtor() {}
+};
+struct DoesntInheritCtor : UserProvidedBaseCtor { // expected-note 0+ {{candidate}}
+  int x;
+};
+DoesntInheritCtor I{{}, 42};
+#if __cplusplus <= 201402L
+// expected-error@-2 {{no matching constructor}}
+#endif
+
+struct BaseCtor { BaseCtor() = default; }; // expected-note 0+ {{candidate}}
+struct InheritsCtor : BaseCtor { // expected-note 1+ {{candidate}}
+  using BaseCtor::BaseCtor;  // expected-note 2 {{inherited here}}
+  int x;
+};
+InheritsCtor II = {{}, 42}; // expected-error {{no matching constructor}}
+
+#endif  // __cplusplus >= 201103L
+}
+
 namespace dr1550 { // dr1550: yes
   int f(bool b, int n) {
 return (b ? (throw 0) : n) + (b ? n : (throw 0));
Index: test/CXX/dcl.decl/dcl.init/p7.cpp
===
--- test/CXX/dcl.decl/dcl.init/p7.cpp
+++ test/CXX/dcl.decl/dcl.init/p7.cpp
@@ -12,3 +12,5 @@
   explicit B() = default; // expected-note {{here}}
 };
 B b = {}; // expected-error {{chosen constructor is explicit}}
+B b2{};
+B b3;
Index: test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1.cpp
===
--- test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1.cpp
+++ test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1.cpp
@@ -122,3 +122,39 @@
   ~DefaultedAggr() = default;
 };
 DefaultedAggr da = { 42 } ;
+
+struct ExplicitDefaultedAggr {
+  int n;
+  explicit ExplicitDefaultedAggr() = default; // expected-note {{candidate}}
+  ExplicitDefaultedAggr(const ExplicitDefaultedAggr &) = default; // expected-note {{candidate}}
+  ExplicitDefaultedAggr(ExplicitDefaultedAggr &&) = default; // expected-note {{candidate}}
+};
+ExplicitDefaultedAggr eda = { 42 }; // expected-error {{no matching constructor}}
+ExplicitDefaultedAggr eda2{};
+
+struct DefaultedBase {
+  int n;
+  DefaultedBase() = default; // expected-note 0+ {{candidate}}
+  DefaultedBase(DefaultedBase const&) = default; // expected-note 0+ {{candidate}}
+  DefaultedBase(DefaultedBase &&) = default; // expected-note 0+ {{candidate}}
+};
+
+struct InheritingConstructors : DefaultedBase { // expected-note 3 {{candidate}}
+  using DefaultedBase::DefaultedBase; // expected-note 2 {{inherited here}}
+};
+InheritingConstructors ic = { 42 }; // expected-error {{no matching constructor}}
+
+struct NonInheritingConstructors : DefaultedBase {}; // expected-note 0+ {{candidate}}
+NonInheritingConstructors nic = { 42 };
+#if __cplusplus <= 201402L
+// expected-error@-2 {{no matching constructor}}
+#endif
+
+struct NonAggrBase {
+  NonAggrBase(int) {}
+};
+struct HasNonAggrBase : NonAggrBase {}; // expected-note 0+ {{candidate}}
+HasNonAggrBase hnab = {42};
+#if __cplusplus <= 201402L
+// expected-error@-2 {{no matching constructor}}
+#endif
Index: lib/AST/DeclCXX.cpp
===
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -533,6 +533,17 @@
   } else if (Constructor->isMoveConstructor())
 SMKind |= SMF_MoveConstructor;
 }
+
+// C++ [dcl.init.aggr]p1:
+//   An aggregate is an array or a class with no user-declared
+//   constructors [...].
+// C++11 [dcl.init.aggr]p1: DR1518
+//  An aggregate is an array or a class with no user-provided, explicit, or
+//  inherited constructors
+if (getASTContext().getLangOpts().CPlusPlus11
+? (Constructor->isUserProvided() || Constructor->isExplicit())
+: !Constructor

[PATCH] D26830: [libcxx] Add string_view literals

2016-11-17 Thread Anton Bikineev via cfe-commits
AntonBikineev created this revision.
AntonBikineev added reviewers: mclow.lists, rsmith, cfe-commits.
Herald added a reviewer: EricWF.

https://reviews.llvm.org/D26830

Files:
  include/string_view
  test/std/strings/string.view/string.view.literals/literal.pass.cpp
  test/std/strings/string.view/string.view.literals/literal1.fail.cpp
  test/std/strings/string.view/string.view.literals/literal1.pass.cpp
  test/std/strings/string.view/string.view.literals/literal2.fail.cpp
  test/std/strings/string.view/string.view.literals/literal2.pass.cpp
  test/std/strings/string.view/string.view.literals/literal3.pass.cpp

Index: test/std/strings/string.view/string.view.literals/literal3.pass.cpp
===
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal3.pass.cpp
@@ -0,0 +1,21 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+int main()
+{
+using namespace std;
+
+string_view foo  =   ""sv;
+}
Index: test/std/strings/string.view/string.view.literals/literal2.pass.cpp
===
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal2.pass.cpp
@@ -0,0 +1,21 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+int main()
+{
+using namespace std::literals::string_view_literals;
+
+std::string_view foo  =   ""sv;
+}
Index: test/std/strings/string.view/string.view.literals/literal2.fail.cpp
===
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal2.fail.cpp
@@ -0,0 +1,19 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+int main()
+{
+std::string_view foo  =   ""sv;  // should fail w/conversion operator not found
+}
Index: test/std/strings/string.view/string.view.literals/literal1.pass.cpp
===
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal1.pass.cpp
@@ -0,0 +1,21 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+int main()
+{
+using namespace std::literals;
+
+std::string_view foo  =   ""sv;
+}
Index: test/std/strings/string.view/string.view.literals/literal1.fail.cpp
===
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal1.fail.cpp
@@ -0,0 +1,21 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+int main()
+{
+using std::string_view;
+
+string_view foo  =   ""sv;  // should fail w/conversion operator not found
+}
Index: test/std/strings/string.view/string.view.literals/literal.pass.cpp
===
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal.pass.cpp
@@ -0,0 +1,45 @@
+// -*- C++ -*-
+//===--===//
+//
+// The

[PATCH] D26829: [clang] Allow lexer to handle string_view literals

2016-11-17 Thread Anton Bikineev via cfe-commits
AntonBikineev created this revision.
AntonBikineev added reviewers: mclow.lists, rsmith, cfe-commits.

https://reviews.llvm.org/D26829

Files:
  lib/Lex/Lexer.cpp


Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -1713,6 +1713,11 @@
  getLangOpts());
 if (!isIdentifierBody(Next)) {
   // End of suffix. Check whether this is on the whitelist.
+  if (getLangOpts().CPlusPlus1z && Chars == 2 && 
+  Buffer[0] == 's' && Buffer[1] == 'v') {
+IsUDSuffix = true;
+break;
+  }
   IsUDSuffix = (Chars == 1 && Buffer[0] == 's') ||
NumericLiteralParser::isValidUDSuffix(
getLangOpts(), StringRef(Buffer, Chars));


Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -1713,6 +1713,11 @@
  getLangOpts());
 if (!isIdentifierBody(Next)) {
   // End of suffix. Check whether this is on the whitelist.
+  if (getLangOpts().CPlusPlus1z && Chars == 2 && 
+  Buffer[0] == 's' && Buffer[1] == 'v') {
+IsUDSuffix = true;
+break;
+  }
   IsUDSuffix = (Chars == 1 && Buffer[0] == 's') ||
NumericLiteralParser::isValidUDSuffix(
getLangOpts(), StringRef(Buffer, Chars));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24289: Add warning when assigning enums to bitfields without an explicit unsigned underlying type

2016-11-17 Thread Arthur O'Dwyer via cfe-commits
On Thu, Nov 17, 2016 at 2:14 PM, Sasha Bermeister 
wrote:

> Although I agree with your philosophical discussion and suggestions, the
> reality is that MSVC's behavior is not a bug and compilers are free to
> interpret enum bitfields with no explicit underlying type in any way they
> want (see spec reference in GCC bug link), with a signed interpretation
> being a valid one. I'd say it's undefined behavior in C/C++ to store an
> enum in a bitfield without specifying an underlying type, since the
> compiler is free to interpret this bitfield in any way it wants -- in
> general, if you haven't specified an underlying type you should probably be
> warned when trying to store it in a bitfield because the compiler may not
> do what you expect.
>

Incorrect. The following program has perfectly well defined behavior:

enum E { e = 0 };
struct S { E bf : 4; } s;
int main() { s.bf = e; }

No compiler in the world should produce a warning on the above program.

Also, once you've got a struct type containing an offending bit-field, *any*
use of that bit-field is subject to the implementation-defined behavior you
noticed on MSVC. It's not just limited to assignment-expressions of
constants. That's why it's important to produce a warning on the
*declaration* of the bit-field, not on each subsequent expression that
refers to that bit-field.

enum E2 { e = 0, f = 1, g = 2, h = 3 };
struct S2 { E2 bf : 2; } s;  // this line should trigger a diagnostic
int main() { s.bf = e; }

Also, the current patch's diagnostic wording suggests to "consider giving
the enum E an unsigned underlying type", which would be very bad advice in
this situation (because it only works in C++11, and because it triggers a
GCC bug, and because it has non-local effects on the program's semantics).
The correct advice is to "consider giving the bit-field bf a width of 3
bits instead of 2."

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


[PATCH] D26825: [libc++] Fix preprocessor guard for overload declaration

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


https://reviews.llvm.org/D26825



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


[PATCH] D26827: Make tests more robust with Release builds

2016-11-17 Thread Douglas Yung via cfe-commits
dyung created this revision.
dyung added a reviewer: ABataev.
dyung added a subscriber: cfe-commits.

These two tests in many places looks for a pattern:
...
br ... label % ...
...


In non-release builds of the compiler, this works fine. For example:

br label %omp.inner.for.cond, !dbg !313

omp.inner.for.cond: ; preds = %omp.inner.for.inc, %cond.end

In a release build, the compiler generates the following:

br label %13, !dbg !313

; :13: ; preds = %20, %11

The filecheck pattern that caused the problem was this:

// CHECK: br label %[[SIMD_LOOP7_COND:[^,]+]]
// CHECK: [[SIMD_LOOP7_COND]]
// CHECK-NEXT: [[IV7:%.+]] = load i64, i64* [[OMP_IV7]]

The problem is that in a release build example from above, SIMD_LOOP7_COND gets 
the value "13", and then the next CHECK line matches the "13" that is part of 
the same line rather than the intended line 2 lines later. After that, the 
CHECK-NEXT line fails to match because the next line is blank, rather than the 
line immediately following the label as the author originally intended.

The fix is to make the label check more explicit by looking for the trailing 
colon after the label so that it is less likely to match the wrong thing.


https://reviews.llvm.org/D26827

Files:
  test/OpenMP/for_simd_codegen.cpp
  test/OpenMP/simd_codegen.cpp

Index: test/OpenMP/simd_codegen.cpp
===
--- test/OpenMP/simd_codegen.cpp
+++ test/OpenMP/simd_codegen.cpp
@@ -20,7 +20,7 @@
 // CHECK-NEXT: [[CMP:%.+]] = icmp slt i32 [[IV]], 6
 // CHECK-NEXT: br i1 [[CMP]], label %[[SIMPLE_LOOP1_BODY:.+]], label %[[SIMPLE_LOOP1_END:[^,]+]]
   for (int i = 3; i < 32; i += 5) {
-// CHECK: [[SIMPLE_LOOP1_BODY]]
+// CHECK: [[SIMPLE_LOOP1_BODY]]:
 // Start of body: calculate i from IV:
 // CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP1_ID]]
 // CHECK: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 5
@@ -35,7 +35,7 @@
 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP1_ID]]
 // br label %{{.+}}, !llvm.loop !{{.+}}
   }
-// CHECK: [[SIMPLE_LOOP1_END]]
+// CHECK: [[SIMPLE_LOOP1_END]]:
 
   long long k = get_val();
 
@@ -50,7 +50,7 @@
 // CHECK-NEXT: [[CMP2:%.+]] = icmp slt i32 [[IV2]], 9
 // CHECK-NEXT: br i1 [[CMP2]], label %[[SIMPLE_LOOP2_BODY:.+]], label %[[SIMPLE_LOOP2_END:[^,]+]]
   for (int i = 10; i > 1; i--) {
-// CHECK: [[SIMPLE_LOOP2_BODY]]
+// CHECK: [[SIMPLE_LOOP2_BODY]]:
 // Start of body: calculate i from IV:
 // CHECK: [[IV2_0:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID]]
 // FIXME: It is interesting, why the following "mul 1" was not constant folded?
@@ -72,7 +72,7 @@
 // CHECK-NEXT: store i32 [[ADD2_2]], i32* [[OMP_IV2]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID]]
 // br label {{.+}}, !llvm.loop ![[SIMPLE_LOOP2_ID]]
   }
-// CHECK: [[SIMPLE_LOOP2_END]]
+// CHECK: [[SIMPLE_LOOP2_END]]:
 //
 // Update linear vars after loop, as the loop was operating on a private version.
 // CHECK: [[LIN0_2:%.+]] = load i64, i64* [[LIN0]]
@@ -100,7 +100,7 @@
 // CHECK-NEXT: [[CMP3:%.+]] = icmp ult i64 [[IV3]], 4
 // CHECK-NEXT: br i1 [[CMP3]], label %[[SIMPLE_LOOP3_BODY:.+]], label %[[SIMPLE_LOOP3_END:[^,]+]]
   for (unsigned long long it = 2000; it >= 600; it-=400) {
-// CHECK: [[SIMPLE_LOOP3_BODY]]
+// CHECK: [[SIMPLE_LOOP3_BODY]]:
 // Start of body: calculate it from IV:
 // CHECK: [[IV3_0:%.+]] = load i64, i64* [[OMP_IV3]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul i64 [[IV3_0]], 400
@@ -126,7 +126,7 @@
 // CHECK-NEXT: [[ADD3_2:%.+]] = add i64 [[IV3_2]], 1
 // CHECK-NEXT: store i64 [[ADD3_2]], i64* [[OMP_IV3]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
   }
-// CHECK: [[SIMPLE_LOOP3_END]]
+// CHECK: [[SIMPLE_LOOP3_END]]:
 //
 // Linear start and step are used to calculate final value of the linear variables.
 // CHECK: [[LINSTART:.+]] = load i32, i32* [[LIN_START]]
@@ -142,7 +142,7 @@
 // CHECK-NEXT: [[CMP4:%.+]] = icmp slt i32 [[IV4]], 4
 // CHECK-NEXT: br i1 [[CMP4]], label %[[SIMPLE_LOOP4_BODY:.+]], label %[[SIMPLE_LOOP4_END:[^,]+]]
   for (short it = 6; it <= 20; it-=-4) {
-// CHECK: [[SIMPLE_LOOP4_BODY]]
+// CHECK: [[SIMPLE_LOOP4_BODY]]:
 // Start of body: calculate it from IV:
 // CHECK: [[IV4_0:%.+]] = load i32, i32* [[OMP_IV4]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP4_ID]]
 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul nsw i32 [[IV4_0]], 4
@@ -154,16 +154,16 @@
 // CHECK-NEXT: [[ADD4_2:%.+]] = add nsw i32 [[IV4_2]], 1
 // CHECK-NEXT: store i32 [[ADD4_2]], i32* [[OMP_IV4]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP4_ID]]
   }
-// CHECK: [[SIMPLE_LOOP4_END]]
+// CHECK: [[SIMPLE_LOOP4_END]]:
 
   #pragma omp simd
 // CHECK: store i32 0, i32* [[OMP_IV5:%[^,]+]]
 
 // CHECK: [[IV5:%.+]] = load i32, i32* [[OMP_IV5]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP5_ID:[0-9]+]]
 // CHECK-NEXT: [[C

[PATCH] D26826: [libcxx] Implement locale.h to fix modules build

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF created this revision.
EricWF added reviewers: mclow.lists, rsmith.
EricWF added a subscriber: cfe-commits.

Because `locale.h` isn't part of the libc++ modules the class definitions it 
provides are exported as part of `__locale` (since it happens to be build 
first). This breaks `` which exports `std::lconv` without including 
`<__locale>`.

This patch implements `locale.h` to fix this issue, it also adds support for 
testing libc++ with modules.


https://reviews.llvm.org/D26826

Files:
  include/locale.h
  include/module.modulemap
  test/libcxx/depr/depr.c.headers/locale_h.pass.cpp
  test/libcxx/modules/clocale_exports.sh.cpp
  test/libcxx/test/config.py

Index: test/libcxx/test/config.py
===
--- test/libcxx/test/config.py
+++ test/libcxx/test/config.py
@@ -13,6 +13,7 @@
 import pkgutil
 import re
 import shlex
+import shutil
 import sys
 
 import lit.Test  # pylint: disable=import-error,no-name-in-module
@@ -64,6 +65,7 @@
 self.cxx_library_root = None
 self.cxx_runtime_root = None
 self.abi_library_root = None
+self.module_cache_path = None
 self.env = {}
 self.use_target = False
 self.use_system_cxx_lib = False
@@ -117,6 +119,7 @@
 self.configure_warnings()
 self.configure_sanitizer()
 self.configure_coverage()
+self.configure_modules()
 self.configure_substitutions()
 self.configure_features()
 
@@ -721,6 +724,27 @@
 self.cxx.flags += ['-g', '--coverage']
 self.cxx.compile_flags += ['-O0']
 
+def configure_modules(self):
+supports_modules = self.cxx.hasCompileFlag('-fmodules')
+enable_modules = self.get_lit_bool('enable_modules', False)
+if enable_modules and not supports_modules:
+self.lit_config.fatal(
+'-fmodules is enabled but not supported by the compiler')
+if not supports_modules:
+return
+self.config.available_features.add('modules-support')
+module_cache = os.path.join(self.config.test_exec_root,
+   'modules.cache')
+module_cache = os.path.realpath(module_cache)
+if os.path.isdir(module_cache):
+shutil.rmtree(module_cache)
+os.makedirs(module_cache)
+self.module_cache_path = module_cache
+if enable_modules:
+self.config.available_features.add('-fmodules')
+self.cxx.compile_flags += ['-fmodules',
+   '-fmodules-cache-path=' + module_cache]
+
 def configure_substitutions(self):
 sub = self.config.substitutions
 # Configure compiler substitutions
@@ -734,6 +758,13 @@
 sub.append(('%compile_flags', compile_flags_str))
 sub.append(('%link_flags', link_flags_str))
 sub.append(('%all_flags', all_flags))
+
+module_flags = None
+if not self.module_cache_path is None:
+module_flags = '-fmodules -fmodules-cache-path=' \
+   + self.module_cache_path + ' '
+
+
 # Add compile and link shortcuts
 compile_str = (self.cxx.path + ' -o %t.o %s -c ' + flags_str
+ compile_flags_str)
@@ -743,6 +774,8 @@
 build_str = self.cxx.path + ' -o %t.exe %s ' + all_flags
 sub.append(('%compile', compile_str))
 sub.append(('%link', link_str))
+if not module_flags is None:
+sub.append(('%build_module', build_str + ' ' + module_flags))
 sub.append(('%build', build_str))
 # Configure exec prefix substitutions.
 exec_env_str = 'env ' if len(self.env) != 0 else ''
Index: test/libcxx/modules/clocale_exports.sh.cpp
===
--- /dev/null
+++ test/libcxx/modules/clocale_exports.sh.cpp
@@ -0,0 +1,23 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// REQUIRES: modules-support
+
+// RUN: %build_module
+
+#include 
+
+#define TEST(...) do { using T = decltype( __VA_ARGS__ ); } while(false)
+
+int main() {
+  std::lconv l; ((void)l);
+
+  TEST(std::setlocale(0, ""));
+  TEST(std::localeconv());
+}
Index: test/libcxx/depr/depr.c.headers/locale_h.pass.cpp
===
--- /dev/null
+++ test/libcxx/depr/depr.c.headers/locale_h.pass.cpp
@@ -0,0 +1,20 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Sour

[PATCH] D25866: [Sema] Support implicit scalar to vector conversions

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



Comment at: lib/Sema/SemaExpr.cpp:7978
+/// without causing truncation of Scalar.
+
+static bool tryGCCVectorConvertAndSpalt(Sema &S, ExprResult *Scalar,

Remove this empty line.



Comment at: lib/Sema/SemaExpr.cpp:7991
+  (!ScalarTy->isIntegralType(S.Context) &&
+   !ScalarTy->isRealFloatingType()))
+return true;

This can be simplified by checking isArithmeticType() for each instead.



Comment at: lib/Sema/SemaExpr.cpp:8005
+// type and then perform the rest of the checks here.
+if (!ScalarTy->isIntegralType(S.Context))
+  return true;

You already checked this condition in the `if` above, this will never trigger.



Comment at: lib/Sema/SemaExpr.cpp:8043
+  } else if (VectorEltTy->isRealFloatingType()) {
+if (ScalarTy->isRealFloatingType() && VectorEltTy != ScalarTy) {
+

I don't see how `VectorEltTy != ScalarTy` is possible here.



Comment at: lib/Sema/SemaExpr.cpp:8064
+  ScalarCast = CK_FloatingCast;
+} else if (ScalarTy->isIntegralType(S.Context)) {
+  // Determine if the integer constant can be expressed as a floating point

I don't see why it's necessary to check for all specific cases where the scalar 
is a constant. For all the others scenarios it should be enough to get the 
right answer via `getIntegerTypeOrder` or `getFloatTypeOrder`. For this is 
specific condition, the `else` part for the `CstScalar` below should also 
handle the constant case, right? 





Comment at: lib/Sema/SemaExpr.cpp:8267
+  }
+
   // Otherwise, use the generic diagnostic.

This change seems orthogonal to this patch. Can you make it a separated patch 
with the changes from test/Sema/vector-cast.c?



Comment at: test/Sema/vector-gcc-compat.c:2
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Weverything
+
+typedef long long v2i64 __attribute__((vector_size(16)));

These are really nice tests. Some cosmetic cleanups: can you run it through 
clang-format and also remove (a) newlines between comments and codes, (b) 
places with double newlines?


https://reviews.llvm.org/D25866



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


[PATCH] D26825: [libc++] Fix preprocessor guard for overload declaration

2016-11-17 Thread Shoaib Meenai via cfe-commits
smeenai created this revision.
smeenai added reviewers: mclow.lists, EricWF.
smeenai added a subscriber: cfe-commits.

Fix a typo in the conditional.  Caught by going through list of removed
symbols when building with hidden visibility.


https://reviews.llvm.org/D26825

Files:
  include/new


Index: include/new
===
--- include/new
+++ include/new
@@ -180,7 +180,7 @@
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const 
std::nothrow_t&) _NOEXCEPT _NOALIAS;
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p) _NOEXCEPT;
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, const 
std::nothrow_t&) _NOEXCEPT;
-#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
+#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, std::size_t 
__sz) _NOEXCEPT;
 #endif
 


Index: include/new
===
--- include/new
+++ include/new
@@ -180,7 +180,7 @@
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p) _NOEXCEPT;
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
-#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
+#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
 _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25208: [libc++] Make _LIBCPP_TYPE_VIS export members

2016-11-17 Thread Shoaib Meenai via cfe-commits
smeenai added a comment.

I should clarify that the ABI omissions are for Linux.


https://reviews.llvm.org/D25208



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


[PATCH] D25208: [libc++] Make _LIBCPP_TYPE_VIS export members

2016-11-17 Thread Shoaib Meenai via cfe-commits
smeenai added a comment.

Ping.

I used @EricWF's ABI list verification work to confirm that this diff doesn't 
change the ABI of libc++ on both Darwin and Linux, so it should be completely 
safe.

Building with hidden visibility on top of this patch gives the following ABI 
removals: https://reviews.llvm.org/P7937. I'll be going through this list over 
the next few days to figure out if the omissions are actually correct or if 
they're indicative of missing source export annotations. 
https://reviews.llvm.org/D26823 resulted from this effort.


https://reviews.llvm.org/D25208



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


r287295 - Add doxygen comments to fxsrintrin.h's intrinsics.

2016-11-17 Thread Ekaterina Romanova via cfe-commits
Author: kromanova
Date: Thu Nov 17 19:42:01 2016
New Revision: 287295

URL: http://llvm.org/viewvc/llvm-project?rev=287295&view=rev
Log:
Add doxygen comments to fxsrintrin.h's intrinsics.

The doxygen comments are automatically generated based on Sony's intrinsics 
document.

I got an OK from Eric Christopher to commit doxygen comments without prior code
review upstream. This patch was internally reviewed by Paul Robinson and 
Charles Li.


Modified:
cfe/trunk/lib/Headers/fxsrintrin.h

Modified: cfe/trunk/lib/Headers/fxsrintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/fxsrintrin.h?rev=287295&r1=287294&r2=287295&view=diff
==
--- cfe/trunk/lib/Headers/fxsrintrin.h (original)
+++ cfe/trunk/lib/Headers/fxsrintrin.h Thu Nov 17 19:42:01 2016
@@ -30,24 +30,72 @@
 
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__,  
__target__("fxsr")))
 
+/// \brief Saves the XMM, MMX, MXCSR and x87 FPU registers into a 512-byte
+///memory region pointed to by the input parameter __p.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c FXSAVE instruction.
+///
+/// \param __p
+///A pointer to a 512-byte memory region. The beginning of this memory
+///region should be aligned on a 16-byte boundary.
 static __inline__ void __DEFAULT_FN_ATTRS
-_fxsave(void *__p) {
+_fxsave(void *__p)
+{
   return __builtin_ia32_fxsave(__p);
 }
 
+/// \brief Restores the XMM, MMX, MXCSR and x87 FPU registers from the 512-byte
+///memory region pointed to by the input parameter __p. The contents of 
this
+///memory region should have been written to by a previous _fxsave or
+///_fxsave64 intrinsic.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c FXRSTOR instruction.
+///
+/// \param __p
+///A pointer to a 512-byte memory region. The beginning of this memory
+///region should be aligned on a 16-byte boundary.
 static __inline__ void __DEFAULT_FN_ATTRS
-_fxrstor(void *__p) {
+_fxrstor(void *__p)
+{
   return __builtin_ia32_fxrstor(__p);
 }
 
 #ifdef __x86_64__
+/// \brief Saves the XMM, MMX, MXCSR and x87 FPU registers into a 512-byte
+///memory region pointed to by the input parameter__p.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c FXSAVE64 instruction.
+///
+/// \param __p
+///A pointer to a 512-byte memory region. The beginning of this memory
+///region should be aligned on a 16-byte boundary.
 static __inline__ void __DEFAULT_FN_ATTRS
-_fxsave64(void *__p) {
+_fxsave64(void *__p)
+{
   return __builtin_ia32_fxsave64(__p);
 }
 
+/// \brief Restores the XMM, MMX, MXCSR and x87 FPU registers from the 512-byte
+///memory region pointed to by the input parameter __p. The contents of 
this
+///memory region should have been written to by a previous _fxsave or
+///_fxsave64 intrinsic.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c FXRSTOR64 instruction.
+///
+/// \param __p
+///A pointer to a 512-byte memory region. The beginning of this memory
+///region should be aligned on a 16-byte boundary.
 static __inline__ void __DEFAULT_FN_ATTRS
-_fxrstor64(void *__p) {
+_fxrstor64(void *__p)
+{
   return __builtin_ia32_fxrstor64(__p);
 }
 #endif


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


[PATCH] D26560: Add a test for vcall on a null ptr.

2016-11-17 Thread Peter Collingbourne via cfe-commits
pcc added inline comments.



Comment at: test/ubsan/TestCases/TypeCheck/null.cpp:1
-// RUN: %clangxx -fsanitize=null %s -O3 -o %t
-// RUN: %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD
-// RUN: %expect_crash %run %t s 2>&1 | FileCheck %s --check-prefix=CHECK-STORE
-// RUN: %run %t r 2>&1 | FileCheck %s --check-prefix=CHECK-REFERENCE
-// RUN: %run %t m 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER
-// RUN: %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN
+// RUN: %clangxx -fsanitize=null -fno-sanitize-recover=null -g %s -O3 -o %t
+// RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD

Why add the -g?



Comment at: test/ubsan/TestCases/TypeCheck/null.cpp:10
+
+#include 
 

Is this #include needed?



Comment at: test/ubsan/TestCases/TypeCheck/null.cpp:35
+
+  if (argv[1][0] == 'T') {
+t = new T;

Did you intend to add tests for these cases?


https://reviews.llvm.org/D26560



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


r287292 - [CUDA] Attempt to fix test failures in cuda-macos-includes.cu.

2016-11-17 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Thu Nov 17 19:11:32 2016
New Revision: 287292

URL: http://llvm.org/viewvc/llvm-project?rev=287292&view=rev
Log:
[CUDA] Attempt to fix test failures in cuda-macos-includes.cu.

Run clang -cc1 -E instead of -S, in an attempt to make this test work
cross-platform.

Modified:
cfe/trunk/test/Preprocessor/cuda-macos-includes.cu

Modified: cfe/trunk/test/Preprocessor/cuda-macos-includes.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/cuda-macos-includes.cu?rev=287292&r1=287291&r2=287292&view=diff
==
--- cfe/trunk/test/Preprocessor/cuda-macos-includes.cu (original)
+++ cfe/trunk/test/Preprocessor/cuda-macos-includes.cu Thu Nov 17 19:11:32 2016
@@ -1,10 +1,10 @@
 // RUN: %clang -cc1 -fcuda-is-device -isysroot /var/empty \
 // RUN:   -triple nvptx-nvidia-cuda -aux-triple i386-apple-macosx \
-// RUN:   -S -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
+// RUN:   -E -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
 
 // RUN: %clang -cc1 -isysroot /var/empty \
 // RUN:   -triple i386-apple-macosx -aux-triple nvptx-nvidia-cuda \
-// RUN:   -S -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
+// RUN:   -E -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
 
 // Check that when we do CUDA host and device compiles on MacOS, we check for
 // includes in /System/Library/Frameworks and /Library/Frameworks.


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


r287291 - Forward ns_consumed delegate arguments with a move.

2016-11-17 Thread John McCall via cfe-commits
Author: rjmccall
Date: Thu Nov 17 19:08:24 2016
New Revision: 287291

URL: http://llvm.org/viewvc/llvm-project?rev=287291&view=rev
Log:
Forward ns_consumed delegate arguments with a move.

StartFunction enters a release cleanup for ns_consumed arguments in
ARC, so we need to balance that somehow.  We could teach StartFunction
that it's emitting a delegating function, so that the cleanup is
unnecessary, but that would be invasive and somewhat fraught.  We could
balance the consumed argument with an extra retain, but clearing the
original variable should be easier to optimize and avoid some extra work
at -O0.  And there shouldn't be any difference as long as nothing else
uses the argument, which should always be true for the places we emit
delegate arguments.

Fixes PR 27887.

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/test/CodeGenObjCXX/arc-attrs.mm

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=287291&r1=287290&r2=287291&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Nov 17 19:08:24 2016
@@ -2912,12 +2912,30 @@ void CodeGenFunction::EmitDelegateCallAr
   assert(!isInAllocaArgument(CGM.getCXXABI(), type) &&
  "cannot emit delegate call arguments for inalloca arguments!");
 
+  // GetAddrOfLocalVar returns a pointer-to-pointer for references,
+  // but the argument needs to be the original pointer.
+  if (type->isReferenceType()) {
+args.add(RValue::get(Builder.CreateLoad(local)), type);
+
+  // In ARC, move out of consumed arguments so that the release cleanup
+  // entered by StartFunction doesn't cause an over-release.  This isn't
+  // optimal -O0 code generation, but it should get cleaned up when
+  // optimization is enabled.  This also assumes that delegate calls are
+  // performed exactly once for a set of arguments, but that should be safe.
+  } else if (getLangOpts().ObjCAutoRefCount &&
+ param->hasAttr() &&
+ type->isObjCRetainableType()) {
+llvm::Value *ptr = Builder.CreateLoad(local);
+auto null =
+  llvm::ConstantPointerNull::get(cast(ptr->getType()));
+Builder.CreateStore(null, local);
+args.add(RValue::get(ptr), type);
+
   // For the most part, we just need to load the alloca, except that
   // aggregate r-values are actually pointers to temporaries.
-  if (type->isReferenceType())
-args.add(RValue::get(Builder.CreateLoad(local)), type);
-  else
+  } else {
 args.add(convertTempToRValue(local, type, loc), type);
+  }
 }
 
 static bool isProvablyNull(llvm::Value *addr) {

Modified: cfe/trunk/test/CodeGenObjCXX/arc-attrs.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-attrs.mm?rev=287291&r1=287290&r2=287291&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/arc-attrs.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/arc-attrs.mm Thu Nov 17 19:08:24 2016
@@ -46,3 +46,24 @@ void templateTest() {
   // CHECK-NEXT: call void @objc_storeStrong(i8** [[X]], i8* null)
   // CHECK-NEXT: ret void
 }
+
+// PR27887
+struct ForwardConsumed {
+  ForwardConsumed(__attribute__((ns_consumed)) id x);
+};
+
+ForwardConsumed::ForwardConsumed(__attribute__((ns_consumed)) id x) {}
+
+// CHECK: define void @_ZN15ForwardConsumedC2EP11objc_object(
+// CHECK-NOT:  objc_retain
+// CHECK:  store i8* {{.*}}, i8** [[X:%.*]],
+// CHECK-NOT:  [[X]]
+// CHECK:  call void @objc_storeStrong(i8** [[X]], i8* null)
+
+// CHECK: define void @_ZN15ForwardConsumedC1EP11objc_object(
+// CHECK-NOT:  objc_retain
+// CHECK:  store i8* {{.*}}, i8** [[X:%.*]],
+// CHECK:  [[T0:%.*]] = load i8*, i8** [[X]],
+// CHECK-NEXT: store i8* null, i8** [[X]],
+// CHECK-NEXT: call void @_ZN15ForwardConsumedC2EP11objc_object({{.*}}, i8* 
[[T0]])
+// CHECK:  call void @objc_storeStrong(i8** [[X]], i8* null)


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


[PATCH] D26780: [CUDA] Wrapper header changes necessary to support MacOS.

2016-11-17 Thread Justin Lebar via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287288: [CUDA] Wrapper header changes necessary to support 
MacOS. (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D26780?vs=78298&id=78438#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26780

Files:
  cfe/trunk/lib/Headers/__clang_cuda_cmath.h
  cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h


Index: cfe/trunk/lib/Headers/__clang_cuda_cmath.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_cmath.h
+++ cfe/trunk/lib/Headers/__clang_cuda_cmath.h
@@ -75,7 +75,10 @@
 __DEVICE__ bool isinf(float __x) { return ::__isinff(__x); }
 __DEVICE__ bool isinf(double __x) { return ::__isinf(__x); }
 __DEVICE__ bool isfinite(float __x) { return ::__finitef(__x); }
-__DEVICE__ bool isfinite(double __x) { return ::__finite(__x); }
+// For inscrutable reasons, __finite(), the double-precision version of
+// __finitef, does not exist when compiling for MacOS.  __isfinited is 
available
+// everywhere and is just as good.
+__DEVICE__ bool isfinite(double __x) { return ::__isfinited(__x); }
 __DEVICE__ bool isgreater(float __x, float __y) {
   return __builtin_isgreater(__x, __y);
 }
@@ -141,7 +144,7 @@
   return ::powi(__base, __iexp);
 }
 __DEVICE__ bool signbit(float __x) { return ::__signbitf(__x); }
-__DEVICE__ bool signbit(double __x) { return ::__signbit(__x); }
+__DEVICE__ bool signbit(double __x) { return ::__signbitd(__x); }
 __DEVICE__ float sin(float __x) { return ::sinf(__x); }
 __DEVICE__ float sinh(float __x) { return ::sinhf(__x); }
 __DEVICE__ float sqrt(float __x) { return ::sqrtf(__x); }
Index: cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h
+++ cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h
@@ -121,6 +121,15 @@
 #undef __cxa_vec_delete3
 #undef __cxa_pure_virtual
 
+// math_functions.hpp expects this host function be defined on MacOS, but it
+// ends up not being there because of the games we play here.  Just define it
+// ourselves; it's simple enough.
+#ifdef __APPLE__
+inline __host__ double __signbitd(double x) {
+  return std::signbit(x);
+}
+#endif
+
 // We need decls for functions in CUDA's libdevice with __device__
 // attribute only. Alas they come either as __host__ __device__ or
 // with no attributes at all. To work around that, define __CUDA_RTC__


Index: cfe/trunk/lib/Headers/__clang_cuda_cmath.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_cmath.h
+++ cfe/trunk/lib/Headers/__clang_cuda_cmath.h
@@ -75,7 +75,10 @@
 __DEVICE__ bool isinf(float __x) { return ::__isinff(__x); }
 __DEVICE__ bool isinf(double __x) { return ::__isinf(__x); }
 __DEVICE__ bool isfinite(float __x) { return ::__finitef(__x); }
-__DEVICE__ bool isfinite(double __x) { return ::__finite(__x); }
+// For inscrutable reasons, __finite(), the double-precision version of
+// __finitef, does not exist when compiling for MacOS.  __isfinited is available
+// everywhere and is just as good.
+__DEVICE__ bool isfinite(double __x) { return ::__isfinited(__x); }
 __DEVICE__ bool isgreater(float __x, float __y) {
   return __builtin_isgreater(__x, __y);
 }
@@ -141,7 +144,7 @@
   return ::powi(__base, __iexp);
 }
 __DEVICE__ bool signbit(float __x) { return ::__signbitf(__x); }
-__DEVICE__ bool signbit(double __x) { return ::__signbit(__x); }
+__DEVICE__ bool signbit(double __x) { return ::__signbitd(__x); }
 __DEVICE__ float sin(float __x) { return ::sinf(__x); }
 __DEVICE__ float sinh(float __x) { return ::sinhf(__x); }
 __DEVICE__ float sqrt(float __x) { return ::sqrtf(__x); }
Index: cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h
+++ cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h
@@ -121,6 +121,15 @@
 #undef __cxa_vec_delete3
 #undef __cxa_pure_virtual
 
+// math_functions.hpp expects this host function be defined on MacOS, but it
+// ends up not being there because of the games we play here.  Just define it
+// ourselves; it's simple enough.
+#ifdef __APPLE__
+inline __host__ double __signbitd(double x) {
+  return std::signbit(x);
+}
+#endif
+
 // We need decls for functions in CUDA's libdevice with __device__
 // attribute only. Alas they come either as __host__ __device__ or
 // with no attributes at all. To work around that, define __CUDA_RTC__
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26776: [CUDA] Initialize our header search using the host triple.

2016-11-17 Thread Justin Lebar via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287286: [CUDA] Initialize our header search using the host 
triple. (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D26776?vs=78290&id=78436#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26776

Files:
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/test/Preprocessor/cuda-macos-includes.cu


Index: cfe/trunk/test/Preprocessor/cuda-macos-includes.cu
===
--- cfe/trunk/test/Preprocessor/cuda-macos-includes.cu
+++ cfe/trunk/test/Preprocessor/cuda-macos-includes.cu
@@ -0,0 +1,13 @@
+// RUN: %clang -cc1 -fcuda-is-device -isysroot /var/empty \
+// RUN:   -triple nvptx-nvidia-cuda -aux-triple i386-apple-macosx \
+// RUN:   -S -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
+
+// RUN: %clang -cc1 -isysroot /var/empty \
+// RUN:   -triple i386-apple-macosx -aux-triple nvptx-nvidia-cuda \
+// RUN:   -S -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
+
+// Check that when we do CUDA host and device compiles on MacOS, we check for
+// includes in /System/Library/Frameworks and /Library/Frameworks.
+
+// CHECK-DAG: ignoring nonexistent directory 
"/var/empty/System/Library/Frameworks"
+// CHECK-DAG: ignoring nonexistent directory "/var/empty/Library/Frameworks"
Index: cfe/trunk/lib/Frontend/CompilerInstance.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp
@@ -334,9 +334,16 @@
   InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
  getFrontendOpts());
 
-  // Initialize the header search object.
+  // Initialize the header search object.  In CUDA compilations, we use the aux
+  // triple (the host triple) to initialize our header search, since we need to
+  // find the host headers in order to compile the CUDA code.
+  const llvm::Triple *HeaderSearchTriple = &PP->getTargetInfo().getTriple();
+  if (PP->getTargetInfo().getTriple().getOS() == llvm::Triple::CUDA &&
+  PP->getAuxTargetInfo())
+HeaderSearchTriple = &PP->getAuxTargetInfo()->getTriple();
+
   ApplyHeaderSearchOptions(PP->getHeaderSearchInfo(), getHeaderSearchOpts(),
-   PP->getLangOpts(), PP->getTargetInfo().getTriple());
+   PP->getLangOpts(), *HeaderSearchTriple);
 
   PP->setPreprocessedOutput(getPreprocessorOutputOpts().ShowCPP);
 


Index: cfe/trunk/test/Preprocessor/cuda-macos-includes.cu
===
--- cfe/trunk/test/Preprocessor/cuda-macos-includes.cu
+++ cfe/trunk/test/Preprocessor/cuda-macos-includes.cu
@@ -0,0 +1,13 @@
+// RUN: %clang -cc1 -fcuda-is-device -isysroot /var/empty \
+// RUN:   -triple nvptx-nvidia-cuda -aux-triple i386-apple-macosx \
+// RUN:   -S -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
+
+// RUN: %clang -cc1 -isysroot /var/empty \
+// RUN:   -triple i386-apple-macosx -aux-triple nvptx-nvidia-cuda \
+// RUN:   -S -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
+
+// Check that when we do CUDA host and device compiles on MacOS, we check for
+// includes in /System/Library/Frameworks and /Library/Frameworks.
+
+// CHECK-DAG: ignoring nonexistent directory "/var/empty/System/Library/Frameworks"
+// CHECK-DAG: ignoring nonexistent directory "/var/empty/Library/Frameworks"
Index: cfe/trunk/lib/Frontend/CompilerInstance.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp
@@ -334,9 +334,16 @@
   InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
  getFrontendOpts());
 
-  // Initialize the header search object.
+  // Initialize the header search object.  In CUDA compilations, we use the aux
+  // triple (the host triple) to initialize our header search, since we need to
+  // find the host headers in order to compile the CUDA code.
+  const llvm::Triple *HeaderSearchTriple = &PP->getTargetInfo().getTriple();
+  if (PP->getTargetInfo().getTriple().getOS() == llvm::Triple::CUDA &&
+  PP->getAuxTargetInfo())
+HeaderSearchTriple = &PP->getAuxTargetInfo()->getTriple();
+
   ApplyHeaderSearchOptions(PP->getHeaderSearchInfo(), getHeaderSearchOpts(),
-   PP->getLangOpts(), PP->getTargetInfo().getTriple());
+   PP->getLangOpts(), *HeaderSearchTriple);
 
   PP->setPreprocessedOutput(getPreprocessorOutputOpts().ShowCPP);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26777: [CUDA] Use the right section and constant names for fatbins when compiling for macos.

2016-11-17 Thread Justin Lebar via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287287: [CUDA] Use the right section and constant names for 
fatbins when compiling for… (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D26777?vs=78291&id=78437#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26777

Files:
  cfe/trunk/lib/CodeGen/CGCUDANV.cpp


Index: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
===
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp
@@ -289,19 +289,24 @@
   continue;
 }
 
+const char *FatbinConstantName =
+CGM.getTriple().isMacOSX() ? "__NV_CUDA,__nv_fatbin" : ".nv_fatbin";
+// NVIDIA's cuobjdump looks for fatbins in this section.
+const char *FatbinSectionName =
+CGM.getTriple().isMacOSX() ? "__NV_CUDA,__fatbin" : ".nvFatBinSegment";
+
 // Create initialized wrapper structure that points to the loaded GPU 
binary
 llvm::Constant *Values[] = {
 llvm::ConstantInt::get(IntTy, 0x466243b1), // Fatbin wrapper magic.
 llvm::ConstantInt::get(IntTy, 1),  // Fatbin version.
 makeConstantString(GpuBinaryOrErr.get()->getBuffer(), // Data.
-   "", ".nv_fatbin", 8),  //
+   "", FatbinConstantName, 8),
 llvm::ConstantPointerNull::get(VoidPtrTy)}; // Unused in fatbin v1.
 llvm::GlobalVariable *FatbinWrapper = new llvm::GlobalVariable(
 TheModule, FatbinWrapperTy, true, llvm::GlobalValue::InternalLinkage,
 llvm::ConstantStruct::get(FatbinWrapperTy, Values),
 "__cuda_fatbin_wrapper");
-// NVIDIA's cuobjdump looks for fatbins in this section.
-FatbinWrapper->setSection(".nvFatBinSegment");
+FatbinWrapper->setSection(FatbinSectionName);
 
 // GpuBinaryHandle = __cudaRegisterFatBinary(&FatbinWrapper);
 llvm::CallInst *RegisterFatbinCall = CtorBuilder.CreateCall(


Index: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
===
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp
@@ -289,19 +289,24 @@
   continue;
 }
 
+const char *FatbinConstantName =
+CGM.getTriple().isMacOSX() ? "__NV_CUDA,__nv_fatbin" : ".nv_fatbin";
+// NVIDIA's cuobjdump looks for fatbins in this section.
+const char *FatbinSectionName =
+CGM.getTriple().isMacOSX() ? "__NV_CUDA,__fatbin" : ".nvFatBinSegment";
+
 // Create initialized wrapper structure that points to the loaded GPU binary
 llvm::Constant *Values[] = {
 llvm::ConstantInt::get(IntTy, 0x466243b1), // Fatbin wrapper magic.
 llvm::ConstantInt::get(IntTy, 1),  // Fatbin version.
 makeConstantString(GpuBinaryOrErr.get()->getBuffer(), // Data.
-   "", ".nv_fatbin", 8),  //
+   "", FatbinConstantName, 8),
 llvm::ConstantPointerNull::get(VoidPtrTy)}; // Unused in fatbin v1.
 llvm::GlobalVariable *FatbinWrapper = new llvm::GlobalVariable(
 TheModule, FatbinWrapperTy, true, llvm::GlobalValue::InternalLinkage,
 llvm::ConstantStruct::get(FatbinWrapperTy, Values),
 "__cuda_fatbin_wrapper");
-// NVIDIA's cuobjdump looks for fatbins in this section.
-FatbinWrapper->setSection(".nvFatBinSegment");
+FatbinWrapper->setSection(FatbinSectionName);
 
 // GpuBinaryHandle = __cudaRegisterFatBinary(&FatbinWrapper);
 llvm::CallInst *RegisterFatbinCall = CtorBuilder.CreateCall(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r287288 - [CUDA] Wrapper header changes necessary to support MacOS.

2016-11-17 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Thu Nov 17 18:41:35 2016
New Revision: 287288

URL: http://llvm.org/viewvc/llvm-project?rev=287288&view=rev
Log:
[CUDA] Wrapper header changes necessary to support MacOS.

Reviewers: tra

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Headers/__clang_cuda_cmath.h
cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h

Modified: cfe/trunk/lib/Headers/__clang_cuda_cmath.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_cmath.h?rev=287288&r1=287287&r2=287288&view=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_cmath.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_cmath.h Thu Nov 17 18:41:35 2016
@@ -75,7 +75,10 @@ __DEVICE__ float frexp(float __arg, int
 __DEVICE__ bool isinf(float __x) { return ::__isinff(__x); }
 __DEVICE__ bool isinf(double __x) { return ::__isinf(__x); }
 __DEVICE__ bool isfinite(float __x) { return ::__finitef(__x); }
-__DEVICE__ bool isfinite(double __x) { return ::__finite(__x); }
+// For inscrutable reasons, __finite(), the double-precision version of
+// __finitef, does not exist when compiling for MacOS.  __isfinited is 
available
+// everywhere and is just as good.
+__DEVICE__ bool isfinite(double __x) { return ::__isfinited(__x); }
 __DEVICE__ bool isgreater(float __x, float __y) {
   return __builtin_isgreater(__x, __y);
 }
@@ -141,7 +144,7 @@ __DEVICE__ double pow(double __base, int
   return ::powi(__base, __iexp);
 }
 __DEVICE__ bool signbit(float __x) { return ::__signbitf(__x); }
-__DEVICE__ bool signbit(double __x) { return ::__signbit(__x); }
+__DEVICE__ bool signbit(double __x) { return ::__signbitd(__x); }
 __DEVICE__ float sin(float __x) { return ::sinf(__x); }
 __DEVICE__ float sinh(float __x) { return ::sinhf(__x); }
 __DEVICE__ float sqrt(float __x) { return ::sqrtf(__x); }

Modified: cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h?rev=287288&r1=287287&r2=287288&view=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h Thu Nov 17 18:41:35 
2016
@@ -121,6 +121,15 @@
 #undef __cxa_vec_delete3
 #undef __cxa_pure_virtual
 
+// math_functions.hpp expects this host function be defined on MacOS, but it
+// ends up not being there because of the games we play here.  Just define it
+// ourselves; it's simple enough.
+#ifdef __APPLE__
+inline __host__ double __signbitd(double x) {
+  return std::signbit(x);
+}
+#endif
+
 // We need decls for functions in CUDA's libdevice with __device__
 // attribute only. Alas they come either as __host__ __device__ or
 // with no attributes at all. To work around that, define __CUDA_RTC__


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


r287285 - [CUDA] Driver changes to support CUDA compilation on MacOS.

2016-11-17 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Thu Nov 17 18:41:22 2016
New Revision: 287285

URL: http://llvm.org/viewvc/llvm-project?rev=287285&view=rev
Log:
[CUDA] Driver changes to support CUDA compilation on MacOS.

Summary:
Compiling CUDA device code requires us to know the host toolchain,
because CUDA device-side compiles pull in e.g. host headers.

When we only supported Linux compilation, this worked because
CudaToolChain, which is responsible for device-side CUDA compilation,
inherited from the Linux toolchain.  But in order to support MacOS,
CudaToolChain needs to take a HostToolChain pointer.

Because a CUDA toolchain now requires a host TC, we no longer will
create a CUDA toolchain from Driver::getToolChain -- you have to go
through CreateOffloadingDeviceToolChains.  I am *pretty* sure this is
correct, and that previously any attempt to create a CUDA toolchain
through getToolChain() would eventually have resulted in us throwing
"error: unsupported use of NVPTX for host compilation".

In any case hacking getToolChain to create a CUDA+host toolchain would
be wrong, because a Driver can be reused for multiple compilations,
potentially with different host TCs, and getToolChain will cache the
result, causing us to potentially use a stale host TC.

So that's the main change in this patch.

In addition, we have to pull CudaInstallationDetector out of Generic_GCC
and into a top-level class.  It's now used by the Generic_GCC and MachO
toolchains.

Reviewers: tra

Subscribers: rryan, hfinkel, sfantao

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

Added:
cfe/trunk/test/Driver/Inputs/CUDA-macosx/
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/bin/
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/bin/.keep
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/include/
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/include/.keep
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/lib/
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/lib/.keep
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/nvvm/
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/nvvm/libdevice/

cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/nvvm/libdevice/libdevice.compute_30.10.bc

cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/nvvm/libdevice/libdevice.compute_35.10.bc
cfe/trunk/test/Driver/cuda-macosx.cu
Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/cuda-detect.cu
cfe/trunk/test/Driver/cuda-external-tools.cu

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=287285&r1=287284&r2=287285&view=diff
==
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Thu Nov 17 18:41:22 2016
@@ -38,6 +38,7 @@ class FileSystem;
 
 namespace driver {
   class Compilation;
+  class CudaInstallationDetector;
   class Driver;
   class JobAction;
   class RegisterEffectiveTriple;

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=287285&r1=287284&r2=287285&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu Nov 17 18:41:22 2016
@@ -473,14 +473,18 @@ void Driver::CreateOffloadingDeviceToolC
   if (llvm::any_of(Inputs, [](std::pair &I) 
{
 return types::isCuda(I.first);
   })) {
-const ToolChain &TC = getToolChain(
-C.getInputArgs(),
-llvm::Triple(C.getSingleOffloadToolChain()
- ->getTriple()
- .isArch64Bit()
- ? "nvptx64-nvidia-cuda"
- : "nvptx-nvidia-cuda"));
-C.addOffloadDeviceToolChain(&TC, Action::OFK_Cuda);
+const ToolChain *HostTC = C.getSingleOffloadToolChain();
+const llvm::Triple &HostTriple = HostTC->getTriple();
+llvm::Triple CudaTriple(HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda"
+ : "nvptx-nvidia-cuda");
+// Use the CUDA and host triples as the key into the ToolChains map, 
because
+// the device toolchain we create depends on both.
+ToolChain *&CudaTC = ToolChains[CudaTriple.str() + "/" + HostTriple.str()];
+if (!CudaTC) {
+  CudaTC = new toolchains::CudaToolChain(*this, CudaTriple, *HostTC,
+ C.getInputArgs());
+}
+C.

r287287 - [CUDA] Use the right section and constant names for fatbins when compiling for macos.

2016-11-17 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Thu Nov 17 18:41:31 2016
New Revision: 287287

URL: http://llvm.org/viewvc/llvm-project?rev=287287&view=rev
Log:
[CUDA] Use the right section and constant names for fatbins when compiling for 
macos.

Reviewers: tra

Subscribers: cfe-commits

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

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

Modified: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCUDANV.cpp?rev=287287&r1=287286&r2=287287&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp Thu Nov 17 18:41:31 2016
@@ -289,19 +289,24 @@ llvm::Function *CGNVCUDARuntime::makeMod
   continue;
 }
 
+const char *FatbinConstantName =
+CGM.getTriple().isMacOSX() ? "__NV_CUDA,__nv_fatbin" : ".nv_fatbin";
+// NVIDIA's cuobjdump looks for fatbins in this section.
+const char *FatbinSectionName =
+CGM.getTriple().isMacOSX() ? "__NV_CUDA,__fatbin" : ".nvFatBinSegment";
+
 // Create initialized wrapper structure that points to the loaded GPU 
binary
 llvm::Constant *Values[] = {
 llvm::ConstantInt::get(IntTy, 0x466243b1), // Fatbin wrapper magic.
 llvm::ConstantInt::get(IntTy, 1),  // Fatbin version.
 makeConstantString(GpuBinaryOrErr.get()->getBuffer(), // Data.
-   "", ".nv_fatbin", 8),  //
+   "", FatbinConstantName, 8),
 llvm::ConstantPointerNull::get(VoidPtrTy)}; // Unused in fatbin v1.
 llvm::GlobalVariable *FatbinWrapper = new llvm::GlobalVariable(
 TheModule, FatbinWrapperTy, true, llvm::GlobalValue::InternalLinkage,
 llvm::ConstantStruct::get(FatbinWrapperTy, Values),
 "__cuda_fatbin_wrapper");
-// NVIDIA's cuobjdump looks for fatbins in this section.
-FatbinWrapper->setSection(".nvFatBinSegment");
+FatbinWrapper->setSection(FatbinSectionName);
 
 // GpuBinaryHandle = __cudaRegisterFatBinary(&FatbinWrapper);
 llvm::CallInst *RegisterFatbinCall = CtorBuilder.CreateCall(


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


[PATCH] D26774: [CUDA] Driver changes to support CUDA compilation on MacOS.

2016-11-17 Thread Justin Lebar via cfe-commits
This revision was automatically updated to reflect the committed changes.
jlebar marked 2 inline comments as done.
Closed by commit rL287285: [CUDA] Driver changes to support CUDA compilation on 
MacOS. (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D26774?vs=78286&id=78435#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26774

Files:
  cfe/trunk/include/clang/Driver/ToolChain.h
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/Driver/ToolChains.cpp
  cfe/trunk/lib/Driver/ToolChains.h
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/bin/.keep
  cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/include/.keep
  cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/lib/.keep
  
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/nvvm/libdevice/libdevice.compute_30.10.bc
  
cfe/trunk/test/Driver/Inputs/CUDA-macosx/usr/local/cuda/nvvm/libdevice/libdevice.compute_35.10.bc
  cfe/trunk/test/Driver/cuda-detect.cu
  cfe/trunk/test/Driver/cuda-external-tools.cu
  cfe/trunk/test/Driver/cuda-macosx.cu

Index: cfe/trunk/include/clang/Driver/ToolChain.h
===
--- cfe/trunk/include/clang/Driver/ToolChain.h
+++ cfe/trunk/include/clang/Driver/ToolChain.h
@@ -38,6 +38,7 @@
 
 namespace driver {
   class Compilation;
+  class CudaInstallationDetector;
   class Driver;
   class JobAction;
   class RegisterEffectiveTriple;
Index: cfe/trunk/test/Driver/cuda-external-tools.cu
===
--- cfe/trunk/test/Driver/cuda-external-tools.cu
+++ cfe/trunk/test/Driver/cuda-external-tools.cu
@@ -1,4 +1,5 @@
-// Tests that ptxas and fatbinary are correctly during CUDA compilation.
+// Tests that ptxas and fatbinary are invoked correctly during CUDA
+// compilation.
 //
 // REQUIRES: clang-driver
 // REQUIRES: x86-registered-target
@@ -56,6 +57,14 @@
 // RUN: | FileCheck -check-prefix SM20 -check-prefix PTXAS-EXTRA \
 // RUN:   -check-prefix FATBINARY-EXTRA %s
 
+// MacOS spot-checks
+// RUN: %clang -### -target x86_64-apple-macosx -O0 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM20 -check-prefix OPT0 %s
+// RUN: %clang -### -target x86_64-apple-macosx --cuda-gpu-arch=sm_35 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM35 %s
+// RUN: %clang -### -target x86_32-apple-macosx -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix ARCH32 -check-prefix SM20 %s
+
 // Match clang job that produces PTX assembly.
 // CHECK: "-cc1" "-triple" "nvptx64-nvidia-cuda"
 // SM20: "-target-cpu" "sm_20"
Index: cfe/trunk/test/Driver/cuda-macosx.cu
===
--- cfe/trunk/test/Driver/cuda-macosx.cu
+++ cfe/trunk/test/Driver/cuda-macosx.cu
@@ -0,0 +1,8 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+//
+// RUN: %clang -v --target=i386-apple-macosx \
+// RUN:   --sysroot=%S/Inputs/CUDA-macosx 2>&1 | FileCheck %s
+
+// CHECK: Found CUDA installation: {{.*}}/Inputs/CUDA-macosx/usr/local/cuda
Index: cfe/trunk/test/Driver/cuda-detect.cu
===
--- cfe/trunk/test/Driver/cuda-detect.cu
+++ cfe/trunk/test/Driver/cuda-detect.cu
@@ -5,10 +5,18 @@
 // # Check that we properly detect CUDA installation.
 // RUN: %clang -v --target=i386-unknown-linux \
 // RUN:   --sysroot=%S/no-cuda-there 2>&1 | FileCheck %s -check-prefix NOCUDA
+// RUN: %clang -v --target=i386-apple-macosx \
+// RUN:   --sysroot=%S/no-cuda-there 2>&1 | FileCheck %s -check-prefix NOCUDA
+
 // RUN: %clang -v --target=i386-unknown-linux \
 // RUN:   --sysroot=%S/Inputs/CUDA 2>&1 | FileCheck %s
+// RUN: %clang -v --target=i386-apple-macosx \
+// RUN:   --sysroot=%S/Inputs/CUDA 2>&1 | FileCheck %s
+
 // RUN: %clang -v --target=i386-unknown-linux \
 // RUN:   --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 | FileCheck %s
+// RUN: %clang -v --target=i386-apple-macosx \
+// RUN:   --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 | FileCheck %s
 
 // Make sure we map libdevice bitcode files to proper GPUs. These
 // tests use Inputs/CUDA_80 which has full set of libdevice files.
@@ -51,33 +59,51 @@
 // RUN:   | FileCheck %s -check-prefix COMMON \
 // RUN: -check-prefix LIBDEVICE -check-prefix LIBDEVICE50
 
-
 // Verify that -nocudainc prevents adding include path to CUDA headers.
 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
 // RUN:   -nocudainc --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix COMMON -check-prefix NOCUDAINC \
 // RUN: -check-prefix LIBDEVICE -check-prefix LIBDEVICE35
+// RUN: %clang -### -v --target=i386-apple-macosx --cuda-gpu-arch=sm_35 \
+// RUN:   -nocudainc --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
+// RUN:   | FileCheck %s -check-prefix COMMON -check-prefix NOCUDAINC \
+// RUN: -chec

r287286 - [CUDA] Initialize our header search using the host triple.

2016-11-17 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Thu Nov 17 18:41:27 2016
New Revision: 287286

URL: http://llvm.org/viewvc/llvm-project?rev=287286&view=rev
Log:
[CUDA] Initialize our header search using the host triple.

Summary:
This used to work because system headers are found in a (somewhat)
predictable set of locations on Linux.  But this is not the case on
MacOS; without this change, we don't look in the right places for our
headers when doing device-side compilation on Mac.

Reviewers: tra

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/Preprocessor/cuda-macos-includes.cu
Modified:
cfe/trunk/lib/Frontend/CompilerInstance.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=287286&r1=287285&r2=287286&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Nov 17 18:41:27 2016
@@ -334,9 +334,16 @@ void CompilerInstance::createPreprocesso
   InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
  getFrontendOpts());
 
-  // Initialize the header search object.
+  // Initialize the header search object.  In CUDA compilations, we use the aux
+  // triple (the host triple) to initialize our header search, since we need to
+  // find the host headers in order to compile the CUDA code.
+  const llvm::Triple *HeaderSearchTriple = &PP->getTargetInfo().getTriple();
+  if (PP->getTargetInfo().getTriple().getOS() == llvm::Triple::CUDA &&
+  PP->getAuxTargetInfo())
+HeaderSearchTriple = &PP->getAuxTargetInfo()->getTriple();
+
   ApplyHeaderSearchOptions(PP->getHeaderSearchInfo(), getHeaderSearchOpts(),
-   PP->getLangOpts(), PP->getTargetInfo().getTriple());
+   PP->getLangOpts(), *HeaderSearchTriple);
 
   PP->setPreprocessedOutput(getPreprocessorOutputOpts().ShowCPP);
 

Added: cfe/trunk/test/Preprocessor/cuda-macos-includes.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/cuda-macos-includes.cu?rev=287286&view=auto
==
--- cfe/trunk/test/Preprocessor/cuda-macos-includes.cu (added)
+++ cfe/trunk/test/Preprocessor/cuda-macos-includes.cu Thu Nov 17 18:41:27 2016
@@ -0,0 +1,13 @@
+// RUN: %clang -cc1 -fcuda-is-device -isysroot /var/empty \
+// RUN:   -triple nvptx-nvidia-cuda -aux-triple i386-apple-macosx \
+// RUN:   -S -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
+
+// RUN: %clang -cc1 -isysroot /var/empty \
+// RUN:   -triple i386-apple-macosx -aux-triple nvptx-nvidia-cuda \
+// RUN:   -S -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
+
+// Check that when we do CUDA host and device compiles on MacOS, we check for
+// includes in /System/Library/Frameworks and /Library/Frameworks.
+
+// CHECK-DAG: ignoring nonexistent directory 
"/var/empty/System/Library/Frameworks"
+// CHECK-DAG: ignoring nonexistent directory "/var/empty/Library/Frameworks"


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


[PATCH] D26774: [CUDA] Driver changes to support CUDA compilation on MacOS.

2016-11-17 Thread Justin Lebar via cfe-commits
jlebar marked 2 inline comments as done.
jlebar added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:3650-3654
+
+  // Intentionally omitted from the switch above: llvm::Triple::CUDA.  CUDA
+  // compiles always need two toolchains, the CUDA toolchain and the host
+  // toolchain.  So the only valid way to create a CUDA toolchain is via
+  // CreateOffloadingDeviceToolChains.

tra wrote:
> should there be an assert() or llvm_unreachable() to ensure that? Right now 
> we'll happily return default toolchain.
Unfortunately no -- the way the code is structured now, we get the toolchain 
before we have a chance to raise an error.

I agree that's pretty broken...



Comment at: clang/test/Driver/cuda-detect.cu:67
 // RUN: -check-prefix LIBDEVICE -check-prefix LIBDEVICE35
+// RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
+// RUN:   -nocudainc --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \

tra wrote:
> Should that be --target=i386-apple-macosx ?
Wow, good eye.


https://reviews.llvm.org/D26774



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


Buildbot numbers for the week of 11/06/2016 - 11/12/2016

2016-11-17 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the last week of 11/06/2016 -
11/12/2016.

Please see the same data in attached csv files:

The longest time each builder was red during the last week;
"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green);
Count of commits by project;
Number of completed builds, failed builds and average build time for
successful builds per active builder;
Average waiting time for a revision to get build result per active builder
(response time).

Thanks

Galina


The longest time each builder was red during the last week:

buildername |  was_red
+--
 lldb-x86-windows-msvc2015  | 108:30:55
 lldb-x86_64-ubuntu-14.04-android   | 85:59:56
 sanitizer-x86_64-linux-bootstrap   | 43:55:59
 sanitizer-x86_64-linux-fast| 42:16:35
 libcxx-libcxxabi-libunwind-x86_64-linux-debian | 25:45:26
 libcxx-libcxxabi-x86_64-linux-debian-noexceptions  | 25:44:55
 clang-ppc64be-linux-multistage | 23:30:33
 clang-ppc64be-linux-lnt| 23:20:10
 clang-ppc64be-linux| 22:47:14
 clang-cmake-mipsel | 21:28:18
 lldb-windows7-android  | 18:34:37
 lldb-x86_64-ubuntu-14.04-cmake | 18:17:33
 sanitizer-ppc64le-linux| 16:32:23
 sanitizer-ppc64be-linux| 15:04:16
 clang-s390x-linux  | 12:08:15
 clang-bpf-build| 12:06:25
 clang-cmake-mips   | 12:05:12
 clang-cmake-aarch64-42vma  | 11:51:35
 clang-ppc64le-linux-multistage | 11:50:41
 clang-cmake-aarch64-39vma  | 11:48:43
 clang-ppc64le-linux-lnt| 11:43:54
 clang-ppc64le-linux| 11:38:49
 clang-cmake-armv7-a15-full | 11:22:50
 clang-3stage-ubuntu| 11:18:37
 sanitizer-x86_64-linux-autoconf| 11:18:36
 clang-cmake-aarch64-full   | 11:10:22
 clang-cmake-thumbv7-a15-full-sh| 10:58:01
 llvm-mips-linux| 10:38:01
 sanitizer-x86_64-linux | 10:20:27
 clang-with-lto-ubuntu  | 07:00:00
 lld-x86_64-darwin13| 06:46:01
 libcxx-libcxxabi-libunwind-arm-linux-noexceptions  | 06:44:50
 perf-x86_64-penryn-O3-polly-fast   | 06:39:56
 lld-x86_64-freebsd | 06:39:21
 clang-with-thin-lto-ubuntu | 06:10:54
 clang-x86_64-linux-selfhost-modules| 05:54:48
 clang-native-arm-lnt   | 05:06:35
 sanitizer-x86_64-linux-fuzzer  | 04:06:08
 libcxx-libcxxabi-libunwind-arm-linux   | 02:55:40
 clang-x64-ninja-win7   | 02:36:05
 polly-amd64-linux  | 02:34:16
 clang-hexagon-elf  | 02:11:00
 clang-cmake-aarch64-quick  | 02:10:56
 clang-x86-windows-msvc2015 | 02:10:44
 perf-x86_64-penryn-O3-polly-unprofitable   | 02:02:50
 libcxx-libcxxabi-libunwind-x86_64-linux-ubuntu | 01:53:59
 clang-cmake-armv7-a15  | 01:52:56
 clang-cmake-thumbv7-a15| 01:52:54
 libcxx-libcxxabi-x86_64-linux-ubuntu-ubsan | 01:51:30
 libcxx-libcxxabi-x86_64-linux-ubuntu-asan  | 01:46:08
 lldb-amd64-ninja-netbsd7   | 01:41:54
 clang-x86_64-linux-abi-test| 01:40:39
 lldb-x86_64-ubuntu-14.04-buildserver   | 01:35:27
 libcxx-libcxxabi-x86_64-linux-ubuntu-msan  | 01:34:56
 libcxx-libcxxabi-x86_64-linux-ubuntu-tsan  | 01:31:22
 perf-x86_64-penryn-O3-polly-parallel-fast  | 01:30:39
 perf-x86_64-penryn-O3-polly-before-vectorizer-unprofitable | 01:26:30
 llvm-sphinx-docs   | 01:19:51
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast   | 01:12:31
 libcxx-libcxxabi-x86_

Buildbot numbers for the week of 10/30/2016 - 11/05/2016

2016-11-17 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the week of 10/30/2016 - 11/05/2016.

Please see the same data in attached csv files:

The longest time each builder was red during the last week;
"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green);
Count of commits by project;
Number of completed builds, failed builds and average build time for
successful builds per active builder;
Average waiting time for a revision to get build result per active builder
(response time).

Thanks

Galina


The longest time each builder was red during the last week:

buildername |  was_red
+--
 clang-3stage-ubuntu| 102:45:51
 lld-x86_64-win7| 62:36:35
 clang-with-thin-lto-ubuntu | 50:21:30
 clang-with-lto-ubuntu  | 49:57:01
 llvm-sphinx-docs   | 46:47:20
 clang-cmake-mipsel | 31:07:29
 lldb-windows7-android  | 29:38:35
 lldb-x86_64-ubuntu-14.04-android   | 29:21:52
 lldb-x86_64-ubuntu-14.04-cmake | 28:53:25
 clang-native-aarch64-full  | 25:33:26
 clang-s390x-linux  | 19:33:55
 llvm-mips-linux| 19:18:24
 libcxx-libcxxabi-singlethreaded-x86_64-linux-debian| 18:33:38
 clang-cmake-mips   | 18:24:40
 clang-cmake-armv7-a15-selfhost-neon| 17:07:34
 clang-cmake-thumbv7-a15-full-sh| 12:32:39
 clang-cmake-armv7-a15-selfhost | 07:26:03
 clang-cmake-armv7-a15-full | 05:29:28
 clang-ppc64le-linux-multistage | 05:08:18
 clang-cmake-thumbv7-a15| 04:47:22
 clang-cmake-armv7-a15  | 04:47:11
 libcxx-libcxxabi-libunwind-arm-linux   | 04:02:26
 clang-ppc64be-linux| 03:34:45
 libcxx-libcxxabi-x86_64-linux-ubuntu-gcc49-cxx11   | 03:16:17
 libcxx-libcxxabi-libunwind-x86_64-linux-ubuntu | 03:15:46
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx11 | 03:14:43
 clang-ppc64be-linux-multistage | 03:14:23
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx14 | 03:13:21
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx1z | 03:05:44
 sanitizer-ppc64be-linux| 03:04:20
 sanitizer-x86_64-linux | 03:02:22
 clang-x86-windows-msvc2015 | 02:58:25
 libcxx-libcxxabi-x86_64-linux-debian   | 02:50:43
 libcxx-libcxxabi-x86_64-linux-debian-noexceptions  | 02:50:43
 libcxx-libcxxabi-libunwind-x86_64-linux-debian | 02:50:37
 clang-bpf-build| 02:48:34
 clang-x86_64-linux-selfhost-modules| 02:45:20
 clang-cmake-aarch64-full   | 02:44:48
 sanitizer-x86_64-linux-fuzzer  | 02:37:33
 clang-ppc64be-linux-lnt| 02:16:04
 perf-x86_64-penryn-O3-polly-unprofitable   | 02:15:46
 clang-cmake-aarch64-39vma  | 02:12:58
 clang-native-arm-lnt   | 02:09:46
 perf-x86_64-penryn-O3-polly-before-vectorizer-unprofitable | 02:09:16
 clang-x64-ninja-win7   | 02:08:28
 clang-cmake-aarch64-quick  | 02:00:09
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast   | 01:49:37
 libcxx-libcxxabi-x86_64-linux-ubuntu-ubsan | 01:39:03
 perf-x86_64-penryn-O3  | 01:31:03
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast | 01:21:23
 libcxx-libcxxabi-libunwind-arm-linux-noexceptions  | 01:18:46
 lld-x86_64-darwin13| 01:17:16
 clang-cmake-aarch64-42vma  | 01:14:37
 clang-hexagon-elf  | 01:09:16
 lld-x86_64-freebsd | 01:07:29
 clang-ppc64le-linux-lnt| 01:06:36
 perf-x86_64-penryn-O3-polly-parallel-fast  | 01:01:25
 lldb-x86_64-ubuntu-14.04-buildserver   | 01:00:38
 clang-ppc64le-linux| 00:54:41
 clang-cuda-build  

[libunwind] r287283 - EHABI: mark some functions as exported

2016-11-17 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Thu Nov 17 17:53:35 2016
New Revision: 287283

URL: http://llvm.org/viewvc/llvm-project?rev=287283&view=rev
Log:
EHABI: mark some functions as exported

These are part of the EHABI specification and are exported to be available to
users.  Mark them as `_LIBUNWIND_EXPORT` like the rest of the unwind interfaces.

Modified:
libunwind/trunk/src/Unwind-EHABI.cpp

Modified: libunwind/trunk/src/Unwind-EHABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/Unwind-EHABI.cpp?rev=287283&r1=287282&r2=287283&view=diff
==
--- libunwind/trunk/src/Unwind-EHABI.cpp (original)
+++ libunwind/trunk/src/Unwind-EHABI.cpp Thu Nov 17 17:53:35 2016
@@ -245,11 +245,9 @@ decode_eht_entry(const uint32_t* data, s
   return data;
 }
 
-_Unwind_Reason_Code _Unwind_VRS_Interpret(
-_Unwind_Context* context,
-const uint32_t* data,
-size_t offset,
-size_t len) {
+_LIBUNWIND_EXPORT _Unwind_Reason_Code
+_Unwind_VRS_Interpret(_Unwind_Context *context, const uint32_t *data,
+  size_t offset, size_t len) {
   bool wrotePC = false;
   bool finish = false;
   while (offset < len && !finish) {
@@ -418,24 +416,21 @@ _Unwind_Reason_Code _Unwind_VRS_Interpre
   return _URC_CONTINUE_UNWIND;
 }
 
-extern "C" _Unwind_Reason_Code __aeabi_unwind_cpp_pr0(
-_Unwind_State state,
-_Unwind_Control_Block *ucbp,
-_Unwind_Context *context) {
+extern "C" _LIBUNWIND_EXPORT _Unwind_Reason_Code
+__aeabi_unwind_cpp_pr0(_Unwind_State state, _Unwind_Control_Block *ucbp,
+   _Unwind_Context *context) {
   return unwindOneFrame(state, ucbp, context);
 }
 
-extern "C" _Unwind_Reason_Code __aeabi_unwind_cpp_pr1(
-_Unwind_State state,
-_Unwind_Control_Block *ucbp,
-_Unwind_Context *context) {
+extern "C" _LIBUNWIND_EXPORT _Unwind_Reason_Code
+__aeabi_unwind_cpp_pr1(_Unwind_State state, _Unwind_Control_Block *ucbp,
+   _Unwind_Context *context) {
   return unwindOneFrame(state, ucbp, context);
 }
 
-extern "C" _Unwind_Reason_Code __aeabi_unwind_cpp_pr2(
-_Unwind_State state,
-_Unwind_Control_Block *ucbp,
-_Unwind_Context *context) {
+extern "C" _LIBUNWIND_EXPORT _Unwind_Reason_Code
+__aeabi_unwind_cpp_pr2(_Unwind_State state, _Unwind_Control_Block *ucbp,
+   _Unwind_Context *context) {
   return unwindOneFrame(state, ucbp, context);
 }
 
@@ -755,7 +750,7 @@ static uint64_t ValueAsBitPattern(_Unwin
   return value;
 }
 
-_Unwind_VRS_Result
+_LIBUNWIND_EXPORT _Unwind_VRS_Result
 _Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
 uint32_t regno, _Unwind_VRS_DataRepresentation representation,
 void *valuep) {
@@ -867,12 +862,10 @@ _Unwind_VRS_Get_Internal(_Unwind_Context
   _LIBUNWIND_ABORT("unsupported register class");
 }
 
-_Unwind_VRS_Result _Unwind_VRS_Get(
-_Unwind_Context *context,
-_Unwind_VRS_RegClass regclass,
-uint32_t regno,
-_Unwind_VRS_DataRepresentation representation,
-void *valuep) {
+_LIBUNWIND_EXPORT _Unwind_VRS_Result
+_Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
+uint32_t regno, _Unwind_VRS_DataRepresentation representation,
+void *valuep) {
   _Unwind_VRS_Result result =
   _Unwind_VRS_Get_Internal(context, regclass, regno, representation,
valuep);


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


[PATCH] D21298: [Clang-tidy] delete null check

2016-11-17 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.



Comment at: test/clang-tidy/readability-delete-null-pointer.cpp:7
+  int *p = 0;
+  if (p) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'if' statement is unnecessary; 
deleting null pointer has no effect [readability-delete-null-pointer]

SilverGeri wrote:
> aaron.ballman wrote:
> > hokein wrote:
> > > Does it work the case like:
> > > 
> > > ```
> > > int *p = nullptr;
> > > if (p == nullptr) {
> > >p = new int[3];
> > >delete[] p;
> > > }
> > > ```
> > > 
> > > ?
> > Similarly, it should not mishandle a case like:
> > 
> > void f(int *p) {
> >   if (p) {
> > delete p;
> >   } else {
> > // Do something else
> >   }
> > }
> it warns only if the compund statement contains only one statement (which is 
> the delete). We want to warn because it is unnecessary to check the pointer 
> validity if you want to just call `delete`. In other cases, we can't be sure 
> about the actual behaviour.
In my example, the compound statement does contain only one statement, the 
delete, but diagnosing is likely a false positive due to the else clause. In 
that case, the pointer validity controls more than just the delete because it 
also controls whether to execute the else clause. Removing the if clause 
shouldn't be a mechanical change in the presence of an else clause, so the 
fixit is definitely inappropriate. I think that diagnosing is still pretty 
reasonable, however.

Another test case, which I think may already be handled appropriately but 
should still be explicitly tested:
```
if (p) {
  // This comment should not disable the check or the fixit.
  // Nor should this comment.
  delete p;
}
```
I think this check should still be able to remove the if clause, but we should 
make sure that the comments don't disable the check, and that the fixit doesn't 
destroy the comments.


https://reviews.llvm.org/D21298



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


r287278 - Minor changes in x86 intrinsics headers; NFC

2016-11-17 Thread Ekaterina Romanova via cfe-commits
Author: kromanova
Date: Thu Nov 17 17:02:00 2016
New Revision: 287278

URL: http://llvm.org/viewvc/llvm-project?rev=287278&view=rev
Log:
Minor changes in x86 intrinsics headers; NFC

I made several changes for consistency with the rest of x86 instrinsics header 
files. Some of these changes help to render doxygen comments better.

1. avxintrin.h –  Moved the opening bracket on a separate line for several 
  intrinsics (for consistency with the rest of the intrinsics).

2. emmintrin.h -  Moved the doxygen comment next to the body of the function;
   -  Added braces after extern "C"  even though there is only 
  one declaration each time

3. xmmintrin.h -  Moved the doxygen comment next to the body of the function;
   -  Added intrinsic prototypes for a couple of macro definitions
  into the doxygen comment;
   -  Added braces after extern "C"  even though there is only one
  declaration each time

4. ammintrin.h –  Removed extra line between the doxygen comment and the body
  of the functions (for consistency with the rest of the files).

Desk reviewed by Paul Robinson.


Modified:
cfe/trunk/lib/Headers/ammintrin.h
cfe/trunk/lib/Headers/avxintrin.h
cfe/trunk/lib/Headers/emmintrin.h
cfe/trunk/lib/Headers/xmmintrin.h

Modified: cfe/trunk/lib/Headers/ammintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/ammintrin.h?rev=287278&r1=287277&r2=287278&view=diff
==
--- cfe/trunk/lib/Headers/ammintrin.h (original)
+++ cfe/trunk/lib/Headers/ammintrin.h Thu Nov 17 17:02:00 2016
@@ -114,7 +114,6 @@ _mm_extract_si64(__m128i __x, __m128i __
 ///destination operand x with the specified bitfields replaced by the lower
 ///bits of source operand y. The upper 64 bits of the return value are
 ///undefined.
-
 #define _mm_inserti_si64(x, y, len, idx) \
   ((__m128i)__builtin_ia32_insertqi((__v2di)(__m128i)(x), \
 (__v2di)(__m128i)(y), \
@@ -146,7 +145,6 @@ _mm_extract_si64(__m128i __x, __m128i __
 ///destination operand __x with the specified bitfields replaced by the
 ///lower bits of source operand __y. The upper 64 bits of the return value
 ///are undefined.
-
 static __inline__ __m128i __DEFAULT_FN_ATTRS
 _mm_insert_si64(__m128i __x, __m128i __y)
 {

Modified: cfe/trunk/lib/Headers/avxintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avxintrin.h?rev=287278&r1=287277&r2=287278&view=diff
==
--- cfe/trunk/lib/Headers/avxintrin.h (original)
+++ cfe/trunk/lib/Headers/avxintrin.h Thu Nov 17 17:02:00 2016
@@ -3823,7 +3823,8 @@ _mm256_storeu2_m128i(__m128i *__addr_hi,
 /// \returns A 256-bit floating-point vector of [8 x float] containing the
 ///concatenated result.
 static __inline __m256 __DEFAULT_FN_ATTRS
-_mm256_set_m128 (__m128 __hi, __m128 __lo) {
+_mm256_set_m128 (__m128 __hi, __m128 __lo)
+{
   return (__m256) __builtin_shufflevector((__v4sf)__lo, (__v4sf)__hi, 0, 1, 2, 
3, 4, 5, 6, 7);
 }
 
@@ -3843,7 +3844,8 @@ _mm256_set_m128 (__m128 __hi, __m128 __l
 /// \returns A 256-bit floating-point vector of [4 x double] containing the
 ///concatenated result.
 static __inline __m256d __DEFAULT_FN_ATTRS
-_mm256_set_m128d (__m128d __hi, __m128d __lo) {
+_mm256_set_m128d (__m128d __hi, __m128d __lo)
+{
   return (__m256d)_mm256_set_m128((__m128)__hi, (__m128)__lo);
 }
 
@@ -3862,7 +3864,8 @@ _mm256_set_m128d (__m128d __hi, __m128d
 ///result.
 /// \returns A 256-bit integer vector containing the concatenated result.
 static __inline __m256i __DEFAULT_FN_ATTRS
-_mm256_set_m128i (__m128i __hi, __m128i __lo) {
+_mm256_set_m128i (__m128i __hi, __m128i __lo)
+{
   return (__m256i)_mm256_set_m128((__m128)__hi, (__m128)__lo);
 }
 
@@ -3884,7 +3887,8 @@ _mm256_set_m128i (__m128i __hi, __m128i
 /// \returns A 256-bit floating-point vector of [8 x float] containing the
 ///concatenated result.
 static __inline __m256 __DEFAULT_FN_ATTRS
-_mm256_setr_m128 (__m128 __lo, __m128 __hi) {
+_mm256_setr_m128 (__m128 __lo, __m128 __hi)
+{
   return _mm256_set_m128(__hi, __lo);
 }
 
@@ -3906,7 +3910,8 @@ _mm256_setr_m128 (__m128 __lo, __m128 __
 /// \returns A 256-bit floating-point vector of [4 x double] containing the
 ///concatenated result.
 static __inline __m256d __DEFAULT_FN_ATTRS
-_mm256_setr_m128d (__m128d __lo, __m128d __hi) {
+_mm256_setr_m128d (__m128d __lo, __m128d __hi)
+{
   return (__m256d)_mm256_set_m128((__m128)__hi, (__m128)__lo);
 }
 
@@ -3926,7 +3931,8 @@ _mm256_setr_m128d (__m128d __lo, __m128d
 ///result.
 /// \returns A 256-bit integer vector containing the concatenated result.
 static __inline __m256i __DEFAULT_FN_ATTRS
-_mm256_setr_m128i (__m128i __lo, __m128i __hi) {
+_mm256_setr_m128i (__m128i __lo, __m128i __hi)
+{
   r

Re: [PATCH] D24289: Add warning when assigning enums to bitfields without an explicit unsigned underlying type

2016-11-17 Thread Sasha Bermeister via cfe-commits
Although I agree with your philosophical discussion and suggestions, the
reality is that MSVC's behavior is not a bug and compilers are free to
interpret enum bitfields with no explicit underlying type in any way they
want (see spec reference in GCC bug link), with a signed interpretation
being a valid one. I'd say it's undefined behavior in C/C++ to store an
enum in a bitfield without specifying an underlying type, since the
compiler is free to interpret this bitfield in any way it wants -- in
general, if you haven't specified an underlying type you should probably be
warned when trying to store it in a bitfield because the compiler may not
do what you expect.

With that said, I'm happy to put this warning behind a flag, or remove it
altogether from Clang. This is an important feature for Blink and whether
or not it lands, we will be using it for compiling our own code. I
submitted the patch upstream to Clang since I thought all developers should
be aware of this undefined behavior. However, if you feel that developers
who write code that uses enum bitfields should be free to write
non-MSVC-compatible code, then there's no need for this to be in the main
Clang release.

Sasha

On Fri, Nov 18, 2016 at 7:48 AM, Arthur O'Dwyer 
wrote:

> On Thu, Nov 17, 2016 at 9:52 AM, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> > On 17 Nov 2016 8:56 am, "Reid Kleckner"  wrote:
> >> In https://reviews.llvm.org/D24289#598169, @rsmith wrote:
> >>> This is causing warnings to fire for headers shared between C and C++,
> >>> where the "give the enum an unsigned underlying type" advice doesn't
> work,
> >>> and where the code in question will never be built for the MS ABI. It
> seems
> >>> really hard to justify this being on by default.
> >>>
> >>> I'm going to turn it off by default for now, but we should probably
> >>> consider turning it back on by default when targeting the MS ABI (as a
> "your
> >>> code is wrong" warning rather than a "your code is not portable"
> warning).
> [...]
> >>> Yeah, suggesting adding an underlying type to the enum to solve this
> >>> problem seems like a bad idea, since that fundamentally changes the
> nature
> >>> of the enum -- typically allowing it to store a lot more values, and
> making
> >>> putting it in a bitfield a bad idea.
> >
> >> Any time you use a bitfield it stores fewer values than the original
> integer
> >> type. I don't see how enums are special here. [...]
> >
> > The range of representable values for a bitfield with no fixed underlying
> > type is actually smaller than that of its underlying type. See
> > http://eel.is/c++draft/dcl.enum#8
> >
> > So a bitfield of width equal to the number of bits needed to store any
> > enumerator does not have fewer values than the original type.
>
> My understanding (from osmosis and practice more than from reading the
> standard) is that programmers are more likely to specify an "unnaturally
> narrow" underlying type (e.g. "int8_t") than to specify an "unnaturally
> wide" underlying type (e.g. "int32_t". When I specify an underlying type,
> I'm saying "The compiler is going to do the wrong thing with this type's
> *storage* by default"; I'm not saying anything about the type's *value
> range*.
> The same goes for bit-fields: I specify a number of bits after the colon
> because the compiler would otherwise do the wrong thing with *storage*,
> not because I'm trying to change the semantics of the *values* involved.
>
>
> >> Do you have any better suggestions for people that want this code to do
> the
> >> right thing when built with MSVC?
> >>
> >>   enum E /* : unsigned */ { E0, E1, E2, E3 };
> >>   struct A { E b : 2; };
> >>   int main() {
> >> A a;
> >> a.b = E3;
> >> return a.b; // comes out as -1 without the underlying type
> >>   }
> >>
> >> Widening the bitfield wastes a bit. Making the bitfield a plain integer
> and
> >> cast in and out of the enum type, but that obscures the true type of the
> >> bitfield. So, I still support this suggestion.
>
> The safest fix is to just change ": 2" to ": 3", even though that "wastes
> a bit" (really it wastes 0 bits in most cases and 32 to 64 bits in some
> cases).
>
> If I had my druthers, the compiler would be completely silent unless it
> detected exactly the cases that would result in changes to the semantics of
> enum *values*. That is,
>
> when declaring a bit-field of enum type E with width B bits:
>   if E has an enumerator e whose value requires >B bits:
> warn that e cannot be stored in the bit-field
> if a fixit is really required, suggest increasing the bit-field's
> width
>   if E has an enumerator e whose positive value requires exactly B
> bits, and E's underlying type is signed:
> warn that e cannot be stored in the bit-field when MSVC semantics
> are in use
> in C++, append the note that this happens because E's underlying
> type is signed
> if a fixit is really required, suggest increas

[PATCH] D21298: [Clang-tidy] delete null check

2016-11-17 Thread Gergely Angeli via cfe-commits
SilverGeri added inline comments.



Comment at: test/clang-tidy/readability-delete-null-pointer.cpp:7
+  int *p = 0;
+  if (p) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'if' statement is unnecessary; 
deleting null pointer has no effect [readability-delete-null-pointer]

aaron.ballman wrote:
> hokein wrote:
> > Does it work the case like:
> > 
> > ```
> > int *p = nullptr;
> > if (p == nullptr) {
> >p = new int[3];
> >delete[] p;
> > }
> > ```
> > 
> > ?
> Similarly, it should not mishandle a case like:
> 
> void f(int *p) {
>   if (p) {
> delete p;
>   } else {
> // Do something else
>   }
> }
it warns only if the compund statement contains only one statement (which is 
the delete). We want to warn because it is unnecessary to check the pointer 
validity if you want to just call `delete`. In other cases, we can't be sure 
about the actual behaviour.


https://reviews.llvm.org/D21298



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


r287275 - [Preprocessor] Support for '-dI' flag

2016-11-17 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Thu Nov 17 16:45:31 2016
New Revision: 287275

URL: http://llvm.org/viewvc/llvm-project?rev=287275&view=rev
Log:
[Preprocessor] Support for '-dI' flag

Re-introduce r285411.

Implement the -dI as supported by GCC: Output ‘#include’ directives in addition
to the result of preprocessing.

This change aims to add this option, pass it through to the preprocessor via
the options class, and when inclusions occur we output some information (+ test
cases).

Patch by Steve O'Brien!

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

Added:
cfe/trunk/test/Preprocessor/dump_import.h
cfe/trunk/test/Preprocessor/dump_import.m
cfe/trunk/test/Preprocessor/dump_include.c
cfe/trunk/test/Preprocessor/dump_include.h
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=287275&r1=287274&r2=287275&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Nov 17 16:45:31 2016
@@ -429,6 +429,8 @@ def fno_cuda_approx_transcendentals : Fl
 def dA : Flag<["-"], "dA">, Group;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode in addition to normal output">;
+def dI : Flag<["-"], "dI">, Group, Flags<[CC1Option]>,
+  HelpText<"Print include directives in -E mode in addition to normal output">;
 def dM : Flag<["-"], "dM">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode instead of normal output">;
 def dead__strip : Flag<["-"], "dead_strip">;

Modified: cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h?rev=287275&r1=287274&r2=287275&view=diff
==
--- cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h Thu Nov 17 
16:45:31 2016
@@ -22,6 +22,7 @@ public:
   unsigned UseLineDirectives : 1;   ///< Use \#line instead of GCC-style \# N.
   unsigned ShowMacroComments : 1;  ///< Show comments, even in macros.
   unsigned ShowMacros : 1; ///< Print macro definitions.
+  unsigned ShowIncludeDirectives : 1;  ///< Print includes, imports etc. 
within preprocessed output.
   unsigned RewriteIncludes : 1;///< Preprocess include directives only.
 
 public:
@@ -32,6 +33,7 @@ public:
 UseLineDirectives = 0;
 ShowMacroComments = 0;
 ShowMacros = 0;
+ShowIncludeDirectives = 0;
 RewriteIncludes = 0;
   }
 };

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=287275&r1=287274&r2=287275&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Nov 17 16:45:31 2016
@@ -2357,6 +2357,7 @@ static void ParsePreprocessorOutputArgs(
   Opts.ShowLineMarkers = !Args.hasArg(OPT_P);
   Opts.ShowMacroComments = Args.hasArg(OPT_CC);
   Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD);
+  Opts.ShowIncludeDirectives = Args.hasArg(OPT_dI);
   Opts.RewriteIncludes = Args.hasArg(OPT_frewrite_includes);
   Opts.UseLineDirectives = Args.hasArg(OPT_fuse_line_directives);
 }

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=287275&r1=287274&r2=287275&view=diff
==
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Thu Nov 17 16:45:31 2016
@@ -93,13 +93,16 @@ private:
   bool Initialized;
   bool DisableLineMarkers;
   bool DumpDefines;
+  bool DumpIncludeDirectives;
   bool UseLineDirectives;
   bool IsFirstFileEntered;
 public:
   PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, bool lineMarkers,
-   bool defines, bool UseLineDirectives)
+   bool defines, bool DumpIncludeDirectives,
+   bool UseLineDirectives)
   : PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os),
 DisableLineMarkers(lineMarkers), DumpDefines(defines),
+DumpIncludeDirectives(DumpIncludeDirectives),
 UseLineDirectives(UseLineDirectives) {
 CurLine = 0;
 CurFilename += "";
@@ -320,10 +323,10 @@ void PrintPPOutputPPCallbacks::I

[PATCH] D25949: [Driver] Refactor distro detection & classification as a separate API

2016-11-17 Thread Bruno Cardoso Lopes via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Very nice! LGTM


https://reviews.llvm.org/D25949



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


r287262 - [CrashReproducer][Darwin] Suggest attaching .crash diagnostic file

2016-11-17 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Thu Nov 17 15:41:22 2016
New Revision: 287262

URL: http://llvm.org/viewvc/llvm-project?rev=287262&view=rev
Log:
[CrashReproducer][Darwin] Suggest attaching .crash diagnostic file

In addition to the preprocessed sources file and reproducer script, also
point to the .crash diagnostic files on Darwin. Example:

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-4.0: note: diagnostic msg: 
/var/folders/bk/1hj20g8j4xvdj5gd25ywhd3mgq/T/RegAllocGreedy-238f28.cpp
clang-4.0: note: diagnostic msg: 
/var/folders/bk/1hj20g8j4xvdj5gd25ywhd3mgq/T/RegAllocGreedy-238f28.cache
clang-4.0: note: diagnostic msg: 
/var/folders/bk/1hj20g8j4xvdj5gd25ywhd3mgq/T/RegAllocGreedy-238f28.sh
clang-4.0: note: diagnostic msg: 
/var/folders/bk/1hj20g8j4xvdj5gd25ywhd3mgq/T/RegAllocGreedy-238f28.crash

When no match is found for the .crash, point the user to a directory
where those can be found. Example:

clang-4.0: note: diagnostic msg: Crash backtrace is located in
clang-4.0: note: diagnostic msg: 
/Users/bruno/Library/Logs/DiagnosticReports/clang-4.0__.crash
clang-4.0: note: diagnostic msg: (choose the .crash file that corresponds to 
your crash)

rdar://problem/27286266

Added:
cfe/trunk/test/Driver/crash-report-crashfile.m
Modified:
cfe/trunk/include/clang/Driver/Driver.h
cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=287262&r1=287261&r2=287262&view=diff
==
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Thu Nov 17 15:41:22 2016
@@ -246,6 +246,20 @@ private:
   void generatePrefixedToolNames(StringRef Tool, const ToolChain &TC,
  SmallVectorImpl &Names) const;
 
+  /// \brief Find the appropriate .crash diagonostic file for the child crash
+  /// under this driver and copy it out to a temporary destination with the
+  /// other reproducer related files (.sh, .cache, etc). If not found, suggest 
a
+  /// directory for the user to look at.
+  ///
+  /// \param The file path to copy the .crash to.
+  /// \param The suggested directory for the user to look at in case the search
+  /// or copy fails.
+  ///
+  /// \returns If the .crash is found and successfully copied return true,
+  /// otherwise false and return the suggested directory in \p CrashDiagDir.
+  bool getCrashDiagnosticFile(StringRef ReproCrashFilename,
+  SmallString<128> &CrashDiagDir);
+
 public:
   Driver(StringRef ClangExecutable, StringRef DefaultTargetTriple,
  DiagnosticsEngine &Diags,

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=287262&r1=287261&r2=287262&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu Nov 17 15:41:22 2016
@@ -42,6 +42,9 @@
 #include 
 #include 
 #include 
+#if LLVM_ON_UNIX
+#include  // getpid
+#endif
 
 using namespace clang::driver;
 using namespace clang;
@@ -695,6 +698,95 @@ static void printArgList(raw_ostream &OS
   OS << '\n';
 }
 
+bool Driver::getCrashDiagnosticFile(StringRef ReproCrashFilename,
+SmallString<128> &CrashDiagDir) {
+  using namespace llvm::sys;
+  assert(llvm::Triple(llvm::sys::getProcessTriple()).isOSDarwin() &&
+ "Only knows about .crash files on Darwin");
+
+  // The .crash file can be found on at ~/Library/Logs/DiagnosticReports/
+  // (or /Library/Logs/DiagnosticReports for root) and has the filename pattern
+  // clang-__.crash.
+  path::home_directory(CrashDiagDir);
+  if (CrashDiagDir.startswith("/var/root"))
+CrashDiagDir = "/";
+  path::append(CrashDiagDir, "Library/Logs/DiagnosticReports");
+  int PID =
+#if LLVM_ON_UNIX
+  getpid();
+#else
+  0;
+#endif
+  std::error_code EC;
+  fs::file_status FileStatus;
+  TimePoint<> LastAccessTime;
+  SmallString<128> CrashFilePath;
+  // Lookup the .crash files and get the one generated by a subprocess spawned
+  // by this driver invocation.
+  for (fs::directory_iterator File(CrashDiagDir, EC), FileEnd;
+   File != FileEnd && !EC; File.increment(EC)) {
+StringRef FileName = path::filename(File->path());
+if (!FileName.startswith(Name))
+  continue;
+if (fs::status(File->path(), FileStatus))
+  continue;
+llvm::ErrorOr> CrashFile =
+llvm::MemoryBuffer::getFile(File->path());
+if (!CrashFile)
+  continue;
+// The first line should start with "Process:", otherwise this isn't a real
+// .crash file.
+StringRef Data = CrashFile.get()->getBuffer();
+if (!Data.startswith("Process:"))
+  continue;
+// Parse parent process pi

[PATCH] D26816: [libcxx] [test] Fix non-Standard assumptions when testing sample().

2016-11-17 Thread Stephan T. Lavavej 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 non-Standard assumptions when testing sample().

sample() isn't specified with a reproducible algorithm, so expecting
exact output is non-Standard. Mark those tests with LIBCPP_ASSERT.

In test_small_population(), we're guaranteed to get all of the elements,
but not necessarily in their original order. When PopulationCategory is
forward, we're guaranteed stability (and can therefore test equal()).
Otherwise, we can only test is_permutation(). (As it happens, both libcxx
and MSVC's STL provide stability in this scenario for input-only iterators.)


https://reviews.llvm.org/D26816

Files:
  test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.pass.cpp


Index: 
test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.pass.cpp
===
--- 
test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.pass.cpp
+++ 
test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.pass.cpp
@@ -19,9 +19,11 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #include "test_iterators.h"
+#include "test_macros.h"
 
 struct ReservoirSampleExpectations {
   enum { os = 4 };
@@ -60,19 +62,21 @@
   const unsigned os = Expectations::os;
   SampleItem oa[os];
   const int *oa1 = Expectations::oa1;
+  ((void)oa1); // Prevent unused warning
   const int *oa2 = Expectations::oa2;
+  ((void)oa2); // Prevent unused warning
   std::minstd_rand g;
   SampleIterator end;
   end = std::sample(PopulationIterator(ia),
   PopulationIterator(ia + is),
   SampleIterator(oa), os, g);
   assert(end.base() - oa == std::min(os, is));
-  assert(std::equal(oa, oa + os, oa1));
+  LIBCPP_ASSERT(std::equal(oa, oa + os, oa1));
   end = std::sample(PopulationIterator(ia),
   PopulationIterator(ia + is),
   SampleIterator(oa), os, std::move(g));
   assert(end.base() - oa == std::min(os, is));
-  assert(std::equal(oa, oa + os, oa2));
+  LIBCPP_ASSERT(std::equal(oa, oa + os, oa2));
 }
 
 template  class PopulationIteratorType, class 
PopulationItem,
@@ -122,7 +126,12 @@
   PopulationIterator(ia + is),
   SampleIterator(oa), os, g);
   assert(end.base() - oa == std::min(os, is));
-  assert(std::equal(oa, end.base(), oa1));
+  typedef typename std::iterator_traits::iterator_category 
PopulationCategory;
+  if (std::is_base_of::value) {
+assert(std::equal(oa, end.base(), oa1));
+  } else {
+assert(std::is_permutation(oa, end.base(), oa1));
+  }
 }
 
 int main() {


Index: test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.pass.cpp
===
--- test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.pass.cpp
+++ test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.pass.cpp
@@ -19,9 +19,11 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #include "test_iterators.h"
+#include "test_macros.h"
 
 struct ReservoirSampleExpectations {
   enum { os = 4 };
@@ -60,19 +62,21 @@
   const unsigned os = Expectations::os;
   SampleItem oa[os];
   const int *oa1 = Expectations::oa1;
+  ((void)oa1); // Prevent unused warning
   const int *oa2 = Expectations::oa2;
+  ((void)oa2); // Prevent unused warning
   std::minstd_rand g;
   SampleIterator end;
   end = std::sample(PopulationIterator(ia),
   PopulationIterator(ia + is),
   SampleIterator(oa), os, g);
   assert(end.base() - oa == std::min(os, is));
-  assert(std::equal(oa, oa + os, oa1));
+  LIBCPP_ASSERT(std::equal(oa, oa + os, oa1));
   end = std::sample(PopulationIterator(ia),
   PopulationIterator(ia + is),
   SampleIterator(oa), os, std::move(g));
   assert(end.base() - oa == std::min(os, is));
-  assert(std::equal(oa, oa + os, oa2));
+  LIBCPP_ASSERT(std::equal(oa, oa + os, oa2));
 }
 
 template  class PopulationIteratorType, class PopulationItem,
@@ -122,7 +126,12 @@
   PopulationIterator(ia + is),
   SampleIterator(oa), os, g);
   assert(end.base() - oa == std::min(os, is));
-  assert(std::equal(oa, end.base(), oa1));
+  typedef typename std::iterator_traits::iterator_category PopulationCategory;
+  if (std::is_base_of::value) {
+assert(std::equal(oa, end.base(), oa1));
+  } else {
+assert(std::is_permutation(oa, end.base(), oa1));
+  }
 }
 
 int main() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26815: [libcxx] [test] Fix an assumption about the state of moved-from std::functions.

2016-11-17 Thread Stephan T. Lavavej 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 an assumption about the state of moved-from std::functions.

The Standard doesn't provide any guarantees beyond "valid but unspecified" for
moved-from std::functions. libcxx moves from small targets and leaves them
there, while MSVC's STL empties out the source. Mark these assertions as
libcxx-specific.


https://reviews.llvm.org/D26815

Files:
  
test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp


Index: 
test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
===
--- 
test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
+++ 
test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
@@ -132,7 +132,7 @@
 assert(A::count == 1);
 assert(f2.target() == nullptr);
 assert(f2.target());
-assert(f.target()); // f is unchanged because the target is small
+LIBCPP_ASSERT(f.target()); // f is unchanged because the target 
is small
 }
 {
 // Test that moving a function constructed from a function pointer
@@ -146,7 +146,7 @@
 std::function f2(std::move(f));
 assert(f2.target() == nullptr);
 assert(f2.target());
-assert(f.target()); // f is unchanged because the target is small
+LIBCPP_ASSERT(f.target()); // f is unchanged because the target 
is small
 }
 #endif  // TEST_STD_VER >= 11
 }


Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
===
--- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
+++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
@@ -132,7 +132,7 @@
 assert(A::count == 1);
 assert(f2.target() == nullptr);
 assert(f2.target());
-assert(f.target()); // f is unchanged because the target is small
+LIBCPP_ASSERT(f.target()); // f is unchanged because the target is small
 }
 {
 // Test that moving a function constructed from a function pointer
@@ -146,7 +146,7 @@
 std::function f2(std::move(f));
 assert(f2.target() == nullptr);
 assert(f2.target());
-assert(f.target()); // f is unchanged because the target is small
+LIBCPP_ASSERT(f.target()); // f is unchanged because the target is small
 }
 #endif  // TEST_STD_VER >= 11
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26814: [libcxx] [test] Change ifstream constructor tests to handle read-only files.

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

[libcxx] [test] Change ifstream constructor tests to handle read-only files.

Certain source control systems like to set the read-only bit on their files,
which interferes with opening "test.dat" for both input and output.
Fortunately, we can work around this without losing test coverage.
Now, the ifstream.cons tests harmlessly ignore failures to open files for
input and output simultaneously. The ofstream.cons tests are creating writable
files (not checked into source control), where the ifstream tests will succeed.


https://reviews.llvm.org/D26814

Files:
  test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp
  test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp
  test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
  test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp

Index: test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
===
--- test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
+++ test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
@@ -31,6 +31,12 @@
 fs >> x;
 assert(x == 3.25);
 }
+{
+std::ifstream fs(temp, std::ios_base::out);
+double x = 0;
+fs >> x;
+assert(x == 3.25);
+}
 std::remove(temp.c_str());
 {
 std::wofstream fs(temp);
@@ -42,5 +48,11 @@
 fs >> x;
 assert(x == 3.25);
 }
+{
+std::wifstream fs(temp, std::ios_base::out);
+double x = 0;
+fs >> x;
+assert(x == 3.25);
+}
 std::remove(temp.c_str());
 }
Index: test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
===
--- test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
+++ test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
@@ -31,6 +31,12 @@
 fs >> x;
 assert(x == 3.25);
 }
+{
+std::ifstream fs(temp.c_str(), std::ios_base::out);
+double x = 0;
+fs >> x;
+assert(x == 3.25);
+}
 std::remove(temp.c_str());
 {
 std::wofstream fs(temp.c_str());
@@ -42,5 +48,11 @@
 fs >> x;
 assert(x == 3.25);
 }
+{
+std::wifstream fs(temp.c_str(), std::ios_base::out);
+double x = 0;
+fs >> x;
+assert(x == 3.25);
+}
 std::remove(temp.c_str());
 }
Index: test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp
===
--- test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp
+++ test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp
@@ -27,9 +27,13 @@
 }
 {
 std::ifstream fs(std::string("test.dat"), std::ios_base::out);
-double x = 0;
-fs >> x;
-assert(x == 3.25);
+
+if (fs) // "test.dat" might be read-only.
+{ // See also: test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
+double x = 0;
+fs >> x;
+assert(x == 3.25);
+}
 }
 {
 std::wifstream fs(std::string("test.dat"));
@@ -39,8 +43,12 @@
 }
 {
 std::wifstream fs(std::string("test.dat"), std::ios_base::out);
-double x = 0;
-fs >> x;
-assert(x == 3.25);
+
+if (fs) // "test.dat" might be read-only.
+{ // See also: test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
+double x = 0;
+fs >> x;
+assert(x == 3.25);
+}
 }
 }
Index: test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp
===
--- test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp
+++ test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp
@@ -27,9 +27,13 @@
 }
 {
 std::ifstream fs("test.dat", std::ios_base::out);
-double x = 0;
-fs >> x;
-assert(x == 3.25);
+
+if (fs) // "test.dat" might be read-only.
+{ // See also: test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
+double x = 0;
+fs >> x;
+assert(x == 3.25);
+}
 }
 {
 std::wifstream fs("test.dat");
@@ -39,8 +43,12 @@
 }
 {
 std::wifstream fs("test.dat", std::ios_base::out);
-double x = 0;
-fs >> x;
-assert(x == 3.25);
+
+if (fs) // "test.dat" might be read-only.
+{ // See also: test/std/input.output/file.streams/fstreams/ofstream.cons/

[PATCH] D26813: [libcxx] [test] allocator is non-Standard.

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

[libcxx] [test] allocator is non-Standard.

N4582 17.6.3.5 [allocator.requirements] says that allocators are given
cv-unqualified object types, and N4582 20.9.9 [default.allocator]
implies that allocator is ill-formed (due to colliding
address() overloads). Therefore, tests for allocator
should be marked as libcxx-specific (if not removed outright).


https://reviews.llvm.org/D26813

Files:
  
test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
  test/std/utilities/memory/default.allocator/allocator_types.pass.cpp


Index: test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
===
--- test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
+++ test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
@@ -32,6 +32,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 int main()
 {
 static_assert((std::is_same::size_type, 
std::size_t>::value), "");
@@ -45,7 +47,7 @@
 std::allocator >::value), "");
 
 static_assert((std::is_same::is_always_equal, 
std::true_type>::value), "");
-static_assert((std::is_same::is_always_equal, 
std::true_type>::value), "");
+LIBCPP_STATIC_ASSERT((std::is_same::is_always_equal, std::true_type>::value), "");
 
 std::allocator a;
 std::allocator a2 = a;
Index: 
test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
===
--- 
test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
+++ 
test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
@@ -16,6 +16,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 template 
 void test_max(size_t count)
 {
@@ -27,23 +29,19 @@
 }
 }
 
-int main()
+template 
+void test()
 {
-{  // Bug 26812 -- allocating too large
-typedef double T;
-std::allocator a;
-test_max (a.max_size() + 1);// just barely too large
-test_max (a.max_size() * 2);// significantly too 
large
-test_max (((size_t) -1) / sizeof(T) + 1);   // multiply will 
overflow
-test_max ((size_t) -1); // way too large
-}
+// Bug 26812 -- allocating too large
+std::allocator a;
+test_max (a.max_size() + 1);// just barely too large
+test_max (a.max_size() * 2);// significantly too large
+test_max (((size_t) -1) / sizeof(T) + 1);   // multiply will overflow
+test_max ((size_t) -1); // way too large
+}
 
-{
-typedef const double T;
-std::allocator a;
-test_max (a.max_size() + 1);// just barely too large
-test_max (a.max_size() * 2);// significantly too 
large
-test_max (((size_t) -1) / sizeof(T) + 1);   // multiply will 
overflow
-test_max ((size_t) -1); // way too large
-}
+int main()
+{
+test();
+LIBCPP_ONLY(test());
 }


Index: test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
===
--- test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
+++ test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
@@ -32,6 +32,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 int main()
 {
 static_assert((std::is_same::size_type, std::size_t>::value), "");
@@ -45,7 +47,7 @@
 std::allocator >::value), "");
 
 static_assert((std::is_same::is_always_equal, std::true_type>::value), "");
-static_assert((std::is_same::is_always_equal, std::true_type>::value), "");
+LIBCPP_STATIC_ASSERT((std::is_same::is_always_equal, std::true_type>::value), "");
 
 std::allocator a;
 std::allocator a2 = a;
Index: test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
===
--- test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
+++ test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
@@ -16,6 +16,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 template 
 void test_max(size_t count)
 {
@@ -27,23 +29,19 @@
 }
 }
 
-int main()
+template 
+void test()
 {
-{  // Bug 26812 -- allocating too large
-typedef double T;
-std::allocator a;
-test_max (a.max_size() + 1);// just barely too large
-test_max (a.max_size() * 2);// significantly too large
-test_max (((size_t) -1) / sizeof(T) + 1);   // multiply will overflow
-test_max ((size_t) -1);  

[PATCH] D26812: [libcxx] [test] In random tests, use real static_asserts and silence a warning.

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

[libcxx] [test] In random tests, use real static_asserts and silence a warning.

One test triggers MSVC's warning C4310 "cast truncates constant value".
The code is valid, and yet the warning is valid, so I'm silencing it
through push-disable-pop.


https://reviews.llvm.org/D26812

Files:
  test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp
  test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp
  test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp
  test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
  test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp
  test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp

Index: test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp
===
--- test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp
+++ test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp
@@ -38,8 +38,8 @@
 static_assert((E::word_size == 24), "");
 static_assert((E::short_lag == 10), "");
 static_assert((E::long_lag == 24), "");
-/*static_*/assert((E::min() == 0)/*, ""*/);
-/*static_*/assert((E::max() == 0xFF)/*, ""*/);
+static_assert((E::min() == 0), "");
+static_assert((E::max() == 0xFF), "");
 static_assert((E::default_seed == 19780503u), "");
 where(E::word_size);
 where(E::short_lag);
@@ -54,8 +54,8 @@
 static_assert((E::word_size == 48), "");
 static_assert((E::short_lag == 5), "");
 static_assert((E::long_lag == 12), "");
-/*static_*/assert((E::min() == 0)/*, ""*/);
-/*static_*/assert((E::max() == 0xull)/*, ""*/);
+static_assert((E::min() == 0), "");
+static_assert((E::max() == 0xull), "");
 static_assert((E::default_seed == 19780503u), "");
 where(E::word_size);
 where(E::short_lag);
Index: test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp
===
--- test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp
+++ test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp
@@ -60,8 +60,8 @@
 static_assert((E::tempering_c == 0xefc6), "");
 static_assert((E::tempering_l == 18), "");
 static_assert((E::initialization_multiplier == 1812433253), "");
-/*static_*/assert((E::min() == 0)/*, ""*/);
-/*static_*/assert((E::max() == 0x)/*, ""*/);
+static_assert((E::min() == 0), "");
+static_assert((E::max() == 0x), "");
 static_assert((E::default_seed == 5489u), "");
 where(E::word_size);
 where(E::state_size);
@@ -96,8 +96,8 @@
 static_assert((E::tempering_c == 0xfff7eee0ull), "");
 static_assert((E::tempering_l == 43), "");
 static_assert((E::initialization_multiplier == 6364136223846793005ull), "");
-/*static_*/assert((E::min() == 0)/*, ""*/);
-/*static_*/assert((E::max() == 0xull)/*, ""*/);
+static_assert((E::min() == 0), "");
+static_assert((E::max() == 0xull), "");
 static_assert((E::default_seed == 5489u), "");
 where(E::word_size);
 where(E::state_size);
Index: test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
===
--- test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
+++ test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
@@ -37,8 +37,19 @@
 static_assert((LCE::multiplier == a), "");
 static_assert((LCE::increment == c), "");
 static_assert((LCE::modulus == m), "");
-/*static_*/assert((LCE::min() == (c == 0u ? 1u: 0u))/*, ""*/);
-/*static_*/assert((LCE::max() == result_type(m - 1u))/*, ""*/);
+static_assert((LCE::min() == (c == 0u ? 1u: 0u)), "");
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable: 4310) // cast truncates constant value
+#endif // _MSC_VER
+
+static_assert((LCE::max() == result_type(m - 1u)), "");
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif // _MSC_VER
+
 static_assert((LCE::default_seed == 1), "");
 where(LCE::multiplier);
 where(LCE::increment);
Index: test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp
===
--- test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp
+++ test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp
@@ -33,8 +33,8 @@
 {
 typedef std::knuth_b E;
 static_assert(E::table_size == 256, "");
-/*static_*/assert((E::min() == 1)/*, ""*/);
-/*static_*/assert((E::max() == 2147483646)/*, ""*/);
+static_assert((E::min() == 1), "");
+static_assert((E::max() == 2147483646), "");
 where(E::table_size);
 }
 
Index: test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp
===

[PATCH] D26774: [CUDA] Driver changes to support CUDA compilation on MacOS.

2016-11-17 Thread Artem Belevich via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM, with couple of minor nits.




Comment at: clang/lib/Driver/Driver.cpp:3650-3654
+
+  // Intentionally omitted from the switch above: llvm::Triple::CUDA.  CUDA
+  // compiles always need two toolchains, the CUDA toolchain and the host
+  // toolchain.  So the only valid way to create a CUDA toolchain is via
+  // CreateOffloadingDeviceToolChains.

should there be an assert() or llvm_unreachable() to ensure that? Right now 
we'll happily return default toolchain.



Comment at: clang/test/Driver/cuda-detect.cu:67
 // RUN: -check-prefix LIBDEVICE -check-prefix LIBDEVICE35
+// RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
+// RUN:   -nocudainc --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \

Should that be --target=i386-apple-macosx ?


https://reviews.llvm.org/D26774



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


[PATCH] D25654: [Sema] Don't perform aggregate initialization for types with explicit constructors

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 78410.
EricWF added a comment.

OK, I've applied the fix to C++11 and C++14. Although the 
inheriting-constructor part still only matters in C++1z since it requires 
having base classes.

I also fixed aggregate initialization for types with non-aggregate base 
classes. For example:

  struct A { A(int); };
  struct B : A {};
  B b = {42}; // OK in C++1z


https://reviews.llvm.org/D25654

Files:
  lib/AST/DeclCXX.cpp
  test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1.cpp
  test/CXX/drs/dr15xx.cpp

Index: test/CXX/drs/dr15xx.cpp
===
--- test/CXX/drs/dr15xx.cpp
+++ test/CXX/drs/dr15xx.cpp
@@ -135,6 +135,53 @@
   }
 }
 
+namespace dr1518 { // dr1518: 4.0
+#if __cplusplus >= 201103L
+struct Z0 { // expected-note 0+ {{candidate}}
+  explicit Z0() = default; // expected-note 0+ {{here}}
+};
+struct Z { // expected-note 0+ {{candidate}}
+  explicit Z(); // expected-note 0+ {{here}}
+  explicit Z(int);
+  explicit Z(int, int); // expected-note 0+ {{here}}
+};
+template  int Eat(T); // expected-note 0+ {{candidate}}
+Z0 a;
+Z0 b{};
+Z0 c = {}; // expected-error {{explicit in copy-initialization}}
+int i = Eat({}); // expected-error {{no matching function for call to 'Eat'}}
+
+Z c2 = {}; // expected-error {{explicit in copy-initialization}}
+int i2 = Eat({}); // expected-error {{no matching function for call to 'Eat'}}
+Z a1 = 1; // expected-error {{no viable conversion}}
+Z a3 = Z(1);
+Z a2(1);
+Z *p = new Z(1);
+Z a4 = (Z)1;
+Z a5 = static_cast(1);
+Z a6 = {4, 3}; // expected-error {{explicit in copy-initialization}}
+
+struct UserProvidedBaseCtor { // expected-note 0+ {{candidate}}
+  UserProvidedBaseCtor() {}
+};
+struct DoesntInheritCtor : UserProvidedBaseCtor { // expected-note 0+ {{candidate}}
+  int x;
+};
+DoesntInheritCtor I{{}, 42};
+#if __cplusplus <= 201402L
+// expected-error@-2 {{no matching constructor}}
+#endif
+
+struct BaseCtor { BaseCtor() = default; }; // expected-note 0+ {{candidate}}
+struct InheritsCtor : BaseCtor { // expected-note 1+ {{candidate}}
+  using BaseCtor::BaseCtor;  // expected-note 2 {{inherited here}}
+  int x;
+};
+InheritsCtor II = {{}, 42}; // expected-error {{no matching constructor}}
+
+#endif  // __cplusplus >= 201103L
+}
+
 namespace dr1550 { // dr1550: yes
   int f(bool b, int n) {
 return (b ? (throw 0) : n) + (b ? n : (throw 0));
Index: test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1.cpp
===
--- test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1.cpp
+++ test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1.cpp
@@ -122,3 +122,38 @@
   ~DefaultedAggr() = default;
 };
 DefaultedAggr da = { 42 } ;
+
+struct ExplicitDefaultedAggr {
+  int n;
+  explicit ExplicitDefaultedAggr() = default; // expected-note {{candidate}}
+  ExplicitDefaultedAggr(const ExplicitDefaultedAggr &) = default; // expected-note {{candidate}}
+  ExplicitDefaultedAggr(ExplicitDefaultedAggr &&) = default; // expected-note {{candidate}}
+};
+ExplicitDefaultedAggr eda = { 42 }; // expected-error {{no matching constructor}}
+
+struct DefaultedBase {
+  int n;
+  DefaultedBase() = default; // expected-note 0+ {{candidate}}
+  DefaultedBase(DefaultedBase const&) = default; // expected-note 0+ {{candidate}}
+  DefaultedBase(DefaultedBase &&) = default; // expected-note 0+ {{candidate}}
+};
+
+struct InheritingConstructors : DefaultedBase { // expected-note 3 {{candidate}}
+  using DefaultedBase::DefaultedBase; // expected-note 2 {{inherited here}}
+};
+InheritingConstructors ic = { 42 }; // expected-error {{no matching constructor}}
+
+struct NonInheritingConstructors : DefaultedBase {}; // expected-note 0+ {{candidate}}
+NonInheritingConstructors nic = { 42 };
+#if __cplusplus <= 201402L
+// expected-error@-2 {{no matching constructor}}
+#endif
+
+struct NonAggrBase {
+  NonAggrBase(int) {}
+};
+struct HasNonAggrBase : NonAggrBase {}; // expected-note 0+ {{candidate}}
+HasNonAggrBase hnab = {42};
+#if __cplusplus <= 201402L
+// expected-error@-2 {{no matching constructor}}
+#endif
Index: lib/AST/DeclCXX.cpp
===
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -533,6 +533,17 @@
   } else if (Constructor->isMoveConstructor())
 SMKind |= SMF_MoveConstructor;
 }
+
+// C++ [dcl.init.aggr]p1:
+//   An aggregate is an array or a class with no user-declared
+//   constructors [...].
+// C++11 [dcl.init.aggr]p1: DR1518
+//  An aggregate is an array or a class with no user-provided, explicit, or
+//  inherited constructors
+if (getASTContext().getLangOpts().CPlusPlus11
+? (Constructor->isUserProvided() || Constructor->isExplicit())
+: !Constructor->isImplicit())
+  data().Aggregate = false;
   }
 
   // Handle constructors, including those inherited from base classes.
@@ -546,20 +557,6 @@
 //   constructor [...]
  

[PATCH] D26807: Fix a comment for -fsave-optimization-record

2016-11-17 Thread Hal Finkel via cfe-commits
hfinkel accepted this revision.
hfinkel added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D26807



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


r287258 - Fixes for r287241. Use placement new. Apply clang-format.

2016-11-17 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Thu Nov 17 15:00:09 2016
New Revision: 287258

URL: http://llvm.org/viewvc/llvm-project?rev=287258&view=rev
Log:
Fixes for r287241. Use placement new. Apply clang-format.

Modified:
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=287258&r1=287257&r2=287258&view=diff
==
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Thu Nov 17 15:00:09 2016
@@ -2039,7 +2039,8 @@ void Parser::HandleMemberFunctionDeclDel
 LateMethod->DefaultArgs.reserve(FTI.NumParams);
 for (unsigned ParamIdx = 0; ParamIdx < FTI.NumParams; ++ParamIdx)
   LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument(
-FTI.Params[ParamIdx].Param, 
std::move(FTI.Params[ParamIdx].DefaultArgTokens)));
+  FTI.Params[ParamIdx].Param,
+  std::move(FTI.Params[ParamIdx].DefaultArgTokens)));
   }
 }
 

Modified: cfe/trunk/lib/Sema/DeclSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=287258&r1=287257&r2=287258&view=diff
==
--- cfe/trunk/lib/Sema/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Sema/DeclSpec.cpp Thu Nov 17 15:00:09 2016
@@ -223,15 +223,11 @@ DeclaratorChunk DeclaratorChunk::getFunc
 if (!TheDeclarator.InlineStorageUsed &&
 NumParams <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
   I.Fun.Params = TheDeclarator.InlineParams;
-  // Zero the memory block so that unique pointers are initialized
-  // properly.
-  memset(I.Fun.Params, 0, sizeof(Params[0]) * NumParams);
+  new (I.Fun.Params) ParamInfo[NumParams];
   I.Fun.DeleteParams = false;
   TheDeclarator.InlineStorageUsed = true;
 } else {
-  // Call the version of new that zeroes memory so that unique pointers
-  // are initialized properly.
-  I.Fun.Params = new DeclaratorChunk::ParamInfo[NumParams]();
+  I.Fun.Params = new DeclaratorChunk::ParamInfo[NumParams];
   I.Fun.DeleteParams = true;
 }
 for (unsigned i = 0; i < NumParams; i++)

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=287258&r1=287257&r2=287258&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Nov 17 15:00:09 2016
@@ -395,7 +395,8 @@ void Sema::CheckExtraCXXDefaultArguments
++argIdx) {
 ParmVarDecl *Param = cast(chunk.Fun.Params[argIdx].Param);
 if (Param->hasUnparsedDefaultArg()) {
-  std::unique_ptr Toks = 
std::move(chunk.Fun.Params[argIdx].DefaultArgTokens);
+  std::unique_ptr Toks =
+  std::move(chunk.Fun.Params[argIdx].DefaultArgTokens);
   SourceRange SR;
   if (Toks->size() > 1)
 SR = SourceRange((*Toks)[1].getLocation(),


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


[PATCH] D26560: Add a test for vcall on a null ptr.

2016-11-17 Thread Ivan Krasin via cfe-commits
krasin updated this revision to Diff 78405.
krasin added a comment.

sync


https://reviews.llvm.org/D26560

Files:
  test/ubsan/TestCases/TypeCheck/null.cpp


Index: test/ubsan/TestCases/TypeCheck/null.cpp
===
--- test/ubsan/TestCases/TypeCheck/null.cpp
+++ test/ubsan/TestCases/TypeCheck/null.cpp
@@ -1,20 +1,50 @@
-// RUN: %clangxx -fsanitize=null %s -O3 -o %t
-// RUN: %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD
-// RUN: %expect_crash %run %t s 2>&1 | FileCheck %s --check-prefix=CHECK-STORE
-// RUN: %run %t r 2>&1 | FileCheck %s --check-prefix=CHECK-REFERENCE
-// RUN: %run %t m 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER
-// RUN: %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN
+// RUN: %clangxx -fsanitize=null -fno-sanitize-recover=null -g %s -O3 -o %t
+// RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD
+// RUN: not %run %t s 2>&1 | FileCheck %s --check-prefix=CHECK-STORE
+// RUN: not %run %t r 2>&1 | FileCheck %s --check-prefix=CHECK-REFERENCE
+// RUN: not %run %t m 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER
+// RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN
+// RUN: not %run %t t 2>&1 | FileCheck %s --check-prefix=CHECK-VCALL
+// RUN: not %run %t u 2>&1 | FileCheck %s --check-prefix=CHECK-VCALL2
+
+#include 
 
 struct S {
   int f() { return 0; }
   int k;
 };
 
+struct T {
+  virtual int v() { return 1; }
+};
+
+struct U : T {
+  virtual int v() { return 2; }
+};
+
+static inline void break_optimization(void *arg) {
+  __asm__ __volatile__("" : : "r" (arg) : "memory");
+}
+
 int main(int, char **argv) {
   int *p = 0;
   S *s = 0;
+  T *t = 0;
+  U *u = 0;
+
+  if (argv[1][0] == 'T') {
+t = new T;
+  }
+  if (argv[1][0] == 'U') {
+u = new U;
+  }
+
+  break_optimization(s);
+  break_optimization(t);
+  break_optimization(u);
 
   (void)*p; // ok!
+  (void)*t; // ok!
 
   switch (argv[1][0]) {
   case 'l':
@@ -34,5 +64,13 @@
   case 'f':
 // CHECK-MEMFUN: null.cpp:[[@LINE+1]]:15: runtime error: member call on 
null pointer of type 'S'
 return s->f();
+  case 't':
+  case 'T':
+// CHECK-VCALL: null.cpp:[[@LINE+1]]:15: runtime error: member call on 
null pointer of type 'T'
+return t->v();
+  case 'u':
+  case 'U':
+// CHECK-VCALL2: null.cpp:[[@LINE+1]]:15: runtime error: member call on 
null pointer of type 'U'
+return u->v();
   }
 }


Index: test/ubsan/TestCases/TypeCheck/null.cpp
===
--- test/ubsan/TestCases/TypeCheck/null.cpp
+++ test/ubsan/TestCases/TypeCheck/null.cpp
@@ -1,20 +1,50 @@
-// RUN: %clangxx -fsanitize=null %s -O3 -o %t
-// RUN: %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD
-// RUN: %expect_crash %run %t s 2>&1 | FileCheck %s --check-prefix=CHECK-STORE
-// RUN: %run %t r 2>&1 | FileCheck %s --check-prefix=CHECK-REFERENCE
-// RUN: %run %t m 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER
-// RUN: %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN
+// RUN: %clangxx -fsanitize=null -fno-sanitize-recover=null -g %s -O3 -o %t
+// RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD
+// RUN: not %run %t s 2>&1 | FileCheck %s --check-prefix=CHECK-STORE
+// RUN: not %run %t r 2>&1 | FileCheck %s --check-prefix=CHECK-REFERENCE
+// RUN: not %run %t m 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER
+// RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN
+// RUN: not %run %t t 2>&1 | FileCheck %s --check-prefix=CHECK-VCALL
+// RUN: not %run %t u 2>&1 | FileCheck %s --check-prefix=CHECK-VCALL2
+
+#include 
 
 struct S {
   int f() { return 0; }
   int k;
 };
 
+struct T {
+  virtual int v() { return 1; }
+};
+
+struct U : T {
+  virtual int v() { return 2; }
+};
+
+static inline void break_optimization(void *arg) {
+  __asm__ __volatile__("" : : "r" (arg) : "memory");
+}
+
 int main(int, char **argv) {
   int *p = 0;
   S *s = 0;
+  T *t = 0;
+  U *u = 0;
+
+  if (argv[1][0] == 'T') {
+t = new T;
+  }
+  if (argv[1][0] == 'U') {
+u = new U;
+  }
+
+  break_optimization(s);
+  break_optimization(t);
+  break_optimization(u);
 
   (void)*p; // ok!
+  (void)*t; // ok!
 
   switch (argv[1][0]) {
   case 'l':
@@ -34,5 +64,13 @@
   case 'f':
 // CHECK-MEMFUN: null.cpp:[[@LINE+1]]:15: runtime error: member call on null pointer of type 'S'
 return s->f();
+  case 't':
+  case 'T':
+// CHECK-VCALL: null.cpp:[[@LINE+1]]:15: runtime error: member call on null pointer of type 'T'
+return t->v();
+  case 'u':
+  case 'U':
+// CHECK-VCALL2: null.cpp:[[@LINE+1]]:15: runtime error: member call on null pointer of type 'U'
+return u->v();
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24289: Add warning when assigning enums to bitfields without an explicit unsigned underlying type

2016-11-17 Thread Arthur O'Dwyer via cfe-commits
On Thu, Nov 17, 2016 at 9:52 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:
> On 17 Nov 2016 8:56 am, "Reid Kleckner"  wrote:
>> In https://reviews.llvm.org/D24289#598169, @rsmith wrote:
>>> This is causing warnings to fire for headers shared between C and C++,
>>> where the "give the enum an unsigned underlying type" advice doesn't
work,
>>> and where the code in question will never be built for the MS ABI. It
seems
>>> really hard to justify this being on by default.
>>>
>>> I'm going to turn it off by default for now, but we should probably
>>> consider turning it back on by default when targeting the MS ABI (as a
"your
>>> code is wrong" warning rather than a "your code is not portable"
warning).
[...]
>>> Yeah, suggesting adding an underlying type to the enum to solve this
>>> problem seems like a bad idea, since that fundamentally changes the
nature
>>> of the enum -- typically allowing it to store a lot more values, and
making
>>> putting it in a bitfield a bad idea.
>
>> Any time you use a bitfield it stores fewer values than the original
integer
>> type. I don't see how enums are special here. [...]
>
> The range of representable values for a bitfield with no fixed underlying
> type is actually smaller than that of its underlying type. See
> http://eel.is/c++draft/dcl.enum#8
>
> So a bitfield of width equal to the number of bits needed to store any
> enumerator does not have fewer values than the original type.

My understanding (from osmosis and practice more than from reading the
standard) is that programmers are more likely to specify an "unnaturally
narrow" underlying type (e.g. "int8_t") than to specify an "unnaturally
wide" underlying type (e.g. "int32_t". When I specify an underlying type,
I'm saying "The compiler is going to do the wrong thing with this type's
*storage* by default"; I'm not saying anything about the type's *value
range*.
The same goes for bit-fields: I specify a number of bits after the colon
because the compiler would otherwise do the wrong thing with *storage*, not
because I'm trying to change the semantics of the *values* involved.


>> Do you have any better suggestions for people that want this code to do
the
>> right thing when built with MSVC?
>>
>>   enum E /* : unsigned */ { E0, E1, E2, E3 };
>>   struct A { E b : 2; };
>>   int main() {
>> A a;
>> a.b = E3;
>> return a.b; // comes out as -1 without the underlying type
>>   }
>>
>> Widening the bitfield wastes a bit. Making the bitfield a plain integer
and
>> cast in and out of the enum type, but that obscures the true type of the
>> bitfield. So, I still support this suggestion.

The safest fix is to just change ": 2" to ": 3", even though that "wastes a
bit" (really it wastes 0 bits in most cases and 32 to 64 bits in some
cases).

If I had my druthers, the compiler would be completely silent unless it
detected exactly the cases that would result in changes to the semantics of
enum *values*. That is,

when declaring a bit-field of enum type E with width B bits:
  if E has an enumerator e whose value requires >B bits:
warn that e cannot be stored in the bit-field
if a fixit is really required, suggest increasing the bit-field's
width
  if E has an enumerator e whose positive value requires exactly B
bits, and E's underlying type is signed:
warn that e cannot be stored in the bit-field when MSVC semantics
are in use
in C++, append the note that this happens because E's underlying
type is signed
if a fixit is really required, suggest increasing the bit-field's
width

Changing the width of the bit-field can affect only the layout of the
struct in question; you could even static_assert that the size *doesn't*
change, if there are padding bits available.
Changing a whole type from signed to unsigned seems like it would have more
dangerous action-at-a-distance than just increasing the width of the
bit-field: that would *unavoidably* affect comparisons (and overload
resolutions?) across the entire codebase using that type.
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#172
Again I'm making a philosophical distinction between the details of storage
(e.g. struct layout) and the actual semantics of values and types (e.g.
signedness).

The problem is with the bit-field inside the struct, so IMHO the solution
should involve changing the bit-field and/or the struct. Not altering the
enum type... which by the way, the programmer might not even control,
right? What if the relevant enum type comes from a third-party library?

> How about we consider msvc's behaviour to just be a bug, and zero-extend
> loads from enum bitfields with no negative enumerators? Since loading
such a
> negative value results in UB, this wouldn't change the meaning of any
> program with defined behaviour, and still respects the MS ABI.

SGTM, at least to put this behavior under a separately toggleable
command-line switch. (-fms-enum-bitfields?)

my $.02,

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

2016-11-17 Thread Akira Hatanaka via cfe-commits
ahatanak updated this revision to Diff 78399.
ahatanak added a comment.

Address Alex's review comments.

Define a static function for setting SrcAlign.


https://reviews.llvm.org/D21099

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


Index: test/Sema/warn-cast-align.c
===
--- test/Sema/warn-cast-align.c
+++ 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 *)&s.s0;
+  i = (int *)a;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -10267,6 +10267,13 @@
   return HasInvalidParm;
 }
 
+static void setSrcAlign(Expr *SE, CharUnits &SrcAlign, ASTContext &Context) {
+  if (const auto *DRE = dyn_cast(SE))
+SrcAlign = Context.getDeclAlign(DRE->getDecl());
+  else if (const auto *ME = dyn_cast(SE))
+SrcAlign = Context.getDeclAlign(ME->getMemberDecl());
+}
+
 /// CheckCastAlign - Implements -Wcast-align, which warns when a
 /// pointer cast increases the alignment requirements.
 void Sema::CheckCastAlign(Expr *Op, QualType T, SourceRange TRange) {
@@ -10301,6 +10308,15 @@
   if (SrcPointee->isIncompleteType()) return;
 
   CharUnits SrcAlign = Context.getTypeAlignInChars(SrcPointee);
+
+  if (auto *CE = dyn_cast(Op)) {
+if (CE->getCastKind() == CK_ArrayToPointerDecay)
+  setSrcAlign(CE->getSubExpr(), SrcAlign, Context);
+  } else if (auto *UO = dyn_cast(Op)) {
+if (UO->getOpcode() == UO_AddrOf)
+  setSrcAlign(UO->getSubExpr(), SrcAlign, Context);
+  }
+
   if (SrcAlign >= DestAlign) return;
 
   Diag(TRange.getBegin(), diag::warn_cast_align)


Index: test/Sema/warn-cast-align.c
===
--- test/Sema/warn-cast-align.c
+++ 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 *)&s.s0;
+  i = (int *)a;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -10267,6 +10267,13 @@
   return HasInvalidParm;
 }
 
+static void setSrcAlign(Expr *SE, CharUnits &SrcAlign, ASTContext &Context) {
+  if (const auto *DRE = dyn_cast(SE))
+SrcAlign = Context.getDeclAlign(DRE->getDecl());
+  else if (const auto *ME = dyn_cast(SE))
+SrcAlign = Context.getDeclAlign(ME->getMemberDecl());
+}
+
 /// CheckCastAlign - Implements -Wcast-align, which warns when a
 /// pointer cast increases the alignment requirements.
 void Sema::CheckCastAlign(Expr *Op, QualType T, SourceRange TRange) {
@@ -10301,6 +10308,15 @@
   if (SrcPointee->isIncompleteType()) return;
 
   CharUnits SrcAlign = Context.getTypeAlignInChars(SrcPointee);
+
+  if (auto *CE = dyn_cast(Op)) {
+if (CE->getCastKind() == CK_ArrayToPointerDecay)
+  setSrcAlign(CE->getSubExpr(), SrcAlign, Context);
+  } else if (auto *UO = dyn_cast(Op)) {
+if (UO->getOpcode() == UO_AddrOf)
+  setSrcAlign(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


[PATCH] D22334: Fix for Bug 28172 : clang crashes on invalid code (with too few arguments to __builtin_signbit) without any proper diagnostics.

2016-11-17 Thread David Majnemer via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM with nits




Comment at: lib/Sema/SemaChecking.cpp:110
+S.Diag(ValArg->getLocStart(), diag::err_typecheck_cond_expect_float)
+  << ValArg->getType() << ValArg->getSourceRange();
+return true;

Can you change this `ValArg->getType()` to `Ty`?


https://reviews.llvm.org/D22334



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


[libcxx] r287255 - Workaround compilers w/o C++1z inline variables

2016-11-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Nov 17 14:08:43 2016
New Revision: 287255

URL: http://llvm.org/viewvc/llvm-project?rev=287255&view=rev
Log:
Workaround compilers w/o C++1z inline variables

Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/utility

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=287255&r1=287254&r2=287255&view=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Thu Nov 17 14:08:43 2016
@@ -796,6 +796,11 @@ template  struct __static_asse
 #define _LIBCPP_CONSTEXPR_AFTER_CXX14
 #endif
 
+// FIXME: Remove all usages of this macro once compilers catch up.
+#if !defined(__cpp_inline_variables) || (__cpp_inline_variables < 201606L)
+# define _LIBCPP_HAS_NO_INLINE_VARIABLES
+#endif
+
 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #  define _LIBCPP_EXPLICIT_MOVE(x) _VSTD::move(x)
 #else

Modified: libcxx/trunk/include/utility
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=287255&r1=287254&r2=287255&view=diff
==
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Thu Nov 17 14:08:43 2016
@@ -897,21 +897,30 @@ _T1 exchange(_T1& __obj, _T2 && __new_va
 struct _LIBCPP_TYPE_VIS in_place_t {
 explicit in_place_t() = default;
 };
-inline constexpr in_place_t in_place{};
+#ifndef _LIBCPP_HAS_NO_INLINE_VARIABLES
+inline
+#endif
+constexpr in_place_t in_place{};
 
 template 
 struct _LIBCPP_TYPE_VIS in_place_type_t {
 explicit in_place_type_t() = default;
 };
 template 
-inline constexpr in_place_type_t<_Tp> in_place_type{};
+#ifndef _LIBCPP_HAS_NO_INLINE_VARIABLES
+inline
+#endif
+constexpr in_place_type_t<_Tp> in_place_type{};
 
 template 
 struct _LIBCPP_TYPE_VIS in_place_index_t {
 explicit in_place_index_t() = default;
 };
 template 
-inline constexpr in_place_index_t<_Idx> in_place_index{};
+#ifndef _LIBCPP_HAS_NO_INLINE_VARIABLES
+inline
+#endif
+constexpr in_place_index_t<_Idx> in_place_index{};
 
 template  struct __is_inplace_type_imp : false_type {};
 template  struct __is_inplace_type_imp> : 
true_type {};


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


[PATCH] D22334: Fix for Bug 28172 : clang crashes on invalid code (with too few arguments to __builtin_signbit) without any proper diagnostics.

2016-11-17 Thread Mayur Pandey via cfe-commits
mayurpandey updated this revision to Diff 78390.
mayurpandey added a comment.

Hi,

Updated the patch to incorporate the review comments. I had missed adding 
ValArg->getType() when emitting the diagnostic which was cauing the crash.

Testing done, no regressions.

Thanks,
Mayur


https://reviews.llvm.org/D22334

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/builtins.c
  test/SemaCXX/builtins.cpp


Index: test/SemaCXX/builtins.cpp
===
--- test/SemaCXX/builtins.cpp
+++ test/SemaCXX/builtins.cpp
@@ -44,3 +44,10 @@
   __noop(1); // expected-error {{use of undeclared}}
   __debugbreak(); // expected-error {{use of undeclared}}
 }
+
+template 
+int test_signbit(T t) { return __builtin_signbit(t); } // expected-error 
{{floating point type is required}}
+
+int test_signbit_call () {
+return test_signbit("1"); // expected-note {{instantiation of function 
template specialization}} 
+}
Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -248,3 +248,11 @@
 
 return buf;
 }
+
+int test21(double a) {
+  return __builtin_signbit();  // expected-error {{too few arguments}}
+}
+
+int test22(void) {
+  return __builtin_signbit("1");  // expected-error {{floating point type is 
required}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -98,6 +98,22 @@
   return false;
 }
 
+static bool SemaBuiltinSignbit(Sema &S, CallExpr *TheCall) {
+  if (checkArgCount(S, TheCall, 1))
+return true;
+
+  // Argument should be an float, double or long double.
+  Expr *ValArg = TheCall->getArg(0);
+  QualType Ty = ValArg->getType();
+  if (!Ty->isRealFloatingType()) {
+S.Diag(ValArg->getLocStart(), diag::err_typecheck_cond_expect_float)
+  << ValArg->getType() << ValArg->getSourceRange();
+return true;
+  }
+
+  return false;
+}
+
 /// Check that the argument to __builtin_addressof is a glvalue, and set the
 /// result type to the corresponding pointer type.
 static bool SemaBuiltinAddressof(Sema &S, CallExpr *TheCall) {
@@ -762,6 +778,10 @@
 }
 break;
   }
+  case Builtin::BI__builtin_signbit:
+if (SemaBuiltinSignbit(*this, TheCall))
+  return ExprError();
+break;
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6845,6 +6845,8 @@
   "(passed in %0)">;
 def err_typecheck_cond_expect_int_float : Error<
   "used type %0 where integer or floating point type is required">;
+def err_typecheck_cond_expect_float : Error<
+  "used type %0 where floating point type is required">;
 def err_typecheck_cond_expect_scalar : Error<
   "used type %0 where arithmetic or pointer type is required">;
 def err_typecheck_cond_expect_nonfloat : Error<


Index: test/SemaCXX/builtins.cpp
===
--- test/SemaCXX/builtins.cpp
+++ test/SemaCXX/builtins.cpp
@@ -44,3 +44,10 @@
   __noop(1); // expected-error {{use of undeclared}}
   __debugbreak(); // expected-error {{use of undeclared}}
 }
+
+template 
+int test_signbit(T t) { return __builtin_signbit(t); } // expected-error {{floating point type is required}}
+
+int test_signbit_call () {
+return test_signbit("1"); // expected-note {{instantiation of function template specialization}} 
+}
Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -248,3 +248,11 @@
 
 return buf;
 }
+
+int test21(double a) {
+  return __builtin_signbit();  // expected-error {{too few arguments}}
+}
+
+int test22(void) {
+  return __builtin_signbit("1");  // expected-error {{floating point type is required}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -98,6 +98,22 @@
   return false;
 }
 
+static bool SemaBuiltinSignbit(Sema &S, CallExpr *TheCall) {
+  if (checkArgCount(S, TheCall, 1))
+return true;
+
+  // Argument should be an float, double or long double.
+  Expr *ValArg = TheCall->getArg(0);
+  QualType Ty = ValArg->getType();
+  if (!Ty->isRealFloatingType()) {
+S.Diag(ValArg->getLocStart(), diag::err_typecheck_cond_expect_float)
+  << ValArg->getType() << ValArg->getSourceRange();
+return true;
+  }
+
+  return false;
+}
+
 /// Check that the argument to __builtin_addressof is a glvalue, and set the
 /// result type to the corresponding pointer type.
 static bool SemaBuiltinAddressof(Sema &S, CallEx

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

2016-11-17 Thread Aleksei Sidorin via cfe-commits
a.sidorin added a comment.

Thank you! I'll update this review again when I have a test for 
NestedNameSpecifierLocs.




Comment at: lib/AST/ASTImporter.cpp:458
+  }
+  return true;
+}

spyffe wrote:
> Is this really an appropriate default result?  I would argue for `false` here 
> so that an error would propagate, as is typical in ASTImporter.
> Note that this does disagree with the original source's `true` but I think 
> that was because we knew we didn't handle anything, whereas now the 
> assumption is we handle everything.
Good point. Default `false` will also fail import if a new non-handled property 
or option will be added in AST and clearly indicate an error so I will change 
it.


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] D26753: ASTImporter: improve support for C++ templates

2016-11-17 Thread Aleksei Sidorin via cfe-commits
a.sidorin updated this revision to Diff 78382.
a.sidorin added a comment.

Address review comments; fix tests.


https://reviews.llvm.org/D26753

Files:
  include/clang/AST/TemplateBase.h
  lib/AST/ASTImporter.cpp
  
test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec1.cpp
  
test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec2.cpp
  test/ASTMerge/class-template-partial-spec/test.cpp

Index: test/ASTMerge/class-template-partial-spec/test.cpp
===
--- /dev/null
+++ test/ASTMerge/class-template-partial-spec/test.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.1.ast %S/Inputs/class-template-partial-spec1.cpp
+// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.2.ast %S/Inputs/class-template-partial-spec2.cpp
+// RUN: not %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
+
+static_assert(sizeof(**SingleSource.member) == sizeof(**SingleDest.member));
+static_assert(sizeof(SecondDoubleSource.member) == sizeof(SecondDoubleDest.member));
+static_assert(NumberSource.val == 42);
+static_assert(sizeof(Z0Source.member) == sizeof(char));
+static_assert(sizeof(Dst::Z0Dst.member) == sizeof(double));
+static_assert(sizeof(One::Child1>::member) == sizeof(double));
+
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec2.cpp:21:32: error: external variable 'X1' declared with incompatible types in different translation units ('TwoOptionTemplate' vs. 'TwoOptionTemplate')
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec1.cpp:21:31: note: declared here with type 'TwoOptionTemplate'
+
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec2.cpp:24:29: error: external variable 'X4' declared with incompatible types in different translation units ('TwoOptionTemplate' vs. 'TwoOptionTemplate')
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec1.cpp:24:33: note: declared here with type 'TwoOptionTemplate'
+
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec1.cpp:38:8: warning: type 'IntTemplateSpec<5, void *>' has incompatible definitions in different translation units
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec1.cpp:39:7: note: field 'member' has type 'int' here
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec2.cpp:39:10: note: field 'member' has type 'double' here
+
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec2.cpp:52:25: error: external variable 'Y3' declared with incompatible types in different translation units ('IntTemplateSpec<2, int>' vs. 'IntTemplateSpec<3, int>')
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec1.cpp:52:25: note: declared here with type 'IntTemplateSpec<3, int>'
+
+// CHECK-NOT: static_assert
Index: test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec2.cpp
===
--- /dev/null
+++ test/ASTMerge/class-template-partial-spec/Inputs/class-template-partial-spec2.cpp
@@ -0,0 +1,79 @@
+template
+struct TwoOptionTemplate {};
+
+template
+struct TwoOptionTemplate {
+  int member;
+};
+
+
+template
+struct TwoOptionTemplate {
+  float member;
+};
+
+template
+struct TwoOptionTemplate {
+  T** member;
+};
+
+TwoOptionTemplate X0;
+TwoOptionTemplate X1;
+TwoOptionTemplate X2;
+TwoOptionTemplate X3;
+TwoOptionTemplate X4;
+TwoOptionTemplate SingleDest;
+TwoOptionTemplate SecondDoubleDest;
+
+
+template
+struct IntTemplateSpec {};
+
+template
+struct IntTemplateSpec<4, C> {
+  C member;
+};
+
+template
+struct IntTemplateSpec {
+  double member;
+  static constexpr int val = I;
+};
+
+template
+struct IntTemplateSpec {
+  char member;
+  static constexpr int val = I;
+};
+
+IntTemplateSpec<4, wchar_t>Y0;
+IntTemplateSpec<5, void *> Y1;
+IntTemplateSpec<1, int> Y2;
+IntTemplateSpec<2, int> Y3;
+IntTemplateSpec<43, double> NumberDest;
+
+namespace One {
+namespace Two {
+namespace Three {
+
+template
+class Parent {};
+
+} // namespace Three
+
+} // namespace Two
+
+template
+struct Child1: public Two::Three::Parent {
+  char member;
+};
+
+template
+struct Child1> {
+  T member;
+};
+
+} // namespace One
+
+namespace Dst { One::Child1> Z0Dst; }
+One::Child1 Z1;
Index: test/ASTMerge/class-template-partial-spec/Inputs

[PATCH] D26808: [Sema] Don't allow applying address-of operator to a call to a function with __unknown_anytype return type

2016-11-17 Thread Akira Hatanaka via cfe-commits
ahatanak created this revision.
ahatanak added reviewers: doug.gregor, spyffe.
ahatanak added a subscriber: cfe-commits.

This patch fixes an assert in CodeGenFunction::EmitCallExprLValue that is 
triggered when the CallExpr's return type is not a reference type:

assert(E->getCallReturnType(getContext())->isReferenceType() &&

  "Can't have a scalar return unless the return type is a "
  "reference type!");

Alternatively, since it's legal to apply the address-of operator to a reference 
return, we can change the function return type to be a reference (in the test 
case, that would be double&) in RebuildUnknownAnyExpr::VisitUnaryAddrOf when 
compiling for C++ (but not when compiling for C).


https://reviews.llvm.org/D26808

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/unknown-anytype.cpp


Index: test/SemaCXX/unknown-anytype.cpp
===
--- test/SemaCXX/unknown-anytype.cpp
+++ test/SemaCXX/unknown-anytype.cpp
@@ -56,3 +56,15 @@
 (X)test0(); // expected-error{{implicit instantiation of undefined 
template 'test5::X'}}
   }
 }
+
+namespace test6 {
+  extern __unknown_anytype func();
+  extern __unknown_anytype var;
+  double *d;
+
+  void test() {
+d = (double*)&func(); // expected-error{{address-of operator cannot be 
applied to a call to a function with unknown return type}}
+d = (double*)&var;
+  }
+
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14773,6 +14773,13 @@
   << E->getSourceRange();
 return ExprError();
   }
+
+  if (isa(E->getSubExpr())) {
+S.Diag(E->getOperatorLoc(), diag::err_unknown_any_addrof_call)
+  << E->getSourceRange();
+return ExprError();
+  }
+
   assert(E->getValueKind() == VK_RValue);
   assert(E->getObjectKind() == OK_Ordinary);
   E->setType(DestType);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8017,6 +8017,9 @@
 def err_unknown_any_addrof : Error<
   "the address of a declaration with unknown type "
   "can only be cast to a pointer type">;
+def err_unknown_any_addrof_call : Error<
+  "address-of operator cannot be applied to a call to a function with "
+  "unknown return type">;
 def err_unknown_any_var_function_type : Error<
   "variable %0 with unknown type cannot be given a function type">;
 def err_unknown_any_function : Error<


Index: test/SemaCXX/unknown-anytype.cpp
===
--- test/SemaCXX/unknown-anytype.cpp
+++ test/SemaCXX/unknown-anytype.cpp
@@ -56,3 +56,15 @@
 (X)test0(); // expected-error{{implicit instantiation of undefined template 'test5::X'}}
   }
 }
+
+namespace test6 {
+  extern __unknown_anytype func();
+  extern __unknown_anytype var;
+  double *d;
+
+  void test() {
+d = (double*)&func(); // expected-error{{address-of operator cannot be applied to a call to a function with unknown return type}}
+d = (double*)&var;
+  }
+
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14773,6 +14773,13 @@
   << E->getSourceRange();
 return ExprError();
   }
+
+  if (isa(E->getSubExpr())) {
+S.Diag(E->getOperatorLoc(), diag::err_unknown_any_addrof_call)
+  << E->getSourceRange();
+return ExprError();
+  }
+
   assert(E->getValueKind() == VK_RValue);
   assert(E->getObjectKind() == OK_Ordinary);
   E->setType(DestType);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8017,6 +8017,9 @@
 def err_unknown_any_addrof : Error<
   "the address of a declaration with unknown type "
   "can only be cast to a pointer type">;
+def err_unknown_any_addrof_call : Error<
+  "address-of operator cannot be applied to a call to a function with "
+  "unknown return type">;
 def err_unknown_any_var_function_type : Error<
   "variable %0 with unknown type cannot be given a function type">;
 def err_unknown_any_function : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25654: [Sema] Don't perform aggregate initialization for types with explicit constructors

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



Comment at: lib/AST/DeclCXX.cpp:564
+// C++1z [dcl.init.aggr]p1:
+//  - no user-provided, explicit, or inherited constructors,
+if (getASTContext().getLangOpts().CPlusPlus1z && Constructor->isExplicit())

rsmith wrote:
> Do we correctly handle the "or inherited" part? I'd also like to find out 
> whether core intended for this issue to be treated as a DR or not (if so, 
> this should apply all the way back to C++11).
According to the current issues list, this issue is in DRWP status, so this 
change should be applied retroactively to C++11 and C++14 as well.


https://reviews.llvm.org/D25654



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


[PATCH] D26782: [libcxx] [test] Test changes for P0504R0 "Revisiting in-place tag types for any/optional/variant"

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF closed this revision.
EricWF added a comment.

r287249. Thanks again!


https://reviews.llvm.org/D26782



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


[libcxx] r287251 - Remove files missed in r287250

2016-11-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Nov 17 13:24:34 2016
New Revision: 287251

URL: http://llvm.org/viewvc/llvm-project?rev=287251&view=rev
Log:
Remove files missed in r287250

Removed:
libcxx/trunk/test/libcxx/utilities/utility/utility.inplace/

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


[libcxx] r287250 - Implement P0504R0: Revisiting in-place tag types for any/optional/variant

2016-11-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Nov 17 13:24:04 2016
New Revision: 287250

URL: http://llvm.org/viewvc/llvm-project?rev=287250&view=rev
Log:
Implement P0504R0: Revisiting in-place tag types for any/optional/variant

Modified:
libcxx/trunk/include/any
libcxx/trunk/include/utility

Modified: libcxx/trunk/include/any
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/any?rev=287250&r1=287249&r2=287250&view=diff
==
--- libcxx/trunk/include/any (original)
+++ libcxx/trunk/include/any Thu Nov 17 13:24:04 2016
@@ -200,7 +200,7 @@ public:
 , class _Tp = decay_t<_ValueType>
 , class = enable_if_t<
 !is_same<_Tp, any>::value &&
-!__is_inplace_type_tag<_ValueType>::value &&
+!__is_inplace_type<_ValueType>::value &&
 is_copy_constructible<_Tp>::value>
 >
   _LIBCPP_INLINE_VISIBILITY
@@ -561,13 +561,13 @@ void swap(any & __lhs, any & __rhs) _NOE
 template 
 inline _LIBCPP_INLINE_VISIBILITY
 any make_any(_Args&&... __args) {
-return any(in_place<_Tp>, _VSTD::forward<_Args>(__args)...);
+return any(in_place_type<_Tp>, _VSTD::forward<_Args>(__args)...);
 }
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY
 any make_any(initializer_list<_Up> __il, _Args&&... __args) {
-return any(in_place<_Tp>, __il, _VSTD::forward<_Args>(__args)...);
+return any(in_place_type<_Tp>, __il, _VSTD::forward<_Args>(__args)...);
 }
 
 template 

Modified: libcxx/trunk/include/utility
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=287250&r1=287249&r2=287250&view=diff
==
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Thu Nov 17 13:24:04 2016
@@ -173,17 +173,22 @@ template
 T exchange(T& obj, U&& new_value);
 
 // 20.2.7, in-place construction // C++17
-struct in_place_tag { in_place_tag() = delete; }; // C++17
-using in_place_t = in_place_tag(&)(unspecified );
+struct in_place_t {
+  explicit in_place_t() = default;
+};
+inline constexpr in_place_t in_place{};
 template 
-using in_place_type_t = in_place_tag(&)(unspecified );
-template 
-using in_place_index_t = in_place_tag(&)(unspecified );
-in_place_tag in_place(unspecified );
+  struct in_place_type_t {
+explicit in_place_type_t() = default;
+  };
 template 
-in_place_tag in_place(unspecified );
+  inline constexpr in_place_type_t in_place_type{};
 template 
-in_place_tag in_place(unspecified );
+  struct in_place_index_t {
+explicit in_place_index_t() = default;
+  };
+template 
+  inline constexpr in_place_index_t in_place_index{};
 
 }  // std
 
@@ -889,59 +894,30 @@ _T1 exchange(_T1& __obj, _T2 && __new_va
 
 #if _LIBCPP_STD_VER > 14
 
-struct _LIBCPP_TYPE_VIS_ONLY __in_place_tag {};
-template  struct _LIBCPP_TYPE_VIS_ONLY __in_place_type_tag {};
-template  struct _LIBCPP_TYPE_VIS_ONLY __in_place_index_tag {};
-
-struct _LIBCPP_TYPE_VIS_ONLY in_place_tag;
+struct _LIBCPP_TYPE_VIS in_place_t {
+explicit in_place_t() = default;
+};
+inline constexpr in_place_t in_place{};
 
-using in_place_t = in_place_tag(&)(__in_place_tag);
 template 
-using in_place_type_t = in_place_tag(&)(__in_place_type_tag<_Tp>);
-template 
-using in_place_index_t = in_place_tag(&)(__in_place_index_tag<_Nx>);
-
-struct in_place_tag {
-  in_place_tag() = delete;
-private:
-  explicit in_place_tag(__in_place_tag) {}
-
-  friend inline in_place_tag in_place(__in_place_tag __t);
-  template 
-  friend inline in_place_tag in_place(__in_place_type_tag<_Tp>);
-  template 
-  friend inline in_place_tag in_place(__in_place_index_tag<_Nx>);
+struct _LIBCPP_TYPE_VIS in_place_type_t {
+explicit in_place_type_t() = default;
 };
-
-inline in_place_tag in_place(__in_place_tag __t) {
-_LIBCPP_ASSERT(false, "The in_place function cannot be invoked");
-return in_place_tag(__t);
-}
 template 
-inline in_place_tag in_place(__in_place_type_tag<_Tp>) {
-_LIBCPP_ASSERT(false, "The in_place function cannot be invoked");
-return in_place_tag(__in_place_tag{});
-}
-template 
-inline in_place_tag in_place(__in_place_index_tag<_Nx>) {
-_LIBCPP_ASSERT(false, "The in_place function cannot be invoked");
-return in_place_tag(__in_place_tag{});
-}
-
-templatestruct __is_inplace_tag_imp : false_type {};
-template <>struct 
__is_inplace_tag_imp : true_type {};
-templatestruct 
__is_inplace_tag_imp)> : true_type {};
-template  struct 
__is_inplace_tag_imp)> : true_type {};
+inline constexpr in_place_type_t<_Tp> in_place_type{};
 
-template 
-using __is_inplace_tag = __is_inplace_tag_imp>>;
+template 
+struct _LIBCPP_TYPE_VIS in_place_index_t {
+explicit in_place_index_t() = default;
+};
+template 
+inline constexpr in_place_index_t<_Idx> in_place_index{};
 
-template  struct __is_inplace_type_tag_imp : false_type {};
-template  struct 
__is_inplace_type_tag_imp)> : true_type 
{};
+template  struc

[libcxx] r287249 - Test changes for P0504R0 "Revisiting in-place tag types for any/optional/variant". Patch from Casey Carter

2016-11-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Nov 17 13:23:35 2016
New Revision: 287249

URL: http://llvm.org/viewvc/llvm-project?rev=287249&view=rev
Log:
Test changes for P0504R0 "Revisiting in-place tag types for 
any/optional/variant". Patch from Casey Carter

Modified:

libcxx/trunk/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp
libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp

libcxx/trunk/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp
libcxx/trunk/test/std/utilities/utility/utility.inplace/inplace.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp?rev=287249&r1=287248&r2=287249&view=diff
==
--- 
libcxx/trunk/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp 
Thu Nov 17 13:23:35 2016
@@ -40,7 +40,7 @@ void test_in_place_type() {
 assert(Type::count == 0);
 Type::reset();
 {
-any a(std::in_place);
+any a(std::in_place_type);
 
 assert(Type::count == 1);
 assert(Type::copied == 0);
@@ -50,7 +50,7 @@ void test_in_place_type() {
 assert(Type::count == 0);
 Type::reset();
 { // Test that the in_place argument is properly decayed
-any a(std::in_place);
+any a(std::in_place_type);
 
 assert(Type::count == 1);
 assert(Type::copied == 0);
@@ -60,7 +60,7 @@ void test_in_place_type() {
 assert(Type::count == 0);
 Type::reset();
 {
-any a(std::in_place, 101);
+any a(std::in_place_type, 101);
 
 assert(Type::count == 1);
 assert(Type::copied == 0);
@@ -70,7 +70,7 @@ void test_in_place_type() {
 assert(Type::count == 0);
 Type::reset();
 {
-any a(std::in_place, -1, 42, -1);
+any a(std::in_place_type, -1, 42, -1);
 
 assert(Type::count == 1);
 assert(Type::copied == 0);
@@ -86,21 +86,21 @@ void test_in_place_type_tracked() {
 // constructing from a small type should perform no allocations.
 DisableAllocationGuard g(isSmallType()); ((void)g);
 {
-any a(std::in_place);
+any a(std::in_place_type);
 assertArgsMatch(a);
 }
 {
-any a(std::in_place, -1, 42, -1);
+any a(std::in_place_type, -1, 42, -1);
 assertArgsMatch(a);
 }
 // initializer_list constructor tests
 {
-any a(std::in_place, {-1, 42, -1});
+any a(std::in_place_type, {-1, 42, -1});
 assertArgsMatch>(a);
 }
 {
 int x = 42;
-any a(std::in_place, {-1, 42, -1}, x);
+any a(std::in_place_type, {-1, 42, -1}, x);
 assertArgsMatch, int&>(a);
 }
 }
@@ -111,7 +111,7 @@ void test_in_place_type_decayed() {
 {
 using Type = decltype(test_func);
 using DecayT = void(*)();
-any a(std::in_place, test_func);
+any a(std::in_place_type, test_func);
 assert(containsType(a));
 assert(any_cast(a) == test_func);
 }
@@ -119,14 +119,14 @@ void test_in_place_type_decayed() {
 int my_arr[5];
 using Type = int(&)[5];
 using DecayT = int*;
-any a(std::in_place, my_arr);
+any a(std::in_place_type, my_arr);
 assert(containsType(a));
 assert(any_cast(a) == my_arr);
 }
 {
 using Type = int[5];
 using DecayT = int*;
-any a(std::in_place);
+any a(std::in_place_type);
 assert(containsType(a));
 assert(any_cast(a) == nullptr);
 }

Modified: libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp?rev=287249&r1=287248&r2=287249&view=diff
==
--- libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp 
(original)
+++ libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp Thu 
Nov 17 13:23:35 2016
@@ -106,13 +106,12 @@ void test_copy_move_value() {
 }
 }
 
-// Test that any(ValueType&&) is *never* selected for a std::in_place type.
+// Test that any(ValueType&&) is *never* selected for a std::in_place_type_t 
specialization.
 void test_sfinae_constraints() {
 using BadTag = std::in_place_type_t;
 using OKTag = std::in_place_t;
-using OKDecay = std::decay_t;
 // Test that the tag type is properly handled in SFINAE
-BadTag t = std::in_place;
+BadTag t = std::in_place_type;
 OKTag ot = std::in_place;
 {
 std::any a(t);
@@ -124,12 +123,7 @@ void test_sfinae_constr

[PATCH] D26782: [libcxx] [test] Test changes for P0504R0 "Revisiting in-place tag types for any/optional/variant"

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM. This patch misses `any.modifiers/emplace.pass.cpp` but I'll fix that up 
and commit with the libc++ changes!


https://reviews.llvm.org/D26782



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


Re: r287241 - Use unique_ptr for cached tokens for default arguments in C++.

2016-11-17 Thread Richard Smith via cfe-commits
On 17 November 2016 at 09:52, Malcolm Parsons via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: malcolm.parsons
> Date: Thu Nov 17 11:52:58 2016
> New Revision: 287241
>
> URL: http://llvm.org/viewvc/llvm-project?rev=287241&view=rev
> Log:
> Use unique_ptr for cached tokens for default arguments in C++.
>
> Summary:
> This changes pointers to cached tokens for default arguments in C++ from
> raw pointers to unique_ptrs.  There was a fixme in the code where the
> cached tokens are created  about using a smart pointer.
>
> The change is straightforward, though I did have to track down and fix a
> memory corruption caused by the change.  memcpy was being used to copy
> parameter information.  This duplicated the unique_ptr, which led to the
> cached token buffer being deleted prematurely.
>
> Patch by David Tarditi!
>
> Reviewers: malcolm.parsons
>
> Subscribers: arphaman, malcolm.parsons, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D26435
>
> Modified:
> cfe/trunk/include/clang/Parse/Parser.h
> cfe/trunk/include/clang/Sema/DeclSpec.h
> cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
> cfe/trunk/lib/Parse/ParseDecl.cpp
> cfe/trunk/lib/Parse/ParseDeclCXX.cpp
> cfe/trunk/lib/Sema/DeclSpec.cpp
> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>
> Modified: cfe/trunk/include/clang/Parse/Parser.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Parse/Parser.h?rev=287241&r1=287240&r2=287241&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Parse/Parser.h (original)
> +++ cfe/trunk/include/clang/Parse/Parser.h Thu Nov 17 11:52:58 2016
> @@ -1017,8 +1017,8 @@ private:
>/// (C++ [class.mem]p2).
>struct LateParsedDefaultArgument {
>  explicit LateParsedDefaultArgument(Decl *P,
> -   CachedTokens *Toks = nullptr)
> -  : Param(P), Toks(Toks) { }
> +   std::unique_ptr Toks
> = nullptr)
> +  : Param(P), Toks(std::move(Toks)) { }
>
>  /// Param - The parameter declaration for this parameter.
>  Decl *Param;
> @@ -1027,7 +1027,7 @@ private:
>  /// argument expression, not including the '=' or the terminating
>  /// ')' or ','. This will be NULL for parameters that have no
>  /// default argument.
> -CachedTokens *Toks;
> +std::unique_ptr Toks;
>};
>
>/// LateParsedMethodDeclaration - A method declaration inside a class
> that
>
> Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/DeclSpec.h?rev=287241&r1=287240&r2=287241&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
> +++ cfe/trunk/include/clang/Sema/DeclSpec.h Thu Nov 17 11:52:58 2016
> @@ -1188,14 +1188,14 @@ struct DeclaratorChunk {
>  /// declaration of a member function), it will be stored here as a
>  /// sequence of tokens to be parsed once the class definition is
>  /// complete. Non-NULL indicates that there is a default argument.
> -CachedTokens *DefaultArgTokens;
> +std::unique_ptr DefaultArgTokens;
>
>  ParamInfo() = default;
>  ParamInfo(IdentifierInfo *ident, SourceLocation iloc,
>Decl *param,
> -  CachedTokens *DefArgTokens = nullptr)
> +  std::unique_ptr DefArgTokens = nullptr)
>: Ident(ident), IdentLoc(iloc), Param(param),
> -DefaultArgTokens(DefArgTokens) {}
> +DefaultArgTokens(std::move(DefArgTokens)) {}
>};
>
>struct TypeAndRange {
> @@ -1310,10 +1310,8 @@ struct DeclaratorChunk {
>  ///
>  /// This is used in various places for error recovery.
>  void freeParams() {
> -  for (unsigned I = 0; I < NumParams; ++I) {
> -delete Params[I].DefaultArgTokens;
> -Params[I].DefaultArgTokens = nullptr;
> -  }
> +  for (unsigned I = 0; I < NumParams; ++I)
> +Params[I].DefaultArgTokens.reset();
>if (DeleteParams) {
>  delete[] Params;
>  DeleteParams = false;
>
> Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/
> ParseCXXInlineMethods.cpp?rev=287241&r1=287240&r2=287241&view=diff
> 
> ==
> --- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Thu Nov 17 11:52:58 2016
> @@ -319,7 +319,8 @@ void Parser::ParseLexedMethodDeclaration
>  // Introduce the parameter into scope.
>  bool HasUnparsed = Param->hasUnparsedDefaultArg();
>  Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param);
> -if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) {
> +std::unique_ptr Toks = std::move(LM.DefaultArgs[I].
> Toks);
> +if (Toks) {
>// Mark 

[PATCH] D25654: [Sema] Don't perform aggregate initialization for types with explicit constructors

2016-11-17 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

@rsmith ping. This is kind-of blocking making libc++'s tag types not 
constructible from `{}`.


https://reviews.llvm.org/D25654



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


[PATCH] D26773: [analyzer] Refactor recursive symbol reachability check to use symbol_iterator

2016-11-17 Thread Dominic Chen via cfe-commits
ddcc added a comment.

I believe you're correct, the original code terminates early because of the 
short circuit evaluation on line 553, and visits all reachable nodes but 
doesn't recurse on non-SymbolData.


https://reviews.llvm.org/D26773



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


[PATCH] D26773: [analyzer] Refactor recursive symbol reachability check to use symbol_iterator

2016-11-17 Thread Dominic Chen via cfe-commits
ddcc updated this revision to Diff 78392.
ddcc added a comment.

Fix visitation, add early termination, add comments


https://reviews.llvm.org/D26773

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  lib/StaticAnalyzer/Core/ProgramState.cpp


Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -527,32 +527,17 @@
 }
 
 bool ScanReachableSymbols::scan(const SymExpr *sym) {
-  bool wasVisited = !visited.insert(sym).second;
-  if (wasVisited)
-return true;
-
-  if (!visitor.VisitSymbol(sym))
-return false;
+  for (SymExpr::symbol_iterator SI = sym->symbol_begin(),
+SE = sym->symbol_end();
+   SI != SE; ++SI) {
+bool wasVisited = !visited.insert(*SI).second;
+if (wasVisited)
+  continue;
 
-  // TODO: should be rewritten using SymExpr::symbol_iterator.
-  switch (sym->getKind()) {
-case SymExpr::SymbolRegionValueKind:
-case SymExpr::SymbolConjuredKind:
-case SymExpr::SymbolDerivedKind:
-case SymExpr::SymbolExtentKind:
-case SymExpr::SymbolMetadataKind:
-  break;
-case SymExpr::SymbolCastKind:
-  return scan(cast(sym)->getOperand());
-case SymExpr::SymIntExprKind:
-  return scan(cast(sym)->getLHS());
-case SymExpr::IntSymExprKind:
-  return scan(cast(sym)->getRHS());
-case SymExpr::SymSymExprKind: {
-  const SymSymExpr *x = cast(sym);
-  return scan(x->getLHS()) && scan(x->getRHS());
-}
+if (!visitor.VisitSymbol(*SI))
+  return false;
   }
+
   return true;
 }
 
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -824,8 +824,9 @@
 }
 
 /// \class ScanReachableSymbols
-/// A Utility class that allows to visit the reachable symbols using a custom
-/// SymbolVisitor.
+/// A utility class that visits the reachable symbols using a custom
+/// SymbolVisitor. Terminates recursive traversal when the visitor function
+/// returns false.
 class ScanReachableSymbols {
   typedef llvm::DenseSet VisitedItems;
 


Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -527,32 +527,17 @@
 }
 
 bool ScanReachableSymbols::scan(const SymExpr *sym) {
-  bool wasVisited = !visited.insert(sym).second;
-  if (wasVisited)
-return true;
-
-  if (!visitor.VisitSymbol(sym))
-return false;
+  for (SymExpr::symbol_iterator SI = sym->symbol_begin(),
+SE = sym->symbol_end();
+   SI != SE; ++SI) {
+bool wasVisited = !visited.insert(*SI).second;
+if (wasVisited)
+  continue;
 
-  // TODO: should be rewritten using SymExpr::symbol_iterator.
-  switch (sym->getKind()) {
-case SymExpr::SymbolRegionValueKind:
-case SymExpr::SymbolConjuredKind:
-case SymExpr::SymbolDerivedKind:
-case SymExpr::SymbolExtentKind:
-case SymExpr::SymbolMetadataKind:
-  break;
-case SymExpr::SymbolCastKind:
-  return scan(cast(sym)->getOperand());
-case SymExpr::SymIntExprKind:
-  return scan(cast(sym)->getLHS());
-case SymExpr::IntSymExprKind:
-  return scan(cast(sym)->getRHS());
-case SymExpr::SymSymExprKind: {
-  const SymSymExpr *x = cast(sym);
-  return scan(x->getLHS()) && scan(x->getRHS());
-}
+if (!visitor.VisitSymbol(*SI))
+  return false;
   }
+
   return true;
 }
 
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -824,8 +824,9 @@
 }
 
 /// \class ScanReachableSymbols
-/// A Utility class that allows to visit the reachable symbols using a custom
-/// SymbolVisitor.
+/// A utility class that visits the reachable symbols using a custom
+/// SymbolVisitor. Terminates recursive traversal when the visitor function
+/// returns false.
 class ScanReachableSymbols {
   typedef llvm::DenseSet VisitedItems;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26774: [CUDA] Driver changes to support CUDA compilation on MacOS.

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



Comment at: clang/lib/Driver/Driver.cpp:479
+// the device toolchain we create depends on both.
+ToolChain *&CudaTC = ToolChains[CudaTriple.str() + "/" + HostTriple.str()];
+if (!CudaTC) {

sfantao wrote:
> I am not sure I understand why to pair host and device toolchain in the map. 
> The driver can be used to several compilations, but how do these compilation 
> use different host toolchains? Can you give an example of an invocation? 
> Maybe add it to the regression tests bellow. 
> The driver can be used to several compilations, but how do these compilation 
> use different host toolchains? 

I don't know if it's possible to do so when compiling through the command line. 
 But if using clang as a library, you can create a Driver and use it for 
multiple compilations with arbitrary targets.

I am not certain we do this inside of the tree, although there are a few places 
where we create Driver objects, such as lib/Tooling/CompilationDatabase.cpp and 
lib/Tooling/Tooling.cpp.  But also anyone downstream can presumably use clang 
this way.


https://reviews.llvm.org/D26774



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


[PATCH] D26763: [compiler-rt] [asan] Use __SSE2__ (rather than __i686__...) for SSE2 test

2016-11-17 Thread Michał Górny via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287245: [tests] Use __SSE2__ (rather than __i686__...) for 
SSE2 ASAN test (authored by mgorny).

Changed prior to commit:
  https://reviews.llvm.org/D26763?vs=78245&id=78391#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26763

Files:
  compiler-rt/trunk/lib/asan/tests/asan_test.cc


Index: compiler-rt/trunk/lib/asan/tests/asan_test.cc
===
--- compiler-rt/trunk/lib/asan/tests/asan_test.cc
+++ compiler-rt/trunk/lib/asan/tests/asan_test.cc
@@ -692,7 +692,7 @@
   PTHREAD_JOIN(t, 0);
 }
 
-#if defined(__i686__) || defined(__x86_64__)
+#if defined(__SSE2__)
 #include 
 TEST(AddressSanitizer, Store128Test) {
   char *a = Ident((char*)malloc(Ident(12)));


Index: compiler-rt/trunk/lib/asan/tests/asan_test.cc
===
--- compiler-rt/trunk/lib/asan/tests/asan_test.cc
+++ compiler-rt/trunk/lib/asan/tests/asan_test.cc
@@ -692,7 +692,7 @@
   PTHREAD_JOIN(t, 0);
 }
 
-#if defined(__i686__) || defined(__x86_64__)
+#if defined(__SSE2__)
 #include 
 TEST(AddressSanitizer, Store128Test) {
   char *a = Ident((char*)malloc(Ident(12)));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r287244 - ObjC Module: try to make objc module deterministic.

2016-11-17 Thread Manman Ren via cfe-commits
Author: mren
Date: Thu Nov 17 12:41:18 2016
New Revision: 287244

URL: http://llvm.org/viewvc/llvm-project?rev=287244&view=rev
Log:
ObjC Module: try to make objc module deterministic.

Make sure that comparing selectors in DeclarationName does its job.
rdar://problem/28988750

Added:
cfe/trunk/test/Modules/stress-objc.m
Modified:
cfe/trunk/lib/AST/DeclarationName.cpp

Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=287244&r1=287243&r2=287244&view=diff
==
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Thu Nov 17 12:41:18 2016
@@ -95,12 +95,18 @@ int DeclarationName::compare(Declaration
   case DeclarationName::ObjCMultiArgSelector: {
 Selector LHSSelector = LHS.getObjCSelector();
 Selector RHSSelector = RHS.getObjCSelector();
+// getNumArgs for ZeroArgSelector returns 0, but we still need to compare.
+if (LHS.getNameKind() == DeclarationName::ObjCZeroArgSelector &&
+RHS.getNameKind() == DeclarationName::ObjCZeroArgSelector) {
+  return LHSSelector.getAsIdentifierInfo()->getName().compare(
+ RHSSelector.getAsIdentifierInfo()->getName());
+}
 unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs();
 for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) {
   switch (LHSSelector.getNameForSlot(I).compare(
RHSSelector.getNameForSlot(I))) 
{
-  case -1: return true;
-  case 1: return false;
+  case -1: return -1;
+  case 1: return 1;
   default: break;
   }
 }

Added: cfe/trunk/test/Modules/stress-objc.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/stress-objc.m?rev=287244&view=auto
==
--- cfe/trunk/test/Modules/stress-objc.m (added)
+++ cfe/trunk/test/Modules/stress-objc.m Thu Nov 17 12:41:18 2016
@@ -0,0 +1,22 @@
+// RUN: cd %S
+
+// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00.pch 
-fno-pch-timestamp
+// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00_1.pch 
-fno-pch-timestamp
+// RUN: diff %t_c00.pch %t_c00_1.pch
+
+// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00_2.pch 
-fno-pch-timestamp
+// RUN: diff %t_c00.pch %t_c00_2.pch
+
+// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00_3.pch 
-fno-pch-timestamp
+// RUN: diff %t_c00.pch %t_c00_3.pch
+
+// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00_4.pch 
-fno-pch-timestamp
+// RUN: diff %t_c00.pch %t_c00_4.pch
+
+// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00_5.pch 
-fno-pch-timestamp
+// RUN: diff %t_c00.pch %t_c00_5.pch
+
+@protocol NSObject
+- (void)doesNotRecognizeSelector:(SEL)aSelector;
+- (id)forwardingTargetForSelector:(SEL)aSelector;
+@end


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


[PATCH] D26763: [compiler-rt] [asan] Use __SSE2__ (rather than __i686__...) for SSE2 test

2016-11-17 Thread Michał Górny via cfe-commits
mgorny added a comment.

I did, even twice ;-). Thanks.


https://reviews.llvm.org/D26763



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


[PATCH] D26773: [analyzer] Refactor recursive symbol reachability check to use symbol_iterator

2016-11-17 Thread Artem Dergachev via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/ProgramState.cpp:535
+if (!isa(*SI))
+  continue;
 

Hmm, the original code does actually visit non-SymbolData.


https://reviews.llvm.org/D26773



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


[PATCH] D26807: Fix a comment for -fsave-optimization-record

2016-11-17 Thread Adam Nemet via cfe-commits
anemet created this revision.
anemet added a reviewer: hfinkel.
anemet added a subscriber: cfe-commits.

https://reviews.llvm.org/D26807

Files:
  lib/Driver/Tools.cpp


Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6225,7 +6225,7 @@
   Args.hasArg(options::OPT_S))) {
 F = Output.getFilename();
   } else {
-// Use the compilation directory.
+// Use the input filename.
 F = llvm::sys::path::stem(Input.getBaseInput());
 
 // If we're compiling for an offload architecture (i.e. a CUDA device),


Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6225,7 +6225,7 @@
   Args.hasArg(options::OPT_S))) {
 F = Output.getFilename();
   } else {
-// Use the compilation directory.
+// Use the input filename.
 F = llvm::sys::path::stem(Input.getBaseInput());
 
 // If we're compiling for an offload architecture (i.e. a CUDA device),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26773: [analyzer] Refactor recursive symbol reachability check to use symbol_iterator

2016-11-17 Thread Artem Dergachev via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/ProgramState.cpp:542
+if (!visitor.VisitSymbol(*SI))
+  Result = false;
   }

I guess we should break the loop here.


https://reviews.llvm.org/D26773



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


[PATCH] D26794: [OpenCL] Blocks are allowed to capture arrays in OpenCL 2.0 and higher.

2016-11-17 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

I have created a bug to Khronos regarding this, but unfortunately I don't see 
it being progressed yet.
https://cvs.khronos.org/bugzilla/show_bug.cgi?id=15659

The problem here is that I am not sure we should deviate from the ObjC 
implementation because OpenCL blocks are largely taken from Clang ObjC 
implementation. My issue is in particular that it's not clear what the capture 
of array would mean and spec should either state it precisely or disallow using 
this feature at all to avoid costly operations. In ObjC community itself there 
were multiple interpretation of this in the past: 
http://lists.llvm.org/pipermail/cfe-dev/2016-March/047849.html

I am not sure we should go ahead with any implementation without further 
clarifications. I will ping the Khronos bug to see if the documentation can be 
improved.

I think this issue has been seen in the OpenCL conformance tests, but was fixed 
later on?


https://reviews.llvm.org/D26794



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


[PATCH] D26782: [libcxx] [test] Test changes for P0504R0 "Revisiting in-place tag types for any/optional/variant"

2016-11-17 Thread Casey Carter via cfe-commits
CaseyCarter updated this revision to Diff 78379.
CaseyCarter marked an inline comment as done.
CaseyCarter added a comment.

Don't `STATIC_ASSERT`; `static_assert`.


https://reviews.llvm.org/D26782

Files:
  test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp
  test/std/utilities/any/any.class/any.cons/value.pass.cpp
  test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp
  test/std/utilities/utility/utility.inplace/inplace.pass.cpp

Index: test/std/utilities/utility/utility.inplace/inplace.pass.cpp
===
--- test/std/utilities/utility/utility.inplace/inplace.pass.cpp
+++ test/std/utilities/utility/utility.inplace/inplace.pass.cpp
@@ -11,21 +11,24 @@
 
 // 
 
-// struct in_place_tag { in_place_tag() = delete; };
-//
-// using in_place_t = in_place_tag(&)(unspecified);
+// struct in_place_t {
+//   explicit in_place_t() = default;
+// };
+// inline constexpr in_place_t in_place{};
+
 // template 
-// using in_place_type_t = in_place_tag(&)(unspecified);
-// template 
-// using in_place_index_t = in_place_tag(&)(unspecified);
-//
-// in_place_tag in_place(unspecified);
-//
-// template ;
-// in_place_tag in_place(unspecified);
-//
-// template 
-// in_place_tag in_place(unspecified);
+//   struct in_place_type_t {
+// explicit in_place_type_t() = default;
+//   };
+// template 
+//   inline constexpr in_place_type_t in_place_type{};
+
+// template 
+//   struct in_place_index_t {
+// explicit in_place_index_t() = default;
+//   };
+// template 
+//   inline constexpr in_place_index_t in_place_index{};
 
 #include 
 #include 
@@ -34,66 +37,38 @@
 #include "test_macros.h"
 #include "type_id.h"
 
-template 
-struct CheckRet : std::false_type {};
-template 
-struct CheckRet : std::true_type {};
-
-TypeID const* test_fn(std::in_place_t) { return &makeTypeID(); }
-template 
-TypeID const* test_fn(std::in_place_type_t)
-{ return &makeTypeID>(); }
-
-template 
-TypeID const* test_fn(std::in_place_index_t)
-{ return &makeTypeID>(); }
-
-// Concrete test overloads that don't have to be deduced.
-template 
-TypeID const* concrete_test_fn(Tag) {  return &makeTypeID(); }
-
-template 
-bool check_tag_basic() {
-  using RawTp = typename std::remove_reference::type;
-  static_assert(std::is_lvalue_reference::value, "");
-  static_assert(std::is_function::value, "");
-  static_assert(CheckRet::value, "");
-  auto concrete_fn = concrete_test_fn;
-  return test_fn((Tp)std::in_place) == &makeTypeID()
-  && concrete_fn(std::in_place) == &makeTypeID();
+template 
+constexpr bool check_tag(Up) {
+return std::is_same>::value
+&& std::is_same::value;
 }
 
 int main() {
-// test in_place_tag
-{
-static_assert(!std::is_default_constructible::value, "");
-}
 // test in_place_t
 {
 using T = std::in_place_t;
-assert(check_tag_basic());
-assert(test_fn((T)std::in_place) == &makeTypeID());
+static_assert(check_tag(std::in_place));
 }
 // test in_place_type_t
 {
 using T1 = std::in_place_type_t;
 using T2 = std::in_place_type_t;
 using T3 = std::in_place_type_t;
-assert(check_tag_basic());
-assert(check_tag_basic());
-assert(check_tag_basic());
-static_assert(!std::is_same::value && !std::is_same::value, "");
-static_assert(!std::is_same::value, "");
+static_assert(!std::is_same::value && !std::is_same::value);
+static_assert(!std::is_same::value);
+static_assert(check_tag(std::in_place_type));
+static_assert(check_tag(std::in_place_type));
+static_assert(check_tag(std::in_place_type));
 }
 // test in_place_index_t
 {
 using T1 = std::in_place_index_t<0>;
 using T2 = std::in_place_index_t<1>;
 using T3 = std::in_place_index_t(-1)>;
-assert(check_tag_basic());
-assert(check_tag_basic());
-assert(check_tag_basic());
-static_assert(!std::is_same::value && !std::is_same::value, "");
-static_assert(!std::is_same::value, "");
+static_assert(!std::is_same::value && !std::is_same::value);
+static_assert(!std::is_same::value);
+static_assert(check_tag(std::in_place_index<0>));
+static_assert(check_tag(std::in_place_index<1>));
+static_assert(check_tag(std::in_place_index(-1)>));
 }
-}
\ No newline at end of file
+}
Index: test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp
===
--- test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp
+++ test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp
@@ -192,7 +192,6 @@
 Type::reset();
 {
 any a((Type(42)));
-any const& ca = a;
 assert(Type::count == 1);
 assert(Type::copied == 0);
 assert(Type::moved == 1);
Index: te

[PATCH] D26796: [Driver] Use arch type to find compiler-rt libraries (on Linux)

2016-11-17 Thread Michał Górny via cfe-commits
mgorny updated this revision to Diff 78378.
mgorny marked 2 inline comments as done.
mgorny added a comment.

Updated the -print-libgcc-file-name test name. Additionally, I've added another 
subvariant of that test using i686-* target to ensure that the mapping works 
for that function too, in case we ever decide to split it.


https://reviews.llvm.org/D26796

Files:
  lib/Driver/ToolChain.cpp
  test/Driver/Inputs/basic_linux_tree/usr/i686-unknown-linux/lib/.keep
  
test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i686-unknown-linux/4.6.0/crtbegin.o
  test/Driver/linux-ld.c
  test/Driver/nostdlib.c
  test/Driver/print-libgcc-file-name-clangrt.c
  test/Driver/windows-cross.c

Index: test/Driver/windows-cross.c
===
--- test/Driver/windows-cross.c
+++ test/Driver/windows-cross.c
@@ -59,7 +59,7 @@
 // RUN:| FileCheck %s --check-prefix CHECK-SANITIZE-ADDRESS-EXE-X86
 
 // CHECK-SANITIZE-ADDRESS-EXE-X86: "-fsanitize=address"
-// CHECK-SANITIZE-ADDRESS-EXE-X86: "{{.*}}clang_rt.asan_dynamic-i686.lib" "{{.*}}clang_rt.asan_dynamic_runtime_thunk-i686.lib" "--undefined" "___asan_seh_interceptor"
+// CHECK-SANITIZE-ADDRESS-EXE-X86: "{{.*}}clang_rt.asan_dynamic-i386.lib" "{{.*}}clang_rt.asan_dynamic_runtime_thunk-i386.lib" "--undefined" "___asan_seh_interceptor"
 
 // RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link2 -shared -o shared.dll -fsanitize=tsan -x c++ %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix CHECK-SANITIZE-TSAN
Index: test/Driver/print-libgcc-file-name-clangrt.c
===
--- test/Driver/print-libgcc-file-name-clangrt.c
+++ test/Driver/print-libgcc-file-name-clangrt.c
@@ -6,6 +6,12 @@
 // CHECK-CLANGRT-X8664: libclang_rt.builtins-x86_64.a
 
 // RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=i386-pc-linux \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-I386 %s
+// CHECK-CLANGRT-I386: libclang_rt.builtins-i386.a
+
+// Check whether alternate arch values map to the correct library.
+//
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
 // RUN: --target=i686-pc-linux \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-I686 %s
-// CHECK-CLANGRT-I686: libclang_rt.builtins-i686.a
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-I386 %s
Index: test/Driver/nostdlib.c
===
--- test/Driver/nostdlib.c
+++ test/Driver/nostdlib.c
@@ -14,18 +14,18 @@
 // passed down to link line
 // RUN: %clang -no-canonical-prefixes %s -### -Wno-liblto -o %t.o 2>&1 \
 // RUN: -target i686-pc-linux-gnu -nostdlib --rtlib=compiler-rt \
-// RUN: -resource-dir=%S/Inputs/resource_dir -lclang_rt.builtins-i686 \
+// RUN: -resource-dir=%S/Inputs/resource_dir -lclang_rt.builtins-i386 \
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-NOSTDLIB %s
 //
 // RUN: %clang -no-canonical-prefixes %s -### -Wno-liblto -o %t.o 2>&1 \
 // RUN: -target i686-pc-linux-gnu --rtlib=compiler-rt -nostdlib \
-// RUN: -resource-dir=%S/Inputs/resource_dir -lclang_rt.builtins-i686 \
+// RUN: -resource-dir=%S/Inputs/resource_dir -lclang_rt.builtins-i386 \
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-NOSTDLIB %s
 //
 // RUN: %clang -target x86_64-pc-windows-msvc -nostdlib --rtlib=compiler-rt -### -Wno-liblto %s 2>&1 | FileCheck %s -check-prefix CHECK-MSVC-NOSTDLIB
 // RUN: %clang -target x86_64-pc-windows-msvc --rtlib=compiler-rt -nostdlib -### -Wno-liblto %s 2>&1 | FileCheck %s -check-prefix CHECK-MSVC-NOSTDLIB
 //
 // CHECK-LINUX-NOSTDLIB: warning: argument unused during compilation: '--rtlib=compiler-rt'
 // CHECK-LINUX-NOSTDLIB: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-NOSTDLIB-NOT: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.builtins-i686.a"
+// CHECK-LINUX-NOSTDLIB-NOT: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.builtins-i386.a"
 // CHECK-MSVC-NOSTDLIB: warning: argument unused during compilation: '--rtlib=compiler-rt'
Index: test/Driver/linux-ld.c
===
--- test/Driver/linux-ld.c
+++ test/Driver/linux-ld.c
@@ -71,6 +71,27 @@
 // CHECK-LD-RT: libclang_rt.builtins-x86_64.a"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=i686-unknown-linux \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: --rtlib=compiler-rt \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-RT-I686 %s
+// CHECK-LD-RT-I686-NOT: warning:
+// CHECK-LD-RT-I686: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-LD-RT-I686: "--eh-frame-hdr"
+// CHECK-LD-RT-I686: "-m" "elf_i386"
+// CHECK-LD-RT-I686: "-dynamic-linker"
+// CHECK-LD-RT-I686: "{{.*}}/usr/lib/gcc/i686-unknown-linux/4.6.0{{/|}

[PATCH] D26435: Use unique_ptr for cached tokens for default arguments in C++.

2016-11-17 Thread Malcolm Parsons via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287241: Use unique_ptr for cached tokens for default 
arguments in C++. (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D26435?vs=78375&id=78380#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26435

Files:
  cfe/trunk/include/clang/Parse/Parser.h
  cfe/trunk/include/clang/Sema/DeclSpec.h
  cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Parse/ParseDeclCXX.cpp
  cfe/trunk/lib/Sema/DeclSpec.cpp
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Index: cfe/trunk/include/clang/Sema/DeclSpec.h
===
--- cfe/trunk/include/clang/Sema/DeclSpec.h
+++ cfe/trunk/include/clang/Sema/DeclSpec.h
@@ -1188,14 +1188,14 @@
 /// declaration of a member function), it will be stored here as a
 /// sequence of tokens to be parsed once the class definition is
 /// complete. Non-NULL indicates that there is a default argument.
-CachedTokens *DefaultArgTokens;
+std::unique_ptr DefaultArgTokens;
 
 ParamInfo() = default;
 ParamInfo(IdentifierInfo *ident, SourceLocation iloc,
   Decl *param,
-  CachedTokens *DefArgTokens = nullptr)
+  std::unique_ptr DefArgTokens = nullptr)
   : Ident(ident), IdentLoc(iloc), Param(param),
-DefaultArgTokens(DefArgTokens) {}
+DefaultArgTokens(std::move(DefArgTokens)) {}
   };
 
   struct TypeAndRange {
@@ -1310,10 +1310,8 @@
 ///
 /// This is used in various places for error recovery.
 void freeParams() {
-  for (unsigned I = 0; I < NumParams; ++I) {
-delete Params[I].DefaultArgTokens;
-Params[I].DefaultArgTokens = nullptr;
-  }
+  for (unsigned I = 0; I < NumParams; ++I)
+Params[I].DefaultArgTokens.reset();
   if (DeleteParams) {
 delete[] Params;
 DeleteParams = false;
Index: cfe/trunk/include/clang/Parse/Parser.h
===
--- cfe/trunk/include/clang/Parse/Parser.h
+++ cfe/trunk/include/clang/Parse/Parser.h
@@ -1017,17 +1017,17 @@
   /// (C++ [class.mem]p2).
   struct LateParsedDefaultArgument {
 explicit LateParsedDefaultArgument(Decl *P,
-   CachedTokens *Toks = nullptr)
-  : Param(P), Toks(Toks) { }
+   std::unique_ptr Toks = nullptr)
+  : Param(P), Toks(std::move(Toks)) { }
 
 /// Param - The parameter declaration for this parameter.
 Decl *Param;
 
 /// Toks - The sequence of tokens that comprises the default
 /// argument expression, not including the '=' or the terminating
 /// ')' or ','. This will be NULL for parameters that have no
 /// default argument.
-CachedTokens *Toks;
+std::unique_ptr Toks;
   };
 
   /// LateParsedMethodDeclaration - A method declaration inside a class that
Index: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
===
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp
@@ -2039,7 +2039,7 @@
 LateMethod->DefaultArgs.reserve(FTI.NumParams);
 for (unsigned ParamIdx = 0; ParamIdx < FTI.NumParams; ++ParamIdx)
   LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument(
-FTI.Params[ParamIdx].Param, FTI.Params[ParamIdx].DefaultArgTokens));
+FTI.Params[ParamIdx].Param, std::move(FTI.Params[ParamIdx].DefaultArgTokens)));
   }
 }
 
Index: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
===
--- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
+++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
@@ -319,7 +319,8 @@
 // Introduce the parameter into scope.
 bool HasUnparsed = Param->hasUnparsedDefaultArg();
 Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param);
-if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) {
+std::unique_ptr Toks = std::move(LM.DefaultArgs[I].Toks);
+if (Toks) {
   // Mark the end of the default argument so that we know when to stop when
   // we parse it later on.
   Token LastDefaultArgToken = Toks->back();
@@ -377,9 +378,6 @@
 
   if (Tok.is(tok::eof) && Tok.getEofData() == Param)
 ConsumeAnyToken();
-
-  delete Toks;
-  LM.DefaultArgs[I].Toks = nullptr;
 } else if (HasUnparsed) {
   assert(Param->hasInheritedDefaultArg());
   FunctionDecl *Old = cast(LM.Method)->getPreviousDecl();
Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -6022,7 +6022,7 @@
 
 // DefArgToks is used when the parsing of default arguments needs
 // to be delayed.
-CachedTokens *DefArgToks = nullptr;
+std::unique_ptr DefArgToks;
 
 // If no

[PATCH] D26782: [libcxx] [test] Test changes for P0504R0 "Revisiting in-place tag types for any/optional/variant"

2016-11-17 Thread Casey Carter via cfe-commits
CaseyCarter marked an inline comment as done.
CaseyCarter added a comment.

> Do these tests pass with the current `` implementation, or will they 
> have to wait?

These tests **do not pass** without making the changes required in P0504R0 to 
`` and ``.  (Interestingly  is unaffected; its use of 
`in_place_t` and `in_place` is source-compatible despite the changed 
definitions of those names.) I would have made those changes as well, but my 
request for permission to contribute changes to non-test code hasn't yet 
returned from the void into which I cast it. If neither of you get around to 
it, I may put an hour into it over the weekend.




Comment at: test/std/utilities/utility/utility.inplace/inplace.pass.cpp:40
 
-template 
-struct CheckRet : std::false_type {};
-template 
-struct CheckRet : std::true_type {};
+#define STATIC_ASSERT(...) static_assert((__VA_ARGS__), #__VA_ARGS__)
 

mclow.lists wrote:
> Please just use `static_assert(x)` instead.  Since this is C++1z only, you 
> don't need to supply a message. If the test fails, the compiler will give you 
> file and line #.
> 
> If I see an all caps `STATIC_ASSERT`, then my first bit of research has to be 
> "how is this different from `static_assert`?"
> 
`static_assert(false);` in Visual C++ diagnoses with the incredibly informative:

> inplace.pass.cpp(59): error C2607: static assertion failed

so I've developed this habit which inadvertently leaked into the diff. Fixing.


https://reviews.llvm.org/D26782



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


r287241 - Use unique_ptr for cached tokens for default arguments in C++.

2016-11-17 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Thu Nov 17 11:52:58 2016
New Revision: 287241

URL: http://llvm.org/viewvc/llvm-project?rev=287241&view=rev
Log:
Use unique_ptr for cached tokens for default arguments in C++.

Summary:
This changes pointers to cached tokens for default arguments in C++ from raw 
pointers to unique_ptrs.  There was a fixme in the code where the cached tokens 
are created  about using a smart pointer.

The change is straightforward, though I did have to track down and fix a memory 
corruption caused by the change.  memcpy was being used to copy parameter 
information.  This duplicated the unique_ptr, which led to the cached token 
buffer being deleted prematurely.

Patch by David Tarditi!

Reviewers: malcolm.parsons

Subscribers: arphaman, malcolm.parsons, cfe-commits

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

Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=287241&r1=287240&r2=287241&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Nov 17 11:52:58 2016
@@ -1017,8 +1017,8 @@ private:
   /// (C++ [class.mem]p2).
   struct LateParsedDefaultArgument {
 explicit LateParsedDefaultArgument(Decl *P,
-   CachedTokens *Toks = nullptr)
-  : Param(P), Toks(Toks) { }
+   std::unique_ptr Toks = 
nullptr)
+  : Param(P), Toks(std::move(Toks)) { }
 
 /// Param - The parameter declaration for this parameter.
 Decl *Param;
@@ -1027,7 +1027,7 @@ private:
 /// argument expression, not including the '=' or the terminating
 /// ')' or ','. This will be NULL for parameters that have no
 /// default argument.
-CachedTokens *Toks;
+std::unique_ptr Toks;
   };
 
   /// LateParsedMethodDeclaration - A method declaration inside a class that

Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=287241&r1=287240&r2=287241&view=diff
==
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Thu Nov 17 11:52:58 2016
@@ -1188,14 +1188,14 @@ struct DeclaratorChunk {
 /// declaration of a member function), it will be stored here as a
 /// sequence of tokens to be parsed once the class definition is
 /// complete. Non-NULL indicates that there is a default argument.
-CachedTokens *DefaultArgTokens;
+std::unique_ptr DefaultArgTokens;
 
 ParamInfo() = default;
 ParamInfo(IdentifierInfo *ident, SourceLocation iloc,
   Decl *param,
-  CachedTokens *DefArgTokens = nullptr)
+  std::unique_ptr DefArgTokens = nullptr)
   : Ident(ident), IdentLoc(iloc), Param(param),
-DefaultArgTokens(DefArgTokens) {}
+DefaultArgTokens(std::move(DefArgTokens)) {}
   };
 
   struct TypeAndRange {
@@ -1310,10 +1310,8 @@ struct DeclaratorChunk {
 ///
 /// This is used in various places for error recovery.
 void freeParams() {
-  for (unsigned I = 0; I < NumParams; ++I) {
-delete Params[I].DefaultArgTokens;
-Params[I].DefaultArgTokens = nullptr;
-  }
+  for (unsigned I = 0; I < NumParams; ++I)
+Params[I].DefaultArgTokens.reset();
   if (DeleteParams) {
 delete[] Params;
 DeleteParams = false;

Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=287241&r1=287240&r2=287241&view=diff
==
--- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Thu Nov 17 11:52:58 2016
@@ -319,7 +319,8 @@ void Parser::ParseLexedMethodDeclaration
 // Introduce the parameter into scope.
 bool HasUnparsed = Param->hasUnparsedDefaultArg();
 Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param);
-if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) {
+std::unique_ptr Toks = std::move(LM.DefaultArgs[I].Toks);
+if (Toks) {
   // Mark the end of the default argument so that we know when to stop when
   // we parse it later on.
   Token LastDefaultArgToken = Toks->back();
@@ -377,9 +378,6 @@ void Parser::ParseLexedMethodDeclaration
 
   if (Tok.is(tok::eof) && Tok.getEofData() == Param)
 ConsumeAnyToken();
-
-  delete Toks;
-

  1   2   >