[PATCH] D70746: [clangd] Highlighting dependent types in more contexts

2019-11-30 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 231609.
nridge added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70746/new/

https://reviews.llvm.org/D70746

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -630,7 +630,24 @@
   R"cpp(
   template 
   struct $Class[[TupleSize]] {
-static const int $StaticField[[size]] = 
sizeof...($TemplateParameter[[Elements]]);
+static const int $StaticField[[size]] =
+sizeof...($TemplateParameter[[Elements]]);
+  };
+)cpp",
+  // More dependent types
+  R"cpp(
+  template 
+  struct $Class[[Waldo]] {
+using $Typedef[[Location1]] = typename $TemplateParameter[[T]]
+::$DependentType[[Resolver]]::$DependentType[[Location]];
+using $Typedef[[Location2]] = typename $TemplateParameter[[T]]
+::template $DependentType[[Resolver]]<$TemplateParameter[[T]]>
+::$DependentType[[Location]];
+using $Typedef[[Location3]] = typename $TemplateParameter[[T]]
+::$DependentType[[Resolver]]
+::template $DependentType[[Location]]<$TemplateParameter[[T]]>;
+static const int $StaticField[[Value]] = $TemplateParameter[[T]]
+::$DependentType[[Resolver]]::$DependentName[[Value]];
   };
 )cpp"};
   for (const auto  : TestCases) {
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -258,6 +258,26 @@
 return true;
   }
 
+  bool VisitDependentTemplateSpecializationTypeLoc(
+  DependentTemplateSpecializationTypeLoc L) {
+H.addToken(L.getTemplateNameLoc(), HighlightingKind::DependentType);
+return true;
+  }
+
+  // findExplicitReferences will walk nested-name-specifiers and
+  // find anything that can be resolved to a Decl. However, non-leaf
+  // components of nested-name-specifiers which are dependent names
+  // (kind "Identifier") cannot be resolved to a decl, so we visit
+  // them here.
+  bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc Q) {
+if (NestedNameSpecifier *NNS = Q.getNestedNameSpecifier()) {
+  if (NNS->getKind() == NestedNameSpecifier::Identifier) {
+H.addToken(Q.getLocalBeginLoc(), HighlightingKind::DependentType);
+  }
+}
+return RecursiveASTVisitor::TraverseNestedNameSpecifierLoc(Q);
+  }
+
 private:
   HighlightingsBuilder 
 };


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -630,7 +630,24 @@
   R"cpp(
   template 
   struct $Class[[TupleSize]] {
-static const int $StaticField[[size]] = sizeof...($TemplateParameter[[Elements]]);
+static const int $StaticField[[size]] =
+sizeof...($TemplateParameter[[Elements]]);
+  };
+)cpp",
+  // More dependent types
+  R"cpp(
+  template 
+  struct $Class[[Waldo]] {
+using $Typedef[[Location1]] = typename $TemplateParameter[[T]]
+::$DependentType[[Resolver]]::$DependentType[[Location]];
+using $Typedef[[Location2]] = typename $TemplateParameter[[T]]
+::template $DependentType[[Resolver]]<$TemplateParameter[[T]]>
+::$DependentType[[Location]];
+using $Typedef[[Location3]] = typename $TemplateParameter[[T]]
+::$DependentType[[Resolver]]
+::template $DependentType[[Location]]<$TemplateParameter[[T]]>;
+static const int $StaticField[[Value]] = $TemplateParameter[[T]]
+::$DependentType[[Resolver]]::$DependentName[[Value]];
   };
 )cpp"};
   for (const auto  : TestCases) {
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -258,6 +258,26 @@
 return true;
   }
 
+  bool VisitDependentTemplateSpecializationTypeLoc(
+  DependentTemplateSpecializationTypeLoc L) {
+H.addToken(L.getTemplateNameLoc(), HighlightingKind::DependentType);
+return true;
+  }
+
+  // findExplicitReferences will walk nested-name-specifiers and
+  // find anything that can be resolved to a Decl. However, non-leaf
+  // components of nested-name-specifiers which are 

[PATCH] D70727: [clangd] Keep go-to-definition working at the end of an identifier (fixes #194)

2019-11-30 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D70727#1763781 , @hokein wrote:

> In D70727#1760485 , @nridge wrote:
>
> > By the way, may I get permissions to assign issues to myself (and make 
> > other such metadata changes to issues) on github?
>
>
> sure, we just sent you an invitation to the clangd org.


Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70727/new/

https://reviews.llvm.org/D70727



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


[PATCH] D70727: [clangd] Keep go-to-definition working at the end of an identifier (fixes #194)

2019-11-30 Thread Nathan Ridge via Phabricator via cfe-commits
nridge abandoned this revision.
nridge marked an inline comment as done.
nridge added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:153
+  // allowing go-to-definition to work at the end of an identifier.
+  if (Result.empty() && Offset > 0) {
+Result = getDeclAtOffset(AST, Offset - 1, Relations);

hokein wrote:
> this looks a hacky workaround, I assume it may introduce other regression 
> issues. 
> 
> I think https://reviews.llvm.org/D70773 and https://reviews.llvm.org/D70807 
> should fix most annoying cases (function call). 
Fair enough! Will abandon this patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70727/new/

https://reviews.llvm.org/D70727



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


[PATCH] D70740: [clangd] Find reference to template parameter in 'sizeof...' expression

2019-11-30 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 231608.
nridge added a comment.

Address review comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70740/new/

https://reviews.llvm.org/D70740

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -625,6 +625,13 @@
 $InactiveCode[[]]  #else
   int $Variable[[Active2]];
   #endif
+)cpp",
+  // Argument to 'sizeof...'
+  R"cpp(
+  template 
+  struct $Class[[TupleSize]] {
+static const int $StaticField[[size]] = 
sizeof...($TemplateParameter[[Elements]]);
+  };
 )cpp"};
   for (const auto  : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -260,6 +260,15 @@
   )cpp";
   // FIXME: deduced type missing in AST. https://llvm.org/PR42914
   EXPECT_DECLS("AutoTypeLoc");
+
+  Code = R"cpp(
+template 
+struct S {
+  static const int size = sizeof...([[E]]);
+};
+  )cpp";
+  // FIXME: We don't do a good job printing TemplateTypeParmDecls, apparently!
+  EXPECT_DECLS("SizeOfPackExpr", "");
 }
 
 TEST_F(TargetDeclTest, ClassTemplate) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -194,6 +194,9 @@
 for (auto *D : OE->decls())
   Outer.add(D, Flags);
   }
+  void VisitSizeOfPackExpr(const SizeOfPackExpr *SE) {
+Outer.add(SE->getPack(), Flags);
+  }
   void VisitCXXConstructExpr(const CXXConstructExpr *CCE) {
 Outer.add(CCE->getConstructor(), Flags);
   }
@@ -491,6 +494,13 @@
   llvm::SmallVector(
   E->decls().begin(), E->decls().end())});
 }
+
+void VisitSizeOfPackExpr(const SizeOfPackExpr *E) {
+  Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
+  E->getPackLoc(),
+  /*IsDecl=*/false,
+  {E->getPack()}});
+}
   };
 
   Visitor V;


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -625,6 +625,13 @@
 $InactiveCode[[]]  #else
   int $Variable[[Active2]];
   #endif
+)cpp",
+  // Argument to 'sizeof...'
+  R"cpp(
+  template 
+  struct $Class[[TupleSize]] {
+static const int $StaticField[[size]] = sizeof...($TemplateParameter[[Elements]]);
+  };
 )cpp"};
   for (const auto  : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -260,6 +260,15 @@
   )cpp";
   // FIXME: deduced type missing in AST. https://llvm.org/PR42914
   EXPECT_DECLS("AutoTypeLoc");
+
+  Code = R"cpp(
+template 
+struct S {
+  static const int size = sizeof...([[E]]);
+};
+  )cpp";
+  // FIXME: We don't do a good job printing TemplateTypeParmDecls, apparently!
+  EXPECT_DECLS("SizeOfPackExpr", "");
 }
 
 TEST_F(TargetDeclTest, ClassTemplate) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -194,6 +194,9 @@
 for (auto *D : OE->decls())
   Outer.add(D, Flags);
   }
+  void VisitSizeOfPackExpr(const SizeOfPackExpr *SE) {
+Outer.add(SE->getPack(), Flags);
+  }
   void VisitCXXConstructExpr(const CXXConstructExpr *CCE) {
 Outer.add(CCE->getConstructor(), Flags);
   }
@@ -491,6 +494,13 @@
   llvm::SmallVector(
   E->decls().begin(), E->decls().end())});
 }
+
+void VisitSizeOfPackExpr(const SizeOfPackExpr *E) {
+  Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
+  E->getPackLoc(),
+  

[PATCH] D70868: [libunwind] Emit dependent libraries only when detected by CMake

2019-11-30 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM, thanks! Would it be possible to make the same change to libc++abi and 
libc++ as well (since they also use dependent library feature)?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70868/new/

https://reviews.llvm.org/D70868



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


[PATCH] D63276: [AST] Add FunctionDecl::getParametersSourceRange()

2019-11-30 Thread Nicolas Manichon via Phabricator via cfe-commits
nicolas updated this revision to Diff 231604.
nicolas added a comment.

Hi @mordante, thanks for the interest.
Here's an updated patch that addresses @aaron.ballman's comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63276/new/

https://reviews.llvm.org/D63276

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaType.cpp
  clang/unittests/AST/SourceLocationTest.cpp

Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -648,6 +648,112 @@
   Language::Lang_CXX11));
 }
 
+class FunctionDeclParametersRangeVerifier : public RangeVerifier {
+protected:
+  SourceRange getRange(const FunctionDecl ) override {
+return Function.getParametersSourceRange();
+  }
+};
+
+TEST(FunctionDeclParameters, FunctionDeclOnlyVariadic) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 8);
+  EXPECT_TRUE(Verifier.match("void f(...);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclVariadic) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 15);
+  EXPECT_TRUE(Verifier.match("void f(int a, ...);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclMacroVariadic) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(2, 8, 1, 18);
+  EXPECT_TRUE(Verifier.match("#define VARIADIC ...\n"
+ "void f(int a, VARIADIC);\n",
+ functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclMacroParams) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 16, 2, 20);
+  EXPECT_TRUE(Verifier.match("#define PARAMS int a, int b\n"
+ "void f(PARAMS, int c);",
+ functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclSingleParameter) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 12);
+  EXPECT_TRUE(Verifier.match("void f(int a);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, MemberFunctionDecl) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(2, 8, 2, 12);
+  EXPECT_TRUE(Verifier.match("class A{\n"
+ "void f(int a);\n"
+ "};",
+ functionDecl()));
+}
+
+TEST(FunctionDeclParameters, MemberFunctionDeclVariadic) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(2, 8, 2, 15);
+  EXPECT_TRUE(Verifier.match("class A{\n"
+ "void f(int a, ...);\n"
+ "};",
+ functionDecl()));
+}
+
+TEST(FunctionDeclParameters, StaticFunctionDecl) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(2, 15, 2, 19);
+  EXPECT_TRUE(Verifier.match("class A{\n"
+ "static void f(int a);\n"
+ "};",
+ functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclMultipleParameters) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 28);
+  EXPECT_TRUE(
+  Verifier.match("void f(int a, int b, char *c);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithDefaultValue) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 16);
+  EXPECT_TRUE(Verifier.match("void f(int a = 5);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithVolatile) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 22);
+  EXPECT_TRUE(Verifier.match("void f(volatile int *i);", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithConstParam) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 19);
+  EXPECT_TRUE(Verifier.match("void f(const int *i);", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithConstVolatileParam) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 28);
+  EXPECT_TRUE(Verifier.match("void f(const volatile int *i);", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithParamAttribute) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 36);
+  EXPECT_TRUE(Verifier.match("void f(__attribute__((unused)) int a) {}",
+ functionDecl()));
+}
+
 TEST(CXXMethodDecl, CXXMethodDeclWithThrowSpecification) {
   RangeVerifier Verifier;
   Verifier.expectRange(2, 1, 2, 16);
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4810,6 +4810,7 @@

[PATCH] D66035: [WebAssembly] WIP: Add support for reference types

2019-11-30 Thread Valentin Churavy via Phabricator via cfe-commits
vchuravy updated this revision to Diff 231601.
vchuravy added a comment.

- fix AS in anyref testfile


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66035/new/

https://reviews.llvm.org/D66035

Files:
  clang/lib/Basic/Targets/WebAssembly.h
  lld/wasm/WriterUtils.cpp
  llvm/include/llvm/BinaryFormat/Wasm.h
  llvm/include/llvm/BinaryFormat/WasmRelocs.def
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/include/llvm/CodeGen/ValueTypes.td
  llvm/include/llvm/MC/MCExpr.h
  llvm/include/llvm/MC/MCSymbolWasm.h
  llvm/include/llvm/Object/Wasm.h
  llvm/include/llvm/Support/MachineValueType.h
  llvm/lib/BinaryFormat/Wasm.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/MC/MCExpr.cpp
  llvm/lib/MC/WasmObjectWriter.cpp
  llvm/lib/Object/WasmObjectFile.cpp
  llvm/lib/ObjectYAML/WasmEmitter.cpp
  llvm/lib/ObjectYAML/WasmYAML.cpp
  llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
  llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
  llvm/lib/Target/WebAssembly/WebAssembly.h
  llvm/lib/Target/WebAssembly/WebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
  llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyRegisterInfo.td
  llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/test/CodeGen/WebAssembly/anyref.ll
  llvm/test/CodeGen/WebAssembly/reg-argument.mir
  llvm/test/CodeGen/WebAssembly/reg-copy.mir
  llvm/utils/TableGen/CodeGenTarget.cpp

Index: llvm/utils/TableGen/CodeGenTarget.cpp
===
--- llvm/utils/TableGen/CodeGenTarget.cpp
+++ llvm/utils/TableGen/CodeGenTarget.cpp
@@ -196,6 +196,7 @@
   case MVT::iPTRAny:  return "MVT::iPTRAny";
   case MVT::Untyped:  return "MVT::Untyped";
   case MVT::exnref:   return "MVT::exnref";
+  case MVT::anyref:   return "MVT::anyref";
   default: llvm_unreachable("ILLEGAL VALUE TYPE!");
   }
 }
Index: llvm/test/CodeGen/WebAssembly/reg-copy.mir
===
--- llvm/test/CodeGen/WebAssembly/reg-copy.mir
+++ llvm/test/CodeGen/WebAssembly/reg-copy.mir
@@ -66,3 +66,14 @@
 %0:exnref = COPY %1:exnref
 RETURN implicit-def $arguments
 ...
+---
+name: copy_anyref
+# CHECK-LABEL: copy_anyref
+body: |
+  ; CHECK-LABEL: bb.0
+  ; CHECK-NEXT: %0:anyref = COPY_ANYREF %1:anyref
+  ; CHECK-NEXT: RETURN
+  bb.0:
+%0:anyref = COPY %1:anyref
+RETURN implicit-def $arguments
+...
Index: llvm/test/CodeGen/WebAssembly/reg-argument.mir
===
--- llvm/test/CodeGen/WebAssembly/reg-argument.mir
+++ llvm/test/CodeGen/WebAssembly/reg-argument.mir
@@ -57,3 +57,14 @@
 %1:exnref = ARGUMENT_exnref 0, implicit $arguments
 RETURN implicit-def $arguments
 ...
+---
+name: argument_anyref
+# CHECK-LABEL: argument_anyref
+body: |
+  ; CHECK-LABEL: bb.0:
+  ; CHECK-NEXT: %1:anyref = ARGUMENT_anyref 0
+  bb.0:
+%0:i32 = CONST_I32 0, implicit-def $arguments
+%1:anyref = ARGUMENT_anyref 0, implicit $arguments
+RETURN implicit-def $arguments
+...
Index: llvm/test/CodeGen/WebAssembly/anyref.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/anyref.ll
@@ -0,0 +1,29 @@
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+reference-types | FileCheck %s
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:256"
+target triple = "wasm32-unknown-unknown"
+
+declare i8 addrspace(256)* @test(i8 addrspace(256)*) 
+
+
+; CHECK-LABEL: call_test:
+; CHECK: .functype   call_test (anyref) -> (anyref)
+define i8 addrspace(256)* @call_test(i8 addrspace(256)*) {
+; CHECK: anyref.call $push0=, test, $0
+  %a = call i8 addrspace(256)* @test(i8 addrspace(256)* %0) 
+  ret i8 addrspace(256)* %a
+}
+
+; TODO: nullref?
+; define i8 

[PATCH] D70872: [clangd] Implement "textDocument/documentLink" protocol support

2019-11-30 Thread Michael Forster via Phabricator via cfe-commits
MForster marked an inline comment as done.
MForster added inline comments.



Comment at: clang-tools-extra/clangd/test/document-link.test:21
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "target": "file://{{.*}}/iostream"
+# CHECK-NEXT:},

Originally I tried to add a header file to the setup with a second didOpen 
request, but I didn't get this to work. Would I need to set this up like 
`background-index.test`, or is there a simpler way?

Anyway, I think the regular expression is probably good enough for the purpose 
of this test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70872/new/

https://reviews.llvm.org/D70872



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


[PATCH] D70872: Advertise documentLink capability

2019-11-30 Thread Michael Forster via Phabricator via cfe-commits
MForster created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.

Add "textDocument/documentLink" protocol support

Implement "textDocument/documentLink"


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70872

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/test/document-link.test
  clang-tools-extra/clangd/test/initialize-params.test

Index: clang-tools-extra/clangd/test/initialize-params.test
===
--- clang-tools-extra/clangd/test/initialize-params.test
+++ clang-tools-extra/clangd/test/initialize-params.test
@@ -18,6 +18,9 @@
 # CHECK-NEXT:  "definitionProvider": true,
 # CHECK-NEXT:  "documentFormattingProvider": true,
 # CHECK-NEXT:  "documentHighlightProvider": true,
+# CHECK-NEXT:  "documentLinkProvider": {
+# CHECK-NEXT:"resolveProvider": false
+# CHECK-NEXT:  }
 # CHECK-NEXT:  "documentOnTypeFormattingProvider": {
 # CHECK-NEXT:"firstTriggerCharacter": "\n",
 # CHECK-NEXT:"moreTriggerCharacter": []
Index: clang-tools-extra/clangd/test/document-link.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/document-link.test
@@ -0,0 +1,42 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"#include \n#include "}}}
+---
+{"jsonrpc":"2.0","id":2,"method":"textDocument/documentLink","params":{"textDocument":{"uri":"test:///main.cpp"}}}
+#  CHECK:  "id": 2,
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 19,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 9,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "target": "file://{{.*}}/iostream"
+# CHECK-NEXT:},
+# CHECK-NEXT:{
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 17,
+# CHECK-NEXT:  "line": 1
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 9,
+# CHECK-NEXT:  "line": 1
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "target": "file://{{.*}}/string"
+# CHECK-NEXT:}
+# CHECK-NEXT:  ]
+# CHECK-NEXT:}
+
+---
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -49,6 +49,9 @@
 std::vector locateSymbolAt(ParsedAST , Position Pos,
   const SymbolIndex *Index = nullptr);
 
+/// Get all document links
+std::vector getDocumentLinks(ParsedAST );
+
 /// Returns highlights for all usages of a symbol at \p Pos.
 std::vector findDocumentHighlights(ParsedAST ,
   Position Pos);
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -166,6 +166,26 @@
 
 } // namespace
 
+std::vector getDocumentLinks(ParsedAST ) {
+  const auto  = AST.getSourceManager();
+  auto MainFilePath =
+  getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
+  if (!MainFilePath) {
+elog("Failed to get a path for the main file, so no links");
+return {};
+  }
+
+  std::vector Result;
+  for (auto  : AST.getIncludeStructure().MainFileIncludes) {
+if (!Inc.Resolved.empty()) {
+  Result.emplace_back(DocumentLink(
+  {Inc.R, URIForFile::canonicalize(Inc.Resolved, *MainFilePath)}));
+}
+  }
+
+  return Result;
+}
+
 std::vector locateSymbolAt(ParsedAST , Position Pos,
   const SymbolIndex *Index) {
   const auto  = AST.getSourceManager();
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -1250,6 +1250,33 @@
 };
 llvm::json::Value toJSON(const SelectionRange &);
 
+/// 

[PATCH] D69180: [Format] Add format check for coroutine keywords with negative numbers

2019-11-30 Thread Brian Gesiak via Phabricator via cfe-commits
modocache added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:1761
+   tok::kw_case, tok::at, tok::l_brace, tok::kw_throw,
+   tok::kw_co_return, tok_kw_co_yield))
   return TT_UnaryOperator;

I didn't notice this during review, but `tok_kw_co_yield` is a typo. I'm 
replacing this with `tok::kw_co_yield` in the commit I'm making for this patch, 
as that spelling allows the build and tests to pass.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69180/new/

https://reviews.llvm.org/D69180



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


[PATCH] D69180: [Format] Add format check for coroutine keywords with negative numbers

2019-11-30 Thread Brian Gesiak via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8682d29a2877: [Format] Add format check for coroutine 
keywords with negative numbers (authored by modocache).

Changed prior to commit:
  https://reviews.llvm.org/D69180?vs=225672=231596#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69180/new/

https://reviews.llvm.org/D69180

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6990,6 +6990,9 @@
   verifyFormat("int a = /* confusing comment */ -1;");
   // FIXME: The space after 'i' is wrong, but hopefully, this is a rare case.
   verifyFormat("int a = i /* confusing comment */++;");
+
+  verifyFormat("co_yield -1;");
+  verifyFormat("co_return -1;");
 }
 
 TEST_F(FormatTest, DoesNotIndentRelativeToUnaryOperators) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1829,7 +1829,8 @@
 // Use heuristics to recognize unary operators.
 if (PrevToken->isOneOf(tok::equal, tok::l_paren, tok::comma, tok::l_square,
tok::question, tok::colon, tok::kw_return,
-   tok::kw_case, tok::at, tok::l_brace, tok::kw_throw))
+   tok::kw_case, tok::at, tok::l_brace, tok::kw_throw,
+   tok::kw_co_return, tok::kw_co_yield))
   return TT_UnaryOperator;
 
 // There can't be two consecutive binary operators.


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6990,6 +6990,9 @@
   verifyFormat("int a = /* confusing comment */ -1;");
   // FIXME: The space after 'i' is wrong, but hopefully, this is a rare case.
   verifyFormat("int a = i /* confusing comment */++;");
+
+  verifyFormat("co_yield -1;");
+  verifyFormat("co_return -1;");
 }
 
 TEST_F(FormatTest, DoesNotIndentRelativeToUnaryOperators) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1829,7 +1829,8 @@
 // Use heuristics to recognize unary operators.
 if (PrevToken->isOneOf(tok::equal, tok::l_paren, tok::comma, tok::l_square,
tok::question, tok::colon, tok::kw_return,
-   tok::kw_case, tok::at, tok::l_brace, tok::kw_throw))
+   tok::kw_case, tok::at, tok::l_brace, tok::kw_throw,
+   tok::kw_co_return, tok::kw_co_yield))
   return TT_UnaryOperator;
 
 // There can't be two consecutive binary operators.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8682d29 - [Format] Add format check for coroutine keywords with negative numbers

2019-11-30 Thread Brian Gesiak via cfe-commits

Author: Brian Gesiak
Date: 2019-11-30T15:47:58-05:00
New Revision: 8682d29a28772bab0283a141b8701bfaea8881a6

URL: 
https://github.com/llvm/llvm-project/commit/8682d29a28772bab0283a141b8701bfaea8881a6
DIFF: 
https://github.com/llvm/llvm-project/commit/8682d29a28772bab0283a141b8701bfaea8881a6.diff

LOG: [Format] Add format check for coroutine keywords with negative numbers

Summary:
As a followup to D69144, this diff fixes the coroutine keyword spacing
for co_yield / co_returning negative numbers.

Reviewers: modocache, sammccall, Quuxplusone

Reviewed By: modocache

Subscribers: cfe-commits

Tags: #clang

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

Patch by Jonathan Thomas (jonathoma)!

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 9fe7fdc9ce93..74ff5b531496 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1829,7 +1829,8 @@ class AnnotatingParser {
 // Use heuristics to recognize unary operators.
 if (PrevToken->isOneOf(tok::equal, tok::l_paren, tok::comma, tok::l_square,
tok::question, tok::colon, tok::kw_return,
-   tok::kw_case, tok::at, tok::l_brace, tok::kw_throw))
+   tok::kw_case, tok::at, tok::l_brace, tok::kw_throw,
+   tok::kw_co_return, tok::kw_co_yield))
   return TT_UnaryOperator;
 
 // There can't be two consecutive binary operators.

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index d89ad44e4577..e6fa829e7ff9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6990,6 +6990,9 @@ TEST_F(FormatTest, UnderstandsUnaryOperators) {
   verifyFormat("int a = /* confusing comment */ -1;");
   // FIXME: The space after 'i' is wrong, but hopefully, this is a rare case.
   verifyFormat("int a = i /* confusing comment */++;");
+
+  verifyFormat("co_yield -1;");
+  verifyFormat("co_return -1;");
 }
 
 TEST_F(FormatTest, DoesNotIndentRelativeToUnaryOperators) {



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


[PATCH] D60455: [SYCL] Add sycl_kernel attribute for accelerated code outlining

2019-11-30 Thread Alexey Bader via Phabricator via cfe-commits
bader updated this revision to Diff 231595.
bader marked 4 inline comments as done.
bader added a comment.

Applied comments from @Fznamznon.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60455/new/

https://reviews.llvm.org/D60455

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaSYCL/kernel-attribute-on-non-sycl.cpp
  clang/test/SemaSYCL/kernel-attribute.cpp

Index: clang/test/SemaSYCL/kernel-attribute.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/kernel-attribute.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+
+[[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+__attribute__((sycl_kernel)) int gv3 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+
+__attribute__((sycl_kernel(1))) void foo(); // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+[[clang::sycl_kernel(1)]] void foo2(); // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+
+// Only function templates
+__attribute__((sycl_kernel)) void foo(); // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+[[clang::sycl_kernel]] void foo1(); // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+
+// At least two template parameters
+template 
+__attribute__((sycl_kernel)) void foo(T P); // expected-warning {{'sycl_kernel' attribute only applies to a function template with at least two template parameters}}
+template 
+[[clang::sycl_kernel]] void foo1(T P); // expected-warning {{'sycl_kernel' attribute only applies to a function template with at least two template parameters}}
+
+// First two template parameters cannot be non-type template parameters
+template 
+__attribute__((sycl_kernel)) void foo(T P); // expected-warning {{template parameter of a function template with the 'sycl_kernel' attribute cannot be a non-type template parameter}}
+template 
+[[clang::sycl_kernel]] void foo1(T P); // expected-warning {{template parameter of a function template with the 'sycl_kernel' attribute cannot be a non-type template parameter}}
+
+// Must return void
+template 
+__attribute__((sycl_kernel)) int foo(T P); // expected-warning {{function template with 'sycl_kernel' attribute must have a 'void' return type}}
+template 
+[[clang::sycl_kernel]] int foo1(T P); // expected-warning {{function template with 'sycl_kernel' attribute must have a 'void' return type}}
+
+// Must take at least one argument
+template 
+__attribute__((sycl_kernel)) void foo(); // expected-warning {{function template with 'sycl_kernel' attribute must have a single parameter}}
+template 
+[[clang::sycl_kernel]] void foo1(T t, A a); // expected-warning {{function template with 'sycl_kernel' attribute must have a single parameter}}
+
+// No diagnostics
+template 
+__attribute__((sycl_kernel)) void foo(T P);
+template 
+[[clang::sycl_kernel]] void foo1(T P);
Index: clang/test/SemaSYCL/kernel-attribute-on-non-sycl.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/kernel-attribute-on-non-sycl.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -x c++ %s
+
+#ifndef __SYCL_DEVICE_ONLY__
+// expected-warning@+7 {{'sycl_kernel' attribute ignored}}
+// expected-warning@+8 {{'sycl_kernel' attribute ignored}}
+#else
+// expected-no-diagnostics
+#endif
+
+template 
+__attribute__((sycl_kernel)) void foo(T P);
+template 
+[[clang::sycl_kernel]] void foo1(T P);
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6412,6 +6412,45 @@
   D->addAttr(::new (S.Context) OpenCLAccessAttr(S.Context, AL));
 }
 
+static void handleSYCLKernelAttr(Sema , Decl *D, const ParsedAttr ) {
+  // The 'sycl_kernel' attribute applies only to function templates.
+  const auto *FD = cast(D);
+  const FunctionTemplateDecl *FT = FD->getDescribedFunctionTemplate();
+  assert(FT && "Function template is expected");
+
+  // Function template must have at least two template parameters.
+  const TemplateParameterList *TL = FT->getTemplateParameters();
+  if (TL->size() < 2) {
+S.Diag(FT->getLocation(), diag::warn_sycl_kernel_num_of_template_params);
+return;
+  }
+
+  // Template parameters must be typenames.
+  for (unsigned I = 0; I < 2; ++I) {
+const NamedDecl *TParam = TL->getParam(I);
+if (isa(TParam)) {
+  S.Diag(FT->getLocation(),
+ diag::warn_sycl_kernel_invalid_template_param_type);
+  return;

[PATCH] D63276: [AST] Add FunctionDecl::getParametersSourceRange()

2019-11-30 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

I've been looking at a way to get the ellipsis location so I'd like this patch 
to move forward. @nicolas are you still working on this patch?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63276/new/

https://reviews.llvm.org/D63276



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


[PATCH] D57660: [Sema] SequenceChecker: Handle references, members and structured bindings.

2019-11-30 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

I like this improvement. However I'm not a reviewer.




Comment at: clang/lib/Sema/SemaChecking.cpp:12361
+  /// \param RefsSeenPtr is used to avoid reference cycles. When such a cycle
+  /// is possible we check first if \param RefsSeenPtr is non-null. If it is
+  /// non-null we use the pointed SmallPtrSet and if null we create one on the

Please use \p here since it's not a parameter definition.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57660/new/

https://reviews.llvm.org/D57660



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


[PATCH] D70869: [Analyzer] Use a reference in a range-based for

2019-11-30 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: dcoughlin, aaron.ballman, xbolva00, Szelethus.
Mordante added a project: clang.
Herald added subscribers: Charusso, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, szepet, baloghadamsoftware, xazax.hun.

This avoids unneeded copies when using a range-based for loops.

This avoids new warnings due to D68912  adds 
-Wrange-loop-analysis to -Wall.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70869

Files:
  clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -505,7 +505,7 @@
   // Recursively examine the base classes.
   // Note that following base classes does not increase the recursion depth.
   if (const auto *RDX = dyn_cast(RD))
-for (const auto II : RDX->bases())
+for (const auto  : RDX->bases())
   if (const RecordDecl *RRD = II.getType()->getAsRecordDecl())
 if (Optional Out =
 findRegionOfInterestInRecord(RRD, State, R, Vec, depth))
Index: clang/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -812,7 +812,7 @@
   // Keep symbolic expressions of iterator positions, container begins and ends
   // alive
   auto RegionMap = State->get();
-  for (const auto Reg : RegionMap) {
+  for (const auto  : RegionMap) {
 const auto Offset = Reg.second.getOffset();
 for (auto i = Offset->symbol_begin(); i != Offset->symbol_end(); ++i)
   if (isa(*i))
@@ -820,7 +820,7 @@
   }
 
   auto SymbolMap = State->get();
-  for (const auto Sym : SymbolMap) {
+  for (const auto  : SymbolMap) {
 const auto Offset = Sym.second.getOffset();
 for (auto i = Offset->symbol_begin(); i != Offset->symbol_end(); ++i)
   if (isa(*i))
@@ -828,7 +828,7 @@
   }
 
   auto ContMap = State->get();
-  for (const auto Cont : ContMap) {
+  for (const auto  : ContMap) {
 const auto CData = Cont.second;
 if (CData.getBegin()) {
   SR.markLive(CData.getBegin());
@@ -849,7 +849,7 @@
   auto State = C.getState();
 
   auto RegionMap = State->get();
-  for (const auto Reg : RegionMap) {
+  for (const auto  : RegionMap) {
 if (!SR.isLiveRegion(Reg.first)) {
   // The region behind the `LazyCompoundVal` is often cleaned up before
   // the `LazyCompoundVal` itself. If there are iterator positions keyed
@@ -861,14 +861,14 @@
   }
 
   auto SymbolMap = State->get();
-  for (const auto Sym : SymbolMap) {
+  for (const auto  : SymbolMap) {
 if (!SR.isLive(Sym.first)) {
   State = State->remove(Sym.first);
 }
   }
 
   auto ContMap = State->get();
-  for (const auto Cont : ContMap) {
+  for (const auto  : ContMap) {
 if (!SR.isLiveRegion(Cont.first)) {
   // We must keep the container data while it has live iterators to be able
   // to compare them to the begin and the end of the container.
@@ -2218,13 +2218,13 @@
 
 bool hasLiveIterators(ProgramStateRef State, const MemRegion *Cont) {
   auto RegionMap = State->get();
-  for (const auto Reg : RegionMap) {
+  for (const auto  : RegionMap) {
 if (Reg.second.getContainer() == Cont)
   return true;
   }
 
   auto SymbolMap = State->get();
-  for (const auto Sym : SymbolMap) {
+  for (const auto  : SymbolMap) {
 if (Sym.second.getContainer() == Cont)
   return true;
   }
@@ -2234,7 +2234,7 @@
 
 bool isBoundThroughLazyCompoundVal(const Environment ,
const MemRegion *Reg) {
-  for (const auto Binding: Env) {
+  for (const auto  : Env) {
 if (const auto LCVal = Binding.second.getAs()) {
   if (LCVal->getRegion() == Reg)
 return true;
@@ -2291,7 +2291,7 @@
   auto  = State->get_context();
   auto RegionMap = State->get();
   bool Changed = false;
-  for (const auto Reg : RegionMap) {
+  for (const auto  : RegionMap) {
 if (Cond(Reg.second)) {
   RegionMap = RegionMapFactory.add(RegionMap, Reg.first, Proc(Reg.second));
   Changed = true;
@@ -2304,7 +2304,7 @@
   auto  = State->get_context();
   auto SymbolMap = State->get();
   Changed = false;
-  for (const auto Sym : SymbolMap) {
+  for (const auto  : SymbolMap) {
 if (Cond(Sym.second)) {
   SymbolMap = SymbolMapFactory.add(SymbolMap, Sym.first, Proc(Sym.second));
   Changed = true;
Index: clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
+++ 

[PATCH] D69223: WDocumentation: Implement the \anchor.

2019-11-30 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 231592.
Mordante added a comment.

Addresses review comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69223/new/

https://reviews.llvm.org/D69223

Files:
  clang/bindings/xml/comment-xml-schema.rng
  clang/include/clang-c/Documentation.h
  clang/include/clang/AST/Comment.h
  clang/include/clang/AST/CommentCommands.td
  clang/lib/AST/CommentSema.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Index/CommentToXML.cpp
  clang/test/Index/Inputs/CommentXML/valid-inline-command-01.xml
  clang/test/Index/comment-to-html-xml-conversion.cpp
  clang/test/Index/comment-xml-schema.c
  clang/test/Sema/warn-documentation.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CXComment.cpp

Index: clang/tools/libclang/CXComment.cpp
===
--- clang/tools/libclang/CXComment.cpp
+++ clang/tools/libclang/CXComment.cpp
@@ -159,6 +159,9 @@
 
   case InlineCommandComment::RenderEmphasized:
 return CXCommentInlineCommandRenderKind_Emphasized;
+
+  case InlineCommandComment::RenderAnchor:
+return CXCommentInlineCommandRenderKind_Anchor;
   }
   llvm_unreachable("unknown InlineCommandComment::RenderKind");
 }
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -497,6 +497,9 @@
 case CXCommentInlineCommandRenderKind_Emphasized:
   printf(" RenderEmphasized");
   break;
+case CXCommentInlineCommandRenderKind_Anchor:
+  printf(" RenderAnchor");
+  break;
 }
 for (i = 0, e = clang_InlineCommandComment_getNumArgs(Comment);
  i != e; ++i) {
Index: clang/test/Sema/warn-documentation.cpp
===
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -1057,6 +1057,13 @@
 /// \a A
 int test_inline_no_argument_a_good(int);
 
+// expected-warning@+1 {{'\anchor' command does not have a valid word argument}}
+/// \anchor
+int test_inline_no_argument_anchor_bad(int);
+
+/// \anchor A
+int test_inline_no_argument_anchor_good(int);
+
 // expected-warning@+1 {{'@b' command does not have a valid word argument}}
 /// @b
 int test_inline_no_argument_b_bad(int);
Index: clang/test/Index/comment-xml-schema.c
===
--- clang/test/Index/comment-xml-schema.c
+++ clang/test/Index/comment-xml-schema.c
@@ -33,6 +33,8 @@
 // RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-enum-01.xml
 //
 // RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-para-kind-01.xml
+//
+// RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-inline-command-01.xml
 
 // RUN: not xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/invalid-function-01.xml 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID
 // RUN: not xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/invalid-function-02.xml 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -734,6 +734,16 @@
 // CHECK-NEXT: (CXComment_Text Text=[Aaa])
 // CHECK-NEXT: (CXComment_HTMLEndTag Name=[h1])))]
 
+/// \anchor A
+void comment_to_html_conversion_37();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_37:{{.*}} FullCommentAsHTML=[ ] FullCommentAsXML=[comment_to_html_conversion_37c:@F@comment_to_html_conversion_37#void comment_to_html_conversion_37() A]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
+// CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))]
+
 
 /// Aaa.
 class comment_to_xml_conversion_01 {
Index: clang/test/Index/Inputs/CommentXML/valid-inline-command-01.xml
===
--- /dev/null
+++ clang/test/Index/Inputs/CommentXML/valid-inline-command-01.xml
@@ -0,0 +1,9 @@
+
+
+aaa
+
+  
+
+  
+
+
Index: clang/lib/Index/CommentToXML.cpp
===
--- clang/lib/Index/CommentToXML.cpp
+++ clang/lib/Index/CommentToXML.cpp
@@ -297,6 +297,10 @@
 appendToResultWithHTMLEscaping(Arg0);
 Result << "";
 return;
+  case InlineCommandComment::RenderAnchor:
+assert(C->getNumArgs() == 1);
+ 

[PATCH] D60455: [SYCL] Add sycl_kernel attribute for accelerated code outlining

2019-11-30 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

A couple of minor comments.




Comment at: clang/include/clang/Basic/AttrDocs.td:313
+
+- Function template with at least two template parameters is expected. The 
compiler
+generates OpenCL kernel and uses first template parameter as unique name to the

aaron.ballman wrote:
> The function must be a template with at least two type template parameters.
@bader , could you please apply this too?



Comment at: clang/include/clang/Basic/AttrDocs.td:314
+  expected. The compiler generates an OpenCL kernel and uses the first template
+  parameter as a unique name to the generated OpenCL kernel. The host
+  application uses this unique name to invoke the OpenCL kernel generated for

I'm not an expert in English, so you can ignore it if I'm wrong, but a phrase 
like "uses parameter as a name **to **the kernel" seems strange. Maybe "**for 
** kernel"?



Comment at: clang/include/clang/Basic/AttrDocs.td:317
+  the ``sycl_kernel_function`` specialized by this name and second template
+  parameter ``KernelType`` (which might be a lambda type).
+- The function must have at least one parameter. The first parameter is

(which might be a lambda or a function object type).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60455/new/

https://reviews.llvm.org/D60455



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


[PATCH] D69223: WDocumentation: Implement the \anchor.

2019-11-30 Thread Mark de Wever via Phabricator via cfe-commits
Mordante marked 5 inline comments as done.
Mordante added a comment.

Thanks for the review. I'll address your comments and upload a new version.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69223/new/

https://reviews.llvm.org/D69223



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


[clang] 3f4b70c - Revert "[clang][modules] Add support for merging lifetime-extended temporaries"

2019-11-30 Thread via cfe-commits

Author: Tyker
Date: 2019-11-30T17:52:26+01:00
New Revision: 3f4b70c79e686117c2754d2c0a5a44c8b6829e79

URL: 
https://github.com/llvm/llvm-project/commit/3f4b70c79e686117c2754d2c0a5a44c8b6829e79
DIFF: 
https://github.com/llvm/llvm-project/commit/3f4b70c79e686117c2754d2c0a5a44c8b6829e79.diff

LOG: Revert "[clang][modules] Add support for merging lifetime-extended 
temporaries"

This reverts commit 3c7f6b439699a9cbbc0ac8d288cc70aff357446b.

Added: 


Modified: 
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/TextNodeDumper.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 
clang/test/Modules/Inputs/merge-lifetime-extended-temporary/a.h
clang/test/Modules/Inputs/merge-lifetime-extended-temporary/b.h
clang/test/Modules/Inputs/merge-lifetime-extended-temporary/c.h
clang/test/Modules/Inputs/merge-lifetime-extended-temporary/module.modulemap
clang/test/Modules/merge-lifetime-extended-temporary.cpp



diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 0f2018fb9e8c..63d67bd3f55b 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -3041,9 +3041,7 @@ class NamespaceAliasDecl : public NamedDecl,
 
 /// Implicit declaration of a temporary that was materialized by
 /// a MaterializeTemporaryExpr and lifetime-extended by a declaration
-class LifetimeExtendedTemporaryDecl final
-: public Decl,
-  public Mergeable {
+class LifetimeExtendedTemporaryDecl final : public Decl {
   friend class MaterializeTemporaryExpr;
   friend class ASTDeclReader;
 

diff  --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index d293ea190aa4..0ff5a614a864 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -346,8 +346,6 @@ class TextNodeDumper
   void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
   void VisitBlockDecl(const BlockDecl *D);
   void VisitConceptDecl(const ConceptDecl *D);
-  void
-  VisitLifetimeExtendedTemporaryDecl(const LifetimeExtendedTemporaryDecl *D);
 };
 
 } // namespace clang

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index b6dae68b3413..f0b5e9933823 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -551,14 +551,6 @@ class ASTReader
   llvm::DenseMap>
 AnonymousDeclarationsForMerging;
 
-  /// Key used to identify LifetimeExtendedTemporaryDecl for merging,
-  /// containing the lifetime-extending declaration and the mangling number.
-  using LETemporaryKey = std::pair;
-
-  /// Map of already deserialiazed temporaries.
-  llvm::DenseMap
-  LETemporaryForMerging;
-
   struct FileDeclsInfo {
 ModuleFile *Mod = nullptr;
 ArrayRef Decls;

diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index 561c76a45cbc..0ff95213118f 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1338,17 +1338,6 @@ void TextNodeDumper::VisitFunctionDecl(const 
FunctionDecl *D) {
 OS << " <>>";
 }
 
-void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl(
-const LifetimeExtendedTemporaryDecl *D) {
-  OS << " extended by ";
-  dumpBareDeclRef(D->getExtendingDecl());
-  OS << " mangling ";
-  {
-ColorScope Color(OS, ShowColors, ValueColor);
-OS << D->getManglingNumber();
-  }
-}
-
 void TextNodeDumper::VisitFieldDecl(const FieldDecl *D) {
   dumpName(D);
   dumpType(D->getType());

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index d6c57757cf8c..8991a39a7067 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -424,9 +424,6 @@ namespace clang {
 template
 void mergeMergeable(Mergeable *D);
 
-template <>
-void mergeMergeable(Mergeable *D);
-
 void mergeTemplatePattern(RedeclarableTemplateDecl *D,
   RedeclarableTemplateDecl *Existing,
   DeclID DsID, bool IsKeyDecl);
@@ -2361,7 +2358,6 @@ void ASTDeclReader::VisitLifetimeExtendedTemporaryDecl(
   if (Record.readInt())
 D->Value = new (D->getASTContext()) APValue(Record.readAPValue());
   D->ManglingNumber = Record.readInt();
-  mergeMergeable(D);
 }
 
 std::pair
@@ -2559,28 +2555,6 @@ static bool allowODRLikeMergeInC(NamedDecl *ND) {
   return false;
 }
 
-/// Attempts to merge LifetimeExtendedTemporaryDecl with
-/// identical class definitions from two 
diff erent modules.
-template<>
-void ASTDeclReader::mergeMergeable(
-Mergeable *D) {
-  // If modules are not available, there is no reason to perform this merge.
-  if 

[PATCH] D70190: [clang][modules] Add support for merging lifetime-extended temporaries

2019-11-30 Thread Tyker via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3c7f6b439699: [clang][modules] Add support for merging 
lifetime-extended temporaries (authored by Tyker).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70190/new/

https://reviews.llvm.org/D70190

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/merge-lifetime-extended-temporary/a.h
  clang/test/Modules/Inputs/merge-lifetime-extended-temporary/b.h
  clang/test/Modules/Inputs/merge-lifetime-extended-temporary/c.h
  clang/test/Modules/Inputs/merge-lifetime-extended-temporary/module.modulemap
  clang/test/Modules/merge-lifetime-extended-temporary.cpp

Index: clang/test/Modules/merge-lifetime-extended-temporary.cpp
===
--- /dev/null
+++ clang/test/Modules/merge-lifetime-extended-temporary.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-lifetime-extended-temporary -verify -std=c++11 %s -DORDER=1
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-lifetime-extended-temporary -verify -std=c++11 %s -DORDER=2
+
+// expected-no-diagnostics
+#if ORDER == 1
+#include "c.h"
+#include "b.h"
+#else
+#include "b.h"
+#include "c.h"
+#endif
+
+static_assert(PtrTemp1 == , "");
+static_assert(PtrTemp1 == PtrTemp2, "");
Index: clang/test/Modules/Inputs/merge-lifetime-extended-temporary/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/merge-lifetime-extended-temporary/module.modulemap
@@ -0,0 +1,14 @@
+module "a" {
+  export *
+  header "a.h"
+}
+
+module "b" {
+  export *
+  header "b.h"
+}
+
+module "c" {
+  export *
+  header "c.h"
+}
Index: clang/test/Modules/Inputs/merge-lifetime-extended-temporary/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/merge-lifetime-extended-temporary/c.h
@@ -0,0 +1,4 @@
+
+#include "a.h"
+
+constexpr const int* PtrTemp2 = 
Index: clang/test/Modules/Inputs/merge-lifetime-extended-temporary/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/merge-lifetime-extended-temporary/b.h
@@ -0,0 +1,4 @@
+
+#include "a.h"
+
+constexpr const int* PtrTemp1 = 
Index: clang/test/Modules/Inputs/merge-lifetime-extended-temporary/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/merge-lifetime-extended-temporary/a.h
@@ -0,0 +1,2 @@
+
+constexpr const int& LETemp = 0;
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -424,6 +424,9 @@
 template
 void mergeMergeable(Mergeable *D);
 
+template <>
+void mergeMergeable(Mergeable *D);
+
 void mergeTemplatePattern(RedeclarableTemplateDecl *D,
   RedeclarableTemplateDecl *Existing,
   DeclID DsID, bool IsKeyDecl);
@@ -2358,6 +2361,7 @@
   if (Record.readInt())
 D->Value = new (D->getASTContext()) APValue(Record.readAPValue());
   D->ManglingNumber = Record.readInt();
+  mergeMergeable(D);
 }
 
 std::pair
@@ -2555,6 +2559,28 @@
   return false;
 }
 
+/// Attempts to merge LifetimeExtendedTemporaryDecl with
+/// identical class definitions from two different modules.
+template<>
+void ASTDeclReader::mergeMergeable(
+Mergeable *D) {
+  // If modules are not available, there is no reason to perform this merge.
+  if (!Reader.getContext().getLangOpts().Modules)
+return;
+
+  LifetimeExtendedTemporaryDecl *LETDecl =
+  static_cast(D);
+
+  LifetimeExtendedTemporaryDecl * =
+  Reader.LETemporaryForMerging[std::make_pair(
+  LETDecl->getExtendingDecl(), LETDecl->getManglingNumber())];
+  if (LookupResult)
+Reader.getContext().setPrimaryMergedDecl(LETDecl,
+ LookupResult->getCanonicalDecl());
+  else
+LookupResult = LETDecl;
+}
+
 /// Attempts to merge the given declaration (D) with another declaration
 /// of the same entity, for the case where the entity is not actually
 /// redeclarable. This happens, for instance, when merging the fields of
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1338,6 +1338,17 @@
 OS << " <>>";
 }
 
+void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl(
+const 

[clang] 3c7f6b4 - [clang][modules] Add support for merging lifetime-extended temporaries

2019-11-30 Thread via cfe-commits

Author: Tyker
Date: 2019-11-30T16:42:33+01:00
New Revision: 3c7f6b439699a9cbbc0ac8d288cc70aff357446b

URL: 
https://github.com/llvm/llvm-project/commit/3c7f6b439699a9cbbc0ac8d288cc70aff357446b
DIFF: 
https://github.com/llvm/llvm-project/commit/3c7f6b439699a9cbbc0ac8d288cc70aff357446b.diff

LOG: [clang][modules] Add support for merging lifetime-extended temporaries

Summary: Add support for merging lifetime-extended temporaries

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: xbolva00, cfe-commits

Tags: #clang

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

Added: 
clang/test/Modules/Inputs/merge-lifetime-extended-temporary/a.h
clang/test/Modules/Inputs/merge-lifetime-extended-temporary/b.h
clang/test/Modules/Inputs/merge-lifetime-extended-temporary/c.h
clang/test/Modules/Inputs/merge-lifetime-extended-temporary/module.modulemap
clang/test/Modules/merge-lifetime-extended-temporary.cpp

Modified: 
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/TextNodeDumper.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 63d67bd3f55b..0f2018fb9e8c 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -3041,7 +3041,9 @@ class NamespaceAliasDecl : public NamedDecl,
 
 /// Implicit declaration of a temporary that was materialized by
 /// a MaterializeTemporaryExpr and lifetime-extended by a declaration
-class LifetimeExtendedTemporaryDecl final : public Decl {
+class LifetimeExtendedTemporaryDecl final
+: public Decl,
+  public Mergeable {
   friend class MaterializeTemporaryExpr;
   friend class ASTDeclReader;
 

diff  --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 0ff5a614a864..d293ea190aa4 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -346,6 +346,8 @@ class TextNodeDumper
   void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
   void VisitBlockDecl(const BlockDecl *D);
   void VisitConceptDecl(const ConceptDecl *D);
+  void
+  VisitLifetimeExtendedTemporaryDecl(const LifetimeExtendedTemporaryDecl *D);
 };
 
 } // namespace clang

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index f0b5e9933823..b6dae68b3413 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -551,6 +551,14 @@ class ASTReader
   llvm::DenseMap>
 AnonymousDeclarationsForMerging;
 
+  /// Key used to identify LifetimeExtendedTemporaryDecl for merging,
+  /// containing the lifetime-extending declaration and the mangling number.
+  using LETemporaryKey = std::pair;
+
+  /// Map of already deserialiazed temporaries.
+  llvm::DenseMap
+  LETemporaryForMerging;
+
   struct FileDeclsInfo {
 ModuleFile *Mod = nullptr;
 ArrayRef Decls;

diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index 0ff95213118f..561c76a45cbc 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1338,6 +1338,17 @@ void TextNodeDumper::VisitFunctionDecl(const 
FunctionDecl *D) {
 OS << " <>>";
 }
 
+void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl(
+const LifetimeExtendedTemporaryDecl *D) {
+  OS << " extended by ";
+  dumpBareDeclRef(D->getExtendingDecl());
+  OS << " mangling ";
+  {
+ColorScope Color(OS, ShowColors, ValueColor);
+OS << D->getManglingNumber();
+  }
+}
+
 void TextNodeDumper::VisitFieldDecl(const FieldDecl *D) {
   dumpName(D);
   dumpType(D->getType());

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 8991a39a7067..d6c57757cf8c 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -424,6 +424,9 @@ namespace clang {
 template
 void mergeMergeable(Mergeable *D);
 
+template <>
+void mergeMergeable(Mergeable *D);
+
 void mergeTemplatePattern(RedeclarableTemplateDecl *D,
   RedeclarableTemplateDecl *Existing,
   DeclID DsID, bool IsKeyDecl);
@@ -2358,6 +2361,7 @@ void ASTDeclReader::VisitLifetimeExtendedTemporaryDecl(
   if (Record.readInt())
 D->Value = new (D->getASTContext()) APValue(Record.readAPValue());
   D->ManglingNumber = Record.readInt();
+  mergeMergeable(D);
 }
 
 std::pair
@@ -2555,6 +2559,28 @@ static bool allowODRLikeMergeInC(NamedDecl *ND) {
   return false;
 }
 
+/// Attempts to merge LifetimeExtendedTemporaryDecl with
+/// identical class definitions from two 
diff erent modules.
+template<>
+void ASTDeclReader::mergeMergeable(
+

[PATCH] D70190: [clang][modules] Add support for merging lifetime-extended temporaries

2019-11-30 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 231589.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70190/new/

https://reviews.llvm.org/D70190

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/merge-lifetime-extended-temporary/a.h
  clang/test/Modules/Inputs/merge-lifetime-extended-temporary/b.h
  clang/test/Modules/Inputs/merge-lifetime-extended-temporary/c.h
  clang/test/Modules/Inputs/merge-lifetime-extended-temporary/module.modulemap
  clang/test/Modules/merge-lifetime-extended-temporary.cpp

Index: clang/test/Modules/merge-lifetime-extended-temporary.cpp
===
--- /dev/null
+++ clang/test/Modules/merge-lifetime-extended-temporary.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-lifetime-extended-temporary -verify -std=c++11 %s -DORDER=1
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-lifetime-extended-temporary -verify -std=c++11 %s -DORDER=2
+
+// expected-no-diagnostics
+#if ORDER == 1
+#include "c.h"
+#include "b.h"
+#else
+#include "b.h"
+#include "c.h"
+#endif
+
+static_assert(PtrTemp1 == , "");
+static_assert(PtrTemp1 == PtrTemp2, "");
Index: clang/test/Modules/Inputs/merge-lifetime-extended-temporary/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/merge-lifetime-extended-temporary/module.modulemap
@@ -0,0 +1,14 @@
+module "a" {
+  export *
+  header "a.h"
+}
+
+module "b" {
+  export *
+  header "b.h"
+}
+
+module "c" {
+  export *
+  header "c.h"
+}
Index: clang/test/Modules/Inputs/merge-lifetime-extended-temporary/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/merge-lifetime-extended-temporary/c.h
@@ -0,0 +1,4 @@
+
+#include "a.h"
+
+constexpr const int* PtrTemp2 = 
Index: clang/test/Modules/Inputs/merge-lifetime-extended-temporary/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/merge-lifetime-extended-temporary/b.h
@@ -0,0 +1,4 @@
+
+#include "a.h"
+
+constexpr const int* PtrTemp1 = 
Index: clang/test/Modules/Inputs/merge-lifetime-extended-temporary/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/merge-lifetime-extended-temporary/a.h
@@ -0,0 +1,2 @@
+
+constexpr const int& LETemp = 0;
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -424,6 +424,9 @@
 template
 void mergeMergeable(Mergeable *D);
 
+template <>
+void mergeMergeable(Mergeable *D);
+
 void mergeTemplatePattern(RedeclarableTemplateDecl *D,
   RedeclarableTemplateDecl *Existing,
   DeclID DsID, bool IsKeyDecl);
@@ -2358,6 +2361,7 @@
   if (Record.readInt())
 D->Value = new (D->getASTContext()) APValue(Record.readAPValue());
   D->ManglingNumber = Record.readInt();
+  mergeMergeable(D);
 }
 
 std::pair
@@ -2555,6 +2559,28 @@
   return false;
 }
 
+/// Attempts to merge LifetimeExtendedTemporaryDecl with
+/// identical class definitions from two different modules.
+template<>
+void ASTDeclReader::mergeMergeable(
+Mergeable *D) {
+  // If modules are not available, there is no reason to perform this merge.
+  if (!Reader.getContext().getLangOpts().Modules)
+return;
+
+  LifetimeExtendedTemporaryDecl *LETDecl =
+  static_cast(D);
+
+  LifetimeExtendedTemporaryDecl * =
+  Reader.LETemporaryForMerging[std::make_pair(
+  LETDecl->getExtendingDecl(), LETDecl->getManglingNumber())];
+  if (LookupResult)
+Reader.getContext().setPrimaryMergedDecl(LETDecl,
+ LookupResult->getCanonicalDecl());
+  else
+LookupResult = LETDecl;
+}
+
 /// Attempts to merge the given declaration (D) with another declaration
 /// of the same entity, for the case where the entity is not actually
 /// redeclarable. This happens, for instance, when merging the fields of
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1338,6 +1338,17 @@
 OS << " <>>";
 }
 
+void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl(
+const LifetimeExtendedTemporaryDecl *D) {
+  OS << " extended by ";
+  dumpBareDeclRef(D->getExtendingDecl());
+  OS << " mangling ";
+  {
+ColorScope Color(OS, ShowColors, ValueColor);
+OS << D->getManglingNumber();
+ 

[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

2019-11-30 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
SouraVX added a comment.

In D70696#1764306 , @umesh.kalappa0 
wrote:

> @SouraVX  and @yonghong-song
>
> cat extern.c 
>  int global_var = 2;
>
> compile as an extern.c shared a library ,then final executable a.out doesn't 
> have debugInfo for global_var.


Perfect! Now we have a better use case and motivation that we should generate 
declaration debug entry. for a variable declared as extern.  
that will also solves @umesh.kalappa0 above case. `a.out` will have debuginfo 
for `global_var`, since we generated it's declaration debuginfo in primary 
object `main.c`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70696/new/

https://reviews.llvm.org/D70696



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


[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

2019-11-30 Thread Umesh Kalappa via Phabricator via cfe-commits
umesh.kalappa0 added a comment.

@SouraVX  and @yonghong-song

cat extern.c 
int global_var = 2;

compile as an extern.c shared a library ,then final executable a.out doesn't 
have debugInfo for global_var.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70696/new/

https://reviews.llvm.org/D70696



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


[PATCH] D70868: [libunwind] Emit dependent libraries only when detected by CMake

2019-11-30 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: phosek, ldionne.
Herald added subscribers: jfb, dexonsmith, christof, krytarowski, srhines.

996e62eef75 added Linux-specific dependent libraries to libunwind
sources.  As a result, building libunwind with modern LLD on *BSD
started failing due to trying to link libdl.  Instead, add those
libraries only if they were detected by CMake.

While technically we could create a long list of systems that need -ldl
and -lpthread, maintaining a duplicate list makes little sense when
CMake needs to detect it for non-LLD systems anyway.  Remove existing
system exceptions since they should be covered by the CMake check
anyway.

Remove -D_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA since it is no longer
explicitly needed, if we make the library-specific defines dependent
on presence of this pragma support.


https://reviews.llvm.org/D70868

Files:
  libunwind/CMakeLists.txt
  libunwind/src/AddressSpace.hpp
  libunwind/src/RWMutex.hpp


Index: libunwind/src/RWMutex.hpp
===
--- libunwind/src/RWMutex.hpp
+++ libunwind/src/RWMutex.hpp
@@ -17,7 +17,7 @@
 #include 
 #elif !defined(_LIBUNWIND_HAS_NO_THREADS)
 #include 
-#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && 
defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+#if defined(__ELF__) && defined(_LIBUNWIND_LINK_PTHREAD_LIB)
 #pragma comment(lib, "pthread")
 #endif
 #endif
Index: libunwind/src/AddressSpace.hpp
===
--- libunwind/src/AddressSpace.hpp
+++ libunwind/src/AddressSpace.hpp
@@ -27,7 +27,7 @@
 
 #if _LIBUNWIND_USE_DLADDR
 #include 
-#if defined(__unix__) && defined(__ELF__) && 
defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+#if defined(__ELF__) && defined(_LIBUNWIND_LINK_DL_LIB)
 #pragma comment(lib, "dl")
 #endif
 #endif
Index: libunwind/CMakeLists.txt
===
--- libunwind/CMakeLists.txt
+++ libunwind/CMakeLists.txt
@@ -352,7 +352,12 @@
 endif()
 
 if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
-  add_definitions(-D_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+  if (LIBUNWIND_HAS_DL_LIB)
+add_definitions(-D_LIBUNWIND_LINK_DL_LIB)
+  endif()
+  if (LIBUNWIND_HAS_PTHREAD_LIB)
+add_definitions(-D_LIBUNWIND_LINK_PTHREAD_LIB)
+  endif()
 endif()
 
 
#===


Index: libunwind/src/RWMutex.hpp
===
--- libunwind/src/RWMutex.hpp
+++ libunwind/src/RWMutex.hpp
@@ -17,7 +17,7 @@
 #include 
 #elif !defined(_LIBUNWIND_HAS_NO_THREADS)
 #include 
-#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+#if defined(__ELF__) && defined(_LIBUNWIND_LINK_PTHREAD_LIB)
 #pragma comment(lib, "pthread")
 #endif
 #endif
Index: libunwind/src/AddressSpace.hpp
===
--- libunwind/src/AddressSpace.hpp
+++ libunwind/src/AddressSpace.hpp
@@ -27,7 +27,7 @@
 
 #if _LIBUNWIND_USE_DLADDR
 #include 
-#if defined(__unix__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+#if defined(__ELF__) && defined(_LIBUNWIND_LINK_DL_LIB)
 #pragma comment(lib, "dl")
 #endif
 #endif
Index: libunwind/CMakeLists.txt
===
--- libunwind/CMakeLists.txt
+++ libunwind/CMakeLists.txt
@@ -352,7 +352,12 @@
 endif()
 
 if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
-  add_definitions(-D_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+  if (LIBUNWIND_HAS_DL_LIB)
+add_definitions(-D_LIBUNWIND_LINK_DL_LIB)
+  endif()
+  if (LIBUNWIND_HAS_PTHREAD_LIB)
+add_definitions(-D_LIBUNWIND_LINK_PTHREAD_LIB)
+  endif()
 endif()
 
 #===
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70048: [LLD] Add NetBSD support as a new flavor of LLD (nb.lld)

2019-11-30 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Ping?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70048/new/

https://reviews.llvm.org/D70048



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


[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

2019-11-30 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
SouraVX added a comment.

In D70696#1764043 , @yonghong-song 
wrote:

> If I remove `!D->isUsed()`, I should be able to generate the debuginfo for 
> `global_var` and eventually in dwarf in your above case.
>  What exactly your use case here for these unused external variables?


I simplified that test case, too much. Obiviously, for a real situation, that 
global variable must be defined possibly in some different file, which 
eventually got linked to final executable. Consider this for a moment -
`cat extern.c`

  int global_var = 2;

`cat main.c`

  extern int global_var;
  int main(){
   int local = global_var;
  }

Now for above, clang produce debug info for `gloabal_var` in `extern.c` fine, 
Not in `main.c` for Declaration of `gloabl_var`. Eventually when producing 
final binary{a.out}, linker will merge debug_info section of {extern.c and 
main.c} and we end up with debugging entry in `a.out` , consequently debugger 
is also seems to be happy with it.

But I think, it would be nice to have a declaration debug entry for 
`global_var` in file{main.o) debugging information contribution. Because it's 
using this global variable{declared extern}. like in present case!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70696/new/

https://reviews.llvm.org/D70696



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


[PATCH] D70829: [ARM][MVE][Intrinsics] Add VMINQ/VMAXQ/VMINNMQ/VMAXNMQ intrinsics.

2019-11-30 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

Thanks. I'm happy if simon does not have any extra comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70829/new/

https://reviews.llvm.org/D70829



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


[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-30 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Looks better, thanks.

Aaron ?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70638/new/

https://reviews.llvm.org/D70638



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


[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-30 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 231585.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70638/new/

https://reviews.llvm.org/D70638

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseStmt.cpp
  clang/test/Index/pragma-diag-reparse.c
  clang/test/Misc/warning-wall.c
  clang/test/Parser/warn-misleading-indentation.cpp
  clang/test/Preprocessor/pragma_diagnostic_sections.cpp

Index: clang/test/Preprocessor/pragma_diagnostic_sections.cpp
===
--- clang/test/Preprocessor/pragma_diagnostic_sections.cpp
+++ clang/test/Preprocessor/pragma_diagnostic_sections.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -Wno-misleading-indentation -verify %s
 
 // rdar://8365684
 struct S {
Index: clang/test/Parser/warn-misleading-indentation.cpp
===
--- /dev/null
+++ clang/test/Parser/warn-misleading-indentation.cpp
@@ -0,0 +1,208 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wmisleading-indentation -DWITH_WARN %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -DWITH_WARN -DCXX17 %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -Wno-misleading-indentation -DCXX17 %s
+
+#ifndef WITH_WARN
+// expected-no-diagnostics
+#endif
+
+void f0(int i) {
+  if (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1;
+int x = 0;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+  return;
+#ifdef CXX17
+  if constexpr (false)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = 0;
+i += 1;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+#endif
+}
+
+void f1(int i) {
+  for (;i;)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1;
+i *= 2;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
+#endif
+  return;
+}
+
+void f2(int i) {
+  while (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1; i *= 2;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'while'}}
+#endif
+  return;
+}
+
+void f3(int i) {
+  if (i)
+i = i + 1;
+  else
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+const int x = 0;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else'}}
+#endif
+}
+
+#ifdef CXX17
+struct Range {
+  int *begin() {return nullptr;}
+  int *end() {return nullptr;}
+};
+#endif
+
+void f4(int i) {
+  if (i)
+  i *= 2;
+  return;
+  if (i)
+i *= 2;
+;
+  if (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+typedef int Int;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+#ifdef CXX17
+  Range R;
+  for (auto e : R)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+using Int2 = int;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
+#endif
+#endif
+}
+
+int bar(void);
+
+int foo(int* dst)
+{   
+if (dst)
+   return
+bar();
+  if (dst)
+dst = dst + \
+bar();
+  return 0;
+}
+
+void g(int i) {
+  if (1)
+i = 2;
+  else
+ if (i == 3)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = 4;
+i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else if'}}
+#endif
+}
+
+// Or this
+#define TEST i = 5
+void g0(int i) {
+  if (1)
+i = 2;
+  else
+i = 5;
+TEST;
+}
+
+void g1(int i) {
+  if (1)
+i = 2;
+  else if (i == 3)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+  i = 4;
+  i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else if'}}
+#endif
+}
+
+void g2(int i) {
+  if (1)
+i = 2;
+  else
+if (i == 3)
+{i = 4;}
+i = 5;
+}
+
+void g6(int i) {
+if (1)
+if (i == 3)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = 4;
+i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+}
+
+void g7(int i) {
+  if (1)
+i = 4;
+#ifdef TEST1
+#endif
+i = 5;
+}
+
+void a1(int i) { if (1) i = 4; return; }
+
+void 

[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-30 Thread Tyker via Phabricator via cfe-commits
Tyker marked an inline comment as done.
Tyker added inline comments.



Comment at: clang/lib/Parse/ParseStmt.cpp:1376
+
+MIChecker.Check(ElseStmt.isUsable());
 

Tyker wrote:
> xbolva00 wrote:
> > What is wrong with code you used some rev ago?
> > 
> > if (usable) check();
> > 
> > Now you uselessly instantiate MIChecker since if Usable = false, check is 
> > not called.
> > 
> > I like the older code more...
> > 
> > If (usable) checkForMisleadingIndention(...) 
> > 
> > Was good and accepted.
> previous patch gave up on else if because we can't know wether there are 
> braces.
> 
> this revision can produce correct diagnostics on else if
the MisleadingIndentationChecker gathers information during its construction 
this allows having more context and removes many false positives. 

but I can bring back
If (usable) MIChecker.Check(...)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70638/new/

https://reviews.llvm.org/D70638



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


[PATCH] D69764: [clang-format] Add Left/Right Const (East/West , Before/After) fixer capability

2019-11-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

gentle ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69764/new/

https://reviews.llvm.org/D69764



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


[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-30 Thread Tyker via Phabricator via cfe-commits
Tyker marked an inline comment as done.
Tyker added inline comments.



Comment at: clang/lib/Parse/ParseStmt.cpp:1376
+
+MIChecker.Check(ElseStmt.isUsable());
 

xbolva00 wrote:
> What is wrong with code you used some rev ago?
> 
> if (usable) check();
> 
> Now you uselessly instantiate MIChecker since if Usable = false, check is not 
> called.
> 
> I like the older code more...
> 
> If (usable) checkForMisleadingIndention(...) 
> 
> Was good and accepted.
previous patch gave up on else if because we can't know wether there are braces.

this revision can produce correct diagnostics on else if


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70638/new/

https://reviews.llvm.org/D70638



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


[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-30 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 231584.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70638/new/

https://reviews.llvm.org/D70638

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseStmt.cpp
  clang/test/Index/pragma-diag-reparse.c
  clang/test/Misc/warning-wall.c
  clang/test/Parser/warn-misleading-indentation.cpp
  clang/test/Preprocessor/pragma_diagnostic_sections.cpp

Index: clang/test/Preprocessor/pragma_diagnostic_sections.cpp
===
--- clang/test/Preprocessor/pragma_diagnostic_sections.cpp
+++ clang/test/Preprocessor/pragma_diagnostic_sections.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -Wno-misleading-indentation -verify %s
 
 // rdar://8365684
 struct S {
Index: clang/test/Parser/warn-misleading-indentation.cpp
===
--- /dev/null
+++ clang/test/Parser/warn-misleading-indentation.cpp
@@ -0,0 +1,208 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wmisleading-indentation -DWITH_WARN %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -DWITH_WARN -DCXX17 %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -Wno-misleading-indentation -DCXX17 %s
+
+#ifndef WITH_WARN
+// expected-no-diagnostics
+#endif
+
+void f0(int i) {
+  if (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1;
+int x = 0;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+  return;
+#ifdef CXX17
+  if constexpr (false)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = 0;
+i += 1;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+#endif
+}
+
+void f1(int i) {
+  for (;i;)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1;
+i *= 2;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
+#endif
+  return;
+}
+
+void f2(int i) {
+  while (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1; i *= 2;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'while'}}
+#endif
+  return;
+}
+
+void f3(int i) {
+  if (i)
+i = i + 1;
+  else
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+const int x = 0;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else'}}
+#endif
+}
+
+#ifdef CXX17
+struct Range {
+  int *begin() {return nullptr;}
+  int *end() {return nullptr;}
+};
+#endif
+
+void f4(int i) {
+  if (i)
+  i *= 2;
+  return;
+  if (i)
+i *= 2;
+;
+  if (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+typedef int Int;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+#ifdef CXX17
+  Range R;
+  for (auto e : R)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+using Int2 = int;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
+#endif
+#endif
+}
+
+int bar(void);
+
+int foo(int* dst)
+{   
+if (dst)
+   return
+bar();
+  if (dst)
+dst = dst + \
+bar();
+  return 0;
+}
+
+void g(int i) {
+  if (1)
+i = 2;
+  else
+ if (i == 3)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = 4;
+i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else if'}}
+#endif
+}
+
+// Or this
+#define TEST i = 5
+void g0(int i) {
+  if (1)
+i = 2;
+  else
+i = 5;
+TEST;
+}
+
+void g1(int i) {
+  if (1)
+i = 2;
+  else if (i == 3)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+  i = 4;
+  i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else if'}}
+#endif
+}
+
+void g2(int i) {
+  if (1)
+i = 2;
+  else
+if (i == 3)
+{i = 4;}
+i = 5;
+}
+
+void g6(int i) {
+if (1)
+if (i == 3)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = 4;
+i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+}
+
+void g7(int i) {
+  if (1)
+i = 4;
+#ifdef TEST1
+#endif
+i = 5;
+}
+
+void a1(int i) { if (1) i = 4; return; }
+
+void 

[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-30 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 231583.
Tyker added a comment.

Improve the warning for else if


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70638/new/

https://reviews.llvm.org/D70638

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseStmt.cpp
  clang/test/Index/pragma-diag-reparse.c
  clang/test/Misc/warning-wall.c
  clang/test/Preprocessor/pragma_diagnostic_sections.cpp

Index: clang/test/Preprocessor/pragma_diagnostic_sections.cpp
===
--- clang/test/Preprocessor/pragma_diagnostic_sections.cpp
+++ clang/test/Preprocessor/pragma_diagnostic_sections.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -Wno-misleading-indentation -verify %s
 
 // rdar://8365684
 struct S {
Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -90,6 +90,7 @@
 CHECK-NEXT:-Wdangling-else
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
+CHECK-NEXT:  -Wmisleading-indentation
 
 
 CHECK-NOT:-W
Index: clang/test/Index/pragma-diag-reparse.c
===
--- clang/test/Index/pragma-diag-reparse.c
+++ clang/test/Index/pragma-diag-reparse.c
@@ -11,6 +11,7 @@
   return x;
 }
 
+#pragma clang diagnostic ignored "-Wmisleading-indentation"
 void foo() { int b=0; while (b==b); }
 
 // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_FAILONERROR=1 c-index-test -test-load-source-reparse 5 local \
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1191,6 +1191,56 @@
   return false;
 }
 
+namespace {
+
+enum MisleadingStatementKind { MSK_if, MSK_else, MSK_for, MSK_while, MSK_else_if };
+
+struct MisleadingIndentationChecker {
+  Parser 
+  SourceLocation StmtLoc;
+  SourceLocation PrevLoc;
+  unsigned NumDirectives;
+  MisleadingStatementKind Kind;
+  bool NeedsChecking;
+  bool ShouldSkip;
+  MisleadingIndentationChecker(Parser , MisleadingStatementKind K,
+   SourceLocation SL)
+  : P(P), StmtLoc(SL), PrevLoc(P.getCurToken().getLocation()),
+NumDirectives(P.getPreprocessor().getNumDirectives()), Kind(K),
+NeedsChecking(true),
+ShouldSkip(P.getCurToken().is(tok::l_brace) ||
+   (K == MSK_else && P.getCurToken().is(tok::kw_if))) {}
+  void Check(bool ShouldCheck) {
+NeedsChecking = false;
+Token Tok = P.getCurToken();
+if (!ShouldCheck || ShouldSkip ||
+NumDirectives != P.getPreprocessor().getNumDirectives() ||
+Tok.isOneOf(tok::semi, tok::r_brace) || Tok.isAnnotation() ||
+Tok.getLocation().isMacroID() || PrevLoc.isMacroID() ||
+StmtLoc.isMacroID())
+  return;
+SourceManager  = P.getPreprocessor().getSourceManager();
+unsigned PrevColNum = SM.getSpellingColumnNumber(PrevLoc);
+unsigned CurColNum = SM.getSpellingColumnNumber(Tok.getLocation());
+unsigned StmtColNum = SM.getSpellingColumnNumber(StmtLoc);
+
+if (PrevColNum != 0 && CurColNum != 0 && StmtColNum != 0 &&
+((PrevColNum > StmtColNum && PrevColNum == CurColNum) ||
+ !Tok.isAtStartOfLine())) {
+  if (SM.getPresumedLineNumber(StmtLoc) ==
+  SM.getPresumedLineNumber(Tok.getLocation()))
+return;
+  P.Diag(Tok.getLocation(), diag::warn_misleading_indentation)
+  << Kind;
+  P.Diag(StmtLoc, diag::note_previous_statement);
+}
+  }
+  ~MisleadingIndentationChecker() {
+assert(!NeedsChecking && "Check Has not been called");
+  }
+};
+
+}
 
 /// ParseIfStatement
 ///   if-statement: [C99 6.8.4.1]
@@ -1199,7 +1249,8 @@
 /// [C++]   'if' '(' condition ')' statement
 /// [C++]   'if' '(' condition ')' statement 'else' statement
 ///
-StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) {
+StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc,
+SourceLocation ElseLocOnElseIf) {
   assert(Tok.is(tok::kw_if) && "Not an if stmt!");
   SourceLocation IfLoc = ConsumeToken();  // eat the 'if'.
 
@@ -1265,6 +1316,10 @@
   //
   ParseScope InnerScope(this, Scope::DeclScope, C99orCXX, Tok.is(tok::l_brace));
 
+  MisleadingIndentationChecker MIChecker(
+  *this, ElseLocOnElseIf.isInvalid() ? MSK_if : MSK_else_if,
+  ElseLocOnElseIf.isInvalid() ? IfLoc : ElseLocOnElseIf);
+
   // Read the 'then' stmt.
   SourceLocation ThenStmtLoc = Tok.getLocation();
 
@@ -1278,6 +1333,8 @@
 ThenStmt = ParseStatement();
   }
 
+  

[PATCH] D70302: [CodeGen] Fix clang crash on aggregate initialization of array of labels

2019-11-30 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes added a comment.

In D70302#1763025 , @rnk wrote:

> Fix looks good post commit, but we should enhance the test.


I see, apologies for the premature commit.




Comment at: clang/test/CodeGen/label-array-aggregate-init.c:1
+// RUN: %clang -cc1 -emit-llvm %s -o /dev/null
+

rnk wrote:
> It's best practice to filecheck for something, even if this used to crash.
I guess the test should make sure that the array is constructed successfully 
after codegen.
I'm unsure about the best way to test that. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70302/new/

https://reviews.llvm.org/D70302



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