Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

2016-02-21 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: lib/Sema/SemaDeclAttr.cpp:5046
@@ +5045,3 @@
+  if (D->hasAttr()) {
+S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers)
+<< D->getSourceRange();

Anastasia wrote:
> Yes, I think attribute would make more sense.
Already changed to attribute.


Comment at: lib/Sema/SemaDeclAttr.cpp:5061
@@ +5060,3 @@
+  if (S.getLangOpts().OpenCLVersion < 200 || DeclTy->isPipeType()) {
+S.Diag(Attr.getLoc(), diag::err_opencl_invalid_read_write)
+<< PDecl->getType() << DeclTy->isImageType();

Anastasia wrote:
> Yes, w/o this attribute it would assume default access qualifier i.e. 
> read_only. So I agree to point to the attribute here too.
Already done.


http://reviews.llvm.org/D16040



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


Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-21 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 48648.

http://reviews.llvm.org/D17436

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCL/invalid-block.cl

Index: test/SemaOpenCL/invalid-block.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-block.cl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s
+
+int (^BlkVariadic)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed in OpenCL}}
+  return 0;
+};
+
+typedef int (^BlkInt)(int);
+void f1(int i) {
+  BlkInt B1 = ^int(int I) {return 1;};
+  BlkInt B2 = ^int(int I) {return 2;};
+  BlkInt Arr[] = {B1, B2}; // expected-error {{array of block type is invalid in OpenCL}}
+  int tmp = i ? B1(i)  // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
+  : B2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
+}
+
+void f2(BlkInt *BlockPtr) {
+  BlkInt B = ^int(int I) {return 1;};
+  BlkInt *P =  // expected-error {{invalid argument type 'BlkInt' (aka 'int (^)(int)') to unary expression}}
+  B = *BlockPtr;  // expected-error {{dereferencing pointer of type '__generic BlkInt *' (aka 'int (^__generic *)(int)') is not allowed in OpenCL}}
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2175,6 +2175,13 @@
 Diag(Loc, diag::warn_vla_used);
   }
 
+  // OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
+  if (getLangOpts().OpenCLVersion >= 200 &&
+  Context.getBaseElementType(T)->isBlockPointerType()) {
+Diag(Loc, diag::err_opencl_invalid_block_array);
+return QualType();
+  }
+
   return T;
 }
 
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -6440,6 +6440,18 @@
   return OpenCLConvertScalarsToVectors(S, LHS, RHS, CondTy, QuestionLoc);
 }
 
+/// \brief Return true if the Expr is block type
+static bool checkBlockType(Sema , const Expr *E) {
+  if (const CallExpr *CE = dyn_cast(E)) {
+QualType Ty = CE->getCallee()->getType();
+if (Ty->isBlockPointerType()) {
+  S.Diag(E->getExprLoc(), diag::err_opencl_ternary_with_block);
+  return true;
+}
+  }
+  return false;
+}
+
 /// Note that LHS is not null here, even if this is the gnu "x ?: y" extension.
 /// In that case, LHS = cond.
 /// C99 6.5.15
@@ -6489,6 +6501,13 @@
   QualType LHSTy = LHS.get()->getType();
   QualType RHSTy = RHS.get()->getType();
 
+  // OpenCL v2.0 s6.12.5 - Blocks cannot be used as expressions of the ternary
+  // selection operator (?:).
+  if (getLangOpts().OpenCLVersion >= 200) {
+if (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get()))
+  return QualType();
+  }
+
   // If both operands have arithmetic type, do the usual arithmetic conversions
   // to find a common type: C99 6.5.15p3,5.
   if (LHSTy->isArithmeticType() && RHSTy->isArithmeticType()) {
@@ -10237,6 +10256,16 @@
   // If the operand has type "type", the result has type "pointer to type".
   if (op->getType()->isObjCObjectType())
 return Context.getObjCObjectPointerType(op->getType());
+
+  // OpenCL v2.0 s6.12.5 - The unary operators & cannot be used with a block.
+  if (getLangOpts().OpenCLVersion >= 200) {
+if (OrigOp.get()->getType()->isBlockPointerType()) {
+  Diag(OpLoc, diag::err_typecheck_unary_expr) << OrigOp.get()->getType()
+  << op->getSourceRange();
+  return QualType();
+}
+  }
+
   return Context.getPointerType(op->getType());
 }
 
@@ -10278,7 +10307,15 @@
   }
 
   if (const PointerType *PT = OpTy->getAs())
+  {
 Result = PT->getPointeeType();
+// OpenCL v2.0 s6.12.5 - The unary operators * cannot be used with a block.
+if (S.getLangOpts().OpenCLVersion >= 200 && Result->isBlockPointerType()) {
+  S.Diag(OpLoc, diag::err_opencl_dereferencing) << OpTy
+<< Op->getSourceRange();
+  return QualType();
+}
+  }
   else if (const ObjCObjectPointerType *OPT =
  OpTy->getAs())
 Result = OPT->getPointeeType();
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -6708,6 +6708,19 @@
 NewVD->setInvalidDecl();
 return;
   }
+
+  // OpenCL v2.0 s6.12.5 - Blocks with variadic arguments are not supported.
+  if (LangOpts.OpenCLVersion >= 200 && T->isBlockPointerType()) {
+const BlockPointerType *BlkTy = T->getAs();
+const FunctionProtoType *FTy =
+BlkTy->getPointeeType()->getAs();
+if (FTy->isVariadic()) {
+  Diag(NewVD->getLocation(), 

Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-21 Thread Xiuli PAN via cfe-commits
pxli168 marked 11 inline comments as done.
pxli168 added a comment.

Block is an OpenCL v2.0 feature, I think all test should be handled only for 
CL2.0 or newer version.



Comment at: lib/Sema/SemaDecl.cpp:6714
@@ +6713,3 @@
+  // supported in OpenCL C: Blocks with variadic arguments.
+  if (getLangOpts().OpenCL && LangOpts.OpenCLVersion >= 200 &&
+  T->isBlockPointerType()) {

Anastasia wrote:
> getLangOpts() -> LangOpts
> 
> Could you remove 'LangOpts.OpenCLVersion >= 200' because we can also enable 
> Blocks with -fblocks flag.
But this is a OpenCL v2.0 restriction, if we do not check about OpenCL version 
it seems meaningless.


Comment at: lib/Sema/SemaExpr.cpp:6525
@@ +6524,3 @@
+// should output error for both LHS and RHS, use | instead ||
+if (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get()))
+  return QualType();

Anastasia wrote:
> I suggest to unify with another check for OpenCL on line 6497 to have OpenCL 
> bits all in one place.
It seems move it to there may change the order of checking condition first.


Comment at: test/SemaOpenCL/invalid-block.cl:16
@@ +15,3 @@
+
+void f2(BlkInt *BlockPtr) {
+  BlkInt B = ^int(int I) {return 1;};

Anastasia wrote:
> Actually I think pointers to blocks have to be disallowed too, but spec 
> doesn't mention that although it forbids the dereferencing.
> 
> I will submit a bug to Khronos to clarify this.
I think it is reasonable, please add me in cc list. I will try to make a change 
here. But this may make deference test case hard to write.

BTW, the qualifier to workgroup pipe builtin functions is resolved by 
https://cvs.khronos.org/bugzilla/show_bug.cgi?id=15541.



http://reviews.llvm.org/D17436



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


Re: r261506 - Fix PR24473 : Teach clang to remember to substitute into member variable templates referred to within dependent qualified ids.

2016-02-21 Thread Richard Smith via cfe-commits
On 21 Feb 2016 8:21 p.m., "Faisal Vali"  wrote:
>
> On Sun, Feb 21, 2016 at 10:06 PM, Richard Smith 
wrote:
> > On 21 Feb 2016 6:29 p.m., "Faisal Vali via cfe-commits"
> >  wrote:
> >>
> >> Author: faisalv
> >> Date: Sun Feb 21 20:24:29 2016
> >> New Revision: 261506
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=261506=rev
> >> Log:
> >> Fix PR24473 : Teach clang to remember to substitute into member
variable
> >> templates referred to within dependent qualified ids.
> >>
> >> In passing also fix a semi-related bug that allows access to variable
> >> templates through member access notation.
> >>
> >>
> >> Modified:
> >> cfe/trunk/lib/Sema/SemaExprMember.cpp
> >> cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
> >>
> >> Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
> >> URL:
> >>
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=261506=261505=261506=diff
> >>
> >>
==
> >> --- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
> >> +++ cfe/trunk/lib/Sema/SemaExprMember.cpp Sun Feb 21 20:24:29 2016
> >> @@ -902,6 +902,32 @@ static bool IsInFnTryBlockHandler(const
> >>return false;
> >>  }
> >>
> >> +static VarDecl *
> >> +getVarTemplateSpecialization(Sema , VarTemplateDecl *VarTempl,
> >> +  const TemplateArgumentListInfo *TemplateArgs,
> >> +  const DeclarationNameInfo ,
> >> +  SourceLocation TemplateKWLoc) {
> >> +
> >> +  if (!TemplateArgs) {
> >> +S.Diag(MemberNameInfo.getBeginLoc(), diag::err_template_decl_ref)
> >> +<< /*Variable template*/ 1 << MemberNameInfo.getName()
> >> +<< MemberNameInfo.getSourceRange();
> >> +
> >> +S.Diag(VarTempl->getLocation(), diag::note_template_decl_here);
> >> +
> >> +return nullptr;
> >> +  }
> >> +  DeclResult VDecl = S.CheckVarTemplateId(
> >> +  VarTempl, TemplateKWLoc, MemberNameInfo.getLoc(),
*TemplateArgs);
> >> +  if (VDecl.isInvalid())
> >> +return nullptr;
> >> +  VarDecl *Var = cast(VDecl.get());
> >> +  if (!Var->getTemplateSpecializationKind())
> >> +Var->setTemplateSpecializationKind(TSK_ImplicitInstantiation,
> >> +   MemberNameInfo.getLoc());
> >> +  return Var;
> >> +}
> >> +
> >>  ExprResult
> >>  Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
> >> SourceLocation OpLoc, bool IsArrow,
> >> @@ -1069,9 +1095,20 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
> >>// Handle the implicit-member-access case.
> >>if (!BaseExpr) {
> >>  // If this is not an instance member, convert to a non-member
access.
> >> -if (!MemberDecl->isCXXInstanceMember())
> >> +if (!MemberDecl->isCXXInstanceMember()) {
> >> +  // If this is a variable template, get the instantiated variable
> >> +  // declaration corresponding to the supplied template arguments
> >> +  // (while emitting diagnostics as necessary) that will be
> >> referenced
> >> +  // by this expression.
> >> +  if (isa(MemberDecl)) {
> >> +MemberDecl = getVarTemplateSpecialization(
> >> +*this, cast(MemberDecl), TemplateArgs,
> >> +R.getLookupNameInfo(), TemplateKWLoc);
> >> +if (!MemberDecl)
> >> +  return ExprError();
> >> +  }
> >>return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(),
> >> MemberDecl);
> >
> > Does this properly preserve the template argument list as written?
> >
>
> Shouldn't it? Since it passes on the passed in template argument list
> (that I'm assuming is preserved) to CheckVarTemplateId?

None of the three arguments passed to BuildDeclarationNameExpr references
the template argument list as written. Passing it to CheckVarTemplateId is
insufficient -- that can't preserve the template arguments from each use,
because it produces the same result for all uses.

> Perhaps you have an example in mind?
>
> Thanks!
>
> >> -
> >> +}
> >>  SourceLocation Loc = R.getNameLoc();
> >>  if (SS.getRange().isValid())
> >>Loc = SS.getRange().getBegin();
> >> @@ -1127,6 +1164,15 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
> >> TemplateKWLoc, Enum, FoundDecl,
> >> MemberNameInfo,
> >> Enum->getType(), VK_RValue, OK_Ordinary);
> >>}
> >> +  if (VarTemplateDecl *VarTempl =
dyn_cast(MemberDecl))
> >> {
> >> +if (VarDecl *Var = getVarTemplateSpecialization(
> >> +*this, VarTempl, TemplateArgs, MemberNameInfo,
> >> TemplateKWLoc))
> >> +  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc,
> >> SS,
> >> + TemplateKWLoc, Var, FoundDecl,
> >> MemberNameInfo,
> >> + Var->getType().getNonReferenceType(),
> >> VK_LValue,
> >> + 

Re: [PATCH] D16928: [OpenCL] Apply missing restrictions for Blocks in OpenCL v2.0

2016-02-21 Thread Xiuli PAN via cfe-commits
pxli168 requested changes to this revision.
pxli168 added a comment.
This revision now requires changes to proceed.

It seems this patch will check block for CL1.2 or eailer? But the spec 
reference is for OpenCL v2.0.


http://reviews.llvm.org/D16928



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


r261512 - Addressing review comments for r261163.

2016-02-21 Thread Manman Ren via cfe-commits
Author: mren
Date: Sun Feb 21 22:47:24 2016
New Revision: 261512

URL: http://llvm.org/viewvc/llvm-project?rev=261512=rev
Log:
Addressing review comments for r261163.

Use "strict" instead of "nopartial". Also make strictly not-introduced
share the same diagnostics as Obsolete and Unavailable.

rdar://23791325

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/AttributeList.h
cfe/trunk/include/clang/Sema/DelayedDiagnostic.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/DelayedDiagnostic.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/attr-availability-macosx.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=261512=261511=261512=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Feb 21 22:47:24 2016
@@ -451,7 +451,7 @@ def Availability : InheritableAttr {
   let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
-  BoolArgument<"nopartial">];
+  BoolArgument<"strict">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=261512=261511=261512=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Sun Feb 21 22:47:24 2016
@@ -685,20 +685,21 @@ are:
   Apple's watchOS operating system.  The minimum deployment target is 
specified by
   the ``-mwatchos-version-min=*version*`` command-line argument.
 
-An optional nopartial can be placed after the platform name.
-With the optional nopartial, when deploying back to a platform version prior to
-when the declaration was introduced, Clang emits an error specifying that the
-function is not introduced yet.
-
-Without the optional nopartial, a declaration can be used even when deploying 
back
-to a platform version prior to when the declaration was introduced.  When this
-happens, the declaration is `weakly linked
+A declaration can typically be used even when deploying back to a platform
+version prior to when the declaration was introduced.  When this happens, the
+declaration is `weakly linked
 
`_,
 as if the ``weak_import`` attribute were added to the declaration.  A
 weakly-linked declaration may or may not be present a run-time, and a program
 can determine whether the declaration is present by checking whether the
 address of that declaration is non-NULL.
 
+The flag ``strict`` disallows using API when deploying back to a
+platform version prior to when the declaration was introduced.  An
+attempt to use such API before its introduction causes a hard error.
+Weakly-linking is almost always a better API choice, since it allows
+users to query availability at runtime.
+
 If there are multiple declarations of the same entity, the availability
 attributes must either match on a per-platform basis or later
 declarations must not have availability attributes for that

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=261512=261511=261512=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Sun Feb 21 22:47:24 2016
@@ -87,7 +87,6 @@ def DeprecatedAttributes : DiagGroup<"de
 def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
 def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
 def PartialAvailability : DiagGroup<"partial-availability">;
-def NotYetIntroducedDeclarations : 
DiagGroup<"not-yet-introduced-declarations">;
 def DeprecatedImplementations :DiagGroup<"deprecated-implementations">;
 def DeprecatedIncrementBool : DiagGroup<"deprecated-increment-bool">;
 def DeprecatedRegister : DiagGroup<"deprecated-register">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 

Re: r261506 - Fix PR24473 : Teach clang to remember to substitute into member variable templates referred to within dependent qualified ids.

2016-02-21 Thread Faisal Vali via cfe-commits
On Sun, Feb 21, 2016 at 10:06 PM, Richard Smith  wrote:
> On 21 Feb 2016 6:29 p.m., "Faisal Vali via cfe-commits"
>  wrote:
>>
>> Author: faisalv
>> Date: Sun Feb 21 20:24:29 2016
>> New Revision: 261506
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=261506=rev
>> Log:
>> Fix PR24473 : Teach clang to remember to substitute into member variable
>> templates referred to within dependent qualified ids.
>>
>> In passing also fix a semi-related bug that allows access to variable
>> templates through member access notation.
>>
>>
>> Modified:
>> cfe/trunk/lib/Sema/SemaExprMember.cpp
>> cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=261506=261505=261506=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExprMember.cpp Sun Feb 21 20:24:29 2016
>> @@ -902,6 +902,32 @@ static bool IsInFnTryBlockHandler(const
>>return false;
>>  }
>>
>> +static VarDecl *
>> +getVarTemplateSpecialization(Sema , VarTemplateDecl *VarTempl,
>> +  const TemplateArgumentListInfo *TemplateArgs,
>> +  const DeclarationNameInfo ,
>> +  SourceLocation TemplateKWLoc) {
>> +
>> +  if (!TemplateArgs) {
>> +S.Diag(MemberNameInfo.getBeginLoc(), diag::err_template_decl_ref)
>> +<< /*Variable template*/ 1 << MemberNameInfo.getName()
>> +<< MemberNameInfo.getSourceRange();
>> +
>> +S.Diag(VarTempl->getLocation(), diag::note_template_decl_here);
>> +
>> +return nullptr;
>> +  }
>> +  DeclResult VDecl = S.CheckVarTemplateId(
>> +  VarTempl, TemplateKWLoc, MemberNameInfo.getLoc(), *TemplateArgs);
>> +  if (VDecl.isInvalid())
>> +return nullptr;
>> +  VarDecl *Var = cast(VDecl.get());
>> +  if (!Var->getTemplateSpecializationKind())
>> +Var->setTemplateSpecializationKind(TSK_ImplicitInstantiation,
>> +   MemberNameInfo.getLoc());
>> +  return Var;
>> +}
>> +
>>  ExprResult
>>  Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
>> SourceLocation OpLoc, bool IsArrow,
>> @@ -1069,9 +1095,20 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
>>// Handle the implicit-member-access case.
>>if (!BaseExpr) {
>>  // If this is not an instance member, convert to a non-member access.
>> -if (!MemberDecl->isCXXInstanceMember())
>> +if (!MemberDecl->isCXXInstanceMember()) {
>> +  // If this is a variable template, get the instantiated variable
>> +  // declaration corresponding to the supplied template arguments
>> +  // (while emitting diagnostics as necessary) that will be
>> referenced
>> +  // by this expression.
>> +  if (isa(MemberDecl)) {
>> +MemberDecl = getVarTemplateSpecialization(
>> +*this, cast(MemberDecl), TemplateArgs,
>> +R.getLookupNameInfo(), TemplateKWLoc);
>> +if (!MemberDecl)
>> +  return ExprError();
>> +  }
>>return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(),
>> MemberDecl);
>
> Does this properly preserve the template argument list as written?
>

Shouldn't it? Since it passes on the passed in template argument list
(that I'm assuming is preserved) to CheckVarTemplateId?
Perhaps you have an example in mind?

Thanks!

>> -
>> +}
>>  SourceLocation Loc = R.getNameLoc();
>>  if (SS.getRange().isValid())
>>Loc = SS.getRange().getBegin();
>> @@ -1127,6 +1164,15 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
>> TemplateKWLoc, Enum, FoundDecl,
>> MemberNameInfo,
>> Enum->getType(), VK_RValue, OK_Ordinary);
>>}
>> +  if (VarTemplateDecl *VarTempl = dyn_cast(MemberDecl))
>> {
>> +if (VarDecl *Var = getVarTemplateSpecialization(
>> +*this, VarTempl, TemplateArgs, MemberNameInfo,
>> TemplateKWLoc))
>> +  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc,
>> SS,
>> + TemplateKWLoc, Var, FoundDecl,
>> MemberNameInfo,
>> + Var->getType().getNonReferenceType(),
>> VK_LValue,
>> + OK_Ordinary);
>> +return ExprError();
>> +  }
>>
>>// We found something that we didn't expect. Complain.
>>if (isa(MemberDecl))
>>
>> Modified: cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp?rev=261506=261505=261506=diff
>>
>> ==
>> --- cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
>> (original)
>> +++ 

Re: r261506 - Fix PR24473 : Teach clang to remember to substitute into member variable templates referred to within dependent qualified ids.

2016-02-21 Thread Richard Smith via cfe-commits
On 21 Feb 2016 6:29 p.m., "Faisal Vali via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:
>
> Author: faisalv
> Date: Sun Feb 21 20:24:29 2016
> New Revision: 261506
>
> URL: http://llvm.org/viewvc/llvm-project?rev=261506=rev
> Log:
> Fix PR24473 : Teach clang to remember to substitute into member variable
templates referred to within dependent qualified ids.
>
> In passing also fix a semi-related bug that allows access to variable
templates through member access notation.
>
>
> Modified:
> cfe/trunk/lib/Sema/SemaExprMember.cpp
> cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=261506=261505=261506=diff
>
==
> --- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprMember.cpp Sun Feb 21 20:24:29 2016
> @@ -902,6 +902,32 @@ static bool IsInFnTryBlockHandler(const
>return false;
>  }
>
> +static VarDecl *
> +getVarTemplateSpecialization(Sema , VarTemplateDecl *VarTempl,
> +  const TemplateArgumentListInfo *TemplateArgs,
> +  const DeclarationNameInfo ,
> +  SourceLocation TemplateKWLoc) {
> +
> +  if (!TemplateArgs) {
> +S.Diag(MemberNameInfo.getBeginLoc(), diag::err_template_decl_ref)
> +<< /*Variable template*/ 1 << MemberNameInfo.getName()
> +<< MemberNameInfo.getSourceRange();
> +
> +S.Diag(VarTempl->getLocation(), diag::note_template_decl_here);
> +
> +return nullptr;
> +  }
> +  DeclResult VDecl = S.CheckVarTemplateId(
> +  VarTempl, TemplateKWLoc, MemberNameInfo.getLoc(), *TemplateArgs);
> +  if (VDecl.isInvalid())
> +return nullptr;
> +  VarDecl *Var = cast(VDecl.get());
> +  if (!Var->getTemplateSpecializationKind())
> +Var->setTemplateSpecializationKind(TSK_ImplicitInstantiation,
> +   MemberNameInfo.getLoc());
> +  return Var;
> +}
> +
>  ExprResult
>  Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
> SourceLocation OpLoc, bool IsArrow,
> @@ -1069,9 +1095,20 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
>// Handle the implicit-member-access case.
>if (!BaseExpr) {
>  // If this is not an instance member, convert to a non-member access.
> -if (!MemberDecl->isCXXInstanceMember())
> +if (!MemberDecl->isCXXInstanceMember()) {
> +  // If this is a variable template, get the instantiated variable
> +  // declaration corresponding to the supplied template arguments
> +  // (while emitting diagnostics as necessary) that will be
referenced
> +  // by this expression.
> +  if (isa(MemberDecl)) {
> +MemberDecl = getVarTemplateSpecialization(
> +*this, cast(MemberDecl), TemplateArgs,
> +R.getLookupNameInfo(), TemplateKWLoc);
> +if (!MemberDecl)
> +  return ExprError();
> +  }
>return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(),
MemberDecl);

Does this properly preserve the template argument list as written?

> -
> +}
>  SourceLocation Loc = R.getNameLoc();
>  if (SS.getRange().isValid())
>Loc = SS.getRange().getBegin();
> @@ -1127,6 +1164,15 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
> TemplateKWLoc, Enum, FoundDecl,
MemberNameInfo,
> Enum->getType(), VK_RValue, OK_Ordinary);
>}
> +  if (VarTemplateDecl *VarTempl = dyn_cast(MemberDecl))
{
> +if (VarDecl *Var = getVarTemplateSpecialization(
> +*this, VarTempl, TemplateArgs, MemberNameInfo,
TemplateKWLoc))
> +  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc,
SS,
> + TemplateKWLoc, Var, FoundDecl,
MemberNameInfo,
> + Var->getType().getNonReferenceType(),
VK_LValue,
> + OK_Ordinary);
> +return ExprError();
> +  }
>
>// We found something that we didn't expect. Complain.
>if (isa(MemberDecl))
>
> Modified: cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp?rev=261506=261505=261506=diff
>
==
> --- cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
(original)
> +++ cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp Sun Feb
21 20:24:29 2016
> @@ -1,6 +1,6 @@
>  // RUN: %clang_cc1 -verify -fsyntax-only %s -Wno-c++11-extensions
-Wno-c++1y-extensions -DPRECXX11
>  // RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only
-Wno-c++1y-extensions %s
> -// RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only %s
> +// RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only %s -DCPP1Y
>
>  #define CONST const
>
> @@ -338,3 

r261506 - Fix PR24473 : Teach clang to remember to substitute into member variable templates referred to within dependent qualified ids.

2016-02-21 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Sun Feb 21 20:24:29 2016
New Revision: 261506

URL: http://llvm.org/viewvc/llvm-project?rev=261506=rev
Log:
Fix PR24473 : Teach clang to remember to substitute into member variable 
templates referred to within dependent qualified ids.

In passing also fix a semi-related bug that allows access to variable templates 
through member access notation.


Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=261506=261505=261506=diff
==
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Sun Feb 21 20:24:29 2016
@@ -902,6 +902,32 @@ static bool IsInFnTryBlockHandler(const
   return false;
 }
 
+static VarDecl *
+getVarTemplateSpecialization(Sema , VarTemplateDecl *VarTempl,
+  const TemplateArgumentListInfo *TemplateArgs,
+  const DeclarationNameInfo ,
+  SourceLocation TemplateKWLoc) {
+
+  if (!TemplateArgs) {
+S.Diag(MemberNameInfo.getBeginLoc(), diag::err_template_decl_ref)
+<< /*Variable template*/ 1 << MemberNameInfo.getName()
+<< MemberNameInfo.getSourceRange();
+
+S.Diag(VarTempl->getLocation(), diag::note_template_decl_here);
+
+return nullptr;
+  }
+  DeclResult VDecl = S.CheckVarTemplateId(
+  VarTempl, TemplateKWLoc, MemberNameInfo.getLoc(), *TemplateArgs);
+  if (VDecl.isInvalid())
+return nullptr;
+  VarDecl *Var = cast(VDecl.get());
+  if (!Var->getTemplateSpecializationKind())
+Var->setTemplateSpecializationKind(TSK_ImplicitInstantiation,
+   MemberNameInfo.getLoc());
+  return Var;
+}
+
 ExprResult
 Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
SourceLocation OpLoc, bool IsArrow,
@@ -1069,9 +1095,20 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
   // Handle the implicit-member-access case.
   if (!BaseExpr) {
 // If this is not an instance member, convert to a non-member access.
-if (!MemberDecl->isCXXInstanceMember())
+if (!MemberDecl->isCXXInstanceMember()) {
+  // If this is a variable template, get the instantiated variable
+  // declaration corresponding to the supplied template arguments
+  // (while emitting diagnostics as necessary) that will be referenced
+  // by this expression.
+  if (isa(MemberDecl)) {
+MemberDecl = getVarTemplateSpecialization(
+*this, cast(MemberDecl), TemplateArgs,
+R.getLookupNameInfo(), TemplateKWLoc);
+if (!MemberDecl)
+  return ExprError();
+  }
   return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), MemberDecl);
-
+}
 SourceLocation Loc = R.getNameLoc();
 if (SS.getRange().isValid())
   Loc = SS.getRange().getBegin();
@@ -1127,6 +1164,15 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
TemplateKWLoc, Enum, FoundDecl, MemberNameInfo,
Enum->getType(), VK_RValue, OK_Ordinary);
   }
+  if (VarTemplateDecl *VarTempl = dyn_cast(MemberDecl)) {
+if (VarDecl *Var = getVarTemplateSpecialization(
+*this, VarTempl, TemplateArgs, MemberNameInfo, TemplateKWLoc))
+  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
+ TemplateKWLoc, Var, FoundDecl, MemberNameInfo,
+ Var->getType().getNonReferenceType(), VK_LValue,
+ OK_Ordinary);
+return ExprError();
+  }
 
   // We found something that we didn't expect. Complain.
   if (isa(MemberDecl))

Modified: cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp?rev=261506=261505=261506=diff
==
--- cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp Sun Feb 21 
20:24:29 2016
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s -Wno-c++11-extensions 
-Wno-c++1y-extensions -DPRECXX11
 // RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -Wno-c++1y-extensions %s
-// RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only %s
+// RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only %s -DCPP1Y
 
 #define CONST const
 
@@ -338,3 +338,47 @@ namespace b20896909 {
 A ai;  // expected-note {{in instantiation of}}
   }
 }
+namespace member_access_is_ok {
+#ifdef CPP1Y
+  namespace ns1 {
+struct A {
+  template constexpr static T Var = N;
+};
+static_assert(A{}.Var == 5,"");
+  } // end ns1
+#endif // CPP1Y
+
+namespace ns2 {
+  template struct A {
+

[PATCH] D17491: Add performance check to flag function parameters of expensive to copy types that can be safely converted to const references.

2016-02-21 Thread Felix Berger via cfe-commits
flx created this revision.
flx added a reviewer: alexfh.
flx added a subscriber: cfe-commits.
flx set the repository for this revision to rL LLVM.

The patch uses [[ http://reviews.llvm.org/D17488 | D17488 ]] as diff base. Once 
D17488 is submitted I'll update the diffbase to head.

Repository:
  rL LLVM

http://reviews.llvm.org/D17491

Files:
  clang-tidy/performance/CMakeLists.txt
  clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tidy/performance/UnnecessaryValueParamCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/performance-unnecessary-value-param.rst
  test/clang-tidy/performance-unnecessary-value-param.cpp

Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- /dev/null
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -0,0 +1,160 @@
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t
+
+struct ExpensiveToCopyType {
+  const ExpensiveToCopyType & constReference() const {
+return *this;
+  }
+  void nonConstMethod() {}
+  virtual ~ExpensiveToCopyType() {}
+};
+
+void mutate(ExpensiveToCopyType &);
+void mutate(ExpensiveToCopyType *);
+void useAsConstReference(const ExpensiveToCopyType &);
+void useByValue(ExpensiveToCopyType);
+
+// This class simulates std::pair<>. It is trivially copy constructible
+// and trivially destructible, but not trivially copy assignable.
+class SomewhatTrivial {
+ public:
+  SomewhatTrivial();
+  SomewhatTrivial(const SomewhatTrivial&) = default;
+  ~SomewhatTrivial() = default;
+  SomewhatTrivial& operator=(const SomewhatTrivial&);
+};
+
+void positiveExpensiveConstValue(const ExpensiveToCopyType Obj);
+// CHECK-FIXES: void positiveExpensiveConstValue(const ExpensiveToCopyType& Obj);
+void positiveExpensiveConstValue(const ExpensiveToCopyType Obj) {
+  // CHECK-MESSAGES: [[@LINE-1]]:60: warning: the const qualified parameter 'Obj' is copied for each invocation; consider making this a reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: void positiveExpensiveConstValue(const ExpensiveToCopyType& Obj) {
+}
+
+void positiveExpensiveValue(ExpensiveToCopyType Obj);
+// CHECK-FIXES: void positiveExpensiveValue(const ExpensiveToCopyType& Obj);
+void positiveExpensiveValue(ExpensiveToCopyType Obj) {
+  // CHECK-MESSAGES: [[@LINE-1]]:49: warning: the parameter 'Obj' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: void positiveExpensiveValue(const ExpensiveToCopyType& Obj) {
+  Obj.constReference();
+  useAsConstReference(Obj);
+  auto Copy = Obj;
+  useByValue(Obj);
+}
+
+void positiveWithComment(const ExpensiveToCopyType /* important */ S);
+// CHECK-FIXES: void positiveWithComment(const ExpensiveToCopyType& /* important */ S);
+void positiveWithComment(const ExpensiveToCopyType /* important */ S) {
+  // CHECK-MESSAGES: [[@LINE-1]]:68: warning: the const qualified
+  // CHECK-FIXES: void positiveWithComment(const ExpensiveToCopyType& /* important */ S) {
+}
+
+void positiveAndNegative(const ExpensiveToCopyType ConstCopy, const ExpensiveToCopyType& ConstRef, ExpensiveToCopyType Copy);
+// CHECK-FIXES: void positiveAndNegative(const ExpensiveToCopyType& ConstCopy, const ExpensiveToCopyType& ConstRef, const ExpensiveToCopyType& Copy);
+void positiveAndNegative(const ExpensiveToCopyType ConstCopy, const ExpensiveToCopyType& ConstRef, ExpensiveToCopyType Copy) {
+  // CHECK-MESSAGES: [[@LINE-1]]:52: warning: the const qualified parameter 'ConstCopy'
+  // CHECK-MESSAGES: [[@LINE-2]]:120: warning: the parameter 'Copy'
+  // CHECK-FIXES: void positiveAndNegative(const ExpensiveToCopyType& ConstCopy, const ExpensiveToCopyType& ConstRef, const ExpensiveToCopyType& Copy) {
+}
+
+struct PositiveConstValueConstructor {
+  PositiveConstValueConstructor(const ExpensiveToCopyType ConstCopy) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:59: warning: the const qualified parameter 'ConstCopy'
+};
+
+template  void templateWithNonTemplatizedParameter(const ExpensiveToCopyType S, T V) {
+  // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
+  // CHECK-FIXES: template  void templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
+}
+
+void instantiated() {
+  templateWithNonTemplatizedParameter(ExpensiveToCopyType(), ExpensiveToCopyType());
+  templateWithNonTemplatizedParameter(ExpensiveToCopyType(), 5);
+}
+
+template  void negativeTemplateType(const T V) {
+}
+
+void negativeArray(const ExpensiveToCopyType[]) {
+}
+
+void negativePointer(ExpensiveToCopyType* Obj) {
+}
+
+void negativeConstPointer(const ExpensiveToCopyType* Obj) {
+}
+
+void negativeConstReference(const ExpensiveToCopyType& Obj) {
+}
+
+void negativeReference(ExpensiveToCopyType& Obj) {
+}
+
+void negativeUniversalReference(ExpensiveToCopyType&& Obj) {
+}
+
+void 

Re: [PATCH] D17019: [OpenMP] Code generation for teams - kernel launching

2016-02-21 Thread Carlo Bertolli via cfe-commits
carlo.bertolli added a comment.

Just wanted to add that tgt_target_teams needs the values for num_teams and 
thread_limit because, for some accelerators, it is necessary to know those 
values in advance, before teams gets actually executed. For instance, on Nvidia 
GPUs we launch one CUDA block for each team. This can only be done at kernel 
launch time, which is performed in the implementation of tgt_target_teams.


http://reviews.llvm.org/D17019



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


Re: [PATCH] D17484: [clang-tidy] introduce modernize-deprecated-headers check

2016-02-21 Thread Joerg Sonnenberger via cfe-commits
On Sun, Feb 21, 2016 at 02:26:30AM +, Eugene Zelenko via cfe-commits wrote:
> Another idea: to replace limits.h with limits and also replace its
> defines with their C++ counterparts. For example, INT_MIN with 
> numeric_limits::min().

I'm not sure how useful it is to write four times as much text just for
the sake of modernization. I don't understand how this adds value.

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


Re: [PATCH] D17091: [analyzer][scan-build-py] Non-existing directory for scan-build output.

2016-02-21 Thread Anton Yartsev via cfe-commits
ayartsev added a comment.

In http://reviews.llvm.org/D17091#358022, @rizsotto.mailinglist wrote:

> the semicolon at the end of line 39 is an issue for PEP8. please remove it.


Done.

Committed as r261480, thanks for the review.


http://reviews.llvm.org/D17091



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


r261480 - [analyzer][scan-build] Non-existing directory for scan-build output.

2016-02-21 Thread Anton Yartsev via cfe-commits
Author: ayartsev
Date: Sun Feb 21 11:04:26 2016
New Revision: 261480

URL: http://llvm.org/viewvc/llvm-project?rev=261480=rev
Log:
[analyzer][scan-build] Non-existing directory for scan-build output.

Makes scan-build successfully accept non-existing output directories provided 
via "-o" option. The directory is created in this case. This behavior is 
conforming to the old perl scan-build implementation.
(http://reviews.llvm.org/D17091)

Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/report.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/report.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/report.py?rev=261480=261479=261480=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/report.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/report.py Sun Feb 21 11:04:26 
2016
@@ -35,7 +35,12 @@ def report_directory(hint, keep):
 keep -- a boolean value to keep or delete the empty report directory. """
 
 stamp = time.strftime('scan-build-%Y-%m-%d-%H%M%S-', time.localtime())
-name = tempfile.mkdtemp(prefix=stamp, dir=hint)
+
+parentdir = os.path.abspath(hint)
+if not os.path.exists(parentdir):
+os.makedirs(parentdir)
+
+name = tempfile.mkdtemp(prefix=stamp, dir=parentdir)
 
 logging.info('Report directory created: %s', name)
 


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


Re: [PATCH] D13388: Add support for querying the visibility of a cursor

2016-02-21 Thread Milian Wolff via cfe-commits
milianw closed this revision.
milianw added a comment.

closing then, since this has been landed


http://reviews.llvm.org/D13388



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


Re: [PATCH] D17362: [Sema] PR23090 Crash when return type or parameter types for extern "C" functions don't have external linkage

2016-02-21 Thread don hinton via cfe-commits
hintonda updated this revision to Diff 48617.
hintonda added a comment.

- Fix remaining test failures caused by linkage errors.


http://reviews.llvm.org/D17362

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  test/CXX/drs/dr3xx.cpp
  test/Sema/pr23090-crash-on-invalid.cpp
  test/SemaCXX/linkage.cpp
  test/SemaCXX/warn-unused-filescoped.cpp

Index: test/SemaCXX/warn-unused-filescoped.cpp
===
--- test/SemaCXX/warn-unused-filescoped.cpp
+++ test/SemaCXX/warn-unused-filescoped.cpp
@@ -121,7 +121,6 @@
   namespace { struct A {}; }
 
   void test(A a); // expected-warning {{unused function}}
-  extern "C" void test4(A a);
 }
 
 namespace rdar8733476 {
Index: test/SemaCXX/linkage.cpp
===
--- test/SemaCXX/linkage.cpp
+++ test/SemaCXX/linkage.cpp
@@ -57,43 +57,21 @@
 
 namespace test3 {
   namespace { struct A {}; }
+  struct B {};
 
   // CHECK: define internal void @_ZN5test34testENS_12_GLOBAL__N_11AE(
   void test(A a) {}
   void force() { test(A()); }
 
   // CHECK: define void @test3(
-  extern "C" void test3(A a) {}
+  extern "C" void test3(B b) {}
 }
 
 namespace {
   // CHECK: define void @test4(
   extern "C" void test4(void) {}
 }
 
-// PR9316: Ensure that even non-namespace-scope function declarations in
-// a C declaration context respect that over the anonymous namespace.
-extern "C" {
-  namespace {
-struct X {
-  int f() {
-extern int g();
-extern int a;
-
-// Test both for mangling in the code generation and warnings from use
-// of internal, undefined names via -Werror.
-// CHECK: call i32 @g(
-// CHECK: load i32, i32* @a,
-return g() + a;
-  }
-};
-  }
-  // Force the above function to be emitted by codegen.
-  int test(X& x) {
-return x.f();
-  }
-}
-
 // CHECK: define linkonce_odr i8* @_ZN5test11A3fooILj0EEEPvv(
 // CHECK: define linkonce_odr i8* @_ZN5test21A1BILj0EE3fooEv(
 
Index: test/Sema/pr23090-crash-on-invalid.cpp
===
--- /dev/null
+++ test/Sema/pr23090-crash-on-invalid.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// Don't crash (PR23090).
+
+namespace {
+
+// check return type
+struct A;
+extern "C" A *foo(); // expected-error {{'foo' has C-linkage specified, but return type '(anonymous namespace)::A *' has internal linkage}}
+A *foo();
+
+// check parameter
+struct B;
+extern "C" void bar(B*); // expected-error {{'bar' has C-linkage specified, but parameter type '(anonymous namespace)::B *' has internal linkage}}
+void bar(B*);
+
+}
Index: test/CXX/drs/dr3xx.cpp
===
--- test/CXX/drs/dr3xx.cpp
+++ test/CXX/drs/dr3xx.cpp
@@ -232,8 +232,8 @@
   typedef struct {
 int i;
   } *ps;
-  extern "C" void f(ps);
-  void g(ps); // FIXME: ill-formed, type 'ps' has no linkage
+  extern "C" void f(ps); // expected-error-re {{'f' has C-linkage specified, but parameter type 'ps' (aka 'dr319::(anonymous struct {{.*}} *') has internal linkage}}
+  void g(ps);
 
   static enum { e } a1;
   enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -8218,6 +8218,25 @@
   Diag(NewFD->getLocation(), diag::ext_out_of_line_declaration)
 << D.getCXXScopeSpec().getRange();
 }
+
+if (NewFD->isExternC()) {
+  // Check return type linkage
+  QualType R = NewFD->getReturnType();
+  if (R.getTypePtr()->getLinkage() != Linkage::ExternalLinkage) {
+Diag(NewFD->getLocation(), diag::err_return_value_linkage)
+  << NewFD << R;
+NewFD->setInvalidDecl();
+  }
+  // Check parameter type linkage
+  for (auto param : NewFD->parameters()) {
+QualType P = param->getOriginalType();
+if (P.getTypePtr()->getLinkage() != Linkage::ExternalLinkage) {
+  Diag(NewFD->getLocation(), diag::err_parameter_value_linkage)
+<< NewFD << P;
+  NewFD->setInvalidDecl();
+}
+  }
+}
   }
 
   ProcessPragmaWeak(S, NewFD);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -325,6 +325,11 @@
 def warn_unused_private_field: Warning<"private field %0 is not used">,
   InGroup, DefaultIgnore;
 
+def err_return_value_linkage: Error<
+  "%0 has C-linkage specified, but return type %1 has internal linkage">;
+def err_parameter_value_linkage: Error<
+  "%0 has C-linkage specified, but parameter type %1 has internal linkage">;
+
 def warn_parameter_size: Warning<
   "%0 is a large (%1 bytes) pass-by-value argument; "
   "pass it by 

r261471 - [CLANG] [AVX512] [BUILTIN] Adding pmovzx{b|d|w}{w|d|q}{128|256|512} builtin to clang

2016-02-21 Thread Michael Zuckerman via cfe-commits
Author: mzuckerm
Date: Sun Feb 21 08:00:11 2016
New Revision: 261471

URL: http://llvm.org/viewvc/llvm-project?rev=261471=rev
Log:
[CLANG] [AVX512] [BUILTIN] Adding pmovzx{b|d|w}{w|d|q}{128|256|512} builtin to 
clang 

Differential Revision: http://reviews.llvm.org/D16961

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx512bwintrin.h
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/lib/Headers/avx512vlbwintrin.h
cfe/trunk/lib/Headers/avx512vlintrin.h
cfe/trunk/test/CodeGen/avx512bw-builtins.c
cfe/trunk/test/CodeGen/avx512f-builtins.c
cfe/trunk/test/CodeGen/avx512vl-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=261471=261470=261471=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Sun Feb 21 08:00:11 2016
@@ -1590,6 +1590,24 @@ TARGET_BUILTIN(__builtin_ia32_pmovsxwd12
 TARGET_BUILTIN(__builtin_ia32_pmovsxwd256_mask, "V8iV8sV8iUc","","avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovsxwq128_mask, 
"V2LLiV8sV2LLiUc","","avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovsxwq256_mask, 
"V4LLiV8sV4LLiUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovzxbw512_mask, "V32sV32cV32sUi","","avx512bw")
+TARGET_BUILTIN(__builtin_ia32_pmovzxbd512_mask, "V16iV16cV16iUs","","avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmovzxbq512_mask, 
"V8LLiV16cV8LLiUc","","avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmovzxdq512_mask, "V8LLiV8iV8LLiUc","","avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmovzxwd512_mask, "V16iV16sV16iUs","","avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmovzxwq512_mask, "V8LLiV8sV8LLiUc","","avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmovzxbw128_mask, 
"V8sV16cV8sUc","","avx512vl,avx512bw")
+TARGET_BUILTIN(__builtin_ia32_pmovzxbw256_mask, 
"V16sV16cV16sUs","","avx512vl,avx512bw")
+TARGET_BUILTIN(__builtin_ia32_pmovzxbd128_mask, "V4iV16cV4iUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovzxbd256_mask, "V8iV16cV8iUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovzxbq128_mask, 
"V2LLiV16cV2LLiUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovzxbq256_mask, 
"V4LLiV16cV4LLiUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovzxdq128_mask, 
"V2LLiV4iV2LLiUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovzxdq256_mask, 
"V4LLiV4iV4LLiUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovzxwd128_mask, "V4iV8sV4iUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovzxwd256_mask, "V8iV8sV8iUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovzxwq128_mask, 
"V2LLiV8sV2LLiUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovzxwq256_mask, 
"V4LLiV8sV4LLiUc","","avx512vl")
 
 #undef BUILTIN
 #undef TARGET_BUILTIN

Modified: cfe/trunk/lib/Headers/avx512bwintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512bwintrin.h?rev=261471=261470=261471=diff
==
--- cfe/trunk/lib/Headers/avx512bwintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512bwintrin.h Sun Feb 21 08:00:11 2016
@@ -1522,6 +1522,33 @@ _mm512_maskz_cvtepi8_epi16 (__mmask32 __
 (__mmask32) __U);
 }
 
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_cvtepu8_epi16 (__m256i __A)
+{
+  return (__m512i) __builtin_ia32_pmovzxbw512_mask ((__v32qi) __A,
+(__v32hi)
+_mm512_setzero_hi (),
+(__mmask32) -1);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_mask_cvtepu8_epi16 (__m512i __W, __mmask32 __U, __m256i __A)
+{
+  return (__m512i) __builtin_ia32_pmovzxbw512_mask ((__v32qi) __A,
+(__v32hi) __W,
+(__mmask32) __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_maskz_cvtepu8_epi16 (__mmask32 __U, __m256i __A)
+{
+  return (__m512i) __builtin_ia32_pmovzxbw512_mask ((__v32qi) __A,
+(__v32hi)
+_mm512_setzero_hi(),
+(__mmask32) __U);
+}
+
+
 #define _mm512_cmp_epi8_mask(a, b, p) __extension__ ({ \
   (__mmask16)__builtin_ia32_cmpb512_mask((__v64qi)(__m512i)(a), \
  (__v64qi)(__m512i)(b), \

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=261471=261470=261471=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Sun Feb 21 08:00:11 2016
@@ -3159,6 +3159,137 @@ _mm512_maskz_cvtepi16_epi64 (__mmask8 __
 (__mmask8) __U);
 }
 
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_cvtepu8_epi32 (__m128i __A)
+{
+  return (__m512i) __builtin_ia32_pmovzxbd512_mask ((__v16qi) __A,
+ 

Re: RFC: Update Intel386, x86-64 and IA MCU psABIs for passing/returning empty struct

2016-02-21 Thread H.J. Lu via cfe-commits
On Sat, Feb 20, 2016 at 10:48 PM, Richard Smith  wrote:
> On 20 Feb 2016 10:01 p.m., "H.J. Lu"  wrote:
>>
>> On Sat, Feb 20, 2016 at 9:47 PM, Richard Smith 
>> wrote:
>> > On 20 Feb 2016 6:54 p.m., "H.J. Lu"  wrote:
>> >>
>> >> On Sat, Feb 20, 2016 at 4:57 PM, Matthijs van Duin
>> >>  wrote:
>> >> > On 20 February 2016 at 23:35, H.J. Lu  wrote:
>> >> >> Can a compiler tell if a copy constructor or destructor is trivial
>> >> >> from the class declaration without function body?
>> >> >
>> >> > Yes, the mere presence of the declaration suffices to render it
>> >> > non-trivial (unless explicitly declared "= default" like I did with
>> >> > the default constructor, in which case there's no function body).
>> >>
>> >> How about this?
>> >>
>> >> An empty type is a type where it and all of its subobjects
>> >> (recursively)
>> >> are of class, structure, union, or array type.  An empty type may only
>> >> have static member functions, default  constructor, default copy
>> >> constructor, default copy assignment operator or default destructor.
>> >
>> > No, that's the wrong rule still. Please leave the C++ rule here to the
>> > C++
>> > ABI rather than trying to reinvent it. Whether a type is empty is
>> > completely
>> > orthogonal to whether it must be passed through memory for C++ ABI /
>> > semantics reasons.
>>
>> What is the correct wording?  The last one:
>>
>> An empty type is a type where it and all of its subobjects (recursively)
>> are of class, structure, union, or array type.
>>
>> doesn't cover "trivially-copyable".
>
> That's correct. Whether a type is trivially copyable is unrelated to whether
> it is empty.

Let get me what you were suggesting.  The x86 psABIs define the empty
type as

An empty type is a type where it and all of its subobjects (recursively)
are of class, structure, union, or array type.  No memory slot nor register
should be used to pass or return an object of empty type.

Footnote: Array of empty type can only passed by reference in C and C++.

As for what other C++ types, which aren't empty type as defined by x86
psABIs, can be passed and returned without memory slot nor register
belong to C++ ABI.

Am I correct?

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


Re: [PATCH] D17484: [clang-tidy] introduce modernize-deprecated-headers check

2016-02-21 Thread Kirill Bobyrev via cfe-commits
omtcyf0 marked 3 inline comments as done.
omtcyf0 added a comment.

http://reviews.llvm.org/D17484



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


Re: [PATCH] D17484: [clang-tidy] introduce modernize-deprecated-headers check

2016-02-21 Thread Kirill Bobyrev via cfe-commits
omtcyf0 updated this revision to Diff 48613.
omtcyf0 added a comment.

Thanks for a review, Richard!
Fixed all the issues you pointed to!

Thanks for the hint, Eugene!
I'll try to add this functionality to this check later on.


http://reviews.llvm.org/D17484

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/DeprecatedHeadersCheck.cpp
  clang-tidy/modernize/DeprecatedHeadersCheck.h
  clang-tidy/modernize/ModernizeTidyModule.cpp
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-deprecated-headers.rst
  test/clang-tidy/modernize-deprecated-headers-cxx03.cpp
  test/clang-tidy/modernize-deprecated-headers-cxx11.cpp

Index: test/clang-tidy/modernize-deprecated-headers-cxx11.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-deprecated-headers-cxx11.cpp
@@ -0,0 +1,109 @@
+// RUN: %check_clang_tidy %s modernize-deprecated-headers %t -- -- -std=c++11 -isystem %S/Inputs/Headers
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+// CHECK-FIXES: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+
+#include "assert.h"
+#include "complex.h"
+#include "ctype.h"
+#include "errno.h"
+#include "fenv.h"
+#include "float.h"
+#include "inttypes.h"
+#include "iso646.h"
+#include "limits.h"
+#include "locale.h"
+#include "math.h"
+#include "setjmp.h"
+#include "signal.h"
+#include "stdalign.h"
+#include "stdarg.h"
+#include "stdbool.h"
+#include "stddef.h"
+#include "stdint.h"
+#include "stdio.h"
+#include "stdlib.h"
+#include "string.h"
+#include "tgmath.h"
+#include "time.h"
+#include "uchar.h"
+#include "wchar.h"
+#include "wctype.h"
+
+// CHECK-FIXES: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
Index: test/clang-tidy/modernize-deprecated-headers-cxx03.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-deprecated-headers-cxx03.cpp
@@ -0,0 +1,103 @@
+// RUN: %check_clang_tidy %s modernize-deprecated-headers %t -- -- -std=c++03 -isystem %S/Inputs/Headers
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+// Headers deprecated since C++11; expect no diagnostics
+#include 
+#include 
+#include 
+#include 
+#include 
+
+// CHECK-FIXES: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+// CHECK-FIXES-NEXT: #include 
+
+#include "assert.h"
+#include "complex.h"
+#include "ctype.h"
+#include "errno.h"
+#include "float.h"
+#include "inttypes.h"
+#include "iso646.h"
+#include "limits.h"
+#include