[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-04-26 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 created this revision.
Herald added subscribers: dexonsmith, jdoerfert, pengfei.
Herald added a project: All.
LiuChen3 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

For now clang will assume the integer parameters have been sign/zero
extended in the caller, which will cause some ABI compatibility issues.
This patch will remove the `signext/zeroext` from the callee so that the
callee will always extend the integer parameters:

1. Adds one new `ConservativeExtend` Kind, which means we shouldn't

make any assumptions about the caller and callee. In this case, we must
do zero/sign extension for integer parameters in caller and callee.

2. Adds `-mconservative-extend/-mno-conservative-extend` options. As

default `-mconservative-extend` is enabled. Use `-mno-conservative-extend`
to get back to the original behavior of clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124435

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/2007-06-18-SextAttrAggregate.c
  clang/test/CodeGen/X86/integer_argument_passing.c
  clang/test/CodeGen/X86/x86_32-arguments-darwin.c
  clang/test/CodeGen/X86/x86_32-arguments-linux.c
  clang/test/CodeGen/X86/x86_64-arguments-nacl.c
  clang/test/CodeGen/X86/x86_64-arguments.c
  clang/test/CodeGen/attr-noundef.cpp
  clang/test/CodeGen/builtin-align.c
  clang/test/CodeGen/catch-implicit-integer-sign-changes.c
  clang/test/CodeGen/ext-int-cc.c
  clang/test/CodeGen/function-attributes.c
  clang/test/CodeGen/mangle-windows.c
  clang/test/CodeGen/matrix-type-builtins.c
  clang/test/CodeGen/matrix-type-operators.c
  clang/test/CodeGen/ms-inline-asm.c
  clang/test/CodeGen/regcall.c
  clang/test/CodeGen/vectorcall.c
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp
  clang/test/CodeGenCXX/new-overflow.cpp
  clang/test/CodeGenCXX/virtual-bases.cpp
  clang/test/CodeGenObjC/property-atomic-bool.m
  clang/test/OpenMP/target_codegen_global_capture.cpp

Index: clang/test/OpenMP/target_codegen_global_capture.cpp
===
--- clang/test/OpenMP/target_codegen_global_capture.cpp
+++ clang/test/OpenMP/target_codegen_global_capture.cpp
@@ -2051,7 +2051,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z3foo
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -2335,7 +2335,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z3bar
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0]] {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0]] {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -2642,7 +2642,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z5tbar2
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0]] {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0]] {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -2661,7 +2661,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z4tbarIsEiT_S0_S0_S0_
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0]] comdat {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0]] comdat {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -2975,7 +2975,7 @@
 //
 //
 // CHECK4-LABEL: define {{[^@]+}}@_Z3foo
-// CHECK4-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK4-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK4-NEXT:  entry:
 // CHECK4-NEXT:[[A_A

[PATCH] D123436: [Clang] Pass llvm::BitstreamCursor by reference. NFC

2022-04-26 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 425134.
junaire added a comment.

use std::move().

I'm not sure this will be better but hope it will make others happy :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436

Files:
  clang/lib/Serialization/GlobalModuleIndex.cpp


Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -277,7 +277,7 @@
   return std::make_pair(nullptr, Res.takeError());
   }
 
-  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), Cursor),
+  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), 
std::move(Cursor)),
 llvm::Error::success());
 }
 


Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -277,7 +277,7 @@
   return std::make_pair(nullptr, Res.takeError());
   }
 
-  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), Cursor),
+  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), std::move(Cursor)),
 llvm::Error::success());
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-04-26 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 updated this revision to Diff 425135.
LiuChen3 added a comment.

fix bug


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/2007-06-18-SextAttrAggregate.c
  clang/test/CodeGen/X86/integer_argument_passing.c
  clang/test/CodeGen/X86/x86_32-arguments-darwin.c
  clang/test/CodeGen/X86/x86_32-arguments-linux.c
  clang/test/CodeGen/X86/x86_64-arguments-nacl.c
  clang/test/CodeGen/X86/x86_64-arguments.c
  clang/test/CodeGen/attr-noundef.cpp
  clang/test/CodeGen/builtin-align.c
  clang/test/CodeGen/catch-implicit-integer-sign-changes.c
  clang/test/CodeGen/ext-int-cc.c
  clang/test/CodeGen/function-attributes.c
  clang/test/CodeGen/mangle-windows.c
  clang/test/CodeGen/matrix-type-builtins.c
  clang/test/CodeGen/matrix-type-operators.c
  clang/test/CodeGen/ms-inline-asm.c
  clang/test/CodeGen/regcall.c
  clang/test/CodeGen/vectorcall.c
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp
  clang/test/CodeGenCXX/new-overflow.cpp
  clang/test/CodeGenCXX/virtual-bases.cpp
  clang/test/CodeGenObjC/property-atomic-bool.m
  clang/test/OpenMP/target_codegen_global_capture.cpp

Index: clang/test/OpenMP/target_codegen_global_capture.cpp
===
--- clang/test/OpenMP/target_codegen_global_capture.cpp
+++ clang/test/OpenMP/target_codegen_global_capture.cpp
@@ -2051,7 +2051,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z3foo
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -2335,7 +2335,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z3bar
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0]] {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0]] {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -2642,7 +2642,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z5tbar2
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0]] {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0]] {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -2661,7 +2661,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z4tbarIsEiT_S0_S0_S0_
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0]] comdat {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0]] comdat {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -2975,7 +2975,7 @@
 //
 //
 // CHECK4-LABEL: define {{[^@]+}}@_Z3foo
-// CHECK4-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK4-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK4-NEXT:  entry:
 // CHECK4-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK4-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -3259,7 +3259,7 @@
 //
 //
 // CHECK4-LABEL: define {{[^@]+}}@_Z3bar
-// CHECK4-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0]] {
+// CHECK4-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0]] {
 // CHECK4-NEXT:  entry:
 // CHECK4-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK4-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -3566,7 +3566,7 @@
 //
 //
 // CHECK4-LABEL: define {{[^@]+}}@_Z5tbar2
-// CHECK4-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [

[PATCH] D124436: [analyzer] Fix Static Analyzer g_memdup false-positive

2022-04-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, Szelethus, martong, xazax.hun, ASDenysPetrov.
Herald added subscribers: manas, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`g_memdup()` allocates and copies memory, thus we should not assume that
the returned memory region is uninitialized because it might not be the
case.

PS: It would be even better to copy the bindings to mimic the actual
content of the buffer, but this works too.

Fixes #53617


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124436

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/gmalloc.c


Index: clang/test/Analysis/gmalloc.c
===
--- clang/test/Analysis/gmalloc.c
+++ clang/test/Analysis/gmalloc.c
@@ -21,6 +21,7 @@
 gpointer g_try_realloc_n(gpointer mem, gsize n_blocks, gsize n_block_bytes);
 void g_free(gpointer mem);
 gpointer g_memdup(gconstpointer mem, guint byte_size);
+gpointer g_strconcat(gconstpointer string1, ...);
 
 static const gsize n_bytes = 1024;
 
@@ -167,3 +168,16 @@
   g_free(g6);
   g_free(g7);
 }
+
+void f8(void) {
+  typedef struct {
+gpointer str;
+  } test_struct;
+
+  test_struct *s1 = (test_struct *)g_malloc0(sizeof(test_struct));
+  test_struct *s2 = (test_struct *)g_memdup(s1, sizeof(test_struct));
+  gpointer str = g_strconcat("text", s1->str, s2->str, NULL); // no-warning
+  g_free(str);
+  g_free(s2);
+  g_free(s1);
+}
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1408,8 +1408,8 @@
 void MallocChecker::checkGMemdup(const CallEvent &Call,
  CheckerContext &C) const {
   ProgramStateRef State = C.getState();
-  State = MallocMemAux(C, Call, Call.getArgExpr(1), UndefinedVal(), State,
-   AF_Malloc);
+  State =
+  MallocMemAux(C, Call, Call.getArgExpr(1), UnknownVal(), State, 
AF_Malloc);
   State = ProcessZeroAllocCheck(Call, 1, State);
   C.addTransition(State);
 }


Index: clang/test/Analysis/gmalloc.c
===
--- clang/test/Analysis/gmalloc.c
+++ clang/test/Analysis/gmalloc.c
@@ -21,6 +21,7 @@
 gpointer g_try_realloc_n(gpointer mem, gsize n_blocks, gsize n_block_bytes);
 void g_free(gpointer mem);
 gpointer g_memdup(gconstpointer mem, guint byte_size);
+gpointer g_strconcat(gconstpointer string1, ...);
 
 static const gsize n_bytes = 1024;
 
@@ -167,3 +168,16 @@
   g_free(g6);
   g_free(g7);
 }
+
+void f8(void) {
+  typedef struct {
+gpointer str;
+  } test_struct;
+
+  test_struct *s1 = (test_struct *)g_malloc0(sizeof(test_struct));
+  test_struct *s2 = (test_struct *)g_memdup(s1, sizeof(test_struct));
+  gpointer str = g_strconcat("text", s1->str, s2->str, NULL); // no-warning
+  g_free(str);
+  g_free(s2);
+  g_free(s1);
+}
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1408,8 +1408,8 @@
 void MallocChecker::checkGMemdup(const CallEvent &Call,
  CheckerContext &C) const {
   ProgramStateRef State = C.getState();
-  State = MallocMemAux(C, Call, Call.getArgExpr(1), UndefinedVal(), State,
-   AF_Malloc);
+  State =
+  MallocMemAux(C, Call, Call.getArgExpr(1), UnknownVal(), State, AF_Malloc);
   State = ProcessZeroAllocCheck(Call, 1, State);
   C.addTransition(State);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124437: [AST] Consider QualifiedTemplateName in TemplateName::getAsUsingDecl().

2022-04-26 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added projects: clang, clang-tools-extra.

If the underlying template name of a qualified template name is a using
decl, TemplateName::getAsUsingDecl() will return it.

This will make the UsingTemplateName consumer life easier.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124437

Files:
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang/lib/AST/TemplateName.cpp
  clang/unittests/AST/TemplateNameTest.cpp


Index: clang/unittests/AST/TemplateNameTest.cpp
===
--- clang/unittests/AST/TemplateNameTest.cpp
+++ clang/unittests/AST/TemplateNameTest.cpp
@@ -82,6 +82,7 @@
   const auto *USD = QTN->getUnderlyingTemplate().getAsUsingShadowDecl();
   EXPECT_TRUE(USD);
   EXPECT_EQ(USD->getTargetDecl(), TN.getAsTemplateDecl());
+  EXPECT_EQ(TN.getAsUsingShadowDecl(), USD);
 }
 
 TEST(TemplateName, UsingTemplate) {
Index: clang/lib/AST/TemplateName.cpp
===
--- clang/lib/AST/TemplateName.cpp
+++ clang/lib/AST/TemplateName.cpp
@@ -172,6 +172,8 @@
   if (Decl *D = Storage.dyn_cast())
 if (UsingShadowDecl *USD = dyn_cast(D))
   return USD;
+  if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())
+return QTN->getUnderlyingTemplate().getAsUsingShadowDecl();
   return nullptr;
 }
 
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -90,6 +90,13 @@
   template  class T> class X {};
   X x;
 )cpp"},
+  {R"cpp(namespace ns { template class A {};
+ namespace absl {using ns::^A;}
+   )cpp",
+   R"cpp(
+  template  class T> class X {};
+  X x;
+   )cpp"},
   {R"cpp(
   namespace ns { template struct ^A { ^A(T); }; }
   using ns::^A;


Index: clang/unittests/AST/TemplateNameTest.cpp
===
--- clang/unittests/AST/TemplateNameTest.cpp
+++ clang/unittests/AST/TemplateNameTest.cpp
@@ -82,6 +82,7 @@
   const auto *USD = QTN->getUnderlyingTemplate().getAsUsingShadowDecl();
   EXPECT_TRUE(USD);
   EXPECT_EQ(USD->getTargetDecl(), TN.getAsTemplateDecl());
+  EXPECT_EQ(TN.getAsUsingShadowDecl(), USD);
 }
 
 TEST(TemplateName, UsingTemplate) {
Index: clang/lib/AST/TemplateName.cpp
===
--- clang/lib/AST/TemplateName.cpp
+++ clang/lib/AST/TemplateName.cpp
@@ -172,6 +172,8 @@
   if (Decl *D = Storage.dyn_cast())
 if (UsingShadowDecl *USD = dyn_cast(D))
   return USD;
+  if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())
+return QTN->getUnderlyingTemplate().getAsUsingShadowDecl();
   return nullptr;
 }
 
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -90,6 +90,13 @@
   template  class T> class X {};
   X x;
 )cpp"},
+  {R"cpp(namespace ns { template class A {};
+ namespace absl {using ns::^A;}
+   )cpp",
+   R"cpp(
+  template  class T> class X {};
+  X x;
+   )cpp"},
   {R"cpp(
   namespace ns { template struct ^A { ^A(T); }; }
   using ns::^A;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109467: [analyzer] check for std::__addressof for inner pointer checker

2022-04-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal commandeered this revision.
steakhal edited reviewers, added: alishuja; removed: steakhal.
steakhal added a comment.
Herald added a reviewer: Szelethus.
Herald added a project: All.

I'll finish this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109467

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


[PATCH] D109467: [analyzer] check for std::__addressof for inner pointer checker

2022-04-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 425139.
steakhal edited the summary of this revision.
steakhal added a comment.

- rebased (now using `matchesAny(...)`
- added a test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109467

Files:
  clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
  clang/test/Analysis/inner-pointer.cpp


Index: clang/test/Analysis/inner-pointer.cpp
===
--- clang/test/Analysis/inner-pointer.cpp
+++ clang/test/Analysis/inner-pointer.cpp
@@ -20,6 +20,9 @@
 template 
 T *addressof(T &arg);
 
+template 
+T *__addressof(T &arg);
+
 char *data(std::string &c);
 
 } // end namespace std
@@ -383,6 +386,14 @@
   consume(c); // no-warning
 }
 
+void func_AddressofFn_() {
+  const char *c;
+  std::string s;
+  c = s.c_str();
+  (void)std::__addressof(s);
+  consume(c); // no-warning
+}
+
 void func_std_data() {
   const char *c;
   std::string s;
Index: clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
@@ -35,9 +35,9 @@
 class InnerPointerChecker
 : public Checker {
 
-  CallDescription AppendFn, AssignFn, AddressofFn, ClearFn, CStrFn, DataFn,
-  DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn, ReplaceFn,
-  ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
+  CallDescription AppendFn, AssignFn, AddressofFn, AddressofFn_, ClearFn,
+  CStrFn, DataFn, DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn,
+  ReplaceFn, ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
 
 public:
   class InnerPointerBRVisitor : public BugReporterVisitor {
@@ -74,7 +74,7 @@
   InnerPointerChecker()
   : AppendFn({"std", "basic_string", "append"}),
 AssignFn({"std", "basic_string", "assign"}),
-AddressofFn({"std", "addressof"}),
+AddressofFn({"std", "addressof"}), AddressofFn_({"std", 
"__addressof"}),
 ClearFn({"std", "basic_string", "clear"}),
 CStrFn({"std", "basic_string", "c_str"}), DataFn({"std", "data"}, 1),
 DataMemberFn({"std", "basic_string", "data"}),
@@ -179,9 +179,9 @@
   if (!ArgRegion)
 continue;
 
-  // std::addressof function accepts a non-const reference as an argument,
+  // std::addressof functions accepts a non-const reference as an argument,
   // but doesn't modify it.
-  if (AddressofFn.matches(Call))
+  if (matchesAny(Call, AddressofFn, AddressofFn_))
 continue;
 
   markPtrSymbolsReleased(Call, State, ArgRegion, C);


Index: clang/test/Analysis/inner-pointer.cpp
===
--- clang/test/Analysis/inner-pointer.cpp
+++ clang/test/Analysis/inner-pointer.cpp
@@ -20,6 +20,9 @@
 template 
 T *addressof(T &arg);
 
+template 
+T *__addressof(T &arg);
+
 char *data(std::string &c);
 
 } // end namespace std
@@ -383,6 +386,14 @@
   consume(c); // no-warning
 }
 
+void func_AddressofFn_() {
+  const char *c;
+  std::string s;
+  c = s.c_str();
+  (void)std::__addressof(s);
+  consume(c); // no-warning
+}
+
 void func_std_data() {
   const char *c;
   std::string s;
Index: clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
@@ -35,9 +35,9 @@
 class InnerPointerChecker
 : public Checker {
 
-  CallDescription AppendFn, AssignFn, AddressofFn, ClearFn, CStrFn, DataFn,
-  DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn, ReplaceFn,
-  ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
+  CallDescription AppendFn, AssignFn, AddressofFn, AddressofFn_, ClearFn,
+  CStrFn, DataFn, DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn,
+  ReplaceFn, ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
 
 public:
   class InnerPointerBRVisitor : public BugReporterVisitor {
@@ -74,7 +74,7 @@
   InnerPointerChecker()
   : AppendFn({"std", "basic_string", "append"}),
 AssignFn({"std", "basic_string", "assign"}),
-AddressofFn({"std", "addressof"}),
+AddressofFn({"std", "addressof"}), AddressofFn_({"std", "__addressof"}),
 ClearFn({"std", "basic_string", "clear"}),
 CStrFn({"std", "basic_string", "c_str"}), DataFn({"std", "data"}, 1),
 DataMemberFn({"std", "basic_string", "data"}),
@@ -179,9 +179,9 @@
   if (!ArgRegion)
 continue;
 
-  // std::addressof function accepts a non-const reference as an argument,
+  // std::addressof functions accepts a non-const reference as an argument,
   // but doesn't modify it.
-  if (AddressofFn.matches(Call))
+  if (matchesAny(Call, AddressofFn, AddressofFn_))
 conti

[PATCH] D124395: [clang][dataflow] Optimize flow condition representation

2022-04-26 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 425143.
sgatev marked 2 inline comments as done.
sgatev added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124395

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -90,4 +90,54 @@
   EXPECT_NE(&NotX1, &NotY);
 }
 
+TEST_F(DataflowAnalysisContextTest, EmptyFlowCondition) {
+  auto &FC = Context.makeFlowConditionToken();
+  auto &C = Context.createAtomicBoolValue();
+  EXPECT_FALSE(Context.flowConditionImplies(FC, C));
+}
+
+TEST_F(DataflowAnalysisContextTest, AddFlowConditionConstraint) {
+  auto &FC = Context.makeFlowConditionToken();
+  auto &C = Context.createAtomicBoolValue();
+  Context.addFlowConditionConstraint(FC, C);
+  EXPECT_TRUE(Context.flowConditionImplies(FC, C));
+}
+
+TEST_F(DataflowAnalysisContextTest, ForkFlowCondition) {
+  auto &FC1 = Context.makeFlowConditionToken();
+  auto &C1 = Context.createAtomicBoolValue();
+  Context.addFlowConditionConstraint(FC1, C1);
+
+  // Forked flow condition inherits the constraints of its parent flow
+  // condition.
+  auto &FC2 = Context.forkFlowCondition(FC1);
+  EXPECT_TRUE(Context.flowConditionImplies(FC2, C1));
+
+  // Adding a new constraint to the forked flow condition does not affect its
+  // parent flow condition.
+  auto &C2 = Context.createAtomicBoolValue();
+  Context.addFlowConditionConstraint(FC2, C2);
+  EXPECT_TRUE(Context.flowConditionImplies(FC2, C2));
+  EXPECT_FALSE(Context.flowConditionImplies(FC1, C2));
+}
+
+TEST_F(DataflowAnalysisContextTest, JoinFlowConditions) {
+  auto &C1 = Context.createAtomicBoolValue();
+  auto &C2 = Context.createAtomicBoolValue();
+  auto &C3 = Context.createAtomicBoolValue();
+
+  auto &FC1 = Context.makeFlowConditionToken();
+  Context.addFlowConditionConstraint(FC1, C1);
+  Context.addFlowConditionConstraint(FC1, C3);
+
+  auto &FC2 = Context.makeFlowConditionToken();
+  Context.addFlowConditionConstraint(FC2, C2);
+  Context.addFlowConditionConstraint(FC2, C3);
+
+  auto &FC3 = Context.joinFlowConditions(FC1, FC2);
+  EXPECT_FALSE(Context.flowConditionImplies(FC3, C1));
+  EXPECT_FALSE(Context.flowConditionImplies(FC3, C2));
+  EXPECT_TRUE(Context.flowConditionImplies(FC3, C3));
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -76,33 +76,14 @@
   Environment &MergedEnv,
   Environment::ValueModel &Model) {
   // Join distinct boolean values preserving information about the constraints
-  // in the respective path conditions. Note: this construction can, in
-  // principle, result in exponential growth in the size of boolean values.
-  // Potential optimizations may be worth considering. For example, represent
-  // the flow condition of each environment using a bool atom and store, in
-  // `DataflowAnalysisContext`, a mapping of bi-conditionals between flow
-  // condition atoms and flow condition constraints. Something like:
-  // \code
-  //   FC1 <=> C1 ^ C2
-  //   FC2 <=> C2 ^ C3 ^ C4
-  //   FC3 <=> (FC1 v FC2) ^ C5
-  // \code
-  // Then, we can track dependencies between flow conditions (e.g. above `FC3`
-  // depends on `FC1` and `FC2`) and modify `flowConditionImplies` to construct
-  // a formula that includes the bi-conditionals for all flow condition atoms in
-  // the transitive set, before invoking the solver.
+  // in the respective path conditions.
   //
   // FIXME: Does not work for backedges, since the two (or more) paths will not
   // have mutually exclusive conditions.
   if (auto *Expr1 = dyn_cast(Val1)) {
-for (BoolValue *Constraint : Env1.getFlowConditionConstraints()) {
-  Expr1 = &MergedEnv.makeAnd(*Expr1, *Constraint);
-}
 auto *Expr2 = cast(Val2);
-for (BoolValue *Constraint : Env2.getFlowConditionConstraints()) {
-  Expr2 = &MergedEnv.makeAnd(*Expr2, *Constraint);
-}
-return &MergedEnv.makeOr(*Expr1, *Expr2);
+return &Env1.makeOr(Env1.makeAnd(Env1.getFlowConditionToken(), *Expr1),
+Env1.makeAnd(Env2.getFlowConditionToken(), *Expr2));
   }
 
   // FIXME: Consider destroying `MergedValue` im

[PATCH] D124384: [clang] Fix a constant evaluator crash on a NULL-type expr.

2022-04-26 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D124384#3471917 , @sammccall wrote:

> This is a reasonable immediate fix, but creating null-typed expressions that 
> live *outside* the recoveryexpr seems scary, and likely to violate expected 
> invariants elsewhere too...

Yeah, the fundamental issue is that we create a null-typed expression 
(`ParenListExpr`) outside a template context, which is similar to our prior 
case where we have a dependent expression outside a template context. Perhaps 
it violates invariants in other places as well, but this is the first time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124384

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


[PATCH] D118996: [clang-tidy] Support C++14 in bugprone-signal-handler.

2022-04-26 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

After adding improvements to the documentation, I think this will be good to 
go, and thank you! Perhaps just for a safety measure you could run it on a few 
projects (LLVM itself?) to ensure we didn't miss a case where it might 
magically crash, but I wonder how many specifically "C++14" projects will use 
signal handlers in the first place.




Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:328
 const LangOptions &LangOpts) const {
-  // FIXME: Make the checker useful on C++ code.
-  if (LangOpts.CPlusPlus)
-return false;
-
-  return true;
+  return LangOpts.CPlusPlus17 == 0;
 }

Aren't these `bool`s?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118996

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


[PATCH] D123436: [Clang] Use std::move in GlobalModuleIndex::readIndex. NFC

2022-04-26 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436

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


[PATCH] D124395: [clang][dataflow] Optimize flow condition representation

2022-04-26 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev marked an inline comment as done.
sgatev added a comment.

In D124395#3472974 , @xazax.hun wrote:

> Nice! Did you do some measurements? Does this improve the performance or 
> decrease the memory consumption?

I didn't do any measurements :( I implemented this as I'd like to add 
context-aware join (what we do for booleans, preserving flow condition context) 
to `UncheckedOptionalAccessModel` and don't really want to make the current 
approach a pattern. I suspect this could also be useful when modeling other 
language constructs.




Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:160
+  void addFlowConditionConstraint(AtomicBoolValue &Token,
+  BoolValue &Constraint);
+

xazax.hun wrote:
> Could this be const?
I think no because we need to pass it to `getOrCreateDisjunctionValue` and 
`getOrCreateNegationValue`, and their sub-values are not `const` currently.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:213
+  //
+  // Flow conditions can depend on other flow conditions (constraints can refer
+  // to flow condition tokens). The graph of flow condition dependencies is

xazax.hun wrote:
> I think an example would be nice what "depending on" a flow condition means. 
> A simplistic example with a nested if would probably be the easiest to 
> understand.
> 
I didn't add an example, but I rephrased this section after adding the 
`forkFlowCondition` and `joinFlowConditions` methods. Let me know what you 
think.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:184-185
+  FlowConditionToken = &DACtx->makeFlowConditionToken();
+  DACtx->addFlowConditionDependency(*FlowConditionToken,
+*Other.FlowConditionToken);
+  DACtx->addFlowConditionConstraint(*FlowConditionToken,

xazax.hun wrote:
> Do we ever expect to call these functions independently of each other? If no, 
> maybe `addFlowConditionDependency` should add the constraint as well.
I added `forkFlowCondition` and `joinFlowConditions` methods so dependencies 
are an implementation detail now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124395

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


[PATCH] D123783: [clang] Eliminate TypeProcessingState::trivial.

2022-04-26 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 425145.
mboehme marked an inline comment as done.
mboehme added a comment.

Eliminate hasSavedAttrs as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123783

Files:
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -166,12 +166,6 @@
 /// DeclSpec.
 unsigned chunkIndex;
 
-/// Whether there are non-trivial modifications to the decl spec.
-bool trivial;
-
-/// Whether we saved the attributes in the decl spec.
-bool hasSavedAttrs;
-
 /// The original set of attributes on the DeclSpec.
 SmallVector savedAttrs;
 
@@ -200,8 +194,7 @@
   public:
 TypeProcessingState(Sema &sema, Declarator &declarator)
 : sema(sema), declarator(declarator),
-  chunkIndex(declarator.getNumTypeObjects()), trivial(true),
-  hasSavedAttrs(false), parsedNoDeref(false) {}
+  chunkIndex(declarator.getNumTypeObjects()), parsedNoDeref(false) {}
 
 Sema &getSema() const {
   return sema;
@@ -233,13 +226,12 @@
 /// Save the current set of attributes on the DeclSpec.
 void saveDeclSpecAttrs() {
   // Don't try to save them multiple times.
-  if (hasSavedAttrs) return;
+  if (!savedAttrs.empty())
+return;
 
   DeclSpec &spec = getMutableDeclSpec();
   llvm::append_range(savedAttrs,
  llvm::make_pointer_range(spec.getAttributes()));
-  trivial &= savedAttrs.empty();
-  hasSavedAttrs = true;
 }
 
 /// Record that we had nowhere to put the given type attribute.
@@ -330,23 +322,18 @@
 bool didParseNoDeref() const { return parsedNoDeref; }
 
 ~TypeProcessingState() {
-  if (trivial) return;
+  if (savedAttrs.empty())
+return;
 
-  restoreDeclSpecAttrs();
+  getMutableDeclSpec().getAttributes().clearListOnly();
+  for (ParsedAttr *AL : savedAttrs)
+getMutableDeclSpec().getAttributes().addAtEnd(AL);
 }
 
   private:
 DeclSpec &getMutableDeclSpec() const {
   return const_cast(declarator.getDeclSpec());
 }
-
-void restoreDeclSpecAttrs() {
-  assert(hasSavedAttrs);
-
-  getMutableDeclSpec().getAttributes().clearListOnly();
-  for (ParsedAttr *AL : savedAttrs)
-getMutableDeclSpec().getAttributes().addAtEnd(AL);
-}
   };
 } // end anonymous namespace
 


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -166,12 +166,6 @@
 /// DeclSpec.
 unsigned chunkIndex;
 
-/// Whether there are non-trivial modifications to the decl spec.
-bool trivial;
-
-/// Whether we saved the attributes in the decl spec.
-bool hasSavedAttrs;
-
 /// The original set of attributes on the DeclSpec.
 SmallVector savedAttrs;
 
@@ -200,8 +194,7 @@
   public:
 TypeProcessingState(Sema &sema, Declarator &declarator)
 : sema(sema), declarator(declarator),
-  chunkIndex(declarator.getNumTypeObjects()), trivial(true),
-  hasSavedAttrs(false), parsedNoDeref(false) {}
+  chunkIndex(declarator.getNumTypeObjects()), parsedNoDeref(false) {}
 
 Sema &getSema() const {
   return sema;
@@ -233,13 +226,12 @@
 /// Save the current set of attributes on the DeclSpec.
 void saveDeclSpecAttrs() {
   // Don't try to save them multiple times.
-  if (hasSavedAttrs) return;
+  if (!savedAttrs.empty())
+return;
 
   DeclSpec &spec = getMutableDeclSpec();
   llvm::append_range(savedAttrs,
  llvm::make_pointer_range(spec.getAttributes()));
-  trivial &= savedAttrs.empty();
-  hasSavedAttrs = true;
 }
 
 /// Record that we had nowhere to put the given type attribute.
@@ -330,23 +322,18 @@
 bool didParseNoDeref() const { return parsedNoDeref; }
 
 ~TypeProcessingState() {
-  if (trivial) return;
+  if (savedAttrs.empty())
+return;
 
-  restoreDeclSpecAttrs();
+  getMutableDeclSpec().getAttributes().clearListOnly();
+  for (ParsedAttr *AL : savedAttrs)
+getMutableDeclSpec().getAttributes().addAtEnd(AL);
 }
 
   private:
 DeclSpec &getMutableDeclSpec() const {
   return const_cast(declarator.getDeclSpec());
 }
-
-void restoreDeclSpecAttrs() {
-  assert(hasSavedAttrs);
-
-  getMutableDeclSpec().getAttributes().clearListOnly();
-  for (ParsedAttr *AL : savedAttrs)
-getMutableDeclSpec().getAttributes().addAtEnd(AL);
-}
   };
 } // end anonymous namespace
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124420: [Serialization] Compress serialized macro expansion SLocEntries

2022-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/lib/Serialization/ASTWriter.cpp:2181
+  // Common cases are covered by abbreviations.
+  unsigned Abbrev = [&]() -> unsigned {
+if (!Expansion.isExpansionTokenRange()) // Token splits.

NIT: maybe avoid the lambda? The code is short enough to be readable without 
early returns:
```
unsigned Abbrev = 0;
if (Expansion.isExpansionTokenRange()) {
  if (Expansion.isMacroArgExpansion())
Abbrev = SLocArgExpansionAbbrv;
  else if (EndIsRelative && Expansion.isFunctionMacroExpansion())
Abbrev = SLocFunctionExpansionAbbrv;
  else if (EndIsRelative)
Abbrev = SLocObjectExpansionAbbrv;
}
```



Comment at: clang/lib/Serialization/ASTWriter.cpp:2195
+  else
+Stream.EmitRecord(SM_SLOC_EXPANSION_ENTRY,
+  // To emit without abbrev, we must omit the code.

It's probably obvious, but I'm not an expert in bitcode format.

Can we have larger records now than before? Are any records emitted without 
abbreviations larger than with abbreviations?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124420

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


[PATCH] D123783: [clang] Eliminate TypeProcessingState::trivial.

2022-04-26 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked an inline comment as done.
mboehme added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:170
 /// Whether we saved the attributes in the decl spec.
 bool hasSavedAttrs;
 

aaron.ballman wrote:
> mboehme wrote:
> > aaron.ballman wrote:
> > > mboehme wrote:
> > > > aaron.ballman wrote:
> > > > > Isn't the same true for this variable? It seems like:
> > > > > 
> > > > > `trivial` == `savedAttrs.empty()`
> > > > > `hasSavedAttrs` == `!savedAttrs.empty()`
> > > > That's what I also thought at first -- but the situation for 
> > > > `hasSavedAttrs` is a bit more complicated. It gets set whenever 
> > > > `saveDeclAttrs()` is called, even if it doesn't actually end up saving 
> > > > any attributes (i.e. if `spec.getAttributes()` is empty).
> > > > 
> > > > `hasSavedAttrs` is then used to prevent any further calls to 
> > > > `saveDeclSpecAttrs()` from doing anything:
> > > > 
> > > > ```
> > > > // Don't try to save them multiple times.
> > > > if (hasSavedAttrs) return;
> > > > ```
> > > > 
> > > > Conceivably, `spec` _might_ have had attributes added to it in the 
> > > > meantime -- not sure? It might be OK to just replace this logic with 
> > > > `if (!savedAttrs.empty()) return;` -- but I'm not familiar enough with 
> > > > how this code gets used and therefore decided it would be better not to 
> > > > change it. Can you give additional input on this?
> > > I have the impression that is an oversight in the code rather than an 
> > > intentional behavior. I think it may be okay to replace the logic with 
> > > `!savedAttrs.empty()` as well; if you do that, do you get any test 
> > > failures? (If you do, then that's a sign something else might be going 
> > > on.)
> > I just tried:
> > 
> > ```
> > // Don't try to save them multiple times.
> > if (!savedAttrs.empty()) return;
> > ```
> > 
> >  I didn't get any test failures.
> > 
> > Of course, this isn't proof that this is _really_ OK, but it's an 
> > indication.
> > 
> > You know this code better than I do, so I would defer to you: How do you 
> > think I should proceed? Should I eliminate `hasSavedAttrs` too?
> I think you should eliminate it -- I don't think the behavior here was 
> intentional (based on what I can tell from the code).
OK -- done!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123783

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


[clang] d6f9000 - [clang] Fix a constant evaluator crash on a NULL-type expr.

2022-04-26 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-04-26T10:08:30+02:00
New Revision: d6f9000ecabeca5819f4f03d774548c7cbb1ff21

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

LOG: [clang] Fix a constant evaluator crash on a NULL-type expr.

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

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/recovery-expr-type.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 3ad44d5e2da80..70a1e0bbd91aa 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8631,7 +8631,7 @@ static bool evaluateLValueAsAllocSize(EvalInfo &Info, 
APValue::LValueBase Base,
 return false;
 
   const Expr *Init = VD->getAnyInitializer();
-  if (!Init)
+  if (!Init || Init->getType().isNull())
 return false;
 
   const Expr *E = Init->IgnoreParens();

diff  --git a/clang/test/SemaCXX/recovery-expr-type.cpp 
b/clang/test/SemaCXX/recovery-expr-type.cpp
index 94b275c9a362f..3db11466529e1 100644
--- a/clang/test/SemaCXX/recovery-expr-type.cpp
+++ b/clang/test/SemaCXX/recovery-expr-type.cpp
@@ -151,3 +151,13 @@ enum Circular { // expected-note {{not 
complete until the closing '}
 // Enumerators can be evaluated (they evaluate as zero, but we don't care).
 static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error 
{{static_assert failed}}
 }
+
+namespace test14 {
+extern "C" void *memset(void *, int b, unsigned long) {
+  int * const c(undef()); // expected-error {{undeclared identifier}}
+  // Verify we do not crash on evaluating *c whose initializer is a NULL-type 
ParenListExpr!
+  memset(c, 0, *c); // crash1
+
+  b = __builtin_object_size(c, 0); // crash2
+}
+}



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


[PATCH] D124384: [clang] Fix a constant evaluator crash on a NULL-type expr.

2022-04-26 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd6f9000ecabe: [clang] Fix a constant evaluator crash on a 
NULL-type expr. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124384

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -151,3 +151,13 @@
 // Enumerators can be evaluated (they evaluate as zero, but we don't care).
 static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error 
{{static_assert failed}}
 }
+
+namespace test14 {
+extern "C" void *memset(void *, int b, unsigned long) {
+  int * const c(undef()); // expected-error {{undeclared identifier}}
+  // Verify we do not crash on evaluating *c whose initializer is a NULL-type 
ParenListExpr!
+  memset(c, 0, *c); // crash1
+
+  b = __builtin_object_size(c, 0); // crash2
+}
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -8631,7 +8631,7 @@
 return false;
 
   const Expr *Init = VD->getAnyInitializer();
-  if (!Init)
+  if (!Init || Init->getType().isNull())
 return false;
 
   const Expr *E = Init->IgnoreParens();


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -151,3 +151,13 @@
 // Enumerators can be evaluated (they evaluate as zero, but we don't care).
 static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error {{static_assert failed}}
 }
+
+namespace test14 {
+extern "C" void *memset(void *, int b, unsigned long) {
+  int * const c(undef()); // expected-error {{undeclared identifier}}
+  // Verify we do not crash on evaluating *c whose initializer is a NULL-type ParenListExpr!
+  memset(c, 0, *c); // crash1
+
+  b = __builtin_object_size(c, 0); // crash2
+}
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -8631,7 +8631,7 @@
 return false;
 
   const Expr *Init = VD->getAnyInitializer();
-  if (!Init)
+  if (!Init || Init->getType().isNull())
 return false;
 
   const Expr *E = Init->IgnoreParens();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124427: [Serialization] Pack Expr ObjectKind and ValueKind into one VBR.

2022-04-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124427

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


[PATCH] D124422: [Serialization] Improve encoding of small SourceRanges.

2022-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

Overall LGTM, but I didn't look closely if there are cases that break now.
Do we have any tests to check this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124422

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


[clang] 218dcda - [Clang] Use std::move in GlobalModuleIndex::readIndex. NFC

2022-04-26 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-04-26T16:45:01+08:00
New Revision: 218dcdad8a0c0f3340a97dafa24456125fe9b4fb

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

LOG: [Clang] Use std::move in GlobalModuleIndex::readIndex. NFC

BitstreamCursors are heavy-weight objects that should not be passed by value.

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

Added: 


Modified: 
clang/lib/Serialization/GlobalModuleIndex.cpp

Removed: 




diff  --git a/clang/lib/Serialization/GlobalModuleIndex.cpp 
b/clang/lib/Serialization/GlobalModuleIndex.cpp
index 52ce17d984bf4..b2283c2b39877 100644
--- a/clang/lib/Serialization/GlobalModuleIndex.cpp
+++ b/clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -277,7 +277,7 @@ GlobalModuleIndex::readIndex(StringRef Path) {
   return std::make_pair(nullptr, Res.takeError());
   }
 
-  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), Cursor),
+  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), 
std::move(Cursor)),
 llvm::Error::success());
 }
 



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


[PATCH] D123436: [Clang] Use std::move in GlobalModuleIndex::readIndex. NFC

2022-04-26 Thread Jun Zhang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG218dcdad8a0c: [Clang] Use std::move in 
GlobalModuleIndex::readIndex. NFC (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436

Files:
  clang/lib/Serialization/GlobalModuleIndex.cpp


Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -277,7 +277,7 @@
   return std::make_pair(nullptr, Res.takeError());
   }
 
-  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), Cursor),
+  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), 
std::move(Cursor)),
 llvm::Error::success());
 }
 


Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -277,7 +277,7 @@
   return std::make_pair(nullptr, Res.takeError());
   }
 
-  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), Cursor),
+  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), std::move(Cursor)),
 llvm::Error::success());
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119544: Deferred Concept Instantiation Implementation

2022-04-26 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D119544#3472537 , @erichkeane 
wrote:

> Alright, a touch more:  It looks like the looping through the `CurContext` at 
> line 6084 finds the wrong thing in evaluating this `CXXMethodDecl`!  The 
> "broken" version has its CurContext as `bar` in the example above, the 
> "working" versions have `foo` or `foo2`.  Therefore the 2nd time through 
> the loop, those both end up on the `ClassTemplateSpecializationDecl`, but the 
> broken one finds the `isFileContext` version.
>
> So I don't know HOW to fix it, but it seems that the 
> `CheckFunctionConstraints` probably has to change the `CurContext`.  I 
> suspect the instantiation of the `WorkingRequires` does something like this 
> correctly.
>
> I'm poking on/off on it today, but if @ChuanqiXu has an idea/help, it would 
> be greatly appreciated.

Yeah, I also find the information looks in a mess. I spent some time to look at 
the bug (my workaround shows below) but it would make deferred-concept-inst.cpp 
fail... it would say `foo()` is not a member of `Test`... I don't have strong 
proves here. But I guess we might need to look at tree transformation for 
RequireExpr in `TreeTransform::TransformRequiresExpr`.




Comment at: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:2431-2439
+  //if (TrailingRequiresClause) {
+  //  Sema::CXXThisScopeRAII ThisScope(SemaRef, Record, 
D->getMethodQualifiers());
+  //  ExprResult Rebuilt =
+  //  SemaRef.RebuildExprInCurrentInstantiation(TrailingRequiresClause);
+  //  if (Rebuilt.isInvalid())
+  //return nullptr;
+  //  TrailingRequiresClause = Rebuilt.get();

The failing test case could be fixed by the above change. The change above is 
just a hack instead of a suggestion.
The rationale is that we need to record some information when we traverse the 
template decl. The bugs now looks like we forget to do something which would be 
done at the first time. And we meet in problems due to the missed information 
(we couldn't find the member in the class).



Comment at: clang/test/SemaTemplate/concepts.cpp:386-388
+  []()
+requires(constraint)
+  {}();

We might need more negative tests.
Now it would pass even if I write:
```
[]()
requires(false)
{}();
```


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

https://reviews.llvm.org/D119544

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


[PATCH] D124348: [1/2][RISCV]Add Intrinsics for B extension in Clang

2022-04-26 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

> And I want to know that do you have any documents about intrinsic of bitmanip 
> extension, like RISC-V Vector Extension Intrinsic Document.

No, we didn't a formal document for that, I expect we will have one once this 
finalized https://github.com/riscv-non-isa/riscv-c-api-doc/pull/25 ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124348

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


[PATCH] D123352: [analyzer] Add FixItHint to `nullability.NullReturnedFromNonnull` and `nullability.NullableReturnedFromNonnull`

2022-04-26 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

Regarding FixIts... FixIts are implemented in the "Diagnostic" library, which 
is non-specific to neither Clang-Tidy nor Sema whatsoever, they use the same 
infrastructure under the hood. Why the apply logic in CSA might do the same 
FixIt multiple times is beyond me, but I know that both 
`clang-apply-replacements` and `clang-tidy` go to length to ensure that in case 
multiple checkers report to the same location with potentially conflicting 
FixIts, then none gets applied, because applying all of them would result in 
ridiculously broken source code. They internally become an object in the 
`clang::tooling` namespace which is implemented as a core Clang library. The 
relevant entrypoint to this logic, at least in Clang-Tidy, should be this one: 
http://github.com/llvm/llvm-project/blob/8f9dd5e608c0ac201ab682ccc89ac3be2dfd0d29/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp#L115-L134

FixIts are very rudimentary under the hood. Essentially, they allow you to, in 
a file at a given position, delete `N` characters and insert `M` characters. 
Removal fixits only delete, insertion fixits only insert (duh), and just like 
in version control, a //modification// is a "removal" and an "insertion" 
grouped into one action...

If FixIts are so broken in CSA's infrastructure as @steakhal observed then it 
might very well be a good thing to hold off on them and fix the infrastructure 
first. Or at least remove the ability to auto-apply them. You don't **have to** 
apply the fixes, but you can always get the neat little green-coloured notes as 
to what could the user should insert.

In D123352#3463063 , @MosheBerman 
wrote:

> There's a DeadStore checker that does have some fixit code, which is where I 
> found the `FixItHint` class. I did notice it isn't used in too many other 
> places.



In D123352#3439390 , @steakhal wrote:

> For fixits, we should be confident that some property holds, but the static 
> analyzer might conclude erroneously that a given pointer is null resulting in 
> a **bad** fixit.

Dead stores and dead code are, for the most part, rather easy to reason about 
and not make dangerous fixits by their removal. (I'd go far enough to say the 
DeadStore checker should be a run-of-the-mill warning in Sema, and not some 
extra fluff only available in CSA...)

In D123352#3439649 , @MosheBerman 
wrote:

> Where can I learn more about this?  Would it be possible and 
> idiomatically/architecturally sounds to write a clang-tidy that processes 
> output from this checker?

Very unlikely. While Clang-Tidy can execute CSA checkers (because CSA is a 
library within Clang, but AFAIK calling CSA from Tidy doesn't handle things 
like CTU), Clang-Tidy does not contain **any** notion of dependency between 
checks and they are meant to be independent. Moreover, you would need to 
enforce a sequential execution by the user //across// binaries (not to mention 
the fact that the entire project needs to be parsed twice, which might not be a 
trivial cost!), which seems error-prone...

-

In general, why you are trying to achieve this with the static analyser? It 
looks to me as if what you want is to mechanically add an annotation to some 
types if they are in between specific macros / annotations. More specifically, 
the table that is in your original post doesn't seem to involve path-sensitive 
information. So could this be a purely (platform-specific?) Tidy check? Your 
test code also doesn't contain anything that seems to depend on path-sensitive 
information.

1. Where is this `NS_` annotation coming from? Is this a thing of a specific 
platform, or specific to your company's products?
2. If you are sure you will not depend on any path-sensitive symbolic execution 
information (which you currently appear you do not), and the answer to `1.` is 
meaningful enough to be useful for a wider community (that is, not just you or 
your company?), then I would suggest rewriting the whole thing within 
Clang-Tidy. Clang-Tidy works off of AST matchers directly. The nullability 
annotations are attributes, which are also AST nodes, so you can handle them 
similarly to matching types or Decls.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123352

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


[clang-tools-extra] 910fb5d - [pseudo] NFC, fix some code-style naming violations.

2022-04-26 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-04-26T10:50:50+02:00
New Revision: 910fb5d7e03afc0009638707f091e94fb63e2a5e

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

LOG: [pseudo] NFC, fix some code-style naming violations.

Added: 


Modified: 
clang-tools-extra/pseudo/lib/Lex.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/Lex.cpp 
b/clang-tools-extra/pseudo/lib/Lex.cpp
index 72eff3c12f25c..3a90b739f97c9 100644
--- a/clang-tools-extra/pseudo/lib/Lex.cpp
+++ b/clang-tools-extra/pseudo/lib/Lex.cpp
@@ -41,18 +41,18 @@ TokenStream lex(const std::string &Code, const 
clang::LangOptions &LangOpts) {
 
 // Update current line number and indentation from raw source code.
 unsigned NewLineStart = 0;
-for (unsigned i = LastOffset; i < Offset; ++i) {
-  if (Code[i] == '\n') {
-NewLineStart = i + 1;
+for (unsigned I = LastOffset; I < Offset; ++I) {
+  if (Code[I] == '\n') {
+NewLineStart = I + 1;
 ++Line;
   }
 }
 if (NewLineStart || !LastOffset) {
   Indent = 0;
-  for (char c : StringRef(Code).slice(NewLineStart, Offset)) {
-if (c == ' ')
+  for (char C : StringRef(Code).slice(NewLineStart, Offset)) {
+if (C == ' ')
   ++Indent;
-else if (c == '\t')
+else if (C == '\t')
   Indent += 8;
 else
   break;



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


[PATCH] D118996: [clang-tidy] Support C++14 in bugprone-signal-handler.

2022-04-26 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:453
+diag(CallOrRef->getBeginLoc(),
+ "functions with other than C linkage are not allowed as signal "
+ "handler (until C++17)");

s/with other than/without



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:472
+StringRef Name = FoundS->getStmtClassName();
+if (Name.startswith("CXX")) {
+  SourceRange R = getSourceRangeOfStmt(FoundS, Ctx);

This just feels very hacky and it's non exhaustive, would lambda for a start as 
that isn't prefixed internally with CXX.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:126
 const LangOptions &LangOpts) const {
-  // FIXME: Make the checker useful on C++ code.
-  if (LangOpts.CPlusPlus)
+  if (LangOpts.CPlusPlus17)
 return false;

Is this check valid on Objective-C code?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118996

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


[PATCH] D123898: Fix crash in ObjC codegen introduced with 5ab6ee75994d645725264e757d67bbb1c96fb2b6

2022-04-26 Thread Frederik Seiffert via Phabricator via cfe-commits
triplef accepted this revision.
triplef added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM!

I tested these changes with our app’s code base, which was triggering the bug 
in a couple of places, and it all builds fine with the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123898

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


[PATCH] D124256: [OpenCL] Add cl_khr_subgroup_rotate builtins

2022-04-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! I imagine tablegen side is being tested automatically?

Btw do we need to set the feature macro for SPIR/SPIR-V target and then test it 
too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124256

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


[PATCH] D123498: [clang] Adding Platform/Architecture Specific Resource Header Installation Targets

2022-04-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/Headers/CMakeLists.txt:367
+add_header_target("mips-resource-headers")
+add_header_target("opencl-resource-headers")
+add_header_target("ppc-resource-headers")

I feel that the above comment doesn't apply here:
`# Architecture/platform specific targets`

This header is not a target or platform specific so I don't imagine it can ever 
be optional unless we start modularization of the language support in clang 
parsing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123498

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


[PATCH] D124441: [Index] [clangd] Support for concept declarations and requires expressions

2022-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
ilya-biryukov requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added projects: clang, clang-tools-extra.

Add support for concepts and requires expression in the clang index.
Genarate USRs for concepts.

Also how `RecursiveASTVisitor` handles return type requirement in
requires expressions. The new code unpacks the synthetic template parameter
list used for storing the actual expression. This simplifies
implementation of the indexing. No code seems to depend on the original
traversal anyway and the synthesized template parameter list is easily
accessible from inside the requires expression if needed.

Add tests in the clangd codebase.

Fixes https://github.com/clangd/clangd/issues/1103.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124441

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Quality.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang-tools-extra/clangd/unittests/TestIndex.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Index/IndexSymbol.h
  clang/lib/Index/IndexBody.cpp
  clang/lib/Index/IndexDecl.cpp
  clang/lib/Index/IndexSymbol.cpp
  clang/lib/Index/IndexTypeSourceInfo.cpp
  clang/lib/Index/IndexingContext.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/tools/libclang/CXIndexDataConsumer.cpp

Index: clang/tools/libclang/CXIndexDataConsumer.cpp
===
--- clang/tools/libclang/CXIndexDataConsumer.cpp
+++ clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -1247,6 +1247,7 @@
   case SymbolKind::TemplateTypeParm:
   case SymbolKind::TemplateTemplateParm:
   case SymbolKind::NonTypeTemplateParm:
+  case SymbolKind::Concept:
 return CXIdxEntity_Unexposed;
 
   case SymbolKind::Enum: return CXIdxEntity_Enum;
Index: clang/lib/Index/USRGeneration.cpp
===
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -103,6 +103,7 @@
   void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
   void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
   void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
+  void VisitConceptDecl(const ConceptDecl *D);
 
   void VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
 IgnoreResults = true; // No USRs for linkage specs themselves.
@@ -1007,7 +1008,13 @@
   Out << D->getName(); // Simple name.
 }
 
-
+void USRGenerator::VisitConceptDecl(const ConceptDecl *D) {
+  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
+return;
+  VisitDeclContext(D->getDeclContext());
+  Out << "@CT@";
+  EmitDeclName(D);
+}
 
 //===--===//
 // USR generation functions.
Index: clang/lib/Index/IndexingContext.cpp
===
--- clang/lib/Index/IndexingContext.cpp
+++ clang/lib/Index/IndexingContext.cpp
@@ -86,7 +86,6 @@
isa(D))) {
 return true;
   }
-
   return handleDeclOccurrence(D, Loc, /*IsRef=*/true, Parent, Roles, Relations,
   RefE, RefD, DC);
 }
@@ -264,7 +263,8 @@
   isa(D) ||
   isa(D) ||
   isa(D) ||
-  isa(D))
+  isa(D) ||
+  isa(D))
 return true;
 
   return false;
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -7,7 +7,10 @@
 //===--===//
 
 #include "IndexingContext.h"
+#include "clang/AST/ASTConcept.h"
+#include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TypeLoc.h"
 #include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
@@ -77,6 +80,13 @@
 return true;
   }
 
+  bool VisitAutoTypeLoc(AutoTypeLoc TL) {
+if (auto *C = TL.getNamedConcept())
+  return IndexCtx.handleReference(C, TL.getConceptNameLoc(), Parent,
+  ParentDC);
+return true;
+  }
+
   bool traverseParamVarHelper(ParmVarDecl *D) {
 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
 if (D->getTypeSourceInfo())
Index: clang/lib/Index/IndexSymbol.cpp
===
--- clang/lib/Index/IndexSymbol.cpp
+++ clang/lib/Index/IndexSymbol.cpp
@@ -371,6 +371,9 @@
 case Decl

[PATCH] D124422: [Serialization] Improve encoding of small SourceRanges.

2022-04-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D124422#3474003 , @ilya-biryukov 
wrote:

> Overall LGTM, but I didn't look closely if there are cases that break now.
> Do we have any tests to check this?

Serialization tests do exist, though I think coverage isn't amazing.
I'd have a reasonable level of confidence through:

- the fact that I made the changes systematically rather than finding them 
through test failures
- I'll go through and audit all the changes myself again (the failures I did 
have after finishing this were mostly typos)
- using it locally for a while (though this will only cover usual C++ nodes)

---

There is a limited & self-defeating nature of this patch.
To have a clear idiom, we only encode SourceRange when begin/end pair are 
directly stored.
Not all SourceLocations are paired, e.g. ForStmt has [KW, LParen, RParen] and 
we benefit from delta-encoding only once.
In the most common types of nodes, there tends to be more complexity around 
exactly which SourceLocations need to be stored for size reasons. (Probably 
size of memory representation, but this is 1:1 with serialized). So I suspect 
the opportunities missed are disproportionately valuable as well.

Before landing this, I'd like to try an approach of compressing all 
SourceLocations within a record as a sequence.
Something with a state machine like:

- at the start of each record, Current = 0
- for each Loc:
  - if Loc is far from current, encode as 33-bit integer Loc<<1 | 1
  - if Loc is close to current, encode as abs(Loc) << 2 | sign(Loc) << 1 | 0
  - if Loc is nonzero, Current = Loc

This would guarantee efficient representations of nearby and null 
sourcelocations, while regressing random locations by 1 bit only.

This can be done explicitly with an API like: `SrcLocSeq Locs(Stream); 
Locs.Add(Loc1); Locs.Add(Loc2);`, or implicitly by changing the behavior of 
AddSourceLocation. The latter seems easier to try, and would require more 
machinery but fewer local changes than this patch.

Let me try to put something together to see what the gains are...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124422

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


[PATCH] D124091: [clang][AArch64][SVE] Implement conditional operator for SVE vectors

2022-04-26 Thread Peter Waller via Phabricator via cfe-commits
peterwaller-arm added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:6266
+LHS = ImpCastExprToType(LHS.get(), ResultType, CK_VectorSplat);
+RHS = ImpCastExprToType(RHS.get(), ResultType, CK_VectorSplat);
+  }

I get an assert with the following input (float64 in, float32 out). I was lead 
here by noticing that the element count comes from `CondElementCount`, but 
nothing ensures that the numbers of elements are consistent with LHS or RHS.

```
svfloat32_t cond_f32_splat(svfloat64_t a) {
return a < 0. ? 1.f : 0.f;
}
```

```
#11 0x01fef77e clang::ASTContext::getCanonicalType(clang::QualType) 
const CodeGenTypes.cpp:0:0
#12 0x0446b39c clang::Sema::ImpCastExprToType(clang::Expr*, 
clang::QualType, clang::CastKind, clang::ExprValueKind, 
llvm::SmallVector const*, clang::Sema::CheckedCo
nversionKind) (out/rel/bin/clang+0x446b39c)
#13 0x048ca1ce 
clang::Sema::CheckSizelessVectorConditionalTypes(clang::ActionResult&, clang::ActionResult&, 
clang::ActionResult&, clan
g::SourceLocation) (out/rel/bin/clang+0x48ca1ce)
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124091

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


[PATCH] D124442: [analyzer] Allow exploded graph dumps in release builds

2022-04-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, martong, Szelethus, ASDenysPetrov.
Herald added subscribers: manas, pengfei, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Historically, exploded graph dumps were disabled in non-debug builds.
It was done so probably because a regular user should not dump the
internal representation of the analyzer anyway and the dump methods
might introduce unnecessary binary size overhead.

It turns out some of the users actually want to dump this.

Note that e.g. `LiveExpressionsDumper`, `LiveVariablesDumper`,
`ControlDependencyTreeDumper` etc. worked previously, and they are
unaffected by this change.
However, `CFGViewer` and `CFGDumper` still won't work for a similar
reason. AFAIK only these two won't work after this change.

Addresses #53873

---

**baseline**

| binary | size | size after strip |
| clang  | 103M | 83M  |
| clang-tidy | 67M  | 54M  |
|

**after this change**

| binary | size | size after strip |
| clang  | 103M | 84M  |
| clang-tidy | 67M  | 54M  |
|

CMake configuration:

  cmake -S llvm -GNinja -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release
  -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
  -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_USE_LINKER=lld
  -DLLVM_ENABLE_DUMP=OFF -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra"
  -DLLVM_ENABLE_Z3_SOLVER=ON -DLLVM_TARGETS_TO_BUILD="X86"

Built by `clang-14.0.0`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124442

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/Analysis/dump_egraph.c
  clang/test/Analysis/dump_egraph.cpp
  clang/test/Analysis/exploded-graph-rewriter/dynamic_types.cpp
  clang/test/Analysis/exploded-graph-rewriter/escapes.c
  
clang/test/Analysis/exploded-graph-rewriter/initializers_under_construction.cpp
  clang/test/Analysis/exploded-graph-rewriter/l_name_starts_with_l.cpp
  clang/test/Analysis/exploded-graph-rewriter/macros.c
  clang/test/Analysis/exploded-graph-rewriter/objects_under_construction.cpp
  clang/test/Analysis/exploded-graph-rewriter/win_path_forbidden_chars.cpp

Index: clang/test/Analysis/exploded-graph-rewriter/win_path_forbidden_chars.cpp
===
--- clang/test/Analysis/exploded-graph-rewriter/win_path_forbidden_chars.cpp
+++ clang/test/Analysis/exploded-graph-rewriter/win_path_forbidden_chars.cpp
@@ -3,7 +3,6 @@
 // RUN: -analyzer-checker=core \
 // RUN: -analyzer-dump-egraph=%t.dot %s
 // RUN: %exploded_graph_rewriter --verbose %t.dot 2>&1 | FileCheck %s
-// REQUIRES: asserts
 // UNSUPPORTED: !windows
 
 // Angle brackets shall not be presented in the field `file`,
Index: clang/test/Analysis/exploded-graph-rewriter/objects_under_construction.cpp
===
--- clang/test/Analysis/exploded-graph-rewriter/objects_under_construction.cpp
+++ clang/test/Analysis/exploded-graph-rewriter/objects_under_construction.cpp
@@ -4,7 +4,6 @@
 // RUN: -analyzer-checker=core \
 // RUN: -analyzer-dump-egraph=%t.dot %s
 // RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
-// REQUIRES: asserts
 
 struct S {
   S() {}
Index: clang/test/Analysis/exploded-graph-rewriter/macros.c
===
--- clang/test/Analysis/exploded-graph-rewriter/macros.c
+++ clang/test/Analysis/exploded-graph-rewriter/macros.c
@@ -11,7 +11,6 @@
 // RUN: -analyzer-checker=core \
 // RUN: -analyzer-dump-egraph=%t.dot %s
 // RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
-// REQUIRES: asserts
 
 // CHECK: macros.c:3:10
 // CHECK-SAME: 
Index: clang/test/Analysis/exploded-graph-rewriter/l_name_starts_with_l.cpp
===
--- clang/test/Analysis/exploded-graph-rewriter/l_name_starts_with_l.cpp
+++ clang/test/Analysis/exploded-graph-rewriter/l_name_starts_with_l.cpp
@@ -4,7 +4,6 @@
 // RUN: -analyzer-checker=core \
 // RUN: -analyzer-dump-egraph=%t.dot %s
 // RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
-// REQUIRES: asserts
 
 void test1() {
   // Here __FILE__ macros produces a string with `\` delimiters on Windows
Index: clang/test/Analysis/exploded-graph-rewriter/initializers_under_construction.cpp
===
--- clang/test/Analysis/exploded-graph-rewriter/initializers_under_construction.cpp
+++ clang/test/Analysis/exploded-graph-rewriter/initializers_under_construction.cpp
@@ -3,7 +3,6 @@
 // RUN: -analyzer-checker=core \
 // RUN:

[PATCH] D123065: [clang-tidy] support --load in clang-tidy-diff.py/run-clang-tidy.py

2022-04-26 Thread Bernhard Manfred Gruber via Phabricator via cfe-commits
bernhardmgruber added a comment.

Ping.

Can someone merge this please for me? Thank you!


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

https://reviews.llvm.org/D123065

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


[PATCH] D124422: [Serialization] Improve encoding of small SourceRanges.

2022-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Yeah, that sounds promising. Various source locations inside the same nodes are 
probably very close. Probably even across nodes.
If we are willing to take on a bit more complexity, we could probably get even 
bigger wins by storing all source locations in a single array  having indices 
into that array in the actual positions where we need the source locations. 
That way we can have:

- get the benefits of delta-encoding in the source locations array, probably 
even across nodes,
- probably still get quite good encoding for indices inside this array inside 
the actual AST nodes. Will definitely get those if we delta-encode the indices 
inside the same node.

I suspect there are requirements that will force us to store the array in 
chunks and allow searching for a particular chunk.

However, that's really adding quite a bit of complexity and I'm not sure 
preamble sizes are such a big deal outside our environment. E.g. even 10% 
savings are borderline for that kind of complexity.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124422

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


[PATCH] D124441: [Index] [clangd] Support for concept declarations and requires expressions

2022-04-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

This looks great!

Only thing I'm uncomfortable with is the lack of test coverage outside clangd.
I think the most valuable thing would be to have some direct testing of how 
RecursiveASTVisitor behaves.
Do you think you could add something to 
`unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp` at least for your 
change and if there are any other bits that seem critical & missing?




Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:3577
+template
+concept b = $expr^A && $expr^sizeof(T) % 2 == 0 || $expr^A && 
sizeof(T) == 1;
+  )cpp");

maybe also a constrained auto usage?



Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:3584
+  std::vector Syms = {conceptSym("same_as")};
+  for (auto P : Code.points("tparam")) {
+ASSERT_THAT(completions(TU, P, Syms).Completions,

I think it'd be useful to assert the presence/absence of template 
brackets/placeholders here, even if the behavior is not ideal today (in which 
case, comment to that effect).

Similarly it's probably worth having a concept B with two type params as these 
are different cases for template brackets when used as type (even if the 
behavior is the same)



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:1851
+void checkFindRefs(llvm::StringRef Test, bool UseIndex = false,
+   std::vector ExtraArgs = {}) {
   Annotations T(Test);

nit: does anything break if we just set c++20 unconditionally?



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:2080
+
+[[IsSmall]] auto i = 8;
+template<[[IsSmal^l]] U> void foo();

maybe `= 'c'` and use `char` below? Don't make me think :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124441

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


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-04-26 Thread Kan Shengchen via Phabricator via cfe-commits
skan added a comment.

Should we update the `clang/docs/ReleaseNotes.rst` for this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

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


[PATCH] D118409: [OpenMPIRBuilder] Remove ContinuationBB argument from Body callback.

2022-04-26 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan accepted this revision.
kiranchandramohan added a comment.
This revision is now accepted and ready to land.

LGTM. You may wait for a day in case there are comments from other reviewers.

I think the CI is complaining about some clang-format issue in  
clang/test/OpenMP/critical_codegen_attr.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118409

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


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-04-26 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added a comment.

In D124435#3474130 , @skan wrote:

> Should we update the `clang/docs/ReleaseNotes.rst` for this?

Maybe? I will update it in the next patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

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


[PATCH] D124443: [analyzer] Allow CFG dumps in release builds

2022-04-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, martong, Szelethus, ASDenysPetrov.
Herald added subscribers: manas, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a similar commit to D124442 , but for 
CFG dumps.
The binary size diff remained the same demonstrated in that patch.

This time I'm adding tests for demonstrating that all the dump debug
checkers work - even in regular builds without asserts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124443

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/debug-checkers.cpp


Index: clang/test/Analysis/debug-checkers.cpp
===
--- /dev/null
+++ clang/test/Analysis/debug-checkers.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpDominators %s > %t 
2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=DOM-CHECK
+// DOM-CHECK: Immediate dominance tree (Node#,IDom#)
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpPostDominators %s 
> %t 2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=POSTDOM-CHECK
+// POSTDOM-CHECK: Immediate post dominance tree (Node#,IDom#)
+
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,debug.DumpControlDependencies %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=CTRLDEPS-CHECK
+// CTRLDEPS-CHECK: Control dependencies (Node#,Dependency#)
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpLiveVars %s > %t 
2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=LIVE-VARS-CHECK
+// LIVE-VARS-CHECK: live variables at block exit
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpLiveExprs %s > %t 
2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=LIVE-EXPRS-CHECK
+// LIVE-EXPRS-CHECK: live expressions at block exit
+
+// Skip testing CFGViewer.
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpCFG %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=CFG-CHECK
+// CFG-CHECK: ENTRY
+
+// Skip testing CallGraphViewer.
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpCallGraph %s > %t 
2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=CALL-GRAPH-CHECK
+// CALL-GRAPH-CHECK: --- Call graph Dump ---
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ConfigDumper %s > %t 
2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=CONFIG-CHECK
+// CONFIG-CHECK: [config]
+
+// Skip testing ExplodedGraphViewer.
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ReportStmts %s > %t 
2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=REPORT-STMTS-CHECK
+// REPORT-STMTS-CHECK: warning: Statement
+
+void foo(int *p) {
+  *p = 3;
+}
+
+int bar() {
+  int x;
+  foo(&x);
+  return x;
+}
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -6127,17 +6127,13 @@
 // CFG Graphviz Visualization
 
//===--===//
 
-#ifndef NDEBUG
-static StmtPrinterHelper* GraphHelper;
-#endif
+static StmtPrinterHelper *GraphHelper;
 
 void CFG::viewCFG(const LangOptions &LO) const {
-#ifndef NDEBUG
   StmtPrinterHelper H(this, LO);
   GraphHelper = &H;
   llvm::ViewGraph(this,"CFG");
   GraphHelper = nullptr;
-#endif
 }
 
 namespace llvm {
@@ -6146,8 +6142,7 @@
 struct DOTGraphTraits : public DefaultDOTGraphTraits {
   DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
 
-  static std::string getNodeLabel(const CFGBlock *Node, const CFG* Graph) {
-#ifndef NDEBUG
+  static std::string getNodeLabel(const CFGBlock *Node, const CFG *Graph) {
 std::string OutSStr;
 llvm::raw_string_ostream Out(OutSStr);
 print_block(Out,Graph, *Node, *GraphHelper, false, false);
@@ -6163,9 +6158,6 @@
   }
 
 return OutStr;
-#else
-return {};
-#endif
   }
 };
 


Index: clang/test/Analysis/debug-checkers.cpp
===
--- /dev/null
+++ clang/test/Analysis/debug-checkers.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpDominators %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=DOM-CHECK
+// DOM-CHECK: Immediate dominance tree (Node#,IDom#)
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpPostDominators %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=POSTDOM-CHECK
+// POSTDOM-CHECK: Immediate post dominance tree (Node#,IDom#)
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.DumpControlDependencies %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s -check-prefix=CTRLDEPS-CHECK
+// CTRLDEPS-CHECK: Control dependencies (Node#,D

[PATCH] D124441: [Index] [clangd] Support for concept declarations and requires expressions

2022-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D124441#3474123 , @sammccall wrote:

> This looks great!
>
> Only thing I'm uncomfortable with is the lack of test coverage outside clangd.
> I think the most valuable thing would be to have some direct testing of how 
> RecursiveASTVisitor behaves.

Just to be clear, I feel it is not `RecursiveASTVisitor` that's at fault here. 
It's rather design of the Index library that splits work into multiple visitors.
Requires expression is produces a template parameter list that suddenly appears 
out of nowhere in the `BodyVisitor`, whereas the code to handle it is in the 
`DeclVisitor`.

> Do you think you could add something to 
> `unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp` at least for your 
> change and if there are any other bits that seem critical & missing?

I actually think neither way to do the traversal works in all cases, so I'm 
reluctant to add a test, which feels like picking which behavior is better.
The change I have avoids code duplication in the index library and is probably 
more convenient for source tooling in general.
However, any code that needs to examine all elements of the AST for whatever 
reason (e.g. dumps or serialization) would probably be better off walking the 
synthesized template parameter list.
The idea is: it's not important how exactly we traverse the nodes there as long 
as all interested visitors get callbacks for nodes they're looking into.

The proper refactoring here would be to add `Traverse` and `Visit`  methods for 
`concept::Requirement` and one for `ExprRequirement::ReturnRequirement`. 
Overriding `VisitReturnRequirement` in `BodyVisitor` would be enough and we can 
still visit the template parameter list like before.
I'd like to do this in a separate change, would that work for you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124441

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


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-04-26 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/docs/ClangCommandLineReference.rst:2988-2992
+.. option:: -mconservative-extend
+Always extend the integer parameter both in the callee and caller.
+
+.. option:: -mno-conservative-extend
+Keep the original integer parameter passing behavior.

Combine like others?



Comment at: clang/include/clang/CodeGen/CGFunctionInfo.h:202-205
+if (Ty->hasSignedIntegerRepresentation())
+  AI.setSignExt(true);
+else
+  AI.setSignExt(false);

`AI.setSignExt(Ty->hasSignedIntegerRepresentation())` for short?
Or we can remove the else block since `SignExt` is initialized to `false`?



Comment at: clang/include/clang/CodeGen/CGFunctionInfo.h:333
   bool canHaveCoerceToType() const {
-return isDirect() || isExtend() || isCoerceAndExpand();
+return isDirect() || isExtend() || isCoerceAndExpand() ||
+   isConservativeExtend();

Can we move it to `isExtend`? e.g. `TheKind == Expand | TheKind == 
ConservativeExtend`



Comment at: clang/lib/CodeGen/CGCall.cpp:2451
+  // attribute to the callee.
+  if (AttrOnCallSite || AI.getKind() == ABIArgInfo::Extend) {
+if (AI.isSignExt())

Does the change affect Windows? Seems Win64 doesn't extend on caller. 
https://godbolt.org/z/c95hvvsWf



Comment at: clang/test/CodeGen/X86/integer_argument_passing.c:2
+// RUN: %clang_cc1 -O2 -triple -x86_64-linux-gnu %s -emit-llvm -o - | 
FileCheck %s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-linux-gnu %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-pc-win32 %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=EXTEND,CHECK

Maybe we can remove the tests for i386 given it's only for 64 bits ABI?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

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


[PATCH] D123924: [clang-apply-replacements] Added an option to ignore insert conflict.

2022-04-26 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 425166.
Sockke added a comment.

Rename the function.


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

https://reviews.llvm.org/D123924

Files:
  
clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
  clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
  clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
  clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
  
clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/file1.yaml
  
clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/ignore-conflict.cpp
  clang-tools-extra/test/clang-apply-replacements/ignore-conflict.cpp
  clang/include/clang/Tooling/Refactoring/AtomicChange.h

Index: clang/include/clang/Tooling/Refactoring/AtomicChange.h
===
--- clang/include/clang/Tooling/Refactoring/AtomicChange.h
+++ clang/include/clang/Tooling/Refactoring/AtomicChange.h
@@ -116,6 +116,8 @@
   /// Returns a const reference to existing replacements.
   const Replacements &getReplacements() const { return Replaces; }
 
+  Replacements &getReplacements() { return Replaces; }
+
   llvm::ArrayRef getInsertedHeaders() const {
 return InsertedHeaders;
   }
Index: clang-tools-extra/test/clang-apply-replacements/ignore-conflict.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/ignore-conflict.cpp
@@ -0,0 +1,5 @@
+// RUN: mkdir -p %T/Inputs/ignore-conflict
+// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/ignore-conflict/ignore-conflict.cpp > %T/Inputs/ignore-conflict/ignore-conflict.cpp
+// RUN: sed "s#\$(path)#%/T/Inputs/ignore-conflict#" %S/Inputs/ignore-conflict/file1.yaml > %T/Inputs/ignore-conflict/file1.yaml
+// RUN: clang-apply-replacements --ignore-insert-conflict %T/Inputs/ignore-conflict
+// RUN: FileCheck -input-file=%T/Inputs/ignore-conflict/ignore-conflict.cpp %S/Inputs/ignore-conflict/ignore-conflict.cpp
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/ignore-conflict.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/ignore-conflict.cpp
@@ -0,0 +1,4 @@
+class MyType {};
+// CHECK: #include 
+// CHECK-NEXT: #include 
+// CEHCK-NEXT: class MyType {};
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/file1.yaml
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/ignore-conflict/file1.yaml
@@ -0,0 +1,24 @@
+---
+MainSourceFile: ignore-conflict.cpp
+Diagnostics:
+  - DiagnosticName: test-ignore-conflict-insertion
+DiagnosticMessage:
+  Message: Fix
+  FilePath: $(path)/ignore-conflict.cpp
+  FileOffset: 0
+  Replacements:
+- FilePath:$(path)/ignore-conflict.cpp
+  Offset:  0
+  Length:  0
+  ReplacementText: "#include \n"
+  - DiagnosticName: test-ignore-conflict-insertion
+DiagnosticMessage:
+  Message: Fix
+  FilePath: $(path)/ignore-conflict.cpp
+  FileOffset: 0
+  Replacements:
+- FilePath:$(path)/ignore-conflict.cpp
+  Offset:  0
+  Length:  0
+  ReplacementText: "#include \n"
+...
Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -178,6 +178,7 @@
 def apply_fixes(args, clang_apply_replacements_binary, tmpdir):
   """Calls clang-apply-fixes on a given directory."""
   invocation = [clang_apply_replacements_binary]
+  invocation.append('-ignore-insert-conflict')
   if args.format:
 invocation.append('-format')
   if args.style:
Index: clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
===
--- clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
+++ clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
@@ -42,6 +42,11 @@
  "merging/replacing."),
 cl::init(false), cl::cat(ReplacementCategory));
 
+static cl::opt IgnoreInsertConflict(
+"ignore-insert-conflict",
+cl::desc("Ignore insert conflict and keep running to fix."),
+cl::init(false), cl::cat(ReplacementCategory));
+
 static cl::opt DoFormat(
 "format",
 cl::desc("Enable formatting of code changed by applying replacements.\n"
@@ -131,7 +136,7 @@
   SourceManager SM(Diagnostics, Files);
 
   FileToChangesMap Changes;
-  if (!mergeAndDeduplicate(TURs, TUDs, Changes, SM))
+  if (!mergeAndDeduplicate(TURs, TU

[PATCH] D124422: [Serialization] Improve encoding of small SourceRanges.

2022-04-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D124422#3474110 , @ilya-biryukov 
wrote:

> Yeah, that sounds promising. Various source locations inside the same nodes 
> are probably very close. Probably even across nodes.

Yeah. The reason to avoid compressing across nodes is it breaks lazy-loading. 
(Also I'm not sure whether related decls end up proximate in the output). Maybe 
there's a way around it, but this is much lower-hanging I think.

> If we are willing to take on a bit more complexity, we could probably get 
> even bigger wins by storing all source locations in a single array  having 
> indices into that array in the actual positions where we need the source 
> locations.

This is an interesting idea, I wonder whether it will be a win.

The delta-encodings are efficient as you note, but we have to represent 
SourceLocations twice. (value + index).
I think the #bits we save storing indices vs SourceLocations is similar to the 
#bits we need to encode the deltas.
If these cancel out then the savings we get are from deduplicating 
SourceLocations in the array - I suspect there aren't actually that many 
duplicates, we'd be lucky to halve the array size.

Rough example with made-up numbers:

- today we store raw SourceLocations, N * ~28 bits
- maybe simple delta-encoding maybe reduces this by 8 to N * 20 bits average
- sorted SourceLocation array (no delta-encoding, no deduplication) is N * 28, 
indices maybe N * 23 (assuming distance of 2^5 between sourcelocations)
- delta-encoding the array means it takes conservatively N * 7 bits (5 bits 
average delta + VBR overhead + variance)
- delta-encoding the indices yields the same 8 bits as before => N * 15
- deduplcating the halves the entries and reduces the size of indices by 1 bit
- this yields N/2*7 for the array + N * 14 for indices = N * 17.5

So we come out ahead (20->17.5) if deduplication halves #locations. If it 
reduces by a third, it's 20->19 instead.
This seems likely to be an improvement, over simple delta, but much smaller 
than delta vs status quo.

> I suspect there are requirements that will force us to store the array in 
> chunks and allow searching for a particular chunk.
>
> However, that's really adding quite a bit of complexity and I'm not sure 
> preamble sizes are such a big deal outside our environment. E.g. even 10% 
> savings are borderline for that kind of complexity.

Yeah, I don't plan to pursue this for now because the complexity/reward scares 
me, but if we get really squeezed for size we could revisit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124422

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


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-04-26 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2451
+  // attribute to the callee.
+  if (AttrOnCallSite || AI.getKind() == ABIArgInfo::Extend) {
+if (AI.isSignExt())

pengfei wrote:
> Does the change affect Windows? Seems Win64 doesn't extend on caller. 
> https://godbolt.org/z/c95hvvsWf
No.  This patch didn't nothing for Win64 ABI.



Comment at: clang/test/CodeGen/X86/integer_argument_passing.c:2
+// RUN: %clang_cc1 -O2 -triple -x86_64-linux-gnu %s -emit-llvm -o - | 
FileCheck %s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-linux-gnu %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-pc-win32 %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=EXTEND,CHECK

pengfei wrote:
> Maybe we can remove the tests for i386 given it's only for 64 bits ABI?
According to the meaning of `ConservativeExtend`, I think the 32bit ABI needs 
to be modified as well:
https://godbolt.org/z/W1Ma1T3f3
The dump of currently clang-cl:
```
_square:
movb4(%esp), %al
mulb%al
mulb8(%esp)
retl

.def_baz;
.scl2;
.type   32;
.endef
.section.text,"xr",one_only,_baz
.globl  _baz
.p2align4, 0x90
_baz:
movswl  4(%esp), %eax
pushl   %eax
calll   _bar
addl$4, %esp
retl
```
Of course with this patch the behavior of clang-cl is still different from 
cl.exe, but I think it fits the meaning of `ConservativeExtend`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

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


[PATCH] D124436: [analyzer] Fix Static Analyzer g_memdup false-positive

2022-04-26 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.

Ok. LGTM.

(Just a note: it looks kind of interesting that we support the GTK related Glib 
functions explicitly here. I suppose they are far less frequently used than the 
`libc` or POSIX functions. This is somewhat similar to the fact that we can 
check WebKit or Fuchsia related code, but at least those are separated into 
their own checker.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124436

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


[PATCH] D124441: [Index] [clangd] Support for concept declarations and requires expressions

2022-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 425171.
ilya-biryukov marked 4 inline comments as done.
ilya-biryukov added a comment.

- Check 'Concept auto' completion,
- set -std=c++20 unconditionally,
- use char instead of int.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124441

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Quality.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang-tools-extra/clangd/unittests/TestIndex.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Index/IndexSymbol.h
  clang/lib/Index/IndexBody.cpp
  clang/lib/Index/IndexDecl.cpp
  clang/lib/Index/IndexSymbol.cpp
  clang/lib/Index/IndexTypeSourceInfo.cpp
  clang/lib/Index/IndexingContext.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/tools/libclang/CXIndexDataConsumer.cpp

Index: clang/tools/libclang/CXIndexDataConsumer.cpp
===
--- clang/tools/libclang/CXIndexDataConsumer.cpp
+++ clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -1247,6 +1247,7 @@
   case SymbolKind::TemplateTypeParm:
   case SymbolKind::TemplateTemplateParm:
   case SymbolKind::NonTypeTemplateParm:
+  case SymbolKind::Concept:
 return CXIdxEntity_Unexposed;
 
   case SymbolKind::Enum: return CXIdxEntity_Enum;
Index: clang/lib/Index/USRGeneration.cpp
===
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -103,6 +103,7 @@
   void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
   void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
   void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
+  void VisitConceptDecl(const ConceptDecl *D);
 
   void VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
 IgnoreResults = true; // No USRs for linkage specs themselves.
@@ -1007,7 +1008,13 @@
   Out << D->getName(); // Simple name.
 }
 
-
+void USRGenerator::VisitConceptDecl(const ConceptDecl *D) {
+  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
+return;
+  VisitDeclContext(D->getDeclContext());
+  Out << "@CT@";
+  EmitDeclName(D);
+}
 
 //===--===//
 // USR generation functions.
Index: clang/lib/Index/IndexingContext.cpp
===
--- clang/lib/Index/IndexingContext.cpp
+++ clang/lib/Index/IndexingContext.cpp
@@ -86,7 +86,6 @@
isa(D))) {
 return true;
   }
-
   return handleDeclOccurrence(D, Loc, /*IsRef=*/true, Parent, Roles, Relations,
   RefE, RefD, DC);
 }
@@ -264,7 +263,8 @@
   isa(D) ||
   isa(D) ||
   isa(D) ||
-  isa(D))
+  isa(D) ||
+  isa(D))
 return true;
 
   return false;
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -7,7 +7,10 @@
 //===--===//
 
 #include "IndexingContext.h"
+#include "clang/AST/ASTConcept.h"
+#include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TypeLoc.h"
 #include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
@@ -77,6 +80,13 @@
 return true;
   }
 
+  bool VisitAutoTypeLoc(AutoTypeLoc TL) {
+if (auto *C = TL.getNamedConcept())
+  return IndexCtx.handleReference(C, TL.getConceptNameLoc(), Parent,
+  ParentDC);
+return true;
+  }
+
   bool traverseParamVarHelper(ParmVarDecl *D) {
 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
 if (D->getTypeSourceInfo())
Index: clang/lib/Index/IndexSymbol.cpp
===
--- clang/lib/Index/IndexSymbol.cpp
+++ clang/lib/Index/IndexSymbol.cpp
@@ -371,6 +371,9 @@
 case Decl::NonTypeTemplateParm:
   Info.Kind = SymbolKind::NonTypeTemplateParm;
   break;
+case Decl::Concept:
+  Info.Kind = SymbolKind::Concept;
+  break;
 // Other decls get the 'unknown' kind.
 default:
   break;
@@ -534,6 +537,7 @@
   case SymbolKind::TemplateTypeParm: return "template-type-param";
   case SymbolKind::TemplateTemplateParm: return "template-template-param";
   case SymbolKind::NonTypeTemplateParm: return "non-type-template-param";
+  case SymbolKind::Concept: return "concept";
   }
   llvm_unreachable("invalid symbol kind");
 }
Index: clang/lib/I

[PATCH] D124441: [Index] [clangd] Support for concept declarations and requires expressions

2022-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:3584
+  std::vector Syms = {conceptSym("same_as")};
+  for (auto P : Code.points("tparam")) {
+ASSERT_THAT(completions(TU, P, Syms).Completions,

sammccall wrote:
> I think it'd be useful to assert the presence/absence of template 
> brackets/placeholders here, even if the behavior is not ideal today (in which 
> case, comment to that effect).
> 
> Similarly it's probably worth having a concept B with two type params as 
> these are different cases for template brackets when used as type (even if 
> the behavior is the same)
The problem is that we currently add the template brackets everywhere.
I forgot to mention that I didn't solve this issue yet, it requires adding a 
new completion context and seems like a good independent change.

I've been collecting missing cases in the github issue, will make a note there.



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:1851
+void checkFindRefs(llvm::StringRef Test, bool UseIndex = false,
+   std::vector ExtraArgs = {}) {
   Annotations T(Test);

sammccall wrote:
> nit: does anything break if we just set c++20 unconditionally?
Yeah, good point. Other tests don't depend on it.



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:2080
+
+[[IsSmall]] auto i = 8;
+template<[[IsSmal^l]] U> void foo();

sammccall wrote:
> maybe `= 'c'` and use `char` below? Don't make me think :-)
Done. Just to make sure we're safe against new architectures for the next 250 
years of C++ history.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124441

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


[PATCH] D124285: [clang][NFC] In parts of Objective-C Sema use Obj-C-specific types instead of `Decl`.

2022-04-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM with two minor questions.




Comment at: clang/include/clang/Sema/Sema.h:3300
 
-  Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
+  void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl);
 

Why the change in return type?



Comment at: clang/lib/Sema/SemaDecl.cpp:17067
+void Sema::ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx) {
+  auto DC = cast(ObjCCtx);
   assert(DC == CurContext && "Mismatch of container contexts");

Why the cast? We should be able to compare/assign `ObjCContainerDecl *` to 
`DeclContext *`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124285

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


[PATCH] D124286: [modules] Allow parsing a duplicate Obj-C interface if a previous one comes from a hidden [sub]module.

2022-04-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

This looks good IMO. Let's see if others have more suggestions besides the 
`Parser`/`Sema` layering.




Comment at: clang/lib/Parse/ParseObjc.cpp:16
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetInfo.h"

vsapsai wrote:
> I'd like to get feedback on Parser/Sema layering. I'll check myself what can 
> be done but at the first glance accessing pieces of Sema from Parser looks 
> questionable.
Yeah, I think introducing new `Sema::ActOnEndClassInterface()` and moving the 
diagnostic logic there might be cleaner.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124286

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


[PATCH] D124446: [clang-tidy] Add the misc-discarded-return-value check

2022-04-26 Thread Benedek Attila Bahrami via Phabricator via cfe-commits
bahramib created this revision.
bahramib added reviewers: aaron.ballman, njames93, whisperity.
bahramib added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, rnkovacs, xazax.hun, mgorny.
Herald added a project: All.
bahramib requested review of this revision.

Flags function calls which return value is discarded if most of the other calls
of the function consume the return value. This check takes the threshold
for "most" as a config option and works on statistics gathered from the
call sites encountered in the analyzed file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124446

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/DiscardedReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/misc/DiscardedReturnValueCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-discarded-return-value.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-discarded-return-value-50p.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-discarded-return-value-50p.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-discarded-return-value-50p.cpp
@@ -0,0 +1,856 @@
+// RUN: %check_clang_tidy %s misc-discarded-return-value -std=c++17 %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: misc-discarded-return-value.ConsumeThreshold, value: 50} \
+// RUN:   ]}'
+
+extern bool Coin;
+extern int sink(int);
+extern int sink2(int, int);
+
+namespace std {
+
+using size_t = decltype(sizeof(void *));
+
+int printf(const char *Format, ...);
+
+template 
+T &&declval() noexcept;
+
+template 
+struct default_delete {};
+
+template 
+struct initializer_list {
+  initializer_list(const T *, std::size_t) {}
+};
+
+template 
+struct numeric_limits {
+  static constexpr std::size_t min() noexcept { return 0; }
+  static constexpr std::size_t max() noexcept { return 4; }
+};
+
+template 
+struct remove_reference { typedef T type; };
+template 
+struct remove_reference { typedef T type; };
+template 
+struct remove_reference { typedef T type; };
+
+template 
+typename remove_reference::type &&move(T &&V) noexcept {
+  return static_cast::type &&>(V);
+}
+
+template >
+class unique_ptr {
+public:
+  unique_ptr();
+  explicit unique_ptr(T *);
+  template 
+  unique_ptr(unique_ptr &&);
+};
+
+} // namespace std
+
+void voidFn();
+void voidTest() {
+  for (voidFn();; voidFn())
+;
+  voidFn(); // NO-WARN: void functions do not count for usages.
+}
+
+[[nodiscard]] int nodiscard();
+void nodiscardTest() {
+  int Consume = nodiscard();
+  nodiscard(); // NO-WARN from the check - [[nodiscard]] handled by Sema.
+}
+
+int silence();
+void silenceTest() {
+  (void)silence();
+  static_cast(silence());
+  reinterpret_cast(silence());
+  silence();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: return value of 'silence' is used in most calls, but not in this one [misc-discarded-return-value]
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: note: value consumed or checked in 75% (3 out of 4) of cases
+}
+
+int varInit();
+int varInit2();
+void varinitTest() {
+  int X = varInit();
+  varInit();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: return value of 'varInit' is used in most calls, but not in this one [misc-discarded-return-value]
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: note: value consumed or checked in 50% (1 out of 2) of cases
+
+  int Y = varInit2(), Z = varInit2();
+  varInit2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: return value of 'varInit2' is used in most calls, but not in this one [misc-discarded-return-value]
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: note: value consumed or checked in 66% (2 out of 3) of cases
+}
+
+int passToFn();
+void passToFnTest() {
+  sink(passToFn());
+  passToFn();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: return value of 'passToFn'
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: note: value consumed or checked in 50% (1 out of 2)
+}
+
+int *array();
+int index();
+void indexTest() {
+  int T[4];
+  array()[index()];
+  T[index()];
+  array()[0];
+
+  index();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: return value of 'index'
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: note: value consumed or checked in 66% (2 out of 3)
+
+  array();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: return value of 'array'
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: note: value consumed or checked in 66% (2 out of 3)
+}
+
+int varargVal();
+void varargTest() {
+  std::printf("%d %d", varargVal(), varargVal());
+  varargVal();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: return value of 'varargVal'
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: note: value consumed or checked in 66% (2 out of 3)
+}
+
+int unary();
+void unaryTest() {
+  if (!unary())
+unary();
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return value of '

[PATCH] D124447: [clang-tidy] Add infrastructure support for running on project-level information

2022-04-26 Thread Benedek Attila Bahrami via Phabricator via cfe-commits
bahramib created this revision.
bahramib added reviewers: aaron.ballman, njames93, whisperity, martong.
bahramib added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, arphaman, rnkovacs, xazax.hun.
Herald added a project: All.
bahramib requested review of this revision.

This patch adds the necessary infrastructure bindings and overloads that
allow checks to implement collecting and emitting per-TU data to a
directory from which the diagnosis mode can read it and decide whether
to diagnose.

What checks emit and how they transform the data is a per-check
implementation detail.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124447

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidy.h
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/index.rst

Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -227,6 +227,32 @@
  complete list of passes, use the
  :option:`--list-checks` and
  :option:`-load` options together.
+  --multipass-dir=   -
+   When executing project-level analysis, specify
+   a directory where data can be stored inbetween
+   phases.
+  --multipass-phase=  -
+   When executing project-level analysis, specify
+   which phase of the analysis to run. Multi-pass
+   project-level analysis requires the execution
+   of 3 passes in sequence. Not all checks support
+   this feature.
+=collect -
+ Collect per-TU analysis data from checks that are
+ capable of multi-pass analysis.
+
+ This pass can be executed in parallel.
+=compact -
+ Transform the per-TU data into a single project-level
+ data to be consumed for diagnostics.
+
+ This pass CAN NOT be executed in parallel!
+=diagnose-
+ Emit diagnostics of the code, using the previously
+ collected and compacted data, or with per-TU data
+ only for single-pass analysis analysis.
+
+ This pass can be executed in parallel.
 -p=- Build path
 --quiet-
  Run clang-tidy in quiet mode. This suppresses
@@ -418,5 +444,44 @@
 :program:`clang-tidy` will generate a ``clang-tidy-nolint`` error diagnostic if
 any ``NOLINTBEGIN``/``NOLINTEND`` comment violates these requirements.
 
+Project-level analysis
+==
+
+By default, Clang-Tidy runs checks on every translation unit of the project
+separately.
+Some checks, however, might benefit from and give better or more meaningful
+results, or only work, when executed not for a single file, but for the entire
+project.
+The **multi-pass** analysis can be used in this case, with which checks can first
+`collect` information into a temporary data location (``--multipass-dir``) on the
+disk, `compact` per-TU data into project-level data, and `diagnose` with the
+project-level data in mind.
+The phase is selected by passing the appropriate value to the
+``--multipass-phase`` command-line parameter.
+
+Whether a check supports project-level analysis, and how project-level data is
+stored and transformed from per-TU to "global" values is specific to each
+individual check.
+
+.. code-block:: bash
+$ clang-tidy --checks=... file1.cpp file2.cpp
+
+$ clang-tidy --checks=... --multipass-phase=collect --multipass-dir="TidyData" file1.cpp file2.cpp
+# No output to the terminal.
+$ ls ./TidyData
+blah.file1.cpp.01234567.yaml
+blah.file2.cpp.89abcdef.yaml
+
+$ clang-tidy --checks=... --multipass-phase=compact --multipass-dir="TidyData"
+# No file list required to be specified.
+# No output to the terminal.
+$ ls ./TidyData
+blah.file1.cpp.01234567.yaml
+blah.file2.cpp.89abcdef.yaml
+blah.yaml
+
+  

[PATCH] D124448: [clang-tidy] Add project-level analysis support to misc-discarded-return-value

2022-04-26 Thread Benedek Attila Bahrami via Phabricator via cfe-commits
bahramib created this revision.
bahramib added reviewers: aaron.ballman, njames93, whisperity, martong.
bahramib added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, rnkovacs, xazax.hun, mgorny.
Herald added a project: All.
bahramib requested review of this revision.

This enables calculating the consumed/discarded distribution of function
calls for the entire project, resulting in more meaningful diagnostics.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124448

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/DiscardedReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/misc/DiscardedReturnValueCheck.h

Index: clang-tools-extra/clang-tidy/misc/DiscardedReturnValueCheck.h
===
--- clang-tools-extra/clang-tidy/misc/DiscardedReturnValueCheck.h
+++ clang-tools-extra/clang-tidy/misc/DiscardedReturnValueCheck.h
@@ -12,6 +12,7 @@
 #include "../ClangTidyCheck.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/StringMap.h"
 #include 
 
 namespace clang {
@@ -28,18 +29,23 @@
   struct Function {
 std::size_t ConsumedCalls;
 std::size_t TotalCalls;
+const FunctionDecl *FD;
 llvm::SmallPtrSet DiscardedCEs;
 
 /// Returns ConsumedCalls / TotalCalls expressed as a whole percentage.
 std::uint8_t ratio() const;
   };
-  using FunctionMapTy = llvm::DenseMap;
+  using FunctionMapTy = llvm::StringMap;
 
   DiscardedReturnValueCheck(StringRef Name, ClangTidyContext *Context);
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void onStartOfTranslationUnit() override;
   void onEndOfTranslationUnit() override;
+  void collect(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void postCollect(StringRef OutputFile) override;
+  void compact(const std::vector &PerTuCollectedData,
+   StringRef OutputFile) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
@@ -49,16 +55,25 @@
   /// the remaining 2 will be warned.
   const std::uint8_t ConsumeThreshold;
 
+  /// Contains whether during diagnostics the data was loaded from a serialized
+  /// project-level file created by compact().
+  /// (This is only used as a result cache so no several rounds of lookup is
+  /// made.)
+  Optional CacheProjectDataLoadedSuccessfully;
+
   /// Stores AST nodes which we have observed to be consuming calls.
   /// (This is a helper data structure to prevent matchers matching consuming
   /// contexts firing multiple times and messing up the statistics created.)
   llvm::DenseMap> ConsumedCalls;
 
   FunctionMapTy CallMap;
+  llvm::DenseMap FunctionIDs;
 
+  void matchResult(const ast_matchers::MatchFinder::MatchResult &Result,
+   bool ShouldCount);
   void registerCall(const CallExpr *CE, const FunctionDecl *FD,
-const void *ConsumingContext);
-  void diagnose(const FunctionDecl *FD, const Function &F);
+bool IncrementCounters, const void *ConsumingContext);
+  void diagnose(const Function &F);
 };
 
 } // namespace misc
Index: clang-tools-extra/clang-tidy/misc/DiscardedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/DiscardedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/DiscardedReturnValueCheck.cpp
@@ -9,11 +9,103 @@
 #include "DiscardedReturnValueCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Index/USRGeneration.h"
+#include "llvm/Support/YAMLParser.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 using namespace clang::ast_matchers;
 using namespace clang::tidy::misc;
 
+namespace {
+
+/// The format of the YAML document the checker uses in multi-pass project-level
+/// mode. This is the same for the per-TU and the per-project data.
+struct SerializedFunction {
+  std::string ID;
+  std::size_t ConsumedCalls, TotalCalls;
+};
+using FunctionVec = std::vector;
+
+} // namespace
+
+namespace llvm {
+namespace yaml {
+
+template <> struct MappingTraits {
+  static void mapping(IO &IO, SerializedFunction &F) {
+IO.mapRequired("ID", F.ID);
+IO.mapRequired("Consumed", F.ConsumedCalls);
+IO.mapRequired("Total", F.TotalCalls);
+  }
+};
+
+} // namespace yaml
+} // namespace llvm
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(SerializedFunction)
+
+static Optional loadYAML(StringRef File) {
+  using namespace llvm;
+
+  ErrorOr> IStream =
+  MemoryBuffer::getFileAsStream(File);
+  if (!IStream)
+return None;
+
+  FunctionVec R;
+  yaml::Input YIn{**IStream};
+  YIn >> R;
+
+  return R;
+}
+
+static bool loadYAML(StringRef FromFile,
+ DiscardedReturnValueCheck::FunctionMapTy &ToMap) {
+  Opt

[PATCH] D124287: [modules][ODRHash] Compare ODR hashes to detect mismatches in duplicate ObjCInterfaceDecl.

2022-04-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

This sounds reasonable to me. What use-cases does `ASTStructuralEquivalence` 
fit better than ODR hashes?




Comment at: clang/include/clang/Sema/Sema.h:3300
+typename = std::enable_if_t::value>>
+  bool ActOnDuplicateDefinition(T *Duplicate, T *Previous) {
+if (Duplicate->getODRHash() != Previous->getODRHash())

I'm not sure I'm a fan of using the exact same function name for checking ODR 
hashes and structural equivalence.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124287

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


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-04-26 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2451
+  // attribute to the callee.
+  if (AttrOnCallSite || AI.getKind() == ABIArgInfo::Extend) {
+if (AI.isSignExt())

LiuChen3 wrote:
> pengfei wrote:
> > Does the change affect Windows? Seems Win64 doesn't extend on caller. 
> > https://godbolt.org/z/c95hvvsWf
> No.  This patch didn't nothing for Win64 ABI.
But I found some Windows tests are affected?



Comment at: clang/test/CodeGen/X86/integer_argument_passing.c:2
+// RUN: %clang_cc1 -O2 -triple -x86_64-linux-gnu %s -emit-llvm -o - | 
FileCheck %s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-linux-gnu %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-pc-win32 %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=EXTEND,CHECK

LiuChen3 wrote:
> pengfei wrote:
> > Maybe we can remove the tests for i386 given it's only for 64 bits ABI?
> According to the meaning of `ConservativeExtend`, I think the 32bit ABI needs 
> to be modified as well:
> https://godbolt.org/z/W1Ma1T3f3
> The dump of currently clang-cl:
> ```
> _square:
> movb4(%esp), %al
> mulb%al
> mulb8(%esp)
> retl
> 
> .def_baz;
> .scl2;
> .type   32;
> .endef
> .section.text,"xr",one_only,_baz
> .globl  _baz
> .p2align4, 0x90
> _baz:
> movswl  4(%esp), %eax
> pushl   %eax
> calll   _bar
> addl$4, %esp
> retl
> ```
> Of course with this patch the behavior of clang-cl is still different from 
> cl.exe, but I think it fits the meaning of `ConservativeExtend`.
My point was, i386 is passing arguments by stack. The extensions don't make 
sense under the circumstances. That's what I understood the comments in above 
test 2007-06-18-SextAttrAggregate.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

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


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-04-26 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/CodeGen/X86/integer_argument_passing.c:2
+// RUN: %clang_cc1 -O2 -triple -x86_64-linux-gnu %s -emit-llvm -o - | 
FileCheck %s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-linux-gnu %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-pc-win32 %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=EXTEND,CHECK

pengfei wrote:
> LiuChen3 wrote:
> > pengfei wrote:
> > > Maybe we can remove the tests for i386 given it's only for 64 bits ABI?
> > According to the meaning of `ConservativeExtend`, I think the 32bit ABI 
> > needs to be modified as well:
> > https://godbolt.org/z/W1Ma1T3f3
> > The dump of currently clang-cl:
> > ```
> > _square:
> > movb4(%esp), %al
> > mulb%al
> > mulb8(%esp)
> > retl
> > 
> > .def_baz;
> > .scl2;
> > .type   32;
> > .endef
> > .section.text,"xr",one_only,_baz
> > .globl  _baz
> > .p2align4, 0x90
> > _baz:
> > movswl  4(%esp), %eax
> > pushl   %eax
> > calll   _bar
> > addl$4, %esp
> > retl
> > ```
> > Of course with this patch the behavior of clang-cl is still different from 
> > cl.exe, but I think it fits the meaning of `ConservativeExtend`.
> My point was, i386 is passing arguments by stack. The extensions don't make 
> sense under the circumstances. That's what I understood the comments in above 
> test 2007-06-18-SextAttrAggregate.c
Oh, seems I misunderstood it. The stack still needs extensions since it's 
aligned to 4 bytes. But from the above output, the clang-cl is wrong, because 
it extends on caller which MSVC extends on callee. So back the another 
question, we should change for Windows too, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

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


[PATCH] D124442: [analyzer] Allow exploded graph dumps in release builds

2022-04-26 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, thanks!

For the record, I am inserting the url of the issue:
https://github.com/llvm/llvm-project/issues/53873


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124442

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


[PATCH] D124443: [analyzer] Allow CFG dumps in release builds

2022-04-26 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!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124443

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


[PATCH] D118996: [clang-tidy] Support C++14 in bugprone-signal-handler.

2022-04-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D118996#3473934 , @whisperity 
wrote:

> After adding improvements to the documentation, I think this will be good to 
> go, and thank you! Perhaps just for a safety measure you could run it on a 
> few projects (LLVM itself?) to ensure we didn't miss a case where it might 
> magically crash, but I wonder how many specifically "C++14" projects will use 
> signal handlers in the first place.

It did not crash on llvm, nor on our internal test set.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118996

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


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-04-26 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added inline comments.



Comment at: clang/test/CodeGen/X86/integer_argument_passing.c:2
+// RUN: %clang_cc1 -O2 -triple -x86_64-linux-gnu %s -emit-llvm -o - | 
FileCheck %s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-linux-gnu %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-pc-win32 %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=EXTEND,CHECK

pengfei wrote:
> pengfei wrote:
> > LiuChen3 wrote:
> > > pengfei wrote:
> > > > Maybe we can remove the tests for i386 given it's only for 64 bits ABI?
> > > According to the meaning of `ConservativeExtend`, I think the 32bit ABI 
> > > needs to be modified as well:
> > > https://godbolt.org/z/W1Ma1T3f3
> > > The dump of currently clang-cl:
> > > ```
> > > _square:
> > > movb4(%esp), %al
> > > mulb%al
> > > mulb8(%esp)
> > > retl
> > > 
> > > .def_baz;
> > > .scl2;
> > > .type   32;
> > > .endef
> > > .section.text,"xr",one_only,_baz
> > > .globl  _baz
> > > .p2align4, 0x90
> > > _baz:
> > > movswl  4(%esp), %eax
> > > pushl   %eax
> > > calll   _bar
> > > addl$4, %esp
> > > retl
> > > ```
> > > Of course with this patch the behavior of clang-cl is still different 
> > > from cl.exe, but I think it fits the meaning of `ConservativeExtend`.
> > My point was, i386 is passing arguments by stack. The extensions don't make 
> > sense under the circumstances. That's what I understood the comments in 
> > above test 2007-06-18-SextAttrAggregate.c
> Oh, seems I misunderstood it. The stack still needs extensions since it's 
> aligned to 4 bytes. But from the above output, the clang-cl is wrong, because 
> it extends on caller which MSVC extends on callee. So back the another 
> question, we should change for Windows too, right?
I just change the behavior of win32. Windows 64 will always do the extensions 
in callee. I didn't support `ConservativeExtend` for win64. The dump IR of 
currently clang-cl is:
```
define dso_local i8 @square(i8 noundef %a, i8 noundef %b) local_unnamed_addr #0 
{
...
}

  %call = tail call i32 @bar(i16 noundef %conv) #3
...
}

define dso_local i32 @baz(i32 noundef %num) local_unnamed_addr #1 {
...
  %call = tail call i32 @bar(i16 noundef %conv) #3
...
}
```
I think maybe we don't need to do the extension both in caller and callee for 
WIN64?  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

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


[clang] a037eac - Fix test from 5ff992 to work with win 32 bit, fix a typo.

2022-04-26 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2022-04-26T06:37:19-07:00
New Revision: a037eace91a350b2a45d0b901f547903df3d3cb3

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

LOG: Fix test from 5ff992 to work with win 32 bit, fix a typo.

See the discussion on D123319.  Default calling convention on Windows32
bit is to have 'this-call' for member functions, so add a wildcard to
take care of that.

Also, one of the FileCheck 'match' flags was incorrect, so fix that too.

Added: 


Modified: 
clang/test/CodeGenCXX/no_auto_return_lambda.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/no_auto_return_lambda.cpp 
b/clang/test/CodeGenCXX/no_auto_return_lambda.cpp
index 76a98263f7668..61e76a0656e67 100644
--- a/clang/test/CodeGenCXX/no_auto_return_lambda.cpp
+++ b/clang/test/CodeGenCXX/no_auto_return_lambda.cpp
@@ -21,5 +21,5 @@ __attribute__((used)) int g() {
 // operator() of the local lambda should have the same return type as g()
 //
 // CHECK: distinct !DISubprogram(name: "operator()",{{.*}}, type: 
![[FUN_TYPE_LAMBDA:[0-9]+]],{{.*}}
-// CHECK: ![[FUN_TYPE_LAMBDA]] = !DISubroutineType(types: 
![[TYPE_NODE_LAMBDA:[0-9]+]])
-// CHECK: ![[TYPE_NODE_LAMBDA]] = !{![[INT_TYPE:[0-9]+]], {{.*}}
+// CHECK: ![[FUN_TYPE_LAMBDA]] = !DISubroutineType({{.*}}types: 
![[TYPE_NODE_LAMBDA:[0-9]+]])
+// CHECK: ![[TYPE_NODE_LAMBDA]] = !{![[INT_TYPE]], {{.*}}



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


[PATCH] D124441: [Index] [clangd] Support for concept declarations and requires expressions

2022-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 425198.
ilya-biryukov added a comment.

- clang-format the code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124441

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Quality.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang-tools-extra/clangd/unittests/TestIndex.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Index/IndexSymbol.h
  clang/lib/Index/IndexBody.cpp
  clang/lib/Index/IndexDecl.cpp
  clang/lib/Index/IndexSymbol.cpp
  clang/lib/Index/IndexTypeSourceInfo.cpp
  clang/lib/Index/IndexingContext.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/tools/libclang/CXIndexDataConsumer.cpp

Index: clang/tools/libclang/CXIndexDataConsumer.cpp
===
--- clang/tools/libclang/CXIndexDataConsumer.cpp
+++ clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -1247,6 +1247,7 @@
   case SymbolKind::TemplateTypeParm:
   case SymbolKind::TemplateTemplateParm:
   case SymbolKind::NonTypeTemplateParm:
+  case SymbolKind::Concept:
 return CXIdxEntity_Unexposed;
 
   case SymbolKind::Enum: return CXIdxEntity_Enum;
Index: clang/lib/Index/USRGeneration.cpp
===
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -103,6 +103,7 @@
   void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
   void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
   void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
+  void VisitConceptDecl(const ConceptDecl *D);
 
   void VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
 IgnoreResults = true; // No USRs for linkage specs themselves.
@@ -1007,7 +1008,13 @@
   Out << D->getName(); // Simple name.
 }
 
-
+void USRGenerator::VisitConceptDecl(const ConceptDecl *D) {
+  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
+return;
+  VisitDeclContext(D->getDeclContext());
+  Out << "@CT@";
+  EmitDeclName(D);
+}
 
 //===--===//
 // USR generation functions.
Index: clang/lib/Index/IndexingContext.cpp
===
--- clang/lib/Index/IndexingContext.cpp
+++ clang/lib/Index/IndexingContext.cpp
@@ -86,7 +86,6 @@
isa(D))) {
 return true;
   }
-
   return handleDeclOccurrence(D, Loc, /*IsRef=*/true, Parent, Roles, Relations,
   RefE, RefD, DC);
 }
@@ -259,12 +258,9 @@
   if (auto MD = dyn_cast(D))
 return MD->isThisDeclarationADefinition() || isa(ContainerDC);
 
-  if (isa(D) ||
-  isa(D) ||
-  isa(D) ||
-  isa(D) ||
-  isa(D) ||
-  isa(D))
+  if (isa(D) || isa(D) ||
+  isa(D) || isa(D) || isa(D) ||
+  isa(D) || isa(D))
 return true;
 
   return false;
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -7,7 +7,10 @@
 //===--===//
 
 #include "IndexingContext.h"
+#include "clang/AST/ASTConcept.h"
+#include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TypeLoc.h"
 #include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
@@ -77,6 +80,13 @@
 return true;
   }
 
+  bool VisitAutoTypeLoc(AutoTypeLoc TL) {
+if (auto *C = TL.getNamedConcept())
+  return IndexCtx.handleReference(C, TL.getConceptNameLoc(), Parent,
+  ParentDC);
+return true;
+  }
+
   bool traverseParamVarHelper(ParmVarDecl *D) {
 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
 if (D->getTypeSourceInfo())
Index: clang/lib/Index/IndexSymbol.cpp
===
--- clang/lib/Index/IndexSymbol.cpp
+++ clang/lib/Index/IndexSymbol.cpp
@@ -371,6 +371,9 @@
 case Decl::NonTypeTemplateParm:
   Info.Kind = SymbolKind::NonTypeTemplateParm;
   break;
+case Decl::Concept:
+  Info.Kind = SymbolKind::Concept;
+  break;
 // Other decls get the 'unknown' kind.
 default:
   break;
@@ -534,6 +537,8 @@
   case SymbolKind::TemplateTypeParm: return "template-type-param";
   case SymbolKind::TemplateTemplateParm: return "template-template-param";
   case SymbolKind::NonTypeTemplateParm: return "non-type-template-param";
+  case SymbolKind::Concept:
+return "con

[PATCH] D123065: [clang-tidy] support --load in clang-tidy-diff.py/run-clang-tidy.py

2022-04-26 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D123065#3474107 , @bernhardmgruber 
wrote:

> Ping.
>
> Can someone merge this please for me? Thank you!

Yes, sure, just please specify what `user.name` and `user.email` would you like 
to be associated with the commit's author?


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

https://reviews.llvm.org/D123065

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


[PATCH] D119544: Deferred Concept Instantiation Implementation

2022-04-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:2431-2439
+  //if (TrailingRequiresClause) {
+  //  Sema::CXXThisScopeRAII ThisScope(SemaRef, Record, 
D->getMethodQualifiers());
+  //  ExprResult Rebuilt =
+  //  SemaRef.RebuildExprInCurrentInstantiation(TrailingRequiresClause);
+  //  if (Rebuilt.isInvalid())
+  //return nullptr;
+  //  TrailingRequiresClause = Rebuilt.get();

ChuanqiXu wrote:
> The failing test case could be fixed by the above change. The change above is 
> just a hack instead of a suggestion.
> The rationale is that we need to record some information when we traverse the 
> template decl. The bugs now looks like we forget to do something which would 
> be done at the first time. And we meet in problems due to the missed 
> information (we couldn't find the member in the class).
So this would un-do the 'deferred constraint checking', because that woudl 
cause us to immediately instantiate the template, so I don't think we want to 
do that.



Comment at: clang/test/SemaTemplate/concepts.cpp:386-388
+  []()
+requires(constraint)
+  {}();

ChuanqiXu wrote:
> We might need more negative tests.
> Now it would pass even if I write:
> ```
> []()
> requires(false)
> {}();
> ```
Ouch!  I'll have to see if I can find where we're missing that check!


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

https://reviews.llvm.org/D119544

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


[clang] 75e16fd - [Index] [clangd] Support for concept declarations and requires expressions

2022-04-26 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2022-04-26T13:50:01Z
New Revision: 75e16fd2c656fb7d27e6edc46dc1a63ff8323999

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

LOG: [Index] [clangd] Support for concept declarations and requires expressions

Add support for concepts and requires expression in the clang index.
Genarate USRs for concepts.

Also change how `RecursiveASTVisitor` handles return type requirement in
requires expressions. The new code unpacks the synthetic template parameter
list used for storing the actual expression. This simplifies
implementation of the indexing. No code seems to depend on the original
traversal anyway and the synthesized template parameter list is easily
accessible from inside the requires expression if needed.

Add tests in the clangd codebase.

Fixes https://github.com/clangd/clangd/issues/1103.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Quality.cpp
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
clang-tools-extra/clangd/unittests/TestIndex.cpp
clang-tools-extra/clangd/unittests/TestIndex.h
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Index/IndexSymbol.h
clang/lib/Index/IndexBody.cpp
clang/lib/Index/IndexDecl.cpp
clang/lib/Index/IndexSymbol.cpp
clang/lib/Index/IndexTypeSourceInfo.cpp
clang/lib/Index/IndexingContext.cpp
clang/lib/Index/USRGeneration.cpp
clang/tools/libclang/CXIndexDataConsumer.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 53989ca6ada3b..920fb77f07dee 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -129,6 +129,8 @@ CompletionItemKind toCompletionItemKind(index::SymbolKind 
Kind) {
   case SK::TemplateTypeParm:
   case SK::TemplateTemplateParm:
 return CompletionItemKind::TypeParameter;
+  case SK::Concept:
+return CompletionItemKind::Interface;
   }
   llvm_unreachable("Unhandled clang::index::SymbolKind.");
 }

diff  --git a/clang-tools-extra/clangd/Protocol.cpp 
b/clang-tools-extra/clangd/Protocol.cpp
index 0144d16320260..7c7d1b7cf7a70 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -301,6 +301,8 @@ SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind 
Kind) {
   case index::SymbolKind::TemplateTemplateParm:
   case index::SymbolKind::TemplateTypeParm:
 return SymbolKind::TypeParameter;
+  case index::SymbolKind::Concept:
+return SymbolKind::Interface;
   }
   llvm_unreachable("invalid symbol kind");
 }

diff  --git a/clang-tools-extra/clangd/Quality.cpp 
b/clang-tools-extra/clangd/Quality.cpp
index 3546d976c5b8d..0f7c2d3da1c6c 100644
--- a/clang-tools-extra/clangd/Quality.cpp
+++ b/clang-tools-extra/clangd/Quality.cpp
@@ -122,6 +122,7 @@ categorize(const index::SymbolInfo &D) {
   case index::SymbolKind::TypeAlias:
   case index::SymbolKind::TemplateTypeParm:
   case index::SymbolKind::TemplateTemplateParm:
+  case index::SymbolKind::Concept:
 return SymbolQualitySignals::Type;
   case index::SymbolKind::Function:
   case index::SymbolKind::ClassMethod:

diff  --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 6153b35edcfdb..ee948f80e7a6d 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -88,6 +88,7 @@ bool shouldCollectIncludePath(index::SymbolKind Kind) {
   case SK::Function:
   case SK::Variable:
   case SK::EnumConstant:
+  case SK::Concept:
 return true;
   default:
 return false;

diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index a0fcb62575e9a..2e42786f76ad6 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3565,6 +3565,38 @@ TEST(CompletionTest, CommentParamName) {
   IsEmpty());
 }
 
+TEST(CompletionTest, Concepts) {
+  Annotations Code(R"cpp(
+template
+concept A = sizeof(T) <= 8;
+
+template<$tparam^A U>
+int foo();
+
+template
+concept b = $other^A && $other^sizeof(T) % 2 == 0 || $other^A && 
sizeof(T) == 1;
+
+$other^A auto i = 19;
+  )cpp");
+  TestTU TU;
+  TU.Code = Code.code().str();
+  TU.ExtraArgs = {"-std=c++20"};
+
+  std::vector Syms

[PATCH] D124441: [Index] [clangd] Support for concept declarations and requires expressions

2022-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG75e16fd2c656: [Index] [clangd] Support for concept 
declarations and requires expressions (authored by ilya-biryukov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124441

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Quality.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang-tools-extra/clangd/unittests/TestIndex.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Index/IndexSymbol.h
  clang/lib/Index/IndexBody.cpp
  clang/lib/Index/IndexDecl.cpp
  clang/lib/Index/IndexSymbol.cpp
  clang/lib/Index/IndexTypeSourceInfo.cpp
  clang/lib/Index/IndexingContext.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/tools/libclang/CXIndexDataConsumer.cpp

Index: clang/tools/libclang/CXIndexDataConsumer.cpp
===
--- clang/tools/libclang/CXIndexDataConsumer.cpp
+++ clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -1249,6 +1249,7 @@
   case SymbolKind::TemplateTypeParm:
   case SymbolKind::TemplateTemplateParm:
   case SymbolKind::NonTypeTemplateParm:
+  case SymbolKind::Concept:
 return CXIdxEntity_Unexposed;
 
   case SymbolKind::Enum: return CXIdxEntity_Enum;
Index: clang/lib/Index/USRGeneration.cpp
===
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -103,6 +103,7 @@
   void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
   void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
   void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
+  void VisitConceptDecl(const ConceptDecl *D);
 
   void VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
 IgnoreResults = true; // No USRs for linkage specs themselves.
@@ -1007,7 +1008,13 @@
   Out << D->getName(); // Simple name.
 }
 
-
+void USRGenerator::VisitConceptDecl(const ConceptDecl *D) {
+  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
+return;
+  VisitDeclContext(D->getDeclContext());
+  Out << "@CT@";
+  EmitDeclName(D);
+}
 
 //===--===//
 // USR generation functions.
Index: clang/lib/Index/IndexingContext.cpp
===
--- clang/lib/Index/IndexingContext.cpp
+++ clang/lib/Index/IndexingContext.cpp
@@ -86,7 +86,6 @@
isa(D))) {
 return true;
   }
-
   return handleDeclOccurrence(D, Loc, /*IsRef=*/true, Parent, Roles, Relations,
   RefE, RefD, DC);
 }
@@ -259,12 +258,9 @@
   if (auto MD = dyn_cast(D))
 return MD->isThisDeclarationADefinition() || isa(ContainerDC);
 
-  if (isa(D) ||
-  isa(D) ||
-  isa(D) ||
-  isa(D) ||
-  isa(D) ||
-  isa(D))
+  if (isa(D) || isa(D) ||
+  isa(D) || isa(D) || isa(D) ||
+  isa(D) || isa(D))
 return true;
 
   return false;
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -7,7 +7,10 @@
 //===--===//
 
 #include "IndexingContext.h"
+#include "clang/AST/ASTConcept.h"
+#include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TypeLoc.h"
 #include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
@@ -77,6 +80,13 @@
 return true;
   }
 
+  bool VisitAutoTypeLoc(AutoTypeLoc TL) {
+if (auto *C = TL.getNamedConcept())
+  return IndexCtx.handleReference(C, TL.getConceptNameLoc(), Parent,
+  ParentDC);
+return true;
+  }
+
   bool traverseParamVarHelper(ParmVarDecl *D) {
 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
 if (D->getTypeSourceInfo())
Index: clang/lib/Index/IndexSymbol.cpp
===
--- clang/lib/Index/IndexSymbol.cpp
+++ clang/lib/Index/IndexSymbol.cpp
@@ -371,6 +371,9 @@
 case Decl::NonTypeTemplateParm:
   Info.Kind = SymbolKind::NonTypeTemplateParm;
   break;
+case Decl::Concept:
+  Info.Kind = SymbolKind::Concept;
+  break;
 // Other decls get the 'unknown' kind.
 default:
   break;
@@ -534,6 +537,8 @@
   case SymbolKind::TemplateTypeParm: return "template-type-param";
   case SymbolKind::TemplateTemplateP

[PATCH] D124452: [clang-format] Adjust editor cursor position past #include blocks

2022-04-26 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/55027.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124452

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/SortIncludesTest.cpp


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -890,6 +890,17 @@
   EXPECT_EQ(10u, newCursor(Code, 43));
 }
 
+TEST_F(SortIncludesTest, CalculatesCorrectCursorPositionWithRegrouping) {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  std::string Code = "#include \"b\"\n"  // Start of line: 0
+ "\n"// Start of line: 13
+ "#include \"aa\"\n" // Start of line: 14
+ "f();\n";   // Start of line: 28
+  EXPECT_EQ(12u, newCursor(Code, 26));
+  EXPECT_EQ(26u, newCursor(Code, 27));
+  EXPECT_EQ(27u, newCursor(Code, 28));
+}
+
 TEST_F(SortIncludesTest, DeduplicateIncludes) {
   EXPECT_EQ("#include \n"
 "#include \n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2638,10 +2638,10 @@
 StringRef Code, tooling::Replacements &Replaces,
 unsigned *Cursor) {
   tooling::IncludeCategoryManager Categories(Style.IncludeStyle, FileName);
-  unsigned IncludesBeginOffset = Includes.front().Offset;
-  unsigned IncludesEndOffset =
+  const unsigned IncludesBeginOffset = Includes.front().Offset;
+  const unsigned IncludesEndOffset =
   Includes.back().Offset + Includes.back().Text.size();
-  unsigned IncludesBlockSize = IncludesEndOffset - IncludesBeginOffset;
+  const unsigned IncludesBlockSize = IncludesEndOffset - IncludesBeginOffset;
   if (!affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset))
 return;
   SmallVector Indices =
@@ -2685,7 +2685,7 @@
   // the entire block. Otherwise, no replacement is generated.
   // In case Style.IncldueStyle.IncludeBlocks != IBS_Preserve, this check is 
not
   // enough as additional newlines might be added or removed across #include
-  // blocks. This we handle below by generating the updated #imclude blocks and
+  // blocks. This we handle below by generating the updated #include blocks and
   // comparing it to the original.
   if (Indices.size() == Includes.size() && llvm::is_sorted(Indices) &&
   Style.IncludeStyle.IncludeBlocks == tooling::IncludeStyle::IBS_Preserve)
@@ -2706,6 +2706,9 @@
 CurrentCategory = Includes[Index].Category;
   }
 
+  if (Cursor && *Cursor >= IncludesEndOffset)
+*Cursor += result.size() - IncludesBlockSize;
+
   // If the #includes are out of order, we generate a single replacement fixing
   // the entire range of blocks. Otherwise, no replacement is generated.
   if (replaceCRLF(result) == replaceCRLF(std::string(Code.substr(


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -890,6 +890,17 @@
   EXPECT_EQ(10u, newCursor(Code, 43));
 }
 
+TEST_F(SortIncludesTest, CalculatesCorrectCursorPositionWithRegrouping) {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  std::string Code = "#include \"b\"\n"  // Start of line: 0
+ "\n"// Start of line: 13
+ "#include \"aa\"\n" // Start of line: 14
+ "f();\n";   // Start of line: 28
+  EXPECT_EQ(12u, newCursor(Code, 26));
+  EXPECT_EQ(26u, newCursor(Code, 27));
+  EXPECT_EQ(27u, newCursor(Code, 28));
+}
+
 TEST_F(SortIncludesTest, DeduplicateIncludes) {
   EXPECT_EQ("#include \n"
 "#include \n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2638,10 +2638,10 @@
 StringRef Code, tooling::Replacements &Replaces,
 unsigned *Cursor) {
   tooling::IncludeCategoryManager Categories(Style.IncludeStyle, FileName);
-  unsigned IncludesBeginOffset = Includes.front().Offset;
-  unsigned IncludesEndOffset =
+  const unsigned IncludesBeginOffset = Includes.front().Offset;
+  const unsigned IncludesEndOffset =
   Includes.back().Offset + Includes.back().Text.size();
-  unsigned IncludesBlockSize = IncludesEndOffset - IncludesBeginOffset;
+  const unsigned IncludesBlockSize = IncludesEndOffset - IncludesBeginOffset;
   if (!affectsRange(Ranges,

[PATCH] D123065: [clang-tidy] support --load in clang-tidy-diff.py/run-clang-tidy.py

2022-04-26 Thread Bernhard Manfred Gruber via Phabricator via cfe-commits
bernhardmgruber added a comment.

> Yes, sure, just please specify what `user.name` and `user.email` would you 
> like to be associated with the commit's author?

`user.name`: Bernhard Manfred Gruber
`user.email`: bernhardmgru...@gmail.com

Thanks a lot!


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

https://reviews.llvm.org/D123065

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


[PATCH] D124452: [clang-format] Adjust editor cursor position past #include blocks

2022-04-26 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

Looks ok, but I'm not very familiar with this part of clang-format, so please 
leave some time for others to chime in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124452

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


[clang] b375882 - [PS5] Correctly test for analyzer defaults

2022-04-26 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-04-26T07:14:48-07:00
New Revision: b375882014ccaa19c14bc7dc46a666a5a09bbb40

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

LOG: [PS5] Correctly test for analyzer defaults

Commit 5c90eca added some analyzer option checking, but a typo meant
it was redundantly checking PS4 and not adding checking for PS5.
With the test corrected, it identified the necessary driver updates,
added in this commit.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/ps4-ps5-analyzer-defaults.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0fd639da45ddf..6e4eadd3ab0e7 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3167,8 +3167,8 @@ static void RenderAnalyzerOptions(const ArgList &Args, 
ArgStringList &CmdArgs,
   CmdArgs.push_back("-analyzer-checker=unix.cstring.NullArg");
 }
 
-// Disable some unix checkers for PS4.
-if (Triple.isPS4()) {
+// Disable some unix checkers for PS4/PS5.
+if (Triple.isPS()) {
   CmdArgs.push_back("-analyzer-disable-checker=unix.API");
   CmdArgs.push_back("-analyzer-disable-checker=unix.Vfork");
 }
@@ -3186,7 +3186,7 @@ static void RenderAnalyzerOptions(const ArgList &Args, 
ArgStringList &CmdArgs,
 if (types::isCXX(Input.getType()))
   CmdArgs.push_back("-analyzer-checker=cplusplus");
 
-if (!Triple.isPS4()) {
+if (!Triple.isPS()) {
   
CmdArgs.push_back("-analyzer-checker=security.insecureAPI.UncheckedReturn");
   CmdArgs.push_back("-analyzer-checker=security.insecureAPI.getpw");
   CmdArgs.push_back("-analyzer-checker=security.insecureAPI.gets");

diff  --git a/clang/test/Driver/ps4-ps5-analyzer-defaults.cpp 
b/clang/test/Driver/ps4-ps5-analyzer-defaults.cpp
index 6e76f2c90ac84..81a302c6bcbe3 100644
--- a/clang/test/Driver/ps4-ps5-analyzer-defaults.cpp
+++ b/clang/test/Driver/ps4-ps5-analyzer-defaults.cpp
@@ -17,13 +17,13 @@
 // Negative check for unexpected checkers
 // RUN: %clang -target x86_64-scei-ps4 --analyze %s -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NEG-CHECKERS
-// RUN: %clang -target x86_64-scei-ps4 --analyze %s -### 2>&1 \
+// RUN: %clang -target x86_64-sie-ps5 --analyze %s -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NEG-CHECKERS
 //
 // Check for all unix checkers except API and Vfork
 // RUN: %clang -target x86_64-scei-ps4 --analyze %s -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-UNIX-CHECKERS
-// RUN: %clang -target x86_64-scei-ps4 --analyze %s -### 2>&1 \
+// RUN: %clang -target x86_64-sie-ps5 --analyze %s -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-UNIX-CHECKERS
 
 // CHECK-POS-CHECKERS-DAG: analyzer-checker=core



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


[PATCH] D124395: [clang][dataflow] Optimize flow condition representation

2022-04-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.
This revision is now accepted and ready to land.

Nice work. On the surface, this adds complexity to the system and so should be 
justified in terms of performance improvements. However, having read through 
the patch, I think it overall reduces the complexity, since both environment 
join and boolean-value join have been radically simplified.  So, I'm fine with 
the patch as is, even without performance measurement. That said, I'm not 
against such measurement -- just saying it's not blocking. :)

If you agree, you may want to reword the description of the patch to focuse on 
the design improvements rather than (exclusively) the optimization aspect.




Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:49
-  /// Returns the SAT solver instance that is available in this context.
-  Solver &getSolver() const { return *S; }
-

nit: Maybe mention this removal in the patch description.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:152
 
+  /// Returns a fresh flow condition token.
+  AtomicBoolValue &makeFlowConditionToken();

I think it would be helpful to expand here with a brief explanation of the role 
of flow condition tokens.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:155
+
+  /// Adds `Constraint` to the flow condition indentified by `Token`.
+  void addFlowConditionConstraint(AtomicBoolValue &Token,





Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:209
+
+  // Flow conditions are represented as `FC <=> (C1 ^ C2 ^ ...)` clauses where
+  // `FC` is a flow condition token (an atomic boolean) and `Ci`s are a set of

Is the idea that this is an encoding of the `<=>`? If so, maybe use "encoded" 
in the internal description, as in "Internally, a flow condition clause is 
encoded as ..."? 

Or, a bigger change:

Flow conditions are tracked symbolically: each unique flow condition is 
associated with a fresh symbolic variable, bound to the clause that defines the 
flow condition.  Conceptually, each binding corresponds to an "iff" over the 
form `FC <=> (C1 ^ C2 ^ ...)`, where `FC` is a flow condition token (an atomic 
boolean) and `Ci`s are the set of constraints that define the flow condition. 
However, we do not record the formula directly as an `iff`. Instead, 
internally, a flow condition clause is ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124395

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


[clang] 712b59c - [clang-format][docs] Fix incorrect 'clang-format 9' option marker

2022-04-26 Thread Krystian Kuzniarek via cfe-commits

Author: Krystian Kuzniarek
Date: 2022-04-26T16:22:04+02:00
New Revision: 712b59cdc5a7d879341cf0caa4d6107f032fff78

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

LOG: [clang-format][docs] Fix incorrect 'clang-format 9' option marker

Introduced by 23a5090c6, this style option marker indicated
'clang-format 9', though its respective option was available in
an earlier release.

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 46471271299bf..90fef542205ad 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1019,7 +1019,7 @@ the configuration (without a prefix: ``Auto``).
 
 
 
-**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) 
:versionbadge:`clang-format 9`
+**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) 
:versionbadge:`clang-format 3.3`
   Dependent on the value, ``if (a) return;`` can be put on a single line.
 
   Possible values:

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 00eaccf61bd17..d53e5d020c4a9 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -600,7 +600,7 @@ struct FormatStyle {
   };
 
   /// Dependent on the value, ``if (a) return;`` can be put on a single line.
-  /// \version 9
+  /// \version 3.3
   ShortIfStyle AllowShortIfStatementsOnASingleLine;
 
   /// Different styles for merging short lambdas containing at most one



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


[PATCH] D123299: [clang-format][docs] Fix incorrect 'clang-format 9' option marker

2022-04-26 Thread Krystian Kuzniarek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG712b59cdc5a7: [clang-format][docs] Fix incorrect 
'clang-format 9' option marker (authored by kuzkry).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123299

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -600,7 +600,7 @@
   };
 
   /// Dependent on the value, ``if (a) return;`` can be put on a single line.
-  /// \version 9
+  /// \version 3.3
   ShortIfStyle AllowShortIfStatementsOnASingleLine;
 
   /// Different styles for merging short lambdas containing at most one
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1019,7 +1019,7 @@
 
 
 
-**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) 
:versionbadge:`clang-format 9`
+**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) 
:versionbadge:`clang-format 3.3`
   Dependent on the value, ``if (a) return;`` can be put on a single line.
 
   Possible values:


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -600,7 +600,7 @@
   };
 
   /// Dependent on the value, ``if (a) return;`` can be put on a single line.
-  /// \version 9
+  /// \version 3.3
   ShortIfStyle AllowShortIfStatementsOnASingleLine;
 
   /// Different styles for merging short lambdas containing at most one
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1019,7 +1019,7 @@
 
 
 
-**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) :versionbadge:`clang-format 9`
+**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) :versionbadge:`clang-format 3.3`
   Dependent on the value, ``if (a) return;`` can be put on a single line.
 
   Possible values:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c89433d - [HIP] Fix diag msg about sanitizer

2022-04-26 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2022-04-26T10:36:36-04:00
New Revision: c89433d7fa10f9a3fe3858ac455ece5913092107

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

LOG: [HIP] Fix diag msg about sanitizer

Fix the misleading diag msg as the option is ignored for a particular
offload arch only.

Reviewed by: Artem Belevich

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/test/Driver/hip-sanitize-options.hip

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 5fbe3cf8cf295..80f16749fdc12 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -107,8 +107,8 @@ def err_drv_bad_offload_arch_combo : Error<
   "a feature should either exist in all offload archs, or not exist in any "
   "offload archs)">;
 def warn_drv_unsupported_option_for_offload_arch_req_feature : Warning<
-  "ignoring '%0' option as it is not currently supported for "
-  "offload arch '%1'. Use it with an offload arch containing '%2' instead">,
+  "ignoring '%0' option for offload arch '%1' as it is not currently supported 
"
+  "there. Use it with an offload arch containing '%2' instead">,
   InGroup;
 def warn_drv_unsupported_option_for_target : Warning<
   "ignoring '%0' option as it is not currently supported for target '%1'">,

diff  --git a/clang/test/Driver/hip-sanitize-options.hip 
b/clang/test/Driver/hip-sanitize-options.hip
index ad7ae72fd2b8a..4ecb1b3e89e04 100644
--- a/clang/test/Driver/hip-sanitize-options.hip
+++ b/clang/test/Driver/hip-sanitize-options.hip
@@ -65,8 +65,8 @@
 // FAIL: AMDGPU address sanitizer runtime library (asanrtl) is not found. 
Please install ROCm device library which supports address sanitizer
 
 // XNACK-DAG: warning: ignoring '-fsanitize=leak' option as it is not 
currently supported for target 'amdgcn-amd-amdhsa'
-// XNACK-DAG: warning: ignoring '-fsanitize=address' option as it is not 
currently supported for offload arch 'gfx900:xnack-'. Use it with an offload 
arch containing 'xnack+' instead
-// XNACK-DAG: warning: ignoring '-fsanitize=address' option as it is not 
currently supported for offload arch 'gfx906'. Use it with an offload arch 
containing 'xnack+' instead
+// XNACK-DAG: warning: ignoring '-fsanitize=address' option for offload arch 
'gfx900:xnack-' as it is not currently supported there. Use it with an offload 
arch containing 'xnack+' instead
+// XNACK-DAG: warning: ignoring '-fsanitize=address' option for offload arch 
'gfx906' as it is not currently supported there. Use it with an offload arch 
containing 'xnack+' instead
 // XNACK-DAG: {{"[^"]*clang[^"]*".* "-mlink-bitcode-file" ".*asanrtl.bc".* 
"-target-cpu" "gfx900".* "-target-feature" "\+xnack".* "-fsanitize=address"}}
 // XNACK-DAG: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx900".* "-target-feature" 
"-xnack"}}
 // XNACK-DAG: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx906"}}
@@ -85,8 +85,8 @@
 // NOGPU-DAG: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx906"}}
 // NOGPU-DAG: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-fsanitize=address,leak"}}
 // NOGPUNEG-NOT: warning: ignoring '-fsanitize=leak' option as it is not 
currently supported for target 'amdgcn-amd-amdhsa'
-// NOGPUNEG-NOT: warning: ignoring '-fsanitize=address' option as it is not 
currently supported for offload arch 'gfx900:xnack-'. Use it with an offload 
arch containing 'xnack+' instead
-// NOGPUNEG-NOT: warning: ignoring '-fsanitize=address' option as it is not 
currently supported for offload arch 'gfx906'. Use it with an offload arch 
containing 'xnack+' instead
+// NOGPUNEG-NOT: warning: ignoring '-fsanitize=address' option for offload 
arch 'gfx900:xnack-' as it is not currently supported there. Use it with an 
offload arch containing 'xnack+' instead
+// NOGPUNEG-NOT: warning: ignoring '-fsanitize=address' option for offload 
arch 'gfx906' as it is not currently supported there. Use it with an offload 
arch containing 'xnack+' instead
 // NOGPUNEG-NOT: {{"[^"]*clang[^"]*".* "-mlink-bitcode-file" ".*asanrtl.bc".* 
"-target-cpu" "gfx900".* "-target-feature" "\+xnack".* "-fsanitize=address"}}
 // NOGPUNEG-NOT: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx900".* 
"-target-feature" "\+xnack".* "-fsanitize=address,leak"}}
 // NOGPUNEG-NOT: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx900".* 
"-target-feature" "-xnack".* "-fsanitize=address,leak"}}



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


[PATCH] D124396: [HIP] Fix diag msg about sanitizer

2022-04-26 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rGc89433d7fa10: [HIP] Fix diag msg about sanitizer (authored 
by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D124396?vs=424923&id=425212#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124396

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/test/Driver/hip-sanitize-options.hip


Index: clang/test/Driver/hip-sanitize-options.hip
===
--- clang/test/Driver/hip-sanitize-options.hip
+++ clang/test/Driver/hip-sanitize-options.hip
@@ -65,8 +65,8 @@
 // FAIL: AMDGPU address sanitizer runtime library (asanrtl) is not found. 
Please install ROCm device library which supports address sanitizer
 
 // XNACK-DAG: warning: ignoring '-fsanitize=leak' option as it is not 
currently supported for target 'amdgcn-amd-amdhsa'
-// XNACK-DAG: warning: ignoring '-fsanitize=address' option as it is not 
currently supported for offload arch 'gfx900:xnack-'. Use it with an offload 
arch containing 'xnack+' instead
-// XNACK-DAG: warning: ignoring '-fsanitize=address' option as it is not 
currently supported for offload arch 'gfx906'. Use it with an offload arch 
containing 'xnack+' instead
+// XNACK-DAG: warning: ignoring '-fsanitize=address' option for offload arch 
'gfx900:xnack-' as it is not currently supported there. Use it with an offload 
arch containing 'xnack+' instead
+// XNACK-DAG: warning: ignoring '-fsanitize=address' option for offload arch 
'gfx906' as it is not currently supported there. Use it with an offload arch 
containing 'xnack+' instead
 // XNACK-DAG: {{"[^"]*clang[^"]*".* "-mlink-bitcode-file" ".*asanrtl.bc".* 
"-target-cpu" "gfx900".* "-target-feature" "\+xnack".* "-fsanitize=address"}}
 // XNACK-DAG: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx900".* "-target-feature" 
"-xnack"}}
 // XNACK-DAG: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx906"}}
@@ -85,8 +85,8 @@
 // NOGPU-DAG: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx906"}}
 // NOGPU-DAG: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-fsanitize=address,leak"}}
 // NOGPUNEG-NOT: warning: ignoring '-fsanitize=leak' option as it is not 
currently supported for target 'amdgcn-amd-amdhsa'
-// NOGPUNEG-NOT: warning: ignoring '-fsanitize=address' option as it is not 
currently supported for offload arch 'gfx900:xnack-'. Use it with an offload 
arch containing 'xnack+' instead
-// NOGPUNEG-NOT: warning: ignoring '-fsanitize=address' option as it is not 
currently supported for offload arch 'gfx906'. Use it with an offload arch 
containing 'xnack+' instead
+// NOGPUNEG-NOT: warning: ignoring '-fsanitize=address' option for offload 
arch 'gfx900:xnack-' as it is not currently supported there. Use it with an 
offload arch containing 'xnack+' instead
+// NOGPUNEG-NOT: warning: ignoring '-fsanitize=address' option for offload 
arch 'gfx906' as it is not currently supported there. Use it with an offload 
arch containing 'xnack+' instead
 // NOGPUNEG-NOT: {{"[^"]*clang[^"]*".* "-mlink-bitcode-file" ".*asanrtl.bc".* 
"-target-cpu" "gfx900".* "-target-feature" "\+xnack".* "-fsanitize=address"}}
 // NOGPUNEG-NOT: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx900".* 
"-target-feature" "\+xnack".* "-fsanitize=address,leak"}}
 // NOGPUNEG-NOT: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx900".* 
"-target-feature" "-xnack".* "-fsanitize=address,leak"}}
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -107,8 +107,8 @@
   "a feature should either exist in all offload archs, or not exist in any "
   "offload archs)">;
 def warn_drv_unsupported_option_for_offload_arch_req_feature : Warning<
-  "ignoring '%0' option as it is not currently supported for "
-  "offload arch '%1'. Use it with an offload arch containing '%2' instead">,
+  "ignoring '%0' option for offload arch '%1' as it is not currently supported 
"
+  "there. Use it with an offload arch containing '%2' instead">,
   InGroup;
 def warn_drv_unsupported_option_for_target : Warning<
   "ignoring '%0' option as it is not currently supported for target '%1'">,


Index: clang/test/Driver/hip-sanitize-options.hip
===
--- clang/test/Driver/hip-sanitize-options.hip
+++ clang/test/Driver/hip-sanitize-options.hip
@@ -65,8 +65,8 @@
 // FAIL: AMDGPU address sanitizer runtime library (asanrtl) is not found. Please install ROCm device library which supports address sanitizer
 
 // XNACK-DAG: warning: ignoring '-fsanitize=leak' option as it is not currently supported for target 'amdgcn-am

[PATCH] D124220: [OpenMP] Add options to only compile the host or device when offloading

2022-04-26 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 425214.
jhuber6 added a comment.

Small change, returning an empty action type should let us stop without an 
extra check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124220

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/openmp-offload-gpu-new.c

Index: clang/test/Driver/openmp-offload-gpu-new.c
===
--- clang/test/Driver/openmp-offload-gpu-new.c
+++ clang/test/Driver/openmp-offload-gpu-new.c
@@ -3,7 +3,6 @@
 ///
 
 // REQUIRES: x86-registered-target
-// REQUIRES: powerpc-registered-target
 // REQUIRES: nvptx-registered-target
 // REQUIRES: amdgpu-registered-target
 
@@ -50,3 +49,18 @@
 // RUN:   | FileCheck -check-prefix=DRIVER_EMBEDDING %s
 
 // DRIVER_EMBEDDING: -fembed-offload-object=[[CUBIN:.*\.cubin]],openmp,nvptx64-nvidia-cuda,sm_70
+
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN: -foffload-host-only -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-HOST-ONLY
+// CHECK-HOST-ONLY: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.*]]"], output: "[[OUTPUT:.*]]"
+// CHECK-HOST-ONLY: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[OUTPUT]]"], output: "a.out"
+
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN: -foffload-device-only -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEVICE-ONLY
+// CHECK-DEVICE-ONLY: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.*]]"], output: "[[HOST_BC:.*]]"
+// CHECK-DEVICE-ONLY: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]", "[[HOST_BC]]"], output: "[[DEVICE_ASM:.*]]"
+// CHECK-DEVICE-ONLY: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[DEVICE_ASM]]"], output: "{{.*}}-openmp-nvptx64-nvidia-cuda.o"
+
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN: -foffload-device-only -E -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEVICE-ONLY-PP
+// CHECK-DEVICE-ONLY-PP: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.*]]"], output: "-"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4052,11 +4052,6 @@
 break;
   }
 
-  // Try to build the offloading actions and add the result as a dependency
-  // to the host.
-  if (UseNewOffloadingDriver)
-Current = BuildOffloadingActions(C, Args, I, Current);
-
   // FIXME: Should we include any prior module file outputs as inputs of
   // later actions in the same command line?
 
@@ -4080,6 +4075,11 @@
 if (OffloadBuilder.addHostDependenceToDeviceActions(Current, InputArg))
   break;
 
+  // Try to build the offloading actions and add the result as a dependency
+  // to the host.
+  if (UseNewOffloadingDriver)
+Current = BuildOffloadingActions(C, Args, I, Current);
+
   if (Current->getType() == types::TY_Nothing)
 break;
 }
@@ -4212,14 +4212,19 @@
llvm::opt::DerivedArgList &Args,
const InputTy &Input,
Action *HostAction) const {
-  if (!isa(HostAction))
+  if (Args.hasArg(options::OPT_foffload_host_only))
 return HostAction;
 
-  OffloadAction::DeviceDependences DDeps;
-
   types::ID InputType = Input.first;
   const Arg *InputArg = Input.second;
 
+  auto PL = types::getCompilationPhases(*this, Args, InputType);
+
+  if (!isa(HostAction) && PL.back() != phases::Preprocess)
+return HostAction;
+
+  OffloadAction::DeviceDependences DDeps;
+
   const Action::OffloadKind OffloadKinds[] = {Action::OFK_OpenMP};
 
   for (Action::OffloadKind Kind : OffloadKinds) {
@@ -4239,8 +4244,6 @@
 if (DeviceActions.empty())
   return HostAction;
 
-auto PL = types::getCompilationPhases(*this, Args, InputType);
-
 for (phases::ID Phase : PL) {
   if (Phase == phases::Link) {
 assert(Phase == PL.back() && "linking must be final compilation step.");
@@ -4251,7 +4254,8 @@
   for (Action *&A : DeviceActions) {
 A = ConstructPhaseAction(C, Args, Phase, A, Kind);
 
-if (isa(A) && Kind == Action::OFK_OpenMP) {
+if (isa(A) && isa(HostAction) &&
+Kind == Action::OFK_OpenMP) {
   HostAction->setCannotBeCollapsedWithNextDependentAction();
   OffloadAction::HostDependence HDep(
   *HostAction, *C.getSingleOffloadToolChain(),
@@ -4271,6 +4275,9 @@
 }
   }
 
+  if (Args.hasArg(options::OPT_foffload_device_only))
+return C.MakeAction(DDeps, types::TY_Nothing);
+
   Offloa

[PATCH] D123783: [clang] Eliminate TypeProcessingState::trivial.

2022-04-26 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, thank you for the cleanup!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123783

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


[PATCH] D124128: Thread safety analysis: Store CapabilityExprs in ScopedLockableFactEntry (NFC)

2022-04-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Continues to LGTM




Comment at: clang/lib/Analysis/ThreadSafety.cpp:911-919
+UnderlyingMutexes.push_back(UnderlyingCapability{M, UCK_Acquired});
   }
 
   void addExclusiveUnlock(const CapabilityExpr &M) {
-UnderlyingMutexes.emplace_back(M.sexpr(), UCK_ReleasedExclusive);
+UnderlyingMutexes.push_back(UnderlyingCapability{M, 
UCK_ReleasedExclusive});
   }
 

aaronpuchert wrote:
> aaron.ballman wrote:
> > I think we can continue to use `emplace_back()` here, can't we?
> For `emplace_back` we need a constructor and can't just do aggregate 
> initialization. But I could omit the explicit type, like 
> `UnderlyingMutexes.push_back({M, UCK_*})`.
Ah good point. No need to change anything, I was just hoping to be able to 
construct in place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124128

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


[clang] 2fb1316 - [OpenMP] Fix incorrect path taken when searching for LLD for offloading

2022-04-26 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-04-26T10:51:04-04:00
New Revision: 2fb131668fff921dcfedb0b22efb908cc794c07f

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

LOG: [OpenMP] Fix incorrect path taken when searching for LLD for offloading

Summary:
A previous patch updated the path searching in the linker wrapper. I
made an error and caused `lld`, which is necessary to link AMDGPU
images, to not be found on some systems. This patch fixes this by
correctly searching that linker-wrapper's binary path first again.

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 2c14c893c6424..09381d93f17df 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -684,7 +684,8 @@ namespace amdgcn {
 Expected link(ArrayRef InputFiles, Triple TheTriple,
StringRef Arch) {
   // AMDGPU uses lld to link device object files.
-  Expected LLDPath = findProgram("lld", {CudaBinaryPath});
+  Expected LLDPath =
+  findProgram("lld", {getMainExecutable("lld")});
   if (!LLDPath)
 return LLDPath.takeError();
 



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


[PATCH] D124395: [clang][dataflow] Optimize flow condition representation

2022-04-26 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 425221.
sgatev marked 4 inline comments as done.
sgatev added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124395

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -90,4 +90,54 @@
   EXPECT_NE(&NotX1, &NotY);
 }
 
+TEST_F(DataflowAnalysisContextTest, EmptyFlowCondition) {
+  auto &FC = Context.makeFlowConditionToken();
+  auto &C = Context.createAtomicBoolValue();
+  EXPECT_FALSE(Context.flowConditionImplies(FC, C));
+}
+
+TEST_F(DataflowAnalysisContextTest, AddFlowConditionConstraint) {
+  auto &FC = Context.makeFlowConditionToken();
+  auto &C = Context.createAtomicBoolValue();
+  Context.addFlowConditionConstraint(FC, C);
+  EXPECT_TRUE(Context.flowConditionImplies(FC, C));
+}
+
+TEST_F(DataflowAnalysisContextTest, ForkFlowCondition) {
+  auto &FC1 = Context.makeFlowConditionToken();
+  auto &C1 = Context.createAtomicBoolValue();
+  Context.addFlowConditionConstraint(FC1, C1);
+
+  // Forked flow condition inherits the constraints of its parent flow
+  // condition.
+  auto &FC2 = Context.forkFlowCondition(FC1);
+  EXPECT_TRUE(Context.flowConditionImplies(FC2, C1));
+
+  // Adding a new constraint to the forked flow condition does not affect its
+  // parent flow condition.
+  auto &C2 = Context.createAtomicBoolValue();
+  Context.addFlowConditionConstraint(FC2, C2);
+  EXPECT_TRUE(Context.flowConditionImplies(FC2, C2));
+  EXPECT_FALSE(Context.flowConditionImplies(FC1, C2));
+}
+
+TEST_F(DataflowAnalysisContextTest, JoinFlowConditions) {
+  auto &C1 = Context.createAtomicBoolValue();
+  auto &C2 = Context.createAtomicBoolValue();
+  auto &C3 = Context.createAtomicBoolValue();
+
+  auto &FC1 = Context.makeFlowConditionToken();
+  Context.addFlowConditionConstraint(FC1, C1);
+  Context.addFlowConditionConstraint(FC1, C3);
+
+  auto &FC2 = Context.makeFlowConditionToken();
+  Context.addFlowConditionConstraint(FC2, C2);
+  Context.addFlowConditionConstraint(FC2, C3);
+
+  auto &FC3 = Context.joinFlowConditions(FC1, FC2);
+  EXPECT_FALSE(Context.flowConditionImplies(FC3, C1));
+  EXPECT_FALSE(Context.flowConditionImplies(FC3, C2));
+  EXPECT_TRUE(Context.flowConditionImplies(FC3, C3));
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -76,33 +76,14 @@
   Environment &MergedEnv,
   Environment::ValueModel &Model) {
   // Join distinct boolean values preserving information about the constraints
-  // in the respective path conditions. Note: this construction can, in
-  // principle, result in exponential growth in the size of boolean values.
-  // Potential optimizations may be worth considering. For example, represent
-  // the flow condition of each environment using a bool atom and store, in
-  // `DataflowAnalysisContext`, a mapping of bi-conditionals between flow
-  // condition atoms and flow condition constraints. Something like:
-  // \code
-  //   FC1 <=> C1 ^ C2
-  //   FC2 <=> C2 ^ C3 ^ C4
-  //   FC3 <=> (FC1 v FC2) ^ C5
-  // \code
-  // Then, we can track dependencies between flow conditions (e.g. above `FC3`
-  // depends on `FC1` and `FC2`) and modify `flowConditionImplies` to construct
-  // a formula that includes the bi-conditionals for all flow condition atoms in
-  // the transitive set, before invoking the solver.
+  // in the respective path conditions.
   //
   // FIXME: Does not work for backedges, since the two (or more) paths will not
   // have mutually exclusive conditions.
   if (auto *Expr1 = dyn_cast(Val1)) {
-for (BoolValue *Constraint : Env1.getFlowConditionConstraints()) {
-  Expr1 = &MergedEnv.makeAnd(*Expr1, *Constraint);
-}
 auto *Expr2 = cast(Val2);
-for (BoolValue *Constraint : Env2.getFlowConditionConstraints()) {
-  Expr2 = &MergedEnv.makeAnd(*Expr2, *Constraint);
-}
-return &MergedEnv.makeOr(*Expr1, *Expr2);
+return &Env1.makeOr(Env1.makeAnd(Env1.getFlowConditionToken(), *Expr1),
+Env1.makeAnd(Env2.getFlowConditionToken(), *Expr2));
   }
 
   // FIXME: Consider destroying `MergedValue` im

[PATCH] D124395: [clang][dataflow] Optimize flow condition representation

2022-04-26 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev marked an inline comment as done.
sgatev added a comment.

In D124395#3474597 , @ymandel wrote:

> Nice work. On the surface, this adds complexity to the system and so should 
> be justified in terms of performance improvements. However, having read 
> through the patch, I think it overall reduces the complexity, since both 
> environment join and boolean-value join have been radically simplified.  So, 
> I'm fine with the patch as is, even without performance measurement. That 
> said, I'm not against such measurement -- just saying it's not blocking. :)
>
> If you agree, you may want to reword the description of the patch to focuse 
> on the design improvements rather than (exclusively) the optimization aspect.

Agreed. I updated the description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124395

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


[PATCH] D124316: [clang-tidy] Modernize-macro-to-enum should skip macros used in other macros

2022-04-26 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 with a few small nits.




Comment at: clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp:230
+  void rememberExpressionName(const Token &Tok);
+  void rememberExpressionTokens(const ArrayRef &MacroTokens);
   void invalidateExpressionNames();

`ArrayRef` is intended to be cheap in the same way as `StringRef`, so we don't 
pass const references for it.



Comment at: clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp:316-318
+  for (Token Tok : MacroTokens)
+if (Tok.isAnyIdentifier())
+  rememberExpressionName(Tok);

I know the coding guide says we can elide braces there, but because the for 
loop substatement is multiple lines, I think braces help readability.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124316

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


[PATCH] D119544: Deferred Concept Instantiation Implementation

2022-04-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I found




Comment at: clang/test/SemaTemplate/concepts.cpp:386-388
+  []()
+requires(constraint)
+  {}();

erichkeane wrote:
> ChuanqiXu wrote:
> > We might need more negative tests.
> > Now it would pass even if I write:
> > ```
> > []()
> > requires(false)
> > {}();
> > ```
> Ouch!  I'll have to see if I can find where we're missing that check!
Well, I fixed most of the OTHER stuff I think by setting up the context 
properly (see incoming patch!), but this ends up failing crashing, as does a 
few other things in this test.  Still looking through it, but want to get you 
the latest.


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

https://reviews.llvm.org/D119544

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


[PATCH] D119544: Deferred Concept Instantiation Implementation

2022-04-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 425224.
erichkeane added a comment.

Now crashes a few times in concepts.cpp, but sets up the instantiation-scope 
for functions such that local variable references work for them.


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

https://reviews.llvm.org/D119544

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CXX/temp/temp.constr/temp.constr.constr/non-function-templates.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/test/SemaTemplate/deferred-concept-inst.cpp
  clang/test/SemaTemplate/instantiate-requires-clause.cpp
  clang/test/SemaTemplate/trailing-return-short-circuit.cpp

Index: clang/test/SemaTemplate/trailing-return-short-circuit.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/trailing-return-short-circuit.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+template 
+  requires(sizeof(T) > 2) || T::value // #FOO_REQ
+void Foo(T){};// #FOO
+
+template 
+void TrailingReturn(T)   // #TRAILING
+  requires(sizeof(T) > 2) || // #TRAILING_REQ
+  T::value   // #TRAILING_REQ_VAL
+{};
+template 
+struct HasValue {
+  static constexpr bool value = B;
+};
+static_assert(sizeof(HasValue) <= 2);
+
+template 
+struct HasValueLarge {
+  static constexpr bool value = B;
+  int I;
+};
+static_assert(sizeof(HasValueLarge) > 2);
+
+void usage() {
+  // Passes the 1st check, short-circuit so the 2nd ::value is not evaluated.
+  Foo(1.0);
+  TrailingReturn(1.0);
+
+  // Fails the 1st check, but has a ::value, so the check happens correctly.
+  Foo(HasValue{});
+  TrailingReturn(HasValue{});
+
+  // Passes the 1st check, but would have passed the 2nd one.
+  Foo(HasValueLarge{});
+  TrailingReturn(HasValueLarge{});
+
+  // Fails the 1st check, fails 2nd because there is no ::value.
+  Foo(true);
+  // expected-error@-1{{no matching function for call to 'Foo'}}
+  // expected-note@#FOO{{candidate template ignored: constraints not satisfied [with T = bool]}}
+  // expected-note@#FOO_REQ{{because 'sizeof(_Bool) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#FOO_REQ{{because substituted constraint expression is ill-formed: type 'bool' cannot be used prior to '::' because it has no members}}
+
+  TrailingReturn(true);
+  // expected-error@-1{{no matching function for call to 'TrailingReturn'}}
+  // expected-note@#TRAILING{{candidate template ignored: constraints not satisfied [with T = bool]}}
+  // expected-note@#TRAILING_REQ{{because 'sizeof(_Bool) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#TRAILING_REQ_VAL{{because substituted constraint expression is ill-formed: type 'bool' cannot be used prior to '::' because it has no members}}
+
+  // Fails the 1st check, fails 2nd because ::value is false.
+  Foo(HasValue{});
+  // expected-error@-1 {{no matching function for call to 'Foo'}}
+  // expected-note@#FOO{{candidate template ignored: constraints not satisfied [with T = HasValue]}}
+  // expected-note@#FOO_REQ{{because 'sizeof(HasValue) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#FOO_REQ{{and 'HasValue::value' evaluated to false}}
+  TrailingReturn(HasValue{});
+  // expected-error@-1 {{no matching function for call to 'TrailingReturn'}}
+  // expected-note@#TRAILING{{candidate template ignored: constraints not satisfied [with T = HasValue]}}
+  // expected-note@#TRAILING_REQ{{because 'sizeof(HasValue) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#TRAILING_REQ_VAL{{and 'HasValue::value' evaluated to false}}
+}
Index: clang/test/SemaTemplate/instantiate-requires-clause.cpp
===
--- clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++2a -x c++ %s -verify
+// RUN: %clang_cc1 -std=c++2a -x c++ %s -Wno-unused-value -verify
 
 template  requires ((sizeof(Args) == 1), ...)
 // expected-note@-1 {{because '(sizeof(int) == 1) , (sizeof(char) == 1) , (sizeof(int) == 1)' evaluated to false}}
@@ -40,6 +40,20 @@
 
 static_assert(S::f(1));
 
+// Similar to the 'S' test, but tries to use 'U' in the requires clause.
+template 
+struct S1 {
+  // expected-note@+3 {{candidate template ignored: constraints not satisfied [with U = int]}}
+  // expected-note@+3 {{

[PATCH] D119544: Deferred Concept Instantiation Implementation

2022-04-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:507
+
+  ContextRAII SavedContext{*this, const_cast(FD)};
+  LocalInstantiationScope Scope(*this, true);

This line was the one that fixed the variable lookup in non-templates.


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

https://reviews.llvm.org/D119544

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


[clang] 9b38e2e - [SystemZ] Fix C++ ABI for passing args of structs containing zero width bitfield.

2022-04-26 Thread Jonas Paulsson via cfe-commits

Author: Jonas Paulsson
Date: 2022-04-26T17:16:14+02:00
New Revision: 9b38e2efa0f0c819ec696d13731ac1ce08f81930

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

LOG: [SystemZ] Fix C++ ABI for passing args of structs containing zero width 
bitfield.

A struct like { float a; int :0; } should per the SystemZ ABI be passed in a
GPR, but to match a bug in GCC it has been passed in an FPR (see 759449c).

GCC has now corrected the C++ ABI for this case, and this patch for clang
follows suit.

Reviewed By: Ulrich Weigand

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

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/SystemZ/systemz-abi.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index c5a031d5487cf..ecbb3505bb91c 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -7514,12 +7514,9 @@ QualType SystemZABIInfo::GetSingleElementType(QualType 
Ty) const {
 
 // Check the fields.
 for (const auto *FD : RD->fields()) {
-  // For compatibility with GCC, ignore empty bitfields in C++ mode.
   // Unlike isSingleElementStruct(), empty structure and array fields
   // do count.  So do anonymous bitfields that aren't zero-sized.
-  if (getContext().getLangOpts().CPlusPlus &&
-  FD->isZeroLengthBitField(getContext()))
-continue;
+
   // Like isSingleElementStruct(), ignore C++20 empty data members.
   if (FD->hasAttr() &&
   isEmptyRecord(getContext(), FD->getType(), true))

diff  --git a/clang/test/CodeGen/SystemZ/systemz-abi.cpp 
b/clang/test/CodeGen/SystemZ/systemz-abi.cpp
index 9a0b2e39c6070..a76bba3561b44 100644
--- a/clang/test/CodeGen/SystemZ/systemz-abi.cpp
+++ b/clang/test/CodeGen/SystemZ/systemz-abi.cpp
@@ -15,12 +15,10 @@ class agg_double_class pass_agg_double_class(class 
agg_double_class arg) { retur
 // SOFT-FLOAT-LABEL: define{{.*}} void 
@_Z21pass_agg_double_class16agg_double_class(%class.agg_double_class* noalias 
sret(%class.agg_double_class) align 8 %{{.*}}, i64 %{{.*}})
 
 
-// For compatibility with GCC, this structure is passed in an FPR in C++,
-// but passed in a GPR in C (checked in systemz-abi.c).
-
+// This structure is passed in a GPR in C++ (and C, checked in systemz-abi.c).
 struct agg_float_cpp { float a; int : 0; };
 struct agg_float_cpp pass_agg_float_cpp(struct agg_float_cpp arg) { return 
arg; }
-// CHECK-LABEL: define{{.*}} void 
@_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias 
sret(%struct.agg_float_cpp) align 4 %{{.*}}, float %{{.*}})
+// CHECK-LABEL: define{{.*}} void 
@_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias 
sret(%struct.agg_float_cpp) align 4 %{{.*}}, i32 %{{.*}})
 // SOFT-FLOAT-LABEL:  define{{.*}} void 
@_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias 
sret(%struct.agg_float_cpp) align 4 %{{.*}}, i32 %{{.*}})
 
 



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


[PATCH] D122388: [SystemZ] Fix C++ ABI for passing args of structs containing zero width bitfield.

2022-04-26 Thread Jonas Paulsson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9b38e2efa0f0: [SystemZ] Fix C++ ABI for passing args of 
structs containing zero width… (authored by jonpa).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122388

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/SystemZ/systemz-abi.cpp


Index: clang/test/CodeGen/SystemZ/systemz-abi.cpp
===
--- clang/test/CodeGen/SystemZ/systemz-abi.cpp
+++ clang/test/CodeGen/SystemZ/systemz-abi.cpp
@@ -15,12 +15,10 @@
 // SOFT-FLOAT-LABEL: define{{.*}} void 
@_Z21pass_agg_double_class16agg_double_class(%class.agg_double_class* noalias 
sret(%class.agg_double_class) align 8 %{{.*}}, i64 %{{.*}})
 
 
-// For compatibility with GCC, this structure is passed in an FPR in C++,
-// but passed in a GPR in C (checked in systemz-abi.c).
-
+// This structure is passed in a GPR in C++ (and C, checked in systemz-abi.c).
 struct agg_float_cpp { float a; int : 0; };
 struct agg_float_cpp pass_agg_float_cpp(struct agg_float_cpp arg) { return 
arg; }
-// CHECK-LABEL: define{{.*}} void 
@_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias 
sret(%struct.agg_float_cpp) align 4 %{{.*}}, float %{{.*}})
+// CHECK-LABEL: define{{.*}} void 
@_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias 
sret(%struct.agg_float_cpp) align 4 %{{.*}}, i32 %{{.*}})
 // SOFT-FLOAT-LABEL:  define{{.*}} void 
@_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias 
sret(%struct.agg_float_cpp) align 4 %{{.*}}, i32 %{{.*}})
 
 
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7514,12 +7514,9 @@
 
 // Check the fields.
 for (const auto *FD : RD->fields()) {
-  // For compatibility with GCC, ignore empty bitfields in C++ mode.
   // Unlike isSingleElementStruct(), empty structure and array fields
   // do count.  So do anonymous bitfields that aren't zero-sized.
-  if (getContext().getLangOpts().CPlusPlus &&
-  FD->isZeroLengthBitField(getContext()))
-continue;
+
   // Like isSingleElementStruct(), ignore C++20 empty data members.
   if (FD->hasAttr() &&
   isEmptyRecord(getContext(), FD->getType(), true))


Index: clang/test/CodeGen/SystemZ/systemz-abi.cpp
===
--- clang/test/CodeGen/SystemZ/systemz-abi.cpp
+++ clang/test/CodeGen/SystemZ/systemz-abi.cpp
@@ -15,12 +15,10 @@
 // SOFT-FLOAT-LABEL: define{{.*}} void @_Z21pass_agg_double_class16agg_double_class(%class.agg_double_class* noalias sret(%class.agg_double_class) align 8 %{{.*}}, i64 %{{.*}})
 
 
-// For compatibility with GCC, this structure is passed in an FPR in C++,
-// but passed in a GPR in C (checked in systemz-abi.c).
-
+// This structure is passed in a GPR in C++ (and C, checked in systemz-abi.c).
 struct agg_float_cpp { float a; int : 0; };
 struct agg_float_cpp pass_agg_float_cpp(struct agg_float_cpp arg) { return arg; }
-// CHECK-LABEL: define{{.*}} void @_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias sret(%struct.agg_float_cpp) align 4 %{{.*}}, float %{{.*}})
+// CHECK-LABEL: define{{.*}} void @_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias sret(%struct.agg_float_cpp) align 4 %{{.*}}, i32 %{{.*}})
 // SOFT-FLOAT-LABEL:  define{{.*}} void @_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias sret(%struct.agg_float_cpp) align 4 %{{.*}}, i32 %{{.*}})
 
 
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7514,12 +7514,9 @@
 
 // Check the fields.
 for (const auto *FD : RD->fields()) {
-  // For compatibility with GCC, ignore empty bitfields in C++ mode.
   // Unlike isSingleElementStruct(), empty structure and array fields
   // do count.  So do anonymous bitfields that aren't zero-sized.
-  if (getContext().getLangOpts().CPlusPlus &&
-  FD->isZeroLengthBitField(getContext()))
-continue;
+
   // Like isSingleElementStruct(), ignore C++20 empty data members.
   if (FD->hasAttr() &&
   isEmptyRecord(getContext(), FD->getType(), true))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123300: [Clang] Enable opaque pointers by default

2022-04-26 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

@yurai007 I've put up https://reviews.llvm.org/D124459 to fix this optimization 
failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123300

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


[PATCH] D119544: Deferred Concept Instantiation Implementation

2022-04-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:507
+
+  ContextRAII SavedContext{*this, const_cast(FD)};
+  LocalInstantiationScope Scope(*this, true);

erichkeane wrote:
> This line was the one that fixed the variable lookup in non-templates.
By changing `FD` to `FD->GetNonClosureContext` (with the appropriate casts), I 
was at least able to fix the crash.  The constraint not being checked for 
failure however, is still a problem.


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

https://reviews.llvm.org/D119544

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


[PATCH] D118409: [OpenMPIRBuilder] Remove ContinuationBB argument from Body callback.

2022-04-26 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

In D118409#3474131 , 
@kiranchandramohan wrote:

> I think the CI is complaining about some clang-format issue in  
> clang/test/OpenMP/critical_codegen_attr.cpp

clang-format should not be applied on Clang tests, many of them have 
significant whitespace (eg. the preprocessor tests). In this case, all that 
clang-format suggests is

  diff --git a/clang/test/OpenMP/critical_codegen.cpp 
b/clang/test/OpenMP/critical_codegen.cpp
  index 41454b6dd1b4..d472325ff8a2 100644
  --- a/clang/test/OpenMP/critical_codegen.cpp
  +++ b/clang/test/OpenMP/critical_codegen.cpp
  @@ -22,7 +22,10 @@
  -void foo() { extern void mayThrow(); mayThrow(); }
  +void foo() {
  +  extern void mayThrow();
  +  mayThrow();
  +}

These lines were not changed in this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118409

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


[PATCH] D112921: [clang] Enable sized deallocation by default in C++14 onwards

2022-04-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Hmm.  Allowing a version on `-stdlib` is intuitively appealing, but I'm not 
sure it actually gives us the information we need.  As I recall, `-stdlib` 
selects the high-level stdlib and not the low-level one, and those are related 
in code but not necessarily at runtime; for example, you can (or at least 
could, historically) use libstdc++ on macOS, but the underlying low-level 
stdlib is going to be libc++abi, not libsupc++.  And the low-level runtime is 
the one that actually provides global `operator new` functions.  Is there a way 
to bridge that gap?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112921

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-04-26 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Size still seems moderately concerning, but might be acceptable.

Got a summary of what the DWARF looks like now (without names)? (maybe there's 
something else we can strip/optimize)

& how many of these descriptions get added to the debug info?

Numbers for Split DWARF may be helpful too - given this'll add an extra 
address/relocation for every string literal, it might make object size 
(specifically unlinked object size where relocations are expensive/plentiful) 
significantly larger in problematic ways.




Comment at: clang/test/CodeGen/debug-info-variables.c:1
+// RUN: %clang_cc1 %s -debug-info-kind=standalone -S -emit-llvm -o - | 
FileCheck %s
+

Presumably named variables are already tested elsewhere - so I probably 
wouldn't test them here, and would give this file a more specific name related 
to string literals. Alternatively/perhaps the other thing to do would be to 
find some test that already covers global variable debug info, and test string 
literals there?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D103096: [analyzer] Implement cast for ranges of symbolic integers

2022-04-26 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 425248.
ASDenysPetrov marked 4 inline comments as done.
ASDenysPetrov edited the summary of this revision.
ASDenysPetrov added a comment.

@martong thank you for the idea. I've tried to implement it. Could you look at 
the patch once again, please?


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

https://reviews.llvm.org/D103096

Files:
  clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
  clang/test/Analysis/symbol-integral-cast.cpp

Index: clang/test/Analysis/symbol-integral-cast.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-integral-cast.cpp
@@ -0,0 +1,374 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -analyzer-config eagerly-assume=false -analyzer-config support-symbolic-integer-casts=true -verify %s
+
+template 
+void clang_analyzer_eval(T);
+void clang_analyzer_warnIfReached();
+
+typedef short int16_t;
+typedef int int32_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+
+void test1(int x) {
+  // Even if two lower bytes of `x` equal to zero, it doesn't mean that
+  // the entire `x` is zero. We are not able to know the exact value of x.
+  // It can be one of  65536 possible values like [0, 65536, 131072, ...]
+  // and so on. To avoid huge range sets we still assume `x` in the range
+  // [INT_MIN, INT_MAX].
+  if (!(short)x) {
+if (!x)
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test2(int x) {
+  // If two lower bytes of `x` equal to zero, and we know x to be 65537,
+  // which is not truncated to short as zero. Thus the branch is infisible.
+  short s = x;
+  if (!s) {
+if (x == 65537)
+  clang_analyzer_warnIfReached(); // no-warning
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test3(int x, short s) {
+  s = x;
+  if ((short)x > -10 && s < 10) {
+if (x > 0 && x < 10) {
+  // If the range of the whole variable was constrained then reason again
+  // about truncated bytes to make the ranges more precise.
+  clang_analyzer_eval((short)x <= 0); // expected-warning {{FALSE}}
+}
+  }
+}
+
+void test4(unsigned x) {
+  if ((char)x > 8) {
+// Constraint the range of the lowest byte of `x` to [9, CHAR_MAX].
+// The original range of `x` still remains [0, UINT_MAX].
+clang_analyzer_eval((char)x < 42); // expected-warning {{UNKNOWN}}
+if (x < 42) {
+  // Constraint the original range to [0, 41] and update (re-constraint)
+  // the range of the lowest byte of 'x' to [9, 41].
+  clang_analyzer_eval((char)x < 42); // expected-warning {{TRUE}}
+}
+  }
+}
+
+void test5(unsigned x) {
+  if ((char)x > -10 && (char)x < 10) {
+if ((short)x == 8) {
+  // If the range of higher bytes(short) was constrained then reason again
+  // about smaller truncated ranges(char) to make it more precise.
+  clang_analyzer_eval((char)x == 8);  // expected-warning {{TRUE}}
+  clang_analyzer_eval((short)x == 8); // expected-warning {{TRUE}}
+  // We still assume full version of `x` in the range [INT_MIN, INT_MAX].
+  clang_analyzer_eval(x == 8); // expected-warning {{UNKNOWN}}
+}
+  }
+}
+
+void test6(int x) {
+  // Even if two lower bytes of `x` less than zero, it doesn't mean that `x`
+  // can't be greater than zero. Thence we don't change the native range of
+  // `x` and this branch is feasible.
+  if (x > 0)
+if ((short)x < 0)
+  clang_analyzer_eval(x > 0); // expected-warning {{TRUE}}
+}
+
+void test7(int x) {
+  // The range of two lower bytes of `x` [1, SHORT_MAX] is enough to cover
+  // all possible values of char [CHAR_MIN, CHAR_MAX]. So the lowest byte
+  // can be lower than zero.
+  if ((short)x > 0) {
+if ((char)x < 0)
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test8(int x) {
+  // Promotion from `signed int` to `signed long long` also reasoning about the
+  // original range, because we know the fact that even after promotion it
+  // remains in the range [INT_MIN, INT_MAX].
+  if ((long long)x < 0)
+clang_analyzer_eval(x < 0); // expected-warning {{TRUE}}
+}
+
+void test9(signed int x) {
+  // Any cast `signed` to `unsigned` produces an unsigned range, which is
+  // [0, UNSIGNED_MAX] and can not be lower than zero.
+  if ((unsigned long long)x < 0)
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+
+  if ((unsig

[PATCH] D124158: [Clang][Attr] Skip adding noundef attribute to arguments when function has convergent attribute

2022-04-26 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2435
 DetermineNoUndef(ParamType, getTypes(), DL, AI)) {
-  Attrs.addAttribute(llvm::Attribute::NoUndef);
+  if(!FuncAttrs.contains(llvm::Attribute::Convergent))
+Attrs.addAttribute(llvm::Attribute::NoUndef);

Missing space before (.
 
Needs comment explaining this



Comment at: 
llvm/test/Transforms/SimplifyCFG/tautological-conditional-branch-convergent-noundef.ll:26
+  %i3 = phi double [%i2, %bb2], [undef, %bb1] 
+  %i4 = call noundef double @two(double %i3, i1 %i1) 
+  ret void

Aren't the cases with defined handling of undef lanes still defined for the 
result?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124158

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


[PATCH] D123319: Change how we handle auto return types for lambda operator() to be consistent with gcc

2022-04-26 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D123319#3473693 , @shafik wrote:

> In D123319#3473283 , @dblaikie 
> wrote:
>
>> ('scuse the delay)
>>
>> Baseline: I'm still not really sure this is the right direction. Is there a 
>> sound argument for why this change is suitable for lambdas, but not for 
>> other types? I believe all the situations that can happen with other types 
>> can happen with lambdas (& the other way around) with sufficiently 
>> interestingly crafted inputs.
>
> I had a couple of approaches but once I saw how gcc was handling it, I just 
> went with consistency with gcc. I might have been missing some cases but I 
> did not have other test case that I ran into issues with.

What's the basic reproduction of the issue? Using that I can probably produce a 
non-lambda example that tickles the same bug & demonstrates why this should be 
generalized and/or fixed in lldb instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123319

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


[PATCH] D123436: [Clang] Use std::move in GlobalModuleIndex::readIndex. NFC

2022-04-26 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D123436#3462567 , @dblaikie wrote:

> Perhaps GlobalModuleIndex should create the cursor itself - it's being handed 
> the buffer anyway?

Ping on this ^ - would this be a better direction that addresses the concerns?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436

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


[PATCH] D124434: [Clang][Test] Run tests in C++14 mode explicitly.

2022-04-26 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added subscribers: aaron.ballman, rsmith.
dblaikie added a comment.

@rsmith @aaron.ballman - might be especially interesting to know your thoughts 
on the C++ chapter-based testing and what the intent there is as clang changes 
default versions/new versions are added. (& also whether there's an approach 
(like moving the default language into the driver) that'd be worthwhile to 
lower the maintenance cost of these sort of migrations without compromising on 
test coverage/ending up with all the test coverage testing previous versions of 
the language and not what everyone's using in the wild)




Comment at: clang/test/CXX/class.access/class.friend/p1.cpp:4
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
-// RUN: %clang_cc1 -fsyntax-only -verify %s
 

Might be worth knowing the version history of tests like this? (in here and 
other test files) - perhaps the intent is for this test to check the code is 
valid in all language versions & so should grow more explicit version lines as 
the language evolves?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124434

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


[PATCH] D124466: [CUDA][HIP] Fix linkage of __clang_gpu_used_external

2022-04-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added a subscriber: mattd.
Herald added a project: All.
yaxunl requested review of this revision.

Different TU's may have this globl var. appending linkage can
only be used with lld recognized special variables.

Change it to internal linkage.


https://reviews.llvm.org/D124466

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/host-used-extern.cu


Index: clang/test/CodeGenCUDA/host-used-extern.cu
===
--- clang/test/CodeGenCUDA/host-used-extern.cu
+++ clang/test/CodeGenCUDA/host-used-extern.cu
@@ -11,7 +11,7 @@
 
 #include "Inputs/cuda.h"
 
-// CHECK-LABEL: @__clang_gpu_used_external = appending {{.*}}global
+// CHECK-LABEL: @__clang_gpu_used_external = internal {{.*}}global
 // CHECK-DAG: @_Z7kernel1v
 // CHECK-DAG: @_Z7kernel4v
 // CHECK-DAG: @var1
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -599,7 +599,7 @@
 llvm::ArrayType *ATy = llvm::ArrayType::get(Int8PtrTy, UsedArray.size());
 
 auto *GV = new llvm::GlobalVariable(
-getModule(), ATy, false, llvm::GlobalValue::AppendingLinkage,
+getModule(), ATy, false, llvm::GlobalValue::InternalLinkage,
 llvm::ConstantArray::get(ATy, UsedArray), "__clang_gpu_used_external");
 addCompilerUsedGlobal(GV);
   }


Index: clang/test/CodeGenCUDA/host-used-extern.cu
===
--- clang/test/CodeGenCUDA/host-used-extern.cu
+++ clang/test/CodeGenCUDA/host-used-extern.cu
@@ -11,7 +11,7 @@
 
 #include "Inputs/cuda.h"
 
-// CHECK-LABEL: @__clang_gpu_used_external = appending {{.*}}global
+// CHECK-LABEL: @__clang_gpu_used_external = internal {{.*}}global
 // CHECK-DAG: @_Z7kernel1v
 // CHECK-DAG: @_Z7kernel4v
 // CHECK-DAG: @var1
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -599,7 +599,7 @@
 llvm::ArrayType *ATy = llvm::ArrayType::get(Int8PtrTy, UsedArray.size());
 
 auto *GV = new llvm::GlobalVariable(
-getModule(), ATy, false, llvm::GlobalValue::AppendingLinkage,
+getModule(), ATy, false, llvm::GlobalValue::InternalLinkage,
 llvm::ConstantArray::get(ATy, UsedArray), "__clang_gpu_used_external");
 addCompilerUsedGlobal(GV);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124341: [clang-tidy][NFC] Replace many instances of std::string where a StringRef would suffice.

2022-04-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I went through the changes and they look correct to me... yet I'm still mildly 
terrified. :-D Have you tried running clang-tidy through its paces with 
ASan/MSan enabled to see if the change introduces any use-after-free issues in 
practice?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124341

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


[PATCH] D120272: [CUDA] Add driver support for compiling CUDA with the new driver

2022-04-26 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 425261.
jhuber6 added a comment.

Changing this to simply require that the user manually passes `-fgpu-rdc` in 
order to use the new driver. I think this makes more sense in the short term 
and we can move to make the new driver the default rdc approach later. I tested 
this and the following should workd,

  clang foo.cu -fgpu-rdc -foffload-new-driver -c
  clang bar.cu -c
  clang foo.o bar.o -fgpu-rdc -foffload-new-driver


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120272

Files:
  clang/include/clang/Basic/Cuda.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cuda-openmp-driver.cu
  clang/test/Driver/cuda-phases.cu

Index: clang/test/Driver/cuda-phases.cu
===
--- clang/test/Driver/cuda-phases.cu
+++ clang/test/Driver/cuda-phases.cu
@@ -217,3 +217,32 @@
 // DASM2-DAG: [[P8:[0-9]+]]: backend, {[[P7]]}, assembler, (device-[[T]], [[ARCH2]])
 // DASM2-DAG: [[P9:[0-9]+]]: offload, "device-[[T]] ([[TRIPLE]]:[[ARCH2]])" {[[P8]]}, assembler
 // DASM2-NOT: host
+
+//
+// Test the phases generated when using the new offloading driver.
+//
+// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -ccc-print-phases -foffload-new-driver \
+// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW_DRIVER %s
+// NEW_DRIVER: 0: input, "[[INPUT:.*]]", cuda, (host-cuda)
+// NEW_DRIVER: 1: preprocessor, {0}, cuda-cpp-output, (host-cuda)
+// NEW_DRIVER: 2: compiler, {1}, ir, (host-cuda)
+// NEW_DRIVER: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52)
+// NEW_DRIVER: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52)
+// NEW_DRIVER: 5: compiler, {4}, ir, (device-cuda, sm_52)
+// NEW_DRIVER: 6: backend, {5}, assembler, (device-cuda, sm_52)
+// NEW_DRIVER: 7: assembler, {6}, object, (device-cuda, sm_52)
+// NEW_DRIVER: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object
+// NEW_DRIVER: 9: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {6}, assembler
+// NEW_DRIVER: 10: linker, {8, 9}, cuda-fatbin, (device-cuda, sm_52)
+// NEW_DRIVER: 11: input, "[[INPUT]]", cuda, (device-cuda, sm_70)
+// NEW_DRIVER: 12: preprocessor, {11}, cuda-cpp-output, (device-cuda, sm_70)
+// NEW_DRIVER: 13: compiler, {12}, ir, (device-cuda, sm_70)
+// NEW_DRIVER: 14: backend, {13}, assembler, (device-cuda, sm_70)
+// NEW_DRIVER: 15: assembler, {14}, object, (device-cuda, sm_70)
+// NEW_DRIVER: 16: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {15}, object
+// NEW_DRIVER: 17: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {14}, assembler
+// NEW_DRIVER: 18: linker, {16, 17}, cuda-fatbin, (device-cuda, sm_70)
+// NEW_DRIVER: 19: offload, "host-cuda (powerpc64le-ibm-linux-gnu)" {2}, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {10}, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {18}, ir
+// NEW_DRIVER: 20: backend, {19}, assembler, (host-cuda)
+// NEW_DRIVER: 21: assembler, {20}, object, (host-cuda)
+// NEW_DRIVER: 22: clang-linker-wrapper, {21}, image, (host-cuda)
Index: clang/test/Driver/cuda-openmp-driver.cu
===
--- /dev/null
+++ clang/test/Driver/cuda-openmp-driver.cu
@@ -0,0 +1,18 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang -### -target x86_64-linux-gnu -nocudalib -ccc-print-bindings -fgpu-rdc \
+// RUN:-foffload-new-driver --offload-arch=sm_35 --offload-arch=sm_70 %s 2>&1 \
+// RUN: | FileCheck -check-prefix BINDINGS %s
+
+// BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[PTX_SM_35:.+]]"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX_SM_35]]"], output: "[[CUBIN_SM_35:.+]]"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Linker", inputs: ["[[CUBIN_SM_35]]", "[[PTX_SM_35]]"], output: "[[FATBIN_SM_35:.+]]"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]"], output: "[[PTX_SM_70:.+]]"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX_SM_70:.+]]"], output: "[[CUBIN_SM_70:.+]]"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Linker", inputs: ["[[CUBIN_SM_70]]", "[[PTX_SM_70:.+]]"], output: "[[FATBIN_SM_70:.+]]"
+// BINDINGS-NEXT: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT]]", "[[FATBIN_SM_35]]", "[[FATBIN_SM_70]]"], output: "[[HOST_OBJ:.+]]"
+// BINDINGS-NEXT: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[HOST_OBJ]]"], output: "a.out"
+
+// RUN: %clang -### -nocudalib -foffload-new-driver %s 2>&1 | FileCheck -check-prefix RDC %s
+// RDC: error: Using '-foffload-new-driver' requires '-fgpu-rdc'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ c

  1   2   3   >