r314056 - Promote storage-only __fp16 vector operands to float vectors.

2017-09-22 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Sep 22 22:02:02 2017
New Revision: 314056

URL: http://llvm.org/viewvc/llvm-project?rev=314056=rev
Log:
Promote storage-only __fp16 vector operands to float vectors.

This commit fixes a bug in the handling of storage-only __fp16 vectors
where clang didn't promote __fp16 vector operands to float vectors.

Conceptually, it performs the following transformation on the AST in
CreateBuiltinBinOp and CreateBuiltinUnaryOp:

(Before)
  typedef __fp16 half4 __attribute__ ((vector_size (8)));
  typedef float float4 __attribute__ ((vector_size (16)));
  half4 hv0, hv1, hv2, hv3;

  hv0 = hv1 + hv2 + hv3;

(After)
  float4 t0 = (float4)hv1 + (float4)hv2;
  float4 t1 = t0 + (float4)hv3;
  hv0 = (half4)t1;

Note that this commit fixes the bug for targets that set
HalfArgsAndReturns to true (ARM and ARM64). Targets using intrinsics
such as llvm.convert.to.fp16 to handle __fp16 are still broken.

rdar://problem/20625184

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

Added:
cfe/trunk/test/CodeGen/fp16vec-ops.c
cfe/trunk/test/Sema/fp16vec-sema.c
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=314056=314055=314056=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Sep 22 22:02:02 2017
@@ -1014,10 +1014,41 @@ Value *ScalarExprEmitter::EmitScalarConv
 return Builder.CreateVectorSplat(NumElements, Src, "splat");
   }
 
-  // Allow bitcast from vector to integer/fp of the same size.
-  if (isa(SrcTy) ||
-  isa(DstTy))
-return Builder.CreateBitCast(Src, DstTy, "conv");
+  if (isa(SrcTy) || isa(DstTy)) {
+// Allow bitcast from vector to integer/fp of the same size.
+unsigned SrcSize = SrcTy->getPrimitiveSizeInBits();
+unsigned DstSize = DstTy->getPrimitiveSizeInBits();
+if (SrcSize == DstSize)
+  return Builder.CreateBitCast(Src, DstTy, "conv");
+
+// Conversions between vectors of different sizes are not allowed except
+// when vectors of half are involved. Operations on storage-only half
+// vectors require promoting half vector operands to float vectors and
+// truncating the result, which is either an int or float vector, to a
+// short or half vector.
+
+// Source and destination are both expected to be vectors.
+llvm::Type *SrcElementTy = SrcTy->getVectorElementType();
+llvm::Type *DstElementTy = DstTy->getVectorElementType();
+
+assert(((SrcElementTy->isIntegerTy() &&
+ DstElementTy->isIntegerTy()) ||
+(SrcElementTy->isFloatingPointTy() &&
+ DstElementTy->isFloatingPointTy())) &&
+   "unexpected conversion between a floating-point vector and an "
+   "integer vector");
+
+// Truncate an i32 vector to an i16 vector.
+if (SrcElementTy->isIntegerTy())
+  return Builder.CreateIntCast(Src, DstTy, false, "conv");
+
+// Truncate a float vector to a half vector.
+if (SrcSize > DstSize)
+  return Builder.CreateFPTrunc(Src, DstTy, "conv");
+
+// Promote a half vector to a float vector.
+return Builder.CreateFPExt(Src, DstTy, "conv");
+  }
 
   // Finally, we have the arithmetic types: real int/float.
   Value *Res = nullptr;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=314056=314055=314056=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Sep 22 22:02:02 2017
@@ -7503,6 +7503,14 @@ Sema::CheckAssignmentConstraints(SourceL
   return CheckAssignmentConstraints(LHSType, RHSPtr, K, /*ConvertRHS=*/false);
 }
 
+/// This helper function returns true if QT is a vector type that has element
+/// type ElementType.
+static bool isVector(QualType QT, QualType ElementType) {
+  if (const VectorType *VT = QT->getAs())
+return VT->getElementType() == ElementType;
+  return false;
+}
+
 /// CheckAssignmentConstraints (C99 6.5.16) - This routine currently
 /// has code to accommodate several GCC extensions when type checking
 /// pointers. Here are some objectionable examples that GCC considers warnings:
@@ -8131,6 +8139,25 @@ static bool tryVectorConvertAndSplat(Sem
   return false;
 }
 
+/// Convert vector E to a vector with the same number of elements but different
+/// element type.
+static ExprResult convertVector(Expr *E, QualType ElementType, Sema ) {
+  const auto *VecTy = E->getType()->getAs();
+  assert(VecTy && "Expression E must be a vector");
+  QualType NewVecTy = S.Context.getVectorType(ElementType,
+  VecTy->getNumElements(),
+  

r314054 - Correctly compute linkage for members of internal linkage classes.

2017-09-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Sep 22 21:02:17 2017
New Revision: 314054

URL: http://llvm.org/viewvc/llvm-project?rev=314054=rev
Log:
Correctly compute linkage for members of internal linkage classes.

We used to give such members no linkage instead of giving them the linkage of
the class.

Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/CXX/basic/basic.link/p8.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=314054=314053=314054=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Sep 22 21:02:17 2017
@@ -871,12 +871,11 @@ LinkageComputer::getLVForClassMember(con
 
   LinkageInfo classLV =
 getLVForDecl(cast(D->getDeclContext()), classComputation);
-  // If the class already has unique-external linkage, we can't improve.
-  if (classLV.getLinkage() == UniqueExternalLinkage)
-return LinkageInfo::uniqueExternal();
-
+  // The member has the same linkage as the class. If that's not externally
+  // visible, we don't need to compute anything about the linkage.
+  // FIXME: If we're only computing linkage, can we bail out here?
   if (!isExternallyVisible(classLV.getLinkage()))
-return LinkageInfo::none();
+return classLV;
 
 
   // Otherwise, don't merge in classLV yet, because in certain cases

Modified: cfe/trunk/test/CXX/basic/basic.link/p8.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.link/p8.cpp?rev=314054=314053=314054=diff
==
--- cfe/trunk/test/CXX/basic/basic.link/p8.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.link/p8.cpp Fri Sep 22 21:02:17 2017
@@ -67,3 +67,12 @@ void use_inline_vars() {
   defined_after_use = 2;
 }
 inline int defined_after_use;
+
+namespace {
+  template struct A {
+static const int n;
+  };
+  template const int A::n = 3;
+  static_assert(A::n == 3);
+  int k = A::n;
+}


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


r314051 - Commit missing fixes for tool_file_rename

2017-09-22 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Sep 22 18:04:42 2017
New Revision: 314051

URL: http://llvm.org/viewvc/llvm-project?rev=314051=rev
Log:
Commit missing fixes for tool_file_rename

Modified:
cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
cfe/trunk/unittests/Frontend/ASTUnitTest.cpp
cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp

Modified: cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp?rev=314051=314050=314051=diff
==
--- cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp (original)
+++ cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp Fri Sep 22 
18:04:42 2017
@@ -44,13 +44,13 @@ public:
 llvm::SmallString<256> ASTFileName;
 ASSERT_FALSE(
 llvm::sys::fs::createTemporaryFile("f_ast", "ast", ASTFD, 
ASTFileName));
-llvm::tool_output_file ASTFile(ASTFileName, ASTFD);
+llvm::ToolOutputFile ASTFile(ASTFileName, ASTFD);
 
 int IndexFD;
 llvm::SmallString<256> IndexFileName;
 ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
 IndexFileName));
-llvm::tool_output_file IndexFile(IndexFileName, IndexFD);
+llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
 IndexFile.os() << "c:@F@f#I# " << ASTFileName << "\n";
 IndexFile.os().flush();
 EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
@@ -61,7 +61,7 @@ public:
 llvm::SmallString<256> SourceFileName;
 ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("input", "cpp", SourceFD,
 SourceFileName));
-llvm::tool_output_file SourceFile(SourceFileName, SourceFD);
+llvm::ToolOutputFile SourceFile(SourceFileName, SourceFD);
 SourceFile.os() << SourceText;
 SourceFile.os().flush();
 EXPECT_TRUE(llvm::sys::fs::exists(SourceFileName));
@@ -118,7 +118,7 @@ TEST(CrossTranslationUnit, IndexFormatCa
   llvm::SmallString<256> IndexFileName;
   ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
   IndexFileName));
-  llvm::tool_output_file IndexFile(IndexFileName, IndexFD);
+  llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
   IndexFile.os() << IndexText;
   IndexFile.os().flush();
   EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));

Modified: cfe/trunk/unittests/Frontend/ASTUnitTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Frontend/ASTUnitTest.cpp?rev=314051=314050=314051=diff
==
--- cfe/trunk/unittests/Frontend/ASTUnitTest.cpp (original)
+++ cfe/trunk/unittests/Frontend/ASTUnitTest.cpp Fri Sep 22 18:04:42 2017
@@ -41,7 +41,7 @@ TEST(ASTUnit, SaveLoadPreservesLangOptio
   int FD;
   llvm::SmallString<256> InputFileName;
   ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("ast-unit", "cpp", FD, 
InputFileName));
-  tool_output_file input_file(InputFileName, FD);
+  ToolOutputFile input_file(InputFileName, FD);
   input_file.os() << "";
 
   const char* Args[] = {"clang", "-xc++", InputFileName.c_str()};
@@ -69,7 +69,7 @@ TEST(ASTUnit, SaveLoadPreservesLangOptio
 
   llvm::SmallString<256> ASTFileName;
   ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("ast-unit", "ast", FD, 
ASTFileName));
-  tool_output_file ast_file(ASTFileName, FD);
+  ToolOutputFile ast_file(ASTFileName, FD);
   AST->Save(ASTFileName.str());
 
   EXPECT_TRUE(llvm::sys::fs::exists(ASTFileName));

Modified: cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp?rev=314051=314050=314051=diff
==
--- cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp (original)
+++ cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp Fri Sep 22 18:04:42 
2017
@@ -24,7 +24,7 @@ TEST(CompilerInstance, DefaultVFSOverlay
   int FD;
   SmallString<256> FileName;
   ASSERT_FALSE(sys::fs::createTemporaryFile("vfs", "yaml", FD, FileName));
-  tool_output_file File(FileName, FD);
+  ToolOutputFile File(FileName, FD);
 
   SmallString<256> CurrentPath;
   sys::fs::current_path(CurrentPath);


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


[libclc] r314050 - [Support] Rename tool_output_file to ToolOutputFile, NFC

2017-09-22 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Sep 22 18:03:17 2017
New Revision: 314050

URL: http://llvm.org/viewvc/llvm-project?rev=314050=rev
Log:
[Support] Rename tool_output_file to ToolOutputFile, NFC

This class isn't similar to anything from the STL, so it shouldn't use
the STL naming conventions.

Modified:
libclc/trunk/utils/prepare-builtins.cpp

Modified: libclc/trunk/utils/prepare-builtins.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/utils/prepare-builtins.cpp?rev=314050=314049=314050=diff
==
--- libclc/trunk/utils/prepare-builtins.cpp (original)
+++ libclc/trunk/utils/prepare-builtins.cpp Fri Sep 22 18:03:17 2017
@@ -84,8 +84,8 @@ int main(int argc, char **argv) {
   }
 
   std::error_code EC;
-  std::unique_ptr Out
-  (new tool_output_file(OutputFilename, EC, sys::fs::F_None));
+  std::unique_ptr Out(
+  new ToolOutputFile(OutputFilename, EC, sys::fs::F_None));
   if (EC) {
 errs() << EC.message() << '\n';
 exit(1);


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


r314050 - [Support] Rename tool_output_file to ToolOutputFile, NFC

2017-09-22 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Sep 22 18:03:17 2017
New Revision: 314050

URL: http://llvm.org/viewvc/llvm-project?rev=314050=rev
Log:
[Support] Rename tool_output_file to ToolOutputFile, NFC

This class isn't similar to anything from the STL, so it shouldn't use
the STL naming conventions.

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

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=314050=314049=314050=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Fri Sep 22 18:03:17 2017
@@ -265,12 +265,11 @@ namespace clang {
 Ctx.setDiagnosticsHotnessThreshold(
 CodeGenOpts.DiagnosticsHotnessThreshold);
 
-  std::unique_ptr OptRecordFile;
+  std::unique_ptr OptRecordFile;
   if (!CodeGenOpts.OptRecordFile.empty()) {
 std::error_code EC;
-OptRecordFile =
-  llvm::make_unique(CodeGenOpts.OptRecordFile,
-EC, sys::fs::F_None);
+OptRecordFile = llvm::make_unique(
+CodeGenOpts.OptRecordFile, EC, sys::fs::F_None);
 if (EC) {
   Diags.Report(diag::err_cannot_open_file) <<
 CodeGenOpts.OptRecordFile << EC.message();


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


[clang-tools-extra] r314050 - [Support] Rename tool_output_file to ToolOutputFile, NFC

2017-09-22 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Sep 22 18:03:17 2017
New Revision: 314050

URL: http://llvm.org/viewvc/llvm-project?rev=314050=rev
Log:
[Support] Rename tool_output_file to ToolOutputFile, NFC

This class isn't similar to anything from the STL, so it shouldn't use
the STL naming conventions.

Modified:
clang-tools-extra/trunk/modularize/ModuleAssistant.cpp
clang-tools-extra/trunk/pp-trace/PPTrace.cpp

Modified: clang-tools-extra/trunk/modularize/ModuleAssistant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/ModuleAssistant.cpp?rev=314050=314049=314050=diff
==
--- clang-tools-extra/trunk/modularize/ModuleAssistant.cpp (original)
+++ clang-tools-extra/trunk/modularize/ModuleAssistant.cpp Fri Sep 22 18:03:17 
2017
@@ -25,7 +25,7 @@
 // to modularize.  It then calls a writeModuleMap function to set up the
 // module map file output and walk the module tree, outputting the module
 // map file using a stream obtained and managed by an
-// llvm::tool_output_file object.
+// llvm::ToolOutputFile object.
 //
 //===-===//
 
@@ -271,7 +271,7 @@ static bool writeModuleMap(llvm::StringR
 
   // Set up module map output file.
   std::error_code EC;
-  llvm::tool_output_file Out(FilePath, EC, llvm::sys::fs::F_Text);
+  llvm::ToolOutputFile Out(FilePath, EC, llvm::sys::fs::F_Text);
   if (EC) {
 llvm::errs() << Argv0 << ": error opening " << FilePath << ":"
  << EC.message() << "\n";
@@ -289,7 +289,7 @@ static bool writeModuleMap(llvm::StringR
   if (!RootModule->output(OS, 0))
 return false;
 
-  // Tell tool_output_file that we want to keep the file.
+  // Tell ToolOutputFile that we want to keep the file.
   Out.keep();
 
   return true;

Modified: clang-tools-extra/trunk/pp-trace/PPTrace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/pp-trace/PPTrace.cpp?rev=314050=314049=314050=diff
==
--- clang-tools-extra/trunk/pp-trace/PPTrace.cpp (original)
+++ clang-tools-extra/trunk/pp-trace/PPTrace.cpp Fri Sep 22 18:03:17 2017
@@ -215,7 +215,7 @@ int main(int Argc, const char **Argv) {
   } else {
 // Set up output file.
 std::error_code EC;
-llvm::tool_output_file Out(OutputFileName, EC, llvm::sys::fs::F_Text);
+llvm::ToolOutputFile Out(OutputFileName, EC, llvm::sys::fs::F_Text);
 if (EC) {
   llvm::errs() << "pp-trace: error creating " << OutputFileName << ":"
<< EC.message() << "\n";
@@ -224,7 +224,7 @@ int main(int Argc, const char **Argv) {
 
 HadErrors = outputPPTrace(CallbackCalls, Out.os());
 
-// Tell tool_output_file that we want to keep the file.
+// Tell ToolOutputFile that we want to keep the file.
 if (HadErrors == 0)
   Out.keep();
   }


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


Re: r313386 - [Sema] Error out early for tags defined inside an enumeration.

2017-09-22 Thread Volodymyr Sapsai via cfe-commits


> On Sep 21, 2017, at 15:17, Richard Smith  wrote:
> 
> On 15 September 2017 at 12:51, Volodymyr Sapsai via cfe-commits 
> > wrote:
> Author: vsapsai
> Date: Fri Sep 15 12:51:42 2017
> New Revision: 313386
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=313386=rev 
> 
> Log:
> [Sema] Error out early for tags defined inside an enumeration.
> 
> This fixes PR28903 by avoiding access check for inner enum constant. We
> are performing access check because one enum constant references another
> and because enum is defined in CXXRecordDecl. But access check doesn't
> work because FindDeclaringClass doesn't expect more than one EnumDecl
> and because inner enum has access AS_none due to not being an immediate
> child of a record.
> 
> The change detects an enum is defined in wrong place and allows to skip
> parsing its body. Access check is skipped together with body parsing.
> There was no crash in C, added test case to cover the new error.
> 
> rdar://problem/28530809
> 
> Reviewers: rnk, doug.gregor, rsmith
> 
> Reviewed By: doug.gregor
> 
> Subscribers: cfe-commits
> 
> Differential Revision: https://reviews.llvm.org/D37089 
> 
> 
> 
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/Sema/enum.c
> cfe/trunk/test/SemaCXX/enum.cpp
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=313386=313385=313386=diff
>  
> 
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 15 12:51:42 
> 2017
> @@ -1335,6 +1335,8 @@ def err_type_defined_in_alias_template :
>"%0 cannot be defined in a type alias template">;
>  def err_type_defined_in_condition : Error<
>"%0 cannot be defined in a condition">;
> +def err_type_defined_in_enum : Error<
> +  "%0 cannot be defined in an enumeration">;
> 
>  def note_pure_virtual_function : Note<
>"unimplemented pure virtual method %0 in %1">;
> 
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=313386=313385=313386=diff
>  
> 
> ==
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Sep 15 12:51:42 2017
> @@ -13928,6 +13928,12 @@ CreateNewDecl:
>  Invalid = true;
>}
> 
> +  if (!Invalid && TUK == TUK_Definition && DC->getDeclKind() == Decl::Enum) {
> +Diag(New->getLocation(), diag::err_type_defined_in_enum)
> +  << Context.getTagDeclType(New);
> +Invalid = true;
> +  }
> 
> This looks like the wrong fix. As noted elsewhere, this is wrong in C. And in 
> C++, the relevant context is a type-specifier, which should be rejected due 
> to the check 7 lines above.
> 
> It looks like the actual bug is that we don't consider the type within a C99 
> compound literal to be a type-specifier. The fact that the context is an 
> enumeration is irrelevant.

At which point can we detect IsTypeSpecifier should be true? Which in turn 
boils down to DeclSpecContext should be DSC_type_specifier. Currently we have 
DeclSpecContext DSC_normal because it is a default argument in 
Parser::ParseSpecifierQualifierList. Which is called from

#4  clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, 
bool, bool, clang::OpaquePtr&, clang::SourceLocation&) at 
llvm-project/clang/lib/Parse/ParseExpr.cpp:2375
#5  clang::Parser::ParseCastExpression(bool, bool, bool&, 
clang::Parser::TypeCastState, bool) at 
llvm-project/clang/lib/Parse/ParseExpr.cpp:768
#6  clang::Parser::ParseCastExpression(bool, bool, 
clang::Parser::TypeCastState, bool) at 
llvm-project/clang/lib/Parse/ParseExpr.cpp:521
#7  
clang::Parser::ParseConstantExpressionInExprEvalContext(clang::Parser::TypeCastState)
 at llvm-project/clang/lib/Parse/ParseExpr.cpp:201

I have considered using TypeCastState for setting DeclSpecContext but its value 
is NotTypeCast because Parser::ParseEnumBody calls ParseConstantExpression with 
default argument. And it looks correct as parsing enum body doesn't imply 
presence of a type cast.

I was struggling to find a good indication we are parsing type specifier and 
the best option seems to be ParseCastExpression because it expects a type. But 
it is too broad and likely to cause false positives. In quick prototype it 
didn't 

Re: r314037 - DR1113: anonymous namespaces formally give their contents internal linkage.

2017-09-22 Thread Richard Smith via cfe-commits
r314047.

On 22 September 2017 at 16:36, Richard Smith  wrote:

> Investigating...
>
>
> On 22 September 2017 at 15:58, Vitaly Buka via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> This breaks check-clang-tools
>> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-
>> scei-ps4-windows10pro-fast/builds/12310/steps/test/logs/stdio
>>
>> On Fri, Sep 22, 2017 at 3:21 PM, Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: rsmith
>>> Date: Fri Sep 22 15:21:44 2017
>>> New Revision: 314037
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=314037=rev
>>> Log:
>>> DR1113: anonymous namespaces formally give their contents internal
>>> linkage.
>>>
>>> This doesn't affect our code generation in any material way -- we
>>> already give
>>> such declarations internal linkage from a codegen perspective -- but it
>>> has
>>> some subtle effects on code validity.
>>>
>>> We suppress the 'L' (internal linkage) marker for mangled names in
>>> anonymous
>>> namespaces, because it is redundant (the information is already carried
>>> by the
>>> namespace); this deviates from GCC's behavior if a variable or function
>>> in an
>>> anonymous namespace is redundantly declared 'static' (where GCC does
>>> include
>>> the 'L'), but GCC's behavior is incoherent because such a declaration
>>> can be
>>> validly declared with or without the 'static'.
>>>
>>> We still deviate from the standard in one regard here: extern "C"
>>> declarations
>>> in anonymous namespaces are still granted external linkage. Changing
>>> those does
>>> not appear to have been an intentional consequence of the standard
>>> change in
>>> DR1113.
>>>
>>> Added:
>>> cfe/trunk/test/CXX/drs/dr11xx.cpp
>>> Modified:
>>> cfe/trunk/lib/AST/Decl.cpp
>>> cfe/trunk/lib/AST/ItaniumMangle.cpp
>>> cfe/trunk/test/CXX/basic/basic.link/p8.cpp
>>> cfe/trunk/test/CodeGenCXX/anonymous-namespaces.cpp
>>> cfe/trunk/test/SemaCXX/linkage2.cpp
>>> cfe/trunk/test/SemaCXX/undefined-internal.cpp
>>>
>>> Modified: cfe/trunk/lib/AST/Decl.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.c
>>> pp?rev=314037=314036=314037=diff
>>> 
>>> ==
>>> --- cfe/trunk/lib/AST/Decl.cpp (original)
>>> +++ cfe/trunk/lib/AST/Decl.cpp Fri Sep 22 15:21:44 2017
>>> @@ -619,16 +619,16 @@ LinkageComputer::getLVForNamespaceScopeD
>>>if (D->isInAnonymousNamespace()) {
>>>  const auto *Var = dyn_cast(D);
>>>  const auto *Func = dyn_cast(D);
>>> -// FIXME: In C++11 onwards, anonymous namespaces should give decls
>>> -// within them (including those inside extern "C" contexts) internal
>>> -// linkage, not unique external linkage:
>>> +// FIXME: The check for extern "C" here is not justified by the
>>> standard
>>> +// wording, but we retain it from the pre-DR1113 model to avoid
>>> breaking
>>> +// code.
>>>  //
>>>  // C++11 [basic.link]p4:
>>>  //   An unnamed namespace or a namespace declared directly or
>>> indirectly
>>>  //   within an unnamed namespace has internal linkage.
>>>  if ((!Var || !isFirstInExternCContext(Var)) &&
>>>  (!Func || !isFirstInExternCContext(Func)))
>>> -  return LinkageInfo::uniqueExternal();
>>> +  return getInternalLinkageFor(D);
>>>}
>>>
>>>// Set up the defaults.
>>> @@ -1130,7 +1130,7 @@ LinkageInfo LinkageComputer::getLVForLoc
>>>if (const auto *Function = dyn_cast(D)) {
>>>  if (Function->isInAnonymousNamespace() &&
>>>  !Function->isInExternCContext())
>>> -  return LinkageInfo::uniqueExternal();
>>> +  return getInternalLinkageFor(Function);
>>>
>>>  // This is a "void f();" which got merged with a file static.
>>>  if (Function->getCanonicalDecl()->getStorageClass() == SC_Static)
>>> @@ -1153,7 +1153,7 @@ LinkageInfo LinkageComputer::getLVForLoc
>>>if (const auto *Var = dyn_cast(D)) {
>>>  if (Var->hasExternalStorage()) {
>>>if (Var->isInAnonymousNamespace() && !Var->isInExternCContext())
>>> -return LinkageInfo::uniqueExternal();
>>> +return getInternalLinkageFor(Var);
>>>
>>>LinkageInfo LV;
>>>if (Var->getStorageClass() == SC_PrivateExtern)
>>>
>>> Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Itaniu
>>> mMangle.cpp?rev=314037=314036=314037=diff
>>> 
>>> ==
>>> --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
>>> +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Sep 22 15:21:44 2017
>>> @@ -1287,9 +1287,15 @@ void CXXNameMangler::mangleUnqualifiedNa
>>>//
>>>//   void test() { extern void foo(); }
>>>//   static void foo();
>>> +  //
>>> +  // Don't bother with the L marker for names in anonymous
>>> namespaces; the
>>> +  // 12_GLOBAL__N_1 mangling 

[clang-tools-extra] r314047 - Fix up clang-tidy after clang r314037.

2017-09-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Sep 22 16:47:20 2017
New Revision: 314047

URL: http://llvm.org/viewvc/llvm-project?rev=314047=rev
Log:
Fix up clang-tidy after clang r314037.

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

clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h

Modified: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp?rev=314047=314046=314047=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp Fri 
Sep 22 16:47:20 2017
@@ -94,7 +94,10 @@ void DefinitionsInHeadersCheck::check(co
   //
   // Although these might also cause ODR violations, we can be less certain and
   // should try to keep the false-positive rate down.
-  if (ND->getLinkageInternal() == InternalLinkage)
+  //
+  // FIXME: Should declarations in anonymous namespaces get the same treatment
+  // as static / const declarations?
+  if (!ND->hasExternalFormalLinkage() && !ND->isInAnonymousNamespace())
 return;
 
   if (const auto *FD = dyn_cast(ND)) {

Modified: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h?rev=314047=314046=314047=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h 
Fri Sep 22 16:47:20 2017
@@ -6,20 +6,20 @@ class default_delete {};
 template >
 class unique_ptr {
 public:
-  unique_ptr();
-  unique_ptr(type *ptr);
+  unique_ptr() {}
+  unique_ptr(type *ptr) {}
   unique_ptr(const unique_ptr ) = delete;
-  unique_ptr(unique_ptr &);
-  ~unique_ptr();
+  unique_ptr(unique_ptr &) {}
+  ~unique_ptr() {}
   type *() { return *ptr; }
   type *operator->() { return ptr; }
-  type *release();
-  void reset();
-  void reset(type *pt);
-  void reset(type pt);
-  unique_ptr =(unique_ptr &&);
+  type *release() { return ptr; }
+  void reset() {}
+  void reset(type *pt) {}
+  void reset(type pt) {}
+  unique_ptr =(unique_ptr &&) { return *this; }
   template 
-  unique_ptr =(unique_ptr &&);
+  unique_ptr =(unique_ptr &&) { return *this; }
 
 private:
   type *ptr;


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


Re: r314037 - DR1113: anonymous namespaces formally give their contents internal linkage.

2017-09-22 Thread Richard Smith via cfe-commits
Investigating...

On 22 September 2017 at 15:58, Vitaly Buka via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> This breaks check-clang-tools
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_
> 64-scei-ps4-windows10pro-fast/builds/12310/steps/test/logs/stdio
>
> On Fri, Sep 22, 2017 at 3:21 PM, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: rsmith
>> Date: Fri Sep 22 15:21:44 2017
>> New Revision: 314037
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=314037=rev
>> Log:
>> DR1113: anonymous namespaces formally give their contents internal
>> linkage.
>>
>> This doesn't affect our code generation in any material way -- we already
>> give
>> such declarations internal linkage from a codegen perspective -- but it
>> has
>> some subtle effects on code validity.
>>
>> We suppress the 'L' (internal linkage) marker for mangled names in
>> anonymous
>> namespaces, because it is redundant (the information is already carried
>> by the
>> namespace); this deviates from GCC's behavior if a variable or function
>> in an
>> anonymous namespace is redundantly declared 'static' (where GCC does
>> include
>> the 'L'), but GCC's behavior is incoherent because such a declaration can
>> be
>> validly declared with or without the 'static'.
>>
>> We still deviate from the standard in one regard here: extern "C"
>> declarations
>> in anonymous namespaces are still granted external linkage. Changing
>> those does
>> not appear to have been an intentional consequence of the standard change
>> in
>> DR1113.
>>
>> Added:
>> cfe/trunk/test/CXX/drs/dr11xx.cpp
>> Modified:
>> cfe/trunk/lib/AST/Decl.cpp
>> cfe/trunk/lib/AST/ItaniumMangle.cpp
>> cfe/trunk/test/CXX/basic/basic.link/p8.cpp
>> cfe/trunk/test/CodeGenCXX/anonymous-namespaces.cpp
>> cfe/trunk/test/SemaCXX/linkage2.cpp
>> cfe/trunk/test/SemaCXX/undefined-internal.cpp
>>
>> Modified: cfe/trunk/lib/AST/Decl.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.
>> cpp?rev=314037=314036=314037=diff
>> 
>> ==
>> --- cfe/trunk/lib/AST/Decl.cpp (original)
>> +++ cfe/trunk/lib/AST/Decl.cpp Fri Sep 22 15:21:44 2017
>> @@ -619,16 +619,16 @@ LinkageComputer::getLVForNamespaceScopeD
>>if (D->isInAnonymousNamespace()) {
>>  const auto *Var = dyn_cast(D);
>>  const auto *Func = dyn_cast(D);
>> -// FIXME: In C++11 onwards, anonymous namespaces should give decls
>> -// within them (including those inside extern "C" contexts) internal
>> -// linkage, not unique external linkage:
>> +// FIXME: The check for extern "C" here is not justified by the
>> standard
>> +// wording, but we retain it from the pre-DR1113 model to avoid
>> breaking
>> +// code.
>>  //
>>  // C++11 [basic.link]p4:
>>  //   An unnamed namespace or a namespace declared directly or
>> indirectly
>>  //   within an unnamed namespace has internal linkage.
>>  if ((!Var || !isFirstInExternCContext(Var)) &&
>>  (!Func || !isFirstInExternCContext(Func)))
>> -  return LinkageInfo::uniqueExternal();
>> +  return getInternalLinkageFor(D);
>>}
>>
>>// Set up the defaults.
>> @@ -1130,7 +1130,7 @@ LinkageInfo LinkageComputer::getLVForLoc
>>if (const auto *Function = dyn_cast(D)) {
>>  if (Function->isInAnonymousNamespace() &&
>>  !Function->isInExternCContext())
>> -  return LinkageInfo::uniqueExternal();
>> +  return getInternalLinkageFor(Function);
>>
>>  // This is a "void f();" which got merged with a file static.
>>  if (Function->getCanonicalDecl()->getStorageClass() == SC_Static)
>> @@ -1153,7 +1153,7 @@ LinkageInfo LinkageComputer::getLVForLoc
>>if (const auto *Var = dyn_cast(D)) {
>>  if (Var->hasExternalStorage()) {
>>if (Var->isInAnonymousNamespace() && !Var->isInExternCContext())
>> -return LinkageInfo::uniqueExternal();
>> +return getInternalLinkageFor(Var);
>>
>>LinkageInfo LV;
>>if (Var->getStorageClass() == SC_PrivateExtern)
>>
>> Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Itaniu
>> mMangle.cpp?rev=314037=314036=314037=diff
>> 
>> ==
>> --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
>> +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Sep 22 15:21:44 2017
>> @@ -1287,9 +1287,15 @@ void CXXNameMangler::mangleUnqualifiedNa
>>//
>>//   void test() { extern void foo(); }
>>//   static void foo();
>> +  //
>> +  // Don't bother with the L marker for names in anonymous
>> namespaces; the
>> +  // 12_GLOBAL__N_1 mangling is quite sufficient there, and this
>> better
>> +  // matches GCC anyway, because GCC does not treat anonymous
>> namespaces as
>> +  // implying internal linkage.
>>if (ND && 

r314042 - [Analyzer] Fix minor errors in python scripts.

2017-09-22 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Fri Sep 22 15:58:46 2017
New Revision: 314042

URL: http://llvm.org/viewvc/llvm-project?rev=314042=rev
Log:
[Analyzer] Fix minor errors in python scripts.

Modified:
cfe/trunk/utils/analyzer/SATestBuild.py
cfe/trunk/utils/analyzer/SATestUpdateDiffs.py

Modified: cfe/trunk/utils/analyzer/SATestBuild.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/SATestBuild.py?rev=314042=314041=314042=diff
==
--- cfe/trunk/utils/analyzer/SATestBuild.py (original)
+++ cfe/trunk/utils/analyzer/SATestBuild.py Fri Sep 22 15:58:46 2017
@@ -485,7 +485,6 @@ def checkBuild(SBOutputDir):
% (NumOfFailuresInSummary,))
 # TODO: Add a line "See the results folder for more."
 
-FailuresCopied = NumOfFailuresInSummary
 Idx = 0
 for FailLogPathI in Failures:
 if Idx >= NumOfFailuresInSummary:

Modified: cfe/trunk/utils/analyzer/SATestUpdateDiffs.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/SATestUpdateDiffs.py?rev=314042=314041=314042=diff
==
--- cfe/trunk/utils/analyzer/SATestUpdateDiffs.py (original)
+++ cfe/trunk/utils/analyzer/SATestUpdateDiffs.py Fri Sep 22 15:58:46 2017
@@ -4,8 +4,9 @@
 Update reference results for static analyzer.
 """
 
-from subprocess import check_call, check_output, CalledProcessError
-import csv
+import SATestBuild
+
+from subprocess import check_call
 import os
 import sys
 
@@ -35,8 +36,7 @@ def updateReferenceResults(ProjName, Pro
 runCmd('cp -r "%s" "%s"' % (CreatedResultsPath, RefResultsPath,))
 
 # Run cleanup script.
-with open(SATestBuild.getBuildLogPath(RefResultsPath), "wb+")
-as PBuildLogFile:
+with open(SATestBuild.getBuildLogPath(RefResultsPath), "wb+") as 
PBuildLogFile:
 SATestBuild.runCleanupScript(ProjDir, PBuildLogFile)
 
 SATestBuild.normalizeReferenceResults(ProjDir, RefResultsPath, 
ProjBuildMode)
@@ -52,7 +52,7 @@ def updateReferenceResults(ProjName, Pro
 def main(argv):
 if len(argv) == 2 and argv[1] in ('-h', '--help'):
 print >> sys.stderr, "Update static analyzer reference results based "\
- "\non the previous run of SATestBuild.py.\n"
+ "\non the previous run of SATestBuild.py.\n"\
  "\nN.B.: Assumes that SATestBuild.py was just 
run."
 sys.exit(-1)
 


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


Re: r314037 - DR1113: anonymous namespaces formally give their contents internal linkage.

2017-09-22 Thread Vitaly Buka via cfe-commits
This breaks check-clang-tools
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/12310/steps/test/logs/stdio

On Fri, Sep 22, 2017 at 3:21 PM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Fri Sep 22 15:21:44 2017
> New Revision: 314037
>
> URL: http://llvm.org/viewvc/llvm-project?rev=314037=rev
> Log:
> DR1113: anonymous namespaces formally give their contents internal linkage.
>
> This doesn't affect our code generation in any material way -- we already
> give
> such declarations internal linkage from a codegen perspective -- but it has
> some subtle effects on code validity.
>
> We suppress the 'L' (internal linkage) marker for mangled names in
> anonymous
> namespaces, because it is redundant (the information is already carried by
> the
> namespace); this deviates from GCC's behavior if a variable or function in
> an
> anonymous namespace is redundantly declared 'static' (where GCC does
> include
> the 'L'), but GCC's behavior is incoherent because such a declaration can
> be
> validly declared with or without the 'static'.
>
> We still deviate from the standard in one regard here: extern "C"
> declarations
> in anonymous namespaces are still granted external linkage. Changing those
> does
> not appear to have been an intentional consequence of the standard change
> in
> DR1113.
>
> Added:
> cfe/trunk/test/CXX/drs/dr11xx.cpp
> Modified:
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/lib/AST/ItaniumMangle.cpp
> cfe/trunk/test/CXX/basic/basic.link/p8.cpp
> cfe/trunk/test/CodeGenCXX/anonymous-namespaces.cpp
> cfe/trunk/test/SemaCXX/linkage2.cpp
> cfe/trunk/test/SemaCXX/undefined-internal.cpp
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> Decl.cpp?rev=314037=314036=314037=diff
> 
> ==
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Fri Sep 22 15:21:44 2017
> @@ -619,16 +619,16 @@ LinkageComputer::getLVForNamespaceScopeD
>if (D->isInAnonymousNamespace()) {
>  const auto *Var = dyn_cast(D);
>  const auto *Func = dyn_cast(D);
> -// FIXME: In C++11 onwards, anonymous namespaces should give decls
> -// within them (including those inside extern "C" contexts) internal
> -// linkage, not unique external linkage:
> +// FIXME: The check for extern "C" here is not justified by the
> standard
> +// wording, but we retain it from the pre-DR1113 model to avoid
> breaking
> +// code.
>  //
>  // C++11 [basic.link]p4:
>  //   An unnamed namespace or a namespace declared directly or
> indirectly
>  //   within an unnamed namespace has internal linkage.
>  if ((!Var || !isFirstInExternCContext(Var)) &&
>  (!Func || !isFirstInExternCContext(Func)))
> -  return LinkageInfo::uniqueExternal();
> +  return getInternalLinkageFor(D);
>}
>
>// Set up the defaults.
> @@ -1130,7 +1130,7 @@ LinkageInfo LinkageComputer::getLVForLoc
>if (const auto *Function = dyn_cast(D)) {
>  if (Function->isInAnonymousNamespace() &&
>  !Function->isInExternCContext())
> -  return LinkageInfo::uniqueExternal();
> +  return getInternalLinkageFor(Function);
>
>  // This is a "void f();" which got merged with a file static.
>  if (Function->getCanonicalDecl()->getStorageClass() == SC_Static)
> @@ -1153,7 +1153,7 @@ LinkageInfo LinkageComputer::getLVForLoc
>if (const auto *Var = dyn_cast(D)) {
>  if (Var->hasExternalStorage()) {
>if (Var->isInAnonymousNamespace() && !Var->isInExternCContext())
> -return LinkageInfo::uniqueExternal();
> +return getInternalLinkageFor(Var);
>
>LinkageInfo LV;
>if (Var->getStorageClass() == SC_PrivateExtern)
>
> Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ItaniumMangle.cpp?rev=314037=314036=314037=diff
> 
> ==
> --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
> +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Sep 22 15:21:44 2017
> @@ -1287,9 +1287,15 @@ void CXXNameMangler::mangleUnqualifiedNa
>//
>//   void test() { extern void foo(); }
>//   static void foo();
> +  //
> +  // Don't bother with the L marker for names in anonymous
> namespaces; the
> +  // 12_GLOBAL__N_1 mangling is quite sufficient there, and this
> better
> +  // matches GCC anyway, because GCC does not treat anonymous
> namespaces as
> +  // implying internal linkage.
>if (ND && ND->getFormalLinkage() == InternalLinkage &&
>!ND->isExternallyVisible() &&
> -  getEffectiveDeclContext(ND)->isFileContext())
> +  getEffectiveDeclContext(ND)->isFileContext() &&
> +  !ND->isInAnonymousNamespace())
>  Out 

r314037 - DR1113: anonymous namespaces formally give their contents internal linkage.

2017-09-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Sep 22 15:21:44 2017
New Revision: 314037

URL: http://llvm.org/viewvc/llvm-project?rev=314037=rev
Log:
DR1113: anonymous namespaces formally give their contents internal linkage.

This doesn't affect our code generation in any material way -- we already give
such declarations internal linkage from a codegen perspective -- but it has
some subtle effects on code validity.

We suppress the 'L' (internal linkage) marker for mangled names in anonymous
namespaces, because it is redundant (the information is already carried by the
namespace); this deviates from GCC's behavior if a variable or function in an
anonymous namespace is redundantly declared 'static' (where GCC does include
the 'L'), but GCC's behavior is incoherent because such a declaration can be
validly declared with or without the 'static'.

We still deviate from the standard in one regard here: extern "C" declarations
in anonymous namespaces are still granted external linkage. Changing those does
not appear to have been an intentional consequence of the standard change in
DR1113.

Added:
cfe/trunk/test/CXX/drs/dr11xx.cpp
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/test/CXX/basic/basic.link/p8.cpp
cfe/trunk/test/CodeGenCXX/anonymous-namespaces.cpp
cfe/trunk/test/SemaCXX/linkage2.cpp
cfe/trunk/test/SemaCXX/undefined-internal.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=314037=314036=314037=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Sep 22 15:21:44 2017
@@ -619,16 +619,16 @@ LinkageComputer::getLVForNamespaceScopeD
   if (D->isInAnonymousNamespace()) {
 const auto *Var = dyn_cast(D);
 const auto *Func = dyn_cast(D);
-// FIXME: In C++11 onwards, anonymous namespaces should give decls
-// within them (including those inside extern "C" contexts) internal
-// linkage, not unique external linkage:
+// FIXME: The check for extern "C" here is not justified by the standard
+// wording, but we retain it from the pre-DR1113 model to avoid breaking
+// code.
 //
 // C++11 [basic.link]p4:
 //   An unnamed namespace or a namespace declared directly or indirectly
 //   within an unnamed namespace has internal linkage.
 if ((!Var || !isFirstInExternCContext(Var)) &&
 (!Func || !isFirstInExternCContext(Func)))
-  return LinkageInfo::uniqueExternal();
+  return getInternalLinkageFor(D);
   }
 
   // Set up the defaults.
@@ -1130,7 +1130,7 @@ LinkageInfo LinkageComputer::getLVForLoc
   if (const auto *Function = dyn_cast(D)) {
 if (Function->isInAnonymousNamespace() &&
 !Function->isInExternCContext())
-  return LinkageInfo::uniqueExternal();
+  return getInternalLinkageFor(Function);
 
 // This is a "void f();" which got merged with a file static.
 if (Function->getCanonicalDecl()->getStorageClass() == SC_Static)
@@ -1153,7 +1153,7 @@ LinkageInfo LinkageComputer::getLVForLoc
   if (const auto *Var = dyn_cast(D)) {
 if (Var->hasExternalStorage()) {
   if (Var->isInAnonymousNamespace() && !Var->isInExternCContext())
-return LinkageInfo::uniqueExternal();
+return getInternalLinkageFor(Var);
 
   LinkageInfo LV;
   if (Var->getStorageClass() == SC_PrivateExtern)

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=314037=314036=314037=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Sep 22 15:21:44 2017
@@ -1287,9 +1287,15 @@ void CXXNameMangler::mangleUnqualifiedNa
   //
   //   void test() { extern void foo(); }
   //   static void foo();
+  //
+  // Don't bother with the L marker for names in anonymous namespaces; the
+  // 12_GLOBAL__N_1 mangling is quite sufficient there, and this better
+  // matches GCC anyway, because GCC does not treat anonymous namespaces as
+  // implying internal linkage.
   if (ND && ND->getFormalLinkage() == InternalLinkage &&
   !ND->isExternallyVisible() &&
-  getEffectiveDeclContext(ND)->isFileContext())
+  getEffectiveDeclContext(ND)->isFileContext() &&
+  !ND->isInAnonymousNamespace())
 Out << 'L';
 
   auto *FD = dyn_cast(ND);

Modified: cfe/trunk/test/CXX/basic/basic.link/p8.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.link/p8.cpp?rev=314037=314036=314037=diff
==
--- cfe/trunk/test/CXX/basic/basic.link/p8.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.link/p8.cpp Fri Sep 22 15:21:44 2017
@@ -52,6 +52,13 @@ void use_visible_no_linkage() {
   

r314036 - [test] Enable clang-func-mapping as a test dep with the analyzer

2017-09-22 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Sep 22 15:17:10 2017
New Revision: 314036

URL: http://llvm.org/viewvc/llvm-project?rev=314036=rev
Log:
[test] Enable clang-func-mapping as a test dep with the analyzer

clang-func-mapping should not be a test dependency when the static
analyzer isn't being built.

Modified:
cfe/trunk/test/CMakeLists.txt

Modified: cfe/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=314036=314035=314036=diff
==
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Fri Sep 22 15:17:10 2017
@@ -54,12 +54,12 @@ list(APPEND CLANG_TEST_DEPS
   clang-rename
   clang-refactor
   clang-diff
-  clang-func-mapping
   )
   
 if(CLANG_ENABLE_STATIC_ANALYZER)
   list(APPEND CLANG_TEST_DEPS
 clang-check
+clang-func-mapping
 )
 endif()
 


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


r314035 - Fix unused variable warning in non-debug builds.

2017-09-22 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Fri Sep 22 15:16:13 2017
New Revision: 314035

URL: http://llvm.org/viewvc/llvm-project?rev=314035=rev
Log:
Fix unused variable warning in non-debug builds.

Modified:
cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp

Modified: cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp?rev=314035=314034=314035=diff
==
--- cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp (original)
+++ cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp Fri Sep 22 15:16:13 2017
@@ -121,7 +121,7 @@ CrossTranslationUnitContext::~CrossTrans
 
 std::string CrossTranslationUnitContext::getLookupName(const NamedDecl *ND) {
   SmallString<128> DeclUSR;
-  bool Ret = index::generateUSRForDecl(ND, DeclUSR);
+  bool Ret = index::generateUSRForDecl(ND, DeclUSR); (void)Ret;
   assert(!Ret && "Unable to generate USR");
   return DeclUSR.str();
 }


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


r314033 - clang-format plugin: Add missing NL (new line) at EOF (end of file)

2017-09-22 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Sep 22 14:47:39 2017
New Revision: 314033

URL: http://llvm.org/viewvc/llvm-project?rev=314033=rev
Log:
clang-format plugin: Add missing NL (new line) at EOF (end of file)

clang-format.exe removes trailing new lines at end of file.

However, if no NL is found at EOF one should be added.

Patch by Teodor MICU!

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

Modified:
cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs

Modified: cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs?rev=314033=314032=314033=diff
==
--- cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs (original)
+++ cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs Fri Sep 
22 14:47:39 2017
@@ -326,7 +326,13 @@ namespace LLVM.ClangFormat
 
 string filePath = Vsix.GetDocumentPath(view);
 var path = Path.GetDirectoryName(filePath);
+
 string text = view.TextBuffer.CurrentSnapshot.GetText();
+if (!text.EndsWith(Environment.NewLine))
+{
+view.TextBuffer.Insert(view.TextBuffer.CurrentSnapshot.Length, 
Environment.NewLine);
+text += Environment.NewLine;
+}
 
 RunClangFormatAndApplyReplacements(text, 0, text.Length, path, 
filePath, options, view);
 }


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


r314029 - [CodeGen][ObjC] Build the global block structure before emitting the

2017-09-22 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Sep 22 14:32:06 2017
New Revision: 314029

URL: http://llvm.org/viewvc/llvm-project?rev=314029=rev
Log:
[CodeGen][ObjC] Build the global block structure before emitting the
body of global block invoke functions.

This commit fixes an infinite loop in IRGen that occurs when compiling
the following code:

void FUNC2() {
  static void (^const block1)(int) = ^(int a){
if (a--)
  block1(a);
  };
}

This is how IRGen gets stuck in the infinite loop:

1. GenerateBlockFunction is called to emit the body of "block1".

2. GetAddrOfGlobalBlock is called to get the address of "block1". The
   function calls getAddrOfGlobalBlockIfEmitted to check whether the
   global block has been emitted. If it hasn't been emitted, it then
   tries to emit the body of the block function by calling
   GenerateBlockFunction, which goes back to step 1.

This commit prevents the inifinite loop by building the global block in
GenerateBlockFunction before emitting the body of the block function.

rdar://problem/34541684

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

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGen/mangle-blocks.c
cfe/trunk/test/CodeGenObjC/local-static-block.m
cfe/trunk/test/CodeGenObjC/mangle-blocks.m

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=314029=314028=314029=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Sep 22 14:32:06 2017
@@ -725,12 +725,13 @@ llvm::Value *CodeGenFunction::EmitBlockL
   llvm::Constant *blockFn
 = CodeGenFunction(CGM, true).GenerateBlockFunction(CurGD, blockInfo,
LocalDeclMap,
-   isLambdaConv);
+   isLambdaConv,
+   blockInfo.CanBeGlobal);
   blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy);
 
   // If there is nothing to capture, we can emit this as a global block.
   if (blockInfo.CanBeGlobal)
-return buildGlobalBlock(CGM, blockInfo, blockFn);
+return CGM.getAddrOfGlobalBlockIfEmitted(blockInfo.BlockExpression);
 
   // Otherwise, we have to emit this as a local block.
 
@@ -1114,17 +1115,14 @@ CodeGenModule::GetAddrOfGlobalBlock(cons
   computeBlockInfo(*this, nullptr, blockInfo);
 
   // Using that metadata, generate the actual block function.
-  llvm::Constant *blockFn;
   {
 CodeGenFunction::DeclMapTy LocalDeclMap;
-blockFn = CodeGenFunction(*this).GenerateBlockFunction(GlobalDecl(),
-   blockInfo,
-   LocalDeclMap,
-   false);
+CodeGenFunction(*this).GenerateBlockFunction(
+GlobalDecl(), blockInfo, LocalDeclMap,
+/*IsLambdaConversionToBlock*/ false, /*BuildGlobalBlock*/ true);
   }
-  blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy);
 
-  return buildGlobalBlock(*this, blockInfo, blockFn);
+  return getAddrOfGlobalBlockIfEmitted(BE);
 }
 
 static llvm::Constant *buildGlobalBlock(CodeGenModule ,
@@ -1226,7 +1224,8 @@ llvm::Function *
 CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
const CGBlockInfo ,
const DeclMapTy ,
-   bool IsLambdaConversionToBlock) {
+   bool IsLambdaConversionToBlock,
+   bool BuildGlobalBlock) {
   const BlockDecl *blockDecl = blockInfo.getBlockDecl();
 
   CurGD = GD;
@@ -1285,6 +1284,10 @@ CodeGenFunction::GenerateBlockFunction(G
   fnLLVMType, llvm::GlobalValue::InternalLinkage, name, ());
   CGM.SetInternalFunctionAttributes(blockDecl, fn, fnInfo);
 
+  if (BuildGlobalBlock)
+buildGlobalBlock(CGM, blockInfo,
+ llvm::ConstantExpr::getBitCast(fn, VoidPtrTy));
+
   // Begin generating the function.
   StartFunction(blockDecl, fnType->getReturnType(), fn, fnInfo, args,
 blockDecl->getLocation(),

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=314029=314028=314029=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Sep 22 14:32:06 2017
@@ -1586,7 +1586,8 @@ public:
   llvm::Function *GenerateBlockFunction(GlobalDecl GD,
 const CGBlockInfo ,
 const DeclMapTy ,
-   

[PATCH] D38151: [clang] Fix isExternC matcher docs

2017-09-22 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314022: [clang] Fix isExternC matcher docs (authored by 
alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D38151?vs=116251=116386#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38151

Files:
  cfe/trunk/docs/LibASTMatchersReference.html
  cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h


Index: cfe/trunk/docs/LibASTMatchersReference.html
===
--- cfe/trunk/docs/LibASTMatchersReference.html
+++ cfe/trunk/docs/LibASTMatchersReference.html
@@ -2741,19 +2741,22 @@
 Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html;>CXXRecordDecl
 
 
-
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisExternC
-Matches extern "C" 
function declarations.
+Matches extern "C" 
function or variable declarations.
 
 Given:
   extern "C" void f() {}
   extern "C" { void g() {} }
   void h() {}
+  extern "C" int x = 1;
+  extern "C" int y = 2;
+  int z = 3;
 functionDecl(isExternC())
-  matches the declaration of f and g, but not the declaration h
+  matches the declaration of f and g, but not the declaration of h.
+varDecl(isExternC())
+  matches the declaration of x and y, but not the declaration of z.
 
 
-
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisInline
 Matches function and 
namespace declarations that are marked with
 the inline keyword.
@@ -3680,19 +3683,22 @@
 Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html;>CXXRecordDecl
 
 
-
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDeclisExternC
-Matches extern "C" 
function declarations.
+Matches extern "C" 
function or variable declarations.
 
 Given:
   extern "C" void f() {}
   extern "C" { void g() {} }
   void h() {}
+  extern "C" int x = 1;
+  extern "C" int y = 2;
+  int z = 3;
 functionDecl(isExternC())
-  matches the declaration of f and g, but not the declaration h
+  matches the declaration of f and g, but not the declaration of h.
+varDecl(isExternC())
+  matches the declaration of x and y, but not the declaration of z.
 
 
-
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDeclisStaticStorageClass
 Matches 
variablefunction declarations that have "static" storage
 class specifier ("static" keyword) written in the source.
Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
===
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
@@ -3533,16 +3533,21 @@
   return InnerMatcher.matches(Node.getReturnType(), Finder, Builder);
 }
 
-/// \brief Matches extern "C" function declarations.
+/// \brief Matches extern "C" function or variable declarations.
 ///
 /// Given:
 /// \code
 ///   extern "C" void f() {}
 ///   extern "C" { void g() {} }
 ///   void h() {}
+///   extern "C" int x = 1;
+///   extern "C" int y = 2;
+///   int z = 3;
 /// \endcode
 /// functionDecl(isExternC())
-///   matches the declaration of f and g, but not the declaration h
+///   matches the declaration of f and g, but not the declaration of h.
+/// varDecl(isExternC())
+///   matches the declaration of x and y, but not the declaration of z.
 AST_POLYMORPHIC_MATCHER(isExternC, 
AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
VarDecl)) {
   return Node.isExternC();


Index: cfe/trunk/docs/LibASTMatchersReference.html
===
--- cfe/trunk/docs/LibASTMatchersReference.html
+++ cfe/trunk/docs/LibASTMatchersReference.html
@@ -2741,19 +2741,22 @@
 Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html;>CXXRecordDecl
 
 
-
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisExternC
-Matches extern "C" function declarations.
+Matches extern "C" function or variable declarations.
 
 Given:
   extern "C" void f() {}
   extern "C" { void g() {} }
   void h() {}
+  extern "C" int x = 1;
+  extern "C" int y = 2;
+  int z = 3;
 functionDecl(isExternC())
-  matches the declaration of f and g, but not the declaration h
+  matches the declaration of f and g, but not the declaration of h.
+varDecl(isExternC())
+  matches the declaration of x and y, but not the declaration of z.
 
 
-
 

[PATCH] D38186: Add the new -Wnull-pointer-arithmetic warnings to the release notes

2017-09-22 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru created this revision.
sylvestre.ledru added a project: clang.

https://reviews.llvm.org/D38186

Files:
  ReleaseNotes.rst


Index: ReleaseNotes.rst
===
--- ReleaseNotes.rst
+++ ReleaseNotes.rst
@@ -78,6 +78,12 @@
   when the signed integer is coerced to an unsigned type for the comparison.
   ``-Wsign-compare`` was adjusted not to warn in this case.
 
+- ``-Wnull-pointer-arithmetic`` now warns about performing pointer arithmetic
+  on a null pointer. It has an undefined behavior if the offset is nonzero.
+
+- ``-Wnull-pointer-arithmetic`` now warns about arithmetic on a null pointer
+  treated as a cast from integer to pointer (GNU extension).
+
 Non-comprehensive list of changes in this release
 -
 


Index: ReleaseNotes.rst
===
--- ReleaseNotes.rst
+++ ReleaseNotes.rst
@@ -78,6 +78,12 @@
   when the signed integer is coerced to an unsigned type for the comparison.
   ``-Wsign-compare`` was adjusted not to warn in this case.
 
+- ``-Wnull-pointer-arithmetic`` now warns about performing pointer arithmetic
+  on a null pointer. It has an undefined behavior if the offset is nonzero.
+
+- ``-Wnull-pointer-arithmetic`` now warns about arithmetic on a null pointer
+  treated as a cast from integer to pointer (GNU extension).
+
 Non-comprehensive list of changes in this release
 -
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36150: [clangd] LSP extension to switch between source/header file

2017-09-22 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 116387.
Nebiroth marked 2 inline comments as done.
Nebiroth added a comment.

Rebased on latest version.
Corrected code style issues in test file.


https://reviews.llvm.org/D36150

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "ClangdLSPServer.h"
 #include "ClangdServer.h"
 #include "Logger.h"
 #include "clang/Basic/VirtualFileSystem.h"
@@ -899,6 +900,84 @@
   }
 }
 
+TEST_F(ClangdVFSTest, CheckSourceHeaderSwitch) {
+  MockFSProvider FS;
+  ErrorCheckingDiagConsumer DiagConsumer;
+  MockCompilationDatabase CDB(/*AddFreestandingFlag=*/true);
+
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*SnippetCompletions=*/false, EmptyLogger::getInstance());
+
+  auto SourceContents = R"cpp(
+  #include "foo.h"
+  int b = a;
+  )cpp";
+
+  auto FooCpp = getVirtualTestFilePath("foo.cpp");
+  auto FooH = getVirtualTestFilePath("foo.h");
+  auto Invalid = getVirtualTestFilePath("main.cpp");
+
+  FS.Files[FooCpp] = SourceContents;
+  FS.Files[FooH] = "int a;";
+  FS.Files[Invalid] = "int main() { \n return 0; \n }";
+
+  llvm::Optional PathResult = Server.switchSourceHeader(FooCpp);
+  EXPECT_TRUE(PathResult.hasValue());
+  ASSERT_EQ(PathResult.getValue(), FooH);
+
+  PathResult = Server.switchSourceHeader(FooH);
+  EXPECT_TRUE(PathResult.hasValue());
+  ASSERT_EQ(PathResult.getValue(), FooCpp);
+
+  SourceContents = R"c(
+  #include "foo.HH"
+  int b = a;
+  )c";
+
+  // Test with header file in capital letters and different extension, source
+  // file with different extension
+  auto FooC = getVirtualTestFilePath("bar.c");
+  auto FooHH = getVirtualTestFilePath("bar.HH");
+
+  FS.Files[FooC] = SourceContents;
+  FS.Files[FooHH] = "int a;";
+
+  PathResult = Server.switchSourceHeader(FooC);
+  EXPECT_TRUE(PathResult.hasValue());
+  ASSERT_EQ(PathResult.getValue(), FooHH);
+
+  // Test with both capital letters
+  auto Foo2C = getVirtualTestFilePath("foo2.C");
+  auto Foo2HH = getVirtualTestFilePath("foo2.HH");
+  FS.Files[Foo2C] = SourceContents;
+  FS.Files[Foo2HH] = "int a;";
+
+  PathResult = Server.switchSourceHeader(Foo2C);
+  EXPECT_TRUE(PathResult.hasValue());
+  ASSERT_EQ(PathResult.getValue(), Foo2HH);
+
+  // Test with source file as capital letter and .hxx header file
+  auto Foo3C = getVirtualTestFilePath("foo3.C");
+  auto Foo3HXX = getVirtualTestFilePath("foo3.hxx");
+
+  SourceContents = R"c(
+  #include "foo3.hxx"
+  int b = a;
+  )c";
+
+  FS.Files[Foo3C] = SourceContents;
+  FS.Files[Foo3HXX] = "int a;";
+
+  PathResult = Server.switchSourceHeader(Foo3C);
+  EXPECT_TRUE(PathResult.hasValue());
+  ASSERT_EQ(PathResult.getValue(), Foo3HXX);
+
+  // Test if asking for a corresponding file that doesn't exist returns an empty
+  // string.
+  PathResult = Server.switchSourceHeader(Invalid);
+  EXPECT_FALSE(PathResult.hasValue());
+}
+
 TEST_F(ClangdThreadingTest, NoConcurrentDiagnostics) {
   class NoConcurrentAccessDiagConsumer : public DiagnosticsConsumer {
   public:
Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -48,6 +48,8 @@
 JSONOutput ) = 0;
   virtual void onGoToDefinition(TextDocumentPositionParams Params, StringRef ID,
 JSONOutput ) = 0;
+  virtual void onSwitchSourceHeader(TextDocumentIdentifier Params, StringRef ID,
+JSONOutput ) = 0;  
 };
 
 void regiterCallbackHandlers(JSONRPCDispatcher , JSONOutput ,
Index: clangd/ProtocolHandlers.cpp
===
--- clangd/ProtocolHandlers.cpp
+++ clangd/ProtocolHandlers.cpp
@@ -204,6 +204,22 @@
   ProtocolCallbacks 
 };
 
+struct SwitchSourceHeaderHandler : Handler {
+  SwitchSourceHeaderHandler(JSONOutput , ProtocolCallbacks )
+  : Handler(Output), Callbacks(Callbacks) {}
+
+  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override {
+auto TDPP = TextDocumentIdentifier::parse(Params, Output);
+if (!TDPP)
+  return;
+
+Callbacks.onSwitchSourceHeader(*TDPP, ID, Output);
+  }
+
+private:
+  ProtocolCallbacks 
+};
+
 } // namespace
 
 void clangd::regiterCallbackHandlers(JSONRPCDispatcher ,
@@ -240,4 +256,7 @@
   Dispatcher.registerHandler(
   "textDocument/definition",
   llvm::make_unique(Out, Callbacks));
+  Dispatcher.registerHandler(
+  "textDocument/switchSourceHeader",
+  

r314022 - [clang] Fix isExternC matcher docs

2017-09-22 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Fri Sep 22 12:29:38 2017
New Revision: 314022

URL: http://llvm.org/viewvc/llvm-project?rev=314022=rev
Log:
[clang] Fix isExternC matcher docs

The wording in the documentation for the matcher isExternC 
appears to be misleading since this matcher 
is applicable to functions and variables as well. 
This diff changes the comment and regenerates the html file.

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=314022=314021=314022=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Fri Sep 22 12:29:38 2017
@@ -2741,19 +2741,22 @@ functionDecl(isExplicitTemplateSpecializ
 Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html;>CXXRecordDecl
 
 
-
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisExternC
-Matches extern "C" 
function declarations.
+Matches extern "C" 
function or variable declarations.
 
 Given:
   extern "C" void f() {}
   extern "C" { void g() {} }
   void h() {}
+  extern "C" int x = 1;
+  extern "C" int y = 2;
+  int z = 3;
 functionDecl(isExternC())
-  matches the declaration of f and g, but not the declaration h
+  matches the declaration of f and g, but not the declaration of h.
+varDecl(isExternC())
+  matches the declaration of x and y, but not the declaration of z.
 
 
-
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisInline
 Matches function and 
namespace declarations that are marked with
 the inline keyword.
@@ -3680,19 +3683,22 @@ functionDecl(isExplicitTemplateSpecializ
 Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html;>CXXRecordDecl
 
 
-
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDeclisExternC
-Matches extern "C" 
function declarations.
+Matches extern "C" 
function or variable declarations.
 
 Given:
   extern "C" void f() {}
   extern "C" { void g() {} }
   void h() {}
+  extern "C" int x = 1;
+  extern "C" int y = 2;
+  int z = 3;
 functionDecl(isExternC())
-  matches the declaration of f and g, but not the declaration h
+  matches the declaration of f and g, but not the declaration of h.
+varDecl(isExternC())
+  matches the declaration of x and y, but not the declaration of z.
 
 
-
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDeclisStaticStorageClass
 Matches 
variablefunction declarations that have "static" storage
 class specifier ("static" keyword) written in the source.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=314022=314021=314022=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Sep 22 12:29:38 2017
@@ -3533,16 +3533,21 @@ AST_MATCHER_P(FunctionDecl, returns,
   return InnerMatcher.matches(Node.getReturnType(), Finder, Builder);
 }
 
-/// \brief Matches extern "C" function declarations.
+/// \brief Matches extern "C" function or variable declarations.
 ///
 /// Given:
 /// \code
 ///   extern "C" void f() {}
 ///   extern "C" { void g() {} }
 ///   void h() {}
+///   extern "C" int x = 1;
+///   extern "C" int y = 2;
+///   int z = 3;
 /// \endcode
 /// functionDecl(isExternC())
-///   matches the declaration of f and g, but not the declaration h
+///   matches the declaration of f and g, but not the declaration of h.
+/// varDecl(isExternC())
+///   matches the declaration of x and y, but not the declaration of z.
 AST_POLYMORPHIC_MATCHER(isExternC, 
AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
VarDecl)) {
   return Node.isExternC();


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


[clang-tools-extra] r314020 - [clangd] Updated gold for completion tests after cfe changes.

2017-09-22 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Sep 22 12:07:45 2017
New Revision: 314020

URL: http://llvm.org/viewvc/llvm-project?rev=314020=rev
Log:
[clangd] Updated gold for completion tests after cfe changes.

Modified:
clang-tools-extra/trunk/test/clangd/completion-snippet.test
clang-tools-extra/trunk/test/clangd/completion.test

Modified: clang-tools-extra/trunk/test/clangd/completion-snippet.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion-snippet.test?rev=314020=314019=314020=diff
==
--- clang-tools-extra/trunk/test/clangd/completion-snippet.test (original)
+++ clang-tools-extra/trunk/test/clangd/completion-snippet.test Fri Sep 22 
12:07:45 2017
@@ -19,8 +19,8 @@ Content-Length: 148
 # CHECK-DAG: 
{"label":"a","kind":5,"detail":"int","sortText":"35a","filterText":"a","insertText":"a","insertTextFormat":1}
 # CHECK-DAG: 
{"label":"bb","kind":5,"detail":"int","sortText":"35bb","filterText":"bb","insertText":"bb","insertTextFormat":1}
 # CHECK-DAG: 
{"label":"ccc","kind":5,"detail":"int","sortText":"35ccc","filterText":"ccc","insertText":"ccc","insertTextFormat":1}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake 
&","sortText":"34operator=","filterText":"operator=","insertText":"operator=(${1:const
 fake &})","insertTextFormat":2}
-# CHECK-DAG: 
{"label":"~fake()","kind":4,"detail":"void","sortText":"34~fake","filterText":"~fake","insertText":"~fake()","insertTextFormat":1}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake 
&","sortText":"79operator=","filterText":"operator=","insertText":"operator=(${1:const
 fake &})","insertTextFormat":2}
+# CHECK-DAG: 
{"label":"~fake()","kind":4,"detail":"void","sortText":"79~fake","filterText":"~fake","insertText":"~fake()","insertTextFormat":1}
 # CHECK-DAG: {"label":"f(int i, const float f) 
const","kind":2,"detail":"int","sortText":"35f","filterText":"f","insertText":"f(${1:int
 i}, ${2:const float f})","insertTextFormat":2}
 # CHECK: ]}
 Content-Length: 148
@@ -32,8 +32,8 @@ Content-Length: 148
 # CHECK-DAG: 
{"label":"a","kind":5,"detail":"int","sortText":"35a","filterText":"a","insertText":"a","insertTextFormat":1}
 # CHECK-DAG: 
{"label":"bb","kind":5,"detail":"int","sortText":"35bb","filterText":"bb","insertText":"bb","insertTextFormat":1}
 # CHECK-DAG: 
{"label":"ccc","kind":5,"detail":"int","sortText":"35ccc","filterText":"ccc","insertText":"ccc","insertTextFormat":1}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake 
&","sortText":"34operator=","filterText":"operator=","insertText":"operator=(${1:const
 fake &})","insertTextFormat":2}
-# CHECK-DAG: 
{"label":"~fake()","kind":4,"detail":"void","sortText":"34~fake","filterText":"~fake","insertText":"~fake()","insertTextFormat":1}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake 
&","sortText":"79operator=","filterText":"operator=","insertText":"operator=(${1:const
 fake &})","insertTextFormat":2}
+# CHECK-DAG: 
{"label":"~fake()","kind":4,"detail":"void","sortText":"79~fake","filterText":"~fake","insertText":"~fake()","insertTextFormat":1}
 # CHECK-DAG: {"label":"f(int i, const float f) 
const","kind":2,"detail":"int","sortText":"35f","filterText":"f","insertText":"f(${1:int
 i}, ${2:const float f})","insertTextFormat":2}
 # CHECK: ]}
 # Update the source file and check for completions again.

Modified: clang-tools-extra/trunk/test/clangd/completion.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion.test?rev=314020=314019=314020=diff
==
--- clang-tools-extra/trunk/test/clangd/completion.test (original)
+++ clang-tools-extra/trunk/test/clangd/completion.test Fri Sep 22 12:07:45 2017
@@ -19,8 +19,8 @@ Content-Length: 148
 # CHECK-DAG: 
{"label":"a","kind":5,"detail":"int","sortText":"35a","filterText":"a","insertText":"a","insertTextFormat":1}
 # CHECK-DAG: 
{"label":"bb","kind":5,"detail":"int","sortText":"35bb","filterText":"bb","insertText":"bb","insertTextFormat":1}
 # CHECK-DAG: 
{"label":"ccc","kind":5,"detail":"int","sortText":"35ccc","filterText":"ccc","insertText":"ccc","insertTextFormat":1}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake 
&","sortText":"34operator=","filterText":"operator=","insertText":"operator=","insertTextFormat":1}
-# CHECK-DAG: 
{"label":"~fake()","kind":4,"detail":"void","sortText":"34~fake","filterText":"~fake","insertText":"~fake","insertTextFormat":1}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake 
&","sortText":"79operator=","filterText":"operator=","insertText":"operator=","insertTextFormat":1}
+# CHECK-DAG: 

[PATCH] D38081: Set completion priority of destructors and operators to CCP_Unlikely.

2017-09-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314019: Set completion priority of destructors and operators 
to CCP_Unlikely. (authored by ibiryukov).

Repository:
  rL LLVM

https://reviews.llvm.org/D38081

Files:
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/test/Index/complete-access-checks.cpp
  cfe/trunk/test/Index/complete-cxx-inline-methods.cpp
  cfe/trunk/test/Index/complete-qualified.cpp
  cfe/trunk/test/Index/complete-with-annotations.cpp

Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp
@@ -10,7 +10,7 @@
 //  This file defines the code-completion semantic actions.
 //
 //===--===//
-#include "clang/Sema/SemaInternal.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -23,6 +23,7 @@
 #include "clang/Sema/Overload.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
+#include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -741,8 +742,18 @@
   }
 
   const DeclContext *DC = ND->getDeclContext()->getRedeclContext();
-  if (DC->isRecord() || isa(DC))
+  if (DC->isRecord() || isa(DC)) {
+// Explicit destructor calls are very rare.
+if (isa(ND))
+  return CCP_Unlikely;
+// Explicit operator and conversion function calls are also very rare.
+auto DeclNameKind = ND->getDeclName().getNameKind();
+if (DeclNameKind == DeclarationName::CXXOperatorName ||
+DeclNameKind == DeclarationName::CXXLiteralOperatorName ||
+DeclNameKind == DeclarationName::CXXConversionFunctionName)
+  return CCP_Unlikely;
 return CCP_MemberDeclaration;
+  }
 
   // Content-based decisions.
   if (isa(ND))
Index: cfe/trunk/test/Index/complete-cxx-inline-methods.cpp
===
--- cfe/trunk/test/Index/complete-cxx-inline-methods.cpp
+++ cfe/trunk/test/Index/complete-cxx-inline-methods.cpp
@@ -25,11 +25,11 @@
 
 // RUN: c-index-test -code-completion-at=%s:4:9 -std=c++98 %s | FileCheck %s
 // RUN: c-index-test -code-completion-at=%s:13:7 -std=c++98 %s | FileCheck %s
-// CHECK:  CXXMethod:{ResultType MyCls::Vec &}{TypedText operator=}{LeftParen (}{Placeholder const MyCls::Vec &}{RightParen )} (34)
+// CHECK:  CXXMethod:{ResultType MyCls::Vec &}{TypedText operator=}{LeftParen (}{Placeholder const MyCls::Vec &}{RightParen )} (79)
 // CHECK-NEXT: StructDecl:{TypedText Vec}{Text ::} (75)
 // CHECK-NEXT: FieldDecl:{ResultType int}{TypedText x} (35)
 // CHECK-NEXT: FieldDecl:{ResultType int}{TypedText y} (35)
-// CHECK-NEXT: CXXDestructor:{ResultType void}{TypedText ~Vec}{LeftParen (}{RightParen )} (34)
+// CHECK-NEXT: CXXDestructor:{ResultType void}{TypedText ~Vec}{LeftParen (}{RightParen )} (79)
 // CHECK-NEXT: Completion contexts:
 // CHECK-NEXT: Dot member access
 // CHECK-NEXT: Container Kind: StructDecl
Index: cfe/trunk/test/Index/complete-with-annotations.cpp
===
--- cfe/trunk/test/Index/complete-with-annotations.cpp
+++ cfe/trunk/test/Index/complete-with-annotations.cpp
@@ -17,7 +17,7 @@
 // CHECK: FieldDecl:{ResultType int}{TypedText field} (35) ("three", "two", "one")
 // CHECK: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) ("some annotation")
 // CHECK: FieldDecl:{ResultType int}{TypedText member2} (35) ("another annotation", "some annotation")
-// CHECK: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (34)
+// CHECK: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (79)
 // CHECK: ClassDecl:{TypedText X}{Text ::} (75)
-// CHECK: CXXDestructor:{ResultType void}{TypedText ~X}{LeftParen (}{RightParen )} (34)
+// CHECK: CXXDestructor:{ResultType void}{TypedText ~X}{LeftParen (}{RightParen )} (79)
 
Index: cfe/trunk/test/Index/complete-qualified.cpp
===
--- cfe/trunk/test/Index/complete-qualified.cpp
+++ cfe/trunk/test/Index/complete-qualified.cpp
@@ -17,4 +17,4 @@
 // CHECK-CC1: FieldDecl:{ResultType C}{TypedText c} (35)
 // CHECK-CC1: ClassDecl:{TypedText Foo} (35)
 // CHECK-CC1: CXXMethod:{ResultType Foo &}{TypedText operator=}{LeftParen (}{Placeholder const Foo &}{RightParen )}
-// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo}{LeftParen (}{RightParen )} (35)
+// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo}{LeftParen (}{RightParen )} (80)
Index: cfe/trunk/test/Index/complete-access-checks.cpp
===
--- 

r314019 - Set completion priority of destructors and operators to CCP_Unlikely.

2017-09-22 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Sep 22 12:07:37 2017
New Revision: 314019

URL: http://llvm.org/viewvc/llvm-project?rev=314019=rev
Log:
Set completion priority of destructors and operators to CCP_Unlikely.

Summary:
It will move destructors and operators to the end of completion list.
Destructors and operators are currently very high on the completion
list, as they have the same priority as member functions. However,
they are clearly not something users usually choose in completion
lists.

Reviewers: arphaman, erikjv, bkramer, krasimir

Reviewed By: arphaman

Subscribers: eraman, klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-access-checks.cpp
cfe/trunk/test/Index/complete-cxx-inline-methods.cpp
cfe/trunk/test/Index/complete-qualified.cpp
cfe/trunk/test/Index/complete-with-annotations.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=314019=314018=314019=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Sep 22 12:07:37 2017
@@ -10,7 +10,7 @@
 //  This file defines the code-completion semantic actions.
 //
 
//===--===//
-#include "clang/Sema/SemaInternal.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -23,6 +23,7 @@
 #include "clang/Sema/Overload.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
+#include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -741,8 +742,18 @@ unsigned ResultBuilder::getBasePriority(
   }
 
   const DeclContext *DC = ND->getDeclContext()->getRedeclContext();
-  if (DC->isRecord() || isa(DC))
+  if (DC->isRecord() || isa(DC)) {
+// Explicit destructor calls are very rare.
+if (isa(ND))
+  return CCP_Unlikely;
+// Explicit operator and conversion function calls are also very rare.
+auto DeclNameKind = ND->getDeclName().getNameKind();
+if (DeclNameKind == DeclarationName::CXXOperatorName ||
+DeclNameKind == DeclarationName::CXXLiteralOperatorName ||
+DeclNameKind == DeclarationName::CXXConversionFunctionName)
+  return CCP_Unlikely;
 return CCP_MemberDeclaration;
+  }
 
   // Content-based decisions.
   if (isa(ND))

Modified: cfe/trunk/test/Index/complete-access-checks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-access-checks.cpp?rev=314019=314018=314019=diff
==
--- cfe/trunk/test/Index/complete-access-checks.cpp (original)
+++ cfe/trunk/test/Index/complete-access-checks.cpp Fri Sep 22 12:07:37 2017
@@ -41,12 +41,12 @@ void Y::doSomething() {
 // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText 
member1} (37)
 // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText 
member2} (37) (inaccessible)
 // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText 
member3} (37) (inaccessible)
-// CHECK-SUPER-ACCESS: CXXMethod:{ResultType Y &}{TypedText 
operator=}{LeftParen (}{Placeholder const Y &}{RightParen )} (34)
-// CHECK-SUPER-ACCESS: CXXMethod:{ResultType X &}{Text X::}{TypedText 
operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (36)
+// CHECK-SUPER-ACCESS: CXXMethod:{ResultType Y &}{TypedText 
operator=}{LeftParen (}{Placeholder const Y &}{RightParen )} (79)
+// CHECK-SUPER-ACCESS: CXXMethod:{ResultType X &}{Text X::}{TypedText 
operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (81)
 // CHECK-SUPER-ACCESS: StructDecl:{TypedText X}{Text ::} (77)
 // CHECK-SUPER-ACCESS: StructDecl:{TypedText Y}{Text ::} (75)
-// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative 
X::}{TypedText ~X}{LeftParen (}{RightParen )} (36)
-// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen 
(}{RightParen )} (34)
+// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative 
X::}{TypedText ~X}{LeftParen (}{RightParen )} (81)
+// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen 
(}{RightParen )} (79)
 
 // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func1}{LeftParen 
(}{RightParen )} (34)
 // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func2}{LeftParen 
(}{RightParen )} (34) (inaccessible)
@@ -54,9 +54,9 @@ void Y::doSomething() {
 // CHECK-ACCESS: FieldDecl:{ResultType int}{TypedText member1} (35)
 // CHECK-ACCESS: FieldDecl:{ResultType int}{TypedText member2} (35) 
(inaccessible)
 // CHECK-ACCESS: FieldDecl:{ResultType int}{TypedText member3} (35) 
(inaccessible)
-// 

[PATCH] D37568: [AMDGPU] Allow flexible register names in inline asm constraints

2017-09-22 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: test/Sema/inline-asm-validate-amdgpu.cl:74
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "=v[1:2]"(ci) : 
"v[3:4]"(ai), "v[5:6]"(bi) : ); //expected-error {{invalid output constraint 
'=v[1:2]' in asm}}
+
+c[i] = ci;

yaxunl wrote:
> arsenm wrote:
> > While you're here can we add some tests for the immediate constraints? 
> > There was a bug report recently when using s_trap with the i constraints 
> > for the constant operand.
> what's the syntax of the immediate constraints? And some examples? Thanks.
Ping. Can we leave this for another patch? Since there are people waiting for 
this feature.


https://reviews.llvm.org/D37568



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


[PATCH] D37568: [AMDGPU] Allow flexible register names in inline asm constraints

2017-09-22 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 116383.
yaxunl marked 4 inline comments as done.
yaxunl edited the summary of this revision.
yaxunl added a comment.

Fix typo.


https://reviews.llvm.org/D37568

Files:
  lib/Basic/Targets/AMDGPU.h
  test/CodeGenOpenCL/amdgcn-inline-asm.cl
  test/Sema/inline-asm-validate-amdgpu.cl

Index: test/Sema/inline-asm-validate-amdgpu.cl
===
--- test/Sema/inline-asm-validate-amdgpu.cl
+++ test/Sema/inline-asm-validate-amdgpu.cl
@@ -1,14 +1,76 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -x cl -triple amdgcn -fsyntax-only  %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -triple amdgcn -fsyntax-only -verify %s
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
 kernel void test () {
 
   int sgpr = 0, vgpr = 0, imm = 0;
 
   // sgpr constraints
   __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "s" (imm) : );
 
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exec}" (imm) : );
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exe" (imm) : ); // expected-error {{invalid input constraint '{exe' in asm}}
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exec" (imm) : ); // expected-error {{invalid input constraint '{exec' in asm}}
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exec}a" (imm) : ); // expected-error {{invalid input constraint '{exec}a' in asm}}
+
   // vgpr constraints
   __asm__ ("v_mov_b32 %0, %1" : "=v" (vgpr) : "v" (imm) : );
 }
+
+__kernel void
+test_float(const __global float *a, const __global float *b, __global float *c, unsigned i)
+{
+float ai = a[i];
+float bi = b[i];
+float ci;
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{v2}"(ai), "{v3}"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : ""(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "="(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '=' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={a}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1a}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v1a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={va}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={va}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}a"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v1}a' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v1' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '=v1}' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v[1]}"(ci) : "{v[2]}"(ai), "{v[3]}"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : "={v[1}"(ci) : "{v[2]}"(ai), "{v[3]}"(bi) : ); // expected-error {{invalid output constraint '={v[1}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v[1]"(ci) : "{v[2]}"(ai), "{v[3]}"(bi) : ); // expected-error {{invalid output constraint '={v[1]' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v[a]}"(ci) : "{v[2]}"(ai), "{v[3]}"(bi) : ); // expected-error {{invalid output constraint '={v[a]}' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "=v"(ci) : "v"(ai), "v"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1"(ci) : "v2"(ai), "v3"(bi) : ); /// expected-error {{invalid output constraint '=v1' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{a}"(ai), "{v3}"(bi) : ); // expected-error {{invalid input constraint '{a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{v2}"(ai), "{a}"(bi) : ); // expected-error {{invalid input constraint '{a}' in asm}}
+c[i] = ci;
+}
+
+__kernel void
+test_double(const __global double *a, const __global double *b, __global double *c, unsigned i)
+{
+double ai = a[i];
+double bi = b[i];
+double ci;
+
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "={v[1:2]}"(ci) : "{v[3:4]}"(ai), "{v[5:6]}"(bi) : );
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "=v{[1:2]}"(ci) : "{v[3:4]}"(ai), "{v[5:6]}"(bi) : ); //expected-error {{invalid output constraint '=v{[1:2]}' in asm}}
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "={v[1:2]a}"(ci) : "{v[3:4]}"(ai), "{v[5:6]}"(bi) : ); //expected-error {{invalid output constraint '={v[1:2]a}' in asm}}
+   

Re: D37042: Teach clang to tolerate the 'p = nullptr + n' idiom used by glibc

2017-09-22 Thread Hal Finkel via cfe-commits


On 09/22/2017 01:45 PM, Sylvestre Ledru wrote:




On 22/09/2017 20:27, Hal Finkel wrote:



On 09/22/2017 01:09 PM, Kaylor, Andrew wrote:

The reason I introduced this patch to begin with is that there are 
circumstances under which the optimizer will eliminate loads from addresses 
that were generated based on the null pointer arithmetic (because clang 
previously emitted a null-based GEP and still will in the Firefox case because 
it's using subtraction).  It would seem that the Firefox case won't ever 
dereference the pointer it is creating this way, so it should be safe from the 
optimization I was seeing.

On the other hand, what the warning says is true, right?  I believe clang will produce an 
inbounds GEP in the Firefox case and the LLVM language reference says, "The only in 
bounds address for a null pointer in the default address-space is the null pointer 
itself."  So it's entirely possible that some optimization will interpret the result 
of the GEP generated to represent '(((char*)0)-1)' as a poison value.

-Andy


I agree. The warning seems good here. As I recall, doing pointer 
arithmetic on the null pointer is UB (even if we never dereference it).


For convenience, it looks like this:


pointer arithmetic on a null pointer has undefined behavior if the offset is 
nonzero [-Werror,-Wnull-pointer-arithmetic]
  return net_FindCharInSet(str, NET_MAX_ADDRESS, set);
^~~
  
/data/jenkins/workspace/firefox-clang-last/obj-x86_64-pc-linux-gnu/dist/include/nsURLHelper.h:224:36:
 note: expanded from macro 'NET_MAX_ADDRESS'
  #define NET_MAX_ADDRESS (((char*)0)-1)



To be clear, I wasn't arguing!
I was just giving feedback about this new warning.


Sounds good :-)



By the way, maybe we should add that to the release notes? 
https://clang.llvm.org/docs/ReleaseNotes.html


I agree. That would be a good idea.

 -Hal



Sylvestre



--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory

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


[PATCH] D37299: [Modules] Add ability to specify module name to module file mapping in a file

2017-09-22 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Hi Boris,

This is a handy option, very nice. Can you also add testcases?




Comment at: lib/Frontend/CompilerInvocation.cpp:1561
+
+  auto Buf = FileMgr.getBufferForFile(File);
+  if (!Buf) {

`auto Buf` -> `auto *Buf`


https://reviews.llvm.org/D37299



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


[PATCH] D38081: Set completion priority of destructors and operators to CCP_Unlikely.

2017-09-22 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Thanks for the review!
Sorry for inappropriate ping, I'll make sure to stick to the policy.


https://reviews.llvm.org/D38081



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


Re: D37042: Teach clang to tolerate the 'p = nullptr + n' idiom used by glibc

2017-09-22 Thread Sylvestre Ledru via cfe-commits


On 22/09/2017 20:27, Hal Finkel wrote:
>
>
> On 09/22/2017 01:09 PM, Kaylor, Andrew wrote:
>> The reason I introduced this patch to begin with is that there are 
>> circumstances under which the optimizer will eliminate loads from addresses 
>> that were generated based on the null pointer arithmetic (because clang 
>> previously emitted a null-based GEP and still will in the Firefox case 
>> because it's using subtraction).  It would seem that the Firefox case won't 
>> ever dereference the pointer it is creating this way, so it should be safe 
>> from the optimization I was seeing.
>>
>> On the other hand, what the warning says is true, right?  I believe clang 
>> will produce an inbounds GEP in the Firefox case and the LLVM language 
>> reference says, "The only in bounds address for a null pointer in the 
>> default address-space is the null pointer itself."  So it's entirely 
>> possible that some optimization will interpret the result of the GEP 
>> generated to represent '(((char*)0)-1)' as a poison value.
>>
>> -Andy
>
> I agree. The warning seems good here. As I recall, doing pointer
> arithmetic on the null pointer is UB (even if we never dereference it).
>
> For convenience, it looks like this:
>
>> pointer arithmetic on a null pointer has undefined behavior if the offset is 
>> nonzero [-Werror,-Wnull-pointer-arithmetic]
>>  return net_FindCharInSet(str, NET_MAX_ADDRESS, set);
>>^~~
>>  
>> /data/jenkins/workspace/firefox-clang-last/obj-x86_64-pc-linux-gnu/dist/include/nsURLHelper.h:224:36:
>>  note: expanded from macro 'NET_MAX_ADDRESS'
>>  #define NET_MAX_ADDRESS (((char*)0)-1)
>
To be clear, I wasn't arguing!
I was just giving feedback about this new warning.

By the way, maybe we should add that to the release notes?
https://clang.llvm.org/docs/ReleaseNotes.html

Sylvestre

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


[PATCH] D38159: [clang] Fix printf fixit for objc specific types

2017-09-22 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314011: [clang] Fix printf fixit for objc specific types 
(authored by alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D38159?vs=116288=116380#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38159

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/FixIt/fixit-format-ios.m


Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -6346,7 +6346,7 @@
   CastFix << ")";
 
   SmallVector Hints;
-  if (!AT.matchesType(S.Context, IntendedTy))
+  if (!AT.matchesType(S.Context, IntendedTy) || ShouldNotPrintDirectly) 
 Hints.push_back(FixItHint::CreateReplacement(SpecRange, os.str()));
 
   if (const CStyleCastExpr *CCast = dyn_cast(E)) {
Index: cfe/trunk/test/FixIt/fixit-format-ios.m
===
--- cfe/trunk/test/FixIt/fixit-format-ios.m
+++ cfe/trunk/test/FixIt/fixit-format-ios.m
@@ -0,0 +1,26 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -triple thumbv7-apple-ios8.0.0 -fsyntax-only -Wformat 
-fixit %t
+// RUN: grep -v CHECK %t | FileCheck %s
+
+int printf(const char * restrict, ...);
+typedef unsigned int NSUInteger;
+typedef int NSInteger;
+NSUInteger getNSUInteger();
+NSInteger getNSInteger();
+
+void test() {
+  // For thumbv7-apple-ios8.0.0 the underlying type of ssize_t is long
+  // and the underlying type of size_t is unsigned long.
+
+  printf("test 1: %zu", getNSUInteger()); 
+  // CHECK: printf("test 1: %lu", (unsigned long)getNSUInteger());
+
+  printf("test 2: %zu %zu", getNSUInteger(), getNSUInteger());
+  // CHECK: printf("test 2: %lu %lu", (unsigned long)getNSUInteger(), 
(unsigned long)getNSUInteger());
+
+  printf("test 3: %zd", getNSInteger()); 
+  // CHECK: printf("test 3: %ld", (long)getNSInteger());
+
+  printf("test 4: %zd %zd", getNSInteger(), getNSInteger());
+  // CHECK: printf("test 4: %ld %ld", (long)getNSInteger(), 
(long)getNSInteger());
+}


Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -6346,7 +6346,7 @@
   CastFix << ")";
 
   SmallVector Hints;
-  if (!AT.matchesType(S.Context, IntendedTy))
+  if (!AT.matchesType(S.Context, IntendedTy) || ShouldNotPrintDirectly) 
 Hints.push_back(FixItHint::CreateReplacement(SpecRange, os.str()));
 
   if (const CStyleCastExpr *CCast = dyn_cast(E)) {
Index: cfe/trunk/test/FixIt/fixit-format-ios.m
===
--- cfe/trunk/test/FixIt/fixit-format-ios.m
+++ cfe/trunk/test/FixIt/fixit-format-ios.m
@@ -0,0 +1,26 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -triple thumbv7-apple-ios8.0.0 -fsyntax-only -Wformat -fixit %t
+// RUN: grep -v CHECK %t | FileCheck %s
+
+int printf(const char * restrict, ...);
+typedef unsigned int NSUInteger;
+typedef int NSInteger;
+NSUInteger getNSUInteger();
+NSInteger getNSInteger();
+
+void test() {
+  // For thumbv7-apple-ios8.0.0 the underlying type of ssize_t is long
+  // and the underlying type of size_t is unsigned long.
+
+  printf("test 1: %zu", getNSUInteger()); 
+  // CHECK: printf("test 1: %lu", (unsigned long)getNSUInteger());
+
+  printf("test 2: %zu %zu", getNSUInteger(), getNSUInteger());
+  // CHECK: printf("test 2: %lu %lu", (unsigned long)getNSUInteger(), (unsigned long)getNSUInteger());
+
+  printf("test 3: %zd", getNSInteger()); 
+  // CHECK: printf("test 3: %ld", (long)getNSInteger());
+
+  printf("test 4: %zd %zd", getNSInteger(), getNSInteger());
+  // CHECK: printf("test 4: %ld %ld", (long)getNSInteger(), (long)getNSInteger());
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38081: Set completion priority of destructors and operators to CCP_Unlikely.

2017-09-22 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 116381.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

- Removed redundant NameKind:: qualifiers.


https://reviews.llvm.org/D38081

Files:
  lib/Sema/SemaCodeComplete.cpp
  test/Index/complete-access-checks.cpp
  test/Index/complete-cxx-inline-methods.cpp
  test/Index/complete-qualified.cpp
  test/Index/complete-with-annotations.cpp

Index: test/Index/complete-with-annotations.cpp
===
--- test/Index/complete-with-annotations.cpp
+++ test/Index/complete-with-annotations.cpp
@@ -17,7 +17,7 @@
 // CHECK: FieldDecl:{ResultType int}{TypedText field} (35) ("three", "two", "one")
 // CHECK: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) ("some annotation")
 // CHECK: FieldDecl:{ResultType int}{TypedText member2} (35) ("another annotation", "some annotation")
-// CHECK: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (34)
+// CHECK: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (79)
 // CHECK: ClassDecl:{TypedText X}{Text ::} (75)
-// CHECK: CXXDestructor:{ResultType void}{TypedText ~X}{LeftParen (}{RightParen )} (34)
+// CHECK: CXXDestructor:{ResultType void}{TypedText ~X}{LeftParen (}{RightParen )} (79)
 
Index: test/Index/complete-qualified.cpp
===
--- test/Index/complete-qualified.cpp
+++ test/Index/complete-qualified.cpp
@@ -17,4 +17,4 @@
 // CHECK-CC1: FieldDecl:{ResultType C}{TypedText c} (35)
 // CHECK-CC1: ClassDecl:{TypedText Foo} (35)
 // CHECK-CC1: CXXMethod:{ResultType Foo &}{TypedText operator=}{LeftParen (}{Placeholder const Foo &}{RightParen )}
-// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo}{LeftParen (}{RightParen )} (35)
+// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo}{LeftParen (}{RightParen )} (80)
Index: test/Index/complete-cxx-inline-methods.cpp
===
--- test/Index/complete-cxx-inline-methods.cpp
+++ test/Index/complete-cxx-inline-methods.cpp
@@ -25,11 +25,11 @@
 
 // RUN: c-index-test -code-completion-at=%s:4:9 -std=c++98 %s | FileCheck %s
 // RUN: c-index-test -code-completion-at=%s:13:7 -std=c++98 %s | FileCheck %s
-// CHECK:  CXXMethod:{ResultType MyCls::Vec &}{TypedText operator=}{LeftParen (}{Placeholder const MyCls::Vec &}{RightParen )} (34)
+// CHECK:  CXXMethod:{ResultType MyCls::Vec &}{TypedText operator=}{LeftParen (}{Placeholder const MyCls::Vec &}{RightParen )} (79)
 // CHECK-NEXT: StructDecl:{TypedText Vec}{Text ::} (75)
 // CHECK-NEXT: FieldDecl:{ResultType int}{TypedText x} (35)
 // CHECK-NEXT: FieldDecl:{ResultType int}{TypedText y} (35)
-// CHECK-NEXT: CXXDestructor:{ResultType void}{TypedText ~Vec}{LeftParen (}{RightParen )} (34)
+// CHECK-NEXT: CXXDestructor:{ResultType void}{TypedText ~Vec}{LeftParen (}{RightParen )} (79)
 // CHECK-NEXT: Completion contexts:
 // CHECK-NEXT: Dot member access
 // CHECK-NEXT: Container Kind: StructDecl
Index: test/Index/complete-access-checks.cpp
===
--- test/Index/complete-access-checks.cpp
+++ test/Index/complete-access-checks.cpp
@@ -41,22 +41,22 @@
 // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member1} (37)
 // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member2} (37) (inaccessible)
 // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member3} (37) (inaccessible)
-// CHECK-SUPER-ACCESS: CXXMethod:{ResultType Y &}{TypedText operator=}{LeftParen (}{Placeholder const Y &}{RightParen )} (34)
-// CHECK-SUPER-ACCESS: CXXMethod:{ResultType X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (36)
+// CHECK-SUPER-ACCESS: CXXMethod:{ResultType Y &}{TypedText operator=}{LeftParen (}{Placeholder const Y &}{RightParen )} (79)
+// CHECK-SUPER-ACCESS: CXXMethod:{ResultType X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (81)
 // CHECK-SUPER-ACCESS: StructDecl:{TypedText X}{Text ::} (77)
 // CHECK-SUPER-ACCESS: StructDecl:{TypedText Y}{Text ::} (75)
-// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} (36)
-// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen (}{RightParen )} (34)
+// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} (81)
+// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen (}{RightParen )} (79)
 
 // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func1}{LeftParen (}{RightParen )} (34)
 // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) (inaccessible)
 

r314013 - [lit.cfg] Avoid concatenating which(clang-func-mapping) if it's missing

2017-09-22 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Sep 22 11:42:28 2017
New Revision: 314013

URL: http://llvm.org/viewvc/llvm-project?rev=314013=rev
Log:
[lit.cfg] Avoid concatenating which(clang-func-mapping) if it's missing

This un-breaks a lit workflow where you run lit tests from a test
sub-directory within clang without first building clang-func-mapping.

Modified:
cfe/trunk/test/lit.cfg.py

Modified: cfe/trunk/test/lit.cfg.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/lit.cfg.py?rev=314013=314012=314013=diff
==
--- cfe/trunk/test/lit.cfg.py (original)
+++ cfe/trunk/test/lit.cfg.py Fri Sep 22 11:42:28 2017
@@ -125,7 +125,11 @@ config.substitutions.append( ('%clang_cl
   ' --driver-mode=cl '))
 config.substitutions.append( ('%clangxx', ' ' + config.clang +
   ' --driver-mode=g++ '))
-config.substitutions.append( ('%clang_func_map', ' ' + 
lit.util.which('clang-func-mapping', config.environment['PATH']) + ' ') )
+
+clang_func_map = lit.util.which('clang-func-mapping', 
config.environment['PATH'])
+if clang_func_map:
+config.substitutions.append( ('%clang_func_map', ' ' + clang_func_map + ' 
') )
+
 config.substitutions.append( ('%clang', ' ' + config.clang + ' ') )
 config.substitutions.append( ('%test_debuginfo',
  ' ' + config.llvm_src_root +  
'/utils/test_debuginfo.pl ') )


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


r314011 - [clang] Fix printf fixit for objc specific types

2017-09-22 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Fri Sep 22 11:36:06 2017
New Revision: 314011

URL: http://llvm.org/viewvc/llvm-project?rev=314011=rev
Log:
[clang] Fix printf fixit for objc specific types

For the triple thumbv7-apple-ios8.0.0 ssize_t is long and size_t is unsigned 
long,
while NSInteger is int and NSUinteger is unsigned int. Following 
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
Clang catches it and insert a cast to long, for example
 printf("%zd", getNSInteger())
will be replaced with 
 printf("%zd", (long)getNSInteger())
but since the underlying type of ssize_t is long the specifier "%zd" is not 
getting replaced.
This diff changes this behavior to enable replacing the specifier "%zd" with 
the correct one.

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

Test plan: make check-all

Added:
cfe/trunk/test/FixIt/fixit-format-ios.m
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=314011=314010=314011=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Sep 22 11:36:06 2017
@@ -6346,7 +6346,7 @@ CheckPrintfHandler::checkFormatExpr(cons
   CastFix << ")";
 
   SmallVector Hints;
-  if (!AT.matchesType(S.Context, IntendedTy))
+  if (!AT.matchesType(S.Context, IntendedTy) || ShouldNotPrintDirectly) 
 Hints.push_back(FixItHint::CreateReplacement(SpecRange, os.str()));
 
   if (const CStyleCastExpr *CCast = dyn_cast(E)) {

Added: cfe/trunk/test/FixIt/fixit-format-ios.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-format-ios.m?rev=314011=auto
==
--- cfe/trunk/test/FixIt/fixit-format-ios.m (added)
+++ cfe/trunk/test/FixIt/fixit-format-ios.m Fri Sep 22 11:36:06 2017
@@ -0,0 +1,26 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -triple thumbv7-apple-ios8.0.0 -fsyntax-only -Wformat 
-fixit %t
+// RUN: grep -v CHECK %t | FileCheck %s
+
+int printf(const char * restrict, ...);
+typedef unsigned int NSUInteger;
+typedef int NSInteger;
+NSUInteger getNSUInteger();
+NSInteger getNSInteger();
+
+void test() {
+  // For thumbv7-apple-ios8.0.0 the underlying type of ssize_t is long
+  // and the underlying type of size_t is unsigned long.
+
+  printf("test 1: %zu", getNSUInteger()); 
+  // CHECK: printf("test 1: %lu", (unsigned long)getNSUInteger());
+
+  printf("test 2: %zu %zu", getNSUInteger(), getNSUInteger());
+  // CHECK: printf("test 2: %lu %lu", (unsigned long)getNSUInteger(), 
(unsigned long)getNSUInteger());
+
+  printf("test 3: %zd", getNSInteger()); 
+  // CHECK: printf("test 3: %ld", (long)getNSInteger());
+
+  printf("test 4: %zd %zd", getNSInteger(), getNSInteger());
+  // CHECK: printf("test 4: %ld %ld", (long)getNSInteger(), 
(long)getNSInteger());
+}


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


[PATCH] D37573: [bindings] add Cursor.linkage

2017-09-22 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd closed this revision.
compnerd added a comment.

SVN r314009


https://reviews.llvm.org/D37573



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


r314009 - bindings: expose Linkage to the python bindings

2017-09-22 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Fri Sep 22 11:35:09 2017
New Revision: 314009

URL: http://llvm.org/viewvc/llvm-project?rev=314009=rev
Log:
bindings: expose Linkage to the python bindings

Add Python bindings for the 'clang_getCursorLinkage', and tests to
validate the functionality.

Patch by Masud Rahman!

Added:
cfe/trunk/bindings/python/tests/cindex/test_linkage.py
Modified:
cfe/trunk/bindings/python/clang/cindex.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=314009=314008=314009=diff
==
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Fri Sep 22 11:35:09 2017
@@ -1549,6 +1549,14 @@ class Cursor(Structure):
 return self._loc
 
 @property
+def linkage(self):
+"""Return the linkage of this cursor."""
+if not hasattr(self, '_linkage'):
+self._linkage = conf.lib.clang_getCursorLinkage(self)
+
+return LinkageKind.from_id(self._linkage)
+
+@property
 def tls_kind(self):
 """Return the thread-local storage (TLS) kind of this cursor."""
 if not hasattr(self, '_tls_kind'):
@@ -2069,6 +2077,25 @@ RefQualifierKind.NONE = RefQualifierKind
 RefQualifierKind.LVALUE = RefQualifierKind(1)
 RefQualifierKind.RVALUE = RefQualifierKind(2)
 
+class LinkageKind(BaseEnumeration):
+"""Describes the kind of linkage of a cursor."""
+
+# The unique kind objects, indexed by id.
+_kinds = []
+_name_map = None
+
+def from_param(self):
+return self.value
+
+def __repr__(self):
+return 'LinkageKind.%s' % (self.name,)
+
+LinkageKind.INVALID = LinkageKind(0)
+LinkageKind.NO_LINKAGE = LinkageKind(1)
+LinkageKind.INTERNAL = LinkageKind(2)
+LinkageKind.UNIQUE_EXTERNAL = LinkageKind(3)
+LinkageKind.EXTERNAL = LinkageKind(4)
+
 class TLSKind(BaseEnumeration):
 """Describes the kind of thread-local storage (TLS) of a cursor."""
 
@@ -4090,6 +4117,7 @@ __all__ = [
 'File',
 'FixIt',
 'Index',
+'LinkageKind',
 'SourceLocation',
 'SourceRange',
 'TLSKind',

Added: cfe/trunk/bindings/python/tests/cindex/test_linkage.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_linkage.py?rev=314009=auto
==
--- cfe/trunk/bindings/python/tests/cindex/test_linkage.py (added)
+++ cfe/trunk/bindings/python/tests/cindex/test_linkage.py Fri Sep 22 11:35:09 
2017
@@ -0,0 +1,30 @@
+
+from clang.cindex import LinkageKind
+from clang.cindex import Cursor
+from clang.cindex import TranslationUnit
+
+from .util import get_cursor
+from .util import get_tu
+
+def test_linkage():
+"""Ensure that linkage specifers are available on cursors"""
+
+tu = get_tu("""
+void foo() { int no_linkage; }
+static int internal;
+namespace { extern int unique_external; }
+extern int external;
+""", lang = 'cpp')
+
+no_linkage = get_cursor(tu.cursor, 'no_linkage')
+assert no_linkage.linkage == LinkageKind.NO_LINKAGE;
+
+internal = get_cursor(tu.cursor, 'internal')
+assert internal.linkage == LinkageKind.INTERNAL
+
+unique_external = get_cursor(tu.cursor, 'unique_external')
+assert unique_external.linkage == LinkageKind.UNIQUE_EXTERNAL
+
+external = get_cursor(tu.cursor, 'external')
+assert external.linkage == LinkageKind.EXTERNAL
+


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


Re: D37042: Teach clang to tolerate the 'p = nullptr + n' idiom used by glibc

2017-09-22 Thread Hal Finkel via cfe-commits


On 09/22/2017 01:09 PM, Kaylor, Andrew wrote:

The reason I introduced this patch to begin with is that there are 
circumstances under which the optimizer will eliminate loads from addresses 
that were generated based on the null pointer arithmetic (because clang 
previously emitted a null-based GEP and still will in the Firefox case because 
it's using subtraction).  It would seem that the Firefox case won't ever 
dereference the pointer it is creating this way, so it should be safe from the 
optimization I was seeing.

On the other hand, what the warning says is true, right?  I believe clang will produce an 
inbounds GEP in the Firefox case and the LLVM language reference says, "The only in 
bounds address for a null pointer in the default address-space is the null pointer 
itself."  So it's entirely possible that some optimization will interpret the result 
of the GEP generated to represent '(((char*)0)-1)' as a poison value.

-Andy


I agree. The warning seems good here. As I recall, doing pointer 
arithmetic on the null pointer is UB (even if we never dereference it).


For convenience, it looks like this:


pointer arithmetic on a null pointer has undefined behavior if the offset is 
nonzero [-Werror,-Wnull-pointer-arithmetic]
  return net_FindCharInSet(str, NET_MAX_ADDRESS, set);
^~~
  
/data/jenkins/workspace/firefox-clang-last/obj-x86_64-pc-linux-gnu/dist/include/nsURLHelper.h:224:36:
 note: expanded from macro 'NET_MAX_ADDRESS'
  #define NET_MAX_ADDRESS (((char*)0)-1)


 -Hal



-Original Message-
From: Sylvestre Ledru via Phabricator [mailto:revi...@reviews.llvm.org]
Sent: Friday, September 22, 2017 9:02 AM
To: Kaylor, Andrew ; rjmcc...@gmail.com; 
rich...@metafoo.co.uk; efrie...@codeaurora.org
Cc: sylves...@debian.org; Ivchenko, Alexander ; 
hfin...@anl.gov; mcros...@codeaurora.org; david.majne...@gmail.com; 
cfe-commits@lists.llvm.org
Subject: [PATCH] D37042: Teach clang to tolerate the 'p = nullptr + n' idiom 
used by glibc

sylvestre.ledru added a comment.

For the record, Firefox was using this trick. This patch is breaking a ci build 
(clang trunk + warning as errors) More information here: 
https://bugzilla.mozilla.org/show_bug.cgi?id=1402362


Repository:
   rL LLVM

https://reviews.llvm.org/D37042





--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory

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


r314002 - [Coverage] Add an option to emit limited coverage info

2017-09-22 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Sep 22 11:23:04 2017
New Revision: 314002

URL: http://llvm.org/viewvc/llvm-project?rev=314002=rev
Log:
[Coverage] Add an option to emit limited coverage info

Add an option to emit limited coverage info for unused decls. It's just a
cl::opt for now to allow us to experiment quickly.

When building llc, this results in an 84% size reduction in the llvm_covmap
section, and a similar size reduction in the llvm_prf_names section. In
practice I expect the size reduction to be roughly quadratic with the size of
the program.

The downside is that coverage for headers will no longer be complete. This will
make the line/function/region coverage metrics incorrect, since they will be
artificially high. One mitigation would be to somehow disable those metrics
when using limited-coverage=true.

This is related to: llvm.org/PR34533 (make SourceBasedCodeCoverage scale)

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CoverageMapping/header.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=314002=314001=314002=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Sep 22 11:23:04 2017
@@ -61,6 +61,11 @@
 using namespace clang;
 using namespace CodeGen;
 
+static llvm::cl::opt LimitedCoverage(
+"limited-coverage-experimental", llvm::cl::ZeroOrMore,
+llvm::cl::desc("Emit limited coverage mapping information (experimental)"),
+llvm::cl::init(false));
+
 static const char AnnotationSection[] = "llvm.metadata";
 
 static CGCXXABI *createCXXABI(CodeGenModule ) {
@@ -4231,6 +4236,9 @@ void CodeGenModule::AddDeferredUnusedCov
   case Decl::CXXDestructor: {
 if (!cast(D)->doesThisDeclarationHaveABody())
   return;
+SourceManager  = getContext().getSourceManager();
+if (LimitedCoverage && SM.getMainFileID() != 
SM.getFileID(D->getLocStart()))
+  return;
 auto I = DeferredEmptyCoverageMappingDecls.find(D);
 if (I == DeferredEmptyCoverageMappingDecls.end())
   DeferredEmptyCoverageMappingDecls[D] = true;

Modified: cfe/trunk/test/CoverageMapping/header.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/header.cpp?rev=314002=314001=314002=diff
==
--- cfe/trunk/test/CoverageMapping/header.cpp (original)
+++ cfe/trunk/test/CoverageMapping/header.cpp Fri Sep 22 11:23:04 2017
@@ -2,6 +2,9 @@
 // RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-FUNC
 // RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-STATIC-FUNC
 // RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-STATIC-FUNC2
+//
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -mllvm 
-limited-coverage-experimental=true -dump-coverage-mapping -emit-llvm-only 
-main-file-name header.cpp %s > %tmapping.limited
+// RUN: FileCheck -input-file %tmapping.limited %s --check-prefix=CHECK-LIMITED
 
 #include "Inputs/header1.h"
 
@@ -22,3 +25,5 @@ int main() {
 
 // CHECK-STATIC-FUNC2: static_func2
 // CHECK-STATIC-FUNC2: File 0, 21:33 -> 29:2 = 0
+
+// CHECK-LIMITED-NOT: static_func2


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


[PATCH] D37544: [ubsan] Skip alignment checks which are folded away

2017-09-22 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D37544



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


[PATCH] D38081: Set completion priority of destructors and operators to CCP_Unlikely.

2017-09-22 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Nice, LGTM

Please keep in mind that LLVM follows a weekly ping rate: 
https://llvm.org/docs/DeveloperPolicy.html#code-reviews .




Comment at: lib/Sema/SemaCodeComplete.cpp:751
+auto DeclNameKind = ND->getDeclName().getNameKind();
+if (DeclNameKind == DeclarationName::NameKind::CXXOperatorName ||
+DeclNameKind == DeclarationName::NameKind::CXXLiteralOperatorName ||

Nit: `NameKind::` is redundant.


https://reviews.llvm.org/D38081



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


RE: D37042: Teach clang to tolerate the 'p = nullptr + n' idiom used by glibc

2017-09-22 Thread Kaylor, Andrew via cfe-commits
The reason I introduced this patch to begin with is that there are 
circumstances under which the optimizer will eliminate loads from addresses 
that were generated based on the null pointer arithmetic (because clang 
previously emitted a null-based GEP and still will in the Firefox case because 
it's using subtraction).  It would seem that the Firefox case won't ever 
dereference the pointer it is creating this way, so it should be safe from the 
optimization I was seeing.

On the other hand, what the warning says is true, right?  I believe clang will 
produce an inbounds GEP in the Firefox case and the LLVM language reference 
says, "The only in bounds address for a null pointer in the default 
address-space is the null pointer itself."  So it's entirely possible that some 
optimization will interpret the result of the GEP generated to represent 
'(((char*)0)-1)' as a poison value.

-Andy

-Original Message-
From: Sylvestre Ledru via Phabricator [mailto:revi...@reviews.llvm.org] 
Sent: Friday, September 22, 2017 9:02 AM
To: Kaylor, Andrew ; rjmcc...@gmail.com; 
rich...@metafoo.co.uk; efrie...@codeaurora.org
Cc: sylves...@debian.org; Ivchenko, Alexander ; 
hfin...@anl.gov; mcros...@codeaurora.org; david.majne...@gmail.com; 
cfe-commits@lists.llvm.org
Subject: [PATCH] D37042: Teach clang to tolerate the 'p = nullptr + n' idiom 
used by glibc

sylvestre.ledru added a comment.

For the record, Firefox was using this trick. This patch is breaking a ci build 
(clang trunk + warning as errors) More information here: 
https://bugzilla.mozilla.org/show_bug.cgi?id=1402362


Repository:
  rL LLVM

https://reviews.llvm.org/D37042



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


[PATCH] D32520: Support __fp16 vectors

2017-09-22 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Thanks Akira.


https://reviews.llvm.org/D32520



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


[PATCH] D37804: [OpenCL] Handle address space conversion while setting type alignment

2017-09-22 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: test/CodeGenOpenCL/vectorLoadStore.cl:7
+typedef float float4 __attribute((ext_vector_type(4)));
+;
 

Can we remove this line?



Comment at: test/CodeGenOpenCL/vectorLoadStore.cl:15
+
+// CHECK: define spir_func void @alignment()
+void alignment() {

Please, set SPIR target in clang options to make this check reliable.


https://reviews.llvm.org/D37804



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


[PATCH] D38134: [OpenCL] Emit enqueued block as kernel

2017-09-22 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 10 inline comments as done.
yaxunl added inline comments.



Comment at: lib/CodeGen/CGOpenCLRuntime.cpp:113
+
+llvm::Value *CGOpenCLRuntime::emitOpenCLEnqueuedBlock(CodeGenFunction ,
+  const Expr *E) {

Anastasia wrote:
> yaxunl wrote:
> > Anastasia wrote:
> > > I am not particularly in favour of duplicating CodeGen functionality as 
> > > it typically has so many special cases that are hard to catch. Is this 
> > > logic needed in order to pass to block literal information  that the 
> > > block is enqueued?
> > This code is needed to emit separate functions for a block which is 
> > directly called and also enqueued as a kernel. Since the kernel needs to 
> > have proper calling convention and ABI, it cannot be emitted as the same 
> > function as when the block is called directly. Since it is OpenCL specific 
> > code, I found it is cleaner to separate this code as member of 
> > CGOpenCLRuntime instead of fitting it into CGF.EmitBlockLiteral.
> This part is replacing standard `EmitScalarExpr` call which is doing several 
> things before calling into block generation. That's why I am a bit worried we 
> are covering all the corner cases here.
> 
> So if we transform all blocks into kernels unconditionally we won't need this 
> special handling then?
> 
> Do we generate two versions of the blocks now: one for enqueue and one for 
> call?
If we transform all blocks into kernels, we could simplify the logic. Probably 
will not need this special handling.

However, when the block is called directly, the first argument is a private 
pointer, when it is executed as a kernel, the first argument is a global 
pointer or a struct (for amdgpu target), therefore the emitted functions cannot 
be the same.



Comment at: lib/CodeGen/CodeGenFunction.cpp:535
+if (i == 0 && IsBlock) {
+  ty = CGF.CGM.getTargetCodeGenInfo().getEnqueuedBlockArgumentType(
+  ASTCtx, *CGF.BlockInfo);

Anastasia wrote:
> yaxunl wrote:
> > Anastasia wrote:
> > > I don't quite understand why we need to special case this? As far as I 
> > > undertsnad block argument is a `generic void* ` type but it's being cast 
> > > to a concrete block struct inside the block function. Do we gain anything 
> > > from having it a specific type here?
> > This argument is not part of BlockDecl. BlockDecl only has arguments shown 
> > up in the source code. The first argument in the LLVM block invoke function 
> > is generated by codegen and there is no correspondence in AST, so it has to 
> > be handled as a special case.
> Considering that enqueued kernel always takes the same type of the arguments 
> (`local void*`) and # of args is specified in `enqueue_kernel`, I was 
> wondering whether we need to generate the information on the kernel 
> parameters at all? The enqueueing side will have the information provided in 
> the `enqueue_kernel` code.
> 
> As for the block itself it can be passed as `generic void*` and then cast to 
> the block struct type inside the block itself.
amdgpu backend relies on kernel argument metadata to generate some metadata in 
elf for runtime to launch the kernel. The backend expects the kernel argument 
metadata on each kernel argument. Not generating kernel metadata on the first 
kernel argument requires special handling in the backend. I think it is better 
to let Clang generate kernel argument metadata for all kernel arguments.



Comment at: lib/CodeGen/CodeGenFunction.cpp:667
   llvm::MDNode::get(Context, argTypeQuals));
-  if (CGM.getCodeGenOpts().EmitOpenCLArgMetadata)
+  if (CGF.CGM.getCodeGenOpts().EmitOpenCLArgMetadata)
 Fn->setMetadata("kernel_arg_name",

Anastasia wrote:
> Why this change?
CGM is no longer a function parameter since now this function requires a CGF 
parameter.



Comment at: test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl:3
+
+// CHECK: %[[S1:struct.__amdgpu_block_arg_t.*]] = type { [3 x i64], [1 x i8] }
+// CHECK: %[[S2:struct.__amdgpu_block_arg_t.*]] = type { [5 x i64], [1 x i8] }

Anastasia wrote:
> This struct is not identical to block literal struct?
The LLVM type of the first argument of block invoke function is created 
directly with sorting and rearrangement. There is no AST type corresponding to 
it. However, the function codegen requires AST type of this argument. I feel it 
is unnecessary to create the corresponding AST type. For simplicity, just 
create an AST type with the same size and alignment as the LLVM type. In the 
function code, it will be bitcasted to the correct LLVM struct type and get the 
captured variables.


https://reviews.llvm.org/D38134



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


[PATCH] D37544: [ubsan] Skip alignment checks which are folded away

2017-09-22 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 116374.
vsk added a comment.

- Tighten up lit test.


https://reviews.llvm.org/D37544

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


Index: test/CodeGenCXX/ubsan-suppress-checks.cpp
===
--- test/CodeGenCXX/ubsan-suppress-checks.cpp
+++ test/CodeGenCXX/ubsan-suppress-checks.cpp
@@ -17,6 +17,17 @@
   // CHECK: ret void
 }
 
+// CHECK-LABEL: define void @_Z31use_us16_aligned_array_elementsv
+void use_us16_aligned_array_elements() {
+  static const unsigned short Arr[] = {0, 1, 2};
+  auto use_array = [](const unsigned short()[3]) -> void {};
+  use_array(Arr);
+
+  // CHECK-NOT: br i1 true
+  // ALIGN-NOT: call void @__ubsan_handle_type_mismatch
+  // CHECK: ret void
+}
+
 struct A {
   int foo;
 
@@ -229,4 +240,5 @@
   d->load_member_3();
 
   load_non_null_pointers();
+  use_us16_aligned_array_elements();
 }
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -618,6 +618,7 @@
   auto PtrToAlloca =
   dyn_cast(Ptr->stripPointerCastsNoFollowAliases());
 
+  llvm::Value *True = llvm::ConstantInt::getTrue(getLLVMContext());
   llvm::Value *IsNonNull = nullptr;
   bool IsGuaranteedNonNull =
   SkippedChecks.has(SanitizerKind::Null) || PtrToAlloca;
@@ -629,8 +630,7 @@
 
 // The IR builder can constant-fold the null check if the pointer points to
 // a constant.
-IsGuaranteedNonNull =
-IsNonNull == llvm::ConstantInt::getTrue(getLLVMContext());
+IsGuaranteedNonNull = IsNonNull == True;
 
 // Skip the null check if the pointer is known to be non-null.
 if (!IsGuaranteedNonNull) {
@@ -684,7 +684,8 @@
   PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
   llvm::Value *Aligned =
   Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0));
-  Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment));
+  if (Aligned != True)
+Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment));
 }
   }
 


Index: test/CodeGenCXX/ubsan-suppress-checks.cpp
===
--- test/CodeGenCXX/ubsan-suppress-checks.cpp
+++ test/CodeGenCXX/ubsan-suppress-checks.cpp
@@ -17,6 +17,17 @@
   // CHECK: ret void
 }
 
+// CHECK-LABEL: define void @_Z31use_us16_aligned_array_elementsv
+void use_us16_aligned_array_elements() {
+  static const unsigned short Arr[] = {0, 1, 2};
+  auto use_array = [](const unsigned short()[3]) -> void {};
+  use_array(Arr);
+
+  // CHECK-NOT: br i1 true
+  // ALIGN-NOT: call void @__ubsan_handle_type_mismatch
+  // CHECK: ret void
+}
+
 struct A {
   int foo;
 
@@ -229,4 +240,5 @@
   d->load_member_3();
 
   load_non_null_pointers();
+  use_us16_aligned_array_elements();
 }
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -618,6 +618,7 @@
   auto PtrToAlloca =
   dyn_cast(Ptr->stripPointerCastsNoFollowAliases());
 
+  llvm::Value *True = llvm::ConstantInt::getTrue(getLLVMContext());
   llvm::Value *IsNonNull = nullptr;
   bool IsGuaranteedNonNull =
   SkippedChecks.has(SanitizerKind::Null) || PtrToAlloca;
@@ -629,8 +630,7 @@
 
 // The IR builder can constant-fold the null check if the pointer points to
 // a constant.
-IsGuaranteedNonNull =
-IsNonNull == llvm::ConstantInt::getTrue(getLLVMContext());
+IsGuaranteedNonNull = IsNonNull == True;
 
 // Skip the null check if the pointer is known to be non-null.
 if (!IsGuaranteedNonNull) {
@@ -684,7 +684,8 @@
   PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
   llvm::Value *Aligned =
   Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0));
-  Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment));
+  if (Aligned != True)
+Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment));
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37544: [ubsan] Skip alignment checks which are folded away

2017-09-22 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Sorry, I see the issue now. The pre-patch IR looked like "br i1 true, label 
%continue, label %diagnose", so there was no alignment check, per-se.


https://reviews.llvm.org/D37544



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


[PATCH] D37573: [bindings] add Cursor.linkage

2017-09-22 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

Sure, Ill get this merged shortly.


https://reviews.llvm.org/D37573



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


[PATCH] D37804: [OpenCL] Handle address space conversion while setting type alignment

2017-09-22 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


https://reviews.llvm.org/D37804



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


[PATCH] D37544: [ubsan] Skip alignment checks which are folded away

2017-09-22 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

This one passes for me too without the code change.


https://reviews.llvm.org/D37544



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


[PATCH] D38074: Fix TBAA information for reference accesses

2017-09-22 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Sure, that's fine.  LGTM.


https://reviews.llvm.org/D38074



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


r313997 - [index] Generate class & metaclass manglings for objc

2017-09-22 Thread Dave Lee via cfe-commits
Author: kastiglione
Date: Fri Sep 22 09:58:57 2017
New Revision: 313997

URL: http://llvm.org/viewvc/llvm-project?rev=313997=rev
Log:
[index] Generate class & metaclass manglings for objc

Summary:
ObjC classes have two associated symbols, one for the class and one for the
metaclass.

This change overloads `CodegenNameGenerator::getAllManglings` to produce both
class and metaclass symbols.

While this function is called by `clang_Cursor_getCXXManglings`, it's only
called for CXXRecordDecl and CXXMethodDecl, and so libclang's behavior is
unchanged.

Reviewers: arphaman, abdulras, alexshap, compnerd

Reviewed By: compnerd

Subscribers: compnerd

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

Added:
cfe/trunk/test/Index/print-objc-manglings.m
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/lib/Index/CodegenNameGenerator.cpp
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/libclang.exports

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=313997=313996=313997=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri Sep 22 09:58:57 2017
@@ -4293,6 +4293,12 @@ CINDEX_LINKAGE CXString clang_Cursor_get
 CINDEX_LINKAGE CXStringSet *clang_Cursor_getCXXManglings(CXCursor);
 
 /**
+ * \brief Retrieve the CXStrings representing the mangled symbols of the ObjC
+ * class interface or implementation at the cursor.
+ */
+CINDEX_LINKAGE CXStringSet *clang_Cursor_getObjCManglings(CXCursor);
+
+/**
  * @}
  */
 

Modified: cfe/trunk/lib/Index/CodegenNameGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/CodegenNameGenerator.cpp?rev=313997=313996=313997=diff
==
--- cfe/trunk/lib/Index/CodegenNameGenerator.cpp (original)
+++ cfe/trunk/lib/Index/CodegenNameGenerator.cpp Fri Sep 22 09:58:57 2017
@@ -68,7 +68,38 @@ struct CodegenNameGenerator::Implementat
 return Name;
   }
 
+  enum ObjCKind {
+ObjCClass,
+ObjCMetaclass,
+  };
+
+  std::vector getAllManglings(const ObjCContainerDecl *OCD) {
+StringRef ClassName;
+if (const auto *OID = dyn_cast(OCD))
+  ClassName = OID->getObjCRuntimeNameAsString();
+else if (const auto *OID = dyn_cast(OCD))
+  ClassName = OID->getObjCRuntimeNameAsString();
+
+if (ClassName.empty())
+  return {};
+
+auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string {
+  SmallString<40> Mangled;
+  auto Prefix = getClassSymbolPrefix(Kind, OCD->getASTContext());
+  llvm::Mangler::getNameWithPrefix(Mangled, Prefix + ClassName, DL);
+  return Mangled.str();
+};
+
+return {
+  Mangle(ObjCClass, ClassName),
+  Mangle(ObjCMetaclass, ClassName),
+};
+  }
+
   std::vector getAllManglings(const Decl *D) {
+if (const auto *OCD = dyn_cast(D))
+  return getAllManglings(OCD);
+
 if (!(isa(D) || isa(D)))
   return {};
 
@@ -135,12 +166,14 @@ private:
   }
 
   void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream ) {
-OS << getClassSymbolPrefix();
+OS << getClassSymbolPrefix(ObjCClass, D->getASTContext());
 OS << D->getObjCRuntimeNameAsString();
   }
 
-  static StringRef getClassSymbolPrefix() {
-return "OBJC_CLASS_$_";
+  static StringRef getClassSymbolPrefix(ObjCKind Kind, const ASTContext 
) {
+if (Context.getLangOpts().ObjCRuntime.isGNUFamily())
+  return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_";
+return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
   }
 
   std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType) {

Added: cfe/trunk/test/Index/print-objc-manglings.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-objc-manglings.m?rev=313997=auto
==
--- cfe/trunk/test/Index/print-objc-manglings.m (added)
+++ cfe/trunk/test/Index/print-objc-manglings.m Fri Sep 22 09:58:57 2017
@@ -0,0 +1,18 @@
+// RUN: c-index-test -write-pch %t.macho.ast -target i686-apple-darwin %s
+// RUN: c-index-test -test-print-manglings %t.macho.ast | FileCheck 
--check-prefix=MACHO %s
+
+// RUN: c-index-test -write-pch %t.itanium.ast -target i686-pc-linux-gnu %s
+// RUN: c-index-test -test-print-manglings %t.itanium.ast | FileCheck 
--check-prefix=ITANIUM %s
+
+@interface C
+@end
+
+// MACHO: ObjCInterfaceDecl=C{{.*}} [mangled=_OBJC_CLASS_$_C] 
[mangled=_OBJC_METACLASS_$_C]
+// ITANIUM: ObjCInterfaceDecl=C{{.*}} [mangled=_OBJC_CLASS_C] 
[mangled=_OBJC_METACLASS_C]
+
+@implementation C
+@end
+
+// MACHO: ObjCImplementationDecl=C{{.*}} (Definition) 
[mangled=_OBJC_CLASS_$_C] [mangled=_OBJC_METACLASS_$_C]
+// ITANIUM: ObjCImplementationDecl=C{{.*}} (Definition) 

r313995 - [OPENMP] Handle re-declaration of captured variables in CodeGen.

2017-09-22 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Sep 22 09:56:13 2017
New Revision: 313995

URL: http://llvm.org/viewvc/llvm-project?rev=313995=rev
Log:
[OPENMP] Handle re-declaration of captured variables in CodeGen.

If the captured variable has re-declaration we may end up with the
situation where the captured variable is the re-declaration while the
referenced variable is the canonical declaration (or vice versa). In
this case we may generate wrong code. Patch fixes this situation.

Modified:
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/OpenMP/target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=313995=313994=313995=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Sep 22 09:56:13 2017
@@ -263,9 +263,9 @@ public:
 if (I->capturesThis())
   CXXThisFieldDecl = *Field;
 else if (I->capturesVariable())
-  CaptureFields[I->getCapturedVar()] = *Field;
+  CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field;
 else if (I->capturesVariableByCopy())
-  CaptureFields[I->getCapturedVar()] = *Field;
+  CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field;
   }
 }
 
@@ -279,7 +279,7 @@ public:
 
 /// \brief Lookup the captured field decl for a variable.
 virtual const FieldDecl *lookup(const VarDecl *VD) const {
-  return CaptureFields.lookup(VD);
+  return CaptureFields.lookup(VD->getCanonicalDecl());
 }
 
 bool isCXXThisExprCaptured() const { return getThisFieldDecl() != nullptr; 
}

Modified: cfe/trunk/test/OpenMP/target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_codegen.cpp?rev=313995=313994=313995=diff
==
--- cfe/trunk/test/OpenMP/target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_codegen.cpp Fri Sep 22 09:56:13 2017
@@ -110,7 +110,7 @@ int foo(int n) {
   // CHECK:   [[RET2:%.+]] = load i32, i32* [[RHV]], align 4
   // CHECK-NEXT:  [[ERROR:%.+]] = icmp ne i32 [[RET2]], 0
   // CHECK:   call void [[HVT1:@.+]](i[[SZ]] {{[^,]+}})
-  #pragma omp target if(0)
+  #pragma omp target if(0) firstprivate(global)
   {
 global += 1;
   }


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


[PATCH] D37822: [OpenCL] Clean up and add missing fields for block struct

2017-09-22 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 116363.
yaxunl edited the summary of this revision.
yaxunl added a comment.

Add custom fields to block and target hooks to fill them.


https://reviews.llvm.org/D37822

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGOpenCLRuntime.cpp
  lib/CodeGen/CGOpenCLRuntime.h
  lib/CodeGen/TargetInfo.h
  test/CodeGen/blocks-opencl.cl
  test/CodeGenOpenCL/blocks.cl
  test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -7,7 +7,7 @@
 typedef struct {int a;} ndrange_t;
 
 // N.B. The check here only exists to set BL_GLOBAL
-// COMMON: @block_G =  addrspace(1) constant void (i8 addrspace(3)*) addrspace(4)* addrspacecast (void (i8 addrspace(3)*) addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* [[BL_GLOBAL:@__block_literal_global(\.[0-9]+)?]] to void (i8 addrspace(3)*) addrspace(1)*) to void (i8 addrspace(3)*) addrspace(4)*)
+// COMMON: @block_G =  addrspace(1) constant void (i8 addrspace(3)*) addrspace(4)* addrspacecast (void (i8 addrspace(3)*) addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BL_GLOBAL:@__block_literal_global(\.[0-9]+)?]] to void (i8 addrspace(3)*) addrspace(1)*) to void (i8 addrspace(3)*) addrspace(4)*)
 const bl_t block_G = (bl_t) ^ (local void *a) {};
 
 kernel void device_side_enqueue(global int *a, global int *b, int i) {
@@ -27,9 +27,10 @@
   // COMMON: [[NDR:%[a-z0-9]+]] = alloca %struct.ndrange_t, align 4
   // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
-  // COMMON: [[BL:%[0-9]+]] = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor addrspace(2)*, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* %block to void ()*
+  // B32: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block to void ()*
+  // B64: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32 addrspace(1)*, i32 }>* %block to void ()*
   // COMMON: [[BL_I8:%[0-9]+]] = addrspacecast void ()* [[BL]] to i8 addrspace(4)*
-  // COMMON: call i32 @__enqueue_kernel_basic(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* byval [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* [[BL_I8]])
+  // COMMON: call i32 @__enqueue_kernel_basic(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* byval [[NDR]]{{([0-9]+)?}}, i8 addrspace(4)* [[BL_I8]])
   enqueue_kernel(default_queue, flags, ndrange,
  ^(void) {
a[i] = b[i];
@@ -39,7 +40,7 @@
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
   // COMMON: [[WAIT_EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** %event_wait_list to %opencl.clk_event_t{{.*}}* addrspace(4)*
   // COMMON: [[EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** %clk_event to %opencl.clk_event_t{{.*}}* addrspace(4)*
-  // COMMON: [[BL:%[0-9]+]] = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor addrspace(2)*, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* %block3 to void ()*
+  // COMMON: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* %block3 to void ()*
   // COMMON: [[BL_I8:%[0-9]+]] = addrspacecast void ()* [[BL]] to i8 addrspace(4)*
   // COMMON: call i32 @__enqueue_kernel_basic_events(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]],  %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}}* addrspace(4)* [[WAIT_EVNT]], %opencl.clk_event_t{{.*}}* addrspace(4)* [[EVNT]], i8 addrspace(4)* [[BL_I8]])
   enqueue_kernel(default_queue, flags, ndrange, 2, _wait_list, _event,
@@ -52,11 +53,11 @@
   // B32: %[[TMP:.*]] = alloca [1 x i32]
   // B32: %[[TMP1:.*]] = getelementptr [1 x i32], [1 x i32]* %[[TMP]], i32 0, i32 0
   // B32: store i32 256, i32* %[[TMP1]], align 4
-  // B32: call i32 @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i32* %[[TMP1]])
+  // B32: call i32 @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i32* %[[TMP1]])
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 256, i64* %[[TMP1]], align 8
-  // B64: call i32 

[PATCH] D38046: [Atomic][X8664] set max atomic inline/promote width according to the target

2017-09-22 Thread Wei Mi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313992: [Atomic][X8664] set max atomic inline width 
according to the target (authored by wmi).

Changed prior to commit:
  https://reviews.llvm.org/D38046?vs=116107=116362#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38046

Files:
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/Basic/Targets/X86.h
  cfe/trunk/test/CodeGenCXX/atomic-inline.cpp
  cfe/trunk/test/OpenMP/atomic_capture_codegen.cpp
  cfe/trunk/test/OpenMP/atomic_read_codegen.c
  cfe/trunk/test/OpenMP/atomic_update_codegen.cpp
  cfe/trunk/test/OpenMP/atomic_write_codegen.c

Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -620,6 +620,7 @@
 
   Target->setSupportedOpenCLOpts();
   Target->setOpenCLExtensionOpts();
+  Target->setMaxAtomicWidth();
 
   if (!Target->validateTarget(Diags))
 return nullptr;
Index: cfe/trunk/lib/Basic/Targets/X86.h
===
--- cfe/trunk/lib/Basic/Targets/X86.h
+++ cfe/trunk/lib/Basic/Targets/X86.h
@@ -814,7 +814,7 @@
 
 // x86-64 has atomics up to 16 bytes.
 MaxAtomicPromoteWidth = 128;
-MaxAtomicInlineWidth = 128;
+MaxAtomicInlineWidth = 64;
   }
 
   BuiltinVaListKind getBuiltinVaListKind() const override {
@@ -872,6 +872,12 @@
  HasSizeMismatch);
   }
 
+  void setMaxAtomicWidth() override {
+if (hasFeature("cx16"))
+  MaxAtomicInlineWidth = 128;
+return;
+  }
+
   ArrayRef getTargetBuiltins() const override;
 };
 
Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -448,6 +448,9 @@
   /// \brief Return the maximum width lock-free atomic operation which can be
   /// inlined given the supported features of the given target.
   unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
+  /// \brief Set the maximum inline or promote width lock-free atomic operation
+  /// for the given target.
+  virtual void setMaxAtomicWidth() {}
   /// \brief Returns true if the given target supports lock-free atomic
   /// operations at the specified width and alignment.
   virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits,
Index: cfe/trunk/test/OpenMP/atomic_read_codegen.c
===
--- cfe/trunk/test/OpenMP/atomic_read_codegen.c
+++ cfe/trunk/test/OpenMP/atomic_read_codegen.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s
-// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
 // expected-no-diagnostics
 // REQUIRES: x86-registered-target
 #ifndef HEADER
Index: cfe/trunk/test/OpenMP/atomic_update_codegen.cpp
===
--- cfe/trunk/test/OpenMP/atomic_update_codegen.cpp
+++ cfe/trunk/test/OpenMP/atomic_update_codegen.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s
-// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
 // expected-no-diagnostics
 #ifndef HEADER
 #define HEADER
Index: cfe/trunk/test/OpenMP/atomic_capture_codegen.cpp
===
--- cfe/trunk/test/OpenMP/atomic_capture_codegen.cpp
+++ cfe/trunk/test/OpenMP/atomic_capture_codegen.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s
-// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c -triple 

r313992 - [Atomic][X8664] set max atomic inline width according to the target

2017-09-22 Thread Wei Mi via cfe-commits
Author: wmi
Date: Fri Sep 22 09:30:00 2017
New Revision: 313992

URL: http://llvm.org/viewvc/llvm-project?rev=313992=rev
Log:
[Atomic][X8664] set max atomic inline width according to the target

This is to fix PR31620. MaxAtomicInlineWidth is set to 128 for x86_64. However
for target without cx16 support, 128 atomic operation will generate __sync_*
libcalls. The patch set MaxAtomicInlineWidth to 64 if the target doesn't support
cx16.

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

Added:
cfe/trunk/test/CodeGenCXX/atomic-inline.cpp
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Basic/Targets/X86.h
cfe/trunk/test/OpenMP/atomic_capture_codegen.cpp
cfe/trunk/test/OpenMP/atomic_read_codegen.c
cfe/trunk/test/OpenMP/atomic_update_codegen.cpp
cfe/trunk/test/OpenMP/atomic_write_codegen.c

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=313992=313991=313992=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Sep 22 09:30:00 2017
@@ -448,6 +448,9 @@ public:
   /// \brief Return the maximum width lock-free atomic operation which can be
   /// inlined given the supported features of the given target.
   unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
+  /// \brief Set the maximum inline or promote width lock-free atomic operation
+  /// for the given target.
+  virtual void setMaxAtomicWidth() {}
   /// \brief Returns true if the given target supports lock-free atomic
   /// operations at the specified width and alignment.
   virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits,

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=313992=313991=313992=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Fri Sep 22 09:30:00 2017
@@ -620,6 +620,7 @@ TargetInfo::CreateTargetInfo(Diagnostics
 
   Target->setSupportedOpenCLOpts();
   Target->setOpenCLExtensionOpts();
+  Target->setMaxAtomicWidth();
 
   if (!Target->validateTarget(Diags))
 return nullptr;

Modified: cfe/trunk/lib/Basic/Targets/X86.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.h?rev=313992=313991=313992=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.h (original)
+++ cfe/trunk/lib/Basic/Targets/X86.h Fri Sep 22 09:30:00 2017
@@ -814,7 +814,7 @@ public:
 
 // x86-64 has atomics up to 16 bytes.
 MaxAtomicPromoteWidth = 128;
-MaxAtomicInlineWidth = 128;
+MaxAtomicInlineWidth = 64;
   }
 
   BuiltinVaListKind getBuiltinVaListKind() const override {
@@ -872,6 +872,12 @@ public:
  HasSizeMismatch);
   }
 
+  void setMaxAtomicWidth() override {
+if (hasFeature("cx16"))
+  MaxAtomicInlineWidth = 128;
+return;
+  }
+
   ArrayRef getTargetBuiltins() const override;
 };
 

Added: cfe/trunk/test/CodeGenCXX/atomic-inline.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/atomic-inline.cpp?rev=313992=auto
==
--- cfe/trunk/test/CodeGenCXX/atomic-inline.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/atomic-inline.cpp Fri Sep 22 09:30:00 2017
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - -triple=x86_64-linux-gnu | 
FileCheck %s
+// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - -triple=x86_64-linux-gnu 
-target-cpu core2 | FileCheck %s --check-prefix=CORE2
+// Check the atomic code generation for cpu targets w/wo cx16 support.
+
+struct alignas(8) AM8 {
+  int f1, f2;
+};
+AM8 m8;
+AM8 load8() {
+  AM8 am;
+  // CHECK-LABEL: @_Z5load8v
+  // CHECK: load atomic i64, {{.*}} monotonic
+  // CORE2-LABEL: @_Z5load8v
+  // CORE2: load atomic i64, {{.*}} monotonic
+  __atomic_load(, , 0);
+  return am;
+}
+
+AM8 s8;
+void store8() {
+  // CHECK-LABEL: @_Z6store8v
+  // CHECK: store atomic i64 {{.*}} monotonic
+  // CORE2-LABEL: @_Z6store8v
+  // CORE2: store atomic i64 {{.*}} monotonic
+  __atomic_store(, , 0);
+}
+
+bool cmpxchg8() {
+  AM8 am;
+  // CHECK-LABEL: @_Z8cmpxchg8v
+  // CHECK: cmpxchg i64* {{.*}} monotonic
+  // CORE2-LABEL: @_Z8cmpxchg8v
+  // CORE2: cmpxchg i64* {{.*}} monotonic
+  return __atomic_compare_exchange(, , , 0, 0, 0);
+}
+
+struct alignas(16) AM16 {
+  long f1, f2;
+};
+
+AM16 m16;
+AM16 load16() {
+  AM16 am;
+  // CHECK-LABEL: @_Z6load16v
+  // CHECK: call void @__atomic_load
+  // CORE2-LABEL: @_Z6load16v
+  // CORE2: load atomic i128, {{.*}} monotonic
+  __atomic_load(, , 0);
+  return am;
+}
+
+AM16 s16;
+void store16() {
+ 

r313991 - Fix unused variable warning. NFCI.

2017-09-22 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Fri Sep 22 09:26:17 2017
New Revision: 313991

URL: http://llvm.org/viewvc/llvm-project?rev=313991=rev
Log:
Fix unused variable warning. NFCI.

Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=313991=313990=313991=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Sep 22 09:26:17 2017
@@ -1698,8 +1698,7 @@ void CXXNameMangler::mangleLambda(const
 = cast(Context)->getIdentifier()) {
 mangleSourceName(Name);
 const TemplateArgumentList *TemplateArgs = nullptr;
-if (const TemplateDecl *TD =
-isTemplate(cast(Context), TemplateArgs))
+if (isTemplate(cast(Context), TemplateArgs))
   mangleTemplateArgs(*TemplateArgs);
 Out << 'M';
   }


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


[PATCH] D37042: Teach clang to tolerate the 'p = nullptr + n' idiom used by glibc

2017-09-22 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

For the record, Firefox was using this trick. This patch is breaking a ci build 
(clang trunk + warning as errors)
More information here: https://bugzilla.mozilla.org/show_bug.cgi?id=1402362


Repository:
  rL LLVM

https://reviews.llvm.org/D37042



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


[PATCH] D38113: OpenCL: Assume functions are convergent

2017-09-22 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In https://reviews.llvm.org/D38113#877874, @Anastasia wrote:

> The problem of adding this attribute conservatively for all functions is that 
> it prevents some optimizations to happen. I agree to commit this as a 
> temporary fix to guarantee correctness of generated code.


This is one of those unfortunate things we had to do for correctness in CUDA, 
and the situation seems the same here. When we're not doing separate 
compilation (which I imagine we're also generally not doing for OpenCL 
complication), I'm under the impression that the attribute removal is fairly 
effective.

> But if we ask to add the `convergent` attribute into the spec we can avoid 
> doing this in the compiler?

But even if you do that, would that not be in a future version of OpenCL? If 
so, for code complying to current standards, you'd need this behavior.


https://reviews.llvm.org/D38113



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


[PATCH] D38179: [clang-tidy] Handle unions in modernize-use-equals-default check

2017-09-22 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons created this revision.
Herald added subscribers: xazax.hun, JDevlieghere.

Do not replace the constructor or destructor of a union with =default
if it would be implicitly deleted.

Fixes: PR27926


https://reviews.llvm.org/D38179

Files:
  clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  test/clang-tidy/modernize-use-equals-default.cpp


Index: test/clang-tidy/modernize-use-equals-default.cpp
===
--- test/clang-tidy/modernize-use-equals-default.cpp
+++ test/clang-tidy/modernize-use-equals-default.cpp
@@ -205,3 +205,23 @@
   };
 
 STRUCT_WITH_DEFAULT(unsigned char, InMacro)
+
+// Unions
+union UnionOfPOD {
+  UnionOfPOD() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-FIXES: UnionOfPOD() = default;
+  ~UnionOfPOD() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-FIXES: ~UnionOfPOD() = default;
+  int i;
+  double j;
+};
+
+union UnionOfNonTrivial {
+  UnionOfNonTrivial() {}
+  ~UnionOfNonTrivial() {}
+  int i;
+  double j;
+  NE k;
+};
Index: clang-tidy/modernize/UseEqualsDefaultCheck.cpp
===
--- clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -111,6 +111,44 @@
  BasesToInit.size() + FieldsToInit.size();
 }
 
+/// Checks that the given default constructor can be defaulted.
+static bool defaultConstructorCanBeDefaulted(ASTContext *Context,
+ const CXXMethodDecl *Operator) {
+  const auto *Record = Operator->getParent();
+
+  // A defaulted default constructor of a union with a field with a non trivial
+  // default constructor would be deleted.
+  if (Record->isUnion()) {
+auto FieldsToInit = getAllNamedFields(Record);
+
+for (const auto *Field : FieldsToInit) {
+  QualType T = Context->getBaseElementType(Field->getType());
+
+  if (const RecordType *RecordTy = T->getAs()) {
+CXXRecordDecl *FieldRec = cast(RecordTy->getDecl());
+
+if (FieldRec->hasNonTrivialDefaultConstructor())
+  return false;
+  }
+}
+  }
+
+  return true;
+}
+
+/// Checks that the given destructor can be defaulted.
+static bool destructorCanBeDefaulted(ASTContext *Context,
+ const CXXMethodDecl *Operator) {
+  const auto *Record = Operator->getParent();
+
+  // A defaulted destructor of a union with a field with a non trivial
+  // destructor would be deleted.
+  if (Record->defaultedDestructorIsDeleted())
+return false;
+
+  return true;
+}
+
 /// \brief Checks that the given method is an overloading of the assignment
 /// operator, has copy signature, returns a reference to "*this" and copies
 /// all its members and subobjects.
@@ -274,6 +312,8 @@
 
   if (const auto *Ctor = dyn_cast(SpecialFunctionDecl)) {
 if (Ctor->getNumParams() == 0) {
+  if (!defaultConstructorCanBeDefaulted(Result.Context, Ctor))
+return;
   SpecialFunctionName = "default constructor";
 } else {
   if (!isCopyConstructorAndCanBeDefaulted(Result.Context, Ctor))
@@ -286,6 +326,8 @@
   }
 }
   } else if (isa(SpecialFunctionDecl)) {
+if (!destructorCanBeDefaulted(Result.Context, SpecialFunctionDecl))
+  return;
 SpecialFunctionName = "destructor";
   } else {
 if (!isCopyAssignmentAndCanBeDefaulted(Result.Context, 
SpecialFunctionDecl))


Index: test/clang-tidy/modernize-use-equals-default.cpp
===
--- test/clang-tidy/modernize-use-equals-default.cpp
+++ test/clang-tidy/modernize-use-equals-default.cpp
@@ -205,3 +205,23 @@
   };
 
 STRUCT_WITH_DEFAULT(unsigned char, InMacro)
+
+// Unions
+union UnionOfPOD {
+  UnionOfPOD() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-FIXES: UnionOfPOD() = default;
+  ~UnionOfPOD() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-FIXES: ~UnionOfPOD() = default;
+  int i;
+  double j;
+};
+
+union UnionOfNonTrivial {
+  UnionOfNonTrivial() {}
+  ~UnionOfNonTrivial() {}
+  int i;
+  double j;
+  NE k;
+};
Index: clang-tidy/modernize/UseEqualsDefaultCheck.cpp
===
--- clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -111,6 +111,44 @@
  BasesToInit.size() + FieldsToInit.size();
 }
 
+/// Checks that the given default constructor can be defaulted.
+static bool defaultConstructorCanBeDefaulted(ASTContext *Context,
+ const CXXMethodDecl *Operator) {
+  const auto *Record = Operator->getParent();
+
+  // A defaulted default constructor of a union with a field with a non trivial
+  // default constructor would be deleted.
+  if (Record->isUnion()) {
+auto FieldsToInit = getAllNamedFields(Record);
+
+for 

[PATCH] D38113: OpenCL: Assume functions are convergent

2017-09-22 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added a comment.

> Yes, that's why if it would be responsibility of the kernel developer to 
> specify this explicitly we could avoid this complications in the compiler. 
> But if we add it into the language now we still need to support the 
> correctness for the code written with the earlier standards. And also it adds 
> the complexity to the programmer to make sure it's specified correctly. But I 
> think it is still worth discussing with the spec committee.

To me this seems like a small complication in the compiler to avoid an 
extremely easy bug for users to write.  But, not my language.  :)

> The deduction of convergent is indeed tricky. So if there is any function in 
> the CFG path which is marked as convergent ( or "non-convergent") this will 
> have to be back propagated to the callers unless we force to explicitly 
> specify it but it would be too error prone for the kernel writers I guess.

This probably isn't the right forum to discuss proposals to change the LLVM IR 
spec.  But if you want to propose something like this, please cc me on the 
thread, I probably have opinions.  :)

> Btw, what is the advantage of having "non-convergent" instead and why is the 
> deduction of convergent property more complicated with it?

The advantage of switching LLVM IR to non-convergent would be that front-ends 
wouldn't have the bug that arsenm is fixing here.  "Unadorned" IR would be 
correct.  And, in the absence of external or unanalyzable indirect calls, you'd 
get the same performance as we get today even if you had no annotations.

The complexity I was referring to occurs if you add the non-convergent 
attribute and keep the convergent attr.  I don't think we want that.

But I'm not really proposing a change to the convergent attribute in LLVM IR -- 
it's probably better to leave it as-is, since we all understand how it works, 
it ain't broke.


https://reviews.llvm.org/D38113



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


[PATCH] D30691: [analyzer] Support for naive cross translational unit analysis

2017-09-22 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl added a comment.

In a similar case, static inline functions are an issue.

inc.h

  void foo();
  static inline void wow()
  {
  int a = *(int*)0;
  }

main.c

  #include "inc.h"
  void moo()
  {
  foo();
  wow();
  }

other.c

  #include "inc.h"
  void foo()
  {
  wow();
  }

The inline function is inlined into each calling AST as different AST objects. 
This causes the PathDiagnostics to be distinct, while pointing to the exact 
same source location.

When the compareCrossTUSourceLocs function tries to compare the FullSourceLocs, 
it cannot find a difference and FlushDiagnostics will assert on an erroneous 
compare function.

For my purposes I replaced the return statement of the compareCrossTUSourceLocs 
function with:

  return XL.getFileID() < YL.getFileID();

A more correct fix would create only one unique diagnostic for both cases.


https://reviews.llvm.org/D30691



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


[PATCH] D38171: Implement clang-tidy check aliases.

2017-09-22 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

On a somewhat related  note, since this is already talking about aliases

I feel like the current handling of the clang-tidy check aliases needs 
adjusting.
If one enables all the checks (`Checks: '*'`), and then disables some of them
on check-by-check basis, if the disabled check has aliases
(`cppcoreguidelines-pro-type-vararg` vs `hicpp-vararg`, `hicpp-no-array-decay`
vs `cppcoreguidelines-pro-bounds-array-to-pointer-decay` and so on)
each of the aliases must be explicitly be disabled too.

This is rather inconvenient.

If that is intentional, perhaps there could be a config option to either disable
creation/registration of the check aliases altogether, or an option to threat
aliases as a hard link, so anything happening to any of the aliases/base check
would happen to all of them.

(Also, if the check has parameters, and one specifies different parameters for 
the base check, and the aliases, what happens?)


https://reviews.llvm.org/D38171



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


[PATCH] D38171: Implement clang-tidy check aliases.

2017-09-22 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

AndrĂ¡s, that's definitely an interesting idea. However, it might be interesting 
to explore a more principled approach:

1. Make `clang-diagnostic-*` checks first-class citizens and take full control 
of all diagnostics, i.e. disable all Clang diagnostics by default, and enable 
the ones that correspond to the enabled clang-diagnostic checks.
2. Make aliases first-class citizens (there was a proposal as well, but we 
didn't arrive to a consensus at that time). That would include the ability to 
configure an alias name for any check including clang-diagnostic- and 
clang-analyzer- checks.
3. Use aliases to map clang-diagnostic- checks to check names under cert-, 
hicpp-, etc.

I didn't carefully consider all possible implications and there may be issues 
with any or all of the three parts of this, but I think it's worth exploring.


https://reviews.llvm.org/D38171



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


[PATCH] D20689: [clang-tidy] Suspicious Call Argument checker

2017-09-22 Thread Barancsuk Lilla via Phabricator via cfe-commits
barancsuk added a comment.

I attached the results of the tests.
The warnings are categorized into false positives and renaming opportunities.

F5376033: PostgreSQL 

F5376032: FFmpeg 

F5376031: LLVM 

F5376030: OpenSSL 

F5376029: Xerces 

F5376028: Cpython 


https://reviews.llvm.org/D20689



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


[PATCH] D37804: [OpenCL] Handle address space conversion while setting type alignment

2017-09-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 116345.
Anastasia added a comment.

Created BitCast or AddrSpaceCast conditionally.


https://reviews.llvm.org/D37804

Files:
  lib/CodeGen/CGBuilder.h
  lib/CodeGen/CGExpr.cpp
  test/CodeGenOpenCL/vectorLoadStore.cl


Index: test/CodeGenOpenCL/vectorLoadStore.cl
===
--- test/CodeGenOpenCL/vectorLoadStore.cl
+++ test/CodeGenOpenCL/vectorLoadStore.cl
@@ -1,9 +1,23 @@
 // RUN: %clang_cc1 %s -emit-llvm -O0 -o - | FileCheck %s
 
-typedef char char3 __attribute((ext_vector_type(3)));;
+typedef char char2 __attribute((ext_vector_type(2)));
+typedef char char3 __attribute((ext_vector_type(3)));
+typedef char char8 __attribute((ext_vector_type(8)));
+typedef float float4 __attribute((ext_vector_type(4)));
+;
 
 // Check for optimized vec3 load/store which treats vec3 as vec4.
 void foo(char3 *P, char3 *Q) {
   *P = *Q;
   // CHECK: %{{.*}} = shufflevector <4 x i8> %{{.*}}, <4 x i8> undef, <3 x 
i32> 
 }
+
+// CHECK: define spir_func void @alignment()
+void alignment() {
+  __private char2 data_generic[100];
+  __private char8 data_private[100];
+
+  // CHECK: %{{.*}} = load <4 x float>, <4 x float> addrspace(4)* %{{.*}}, 
align 2
+  // CHECK: store <4 x float> %{{.*}}, <4 x float>* %{{.*}}, align 8
+  ((private float4 *)data_private)[1] = ((float4 *)data_generic)[2];
+}
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -925,6 +925,7 @@
 // Non-converting casts (but not C's implicit conversion from void*).
 case CK_BitCast:
 case CK_NoOp:
+case CK_AddressSpaceConversion:
   if (auto PtrTy = CE->getSubExpr()->getType()->getAs()) {
 if (PtrTy->getPointeeType()->isVoidType())
   break;
@@ -953,8 +954,10 @@
   CodeGenFunction::CFITCK_UnrelatedCast,
   CE->getLocStart());
 }
-
-return Builder.CreateBitCast(Addr, ConvertType(E->getType()));
+return CE->getCastKind() != CK_AddressSpaceConversion
+   ? Builder.CreateBitCast(Addr, ConvertType(E->getType()))
+   : Builder.CreateAddrSpaceCast(Addr,
+ ConvertType(E->getType()));
   }
   break;
 
Index: lib/CodeGen/CGBuilder.h
===
--- lib/CodeGen/CGBuilder.h
+++ lib/CodeGen/CGBuilder.h
@@ -145,6 +145,13 @@
Addr.getAlignment());
   }
 
+  using CGBuilderBaseTy::CreateAddrSpaceCast;
+  Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty,
+  const llvm::Twine  = "") {
+return Address(CreateAddrSpaceCast(Addr.getPointer(), Ty, Name),
+   Addr.getAlignment());
+  }
+
   /// Cast the element type of the given address to a different type,
   /// preserving information like the alignment and address space.
   Address CreateElementBitCast(Address Addr, llvm::Type *Ty,


Index: test/CodeGenOpenCL/vectorLoadStore.cl
===
--- test/CodeGenOpenCL/vectorLoadStore.cl
+++ test/CodeGenOpenCL/vectorLoadStore.cl
@@ -1,9 +1,23 @@
 // RUN: %clang_cc1 %s -emit-llvm -O0 -o - | FileCheck %s
 
-typedef char char3 __attribute((ext_vector_type(3)));;
+typedef char char2 __attribute((ext_vector_type(2)));
+typedef char char3 __attribute((ext_vector_type(3)));
+typedef char char8 __attribute((ext_vector_type(8)));
+typedef float float4 __attribute((ext_vector_type(4)));
+;
 
 // Check for optimized vec3 load/store which treats vec3 as vec4.
 void foo(char3 *P, char3 *Q) {
   *P = *Q;
   // CHECK: %{{.*}} = shufflevector <4 x i8> %{{.*}}, <4 x i8> undef, <3 x i32> 
 }
+
+// CHECK: define spir_func void @alignment()
+void alignment() {
+  __private char2 data_generic[100];
+  __private char8 data_private[100];
+
+  // CHECK: %{{.*}} = load <4 x float>, <4 x float> addrspace(4)* %{{.*}}, align 2
+  // CHECK: store <4 x float> %{{.*}}, <4 x float>* %{{.*}}, align 8
+  ((private float4 *)data_private)[1] = ((float4 *)data_generic)[2];
+}
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -925,6 +925,7 @@
 // Non-converting casts (but not C's implicit conversion from void*).
 case CK_BitCast:
 case CK_NoOp:
+case CK_AddressSpaceConversion:
   if (auto PtrTy = CE->getSubExpr()->getType()->getAs()) {
 if (PtrTy->getPointeeType()->isVoidType())
   break;
@@ -953,8 +954,10 @@
   CodeGenFunction::CFITCK_UnrelatedCast,
   CE->getLocStart());
 }
-
-return Builder.CreateBitCast(Addr, ConvertType(E->getType()));
+return CE->getCastKind() != CK_AddressSpaceConversion
+  

[PATCH] D38040: [OpenMP] Add an additional test for D34888

2017-09-22 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D38040#878441, @gtbercea wrote:

> The test is verifying whether the parameter is passed to the kernel 
> correctly. I believe it was not passed as a reference before the patch.


Ah, right: This isn't checked anywhere before. Maybe add a comment about what's 
tested here?
Do we want to check the rest of the codegen with a focus that the variable is 
passed as a reference?

> In addition to that, something that was in my previous patch is related to 
> this code:
> 
>   DSAStack->checkMappableExprComponentListsForDeclAtLevel(
>   D, Level, 
> [&](OMPClauseMappableExprCommon::MappableExprComponentListRef
> 
> 
> In particular with the Level variable. Should the Level variable actually be 
> Level + 1 in this case?

I'm not sure, the current public `clang-ykt` has `Level`:  
https://github.com/clang-ykt/clang/blob/d181aed/lib/Sema/SemaOpenMP.cpp#L1361


Repository:
  rL LLVM

https://reviews.llvm.org/D38040



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


[PATCH] D37861: preserving #pragma clang assume_nonnull in preprocessed output

2017-09-22 Thread Zbigniew Sarbinowski via Phabricator via cfe-commits
zibi added a comment.

Yes, please do the commit, thank you.

In https://reviews.llvm.org/D37861#878194, @efriedma wrote:

> LGTM.
>
> Do you want me to commit this for you?





https://reviews.llvm.org/D37861



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


[PATCH] D38159: [clang] Fix printf fixit for objc specific types

2017-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Aside from a few minor nits, LGTM!




Comment at: test/FixIt/fixit-format-ios.m:2
+// RUN: cp %s %t
+// RUN: %clang_cc1 -triple thumbv7-apple-ios8.0.0 -fsyntax-only -fblocks 
-Wformat -fixit %t
+// RUN: grep -v CHECK %t | FileCheck %s

I don't think you need to enable `-fblocks` for this test.



Comment at: test/FixIt/fixit-format-ios.m:12-14
+  // For thumbv7-apple-ios8.0.0 
+  // the underlying type of size_t is unsigned long 
+  // and for ssize_t it is long.

Reflow these comments.


Repository:
  rL LLVM

https://reviews.llvm.org/D38159



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


[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-09-22 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

The run on llvm indicates that we don't want this to trigger if the base class 
doesn't have anything to copy (that is, no fields & a defaulted copy-ctor, or 
an empty copy-ctor).


https://reviews.llvm.org/D33722



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


[PATCH] D38171: Implement clang-tidy check aliases.

2017-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for working on this -- it's very nice functionality!




Comment at: clang-tidy/cert/CERTTidyModule.cpp:79
+  void addWarningCheckAliases(
+  llvm::DenseMap ) {
+WarningCheckAliases.insert(

You should declare this as `override`.



Comment at: clang-tidy/cert/CERTTidyModule.cpp:80-82
+WarningCheckAliases.insert(
+{diag::warn_exception_caught_by_earlier_handler, "cert-err54-cpp"});
+WarningCheckAliases.insert(

Can you use `try_emplace()` instead of `insert()` -- this removes the need for 
the braced initializers to create the pair.



Comment at: clang-tidy/cert/CERTTidyModule.cpp:83
+WarningCheckAliases.insert(
+{diag::ext_offsetof_non_standardlayout_type, "cert-exp59-cpp"});
+  }

This check also needs a test case.


https://reviews.llvm.org/D38171



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


[PATCH] D30691: [analyzer] Support for naive cross translational unit analysis

2017-09-22 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl added a comment.

While testing this I stumbled upon a crash with the following test case:

inc.h

  #define BASE ((int*)0)
  void foo();

main.c:

  #include "inc.h"
  void moo()
  {
  int a = BASE[0];
  foo();
  }

other.c

  #include "inc.h"
  void foo()
  {
  int a = BASE[0];
  }

Note that I used a custom checker that did not stop on the path like the 
DerefChecker would here. I did not know how to reproduce it with official 
checkers, but the issue should be understandable without reproduction.

With the given test a checker may produce two results for the null dereference 
in moo() and foo(). When analyzing main.c they will both be found and therefore 
sorted with PathDiagnostic.cpp "compareCrossTUSourceLocs".

If either of the FullSourceLocs is a MacroID, the call 
SM.getFileEntryForID(XL.getFileID()) will return a null pointer. The null 
pointer will crash the program when attempting to call ->getName() on it.

My solution was to add the following lines before the .getFileID() calls:

  XL = XL.getExpansionLoc();
  YL = YL.getExpansionLoc();




Comment at: lib/StaticAnalyzer/Core/PathDiagnostic.cpp:391
+return XL.isBeforeInTranslationUnitThan(YL);
+  return SM.getFileEntryForID(XL.getFileID())->getName() <
+ SM.getFileEntryForID(YL.getFileID())->getName();

see comment


https://reviews.llvm.org/D30691



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


[PATCH] D38151: [clang] Fix isExternC matcher docs

2017-09-22 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rL LLVM

https://reviews.llvm.org/D38151



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


[PATCH] D38113: OpenCL: Assume functions are convergent

2017-09-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: test/CodeGenOpenCL/convergent.cl:130
+// CHECK: attributes #0 = { noinline norecurse nounwind "
+// CHECK: attributes #1 = { {{[^}]*}}convergent{{[^}]*}} }
+// CHECK: attributes #2 = { {{[^}]*}}convergent{{[^}]*}} }

We won't have noduplicate any more?


https://reviews.llvm.org/D38113



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


[PATCH] D38113: OpenCL: Assume functions are convergent

2017-09-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In https://reviews.llvm.org/D38113#877906, @jlebar wrote:

> > The problem of adding this attribute conservatively for all functions is 
> > that it prevents some optimizations to happen.
>
> function-attrs removes the convergent attribute from anything it can prove 
> does not call a convergent function.
>
> I agree this is a nonoptimal solution.  A better way would be to assume that 
> any cuda/opencl function is convergent and then figure out what isn't.  This 
> would let you generate correct cuda/opencl code in a front-end without 
> worrying about this attribute.
>
> One problem with this approach is, suppose you call an external function, 
> whose body llvm cannot see.  We need some way to mark this function as 
> not-convergent, so that its callers can also be inferred to be not 
> convergent.  LLVM currently only has a "convergent" attribute.  In the 
> absence of a new "not-convergent" attribute, the only way we can tell LLVM 
> that this external function is not convergent is to leave off the attribute.  
> But then this means we assume all functions without the convergent attribute 
> are not convergent, and thus we have to add the attribute everywhere, as this 
> patch does.
>
> OTOH if we added a not-convergent attribute, we'd have to have rules about 
> what happens if both attributes are on a function, and everywhere that 
> checked whether a function was convergent would become significantly more 
> complicated.  I'm not sure that's worthwhile.


Yes, that's why if it would be responsibility of the kernel developer to  
specify this explicitly we could avoid this complications in the compiler. But 
if we add it into the language now we still need to support the correctness for 
the code written with the earlier standards. And also it adds the complexity to 
the programmer to make sure it's specified correctly. But I think it is still 
worth discussing with the spec committee.

The deduction of convergent is indeed tricky. So if there is any function in 
the CFG path which is marked as `convergent` ( or "non-convergent") this will 
have to be back propagated to the callers unless we force to explicitly specify 
it but it would be too error prone for the kernel writers I guess. Btw, what is 
the advantage of having "non-convergent" instead and why is the deduction of 
convergent property more complicated with it?


https://reviews.llvm.org/D38113



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


[PATCH] D34512: Add preliminary Cross Translation Unit support library

2017-09-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313975: Add Cross Translation Unit support library (authored 
by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D34512?vs=116195=116327#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34512

Files:
  cfe/trunk/include/clang/Basic/AllDiagnostics.h
  cfe/trunk/include/clang/Basic/CMakeLists.txt
  cfe/trunk/include/clang/Basic/Diagnostic.td
  cfe/trunk/include/clang/Basic/DiagnosticCrossTUKinds.td
  cfe/trunk/include/clang/Basic/DiagnosticIDs.h
  cfe/trunk/include/clang/CrossTU/CrossTUDiagnostic.h
  cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/lib/Basic/DiagnosticIDs.cpp
  cfe/trunk/lib/CMakeLists.txt
  cfe/trunk/lib/CrossTU/CMakeLists.txt
  cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
  cfe/trunk/test/Analysis/func-mapping-test.cpp
  cfe/trunk/test/CMakeLists.txt
  cfe/trunk/test/lit.cfg.py
  cfe/trunk/tools/CMakeLists.txt
  cfe/trunk/tools/clang-func-mapping/CMakeLists.txt
  cfe/trunk/tools/clang-func-mapping/ClangFnMapGen.cpp
  cfe/trunk/tools/diagtool/DiagnosticNames.cpp
  cfe/trunk/unittests/CMakeLists.txt
  cfe/trunk/unittests/CrossTU/CMakeLists.txt
  cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: cfe/trunk/include/clang/Basic/CMakeLists.txt
===
--- cfe/trunk/include/clang/Basic/CMakeLists.txt
+++ cfe/trunk/include/clang/Basic/CMakeLists.txt
@@ -9,6 +9,7 @@
 clang_diag_gen(AST)
 clang_diag_gen(Comment)
 clang_diag_gen(Common)
+clang_diag_gen(CrossTU)
 clang_diag_gen(Driver)
 clang_diag_gen(Frontend)
 clang_diag_gen(Lex)
Index: cfe/trunk/include/clang/Basic/DiagnosticIDs.h
===
--- cfe/trunk/include/clang/Basic/DiagnosticIDs.h
+++ cfe/trunk/include/clang/Basic/DiagnosticIDs.h
@@ -36,6 +36,7 @@
   DIAG_SIZE_PARSE =  500,
   DIAG_SIZE_AST   =  110,
   DIAG_SIZE_COMMENT   =  100,
+  DIAG_SIZE_CROSSTU   =  100,
   DIAG_SIZE_SEMA  = 3500,
   DIAG_SIZE_ANALYSIS  =  100
 };
@@ -49,7 +50,8 @@
   DIAG_START_PARSE = DIAG_START_LEX   + DIAG_SIZE_LEX,
   DIAG_START_AST   = DIAG_START_PARSE + DIAG_SIZE_PARSE,
   DIAG_START_COMMENT   = DIAG_START_AST   + DIAG_SIZE_AST,
-  DIAG_START_SEMA  = DIAG_START_COMMENT   + DIAG_SIZE_COMMENT,
+  DIAG_START_CROSSTU   = DIAG_START_COMMENT   + DIAG_SIZE_CROSSTU,
+  DIAG_START_SEMA  = DIAG_START_CROSSTU   + DIAG_SIZE_COMMENT,
   DIAG_START_ANALYSIS  = DIAG_START_SEMA  + DIAG_SIZE_SEMA,
   DIAG_UPPER_LIMIT = DIAG_START_ANALYSIS  + DIAG_SIZE_ANALYSIS
 };
Index: cfe/trunk/include/clang/Basic/DiagnosticCrossTUKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticCrossTUKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticCrossTUKinds.td
@@ -0,0 +1,18 @@
+//==--- DiagnosticCrossTUKinds.td - Cross Translation Unit diagnostics ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+let Component = "CrossTU" in {
+
+def err_fnmap_parsing : Error<
+  "error parsing index file: '%0' line: %1 'UniqueID filename' format "
+  "expected">;
+
+def err_multiple_def_index : Error<
+  "multiple definitions are found for the same key in index ">;
+}
Index: cfe/trunk/include/clang/Basic/Diagnostic.td
===
--- cfe/trunk/include/clang/Basic/Diagnostic.td
+++ cfe/trunk/include/clang/Basic/Diagnostic.td
@@ -133,6 +133,7 @@
 include "DiagnosticAnalysisKinds.td"
 include "DiagnosticCommentKinds.td"
 include "DiagnosticCommonKinds.td"
+include "DiagnosticCrossTUKinds.td"
 include "DiagnosticDriverKinds.td"
 include "DiagnosticFrontendKinds.td"
 include "DiagnosticLexKinds.td"
Index: cfe/trunk/include/clang/Basic/AllDiagnostics.h
===
--- cfe/trunk/include/clang/Basic/AllDiagnostics.h
+++ cfe/trunk/include/clang/Basic/AllDiagnostics.h
@@ -18,6 +18,7 @@
 #include "clang/AST/ASTDiagnostic.h"
 #include "clang/AST/CommentDiagnostic.h"
 #include "clang/Analysis/AnalysisDiagnostic.h"
+#include "clang/CrossTU/CrossTUDiagnostic.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Lex/LexDiagnostic.h"
Index: cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h
===
--- cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h
+++ 

[PATCH] D38074: Fix TBAA information for reference accesses

2017-09-22 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 116326.
kosarev added a comment.

Refined the TODO wording.


https://reviews.llvm.org/D38074

Files:
  lib/CodeGen/CodeGenTBAA.cpp
  test/CodeGen/tbaa-reference.cpp


Index: test/CodeGen/tbaa-reference.cpp
===
--- test/CodeGen/tbaa-reference.cpp
+++ test/CodeGen/tbaa-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm 
-o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for reference accesses.
+
+struct S;
+
+struct B {
+  S 
+  B(S ) : s(s) {}
+  void bar();
+};
+
+void foo(S ) {
+  B b(s);
+  b.bar();
+}
+
+// CHECK-LABEL: _Z3fooR1S
+// Check initialization of the reference parameter in foo().
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa 
[[TAG_pointer:!.*]]
+//
+// CHECK-LABEL: _ZN1BC2ER1S
+// TODO: Check loading of the reference parameter in B::B(S&).
+// Check initialization of B::s in B::B(S&).
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+//
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 
0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -145,10 +145,10 @@
   if (Ty->isStdByteType())
 return MetadataCache[Ty] = getChar();
 
-  // Handle pointers.
+  // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
-  if (Ty->isPointerType())
+  if (Ty->isPointerType() || Ty->isReferenceType())
 return MetadataCache[Ty] = createTBAAScalarType("any pointer",
 getChar());
 


Index: test/CodeGen/tbaa-reference.cpp
===
--- test/CodeGen/tbaa-reference.cpp
+++ test/CodeGen/tbaa-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for reference accesses.
+
+struct S;
+
+struct B {
+  S 
+  B(S ) : s(s) {}
+  void bar();
+};
+
+void foo(S ) {
+  B b(s);
+  b.bar();
+}
+
+// CHECK-LABEL: _Z3fooR1S
+// Check initialization of the reference parameter in foo().
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer:!.*]]
+//
+// CHECK-LABEL: _ZN1BC2ER1S
+// TODO: Check loading of the reference parameter in B::B(S&).
+// Check initialization of B::s in B::B(S&).
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+//
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -145,10 +145,10 @@
   if (Ty->isStdByteType())
 return MetadataCache[Ty] = getChar();
 
-  // Handle pointers.
+  // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
-  if (Ty->isPointerType())
+  if (Ty->isPointerType() || Ty->isReferenceType())
 return MetadataCache[Ty] = createTBAAScalarType("any pointer",
 getChar());
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r313975 - Add Cross Translation Unit support library

2017-09-22 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Sep 22 04:11:01 2017
New Revision: 313975

URL: http://llvm.org/viewvc/llvm-project?rev=313975=rev
Log:
Add Cross Translation Unit support library

This patch introduces a class that can help to build tools that require cross
translation unit facilities. This class allows function definitions to be loaded
from external AST files based on an index. In order to use this functionality an
index is required. The index format is a flat text file but it might be
replaced with a different solution in the near future. USRs are used as names to
look up the functions definitions. This class also does caching to avoid
redundant loading of AST files.

Right now only function defnitions can be loaded using this API because this is
what the in progress cross translation unit feature of the Static Analyzer
requires. In to future this might be extended to classes, types etc.

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

Added:
cfe/trunk/include/clang/Basic/DiagnosticCrossTUKinds.td
cfe/trunk/include/clang/CrossTU/
cfe/trunk/include/clang/CrossTU/CrossTUDiagnostic.h
cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h
cfe/trunk/lib/CrossTU/
cfe/trunk/lib/CrossTU/CMakeLists.txt
cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
cfe/trunk/test/Analysis/func-mapping-test.cpp
cfe/trunk/tools/clang-func-mapping/
cfe/trunk/tools/clang-func-mapping/CMakeLists.txt
cfe/trunk/tools/clang-func-mapping/ClangFnMapGen.cpp
cfe/trunk/unittests/CrossTU/
cfe/trunk/unittests/CrossTU/CMakeLists.txt
cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
Modified:
cfe/trunk/include/clang/Basic/AllDiagnostics.h
cfe/trunk/include/clang/Basic/CMakeLists.txt
cfe/trunk/include/clang/Basic/Diagnostic.td
cfe/trunk/include/clang/Basic/DiagnosticIDs.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/Basic/DiagnosticIDs.cpp
cfe/trunk/lib/CMakeLists.txt
cfe/trunk/test/CMakeLists.txt
cfe/trunk/test/lit.cfg.py
cfe/trunk/tools/CMakeLists.txt
cfe/trunk/tools/diagtool/DiagnosticNames.cpp
cfe/trunk/unittests/CMakeLists.txt

Modified: cfe/trunk/include/clang/Basic/AllDiagnostics.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AllDiagnostics.h?rev=313975=313974=313975=diff
==
--- cfe/trunk/include/clang/Basic/AllDiagnostics.h (original)
+++ cfe/trunk/include/clang/Basic/AllDiagnostics.h Fri Sep 22 04:11:01 2017
@@ -18,6 +18,7 @@
 #include "clang/AST/ASTDiagnostic.h"
 #include "clang/AST/CommentDiagnostic.h"
 #include "clang/Analysis/AnalysisDiagnostic.h"
+#include "clang/CrossTU/CrossTUDiagnostic.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Lex/LexDiagnostic.h"

Modified: cfe/trunk/include/clang/Basic/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CMakeLists.txt?rev=313975=313974=313975=diff
==
--- cfe/trunk/include/clang/Basic/CMakeLists.txt (original)
+++ cfe/trunk/include/clang/Basic/CMakeLists.txt Fri Sep 22 04:11:01 2017
@@ -9,6 +9,7 @@ clang_diag_gen(Analysis)
 clang_diag_gen(AST)
 clang_diag_gen(Comment)
 clang_diag_gen(Common)
+clang_diag_gen(CrossTU)
 clang_diag_gen(Driver)
 clang_diag_gen(Frontend)
 clang_diag_gen(Lex)

Modified: cfe/trunk/include/clang/Basic/Diagnostic.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.td?rev=313975=313974=313975=diff
==
--- cfe/trunk/include/clang/Basic/Diagnostic.td (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.td Fri Sep 22 04:11:01 2017
@@ -133,6 +133,7 @@ include "DiagnosticASTKinds.td"
 include "DiagnosticAnalysisKinds.td"
 include "DiagnosticCommentKinds.td"
 include "DiagnosticCommonKinds.td"
+include "DiagnosticCrossTUKinds.td"
 include "DiagnosticDriverKinds.td"
 include "DiagnosticFrontendKinds.td"
 include "DiagnosticLexKinds.td"

Added: cfe/trunk/include/clang/Basic/DiagnosticCrossTUKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCrossTUKinds.td?rev=313975=auto
==
--- cfe/trunk/include/clang/Basic/DiagnosticCrossTUKinds.td (added)
+++ cfe/trunk/include/clang/Basic/DiagnosticCrossTUKinds.td Fri Sep 22 04:11:01 
2017
@@ -0,0 +1,18 @@
+//==--- DiagnosticCrossTUKinds.td - Cross Translation Unit diagnostics 
===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+let Component = "CrossTU" in {
+
+def err_fnmap_parsing : Error<
+  "error 

[PATCH] D38074: Fix TBAA information for reference accesses

2017-09-22 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 116325.
kosarev added a comment.

Added a check for the initialization of the reference member in B::B(S&). (That 
in fact was my original intent; thanks for catching it.)

As to reference loads, we generate them with 
CodeGenFunction::EmitLoadOfReference() that, in contrast to 
CodeGenFunction::EmitLoadOfScalar(), is not TBAA-ready yet and looks to be a 
subject to a separate patch. So, what if we land 
https://reviews.llvm.org/D38126 first and then eventually re-consider the 
issue? Thanks again.


https://reviews.llvm.org/D38074

Files:
  lib/CodeGen/CodeGenTBAA.cpp
  test/CodeGen/tbaa-reference.cpp


Index: test/CodeGen/tbaa-reference.cpp
===
--- test/CodeGen/tbaa-reference.cpp
+++ test/CodeGen/tbaa-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm 
-o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for reference accesses.
+
+struct S;
+
+struct B {
+  S 
+  B(S ) : s(s) {}
+  void bar();
+};
+
+void foo(S ) {
+  B b(s);
+  b.bar();
+}
+
+// CHECK-LABEL: _Z3fooR1S
+// Check initialization of the reference parameter in foo().
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa 
[[TAG_pointer:!.*]]
+//
+// CHECK-LABEL: _ZN1BC2ER1S
+// TODO: Check initialization of the parameter s in B::B(S&).
+// Check initialization of B::s in B::B(S&).
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+//
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 
0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -145,10 +145,10 @@
   if (Ty->isStdByteType())
 return MetadataCache[Ty] = getChar();
 
-  // Handle pointers.
+  // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
-  if (Ty->isPointerType())
+  if (Ty->isPointerType() || Ty->isReferenceType())
 return MetadataCache[Ty] = createTBAAScalarType("any pointer",
 getChar());
 


Index: test/CodeGen/tbaa-reference.cpp
===
--- test/CodeGen/tbaa-reference.cpp
+++ test/CodeGen/tbaa-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for reference accesses.
+
+struct S;
+
+struct B {
+  S 
+  B(S ) : s(s) {}
+  void bar();
+};
+
+void foo(S ) {
+  B b(s);
+  b.bar();
+}
+
+// CHECK-LABEL: _Z3fooR1S
+// Check initialization of the reference parameter in foo().
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer:!.*]]
+//
+// CHECK-LABEL: _ZN1BC2ER1S
+// TODO: Check initialization of the parameter s in B::B(S&).
+// Check initialization of B::s in B::B(S&).
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+//
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -145,10 +145,10 @@
   if (Ty->isStdByteType())
 return MetadataCache[Ty] = getChar();
 
-  // Handle pointers.
+  // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
-  if (Ty->isPointerType())
+  if (Ty->isPointerType() || Ty->isReferenceType())
 return MetadataCache[Ty] = createTBAAScalarType("any pointer",
 getChar());
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38134: [OpenCL] Emit enqueued block as kernel

2017-09-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

>> I feel it would be much simpler if we could always generate the kernel 
>> metadata for blocks. A lot of special case code would be removed if we do 
>> this. OpenCL doesn't prevent kernel functions to be used just as normal 
>> functions (6.7.1) so it should be a perfectly valid thing to do. Do you seen 
>> any issues with that?
> 
> The special cases in metadata generation code is due to the first argument of 
> LLVM block invoke function is not defined in BlockDecl. Emitting metadata for 
> all block invoke functions does not help here.

To be more specific. I am just wondering what do we need for blocks to be used 
as kernels pragmatically. I feel it is essentially kernel calling convention 
and kernel metadata? The kernel arguments metadata however can be omitted 
because their type is fixed to be `local void*` and the number of arguments is 
passed into `enqueue_kernel` call so it is known at the enqueueing side too. 
The block descriptor can be passed as a generic pointer `generic void*` as it 
is cast to the right struct type inside the block invoke function anyway. So if 
we do this we can avoid adding a lot of extra code. Because blocks have reduced 
functionality compared to kernel functions. Also OpenCL allows kernel functions 
to be called just as normal functions so this way we can support second use 
case for blocks too. What do you think about it?




Comment at: lib/CodeGen/CGOpenCLRuntime.cpp:113
+
+llvm::Value *CGOpenCLRuntime::emitOpenCLEnqueuedBlock(CodeGenFunction ,
+  const Expr *E) {

yaxunl wrote:
> Anastasia wrote:
> > I am not particularly in favour of duplicating CodeGen functionality as it 
> > typically has so many special cases that are hard to catch. Is this logic 
> > needed in order to pass to block literal information  that the block is 
> > enqueued?
> This code is needed to emit separate functions for a block which is directly 
> called and also enqueued as a kernel. Since the kernel needs to have proper 
> calling convention and ABI, it cannot be emitted as the same function as when 
> the block is called directly. Since it is OpenCL specific code, I found it is 
> cleaner to separate this code as member of CGOpenCLRuntime instead of fitting 
> it into CGF.EmitBlockLiteral.
This part is replacing standard `EmitScalarExpr` call which is doing several 
things before calling into block generation. That's why I am a bit worried we 
are covering all the corner cases here.

So if we transform all blocks into kernels unconditionally we won't need this 
special handling then?

Do we generate two versions of the blocks now: one for enqueue and one for call?



Comment at: lib/CodeGen/CodeGenFunction.cpp:535
+if (i == 0 && IsBlock) {
+  ty = CGF.CGM.getTargetCodeGenInfo().getEnqueuedBlockArgumentType(
+  ASTCtx, *CGF.BlockInfo);

yaxunl wrote:
> Anastasia wrote:
> > I don't quite understand why we need to special case this? As far as I 
> > undertsnad block argument is a `generic void* ` type but it's being cast to 
> > a concrete block struct inside the block function. Do we gain anything from 
> > having it a specific type here?
> This argument is not part of BlockDecl. BlockDecl only has arguments shown up 
> in the source code. The first argument in the LLVM block invoke function is 
> generated by codegen and there is no correspondence in AST, so it has to be 
> handled as a special case.
Considering that enqueued kernel always takes the same type of the arguments 
(`local void*`) and # of args is specified in `enqueue_kernel`, I was wondering 
whether we need to generate the information on the kernel parameters at all? 
The enqueueing side will have the information provided in the `enqueue_kernel` 
code.

As for the block itself it can be passed as `generic void*` and then cast to 
the block struct type inside the block itself.



Comment at: lib/CodeGen/CodeGenFunction.cpp:667
   llvm::MDNode::get(Context, argTypeQuals));
-  if (CGM.getCodeGenOpts().EmitOpenCLArgMetadata)
+  if (CGF.CGM.getCodeGenOpts().EmitOpenCLArgMetadata)
 Fn->setMetadata("kernel_arg_name",

Why this change?



Comment at: test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl:3
+
+// CHECK: %[[S1:struct.__amdgpu_block_arg_t.*]] = type { [3 x i64], [1 x i8] }
+// CHECK: %[[S2:struct.__amdgpu_block_arg_t.*]] = type { [5 x i64], [1 x i8] }

This struct is not identical to block literal struct?


https://reviews.llvm.org/D38134



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


[PATCH] D38171: Implement clang-tidy check aliases.

2017-09-22 Thread AndrĂ¡s Leitereg via Phabricator via cfe-commits
leanil created this revision.
Herald added a subscriber: JDevlieghere.

Clang warnings can be mapped to virtual check names as aliases. The mappings 
can be set in the appropriate ClangTidyModules. If the virtual check is 
enabled, then

- the corresponding warning options get passed to clang, and
- the warning names are replaced with the check alias in the produced messages.

This is an implementation of the proposal here 
.


https://reviews.llvm.org/D38171

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tidy/ClangTidyModule.h
  clang-tidy/cert/CERTTidyModule.cpp
  test/clang-tidy/warning-check-aliases.cpp

Index: test/clang-tidy/warning-check-aliases.cpp
===
--- /dev/null
+++ test/clang-tidy/warning-check-aliases.cpp
@@ -0,0 +1,20 @@
+// RUN: clang-tidy %s -- 2>&1 | FileCheck -implicit-check-not='{{warning:|error:}}' %s
+// RUN: clang-tidy %s -checks='-*,cert-err54-cpp' -- 2>&1 | FileCheck -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK2 %s
+
+class B {};
+class D : public B {};
+
+void f() {
+  try {
+
+  } catch (B ) {
+
+  } catch (D ) {
+  }
+}
+
+//CHECK: :12:12: warning: exception of type 'D &' will be caught by earlier handler [clang-diagnostic-exceptions]
+//CHECK: :10:12: note: for type 'B &'
+
+//CHECK2: :12:12: warning: exception of type 'D &' will be caught by earlier handler [cert-err54-cpp]
+//CHECK2: :10:12: note: for type 'B &'
Index: clang-tidy/cert/CERTTidyModule.cpp
===
--- clang-tidy/cert/CERTTidyModule.cpp
+++ clang-tidy/cert/CERTTidyModule.cpp
@@ -26,6 +26,7 @@
 #include "StrToNumCheck.h"
 #include "ThrownExceptionTypeCheck.h"
 #include "VariadicFunctionDefCheck.h"
+#include "clang/Sema/SemaDiagnostic.h"
 
 namespace clang {
 namespace tidy {
@@ -73,6 +74,14 @@
 // MSC
 CheckFactories.registerCheck("cert-msc30-c");
   }
+
+  void addWarningCheckAliases(
+  llvm::DenseMap ) {
+WarningCheckAliases.insert(
+{diag::warn_exception_caught_by_earlier_handler, "cert-err54-cpp"});
+WarningCheckAliases.insert(
+{diag::ext_offsetof_non_standardlayout_type, "cert-exp59-cpp"});
+  }
 };
 
 } // namespace cert
Index: clang-tidy/ClangTidyModule.h
===
--- clang-tidy/ClangTidyModule.h
+++ clang-tidy/ClangTidyModule.h
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULE_H
 
 #include "ClangTidy.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringRef.h"
 #include 
 #include 
@@ -89,6 +90,11 @@
   /// belonging to this module.
   virtual void addCheckFactories(ClangTidyCheckFactories ) = 0;
 
+  /// \brief Implement this function in order to register all warning-check
+  /// aliases belonging to this module.
+  virtual void addWarningCheckAliases(
+  llvm::DenseMap ) {}
+
   /// \brief Gets default options for checks defined in this module.
   virtual ClangTidyOptions getModuleOptions();
 };
Index: clang-tidy/ClangTidyDiagnosticConsumer.h
===
--- clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -17,6 +17,7 @@
 #include "clang/Tooling/Refactoring.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/Timer.h"
 
@@ -186,6 +187,8 @@
 return CurrentBuildDirectory;
   }
 
+  llvm::DenseMap WarningCheckAliases;
+
 private:
   // Calls setDiagnosticsEngine() and storeError().
   friend class ClangTidyDiagnosticConsumer;
Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -374,9 +374,15 @@
 StringRef WarningOption =
 Context.DiagEngine->getDiagnosticIDs()->getWarningOptionForDiag(
 Info.getID());
-std::string CheckName = !WarningOption.empty()
-? ("clang-diagnostic-" + WarningOption).str()
-: Context.getCheckName(Info.getID()).str();
+auto Alias = Context.WarningCheckAliases.find(Info.getID());
+std::string CheckName;
+if (Alias != Context.WarningCheckAliases.end() &&
+Context.isCheckEnabled(Alias->second))
+  CheckName = Alias->second;
+else
+  CheckName = !WarningOption.empty()
+  ? ("clang-diagnostic-" + WarningOption).str()
+  : Context.getCheckName(Info.getID()).str();
 
 if (CheckName.empty()) {
   // This is a compiler 

r313973 - [analyzer] Add new delete with non-virtual destructor check

2017-09-22 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Sep 22 03:16:33 2017
New Revision: 313973

URL: http://llvm.org/viewvc/llvm-project?rev=313973=rev
Log:
[analyzer] Add new delete with non-virtual destructor check

Patch by: Reka Nikolett Kovacs

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

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
cfe/trunk/test/Analysis/DeleteWithNonVirtualDtor.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=313973=313972=313973=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Fri Sep 22 
03:16:33 2017
@@ -284,6 +284,11 @@ def VirtualCallChecker : Checker<"Virtua
 
 let ParentPackage = CplusplusAlpha in {
 
+def DeleteWithNonVirtualDtorChecker : Checker<"DeleteWithNonVirtualDtor">,
+  HelpText<"Reports destructions of polymorphic objects with a non-virtual "
+   "destructor in their base class">,
+  DescFile<"DeleteWithNonVirtualDtorChecker.cpp">;
+
 def IteratorRangeChecker : Checker<"IteratorRange">,
   HelpText<"Check for iterators used outside their valid ranges">,
   DescFile<"IteratorChecker.cpp">;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=313973=313972=313973=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Fri Sep 22 03:16:33 
2017
@@ -29,6 +29,7 @@ add_clang_library(clangStaticAnalyzerChe
   CXXSelfAssignmentChecker.cpp
   DeadStoresChecker.cpp
   DebugCheckers.cpp
+  DeleteWithNonVirtualDtorChecker.cpp
   DereferenceChecker.cpp
   DirectIvarAssignment.cpp
   DivZeroChecker.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp?rev=313973=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp 
(added)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp 
Fri Sep 22 03:16:33 2017
@@ -0,0 +1,153 @@
+//===-- DeleteWithNonVirtualDtorChecker.cpp ---*- C++ 
-*--//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines a checker for the OOP52-CPP CERT rule: Do not delete a polymorphic
+// object without a virtual destructor.
+//
+// Diagnostic flags -Wnon-virtual-dtor and -Wdelete-non-virtual-dtor report if
+// an object with a virtual function but a non-virtual destructor exists or is
+// deleted, respectively.
+//
+// This check exceeds them by comparing the dynamic and static types of the
+// object at the point of destruction and only warns if it happens through a
+// pointer to a base type without a virtual destructor. The check places a note
+// at the last point where the conversion from derived to base happened.
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class DeleteWithNonVirtualDtorChecker
+: public Checker {
+  mutable std::unique_ptr BT;
+
+  class DeleteBugVisitor : public BugReporterVisitorImpl {
+  public:
+DeleteBugVisitor() : Satisfied(false) {}
+void Profile(llvm::FoldingSetNodeID ) const override {
+  static int X = 0;
+  ID.AddPointer();
+}
+std::shared_ptr VisitNode(const ExplodedNode *N,
+   const ExplodedNode *PrevN,
+   BugReporterContext ,
+   BugReport ) override;
+
+  private:
+

[PATCH] D35796: [analyzer] Delete with non-virtual destructor check

2017-09-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313973: [analyzer] Add new delete with non-virtual 
destructor check (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D35796?vs=116060=116319#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35796

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
  cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
  cfe/trunk/test/Analysis/DeleteWithNonVirtualDtor.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
@@ -0,0 +1,153 @@
+//===-- DeleteWithNonVirtualDtorChecker.cpp ---*- C++ -*--//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines a checker for the OOP52-CPP CERT rule: Do not delete a polymorphic
+// object without a virtual destructor.
+//
+// Diagnostic flags -Wnon-virtual-dtor and -Wdelete-non-virtual-dtor report if
+// an object with a virtual function but a non-virtual destructor exists or is
+// deleted, respectively.
+//
+// This check exceeds them by comparing the dynamic and static types of the
+// object at the point of destruction and only warns if it happens through a
+// pointer to a base type without a virtual destructor. The check places a note
+// at the last point where the conversion from derived to base happened.
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class DeleteWithNonVirtualDtorChecker
+: public Checker {
+  mutable std::unique_ptr BT;
+
+  class DeleteBugVisitor : public BugReporterVisitorImpl {
+  public:
+DeleteBugVisitor() : Satisfied(false) {}
+void Profile(llvm::FoldingSetNodeID ) const override {
+  static int X = 0;
+  ID.AddPointer();
+}
+std::shared_ptr VisitNode(const ExplodedNode *N,
+   const ExplodedNode *PrevN,
+   BugReporterContext ,
+   BugReport ) override;
+
+  private:
+bool Satisfied;
+  };
+
+public:
+  void checkPreStmt(const CXXDeleteExpr *DE, CheckerContext ) const;
+};
+} // end anonymous namespace
+
+void DeleteWithNonVirtualDtorChecker::checkPreStmt(const CXXDeleteExpr *DE,
+   CheckerContext ) const {
+  const Expr *DeletedObj = DE->getArgument();
+  const MemRegion *MR = C.getSVal(DeletedObj).getAsRegion();
+  if (!MR)
+return;
+
+  const auto *BaseClassRegion = MR->getAs();
+  const auto *DerivedClassRegion = MR->getBaseRegion()->getAs();
+  if (!BaseClassRegion || !DerivedClassRegion)
+return;
+
+  const auto *BaseClass = BaseClassRegion->getValueType()->getAsCXXRecordDecl();
+  const auto *DerivedClass =
+  DerivedClassRegion->getSymbol()->getType()->getPointeeCXXRecordDecl();
+  if (!BaseClass || !DerivedClass)
+return;
+
+  if (!BaseClass->hasDefinition() || !DerivedClass->hasDefinition())
+return;
+
+  if (BaseClass->getDestructor()->isVirtual())
+return;
+
+  if (!DerivedClass->isDerivedFrom(BaseClass))
+return;
+
+  if (!BT)
+BT.reset(new BugType(this,
+ "Destruction of a polymorphic object with no "
+ "virtual destructor",
+ "Logic error"));
+
+  ExplodedNode *N = C.generateNonFatalErrorNode();
+  auto R = llvm::make_unique(*BT, BT->getName(), N);
+
+  // Mark region of problematic base class for later use in the BugVisitor.
+  R->markInteresting(BaseClassRegion);
+  R->addVisitor(llvm::make_unique());
+  C.emitReport(std::move(R));
+}
+
+std::shared_ptr
+DeleteWithNonVirtualDtorChecker::DeleteBugVisitor::VisitNode(
+const ExplodedNode *N, const ExplodedNode *PrevN, BugReporterContext ,
+BugReport ) {
+  // Stop traversal after the first conversion was 

[PATCH] D38168: [mips] Accept but ignore -m(no-)branch-likely

2017-09-22 Thread Simon Atanasyan via Phabricator via cfe-commits
atanasyan accepted this revision.
atanasyan added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D38168



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


[PATCH] D38168: [mips] Accept but ignore -m(no-)branch-likely

2017-09-22 Thread Simon Dardis via Phabricator via cfe-commits
sdardis created this revision.
Herald added a subscriber: arichardson.

-mbranch-likely and -mno-branch-likely are used in some build systems for
some MIPS targets. Accept these options but ignore them as they are an
(de)optimiztion hint, and that branch likely instructions were deprecated
but not removed from MIPS32 and MIPS64 ISAs.


https://reviews.llvm.org/D38168

Files:
  include/clang/Driver/Options.td
  test/Driver/mips-features.c


Index: test/Driver/mips-features.c
===
--- test/Driver/mips-features.c
+++ test/Driver/mips-features.c
@@ -392,3 +392,13 @@
 // LONG-CALLS-ON: "-target-feature" "+long-calls"
 // LONG-CALLS-OFF: "-target-feature" "-long-calls"
 // LONG-CALLS-DEF-NOT: "long-calls"
+//
+// -mbranch-likely
+// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN:   | FileCheck --check-prefix=BRANCH-LIKELY %s
+// BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
+//
+// -mno-branch-likely
+// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN:   | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
+// NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -2047,6 +2047,10 @@
 def mno_check_zero_division : Flag<["-"], "mno-check-zero-division">,
   Group;
 def mcompact_branches_EQ : Joined<["-"], "mcompact-branches=">, Group;
+def mbranch_likely : Flag<["-"], "mbranch-likely">, Group,
+  IgnoredGCCCompat;
+def mno_branch_likely : Flag<["-"], "mno-branch-likely">, Group,
+  IgnoredGCCCompat;
 def mdsp : Flag<["-"], "mdsp">, Group;
 def mno_dsp : Flag<["-"], "mno-dsp">, Group;
 def mdspr2 : Flag<["-"], "mdspr2">, Group;


Index: test/Driver/mips-features.c
===
--- test/Driver/mips-features.c
+++ test/Driver/mips-features.c
@@ -392,3 +392,13 @@
 // LONG-CALLS-ON: "-target-feature" "+long-calls"
 // LONG-CALLS-OFF: "-target-feature" "-long-calls"
 // LONG-CALLS-DEF-NOT: "long-calls"
+//
+// -mbranch-likely
+// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN:   | FileCheck --check-prefix=BRANCH-LIKELY %s
+// BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
+//
+// -mno-branch-likely
+// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN:   | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
+// NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -2047,6 +2047,10 @@
 def mno_check_zero_division : Flag<["-"], "mno-check-zero-division">,
   Group;
 def mcompact_branches_EQ : Joined<["-"], "mcompact-branches=">, Group;
+def mbranch_likely : Flag<["-"], "mbranch-likely">, Group,
+  IgnoredGCCCompat;
+def mno_branch_likely : Flag<["-"], "mno-branch-likely">, Group,
+  IgnoredGCCCompat;
 def mdsp : Flag<["-"], "mdsp">, Group;
 def mno_dsp : Flag<["-"], "mno-dsp">, Group;
 def mdspr2 : Flag<["-"], "mdspr2">, Group;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38126: Make TBAA information to be part of LValueBaseInfo

2017-09-22 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Sure, will do. Just added it to https://reviews.llvm.org/D38074. Thanks.


https://reviews.llvm.org/D38126



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


[PATCH] D35796: [analyzer] Delete with non-virtual destructor check

2017-09-22 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs added a comment.

In https://reviews.llvm.org/D35796#878200, @dcoughlin wrote:

> This looks good to me! Do you have commit access, or do you need someone to 
> commit it for you?


Thanks! I don't, so it would be nice if someone committed it for me.


https://reviews.llvm.org/D35796



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