[clang] 5b9d793 - [clang][NFC] Annotate Expr-related headers with `preferred_type`

2023-11-03 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-04T09:23:50+03:00
New Revision: 5b9d793290c187aee4e63b61d4a12c3766f7cfe6

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

LOG: [clang][NFC] Annotate Expr-related headers with `preferred_type`

Namely `Expr.h`, `ExprConcept.h`, `ExprCXX.h`, `ExprObjC.h`.

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/ExprConcepts.h
clang/include/clang/AST/ExprObjC.h

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 638f886edd095f1..87e80a5a37750ac 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -5114,6 +5114,7 @@ class DesignatedInitExpr final
 
   /// Whether this designated initializer used the GNU deprecated
   /// syntax rather than the C99 '=' syntax.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned GNUSyntax : 1;
 
   /// The number of designators in this initializer expression.
@@ -5745,6 +5746,7 @@ class GenericSelectionExpr final
   /// if and only if the generic selection expression is result-dependent.
   unsigned NumAssocs : 15;
   unsigned ResultIndex : 15; // NB: ResultDependentIndex is tied to this width.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsExprPredicate : 1;
   enum : unsigned {
 ResultDependentIndex = 0x7FFF

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 798c98cfcf2d4db..020dcfd86ad67ea 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1727,10 +1727,12 @@ class CXXInheritedCtorInitExpr : public Expr {
   SourceLocation Loc;
 
   /// Whether this is the construction of a virtual base.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned ConstructsVirtualBase : 1;
 
   /// Whether the constructor is inherited from a virtual base class of the
   /// class that we construct.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned InheritedFromVirtualBase : 1;
 
 public:
@@ -2610,6 +2612,7 @@ class CXXPseudoDestructorExpr : public Expr {
 
   /// Whether the operator was an arrow ('->'); otherwise, it was a
   /// period ('.').
+  LLVM_PREFERRED_TYPE(bool)
   bool IsArrow : 1;
 
   /// The location of the '.' or '->' operator.
@@ -2839,6 +2842,7 @@ class TypeTraitExpr final
 /// \endcode
 class ArrayTypeTraitExpr : public Expr {
   /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
+  LLVM_PREFERRED_TYPE(ArrayTypeTrait)
   unsigned ATT : 2;
 
   /// The value of the type trait. Unspecified if dependent.
@@ -2909,9 +2913,11 @@ class ArrayTypeTraitExpr : public Expr {
 /// \endcode
 class ExpressionTraitExpr : public Expr {
   /// The trait. A ExpressionTrait enum in MSVC compatible unsigned.
+  LLVM_PREFERRED_TYPE(ExpressionTrait)
   unsigned ET : 31;
 
   /// The value of the type trait. Unspecified if dependent.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned Value : 1;
 
   /// The location of the type trait keyword.

diff  --git a/clang/include/clang/AST/ExprConcepts.h 
b/clang/include/clang/AST/ExprConcepts.h
index 4f34799bad05021..29913fd84c58b4d 100644
--- a/clang/include/clang/AST/ExprConcepts.h
+++ b/clang/include/clang/AST/ExprConcepts.h
@@ -173,8 +173,11 @@ class Requirement {
 private:
   const RequirementKind Kind;
   // FIXME: use RequirementDependence to model dependence?
+  LLVM_PREFERRED_TYPE(bool)
   bool Dependent : 1;
+  LLVM_PREFERRED_TYPE(bool)
   bool ContainsUnexpandedParameterPack : 1;
+  LLVM_PREFERRED_TYPE(bool)
   bool Satisfied : 1;
 public:
   struct SubstitutionDiagnostic {

diff  --git a/clang/include/clang/AST/ExprObjC.h 
b/clang/include/clang/AST/ExprObjC.h
index 55bb5fa06b8b7ab..f833916c91aa544 100644
--- a/clang/include/clang/AST/ExprObjC.h
+++ b/clang/include/clang/AST/ExprObjC.h
@@ -317,6 +317,7 @@ class ObjCDictionaryLiteral final
   /// key/value pairs, which provide the locations of the ellipses (if
   /// any) and number of elements in the expansion (if known). If
   /// there are no pack expansions, we optimize away this storage.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasPackExpansions : 1;
 
   SourceRange Range;
@@ -554,9 +555,11 @@ class ObjCIvarRefExpr : public Expr {
   SourceLocation OpLoc;
 
   // True if this is "X->F", false if this is "X.F".
+  LLVM_PREFERRED_TYPE(bool)
   bool IsArrow : 1;
 
   // True if ivar reference has no base (self assumed).
+  LLVM_PREFERRED_TYPE(bool)
   bool IsFreeIvar : 1;
 
 public:
@@ -940,6 +943,23 @@ class ObjCSubscriptRefExpr : public Expr {
 class ObjCMessageExpr final
 : public Expr,
   private llvm::TrailingObjects {
+public:
+  /// The kind of receiver this message is sending to.
+  enum ReceiverKind {
+/// The receiver is a class.
+Class = 0,
+
+/// The receiver is an object instance.
+Instance,
+
+//

[clang] c4b2d33 - [clang][NFC] Annotate 2 leftover bit-fields in `Type.h` with `preferred_type`

2023-11-03 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-04T08:58:57+03:00
New Revision: c4b2d338cc450ff4499fd062cd9261bea55808a1

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

LOG: [clang][NFC] Annotate 2 leftover bit-fields in `Type.h` with 
`preferred_type`

Added: 


Modified: 
clang/include/clang/AST/Type.h

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 42e9b8f94b4e7b6..ca94d30da217f62 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1672,7 +1672,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 
 /// Storage class qualifiers from declarations like
 /// 'int X[static restrict 4]'. For function parameters only.
-/// Actually an ArraySizeModifier.
+LLVM_PREFERRED_TYPE(ArraySizeModifier)
 unsigned SizeModifier : 3;
   };
   enum { NumArrayTypeBits = NumTypeBits + 6 };
@@ -6663,6 +6663,7 @@ class PipeType : public Type, public llvm::FoldingSetNode 
{
 /// A fixed int type of a specified bitwidth.
 class BitIntType final : public Type, public llvm::FoldingSetNode {
   friend class ASTContext;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsUnsigned : 1;
   unsigned NumBits : 24;
 



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


[clang] 0fea0d2 - [clang][NFC] Annotate DeclBase.h with `preferred_type`

2023-11-03 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-04T08:43:59+03:00
New Revision: 0fea0d2f3b5e5be011e229cdddc7540095ff9236

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

LOG: [clang][NFC] Annotate DeclBase.h with `preferred_type`

This patch adds `preferred_type` annotations to `Decl` and `DeclContext` 
bit-fields. Those annotations help debuggers reason about the type of the value 
stored in bit-field.

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index fdc59ac7419d9e3..5b1038582bc6747 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -16,6 +16,7 @@
 #include "clang/AST/ASTDumperUtils.h"
 #include "clang/AST/AttrIterator.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/SelectorLocationsKind.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
@@ -284,31 +285,38 @@ class alignas(8) Decl {
   SourceLocation Loc;
 
   /// DeclKind - This indicates which class this is.
+  LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
   /// InvalidDecl - This indicates a semantic error occurred.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned InvalidDecl :  1;
 
   /// HasAttrs - This indicates whether the decl has attributes or not.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasAttrs : 1;
 
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned Implicit : 1;
 
   /// Whether this declaration was "used", meaning that a definition is
   /// required.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned Used : 1;
 
   /// Whether this declaration was "referenced".
   /// The 
diff erence with 'Used' is whether the reference appears in a
   /// evaluated context or not, e.g. functions used in uninstantiated templates
   /// are regarded as "referenced" but not "used".
+  LLVM_PREFERRED_TYPE(bool)
   unsigned Referenced : 1;
 
   /// Whether this declaration is a top-level declaration (function,
   /// global variable, etc.) that is lexically inside an objc container
   /// definition.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned TopLevelDeclInObjCContainer : 1;
 
   /// Whether statistic collection is enabled.
@@ -326,15 +334,19 @@ class alignas(8) Decl {
 
   /// Access - Used by C++ decls for the access specifier.
   // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
+  LLVM_PREFERRED_TYPE(AccessSpecifier)
   unsigned Access : 2;
 
   /// Whether this declaration was loaded from an AST file.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned FromASTFile : 1;
 
   /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
+  LLVM_PREFERRED_TYPE(IdentifierNamespace)
   unsigned IdentifierNamespace : 14;
 
   /// If 0, we have not computed the linkage of this declaration.
+  LLVM_PREFERRED_TYPE(Linkage)
   mutable unsigned CacheValidAndLinkage : 3;
 
   /// Allocate memory for a deserialized declaration.
@@ -1443,35 +1455,42 @@ class DeclContext {
   class DeclContextBitfields {
 friend class DeclContext;
 /// DeclKind - This indicates which class this is.
+LLVM_PREFERRED_TYPE(Decl::Kind)
 uint64_t DeclKind : 7;
 
 /// Whether this declaration context also has some external
 /// storage that contains additional declarations that are lexically
 /// part of this context.
+LLVM_PREFERRED_TYPE(bool)
 mutable uint64_t ExternalLexicalStorage : 1;
 
 /// Whether this declaration context also has some external
 /// storage that contains additional declarations that are visible
 /// in this context.
+LLVM_PREFERRED_TYPE(bool)
 mutable uint64_t ExternalVisibleStorage : 1;
 
 /// Whether this declaration context has had externally visible
 /// storage added since the last lookup. In this case, \c LookupPtr's
 /// invariant may not hold and needs to be fixed before we perform
 /// another lookup.
+LLVM_PREFERRED_TYPE(bool)
 mutable uint64_t NeedToReconcileExternalVisibleStorage : 1;
 
 /// If \c true, this context may have local lexical declarations
 /// that are missing from the lookup table.
+LLVM_PREFERRED_TYPE(bool)
 mutable uint64_t HasLazyLocalLexicalLookups : 1;
 
 /// If \c true, the external source may have lexical declarations
 /// that are missing from the lookup table.
+LLVM_PREFERRED_TYPE(bool)
 mutable uint64_t HasLazyExternalLexicalLookups : 1;
 
 /// If \c true, lookups should only return identifier from
 /// DeclContext scope (for example TranslationUnit). Used in
 /// LookupQualifiedName()
+LLVM_PREFERRED_TYP

[clang] [llvm] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-03 Thread Stefan Pintilie via cfe-commits

https://github.com/stefanp-ibm updated 
https://github.com/llvm/llvm-project/pull/70255

>From b09304032b13927bfa9e1920313ba1193cfd53ad Mon Sep 17 00:00:00 2001
From: Stefan Pintilie 
Date: Wed, 25 Oct 2023 15:21:11 -0500
Subject: [PATCH 1/7] [PowerPC] Add an alias for -mregnames so that full
 register names used in assembly.

This option already exists on GCC and so it is being added to LLVM so that we
use the same option as them.
---
 clang/include/clang/Driver/Options.td |  4 +
 clang/lib/Basic/Targets/PPC.cpp   |  6 ++
 clang/lib/Basic/Targets/PPC.h |  1 +
 .../test/CodeGen/PowerPC/ppc-full-reg-names.c | 78 +++
 .../PowerPC/MCTargetDesc/PPCInstPrinter.cpp   | 15 ++--
 .../PowerPC/MCTargetDesc/PPCInstPrinter.h |  5 +-
 llvm/lib/Target/PowerPC/PPC.td|  4 +
 .../CodeGen/PowerPC/ppc-full-reg-names.ll | 62 +++
 8 files changed, 167 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
 create mode 100644 llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fcf6a4b2ccb2369..339966a36b513bc 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4777,6 +4777,10 @@ def mrop_protect : Flag<["-"], "mrop-protect">,
 Group;
 def mprivileged : Flag<["-"], "mprivileged">,
 Group;
+def mregnames : Flag<["-"], "mregnames">, Group,
+Visibility<[ClangOption]>;
+def mno_regnames : Flag<["-"], "mno-regnames">, Group,
+   Visibility<[ClangOption]>;
 } // let Flags = [TargetSpecific]
 def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
   Group,
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 5ce276e1af9ef64..211d9a0295c9ad9 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -89,6 +89,8 @@ bool 
PPCTargetInfo::handleTargetFeatures(std::vector &Features,
   IsISA3_1 = true;
 } else if (Feature == "+quadword-atomics") {
   HasQuadwordAtomics = true;
+} else if (Feature == "+regnames") {
+  FullRegisterNames = true;
 }
 // TODO: Finish this list and add an assert that we've handled them
 // all.
@@ -551,6 +553,9 @@ bool PPCTargetInfo::initFeatureMap(
   // off by default.
   Features["aix-small-local-exec-tls"] = false;
 
+  // By default full register names are not used in assembly.
+  Features["regnames"] = false;
+
   Features["spe"] = llvm::StringSwitch(CPU)
 .Case("8548", true)
 .Case("e500", true)
@@ -700,6 +705,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
   .Case("isa-v30-instructions", IsISA3_0)
   .Case("isa-v31-instructions", IsISA3_1)
   .Case("quadword-atomics", HasQuadwordAtomics)
+  .Case("regnames", FullRegisterNames)
   .Default(false);
 }
 
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 4d62673ba7fb8c5..ddef057bb306cad 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -80,6 +80,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool IsISA3_0 = false;
   bool IsISA3_1 = false;
   bool HasQuadwordAtomics = false;
+  bool FullRegisterNames = false;
 
 protected:
   std::string ABI;
diff --git a/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c 
b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
new file mode 100644
index 000..c1bd22c1134c9a7
--- /dev/null
+++ b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
@@ -0,0 +1,78 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S 
-emit-llvm -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S 
-emit-llvm -mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+
+// Also check the assembly to make sure that the full names are used.
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8

[clang] [LoongArch] Fix ABI mismatch with g++ when handling empty unions (PR #71025)

2023-11-03 Thread Lu Weining via cfe-commits

https://github.com/SixWeining closed 
https://github.com/llvm/llvm-project/pull/71025
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4253fdc - [LoongArch] Fix ABI mismatch with g++ when handling empty unions (#71025)

2023-11-03 Thread via cfe-commits

Author: Lu Weining
Date: 2023-11-04T10:04:37+08:00
New Revision: 4253fdc2c462da61cc0deb74a43265665720c828

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

LOG: [LoongArch] Fix ABI mismatch with g++ when handling empty unions (#71025)

In g++, empty unions are not ignored like empty structs when flattening
structs to examine whether the structs can be passed via FARs in C++.
This patch aligns clang++ with g++.

Fix https://github.com/llvm/llvm-project/issues/70890.

Added: 


Modified: 
clang/lib/CodeGen/Targets/LoongArch.cpp
clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c

Removed: 




diff  --git a/clang/lib/CodeGen/Targets/LoongArch.cpp 
b/clang/lib/CodeGen/Targets/LoongArch.cpp
index c4d886eb40725f8..7b2c31139b0b2a3 100644
--- a/clang/lib/CodeGen/Targets/LoongArch.cpp
+++ b/clang/lib/CodeGen/Targets/LoongArch.cpp
@@ -170,10 +170,11 @@ bool LoongArchABIInfo::detectFARsEligibleStructHelper(
 // copy constructor are not eligible for the FP calling convention.
 if (getRecordArgABI(Ty, CGT.getCXXABI()))
   return false;
-if (isEmptyRecord(getContext(), Ty, true, true))
-  return true;
 const RecordDecl *RD = RTy->getDecl();
-// Unions aren't eligible unless they're empty (which is caught above).
+if (isEmptyRecord(getContext(), Ty, true, true) &&
+(!RD->isUnion() || !isa(RD)))
+  return true;
+// Unions aren't eligible unless they're empty in C (which is caught 
above).
 if (RD->isUnion())
   return false;
 const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);

diff  --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
index 281b7b15841a999..2f7596f0ebdc8be 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d 
-target-abi lp64d -emit-llvm %s -o - -x c++ | \
 // RUN:   FileCheck --check-prefix=CHECK-CXX %s
 
-// Fields containing empty structs or unions are ignored when flattening
+// Fields containing empty structs are ignored when flattening
 // structs to examine whether the structs can be passed via FARs, even in C++.
 // But there is an exception that non-zero-length array of empty structures are
 // not ignored in C++. These rules are not documented in psABI 


diff  --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
index b0607425336e285..363e37efb64691e 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
@@ -19,8 +19,7 @@ struct s1 {
 };
 
 // CHECK-C: define{{.*}} { i32, float } @test2(i32{{[^,]*}}, float{{[^,]*}})
-/// FIXME: This doesn't match g++.
-// CHECK-CXX: define{{.*}} { i32, float } @_Z5test22s1(i32{{[^,]*}}, 
float{{[^,]*}})
+// CHECK-CXX: define{{.*}} [2 x i64] @_Z5test22s1([2 x i64]{{[^,]*}})
 struct s1 test2(struct s1 a) {
   return a;
 }



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


[clang] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

2023-11-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Justin Bogner (bogner)


Changes

If a template is defined via an external AST source, it won't have a
location. When we emit warnings about misusing such templates we
shouldn't emit a "template is declared here" warning with no location,
as that's just confusing.


---

Patch is 21.78 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/71264.diff


7 Files Affected:

- (modified) clang/lib/Sema/SemaDecl.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaInit.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaLambda.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+80-43) 
- (modified) clang/lib/Sema/SemaType.cpp (+2-1) 
- (modified) clang/test/SemaHLSL/BuiltIns/vector-errors.hlsl (-5) 


``diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 396566a8f10a9b7..a86c428c9121abf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5929,7 +5929,7 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) 
{
   Diag(Name.StartLocation,
diag::err_deduction_guide_name_not_class_template)
 << (int)getTemplateNameKindForDiagnostics(TN) << TN;
-  if (Template)
+  if (Template && Template->getLocation().isValid())
 Diag(Template->getLocation(), diag::note_template_decl_here);
   return DeclarationNameInfo();
 }
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 397b7a00e453126..de5cc07f5d42865 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11462,7 +11462,8 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, 
QualType &R,
   GuidedTemplateDecl->getDeclContext()->getRedeclContext())) {
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_wrong_scope)
   << GuidedTemplateDecl;
-Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
+if (GuidedTemplateDecl->getLocation().isValid())
+  Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
   }
 
   auto &DS = D.getMutableDeclSpec();
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ed02d3580f34f9a..0952b065d56b58e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10575,7 +10575,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
  diag::err_deduced_non_class_template_specialization_type)
   << (int)getTemplateNameKindForDiagnostics(TemplateName) << TemplateName;
 if (auto *TD = TemplateName.getAsTemplateDecl())
-  Diag(TD->getLocation(), diag::note_template_decl_here);
+  if (TD->getLocation().isValid())
+Diag(TD->getLocation(), diag::note_template_decl_here);
 return QualType();
   }
 
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca09b0481bcac76..603b7465323e237 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1444,7 +1444,8 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
   for (const auto &Capture : Intro.Captures) {
 if (Capture.Id == TP->getIdentifier()) {
   Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
-  Diag(TP->getLocation(), diag::note_template_param_here);
+  if (TP->getLocation().isValid())
+Diag(TP->getLocation(), diag::note_template_param_here);
 }
   }
 }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ee354862212803f..1a6eaa196db09be 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -872,7 +872,7 @@ bool Sema::DiagnoseUninstantiableTemplate(SourceLocation 
PointOfInstantiation,
   Note = diag::note_explicit_instantiation_here;
 }
   }
-  if (Note) // Diagnostics were emitted.
+  if (Note && Pattern->getLocation().isValid()) // Diagnostics were emitted.
 Diag(Pattern->getLocation(), *Note);
 
   // In general, Instantiation isn't marked invalid to get more than one
@@ -899,7 +899,8 @@ void Sema::DiagnoseTemplateParameterShadow(SourceLocation 
Loc, Decl *PrevDecl) {
   unsigned DiagId = getLangOpts().MSVCCompat ? diag::ext_template_param_shadow
  : diag::err_template_param_shadow;
   Diag(Loc, DiagId) << cast(PrevDecl)->getDeclName();
-  Diag(PrevDecl->getLocation(), diag::note_template_param_here);
+  if (PrevDecl->getLocation().isValid())
+Diag(PrevDecl->getLocation(), diag::note_template_param_here);
 }
 
 /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
@@ -4434,7 +4435,8 @@ static void checkMoreSpecializedThanPrimary(Sema &S, 
PartialSpecDecl *Partial) {
   << SFINAEArgString;
   }
 
-  S.Diag(Template->getLocation(), diag::note_template_decl_here);
+  if (Template->getLocation().isValid())
+S.Diag(Template->getLocation(),

[clang] [clang] Stub out gcc_struct attribute (PR #71148)

2023-11-03 Thread Dan Klishch via cfe-commits

https://github.com/DanShaders updated 
https://github.com/llvm/llvm-project/pull/71148

>From 19124226ee4d08a8025f1e6b61d750096e13ee75 Mon Sep 17 00:00:00 2001
From: Dan Klishch 
Date: Fri, 3 Nov 2023 21:18:06 -0400
Subject: [PATCH] [clang] Stub out gcc_struct attribute

This commit implements gcc_struct attribute with the behavior similar to
one in GCC. Current behavior is as follows:

When C++ ABI is not "Microsoft" (i. e. when
ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel
the effect of -mms-bitfields on a record. If -mms-bitfields is not
supplied and is not a default behavior on a target, [[gcc_struct]] will
be a no-op. This should provide enough compatibility with GCC.

If C++ ABI is "Microsoft", [[gcc_struct]] will currently always be a
no-op, since support for it is not yet implemented in
MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure
is ready for the future implementation.

In particular, check for default value of -mms-bitfield is moved from a
driver to TargetInfo, since it now non-trivially depends on other
supplied flags. Also, unfortunately, this makes it impossible to use
usual argument parsing for `-m{no-,}ms-bitfield`.

The patch doesn't introduce any not backwards-compatible changes, except
for situations when cc1 is called directly on a target with
-mms-bitfields being a default option.
---
 clang/include/clang/Basic/Attr.td |  7 +
 clang/include/clang/Basic/LangOptions.def |  1 -
 clang/include/clang/Basic/LangOptions.h   |  2 ++
 clang/include/clang/Basic/TargetInfo.h|  4 +++
 clang/include/clang/Driver/Options.td |  4 +--
 clang/lib/AST/Decl.cpp|  7 -
 clang/lib/CodeGen/CGRecordLayoutBuilder.cpp   |  5 +---
 clang/lib/Driver/ToolChains/Clang.cpp | 10 ---
 clang/lib/Frontend/CompilerInvocation.cpp | 12 +
 clang/lib/Sema/SemaDecl.cpp   |  4 +--
 clang/lib/Sema/SemaDeclCXX.cpp| 27 ---
 clang/test/Driver/ms-bitfields.c  | 11 +---
 clang/test/Layout/itanium-union-bitfield.cpp  |  2 +-
 ...a-attribute-supported-attributes-list.test |  1 +
 14 files changed, 69 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 60b54c155e5..34ec6c22481837e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3635,6 +3635,13 @@ def MSStruct : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def GCCStruct : InheritableAttr {
+  let Spellings = [GCC<"gcc_struct">];
+  let Subjects = SubjectList<[Record]>;
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+}
+
 def DLLExport : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
   let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index c0ea4ecb9806a5b..afbb3c724a8d193 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -148,7 +148,6 @@ LANGOPT(ExternCNoUnwind   , 1, 0, "Assume extern C 
functions don't unwind")
 LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation")
 LANGOPT(RTTI  , 1, 1, "run-time type information")
 LANGOPT(RTTIData  , 1, 1, "emit run-time type information data")
-LANGOPT(MSBitfields   , 1, 0, "Microsoft-compatible structure layout")
 LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and 
stores")
 LANGOPT(Freestanding, 1, 0, "freestanding implementation")
 LANGOPT(NoBuiltin , 1, 0, "disable builtin functions")
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 20a8ada60e0fe51..07eae8dad61813c 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase {
   // received as a result of a standard operator new (-fcheck-new)
   bool CheckNew = false;
 
+  std::optional MSBitfields;
+
   LangOptions();
 
   /// Set language defaults for the given input language and
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index b3c5cbfb319f01f..6865b6e23bc9628 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1724,6 +1724,10 @@ class TargetInfo : public TransferrableTargetInfo,
   /// Whether to support HIP image/texture API's.
   virtual bool hasHIPImageSupport() const { return true; }
 
+  virtual bool defaultsToMsStruct() const {
+return getCXXABI().isMicrosoft() || getTriple().isWindowsGNUEnvironment();
+  }
+
 protected:
   /// Copy type and layout related info.
   void copyAuxTarget(const TargetInfo *Aux);
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td

[clang] [clang] Stub out gcc_struct attribute (PR #71148)

2023-11-03 Thread Dan Klishch via cfe-commits

https://github.com/DanShaders edited 
https://github.com/llvm/llvm-project/pull/71148
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Stub out gcc_struct attribute (PR #71148)

2023-11-03 Thread Dan Klishch via cfe-commits

https://github.com/DanShaders edited 
https://github.com/llvm/llvm-project/pull/71148
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Stub out gcc_struct attribute (PR #71148)

2023-11-03 Thread Dan Klishch via cfe-commits

https://github.com/DanShaders edited 
https://github.com/llvm/llvm-project/pull/71148
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Stub out gcc_struct attribute (PR #71148)

2023-11-03 Thread Dan Klishch via cfe-commits

https://github.com/DanShaders edited 
https://github.com/llvm/llvm-project/pull/71148
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Stub out gcc_struct attribute (PR #71148)

2023-11-03 Thread Dan Klishch via cfe-commits

https://github.com/DanShaders edited 
https://github.com/llvm/llvm-project/pull/71148
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ASTMatcher] Add matchers for CXXFoldExpr (PR #71245)

2023-11-03 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/71245

>From ae352f244a031b587d136423e0e3ef51f522c771 Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Fri, 3 Nov 2023 21:51:57 +0100
Subject: [PATCH] [clang][ASTMatcher] Add matchers for CXXFoldExpr

---
 clang/docs/LibASTMatchersReference.html   | 209 +-
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/ASTMatchers/ASTMatchers.h | 194 ++--
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp |   1 +
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|   1 +
 clang/unittests/AST/ASTImporterTest.cpp   |  27 +--
 .../ASTMatchers/ASTMatchersNarrowingTest.cpp  |  99 -
 .../ASTMatchers/ASTMatchersNodeTest.cpp   |  13 ++
 .../ASTMatchers/ASTMatchersTraversalTest.cpp  |  89 
 9 files changed, 594 insertions(+), 42 deletions(-)

diff --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index fcd3114bb523105..39d1ffe3d2dee3b 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1629,6 +1629,17 @@ Node Matchers
 
 
 
+MatcherStmt>cxxFoldExprMatcherCXXFoldExpr>...
+Matches C++17 fold 
expressions.
+
+Example matches `(0 + ... + args)`:
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+
+
 MatcherStmt>cxxForRangeStmtMatcherCXXForRangeStmt>...
 Matches range-based 
for statements.
 
@@ -3430,6 +3441,92 @@ Narrowing Matchers
 
 
 
+MatcherCXXFoldExpr>hasOperatorBinaryOperatorKind 
Op
+Matches the operator 
kind of the fold expression.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(hasOperator(BO_Add)))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isBinaryFold
+Matches binary fold 
expressions, i.e. fold expressions with an initializer.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(isBinaryFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ...);
+  }
+
+
+
+MatcherCXXFoldExpr>isLeftFold
+Matches left-folding 
fold expressions.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(isLeftFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isRightFold
+Matches right-folding 
fold expressions.
+
+Example matches `(args * ... * 1)`
+(matcher = cxxFoldExpr(isRightFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isUnaryFold
+Matches unary fold 
expressions, i.e. fold expressions without an
+initializer.
+
+Example matches `(args * ...)`
+(matcher = cxxFoldExpr(isUnaryFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ...);
+  }
+
+
+
 MatcherCXXMethodDecl>isConst
 Matches if the given method 
declaration is const.
 
@@ -6885,6 +6982,93 @@ AST Traversal Matchers
 
 
 
+MatcherCXXFoldExpr>calleeMatcherStmt> 
InnerMatcher
+Matches if the call or fold 
expression's callee expression matches.
+
+Given
+  class Y { void x() { this->x(); x(); Y y; y.x(); } };
+  void f() { f(); }
+callExpr(callee(expr()))
+  matches this->x(), x(), y.x(), f()
+with callee(...)
+  matching this->x, x, y.x, f respectively
+
+Given
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+cxxFoldExpr(callee(expr()))
+  matches (args * ... * 1)
+with callee(...)

[clang] [clang] Stub out gcc_struct attribute (PR #71148)

2023-11-03 Thread Dan Klishch via cfe-commits

https://github.com/DanShaders edited 
https://github.com/llvm/llvm-project/pull/71148
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Stub out gcc_struct attribute (PR #71148)

2023-11-03 Thread Dan Klishch via cfe-commits

https://github.com/DanShaders edited 
https://github.com/llvm/llvm-project/pull/71148
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement gcc_struct attribute (PR #71148)

2023-11-03 Thread Dan Klishch via cfe-commits

https://github.com/DanShaders updated 
https://github.com/llvm/llvm-project/pull/71148

>From 0d6728f06d7633b6b9ffaed45182dac0e54546ba Mon Sep 17 00:00:00 2001
From: Dan Klishch 
Date: Fri, 3 Nov 2023 21:18:06 -0400
Subject: [PATCH] [clang] Stub out gcc_struct attribute

This commit implements gcc_struct attribute with the behavior similar to
one in GCC. Current behavior is as follows:

When C++ ABI is not "Microsoft" (i. e. when
ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel
the effect of -mms-bitfields on a record. If -mms-bitfields is not
supplied and is not a default behavior on a target, [[gcc_struct]] will
be a no-op. This should provide enough compatibility with GCC.

If C++ ABI is "Microsoft", [[gcc_struct]] will currently always be a
no-op, since support for it is not yet implemented in
MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure
is ready for the future implementation.

In particular, check for default value of -mms-bitfield is moved from a
driver to TargetInfo, since it now non-trivially depends on other
supplied flags. Also, unfortunately, this makes it impossible to use
usual argument parsing for `-m{no-,}ms-bitfield`.

The patch doesn't introduce any not backwards-compatible changes, except
for situations when cc1 is called directly on a target with
-mms-bitfields being a default option.
---
 clang/include/clang/Basic/Attr.td|  7 +
 clang/include/clang/Basic/LangOptions.def|  1 -
 clang/include/clang/Basic/LangOptions.h  |  2 ++
 clang/include/clang/Basic/TargetInfo.h   |  4 +++
 clang/include/clang/Driver/Options.td|  4 +--
 clang/lib/AST/Decl.cpp   |  7 -
 clang/lib/CodeGen/CGRecordLayoutBuilder.cpp  |  5 +---
 clang/lib/Driver/ToolChains/Clang.cpp| 10 +---
 clang/lib/Frontend/CompilerInvocation.cpp| 12 +
 clang/lib/Sema/SemaDecl.cpp  |  4 +--
 clang/lib/Sema/SemaDeclCXX.cpp   | 27 
 clang/test/Driver/ms-bitfields.c | 11 +---
 clang/test/Layout/itanium-union-bitfield.cpp |  2 +-
 13 files changed, 68 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 60b54c155e5..34ec6c22481837e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3635,6 +3635,13 @@ def MSStruct : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def GCCStruct : InheritableAttr {
+  let Spellings = [GCC<"gcc_struct">];
+  let Subjects = SubjectList<[Record]>;
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+}
+
 def DLLExport : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
   let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index c0ea4ecb9806a5b..afbb3c724a8d193 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -148,7 +148,6 @@ LANGOPT(ExternCNoUnwind   , 1, 0, "Assume extern C 
functions don't unwind")
 LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation")
 LANGOPT(RTTI  , 1, 1, "run-time type information")
 LANGOPT(RTTIData  , 1, 1, "emit run-time type information data")
-LANGOPT(MSBitfields   , 1, 0, "Microsoft-compatible structure layout")
 LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and 
stores")
 LANGOPT(Freestanding, 1, 0, "freestanding implementation")
 LANGOPT(NoBuiltin , 1, 0, "disable builtin functions")
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 20a8ada60e0fe51..07eae8dad61813c 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase {
   // received as a result of a standard operator new (-fcheck-new)
   bool CheckNew = false;
 
+  std::optional MSBitfields;
+
   LangOptions();
 
   /// Set language defaults for the given input language and
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index b3c5cbfb319f01f..6865b6e23bc9628 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1724,6 +1724,10 @@ class TargetInfo : public TransferrableTargetInfo,
   /// Whether to support HIP image/texture API's.
   virtual bool hasHIPImageSupport() const { return true; }
 
+  virtual bool defaultsToMsStruct() const {
+return getCXXABI().isMicrosoft() || getTriple().isWindowsGNUEnvironment();
+  }
+
 protected:
   /// Copy type and layout related info.
   void copyAuxTarget(const TargetInfo *Aux);
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9c0dcaa8b3f6276..d29214ed3cb13db 100644
--- a/clang/includ

[clang] [clang][ASTMatcher] Add matchers for CXXFoldExpr (PR #71245)

2023-11-03 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 9b2246d9fad9fe62be26d22e184f241304779551 
bd26678cd8a444aac6c7362df7eadedbb614b7fe -- 
clang/include/clang/ASTMatchers/ASTMatchers.h 
clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
clang/lib/ASTMatchers/Dynamic/Registry.cpp 
clang/unittests/AST/ASTImporterTest.cpp 
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 4e67faa155f0..2cd50dbf3a55 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4704,7 +4704,7 @@ AST_MATCHER_P(CXXFoldExpr, hasOperator, 
BinaryOperatorKind, Op) {
 ///   int x{y}.
 /// \endcode
 AST_MATCHER_P2(InitListExpr, hasInit, unsigned, N,
-ast_matchers::internal::Matcher, InnerMatcher) {
+   ast_matchers::internal::Matcher, InnerMatcher) {
   return N < Node.getNumInits() &&
   InnerMatcher.matches(*Node.getInit(N), Finder, Builder);
 }
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index a312ffa7070d..b150ba665fa4 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -804,11 +804,12 @@ TEST_P(ImportExpr, ImportSizeOfPackExpr) {
 }
 
 TEST_P(ImportExpr, ImportCXXFoldExpr) {
-  auto Match1 =
-  cxxFoldExpr(hasOperator(BO_Add), isLeftFold(), 
unless(hasFoldInit(expr(;
-  auto Match2 = cxxFoldExpr(hasOperator(BO_Sub), isLeftFold(), 
hasFoldInit(expr()));
-  auto Match3 =
-  cxxFoldExpr(hasOperator(BO_Mul), isRightFold(), 
unless(hasFoldInit(expr(;
+  auto Match1 = cxxFoldExpr(hasOperator(BO_Add), isLeftFold(),
+unless(hasFoldInit(expr(;
+  auto Match2 =
+  cxxFoldExpr(hasOperator(BO_Sub), isLeftFold(), hasFoldInit(expr()));
+  auto Match3 = cxxFoldExpr(hasOperator(BO_Mul), isRightFold(),
+unless(hasFoldInit(expr(;
   auto Match4 =
   cxxFoldExpr(hasOperator(BO_Div), isRightFold(), hasFoldInit(expr()));
 

``




https://github.com/llvm/llvm-project/pull/71245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ASTMatcher] Add matchers for CXXFoldExpr (PR #71245)

2023-11-03 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/71245

>From bd26678cd8a444aac6c7362df7eadedbb614b7fe Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Fri, 3 Nov 2023 21:51:57 +0100
Subject: [PATCH] [clang][ASTMatcher] Add matchers for CXXFoldExpr

---
 clang/docs/LibASTMatchersReference.html   | 209 +-
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/ASTMatchers/ASTMatchers.h | 196 ++--
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp |   1 +
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|   1 +
 clang/unittests/AST/ASTImporterTest.cpp   |  22 +-
 .../ASTMatchers/ASTMatchersNarrowingTest.cpp  |  99 -
 .../ASTMatchers/ASTMatchersNodeTest.cpp   |  13 ++
 .../ASTMatchers/ASTMatchersTraversalTest.cpp  |  89 
 9 files changed, 592 insertions(+), 41 deletions(-)

diff --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index fcd3114bb523105..39d1ffe3d2dee3b 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1629,6 +1629,17 @@ Node Matchers
 
 
 
+MatcherStmt>cxxFoldExprMatcherCXXFoldExpr>...
+Matches C++17 fold 
expressions.
+
+Example matches `(0 + ... + args)`:
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+
+
 MatcherStmt>cxxForRangeStmtMatcherCXXForRangeStmt>...
 Matches range-based 
for statements.
 
@@ -3430,6 +3441,92 @@ Narrowing Matchers
 
 
 
+MatcherCXXFoldExpr>hasOperatorBinaryOperatorKind 
Op
+Matches the operator 
kind of the fold expression.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(hasOperator(BO_Add)))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isBinaryFold
+Matches binary fold 
expressions, i.e. fold expressions with an initializer.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(isBinaryFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ...);
+  }
+
+
+
+MatcherCXXFoldExpr>isLeftFold
+Matches left-folding 
fold expressions.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(isLeftFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isRightFold
+Matches right-folding 
fold expressions.
+
+Example matches `(args * ... * 1)`
+(matcher = cxxFoldExpr(isRightFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isUnaryFold
+Matches unary fold 
expressions, i.e. fold expressions without an
+initializer.
+
+Example matches `(args * ...)`
+(matcher = cxxFoldExpr(isUnaryFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ...);
+  }
+
+
+
 MatcherCXXMethodDecl>isConst
 Matches if the given method 
declaration is const.
 
@@ -6885,6 +6982,93 @@ AST Traversal Matchers
 
 
 
+MatcherCXXFoldExpr>calleeMatcherStmt> 
InnerMatcher
+Matches if the call or fold 
expression's callee expression matches.
+
+Given
+  class Y { void x() { this->x(); x(); Y y; y.x(); } };
+  void f() { f(); }
+callExpr(callee(expr()))
+  matches this->x(), x(), y.x(), f()
+with callee(...)
+  matching this->x, x, y.x, f respectively
+
+Given
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+cxxFoldExpr(callee(expr()))
+  matches (args * ... * 1)
+with callee(...)
+

[llvm] [libc] [clang-tools-extra] [lld] [libcxx] [clang] [flang] [lldb] [OpenACC] Initial commits to support OpenACC (PR #70234)

2023-11-03 Thread Bruno Cardoso Lopes via cfe-commits


@@ -0,0 +1,14 @@
+// RUN: %clang -S -### -fopenacc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DRIVER
+// CHECK-DRIVER: "-cc1" {{.*}} "-fopenacc"

bcardosolopes wrote:

Thanks for the explanation!

https://github.com/llvm/llvm-project/pull/70234
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-03 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,28 @@
+.. title:: clang-tidy - modernize-use-std-numbers
+
+modernize-use-std-numbers
+=
+
+Finds constants and function calls to math functions that can be replaced
+with c++20's mathematical constants from the ``numbers`` header and offers 
fix-it hints.
+Does not match the use of variables with that value, and instead,
+offers a replacement at the definition of those variables.
+

5chmidti wrote:

I’ve also extended the documentation slightly to explain the replacements a bit 
further.

https://github.com/llvm/llvm-project/pull/66583
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-03 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/66583
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-03 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,284 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "../ClangTidyDiagnosticConsumer.h"
+#include "../utils/TransformerClangTidyCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr auto DiffThreshold = 0.001;
+
+AST_MATCHER_P(clang::FloatingLiteral, near, double, Value) {
+  return std::abs(Node.getValueAsApproximateDouble() - Value) < DiffThreshold;
+}
+
+AST_MATCHER_P(clang::QualType, hasCanonicalTypeUnqualified,
+  Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node->getCanonicalTypeUnqualified(), Finder,
+  Builder);
+}
+
+AST_MATCHER(clang::QualType, isArithmetic) { return Node->isArithmeticType(); }
+AST_MATCHER(clang::QualType, isFloating) { return Node->isFloatingType(); }
+
+auto ignoreImplicitAndArithmeticCasting(const Matcher Matcher) {
+  return expr(
+  ignoringImplicit(expr(hasType(qualType(isArithmetic())),
+ignoringParenCasts(ignoringImplicit(Matcher);
+}
+
+auto ignoreImplicitAndFloatingCasting(const Matcher Matcher) {
+  return expr(
+  ignoringImplicit(expr(hasType(qualType(isFloating())),
+ignoringParenCasts(ignoringImplicit(Matcher);
+}
+
+auto matchMathCall(const StringRef FunctionName,
+   const Matcher ArgumentMatcher) {
+  return callExpr(
+  callee(functionDecl(hasName(FunctionName),
+  hasParameter(0, hasType(isArithmetic(),
+  hasArgument(0, ArgumentMatcher));
+}
+
+auto matchSqrt(const Matcher ArgumentMatcher) {
+  return matchMathCall("sqrt", ArgumentMatcher);
+}
+
+// Used for top-level matchers (i.e. the match that replaces Val with its
+// constant).
+//
+// E.g. The matcher of `std::numbers::pi` uses this matcher to look to
+// floatLiterals that have the value of pi.
+//
+// We only care about the literal if the match is for a top-level match
+auto matchFloatLiteralNear(const double Val) {
+  return expr(ignoreImplicitAndFloatingCasting(floatLiteral(near(Val;
+}
+
+// Used for non-top-level matchers (i.e. matchers that are used as inner
+// matchers for top-level matchers).
+//
+// E.g.: The matcher of `std::numbers::log2e` uses this matcher to check if `e`
+// of `log2(e)` is declared constant and initialized with the value for eulers
+// number.
+//
+// Here, we do care about literals and about DeclRefExprs to variable
+// declarations that are constant and initialized with `Val`. This allows
+// top-level matchers to see through declared constants for their inner matches
+// like the `std::numbers::log2e` matcher.
+auto matchFloatValueNear(const double Val) {
+  const auto Float = floatLiteral(near(Val));
+
+  const auto Dref = declRefExpr(to(varDecl(
+  anyOf(isConstexpr(),
+varDecl(hasType(qualType(isConstQualified(), isArithmetic(),

5chmidti wrote:

This is not needed. I just checked 
https://github.com/llvm/llvm-project/blob/af4abc4fa7778f83ba7fd759b818352dc2d19469/clang/lib/AST/Type.cpp#L2186
 The canonical type is used to check if the type is a floating type, instead of 
the `BaseType` pointer in `ExtQualsTypeCommonBase`.

Tests that confirm this behavior are
- `bar::sqrt(Actually2MyFloat);`
- `log2(Euler5);` (`Euler5` has the type `my_double`)
- `log2(Euler6);` (`Euler6` has the type `my_float`)

https://github.com/llvm/llvm-project/pull/66583
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-03 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,28 @@
+.. title:: clang-tidy - modernize-use-std-numbers
+
+modernize-use-std-numbers
+=
+
+Finds constants and function calls to math functions that can be replaced
+with c++20's mathematical constants from the ``numbers`` header and offers 
fix-it hints.
+Does not match the use of variables with that value, and instead,
+offers a replacement at the definition of those variables.
+

5chmidti wrote:

done

https://github.com/llvm/llvm-project/pull/66583
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-03 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,284 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "../ClangTidyDiagnosticConsumer.h"
+#include "../utils/TransformerClangTidyCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr auto DiffThreshold = 0.001;
+
+AST_MATCHER_P(clang::FloatingLiteral, near, double, Value) {
+  return std::abs(Node.getValueAsApproximateDouble() - Value) < DiffThreshold;
+}
+
+AST_MATCHER_P(clang::QualType, hasCanonicalTypeUnqualified,
+  Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node->getCanonicalTypeUnqualified(), Finder,

5chmidti wrote:

done

https://github.com/llvm/llvm-project/pull/66583
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-03 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,284 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "../ClangTidyDiagnosticConsumer.h"
+#include "../utils/TransformerClangTidyCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr auto DiffThreshold = 0.001;
+
+AST_MATCHER_P(clang::FloatingLiteral, near, double, Value) {
+  return std::abs(Node.getValueAsApproximateDouble() - Value) < DiffThreshold;
+}
+
+AST_MATCHER_P(clang::QualType, hasCanonicalTypeUnqualified,
+  Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node->getCanonicalTypeUnqualified(), Finder,
+  Builder);
+}
+
+AST_MATCHER(clang::QualType, isArithmetic) { return Node->isArithmeticType(); }

5chmidti wrote:

done

https://github.com/llvm/llvm-project/pull/66583
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-11-03 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 671741bb9cbf1566ddadb401b41452475031a0ee 
2f57f925e81b7e5171eb8d283e3450823d6acbf1 -- clang/lib/CodeGen/CGBuiltin.cpp 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c 
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
llvm/lib/Target/AArch64/AArch64ISelLowering.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 65c6530bcbcf..0fac8545b095 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9599,7 +9599,7 @@ Value *CodeGenFunction::EmitSVEStructStore(const 
SVETypeFlags &TypeFlags,
   }
   Operands.append({Predicate, BasePtr});
 
-  Function *F = CGM.getIntrinsic(IntID, { VTy });
+  Function *F = CGM.getIntrinsic(IntID, {VTy});
   return Builder.CreateCall(F, Operands);
 }
 
@@ -9948,14 +9948,14 @@ Value 
*CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID,
 return EmitSVEPrefetchLoad(TypeFlags, Ops, Builtin->LLVMIntrinsic);
   else if (TypeFlags.isGatherPrefetch())
 return EmitSVEGatherPrefetch(TypeFlags, Ops, Builtin->LLVMIntrinsic);
-   else if (TypeFlags.isStructLoad())
-   return EmitSVEStructLoad(TypeFlags, Ops, 
Builtin->LLVMIntrinsic);
-   else if (TypeFlags.isStructStore())
-   return EmitSVEStructStore(TypeFlags, Ops, 
Builtin->LLVMIntrinsic);
+  else if (TypeFlags.isStructLoad())
+return EmitSVEStructLoad(TypeFlags, Ops, Builtin->LLVMIntrinsic);
+  else if (TypeFlags.isStructStore())
+return EmitSVEStructStore(TypeFlags, Ops, Builtin->LLVMIntrinsic);
   else if (TypeFlags.isTupleSet() || TypeFlags.isTupleGet())
-return EmitSVETupleSetOrGet(TypeFlags, Ty, Ops);
+return EmitSVETupleSetOrGet(TypeFlags, Ty, Ops);
   else if (TypeFlags.isTupleCreate())
-return EmitSVETupleCreate(TypeFlags, Ty, Ops);
+return EmitSVETupleCreate(TypeFlags, Ty, Ops);
   else if (TypeFlags.isUndef())
 return UndefValue::get(Ty);
   else if (Builtin->LLVMIntrinsic != 0) {
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index ad76289d09a3..3d40701ab251 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -10350,7 +10350,7 @@ AArch64TargetLowering::getConstraintType(StringRef 
Constraint) const {
 }
   } else if (parsePredicateConstraint(Constraint) !=
  PredicateConstraint::Invalid)
-  return C_RegisterClass;
+return C_RegisterClass;
   else if (parseConstraintCode(Constraint) != AArch64CC::Invalid)
 return C_Other;
   return TargetLowering::getConstraintType(Constraint);

``




https://github.com/llvm/llvm-project/pull/68565
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-11-03 Thread Sam Tebbs via cfe-commits

https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/68565

>From de07976922782b9dcf5d13d44551b782dc8b3b94 Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Fri, 6 Oct 2023 17:09:36 +0100
Subject: [PATCH 1/4] [AArch64][SME] Remove immediate argument restriction for
 svldr and svstr

The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, since the instructions
take an immediate vector number. However, we emit 0 as the immediate
for the instruction no matter what, and instead modify the base register.

This patch removes that restriction on the argument, so that the
argument can be a non-immediate. If an appropriate immediate was
passed to the builtin then CGBuiltin passes that directly to the LLVM
intrinsic, otherwise it modifies the base register as is existing
behaviour.
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 45 
 .../aarch64-sme-intrinsics/acle_sme_ldr.c | 71 ---
 .../aarch64-sme-intrinsics/acle_sme_str.c | 51 -
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  4 +-
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 10 +--
 .../CostModel/ARM/unaligned_double_load.ll| 59 +++
 .../CodeGen/AArch64/sme-intrinsics-loads.ll   | 33 +++--
 7 files changed, 166 insertions(+), 107 deletions(-)
 create mode 100644 llvm/test/Analysis/CostModel/ARM/unaligned_double_load.ll

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..63508b40096141e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9712,6 +9712,11 @@ Value *CodeGenFunction::EmitSVEMaskedStore(const 
CallExpr *E,
   return Store;
 }
 
+Value *CodeGenFunction::EmitTileslice(Value *Offset, Value *Base) {
+  llvm::Value *CastOffset = Builder.CreateIntCast(Offset, Int64Ty, false);
+  return Builder.CreateAdd(Base, CastOffset, "tileslice");
+}
+
 Value *CodeGenFunction::EmitSMELd1St1(const SVETypeFlags &TypeFlags,
   SmallVectorImpl &Ops,
   unsigned IntID) {
@@ -9767,18 +9772,34 @@ Value *CodeGenFunction::EmitSMEZero(const SVETypeFlags 
&TypeFlags,
 Value *CodeGenFunction::EmitSMELdrStr(const SVETypeFlags &TypeFlags,
   SmallVectorImpl &Ops,
   unsigned IntID) {
-  if (Ops.size() == 3) {
-Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
-llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-
-llvm::Value *VecNum = Ops[2];
-llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
-
-Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = Builder.CreateAdd(
-Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true), "tileslice");
-Ops.erase(&Ops[2]);
-  }
+  if (Ops.size() == 2) {
+// Intrinsics without a vecnum also use this function, so just provide 0
+Ops.push_back(Ops[1]);
+Ops[1] = Builder.getInt32(0);
+  } else {
+int Imm = -1;
+if (ConstantInt* C = dyn_cast(Ops[2]))
+  if (C->getZExtValue() <= 15)
+  Imm = C->getZExtValue();
+
+if (Imm != -1) {
+  Ops[2] = Ops[1];
+  Ops[1] = Builder.getInt32(Imm);
+} else {
+  Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
+  llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
+
+  llvm::Value *VecNum = Ops[2];
+  llvm::Value *MulVL = Builder.CreateMul(
+  CntsbCall,
+  VecNum,
+  "mulvl");
+
+  Ops[2] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
+  Ops[1] = Builder.getInt32(0);
+  Ops[0] = Builder.CreateIntCast(EmitTileslice(Ops[0], VecNum), Int32Ty, 
false);
+}
+   }
   Function *F = CGM.getIntrinsic(IntID, {});
   return Builder.CreateCall(F, Ops);
 }
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index e85c47072f2df80..8e07cf1d11c19b2 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -6,57 +6,46 @@
 
 #include 
 
-// CHECK-C-LABEL: define dso_local void @test_svldr_vnum_za(
-// CHECK-C-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
-// CHECK-C-NEXT:  entry:
-// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE]], 
ptr [[PTR]])
-// CHECK-C-NEXT:ret void
-//
-// CHECK-CXX-LABEL: define dso_local void @_Z18test_svldr_vnum_zajPKv(
-// CHECK-CXX-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
-// CHECK-CXX-NEXT:  entry:
-// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE]], 
ptr [[PTR]])
-// CHECK-CXX-NEXT:ret void
+// CHECK-C-LABEL: @test_svldr_vnum_za(
+// CHECK-CXX-LABEL: @_Z18test_svldr_vnum_zajPK

[clang-tools-extra] [flang] [compiler-rt] [llvm] [clang] [Bazel][Clang Tidy] Include builtin headers with clang-tidy (PR #67626)

2023-11-03 Thread via cfe-commits

https://github.com/jathu updated https://github.com/llvm/llvm-project/pull/67626

>From 20d9ca99fbf11868a5816df217b2aad09e079fb6 Mon Sep 17 00:00:00 2001
From: jathu 
Date: Wed, 27 Sep 2023 18:01:19 -0700
Subject: [PATCH] [clang-tidy][bazel] Include builtin headers with clang-tidy

---
 .../clang-tools-extra/BUILD.bazel | 21 +++
 .../clang-tools-extra/clang-tidy/BUILD.bazel  |  1 +
 .../clang-tools-extra/defs.bzl| 26 +++
 .../llvm-project-overlay/clang/BUILD.bazel| 12 ++---
 .../bazel/llvm-project-overlay/clang/defs.bzl |  5 
 5 files changed, 61 insertions(+), 4 deletions(-)
 create mode 100644 
utils/bazel/llvm-project-overlay/clang-tools-extra/BUILD.bazel
 create mode 100644 utils/bazel/llvm-project-overlay/clang-tools-extra/defs.bzl
 create mode 100644 utils/bazel/llvm-project-overlay/clang/defs.bzl

diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/BUILD.bazel 
b/utils/bazel/llvm-project-overlay/clang-tools-extra/BUILD.bazel
new file mode 100644
index 000..d7559a376698583
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/BUILD.bazel
@@ -0,0 +1,21 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+load("//:vars.bzl", "LLVM_VERSION_MAJOR")
+load("//clang:defs.bzl", "BUILTIN_HEADERS_GEN_DIR")
+load("defs.bzl", "symlink")
+
+package(
+default_visibility = ["//visibility:public"],
+features = ["layering_check"],
+)
+
+licenses(["notice"])
+
+symlink(
+name = "builtin_headers",
+srcs = ["//clang:builtin_headers_gen"],
+destination = "lib/clang/{0}/include".format(LLVM_VERSION_MAJOR),
+partition = BUILTIN_HEADERS_GEN_DIR,
+)
diff --git 
a/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel 
b/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
index bbabc5397e98937..257c9e875d0133b 100644
--- a/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
@@ -370,6 +370,7 @@ cc_library(
 cc_binary(
 name = "clang-tidy",
 srcs = ["tool/ClangTidyToolMain.cpp"],
+data = ["//clang-tools-extra:builtin_headers"],
 stamp = 0,
 deps = [":tool"],
 )
diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/defs.bzl 
b/utils/bazel/llvm-project-overlay/clang-tools-extra/defs.bzl
new file mode 100644
index 000..fd992c052b0f055
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/defs.bzl
@@ -0,0 +1,26 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+load("@bazel_skylib//lib:paths.bzl", "paths")
+
+def _symlink_impl(ctx):
+copied_files = []
+for input_file in ctx.files.srcs:
+(_, _, relative_filename) = 
input_file.path.rpartition(ctx.attr.partition)
+output_file = 
ctx.actions.declare_file(paths.join(ctx.attr.destination, relative_filename))
+ctx.actions.symlink(
+target_file = input_file,
+output = output_file,
+)
+copied_files.append(output_file)
+return DefaultInfo(files = depset(copied_files))
+
+symlink = rule(
+implementation = _symlink_impl,
+attrs = {
+"destination": attr.string(mandatory = True),
+"partition": attr.string(mandatory = True),
+"srcs": attr.label_list(allow_files = True),
+},
+)
diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel 
b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
index cac8ec120929a37..02f0f6076c6fddd 100644
--- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -14,6 +14,7 @@ load(
 "LLVM_VERSION_MINOR",
 "LLVM_VERSION_PATCH",
 )
+load("defs.bzl", "BUILTIN_HEADERS_GEN_DIR")
 
 package(
 default_visibility = ["//visibility:public"],
@@ -1696,14 +1697,17 @@ builtin_headers = glob(
 genrule(
 name = "builtin_headers_gen",
 srcs = builtin_headers,
-outs = [hdr.replace("lib/Headers/", "staging/include/") for hdr in 
builtin_headers],
+outs = [
+header.replace("lib/Headers/", BUILTIN_HEADERS_GEN_DIR)
+for header in builtin_headers
+],
 cmd = """
for src in $(SRCS); do
- relsrc=$${src#*"$(WORKSPACE_ROOT)"/clang/lib/Headers}
- target=$(@D)/staging/include/$$relsrc
+ relsrc=$${{src#*"$(WORKSPACE_ROOT)"/clang/lib/Headers}}
+ target=$(@D)/{resource_dir}$$relsrc
  mkdir -p $$(dirname $$target)
  cp $$src $$target
-   done""",
+   done""".format(resource_dir = BUILTIN_HEADERS_GEN_DIR),
 output_to_bindir = 1,
 toolchains = [
 ":workspace_root",
diff --g

[clang] [Clang][CodeGen] Emit `llvm.ptrmask` for `align_up` and `align_down` (PR #71238)

2023-11-03 Thread via cfe-commits

goldsteinn wrote:

> LGTM
> 
> As a possible followup, we can probably drop the alignment assumption now? I 
> don't think it adds additional value if we're using ptrmask...

Would think thats okay. Will post that after I push this.

https://github.com/llvm/llvm-project/pull/71238
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [flang] [compiler-rt] [llvm] [clang] [Bazel][Clang Tidy] Include builtin headers with clang-tidy (PR #67626)

2023-11-03 Thread via cfe-commits

jathu wrote:

@aeubanks @rnk 

> issues with 2: relies on bazel paths, i.e. this puts the symlink at 
> bazel-bin/external/llvm-project/clang-tools-extra/ which happens to be two 
> directories up from 
> bazel-bin/external/llvm-project/clang-tools-extra/clang-tidy/clang-tidy

I also think this is weird, however this seems to be the location clang-tidy 
expects the headers to be located. This symlink approach was the least 
intrusive solution I can think of without modifying the overlay logic.

> my worry about baking in the resource dir for the bazel build is that it'll 
> be tied to the bazel build directory structure implementation details, so 
> it's likely that you can't copy the binaries around and create a toolchain 
> out of it

Maybe I'm misunderstanding your point — since these headers are included in the 
runfiles of the binary, if we do a copy/package the binary, the runfiles will 
be bundled with the binary. If there is a solution to bundle the headers 
*within* the binary, that would be great, but I think that goes beyond the goal 
of this diff.

https://github.com/llvm/llvm-project/pull/67626
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 closed 
https://github.com/llvm/llvm-project/pull/70841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 34c0d32 - [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (#70841)

2023-11-03 Thread via cfe-commits

Author: Mingming Liu
Date: 2023-11-03T16:01:10-07:00
New Revision: 34c0d32c81bf8d7cbeadbd4e9544378d4bf85a35

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

LOG: [Clang] Emit type metadata on vtables when IRPGO instrumentation option is 
on. (#70841)

The motivating use case is to have type metadata on vtables if IR 
instrumentation is on (without the requirement of`-fwhole-program-vtables` or 
`-flto`).

A related rfc is in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600

Added: 


Modified: 
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/type-metadata.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 25e4b1c27932026..959940775ee8096 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -1312,7 +1312,10 @@ llvm::GlobalObject::VCallVisibility 
CodeGenModule::GetVCallVisibilityLevel(
 void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD,
llvm::GlobalVariable *VTable,
const VTableLayout &VTLayout) {
-  if (!getCodeGenOpts().LTOUnit)
+  // Emit type metadata on vtables with LTO or IR instrumentation.
+  // In IR instrumentation, the type metadata is used to find out vtable
+  // definitions (for type profiling) among all global variables.
+  if (!getCodeGenOpts().LTOUnit && !getCodeGenOpts().hasProfileIRInstr())
 return;
 
   CharUnits ComponentWidth = GetTargetTypeStoreSize(getVTableComponentType());

diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 1f0e6c1be705525..f7b9328fbce339f 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1673,7 +1673,11 @@ void MicrosoftCXXABI::EmitDestructorCall(CodeGenFunction 
&CGF,
 void MicrosoftCXXABI::emitVTableTypeMetadata(const VPtrInfo &Info,
  const CXXRecordDecl *RD,
  llvm::GlobalVariable *VTable) {
-  if (!CGM.getCodeGenOpts().LTOUnit)
+  // Emit type metadata on vtables with LTO or IR instrumentation.
+  // In IR instrumentation, the type metadata could be used to find out vtable
+  // definitions (for type profiling) among all global variables.
+  if (!CGM.getCodeGenOpts().LTOUnit &&
+  !CGM.getCodeGenOpts().hasProfileIRInstr())
 return;
 
   // TODO: Should VirtualFunctionElimination also be supported here?

diff  --git a/clang/test/CodeGenCXX/type-metadata.cpp 
b/clang/test/CodeGenCXX/type-metadata.cpp
index 3f8b54af801f8d6..b93c4288bb9a5d2 100644
--- a/clang/test/CodeGenCXX/type-metadata.cpp
+++ b/clang/test/CodeGenCXX/type-metadata.cpp
@@ -1,113 +1,133 @@
+// A meta comment on the prefixes:
+// ITANIUM-COMMON-MD prefix is common when the options are either non-relative 
vtable or relative vtables.
+// ITANIUM-NO-RV-MD prefix is used when the options specify non-relative 
vtables, and RV-MD is used when the options specify relative vtables.
+
 // Tests for the cfi-vcall feature:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-ABORT %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG 
--check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS 
--check-prefix=TT-MS --check-prefix=NDIAG %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM-H

[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Mingming Liu via cfe-commits

minglotus-6 wrote:

> Somehow I missed those other uses of the ITANIUM prefix. Thanks for cleaning 
> it up though I think the new names are more descriptive.

yep! I hope the new names helps more or less going forward. Thanks for the 
feedbacks!

https://github.com/llvm/llvm-project/pull/70841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ASTMatcher] Add matchers for CXXFoldExpr (PR #71245)

2023-11-03 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/71245

>From 6a0a568fe0887c9665aa78bd51610e063d022c19 Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Fri, 3 Nov 2023 21:51:57 +0100
Subject: [PATCH] [clang][ASTMatcher] Add matchers for CXXFoldExpr

---
 clang/docs/LibASTMatchersReference.html   | 213 +-
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/ASTMatchers/ASTMatchers.h | 199 ++--
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp |   1 +
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|   2 +-
 clang/unittests/AST/ASTImporterTest.cpp   |  18 +-
 .../ASTMatchers/ASTMatchersNarrowingTest.cpp  |  99 +++-
 .../ASTMatchers/ASTMatchersNodeTest.cpp   |  13 ++
 .../ASTMatchers/ASTMatchersTraversalTest.cpp  |  87 +++
 9 files changed, 592 insertions(+), 43 deletions(-)

diff --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index fcd3114bb523105..d559732c0fe4764 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1629,6 +1629,17 @@ Node Matchers
 
 
 
+MatcherStmt>cxxFoldExprMatcherCXXFoldExpr>...
+Matches C++17 fold 
expressions.
+
+Example matches `(0 + ... + args)`:
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+
+
 MatcherStmt>cxxForRangeStmtMatcherCXXForRangeStmt>...
 Matches range-based 
for statements.
 
@@ -3430,6 +3441,92 @@ Narrowing Matchers
 
 
 
+MatcherCXXFoldExpr>hasOperatorBinaryOperatorKind 
Op
+Matches the operator 
kind of the fold expression.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(hasOperator(BO_Add)))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isBinaryFold
+Matches binary fold 
expressions, i.e. fold expressions with an initializer.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(isBinaryFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ...);
+  }
+
+
+
+MatcherCXXFoldExpr>isLeftFold
+Matches left-folding 
fold expressions.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(isLeftFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isRightFold
+Matches right-folding 
fold expressions.
+
+Example matches `(args * ... * 1)`
+(matcher = cxxFoldExpr(isRightFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isUnaryFold
+Matches unary fold 
expressions, i.e. fold expressions without an
+initializer.
+
+Example matches `(args * ...)`
+(matcher = cxxFoldExpr(isUnaryFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ...);
+  }
+
+
+
 MatcherCXXMethodDecl>isConst
 Matches if the given method 
declaration is const.
 
@@ -6885,6 +6982,93 @@ AST Traversal Matchers
 
 
 
+MatcherCXXFoldExpr>calleeMatcherStmt> 
InnerMatcher
+Matches if the call or fold 
expression's callee expression matches.
+
+Given
+  class Y { void x() { this->x(); x(); Y y; y.x(); } };
+  void f() { f(); }
+callExpr(callee(expr()))
+  matches this->x(), x(), y.x(), f()
+with callee(...)
+  matching this->x, x, y.x, f respectively
+
+Given
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+cxxFoldExpr(callee(expr()))
+  matches (args * ... * 1)
+with callee(...)
+ 

[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-03 Thread Joseph Huber via cfe-commits


@@ -88,7 +88,7 @@ class TargetOptions {
 COV_5 = 500,
   };
   /// \brief Code object version for AMDGPU.
-  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_None;
+  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_4;

jhuber6 wrote:

Is this the default?

https://github.com/llvm/llvm-project/pull/71234
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ASTMatcher] Add matchers for CXXFoldExpr (PR #71245)

2023-11-03 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti created 
https://github.com/llvm/llvm-project/pull/71245

None

>From 17cec21d5a92a2f1e09f7294d7990b0b584e5ec8 Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Fri, 3 Nov 2023 21:51:57 +0100
Subject: [PATCH] [clang][ASTMatcher] Add matchers for CXXFoldExpr

---
 clang/docs/LibASTMatchersReference.html   | 212 +-
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/ASTMatchers/ASTMatchers.h | 198 ++--
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp |   1 +
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|   2 +-
 clang/unittests/AST/ASTImporterTest.cpp   |  18 +-
 .../ASTMatchers/ASTMatchersNarrowingTest.cpp  |  99 +++-
 .../ASTMatchers/ASTMatchersNodeTest.cpp   |  13 ++
 .../ASTMatchers/ASTMatchersTraversalTest.cpp  |  55 +
 9 files changed, 558 insertions(+), 43 deletions(-)

diff --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index fcd3114bb523105..deeaf331c82fbd8 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1629,6 +1629,17 @@ Node Matchers
 
 
 
+MatcherStmt>cxxFoldExprMatcherCXXFoldExpr>...
+Matches C++17 fold 
expressions.
+
+Example matches `(0 + ... + args)`:
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+
+
 MatcherStmt>cxxForRangeStmtMatcherCXXForRangeStmt>...
 Matches range-based 
for statements.
 
@@ -3430,6 +3441,91 @@ Narrowing Matchers
 
 
 
+MatcherCXXFoldExpr>hasOperatorBinaryOperatorKind 
Op
+Matches the operator 
kind of the fold expression.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(hasOperator(BO_Add)))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isBinaryFold
+Matches the operand 
that contains the parameter pack.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(isBinaryFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ...);
+  }
+
+
+
+MatcherCXXFoldExpr>isLeftFold
+Matches the operand that 
contains the parameter pack.
+
+Example matches `(0 + ... + args)`
+(matcher = cxxFoldExpr(isLeftFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isRightFold
+Matches the operand 
that contains the parameter pack.
+
+Example matches `(args * ... * 1)`
+(matcher = cxxFoldExpr(isRightFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+
+
+
+MatcherCXXFoldExpr>isUnaryFold
+Matches the operand 
that contains the parameter pack.
+
+Example matches `(args * ...)`
+(matcher = cxxFoldExpr(isUnaryFold()))
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ...);
+  }
+
+
+
 MatcherCXXMethodDecl>isConst
 Matches if the given method 
declaration is const.
 
@@ -6885,6 +6981,93 @@ AST Traversal Matchers
 
 
 
+MatcherCXXFoldExpr>calleeMatcherStmt> 
InnerMatcher
+Matches if the call or fold 
expression's callee expression matches.
+
+Given
+  class Y { void x() { this->x(); x(); Y y; y.x(); } };
+  void f() { f(); }
+callExpr(callee(expr()))
+  matches this->x(), x(), y.x(), f()
+with callee(...)
+  matching this->x, x, y.x, f respectively
+
+Given
+  template 
+  auto sum(Args... args) {
+  return (0 + ... + args);
+  }
+
+  template 
+  auto multiply(Args... args) {
+  return (args * ... * 1);
+  }
+cxxFoldExpr(callee(expr()))
+  matches (args * ... * 1)
+with callee(...)
+  matching *
+

[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

2023-11-03 Thread Bill Wendling via cfe-commits

bwendling wrote:

> I just wanted to call out that this case is interesting because the size 
> derived from malloc and __counted_by compete each other. And __counted_by 
> always wins. This conforms to how -fbounds-safety will see the size of 
> objects, so sounds like we are all happy with it.

Great! :-)

As for the updating the docs and adding the intrinsic, I'd like to do that 
after GCC settles on their implementation. So I'd do it as a follow-up to this.

https://github.com/llvm/llvm-project/pull/70606
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Teresa Johnson via cfe-commits

https://github.com/teresajohnson approved this pull request.

Somehow I missed those other uses of the ITANIUM prefix. Thanks for cleaning it 
up though I think the new names are more descriptive.

https://github.com/llvm/llvm-project/pull/70841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fc55068 - [clang][MicrosoftCXXABI] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-03 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-03T17:05:44-05:00
New Revision: fc55068c0969fa83d894d46e14d4fdec05a30b2c

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

LOG: [clang][MicrosoftCXXABI] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 4e55d6be376a517..1f0e6c1be705525 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -2986,7 +2986,6 @@ MicrosoftCXXABI::EmitMemberFunctionPointer(const 
CXXMethodDecl *MD) {
 NonVirtualBaseAdjustment -= getContext().getOffsetOfBaseWithVBPtr(RD);
 
   // The rest of the fields are common with data member pointers.
-  FirstField = llvm::ConstantExpr::getBitCast(FirstField, CGM.VoidPtrTy);
   return EmitFullMemberPointer(FirstField, /*IsMemberFunction=*/true, RD,
NonVirtualBaseAdjustment, VBTableIndex);
 }
@@ -3981,7 +3980,7 @@ llvm::Constant 
*MicrosoftCXXABI::getAddrOfRTTIDescriptor(QualType Type) {
 
   // Check to see if we've already declared this TypeDescriptor.
   if (llvm::GlobalVariable *GV = CGM.getModule().getNamedGlobal(MangledName))
-return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
+return GV;
 
   // Note for the future: If we would ever like to do deferred emission of
   // RTTI, check if emitting vtables opportunistically need any adjustment.
@@ -4007,7 +4006,7 @@ llvm::Constant 
*MicrosoftCXXABI::getAddrOfRTTIDescriptor(QualType Type) {
   MangledName);
   if (Var->isWeakForLinker())
 Var->setComdat(CGM.getModule().getOrInsertComdat(Var->getName()));
-  return llvm::ConstantExpr::getBitCast(Var, CGM.Int8PtrTy);
+  return Var;
 }
 
 /// Gets or a creates a Microsoft CompleteObjectLocator.
@@ -4200,8 +4199,6 @@ llvm::Constant 
*MicrosoftCXXABI::getCatchableType(QualType T,
   CopyCtor = getAddrOfCXXCtorClosure(CD, Ctor_CopyingClosure);
 else
   CopyCtor = CGM.getAddrOfCXXStructor(GlobalDecl(CD, Ctor_Complete));
-
-CopyCtor = llvm::ConstantExpr::getBitCast(CopyCtor, CGM.Int8PtrTy);
   } else {
 CopyCtor = llvm::Constant::getNullValue(CGM.Int8PtrTy);
   }
@@ -4411,14 +4408,11 @@ llvm::GlobalVariable 
*MicrosoftCXXABI::getThrowInfo(QualType T) {
   if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
 if (CXXDestructorDecl *DtorD = RD->getDestructor())
   if (!DtorD->isTrivial())
-CleanupFn = llvm::ConstantExpr::getBitCast(
-CGM.getAddrOfCXXStructor(GlobalDecl(DtorD, Dtor_Complete)),
-CGM.Int8PtrTy);
+CleanupFn = CGM.getAddrOfCXXStructor(GlobalDecl(DtorD, Dtor_Complete));
   // This is unused as far as we can tell, initialize it to null.
   llvm::Constant *ForwardCompat =
   getImageRelativeConstant(llvm::Constant::getNullValue(CGM.Int8PtrTy));
-  llvm::Constant *PointerToCatchableTypes = getImageRelativeConstant(
-  llvm::ConstantExpr::getBitCast(CTA, CGM.Int8PtrTy));
+  llvm::Constant *PointerToCatchableTypes = getImageRelativeConstant(CTA);
   llvm::StructType *TIType = getThrowInfoType();
   llvm::Constant *Fields[] = {
   llvm::ConstantInt::get(CGM.IntTy, Flags), // Flags



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


[clang] [Clang][CodeGen] Emit `llvm.ptrmask` for `align_up` and `align_down` (PR #71238)

2023-11-03 Thread Nikita Popov via cfe-commits

https://github.com/nikic approved this pull request.

LGTM

As a possible followup, we can probably drop the alignment assumption now? I 
don't think it adds additional value if we're using ptrmask...

https://github.com/llvm/llvm-project/pull/71238
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][libc] Ignore implicit function inline (PR #71095)

2023-11-03 Thread via cfe-commits

https://github.com/michaelrj-google closed 
https://github.com/llvm/llvm-project/pull/71095
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] c92cf31 - [clang-tidy][libc] Ignore implicit function inline (#71095)

2023-11-03 Thread via cfe-commits

Author: michaelrj-google
Date: 2023-11-03T14:57:03-07:00
New Revision: c92cf315c67edaffea1c4f3a914197dce2a194f3

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

LOG: [clang-tidy][libc] Ignore implicit function inline (#71095)

This patch adjusts the inline function decl check for LLVM libc to
ignore implicit functions. For the moment the plan is to ignore these
and mark the class with a macro so that it can be given the appropriate
properties without explicitly defining all its ctors/dtors.

Added: 


Modified: 
clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl.rst
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
index c119e393d3ab692..0607fd9d5add869 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -45,7 +45,9 @@ InlineFunctionDeclCheck::InlineFunctionDeclCheck(StringRef 
Name,
   HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void InlineFunctionDeclCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(decl(functionDecl()).bind("func_decl"), this);
+  // Ignore functions that have been deleted.
+  Finder->addMatcher(decl(functionDecl(unless(isDeleted(.bind("func_decl"),
+ this);
 }
 
 void InlineFunctionDeclCheck::check(const MatchFinder::MatchResult &Result) {

diff  --git a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.h 
b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.h
index 662a592abd9be12..52516f776ad49ce 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.h
+++ b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.h
@@ -33,6 +33,11 @@ class InlineFunctionDeclCheck : public ClangTidyCheck {
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
+  // Ignore implicit functions (e.g. implicit constructors or destructors)
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
+
 private:
   FileExtensionsSet HeaderFileExtensions;
 };

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index f9671a65a26fca3..fe8c7175d554c7b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -304,6 +304,10 @@ Changes in existing checks
   customizable namespace. This further allows for testing the libc when the
   system-libc is also LLVM's libc.
 
+- Improved :doc:`llvmlibc-inline-function-decl
+  ` to properly ignore 
implicit
+  functions, such as struct constructors, and explicitly deleted functions.
+
 - Improved :doc:`misc-const-correctness
   ` check to avoid false positive 
when
   using pointer to member function.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl.rst 
b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl.rst
index 101217b64c82852..71d963969005bad 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl.rst
@@ -3,6 +3,8 @@
 llvmlibc-inline-function-decl
 =
 
-Checks that all implicit and explicit inline functions in header files are
-tagged with the ``LIBC_INLINE`` macro. See the `libc style guide
-`_ for more information about this 
macro.
+Checks that all implicitly and explicitly inline functions in header files are
+tagged with the ``LIBC_INLINE`` macro, except for functions implicit to classes
+or deleted functions.
+See the `libc style guide `_ for 
more
+information about this macro.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
index 0028c575b1d6871..fd2a59289f7682e 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -278,6 +278,28 @@ template LIBC_INLINE void 
goodWeirdFormatting() {}
 template void LIBC_INLINE badWeirdFormatting() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 'b

[clang] [llvm] Recommit changes to global checks (PR #71171)

2023-11-03 Thread Johannes Doerfert via cfe-commits

jdoerfert wrote:

> > I think if the issues with the original commit are resolved, this is good 
> > to go.
> > Did you verify we can properly auto-generate files, e.g., in 
> > llvm/test/Transforms/Attributor and clang/test/OpenMP?
> 
> Ah no I did not, I'll do that on Monday.

I'd run `./llvm/utils/update_any_test_checks.py` once and see if the tests pass 
afterwards.
Then do it again to ensure the nasty ordering and duplication issues are gone 
for good.


https://github.com/llvm/llvm-project/pull/71171
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][CodeGen] Emit `llvm.ptrmask` for `align_up` and `align_down` (PR #71238)

2023-11-03 Thread via cfe-commits

goldsteinn wrote:

If we get this in, any reason to add support for also directly canonicalizing 
the pattern (i.e: https://reviews.llvm.org/D154010) or is that gratuitous?

https://github.com/llvm/llvm-project/pull/71238
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][CodeGen] Emit `llvm.ptrmask` for `align_up` and `align_down` (PR #71238)

2023-11-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (goldsteinn)


Changes

Since PR's #69343 and #67166 we probably have enough support for
`llvm.ptrmask` to make it preferable to the GEP stategy.


---
Full diff: https://github.com/llvm/llvm-project/pull/71238.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+20-23) 
- (modified) clang/test/CodeGen/builtin-align-array.c (+12-24) 
- (modified) clang/test/CodeGen/builtin-align.c (+26-38) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 972aa1c708e5f65..e4d1b2c93e4b113 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19671,41 +19671,38 @@ RValue CodeGenFunction::EmitBuiltinIsAligned(const 
CallExpr *E) {
 /// TODO: actually use ptrmask once most optimization passes know about it.
 RValue CodeGenFunction::EmitBuiltinAlignTo(const CallExpr *E, bool AlignUp) {
   BuiltinAlignArgs Args(E, *this);
-  llvm::Value *SrcAddr = Args.Src;
-  if (Args.Src->getType()->isPointerTy())
-SrcAddr = Builder.CreatePtrToInt(Args.Src, Args.IntType, "intptr");
-  llvm::Value *SrcForMask = SrcAddr;
+  llvm::Value *SrcForMask = Args.Src;
   if (AlignUp) {
 // When aligning up we have to first add the mask to ensure we go over the
 // next alignment value and then align down to the next valid multiple.
 // By adding the mask, we ensure that align_up on an already aligned
 // value will not change the value.
-SrcForMask = Builder.CreateAdd(SrcForMask, Args.Mask, "over_boundary");
+if (Args.Src->getType()->isPointerTy()) {
+  if (getLangOpts().isSignedOverflowDefined())
+SrcForMask =
+Builder.CreateGEP(Int8Ty, SrcForMask, Args.Mask, "over_boundary");
+  else
+SrcForMask = EmitCheckedInBoundsGEP(Int8Ty, SrcForMask, Args.Mask,
+/*SignedIndices=*/true,
+/*isSubtraction=*/false,
+E->getExprLoc(), "over_boundary");
+} else {
+  SrcForMask = Builder.CreateAdd(SrcForMask, Args.Mask, "over_boundary");
+}
   }
   // Invert the mask to only clear the lower bits.
   llvm::Value *InvertedMask = Builder.CreateNot(Args.Mask, "inverted_mask");
-  llvm::Value *Result =
-  Builder.CreateAnd(SrcForMask, InvertedMask, "aligned_result");
+  llvm::Value *Result = nullptr;
   if (Args.Src->getType()->isPointerTy()) {
-/// TODO: Use ptrmask instead of ptrtoint+gep once it is optimized well.
-// Result = Builder.CreateIntrinsic(
-//  Intrinsic::ptrmask, {Args.SrcType, SrcForMask->getType(), 
Args.IntType},
-//  {SrcForMask, NegatedMask}, nullptr, "aligned_result");
-Result->setName("aligned_intptr");
-llvm::Value *Difference = Builder.CreateSub(Result, SrcAddr, "diff");
-// The result must point to the same underlying allocation. This means we
-// can use an inbounds GEP to enable better optimization.
-if (getLangOpts().isSignedOverflowDefined())
-  Result =
-  Builder.CreateGEP(Int8Ty, Args.Src, Difference, "aligned_result");
-else
-  Result = EmitCheckedInBoundsGEP(Int8Ty, Args.Src, Difference,
-  /*SignedIndices=*/true,
-  /*isSubtraction=*/!AlignUp,
-  E->getExprLoc(), "aligned_result");
+Result = Builder.CreateIntrinsic(
+Intrinsic::ptrmask, {Args.SrcType, Args.IntType},
+{SrcForMask, InvertedMask}, nullptr, "aligned_result");
+
 // Emit an alignment assumption to ensure that the new alignment is
 // propagated to loads/stores, etc.
 emitAlignmentAssumption(Result, E, E->getExprLoc(), Args.Alignment);
+  } else {
+Result = Builder.CreateAnd(SrcForMask, InvertedMask, "aligned_result");
   }
   assert(Result->getType() == Args.SrcType);
   return RValue::get(Result);
diff --git a/clang/test/CodeGen/builtin-align-array.c 
b/clang/test/CodeGen/builtin-align-array.c
index 5d1377b98d2814f..18a77b9a710db40 100644
--- a/clang/test/CodeGen/builtin-align-array.c
+++ b/clang/test/CodeGen/builtin-align-array.c
@@ -8,22 +8,16 @@ extern int func(char *c);
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[BUF:%.*]] = alloca [1024 x i8], align 16
 // CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [1024 x i8], ptr 
[[BUF]], i64 0, i64 44
-// CHECK-NEXT:[[INTPTR:%.*]] = ptrtoint ptr [[ARRAYIDX]] to i64
-// CHECK-NEXT:[[ALIGNED_INTPTR:%.*]] = and i64 [[INTPTR]], -16
-// CHECK-NEXT:[[DIFF:%.*]] = sub i64 [[ALIGNED_INTPTR]], [[INTPTR]]
-// CHECK-NEXT:[[ALIGNED_RESULT:%.*]] = getelementptr inbounds i8, ptr 
[[ARRAYIDX]], i64 [[DIFF]]
+// CHECK-NEXT:[[ALIGNED_RESULT:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr 
[[ARRAYIDX]], i64 -16)
 // CHECK-NEXT:call void @llvm.assume(i1 true) [ "align"(ptr 
[[ALIGNED_RESULT]], i64 16) ]
 // CHECK-NEXT:[[CALL:%.*]] = call i32 @func(pt

[clang] [Clang][CodeGen] Emit `llvm.ptrmask` for `align_up` and `align_down` (PR #71238)

2023-11-03 Thread via cfe-commits

https://github.com/goldsteinn created 
https://github.com/llvm/llvm-project/pull/71238

Since PR's #69343 and #67166 we probably have enough support for
`llvm.ptrmask` to make it preferable to the GEP stategy.


>From fd00614be8cbe3dceaba654a687844f85f5436b4 Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Fri, 3 Nov 2023 16:45:46 -0500
Subject: [PATCH] [Clang][CodeGen] Emit `llvm.ptrmask` for `align_up` and
 `align_down`

Since PR's #69343 and #67166 we probably have enough support for
`llvm.ptrmask` to make it preferable to the GEP stategy.
---
 clang/lib/CodeGen/CGBuiltin.cpp  | 43 
 clang/test/CodeGen/builtin-align-array.c | 36 +
 clang/test/CodeGen/builtin-align.c   | 64 ++--
 3 files changed, 58 insertions(+), 85 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 972aa1c708e5f65..e4d1b2c93e4b113 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19671,41 +19671,38 @@ RValue CodeGenFunction::EmitBuiltinIsAligned(const 
CallExpr *E) {
 /// TODO: actually use ptrmask once most optimization passes know about it.
 RValue CodeGenFunction::EmitBuiltinAlignTo(const CallExpr *E, bool AlignUp) {
   BuiltinAlignArgs Args(E, *this);
-  llvm::Value *SrcAddr = Args.Src;
-  if (Args.Src->getType()->isPointerTy())
-SrcAddr = Builder.CreatePtrToInt(Args.Src, Args.IntType, "intptr");
-  llvm::Value *SrcForMask = SrcAddr;
+  llvm::Value *SrcForMask = Args.Src;
   if (AlignUp) {
 // When aligning up we have to first add the mask to ensure we go over the
 // next alignment value and then align down to the next valid multiple.
 // By adding the mask, we ensure that align_up on an already aligned
 // value will not change the value.
-SrcForMask = Builder.CreateAdd(SrcForMask, Args.Mask, "over_boundary");
+if (Args.Src->getType()->isPointerTy()) {
+  if (getLangOpts().isSignedOverflowDefined())
+SrcForMask =
+Builder.CreateGEP(Int8Ty, SrcForMask, Args.Mask, "over_boundary");
+  else
+SrcForMask = EmitCheckedInBoundsGEP(Int8Ty, SrcForMask, Args.Mask,
+/*SignedIndices=*/true,
+/*isSubtraction=*/false,
+E->getExprLoc(), "over_boundary");
+} else {
+  SrcForMask = Builder.CreateAdd(SrcForMask, Args.Mask, "over_boundary");
+}
   }
   // Invert the mask to only clear the lower bits.
   llvm::Value *InvertedMask = Builder.CreateNot(Args.Mask, "inverted_mask");
-  llvm::Value *Result =
-  Builder.CreateAnd(SrcForMask, InvertedMask, "aligned_result");
+  llvm::Value *Result = nullptr;
   if (Args.Src->getType()->isPointerTy()) {
-/// TODO: Use ptrmask instead of ptrtoint+gep once it is optimized well.
-// Result = Builder.CreateIntrinsic(
-//  Intrinsic::ptrmask, {Args.SrcType, SrcForMask->getType(), 
Args.IntType},
-//  {SrcForMask, NegatedMask}, nullptr, "aligned_result");
-Result->setName("aligned_intptr");
-llvm::Value *Difference = Builder.CreateSub(Result, SrcAddr, "diff");
-// The result must point to the same underlying allocation. This means we
-// can use an inbounds GEP to enable better optimization.
-if (getLangOpts().isSignedOverflowDefined())
-  Result =
-  Builder.CreateGEP(Int8Ty, Args.Src, Difference, "aligned_result");
-else
-  Result = EmitCheckedInBoundsGEP(Int8Ty, Args.Src, Difference,
-  /*SignedIndices=*/true,
-  /*isSubtraction=*/!AlignUp,
-  E->getExprLoc(), "aligned_result");
+Result = Builder.CreateIntrinsic(
+Intrinsic::ptrmask, {Args.SrcType, Args.IntType},
+{SrcForMask, InvertedMask}, nullptr, "aligned_result");
+
 // Emit an alignment assumption to ensure that the new alignment is
 // propagated to loads/stores, etc.
 emitAlignmentAssumption(Result, E, E->getExprLoc(), Args.Alignment);
+  } else {
+Result = Builder.CreateAnd(SrcForMask, InvertedMask, "aligned_result");
   }
   assert(Result->getType() == Args.SrcType);
   return RValue::get(Result);
diff --git a/clang/test/CodeGen/builtin-align-array.c 
b/clang/test/CodeGen/builtin-align-array.c
index 5d1377b98d2814f..18a77b9a710db40 100644
--- a/clang/test/CodeGen/builtin-align-array.c
+++ b/clang/test/CodeGen/builtin-align-array.c
@@ -8,22 +8,16 @@ extern int func(char *c);
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[BUF:%.*]] = alloca [1024 x i8], align 16
 // CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [1024 x i8], ptr 
[[BUF]], i64 0, i64 44
-// CHECK-NEXT:[[INTPTR:%.*]] = ptrtoint ptr [[ARRAYIDX]] to i64
-// CHECK-NEXT:[[ALIGNED_INTPTR:%.*]] = and i64 [[INTPTR]], -16
-// CHECK-NEXT:[[DIFF:%.*]] = sub i64 [[ALIGNED_INTPTR]], [[INTPTR]]
-// CHECK-NEXT:[[ALIGNED_RESULT:

[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2023-11-03 Thread Dan Liew via cfe-commits


@@ -0,0 +1,480 @@
+==
+-fbounds-safety: Enforcing bounds safety for C
+==
+
+.. contents::
+   :local:
+
+Overview
+
+
+-fbounds-safety is a C extension to enforce bounds safety to prevent 
out-of-bounds (OOB) memory accesses, which remain a major source of security 
vulnerabilities in C. -fbounds-safety aims to eliminate this class of bugs by 
turning OOB accesses into deterministic traps.
+
+The -fbounds-safety extension offers bounds annotations that programmers can 
use to attach bounds to pointers. For example, programmers can add the 
__counted_by(N) annotation to parameter ptr, indicating that the pointer has N 
valid elements:
+
+.. code-block:: c
+
+   void foo(int *__counted_by(N) ptr, size_t N);
+
+Using this bounds information, the compiler inserts bounds checks on every 
pointer dereference, ensuring that the program does not access memory outside 
the specified bounds. The compiler requires programmers to provide enough 
bounds information so that the accesses can be checked at either run time or 
compile time — and it rejects code if it cannot.
+
+The most important contribution of “-fbounds-safety” is how it reduces the 
programmer’s annotation burden by reconciling bounds annotations at ABI 
boundaries with the use of implicit wide pointers (a.k.a. “fat” pointers) that 
carry bounds information on local variables without the need for annotations. 
We designed this model so that it preserves ABI compatibility with C while 
minimizing adoption effort.
+
+The -fbounds-safety extension has been adopted on millions of lines of 
production C code and proven to work in a consumer operating system setting. 
The extension was designed to enable incremental adoption — a key requirement 
in real-world settings where modifying an entire project and its dependencies 
all at once is often not possible. It also addresses multiple of other 
practical challenges that have made existing approaches to safer C dialects 
difficult to adopt, offering these properties that make it widely adoptable in 
practice:
+
+* It is designed to preserve the Application Binary Interface (ABI)
+* It interoperates well with plain C code
+* It can be adopted partially and incrementally while still providing safety 
benefits
+* It is syntactically and semantically compatible with C
+* Consequently, source code that adopts the extension can continue to be 
compiled by toolchains that do not support the extension.
+* It has a relatively low adoption cost
+* It can be implemented on top of Clang
+
+
+Programming Model
+
+
+Overview
+-
+
+-fbounds-safety ensures that pointers are not used to access memory beyond 
their bounds by performing bounds checking. If a bounds check fails, the 
program will deterministically trap before out-of-bounds memory is accessed.
+
+In our model, every pointer has an explicit or implicit bounds attribute that 
determines its bounds and ensures guaranteed bounds checking. Consider the 
example below where the __counted_by(count) annotation indicates that parameter 
ppoints to a buffer of int s containing count elements. An off-by-one error is 
present in the loop condition, leading to p[i]being out-of-bounds access during 
the loop’s final iteration. The compiler inserts a bounds check before p is 
dereferenced to ensure that the access remains within the specified bounds.
+
+.. code-block:: c
+
+   void fill_array_with_indices(int *__counted_by(count) p, unsigned count) {  
+   // off-by-one error (i < count)  
+  for (unsigned i = 0; i <= count; ++i) {  
+ // bounds check inserted:  
+ //   if (i >= count) trap();  
+ p[i] = i;  
+  }  
+   }
+
+A bounds annotation defines an invariant for the pointer type, and the model 
ensures that this invariant remains true. In the example below, pointer p 
annotated with __counted_by(count) must always point to a memory buffer 
containing at least count elements of the pointee type. Increasing the value of 
count , like in the example below, would violate this invariant and permit 
out-of-bounds access to the pointer. To avoid this, the compiler emits either a 
compile-time error or a run-time trap. Section “Maintaining correctness of 
bounds annotations”) provides more details about the programming model.
+
+.. code-block:: c
+
+   void foo(int *__counted_by(count) p, size_t count) {  
+  count++; // violates the invariant of __counted_by   
+   }
+
+The requirement to annotate all pointers with explicit bounds information 
could present a significant adoption burden. To tackle this issue, the model 
incorporates the concept of a “wide pointer” (a.k.a. fat pointer) – a larger 
pointer that carries bounds information alongside the pointer value. Utilizing 
wide pointers can potentially reduce the adoption burden, as it contains bounds 
information internally and

[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2023-11-03 Thread Dan Liew via cfe-commits


@@ -0,0 +1,480 @@
+==
+-fbounds-safety: Enforcing bounds safety for C
+==
+
+.. contents::
+   :local:
+
+Overview
+
+
+-fbounds-safety is a C extension to enforce bounds safety to prevent 
out-of-bounds (OOB) memory accesses, which remain a major source of security 
vulnerabilities in C. -fbounds-safety aims to eliminate this class of bugs by 
turning OOB accesses into deterministic traps.
+
+The -fbounds-safety extension offers bounds annotations that programmers can 
use to attach bounds to pointers. For example, programmers can add the 
__counted_by(N) annotation to parameter ptr, indicating that the pointer has N 
valid elements:

delcypher wrote:

Should `__counted_by(...)` and other attributes be quoted to be monospaced?

https://github.com/llvm/llvm-project/pull/70749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2023-11-03 Thread Dan Liew via cfe-commits

https://github.com/delcypher edited 
https://github.com/llvm/llvm-project/pull/70749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2023-11-03 Thread Dan Liew via cfe-commits


@@ -0,0 +1,480 @@
+==
+-fbounds-safety: Enforcing bounds safety for C
+==
+
+.. contents::
+   :local:
+
+Overview
+
+
+-fbounds-safety is a C extension to enforce bounds safety to prevent 
out-of-bounds (OOB) memory accesses, which remain a major source of security 
vulnerabilities in C. -fbounds-safety aims to eliminate this class of bugs by 
turning OOB accesses into deterministic traps.
+
+The -fbounds-safety extension offers bounds annotations that programmers can 
use to attach bounds to pointers. For example, programmers can add the 
__counted_by(N) annotation to parameter ptr, indicating that the pointer has N 
valid elements:
+
+.. code-block:: c
+
+   void foo(int *__counted_by(N) ptr, size_t N);
+
+Using this bounds information, the compiler inserts bounds checks on every 
pointer dereference, ensuring that the program does not access memory outside 
the specified bounds. The compiler requires programmers to provide enough 
bounds information so that the accesses can be checked at either run time or 
compile time — and it rejects code if it cannot.
+
+The most important contribution of “-fbounds-safety” is how it reduces the 
programmer’s annotation burden by reconciling bounds annotations at ABI 
boundaries with the use of implicit wide pointers (a.k.a. “fat” pointers) that 
carry bounds information on local variables without the need for annotations. 
We designed this model so that it preserves ABI compatibility with C while 
minimizing adoption effort.
+
+The -fbounds-safety extension has been adopted on millions of lines of 
production C code and proven to work in a consumer operating system setting. 
The extension was designed to enable incremental adoption — a key requirement 
in real-world settings where modifying an entire project and its dependencies 
all at once is often not possible. It also addresses multiple of other 
practical challenges that have made existing approaches to safer C dialects 
difficult to adopt, offering these properties that make it widely adoptable in 
practice:
+
+* It is designed to preserve the Application Binary Interface (ABI)
+* It interoperates well with plain C code
+* It can be adopted partially and incrementally while still providing safety 
benefits
+* It is syntactically and semantically compatible with C
+* Consequently, source code that adopts the extension can continue to be 
compiled by toolchains that do not support the extension.
+* It has a relatively low adoption cost
+* It can be implemented on top of Clang
+
+
+Programming Model
+
+
+Overview
+-

delcypher wrote:

Nit: Too may `-` characters?

https://github.com/llvm/llvm-project/pull/70749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2023-11-03 Thread Dan Liew via cfe-commits


@@ -0,0 +1,480 @@
+==
+-fbounds-safety: Enforcing bounds safety for C
+==
+
+.. contents::
+   :local:
+
+Overview
+
+
+-fbounds-safety is a C extension to enforce bounds safety to prevent 
out-of-bounds (OOB) memory accesses, which remain a major source of security 
vulnerabilities in C. -fbounds-safety aims to eliminate this class of bugs by 
turning OOB accesses into deterministic traps.
+
+The -fbounds-safety extension offers bounds annotations that programmers can 
use to attach bounds to pointers. For example, programmers can add the 
__counted_by(N) annotation to parameter ptr, indicating that the pointer has N 
valid elements:
+
+.. code-block:: c
+
+   void foo(int *__counted_by(N) ptr, size_t N);
+
+Using this bounds information, the compiler inserts bounds checks on every 
pointer dereference, ensuring that the program does not access memory outside 
the specified bounds. The compiler requires programmers to provide enough 
bounds information so that the accesses can be checked at either run time or 
compile time — and it rejects code if it cannot.
+
+The most important contribution of “-fbounds-safety” is how it reduces the 
programmer’s annotation burden by reconciling bounds annotations at ABI 
boundaries with the use of implicit wide pointers (a.k.a. “fat” pointers) that 
carry bounds information on local variables without the need for annotations. 
We designed this model so that it preserves ABI compatibility with C while 
minimizing adoption effort.
+
+The -fbounds-safety extension has been adopted on millions of lines of 
production C code and proven to work in a consumer operating system setting. 
The extension was designed to enable incremental adoption — a key requirement 
in real-world settings where modifying an entire project and its dependencies 
all at once is often not possible. It also addresses multiple of other 
practical challenges that have made existing approaches to safer C dialects 
difficult to adopt, offering these properties that make it widely adoptable in 
practice:
+
+* It is designed to preserve the Application Binary Interface (ABI)
+* It interoperates well with plain C code
+* It can be adopted partially and incrementally while still providing safety 
benefits
+* It is syntactically and semantically compatible with C
+* Consequently, source code that adopts the extension can continue to be 
compiled by toolchains that do not support the extension.
+* It has a relatively low adoption cost
+* It can be implemented on top of Clang
+
+
+Programming Model
+
+
+Overview
+-
+
+-fbounds-safety ensures that pointers are not used to access memory beyond 
their bounds by performing bounds checking. If a bounds check fails, the 
program will deterministically trap before out-of-bounds memory is accessed.
+
+In our model, every pointer has an explicit or implicit bounds attribute that 
determines its bounds and ensures guaranteed bounds checking. Consider the 
example below where the __counted_by(count) annotation indicates that parameter 
ppoints to a buffer of int s containing count elements. An off-by-one error is 
present in the loop condition, leading to p[i]being out-of-bounds access during 
the loop’s final iteration. The compiler inserts a bounds check before p is 
dereferenced to ensure that the access remains within the specified bounds.
+
+.. code-block:: c
+
+   void fill_array_with_indices(int *__counted_by(count) p, unsigned count) {  
+   // off-by-one error (i < count)  
+  for (unsigned i = 0; i <= count; ++i) {  
+ // bounds check inserted:  
+ //   if (i >= count) trap();  
+ p[i] = i;  
+  }  
+   }
+
+A bounds annotation defines an invariant for the pointer type, and the model 
ensures that this invariant remains true. In the example below, pointer p 
annotated with __counted_by(count) must always point to a memory buffer 
containing at least count elements of the pointee type. Increasing the value of 
count , like in the example below, would violate this invariant and permit 
out-of-bounds access to the pointer. To avoid this, the compiler emits either a 
compile-time error or a run-time trap. Section “Maintaining correctness of 
bounds annotations”) provides more details about the programming model.
+
+.. code-block:: c
+
+   void foo(int *__counted_by(count) p, size_t count) {  
+  count++; // violates the invariant of __counted_by   
+   }
+
+The requirement to annotate all pointers with explicit bounds information 
could present a significant adoption burden. To tackle this issue, the model 
incorporates the concept of a “wide pointer” (a.k.a. fat pointer) – a larger 
pointer that carries bounds information alongside the pointer value. Utilizing 
wide pointers can potentially reduce the adoption burden, as it contains bounds 
information internally and

[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2023-11-03 Thread Dan Liew via cfe-commits


@@ -0,0 +1,480 @@
+==
+-fbounds-safety: Enforcing bounds safety for C
+==
+
+.. contents::
+   :local:
+
+Overview
+
+
+-fbounds-safety is a C extension to enforce bounds safety to prevent 
out-of-bounds (OOB) memory accesses, which remain a major source of security 
vulnerabilities in C. -fbounds-safety aims to eliminate this class of bugs by 
turning OOB accesses into deterministic traps.

delcypher wrote:

Should `-fbounds-safety` be quoted to be monospaced?

https://github.com/llvm/llvm-project/pull/70749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2023-11-03 Thread Dan Liew via cfe-commits

https://github.com/delcypher edited 
https://github.com/llvm/llvm-project/pull/70749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2023-11-03 Thread Dan Liew via cfe-commits


@@ -0,0 +1,480 @@
+==
+-fbounds-safety: Enforcing bounds safety for C
+==
+
+.. contents::
+   :local:
+
+Overview
+
+
+-fbounds-safety is a C extension to enforce bounds safety to prevent 
out-of-bounds (OOB) memory accesses, which remain a major source of security 
vulnerabilities in C. -fbounds-safety aims to eliminate this class of bugs by 
turning OOB accesses into deterministic traps.
+
+The -fbounds-safety extension offers bounds annotations that programmers can 
use to attach bounds to pointers. For example, programmers can add the 
__counted_by(N) annotation to parameter ptr, indicating that the pointer has N 
valid elements:
+
+.. code-block:: c
+
+   void foo(int *__counted_by(N) ptr, size_t N);
+
+Using this bounds information, the compiler inserts bounds checks on every 
pointer dereference, ensuring that the program does not access memory outside 
the specified bounds. The compiler requires programmers to provide enough 
bounds information so that the accesses can be checked at either run time or 
compile time — and it rejects code if it cannot.
+
+The most important contribution of “-fbounds-safety” is how it reduces the 
programmer’s annotation burden by reconciling bounds annotations at ABI 
boundaries with the use of implicit wide pointers (a.k.a. “fat” pointers) that 
carry bounds information on local variables without the need for annotations. 
We designed this model so that it preserves ABI compatibility with C while 
minimizing adoption effort.

delcypher wrote:

Did you mean to use open and close quotes (`“` and `”`) rather than symmetrical 
quote `"`? I would prefer to use the symmetrical quote because it makes edits 
to the document easier.

https://github.com/llvm/llvm-project/pull/70749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2023-11-03 Thread Dan Liew via cfe-commits

https://github.com/delcypher approved this pull request.

I have a few minor nits but other than that LGTM.

Please make sure this builds without errors/warnings.

I think you can configure CMake with `-DLLVM_BUILD_DOCS=ON -D 
LLVM_ENABLE_SPHINX=ON -DSPHINX_WARNINGS_AS_ERROR=ON` to enable building the 
documentation. The target to build the docs is `docs-clang-html`

https://github.com/llvm/llvm-project/pull/70749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-03 Thread Saiyedul Islam via cfe-commits

https://github.com/saiislam updated 
https://github.com/llvm/llvm-project/pull/71234

>From 36976c1a97518c9cdf080d80b5fab2b16837b055 Mon Sep 17 00:00:00 2001
From: Saiyedul Islam 
Date: Fri, 3 Nov 2023 16:16:25 -0500
Subject: [PATCH 1/2] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL

Fixes the DeviceRTL compilation to ensure it is ABI agnostic.
Uses already available global variable "oclc_ABI_version" instead
of "llvm.amdgcn.abi.verion".

It also adds some minor fields in ImplicitArg structure.
---
 clang/include/clang/Basic/TargetOptions.h |  2 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |  6 +-
 clang/lib/CodeGen/Targets/AMDGPU.cpp  |  5 +-
 clang/test/CodeGen/amdgpu-abi-version.c   |  4 +-
 clang/test/CodeGen/amdgpu-address-spaces.cpp  |  2 +-
 .../amdgpu-code-object-version-linking.cu | 16 +++---
 .../test/CodeGenCUDA/amdgpu-workgroup-size.cu |  6 +-
 .../plugins-nextgen/amdgpu/src/rtl.cpp| 57 +++
 .../amdgpu/utils/UtilitiesRTL.h   |  4 +-
 9 files changed, 82 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/Basic/TargetOptions.h 
b/clang/include/clang/Basic/TargetOptions.h
index 8bb03249b7f8308..f9c03b61a2a827c 100644
--- a/clang/include/clang/Basic/TargetOptions.h
+++ b/clang/include/clang/Basic/TargetOptions.h
@@ -88,7 +88,7 @@ class TargetOptions {
 COV_5 = 500,
   };
   /// \brief Code object version for AMDGPU.
-  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_None;
+  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_4;
 
   /// \brief Enumeration values for AMDGPU printf lowering scheme
   enum class AMDGPUPrintfKind {
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 972aa1c708e5f65..8a9d83fd29e2b77 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17468,11 +17468,11 @@ Value *EmitAMDGPUImplicitArgPtr(CodeGenFunction &CGF) 
{
 /// Emit code based on Code Object ABI version.
 /// COV_4: Emit code to use dispatch ptr
 /// COV_5: Emit code to use implicitarg ptr
-/// COV_NONE : Emit code to load a global variable "llvm.amdgcn.abi.version"
+/// COV_NONE : Emit code to load a global variable "__oclc_ABI_version"
 ///and use its value for COV_4 or COV_5 approach. It is used for
 ///compiling device libraries in an ABI-agnostic way.
 ///
-/// Note: "llvm.amdgcn.abi.version" is supposed to be emitted and intialized by
+/// Note: "__oclc_ABI_version" is supposed to be emitted and intialized by
 ///   clang during compilation of user code.
 Value *EmitAMDGPUWorkGroupSize(CodeGenFunction &CGF, unsigned Index) {
   llvm::LoadInst *LD;
@@ -17480,7 +17480,7 @@ Value *EmitAMDGPUWorkGroupSize(CodeGenFunction &CGF, 
unsigned Index) {
   auto Cov = CGF.getTarget().getTargetOpts().CodeObjectVersion;
 
   if (Cov == clang::TargetOptions::COV_None) {
-StringRef Name = "llvm.amdgcn.abi.version";
+StringRef Name = "__oclc_ABI_version";
 auto *ABIVersionC = CGF.CGM.getModule().getNamedGlobal(Name);
 if (!ABIVersionC)
   ABIVersionC = new llvm::GlobalVariable(
diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index 0411846cf9b02bd..d793d27e0db8b80 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -362,11 +362,14 @@ void AMDGPUTargetCodeGenInfo::setFunctionDeclAttributes(
 /// AMDGPU ROCm device libraries.
 void AMDGPUTargetCodeGenInfo::emitTargetGlobals(
 CodeGen::CodeGenModule &CGM) const {
-  StringRef Name = "llvm.amdgcn.abi.version";
+  StringRef Name = "__oclc_ABI_version";
   llvm::GlobalVariable *OriginalGV = CGM.getModule().getNamedGlobal(Name);
   if (OriginalGV && 
!llvm::GlobalVariable::isExternalLinkage(OriginalGV->getLinkage()))
 return;
 
+  if(CGM.getTarget().getTargetOpts().CodeObjectVersion == 
clang::TargetOptions::COV_None)
+return;
+
   auto *Type = llvm::IntegerType::getIntNTy(CGM.getModule().getContext(), 32);
   llvm::Constant *COV = llvm::ConstantInt::get(
   Type, CGM.getTarget().getTargetOpts().CodeObjectVersion);
diff --git a/clang/test/CodeGen/amdgpu-abi-version.c 
b/clang/test/CodeGen/amdgpu-abi-version.c
index d1189545139e2a6..4e5ad87655f2305 100644
--- a/clang/test/CodeGen/amdgpu-abi-version.c
+++ b/clang/test/CodeGen/amdgpu-abi-version.c
@@ -2,14 +2,14 @@
 // RUN: %clang_cc1 -cc1 -triple amdgcn-amd-amdhsa -emit-llvm 
-mcode-object-version=none %s -o - | FileCheck %s
 
 //.
-// CHECK: @llvm.amdgcn.abi.version = weak_odr hidden local_unnamed_addr 
addrspace(4) constant i32 0
+// CHECK: @__oclc_ABI_version = external addrspace(4) global i32
 //.
 // CHECK-LABEL: define dso_local i32 @foo(
 // 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:[[TMP0

[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-03 Thread Saiyedul Islam via cfe-commits

https://github.com/saiislam updated 
https://github.com/llvm/llvm-project/pull/71234

>From 36976c1a97518c9cdf080d80b5fab2b16837b055 Mon Sep 17 00:00:00 2001
From: Saiyedul Islam 
Date: Fri, 3 Nov 2023 16:16:25 -0500
Subject: [PATCH 1/2] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL

Fixes the DeviceRTL compilation to ensure it is ABI agnostic.
Uses already available global variable "oclc_ABI_version" instead
of "llvm.amdgcn.abi.verion".

It also adds some minor fields in ImplicitArg structure.
---
 clang/include/clang/Basic/TargetOptions.h |  2 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |  6 +-
 clang/lib/CodeGen/Targets/AMDGPU.cpp  |  5 +-
 clang/test/CodeGen/amdgpu-abi-version.c   |  4 +-
 clang/test/CodeGen/amdgpu-address-spaces.cpp  |  2 +-
 .../amdgpu-code-object-version-linking.cu | 16 +++---
 .../test/CodeGenCUDA/amdgpu-workgroup-size.cu |  6 +-
 .../plugins-nextgen/amdgpu/src/rtl.cpp| 57 +++
 .../amdgpu/utils/UtilitiesRTL.h   |  4 +-
 9 files changed, 82 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/Basic/TargetOptions.h 
b/clang/include/clang/Basic/TargetOptions.h
index 8bb03249b7f8308..f9c03b61a2a827c 100644
--- a/clang/include/clang/Basic/TargetOptions.h
+++ b/clang/include/clang/Basic/TargetOptions.h
@@ -88,7 +88,7 @@ class TargetOptions {
 COV_5 = 500,
   };
   /// \brief Code object version for AMDGPU.
-  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_None;
+  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_4;
 
   /// \brief Enumeration values for AMDGPU printf lowering scheme
   enum class AMDGPUPrintfKind {
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 972aa1c708e5f65..8a9d83fd29e2b77 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17468,11 +17468,11 @@ Value *EmitAMDGPUImplicitArgPtr(CodeGenFunction &CGF) 
{
 /// Emit code based on Code Object ABI version.
 /// COV_4: Emit code to use dispatch ptr
 /// COV_5: Emit code to use implicitarg ptr
-/// COV_NONE : Emit code to load a global variable "llvm.amdgcn.abi.version"
+/// COV_NONE : Emit code to load a global variable "__oclc_ABI_version"
 ///and use its value for COV_4 or COV_5 approach. It is used for
 ///compiling device libraries in an ABI-agnostic way.
 ///
-/// Note: "llvm.amdgcn.abi.version" is supposed to be emitted and intialized by
+/// Note: "__oclc_ABI_version" is supposed to be emitted and intialized by
 ///   clang during compilation of user code.
 Value *EmitAMDGPUWorkGroupSize(CodeGenFunction &CGF, unsigned Index) {
   llvm::LoadInst *LD;
@@ -17480,7 +17480,7 @@ Value *EmitAMDGPUWorkGroupSize(CodeGenFunction &CGF, 
unsigned Index) {
   auto Cov = CGF.getTarget().getTargetOpts().CodeObjectVersion;
 
   if (Cov == clang::TargetOptions::COV_None) {
-StringRef Name = "llvm.amdgcn.abi.version";
+StringRef Name = "__oclc_ABI_version";
 auto *ABIVersionC = CGF.CGM.getModule().getNamedGlobal(Name);
 if (!ABIVersionC)
   ABIVersionC = new llvm::GlobalVariable(
diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index 0411846cf9b02bd..d793d27e0db8b80 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -362,11 +362,14 @@ void AMDGPUTargetCodeGenInfo::setFunctionDeclAttributes(
 /// AMDGPU ROCm device libraries.
 void AMDGPUTargetCodeGenInfo::emitTargetGlobals(
 CodeGen::CodeGenModule &CGM) const {
-  StringRef Name = "llvm.amdgcn.abi.version";
+  StringRef Name = "__oclc_ABI_version";
   llvm::GlobalVariable *OriginalGV = CGM.getModule().getNamedGlobal(Name);
   if (OriginalGV && 
!llvm::GlobalVariable::isExternalLinkage(OriginalGV->getLinkage()))
 return;
 
+  if(CGM.getTarget().getTargetOpts().CodeObjectVersion == 
clang::TargetOptions::COV_None)
+return;
+
   auto *Type = llvm::IntegerType::getIntNTy(CGM.getModule().getContext(), 32);
   llvm::Constant *COV = llvm::ConstantInt::get(
   Type, CGM.getTarget().getTargetOpts().CodeObjectVersion);
diff --git a/clang/test/CodeGen/amdgpu-abi-version.c 
b/clang/test/CodeGen/amdgpu-abi-version.c
index d1189545139e2a6..4e5ad87655f2305 100644
--- a/clang/test/CodeGen/amdgpu-abi-version.c
+++ b/clang/test/CodeGen/amdgpu-abi-version.c
@@ -2,14 +2,14 @@
 // RUN: %clang_cc1 -cc1 -triple amdgcn-amd-amdhsa -emit-llvm 
-mcode-object-version=none %s -o - | FileCheck %s
 
 //.
-// CHECK: @llvm.amdgcn.abi.version = weak_odr hidden local_unnamed_addr 
addrspace(4) constant i32 0
+// CHECK: @__oclc_ABI_version = external addrspace(4) global i32
 //.
 // CHECK-LABEL: define dso_local i32 @foo(
 // 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:[[TMP0

[clang] [clang][analyzer] Do not analyze opaque types in CXXDeleteChecker (PR #70638)

2023-11-03 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

In case it is not too hard to synthesize a test case, could you add a 
regression test as well in a follow-up commit?

https://github.com/llvm/llvm-project/pull/70638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-03 Thread Saiyedul Islam via cfe-commits


@@ -3086,10 +3139,14 @@ Error AMDGPUKernelTy::launchImpl(GenericDeviceTy 
&GenericDevice,
   // Only COV5 implicitargs needs to be set. COV4 implicitargs are not used.
   if (getImplicitArgsSize() == sizeof(utils::AMDGPUImplicitArgsTy)) {
 ImplArgs->BlockCountX = NumBlocks;
+ImplArgs->BlockCountY = 1;
+ImplArgs->BlockCountZ = 1;
 ImplArgs->GroupSizeX = NumThreads;
 ImplArgs->GroupSizeY = 1;
 ImplArgs->GroupSizeZ = 1;
 ImplArgs->GridDims = 1;
+ImplArgs->HeapV1Ptr =

saiislam wrote:

Agreed. Removing the field.

https://github.com/llvm/llvm-project/pull/71234
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-03 Thread Saiyedul Islam via cfe-commits


@@ -17468,19 +17468,19 @@ Value *EmitAMDGPUImplicitArgPtr(CodeGenFunction &CGF) 
{
 /// Emit code based on Code Object ABI version.
 /// COV_4: Emit code to use dispatch ptr
 /// COV_5: Emit code to use implicitarg ptr
-/// COV_NONE : Emit code to load a global variable "llvm.amdgcn.abi.version"
+/// COV_NONE : Emit code to load a global variable "__oclc_ABI_version"

saiislam wrote:

`oclc_ABI_version` already exist in the upstream. And, it contains the exact 
same information as `llvm.amdgcn.abi.version` was supposed to store. So, I 
removed the latter with the former.

This patch is ensuring that DeviceRTL is indeed ABI agnostic.

I agree with your suggestion that it would be great to not deal with these 
things in the driver.

https://github.com/llvm/llvm-project/pull/71234
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-03 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 3cf9bf343de5fbc0b755572c60e8ed53628ff614 
36976c1a97518c9cdf080d80b5fab2b16837b055 -- 
clang/include/clang/Basic/TargetOptions.h clang/lib/CodeGen/CGBuiltin.cpp 
clang/lib/CodeGen/Targets/AMDGPU.cpp clang/test/CodeGen/amdgpu-abi-version.c 
clang/test/CodeGen/amdgpu-address-spaces.cpp 
openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp 
openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index d793d27e0db8..4dd25213dda9 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -367,7 +367,8 @@ void AMDGPUTargetCodeGenInfo::emitTargetGlobals(
   if (OriginalGV && 
!llvm::GlobalVariable::isExternalLinkage(OriginalGV->getLinkage()))
 return;
 
-  if(CGM.getTarget().getTargetOpts().CodeObjectVersion == 
clang::TargetOptions::COV_None)
+  if (CGM.getTarget().getTargetOpts().CodeObjectVersion ==
+  clang::TargetOptions::COV_None)
 return;
 
   auto *Type = llvm::IntegerType::getIntNTy(CGM.getModule().getContext(), 32);
diff --git a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp 
b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
index c16b1a147982..1d7763fe37fe 100644
--- a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -2633,7 +2633,7 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, 
AMDGenericDeviceTy {
 });
   }
 
-/// Get the address of pointer to the preallocated device memory pool.
+  /// Get the address of pointer to the preallocated device memory pool.
   void *getPreAllocatedDeviceMemoryPool() {
 return PreAllocatedDeviceMemoryPool;
   }
@@ -2652,7 +2652,7 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, 
AMDGenericDeviceTy {
 
   if (MemoryPool->isCoarseGrained()) {
 DevPtr = nullptr;
-size_t PreAllocSize = 131072; //128 KB
+size_t PreAllocSize = 131072; // 128 KB
 
 Err = MemoryPool->allocate(PreAllocSize, &DevPtr);
 if (Err)

``




https://github.com/llvm/llvm-project/pull/71234
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-03 Thread Joseph Huber via cfe-commits


@@ -17468,19 +17468,19 @@ Value *EmitAMDGPUImplicitArgPtr(CodeGenFunction &CGF) 
{
 /// Emit code based on Code Object ABI version.
 /// COV_4: Emit code to use dispatch ptr
 /// COV_5: Emit code to use implicitarg ptr
-/// COV_NONE : Emit code to load a global variable "llvm.amdgcn.abi.version"
+/// COV_NONE : Emit code to load a global variable "__oclc_ABI_version"

jhuber6 wrote:

I have encountered the need for `__oclc_ABI_version` to be defined while I was 
fixing the new driver downstream, so I think this should be done at least in 
the downstream version. There's probably no reason to split the name at this 
point when they describe the same thing.

Long term, I don't think we should be using things related to the ROCm Device 
Libraries since they're an external thing. The best solution for this stuff is 
to either handle it in the backend or just default to some value. I'm going to 
assume that there will be a grace period where we support COV4, but once we've 
decided that support isn't needed we can probably just get rid of this code 
entirely and just expect COV5 or something. Hopefully we don't end up needing 
more things tied to this logic because I really don't like it.

https://github.com/llvm/llvm-project/pull/71234
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-03 Thread Joseph Huber via cfe-commits


@@ -3086,10 +3139,14 @@ Error AMDGPUKernelTy::launchImpl(GenericDeviceTy 
&GenericDevice,
   // Only COV5 implicitargs needs to be set. COV4 implicitargs are not used.
   if (getImplicitArgsSize() == sizeof(utils::AMDGPUImplicitArgsTy)) {
 ImplArgs->BlockCountX = NumBlocks;
+ImplArgs->BlockCountY = 1;
+ImplArgs->BlockCountZ = 1;
 ImplArgs->GroupSizeX = NumThreads;
 ImplArgs->GroupSizeY = 1;
 ImplArgs->GroupSizeZ = 1;
 ImplArgs->GridDims = 1;
+ImplArgs->HeapV1Ptr =

jhuber6 wrote:

Why do we need this? I'm assuming the user is `__ockl_dm_alloc`, but we don't 
use that anywhere because it requires the AMD RPC implementation.

https://github.com/llvm/llvm-project/pull/71234
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-03 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Saiyedul Islam (saiislam)


Changes

Fixes the DeviceRTL compilation to ensure it is ABI agnostic. Uses already 
available global variable "oclc_ABI_version" instead of 
"llvm.amdgcn.abi.verion".

It also adds some minor fields in ImplicitArg structure.

---
Full diff: https://github.com/llvm/llvm-project/pull/71234.diff


9 Files Affected:

- (modified) clang/include/clang/Basic/TargetOptions.h (+1-1) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+3-3) 
- (modified) clang/lib/CodeGen/Targets/AMDGPU.cpp (+4-1) 
- (modified) clang/test/CodeGen/amdgpu-abi-version.c (+2-2) 
- (modified) clang/test/CodeGen/amdgpu-address-spaces.cpp (+1-1) 
- (modified) clang/test/CodeGenCUDA/amdgpu-code-object-version-linking.cu 
(+8-8) 
- (modified) clang/test/CodeGenCUDA/amdgpu-workgroup-size.cu (+3-3) 
- (modified) openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp (+57) 
- (modified) openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h 
(+3-1) 


``diff
diff --git a/clang/include/clang/Basic/TargetOptions.h 
b/clang/include/clang/Basic/TargetOptions.h
index 8bb03249b7f8308..f9c03b61a2a827c 100644
--- a/clang/include/clang/Basic/TargetOptions.h
+++ b/clang/include/clang/Basic/TargetOptions.h
@@ -88,7 +88,7 @@ class TargetOptions {
 COV_5 = 500,
   };
   /// \brief Code object version for AMDGPU.
-  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_None;
+  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_4;
 
   /// \brief Enumeration values for AMDGPU printf lowering scheme
   enum class AMDGPUPrintfKind {
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 972aa1c708e5f65..8a9d83fd29e2b77 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17468,11 +17468,11 @@ Value *EmitAMDGPUImplicitArgPtr(CodeGenFunction &CGF) 
{
 /// Emit code based on Code Object ABI version.
 /// COV_4: Emit code to use dispatch ptr
 /// COV_5: Emit code to use implicitarg ptr
-/// COV_NONE : Emit code to load a global variable "llvm.amdgcn.abi.version"
+/// COV_NONE : Emit code to load a global variable "__oclc_ABI_version"
 ///and use its value for COV_4 or COV_5 approach. It is used for
 ///compiling device libraries in an ABI-agnostic way.
 ///
-/// Note: "llvm.amdgcn.abi.version" is supposed to be emitted and intialized by
+/// Note: "__oclc_ABI_version" is supposed to be emitted and intialized by
 ///   clang during compilation of user code.
 Value *EmitAMDGPUWorkGroupSize(CodeGenFunction &CGF, unsigned Index) {
   llvm::LoadInst *LD;
@@ -17480,7 +17480,7 @@ Value *EmitAMDGPUWorkGroupSize(CodeGenFunction &CGF, 
unsigned Index) {
   auto Cov = CGF.getTarget().getTargetOpts().CodeObjectVersion;
 
   if (Cov == clang::TargetOptions::COV_None) {
-StringRef Name = "llvm.amdgcn.abi.version";
+StringRef Name = "__oclc_ABI_version";
 auto *ABIVersionC = CGF.CGM.getModule().getNamedGlobal(Name);
 if (!ABIVersionC)
   ABIVersionC = new llvm::GlobalVariable(
diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index 0411846cf9b02bd..d793d27e0db8b80 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -362,11 +362,14 @@ void AMDGPUTargetCodeGenInfo::setFunctionDeclAttributes(
 /// AMDGPU ROCm device libraries.
 void AMDGPUTargetCodeGenInfo::emitTargetGlobals(
 CodeGen::CodeGenModule &CGM) const {
-  StringRef Name = "llvm.amdgcn.abi.version";
+  StringRef Name = "__oclc_ABI_version";
   llvm::GlobalVariable *OriginalGV = CGM.getModule().getNamedGlobal(Name);
   if (OriginalGV && 
!llvm::GlobalVariable::isExternalLinkage(OriginalGV->getLinkage()))
 return;
 
+  if(CGM.getTarget().getTargetOpts().CodeObjectVersion == 
clang::TargetOptions::COV_None)
+return;
+
   auto *Type = llvm::IntegerType::getIntNTy(CGM.getModule().getContext(), 32);
   llvm::Constant *COV = llvm::ConstantInt::get(
   Type, CGM.getTarget().getTargetOpts().CodeObjectVersion);
diff --git a/clang/test/CodeGen/amdgpu-abi-version.c 
b/clang/test/CodeGen/amdgpu-abi-version.c
index d1189545139e2a6..4e5ad87655f2305 100644
--- a/clang/test/CodeGen/amdgpu-abi-version.c
+++ b/clang/test/CodeGen/amdgpu-abi-version.c
@@ -2,14 +2,14 @@
 // RUN: %clang_cc1 -cc1 -triple amdgcn-amd-amdhsa -emit-llvm 
-mcode-object-version=none %s -o - | FileCheck %s
 
 //.
-// CHECK: @llvm.amdgcn.abi.version = weak_odr hidden local_unnamed_addr 
addrspace(4) constant i32 0
+// CHECK: @__oclc_ABI_version = external addrspace(4) global i32
 //.
 // CHECK-LABEL: define dso_local i32 @foo(
 // 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:[[TMP0:%.*]] = load i3

[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-03 Thread Saiyedul Islam via cfe-commits

https://github.com/saiislam created 
https://github.com/llvm/llvm-project/pull/71234

Fixes the DeviceRTL compilation to ensure it is ABI agnostic. Uses already 
available global variable "oclc_ABI_version" instead of 
"llvm.amdgcn.abi.verion".

It also adds some minor fields in ImplicitArg structure.

>From 36976c1a97518c9cdf080d80b5fab2b16837b055 Mon Sep 17 00:00:00 2001
From: Saiyedul Islam 
Date: Fri, 3 Nov 2023 16:16:25 -0500
Subject: [PATCH] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL

Fixes the DeviceRTL compilation to ensure it is ABI agnostic.
Uses already available global variable "oclc_ABI_version" instead
of "llvm.amdgcn.abi.verion".

It also adds some minor fields in ImplicitArg structure.
---
 clang/include/clang/Basic/TargetOptions.h |  2 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |  6 +-
 clang/lib/CodeGen/Targets/AMDGPU.cpp  |  5 +-
 clang/test/CodeGen/amdgpu-abi-version.c   |  4 +-
 clang/test/CodeGen/amdgpu-address-spaces.cpp  |  2 +-
 .../amdgpu-code-object-version-linking.cu | 16 +++---
 .../test/CodeGenCUDA/amdgpu-workgroup-size.cu |  6 +-
 .../plugins-nextgen/amdgpu/src/rtl.cpp| 57 +++
 .../amdgpu/utils/UtilitiesRTL.h   |  4 +-
 9 files changed, 82 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/Basic/TargetOptions.h 
b/clang/include/clang/Basic/TargetOptions.h
index 8bb03249b7f8308..f9c03b61a2a827c 100644
--- a/clang/include/clang/Basic/TargetOptions.h
+++ b/clang/include/clang/Basic/TargetOptions.h
@@ -88,7 +88,7 @@ class TargetOptions {
 COV_5 = 500,
   };
   /// \brief Code object version for AMDGPU.
-  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_None;
+  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_4;
 
   /// \brief Enumeration values for AMDGPU printf lowering scheme
   enum class AMDGPUPrintfKind {
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 972aa1c708e5f65..8a9d83fd29e2b77 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17468,11 +17468,11 @@ Value *EmitAMDGPUImplicitArgPtr(CodeGenFunction &CGF) 
{
 /// Emit code based on Code Object ABI version.
 /// COV_4: Emit code to use dispatch ptr
 /// COV_5: Emit code to use implicitarg ptr
-/// COV_NONE : Emit code to load a global variable "llvm.amdgcn.abi.version"
+/// COV_NONE : Emit code to load a global variable "__oclc_ABI_version"
 ///and use its value for COV_4 or COV_5 approach. It is used for
 ///compiling device libraries in an ABI-agnostic way.
 ///
-/// Note: "llvm.amdgcn.abi.version" is supposed to be emitted and intialized by
+/// Note: "__oclc_ABI_version" is supposed to be emitted and intialized by
 ///   clang during compilation of user code.
 Value *EmitAMDGPUWorkGroupSize(CodeGenFunction &CGF, unsigned Index) {
   llvm::LoadInst *LD;
@@ -17480,7 +17480,7 @@ Value *EmitAMDGPUWorkGroupSize(CodeGenFunction &CGF, 
unsigned Index) {
   auto Cov = CGF.getTarget().getTargetOpts().CodeObjectVersion;
 
   if (Cov == clang::TargetOptions::COV_None) {
-StringRef Name = "llvm.amdgcn.abi.version";
+StringRef Name = "__oclc_ABI_version";
 auto *ABIVersionC = CGF.CGM.getModule().getNamedGlobal(Name);
 if (!ABIVersionC)
   ABIVersionC = new llvm::GlobalVariable(
diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index 0411846cf9b02bd..d793d27e0db8b80 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -362,11 +362,14 @@ void AMDGPUTargetCodeGenInfo::setFunctionDeclAttributes(
 /// AMDGPU ROCm device libraries.
 void AMDGPUTargetCodeGenInfo::emitTargetGlobals(
 CodeGen::CodeGenModule &CGM) const {
-  StringRef Name = "llvm.amdgcn.abi.version";
+  StringRef Name = "__oclc_ABI_version";
   llvm::GlobalVariable *OriginalGV = CGM.getModule().getNamedGlobal(Name);
   if (OriginalGV && 
!llvm::GlobalVariable::isExternalLinkage(OriginalGV->getLinkage()))
 return;
 
+  if(CGM.getTarget().getTargetOpts().CodeObjectVersion == 
clang::TargetOptions::COV_None)
+return;
+
   auto *Type = llvm::IntegerType::getIntNTy(CGM.getModule().getContext(), 32);
   llvm::Constant *COV = llvm::ConstantInt::get(
   Type, CGM.getTarget().getTargetOpts().CodeObjectVersion);
diff --git a/clang/test/CodeGen/amdgpu-abi-version.c 
b/clang/test/CodeGen/amdgpu-abi-version.c
index d1189545139e2a6..4e5ad87655f2305 100644
--- a/clang/test/CodeGen/amdgpu-abi-version.c
+++ b/clang/test/CodeGen/amdgpu-abi-version.c
@@ -2,14 +2,14 @@
 // RUN: %clang_cc1 -cc1 -triple amdgcn-amd-amdhsa -emit-llvm 
-mcode-object-version=none %s -o - | FileCheck %s
 
 //.
-// CHECK: @llvm.amdgcn.abi.version = weak_odr hidden local_unnamed_addr 
addrspace(4) constant i32 0
+// CHECK: @__oclc_ABI_version = external addrspace(4) global i32
 //.
 // CHECK-LABEL: define dso_local i32 @foo(
 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] 

[libcxxabi] [flang] [libcxx] [llvm] [clang] [mlir] [clang-tools-extra] [lldb] [lld] [compiler-rt] Refactor ModuleToObject to offer more flexibility to subclass (NFC) (PR #71165)

2023-11-03 Thread Mehdi Amini via cfe-commits

https://github.com/joker-eph closed 
https://github.com/llvm/llvm-project/pull/71165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxxabi] [flang] [libcxx] [llvm] [clang] [mlir] [clang-tools-extra] [lldb] [lld] [compiler-rt] Refactor ModuleToObject to offer more flexibility to subclass (NFC) (PR #71165)

2023-11-03 Thread Mehdi Amini via cfe-commits

https://github.com/joker-eph edited 
https://github.com/llvm/llvm-project/pull/71165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

2023-11-03 Thread Yeoul Na via cfe-commits

rapidsna wrote:

> With this PR I get:
> 
> ```
> $ clang -O2 ~/llvm/bdos.c
> $ ./a.out
> 400
> 400
> 404
> ```

Oh I see. 

> I think the first two `printf` s in your code seem correct with 40, because 
> they're both looking at only the FAM, not the entire struct.

Interesting. So this sounds different from non-fam array cases. When the struct 
is not a flexible array member, e.g., `struct s {int a; int arr[3]; int b;};`  
`__bdos(&p->arr[0], 0)` would return the whole object size instead of the 
array-only size (12). https://godbolt.org/z/1e9nKPYb4 Was this difference part 
of the specification?

> struct flex *p = (struct flex *)malloc(sizeof(struct flex) + sizeof(int) * 
> 10);

I just wanted to call out that this case is interesting because the size 
derived from malloc and __counted_by compete each other. And __counted_by 
always wins. This conforms to how `-fbounds-safety` will see the size of 
objects, so sounds like we are all happy with it.

Similarly, this will also mean that , when we support `__counted_by` for 
pointers, the following will be the case.

```
int arr[10];
int *__counted_by(4) p = arr;

__bdos(arr, 0); // returns 4 * sizeof(int) instead of 10 * sizeof(int)

``` 

https://github.com/llvm/llvm-project/pull/70606
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/70841

>From 99abebc88c09346bd4a70bbf39df13b249116c09 Mon Sep 17 00:00:00 2001
From: Mingming Liu 
Date: Tue, 31 Oct 2023 01:17:03 -0700
Subject: [PATCH 1/6] [Clang]Emit type metadata when -fprofile-generate is on

---
 clang/lib/CodeGen/CGVTables.cpp |   2 +-
 clang/lib/CodeGen/MicrosoftCXXABI.cpp   |   3 +-
 clang/test/CodeGenCXX/type-metadata.cpp | 150 
 3 files changed, 80 insertions(+), 75 deletions(-)

diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 25e4b1c27932026..895e160dfa8a536 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -1312,7 +1312,7 @@ llvm::GlobalObject::VCallVisibility 
CodeGenModule::GetVCallVisibilityLevel(
 void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD,
llvm::GlobalVariable *VTable,
const VTableLayout &VTLayout) {
-  if (!getCodeGenOpts().LTOUnit)
+  if (!getCodeGenOpts().LTOUnit && !getCodeGenOpts().hasProfileIRInstr())
 return;
 
   CharUnits ComponentWidth = GetTargetTypeStoreSize(getVTableComponentType());
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index d623f8f63ae56c4..740c0b6cb1aac04 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1673,7 +1673,8 @@ void MicrosoftCXXABI::EmitDestructorCall(CodeGenFunction 
&CGF,
 void MicrosoftCXXABI::emitVTableTypeMetadata(const VPtrInfo &Info,
  const CXXRecordDecl *RD,
  llvm::GlobalVariable *VTable) {
-  if (!CGM.getCodeGenOpts().LTOUnit)
+  if (!CGM.getCodeGenOpts().LTOUnit &&
+  !CGM.getCodeGenOpts().hasProfileIRInstr())
 return;
 
   // TODO: Should VirtualFunctionElimination also be supported here?
diff --git a/clang/test/CodeGenCXX/type-metadata.cpp 
b/clang/test/CodeGenCXX/type-metadata.cpp
index 3f8b54af801f8d6..637ec6e6c326ab6 100644
--- a/clang/test/CodeGenCXX/type-metadata.cpp
+++ b/clang/test/CodeGenCXX/type-metadata.cpp
@@ -1,113 +1,117 @@
 // Tests for the cfi-vcall feature:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-ABORT %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG 
--check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS 
--check-prefix=TT-MS --check-prefix=NDIAG %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV  
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG 
%s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-ABORT %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-RECOVER %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fs

[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/70841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Mingming Liu via cfe-commits


@@ -1,98 +1,116 @@
+
 // Tests for the cfi-vcall feature:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-ABORT %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG 
--check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS 
--check-prefix=TT-MS --check-prefix=NDIAG %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-TYPEMETADATA 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG 
%s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM 
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG 
--check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-TYPEMETADATA 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-RECOVER %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS 
--check-prefix=MS-TYPEMETADATA --check-prefix=TT-MS --check-prefix=NDIAG %s
 
 // Tests for the whole-program-vtables feature:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM 
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN %s
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS 
--check-prefix=TT-ITANIUM-DEFAULT %s
 // RUN: %clang_cc1 -O2 -flto -flto-unit -triple x86_64-unknown-linux 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=ITANIUM-OPT --check-prefix=ITANIUM-OPT-LAYOUT %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=TT-MS %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=MS-TYPEMETADATA 
--check-prefix=TT-MS %s
 
 // Tests for cfi + whole-program-vtables:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI 
--check-prefix=CFI-VT --check-prefix=ITANIUM --check-prefix=TC-ITANIUM 
--check-prefix=ITANIUM-MD %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT 
--check-prefix=MS --check-prefix=T

[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Mingming Liu via cfe-commits


@@ -1312,7 +1312,7 @@ llvm::GlobalObject::VCallVisibility 
CodeGenModule::GetVCallVisibilityLevel(
 void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD,
llvm::GlobalVariable *VTable,
const VTableLayout &VTLayout) {
-  if (!getCodeGenOpts().LTOUnit)
+  if (!getCodeGenOpts().LTOUnit && !getCodeGenOpts().hasProfileIRInstr())

minglotus-6 wrote:

done.


https://github.com/llvm/llvm-project/pull/70841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

2023-11-03 Thread Bill Wendling via cfe-commits


@@ -966,9 +962,65 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction 
&CGF,
   return nullptr;
 }
 
-FieldDecl *CodeGenFunction::FindCountedByField(
-const Expr *Base,
-LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel) {
+const Expr *
+CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
+ const ValueDecl *CountedByVD) {
+  // Find the outer struct expr (i.e. p in p->a.b.c.d).
+  Expr *CountedByExpr = const_cast(Base)->IgnoreParenImpCasts();
+
+  // Work our way up the expression until we reach the DeclRefExpr.
+  while (!isa(CountedByExpr))
+if (const auto *ME = dyn_cast(CountedByExpr))
+  CountedByExpr = ME->getBase()->IgnoreParenImpCasts();
+
+  // Add back an implicit cast to create the required pr-value.
+  CountedByExpr = ImplicitCastExpr::Create(
+  getContext(), CountedByExpr->getType(), CK_LValueToRValue, CountedByExpr,
+  nullptr, VK_PRValue, FPOptionsOverride());
+
+  if (const auto *IFD = dyn_cast(CountedByVD)) {
+// The counted_by field is inside an anonymous struct / union. The
+// IndirectFieldDecl has the correct order of FieldDecls to build this
+// easily. (Yay!)
+for (NamedDecl *ND : IFD->chain()) {
+  auto *VD = cast(ND);
+  CountedByExpr =
+  MemberExpr::CreateImplicit(getContext(), CountedByExpr,
+ CountedByExpr->getType()->isPointerType(),
+ VD, VD->getType(), VK_LValue, 
OK_Ordinary);
+}
+  } else {
+CountedByExpr = MemberExpr::CreateImplicit(
+getContext(), const_cast(CountedByExpr),
+CountedByExpr->getType()->isPointerType(),
+const_cast(CountedByVD), CountedByVD->getType(), 
VK_LValue,
+OK_Ordinary);
+  }
+
+  return CountedByExpr;
+}
+
+const ValueDecl *
+CodeGenFunction::FindFlexibleArrayMemberField(ASTContext &Ctx,
+  const RecordDecl *RD) {
+  LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
+  getLangOpts().getStrictFlexArraysLevel();
+
+  for (const Decl *D : RD->decls()) {
+if (const auto *VD = dyn_cast(D);
+VD && Decl::isFlexibleArrayMemberLike(Ctx, VD, VD->getType(),
+  StrictFlexArraysLevel, true))

bwendling wrote:

Done.

https://github.com/llvm/llvm-project/pull/70606
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

2023-11-03 Thread Bill Wendling via cfe-commits

bwendling wrote:

> ```
> #include 
> #include 
> struct flex {
> int c;
> int fam[] __attribute__((counted_by(c)));
> };
> 
> int main() {
> struct flex *p = (struct flex *)malloc(sizeof(struct flex) + sizeof(int) 
> * 10);
> p->c = 100;
> printf("%lu\n", __builtin_dynamic_object_size(&p->fam[0], 0)); // 40 : 
> size from malloc, but it only contains the array part. Shouldn't it be 44 to 
> include the entire object size?
> printf("%lu\n", __builtin_dynamic_object_size(&p->fam[0], 1)); // 40 : 
> size from malloc;
> printf("%lu\n", __builtin_dynamic_object_size(p, 0));  // 404 : 
> size from counted_by
> }
> ```
> 
> @bwendling It could be tracked as a separate issue, but there seems to be 
> some inconsistencies in where bdos is derived from. For `p` it seems the 
> counted_by wins over malloc. But for `&->fam[0]` malloc seems to win.
> 
> https://godbolt.org/z/G7WfY4faE

I think the first two `printf` s in your code seem correct with 40, because 
they're both looking at only the FAM, not the entire struct. The fact that 
they're not reporting 400 here is because godbolt doesn't have this PR. With 
this PR I get:

```
$ clang -O2 ~/llvm/bdos.c
$ ./a.out
400
400
404
```

Which seems correct to me, given the incorrect value in `p->c`. The 
documentation does make it very clear that the user is responsible for 
supplying the correct value to the FAM counter. The GCC people are making that 
language even stricter, so I'll do that as well. (They also have a dependency 
issue between the FAM and the counter field that they're solving with a 
compiler-only pseudo-function call. I'll create an intrinsic on our side to do 
the same once they land on a solution.)

https://github.com/llvm/llvm-project/pull/70606
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] [compiler-rt] [llvm] [flang] [clang] [libcxx] [mlir] [MLIR] SPIRV Target Attribute (PR #69949)

2023-11-03 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

@antiagainst I'm waiting for your approval.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Mingming Liu via cfe-commits


@@ -101,14 +119,16 @@
 // ITANIUM-OPT-SAME: !type [[EF16:![0-9]+]]
 // ITANIUM-OPT: @llvm.compiler.used = appending global [1 x ptr] [ptr 
@_ZTVN5test31EE]
 
-// MS: comdat($"??_7A@@6B@"), !type [[A8:![0-9]+]]
-// MS: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]]
-// MS: comdat($"??_7B@@6BA@@@"), !type [[A8]]
-// MS: comdat($"??_7C@@6B@"), !type [[A8]]
-// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], !type 
[[D8:![0-9]+]]
-// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]]
-// MS: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type 
[[FA8:![0-9]+]]
+// MS-TYPEMETADATA: comdat($"??_7A@@6B@"), !type [[A8:![0-9]+]]
+// MS-TYPEMETADATA: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]]
+// MS-TYPEMETADATA: comdat($"??_7B@@6BA@@@"), !type [[A8]]
+// MS-TYPEMETADATA: comdat($"??_7C@@6B@"), !type [[A8]]
+// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], 
!type [[D8:![0-9]+]]
+// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]]
+// MS-TYPEMETADATA: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type 
[[FA8:![0-9]+]]
 
+// Test !type doesn't exist in the generated IR.
+// NOTYPEMD-NOT: !type

minglotus-6 wrote:

done.

https://github.com/llvm/llvm-project/pull/70841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Mingming Liu via cfe-commits


@@ -1,98 +1,116 @@
+
 // Tests for the cfi-vcall feature:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-ABORT %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG 
--check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS 
--check-prefix=TT-MS --check-prefix=NDIAG %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-TYPEMETADATA 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG 
%s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM 
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG 
--check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-TYPEMETADATA 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-RECOVER %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS 
--check-prefix=MS-TYPEMETADATA --check-prefix=TT-MS --check-prefix=NDIAG %s
 
 // Tests for the whole-program-vtables feature:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM 
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN %s
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS 
--check-prefix=TT-ITANIUM-DEFAULT %s
 // RUN: %clang_cc1 -O2 -flto -flto-unit -triple x86_64-unknown-linux 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=ITANIUM-OPT --check-prefix=ITANIUM-OPT-LAYOUT %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=TT-MS %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=MS-TYPEMETADATA 
--check-prefix=TT-MS %s
 
 // Tests for cfi + whole-program-vtables:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI 
--check-prefix=CFI-VT --check-prefix=ITANIUM --check-prefix=TC-ITANIUM 
--check-prefix=ITANIUM-MD %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT 
--check-prefix=MS --check-prefix=T

[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Teresa Johnson via cfe-commits


@@ -101,14 +119,16 @@
 // ITANIUM-OPT-SAME: !type [[EF16:![0-9]+]]
 // ITANIUM-OPT: @llvm.compiler.used = appending global [1 x ptr] [ptr 
@_ZTVN5test31EE]
 
-// MS: comdat($"??_7A@@6B@"), !type [[A8:![0-9]+]]
-// MS: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]]
-// MS: comdat($"??_7B@@6BA@@@"), !type [[A8]]
-// MS: comdat($"??_7C@@6B@"), !type [[A8]]
-// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], !type 
[[D8:![0-9]+]]
-// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]]
-// MS: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type 
[[FA8:![0-9]+]]
+// MS-TYPEMETADATA: comdat($"??_7A@@6B@"), !type [[A8:![0-9]+]]
+// MS-TYPEMETADATA: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]]
+// MS-TYPEMETADATA: comdat($"??_7B@@6BA@@@"), !type [[A8]]
+// MS-TYPEMETADATA: comdat($"??_7C@@6B@"), !type [[A8]]
+// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], 
!type [[D8:![0-9]+]]
+// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]]
+// MS-TYPEMETADATA: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type 
[[FA8:![0-9]+]]
 
+// Test !type doesn't exist in the generated IR.
+// NOTYPEMD-NOT: !type

teresajohnson wrote:

Instead of this do an --implicit-check-not='!type' on the FileCheck invocations

https://github.com/llvm/llvm-project/pull/70841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Teresa Johnson via cfe-commits


@@ -1,98 +1,116 @@
+
 // Tests for the cfi-vcall feature:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-ABORT %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG 
--check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS 
--check-prefix=TT-MS --check-prefix=NDIAG %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-TYPEMETADATA 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG 
%s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM 
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG 
--check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-TYPEMETADATA 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-RECOVER %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS 
--check-prefix=MS-TYPEMETADATA --check-prefix=TT-MS --check-prefix=NDIAG %s
 
 // Tests for the whole-program-vtables feature:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM 
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN %s
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS 
--check-prefix=TT-ITANIUM-DEFAULT %s
 // RUN: %clang_cc1 -O2 -flto -flto-unit -triple x86_64-unknown-linux 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=ITANIUM-OPT --check-prefix=ITANIUM-OPT-LAYOUT %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=TT-MS %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=MS-TYPEMETADATA 
--check-prefix=TT-MS %s
 
 // Tests for cfi + whole-program-vtables:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI 
--check-prefix=CFI-VT --check-prefix=ITANIUM --check-prefix=TC-ITANIUM 
--check-prefix=ITANIUM-MD %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT 
--check-prefix=MS --check-prefix=T

[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Teresa Johnson via cfe-commits


@@ -1312,7 +1312,7 @@ llvm::GlobalObject::VCallVisibility 
CodeGenModule::GetVCallVisibilityLevel(
 void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD,
llvm::GlobalVariable *VTable,
const VTableLayout &VTLayout) {
-  if (!getCodeGenOpts().LTOUnit)
+  if (!getCodeGenOpts().LTOUnit && !getCodeGenOpts().hasProfileIRInstr())

teresajohnson wrote:

Add a comment here and in the other file noting why it is added for IR 
instrumentation.

https://github.com/llvm/llvm-project/pull/70841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

2023-11-03 Thread Teresa Johnson via cfe-commits


@@ -1,98 +1,116 @@
+
 // Tests for the cfi-vcall feature:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-ABORT %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG 
--check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS 
--check-prefix=TT-MS --check-prefix=NDIAG %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm 
-o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-TYPEMETADATA 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG 
%s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM 
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG 
--check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV 
--check-prefix=ITANIUM --check-prefix=ITANIUM-TYPEMETADATA 
--check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN 
--check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG 
--check-prefix=DIAG-RECOVER %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck 
--check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS 
--check-prefix=MS-TYPEMETADATA --check-prefix=TT-MS --check-prefix=NDIAG %s
 
 // Tests for the whole-program-vtables feature:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM 
--check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-MD 
--check-prefix=TT-ITANIUM-HIDDEN %s
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS 
--check-prefix=TT-ITANIUM-DEFAULT %s
 // RUN: %clang_cc1 -O2 -flto -flto-unit -triple x86_64-unknown-linux 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=ITANIUM-OPT --check-prefix=ITANIUM-OPT-LAYOUT %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=TT-MS %s
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck 
--check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=MS-TYPEMETADATA 
--check-prefix=TT-MS %s
 
 // Tests for cfi + whole-program-vtables:
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux 
-fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI 
--check-prefix=CFI-VT --check-prefix=ITANIUM --check-prefix=TC-ITANIUM 
--check-prefix=ITANIUM-MD %s
-// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc 
-fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables 
-emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT 
--check-prefix=MS --check-prefix=T

[clang-tools-extra] 2b76bdc - [clang-doc] Fix a warning

2023-11-03 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-11-03T11:03:15-07:00
New Revision: 2b76bdc33b555beb637c13b8bdbd8d3e935d9d56

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

LOG: [clang-doc] Fix a warning

This patch fixes:

  clang-tools-extra/clang-doc/BitcodeReader.cpp:78:3: error: default
  label in switch which covers all enumeration values
  [-Werror,-Wcovered-switch-default]

Added: 


Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 8c97186b299fc2e..bfb04e7407b3804 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -75,10 +75,9 @@ llvm::Error decodeRecord(const Record &R, TagTypeKind &Field,
   case TagTypeKind::Enum:
 Field = static_cast(R[0]);
 return llvm::Error::success();
-  default:
-return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "invalid value for TagTypeKind");
   }
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid value for TagTypeKind");
 }
 
 llvm::Error decodeRecord(const Record &R, std::optional &Field,



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


[clang] 141122e - [TableGen] Use StringRef::starts_with/ends_with instead of startswith/endswith. NFC.

2023-11-03 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2023-11-03T17:53:56Z
New Revision: 141122ece3c09a2f2e3c0280687633820bf632d5

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

LOG: [TableGen] Use StringRef::starts_with/ends_with instead of 
startswith/endswith. NFC.

startswith/endswith wrap starts_with/ends_with and will eventually go away (to 
more closely match string_view)

Added: 


Modified: 
clang/utils/TableGen/ClangAttrEmitter.cpp
clang/utils/TableGen/NeonEmitter.cpp
llvm/utils/TableGen/AsmMatcherEmitter.cpp
llvm/utils/TableGen/CallingConvEmitter.cpp
llvm/utils/TableGen/CodeGenSchedule.cpp
llvm/utils/TableGen/DXILEmitter.cpp
llvm/utils/TableGen/GlobalISel/CodeExpander.cpp
llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h
llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp
llvm/utils/TableGen/X86FoldTablesEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 4231bcbb362539d..4ec00573e8a9da8 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -161,7 +161,7 @@ static StringRef 
NormalizeNameForSpellingComparison(StringRef Name) {
 // Normalize the spelling of a GNU attribute (i.e. "x" in 
"__attribute__((x))"),
 // removing "__" if it appears at the beginning and end of the attribute's 
name.
 static StringRef NormalizeGNUAttrSpelling(StringRef AttrSpelling) {
-  if (AttrSpelling.startswith("__") && AttrSpelling.endswith("__")) {
+  if (AttrSpelling.starts_with("__") && AttrSpelling.ends_with("__")) {
 AttrSpelling = AttrSpelling.substr(2, AttrSpelling.size() - 4);
   }
 
@@ -356,7 +356,7 @@ namespace {
 }
 
 void writeDump(raw_ostream &OS) const override {
-  if (StringRef(type).endswith("Decl *")) {
+  if (StringRef(type).ends_with("Decl *")) {
 OS << "OS << \" \";\n";
 OS << "dumpBareDeclRef(SA->get" << getUpperName() << "());\n";
   } else if (type == "IdentifierInfo *") {
@@ -4537,7 +4537,7 @@ void EmitClangAttrParsedAttrImpl(RecordKeeper &Records, 
raw_ostream &OS) {
 continue;
   ArgNames.push_back(Arg->getValueAsString("Name").str());
   for (const auto &Class : Arg->getSuperClasses()) {
-if (Class.first->getName().startswith("Variadic")) {
+if (Class.first->getName().starts_with("Variadic")) {
   ArgNames.back().append("...");
   break;
 }

diff  --git a/clang/utils/TableGen/NeonEmitter.cpp 
b/clang/utils/TableGen/NeonEmitter.cpp
index 3c891dbe9d7aa0f..4b112972a1ec981 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -736,17 +736,17 @@ Type Type::fromTypedefName(StringRef Name) {
 Name = Name.drop_front();
   }
 
-  if (Name.startswith("float")) {
+  if (Name.starts_with("float")) {
 T.Kind = Float;
 Name = Name.drop_front(5);
-  } else if (Name.startswith("poly")) {
+  } else if (Name.starts_with("poly")) {
 T.Kind = Poly;
 Name = Name.drop_front(4);
-  } else if (Name.startswith("bfloat")) {
+  } else if (Name.starts_with("bfloat")) {
 T.Kind = BFloat16;
 Name = Name.drop_front(6);
   } else {
-assert(Name.startswith("int"));
+assert(Name.starts_with("int"));
 Name = Name.drop_front(3);
   }
 
@@ -787,7 +787,7 @@ Type Type::fromTypedefName(StringRef Name) {
 Name = Name.drop_front(I);
   }
 
-  assert(Name.startswith("_t") && "Malformed typedef!");
+  assert(Name.starts_with("_t") && "Malformed typedef!");
   return T;
 }
 
@@ -1655,7 +1655,7 @@ std::pair 
Intrinsic::DagEmitter::emitDagShuffle(DagInit *DI){
   std::string S = "__builtin_shufflevector(" + Arg1.second + ", " + 
Arg2.second;
   for (auto &E : Elts) {
 StringRef Name = E->getName();
-assert_with_loc(Name.startswith("sv"),
+assert_with_loc(Name.starts_with("sv"),
 "Incorrect element kind in shuffle mask!");
 S += ", " + Name.drop_front(2).str();
   }

diff  --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp 
b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 6231f5530d35146..f774f0c1018b3e1 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -910,7 +910,7 @@ 
extractSingletonRegisterForAsmOperand(MatchableInfo::AsmOperand &Op,
 return;
   }
 
-  if (!Tok.startswith(RegisterPrefix))
+  if (!Tok.starts_with(RegisterPrefix))
 return;
 
   StringRef RegName = Tok.substr(RegisterPrefix.size());
@@ -1520,7 +1520,7 @@ void AsmMatcherInfo::buildInfo() {
 
   // If the tblgen -match-prefix option is specified (for tblgen hackers),
   // filter the set of instructions we consider.
-  if (!StringRef(CGI->TheDef->getName()).startswith(MatchPrefix))
+  if (!Stri

[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-03 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,28 @@
+.. title:: clang-tidy - modernize-use-std-numbers
+
+modernize-use-std-numbers
+=
+
+Finds constants and function calls to math functions that can be replaced
+with c++20's mathematical constants from the ``numbers`` header and offers 
fix-it hints.
+Does not match the use of variables with that value, and instead,
+offers a replacement at the definition of those variables.
+

PiotrZSL wrote:

List here all possible replacements.

https://github.com/llvm/llvm-project/pull/66583
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-03 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,284 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "../ClangTidyDiagnosticConsumer.h"
+#include "../utils/TransformerClangTidyCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr auto DiffThreshold = 0.001;
+
+AST_MATCHER_P(clang::FloatingLiteral, near, double, Value) {
+  return std::abs(Node.getValueAsApproximateDouble() - Value) < DiffThreshold;
+}
+
+AST_MATCHER_P(clang::QualType, hasCanonicalTypeUnqualified,
+  Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node->getCanonicalTypeUnqualified(), Finder,
+  Builder);
+}
+
+AST_MATCHER(clang::QualType, isArithmetic) { return Node->isArithmeticType(); }
+AST_MATCHER(clang::QualType, isFloating) { return Node->isFloatingType(); }
+
+auto ignoreImplicitAndArithmeticCasting(const Matcher Matcher) {
+  return expr(
+  ignoringImplicit(expr(hasType(qualType(isArithmetic())),
+ignoringParenCasts(ignoringImplicit(Matcher);
+}
+
+auto ignoreImplicitAndFloatingCasting(const Matcher Matcher) {
+  return expr(
+  ignoringImplicit(expr(hasType(qualType(isFloating())),
+ignoringParenCasts(ignoringImplicit(Matcher);
+}
+
+auto matchMathCall(const StringRef FunctionName,
+   const Matcher ArgumentMatcher) {
+  return callExpr(
+  callee(functionDecl(hasName(FunctionName),
+  hasParameter(0, hasType(isArithmetic(),
+  hasArgument(0, ArgumentMatcher));
+}
+
+auto matchSqrt(const Matcher ArgumentMatcher) {
+  return matchMathCall("sqrt", ArgumentMatcher);
+}
+
+// Used for top-level matchers (i.e. the match that replaces Val with its
+// constant).
+//
+// E.g. The matcher of `std::numbers::pi` uses this matcher to look to
+// floatLiterals that have the value of pi.
+//
+// We only care about the literal if the match is for a top-level match
+auto matchFloatLiteralNear(const double Val) {
+  return expr(ignoreImplicitAndFloatingCasting(floatLiteral(near(Val;
+}
+
+// Used for non-top-level matchers (i.e. matchers that are used as inner
+// matchers for top-level matchers).
+//
+// E.g.: The matcher of `std::numbers::log2e` uses this matcher to check if `e`
+// of `log2(e)` is declared constant and initialized with the value for eulers
+// number.
+//
+// Here, we do care about literals and about DeclRefExprs to variable
+// declarations that are constant and initialized with `Val`. This allows
+// top-level matchers to see through declared constants for their inner matches
+// like the `std::numbers::log2e` matcher.
+auto matchFloatValueNear(const double Val) {
+  const auto Float = floatLiteral(near(Val));
+
+  const auto Dref = declRefExpr(to(varDecl(
+  anyOf(isConstexpr(),
+varDecl(hasType(qualType(isConstQualified(), isArithmetic(),

PiotrZSL wrote:

Consier checking here CanonicalType to ignore all typedefs

https://github.com/llvm/llvm-project/pull/66583
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-03 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,284 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "../ClangTidyDiagnosticConsumer.h"
+#include "../utils/TransformerClangTidyCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr auto DiffThreshold = 0.001;
+
+AST_MATCHER_P(clang::FloatingLiteral, near, double, Value) {
+  return std::abs(Node.getValueAsApproximateDouble() - Value) < DiffThreshold;
+}
+
+AST_MATCHER_P(clang::QualType, hasCanonicalTypeUnqualified,
+  Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node->getCanonicalTypeUnqualified(), Finder,
+  Builder);
+}
+
+AST_MATCHER(clang::QualType, isArithmetic) { return Node->isArithmeticType(); }

PiotrZSL wrote:

Same in those both, verify that Type isn't null.

https://github.com/llvm/llvm-project/pull/66583
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-03 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,284 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "../ClangTidyDiagnosticConsumer.h"
+#include "../utils/TransformerClangTidyCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr auto DiffThreshold = 0.001;
+
+AST_MATCHER_P(clang::FloatingLiteral, near, double, Value) {
+  return std::abs(Node.getValueAsApproximateDouble() - Value) < DiffThreshold;
+}
+
+AST_MATCHER_P(clang::QualType, hasCanonicalTypeUnqualified,
+  Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node->getCanonicalTypeUnqualified(), Finder,

PiotrZSL wrote:

Verify here that Node is Null, so `return !Node.isNull() && InnerMatcher...`

https://github.com/llvm/llvm-project/pull/66583
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [flang] [compiler-rt] [openmp] [clang] [mlir] [libcxx] [lldb] [clang-tools-extra] [clang][NFC] Refactor `TagTypeKind` (PR #71160)

2023-11-03 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll closed 
https://github.com/llvm/llvm-project/pull/71160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][BoundsSafety] Add -fbounds-safety-experimental flag (PR #70480)

2023-11-03 Thread Yeoul Na via cfe-commits


@@ -0,0 +1,12 @@
+// This reports a warning to follow the default behavior of ClangAs.
+// RUN: %clang -fexperimental-bounds-safety -x assembler -c %s -o /dev/null 
2>&1 | FileCheck -check-prefix WARN %s
+
+
+// WARN: warning: argument unused during compilation: 
'-fexperimental-bounds-safety'
+
+// expected-no-diagnostics
+// RUN: %clang -fexperimental-bounds-safety -Xclang -verify -c -x c %s -o 
/dev/null
+// Unlike '-x assembler', '-x assembler-with-cpp' silently ignores unused 
options by default.
+// XXX: Should report a targeted warning in future when assembler tries to use 
preprocessor directives to conditionalize behavior when bounds safety is 
enabled.

rapidsna wrote:

@delcypher Perfect, thanks!

https://github.com/llvm/llvm-project/pull/70480
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [flang] [compiler-rt] [openmp] [clang] [mlir] [libcxx] [lldb] [clang-tools-extra] [clang][NFC] Refactor `TagTypeKind` (PR #71160)

2023-11-03 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 7ca0f4418a6d385e07d9aff42865c34d3dc2adf7 
9f0245e71c92f5f613689dabe227628b624ddc2b -- 
clang-tools-extra/clang-doc/BitcodeReader.cpp 
clang-tools-extra/clang-doc/BitcodeWriter.cpp 
clang-tools-extra/clang-doc/Generators.cpp 
clang-tools-extra/clang-doc/Representation.cpp 
clang-tools-extra/clang-doc/Representation.h 
clang-tools-extra/clang-doc/YAMLGenerator.cpp 
clang-tools-extra/clangd/refactor/InsertionPoint.cpp 
clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp 
clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp 
clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp 
clang-tools-extra/unittests/clang-doc/MergeTest.cpp 
clang-tools-extra/unittests/clang-doc/SerializeTest.cpp 
clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp 
clang/include/clang/AST/ASTContext.h clang/include/clang/AST/Decl.h 
clang/include/clang/AST/Type.h clang/lib/AST/ASTContext.cpp 
clang/lib/AST/Decl.cpp clang/lib/AST/DeclCXX.cpp clang/lib/AST/DeclTemplate.cpp 
clang/lib/AST/MicrosoftMangle.cpp clang/lib/AST/RecordLayoutBuilder.cpp 
clang/lib/AST/Type.cpp clang/lib/CodeGen/CGObjCMac.cpp 
clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
clang/lib/Frontend/Rewrite/RewriteObjC.cpp clang/lib/Index/IndexSymbol.cpp 
clang/lib/Index/USRGeneration.cpp clang/lib/Sema/HLSLExternalSemaSource.cpp 
clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaCodeComplete.cpp 
clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclAttr.cpp 
clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaDeclObjC.cpp 
clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaStmt.cpp 
clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
clang/lib/Sema/SemaType.cpp clang/lib/Sema/TreeTransform.h 
clang/lib/Serialization/ASTReaderDecl.cpp clang/lib/Serialization/ASTWriter.cpp 
clang/lib/Serialization/ASTWriterDecl.cpp 
clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp 
clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
clang/tools/libclang/CIndexCXX.cpp clang/unittests/AST/ASTImporterTest.cpp 
lldb/source/Plugins/Language/ObjC/NSDictionary.cpp 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
 lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp 
lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp 
lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp 
lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp 
lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp 
lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp 
lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp 
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp 
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
lldb/unittests/Symbol/TestTypeSystemClang.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index df0bb049ebc4..79817b3fb1ec 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -757,7 +757,8 @@ ASTDeclReader::RedeclarableResult 
ASTDeclReader::VisitTagDecl(TagDecl *TD) {
   TD->IdentifierNamespace = Record.readInt();
 
   BitsUnpacker TagDeclBits(Record.readInt());
-  
TD->setTagKind(static_cast(TagDeclBits.getNextBits(/*Width=*/3)));
+  TD->setTagKind(
+  static_cast(TagDeclBits.getNextBits(/*Width=*/3)));
   TD->setCompleteDefinition(TagDeclBits.getNextBit());
   TD->setEmbeddedInDeclarator(TagDeclBits.getNextBit());
   TD->setFreeStanding(TagDeclBits.getNextBit());

``




https://github.com/llvm/llvm-project/pull/71160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][BoundsSafety] Add -fbounds-safety-experimental flag (PR #70480)

2023-11-03 Thread Dan Liew via cfe-commits


@@ -0,0 +1,12 @@
+// This reports a warning to follow the default behavior of ClangAs.
+// RUN: %clang -fexperimental-bounds-safety -x assembler -c %s -o /dev/null 
2>&1 | FileCheck -check-prefix WARN %s
+
+
+// WARN: warning: argument unused during compilation: 
'-fexperimental-bounds-safety'
+
+// expected-no-diagnostics
+// RUN: %clang -fexperimental-bounds-safety -Xclang -verify -c -x c %s -o 
/dev/null
+// Unlike '-x assembler', '-x assembler-with-cpp' silently ignores unused 
options by default.
+// XXX: Should report a targeted warning in future when assembler tries to use 
preprocessor directives to conditionalize behavior when bounds safety is 
enabled.

delcypher wrote:

@rapidsna We should file an issue and refer to it in the code.

I've created #71206 for you and created a new `clang:bounds-safety` tag so we 
can track all the `-fbounds-safety` issues in open source.

https://github.com/llvm/llvm-project/pull/70480
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-11-03 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a updated this revision to Diff 558001.
bolshakov-a added a comment.

One more problem has been discovered and fixed: IR emitting didn't work when 
using a subobject as a template argument when the corresponding template 
parameter is used in an lvalue context. A test case has been added into 
`CodeGenCXX/template-arguments.cpp` test (but, maybe, there is a more 
appropriate place?)


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

https://reviews.llvm.org/D140996

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TemplateArgumentVisitor.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CXX/drs/dr12xx.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp
  clang/test/CodeGenCXX/mangle-template.cpp
  clang/test/CodeGenCXX/template-arguments.cpp
  clang/test/Index/USR/structural-value-tpl-arg.cpp
  clang/test/Modules/odr_hash.cpp
  clang/test/SemaCXX/warn-bool-conversion.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/www/cxx_status.html
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7218,6 +7218,9 @@
 
   case clang::TemplateArgument::Pack:
 return eTemplateArgumentKindPack;
+
+  case clang::TemplateArgument::StructuralValue:
+return eTemplateArgumentKindStructuralValue;
   }
   llvm_unreachable("Unhandled clang::TemplateArgument::ArgKind");
 }
Index: lldb/include/lldb/lldb-enumerations.h
===
--- lldb/include/lldb/lldb-enumerations.h
+++ lldb/include/lldb/lldb-enumerations.h
@@ -856,6 +856,7 @@
   eTemplateArgumentKindExpression,
   eTemplateArgumentKindPack,
   eTemplateArgumentKindNullPtr,
+  eTemplateArgumentKindStructuralValue,
 };
 
 /// Type of match to be performed when looking for a formatter for a data type.
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -626,13 +626,21 @@
 
 
 
-  Class types as non-type template parameters
+  Class types as non-type template parameters
   https://wg21.link/p0732r2";>P0732R2
-  Partial
+  Clang 12
+
+ 
+  Generalized non-type template parameters of scalar type
+  https://wg21.link/p1907r1";>P1907R1
+  
+
+  Clang 18 (Partial)
+  Reference type template arguments referring to instantiation-dependent objects and subobjects
+  (i.e. declared inside a template but neither type- nor value-dependent) aren't fully supported.
+
+  
 
-   
-https://wg21.link/p1907r1";>P1907R1
-  
 
   Destroying operator delete
   https://wg21.link/p0722r3";>P0722R3
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1463,6 +1463,9 @@
 return CXTemplateArgumentKind_NullPtr;
   case TemplateArgument::Integral:
 return CXTemplateArgumentKind_Integral;
+  case TemplateArgument::StructuralValue:
+// FIXME: Expose these values.
+return CXTemplateArgumentKind_Invalid;
   case TemplateArgument::Template:
 return CXTemplateArgumentKind_Template;
   case TemplateArgument::TemplateExpansion:
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/li

[clang] d3e7a48 - [OpenMP][NFC] Remove a no-op function

2023-11-03 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2023-11-03T10:28:36-07:00
New Revision: d3e7a48cbde060a6dbc1edcb00f375fb2f9405dc

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

LOG: [OpenMP][NFC] Remove a no-op function

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
clang/test/OpenMP/reduction_implicit_map.cpp
clang/test/OpenMP/target_teams_generic_loop_codegen.cpp
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/test/Transforms/OpenMP/add_attributes.ll
openmp/libomptarget/DeviceRTL/include/Interface.h
openmp/libomptarget/DeviceRTL/src/Reduction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 0ed665e0dfb9722..009b3f0a85a3785 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3081,14 +3081,7 @@ void CGOpenMPRuntimeGPU::emitReduction(
   ++IRHS;
 }
   };
-  llvm::Value *EndArgs[] = {ThreadId};
   RegionCodeGenTy RCG(CodeGen);
-  NVPTXActionTy Action(
-  nullptr, std::nullopt,
-  OMPBuilder.getOrCreateRuntimeFunction(
-  CGM.getModule(), OMPRTL___kmpc_nvptx_end_reduce_nowait),
-  EndArgs);
-  RCG.setAction(Action);
   RCG(CGF);
   // There is no need to emit line number for unconditional branch.
   (void)ApplyDebugLocation::CreateEmpty(CGF);

diff  --git a/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp 
b/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
index 094c5ae3522f96d..c2a958dfdd2453e 100644
--- a/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
+++ b/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
@@ -148,7 +148,6 @@ int bar(int n){
 // CHECK-64-NEXT:[[TMP8:%.*]] = load double, ptr [[E1]], align 8
 // CHECK-64-NEXT:[[ADD2:%.*]] = fadd double [[TMP7]], [[TMP8]]
 // CHECK-64-NEXT:store double [[ADD2]], ptr [[TMP0]], align 8
-// CHECK-64-NEXT:call void @__kmpc_nvptx_end_reduce_nowait(i32 [[TMP3]])
 // CHECK-64-NEXT:br label [[DOTOMP_REDUCTION_DONE]]
 // CHECK-64:   .omp.reduction.done:
 // CHECK-64-NEXT:ret void
@@ -353,7 +352,6 @@ int bar(int n){
 // CHECK-64-NEXT:[[TMP13:%.*]] = load float, ptr [[D2]], align 4
 // CHECK-64-NEXT:[[MUL8:%.*]] = fmul float [[TMP12]], [[TMP13]]
 // CHECK-64-NEXT:store float [[MUL8]], ptr [[TMP1]], align 4
-// CHECK-64-NEXT:call void @__kmpc_nvptx_end_reduce_nowait(i32 [[TMP5]])
 // CHECK-64-NEXT:br label [[DOTOMP_REDUCTION_DONE]]
 // CHECK-64:   .omp.reduction.done:
 // CHECK-64-NEXT:ret void
@@ -609,7 +607,6 @@ int bar(int n){
 // CHECK-64:   cond.end11:
 // CHECK-64-NEXT:[[COND12:%.*]] = phi i16 [ [[TMP15]], [[COND_TRUE9]] ], [ 
[[TMP16]], [[COND_FALSE10]] ]
 // CHECK-64-NEXT:store i16 [[COND12]], ptr [[TMP1]], align 2
-// CHECK-64-NEXT:call void @__kmpc_nvptx_end_reduce_nowait(i32 [[TMP6]])
 // CHECK-64-NEXT:br label [[DOTOMP_REDUCTION_DONE]]
 // CHECK-64:   .omp.reduction.done:
 // CHECK-64-NEXT:ret void
@@ -824,7 +821,6 @@ int bar(int n){
 // CHECK-32-NEXT:[[TMP8:%.*]] = load double, ptr [[E1]], align 8
 // CHECK-32-NEXT:[[ADD2:%.*]] = fadd double [[TMP7]], [[TMP8]]
 // CHECK-32-NEXT:store double [[ADD2]], ptr [[TMP0]], align 8
-// CHECK-32-NEXT:call void @__kmpc_nvptx_end_reduce_nowait(i32 [[TMP3]])
 // CHECK-32-NEXT:br label [[DOTOMP_REDUCTION_DONE]]
 // CHECK-32:   .omp.reduction.done:
 // CHECK-32-NEXT:ret void
@@ -1029,7 +1025,6 @@ int bar(int n){
 // CHECK-32-NEXT:[[TMP13:%.*]] = load float, ptr [[D2]], align 4
 // CHECK-32-NEXT:[[MUL8:%.*]] = fmul float [[TMP12]], [[TMP13]]
 // CHECK-32-NEXT:store float [[MUL8]], ptr [[TMP1]], align 4
-// CHECK-32-NEXT:call void @__kmpc_nvptx_end_reduce_nowait(i32 [[TMP5]])
 // CHECK-32-NEXT:br label [[DOTOMP_REDUCTION_DONE]]
 // CHECK-32:   .omp.reduction.done:
 // CHECK-32-NEXT:ret void
@@ -1285,7 +1280,6 @@ int bar(int n){
 // CHECK-32:   cond.end11:
 // CHECK-32-NEXT:[[COND12:%.*]] = phi i16 [ [[TMP15]], [[COND_TRUE9]] ], [ 
[[TMP16]], [[COND_FALSE10]] ]
 // CHECK-32-NEXT:store i16 [[COND12]], ptr [[TMP1]], align 2
-// CHECK-32-NEXT:call void @__kmpc_nvptx_end_reduce_nowait(i32 [[TMP6]])
 // CHECK-32-NEXT:br label [[DOTOMP_REDUCTION_DONE]]
 // CHECK-32:   .omp.reduction.done:
 // CHECK-32-NEXT:ret void
@@ -1500,7 +1494,6 @@ int bar(int n){
 // CHECK-32-EX-NEXT:[[TMP8:%.*]] = load double, ptr [[E1]], align 8
 // CHECK-32-EX-NEXT:[[ADD2:%.*]] = fadd

[llvm] [clang] Recommit changes to global checks (PR #71171)

2023-11-03 Thread Henrik G. Olsson via cfe-commits

hnrklssn wrote:

> I think if the issues with the original commit are resolved, this is good to 
> go.
> 
> Did you verify we can properly auto-generate files, e.g., in 
> llvm/test/Transforms/Attributor and clang/test/OpenMP?
> 
> 

Ah no I did not, I'll do that on Monday. 

https://github.com/llvm/llvm-project/pull/71171
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add codegen option to add passbuilder callback functions (PR #70171)

2023-11-03 Thread William Moses via cfe-commits

wsmoses wrote:

bump @efriedma-quic for reviewing this PR

https://github.com/llvm/llvm-project/pull/70171
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-11-03 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

What is the next step to get this PR merged?

https://github.com/llvm/llvm-project/pull/66651
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [clang-tidy] fix match for binaryOperator in ExprMutationAnalyzer for misc-const-correctness (PR #70559)

2023-11-03 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

I found the issue, but I have not looked for a solution.
See https://godbolt.org/z/or4EnMfWj and #71203.
When using clang with `-target` to specify `x86_64-pc-win32` and 
`x86_64-linux`, the body for the function `f` is `NULL` in the AST with the 
windows target. This only happens for `-target x86_64-windows` pre `c++20`.

Although the tested code does not directly depend on being `c++20` (it is valid 
in `c++11`), maybe I constrain the tests in this pr to be in `c++20` mode until 
the issue is fixed? What do you think?

https://github.com/llvm/llvm-project/pull/70559
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][BoundsSafety] Add -fbounds-safety-experimental flag (PR #70480)

2023-11-03 Thread Nick Desaulniers via cfe-commits

https://github.com/nickdesaulniers approved this pull request.

If you make all of the newly added tests share a similar filename prefix, it 
will be easier to test via `llvm-lit -vv clang/test/Driver/bounds-safety*`.  
`fbounds-safety.c` seems to break that convention.

https://github.com/llvm/llvm-project/pull/70480
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] Recommit changes to global checks (PR #71171)

2023-11-03 Thread Johannes Doerfert via cfe-commits

https://github.com/jdoerfert commented:

I think if the issues with the original commit are resolved, this is good to go.
Did you verify we can properly auto-generate files, e.g., in 
llvm/test/Transforms/Attributor and clang/test/OpenMP?


https://github.com/llvm/llvm-project/pull/71171
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >