[PATCH] D76497: [Syntax] Test both the default and windows target platforms in unittests

2020-03-20 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 251649.
hlopko added a comment.

.equals -> == :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76497

Files:
  clang/unittests/Tooling/Syntax/TreeTest.cpp


Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -47,7 +47,9 @@
 class SyntaxTreeTest : public ::testing::Test {
 protected:
   // Build a syntax tree for the code.
-  syntax::TranslationUnit *buildTree(llvm::StringRef Code) {
+  syntax::TranslationUnit *
+  buildTree(llvm::StringRef Code,
+const std::string &Target = "x86_64-pc-linux-gnu") {
 // FIXME: this code is almost the identical to the one in TokensTest. Share
 //it.
 class BuildSyntaxTree : public ASTConsumer {
@@ -98,9 +100,10 @@
 if (!Diags->getClient())
   Diags->setClient(new IgnoringDiagConsumer);
 // Prepare to run a compiler.
-std::vector Args = {"syntax-test", "-std=c++11",
-  "-fno-delayed-template-parsing",
-  "-fsyntax-only", FileName};
+std::vector Args = {
+"syntax-test", "-target",   Target.c_str(),
+FileName,  "-fsyntax-only", "-std=c++17",
+};
 Invocation = createInvocationFromCommandLine(Args, Diags, FS);
 assert(Invocation);
 Invocation->getFrontendOpts().DisableFree = false;
@@ -121,14 +124,30 @@
 return Root;
   }
 
-  void expectTreeDumpEqual(StringRef code, StringRef tree) {
-SCOPED_TRACE(code);
-
-auto *Root = buildTree(code);
-std::string Expected = tree.trim().str();
-std::string Actual =
-std::string(llvm::StringRef(Root->dump(*Arena)).trim());
-EXPECT_EQ(Expected, Actual) << "the resulting dump is:\n" << Actual;
+  void expectTreeDumpEqual(StringRef Code, StringRef Tree,
+   bool RunWithDelayedTemplateParsing = true) {
+SCOPED_TRACE(Code);
+
+std::string Expected = Tree.trim().str();
+
+// We want to run the test with -fdelayed-template-parsing enabled and
+// disabled, therefore we use these representative targets that differ in
+// the default value.
+// We are not passing -fdelayed-template-parsing directly but we are using
+// the `-target` to improve coverage and discover differences in behavior
+// early.
+for (const std::string Target :
+ {"x86_64-pc-linux-gnu", "x86_64-pc-win32-msvc"}) {
+  if (!RunWithDelayedTemplateParsing &&
+  Target == "x86_64-pc-win32-msvc") {
+continue;
+  }
+  auto *Root = buildTree(Code, Target);
+  std::string Actual = std::string(StringRef(Root->dump(*Arena)).trim());
+  EXPECT_EQ(Expected, Actual)
+  << "for target " << Target << " the resulting dump is:\n"
+  << Actual;
+}
   }
 
   // Adds a file to the test VFS.
@@ -794,7 +813,10 @@
 `-CompoundStatement
   |-{
   `-}
-)txt");
+)txt",
+  // FIXME: Make this test work on windows by generating the expected 
Syntax
+  // tree when -fdelayed-template-parsing is active.
+  /*RunWithDelayedTemplateParsing=*/false);
 }
 
 TEST_F(SyntaxTreeTest, NestedTemplates) {


Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -47,7 +47,9 @@
 class SyntaxTreeTest : public ::testing::Test {
 protected:
   // Build a syntax tree for the code.
-  syntax::TranslationUnit *buildTree(llvm::StringRef Code) {
+  syntax::TranslationUnit *
+  buildTree(llvm::StringRef Code,
+const std::string &Target = "x86_64-pc-linux-gnu") {
 // FIXME: this code is almost the identical to the one in TokensTest. Share
 //it.
 class BuildSyntaxTree : public ASTConsumer {
@@ -98,9 +100,10 @@
 if (!Diags->getClient())
   Diags->setClient(new IgnoringDiagConsumer);
 // Prepare to run a compiler.
-std::vector Args = {"syntax-test", "-std=c++11",
-  "-fno-delayed-template-parsing",
-  "-fsyntax-only", FileName};
+std::vector Args = {
+"syntax-test", "-target",   Target.c_str(),
+FileName,  "-fsyntax-only", "-std=c++17",
+};
 Invocation = createInvocationFromCommandLine(Args, Diags, FS);
 assert(Invocation);
 Invocation->getFrontendOpts().DisableFree = false;
@@ -121,14 +124,30 @@
 return Root;
   }
 
-  void expectTreeDumpEqual(StringRef code, StringRef tree) {
-SCOPED_TRACE(code);
-
-auto *Root = buildTree(code);
-std::string Expected = tree.trim().str();
-std::string Actual =
-std::string(llvm::StringRef(Root->dump(*Arena)).trim());
-EXPECT_EQ(E

[PATCH] D76497: [Syntax] Test both the default and windows target platforms in unittests

2020-03-20 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 251646.
hlopko added a comment.

Polish


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76497

Files:
  clang/unittests/Tooling/Syntax/TreeTest.cpp


Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -47,7 +47,9 @@
 class SyntaxTreeTest : public ::testing::Test {
 protected:
   // Build a syntax tree for the code.
-  syntax::TranslationUnit *buildTree(llvm::StringRef Code) {
+  syntax::TranslationUnit *
+  buildTree(llvm::StringRef Code,
+const std::string &Target = "x86_64-pc-linux-gnu") {
 // FIXME: this code is almost the identical to the one in TokensTest. Share
 //it.
 class BuildSyntaxTree : public ASTConsumer {
@@ -98,9 +100,10 @@
 if (!Diags->getClient())
   Diags->setClient(new IgnoringDiagConsumer);
 // Prepare to run a compiler.
-std::vector Args = {"syntax-test", "-std=c++11",
-  "-fno-delayed-template-parsing",
-  "-fsyntax-only", FileName};
+std::vector Args = {
+"syntax-test", "-target",   Target.c_str(),
+FileName,  "-fsyntax-only", "-std=c++17",
+};
 Invocation = createInvocationFromCommandLine(Args, Diags, FS);
 assert(Invocation);
 Invocation->getFrontendOpts().DisableFree = false;
@@ -121,14 +124,30 @@
 return Root;
   }
 
-  void expectTreeDumpEqual(StringRef code, StringRef tree) {
-SCOPED_TRACE(code);
-
-auto *Root = buildTree(code);
-std::string Expected = tree.trim().str();
-std::string Actual =
-std::string(llvm::StringRef(Root->dump(*Arena)).trim());
-EXPECT_EQ(Expected, Actual) << "the resulting dump is:\n" << Actual;
+  void expectTreeDumpEqual(StringRef Code, StringRef Tree,
+   bool RunWithDelayedTemplateParsing = true) {
+SCOPED_TRACE(Code);
+
+std::string Expected = Tree.trim().str();
+
+// We want to run the test with -fdelayed-template-parsing enabled and
+// disabled, therefore we use these representative targets that differ in
+// the default value.
+// We are not passing -fdelayed-template-parsing directly but we are using
+// the `-target` to improve coverage and discover differences in behavior
+// early.
+for (const std::string Target :
+ {"x86_64-pc-linux-gnu", "x86_64-pc-win32-msvc"}) {
+  if (!RunWithDelayedTemplateParsing &&
+  Target.equals("x86_64-pc-win32-msvc")) {
+continue;
+  }
+  auto *Root = buildTree(Code, Target);
+  std::string Actual = std::string(StringRef(Root->dump(*Arena)).trim());
+  EXPECT_EQ(Expected, Actual)
+  << "for target " << Target << " the resulting dump is:\n"
+  << Actual;
+}
   }
 
   // Adds a file to the test VFS.
@@ -794,7 +813,10 @@
 `-CompoundStatement
   |-{
   `-}
-)txt");
+)txt",
+  // FIXME: Make this test work on windows by generating the expected 
Syntax
+  // tree when -fdelayed-template-parsing is active.
+  /*RunWithDelayedTemplateParsing=*/false);
 }
 
 TEST_F(SyntaxTreeTest, NestedTemplates) {


Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -47,7 +47,9 @@
 class SyntaxTreeTest : public ::testing::Test {
 protected:
   // Build a syntax tree for the code.
-  syntax::TranslationUnit *buildTree(llvm::StringRef Code) {
+  syntax::TranslationUnit *
+  buildTree(llvm::StringRef Code,
+const std::string &Target = "x86_64-pc-linux-gnu") {
 // FIXME: this code is almost the identical to the one in TokensTest. Share
 //it.
 class BuildSyntaxTree : public ASTConsumer {
@@ -98,9 +100,10 @@
 if (!Diags->getClient())
   Diags->setClient(new IgnoringDiagConsumer);
 // Prepare to run a compiler.
-std::vector Args = {"syntax-test", "-std=c++11",
-  "-fno-delayed-template-parsing",
-  "-fsyntax-only", FileName};
+std::vector Args = {
+"syntax-test", "-target",   Target.c_str(),
+FileName,  "-fsyntax-only", "-std=c++17",
+};
 Invocation = createInvocationFromCommandLine(Args, Diags, FS);
 assert(Invocation);
 Invocation->getFrontendOpts().DisableFree = false;
@@ -121,14 +124,30 @@
 return Root;
   }
 
-  void expectTreeDumpEqual(StringRef code, StringRef tree) {
-SCOPED_TRACE(code);
-
-auto *Root = buildTree(code);
-std::string Expected = tree.trim().str();
-std::string Actual =
-std::string(llvm::StringRef(Root->dump(*Arena)).trim());
-EXPECT_EQ(Expect

[PATCH] D76323: [AST] Fix handling of long double and bool in __builtin_bit_cast

2020-03-20 Thread Louis Dionne via Phabricator via cfe-commits
ldionne accepted this revision.
ldionne added a comment.
This revision is now accepted and ready to land.

LGTM at high level, but I'm not really familiar with the code.




Comment at: clang/lib/AST/ExprConstant.cpp:6365
+const llvm::fltSemantics &Semantics = Info.Ctx.getFloatTypeSemantics(Ty);
+unsigned NumBits = APFloat::semanticsSizeInBits(Semantics);
+assert(NumBits % 8 == 0);

`semanticsSizeInBits` is the number of bits actually used in the type?


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

https://reviews.llvm.org/D76323



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


[PATCH] D73898: [analyzer] StdLibraryFunctionsChecker: Add argument constraints

2020-03-20 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 251648.
martong marked an inline comment as done.
martong added a comment.

- Use prefixes for -verify to check different things in the same test file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73898

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions.c

Index: clang/test/Analysis/std-c-library-functions.c
===
--- clang/test/Analysis/std-c-library-functions.c
+++ clang/test/Analysis/std-c-library-functions.c
@@ -1,8 +1,34 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple i686-unknown-linux \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple x86_64-unknown-linux \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple armv7-a15-linux \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple thumbv7-a15-linux \
+// RUN:   -verify
 
 void clang_analyzer_eval(int);
 
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -0,0 +1,61 @@
+// Check the basic reporting/warning and the application of constraints.
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -triple x86_64-unknown-linux-gnu \
+// RUN:   -verify=report
+
+// Check the bugpath related to the reports.
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -triple x86_64-unknown-linux-gnu \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify=bugpath
+
+void clang_analyzer_eval(int);
+
+int glob;
+
+#define EOF -1
+
+int isalnum(int);
+
+void test_alnum_concrete(int v) {
+  int ret = isalnum(256); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+  (void)ret;
+}
+
+void test_alnum_symbolic(int x) {
+  int ret = isalnum(x);
+  (void)ret;
+
+  clang_analyzer_eval(EOF <= x && x <= 255); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{Left side of '&&' is true}} \
+  // bugpath-note{{'x' is <= 255}}
+
+}
+
+void test_alnum_symbolic2(int x) {
+  if (x > 255) { // \
+// bugpath-note{{Assuming 'x' is > 255}} \
+// bugpath-note{{Taking true branch}}
+
+int ret = isalnum(x); // \
+// report-warning{{Function argument constraint is not satisfied}} \
+// bugpath-warning{{Function argument constraint is not satisfie

[PATCH] D73898: [analyzer] StdLibraryFunctionsChecker: Add argument constraints

2020-03-20 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added a comment.

Thanks for the review guys!




Comment at: clang/test/Analysis/std-c-library-functions-arg-constraints.c:1-7
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -triple x86_64-unknown-linux-gnu \
+// RUN:   -verify

Szelethus wrote:
> martong wrote:
> > Szelethus wrote:
> > > Hmm, why do we have 2 different test files that essentially do the same? 
> > > Shouldn't we only have a single one with `analyzer-output=text`?
> > No, I wanted to have two different test files to test two different things: 
> > (1) We do have the constraints applied (here we don't care about the 
> > warnings and the path)
> > (2) Check that we have a warning with the proper tracking and notes.
> What if we had different `-verify`s? 
> `clang/test/Analysis/track-conditions.cpp` is a great example.
Yeah, that's a very good approach, I just changed it like that. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73898



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


[PATCH] D76491: [ARM,MVE] Add ACLE intrinsics for the vaddv/vaddlv family.

2020-03-20 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

Sounds great, from what I can see. The predicated lowering looks useful when/if 
we try and get predicated vecreduce's working.

We'll have to do the same for VMLA at some point.
LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76491



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


[PATCH] D76504: [clang] Fix crash during template sema checking

2020-03-20 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added a comment.

Buggy trace here 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76504



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


[PATCH] D73245: Depend stddef.h to provide max_align_t for C++11 and provide better fallback in

2020-03-20 Thread Louis Dionne via Phabricator via cfe-commits
ldionne requested changes to this revision.
ldionne added a comment.
This revision now requires changes to proceed.

I think the direction works, but I have questions about some thing I don't 
understand (mostly in the tests).




Comment at: libcxx/include/stddef.h:58
 !defined(__DEFINED_max_align_t) && !defined(__NetBSD__)
 typedef long double max_align_t;
 #endif

Why do we need this at all anymore? In C++11, can't we rely on the C Standard 
Library providing it `::max_align_t`?



Comment at: 
libcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp:40
+#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
+std::size_t maxSize = std::numeric_limits::max()
+- __STDCPP_DEFAULT_NEW_ALIGNMENT__;

This test is only enabled in >= C++11, so I think `std::max_align_t` should 
always be provided. So why do we want that `#if`?



Comment at: 
libcxx/test/std/language.support/support.types/max_align_t.pass.cpp:47
+#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
+static_assert(std::alignment_of::value <=
+  __STDCPP_DEFAULT_NEW_ALIGNMENT__,

Since we now assume that `__STDCPP_DEFAULT_NEW_ALIGNMENT__` is defined, can we 
remove that `#if` and keep the assertion?



Comment at: 
libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp:275
+#if TEST_STD_VER >= 11
+const size_t alignment = TEST_ALIGNOF(std::max_align_t) > 16 ?
+16 : TEST_ALIGNOF(std::max_align_t);

Can you walk me through why the check for `> 16` is required?


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

https://reviews.llvm.org/D73245



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


[PATCH] D76504: [clang] Fix crash during template sema checking

2020-03-20 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet created this revision.
gchatelet added reviewers: efriedma, courbet.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
gchatelet added a subscriber: abrachet.
gchatelet added a comment.

Buggy trace here 



If the size parameter of `__builtin_memcpy_inline` comes from an 
un-instantiated template parameter current code would crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76504

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtins-memcpy-inline.c
  clang/test/Sema/builtins-memcpy-inline.cpp


Index: clang/test/Sema/builtins-memcpy-inline.cpp
===
--- clang/test/Sema/builtins-memcpy-inline.cpp
+++ clang/test/Sema/builtins-memcpy-inline.cpp
@@ -30,3 +30,9 @@
 void test_memcpy_inline_non_constant_size(void *dst, const void *src, unsigned 
size) {
   __builtin_memcpy_inline(dst, src, size); // expected-error {{argument to 
'__builtin_memcpy_inline' must be a constant integer}}
 }
+
+template 
+void test_memcpy_inline_template(void *dst, const void *src) {
+  // we do not try to evaluate size in non intantiated templates.
+  __builtin_memcpy_inline(dst, src, size);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1649,11 +1649,18 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
+clang::Expr *DstOp = TheCall->getArg(0);
+clang::Expr *SrcOp = TheCall->getArg(1);
+clang::Expr *SizeOp = TheCall->getArg(2);
+// If any arg is instantiation dependent we bail out.
+if (DstOp->isInstantiationDependent() ||
+SrcOp->isInstantiationDependent() || 
SizeOp->isInstantiationDependent())
+  break;
 // __builtin_memcpy_inline size argument is a constant by definition.
-if (TheCall->getArg(2)->EvaluateKnownConstInt(Context).isNullValue())
+if (SizeOp->EvaluateKnownConstInt(Context).isNullValue())
   break;
-CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
-CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+CheckNonNullArgument(*this, DstOp, TheCall->getExprLoc());
+CheckNonNullArgument(*this, SrcOp, TheCall->getExprLoc());
 break;
   }
 #define BUILTIN(ID, TYPE, ATTRS)


Index: clang/test/Sema/builtins-memcpy-inline.cpp
===
--- clang/test/Sema/builtins-memcpy-inline.cpp
+++ clang/test/Sema/builtins-memcpy-inline.cpp
@@ -30,3 +30,9 @@
 void test_memcpy_inline_non_constant_size(void *dst, const void *src, unsigned size) {
   __builtin_memcpy_inline(dst, src, size); // expected-error {{argument to '__builtin_memcpy_inline' must be a constant integer}}
 }
+
+template 
+void test_memcpy_inline_template(void *dst, const void *src) {
+  // we do not try to evaluate size in non intantiated templates.
+  __builtin_memcpy_inline(dst, src, size);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1649,11 +1649,18 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
+clang::Expr *DstOp = TheCall->getArg(0);
+clang::Expr *SrcOp = TheCall->getArg(1);
+clang::Expr *SizeOp = TheCall->getArg(2);
+// If any arg is instantiation dependent we bail out.
+if (DstOp->isInstantiationDependent() ||
+SrcOp->isInstantiationDependent() || SizeOp->isInstantiationDependent())
+  break;
 // __builtin_memcpy_inline size argument is a constant by definition.
-if (TheCall->getArg(2)->EvaluateKnownConstInt(Context).isNullValue())
+if (SizeOp->EvaluateKnownConstInt(Context).isNullValue())
   break;
-CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
-CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+CheckNonNullArgument(*this, DstOp, TheCall->getExprLoc());
+CheckNonNullArgument(*this, SrcOp, TheCall->getExprLoc());
 break;
   }
 #define BUILTIN(ID, TYPE, ATTRS)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75661: Remove SequentialType from the type heirarchy.

2020-03-20 Thread Christopher Tetreault via Phabricator via cfe-commits
ctetreau added inline comments.
Herald added a reviewer: aartbik.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1059
+llvm::Type *ElemTy = ArrayTy->getElementType();
+bool ZeroInitializer = constant->isNullValue();
 llvm::Constant *OpValue, *PaddedOp;

I assume the reasoning here is that [-0.0f, ...] isn't the zero initialized 
value, but why make this change now? Seems unrelated.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1078
   }
+  // FIXME: Do we need to handle tail padding in vectors?
   return constant;

The fact that you have to ask this question tells me that you should probably 
just make this handle vectors.

You could add a templated helper function above this function that is basically 
just the original body of the SequentialType branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75661



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


[PATCH] D73898: [analyzer] StdLibraryFunctionsChecker: Add argument constraints

2020-03-20 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG94061df6e5f2: [analyzer] StdLibraryFunctionsChecker: Add 
argument constraints (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73898

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions.c

Index: clang/test/Analysis/std-c-library-functions.c
===
--- clang/test/Analysis/std-c-library-functions.c
+++ clang/test/Analysis/std-c-library-functions.c
@@ -1,8 +1,34 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple i686-unknown-linux \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple x86_64-unknown-linux \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple armv7-a15-linux \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple thumbv7-a15-linux \
+// RUN:   -verify
 
 void clang_analyzer_eval(int);
 
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -0,0 +1,61 @@
+// Check the basic reporting/warning and the application of constraints.
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -triple x86_64-unknown-linux-gnu \
+// RUN:   -verify=report
+
+// Check the bugpath related to the reports.
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -triple x86_64-unknown-linux-gnu \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify=bugpath
+
+void clang_analyzer_eval(int);
+
+int glob;
+
+#define EOF -1
+
+int isalnum(int);
+
+void test_alnum_concrete(int v) {
+  int ret = isalnum(256); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+  (void)ret;
+}
+
+void test_alnum_symbolic(int x) {
+  int ret = isalnum(x);
+  (void)ret;
+
+  clang_analyzer_eval(EOF <= x && x <= 255); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{Left side of '&&' is true}} \
+  // bugpath-note{{'x' is <= 255}}
+
+}
+
+void test_alnum_symbolic2(int x) {
+  if (x > 255) { // \
+// bugpath-note{{Assuming 'x' is > 255}} \
+// bugpath-note{{Taking true branch}}
+
+int ret = isalnum(x); // \
+// report-warning{{Function argument constraint is not satisfied}} \
+// bugpath-warning{{Function argument constraint is not sat

[PATCH] D76497: [Syntax] Test both the default and windows target platforms in unittests

2020-03-20 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeddede9d5184: [Syntax] Test both the default and windows 
target platforms in unittests (authored by hlopko, committed by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76497

Files:
  clang/unittests/Tooling/Syntax/TreeTest.cpp


Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -47,7 +47,9 @@
 class SyntaxTreeTest : public ::testing::Test {
 protected:
   // Build a syntax tree for the code.
-  syntax::TranslationUnit *buildTree(llvm::StringRef Code) {
+  syntax::TranslationUnit *
+  buildTree(llvm::StringRef Code,
+const std::string &Target = "x86_64-pc-linux-gnu") {
 // FIXME: this code is almost the identical to the one in TokensTest. Share
 //it.
 class BuildSyntaxTree : public ASTConsumer {
@@ -98,9 +100,10 @@
 if (!Diags->getClient())
   Diags->setClient(new IgnoringDiagConsumer);
 // Prepare to run a compiler.
-std::vector Args = {"syntax-test", "-std=c++11",
-  "-fno-delayed-template-parsing",
-  "-fsyntax-only", FileName};
+std::vector Args = {
+"syntax-test", "-target",   Target.c_str(),
+FileName,  "-fsyntax-only", "-std=c++17",
+};
 Invocation = createInvocationFromCommandLine(Args, Diags, FS);
 assert(Invocation);
 Invocation->getFrontendOpts().DisableFree = false;
@@ -121,14 +124,30 @@
 return Root;
   }
 
-  void expectTreeDumpEqual(StringRef code, StringRef tree) {
-SCOPED_TRACE(code);
-
-auto *Root = buildTree(code);
-std::string Expected = tree.trim().str();
-std::string Actual =
-std::string(llvm::StringRef(Root->dump(*Arena)).trim());
-EXPECT_EQ(Expected, Actual) << "the resulting dump is:\n" << Actual;
+  void expectTreeDumpEqual(StringRef Code, StringRef Tree,
+   bool RunWithDelayedTemplateParsing = true) {
+SCOPED_TRACE(Code);
+
+std::string Expected = Tree.trim().str();
+
+// We want to run the test with -fdelayed-template-parsing enabled and
+// disabled, therefore we use these representative targets that differ in
+// the default value.
+// We are not passing -fdelayed-template-parsing directly but we are using
+// the `-target` to improve coverage and discover differences in behavior
+// early.
+for (const std::string Target :
+ {"x86_64-pc-linux-gnu", "x86_64-pc-win32-msvc"}) {
+  if (!RunWithDelayedTemplateParsing &&
+  Target == "x86_64-pc-win32-msvc") {
+continue;
+  }
+  auto *Root = buildTree(Code, Target);
+  std::string Actual = std::string(StringRef(Root->dump(*Arena)).trim());
+  EXPECT_EQ(Expected, Actual)
+  << "for target " << Target << " the resulting dump is:\n"
+  << Actual;
+}
   }
 
   // Adds a file to the test VFS.
@@ -794,7 +813,10 @@
 `-CompoundStatement
   |-{
   `-}
-)txt");
+)txt",
+  // FIXME: Make this test work on windows by generating the expected 
Syntax
+  // tree when -fdelayed-template-parsing is active.
+  /*RunWithDelayedTemplateParsing=*/false);
 }
 
 TEST_F(SyntaxTreeTest, NestedTemplates) {


Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -47,7 +47,9 @@
 class SyntaxTreeTest : public ::testing::Test {
 protected:
   // Build a syntax tree for the code.
-  syntax::TranslationUnit *buildTree(llvm::StringRef Code) {
+  syntax::TranslationUnit *
+  buildTree(llvm::StringRef Code,
+const std::string &Target = "x86_64-pc-linux-gnu") {
 // FIXME: this code is almost the identical to the one in TokensTest. Share
 //it.
 class BuildSyntaxTree : public ASTConsumer {
@@ -98,9 +100,10 @@
 if (!Diags->getClient())
   Diags->setClient(new IgnoringDiagConsumer);
 // Prepare to run a compiler.
-std::vector Args = {"syntax-test", "-std=c++11",
-  "-fno-delayed-template-parsing",
-  "-fsyntax-only", FileName};
+std::vector Args = {
+"syntax-test", "-target",   Target.c_str(),
+FileName,  "-fsyntax-only", "-std=c++17",
+};
 Invocation = createInvocationFromCommandLine(Args, Diags, FS);
 assert(Invocation);
 Invocation->getFrontendOpts().DisableFree = false;
@@ -121,14 +124,30 @@
 return Root;
   }
 
-  void expectTreeDumpEqual(StringRef code, StringRef tree) {
-SCOPED_TRACE(code);
-
-auto *Root = buildTree(code);
-std::string

[clang] 45a9945 - [ARM, MVE] Add ACLE intrinsics for the vminv/vmaxv family.

2020-03-20 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2020-03-20T15:42:33Z
New Revision: 45a9945b9ea95bd065d3c4e08d9089a309b24a23

URL: 
https://github.com/llvm/llvm-project/commit/45a9945b9ea95bd065d3c4e08d9089a309b24a23
DIFF: 
https://github.com/llvm/llvm-project/commit/45a9945b9ea95bd065d3c4e08d9089a309b24a23.diff

LOG: [ARM,MVE] Add ACLE intrinsics for the vminv/vmaxv family.

Summary:
I've implemented these as target-specific IR intrinsics, because
they're not //quite// enough like @llvm.experimental.vector.reduce.min
(which doesn't take the extra scalar parameter). Also this keeps the
predicated and unpredicated versions looking similar, and the
floating-point minnm/maxnm versions fold into the same schema.

We had a couple of min/max reductions already implemented, from the
initial pathfinding exercise in D67158. Those were done by having
separate IR intrinsic names for the signed and unsigned integer
versions; as part of this commit, I've changed them to use a flag
parameter indicating signedness, which is how we ended up deciding
that the rest of the MVE intrinsics family ought to work. So now
hopefully the ewhole lot is consistent.

In the new llc test, the output code from the `v8f16` test functions
looks quite unpleasant, but most of it is PCS lowering (you can't pass
a `half` directly in or out of a function). In other circumstances,
where you do something else with your `half` in the same function, it
doesn't look nearly as nasty.

Reviewers: dmgreen, MarkMurrayARM, miyuki, ostannard

Reviewed By: MarkMurrayARM

Subscribers: kristof.beyls, hiraditya, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/arm_mve.td
clang/test/CodeGen/arm-mve-intrinsics/vminvq.c
llvm/include/llvm/IR/IntrinsicsARM.td
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/lib/Target/ARM/ARMInstrMVE.td
llvm/test/CodeGen/Thumb2/mve-intrinsics/vminvq.ll

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index 45e45899de5f..d32f7fd92f2c 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -536,11 +536,42 @@ let params = T.Float in {
 (IRInt<"vmaxnma_predicated", 
[Vector,Predicate]> $a, $b, $pred)>;
 }
 
+multiclass Reduction basetypes,
+ bit needSign = 0,
+ dag postCG = (seq (id $ret)),
+ dag accArg = (args Accumulator:$prev),
+ dag preCG = (seq)> {
+  defvar intArgsBase   = (? $prev, $vec);
+  defvar intArgsUnpred = !con(intArgsBase,
+  !if(needSign, (? (unsignedflag Scalar)), (?)));
+  defvar intArgsPred   = !con(intArgsUnpred, (? $pred));
+  defvar intUnpred = !setop(intArgsUnpred, IRInt);
+  defvar intPred   = !setop(intArgsPred, IRInt<
+basename#"_predicated", !listconcat(basetypes, [Predicate])>);
+
+  def "": Intrinsic<
+Accumulator, !con(accArg, (args Vector:$vec)),
+!con(preCG, (seq intUnpred:$ret), postCG)>;
+  def _p: Intrinsic<
+Accumulator, !con(accArg, (args Vector:$vec, Predicate:$pred)),
+!con(preCG, (seq intPred:$ret), postCG)>;
+}
+
 let params = T.Int in {
-def vminvq: Intrinsic $prev, $vec))>;
-def vmaxvq: Intrinsic $prev, $vec))>;
+defm vminvq: Reduction;
+defm vmaxvq: Reduction;
+}
+
+let params = T.Signed in {
+defm vminavq: Reduction;
+defm vmaxavq: Reduction;
+}
+
+let params = T.Float in {
+defm vminnmvq: Reduction;
+defm vmaxnmvq: Reduction;
+defm vminnmavq: Reduction;
+defm vmaxnmavq: Reduction;
 }
 
 foreach half = [ "b", "t" ] in {

diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/vminvq.c 
b/clang/test/CodeGen/arm-mve-intrinsics/vminvq.c
index 1cf4d0ee198e..0d484bf98f7a 100644
--- a/clang/test/CodeGen/arm-mve-intrinsics/vminvq.c
+++ b/clang/test/CodeGen/arm-mve-intrinsics/vminvq.c
@@ -1,97 +1,853 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature 
+mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O0 
-disable-O0-optnone -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
-// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature 
+mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O0 
-disable-O0-optnone -DPOLYMORPHIC -S -emit-llvm -o - %s | opt -S -mem2reg | 
FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature 
+mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O0 
-disable-O0-optnone -S -emit-llvm -o - %s | opt -S -mem2reg -sroa | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature 
+mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O0 
-disable-O0-optnone -DPOLYMORPHIC -S -emit-llvm -o - %s | opt -S -mem2reg -sroa 
| FileCheck %s

[clang] 1adfa4c - [ARM, MVE] Add ACLE intrinsics for the vaddv/vaddlv family.

2020-03-20 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2020-03-20T15:42:33Z
New Revision: 1adfa4c99169733dedb67b4f7ab03d2fbb196162

URL: 
https://github.com/llvm/llvm-project/commit/1adfa4c99169733dedb67b4f7ab03d2fbb196162
DIFF: 
https://github.com/llvm/llvm-project/commit/1adfa4c99169733dedb67b4f7ab03d2fbb196162.diff

LOG: [ARM,MVE] Add ACLE intrinsics for the vaddv/vaddlv family.

Summary:
I've implemented them as target-specific IR intrinsics rather than
using `@llvm.experimental.vector.reduce.add`, on the grounds that the
'experimental' intrinsic doesn't currently have much code generation
benefit, and my replacements encapsulate the sign- or zero-extension
so that you don't expose the illegal MVE vector type (`<4 x i64>`) in
IR.

The machine instructions come in two versions: with and without an
input accumulator. My new IR intrinsics, like the 'experimental' one,
don't take an accumulator parameter: we represent that by just adding
on the input value using an ordinary i32 or i64 add. So if you write
the `vaddvaq` C-language intrinsic with an input accumulator of zero,
it can be optimised to VADDV, and conversely, if you write something
like `x += vaddvq(y)` then that can be combined into VADDVA.

Most of this is achieved in isel lowering, by converting these IR
intrinsics into the existing `ARMISD::VADDV` family of custom SDNode
types. For the difficult case (64-bit accumulators), isel lowering
already implements the optimization of folding an addition into a
VADDLV to make a VADDLVA; so once we've made a VADDLV, our job is
already done, except that I had to introduce a parallel set of ARMISD
nodes for the //predicated// forms of VADDLV.

For the simpler VADDV, we handle the predicated form by just leaving
the IR intrinsic alone and matching it in an ordinary dag pattern.

Reviewers: dmgreen, MarkMurrayARM, miyuki, ostannard

Reviewed By: dmgreen

Subscribers: kristof.beyls, hiraditya, danielkiss, cfe-commits

Tags: #clang

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

Added: 
clang/test/CodeGen/arm-mve-intrinsics/vaddv.c
llvm/test/CodeGen/Thumb2/mve-intrinsics/vaddv.ll

Modified: 
clang/include/clang/Basic/arm_mve.td
llvm/include/llvm/IR/IntrinsicsARM.td
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/lib/Target/ARM/ARMISelLowering.h
llvm/lib/Target/ARM/ARMInstrMVE.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index d32f7fd92f2c..25daae2a0a25 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -1445,6 +1445,33 @@ multiclass MVEBinaryVectorHoriz64R {
"vrmlldavha">;
 }
 
+multiclass VADDV {
+  defvar accArg = !if(acc, (args Scalar:$acc), (args));
+  defvar predArg = !if(pred, (args Predicate:$pred), (args));
+  defvar intrinsic = !if(pred,
+  IRInt,
+  IRInt);
+  defvar intCG = !con((intrinsic $v, (unsignedflag Scalar)),
+  !if(pred, (? $pred), (?)));
+  defvar accCG = !if(acc, (add intCG, $acc), intCG);
+
+  def "": Intrinsic;
+}
+
+let params = T.Int in {
+defm vaddvq: VADDV<0, 0, "addv", Scalar32>;
+defm vaddvaq   : VADDV<1, 0, "addv", Scalar32>;
+defm vaddvq_p  : VADDV<0, 1, "addv", Scalar32>;
+defm vaddvaq_p : VADDV<1, 1, "addv", Scalar32>;
+}
+
+let params = [s32, u32] in {
+defm vaddlvq: VADDV<0, 0, "addlv", Scalar64>;
+defm vaddlvaq   : VADDV<1, 0, "addlv", Scalar64>;
+defm vaddlvq_p  : VADDV<0, 1, "addlv", Scalar64>;
+defm vaddlvaq_p : VADDV<1, 1, "addlv", Scalar64>;
+}
+
 let params = T.Int in {
 def vabavq : Intrinsic (unsignedflag Scalar), $a, $b, $c)>;

diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/vaddv.c 
b/clang/test/CodeGen/arm-mve-intrinsics/vaddv.c
new file mode 100644
index ..6bacc2775881
--- /dev/null
+++ b/clang/test/CodeGen/arm-mve-intrinsics/vaddv.c
@@ -0,0 +1,470 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+ // RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature +mve 
-mfloat-abi hard -O0 -disable-O0-optnone -S -emit-llvm -o - %s | opt -S 
-mem2reg | FileCheck %s
+ // RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature +mve 
-mfloat-abi hard -O0 -disable-O0-optnone -DPOLYMORPHIC -S -emit-llvm -o - %s | 
opt -S -mem2reg | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @test_vaddvq_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 @llvm.arm.mve.addv.v16i8(<16 x i8> 
[[A:%.*]], i32 0)
+// CHECK-NEXT:ret i32 [[TMP0]]
+//
+int32_t test_vaddvq_s8(int8x16_t a) {
+#ifdef POLYMORPHIC
+  return vaddvq(a);
+#else  /* POLYMORPHIC */
+  return vaddvq_s8(a);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @test_vaddvq_s16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 @llvm.arm.mve.addv.v8i16(<8 x i16> 
[[A:%.*]], i32 0)
+// CHECK-NEXT:ret i32 [[TMP0]]
+//
+int32_t test_vaddvq_s16(in

[clang] ffcc076 - [[Clang CallGraph]] CallGraph should still record calls to decls.

2020-03-20 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2020-03-20T08:55:23-07:00
New Revision: ffcc076a2b23363025de2f67243086963f235b20

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

LOG: [[Clang CallGraph]] CallGraph should still record calls to decls.

Discovered by a downstream user, we found that the CallGraph ignores
callees unless they are defined.  This seems foolish, and prevents
combining the report with other reports to create unified reports.
Additionally, declarations contain information that is likely useful to
consumers of the CallGraph.

This patch implements this by splitting the includeInGraph function into
two versions, the current one plus one that is for callees only.  The
only difference currently is that includeInGraph checks for a body, then
calls includeCalleeInGraph.

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

Added: 


Modified: 
clang/include/clang/Analysis/CallGraph.h
clang/lib/Analysis/CallGraph.cpp
clang/test/Analysis/debug-CallGraph.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/CallGraph.h 
b/clang/include/clang/Analysis/CallGraph.h
index 041050319239..6f7159330f5d 100644
--- a/clang/include/clang/Analysis/CallGraph.h
+++ b/clang/include/clang/Analysis/CallGraph.h
@@ -66,6 +66,11 @@ class CallGraph : public RecursiveASTVisitor {
   /// Determine if a declaration should be included in the graph.
   static bool includeInGraph(const Decl *D);
 
+  /// Determine if a declaration should be included in the graph for the 
+  /// purposes of being a callee. This is similar to includeInGraph except
+  /// it permits declarations, not just definitions.
+  static bool includeCalleeInGraph(const Decl *D);
+
   /// Lookup the node for the given declaration.
   CallGraphNode *getNode(const Decl *) const;
 

diff  --git a/clang/lib/Analysis/CallGraph.cpp 
b/clang/lib/Analysis/CallGraph.cpp
index 419f3ad2e724..59cc939b6fd1 100644
--- a/clang/lib/Analysis/CallGraph.cpp
+++ b/clang/lib/Analysis/CallGraph.cpp
@@ -67,7 +67,7 @@ class CGBuilder : public StmtVisitor {
   }
 
   void addCalledDecl(Decl *D, Expr *CallExpr) {
-if (G->includeInGraph(D)) {
+if (G->includeCalleeInGraph(D)) {
   CallGraphNode *CalleeNode = G->getOrInsertNode(D);
   CallerNode->addCallee({CalleeNode, CallExpr});
 }
@@ -157,6 +157,10 @@ bool CallGraph::includeInGraph(const Decl *D) {
   if (!D->hasBody())
 return false;
 
+  return includeCalleeInGraph(D);
+}
+
+bool CallGraph::includeCalleeInGraph(const Decl *D) {
   if (const FunctionDecl *FD = dyn_cast(D)) {
 // We skip function template definitions, as their semantics is
 // only determined when they are instantiated.

diff  --git a/clang/test/Analysis/debug-CallGraph.cpp 
b/clang/test/Analysis/debug-CallGraph.cpp
index 5453e2f21533..120bb38d3bb3 100644
--- a/clang/test/Analysis/debug-CallGraph.cpp
+++ b/clang/test/Analysis/debug-CallGraph.cpp
@@ -97,9 +97,10 @@ namespace CallDecl {
 }
 
 // CHECK:--- Call graph Dump ---
-// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > 
bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ 
SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(anonymous 
class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) 
CallDecl::SomeDef CallDecl::Caller CallDecl::SomeOtherDecl $}}
-// CHECK-NEXT: {{Function: CallDecl::Caller calls: CallDecl::SomeOtherDecl $}}
+// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > 
bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ 
SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(anonymous 
class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) 
CallDecl::SomeDef CallDecl::Caller CallDecl::SomeDecl CallDecl::SomeOtherDecl 
$}}
+// CHECK-NEXT: {{Function: CallDecl::Caller calls: CallDecl::SomeDecl 
CallDecl::SomeOtherDecl $}}
 // CHECK-NEXT: {{Function: CallDecl::SomeOtherDecl calls: CallDecl::SomeDef $}}
+// CHECK-NEXT: {{Function: CallDecl::SomeDecl calls: $}}
 // CHECK-NEXT: {{Function: CallDecl::SomeDef calls: $}}
 // CHECK-NEXT: {{Function: Lambdas::f1 calls: Lambdas::f1\(\)::\(anonymous 
class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) $}}
 // CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) 
calls: Lambdas::Callee $}}



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


[clang] ce5173c - Use FinishThunk to finish musttail thunks

2020-03-20 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2020-03-20T09:02:21-07:00
New Revision: ce5173c0e174870934d1b3a026f631d996136191

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

LOG: Use FinishThunk to finish musttail thunks

FinishThunk, and the invariant of setting and then unsetting
CurCodeDecl, was added in 7f416cc42638 (2015). The invariant didn't
exist when I added this musttail codepath in ab2090d10765 (2014).
Recently in 28328c3771, I started using this codepath on non-Windows
platforms, and users reported problems during release testing (PR44987).

The issue was already present for users of EH on i686-windows-msvc, so I
added a test for that case as well.

Reviewed By: hans

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

Added: 
clang/test/CodeGenCXX/ms-thunks-ehspec.cpp
clang/test/CodeGenCXX/thunks-ehspec.cpp

Modified: 
clang/lib/CodeGen/CGVTables.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 403b9e25f7a3..412fc693c5b2 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -437,7 +437,8 @@ void CodeGenFunction::EmitMustTailThunk(GlobalDecl GD,
   // Finish the function to maintain CodeGenFunction invariants.
   // FIXME: Don't emit unreachable code.
   EmitBlock(createBasicBlock());
-  FinishFunction();
+
+  FinishThunk();
 }
 
 void CodeGenFunction::generateThunk(llvm::Function *Fn,
@@ -564,7 +565,7 @@ llvm::Constant *CodeGenVTables::maybeEmitThunk(GlobalDecl 
GD,
   CGM.SetLLVMFunctionAttributesForDefinition(GD.getDecl(), ThunkFn);
 
   // Thunks for variadic methods are special because in general variadic
-  // arguments cannot be perferctly forwarded. In the general case, clang
+  // arguments cannot be perfectly forwarded. In the general case, clang
   // implements such thunks by cloning the original function body. However, for
   // thunks with no return adjustment on targets that support musttail, we can
   // use musttail to perfectly forward the variadic arguments.

diff  --git a/clang/test/CodeGenCXX/ms-thunks-ehspec.cpp 
b/clang/test/CodeGenCXX/ms-thunks-ehspec.cpp
new file mode 100644
index ..f72100d5078b
--- /dev/null
+++ b/clang/test/CodeGenCXX/ms-thunks-ehspec.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fexceptions -fcxx-exceptions %s -triple=i686-windows-msvc 
-emit-llvm -o - | FileCheck %s
+
+// When generating thunks using musttail due to inalloca parameters, don't push
+// and pop terminate scopes. PR44987
+
+struct NonTrivial {
+  NonTrivial();
+  NonTrivial(const NonTrivial &o);
+  ~NonTrivial();
+  int x;
+};
+struct A {
+  virtual void f(NonTrivial o) noexcept;
+};
+struct B {
+  virtual void f(NonTrivial o) noexcept;
+};
+class C : A, B {
+  virtual void f(NonTrivial o) noexcept;
+};
+C c;
+
+// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void 
@"?f@C@@G3AEXUNonTrivial@@@Z"(%class.C* %this, <{ %struct.NonTrivial }>* 
inalloca %0)
+// CHECK-NOT: invoke
+// CHECK: musttail call x86_thiscallcc void 
@"?f@C@@EAEXUNonTrivial@@@Z"(%class.C* %{{.*}}, <{ %struct.NonTrivial }>* 
inalloca %0)
+// CHECK-NEXT  ret void
+

diff  --git a/clang/test/CodeGenCXX/thunks-ehspec.cpp 
b/clang/test/CodeGenCXX/thunks-ehspec.cpp
new file mode 100644
index ..30276948d3fc
--- /dev/null
+++ b/clang/test/CodeGenCXX/thunks-ehspec.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fexceptions -fcxx-exceptions %s 
-triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 
-disable-llvm-passes | FileCheck %s
+
+// When generating the thunk for secondary, do not push terminate scopes for
+// either the varargs or non-varargs case. Related to PR44987.
+
+struct A {
+  virtual void primary_key();
+};
+struct B {
+  virtual void secondary();
+  virtual void secondary_vararg(int, ...);
+};
+class C : A, B {
+  virtual void primary_key();
+  void secondary() noexcept;
+  void secondary_vararg(int, ...) noexcept;
+};
+void C::primary_key() {}
+
+// CHECK-LABEL: define available_externally void 
@_ZThn8_N1C9secondaryEv(%class.C* %this)
+// CHECK-NOT: invoke
+// CHECK: tail call void @_ZN1C9secondaryEv(%class.C* %{{.*}})
+// CHECK-NOT: invoke
+// CHECK: ret void
+
+// CHECK-LABEL: define available_externally void 
@_ZThn8_N1C16secondary_varargEiz(%class.C* %this, i32 %0, ...)
+// CHECK-NOT: invoke
+// CHECK:  musttail call void (%class.C*, i32, ...) 
@_ZN1C16secondary_varargEiz(%class.C* %{{.*}}, i32 %{{.*}}, ...) #2
+// CHECK-NEXT:  ret void



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


[PATCH] D76504: [clang] Fix crash during template sema checking

2020-03-20 Thread Clement Courbet via Phabricator via cfe-commits
courbet added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:1655
+clang::Expr *SizeOp = TheCall->getArg(2);
+// If any arg is instantiation dependent we bail out.
+if (DstOp->isInstantiationDependent() ||

Are the first two necessary ? IIRC only `EvaluateKnownConstInt()` does not like 
template-dependent stuff. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76504



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


[PATCH] D76078: [AArch64][SVE] Add a pass for SVE intrinsic optimisations

2020-03-20 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin updated this revision to Diff 251643.
kmclaughlin marked 13 inline comments as done.
kmclaughlin added a comment.

- Changed this from a function pass to a module pass & now check if any of the 
relevant SVE intrinsics are declared first before iterating over functions
- Added more checks on expected output in the tests


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

https://reviews.llvm.org/D76078

Files:
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp
  llvm/test/CodeGen/AArch64/O3-pipeline.ll
  llvm/test/CodeGen/AArch64/sve-intrinsic-opts-ptest.ll
  llvm/test/CodeGen/AArch64/sve-intrinsic-opts-reinterpret.ll

Index: llvm/test/CodeGen/AArch64/sve-intrinsic-opts-reinterpret.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sve-intrinsic-opts-reinterpret.ll
@@ -0,0 +1,199 @@
+; RUN: opt -S -sve-intrinsic-opts -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck --check-prefix OPT %s
+
+define  @reinterpret_test_h( %a) {
+; OPT-LABEL: @reinterpret_test_h(
+; OPT-NOT: convert
+; OPT: ret  %a
+  %1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv8i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( %1)
+  ret  %2
+}
+
+; Reinterprets are not redundant because the second reinterpret zeros the
+; lanes that don't exist within its input.
+define  @reinterpret_test_h_rev( %a) {
+; OPT-LABEL: @reinterpret_test_h_rev(
+; OPT: %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( %a)
+; OPT-NEXT: %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv8i1( %1)
+; OPT-NEXT: ret  %2
+  %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv8i1( %1)
+  ret  %2
+}
+
+define  @reinterpret_test_w( %a) {
+; OPT-LABEL: @reinterpret_test_w(
+; OPT-NOT: convert
+; OPT: ret  %a
+  %1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( %1)
+  ret  %2
+}
+
+; Reinterprets are not redundant because the second reinterpret zeros the
+; lanes that don't exist within its input.
+define  @reinterpret_test_w_rev( %a) {
+; OPT-LABEL: @reinterpret_test_w_rev(
+; OPT: %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( %a)
+; OPT-NEXT: %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %1)
+; OPT-NEXT: ret  %2
+  %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %1)
+  ret  %2
+}
+
+define  @reinterpret_test_d( %a) {
+; OPT-LABEL: @reinterpret_test_d(
+; OPT-NOT: convert
+; OPT: ret  %a
+  %1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( %1)
+  ret  %2
+}
+
+; Reinterprets are not redundant because the second reinterpret zeros the
+; lanes that don't exist within its input.
+define  @reinterpret_test_d_rev( %a) {
+; OPT-LABEL: @reinterpret_test_d_rev(
+; OPT: %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( %a)
+; OPT-NEXT: %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %1)
+; OPT-NEXT: ret  %2
+  %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %1)
+  ret  %2
+}
+
+define  @reinterpret_reductions(i32 %cond,  %a,  %b,  %c) {
+; OPT-LABEL: reinterpret_reductions
+; OPT-NOT: convert
+; OPT-NOT: phi 
+; OPT: phi  [ %a, %br_phi_a ], [ %b, %br_phi_b ], [ %c, %br_phi_c ]
+; OPT-NOT: convert
+; OPT: ret
+
+entry:
+  switch i32 %cond, label %br_phi_c [
+ i32 43, label %br_phi_a
+ i32 45, label %br_phi_b
+  ]
+
+br_phi_a:
+  %a1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %a)
+  br label %join
+
+br_phi_b:
+  %b1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %b)
+  br label %join
+
+br_phi_c:
+  %c1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %c)
+  br label %join
+
+join:
+  %pg = phi  [ %a1, %br_phi_a ], [ %b1, %br_phi_b ], [ %c1, %br_phi_c ]
+  %pg1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( %pg)
+  ret  %pg1
+}
+
+define  @reinterpret_reductions_1(i32 %cond,  %a,  %b,  %c) {
+; OPT-LABEL: reinterpret_reductions_1
+; OPT: convert
+; OPT: phi  [ %a1, %br_phi_a ], [ %b1, %br_phi_b ], [ %c1, %br_phi_c ]
+; OPT-NOT: phi 
+; OPT: tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( %pg)
+; OPT: ret
+
+entry:
+  switch i32 %cond, label %br_phi_c [
+ i32 43, label %br_phi_a
+ i32 45, label %br_phi_b
+  ]
+
+br_phi_a:
+  %a1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %a)
+  br label %join
+
+br_phi_b:
+  %b1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %b)
+  br label %join
+
+br_phi_c:
+  %c1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %c)
+  br label %j

[PATCH] D76078: [AArch64][SVE] Add a pass for SVE intrinsic optimisations

2020-03-20 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin added a comment.

Thanks for reviewing this, @efriedma & @andwar!




Comment at: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp:441
+  // Expand any SVE vector library calls that we can't code generate directly.
+  bool ExpandToOptimize = (TM->getOptLevel() != CodeGenOpt::None);
+  if (EnableSVEIntrinsicOpts && TM->getOptLevel() == CodeGenOpt::Aggressive)

efriedma wrote:
> unused bool?
Removed



Comment at: llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp:120
+if (!Reinterpret ||
+RequiredType != Reinterpret->getArgOperand(0)->getType())
+  return false;

andwar wrote:
> Isn't it guaranteed that `RequiredType == 
> Reinterpret->getArgOperand(0)->getType()` is always true? I.e., `PN` and the 
> incoming values have identical type.
The incoming values to `PN` will all have the same type, but this is making 
sure that the reinterprets are all converting from the same type (there is a 
test for this in sve-intrinsic-opts-reinterpret.ll called 
`reinterpret_reductions_1`, where the arguments to convert.to.svbool are a mix 
of nxv2i1 and nxv4i1)



Comment at: llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp:224
+  bool Changed = false;
+  for (auto II = BB->begin(), IE = BB->end(); II != IE;) {
+Instruction *I = &(*II);

andwar wrote:
> 1. Could this be a for-range loop instead?
> 
> 2. This loop seems to be a perfect candidate for `make_early_inc_range` 
> (https://github.com/llvm/llvm-project/blob/172f1460ae05ab5c33c757142c8bdb10acfbdbe1/llvm/include/llvm/ADT/STLExtras.h#L499),
>  e.g.
> ```
>  for (Instruction &I : make_early_inc_range(BB))
>   Changed |= optimizeIntrinsic(&I);
> ```
Changed this to use `make_early_inc_range` as suggested



Comment at: llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp:234
+  DT = &getAnalysis().getDomTree();
+  bool Changed = false;
+

efriedma wrote:
> You might want to check whether the module actually declares any of the SVE 
> intrinsics before you iterate over the whole function.
Thanks for the suggestion - I changed this to a module pass so that we can 
check if any of the SVE intrinsics we are interested in are declared first.



Comment at: llvm/test/CodeGen/AArch64/sve-intrinsic-opts-ptest.ll:18
+; OPT-LABEL: ptest_any2
+; OPT: %out = call i1 @llvm.aarch64.sve.ptest.any.nxv16i1( 
%1,  %2)
+  %mask = tail call  @llvm.aarch64.sve.ptrue.nxv2i1(i32 31)

andwar wrote:
> What's `%1` and `%2`? Is it worth adding the calls that generated them in the 
> expected output?
I think that would make sense. I've added `%1` and `%2` to the expected output 
and added more checks to the other tests here.


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

https://reviews.llvm.org/D76078



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


[PATCH] D76490: [ARM,MVE] Add ACLE intrinsics for the vminv/vmaxv family.

2020-03-20 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG45a9945b9ea9: [ARM,MVE] Add ACLE intrinsics for the 
vminv/vmaxv family. (authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76490

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/test/CodeGen/arm-mve-intrinsics/vminvq.c
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/ARM/ARMInstrMVE.td
  llvm/test/CodeGen/Thumb2/mve-intrinsics/vminvq.ll

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/vminvq.ll
===
--- llvm/test/CodeGen/Thumb2/mve-intrinsics/vminvq.ll
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/vminvq.ll
@@ -1,36 +1,865 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc -mtriple=thumbv8.1m.main -mattr=+mve.fp -verify-machineinstrs -o - %s | FileCheck %s
 
+define arm_aapcs_vfpcc signext i8 @test_vminvq_s8(i8 signext %a, <16 x i8> %b) {
+; CHECK-LABEL: test_vminvq_s8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vminv.s8 r0, q0
+; CHECK-NEXT:sxtb r0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i8 %a to i32
+  %1 = tail call i32 @llvm.arm.mve.minv.v16i8(i32 %0, <16 x i8> %b, i32 0)
+  %2 = trunc i32 %1 to i8
+  ret i8 %2
+}
+
+define arm_aapcs_vfpcc signext i16 @test_vminvq_s16(i16 signext %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vminvq_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vminv.s16 r0, q0
+; CHECK-NEXT:sxth r0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i16 %a to i32
+  %1 = tail call i32 @llvm.arm.mve.minv.v8i16(i32 %0, <8 x i16> %b, i32 0)
+  %2 = trunc i32 %1 to i16
+  ret i16 %2
+}
+
+define arm_aapcs_vfpcc i32 @test_vminvq_s32(i32 %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vminvq_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vminv.s32 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.minv.v4i32(i32 %a, <4 x i32> %b, i32 0)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc zeroext i8 @test_vminvq_u8(i8 zeroext %a, <16 x i8> %b) {
+; CHECK-LABEL: test_vminvq_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vminv.u8 r0, q0
+; CHECK-NEXT:uxtb r0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i8 %a to i32
+  %1 = tail call i32 @llvm.arm.mve.minv.v16i8(i32 %0, <16 x i8> %b, i32 1)
+  %2 = trunc i32 %1 to i8
+  ret i8 %2
+}
+
+define arm_aapcs_vfpcc zeroext i16 @test_vminvq_u16(i16 zeroext %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vminvq_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vminv.u16 r0, q0
+; CHECK-NEXT:uxth r0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i16 %a to i32
+  %1 = tail call i32 @llvm.arm.mve.minv.v8i16(i32 %0, <8 x i16> %b, i32 1)
+  %2 = trunc i32 %1 to i16
+  ret i16 %2
+}
+
 define arm_aapcs_vfpcc i32 @test_vminvq_u32(i32 %a, <4 x i32> %b) {
 ; CHECK-LABEL: test_vminvq_u32:
 ; CHECK:   @ %bb.0: @ %entry
 ; CHECK-NEXT:vminv.u32 r0, q0
 ; CHECK-NEXT:bx lr
 entry:
-  %0 = tail call i32 @llvm.arm.mve.minv.u.v4i32(i32 %a, <4 x i32> %b)
+  %0 = tail call i32 @llvm.arm.mve.minv.v4i32(i32 %a, <4 x i32> %b, i32 1)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc signext i8 @test_vmaxvq_s8(i8 signext %a, <16 x i8> %b) {
+; CHECK-LABEL: test_vmaxvq_s8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmaxv.s8 r0, q0
+; CHECK-NEXT:sxtb r0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i8 %a to i32
+  %1 = tail call i32 @llvm.arm.mve.maxv.v16i8(i32 %0, <16 x i8> %b, i32 0)
+  %2 = trunc i32 %1 to i8
+  ret i8 %2
+}
+
+define arm_aapcs_vfpcc signext i16 @test_vmaxvq_s16(i16 signext %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vmaxvq_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmaxv.s16 r0, q0
+; CHECK-NEXT:sxth r0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i16 %a to i32
+  %1 = tail call i32 @llvm.arm.mve.maxv.v8i16(i32 %0, <8 x i16> %b, i32 0)
+  %2 = trunc i32 %1 to i16
+  ret i16 %2
+}
+
+define arm_aapcs_vfpcc i32 @test_vmaxvq_s32(i32 %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vmaxvq_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmaxv.s32 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.maxv.v4i32(i32 %a, <4 x i32> %b, i32 0)
   ret i32 %0
 }
 
-define arm_aapcs_vfpcc i32 @test_vmaxvq_u8(i32 %a, <16 x i8> %b) {
+define arm_aapcs_vfpcc zeroext i8 @test_vmaxvq_u8(i8 zeroext %a, <16 x i8> %b) {
 ; CHECK-LABEL: test_vmaxvq_u8:
 ; CHECK:   @ %bb.0: @ %entry
 ; CHECK-NEXT:vmaxv.u8 r0, q0
+; CHECK-NEXT:uxtb r0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i8 %a to i32
+  %1 = tail call i32 @llvm.arm.mve.maxv.v16i8(i32 %0, <16 x i8> %b, i32 1)
+  %2 = trunc i32 %1 to i8
+  ret i8 %2
+}
+
+define arm_aapcs_vfpcc zeroext i16 @test_vmaxvq_u16(i16 zeroext %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vmaxvq_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmaxv

[PATCH] D76491: [ARM,MVE] Add ACLE intrinsics for the vaddv/vaddlv family.

2020-03-20 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1adfa4c99169: [ARM,MVE] Add ACLE intrinsics for the 
vaddv/vaddlv family. (authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76491

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/test/CodeGen/arm-mve-intrinsics/vaddv.c
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/ARM/ARMISelLowering.h
  llvm/lib/Target/ARM/ARMInstrMVE.td
  llvm/test/CodeGen/Thumb2/mve-intrinsics/vaddv.ll

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/vaddv.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/vaddv.ll
@@ -0,0 +1,416 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=thumbv8.1m.main -mattr=+mve.fp -verify-machineinstrs -o - %s | FileCheck %s
+
+define arm_aapcs_vfpcc i32 @test_vaddvq_s8(<16 x i8> %a) {
+; CHECK-LABEL: test_vaddvq_s8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddv.s8 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v16i8(<16 x i8> %a, i32 0)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvq_s16(<8 x i16> %a) {
+; CHECK-LABEL: test_vaddvq_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddv.s16 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v8i16(<8 x i16> %a, i32 0)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvq_s32(<4 x i32> %a) {
+; CHECK-LABEL: test_vaddvq_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddv.s32 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v4i32(<4 x i32> %a, i32 0)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvq_u8(<16 x i8> %a) {
+; CHECK-LABEL: test_vaddvq_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddv.u8 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v16i8(<16 x i8> %a, i32 1)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvq_u16(<8 x i16> %a) {
+; CHECK-LABEL: test_vaddvq_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddv.u16 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v8i16(<8 x i16> %a, i32 1)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvq_u32(<4 x i32> %a) {
+; CHECK-LABEL: test_vaddvq_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddv.u32 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v4i32(<4 x i32> %a, i32 1)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvaq_s8(i32 %a, <16 x i8> %b) {
+; CHECK-LABEL: test_vaddvaq_s8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddva.s8 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v16i8(<16 x i8> %b, i32 0)
+  %1 = add i32 %0, %a
+  ret i32 %1
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvaq_s16(i32 %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vaddvaq_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddva.s16 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v8i16(<8 x i16> %b, i32 0)
+  %1 = add i32 %0, %a
+  ret i32 %1
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvaq_s32(i32 %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vaddvaq_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddva.s32 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v4i32(<4 x i32> %b, i32 0)
+  %1 = add i32 %0, %a
+  ret i32 %1
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvaq_u8(i32 %a, <16 x i8> %b) {
+; CHECK-LABEL: test_vaddvaq_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddva.u8 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v16i8(<16 x i8> %b, i32 1)
+  %1 = add i32 %0, %a
+  ret i32 %1
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvaq_u16(i32 %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vaddvaq_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddva.u16 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v8i16(<8 x i16> %b, i32 1)
+  %1 = add i32 %0, %a
+  ret i32 %1
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvaq_u32(i32 %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vaddvaq_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vaddva.u32 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call i32 @llvm.arm.mve.addv.v4i32(<4 x i32> %b, i32 1)
+  %1 = add i32 %0, %a
+  ret i32 %1
+}
+
+define arm_aapcs_vfpcc i32 @test_vaddvq_p_s8(<16 x i8> %a, i16 zeroext %p) {
+; CHECK-LABEL: test_vaddvq_p_s8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r0
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vaddvt.s8 r0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i16 %p to i32
+  %1 = tail call <16 x i1> @llvm.arm.mve.pred.i2v.v16i1(i32 %0)
+  %2 = tail call i32 @llvm.arm.mve.add

[PATCH] D76435: [[Clang CallGraph]] CallGraph should still record calls to decls.

2020-03-20 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGffcc076a2b23: [[Clang CallGraph]] CallGraph should still 
record calls to decls. (authored by erichkeane).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76435

Files:
  clang/include/clang/Analysis/CallGraph.h
  clang/lib/Analysis/CallGraph.cpp
  clang/test/Analysis/debug-CallGraph.cpp


Index: clang/test/Analysis/debug-CallGraph.cpp
===
--- clang/test/Analysis/debug-CallGraph.cpp
+++ clang/test/Analysis/debug-CallGraph.cpp
@@ -97,9 +97,10 @@
 }
 
 // CHECK:--- Call graph Dump ---
-// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > 
bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ 
SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(anonymous 
class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) 
CallDecl::SomeDef CallDecl::Caller CallDecl::SomeOtherDecl $}}
-// CHECK-NEXT: {{Function: CallDecl::Caller calls: CallDecl::SomeOtherDecl $}}
+// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > 
bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ 
SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(anonymous 
class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) 
CallDecl::SomeDef CallDecl::Caller CallDecl::SomeDecl CallDecl::SomeOtherDecl 
$}}
+// CHECK-NEXT: {{Function: CallDecl::Caller calls: CallDecl::SomeDecl 
CallDecl::SomeOtherDecl $}}
 // CHECK-NEXT: {{Function: CallDecl::SomeOtherDecl calls: CallDecl::SomeDef $}}
+// CHECK-NEXT: {{Function: CallDecl::SomeDecl calls: $}}
 // CHECK-NEXT: {{Function: CallDecl::SomeDef calls: $}}
 // CHECK-NEXT: {{Function: Lambdas::f1 calls: Lambdas::f1\(\)::\(anonymous 
class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) $}}
 // CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) 
calls: Lambdas::Callee $}}
Index: clang/lib/Analysis/CallGraph.cpp
===
--- clang/lib/Analysis/CallGraph.cpp
+++ clang/lib/Analysis/CallGraph.cpp
@@ -67,7 +67,7 @@
   }
 
   void addCalledDecl(Decl *D, Expr *CallExpr) {
-if (G->includeInGraph(D)) {
+if (G->includeCalleeInGraph(D)) {
   CallGraphNode *CalleeNode = G->getOrInsertNode(D);
   CallerNode->addCallee({CalleeNode, CallExpr});
 }
@@ -157,6 +157,10 @@
   if (!D->hasBody())
 return false;
 
+  return includeCalleeInGraph(D);
+}
+
+bool CallGraph::includeCalleeInGraph(const Decl *D) {
   if (const FunctionDecl *FD = dyn_cast(D)) {
 // We skip function template definitions, as their semantics is
 // only determined when they are instantiated.
Index: clang/include/clang/Analysis/CallGraph.h
===
--- clang/include/clang/Analysis/CallGraph.h
+++ clang/include/clang/Analysis/CallGraph.h
@@ -66,6 +66,11 @@
   /// Determine if a declaration should be included in the graph.
   static bool includeInGraph(const Decl *D);
 
+  /// Determine if a declaration should be included in the graph for the 
+  /// purposes of being a callee. This is similar to includeInGraph except
+  /// it permits declarations, not just definitions.
+  static bool includeCalleeInGraph(const Decl *D);
+
   /// Lookup the node for the given declaration.
   CallGraphNode *getNode(const Decl *) const;
 


Index: clang/test/Analysis/debug-CallGraph.cpp
===
--- clang/test/Analysis/debug-CallGraph.cpp
+++ clang/test/Analysis/debug-CallGraph.cpp
@@ -97,9 +97,10 @@
 }
 
 // CHECK:--- Call graph Dump ---
-// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(anonymous class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) CallDecl::SomeDef CallDecl::Caller CallDecl::SomeOtherDecl $}}
-// CHECK-NEXT: {{Function: CallDecl::Caller calls: CallDecl::SomeOtherDecl $}}
+// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(anonymous class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) CallDecl::SomeDef CallDecl::Caller CallDecl::SomeDecl CallDecl::SomeOtherDecl $}}
+// CHECK-NEXT: {{Function: CallDecl::Caller calls: CallDecl::SomeDecl CallDecl::SomeOtherDecl $}}
 // CHECK-NEXT: {{Function: CallDecl::SomeOtherDecl calls: CallDecl::SomeDef $}}
+// CHECK-NEXT: {{Function: CallDecl::SomeDecl calls: $}}
 /

[PATCH] D76444: Use FinishThunk to finish musttail thunks

2020-03-20 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGce5173c0e174: Use FinishThunk to finish musttail thunks 
(authored by rnk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76444

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/test/CodeGenCXX/ms-thunks-ehspec.cpp
  clang/test/CodeGenCXX/thunks-ehspec.cpp


Index: clang/test/CodeGenCXX/thunks-ehspec.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/thunks-ehspec.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fexceptions -fcxx-exceptions %s 
-triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 
-disable-llvm-passes | FileCheck %s
+
+// When generating the thunk for secondary, do not push terminate scopes for
+// either the varargs or non-varargs case. Related to PR44987.
+
+struct A {
+  virtual void primary_key();
+};
+struct B {
+  virtual void secondary();
+  virtual void secondary_vararg(int, ...);
+};
+class C : A, B {
+  virtual void primary_key();
+  void secondary() noexcept;
+  void secondary_vararg(int, ...) noexcept;
+};
+void C::primary_key() {}
+
+// CHECK-LABEL: define available_externally void 
@_ZThn8_N1C9secondaryEv(%class.C* %this)
+// CHECK-NOT: invoke
+// CHECK: tail call void @_ZN1C9secondaryEv(%class.C* %{{.*}})
+// CHECK-NOT: invoke
+// CHECK: ret void
+
+// CHECK-LABEL: define available_externally void 
@_ZThn8_N1C16secondary_varargEiz(%class.C* %this, i32 %0, ...)
+// CHECK-NOT: invoke
+// CHECK:  musttail call void (%class.C*, i32, ...) 
@_ZN1C16secondary_varargEiz(%class.C* %{{.*}}, i32 %{{.*}}, ...) #2
+// CHECK-NEXT:  ret void
Index: clang/test/CodeGenCXX/ms-thunks-ehspec.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ms-thunks-ehspec.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fexceptions -fcxx-exceptions %s -triple=i686-windows-msvc 
-emit-llvm -o - | FileCheck %s
+
+// When generating thunks using musttail due to inalloca parameters, don't push
+// and pop terminate scopes. PR44987
+
+struct NonTrivial {
+  NonTrivial();
+  NonTrivial(const NonTrivial &o);
+  ~NonTrivial();
+  int x;
+};
+struct A {
+  virtual void f(NonTrivial o) noexcept;
+};
+struct B {
+  virtual void f(NonTrivial o) noexcept;
+};
+class C : A, B {
+  virtual void f(NonTrivial o) noexcept;
+};
+C c;
+
+// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void 
@"?f@C@@G3AEXUNonTrivial@@@Z"(%class.C* %this, <{ %struct.NonTrivial }>* 
inalloca %0)
+// CHECK-NOT: invoke
+// CHECK: musttail call x86_thiscallcc void 
@"?f@C@@EAEXUNonTrivial@@@Z"(%class.C* %{{.*}}, <{ %struct.NonTrivial }>* 
inalloca %0)
+// CHECK-NEXT  ret void
+
Index: clang/lib/CodeGen/CGVTables.cpp
===
--- clang/lib/CodeGen/CGVTables.cpp
+++ clang/lib/CodeGen/CGVTables.cpp
@@ -437,7 +437,8 @@
   // Finish the function to maintain CodeGenFunction invariants.
   // FIXME: Don't emit unreachable code.
   EmitBlock(createBasicBlock());
-  FinishFunction();
+
+  FinishThunk();
 }
 
 void CodeGenFunction::generateThunk(llvm::Function *Fn,
@@ -564,7 +565,7 @@
   CGM.SetLLVMFunctionAttributesForDefinition(GD.getDecl(), ThunkFn);
 
   // Thunks for variadic methods are special because in general variadic
-  // arguments cannot be perferctly forwarded. In the general case, clang
+  // arguments cannot be perfectly forwarded. In the general case, clang
   // implements such thunks by cloning the original function body. However, for
   // thunks with no return adjustment on targets that support musttail, we can
   // use musttail to perfectly forward the variadic arguments.


Index: clang/test/CodeGenCXX/thunks-ehspec.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/thunks-ehspec.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fexceptions -fcxx-exceptions %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes | FileCheck %s
+
+// When generating the thunk for secondary, do not push terminate scopes for
+// either the varargs or non-varargs case. Related to PR44987.
+
+struct A {
+  virtual void primary_key();
+};
+struct B {
+  virtual void secondary();
+  virtual void secondary_vararg(int, ...);
+};
+class C : A, B {
+  virtual void primary_key();
+  void secondary() noexcept;
+  void secondary_vararg(int, ...) noexcept;
+};
+void C::primary_key() {}
+
+// CHECK-LABEL: define available_externally void @_ZThn8_N1C9secondaryEv(%class.C* %this)
+// CHECK-NOT: invoke
+// CHECK: tail call void @_ZN1C9secondaryEv(%class.C* %{{.*}})
+// CHECK-NOT: invoke
+// CHECK: ret void
+
+// CHECK-LABEL: define available_externally void @_ZThn8_N1C16secondary_varargEiz(%class.C* %this, i32 %0, ...)
+// CHECK-NOT: invoke
+// CHECK:  musttail call void (%class.C*, i32, ...) @_ZN1C16secondary_varargEiz(%class

[clang] ededa65 - [analyzer] StdLibraryFunctionsChecker: Add NotNull Arg Constraint

2020-03-20 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2020-03-20T17:34:29+01:00
New Revision: ededa65d559dac04ae50d3a33610875bb8f1a85e

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

LOG: [analyzer] StdLibraryFunctionsChecker: Add NotNull Arg Constraint

Reviewers: NoQ, Szelethus, balazske, gamesh411, baloghadamsoftware, steakhal

Subscribers: whisperity, xazax.hun, szepet, rnkovacs, a.sidorin, 
mikhail.ramalho, donat.nagy, dkrupp, Charusso, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints.c
clang/test/Analysis/std-c-library-functions.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 2e956cc2bfe7..590dc8b67690 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -183,6 +183,29 @@ class StdLibraryFunctionsChecker
   const Summary &Summary) const override;
   };
 
+  class NotNullConstraint : public ValueConstraint {
+using ValueConstraint::ValueConstraint;
+// This variable has a role when we negate the constraint.
+bool CannotBeNull = true;
+
+  public:
+ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
+  const Summary &Summary) const override {
+  SVal V = getArgSVal(Call, getArgNo());
+  DefinedOrUnknownSVal L = V.castAs();
+  if (!L.getAs())
+return State;
+
+  return State->assume(L, CannotBeNull);
+}
+
+ValueConstraintPtr negate() const override {
+  NotNullConstraint Tmp(*this);
+  Tmp.CannotBeNull = !this->CannotBeNull;
+  return std::make_shared(Tmp);
+}
+  };
+
   /// The complete list of constraints that defines a single branch.
   typedef std::vector ConstraintSet;
 
@@ -233,9 +256,6 @@ class StdLibraryFunctionsChecker
  "We should have had no significant void types in the spec");
   assert(T.isCanonical() &&
  "We should only have canonical types in the spec");
-  // FIXME: lift this assert (but not the ones above!)
-  assert(T->isIntegralOrEnumerationType() &&
- "We only support integral ranges in the spec");
 }
 
   public:
@@ -602,6 +622,9 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   const QualType LongTy = ACtx.LongTy;
   const QualType LongLongTy = ACtx.LongLongTy;
   const QualType SizeTy = ACtx.getSizeType();
+  const QualType VoidPtrTy = ACtx.VoidPtrTy; // void *T
+  const QualType ConstVoidPtrTy =
+  ACtx.getPointerType(ACtx.VoidTy.withConst()); // const void *T
 
   const RangeInt IntMax = BVF.getMaxValue(IntTy).getLimitedValue();
   const RangeInt LongMax = BVF.getMaxValue(LongTy).getLimitedValue();
@@ -672,6 +695,9 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 return IntRangeVector{std::pair{v, v}};
   };
   auto LessThanOrEq = BO_LE;
+  auto NotNull = [&](ArgNo ArgN) {
+return std::make_shared(ArgN);
+  };
 
   using RetType = QualType;
   // Templates for summaries that are reused by many functions.
@@ -687,11 +713,20 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
ReturnValueCondition(WithinRange, Range(-1, Max))});
   };
   auto Fread = [&]() {
-return Summary(ArgTypes{Irrelevant, Irrelevant, SizeTy, Irrelevant},
+return Summary(ArgTypes{VoidPtrTy, Irrelevant, SizeTy, Irrelevant},
+   RetType{SizeTy}, NoEvalCall)
+.Case({
+ReturnValueCondition(LessThanOrEq, ArgNo(2)),
+})
+.ArgConstraint(NotNull(ArgNo(0)));
+  };
+  auto Fwrite = [&]() {
+return Summary(ArgTypes{ConstVoidPtrTy, Irrelevant, SizeTy, Irrelevant},
RetType{SizeTy}, NoEvalCall)
 .Case({
 ReturnValueCondition(LessThanOrEq, ArgNo(2)),
-});
+})
+.ArgConstraint(NotNull(ArgNo(0)));
   };
   auto Getline = [&](RetType R, RangeInt Max) {
 return Summary(ArgTypes{Irrelevant, Irrelevant, Irrelevant}, RetType{R},
@@ -893,7 +928,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   {"write", Summaries{Read(IntTy, IntMax), Read(LongTy, LongMax),
   Read(LongLongTy, LongLongMax)}},
   {"fread", Summaries{Fread()}},
-  {"fwrite", Summaries{Fread()}},
+  {"fwrite", Summaries{Fwrite()}},
   // getline()-like functions either fail or read at least the delimiter.
   {"getline", Summaries{Getline(IntTy, IntMax), Getline(LongTy, LongMax),
 Getline(LongLongTy, LongLongMax)}

[PATCH] D76323: [AST] Fix handling of long double and bool in __builtin_bit_cast

2020-03-20 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

Maybe you should test `nullptr` as well, given that it's all padding?




Comment at: clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp:407
+
+constexpr bool test_bad_bool = bit_cast('A'); // expected-error {{must 
be initialized by a constant expression}} expected-note{{in call}}
+

Sanity-check: `0` and `1` work? IIRC we had a discussion about whether `false` 
was `0` and `true` was `1`, and we concluded that `false` was indeed `0` but 
`true` wasn't specified to be `1`.


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

https://reviews.llvm.org/D76323



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


[PATCH] D76504: [clang] Fix crash during template sema checking

2020-03-20 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:1655
+clang::Expr *SizeOp = TheCall->getArg(2);
+// If any arg is instantiation dependent we bail out.
+if (DstOp->isInstantiationDependent() ||

courbet wrote:
> Are the first two necessary ? IIRC only `EvaluateKnownConstInt()` does not 
> like template-dependent stuff. 
That's right I don't think it's realistic to pass the pointers as template 
parameters so whatever `CheckNonNullArgument` is doing it will probably never 
end up crashing in the same way.

I'll limit the fix to `SizeOp` then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76504



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


[PATCH] D76509: [analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions

2020-03-20 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, baloghadamsoftware, martong, 
balazske, rnkovacs, dcoughlin, steakhal.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, ASDenysPetrov, usaxena95, Charusso, 
gamesh411, dkrupp, donat.nagy, kadircet, mikhail.ramalho, a.sidorin, szepet, 
ilya-biryukov, whisperity, mgorny.
Szelethus added a child revision: D76510: [analyzer] Change the default output 
type to PD_TEXT_MINIMAL, error if an output loc is missing for 
PathDiagConsumers that need it.

TableGen and `.def` files (which are meant to be used with the preprocessor) 
come with obvious downsides. One of those issues is that generated 
`switch`-`case` branches have to be identical. This pushes corner cases either 
to an outer code block, or into the generated code.

Inspect the removed code in `AnalysisConsumer::DigestAnalyzerOptions`. You can 
see how corner cases like a not existing output file, the analysis output type 
being set to `PD_NONE`, or whether to complement the output with additional 
diagnostics on stderr  lay //around// the preprocessor generated code. This is 
a bit problematic, as to how to deal with such errors is not in the hands of 
the users of this interface (those implementing output types, like 
`PlistDiagnostics` etc).

This patch changes this by moving these corner cases into the generated code, 
more specifically, into the called functions. In addition, I introduced a new 
output type for convenience purposes, `PD_TEXT_MINIMAL`, which always existed 
conceptually, but never in the actual `Analyses.def` file. This refactoring 
allowed me to move `TextDiagnostics` (renamed from `ClangDiagPathDiagConsumer`) 
to its own file, which it really deserved.

Also, those that had the misfortune to gaze upon `Analyses.def` will probably 
enjoy the sight that a clang-format did on it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76509

Files:
  clang/include/clang/StaticAnalyzer/Core/Analyses.def
  clang/lib/StaticAnalyzer/Core/CMakeLists.txt
  clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -60,115 +60,6 @@
 STATISTIC(PercentReachableBlocks, "The % of reachable basic blocks.");
 STATISTIC(MaxCFGSize, "The maximum number of basic blocks in a function.");
 
-//===--===//
-// Special PathDiagnosticConsumers.
-//===--===//
-
-void ento::createPlistHTMLDiagnosticConsumer(
-AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
-const std::string &prefix, const Preprocessor &PP,
-const cross_tu::CrossTranslationUnitContext &CTU) {
-  createHTMLDiagnosticConsumer(
-  AnalyzerOpts, C, std::string(llvm::sys::path::parent_path(prefix)), PP,
-  CTU);
-  createPlistMultiFileDiagnosticConsumer(AnalyzerOpts, C, prefix, PP, CTU);
-}
-
-void ento::createTextPathDiagnosticConsumer(
-AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
-const std::string &Prefix, const clang::Preprocessor &PP,
-const cross_tu::CrossTranslationUnitContext &CTU) {
-  llvm_unreachable("'text' consumer should be enabled on ClangDiags");
-}
-
-namespace {
-class ClangDiagPathDiagConsumer : public PathDiagnosticConsumer {
-  DiagnosticsEngine &Diag;
-  bool IncludePath = false, ShouldEmitAsError = false, FixitsAsRemarks = false;
-
-public:
-  ClangDiagPathDiagConsumer(DiagnosticsEngine &Diag)
-  : Diag(Diag) {}
-  ~ClangDiagPathDiagConsumer() override {}
-  StringRef getName() const override { return "ClangDiags"; }
-
-  bool supportsLogicalOpControlFlow() const override { return true; }
-  bool supportsCrossFileDiagnostics() const override { return true; }
-
-  PathGenerationScheme getGenerationScheme() const override {
-return IncludePath ? Minimal : None;
-  }
-
-  void enablePaths() { IncludePath = true; }
-  void enableWerror() { ShouldEmitAsError = true; }
-  void enableFixitsAsRemarks() { FixitsAsRemarks = true; }
-
-  void FlushDiagnosticsImpl(std::vector &Diags,
-FilesMade *filesMade) override {
-unsigned WarnID =
-ShouldEmitAsError
-? Diag.getCustomDiagID(DiagnosticsEngine::Error, "%0")
-: Diag.getCustomDiagID(DiagnosticsEngine::Warning, "%0");
-unsigned NoteID = Diag.getCustomDiagID(DiagnosticsEngine::Note, "%0");
-unsigned RemarkID = Diag.getCustomDiagID(DiagnosticsEngine::Remark, "%0");
-
-auto reportPiece =
-[&](unsigned I

[PATCH] D76510: [analyzer] Change the default output type to PD_TEXT_MINIMAL, error if an output loc is missing for PathDiagConsumers that need it

2020-03-20 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, baloghadamsoftware, rnkovacs, 
martong, balazske, dcoughlin.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, ASDenysPetrov, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, szepet, whisperity.
Szelethus added a parent revision: D76509: [analyzer][NFC] Move the text output 
type to its own file, move code to PathDiagnosticConsumer creator functions.

The title and the included test file sums everything up -- the only thing I'm 
mildly afraid of is whether anyone actually depends on the weird behavior of 
`HTMLDiagnostics` pretending to be `TextDiagnostics` if an output directory is 
not supplied. If it is, I guess we would need to resort to tiptoeing around the 
compatibility flag.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76510

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  clang/test/Analysis/output_types.cpp

Index: clang/test/Analysis/output_types.cpp
===
--- /dev/null
+++ clang/test/Analysis/output_types.cpp
@@ -0,0 +1,49 @@
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=plist \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-PLIST
+
+// CHECK-PLIST: error: analyzer output type 'plist' requires an output file to
+// CHECK-PLIST-SAME: be specified with -o 
+
+
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=plist-multi-file \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-PLIST-MULTI
+
+// CHECK-PLIST-MULTI: error: analyzer output type 'plist-multi-file' requires
+// CHECK-PLIST-MULTI-SAME: an output file to be specified with
+// CHECK-PLIST-MULTI-SAME: -o 
+
+
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=plist-html \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-PLIST-HTML
+
+// CHECK-PLIST-HTML: error: analyzer output type 'plist-html' requires an output
+// CHECK-PLIST-HTML-SAME: directory to be specified with
+// CHECK-PLIST-HTML-SAME: -o 
+
+
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=sarif \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-SARIF
+
+// CHECK-SARIF: error: analyzer output type 'sarif' requires an output file to
+// CHECK-SARIF-SAME: be specified with -o 
+
+
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=html \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-HTML
+
+// CHECK-HTML: error: analyzer output type 'html' requires an output directory
+// CHECK-HTML-SAME: to be specified with -o 
+
+
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=html-single-file \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-HTML-SINGLE
+
+// CHECK-HTML-SINGLE: error: analyzer output type 'html-single-file' requires
+// CHECK-HTML-SINGLE-SAME: an output directory to be specified with
+// CHECK-HTML-SINGLE-SAME: -o 
Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -23,6 +23,7 @@
 #include "clang/Analysis/CodeInjector.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/StaticAnalyzer/Checkers/LocalCheckers.h"
Index: clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Version.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -51,9 +52,11 @@
 const std::string &Output, const Preprocessor &PP,
 const cross_tu::CrossTranslationUnitContext &CTU) {
 
-  // TODO: Emit an error here.
-  if (Output.empty())
+  if (Output.empty()) {
+PP.getDiagnostics().Report(diag::err_analyzer_missing_output_loc)
+  << "sarif" << "file";
 return;
+  }
 
   C.push_back(new SarifDiagnostics(AnalyzerOpts, Output, PP.getLangOpts()));
   createTextMinimalPathDiagnosticConsumer(AnalyzerOpts, C, Output, PP, CTU);
Index: clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/Pli

[PATCH] D75063: [analyzer] StdLibraryFunctionsChecker: Add NotNull Arg Constraint

2020-03-20 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 251674.
martong marked 9 inline comments as done.
martong added a comment.

- Use report/bugpath verify prefixes in test
- Address review nits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75063

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions.c

Index: clang/test/Analysis/std-c-library-functions.c
===
--- clang/test/Analysis/std-c-library-functions.c
+++ clang/test/Analysis/std-c-library-functions.c
@@ -78,10 +78,13 @@
 size_t fread(void *, size_t, size_t, FILE *);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 void test_fread_fwrite(FILE *fp, int *buf) {
+
   size_t x = fwrite(buf, sizeof(int), 10, fp);
   clang_analyzer_eval(x <= 10); // expected-warning{{TRUE}}
+
   size_t y = fread(buf, sizeof(int), 10, fp);
   clang_analyzer_eval(y <= 10); // expected-warning{{TRUE}}
+
   size_t z = fwrite(buf, sizeof(int), y, fp);
   clang_analyzer_eval(z <= y); // expected-warning{{TRUE}}
 }
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -59,3 +59,29 @@
 (void)ret;
   }
 }
+
+typedef struct FILE FILE;
+typedef typeof(sizeof(int)) size_t;
+size_t fread(void *, size_t, size_t, FILE *);
+void test_notnull_concrete(FILE *fp) {
+  fread(0, sizeof(int), 10, fp); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+}
+void test_notnull_symbolic(FILE *fp, int *buf) {
+  fread(buf, sizeof(int), 10, fp);
+  clang_analyzer_eval(buf != 0); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{'buf' is not equal to null}}
+}
+void test_notnull_symbolic2(FILE *fp, int *buf) {
+  if (!buf) // bugpath-note{{Assuming 'buf' is null}} \
+// bugpath-note{{Taking true branch}}
+fread(buf, sizeof(int), 10, fp); // \
+// report-warning{{Function argument constraint is not satisfied}} \
+// bugpath-warning{{Function argument constraint is not satisfied}} \
+// bugpath-note{{Function argument constraint is not satisfied}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -183,6 +183,29 @@
   const Summary &Summary) const override;
   };
 
+  class NotNullConstraint : public ValueConstraint {
+using ValueConstraint::ValueConstraint;
+// This variable has a role when we negate the constraint.
+bool CannotBeNull = true;
+
+  public:
+ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
+  const Summary &Summary) const override {
+  SVal V = getArgSVal(Call, getArgNo());
+  DefinedOrUnknownSVal L = V.castAs();
+  if (!L.getAs())
+return State;
+
+  return State->assume(L, CannotBeNull);
+}
+
+ValueConstraintPtr negate() const override {
+  NotNullConstraint Tmp(*this);
+  Tmp.CannotBeNull = !this->CannotBeNull;
+  return std::make_shared(Tmp);
+}
+  };
+
   /// The complete list of constraints that defines a single branch.
   typedef std::vector ConstraintSet;
 
@@ -233,9 +256,6 @@
  "We should have had no significant void types in the spec");
   assert(T.isCanonical() &&
  "We should only have canonical types in the spec");
-  // FIXME: lift this assert (but not the ones above!)
-  assert(T->isIntegralOrEnumerationType() &&
- "We only support integral ranges in the spec");
 }
 
   public:
@@ -602,6 +622,9 @@
   const QualType LongTy = ACtx.LongTy;
   const QualType LongLongTy = ACtx.LongLongTy;
   const QualType SizeTy = ACtx.getSizeType();
+  const QualType VoidPtrTy = ACtx.VoidPtrTy; // void *T
+  const QualType ConstVoidPtrTy =
+  ACtx.getPointerType(ACtx.VoidTy.withConst()); // const void *T
 
   const RangeInt IntMax = BVF.getMaxValue(IntTy).getLimitedValue();
   const RangeInt LongMax = BVF.getMaxValue(LongTy).getLimitedValue();
@@ -672,6 +695,9 @@
 return IntRangeVector{std::pair{v, v}};
   };
   auto LessThanOrEq = BO_LE;
+  auto NotNull = [&](ArgNo ArgN) {
+return std::make_shared(ArgN);
+  };
 
   using RetType = QualType;
   // Templates for summaries that are reused by many functions.
@@ -687,11

[PATCH] D76377: Correctly initialize the DW_AT_comp_dir attribute of Clang module skeleton CUs

2020-03-20 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2499
+DIB.createFile(Mod.getModuleName(), TheCU->getDirectory()),
+TheCU->getProducer(), false, StringRef(), 0, Mod.getASTFile(),
+llvm::DICompileUnit::FullDebug, Signature);

The isOptimized parameter changed from true to false?


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

https://reviews.llvm.org/D76377



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


[PATCH] D76435: [[Clang CallGraph]] CallGraph should still record calls to decls.

2020-03-20 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Whoops, i did not see cfe-commits again got sidestepped.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76435



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


[PATCH] D76504: [clang] Fix crash during template sema checking

2020-03-20 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 251671.
gchatelet marked an inline comment as done.
gchatelet added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76504

Files:
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1649,18 +1649,16 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
-clang::Expr *DstOp = TheCall->getArg(0);
-clang::Expr *SrcOp = TheCall->getArg(1);
 clang::Expr *SizeOp = TheCall->getArg(2);
-// If any arg is instantiation dependent we bail out.
-if (DstOp->isInstantiationDependent() ||
-SrcOp->isInstantiationDependent() || 
SizeOp->isInstantiationDependent())
+// We warn about copying to or from `nullptr` pointers when size is greater
+// than 0. When `size` is instantiation dependent we cannot evaluate its
+// value so we bail out.
+if (SizeOp->isInstantiationDependent())
   break;
-// __builtin_memcpy_inline size argument is a constant by definition.
-if (SizeOp->EvaluateKnownConstInt(Context).isNullValue())
-  break;
-CheckNonNullArgument(*this, DstOp, TheCall->getExprLoc());
-CheckNonNullArgument(*this, SrcOp, TheCall->getExprLoc());
+if (!SizeOp->EvaluateKnownConstInt(Context).isNullValue()) {
+  CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
+  CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+}
 break;
   }
 #define BUILTIN(ID, TYPE, ATTRS)


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1649,18 +1649,16 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
-clang::Expr *DstOp = TheCall->getArg(0);
-clang::Expr *SrcOp = TheCall->getArg(1);
 clang::Expr *SizeOp = TheCall->getArg(2);
-// If any arg is instantiation dependent we bail out.
-if (DstOp->isInstantiationDependent() ||
-SrcOp->isInstantiationDependent() || SizeOp->isInstantiationDependent())
+// We warn about copying to or from `nullptr` pointers when size is greater
+// than 0. When `size` is instantiation dependent we cannot evaluate its
+// value so we bail out.
+if (SizeOp->isInstantiationDependent())
   break;
-// __builtin_memcpy_inline size argument is a constant by definition.
-if (SizeOp->EvaluateKnownConstInt(Context).isNullValue())
-  break;
-CheckNonNullArgument(*this, DstOp, TheCall->getExprLoc());
-CheckNonNullArgument(*this, SrcOp, TheCall->getExprLoc());
+if (!SizeOp->EvaluateKnownConstInt(Context).isNullValue()) {
+  CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
+  CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+}
 break;
   }
 #define BUILTIN(ID, TYPE, ATTRS)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75063: [analyzer] StdLibraryFunctionsChecker: Add NotNull Arg Constraint

2020-03-20 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D75063#1923780 , @NoQ wrote:

> This is basically a shorthand for "outside [0, 0]", right? I don't mind ^.^


Yeah, and my first attempt was exactly to implement this with ranges. However, 
it failed when I realized that we cannot cast a pointer to `NonLoc`, so the 
already written `RangeConstraint::apply*` functions could not work (I would 
have to add another branch for handling `Loc` kind of SVals for the pointer 
case).




Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:175
+using ValueConstraint::ValueConstraint;
+bool CannotBeNull = true;
+

Szelethus wrote:
> martong wrote:
> > Szelethus wrote:
> > > What does this do? Is it ever used in the patch?
> > Yes, it is used. We use it in `apply` the value is passed to `assume`.
> > And in `negate` we flip the value.
> Forgot my eyes in the office. Woops. I would still prefer a line of comment 
> here :)
Ok, I added a comment about its role.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:684
+.Case({
+ReturnValueCondition(LessThanOrEq, ArgNo(2)),
+})

martong wrote:
> steakhal wrote:
> > Two lines below you are using the `{0U}` initialization syntax, and here 
> > the simple constructor call syntax.
> > Shouldn't we pick one?
> Yes, definitely. I think I am going to use brace initialization syntax 
> everywhere.
Finally I ended up with the parens. :)



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:889-890
   Read(LongLongTy, LongLongMax)}},
   {"fread", Summaries{Fread()}},
-  {"fwrite", Summaries{Fread()}},
+  {"fwrite", Summaries{Fwrite()}},
   // getline()-like functions either fail or read at least the delimiter.

Szelethus wrote:
> Not super relevant to this specific revision, but shouldn't we leave these to 
> `StreamChecker`?
Well, yeah we could remove `fread` and `fwrite` from the summaries entirely at 
some point, but that will require changing the test files here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75063



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


[PATCH] D76361: [Analyzer] Iterator Modeling - Model `std::advance()`, `std::prev()` and `std::next()`

2020-03-20 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp:221
+if (Handler) {
+  if (!C.wasInlined) {
+if (Call.getNumArgs() > 1) {

baloghadamsoftware wrote:
> martong wrote:
> > Perhaps putting this hunk into a separate function or lambda could decrease 
> > the nesting level, b/c you could have an early return if there is no 
> > `Handler`.
> Early return is not possible because the execution must continue if the is no 
> handler. However, I refactored `checkPostCall` now, the handling of both 
> overloaded operators and advance-like functions are moved to separate 
> functions.
Thanks, that's much better structured this way.



Comment at: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp:559
 
+bool IteratorModeling::noChangeInPosition(CheckerContext &C, SVal Iter,
+  const Expr *CE) const {

baloghadamsoftware wrote:
> martong wrote:
> > Some comments would be helpful here. Also, should we use this function only 
> > with `advance()` or it could be useful perhaps in other context?
> I renamed the function and added a short comment. Is it OK?
Yeah, looks ok.



Comment at: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp:571
+  const ExplodedNode *N = C.getPredecessor();
+  while (N) {
+ProgramPoint PP = N->getLocation();

baloghadamsoftware wrote:
> martong wrote:
> > I have a rough presumption that this hunk is a general pattern to get the 
> > previous node for the previous iterator position. So perhaps it would be 
> > useful as a standalone free/static member function too?
> I moved this to a standalone function and named it accordingly.
Thanks, it's easier to read the code this way.


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

https://reviews.llvm.org/D76361



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


[PATCH] D75063: [analyzer] StdLibraryFunctionsChecker: Add NotNull Arg Constraint

2020-03-20 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGededa65d559d: [analyzer] StdLibraryFunctionsChecker: Add 
NotNull Arg Constraint (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75063

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions.c

Index: clang/test/Analysis/std-c-library-functions.c
===
--- clang/test/Analysis/std-c-library-functions.c
+++ clang/test/Analysis/std-c-library-functions.c
@@ -78,10 +78,13 @@
 size_t fread(void *, size_t, size_t, FILE *);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 void test_fread_fwrite(FILE *fp, int *buf) {
+
   size_t x = fwrite(buf, sizeof(int), 10, fp);
   clang_analyzer_eval(x <= 10); // expected-warning{{TRUE}}
+
   size_t y = fread(buf, sizeof(int), 10, fp);
   clang_analyzer_eval(y <= 10); // expected-warning{{TRUE}}
+
   size_t z = fwrite(buf, sizeof(int), y, fp);
   clang_analyzer_eval(z <= y); // expected-warning{{TRUE}}
 }
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -59,3 +59,29 @@
 (void)ret;
   }
 }
+
+typedef struct FILE FILE;
+typedef typeof(sizeof(int)) size_t;
+size_t fread(void *, size_t, size_t, FILE *);
+void test_notnull_concrete(FILE *fp) {
+  fread(0, sizeof(int), 10, fp); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+}
+void test_notnull_symbolic(FILE *fp, int *buf) {
+  fread(buf, sizeof(int), 10, fp);
+  clang_analyzer_eval(buf != 0); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{'buf' is not equal to null}}
+}
+void test_notnull_symbolic2(FILE *fp, int *buf) {
+  if (!buf) // bugpath-note{{Assuming 'buf' is null}} \
+// bugpath-note{{Taking true branch}}
+fread(buf, sizeof(int), 10, fp); // \
+// report-warning{{Function argument constraint is not satisfied}} \
+// bugpath-warning{{Function argument constraint is not satisfied}} \
+// bugpath-note{{Function argument constraint is not satisfied}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -183,6 +183,29 @@
   const Summary &Summary) const override;
   };
 
+  class NotNullConstraint : public ValueConstraint {
+using ValueConstraint::ValueConstraint;
+// This variable has a role when we negate the constraint.
+bool CannotBeNull = true;
+
+  public:
+ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
+  const Summary &Summary) const override {
+  SVal V = getArgSVal(Call, getArgNo());
+  DefinedOrUnknownSVal L = V.castAs();
+  if (!L.getAs())
+return State;
+
+  return State->assume(L, CannotBeNull);
+}
+
+ValueConstraintPtr negate() const override {
+  NotNullConstraint Tmp(*this);
+  Tmp.CannotBeNull = !this->CannotBeNull;
+  return std::make_shared(Tmp);
+}
+  };
+
   /// The complete list of constraints that defines a single branch.
   typedef std::vector ConstraintSet;
 
@@ -233,9 +256,6 @@
  "We should have had no significant void types in the spec");
   assert(T.isCanonical() &&
  "We should only have canonical types in the spec");
-  // FIXME: lift this assert (but not the ones above!)
-  assert(T->isIntegralOrEnumerationType() &&
- "We only support integral ranges in the spec");
 }
 
   public:
@@ -602,6 +622,9 @@
   const QualType LongTy = ACtx.LongTy;
   const QualType LongLongTy = ACtx.LongLongTy;
   const QualType SizeTy = ACtx.getSizeType();
+  const QualType VoidPtrTy = ACtx.VoidPtrTy; // void *T
+  const QualType ConstVoidPtrTy =
+  ACtx.getPointerType(ACtx.VoidTy.withConst()); // const void *T
 
   const RangeInt IntMax = BVF.getMaxValue(IntTy).getLimitedValue();
   const RangeInt LongMax = BVF.getMaxValue(LongTy).getLimitedValue();
@@ -672,6 +695,9 @@
 return IntRangeVector{std::pair{v, v}};
   };
   auto LessThanOrEq = BO_LE;
+  auto NotNull = [&](ArgNo ArgN) {
+return std::make_shared(ArgN);
+  };
 
   using RetType = QualType;
   // Templates for summaries that are reused by many functi

[clang] f59bb40 - Attempt to fix failing build-bot with [-Werror,-Wcovered-switch-default]

2020-03-20 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2020-03-20T18:04:55+01:00
New Revision: f59bb40e361c061adaa19e988f1f5769d3b8fac7

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

LOG: Attempt to fix failing build-bot with [-Werror,-Wcovered-switch-default]

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 590dc8b67690..ff296e7ea46b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -162,8 +162,6 @@ class StdLibraryFunctionsChecker
   case WithinRange:
 Tmp.Kind = OutOfRange;
 break;
-  default:
-llvm_unreachable("Unknown RangeConstraint kind!");
   }
   return std::make_shared(Tmp);
 }



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


[PATCH] D76509: [analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions

2020-03-20 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked an inline comment as done.
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:148
   void DigestAnalyzerOptions() {
-if (Opts->AnalysisDiagOpt != PD_NONE) {
-  // Create the PathDiagnosticConsumer.
-  ClangDiagPathDiagConsumer *clangDiags =
-  new ClangDiagPathDiagConsumer(PP.getDiagnostics());
-  PathConsumers.push_back(clangDiags);
-
-  if (Opts->AnalyzerWerror)
-clangDiags->enableWerror();
-
-  if (Opts->ShouldEmitFixItHintsAsRemarks)
-clangDiags->enableFixitsAsRemarks();
-
-  if (Opts->AnalysisDiagOpt == PD_TEXT) {
-clangDiags->enablePaths();
-
-  } else if (!OutDir.empty()) {
-switch (Opts->AnalysisDiagOpt) {
-default:
+switch (Opts->AnalysisDiagOpt) {
 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)
\

Will need to handle `PD_NONE`, or clang-tidy will crash all over the place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76509



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


[PATCH] D73534: [DebugInfo] Enable the debug entry values feature by default

2020-03-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Still causing a crash using a previously supplied test 
https://bugs.chromium.org/p/chromium/issues/detail?id=1061533#c7. Any reason 
this was not tested with a previous repro?


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

https://reviews.llvm.org/D73534



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


[PATCH] D52898: [Porting MergeSimilarFunctions 2/n] Changes to DataLayout

2020-03-20 Thread Vishal Chebrolu via Phabricator via cfe-commits
vish99 updated this revision to Diff 251696.
vish99 added a comment.

Changes to merge the 5 patches together


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52898

Files:
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/IPO/MergeSimilarFunctions.cpp
  llvm/lib/Transforms/Utils/CloneFunction.cpp

Index: llvm/lib/Transforms/Utils/CloneFunction.cpp
===
--- llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -162,7 +162,7 @@
 
 // Create a new basic block and copy instructions into it!
 BasicBlock *CBB = CloneBasicBlock(&BB, VMap, NameSuffix, NewFunc, CodeInfo,
-  ModuleLevelChanges ? &DIFinder : nullptr);
+  CT == CloneType::ModuleLevelChanges ? &DIFinder : nullptr);
 
 // Add basic block mapping.
 VMap[&BB] = CBB;
Index: llvm/lib/Transforms/IPO/MergeSimilarFunctions.cpp
===
--- llvm/lib/Transforms/IPO/MergeSimilarFunctions.cpp
+++ llvm/lib/Transforms/IPO/MergeSimilarFunctions.cpp
@@ -273,7 +273,7 @@
 /// IntPtrType (get it from DataLayout). This is guaranteed to generate no-op
 /// casts, otherwise it will assert.
 static Value *createCastIfNeeded(Value *V, Type *DstType,
- Value *InstrOrBB, Type *IntPtrType) {
+ Value *InstrOrBB, Type *IntPtrType, const DataLayout *DL) {
   if (V->getType() == DstType)
 return V;
 
@@ -297,7 +297,7 @@
 = Builder.CreateExtractValue(V, ArrayRef(I));
   Value *Element = createCastIfNeeded(ExtractedValue,
   DstType->getStructElementType(I),
-  InstrOrBB, IntPtrType);
+  InstrOrBB, IntPtrType, DL);
   Result =
   Builder.CreateInsertValue(Result, Element, ArrayRef(I));
 }
@@ -325,7 +325,7 @@
 llvm_unreachable("Can only cast int -> ptr or ptr -> (ptr or int)");
   }
 
-  assert(cast(Result)->isNoopCast(IntPtrType) &&
+  assert(cast(Result)->isNoopCast(*DL) &&
   "Cast is not a no-op cast. Potential loss of precision");
 
   return Result;
@@ -1395,7 +1395,7 @@
   FunctionType *FFTy = F->getFunctionType();
   Type *IntPtrTy = DL->getIntPtrType(FFTy->getContext());
   for (auto &AI : Thunk->args()) {
-Value *Cast = createCastIfNeeded(&AI, FFTy->getParamType(i), BB, IntPtrTy);
+Value *Cast = createCastIfNeeded(&AI, FFTy->getParamType(i), BB, IntPtrTy, DL);
 Args.push_back(Cast);
 ++i;
   }
@@ -1416,7 +1416,7 @@
 else if (CI->getType()->isPointerTy() && RetTy->isIntegerTy())
   Builder.CreateRet(Builder.CreatePtrToInt(CI, RetTy));
 else {
-  Value *Cast = createCastIfNeeded(CI, RetTy, BB, IntPtrTy);
+  Value *Cast = createCastIfNeeded(CI, RetTy, BB, IntPtrTy, DL);
   Builder.CreateRet(Cast);
 }
   }
@@ -1550,7 +1550,7 @@
 Instruction *F1InstInNewF, const std::vector &F2Insts,
 Function *NewF, ValueToValueMapTy &F1toNewF,
 const SmallVectorImpl &Comps,
-Type *IntPtrTy) {
+Type *IntPtrTy, const DataLayout *DL) {
   assert(F2Insts.size() == Comps.size() &&
   "Mis-match between F2Insts & Comps!");
 
@@ -1598,7 +1598,7 @@
 Value *Cast = createCastIfNeeded(F2NewFOperand,
 F2OrigOperand->getType(),
 F2InstInNewF,
-IntPtrTy);
+IntPtrTy, DL);
 F2InstInNewF->setOperand(OpId, Cast);
   }
 }
@@ -1621,7 +1621,7 @@
 F2Ret->setOperand(0,
   createCastIfNeeded(F2Ret->getReturnValue(),
  F1Ret->getReturnValue()->getType(),
- F2Ret, IntPtrTy));
+ F2Ret, IntPtrTy, DL));
 }
   } else if (!F1InstInNewF->use_empty()) {
 // If the instructions have uses, we need to insert a PHI node.
@@ -1649,7 +1649,7 @@
 createCastIfNeeded(F2InstInNewF,
   F1IType,
   Terminators[FnI+1],
-  IntPtrTy));
+  IntPtrTy, DL));
   }
 
   Phi->addIncoming(F2InstInNewF, F2InstInNewF->getParent());
@@ -1742,7 +1742,7 @@
   const DataLayout *FTD = Fns[FnI]->getDataLayout();
   Type *IntPtrTy = FTD ? FTD->getIntPtrType(Ctx) : NULL;
   F2InValNewF = createCastIfNeeded(F2InValNewF, F1InValNewF->getType(),
-   InsertPt, IntPtrTy);
+   InsertPt, IntPtrTy, FTD);
 
   // Create compare & select
   Value *ChoiceArg = getLastArg(NewF);
@@ -1970,7 +1970,7 @@
   continue; // we already handled these above
 
   

[PATCH] D76377: Correctly initialize the DW_AT_comp_dir attribute of Clang module skeleton CUs

2020-03-20 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl marked an inline comment as done.
aprantl added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2499
+DIB.createFile(Mod.getModuleName(), TheCU->getDirectory()),
+TheCU->getProducer(), false, StringRef(), 0, Mod.getASTFile(),
+llvm::DICompileUnit::FullDebug, Signature);

probinson wrote:
> The isOptimized parameter changed from true to false?
Good catch, that was a drive-by fix. It has no meaning in the skeleton CU so we 
might as well not set it. Should be a separate commit though.


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

https://reviews.llvm.org/D76377



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


[PATCH] D75661: Remove SequentialType from the type heirarchy.

2020-03-20 Thread Eli Friedman via Phabricator via cfe-commits
efriedma marked 2 inline comments as done.
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1059
+llvm::Type *ElemTy = ArrayTy->getElementType();
+bool ZeroInitializer = constant->isNullValue();
 llvm::Constant *OpValue, *PaddedOp;

ctetreau wrote:
> I assume the reasoning here is that [-0.0f, ...] isn't the zero initialized 
> value, but why make this change now? Seems unrelated.
I'll post this separately for review, since it's a little complicated.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1078
   }
+  // FIXME: Do we need to handle tail padding in vectors?
   return constant;

ctetreau wrote:
> The fact that you have to ask this question tells me that you should probably 
> just make this handle vectors.
> 
> You could add a templated helper function above this function that is 
> basically just the original body of the SequentialType branch.
Well, no, the original code doesn't handle vectors either.  The issue here 
would be that we need to pad out the vector with additional elements, or 
something like that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75661



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


[PATCH] D76384: Move FPFeatures from BinaryOperator bitfields to Trailing storage

2020-03-20 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 251699.
mibintc retitled this revision from "Move FPFeatures from BinaryOperator 
bitfields to Trailing storage - preliminary" to "Move FPFeatures from 
BinaryOperator bitfields to Trailing storage".
mibintc added a comment.

This revision has been rebased, the LIT test failures seen in the previous 
revision have been corrected: check-all passes.  Still owe you some polishing. 
I'm going to add a couple inline comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76384

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/StmtVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/Analysis/ReachableCode.cpp
  clang/lib/Analysis/ThreadSafetyCommon.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Frontend/Rewrite/RewriteObjC.cpp
  clang/lib/Index/IndexBody.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaPseudoObject.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/AST/ast-dump-expr-json.c
  clang/test/AST/ast-dump-expr.c
  clang/test/AST/dump.cpp
  clang/test/Analysis/loopexit-cfg-output.cpp
  clang/test/Import/compound-assign-op/test.cpp
  clang/test/Sema/warn-unreachable.c
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -383,10 +383,6 @@
 K = CXCursor_BinaryOperator;
 break;
 
-  case Stmt::CompoundAssignOperatorClass:
-K = CXCursor_CompoundAssignOperator;
-break;
-
   case Stmt::ConditionalOperatorClass:
 K = CXCursor_ConditionalOperator;
 break;
Index: clang/test/Sema/warn-unreachable.c
===
--- clang/test/Sema/warn-unreachable.c
+++ clang/test/Sema/warn-unreachable.c
@@ -83,8 +83,8 @@
 -   // expected-warning {{will never be executed}}
   halt();
   case 8:
-i
-  +=// expected-warning {{will never be executed}}
+i   // expected-warning {{will never be executed}}
+  +=
   halt();
   case 9:
 halt()
Index: clang/test/Import/compound-assign-op/test.cpp
===
--- clang/test/Import/compound-assign-op/test.cpp
+++ clang/test/Import/compound-assign-op/test.cpp
@@ -2,42 +2,42 @@
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '+='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '-='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '*='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '/='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '&='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '^='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '<<='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '>>='
 
 void expr() {
Index: clang/test/Analysis/loopexit-cfg-output.cpp
===

[PATCH] D76504: [clang] Fix crash during template sema checking

2020-03-20 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Please post patches against master, not previous versions of the patch.

I think you want to check isValueDependent(); isInstantiationDependent() 
includes some other stuff that isn't relevant here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76504



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


[PATCH] D75591: [OpenMP] Add firstprivate as a default data-sharing attribute to clang

2020-03-20 Thread Fady Ghanim via Phabricator via cfe-commits
fghanim added a comment.

My comments were nits so.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75591



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


[PATCH] D76384: Move FPFeatures from BinaryOperator bitfields to Trailing storage

2020-03-20 Thread Melanie Blower via Phabricator via cfe-commits
mibintc marked 3 inline comments as done.
mibintc added a comment.

In D76384#1929774 , @mibintc wrote:

> There's a bug in this patch that i haven't solved yet. I think it's just 1 
> bug. The bug is that the AST statement visitor is going to the "fallback" 
> instead of the right destination when walking CompoundAssignmentOperator.  
> This patch collapses CompoundAssignmentOperator class into BinaryOperator 
> class.  In a spot check, i think all the failing tests are because the 
> Visitor walk isn't working correctly for CompoundAssign (for example += ). 
> These are the test fails reported by check-clang in my sandbox,
>  Failing Tests (15):
>
>   Clang :: Analysis/loopexit-cfg-output.cpp
>   Clang :: CXX/drs/dr2xx.cpp
>   Clang :: CXX/expr/expr.const/p2-0x.cpp
>   Clang :: 
> CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p17.cpp
>   Clang :: CodeGen/ffp-contract-fast-option.cpp
>   Clang :: CodeGenCXX/const-init-cxx1y.cpp
>   Clang :: CodeGenCXX/const-init-cxx2a.cpp
>   Clang :: CodeGenCXX/non-const-init-cxx2a.cpp
>   Clang :: Sema/warn-unreachable.c
>   Clang :: Sema/warn-unsequenced.c
>   Clang :: SemaCXX/constant-expression-cxx1y.cpp
>   Clang :: SemaCXX/constant-expression-cxx2a.cpp
>   Clang :: SemaCXX/decomposed-condition.cpp
>   Clang :: SemaCXX/integer-overflow.cpp
>   Clang :: SemaCXX/warn-unsequenced.cpp


The new revision corrects all these fails. i have a couple questions about test 
cases, i've inline those in the test case modification. Also need to do 
clang-format and also some changes to CXXCallOperator to remove redundant 
accessor




Comment at: clang/include/clang/AST/ExprCXX.h:168
   // operations on floating point types.
   void setFPFeatures(FPOptions F) {
+FPFeatures = F;

i can get rid of these 2 accessor functions, we get them from CallExpr



Comment at: clang/test/Analysis/loopexit-cfg-output.cpp:211
 // CHECK:   [B3]
-// CHECK-NEXT:   1: j
-// CHECK-NEXT:   2: 2
-// CHECK-NEXT:   3: [B3.1] += [B3.2]
+// CHECK-NEXT:   1: 2
+// CHECK-NEXT:   2: j

With these changes, the blocks print out in a different order but the semantic 
meaning appears to be the same. Is this difference acceptable? 



Comment at: clang/test/Sema/warn-unreachable.c:86
   case 8:
-i
-  +=// expected-warning {{will never be executed}}
+i   // expected-warning {{will never be executed}}
+  +=

The srcpos for compound assignment is now the same as srcpos for ordinary 
binary operator, so i changed the test case to move the diagnostic,  ok?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76384



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


[PATCH] D76395: [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes

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

LGTM aside from some small nits!




Comment at: clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt:15
   clangTooling
+  clangTidyPortabilityModule
   )

Can you keep this list sorted in alphabetical order?



Comment at: 
clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h:85
 #endif // 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H
\ No newline at end of file


Can you add a newline to the end of the file (as a drive-by)?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst:32
+
+   This can be used to whitelist known safe includes such as Linux development
+   headers. See :doc:`portability-restrict-system-includes

whitelist -> allow


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76395



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


[PATCH] D75661: Remove SequentialType from the type heirarchy.

2020-03-20 Thread Christopher Tetreault via Phabricator via cfe-commits
ctetreau added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1078
   }
+  // FIXME: Do we need to handle tail padding in vectors?
   return constant;

efriedma wrote:
> ctetreau wrote:
> > The fact that you have to ask this question tells me that you should 
> > probably just make this handle vectors.
> > 
> > You could add a templated helper function above this function that is 
> > basically just the original body of the SequentialType branch.
> Well, no, the original code doesn't handle vectors either.  The issue here 
> would be that we need to pad out the vector with additional elements, or 
> something like that.
At a cursory glance, it seemed to me that the addition of this comment implied 
that it used to handle the tail padding. However, after having dug into what 
this function does, assuming that vectors only ever actually contain scalars, 
then it seems that this does currently just return the original vector and that 
this patch does not change the behavior.

Given this, your comment really kind of just says "FIXME: is this function 
correct?", a question that applies to basically every function. If you have 
reason to believe that the answer to your question is yes, you should probably 
add why you think so to this comment. Otherwise, I think you should remove it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75661



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


[PATCH] D31342: Add ParsedAttrInfo::handleDeclAttribute

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

LGTM!


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

https://reviews.llvm.org/D31342



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


[PATCH] D31343: Add an attribute plugin example

2020-03-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/examples/Attribute/Attribute.cpp:35
+Spellings.push_back({ParsedAttr::AS_GNU, "example"});
+Spellings.push_back({ParsedAttr::AS_CXX11, "::example"});
+Spellings.push_back({ParsedAttr::AS_CXX11, "plugin::example"});

john.brawn wrote:
> aaron.ballman wrote:
> > This is not a valid spelling for an attribute (we should probably assert 
> > that an attribute-scoped-token does not have an empty scope).
> "::example" is actually how an unscoped spelling is specified - normalizeName 
> in Basic/Attributes.cpp adds a "::" to the start if there's no scope, and the 
> tablegen-generated getAttrKind expects it as well.
It's not how an unscoped spelling is specified by either C or C++ -- in both 
languages, that would be an error. I don't think we want to leak this 
implementation detail out to the user as it will be confusing to them.



Comment at: clang/examples/Attribute/Attribute.cpp:42
+// This attribute appertains to functions only.
+if (!D || !isa(D)) {
+  S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type_str)

john.brawn wrote:
> aaron.ballman wrote:
> > I don't think `D` can ever be null, can it?
> I don't know, but this is how the auto-generated diagAppertainsToDecl 
> functions do it.
I'll fix that up -- I just verified that `D` can never be null. 
`Sema::ProcessDeclAttributeList` dereferences `D` unconditionally and has for a 
long time.


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

https://reviews.llvm.org/D31343



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


[PATCH] D73534: [DebugInfo] Enable the debug entry values feature by default

2020-03-20 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In D73534#1933988 , @djtodoro wrote:

> In D73534#1933985 , @djtodoro wrote:
>
> > Oh sorry, I thought it all has been fixed, since all the tests pass.
> >
> > We should revert the D75036  until we fix 
> > all the issues.
>
>
> @dstenb do you agree?


This was an oversight on my part, the fix from D76164 
 was not complete. I need a few more minutes 
to write a test, but I should be able to fix this very soon. If we can 
fix-forward, that would be easier.


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

https://reviews.llvm.org/D73534



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


[PATCH] D73534: [DebugInfo] Enable the debug entry values feature by default

2020-03-20 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro added a comment.

In D73534#1934105 , @vsk wrote:

> In D73534#1933988 , @djtodoro wrote:
>
> > In D73534#1933985 , @djtodoro 
> > wrote:
> >
> > > Oh sorry, I thought it all has been fixed, since all the tests pass.
> > >
> > > We should revert the D75036  until we 
> > > fix all the issues.
> >
> >
> > @dstenb do you agree?
>
>
> This was an oversight on my part, the fix from D76164 
>  was not complete. I need a few more minutes 
> to write a test, but I should be able to fix this very soon. If we can 
> fix-forward, that would be easier.


@vsk That would be great. Thanks a lot!


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

https://reviews.llvm.org/D73534



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


[PATCH] D73534: [DebugInfo] Enable the debug entry values feature by default

2020-03-20 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro added a comment.

In D73534#1933985 , @djtodoro wrote:

> Oh sorry, I thought it all has been fixed, since all the tests pass.
>
> We should revert the D75036  until we fix 
> all the issues.


@dstenb do you agree?


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

https://reviews.llvm.org/D73534



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


[PATCH] D73534: [DebugInfo] Enable the debug entry values feature by default

2020-03-20 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro added a comment.

Oh sorry, I thought it all has been fixed, since all the tests pass.

We should revert the D75036  until we fix all 
the issues.


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

https://reviews.llvm.org/D73534



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


[PATCH] D73534: [DebugInfo] Enable the debug entry values feature by default

2020-03-20 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

@manojgupta I apologize for not catching this earlier. The issue should really 
be fixed by 636665331bbd4c369a9f33c4d35fb9a863c94646 
.


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

https://reviews.llvm.org/D73534



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


[clang] 06dea73 - [OPENMP50]Initial support for inclusive clause.

2020-03-20 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-03-20T14:20:38-04:00
New Revision: 06dea73307e75f0227ba24cab2adf2e4dad62b88

URL: 
https://github.com/llvm/llvm-project/commit/06dea73307e75f0227ba24cab2adf2e4dad62b88
DIFF: 
https://github.com/llvm/llvm-project/commit/06dea73307e75f0227ba24cab2adf2e4dad62b88.diff

LOG: [OPENMP50]Initial support for inclusive clause.

Added parsing/sema/serialization support for inclusive clause in scan
directive.

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/nesting_of_regions.cpp
clang/test/OpenMP/scan_ast_print.cpp
clang/test/OpenMP/scan_messages.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index e82a5f09a32d..38485cb1ad7e 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6911,6 +6911,80 @@ class OMPDetachClause final : public OMPClause {
   }
 };
 
+/// This represents clause 'inclusive' in the '#pragma omp scan' directive.
+///
+/// \code
+/// #pragma omp scan inclusive(a,b)
+/// \endcode
+/// In this example directive '#pragma omp scan' has clause 'inclusive'
+/// with the variables 'a' and 'b'.
+class OMPInclusiveClause final
+: public OMPVarListClause,
+  private llvm::TrailingObjects {
+  friend class OMPClauseReader;
+  friend OMPVarListClause;
+  friend TrailingObjects;
+
+  /// Build clause with number of variables \a N.
+  ///
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  /// \param N Number of the variables in the clause.
+  OMPInclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
+ SourceLocation EndLoc, unsigned N)
+  : OMPVarListClause(OMPC_inclusive, StartLoc,
+ LParenLoc, EndLoc, N) {}
+
+  /// Build an empty clause.
+  ///
+  /// \param N Number of variables.
+  explicit OMPInclusiveClause(unsigned N)
+  : OMPVarListClause(OMPC_inclusive, SourceLocation(),
+ SourceLocation(), 
SourceLocation(),
+ N) {}
+
+public:
+  /// Creates clause with a list of variables \a VL.
+  ///
+  /// \param C AST context.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  /// \param VL List of references to the original variables.
+  static OMPInclusiveClause *Create(const ASTContext &C,
+SourceLocation StartLoc,
+SourceLocation LParenLoc,
+SourceLocation EndLoc, ArrayRef 
VL);
+
+  /// Creates an empty clause with the place for \a N variables.
+  ///
+  /// \param C AST context.
+  /// \param N The number of variables.
+  static OMPInclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
+
+  child_range children() {
+return child_range(reinterpret_cast(varlist_begin()),
+   reinterpret_cast(varlist_end()));
+  }
+
+  const_child_range children() const {
+auto Children = const_cast(this)->children();
+return const_child_range(Children.begin(), Children.end());
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == OMPC_inclusive;
+  }
+};
+
 /// This class implements a simple visitor for OMPClause
 /// subclasses.
 template class Ptr, typename RetTy>

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 4cc8b95c3bd1..94f68f555fdf 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3183,6 +3183,13 @@ bool RecursiveASTVisitor::VisitOMPClauseList(T 
*Node) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPInclusiveClause(
+OMPInclusiveClause *C) {
+  TRY_TO(VisitOMPClauseList(C));
+  return true;
+}
+
 template 
 bool RecursiveASTVisitor::VisitOMPPrivateClause(OMPPrivateCl

[PATCH] D76510: [analyzer] Change the default output type to PD_TEXT_MINIMAL, error if an output loc is missing for PathDiagConsumers that need it

2020-03-20 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware accepted this revision.
baloghadamsoftware added a comment.
This revision is now accepted and ready to land.

Basically LGTM, but please wait for @NoQ or someone for the compatibility 
questions.




Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:26
 #include "clang/CrossTU/CrossTranslationUnit.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Frontend/CompilerInstance.h"

Why?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76510



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


[PATCH] D73534: [DebugInfo] Enable the debug entry values feature by default

2020-03-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Thanks for the quick fix, verified that the crash is fixed on trunk.


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

https://reviews.llvm.org/D73534



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


[PATCH] D76395: [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes

2020-03-20 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76395



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


[PATCH] D76395: [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes

2020-03-20 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 251713.
PaulkaToast marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76395

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/math.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -3,11 +3,11 @@
 // RUN:   -resource-dir %S/Inputs/llvmlibc/resource
 
 #include 
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not allowed
 #include 
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not allowed
 #include "string.h"
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed
 #include "stdatomic.h"
 #include 
 // Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
-// RUN:   -- -header-filter=.* \
-// RUN:   -- -I %S/Inputs/llvmlibc \
-// RUN:   -isystem %S/Inputs/llvmlibc/system \
-// RUN:   -resource-dir %S/Inputs/llvmlibc/resource
-
-#include "transitive.h"
-// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
+++ /dev/null
@@ -1 +0,0 @@
-#include 
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -18,3 +18,18 @@
 whose ``dirent`` struct has slightly different field ordering than llvm-libc.
 While this will compile successfully, this can cause issues during runtime
 because they are ABI incompatible.
+
+Options
+---
+
+.. option:: Includes
+
+   A string containing a comma separated glob list of allowed include
+   filenames. Similar to the -checks glob list for running clang-tidy itself,
+   the two wildcard characters are `*` and `-`, to include and exclude globs,
+   respectively. The default is `-*`, which disallows all includes.
+
+   This can be used to allow known safe includes such as Linux development
+   headers. See :doc:`portability-restrict-system-includes
+   ` for more
+   details.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,7 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
-   `llvmlibc-restrict-system-libc-headers `_,
+   `llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
`misc-new-delete-overloads `_,
Index: clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
===
--- clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
+++ clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesChe

[PATCH] D72810: [LifetimeAnalysis] Add support for lifetime annotations on functions

2020-03-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/LifetimeAttr.h:163
+// Maps each annotated entity to a lifetime set.
+using LifetimeContracts = std::map;
+

xazax.hun wrote:
> aaron.ballman wrote:
> > xazax.hun wrote:
> > > gribozavr2 wrote:
> > > > Generally, DenseMap and DenseSet are faster. Any reason to not use them 
> > > > instead?
> > > No specific reason other than I am always insecure about the choice. 
> > > Dense data structures are great for small objects and I do not know where 
> > > the break even point is and never really did any benchmarks. Is there 
> > > some guidelines somewhere for what object size should we prefer one over 
> > > the other?
> > I usually figure that if it's less than two pointers in size, it's 
> > sufficiently small, but maybe others have a different opinion. This class 
> > is probably a bit large for using dense containers.
> > 
> > I do worry a little bit about the hoops we're jumping through to make the 
> > class orderable -- is there a reason to avoid an unordered container 
> > instead?
> I am not insisting on using ordered containers but note that since I have no 
> idea how to get a deterministic and efficient hash value of a `RecordDecl` I 
> would likely just include the address of the canonical decl. So the order of 
> the elements in the container would be non-deterministic both ways. But the 
> algorithm (other than the debug dumps which are fixable) will not depend on 
> the order of the elements.
I guess I was more speaking to the point that, if this is going to be unordered 
anyway, why not just use unordered containers and not attempt to impose an 
ordering in the first place? If the nondeterminism is not user-observable, then 
I'm not certain it matters.



Comment at: clang/include/clang/AST/LifetimeAttr.h:70
+  bool operator<(const LifetimeContractVariable &O) const {
+if (Tag != O.Tag)
+  return Tag < O.Tag;

xazax.hun wrote:
> aaron.ballman wrote:
> > I think it would be easier to read if the pattern was: `if (Foo < Bar) 
> > return true;` as opposed to checking inequality before returning the 
> > comparison.
> I think this might not be equivalent. 
> 
> The code below will always early return if the `Tag` is not the same.
> ```
> if (Tag != O.Tag)
>   return Tag < O.Tag;
> ```
> 
> The code below will only early return if the condition is true.
> 
> ```
> if (Tag < O.Tag)
>   return true;
> ```
> 
> So I think the pattern above is an optimization. 
> 
Good point about ordering requirements, but this is still extremely hard to 
read. Can you use `std::tie()` to simplify the logic somewhat?



Comment at: clang/include/clang/AST/LifetimeAttr.h:79
+  if (RD != O.RD)
+return std::less()(RD, O.RD);
+

xazax.hun wrote:
> aaron.ballman wrote:
> > This will have non deterministic behavior between program executions -- are 
> > you sure that's what we want? Similar below for fields.
> Good point. As far as the analysis is concerned the end result should always 
> be the same. I see potential problems in the tests where the contents of some 
> ordered data structures using this ordering is dumped. I do not see any 
> natural (and preformant) way to order RecordDecls. (I can order FieldDecls 
> using their indices.) Are you ok with sorting the string representation 
> before outputting them as strings? This should solve the potential 
> non-deterministic behavior of tests. 
Would it make sense to order the records by their source location when the 
pointer values are not equal? Or ordering on the fully-qualified name of the 
record?



Comment at: clang/lib/Sema/SemaType.cpp:7727
 
+// Move function type attribute to the declarator.
+case ParsedAttr::AT_LifetimeContract:

xazax.hun wrote:
> aaron.ballman wrote:
> > This is not an okay thing to do for C++ attributes. They have a specific 
> > meaning as to what they appertain to and do not move around to better 
> > subjects like GNU-style attributes.
> Yeah, I know that. But this is problematic in the standard. See the contracts 
> proposal which also kind of violates this rule by adding an exception. 
> Basically, this is the poor man's version of emulating the contracts 
> proposal.  In the long term we plan to piggyback on contracts rather than 
> hacking the C++ attributes.
The contracts proposal was not adopted and I am opposed to adding this change 
for any standard attribute. We've done a lot of work to ensure that those 
attributes attach to the correct thing based on lexical placement and I don't 
want to start to undo that effort.


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

https://reviews.llvm.org/D72810



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


[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-20 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/CodeGen/CGCUDARuntime.h:51
+};
+unsigned Kind : 2;
+unsigned Extern : 1;

This should be `DeviceVarKind`



Comment at: clang/lib/CodeGen/CGCUDARuntime.h:53
+unsigned Extern : 1;
+unsigned Constant : 2;   // Constant variable.
+unsigned Normalized : 1; // Normalized texture.

Why does it need 2 bits?

In general, I think there's no point squeezing things into bitfields here as 
this struct is not going to be used all that often. I'd just use enum and bool.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:701-713
+  if (getLangOpts().CUDAIsDevice) {
+// As CUDA builtin surface/texture types are replaced, skip generating TBAA
+// access info.
+if (AccessType->isCUDADeviceBuiltinSurfaceType()) {
+  if (getTargetCodeGenInfo().getCUDADeviceBuiltinSurfaceDeviceType() !=
+  nullptr)
+return TBAAAccessInfo();

Would `isCUDADeviceBuiltinTextureType()` be sufficient criteria for skipping 
TBAA regeneration?
Or does it need to be 'it is the texture type and it will be replaced with 
something else'? What is 'something else' is the same type?





Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4101-4127
+if (const ClassTemplateSpecializationDecl *TD =
+dyn_cast(RD)) {
+  Linkage = llvm::GlobalValue::InternalLinkage;
+  const TemplateArgumentList &Args = 
TD->getTemplateInstantiationArgs();
+  if (RD->hasAttr()) {
+assert(Args.size() == 2 &&
+   "Unexpcted number of template arguments of CUDA device "

This is the part I'm not comfortable with.
It's possible for the user to use the attribute on other types that do not 
match the expectations encoded here.
We should not be failing with an assert here because that's *user* error, not a 
compiler bug.

Expectations we have for the types should be enforced by Sema and compiler 
should produce proper diagnostics.




Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4107
+assert(Args.size() == 2 &&
+   "Unexpcted number of template arguments of CUDA device "
+   "builtin surface type.");

Nit: 'Unexp*e*cted'



Comment at: clang/lib/CodeGen/TargetInfo.cpp:6471-6472
+// Lookup `addrspacecast` through the constant pointer if any.
+if (auto *ASC = llvm::dyn_cast_or_null(C))
+  C = llvm::cast(ASC->getPointerOperand());
+if (auto *GV = llvm::dyn_cast_or_null(C)) {

What's the expectation here? Do we care which address spaces we're casting 
to/from? 



Comment at: clang/lib/CodeGen/TargetInfo.cpp:6561
+  if (Ty->isCUDADeviceBuiltinSurfaceType())
+return ABIArgInfo::getDirect(llvm::Type::getInt64Ty(getVMContext()));
+  if (Ty->isCUDADeviceBuiltinTextureType())

This part could use some additional comments. Why do we return an int64? Is 
that the size of the handle object? Is it guaranteed to always be a 64-bit int, 
or does it depend on particualr PTX version?



Comment at: clang/lib/Headers/__clang_cuda_runtime_wrapper.h:82-94
 #undef __CUDACC__
 #if CUDA_VERSION < 9000
 #define __CUDABE__
 #else
+#define __CUDACC__
 #define __CUDA_LIBDEVICE__
 #endif

Please add comments on why __CUDACC__ is needed for driver_types.h here? 
AFAICT, driver_types.h does not have any conditionals that depend on 
__CUDACC__. What happens if it's not defined.





Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6944-6945
+handleSimpleAttributeWithExclusions(S, D,
+  AL);
+break;

Nit: Formatting is a bit odd here. Why is AL on a separate line?



Comment at: clang/test/CodeGenCUDA/surface.cu:12-14
+template
+struct __attribute__((device_builtin_surface_type)) surface : public 
surfaceReference {
+};

Please add a test for applying the attribute to a wrong type. I.e. a 
non-template or a template with different number or kinds of parameters. We 
should have a proper syntax error and not a compiler crash or silent failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365



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


[PATCH] D76520: [CUDA][HIP] Add -Xarch_device and -Xarch_host options

2020-03-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added a reviewer: jdoerfert.

The argument after -Xarch_device will be added to the arguments for CUDA/HIP
device compilation and will be removed for host compilation.

The argument after -Xarch_host will be added to the arguments for CUDA/HIP
host compilation and will be removed for device compilation.


https://reviews.llvm.org/D76520

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Compilation.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/hip-options.hip

Index: clang/test/Driver/hip-options.hip
===
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -13,3 +13,15 @@
 // RUN:   -mllvm -amdgpu-early-inline-all=true  %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=MLLVM %s
 // MLLVM-NOT: "-mllvm"{{.*}}"-amdgpu-early-inline-all=true"{{.*}}"-mllvm"{{.*}}"-amdgpu-early-inline-all=true"
+
+// RUN: %clang -### -Xarch_device -g -nogpulib --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=DEV %s
+// DEV: clang{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}"
+// DEV: clang{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}"
+// DEV-NOT: clang{{.*}} {{.*}} "-debug-info-kind={{.*}}"
+
+// RUN: %clang -### -Xarch_host -g -nogpulib --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=HOST %s
+// HOST-NOT: clang{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}"
+// HOST-NOT: clang{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}"
+// HOST: clang{{.*}} "-debug-info-kind={{.*}}"
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -378,12 +378,6 @@
   const OptTable &Opts = getDriver().getOpts();
 
   for (Arg *A : Args) {
-if (A->getOption().matches(options::OPT_Xarch__)) {
-  // Skip this argument unless the architecture matches BoundArch.
-  if (BoundArch.empty() || A->getValue(0) != BoundArch)
-continue;
-  TranslateXarchArgs(Args, A, DAL);
-}
 DAL->append(A);
   }
 
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -800,12 +800,6 @@
   }
 
   for (Arg *A : Args) {
-if (A->getOption().matches(options::OPT_Xarch__)) {
-  // Skip this argument unless the architecture matches BoundArch
-  if (BoundArch.empty() || A->getValue(0) != BoundArch)
-continue;
-  TranslateXarchArgs(Args, A, DAL);
-}
 DAL->append(A);
   }
 
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -1103,11 +1103,17 @@
   return nullptr;
 }
 
-void ToolChain::TranslateXarchArgs(const llvm::opt::DerivedArgList &Args,
-   llvm::opt::Arg *&A,
-   llvm::opt::DerivedArgList *DAL) const {
+void ToolChain::TranslateXarchArgs(
+const llvm::opt::DerivedArgList &Args, llvm::opt::Arg *&A,
+llvm::opt::DerivedArgList *DAL,
+SmallVectorImpl *AllocatedArgs) const {
   const OptTable &Opts = getDriver().getOpts();
-  unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
+  unsigned ValuePos = 1;
+  if (A->getOption().matches(options::OPT_Xarch_device) ||
+  A->getOption().matches(options::OPT_Xarch_host))
+ValuePos = 0;
+
+  unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(ValuePos));
   unsigned Prev = Index;
   std::unique_ptr XarchArg(Opts.ParseOneArg(Args, Index));
 
@@ -1130,5 +1136,49 @@
   }
   XarchArg->setBaseArg(A);
   A = XarchArg.release();
-  DAL->AddSynthesizedArg(A);
+  if (!AllocatedArgs)
+DAL->AddSynthesizedArg(A);
+  else
+AllocatedArgs->push_back(A);
+}
+
+llvm::opt::DerivedArgList *ToolChain::TranslateXarchArgs(
+const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
+Action::OffloadKind OFK,
+SmallVectorImpl *AllocatedArgs) const {
+  DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
+  bool Modified = false;
+
+  bool IsGPU = OFK == Action::OFK_Cuda || OFK == Action::OFK_HIP;
+  for (Arg *A : Args) {
+bool NeedTrans = false;
+bool Skip = false;
+if (A->getOption().matches(options::OPT_Xarch_device)) {
+  NeedTrans = IsGPU;
+  Skip = !IsGPU;
+} else if (A->getOption().matches(options::OPT_Xarch_host)) {
+  NeedTrans = !IsGPU;
+  Skip = IsGPU;
+} else if (A->getOption().matches(options::OPT_Xarch__) && IsGPU) {
+  // Do not translate -Xarch_ options for non CUDA/HIP toolchain since
+  //

[clang] 9b95929 - [OPENMP50]Do not allow several scan directives in the same parent

2020-03-20 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-03-20T15:45:31-04:00
New Revision: 9b95929a26e133bc3cae9f29f91e8e351d233840

URL: 
https://github.com/llvm/llvm-project/commit/9b95929a26e133bc3cae9f29f91e8e351d233840
DIFF: 
https://github.com/llvm/llvm-project/commit/9b95929a26e133bc3cae9f29f91e8e351d233840.diff

LOG: [OPENMP50]Do not allow several scan directives in the same parent
region.

According to OpenMP 5.0, exactly one scan directive must appear in the loop 
body of an enclosing worksharing-loop, worksharing-loop SIMD, or simd construct 
on which a reduction clause with the inscan modifier is present.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/scan_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 39d29060372f..90845ecf5468 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9833,6 +9833,10 @@ def err_omp_prohibited_region_critical_same_name : Error<
   "cannot nest 'critical' regions having the same name %0">;
 def note_omp_previous_critical_region : Note<
   "previous 'critical' region starts here">;
+def err_omp_several_scan_directives_in_region : Error<
+  "exactly one 'scan' directive must appear in the loop body of an enclosing 
directive">;
+def note_omp_previous_scan_directive : Note<
+  "previous 'scan' directive used here">;
 def err_omp_sections_not_compound_stmt : Error<
   "the statement for '#pragma omp sections' must be a compound statement">;
 def err_omp_parallel_sections_not_compound_stmt : Error<

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 861b75a774d8..309ab4afa69d 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -154,6 +154,7 @@ class DSAStackTy {
 bool CancelRegion = false;
 bool LoopStart = false;
 bool BodyComplete = false;
+SourceLocation PrevScanLocation;
 SourceLocation InnerTeamsRegionLoc;
 /// Reference to the taskgroup task_reduction reference expression.
 Expr *TaskgroupReductionRef = nullptr;
@@ -781,6 +782,22 @@ class DSAStackTy {
 return Top ? Top->CancelRegion : false;
   }
 
+  /// Mark that parent region already has scan directive.
+  void setParentHasScanDirective(SourceLocation Loc) {
+if (SharingMapTy *Parent = getSecondOnStackOrNull())
+  Parent->PrevScanLocation = Loc;
+  }
+  /// Return true if current region has inner cancel construct.
+  bool doesParentHasScanDirective() const {
+const SharingMapTy *Top = getSecondOnStackOrNull();
+return Top ? Top->PrevScanLocation.isValid() : false;
+  }
+  /// Return true if current region has inner cancel construct.
+  SourceLocation getParentScanDirectiveLoc() const {
+const SharingMapTy *Top = getSecondOnStackOrNull();
+return Top ? Top->PrevScanLocation : SourceLocation();
+  }
+
   /// Set collapse value for the region.
   void setAssociatedLoops(unsigned Val) {
 getTopOfStack().AssociatedLoops = Val;
@@ -8795,11 +8812,21 @@ StmtResult 
Sema::ActOnOpenMPDepobjDirective(ArrayRef Clauses,
 StmtResult Sema::ActOnOpenMPScanDirective(ArrayRef Clauses,
   SourceLocation StartLoc,
   SourceLocation EndLoc) {
+  // Check that exactly one clause is specified.
   if (Clauses.size() != 1) {
 Diag(Clauses.empty() ? EndLoc : Clauses[1]->getBeginLoc(),
  diag::err_omp_scan_single_clause_expected);
 return StmtError();
   }
+  // Check that only one instance of scan directives is used in the same outer
+  // region.
+  if (DSAStack->doesParentHasScanDirective()) {
+Diag(StartLoc, diag::err_omp_several_scan_directives_in_region);
+Diag(DSAStack->getParentScanDirectiveLoc(),
+ diag::note_omp_previous_scan_directive);
+return StmtError();
+  }
+  DSAStack->setParentHasScanDirective(StartLoc);
   return OMPScanDirective::Create(Context, StartLoc, EndLoc, Clauses);
 }
 

diff  --git a/clang/test/OpenMP/scan_messages.cpp 
b/clang/test/OpenMP/scan_messages.cpp
index ea4e273e9d0b..3be998d0f96e 100644
--- a/clang/test/OpenMP/scan_messages.cpp
+++ b/clang/test/OpenMP/scan_messages.cpp
@@ -54,12 +54,12 @@ T tmain(T argc) {
 #pragma omp simd
   for (int i = 0; i < 10; ++i)
   switch (argc) {
-#pragma omp scan inclusive(argc)
+#pragma omp scan inclusive(argc) // expected-note 2 {{previous 'scan' 
directive used here}}
   case 1:
-#pragma omp scan inclusive(argc)
+#pragma omp scan inclusive(argc) // expected-error {{exactly one 'scan' 
directive must appear in the loop body of an enclosing directive}}
 break;
   default: {
-#pragma omp scan inclusive(argc)
+#pragma omp scan inclusive(argc) // expected-error {{exactly one 'scan' 
directive must appear in the loop body of 

[PATCH] D76438: ConstantExpr cached APValues if present for constant evaluation

2020-03-20 Thread Wyatt Childers via Phabricator via cfe-commits
wchilders marked 2 inline comments as done.
wchilders added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:7329
+  if (Result.isLValue())
+return Success(Result, E);
+}

rsmith wrote:
> wchilders wrote:
> > rsmith wrote:
> > > wchilders wrote:
> > > > This doesn't seem to be the right answer, and `ConstantExpr`s don't 
> > > > have `LValue` `APValue`s, at least, not that are reaching this case. We 
> > > > had a previous implementation that also, kind of punted on this issue 
> > > > with an override in `TemporaryExprEvaluator`: 
> > > > https://gitlab.com/lock3/clang/-/blob/9fbaeea06fc567ac472264bec2a72661a1e06c73/clang/lib/AST/ExprConstant.cpp#L9753
> > > The base class version seems appropriate to me, even for this case. We 
> > > eventually want to use `ConstantExpr` to store the evaluated initializer 
> > > value of a `constexpr` variable (replacing the existing special-case 
> > > caching on `VarDecl`) and the like, not only for immediate invocations, 
> > > and once we start doing that for reference variables we'll have glvalue 
> > > `ConstantExpr`s.
> > > 
> > > Is there some circumstance under which a glvalue `ConstantExpr`'s 
> > > `APValue` result is not of kind `LValue`?
> > > Is there some circumstance under which a glvalue ConstantExpr's APValue 
> > > result is not of kind LValue?
> > 
> > Good question, the `Sema/switch.c` test fails if you 
> > `assert(Result.isLValue())`.
> > 
> > ```
> > ConstantExpr 0x62ab8760 'const int' lvalue Int: 3
> > `-DeclRefExpr 0x62ab8740 'const int' lvalue Var 0x62ab8230 'a' 
> > 'const int'
> > ```
> > 
> > With an attributed line no. 359: 
> > https://github.com/llvm/llvm-project/blob/4b0029995853fe37d1dc95ef96f46697c743fcad/clang/test/Sema/switch.c#L359
> > 
> > The offending RValue is created in SemaExpr.cpp here: 
> > https://github.com/llvm/llvm-project/blob/f87563661d6661fd4843beb8f391acd077b08dbe/clang/lib/Sema/SemaExpr.cpp#L15190
> > 
> > The issue stems from evaluating this as an RValue to produce an integer, 
> > then caching that RValue in an lvalue constant expression. Do you have any 
> > suggestions? Perhaps an LValue to RValue conversion should be performed on 
> > the expression if it folds correctly, so that the ConstantExpr is actually 
> > an RValue?
> I think we should be inserting the lvalue-to-rvalue conversion before we even 
> try evaluating the expression. Does this go wrong along both the C++11 and 
> pre-C++11 codepaths? (They do rather different conversions to the 
> expression.) In any case, we're likely missing a call to 
> `DefaultLvalueConversion` on whichever side is failing.
> 
> Judging by the fact that `struct X { void f() { switch (0) case f: ; } };` 
> misses the "non-static member function must be called" diagnostic only in 
> C++98 mode, I'd imagine it's just the pre-C++11 codepath that's broken here.
This is a C test, the C++ language level is actually irrelevant as best I can 
tell. I added the missing LValue -> RValue conversion so that the APValue is 
generated correctly. With that things function as you'd expect, I added an 
assertion to the LValue base evaluator to detect this case early in 
development, otherwise, the logic is now shared across evaluator classes.


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

https://reviews.llvm.org/D76438



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


[PATCH] D76452: Use LLD by default for Android.

2020-03-20 Thread Stephen Hines via Phabricator via cfe-commits
srhines accepted this revision.
srhines added a comment.
This revision is now accepted and ready to land.

Thanks, Dan, for setting this up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76452



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


[PATCH] D76438: ConstantExpr cached APValues if present for constant evaluation

2020-03-20 Thread Wyatt Childers via Phabricator via cfe-commits
wchilders updated this revision to Diff 251732.
wchilders added a comment.

Updated to assume LValue `ConstantExpr`s have LValue `APValue`s, with 
verification in debug mode. Additionally, added a missing LValue -> RValue 
conversion for `VerifyIntegerConstantExpression`.


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

https://reviews.llvm.org/D76438

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15167,6 +15167,12 @@
 return ExprError();
   }
 
+  ExprResult RValueExpr = DefaultLvalueConversion(E);
+  if (RValueExpr.isInvalid())
+return ExprError();
+
+  E = RValueExpr.get();
+
   // Circumvent ICE checking in C++11 to avoid evaluating the expression twice
   // in the non-ICE case.
   if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -6751,8 +6751,13 @@
 return Error(E);
   }
 
-  bool VisitConstantExpr(const ConstantExpr *E)
-{ return StmtVisitorTy::Visit(E->getSubExpr()); }
+  bool VisitConstantExpr(const ConstantExpr *E) {
+if (E->hasAPValueResult())
+  return DerivedSuccess(E->getAPValueResult(), E);
+
+return StmtVisitorTy::Visit(E->getSubExpr());
+  }
+
   bool VisitParenExpr(const ParenExpr *E)
 { return StmtVisitorTy::Visit(E->getSubExpr()); }
   bool VisitUnaryExtension(const UnaryOperator *E)
@@ -7317,6 +7322,13 @@
 return true;
   }
 
+  // Override to perform additional checks to ensure the cached APValue
+  // is actually an LValue.
+  bool VisitConstantExpr(const ConstantExpr *E) {
+assert(!E->hasAPValueResult() || E->getAPValueResult().isLValue());
+return ExprEvaluatorBaseTy::VisitConstantExpr(E);
+  }
+
   bool VisitMemberExpr(const MemberExpr *E) {
 // Handle non-static data members.
 QualType BaseTy;
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -356,6 +356,8 @@
 }
 
 APValue ConstantExpr::getAPValueResult() const {
+  assert(hasAPValueResult());
+
   switch (ConstantExprBits.ResultKind) {
   case ConstantExpr::RSK_APValue:
 return APValueResult();
@@ -2870,9 +2872,6 @@
   return CE->getChosenSubExpr();
   }
 
-  else if (auto *CE = dyn_cast(E))
-return CE->getSubExpr();
-
   return E;
 }
 
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -1063,6 +1063,9 @@
   bool isImmediateInvocation() const {
 return ConstantExprBits.IsImmediateInvocation;
   }
+  bool hasAPValueResult() const {
+return ConstantExprBits.APValueKind != APValue::None;
+  }
   APValue getAPValueResult() const;
   APValue &getResultAsAPValue() const { return APValueResult(); }
   llvm::APSInt getResultAsAPSInt() const;


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15167,6 +15167,12 @@
 return ExprError();
   }
 
+  ExprResult RValueExpr = DefaultLvalueConversion(E);
+  if (RValueExpr.isInvalid())
+return ExprError();
+
+  E = RValueExpr.get();
+
   // Circumvent ICE checking in C++11 to avoid evaluating the expression twice
   // in the non-ICE case.
   if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -6751,8 +6751,13 @@
 return Error(E);
   }
 
-  bool VisitConstantExpr(const ConstantExpr *E)
-{ return StmtVisitorTy::Visit(E->getSubExpr()); }
+  bool VisitConstantExpr(const ConstantExpr *E) {
+if (E->hasAPValueResult())
+  return DerivedSuccess(E->getAPValueResult(), E);
+
+return StmtVisitorTy::Visit(E->getSubExpr());
+  }
+
   bool VisitParenExpr(const ParenExpr *E)
 { return StmtVisitorTy::Visit(E->getSubExpr()); }
   bool VisitUnaryExtension(const UnaryOperator *E)
@@ -7317,6 +7322,13 @@
 return true;
   }
 
+  // Override to perform additional checks to ensure the cached APValue
+  // is actually an LValue.
+  bool VisitConstantExpr(const ConstantExpr *E) {
+assert(!E->hasAPValueResult() || E->getAPValueResult().isLValue());
+return ExprEvaluatorBaseTy::VisitConstantExpr(E);
+  }
+
   bool VisitMemberExpr(const MemberExpr *E) {
 // Handle non-static data members.
 QualType BaseTy;
Index: clang/lib/AST/Expr.cpp
=

[PATCH] D76520: [CUDA][HIP] Add -Xarch_device and -Xarch_host options

2020-03-20 Thread Artem Belevich via Phabricator via cfe-commits
tra added a reviewer: echristo.
tra added a comment.

Does it handle options with values? E.g. if I want to pass 
`-mframe-pointer=none` ? I vaguely recall the current -Xarch_* implementation 
had some limitations. 
It may be worth adding a test for that.


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

https://reviews.llvm.org/D76520



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


[PATCH] D74387: [SYCL] Defer __float128 type usage diagnostics

2020-03-20 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 251735.
Fznamznon added a comment.
Herald added a subscriber: mgorny.

Added diagnosing of __float128 type usage.
See the summary of revision for details.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74387

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/CMakeLists.txt
  clang/lib/Sema/SemaAvailability.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaSYCL/float128.cpp

Index: clang/test/SemaSYCL/float128.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/float128.cpp
@@ -0,0 +1,92 @@
+// RUN: %clang_cc1 -triple spir64 -fsycl -fsycl-is-device -verify -fsyntax-only %s
+// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only %s
+
+template 
+class Z {
+public:
+  // TODO: If T is __float128 This might be a problem
+  T field;
+  //expected-error@+1 2{{'__float128' is not supported on this target}}
+  __float128 field1;
+};
+
+void host_ok(void) {
+  __float128 A;
+  int B = sizeof(__float128);
+  Z<__float128> C;
+  C.field1 = A;
+}
+
+void usage() {
+  //expected-error@+1 5{{'__float128' is not supported on this target}}
+  __float128 A;
+  Z<__float128> C;
+  //expected-error@+2 {{'A' is unavailable}}
+  //expected-error@+1 {{'field1' is unavailable}}
+  C.field1 = A;
+  //expected-error@+1 {{'A' is unavailable}}
+  decltype(A) D;
+
+  //expected-error@+1 {{'A' is unavailable}}
+  auto foo1 = [=]() {
+//expected-error@+1 {{'__float128' is not supported on this target}}
+__float128 AA;
+//expected-error@+1 {{'A' is unavailable}}
+auto BB = A;
+BB += 1;
+  };
+
+  //expected-note@+1 {{called by 'usage'}}
+  foo1();
+}
+
+template 
+void foo2(){};
+
+//expected-error@+1 {{'__float128 (__float128)' is not supported on this target}}
+__float128 foo(__float128 P) { return P; }
+
+template 
+__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+  //expected-note@+1 5{{called by 'kernel}}
+  kernelFunc();
+  //expected-error@+1 {{'__float128' is not supported on this target}}
+  __float128 A;
+}
+
+int main() {
+  //expected-error@+1 2{{'__float128' is not supported on this target}}
+  __float128 CapturedToDevice = 1;
+  host_ok();
+  kernel([=]() {
+//expected-error@+1 {{'CapturedToDevice' is unavailable}}
+decltype(CapturedToDevice) D;
+//expected-error@+1 {{'CapturedToDevice' is unavailable}}
+auto C = CapturedToDevice;
+//expected-error@+1 {{'__float128' is not supported on this target}}
+__float128 ;
+Z<__float128> S;
+//expected-error@+1 {{'field1' is unavailable}}
+S.field1 += 1;
+S.field = 1;
+  });
+
+  kernel([=]() {
+//expected-note@+1 2{{called by 'operator()'}}
+usage();
+// expected-error@+1 2{{'__float128' is not supported on this target}}
+__float128 ;
+// expected-error@+2 {{'' is unavailable}}
+// expected-error@+1 {{'foo' is unavailable}}
+auto A = foo();
+  });
+
+  kernel([=]() {
+Z<__float128> S;
+foo2<__float128>();
+// TODO: this shouldn't be diagnosed
+// expected-error@+1 {{'__float128' is not supported on this target}}
+int E = sizeof(__float128);
+  });
+  return 0;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1516,10 +1516,21 @@
 break;
   case DeclSpec::TST_float128:
 if (!S.Context.getTargetInfo().hasFloat128Type() &&
+!S.getLangOpts().SYCLIsDevice &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice))
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
 << "__float128";
 Result = Context.Float128Ty;
+if (!S.Context.getTargetInfo().hasFloat128Type() &&
+S.getLangOpts().SYCLIsDevice &&
+S.DelayedDiagnostics.shouldDelayDiagnostics()) {
+  S.DelayedDiagnostics.add(sema::DelayedDiagnostic::makeForbiddenType(
+  DS.getTypeSpecTypeLoc(), diag::err_type_unsupported, Result,
+  /*ignored*/ 0));
+  S.SYCLDiagIfDeviceCode(DS.getTypeSpecTypeLoc(),
+ diag::err_type_unsupported)
+  << Result;
+}
 break;
   case DeclSpec::TST_bool: Result = Context.BoolTy; break; // _Bool or bool
 break;
Index: clang/lib/Sema/SemaSYCL.cpp
===
--- /dev/null
+++ clang/lib/Sema/SemaSYCL.cpp
@@ -0,0 +1,63 @@
+//===- SemaSYCL.cpp - Semantic Analysis for SYCL constructs ---===//
+//
+// 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: Apa

[PATCH] D73245: Depend stddef.h to provide max_align_t for C++11 and provide better fallback in

2020-03-20 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg marked 5 inline comments as done.
joerg added inline comments.



Comment at: libcxx/include/stddef.h:58
 !defined(__DEFINED_max_align_t) && !defined(__NetBSD__)
 typedef long double max_align_t;
 #endif

ldionne wrote:
> Why do we need this at all anymore? In C++11, can't we rely on the C Standard 
> Library providing it `::max_align_t`?
Sorry, left-over. Will be killed.



Comment at: 
libcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp:40
+#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
+std::size_t maxSize = std::numeric_limits::max()
+- __STDCPP_DEFAULT_NEW_ALIGNMENT__;

ldionne wrote:
> This test is only enabled in >= C++11, so I think `std::max_align_t` should 
> always be provided. So why do we want that `#if`?
We know that the new alignment can be stricter than max_align_t and we want to 
test the overflow case here. So going for the strictest alignment is more 
sensible.



Comment at: 
libcxx/test/std/language.support/support.types/max_align_t.pass.cpp:47
+#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
+static_assert(std::alignment_of::value <=
+  __STDCPP_DEFAULT_NEW_ALIGNMENT__,

ldionne wrote:
> Since we now assume that `__STDCPP_DEFAULT_NEW_ALIGNMENT__` is defined, can 
> we remove that `#if` and keep the assertion?
It's only required in C++03 mode. We still support C++11 and higher without it, 
e.g. for gcc.



Comment at: 
libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp:275
+#if TEST_STD_VER >= 11
+const size_t alignment = TEST_ALIGNOF(std::max_align_t) > 16 ?
+16 : TEST_ALIGNOF(std::max_align_t);

ldionne wrote:
> Can you walk me through why the check for `> 16` is required?
If max_align_t is 256bit, we still only expect 128bit alignment (long double). 
This test is still checking more than it should, e.g. in principle a target 
could legitimately have no natural type larger than 64bit, but support 256bit 
vector types and set max_align_t accordingly. The condition is here because 
std::min in C++11 is not constexpr.


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

https://reviews.llvm.org/D73245



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


[PATCH] D76384: Move FPFeatures from BinaryOperator bitfields to Trailing storage

2020-03-20 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 251746.
mibintc added a comment.

This revision fixes the clang-tidy,clang-format and removes the redundant 
accessors. Ready for your review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76384

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/StmtVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/Analysis/ReachableCode.cpp
  clang/lib/Analysis/ThreadSafetyCommon.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Frontend/Rewrite/RewriteObjC.cpp
  clang/lib/Index/IndexBody.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaPseudoObject.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/AST/ast-dump-expr-json.c
  clang/test/AST/ast-dump-expr.c
  clang/test/AST/dump.cpp
  clang/test/Analysis/loopexit-cfg-output.cpp
  clang/test/Import/compound-assign-op/test.cpp
  clang/test/Sema/warn-unreachable.c
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -383,10 +383,6 @@
 K = CXCursor_BinaryOperator;
 break;
 
-  case Stmt::CompoundAssignOperatorClass:
-K = CXCursor_CompoundAssignOperator;
-break;
-
   case Stmt::ConditionalOperatorClass:
 K = CXCursor_ConditionalOperator;
 break;
Index: clang/test/Sema/warn-unreachable.c
===
--- clang/test/Sema/warn-unreachable.c
+++ clang/test/Sema/warn-unreachable.c
@@ -83,9 +83,9 @@
 -   // expected-warning {{will never be executed}}
   halt();
   case 8:
-i
-  +=// expected-warning {{will never be executed}}
-  halt();
+i // expected-warning {{will never be executed}}
++=
+halt();
   case 9:
 halt()
   ? // expected-warning {{will never be executed}}
Index: clang/test/Import/compound-assign-op/test.cpp
===
--- clang/test/Import/compound-assign-op/test.cpp
+++ clang/test/Import/compound-assign-op/test.cpp
@@ -2,42 +2,42 @@
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '+='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '-='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '*='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '/='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '&='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '^='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '<<='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '>>='
 
 void expr() {
Index: clang/test/Analysis/loopexit-cfg-output.cpp
===
--- clang/test/Analysis/loopexit-cfg-output.cpp
+++ clang/test/Analysis/loopexit-cfg-output.cpp
@@ -208,9 +208,9 @@
 // CHECK-NEXT:   Succs (2): B4 B1
 
 // CHECK:   [B3]
-// CHECK-NEXT:  

[PATCH] D76438: ConstantExpr cached APValues if present for constant evaluation

2020-03-20 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/ExprConstant.cpp:7325-7329
+  // Override to perform additional checks to ensure the cached APValue
+  // is actually an LValue.
+  bool VisitConstantExpr(const ConstantExpr *E) {
+assert(!E->hasAPValueResult() || E->getAPValueResult().isLValue());
+return ExprEvaluatorBaseTy::VisitConstantExpr(E);

I think this override is now fully redundant and can be removed: the 
`isLValue()` assert is reached anyway when `DerivedSuccess` calls 
`LValueExprEvaluatorBase::Success` which calls `LValue::setFrom`.


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

https://reviews.llvm.org/D76438



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


[PATCH] D74918: Add method to TargetInfo to get CPU cache line size

2020-03-20 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver added a comment.

In D76525  I've added a builtin that uses this 
API. We can use that builtin in libc++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74918



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


[PATCH] D76525: Expose cache line size in __builtin_get_cpu_cache_line_size

2020-03-20 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
zoecarver added reviewers: jfb, EricWF, efriedma, jyknight, echristo, __simt__.
Herald added a subscriber: dexonsmith.

This patch creates the __builtin_get_cpu_cache_line_size to wrap the cpu cache 
line size API from D74918 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76525

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/builtin-cache-line-size.cpp


Index: clang/test/SemaCXX/builtin-cache-line-size.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/builtin-cache-line-size.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang -mcpu=i368 %s
+// RUN: ./a.out
+
+#include 
+
+size_t a() {
+  return __builtin_get_cpu_cache_line_size();
+}
+
+size_t b(bool x) {
+  if (x) {
+return __builtin_get_cpu_cache_line_size();
+  }
+  return 0;
+}
+
+int main() {
+  assert(a() == 64);
+  assert(b(true) == 64);
+  assert(b(false) == 0);
+}
+
+// This is based on the value for i368.
+static_assert(__builtin_get_cpu_cache_line_size() == 64, "");
+
+struct keep_apart {
+  alignas(__builtin_get_cpu_cache_line_size()) int cat;
+  alignas(__builtin_get_cpu_cache_line_size()) int dog;
+};
+
+static_assert(sizeof(keep_apart) == __builtin_get_cpu_cache_line_size() * 2 ||
+  __builtin_get_cpu_cache_line_size() == 0, "");
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10910,6 +10910,13 @@
 return Success(Info.InConstantContext, E);
   }
 
+  case Builtin::BI__builtin_get_cpu_cache_line_size: {
+Optional cacheLineSize = 
Info.Ctx.getTargetInfo().getCPUCacheLineSize();
+if (cacheLineSize.hasValue())
+  return Success(cacheLineSize.getValue(), E);
+return Success(0, E);
+  }
+
   case Builtin::BI__builtin_ctz:
   case Builtin::BI__builtin_ctzl:
   case Builtin::BI__builtin_ctzll:
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -1480,6 +1480,7 @@
 BUILTIN(__builtin_char_memchr, "c*cC*iz", "n")
 BUILTIN(__builtin_dump_struct, "ivC*v*", "tn")
 BUILTIN(__builtin_preserve_access_index, "v.", "t")
+BUILTIN(__builtin_get_cpu_cache_line_size, "z", "nctu")
 
 // Alignment builtins (uses custom parsing to support pointers and integers)
 BUILTIN(__builtin_is_aligned, "bvC*z", "nct")


Index: clang/test/SemaCXX/builtin-cache-line-size.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/builtin-cache-line-size.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang -mcpu=i368 %s
+// RUN: ./a.out
+
+#include 
+
+size_t a() {
+  return __builtin_get_cpu_cache_line_size();
+}
+
+size_t b(bool x) {
+  if (x) {
+return __builtin_get_cpu_cache_line_size();
+  }
+  return 0;
+}
+
+int main() {
+  assert(a() == 64);
+  assert(b(true) == 64);
+  assert(b(false) == 0);
+}
+
+// This is based on the value for i368.
+static_assert(__builtin_get_cpu_cache_line_size() == 64, "");
+
+struct keep_apart {
+  alignas(__builtin_get_cpu_cache_line_size()) int cat;
+  alignas(__builtin_get_cpu_cache_line_size()) int dog;
+};
+
+static_assert(sizeof(keep_apart) == __builtin_get_cpu_cache_line_size() * 2 ||
+  __builtin_get_cpu_cache_line_size() == 0, "");
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10910,6 +10910,13 @@
 return Success(Info.InConstantContext, E);
   }
 
+  case Builtin::BI__builtin_get_cpu_cache_line_size: {
+Optional cacheLineSize = Info.Ctx.getTargetInfo().getCPUCacheLineSize();
+if (cacheLineSize.hasValue())
+  return Success(cacheLineSize.getValue(), E);
+return Success(0, E);
+  }
+
   case Builtin::BI__builtin_ctz:
   case Builtin::BI__builtin_ctzl:
   case Builtin::BI__builtin_ctzll:
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -1480,6 +1480,7 @@
 BUILTIN(__builtin_char_memchr, "c*cC*iz", "n")
 BUILTIN(__builtin_dump_struct, "ivC*v*", "tn")
 BUILTIN(__builtin_preserve_access_index, "v.", "t")
+BUILTIN(__builtin_get_cpu_cache_line_size, "z", "nctu")
 
 // Alignment builtins (uses custom parsing to support pointers and integers)
 BUILTIN(__builtin_is_aligned, "bvC*z", "nct")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76527: Don't export symbols from clang/opt/llc if plugins are disabled.

2020-03-20 Thread Eli Friedman via Phabricator via cfe-commits
efriedma created this revision.
efriedma added reviewers: MaskRay, serge-sans-paille, Meinersbur.
Herald added subscribers: cfe-commits, dexonsmith, mgorny.
Herald added a project: clang.

The only reason we export symbols from these tools is to support plugins; if we 
don't have plugins, exporting symbols just bloats the executable and makes LTO 
less effective.

See review of D75879  for the discussion that 
led to this patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76527

Files:
  clang/tools/driver/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/tools/bugpoint/CMakeLists.txt
  llvm/tools/llc/CMakeLists.txt
  llvm/tools/llvm-stress/CMakeLists.txt
  llvm/tools/opt/CMakeLists.txt
  llvm/unittests/Passes/CMakeLists.txt


Index: llvm/unittests/Passes/CMakeLists.txt
===
--- llvm/unittests/Passes/CMakeLists.txt
+++ llvm/unittests/Passes/CMakeLists.txt
@@ -16,7 +16,7 @@
   add_llvm_unittest(PluginsTests
 PluginsTest.cpp
 )
-  export_executable_symbols(PluginsTests)
+  export_executable_symbols_for_plugins(PluginsTests)
   target_link_libraries(PluginsTests PRIVATE LLVMTestingSupport)
 
   set(LLVM_LINK_COMPONENTS)
Index: llvm/tools/opt/CMakeLists.txt
===
--- llvm/tools/opt/CMakeLists.txt
+++ llvm/tools/opt/CMakeLists.txt
@@ -39,7 +39,7 @@
   intrinsics_gen
   SUPPORT_PLUGINS
   )
-export_executable_symbols(opt)
+export_executable_symbols_for_plugins(opt)
 
 if(LLVM_BUILD_EXAMPLES)
 target_link_libraries(opt PRIVATE ExampleIRTransforms)
Index: llvm/tools/llvm-stress/CMakeLists.txt
===
--- llvm/tools/llvm-stress/CMakeLists.txt
+++ llvm/tools/llvm-stress/CMakeLists.txt
@@ -10,4 +10,3 @@
   DEPENDS
   intrinsics_gen
   )
-export_executable_symbols(llvm-stress)
Index: llvm/tools/llc/CMakeLists.txt
===
--- llvm/tools/llc/CMakeLists.txt
+++ llvm/tools/llc/CMakeLists.txt
@@ -27,4 +27,4 @@
   SUPPORT_PLUGINS
   )
 
-export_executable_symbols(llc)
+export_executable_symbols_for_plugins(llc)
Index: llvm/tools/bugpoint/CMakeLists.txt
===
--- llvm/tools/bugpoint/CMakeLists.txt
+++ llvm/tools/bugpoint/CMakeLists.txt
@@ -38,4 +38,4 @@
   intrinsics_gen
   SUPPORT_PLUGINS
   )
-export_executable_symbols(bugpoint)
+export_executable_symbols_for_plugins(bugpoint)
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1029,6 +1029,13 @@
   endif()
 endfunction()
 
+# Export symbols if LLVM plugins are enabled.
+function(export_executable_symbols_for_plugins target)
+  if(LLVM_ENABLE_PLUGINS)
+export_executable_symbols(${target})
+  endif()
+endfunction()
+
 if(NOT LLVM_TOOLCHAIN_TOOLS)
   set (LLVM_TOOLCHAIN_TOOLS
 llvm-ar
Index: clang/tools/driver/CMakeLists.txt
===
--- clang/tools/driver/CMakeLists.txt
+++ clang/tools/driver/CMakeLists.txt
@@ -57,7 +57,7 @@
 
 # Support plugins.
 if(CLANG_PLUGIN_SUPPORT)
-  export_executable_symbols(clang)
+  export_executable_symbols_for_plugins(clang)
 endif()
 
 add_dependencies(clang clang-resource-headers)


Index: llvm/unittests/Passes/CMakeLists.txt
===
--- llvm/unittests/Passes/CMakeLists.txt
+++ llvm/unittests/Passes/CMakeLists.txt
@@ -16,7 +16,7 @@
   add_llvm_unittest(PluginsTests
 PluginsTest.cpp
 )
-  export_executable_symbols(PluginsTests)
+  export_executable_symbols_for_plugins(PluginsTests)
   target_link_libraries(PluginsTests PRIVATE LLVMTestingSupport)
 
   set(LLVM_LINK_COMPONENTS)
Index: llvm/tools/opt/CMakeLists.txt
===
--- llvm/tools/opt/CMakeLists.txt
+++ llvm/tools/opt/CMakeLists.txt
@@ -39,7 +39,7 @@
   intrinsics_gen
   SUPPORT_PLUGINS
   )
-export_executable_symbols(opt)
+export_executable_symbols_for_plugins(opt)
 
 if(LLVM_BUILD_EXAMPLES)
 target_link_libraries(opt PRIVATE ExampleIRTransforms)
Index: llvm/tools/llvm-stress/CMakeLists.txt
===
--- llvm/tools/llvm-stress/CMakeLists.txt
+++ llvm/tools/llvm-stress/CMakeLists.txt
@@ -10,4 +10,3 @@
   DEPENDS
   intrinsics_gen
   )
-export_executable_symbols(llvm-stress)
Index: llvm/tools/llc/CMakeLists.txt
===
--- llvm/tools/llc/CMakeLists.txt
+++ llvm/tools/llc/CMakeLists.txt
@@ -27,4 +27,4 @@
   SUPPORT_PLUGINS
   )
 
-export_executable_symbols(llc)
+export_executable_symbols_for_plugins(llc)
Index: llvm/tools/bugpoint/CMakeLists.txt

[clang] 079c6dd - Correctly initialize the DW_AT_comp_dir attribute of Clang module skeleton CUs

2020-03-20 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2020-03-20T14:18:14-07:00
New Revision: 079c6ddaf5344eb501652c2a874e3e4e8c466c2b

URL: 
https://github.com/llvm/llvm-project/commit/079c6ddaf5344eb501652c2a874e3e4e8c466c2b
DIFF: 
https://github.com/llvm/llvm-project/commit/079c6ddaf5344eb501652c2a874e3e4e8c466c2b.diff

LOG: Correctly initialize the DW_AT_comp_dir attribute of Clang module skeleton 
CUs

Before this patch a Clang module skeleton CU would have a
DW_AT_comp_dir pointing to the directory of the module map file, and
this information was not used by anyone. Even worse, LLDB actually
resolves relative DWO paths by appending it to DW_AT_comp_dir. This
patch sets it to the same directory that is used as the main CU's
compilation directory, which would make the LLDB code work.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/Modules/debug-info-moduleimport.m
clang/test/PCH/debug-info-pch-path.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index eeb1927177c5..6d0960687a95 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2492,12 +2492,16 @@ llvm::DIModule 
*CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
 ? (uint64_t)Mod.getSignature()[1] << 32 | Mod.getSignature()[0]
 : ~1ULL;
 llvm::DIBuilder DIB(CGM.getModule());
+SmallString<0> PCM;
+if (!llvm::sys::path::is_absolute(PCM))
+  PCM = Mod.getPath();
+llvm::sys::path::append(PCM, Mod.getASTFile());
+StringRef CompDir = getCurrentDirname();
 DIB.createCompileUnit(TheCU->getSourceLanguage(),
   // TODO: Support "Source" from external AST 
providers?
-  DIB.createFile(Mod.getModuleName(), Mod.getPath()),
-  TheCU->getProducer(), true, StringRef(), 0,
-  Mod.getASTFile(), llvm::DICompileUnit::FullDebug,
-  Signature);
+  DIB.createFile(Mod.getModuleName(), CompDir),
+  TheCU->getProducer(), true, StringRef(), 0, PCM,
+  llvm::DICompileUnit::FullDebug, Signature);
 DIB.finalize();
   }
 

diff  --git a/clang/test/Modules/debug-info-moduleimport.m 
b/clang/test/Modules/debug-info-moduleimport.m
index f07c6fce784d..837459b0786c 100644
--- a/clang/test/Modules/debug-info-moduleimport.m
+++ b/clang/test/Modules/debug-info-moduleimport.m
@@ -28,5 +28,7 @@
 // RUN:   -fmodule-format=obj -dwarf-ext-refs \
 // RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
 // RUN: | FileCheck %s --check-prefix=SKEL-CHECK
-// SKEL-CHECK: distinct !DICompileUnit
-// SKEL-CHECK: distinct !DICompileUnit{{.*}}dwoId
+// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
+// SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
+// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: 
![[DWOFILE:[0-9]+]]{{.*}}dwoId
+// SKEL-CHECK: ![[DWOFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR]]"

diff  --git a/clang/test/PCH/debug-info-pch-path.c 
b/clang/test/PCH/debug-info-pch-path.c
index dcf7ed41f50e..32d1cbd44bdf 100644
--- a/clang/test/PCH/debug-info-pch-path.c
+++ b/clang/test/PCH/debug-info-pch-path.c
@@ -23,7 +23,7 @@
 // CHECK-REL-NODIR: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-REL-NODIR: !DICompileUnit(
 // CHECK-REL-NODIR-SAME:   file: ![[PCH:[0-9]+]]
-// CHECK-REL-NODIR-SAME:   splitDebugFilename: "prefix.pch"
+// CHECK-REL-NODIR-SAME:   splitDebugFilename: 
"{{.*}}PCH{{.*}}prefix.pch"
 // CHECK-REL-NODIR: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]
 
 // -
@@ -47,8 +47,8 @@
 // CHECK-REL: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-REL: !DICompileUnit(
 // CHECK-REL-SAME:   file: ![[PCH:[0-9]+]]
-// CHECK-REL-SAME:   splitDebugFilename: "prefix.pch"
-// CHECK-REL: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]{{.*}}pchdir"
+// CHECK-REL-SAME:   splitDebugFilename: 
"[[DIR]]{{.*}}pchdir{{.*}}prefix.pch"
+// CHECK-REL: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]"
 
 // -
 // Absolute PCH.
@@ -70,5 +70,5 @@
 // CHECK-ABS: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-ABS: !DICompileUnit(
 // CHECK-ABS-SAME:   file: ![[PCH:[0-9]+]]
-// CHECK-ABS-SAME:   splitDebugFilename: "prefix.pch"
+// CHECK-ABS-SAME:   splitDebugFilename: "[[DIR]]{{.*}}prefix.pch"
 // CHECK-ABS: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]



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


[clang] 97f490d - Don't set the isOptimized flag in module skeleton DICompileUnits.

2020-03-20 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2020-03-20T14:18:15-07:00
New Revision: 97f490d87b226b1deade74ec93b4378fb28d26cc

URL: 
https://github.com/llvm/llvm-project/commit/97f490d87b226b1deade74ec93b4378fb28d26cc
DIFF: 
https://github.com/llvm/llvm-project/commit/97f490d87b226b1deade74ec93b4378fb28d26cc.diff

LOG: Don't set the isOptimized flag in module skeleton DICompileUnits.

It's not used for anything.

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/Modules/ExtDebugInfo.m

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 6d0960687a95..9645dd1deb42 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2500,7 +2500,7 @@ llvm::DIModule 
*CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
 DIB.createCompileUnit(TheCU->getSourceLanguage(),
   // TODO: Support "Source" from external AST 
providers?
   DIB.createFile(Mod.getModuleName(), CompDir),
-  TheCU->getProducer(), true, StringRef(), 0, PCM,
+  TheCU->getProducer(), false, StringRef(), 0, PCM,
   llvm::DICompileUnit::FullDebug, Signature);
 DIB.finalize();
   }

diff  --git a/clang/test/Modules/ExtDebugInfo.m 
b/clang/test/Modules/ExtDebugInfo.m
index 41247b00a49f..380bc4c9bb98 100644
--- a/clang/test/Modules/ExtDebugInfo.m
+++ b/clang/test/Modules/ExtDebugInfo.m
@@ -6,13 +6,16 @@
 // RUN: -fmodule-format=obj -fimplicit-module-maps -DMODULES \
 // RUN: -fmodules-cache-path=%t %s -I %S/Inputs -I %t -emit-llvm -o 
%t-mod.ll
 // RUN: cat %t-mod.ll |  FileCheck %s
+// RUN: cat %t-mod.ll |  FileCheck %s --check-prefix=DWOID
 
 // PCH:
 // RUN: %clang_cc1 -x objective-c -fmodule-format=obj -emit-pch -I%S/Inputs \
 // RUN: -o %t.pch %S/Inputs/DebugObjC.h
-// RUN: %clang_cc1 -x objective-c -debug-info-kind=limited -dwarf-ext-refs 
-fmodule-format=obj \
+// RUN: %clang_cc1 -x objective-c -debug-info-kind=limited -dwarf-ext-refs \
+// RUN: -fmodule-format=obj \
 // RUN: -include-pch %t.pch %s -emit-llvm -o %t-pch.ll %s
 // RUN: cat %t-pch.ll |  FileCheck %s
+// RUN: cat %t-pch.ll |  FileCheck %s --check-prefix=DWOID
 
 #ifdef MODULES
 @import DebugObjC;
@@ -34,6 +37,8 @@ int foo(ObjCClass *c) {
   return [c property];
 }
 
+// DWOID: !DICompileUnit(language: DW_LANG_ObjC,{{.*}}isOptimized: 
false,{{.*}}dwoId:
+
 // CHECK: ![[MOD:.*]] = !DIModule(scope: null, name: "DebugObjC
 
 // CHECK: !DIGlobalVariable(name: "GlobalUnion",



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


[clang] dc4259d - [c++20] Further extend the set of comparisons broken by C++20 that we

2020-03-20 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-03-20T14:22:48-07:00
New Revision: dc4259d5a38409e65b60266a7df0f03c3b91a151

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

LOG: [c++20] Further extend the set of comparisons broken by C++20 that we
accept as an extension.

This attempts to accept the same cases a GCC, plus cases where a
comparison is rewritten to an operator== with an integral but non-bool
return type; this is sufficient to avoid most problems with various
major open-source projects (such as ICU) and appears to fix all but one
of the comparison-related C++20 build breaks in LLVM.

This approach is being pursued for standardization.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Overload.h
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p9-2a.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 90845ecf5468..ca9333d50e42 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4214,11 +4214,16 @@ def err_ovl_ambiguous_oper_binary : Error<
   "use of overloaded operator '%0' is ambiguous (with operand types %1 and 
%2)">;
 def ext_ovl_ambiguous_oper_binary_reversed : ExtWarn<
   "ISO C++20 considers use of overloaded operator '%0' (with operand types %1 "
-  "and %2) to be ambiguous despite there being a unique best viable function">,
+  "and %2) to be ambiguous despite there being a unique best viable function"
+  "%select{ with non-reversed arguments|}3">,
   InGroup>, SFINAEFailure;
-def note_ovl_ambiguous_oper_binary_reversed_candidate : Note<
+def note_ovl_ambiguous_oper_binary_reversed_self : Note<
   "ambiguity is between a regular call to this operator and a call with the "
   "argument order reversed">;
+def note_ovl_ambiguous_oper_binary_selected_candidate : Note<
+  "candidate function with non-reversed arguments">;
+def note_ovl_ambiguous_oper_binary_reversed_candidate : Note<
+  "ambiguous candidate function with reversed arguments">;
 def err_ovl_no_viable_oper : Error<"no viable overloaded '%0'">;
 def note_assign_lhs_incomplete : Note<"type %0 is incomplete">;
 def err_ovl_deleted_oper : Error<
@@ -4232,6 +4237,10 @@ def err_ovl_deleted_comparison : Error<
 def err_ovl_rewrite_equalequal_not_bool : Error<
   "return type %0 of selected 'operator==' function for rewritten "
   "'%1' comparison is not 'bool'">;
+def ext_ovl_rewrite_equalequal_not_bool : ExtWarn<
+  "ISO C++20 requires return type of selected 'operator==' function for "
+  "rewritten '%1' comparison to be 'bool', not %0">,
+  InGroup>, SFINAEFailure;
 def err_ovl_no_viable_subscript :
 Error<"no viable overloaded operator[] for type %0">;
 def err_ovl_no_oper :

diff  --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 6944b0b5756e..5023525aa41b 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -983,6 +983,14 @@ class Sema;
 return CRK;
   }
 
+  /// Determines whether this operator could be implemented by a function
+  /// with reversed parameter order.
+  bool isReversible() {
+return AllowRewrittenCandidates && OriginalOperator &&
+   (getRewrittenOverloadedOperator(OriginalOperator) != OO_None ||
+shouldAddReversed(OriginalOperator));
+  }
+
   /// Determine whether we should consider looking for and adding reversed
   /// candidates for operator Op.
   bool shouldAddReversed(OverloadedOperatorKind Op);

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index dd7dbf87b947..b048c5a8d8cf 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -9420,6 +9420,49 @@ static bool isBetterMultiversionCandidate(const 
OverloadCandidate &Cand1,
   llvm_unreachable("No way to get here unless both had cpu_dispatch");
 }
 
+/// Compute the type of the implicit object parameter for the given function,
+/// if any. Returns None if there is no implicit object parameter, and a null
+/// QualType if there is a 'matches anything' implicit object parameter.
+static Optional getImplicitObjectParamType(ASTContext &Context,
+ const FunctionDecl *F) {
+  if (!isa(F) || isa(F))
+return llvm::None;
+
+  auto *M = cast(F);
+  // Static member functions' object parameters match all types.
+  if (M->isStatic())
+return QualType();
+
+  QualType T = M->getThisObjectType();
+  if (M->getRefQualifier() == RQ_RValue)
+  

[PATCH] D74918: Add method to TargetInfo to get CPU cache line size

2020-03-20 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver marked 2 inline comments as done.
zoecarver added a comment.

I've made the suggested changes. Is there a consensus that this should be moved 
to LLVM? I think it's fairly clang-specific (given the use case). We can also 
always move it to LLVM if the need arises in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74918



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


[PATCH] D74918: Add method to TargetInfo to get CPU cache line size

2020-03-20 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver updated this revision to Diff 251758.
zoecarver added a comment.

Fix based on review:

- update comments
- return 64 for Core2


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74918

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/X86.cpp


Index: clang/lib/Basic/Targets/X86.cpp
===
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targets/X86.cpp
@@ -1745,7 +1745,7 @@
 // | Sandy Bridge   |  64 | 
https://en.wikipedia.org/wiki/Sandy_Bridge and 
https://www.7-cpu.com/cpu/SandyBridge.html  
  |
 // | Ivy Bridge |  64 | 
https://blog.stuffedcow.net/2013/01/ivb-cache-replacement/ and 
https://www.7-cpu.com/cpu/IvyBridge.html
  |
 // | Haswell|  64 | 
https://www.7-cpu.com/cpu/Haswell.html  
 |
-// | Bradwell   |  64 | 
https://www.7-cpu.com/cpu/Broadwell.html
 |
+// | Boadwell   |  64 | 
https://www.7-cpu.com/cpu/Broadwell.html
 |
 // | Skylake (including skylake-avx512) |  64 | 
https://www.nas.nasa.gov/hecc/support/kb/skylake-processors_550.html "Cache 
Hierarchy"  
 |
 // | Cascade Lake   |  64 | 
https://www.nas.nasa.gov/hecc/support/kb/cascade-lake-processors_579.html 
"Cache Hierarchy"   
   |
 // | Skylake|  64 | 
https://en.wikichip.org/wiki/intel/microarchitectures/kaby_lake "Memory 
Hierarchy"  
 |
@@ -1833,11 +1833,11 @@
 case CK_x86_64:
 case CK_Yonah:
 case CK_Penryn:
+case CK_Core2:
   return 64;
 
 // The following currently have unknown cache line sizes (but they are 
probably all 64):
 // Core
-case CK_Core2:
 case CK_Generic:
   return None;
   }
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -1207,7 +1207,7 @@
   }
 
   // Get the cache line size of a given cpu. This method switches over
-  // the given cpu and returns `0` if the CPU is not found.
+  // the given cpu and returns "None" if the CPU is not found.
   virtual Optional getCPUCacheLineSize() const { return None; }
 
   // Returns maximal number of args passed in registers.


Index: clang/lib/Basic/Targets/X86.cpp
===
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targets/X86.cpp
@@ -1745,7 +1745,7 @@
 // | Sandy Bridge   |  64 | https://en.wikipedia.org/wiki/Sandy_Bridge and https://www.7-cpu.com/cpu/SandyBridge.html|
 // | Ivy Bridge |  64 | https://blog.stuffedcow.net/2013/01/ivb-cache-replacement/ and https://www.7-cpu.com/cpu/IvyBridge.html  |
 // | Haswell|  64 | https://www.7-cpu.com/cpu/Haswell.html   |
-// | Bradwell   |  64 | https://www.7-cpu.com/cpu/Broadwell.html |
+// | Boadwell   |  64 | https://www.7-cpu.com/cpu/Broadwell.html |
 // | Skylake (including skylake-avx512) |  64 | https://www.nas.nasa.gov/hecc/support/kb/skylake-processors_550.html "Cache Hierarchy"   |
 // | Cascade Lake   |  64 | https://www.nas.nasa.gov/hecc/support/kb/cascade-lake-processors_579.html "Cache Hierarchy"

[PATCH] D76438: ConstantExpr cached APValues if present for constant evaluation

2020-03-20 Thread Wyatt Childers via Phabricator via cfe-commits
wchilders marked 2 inline comments as done.
wchilders added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:7325-7329
+  // Override to perform additional checks to ensure the cached APValue
+  // is actually an LValue.
+  bool VisitConstantExpr(const ConstantExpr *E) {
+assert(!E->hasAPValueResult() || E->getAPValueResult().isLValue());
+return ExprEvaluatorBaseTy::VisitConstantExpr(E);

rsmith wrote:
> I think this override is now fully redundant and can be removed: the 
> `isLValue()` assert is reached anyway when `DerivedSuccess` calls 
> `LValueExprEvaluatorBase::Success` which calls `LValue::setFrom`.
Good catch, updated the patch to drop this. :)


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

https://reviews.llvm.org/D76438



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


[PATCH] D76438: ConstantExpr cached APValues if present for constant evaluation

2020-03-20 Thread Wyatt Childers via Phabricator via cfe-commits
wchilders added a comment.

I should note, I don't have commit access, so I'm unable to commit this myself. 
Attribution would be `Wyatt Childers `


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

https://reviews.llvm.org/D76438



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


[PATCH] D76528: [clang codegen] Clean up handling of vectors with trivial-auto-var-init.

2020-03-20 Thread Eli Friedman via Phabricator via cfe-commits
efriedma created this revision.
efriedma added reviewers: glider, jfb.
Herald added a subscriber: dexonsmith.
Herald added a project: clang.

The code was pretending to be doing something useful with vectors, but really 
it was doing nothing: the element type of a vector is always a scalar type, so 
constWithPadding would always just return the input constant.

Split off from D75661  so it can be reviewed 
separately.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76528

Files:
  clang/lib/CodeGen/CGDecl.cpp


Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1050,13 +1050,13 @@
   llvm::Type *OrigTy = constant->getType();
   if (const auto STy = dyn_cast(OrigTy))
 return constStructWithPadding(CGM, isPattern, STy, constant);
-  if (auto *STy = dyn_cast(OrigTy)) {
+  if (auto *ArrayTy = dyn_cast(OrigTy)) {
 llvm::SmallVector Values;
-unsigned Size = STy->getNumElements();
+uint64_t Size = ArrayTy->getNumElements();
 if (!Size)
   return constant;
-llvm::Type *ElemTy = STy->getElementType();
-bool ZeroInitializer = constant->isZeroValue();
+llvm::Type *ElemTy = ArrayTy->getElementType();
+bool ZeroInitializer = constant->isNullValue();
 llvm::Constant *OpValue, *PaddedOp;
 if (ZeroInitializer) {
   OpValue = llvm::Constant::getNullValue(ElemTy);
@@ -1072,13 +1072,10 @@
 auto *NewElemTy = Values[0]->getType();
 if (NewElemTy == ElemTy)
   return constant;
-if (OrigTy->isArrayTy()) {
-  auto *ArrayTy = llvm::ArrayType::get(NewElemTy, Size);
-  return llvm::ConstantArray::get(ArrayTy, Values);
-} else {
-  return llvm::ConstantVector::get(Values);
-}
+auto *NewArrayTy = llvm::ArrayType::get(NewElemTy, Size);
+return llvm::ConstantArray::get(NewArrayTy, Values);
   }
+  // FIXME: Do we need to handle tail padding in vectors?
   return constant;
 }
 


Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1050,13 +1050,13 @@
   llvm::Type *OrigTy = constant->getType();
   if (const auto STy = dyn_cast(OrigTy))
 return constStructWithPadding(CGM, isPattern, STy, constant);
-  if (auto *STy = dyn_cast(OrigTy)) {
+  if (auto *ArrayTy = dyn_cast(OrigTy)) {
 llvm::SmallVector Values;
-unsigned Size = STy->getNumElements();
+uint64_t Size = ArrayTy->getNumElements();
 if (!Size)
   return constant;
-llvm::Type *ElemTy = STy->getElementType();
-bool ZeroInitializer = constant->isZeroValue();
+llvm::Type *ElemTy = ArrayTy->getElementType();
+bool ZeroInitializer = constant->isNullValue();
 llvm::Constant *OpValue, *PaddedOp;
 if (ZeroInitializer) {
   OpValue = llvm::Constant::getNullValue(ElemTy);
@@ -1072,13 +1072,10 @@
 auto *NewElemTy = Values[0]->getType();
 if (NewElemTy == ElemTy)
   return constant;
-if (OrigTy->isArrayTy()) {
-  auto *ArrayTy = llvm::ArrayType::get(NewElemTy, Size);
-  return llvm::ConstantArray::get(ArrayTy, Values);
-} else {
-  return llvm::ConstantVector::get(Values);
-}
+auto *NewArrayTy = llvm::ArrayType::get(NewElemTy, Size);
+return llvm::ConstantArray::get(NewArrayTy, Values);
   }
+  // FIXME: Do we need to handle tail padding in vectors?
   return constant;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76438: ConstantExpr cached APValues if present for constant evaluation

2020-03-20 Thread Wyatt Childers via Phabricator via cfe-commits
wchilders updated this revision to Diff 251763.
wchilders marked an inline comment as done.
wchilders added a comment.

Dropped the override for constexpr evaluator, LValue evaluation base class


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

https://reviews.llvm.org/D76438

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15167,6 +15167,12 @@
 return ExprError();
   }
 
+  ExprResult RValueExpr = DefaultLvalueConversion(E);
+  if (RValueExpr.isInvalid())
+return ExprError();
+
+  E = RValueExpr.get();
+
   // Circumvent ICE checking in C++11 to avoid evaluating the expression twice
   // in the non-ICE case.
   if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -6751,8 +6751,13 @@
 return Error(E);
   }
 
-  bool VisitConstantExpr(const ConstantExpr *E)
-{ return StmtVisitorTy::Visit(E->getSubExpr()); }
+  bool VisitConstantExpr(const ConstantExpr *E) {
+if (E->hasAPValueResult())
+  return DerivedSuccess(E->getAPValueResult(), E);
+
+return StmtVisitorTy::Visit(E->getSubExpr());
+  }
+
   bool VisitParenExpr(const ParenExpr *E)
 { return StmtVisitorTy::Visit(E->getSubExpr()); }
   bool VisitUnaryExtension(const UnaryOperator *E)
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -356,6 +356,8 @@
 }
 
 APValue ConstantExpr::getAPValueResult() const {
+  assert(hasAPValueResult());
+
   switch (ConstantExprBits.ResultKind) {
   case ConstantExpr::RSK_APValue:
 return APValueResult();
@@ -2870,9 +2872,6 @@
   return CE->getChosenSubExpr();
   }
 
-  else if (auto *CE = dyn_cast(E))
-return CE->getSubExpr();
-
   return E;
 }
 
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -1063,6 +1063,9 @@
   bool isImmediateInvocation() const {
 return ConstantExprBits.IsImmediateInvocation;
   }
+  bool hasAPValueResult() const {
+return ConstantExprBits.APValueKind != APValue::None;
+  }
   APValue getAPValueResult() const;
   APValue &getResultAsAPValue() const { return APValueResult(); }
   llvm::APSInt getResultAsAPSInt() const;


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15167,6 +15167,12 @@
 return ExprError();
   }
 
+  ExprResult RValueExpr = DefaultLvalueConversion(E);
+  if (RValueExpr.isInvalid())
+return ExprError();
+
+  E = RValueExpr.get();
+
   // Circumvent ICE checking in C++11 to avoid evaluating the expression twice
   // in the non-ICE case.
   if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -6751,8 +6751,13 @@
 return Error(E);
   }
 
-  bool VisitConstantExpr(const ConstantExpr *E)
-{ return StmtVisitorTy::Visit(E->getSubExpr()); }
+  bool VisitConstantExpr(const ConstantExpr *E) {
+if (E->hasAPValueResult())
+  return DerivedSuccess(E->getAPValueResult(), E);
+
+return StmtVisitorTy::Visit(E->getSubExpr());
+  }
+
   bool VisitParenExpr(const ParenExpr *E)
 { return StmtVisitorTy::Visit(E->getSubExpr()); }
   bool VisitUnaryExtension(const UnaryOperator *E)
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -356,6 +356,8 @@
 }
 
 APValue ConstantExpr::getAPValueResult() const {
+  assert(hasAPValueResult());
+
   switch (ConstantExprBits.ResultKind) {
   case ConstantExpr::RSK_APValue:
 return APValueResult();
@@ -2870,9 +2872,6 @@
   return CE->getChosenSubExpr();
   }
 
-  else if (auto *CE = dyn_cast(E))
-return CE->getSubExpr();
-
   return E;
 }
 
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -1063,6 +1063,9 @@
   bool isImmediateInvocation() const {
 return ConstantExprBits.IsImmediateInvocation;
   }
+  bool hasAPValueResult() const {
+return ConstantExprBits.APValueKind != APValue::None;
+  }
   APValue getAPValueResult() const;
   APValue &getResultAsAPValue() const { return APValueResult(); }
   llvm::APSInt getResultAsAPSInt() const;

[PATCH] D76377: Correctly initialize the DW_AT_comp_dir attribute of Clang module skeleton CUs

2020-03-20 Thread Adrian Prantl via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG079c6ddaf534: Correctly initialize the DW_AT_comp_dir 
attribute of Clang module skeleton CUs (authored by aprantl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D76377?vs=251142&id=251771#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76377

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/Modules/debug-info-moduleimport.m
  clang/test/PCH/debug-info-pch-path.c


Index: clang/test/PCH/debug-info-pch-path.c
===
--- clang/test/PCH/debug-info-pch-path.c
+++ clang/test/PCH/debug-info-pch-path.c
@@ -23,7 +23,7 @@
 // CHECK-REL-NODIR: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-REL-NODIR: !DICompileUnit(
 // CHECK-REL-NODIR-SAME:   file: ![[PCH:[0-9]+]]
-// CHECK-REL-NODIR-SAME:   splitDebugFilename: "prefix.pch"
+// CHECK-REL-NODIR-SAME:   splitDebugFilename: 
"{{.*}}PCH{{.*}}prefix.pch"
 // CHECK-REL-NODIR: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]
 
 // -
@@ -47,8 +47,8 @@
 // CHECK-REL: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-REL: !DICompileUnit(
 // CHECK-REL-SAME:   file: ![[PCH:[0-9]+]]
-// CHECK-REL-SAME:   splitDebugFilename: "prefix.pch"
-// CHECK-REL: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]{{.*}}pchdir"
+// CHECK-REL-SAME:   splitDebugFilename: 
"[[DIR]]{{.*}}pchdir{{.*}}prefix.pch"
+// CHECK-REL: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]"
 
 // -
 // Absolute PCH.
@@ -70,5 +70,5 @@
 // CHECK-ABS: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-ABS: !DICompileUnit(
 // CHECK-ABS-SAME:   file: ![[PCH:[0-9]+]]
-// CHECK-ABS-SAME:   splitDebugFilename: "prefix.pch"
+// CHECK-ABS-SAME:   splitDebugFilename: "[[DIR]]{{.*}}prefix.pch"
 // CHECK-ABS: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]
Index: clang/test/Modules/debug-info-moduleimport.m
===
--- clang/test/Modules/debug-info-moduleimport.m
+++ clang/test/Modules/debug-info-moduleimport.m
@@ -28,5 +28,7 @@
 // RUN:   -fmodule-format=obj -dwarf-ext-refs \
 // RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
 // RUN: | FileCheck %s --check-prefix=SKEL-CHECK
-// SKEL-CHECK: distinct !DICompileUnit
-// SKEL-CHECK: distinct !DICompileUnit{{.*}}dwoId
+// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
+// SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
+// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: 
![[DWOFILE:[0-9]+]]{{.*}}dwoId
+// SKEL-CHECK: ![[DWOFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR]]"
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2492,12 +2492,16 @@
 ? (uint64_t)Mod.getSignature()[1] << 32 | Mod.getSignature()[0]
 : ~1ULL;
 llvm::DIBuilder DIB(CGM.getModule());
+SmallString<0> PCM;
+if (!llvm::sys::path::is_absolute(PCM))
+  PCM = Mod.getPath();
+llvm::sys::path::append(PCM, Mod.getASTFile());
+StringRef CompDir = getCurrentDirname();
 DIB.createCompileUnit(TheCU->getSourceLanguage(),
   // TODO: Support "Source" from external AST 
providers?
-  DIB.createFile(Mod.getModuleName(), Mod.getPath()),
-  TheCU->getProducer(), true, StringRef(), 0,
-  Mod.getASTFile(), llvm::DICompileUnit::FullDebug,
-  Signature);
+  DIB.createFile(Mod.getModuleName(), CompDir),
+  TheCU->getProducer(), true, StringRef(), 0, PCM,
+  llvm::DICompileUnit::FullDebug, Signature);
 DIB.finalize();
   }
 


Index: clang/test/PCH/debug-info-pch-path.c
===
--- clang/test/PCH/debug-info-pch-path.c
+++ clang/test/PCH/debug-info-pch-path.c
@@ -23,7 +23,7 @@
 // CHECK-REL-NODIR: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-REL-NODIR: !DICompileUnit(
 // CHECK-REL-NODIR-SAME:   file: ![[PCH:[0-9]+]]
-// CHECK-REL-NODIR-SAME:   splitDebugFilename: "prefix.pch"
+// CHECK-REL-NODIR-SAME:   splitDebugFilename: "{{.*}}PCH{{.*}}prefix.pch"
 // CHECK-REL-NODIR: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]
 
 // -
@@ -47,8 +47,8 @@
 // CHECK-REL: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-REL: !DICompileUnit(
 // CHECK-REL-SAME:   file: ![[PCH:[0-9

[clang] fc8a009 - Clean up and simplify after collision of c48442c and 19fccc5, which

2020-03-20 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-03-20T14:53:09-07:00
New Revision: fc8a009bf39d74ce0ee3f586e0b4056035db30cb

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

LOG: Clean up and simplify after collision of c48442c and 19fccc5, which
fixed the same bug in two similar ways.

Added: 


Modified: 
clang/lib/Parse/ParseDecl.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index ba4f5d86612a..e3c784c1b61c 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3251,10 +3251,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
   if (!TypeRep) {
 if (TryAnnotateTypeConstraint())
   goto DoneWithDeclSpec;
-if (isTypeConstraintAnnotation())
-  continue;
-if (NextToken().is(tok::annot_template_id))
-  // Might have been annotated by TryAnnotateTypeConstraint.
+if (Tok.isNot(tok::annot_cxxscope) ||
+NextToken().isNot(tok::identifier))
   continue;
 // Eat the scope spec so the identifier is current.
 ConsumeAnnotationToken();
@@ -3409,9 +3407,6 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
   goto DoneWithDeclSpec;
 if (Tok.isNot(tok::identifier))
   continue;
-if (Tok.is(tok::annot_template_id))
-  // Might have been annotated by TryAnnotateTypeConstraint.
-  continue;
 ParsedAttributesWithRange Attrs(AttrFactory);
 if (ParseImplicitInt(DS, nullptr, TemplateInfo, AS, DSContext, Attrs)) 
{
   if (!Attrs.empty()) {



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


[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-20 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 251777.
hliao added a comment.

Minor revising following reviewer's comment. Work on Sema checks and upload 
another review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/Type.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGCUDARuntime.h
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGenCUDA/surface.cu
  clang/test/CodeGenCUDA/texture.cu
  clang/test/SemaCUDA/attr-declspec.cu
  clang/test/SemaCUDA/attributes-on-non-cuda.cu
  llvm/include/llvm/IR/Operator.h

Index: llvm/include/llvm/IR/Operator.h
===
--- llvm/include/llvm/IR/Operator.h
+++ llvm/include/llvm/IR/Operator.h
@@ -599,6 +599,25 @@
   }
 };
 
+class AddrSpaceCastOperator
+: public ConcreteOperator {
+  friend class AddrSpaceCastInst;
+  friend class ConstantExpr;
+
+public:
+  Value *getPointerOperand() { return getOperand(0); }
+
+  const Value *getPointerOperand() const { return getOperand(0); }
+
+  unsigned getSrcAddressSpace() const {
+return getPointerOperand()->getType()->getPointerAddressSpace();
+  }
+
+  unsigned getDestAddressSpace() const {
+return getType()->getPointerAddressSpace();
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_OPERATOR_H
Index: clang/test/SemaCUDA/attributes-on-non-cuda.cu
===
--- clang/test/SemaCUDA/attributes-on-non-cuda.cu
+++ clang/test/SemaCUDA/attributes-on-non-cuda.cu
@@ -7,16 +7,21 @@
 // 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@+17 {{'device' attribute ignored}}
+// expected-warning@+17 {{'global' attribute ignored}}
+// expected-warning@+17 {{'constant' attribute ignored}}
+// expected-warning@+17 {{'shared' attribute ignored}}
+// expected-warning@+17 {{'host' attribute ignored}}
+// expected-warning@+23 {{'device_builtin_surface_type' attribute ignored}}
+// expected-warning@+23 {{'device_builtin_texture_type' attribute ignored}}
+// expected-warning@+23 {{'device_builtin_surface_type' attribute ignored}}
+// expected-warning@+23 {{'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.
 #else
-// expected-no-diagnostics
+// expected-warning@+15 {{'device_builtin_surface_type' attribute only applies to types}}
+// expected-warning@+15 {{'device_builtin_texture_type' attribute only applies to types}}
 #endif
 
 __attribute__((device)) void f_device();
@@ -32,3 +37,5 @@
 __attribute__((nv_weak)) void f_nv_weak();
 __attribute__((device_builtin_surface_type)) unsigned long long surface_var;
 __attribute__((device_builtin_texture_type)) unsigned long long texture_var;
+struct __attribute__((device_builtin_surface_type)) surf_ref {};
+struct __attribute__((device_builtin_texture_type)) tex_ref {};
Index: clang/test/SemaCUDA/attr-declspec.cu
===
--- clang/test/SemaCUDA/attr-declspec.cu
+++ clang/test/SemaCUDA/attr-declspec.cu
@@ -6,16 +6,21 @@
 // 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@+17 {{'__device__' attribute ignored}}
+// expected-warning@+17 {{'__global__' attribute ignored}}
+// expected-warning@+17 {{'__constant__' attribute ignored}}
+// expected-warning@+17 {{'__shared__' attribute ignored}}
+// expected-warning@+17 {{'__host__' attribute ignored}}
+// expected-warning@+22 {{'__device_builtin_surface_type__' attribute ignored}}
+// expected-warning@+22 {{'__device_builtin_texture_type__' attribute ignored}}
+// expected-warning@+22 {{'__device_builtin_surface_type__' attribute ignored}}
+// expected-warning@+22 {{'__device_builtin_texture_type__' attribute ignored}}
 //
 // (Currently we don't for the other attributes. They are implemented wi

[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-20 Thread Michael Liao via Phabricator via cfe-commits
hliao marked 5 inline comments as done.
hliao added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:701-713
+  if (getLangOpts().CUDAIsDevice) {
+// As CUDA builtin surface/texture types are replaced, skip generating TBAA
+// access info.
+if (AccessType->isCUDADeviceBuiltinSurfaceType()) {
+  if (getTargetCodeGenInfo().getCUDADeviceBuiltinSurfaceDeviceType() !=
+  nullptr)
+return TBAAAccessInfo();

tra wrote:
> Would `isCUDADeviceBuiltinTextureType()` be sufficient criteria for skipping 
> TBAA regeneration?
> Or does it need to be 'it is the texture type and it will be replaced with 
> something else'? What is 'something else' is the same type?
> 
> 
The replacement only happens in the device compilation. On the host-side, the 
original type is still used.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4101-4127
+if (const ClassTemplateSpecializationDecl *TD =
+dyn_cast(RD)) {
+  Linkage = llvm::GlobalValue::InternalLinkage;
+  const TemplateArgumentList &Args = 
TD->getTemplateInstantiationArgs();
+  if (RD->hasAttr()) {
+assert(Args.size() == 2 &&
+   "Unexpcted number of template arguments of CUDA device "

tra wrote:
> This is the part I'm not comfortable with.
> It's possible for the user to use the attribute on other types that do not 
> match the expectations encoded here.
> We should not be failing with an assert here because that's *user* error, not 
> a compiler bug.
> 
> Expectations we have for the types should be enforced by Sema and compiler 
> should produce proper diagnostics.
> 
`device_builtin_surface_type` and `device_builtin_texture_type` should only be 
used internally. Regular users of either CUDA or HIP must not use them as they 
need special internal handling and coordination beyond the compiler itself.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:6471-6472
+// Lookup `addrspacecast` through the constant pointer if any.
+if (auto *ASC = llvm::dyn_cast_or_null(C))
+  C = llvm::cast(ASC->getPointerOperand());
+if (auto *GV = llvm::dyn_cast_or_null(C)) {

tra wrote:
> What's the expectation here? Do we care which address spaces we're casting 
> to/from? 
We need to check whether we copy from that global variable directly. As all 
pointers are generic ones, the code here is to look through the `addrspacecast` 
constant expression for the original global variable.



Comment at: clang/lib/Headers/__clang_cuda_runtime_wrapper.h:82-94
 #undef __CUDACC__
 #if CUDA_VERSION < 9000
 #define __CUDABE__
 #else
+#define __CUDACC__
 #define __CUDA_LIBDEVICE__
 #endif

tra wrote:
> Please add comments on why __CUDACC__ is needed for driver_types.h here? 
> AFAICT, driver_types.h does not have any conditionals that depend on 
> __CUDACC__. What happens if it's not defined.
> 
> 
`driver_types.h` includes `host_defines.h`, where macros 
`__device_builtin_surface_type__` and `__device_builtin_texture_type__` are 
conditional defined if `__CUDACC__`.

The following is extracted from `cuda/crt/host_defines.h`

```
#if !defined(__CUDACC__)
#define __device_builtin__
#define __device_builtin_texture_type__
#define __device_builtin_surface_type__
#define __cudart_builtin__
#else /* defined(__CUDACC__) */
#define __device_builtin__ \
__location__(device_builtin)
#define __device_builtin_texture_type__ \
__location__(device_builtin_texture_type)
#define __device_builtin_surface_type__ \
__location__(device_builtin_surface_type)
#define __cudart_builtin__ \
__location__(cudart_builtin)
#endif /* !defined(__CUDACC__) */
```



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6944-6945
+handleSimpleAttributeWithExclusions(S, D,
+  AL);
+break;

tra wrote:
> Nit: Formatting is a bit odd here. Why is AL on a separate line?
it's formatted by `clang-format`, which is run in pre-merge checks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365



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


[PATCH] D76504: [clang] Fix crash during template sema checking

2020-03-20 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 251780.
gchatelet added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76504

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtins-memcpy-inline.c
  clang/test/Sema/builtins-memcpy-inline.cpp


Index: clang/test/Sema/builtins-memcpy-inline.cpp
===
--- clang/test/Sema/builtins-memcpy-inline.cpp
+++ clang/test/Sema/builtins-memcpy-inline.cpp
@@ -30,3 +30,9 @@
 void test_memcpy_inline_non_constant_size(void *dst, const void *src, unsigned 
size) {
   __builtin_memcpy_inline(dst, src, size); // expected-error {{argument to 
'__builtin_memcpy_inline' must be a constant integer}}
 }
+
+template 
+void test_memcpy_inline_template(void *dst, const void *src) {
+  // we do not try to evaluate size in non intantiated templates.
+  __builtin_memcpy_inline(dst, src, size);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1649,11 +1649,16 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
-// __builtin_memcpy_inline size argument is a constant by definition.
-if (TheCall->getArg(2)->EvaluateKnownConstInt(Context).isNullValue())
+clang::Expr *SizeOp = TheCall->getArg(2);
+// We warn about copying to or from `nullptr` pointers when `size` is
+// greater than 0. When `size` is value dependent we cannot evaluate its
+// value so we bail<< out.
+if (SizeOp->isValueDependent())
   break;
-CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
-CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+if (!SizeOp->EvaluateKnownConstInt(Context).isNullValue()) {
+  CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
+  CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+}
 break;
   }
 #define BUILTIN(ID, TYPE, ATTRS)


Index: clang/test/Sema/builtins-memcpy-inline.cpp
===
--- clang/test/Sema/builtins-memcpy-inline.cpp
+++ clang/test/Sema/builtins-memcpy-inline.cpp
@@ -30,3 +30,9 @@
 void test_memcpy_inline_non_constant_size(void *dst, const void *src, unsigned size) {
   __builtin_memcpy_inline(dst, src, size); // expected-error {{argument to '__builtin_memcpy_inline' must be a constant integer}}
 }
+
+template 
+void test_memcpy_inline_template(void *dst, const void *src) {
+  // we do not try to evaluate size in non intantiated templates.
+  __builtin_memcpy_inline(dst, src, size);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1649,11 +1649,16 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
-// __builtin_memcpy_inline size argument is a constant by definition.
-if (TheCall->getArg(2)->EvaluateKnownConstInt(Context).isNullValue())
+clang::Expr *SizeOp = TheCall->getArg(2);
+// We warn about copying to or from `nullptr` pointers when `size` is
+// greater than 0. When `size` is value dependent we cannot evaluate its
+// value so we bail<< out.
+if (SizeOp->isValueDependent())
   break;
-CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
-CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+if (!SizeOp->EvaluateKnownConstInt(Context).isNullValue()) {
+  CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
+  CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+}
 break;
   }
 #define BUILTIN(ID, TYPE, ATTRS)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D74619: [ARM] Enabling range checks on Neon intrinsics' lane arguments

2020-03-20 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

Hi, a bisect seems to show 
https://reviews.llvm.org/rGf56550cf7f12b581a237b48a7f4d8b6682d45a09 is causing 
us to see the following error:

  error: argument value 1 is outside the valid range [0, 0]
  v2 = vdupq_lane_f64(vget_high_f64(a.v), 1);
  ^  ~
  
../../prebuilt/third_party/clang/linux-x64/lib/clang/11.0.0/include/arm_neon.h:46503:15:
 note: expanded from macro 'vdupq_lane_f64'
  __ret_307 = splatq_lane_f64(__s0_307, __p1_307); \
  ^ 
  
../../prebuilt/third_party/clang/linux-x64/lib/clang/11.0.0/include/arm_neon.h:680:25:
 note: expanded from macro 'splatq_lane_f64'
  __ret = (float64x2_t) __builtin_neon_splatq_lane_v((int8x8_t)__s0, __p1, 10); 
\
  ^
  1 error generated.

when building Fuchsia.

I'll see if I can make a minimal reproducer. Just wanted to raise awareness in 
the meantime to see if you can take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74619



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


[clang] 43580a5 - Allow remapping Clang module skeleton CU references with -fdebug-prefix-map

2020-03-20 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2020-03-20T15:15:56-07:00
New Revision: 43580a5c5afc3cd935e4e3d67f285fe81dd7e8c5

URL: 
https://github.com/llvm/llvm-project/commit/43580a5c5afc3cd935e4e3d67f285fe81dd7e8c5
DIFF: 
https://github.com/llvm/llvm-project/commit/43580a5c5afc3cd935e4e3d67f285fe81dd7e8c5.diff

LOG: Allow remapping Clang module skeleton CU references with -fdebug-prefix-map

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/Modules/debug-info-moduleimport.m
clang/test/PCH/debug-info-pch-path.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 9645dd1deb42..a98d82f7152c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2493,14 +2493,18 @@ llvm::DIModule 
*CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
 : ~1ULL;
 llvm::DIBuilder DIB(CGM.getModule());
 SmallString<0> PCM;
-if (!llvm::sys::path::is_absolute(PCM))
+if (!llvm::sys::path::is_absolute(Mod.getASTFile()))
   PCM = Mod.getPath();
 llvm::sys::path::append(PCM, Mod.getASTFile());
-StringRef CompDir = getCurrentDirname();
+std::string RemappedPCM = remapDIPath(PCM);
+StringRef RelativePCM(RemappedPCM);
+StringRef CompDir = TheCU->getDirectory();
+if (RelativePCM.consume_front(CompDir))
+  RelativePCM.consume_front(llvm::sys::path::get_separator());
 DIB.createCompileUnit(TheCU->getSourceLanguage(),
   // TODO: Support "Source" from external AST 
providers?
   DIB.createFile(Mod.getModuleName(), CompDir),
-  TheCU->getProducer(), false, StringRef(), 0, PCM,
+  TheCU->getProducer(), false, StringRef(), 0, 
RelativePCM,
   llvm::DICompileUnit::FullDebug, Signature);
 DIB.finalize();
   }

diff  --git a/clang/test/Modules/debug-info-moduleimport.m 
b/clang/test/Modules/debug-info-moduleimport.m
index 837459b0786c..9dee9964b538 100644
--- a/clang/test/Modules/debug-info-moduleimport.m
+++ b/clang/test/Modules/debug-info-moduleimport.m
@@ -1,11 +1,19 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -DGREETING="Hello World" 
-UNDEBUG -fimplicit-module-maps -fmodules-cache-path=%t %s -I %S/Inputs 
-isysroot /tmp/.. -I %t -emit-llvm -o - | FileCheck %s --check-prefix=NOIMPORT
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules \
+// RUN: -DGREETING="Hello World" -UNDEBUG \
+// RUN: -fimplicit-module-maps -fmodules-cache-path=%t %s \
+// RUN: -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
+// RUN: | FileCheck %s --check-prefix=NOIMPORT
 
 // NOIMPORT-NOT: !DIImportedEntity
 // NOIMPORT-NOT: !DIModule
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -DGREETING="Hello World" 
-UNDEBUG -fimplicit-module-maps -fmodules-cache-path=%t %s -I %S/Inputs 
-isysroot /tmp/.. -I %t -emit-llvm -debugger-tuning=lldb -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules \
+// RUN:-DGREETING="Hello World" -UNDEBUG \
+// RUN:-fimplicit-module-maps -fmodules-cache-path=%t %s \
+// RUN:-I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm \
+// RUN:-debugger-tuning=lldb -o - | FileCheck %s
 
 // CHECK: ![[CU:.*]] = distinct !DICompileUnit
 // CHECK-SAME:  sysroot: "/tmp/..")
@@ -18,17 +26,18 @@
 // CHECK-SAME:  includePath: "{{.*}}test{{.*}}Modules{{.*}}Inputs"
 // CHECK: ![[F]] = !DIFile(filename: {{.*}}debug-info-moduleimport.m
 
-// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t \
-// RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
-// RUN: | FileCheck %s --check-prefix=NO-SKEL-CHECK
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
+// RUN:   -fmodules-cache-path=%t %s -I %S/Inputs -isysroot /tmp/.. -I %t \
+// RUN:   -emit-llvm -o - | FileCheck %s --check-prefix=NO-SKEL-CHECK
 // NO-SKEL-CHECK: distinct !DICompileUnit
 // NO-SKEL-CHECK-NOT: distinct !DICompileUnit
 
-// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t \
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
+// RUN:   -fmodules-cache-path=%t -fdebug-prefix-map=%t=/MODULE-CACHE \
 // RUN:   -fmodule-format=obj -dwarf-ext-refs \
 // RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
 // RUN: | FileCheck %s --check-prefix=SKEL-CHECK
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
 // SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
-// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: 
![[DWOFILE:[0-9]+]]{{.*}}dwoId
+// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: 
![[DWOFILE:[0-9]+]]{{.*}}splitDebugFile

[clang] f75f19c - [Clang][test] Add .i files for test discovery

2020-03-20 Thread Sylvain Audi via cfe-commits

Author: Sylvain Audi
Date: 2020-03-20T18:21:27-04:00
New Revision: f75f19c2374807247e779a1e00bfeabc337ee446

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

LOG: [Clang][test] Add .i files for test discovery

The .i files in the clang tests (2 files) were not run by lit :
clang/test/CodeGen/debug-info-preprocessed-file.i
clang/test/FrontEnd/processed-input.i

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

Added: 


Modified: 
clang/test/lit.cfg.py

Removed: 




diff  --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index bdf3b1179225..18b5a2991f7e 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -25,7 +25,7 @@
 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu',
+config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu',
'.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', 
'.ifs']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'



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


[PATCH] D76533: [clangd] Skip ClangdVFSTest.TestStackOverflow when address sanitizer is used

2020-03-20 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope created this revision.
bjope added reviewers: sammccall, Dmitry.Kozhevnikov.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay, ilya-biryukov.
Herald added a project: clang.
bjope added a comment.
bjope added subscribers: uabelho, dstenb.

I don't know if this is a good solution. But we've had problems with our 
downstream bots that builds llvm with asan, and runs check-all, for awhile 
(probably since we merged https://reviews.llvm.org/D50993).


The ClangdVFSTest.TestStackOverflow unittest does not seem to work
when building the test with address sanitizer activated. Afaict the
goal is to get a constexpr depth error, rather than stack overflow.
But with asan instrumentation we do get stack overflow complaints
from asan. As a workaround this patch simply disables the test case,
when being built with address sanitizer activated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76533

Files:
  clang-tools-extra/clangd/unittests/ClangdTests.cpp


Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -1083,6 +1083,9 @@
 Field(&CodeCompletion::Scope, "ns::";
 }
 
+// Tests fails when built with asan due to stack overflow. So skip running the
+// test as a workaround.
+#if !defined(__has_feature) || !__has_feature(address_sanitizer)
 TEST_F(ClangdVFSTest, TestStackOverflow) {
   MockFSProvider FS;
   ErrorCheckingCallbacks DiagConsumer;
@@ -1103,6 +1106,7 @@
   // overflow
   EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
 }
+#endif
 
 } // namespace
 } // namespace clangd


Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -1083,6 +1083,9 @@
 Field(&CodeCompletion::Scope, "ns::";
 }
 
+// Tests fails when built with asan due to stack overflow. So skip running the
+// test as a workaround.
+#if !defined(__has_feature) || !__has_feature(address_sanitizer)
 TEST_F(ClangdVFSTest, TestStackOverflow) {
   MockFSProvider FS;
   ErrorCheckingCallbacks DiagConsumer;
@@ -1103,6 +1106,7 @@
   // overflow
   EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
 }
+#endif
 
 } // namespace
 } // namespace clangd
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76534: [clang/docs] Fix various sphinx warnings/errors in docs.

2020-03-20 Thread Florian Hahn via Phabricator via cfe-commits
fhahn created this revision.
fhahn added reviewers: jfb, Bigcheese, dexonsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There are a few places with unexpected indents that trip over sphinx and
other syntax errors.

Also, the C++ syntax highlighting does not work for

  class [[gsl::Owner(int)]] IntOwner {

Use a regular code:: block instead.

There are a few other warnings errors remaining, of the form
'Duplicate explicit target name: "cmdoption-clang--prefix"'. They seem
to be caused by the following

  .. option:: -B, --prefix , --prefix=

I am no Restructured Text expert, but it seems like sphinx 1.8.5
tries to generate the same target for the --prefix  and
--prefix=. This pops up in a lot of places and I am not sure how to
best resolve it


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76534

Files:
  clang/docs/InternalsManual.rst
  clang/docs/LanguageExtensions.rst
  clang/docs/OpenMPSupport.rst
  clang/docs/analyzer/checkers.rst
  clang/docs/analyzer/developer-docs/DebugChecks.rst
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td

Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1176,7 +1176,7 @@
 the token limit, which can be set in three ways:
 
 1. As a limit at a specific point in a file, using the ``clang max_tokens_here``
-  pragma:
+   pragma:
 
.. code-block: c++
   #pragma clang max_tokens_here 1234
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3373,8 +3373,8 @@
   let Heading = "#pragma omp declare variant";
   let Content = [{
 The `declare variant` directive declares a specialized variant of a base
- function and specifies the context in which that specialized variant is used.
- The declare variant directive is a declarative directive.
+function and specifies the context in which that specialized variant is used.
+The declare variant directive is a declarative directive.
 The syntax of the `declare variant` construct is as follows:
 
   .. code-block:: none
@@ -3391,7 +3391,7 @@
 match(context-selector-specification)
 
 and where `variant-func-id` is the name of a function variant that is either a
- base language identifier or, for C++, a template-id.
+base language identifier or, for C++, a template-id.
 
   }];
 }
@@ -4076,8 +4076,8 @@
   including calling the ``+initialize`` method if present.
 
 - The implicit ``_cmd`` parameter containing the method's selector is still defined.
- In order to minimize code-size costs, the implementation will not emit a reference
- to the selector if the parameter is unused within the method.
+  In order to minimize code-size costs, the implementation will not emit a reference
+  to the selector if the parameter is unused within the method.
 
 Symbols for direct method implementations are implicitly given hidden
 visibility, meaning that they can only be called within the same linkage unit.
@@ -4633,7 +4633,7 @@
 The attribute ``[[gsl::Owner(T)]]`` applies to structs and classes that own an
 object of type ``T``:
 
-.. code-block:: c++
+.. code::
 
   class [[gsl::Owner(int)]] IntOwner {
   private:
@@ -4659,7 +4659,7 @@
 The attribute ``[[gsl::Pointer(T)]]`` applies to structs and classes that behave
 like pointers to an object of type ``T``:
 
-.. code-block:: c++
+.. code::
 
   class [[gsl::Pointer(int)]] IntPointer {
   private:
@@ -4718,7 +4718,7 @@
   let Category = DocCatFunction;
   let Content = [{
 .. Note:: This attribute is not yet fully implemented, it is validated but has
-no effect on the generated code.
+  no effect on the generated code.
 
 The ``__attribute__((no_builtin))`` is similar to the ``-fno-builtin`` flag
 except it is specific to the body of a function. The attribute may also be
Index: clang/docs/analyzer/developer-docs/DebugChecks.rst
===
--- clang/docs/analyzer/developer-docs/DebugChecks.rst
+++ clang/docs/analyzer/developer-docs/DebugChecks.rst
@@ -281,7 +281,7 @@
   This is useful in tests, where we don't want to issue warning for all tainted
   expressions but only check for certain expressions.
   This would help to reduce the *noise* that the `TaintTest` debug checker would
-  introduce and let you focus on the `expected-warning`s that you really care
+  introduce and let you focus on the `expected-warning`'s that you really care
   about.
 
   Example usage::
Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -1934,14 +1934,14 @@
 alpha.security.cert
 ^^^
 
-SEI CERT checke

[PATCH] D76504: [clang] Fix crash during template sema checking

2020-03-20 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/Sema/SemaChecking.cpp:1655
+// greater than 0. When `size` is value dependent we cannot evaluate its
+// value so we bail<< out.
+if (SizeOp->isValueDependent())

"<<"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76504



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


[PATCH] D76385: Allow remapping Clang module include paths

2020-03-20 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl updated this revision to Diff 251789.
aprantl added a comment.

Rebased and addressed review comments.


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

https://reviews.llvm.org/D76385

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/Modules/debug-info-moduleimport.m


Index: clang/test/Modules/debug-info-moduleimport.m
===
--- clang/test/Modules/debug-info-moduleimport.m
+++ clang/test/Modules/debug-info-moduleimport.m
@@ -34,9 +34,11 @@
 
 // RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
 // RUN:   -fmodules-cache-path=%t -fdebug-prefix-map=%t=/MODULE-CACHE \
+// RUN:   -fdebug-prefix-map=%S=/SRCDIR \
 // RUN:   -fmodule-format=obj -dwarf-ext-refs \
 // RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
 // RUN: | FileCheck %s --check-prefix=SKEL-CHECK
+// SKEL-CHECK: includePath: "/SRCDIR/Inputs"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
 // SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: 
![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2483,6 +2483,17 @@
 assert(StringRef(M->Name).startswith(CGM.getLangOpts().ModuleName) &&
"clang module without ASTFile must be specified by -fmodule-name");
 
+  // Return a StringRef to the remapped Path.
+  auto RemapPath = [this](StringRef Path) -> std::string {
+std::string Remapped = remapDIPath(Path);
+StringRef Relative(Remapped);
+StringRef CompDir = TheCU->getDirectory();
+if (Relative.consume_front(CompDir))
+  Relative.consume_front(llvm::sys::path::get_separator());
+
+return Relative.str();
+  };
+
   if (CreateSkeletonCU && IsRootModule && !Mod.getASTFile().empty()) {
 // PCH files don't have a signature field in the control block,
 // but LLVM detects skeleton CUs by looking for a non-zero DWO id.
@@ -2496,16 +2507,12 @@
 if (!llvm::sys::path::is_absolute(Mod.getASTFile()))
   PCM = Mod.getPath();
 llvm::sys::path::append(PCM, Mod.getASTFile());
-std::string RemappedPCM = remapDIPath(PCM);
-StringRef RelativePCM(RemappedPCM);
-StringRef CompDir = TheCU->getDirectory();
-if (RelativePCM.consume_front(CompDir))
-  RelativePCM.consume_front(llvm::sys::path::get_separator());
-DIB.createCompileUnit(TheCU->getSourceLanguage(),
-  // TODO: Support "Source" from external AST 
providers?
-  DIB.createFile(Mod.getModuleName(), CompDir),
-  TheCU->getProducer(), false, StringRef(), 0, 
RelativePCM,
-  llvm::DICompileUnit::FullDebug, Signature);
+DIB.createCompileUnit(
+TheCU->getSourceLanguage(),
+// TODO: Support "Source" from external AST providers?
+DIB.createFile(Mod.getModuleName(), TheCU->getDirectory()),
+TheCU->getProducer(), false, StringRef(), 0, RemapPath(PCM),
+llvm::DICompileUnit::FullDebug, Signature);
 DIB.finalize();
   }
 
@@ -2513,9 +2520,10 @@
   IsRootModule ? nullptr
: getOrCreateModuleRef(ASTSourceDescriptor(*M->Parent),
   CreateSkeletonCU);
+  std::string IncludePath = Mod.getPath().str();
   llvm::DIModule *DIMod =
   DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
-Mod.getPath());
+RemapPath(IncludePath));
   ModuleCache[M].reset(DIMod);
   return DIMod;
 }


Index: clang/test/Modules/debug-info-moduleimport.m
===
--- clang/test/Modules/debug-info-moduleimport.m
+++ clang/test/Modules/debug-info-moduleimport.m
@@ -34,9 +34,11 @@
 
 // RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
 // RUN:   -fmodules-cache-path=%t -fdebug-prefix-map=%t=/MODULE-CACHE \
+// RUN:   -fdebug-prefix-map=%S=/SRCDIR \
 // RUN:   -fmodule-format=obj -dwarf-ext-refs \
 // RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
 // RUN: | FileCheck %s --check-prefix=SKEL-CHECK
+// SKEL-CHECK: includePath: "/SRCDIR/Inputs"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
 // SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2483,6 +2483,17 @@
 assert(StringRef(M->Name).startswith(CGM.getLangOpts().Mo

[PATCH] D75853: [Clang][test] Add .i files for test discovery

2020-03-20 Thread Sylvain Audi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf75f19c23748: [Clang][test] Add .i files for test discovery 
(authored by saudi).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75853

Files:
  clang/test/lit.cfg.py


Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -25,7 +25,7 @@
 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu',
+config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu',
'.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', 
'.ifs']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'


Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -25,7 +25,7 @@
 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu',
+config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu',
'.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76533: [clangd] Skip ClangdVFSTest.TestStackOverflow when address sanitizer is used

2020-03-20 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope added a comment.

I don't know if this is a good solution. But we've had problems with our 
downstream bots that builds llvm with asan, and runs check-all, for awhile 
(probably since we merged https://reviews.llvm.org/D50993).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76533



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


[PATCH] D76383: Allow remapping Clang module skeleton CU references with -fdebug-prefix-map

2020-03-20 Thread Adrian Prantl via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG43580a5c5afc: Allow remapping Clang module skeleton CU 
references with -fdebug-prefix-map (authored by aprantl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D76383?vs=251160&id=251791#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76383

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/Modules/debug-info-moduleimport.m
  clang/test/PCH/debug-info-pch-path.c

Index: clang/test/PCH/debug-info-pch-path.c
===
--- clang/test/PCH/debug-info-pch-path.c
+++ clang/test/PCH/debug-info-pch-path.c
@@ -23,7 +23,7 @@
 // CHECK-REL-NODIR: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-REL-NODIR: !DICompileUnit(
 // CHECK-REL-NODIR-SAME:   file: ![[PCH:[0-9]+]]
-// CHECK-REL-NODIR-SAME:   splitDebugFilename: "{{.*}}PCH{{.*}}prefix.pch"
+// CHECK-REL-NODIR-SAME:   splitDebugFilename: "prefix.pch"
 // CHECK-REL-NODIR: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]
 
 // -
@@ -47,7 +47,7 @@
 // CHECK-REL: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-REL: !DICompileUnit(
 // CHECK-REL-SAME:   file: ![[PCH:[0-9]+]]
-// CHECK-REL-SAME:   splitDebugFilename: "[[DIR]]{{.*}}pchdir{{.*}}prefix.pch"
+// CHECK-REL-SAME:   splitDebugFilename: "pchdir{{.*}}prefix.pch"
 // CHECK-REL: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]"
 
 // -
@@ -70,5 +70,5 @@
 // CHECK-ABS: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
 // CHECK-ABS: !DICompileUnit(
 // CHECK-ABS-SAME:   file: ![[PCH:[0-9]+]]
-// CHECK-ABS-SAME:   splitDebugFilename: "[[DIR]]{{.*}}prefix.pch"
+// CHECK-ABS-SAME:   splitDebugFilename: "prefix.pch"
 // CHECK-ABS: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]
Index: clang/test/Modules/debug-info-moduleimport.m
===
--- clang/test/Modules/debug-info-moduleimport.m
+++ clang/test/Modules/debug-info-moduleimport.m
@@ -1,11 +1,19 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -DGREETING="Hello World" -UNDEBUG -fimplicit-module-maps -fmodules-cache-path=%t %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - | FileCheck %s --check-prefix=NOIMPORT
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules \
+// RUN: -DGREETING="Hello World" -UNDEBUG \
+// RUN: -fimplicit-module-maps -fmodules-cache-path=%t %s \
+// RUN: -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
+// RUN: | FileCheck %s --check-prefix=NOIMPORT
 
 // NOIMPORT-NOT: !DIImportedEntity
 // NOIMPORT-NOT: !DIModule
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -DGREETING="Hello World" -UNDEBUG -fimplicit-module-maps -fmodules-cache-path=%t %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -debugger-tuning=lldb -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules \
+// RUN:-DGREETING="Hello World" -UNDEBUG \
+// RUN:-fimplicit-module-maps -fmodules-cache-path=%t %s \
+// RUN:-I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm \
+// RUN:-debugger-tuning=lldb -o - | FileCheck %s
 
 // CHECK: ![[CU:.*]] = distinct !DICompileUnit
 // CHECK-SAME:  sysroot: "/tmp/..")
@@ -18,17 +26,18 @@
 // CHECK-SAME:  includePath: "{{.*}}test{{.*}}Modules{{.*}}Inputs"
 // CHECK: ![[F]] = !DIFile(filename: {{.*}}debug-info-moduleimport.m
 
-// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \
-// RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
-// RUN: | FileCheck %s --check-prefix=NO-SKEL-CHECK
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
+// RUN:   -fmodules-cache-path=%t %s -I %S/Inputs -isysroot /tmp/.. -I %t \
+// RUN:   -emit-llvm -o - | FileCheck %s --check-prefix=NO-SKEL-CHECK
 // NO-SKEL-CHECK: distinct !DICompileUnit
 // NO-SKEL-CHECK-NOT: distinct !DICompileUnit
 
-// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
+// RUN:   -fmodules-cache-path=%t -fdebug-prefix-map=%t=/MODULE-CACHE \
 // RUN:   -fmodule-format=obj -dwarf-ext-refs \
 // RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
 // RUN: | FileCheck %s --check-prefix=SKEL-CHECK
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
 // SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
-// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}dwoId

[clang] 6725c48 - Allow remapping the sysroot with -fdebug-prefix-map.

2020-03-20 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2020-03-20T15:52:39-07:00
New Revision: 6725c4836a5b3c11227869a6f456019a244aa29f

URL: 
https://github.com/llvm/llvm-project/commit/6725c4836a5b3c11227869a6f456019a244aa29f
DIFF: 
https://github.com/llvm/llvm-project/commit/6725c4836a5b3c11227869a6f456019a244aa29f.diff

LOG: Allow remapping the sysroot with -fdebug-prefix-map.



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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-prefix-map.c
llvm/lib/DWARFLinker/DWARFLinker.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index a98d82f7152c..da6cb458982b 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -631,7 +631,7 @@ void CGDebugInfo::CreateCompileUnit() {
   ? llvm::DICompileUnit::DebugNameTableKind::None
   : static_cast(
 CGOpts.DebugNameTable),
-  CGOpts.DebugRangesBaseAddress, Sysroot, SDK);
+  CGOpts.DebugRangesBaseAddress, remapDIPath(Sysroot), SDK);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {

diff  --git a/clang/test/CodeGen/debug-prefix-map.c 
b/clang/test/CodeGen/debug-prefix-map.c
index 5366e19447ae..354110d1b0da 100644
--- a/clang/test/CodeGen/debug-prefix-map.c
+++ b/clang/test/CodeGen/debug-prefix-map.c
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s 
-check-prefix CHECK-EVIL
 // RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -main-file-name 
debug-prefix-map.c | FileCheck %s
 // RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - 
-fdebug-compilation-dir %p | FileCheck %s -check-prefix CHECK-COMPILATION-DIR
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -isysroot %p 
-debugger-tuning=lldb | FileCheck %s -check-prefix CHECK-SYSROOT
 // RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s
 // RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s
 
@@ -40,3 +41,4 @@ void test_rewrite_includes() {
 // CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}", directory: 
"/UNLIKELY_PATH/empty")
 // CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}Inputs/stdio.h", directory: 
"/UNLIKELY_PATH/empty")
 // CHECK-COMPILATION-DIR-NOT: !DIFile(filename:
+// CHECK-SYSROOT: !DICompileUnit({{.*}}sysroot: "/UNLIKELY_PATH/empty"

diff  --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp 
b/llvm/lib/DWARFLinker/DWARFLinker.cpp
index 8464c04f801e..fbc3a3e60cc9 100644
--- a/llvm/lib/DWARFLinker/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp
@@ -1914,6 +1914,15 @@ static uint64_t getDwoId(const DWARFDie &CUDie, const 
DWARFUnit &Unit) {
   return 0;
 }
 
+static std::string remapPath(std::string Path,
+ const objectPrefixMap &ObjectPrefixMap) {
+  StringRef PathRef(Path);
+  for (const auto &Entry : ObjectPrefixMap)
+if (PathRef.startswith(Entry.first))
+  return (Twine(Entry.second) + PathRef.substr(Entry.first.size())).str();
+  return Path;
+}
+
 bool DWARFLinker::registerModuleReference(
 DWARFDie CUDie, const DWARFUnit &Unit, const DwarfFile &File,
 OffsetsStringPool &StringPool, UniquingStringPool &UniquingStringPool,



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


[clang-tools-extra] 556b917 - [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes

2020-03-20 Thread Paula Toth via cfe-commits

Author: Paula Toth
Date: 2020-03-20T15:53:05-07:00
New Revision: 556b917fffcfaa15ea11a277e1b0d87b8d13e0f1

URL: 
https://github.com/llvm/llvm-project/commit/556b917fffcfaa15ea11a277e1b0d87b8d13e0f1
DIFF: 
https://github.com/llvm/llvm-project/commit/556b917fffcfaa15ea11a277e1b0d87b8d13e0f1.diff

LOG: [clang-tidy] Merge common code between 
llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes

Summary:
Made llvmlibc::RestrictSystemLibcHeadersCheck a subclass of 
protability::RestrictSystemIncludesCheck to re-use common code between the two.
This also adds the ability to white list linux development headers.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: mgorny, xazax.hun, MaskRay, cfe-commits, sivachandra

Tags: #clang-tools-extra, #clang

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
clang-tools-extra/docs/clang-tidy/checks/list.rst

clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst

clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Removed: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/math.h
clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h

clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp



diff  --git a/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
index c03d8b677f26..cc213d35a572 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
@@ -10,6 +10,7 @@ add_clang_library(clangTidyLLVMLibcModule
   clangBasic
   clangLex
   clangTidy
+  clangTidyPortabilityModule
   clangTidyUtils
   clangTooling
   )

diff  --git 
a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
index 8a597c0b2a24..4a19b5359d4f 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
@@ -18,12 +18,14 @@ namespace llvm_libc {
 
 namespace {
 
-class RestrictedIncludesPPCallbacks : public PPCallbacks {
+class RestrictedIncludesPPCallbacks
+: public portability::RestrictedIncludesPPCallbacks {
 public:
   explicit RestrictedIncludesPPCallbacks(
   RestrictSystemLibcHeadersCheck &Check, const SourceManager &SM,
   const SmallString<128> CompilerIncudeDir)
-  : Check(Check), SM(SM), CompilerIncudeDir(CompilerIncudeDir) {}
+  : portability::RestrictedIncludesPPCallbacks(Check, SM),
+CompilerIncudeDir(CompilerIncudeDir) {}
 
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
@@ -33,8 +35,6 @@ class RestrictedIncludesPPCallbacks : public PPCallbacks {
   SrcMgr::CharacteristicKind FileType) override;
 
 private:
-  RestrictSystemLibcHeadersCheck &Check;
-  const SourceManager &SM;
   const SmallString<128> CompilerIncudeDir;
 };
 
@@ -45,18 +45,12 @@ void RestrictedIncludesPPCallbacks::InclusionDirective(
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
 StringRef SearchPath, StringRef RelativePath, const Module *Imported,
 SrcMgr::CharacteristicKind FileType) {
-  if (SrcMgr::isSystem(FileType)) {
-// Compiler provided headers are allowed (e.g stddef.h).
-if (SearchPath == CompilerIncudeDir) return;
-if (!SM.isInMainFile(HashLoc)) {
-  Check.diag(
-  HashLoc,
-  "system libc header %0 not allowed, transitively included from %1")
-  << FileName << SM.getFilename(HashLoc);
-} else {
-  Check.diag(HashLoc, "system libc header %0 not allowed") << FileName;
-}
-  }
+  // Compiler provided headers are allowed (e.g stddef.h).
+  if (SrcMgr::isSystem(FileType) && SearchPath == CompilerIncudeDir)
+return;
+  portability::RestrictedIncludesPPCallbacks::InclusionDirective(
+  HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath,
+  RelativePath, Imported, FileType);
 }
 
 void RestrictSystemLibcHeadersCheck::registerPPCallbacks(

diff  --git 
a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h 
b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
index 3910a29a28e4..9eead7a22882 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/Rest

  1   2   >