[PATCH] D127259: [CodeGen] guarantee templated static variables are initialized in the reverse instantiation order

2023-03-03 Thread Yuanfang Chen 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 rGe423885e272c: [CodeGen] guarantee templated static variables 
are initialized in the reverse… (authored by ychen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127259

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp

Index: clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
===
--- clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
+++ clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
@@ -29,32 +29,56 @@
 // ALL: @_ZN1AIbE1aE ={{.*}} global i32 10
 template<> int A::a = 10;
 
-// ALL: @llvm.global_ctors = appending global [8 x { i32, ptr, ptr }]
+// ALL: @llvm.global_ctors = appending global [16 x { i32, ptr, ptr }]
 
-// ELF: [{ i32, ptr, ptr } { i32 65535, ptr @[[unordered1:[^,]*]], ptr @_ZN1AIsE1aE },
-// MACHO: [{ i32, ptr, ptr } { i32 65535, ptr @[[unordered1:[^,]*]], ptr null },
+// ELF:  [{ i32, ptr, ptr } { i32 65535, ptr @[[unordered:[^,]*]], ptr @_ZN1AIsE1aE },
+// MACHO: [{ i32, ptr, ptr } { i32 65535, ptr @[[unordered:[^,]*]], ptr null },
 
-// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered2:[^,]*]], ptr @_Z1xIsE },
-// MACHO:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered2:[^,]*]], ptr null },
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered7:[^,]*]], ptr @_Z1xIsE },
+// MACHO:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered7:[^,]*]], ptr null },
 
-// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered3:[^,]*]], ptr @_ZN2ns1aIiE1iE },
-// MACHO:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered3:[^,]*]], ptr null },
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered10:[^,]*]], ptr @_ZN2ns1aIiE1iE },
+// MACHO:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered10:[^,]*]], ptr null },
 
-// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered4:[^,]*]], ptr @_ZN2ns1b1iIiEE },
-// MACHO:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered4:[^,]*]], ptr null },
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered11:[^,]*]], ptr @_ZN2ns1b1iIiEE },
+// MACHO:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered11:[^,]*]], ptr null },
 
-// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered5:[^,]*]], ptr @_ZN1AIvE1aE },
-// MACHO:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered5:[^,]*]], ptr null },
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered14:[^,]*]], ptr @_ZN1AIvE1aE },
+// MACHO:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered14:[^,]*]], ptr null },
 
-// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered6:[^,]*]], ptr @_Z1xIcE },
-// MACHO:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered6:[^,]*]], ptr null },
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered15:[^,]*]], ptr @_Z1xIcE },
+// MACHO:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered15:[^,]*]], ptr null },
 
-// ALL:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered7:[^,]*]], ptr null },
+// ALL:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered16:[^,]*]], ptr null },
+
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered19:[^,]*]], ptr @_ZN3FibILi2EE1aE },
+// MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered19:[^,]*]], ptr null },
+
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered18:[^,]*]], ptr @_ZN3FibILi3EE1aE },
+// MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered18:[^,]*]], ptr null },
+
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered20:[^,]*]], ptr @_ZN3FibILi4EE1aE },
+// MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered20:[^,]*]], ptr null },
+
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered17:[^,]*]], ptr @_ZN3FibILi5EE1aE },
+// MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered17:[^,]*]], ptr null },
+
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered23:[^,]*]], ptr @_ZN4Fib2ILi2EE1aE },
+// MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered23:[^,]*]], ptr null },
+
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered24:[^,]*]], ptr @_ZN4Fib2ILi3EE1aE },
+// MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered24:[^,]*]], ptr null },
+
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered22:[^,]*]], ptr @_ZN4Fib2ILi4EE1aE },
+// MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered22:[^,]*]], ptr null },
+
+// ELF:  { i32, ptr, ptr } { i32 65535, ptr @[[unordered21:[^,]*]], ptr @_ZN4Fib2ILi5EE1aE },
+// MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered21:[^,]*]], ptr null }, 
 
 // ALL:  { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_static_member_variable_explicit_specialization.cpp, ptr null }]
 
 /// llvm.used ensures SHT_INIT_ARRAY in a section group cannot be GCed.
-// ELF: @llvm.used = appending global [6 x ptr] [ptr @_ZN1A

[PATCH] D145034: [Clang][Sema] Preparations to fix handling of out-of-line definitions of constrained templates

2023-03-03 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov updated this revision to Diff 502067.
alexander-shaposhnikov added a comment.

1/ Add support for out-of-line definitions of member enums + add tests
2/ Updated comments DeclSpec.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145034

Files:
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  
clang/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1-neg.cpp
  clang/test/SemaTemplate/concepts-out-of-line-def.cpp

Index: clang/test/SemaTemplate/concepts-out-of-line-def.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -0,0 +1,87 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+static constexpr int PRIMARY = 0;
+static constexpr int SPECIALIZATION_CONCEPT = 1;
+static constexpr int SPECIALIZATION_REQUIRES = 2;
+
+template 
+concept Concept = (sizeof(T) >= 2 * sizeof(int));
+
+struct XY {
+  int x;
+  int y;
+};
+
+namespace members {
+
+template  struct S {
+  constexpr int primary();
+};
+
+template  constexpr int S::primary() {
+  return PRIMARY;
+};
+
+template  struct S {
+  constexpr int specialization();
+};
+
+template 
+  requires(sizeof(T) == sizeof(int))
+struct S {
+  constexpr int specialization();
+};
+
+template  constexpr int S::specialization() {
+  return SPECIALIZATION_CONCEPT;
+}
+
+template 
+  requires(sizeof(T) == sizeof(int))
+constexpr int S::specialization() {
+  return SPECIALIZATION_REQUIRES;
+}
+
+static_assert(S().primary() == PRIMARY);
+static_assert(S().specialization() == SPECIALIZATION_CONCEPT);
+static_assert(S().specialization() == SPECIALIZATION_REQUIRES);
+
+} // namespace members
+
+namespace enumerations {
+
+template  struct S {
+  enum class E : int;
+};
+
+template  enum class S::E { Value = PRIMARY };
+
+template  struct S {
+  enum class E : int;
+};
+
+template 
+enum class S::E {
+  Value = SPECIALIZATION_CONCEPT
+};
+
+template 
+  requires(sizeof(T) == sizeof(int))
+struct S {
+  enum class E : int;
+};
+
+template 
+  requires(sizeof(T) == sizeof(int))
+enum class S::E {
+  Value = SPECIALIZATION_REQUIRES
+};
+
+static_assert(static_cast(S::E::Value) == PRIMARY);
+static_assert(static_cast(S::E::Value) ==
+  SPECIALIZATION_CONCEPT);
+static_assert(static_cast(S::E::Value) ==
+  SPECIALIZATION_REQUIRES);
+
+} // namespace  enumerations
Index: clang/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1-neg.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1-neg.cpp
+++ clang/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1-neg.cpp
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// XFAIL: *
+// NOTE: This test is marked XFAIL until the diagnostics of
+// too many template parameters is fixed.
 
 template
 struct A;
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -102,31 +102,44 @@
   QualType ContextType
 = Context.getCanonicalType(QualType(SpecType, 0));
 
-  // If the type of the nested name specifier is the same as the
-  // injected class name of the named class template, we're entering
-  // into that class template definition.
-  QualType Injected
-= ClassTemplate->getInjectedClassNameSpecialization();
-  if (Context.hasSameType(Injected, ContextType))
-return ClassTemplate->getTemplatedDecl();
+  // FIXME: currently only the case of ParamLists containing a single
+  // element is supported. The fallback on the search of partial
+  // specialization using ContextType should be eventually removed since
+  // it doesn't handle the case of constrained template parameters
+  // correctly.
+  ClassTemplatePartialSpecializationDecl *PartialSpec = nullptr;
+  ArrayRef TemplateParamLists = SS.getTemplateParamLists();
+  if (TemplateParamLists.size() == 1) {
+// FIXME: pick the correct template parameter list based on NNS, SS
+// and getCurScope().
+TemplateParameterList *L = TemplateParamLists[0];
+void *Pos = nullptr;
+PartialSpec = ClassTemplate->findPartialSpecialization(
+SpecType->template_arguments(), L, Pos);
+  } else {
+PartialSpec = ClassTemplate->findPartialSpecialization(ContextType);
+  }
 
-  // If the type of the nested name specifier is the same as the
-  // type of one of the class template's class template partial
-  // specializations, we

[clang] be437f3 - [clang][RISCV] Enable -fasynchronous-unwind-tables by default on Linux

2023-03-03 Thread Kito Cheng via cfe-commits

Author: Kito Cheng
Date: 2023-03-03T16:13:53+08:00
New Revision: be437f3bb8b657f4d2de4603734f24daa624d204

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

LOG: [clang][RISCV] Enable -fasynchronous-unwind-tables by default on Linux

This could improve user experience for stack unwinding, and also this is
enabled by default by X86 and AArch64 and RISC-V GCC.

Reviewed By: luismarques, MaskRay

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/riscv-features.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 3a69a2967462e..24fbdcffc07ba 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2900,6 +2900,8 @@ Generic_GCC::getDefaultUnwindTableLevel(const ArgList 
&Args) const {
   case llvm::Triple::ppcle:
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64:
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 return UnwindTableLevel::Asynchronous;

diff  --git a/clang/test/Driver/riscv-features.c 
b/clang/test/Driver/riscv-features.c
index 37b6f8647d49b..98445b1920301 100644
--- a/clang/test/Driver/riscv-features.c
+++ b/clang/test/Driver/riscv-features.c
@@ -26,7 +26,8 @@
 // RUN: %clang --target=riscv64-linux -### %s -fsyntax-only 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DEFAULT-LINUX
 
-// DEFAULT-LINUX: "-target-feature" "+m"
+// DEFAULT-LINUX: "-funwind-tables=2"
+// DEFAULT-LINUX-SAME: "-target-feature" "+m"
 // DEFAULT-LINUX-SAME: "-target-feature" "+a"
 // DEFAULT-LINUX-SAME: "-target-feature" "+f"
 // DEFAULT-LINUX-SAME: "-target-feature" "+d"



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


[PATCH] D145164: [clang][RISCV] Enable -fasynchronous-unwind-tables by default on Linux

2023-03-03 Thread Kito Cheng via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbe437f3bb8b6: [clang][RISCV] Enable 
-fasynchronous-unwind-tables by default on Linux (authored by kito-cheng).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145164

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/riscv-features.c


Index: clang/test/Driver/riscv-features.c
===
--- clang/test/Driver/riscv-features.c
+++ clang/test/Driver/riscv-features.c
@@ -26,7 +26,8 @@
 // RUN: %clang --target=riscv64-linux -### %s -fsyntax-only 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DEFAULT-LINUX
 
-// DEFAULT-LINUX: "-target-feature" "+m"
+// DEFAULT-LINUX: "-funwind-tables=2"
+// DEFAULT-LINUX-SAME: "-target-feature" "+m"
 // DEFAULT-LINUX-SAME: "-target-feature" "+a"
 // DEFAULT-LINUX-SAME: "-target-feature" "+f"
 // DEFAULT-LINUX-SAME: "-target-feature" "+d"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2900,6 +2900,8 @@
   case llvm::Triple::ppcle:
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64:
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 return UnwindTableLevel::Asynchronous;


Index: clang/test/Driver/riscv-features.c
===
--- clang/test/Driver/riscv-features.c
+++ clang/test/Driver/riscv-features.c
@@ -26,7 +26,8 @@
 // RUN: %clang --target=riscv64-linux -### %s -fsyntax-only 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DEFAULT-LINUX
 
-// DEFAULT-LINUX: "-target-feature" "+m"
+// DEFAULT-LINUX: "-funwind-tables=2"
+// DEFAULT-LINUX-SAME: "-target-feature" "+m"
 // DEFAULT-LINUX-SAME: "-target-feature" "+a"
 // DEFAULT-LINUX-SAME: "-target-feature" "+f"
 // DEFAULT-LINUX-SAME: "-target-feature" "+d"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2900,6 +2900,8 @@
   case llvm::Triple::ppcle:
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64:
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 return UnwindTableLevel::Asynchronous;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 27ab138 - [clang][ASTImporter] Import TemplateName correctly

2023-03-03 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-03-03T09:16:43+01:00
New Revision: 27ab138c69fc61b22ef898a0f4d0f5c9bad649bd

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

LOG: [clang][ASTImporter] Import TemplateName correctly

This is a fix for a problem when multiple template
specializations are created by ASTImporter for the
same specialization. The problem happens if a
TemplateName is imported that points to a template
delcaration (for a template template argument)
(specialization) that has multiple instances in the
declaration chain. If two TemplateName objects contain
different pointers to a template specialization,
these TemplateName objects will have different checksum
even if they point into the same declaration chain.
The problem is fixed if the canonical declaration is used.

Reviewed By: vabridgers, donat.nagy

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

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 4c173ebb10d1e..bd055082778df 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -9385,7 +9385,7 @@ Expected ASTImporter::Import(TemplateName 
From) {
   switch (From.getKind()) {
   case TemplateName::Template:
 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
-  return TemplateName(cast(*ToTemplateOrErr));
+  return 
TemplateName(cast((*ToTemplateOrErr)->getCanonicalDecl()));
 else
   return ToTemplateOrErr.takeError();
 

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 87b9fe52d906c..3c9b804a92e13 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -8378,6 +8378,66 @@ TEST_P(ImportInjectedClassNameType, ImportTypedefType) {
   EXPECT_TRUE(ToCtx.hasSameType(ToInjTypedef, ToInjParmVar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportCorrectTemplateName) {
+  constexpr auto TestCode = R"(
+  template 
+  struct A;
+  template 
+  struct A {};
+  template  class T = A>
+  struct B {};
+  using C = B<>;
+  )";
+  Decl *ToTU = getToTuDecl(TestCode, Lang_CXX11);
+  Decl *FromTU = getTuDecl(TestCode, Lang_CXX11);
+
+  auto *ToUsingFirst = FirstDeclMatcher().match(
+  ToTU, typeAliasDecl(hasName("C")));
+
+  auto *FromUsing = FirstDeclMatcher().match(
+  FromTU, typeAliasDecl(hasName("C")));
+  auto *ToUsing = Import(FromUsing, Lang_CXX11);
+  EXPECT_TRUE(ToUsing);
+
+  auto *ToB = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("B")));
+  auto *ToB1 = LastDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("B")));
+  // One template definition of 'B' should exist.
+  EXPECT_EQ(ToB, ToB1);
+
+  // These declarations are imported separately.
+  EXPECT_NE(ToUsingFirst, ToUsing);
+
+  auto SpB = ToB->spec_begin();
+  auto SpE = ToB->spec_end();
+  EXPECT_TRUE(SpB != SpE);
+  ClassTemplateSpecializationDecl *Spec1 = *SpB;
+  ++SpB;
+  // The template 'B' should have one specialization (with default argument).
+  EXPECT_TRUE(SpB == SpE);
+
+  // Even if 'B' has one specialization with the default arguments, the AST
+  // contains after the import two specializations that are linked in the
+  // declaration chain. The 'spec_begin' iteration does not find these because
+  // the template arguments are the same. But the imported type alias has the
+  // link to the second specialization. The template name object in these
+  // specializations must point to the same (and one) instance of definition of
+  // 'B'.
+  auto *Spec2 = cast(
+  ToUsing->getUnderlyingType()
+  ->getAs()
+  ->getAsRecordDecl());
+  EXPECT_NE(Spec1, Spec2);
+  EXPECT_TRUE(Spec1->getPreviousDecl() == Spec2 ||
+  Spec2->getPreviousDecl() == Spec1);
+  TemplateDecl *Templ1 =
+  Spec1->getTemplateArgs()[0].getAsTemplate().getAsTemplateDecl();
+  TemplateDecl *Templ2 =
+  Spec2->getTemplateArgs()[0].getAsTemplate().getAsTemplateDecl();
+  EXPECT_EQ(Templ1, Templ2);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 



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


[PATCH] D144622: [clang][ASTImporter] Import TemplateName correctly

2023-03-03 Thread Balázs Kéri 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 rG27ab138c69fc: [clang][ASTImporter] Import TemplateName 
correctly (authored by balazske).

Changed prior to commit:
  https://reviews.llvm.org/D144622?vs=501539&id=502071#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144622

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8378,6 +8378,66 @@
   EXPECT_TRUE(ToCtx.hasSameType(ToInjTypedef, ToInjParmVar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportCorrectTemplateName) {
+  constexpr auto TestCode = R"(
+  template 
+  struct A;
+  template 
+  struct A {};
+  template  class T = A>
+  struct B {};
+  using C = B<>;
+  )";
+  Decl *ToTU = getToTuDecl(TestCode, Lang_CXX11);
+  Decl *FromTU = getTuDecl(TestCode, Lang_CXX11);
+
+  auto *ToUsingFirst = FirstDeclMatcher().match(
+  ToTU, typeAliasDecl(hasName("C")));
+
+  auto *FromUsing = FirstDeclMatcher().match(
+  FromTU, typeAliasDecl(hasName("C")));
+  auto *ToUsing = Import(FromUsing, Lang_CXX11);
+  EXPECT_TRUE(ToUsing);
+
+  auto *ToB = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("B")));
+  auto *ToB1 = LastDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("B")));
+  // One template definition of 'B' should exist.
+  EXPECT_EQ(ToB, ToB1);
+
+  // These declarations are imported separately.
+  EXPECT_NE(ToUsingFirst, ToUsing);
+
+  auto SpB = ToB->spec_begin();
+  auto SpE = ToB->spec_end();
+  EXPECT_TRUE(SpB != SpE);
+  ClassTemplateSpecializationDecl *Spec1 = *SpB;
+  ++SpB;
+  // The template 'B' should have one specialization (with default argument).
+  EXPECT_TRUE(SpB == SpE);
+
+  // Even if 'B' has one specialization with the default arguments, the AST
+  // contains after the import two specializations that are linked in the
+  // declaration chain. The 'spec_begin' iteration does not find these because
+  // the template arguments are the same. But the imported type alias has the
+  // link to the second specialization. The template name object in these
+  // specializations must point to the same (and one) instance of definition of
+  // 'B'.
+  auto *Spec2 = cast(
+  ToUsing->getUnderlyingType()
+  ->getAs()
+  ->getAsRecordDecl());
+  EXPECT_NE(Spec1, Spec2);
+  EXPECT_TRUE(Spec1->getPreviousDecl() == Spec2 ||
+  Spec2->getPreviousDecl() == Spec1);
+  TemplateDecl *Templ1 =
+  Spec1->getTemplateArgs()[0].getAsTemplate().getAsTemplateDecl();
+  TemplateDecl *Templ2 =
+  Spec2->getTemplateArgs()[0].getAsTemplate().getAsTemplateDecl();
+  EXPECT_EQ(Templ1, Templ2);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -9385,7 +9385,7 @@
   switch (From.getKind()) {
   case TemplateName::Template:
 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
-  return TemplateName(cast(*ToTemplateOrErr));
+  return 
TemplateName(cast((*ToTemplateOrErr)->getCanonicalDecl()));
 else
   return ToTemplateOrErr.takeError();
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8378,6 +8378,66 @@
   EXPECT_TRUE(ToCtx.hasSameType(ToInjTypedef, ToInjParmVar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportCorrectTemplateName) {
+  constexpr auto TestCode = R"(
+  template 
+  struct A;
+  template 
+  struct A {};
+  template  class T = A>
+  struct B {};
+  using C = B<>;
+  )";
+  Decl *ToTU = getToTuDecl(TestCode, Lang_CXX11);
+  Decl *FromTU = getTuDecl(TestCode, Lang_CXX11);
+
+  auto *ToUsingFirst = FirstDeclMatcher().match(
+  ToTU, typeAliasDecl(hasName("C")));
+
+  auto *FromUsing = FirstDeclMatcher().match(
+  FromTU, typeAliasDecl(hasName("C")));
+  auto *ToUsing = Import(FromUsing, Lang_CXX11);
+  EXPECT_TRUE(ToUsing);
+
+  auto *ToB = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("B")));
+  auto *ToB1 = LastDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("B")));
+  // One template definition of 'B' should exist.
+  EXPECT_EQ(ToB, ToB1);
+
+  // These declarations are imported separately.
+  EXPECT_NE(ToUsingFirst, ToUsing);
+
+  auto SpB = ToB->spec_begin();
+  auto SpE = ToB->spec_end

[PATCH] D145150: clang: Emit nofpclass(nan inf) for -ffinite-math-only

2023-03-03 Thread Nikita Popov via Phabricator via cfe-commits
nikic resigned from this revision.
nikic added a comment.

(Sounds reasonable conceptually, but I'm not familiar enough with clang codegen 
for the details.)


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

https://reviews.llvm.org/D145150

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


[PATCH] D145034: [Clang][Sema] Preparations to fix handling of out-of-line definitions of constrained templates

2023-03-03 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov added inline comments.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:1677-1678
 CXXScopeSpec Spec;
+if (TemplateInfo.TemplateParams)
+  Spec.setTemplateParamLists(*TemplateInfo.TemplateParams);
+

rsmith wrote:
> I think we'll need some similar logic for out-of-line definitions of member 
> enums too:
> ```
> template struct X;
> template concept bool Small = sizeof(T) == 1;
> template struct X {
>   enum class E;
> };
> template enum class X::E { e };
> ```
> 
> More generally, anywhere we might pass `EnteringContext = true`, we probably 
> ought to think about whether we have template parameters to pass in.
Added missing bits for enums,
regarding EnteringContext = true - yeah, I agree, I haven't done it on this 
diff  cause I'm kind of worried to do it without test cases and extracting test 
cases requires some efforts.




Comment at: 
clang/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1-neg.cpp:2-4
+// XFAIL: *
+// NOTE: This test is marked XFAIL until the diagnostics of
+// too many template parameters is fixed.

rsmith wrote:
> What is the new diagnostic output? (Presumably we no longer match the partial 
> specialization when trying to match the declaration on line 25, because the 
> template parameter list doesn't match.)
the new diagnostic output:
  error: nested name specifier 'A::' for declaration does not refer 
into a class, class template or class template partial specialization 

```
template
void A::f0() { }
```




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145034

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


[PATCH] D115456: [MS] Implement on-demand TLS initialization for Microsoft CXX ABI

2023-03-03 Thread Leah Stafford via Phabricator via cfe-commits
doughnutlifetime added a comment.
Herald added a project: All.

@dumb ways to die  This article was very helpful to 
me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115456

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


[clang] 2408f97 - Recommit [C++20] [Modules] Trying to compare the trailing require clause from the primary template function

2023-03-03 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-03-03T17:27:37+08:00
New Revision: 2408f97652caadf733a879e1d7d9c0702a80d609

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

LOG: Recommit [C++20] [Modules] Trying to compare the trailing require clause 
from the primary template function

Close https://github.com/llvm/llvm-project/issues/60890.

For the following example:

```
export module a;

export template
struct a {
friend void aa(a) requires(true) {
}
};
```

```
export module b;

import a;

struct b {
a m;
};
```

```
export module c;

import a;

struct c {
void f() const {
aa(a());
}
};
```

```
import a;
import b;
import c;

void d() {
aa(a());
}
```

The current clang will reject this incorrectly. The reason is that the
require clause  will be replaced with the evaluated version
(https://github.com/llvm/llvm-project/blob/efae3174f09560353fb0f3d528bcbffe060d5438/clang/lib/Sema/SemaConcept.cpp#L664-L665).
In module 'b', the friend function is instantiated but not used so the
require clause of the friend function is `(true)`. However, in module
'c', the friend function is used so the require clause is `true`. So
deserializer classify these two function to two different functions
instead of one. Then here is the bug report.

The proposed solution is to try to compare the trailing require clause
of the primary template when performing ODR checking.

Reviewed By: erichkeane

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

Added: 
clang/test/Modules/pr60890.cppm

Modified: 
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 482791ada5d1..f22683296664 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6591,7 +6591,10 @@ bool ASTContext::FriendsDifferByConstraints(const 
FunctionDecl *X,
 
   // If the two functions share lexical declaration context, they are not in
   // separate instantations, and thus in the same scope.
-  if (X->getLexicalDeclContext() == Y->getLexicalDeclContext())
+  if (declaresSameEntity(cast(X->getLexicalDeclContext()
+ ->getRedeclContext()),
+ cast(Y->getLexicalDeclContext()
+ ->getRedeclContext(
 return false;
 
   if (!X->getDescribedFunctionTemplate()) {
@@ -6683,8 +6686,28 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const 
NamedDecl *Y) const {
 return false;
 }
 
-if (!isSameConstraintExpr(FuncX->getTrailingRequiresClause(),
-  FuncY->getTrailingRequiresClause()))
+// The trailing require clause of instantiated function may change during
+// the semantic analysis. Trying to get the primary template function (if
+// exists) to compare the primary trailing require clause.
+auto TryToGetPrimaryTemplatedFunction =
+[](const FunctionDecl *FD) -> const FunctionDecl * {
+  switch (FD->getTemplatedKind()) {
+  case FunctionDecl::TK_DependentNonTemplate:
+return FD->getInstantiatedFromDecl();
+  case FunctionDecl::TK_FunctionTemplate:
+return FD->getDescribedFunctionTemplate()->getTemplatedDecl();
+  case FunctionDecl::TK_MemberSpecialization:
+return FD->getInstantiatedFromMemberFunction();
+  case FunctionDecl::TK_FunctionTemplateSpecialization:
+return FD->getPrimaryTemplate()->getTemplatedDecl();
+  default:
+return FD;
+  }
+};
+const FunctionDecl *PrimaryX = TryToGetPrimaryTemplatedFunction(FuncX);
+const FunctionDecl *PrimaryY = TryToGetPrimaryTemplatedFunction(FuncY);
+if (!isSameConstraintExpr(PrimaryX->getTrailingRequiresClause(),
+  PrimaryY->getTrailingRequiresClause()))
   return false;
 
 // Constrained friends are 
diff erent in certain cases, see: [temp.friend]p9.

diff  --git a/clang/test/Modules/pr60890.cppm b/clang/test/Modules/pr60890.cppm
new file mode 100644
index ..2560bec5b433
--- /dev/null
+++ b/clang/test/Modules/pr60890.cppm
@@ -0,0 +1,82 @@
+// https://github.com/llvm/llvm-project/issues/60890
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/a.cppm -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/b.cppm 
-fprebuilt-module-path=%t -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/c.cppm 
-fprebuilt-module-path=%t -o %t/c.pcm
+// RUN: %clang_cc1 -std=c++20 %t/d.cpp -fprebuilt-module-path=%t -S -emit-llvm 
-o -
+
+//--- a.cppm
+export module a;
+ 
+export template
+struct a {
+   friend void aa(a x) requires(true) {}
+   void aaa() requires(true) {}
+};
+
+e

[PATCH] D144603: Add option to disable compiler launcher on external projects

2023-03-03 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D144603#4165569 , @fangism wrote:

> In D144603#4163751 , @phosek wrote:
>
>> In D144603#4162974 , @haowei wrote:
>>
>>> I think remove the compiler launcher from default pass through flags are 
>>> fine. What about the using compiler launcher in runtime builds? I don't 
>>> think we should read `CLANG_BOOTSTRAP_PASSTHROUGH` to determine if we 
>>> should pass through compiler launcher flags.
>>
>> I'd suggest a similar approach, that is remove `C_COMPILER_LAUNCHER` and 
>> `CXX_COMPILER_LAUNCHER` from the default passthrough list and provide a new 
>> `LLVM_EXTERNAL_PROJECT_PASSTHROUGH` variable.
>
> Will the PASSTHROUGH approach let us choose a //different// LAUNCHER for the 
> external projects?  For example, we could still distribute those compiles, 
> albeit without expecting any caching.

No, we would need a different option for that. I'd start with the passthrough 
approach which is generic and then look into the possibility of overriding the 
launcher for subprojects if there's a compelling use case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144603

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


[PATCH] D145187: [Fuchsia] Add other necessary components to LLDB install.

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145187

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


[PATCH] D145074: [clang][RISCV] Fix ABI lowering for _Float16 for FP ABIs

2023-03-03 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

LGTM, just a nit :)




Comment at: clang/test/CodeGen/RISCV/riscv64-abi.c:1909
- NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
-// LP64F: {{.*}}

This seems removed accidentally, I saw `clang/test/CodeGen/RISCV/riscv32-abi.c` 
still keep.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145074

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


[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-03-03 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 502084.
VitaNuo marked 23 inline comments as done.
VitaNuo added a comment.

Improve test coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143496

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp

Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -49,8 +49,8 @@
   }
 }
 
-static std::string spellHeader(const Header &H, HeaderSearch &HS,
-   const FileEntry *Main) {
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main) {
   switch (H.kind()) {
   case Header::Physical: {
 bool IsSystem = false;
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -73,6 +73,8 @@
 std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main);
 } // namespace include_cleaner
 } // namespace clang
 
Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -665,7 +665,7 @@
 TEST(PreamblePatch, DiagnosticsToPreamble) {
   Config Cfg;
   Cfg.Diagnostics.AllowStalePreamble = true;
-  Cfg.Diagnostics.UnusedIncludes = Config::UnusedIncludesPolicy::Strict;
+  Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
   WithContextValue WithCfg(Config::Key, std::move(Cfg));
 
   llvm::StringMap AdditionalFiles;
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -8,26 +8,56 @@
 
 #include "Annotations.h"
 #include "Config.h"
+#include "Diagnostics.h"
 #include "IncludeCleaner.h"
+#include "ParsedAST.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "support/Context.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
 using ::testing::IsEmpty;
+using ::testing::Matcher;
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
+Matcher withFix(::testing::Matcher FixMatcher) {
+  return Field(&Diag::Fixes, ElementsAre(FixMatcher));
+}
+
+MATCHER_P2(Diag, Range, Message,
+   "Diag at " + llvm::to_string(Range) + " = [" + Message + "]") {
+  return arg.Range == Range && arg.Message == Message;
+}
+
+MATCHER_P3(Fix, Range, Replacement, Message,
+   "Fix " + llvm::to_string(Range) + " => " +
+   ::testing::PrintToString(Replacement) + " = [" + Message + "]") {
+  return arg.Message == Message && arg.Edits.size() == 1 &&
+ arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
+}
+
 std::string guard(llvm::StringRef Code) {
   return "#pragma once\n" + Code.str();
 }
@@ -342,7 +372,8 @@
   auto AST = TU.build();
   EXPECT_THAT(computeUnusedIncludes(AST),
   ElementsAre(Pointee(writtenInclusion("";
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST),
+  IncludeCleanerFindings Findings = compute

[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-03-03 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked an inline comment as done.
VitaNuo added a comment.

Thank you for all the thoughtful comments!




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:414
+
+std::string findResolvedPath(const include_cleaner::Header &SymProvider) {
+  std::string ResolvedPath;

kadircet wrote:
> what about just `resolvedPath`, if you'd rather keep the verb, i think `get` 
> makes more sense than `find`. we're not really searching anything.
Ok, let's call it `get`. I do prefer verbs for methods, that's correct. 



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:449
+include_cleaner::Symbol B{*D};
+syntax::FileRange BRange{SM, B.declaration().getBeginLoc(), 1};
+include_cleaner::Header Header{*SM.getFileManager().getFile("b.h")};

kadircet wrote:
> this is pointing at the declaration inside `b.h` not to the reference inside 
> the main file. are you sure this test passes?
Yes, all the tests pass. 
`D` is a `Decl` from the main file, otherwise it wouldn't have passed the 
safeguard ` if (!SM.isWrittenInMainFile(SM.getExpansionLoc(D->getLocation( 
continue;` above.



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:469
+  $d[[d]]();
+  $f[[f]]();
+})cpp");

kadircet wrote:
> can you also add a reference (and declaration) for std::vector, and have an 
> IWYU private pragma in one of the headers to test code paths that spell 
> verbatim and standard headers? also having some diagnostic suppressed via 
> `IgnoreHeaders` is important to check
Thank you for the great tips on improving test coverage!

In fact, I had to also introduce support for private pragmas, as they were not 
taken care of. Hopefully, the solution will make sense to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143496

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


[PATCH] D145227: [LLVM][OHOS] Clang toolchain and targets

2023-03-03 Thread Pavel Kosov via Phabricator via cfe-commits
kpdev42 created this revision.
kpdev42 added reviewers: DavidSpickett, echristo.
kpdev42 added a project: LLVM.
Herald added subscribers: yaneury, supersymetrie, Chia-hungDuan, s.egerton, 
ormris, cryptoad, simoncook, hiraditya, kristof.beyls.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
kpdev42 requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

Add a clang part of OpenHarmony target

Related LLVM part: D138202 

~~~

Huawei RRI, OS Lab


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145227

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/OHOS.cpp
  clang/lib/Driver/ToolChains/OHOS.h
  clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c
  clang/test/Driver/Inputs/ohos_native_tree/llvm/bin/.keep
  clang/test/Driver/Inputs/ohos_native_tree/llvm/include/c++/v1/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/a7_soft/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/c++/a7_hard_neon-vfpv4/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/c++/a7_soft/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/c++/a7_softfp_neon-vfpv4/libc++.so
  clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/arm-liteos-ohos/libc++.so
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/libclang_rt.profile.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_soft/libclang_rt.profile.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/a7_softfp_neon-vfpv4/libclang_rt.profile.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/clang_rt.crtbegin.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/clang_rt.crtend.o
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/arm-liteos-ohos/libclang_rt.profile.a
  clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/include/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/include/arm-liteos-ohos/.keep
  clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/a7_hard_neon-vfpv4/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/arm-liteos-ohos/a7_soft/.keep
  
clang/test/Driver/Inputs/ohos_native_tree/sysroot/u

[PATCH] D144273: [clang][ASTImporter] Add VaList declaration to lookup table.

2023-03-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 502089.
balazske added a comment.

Changed the lit test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144273

Files:
  clang/lib/AST/ASTImporterLookupTable.cpp
  clang/test/Import/cxx-valist/Inputs/I1.cpp
  clang/test/Import/cxx-valist/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8378,6 +8378,42 @@
   EXPECT_TRUE(ToCtx.hasSameType(ToInjTypedef, ToInjParmVar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VaListC) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_C99);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_C99);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, VaListCpp) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", 
Lang_CXX03);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_CXX03);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/test/Import/cxx-valist/test.cpp
===
--- /dev/null
+++ clang/test/Import/cxx-valist/test.cpp
@@ -0,0 +1,7 @@
+// RUN: clang-import-test -import %S/Inputs/I1.cpp -expression %s
+
+void expr() {
+  f(0);
+}
+
+int std = 17;
Index: clang/test/Import/cxx-valist/Inputs/I1.cpp
===
--- /dev/null
+++ clang/test/Import/cxx-valist/Inputs/I1.cpp
@@ -0,0 +1,3 @@
+int f(int N) {
+  return N;
+}
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -87,6 +87,18 @@
 ASTImporterLookupTable::ASTImporterLookupTable(TranslationUnitDecl &TU) {
   Builder B(*this);
   B.TraverseDecl(&TU);
+  // The VaList declaration may be created on demand only or not traversed.
+  // To ensure it is present and found during import, add it to the table now.
+  if (auto *D =
+  dyn_cast_or_null(TU.getASTContext().getVaListTagDecl())) {
+// On some platforms (AArch64) the VaList declaration can be inside a 'std'
+// namespace. This is handled specially and not visible by AST traversal.
+// ASTImporter must be able to find this namespace to import the VaList
+// declaration (and the namespace) correctly.
+if (auto *Ns = dyn_cast(D->getDeclContext()))
+  add(&TU, Ns);
+add(D->getDeclContext(), D);
+  }
 }
 
 void ASTImporterLookupTable::add(DeclContext *DC, NamedDecl *ND) {


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8378,6 +8378,42 @@
   EXPECT_TRUE(ToCtx.hasSameType(ToInjTypedef, ToInjParmVar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VaListC) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_C99);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_C99);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, VaListCpp) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_CXX03);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_CXX03);
+  ASSERT_TRUE(ToVaList);
+
+  aut

[PATCH] D144273: [clang][ASTImporter] Add VaList declaration to lookup table.

2023-03-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

The new test should be better, it imports the `f` function without `new` and no 
VaList should exist in the imported translation unit. It looks like the 
`test.cpp` is appended to the AST after the import of the other files. I 
changed function `CreateVaListDecl` to always use the AArch64 create function, 
the test did not fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144273

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


[clang] 71b0658 - [NVPTX] Add f16 and v2f16 ldg builtins

2023-03-03 Thread Jakub Chlanda via cfe-commits

Author: Jakub Chlanda
Date: 2023-03-03T12:49:18+01:00
New Revision: 71b06585857a77691761a7bfd16b5b91454a6894

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

LOG: [NVPTX] Add f16 and v2f16 ldg builtins

Adds f16 and v2f16 ldg builtins and relevant tests.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsNVPTX.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-nvptx-native-half-type.c
llvm/test/CodeGen/NVPTX/ldu-ldg.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index ea0cd8c3e8431..7fcd906c599b8 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -795,6 +795,7 @@ BUILTIN(__nvvm_ldg_ui, "UiUiC*", "")
 BUILTIN(__nvvm_ldg_ul, "ULiULiC*", "")
 BUILTIN(__nvvm_ldg_ull, "ULLiULLiC*", "")
 
+BUILTIN(__nvvm_ldg_h, "hhC*", "")
 BUILTIN(__nvvm_ldg_f, "ffC*", "")
 BUILTIN(__nvvm_ldg_d, "ddC*", "")
 
@@ -814,6 +815,7 @@ BUILTIN(__nvvm_ldg_ui2, "E2UiE2UiC*", "")
 BUILTIN(__nvvm_ldg_ui4, "E4UiE4UiC*", "")
 BUILTIN(__nvvm_ldg_ull2, "E2ULLiE2ULLiC*", "")
 
+BUILTIN(__nvvm_ldg_h2, "E2hE2hC*", "")
 BUILTIN(__nvvm_ldg_f2, "E2fE2fC*", "")
 BUILTIN(__nvvm_ldg_f4, "E4fE4fC*", "")
 BUILTIN(__nvvm_ldg_d2, "E2dE2dC*", "")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1535b14c7fb40..07a39bca9d7a2 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18228,7 +18228,9 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID, const CallExpr *E) {
 // elements, its alignment is set to number of elements times the alignment
 // of its member: n*alignof(t)."
 return MakeLdg(Intrinsic::nvvm_ldg_global_i);
+  case NVPTX::BI__nvvm_ldg_h:
   case NVPTX::BI__nvvm_ldg_f:
+  case NVPTX::BI__nvvm_ldg_h2:
   case NVPTX::BI__nvvm_ldg_f2:
   case NVPTX::BI__nvvm_ldg_f4:
   case NVPTX::BI__nvvm_ldg_d:

diff  --git a/clang/test/CodeGen/builtins-nvptx-native-half-type.c 
b/clang/test/CodeGen/builtins-nvptx-native-half-type.c
index 95021f274cd0f..9dc61d6014210 100644
--- a/clang/test/CodeGen/builtins-nvptx-native-half-type.c
+++ b/clang/test/CodeGen/builtins-nvptx-native-half-type.c
@@ -172,3 +172,12 @@ __device__ void nvvm_min_max_sm86() {
 #endif
   // CHECK: ret void
 }
+
+// CHECK-LABEL: nvvm_ldg_native_half_types
+__device__ void nvvm_ldg_native_half_types(const void *p) {
+  // CHECK: call half @llvm.nvvm.ldg.global.f.f16.p0
+  __nvvm_ldg_h((const __fp16 *)p);
+  typedef __fp16 __fp16v2 __attribute__((ext_vector_type(2)));
+  // CHECK: call <2 x half> @llvm.nvvm.ldg.global.f.v2f16.p0
+  __nvvm_ldg_h2((const __fp16v2 *)p);
+}

diff  --git a/llvm/test/CodeGen/NVPTX/ldu-ldg.ll 
b/llvm/test/CodeGen/NVPTX/ldu-ldg.ll
index 6d5fcb4cd317e..d40eb7a32027d 100644
--- a/llvm/test/CodeGen/NVPTX/ldu-ldg.ll
+++ b/llvm/test/CodeGen/NVPTX/ldu-ldg.ll
@@ -4,34 +4,82 @@
 
 declare i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 %align)
+
 declare i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i32 @llvm.nvvm.ldg.global.i.i32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i64 @llvm.nvvm.ldg.global.i.i64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare float @llvm.nvvm.ldg.global.f.f32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare double @llvm.nvvm.ldg.global.f.f64.p1(ptr addrspace(1) %ptr, i32 
%align)
+declare half @llvm.nvvm.ldg.global.f.f16.p1(ptr addrspace(1) %ptr, i32 %align)
+declare <2 x half> @llvm.nvvm.ldg.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 
%align)
 
-
-; CHECK: func0
-define i8 @func0(ptr addrspace(1) %ptr) {
+; CHECK: test_ldu_i8
+define i8 @test_ldu_i8(ptr addrspace(1) %ptr) {
 ; ldu.global.u8
   %val = tail call i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 
4)
   ret i8 %val
 }
 
-; CHECK: func1
-define i32 @func1(ptr addrspace(1) %ptr) {
+; CHECK: test_ldu_i32
+define i32 @test_ldu_i32(ptr addrspace(1) %ptr) {
 ; ldu.global.u32
   %val = tail call i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, 
i32 4)
   ret i32 %val
 }
 
-; CHECK: func2
-define i8 @func2(ptr addrspace(1) %ptr) {
+; CHECK: test_ldg_i8
+define i8 @test_ldg_i8(ptr addrspace(1) %ptr) {
 ; ld.global.nc.u8
   %val = tail call i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 
4)
   ret i8 %val
 }
 
-; CHECK: func3
-define i32 @func3(ptr addrspace(1) %ptr) {
+; CHECK: test_ldg_i16
+define i16 @test_ldg_i16(ptr addrspace(1) %ptr) {
+; ld.global.nc.u16
+  %val = tail call i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace

[PATCH] D145228: [clangd] Add clangd headers to install targets

2023-03-03 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko created this revision.
ivanmurashko added reviewers: sammccall, alexfh, smeenai, aaron.ballman.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
ivanmurashko requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

The install target for clang distributes the clangd static libs but missing 
corresponding headers. The diff adds necessary headers. That opens a 
possibility to create custom clangd builds outside LLVM repo.

Test Plan:

  ninja install-clangd-headers

see the headers installed at the install folder


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145228

Files:
  clang-tools-extra/clangd/CMakeLists.txt


Index: clang-tools-extra/clangd/CMakeLists.txt
===
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -218,3 +218,26 @@
 
 add_subdirectory(index/remote)
 add_subdirectory(index/dex/dexp)
+
+if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
+  install(DIRECTORY .
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/clangd"
+COMPONENT clangd-headers
+FILES_MATCHING
+PATTERN "*.h"
+)
+  install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+COMPONENT clangd-headers
+FILES_MATCHING
+PATTERN "CMakeFiles" EXCLUDE
+PATTERN "*.inc"
+)
+  add_custom_target(clangd-headers)
+  set_target_properties(clangd-headers PROPERTIES FOLDER "Misc")
+  if(NOT LLVM_ENABLE_IDE)
+add_llvm_install_targets(install-clangd-headers
+ DEPENDS clangd-headers
+ COMPONENT clangd-headers)
+  endif()
+endif()


Index: clang-tools-extra/clangd/CMakeLists.txt
===
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -218,3 +218,26 @@
 
 add_subdirectory(index/remote)
 add_subdirectory(index/dex/dexp)
+
+if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
+  install(DIRECTORY .
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/clangd"
+COMPONENT clangd-headers
+FILES_MATCHING
+PATTERN "*.h"
+)
+  install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+COMPONENT clangd-headers
+FILES_MATCHING
+PATTERN "CMakeFiles" EXCLUDE
+PATTERN "*.inc"
+)
+  add_custom_target(clangd-headers)
+  set_target_properties(clangd-headers PROPERTIES FOLDER "Misc")
+  if(NOT LLVM_ENABLE_IDE)
+add_llvm_install_targets(install-clangd-headers
+ DEPENDS clangd-headers
+ COMPONENT clangd-headers)
+  endif()
+endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144961: [NVPTX] Add f16 and v2f16 ldg builtins

2023-03-03 Thread Jakub Chlanda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG71b06585857a: [NVPTX] Add f16 and v2f16 ldg builtins 
(authored by jchlanda).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144961

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-nvptx-native-half-type.c
  llvm/test/CodeGen/NVPTX/ldu-ldg.ll

Index: llvm/test/CodeGen/NVPTX/ldu-ldg.ll
===
--- llvm/test/CodeGen/NVPTX/ldu-ldg.ll
+++ llvm/test/CodeGen/NVPTX/ldu-ldg.ll
@@ -4,34 +4,82 @@
 
 declare i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 %align)
+
 declare i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i32 @llvm.nvvm.ldg.global.i.i32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i64 @llvm.nvvm.ldg.global.i.i64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare float @llvm.nvvm.ldg.global.f.f32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare double @llvm.nvvm.ldg.global.f.f64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare half @llvm.nvvm.ldg.global.f.f16.p1(ptr addrspace(1) %ptr, i32 %align)
+declare <2 x half> @llvm.nvvm.ldg.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 %align)
 
-
-; CHECK: func0
-define i8 @func0(ptr addrspace(1) %ptr) {
+; CHECK: test_ldu_i8
+define i8 @test_ldu_i8(ptr addrspace(1) %ptr) {
 ; ldu.global.u8
   %val = tail call i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 4)
   ret i8 %val
 }
 
-; CHECK: func1
-define i32 @func1(ptr addrspace(1) %ptr) {
+; CHECK: test_ldu_i32
+define i32 @test_ldu_i32(ptr addrspace(1) %ptr) {
 ; ldu.global.u32
   %val = tail call i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 4)
   ret i32 %val
 }
 
-; CHECK: func2
-define i8 @func2(ptr addrspace(1) %ptr) {
+; CHECK: test_ldg_i8
+define i8 @test_ldg_i8(ptr addrspace(1) %ptr) {
 ; ld.global.nc.u8
   %val = tail call i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 4)
   ret i8 %val
 }
 
-; CHECK: func3
-define i32 @func3(ptr addrspace(1) %ptr) {
+; CHECK: test_ldg_i16
+define i16 @test_ldg_i16(ptr addrspace(1) %ptr) {
+; ld.global.nc.u16
+  %val = tail call i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret i16 %val
+}
+
+; CHECK: test_ldg_i32
+define i32 @test_ldg_i32(ptr addrspace(1) %ptr) {
 ; ld.global.nc.u32
   %val = tail call i32 @llvm.nvvm.ldg.global.i.i32.p1(ptr addrspace(1) %ptr, i32 4)
   ret i32 %val
 }
+
+; CHECK: test_ldg_i64
+define i64 @test_ldg_i64(ptr addrspace(1) %ptr) {
+; ld.global.nc.u64
+  %val = tail call i64 @llvm.nvvm.ldg.global.i.i64.p1(ptr addrspace(1) %ptr, i32 8)
+  ret i64 %val
+}
+
+; CHECK: test_ldg_f32
+define float @test_ldg_f32(ptr addrspace(1) %ptr) {
+; ld.global.nc.u64
+  %val = tail call float @llvm.nvvm.ldg.global.f.f32.p1(ptr addrspace(1) %ptr, i32 4)
+  ret float %val
+}
+
+; CHECK: test_ldg_f64
+define double @test_ldg_f64(ptr addrspace(1) %ptr) {
+; ld.global.nc.u64
+  %val = tail call double @llvm.nvvm.ldg.global.f.f64.p1(ptr addrspace(1) %ptr, i32 8)
+  ret double %val
+}
+
+; CHECK: test_ldg_f16
+define half @test_ldg_f16(ptr addrspace(1) %ptr) {
+; ld.global.nc.b16
+  %val = tail call half @llvm.nvvm.ldg.global.f.f16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret half %val
+}
+
+; CHECK: test_ldg_v2f16
+define <2 x half> @test_ldg_v2f16(ptr addrspace(1) %ptr) {
+; ld.global.nc.b32
+  %val = tail call <2 x half> @llvm.nvvm.ldg.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret <2 x half> %val
+}
Index: clang/test/CodeGen/builtins-nvptx-native-half-type.c
===
--- clang/test/CodeGen/builtins-nvptx-native-half-type.c
+++ clang/test/CodeGen/builtins-nvptx-native-half-type.c
@@ -172,3 +172,12 @@
 #endif
   // CHECK: ret void
 }
+
+// CHECK-LABEL: nvvm_ldg_native_half_types
+__device__ void nvvm_ldg_native_half_types(const void *p) {
+  // CHECK: call half @llvm.nvvm.ldg.global.f.f16.p0
+  __nvvm_ldg_h((const __fp16 *)p);
+  typedef __fp16 __fp16v2 __attribute__((ext_vector_type(2)));
+  // CHECK: call <2 x half> @llvm.nvvm.ldg.global.f.v2f16.p0
+  __nvvm_ldg_h2((const __fp16v2 *)p);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -18228,7 +18228,9 @@
 // elements, its alignment is set to number of elements times the alignment
 // of its member: n*alignof(t)."
 return MakeLdg(Intrinsic::nvvm_ldg_global_i);
+  case NVPTX::BI__nvvm_ldg_h:
   case NVPTX::BI__nvvm_ldg_f:
+  case NVPTX::BI__nvvm_ldg_h2:
   case NVPTX::BI__nvvm_ldg_f2:
   case NVPTX::BI__nvvm_ldg_f4:
   case NVPTX::BI__nvvm_ldg_d:
Index:

[PATCH] D144273: [clang][ASTImporter] Add VaList declaration to lookup table.

2023-03-03 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy accepted this revision.
donat.nagy added a comment.

LGTM, the test result sounds promising, let's hope that it'll work in the CI as 
well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144273

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


[PATCH] D145229: [analyzer] Improve the documentation of the alpha.security.taint.TaintPropagation checker

2023-03-03 Thread Daniel Krupp via Phabricator via cfe-commits
dkrupp created this revision.
dkrupp added a project: clang.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, gamesh411, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a project: All.
dkrupp requested review of this revision.
Herald added a subscriber: cfe-commits.

We extend the checker documentation with the following information

-How the user can mark inline that a data sanitation was performed performed to 
make a superflous report disappear
-Add references to CWEs and coding guidelines
-Describe the limitations of the checker
-Provide life-like examples


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145229

Files:
  clang/docs/analyzer/checkers.rst

Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -66,7 +66,7 @@
 
 core.NullDereference (C, C++, ObjC)
 """
-Check for dereferences of null pointers. 
+Check for dereferences of null pointers.
 
 This checker specifically does
 not report null pointer dereferences for x86 and x86-64 targets when the
@@ -75,7 +75,7 @@
 `__
 for reference.
 
-The ``SuppressAddressSpaces`` option suppresses 
+The ``SuppressAddressSpaces`` option suppresses
 warnings for null dereferences of all pointers with address spaces. You can
 disable this behavior with the option
 ``-analyzer-config core.NullDereference:SuppressAddressSpaces=false``.
@@ -2366,17 +2366,119 @@
 alpha.security.taint.TaintPropagation (C, C++)
 ""
 
-Taint analysis identifies untrusted sources of information (taint sources), rules as to how the untrusted data flows along the execution path (propagation rules), and points of execution where the use of tainted data is risky (taints sinks).
+Taint analysis identifies potential security vulnerabilities where
+attacker can inject malicious data to the program to execute an attack
+(privilege escalation, command injection, SQL injection etc.).
+
+The malicious data is injected at the taint source (e.g. getenv() call)
+which is then propagated through function calls and being used as arguments of
+sensitive operations, also called as taint sinks (e.g. system() call).
+
+One can defend agains this type of vulnerability by always checking and
+santizing the potentially malicious, untrusted user input.
+
+The goal of the checker is to discover and show to the user these potential
+taint source-sink pairs and the propagation call chain.
+
 The most notable examples of taint sources are:
 
   - network originating data
+  - files or standard input
   - environment variables
   - database originating data
 
-``GenericTaintChecker`` is the main implementation checker for this rule, and it generates taint information used by other checkers.
+Let us examine a practical example of a Command Injection attack.
+.. code-block:: C
+ //Command Injection Vulnerability Example
 
-.. code-block:: c
+ int main(int argc, char** argv) {
+  char cmd[1024] = "/bin/cat ";
+  char filename[1024];
+  printf("Filename:");
+  scanf (" %1023[^\n]", filename); // The attacker can inject a shell escape here
+
+  if (access(filename,F_OK)){
+printf("File does not exist\n");
+return -1;
+  }
+  strcat(cmd, filename);
+  system(cmd); // Warning: Untrusted data is passed to a system call
+ }
+
+The program prints the content of any user specified file.
+Unfortunately the attacker can execute arbitrary commands
+with shell escapes. For example with the following input the `ls` command is also
+executed after the contents of `/etc/shadow` is printed.
+`Input: /etc/shadow ; ls /`
+
+The analysis implemented in this checker points out this problem.
+
+One can protect against such attack by for example checking if the provided
+input refers to a valid file.
+.. code-block:: C
+ //No vulnerability anymore, but we still get the warning.
+ int main(int argc, char** argv) {
+  char cmd[1024] = "/bin/cat ";
+  char filename[1024];
+  printf("Filename:");
+  scanf (" %1023[^\n]", filename); // The attacker can inject a shell escape here
+
+  if (access(filename,F_OK)){//sanitizing user input
+printf("File does not exist\n");
+return -1;
+  }
+  // filename is safe after this point
+  strcat(cmd, filename);
+  system(cmd); // Superflous Warning: Untrusted data is passed to a system call
+ }
+
+Unfortunately, the checker cannot discover automatically
+that the programmer have performed data sanitation, so it still emits the warning.
+
+One can get rid of this superflous warning by telling about such data sanitation
+actions to the analyzer by adding the following lines.
+
+.. code-block:: C
+ //Marking sanitized variables safe.
+ //No vulnerability anymore, no warning.
+
+ //User defiend csa

[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

yln wrote:
> zixuw wrote:
> > dmaclach wrote:
> > > yln wrote:
> > > > This should work, right?
> > > No.. darwin should fail with the `-static-libsan` flag. This is the test 
> > > that was failing and caused the rollback.
> > I think @yln is suggesting using `REQUIRES: asan-static-runtime` instead of 
> > `XFAIL: darwin`. I wasn't aware of that conditional but yeah that should be 
> > better if it works.
> I meant using `// REQUIRES: asan-static-runtime ` instead of `XFAIL: darwin` 
> since it seems that we already have a lit feature for it.
I think UNSUPPORTED: darwin makes the most sense here. I don't think lit 
understands that REQUIRES: asan-static-runtime should result in skipping the 
test on Darwin as it does not know about this dependency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144672

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


[PATCH] D144967: [PowerPC] Recognize long CPU name for -mtune in Clang

2023-03-03 Thread Amy Kwan via Phabricator via cfe-commits
amyk added a comment.

In D144967#4164858 , @nathanchance 
wrote:

> Could this be merged into `main` and backported to `release/16.x`? If this 
> makes 16.0.0 final, I think the kernel can avoid working around this issue 
> altogether, as `-mtune` was only wired up to do something on PowerPC in 
> during the 16 development cycle; in prior versions, it was ignored so any 
> value was accepted.

@nathanchance Just wanted to let you know that this patch is now backported 
into `release/16.x`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144967

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


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-03 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added a comment.

@kiranchandramohan I've added the MLIR test as requested. Please let me know if 
any other changes are required :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142914

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


[PATCH] D144179: [Clang] Added functionality to provide config file name via env variable

2023-03-03 Thread mgabka via Phabricator via cfe-commits
mgabka added a comment.

In D144179#4146599 , @MaskRay wrote:

> This looks like introducing a footgun (when something behaves differently 
> from an upstream Clang, it would be difficult for toolchain maintainers to 
> know why).
> Why can't your user specify `CLANG_CONFIG_FILE_SYSTEM_DIR`?

hi @MaskRay,
The reason we wanted to suggest use of environment variable is that the 
CLANG_CONFIG_FILE_SYSTEM_DIR is only defined at compilation time, after 
discussing it once again we would rather lean towards introducing an 
environment variable with similar semantics as CLANG_CONFIG_FILE_SYSTEM_DIR or 
rather ``CLANG_CONFIG_FILE_USER_DIR``, the motivation here is that it will 
allow to specify the directory to search for config files in a dynamic way, 
without need to recompile the compiler.
It is for user convenience in situations when they are using a system wide 
installation in a location where they do not have access right, and the 
``CLANG_CONFIG_FILE_SYSTEM_DIR`` and ``CLANG_CONFIG_FILE_USER_DIR`` were not 
defined at build time.

We realised that environment variables are already used in this area, for 
example CLANG_NO_DEFAULT_CONFIG, so adding another one is not breaking existing 
convention.

What do you think about it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144179

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


[PATCH] D143436: [clangd] Move standard options adaptor to CommandMangler

2023-03-03 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 502110.
DmitryPolukhin added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/Inputs/did-change-configuration-params.args
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/Tooling.cpp

Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -299,6 +300,31 @@
   }
 }
 
+void addExpandedResponseFiles(std::vector &CommandLine,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem &FS) {
+  bool SeenRSPFile = false;
+  llvm::SmallVector Argv;
+  Argv.reserve(CommandLine.size());
+  for (auto &Arg : CommandLine) {
+Argv.push_back(Arg.c_str());
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
+  }
+  if (!SeenRSPFile)
+return;
+  llvm::BumpPtrAllocator Alloc;
+  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
+  llvm::Error Err =
+  ECtx.setVFS(&FS).setCurrentDir(WorkingDir).expandResponseFiles(Argv);
+  if (Err)
+llvm::errs() << Err;
+  // Don't assign directly, Argv aliases CommandLine.
+  std::vector ExpandedArgv(Argv.begin(), Argv.end());
+  CommandLine = std::move(ExpandedArgv);
+}
+
 } // namespace tooling
 } // namespace clang
 
@@ -684,7 +710,7 @@
 
   if (!Invocation.run())
 return nullptr;
- 
+
   assert(ASTs.size() == 1);
   return std::move(ASTs[0]);
 }
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -48,28 +49,9 @@
 
 private:
   std::vector expand(std::vector Cmds) const {
-for (auto &Cmd : Cmds) {
-  bool SeenRSPFile = false;
-  llvm::SmallVector Argv;
-  Argv.reserve(Cmd.CommandLine.size());
-  for (auto &Arg : Cmd.CommandLine) {
-Argv.push_back(Arg.c_str());
-if (!Arg.empty())
-  SeenRSPFile |= Arg.front() == '@';
-  }
-  if (!SeenRSPFile)
-continue;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
-  llvm::Error Err = ECtx.setVFS(FS.get())
-.setCurrentDir(Cmd.Directory)
-.expandResponseFiles(Argv);
-  if (Err)
-llvm::errs() << Err;
-  // Don't assign directly, Argv aliases CommandLine.
-  std::vector ExpandedArgv(Argv.begin(), Argv.end());
-  Cmd.CommandLine = std::move(ExpandedArgv);
-}
+for (auto &Cmd : Cmds)
+  tooling::addExpandedResponseFiles(Cmd.CommandLine, Cmd.Directory,
+Tokenizer, *FS);
 return Cmds;
   }
 
Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -506,6 +506,12 @@
 void addTargetAndModeForProgramName(std::vector &CommandLine,
 StringRef InvokedAs);
 
+/// Helper function that expands response files in command line.
+void addExpandedResponseFiles(std::vector &CommandLine,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem &FS);
+
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
   ArrayRef CC1Args,
Index: clang-tools-extra/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/clangd

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-03 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan requested changes to this revision.
kiranchandramohan added a comment.
This revision now requires changes to proceed.

Thanks for making the change.
I am still going through the patch, I have a few comments.




Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:1574-1575
+  const LocationDescription &Loc, OpenMPIRBuilder::InsertPointTy CodeGenIP,
+  bool HasRegion, SmallVector &MapTypeFlags,
+  SmallVector &MapNames, struct MapperAllocas &MapperAllocas,
+  Function *MapperFunc, int64_t DeviceID, Value *IfCond,

SmallVector -> SmallVectorImpl 
https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4052-4060
+  // LLVM utilities like blocks with terminators.
+  auto *UI = Builder.CreateUnreachable();
+  Instruction *ThenTI = UI, *ElseTI = nullptr;
+  if (IfCond) {
+SplitBlockAndInsertIfThenElse(IfCond, UI, &ThenTI, &ElseTI);
+ThenTI->getParent()->setName("omp_if.then");
+ElseTI->getParent()->setName("omp_if.else");

There is some recent recommendation to not insert artificial instructions and 
remove them. The preferred approach is to use `splitBB` function(s) inside the 
OpenMPIRBuilder. This function works on blocks without terminators. You can 
consult the `IfCondition` code in `createParallel`.



Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:4983
+  CallInst *TargetDataCall = dyn_cast(&BB->back());
+  BB->dump();
+  EXPECT_NE(TargetDataCall, nullptr);

Is this a debugging leftover?



Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:4990
+  EXPECT_TRUE(TargetDataCall->getOperand(2)->getType()->isIntegerTy(32));
+  EXPECT_TRUE(TargetDataCall->getOperand(8)->getType()->isPointerTy());
+}

Call verifyModule to ensure the IR is well formed.



Comment at: mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h:13-14
+
+#ifndef MLIR_TARGET_LLVMIR_DIALECT_UTILS_H
+#define MLIR_TARGET_LLVMIR_DIALECT_UTILS_H
+

Nit: The header guards would need changing.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1471
+mapTypes = enterDataOp.getMapTypes();
+mapperFunc = ompBuilder->getOrCreateRuntimeFunctionPtr(
+llvm::omp::OMPRTL___tgt_target_data_begin_mapper);

Ideally we would not want to create an OpenMP runtime calls in the Translation. 
This is the job of the OpenMPIRbuilder. I would recommend passing a boolean to 
the OpenMPIRBuilder and let the IRBuilder pick up the runtime function.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1492
+mapTypes = exitDataOp.getMapTypes();
+mapperFunc = ompBuilder->getOrCreateRuntimeFunctionPtr(
+llvm::omp::OMPRTL___tgt_target_data_end_mapper);

Same comment as above.



Comment at: mlir/test/Target/LLVMIR/omptarget-llvm.mlir:1
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+

In MLIR it is preferred to test the minimal set of functionalities. So you will 
have to minimize the CHECK lines and write them manually. Focus on Checking the 
runtime call and any important IR inserted by the IRBuilder. Keep the contents 
of the region to a minimum.
https://mlir.llvm.org/getting_started/TestingGuide/#filecheck-best-practices


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142914

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


[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-03 Thread jonathan molinatto via Phabricator via cfe-commits
jrmolin updated this revision to Diff 502112.
jrmolin added a comment.

Finally figured out how to run the latest `git-clang-format` on the code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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

Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4735,6 +4735,17 @@
 return true;
   }
 
+  // If AlwaysBreakBeforeFunctionParameters is true, we want to break before
+  // the next parameter, if there is one.
+  if (Left.is(tok::l_paren) && Style.AlwaysBreakBeforeFunctionParameters &&
+  !Right.is(tok::r_paren)) {
+if (Left.Previous) {
+  const FormatToken &TwoPrevious = *Left.Previous;
+  if (TwoPrevious.is(TT_FunctionDeclarationName))
+return true;
+}
+  }
+
   // If the last token before a '}', ']', or ')' is a comma or a trailing
   // comment, the intention is to insert a line break after it in order to make
   // shuffling around entries easier. Import statements, especially in
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -870,6 +870,8 @@
Style.AlwaysBreakAfterReturnType);
 IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
+IO.mapOptional("AlwaysBreakBeforeFunctionParameters",
+   Style.AlwaysBreakBeforeFunctionParameters);
 IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
 IO.mapOptional("AttributeMacros", Style.AttributeMacros);
@@ -1505,6 +1507,7 @@
   FormatStyle::SIS_WithoutElse;
   GoogleStyle.AllowShortLoopsOnASingleLine = true;
   GoogleStyle.AlwaysBreakBeforeMultilineStrings = true;
+  GoogleStyle.AlwaysBreakBeforeFunctionParameters = false;
   GoogleStyle.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes;
   GoogleStyle.DerivePointerAlignment = true;
   GoogleStyle.IncludeStyle.IncludeCategories = {{"^", 2, 0, false},
@@ -1577,6 +1580,7 @@
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
 GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
 GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
+GoogleStyle.AlwaysBreakBeforeFunctionParameters = false;
 GoogleStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
 GoogleStyle.ColumnLimit = 100;
 GoogleStyle.SpaceAfterCStyleCast = true;
@@ -1588,6 +1592,7 @@
 // TODO: still under discussion whether to switch to SLS_All.
 GoogleStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_Empty;
 GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
+GoogleStyle.AlwaysBreakBeforeFunctionParameters = false;
 GoogleStyle.BreakBeforeTernaryOperators = false;
 // taze:, triple slash directives (`/// <...`), tslint:, and @see, which is
 // commonly followed by overlong URLs.
@@ -1613,6 +1618,7 @@
 GoogleStyle.BreakStringLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
+GoogleStyle.AlwaysBreakBeforeFunctionParameters = false;
 GoogleStyle.ColumnLimit = 100;
 // "Regroup" doesn't work well for ObjC yet (main header heuristic,
 // relationship between ObjC standard library headers and other heades,
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -354,6 +354,12 @@
 auto LambdaBodyLength = getLengthToMatchingParen(Current, State.Stack);
 return LambdaBodyLength > getColumnLimit(State);
   }
+  // Check if we want to break before function parameters in declarations
+  if (startsNextParameter(Current, Style) &&
+  Style.AlwaysBreakBeforeFunctionParameters &&
+  State.Line->MustBeDeclaration) {
+return true;
+  }
   if (Current.MustBreakBefore ||
   (Current.is(TT_InlineASMColon) &&
(Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_Always ||
@@ -1055,7 +1061,9 @@
 // If we are breaking after '(', '{', '<', or this is the break after a ':'
 // to start a member initializater list in a constructor, this should not
 // be considered bin packing unless the relevant AllowAll option is false or
-// this is a dict/object literal.
+// this is a dict/object literal. Break if
+// AlwaysBreakBeforeFunctionParameters is true and it's a function
+// declaration.
 bool PreviousIsB

[PATCH] D145227: [LLVM][OHOS] Clang toolchain and targets

2023-03-03 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

I'm not familiar with the details of toolchain config, but added some general 
comments.




Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1404
+  // OHOS-specific defaults for PIC/PIE
+  if (Triple.isOHOSFamily()) {
+switch (Triple.getArch()) {

Collapse this into `if isohos && triple.getarch is...`.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1702
+  if (TC.getTriple().isOHOSFamily() && UNW != ToolChain::UNW_None) {
+CmdArgs.push_back("-l:libunwind.a");
+return;

Please add a comment explaining this. Even if it is just "OHOS is only 
compatible with libunwind". At least then we know it's nothing more mysterious.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:645
 
-  if (WantPthread && !isAndroid)
+  // We don't need libpthread neither for bionic nor for musl
+  if (WantPthread && !isAndroid && !isOHOSFamily)

And musl is what OHOS uses? Please add that to the comment if so "for musl, 
which OHOS uses...".



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2318
+  "mipsel-linux-gnu", "mips-img-linux-gnu", "mipsisa32r6el-linux-gnu",
+  "mipsel-linux-ohos"};
 

No riscv related changes needed in this file?



Comment at: clang/lib/Driver/ToolChains/OHOS.cpp:164
+  // For compatibility with arm-liteos sysroot
+  // FIXME: Remove this when we'll use arm-liteos sysroot produced by build.py.
+  addPathIfExists(

Keep FIXMEs that refer to stuff outside the project downstream please :)



Comment at: clang/lib/Driver/ToolChains/OHOS.cpp:372
+// FIXME: gnu or both???
+CmdArgs.push_back("--hash-style=both");
+  }

Maybe this helps? 
https://github.com/llvm/llvm-project/blob/e00c73c856a325008afead10cfb3e9d0fc4a1e41/clang/lib/Driver/ToolChains/Linux.cpp#L235

(no idea myself)



Comment at: clang/test/Driver/ohos.c:240
+
+// CHECK-OHOS-PTHREAD-NOT: -lpthread
+

This one is checking that we do not link to a pthread library, because when 
using musl, it already provides one?

Just checking you're not accepting the option but doing the opposite here. 
Worth adding a comment to explain the reasoning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145227

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


[PATCH] D145238: [NVPTX] Expose LDU builtins

2023-03-03 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda created this revision.
jchlanda added a reviewer: tra.
Herald added subscribers: mattd, gchakrabarti, asavonic.
Herald added a project: All.
jchlanda requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jholewinski.
Herald added projects: clang, LLVM.

Also check if native half types are supported to give more descriptive error 
message, without it clang only reports incorrect intrinsic return type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145238

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-nvptx-native-half-type-err.c
  clang/test/CodeGen/builtins-nvptx-native-half-type.c
  clang/test/CodeGen/builtins-nvptx.c
  llvm/test/CodeGen/NVPTX/ldu-ldg.ll

Index: llvm/test/CodeGen/NVPTX/ldu-ldg.ll
===
--- llvm/test/CodeGen/NVPTX/ldu-ldg.ll
+++ llvm/test/CodeGen/NVPTX/ldu-ldg.ll
@@ -3,7 +3,13 @@
 
 
 declare i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i16 @llvm.nvvm.ldu.global.i.i16.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i64 @llvm.nvvm.ldu.global.i.i64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare float @llvm.nvvm.ldu.global.f.f32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare double @llvm.nvvm.ldu.global.f.f64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare half @llvm.nvvm.ldu.global.f.f16.p1(ptr addrspace(1) %ptr, i32 %align)
+declare <2 x half> @llvm.nvvm.ldu.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 %align)
 
 declare i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 %align)
@@ -21,6 +27,13 @@
   ret i8 %val
 }
 
+; CHECK: test_ldu_i16
+define i16 @test_ldu_i16(ptr addrspace(1) %ptr) {
+; ldu.global.u16
+  %val = tail call i16 @llvm.nvvm.ldu.global.i.i16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret i16 %val
+}
+
 ; CHECK: test_ldu_i32
 define i32 @test_ldu_i32(ptr addrspace(1) %ptr) {
 ; ldu.global.u32
@@ -28,6 +41,41 @@
   ret i32 %val
 }
 
+; CHECK: test_ldu_i64
+define i64 @test_ldu_i64(ptr addrspace(1) %ptr) {
+; ldu.global.u64
+  %val = tail call i64 @llvm.nvvm.ldu.global.i.i64.p1(ptr addrspace(1) %ptr, i32 8)
+  ret i64 %val
+}
+
+; CHECK: test_ldu_f32
+define float @test_ldu_f32(ptr addrspace(1) %ptr) {
+; ldu.global.u64
+  %val = tail call float @llvm.nvvm.ldu.global.f.f32.p1(ptr addrspace(1) %ptr, i32 4)
+  ret float %val
+}
+
+; CHECK: test_ldu_f64
+define double @test_ldu_f64(ptr addrspace(1) %ptr) {
+; ldu.global.u64
+  %val = tail call double @llvm.nvvm.ldu.global.f.f64.p1(ptr addrspace(1) %ptr, i32 8)
+  ret double %val
+}
+
+; CHECK: test_ldu_f16
+define half @test_ldu_f16(ptr addrspace(1) %ptr) {
+; ldu.global.b16
+  %val = tail call half @llvm.nvvm.ldu.global.f.f16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret half %val
+}
+
+; CHECK: test_ldu_v2f16
+define <2 x half> @test_ldu_v2f16(ptr addrspace(1) %ptr) {
+; ldu.global.b32
+  %val = tail call <2 x half> @llvm.nvvm.ldu.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret <2 x half> %val
+}
+
 ; CHECK: test_ldg_i8
 define i8 @test_ldg_i8(ptr addrspace(1) %ptr) {
 ; ld.global.nc.u8
Index: clang/test/CodeGen/builtins-nvptx.c
===
--- clang/test/CodeGen/builtins-nvptx.c
+++ clang/test/CodeGen/builtins-nvptx.c
@@ -652,6 +652,97 @@
   __nvvm_ldg_d2((const double2 *)p);
 }
 
+// CHECK-LABEL: nvvm_ldu
+__device__ void nvvm_ldu(const void *p) {
+  // CHECK: call i8 @llvm.nvvm.ldu.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
+  // CHECK: call i8 @llvm.nvvm.ldu.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
+  __nvvm_ldu_c((const char *)p);
+  __nvvm_ldu_uc((const unsigned char *)p);
+
+  // CHECK: call i16 @llvm.nvvm.ldu.global.i.i16.p0(ptr {{%[0-9]+}}, i32 2)
+  // CHECK: call i16 @llvm.nvvm.ldu.global.i.i16.p0(ptr {{%[0-9]+}}, i32 2)
+  __nvvm_ldu_s((const short *)p);
+  __nvvm_ldu_us((const unsigned short *)p);
+
+  // CHECK: call i32 @llvm.nvvm.ldu.global.i.i32.p0(ptr {{%[0-9]+}}, i32 4)
+  // CHECK: call i32 @llvm.nvvm.ldu.global.i.i32.p0(ptr {{%[0-9]+}}, i32 4)
+  __nvvm_ldu_i((const int *)p);
+  __nvvm_ldu_ui((const unsigned int *)p);
+
+  // LP32: call i32 @llvm.nvvm.ldu.global.i.i32.p0(ptr {{%[0-9]+}}, i32 4)
+  // LP32: call i32 @llvm.nvvm.ldu.global.i.i32.p0(ptr {{%[0-9]+}}, i32 4)
+  // LP64: call i64 @llvm.nvvm.ldu.global.i.i64.p0(ptr {{%[0-9]+}}, i32 8)
+  // LP64: call i64 @llvm.nvvm.ldu.global.i.i64.p0(ptr {{%[0-9]+}}, i32 8)
+  __nvvm_ldu_l((const long *)p);
+  __nvvm_ldu_ul((const unsigned long *)p);
+
+  // CHECK: call float @llvm.nvvm.ldu.global.f.f32.p0(ptr {{%[0-9]+}}, i32 4)
+  __nvvm_ldu_f((const float *)p);
+  // CHECK: call double @llvm.nvvm.ldu.global.f.f64.p0(ptr {{%[0-9]+}}, i32 8)
+  __nvvm_ldu_d((const double *)p);
+
+  // CHECK: call <2 x i8> @llvm.nvvm.ldu.global.i.v2i8.

[PATCH] D65956: clang: Diag running out of file handles while looking for files

2023-03-03 Thread Axel Naumann via Phabricator via cfe-commits
karies added a comment.
Herald added a project: All.

Similar to the concern raised at 
https://github.com/llvm/llvm-project/commit/50fcf7285eeb001d751eadac5d001a0e216fd701
 we have received user reports about this patch: with `-Ino-access-permissions 
-Iall-good`, clang will throw an error (EACCES) even though header search goes 
on and will find the header in `all-good`. That seems a misleading an 
unnecessary error, especially as the header *is* found later, yet compilation 
"fails" because of this diagnostic.

I would propose to collect these errors, and where originally (before this 
patch), cling would complain "file not found" we could diagnose "while 
searching for this header, the following errors have been seen" and reporting 
the uniq-ed set of collected diags - but *only* in the case where the file 
cannot be found. This would prevent spurious diags during iteration through the 
SearchDirs when HeaderSearch actually finds the file. And I am fully aware that 
it's pointless to propose something without providing a differential :-/

FYI here's what we do right now to handle the EACCES case:

  patch
  --- a/interpreter/llvm/src/tools/clang/lib/Lex/HeaderSearch.cpp
  +++ b/interpreter/llvm/src/tools/clang/lib/Lex/HeaderSearch.cpp
  @@ -367,7 +367,9 @@ Optional 
HeaderSearch::getFileAndSuggestModule(
   std::error_code EC = llvm::errorToErrorCode(File.takeError());
   if (EC != llvm::errc::no_such_file_or_directory &&
   EC != llvm::errc::invalid_argument &&
  -EC != llvm::errc::is_a_directory && EC != 
llvm::errc::not_a_directory) {
  +EC != llvm::errc::is_a_directory &&
  +EC != llvm::errc::not_a_directory &&
  +EC != llvm::errc::permission_denied) {
 Diags.Report(IncludeLoc, diag::err_cannot_open_file)
 << FileName << EC.message();
   }


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65956

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


[PATCH] D145178: [clang][NFC] reformats the SARIF diagnostic test so it's human readable

2023-03-03 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, this is incremental progress. Hopefully we won't be adding too many more 
RUN lines to this file though (sticking too many tests into one file is also 
tech debt).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145178

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


[PATCH] D145244: [clang-format] Add ability to trace tokens.

2023-03-03 Thread Manuel Klimek via Phabricator via cfe-commits
klimek created this revision.
klimek added a reviewer: sammccall.
Herald added a project: All.
klimek requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145244

Files:
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatDebug.cpp
  clang/lib/Format/FormatDebug.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp

Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "UnwrappedLineFormatter.h"
+#include "ContinuationIndenter.h"
+#include "FormatDebug.h"
 #include "FormatToken.h"
 #include "NamespaceEndCommentsFixer.h"
 #include "WhitespaceManager.h"
@@ -1252,17 +1254,43 @@
   /// penalty of \p Penalty. Insert a line break if \p NewLine is \c true.
   void addNextStateToQueue(unsigned Penalty, StateNode *PreviousNode,
bool NewLine, unsigned *Count, QueueType *Queue) {
-if (NewLine && !Indenter->canBreak(PreviousNode->State))
+bool MustBreak = false;
+bool MustNotBreak = false;
+LLVM_DEBUG({
+  if (internal::DebugForceMustBreak().match(
+  PreviousNode->State.NextToken->TokenText)) {
+MustBreak = true;
+  }
+  if (internal::DebugForceMustNotBreak().match(
+  PreviousNode->State.NextToken->TokenText)) {
+MustNotBreak = true;
+  }
+});
+
+if (NewLine && (!Indenter->canBreak(PreviousNode->State) || MustNotBreak) &&
+!MustBreak) {
+  DEBUG_FORMAT_TRACE_TOKEN(*PreviousNode->State.NextToken,
+   "Cannot break before");
   return;
-if (!NewLine && Indenter->mustBreak(PreviousNode->State))
+}
+if (!NewLine && (Indenter->mustBreak(PreviousNode->State) || MustBreak) &&
+!MustNotBreak) {
+  DEBUG_FORMAT_TRACE_TOKEN(*PreviousNode->State.NextToken,
+   "Must break before");
   return;
+}
 
 StateNode *Node = new (Allocator.Allocate())
 StateNode(PreviousNode->State, NewLine, PreviousNode);
 if (!formatChildren(Node->State, NewLine, /*DryRun=*/true, Penalty))
   return;
 
-Penalty += Indenter->addTokenToState(Node->State, NewLine, true);
+unsigned AddPenalty = Indenter->addTokenToState(Node->State, NewLine, true);
+DEBUG_FORMAT_TRACE_TOKEN(*PreviousNode->State.NextToken,
+ "Penalty for " << (!NewLine ? "not " : "")
+<< "breaking before token is "
+<< AddPenalty);
+Penalty += AddPenalty;
 
 Queue->push(QueueItem(OrderedPenalty(Penalty, *Count), Node));
 ++(*Count);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -13,6 +13,8 @@
 //===--===//
 
 #include "TokenAnnotator.h"
+#include "ContinuationIndenter.h"
+#include "FormatDebug.h"
 #include "FormatToken.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
@@ -3244,6 +3246,7 @@
 
 const auto &Children = Prev->Children;
 if (!Children.empty() && Children.back()->Last->is(TT_LineComment)) {
+  DEBUG_FORMAT_TRACE_TOKEN(*Current, "MustBreakBefore");
   Current->MustBreakBefore = true;
 } else {
   Current->MustBreakBefore =
@@ -3252,6 +3255,8 @@
   Current->is(TT_FunctionDeclarationName)) {
 Current->MustBreakBefore = mustBreakForReturnType(Line);
   }
+  DEBUG_FORMAT_TRACE_TOKEN(*Current, (Current->MustBreakBefore ? "" : "!")
+ << "MustBreakBefore");
 }
 
 Current->CanBreakBefore =
Index: clang/lib/Format/FormatDebug.h
===
--- /dev/null
+++ clang/lib/Format/FormatDebug.h
@@ -0,0 +1,41 @@
+//===--- FormatDebug.h - Format C++ code *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file declares utilities used in clang-format in debug mode.
+///
+//===--===//
+#ifndef LLVM_CLANG_LIB_FORMAT_FORMATDEBUG_H
+#define LLVM_CLANG_LIB_FORMAT_FORMATDEBUG_H
+
+#include "llvm/Support/Regex.h"
+
+namespace clang {
+namespace format {

[PATCH] D145244: [clang-format] Add ability to trace tokens.

2023-03-03 Thread Manuel Klimek via Phabricator via cfe-commits
klimek updated this revision to Diff 502123.
klimek added a comment.

Remove superfluous include.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145244

Files:
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatDebug.cpp
  clang/lib/Format/FormatDebug.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp

Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "UnwrappedLineFormatter.h"
+#include "FormatDebug.h"
 #include "FormatToken.h"
 #include "NamespaceEndCommentsFixer.h"
 #include "WhitespaceManager.h"
@@ -1252,17 +1253,43 @@
   /// penalty of \p Penalty. Insert a line break if \p NewLine is \c true.
   void addNextStateToQueue(unsigned Penalty, StateNode *PreviousNode,
bool NewLine, unsigned *Count, QueueType *Queue) {
-if (NewLine && !Indenter->canBreak(PreviousNode->State))
+bool MustBreak = false;
+bool MustNotBreak = false;
+LLVM_DEBUG({
+  if (internal::DebugForceMustBreak().match(
+  PreviousNode->State.NextToken->TokenText)) {
+MustBreak = true;
+  }
+  if (internal::DebugForceMustNotBreak().match(
+  PreviousNode->State.NextToken->TokenText)) {
+MustNotBreak = true;
+  }
+});
+
+if (NewLine && (!Indenter->canBreak(PreviousNode->State) || MustNotBreak) &&
+!MustBreak) {
+  DEBUG_FORMAT_TRACE_TOKEN(*PreviousNode->State.NextToken,
+   "Cannot break before");
   return;
-if (!NewLine && Indenter->mustBreak(PreviousNode->State))
+}
+if (!NewLine && (Indenter->mustBreak(PreviousNode->State) || MustBreak) &&
+!MustNotBreak) {
+  DEBUG_FORMAT_TRACE_TOKEN(*PreviousNode->State.NextToken,
+   "Must break before");
   return;
+}
 
 StateNode *Node = new (Allocator.Allocate())
 StateNode(PreviousNode->State, NewLine, PreviousNode);
 if (!formatChildren(Node->State, NewLine, /*DryRun=*/true, Penalty))
   return;
 
-Penalty += Indenter->addTokenToState(Node->State, NewLine, true);
+unsigned AddPenalty = Indenter->addTokenToState(Node->State, NewLine, true);
+DEBUG_FORMAT_TRACE_TOKEN(*PreviousNode->State.NextToken,
+ "Penalty for " << (!NewLine ? "not " : "")
+<< "breaking before token is "
+<< AddPenalty);
+Penalty += AddPenalty;
 
 Queue->push(QueueItem(OrderedPenalty(Penalty, *Count), Node));
 ++(*Count);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -13,6 +13,8 @@
 //===--===//
 
 #include "TokenAnnotator.h"
+#include "ContinuationIndenter.h"
+#include "FormatDebug.h"
 #include "FormatToken.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
@@ -3244,6 +3246,7 @@
 
 const auto &Children = Prev->Children;
 if (!Children.empty() && Children.back()->Last->is(TT_LineComment)) {
+  DEBUG_FORMAT_TRACE_TOKEN(*Current, "MustBreakBefore");
   Current->MustBreakBefore = true;
 } else {
   Current->MustBreakBefore =
@@ -3252,6 +3255,8 @@
   Current->is(TT_FunctionDeclarationName)) {
 Current->MustBreakBefore = mustBreakForReturnType(Line);
   }
+  DEBUG_FORMAT_TRACE_TOKEN(*Current, (Current->MustBreakBefore ? "" : "!")
+ << "MustBreakBefore");
 }
 
 Current->CanBreakBefore =
Index: clang/lib/Format/FormatDebug.h
===
--- /dev/null
+++ clang/lib/Format/FormatDebug.h
@@ -0,0 +1,41 @@
+//===--- FormatDebug.h - Format C++ code *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file declares utilities used in clang-format in debug mode.
+///
+//===--===//
+#ifndef LLVM_CLANG_LIB_FORMAT_FORMATDEBUG_H
+#define LLVM_CLANG_LIB_FORMAT_FORMATDEBUG_H
+
+#include "llvm/Support/Regex.h"
+
+namespace clang {
+namespace format {
+namespace internal {
+
+#ifndef NDE

[PATCH] D145201: [clang] fixes header processing for `-fdiagnostics-format=sarif`

2023-03-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

It looks like there's a valid precommit CI failure that needs to be addressed:

  
  Failed Tests (1):
Clang :: Frontend/sarif-diagnostics.cpp




Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:214
 void SARIFDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) 
{
-  assert(false && "Not implemented in SARIF mode");
+  SarifRule Rule = SarifRule::create().setRuleId(std::to_string(-1));
+  Rule = addDiagnosticLevelToRule(Rule, DiagnosticsEngine::Level::Note);

Why do we want -1 as the rule ID and... can we use `"-1"` instead of doing a 
string conversion?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145201

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


[PATCH] D142328: [clang][Interp] Fix compound assign operator types

2023-03-03 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Hi @tbaeder, I was looking for commits that mentions "fix" "assertion" or 
"crash" in the title, that are part of the `main` branch but not backported to 
`release/16.x` to be eventually released as `clang-16`.
I wonder what's the status of this and the related patches given that the 
commit that the summary mentions (490e8214fca48824beda8b508d6d6bbbf3d8d9a7 
) is 
present in `release/16.x`. I can also see that quite a few revert commits are 
also related to `Interp`.
It's probably the case that the mentioned change was removed from `clang-16` by 
f6ea1af9a4b71d27de2dde629224af1220c5c85b 
.

Could you please confirm that the changes around `Interp` are consistent and no 
patches are missing from the `release/16.x` just to be sure?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142328

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


[PATCH] D144967: [PowerPC] Recognize long CPU name for -mtune in Clang

2023-03-03 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

@amyk thank you so much!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144967

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


[PATCH] D142384: [C++20] Fix a crash with modules.

2023-03-03 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

@usaxena95 @ilya-biryukov, @hans, I wonder if we should backport this change to 
`release/16.x`. Otherwise, clang-16 won't have this fix. WDYT?
I'm also a bit worried that we don't have tests. And that we have "unexpected" 
sideeffects like what you mentioned @hans.

Given all these, I would probably vote for not backporting this, but this is 
the chance if we want.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142384

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


[PATCH] D144546: [clang][dataflow] Fix assert for CXXConstructExpr argument number

2023-03-03 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

By looking at the title, I get the impression that this fixes an assertion 
violation.
I also observed that this commit is part of `main` but not part of 
`release/16.x`, hence the `clang-16` would be released without this fix.

I want to raise awareness of backporting crash fixes to llvm releases. IMO 
that's a good practice.
So my question is, should we backport this patch to the release branch?

If so, could you please check if there are more commits like this for the 
dataflow library @ymandel?

I used `git log release/16.x..main --oneline 
clang/lib/{Analysis,AST,ASTMatchers,StaticAnalyzer} 
clang/include/clang/{Analysis,AST,ASTMatchers,StaticAnalyzer}  | grep -i 
'crash\|fix\|assert'` to check for relevant commits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144546

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


[PATCH] D145098: [clang][deps] Preserve input ordering in the full output

2023-03-03 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan added a comment.

Hi, this new test fails on AIX, could you take a look please?
https://lab.llvm.org/buildbot/#/builders/214/builds/6148/steps/6/logs/FAIL__Clang__modules-full-output-tu-order_c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145098

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


[PATCH] D127259: [CodeGen] guarantee templated static variables are initialized in the reverse instantiation order

2023-03-03 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:19907
+  if (Iter != I.end()) {
+SemaRef.PendingInstantiations.push_back(*Iter);
+I.erase(Iter);

Doesn't this invalidate the iterators? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127259

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


[PATCH] D144864: [Flang][Driver][MLIR] Add -fopenmp-is-device to Flang and link to an omp.is_device attribute

2023-03-03 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 502134.
agozillon added a comment.

- [MLIR][OpenMP] Fix attribute helpers to apply to more than builtin.module
- [Flang][mlir] Adding space at the end of the omp-is-device test file
- [Clang][Flang][Driver][Test] Add flang-omp.f90 to test 
fopenmp/fopenmp-is-device for flang driver-mode
- [Flang][MLIR][OpenMP] Add additional tests to omp-is-device.f90 test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144864

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  clang/test/Driver/flang/flang-omp.f90
  flang/include/flang/Frontend/LangOptions.def
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Lower/OpenMP/omp-is-device.f90
  flang/tools/bbc/bbc.cpp
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Index: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
===
--- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1417,6 +1417,26 @@
   return success();
 }
 
+//===--===//
+// OpenMPDialect helper functions
+//===--===//
+
+// Set the omp.is_device attribute on the module with the specified boolean
+void OpenMPDialect::setIsDevice(Operation* module, bool isDevice) {
+  module->setAttr(
+  mlir::StringAttr::get(module->getContext(), llvm::Twine{"omp.is_device"}),
+  mlir::BoolAttr::get(module->getContext(), isDevice));
+}
+
+// Return the value of the omp.is_device attribute stored in the module if it
+// exists, otherwise return false by default
+bool OpenMPDialect::getIsDevice(Operation* module) {
+  if (Attribute isDevice = module->getAttr("omp.is_device"))
+if (isDevice.isa())
+  return isDevice.dyn_cast().getValue();
+  return false;
+}
+
 #define GET_ATTRDEF_CLASSES
 #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
 
Index: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
===
--- mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -28,6 +28,15 @@
   let cppNamespace = "::mlir::omp";
   let dependentDialects = ["::mlir::LLVM::LLVMDialect"];
   let useDefaultAttributePrinterParser = 1;
+
+  let extraClassDeclaration = [{
+// Set the omp.is_device attribute on the module with the specified boolean
+static void setIsDevice(Operation* module, bool isDevice);
+
+// Return the value of the omp.is_device attribute stored in the module if it
+// exists, otherwise return false by default
+static bool getIsDevice(Operation* module);
+  }];
 }
 
 // OmpCommon requires definition of OpenACC_Dialect.
Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -38,6 +38,7 @@
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/unparse-with-symbols.h"
 #include "flang/Version.inc"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/IR/AsmState.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/MLIRContext.h"
@@ -122,6 +123,11 @@
 llvm::cl::desc("enable openmp"),
 llvm::cl::init(false));
 
+static llvm::cl::opt
+enableOpenMPDevice("fopenmp-is-device",
+   llvm::cl::desc("enable openmp device compilation"),
+   llvm::cl::init(false));
+
 static llvm::cl::opt enableOpenACC("fopenacc",
  llvm::cl::desc("enable openacc"),
  llvm::cl::init(false));
@@ -237,6 +243,8 @@
   kindMap, loweringOptions, {});
   burnside.lower(parseTree, semanticsContext);
   mlir::ModuleOp mlirModule = burnside.getModule();
+  if (enableOpenMP)
+mlir::omp::OpenMPDialect::setIsDevice(mlirModule, enableOpenMPDevice);
   std::error_code ec;
   std::string outputName = outputFilename;
   if (!outputName.size())
Index: flang/test/Lower/OpenMP/omp-is-device.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/omp-is-device.f90
@@ -0,0 +1,19 @@
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DEVICE
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefix=HOST
+!RUN: %flang_fc1 -emit-fir -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DEVICE-FLAG-ONLY
+!RUN: bbc -fopenmp -fopenmp-is-device -emit-fir -o - %s | FileCheck %s --check-prefix=BBC-DEVICE
+!RUN: bbc -fopenmp -emit-fir 

[PATCH] D145229: [analyzer] Improve the documentation of the alpha.security.taint.TaintPropagation checker

2023-03-03 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added inline comments.



Comment at: clang/docs/analyzer/checkers.rst:78-80
+The ``SuppressAddressSpaces`` option suppresses
 warnings for null dereferences of all pointers with address spaces. You can
 disable this behavior with the option

Why is this paragraph (and the one above it) wrapped inconsistently? If we are 
touching these docs, perhaps we could re-wrap them to e.g 80 characters / line.



Comment at: clang/docs/analyzer/checkers.rst:2385
 
   - network originating data
+  - files or standard input

This old word choice is awkward, consider replacing it with e.g. "data from the 
network".



Comment at: clang/docs/analyzer/checkers.rst:2388
   - environment variables
   - database originating data
 

Why not just "databases"?



Comment at: clang/docs/analyzer/checkers.rst:2404
+  }
+  strcat(cmd, filename);
+  system(cmd); // Warning: Untrusted data is passed to a system call

If the filename is too long (more than 1014 characters), this is a buffer 
overflow. I admit that having a secondary unrelated vulnerability makes the 
example more realistic :), but I think we should still avoid it. (This also 
appears in other variants of the example code, including the "No vulnerability 
anymore" one.)



Comment at: clang/docs/analyzer/checkers.rst:2426
+
+  if (access(filename,F_OK)){//sanitizing user input
+printf("File does not exist\n");

Nitpick: the comment formatting is inconsistent: for example, this is lowercase 
while most others start with an uppercase letter, or half of the comments have 
a space after the `//` while the others don't.



Comment at: clang/docs/analyzer/checkers.rst:2457-2461
+  if (access(filename,F_OK)){//sanitizing user input
+printf("File does not exist\n");
+return -1;
+  }
+  csa_sanitize(filename); // Indicating to CSA that filename variable is safe 
to be used after this point

Separating the actual sanitization and the function that's magically recognized 
by the taint checker doesn't seem to be a good design pattern. Here 
`csa_sanitize()` is just a synonym for the "silence this checker here" marker, 
which is //very// confusing, because if someone is not familiar with this 
locally introduced no-op function, they will think that it's performing actual 
sanitization! At the very least we should rename this magical no-op to 
`csa_mark_sanitized()` or something similar.

The root issue is that in this example we would like to use a verifier function 
(that determines whether the tainted data is safe) instead of a sanitizer 
function (that can convert //any// tainted data into safe data) and our taint 
handling engine is not prepared to handle conditional Filter effects like "this 
function removes taint from its first argument //if its return value is true//".

I think it would be much better to switch to a different example where the 
"natural" solution is more aligned with the limited toolbox provided by our 
taint framework (i.e. it's possible define a filter function that actually 
removes problematic parts of the untrusted input).



Comment at: clang/docs/analyzer/checkers.rst:2505
 
-There are built-in sources, propagations and sinks defined in code inside 
``GenericTaintChecker``.
-These operations are handled even if no external taint configuration is 
provided.
+There are built-in sources, propagations and sinks even if no external taint 
configuration is provided.
 

Perhaps explicitly mention that there are no built-in filters.



Comment at: clang/docs/analyzer/checkers.rst:2535
+
+* The taintedness property is not propagated through function calls which are 
unkown (or too complex) to the analyzer, unless there is a specific
+propagation rule built-in to the checker or given in the YAML configuration 
file. This causes potential true positive findings to be lost.

Spellcheck: "unknown"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145229

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


[PATCH] D143418: [libclang] Add API to override preamble storage path

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



Comment at: clang/include/clang-c/Index.h:329
+ * CXIndexOptions Opts = { sizeof(CXIndexOptions),
+ * clang_getDefaultGlobalOptions() };
+ * \endcode

vedgy wrote:
> aaron.ballman wrote:
> > vedgy wrote:
> > > vedgy wrote:
> > > > aaron.ballman wrote:
> > > > > vedgy wrote:
> > > > > > When I almost finished the requested changes, I remembered that the 
> > > > > > return value of `clang_getDefaultGlobalOptions()` depends on 
> > > > > > environment variables, and thus `0` is not necessarily the default. 
> > > > > > Adjusted the changes and updated this revision.
> > > > > > 
> > > > > > Does the extra requirement to non-zero initialize this second 
> > > > > > member sway your opinion on the usefulness of the helper function 
> > > > > > `inline CXIndexOptions clang_getDefaultIndexOptions()`? Note that 
> > > > > > there may be same (environment) or other important reasons why 
> > > > > > future new options couldn't be zeroes by default.
> > > > > Thinking out loud a bit... (potentially bad idea incoming)
> > > > > 
> > > > > What if we dropped `clang_getDefaultGlobalOptions()` and instead made 
> > > > > a change to `CXGlobalOptFlags`:
> > > > > ```
> > > > > typedef enum {
> > > > >   /**
> > > > >* Used to indicate that the default CXIndex options are used. By 
> > > > > default, no
> > > > >* global options will be used. However, environment variables may 
> > > > > change which
> > > > >* global options are in effect at runtime.
> > > > >*/
> > > > >   CXGlobalOpt_Default = 0x0,
> > > > > 
> > > > >   /**
> > > > >* Used to indicate that threads that libclang creates for indexing
> > > > >* purposes should use background priority.
> > > > >*
> > > > >* Affects #clang_indexSourceFile, #clang_indexTranslationUnit,
> > > > >* #clang_parseTranslationUnit, #clang_saveTranslationUnit.
> > > > >*/
> > > > >   CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
> > > > > 
> > > > >   /**
> > > > >* Used to indicate that threads that libclang creates for editing
> > > > >* purposes should use background priority.
> > > > >*
> > > > >* Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt,
> > > > >* #clang_annotateTokens
> > > > >*/
> > > > >   CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
> > > > > 
> > > > >   /**
> > > > >* Used to indicate that all threads that libclang creates should 
> > > > > use
> > > > >* background priority.
> > > > >*/
> > > > >   CXGlobalOpt_ThreadBackgroundPriorityForAll =
> > > > >   CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
> > > > >   CXGlobalOpt_ThreadBackgroundPriorityForEditing,
> > > > > 
> > > > >   /**
> > > > >* Used to indicate that no global options should be used, even
> > > > >* in the presence of environment variables.
> > > > >*/
> > > > >   CXGlobalOpt_None = 0x
> > > > > } CXGlobalOptFlags;
> > > > > ```
> > > > > so that when the user passes `0` they get the previous behavior.
> > > > > 
> > > > > `clang_CXIndex_setGlobalOptions()` would remain deprecated. 
> > > > > `clang_CXIndex_getGlobalOptions()` would be interesting though -- 
> > > > > would it return `CXGlobalOpt_None` or `CXGlobalOpt_Default` in the 
> > > > > event the index was created without any global options? Hmmm.
> > > > > 
> > > > > Err, actually, I suppose this won't work too well because then code 
> > > > > silently changes behavior if it does 
> > > > > `clang_CXIndex_setGlobalOptions(CXGlobalOpt_None);` because that 
> > > > > would change from "do what the environment says" to "ignore the 
> > > > > environment". But I have to wonder whether anyone actually *does* 
> > > > > that or not... my intuition is that folks would not call 
> > > > > `clang_CXIndex_setGlobalOptions()` at all unless they were setting an 
> > > > > option to a non-none value. We could rename `CXGlobalOpt_None` to 
> > > > > `CXGlobalOpt_Nothing` (or something along those lines) to force a 
> > > > > compilation error, but that's a bit of a nuclear option for what's 
> > > > > supposed to be a stable API.
> > > > > 
> > > > > So I'm on the fence, I guess. I'd still prefer for zero to give 
> > > > > sensible defaults and I don't think there's enough use of the global 
> > > > > options + environment variables to matter. But I also don't like 
> > > > > silently breaking code, so my idea above may be a nonstarter.
> > > > > 
> > > > > I suppose another possible idea is: deprecate the notion of global 
> > > > > options enum and setter/getter entirely, add two new fields to 
> > > > > `CXIndexOptions`:
> > > > > ```
> > > > > typedef enum {
> > > > >   CXChoice_Default = 0,
> > > > >   CXChoice_Enabled = 1,
> > > > >   CXChoice_Disabled = 2
> > > > > } CXChoice;
> > > > > 
> > > > > ...
> > > > > unsigned ThreadPriorityBackgroundForIndexing;
> > > > > unsigned ThreadPriorityBackgroundForEditing

[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach updated this revision to Diff 502138.
dmaclach marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144672

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/test/asan/TestCases/replaceable_new_delete.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp

Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
===
--- /dev/null
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
@@ -0,0 +1,35 @@
+// Ensure that operator new/delete are still replaceable using static-libsan.
+
+// FIXME: Weak symbols aren't supported on Windows, although some code in
+// compiler-rt already exists to solve this problem. We should probably define
+// the new/delete interceptors as "weak" using those workarounds as well.
+// UNSUPPORTED: target={{.*windows.*}}
+
+// darwin only supports `shared-libsan`.
+// UNSUPPORTED: darwin
+
+// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
+
+#include 
+#include 
+#include 
+
+void *operator new[](size_t size) {
+  fprintf(stderr, "replaced new\n");
+  return malloc(size);
+}
+
+void operator delete[](void *ptr) noexcept {
+  fprintf(stderr, "replaced delete\n");
+  return free(ptr);
+}
+
+int main(int argc, char **argv) {
+  // CHECK: replaced new
+  char *x = new char[5];
+  // CHECK: replaced delete
+  delete[] x;
+  // CHECK: ERROR: AddressSanitizer
+  *x = 13;
+  return 0;
+}
Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
===
--- compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
@@ -1,4 +1,4 @@
-// Ensure that operator new/delete are still replaceable.
+// Ensure that operator new/delete are still replaceable using shared-libsan.
 
 // FIXME: Weak symbols aren't supported on Windows, although some code in
 // compiler-rt already exists to solve this problem. We should probably define
@@ -6,7 +6,6 @@
 // UNSUPPORTED: target={{.*windows.*}}
 
 // RUN: %clangxx %s -o %t -fsanitize=address -shared-libsan && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
 
 #include 
 #include 
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -457,6 +457,18 @@
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-STATIC-DARWIN %s
 // CHECK-UBSAN-STATIC-DARWIN: {{.*}}error: static UndefinedBehaviorSanitizer runtime is not supported on darwin
 
+// RUN: %clang -fsanitize=address -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-STATIC-DARWIN %s
+// CHECK-ASAN-STATIC-DARWIN: {{.*}}error: static AddressSanitizer runtime is not supported on darwin
+
+// RUN: %clang -fsanitize=thread -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TSAN-STATIC-DARWIN %s
+// CHECK-TSAN-STATIC-DARWIN: {{.*}}error: static ThreadSanitizer runtime is not supported on darwin
+
 // RUN: %clang -fsanitize=address,undefined -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1426,24 +1426,42 @@
 
   const SanitizerArgs &Sanitize = getSanitizerArgs(Args);
 
-  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
-getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
-return;
+  if (!Sanitize.needsSharedRt()) {
+const char *sanitizer = nullptr;
+if (Sanitize.needsUbsanRt()) {
+  sanitizer = "UndefinedBehaviorSanitizer";
+} else if (Sanitize.needsAsanRt()) {
+  sanitizer = "AddressSanitizer";
+} else if (Sanitize.needsTsanRt()) {
+  sanitizer = "ThreadSanitizer";
+}
+if (sanitizer) {
+  getDriver().Diag(diag::err_drv_unsupported_static_sanitizer_darwin)
+  << sanitizer;
+  return;
+}
   }
 
   if (Sanitize.linkRuntimes()) {
-if (Sanitize.needsAsanRt())
+if (Sanitize.needsAsanRt()) {
+  assert(Sanitize.needsSharedRt() &&
+ "Static saniti

[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach added a comment.

Went with unsupported.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144672

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


[PATCH] D144864: [Flang][Driver][MLIR] Add -fopenmp-is-device to Flang and link to an omp.is_device attribute

2023-03-03 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 502139.
agozillon added a comment.

- [Flang][MLIR][Test] Add newline at end of test file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144864

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  clang/test/Driver/flang/flang-omp.f90
  flang/include/flang/Frontend/LangOptions.def
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Lower/OpenMP/omp-is-device.f90
  flang/tools/bbc/bbc.cpp
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Index: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
===
--- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1417,6 +1417,26 @@
   return success();
 }
 
+//===--===//
+// OpenMPDialect helper functions
+//===--===//
+
+// Set the omp.is_device attribute on the module with the specified boolean
+void OpenMPDialect::setIsDevice(Operation* module, bool isDevice) {
+  module->setAttr(
+  mlir::StringAttr::get(module->getContext(), llvm::Twine{"omp.is_device"}),
+  mlir::BoolAttr::get(module->getContext(), isDevice));
+}
+
+// Return the value of the omp.is_device attribute stored in the module if it
+// exists, otherwise return false by default
+bool OpenMPDialect::getIsDevice(Operation* module) {
+  if (Attribute isDevice = module->getAttr("omp.is_device"))
+if (isDevice.isa())
+  return isDevice.dyn_cast().getValue();
+  return false;
+}
+
 #define GET_ATTRDEF_CLASSES
 #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
 
Index: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
===
--- mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -28,6 +28,15 @@
   let cppNamespace = "::mlir::omp";
   let dependentDialects = ["::mlir::LLVM::LLVMDialect"];
   let useDefaultAttributePrinterParser = 1;
+
+  let extraClassDeclaration = [{
+// Set the omp.is_device attribute on the module with the specified boolean
+static void setIsDevice(Operation* module, bool isDevice);
+
+// Return the value of the omp.is_device attribute stored in the module if it
+// exists, otherwise return false by default
+static bool getIsDevice(Operation* module);
+  }];
 }
 
 // OmpCommon requires definition of OpenACC_Dialect.
Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -38,6 +38,7 @@
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/unparse-with-symbols.h"
 #include "flang/Version.inc"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/IR/AsmState.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/MLIRContext.h"
@@ -122,6 +123,11 @@
 llvm::cl::desc("enable openmp"),
 llvm::cl::init(false));
 
+static llvm::cl::opt
+enableOpenMPDevice("fopenmp-is-device",
+   llvm::cl::desc("enable openmp device compilation"),
+   llvm::cl::init(false));
+
 static llvm::cl::opt enableOpenACC("fopenacc",
  llvm::cl::desc("enable openacc"),
  llvm::cl::init(false));
@@ -237,6 +243,8 @@
   kindMap, loweringOptions, {});
   burnside.lower(parseTree, semanticsContext);
   mlir::ModuleOp mlirModule = burnside.getModule();
+  if (enableOpenMP)
+mlir::omp::OpenMPDialect::setIsDevice(mlirModule, enableOpenMPDevice);
   std::error_code ec;
   std::string outputName = outputFilename;
   if (!outputName.size())
Index: flang/test/Lower/OpenMP/omp-is-device.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/omp-is-device.f90
@@ -0,0 +1,19 @@
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DEVICE
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefix=HOST
+!RUN: %flang_fc1 -emit-fir -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DEVICE-FLAG-ONLY
+!RUN: bbc -fopenmp -fopenmp-is-device -emit-fir -o - %s | FileCheck %s --check-prefix=BBC-DEVICE
+!RUN: bbc -fopenmp -emit-fir -o - %s | FileCheck %s --check-prefix=BBC-HOST
+!RUN: bbc -fopenmp-is-device -emit-fir -o - %s | FileCheck %s --check-prefix=BBC-DEVICE-FLAG-ONLY
+
+!DEVICE: module attributes {{{.*}}, omp.is_device = true{{.*}}}
+!HOST: module attributes {{{.*}}, omp.is_device = false{

[clang] 4679d7a - [NFC][ARM][AArch64] Cleanup TargetParser includes

2023-03-03 Thread Archibald Elliott via cfe-commits

Author: Archibald Elliott
Date: 2023-03-03T16:24:55Z
New Revision: 4679d7a26a5f42f1128fac6fdf49488d13066c52

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

LOG: [NFC][ARM][AArch64] Cleanup TargetParser includes

llvm/TargetParser/TargetParser.h now only includes AMDGPU-specific
functionality, the ARM- and AArch64-specific functionality is in other
headers.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/lib/Driver/ToolChains/Arch/ARM.h
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/lib/Target/ARM/ARMAsmPrinter.cpp
llvm/lib/Target/ARM/ARMSubtarget.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 519da92b09417..0b2ee72f7868e 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -14,7 +14,6 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/Host.h"
-#include "llvm/TargetParser/TargetParser.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;

diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 0967ffe047579..e75f8a474410c 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -14,7 +14,6 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/TargetParser/ARMTargetParser.h"
 #include "llvm/TargetParser/Host.h"
-#include "llvm/TargetParser/TargetParser.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;

diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.h 
b/clang/lib/Driver/ToolChains/Arch/ARM.h
index ef56c8b065df7..18a358c55c1b4 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.h
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.h
@@ -13,7 +13,6 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Option/Option.h"
 #include "llvm/TargetParser/ARMTargetParser.h"
-#include "llvm/TargetParser/TargetParser.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 #include 

diff  --git a/llvm/lib/Target/AArch64/AArch64Subtarget.cpp 
b/llvm/lib/Target/AArch64/AArch64Subtarget.cpp
index 6241b145f9b50..843c3b78f8758 100644
--- a/llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ b/llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -25,7 +25,6 @@
 #include "llvm/CodeGen/MachineScheduler.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
-#include "llvm/TargetParser/TargetParser.h"
 
 using namespace llvm;
 

diff  --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp 
b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
index 8393fb1aa9aba..4f2833c1c4230 100644
--- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -50,7 +50,6 @@
 #include "llvm/Support/SMLoc.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
-#include "llvm/TargetParser/TargetParser.h"
 #include 
 #include 
 #include 

diff  --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp 
b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 7cd7ee7543a0e..5ed8f900fb88f 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -46,7 +46,6 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/TargetParser/TargetParser.h"
 using namespace llvm;
 
 #define DEBUG_TYPE "asm-printer"

diff  --git a/llvm/lib/Target/ARM/ARMSubtarget.cpp 
b/llvm/lib/Target/ARM/ARMSubtarget.cpp
index 9cc9056f408b7..53c03a6b28d7e 100644
--- a/llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ b/llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -36,7 +36,6 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/TargetParser/ARMTargetParser.h"
-#include "llvm/TargetParser/TargetParser.h"
 #include "llvm/TargetParser/Triple.h"
 
 using namespace llvm;

diff  --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp 
b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
index d694385098583..bf419511b 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
@@ -35,7 +35,6 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Ta

[PATCH] D143751: [clang][analyzer][NFC] Refactor code of StdLibraryFunctionsChecker.

2023-03-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 502143.
balazske added a comment.

changed comments, small variable rename


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143751

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

Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -65,47 +65,68 @@
   class Summary;
 
   /// Specify how much the analyzer engine should entrust modeling this function
-  /// to us. If he doesn't, he performs additional invalidations.
-  enum InvalidationKind { NoEvalCall, EvalCallAsPure };
+  /// to us.
+  enum InvalidationKind {
+/// No \c eval::Call for the function, it can be modeled elsewhere.
+/// This checker checks only pre and post conditions.
+NoEvalCall,
+/// The function is modeled completely in this checker.
+EvalCallAsPure
+  };
 
-  // The universal integral type to use in value range descriptions.
-  // Unsigned to make sure overflows are well-defined.
+  /// Given a range, should the argument stay inside or outside this range?
+  enum RangeKind { OutOfRange, WithinRange };
+
+  static RangeKind negateKind(RangeKind K) {
+switch (K) {
+case OutOfRange:
+  return WithinRange;
+case WithinRange:
+  return OutOfRange;
+}
+llvm_unreachable("Unknown range kind");
+  }
+
+  /// The universal integral type to use in value range descriptions.
+  /// Unsigned to make sure overflows are well-defined.
   typedef uint64_t RangeInt;
 
-  /// Normally, describes a single range constraint, eg. {{0, 1}, {3, 4}} is
-  /// a non-negative integer, which less than 5 and not equal to 2. For
-  /// `ComparesToArgument', holds information about how exactly to compare to
-  /// the argument.
+  /// Describes a single range constraint. Eg. {{0, 1}, {3, 4}} is
+  /// a non-negative integer, which less than 5 and not equal to 2.
   typedef std::vector> IntRangeVector;
 
   /// A reference to an argument or return value by its number.
   /// ArgNo in CallExpr and CallEvent is defined as Unsigned, but
   /// obviously uint32_t should be enough for all practical purposes.
   typedef uint32_t ArgNo;
+  /// Special argument number for specifying the return value.
   static const ArgNo Ret;
 
   using DescString = SmallString<96>;
+
   /// Returns the string representation of an argument index.
   /// E.g.: (1) -> '1st arg', (2) - > '2nd arg'
   static SmallString<8> getArgDesc(ArgNo);
   /// Append textual description of a numeric range [RMin,RMax] to the string
-  /// 'Out'.
+  /// \p Out.
   static void appendInsideRangeDesc(llvm::APSInt RMin, llvm::APSInt RMax,
 QualType ArgT, BasicValueFactory &BVF,
 DescString &Out);
   /// Append textual description of a numeric range out of [RMin,RMax] to the
-  /// string 'Out'.
+  /// string \p Out.
   static void appendOutOfRangeDesc(llvm::APSInt RMin, llvm::APSInt RMax,
QualType ArgT, BasicValueFactory &BVF,
DescString &Out);
 
   class ValueConstraint;
 
-  // Pointer to the ValueConstraint. We need a copyable, polymorphic and
-  // default initialize able type (vector needs that). A raw pointer was good,
-  // however, we cannot default initialize that. unique_ptr makes the Summary
-  // class non-copyable, therefore not an option. Releasing the copyability
-  // requirement would render the initialization of the Summary map infeasible.
+  /// Pointer to the ValueConstraint. We need a copyable, polymorphic and
+  /// default initializable type (vector needs that). A raw pointer was good,
+  /// however, we cannot default initialize that. unique_ptr makes the Summary
+  /// class non-copyable, therefore not an option. Releasing the copyability
+  /// requirement would render the initialization of the Summary map infeasible.
+  /// Mind that a pointer to a new value constraint is created when the negate
+  /// function is used.
   using ValueConstraintPtr = std::shared_ptr;
 
   /// Polymorphic base class that represents a constraint on a given argument
@@ -122,35 +143,12 @@
   public:
 ValueConstraint(ArgNo ArgN) : ArgN(ArgN) {}
 virtual ~ValueConstraint() {}
+
 /// Apply the effects of the constraint on the given program state. If null
 /// is returned then the constraint is not feasible.
 virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
   const Summary &Summary,
   CheckerContext &C) const = 0;
-virtual ValueConstraintPtr negate() const {
-  llvm_unreachable("Not implemented");
-};
-
-/// Check whether the co

[clang] 637ce0f - [C2x] Claim support for WG14 N2838

2023-03-03 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-03-03T11:57:21-05:00
New Revision: 637ce0f7139015735d7e50cf12ad312a382f6283

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

LOG: [C2x] Claim support for WG14 N2838

This paper clarifies that complete object types need to be smaller than
SIZE_MAX. We already conformed to that requirement, so this adds some
test coverage to prove it.

Added: 
clang/test/C/C2x/n2838.c

Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/test/C/C2x/n2838.c b/clang/test/C/C2x/n2838.c
new file mode 100644
index 0..f110fef9d0f41
--- /dev/null
+++ b/clang/test/C/C2x/n2838.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -std=c2x %s
+
+/* WG14 N2838: yes
+ * Types and sizes
+ */
+
+char buffer4[0x''''1wb]; /* expected-error {{array is too 
large (295147905179352825841 elements)}} */
+char buffer3[0x'''wb];   /* expected-error {{array is too 
large (18446744073709551615 elements)}} */
+char buffer2[0x7FFF'''wb];   /* expected-error {{array is too 
large (9223372036854775807 elements)}} */
+char buffer1[0x1FFF'''wb];   /* array is juust right */
+
+/* The largest object we can create is still smaller than SIZE_MAX. */
+static_assert(0x1FFF'''wb <= __SIZE_MAX__);

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index dcc02e8b05145..20eec37fce3de 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -972,7 +972,7 @@ C2x implementation status
 
   Types and sizes
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2838.htm";>N2838
-  Unknown
+  Yes
 
 
   Clarifying integer terms



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


[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

2023-03-03 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

ping


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

https://reviews.llvm.org/D142907

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


[PATCH] D145251: [clang] Treat function parameter scope as an immediate function context

2023-03-03 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This results in expressions that appear in default function argument not
being checked for being actual constant expressions.
This aligns clang's behavior with the standard and fixes one of the
examples from https://wg21.link/P1073R3.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145251

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/expr/expr.const/p6-2a.cpp


Index: clang/test/CXX/expr/expr.const/p6-2a.cpp
===
--- clang/test/CXX/expr/expr.const/p6-2a.cpp
+++ clang/test/CXX/expr/expr.const/p6-2a.cpp
@@ -43,14 +43,12 @@
 constexpr Temporary t = {3}; // expected-error {{must have constant 
destruction}} expected-note {{created here}} expected-note {{in call}}
 
 namespace P1073R3 {
-consteval int f() { return 42; } // expected-note 3 {{declared here}}
+consteval int f() { return 42; } // expected-note 2 {{declared here}}
 consteval auto g() { return f; }
-// FIXME: there should be no diagnostics associated with either h() or r.
-consteval int h(int (*p)() = g()) { return p(); } // expected-error {{call to 
consteval function 'P1073R3::g' is not a constant expression}} \
- expected-note {{declared 
here}} \
- expected-note {{pointer 
to a consteval declaration is not a constant expression}}
-constexpr int r = h();   // expected-note {{in the default initalizer of 'p'}}
+consteval int h(int (*p)() = g()) { return p(); }
+constexpr int r = h();
 constexpr auto e = g();  // expected-error {{call to consteval function 
'P1073R3::g' is not a constant expression}} \
 expected-error {{constexpr variable 'e' must be 
initialized by a constant expression}} \
 expected-note 2 {{pointer to a consteval 
declaration is not a constant expression}}
+static_assert(r == 42);
 } // namespace P1073R3
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5918,7 +5918,10 @@
"default argument expression has capturing blocks?");
   }
   EnterExpressionEvaluationContext EvalContext(
-  *this, ExpressionEvaluationContext::PotentiallyEvaluated, Param);
+  *this,
+  FD->isConsteval() ? ExpressionEvaluationContext::ImmediateFunctionContext
+: ExpressionEvaluationContext::PotentiallyEvaluated,
+  Param);
   ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
   SkipImmediateInvocations;
   MarkDeclarationsReferencedInExpr(Init, /*SkipLocalVariables*/ true);
@@ -6006,7 +6009,11 @@
 // If we are instantiating a template we won't have to
 // retransform immediate calls.
 EnterExpressionEvaluationContext EvalContext(
-*this, ExpressionEvaluationContext::PotentiallyEvaluated, Param);
+*this,
+FD->isConsteval()
+? ExpressionEvaluationContext::ImmediateFunctionContext
+: ExpressionEvaluationContext::PotentiallyEvaluated,
+Param);
 
 if (Param->hasUninstantiatedDefaultArg()) {
   if (InstantiateDefaultArgument(CallLoc, FD, Param))


Index: clang/test/CXX/expr/expr.const/p6-2a.cpp
===
--- clang/test/CXX/expr/expr.const/p6-2a.cpp
+++ clang/test/CXX/expr/expr.const/p6-2a.cpp
@@ -43,14 +43,12 @@
 constexpr Temporary t = {3}; // expected-error {{must have constant destruction}} expected-note {{created here}} expected-note {{in call}}
 
 namespace P1073R3 {
-consteval int f() { return 42; } // expected-note 3 {{declared here}}
+consteval int f() { return 42; } // expected-note 2 {{declared here}}
 consteval auto g() { return f; }
-// FIXME: there should be no diagnostics associated with either h() or r.
-consteval int h(int (*p)() = g()) { return p(); } // expected-error {{call to consteval function 'P1073R3::g' is not a constant expression}} \
- expected-note {{declared here}} \
- expected-note {{pointer to a consteval declaration is not a constant expression}}
-constexpr int r = h();   // expected-note {{in the default initalizer of 'p'}}
+consteval int h(int (*p)() = g()) { return p(); }
+constexpr int r = h();
 constexpr auto e = g();  // expected-error {{call to consteval function 'P1073R3::g' is not a constant expression}} \
 expected-error {{constexpr variable 'e' must be initialized by a constant expression}} \
 expected-note 2 {{pointer to a consteval declaration is not a constant expression}}
+static_assert(r == 42);
 } // namespace

[PATCH] D144864: [Flang][Driver][MLIR] Add -fopenmp-is-device to Flang and link to an omp.is_device attribute

2023-03-03 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

The new update adds the suggested new tests! Thank you very much @awarzynski 
for suggesting them that was a great help. Hopefully the new additions cover 
what you have requested, if not I am of course happy to change or add more 
tests as needed.




Comment at: clang/lib/Driver/ToolChains/Flang.cpp:121-125
+  if (IsOpenMPDevice) {
+// -fopenmp-is-device is passed along to tell the frontend that it is
+// generating code for a device, so that only the relevant declarations are
+// emitted.
+CmdArgs.push_back("-fopenmp-is-device");

awarzynski wrote:
> Can you add a test for this section?
I have added a new test file flang-omp.f90 which aims to test that the 
appropriate flags are generated when openmp related flags are used it currently 
checks for -fopenmp/fopenmp-is-device



Comment at: flang/test/Lower/OpenMP/omp-is-device.f90:1
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s 
--check-prefix=DEVICE
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefix=HOST

awarzynski wrote:
> What happens if `-fopenmp-is-device` is used without `-fopnemp`?
I think I now cover this in the test with the *-DEVICE-FLAG-ONLY tests, 
currently it is silently ignored and nothing is applied to the module.



Comment at: flang/tools/bbc/bbc.cpp:127
+static llvm::cl::opt
+enableOpenMPDevice("fopenmp-is-device",
+   llvm::cl::desc("enable openmp device compilation"),

awarzynski wrote:
> This option is not tested
I believe I now test this in the omp-is-device.f90 test!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144864

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


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Julian Lettner via Phabricator via cfe-commits
yln added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

usama54321 wrote:
> yln wrote:
> > zixuw wrote:
> > > dmaclach wrote:
> > > > yln wrote:
> > > > > This should work, right?
> > > > No.. darwin should fail with the `-static-libsan` flag. This is the 
> > > > test that was failing and caused the rollback.
> > > I think @yln is suggesting using `REQUIRES: asan-static-runtime` instead 
> > > of `XFAIL: darwin`. I wasn't aware of that conditional but yeah that 
> > > should be better if it works.
> > I meant using `// REQUIRES: asan-static-runtime ` instead of `XFAIL: 
> > darwin` since it seems that we already have a lit feature for it.
> I think UNSUPPORTED: darwin makes the most sense here. I don't think lit 
> understands that REQUIRES: asan-static-runtime should result in skipping the 
> test on Darwin as it does not know about this dependency.
> I don't think lit understands that REQUIRES: asan-static-runtime should 
> result in skipping the test on Darwin as it does not know about this 
> dependency.

Actually, this was exactly my point.  We have other tests already marked with 
`REQUIRES: asan-static-runtime` and we should double check our changes don't 
affect these as well.

If LIT doesn't model this dependency yet, then we should make sure it does!  
And this test can act as a good "canary in the coal mine".

Please use `REQUIRES: asan-static-runtime` and make sure we understand and deal 
with any fallout.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144672

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


[PATCH] D143751: [clang][analyzer][NFC] Refactor code of StdLibraryFunctionsChecker.

2023-03-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 502153.
balazske added a comment.

rebase, reformatted code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143751

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

Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -65,47 +65,68 @@
   class Summary;
 
   /// Specify how much the analyzer engine should entrust modeling this function
-  /// to us. If he doesn't, he performs additional invalidations.
-  enum InvalidationKind { NoEvalCall, EvalCallAsPure };
+  /// to us.
+  enum InvalidationKind {
+/// No \c eval::Call for the function, it can be modeled elsewhere.
+/// This checker checks only pre and post conditions.
+NoEvalCall,
+/// The function is modeled completely in this checker.
+EvalCallAsPure
+  };
 
-  // The universal integral type to use in value range descriptions.
-  // Unsigned to make sure overflows are well-defined.
+  /// Given a range, should the argument stay inside or outside this range?
+  enum RangeKind { OutOfRange, WithinRange };
+
+  static RangeKind negateKind(RangeKind K) {
+switch (K) {
+case OutOfRange:
+  return WithinRange;
+case WithinRange:
+  return OutOfRange;
+}
+llvm_unreachable("Unknown range kind");
+  }
+
+  /// The universal integral type to use in value range descriptions.
+  /// Unsigned to make sure overflows are well-defined.
   typedef uint64_t RangeInt;
 
-  /// Normally, describes a single range constraint, eg. {{0, 1}, {3, 4}} is
-  /// a non-negative integer, which less than 5 and not equal to 2. For
-  /// `ComparesToArgument', holds information about how exactly to compare to
-  /// the argument.
+  /// Describes a single range constraint. Eg. {{0, 1}, {3, 4}} is
+  /// a non-negative integer, which less than 5 and not equal to 2.
   typedef std::vector> IntRangeVector;
 
   /// A reference to an argument or return value by its number.
   /// ArgNo in CallExpr and CallEvent is defined as Unsigned, but
   /// obviously uint32_t should be enough for all practical purposes.
   typedef uint32_t ArgNo;
+  /// Special argument number for specifying the return value.
   static const ArgNo Ret;
 
   using DescString = SmallString<96>;
+
   /// Returns the string representation of an argument index.
   /// E.g.: (1) -> '1st arg', (2) - > '2nd arg'
   static SmallString<8> getArgDesc(ArgNo);
   /// Append textual description of a numeric range [RMin,RMax] to the string
-  /// 'Out'.
+  /// \p Out.
   static void appendInsideRangeDesc(llvm::APSInt RMin, llvm::APSInt RMax,
 QualType ArgT, BasicValueFactory &BVF,
 DescString &Out);
   /// Append textual description of a numeric range out of [RMin,RMax] to the
-  /// string 'Out'.
+  /// string \p Out.
   static void appendOutOfRangeDesc(llvm::APSInt RMin, llvm::APSInt RMax,
QualType ArgT, BasicValueFactory &BVF,
DescString &Out);
 
   class ValueConstraint;
 
-  // Pointer to the ValueConstraint. We need a copyable, polymorphic and
-  // default initialize able type (vector needs that). A raw pointer was good,
-  // however, we cannot default initialize that. unique_ptr makes the Summary
-  // class non-copyable, therefore not an option. Releasing the copyability
-  // requirement would render the initialization of the Summary map infeasible.
+  /// Pointer to the ValueConstraint. We need a copyable, polymorphic and
+  /// default initializable type (vector needs that). A raw pointer was good,
+  /// however, we cannot default initialize that. unique_ptr makes the Summary
+  /// class non-copyable, therefore not an option. Releasing the copyability
+  /// requirement would render the initialization of the Summary map infeasible.
+  /// Mind that a pointer to a new value constraint is created when the negate
+  /// function is used.
   using ValueConstraintPtr = std::shared_ptr;
 
   /// Polymorphic base class that represents a constraint on a given argument
@@ -122,35 +143,12 @@
   public:
 ValueConstraint(ArgNo ArgN) : ArgN(ArgN) {}
 virtual ~ValueConstraint() {}
+
 /// Apply the effects of the constraint on the given program state. If null
 /// is returned then the constraint is not feasible.
 virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
   const Summary &Summary,
   CheckerContext &C) const = 0;
-virtual ValueConstraintPtr negate() const {
-  llvm_unreachable("Not implemented");
-};
-
-/// Check whether the constraint is mal

[PATCH] D145093: Add map info for dereference pointer.

2023-03-03 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 502144.
jyu2 added a comment.

Thanks Alexey for the code review.  I removed loop by using last expression in 
the component for checking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145093

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_map_deref_array_codegen.cpp
  openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp

Index: openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
@@ -0,0 +1,33 @@
+// RUN: %libomptarget-compilexx-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+#include 
+#include 
+
+void foo(int **t1d) {
+  int ***t2d = &t1d;
+  int t3d = &t2d;
+  *t1d = (int *)malloc(3 * sizeof(int));
+  int j;
+
+  for (j = 0; j < 3; j++)
+(*t1d)[j] = 0;
+#pragma omp target map(tofrom : (*t1d)[0 : 3])
+  { (*t1d)[1] = 1; }
+  // CHECK: 1
+  printf("%d\n", (*t1d)[1]);
+#pragma omp target map(tofrom : (**t2d)[0 : 3])
+  { (**t2d)[1] = 2; }
+  // CHECK: 2
+  printf("%d\n", (**t2d)[1]);
+#pragma omp target map(tofrom : (***t3d)[0 : 3])
+  { (***t3d)[1] = 3; }
+  // CHECK: 3
+  printf("%d\n", (***t3d)[1]);
+}
+
+int main() {
+  int *data = 0;
+  foo(&data);
+}
Index: clang/test/OpenMP/target_map_deref_array_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_deref_array_codegen.cpp
@@ -0,0 +1,131 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+extern void *malloc (int __size) throw () __attribute__ ((__malloc__));
+
+void foo(int **t1d)
+{
+  *t1d = (int *) malloc(3 * sizeof(int));
+  for (int j=0; j < 3; j++)
+(*t1d)[j] = 1;
+  #pragma omp target map(to: (*t1d)[0:3])
+(*t1d)[2] = 2;
+}
+
+#endif
+
+// CHECK: @.offload_sizes = private unnamed_addr constant [2 x i64] [i64 8, i64 12]
+// CHECK: @.offload_maptypes = private unnamed_addr constant [2 x i64] [i64 33, i64 17]
+// CHECK-LABEL: define {{[^@]+}}@_Z3fooPPi
+// CHECK-SAME: (ptr noundef [[T1D:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[T1D_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[J:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:store ptr [[T1D]], ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noalias noundef ptr @_Z6malloci(i32 noundef signext 12) #[[ATTR3:[0-9]+]]
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:store ptr [[CALL]], ptr [[TMP0]], align 8
+// CHECK-NEXT:store i32 0, ptr [[J]], align 4
+// CHECK-NEXT:br label [[FOR_COND:%.*]]
+// CHECK:   for.cond:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[TMP1]], 3
+// CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
+// CHECK:   for.body:
+// CHECK-NEXT:[[TMP2:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[TMP2]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[IDXPROM:%.*]] = sext i32 [[TMP4]] to i64
+// CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 [[IDXPROM]]
+// CHECK-NEXT:store i32 1, ptr [[ARRAYIDX]], align 4
+// CHECK-NEXT:br label [[FOR_INC:%.*]]
+// CHECK:   for.inc:
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[INC:%.*]] = add nsw i32 [[TMP5]], 1
+// CHECK-NEXT:store i32 [[INC]], ptr [[J]], align 4
+// CHECK-NEXT:br label [[FOR_COND]], !llvm.loop [[LOOP4:![0-9]+]]
+// CHECK:   for.end:
+// CHECK-NEXT:[[TMP6:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[TMP7:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8

[PATCH] D145093: Add map info for dereference pointer.

2023-03-03 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 marked an inline comment as done.
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:7487-7497
+  auto TNext = Next;
+  bool IsVarDerefAssoWithArray = false;
+  if (UO && UO->getOpcode() == UO_Deref)
+for (; TNext != CE; TNext = std::next(TNext))
+  if (isa(TNext->getAssociatedExpression()) ||
+  isa(TNext->getAssociatedExpression()) ||
+  isa(TNext->getAssociatedExpression()) ||

ABataev wrote:
> jyu2 wrote:
> > ABataev wrote:
> > > jyu2 wrote:
> > > > ABataev wrote:
> > > > > Why need a loop here? Can you somehow merge analysis for (*p) 
> > > > > expression with the pointer subscript analysis?
> > > > What about if you have three dereference pointers like (***a)[0:3]  or 
> > > > four pointers...
> > > Why you can't iterate through the required components just like for the 
> > > array subscrit expression?
> > Because currently, for unarray operator the map info is skipped following 
> > the rule:
> > 
> > bool IsNonDerefPointer = IsPointer && !UO && !BO && !IsNonContiguous;
> > 
> > So I need to check if it is dereference to array some how to not skip it.
> 1. Same problem in Sema too.
> 2. Can you try to fix it to avoid those loops?
Thanks.  I removed loop.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145093

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


[PATCH] D145093: Add map info for dereference pointer.

2023-03-03 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:7489-7493
+  if (UO && UO->getOpcode() == UO_Deref)
+if (isa(Last->getAssociatedExpression()) ||
+isa(Last->getAssociatedExpression()) ||
+isa(Last->getAssociatedExpression()))
+  IsVarDerefAssoWithArray = true;

What if we have something like:
```
typedef int (T)[3];

T** p;
map(**p)
```
? Shall it work? I.e. mapping of the whole array by dereferening the pointer to 
the array.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145093

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


[PATCH] D144454: Add builtin for llvm set rounding

2023-03-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Okay, so if we're adding this builtin, and it's not just imitating a stdlib 
function, we should definitely document it as a language extension.  There's a 
section in the manual about controlling FP modes which is probably an 
appropriate place for this.

I assume we need to document that the builtin has undefined behavior if it 
receives a value outside of the standard-defined set.  (We can't guarantee that 
it's a no-op or else we'll never be able to extend the standard-defined set.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144454

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


[clang] 34d6a6e - Fix bots by adding a triple to the test

2023-03-03 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-03-03T12:26:52-05:00
New Revision: 34d6a6e23a6d8d78c86fad06bc219107ce6b5780

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

LOG: Fix bots by adding a triple to the test

Resolves the issue found by:
https://lab.llvm.org/buildbot/#/builders/245/builds/5384

Added: 


Modified: 
clang/test/C/C2x/n2838.c

Removed: 




diff  --git a/clang/test/C/C2x/n2838.c b/clang/test/C/C2x/n2838.c
index f110fef9d0f4..cd20ea59884b 100644
--- a/clang/test/C/C2x/n2838.c
+++ b/clang/test/C/C2x/n2838.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -std=c2x %s
+// RUN: %clang_cc1 -triple x86_64 -verify -std=c2x %s
 
 /* WG14 N2838: yes
  * Types and sizes



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


[clang] 7ac0551 - [HLSL] add max/min library functions

2023-03-03 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-03-03T09:31:50-08:00
New Revision: 7ac0551e77f4adab18f3ac6ae428d4c09f9b6c49

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

LOG: [HLSL] add max/min library functions

This change exposes the max and min library functions for HLSL, excluding long, 
and long long doubles.
The max / min functions are supported for all scalar, vector, and matrix types.
Long and long long double support is missing in this patch because those types
don't exist in HLSL.

The full documentation of the HLSL max / min functions are available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-max
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-min

Reviewed By: python3kgae

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

Added: 
clang/test/CodeGenHLSL/builtins/max.hlsl
clang/test/CodeGenHLSL/builtins/min.hlsl

Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 570552367215b..1a34e1626e5a6 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -308,5 +308,173 @@ double3 log10(double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
 double4 log10(double4);
 
+// max builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+half max(half, half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+half2 max(half2, half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+half3 max(half3, half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+half4 max(half4, half4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int16_t max(int16_t, int16_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int16_t2 max(int16_t2, int16_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int16_t3 max(int16_t3, int16_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int16_t4 max(int16_t4, int16_t4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint16_t max(uint16_t, uint16_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint16_t2 max(uint16_t2, uint16_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint16_t3 max(uint16_t3, uint16_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint16_t4 max(uint16_t4, uint16_t4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max))) int max(int,
+int);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int2 max(int2, int2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int3 max(int3, int3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int4 max(int4, int4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint max(uint, uint);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint2 max(uint2, uint2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint3 max(uint3, uint3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint4 max(uint4, uint4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int64_t max(int64_t, int64_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int64_t2 max(int64_t2, int64_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int64_t3 max(int64_t3, int64_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int64_t4 max(int64_t4, int64_t4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint64_t max(uint64_t, uint64_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint64_t2 max(uint64_t2, uint64_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint64_t3 max(uint64_t3, uint64_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint64_t4 max(uint64_t4, uint64_t4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max))) float
+max(float, float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+float2 max(float2, float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+float3 max(float3, float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+float4 max(float4, float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max))) double
+max(double, double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+double2 max(double2, double2);
+__attribute__((clang_builtin_a

[PATCH] D144309: [HLSL] add max/min library functions

2023-03-03 Thread Joshua Batista via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7ac0551e77f4: [HLSL] add max/min library functions (authored 
by bob80905).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144309

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/max.hlsl
  clang/test/CodeGenHLSL/builtins/min.hlsl

Index: clang/test/CodeGenHLSL/builtins/min.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/min.hlsl
@@ -0,0 +1,223 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+#ifdef __HLSL_ENABLE_16_BIT
+// CHECK: define noundef i16 @
+// CHECK: call i16 @llvm.smin.i16(
+// NO_HALF: define noundef i16 @"?test_min_short@@YAFFF@Z"(
+// NO_HALF: call i16 @llvm.smin.i16(
+int16_t test_min_short ( int16_t p0, int16_t p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <2 x i16> @
+// CHECK: call <2 x i16> @llvm.smin.v2i16(
+// NO_HALF: define noundef <2 x i16> @"?test_min_short2@@YAT?$__vector@F$01@__clang@@T12@0@Z"(
+// NO_HALF: call <2 x i16> @llvm.smin.v2i16(
+int16_t2 test_min_short2 ( int16_t2 p0, int16_t2 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <3 x i16> @
+// CHECK: call <3 x i16> @llvm.smin.v3i16
+// NO_HALF: define noundef <3 x i16> @"?test_min_short3@@YAT?$__vector@F$02@__clang@@T12@0@Z"(
+// NO_HALF: call <3 x i16> @llvm.smin.v3i16(
+int16_t3 test_min_short3 ( int16_t3 p0, int16_t3 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <4 x i16> @
+// CHECK: call <4 x i16> @llvm.smin.v4i16
+// NO_HALF: define noundef <4 x i16> @"?test_min_short4@@YAT?$__vector@F$03@__clang@@T12@0@Z"(
+// NO_HALF: call <4 x i16> @llvm.smin.v4i16(
+int16_t4 test_min_short4 ( int16_t4 p0, int16_t4 p1 ) {
+  return min ( p0, p1 );
+}
+
+
+// CHECK: define noundef i16 @
+// CHECK: call i16 @llvm.umin.i16(
+// NO_HALF: define noundef i16 @"?test_min_ushort@@YAGGG@Z"(
+// NO_HALF: call i16 @llvm.umin.i16(
+uint16_t test_min_ushort ( uint16_t p0, uint16_t p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <2 x i16> @
+// CHECK: call <2 x i16> @llvm.umin.v2i16
+// NO_HALF: define noundef <2 x i16> @"?test_min_ushort2@@YAT?$__vector@G$01@__clang@@T12@0@Z"(
+// NO_HALF: call <2 x i16> @llvm.umin.v2i16(
+uint16_t2 test_min_ushort2 ( uint16_t2 p0, uint16_t2 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <3 x i16> @
+// CHECK: call <3 x i16> @llvm.umin.v3i16
+// NO_HALF: define noundef <3 x i16> @"?test_min_ushort3@@YAT?$__vector@G$02@__clang@@T12@0@Z"(
+// NO_HALF: call <3 x i16> @llvm.umin.v3i16(
+uint16_t3 test_min_ushort3 ( uint16_t3 p0, uint16_t3 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <4 x i16> @
+// CHECK: call <4 x i16> @llvm.umin.v4i16
+// NO_HALF: define noundef <4 x i16> @"?test_min_ushort4@@YAT?$__vector@G$03@__clang@@T12@0@Z"(
+// NO_HALF: call <4 x i16> @llvm.umin.v4i16(
+uint16_t4 test_min_ushort4 ( uint16_t4 p0, uint16_t4 p1 ) {
+  return min ( p0, p1 );
+}
+#endif
+
+// CHECK: define noundef i32 @
+// CHECK: call i32 @llvm.smin.i32(
+int test_min_int ( int p0, int p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <2 x i32> @
+// CHECK: call <2 x i32> @llvm.smin.v2i32
+int2 test_min_int2 ( int2 p0, int2 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <3 x i32> @
+// CHECK: call <3 x i32> @llvm.smin.v3i32
+int3 test_min_int3 ( int3 p0, int3 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <4 x i32> @
+// CHECK: call <4 x i32> @llvm.smin.v4i32
+int4 test_min_int4 ( int4 p0, int4 p1) {
+  return min ( p0, p1 );
+}
+
+// CHECK: define noundef i32 @
+// CHECK: call i32 @llvm.umin.i32(
+int test_min_uint ( uint p0, uint p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <2 x i32> @
+// CHECK: call <2 x i32> @llvm.umin.v2i32
+uint2 test_min_uint2 ( uint2 p0, uint2 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <3 x i32> @
+// CHECK: call <3 x i32> @llvm.umin.v3i32
+uint3 test_min_uint3 ( uint3 p0, uint3 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <4 x i32> @
+// CHECK: call <4 x i32> @llvm.umin.v4i32
+uint4 test_min_uint4 ( uint4 p0, uint4 p1) {
+  return min ( p0, p1 );
+}
+
+// CHECK: define noundef i64 @
+// CHECK: call i64 @llvm.smin.i64(
+int64_t test_min_long ( int64_t p0, int64_t p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <2 x i64> @
+// CHECK: call <2 x i64> @llvm.smin.v2i64
+int64_t2 test_min_long2 ( int64_t2 p0, int64_t2 p1 ) {
+  re

[PATCH] D144864: [Flang][Driver][MLIR] Add -fopenmp-is-device to Flang and link to an omp.is_device attribute

2023-03-03 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski accepted this revision.
awarzynski added a comment.
This revision is now accepted and ready to land.

> Thank you very much @awarzynski for suggesting them that was a great help.

I'm happy that I could help :) The driver logic LGTM, but please wait for 
either @jdoerfert and/or @kiranchandramohan to also approve. Thanks for 
contributing!




Comment at: clang/test/Driver/flang/flang-omp.f90:1
+! Check that flang -fc1 is invoked when in --driver-mode=flang 
+! and the relevant openmp and openmp offload flags are utilised

This test looks correct to me, but please note that:

```
! Check that flang -fc1 is invoked when in --driver-mode=flang 
```

yet (`%clang` instead of `%flang`)

```
! RUN: %clang --driver-mode=flang -### -fopenmp %s 2>&1 | FileCheck 
--check-prefixes=CHECK-OPENMP %s
```

I'm not really sure whether we should be testing Flang-specific logic in Clang. 
Having said that, Flang does use `clangDriver` to implement its driver :) 

You could consider using 
https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/frontend-forwarding.f90
 instead (or add an OpenMP specific file there).

Not a blocker.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144864

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


[PATCH] D142800: [Clang][Diagnostic] Add `-Wcomparison-op-parentheses` to warn on chained comparisons

2023-03-03 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 502166.
hazohelet added a comment.

Update the differential

- Revise warning messages based on ideas from @aaron.ballman.
- Introduce a new warning flag `-Wchaining-comparisons` that is enabled by 
default, to warn about chaining relationals or equal operators.
- Adjust existing test files to conform with the new warning settings.


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

https://reviews.llvm.org/D142800

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/cxx-uninitialized-object.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/bool-compare.c
  clang/test/Sema/chaining-comparisons.c
  clang/test/Sema/comparison-op-parentheses.c
  clang/test/SemaCXX/bool-compare.cpp
  clang/test/SemaCXX/cxx2a-adl-only-template-id.cpp
  clang/test/SemaTemplate/dependent-template-recover.cpp
  clang/test/SemaTemplate/typo-dependent-name.cpp
  clang/test/SemaTemplate/typo-template-name.cpp
  libcxx/test/support/test_comparisons.h

Index: libcxx/test/support/test_comparisons.h
===
--- libcxx/test/support/test_comparisons.h
+++ libcxx/test/support/test_comparisons.h
@@ -164,7 +164,7 @@
 bool less= order == Order::less;
 bool greater = order == Order::greater;
 
-return (t1 <=> t2 == order) && testComparisonsComplete(t1, t2, equal, less, greater);
+return ((t1 <=> t2) == order) && testComparisonsComplete(t1, t2, equal, less, greater);
 }
 
 template 
Index: clang/test/SemaTemplate/typo-template-name.cpp
===
--- clang/test/SemaTemplate/typo-template-name.cpp
+++ clang/test/SemaTemplate/typo-template-name.cpp
@@ -37,6 +37,8 @@
 // These are valid expressions.
 foo(0);
+  // expected-warning@-1 {{boolean value derived from '<' is compared as the operand of '>'; did you mean 'foo < int() && int() > (0)'?}}
+  // expected-note@-2 {{split the comparison into two}}
 foo(false);
 fooinner < other > ::z;
+  // expected-warning@-1 {{boolean value derived from '<' is compared as the operand of '>'; did you mean 'this->inner < other && other > ::z'?}}
+  // expected-note@-2 {{split the comparison into two}}
   }
 };
 
Index: clang/test/SemaTemplate/dependent-template-recover.cpp
===
--- clang/test/SemaTemplate/dependent-template-recover.cpp
+++ clang/test/SemaTemplate/dependent-template-recover.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-chaining-comparisons %s
 template
 struct X {
   void f(T* t) {
Index: clang/test/SemaCXX/cxx2a-adl-only-template-id.cpp
===
--- clang/test/SemaCXX/cxx2a-adl-only-template-id.cpp
+++ clang/test/SemaCXX/cxx2a-adl-only-template-id.cpp
@@ -28,6 +28,8 @@
   f<0>(q);
   int f;
   f<0>(q); // expected-error {{invalid operands to binary expression}}
+  // expected-warning@-1 {{boolean value derived from '<' is compared as the operand of '>'; did you mean 'f < 0 && 0 > (q)'?}}
+  // expected-note@-2 {{split the comparison into two}}
 }
 
 void disambig() {
Index: clang/test/SemaCXX/bool-compare.cpp
===
--- clang/test/SemaCXX/bool-compare.cpp
+++ clang/test/SemaCXX/bool-compare.cpp
@@ -98,7 +98,9 @@
   if ((ayy' is compared as the operand of '<'; did you mean 'a > y && y < z'?}}
+  // expected-note@-2 {{split the comparison into two}}
   if ((a z)  {} // no warning
   if((a(zy)  {} // no warning
+  if (zy)  {}
+  // expected-warning@-1 {{boolean value derived from '<' is compared as the operand of '>'; did you mean 'z < a && a > y'?}}
+  // expected-note@-2 {{split the comparison into two}}
   if (z > (a(a&1 | FileCheck %s
+
+// off-no-diagnostics
+
+void comparison_op_parentheses(int a, int b, int c) {
+  (void)(a ==
+ b > c);
+  // expected-warning@-1 {{boolean value derived from '>' is compared as the operand of '=='}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:14-[[@LINE-3]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:19-[[@LINE-4]]:19}:")"
+
+  (void)(a !=b == c);
+  // expected-warning@-1 {{boolean value derived from '!=' is compared as the operand of '=='}}
+  // expected-note@-2 {{place parentheses around the '!=' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:15-[[@LINE-4]]:15}:")"
+
+  (void)(a !=
+ b < c);
+  // expected-warning@-1 {{boolean value derived from '<' is compared as the operand of '!='}}
+  // expected-note@-2 {{place parentheses around the '<' e

[PATCH] D142800: [Clang][Diagnostic] Add `-Wcomparison-op-parentheses` to warn on chained comparisons

2023-03-03 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

In D142800#4165090 , @aaron.ballman 
wrote:

> In D142800#4104241 , @hazohelet 
> wrote:
>
>>> Also, why are these diagnostics off by default? Do we have some idea as to 
>>> the false positive rate?
>>
>> As for the false positive rate, I have checked for instances of this warning 
>> in the codebases for 'oneapi-src/oneTBB', 'rui314/mold', and 
>> 'microsoft/lightgbm', but did not find any new cases.
>
> Thank you for doing the extra testing! Sorry for the delayed response, this 
> review fell off my radar for a bit.
>
>> I also ran a test on  'tensorflow/tensorflow' using gcc '-Wparentheses' and 
>> found six lines of code that trigger the new diagnostic. They all relate to 
>> checking whether `x` and `y` have the same sign using `x > 0 == y > 0` and 
>> alike. I tried to build with tensorflow using clang, but I stumbled upon 
>> some errors (for my poor knowledge of bazel configuration), so here I am 
>> using gcc.
>
> Thank you for reporting this, that's really good information.
>
>> I set the diagnostic disabled by default for compatibility with gcc. 
>> Considering the test against tensorflow above, it would be too noisy if we 
>> turned on the suggest-parentheses diagnostic by default (From my best guess, 
>> it would generate at least 18 new instances of warning on the tensorflow 
>> build for the six lines).
>> However, in my opinion, it is reasonable enough to have the diagnostic on 
>> chained relational operators enabled by default. The following is an excerpt 
>> from the 'Existing Code in C++' section of the proposal document of the 
>> introduction of chaining comparison for C++17.
>>
>>> Overall, what we found was:
>>>
>>> - Zero instances of chained arithmetic comparisons that are correct today. 
>>> That is, intentionally using the current standard behavior.
>>> - Four instances of currently-erroneous arithmetic chaining, of the 
>>> assert(0 <= ratio <= 1.0); variety. These are bugs that compile today but 
>>> don’t do what the programmer intended, but with this proposal would change 
>>> in meaning to become correct.
>>> - Many instances of using successive comparison operators in DSLs that 
>>> overloaded these operators to give meaning unrelated to comparisons.
>>
>> Note that the 'chaining comparisons' in the document are
>>
>>> - all `==`, such as `a == b == c == d`;
>>> - all `{<, <=}`, such as `a < b <= c < d`; and
>>> - all `{>, >=}` (e.g., `a >= b > c > d`).
>>
>> URL: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0893r0.html
>>
>> Although this paper is five years old now, I think we can conclude chaining 
>> relational operators are bug-prone and should be diagnosed by default.
>> Also, reading the document above, I think it would be reasonable to suggest 
>> adding '&&' in `a == b == c` case, too.
>
> I tend to agree -- I was searching around sourcegraph 
> (https://sourcegraph.com/search?q=context:global+lang:C+lang:C%2B%2B+%5BA-Za-z0-9_%5D%2B%5Cs*%28%3D%3D%7C%21%3D%7C%3C%3D%7C%3E%3D%29%5Cs*%5BA-Za-z0-9_%5D%2B%5Cs*%28%3D%3D%7C%21%3D%7C%3C%3D%7C%3E%3D%29&patternType=regexp&sm=1&groupBy=repo)
>  and I can't find a whole lot of evidence for chained operators outside of 
> comments.

Thanks for the review and the sourcegraph search!
I added a new warning flag `-Wchaining-comparisons` that is enabled by default. 
I added this flag to `-Wparentheses` for gcc compatibility.


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

https://reviews.llvm.org/D142800

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


[clang] c65fb80 - [Fuchsia] Add other necessary components to LLDB install.

2023-03-03 Thread Daniel Thornburgh via cfe-commits

Author: Daniel Thornburgh
Date: 2023-03-03T10:07:08-08:00
New Revision: c65fb80b73aa5087a4bba79e61d96b4d652e1b54

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

LOG: [Fuchsia] Add other necessary components to LLDB install.

Reviewed By: phosek

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 54a64a84f231b..016fa9eb5f9d2 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -343,8 +343,8 @@ set(_FUCHSIA_DISTRIBUTION_COMPONENTS
 
 set(FUCHSIA_ENABLE_LLDB OFF CACHE BOOL "Enable LLDB")
 if(FUCHSIA_ENABLE_LLDB)
-  list(APPEND _FUCHSIA_ENABLE_PROJECTS "lldb")
-  list(APPEND _FUCHSIA_DISTRIBUTION_COMPONENTS "lldb")
+  list(APPEND _FUCHSIA_ENABLE_PROJECTS lldb)
+  list(APPEND _FUCHSIA_DISTRIBUTION_COMPONENTS lldb liblldb lldb-server 
lldb-argdumper)
 endif()
 
 set(LLVM_ENABLE_PROJECTS ${_FUCHSIA_ENABLE_PROJECTS} CACHE STRING "")



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


[PATCH] D145187: [Fuchsia] Add other necessary components to LLDB install.

2023-03-03 Thread Daniel Thornburgh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc65fb80b73aa: [Fuchsia] Add other necessary components to 
LLDB install. (authored by mysterymath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145187

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -343,8 +343,8 @@
 
 set(FUCHSIA_ENABLE_LLDB OFF CACHE BOOL "Enable LLDB")
 if(FUCHSIA_ENABLE_LLDB)
-  list(APPEND _FUCHSIA_ENABLE_PROJECTS "lldb")
-  list(APPEND _FUCHSIA_DISTRIBUTION_COMPONENTS "lldb")
+  list(APPEND _FUCHSIA_ENABLE_PROJECTS lldb)
+  list(APPEND _FUCHSIA_DISTRIBUTION_COMPONENTS lldb liblldb lldb-server 
lldb-argdumper)
 endif()
 
 set(LLVM_ENABLE_PROJECTS ${_FUCHSIA_ENABLE_PROJECTS} CACHE STRING "")


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -343,8 +343,8 @@
 
 set(FUCHSIA_ENABLE_LLDB OFF CACHE BOOL "Enable LLDB")
 if(FUCHSIA_ENABLE_LLDB)
-  list(APPEND _FUCHSIA_ENABLE_PROJECTS "lldb")
-  list(APPEND _FUCHSIA_DISTRIBUTION_COMPONENTS "lldb")
+  list(APPEND _FUCHSIA_ENABLE_PROJECTS lldb)
+  list(APPEND _FUCHSIA_DISTRIBUTION_COMPONENTS lldb liblldb lldb-server lldb-argdumper)
 endif()
 
 set(LLVM_ENABLE_PROJECTS ${_FUCHSIA_ENABLE_PROJECTS} CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-03 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 502175.
TIFitis marked 7 inline comments as done.
TIFitis added a comment.

Addressed reviewer comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,205 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_loop(%1 : !llvm.ptr>) {
+  %2 = llvm.mlir.constant(1 : i64) : i64
+  %3 = llvm.alloca %2 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_data_loopEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%4 = llvm.mlir.constant(1 : i32) : i32
+%5 = llvm.sext %4 : i32 to i64
+%6 = llvm.mlir.constant(1024 : i32) : i32
+%7 = llvm.sext %6 : i32 to i64
+%8 = llvm.mlir.constant(1 : index) : i64
+%9 = llvm.trunc %5 : i64 to i32
+%10 = llvm.sub %7, %5  : i64
+%11 = llvm.add %10, %8  : i64
+llvm.br ^bb1(%5, %9, %11 : i64, i32, i64)
+  ^bb1(%12: i64, %13: i32, %14: i64):  // 2 preds: ^bb0, ^bb2
+%15 = llvm.mlir.constant(0 : index) : i64
+%16 = llvm.icmp "sgt" %14, %15 : i64
+llvm.cond_br %16, ^bb2, ^bb3
+  ^bb2:  // pred: ^bb1
+llvm.store %13, %3 : !llvm.ptr
+%17 = llvm.load %3 : !llvm.ptr
+%18 = llvm.load %3 : !llvm.ptr
+%19 = llvm.sext %18 : i32 to i64
+%20 = llvm.m

[PATCH] D143128: [-Wunsafe-buffer-usage] Fix-Its transforming `&DRE[any]` to `(DRE.data() + any)`

2023-03-03 Thread Jan Korous via Phabricator via cfe-commits
jkorous added a comment.

This is an interesting topic. In the abstract I see the question as should the 
Fix-Its prioritize how the code will fit the desired end state (presumably 
modern idiomatic C++) or carefully respect the state of the code as is now.

The only thing I feel pretty strongly about is that no matter what philosophy 
we decide to use here we should apply it consistently to all our Fix-Its (which 
might or might not already be the case).

And FWIW I can also imagine at some point in the future we might either have 
two dialects of the Fix-Its or that a separate modernizer tool (completely 
independent of Safe Buffers) could suggest transformations like:
"Would you like to change `&DRE.data()[any]` to `(DRE.data() + any)`?"


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

https://reviews.llvm.org/D143128

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


[clang] 3ac8d32 - [clang][deps] Fix test failing on AIX

2023-03-03 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-03-03T10:22:39-08:00
New Revision: 3ac8d322100bc72aaacb67f13eb21d9b644f9930

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

LOG: [clang][deps] Fix test failing on AIX

Introduced in 86405450, caused by AIX defaulting to `-fno-integrated-as`.

Added: 


Modified: 
clang/test/ClangScanDeps/modules-full-output-tu-order.c

Removed: 




diff  --git a/clang/test/ClangScanDeps/modules-full-output-tu-order.c 
b/clang/test/ClangScanDeps/modules-full-output-tu-order.c
index dd5002809daa9..eb96d2e99c622 100644
--- a/clang/test/ClangScanDeps/modules-full-output-tu-order.c
+++ b/clang/test/ClangScanDeps/modules-full-output-tu-order.c
@@ -8,12 +8,12 @@
   {
 "directory": "DIR",
 "file": "DIR/tu.c",
-"command": "clang -fmodules -fmodules-cache-path=DIR/cache -c DIR/tu.c -o 
DIR/tu1.o"
+"command": "clang -fmodules -fmodules-cache-path=DIR/cache -c DIR/tu.c 
-DONE -o DIR/tu1.o"
   },
   {
 "directory": "DIR",
 "file": "DIR/tu.c",
-"command": "clang -fmodules -fmodules-cache-path=DIR/cache -c DIR/tu.c -o 
DIR/tu2.o"
+"command": "clang -fmodules -fmodules-cache-path=DIR/cache -c DIR/tu.c 
-DTWO -o DIR/tu2.o"
   }
 ]
 
@@ -32,8 +32,8 @@
 // CHECK-NEXT:   "clang-context-hash": "{{.*}}",
 // CHECK-NEXT:   "clang-module-deps": [],
 // CHECK-NEXT:   "command-line": [
-// CHECK:  "-o",
-// CHECK-NEXT: "[[PREFIX]]/tu1.o",
+// CHECK:  "-D"
+// CHECK-NEXT: "ONE"
 // CHECK:],
 // CHECK-NEXT:   "executable": "clang",
 // CHECK-NEXT:   "file-deps": [
@@ -49,8 +49,8 @@
 // CHECK-NEXT:   "clang-context-hash": "{{.*}}",
 // CHECK-NEXT:   "clang-module-deps": [],
 // CHECK-NEXT:   "command-line": [
-// CHECK:  "-o",
-// CHECK-NEXT: "[[PREFIX]]/tu2.o",
+// CHECK:  "-D"
+// CHECK-NEXT: "TWO"
 // CHECK:],
 // CHECK-NEXT:   "executable": "clang",
 // CHECK-NEXT:   "file-deps": [



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


[PATCH] D145098: [clang][deps] Preserve input ordering in the full output

2023-03-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D145098#4167163 , @Jake-Egan wrote:

> Hi, this new test fails on AIX, could you take a look please?
> https://lab.llvm.org/buildbot/#/builders/214/builds/6148/steps/6/logs/FAIL__Clang__modules-full-output-tu-order_c

`-fno-integrated-as` strikes again. Thanks for reporting this, should be fixed 
in 3ac8d32 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145098

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


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-03 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4052-4060
+  // LLVM utilities like blocks with terminators.
+  auto *UI = Builder.CreateUnreachable();
+  Instruction *ThenTI = UI, *ElseTI = nullptr;
+  if (IfCond) {
+SplitBlockAndInsertIfThenElse(IfCond, UI, &ThenTI, &ElseTI);
+ThenTI->getParent()->setName("omp_if.then");
+ElseTI->getParent()->setName("omp_if.else");

kiranchandramohan wrote:
> There is some recent recommendation to not insert artificial instructions and 
> remove them. The preferred approach is to use `splitBB` function(s) inside 
> the OpenMPIRBuilder. This function works on blocks without terminators. You 
> can consult the `IfCondition` code in `createParallel`.
Thanks a lot for taking the time to review this lengthy patch.

This one seems a bit tricky to do. At first glance `createParallel` seems to be 
doing something different where its calling different runtime functions based 
on the `IfCondition` instead of much in the way of Control Flow changes.

The `unreachable` inst helps out a lot here as it makes it really easy to keep 
trace of the resume point for adding instructions after the `BodyGen` codes are 
generated.

I am still looking into finding a way to do this elegantly without having to 
use the `unreachable` instruction, but would it be a major blocker if we had to 
keep it?

I have addressed all the other changes you requested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142914

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


[PATCH] D145178: [clang][NFC] reformats the SARIF diagnostic test so it's human readable

2023-03-03 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D145178#4167103 , @aaron.ballman 
wrote:

> LGTM, this is incremental progress. Hopefully we won't be adding too many 
> more RUN lines to this file though (sticking too many tests into one file is 
> also tech debt).

Thanks! 100% of the RUN lines I intend to add are bug regressions, but there 
will be more //RUN// lines in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145178

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


[PATCH] D143128: [-Wunsafe-buffer-usage] Fix-Its transforming `&DRE[any]` to `(DRE.data() + any)`

2023-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D143128#4167626 , @jkorous wrote:

> This is an interesting topic. In the abstract I see the question as: "Should 
> the Fix-Its prioritize how the code will fit the desired end state 
> (presumably modern idiomatic C++) or carefully respect the state of the code 
> as is now?"
>
> The only thing I feel pretty strongly about is that no matter what philosophy 
> we decide to use here we should apply it consistently to all our Fix-Its 
> (which might or might not already be the case).
>
> And FWIW I can also imagine at some point in the future we might either have 
> two dialects of the Fix-Its or that a separate modernizer tool (completely 
> independent of Safe Buffers) could suggest transformations like:
> "Would you like to change `&DRE.data()[any]` to `(DRE.data() + any)`?"

Fantastic topic! :)  In our experience at Google, we've generally followed the 
philosophy of leaving the code at least as good as it was before we touched it. 
So, if the idiom is archaic, but we're just adjusting it, that's fine (as in 
this example), but our tools shouldn't generate non-idiomatic (or anti-idiomic) 
code.  We've also often taken the path of "leave cleanups to a separate pass", 
especially when we already have say, a clang tidy check, that does that kind of 
clean up running regularly.  But, this one is more a judgment call. I'd 
probably lean towards "make the code better once you're at it", but certainly 
see the conservative argument.


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

https://reviews.llvm.org/D143128

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


[PATCH] D144864: [Flang][Driver][MLIR] Add -fopenmp-is-device to Flang and link to an omp.is_device attribute

2023-03-03 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

Thank you very much @awarzynski I will wait for further approval!




Comment at: clang/test/Driver/flang/flang-omp.f90:1
+! Check that flang -fc1 is invoked when in --driver-mode=flang 
+! and the relevant openmp and openmp offload flags are utilised

awarzynski wrote:
> This test looks correct to me, but please note that:
> 
> ```
> ! Check that flang -fc1 is invoked when in --driver-mode=flang 
> ```
> 
> yet (`%clang` instead of `%flang`)
> 
> ```
> ! RUN: %clang --driver-mode=flang -### -fopenmp %s 2>&1 | FileCheck 
> --check-prefixes=CHECK-OPENMP %s
> ```
> 
> I'm not really sure whether we should be testing Flang-specific logic in 
> Clang. Having said that, Flang does use `clangDriver` to implement its driver 
> :) 
> 
> You could consider using 
> https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/frontend-forwarding.f90
>  instead (or add an OpenMP specific file there).
> 
> Not a blocker.
Yes, I wasn't so sure either as it felt a little weird to test Flang components 
inside of Clang, but as you said it is a Clang toolchain (that this test is 
checking) and borrows from the clangDriver! 

I borrowed this test from other similar tests in the same folder that test 
other flang specific driver logic in a similar manner, but I am more than happy 
to add an additional flang specific driver test as you mention! 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144864

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


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

yln wrote:
> usama54321 wrote:
> > yln wrote:
> > > zixuw wrote:
> > > > dmaclach wrote:
> > > > > yln wrote:
> > > > > > This should work, right?
> > > > > No.. darwin should fail with the `-static-libsan` flag. This is the 
> > > > > test that was failing and caused the rollback.
> > > > I think @yln is suggesting using `REQUIRES: asan-static-runtime` 
> > > > instead of `XFAIL: darwin`. I wasn't aware of that conditional but yeah 
> > > > that should be better if it works.
> > > I meant using `// REQUIRES: asan-static-runtime ` instead of `XFAIL: 
> > > darwin` since it seems that we already have a lit feature for it.
> > I think UNSUPPORTED: darwin makes the most sense here. I don't think lit 
> > understands that REQUIRES: asan-static-runtime should result in skipping 
> > the test on Darwin as it does not know about this dependency.
> > I don't think lit understands that REQUIRES: asan-static-runtime should 
> > result in skipping the test on Darwin as it does not know about this 
> > dependency.
> 
> Actually, this was exactly my point.  We have other tests already marked with 
> `REQUIRES: asan-static-runtime` and we should double check our changes don't 
> affect these as well.
> 
> If LIT doesn't model this dependency yet, then we should make sure it does!  
> And this test can act as a good "canary in the coal mine".
> 
> Please use `REQUIRES: asan-static-runtime` and make sure we understand and 
> deal with any fallout.
Sorry for my earlier comment. @yln is correct, and we should use REQUIRES: 
asan-static-runtime. I double checked, and this already works as expected on 
darwin, i.e. these tests are unsupported on darwin. So you should not need to 
do anything apart from adding the REQUIRES in the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144672

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


[PATCH] D142328: [clang][Interp] Fix compound assign operator types

2023-03-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

All the interpreter work is experimental so it doesn't really need to be in the 
release branch. This should all be fine, thanks for asking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142328

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


[PATCH] D145256: [clang/Diagnostic] Use `optional` to disambiguate between a `StoredDiagMessage` that is not set vs set as empty string

2023-03-03 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

"But when would you have a completely empty diagnostic message", you ask dear 
reader?
That is when there is an empty "#warning" in code.

rdar://106155415


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145256

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/lib/Basic/Diagnostic.cpp
  clang/unittests/Basic/DiagnosticTest.cpp


Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticError.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -128,4 +129,27 @@
   EXPECT_EQ(*Value, std::make_pair(20, 1));
   EXPECT_EQ(Value->first, 20);
 }
+
+TEST(DiagnosticTest, storedDiagEmptyWarning) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
+  new IgnoringDiagConsumer());
+
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+SmallVector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic &Info) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+
+  CaptureDiagnosticConsumer CaptureConsumer;
+  Diags.setClient(&CaptureConsumer, /*ShouldOwnClient=*/false);
+  Diags.Report(diag::pp_hash_warning) << "";
+  ASSERT_TRUE(CaptureConsumer.StoredDiags.size() == 1);
+
+  // Make sure an empty warning can round-trip with \c StoredDiagnostic.
+  Diags.Report(CaptureConsumer.StoredDiags.front());
+}
 }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -793,8 +793,8 @@
 /// array.
 void Diagnostic::
 FormatDiagnostic(SmallVectorImpl &OutStr) const {
-  if (!StoredDiagMessage.empty()) {
-OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+  if (StoredDiagMessage.has_value()) {
+OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
 return;
   }
 
Index: clang/include/clang/Basic/Diagnostic.h
===
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -1565,7 +1565,7 @@
 /// currently in-flight diagnostic.
 class Diagnostic {
   const DiagnosticsEngine *DiagObj;
-  StringRef StoredDiagMessage;
+  std::optional StoredDiagMessage;
 
 public:
   explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}


Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticError.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -128,4 +129,27 @@
   EXPECT_EQ(*Value, std::make_pair(20, 1));
   EXPECT_EQ(Value->first, 20);
 }
+
+TEST(DiagnosticTest, storedDiagEmptyWarning) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
+  new IgnoringDiagConsumer());
+
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+SmallVector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic &Info) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+
+  CaptureDiagnosticConsumer CaptureConsumer;
+  Diags.setClient(&CaptureConsumer, /*ShouldOwnClient=*/false);
+  Diags.Report(diag::pp_hash_warning) << "";
+  ASSERT_TRUE(CaptureConsumer.StoredDiags.size() == 1);
+
+  // Make sure an empty warning can round-trip with \c StoredDiagnostic.
+  Diags.Report(CaptureConsumer.StoredDiags.front());
+}
 }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -793,8 +793,8 @@
 /// array.
 void Diagnostic::
 FormatDiagnostic(SmallVectorImpl &OutStr) const {
-  if (!StoredDiagMessage.empty()) {
-OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+  if (StoredDiagMessage.has_value()) {
+OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
 return;
   }
 
Index: clang/include/clang/Basic/Diagnostic.h
===
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -1565,7 +1565,7 @@
 /// currently in-flight di

[PATCH] D145228: [clangd] Add clangd headers to install targets

2023-03-03 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai accepted this revision.
smeenai 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/D145228/new/

https://reviews.llvm.org/D145228

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


[PATCH] D145201: [clang] fixes header processing for `-fdiagnostics-format=sarif`

2023-03-03 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 502186.
cjdb added a comment.
Herald added a subscriber: mgrang.

sorts artifacts so that they're output in index order


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145201

Files:
  clang/include/clang/Frontend/SARIFDiagnostic.h
  clang/lib/Basic/Sarif.cpp
  clang/lib/Frontend/SARIFDiagnostic.cpp
  clang/test/Frontend/sarif-diagnostics.cpp
  clang/test/Frontend/sarif-diagnostics.hpp

Index: clang/test/Frontend/sarif-diagnostics.hpp
===
--- /dev/null
+++ clang/test/Frontend/sarif-diagnostics.hpp
@@ -0,0 +1 @@
+Test test;
Index: clang/test/Frontend/sarif-diagnostics.cpp
===
--- clang/test/Frontend/sarif-diagnostics.cpp
+++ clang/test/Frontend/sarif-diagnostics.cpp
@@ -27,6 +27,8 @@
 x + y;
 }
 
+#include "sarif-diagnostics.hpp"
+
 // RUN: %clang -fsyntax-only -Wall -Wextra -fdiagnostics-format=sarif %s > %t.txt 2>&1 || true
 // RUN: FileCheck -dump-input=always %s --input-file=%t.txt --check-prefixes=STDERR,SARIF
 
@@ -46,6 +48,17 @@
 // SARIF:   "roles":[
 // SARIF: "resultFile"
 // SARIF:   ]
+// SARIF: },
+// SARIF: {
+// SARIF:   "length":{{[0-9]+}},
+// SARIF:   "location":{
+// SARIF: "index":1,
+// SARIF: "uri":"file://{{[^"]+test/Frontend/sarif-diagnostics.hpp}}"
+// SARIF:   },
+// SARIF:   "mimeType":"text/plain",
+// SARIF:   "roles":[
+// SARIF: "resultFile"
+// SARIF:   ]
 // SARIF: }
 // SARIF:   ],
 // SARIF:   "columnKind":"unicodeCodePoints",
@@ -172,7 +185,7 @@
 // SARIF:   "physicalLocation":{
 // SARIF: "artifactLocation":{
 // SARIF:   "index":0,
-// SARIF:   "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}}
+// SARIF:   "uri":{{"file://[^"]+clang/test/Frontend/sarif-diagnostics.cpp"}}
 // SARIF: },
 // SARIF: "region":{
 // SARIF:   "endColumn":10,
@@ -195,7 +208,7 @@
 // SARIF:   "physicalLocation":{
 // SARIF: "artifactLocation":{
 // SARIF:   "index":0,
-// SARIF:   "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}}
+// SARIF:   "uri":{{"file://[^"]+clang/test/Frontend/sarif-diagnostics.cpp"}}
 // SARIF: },
 // SARIF: "region":{
 // SARIF:   "endColumn":12,
@@ -284,6 +297,52 @@
 // SARIF:   },
 // SARIF:   "ruleId":"4567",
 // SARIF:   "ruleIndex":8
+// SARIF: },
+// SARIF: {
+// SARIF:   "level":"note",
+// SARIF:   "locations":[
+// SARIF: {
+// SARIF:   "physicalLocation":{
+// SARIF: "artifactLocation":{
+// SARIF:   "index":0,
+// SARIF:   "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}}
+// SARIF: },
+// SARIF: "region":{
+// SARIF:   "endColumn":10,
+// SARIF:   "startColumn":10,
+// SARIF:   "startLine":30
+// SARIF: }
+// SARIF:   }
+// SARIF: }
+// SARIF:   ],
+// SARIF:   "message":{
+// SARIF: "text":"in file included from {{[^"]+test/Frontend/sarif-diagnostics.cpp:30:}}\n"
+// SARIF:   },
+// SARIF:   "ruleId":"-1",
+// SARIF:   "ruleIndex":9
+// SARIF: },
+// SARIF: {
+// SARIF:   "level":"error",
+// SARIF:   "locations":[
+// SARIF: {
+// SARIF:   "physicalLocation":{
+// SARIF: "artifactLocation":{
+// SARIF:   "index":1,
+// SARIF:   "uri":"file:///{{[^"]+/test/Frontend/sarif-diagnostics.hpp}}"
+// SARIF: },
+// SARIF: "region":{
+// SARIF:   "endColumn":1,
+// SARIF:   "startColumn":1,
+// SARIF:   "startLine":1
+// SARIF: }
+// SARIF:   }
+// SARIF: }
+// SARIF:   ],
+// SARIF:   "message":{
+// SARIF: "text":"unknown type name 'Test'"
+// SARIF:   },
+// SARIF:   "ruleId":"4657",
+// SARIF:   "ruleIndex":10
 // SARIF: }
 // SARIF:   ],
 // SARIF:   "tool":{
@@ -400,6 +459,30 @@
 // SARIF:   },
 // SARIF:   "id":"4567",
 // SARIF:   "name":""
+// SARIF: },
+// SARIF: {
+// SARIF:   "defaultConfiguration":{
+// SARIF: "enabled":true,
+// SARIF: "level":"note",
+// SARIF: "rank":-1

[PATCH] D145201: [clang] fixes header processing for `-fdiagnostics-format=sarif`

2023-03-03 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

That test is kinda problematic because it seems that the artifacts aren't 
ordered. I think we should change this from a




Comment at: clang/lib/Basic/Sarif.cpp:314-317
+  llvm::sort(*Artifacts, [](const json::Value &x, const json::Value &y) {
+return x.getAsObject()->getNumber("index") <
+   y.getAsObject()->getNumber("index");
+  });

I'm wondering if I should instead copy `CurrentArtifacts` to a vector and sort 
prior to insertion, rather than in post.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:214
 void SARIFDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) 
{
-  assert(false && "Not implemented in SARIF mode");
+  SarifRule Rule = SarifRule::create().setRuleId(std::to_string(-1));
+  Rule = addDiagnosticLevelToRule(Rule, DiagnosticsEngine::Level::Note);

aaron.ballman wrote:
> Why do we want -1 as the rule ID and... can we use `"-1"` instead of doing a 
> string conversion?
lol at obvious C++ goof.

Re -1, there doesn't seem to be a diagnostic associated with this note, so I 
picked a value that I know isn't in use.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145201

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


[PATCH] D145201: [clang] fixes header processing for `-fdiagnostics-format=sarif`

2023-03-03 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 502190.
cjdb added a comment.

fixes string goof


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145201

Files:
  clang/include/clang/Frontend/SARIFDiagnostic.h
  clang/lib/Basic/Sarif.cpp
  clang/lib/Frontend/SARIFDiagnostic.cpp
  clang/test/Frontend/sarif-diagnostics.cpp
  clang/test/Frontend/sarif-diagnostics.hpp

Index: clang/test/Frontend/sarif-diagnostics.hpp
===
--- /dev/null
+++ clang/test/Frontend/sarif-diagnostics.hpp
@@ -0,0 +1 @@
+Test test;
Index: clang/test/Frontend/sarif-diagnostics.cpp
===
--- clang/test/Frontend/sarif-diagnostics.cpp
+++ clang/test/Frontend/sarif-diagnostics.cpp
@@ -27,6 +27,8 @@
 x + y;
 }
 
+#include "sarif-diagnostics.hpp"
+
 // RUN: %clang -fsyntax-only -Wall -Wextra -fdiagnostics-format=sarif %s > %t.txt 2>&1 || true
 // RUN: FileCheck -dump-input=always %s --input-file=%t.txt --check-prefixes=STDERR,SARIF
 
@@ -46,6 +48,17 @@
 // SARIF:   "roles":[
 // SARIF: "resultFile"
 // SARIF:   ]
+// SARIF: },
+// SARIF: {
+// SARIF:   "length":{{[0-9]+}},
+// SARIF:   "location":{
+// SARIF: "index":1,
+// SARIF: "uri":"file://{{[^"]+test/Frontend/sarif-diagnostics.hpp}}"
+// SARIF:   },
+// SARIF:   "mimeType":"text/plain",
+// SARIF:   "roles":[
+// SARIF: "resultFile"
+// SARIF:   ]
 // SARIF: }
 // SARIF:   ],
 // SARIF:   "columnKind":"unicodeCodePoints",
@@ -172,7 +185,7 @@
 // SARIF:   "physicalLocation":{
 // SARIF: "artifactLocation":{
 // SARIF:   "index":0,
-// SARIF:   "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}}
+// SARIF:   "uri":{{"file://[^"]+clang/test/Frontend/sarif-diagnostics.cpp"}}
 // SARIF: },
 // SARIF: "region":{
 // SARIF:   "endColumn":10,
@@ -195,7 +208,7 @@
 // SARIF:   "physicalLocation":{
 // SARIF: "artifactLocation":{
 // SARIF:   "index":0,
-// SARIF:   "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}}
+// SARIF:   "uri":{{"file://[^"]+clang/test/Frontend/sarif-diagnostics.cpp"}}
 // SARIF: },
 // SARIF: "region":{
 // SARIF:   "endColumn":12,
@@ -284,6 +297,52 @@
 // SARIF:   },
 // SARIF:   "ruleId":"4567",
 // SARIF:   "ruleIndex":8
+// SARIF: },
+// SARIF: {
+// SARIF:   "level":"note",
+// SARIF:   "locations":[
+// SARIF: {
+// SARIF:   "physicalLocation":{
+// SARIF: "artifactLocation":{
+// SARIF:   "index":0,
+// SARIF:   "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}}
+// SARIF: },
+// SARIF: "region":{
+// SARIF:   "endColumn":10,
+// SARIF:   "startColumn":10,
+// SARIF:   "startLine":30
+// SARIF: }
+// SARIF:   }
+// SARIF: }
+// SARIF:   ],
+// SARIF:   "message":{
+// SARIF: "text":"in file included from {{[^"]+test/Frontend/sarif-diagnostics.cpp:30:}}\n"
+// SARIF:   },
+// SARIF:   "ruleId":"-1",
+// SARIF:   "ruleIndex":9
+// SARIF: },
+// SARIF: {
+// SARIF:   "level":"error",
+// SARIF:   "locations":[
+// SARIF: {
+// SARIF:   "physicalLocation":{
+// SARIF: "artifactLocation":{
+// SARIF:   "index":1,
+// SARIF:   "uri":"file:///{{[^"]+/test/Frontend/sarif-diagnostics.hpp}}"
+// SARIF: },
+// SARIF: "region":{
+// SARIF:   "endColumn":1,
+// SARIF:   "startColumn":1,
+// SARIF:   "startLine":1
+// SARIF: }
+// SARIF:   }
+// SARIF: }
+// SARIF:   ],
+// SARIF:   "message":{
+// SARIF: "text":"unknown type name 'Test'"
+// SARIF:   },
+// SARIF:   "ruleId":"4657",
+// SARIF:   "ruleIndex":10
 // SARIF: }
 // SARIF:   ],
 // SARIF:   "tool":{
@@ -400,6 +459,30 @@
 // SARIF:   },
 // SARIF:   "id":"4567",
 // SARIF:   "name":""
+// SARIF: },
+// SARIF: {
+// SARIF:   "defaultConfiguration":{
+// SARIF: "enabled":true,
+// SARIF: "level":"note",
+// SARIF: "rank":-1
+// SARIF:   },
+// SARIF:   "fullDescription":

[PATCH] D145256: [clang/Diagnostic] Use `optional` to disambiguate between a `StoredDiagMessage` that is not set vs set as empty string

2023-03-03 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


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145256

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


[PATCH] D145256: [clang/Diagnostic] Use `optional` to disambiguate between a `StoredDiagMessage` that is not set vs set as empty string

2023-03-03 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 502201.
akyrtzi added a comment.

Avoid passing a new `IgnoringDiagConsumer` for the test since it's unused.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145256

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/lib/Basic/Diagnostic.cpp
  clang/unittests/Basic/DiagnosticTest.cpp


Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticError.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -128,4 +129,26 @@
   EXPECT_EQ(*Value, std::make_pair(20, 1));
   EXPECT_EQ(Value->first, 20);
 }
+
+TEST(DiagnosticTest, storedDiagEmptyWarning) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions);
+
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+SmallVector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic &Info) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+
+  CaptureDiagnosticConsumer CaptureConsumer;
+  Diags.setClient(&CaptureConsumer, /*ShouldOwnClient=*/false);
+  Diags.Report(diag::pp_hash_warning) << "";
+  ASSERT_TRUE(CaptureConsumer.StoredDiags.size() == 1);
+
+  // Make sure an empty warning can round-trip with \c StoredDiagnostic.
+  Diags.Report(CaptureConsumer.StoredDiags.front());
+}
 }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -793,8 +793,8 @@
 /// array.
 void Diagnostic::
 FormatDiagnostic(SmallVectorImpl &OutStr) const {
-  if (!StoredDiagMessage.empty()) {
-OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+  if (StoredDiagMessage.has_value()) {
+OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
 return;
   }
 
Index: clang/include/clang/Basic/Diagnostic.h
===
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -1565,7 +1565,7 @@
 /// currently in-flight diagnostic.
 class Diagnostic {
   const DiagnosticsEngine *DiagObj;
-  StringRef StoredDiagMessage;
+  std::optional StoredDiagMessage;
 
 public:
   explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}


Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticError.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -128,4 +129,26 @@
   EXPECT_EQ(*Value, std::make_pair(20, 1));
   EXPECT_EQ(Value->first, 20);
 }
+
+TEST(DiagnosticTest, storedDiagEmptyWarning) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions);
+
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+SmallVector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic &Info) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+
+  CaptureDiagnosticConsumer CaptureConsumer;
+  Diags.setClient(&CaptureConsumer, /*ShouldOwnClient=*/false);
+  Diags.Report(diag::pp_hash_warning) << "";
+  ASSERT_TRUE(CaptureConsumer.StoredDiags.size() == 1);
+
+  // Make sure an empty warning can round-trip with \c StoredDiagnostic.
+  Diags.Report(CaptureConsumer.StoredDiags.front());
+}
 }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -793,8 +793,8 @@
 /// array.
 void Diagnostic::
 FormatDiagnostic(SmallVectorImpl &OutStr) const {
-  if (!StoredDiagMessage.empty()) {
-OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+  if (StoredDiagMessage.has_value()) {
+OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
 return;
   }
 
Index: clang/include/clang/Basic/Diagnostic.h
===
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -1565,7 +1565,7 @@
 /// currently in-flight diagnostic.
 class Diagnostic {
   const DiagnosticsEngine *DiagObj;
-  StringRef StoredDiagMessage;
+  std::optional StoredDiagMessage;
 
 public:
   explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}

[PATCH] D145021: [Clang][AIX][p] Claim -p in front end

2023-03-03 Thread Michael Francis via Phabricator via cfe-commits
francii added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6327
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {

daltenty wrote:
> Actually, a question here. Does this now result in the arg being claimed even 
> if nothing was done it? Since there are case we don't go into the error path.
I've updated the logic of this patch entirely. With these changes, using `-p` 
and `-pg` together now gives precedence to the option that is passed last.

Now, whenever we check for `-p`, we **never** do a blind claim. We instead 
manually claim `-p` in the following instances:
1. The user passes `-p` without also passing `-pg`: We manually claim `-p`, and 
push `-pg` to `CmdArgs`.
2. The user passes both `-p` and `-pg`, but `-p` is given precedence: We 
manually claim `-p`, and do nothing (since `-pg` is already in `CmdArgs`).

As a result, `-p` will only warn that it goes unused if it is passed before 
`-pg` (i.e. `clang -p -pg`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

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


[PATCH] D145021: [Clang][AIX][p] Claim -p in front end

2023-03-03 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 502204.
francii added a comment.

Fix missing bracket


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ibm-profiling.c
  clang/test/Driver/zos-profiling-error.c

Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,27 @@
+// Check that -pg throws an error on z/OS.
+// RUN: %clang -### 2>&1 --target=s390x-none-zos -S -pg %s | FileCheck -check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang -### 2>&1 --target=powerpc-ibm-aix7.1.0.0 -S -p -S %s \
+// RUN:   | FileCheck --check-prefix=CHECK3 %s
+// CHECK3-NOT: warning: argument unused during compilation: '-p'
+
+// Check precedence: -pg is unused when passed first on AIX.
+// RUN: %clang -### 2>&1 --target=powerpc-ibm-aix7.1.0.0 --sysroot %S/Inputs/aix_ppc_tree -pg -p %s \
+// RUN:| FileCheck --check-prefix=CHECK %s
+// CHECK-NOT: warning: argument unused during compilation: '-p' [-Wunused-command-line-argument]
+// CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK: "[[SYSROOT]]/usr/lib{{/|}}mcrt0.o"
+// CHECK: "-L[[SYSROOT]]/lib/profiled"
+// CHECK: "-L[[SYSROOT]]/usr/lib/profiled"
+
+// Check precedence: -p is unused when passed first on AIX.
+// RUN: %clang -### 2>&1 --target=powerpc-ibm-aix7.1.0.0 --sysroot %S/Inputs/aix_ppc_tree -p -pg %s \
+// RUN:| FileCheck --check-prefix=CHECK2 %s
+// CHECK2: warning: argument unused during compilation: '-p' [-Wunused-command-line-argument]
+// CHECK2: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK2: "[[SYSROOT]]/usr/lib{{/|}}gcrt0.o"
+// CHECK2: "-L[[SYSROOT]]/lib/profiled"
+// CHECK2: "-L[[SYSROOT]]/usr/lib/profiled"
+
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6322,20 +6322,26 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
-if (TC.getTriple().isOSAIX()) {
-  CmdArgs.push_back("-pg");
-} else if (!TC.getTriple().isOSOpenBSD()) {
+
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
+if (TC.getTriple().isOSzOS()) {
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
-if (TC.getTriple().isOSzOS()) {
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+if (!(TC.getTriple().isOSAIX() || TC.getTriple().isOSOpenBSD())) {
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
   }
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) {
+if (A->getOption().matches(options::OPT_p)) {
+  A->claim();
+  if (TC.getTriple().isOSAIX() && !Args.hasArgNoClaim(options::OPT_pg))
+CmdArgs.push_back("-pg");
+}
+  }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
   (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -164,11 +164,12 @@
   }
 
   auto getCrt0Basename = [&Args, IsArch32Bit] {
+Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg);
 // Enable gprofiling when "-pg" is specified.
-if (Args.hasArg(options::OPT_pg))
+if (A->getOption().matches(options::OPT_pg))
   return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o";
 // Enable profiling when "-p" is specified.
-else if (Args.hasArg(options::OPT_p))
+else if (A->getOption().matches(options::OPT_p))
   return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o";
 else
   return IsArch32Bit ? "crt0.o" : "crt0_64.o";
@@ -271,7 +272,7 @@
 
 CmdArgs.push_back("-lc");
 
-if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
+if (Args.hasArgNoClaim(options::OPT_p, options::OPT_pg)) {
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
"/lib/profiled"));
   CmdArgs.push_back(Args.MakeAr

[PATCH] D144864: [Flang][Driver][MLIR] Add -fopenmp-is-device to Flang and link to an omp.is_device attribute

2023-03-03 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added inline comments.



Comment at: clang/test/Driver/flang/flang-omp.f90:1
+! Check that flang -fc1 is invoked when in --driver-mode=flang 
+! and the relevant openmp and openmp offload flags are utilised

agozillon wrote:
> awarzynski wrote:
> > This test looks correct to me, but please note that:
> > 
> > ```
> > ! Check that flang -fc1 is invoked when in --driver-mode=flang 
> > ```
> > 
> > yet (`%clang` instead of `%flang`)
> > 
> > ```
> > ! RUN: %clang --driver-mode=flang -### -fopenmp %s 2>&1 | FileCheck 
> > --check-prefixes=CHECK-OPENMP %s
> > ```
> > 
> > I'm not really sure whether we should be testing Flang-specific logic in 
> > Clang. Having said that, Flang does use `clangDriver` to implement its 
> > driver :) 
> > 
> > You could consider using 
> > https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/frontend-forwarding.f90
> >  instead (or add an OpenMP specific file there).
> > 
> > Not a blocker.
> Yes, I wasn't so sure either as it felt a little weird to test Flang 
> components inside of Clang, but as you said it is a Clang toolchain (that 
> this test is checking) and borrows from the clangDriver! 
> 
> I borrowed this test from other similar tests in the same folder that test 
> other flang specific driver logic in a similar manner, but I am more than 
> happy to add an additional flang specific driver test as you mention! 
On further looking into the frontend-forwarding test, I don't know if it is 
suitable for fopenmp-is-device as it is an fc1 option and won't be forwarded 
from the flang-new frontend down to fc1 at the moment! 

I think this test will be more suitable when additional flags like the 
fopenmp-targets (or similar flags) that are used in this test are added to the 
Flang driver. As they spawn/propagate the openmp-is-device flag. However, 
perhaps I am incorrect.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144864

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


[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-03 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

Please see 
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-03 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

See also 
https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros

2023-03-03 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb created this revision.
jaredgrubb added reviewers: HazardyKnusperkeks, djasper, egorzhdan.
jaredgrubb added a project: clang-format.
Herald added a project: All.
jaredgrubb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I noticed that clang-format was inserting some strange indentation whenever I 
used custom "attribute-like macros"
(things like `FOO_EXTERN` to wrap attribute-visible-default, or macros with 
parentheses like `NS_SWIFT_NAME(...)`).

There are two parts to this fix:

- tokenize the paren after an `AttributeMacro` as a `TT_AttributeParen`
- treat a `AttributeMacro`-without-paren the same as one with a paren (eg, the 
`FOO_EXTERN` case)

I added a new test-case to differentiate a macro that is or is-not a 
`AttributeMacro`; also handled whether the
`ColumnLimit` is set to infinite (0) or a finite value, as part of this patch 
is in `ContinuationIndenter`.

There may be other places that need to handle `TT_AttributeMacro` better, but 
this is at least a step in the right
direction.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145262

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/test/Format/objc-definitions.m

Index: clang/test/Format/objc-definitions.m
===
--- /dev/null
+++ clang/test/Format/objc-definitions.m
@@ -0,0 +1,58 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s \
+// RUN:   | clang-format -style="{BasedOnStyle: LLVM, AttributeMacros: [MACRO]}" \
+// RUN:   | FileCheck -strict-whitespace %s --check-prefixes=CHECK-COMMON,CHECK-ATTRMACRO
+// RUN: grep -Ev "// *[A-Z-]+:" %s \
+// RUN:   | clang-format -style="{BasedOnStyle: LLVM, AttributeMacros: [MACRO], ColumnLimit: 0}" \
+// RUN:   | FileCheck -strict-whitespace %s --check-prefixes=CHECK-COMMON,CHECK-ATTRMACRO
+// RUN: grep -Ev "// *[A-Z-]+:" %s \
+// RUN:   | clang-format -style="{BasedOnStyle: LLVM}" \
+// RUN:   | FileCheck -strict-whitespace %s --check-prefixes=CHECK-COMMON,CHECK-PLAIN
+// RUN: grep -Ev "// *[A-Z-]+:" %s \
+// RUN:   | clang-format -style="{BasedOnStyle: LLVM, ColumnLimit: 0}" \
+// RUN:   | FileCheck -strict-whitespace %s --check-prefixes=CHECK-COMMON,CHECK-PLAIN-COL0
+
+// CHECK-COMMON: {{^@interface Foo$}}
+// CHECK-COMMON-NEXT: {{^@end$}}
+@interface Foo
+@end
+
+// CHECK-COMMON: {{^MACRO$}}
+// CHECK-COMMON-NEXT: {{^@interface Foo$}}
+// CHECK-COMMON-NEXT: {{^@end$}}
+MACRO
+@interface Foo
+@end
+
+// CHECK-COMMON: {{^MACRO\(A\)$}}
+// CHECK-COMMON-NEXT: {{^@interface Foo$}}
+// CHECK-COMMON-NEXT: {{^@end$}}
+MACRO(A)
+@interface Foo
+@end
+
+// CHECK-ATTRMACRO: {{^MACRO MACRO\(A\)$}}
+// CHECK-ATTRMACRO-NEXT: {{^@interface Foo$}}
+// CHECK-ATTRMACRO-NEXT: {{^@end$}}
+// CHECK-PLAIN: {{^MACRO MACRO\(A\) @interface Foo$}}
+// CHECK-PLAIN-NEXT: {{^@end$}}
+// COM: The leading indentation in the next case is existing behavior but probably not desired.
+// CHECK-PLAIN-COL0: {{^MACRO MACRO\(A\)$}}
+// CHECK-PLAIN-COL0-NEXT: {{^@interface Foo$}}
+// CHECK-PLAIN-COL0-NEXT: {{^@end$}}
+MACRO MACRO(A)
+@interface Foo
+@end
+
+// CHECK-ATTRMACRO: {{^MACRO\(A\) MACRO$}}
+// CHECK-ATTRMACRO-NEXT: {{^@interface Foo$}}
+// CHECK-ATTRMACRO-NEXT: {{^@end$}}
+// CHECK-PLAIN: {{^MACRO\(A\) MACRO @interface Foo$}}
+// CHECK-PLAIN-NEXT: {{^@end$}}
+// COM: The leading indentation in the next case is existing behavior but probably not desired.
+// CHECK-PLAIN-COL0: {{^MACRO\(A\)$}}
+// CHECK-PLAIN-COL0: {{^MACRO$}}
+// CHECK-PLAIN-COL0-NEXT: {{^@interface Foo$}}
+// CHECK-PLAIN-COL0-NEXT: {{^@end$}}
+MACRO(A) MACRO
+@interface Foo
+@end
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -369,7 +369,7 @@
 // Infer the role of the l_paren based on the previous token if we haven't
 // detected one yet.
 if (PrevNonComment && OpeningParen.is(TT_Unknown)) {
-  if (PrevNonComment->is(tok::kw___attribute)) {
+  if (PrevNonComment->isOneOf(tok::kw___attribute, TT_AttributeMacro)) {
 OpeningParen.setType(TT_AttributeParen);
   } else if (PrevNonComment->isOneOf(TT_TypenameMacro, tok::kw_decltype,
  tok::kw_typeof,
@@ -4889,8 +4889,10 @@
   }
 
   // Ensure wrapping after __attribute__((XX)) and @interface etc.
-  if (Left.is(TT_AttributeParen) && Right.is(TT_ObjCDecl))
+  if (Left.isOneOf(TT_AttributeMacro, TT_AttributeParen) &&
+  Right.is(TT_ObjCDecl)) {
 return true;
+  }
 
   if (Left.is(TT_LambdaLBrace)) {
 if (IsFunctionArgument(Left) &&
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1228,8 +1228,9 @@
(PreviousNonComment->ClosesTemplate

[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-03 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

Please add unit tests to relevant files in `clang/unittests/Format/`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Please reupload with the complete context.

Please add tests.




Comment at: clang/include/clang/Format/Format.h:827
+  /// \code
+  ///   someFunction(
+  ///   int argument1,

That's not a valid declaration (missing return type), so not a good example.



Comment at: clang/include/clang/Format/Format.h:831
+  /// \endcode
+  bool AlwaysBreakBeforeFunctionParameters;
+

Please sort alphabetically. (So above `AlwaysBreakBeforeMultilineStrings`.)



Comment at: clang/include/clang/Format/Format.h:831
+  /// \endcode
+  bool AlwaysBreakBeforeFunctionParameters;
+

HazardyKnusperkeks wrote:
> Please sort alphabetically. (So above `AlwaysBreakBeforeMultilineStrings`.)
You are missing the \since 17.



Comment at: clang/lib/Format/Format.cpp:1510
   GoogleStyle.AlwaysBreakBeforeMultilineStrings = true;
+  GoogleStyle.AlwaysBreakBeforeFunctionParameters = false;
   GoogleStyle.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes;

Only set it in getLLVMStyle, which you are missing right now. Every other style 
will inherit it.



Comment at: clang/lib/Format/TokenAnnotator.cpp:4740-4742
+  if (Left.is(tok::l_paren) && Style.AlwaysBreakBeforeFunctionParameters &&
+  !Right.is(tok::r_paren)) {
+if (Left.Previous) {

Merge the `if`s.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros

2023-03-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added reviewers: rymiel, owenpan, MyDeveloperDay.
HazardyKnusperkeks added a comment.

Our tests reside in `clang/unittests/Format`, you want to look into the 
`TokenAnnotatorTests`. In fact **I** can't read the tests you wrote there.

And could you please provide an example what you want to format and where the 
misformatting (or apparently misannotation) happens?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145262

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


[PATCH] D145264: [OpenMP][MLIR] Lower and apply RTLModuleFlagsAttr

2023-03-03 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon created this revision.
Herald added subscribers: Moerafaat, zero9178, bzcheeseman, awarzynski, 
sdasgup3, wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, 
jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini, thopre, guansong, yaxunl.
Herald added a reviewer: sscalpone.
Herald added a reviewer: ftynse.
Herald added a reviewer: awarzynski.
Herald added projects: Flang, All.
agozillon requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, stephenneuendorffer, 
nicolasvasilache, jdoerfert, MaskRay.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: nicolasvasilache.
Herald added projects: clang, MLIR.

This patch adds the lowering for the RTLModuleFlagsAttr to LLVM-IR,
which lowers each individual arguent of the attribute to globals. AS well
as the application of it by flags in the frontend which have been activated
for flang fc1.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145264

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  clang/test/Driver/flang/flang-omp.f90
  flang/include/flang/Frontend/LangOptions.def
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Lower/OpenMP/rtl-flags.f90
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -1351,6 +1351,40 @@
   return success();
 }
 
+/// Lowers the RTLModuleFlagsAttr which is applied to the module on the device
+/// pass when offloading, this attribute contains OpenMP RTL globals that can
+/// be passed as flags to the frontend, otherwise they are set to default
+LogicalResult
+convertRTLModuleFlagsAttr(Operation *op,
+  mlir::omp::RTLModuleFlagsAttr attribute,
+  LLVM::ModuleTranslation &moduleTranslation) {
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+
+  ompBuilder->createGlobalFlag(
+  attribute.getDebugKind() /*LangOpts().OpenMPTargetDebug*/,
+  "__omp_rtl_debug_kind");
+  ompBuilder->createGlobalFlag(
+  attribute
+  .getAssumeTeamsOversubscription() /*LangOpts().OpenMPTeamSubscription*/
+  ,
+  "__omp_rtl_assume_teams_oversubscription");
+  ompBuilder->createGlobalFlag(
+  attribute
+  .getAssumeThreadsOversubscription() /*LangOpts().OpenMPThreadSubscription*/
+  ,
+  "__omp_rtl_assume_threads_oversubscription");
+  ompBuilder->createGlobalFlag(
+  attribute.getAssumeNoThreadState() /*LangOpts().OpenMPNoThreadState*/,
+  "__omp_rtl_assume_no_thread_state");
+  ompBuilder->createGlobalFlag(
+  attribute
+  .getAssumeNoNestedParallelism() /*LangOpts().OpenMPNoNestedParallelism*/
+  ,
+  "__omp_rtl_assume_no_nested_parallelism");
+
+  return success();
+}
+
 namespace {
 
 /// Implementation of the dialect interface that converts operations belonging
@@ -1365,10 +1399,34 @@
   LogicalResult
   convertOperation(Operation *op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) const final;
+
+  LogicalResult
+  amendOperation(Operation *op, NamedAttribute attribute,
+ LLVM::ModuleTranslation &moduleTranslation) const final;
 };
 
 } // namespace
 
+/// Given an OpenMP MLIR attribute, create the corresponding LLVM-IR, runtime
+/// calls, or operation amendments
+LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
+Operation *op, NamedAttribute attribute,
+LLVM::ModuleTranslation &moduleTranslation) const {
+
+  return llvm::TypeSwitch(attribute.getValue())
+  .Case([&](mlir::omp::RTLModuleFlagsAttr rtlAttr) {
+return convertRTLModuleFlagsAttr(op, rtlAttr, moduleTranslation);
+  })
+  .Default([&](Attribute attr) {
+// fall through for omp attributes that do not require lowering and/or
+// have no concrete definition and thus no type to define a case on
+// e.g. omp.is_device
+return success();
+  });
+
+  return failure();
+}
+
 /// Given an OpenMP MLIR operation, create the corresponding LLVM IR
 /// (including OpenMP runtime calls).
 LogicalResult OpenMPDialectLLVMIRTranslationInterface::convertOperation(
Index: flang/test/Lower/OpenMP/rtl-flags.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/rtl-flags.f90
@@ -0,0 +1,76 @@
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DEFAULT-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp %s

[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

And please add an entry to the `ReleaseNotes.rst`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D145264: [OpenMP][MLIR] Lower and apply RTLModuleFlagsAttr

2023-03-03 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

This builds on the following phabricator patches that are in review at the 
moment, so there are components that are used here that are added from these:

https://reviews.llvm.org/D144864 : add fopenmp-is-device and an mlir is-device 
attribute for the OpenMP dialect
https://reviews.llvm.org/D144896 : the RTLModuleFlagsAttr that is in use within 
this patch for lowering and application
https://reviews.llvm.org/D144883 : an infrastructure addition for the MLIR LLVM 
translation interface

For the moment, this patch is primarily to give context to the usage of the 
RTLModuleFlagsAttr mlir attribute and give some further understanding for a 
reviewer, however, please feel free to review it if you have time as I will 
eventually ask for some revision of it after all the components it depends on 
have been progressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

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


[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros

2023-03-03 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb added a comment.

For background, the current clang-format results in the following 
(`-style="{BasedOnStyle: LLVM, ColumnLimit: 0, AttributeMacros: [MACRO]}`):

  MACRO MACRO(A)
  @interface Foo
  @end
  
  MACRO(A)
  MACRO
  @interface Foo
  @end

This patch improves it (removes the indention and makes both cases have same 
wrapping):

  MACRO MACRO(A)
  @interface Foo
  @end
  
  MACRO(A) MACRO
  @interface Foo
  @end


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145262

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


[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros

2023-03-03 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb added a comment.

I wasn't sure about testing (this is my first patch!) and the test-case I did 
was in `clang/test/Format` .. I can look at `clang/unittests/Format` and see 
how to model something like it.

If I do that, would that be in-addition-to or instead-of the test-case I 
included already?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145262

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


  1   2   >