[PATCH] D58880: [clangd] Type hierarchy subtypes

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

Get disabled tests passing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58880

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/test/type-hierarchy.test
  clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp

Index: clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
===
--- clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -450,6 +450,169 @@
   SelectionRangeIs(Source.range("SDef")), Parents();
 }
 
+SymbolID findSymbolIDByName(SymbolIndex *Index, llvm::StringRef Name,
+llvm::StringRef TemplateArgs = "") {
+  SymbolID Result;
+  FuzzyFindRequest Request;
+  Request.Query = Name;
+  Request.AnyScope = true;
+  int ResultCount = 0;
+  Index->fuzzyFind(Request, [&](const Symbol ) {
+if (TemplateArgs == S.TemplateSpecializationArgs) {
+  Result = S.ID;
+  ++ResultCount;
+}
+  });
+  EXPECT_EQ(1, ResultCount);
+  return Result;
+}
+
+std::vector collectSubtypes(SymbolID Type, SymbolIndex *Index) {
+  std::vector Result;
+  Index->relations(
+  RelationsRequest{Type, index::SymbolRole::RelationBaseOf, llvm::None},
+  [](const Symbol ) { Result.push_back(S.ID); });
+  return Result;
+}
+
+TEST(Subtypes, SimpleInheritance) {
+  Annotations Source(R"cpp(
+struct Parent {
+  int a;
+};
+
+struct Child1 : Parent {
+  int b;
+};
+
+struct Child2 : Child1 {
+  int c;
+};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName(Index.get(), "Parent");
+  SymbolID Child1 = findSymbolIDByName(Index.get(), "Child1");
+  SymbolID Child2 = findSymbolIDByName(Index.get(), "Child2");
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()), ElementsAre(Child1));
+  EXPECT_THAT(collectSubtypes(Child1, Index.get()), ElementsAre(Child2));
+}
+
+TEST(Subtypes, MultipleInheritance) {
+  Annotations Source(R"cpp(
+struct Parent1 {
+  int a;
+};
+
+struct Parent2 {
+  int b;
+};
+
+struct Parent3 : Parent2 {
+  int c;
+};
+
+struct Child : Parent1, Parent3 {
+  int d;
+};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent1 = findSymbolIDByName(Index.get(), "Parent1");
+  SymbolID Parent2 = findSymbolIDByName(Index.get(), "Parent2");
+  SymbolID Parent3 = findSymbolIDByName(Index.get(), "Parent3");
+  SymbolID Child = findSymbolIDByName(Index.get(), "Child");
+
+  EXPECT_THAT(collectSubtypes(Parent1, Index.get()), ElementsAre(Child));
+  EXPECT_THAT(collectSubtypes(Parent2, Index.get()), ElementsAre(Parent3));
+  EXPECT_THAT(collectSubtypes(Parent3, Index.get()), ElementsAre(Child));
+}
+
+TEST(Subtypes, ClassTemplate) {
+  Annotations Source(R"cpp(
+struct Parent {};
+
+template 
+struct Child : Parent {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName(Index.get(), "Parent");
+  SymbolID Child = findSymbolIDByName(Index.get(), "Child");
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()), ElementsAre(Child));
+}
+
+TEST(Subtypes, TemplateSpec1) {
+  Annotations Source(R"cpp(
+template 
+struct Parent {};
+
+template <>
+struct Parent {};
+
+struct Child1 : Parent {};
+
+struct Child2 : Parent {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName(Index.get(), "Parent");
+  SymbolID ParentSpec = findSymbolIDByName(Index.get(), "Parent", "");
+  SymbolID Child1 = findSymbolIDByName(Index.get(), "Child1");
+  SymbolID Child2 = findSymbolIDByName(Index.get(), "Child2");
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()), ElementsAre(Child1));
+  EXPECT_THAT(collectSubtypes(ParentSpec, Index.get()), ElementsAre(Child2));
+}
+
+TEST(Subtypes, TemplateSpec2) {
+  Annotations Source(R"cpp(
+struct Parent {};
+
+template 
+struct Child {};
+
+template <>
+struct Child : Parent {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName(Index.get(), "Parent");
+  SymbolID ChildSpec = findSymbolIDByName(Index.get(), "Child", "");
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()), ElementsAre(ChildSpec));
+}
+
+TEST(Subtypes, DependentBase) {
+  Annotations Source(R"cpp(
+template 
+struct Parent {};
+
+template 
+struct Child : Parent {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName(Index.get(), "Parent");
+  SymbolID Child = findSymbolIDByName(Index.get(), "Child");
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()), 

[PATCH] D6833: Clang-format: Braces Indent Style Whitesmith

2019-06-11 Thread Tim Wojtulewicz via Phabricator via cfe-commits
timwoj added a comment.

I updated this patch to remove all of the code from `ContinuationIndenter` and 
to use the newer `BraceWrapping` style option instead of setting each one 
individually in `UnwrappedLineParser`.

I still have the same issue with enums. Looking at the `RootToken` in 
`UnwrappedLineFormatter::formatFirstToken` when parsing an enum, the first pass 
through it has the entire line for the enum in it with all of the newlines 
stripped from my test case. It then doesn't ever return the braces as separate 
lines. If someone could give me a pointer as to how/why enums are tokenized 
differently from everything else, I can likely fix it. The test case I'm using 
looks like:

  verifyFormat("enum X\n"
   "  {\n"
   "  Y = 0,\n"
   "  }\n",
   WhitesmithsBraceStyle);

I also have the issue with a `break` after a block inside of a case statement, 
as mentioned in https://reviews.llvm.org/D6833#107539. Other than those two, 
it's mostly working correctly. I removed the test for lambdas because I'm not 
entirely sure how that should even be formatted with Whitesmiths, but I can add 
it back in again.

Should I update this thread with the new diff against HEAD, or should I open a 
new one and close this one as dead?


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

https://reviews.llvm.org/D6833



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


[PATCH] D63180: [clang-doc] Adds HTML generator

2019-06-11 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich, lebedev.ri.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman, mgorny.

Implement a simple HMTL generator based on the existing Markdown generator.
Basic HTML tags are included: h, p, em, strong, br.
HTML templates will be used in the future instead of generating each of the 
HTML tags individually.


https://reviews.llvm.org/D63180

Files:
  clang-tools-extra/clang-doc/CMakeLists.txt
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -0,0 +1,306 @@
+//===-- clang-doc/HTMLGeneratorTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+std::unique_ptr getHTMLGenerator() {
+  auto G = doc::findGeneratorByName("html");
+  if (!G)
+return nullptr;
+  return std::move(G.get());
+}
+
+TEST(HTMLGeneratorTest, emitNamespaceHTML) {
+  NamespaceInfo I;
+  I.Name = "Namespace";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
+ InfoType::IT_namespace);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getHTMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual);
+  assert(!Err);
+  std::string Expected = R"raw(namespace Namespace
+
+Namespaces
+ChildNamespace
+
+Records
+ChildStruct
+
+Functions
+OneFunction
+ OneFunction()
+
+Enums
+| enum OneEnum |
+--
+
+
+)raw";
+
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(HTMLGeneratorTest, emitRecordHTML) {
+  RecordInfo I;
+  I.Name = "r";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
+
+  I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
+  I.TagType = TagTypeKind::TTK_Class;
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
+  I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getHTMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual);
+  assert(!Err);
+  std::string Expected = R"raw(class r
+Defined at line 10 of test.cpp
+Inherits from F, G
+
+Members
+private int X
+
+Records
+ChildStruct
+
+Functions
+OneFunction
+ OneFunction()
+
+Enums
+| enum OneEnum |
+--
+
+
+)raw";
+
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(HTMLGeneratorTest, emitFunctionHTML) {
+  FunctionInfo I;
+  I.Name = "f";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
+
+  I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  I.Params.emplace_back("int", "P");
+  I.IsMethod = true;
+  I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
+
+  auto G = getHTMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual);
+  assert(!Err);
+  std::string Expected = R"raw(f
+void f(int P)
+Defined at line 10 of test.cpp
+)raw";
+
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(HTMLGeneratorTest, emitEnumHTML) {
+  EnumInfo I;
+  I.Name = "e";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
+
+  

[PATCH] D63164: [HIP] Add option to force lambda nameing following ODR in HIP/CUDA.

2019-06-11 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D63164#1538968 , @tra wrote:

> So, in short, what you're saying is that lambda type may leak into the 
> mangled name of a `__global__` function and ne need to ensure that the 
> mangled name is identical for both host and device, hence the need for 
> consistent naming of lambdas.
>
> If that's the case, shouldn't it be enabled for CUDA/HIP by default? While 
> it's not frequently used ATM, it is something we do want to work correctly 
> all the time. The failure to do so results in weird runtime failures that 
> would be hard to debug for end-users.
>
> @rsmith -- are there any downsides having this enabled all the time?


yeah, we should ensure consistent naming by default. But, I want to hear more 
suggestion and comment before making that option by default. To more specific, 
as that option forces all naming of lambda to follow ODR rule. For 
non-`__device__` lambda, even though there is no code quality change, we do add 
overhead for the compiler itself, as the additional records, though that should 
be negligible.  A potential solution is to record the ODR context for parent 
lambdas and re-number them if the inner lambda is found as `__device__` one.
However, I do like the straight-forward and extremely simple solution of this 
patch to force all lambda naming following ODR, there is no code quality change 
and, potentially slight, FE overhead. What's your thought?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63164



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


[PATCH] D59744: Fix i386 ABI "__m64" type bug

2019-06-11 Thread Pengfei Wang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363116: [X86] [ABI] Fix i386 ABI __m64 type bug 
(authored by pengfei, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59744?vs=204197=204203#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59744

Files:
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/test/CodeGen/x86_32-arguments-linux.c
  cfe/trunk/test/CodeGen/x86_32-m64.c

Index: cfe/trunk/test/CodeGen/x86_32-arguments-linux.c
===
--- cfe/trunk/test/CodeGen/x86_32-arguments-linux.c
+++ cfe/trunk/test/CodeGen/x86_32-arguments-linux.c
@@ -3,7 +3,7 @@
 
 // CHECK-LABEL: define void @f56(
 // CHECK: i8 signext %a0, %struct.s56_0* byval(%struct.s56_0) align 4 %a1,
-// CHECK: i64 %a2.coerce, %struct.s56_1* byval(%struct.s56_1) align 4,
+// CHECK: x86_mmx %a2.coerce, %struct.s56_1* byval(%struct.s56_1) align 4,
 // CHECK: <1 x double> %a4, %struct.s56_2* byval(%struct.s56_2) align 4,
 // CHECK: <4 x i32> %a6, %struct.s56_3* byval(%struct.s56_3) align 4,
 // CHECK: <2 x double> %a8, %struct.s56_4* byval(%struct.s56_4) align 4,
@@ -12,7 +12,7 @@
 
 // CHECK: call void (i32, ...) @f56_0(i32 1,
 // CHECK: i32 %{{.*}}, %struct.s56_0* byval(%struct.s56_0) align 4 %{{[^ ]*}},
-// CHECK: i64 %{{[^ ]*}}, %struct.s56_1* byval(%struct.s56_1) align 4 %{{[^ ]*}},
+// CHECK: x86_mmx %{{[^ ]*}}, %struct.s56_1* byval(%struct.s56_1) align 4 %{{[^ ]*}},
 // CHECK: <1 x double> %{{[^ ]*}}, %struct.s56_2* byval(%struct.s56_2) align 4 %{{[^ ]*}},
 // CHECK: <4 x i32> %{{[^ ]*}}, %struct.s56_3* byval(%struct.s56_3) align 4 %{{[^ ]*}},
 // CHECK: <2 x double> %{{[^ ]*}}, %struct.s56_4* byval(%struct.s56_4) align 4 %{{[^ ]*}},
Index: cfe/trunk/test/CodeGen/x86_32-m64.c
===
--- cfe/trunk/test/CodeGen/x86_32-m64.c
+++ cfe/trunk/test/CodeGen/x86_32-m64.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -w -O2 -fblocks -triple i386-pc-linux-gnu -target-cpu pentium4 -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LINUX
+// RUN: %clang_cc1 -w -O2 -fblocks -triple i386-netbsd -target-cpu pentium4 -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,NETBSD
+// RUN: %clang_cc1 -w -O2 -fblocks -triple i386-apple-darwin9 -target-cpu yonah -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,DARWIN
+// RUN: %clang_cc1 -w -O2 -fblocks -triple i386-pc-elfiamcu -mfloat-abi soft -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,IAMCU
+// RUN: %clang_cc1 -w -O2 -fblocks -triple i386-pc-win32 -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WIN32
+
+#include 
+__m64 m64;
+void callee(__m64 __m1, __m64 __m2);
+__m64 caller(__m64 __m1, __m64 __m2)
+{
+// LINUX-LABEL: define x86_mmx @caller(x86_mmx %__m1.coerce, x86_mmx %__m2.coerce)
+// LINUX: tail call void @callee(x86_mmx %__m2.coerce, x86_mmx %__m1.coerce)
+// LINUX: ret x86_mmx
+// NETBSD-LABEL: define x86_mmx @caller(x86_mmx %__m1.coerce, x86_mmx %__m2.coerce)
+// NETBSD: tail call void @callee(x86_mmx %__m2.coerce, x86_mmx %__m1.coerce)
+// NETBSD: ret x86_mmx
+// DARWIN-LABEL: define i64 @caller(i64 %__m1.coerce, i64 %__m2.coerce)
+// DARWIN: tail call void @callee(i64 %__m2.coerce, i64 %__m1.coerce)
+// DARWIN: ret i64
+// IAMCU-LABEL: define <1 x i64> @caller(i64 %__m1.coerce, i64 %__m2.coerce)
+// IAMCU: tail call void @callee(i64 %__m2.coerce, i64 %__m1.coerce)
+// IAMCU: ret <1 x i64>
+// WIN32-LABEL: define dso_local <1 x i64> @caller(i64 %__m1.coerce, i64 %__m2.coerce)
+// WIN32: call void @callee(i64 %__m2.coerce, i64 %__m1.coerce)
+// WIN32: ret <1 x i64>
+  callee(__m2, __m1);
+  return m64;
+}
Index: cfe/trunk/lib/CodeGen/TargetInfo.cpp
===
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp
@@ -915,14 +915,6 @@
: ABIArgInfo::getDirect());
 }
 
-/// IsX86_MMXType - Return true if this is an MMX type.
-bool IsX86_MMXType(llvm::Type *IRType) {
-  // Return true if the type is an MMX type <2 x i32>, <4 x i16>, or <8 x i8>.
-  return IRType->isVectorTy() && IRType->getPrimitiveSizeInBits() == 64 &&
-cast(IRType)->getElementType()->isIntegerTy() &&
-IRType->getScalarSizeInBits() != 64;
-}
-
 static llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction ,
   StringRef Constraint,
   llvm::Type* Ty) {
@@ -1011,6 +1003,7 @@
   bool IsSoftFloatABI;
   bool IsMCUABI;
   unsigned DefaultNumRegisterParameters;
+  bool IsMMXEnabled;
 
   static bool isRegisterSize(unsigned Size) {
 return (Size == 8 || Size == 16 || Size == 32 || Size == 64);
@@ -1070,13 +1063,15 @@
 
   X86_32ABIInfo(CodeGen::CodeGenTypes , bool 

r363116 - [X86] [ABI] Fix i386 ABI "__m64" type bug

2019-06-11 Thread Pengfei Wang via cfe-commits
Author: pengfei
Date: Tue Jun 11 18:52:23 2019
New Revision: 363116

URL: http://llvm.org/viewvc/llvm-project?rev=363116=rev
Log:
[X86] [ABI] Fix i386 ABI "__m64" type bug

According to System V i386 ABI: the  __m64 type paramater and return
value are passed by MMX registers. But current implementation treats
__m64 as i64 which results in parameter passing by stack and returning
by EDX and EAX.

This patch fixes the bug (https://bugs.llvm.org/show_bug.cgi?id=41029)
for Linux and NetBSD.

Patch by Wei Xiao (wxiao3)

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

Added:
cfe/trunk/test/CodeGen/x86_32-m64.c
Modified:
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/CodeGen/x86_32-arguments-linux.c

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=363116=363115=363116=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Tue Jun 11 18:52:23 2019
@@ -915,14 +915,6 @@ ABIArgInfo PNaClABIInfo::classifyReturnT
: ABIArgInfo::getDirect());
 }
 
-/// IsX86_MMXType - Return true if this is an MMX type.
-bool IsX86_MMXType(llvm::Type *IRType) {
-  // Return true if the type is an MMX type <2 x i32>, <4 x i16>, or <8 x i8>.
-  return IRType->isVectorTy() && IRType->getPrimitiveSizeInBits() == 64 &&
-cast(IRType)->getElementType()->isIntegerTy() &&
-IRType->getScalarSizeInBits() != 64;
-}
-
 static llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction ,
   StringRef Constraint,
   llvm::Type* Ty) {
@@ -1011,6 +1003,7 @@ class X86_32ABIInfo : public SwiftABIInf
   bool IsSoftFloatABI;
   bool IsMCUABI;
   unsigned DefaultNumRegisterParameters;
+  bool IsMMXEnabled;
 
   static bool isRegisterSize(unsigned Size) {
 return (Size == 8 || Size == 16 || Size == 32 || Size == 64);
@@ -1070,13 +1063,15 @@ public:
 
   X86_32ABIInfo(CodeGen::CodeGenTypes , bool DarwinVectorABI,
 bool RetSmallStructInRegABI, bool Win32StructABI,
-unsigned NumRegisterParameters, bool SoftFloatABI)
+unsigned NumRegisterParameters, bool SoftFloatABI,
+bool MMXEnabled)
 : SwiftABIInfo(CGT), IsDarwinVectorABI(DarwinVectorABI),
   IsRetSmallStructInRegABI(RetSmallStructInRegABI),
   IsWin32StructABI(Win32StructABI),
   IsSoftFloatABI(SoftFloatABI),
   IsMCUABI(CGT.getTarget().getTriple().isOSIAMCU()),
-  DefaultNumRegisterParameters(NumRegisterParameters) {}
+  DefaultNumRegisterParameters(NumRegisterParameters),
+  IsMMXEnabled(MMXEnabled) {}
 
   bool shouldPassIndirectlyForSwift(ArrayRef scalars,
 bool asReturnValue) const override {
@@ -1091,16 +1086,30 @@ public:
 // x86-32 lowering does not support passing swifterror in a register.
 return false;
   }
+
+  bool isPassInMMXRegABI() const {
+// The System V i386 psABI requires __m64 to be passed in MMX registers.
+// Clang historically had a bug where it failed to apply this rule, and
+// some platforms (e.g. Darwin, PS4, and FreeBSD) have opted to maintain
+// compatibility with the old Clang behavior, so we only apply it on
+// platforms that have specifically requested it (currently just Linux and
+// NetBSD).
+const llvm::Triple  = getTarget().getTriple();
+if (IsMMXEnabled && (T.isOSLinux() || T.isOSNetBSD()))
+  return true;
+return false;
+  }
 };
 
 class X86_32TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   X86_32TargetCodeGenInfo(CodeGen::CodeGenTypes , bool DarwinVectorABI,
   bool RetSmallStructInRegABI, bool Win32StructABI,
-  unsigned NumRegisterParameters, bool SoftFloatABI)
+  unsigned NumRegisterParameters, bool SoftFloatABI,
+  bool MMXEnabled = false)
   : TargetCodeGenInfo(new X86_32ABIInfo(
 CGT, DarwinVectorABI, RetSmallStructInRegABI, Win32StructABI,
-NumRegisterParameters, SoftFloatABI)) {}
+NumRegisterParameters, SoftFloatABI, MMXEnabled)) {}
 
   static bool isStructReturnInRegABI(
   const llvm::Triple , const CodeGenOptions );
@@ -1386,10 +1395,9 @@ ABIArgInfo X86_32ABIInfo::classifyReturn
   }
 
   if (const VectorType *VT = RetTy->getAs()) {
+uint64_t Size = getContext().getTypeSize(RetTy);
 // On Darwin, some vectors are returned in registers.
 if (IsDarwinVectorABI) {
-  uint64_t Size = getContext().getTypeSize(RetTy);
-
   // 128-bit vectors are a special case; they are returned in
   // registers and we need to make sure to pick a type the LLVM
   // backend will like.
@@ -1407,6 +1415,10 @@ ABIArgInfo X86_32ABIInfo::classifyReturn
   return 

[PATCH] D62988: Add an attribute to allow fields of non-trivial types in C unions

2019-06-11 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

In D62988#1538577 , @rsmith wrote:

> How do you write correct (non-leaking, non-double-freeing, 
> non-releasing-invalid-pointers) code with this attribute? For example, 
> suppose I have a `__strong` union member: does storing to it release the old 
> value (which might be a different union member)? If so, how do you work 
> around that? 
> https://clang.llvm.org/docs/AutomaticReferenceCounting.html#ownership-qualified-fields-of-structs-and-unions
>  should be updated to say what happens. If manual reference counting code is 
> required to make any use of this feature correct (which seems superficially 
> likely), is this a better programming model than `__unsafe_unretained`?


I should first make it clear that this attribute is a dangerous feature that 
makes it easier for users to write incorrect code if they aren't careful.

To write correct code, users have to manually (I don't mean 
manual-retain-release, this is compiled with ARC) do assignments to the fields 
that are annotated with the attribute to patch up the code generated by the 
compiler since the compiler isn't generating the kind of special functions it 
generates for non-trivial structs. For example:

  union U1 {
id __weak __attribute__((non_trivial_union_member)) a;
id __attribute__((non_trivial_union_member)) b;
  };

  id getObj(int);
  
  void foo() {
union U1 u1 = { .b = 0}; // zero-initialize 'b'.
u1.b = getObj(1); // assign to __strong field 'b'.
u1.b = getObj(2); // retain and assign another object to 'b' and release 
the previously referenced object.
u1.b = 0; // release the object.
id t = getObj(3);
u1.a = t; // assign to __weak field 'a'.
u1.a = 0; // unregister as a __weak object.
  }
  
  struct S1 {
union U1 f0;
int f1;
  };
  
  void foo1() {
struct S1 s1 = { .f0 = 0};
s1.f0.a = getObj(4);
struct S1 s2 = s1; // this is just a memcpy
s2.f0.a = s1.f0.a;  // manually copy __weak field 'a'.
s2.f0.a = 0;  // unregister as a __weak object.
  }

Storing to a `__strong` union member does release the old value. The old value 
can be a different union member and I think that should be fine as long as the 
other member is also `__strong`. If the other member has a different lifetime 
qualifier, I believe it has to be nulled out before assigning the new object as 
shown in the example above.

> Unions with non-trivial members are only permitted in C++11 onwards; should 
> we allow the attribute in C++98 mode? But more than that, unions with 
> non-trivial members require user-provided special members in C++11 onwards, 
> meaning that a union using this attribute in C would have a different calling 
> convention than the "natural" equivalent in C++. So I'm also wondering if we 
> should allow this in all language modes.

I think we can allow this attribute in C++ mode including C++98. One thing to 
note is that the compiler creates temporaries users can't directly access when 
passing/returning unions with non-trivial members to/from functions or 
capturing them as a block capture. In those cases, users won't be able to patch 
up the code generated by the compiler, so it would be incorrect to pass a union 
whose active member is the one annotated with `non_trivial_union_member`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62988



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


[PATCH] D62225: [clang][NewPM] Fixing remaining -O0 tests that are broken under new PM

2019-06-11 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D62225#1537248 , @chandlerc wrote:

> I think this ultimately needs to be split up into smaller patches. A bunch of 
> these things can be landed independently. Here is my first cut at things to 
> split out, each one into its own patch.


Done. I split them into 6 other patches plus this one.

> 1. the LLVM change to the always inliner

Addressed in D63170 .

> 2. the Clang change to how we build the always inliner

Addressed in D63153 .

> 3. the PGO pipeline changes (which I have to admit I still don't fully 
> understand)

Addressed in D63155 . There aren't any logical 
changes to PGO in this. This just adds `PGOInstrumentationGenCreateVar` to the 
pipeline such that `./default.profraw` is generated and allows 
`Profile/gcc-flag-compatibility.c` to pass.

> 4. The additions of `-fno-experimental-new-pass-manager` for test cases that 
> are explicitly testing legacy PM behavior

Addressed in D63156 . I also combined #6 in 
this one since those `-O` tests are pretty much `-O2` tests.

> 5. switching tests to be resilient to changes in attribute group numbering 
> (and adding a RUN line w/ the new PM to ensure we don't regress)
> 
>   for #5 (or others) where *some* testing needs to be working before they can 
> land, just sequence them after whatever they depend on

Addressed in D63174 . The tests that were 
failing due to attribute numbering don't seem to fail anymore, so someone 
must've addressed that in a previous patch. This one now just contains the 
tests that produces slightly different IR.

> Other things I think can also be split out, but I suspect into *different* 
> changes from what you have here:
> 
> 6. Instead of passing `-fno-experimental-new-pass-manager` for tests that use 
> `-O` but don't specify a number, Clang should pick a consistent value for the 
> level I think

D63168  seems separate from the rest and fixes 
`CodeGen/split-debug-single-file.c`.

> I'd be interested to then see what is left here.

The remaining ones here are the flatten tests and optimization remark tests. 
The flatten tests fail since the new PM AlwaysInliner seems to inline functions 
only and not calls (based off the description in D23299 
), so for now they are marked as UNSUPPORTED.

The optimization remark tests fail since it seems that the new PM inliner is 
not enabled at `-O0` and emit slightly different remarks. This patch forces 
those breaking runs to run with legacy PM only and adds separate new PM tests 
with `-O1` to enable the inliner.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62225



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


[PATCH] D58880: [WIP] [clangd] Type hierarchy subtypes

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

Rebase, add lit test, and post for review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58880

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/test/type-hierarchy.test
  clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp

Index: clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
===
--- clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -450,6 +450,177 @@
   SelectionRangeIs(Source.range("SDef")), Parents();
 }
 
+SymbolID findSymbolIDByName(llvm::StringRef Name, SymbolIndex *Index) {
+  SymbolID Result;
+  FuzzyFindRequest Request;
+  Request.Query = Name;
+  Request.AnyScope = true;
+  Request.Limit = 1;
+  int ResultCount = 0;
+  Index->fuzzyFind(Request, [&](const Symbol ) {
+Result = S.ID;
+++ResultCount;
+  });
+  EXPECT_EQ(1, ResultCount);
+  return Result;
+}
+
+std::vector collectSubtypes(SymbolID Type, SymbolIndex *Index) {
+  std::vector Result;
+  Index->relations(
+  RelationsRequest{Type, index::SymbolRole::RelationBaseOf, llvm::None},
+  [](const Symbol ) { Result.push_back(S.ID); });
+  return Result;
+}
+
+TEST(Subtypes, SimpleInheritance) {
+  Annotations Source(R"cpp(
+struct Parent {
+  int a;
+};
+
+struct Child1 : Parent {
+  int b;
+};
+
+struct Child2 : Child1 {
+  int c;
+};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName("Parent", Index.get());
+  SymbolID Child1 = findSymbolIDByName("Child1", Index.get());
+  SymbolID Child2 = findSymbolIDByName("Child2", Index.get());
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()), ElementsAre(Child1));
+  EXPECT_THAT(collectSubtypes(Child1, Index.get()), ElementsAre(Child2));
+}
+
+TEST(Subtypes, MultipleInheritance) {
+  Annotations Source(R"cpp(
+struct Parent1 {
+  int a;
+};
+
+struct Parent2 {
+  int b;
+};
+
+struct Parent3 : Parent2 {
+  int c;
+};
+
+struct Child : Parent1, Parent3 {
+  int d;
+};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent1 = findSymbolIDByName("Parent1", Index.get());
+  SymbolID Parent2 = findSymbolIDByName("Parent2", Index.get());
+  SymbolID Parent3 = findSymbolIDByName("Parent3", Index.get());
+  SymbolID Child = findSymbolIDByName("Child", Index.get());
+
+  EXPECT_THAT(collectSubtypes(Parent1, Index.get()), ElementsAre(Child));
+  EXPECT_THAT(collectSubtypes(Parent2, Index.get()), ElementsAre(Parent3));
+  EXPECT_THAT(collectSubtypes(Parent3, Index.get()), ElementsAre(Child));
+}
+
+TEST(Subtypes, ClassTemplate) {
+  Annotations Source(R"cpp(
+struct Parent {};
+
+template 
+struct Child : Parent {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName("Parent", Index.get());
+  SymbolID Child = findSymbolIDByName("Child", Index.get());
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()), ElementsAre(Child));
+}
+
+// FIXME(nridge):
+//   This test is failing because findSymbolIDByName("Parent")
+//   does not find the explicit specialization. Figure out why this
+//   is the case even though we are now storing explicit specializations
+//   and their template argument lists in the index.
+TEST(Subtypes, DISABLED_TemplateSpec1) {
+  Annotations Source(R"cpp(
+template 
+struct Parent {};
+
+template <>
+struct Parent {};
+
+struct Child1 : Parent {};
+
+struct Child2 : Parent {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName("Parent", Index.get());
+  SymbolID ParentSpec = findSymbolIDByName("Parent", Index.get());
+  SymbolID Child1 = findSymbolIDByName("Child1", Index.get());
+  SymbolID Child2 = findSymbolIDByName("Child2", Index.get());
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()), ElementsAre(Child1));
+  EXPECT_THAT(collectSubtypes(ParentSpec, Index.get()), ElementsAre(Child2));
+}
+
+// FIXME(nridge):
+//   This test is failing because findSymbolIDByName("Child")
+//   does not find the explicit specialization. Figure out why this
+//   is the case even though we are now storing explicit specializations
+//   and their template argument lists in the index.
+TEST(Subtypes, DISABLED_TemplateSpec2) {
+  Annotations Source(R"cpp(
+struct Parent {};
+
+template 
+struct Child {};
+
+template <>
+struct Child : Parent {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName("Parent", Index.get());
+  SymbolID ChildSpec = findSymbolIDByName("Child", Index.get());
+
+  

[PATCH] D62978: [analyzer] trackExpressionValue(): Handle unknown values better

2019-06-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

This problem is fairly complicated. We clearly need both behaviors (sometimes 
track until the definition, sometimes track until the collapse-to-null), and 
it's not clear to me right now when exactly do we need each of them. This is 
also not a high priority for GSoC because neither there are a lot of warnings 
of this kind (~15 or so) nor they're actually that false. I suggest taking this 
more slowly and delay this patch until we actually understand what is the right 
thing to do here.




Comment at: clang/test/Analysis/null-deref-path-notes.cpp:20
 // expected-note@-1{{Array access (via field 'd') results in a 
null pointer dereference}}
-  B h, a; // expected-note{{Value assigned to 'h.d'}}
   a.d == __null; // expected-note{{Assuming the condition is true}}

This note was pretty good. It's not very clear but we should definitely keep it.



Comment at: clang/test/Analysis/uninit-vals.m:405
 int y : 4;
-  } a, b, c; // expected-note{{'c' initialized here}}
 

These notes are also nice, we should keep them.


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

https://reviews.llvm.org/D62978



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


[PATCH] D62225: [clang][NewPM] Fixing remaining -O0 tests that are broken under new PM

2019-06-11 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 204198.
leonardchan retitled this revision from "[clang][NewPM] Fixing -O0 tests that 
are broken under new PM" to "[clang][NewPM] Fixing remaining -O0 tests that are 
broken under new PM".
leonardchan edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62225

Files:
  clang/test/CMakeLists.txt
  clang/test/CodeGen/flatten.c
  clang/test/CodeGenCXX/flatten.cpp
  clang/test/Frontend/optimization-remark-line-directive.c
  clang/test/Frontend/optimization-remark-new-pm.c
  clang/test/Frontend/optimization-remark-with-hotness-new-pm.c
  clang/test/Frontend/optimization-remark-with-hotness.c
  clang/test/Frontend/optimization-remark.c
  clang/test/lit.cfg.py
  clang/test/lit.site.cfg.py.in

Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -24,6 +24,7 @@
 config.clang_examples = @CLANG_BUILD_EXAMPLES@
 config.enable_shared = @ENABLE_SHARED@
 config.enable_backtrace = @ENABLE_BACKTRACES@
+config.enable_experimental_new_pass_manager = @ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER@
 config.host_arch = "@HOST_ARCH@"
 config.python_executable = "@PYTHON_EXECUTABLE@"
 config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', "@USE_Z3_SOLVER@")
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -97,6 +97,10 @@
 if platform.system() not in ['FreeBSD']:
 config.available_features.add('crash-recovery')
 
+# Support for new pass manager.
+if config.enable_experimental_new_pass_manager:
+config.available_features.add('experimental-new-pass-manager')
+
 # ANSI escape sequences in non-dumb terminal
 if platform.system() not in ['Windows']:
 config.available_features.add('ansi-escape-sequences')
Index: clang/test/Frontend/optimization-remark.c
===
--- clang/test/Frontend/optimization-remark.c
+++ clang/test/Frontend/optimization-remark.c
@@ -1,20 +1,30 @@
 // This file tests the -Rpass family of flags (-Rpass, -Rpass-missed
 // and -Rpass-analysis) with the inliner. The test is designed to
 // always trigger the inliner, so it should be independent of the
-// optimization level.
+// optimization level (under the legacy PM). The inliner is not added to the new
+// PM pipeline unless optimizations are present.
 
-// RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline -Rpass-missed=inline -O0 -emit-llvm-only -verify
-// RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline -Rpass-missed=inline -O0 -emit-llvm-only -debug-info-kind=line-tables-only -verify
+// The inliner for the new PM does not seem to be enabled at O0, but we still
+// get the same remarks with at least O1. The remarks are also slightly
+// different and located in another test file.
+// RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline -Rpass-missed=inline -O0 -fno-experimental-new-pass-manager -emit-llvm-only -verify
+// RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline -Rpass-missed=inline -O0 -fno-experimental-new-pass-manager -emit-llvm-only -debug-info-kind=line-tables-only -verify
 // RUN: %clang_cc1 %s -Rpass=inline -emit-llvm -o - 2>/dev/null | FileCheck %s
 //
 // Check that we can override -Rpass= with -Rno-pass.
-// RUN: %clang_cc1 %s -Rpass=inline -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+// RUN: %clang_cc1 %s -Rpass=inline -fno-experimental-new-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
 // RUN: %clang_cc1 %s -Rpass=inline -Rno-pass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
 // RUN: %clang_cc1 %s -Rpass=inline -Rno-everything -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
-// RUN: %clang_cc1 %s -Rpass=inline -Rno-everything -Reverything -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+// RUN: %clang_cc1 %s -Rpass=inline -fno-experimental-new-pass-manager -Rno-everything -Reverything -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+//
+// The inliner for the new PM does not seem to be enabled at O0, but we still
+// get the same remarks with at least O1.
+// RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+// RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 -Rno-everything -Reverything -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
 //
 // Check that -w doesn't disable remarks.
-// RUN: %clang_cc1 %s -Rpass=inline -w -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+// RUN: %clang_cc1 %s -Rpass=inline -fno-experimental-new-pass-manager -w -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+// 

[PATCH] D59744: Fix i386 ABI "__m64" type bug

2019-06-11 Thread Wei Xiao via Phabricator via cfe-commits
wxiao3 added a comment.

Thanks for the comments!
Updated for landing.


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

https://reviews.llvm.org/D59744



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


[PATCH] D59744: Fix i386 ABI "__m64" type bug

2019-06-11 Thread Wei Xiao via Phabricator via cfe-commits
wxiao3 updated this revision to Diff 204197.

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

https://reviews.llvm.org/D59744

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/x86_32-arguments-linux.c
  test/CodeGen/x86_32-m64.c

Index: test/CodeGen/x86_32-m64.c
===
--- /dev/null
+++ test/CodeGen/x86_32-m64.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -w -O2 -fblocks -triple i386-pc-linux-gnu -target-cpu pentium4 -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LINUX
+// RUN: %clang_cc1 -w -O2 -fblocks -triple i386-netbsd -target-cpu pentium4 -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,NETBSD
+// RUN: %clang_cc1 -w -O2 -fblocks -triple i386-apple-darwin9 -target-cpu yonah -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,DARWIN
+// RUN: %clang_cc1 -w -O2 -fblocks -triple i386-pc-elfiamcu -mfloat-abi soft -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,IAMCU
+// RUN: %clang_cc1 -w -O2 -fblocks -triple i386-pc-win32 -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WIN32
+
+#include 
+__m64 m64;
+void callee(__m64 __m1, __m64 __m2);
+__m64 caller(__m64 __m1, __m64 __m2)
+{
+// LINUX-LABEL: define x86_mmx @caller(x86_mmx %__m1.coerce, x86_mmx %__m2.coerce)
+// LINUX: tail call void @callee(x86_mmx %__m2.coerce, x86_mmx %__m1.coerce)
+// LINUX: ret x86_mmx
+// NETBSD-LABEL: define x86_mmx @caller(x86_mmx %__m1.coerce, x86_mmx %__m2.coerce)
+// NETBSD: tail call void @callee(x86_mmx %__m2.coerce, x86_mmx %__m1.coerce)
+// NETBSD: ret x86_mmx
+// DARWIN-LABEL: define i64 @caller(i64 %__m1.coerce, i64 %__m2.coerce)
+// DARWIN: tail call void @callee(i64 %__m2.coerce, i64 %__m1.coerce)
+// DARWIN: ret i64
+// IAMCU-LABEL: define <1 x i64> @caller(i64 %__m1.coerce, i64 %__m2.coerce)
+// IAMCU: tail call void @callee(i64 %__m2.coerce, i64 %__m1.coerce)
+// IAMCU: ret <1 x i64>
+// WIN32-LABEL: define dso_local <1 x i64> @caller(i64 %__m1.coerce, i64 %__m2.coerce)
+// WIN32: call void @callee(i64 %__m2.coerce, i64 %__m1.coerce)
+// WIN32: ret <1 x i64>
+  callee(__m2, __m1);
+  return m64;
+}
Index: test/CodeGen/x86_32-arguments-linux.c
===
--- test/CodeGen/x86_32-arguments-linux.c
+++ test/CodeGen/x86_32-arguments-linux.c
@@ -3,7 +3,7 @@
 
 // CHECK-LABEL: define void @f56(
 // CHECK: i8 signext %a0, %struct.s56_0* byval(%struct.s56_0) align 4 %a1,
-// CHECK: i64 %a2.coerce, %struct.s56_1* byval(%struct.s56_1) align 4,
+// CHECK: x86_mmx %a2.coerce, %struct.s56_1* byval(%struct.s56_1) align 4,
 // CHECK: <1 x double> %a4, %struct.s56_2* byval(%struct.s56_2) align 4,
 // CHECK: <4 x i32> %a6, %struct.s56_3* byval(%struct.s56_3) align 4,
 // CHECK: <2 x double> %a8, %struct.s56_4* byval(%struct.s56_4) align 4,
@@ -12,7 +12,7 @@
 
 // CHECK: call void (i32, ...) @f56_0(i32 1,
 // CHECK: i32 %{{.*}}, %struct.s56_0* byval(%struct.s56_0) align 4 %{{[^ ]*}},
-// CHECK: i64 %{{[^ ]*}}, %struct.s56_1* byval(%struct.s56_1) align 4 %{{[^ ]*}},
+// CHECK: x86_mmx %{{[^ ]*}}, %struct.s56_1* byval(%struct.s56_1) align 4 %{{[^ ]*}},
 // CHECK: <1 x double> %{{[^ ]*}}, %struct.s56_2* byval(%struct.s56_2) align 4 %{{[^ ]*}},
 // CHECK: <4 x i32> %{{[^ ]*}}, %struct.s56_3* byval(%struct.s56_3) align 4 %{{[^ ]*}},
 // CHECK: <2 x double> %{{[^ ]*}}, %struct.s56_4* byval(%struct.s56_4) align 4 %{{[^ ]*}},
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -915,14 +915,6 @@
: ABIArgInfo::getDirect());
 }
 
-/// IsX86_MMXType - Return true if this is an MMX type.
-bool IsX86_MMXType(llvm::Type *IRType) {
-  // Return true if the type is an MMX type <2 x i32>, <4 x i16>, or <8 x i8>.
-  return IRType->isVectorTy() && IRType->getPrimitiveSizeInBits() == 64 &&
-cast(IRType)->getElementType()->isIntegerTy() &&
-IRType->getScalarSizeInBits() != 64;
-}
-
 static llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction ,
   StringRef Constraint,
   llvm::Type* Ty) {
@@ -1011,6 +1003,7 @@
   bool IsSoftFloatABI;
   bool IsMCUABI;
   unsigned DefaultNumRegisterParameters;
+  bool IsMMXEnabled;
 
   static bool isRegisterSize(unsigned Size) {
 return (Size == 8 || Size == 16 || Size == 32 || Size == 64);
@@ -1070,13 +1063,15 @@
 
   X86_32ABIInfo(CodeGen::CodeGenTypes , bool DarwinVectorABI,
 bool RetSmallStructInRegABI, bool Win32StructABI,
-unsigned NumRegisterParameters, bool SoftFloatABI)
+unsigned NumRegisterParameters, bool SoftFloatABI,
+bool MMXEnabled)
 : SwiftABIInfo(CGT), IsDarwinVectorABI(DarwinVectorABI),
   IsRetSmallStructInRegABI(RetSmallStructInRegABI),
   IsWin32StructABI(Win32StructABI),
   

[PATCH] D59673: [Clang] Harmonize Split DWARF options with llc

2019-06-11 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good!


Repository:
  rC Clang

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

https://reviews.llvm.org/D59673



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


[PATCH] D63167: [Clang] Remove obsolete -enable-split-dwarf={single,split}

2019-06-11 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: include/clang/Basic/CodeGenOptions.def:263
 
-ENUM_CODEGENOPT(SplitDwarfMode, DwarfFissionKind, 2, NoFission) ///< DWARF 
fission mode to use.
+CODEGENOPT(EnableSplitDwarf, 1, 0) ///< Whether to enable split DWARF.
 

Could we skip this and rely on "SplitDwarFile" being non-empty?


Repository:
  rC Clang

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

https://reviews.llvm.org/D63167



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


[PATCH] D63130: [Clang] Rename -split-dwarf-file to -split-dwarf-output

2019-06-11 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good - thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D63130



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


[PATCH] D61809: [BPF] Preserve debuginfo array/union/struct type/access index

2019-06-11 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

The general idea of restricting the intrinsics to specific contexts makes 
sense.  I'm not sure it makes sense to mark expressions, as opposed to types, 
though; can we really expect the user to know which expressions to apply this 
to?

I'd like to see an actual specification for this in docs/LanguageExtensions.rst 
at some point.

Other than that, generally seems okay.




Comment at: lib/CodeGen/CGExpr.cpp:663
+  while (true) {
+const auto  = getContext().getParents(*E);
+if (Parents.size() != 1)

I'm not sure you can use getParents like this safely... it's not really meant 
for use inside of clang semantic analysis/code generation, and I don't think we 
recompute it as the AST changes.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61809



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


[PATCH] D62926: [analyzer] ReturnVisitor: Bypass everything to see inlined calls

2019-06-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

All right, it seems that i'm completely misunderstanding this problem and we've 
been talking past each other this whole time.

The problem is not that we need to skip the `CXXConstructExpr`. The problem is 
that we need to skip `CXXNewExpr` (!!). CFG elements for an operator-new call 
go like this:

1. CFGAllocatorCall
2. CXXConstructExpr
3. CXXNewExpr

We're staring at element 3. The original loop says "hey, that's our statement! 
we've found it!". However, even though this is the statement that's taken as 
the call site, the respective ExplodedNode does not correspond to the end of 
the call. Instead, it corresponds to a moment of time after construction has 
finished and the new-expression is fully evaluated. So we need to ignore 
element 3. Then, element 2 is ignored automatically because the statements 
don't match. Then, we need to learn to recognize that element 1 is the right 
element, which is going to be either a `CallExitEnd` (if the allocator call was 
inlined) or dunno-but-definitely-not-`PostStmt` if the allocator was evaluated 
conservatively.

Bonus: the constructor is never inlined in our scenario, so it's easy to skip 
element 2, as it's going to be just PreStmt/PostStmt and no inlined call within 
it. Why? Because how the hell do you inline a constructor of a null pointer. 
The Standard guarantees that when the allocator returns a null pointer, the 
constructor is gracefully omitted. We currently have a FIXME in 
`prepareForObjectConstruction()` to implement this behavior:

  179 // TODO: Detect when the allocator returns a null pointer.
  180 // Constructor shall not be called in this case.

The current incorrect behavior is to instead evaluate the constructor 
conservatively, with a fake temporary region instead of the null pointer (this 
is generally the conservative approach to evaluating the constructor when 
object-under-construction is not known).

So my request to come up with a test case in which the constructor is going to 
be inlined was completely pointless. But in the general case we aren't really 
sure that it's going to be a null pointer (we may want to track an arbitrary 
value), so we shouldn't rely on that.




Comment at: clang/test/Analysis/new-ctor-null.cpp:37
   S *s = new S();
   // FIXME: Should be FALSE - we should not invalidate globals.
   clang_analyzer_eval(global); // expected-warning{{UNKNOWN}}

This is essentially the same FIXME: the constructor should not have been 
evaluated, so in particular we should not invalidate globals.


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

https://reviews.llvm.org/D62926



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


[PATCH] D63176: [SemaObjC] Infer availability of stuff declared in categories from the availability of the enclosing category

2019-06-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: clang/test/SemaObjC/unguarded-availability.m:365
+// FIXME: The pretty-printing for categories sucks.
+@interface HasCat () // expected-note 3 {{'' has been marked as being 
introduced in macOS 10.11 here, but the deployment target is macOS 10.9.0}}
+-(void)meth1;

Can't we just fix it here with a more contextual message? It would be nice to 
say `enclosing category has been marked...`


Repository:
  rC Clang

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

https://reviews.llvm.org/D63176



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


[PATCH] D62761: [analyzer] exploded-graph-rewriter: Implement a --diff mode.

2019-06-11 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D62761#1539143 , @NoQ wrote:

> In D62761#1539137 , @Charusso wrote:
>
> > I asked for the new behavior, but I think it should be cool.
>
>
> The new behavior is on the original screenshot, i just uploaded the wrong 
> patch initially >.<


No problem, thanks for the screenshot and for the clarification!


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

https://reviews.llvm.org/D62761



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


[PATCH] D61809: [BPF] Preserve debuginfo array/union/struct type/access index

2019-06-11 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@rsmith @eli.friedman Ping again. Do you have any comments on my proposed 
clang/IR intrinsics? Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D61809



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


[PATCH] D63176: [SemaObjC] Infer availability of stuff declared in categories from the availability of the enclosing category

2019-06-11 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
erik.pilkington added reviewers: arphaman, steven_wu.
Herald added subscribers: dexonsmith, jkorous.
Herald added a project: clang.

These extend the class, but (unlike methods in @interfaces) can be referenced 
without mentioning the the category, so we don't otherwise emit a diagnostic.

rdar://51318091


Repository:
  rC Clang

https://reviews.llvm.org/D63176

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/unguarded-availability.m


Index: clang/test/SemaObjC/unguarded-availability.m
===
--- clang/test/SemaObjC/unguarded-availability.m
+++ clang/test/SemaObjC/unguarded-availability.m
@@ -353,3 +353,41 @@
 void is_destructor() {
   func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 
10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to 
silence this warning}}
 }
+
+@interface HasCat
+-(void)meth;
++(void)class_meth;
+@property int prop;
+@end
+
+AVAILABLE_10_11
+// FIXME: The pretty-printing for categories sucks.
+@interface HasCat () // expected-note 3 {{'' has been marked as being 
introduced in macOS 10.11 here, but the deployment target is macOS 10.9.0}}
+-(void)meth1;
++(void)class_meth1;
+
+@property int prop1;
+
+@end
+
+AVAILABLE_10_12
+@interface HasCat (Named) // expected-note{{'Named' has been marked as being 
introduced in macOS 10.12 here, but the deployment target is macOS 10.9.0}}
+-(void)meth2;
+@end
+
+@interface HasCat (OtherNamed)
+-(void)meth3;
+@end
+
+void test_category(HasCat *hc) {
+  [hc meth];
+  [hc meth1]; // expected-warning{{'meth1' is only available on macOS 10.11 or 
newer}} expected-note{{enclose 'meth1' in an @available check to silence this 
warning}}
+  [hc meth2]; // expected-warning{{'meth2' is only available on macOS 10.12 or 
newer}} expected-note{{enclose 'meth2' in an @available check to silence this 
warning}}
+  [hc meth3];
+
+  [HasCat class_meth];
+  [HasCat class_meth1]; // expected-warning{{'class_meth1' is only available 
on macOS 10.11 or newer}} expected-note{{enclose 'class_meth1' in an @available 
check to silence this warning}}
+
+  hc.prop = 42;
+  hc.prop1 = 42; // expected-warning{{'setProp1:' is only available on macOS 
10.11 or newer}} expected-note{{enclose 'setProp1:' in an @available check to 
silence this warning}}
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7716,6 +7716,15 @@
 }
   }
 
+  // If this entity was declared in an Objective-C category then infer its
+  // availability from the category's availability.
+  if (auto *CatDecl = dyn_cast(D->getDeclContext())) {
+if (Result == AR_Available) {
+  Result = CatDecl->getAvailability(Message);
+  D = CatDecl;
+}
+  }
+
   return {Result, D};
 }
 


Index: clang/test/SemaObjC/unguarded-availability.m
===
--- clang/test/SemaObjC/unguarded-availability.m
+++ clang/test/SemaObjC/unguarded-availability.m
@@ -353,3 +353,41 @@
 void is_destructor() {
   func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
 }
+
+@interface HasCat
+-(void)meth;
++(void)class_meth;
+@property int prop;
+@end
+
+AVAILABLE_10_11
+// FIXME: The pretty-printing for categories sucks.
+@interface HasCat () // expected-note 3 {{'' has been marked as being introduced in macOS 10.11 here, but the deployment target is macOS 10.9.0}}
+-(void)meth1;
++(void)class_meth1;
+
+@property int prop1;
+
+@end
+
+AVAILABLE_10_12
+@interface HasCat (Named) // expected-note{{'Named' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9.0}}
+-(void)meth2;
+@end
+
+@interface HasCat (OtherNamed)
+-(void)meth3;
+@end
+
+void test_category(HasCat *hc) {
+  [hc meth];
+  [hc meth1]; // expected-warning{{'meth1' is only available on macOS 10.11 or newer}} expected-note{{enclose 'meth1' in an @available check to silence this warning}}
+  [hc meth2]; // expected-warning{{'meth2' is only available on macOS 10.12 or newer}} expected-note{{enclose 'meth2' in an @available check to silence this warning}}
+  [hc meth3];
+
+  [HasCat class_meth];
+  [HasCat class_meth1]; // expected-warning{{'class_meth1' is only available on macOS 10.11 or newer}} expected-note{{enclose 'class_meth1' in an @available check to silence this warning}}
+
+  hc.prop = 42;
+  hc.prop1 = 42; // expected-warning{{'setProp1:' is only available on macOS 10.11 or newer}} expected-note{{enclose 'setProp1:' in an @available check to silence this warning}}
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ 

[PATCH] D62761: [analyzer] exploded-graph-rewriter: Implement a --diff mode.

2019-06-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D62761#1539137 , @Charusso wrote:

> I asked for the new behavior, but I think it should be cool.


The new behavior is on the original screenshot, i just uploaded the wrong patch 
initially >.<


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

https://reviews.llvm.org/D62761



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


[PATCH] D62761: [analyzer] exploded-graph-rewriter: Implement a --diff mode.

2019-06-11 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso accepted this revision.
Charusso added a comment.
This revision is now accepted and ready to land.

I asked for the new behavior, but I think it should be cool.


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

https://reviews.llvm.org/D62761



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


[PATCH] D62761: [analyzer] exploded-graph-rewriter: Implement a --diff mode.

2019-06-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D62761#1525923 , @Charusso wrote:

> In D62761#1525917 , @NoQ wrote:
>
> > Remove "-" from program point dumps because it resembles a removal marker 
> > in diffs.
>
>
> Could you add an image? I have not seen any problematic stuff, just that.


F9179567: Screen Shot 2019-06-11 at 4.52.59 PM.png 

The minus signs in "Program points: - one - two - three" are confusing.


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

https://reviews.llvm.org/D62761



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


[PATCH] D63175: [MS] Pretend constexpr variable template specializations are inline

2019-06-11 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/AST/ASTContext.cpp:9809
+  // variable template specializations inline.
+  if (isa(VD) && VD->isConstexpr())
+return GVA_DiscardableODR;

It'd be nice to include a note here that this is strictly non-conforming (since 
another TU could be relying on this TU to provide the definition), but that we 
don't expect that to happen in practice for variable template specializations 
declared `constexpr`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63175



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


Re: r363086 - For DR712: store on a DeclRefExpr whether it constitutes an odr-use.

2019-06-11 Thread Richard Smith via cfe-commits
Thanks, should be fixed by r363113.

On Tue, 11 Jun 2019 at 16:21, Reid Kleckner via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> The new assert is firing across Chromium, please fix or revert. This is a
> reduced test case:
>
> int a;
> struct Foo {
>   template  void operator()(b, c =
> a);
> };
> Foo d;
> bool e;
> decltype(d(e)) gv;
>
> This causes the "missing non-odr-use marking for unevaluated decl ref"
> assertion on SemaExpr.cpp:16227 to fire.
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r363113 - Mark declarations as referenced by a default argument in a

2019-06-11 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Jun 11 16:51:46 2019
New Revision: 363113

URL: http://llvm.org/viewvc/llvm-project?rev=363113=rev
Log:
Mark declarations as referenced by a default argument in a
potentially-evaluated context.

This applies even if the use of the default argument is within an
unevaluated context.

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaTemplate/default-arguments.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=363113=363112=363113=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jun 11 16:51:46 2019
@@ -4855,6 +4855,8 @@ bool Sema::CheckCXXDefaultArgExpr(Source
   // We already type-checked the argument, so we know it works.
   // Just mark all of the declarations in this potentially-evaluated expression
   // as being "referenced".
+  EnterExpressionEvaluationContext EvalContext(
+  *this, ExpressionEvaluationContext::PotentiallyEvaluated, Param);
   MarkDeclarationsReferencedInExpr(Param->getDefaultArg(),
/*SkipLocalVariables=*/true);
   return false;

Modified: cfe/trunk/test/SemaTemplate/default-arguments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/default-arguments.cpp?rev=363113=363112=363113=diff
==
--- cfe/trunk/test/SemaTemplate/default-arguments.cpp (original)
+++ cfe/trunk/test/SemaTemplate/default-arguments.cpp Tue Jun 11 16:51:46 2019
@@ -223,3 +223,9 @@ namespace friends {
 X *p;
   }
 }
+
+namespace unevaluated {
+  int a;
+  template int f(int = a); // expected-warning 0-1{{extension}}
+  int k = sizeof(f());
+}


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


[PATCH] D63175: [MS] Pretend constexpr variable template specializations are inline

2019-06-11 Thread Reid Kleckner via Phabricator via cfe-commits
rnk created this revision.
rnk added a reviewer: rsmith.
Herald added a project: clang.

Fixes link errors with clang and the latest Visual C++ 14.21.27702
headers, which was reported as PR42027.

I chose to intentionally make these things linkonce_odr, i.e.
discardable, so that we don't emit definitions of these things in every
translation unit that includes STL headers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63175

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/CodeGenCXX/ms-constexpr-var-template.cpp


Index: clang/test/CodeGenCXX/ms-constexpr-var-template.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ms-constexpr-var-template.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-windows-msvc -fms-compatibility 
%s -o - | FileCheck %s
+
+template  constexpr bool _Is_integer = false;
+template <> constexpr bool _Is_integer = true;
+template <> constexpr bool _Is_integer = false;
+extern "C" const bool *escape = &_Is_integer;
+
+// CHECK: @"??$_Is_integer@H@@3_NB" = linkonce_odr dso_local constant i8 1, 
comdat, align 1
+//   Should not emit _Is_integer, since it's not referenced.
+// CHECK-NOT: @"??$_Is_integer@D@@3_NB"
+// CHECK: @escape = dso_local global i8* @"??$_Is_integer@H@@3_NB", align 8
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -9799,10 +9799,22 @@
 return StrongLinkage;
 
   case TSK_ExplicitSpecialization:
-return Context.getTargetInfo().getCXXABI().isMicrosoft() &&
-   VD->isStaticDataMember()
-   ? GVA_StrongODR
-   : StrongLinkage;
+if (Context.getTargetInfo().getCXXABI().isMicrosoft()) {
+  // If this is a fully specialized constexpr variable template, pretend it
+  // was marked inline. MSVC 14.21.27702 headers define _Is_integral in a
+  // header this way, and we don't want to emit non-discardable definitions
+  // of these variables in every TU that includes . This
+  // behavior can be removed if the headers change to explicitly mark such
+  // variable template specializations inline.
+  if (isa(VD) && VD->isConstexpr())
+return GVA_DiscardableODR;
+
+  // Use ODR linkage for static data members of fully specialized templates
+  // to prevent duplicate definition errors with MSVC.
+  if (VD->isStaticDataMember())
+return GVA_StrongODR;
+}
+return StrongLinkage;
 
   case TSK_ExplicitInstantiationDefinition:
 return GVA_StrongODR;


Index: clang/test/CodeGenCXX/ms-constexpr-var-template.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ms-constexpr-var-template.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-windows-msvc -fms-compatibility %s -o - | FileCheck %s
+
+template  constexpr bool _Is_integer = false;
+template <> constexpr bool _Is_integer = true;
+template <> constexpr bool _Is_integer = false;
+extern "C" const bool *escape = &_Is_integer;
+
+// CHECK: @"??$_Is_integer@H@@3_NB" = linkonce_odr dso_local constant i8 1, comdat, align 1
+//   Should not emit _Is_integer, since it's not referenced.
+// CHECK-NOT: @"??$_Is_integer@D@@3_NB"
+// CHECK: @escape = dso_local global i8* @"??$_Is_integer@H@@3_NB", align 8
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -9799,10 +9799,22 @@
 return StrongLinkage;
 
   case TSK_ExplicitSpecialization:
-return Context.getTargetInfo().getCXXABI().isMicrosoft() &&
-   VD->isStaticDataMember()
-   ? GVA_StrongODR
-   : StrongLinkage;
+if (Context.getTargetInfo().getCXXABI().isMicrosoft()) {
+  // If this is a fully specialized constexpr variable template, pretend it
+  // was marked inline. MSVC 14.21.27702 headers define _Is_integral in a
+  // header this way, and we don't want to emit non-discardable definitions
+  // of these variables in every TU that includes . This
+  // behavior can be removed if the headers change to explicitly mark such
+  // variable template specializations inline.
+  if (isa(VD) && VD->isConstexpr())
+return GVA_DiscardableODR;
+
+  // Use ODR linkage for static data members of fully specialized templates
+  // to prevent duplicate definition errors with MSVC.
+  if (VD->isStaticDataMember())
+return GVA_StrongODR;
+}
+return StrongLinkage;
 
   case TSK_ExplicitInstantiationDefinition:
 return GVA_StrongODR;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62839: [clangd] Index API and implementations for relations

2019-06-11 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 204189.
nridge marked 9 inline comments as done.
nridge added a comment.

Address remaining review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62839

Files:
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/index/Index.cpp
  clang-tools-extra/clangd/index/Index.h
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/index/IndexAction.h
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/MemIndex.h
  clang-tools-extra/clangd/index/Merge.cpp
  clang-tools-extra/clangd/index/Merge.h
  clang-tools-extra/clangd/index/Relation.h
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/index/dex/Dex.cpp
  clang-tools-extra/clangd/index/dex/Dex.h
  clang-tools-extra/clangd/indexer/IndexerMain.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/DexTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/IndexActionTests.cpp
  clang-tools-extra/clangd/unittests/IndexTests.cpp

Index: clang-tools-extra/clangd/unittests/IndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexTests.cpp
@@ -119,8 +119,9 @@
   auto Token = std::make_shared();
   std::weak_ptr WeakToken = Token;
 
-  SwapIndex S(llvm::make_unique(
-  SymbolSlab(), RefSlab(), std::move(Token), /*BackingDataSize=*/0));
+  SwapIndex S(llvm::make_unique(SymbolSlab(), RefSlab(),
+  RelationSlab(), std::move(Token),
+  /*BackingDataSize=*/0));
   EXPECT_FALSE(WeakToken.expired());  // Current MemIndex keeps it alive.
   S.reset(llvm::make_unique()); // Now the MemIndex is destroyed.
   EXPECT_TRUE(WeakToken.expired());   // So the token is too.
@@ -132,12 +133,13 @@
   FuzzyFindRequest Req;
   Req.Query = "2";
   Req.AnyScope = true;
-  MemIndex I(Symbols, RefSlab());
+  MemIndex I(Symbols, RefSlab(), RelationSlab());
   EXPECT_THAT(match(I, Req), ElementsAre("2"));
 }
 
 TEST(MemIndexTest, MemIndexLimitedNumMatches) {
-  auto I = MemIndex::build(generateNumSymbols(0, 100), RefSlab());
+  auto I =
+  MemIndex::build(generateNumSymbols(0, 100), RefSlab(), RelationSlab());
   FuzzyFindRequest Req;
   Req.Query = "5";
   Req.AnyScope = true;
@@ -152,7 +154,7 @@
 TEST(MemIndexTest, FuzzyMatch) {
   auto I = MemIndex::build(
   generateSymbols({"LaughingOutLoud", "LionPopulation", "LittleOldLady"}),
-  RefSlab());
+  RefSlab(), RelationSlab());
   FuzzyFindRequest Req;
   Req.Query = "lol";
   Req.AnyScope = true;
@@ -162,8 +164,8 @@
 }
 
 TEST(MemIndexTest, MatchQualifiedNamesWithoutSpecificScope) {
-  auto I =
-  MemIndex::build(generateSymbols({"a::y1", "b::y2", "y3"}), RefSlab());
+  auto I = MemIndex::build(generateSymbols({"a::y1", "b::y2", "y3"}), RefSlab(),
+   RelationSlab());
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.AnyScope = true;
@@ -171,8 +173,8 @@
 }
 
 TEST(MemIndexTest, MatchQualifiedNamesWithGlobalScope) {
-  auto I =
-  MemIndex::build(generateSymbols({"a::y1", "b::y2", "y3"}), RefSlab());
+  auto I = MemIndex::build(generateSymbols({"a::y1", "b::y2", "y3"}), RefSlab(),
+   RelationSlab());
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {""};
@@ -181,7 +183,8 @@
 
 TEST(MemIndexTest, MatchQualifiedNamesWithOneScope) {
   auto I = MemIndex::build(
-  generateSymbols({"a::y1", "a::y2", "a::x", "b::y2", "y3"}), RefSlab());
+  generateSymbols({"a::y1", "a::y2", "a::x", "b::y2", "y3"}), RefSlab(),
+  RelationSlab());
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {"a::"};
@@ -190,7 +193,8 @@
 
 TEST(MemIndexTest, MatchQualifiedNamesWithMultipleScopes) {
   auto I = MemIndex::build(
-  generateSymbols({"a::y1", "a::y2", "a::x", "b::y3", "y3"}), RefSlab());
+  generateSymbols({"a::y1", "a::y2", "a::x", "b::y3", "y3"}), RefSlab(),
+  RelationSlab());
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {"a::", "b::"};
@@ -198,7 +202,8 @@
 }
 
 TEST(MemIndexTest, NoMatchNestedScopes) {
-  auto I = MemIndex::build(generateSymbols({"a::y1", "a::b::y2"}), RefSlab());
+  auto I = MemIndex::build(generateSymbols({"a::y1", "a::b::y2"}), RefSlab(),
+   RelationSlab());
   FuzzyFindRequest Req;
   Req.Query = "y";
   Req.Scopes = {"a::"};
@@ -206,7 +211,8 @@
 }
 
 TEST(MemIndexTest, IgnoreCases) {
-  auto I = MemIndex::build(generateSymbols({"ns::ABC", 

[PATCH] D62839: [clangd] Index API and implementations for relations

2019-06-11 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/index/FileIndex.cpp:250
   Path, llvm::make_unique(std::move(Symbols)),
-  llvm::make_unique(), /*CountReferences=*/false);
+  llvm::make_unique(), llvm::make_unique(),
+  /*CountReferences=*/false);

kadircet wrote:
> I think we need to pass relationslab in here. Since we might miss relations 
> like the following that are outside the main file:
> ```
> class A {};
> class B : public A {};
> ```
> Would be glad if you could prove me right/wrong with a unittest as well.
You are right! Fixed, and added a test to FileIndexTests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62839



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


[PATCH] D63174: [clang][NewPM] Add RUNS for tests that produce slightly different IR under new PM

2019-06-11 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: chandlerc, echristo, phosek, serge-sans-paille.
leonardchan added a project: clang.
Herald added subscribers: dmgreen, Anastasia.

With the new pass manager enabled by default, some tests produce slightly 
different IR from the legacy PM. This patch just adds separate new PM runs and 
checks for the new PM IR.

This fixes:

  Clang :: CodeGen/avx512-reduceMinMaxIntrin.c
  Clang :: CodeGen/avx512f-builtins.c
  Clang :: CodeGen/avx512vl-builtins.c
  Clang :: CodeGen/avx512vlbw-builtins.c
  Clang :: CodeGenOpenCL/convergent.cl

For `CodeGenOpenCL/convergent.cl`, the new PM produced a slightly different for 
loop, but this still checks for no loop unrolling as intended.

For the avx-builtins tests, the new PM would produce extra bitcasts that did 
not affect the overall logic of the function, but I do not know a simple way to 
get rid of these bitcasts.

For `CodeGen/avx512-reduceMinMaxIntrin.c`, temporary local variables are 
produced in the codegen, but the allocas are out of order and the tests were 
pretty strict on order even though the logic/use of these variables was the 
same. Nearly all checks in this large file were broken, so I was hoping we 
could  run it with legacy only for now and come back to it later to make this 
easier.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63174

Files:
  clang/test/CodeGen/avx512-reduceMinMaxIntrin.c
  clang/test/CodeGen/avx512f-builtins.c
  clang/test/CodeGen/avx512vl-builtins.c
  clang/test/CodeGen/avx512vlbw-builtins.c
  clang/test/CodeGenOpenCL/convergent.cl

Index: clang/test/CodeGenOpenCL/convergent.cl
===
--- clang/test/CodeGenOpenCL/convergent.cl
+++ clang/test/CodeGenOpenCL/convergent.cl
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - | opt -instnamer -S | FileCheck -enable-var-scope %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - -fno-experimental-new-pass-manager | opt -instnamer -S | FileCheck -enable-var-scope %s --check-prefixes=CHECK,CHECK-LEGACY
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - -fexperimental-new-pass-manager | opt -instnamer -S | FileCheck -enable-var-scope %s --check-prefixes=CHECK,CHECK-NEWPM
 
 // This is initially assumed convergent, but can be deduced to not require it.
 
@@ -117,7 +118,12 @@
 // CHECK: [[for_body]]:
 // CHECK:  tail call spir_func void @nodupfun() #[[attr5:[0-9]+]]
 // CHECK-NOT: call spir_func void @nodupfun()
-// CHECK:  br i1 %{{.+}}, label %[[for_body]], label %[[for_cond_cleanup]]
+
+// The new PM produces a slightly different IR for the loop from the legacy PM,
+// but the test still checks that the loop is not unrolled.
+// CHECK-LEGACY:  br i1 %{{.+}}, label %[[for_body]], label %[[for_cond_cleanup]]
+// CHECK-NEW: br i1 %{{.+}}, label %[[for_body_crit_edge:.+]], label %[[for_cond_cleanup]]
+// CHECK-NEW: [[for_body_crit_edge]]:
 
 void test_not_unroll() {
   for (int i = 0; i < 10; i++)
Index: clang/test/CodeGen/avx512vlbw-builtins.c
===
--- clang/test/CodeGen/avx512vlbw-builtins.c
+++ clang/test/CodeGen/avx512vlbw-builtins.c
@@ -1,6 +1,10 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding %s -fno-experimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding %s -fno-experimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// There are a few cases where instead accpeting the result of an instruction
+// directly as an argument to a select, it instead goes through some bitcasts.
+// RUN: %clang_cc1 -ffreestanding %s -fexperimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
+// RUN: %clang_cc1 -ffreestanding %s -fexperimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
 
 #include 
 
@@ -901,6 +905,8 @@
   // CHECK: [[SUB:%.*]] = sub <16 x i8> zeroinitializer, [[A:%.*]]
   // CHECK: [[CMP:%.*]] = icmp sgt <16 x i8> [[A]], zeroinitializer
   // CHECK: [[SEL:%.*]] = select <16 x i1> [[CMP]], <16 x i8> [[A]], <16 x i8> [[SUB]]
+  // CHECK-NEWPM: [[TMP:%.*]] = bitcast 

Re: r363086 - For DR712: store on a DeclRefExpr whether it constitutes an odr-use.

2019-06-11 Thread Reid Kleckner via cfe-commits
The new assert is firing across Chromium, please fix or revert. This is a
reduced test case:

int a;
struct Foo {
  template  void operator()(b, c = a);
};
Foo d;
bool e;
decltype(d(e)) gv;

This causes the "missing non-odr-use marking for unevaluated decl ref"
assertion on SemaExpr.cpp:16227 to fire.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60974: Clang IFSO driver action.

2019-06-11 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 3 inline comments as done.
plotfi added a comment.

In D60974#1534662 , @rupprecht wrote:

> Can you upload this patch with context? Either use arc or upload w/ -U9


Thanks for the review.

> I seem to have a lot of comments, but they're all nits -- my major concern 
> being the `llvm_unreachable`s should be errors instead (i.e. should be 
> triggered in release builds).
> 
> Since this is clearly labeled as experimental, I think you should feel free 
> to commit if you can get another lgtm (@compnerd?)






Comment at: clang/lib/Driver/ToolChains/Clang.cpp:3614-3616
+  Args.hasArg(options::OPT_iterface_stub_version_EQ)
+  ? Args.getLastArgValue(options::OPT_iterface_stub_version_EQ)
+  : "")

rupprecht wrote:
> `Args.getLastArgValue(options::OPT_iterface_stub_version_EQ)` should already 
> default to returning the empty string if unset (note the default param)
But what if it is set to something that's not either experimental-yaml-elf-v1 
or experimental-tapi-elf-v1? This was to truncate any values that aren't those 
two to "" so that the error check could just be if (StubFormat.empty()). Maybe 
something other than a string switch would have been more explicit. 



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1688
+  if (!ProgramActionPair.second)
+llvm_unreachable("Must specify a valid interface stub format.");
+  Opts.ProgramAction = ProgramActionPair.first;

rupprecht wrote:
> I think this is very much reachable if someone provides 
> `--interface-stub-version=x`
AH yes, you are right. This should probably be a diag. 
(clang/test/InterfaceStubs/bad-format.cpp tests for this "unreachable").



Comment at: clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp:41
+  return true;
+if (Symbols.find(ND) != Symbols.end())
+  return true;

rupprecht wrote:
> llvm::is_contained(Symbols, ND)
llvm::is_contained does not appear to work with std::map. I will try to figure 
out why. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-06-11 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 204187.
plotfi marked 11 inline comments as done.
plotfi added a comment.

addressing @rupprecht's feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/hidden-class-inheritance.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-DAG:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-DAG:   - Name:_Z8weakFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_WEAK
+// CHECK-YAML-DAG:   - Name:_Z10strongFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS-DAG: _Z10strongFuncv
+// CHECK-SYMBOLS-DAG: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK-DAG: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK-DAG: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS-DAG: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+#define HIDDEN  __attribute__((__visibility__(("hidden"
+#define DEFAULT __attribute__((__visibility__(("default"
+
+// CHECK-TAPI-NOT: _ZNK1Q5func1Ev
+// CHECK-TAPI-NOT: 

[PATCH] D62611: [analyzer][Dominators] Add unittests

2019-06-11 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Ping.


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

https://reviews.llvm.org/D62611



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


[PATCH] D63164: [HIP] Add option to force lambda nameing following ODR in HIP/CUDA.

2019-06-11 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

So, in short, what you're saying is that lambda type may leak into the mangled 
name of a `__global__` function and ne need to ensure that the mangled name is 
identical for both host and device, hence the need for consistent naming of 
lambdas.

If that's the case, shouldn't it be enabled for CUDA/HIP by default? While it's 
not frequently used ATM, it is something we do want to work correctly all the 
time. The failure to do so results in weird runtime failures that would be hard 
to debug for end-users.

@rsmith -- are there any downsides having this enabled all the time?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63164



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


[PATCH] D63170: [clang][NewPM] Fix broken -O0 test from missing assumptions

2019-06-11 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 204174.
Herald added subscribers: dexonsmith, steven_wu, mehdi_amini.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63170

Files:
  clang/test/CodeGen/lto-newpm-pipeline.c
  llvm/lib/Transforms/IPO/AlwaysInliner.cpp


Index: llvm/lib/Transforms/IPO/AlwaysInliner.cpp
===
--- llvm/lib/Transforms/IPO/AlwaysInliner.cpp
+++ llvm/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -31,8 +31,17 @@
 
 #define DEBUG_TYPE "inline"
 
-PreservedAnalyses AlwaysInlinerPass::run(Module , ModuleAnalysisManager &) {
-  InlineFunctionInfo IFI;
+PreservedAnalyses AlwaysInlinerPass::run(Module ,
+ ModuleAnalysisManager ) {
+  // Add inline assumptions during code generation.
+  FunctionAnalysisManager  =
+  MAM.getResult(M).getManager();
+  std::function GetAssumptionCache =
+  [&](Function ) -> AssumptionCache & {
+return FAM.getResult(F);
+  };
+  InlineFunctionInfo IFI(/*cg=*/nullptr, );
+
   SmallSetVector Calls;
   bool Changed = false;
   SmallVector InlinedFunctions;
Index: clang/test/CodeGen/lto-newpm-pipeline.c
===
--- clang/test/CodeGen/lto-newpm-pipeline.c
+++ clang/test/CodeGen/lto-newpm-pipeline.c
@@ -27,6 +27,7 @@
 
 // CHECK-FULL-O0: Starting llvm::Module pass manager run.
 // CHECK-FULL-O0: Running pass: AlwaysInlinerPass
+// CHECK-FULL-O0-NEXT: Running analysis: InnerAnalysisManagerProxy
 // CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-FULL-O0-NEXT: Running pass: NameAnonGlobalPass
 // CHECK-FULL-O0-NEXT: Running pass: BitcodeWriterPass
@@ -34,6 +35,7 @@
 
 // CHECK-THIN-O0: Starting llvm::Module pass manager run.
 // CHECK-THIN-O0: Running pass: AlwaysInlinerPass
+// CHECK-THIN-O0-NEXT: Running analysis: InnerAnalysisManagerProxy
 // CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass
 // CHECK-THIN-O0-NEXT: Running pass: ThinLTOBitcodeWriterPass


Index: llvm/lib/Transforms/IPO/AlwaysInliner.cpp
===
--- llvm/lib/Transforms/IPO/AlwaysInliner.cpp
+++ llvm/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -31,8 +31,17 @@
 
 #define DEBUG_TYPE "inline"
 
-PreservedAnalyses AlwaysInlinerPass::run(Module , ModuleAnalysisManager &) {
-  InlineFunctionInfo IFI;
+PreservedAnalyses AlwaysInlinerPass::run(Module ,
+ ModuleAnalysisManager ) {
+  // Add inline assumptions during code generation.
+  FunctionAnalysisManager  =
+  MAM.getResult(M).getManager();
+  std::function GetAssumptionCache =
+  [&](Function ) -> AssumptionCache & {
+return FAM.getResult(F);
+  };
+  InlineFunctionInfo IFI(/*cg=*/nullptr, );
+
   SmallSetVector Calls;
   bool Changed = false;
   SmallVector InlinedFunctions;
Index: clang/test/CodeGen/lto-newpm-pipeline.c
===
--- clang/test/CodeGen/lto-newpm-pipeline.c
+++ clang/test/CodeGen/lto-newpm-pipeline.c
@@ -27,6 +27,7 @@
 
 // CHECK-FULL-O0: Starting llvm::Module pass manager run.
 // CHECK-FULL-O0: Running pass: AlwaysInlinerPass
+// CHECK-FULL-O0-NEXT: Running analysis: InnerAnalysisManagerProxy
 // CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-FULL-O0-NEXT: Running pass: NameAnonGlobalPass
 // CHECK-FULL-O0-NEXT: Running pass: BitcodeWriterPass
@@ -34,6 +35,7 @@
 
 // CHECK-THIN-O0: Starting llvm::Module pass manager run.
 // CHECK-THIN-O0: Running pass: AlwaysInlinerPass
+// CHECK-THIN-O0-NEXT: Running analysis: InnerAnalysisManagerProxy
 // CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass
 // CHECK-THIN-O0-NEXT: Running pass: ThinLTOBitcodeWriterPass
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-06-11 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

See also: https://github.com/ClangBuiltLinux/linux/issues/520


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963



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


[PATCH] D62750: Show note for -Wmissing-prototypes for functions with parameters

2019-06-11 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert updated this revision to Diff 204171.
aaronpuchert added a comment.

Add checks that we don't emit the fix-it when we shouldn't.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62750

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  test/Sema/warn-missing-prototypes.c

Index: test/Sema/warn-missing-prototypes.c
===
--- test/Sema/warn-missing-prototypes.c
+++ test/Sema/warn-missing-prototypes.c
@@ -1,7 +1,8 @@
 // RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wmissing-prototypes -verify %s
 // RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wmissing-prototypes -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
-int f();
+int f(); // expected-note{{this declaration is not a prototype; add parameter declarations to make it one}}
+// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:{{.*}}-[[@LINE-1]]:{{.*}}}:"{{.*}}"
 
 int f(int x) { return x; } // expected-warning{{no previous prototype for function 'f'}}
 
@@ -15,7 +16,8 @@
 
 void test(void);
 
-int h3();
+int h3(); // expected-note{{this declaration is not a prototype; add parameter declarations to make it one}}
+// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:{{.*}}-[[@LINE-1]]:{{.*}}}:"{{.*}}"
 int h4(int);
 int h4();
 
@@ -38,6 +40,5 @@
 int main(void) { return 0; }
 
 void not_a_prototype_test(); // expected-note{{this declaration is not a prototype; add 'void' to make it a prototype for a zero-parameter function}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:27-[[@LINE-1]]:27}:"void"
 void not_a_prototype_test() { } // expected-warning{{no previous prototype for function 'not_a_prototype_test'}}
-
-// CHECK: fix-it:"{{.*}}":{40:27-40:27}:"void"
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -12747,8 +12747,9 @@
   Consumer.HandleInlineFunctionDefinition(D);
 }
 
-static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
- const FunctionDecl*& PossibleZeroParamPrototype) {
+static bool
+ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
+const FunctionDecl *) {
   // Don't warn about invalid declarations.
   if (FD->isInvalidDecl())
 return false;
@@ -12785,7 +12786,6 @@
   if (FD->isDeleted())
 return false;
 
-  bool MissingPrototype = true;
   for (const FunctionDecl *Prev = FD->getPreviousDecl();
Prev; Prev = Prev->getPreviousDecl()) {
 // Ignore any declarations that occur in function or method
@@ -12793,13 +12793,11 @@
 if (Prev->getLexicalDeclContext()->isFunctionOrMethod())
   continue;
 
-MissingPrototype = !Prev->getType()->isFunctionProtoType();
-if (FD->getNumParams() == 0)
-  PossibleZeroParamPrototype = Prev;
-break;
+PossiblePrototype = Prev;
+return Prev->getType()->isFunctionNoProtoType();
   }
 
-  return MissingPrototype;
+  return true;
 }
 
 void
@@ -13319,21 +13317,22 @@
 //   prototype declaration. This warning is issued even if the
 //   definition itself provides a prototype. The aim is to detect
 //   global functions that fail to be declared in header files.
-const FunctionDecl *PossibleZeroParamPrototype = nullptr;
-if (ShouldWarnAboutMissingPrototype(FD, PossibleZeroParamPrototype)) {
+const FunctionDecl *PossiblePrototype = nullptr;
+if (ShouldWarnAboutMissingPrototype(FD, PossiblePrototype)) {
   Diag(FD->getLocation(), diag::warn_missing_prototype) << FD;
 
-  if (PossibleZeroParamPrototype) {
+  if (PossiblePrototype) {
 // We found a declaration that is not a prototype,
 // but that could be a zero-parameter prototype
-if (TypeSourceInfo *TI =
-PossibleZeroParamPrototype->getTypeSourceInfo()) {
+if (TypeSourceInfo *TI = PossiblePrototype->getTypeSourceInfo()) {
   TypeLoc TL = TI->getTypeLoc();
   if (FunctionNoProtoTypeLoc FTL = TL.getAs())
-Diag(PossibleZeroParamPrototype->getLocation(),
+Diag(PossiblePrototype->getLocation(),
  diag::note_declaration_not_a_prototype)
-<< PossibleZeroParamPrototype
-<< FixItHint::CreateInsertion(FTL.getRParenLoc(), "void");
+<< (FD->getNumParams() != 0)
+<< (FD->getNumParams() == 0
+? FixItHint::CreateInsertion(FTL.getRParenLoc(), "void")
+: FixItHint{});
 }
   }
 
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -4661,7 +4661,8 @@
   "no previous prototype for function %0">,
   InGroup>, DefaultIgnore;
 def note_declaration_not_a_prototype : Note<
-  "this declaration 

[PATCH] D63170: [clang][NewPM] Fix broken -O0 test from missing assumptions

2019-06-11 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: chandlerc, echristo, phosek, serge-sans-paille.
leonardchan added a project: clang.
Herald added subscribers: llvm-commits, hiraditya, eraman.
Herald added a project: LLVM.
leonardchan added a parent revision: D62225: [clang][NewPM] Fixing -O0 tests 
that are broken under new PM.

Add an AssumptionCache callback to the InlineFuntionInfo used for the 
AlwaysInlinerPass to match codegen of the AlwaysInlinerLegacyPass to generate 
llvm.assume. This fixes `CodeGen/builtin-movdir.c` when new PM is enabled by 
default.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63170

Files:
  llvm/lib/Transforms/IPO/AlwaysInliner.cpp


Index: llvm/lib/Transforms/IPO/AlwaysInliner.cpp
===
--- llvm/lib/Transforms/IPO/AlwaysInliner.cpp
+++ llvm/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -31,8 +31,17 @@
 
 #define DEBUG_TYPE "inline"
 
-PreservedAnalyses AlwaysInlinerPass::run(Module , ModuleAnalysisManager &) {
-  InlineFunctionInfo IFI;
+PreservedAnalyses AlwaysInlinerPass::run(Module ,
+ ModuleAnalysisManager ) {
+  // Add inline assumptions during code generation.
+  FunctionAnalysisManager  =
+  MAM.getResult(M).getManager();
+  std::function GetAssumptionCache =
+  [&](Function ) -> AssumptionCache & {
+return FAM.getResult(F);
+  };
+  InlineFunctionInfo IFI(/*cg=*/nullptr, );
+
   SmallSetVector Calls;
   bool Changed = false;
   SmallVector InlinedFunctions;


Index: llvm/lib/Transforms/IPO/AlwaysInliner.cpp
===
--- llvm/lib/Transforms/IPO/AlwaysInliner.cpp
+++ llvm/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -31,8 +31,17 @@
 
 #define DEBUG_TYPE "inline"
 
-PreservedAnalyses AlwaysInlinerPass::run(Module , ModuleAnalysisManager &) {
-  InlineFunctionInfo IFI;
+PreservedAnalyses AlwaysInlinerPass::run(Module ,
+ ModuleAnalysisManager ) {
+  // Add inline assumptions during code generation.
+  FunctionAnalysisManager  =
+  MAM.getResult(M).getManager();
+  std::function GetAssumptionCache =
+  [&](Function ) -> AssumptionCache & {
+return FAM.getResult(F);
+  };
+  InlineFunctionInfo IFI(/*cg=*/nullptr, );
+
   SmallSetVector Calls;
   bool Changed = false;
   SmallVector InlinedFunctions;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62738: [HIP] Support texture type

2019-06-11 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

So, the only thing this patch appears to do is make everything with this 
attribute uninitialized on device side and give protected visibility.
If I understand it correctly, you're using the attribute in order to construct 
something that's sort of opposite of the currently used __device__ vars with 
host-side shadows. Only now the real variable lives on the host side and it's 
device side that gets the 'shadow' copy. Do I understand it correctly?

If so, then this functionality seems to be fairly general-purpose to me. I.e. 
it has literally nothing to do with textures other than the name.

Perhaps it would make more sense to rename this attribute to something along 
the lines of 'device_referenceable' and bring its implementation to somewhat 
more complete shape.

By 'complete' I mean that it would be great to flesh out what can and can't use 
the attribute. Does it have to be a type attribute, or can it be applied to 
variables? 
The example in the patch suggests that it's the *variable* that's affected by 
the attribute.

Once it works, HIP's texture support can use it for its purposes.

E.g. your example could look like this:

  #define  __attribute__((device_builtin_texture_type)) __texture__
  
  template 
  struct  texture
: public textureReference { ... }
  
  __texture__ texture tex;

This way compiler does not need to deal with the details of texture 
implementation on the HIP side.
Host/device visibility of the variables is easy to see in the source (similar 
to __device__, __shared__, etc) and there will be no need to dig into template 
defined somewhere else to become aware of this.
It will be potentially useful beyond HIP-only texture implementation.

What do you think?


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

https://reviews.llvm.org/D62738



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


[PATCH] D63168: [clang][NewPM] Fix

2019-06-11 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: chandlerc, echristo, phosek, serge-sans-paille.
leonardchan added a project: clang.
Herald added a subscriber: aprantl.

This contains the part of D62225  which fixes 
CodeGen/split-debug-single-file.c by not placing .dwo sections when using 
`-enable-split-dwarf=split`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63168

Files:
  clang/lib/CodeGen/BackendUtil.cpp


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1275,7 +1275,8 @@
 NeedCodeGen = true;
 CodeGenPasses.add(
 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
-if (!CodeGenOpts.SplitDwarfFile.empty()) {
+if (!CodeGenOpts.SplitDwarfFile.empty() &&
+CodeGenOpts.getSplitDwarfMode() == CodeGenOptions::SplitFileFission) {
   DwoOS = openOutputFile(CodeGenOpts.SplitDwarfFile);
   if (!DwoOS)
 return;


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1275,7 +1275,8 @@
 NeedCodeGen = true;
 CodeGenPasses.add(
 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
-if (!CodeGenOpts.SplitDwarfFile.empty()) {
+if (!CodeGenOpts.SplitDwarfFile.empty() &&
+CodeGenOpts.getSplitDwarfMode() == CodeGenOptions::SplitFileFission) {
   DwoOS = openOutputFile(CodeGenOpts.SplitDwarfFile);
   if (!DwoOS)
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59673: [Clang] Harmonize Split DWARF options with llc

2019-06-11 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert marked 2 inline comments as done.
aaronpuchert added a comment.

In D59673#1521413 , @dblaikie wrote:

> Might be easier as a few patches - renaming the existing option,


D63130 

> adding the new one,

This change.

> then removing the single split dwarf flag handling in favor of implying that 
> by the absence of an output file name. (if I'm reading what this patch does)

D63167 


Repository:
  rC Clang

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

https://reviews.llvm.org/D59673



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


[PATCH] D63167: [Clang] Remove obsolete -enable-split-dwarf={single,split}

2019-06-11 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert created this revision.
aaronpuchert added reviewers: dblaikie, echristo.
aaronpuchert added a project: clang.
Herald added a subscriber: aprantl.

The changes in D59673  make the choice 
redundant, since we can achieve
single-file split DWARF just by not setting an output file name.
This behavior can also be observed with llc.


Repository:
  rC Clang

https://reviews.llvm.org/D63167

Files:
  include/clang/Basic/CodeGenOptions.def
  include/clang/Basic/CodeGenOptions.h
  include/clang/Driver/CC1Options.td
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/split-debug-single-file.c
  test/Driver/split-debug.c

Index: test/Driver/split-debug.c
===
--- test/Driver/split-debug.c
+++ test/Driver/split-debug.c
@@ -13,7 +13,7 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=single -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS-SINGLE-SPLIT < %t %s
 //
-// CHECK-ACTIONS-SINGLE-SPLIT: "-enable-split-dwarf=single"
+// CHECK-ACTIONS-SINGLE-SPLIT: "-enable-split-dwarf"
 // CHECK-ACTIONS-SINGLE-SPLIT: "-split-dwarf-file" "split-debug.o"
 // CHECK-ACTIONS-SINGLE-SPLIT-NOT: "-split-dwarf-output"
 
Index: test/CodeGen/split-debug-single-file.c
===
--- test/CodeGen/split-debug-single-file.c
+++ test/CodeGen/split-debug-single-file.c
@@ -1,14 +1,15 @@
 // REQUIRES: x86-registered-target
 
-// Testing to ensure -enable-split-dwarf=single allows to place .dwo sections into regular output object.
+// Testing to ensure that setting only -split-dwarf-file allows to place .dwo sections into regular output object.
 //  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
-//  RUN:   -enable-split-dwarf=single -split-dwarf-file %t.o -emit-obj -o %t.o %s
+//  RUN:   -enable-split-dwarf -split-dwarf-file %t.o -emit-obj -o %t.o %s
 //  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SINGLE %s
 //  MODE-SINGLE: .dwo
 
-// Testing to ensure -enable-split-dwarf=split does not place .dwo sections into regular output object.
+// Testing to ensure that setting both -split-dwarf-file and -split-dwarf-output
+// does not place .dwo sections into regular output object.
 //  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
-//  RUN:   -enable-split-dwarf=split -split-dwarf-file %t.dwo -split-dwarf-output %t.dwo -emit-obj -o %t.o %s
+//  RUN:   -enable-split-dwarf -split-dwarf-file %t.dwo -split-dwarf-output %t.dwo -emit-obj -o %t.o %s
 //  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SPLIT %s
 //  MODE-SPLIT-NOT: .dwo
 
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -723,26 +723,10 @@
   Opts.MacroDebugInfo = Args.hasArg(OPT_debug_info_macro);
   Opts.WholeProgramVTables = Args.hasArg(OPT_fwhole_program_vtables);
   Opts.LTOVisibilityPublicStd = Args.hasArg(OPT_flto_visibility_public_std);
+  Opts.EnableSplitDwarf = Args.hasArg(OPT_enable_split_dwarf);
   Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
   Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output);
   Opts.SplitDwarfInlining = !Args.hasArg(OPT_fno_split_dwarf_inlining);
-
-  if (Arg *A =
-  Args.getLastArg(OPT_enable_split_dwarf, OPT_enable_split_dwarf_EQ)) {
-if (A->getOption().matches(options::OPT_enable_split_dwarf)) {
-  Opts.setSplitDwarfMode(CodeGenOptions::SplitFileFission);
-} else {
-  StringRef Name = A->getValue();
-  if (Name == "single")
-Opts.setSplitDwarfMode(CodeGenOptions::SingleFileFission);
-  else if (Name == "split")
-Opts.setSplitDwarfMode(CodeGenOptions::SplitFileFission);
-  else
-Diags.Report(diag::err_drv_invalid_value)
-<< A->getAsString(Args) << Name;
-}
-  }
-
   Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs);
   Opts.DebugExplicitImport = Args.hasArg(OPT_dwarf_explicit_import);
   Opts.DebugFwdTemplateParams = Args.hasArg(OPT_debug_forward_template_params);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3294,12 +3294,8 @@
 if (!SplitDWARFInlining)
   CmdArgs.push_back("-fno-split-dwarf-inlining");
 
-if (DwarfFission != DwarfFissionKind::None) {
-  if (DwarfFission == DwarfFissionKind::Single)
-CmdArgs.push_back("-enable-split-dwarf=single");
-  else
-CmdArgs.push_back("-enable-split-dwarf");
-}
+if (DwarfFission != DwarfFissionKind::None)
+  CmdArgs.push_back("-enable-split-dwarf");
   }
 
   // After we've dealt with all combinations of things that 

[PATCH] D63010: [OpenMP] Add task alloc function

2019-06-11 Thread Alexandre Eichenberger via Phabricator via cfe-commits
AlexEichenberger accepted this revision.
AlexEichenberger added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rOMP OpenMP

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

https://reviews.llvm.org/D63010



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


[PATCH] D62437: [clang-tidy] Splits fuchsia-default-arguments

2019-06-11 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 204157.
DiegoAstiazaran added a comment.

Improve format of documentation in ReleaseNotes.


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

https://reviews.llvm.org/D62437

Files:
  clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp
  clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h
  clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp
  clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCheck.h
  clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp
  clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h
  clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst
  
clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst
  clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-calls.cpp
  clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-declarations.cpp
  clang-tools-extra/test/clang-tidy/fuchsia-default-arguments.cpp

Index: clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-declarations.cpp
===
--- clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-declarations.cpp
+++ clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-declarations.cpp
@@ -1,26 +1,15 @@
-// RUN: %check_clang_tidy %s fuchsia-default-arguments %t
+// RUN: %check_clang_tidy %s fuchsia-default-arguments-declarations %t
 
 int foo(int value = 5) { return value; }
-// CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
+// CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
 // CHECK-FIXES: int foo(int value) { return value; }
 
-int f() {
-  foo();
-  // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments]
-  // CHECK-NOTES: [[@LINE-7]]:9: note: default parameter was declared here
-}
-
 int bar(int value) { return value; }
 
-int n() {
-  foo(0);
-  bar(0);
-}
-
 class Baz {
 public:
   int a(int value = 5) { return value; }
-  // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
+  // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
   // CHECK-FIXES: int a(int value) { return value; }
 
   int b(int value) { return value; }
@@ -29,7 +18,7 @@
 class Foo {
   // Fix should be suggested in declaration
   int a(int value = 53);
-  // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
+  // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
   // CHECK-FIXES: int a(int value);
 };
 
@@ -40,7 +29,7 @@
 
 // Elided functions
 void f(int = 5) {};
-// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
+// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
 // CHECK-FIXES: void f(int) {};
 
 void g(int) {};
@@ -49,12 +38,12 @@
 #define D(val) = val
 
 void h(int i D(5));
-// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
+// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
 // CHECK-FIXES-NOT: void h(int i);
 
 void x(int i);
 void x(int i = 12);
-// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
+// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
 // CHECK-FIXES: void x(int i);
 
 void x(int i) {}
@@ -64,17 +53,5 @@
 };
 
 void S::x(int i = 12) {}
-// CHECK-NOTES: [[@LINE-1]]:11: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
+// CHECK-NOTES: [[@LINE-1]]:11: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
 // CHECK-FIXES: void S::x(int i) {}
-
-int main() {
-  S s;
-  s.x();
-  // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments]
-  // CHECK-NOTES: 

[PATCH] D62738: [HIP] Support texture type

2019-06-11 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 204155.
yaxunl marked 5 inline comments as done.
yaxunl added a comment.

Revised by Artem's comments.


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

https://reviews.llvm.org/D62738

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/AST/TypePrinter.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/AST/ast-dump-cuda-texture.cu
  test/CodeGenCUDA/texture.cu
  test/SemaCUDA/attr-declspec.cu
  test/SemaCUDA/attributes-on-non-cuda.cu

Index: test/SemaCUDA/attributes-on-non-cuda.cu
===
--- test/SemaCUDA/attributes-on-non-cuda.cu
+++ test/SemaCUDA/attributes-on-non-cuda.cu
@@ -7,11 +7,12 @@
 // RUN: %clang_cc1 -DEXPECT_WARNINGS -fsyntax-only -verify -x c %s
 
 #if defined(EXPECT_WARNINGS)
-// expected-warning@+12 {{'device' attribute ignored}}
-// expected-warning@+12 {{'global' attribute ignored}}
-// expected-warning@+12 {{'constant' attribute ignored}}
-// expected-warning@+12 {{'shared' attribute ignored}}
-// expected-warning@+12 {{'host' attribute ignored}}
+// expected-warning@+13 {{'device' attribute ignored}}
+// expected-warning@+13 {{'global' attribute ignored}}
+// expected-warning@+13 {{'constant' attribute ignored}}
+// expected-warning@+13 {{'shared' attribute ignored}}
+// expected-warning@+13 {{'host' attribute ignored}}
+// expected-warning@+20 {{'device_builtin_texture_type' attribute ignored}}
 //
 // NOTE: IgnoredAttr in clang which is used for the rest of
 // attributes ignores LangOpts, so there are no warnings.
Index: test/SemaCUDA/attr-declspec.cu
===
--- test/SemaCUDA/attr-declspec.cu
+++ test/SemaCUDA/attr-declspec.cu
@@ -6,11 +6,12 @@
 // RUN: %clang_cc1 -DEXPECT_WARNINGS -fms-extensions -fsyntax-only -verify -x c %s
 
 #if defined(EXPECT_WARNINGS)
-// expected-warning@+12 {{'__device__' attribute ignored}}
-// expected-warning@+12 {{'__global__' attribute ignored}}
-// expected-warning@+12 {{'__constant__' attribute ignored}}
-// expected-warning@+12 {{'__shared__' attribute ignored}}
-// expected-warning@+12 {{'__host__' attribute ignored}}
+// expected-warning@+13 {{'__device__' attribute ignored}}
+// expected-warning@+13 {{'__global__' attribute ignored}}
+// expected-warning@+13 {{'__constant__' attribute ignored}}
+// expected-warning@+13 {{'__shared__' attribute ignored}}
+// expected-warning@+13 {{'__host__' attribute ignored}}
+// expected-warning@+19 {{'__device_builtin_texture_type__' attribute ignored}}
 //
 // (Currently we don't for the other attributes. They are implemented with
 // IgnoredAttr, which is ignored irrespective of any LangOpts.)
Index: test/CodeGenCUDA/texture.cu
===
--- /dev/null
+++ test/CodeGenCUDA/texture.cu
@@ -0,0 +1,28 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -std=c++11 -fcuda-is-device \
+// RUN: -emit-llvm -o - %s | FileCheck -check-prefixes=CUDADEV %s
+// RUN: %clang_cc1 -triple x86_64 -std=c++11 \
+// RUN: -emit-llvm -o - %s | FileCheck -check-prefixes=CUDAHOST %s
+
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 -fvisibility hidden -fapply-global-visibility-to-externs \
+// RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPDEV %s
+// RUN: %clang_cc1 -triple x86_64 -std=c++11 \
+// RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPHOST %s
+
+struct textureReference {
+  int a;
+};
+
+template 
+struct __attribute__((device_builtin_texture_type)) texture : public textureReference {
+texture() { a = 1; }
+};
+
+texture tex;
+// CUDADEV-NOT: @tex
+// CUDAHOST-NOT: call i32 @__hipRegisterVar{{.*}}@tex
+// HIPDEV: @tex = protected addrspace(1) global %struct.texture undef
+// HIPDEV-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev
+// HIPHOST:  define{{.*}}@_ZN7textureIfLi2ELi1EEC1Ev
+// HIPHOST:  call i32 @__hipRegisterVar{{.*}}@tex
Index: test/AST/ast-dump-cuda-texture.cu
===
--- /dev/null
+++ test/AST/ast-dump-cuda-texture.cu
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fcuda-is-device -ast-dump -ast-dump-filter texture %s | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -ast-dump -ast-dump-filter texture %s | FileCheck -strict-whitespace %s
+struct textureReference {
+  int a;
+};
+
+// CHECK: CUDADeviceBuiltinTextureTypeAttr
+template 
+struct __attribute__((device_builtin_texture_type)) texture : public textureReference {
+texture() { a = 1; }
+};
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6786,6 +6786,9 @@
   case ParsedAttr::AT_CUDAHost:
 handleSimpleAttributeWithExclusions(S, D, AL);
 break;
+  case 

[PATCH] D63012: Use fully qualified name when printing S_CONSTANT records

2019-06-11 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63012



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


[PATCH] D62970: [clang-doc] De-duplicate comments and locations

2019-06-11 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran marked 4 inline comments as done.
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/Representation.cpp:124
+  for (auto  : Other.Description) {
+bool IsCommentUnique = std::find(Description.begin(), Description.end(),
+ Comment) == Description.end();

jakehehrlich wrote:
> juliehockett wrote:
> > ```if (std::find(Description.begin(), Description.end(), Comment) == 
> > Description.end())
> >   Description.emplace_back(std::move(Comment));```
> Instead of deduping like this can we just make Description a set?
The YAML generator uses an llvm method that doesn't support sets, so changing 
Description to a set would break that.
Talking with Julie we decided to de-duplicate with sort and unique.


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

https://reviews.llvm.org/D62970



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


[PATCH] D63164: [HIP] Add option to force lambda nameing following ODR in HIP/CUDA.

2019-06-11 Thread Michael Liao via Phabricator via cfe-commits
hliao created this revision.
hliao added reviewers: tra, yaxunl.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Clang follows its own scheme for lambdas which don't need to follow ODR rule. 
That scheme will assign an unqiue ID within the TU scope and won't be unique or 
consistent across TUs.
- In CUDA/HIP, a lambda with `__device__` or `__host__ __device__` (or an 
extended lambda) may be used in `__global__` template function instantiation. 
If that lambda cannot be named following ODR rule, the device compilation may 
produce a mismatching device kernel name from the host compilation as the 
anonymous type ID assignment aforementioned.
- In this patch, a new language option, `-fcuda-force-lambda-odr`, is 
introduced to force ODR for lambda naming so that all lambda could be 
consistently named across TUs, including the device compilation. This solves 
the assertion checking device kernel names as well as ensures the named-based 
resolution could resolve the correct device binaries from the device name 
generated in the host compilation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63164

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCUDA/unnamed-types.cu

Index: clang/test/CodeGenCUDA/unnamed-types.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/unnamed-types.cu
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++11 -x hip -triple x86_64-linux-gnu -fcuda-force-lambda-odr -emit-llvm %s -o - | FileCheck %s --check-prefix=HOST
+// RUN: %clang_cc1 -std=c++11 -x hip -triple amdgcn-amd-amdhsa -fcuda-force-lambda-odr -fcuda-is-device -emit-llvm %s -o - | FileCheck %s --check-prefix=DEVICE
+
+#include "Inputs/cuda.h"
+
+// HOST: @0 = private unnamed_addr constant [43 x i8] c"_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_\00", align 1
+
+__device__ float d0(float x) {
+  return [](float x) { return x + 2.f; }(x);
+}
+
+__device__ float d1(float x) {
+  return [](float x) { return x * 2.f; }(x);
+}
+
+// DEVICE: amdgpu_kernel void @_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_(
+template 
+__global__ void k0(float *p, F f) {
+  p[0] = f(p[0]) + d0(p[1]) + d1(p[2]);
+}
+
+void f0(float *p) {
+  [](float *p) {
+*p = 1.f;
+  }(p);
+}
+
+void f1(float *p) {
+  [](float *p) {
+k0<<<1,1>>>(p, [] __device__ (float x) { return x + 1.f; });
+  }(p);
+}
+// HOST: @__hip_register_globals
+// HOST: __hipRegisterFunction{{.*}}@_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_{{.*}}@0
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -272,9 +272,8 @@
   return false;
 }
 
-MangleNumberingContext *
-Sema::getCurrentMangleNumberContext(const DeclContext *DC,
-Decl *) {
+MangleNumberingContext *Sema::getCurrentMangleNumberContext(
+const DeclContext *DC, Decl *, bool SkpNoODRChk) {
   // Compute the context for allocating mangling numbers in the current
   // expression, if the ABI requires them.
   ManglingContextDecl = ExprEvalContexts.back().ManglingContextDecl;
@@ -322,7 +321,8 @@
   case Normal: {
 //  -- the bodies of non-exported nonspecialized template functions
 //  -- the bodies of inline functions
-if ((IsInNonspecializedTemplate &&
+if (SkpNoODRChk ||
+(IsInNonspecializedTemplate &&
  !(ManglingContextDecl && isa(ManglingContextDecl))) ||
 isInInlineFunction(CurContext)) {
   ManglingContextDecl = nullptr;
@@ -337,7 +337,7 @@
 
   case StaticDataMember:
 //  -- the initializers of nonspecialized static members of template classes
-if (!IsInNonspecializedTemplate) {
+if (!SkpNoODRChk && !IsInNonspecializedTemplate) {
   ManglingContextDecl = nullptr;
   return nullptr;
 }
@@ -441,9 +441,9 @@
 Class->setLambdaMangling(Mangling->first, Mangling->second);
   } else {
 Decl *ManglingContextDecl;
-if (MangleNumberingContext *MCtx =
-getCurrentMangleNumberContext(Class->getDeclContext(),
-  ManglingContextDecl)) {
+if (MangleNumberingContext *MCtx = getCurrentMangleNumberContext(
+Class->getDeclContext(), ManglingContextDecl,
+getLangOpts().CUDAForceLambdaODR)) {
   unsigned ManglingNumber = MCtx->getManglingNumber(Method);
   Class->setLambdaMangling(ManglingNumber, ManglingContextDecl);
 }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2431,6 +2431,9 @@
   if (Args.hasArg(OPT_fno_cuda_host_device_constexpr))
 Opts.CUDAHostDeviceConstexpr = 0;
 
+  if 

[PATCH] D62970: [clang-doc] De-duplicate comments and locations

2019-06-11 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 204146.
DiegoAstiazaran retitled this revision from "[clang-doc] De-duplicate comments" 
to "[clang-doc] De-duplicate comments and locations".
DiegoAstiazaran edited the summary of this revision.
DiegoAstiazaran added a comment.
Herald added a subscriber: mgrang.

Change how the vectors are de-duplicated.
Add de-duplication of declaration locations.
Add tests.


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

https://reviews.llvm.org/D62970

Files:
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/MergeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/MergeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/MergeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/MergeTest.cpp
@@ -159,15 +159,37 @@
   One.IsMethod = true;
   One.Parent = Reference(EmptySID, "Parent", InfoType::IT_namespace);
 
+  One.Description.emplace_back();
+  auto OneFullComment = ();
+  OneFullComment->Kind = "FullComment";
+  auto OneParagraphComment = llvm::make_unique();
+  OneParagraphComment->Kind = "ParagraphComment";
+  auto OneTextComment = llvm::make_unique();
+  OneTextComment->Kind = "TextComment";
+  OneTextComment->Text = "This is a text comment.";
+  OneParagraphComment->Children.push_back(std::move(OneTextComment));
+  OneFullComment->Children.push_back(std::move(OneParagraphComment));
+
   FunctionInfo Two;
   Two.Name = "f";
   Two.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  Two.Loc.emplace_back(20, llvm::SmallString<16>{"test.cpp"});
+  Two.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   Two.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   Two.Params.emplace_back("int", "P");
 
+  Two.Description.emplace_back();
+  auto TwoFullComment = ();
+  TwoFullComment->Kind = "FullComment";
+  auto TwoParagraphComment = llvm::make_unique();
+  TwoParagraphComment->Kind = "ParagraphComment";
+  auto TwoTextComment = llvm::make_unique();
+  TwoTextComment->Kind = "TextComment";
+  TwoTextComment->Text = "This is a text comment.";
+  TwoParagraphComment->Children.push_back(std::move(TwoTextComment));
+  TwoFullComment->Children.push_back(std::move(TwoParagraphComment));
+
   std::vector> Infos;
   Infos.emplace_back(llvm::make_unique(std::move(One)));
   Infos.emplace_back(llvm::make_unique(std::move(Two)));
@@ -178,13 +200,23 @@
 
   Expected->DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
   Expected->Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
-  Expected->Loc.emplace_back(20, llvm::SmallString<16>{"test.cpp"});
 
   Expected->ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   Expected->Params.emplace_back("int", "P");
   Expected->IsMethod = true;
   Expected->Parent = Reference(EmptySID, "Parent", InfoType::IT_namespace);
 
+  Expected->Description.emplace_back();
+  auto ExpectedFullComment = >Description.back();
+  ExpectedFullComment->Kind = "FullComment";
+  auto ExpectedParagraphComment = llvm::make_unique();
+  ExpectedParagraphComment->Kind = "ParagraphComment";
+  auto ExpectedTextComment = llvm::make_unique();
+  ExpectedTextComment->Kind = "TextComment";
+  ExpectedTextComment->Text = "This is a text comment.";
+  ExpectedParagraphComment->Children.push_back(std::move(ExpectedTextComment));
+  ExpectedFullComment->Children.push_back(std::move(ExpectedParagraphComment));
+
   auto Actual = mergeInfos(Infos);
   assert(Actual);
   CheckFunctionInfo(InfoAsFunction(Expected.get()),
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -46,6 +46,41 @@
   CommentInfo() = default;
   CommentInfo(CommentInfo ) = delete;
   CommentInfo(CommentInfo &) = default;
+  CommentInfo =(CommentInfo &) = default;
+
+  bool operator==(const CommentInfo ) const {
+auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,
+SelfClosing, Explicit, AttrKeys, AttrValues, Args);
+auto SecondCI =
+std::tie(Other.Kind, Other.Text, Other.Name, Other.Direction,
+ Other.ParamName, Other.CloseName, Other.SelfClosing,
+ Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args);
+
+if (FirstCI != SecondCI || Children.size() != Other.Children.size())
+  return false;
+
+return std::equal(Children.begin(), Children.end(), Other.Children.begin(),
+  llvm::deref{});
+  }
+
+  bool operator<(const CommentInfo ) const {
+auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,
+SelfClosing, Explicit, AttrKeys, AttrValues, Args);
+auto SecondCI =
+std::tie(Other.Kind, Other.Text, Other.Name, 

[PATCH] D63143: [HIP] Enforce ODR rule for lambda in HIP/CUDA.

2019-06-11 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 204152.
hliao added a comment.

Add the comment for the motivation of this patch as well as reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63143

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCUDA/unnamed-types.cu

Index: clang/test/CodeGenCUDA/unnamed-types.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/unnamed-types.cu
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++11 -x hip -triple x86_64-linux-gnu -fcuda-force-lambda-odr -emit-llvm %s -o - | FileCheck %s --check-prefix=HOST
+// RUN: %clang_cc1 -std=c++11 -x hip -triple amdgcn-amd-amdhsa -fcuda-force-lambda-odr -fcuda-is-device -emit-llvm %s -o - | FileCheck %s --check-prefix=DEVICE
+
+#include "Inputs/cuda.h"
+
+// HOST: @0 = private unnamed_addr constant [43 x i8] c"_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_\00", align 1
+
+__device__ float d0(float x) {
+  return [](float x) { return x + 2.f; }(x);
+}
+
+__device__ float d1(float x) {
+  return [](float x) { return x * 2.f; }(x);
+}
+
+// DEVICE: amdgpu_kernel void @_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_(
+template 
+__global__ void k0(float *p, F f) {
+  p[0] = f(p[0]) + d0(p[1]) + d1(p[2]);
+}
+
+void f0(float *p) {
+  [](float *p) {
+*p = 1.f;
+  }(p);
+}
+
+void f1(float *p) {
+  [](float *p) {
+k0<<<1,1>>>(p, [] __device__ (float x) { return x + 1.f; });
+  }(p);
+}
+// HOST: @__hip_register_globals
+// HOST: __hipRegisterFunction{{.*}}@_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_{{.*}}@0
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -272,9 +272,8 @@
   return false;
 }
 
-MangleNumberingContext *
-Sema::getCurrentMangleNumberContext(const DeclContext *DC,
-Decl *) {
+MangleNumberingContext *Sema::getCurrentMangleNumberContext(
+const DeclContext *DC, Decl *, bool SkpNoODRChk) {
   // Compute the context for allocating mangling numbers in the current
   // expression, if the ABI requires them.
   ManglingContextDecl = ExprEvalContexts.back().ManglingContextDecl;
@@ -322,7 +321,8 @@
   case Normal: {
 //  -- the bodies of non-exported nonspecialized template functions
 //  -- the bodies of inline functions
-if ((IsInNonspecializedTemplate &&
+if (SkpNoODRChk ||
+(IsInNonspecializedTemplate &&
  !(ManglingContextDecl && isa(ManglingContextDecl))) ||
 isInInlineFunction(CurContext)) {
   ManglingContextDecl = nullptr;
@@ -337,7 +337,7 @@
 
   case StaticDataMember:
 //  -- the initializers of nonspecialized static members of template classes
-if (!IsInNonspecializedTemplate) {
+if (!SkpNoODRChk && !IsInNonspecializedTemplate) {
   ManglingContextDecl = nullptr;
   return nullptr;
 }
@@ -441,9 +441,9 @@
 Class->setLambdaMangling(Mangling->first, Mangling->second);
   } else {
 Decl *ManglingContextDecl;
-if (MangleNumberingContext *MCtx =
-getCurrentMangleNumberContext(Class->getDeclContext(),
-  ManglingContextDecl)) {
+if (MangleNumberingContext *MCtx = getCurrentMangleNumberContext(
+Class->getDeclContext(), ManglingContextDecl,
+getLangOpts().CUDAForceLambdaODR)) {
   unsigned ManglingNumber = MCtx->getManglingNumber(Method);
   Class->setLambdaMangling(ManglingNumber, ManglingContextDecl);
 }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2431,6 +2431,9 @@
   if (Args.hasArg(OPT_fno_cuda_host_device_constexpr))
 Opts.CUDAHostDeviceConstexpr = 0;
 
+  if (Args.hasArg(OPT_fcuda_force_lambda_odr))
+Opts.CUDAForceLambdaODR = 1;
+
   if (Opts.CUDAIsDevice && Args.hasArg(OPT_fcuda_approx_transcendentals))
 Opts.CUDADeviceApproxTranscendentals = 1;
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1090,10 +1090,10 @@
   /// block literal.
   /// \param[out] ManglingContextDecl - Returns the ManglingContextDecl
   /// associated with the context, if relevant.
-  MangleNumberingContext *getCurrentMangleNumberContext(
-const DeclContext *DC,
-Decl *);
-
+  MangleNumberingContext *
+  getCurrentMangleNumberContext(const DeclContext *DC,
+Decl *,
+bool SkpNoODRChk = false);
 
   /// SpecialMemberOverloadResult - The 

[PATCH] D63161: Devirtualize destructor of final class.

2019-06-11 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/CodeGen/CGExprCXX.cpp:1867-1868
 
-  if (Dtor->isVirtual()) {
+  if (Dtor->isVirtual() &&
+  !(Dtor->hasAttr() || RD->hasAttr())) {
 CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType,

Can we use `getDevirtualizedMethod` here instead? That catches a few other 
cases that just checking for `final` will miss, and disables this for cases 
where it will currently do the wrong thing (eg, `-fapple-kext`). See 
`EmitCXXMemberOrOperatorMemberCallExpr` for where we do this for other virtual 
calls.

As a particularly terrible example:

```
struct A { virtual ~A() final = 0; };
void evil(A *p) { delete p; }
```

is (amazingly) valid, and must not be devirtualized because there is no 
requirement that the destructor of `A` have a definition in this program. (It 
would, however, be correct to optimize out the entire `delete` expression in 
this case, on the basis that `p` must always be `nullptr` whenever it's 
reached. But that doesn't really seem worthwhile.)


Repository:
  rC Clang

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

https://reviews.llvm.org/D63161



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


[PATCH] D63161: Devirtualize destructor of final class.

2019-06-11 Thread Hiroshi Yamauchi via Phabricator via cfe-commits
yamauchi created this revision.
yamauchi added a reviewer: davidxl.
Herald added a subscriber: Prazek.
Herald added a project: clang.

Take advantage of the final keyword to devirtualize destructor calls.

Fix https://bugs.llvm.org/show_bug.cgi?id=21368


Repository:
  rC Clang

https://reviews.llvm.org/D63161

Files:
  lib/CodeGen/CGExprCXX.cpp
  test/CodeGenCXX/devirtualize-dtor-final.cpp


Index: test/CodeGenCXX/devirtualize-dtor-final.cpp
===
--- /dev/null
+++ test/CodeGenCXX/devirtualize-dtor-final.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 %s -emit-llvm -o - 
| FileCheck %s
+
+namespace Test1 {
+  struct A { virtual ~A() {} };
+  struct B final : public A {};
+  struct C : public A { virtual ~C() final {} };
+  // CHECK-LABEL: define void @_ZN5Test13fooEPNS_1BE
+  void foo(B *b) {
+// CHECK: call void @_ZN5Test11BD1Ev
+delete b;
+  }
+  // CHECK-LABEL: define void @_ZN5Test14foo2EPNS_1CE
+  void foo2(C *c) {
+// CHECK: call void @_ZN5Test11CD1Ev
+delete c;
+  }
+}
Index: lib/CodeGen/CGExprCXX.cpp
===
--- lib/CodeGen/CGExprCXX.cpp
+++ lib/CodeGen/CGExprCXX.cpp
@@ -1864,7 +1864,8 @@
 if (RD->hasDefinition() && !RD->hasTrivialDestructor()) {
   Dtor = RD->getDestructor();
 
-  if (Dtor->isVirtual()) {
+  if (Dtor->isVirtual() &&
+  !(Dtor->hasAttr() || RD->hasAttr())) {
 CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType,
 Dtor);
 return;


Index: test/CodeGenCXX/devirtualize-dtor-final.cpp
===
--- /dev/null
+++ test/CodeGenCXX/devirtualize-dtor-final.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 %s -emit-llvm -o - | FileCheck %s
+
+namespace Test1 {
+  struct A { virtual ~A() {} };
+  struct B final : public A {};
+  struct C : public A { virtual ~C() final {} };
+  // CHECK-LABEL: define void @_ZN5Test13fooEPNS_1BE
+  void foo(B *b) {
+// CHECK: call void @_ZN5Test11BD1Ev
+delete b;
+  }
+  // CHECK-LABEL: define void @_ZN5Test14foo2EPNS_1CE
+  void foo2(C *c) {
+// CHECK: call void @_ZN5Test11CD1Ev
+delete c;
+  }
+}
Index: lib/CodeGen/CGExprCXX.cpp
===
--- lib/CodeGen/CGExprCXX.cpp
+++ lib/CodeGen/CGExprCXX.cpp
@@ -1864,7 +1864,8 @@
 if (RD->hasDefinition() && !RD->hasTrivialDestructor()) {
   Dtor = RD->getDestructor();
 
-  if (Dtor->isVirtual()) {
+  if (Dtor->isVirtual() &&
+  !(Dtor->hasAttr() || RD->hasAttr())) {
 CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType,
 Dtor);
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63009: [OpenMP] Add target task alloc function with device ID

2019-06-11 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 204141.
gtbercea added a comment.

- Add tests.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63009

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/target_depend_codegen.cpp
  test/OpenMP/target_enter_data_depend_codegen.cpp
  test/OpenMP/target_exit_data_depend_codegen.cpp
  test/OpenMP/target_parallel_depend_codegen.cpp
  test/OpenMP/target_parallel_for_depend_codegen.cpp
  test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
  test/OpenMP/target_simd_depend_codegen.cpp
  test/OpenMP/target_teams_depend_codegen.cpp
  test/OpenMP/target_teams_distribute_depend_codegen.cpp
  test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp
  test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
  test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
  test/OpenMP/target_update_depend_codegen.cpp

Index: test/OpenMP/target_update_depend_codegen.cpp
===
--- test/OpenMP/target_update_depend_codegen.cpp
+++ test/OpenMP/target_update_depend_codegen.cpp
@@ -63,7 +63,7 @@
   // CK1: [[CAP_DEVICE:%.+]] = getelementptr inbounds %struct.anon, %struct.anon* [[CAPTURES:%.+]], i32 0, i32 0
   // CK1: [[DEVICE:%.+]] = load i32, i32* %{{.+}}
   // CK1: store i32 [[DEVICE]], i32* [[CAP_DEVICE]],
-  // CK1: [[RES:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* {{.+}}, i32 {{.+}}, i32 1, i[[sz]] [[sz]], i[[sz]] 4, i32 (i32, i8*)* bitcast (i32 (i32, %struct.kmp_task_t_with_privates*)* [[TASK_ENTRY0:@.+]] to i32 (i32, i8*)*))
+  // CK1: [[RES:%.+]] = call i8* @__kmpc_omp_target_task_alloc(%struct.ident_t* {{.+}}, i32 {{.+}}, i32 1, i[[sz]] [[sz]], i[[sz]] 4, i32 (i32, i8*)* bitcast (i32 (i32, %struct.kmp_task_t_with_privates*)* [[TASK_ENTRY0:@.+]] to i32 (i32, i8*)*), i64 -1)
   // CK1: [[BC:%.+]] = bitcast i8* [[RES]] to %struct.kmp_task_t_with_privates*
   // CK1: [[TASK_T:%.+]] = getelementptr inbounds %struct.kmp_task_t_with_privates, %struct.kmp_task_t_with_privates* [[BC]], i32 0, i32 0
   // CK1: [[SHAREDS:%.+]] = getelementptr inbounds %struct.kmp_task_t, %struct.kmp_task_t* [[TASK_T]], i32 0, i32 0
Index: test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
===
--- test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
+++ test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
@@ -133,7 +133,7 @@
   // CHECK:   [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
   // CHECK:   store i32 [[DEV]], i32* [[GEP]],
 
-  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{104|52}}, i[[SZ]] {{16|12}}, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY1_:@.+]] to i32 (i32, i8*)*))
+  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc(%struct.ident_t* [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{104|52}}, i[[SZ]] {{16|12}}, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY1_:@.+]] to i32 (i32, i8*)*), i64 -1)
   // CHECK:   [[BC_TASK:%.+]] = bitcast i8* [[TASK]] to [[TASK_TY1_:%.+]]*
   // CHECK:   getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
   // CHECK:   getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 1
@@ -149,7 +149,7 @@
   // CHECK:   [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
   // CHECK:   store i32 [[DEV]], i32* [[GEP]],
 
-  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{56|28}}, i[[SZ]] {{16|12}}, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY1__:@.+]] to i32 (i32, i8*)*))
+  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc(%struct.ident_t* [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{56|28}}, i[[SZ]] {{16|12}}, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY1__:@.+]] to i32 (i32, i8*)*), i64 -1)
   // CHECK:   [[BC_TASK:%.+]] = bitcast i8* [[TASK]] to [[TASK_TY1__:%.+]]*
   // CHECK:   getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
   // CHECK:   getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 1
Index: test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
===
--- test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
+++ test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
@@ -133,7 +133,7 @@
   // CHECK:   [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
   // CHECK:   store i32 [[DEV]], i32* [[GEP]],
 
-  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* [[ID]], 

[PATCH] D63010: [OpenMP] Add task alloc function

2019-06-11 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 204140.
gtbercea added a comment.

- Add temporary implementation.


Repository:
  rOMP OpenMP

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

https://reviews.llvm.org/D63010

Files:
  runtime/src/kmp.h
  runtime/src/kmp_tasking.cpp


Index: runtime/src/kmp_tasking.cpp
===
--- runtime/src/kmp_tasking.cpp
+++ runtime/src/kmp_tasking.cpp
@@ -1398,6 +1398,16 @@
   return retval;
 }
 
+kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
+ kmp_int32 flags,
+ size_t sizeof_kmp_task_t,
+ size_t sizeof_shareds,
+ kmp_routine_entry_t task_entry,
+ kmp_int64 device_id) {
+  return __kmpc_omp_task_alloc(loc_ref, gtid, flags, sizeof_kmp_task_t,
+   sizeof_shareds, task_entry);
+}
+
 #if OMP_50_ENABLED
 /*!
 @ingroup TASKING
Index: runtime/src/kmp.h
===
--- runtime/src/kmp.h
+++ runtime/src/kmp.h
@@ -3778,6 +3778,12 @@
  size_t sizeof_kmp_task_t,
  size_t sizeof_shareds,
  kmp_routine_entry_t task_entry);
+KMP_EXPORT kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *loc_ref, 
kmp_int32 gtid,
+kmp_int32 flags,
+size_t sizeof_kmp_task_t,
+size_t sizeof_shareds,
+kmp_routine_entry_t 
task_entry,
+kmp_int64 device_id);
 KMP_EXPORT void __kmpc_omp_task_begin_if0(ident_t *loc_ref, kmp_int32 gtid,
   kmp_task_t *task);
 KMP_EXPORT void __kmpc_omp_task_complete_if0(ident_t *loc_ref, kmp_int32 gtid,


Index: runtime/src/kmp_tasking.cpp
===
--- runtime/src/kmp_tasking.cpp
+++ runtime/src/kmp_tasking.cpp
@@ -1398,6 +1398,16 @@
   return retval;
 }
 
+kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
+ kmp_int32 flags,
+ size_t sizeof_kmp_task_t,
+ size_t sizeof_shareds,
+ kmp_routine_entry_t task_entry,
+ kmp_int64 device_id) {
+  return __kmpc_omp_task_alloc(loc_ref, gtid, flags, sizeof_kmp_task_t,
+   sizeof_shareds, task_entry);
+}
+
 #if OMP_50_ENABLED
 /*!
 @ingroup TASKING
Index: runtime/src/kmp.h
===
--- runtime/src/kmp.h
+++ runtime/src/kmp.h
@@ -3778,6 +3778,12 @@
  size_t sizeof_kmp_task_t,
  size_t sizeof_shareds,
  kmp_routine_entry_t task_entry);
+KMP_EXPORT kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
+kmp_int32 flags,
+size_t sizeof_kmp_task_t,
+size_t sizeof_shareds,
+kmp_routine_entry_t task_entry,
+kmp_int64 device_id);
 KMP_EXPORT void __kmpc_omp_task_begin_if0(ident_t *loc_ref, kmp_int32 gtid,
   kmp_task_t *task);
 KMP_EXPORT void __kmpc_omp_task_complete_if0(ident_t *loc_ref, kmp_int32 gtid,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63009: [OpenMP] Add target task alloc function with device ID

2019-06-11 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 204139.
gtbercea added a comment.
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.

- Add temporary implementation.


Repository:
  rOMP OpenMP

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

https://reviews.llvm.org/D63009

Files:
  runtime/src/kmp.h
  runtime/src/kmp_tasking.cpp


Index: runtime/src/kmp_tasking.cpp
===
--- runtime/src/kmp_tasking.cpp
+++ runtime/src/kmp_tasking.cpp
@@ -1398,6 +1398,16 @@
   return retval;
 }
 
+kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
+ kmp_int32 flags,
+ size_t sizeof_kmp_task_t,
+ size_t sizeof_shareds,
+ kmp_routine_entry_t task_entry,
+ kmp_int64 device_id) {
+  return __kmpc_omp_task_alloc(loc_ref, gtid, flags, sizeof_kmp_task_t,
+   sizeof_shareds, task_entry);
+}
+
 #if OMP_50_ENABLED
 /*!
 @ingroup TASKING
Index: runtime/src/kmp.h
===
--- runtime/src/kmp.h
+++ runtime/src/kmp.h
@@ -3778,6 +3778,12 @@
  size_t sizeof_kmp_task_t,
  size_t sizeof_shareds,
  kmp_routine_entry_t task_entry);
+KMP_EXPORT kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *loc_ref, 
kmp_int32 gtid,
+kmp_int32 flags,
+size_t sizeof_kmp_task_t,
+size_t sizeof_shareds,
+kmp_routine_entry_t 
task_entry,
+kmp_int64 device_id);
 KMP_EXPORT void __kmpc_omp_task_begin_if0(ident_t *loc_ref, kmp_int32 gtid,
   kmp_task_t *task);
 KMP_EXPORT void __kmpc_omp_task_complete_if0(ident_t *loc_ref, kmp_int32 gtid,


Index: runtime/src/kmp_tasking.cpp
===
--- runtime/src/kmp_tasking.cpp
+++ runtime/src/kmp_tasking.cpp
@@ -1398,6 +1398,16 @@
   return retval;
 }
 
+kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
+ kmp_int32 flags,
+ size_t sizeof_kmp_task_t,
+ size_t sizeof_shareds,
+ kmp_routine_entry_t task_entry,
+ kmp_int64 device_id) {
+  return __kmpc_omp_task_alloc(loc_ref, gtid, flags, sizeof_kmp_task_t,
+   sizeof_shareds, task_entry);
+}
+
 #if OMP_50_ENABLED
 /*!
 @ingroup TASKING
Index: runtime/src/kmp.h
===
--- runtime/src/kmp.h
+++ runtime/src/kmp.h
@@ -3778,6 +3778,12 @@
  size_t sizeof_kmp_task_t,
  size_t sizeof_shareds,
  kmp_routine_entry_t task_entry);
+KMP_EXPORT kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
+kmp_int32 flags,
+size_t sizeof_kmp_task_t,
+size_t sizeof_shareds,
+kmp_routine_entry_t task_entry,
+kmp_int64 device_id);
 KMP_EXPORT void __kmpc_omp_task_begin_if0(ident_t *loc_ref, kmp_int32 gtid,
   kmp_task_t *task);
 KMP_EXPORT void __kmpc_omp_task_complete_if0(ident_t *loc_ref, kmp_int32 gtid,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63010: [OpenMP] Add task alloc function

2019-06-11 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 204138.
gtbercea added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Add tests.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63010

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/target_depend_codegen.cpp
  test/OpenMP/target_enter_data_depend_codegen.cpp
  test/OpenMP/target_exit_data_depend_codegen.cpp
  test/OpenMP/target_parallel_depend_codegen.cpp
  test/OpenMP/target_parallel_for_depend_codegen.cpp
  test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
  test/OpenMP/target_simd_depend_codegen.cpp
  test/OpenMP/target_teams_depend_codegen.cpp
  test/OpenMP/target_teams_distribute_depend_codegen.cpp
  test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp
  test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
  test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
  test/OpenMP/target_update_depend_codegen.cpp

Index: test/OpenMP/target_update_depend_codegen.cpp
===
--- test/OpenMP/target_update_depend_codegen.cpp
+++ test/OpenMP/target_update_depend_codegen.cpp
@@ -63,7 +63,7 @@
   // CK1: [[CAP_DEVICE:%.+]] = getelementptr inbounds %struct.anon, %struct.anon* [[CAPTURES:%.+]], i32 0, i32 0
   // CK1: [[DEVICE:%.+]] = load i32, i32* %{{.+}}
   // CK1: store i32 [[DEVICE]], i32* [[CAP_DEVICE]],
-  // CK1: [[RES:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* {{.+}}, i32 {{.+}}, i32 1, i[[sz]] [[sz]], i[[sz]] 4, i32 (i32, i8*)* bitcast (i32 (i32, %struct.kmp_task_t_with_privates*)* [[TASK_ENTRY0:@.+]] to i32 (i32, i8*)*))
+  // CK1: [[RES:%.+]] = call i8* @__kmpc_omp_target_task_alloc(%struct.ident_t* {{.+}}, i32 {{.+}}, i32 1, i[[sz]] [[sz]], i[[sz]] 4, i32 (i32, i8*)* bitcast (i32 (i32, %struct.kmp_task_t_with_privates*)* [[TASK_ENTRY0:@.+]] to i32 (i32, i8*)*), i64 -1)
   // CK1: [[BC:%.+]] = bitcast i8* [[RES]] to %struct.kmp_task_t_with_privates*
   // CK1: [[TASK_T:%.+]] = getelementptr inbounds %struct.kmp_task_t_with_privates, %struct.kmp_task_t_with_privates* [[BC]], i32 0, i32 0
   // CK1: [[SHAREDS:%.+]] = getelementptr inbounds %struct.kmp_task_t, %struct.kmp_task_t* [[TASK_T]], i32 0, i32 0
Index: test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
===
--- test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
+++ test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
@@ -133,7 +133,7 @@
   // CHECK:   [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
   // CHECK:   store i32 [[DEV]], i32* [[GEP]],
 
-  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{104|52}}, i[[SZ]] {{16|12}}, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY1_:@.+]] to i32 (i32, i8*)*))
+  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc(%struct.ident_t* [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{104|52}}, i[[SZ]] {{16|12}}, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY1_:@.+]] to i32 (i32, i8*)*), i64 -1)
   // CHECK:   [[BC_TASK:%.+]] = bitcast i8* [[TASK]] to [[TASK_TY1_:%.+]]*
   // CHECK:   getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
   // CHECK:   getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 1
@@ -149,7 +149,7 @@
   // CHECK:   [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
   // CHECK:   store i32 [[DEV]], i32* [[GEP]],
 
-  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{56|28}}, i[[SZ]] {{16|12}}, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY1__:@.+]] to i32 (i32, i8*)*))
+  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc(%struct.ident_t* [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{56|28}}, i[[SZ]] {{16|12}}, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY1__:@.+]] to i32 (i32, i8*)*), i64 -1)
   // CHECK:   [[BC_TASK:%.+]] = bitcast i8* [[TASK]] to [[TASK_TY1__:%.+]]*
   // CHECK:   getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
   // CHECK:   getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 1
Index: test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
===
--- test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
+++ test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
@@ -133,7 +133,7 @@
   // CHECK:   [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
   // CHECK:   store i32 [[DEV]], i32* [[GEP]],
 
-  // CHECK:   

[PATCH] D63012: Use fully qualified name when printing S_CONSTANT records

2019-06-11 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 204137.
akhuang added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Change to not emit DIGlobalVariable for enums when they are defined in a class, 
which
matches MSVC's behavior and gets around the issue of having to create a name 
with scope.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63012

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/global-constants.ll

Index: llvm/test/DebugInfo/COFF/global-constants.ll
===
--- llvm/test/DebugInfo/COFF/global-constants.ll
+++ llvm/test/DebugInfo/COFF/global-constants.ll
@@ -2,9 +2,12 @@
 ; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s --check-prefix=OBJ
 
 ; C++ source to regenerate:
+; namespace Test1 {
 ; const float TestConst1 = 3.14;
+; }
 ; struct S {
 ;   static const int TestConst2 = -10;
+;   enum { SEnum = 42 };
 ; }
 ; enum TestEnum : int {
 ;ENUM_A = 214700,
@@ -12,31 +15,33 @@
 ; };
 ; void useConst(int);
 ; void foo() {
-;   useConst(TestConst1);
+;   useConst(Test1::TestConst1);
 ;   useConst(S::TestConst2);
 ;   useConst(ENUM_B);
+;   useConst(S::SEnum);
 ; }
 ; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll
 
 ; ASM-LABEL:  .long 241 # Symbol subsection for globals
 ; ASM:.short {{.*-.*}}  # Record length
 ; ASM:.short 4359   # Record kind: S_CONSTANT
-; ASM-NEXT:   .long 4099# Type
+; ASM-NEXT:   .long 4102# Type
 ; ASM-NEXT:   .byte 0x04, 0x80, 0xc3, 0xf5  # Value
 ; ASM-NEXT:   .byte 0x48, 0x40
-; ASM-NEXT:   .asciz "TestConst1"   # Name
+; ASM-NEXT:   .asciz "Test1::TestConst1"# Name
 ; ASM:.short {{.*-.*}}  # Record length
 ; ASM:.short 4359   # Record kind: S_CONSTANT
-; ASM-NEXT:   .long 4100# Type
+; ASM-NEXT:   .long 4103# Type
 ; ASM-NEXT:   .byte 0x61, 0x00  # Value
 ; ASM-NEXT:   .asciz "S::TestConst2"# Name
 ; ASM:.short {{.*-.*}}  # Record length
 ; ASM:.short 4359   # Record kind: S_CONSTANT
-; ASM-NEXT:   .long 4102# Type
+; ASM-NEXT:   .long 4105# Type
 ; ASM-NEXT:   .byte 0x0a, 0x80, 0x40, 0x61  # Value
 ; ASM-NEXT:   .byte 0x07, 0x80, 0xff, 0xff
 ; ASM-NEXT:   .byte 0xff, 0xff
 ; ASM-NEXT:   .asciz "ENUM_B"   # Name
+; ASM-NOT:.asciz "S::SEnum" # Name
 
 ; OBJ:CodeViewDebugInfo [
 ; OBJ:  Section: .debug$S
@@ -45,77 +50,110 @@
 ; OBJ:SubSectionType: Symbols (0xF1)
 ; OBJ:ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: const float (0x1003)
+; OBJ-NEXT: Type: const float (0x1006)
 ; OBJ-NEXT: Value: 1078523331
-; OBJ-NEXT: Name: TestConst1
+; OBJ-NEXT: Name: Test1::TestConst1
 ; OBJ-NEXT:   }
 ; OBJ-NEXT:   ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: const char (0x1004)
+; OBJ-NEXT: Type: const char (0x1007)
 ; OBJ-NEXT: Value: 97
 ; OBJ-NEXT: Name: S::TestConst2
 ; OBJ-NEXT:   }
 ; OBJ-NEXT:   ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: TestEnum (0x1006)
+; OBJ-NEXT: Type: TestEnum (0x1009)
 ; OBJ-NEXT: Value: 18446744071562551616
 ; OBJ-NEXT: Name: ENUM_B
 ; OBJ-NEXT:   }
-
+; OBJ-NOT:  Name: S::SEnum
 
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-w64-windows-gnu"
+target triple = "x86_64-pc-windows-msvc19.16.27030"
 
-; Function Attrs: noinline nounwind optnone
-define dso_local void @_Z3foov() #0 !dbg !28 {
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local void @"?useConst@@YAXH@Z"(i32) #0 !dbg !32 {
 entry:
-  call void @_Z8useConsti(i32 3), !dbg !32
-  call void @_Z8useConsti(i32 97), !dbg !33
-  call void @_Z8useConsti(i32 -214700), !dbg !34
-  ret void, !dbg !35
+  %.addr = alloca i32, align 4
+  store i32 %0, i32* %.addr, align 4
+  call void @llvm.dbg.declare(metadata i32* %.addr, metadata !36, metadata !DIExpression()), !dbg !37
+  ret void, !dbg !37
 }
 
-declare dso_local void @_Z8useConsti(i32) #1
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: noinline norecurse nounwind optnone uwtable
+define dso_local i32 @main() #2 !dbg !38 {
+entry:
+  %retval = alloca i32, align 4
+  store i32 0, i32* %retval, align 4
+  call void @"?useConst@@YAXH@Z"(i32 3), !dbg !41
+  call void 

[PATCH] D63157: C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue conversion applied to a member access or similar not-quite-trivial lvalue expression.

2019-06-11 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added a reviewer: rjmccall.
Herald added a subscriber: jdoerfert.
Herald added a project: clang.

When a variable is named in a context where we can't directly emit a
reference to it (because we don't know for sure that it's going to be
defined, or it's from an enclosing function and not captured, or the
reference might not "work" for some reason), we emit a copy of the
variable as a global and use that for the known-to-be-read-only access.


Repository:
  rC Clang

https://reviews.llvm.org/D63157

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/SemaExpr.cpp
  test/CXX/basic/basic.def.odr/p2.cpp
  test/CXX/drs/dr20xx.cpp
  test/CXX/drs/dr21xx.cpp
  test/CXX/drs/dr23xx.cpp
  test/CXX/drs/dr6xx.cpp
  test/CXX/drs/dr7xx.cpp
  test/CodeGenCXX/no-odr-use.cpp
  www/cxx_dr_status.html

Index: www/cxx_dr_status.html
===
--- www/cxx_dr_status.html
+++ www/cxx_dr_status.html
@@ -4219,7 +4219,7 @@
 http://wg21.link/cwg696;>696
 C++11
 Use of block-scope constants in local classes
-Unknown
+Yes
   
   
 http://wg21.link/cwg697;>697
@@ -4315,7 +4315,7 @@
 http://wg21.link/cwg712;>712
 CD3
 Are integer constant operands of a conditional-expression used?
-Unknown
+Partial
   
   
 http://wg21.link/cwg713;>713
@@ -12313,7 +12313,7 @@
 http://wg21.link/cwg2083;>2083
 DR
 Incorrect cases of odr-use
-Unknown
+Partial
   
   
 http://wg21.link/cwg2084;>2084
@@ -12433,7 +12433,7 @@
 http://wg21.link/cwg2103;>2103
 DR
 Lvalue-to-rvalue conversion is irrelevant in odr-use of a reference
-Unknown
+Yes
   
   
 http://wg21.link/cwg2104;>2104
@@ -12835,7 +12835,7 @@
 http://wg21.link/cwg2170;>2170
 DR
 Unclear definition of odr-use for arrays
-Unknown
+SVN
   
   
 http://wg21.link/cwg2171;>2171
@@ -13933,7 +13933,7 @@
 http://wg21.link/cwg2353;>2353
 DR
 Potential results of a member access expression for a static data member
-Unknown
+SVN
   
   
 http://wg21.link/cwg2354;>2354
Index: test/CodeGenCXX/no-odr-use.cpp
===
--- /dev/null
+++ test/CodeGenCXX/no-odr-use.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-linux-gnu %s | FileCheck %s
+
+// CHECK: @__const._Z1fi.a = private unnamed_addr constant {{.*}} { i32 1, [2 x i32] [i32 2, i32 3], [3 x i32] [i32 4, i32 5, i32 6] }
+
+struct A { int x, y[2]; int arr[3]; };
+// CHECK-LABEL: define i32 @_Z1fi(
+int f(int i) {
+  // CHECK: call void {{.*}}memcpy{{.*}}({{.*}}, {{.*}} @__const._Z1fi.a
+  constexpr A a = {1, 2, 3, 4, 5, 6};
+
+  // CHECK-LABEL: define {{.*}}@"_ZZ1fiENK3$_0clEiM1Ai"(
+  return [] (int n, int A::*p) {
+// CHECK: br i1
+return (n >= 0
+  // CHECK: getelementptr inbounds [3 x i32], [3 x i32]* getelementptr inbounds ({{.*}} @__const._Z1fi.a, i32 0, i32 2), i64 0, i64 %
+  ? a.arr[n]
+  // CHECK: br i1
+  : (n == -1
+// CHECK: getelementptr inbounds i8, i8* bitcast ({{.*}} @__const._Z1fi.a to i8*), i64 %
+// CHECK: bitcast i8* %{{.*}} to i32*
+// CHECK: load i32
+? a.*p
+// CHECK: getelementptr inbounds [2 x i32], [2 x i32]* getelementptr inbounds ({{.*}} @__const._Z1fi.a, i32 0, i32 1), i64 0, i64 %
+// CHECK: load i32
+: a.y[2 - n]));
+  }(i, ::x);
+}
Index: test/CXX/drs/dr7xx.cpp
===
--- test/CXX/drs/dr7xx.cpp
+++ test/CXX/drs/dr7xx.cpp
@@ -17,6 +17,42 @@
   }
 }
 
+namespace dr712 { // dr712: partial
+  void use(int);
+  void f() {
+const int a = 0; // expected-note 5{{here}}
+struct X {
+  void g(bool cond) {
+use(a);
+use((a));
+use(cond ? a : a);
+use((cond, a)); // expected-warning 2{{unused}} FIXME: should only warn once
+
+(void)a; // FIXME: expected-error {{declared in enclosing}}
+(void)(a); // FIXME: expected-error {{declared in enclosing}}
+(void)(cond ? a : a); // FIXME: expected-error 2{{declared in enclosing}}
+(void)(cond, a); // FIXME: expected-error {{declared in enclosing}} expected-warning {{unused}}
+  }
+};
+  }
+
+#if __cplusplus >= 201103L
+  void g() {
+struct A { int n; };
+constexpr A a = {0}; // expected-note 2{{here}}
+struct X {
+  void g(bool cond) {
+use(a.n);
+use(a.*::n);
+
+(void)a.n; // FIXME: expected-error {{declared in enclosing}}
+(void)(a.*::n); // FIXME: expected-error {{declared in enclosing}}
+  }
+};
+  }
+#endif
+}
+
 namespace dr727 { // dr727: partial
   struct A {
 template struct C; // expected-note 6{{here}}
Index: test/CXX/drs/dr6xx.cpp
===
--- test/CXX/drs/dr6xx.cpp
+++ 

[PATCH] D62115: fix a issue that clang is incompatible with gcc with -H option.

2019-06-11 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

I think the test needs a bit more work. It's essentially checking the same 
thing twice to exercise the Windows path separators.

It looks like there's already a test for `-H` in 
`FrontEnd/print-header-includes.c`. That also demonstrates the use of 
`--check-prefix` to handle target-specific stuff. Maybe you could fold this 
into there?


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

https://reviews.llvm.org/D62115



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


[PATCH] D63156: [clang][NewPM] Add -fno-experimental-new-pass-manager to tests

2019-06-11 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: chandlerc, echristo, phosek, serge-sans-paille.
leonardchan added a project: clang.
Herald added subscribers: dexonsmith, steven_wu, javed.absar, mehdi_amini.

As per the discussion on D58375 , we disable 
test that have optimizations under the new PM. This patch adds 
`-fno-experimental-new-pass-manager` to RUNS that:

- Already run with optimizations (`-O1` or higher) that were missed in D58375 
.
- Explicitly test new PM behavior along side some new PM RUNS, but are missing 
this flag if new PM is enabled by default.
- Specify `-O` without the number. Based on `getOptimizationLevel()`, it seems 
the default is 2, and the IR appears to be the same when changed to `-O2`, so 
update the test to explicitly say `-O2` and provide 
-fno-experimental-new-pass-manager`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63156

Files:
  clang/test/CodeGen/aggregate-assign-call.c
  clang/test/CodeGen/arm_acle.c
  clang/test/CodeGen/available-externally-suppress.c
  clang/test/CodeGen/cspgo-instrumentation.c
  clang/test/CodeGen/cspgo-instrumentation_lto.c
  clang/test/CodeGen/cspgo-instrumentation_thinlto.c
  clang/test/CodeGen/pgo-instrumentation.c
  clang/test/CodeGen/pgo-sample.c
  clang/test/CodeGen/thinlto-debug-pm.c
  clang/test/CodeGen/x86_64-instrument-functions.c
  clang/test/CodeGenCXX/auto-var-init.cpp
  clang/test/CodeGenCXX/conditional-temporaries.cpp
  clang/test/CodeGenCXX/member-function-pointer-calls.cpp
  clang/test/CodeGenObjC/os_log.m
  clang/test/CodeGenObjCXX/os_log.mm
  clang/test/Misc/pr32207.c

Index: clang/test/Misc/pr32207.c
===
--- clang/test/Misc/pr32207.c
+++ clang/test/Misc/pr32207.c
@@ -1,4 +1,4 @@
 // test for r305179
-// RUN: %clang_cc1 -emit-llvm -O -mllvm -print-after-all %s -o %t 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O2 -fno-experimental-new-pass-manager -mllvm -print-after-all %s -o %t 2>&1 | FileCheck %s
 // CHECK: *** IR Dump After Function Integration/Inlining ***
 void foo() {}
Index: clang/test/CodeGenObjCXX/os_log.mm
===
--- clang/test/CodeGenObjCXX/os_log.mm
+++ clang/test/CodeGenObjCXX/os_log.mm
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc \
-// RUN:   -fexceptions -fcxx-exceptions -O1 | FileCheck %s
+// RUN:   -fexceptions -fcxx-exceptions -O1 -fno-experimental-new-pass-manager | FileCheck %s
 
 // Check that no EH cleanup is emitted around the call to __os_log_helper.
 namespace no_eh_cleanup {
Index: clang/test/CodeGenObjC/os_log.m
===
--- clang/test/CodeGenObjC/os_log.m
+++ clang/test/CodeGenObjC/os_log.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 -fno-experimental-new-pass-manager | FileCheck %s
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O0 | FileCheck %s -check-prefix=CHECK-O0
 
 // Make sure we emit clang.arc.use before calling objc_release as part of the
Index: clang/test/CodeGenCXX/member-function-pointer-calls.cpp
===
--- clang/test/CodeGenCXX/member-function-pointer-calls.cpp
+++ clang/test/CodeGenCXX/member-function-pointer-calls.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O3 -fno-experimental-new-pass-manager  -o - | FileCheck %s
 // RUN: %clang_cc1 %s -triple=x86_64-windows-gnu -emit-llvm -o - | FileCheck %s -check-prefix MINGW64
 struct A {
   virtual int vf1() { return 1; }
Index: clang/test/CodeGenCXX/conditional-temporaries.cpp
===
--- clang/test/CodeGenCXX/conditional-temporaries.cpp
+++ clang/test/CodeGenCXX/conditional-temporaries.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-NOOPT
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O2 | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 -fno-experimental-new-pass-manager -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-NOOPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 -fno-experimental-new-pass-manager | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
+// RUN: %clang_cc1 -emit-llvm 

[PATCH] D63155: [clang][NewPM] Fix broken profile test

2019-06-11 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: chandlerc, echristo, phosek, serge-sans-paille.
leonardchan added a project: clang.
leonardchan added a parent revision: D62225: [clang][NewPM] Fixing -O0 tests 
that are broken under new PM.

This contains the part of D62225  which fixes 
`Profile/gcc-flag-compatibility.c` by adding the pass that allows default 
profile generation to work under the new PM. It seems that `./default.profraw` 
was not being generated with new PM enabled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63155

Files:
  clang/lib/CodeGen/BackendUtil.cpp


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -60,6 +60,7 @@
 #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
 #include "llvm/Transforms/Instrumentation/InstrProfiling.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
+#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Scalar.h"
@@ -1216,6 +1217,11 @@
 
 if (CodeGenOpts.OptimizationLevel == 0)
   addSanitizersAtO0(MPM, TargetTriple, LangOpts, CodeGenOpts);
+
+if (CodeGenOpts.hasProfileIRInstr()) {
+  // This file is stored as the ProfileFile.
+  MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->ProfileFile));
+}
   }
 
   // FIXME: We still use the legacy pass manager to do code generation. We


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -60,6 +60,7 @@
 #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
 #include "llvm/Transforms/Instrumentation/InstrProfiling.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
+#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Scalar.h"
@@ -1216,6 +1217,11 @@
 
 if (CodeGenOpts.OptimizationLevel == 0)
   addSanitizersAtO0(MPM, TargetTriple, LangOpts, CodeGenOpts);
+
+if (CodeGenOpts.hasProfileIRInstr()) {
+  // This file is stored as the ProfileFile.
+  MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->ProfileFile));
+}
   }
 
   // FIXME: We still use the legacy pass manager to do code generation. We
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62738: [HIP] Support texture type

2019-06-11 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Syntactically the patch looks OK to me, but I think the purpose and meaning of 
the builtin type should be documented in more details. Based on this patch 
alone it's not clear at all what it's supposed to be used for and how.




Comment at: include/clang/Basic/AttrDocs.td:4166
+style attribute __declspec(device_builtin_texture_type) can be added to the
+definition of a class template to indicate it is the HIP builtin texture type.
+It is ignored for CUDA and other languages.

What does it mean for user-defined template to be a builtin type? This sounds 
like contradiction to me.

At the very least it should be documented somewhere what are the requirements 
for such a template and what is it supposed to do in the end. 



Comment at: lib/CodeGen/CodeGenModule.cpp:2424
+  !Global->hasAttr() &&
+  !(isCUDATextureType(Global->getType()) && LangOpts.HIP))
 return;

Nit: I'd check LangOpts.HIP first. No need chasing pointers in 
isCUDATExtureType if it's not a HIP compilation.



Comment at: lib/CodeGen/CodeGenModule.cpp:3781
+  (IsCUDASharedVar || IsCUDAShadowVar ||
+   (getLangOpts().CUDAIsDevice && isCUDATextureType(D->getType()
 Init = llvm::UndefValue::get(getTypes().ConvertType(ASTTy));

This is not predicated by HIP compilation and will have effect on CUDA.

It's also not clear to me why texture is initialized as undef on device side. 
Adding a comment about that would be great.



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

https://reviews.llvm.org/D62738



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


[PATCH] D62988: Add an attribute to allow fields of non-trivial types in C unions

2019-06-11 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

How do you write correct (non-leaking, non-double-freeing, 
non-releasing-invalid-pointers) code with this attribute? For example, suppose 
I have a `__strong` union member: does storing to it release the old value 
(which might be a different union member)? If so, how do you work around that? 
https://clang.llvm.org/docs/AutomaticReferenceCounting.html#ownership-qualified-fields-of-structs-and-unions
 should be updated to say what happens. If manual reference counting code is 
required to make any use of this feature correct (which seems superficially 
likely), is this a better programming model than `__unsafe_unretained`?

Unions with non-trivial members are only permitted in C++11 onwards; should we 
allow the attribute in C++98 mode? But more than that, unions with non-trivial 
members require user-provided special members in C++11 onwards, meaning that a 
union using this attribute in C would have a different calling convention than 
the "natural" equivalent in C++. So I'm also wondering if we should allow this 
in all language modes.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62988



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


[PATCH] D62978: [analyzer] trackExpressionValue(): Handle unknown values better

2019-06-11 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked 8 inline comments as done.
Charusso added inline comments.



Comment at: clang/test/Analysis/diagnostics/deref-track-symbolic-region.c:14
   int m = 0;
-  syz.x = foo(); // expected-note{{Value assigned to 'syz.x'}}
 

Here.



Comment at: clang/test/Analysis/diagnostics/find_last_store.c:9
 void no_find_last_store() {
-  c *e = d(); // expected-note{{Calling 'd'}}
-  // expected-note@-1{{Returning from 'd'}}
-  // expected-note@-2{{'e' initialized here}}
+  c *e = d(); // expected-note{{'e' initialized here}}
 

NoQ wrote:
> This remaining note is also unnecessary. You can safely stop tracking the 
> value at `e || ...`. In particular, `ReturnVisitor` is not at fault.
> 
> That said, when we renamed `trackNullOrUndefValue` to `trackExpressionValue`, 
> we kinda assumed that it's not really important whether the value is 
> null/undef or not - the function simply tracks the value. This change would 
> break this invariant, causing null values to be handled in a special manner. 
> I recommend adding another flag argument (similar to 
> `EnableNullFPSuppression`) that would allow the caller to tell whether it's 
> interested in the null or in the "whole" value (defaulting to the latter).
That is a great idea! I tried my best but after a while I give up because it is 
already too complex, so I just removed them. It turns out it makes sense to 
remove those notes, see inline.



Comment at: clang/test/Analysis/diagnostics/macro-null-return-suppression.cpp:53
   int *x = RETURN_NULL();
-  x = returnFreshPointer();  // expected-note{{Value assigned to 'x'}}
   if (x) {} // expected-note{{Taking false branch}}

Here.



Comment at: clang/test/Analysis/loop-widening-notes.cpp:12
// expected-note@-1 {{Loop condition is false. Execution 
continues on line 16}}
-   ++i,// expected-note {{Value assigned to 'p_a'}} 
i < flag_a;

Here.



Comment at: clang/test/Analysis/uninit-const.cpp:59
   int p = f6_1_sub(t); //expected-warning {{Assigned value is garbage or 
undefined}}
-   //expected-note@-1 {{Passing value via 1st parameter 
'p'}}
-   //expected-note@-2 {{Calling 'f6_1_sub'}}

Here we mismatch the parameter.


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

https://reviews.llvm.org/D62978



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


[PATCH] D62926: [analyzer] ReturnVisitor: Bypass everything to see inlined calls

2019-06-11 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked 2 inline comments as done.
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:842-849
+  if (Optional CEE = Node->getLocationAs())
 if (CEE->getCalleeContext()->getCallSite() == S)
   break;
-  if (auto SP = Node->getLocationAs())
-if (SP->getStmt() == S)
-  break;
+
+  if (!IsBypass)
+if (Optional SP = Node->getLocationAs())
+  if (SP->getStmt() == S)

NoQ wrote:
> Charusso wrote:
> > NoQ wrote:
> > > Comparing statements is usually insufficient because the same statement 
> > > may appear multiple times due to recursion. When recursion occurs, you 
> > > may reach the same statement in a different location context. You should 
> > > think in terms of (statement, location context) pairs to avoid these 
> > > problems. Your aim here is to find the `CallExitEnd` node that 
> > > corresponds to returning from an inlined operator new to the current 
> > > location context. You should stop searching when you find an unrelated 
> > > statement in the current location context or when you exit the current 
> > > location context entirely.
> > I have made a little test when we have a 25-second long Static Analyzer run 
> > with predefined names and checker. The loop ran 500 times in summary and we 
> > have some serious performance impacts at other places.
> > 
> > We exit the current context to see inlined calls, so that could not work 
> > sadly. If you remove that nonsense second condition we run at the same 
> > time, so if we have not got any problem since 7 years ago I think it is 
> > good to go.
> You should break the loop as soon as we go past the new-expression that we've 
> started with in the stack frame that we've started with. That is, you should 
> at most go through the constructor within the new-expression, and then break. 
> You shouldn't explore the whole graph to the root every time the operator-new 
> call isn't inlined.
> 
> This might still be slow in some rare cases, but it should be much faster.
Sorry, I was dumb and I have used `isParentOf()` before, I think it is the most 
simple approach now truly.


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

https://reviews.llvm.org/D62926



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


[PATCH] D62926: [analyzer] ReturnVisitor: Bypass everything to see inlined calls

2019-06-11 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 204111.
Charusso marked an inline comment as done.
Charusso added a comment.

- I have used `LocationContext::isParentOf()`which is not worked well, so I 
thought we are out of our context.
- With that I made some misleading assumptions about our code.


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

https://reviews.llvm.org/D62926

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/new-ctor-null-throw.cpp
  clang/test/Analysis/new-ctor-null.cpp

Index: clang/test/Analysis/new-ctor-null.cpp
===
--- clang/test/Analysis/new-ctor-null.cpp
+++ clang/test/Analysis/new-ctor-null.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,debug.ExprInspection \
+// RUN:  -verify %s
 
 void clang_analyzer_eval(bool);
 void clang_analyzer_warnIfReached();
@@ -24,7 +26,8 @@
 
 void testArrays() {
   S *s = new S[10]; // no-crash
-  s[0].x = 2; // expected-warning{{Dereference of null pointer}}
+  s[0].x = 2;
+  // no-warning: 'Dereference of null pointer' suppressed by ReturnVisitor.
 }
 
 int global;
Index: clang/test/Analysis/new-ctor-null-throw.cpp
===
--- clang/test/Analysis/new-ctor-null-throw.cpp
+++ clang/test/Analysis/new-ctor-null-throw.cpp
@@ -1,4 +1,9 @@
-// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-config suppress-null-return-paths=false \
+// RUN:  -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -DSUPPRESSED \
+// RUN:  -verify %s
 
 void clang_analyzer_eval(bool);
 
@@ -9,18 +14,41 @@
 // operator new.
 void *operator new(size_t size) {
   return nullptr;
+  // expected-warning@-1 {{'operator new' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}
 }
 void *operator new[](size_t size) {
   return nullptr;
+  // expected-warning@-1 {{'operator new[]' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}
 }
 
 struct S {
   int x;
   S() : x(1) {}
   ~S() {}
+  int getX() const { return x; }
 };
 
 void testArrays() {
   S *s = new S[10]; // no-crash
-  s[0].x = 2; // expected-warning{{Dereference of null pointer}}
+  s[0].x = 2;
+#ifndef SUPPRESSED
+  // expected-warning@-2 {{Dereference of null pointer}}
+#endif
 }
+
+void testCtor() {
+  S *s = new S();
+  s->x = 13;
+#ifndef SUPPRESSED
+  // expected-warning@-2 {{Access to field 'x' results in a dereference of a null pointer (loaded from variable 's')}}
+#endif
+}
+
+void testMethod() {
+  S *s = new S();
+  const int X = s->getX();
+#ifndef SUPPRESSED
+  // expected-warning@-2 {{Called C++ object pointer is null}}
+#endif
+}
+
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -833,16 +833,15 @@
   return;
 
 // First, find when we processed the statement.
+const StackFrameContext *BeginSC =
+Node->getLocationContext()->getStackFrame();
 do {
-  if (auto CEE = Node->getLocationAs())
+  if (Optional CEE = Node->getLocationAs())
 if (CEE->getCalleeContext()->getCallSite() == S)
   break;
-  if (auto SP = Node->getLocationAs())
-if (SP->getStmt() == S)
-  break;
 
   Node = Node->getFirstPred();
-} while (Node);
+} while (Node && Node->getLocationContext()->getStackFrame() == BeginSC);
 
 // Next, step over any post-statement checks.
 while (Node && Node->getLocation().getAs())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62738: [HIP] Support texture type

2019-06-11 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

ping


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

https://reviews.llvm.org/D62738



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


[PATCH] D63153: [clang][NewPM] Fix broken -O0 test from the AlwaysInliner

2019-06-11 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: chandlerc, echristo, phosek, serge-sans-paille.
leonardchan added a project: clang.
Herald added subscribers: kristof.beyls, javed.absar.

This contains the part of D62225  which 
prevents insertion of lifetime intrinsics when creating the AlwaysInliner. This 
fixes the following tests when the new PM is enabled by default:

  Clang :: CodeGen/aarch64-neon-across.c
  Clang :: CodeGen/aarch64-neon-fcvt-intrinsics.c
  Clang :: CodeGen/aarch64-neon-fma.c
  Clang :: CodeGen/aarch64-neon-perm.c
  Clang :: CodeGen/aarch64-neon-tbl.c
  Clang :: CodeGen/aarch64-poly128.c
  Clang :: CodeGen/aarch64-v8.2a-neon-intrinsics.c
  Clang :: CodeGen/arm-neon-fma.c
  Clang :: CodeGen/arm-neon-numeric-maxmin.c
  Clang :: CodeGen/arm-neon-vcvtX.c
  Clang :: CodeGen/avx-builtins.c
  Clang :: CodeGen/builtins-ppc-p9vector.c
  Clang :: CodeGen/builtins-ppc-vsx.c
  Clang :: CodeGen/lifetime.c
  Clang :: CodeGen/sse-builtins.c
  Clang :: CodeGen/sse2-builtins.c


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63153

Files:
  clang/lib/CodeGen/BackendUtil.cpp


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -,8 +,10 @@
 MPM.addPass(InstrProfiling(*Options, false));
 
   // Build a minimal pipeline based on the semantics required by Clang,
-  // which is just that always inlining occurs.
-  MPM.addPass(AlwaysInlinerPass());
+  // which is just that always inlining occurs. Further, disable generating
+  // lifetime intrinsics to avoid enabling further optimizations during
+  // code generation.
+  MPM.addPass(AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/false));
 
   // At -O0 we directly run necessary sanitizer passes.
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -,8 +,10 @@
 MPM.addPass(InstrProfiling(*Options, false));
 
   // Build a minimal pipeline based on the semantics required by Clang,
-  // which is just that always inlining occurs.
-  MPM.addPass(AlwaysInlinerPass());
+  // which is just that always inlining occurs. Further, disable generating
+  // lifetime intrinsics to avoid enabling further optimizations during
+  // code generation.
+  MPM.addPass(AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/false));
 
   // At -O0 we directly run necessary sanitizer passes.
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r363086 - For DR712: store on a DeclRefExpr whether it constitutes an odr-use.

2019-06-11 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Jun 11 10:50:32 2019
New Revision: 363086

URL: http://llvm.org/viewvc/llvm-project?rev=363086=rev
Log:
For DR712: store on a DeclRefExpr whether it constitutes an odr-use.

Begin restructuring to support the forms of non-odr-use reference
permitted by DR712.

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Sema/SemaInternal.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/JSONNodeDumper.cpp
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/AST/ast-dump-color.cpp
cfe/trunk/test/AST/ast-dump-expr-json.c
cfe/trunk/test/AST/ast-dump-expr-json.cpp
cfe/trunk/test/AST/ast-dump-stmt-json.c
cfe/trunk/test/AST/ast-dump-stmt-json.cpp
cfe/trunk/test/PCH/cxx_exprs.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=363086=363085=363086=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Jun 11 10:50:32 2019
@@ -1226,10 +1226,15 @@ public:
 
   void setInit(Expr *I);
 
-  /// Determine whether this variable's value can be used in a
+  /// Determine whether this variable's value might be usable in a
   /// constant expression, according to the relevant language standard.
   /// This only checks properties of the declaration, and does not check
   /// whether the initializer is in fact a constant expression.
+  bool mightBeUsableInConstantExpressions(ASTContext ) const;
+
+  /// Determine whether this variable's value can be used in a
+  /// constant expression, according to the relevant language standard,
+  /// including checking whether it was initialized by a constant expression.
   bool isUsableInConstantExpressions(ASTContext ) const;
 
   EvaluatedStmt *ensureEvaluatedStmt() const;

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=363086=363085=363086=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Jun 11 10:50:32 2019
@@ -1115,7 +1115,7 @@ class DeclRefExpr final
   bool RefersToEnlosingVariableOrCapture,
   const DeclarationNameInfo , NamedDecl *FoundD,
   const TemplateArgumentListInfo *TemplateArgs, QualType T,
-  ExprValueKind VK);
+  ExprValueKind VK, NonOdrUseReason NOUR);
 
   /// Construct an empty declaration reference expression.
   explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {}
@@ -1128,14 +1128,16 @@ public:
   DeclRefExpr(const ASTContext , ValueDecl *D,
   bool RefersToEnclosingVariableOrCapture, QualType T,
   ExprValueKind VK, SourceLocation L,
-  const DeclarationNameLoc  = DeclarationNameLoc());
+  const DeclarationNameLoc  = DeclarationNameLoc(),
+  NonOdrUseReason NOUR = NOUR_None);
 
   static DeclRefExpr *
   Create(const ASTContext , NestedNameSpecifierLoc QualifierLoc,
  SourceLocation TemplateKWLoc, ValueDecl *D,
  bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc,
  QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr,
- const TemplateArgumentListInfo *TemplateArgs = nullptr);
+ const TemplateArgumentListInfo *TemplateArgs = nullptr,
+ NonOdrUseReason NOUR = NOUR_None);
 
   static DeclRefExpr *
   Create(const ASTContext , NestedNameSpecifierLoc QualifierLoc,
@@ -1143,7 +1145,8 @@ public:
  bool RefersToEnclosingVariableOrCapture,
  const DeclarationNameInfo , QualType T, ExprValueKind VK,
  NamedDecl *FoundD = nullptr,
- const TemplateArgumentListInfo *TemplateArgs = nullptr);
+ const TemplateArgumentListInfo *TemplateArgs = nullptr,
+ NonOdrUseReason NOUR = NOUR_None);
 
   /// Construct an empty declaration reference expression.
   static DeclRefExpr *CreateEmpty(const ASTContext , bool HasQualifier,
@@ -1274,6 +1277,11 @@ public:
 DeclRefExprBits.HadMultipleCandidates = V;
   }
 
+  /// Is this expression a non-odr-use reference, and if so, why?
+  

r363088 - Remove redundant check for whether a DeclRefExpr that names a capture

2019-06-11 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Jun 11 10:50:37 2019
New Revision: 363088

URL: http://llvm.org/viewvc/llvm-project?rev=363088=rev
Log:
Remove redundant check for whether a DeclRefExpr that names a capture
constitutes an odr-use.

We now track this accurately on the DeclRefExpr.

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

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=363088=363087=363088=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Jun 11 10:50:37 2019
@@ -2463,16 +2463,7 @@ LValue CodeGenFunction::EmitDeclRefLValu
 // A DeclRefExpr for a reference initialized by a constant expression can
 // appear without being odr-used. Directly emit the constant initializer.
 VD->getAnyInitializer(VD);
-const auto *BD = dyn_cast_or_null(CurCodeDecl);
-if (E->isNonOdrUse() == NOUR_Constant && VD->getType()->isReferenceType() 
&&
-// Do not emit if it is private OpenMP variable.
-// FIXME: This should be handled in odr-use marking, not here.
-!(E->refersToEnclosingVariableOrCapture() &&
-  ((CapturedStmtInfo &&
-(LocalDeclMap.count(VD->getCanonicalDecl()) ||
- CapturedStmtInfo->lookup(VD->getCanonicalDecl( ||
-   LambdaCaptureFields.lookup(VD->getCanonicalDecl()) ||
-   (BD && BD->capturesVariable(VD) {
+if (E->isNonOdrUse() == NOUR_Constant && VD->getType()->isReferenceType()) 
{
   llvm::Constant *Val =
 ConstantEmitter(*this).emitAbstract(E->getLocation(),
 *VD->evaluateValue(),


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


r363087 - For DR712: store on a MemberExpr whether it constitutes an odr-use.

2019-06-11 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Jun 11 10:50:36 2019
New Revision: 363087

URL: http://llvm.org/viewvc/llvm-project?rev=363087=rev
Log:
For DR712: store on a MemberExpr whether it constitutes an odr-use.

Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/JSONNodeDumper.cpp
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/lib/Analysis/BodyFarm.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=363087=363086=363087=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Jun 11 10:50:36 2019
@@ -2780,7 +2780,8 @@ class MemberExpr final
 
   MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
  ValueDecl *MemberDecl, const DeclarationNameInfo ,
- QualType T, ExprValueKind VK, ExprObjectKind OK);
+ QualType T, ExprValueKind VK, ExprObjectKind OK,
+ NonOdrUseReason NOUR);
   MemberExpr(EmptyShell Empty)
   : Expr(MemberExprClass, Empty), Base(), MemberDecl() {}
 
@@ -2792,10 +2793,11 @@ public:
 DeclAccessPair FoundDecl,
 DeclarationNameInfo MemberNameInfo,
 const TemplateArgumentListInfo *TemplateArgs,
-QualType T, ExprValueKind VK, ExprObjectKind OK);
+QualType T, ExprValueKind VK, ExprObjectKind OK,
+NonOdrUseReason NOUR);
 
   /// Create an implicit MemberExpr, with no location, qualifier, template
-  /// arguments, and so on.
+  /// arguments, and so on. Suitable only for non-static member access.
   static MemberExpr *CreateImplicit(const ASTContext , Expr *Base,
 bool IsArrow, ValueDecl *MemberDecl,
 QualType T, ExprValueKind VK,
@@ -2803,7 +2805,7 @@ public:
 return Create(C, Base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(),
   SourceLocation(), MemberDecl,
   DeclAccessPair::make(MemberDecl, MemberDecl->getAccess()),
-  DeclarationNameInfo(), nullptr, T, VK, OK);
+  DeclarationNameInfo(), nullptr, T, VK, OK, NOUR_None);
   }
 
   static MemberExpr *CreateEmpty(const ASTContext , bool HasQualifier,
@@ -2957,6 +2959,12 @@ public:
 return LO.AppleKext || !hasQualifier();
   }
 
+  /// Is this expression a non-odr-use reference, and if so, why?
+  /// This is only meaningful if the named member is a static member.
+  NonOdrUseReason isNonOdrUse() const {
+return static_cast(MemberExprBits.NonOdrUseReason);
+  }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == MemberExprClass;
   }

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=363087=363086=363087=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Jun 11 10:50:36 2019
@@ -479,6 +479,11 @@ protected:
 /// was resolved from an overloaded set having size greater than 1.
 unsigned HadMultipleCandidates : 1;
 
+/// Value of type NonOdrUseReason indicating why this MemberExpr does
+/// not constitute an odr-use of the named declaration. Meaningful only
+/// when naming a static member.
+unsigned NonOdrUseReason : 2;
+
 /// This is the location of the -> or . in the expression.
 SourceLocation OperatorLoc;
   };

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=363087=363086=363087=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Jun 11 10:50:36 2019
@@ -4305,6 +4305,10 @@ public:
 bool isAddressOfOperand,
 const TemplateArgumentListInfo *TemplateArgs);
 
+  /// If \p D cannot be odr-used in the current expression evaluation context,
+  /// return a reason explaining why. Otherwise, return NOUR_None.
+  NonOdrUseReason getNonOdrUseReasonInCurrentContext(ValueDecl *D);
+
   DeclRefExpr *BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
 SourceLocation Loc,
 const CXXScopeSpec *SS = nullptr);


[PATCH] D63149: Added AST matcher for ignoring elidable constructors

2019-06-11 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6455
 
+/// Matches expressions that match InnerMatcher after any elidable constructor 
are stripped off.
+///

80 columns



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6455
 
+/// Matches expressions that match InnerMatcher after any elidable constructor 
are stripped off.
+///

gribozavr wrote:
> 80 columns
It would help if you described why a user would want to skip the elidable 
constructor using this matcher rather than hardcoding the presence of such an 
AST node.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6457
+///
+/// Example matches the entire D1 = ... (matcher = 
cxxOperatorCallExpr(hasArgument(1, callExpr(hasArgument(0, 
ignoringElidableMoveConstructorCall(ignoringParenImpCasts(callExpr(
+/// \code

I'd suggest to rephrase the example using the "Given:" format (see other 
comments around), and wrap the code to 80 columns.



Comment at: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp:575
+
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct H {};"

Can you run these tests in both C++14 and C++17 modes?



Comment at: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp:628
+  EXPECT_TRUE(matches(
+"void f(){"
+"int D = 10;"

Need a space before the open brace, and indentation in the function body (in 
every test).



Comment at: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp:631
+"}"
+  , matcher));
+}

Please clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63149



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


[PATCH] D63149: Added AST matcher for ignoring elidable constructors

2019-06-11 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom created this revision.
jvikstrom added reviewers: hokein, gribozavr.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Added AST matcher for ignoring elidable move constructors


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63149

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -566,6 +566,71 @@
llvm::make_unique>("x")));
 }
 
+TEST(Matcher, IgnoresElidableConstructors) {
+  StatementMatcher matcher = cxxOperatorCallExpr(
+hasArgument(1, callExpr(hasArgument(0, 
+ignoringElidableMoveConstructorCall(
+  ignoringParenImpCasts(expr().bind("c")));
+
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct H {};"
+"template H B(T A);"
+"void f(){"
+"H D1;"
+"D1=B(B(1));"
+"}"
+, matcher, llvm::make_unique>("c")));
+
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct H {};"
+"template H B(T A);"
+"void f(){"
+"H D1;"
+"D1=B(1);"
+"}"
+, matcher, llvm::make_unique>("c")));
+}
+
+TEST(Matcher, IgnoresElidableInReturn) {
+  auto matcher = expr(ignoringElidableMoveConstructorCall(declRefExpr()));
+
+  EXPECT_TRUE(matches(
+"struct H{};"
+"H f(){"
+"H g;"
+"return g;"
+"}"
+, matcher));
+
+  EXPECT_FALSE(matches(
+"struct H{};"
+"H f(){"
+"return H();"
+"}"
+, matcher
+  ));
+}
+
+TEST(Matcher, IgnoreElidableConstructorDoesNotMatchConstructors) {
+  auto matcher = varDecl(hasInitializer(ignoringElidableMoveConstructorCall(cxxConstructExpr(;
+  EXPECT_TRUE(matches(
+"struct H {};"
+"void f(){"
+"H D;"
+"}"
+  , matcher));
+
+};
+
+TEST(Matcher, IgnoresElidableDoesNotPreventMatches) {
+  auto matcher = expr(ignoringElidableMoveConstructorCall(integerLiteral()));
+  EXPECT_TRUE(matches(
+"void f(){"
+"int D = 10;"
+"}"
+  , matcher));
+}
+
 TEST(Matcher, BindTheSameNameInAlternatives) {
   StatementMatcher matcher = anyOf(
 binaryOperator(hasOperatorName("+"),
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -320,6 +320,7 @@
   REGISTER_MATCHER(hasUnqualifiedDesugaredType);
   REGISTER_MATCHER(hasValueType);
   REGISTER_MATCHER(ifStmt);
+  REGISTER_MATCHER(ignoringElidableMoveConstructorCall);
   REGISTER_MATCHER(ignoringImpCasts);
   REGISTER_MATCHER(ignoringImplicit);
   REGISTER_MATCHER(ignoringParenCasts);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6452,6 +6452,31 @@
   return false;
 }
 
+/// Matches expressions that match InnerMatcher after any elidable constructor are stripped off.
+///
+/// Example matches the entire D1 = ... (matcher = cxxOperatorCallExpr(hasArgument(1, callExpr(hasArgument(0, ignoringElidableMoveConstructorCall(ignoringParenImpCasts(callExpr(
+/// \code
+/// struct H {};
+/// template H B(T A);
+/// void f() {
+///   H D1;
+///   D1 = B(B(1));
+/// }
+/// \endcode
+AST_MATCHER_P(Expr, ignoringElidableMoveConstructorCall,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  if (const auto* cxx_construct_expr = dyn_cast()) {
+if (cxx_construct_expr->isElidable()) {
+  if (const auto* materialize_temp = dyn_cast(
+  cxx_construct_expr->getArg(0))) {
+return InnerMatcher.matches(*materialize_temp, Finder, Builder);
+  }
+  return InnerMatcher.matches(*cxx_construct_expr, Finder, Builder);
+}
+  }
+  return InnerMatcher.matches(Node, Finder, Builder);
+}
+
 ////
 // OpenMP handling.
 ////
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -5728,6 +5728,19 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>ExprignoringElidableMoveConstructorCallast_matchers::Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr InnerMatcher
+Matches expressions that match InnerMatcher after any elidable constructor are stripped off.
+
+Example matches the entire D1 = ... 

[PATCH] D62831: [CodeGen][ObjC] Add attribute "arc_retain_agnostic" to ObjC globals that are retain-agnostic

2019-06-11 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Should `objc` be in the attribute somewhere to avoid any future awkwardness?  I 
don't remember what we've called similar attributes.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62831



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


[PATCH] D62988: Add an attribute to allow fields of non-trivial types in C unions

2019-06-11 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D62988#1537401 , @ahatanak wrote:

> In D62988#1537082 , @rjmccall wrote:
>
> > Does this lead to C/C++ ABI mismatches?  Should we just honor this in C++ 
> > as well by ignoring it when deciding to delete special members?  Is taking 
> > such a general name a good idea if it's language-specific?  Richard, 
> > thoughts?
>
>
> This is a C-only attribute, so clang will emit a diagnostic (warning 
> 'attribute ignored') if the attribute is used to annotate a member of a C++ 
> union. I think that would be sufficient to prevent possible C/C++ ABI 
> mismatches?


Is there a way to write a C++ union that would be ABI-compatible with a C union 
with this attribute?


Repository:
  rC Clang

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

https://reviews.llvm.org/D62988



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


[PATCH] D59744: Fix i386 ABI "__m64" type bug

2019-06-11 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Minor comments, then LGTM.




Comment at: lib/CodeGen/TargetInfo.cpp:1094
+// FreeBSD) don't want to spend any effort dealing with the ramifications
+// of ABI breaks at present.
+const llvm::Triple  = getTarget().getTriple();

"The System V i386 psABI requires __m64 to be passed in MMX registers.
Clang historically had a bug where it failed to apply this rule, and some 
platforms
(e.g. Darwin, PS4, and FreeBSD) have opted to maintain compatibility with the 
old
Clang behavior, so we only apply it on platforms that have specifically 
requested it
(currently just Linux and NetBSD)."



Comment at: lib/CodeGen/TargetInfo.cpp:1417
+if (VT->getElementType()->isIntegerType() && Size == 64 &&
+  isPassInMMXRegABI())
+  return ABIArgInfo::getDirect(llvm::Type::getX86_MMXTy(getVMContext()));

Indentation on the continuation line.


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

https://reviews.llvm.org/D59744



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


Re: r363009 - [Frontend] SetUpDiagnosticLog should handle unowned diagnostic consumer

2019-06-11 Thread Alex L via cfe-commits
Hmm, the logging was meant to exercise the creation of chained diagnostic
consumer, so without it the test is kind of pointless. I'll undo your
change, but will set the file to "-" which will print the log to STDERR and
won't create new files. Does that sound reasonable?

Cheers,
Alex

On Tue, 11 Jun 2019 at 02:51, Ilya Biryukov  wrote:

> Hi Alex,
>
> Just wanted to let you know that I removed logging of diagnostics into a
> file inside the unit test in r363041 to unbreak our integrate.
>
> On Tue, Jun 11, 2019 at 1:29 AM Alex Lorenz via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: arphaman
>> Date: Mon Jun 10 16:32:42 2019
>> New Revision: 363009
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=363009=rev
>> Log:
>> [Frontend] SetUpDiagnosticLog should handle unowned diagnostic consumer
>> in the compiler
>>
>> The function SetUpDiagnosticLog that was called from createDiagnostics
>> didn't
>> handle the case where the diagnostics engine didn't own the diagnostics
>> consumer.
>> This is a potential problem for a clang tool, in particular some of the
>> follow-up
>> patches for clang-scan-deps will need this fix.
>>
>> Differential Revision: https://reviews.llvm.org/D63101
>>
>> Modified:
>> cfe/trunk/lib/Frontend/CompilerInstance.cpp
>> cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp
>>
>> Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=363009=363008=363009=diff
>>
>> ==
>> --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
>> +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Mon Jun 10 16:32:42 2019
>> @@ -232,9 +232,13 @@ static void SetUpDiagnosticLog(Diagnosti
>>
>>  std::move(StreamOwner));
>>if (CodeGenOpts)
>>  Logger->setDwarfDebugFlags(CodeGenOpts->DwarfDebugFlags);
>> -  assert(Diags.ownsClient());
>> -  Diags.setClient(
>> -  new ChainedDiagnosticConsumer(Diags.takeClient(),
>> std::move(Logger)));
>> +  if (Diags.ownsClient()) {
>> +Diags.setClient(
>> +new ChainedDiagnosticConsumer(Diags.takeClient(),
>> std::move(Logger)));
>> +  } else {
>> +Diags.setClient(
>> +new ChainedDiagnosticConsumer(Diags.getClient(),
>> std::move(Logger)));
>> +  }
>>  }
>>
>>  static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts,
>>
>> Modified: cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp?rev=363009=363008=363009=diff
>>
>> ==
>> --- cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp (original)
>> +++ cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp Mon Jun 10
>> 16:32:42 2019
>> @@ -8,6 +8,7 @@
>>
>>  #include "clang/Frontend/CompilerInstance.h"
>>  #include "clang/Frontend/CompilerInvocation.h"
>> +#include "clang/Frontend/TextDiagnosticPrinter.h"
>>  #include "llvm/Support/FileSystem.h"
>>  #include "llvm/Support/Format.h"
>>  #include "llvm/Support/ToolOutputFile.h"
>> @@ -70,4 +71,21 @@ TEST(CompilerInstance, DefaultVFSOverlay
>>ASSERT_TRUE(Instance.getFileManager().getFile("vfs-virtual.file"));
>>  }
>>
>> +TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
>> +  auto DiagOpts = new DiagnosticOptions();
>> +  DiagOpts->DiagnosticLogFile = "log.diags";
>> +
>> +  // Create the diagnostic engine with unowned consumer.
>> +  std::string DiagnosticOutput;
>> +  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
>> +  auto DiagPrinter = llvm::make_unique(
>> +  DiagnosticsOS, new DiagnosticOptions());
>> +  CompilerInstance Instance;
>> +  IntrusiveRefCntPtr Diags =
>> Instance.createDiagnostics(
>> +  DiagOpts, DiagPrinter.get(), /*ShouldOwnClient=*/false);
>> +
>> +  Diags->Report(diag::err_expected) << "no crash";
>> +  ASSERT_EQ(DiagnosticsOS.str(), "error: expected no crash\n");
>> +}
>> +
>>  } // anonymous namespace
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
> --
> Regards,
> Ilya Biryukov
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D60455: [SYCL] Implement SYCL device code outlining

2019-06-11 Thread Aaron Ballman via cfe-commits
Richard Smith, but his time is sometimes limited. John McCall would also be
a great choice. Otherwise, I am happy to review when back next week.

~Aaron

On Tue, Jun 11, 2019, 4:45 PM Bader, Alexey  wrote:

> Hi Aaron,
>
>
>
> I think Anastasia is on vacation.
>
> Could you recommend someone who can be “trusted reviewer” for this change,
> please?
>
> If no, we will wait for your/Anastasia review.
>
>
>
> Thanks,
>
> Alexey
>
>
>
> *From:* Aaron Ballman 
> *Sent:* Tuesday, June 11, 2019 5:04 PM
> *To:* reviews+d60455+public+bc9d5bb3412ac...@reviews.llvm.org
> *Cc:* Podchishchaeva, Mariya ; Justin
> Lebar ; ronan-l...@keryell.fr; v.lomul...@gmail.com;
> a.bat...@hotmail.com; anastasia.stul...@arm.com; Bader, Alexey <
> alexey.ba...@intel.com>; mgo...@gentoo.org; Maslov, Oleg <
> oleg.mas...@intel.com>; Gainullin, Artur ;
> b00234...@studentmail.uws.ac.uk; bevin.hans...@ericsson.com;
> cfe-commits@lists.llvm.org; mlek...@skidmore.edu; blitzrak...@gmail.com;
> shen...@google.com
> *Subject:* Re: [PATCH] D60455: [SYCL] Implement SYCL device code outlining
>
>
>
> I'm out of the office until next week and won't be able to review it until
> then. If another trusted reviewer accepts, I can always do post commit
> review.
>
>
>
> ~Aaron
>
>
>
> On Tue, Jun 11, 2019, 2:43 PM Mariya Podchishchaeva via Phabricator <
> revi...@reviews.llvm.org> wrote:
>
> Fznamznon added a comment.
>
> @aaron.ballman , please let me know if you have additional
> comments/suggestions. If not, could you please accept this revision?
>
>
> 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] D63143: [HIP] Enforce ODR rule for lambda in HIP/CUDA.

2019-06-11 Thread Michael Liao via Phabricator via cfe-commits
hliao created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63143

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCUDA/unnamed-types.cu

Index: clang/test/CodeGenCUDA/unnamed-types.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/unnamed-types.cu
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++11 -x hip -triple x86_64-linux-gnu -fcuda-force-lambda-odr -emit-llvm %s -o - | FileCheck %s --check-prefix=HOST
+// RUN: %clang_cc1 -std=c++11 -x hip -triple amdgcn-amd-amdhsa -fcuda-force-lambda-odr -fcuda-is-device -emit-llvm %s -o - | FileCheck %s --check-prefix=DEVICE
+
+#include "Inputs/cuda.h"
+
+// HOST: @0 = private unnamed_addr constant [43 x i8] c"_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_\00", align 1
+
+__device__ float d0(float x) {
+  return [](float x) { return x + 2.f; }(x);
+}
+
+__device__ float d1(float x) {
+  return [](float x) { return x * 2.f; }(x);
+}
+
+// DEVICE: amdgpu_kernel void @_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_(
+template 
+__global__ void k0(float *p, F f) {
+  p[0] = f(p[0]) + d0(p[1]) + d1(p[2]);
+}
+
+void f0(float *p) {
+  [](float *p) {
+*p = 1.f;
+  }(p);
+}
+
+void f1(float *p) {
+  [](float *p) {
+k0<<<1,1>>>(p, [] __device__ (float x) { return x + 1.f; });
+  }(p);
+}
+// HOST: @__hip_register_globals
+// HOST: __hipRegisterFunction{{.*}}@_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_{{.*}}@0
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -272,9 +272,8 @@
   return false;
 }
 
-MangleNumberingContext *
-Sema::getCurrentMangleNumberContext(const DeclContext *DC,
-Decl *) {
+MangleNumberingContext *Sema::getCurrentMangleNumberContext(
+const DeclContext *DC, Decl *, bool SkpNoODRChk) {
   // Compute the context for allocating mangling numbers in the current
   // expression, if the ABI requires them.
   ManglingContextDecl = ExprEvalContexts.back().ManglingContextDecl;
@@ -322,7 +321,8 @@
   case Normal: {
 //  -- the bodies of non-exported nonspecialized template functions
 //  -- the bodies of inline functions
-if ((IsInNonspecializedTemplate &&
+if (SkpNoODRChk ||
+(IsInNonspecializedTemplate &&
  !(ManglingContextDecl && isa(ManglingContextDecl))) ||
 isInInlineFunction(CurContext)) {
   ManglingContextDecl = nullptr;
@@ -337,7 +337,7 @@
 
   case StaticDataMember:
 //  -- the initializers of nonspecialized static members of template classes
-if (!IsInNonspecializedTemplate) {
+if (!SkpNoODRChk && !IsInNonspecializedTemplate) {
   ManglingContextDecl = nullptr;
   return nullptr;
 }
@@ -441,9 +441,9 @@
 Class->setLambdaMangling(Mangling->first, Mangling->second);
   } else {
 Decl *ManglingContextDecl;
-if (MangleNumberingContext *MCtx =
-getCurrentMangleNumberContext(Class->getDeclContext(),
-  ManglingContextDecl)) {
+if (MangleNumberingContext *MCtx = getCurrentMangleNumberContext(
+Class->getDeclContext(), ManglingContextDecl,
+getLangOpts().CUDAForceLambdaODR)) {
   unsigned ManglingNumber = MCtx->getManglingNumber(Method);
   Class->setLambdaMangling(ManglingNumber, ManglingContextDecl);
 }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2431,6 +2431,9 @@
   if (Args.hasArg(OPT_fno_cuda_host_device_constexpr))
 Opts.CUDAHostDeviceConstexpr = 0;
 
+  if (Args.hasArg(OPT_fcuda_force_lambda_odr))
+Opts.CUDAForceLambdaODR = 1;
+
   if (Opts.CUDAIsDevice && Args.hasArg(OPT_fcuda_approx_transcendentals))
 Opts.CUDADeviceApproxTranscendentals = 1;
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1090,10 +1090,10 @@
   /// block literal.
   /// \param[out] ManglingContextDecl - Returns the ManglingContextDecl
   /// associated with the context, if relevant.
-  MangleNumberingContext *getCurrentMangleNumberContext(
-const DeclContext *DC,
-Decl *);
-
+  MangleNumberingContext *
+  getCurrentMangleNumberContext(const DeclContext *DC,
+Decl *,
+bool SkpNoODRChk = false);
 
   /// SpecialMemberOverloadResult - The overloading result for a special member
   /// function.
Index: clang/include/clang/Driver/CC1Options.td

[PATCH] D63098: [CodeComplete] Allow completing enum values within case statements, and insert 'case' as a fixit.

2019-06-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Notes from the offline discussion:

- Sam: supporting multiple typed text chunks is hard, many clients that expect 
only one. Objective-C already does that, though, but in a way that does not 
break most targets.
- Sam: supporting any other form of custom text for filtering is also hard, 
particularly in clangd that exposes a structured completion item with 
qualifiers, etc.
- me: feel strongly that we should show `case` at the start **and** match it.
- me: also feel strongly that the feature is useful. Having a single big "typed 
text" chunk that includes the qualifier and 'case' looks better than not having 
the feature.

Let me know if I missed or misinterpreted something.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63098



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


[PATCH] D61446: Generalize the pass registration mechanism used by Polly to any third-party tool

2019-06-11 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: polly/lib/Support/RegisterPasses.cpp:727
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
+llvmGetPassPluginInfo() {
+  return getPassPluginInfo();

Meinersbur wrote:
> [serious] Unfortunately, the new pass manager's plugin system relies on the 
> function name to be `llvmGetPassPluginInfo` in each plugin. This works with 
> multiple dynamic libraries all declaring the same name using the 
> `PassPlugin::Load` mechanism, but linking them all statically will violate 
> the one-definition-rule.
> 
> IMHO, Polly.cpp would have been a better place for this function.
> but linking them all statically will violate the one-definition-rule.

They are unused when liked statically, and flagged as weak to avoid link-time 
conflict.

> IMHO, Polly.cpp would have been a better place for this function.
I still agree it's more explicit if linked conditionaly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61446



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


[PATCH] D61446: Generalize the pass registration mechanism used by Polly to any third-party tool

2019-06-11 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 204073.
serge-sans-paille marked 3 inline comments as done.
serge-sans-paille added a comment.

@beanz : In addition to your suggested changes, I've renamed the cmake utility 
into `add_llvm_pass_plugin` to match other functions from `AddLLVM.cmake`

@Meinersbur : thanks a lot for the polly layout explanation. I've slighlty 
updated your suggection like this:

  PollyCore.a:
RegisterPasses.o
polly_static_entry_point.cpp
  
  LLVMPolly.so (for use with -load mechanism)
RegisterPasses.o
polly_plugin_entry_point.cpp

initialization is done in both cases through a static initializer in 
`RegisterPasses.cpp`. `llvmGetPassPluginInfo` is only available in 
`polly_plugin_entry_point.cpp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61446

Files:
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/cc1_main.cpp
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/docs/WritingAnLLVMPass.rst
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/tools/CMakeLists.txt
  llvm/tools/bugpoint/CMakeLists.txt
  llvm/tools/bugpoint/bugpoint.cpp
  llvm/tools/opt/CMakeLists.txt
  llvm/tools/opt/NewPMDriver.cpp
  llvm/tools/opt/opt.cpp
  llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
  polly/include/polly/RegisterPasses.h
  polly/lib/CMakeLists.txt
  polly/lib/Polly.cpp
  polly/lib/Support/RegisterPasses.cpp
  polly/test/Unit/lit.site.cfg.in
  polly/test/lit.site.cfg.in
  polly/test/update_check.py

Index: polly/test/update_check.py
===
--- polly/test/update_check.py
+++ polly/test/update_check.py
@@ -15,7 +15,7 @@
 polly_lib_dir = '''@POLLY_LIB_DIR@'''
 shlibext = '''@LLVM_SHLIBEXT@'''
 llvm_tools_dir = '''@LLVM_TOOLS_DIR@'''
-link_polly_into_tools = not '''@LINK_POLLY_INTO_TOOLS@'''.lower() in {'','0','n','no','off','false','notfound','link_polly_into_tools-notfound'}
+llvm_polly_link_into_tools = not '''@LLVM_POLLY_LINK_INTO_TOOLS@'''.lower() in {'','0','n','no','off','false','notfound','llvm_polly_link_into_tools-notfound'}
 
 runre = re.compile(r'\s*\;\s*RUN\s*\:(?P.*)')
 filecheckre = re.compile(r'\s*(?P.*)\|\s*(?PFileCheck\s[^|]*)')
@@ -298,7 +298,7 @@
 toolarg = toolarg.replace('%s', filename)
 toolarg = toolarg.replace('%S', os.path.dirname(filename))
 if toolarg == '%loadPolly':
-if not link_polly_into_tools:
+if not llvm_polly_link_into_tools:
 newtool += ['-load',os.path.join(polly_lib_dir,'LLVMPolly' + shlibext)]
 newtool.append('-polly-process-unprofitable')
 newtool.append('-polly-remarks-minimal')
Index: polly/test/lit.site.cfg.in
===
--- polly/test/lit.site.cfg.in
+++ polly/test/lit.site.cfg.in
@@ -8,7 +8,7 @@
 config.polly_lib_dir = "@POLLY_LIB_DIR@"
 config.target_triple = "@TARGET_TRIPLE@"
 config.enable_gpgpu_codegen = "@GPU_CODEGEN@"
-config.link_polly_into_tools = "@LINK_POLLY_INTO_TOOLS@"
+config.llvm_polly_link_into_tools = "@LLVM_POLLY_LINK_INTO_TOOLS@"
 config.targets_to_build = "@TARGETS_TO_BUILD@"
 config.extra_paths = "@POLLY_TEST_EXTRA_PATHS@".split(";")
 
@@ -36,14 +36,14 @@
 # directories.
 config.excludes = ['Inputs']
 
-if config.link_polly_into_tools == '' or \
-   config.link_polly_into_tools.lower() == '0' or \
-   config.link_polly_into_tools.lower() == 'n' or \
-   config.link_polly_into_tools.lower() == 'no' or \
-   config.link_polly_into_tools.lower() == 'off' or \
-   config.link_polly_into_tools.lower() == 'false' or \
-   config.link_polly_into_tools.lower() == 'notfound' or \
-   config.link_polly_into_tools.lower() == 'link_polly_into_tools-notfound':
+if config.llvm_polly_link_into_tools == '' or \
+   config.llvm_polly_link_into_tools.lower() == '0' or \
+   config.llvm_polly_link_into_tools.lower() == 'n' or \
+   config.llvm_polly_link_into_tools.lower() == 'no' or \
+   config.llvm_polly_link_into_tools.lower() == 'off' or \
+   config.llvm_polly_link_into_tools.lower() == 'false' or \
+   config.llvm_polly_link_into_tools.lower() == 'notfound' or \
+   config.llvm_polly_link_into_tools.lower() == 'llvm_polly_link_into_tools-notfound':
 config.substitutions.append(('%loadPolly', '-load '
  + config.polly_lib_dir + '/LLVMPolly@LLVM_SHLIBEXT@'
  + ' -load-pass-plugin '
Index: polly/test/Unit/lit.site.cfg.in
===
--- polly/test/Unit/lit.site.cfg.in
+++ polly/test/Unit/lit.site.cfg.in
@@ -13,7 +13,7 @@
 config.shlibdir = "@SHLIBDIR@"
 config.target_triple = "@TARGET_TRIPLE@"
 config.enable_gpgpu_codegen = "@GPU_CODEGEN@"
-config.link_polly_into_tools = "@LINK_POLLY_INTO_TOOLS@"
+config.llvm_polly_link_into_tools = 

r363076 - Revert r344630 Disable code object version 3 for HIP toolchain.

2019-06-11 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Tue Jun 11 08:05:11 2019
New Revision: 363076

URL: http://llvm.org/viewvc/llvm-project?rev=363076=rev
Log:
Revert r344630 Disable code object version 3 for HIP toolchain.

Remove the workaround so that by default code object v3 is enabled.

Modified:
cfe/trunk/lib/Driver/ToolChains/HIP.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/HIP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/HIP.cpp?rev=363076=363075=363076=diff
==
--- cfe/trunk/lib/Driver/ToolChains/HIP.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/HIP.cpp Tue Jun 11 08:05:11 2019
@@ -127,7 +127,7 @@ const char *AMDGCN::Linker::constructLlc
 llvm::StringRef OutputFilePrefix, const char *InputFileName) const {
   // Construct llc command.
   ArgStringList LlcArgs{InputFileName, "-mtriple=amdgcn-amd-amdhsa",
-"-filetype=obj", "-mattr=-code-object-v3",
+"-filetype=obj",
 Args.MakeArgString("-mcpu=" + SubArchName)};
 
   // Extract all the -m options


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


[PATCH] D62804: [clangd] Enable extraction of system includes from custom toolchains

2019-06-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D62804#1538155 , @kadircet wrote:

> For example a gcc cross compiling to arm comes with its own system includes 
> and has some mechanisms to discover that implicitly, without requiring any 
> "-I" flags.
>  Hence when used with clangd, we make use of system includes instead of the 
> target's include library. This patch aims to solve that issue, tools like 
> cquery also handles that problem in a similar way.


That's exactly what driver is about. The approach is slightly different, 
though. Instead of executing a binary, one has to mimic the toolchain search 
logic of a particular toolchain by hand.
In addition to includes, it also handles adding the corresponding `-D` flags 
and anything else that the cross-compile toolchain does. Is this toolchain not 
currently supported by the driver? Is adding it so much work that we would 
choose to workaround like this instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62804



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


r363074 - Fix for r42230, MSVC test failure in DependencyDirectivesSourceMinimizerTest.cpp

2019-06-11 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Tue Jun 11 07:58:26 2019
New Revision: 363074

URL: http://llvm.org/viewvc/llvm-project?rev=363074=rev
Log:
Fix for r42230, MSVC test failure in DependencyDirectivesSourceMinimizerTest.cpp

r362459 introduced DependencyDirectivesSourceMinimizerTest.cpp, which
hits an MSVC bug:
developercommunity.visualstudio.com/content/problem/67300/stringifying-raw-string-literal.html

This only happens when the parameter to a macro is stringified in the
macro.  This patch removes the string from the assert so that the
warning no longer happens.

Modified:
cfe/trunk/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp

Modified: cfe/trunk/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp?rev=363074=363073=363074=diff
==
--- cfe/trunk/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp 
(original)
+++ cfe/trunk/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp Tue Jun 
11 07:58:26 2019
@@ -405,25 +405,27 @@ TEST(MinimizeSourceToDependencyDirective
"#endif\n",
Out.data());
 
-  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  bool RawStringLiteralResult = minimizeSourceToDependencyDirectives(
   "#ifndef GUARD\n"
   "#define GUARD\n"
   R"raw(static constexpr char bytes[] = R"(-?:\,[]{}#&*!|>'"%@`)";)raw"
   "\n"
   "#endif\n",
-  Out));
+  Out);
+  ASSERT_FALSE(RawStringLiteralResult);
   EXPECT_STREQ("#ifndef GUARD\n"
"#define GUARD\n"
"#endif\n",
Out.data());
 
-  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  bool RawStringLiteralResult2 = minimizeSourceToDependencyDirectives(
   "#ifndef GUARD\n"
   "#define GUARD\n"
   R"raw(static constexpr char bytes[] = 
R"abc(-?:\,[]{}#&*!|>'"%@`)abc";)raw"
   "\n"
   "#endif\n",
-  Out));
+  Out);
+  ASSERT_FALSE(RawStringLiteralResult2);
   EXPECT_STREQ("#ifndef GUARD\n"
"#define GUARD\n"
"#endif\n",


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


RE: [PATCH] D60455: [SYCL] Implement SYCL device code outlining

2019-06-11 Thread Bader, Alexey via cfe-commits
Hi Aaron,

I think Anastasia is on vacation.
Could you recommend someone who can be “trusted reviewer” for this change, 
please?
If no, we will wait for your/Anastasia review.

Thanks,
Alexey

From: Aaron Ballman 
Sent: Tuesday, June 11, 2019 5:04 PM
To: reviews+d60455+public+bc9d5bb3412ac...@reviews.llvm.org
Cc: Podchishchaeva, Mariya ; Justin Lebar 
; ronan-l...@keryell.fr; v.lomul...@gmail.com; 
a.bat...@hotmail.com; anastasia.stul...@arm.com; Bader, Alexey 
; mgo...@gentoo.org; Maslov, Oleg 
; Gainullin, Artur ; 
b00234...@studentmail.uws.ac.uk; bevin.hans...@ericsson.com; 
cfe-commits@lists.llvm.org; mlek...@skidmore.edu; blitzrak...@gmail.com; 
shen...@google.com
Subject: Re: [PATCH] D60455: [SYCL] Implement SYCL device code outlining

I'm out of the office until next week and won't be able to review it until 
then. If another trusted reviewer accepts, I can always do post commit review.

~Aaron

On Tue, Jun 11, 2019, 2:43 PM Mariya Podchishchaeva via Phabricator 
mailto:revi...@reviews.llvm.org>> wrote:
Fznamznon added a comment.

@aaron.ballman , please let me know if you have additional 
comments/suggestions. If not, could you please accept this revision?


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] D62804: [clangd] Enable extraction of system includes from custom toolchains

2019-06-11 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D62804#1533710 , @ilya-biryukov 
wrote:

> Could you give more context on what the custom toolchains are?
>  One feasible alternative is to move this detection to clang's driver (where 
> the rest of include path detection lives), why won't that work?


Moving this logic into clang's driver should also work there is nothing 
specific to clangd. This patch just fetches those headers and adds them to 
clang invocation command line with a "-isystem" in front of them.
But we execute an arbitrary binary to fetch system includes coming from the 
custom toolchain drivers. Therefore we decided to rather keep it contained in 
clangd hidden behind a flag during offline discussions.

For example a gcc cross compiling to arm comes with its own system includes and 
has some mechanisms to discover that implicitly, without requiring any "-I" 
flags.
Hence when used with clangd, we make use of system includes instead of the 
target's include library. This patch aims to solve that issue, tools like 
cquery also handles that problem in a similar way.




Comment at: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp:82
+
+if (!llvm::sys::fs::exists(Line))
+  elog("Parsed non-existing system include: {0}", Line);

sammccall wrote:
> Is this check important? (What happens if non-existent dirs are on the 
> include path?)
> 
> If it is, maybe we should pass in the VFS (factory?) here.
Existence of the directory doesn't really matter, I've put this as a debug 
measure, in case we get a "non-path"(malformed) entry.
But I suppose we can already see this in the "Updating a.cc with command " 
log.

So removing it.



Comment at: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp:90
+
+std::vector extractSystemIncludes(PathRef Driver, PathRef File) {
+  trace::Span Tracer("Extract system includes");

sammccall wrote:
> some explanation of what this is doing?
> 
> e.g. "Many compilers have default system includes... these are known by the 
> driver and passed to cc1 ... gcc and compilers with compatible CLI can dump 
> the cc1 invocation information with this syntax... we do so and parse the 
> result."
I've aleady mentioned this in file comment, do you think it is necessary to 
mention that in here as well?



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:276
+   "for non-sequence match."),
+llvm::cl::init(""));
+

sammccall wrote:
> is there something useful we should set this to by default? like 
> `/usr/bin/gcc,/usr/bin/g++`?
> 
> Or is the assumption that the standard/system compilers will never have weird 
> information to extract?
I believe this is not an issue with default gcc/g++ since we never heard such 
complaints. I would rather leave the default empty until we observe some wide 
usage, due to security concerns


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62804



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


[PATCH] D63062: [clang-format] Added New Style Rule: OnePerLineBitFieldDecl

2019-06-11 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 204068.

Repository:
  rC Clang

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

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3656,6 +3656,19 @@
"#define A Just forcing a new line\n"
"ddd);");
 }
+TEST_F(FormatTest, AlignBitFieldDeclarationsOnConsecutiveLines){
+  FormatStyle Style = {};
+  Style.OnePerLineBitFieldDecl = true;
+  verifyFormat(
+"unsigned int baz : 11,
+  aaa : 2,
+  foo : 3"
+  );
+  Style.OnePerLineBitFieldDecl = false;
+  verifyFormat(
+"unsigned int baz : 11, aaa : 2, foo : 3"
+  );
+} 
 
 TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
   verifyFormat(
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,9 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) {
   const FormatToken  = *Right.Previous;
+  if (Right.Previous->is(tok::comma) && Style.OnePerLineBitFieldDecl &&
+  Right.is(tok::identifier) && (Right.Next->is(tok::colon)))
+return true;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -516,6 +516,14 @@
 return T && T->is(tok::kw_auto);
   }
 
+  /// Returns whether the token is a Bit field, and checks whether
+  /// the Style is C / C++.
+  bool isBitField() const {
+const FormatToken *T = this;
+T = T->getPreviousNonComment();
+return (T->Tok.is(tok::comma) && Tok.is(tok::identifier) &&
+T->Next->Tok.is(tok::colon));
+  }
   /// Same as opensBlockOrBlockTypeList, but for the closing token.
   bool closesBlockOrBlockTypeList(const FormatStyle ) const {
 if (is(TT_TemplateString) && closesScope())
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("OnePerLineBitFieldDecl", Style.OnePerLineBitFieldDecl);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -329,6 +329,8 @@
 bool ContinuationIndenter::mustBreak(const LineState ) {
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
+  if (Style.isCpp() && Current.isBitField() && Style.OnePerLineBitFieldDecl)
+return true; 
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +543,7 @@
  unsigned ExtraSpaces) {
   FormatToken  = *State.NextToken;
   const FormatToken  = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool OnePerLineBitFieldDecl;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle {
 /// Don't align escaped newlines.
@@ -1950,6 +1960,7 @@
JavaScriptWrapImports == R.JavaScriptWrapImports &&
KeepEmptyLinesAtTheStartOfBlocks ==

[PATCH] D63140: [clangd] Return TextEdits from ClangdServer::applyTweak

2019-06-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: kadircet.
Herald added subscribers: arphaman, jkorous, MaskRay.
Herald added a project: clang.

Instead of tooling::Replacements. So that embedders do not need to store
the contents of the file.

This also aligns better ClangdServer::rename.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63140

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h


Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -234,7 +234,7 @@
 
   /// Apply the code tweak with a specified \p ID.
   void applyTweak(PathRef File, Range Sel, StringRef ID,
-  Callback CB);
+  Callback> CB);
 
   /// Only for testing purposes.
   /// Waits until all requests to worker thread are finished and dumps AST for
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -321,7 +321,7 @@
 }
 
 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
-  Callback CB) {
+  Callback> CB) {
   auto Action = [Sel](decltype(CB) CB, std::string File, std::string TweakID,
   Expected InpAST) {
 if (!InpAST)
@@ -332,15 +332,18 @@
 auto A = prepareTweak(TweakID, *Selection);
 if (!A)
   return CB(A.takeError());
-auto RawReplacements = (*A)->apply(*Selection);
-if (!RawReplacements)
-  return CB(RawReplacements.takeError());
+auto Raw = (*A)->apply(*Selection);
+if (!Raw)
+  return CB(Raw.takeError());
 // FIXME: this function has I/O operations (find .clang-format file), 
figure
 // out a way to cache the format style.
 auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
InpAST->Inputs.FS.get());
-return CB(
-cleanupAndFormat(InpAST->Inputs.Contents, *RawReplacements, Style));
+auto Formatted =
+cleanupAndFormat(InpAST->Inputs.Contents, *Raw, Style);
+if (!Formatted)
+  return CB(Formatted.takeError());
+return CB(replacementsToEdits(InpAST->Inputs.Contents, *Formatted));
   };
   WorkScheduler.runWithAST(
   "ApplyTweak", File,
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -482,13 +482,13 @@
 
 auto Action = [ApplyEdit](decltype(Reply) Reply, URIForFile File,
   std::string Code,
-  llvm::Expected R) {
+  llvm::Expected> R) {
   if (!R)
 return Reply(R.takeError());
 
   WorkspaceEdit WE;
   WE.changes.emplace();
-  (*WE.changes)[File.uri()] = replacementsToEdits(Code, *R);
+  (*WE.changes)[File.uri()] = std::move(*R);
 
   Reply("Fix applied.");
   ApplyEdit(std::move(WE));


Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -234,7 +234,7 @@
 
   /// Apply the code tweak with a specified \p ID.
   void applyTweak(PathRef File, Range Sel, StringRef ID,
-  Callback CB);
+  Callback> CB);
 
   /// Only for testing purposes.
   /// Waits until all requests to worker thread are finished and dumps AST for
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -321,7 +321,7 @@
 }
 
 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
-  Callback CB) {
+  Callback> CB) {
   auto Action = [Sel](decltype(CB) CB, std::string File, std::string TweakID,
   Expected InpAST) {
 if (!InpAST)
@@ -332,15 +332,18 @@
 auto A = prepareTweak(TweakID, *Selection);
 if (!A)
   return CB(A.takeError());
-auto RawReplacements = (*A)->apply(*Selection);
-if (!RawReplacements)
-  return CB(RawReplacements.takeError());
+auto Raw = (*A)->apply(*Selection);
+if (!Raw)
+  return CB(Raw.takeError());
 // FIXME: this function has I/O operations (find .clang-format file), figure
 // out a way to cache the format style.
 auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
InpAST->Inputs.FS.get());
-return CB(
-  

[PATCH] D62804: [clangd] Enable extraction of system includes from custom toolchains

2019-06-11 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 204066.
kadircet marked 27 inline comments as done.
kadircet added a comment.
Herald added a subscriber: mgorny.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62804

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/SystemIncludeExtractor.cpp
  clang-tools-extra/clangd/test/system-include-extractor.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -268,6 +268,15 @@
 "Always used text-based completion")),
 llvm::cl::init(CodeCompleteOptions().RunParser), llvm::cl::Hidden);
 
+static llvm::cl::list QueryDriverGlobs(
+"query-driver",
+llvm::cl::desc(
+"Comma separated list of globs for white-listing gcc-compatible "
+"drivers that are safe to execute. Drivers matching any of these globs "
+"will be used to extract system includes. e.g. "
+"/usr/bin/**/clang-*,/path/to/repo/**/g++-*"),
+llvm::cl::CommaSeparated);
+
 namespace {
 
 /// \brief Supports a test URI scheme with relaxed constraints for lit tests.
@@ -521,6 +530,7 @@
 };
   }
   Opts.SuggestMissingIncludes = SuggestMissingIncludes;
+  Opts.QueryDriverGlobs = std::move(QueryDriverGlobs);
   llvm::Optional OffsetEncodingFromFlag;
   if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
 OffsetEncodingFromFlag = ForceOffsetEncoding;
Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -0,0 +1,41 @@
+# RUN: rm -rf %t.dir && mkdir -p %t.dir
+
+# RUN: echo '#!/bin/bash' >> %t.dir/my_driver.sh
+# RUN: echo 'echo line to ignore' >> %t.dir/my_driver.sh
+# RUN: echo 'echo \#include \<...\> search starts here:' >> %t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir/' >> %t.dir/my_driver.sh
+# RUN: echo 'echo End of search list.' >> %t.dir/my_driver.sh
+# RUN: chmod +x %t.dir/my_driver.sh
+
+# RUN: mkdir -p %t.dir/my/dir
+# RUN: touch %t.dir/my/dir/a.h
+
+# RUN: echo '[{"directory": "%/t.dir", "command": "%/t.dir/my_driver.sh the-file.cpp", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
+
+# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
+# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
+# (with the extra slash in the front), so we add it here.
+# RUN: sed -e "s|file://\([A-Z]\):/|file:///\1:/|g" %t.test.1 > %t.test
+
+# RUN: clangd -lit-test -query-driver="**/*.sh" < %t.test | FileCheck -strict-whitespace %t.test
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
+---
+{
+  "jsonrpc":"2.0",
+  "method":"textDocument/didOpen",
+  "params": {
+"textDocument": {
+  "uri": "file://INPUT_DIR/the-file.cpp",
+  "languageId":"cpp",
+  "version":1,
+  "text":"#include "
+}
+  }
+}
+# CHECK:   "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:   "params": {
+# CHECK-NEXT: "diagnostics": [],
+---
+{"jsonrpc":"2.0","id":1,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/SystemIncludeExtractor.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -0,0 +1,258 @@
+//===--- SystemIncludeExtractor.cpp --*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+// Some compiler drivers have implicit search mechanism for system headers.
+// This compilation database implementation tries to extract that information by
+// executing the driver in verbose mode. gcc-compatible drivers print something
+// like:
+// 
+// 
+// #include <...> search starts here:
+//  /usr/lib/gcc/x86_64-linux-gnu/7/include
+//  /usr/local/include
+//  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
+//  /usr/include/x86_64-linux-gnu
+//  /usr/include
+// End of search list.
+// 
+// 
+// This component parses that output and adds each path to command line args
+// provided by Base, after prepending them with -isystem. Therefore current
+// implementation would not work with a driver that is not gcc-compatible.
+//
+// First argument of the command line received from underlying compilation
+// 

r363070 - [NFC][PowerPC] Header-dependent test requires "native"

2019-06-11 Thread Hubert Tong via cfe-commits
Author: hubert.reinterpretcast
Date: Tue Jun 11 07:23:55 2019
New Revision: 363070

URL: http://llvm.org/viewvc/llvm-project?rev=363070=rev
Log:
[NFC][PowerPC] Header-dependent test requires "native"

Two recently added tests mention complications for cross-compile, but
they do not actually enforce native compilation. This patch makes them
require native compilation to avoid the complications they mention.

Modified:
cfe/trunk/test/CodeGen/ppc-mm-malloc-le.c
cfe/trunk/test/CodeGen/ppc-mm-malloc.c

Modified: cfe/trunk/test/CodeGen/ppc-mm-malloc-le.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ppc-mm-malloc-le.c?rev=363070=363069=363070=diff
==
--- cfe/trunk/test/CodeGen/ppc-mm-malloc-le.c (original)
+++ cfe/trunk/test/CodeGen/ppc-mm-malloc-le.c Tue Jun 11 07:23:55 2019
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: powerpc-registered-target
+// REQUIRES: native, powerpc-registered-target
 // UNSUPPORTED: !powerpc64le-
 // The stdlib.h included in mm_malloc.h references native system header
 // like: bits/libc-header-start.h or features.h, cross-compile it may

Modified: cfe/trunk/test/CodeGen/ppc-mm-malloc.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ppc-mm-malloc.c?rev=363070=363069=363070=diff
==
--- cfe/trunk/test/CodeGen/ppc-mm-malloc.c (original)
+++ cfe/trunk/test/CodeGen/ppc-mm-malloc.c Tue Jun 11 07:23:55 2019
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: powerpc-registered-target
+// REQUIRES: native, powerpc-registered-target
 // UNSUPPORTED: !powerpc64-
 // The stdlib.h included in mm_malloc.h references native system header
 // like: bits/libc-header-start.h or features.h, cross-compile it may


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


r363069 - Reapply r362994 & co "[analyzer][tests] Add normalize_plist to replace diff_plist"

2019-06-11 Thread Hubert Tong via cfe-commits
Author: hubert.reinterpretcast
Date: Tue Jun 11 07:21:32 2019
New Revision: 363069

URL: http://llvm.org/viewvc/llvm-project?rev=363069=rev
Log:
Reapply r362994 & co "[analyzer][tests] Add normalize_plist to replace 
diff_plist"

Following r363007, which reverted r362998, r362996, and r362994,
reapply with adjustments for the CRLF differences encountered with
Windows. Namely, the `-b` option of `diff` is employed, and the `grep`
patterns have `$` replaced with `[[:space:]]*$`.

Modified:
cfe/trunk/test/Analysis/MismatchedDeallocator-path-notes.cpp
cfe/trunk/test/Analysis/NewDelete-path-notes.cpp
cfe/trunk/test/Analysis/conditional-path-notes.c
cfe/trunk/test/Analysis/copypaste/plist-diagnostics-notes-as-events.cpp
cfe/trunk/test/Analysis/copypaste/plist-diagnostics.cpp
cfe/trunk/test/Analysis/cxx-for-range.cpp
cfe/trunk/test/Analysis/diagnostics/deref-track-symbolic-region.c
cfe/trunk/test/Analysis/diagnostics/plist-diagnostics-include-check.cpp
cfe/trunk/test/Analysis/diagnostics/plist-multi-file.c
cfe/trunk/test/Analysis/diagnostics/report-issues-within-main-file.cpp
cfe/trunk/test/Analysis/diagnostics/undef-value-caller.c
cfe/trunk/test/Analysis/diagnostics/undef-value-param.c
cfe/trunk/test/Analysis/diagnostics/undef-value-param.m
cfe/trunk/test/Analysis/edges-new.mm
cfe/trunk/test/Analysis/generics.m
cfe/trunk/test/Analysis/inline-plist.c
cfe/trunk/test/Analysis/inline-unique-reports.c
cfe/trunk/test/Analysis/inlining/eager-reclamation-path-notes.c
cfe/trunk/test/Analysis/inlining/eager-reclamation-path-notes.cpp
cfe/trunk/test/Analysis/inlining/path-notes.c
cfe/trunk/test/Analysis/inlining/path-notes.cpp
cfe/trunk/test/Analysis/inlining/path-notes.m
cfe/trunk/test/Analysis/lambda-notes.cpp
cfe/trunk/test/Analysis/lit.local.cfg
cfe/trunk/test/Analysis/malloc-plist.c
cfe/trunk/test/Analysis/method-call-path-notes.cpp
cfe/trunk/test/Analysis/model-file.cpp
cfe/trunk/test/Analysis/null-deref-path-notes.m
cfe/trunk/test/Analysis/nullability-notes.m
cfe/trunk/test/Analysis/objc-arc.m
cfe/trunk/test/Analysis/objc-radar17039661.m
cfe/trunk/test/Analysis/plist-macros-with-expansion.cpp
cfe/trunk/test/Analysis/plist-macros.cpp
cfe/trunk/test/Analysis/plist-output-alternate.m
cfe/trunk/test/Analysis/plist-output.m
cfe/trunk/test/Analysis/retain-release-path-notes.m
cfe/trunk/test/Analysis/retain-release.m
cfe/trunk/test/Analysis/unix-fns.c

Modified: cfe/trunk/test/Analysis/MismatchedDeallocator-path-notes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/MismatchedDeallocator-path-notes.cpp?rev=363069=363068=363069=diff
==
--- cfe/trunk/test/Analysis/MismatchedDeallocator-path-notes.cpp (original)
+++ cfe/trunk/test/Analysis/MismatchedDeallocator-path-notes.cpp Tue Jun 11 
07:21:32 2019
@@ -1,6 +1,6 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.MismatchedDeallocator 
-analyzer-output=text -verify %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.MismatchedDeallocator 
-analyzer-output=plist %s -o %t.plist
-// RUN: tail -n +11 %t.plist | %diff_plist 
%S/copypaste/Inputs/expected-plists/MismatchedDeallocator-path-notes.cpp.plist -
+// RUN: tail -n +11 %t.plist | %normalize_plist | diff -ub 
%S/copypaste/Inputs/expected-plists/MismatchedDeallocator-path-notes.cpp.plist -
 
 void changePointee(int *p);
 int *allocIntArray(unsigned c) {

Modified: cfe/trunk/test/Analysis/NewDelete-path-notes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/NewDelete-path-notes.cpp?rev=363069=363068=363069=diff
==
--- cfe/trunk/test/Analysis/NewDelete-path-notes.cpp (original)
+++ cfe/trunk/test/Analysis/NewDelete-path-notes.cpp Tue Jun 11 07:21:32 2019
@@ -11,7 +11,7 @@
 // RUN:   -analyzer-checker=cplusplus.NewDelete,unix.Malloc \
 // RUN:   -analyzer-config add-pop-up-notes=false \
 // RUN:   -analyzer-output=plist %s -o %t.plist
-// RUN: cat %t.plist | %diff_plist \
+// RUN: %normalize_plist <%t.plist | diff -ub \
 // RUN:   %S/Inputs/expected-plists/NewDelete-path-notes.cpp.plist -
 
 void test() {

Modified: cfe/trunk/test/Analysis/conditional-path-notes.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/conditional-path-notes.c?rev=363069=363068=363069=diff
==
--- cfe/trunk/test/Analysis/conditional-path-notes.c (original)
+++ cfe/trunk/test/Analysis/conditional-path-notes.c Tue Jun 11 07:21:32 2019
@@ -1,6 +1,6 @@
 // RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference 
-analyzer-output=text -verify
 // RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference 
-analyzer-output=plist -o %t
-// RUN: cat %t | %diff_plist 

[PATCH] D63129: [clang-tidy] Fix invalid read on destruction

2019-06-11 Thread Nikolai Kosjar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363068: [clang-tidy] Fix invalid read on destruction 
(authored by nik, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63129

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp


Index: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -44,18 +44,22 @@
 static const char DerefByRefResultName[] = "derefByRefResult";
 
 // shared matchers
-static const TypeMatcher AnyType = anything();
+static const TypeMatcher AnyType() { return anything(); }
 
-static const StatementMatcher IntegerComparisonMatcher =
-expr(ignoringParenImpCasts(
-
declRefExpr(to(varDecl(hasType(isInteger())).bind(ConditionVarName);
-
-static const DeclarationMatcher InitToZeroMatcher =
-varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral(equals(0)
-.bind(InitVarName);
+static const StatementMatcher IntegerComparisonMatcher() {
+  return expr(ignoringParenImpCasts(
+  declRefExpr(to(varDecl(hasType(isInteger())).bind(ConditionVarName);
+}
+
+static const DeclarationMatcher InitToZeroMatcher() {
+  return varDecl(
+ hasInitializer(ignoringParenImpCasts(integerLiteral(equals(0)
+  .bind(InitVarName);
+}
 
-static const StatementMatcher IncrementVarMatcher =
-declRefExpr(to(varDecl(hasType(isInteger())).bind(IncrementVarName)));
+static const StatementMatcher IncrementVarMatcher() {
+  return declRefExpr(to(varDecl(hasType(isInteger())).bind(IncrementVarName)));
+}
 
 /// \brief The matcher for loops over arrays.
 ///
@@ -81,15 +85,15 @@
 
   return forStmt(
  unless(isInTemplateInstantiation()),
- hasLoopInit(declStmt(hasSingleDecl(InitToZeroMatcher))),
+ hasLoopInit(declStmt(hasSingleDecl(InitToZeroMatcher(,
  hasCondition(anyOf(
  binaryOperator(hasOperatorName("<"),
-hasLHS(IntegerComparisonMatcher),
+hasLHS(IntegerComparisonMatcher()),
 hasRHS(ArrayBoundMatcher)),
  binaryOperator(hasOperatorName(">"), 
hasLHS(ArrayBoundMatcher),
-hasRHS(IntegerComparisonMatcher,
+hasRHS(IntegerComparisonMatcher(),
  hasIncrement(unaryOperator(hasOperatorName("++"),
-hasUnaryOperand(IncrementVarMatcher
+
hasUnaryOperand(IncrementVarMatcher()
   .bind(LoopNameArray);
 }
 
@@ -190,7 +194,7 @@
  hasIncrement(anyOf(
  unaryOperator(hasOperatorName("++"),
hasUnaryOperand(declRefExpr(
-   to(varDecl(hasType(pointsTo(AnyType)))
+   to(varDecl(hasType(pointsTo(AnyType(
   .bind(IncrementVarName),
  cxxOperatorCallExpr(
  hasOverloadedOperatorName("++"),
@@ -278,17 +282,17 @@
  unless(isInTemplateInstantiation()),
  hasLoopInit(
  anyOf(declStmt(declCountIs(2),
-containsDeclaration(0, InitToZeroMatcher),
+containsDeclaration(0, InitToZeroMatcher()),
 containsDeclaration(1, EndDeclMatcher)),
-   declStmt(hasSingleDecl(InitToZeroMatcher,
+   declStmt(hasSingleDecl(InitToZeroMatcher(),
  hasCondition(anyOf(
  binaryOperator(hasOperatorName("<"),
-hasLHS(IntegerComparisonMatcher),
+hasLHS(IntegerComparisonMatcher()),
 hasRHS(IndexBoundMatcher)),
  binaryOperator(hasOperatorName(">"), 
hasLHS(IndexBoundMatcher),
-hasRHS(IntegerComparisonMatcher,
+hasRHS(IntegerComparisonMatcher(),
  hasIncrement(unaryOperator(hasOperatorName("++"),
-hasUnaryOperand(IncrementVarMatcher
+
hasUnaryOperand(IncrementVarMatcher()
   .bind(LoopNamePseudoArray);
 }
 


Index: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
+++ 

[clang-tools-extra] r363068 - [clang-tidy] Fix invalid read on destruction

2019-06-11 Thread Nikolai Kosjar via cfe-commits
Author: nik
Date: Tue Jun 11 07:19:09 2019
New Revision: 363068

URL: http://llvm.org/viewvc/llvm-project?rev=363068=rev
Log:
[clang-tidy] Fix invalid read on destruction

...in case the clang tidy plugin is linked into the clang binary.

Valgrind's memcheck reports:

8949== Invalid read ==8866== Invalid read of size 4
8866== at 0x164D248B: fetch_sub (atomic_base.h:524)
8866== by 0x164D248B: 
llvm::ThreadSafeRefCountedBase::Release()
 const (IntrusiveRefCntPtr.h:98)
8866== by 0x164CE16C: 
llvm::IntrusiveRefCntPtrInfo::release(clang::ast_matchers::internal::DynMatcherInterface*)
 (IntrusiveRefCntPtr.h:127)
8866== by 0x164C8D5C: 
llvm::IntrusiveRefCntPtr::release()
 (IntrusiveRefCntPtr.h:190)
8866== by 0x164C3B87: 
llvm::IntrusiveRefCntPtr::~IntrusiveRefCntPtr()
 (IntrusiveRefCntPtr.h:157)
8866== by 0x164BB4F1: 
clang::ast_matchers::internal::DynTypedMatcher::~DynTypedMatcher() 
(ASTMatchersInternal.h:341)
8866== by 0x164BB529: 
clang::ast_matchers::internal::Matcher::~Matcher() 
(ASTMatchersInternal.h:496)
8866== by 0xD7AE614: __cxa_finalize (cxa_finalize.c:83)
8866== by 0x164B3082: ??? (in 
/d2/llvm/8/qtc/builds/DebugShared/lib/libclangTidyModernizeModule.so.8)
8866== by 0x4010B72: _dl_fini (dl-fini.c:138)
8866== by 0xD7AE040: __run_exit_handlers (exit.c:108)
8866== by 0xD7AE139: exit (exit.c:139)
8866== by 0xD78CB9D: (below main) (libc-start.c:344)
8866== Address 0x19dd9bc8 is 8 bytes inside a block of size 16 free'd
8866== at 0x4C3123B: operator delete(void*) (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
8866== by 0x1469BB99: clang::ast_matchers::internal::(anonymous 
namespace)::TrueMatcherImpl::~TrueMatcherImpl() (ASTMatchersInternal.cpp:126)
8866== by 0x1469BBC5: 
llvm::object_deleter::call(void*) (ManagedStatic.h:30)
8866== by 0x9ABFF26: llvm::ManagedStaticBase::destroy() const 
(ManagedStatic.cpp:72)
8866== by 0x9ABFF94: llvm::llvm_shutdown() (ManagedStatic.cpp:84)
8866== by 0x9A65232: llvm::InitLLVM::~InitLLVM() (InitLLVM.cpp:52)
8866== by 0x14B0C8: main (driver.cpp:323)
8866== Block was alloc'd at
8866== at 0x4C3017F: operator new(unsigned long) (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
8866== by 0x1469BB36: 
llvm::object_creator::call() (ManagedStatic.h:24)
8866== by 0x9ABFD99: llvm::ManagedStaticBase::RegisterManagedStatic(void* 
(*)(), void (*)(void*)) const (ManagedStatic.cpp:42)
8866== by 0x1469B5DF: 
llvm::ManagedStatic, 
llvm::object_deleter >::operator*() (ManagedStatic.h:67)
8866== by 0x14698F9D: 
clang::ast_matchers::internal::DynTypedMatcher::trueMatcher(clang::ast_type_traits::ASTNodeKind)
 (ASTMatchersInternal.cpp:195)
8866== by 0x164C9D3B: 
_ZNK5clang12ast_matchers8internal11TrueMatchercvNS1_7MatcherIT_EEINS_8QualTypeEEEv
 (ASTMatchersInternal.h:1247)
8866== by 0x16501458: __static_initialization_and_destruction_0(int, int) 
(LoopConvertCheck.cpp:48)
8866== by 0x16501976: _GLOBAL__sub_I_LoopConvertCheck.cpp 
(LoopConvertCheck.cpp:920)
8866== by 0x4010732: call_init (dl-init.c:72)
8866== by 0x4010732: _dl_init (dl-init.c:119)
8866== by 0x40010C9: ??? (in /lib/x86_64-linux-gnu/ld-2.27.so)

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=363068=363067=363068=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Tue Jun 
11 07:19:09 2019
@@ -44,18 +44,22 @@ static const char DerefByValueResultName
 static const char DerefByRefResultName[] = "derefByRefResult";
 
 // shared matchers
-static const TypeMatcher AnyType = anything();
+static const TypeMatcher AnyType() { return anything(); }
 
-static const StatementMatcher IntegerComparisonMatcher =
-expr(ignoringParenImpCasts(
-
declRefExpr(to(varDecl(hasType(isInteger())).bind(ConditionVarName);
-
-static const DeclarationMatcher InitToZeroMatcher =
-varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral(equals(0)
-.bind(InitVarName);
+static const StatementMatcher IntegerComparisonMatcher() {
+  return expr(ignoringParenImpCasts(
+  declRefExpr(to(varDecl(hasType(isInteger())).bind(ConditionVarName);
+}
+
+static const DeclarationMatcher InitToZeroMatcher() {
+  return varDecl(
+ hasInitializer(ignoringParenImpCasts(integerLiteral(equals(0)
+  .bind(InitVarName);
+}
 
-static const StatementMatcher IncrementVarMatcher =
-declRefExpr(to(varDecl(hasType(isInteger())).bind(IncrementVarName)));
+static const StatementMatcher IncrementVarMatcher() {
+  return declRefExpr(to(varDecl(hasType(isInteger())).bind(IncrementVarName)));
+}
 
 /// \brief The matcher for loops over arrays.
 ///
@@ -81,15 

[PATCH] D63139: [Diagnostics] Implement -Wswitch-unreachable

2019-06-11 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 created this revision.
xbolva00 added reviewers: aaron.ballman, rsmith, rjmccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Detects unreachable statements in switches. GCC supports this warning too, on 
by default.


Repository:
  rC Clang

https://reviews.llvm.org/D63139

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaStmt.cpp
  test/Sema/switch_unreachable.c
  test/SemaCXX/switch_unreachable.cpp

Index: test/SemaCXX/switch_unreachable.cpp
===
--- test/SemaCXX/switch_unreachable.cpp
+++ test/SemaCXX/switch_unreachable.cpp
@@ -0,0 +1,103 @@
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wswitch-unreachable %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+void g(int x);
+
+void foo(int x) {
+  int b = 0;
+  if (x == 7)
+goto label;
+  if (x == 3)
+goto label2;
+  if (x == 4)
+goto label3;
+  if (x == 1)
+goto label4;
+
+  switch (x) {
+  label:
+  case 4:
+break;
+  default:
+return;
+  }
+
+  switch (x) {
+x++; // expected-warning {{statement will be never executed}}
+  label2:
+  case 4:
+break;
+  default:
+return;
+  }
+
+  switch (x) {
+  label3:
+x++;
+  case 4:
+break;
+  default:
+return;
+  }
+
+  switch (x) {
+  case 4:
+return;
+  }
+
+  switch (x) {
+b = x; // expected-warning {{statement will be never executed}}
+  case 7:
+g(b);
+break;
+  }
+
+  switch (x) {
+break; // expected-warning {{statement will be never executed}}
+  case 7:
+break;
+  }
+
+  switch (x) {
+return; // expected-warning {{statement will be never executed}}
+  case 7:
+break;
+  }
+
+  switch (x) {
+x++;  // expected-warning {{statement will be never executed}}
+g(x); // expected-warning {{statement will be never executed}}
+  case 7:
+break;
+  }
+
+  switch (x) {
+x++; // expected-warning {{statement will be never executed}}
+  label4:
+g(x);
+  case 7:
+break;
+  }
+
+  switch (x) {
+g(x); // expected-warning {{statement will be never executed}}
+  case 7:
+break;
+  }
+
+  switch (x) {
+g(x); // expected-warning {{statement will be never executed}}
+  case 1:
+break;
+  case 2:
+break;
+  }
+
+  switch (x) {
+g(x); // expected-warning {{statement will be never executed}}
+  case 1:
+  case 2:
+  case 3:
+break;
+  }
+}
Index: test/Sema/switch_unreachable.c
===
--- test/Sema/switch_unreachable.c
+++ test/Sema/switch_unreachable.c
@@ -0,0 +1,97 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wswitch-unreachable %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+
+void g(int x);
+
+void foo(int x) {
+  int b = 0;
+  if (x == 7)
+goto label;
+  if (x == 3)
+goto label2;
+  if (x == 4)
+goto label3;
+  if (x == 1)
+goto label4;
+
+  switch (x) {
+  label:
+  case 4:
+break;
+  default:
+return;
+  }
+
+  switch (x) {
+x++; // expected-warning {{statement will be never executed}}
+  label2:
+  case 4:
+break;
+  default:
+return;
+  }
+
+  switch (x) {
+  label3:
+x++;
+  case 4:
+break;
+  default:
+return;
+  }
+
+  switch (x) {
+  case 4:
+return;
+  }
+
+  switch (x) {
+b = x; // expected-warning {{statement will be never executed}}
+  case 7:
+g(b);
+break;
+  }
+
+  switch (x) {
+break; // expected-warning {{statement will be never executed}}
+  case 7:
+break;
+  }
+
+  switch (x) {
+return; // expected-warning {{statement will be never executed}}
+  case 7:
+break;
+  }
+
+  switch (x) {
+x++;  // expected-warning {{statement will be never executed}}
+g(x); // expected-warning {{statement will be never executed}}
+  case 7:
+break;
+  }
+
+  switch (x) {
+x++; // expected-warning {{statement will be never executed}}
+  label4:
+g(x);
+  case 7:
+break;
+  }
+
+  switch (x) {
+g(x); // expected-warning {{statement will be never executed}}
+  case 1:
+break;
+  case 2:
+break;
+  }
+
+  switch (x) {
+g(x); // expected-warning {{statement will be never executed}}
+  case 1:
+  case 2:
+  case 3:
+break;
+  }
+}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -861,6 +861,16 @@
   typedef std::vector > CaseRangesTy;
   CaseRangesTy CaseRanges;
 
+  CompoundStmt *CS = dyn_cast(BodyStmt);
+  if (CS && !CS->body_empty()) {
+for (auto It = CS->body_begin(); It != CS->body_end(); ++It) {
+  auto *S = *It;
+  if (isa(S) || isa(S) || isa(S))
+break;
+  Diag(S->getBeginLoc(), diag::warn_unreachable_stmt_in_switch);
+}
+  }
+
   DefaultStmt *TheDefaultStmt = nullptr;
 
   bool CaseListIsErroneous = false;
Index: include/clang/Basic/DiagnosticSemaKinds.td

[PATCH] D48116: [libclang] Allow skipping warnings from all included files

2019-06-11 Thread Nikolai Kosjar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363067: [libclang] Allow skipping warnings from all included 
files (authored by nik, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48116?vs=199015=204060#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D48116

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/include/clang/Frontend/ASTUnit.h
  cfe/trunk/lib/Frontend/ASTUnit.cpp
  cfe/trunk/test/Index/ignore-warnings-from-headers.cpp
  cfe/trunk/test/Index/ignore-warnings-from-headers.h
  cfe/trunk/tools/c-index-test/c-index-test.c
  cfe/trunk/tools/c-index-test/core_main.cpp
  cfe/trunk/tools/libclang/CIndex.cpp
  cfe/trunk/tools/libclang/Indexing.cpp
  cfe/trunk/unittests/Frontend/ASTUnitTest.cpp
  cfe/trunk/unittests/Frontend/PCHPreambleTest.cpp

Index: cfe/trunk/lib/Frontend/ASTUnit.cpp
===
--- cfe/trunk/lib/Frontend/ASTUnit.cpp
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp
@@ -608,17 +608,20 @@
 };
 
 /// Diagnostic consumer that saves each diagnostic it is given.
-class StoredDiagnosticConsumer : public DiagnosticConsumer {
+class FilterAndStoreDiagnosticConsumer : public DiagnosticConsumer {
   SmallVectorImpl *StoredDiags;
   SmallVectorImpl *StandaloneDiags;
+  bool CaptureNonErrorsFromIncludes = true;
   const LangOptions *LangOpts = nullptr;
   SourceManager *SourceMgr = nullptr;
 
 public:
-  StoredDiagnosticConsumer(
+  FilterAndStoreDiagnosticConsumer(
   SmallVectorImpl *StoredDiags,
-  SmallVectorImpl *StandaloneDiags)
-  : StoredDiags(StoredDiags), StandaloneDiags(StandaloneDiags) {
+  SmallVectorImpl *StandaloneDiags,
+  bool CaptureNonErrorsFromIncludes)
+  : StoredDiags(StoredDiags), StandaloneDiags(StandaloneDiags),
+CaptureNonErrorsFromIncludes(CaptureNonErrorsFromIncludes) {
 assert((StoredDiags || StandaloneDiags) &&
"No output collections were passed to StoredDiagnosticConsumer.");
   }
@@ -634,21 +637,25 @@
 const Diagnostic ) override;
 };
 
-/// RAII object that optionally captures diagnostics, if
+/// RAII object that optionally captures and filters diagnostics, if
 /// there is no diagnostic client to capture them already.
 class CaptureDroppedDiagnostics {
   DiagnosticsEngine 
-  StoredDiagnosticConsumer Client;
+  FilterAndStoreDiagnosticConsumer Client;
   DiagnosticConsumer *PreviousClient = nullptr;
   std::unique_ptr OwningPreviousClient;
 
 public:
   CaptureDroppedDiagnostics(
-  bool RequestCapture, DiagnosticsEngine ,
+  CaptureDiagsKind CaptureDiagnostics, DiagnosticsEngine ,
   SmallVectorImpl *StoredDiags,
   SmallVectorImpl *StandaloneDiags)
-  : Diags(Diags), Client(StoredDiags, StandaloneDiags) {
-if (RequestCapture || Diags.getClient() == nullptr) {
+  : Diags(Diags),
+Client(StoredDiags, StandaloneDiags,
+   CaptureDiagnostics !=
+   CaptureDiagsKind::AllWithoutNonErrorsFromIncludes) {
+if (CaptureDiagnostics != CaptureDiagsKind::None ||
+Diags.getClient() == nullptr) {
   OwningPreviousClient = Diags.takeClient();
   PreviousClient = Diags.getClient();
   Diags.setClient(, false);
@@ -667,8 +674,16 @@
 makeStandaloneDiagnostic(const LangOptions ,
  const StoredDiagnostic );
 
-void StoredDiagnosticConsumer::HandleDiagnostic(DiagnosticsEngine::Level Level,
-const Diagnostic ) {
+static bool isInMainFile(const clang::Diagnostic ) {
+  if (!D.hasSourceManager() || !D.getLocation().isValid())
+return false;
+
+  auto  = D.getSourceManager();
+  return M.isWrittenInMainFile(M.getExpansionLoc(D.getLocation()));
+}
+
+void FilterAndStoreDiagnosticConsumer::HandleDiagnostic(
+DiagnosticsEngine::Level Level, const Diagnostic ) {
   // Default implementation (Warnings/errors count).
   DiagnosticConsumer::HandleDiagnostic(Level, Info);
 
@@ -676,6 +691,11 @@
   // about. This effectively drops diagnostics from modules we're building.
   // FIXME: In the long run, ee don't want to drop source managers from modules.
   if (!Info.hasSourceManager() || () == SourceMgr) {
+if (!CaptureNonErrorsFromIncludes && Level <= DiagnosticsEngine::Warning &&
+!isInMainFile(Info)) {
+  return;
+}
+
 StoredDiagnostic *ResultDiag = nullptr;
 if (StoredDiags) {
   StoredDiags->emplace_back(Level, Info);
@@ -723,10 +743,13 @@
 
 /// Configure the diagnostics object for use with ASTUnit.
 void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr Diags,
- ASTUnit , bool CaptureDiagnostics) {
+ ASTUnit ,
+ CaptureDiagsKind CaptureDiagnostics) {
   assert(Diags.get() && "no 

r363067 - [libclang] Allow skipping warnings from all included files

2019-06-11 Thread Nikolai Kosjar via cfe-commits
Author: nik
Date: Tue Jun 11 07:14:24 2019
New Revision: 363067

URL: http://llvm.org/viewvc/llvm-project?rev=363067=rev
Log:
[libclang] Allow skipping warnings from all included files

Depending on the included files and the used warning flags, e.g. -
Weverything, a huge number of warnings can be reported for included
files. As processing that many diagnostics comes with a performance
impact and not all clients are interested in those diagnostics, add a
flag to skip them.

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


Added:
cfe/trunk/test/Index/ignore-warnings-from-headers.cpp
cfe/trunk/test/Index/ignore-warnings-from-headers.h
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/c-index-test/core_main.cpp
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/Indexing.cpp
cfe/trunk/unittests/Frontend/ASTUnitTest.cpp
cfe/trunk/unittests/Frontend/PCHPreambleTest.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=363067=363066=363067=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Jun 11 07:14:24 2019
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 58
+#define CINDEX_VERSION_MINOR 59
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -1346,7 +1346,17 @@ enum CXTranslationUnit_Flags {
   /**
* Used to indicate that implicit attributes should be visited.
*/
-  CXTranslationUnit_VisitImplicitAttributes = 0x2000
+  CXTranslationUnit_VisitImplicitAttributes = 0x2000,
+
+  /**
+   * Used to indicate that non-errors from included files should be ignored.
+   *
+   * If set, clang_getDiagnosticSetFromTU() will not report e.g. warnings from
+   * included files anymore. This speeds up clang_getDiagnosticSetFromTU() for
+   * the case where these warnings are not of interest, as for an IDE for
+   * example, which typically shows only the diagnostics in the main file.
+   */
+  CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles = 0x4000
 };
 
 /**

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=363067=363066=363067=diff
==
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Tue Jun 11 07:14:24 2019
@@ -82,6 +82,9 @@ class TargetInfo;
 /// \brief Enumerates the available scopes for skipping function bodies.
 enum class SkipFunctionBodiesScope { None, Preamble, PreambleAndMainFile };
 
+/// \brief Enumerates the available kinds for capturing diagnostics.
+enum class CaptureDiagsKind { None, All, AllWithoutNonErrorsFromIncludes };
+
 /// Utility class for loading a ASTContext from an AST file.
 class ASTUnit {
 public:
@@ -144,7 +147,7 @@ private:
   bool OnlyLocalDecls = false;
 
   /// Whether to capture any diagnostics produced.
-  bool CaptureDiagnostics = false;
+  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None;
 
   /// Track whether the main file was loaded from an AST or not.
   bool MainFileIsAST;
@@ -250,7 +253,7 @@ private:
   bool UserFilesAreVolatile : 1;
 
   static void ConfigureDiags(IntrusiveRefCntPtr Diags,
- ASTUnit , bool CaptureDiagnostics);
+ ASTUnit , CaptureDiagsKind 
CaptureDiagnostics);
 
   void TranslateStoredDiagnostics(FileManager ,
   SourceManager ,
@@ -661,8 +664,8 @@ public:
   /// Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
   static std::unique_ptr
   create(std::shared_ptr CI,
- IntrusiveRefCntPtr Diags, bool CaptureDiagnostics,
- bool UserFilesAreVolatile);
+ IntrusiveRefCntPtr Diags,
+ CaptureDiagsKind CaptureDiagnostics, bool UserFilesAreVolatile);
 
   enum WhatToLoad {
 /// Load options and the preprocessor state.
@@ -690,7 +693,8 @@ public:
   WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
   const FileSystemOptions , bool UseDebugInfo = false,
   bool OnlyLocalDecls = false, ArrayRef RemappedFiles = None,
-  bool CaptureDiagnostics = false, bool AllowPCHWithCompilerErrors = false,
+  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
+  bool AllowPCHWithCompilerErrors = false,
   bool UserFilesAreVolatile = false);
 
 private:
@@ -748,7 +752,8 @@ public:
   IntrusiveRefCntPtr Diags,
   FrontendAction *Action = nullptr, ASTUnit *Unit = nullptr,
   bool Persistent = true, StringRef 

  1   2   >