[clang] a4fbc09 - Clang: Don't warn about unused private fields of types declared maybe_unused

2023-08-30 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2023-08-30T09:06:39+02:00
New Revision: a4fbc091846206fb6f5bc36115d65075764b51ea

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

LOG: Clang: Don't warn about unused private fields of types declared 
maybe_unused

The compiler should not warn on code such as:

  class [[maybe_unused]] MaybeUnusedClass {};
  class C {
MaybeUnusedClass c;
  };

Patch based on comments on the bug by Shafik and Aaron.

Fixes #61334

Differential revision: https://reviews.llvm.org/D159083

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/warn-unused-private-field.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1bd295c68b83b7..1e273c1b7ce46a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@ Bug Fixes in This Version
 - Clang now emits an error if it is not possible to deduce array size for a
   variable with incomplete array type.
   (`#37257 `_)
+- Clang's ``-Wunused-private-field`` no longer warns on fields whose type is
+  declared with ``[[maybe_unused]]``.
+  (`#61334 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a7ab0948d01bf3..2b2b7391f88fd5 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -3729,10 +3729,20 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, 
AccessSpecifier AS, Declarator &D,
 if (!Diags.isIgnored(diag::warn_unused_private_field, FD->getLocation())) {
   // Remember all explicit private FieldDecls that have a name, no side
   // effects and are not part of a dependent type declaration.
+
+  auto DeclHasUnusedAttr = [](const QualType &T) {
+if (const TagDecl *TD = T->getAsTagDecl())
+  return TD->hasAttr();
+if (const TypedefType *TDT = T->getAs())
+  return TDT->getDecl()->hasAttr();
+return false;
+  };
+
   if (!FD->isImplicit() && FD->getDeclName() &&
   FD->getAccess() == AS_private &&
   !FD->hasAttr() &&
   !FD->getParent()->isDependentContext() &&
+  !DeclHasUnusedAttr(FD->getType()) &&
   !InitializationHasSideEffects(*FD))
 UnusedPrivateFields.insert(FD);
 }

diff  --git a/clang/test/SemaCXX/warn-unused-private-field.cpp 
b/clang/test/SemaCXX/warn-unused-private-field.cpp
index e67603eaceae66..1128eacc309d9f 100644
--- a/clang/test/SemaCXX/warn-unused-private-field.cpp
+++ b/clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -284,3 +284,14 @@ class defaulted_special_member {
 private:
   int n; // expected-warning{{private field 'n' is not used}}
 };
+
+namespace pr61334 {
+class [[maybe_unused]] MaybeUnusedClass {};
+enum [[maybe_unused]] MaybeUnusedEnum {};
+typedef int MaybeUnusedTypedef [[maybe_unused]];
+class C {
+  MaybeUnusedClass c; // no-warning
+  MaybeUnusedEnum e; // no-warning
+  MaybeUnusedTypedef t; // no-warning
+};
+}



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


[PATCH] D159083: Clang: Don't warn about unused private fields of types declared maybe_unused

2023-08-30 Thread Hans Wennborg 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 rGa4fbc0918462: Clang: Don't warn about unused private 
fields of types declared maybe_unused (authored by hans).

Changed prior to commit:
  https://reviews.llvm.org/D159083?vs=554312&id=554594#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159083

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/warn-unused-private-field.cpp


Index: clang/test/SemaCXX/warn-unused-private-field.cpp
===
--- clang/test/SemaCXX/warn-unused-private-field.cpp
+++ clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -284,3 +284,14 @@
 private:
   int n; // expected-warning{{private field 'n' is not used}}
 };
+
+namespace pr61334 {
+class [[maybe_unused]] MaybeUnusedClass {};
+enum [[maybe_unused]] MaybeUnusedEnum {};
+typedef int MaybeUnusedTypedef [[maybe_unused]];
+class C {
+  MaybeUnusedClass c; // no-warning
+  MaybeUnusedEnum e; // no-warning
+  MaybeUnusedTypedef t; // no-warning
+};
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3729,10 +3729,20 @@
 if (!Diags.isIgnored(diag::warn_unused_private_field, FD->getLocation())) {
   // Remember all explicit private FieldDecls that have a name, no side
   // effects and are not part of a dependent type declaration.
+
+  auto DeclHasUnusedAttr = [](const QualType &T) {
+if (const TagDecl *TD = T->getAsTagDecl())
+  return TD->hasAttr();
+if (const TypedefType *TDT = T->getAs())
+  return TDT->getDecl()->hasAttr();
+return false;
+  };
+
   if (!FD->isImplicit() && FD->getDeclName() &&
   FD->getAccess() == AS_private &&
   !FD->hasAttr() &&
   !FD->getParent()->isDependentContext() &&
+  !DeclHasUnusedAttr(FD->getType()) &&
   !InitializationHasSideEffects(*FD))
 UnusedPrivateFields.insert(FD);
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Clang now emits an error if it is not possible to deduce array size for a
   variable with incomplete array type.
   (`#37257 `_)
+- Clang's ``-Wunused-private-field`` no longer warns on fields whose type is
+  declared with ``[[maybe_unused]]``.
+  (`#61334 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/warn-unused-private-field.cpp
===
--- clang/test/SemaCXX/warn-unused-private-field.cpp
+++ clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -284,3 +284,14 @@
 private:
   int n; // expected-warning{{private field 'n' is not used}}
 };
+
+namespace pr61334 {
+class [[maybe_unused]] MaybeUnusedClass {};
+enum [[maybe_unused]] MaybeUnusedEnum {};
+typedef int MaybeUnusedTypedef [[maybe_unused]];
+class C {
+  MaybeUnusedClass c; // no-warning
+  MaybeUnusedEnum e; // no-warning
+  MaybeUnusedTypedef t; // no-warning
+};
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3729,10 +3729,20 @@
 if (!Diags.isIgnored(diag::warn_unused_private_field, FD->getLocation())) {
   // Remember all explicit private FieldDecls that have a name, no side
   // effects and are not part of a dependent type declaration.
+
+  auto DeclHasUnusedAttr = [](const QualType &T) {
+if (const TagDecl *TD = T->getAsTagDecl())
+  return TD->hasAttr();
+if (const TypedefType *TDT = T->getAs())
+  return TDT->getDecl()->hasAttr();
+return false;
+  };
+
   if (!FD->isImplicit() && FD->getDeclName() &&
   FD->getAccess() == AS_private &&
   !FD->hasAttr() &&
   !FD->getParent()->isDependentContext() &&
+  !DeclHasUnusedAttr(FD->getType()) &&
   !InitializationHasSideEffects(*FD))
 UnusedPrivateFields.insert(FD);
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Clang now emits an error if it is not possible to deduce array size for a
   variable with incomplete array type.
   (`#37257 `_)
+- Clang's ``-Wunused-private-field`` no longer warns on fields whose type is
+  declared with ``[[maybe_unused]]``

[PATCH] D159138: [clang][Sema] Fix format size estimator's handling of %o, %x, %X with alternative form

2023-08-30 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:966
+// size. e.g.(("%#3x", 0xf) is "0xf")
+
+// If the result is zero, o, b, x, X adds nothing.

Then couldn't we increase the Size if the `FieldWidth` is unspecified?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159138

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


[PATCH] D159024: [Parser] Parse string literal arguments of 'availability', 'external_source_symbol' and 'uuid' attributes as unevaluated

2023-08-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks again for working on this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159024

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


[PATCH] D159133: [Sema] Make C++ functional-style cast warn about dropped qualifiers (-Wcast-qual)

2023-08-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

I think this should get a mention in clang's releases notes. Otherwise LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159133

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


[PATCH] D158948: [clang][ASTImporter] Add import of type-related nodes

2023-08-30 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 554603.
danix800 added a comment.

Pulling local matchers for testcases, since https://reviews.llvm.org/D158872 is 
abandoned.


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

https://reviews.llvm.org/D158948

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

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -583,6 +583,96 @@
   functionDecl(hasDescendant(typedefDecl(has(atomicType());
 }
 
+TEST_P(ImportType, ImportBitIntType) {
+  const AstTypeMatcher bitIntType;
+  MatchVerifier Verifier;
+  testImport("_BitInt(10) declToImport;", Lang_CXX11, "", Lang_CXX11, Verifier,
+ varDecl(hasType(bitIntType(;
+}
+
+TEST_P(ImportType, ImportDependentBitIntType) {
+  const AstTypeMatcher dependentBitIntType;
+  MatchVerifier Verifier;
+  testImport("template using declToImport = _BitInt(Width);",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typeAliasTemplateDecl(
+ has(typeAliasDecl(hasType(dependentBitIntType());
+}
+
+TEST_P(ImportType, ImportDependentAddressSpaceType) {
+  const AstTypeMatcher dependentAddressSpaceType;
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((address_space(AddrSpace)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentAddressSpaceType());
+}
+
+TEST_P(ImportType, ImportVectorType) {
+  const AstTypeMatcher vectorType;
+  MatchVerifier Verifier;
+  testImport("typedef int __attribute__((vector_size(12))) declToImport;",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typedefDecl(hasType(vectorType(;
+}
+
+TEST_P(ImportType, ImportDependentVectorType) {
+  const AstTypeMatcher dependentVectorType;
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((vector_size(Size)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentVectorType());
+}
+
+struct ImportOpenCLPipe : ImportType {
+  std::vector getExtraArgs() const override {
+return {"-x", "cl", "-cl-no-stdinc", "-cl-std=CL2.0"};
+  }
+};
+
+TEST_P(ImportOpenCLPipe, ImportPipeType) {
+  const AstTypeMatcher pipeType;
+  MatchVerifier Verifier;
+  testImport("typedef pipe int declToImport;", Lang_OpenCL, "", Lang_OpenCL,
+ Verifier, typedefDecl(hasType(pipeType(;
+}
+
+struct ImportMatrixType : ImportType {
+  std::vector getExtraArgs() const override {
+return {"-fenable-matrix"};
+  }
+};
+
+TEST_P(ImportMatrixType, ImportConstantMatrixType) {
+  const AstTypeMatcher constantMatrixType;
+  MatchVerifier Verifier;
+  testImport("typedef int __attribute__((matrix_type(5, 5))) declToImport;",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typedefDecl(hasType(constantMatrixType(;
+}
+
+TEST_P(ImportMatrixType, ImportDependentSizedMatrixType) {
+  const AstTypeMatcher dependentSizedMatrixType;
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((matrix_type(Rows, Cols)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentSizedMatrixType());
+}
+
 TEST_P(ImportType, ImportUsingType) {
   MatchVerifier Verifier;
   testImport("struct C {};"
Index: clang/unittests/AST/ASTImporterObjCTest.cpp
===
--- clang/unittests/AST/ASTImporterObjCTest.cpp
+++ clang/unittests/AST/ASTImporterObjCTest.cpp
@@ -77,6 +77,22 @@
   }
 }
 
+TEST_P(ImportObjCDecl, ImportObjCTypeParamDecl) {
+  Decl *FromTU = getTuDecl(
+  R"(
+@interface X 
+@end
+  )",
+  Lang_OBJCXX, "input.mm");
+  auto *FromInterfaceDecl = FirstDeclMatcher().match(
+  FromTU, namedDecl(hasName("X")));
+  auto *FromTypeParamDecl =
+  FromInterfaceDecl->getTypeParamListAsWritten()->front();
+
+  auto *ToTypeParamDeclImported = Import(FromTypeParamDecl, Lang_OBJCXX);
+  ASSERT_TRUE(ToTypeParamDeclImported);
+}
+
 static const auto ObjCTestArrayForRunOptions =
 std::array, 2>{
 {std::vector{"-fno-objc-arc"},
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -368,58 +368,9 @@
 
 // Importing types
 ExpectedType VisitType(const Type *T);
-ExpectedType VisitAtomicType(const AtomicType *T);
-ExpectedType VisitBuiltinType(const BuiltinType *T);
-ExpectedType VisitDecayedType(const Decaye

[PATCH] D159163: [analyzer][NFC] Workaround miscompilation on recent MSVC

2023-08-30 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

Feel free to merge it. Thanks!
I'd be curious to see if this bug is tracked at Microsoft.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159163

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


[PATCH] D159173: [Driver] Report warnings for unlaimed TargetSpecific options for assembler input

2023-08-30 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: jansvoboda11, thesamesam, chill, peter.smith, 
simon_tatham, stuij.
Herald added subscribers: kadircet, kristof.beyls.
Herald added a reviewer: ctetreau.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, ilya-biryukov.
Herald added a project: clang.

This patch amends D151590  to not error for 
unlaimed TargetSpecific
options for `-x assembler` input files. This input type causes Driver to
construct tools::ClangAs (-fintegrated-as) or other assemblers (e.g.
tools::gnutools::Assembler) Their ConstructJobs methods, unlike
Clang::ConstructJobs, claim very few options. If an option is unclaimed,
it either leads to a -Wunused-command-line-argument warning or an error
(if `TargetSpecific` is set):

  % clang '-###' --target=aarch64 -mbranch-protection=bti -c a.s
  clang: error: unsupported option '-mbranch-protection=' for target 'aarch64'

It seems that downgrading the diagnostic to warning is most useful as
many users use CFLAGS even for `.s` files:

  clang --target=aarch64 -mbranch-protection=bti -S a.c
  clang --target=aarch64 -mbranch-protection=bti -c a.s

I decide not to suppress the warning so that
-Wunused-command-line-argument lovers still get a warning, and help
projects use proper ASFLAGS/CFLAGS/etc.

Note: `-mbranch-protection=bti a.S` currently has no warning as `-x 
assembler-with-cpp`
instructs clangDriver to select tools::Clang and claim most options.

Revert D159010  to demonstrate that we emit a 
warning for -mfpmath= for
`-x assembler` input.

Modify my AIX cleanup cd18efb61d759405956dbd30e4b5f2720d8e1783 
 to
add an err_drv_unsupported_opt_for_target.

Planned for main and release/17.x


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159173

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  clang/lib/Driver/ToolChains/Arch/X86.h
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/aarch64-target-as-march.s
  clang/test/Driver/target-specific.s
  clang/test/Driver/x86-mfpmath.c

Index: clang/test/Driver/x86-mfpmath.c
===
--- clang/test/Driver/x86-mfpmath.c
+++ clang/test/Driver/x86-mfpmath.c
@@ -1,5 +1,5 @@
 // RUN: %clang -### -c --target=x86_64 -mfpmath=sse %s 2>&1 | FileCheck %s
 // CHECK: "-mfpmath" "sse"
 
-/// Don't warn for assembler input.
-// RUN: %clang -### -Werror -c --target=x86_64 -mfpmath=sse -x assembler %s 2>&1 | FileCheck /dev/null --implicit-check-not='"-mfpmath"'
+// RUN: %clang -### -c --target=x86_64 -mfpmath=sse -x assembler %s 2>&1 | FileCheck %s --check-prefix=WARN
+// WARN: warning: argument unused during compilation: '-mfpmath=sse'
Index: clang/test/Driver/target-specific.s
===
--- /dev/null
+++ clang/test/Driver/target-specific.s
@@ -0,0 +1,12 @@
+/// Check that we report a warning instead of an error for target-specific compilation only options.
+// RUN: %clang -### --target=aarch64 -faddrsig -mbranch-protection=standard -c %s 2>&1 | FileCheck %s
+// RUN: %clang -### --target=aarch64 -faddrsig -mbranch-protection=standard -c -fno-integrated-as %s 2>&1 | FileCheck %s
+
+/// Report a warning if we perform the link phase.
+// RUN: %clang -### --target=aarch64 -faddrsig -mbranch-protection=standard %s 2>&1 | FileCheck %s
+
+// CHECK: warning: argument unused during compilation: '-faddrsig'
+// CHECK: warning: argument unused during compilation: '-mbranch-protection=standard'
+
+/// assembler-with-cpp claims compile only options. Ideally we should emit a warning.
+// RUN: %clang -### -Werror --target=aarch64 -c -faddrsig -mbranch-protection=standard -x assembler-with-cpp %s
Index: clang/test/Driver/aarch64-target-as-march.s
===
--- clang/test/Driver/aarch64-target-as-march.s
+++ clang/test/Driver/aarch64-target-as-march.s
@@ -35,7 +35,7 @@
 // MULTIPLE-VALUES-NOT: "-target-feature" "+v8.2a
 
 /// march to compiler and assembler, we choose the one suited to the input file type
-// RUN: not %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.3-a -march=armv8.4-a %s 2>&1 | \
+// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.3-a -march=armv8.4-a %s 2>&1 | \
 // RUN: FileCheck --check-prefix=TARGET-FEATURE-3 %s
 // RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.3-a -march=armv8.4-a \
 // RUN: %S/Inputs/wildcard1.c 2>&1 | FileCheck --check-prefix=TARGET-FEATURE-4 %s
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ 

[PATCH] D159174: [clang] Use stable_sort in AppendTargetMangling

2023-08-30 Thread Piyou Chen via Phabricator via cfe-commits
BeMg created this revision.
Herald added a subscriber: mgrang.
Herald added a project: All.
BeMg requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For the target features in the same priority, make sure it is not a random 
mangling name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159174

Files:
  clang/lib/CodeGen/CodeGenModule.cpp


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1627,7 +1627,7 @@
   Out << '.';
   const TargetInfo &Target = CGM.getTarget();
   ParsedTargetAttr Info = Target.parseTargetAttr(Attr->getFeaturesStr());
-  llvm::sort(Info.Features, [&Target](StringRef LHS, StringRef RHS) {
+  llvm::stable_sort(Info.Features, [&Target](StringRef LHS, StringRef RHS) {
 // Multiversioning doesn't allow "no-${feature}", so we can
 // only have "+" prefixes here.
 assert(LHS.startswith("+") && RHS.startswith("+") &&


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1627,7 +1627,7 @@
   Out << '.';
   const TargetInfo &Target = CGM.getTarget();
   ParsedTargetAttr Info = Target.parseTargetAttr(Attr->getFeaturesStr());
-  llvm::sort(Info.Features, [&Target](StringRef LHS, StringRef RHS) {
+  llvm::stable_sort(Info.Features, [&Target](StringRef LHS, StringRef RHS) {
 // Multiversioning doesn't allow "no-${feature}", so we can
 // only have "+" prefixes here.
 assert(LHS.startswith("+") && RHS.startswith("+") &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146054: [RISCV] Add --print-supported-extensions support

2023-08-30 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat added a comment.

In D146054#4596571 , @MaskRay wrote:

> In D146054#4587210 , @4vtomat wrote:
>
>> In D146054#4586067 , @MaskRay 
>> wrote:
>>
>>> I think the best place to test `RISCVISAInfo.cpp` is 
>>> `llvm/unittests/Support/RISCVISAInfoTest.cpp`.
>>>
>>> `clang/test/Driver/print-supported-extensions.c` can test just a few lines 
>>> (there will be some overlap with the testing in 
>>> `llvm/unittests/Support/RISCVISAInfoTest.cpp`), so that changes to RISC-V 
>>> extensions will generally not require updates to 
>>> `clang/test/Driver/print-supported-extensions.c`
>>
>> The goal of this patch is to list the supported extensions and their 
>> versions by providing an option, so I guess 
>> `clang/test/Driver/print-supported-extensions.c` aims differently with 
>> `llvm/unittests/Support/RISCVISAInfoTest.cpp` which is testing the 
>> functionalities in `RISCVISAInfoTest.cpp`.
>> `clang/test/Driver/print-supported-extensions.c` only tracks the extensions 
>> added and the their version changes and `riscvExtensionsHelp` in 
>> `llvm/lib/Support/RISCVISAInfo.cpp` doesn't have any input or output as well 
>> as any side effect, it only reads `SupportedExtensions` and 
>> `SupportedExperimentalExtensions` and dump the information.
>> So I think `clang/test/Driver/print-supported-extensions.c` is enough for 
>> this patch?
>
> My comment is about: the test is placed at the wrong layer. See 
> https://maskray.me/blog/2021-08-08-toolchain-testing#the-test-checks-at-the-wrong-layer
>
> I don't want that RISC-V development in LLVM causes repeated changes to 
> `clang/test/Driver`.

Got it, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146054

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


[PATCH] D146054: [RISCV] Add --print-supported-extensions support

2023-08-30 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat updated this revision to Diff 554609.
4vtomat added a comment.

Resolved MaskRay's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146054

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/tools/driver/cc1_main.cpp
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/unittests/Support/RISCVISAInfoTest.cpp

Index: llvm/unittests/Support/RISCVISAInfoTest.cpp
===
--- llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -604,3 +604,140 @@
   EXPECT_EQ(ExtsRV64IDZce.count("zcmp"), 1U);
   EXPECT_EQ(ExtsRV64IDZce.count("zcmt"), 1U);
 }
+
+TEST(RiscvExtensionsHelp, CheckExtensions) {
+  std::string ExpectedOutput =
+R"(All available -march extensions for RISC-V
+
+	NameVersion
+	i   2.1
+	e   2.0
+	m   2.0
+	a   2.1
+	f   2.2
+	d   2.2
+	c   2.0
+	v   1.0
+	h   1.0
+	zicbom  1.0
+	zicbop  1.0
+	zicboz  1.0
+	zicntr  1.0
+	zicsr   2.0
+	zifencei2.0
+	zihintpause 2.0
+	zihpm   1.0
+	zmmul   1.0
+	zawrs   1.0
+	zfh 1.0
+	zfhmin  1.0
+	zfinx   1.0
+	zdinx   1.0
+	zca 1.0
+	zcb 1.0
+	zcd 1.0
+	zce 1.0
+	zcf 1.0
+	zcmp1.0
+	zcmt1.0
+	zba 1.0
+	zbb 1.0
+	zbc 1.0
+	zbkb1.0
+	zbkc1.0
+	zbkx1.0
+	zbs 1.0
+	zk  1.0
+	zkn 1.0
+	zknd1.0
+	zkne1.0
+	zknh1.0
+	zkr 1.0
+	zks 1.0
+	zksed   1.0
+	zksh1.0
+	zkt 1.0
+	zve32f  1.0
+	zve32x  1.0
+	zve64d  1.0
+	zve64f  1.0
+	zve64x  1.0
+	zvfh1.0
+	zvl1024b1.0
+	zvl128b 1.0
+	zvl16384b   1.0
+	zvl2048b1.0
+	zvl256b 1.0
+	zvl32768b   1.0
+	zvl32b  1.0
+	zvl4096b1.0
+	zvl512b 1.0
+	zvl64b  1.0
+	zvl65536b   1.0
+	zvl8192b1.0
+	zhinx   1.0
+	zhinxmin1.0
+	svinval 1.0
+	svnapot 1.0
+	svpbmt  1.0
+	xcvalu  1.0
+	xcvbi   1.0
+	xcvbitmanip 1.0
+	xcvmac  1.0
+	xcvsimd 1.0
+	xsfcie  1.0
+	xsfvcp  1.0
+	xtheadba1.0
+	xtheadbb1.0
+	xtheadbs1.0
+	xtheadcmo   1.0
+	xtheadcondmov   1.0
+	xtheadfmemidx   1.0
+	xtheadmac   1.0
+	xtheadmemidx1.0
+	xtheadmempair   1.0
+	xtheadsync  1.0
+	xtheadvdot  1.0
+	xventanacondops 1.0
+
+Experimental extensions
+	zicond  1.0
+	zihintntl   0.2
+	zacas   1.0
+	zfa 0.2
+	zfbfmin 0.8
+	ztso0.1
+	zvbb1.0
+	zvbc1.0
+	zvfbfmin0.8
+	zvfbfwma0.8
+	zvkg1.0
+	zvkn1.0
+	zvknc   1.0
+	zvkned  1.0
+	zvkng   1.0
+	zvknha  1.0
+	zvknhb  1.0
+	zvks1.0
+	zvksc   1.0
+	zvksed  1.0
+	zvksg   1.0
+	zvksh   1.0
+	zvkt1.0
+	smaia   1.0
+	ssaia   1.0
+
+Use -march to specify the target's extension.
+For example, clang -march=rv32i_v1p0)";
+
+  outs().flush();
+  testing::internal::CaptureStdout();
+
+  llvm::riscvExtensionsHelp();
+  outs().flush();
+
+  std::string CapturedOutput = testing::internal::GetCapturedStdout();
+  EXPECT_TRUE([](std::string &Captured, std::string &Expected) {
+return Captured.find(Expected) != std::string::npos;
+  }(CapturedOutput, ExpectedOutput));
+}
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -208,6 +208,29 @@
 #endif
 }
 
+void llvm::riscvExtensionsHelp() {
+  outs() << "All available -march extensions for RISC-V\n\n";
+  outs() << '\t' << left_justify("Name", 20) << "Version\n";
+
+  RISCVISAInfo::OrderedExtensionMap ExtMap;
+  for (const auto &E : SupportedExtensions)
+ExtMap[E.Name] = {E.Version.Major, E.Versi

[PATCH] D158688: [Driver,ARM,AArch64] Ignore -mbranch-protection= diagnostics for assembler input

2023-08-30 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D158688#4625839 , @MaskRay wrote:

> In D158688#4624267 , @simon_tatham 
> wrote:
>
>> The change LGTM, and "agree with gcc" seems like a reasonable justification 
>> in this case.
>
> Thank you both!
>
>> But I'm curious more generally about what options should / shouldn't be 
>> covered by `-Wunused-command-line-argument`. Doesn't the same reasoning 
>> apply to //most// options that C compilation uses and assembly doesn't? If 
>> you have a command of the form `clang -someoption -c foo.c`, it's surely 
>> //always// convenient for a user to be able to change the `.c` into a `.s`, 
>> or to put a variable list of files on the end of the command line which 
>> might or might not include any `.c` files.
>
> `-Wunused-command-line-argument` does fire for most options when the only 
> input kind is assembly without preprocessing.
> It seems that the diagnostics are for `assembler` input, not 
> `assembler-with-cpp`...
>
>> Why is this option in particular different from others? Is there a 
>> documented policy anywhere?
>
> I am not aware of a documented policy anywhere, but I have some notes on 
> https://maskray.me/blog/2023-08-25-clang-wunused-command-line-argument#assembler-input
>  .
>
> Let me ask on Discourse: 
> https://discourse.llvm.org/t/wunused-command-line-argument-for-assembly-files/73111

I think we should do D159173  .. The warnings 
are still useful, but we can do it in Driver.cpp to avoid the `ForAS` hacks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158688

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


[PATCH] D159163: [analyzer][NFC] Workaround miscompilation on recent MSVC

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

Please add the exact versions to the commit message of Visual Studio where it 
worked, and where it didn't, thus we applied this change so that it would work 
on all (both) Visual Studio versions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159163

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


[clang] c1dda0f - [AST] Remove unneeded `return false` from UseExcessPrecision. NFC.

2023-08-30 Thread Jim Lin via cfe-commits

Author: Jim Lin
Date: 2023-08-30T16:05:55+08:00
New Revision: c1dda0f7934d28eb8dfc92206c49b188a1a091de

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

LOG: [AST] Remove unneeded `return false` from UseExcessPrecision. NFC.

Remove unneeded `return false` from UseExcessPrecision and move `break` inside.

Added: 


Modified: 
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 8173e082048207..c08ebfb7f142b3 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -1526,16 +1526,16 @@ bool QualType::UseExcessPrecision(const ASTContext 
&Ctx) {
   Ctx.getLangOpts().getFloat16ExcessPrecision() !=
   Ctx.getLangOpts().ExcessPrecisionKind::FPP_None)
 return true;
-  return false;
-} break;
+  break;
+}
 case BuiltinType::Kind::BFloat16: {
   const TargetInfo &TI = Ctx.getTargetInfo();
   if (TI.hasBFloat16Type() && !TI.hasFullBFloat16Type() &&
   Ctx.getLangOpts().getBFloat16ExcessPrecision() !=
   Ctx.getLangOpts().ExcessPrecisionKind::FPP_None)
 return true;
-  return false;
-} break;
+  break;
+}
 default:
   return false;
 }



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


[PATCH] D152752: [MS] Fix passing aligned records by value in some cases

2023-08-30 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D152752#4626234 , @rnk wrote:

> I need to get to it, my recollection is that @mstorsjo ran into the same 
> issue here for mingw and made some changes, I wanted to go dig those up as a 
> starting point. I may have completely forgotten things though.

Hmm, I don't remember doing anything in that area - I don't think I've had to 
touch variadics on i386 (or x86_64 for that matter) so far, or anything 
relating to aligned variadics. (The main thing that might sound similar to 
alignment was about setting up the homed registers on aarch64 when receiving 
variadics; there's some special casing there relating to whether the number of 
homed registers is even or odd. But all of that is much deeper within lowering 
in LLVM.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152752

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


[PATCH] D156076: [PowerPC][Clang] Remove constraint for initial-exec TLS mode on AIX

2023-08-30 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156076

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


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-30 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 updated this revision to Diff 554626.
NoumanAmir657 set the repository for this revision to rG LLVM Github Monorepo.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158540

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
  clang/test/CXX/drs/dr13xx.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/special/class.copy/p13-0x.cpp
  clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp

Index: clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
@@ -54,5 +54,5 @@
 
 struct W {
   int w;
-  constexpr W() __constant = default; // expected-error {{defaulted definition of default constructor is not constexpr}}
+  constexpr W() __constant = default; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'W' in 'W' class}}
 };
Index: clang/test/CXX/special/class.copy/p13-0x.cpp
===
--- clang/test/CXX/special/class.copy/p13-0x.cpp
+++ clang/test/CXX/special/class.copy/p13-0x.cpp
@@ -125,7 +125,7 @@
 mutable A a;
   };
   struct C {
-constexpr C(const C &) = default; // expected-error {{not constexpr}}
+constexpr C(const C &) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class}}
 A a;
   };
 }
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -129,19 +129,19 @@
 union A { constexpr A() = default; };
 union B { int n; constexpr B() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note@-2 {{see reference to function 'B' in 'B' class}}
 #endif
 union C { int n = 0; constexpr C() = default; };
 struct D { union {}; constexpr D() = default; }; // expected-error {{does not declare anything}}
 struct E { union { int n; }; constexpr E() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note@-2 {{see reference to function 'E' in 'E' class}}
 #endif
 struct F { union { int n = 0; }; constexpr F() = default; };
 
 struct G { union { int n = 0; }; union { int m; }; constexpr G() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note@-2 {{see reference to function 'G' in 'G' class}}
 #endif
 struct H {
   union {
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -328,10 +328,10 @@
 namespace dr1359 { // dr1359: 3.5
 #if __cplusplus >= 201103L
   union A { constexpr A() = default; };
-  union B { constexpr B() = default; int a; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
-  union C { constexpr C() = default; int a, b; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
+  union B { constexpr B() = default; int a; }; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'B' in 'B' class}} expected-note 2{{candidate}}
+  union C { constexpr C() = default; int a, b; }; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class}} expected-note 2{{candidate}}
   struct X { constexpr X() = default; union {}; }; // expected-error {{does not declare anything}}
-  struct Y { constexpr Y() = default; union { int a; }; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
+  struct Y { constexpr Y() = default; union { int a; }; }; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'Y' in 'Y' class}} expected-note 2{{candidate}}
 
   constexpr A a = A();
   constexpr B b = B(); // expected-error {{no matching}}
Index: clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp

[clang] 9b35254 - [NFC][Clang] Remove unused function `CodeGenModule::addDefaultFunctionDefinitionAttributes`

2023-08-30 Thread Juan Manuel MARTINEZ CAAMAÑO via cfe-commits

Author: Juan Manuel MARTINEZ CAAMAÑO
Date: 2023-08-30T10:32:51+02:00
New Revision: 9b352540184e181d2a38423d352c5d5e2142839e

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

LOG: [NFC][Clang] Remove unused function 
`CodeGenModule::addDefaultFunctionDefinitionAttributes`

This patch deletes the unused 
`addDefaultFunctionDefinitionAttributes(llvm::Function);` function,
while it still keeps `void 
addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs);` which is 
being used.

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

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7127bbb0450e93..01bbbd7371aad4 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2094,14 +2094,6 @@ void 
CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
 addMergableDefaultFunctionAttributes(CodeGenOpts, FuncAttrs);
 }
 
-void CodeGenModule::addDefaultFunctionDefinitionAttributes(llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  getDefaultFunctionAttributes(F.getName(), F.hasOptNone(),
-   /* AttrOnCallSite = */ false, FuncAttrs);
-  // TODO: call GetCPUAndFeaturesAttributes?
-  F.addFnAttrs(FuncAttrs);
-}
-
 /// Apply default attributes to \p F, accounting for merge semantics of
 /// attributes that should not overwrite existing attributes.
 void CodeGenModule::mergeDefaultFunctionDefinitionAttributes(

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index d4032aa6feb950..c8fc068bde7bba 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1276,7 +1276,6 @@ class CodeGenModule : public CodeGenTypeCache {
   /// on the function more conservative.  But it's unsafe to call this on a
   /// function which relies on particular fast-math attributes for correctness.
   /// It's up to you to ensure that this is safe.
-  void addDefaultFunctionDefinitionAttributes(llvm::Function &F);
   void mergeDefaultFunctionDefinitionAttributes(llvm::Function &F,
 bool WillInternalize);
 



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


[PATCH] D158990: [NFC][Clang] Remove unused function `CodeGenModule::addDefaultFunctionDefinitionAttributes`

2023-08-30 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9b352540184e: [NFC][Clang] Remove unused function 
`CodeGenModule… (authored by jmmartinez).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158990

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.h


Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1276,7 +1276,6 @@
   /// on the function more conservative.  But it's unsafe to call this on a
   /// function which relies on particular fast-math attributes for correctness.
   /// It's up to you to ensure that this is safe.
-  void addDefaultFunctionDefinitionAttributes(llvm::Function &F);
   void mergeDefaultFunctionDefinitionAttributes(llvm::Function &F,
 bool WillInternalize);
 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2094,14 +2094,6 @@
 addMergableDefaultFunctionAttributes(CodeGenOpts, FuncAttrs);
 }
 
-void CodeGenModule::addDefaultFunctionDefinitionAttributes(llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  getDefaultFunctionAttributes(F.getName(), F.hasOptNone(),
-   /* AttrOnCallSite = */ false, FuncAttrs);
-  // TODO: call GetCPUAndFeaturesAttributes?
-  F.addFnAttrs(FuncAttrs);
-}
-
 /// Apply default attributes to \p F, accounting for merge semantics of
 /// attributes that should not overwrite existing attributes.
 void CodeGenModule::mergeDefaultFunctionDefinitionAttributes(


Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1276,7 +1276,6 @@
   /// on the function more conservative.  But it's unsafe to call this on a
   /// function which relies on particular fast-math attributes for correctness.
   /// It's up to you to ensure that this is safe.
-  void addDefaultFunctionDefinitionAttributes(llvm::Function &F);
   void mergeDefaultFunctionDefinitionAttributes(llvm::Function &F,
 bool WillInternalize);
 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2094,14 +2094,6 @@
 addMergableDefaultFunctionAttributes(CodeGenOpts, FuncAttrs);
 }
 
-void CodeGenModule::addDefaultFunctionDefinitionAttributes(llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  getDefaultFunctionAttributes(F.getName(), F.hasOptNone(),
-   /* AttrOnCallSite = */ false, FuncAttrs);
-  // TODO: call GetCPUAndFeaturesAttributes?
-  F.addFnAttrs(FuncAttrs);
-}
-
 /// Apply default attributes to \p F, accounting for merge semantics of
 /// attributes that should not overwrite existing attributes.
 void CodeGenModule::mergeDefaultFunctionDefinitionAttributes(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-30 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 updated this revision to Diff 554629.

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

https://reviews.llvm.org/D158540

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
  clang/test/CXX/drs/dr13xx.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/special/class.copy/p13-0x.cpp
  clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp

Index: clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
@@ -54,5 +54,5 @@
 
 struct W {
   int w;
-  constexpr W() __constant = default; // expected-error {{defaulted definition of default constructor is not constexpr}}
+  constexpr W() __constant = default; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'W' in 'W' class}}
 };
Index: clang/test/CXX/special/class.copy/p13-0x.cpp
===
--- clang/test/CXX/special/class.copy/p13-0x.cpp
+++ clang/test/CXX/special/class.copy/p13-0x.cpp
@@ -125,7 +125,7 @@
 mutable A a;
   };
   struct C {
-constexpr C(const C &) = default; // expected-error {{not constexpr}}
+constexpr C(const C &) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class}}
 A a;
   };
 }
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -129,19 +129,19 @@
 union A { constexpr A() = default; };
 union B { int n; constexpr B() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note@-2 {{see reference to function 'B' in 'B' class}}
 #endif
 union C { int n = 0; constexpr C() = default; };
 struct D { union {}; constexpr D() = default; }; // expected-error {{does not declare anything}}
 struct E { union { int n; }; constexpr E() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note@-2 {{see reference to function 'E' in 'E' class}}
 #endif
 struct F { union { int n = 0; }; constexpr F() = default; };
 
 struct G { union { int n = 0; }; union { int m; }; constexpr G() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note@-2 {{see reference to function 'G' in 'G' class}}
 #endif
 struct H {
   union {
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -328,10 +328,10 @@
 namespace dr1359 { // dr1359: 3.5
 #if __cplusplus >= 201103L
   union A { constexpr A() = default; };
-  union B { constexpr B() = default; int a; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
-  union C { constexpr C() = default; int a, b; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
+  union B { constexpr B() = default; int a; }; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'B' in 'B' class}} expected-note 2{{candidate}}
+  union C { constexpr C() = default; int a, b; }; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class}} expected-note 2{{candidate}}
   struct X { constexpr X() = default; union {}; }; // expected-error {{does not declare anything}}
-  struct Y { constexpr Y() = default; union { int a; }; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
+  struct Y { constexpr Y() = default; union { int a; }; }; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'Y' in 'Y' class}} expected-note 2{{candidate}}
 
   constexpr A a = A();
   constexpr B b = B(); // expected-error {{no matching}}
Index: clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
===
--- clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
+++ cla

[clang] a7eaaba - [Parser] Parse string literal arguments of 'availability', 'external_source_symbol' and 'uuid' attributes as unevaluated

2023-08-30 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-08-30T11:46:54+03:00
New Revision: a7eaaba69906d3305752cb738332b9365e666def

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

LOG: [Parser] Parse string literal arguments of 'availability', 
'external_source_symbol' and 'uuid' attributes as unevaluated

This is a complementary to D156237.
These attributes have custom parsing logic.

Reviewed By: cor3ntin

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

Added: 


Modified: 
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/Parser/attr-availability-xcore.c
clang/test/Parser/attr-availability.c
clang/test/Parser/attr-external-source-symbol.m
clang/test/Parser/ms-square-bracket-attributes.mm

Removed: 




diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 8daa33a2a7b5b8..7c27a02ee4af62 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -1316,31 +1316,19 @@ void Parser::ParseAvailabilityAttribute(
 }
 ConsumeToken();
 if (Keyword == Ident_message || Keyword == Ident_replacement) {
-  if (Tok.isNot(tok::string_literal)) {
+  if (!isTokenStringLiteral()) {
 Diag(Tok, diag::err_expected_string_literal)
   << /*Source='availability attribute'*/2;
 SkipUntil(tok::r_paren, StopAtSemi);
 return;
   }
-  if (Keyword == Ident_message)
-MessageExpr = ParseStringLiteralExpression();
-  else
-ReplacementExpr = ParseStringLiteralExpression();
-  // Also reject wide string literals.
-  if (StringLiteral *MessageStringLiteral =
-  cast_or_null(MessageExpr.get())) {
-if (!MessageStringLiteral->isOrdinary()) {
-  Diag(MessageStringLiteral->getSourceRange().getBegin(),
-   diag::err_expected_string_literal)
-<< /*Source='availability attribute'*/ 2;
-  SkipUntil(tok::r_paren, StopAtSemi);
-  return;
-}
-  }
-  if (Keyword == Ident_message)
+  if (Keyword == Ident_message) {
+MessageExpr = ParseUnevaluatedStringLiteralExpression();
 break;
-  else
+  } else {
+ReplacementExpr = ParseUnevaluatedStringLiteralExpression();
 continue;
+  }
 }
 
 // Special handling of 'NA' only when applied to introduced or
@@ -1508,7 +1496,7 @@ void Parser::ParseExternalSourceSymbolAttribute(
 else
   HasDefinedIn = true;
 
-if (Tok.isNot(tok::string_literal)) {
+if (!isTokenStringLiteral()) {
   Diag(Tok, diag::err_expected_string_literal)
   << /*Source='external_source_symbol attribute'*/ 3
   << /*language | source container | USR*/ (
@@ -1522,27 +1510,27 @@ void Parser::ParseExternalSourceSymbolAttribute(
   if (HadLanguage) {
 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
 << Keyword;
-ParseStringLiteralExpression();
+ParseUnevaluatedStringLiteralExpression();
 continue;
   }
-  Language = ParseStringLiteralExpression();
+  Language = ParseUnevaluatedStringLiteralExpression();
 } else if (Keyword == Ident_USR) {
   if (HadUSR) {
 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
 << Keyword;
-ParseStringLiteralExpression();
+ParseUnevaluatedStringLiteralExpression();
 continue;
   }
-  USR = ParseStringLiteralExpression();
+  USR = ParseUnevaluatedStringLiteralExpression();
 } else {
   assert(Keyword == Ident_defined_in && "Invalid clause keyword!");
   if (HadDefinedIn) {
 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
 << Keyword;
-ParseStringLiteralExpression();
+ParseUnevaluatedStringLiteralExpression();
 continue;
   }
-  DefinedInExpr = ParseStringLiteralExpression();
+  DefinedInExpr = ParseUnevaluatedStringLiteralExpression();
 }
   } while (TryConsumeToken(tok::comma));
 

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 186a5e61a8fa32..730b6e55246d6b 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -4715,9 +4715,9 @@ void 
Parser::ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs) {
   }
 
   ArgsVector ArgExprs;
-  if (Tok.is(tok::string_literal)) {
+  if (isTokenStringLiteral()) {
 // Easy case: uuid("...") -- quoted string.
-ExprResult StringResult = ParseStringLiteralExpression();
+ExprResult StringResult = ParseUnevaluatedStringLiteralExpression();
 if (StringResult.isInvalid())
   return;
 ArgExprs.push_back(StringResult.get());
@@ -4772,7 +4772,7 @@ void 
Parser::ParseMicrosoftUu

[PATCH] D159024: [Parser] Parse string literal arguments of 'availability', 'external_source_symbol' and 'uuid' attributes as unevaluated

2023-08-30 Thread Sergei Barannikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa7eaaba69906: [Parser] Parse string literal arguments of 
'availability'… (authored by barannikov88).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159024

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/Parser/attr-availability-xcore.c
  clang/test/Parser/attr-availability.c
  clang/test/Parser/attr-external-source-symbol.m
  clang/test/Parser/ms-square-bracket-attributes.mm

Index: clang/test/Parser/ms-square-bracket-attributes.mm
===
--- clang/test/Parser/ms-square-bracket-attributes.mm
+++ clang/test/Parser/ms-square-bracket-attributes.mm
@@ -17,9 +17,9 @@
 )] struct struct_with_uuid_brace;
 
 // uuids must be ascii string literals.
-// expected-error@+1 {{uuid attribute contains a malformed GUID}}
+// expected-warning@+1 {{encoding prefix 'u8' on an unevaluated string literal has no effect and is incompatible with c++2c}}
 [uuid(u8"00A0---C000-0049")] struct struct_with_uuid_u8;
-// expected-error@+1 {{uuid attribute contains a malformed GUID}}
+// expected-warning@+1 {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}}
 [uuid(L"00A0---C000-0049")] struct struct_with_uuid_L;
 
 // cl.exe doesn't allow raw string literals in []-style attributes, but does
Index: clang/test/Parser/attr-external-source-symbol.m
===
--- clang/test/Parser/attr-external-source-symbol.m
+++ clang/test/Parser/attr-external-source-symbol.m
@@ -95,6 +95,27 @@
 void f28(void)
 __attribute__((external_source_symbol(USR="")));
 
+void f29(void)
+__attribute__((external_source_symbol(language=L"Swift"))); // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect}}
+
+void f30(void)
+__attribute__((external_source_symbol(language="Swift", language=L"Swift"))); // expected-error {{duplicate 'language' clause in an 'external_source_symbol' attribute}} \
+  // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect}}
+
+void f31(void)
+__attribute__((external_source_symbol(USR=u"foo"))); // expected-warning {{encoding prefix 'u' on an unevaluated string literal has no effect}}
+
+void f32(void)
+__attribute__((external_source_symbol(USR="foo", USR=u"foo"))); // expected-error {{duplicate 'USR' clause in an 'external_source_symbol' attribute}} \
+// expected-warning {{encoding prefix 'u' on an unevaluated string literal has no effect}}
+
+void f33(void)
+__attribute__((external_source_symbol(defined_in=U"module"))); // expected-warning {{encoding prefix 'U' on an unevaluated string literal has no effect}}
+
+void f34(void)
+__attribute__((external_source_symbol(defined_in="module", defined_in=U"module"))); // expected-error {{duplicate 'defined_in' clause in an 'external_source_symbol' attribute}} \
+// expected-warning {{encoding prefix 'U' on an unevaluated string literal has no effect}}
+
 #if __has_attribute(external_source_symbol) != 20230206
 # error "invalid __has_attribute version"
 #endif
Index: clang/test/Parser/attr-availability.c
===
--- clang/test/Parser/attr-availability.c
+++ clang/test/Parser/attr-availability.c
@@ -18,17 +18,17 @@
 
 void f6(void) __attribute__((availability(macosx,unavailable,introduced=10.5))); // expected-warning{{'unavailable' availability overrides all other availability information}}
 
-void f7(void) __attribute__((availability(macosx,message=L"wide"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+void f7(void) __attribute__((availability(macosx,message=L"wide"))); // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect}}
 
-void f8(void) __attribute__((availability(macosx,message="a" L"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+void f8(void) __attribute__((availability(macosx,message="a" L"b"))); // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect}}
 
-void f9(void) __attribute__((availability(macosx,message=u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+void f9(void) __attribute__((availability(macosx,message=u8"b"))); // expected-warning {{encoding prefix 'u8' on an unevaluated string literal has no effect}}
 
-void f10(void) __attribute__((availability(macosx,message="a" u8"b"))); // expe

[PATCH] D159163: [analyzer][NFC] Workaround miscompilation on recent MSVC

2023-08-30 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D159163#4627497 , @steakhal wrote:

> Feel free to merge it. Thanks!
> I'd be curious to see if this bug is tracked at Microsoft.

I searched but no result so I submitted it to MS: 
https://developercommunity.visualstudio.com/t/Possible-miscompilation-in-release-mode-/10453172


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159163

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


[PATCH] D159105: [analyzer] ArrayBoundCheckerV2 should check the region for taint as well

2023-08-30 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

I was thinking about adding an improvement like this for the sake of 
consistency, but I fear that this might cause a surprising amount of false 
positives. (Did you test it on larger codebases?)

As far as I understand (correct me if I'm wrong), there are situations when 
TaintChecker marks the memory region of e.g. a returned string as tainted to 
mark that the //contents// of the region are unreliable. (There may be other 
more exotic situations when even the //pointer value// or the //extent// 
becomes unreliable e.g. your testcases where you `scanf` into a pointer.)

I fear that the overzealous handling of tainted data would produce too many 
false positives in situations when code indexes strings that contain user input 
and the SA engine cannot understand the logic that calculates the indices. For 
example if I understand it correctly a function like

  char f(int n) {
char *var = getenv("FOO");
return var[n];
  }

would be reported as an out of bounds memory access, because the region is 
tainted and the index value is not known. This is especially problematic on the 
underflow side (which is introduced by your commit), because I'd assume that 
it's common to have numeric values (e.g. function arguments) where the 
programmer knows that they're nonnegative, but the analyzer cannot deduce this.

Also note that the error message "Out of bound memory access (index is 
tainted)" becomes misleading after this patch -- but don't spend too much time 
on resolving this, because right now I'm working on a complete rewrite the 
message generation to replace the current spartan messages with useful error 
reporting.




Comment at: clang/test/Analysis/taint-generic.c:1133-1141
+void testTaintedLowerConstrainedIndex() {
+  int n;
+  scanf("%d", &n);
+  if (n >= 0) {
+// We only constained the lower end, and it's tainted => report.
+Buffer[n] = 1; // expected-warning {{Out of bound memory access (index is 
tainted)}}
+  }

Also add the "opposite" of this where you test `if (n < BUFSIZE)`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159105

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


[PATCH] D156076: [PowerPC][Clang] Remove constraint for initial-exec TLS mode on AIX

2023-08-30 Thread ChenZheng via Phabricator via cfe-commits
shchenz accepted this revision as: shchenz.
shchenz added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156076

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


[PATCH] D159106: [analyzer] ArrayBoundCheckerV2 should listen to check::Bind as well

2023-08-30 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy accepted this revision.
donat.nagy added a comment.
This revision is now accepted and ready to land.

This seems to be a straightforward improvement over the current situation; LGTM 
if you test(ed) it on some real-life code (to ensure that it doesn't introduce 
a corner case that crashes).




Comment at: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp:46
 
+  void impl(SVal Loc, bool isLoad, const Stmt *S, CheckerContext &C) const;
+

I'd call this function `performCheck` or something similar, but "`impl`" is 
also fine especially if it's a traditional name (that I haven't encountered yet 
in clang SA code).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159106

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


[clang] 5b3f41c - [analyzer][NFC] Workaround miscompilation on recent MSVC

2023-08-30 Thread via cfe-commits

Author: dingfei
Date: 2023-08-30T17:14:38+08:00
New Revision: 5b3f41c55d9261dcb682d60a4258fa2c30fd50c8

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

LOG: [analyzer][NFC] Workaround miscompilation on recent MSVC

SVal argument 'Cond' passed in is corrupted in release mode with
exception handling enabled (result in an UndefinedSVal), or changing
lambda capture inside the callee can workaround this.

Known problematic VS Versions:
- VS 2022 17.4.4
- VS 2022 17.5.4
- VS 2022 17.7.2

Verified working VS Version:
- VS 2019 16.11.25

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

Reviewed By: steakhal

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
index 9ef3455a110a84..c0b3f346b654df 100644
--- a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -91,7 +91,7 @@ ConstraintManager::assumeDualImpl(ProgramStateRef &State,
 
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDual(ProgramStateRef State, DefinedSVal Cond) {
-  auto AssumeFun = [&](bool Assumption) {
+  auto AssumeFun = [&, Cond](bool Assumption) {
 return assumeInternal(State, Cond, Assumption);
   };
   return assumeDualImpl(State, AssumeFun);



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


[PATCH] D159163: [analyzer][NFC] Workaround miscompilation on recent MSVC

2023-08-30 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b3f41c55d92: [analyzer][NFC] Workaround miscompilation on 
recent MSVC (authored by dingfei ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159163

Files:
  clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp


Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -91,7 +91,7 @@
 
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDual(ProgramStateRef State, DefinedSVal Cond) {
-  auto AssumeFun = [&](bool Assumption) {
+  auto AssumeFun = [&, Cond](bool Assumption) {
 return assumeInternal(State, Cond, Assumption);
   };
   return assumeDualImpl(State, AssumeFun);


Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -91,7 +91,7 @@
 
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDual(ProgramStateRef State, DefinedSVal Cond) {
-  auto AssumeFun = [&](bool Assumption) {
+  auto AssumeFun = [&, Cond](bool Assumption) {
 return assumeInternal(State, Cond, Assumption);
   };
   return assumeDualImpl(State, AssumeFun);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159138: [clang][Sema] Fix format size estimator's handling of %o, %x, %X with alternative form

2023-08-30 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet marked an inline comment as done.
hazohelet added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:966
+// size. e.g.(("%#3x", 0xf) is "0xf")
+
+// If the result is zero, o, b, x, X adds nothing.

serge-sans-paille wrote:
> Then couldn't we increase the Size if the `FieldWidth` is unspecified?
We cannot, unless the formatted integer is known to be nonzero.
`("%#x", 0)` is `"0"` and not `"0x0"`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159138

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


[PATCH] D159105: [analyzer] ArrayBoundCheckerV2 should check the region for taint as well

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

In D159105#4627724 , @donat.nagy 
wrote:

> I was thinking about adding an improvement like this for the sake of 
> consistency, but I fear that this might cause a surprising amount of false 
> positives. (Did you test it on larger codebases?)

I'm just done backporting the first batch to our fork and scheduling a 
large-scale measurement.
But my gut instinct suggests there won't be too many new reports, as I believe 
"tainted" pointers shouldn't be really a thing, except for really exotic cases, 
like `scanf` a pointer - which is dubious at best in presence of ASLR.

> As far as I understand (correct me if I'm wrong), there are situations when 
> TaintChecker marks the memory region of e.g. a returned string as tainted to 
> mark that the //contents// of the region are unreliable. (There may be other 
> more exotic situations when even the //pointer value// or the //extent// 
> becomes unreliable e.g. your testcases where you `scanf` into a pointer.)

Taint can only bind to symbols, thus a memregion per-say cannot be tainted, 
only the "conjured address of it" or the "symbol bound to the 
pointee's/referred lvalue" can be tainted.
WDYM by "are unreliable" and "becomes unreliable"?

> I fear that the overzealous handling of tainted data would produce too many 
> false positives in situations when code indexes strings that contain user 
> input and the SA engine cannot understand the logic that calculates the 
> indices. For example if I understand it correctly a function like
>
>   char f(int n) {
> char *var = getenv("FOO");
> return var[n];
>   }
>
> would be reported as an out of bounds memory access, because the region is 
> tainted and the index value is not known. This is especially problematic on 
> the underflow side (which is introduced by your commit), because I'd assume 
> that it's common to have numeric values (e.g. function arguments) where the 
> programmer knows that they're nonnegative, but the analyzer cannot deduce 
> this.

To me, this is a TP. The envvar might not be present, and even if it's present, 
the relation of the string length of `var` to `n` is not expressed or checked; 
thus this deserves a report.
But I see your concern, however, I cannot think of valid counterexamples, aka. 
FPs off the top of my head. I'll come back once I see the real results.

> Also note that the error message "Out of bound memory access (index is 
> tainted)" becomes misleading after this patch -- but don't spend too much 
> time on resolving this, because right now I'm working on a complete rewrite 
> the message generation to replace the current spartan messages with useful 
> error reporting.

I agree, but I'm not sure how much more readable something more accurate like 
"the location where this pointer points to potentially depends on untrusted 
tainted data". (Note that this would also work for tainted indexes as well).

I must admit, that reporting and diagnostics were low priorities for this patch 
stack, so I'd focus on addressing logic concerns first for the whole stack and 
then come back to reporting to make it consistent across the stack.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159105

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


[PATCH] D159106: [analyzer] ArrayBoundCheckerV2 should listen to check::Bind as well

2023-08-30 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp:46
 
+  void impl(SVal Loc, bool isLoad, const Stmt *S, CheckerContext &C) const;
+

donat.nagy wrote:
> I'd call this function `performCheck` or something similar, but "`impl`" is 
> also fine especially if it's a traditional name (that I haven't encountered 
> yet in clang SA code).
Yes, I'll rename it. I was already thinking about it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159106

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


[PATCH] D158008: [AArch64] Add patterns for FMADD, FMSUB

2023-08-30 Thread OverMighty via Phabricator via cfe-commits
overmighty added a comment.

Ping.

If you would like the current patch with `extractelt` to be committed, please 
commit it as "OverMighty ". Thank you.


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

https://reviews.llvm.org/D158008

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


[PATCH] D159105: [analyzer] ArrayBoundCheckerV2 should check the region for taint as well

2023-08-30 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

In D159105#4627785 , @steakhal wrote:

> In D159105#4627724 , @donat.nagy 
> wrote:
>
>> I was thinking about adding an improvement like this for the sake of 
>> consistency, but I fear that this might cause a surprising amount of false 
>> positives. (Did you test it on larger codebases?)
>
> I'm just done backporting the first batch to our fork and scheduling a 
> large-scale measurement.
> But my gut instinct suggests there won't be too many new reports, as I 
> believe "tainted" pointers shouldn't be really a thing, except for really 
> exotic cases, like `scanf` a pointer - which is dubious at best in presence 
> of ASLR.
>
>> As far as I understand (correct me if I'm wrong), there are situations when 
>> TaintChecker marks the memory region of e.g. a returned string as tainted to 
>> mark that the //contents// of the region are unreliable. (There may be other 
>> more exotic situations when even the //pointer value// or the //extent// 
>> becomes unreliable e.g. your testcases where you `scanf` into a pointer.)
>
> Taint can only bind to symbols, thus a memregion per-say cannot be tainted, 
> only the "conjured address of it" or the "symbol bound to the 
> pointee's/referred lvalue" can be tainted.

Thanks for the clarification! As I dig deeper I see that the functions that 
look like "let's taint a MemRegion" are in fact only affecting 
`SymbolicRegion`s (targeting the corresponding symbol). This taint may be seen 
by the logic that checks the taintedness of the ElementRegion -- but as it's 
limited to symbolic regions it probably won't appear in the underflow test 
[which is skipped for symbolic regions //in unknown space//]. (There are also 
some calls which taint the pointee's/referred value -- that won't affect us.)

> WDYM by "are unreliable" and "becomes unreliable"?

"may be controlled by a malicious actor", basically a synonym of "tainted" but 
I used "tainted" for things that are marked as tainted by the SA code and 
"unreliable" for things that would be marked as tainted by an ideal algorithm.

>> I fear that the overzealous handling of tainted data would produce too many 
>> false positives in situations when code indexes strings that contain user 
>> input and the SA engine cannot understand the logic that calculates the 
>> indices. For example if I understand it correctly a function like
>>
>>   char f(int n) {
>> char *var = getenv("FOO");
>> return var[n];
>>   }
>>
>> would be reported as an out of bounds memory access, because the region is 
>> tainted and the index value is not known. This is especially problematic on 
>> the underflow side (which is introduced by your commit), because I'd assume 
>> that it's common to have numeric values (e.g. function arguments) where the 
>> programmer knows that they're nonnegative, but the analyzer cannot deduce 
>> this.
>
> To me, this is a TP. The envvar might not be present, and even if it's 
> present, the relation of the string length of `var` to `n` is not expressed 
> or checked; thus this deserves a report.
> But I see your concern, however, I cannot think of valid counterexamples, 
> aka. FPs off the top of my head. I'll come back once I see the real results.

Hmm, you're right that my example is a TP as written; however I could imagine 
similar FPs where we e.g. check that `n < strlen(var)` but don't check that `n` 
is nonnegative (because that's the responsibility of the caller).

Anyway, let's wait for the test results, they'll be enlightening. (You mostly 
convinced me that your commit will work, but Murphy's laws are still 
standing...)

>> Also note that the error message "Out of bound memory access (index is 
>> tainted)" becomes misleading after this patch -- but don't spend too much 
>> time on resolving this, because right now I'm working on a complete rewrite 
>> the message generation to replace the current spartan messages with useful 
>> error reporting.
>
> I agree, but I'm not sure how much more readable something more accurate like 
> "the location where this pointer points to potentially depends on untrusted 
> tainted data". (Note that this would also work for tainted indexes as well).
>
> I must admit, that reporting and diagnostics were low priorities for this 
> patch stack, so I'd focus on addressing logic concerns first for the whole 
> stack and then come back to reporting to make it consistent across the stack.

Improving reporting and diagnostics is also on my TODO list, so we should 
coordinate progress in that area to avoid redundant work. If you wish to work 
on it, then I'm happy to review; otherwise I'll do something with it soon 
(perhaps after you merged these commits to avoid merge conflicts).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159105

__

[PATCH] D159107: [analyzer] ArrayBoundCheckerV2 should disallow forming lvalues to out-of-bounds locations

2023-08-30 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

Good direction of development, this will be useful for providing better bug 
reports (in addition to ensuring correct behavior some situations).

Note that it's also possible to dereference pointers with the operator `->`, 
which is represented by `MemberExpr`s in the AST; we should probably handle 
that as if it was a `UO_Deref`.

There is also a small corner case that for an array `some_type arr[N]` it's 
well-defined to form the past-the-end pointer as `&arr[N]` (instead of `arr + 
N`) -- while any other use of `arr[N]` is undefined behavior. If this occurs in 
practice, then we'll probably need some additional logic to handle it. (Note 
that the `check::Location` implementation dodged this question, because it 
didn't report anything when the program formed `&arr[N]`, but later created a 
bug report when this pointer value was dereferenced.)




Comment at: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp:34
+class ArrayBoundCheckerV2
+: public Checker,
+ check::PostStmt> {

Which testcase would break without the `check::Bind` callback? (Not action 
needed, I'm just curious.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159107

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


[PATCH] D159109: [analyzer] CStringChecker buffer access checks should check the first bytes

2023-08-30 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy accepted this revision.
donat.nagy added a comment.
This revision is now accepted and ready to land.

LGTM if the test results are also good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159109

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


[PATCH] D159108: [analyzer] CStringChecker should check the first byte of the destination of strcpy, strncpy

2023-08-30 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy accepted this revision.
donat.nagy added a comment.
This revision is now accepted and ready to land.

LGTM if the test results are good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159108

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


[clang] 38c92c1 - [AArch64] Add patterns for FMADD, FMSUB

2023-08-30 Thread Vladislav Dzhidzhoev via cfe-commits

Author: OverMighty
Date: 2023-08-30T12:39:04+02:00
New Revision: 38c92c1ee2f07e3260c94d51834a97e84f93c708

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

LOG: [AArch64] Add patterns for FMADD, FMSUB

FMADD, FMSUB instructions perform better or the same compared to indexed
FMLA, FMLS.

For example, the Arm Cortex-A55 Software Optimization Guide lists "FP
multiply accumulate" FMADD, FMSUB instructions with a throughput of 2
IPC, whereas it lists "ASIMD FP multiply accumulate, by element" FMLA,
FMLS with a throughput of 1 IPC.

The Arm Cortex-A77 Software Optimization Guide, however, does not
separately list "by element" variants of the "ASIMD FP multiply
accumulate" instructions, which are listed with the same throughput of 2
IPC as "FP multiply accumulate" instructions.

Reviewed By: samtebbs, dzhidzhoev

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

Added: 


Modified: 
clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
llvm/lib/Target/AArch64/AArch64InstrFormats.td
llvm/test/CodeGen/AArch64/complex-deinterleaving-f16-mul.ll
llvm/test/CodeGen/AArch64/fp16_intrinsic_lane.ll
llvm/test/CodeGen/AArch64/neon-scalar-by-elem-fma.ll

Removed: 




diff  --git 
a/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c 
b/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
index 6371339f0a40dd..1d0db697e4fddd 100644
--- a/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
+++ b/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
@@ -103,7 +103,7 @@ float64x1_t test_vfms_lane_f64(float64x1_t a, float64x1_t 
b, float64x1_t v) {
 // COMMONIR:[[EXTRACT:%.*]] = extractelement <2 x double> [[TMP5]], 
i32 0
 // UNCONSTRAINED:   [[TMP6:%.*]] = call double @llvm.fma.f64(double [[TMP4]], 
double [[EXTRACT]], double [[TMP3]])
 // CONSTRAINED: [[TMP6:%.*]] = call double 
@llvm.experimental.constrained.fma.f64(double [[TMP4]], double [[EXTRACT]], 
double [[TMP3]], metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM:   fmla d{{[0-9]+}}, d{{[0-9]+}}, v{{[0-9]+}}.d[{{[0-9]+}}]
+// CHECK-ASM:   fmadd d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}
 // COMMONIR:[[TMP7:%.*]] = bitcast double [[TMP6]] to <1 x double>
 // COMMONIR:ret <1 x double> [[TMP7]]
 float64x1_t test_vfma_laneq_f64(float64x1_t a, float64x1_t b, float64x2_t v) {
@@ -122,7 +122,7 @@ float64x1_t test_vfma_laneq_f64(float64x1_t a, float64x1_t 
b, float64x2_t v) {
 // COMMONIR:[[EXTRACT:%.*]] = extractelement <2 x double> [[TMP5]], 
i32 0
 // UNCONSTRAINED:   [[TMP6:%.*]] = call double @llvm.fma.f64(double [[TMP4]], 
double [[EXTRACT]], double [[TMP3]])
 // CONSTRAINED: [[TMP6:%.*]] = call double 
@llvm.experimental.constrained.fma.f64(double [[TMP4]], double [[EXTRACT]], 
double [[TMP3]], metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM:   fmla d{{[0-9]+}}, d{{[0-9]+}}, v{{[0-9]+}}.d[{{[0-9]+}}]
+// CHECK-ASM:   fmadd d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}
 // COMMONIR:[[TMP7:%.*]] = bitcast double [[TMP6]] to <1 x double>
 // COMMONIR:ret <1 x double> [[TMP7]]
 float64x1_t test_vfms_laneq_f64(float64x1_t a, float64x1_t b, float64x2_t v) {

diff  --git a/llvm/lib/Target/AArch64/AArch64InstrFormats.td 
b/llvm/lib/Target/AArch64/AArch64InstrFormats.td
index 885b70a50121f3..57d69ae05c47ff 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrFormats.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrFormats.td
@@ -5409,6 +5409,44 @@ multiclass ThreeOperandFPData {
 let Inst{23-22} = 0b01; // 64-bit size flag
   }
+
+  let Predicates = [HasFullFP16] in {
+  def : Pat<(f16 (node (f16 FPR16:$Rn),
+   (f16 (extractelt (v8f16 V128:$Rm), (i64 0))),
+   (f16 FPR16:$Ra))),
+(!cast(NAME # Hrrr)
+  FPR16:$Rn, (f16 (EXTRACT_SUBREG V128:$Rm, hsub)), FPR16:$Ra)>;
+
+  def : Pat<(f16 (node (f16 (extractelt (v8f16 V128:$Rn), (i64 0))),
+   (f16 FPR16:$Rm),
+   (f16 FPR16:$Ra))),
+(!cast(NAME # Hrrr)
+  (f16 (EXTRACT_SUBREG V128:$Rn, hsub)), FPR16:$Rm, FPR16:$Ra)>;
+  }
+
+  def : Pat<(f32 (node (f32 FPR32:$Rn),
+   (f32 (extractelt (v4f32 V128:$Rm), (i64 0))),
+   (f32 FPR32:$Ra))),
+(!cast(NAME # Srrr)
+  FPR32:$Rn, (EXTRACT_SUBREG V128:$Rm, ssub), FPR32:$Ra)>;
+
+  def : Pat<(f32 (node (f32 (extractelt (v4f32 V128:$Rn), (i64 0))),
+   (f32 FPR32:$Rm),
+   (f32 FPR32:$Ra))),
+(!cast(NAME # Srrr)
+  (EXTRACT_SUBREG V128:$Rn, ssub), FPR32:$Rm, FPR32:$Ra)>;
+
+  def : Pat<(f64 (nod

[PATCH] D158008: [AArch64] Add patterns for FMADD, FMSUB

2023-08-30 Thread Vladislav Dzhidzhoev 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 rG38c92c1ee2f0: [AArch64] Add patterns for FMADD, FMSUB 
(authored by overmighty, committed by dzhidzhoev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158008

Files:
  clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/test/CodeGen/AArch64/complex-deinterleaving-f16-mul.ll
  llvm/test/CodeGen/AArch64/fp16_intrinsic_lane.ll
  llvm/test/CodeGen/AArch64/neon-scalar-by-elem-fma.ll

Index: llvm/test/CodeGen/AArch64/neon-scalar-by-elem-fma.ll
===
--- llvm/test/CodeGen/AArch64/neon-scalar-by-elem-fma.ll
+++ llvm/test/CodeGen/AArch64/neon-scalar-by-elem-fma.ll
@@ -7,56 +7,132 @@
 declare float @llvm.experimental.constrained.fma.f32(float, float, float, metadata, metadata)
 declare double @llvm.experimental.constrained.fma.f64(double, double, double, metadata, metadata)
 
-define float @test_fmla_ss4S(float %a, float %b, <4 x float> %v) {
-  ; CHECK-LABEL: test_fmla_ss4S
+define float @test_fmla_ss4S_0(float %a, float %b, <4 x float> %v) {
+  ; CHECK-LABEL: test_fmla_ss4S_0
+  ; CHECK: fmadd s0, s1, s2, s0
+  %tmp1 = extractelement <4 x float> %v, i32 0
+  %tmp2 = call float @llvm.fma.f32(float %b, float %tmp1, float %a)
+  ret float %tmp2
+}
+
+define float @test_fmla_ss4S_0_swap(float %a, float %b, <4 x float> %v) {
+  ; CHECK-LABEL: test_fmla_ss4S_0_swap
+  ; CHECK: fmadd s0, s2, s1, s0
+  %tmp1 = extractelement <4 x float> %v, i32 0
+  %tmp2 = call float @llvm.fma.f32(float %tmp1, float %b, float %a)
+  ret float %tmp2
+}
+
+define float @test_fmla_ss4S_3(float %a, float %b, <4 x float> %v) {
+  ; CHECK-LABEL: test_fmla_ss4S_3
   ; CHECK: fmla {{s[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}.s[3]
   %tmp1 = extractelement <4 x float> %v, i32 3
   %tmp2 = call float @llvm.fma.f32(float %b, float %tmp1, float %a)
   ret float %tmp2
 }
 
-define float @test_fmla_ss4S_swap(float %a, float %b, <4 x float> %v) {
-  ; CHECK-LABEL: test_fmla_ss4S_swap
+define float @test_fmla_ss4S_3_swap(float %a, float %b, <4 x float> %v) {
+  ; CHECK-LABEL: test_fmla_ss4S_3_swap
   ; CHECK: fmla {{s[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}.s[3]
   %tmp1 = extractelement <4 x float> %v, i32 3
   %tmp2 = call float @llvm.fma.f32(float %tmp1, float %a, float %a)
   ret float %tmp2
 }
 
-define float @test_fmla_ss2S(float %a, float %b, <2 x float> %v) {
-  ; CHECK-LABEL: test_fmla_ss2S
+define float @test_fmla_ss2S_0(float %a, float %b, <2 x float> %v) {
+  ; CHECK-LABEL: test_fmla_ss2S_0
+  ; CHECK: fmadd s0, s1, s2, s0
+  %tmp1 = extractelement <2 x float> %v, i32 0
+  %tmp2 = call float @llvm.fma.f32(float %b, float %tmp1, float %a)
+  ret float %tmp2
+}
+
+define float @test_fmla_ss2S_0_swap(float %a, float %b, <2 x float> %v) {
+  ; CHECK-LABEL: test_fmla_ss2S_0_swap
+  ; CHECK: fmadd s0, s2, s1, s0
+  %tmp1 = extractelement <2 x float> %v, i32 0
+  %tmp2 = call float @llvm.fma.f32(float %tmp1, float %b, float %a)
+  ret float %tmp2
+}
+
+define float @test_fmla_ss2S_1(float %a, float %b, <2 x float> %v) {
+  ; CHECK-LABEL: test_fmla_ss2S_1
   ; CHECK: fmla {{s[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}.s[1]
   %tmp1 = extractelement <2 x float> %v, i32 1
   %tmp2 = call float @llvm.fma.f32(float %b, float %tmp1, float %a)
   ret float %tmp2
 }
 
-define double @test_fmla_ddD(double %a, double %b, <1 x double> %v) {
-  ; CHECK-LABEL: test_fmla_ddD
-  ; CHECK: {{fmla d[0-9]+, d[0-9]+, v[0-9]+.d\[0]|fmadd d[0-9]+, d[0-9]+, d[0-9]+, d[0-9]+}}
+define double @test_fmla_ddD_0(double %a, double %b, <1 x double> %v) {
+  ; CHECK-LABEL: test_fmla_ddD_0
+  ; CHECK: fmadd d0, d1, d2, d0
   %tmp1 = extractelement <1 x double> %v, i32 0
   %tmp2 = call double @llvm.fma.f64(double %b, double %tmp1, double %a)
   ret double %tmp2
 }
 
-define double @test_fmla_dd2D(double %a, double %b, <2 x double> %v) {
-  ; CHECK-LABEL: test_fmla_dd2D
+define double @test_fmla_ddD_0_swap(double %a, double %b, <1 x double> %v) {
+  ; CHECK-LABEL: test_fmla_ddD_0_swap
+  ; CHECK: fmadd d0, d2, d1, d0
+  %tmp1 = extractelement <1 x double> %v, i32 0
+  %tmp2 = call double @llvm.fma.f64(double %tmp1, double %b, double %a)
+  ret double %tmp2
+}
+
+define double @test_fmla_dd2D_0(double %a, double %b, <2 x double> %v) {
+  ; CHECK-LABEL: test_fmla_dd2D_0
+  ; CHECK: fmadd d0, d1, d2, d0
+  %tmp1 = extractelement <2 x double> %v, i32 0
+  %tmp2 = call double @llvm.fma.f64(double %b, double %tmp1, double %a)
+  ret double %tmp2
+}
+
+define double @test_fmla_dd2D_0_swap(double %a, double %b, <2 x double> %v) {
+  ; CHECK-LABEL: test_fmla_dd2D_0_swap
+  ; CHECK: fmadd d0, d2, d1, d0
+  %tmp1 = extractelement <2 x double> %v, i32 0
+  %tmp2 = call double @llvm.fma.f64(double %tmp1, double %b, double %a)
+  ret double %tmp2
+}
+

[PATCH] D155858: Add a concept AST node.

2023-08-30 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 554660.
massberg marked 3 inline comments as done.
massberg added a comment.

Resolve remaining comments.

- Added tests for new location functions of `ConceptReference`. There is an 
existing bug with the end location if there are no template arguments. As it is 
an existing bug I have added a FIXME which will be fixed in a follow up patch.
- Additional minor changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155858

Files:
  clang/include/clang/AST/ASTConcept.h
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/ExprConcepts.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TypeLoc.h
  clang/include/clang/Serialization/ASTRecordReader.h
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/ExprConcepts.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/unittests/AST/SourceLocationTest.cpp
  clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp

Index: clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp
===
--- clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp
@@ -29,12 +29,22 @@
 ++ConceptRequirementsTraversed;
 return ExpectedLocationVisitor::TraverseConceptRequirement(R);
   }
+  bool TraverseConceptReference(ConceptReference *CR) {
+++ConceptReferencesTraversed;
+return ExpectedLocationVisitor::TraverseConceptReference(CR);
+  }
+  bool VisitConceptReference(ConceptReference *CR) {
+++ConceptReferencesVisited;
+return true;
+  }
 
   bool shouldVisitImplicitCode() { return ShouldVisitImplicitCode; }
 
   int ConceptSpecializationExprsVisited = 0;
   int TypeConstraintsTraversed = 0;
   int ConceptRequirementsTraversed = 0;
+  int ConceptReferencesTraversed = 0;
+  int ConceptReferencesVisited = 0;
   bool ShouldVisitImplicitCode = false;
 };
 
@@ -50,6 +60,8 @@
   EXPECT_EQ(1, Visitor.ConceptSpecializationExprsVisited);
   // Also check we traversed the TypeConstraint that produced the expr.
   EXPECT_EQ(1, Visitor.TypeConstraintsTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesVisited);
 
   Visitor = {}; // Don't visit implicit code now.
   EXPECT_TRUE(Visitor.runOver("template  concept Fooable = true;\n"
@@ -59,6 +71,8 @@
   // generated immediately declared expression.
   EXPECT_EQ(0, Visitor.ConceptSpecializationExprsVisited);
   EXPECT_EQ(1, Visitor.TypeConstraintsTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesVisited);
 
   Visitor = {};
   EXPECT_TRUE(Visitor.runOver("template  concept A = true;\n"
@@ -70,6 +84,8 @@
   "};",
   ConceptVisitor::Lang_CXX2a));
   EXPECT_EQ(3, Visitor.ConceptRequirementsTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesVisited);
 }
 
 struct VisitDeclOnlyOnce : ExpectedLocationVisitor {
@@ -86,6 +102,10 @@
 ++AutoTypeLocVisited;
 return true;
   }
+  bool VisitConceptReference(ConceptReference *) {
+++ConceptReferencesVisited;
+return true;
+  }
 
   bool TraverseVarDecl(VarDecl *V) {
 // The base traversal visits only the `TypeLoc`.
@@ -99,6 +119,7 @@
   int ConceptDeclsVisited = 0;
   int AutoTypeVisited = 0;
   int AutoTypeLocVisited = 0;
+  int ConceptReferencesVisited = 0;
 };
 
 TEST(RecursiveASTVisitor, ConceptDeclInAutoType) {
@@ -111,6 +132,7 @@
   EXPECT_EQ(1, Visitor.AutoTypeVisited);
   EXPECT_EQ(1, Visitor.AutoTypeLocVisited);
   EXPECT_EQ(1, Visitor.ConceptDeclsVisited);
+  EXPECT_EQ(1, Visitor.ConceptReferencesVisited);
 }
 
 } // end anonymous namespace
Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -16,7 +16,11 @@
 //===--===//
 
 #include "MatchVerifier.h"
+#include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTFwd.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprConcepts.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Too

[PATCH] D155858: Add a concept AST node.

2023-08-30 Thread Jens Massberg via Phabricator via cfe-commits
massberg added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:6824-6836
+  unsigned size = TL.getTypePtr()->getTypeConstraintArguments().size();
+  TemplateArgumentLocInfo *TALI = new TemplateArgumentLocInfo[size];
+  TemplateSpecializationTypeLoc::initializeArgLocs(
+  SemaRef.Context, TL.getTypePtr()->getTypeConstraintArguments(), TALI,
+  SourceLocation());
+  TemplateArgumentLoc *TAL = new TemplateArgumentLoc[size];
+  for (unsigned i = 0; i < size; ++i)

sammccall wrote:
> massberg wrote:
> > This is very ugly as I have to create the TALI and TAL arrays temporarily 
> > to use the existing transformations.
> > Is there a better way to do that?
> > Moreover, is this the correct place for the transformation? This is 
> > necessary as the passed `AutoTypeLoc` doesn't have an attached 
> > `ConceptReference` even if it is constrained. Has the `ConceptReferenec`of 
> > the original `AutoTypeLoc` be added somewhere earlier?
> If I'm understanding the situation right...
> the AutoTypeLoc in the template should have a ConceptReference, since the 
> `auto` is constrained.
> This seems like a bug to be fixed elsewhere, and then this `else` becomes 
> dead.
> 
> Do you have a minimal example?
A minimal example:

```
template  concept C = true;

template
void foo2() {}

int main(void) {
  foo2<1>();
}
```

As discussed, a `ConceptReference` will now be created in `initializeLocal` so 
that it is guaranteed that we have it available here. I have added an assert to 
verify that there is an `ConceptReference` in case that the `AutoType` is 
constrained.
If we do not set the `ConceptReference` in `initializeLocal` then there are 
already several tests that fail as the `assert` isn't satisifed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155858

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


[PATCH] D153690: [clang][Sema] Remove dead diagnostic for loss of __unaligned qualifier

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

In D153690#4624726 , 
@michael-jabbour-sonarsource wrote:

> The removal of the early return in this patch causes a crash when parsing the 
> following example:
>
>   struct S {
> bool operator==(int) const;
>   };
>   
>   void func() {
> S __unaligned s;
> s == 42;
>   }
>
> See this Compiler Explorer link with a stacktrace: 
> https://godbolt.org/z/n9vscYoYa.
>
> Maybe we want to avoid the call to `DiagnoseBadConversion` here? I think that 
> we don't want `OverloadCandidateSet::BestViableFunction` (called in 
> `Sema::CreateOverloadedBinOp`) to return `OR_No_Viable_Function` in this case?

Thank you for the report and reproducer!
@rnk This reproducer code should be accepted for clang to be aligned with 
msvc's behavior, correct?

About the fix, there's probably some code that makes a candidate that loses 
const qualifier invalid, and the __unaligned is likely to be handled in the 
same place. (I haven't checked the code, so may be off base)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153690

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


[PATCH] D158614: [UBSan] Disable the function sanitizer on an execute-only target.

2023-08-30 Thread Ying Yi via Phabricator via cfe-commits
MaggieYi updated this revision to Diff 554665.
MaggieYi marked 5 inline comments as done.
MaggieYi added a comment.

Thanks @MaskRay. The patch is updated.

Hi @simon_tatham, are you happy with the patch?

Thanks


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

https://reviews.llvm.org/D158614

Files:
  clang/include/clang/Basic/Sanitizers.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Sanitizers.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGenObjCXX/crash-function-type.mm
  clang/test/Driver/fsanitize.c

Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -966,3 +966,17 @@
 
 // RUN: not %clang --target=x86_64-linux-gnu -fsanitize=undefined,function -mcmodel=large %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-CODE-MODEL
 // CHECK-UBSAN-FUNCTION-CODE-MODEL: error: invalid argument '-fsanitize=function' only allowed with '-mcmodel=small'
+
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=undefined -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function -fsanitize=kcfi %s -### 2>&1 | FileCheck %s  --check-prefix=CHECK-UBSAN-KCFI --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: %clang --target=x86_64-sie-ps5 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
+
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
+// RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
+
+// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-UNDEFINED: "-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound),?){17}"}}
Index: clang/test/CodeGenObjCXX/crash-function-type.mm
===
--- clang/test/CodeGenObjCXX/crash-function-type.mm
+++ clang/test/CodeGenObjCXX/crash-function-type.mm
@@ -1,3 +1,6 @@
+// Mark test as unsupported on PS5 due to PS5 doesn't support function sanitizer.
+// UNSUPPORTED: target=x86_64-sie-ps5
+
 // RUN: %clang_cc1 -fblocks -fsanitize=function -emit-llvm %s -o %t
 
 void g(void (^)());
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -37,6 +37,8 @@
 SanitizerKind::Vptr | SanitizerKind::CFI;
 static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
 static const SanitizerMask NotAllowedWithMinimalRuntime = SanitizerKind::Vptr;
+static const SanitizerMask NotAllowedWithExecuteOnly =
+SanitizerKind::Function | SanitizerKind::KCFI;
 static const SanitizerMask RequiresPIE =
 SanitizerKind::DataFlow | SanitizerKind::Scudo;
 static const SanitizerMask NeedsUnwindTables =
@@ -395,6 +397,22 @@
   DiagnosedKinds |= SanitizerKind::Function;
 }
   }
+  // -fsanitize=function and -fsanitize=kcfi instrument indirect function
+  // calls to load a type hash before the function label. Therefore, an
+  // execute-only target doesn't support the function and kcfi sanitizers.
+  const llvm::Triple &Triple = TC.getTriple();
+  if (isExecuteOnlyTarget(Triple, Args)) {
+if (SanitizerMask KindsToDiagnose =
+Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) {
+  if (DiagnoseErrors) {
+std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
+D.Diag(diag::err_drv_argument_not_allowed_with)
+<< Desc << Triple.str();
+  }
+  DiagnosedKinds |= KindsToDiagnose;
+}
+Add &= ~NotAllowedWithExecuteOnly;
+  }
 
   // FIXME: Make CFI on member function calls compatible with cross-DSO CFI.
   // There are currently two problems:
@@ -457,6 +475,10 @@
   if (MinimalRuntime) {
 Add &= ~NotAllowedWithMinimalRuntime;
   }
+  // NotAllowedWithExecuteOnly is silently discar

[PATCH] D159051: [clang-format][NFC] Change EXPECT_EQ to verifyFormat or verifyNoChang

2023-08-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

+1 to this before we goto github


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159051

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


[clang] 9939556 - [APINotes] Initial support for C++ namespaces

2023-08-30 Thread Egor Zhdan via cfe-commits

Author: Egor Zhdan
Date: 2023-08-30T12:54:42+01:00
New Revision: 9939556625548d7ba2c3eba4d131b9b4d6bc0c02

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

LOG: [APINotes] Initial support for C++ namespaces

This upstreams a part of the C++ namespaces support in Clang API Notes.

The complete patch was recently merged downstream in the Apple fork: 
https://github.com/apple/llvm-project/pull/7230.

This patch only adds the parts of the namespace support that can be cleanly 
applied on top of the API Notes infrastructure that was upstreamed previously.

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

Added: 


Modified: 
clang/include/clang/APINotes/Types.h
clang/lib/APINotes/APINotesFormat.h
clang/lib/APINotes/APINotesWriter.cpp
clang/lib/APINotes/APINotesYAMLCompiler.cpp

Removed: 




diff  --git a/clang/include/clang/APINotes/Types.h 
b/clang/include/clang/APINotes/Types.h
index 61f3592ea145b8..817d6ac1bb3fe8 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -727,6 +727,28 @@ inline bool operator==(const TypedefInfo &LHS, const 
TypedefInfo &RHS) {
 inline bool operator!=(const TypedefInfo &LHS, const TypedefInfo &RHS) {
   return !(LHS == RHS);
 }
+
+/// Opaque context ID used to refer to an Objective-C class or protocol or a 
C++
+/// namespace.
+class ContextID {
+public:
+  unsigned Value;
+
+  explicit ContextID(unsigned value) : Value(value) {}
+};
+
+enum class ContextKind : uint8_t {
+  ObjCClass = 0,
+  ObjCProtocol = 1,
+  Namespace = 2,
+};
+
+struct Context {
+  ContextID id;
+  ContextKind kind;
+
+  Context(ContextID id, ContextKind kind) : id(id), kind(kind) {}
+};
 } // namespace api_notes
 } // namespace clang
 

diff  --git a/clang/lib/APINotes/APINotesFormat.h 
b/clang/lib/APINotes/APINotesFormat.h
index e18ba2ab337699..1e960773074e26 100644
--- a/clang/lib/APINotes/APINotesFormat.h
+++ b/clang/lib/APINotes/APINotesFormat.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H
 #define LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H
 
+#include "clang/APINotes/Types.h"
 #include "llvm/ADT/PointerEmbeddedInt.h"
 #include "llvm/Bitcode/BitcodeConvenience.h"
 
@@ -249,6 +250,38 @@ struct StoredObjCSelector {
   unsigned NumPieces;
   llvm::SmallVector Identifiers;
 };
+
+/// A stored Objective-C or C++ context, represented by the ID of its parent
+/// context, the kind of this context (Objective-C class / C++ namespace / 
etc),
+/// and the ID of this context.
+struct ContextTableKey {
+  uint32_t parentContextID;
+  uint8_t contextKind;
+  uint32_t contextID;
+
+  ContextTableKey() : parentContextID(-1), contextKind(-1), contextID(-1) {}
+
+  ContextTableKey(uint32_t parentContextID, uint8_t contextKind,
+  uint32_t contextID)
+  : parentContextID(parentContextID), contextKind(contextKind),
+contextID(contextID) {}
+
+  ContextTableKey(std::optional context, IdentifierID nameID)
+  : parentContextID(context ? context->id.Value : (uint32_t)-1),
+contextKind(context ? (uint8_t)context->kind : (uint8_t)-1),
+contextID(nameID) {}
+
+  llvm::hash_code hashValue() const {
+return llvm::hash_value(
+std::tuple{parentContextID, contextKind, contextID});
+  }
+};
+
+inline bool operator==(const ContextTableKey &lhs, const ContextTableKey &rhs) 
{
+  return lhs.parentContextID == rhs.parentContextID &&
+ lhs.contextKind == rhs.contextKind && lhs.contextID == rhs.contextID;
+}
+
 } // namespace api_notes
 } // namespace clang
 
@@ -282,6 +315,28 @@ template <> struct 
DenseMapInfo {
 return LHS.NumPieces == RHS.NumPieces && LHS.Identifiers == 
RHS.Identifiers;
   }
 };
+
+template <> struct DenseMapInfo {
+  static inline clang::api_notes::ContextTableKey getEmptyKey() {
+return clang::api_notes::ContextTableKey();
+  }
+
+  static inline clang::api_notes::ContextTableKey getTombstoneKey() {
+return clang::api_notes::ContextTableKey{
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey()};
+  }
+
+  static unsigned getHashValue(const clang::api_notes::ContextTableKey &value) 
{
+return value.hashValue();
+  }
+
+  static bool isEqual(const clang::api_notes::ContextTableKey &lhs,
+  const clang::api_notes::ContextTableKey &rhs) {
+return lhs == rhs;
+  }
+};
 } // namespace llvm
 
 #endif

diff  --git a/clang/lib/APINotes/APINotesWriter.cpp 
b/clang/lib/APINotes/APINotesWriter.cpp
index 3f2454c47df3b9..f357af90f949c8 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -33,15 +33,21 @@ class APINotesWriter::Implementation {
   /// Mapping from strings to identifier IDs.
   llvm::St

[PATCH] D159092: [APINotes] Initial support for C++ namespaces

2023-08-30 Thread Egor Zhdan 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 rG993955662554: [APINotes] Initial support for C++ namespaces 
(authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159092

Files:
  clang/include/clang/APINotes/Types.h
  clang/lib/APINotes/APINotesFormat.h
  clang/lib/APINotes/APINotesWriter.cpp
  clang/lib/APINotes/APINotesYAMLCompiler.cpp

Index: clang/lib/APINotes/APINotesYAMLCompiler.cpp
===
--- clang/lib/APINotes/APINotesYAMLCompiler.cpp
+++ clang/lib/APINotes/APINotesYAMLCompiler.cpp
@@ -495,6 +495,9 @@
 } // namespace llvm
 
 namespace {
+struct Namespace;
+typedef std::vector NamespacesSeq;
+
 struct TopLevelItems {
   ClassesSeq Classes;
   ClassesSeq Protocols;
@@ -503,6 +506,7 @@
   EnumConstantsSeq EnumConstants;
   TagsSeq Tags;
   TypedefsSeq Typedefs;
+  NamespacesSeq Namespaces;
 };
 } // namespace
 
@@ -516,10 +520,39 @@
   IO.mapOptional("Enumerators", TLI.EnumConstants);
   IO.mapOptional("Tags", TLI.Tags);
   IO.mapOptional("Typedefs", TLI.Typedefs);
+  IO.mapOptional("Namespaces", TLI.Namespaces);
 }
 } // namespace yaml
 } // namespace llvm
 
+namespace {
+struct Namespace {
+  StringRef Name;
+  AvailabilityItem Availability;
+  StringRef SwiftName;
+  std::optional SwiftPrivate;
+  TopLevelItems Items;
+};
+} // namespace
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(Namespace)
+
+namespace llvm {
+namespace yaml {
+template <> struct MappingTraits {
+  static void mapping(IO &IO, Namespace &T) {
+IO.mapRequired("Name", T.Name);
+IO.mapOptional("Availability", T.Availability.Mode,
+   APIAvailability::Available);
+IO.mapOptional("AvailabilityMsg", T.Availability.Msg, StringRef(""));
+IO.mapOptional("SwiftPrivate", T.SwiftPrivate);
+IO.mapOptional("SwiftName", T.SwiftName, StringRef(""));
+mapTopLevelItems(IO, T.Items);
+  }
+};
+} // namespace yaml
+} // namespace llvm
+
 namespace {
 struct Versioned {
   VersionTuple Version;
Index: clang/lib/APINotes/APINotesWriter.cpp
===
--- clang/lib/APINotes/APINotesWriter.cpp
+++ clang/lib/APINotes/APINotesWriter.cpp
@@ -33,15 +33,21 @@
   /// Mapping from strings to identifier IDs.
   llvm::StringMap IdentifierIDs;
 
-  /// Information about Objective-C contexts (classes or protocols).
+  /// Information about contexts (Objective-C classes or protocols or C++
+  /// namespaces).
   ///
-  /// Indexed by the identifier ID and a bit indication whether we're looking
-  /// for a class (0) or protocol (1) and provides both the context ID and
-  /// information describing the context within that module.
-  llvm::DenseMap,
+  /// Indexed by the parent context ID, context kind and the identifier ID of
+  /// this context and provides both the context ID and information describing
+  /// the context within that module.
+  llvm::DenseMap>>
   ObjCContexts;
 
+  /// Information about parent contexts for each context.
+  ///
+  /// Indexed by context ID, provides the parent context ID.
+  llvm::DenseMap ParentContexts;
+
   /// Information about Objective-C properties.
   ///
   /// Indexed by the context ID, property name, and whether this is an
@@ -64,16 +70,18 @@
 
   /// Information about global variables.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
+  /// Indexed by the context ID, contextKind, identifier ID.
+  llvm::DenseMap<
+  ContextTableKey,
+  llvm::SmallVector, 1>>
   GlobalVariables;
 
   /// Information about global functions.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
+  /// Indexed by the context ID, contextKind, identifier ID.
+  llvm::DenseMap<
+  ContextTableKey,
+  llvm::SmallVector, 1>>
   GlobalFunctions;
 
   /// Information about enumerators.
@@ -85,15 +93,15 @@
 
   /// Information about tags.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
   Tags;
 
   /// Information about typedefs.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
   Typedefs;
 
@@ -292,7 +300,7 @@
 /// Used to serialize the on-disk Objective-C context table.
 class ObjCContextIDTableInfo {
 public:
-  using key_type = std::pair; // identifier ID, is-protocol
+  using key_type = ContextTableKey;
   using key_type_ref = key_type;
   using data_type = unsigned;
   using data_type_ref = const data_type &;
@@ -300,12 +308,12 @@
   using offset_type = unsigned;
 
   hash_value_type ComputeHash(key_type_ref Key) {
-return static_cast(llvm::hash_value(Key));
+return static_cast(Key.hashValue());
   }
 
   std::pair EmitKeyDataLength(raw_ostream &OS, key_type_ref,
   data_type_ref) {
-uint32_t KeyLength = sizeof(uint32_t) + 1;
+uint3

[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-08-30 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: openmp/runtime/test/target/target_thread_limit.cpp:28
+// OMP51: target: parallel
+// OMP51: target: parallel
+// OMP51-NOT: target: parallel

This test fails when running (on Windows) on GitHub Actions runners - see 
https://github.com/mstorsjo/llvm-mingw/actions/runs/6019088705/job/16342540379.

I believe that this bit of the test has got a hidden assumption that it is 
running in an environment with 4 or more cores. By setting `#pragma omp target 
thread_limit(tl)` (with `tl=4`) and running a line in parallel with `#pragma 
omp parallel`, it expects that we'll get 4 printouts - while in practice, we'll 
get anywhere between 1 and 4 printouts depending on the number of cores.

Is there something that can be done to make this test work in such an 
environment too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-30 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 added a comment.

@xgupta the build is successful now. Earlier it failed due to format issues.


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

https://reviews.llvm.org/D158540

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


[PATCH] D158614: [UBSan] Disable the function sanitizer on an execute-only target.

2023-08-30 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham accepted this revision.
simon_tatham added a comment.

Yes, this looks good to me too. Thanks!


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

https://reviews.llvm.org/D158614

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


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:7808-7809
+if (!MD->isConsteval()) {
+  Diag(MD->getBeginLoc(), diag::note_incorrect_defaulted_constexpr)
+  << RD << MD;
+}

I'm not certain I understand how this note helps users -- the note is always 
attached to the instance method being defaulted, so it will always appear where 
the class context is obvious. e.g.,
```
struct S {
  constexpr S() = default; // Can quickly tell we're in class S
  constexpr S(const S&);
};

constexpr S::S(const S&) = default; // Can still quickly tell we're in class S
```
Do you have some code examples where this note helps clarify in ways I'm not 
seeing from the test coverage?


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

https://reviews.llvm.org/D158540

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


[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-08-30 Thread Mikhail Goncharov via Phabricator via cfe-commits
goncharov added a comment.

there is a number of unused vaiables in conditional loops there are firing now, 
I have submitted  
https://github.com/llvm/llvm-project/commit/74f4daef0412be33002bd4e24a30cb47d0187ecf
 but I suspect it's just a start.
How did you checked the project code for that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152495

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


[PATCH] D158967: [clang][clangd] Ensure the stack bottom before building AST

2023-08-30 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 554674.
zyounan marked an inline comment as done.
zyounan added a comment.

Address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158967

Files:
  clang-tools-extra/clangd/support/Threading.cpp
  clang-tools-extra/clangd/test/infinite-instantiation.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang/lib/Frontend/FrontendAction.cpp


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/LangStandard.h"
 #include "clang/Basic/Sarif.h"
+#include "clang/Basic/Stack.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
@@ -1155,6 +1156,10 @@
   CompilerInstance &CI = getCompilerInstance();
   if (!CI.hasPreprocessor())
 return;
+  // This is a fallback: If the client forgets to invoke this, we mark the
+  // current stack as the bottom. Though not optimal, this could help prevent
+  // stack overflow during deep recursion.
+  clang::noteBottomOfStack();
 
   // FIXME: Move the truncation aspect of this into Sema, we delayed this till
   // here so the source manager would be initialized.
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -29,6 +29,7 @@
 #include "support/ThreadCrashReporter.h"
 #include "support/ThreadsafeFS.h"
 #include "support/Trace.h"
+#include "clang/Basic/Stack.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
@@ -710,6 +711,9 @@
 };
 
 int clangdMain(int argc, char *argv[]) {
+  // Clang could run on the main thread. e.g., when the flag '-check' or 
'-sync'
+  // is enabled.
+  clang::noteBottomOfStack();
   llvm::InitializeAllTargetInfos();
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::sys::AddSignalHandler(
Index: clang-tools-extra/clangd/test/infinite-instantiation.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/infinite-instantiation.test
@@ -0,0 +1,13 @@
+// RUN: cp %s %t.cpp
+// RUN: not clangd -check=%t.cpp 2>&1 | FileCheck -strict-whitespace %s
+
+// CHECK: [template_recursion_depth_exceeded]
+
+template 
+constexpr int f(T... args) {
+  return f(0, args...);
+}
+
+int main() {
+  auto i = f();
+}
Index: clang-tools-extra/clangd/support/Threading.cpp
===
--- clang-tools-extra/clangd/support/Threading.cpp
+++ clang-tools-extra/clangd/support/Threading.cpp
@@ -8,6 +8,7 @@
 
 #include "support/Threading.h"
 #include "support/Trace.h"
+#include "clang/Basic/Stack.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/thread.h"
@@ -98,6 +99,9 @@
   auto Task = [Name = Name.str(), Action = std::move(Action),
Cleanup = std::move(CleanupTask)]() mutable {
 llvm::set_thread_name(Name);
+// Mark the bottom of the stack for clang to be aware of the stack usage 
and
+// prevent stack overflow.
+clang::noteBottomOfStack();
 Action();
 // Make sure function stored by ThreadFunc is destroyed before Cleanup 
runs.
 Action = nullptr;


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/LangStandard.h"
 #include "clang/Basic/Sarif.h"
+#include "clang/Basic/Stack.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
@@ -1155,6 +1156,10 @@
   CompilerInstance &CI = getCompilerInstance();
   if (!CI.hasPreprocessor())
 return;
+  // This is a fallback: If the client forgets to invoke this, we mark the
+  // current stack as the bottom. Though not optimal, this could help prevent
+  // stack overflow during deep recursion.
+  clang::noteBottomOfStack();
 
   // FIXME: Move the truncation aspect of this into Sema, we delayed this till
   // here so the source manager would be initialized.
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -29,6 +29,7 @@
 #include "support/ThreadCrashReporter.h"
 #include "support/ThreadsafeFS.h"
 #include "support/Trace.h"
+#include "clang/Basic/Stack.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/S

[PATCH] D158967: [clang][clangd] Ensure the stack bottom before building AST

2023-08-30 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Thanks again for Richard and Sam's comments!

(I didn't add another lit test for asynchronous case since it essentially works 
the same as the synchronous one. Hope this isn't harmful.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158967

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


[PATCH] D159188: [AArch64][SME] Make the overloaded svreinterpret_* functions streaming-compatible.

2023-08-30 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen created this revision.
sdesmalen added reviewers: david-arm, paulwalker-arm.
Herald added a subscriber: kristof.beyls.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
sdesmalen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Otherwise these functions are not inlined when invoked from streaming
functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159188

Files:
  clang/include/clang/Basic/Attr.td
  
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret_from_streaming_mode.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
  clang/utils/TableGen/SveEmitter.cpp


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -1284,7 +1284,7 @@
 if (ShortForm) {
   OS << "__aio __attribute__((target(\"sve\"))) " << From.Type
  << " svreinterpret_" << From.Suffix;
-  OS << "(" << To.Type << " op) {\n";
+  OS << "(" << To.Type << " op) __arm_streaming_compatible {\n";
   OS << "  return __builtin_sve_reinterpret_" << From.Suffix << "_"
  << To.Suffix << "(op);\n";
   OS << "}\n\n";
Index: clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
===
--- clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
+++ clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
@@ -3,7 +3,6 @@
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -mvscale-min=4 -mvscale-max=4 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=CHECK-512
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -mvscale-min=8 -mvscale-max=8 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=CHECK-1024
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -mvscale-min=16 -mvscale-max=16 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=CHECK-2048
-// RUN: %clang_cc1 -triple aarch64_32-unknown-darwin -target-feature +sve 
-target-feature +bf16 -mvscale-min=4 -mvscale-max=4 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=CHECK-ILP32
 
 // REQUIRES: aarch64-registered-target
 
Index: 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret_from_streaming_mode.c
===
--- /dev/null
+++ 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret_from_streaming_mode.c
@@ -0,0 +1,35 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -S -O1 
-Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -S -O1 
-Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck 
%s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -S -O1 
-Werror -Wall -o /dev/null %s
+
+// Note: We need to run this test with '-O1' because oddly enough the 
svreinterpret is always inlined at -O0.
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+// Test that svreinterpret is inlined (because it should be 
streaming-compatible)
+__attribute__((target("sme")))
+// CHECK-LABEL: @test_svreinterpret_s16_s8_from_streaming_mode(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast  [[OP:%.*]] to 

+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z45test_svreinterpret_s16_s8_from_streaming_modeu10__SVInt8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = bitcast  [[OP:%.*]] to 

+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint16_t test_svreinterpret_s16_s8_from_streaming_mode(svint8_t op) 
__arm_streaming {
+  return SVE_ACLE_FUNC(svreinterpret_s16,_s8,,)(op);
+}
+
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -415,7 +415,7 @@
   let Arches = arches;
 }
 def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
-def TargetAArch64 : TargetArch<["aarch64"]>;
+def TargetAArch64 : TargetArch<["aarch64", "aarch64_be"]>;
 def TargetAnyArm : TargetArch;
 def TargetAVR : Ta

[PATCH] D158995: [clang] Add a Windows build in the Clang pre-commit CI

2023-08-30 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

This looks good, the Windows CI is failing with the original premerge checks in 
exactly the same way as this new job, so I guess it's a current issue on `main`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158995

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


[clang] eb27be9 - [clang] Add a Windows build in the Clang pre-commit CI

2023-08-30 Thread Louis Dionne via cfe-commits

Author: Louis Dionne
Date: 2023-08-30T09:15:55-04:00
New Revision: eb27be95a4c648707ad93e48049b3d463260a747

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

LOG: [clang] Add a Windows build in the Clang pre-commit CI

This patch adds a CI job for Clang on Windows that is separate from
the monolithic job that gets added automatically via the Phabricator
integration with Buildkite. This way, we will retain the Windows testing
for Clang when we move to GitHub Pull Requests.

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

Added: 


Modified: 
clang/utils/ci/buildkite-pipeline.yml
clang/utils/ci/run-buildbot

Removed: 




diff  --git a/clang/utils/ci/buildkite-pipeline.yml 
b/clang/utils/ci/buildkite-pipeline.yml
index 621817c3ce52f5..92793480217932 100644
--- a/clang/utils/ci/buildkite-pipeline.yml
+++ b/clang/utils/ci/buildkite-pipeline.yml
@@ -31,7 +31,7 @@ steps:
 
   - wait
 
-  - label: "Building and testing clang"
+  - label: "Building and testing clang (Linux)"
 commands:
   - "clang/utils/ci/run-buildbot build-clang"
 agents:
@@ -42,6 +42,18 @@ steps:
   limit: 2
 timeout_in_minutes: 120
 
+  - label: "Building and testing clang (Windows)"
+commands:
+  - "C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat -arch=amd64 
-host_arch=amd64"
+  - "bash clang/utils/ci/run-buildbot build-clang-windows"
+agents:
+  queue: "windows"
+retry:
+  automatic:
+- exit_status: -1  # Agent was lost
+  limit: 2
+timeout_in_minutes: 120
+
   - wait
 
   - label: "Running libc++ test suite in C++03"

diff  --git a/clang/utils/ci/run-buildbot b/clang/utils/ci/run-buildbot
index 9314f8fe5bc76e..d117fccc7e3fbd 100755
--- a/clang/utils/ci/run-buildbot
+++ b/clang/utils/ci/run-buildbot
@@ -95,6 +95,21 @@ build-clang)
 
 ninja -C ${BUILD_DIR} check-clang
 ;;
+build-clang-windows)
+cmake -S llvm -B ${BUILD_DIR} -G Ninja 
 \
+-D CMAKE_C_COMPILER_LAUNCHER=sccache   
 \
+-D CMAKE_CXX_COMPILER_LAUNCHER=sccache 
 \
+-D CMAKE_BUILD_TYPE=Release
 \
+-D CMAKE_INSTALL_PREFIX=install-windows
 \
+-D LLVM_ENABLE_PROJECTS="clang;compiler-rt"
 \
+-D LLVM_ENABLE_ASSERTIONS=ON   
 \
+-D LLVM_BUILD_EXAMPLES=ON  
 \
+-D COMPILER_RT_BUILD_LIBFUZZER=OFF 
 \
+-D COMPILER_RT_BUILD_ORC=OFF
+
+ninja -C ${BUILD_DIR} install-clang install-clang-resource-headers
+ninja -C ${BUILD_DIR} check-clang
+;;
 generic-cxx03)
 buildkite-agent artifact download install.tar.xz .
 tar -xvf install.tar.xz



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


[PATCH] D158995: [clang] Add a Windows build in the Clang pre-commit CI

2023-08-30 Thread Louis Dionne via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb27be95a4c6: [clang] Add a Windows build in the Clang 
pre-commit CI (authored by ldionne).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158995

Files:
  clang/utils/ci/buildkite-pipeline.yml
  clang/utils/ci/run-buildbot


Index: clang/utils/ci/run-buildbot
===
--- clang/utils/ci/run-buildbot
+++ clang/utils/ci/run-buildbot
@@ -95,6 +95,21 @@
 
 ninja -C ${BUILD_DIR} check-clang
 ;;
+build-clang-windows)
+cmake -S llvm -B ${BUILD_DIR} -G Ninja 
 \
+-D CMAKE_C_COMPILER_LAUNCHER=sccache   
 \
+-D CMAKE_CXX_COMPILER_LAUNCHER=sccache 
 \
+-D CMAKE_BUILD_TYPE=Release
 \
+-D CMAKE_INSTALL_PREFIX=install-windows
 \
+-D LLVM_ENABLE_PROJECTS="clang;compiler-rt"
 \
+-D LLVM_ENABLE_ASSERTIONS=ON   
 \
+-D LLVM_BUILD_EXAMPLES=ON  
 \
+-D COMPILER_RT_BUILD_LIBFUZZER=OFF 
 \
+-D COMPILER_RT_BUILD_ORC=OFF
+
+ninja -C ${BUILD_DIR} install-clang install-clang-resource-headers
+ninja -C ${BUILD_DIR} check-clang
+;;
 generic-cxx03)
 buildkite-agent artifact download install.tar.xz .
 tar -xvf install.tar.xz
Index: clang/utils/ci/buildkite-pipeline.yml
===
--- clang/utils/ci/buildkite-pipeline.yml
+++ clang/utils/ci/buildkite-pipeline.yml
@@ -31,7 +31,7 @@
 
   - wait
 
-  - label: "Building and testing clang"
+  - label: "Building and testing clang (Linux)"
 commands:
   - "clang/utils/ci/run-buildbot build-clang"
 agents:
@@ -42,6 +42,18 @@
   limit: 2
 timeout_in_minutes: 120
 
+  - label: "Building and testing clang (Windows)"
+commands:
+  - "C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat -arch=amd64 
-host_arch=amd64"
+  - "bash clang/utils/ci/run-buildbot build-clang-windows"
+agents:
+  queue: "windows"
+retry:
+  automatic:
+- exit_status: -1  # Agent was lost
+  limit: 2
+timeout_in_minutes: 120
+
   - wait
 
   - label: "Running libc++ test suite in C++03"


Index: clang/utils/ci/run-buildbot
===
--- clang/utils/ci/run-buildbot
+++ clang/utils/ci/run-buildbot
@@ -95,6 +95,21 @@
 
 ninja -C ${BUILD_DIR} check-clang
 ;;
+build-clang-windows)
+cmake -S llvm -B ${BUILD_DIR} -G Ninja  \
+-D CMAKE_C_COMPILER_LAUNCHER=sccache\
+-D CMAKE_CXX_COMPILER_LAUNCHER=sccache  \
+-D CMAKE_BUILD_TYPE=Release \
+-D CMAKE_INSTALL_PREFIX=install-windows \
+-D LLVM_ENABLE_PROJECTS="clang;compiler-rt" \
+-D LLVM_ENABLE_ASSERTIONS=ON\
+-D LLVM_BUILD_EXAMPLES=ON   \
+-D COMPILER_RT_BUILD_LIBFUZZER=OFF  \
+-D COMPILER_RT_BUILD_ORC=OFF
+
+ninja -C ${BUILD_DIR} install-clang install-clang-resource-headers
+ninja -C ${BUILD_DIR} check-clang
+;;
 generic-cxx03)
 buildkite-agent artifact download install.tar.xz .
 tar -xvf install.tar.xz
Index: clang/utils/ci/buildkite-pipeline.yml
===
--- clang/utils/ci/buildkite-pipeline.yml
+++ clang/utils/ci/buildkite-pipeline.yml
@@ -31,7 +31,7 @@
 
   - wait
 
-  - label: "Building and testing clang"
+  - label: "Building and testing clang (Linux)"
 commands:
   - "clang/utils/ci/run-buildbot build-clang"
 agents:
@@ -42,6 +42,18 @@
   limit: 2
 timeout_in_minutes: 120
 
+  - label: "Building and testing clang (Windows)"
+commands:
+  - "C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat -arch=amd64 -host_arch=amd64"
+  - "bash clang/utils/ci/run-buildbot build-clang-windows"
+agents:
+  queue: "windows"
+retry:
+  automatic:
+- exit_status: -1  # Agent was lost
+  limit: 2
+timeout_in_minutes: 120
+
   - wait
 
   - label: "Running libc++ test suite in C++03"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.ll

[PATCH] D159197: [clang][ci] Don't block all jobs on clang-format

2023-08-30 Thread Louis Dionne via Phabricator via cfe-commits
ldionne created this revision.
ldionne added a reviewer: aaron.ballman.
Herald added a project: All.
ldionne requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It was expressed in some reviews that Clang folks didn't want to hold
off other testing jobs in case clang-format failed. This patch makes
it so that the basic clang testing jobs will run even if clang-format
fails on the patch. The overall build will still be marked as failed,
but it will be possible to see the failures in clang tests so at least
there will be some feedback available.

The whole pipeline was originally blocked on clang-format because we
inherited that pipeline definition from libc++, where we want to block
on clang-format for capacity reasons.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159197

Files:
  clang/utils/ci/buildkite-pipeline.yml


Index: clang/utils/ci/buildkite-pipeline.yml
===
--- clang/utils/ci/buildkite-pipeline.yml
+++ clang/utils/ci/buildkite-pipeline.yml
@@ -20,7 +20,6 @@
   - label: "Format"
 commands:
   - "clang/utils/ci/run-buildbot check-format"
-
 agents:
   queue: "linux"
 retry:
@@ -29,8 +28,6 @@
   limit: 2
 timeout_in_minutes: 120
 
-  - wait
-
   - label: "Building and testing clang (Linux)"
 commands:
   - "clang/utils/ci/run-buildbot build-clang"


Index: clang/utils/ci/buildkite-pipeline.yml
===
--- clang/utils/ci/buildkite-pipeline.yml
+++ clang/utils/ci/buildkite-pipeline.yml
@@ -20,7 +20,6 @@
   - label: "Format"
 commands:
   - "clang/utils/ci/run-buildbot check-format"
-
 agents:
   queue: "linux"
 retry:
@@ -29,8 +28,6 @@
   limit: 2
 timeout_in_minutes: 120
 
-  - wait
-
   - label: "Building and testing clang (Linux)"
 commands:
   - "clang/utils/ci/run-buildbot build-clang"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159197: [clang][ci] Don't block all jobs on clang-format

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

Thank you for this! I'm not qualified to say the changes are correct (they look 
sensible to me though), but I am really appreciative of the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159197

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


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-30 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 added a comment.

No, I don't have code examples that showcase the importance of the note. As you 
said the class context would be obvious whenever we run into this error.
The test files also don't show where the note would be helpful.


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

https://reviews.llvm.org/D158540

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


[PATCH] D159054: [Driver] Removal of C_INCLUDE_DIRS feature

2023-08-30 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

In D159054#4626772 , @brad wrote:

> Just FYI I am not in a rush to commit this. I am posting this more so as a 
> means of prodding for discussion of the feature.

So far nobody has popped up to say they want it.

@MaskRay I poked around a bit on sourcegraph.com and didn't see any statement 
about what it actually searches, other than vague "all your repositories" and 
"all your code." The "your" bit makes me wonder how broad it is really. The 
website doesn't say.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159054

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


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

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

In D158540#4628265 , @NoumanAmir657 
wrote:

> No, I don't have code examples that showcase the importance of the note. As 
> you said the class context would be obvious whenever we run into this error.
> The test files also don't show where the note would be helpful.

The crux of https://github.com/llvm/llvm-project/issues/64843 is about the 
error diagnostic, and that logic hasn't been changed in this patch -- are there 
other changes that are missing from the patch? The text of the tests shows that 
the error diagnostic behavior should have changed as well, but I'm not seeing 
the functional changes to make that happen.


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

https://reviews.llvm.org/D158540

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


[PATCH] D148131: Avoid unnecessarily aggressive line-breaking when using "LambdaBodyIndentation: OuterScope" with argument bin-packing.

2023-08-30 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 updated this revision to Diff 554704.
jp4a50 added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148131

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22737,8 +22737,7 @@
"  []() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
-   "  },\n"
-   "  foo, bar)\n"
+   "  }, foo, bar)\n"
"  .foo();\n"
"}",
Style);
@@ -22764,32 +22763,12 @@
"  })));\n"
"}",
Style);
-  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
-  verifyFormat("void foo() {\n"
-   "  aFunction(\n"
-   "  1, b(c(\n"
-   " [](d) -> Foo {\n"
-   "auto f = e(d);\n"
-   "return f;\n"
-   "  },\n"
-   " foo, Bar{},\n"
-   " [] {\n"
-   "auto g = h();\n"
-   "return g;\n"
-   "  },\n"
-   " baz)));\n"
-   "}",
-   Style);
   verifyFormat("void foo() {\n"
"  aFunction(1, b(c(foo, Bar{}, baz, [](d) -> Foo {\n"
-   "auto f = e(\n"
-   "foo,\n"
-   "[&] {\n"
+   "auto f = e(foo, [&] {\n"
"  auto g = h();\n"
"  return g;\n"
-   "},\n"
-   "qux,\n"
-   "[&] -> Bar {\n"
+   "}, qux, [&] -> Bar {\n"
"  auto i = j();\n"
"  return i;\n"
"});\n"
@@ -22797,28 +22776,74 @@
"  })));\n"
"}",
Style);
-  verifyFormat("Namespace::Foo::Foo(\n"
-   "LongClassName bar, AnotherLongClassName baz)\n"
+  verifyFormat("Namespace::Foo::Foo(LongClassName bar,\n"
+   "AnotherLongClassName baz)\n"
": baz{baz}, func{[&] {\n"
"  auto qux = bar;\n"
"  return aFunkyFunctionCall(qux);\n"
"}} {}",
Style);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  // As long as all the non-lambda arguments fit on a single line, AlwaysBreak
+  // doesn't force an initial line break, even if lambdas span multiple lines.
+  // This should probably be considered a bug.
+  verifyFormat("void foo() {\n"
+   "  aFunction([](d) -> Foo {\n"
+   "auto f = e(d);\n"
+   "return f;\n"
+   "  }, foo, Bar{}, [] {\n"
+   "auto g = h();\n"
+   "return g;\n"
+   "  }, baz);\n"
+   "}",
+   Style);
+  // A long non-lambda argument forces arguments to span multiple lines and thus
+  // forces an initial line break when using AlwaysBreak.
+  verifyFormat("void foo() {\n"
+   "  aFunction(\n"
+   "  1,\n"
+   "  [](d) -> Foo {\n"
+   "auto f = e(d);\n"
+   "return f;\n"
+   "  }, foo, Bar{},\n"
+   "  [] {\n"
+   "auto g = h();\n"
+   "return g;\n"
+   "  }, baz,\n"
+   "  qx);\n"
+   "}",
+   Style);
+  Style.BinPackArguments = false;
+  verifyFormat("void foo() {\n"
+   "  aFunction(\n"
+   "  1,\n"
+   "  [](d) -> Foo {\n"
+   "auto f = e(d);\n"
+   "return f;\n"
+   "  },\n"
+   "  foo,\n"
+   "  Bar{},\n"
+   "  [] {\n"
+   "auto g = h();\n"
+   "return g;\n"
+   "  },\n"
+   "  baz,\n"
+   "  qx);\n"
+   "}",
+   Style);
+  Style.BinPackArguments = true;
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.BeforeLambdaBody = true;
   verifyFormat("void foo() {\n"
"  aFunction(\n"
-   "  1, b(c(foo, Bar{}, baz,\n"
-   " [](d) -> Foo\n"
+   "  1, b(c(foo, Bar{}, baz, [](d) -> Foo\n"
"  {\n"
"auto f = e(\n"
"[&]\n"
"{\n"
"  auto 

[PATCH] D148131: Avoid unnecessarily aggressive line-breaking when using "LambdaBodyIndentation: OuterScope" with argument bin-packing.

2023-08-30 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 marked 6 inline comments as done.
jp4a50 added a comment.

All comments addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148131

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


[PATCH] D159083: Clang: Don't warn about unused private fields of types declared maybe_unused

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

Thanks! I filed https://github.com/llvm/llvm-project/issues/65111 to track the 
template instantiation concerns


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159083

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


[PATCH] D85309: [Driver] Support GNU ld on Solaris

2023-08-30 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 554711.
ro retitled this revision from "[WIP][clang][Driver] Support GNU ld on Solaris" 
to "[Driver] Support GNU ld on Solaris".
ro added a comment.
Herald added subscribers: llvm-commits, Sanitizers, Enna1, ormris.
Herald added a reviewer: sscalpone.
Herald added a reviewer: awarzynski.
Herald added projects: Sanitizers, LLVM, Flang, All.

This is a major revison of the original WIP patch that should be (close to) 
ready.  Major differences are:

- Linker selection is dynamic now: one can switch between Solaris ld and GNU ld 
at runtime, with the default selectable with `-DCLANG_DEFAULT_LINKER`.
- Testcases have been adjusted to test both variants in case there are 
differences.
- The `compiler-rt/cmake/config-ix.cmake` and 
`llvm/cmake/modules/AddLLVM.cmake` changes to restrict the tests to Solaris ld 
are necessary because GNU accepts unknown `-z` options, but warns every time 
they are used, creating a lot of noise.  Since there seems to be no way to 
check for those warnings in `llvm_check_compiler_linker_flag` or 
`llvm_check_compiler_linker_flag`, I restrict the cmake tests to Solaris ld in 
the first place.
- The changes to `clang/test/Driver/hip-link-bundle-archive.hip` and 
`flang/test/Driver/linker-flags.f90` are required to handle the 
`-DCLANG_DEFAULT_LINKER=gld` case: when this is passed to `cmake`, the 
`WebAssembly.cpp` `getLinkerPath` returns `/usr/bin/gld` instead of the 
expected `link`.
- `compiler-rt/test/asan/TestCases/global-location-nodebug.cpp` needs to 
enforce the Solaris ld, otherwise the test would `XPASS` with GNU ld which has 
the `-S` semantics expected by the test.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11` with both 
`-DCLANG_DEFAULT_LINKER=gld` and the default, and `x86_64-pc-linux-gnu`.  No 
regressions in either case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85309

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/lib/Driver/ToolChains/Solaris.h
  clang/test/Driver/hip-link-bundle-archive.hip
  clang/test/Driver/solaris-ld-sanitizer.c
  clang/test/Driver/solaris-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  flang/test/Driver/linker-flags.f90
  llvm/cmake/modules/AddLLVM.cmake

Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -282,9 +282,9 @@
 # ld64's implementation of -dead_strip breaks tools that use plugins.
 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
  LINK_FLAGS " -Wl,-dead_strip")
-  elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
+  elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
 # Support for ld -z discard-unused=sections was only added in
-# Solaris 11.4.
+# Solaris 11.4.  GNU ld ignores it, but warns every time.
 include(LLVMCheckLinkerFlag)
 llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
 if (LINKER_SUPPORTS_Z_DISCARD_UNUSED)
@@ -1288,7 +1288,10 @@
 # the size of the exported symbol table, but on other platforms we can do
 # it without any trouble.
 set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
-if (APPLE)
+# CMake doesn't set CMAKE_EXE_EXPORTS_${lang}_FLAG on Solaris, so
+# ENABLE_EXPORTS has no effect.  While Solaris ld defaults to -rdynamic
+# behaviour, GNU ld needs it.
+if (APPLE OR ${CMAKE_SYSTEM_NAME} STREQUAL "SunOS")
   set_property(TARGET ${target} APPEND_STRING PROPERTY
 LINK_FLAGS " -rdynamic")
 endif()
Index: flang/test/Driver/linker-flags.f90
===
--- flang/test/Driver/linker-flags.f90
+++ flang/test/Driver/linker-flags.f90
@@ -10,7 +10,7 @@
 !   'oldnames' on Windows, but they are not needed when compiling
 !   Fortran code and they might bring in additional dependencies.
 !   Make sure they're not added.
-! RUN: %flang -### -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
+! RUN: %flang -### -target aarch64-windows-msvc -fuse-ld= %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
 
 ! Compiler invocation to generate the object file
 ! CHECK-LABEL: {{.*}} "-emit-obj"
Index: compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
===
--- compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
+++ compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
@@ 

[PATCH] D159206: [Clang] Propagate target-features if compatible when using mlink-builtin-bitcode

2023-08-30 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez created this revision.
jmmartinez added reviewers: arsenm, Pierre-vh, yaxunl, jhuber6.
Herald added a project: All.
jmmartinez requested review of this revision.
Herald added subscribers: cfe-commits, wdng.
Herald added a project: clang.

Buitlins from AMD's device-libs are compiled without specifying a
target-cpu, which results in builtins without the target-features
attribute set.

Before this patch, when linking this builtins with -mlink-builtin-bitcode
the target-features were not propagated in the incoming builtins.

With this patch, the default target features are propagated
if they are compatible with the target-features in the incoming builtin.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159206

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/link-builtin-bitcode.c
  clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu

Index: clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
===
--- clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
+++ clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
@@ -31,7 +31,7 @@
 
 
 // CHECK: define {{.*}} i64 @do_intrin_stuff() #[[ATTR:[0-9]+]]
-// INTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-cpu"="gfx{{.*}}" "target-features"="+gfx11-insts"
+// INTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-cpu"="gfx{{.*}}" "target-features"="{{.*}}+gfx11-insts{{.*}}"
 // NOINTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-features"="+gfx11-insts"
 
 #define __device__ __attribute__((device))
Index: clang/test/CodeGen/link-builtin-bitcode.c
===
--- clang/test/CodeGen/link-builtin-bitcode.c
+++ clang/test/CodeGen/link-builtin-bitcode.c
@@ -1,42 +1,50 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --check-globals --include-generated-funcs --version 2
+// Build two version of the bitcode library, one with a target-cpu set and one without
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx803 -DBITCODE -emit-llvm-bc -o %t-lib.bc %s
+// RUN: %clang_cc1 -triple amdgcn-- -DBITCODE -emit-llvm-bc -o %t-lib.no-cpu.bc %s
+
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm-bc -o %t.bc %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm \
+// RUN:   -mlink-builtin-bitcode %t-lib.bc -o - %t.bc | FileCheck %s --check-prefixes=COMMON,CPU
+
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm-bc -o %t.bc %s
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm \
-// RUN:   -mlink-builtin-bitcode %t-lib.bc -o - %t.bc | FileCheck %s
+// RUN:   -mlink-builtin-bitcode %t-lib.no-cpu.bc -o - %t.bc | FileCheck %s --check-prefixes=COMMON,NOCPU
 
 #ifdef BITCODE
-int foo(void) { return 42; }
+int no_attr(void) { return 42; }
+int __attribute__((target("gfx8-insts"))) attr_in_target(void) { return 42; }
+int __attribute__((target("extended-image-insts"))) attr_not_in_target(void) { return 42; }
+int __attribute__((target("no-gfx9-insts"))) attr_uncompatible(void) { return 42; }
 int x = 12;
 #endif
 
-extern int foo(void);
+extern int no_attr(void);
+extern int attr_in_target(void);
+extern int attr_not_in_target(void);
+extern int attr_uncompatible(void);
 extern int x;
 
-int bar() { return foo() + x; }
-//.
-// CHECK: @x = internal addrspace(1) global i32 12, align 4
-//.
-// CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define dso_local i32 @bar
-// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4, addrspace(5)
-// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
-// CHECK-NEXT:[[CALL:%.*]] = call i32 @foo()
-// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr addrspacecast (ptr addrspace(1) @x to ptr), align 4
-// CHECK-NEXT:[[ADD:%.*]] = add nsw i32 [[CALL]], [[TMP0]]
-// CHECK-NEXT:ret i32 [[ADD]]
-//
-//
-// CHECK: Function Attrs: convergent noinline nounwind optnone
-// CHECK-LABEL: define internal i32 @foo
-// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4, addrspace(5)
-// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
-// CHECK-NEXT:ret i32 42
+int bar() { return no_attr() + attr_in_target() + attr_not_in_target() + attr_uncompatible() + x; }
+
+// COMMON: @x = internal addrspace(1) global i32 12, align 4
+
+// COMMON-LABEL: define dso_local i32 @bar
+// COMMON-SAME: () #[[ATTR_BAR:[0-9]+]] {
 //
-//.
-// CHECK: attributes #0 = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx90a" "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-in

[PATCH] D159206: [Clang] Propagate target-features if compatible when using mlink-builtin-bitcode

2023-08-30 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2034
+  }
+
+  FuncAttr.addAttribute("target-features", llvm::join(MergedFeatures, ","));

Really it would be less bad if the incompatible functions were not imported 
rather than the backend pass



Comment at: clang/test/CodeGen/link-builtin-bitcode.c:17
+int __attribute__((target("extended-image-insts"))) attr_not_in_target(void) { 
return 42; }
+int __attribute__((target("no-gfx9-insts"))) attr_uncompatible(void) { return 
42; }
 int x = 12;

This isn't a real target feature (do we not have a warning on this?)

s/uncompatible/incompatible


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159206

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


[PATCH] D159206: [Clang] Propagate target-features if compatible when using mlink-builtin-bitcode

2023-08-30 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2035
+
+  FuncAttr.addAttribute("target-features", llvm::join(MergedFeatures, ","));
+}

do you need to guard against adding the empty attribute? I don't want to see 
"target-features"=""


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159206

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


[PATCH] D156743: clang/OpenCL: Add inline implementations of sqrt in builtin header

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

ping

The alternative is to directly put the !fpmath on the sqrt call sites but I 
have no idea how to do that


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

https://reviews.llvm.org/D156743

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


[PATCH] D158061: [clang] Construct ExprRequirement with SubstitutionDiagnostic on SubstFailure

2023-08-30 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Hi, sorry for the delay in reviewing, I'm just coming back from an extended 
vacation.  This looks alright, except for the test.




Comment at: clang/test/SemaCXX/concept-crash-on-diagnostic.cpp:26
+// Consume remaining notes/errors.
+// expected-note@* 0+{{}}
+// expected-error@* 0+{{}}

Please don't do this, actually write out the remaining diagnostics.  Same with 
the notes above.

Additionally, please use the 'bookmark' feature of verify-consumer to make sure 
the diagnostics/notes are in proper order (which makes it easier to figure out 
when reviewing).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158061

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


[PATCH] D155858: Add a concept AST node.

2023-08-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

LGTM, just nits!

The SourceRanges are actually correct :-)




Comment at: clang/include/clang/AST/ASTConcept.h:124
 class ConceptReference {
 protected:
   // \brief The optional nested name specifier used when naming the concept.

remove `protected` (and `private:` below), we don't inherit from this



Comment at: clang/include/clang/AST/ExprConcepts.h:46
 public:
   using SubstitutionDiagnostic = std::pair;
 

while here: this is unused, remove?



Comment at: clang/include/clang/AST/ExprConcepts.h:48
 
 protected:
+  ConceptReference *ConceptRef;

while here: this class is final, so these can be private instead of protected



Comment at: clang/lib/AST/TypeLoc.cpp:625
 
-DeclarationNameInfo AutoTypeLoc::getConceptNameInfo() const {
-  return DeclarationNameInfo(getNamedConcept()->getDeclName(),
- getLocalData()->ConceptNameLoc);
+static ConceptReference *createConceptReference(ASTContext &Context,
+SourceLocation Loc,

nit: createTrivialConceptReference?
hinting at the relationship to trivial TypeSourceInfo

maybe a comment too?
```
// Builds a ConceptReference where all locations point at the same token,
// for use in trivial TypeSourceInfo for constrained AutoType
```



Comment at: clang/unittests/AST/SourceLocationTest.cpp:1025
+)cpp";
+  // FIXME: expected range should be (2, 1, 2, 3)
+  Verifier.expectRange(2, 1, 2, 1);

why that range?
SourceRanges are generally "closed token ranges", so the endpoint is the 
*beginning* of the last token *in* the range.
`CCC` is (2, 1, 2, 1)



Comment at: clang/unittests/AST/SourceLocationTest.cpp:1073
+)cpp";
+  // FIXME: expected range should be (2, 11, 2, 13)
+  Verifier.expectRange(2, 11, 2, 11);

as above


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155858

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


[PATCH] D158963: [CodeGen] Function multi-versioning: don't set comdat for internal linkage resolvers

2023-08-30 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Needs a release note.  I don't have a problem with the patch, but don't really 
understand how COMDAT works/linking works, but since you're basically the 
person I'd tell someone else to ask, I guess I'll trust you know what you're 
doing :)

Please add the release note while committing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158963

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


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-30 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 added a comment.

In D158540#4628310 , @aaron.ballman 
wrote:

> In D158540#4628265 , @NoumanAmir657 
> wrote:
>
>> No, I don't have code examples that showcase the importance of the note. As 
>> you said the class context would be obvious whenever we run into this error.
>> The test files also don't show where the note would be helpful.
>
> The crux of https://github.com/llvm/llvm-project/issues/64843 is about the 
> error diagnostic, and that logic hasn't been changed in this patch -- are 
> there other changes that are missing from the patch? The text of the tests 
> shows that the error diagnostic behavior should have changed as well, but I'm 
> not seeing the functional changes to make that happen.

Can you elaborate further? I did not understand what you mean by functional 
changes. According to my knowledge, I don't think anything else is missing from 
the patch.


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

https://reviews.llvm.org/D158540

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


[clang] c2647ed - fix unused variables in condition warning

2023-08-30 Thread Mikhail Goncharov via cfe-commits

Author: Mikhail Goncharov
Date: 2023-08-30T17:39:54+02:00
New Revision: c2647ed9b9cd5a0baddb2edf242c9b1f8976d7b6

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

LOG: fix unused variables in condition warning

for 92023b15099012a657da07ebf49dd7d94a260f84

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 7cd505218f2b90..f2e86da1c745a0 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -377,7 +377,8 @@ class DefaultArgStorage {
 InheritedFrom = getParmOwningDefaultArg(InheritedFrom);
 if (!isSet())
   ValueOrInherited = InheritedFrom;
-else if (auto *D = ValueOrInherited.template dyn_cast()) {
+else if ([[maybe_unused]] auto *D =
+ ValueOrInherited.template dyn_cast()) {
   assert(C.isSameDefaultTemplateArgument(D, InheritedFrom));
   ValueOrInherited =
   new (allocateDefaultArgStorageChain(C)) Chain{InheritedFrom, get()};

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d8a4ca0db12fc8..a865faeedae6f4 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1670,7 +1670,7 @@ template 
 std::optional
 ByteCodeExprGen::allocateLocal(DeclTy &&Src, bool IsExtended) {
   // Make sure we don't accidentally register the same decl twice.
-  if (const auto *VD =
+  if ([[maybe_unused]]  const auto *VD =
   dyn_cast_if_present(Src.dyn_cast())) {
 assert(!P.getGlobal(VD));
 assert(!Locals.contains(VD));



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


[PATCH] D159212: [MLIR] Allow dialects to disable CSE for certain operations

2023-08-30 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak created this revision.
skatrak added reviewers: ftynse, kiranchandramohan, jsjodin, domada, agozillon, 
raghavendhra, TIFitis, shraiysh.
Herald added subscribers: bviyer, Moerafaat, zero9178, bzcheeseman, sdasgup3, 
wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, 
Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a project: All.
skatrak requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: cfe-commits, stephenneuendorffer, nicolasvasilache.
Herald added projects: clang, MLIR.

This patch adds the `DialectCSEInterface`, which dialects can implement and 
register to prevent the common sub-expression elimination (CSE) pass from 
modifying regions of certain operations.

The result is that these operations would be treated by CSE as if they were 
`IsolatedFromAbove`, but without the restrictions that come with that trait.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159212

Files:
  clang/docs/tools/clang-formatted-files.txt
  mlir/include/mlir/Interfaces/CSEInterfaces.h
  mlir/lib/Transforms/CSE.cpp
  mlir/test/Transforms/cse.mlir
  mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp
  mlir/test/lib/Dialect/Test/TestOps.td

Index: mlir/test/lib/Dialect/Test/TestOps.td
===
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -2703,6 +2703,10 @@
   }];
 }
 
+def NoCSEOneRegionOp : TEST_Op<"no_cse_one_region_op", []> {
+  let regions = (region AnyRegion);
+}
+
 //===--===//
 // Test Ops to upgrade base on the dialect versions
 //===--===//
Index: mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp
===
--- mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp
+++ mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "TestDialect.h"
+#include "mlir/Interfaces/CSEInterfaces.h"
 #include "mlir/Interfaces/FoldInterfaces.h"
 #include "mlir/Reducer/ReductionPatternInterface.h"
 #include "mlir/Transforms/InliningUtils.h"
@@ -273,6 +274,16 @@
   }
 };
 
+struct TestDialectCSEInterface : public DialectCSEInterface {
+  using DialectCSEInterface::DialectCSEInterface;
+
+  bool subexpressionExtractionAllowed(Operation *op) const final {
+// Don't allow extracting common subexpressions from the region of these
+// operations.
+return !isa(op);
+  }
+};
+
 /// This class defines the interface for handling inlining with standard
 /// operations.
 struct TestInlinerInterface : public DialectInlinerInterface {
@@ -385,6 +396,7 @@
   auto &blobInterface = addInterface();
   addInterface(blobInterface);
 
-  addInterfaces();
+  addInterfaces();
 }
Index: mlir/test/Transforms/cse.mlir
===
--- mlir/test/Transforms/cse.mlir
+++ mlir/test/Transforms/cse.mlir
@@ -520,3 +520,23 @@
   %2 = "test.op_with_memread"() : () -> (i32)
   return %0, %2, %1 : i32, i32, i32
 }
+
+// CHECK-LABEL: @no_cse_across_disabled_op
+func.func @no_cse_across_disabled_op() -> (i32) {
+  // CHECK-NEXT: %[[CONST1:.+]] = arith.constant 1 : i32
+  %0 = arith.constant 1 : i32
+
+  // CHECK-NEXT: test.no_cse_one_region_op
+  "test.no_cse_one_region_op"() ({
+%1 = arith.constant 1 : i32
+%2 = arith.addi %1, %1 : i32
+"foo.yield"(%2) : (i32) -> ()
+
+// CHECK-NEXT: %[[CONST2:.+]] = arith.constant 1 : i32
+// CHECK-NEXT: %[[SUM:.+]] = arith.addi %[[CONST2]], %[[CONST2]] : i32
+// CHECK-NEXT: "foo.yield"(%[[SUM]]) : (i32) -> ()
+  }) : () -> ()
+
+  // CHECK: return %[[CONST1]] : i32
+  return %0 : i32
+}
Index: mlir/lib/Transforms/CSE.cpp
===
--- mlir/lib/Transforms/CSE.cpp
+++ mlir/lib/Transforms/CSE.cpp
@@ -15,6 +15,7 @@
 
 #include "mlir/IR/Dominance.h"
 #include "mlir/IR/PatternMatch.h"
+#include "mlir/Interfaces/CSEInterfaces.h"
 #include "mlir/Interfaces/SideEffectInterfaces.h"
 #include "mlir/Pass/Pass.h"
 #include "mlir/Transforms/Passes.h"
@@ -61,7 +62,8 @@
 class CSEDriver {
 public:
   CSEDriver(RewriterBase &rewriter, DominanceInfo *domInfo)
-  : rewriter(rewriter), domInfo(domInfo) {}
+  : rewriter(rewriter), domInfo(domInfo),
+interfaces(rewriter.getContext()) {}
 
   /// Simplify all operations within the given op.
   void simplify(Operation *op, bool *changed = nullptr);
@@ -122,6 +124,9 @@
   DominanceInfo *domInfo = nullptr;
   MemEffectsCache memEffectsCache;
 
+  /// CSE interfaces in the present context that can modify CSE behavior.
+  DialectInterfaceCollection interfaces;
+
   // Va

[PATCH] D157813: [Driver][VE] Support VPU flag as a feature for VE

2023-08-30 Thread Kazushi Marukawa via Phabricator via cfe-commits
kaz7 updated this revision to Diff 554742.
kaz7 added a comment.

By using hasFlag, change to enable VPU flag for VE by default again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157813

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/VE.cpp
  clang/test/Driver/ve-features.c


Index: clang/test/Driver/ve-features.c
===
--- /dev/null
+++ clang/test/Driver/ve-features.c
@@ -0,0 +1,5 @@
+// RUN: %clang --target=ve-unknown-linux-gnu -### %s 2>&1 | FileCheck %s 
-check-prefix=DEFAULT
+// RUN: %clang --target=ve-unknown-linux-gnu -### %s -mvevpu -mno-vevpu 2>&1 | 
FileCheck %s -check-prefix=NO-VEVPU
+
+// DEFAULT: "-target-feature" "+vpu"
+// NO-VEVPU: "-target-feature" "-vpu"
Index: clang/lib/Driver/ToolChains/Arch/VE.cpp
===
--- clang/lib/Driver/ToolChains/Arch/VE.cpp
+++ clang/lib/Driver/ToolChains/Arch/VE.cpp
@@ -18,4 +18,9 @@
 using namespace llvm::opt;
 
 void ve::getVETargetFeatures(const Driver &D, const ArgList &Args,
- std::vector &Features) {}
+ std::vector &Features) {
+  if (Args.hasFlag(options::OPT_mvevpu, options::OPT_mno_vevpu, true))
+Features.push_back("+vpu");
+  else
+Features.push_back("-vpu");
+}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -202,6 +202,8 @@
Group, Flags<[CoreOption]>, DocName<"X86">;
 def m_riscv_Features_Group : OptionGroup<"">,
  Group, DocName<"RISC-V">;
+def m_ve_Features_Group : OptionGroup<"">,
+  Group, DocName<"VE">;
 
 def m_libc_Group : OptionGroup<"">, Group,
Flags<[HelpHidden]>;
@@ -5160,6 +5162,13 @@
 def mno_vzeroupper : Flag<["-"], "mno-vzeroupper">, 
Group;
 } // let Flags = [TargetSpecific]
 
+// VE feature flags
+let Flags = [TargetSpecific] in {
+def mvevpu : Flag<["-"], "mvevpu">, Group,
+  HelpText<"Emit VPU instructions for VE">;
+def mno_vevpu : Flag<["-"], "mno-vevpu">, Group;
+} // let Flags = [TargetSpecific]
+
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag
 // style of double-dash and equals-joined flags.


Index: clang/test/Driver/ve-features.c
===
--- /dev/null
+++ clang/test/Driver/ve-features.c
@@ -0,0 +1,5 @@
+// RUN: %clang --target=ve-unknown-linux-gnu -### %s 2>&1 | FileCheck %s -check-prefix=DEFAULT
+// RUN: %clang --target=ve-unknown-linux-gnu -### %s -mvevpu -mno-vevpu 2>&1 | FileCheck %s -check-prefix=NO-VEVPU
+
+// DEFAULT: "-target-feature" "+vpu"
+// NO-VEVPU: "-target-feature" "-vpu"
Index: clang/lib/Driver/ToolChains/Arch/VE.cpp
===
--- clang/lib/Driver/ToolChains/Arch/VE.cpp
+++ clang/lib/Driver/ToolChains/Arch/VE.cpp
@@ -18,4 +18,9 @@
 using namespace llvm::opt;
 
 void ve::getVETargetFeatures(const Driver &D, const ArgList &Args,
- std::vector &Features) {}
+ std::vector &Features) {
+  if (Args.hasFlag(options::OPT_mvevpu, options::OPT_mno_vevpu, true))
+Features.push_back("+vpu");
+  else
+Features.push_back("-vpu");
+}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -202,6 +202,8 @@
Group, Flags<[CoreOption]>, DocName<"X86">;
 def m_riscv_Features_Group : OptionGroup<"">,
  Group, DocName<"RISC-V">;
+def m_ve_Features_Group : OptionGroup<"">,
+  Group, DocName<"VE">;
 
 def m_libc_Group : OptionGroup<"">, Group,
Flags<[HelpHidden]>;
@@ -5160,6 +5162,13 @@
 def mno_vzeroupper : Flag<["-"], "mno-vzeroupper">, Group;
 } // let Flags = [TargetSpecific]
 
+// VE feature flags
+let Flags = [TargetSpecific] in {
+def mvevpu : Flag<["-"], "mvevpu">, Group,
+  HelpText<"Emit VPU instructions for VE">;
+def mno_vevpu : Flag<["-"], "mno-vevpu">, Group;
+} // let Flags = [TargetSpecific]
+
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag
 // style of double-dash and equals-joined flags.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155858: Add a concept AST node.

2023-08-30 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 554743.
massberg marked 7 inline comments as done.
massberg added a comment.

Fixed remaining nits. Thanks for the reviews and comments everyone!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155858

Files:
  clang/include/clang/AST/ASTConcept.h
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/ExprConcepts.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TypeLoc.h
  clang/include/clang/Serialization/ASTRecordReader.h
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/ExprConcepts.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/unittests/AST/SourceLocationTest.cpp
  clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp

Index: clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp
===
--- clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp
@@ -29,12 +29,22 @@
 ++ConceptRequirementsTraversed;
 return ExpectedLocationVisitor::TraverseConceptRequirement(R);
   }
+  bool TraverseConceptReference(ConceptReference *CR) {
+++ConceptReferencesTraversed;
+return ExpectedLocationVisitor::TraverseConceptReference(CR);
+  }
+  bool VisitConceptReference(ConceptReference *CR) {
+++ConceptReferencesVisited;
+return true;
+  }
 
   bool shouldVisitImplicitCode() { return ShouldVisitImplicitCode; }
 
   int ConceptSpecializationExprsVisited = 0;
   int TypeConstraintsTraversed = 0;
   int ConceptRequirementsTraversed = 0;
+  int ConceptReferencesTraversed = 0;
+  int ConceptReferencesVisited = 0;
   bool ShouldVisitImplicitCode = false;
 };
 
@@ -50,6 +60,8 @@
   EXPECT_EQ(1, Visitor.ConceptSpecializationExprsVisited);
   // Also check we traversed the TypeConstraint that produced the expr.
   EXPECT_EQ(1, Visitor.TypeConstraintsTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesVisited);
 
   Visitor = {}; // Don't visit implicit code now.
   EXPECT_TRUE(Visitor.runOver("template  concept Fooable = true;\n"
@@ -59,6 +71,8 @@
   // generated immediately declared expression.
   EXPECT_EQ(0, Visitor.ConceptSpecializationExprsVisited);
   EXPECT_EQ(1, Visitor.TypeConstraintsTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesVisited);
 
   Visitor = {};
   EXPECT_TRUE(Visitor.runOver("template  concept A = true;\n"
@@ -70,6 +84,8 @@
   "};",
   ConceptVisitor::Lang_CXX2a));
   EXPECT_EQ(3, Visitor.ConceptRequirementsTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesTraversed);
+  EXPECT_EQ(1, Visitor.ConceptReferencesVisited);
 }
 
 struct VisitDeclOnlyOnce : ExpectedLocationVisitor {
@@ -86,6 +102,10 @@
 ++AutoTypeLocVisited;
 return true;
   }
+  bool VisitConceptReference(ConceptReference *) {
+++ConceptReferencesVisited;
+return true;
+  }
 
   bool TraverseVarDecl(VarDecl *V) {
 // The base traversal visits only the `TypeLoc`.
@@ -99,6 +119,7 @@
   int ConceptDeclsVisited = 0;
   int AutoTypeVisited = 0;
   int AutoTypeLocVisited = 0;
+  int ConceptReferencesVisited = 0;
 };
 
 TEST(RecursiveASTVisitor, ConceptDeclInAutoType) {
@@ -111,6 +132,7 @@
   EXPECT_EQ(1, Visitor.AutoTypeVisited);
   EXPECT_EQ(1, Visitor.AutoTypeLocVisited);
   EXPECT_EQ(1, Visitor.ConceptDeclsVisited);
+  EXPECT_EQ(1, Visitor.ConceptReferencesVisited);
 }
 
 } // end anonymous namespace
Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -16,7 +16,11 @@
 //===--===//
 
 #include "MatchVerifier.h"
+#include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTFwd.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprConcepts.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/Tooling.h"
@@ -370,10 +374,10 @@
 TEST(CompoundLiteralExpr, ParensCompoundVectorLiteralRange) {
   RangeVerifier Verifier;
   Verifier.expectRange(2, 20, 2, 31);
-  EXPECT_TRUE(Verifier.match(
-  "typedef 

[PATCH] D157813: [Driver][VE] Support VPU flag as a feature for VE

2023-08-30 Thread Kazushi Marukawa via Phabricator via cfe-commits
kaz7 marked an inline comment as done.
kaz7 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/VE.cpp:22
+ std::vector &Features) {
+  // Defaults.
+  bool EnableVPU = true;

MaskRay wrote:
> kaz7 wrote:
> > MaskRay wrote:
> > > Delete the comment. The code speaks itself. 
> > > 
> > > ```
> > > if (Args.hasArg(options::OPT_mvevpu, options::OPT_mno_vevpu, true)
> > >   Features.push_back("+vpu");
> > > ```
> > Thanks.  I remove comments and simplify existing code.
> Sorry for my typo. We should use the 3-argument `hasFlag` here. It's simpler 
> than getLastArg+matches
I see.  I was wondering that part too.  Now, I change it to use hasFlag 
function with default value.



Comment at: clang/test/Driver/ve-features.c:1
+// RUN: %clang -target ve-unknown-linux-gnu -### %s -mvevpu 2>&1 | FileCheck 
%s -check-prefix=VEVPU
+// RUN: %clang -target ve-unknown-linux-gnu -### %s -mno-vevpu 2>&1 | 
FileCheck %s -check-prefix=NO-VEVPU

kaz7 wrote:
> MaskRay wrote:
> > kaz7 wrote:
> > > MaskRay wrote:
> > > > `-target ` has been deprecated since Clang 3.4. Use `--target=`
> > > I didn't know that.  Thank you!
> > I think we typically spend just two RUN lines:
> > 
> > * one for the default
> > * one for `-mvevpu -mno-vevpu`
> > 
> > The additional coverage for having 3 RUN lines is probably not useful.
> Thank you for suggesting.  I consider what this patch should do and change 
> the purpose to support VPU flag in the backend for VE.  As a result, Tests 
> are two RUN lines.
> 
> - one for enable VPU
> - one for disable VPU
Because we use hasFlag with default value, test is changed again for following 
two RUN lines.
- one for the default
- one for `-mvevpu -mno-vevpu`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157813

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


[clang] 2263dfe - [test] Correct PS5 triple in clang :: Driver/unified-lto.c

2023-08-30 Thread Matthew Voss via cfe-commits

Author: Matthew Voss
Date: 2023-08-30T08:45:16-07:00
New Revision: 2263dfe368ce4925eb9f1fdcd11ff50455f546af

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

LOG: [test] Correct PS5 triple in clang :: Driver/unified-lto.c

Added: 


Modified: 
clang/test/Driver/unified-lto.c

Removed: 




diff  --git a/clang/test/Driver/unified-lto.c b/clang/test/Driver/unified-lto.c
index e16affe2c5efda..3a6fe44f5b32df 100644
--- a/clang/test/Driver/unified-lto.c
+++ b/clang/test/Driver/unified-lto.c
@@ -6,7 +6,7 @@
 // UNIT: "-flto-unit"
 // NOUNIT-NOT: "-flto-unit"
 
-// RUN: %clang --target=x86_64-sie-prospero -### %s -funified-lto 2>&1 | 
FileCheck --check-prefix=NOUNILTO %s
+// RUN: %clang --target=x86_64-sie-ps5 -### %s -funified-lto 2>&1 | FileCheck 
--check-prefix=NOUNILTO %s
 // NOUNILTO: clang: warning: argument unused during compilation: 
'-funified-lto'
 // NOUNILTO: "-cc1"
 // NOUNILTO-NOT: "-funified-lto



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


[PATCH] D157813: [Driver][VE] Change to enable VPU flag by default

2023-08-30 Thread Kazushi Marukawa via Phabricator via cfe-commits
kaz7 marked an inline comment as done.
kaz7 added a comment.

Thank you for correction.  I clean code again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157813

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


[PATCH] D158255: [RISCV][NFC] Update compile options for some vector crypto C intrinsics

2023-08-30 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper 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/D158255/new/

https://reviews.llvm.org/D158255

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


[PATCH] D159105: [analyzer] ArrayBoundCheckerV2 should check the region for taint as well

2023-08-30 Thread Balázs Benics via Phabricator via cfe-commits
steakhal planned changes to this revision.
steakhal added a comment.

In D159105#4627883 , @donat.nagy 
wrote:

> In D159105#4627785 , @steakhal 
> wrote:
>
>> In D159105#4627724 , @donat.nagy 
>> wrote:
>>
>>> I fear that the overzealous handling of tainted data would produce too many 
>>> false positives in situations when code indexes strings that contain user 
>>> input and the SA engine cannot understand the logic that calculates the 
>>> indices. For example if I understand it correctly a function like
>>>
>>>   char f(int n) {
>>> char *var = getenv("FOO");
>>> return var[n];
>>>   }
>>>
>>> would be reported as an out of bounds memory access, because the region is 
>>> tainted and the index value is not known. This is especially problematic on 
>>> the underflow side (which is introduced by your commit), because I'd assume 
>>> that it's common to have numeric values (e.g. function arguments) where the 
>>> programmer knows that they're nonnegative, but the analyzer cannot deduce 
>>> this.
>>
>> To me, this is a TP. The envvar might not be present, and even if it's 
>> present, the relation of the string length of `var` to `n` is not expressed 
>> or checked; thus this deserves a report.
>> But I see your concern, however, I cannot think of valid counterexamples, 
>> aka. FPs off the top of my head. I'll come back once I see the real results.
>
> Hmm, you're right that my example is a TP as written; however I could imagine 
> similar FPs where we e.g. check that `n < strlen(var)` but don't check that 
> `n` is nonnegative (because that's the responsibility of the caller).
>
> Anyway, let's wait for the test results, they'll be enlightening. (You mostly 
> convinced me that your commit will work, but Murphy's laws are still 
> standing...)

I have the results now, I just need to evaluate it. It turns out to require 
some scripting, as we sooner detect out-of-bounds accesses (by not allowing to 
form an lvalue to such) the locations change.
Because of this changed location, I have to filter out the cases when the "same 
line" has a report "disappearing" and "appearing".
The sooner detection also means that I have more paths killed, thus "in the 
close proximity below the appearing issue some others disappear - if they are 
dominated".
I have to manually check these because that diff is sort of intentional; to see 
what's left and look for unintentional cases.

I can already confirm an issue though, similar to the one you showed, and 
similar variants:

  char *str = getenv(name);
  if (str && str[0])
return atoi(str);
  return 0;

This sort of code looks good, and I'll think about how to suppress them.
Probably, because of this, we have a huge relative increase for `Out of bound 
memory access (index is tainted)` diagnostics (+72%, +447).
The second biggest relative change was for `Out of bound memory access (access 
exceeds upper limit of memory block)` (+18%, +1862).
These are preliminary numbers, and I'll continue the validation.

>>> Also note that the error message "Out of bound memory access (index is 
>>> tainted)" becomes misleading after this patch -- but don't spend too much 
>>> time on resolving this, because right now I'm working on a complete rewrite 
>>> the message generation to replace the current spartan messages with useful 
>>> error reporting.
>>
>> I agree, but I'm not sure how much more readable something more accurate 
>> like "the location where this pointer points to potentially depends on 
>> untrusted tainted data". (Note that this would also work for tainted indexes 
>> as well).
>>
>> I must admit, that reporting and diagnostics were low priorities for this 
>> patch stack, so I'd focus on addressing logic concerns first for the whole 
>> stack and then come back to reporting to make it consistent across the stack.
>
> Improving reporting and diagnostics is also on my TODO list, so we should 
> coordinate progress in that area to avoid redundant work. If you wish to work 
> on it, then I'm happy to review; otherwise I'll do something with it soon 
> (perhaps after you merged these commits to avoid merge conflicts).

I don't plan to work on the checker.

I'll post the result of the evaluation, once I'm happy with the findings. This 
might need some iterations.

Thanks for the review!
And sorry that I haven't done this evaluation before I posted these for review. 
Usually, it takes more time for the community to review patches - but this was 
a pleasant surprise!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159105

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


[PATCH] D141714: Fix ast print of variables with attributes

2023-08-30 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I think we can do better naming the tablegen'ed parts, else a bunch of smaller 
changes.  Approach seems good enough to me, though Aaron should scroll 
through/make a determination after you've fixed my concerns.




Comment at: clang/include/clang/Basic/Attr.td:565
 class Attr {
+  // On a declaration, can this attribute be print on the left side?
+  bit CanPrintOnLeftSide = 1;





Comment at: clang/include/clang/Basic/Attr.td:566
+  // On a declaration, can this attribute be print on the left side?
+  bit CanPrintOnLeftSide = 1;
+  // On a declaration, must this attribute be print on the left side?





Comment at: clang/include/clang/Basic/Attr.td:567
+  bit CanPrintOnLeftSide = 1;
+  // On a declaration, must this attribute be print on the left side?
+  bit MustPrintOnLeftSide = 0;





Comment at: clang/include/clang/Basic/Attr.td:568
+  // On a declaration, must this attribute be print on the left side?
+  bit MustPrintOnLeftSide = 0;
   // The various ways in which an attribute can be spelled in source





Comment at: clang/lib/AST/DeclPrinter.cpp:263
+static bool canPrintOnLeftSide(const Attr *A) {
+  if (A->isStandardAttributeSyntax()) {
+return false;

Don't include curley brackets here.



Comment at: clang/lib/AST/DeclPrinter.cpp:280
+static bool mustPrintOnLeftSide(const Attr *A) {
+  if (A->isDeclspecAttribute()) {
+return true;

Same here, don't use curleys on single-liners.



Comment at: clang/lib/AST/DeclPrinter.cpp:298
+
+  AttrPrintLoc attrloc = AttrPrintLoc::Right;
+  if (mustPrintOnLeftSide(A)) {





Comment at: clang/lib/AST/DeclPrinter.cpp:306
+// side so that GCC accept our dumps as well.
+if (const FunctionDecl *FD = dyn_cast(D);
+FD && FD->isThisDeclarationADefinition()) {





Comment at: clang/lib/AST/DeclPrinter.cpp:314
+  // printing on the left side for readbility.
+} else if (const VarDecl *VD = dyn_cast(D);
+   VD && VD->getInit() &&





Comment at: clang/lib/AST/DeclPrinter.cpp:1003
 
-  printDeclType(T, (isa(D) && Policy.CleanUglifiedParameters &&
-D->getIdentifier())
-   ? D->getIdentifier()->deuglifiedName()
-   : D->getName());
+  std::string Name;
+

Instead of making this a std::string, make it a StringRef and just assign it on 
line 1005, it looks like both sides of that return a StringRef (deuglifiedName 
and getName), and your += is unnecessary (since there is nothing in Name here 
anyway).



Comment at: clang/utils/TableGen/TableGen.cpp:282
"Generate riscv_vector_builtin_sema.inc for clang"),
-clEnumValN(GenRISCVSiFiveVectorBuiltins, 
"gen-riscv-sifive-vector-builtins",
+clEnumValN(GenRISCVSiFiveVectorBuiltins,
+   "gen-riscv-sifive-vector-builtins",

Unrelated changes, please remove.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141714

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


[PATCH] D148131: Avoid unnecessarily aggressive line-breaking when using "LambdaBodyIndentation: OuterScope" with argument bin-packing.

2023-08-30 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

But please wait for other opinions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148131

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


[PATCH] D159145: [RISCV] Don't add -unaligned-scalar-mem to target features by default.

2023-08-30 Thread Wang Pengcheng via Phabricator via cfe-commits
wangpc accepted this revision.
wangpc 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/D159145/new/

https://reviews.llvm.org/D159145

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


[PATCH] D159213: [AIX][ClangRepl] Disable new tests on AIX

2023-08-30 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan created this revision.
Herald added a project: All.
Jake-Egan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159213

Files:
  clang/unittests/Interpreter/CodeCompletionTest.cpp


Index: clang/unittests/Interpreter/CodeCompletionTest.cpp
===
--- clang/unittests/Interpreter/CodeCompletionTest.cpp
+++ clang/unittests/Interpreter/CodeCompletionTest.cpp
@@ -50,7 +50,11 @@
   return Comps;
 }
 
+#ifdef _AIX
+TEST(CodeCompletionTest, DISABLED_Sanity) {
+#else
 TEST(CodeCompletionTest, Sanity) {
+#endif
   auto Interp = createInterpreter();
   if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
 consumeError(std::move(R));
@@ -63,7 +67,11 @@
   EXPECT_EQ((bool)Err, false);
 }
 
+#ifdef _AIX
+TEST(CodeCompletionTest, DISABLED_SanityNoneValid) {
+#else
 TEST(CodeCompletionTest, SanityNoneValid) {
+#endif
   auto Interp = createInterpreter();
   if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
 consumeError(std::move(R));
@@ -75,7 +83,11 @@
   EXPECT_EQ((bool)Err, false);
 }
 
+#ifdef _AIX
+TEST(CodeCompletionTest, DISABLED_TwoDecls) {
+#else
 TEST(CodeCompletionTest, TwoDecls) {
+#endif
   auto Interp = createInterpreter();
   if (auto R = Interp->ParseAndExecute("int application = 12;")) {
 consumeError(std::move(R));


Index: clang/unittests/Interpreter/CodeCompletionTest.cpp
===
--- clang/unittests/Interpreter/CodeCompletionTest.cpp
+++ clang/unittests/Interpreter/CodeCompletionTest.cpp
@@ -50,7 +50,11 @@
   return Comps;
 }
 
+#ifdef _AIX
+TEST(CodeCompletionTest, DISABLED_Sanity) {
+#else
 TEST(CodeCompletionTest, Sanity) {
+#endif
   auto Interp = createInterpreter();
   if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
 consumeError(std::move(R));
@@ -63,7 +67,11 @@
   EXPECT_EQ((bool)Err, false);
 }
 
+#ifdef _AIX
+TEST(CodeCompletionTest, DISABLED_SanityNoneValid) {
+#else
 TEST(CodeCompletionTest, SanityNoneValid) {
+#endif
   auto Interp = createInterpreter();
   if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
 consumeError(std::move(R));
@@ -75,7 +83,11 @@
   EXPECT_EQ((bool)Err, false);
 }
 
+#ifdef _AIX
+TEST(CodeCompletionTest, DISABLED_TwoDecls) {
+#else
 TEST(CodeCompletionTest, TwoDecls) {
+#endif
   auto Interp = createInterpreter();
   if (auto R = Interp->ParseAndExecute("int application = 12;")) {
 consumeError(std::move(R));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153339: [clang] Support vectors in __builtin_isfpclass

2023-08-30 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 554750.
sepavloff added a comment.

Update documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153339

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/isfpclass.c

Index: clang/test/CodeGen/isfpclass.c
===
--- clang/test/CodeGen/isfpclass.c
+++ clang/test/CodeGen/isfpclass.c
@@ -15,7 +15,7 @@
 // CHECK-LABEL: define dso_local i1 @check_isfpclass_finite_strict
 // CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 504) #[[ATTR5:[0-9]+]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 504) #[[ATTR6:[0-9]+]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isfpclass_finite_strict(float x) {
@@ -36,7 +36,7 @@
 // CHECK-LABEL: define dso_local i1 @check_isfpclass_nan_f32_strict
 // CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 3) #[[ATTR5]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 3) #[[ATTR6]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isfpclass_nan_f32_strict(float x) {
@@ -57,7 +57,7 @@
 // CHECK-LABEL: define dso_local i1 @check_isfpclass_snan_f64_strict
 // CHECK-SAME: (double noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f64(double [[X]], i32 1) #[[ATTR5]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f64(double [[X]], i32 1) #[[ATTR6]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isfpclass_snan_f64_strict(double x) {
@@ -78,7 +78,7 @@
 // CHECK-LABEL: define dso_local i1 @check_isfpclass_zero_f16_strict
 // CHECK-SAME: (half noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f16(half [[X]], i32 96) #[[ATTR5]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f16(half [[X]], i32 96) #[[ATTR6]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isfpclass_zero_f16_strict(_Float16 x) {
@@ -89,7 +89,7 @@
 // CHECK-LABEL: define dso_local i1 @check_isnan
 // CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 3) #[[ATTR5]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 3) #[[ATTR6]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isnan(float x) {
@@ -100,7 +100,7 @@
 // CHECK-LABEL: define dso_local i1 @check_isinf
 // CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 516) #[[ATTR5]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 516) #[[ATTR6]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isinf(float x) {
@@ -111,7 +111,7 @@
 // CHECK-LABEL: define dso_local i1 @check_isfinite
 // CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 504) #[[ATTR5]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 504) #[[ATTR6]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isfinite(float x) {
@@ -122,7 +122,7 @@
 // CHECK-LABEL: define dso_local i1 @check_isnormal
 // CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 264) #[[ATTR5]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X]], i32 264) #[[ATTR6]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isnormal(float x) {
@@ -130,3 +130,44 @@
   return __builtin_isnormal(x);
 }
 
+
+typedef float __attribute__((ext_vector_type(4))) float4;
+typedef double __attribute__((ext_vector_type(4))) double4;
+typedef int __attribute__((ext_vector_type(4))) int4;
+typedef long __attribute__((ext_vector_type(4))) long4;
+
+// CHECK-LABEL: define dso_local <4 x i32> @check_isfpclass_nan_v4f32
+// CHECK-SAME: (<4 x float> noundef [[X:%.*]]) local_unnamed_addr #[[ATTR3]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = fcmp uno <4 x float> [[X]], zeroinitializer
+// CHECK-NEXT:[[TMP1:%.*]] = zext <4 x i1> [[TMP0]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP1]]
+//
+int4 check_isfpclass_nan_v4f32(float4 x) {
+  return __builtin_isfpclass(x, 3 /*NaN*/);
+}
+
+// CH

[PATCH] D158614: [UBSan] Disable the function sanitizer on an execute-only target.

2023-08-30 Thread Ying Yi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ef536a12ea6: [UBSan] Disable the function and kcfi 
sanitizers on an execute-only target. (authored by MaggieYi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158614

Files:
  clang/include/clang/Basic/Sanitizers.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Sanitizers.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGenObjCXX/crash-function-type.mm
  clang/test/Driver/fsanitize.c

Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -966,3 +966,17 @@
 
 // RUN: not %clang --target=x86_64-linux-gnu -fsanitize=undefined,function -mcmodel=large %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-CODE-MODEL
 // CHECK-UBSAN-FUNCTION-CODE-MODEL: error: invalid argument '-fsanitize=function' only allowed with '-mcmodel=small'
+
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=undefined -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function -fsanitize=kcfi %s -### 2>&1 | FileCheck %s  --check-prefix=CHECK-UBSAN-KCFI --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: %clang --target=x86_64-sie-ps5 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
+
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
+// RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
+
+// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-UNDEFINED: "-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound),?){17}"}}
Index: clang/test/CodeGenObjCXX/crash-function-type.mm
===
--- clang/test/CodeGenObjCXX/crash-function-type.mm
+++ clang/test/CodeGenObjCXX/crash-function-type.mm
@@ -1,3 +1,6 @@
+// Mark test as unsupported on PS5 due to PS5 doesn't support function sanitizer.
+// UNSUPPORTED: target=x86_64-sie-ps5
+
 // RUN: %clang_cc1 -fblocks -fsanitize=function -emit-llvm %s -o %t
 
 void g(void (^)());
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -37,6 +37,8 @@
 SanitizerKind::Vptr | SanitizerKind::CFI;
 static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
 static const SanitizerMask NotAllowedWithMinimalRuntime = SanitizerKind::Vptr;
+static const SanitizerMask NotAllowedWithExecuteOnly =
+SanitizerKind::Function | SanitizerKind::KCFI;
 static const SanitizerMask RequiresPIE =
 SanitizerKind::DataFlow | SanitizerKind::Scudo;
 static const SanitizerMask NeedsUnwindTables =
@@ -395,6 +397,22 @@
   DiagnosedKinds |= SanitizerKind::Function;
 }
   }
+  // -fsanitize=function and -fsanitize=kcfi instrument indirect function
+  // calls to load a type hash before the function label. Therefore, an
+  // execute-only target doesn't support the function and kcfi sanitizers.
+  const llvm::Triple &Triple = TC.getTriple();
+  if (isExecuteOnlyTarget(Triple, Args)) {
+if (SanitizerMask KindsToDiagnose =
+Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) {
+  if (DiagnoseErrors) {
+std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
+D.Diag(diag::err_drv_argument_not_allowed_with)
+<< Desc << Triple.str();
+  }
+  DiagnosedKinds |= KindsToDiagnose;
+}
+Add &= ~NotAllowedWithExecuteOnly;
+  }
 
   // FIXME: Make CFI on member function calls compatible with cross-DSO CFI.
   // There are currently two problems:
@@ -457,6 +475,10 @@
   if (MinimalRuntime) {
 Add &= ~NotAllowedWithMinimalRuntime;
   }
+  // NotAllowedW

[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-08-30 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D152495#4628028 , @goncharov wrote:

> there is a number of unused vaiables in conditional loops that are firing 
> now, I have submitted  
> https://github.com/llvm/llvm-project/commit/74f4daef0412be33002bd4e24a30cb47d0187ecf
>  but I suspect it's just a start.
> How did you checked the project code for that?

Per rG01b88dd66d9d52d3f531a7d490e18c549f36f445 
, unused 
`dyn_cast` results should turn into `isa`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152495

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


[PATCH] D154869: [Flang] [FlangRT] Introduce FlangRT project as solution to Flang's runtime LLVM integration

2023-08-30 Thread Mark Danial via Phabricator via cfe-commits
madanial added a comment.

Pinging for review. I will be taking over this patch from Paul, but Paul will 
still be around to answer any questions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154869

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


[clang] 9ef536a - [UBSan] Disable the function and kcfi sanitizers on an execute-only target.

2023-08-30 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2023-08-30T17:17:37+01:00
New Revision: 9ef536a12ea65a2b9e2511936327c7b621af38fb

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

LOG: [UBSan] Disable the function and kcfi sanitizers on an execute-only target.

An execute-only target disallows data access to code sections.
-fsanitize=function and -fsanitize=kcfi instrument indirect function
calls to load a type hash before the function label. This results in a
non-execute access to the code section and a runtime error.

To solve the issue, -fsanitize=function should not be included in any
check group (e.g. undefined) on an execute-only target. If a user passes
-fsanitize=undefined, there is no error and no warning. However, if the
user explicitly passes -fsanitize=function or -fsanitize=kcfi on an
execute-only target, an error will be emitted.

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

Reviewed By: MaskRay, probinson, simon_tatham

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

Added: 


Modified: 
clang/include/clang/Basic/Sanitizers.h
clang/lib/Basic/CMakeLists.txt
clang/lib/Basic/Sanitizers.cpp
clang/lib/Driver/SanitizerArgs.cpp
clang/test/CodeGenObjCXX/crash-function-type.mm
clang/test/Driver/fsanitize.c

Removed: 




diff  --git a/clang/include/clang/Basic/Sanitizers.h 
b/clang/include/clang/Basic/Sanitizers.h
index db53010645ae3b..c212f80fe03adc 100644
--- a/clang/include/clang/Basic/Sanitizers.h
+++ b/clang/include/clang/Basic/Sanitizers.h
@@ -23,7 +23,11 @@
 
 namespace llvm {
 class hash_code;
+class Triple;
+namespace opt {
+class ArgList;
 }
+} // namespace llvm
 
 namespace clang {
 
@@ -205,6 +209,11 @@ StringRef AsanDetectStackUseAfterReturnModeToString(
 llvm::AsanDetectStackUseAfterReturnMode
 AsanDetectStackUseAfterReturnModeFromString(StringRef modeStr);
 
+/// Return true if an execute-only target disallows data access to code
+/// sections.
+bool isExecuteOnlyTarget(const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args);
+
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_SANITIZERS_H

diff  --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index db59d7dd96da0a..f93ee707dab470 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_LINK_COMPONENTS
+  Option
   Support
   TargetParser
   )

diff  --git a/clang/lib/Basic/Sanitizers.cpp b/clang/lib/Basic/Sanitizers.cpp
index 62ccdf8e9bbf28..6fbc32df314896 100644
--- a/clang/lib/Basic/Sanitizers.cpp
+++ b/clang/lib/Basic/Sanitizers.cpp
@@ -11,10 +11,13 @@
 
//===--===//
 
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Driver/Options.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Option/ArgList.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/TargetParser/Triple.h"
 
 using namespace clang;
 
@@ -112,4 +115,14 @@ AsanDetectStackUseAfterReturnModeFromString(StringRef 
modeStr) {
   .Default(llvm::AsanDetectStackUseAfterReturnMode::Invalid);
 }
 
+bool isExecuteOnlyTarget(const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args) {
+  if (Triple.isPS5())
+return true;
+
+  // On Arm, the clang `-mexecute-only` option is used to generate the
+  // execute-only output (no data access to code sections).
+  return Args.hasFlag(clang::driver::options::OPT_mexecute_only,
+  clang::driver::options::OPT_mno_execute_only, false);
+}
 } // namespace clang

diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 12f7e9fb9d2966..71968a47fbf4fc 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -37,6 +37,8 @@ static const SanitizerMask NeedsUbsanCxxRt =
 SanitizerKind::Vptr | SanitizerKind::CFI;
 static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
 static const SanitizerMask NotAllowedWithMinimalRuntime = SanitizerKind::Vptr;
+static const SanitizerMask NotAllowedWithExecuteOnly =
+SanitizerKind::Function | SanitizerKind::KCFI;
 static const SanitizerMask RequiresPIE =
 SanitizerKind::DataFlow | SanitizerKind::Scudo;
 static const SanitizerMask NeedsUnwindTables =
@@ -395,6 +397,22 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   DiagnosedKinds |= SanitizerKind::Function;
 }
   }
+  // -fsanitize=function and -fsanitize=kcfi instrument indirect function
+  // calls to load a type hash before the function label. Therefore, an
+  // execute-only target doesn't support the function and kcfi sanitizers.
+  const llvm::Triple &Triple = TC.getTriple();
+

[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-08-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

It is used, but only in an assert. Seems like the right fix!

In D152495#4628778 , @smeenai wrote:

> In D152495#4628028 , @goncharov 
> wrote:
>
>> there is a number of unused vaiables in conditional loops that are firing 
>> now, I have submitted  
>> https://github.com/llvm/llvm-project/commit/74f4daef0412be33002bd4e24a30cb47d0187ecf
>>  but I suspect it's just a start.
>> How did you checked the project code for that?
>
> Per rG01b88dd66d9d52d3f531a7d490e18c549f36f445 
> , unused 
> `dyn_cast` results should turn into `isa`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152495

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


[PATCH] D159206: [Clang] Propagate target-features if compatible when using mlink-builtin-bitcode

2023-08-30 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez marked 2 inline comments as done.
jmmartinez added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2034
+  }
+
+  FuncAttr.addAttribute("target-features", llvm::join(MergedFeatures, ","));

arsenm wrote:
> Really it would be less bad if the incompatible functions were not imported 
> rather than the backend pass
I thought it was possible to have functions with incompatible features in the 
same module. 
e.g. one function compiled with some instruction set support, one without, and 
an ifunc that resolves to one or the other.

Maybe it's not the case in the context of `-mlink-builtin-bitcode`?



Comment at: clang/test/CodeGen/link-builtin-bitcode.c:17
+int __attribute__((target("extended-image-insts"))) attr_not_in_target(void) { 
return 42; }
+int __attribute__((target("no-gfx9-insts"))) attr_uncompatible(void) { return 
42; }
 int x = 12;

arsenm wrote:
> This isn't a real target feature (do we not have a warning on this?)
> 
> s/uncompatible/incompatible
Only when the feature doesn't map to any "+" or "-" feature.

If I use "foo-insts" I get a warning because there are no +foo-insts / 
-foo-insts (and it still ends up in the generated llvm-ir)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159206

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


[PATCH] D159206: [Clang] Propagate target-features if compatible when using mlink-builtin-bitcode

2023-08-30 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez updated this revision to Diff 554753.
jmmartinez marked an inline comment as done.
jmmartinez added a comment.

- Drop incoming builtins with incompatible target-features


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159206

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCall.h
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/link-builtin-bitcode.c
  clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu

Index: clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
===
--- clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
+++ clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
@@ -31,7 +31,7 @@
 
 
 // CHECK: define {{.*}} i64 @do_intrin_stuff() #[[ATTR:[0-9]+]]
-// INTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-cpu"="gfx{{.*}}" "target-features"="+gfx11-insts"
+// INTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-cpu"="gfx{{.*}}" "target-features"="{{.*}}+gfx11-insts{{.*}}"
 // NOINTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-features"="+gfx11-insts"
 
 #define __device__ __attribute__((device))
Index: clang/test/CodeGen/link-builtin-bitcode.c
===
--- clang/test/CodeGen/link-builtin-bitcode.c
+++ clang/test/CodeGen/link-builtin-bitcode.c
@@ -1,42 +1,47 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --check-globals --include-generated-funcs --version 2
+// Build two version of the bitcode library, one with a target-cpu set and one without
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx803 -DBITCODE -emit-llvm-bc -o %t-lib.bc %s
+// RUN: %clang_cc1 -triple amdgcn-- -DBITCODE -emit-llvm-bc -o %t-lib.no-cpu.bc %s
+
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm-bc -o %t.bc %s
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm \
 // RUN:   -mlink-builtin-bitcode %t-lib.bc -o - %t.bc | FileCheck %s
 
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm-bc -o %t.bc %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm \
+// RUN:   -mlink-builtin-bitcode %t-lib.no-cpu.bc -o - %t.bc | FileCheck %s
+
 #ifdef BITCODE
-int foo(void) { return 42; }
+int no_attr(void) { return 42; }
+int __attribute__((target("gfx8-insts"))) attr_in_target(void) { return 42; }
+int __attribute__((target("extended-image-insts"))) attr_not_in_target(void) { return 42; }
+int __attribute__((target("no-gfx9-insts"))) attr_incompatible(void) { return 42; }
 int x = 12;
 #endif
 
-extern int foo(void);
+extern int no_attr(void);
+extern int attr_in_target(void);
+extern int attr_not_in_target(void);
+extern int attr_incompatible(void);
 extern int x;
 
-int bar() { return foo() + x; }
-//.
+int bar() { return no_attr() + attr_in_target() + attr_not_in_target() + attr_incompatible() + x; }
+
 // CHECK: @x = internal addrspace(1) global i32 12, align 4
-//.
-// CHECK: Function Attrs: noinline nounwind optnone
+
 // CHECK-LABEL: define dso_local i32 @bar
-// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4, addrspace(5)
-// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
-// CHECK-NEXT:[[CALL:%.*]] = call i32 @foo()
-// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr addrspacecast (ptr addrspace(1) @x to ptr), align 4
-// CHECK-NEXT:[[ADD:%.*]] = add nsw i32 [[CALL]], [[TMP0]]
-// CHECK-NEXT:ret i32 [[ADD]]
+// CHECK-SAME: () #[[ATTR_BAR:[0-9]+]] {
 //
-//
-// CHECK: Function Attrs: convergent noinline nounwind optnone
-// CHECK-LABEL: define internal i32 @foo
-// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4, addrspace(5)
-// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
-// CHECK-NEXT:ret i32 42
-//
-//.
-// CHECK: attributes #0 = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx90a" "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" }
-// CHECK: attributes #1 = { convergent noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx90a" "target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" }
-//.
+// CHECK-LABEL: define internal i32 @no_attr
+// CHECK-SAME: () #[[ATTR_COMPATIBLE:[0-9]+]] {
+
+// CHECK-LABEL: define internal i32 @attr_in_target
+// CHECK-SAME: () #

[PATCH] D159206: [Clang] Propagate target-features if compatible when using mlink-builtin-bitcode

2023-08-30 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez added inline comments.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:282
   }
+}
 

Remove { }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159206

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


[PATCH] D153924: [OpenMP] Allow exceptions in target regions when offloading to GPUs

2023-08-30 Thread Anton Rydahl 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 rG3c9988f85d25: [OpenMP] Allow exceptions in target regions 
when offloading to GPUs (authored by AntonRydahl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153924

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CGException.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/OpenMP/amdgpu_exceptions.cpp
  clang/test/OpenMP/amdgpu_throw.cpp
  clang/test/OpenMP/amdgpu_throw_trap.cpp
  clang/test/OpenMP/amdgpu_try_catch.cpp
  clang/test/OpenMP/nvptx_exceptions.cpp
  clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
  clang/test/OpenMP/nvptx_throw.cpp
  clang/test/OpenMP/nvptx_throw_trap.cpp
  clang/test/OpenMP/nvptx_try_catch.cpp
  clang/test/OpenMP/x86_target_exceptions.cpp
  clang/test/OpenMP/x86_target_throw.cpp
  clang/test/OpenMP/x86_target_try_catch.cpp

Index: clang/test/OpenMP/x86_target_try_catch.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_try_catch.cpp
@@ -0,0 +1,16 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -analyze
+#pragma omp declare target
+int foo(void) {
+	int error = -1;
+	try {
+		error = 1;
+	}
+	catch (int e){ 
+		error = e;
+	}
+	return error;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/x86_target_throw.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_throw.cpp
@@ -0,0 +1,9 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -analyze
+#pragma omp declare target
+void foo(void) {
+	throw 404;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/x86_target_exceptions.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_exceptions.cpp
@@ -0,0 +1,16 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -analyze
+#pragma omp declare target
+int foo(void) {
+	int error = -1;
+	try {
+		throw 404;
+	}
+	catch (int e){ 
+		error = e;
+	}
+	return error;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/nvptx_try_catch.cpp
===
--- /dev/null
+++ clang/test/OpenMP/nvptx_try_catch.cpp
@@ -0,0 +1,47 @@
+// REQUIRES: nvptx-registered-target
+
+/**
+ * The first four lines test that a warning is produced when enabling 
+ * -Wopenmp-target-exception no matter what combination of -fexceptions and 
+ * -fcxx-exceptions are set, as we want OpenMP to always allow exceptions in the
+ * target region but emit a warning instead.
+*/
+
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+
+/**
+ * The following four lines test that no warning is emitted when providing 
+ * -Wno-openmp-target-exception no matter the combination of -fexceptions and 
+ * -fcxx-exceptions.
+*/
+
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fexceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+
+/**
+ * Finally we should test that we only ignore exceptions in the OpenMP 
+ * offloading tool-chain
+*/
+
+// RUN: %clang_cc1 -triple nvptx64 %s -emit-llvm -S -verify=noexceptions 

[clang] 3c9988f - [OpenMP] Allow exceptions in target regions when offloading to GPUs

2023-08-30 Thread via cfe-commits

Author: Anton Rydahl
Date: 2023-08-30T09:36:22-07:00
New Revision: 3c9988f85d2508bdbc64c81fed7c4b9b8db54262

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

LOG: [OpenMP] Allow exceptions in target regions when offloading to GPUs

The motivation for this patch is that many code bases use exception handling. 
As GPUs are not expected to support exception handling in the near future, we 
can experiment with compiling the code for GPU targets anyway. This will
allow us to run the code, as long as no exception is thrown.

The overall idea is very simple:
- If a throw expression is compiled to AMDGCN or NVPTX, it is replaced with a 
trap during code generation.
- If a try/catch statement is compiled to AMDGCN or NVPTX, we generate code for 
the try statement as if it were a basic block.

With this patch, the compilation of the following example
```
int gaussian_sum(int a,int b){
if ((a + b) % 2 == 0) {throw -1;};
return (a+b) * ((a+b)/2);
}

int main(void) {
int gauss = 0;
#pragma omp target map(from:gauss)
{
try {
gauss = gaussian_sum(1,100);
}
catch (int e){
gauss = e;
}
}
std::cout << "GaussianSum(1,100)=";
 def err_opencl_feature_requires : Error<
   "feature %0 requires support of %1 feature">;
+
+def warn_throw_not_valid_on_target : Warning<
+  "target '%0' does not support exception handling;"
+  " 'throw' is assumed to be never reached">,
+  InGroup;
+def warn_try_not_valid_on_target : Warning<
+  "target '%0' does not support exception handling;"
+  " 'catch' block is ignored">,
+  InGroup;
 }

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d1aa51393ef357..00c458fb23e73e 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1292,9 +1292,10 @@ def OpenMPTarget : DiagGroup<"openmp-target", 
[OpenMPMapping]>;
 def OpenMPPre51Compat : DiagGroup<"pre-openmp-51-compat">;
 def OpenMP51Ext : DiagGroup<"openmp-51-extensions">;
 def OpenMPExtensions : DiagGroup<"openmp-extensions">;
+def OpenMPTargetException : DiagGroup<"openmp-target-exception">;
 def OpenMP : DiagGroup<"openmp", [
 SourceUsesOpenMP, OpenMPClauses, OpenMPLoopForm, OpenMPTarget,
-OpenMPMapping, OpenMP51Ext, OpenMPExtensions
+OpenMPMapping, OpenMP51Ext, OpenMPExtensions, OpenMPTargetException
   ]>;
 
 // Backend warnings.

diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 9cb7d4c7731deb..3996f2948349cb 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -440,6 +440,15 @@ llvm::Value *CodeGenFunction::getSelectorFromSlot() {
 
 void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E,
bool KeepInsertionPoint) {
+  // If the exception is being emitted in an OpenMP target region,
+  // and the target is a GPU, we do not support exception handling.
+  // Therefore, we emit a trap which will abort the program, and
+  // prompt a warning indicating that a trap will be emitted.
+  const llvm::Triple &T = Target.getTriple();
+  if (CGM.getLangOpts().OpenMPIsTargetDevice && (T.isNVPTX() || T.isAMDGCN())) 
{
+EmitTrapCall(llvm::Intrinsic::trap);
+return;
+  }
   if (const Expr *SubExpr = E->getSubExpr()) {
 QualType ThrowType = SubExpr->getType();
 if (ThrowType->isObjCObjectPointerType()) {
@@ -6

[PATCH] D158963: [CodeGen] Function multi-versioning: don't set comdat for internal linkage resolvers

2023-08-30 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 554756.
MaskRay edited the summary of this revision.
MaskRay added a comment.

add release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158963

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-target-clones.c
  clang/test/CodeGen/attr-target-mv.c


Index: clang/test/CodeGen/attr-target-mv.c
===
--- clang/test/CodeGen/attr-target-mv.c
+++ clang/test/CodeGen/attr-target-mv.c
@@ -32,6 +32,13 @@
   return foo();
 }
 
+static int __attribute__((target("arch=meteorlake"))) foo_internal(void) 
{return 15;}
+static int __attribute__((target("default"))) foo_internal(void) { return 2; }
+
+int bar1(void) {
+  return foo_internal();
+}
+
 inline int __attribute__((target("sse4.2"))) foo_inline(void) { return 0; }
 inline int __attribute__((target("arch=sandybridge"))) foo_inline(void);
 inline int __attribute__((target("arch=ivybridge"))) foo_inline(void) {return 
1;}
@@ -128,6 +135,7 @@
 
 
 // LINUX: @foo.ifunc = weak_odr ifunc i32 (), ptr @foo.resolver
+// LINUX: @foo_internal.ifunc = internal ifunc i32 (), ptr 
@foo_internal.resolver
 // LINUX: @foo_inline.ifunc = weak_odr ifunc i32 (), ptr @foo_inline.resolver
 // LINUX: @foo_decls.ifunc = weak_odr ifunc void (), ptr @foo_decls.resolver
 // LINUX: @foo_multi.ifunc = weak_odr ifunc void (i32, double), ptr 
@foo_multi.resolver
@@ -254,6 +262,11 @@
 // WINDOWS: call i32 @foo.sse4.2
 // WINDOWS: call i32 @foo
 
+/// Internal linkage resolvers do not use comdat.
+// LINUX: define internal ptr @foo_internal.resolver() {
+
+// WINDOWS: define internal i32 @foo_internal.resolver() {
+
 // LINUX: define{{.*}} i32 @bar2()
 // LINUX: call i32 @foo_inline.ifunc()
 
Index: clang/test/CodeGen/attr-target-clones.c
===
--- clang/test/CodeGen/attr-target-clones.c
+++ clang/test/CodeGen/attr-target-clones.c
@@ -16,6 +16,7 @@
 // LINUX: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] }
 // LINUX: @__cpu_features2 = external dso_local global [3 x i32]
 
+// LINUX: @internal.ifunc = internal ifunc i32 (), ptr @internal.resolver
 // LINUX: @foo.ifunc = weak_odr ifunc i32 (), ptr @foo.resolver
 // LINUX: @foo_dupes.ifunc = weak_odr ifunc void (), ptr @foo_dupes.resolver
 // LINUX: @unused.ifunc = weak_odr ifunc void (), ptr @unused.resolver
@@ -23,6 +24,12 @@
 // LINUX: @foo_inline2.ifunc = weak_odr ifunc i32 (), ptr @foo_inline2.resolver
 // LINUX: @foo_used_no_defn.ifunc = weak_odr ifunc i32 (), ptr 
@foo_used_no_defn.resolver
 
+static int __attribute__((target_clones("sse4.2, default"))) internal(void) { 
return 0; }
+int use(void) { return internal(); }
+/// Internal linkage resolvers do not use comdat.
+// LINUX: define internal ptr @internal.resolver() {
+// WINDOWS: define internal i32 @internal() {
+
 int __attribute__((target_clones("sse4.2, default"))) foo(void) { return 0; }
 // LINUX: define {{.*}}i32 @foo.sse4.2.0()
 // LINUX: define {{.*}}i32 @foo.default.1()
@@ -192,7 +199,5 @@
 
 // CHECK: attributes #[[SSE42]] =
 // CHECK-SAME: 
"target-features"="+crc32,+cx8,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
-// CHECK: attributes #[[DEF]] =
-// Don't bother checking features, we verified it is the same as a normal 
function.
 // CHECK: attributes #[[SB]] =
 // CHECK-SAME: 
"target-features"="+avx,+cmov,+crc32,+cx16,+cx8,+fxsr,+mmx,+pclmul,+popcnt,+sahf,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt"
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4052,7 +4052,7 @@
 
 ResolverFunc->setLinkage(getMultiversionLinkage(*this, GD));
 
-if (supportsCOMDAT())
+if (!ResolverFunc->hasLocalLinkage() && supportsCOMDAT())
   ResolverFunc->setComdat(
   getModule().getOrInsertComdat(ResolverFunc->getName()));
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@
 - Clang's ``-Wunused-private-field`` no longer warns on fields whose type is
   declared with ``[[maybe_unused]]``.
   (`#61334 `_)
+- For function multi-versioning using the ``target`` or ``target_clones``
+  attributes, remove comdat for internal linkage functions.
+  (`#65114 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGen/attr-target-mv.c
===
--- clang/test/CodeGen/attr-target-mv.c
+++ clang/test/CodeGen/attr-target-mv.c
@@ -32,6 +32,13 @@
   return foo();

[clang] 651b2fb - [CodeGen] Function multi-versioning: don't set comdat for internal linkage resolvers

2023-08-30 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-08-30T09:46:48-07:00
New Revision: 651b2fbc1c7ec4992d2c80b8456c5c5a72394caf

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

LOG: [CodeGen] Function multi-versioning: don't set comdat for internal linkage 
resolvers

For function multi-versioning using the target or target_clones
function attributes, currently we incorrectly set comdat for internal
linkage resolvers. This is problematic for ELF linkers
as GRP_COMDAT deduplication will kick in even with STB_LOCAL signature
(https://groups.google.com/g/generic-abi/c/2X6mR-s2zoc
"GRP_COMDAT group with STB_LOCAL signature").

In short, two `__attribute((target_clones(...))) static void foo()`
in two translation units will be deduplicated. Fix this.

Fix #65114

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/attr-target-clones.c
clang/test/CodeGen/attr-target-mv.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1e273c1b7ce46a..ded58a369c7a03 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@ Bug Fixes in This Version
 - Clang's ``-Wunused-private-field`` no longer warns on fields whose type is
   declared with ``[[maybe_unused]]``.
   (`#61334 `_)
+- For function multi-versioning using the ``target`` or ``target_clones``
+  attributes, remove comdat for internal linkage functions.
+  (`#65114 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 21e1363b613e0e..f27fc019ccc53e 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4052,7 +4052,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
 
 ResolverFunc->setLinkage(getMultiversionLinkage(*this, GD));
 
-if (supportsCOMDAT())
+if (!ResolverFunc->hasLocalLinkage() && supportsCOMDAT())
   ResolverFunc->setComdat(
   getModule().getOrInsertComdat(ResolverFunc->getName()));
 

diff  --git a/clang/test/CodeGen/attr-target-clones.c 
b/clang/test/CodeGen/attr-target-clones.c
index 5da9548067831a..98ffea40f56d88 100644
--- a/clang/test/CodeGen/attr-target-clones.c
+++ b/clang/test/CodeGen/attr-target-clones.c
@@ -16,6 +16,7 @@
 // LINUX: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] }
 // LINUX: @__cpu_features2 = external dso_local global [3 x i32]
 
+// LINUX: @internal.ifunc = internal ifunc i32 (), ptr @internal.resolver
 // LINUX: @foo.ifunc = weak_odr ifunc i32 (), ptr @foo.resolver
 // LINUX: @foo_dupes.ifunc = weak_odr ifunc void (), ptr @foo_dupes.resolver
 // LINUX: @unused.ifunc = weak_odr ifunc void (), ptr @unused.resolver
@@ -23,6 +24,12 @@
 // LINUX: @foo_inline2.ifunc = weak_odr ifunc i32 (), ptr @foo_inline2.resolver
 // LINUX: @foo_used_no_defn.ifunc = weak_odr ifunc i32 (), ptr 
@foo_used_no_defn.resolver
 
+static int __attribute__((target_clones("sse4.2, default"))) internal(void) { 
return 0; }
+int use(void) { return internal(); }
+/// Internal linkage resolvers do not use comdat.
+// LINUX: define internal ptr @internal.resolver() {
+// WINDOWS: define internal i32 @internal() {
+
 int __attribute__((target_clones("sse4.2, default"))) foo(void) { return 0; }
 // LINUX: define {{.*}}i32 @foo.sse4.2.0()
 // LINUX: define {{.*}}i32 @foo.default.1()
@@ -192,7 +199,5 @@ int isa_level(int) { return 0; }
 
 // CHECK: attributes #[[SSE42]] =
 // CHECK-SAME: 
"target-features"="+crc32,+cx8,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
-// CHECK: attributes #[[DEF]] =
-// Don't bother checking features, we verified it is the same as a normal 
function.
 // CHECK: attributes #[[SB]] =
 // CHECK-SAME: 
"target-features"="+avx,+cmov,+crc32,+cx16,+cx8,+fxsr,+mmx,+pclmul,+popcnt,+sahf,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt"

diff  --git a/clang/test/CodeGen/attr-target-mv.c 
b/clang/test/CodeGen/attr-target-mv.c
index 261ce514763113..301cb704f20316 100644
--- a/clang/test/CodeGen/attr-target-mv.c
+++ b/clang/test/CodeGen/attr-target-mv.c
@@ -32,6 +32,13 @@ int bar(void) {
   return foo();
 }
 
+static int __attribute__((target("arch=meteorlake"))) foo_internal(void) 
{return 15;}
+static int __attribute__((target("default"))) foo_internal(void) { return 2; }
+
+int bar1(void) {
+  return foo_internal();
+}
+
 inline int __attribute__((target("sse4.2"))) foo_inline(void) { return 0; }
 inline int __attribute__((target("arch=sandybridge"))) foo_inline(void);
 inline int __attrib

[PATCH] D154869: [Flang] [FlangRT] Introduce FlangRT project as solution to Flang's runtime LLVM integration

2023-08-30 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Maybe split the changes to reformat the unittests into a separate patch?

Otherwise, I'm happy with the current state of this patch, but probably someone 
more active in flang should approve.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154869

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


  1   2   >