[clang] [llvm] New calling convention preserve_none (PR #76868)

2024-01-17 Thread via cfe-commits


@@ -1056,6 +1056,23 @@ def CC_Intel_OCL_BI : CallingConv<[
   CCDelegateTo
 ]>;
 
+def CC_X86_64_Preserve_None : CallingConv<[
+  // We don't preserve general registers, so all of them can be used to pass
+  // arguments except
+  //   - RBPframe pointer
+  //   - R10'nest' parameter
+  //   - RBXbase pointer
+  //   - R16 - R31  these are not available everywhere
+  CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D,
+R11D, R12D, R13D, R14D, R15D, EAX]>>,
+
+  CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8, R9,
+ R11, R12, R13, R14, R15, RAX]>>,
+
+  // Otherwise it's the same as the regular C calling convention.
+  CCDelegateTo

weiguozhi wrote:

I added code to check if there are any swift attributes used with preserve_none 
at the same time, and report error if it is detected.

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


[clang] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-17 Thread Jon Roelofs via cfe-commits


@@ -153,6 +155,11 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
 }
 return TargetCodeGenInfo::isScalarizableAsmOperand(CGF, Ty);
   }
+
+  void checkFunctionCallABI(CodeGenModule , SourceLocation CallLoc,

jroelofs wrote:

where is this new function called?

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


[clang] [llvm] [RISCV] Update TargetAttr target-cpu override rule (PR #75804)

2024-01-17 Thread Michael Maitland via cfe-commits


@@ -482,5 +482,35 @@ ParsedTargetAttr 
RISCVTargetInfo::parseTargetAttr(StringRef Features) const {
   Ret.Tune = AttrString;
 }
   }
+
+  StringRef MCPU = this->getTargetOpts().CPU;
+  StringRef MTune = this->getTargetOpts().TuneCPU;
+
+  // attr-cpu override march only if arch isn't present.
+  if (FoundArch) {
+// If tune-cpu infer from CPU, then try to keep it.
+// Otherwise, just use current tune option.
+if (Ret.Tune.empty() && MTune.empty()) {
+  if (!Ret.CPU.empty())
+Ret.Tune = Ret.CPU; // Keep attr-cpu in tune-cpu
+  else if (!MCPU.empty())
+Ret.Tune = MCPU; // Keep mcpu in tune-cpu
+}
+
+// Reassign mcpu due to attr-arch= need
+// target-feature from mcpu/march.
+// Use attr-cpu will affect target-feature.
+Ret.CPU = MCPU;
+
+// arch= need keep target feature clean,
+// use the baseline cpu.
+if (llvm::find(Ret.Features, "__RISCV_TargetAttrNeedOverride") !=
+Ret.Features.end())
+  Ret.CPU =

michaelmaitland wrote:

I think this here is confusing because it is possible to specify a CPU that 
gets overridden if there is a full arch string. I think this drops the 
scheduler model which was not intended?

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


[clang] [llvm] New calling convention preserve_none (PR #76868)

2024-01-17 Thread via cfe-commits

https://github.com/weiguozhi updated 
https://github.com/llvm/llvm-project/pull/76868

>From 90e14918a0eb13e2187f8548416ac72491d966c1 Mon Sep 17 00:00:00 2001
From: Guozhi Wei 
Date: Thu, 21 Dec 2023 19:04:44 +
Subject: [PATCH 1/4] New calling convention preserve_none

The new calling convention preserve_none is the opposite side of
existing preserve_all. It tries to preserve as few general registers as
possible. So all general registers are caller saved registers. It can
also uses more general registers to pass arguments. This attribute
doesn't impact floating-point registers. Floating-point registers still
follow the c calling convention.

Currently preserve_none is supported on X86-64 only.
---
 clang/include/clang-c/Index.h |  1 +
 clang/include/clang/Basic/Attr.td |  5 ++
 clang/include/clang/Basic/AttrDocs.td | 17 
 clang/include/clang/Basic/Specifiers.h|  1 +
 clang/lib/AST/ItaniumMangle.cpp   |  1 +
 clang/lib/AST/Type.cpp|  2 +
 clang/lib/AST/TypePrinter.cpp |  6 ++
 clang/lib/Basic/Targets/X86.h |  2 +
 clang/lib/CodeGen/CGCall.cpp  |  4 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  2 +
 clang/lib/Sema/SemaDeclAttr.cpp   |  7 ++
 clang/lib/Sema/SemaType.cpp   |  5 +-
 clang/test/CodeGen/debug-info-cc.c|  7 ++
 clang/test/CodeGen/preserve-call-conv.c   |  8 +-
 clang/test/Sema/no_callconv.cpp   |  2 +
 clang/test/Sema/preserve-none-call-conv.c | 19 
 clang/tools/libclang/CXType.cpp   |  1 +
 llvm/docs/LangRef.rst |  6 ++
 llvm/include/llvm/AsmParser/LLToken.h |  1 +
 llvm/include/llvm/BinaryFormat/Dwarf.def  |  1 +
 llvm/include/llvm/IR/CallingConv.h|  3 +
 llvm/lib/AsmParser/LLLexer.cpp|  1 +
 llvm/lib/AsmParser/LLParser.cpp   |  2 +
 llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp |  3 +
 llvm/lib/IR/AsmWriter.cpp |  1 +
 llvm/lib/Target/X86/X86CallingConv.td | 18 
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp   |  1 +
 llvm/lib/Target/X86/X86RegisterInfo.cpp   |  4 +
 llvm/test/Bitcode/compatibility.ll|  2 +
 .../X86/dynamic-regmask-preserve-none.ll  | 88 +++
 llvm/test/CodeGen/X86/ipra-reg-usage.ll   |  9 +-
 llvm/test/CodeGen/X86/ipra-transform.ll   | 19 
 .../X86/preserve_nonecc64-ret-double.ll   | 85 ++
 llvm/test/CodeGen/X86/preserve_nonecc64.ll| 86 ++
 34 files changed, 417 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/preserve-none-call-conv.c
 create mode 100644 llvm/test/CodeGen/X86/dynamic-regmask-preserve-none.ll
 create mode 100644 llvm/test/CodeGen/X86/preserve_nonecc64-ret-double.ll
 create mode 100644 llvm/test/CodeGen/X86/preserve_nonecc64.ll

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 64ab3378957c70..c241a8ccc7dfac 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2981,6 +2981,7 @@ enum CXCallingConv {
   CXCallingConv_SwiftAsync = 17,
   CXCallingConv_AArch64SVEPCS = 18,
   CXCallingConv_M68kRTD = 19,
+  CXCallingConv_PreserveNone = 20,
 
   CXCallingConv_Invalid = 100,
   CXCallingConv_Unexposed = 200
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index db17211747b17d..87e2ce91a0afb7 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2868,6 +2868,11 @@ def M68kRTD: DeclOrTypeAttr {
   let Documentation = [M68kRTDDocs];
 }
 
+def PreserveNone : DeclOrTypeAttr {
+  let Spellings = [Clang<"preserve_none">];
+  let Documentation = [PreserveNoneDocs];
+}
+
 def Target : InheritableAttr {
   let Spellings = [GCC<"target">];
   let Args = [StringArgument<"featuresStr">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 98a7ecc7fd7df3..a43e00c07e141d 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5494,6 +5494,23 @@ experimental at this time.
   }];
 }
 
+def PreserveNoneDocs : Documentation {
+  let Category = DocCatCallingConvs;
+  let Content = [{
+On X86-64 target, this attribute changes the calling convention of a function.
+The ``preserve_none`` calling convention tries to preserve as few general
+registers as possible. So all general registers are caller saved registers. It
+also uses more general registers to pass arguments. This attribute doesn't
+impact floating-point registers (XMMs/YMMs). Floating-point registers still
+follow the c calling convention.
+
+- Only RSP and RBP are preserved by callee.
+
+- Register RDI, RSI, RDX, RCX, R8, R9, R11, R12, R13, R14, R15 and RAX now can
+  be used to pass function arguments.
+  }];
+}
+
 def DeprecatedDocs : Documentation {
   let Category = DocCatDecl;
   let 

[clang] [Clang][C++23] Core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2024-01-17 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 de423cfe3d5de0110b4f55ff1742988b529be6d2 
d47d92d074e6a4870849db79dec5adb197bed010 -- 
clang/test/CodeGenCXX/cxx23-fp-ext-std-names-p1467r9.cpp 
clang/test/CodeGenCXX/cxx23-vector-bfloat16.cpp 
clang/test/Sema/cxx23-fp-ext-std-names-p1467r9.cpp 
clang/include/clang/AST/ASTContext.h clang/include/clang/AST/Type.h 
clang/include/clang/Lex/LiteralSupport.h 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h 
clang/lib/AST/ASTContext.cpp clang/lib/AST/StmtPrinter.cpp 
clang/lib/AST/Type.cpp clang/lib/Frontend/InitPreprocessor.cpp 
clang/lib/Lex/LiteralSupport.cpp clang/lib/Sema/Sema.cpp 
clang/lib/Sema/SemaCast.cpp clang/lib/Sema/SemaChecking.cpp 
clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaOverload.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index beec40b4a8..beb0a49e72 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1116,7 +1116,8 @@ public:
   SatUnsignedLongFractTy;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
   CanQualType BFloat16Ty; // [C++23 6.8.3p5][basic.extended.fp]
-  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3 and [C++23 
6.8.3p5][basic.extended.fp]
+  CanQualType Float16Ty;  // C11 extension ISO/IEC TS 18661-3 and
+  // [C++23 6.8.3p5][basic.extended.fp]
   CanQualType VoidPtrTy, NullPtrTy;
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
   CanQualType BuiltinFnTy;
@@ -2838,8 +2839,8 @@ public:
 
   /// C++23 6.8.2p12 [basic.fundamental]
   /// Returns true if \p Result is FRCR_Lesser or FRCR_Unordered rank.
-  bool
-  isCXX23SmallerOrUnorderedFloatingPointRank(FloatingRankCompareResult Result) 
const;
+  bool isCXX23SmallerOrUnorderedFloatingPointRank(
+  FloatingRankCompareResult Result) const;
 
   /// C++23 6.8.2p12 [basic.fundamental]
   /// Returns true if \p Result is FRCR_Equal, FRCR_Equal_Lesser_Subrank or
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 989dee9fca..15f3e326d3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -125,7 +125,8 @@ constexpr unsigned 
CXX23FloatRankToIndex(clang::BuiltinType::Kind Kind) {
   case clang::BuiltinType::LongDouble:
 return 4;
   default:
-// Both __float128 and __ibm128 are compiler extensions, not extended 
floating points.
+// Both __float128 and __ibm128 are compiler extensions, not extended
+// floating points.
 // __float128 also predates the invention of floating-point types.
 llvm_unreachable("Not a CXX23+ floating point builtin type");
   }
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index b762b58185..26ad81b5dd 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -1358,7 +1358,9 @@ static void PrintFloatingLiteral(raw_ostream , 
FloatingLiteral *Node,
   case BuiltinType::Float:  OS << 'F'; break;
   case BuiltinType::LongDouble: OS << 'L'; break;
   case BuiltinType::Float128:   OS << 'Q'; break;
-  case BuiltinType::BFloat16:   OS << "BF16"; break;
+  case BuiltinType::BFloat16:
+OS << "BF16";
+break;
   }
 }
 

``




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


[clang] [Clang][C++23] Core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2024-01-17 Thread M. Zeeshan Siddiqui via cfe-commits

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


[clang] [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2024-01-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: M. Zeeshan Siddiqui (codemzs)


Changes

Implements Core language changes based on 
[P1467R9](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html)
 Extended floating-point types and standard names.

As per the proposal's definition the following two types are marked as extended 
floating point: `Float16` (aka `_Float16`) and `Bfloat16` (aka `decltype 
(0.0bf16)` or `__bf16`). Future work can extend this to support other 
floating-point types such as `Float32`, `Float64`, and `Float128`.

RFC: 
https://discourse.llvm.org/t/rfc-c-23-p1467r9-extended-floating-point-types-and-standard-names/70033

This pull request is a carryover from the now offline phabricator differential 
revision: https://reviews.llvm.org/D149573

---

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


18 Files Affected:

- (modified) clang/include/clang/AST/ASTContext.h (+41-7) 
- (modified) clang/include/clang/AST/Type.h (+7) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1) 
- (modified) clang/include/clang/Lex/LiteralSupport.h (+1) 
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h 
(+4-3) 
- (modified) clang/lib/AST/ASTContext.cpp (+129-8) 
- (modified) clang/lib/AST/StmtPrinter.cpp (+1) 
- (modified) clang/lib/AST/Type.cpp (+27) 
- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+5-1) 
- (modified) clang/lib/Lex/LiteralSupport.cpp (+17) 
- (modified) clang/lib/Sema/Sema.cpp (+17) 
- (modified) clang/lib/Sema/SemaCast.cpp (+13) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+11-6) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+47-13) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+79-2) 
- (added) clang/test/CodeGenCXX/cxx23-fp-ext-std-names-p1467r9.cpp (+499) 
- (added) clang/test/CodeGenCXX/cxx23-vector-bfloat16.cpp (+67) 
- (added) clang/test/Sema/cxx23-fp-ext-std-names-p1467r9.cpp (+505) 


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3e46a5da3fc043..beec40b4a8197b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -52,6 +52,16 @@ template  class SmallPtrSet;
 
 namespace clang {
 
+// Conversion ranks introduced in C++23 6.8.6p2 [conv.rank]
+enum FloatingRankCompareResult {
+  FRCR_Unordered,
+  FRCR_Lesser,
+  FRCR_Greater,
+  FRCR_Equal,
+  FRCR_Equal_Lesser_Subrank,
+  FRCR_Equal_Greater_Subrank,
+};
+
 class APValue;
 class ASTMutationListener;
 class ASTRecordLayout;
@@ -1105,8 +1115,8 @@ class ASTContext : public RefCountedBase {
   CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
   SatUnsignedLongFractTy;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
-  CanQualType BFloat16Ty;
-  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
+  CanQualType BFloat16Ty; // [C++23 6.8.3p5][basic.extended.fp]
+  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3 and [C++23 
6.8.3p5][basic.extended.fp]
   CanQualType VoidPtrTy, NullPtrTy;
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
   CanQualType BuiltinFnTy;
@@ -2803,14 +2813,38 @@ class ASTContext : public RefCountedBase {
   /// Compare the rank of the two specified floating point types,
   /// ignoring the domain of the type (i.e. 'double' == '_Complex double').
   ///
-  /// If \p LHS > \p RHS, returns 1.  If \p LHS == \p RHS, returns 0.  If
-  /// \p LHS < \p RHS, return -1.
-  int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
+  /// If \p LHS > \p RHS, returns FRCR_Greater. If \p LHS == \p RHS, returns
+  /// FRCR_Equal.  If \p LHS < \p RHS, return FRCR_Lesser. If \p LHS and \p RHS
+  /// are unordered, return FRCR_Unordered. If \p LHS and \p RHS are equal but
+  /// the subrank of \p LHS is greater than \p RHS, return
+  /// FRCR_Equal_Greater_Subrank. If \p LHS and \p RHS are equal but the 
subrank
+  /// of \p LHS is less than \p RHS, return FRCR_Equal_Lesser_Subrank. Subrank
+  /// and Unordered comparison were introduced in C++23.
+  FloatingRankCompareResult getFloatingTypeOrder(QualType LHS,
+ QualType RHS) const;
 
   /// Compare the rank of two floating point types as above, but compare equal
   /// if both types have the same floating-point semantics on the target (i.e.
-  /// long double and double on AArch64 will return 0).
-  int getFloatingTypeSemanticOrder(QualType LHS, QualType RHS) const;
+  /// long double and double on AArch64 will return FRCR_Equal).
+  FloatingRankCompareResult getFloatingTypeSemanticOrder(QualType LHS,
+ QualType RHS) const;
+
+  /// C++23 6.8.2p12 [basic.fundamental]
+  /// Checks if extended floating point rules apply to a pair of types.
+  /// It returns true if both the types are C++23 floating point types and
+  /// at least 

[clang] [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2024-01-17 Thread M. Zeeshan Siddiqui via cfe-commits

https://github.com/codemzs created 
https://github.com/llvm/llvm-project/pull/78503

Implements Core language changes based on 
[P1467R9](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html)
 Extended floating-point types and standard names.

As per the proposal's definition the following two types are marked as extended 
floating point: `Float16` (aka `_Float16`) and `Bfloat16` (aka `decltype 
(0.0bf16)` or `__bf16`). Future work can extend this to support other 
floating-point types such as `Float32`, `Float64`, and `Float128`.

RFC: 
https://discourse.llvm.org/t/rfc-c-23-p1467r9-extended-floating-point-types-and-standard-names/70033

This pull request is a carryover from the now offline phabricator differential 
revision: https://reviews.llvm.org/D149573

>From d47d92d074e6a4870849db79dec5adb197bed010 Mon Sep 17 00:00:00 2001
From: "M. Zeeshan Siddiqui" 
Date: Mon, 13 Nov 2023 17:37:36 +
Subject: [PATCH] [Clang][C++23] Implement core language changes from P1467R9
 extended floating-point types and standard names.

This commit implements Core language changes based on P1467R9 Extended
floating-point types and standard names.

As per the proposal's definition the following two types are marked as
extended floating point: Float16 (aka _Float16) and
Bfloat16 (aka decltype (0.0bf16) or __bf16). Future work can extend this
to support other floating-point types such as Float32, Float64, and
Float128.

RFC: 
https://discourse.llvm.org/t/rfc-c-23-p1467r9-extended-floating-point-types-and-standard-names/70033

Differential Revision: https://reviews.llvm.org/D149573
---
 clang/include/clang/AST/ASTContext.h  |  48 +-
 clang/include/clang/AST/Type.h|   7 +
 .../clang/Basic/DiagnosticSemaKinds.td|   1 +
 clang/include/clang/Lex/LiteralSupport.h  |   1 +
 .../Core/PathSensitive/SMTConv.h  |   7 +-
 clang/lib/AST/ASTContext.cpp  | 137 -
 clang/lib/AST/StmtPrinter.cpp |   1 +
 clang/lib/AST/Type.cpp|  27 +
 clang/lib/Frontend/InitPreprocessor.cpp   |   6 +-
 clang/lib/Lex/LiteralSupport.cpp  |  17 +
 clang/lib/Sema/Sema.cpp   |  17 +
 clang/lib/Sema/SemaCast.cpp   |  13 +
 clang/lib/Sema/SemaChecking.cpp   |  17 +-
 clang/lib/Sema/SemaExpr.cpp   |  60 ++-
 clang/lib/Sema/SemaOverload.cpp   |  81 ++-
 .../cxx23-fp-ext-std-names-p1467r9.cpp| 499 +
 .../test/CodeGenCXX/cxx23-vector-bfloat16.cpp |  67 +++
 .../Sema/cxx23-fp-ext-std-names-p1467r9.cpp   | 505 ++
 18 files changed, 1471 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/cxx23-fp-ext-std-names-p1467r9.cpp
 create mode 100644 clang/test/CodeGenCXX/cxx23-vector-bfloat16.cpp
 create mode 100644 clang/test/Sema/cxx23-fp-ext-std-names-p1467r9.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3e46a5da3fc043..beec40b4a8197b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -52,6 +52,16 @@ template  class SmallPtrSet;
 
 namespace clang {
 
+// Conversion ranks introduced in C++23 6.8.6p2 [conv.rank]
+enum FloatingRankCompareResult {
+  FRCR_Unordered,
+  FRCR_Lesser,
+  FRCR_Greater,
+  FRCR_Equal,
+  FRCR_Equal_Lesser_Subrank,
+  FRCR_Equal_Greater_Subrank,
+};
+
 class APValue;
 class ASTMutationListener;
 class ASTRecordLayout;
@@ -1105,8 +1115,8 @@ class ASTContext : public RefCountedBase {
   CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
   SatUnsignedLongFractTy;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
-  CanQualType BFloat16Ty;
-  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
+  CanQualType BFloat16Ty; // [C++23 6.8.3p5][basic.extended.fp]
+  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3 and [C++23 
6.8.3p5][basic.extended.fp]
   CanQualType VoidPtrTy, NullPtrTy;
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
   CanQualType BuiltinFnTy;
@@ -2803,14 +2813,38 @@ class ASTContext : public RefCountedBase {
   /// Compare the rank of the two specified floating point types,
   /// ignoring the domain of the type (i.e. 'double' == '_Complex double').
   ///
-  /// If \p LHS > \p RHS, returns 1.  If \p LHS == \p RHS, returns 0.  If
-  /// \p LHS < \p RHS, return -1.
-  int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
+  /// If \p LHS > \p RHS, returns FRCR_Greater. If \p LHS == \p RHS, returns
+  /// FRCR_Equal.  If \p LHS < \p RHS, return FRCR_Lesser. If \p LHS and \p RHS
+  /// are unordered, return FRCR_Unordered. If \p LHS and \p RHS are equal but
+  /// the subrank of \p LHS is greater than \p RHS, return
+  /// FRCR_Equal_Greater_Subrank. If \p LHS and \p RHS are equal but the 
subrank
+  /// of \p LHS is less than \p RHS, return FRCR_Equal_Lesser_Subrank. Subrank
+  /// and Unordered comparison were 

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-17 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

The logic in CGExprCXX.cpp is a bit more complicated than I'd like, but I don't 
see any obvious way to simplify it.

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


[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-17 Thread Eli Friedman via cfe-commits


@@ -1038,11 +1038,14 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
+  const StringLiteral *SL = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE || SL) {

efriedma-quic wrote:

That's fine.

https://github.com/llvm/llvm-project/pull/76976
___
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 misc-const-correctnes false-positive for fold expressions (PR #78320)

2024-01-17 Thread Julian Schmidt via cfe-commits


@@ -382,7 +382,8 @@ Changes in existing checks
   using pointer to member function. Additionally, the check no longer emits
   a diagnostic when a variable that is not type-dependent is an operand of a
   type-dependent binary operator. Improved performance of the check through
-  optimizations.
+  optimizations. The check no longer emits a diagnostic for
+  variables used as the initializer of C++17 fold expressions.

5chmidti wrote:

Done

https://github.com/llvm/llvm-project/pull/78320
___
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 misc-const-correctnes false-positive for fold expressions (PR #78320)

2024-01-17 Thread Julian Schmidt via cfe-commits

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

>From 1951630fd6a0edc5258f5a775c95b9e9c30106df Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Sat, 28 Oct 2023 18:39:18 +0200
Subject: [PATCH 1/4] [clang-tidy] fix misc-const-correctnes false-positive for
 fold expressions

The check no longer emits a diagnostic for variables used as the
initializer of C++17 fold expressions.
The operator used is type-dependent because of the parameter pack
and can therefore not be guaranteed to not mutate the variable.

Fixes: #70323
---
 clang-tools-extra/docs/ReleaseNotes.rst |  5 +++--
 .../misc/const-correctness-templates.cpp| 17 +
 clang/lib/Analysis/ExprMutationAnalyzer.cpp |  4 
 .../Analysis/ExprMutationAnalyzerTest.cpp   | 15 +++
 4 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index d77267588db9158..95e259873eb3c5a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -382,7 +382,8 @@ Changes in existing checks
   using pointer to member function. Additionally, the check no longer emits
   a diagnostic when a variable that is not type-dependent is an operand of a
   type-dependent binary operator. Improved performance of the check through
-  optimizations.
+  optimizations. The check no longer emits a diagnostic for
+  variables used as the initializer of C++17 fold expressions.
 
 - Improved :doc:`misc-include-cleaner
   ` check by adding option
@@ -502,7 +503,7 @@ Changes in existing checks
   ` check to take
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options. It also now provides more consistent
-  suggestions when parentheses are added to the return value or expressions. 
+  suggestions when parentheses are added to the return value or expressions.
   It also ignores false-positives for comparison containing bool bitfield.
 
 - Improved :doc:`readability-misleading-indentation
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
index 794578ceeeba8fc..a4be41d20eae131 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
@@ -30,3 +30,20 @@ namespace gh57297{
 struct Stream { };
 template  void f() { T t; Stream x; x << t; }
 } // namespace gh57297
+
+namespace gh70323{
+// A fold expression may contain the checked variable as it's initializer.
+// We don't know if the operator modifies that variable because the
+// operator is type dependent due to the parameter pack.
+
+struct Stream {};
+template 
+Stream& operator<<(Stream&, T);
+template 
+void concatenate(Args... args)
+{
+Stream stream;
+(stream << ... << args);
+(args << ... << stream);
+}
+} // namespace gh70323
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 9af818be0415f39..bb042760d297a78 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -343,6 +343,10 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const 
Expr *Exp) {
   // in different instantiations of the template.
   binaryOperator(isTypeDependent(),
  
hasEitherOperand(ignoringImpCasts(canResolveToExpr(Exp,
+  // A fold expression may contain `Exp` as it's initializer.
+  // We don't know if the operator modifies `Exp` because the
+  // operator is type dependent due to the parameter pack.
+  cxxFoldExpr(hasFoldInit(ignoringImpCasts(canResolveToExpr(Exp,
   // Within class templates and member functions the member expression 
might
   // not be resolved. In that case, the `callExpr` is considered to be a
   // modification.
diff --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp 
b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
index a94f857720b0357..50d0399ed4b0159 100644
--- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -359,6 +359,21 @@ TEST(ExprMutationAnalyzerTest, 
DependentOperatorWithNonDependentOperand) {
   EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x << t"));
 }
 
+TEST(ExprMutationAnalyzerTest, FoldExpression) {
+  // gh70323
+  // A fold expression may contain `Exp` as it's initializer.
+  // We don't know if the operator modifies `Exp` because the
+  // operator is type dependent due to the parameter pack.
+  const auto AST = buildASTFromCode(
+  "struct Stream {};"
+  "template  Stream& operator<<(Stream&, T); "
+  "template  void concatenate(Args... args) "
+  "{ Stream x; 

[clang] [llvm] [CMake] Detect properly new linker introduced in Xcode 15 (PR #77806)

2024-01-17 Thread Eric Miotto via cfe-commits

https://github.com/edymtt updated 
https://github.com/llvm/llvm-project/pull/77806

>From c97e07011f2f780e29aa7cd5db9bfec8c3b4a6a8 Mon Sep 17 00:00:00 2001
From: Eric Miotto <1094986+edy...@users.noreply.github.com>
Date: Thu, 11 Jan 2024 08:27:21 -0800
Subject: [PATCH] [CMake] Detect properly new linker introduced in Xcode 15

[This 
linker](https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking)
is functionally equivalent to the classic one (`ld64`) for build system
purposes -- in particular to enable the use of order files to link
`clang`.
For this reason, in addition to fixing the detection rename
`LLVM_LINKER_IS_LD64` to `LLVM_LINKER_IS_APPLE` to make the result of
such detection more clear -- this should not cause any issue to
downstream users, from a quick serch in
[Sourcegraph](https://sourcegraph.com/search?q=context:global+LLVM_LINKER_IS_LD64+lang:cmake+fork:no+-file:AddLLVM.cmake+-file:clang/tools/driver/CMakeLists.txt=standard=1=repo)
only Swift uses the value of this variable (which I will take care of
updating in due time).

rdar://120740222
---
 clang/tools/driver/CMakeLists.txt | 4 ++--
 llvm/cmake/modules/AddLLVM.cmake  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/tools/driver/CMakeLists.txt 
b/clang/tools/driver/CMakeLists.txt
index 2182486f93a5553..d70b92b0984e52f 100644
--- a/clang/tools/driver/CMakeLists.txt
+++ b/clang/tools/driver/CMakeLists.txt
@@ -103,10 +103,10 @@ if (APPLE)
 endif()
 
 if(CLANG_ORDER_FILE AND
-(LLVM_LINKER_IS_LD64 OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD))
+(LLVM_LINKER_IS_APPLE OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD))
   include(LLVMCheckLinkerFlag)
 
-  if (LLVM_LINKER_IS_LD64 OR (LLVM_LINKER_IS_LLD AND APPLE))
+  if (LLVM_LINKER_IS_APPLE OR (LLVM_LINKER_IS_LLD AND APPLE))
 set(LINKER_ORDER_FILE_OPTION "-Wl,-order_file,${CLANG_ORDER_FILE}")
   elseif (LLVM_LINKER_IS_GOLD)
 set(LINKER_ORDER_FILE_OPTION 
"-Wl,--section-ordering-file,${CLANG_ORDER_FILE}")
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 14c0837c35964d2..5e9896185528246 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -211,10 +211,10 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
 )
 
   if(APPLE)
-if("${stderr}" MATCHES "PROJECT:ld64")
+if("${stderr}" MATCHES "PROGRAM:ld")
   set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
-  set(LLVM_LINKER_IS_LD64 YES CACHE INTERNAL "")
-  message(STATUS "Linker detection: ld64")
+  set(LLVM_LINKER_IS_APPLE YES CACHE INTERNAL "")
+  message(STATUS "Linker detection: Apple")
 elseif("${stderr}" MATCHES "^LLD" OR
"${stdout}" MATCHES "^LLD")
   set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")

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


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2024-01-17 Thread Zixu Wang via cfe-commits

zixu-w wrote:

> > We have provided a fix for zlib 
> > ([madler/zlib#895](https://github.com/madler/zlib/pull/895)) which was 
> > accepted by @madler.
> 
> But nowhere released, not even in the repository :(

Yeah... Not entirely familiar with the zlib development and contribution 
process, but looks like most of the PRs were just closed and changes committed 
separately some time after (presumably with a release?).

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


[lldb] [libunwind] [clang-tools-extra] [lld] [clang] [libcxx] [libc] [compiler-rt] [libcxxabi] [flang] [llvm] Fix a bug in Smith's algorithm used in complex div/mul. (PR #78330)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zahira Ammarguellat (zahiraam)


Changes

This patch fixes a bug in Smith's algorithm (thanks to @andykaylor who 
detected it) and makes sure that last option in command line rules.

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


4 Files Affected:

- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+6-2) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10-9) 
- (modified) clang/test/CodeGen/cx-complex-range.c (+16) 
- (modified) clang/test/Driver/range.c (+7) 


``diff
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index e532794b71bdb4a..6fbd8f19eeb50a4 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -936,7 +936,7 @@ ComplexPairTy 
ComplexExprEmitter::EmitRangeReductionDiv(llvm::Value *LHSr,
   llvm::Value *RC = Builder.CreateFMul(CdD, RHSr);  // rc
   llvm::Value *DpRC = Builder.CreateFAdd(RHSi, RC); // tmp=d+rc
 
-  llvm::Value *T7 = Builder.CreateFMul(LHSr, RC);// ar
+  llvm::Value *T7 = Builder.CreateFMul(LHSr, CdD);   // ar
   llvm::Value *T8 = Builder.CreateFAdd(T7, LHSi);// ar+b
   llvm::Value *DSTFr = Builder.CreateFDiv(T8, DpRC); // (ar+b)/tmp
 
@@ -978,7 +978,11 @@ ComplexPairTy ComplexExprEmitter::EmitBinDiv(const 
BinOpInfo ) {
   return EmitRangeReductionDiv(LHSr, LHSi, RHSr, RHSi);
 else if (Op.FPFeatures.getComplexRange() == LangOptions::CX_Limited)
   return EmitAlgebraicDiv(LHSr, LHSi, RHSr, RHSi);
-else if (!CGF.getLangOpts().FastMath) {
+else if (!CGF.getLangOpts().FastMath ||
+ // '-ffast-math' is used in the command line but followed by an
+ // '-fno-cx-limited-range'.
+ (CGF.getLangOpts().FastMath &&
+  Op.FPFeatures.getComplexRange() == LangOptions::CX_Full)) {
   LHSi = OrigLHSi;
   // If we have a complex operand on the RHS and FastMath is not allowed, 
we
   // delegate to a libcall to handle all of the complexities and minimize
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 997ec2d491d02c8..7e25347677e23e8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2765,6 +2765,7 @@ static void RenderFloatingPointOptions(const ToolChain 
, const Driver ,
   StringRef Float16ExcessPrecision = "";
   StringRef BFloat16ExcessPrecision = "";
   LangOptions::ComplexRangeKind Range = LangOptions::ComplexRangeKind::CX_Full;
+  std::string ComplexRangeStr = "";
 
   if (const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
 CmdArgs.push_back("-mlimit-float-precision");
@@ -2780,24 +2781,24 @@ static void RenderFloatingPointOptions(const ToolChain 
, const Driver ,
 case options::OPT_fcx_limited_range: {
   EmitComplexRangeDiag(D, Range, 
LangOptions::ComplexRangeKind::CX_Limited);
   Range = LangOptions::ComplexRangeKind::CX_Limited;
-  std::string ComplexRangeStr = RenderComplexRangeOption("limited");
-  if (!ComplexRangeStr.empty())
-CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
+  ComplexRangeStr = RenderComplexRangeOption("limited");
   break;
 }
 case options::OPT_fno_cx_limited_range:
+  EmitComplexRangeDiag(D, Range, LangOptions::ComplexRangeKind::CX_Full);
   Range = LangOptions::ComplexRangeKind::CX_Full;
+  ComplexRangeStr = RenderComplexRangeOption("full");
   break;
 case options::OPT_fcx_fortran_rules: {
   EmitComplexRangeDiag(D, Range, 
LangOptions::ComplexRangeKind::CX_Fortran);
   Range = LangOptions::ComplexRangeKind::CX_Fortran;
-  std::string ComplexRangeStr = RenderComplexRangeOption("fortran");
-  if (!ComplexRangeStr.empty())
-CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
+  ComplexRangeStr = RenderComplexRangeOption("fortran");
   break;
 }
 case options::OPT_fno_cx_fortran_rules:
+  EmitComplexRangeDiag(D, Range, LangOptions::ComplexRangeKind::CX_Full);
   Range = LangOptions::ComplexRangeKind::CX_Full;
+  ComplexRangeStr = RenderComplexRangeOption("full");
   break;
 case options::OPT_ffp_model_EQ: {
   // If -ffp-model= is seen, reset to fno-fast-math
@@ -3068,9 +3069,7 @@ static void RenderFloatingPointOptions(const ToolChain 
, const Driver ,
   SeenUnsafeMathModeOption = true;
   // ffast-math enables fortran rules for complex multiplication and
   // division.
-  std::string ComplexRangeStr = RenderComplexRangeOption("limited");
-  if (!ComplexRangeStr.empty())
-CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
+  ComplexRangeStr = RenderComplexRangeOption("limited");
   break;
 }
 case options::OPT_fno_fast_math:
@@ -3227,6 +3226,8 @@ static void RenderFloatingPointOptions(const ToolChain 
, const Driver ,
options::OPT_fstrict_float_cast_overflow, false))
 

[libcxx] [libcxxabi] [lldb] [flang] [clang-tools-extra] [clang] [llvm] [compiler-rt] [libunwind] [libc] [lld] Fix a bug in Smith's algorithm used in complex div/mul. (PR #78330)

2024-01-17 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [clang] Upstream XROS support in Clang (PR #78392)

2024-01-17 Thread Jonas Devlieghere via cfe-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/78392

>From 52ff81ffbce596fd89b296e7f4199be13f9402ff Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 16 Jan 2024 20:36:47 -0800
Subject: [PATCH 1/2] [clang] Upstream XROS support in Clang

Upstream XROS support in the clang frontend and driver.
---
 clang/lib/Basic/Targets/OSTargets.h   |  6 +-
 clang/lib/CodeGen/CGObjC.cpp  |  5 ++
 clang/lib/Driver/Driver.cpp   |  1 +
 clang/lib/Driver/ToolChains/Arch/AArch64.cpp  |  5 ++
 clang/lib/Driver/ToolChains/Arch/ARM.cpp  |  5 +-
 clang/lib/Driver/ToolChains/Darwin.cpp| 56 ++-
 clang/lib/Driver/ToolChains/Darwin.h  | 14 -
 .../Checkers/CheckSecuritySyntaxOnly.cpp  |  2 +
 clang/test/Driver/xros-driver.c   | 41 ++
 clang/test/Frontend/xros-version.c|  3 +
 10 files changed, 131 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Driver/xros-driver.c
 create mode 100644 clang/test/Frontend/xros-version.c

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 342af4bbc42b7b..4366c1149e4053 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -74,7 +74,8 @@ class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo : public 
OSTargetInfo {
 this->TLSSupported = !Triple.isOSVersionLT(3);
 } else if (Triple.isDriverKit()) {
   // No TLS on DriverKit.
-}
+} else if (Triple.isXROS())
+  this->TLSSupported = true;
 
 this->MCountName = "\01mcount";
   }
@@ -109,6 +110,9 @@ class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo : public 
OSTargetInfo {
 case llvm::Triple::WatchOS: // Earliest supporting version is 5.0.0.
   MinVersion = llvm::VersionTuple(5U);
   break;
+case llvm::Triple::XROS:
+  MinVersion = llvm::VersionTuple(0);
+  break;
 default:
   // Conservatively return 8 bytes if OS is unknown.
   return 64;
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index acc85165a470be..03fc0ec7ff54e1 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -3941,6 +3941,8 @@ static unsigned getBaseMachOPlatformID(const llvm::Triple 
) {
 return llvm::MachO::PLATFORM_TVOS;
   case llvm::Triple::WatchOS:
 return llvm::MachO::PLATFORM_WATCHOS;
+  case llvm::Triple::XROS:
+return llvm::MachO::PLATFORM_XROS;
   case llvm::Triple::DriverKit:
 return llvm::MachO::PLATFORM_DRIVERKIT;
   default:
@@ -4024,6 +4026,9 @@ static bool isFoundationNeededForDarwinAvailabilityCheck(
   case llvm::Triple::MacOSX:
 FoundationDroppedInVersion = VersionTuple(/*Major=*/10, /*Minor=*/15);
 break;
+  case llvm::Triple::XROS:
+// XROS doesn't need Foundation.
+return false;
   case llvm::Triple::DriverKit:
 // DriverKit doesn't need Foundation.
 return false;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df1..35d563b9a87fac 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6213,6 +6213,7 @@ const ToolChain ::getToolChain(const ArgList ,
 case llvm::Triple::IOS:
 case llvm::Triple::TvOS:
 case llvm::Triple::WatchOS:
+case llvm::Triple::XROS:
 case llvm::Triple::DriverKit:
   TC = std::make_unique(*this, Target, Args);
   break;
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 85f053dc8b6eab..0cf96bb5c9cb02 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -53,6 +53,11 @@ std::string aarch64::getAArch64TargetCPU(const ArgList ,
 return "apple-m1";
   }
 
+  if (Triple.isXROS()) {
+// The xrOS simulator runs on M1 as well, it should have been covered 
above.
+assert(!Triple.isSimulatorEnvironment() && "xrossim should be mac-like");
+return "apple-a12";
+  }
   // arm64e requires v8.3a and only runs on apple-a12 and later CPUs.
   if (Triple.isArm64e())
 return "apple-a12";
diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 25470db2b6cebd..e6ee2f88a84edf 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -367,6 +367,7 @@ arm::FloatABI arm::getDefaultFloatABI(const llvm::Triple 
) {
   case llvm::Triple::IOS:
   case llvm::Triple::TvOS:
   case llvm::Triple::DriverKit:
+  case llvm::Triple::XROS:
 // Darwin defaults to "softfp" for v6 and v7.
 if (Triple.isWatchABI())
   return FloatABI::Hard;
@@ -836,8 +837,8 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
,
 if (A->getOption().matches(options::OPT_mlong_calls))
   Features.push_back("+long-calls");
   } else if (KernelOrKext && (!Triple.isiOS() || Triple.isOSVersionLT(6)) &&
- !Triple.isWatchOS()) {
-  

[llvm] [clang] [CMake][PGO] Build Sema.cpp to generate profdata for PGO builds (PR #77347)

2024-01-17 Thread Tom Stellard via cfe-commits


@@ -26,9 +30,23 @@ if(LLVM_BUILD_INSTRUMENTED)
 message(STATUS "To enable merging PGO data LLVM_PROFDATA has to point to 
llvm-profdata")
   else()
 add_custom_target(generate-profdata
-  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR}
+  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/
   COMMENT "Merging profdata"
   DEPENDS generate-profraw)
+if (CLANG_PGO_TRAINING_DATA_SOURCE_DIR)
+  llvm_ExternalProject_Add(generate-profraw-external 
${CLANG_PGO_TRAINING_DATA_SOURCE_DIR}
+  USE_TOOLCHAIN EXLUDE_FROM_ALL NO_INSTALL DEPENDS 
generate-profraw)
+  add_dependencies(generate-profdata generate-profraw-external)
+else()
+  # Default to compiling a file from clang. This also builds all the
+  # dependencies needed to build this file, like TableGen.
+  set(generate_profraw_clang_sema 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/Sema.cpp.o)
+  llvm_ExternalProject_Add(generate-profraw-clang 
${CMAKE_CURRENT_SOURCE_DIR}/../../../llvm
+  USE_TOOLCHAIN EXLUDE_FROM_ALL NO_INSTALL DEPENDS generate-profraw
+  EXTRA_TARGETS generate_profraw_clang_sema

tstellar wrote:

> The idea I'd like explore is using libc++ (and perhaps also libc) test suite 
> for training. It consists of self-contained test programs which should 
> sufficiently exercise various aspects of C/C++ frontend.

I've updated the patch to use the check-cxx target to generate the profile 
data.  The gains (~20%) are less than with Sema.cpp (~34%) but still pretty 
good.  The only issue is that the profile data comes from building libcxx as 
well, so it's not just from the test suite.

It may be possible to get test data from just running the test suite, but that 
might be a lot more complicated to set up.


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


[llvm] [clang] [CMake][PGO] Build Sema.cpp to generate profdata for PGO builds (PR #77347)

2024-01-17 Thread Tom Stellard via cfe-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/77347

>From 127e2ae83f33843cfb9c5cca314afa2fc9844239 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Sat, 6 Jan 2024 07:46:01 +
Subject: [PATCH 1/7] [CMake][PGO] Use check-clang target to generate profdata
 for PGO builds

When doing a multi-stage PGO build of clang, run the check-clang and
check-llvm targets using the instrumented clang and use that profile
data for building the final stage2 clang.  This is what is recommended
by our official documentation: 
https://llvm.org/docs/HowToBuildWithPGO.html#building-clang-with-pgo

I benchmarked this change by compiling the SemaChecking.cpp file from
clang.  Using check-clang/check-llvm to generate the profile data gives a 25% 
speedup
in the PGO+LTO stage2 clang when compared to the stage1 clang (no-LTO).

Prior to this change, I was only seeing ~5% speedup when comparing the
stage2 and stage1 builds.
---
 clang/utils/perf-training/CMakeLists.txt |  6 +++---
 clang/utils/perf-training/perf-helper.py | 16 +---
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index c6d51863fb1b5c..95ff8115aa538b 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -15,7 +15,7 @@ if(LLVM_BUILD_INSTRUMENTED)
 )
 
   add_custom_target(clear-profraw
-COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} profraw
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/ profraw
 COMMENT "Clearing old profraw data")
 
   if(NOT LLVM_PROFDATA)
@@ -26,9 +26,9 @@ if(LLVM_BUILD_INSTRUMENTED)
 message(STATUS "To enable merging PGO data LLVM_PROFDATA has to point to 
llvm-profdata")
   else()
 add_custom_target(generate-profdata
-  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR}
+  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/
   COMMENT "Merging profdata"
-  DEPENDS generate-profraw)
+  DEPENDS generate-profraw check-clang check-llvm)
   endif()
 endif()
 
diff --git a/clang/utils/perf-training/perf-helper.py 
b/clang/utils/perf-training/perf-helper.py
index 99d6ab6ef0..bd8f74c9c2e129 100644
--- a/clang/utils/perf-training/perf-helper.py
+++ b/clang/utils/perf-training/perf-helper.py
@@ -30,26 +30,28 @@ def findFilesWithExtension(path, extension):
 
 
 def clean(args):
-if len(args) != 2:
+if len(args) < 2:
 print(
-"Usage: %s clean  \n" % __file__
+"Usage: %s clean  \n" % __file__
 + "\tRemoves all files with extension from ."
 )
 return 1
-for filename in findFilesWithExtension(args[0], args[1]):
-os.remove(filename)
+for path in args[1:-1]:
+   for filename in findFilesWithExtension(path, args[-1]):
+   os.remove(filename)
 return 0
 
 
 def merge(args):
-if len(args) != 3:
+if len(args) < 3:
 print(
-"Usage: %s merge   \n" % __file__
+"Usage: %s merge   \n" % __file__
 + "\tMerges all profraw files from path into output."
 )
 return 1
 cmd = [args[0], "merge", "-o", args[1]]
-cmd.extend(findFilesWithExtension(args[2], "profraw"))
+for i in range(2, len(args)):
+  cmd.extend(findFilesWithExtension(args[i], "profraw"))
 subprocess.check_call(cmd)
 return 0
 

>From 4f7734584af3aa9a18bde17349ceccbef3658c53 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Mon, 8 Jan 2024 18:07:31 +
Subject: [PATCH 2/7] Fix python formatting

---
 clang/utils/perf-training/perf-helper.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/utils/perf-training/perf-helper.py 
b/clang/utils/perf-training/perf-helper.py
index bd8f74c9c2e129..844aa274f049aa 100644
--- a/clang/utils/perf-training/perf-helper.py
+++ b/clang/utils/perf-training/perf-helper.py
@@ -37,8 +37,8 @@ def clean(args):
 )
 return 1
 for path in args[1:-1]:
-   for filename in findFilesWithExtension(path, args[-1]):
-   os.remove(filename)
+for filename in findFilesWithExtension(path, args[-1]):
+os.remove(filename)
 return 0
 
 
@@ -51,7 +51,7 @@ def merge(args):
 return 1
 cmd = [args[0], "merge", "-o", args[1]]
 for i in range(2, len(args)):
-  cmd.extend(findFilesWithExtension(args[i], "profraw"))
+cmd.extend(findFilesWithExtension(args[i], "profraw"))
 subprocess.check_call(cmd)
 return 0
 

>From 

[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-01-17 Thread Richard Smith via cfe-commits


@@ -1357,6 +1363,19 @@ class Sema final {
 // VLAs).
 bool InConditionallyConstantEvaluateContext = false;
 
+/// Whether we are currently in a context in which temporaries must be
+/// lifetime-extended (Eg. in a for-range initializer).
+bool IsInLifetimeExtendingContext = false;

zygoloid wrote:

I think we should be clear here that this is only for unusual 
lifetime-extension contexts, and not just (for example) in an initializer of a 
reference.
```suggestion
/// Whether we are currently in a context in which all temporaries must be
/// lifetime-extended, even if they're not bound to a reference (for 
example,
/// in a for-range initializer).
bool IsInLifetimeExtendingContext = false;
```

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


[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-01-17 Thread Richard Smith via cfe-commits


@@ -9959,6 +9976,18 @@ class Sema final {
 return currentEvaluationContext().isImmediateFunctionContext();
   }
 
+  bool isInLifetimeExtendingContext() const {
+assert(!ExprEvalContexts.empty() &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts.back().IsInLifetimeExtendingContext;
+  }
+
+  bool ShouldMaterializePRValueInDiscardedExpression() const {

zygoloid wrote:

Is there a reason that this is capitalized and the function above is not? 
(Genuine question, I've lost track of LLVM's preferred capitalization rule for 
functions, but this locally looks inconsistent.)

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


[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-01-17 Thread Richard Smith via cfe-commits

https://github.com/zygoloid commented:

This looks good to me.

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


[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-01-17 Thread Richard Smith via cfe-commits

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


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2024-01-17 Thread Mike Hommey via cfe-commits

glandium wrote:

> We have provided a fix for zlib 
> ([madler/zlib#895](https://github.com/madler/zlib/pull/895)) which was 
> accepted by @madler.

But nowhere released, not even in the repository :(

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


[clang] [driver] Respect the mode the driver is in for autocomplete (PR #74770)

2024-01-17 Thread Philip Reames via cfe-commits

preames wrote:

Not actively working on this.  Anyone interested is welcome to pick up the 
patch.  

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


[clang] [driver] Respect the mode the driver is in for autocomplete (PR #74770)

2024-01-17 Thread Philip Reames via cfe-commits

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


[clang] [Clang] Support MSPropertyRefExpr as placement arg to new-expression (PR #75883)

2024-01-17 Thread Erich Keane via cfe-commits

erichkeane wrote:

> I’m curious, because I legitimately don’t know, is it common for CI on 
> windows to take 9 hours?
> 
> ![image](https://private-user-images.githubusercontent.com/74590115/297492800-203deb5a-b798-4ca2-8a6f-cc45a811d0f6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDU1MjA4ODksIm5iZiI6MTcwNTUyMDU4OSwicGF0aCI6Ii83NDU5MDExNS8yOTc0OTI4MDAtMjAzZGViNWEtYjc5OC00Y2EyLThhNmYtY2M0NWE4MTFkMGY2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDAxMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwMTE3VDE5NDMwOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYzNjQxY2Q5YmIxMWYwZTdlNTRiZjJhMjg3ZGQyNGJmZmFkNmQ2MmQ3YzA2ZGI5Mjk3YWE0MTZmODk4YjVmYzMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.My4H1GBinAmCmtTNB9o-x4z5eB1WLlPwdDQf9wOcmQQ)

It is unfortunately becoming more and more common.  The bot infrastructure is 
having trouble keeping up these days during the day.

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


[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)

2024-01-17 Thread Arthur Eubanks via cfe-commits

aeubanks wrote:

sorry, I keep missing notifications, will find a repro

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


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-01-17 Thread via cfe-commits

https://github.com/Logikable updated 
https://github.com/llvm/llvm-project/pull/73176

>From 9dfcc46c600a0c4720553faf7e070862650792bc Mon Sep 17 00:00:00 2001
From: Sean Luchen 
Date: Fri, 17 Nov 2023 17:29:52 +
Subject: [PATCH] [clang][CodeGen] Emit atomic IR in place of optimized
 libcalls.

In the beginning, Clang only emitted atomic IR for operations it knew the
underlying microarch had instructions for, meaning it required significant
knowledge of the target. Later, the backend acquired the ability to lower
IR to libcalls. To avoid duplicating logic and improve logic locality,
we'd like to move as much as possible to the backend.

There are many ways to describe this change. For example, this change
reduces the variables Clang uses to decide whether to emit libcalls or
IR, down to only the atomic's size.
---
 clang/lib/CodeGen/CGAtomic.cpp| 321 +++---
 clang/test/CodeGen/LoongArch/atomics.c|  16 +-
 clang/test/CodeGen/PowerPC/quadword-atomics.c |  50 +--
 clang/test/CodeGen/RISCV/riscv-atomics.c  |  68 +---
 .../SystemZ/gnu-atomic-builtins-i128-8Al.c| 119 +++
 clang/test/CodeGen/arm-atomics-m.c|   8 +-
 clang/test/CodeGen/arm-atomics-m0.c   |  16 +-
 clang/test/CodeGen/atomic-ops-libcall.c   | 310 ++---
 clang/test/CodeGen/atomic-ops.c   |  27 +-
 clang/test/CodeGen/atomics-inlining.c |  38 +--
 clang/test/CodeGen/c11atomics.c   |  30 +-
 clang/test/CodeGenCXX/atomic-inline.cpp   |   6 +-
 .../test/CodeGenOpenCL/atomic-ops-libcall.cl  |  57 ++--
 13 files changed, 497 insertions(+), 569 deletions(-)

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 52e6ddb7d6afb0..a8d846b4f6a592 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -811,29 +811,6 @@ static void EmitAtomicOp(CodeGenFunction , AtomicExpr 
*Expr, Address Dest,
   Builder.SetInsertPoint(ContBB);
 }
 
-static void
-AddDirectArgument(CodeGenFunction , CallArgList ,
-  bool UseOptimizedLibcall, llvm::Value *Val, QualType ValTy,
-  SourceLocation Loc, CharUnits SizeInChars) {
-  if (UseOptimizedLibcall) {
-// Load value and pass it to the function directly.
-CharUnits Align = CGF.getContext().getTypeAlignInChars(ValTy);
-int64_t SizeInBits = CGF.getContext().toBits(SizeInChars);
-ValTy =
-CGF.getContext().getIntTypeForBitwidth(SizeInBits, /*Signed=*/false);
-llvm::Type *ITy = llvm::IntegerType::get(CGF.getLLVMContext(), SizeInBits);
-Address Ptr = Address(Val, ITy, Align);
-Val = CGF.EmitLoadOfScalar(Ptr, false,
-   CGF.getContext().getPointerType(ValTy),
-   Loc);
-// Coerce the value into an appropriately sized integer type.
-Args.add(RValue::get(Val), ValTy);
-  } else {
-// Non-optimized functions always take a reference.
-Args.add(RValue::get(Val), CGF.getContext().VoidPtrTy);
-  }
-}
-
 RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   QualType AtomicTy = E->getPtr()->getType()->getPointeeType();
   QualType MemTy = AtomicTy;
@@ -857,22 +834,16 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   uint64_t Size = TInfo.Width.getQuantity();
   unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
 
-  bool Oversized = getContext().toBits(TInfo.Width) > MaxInlineWidthInBits;
-  bool Misaligned = (Ptr.getAlignment() % TInfo.Width) != 0;
-  bool UseLibcall = Misaligned | Oversized;
-  bool ShouldCastToIntPtrTy = true;
-
   CharUnits MaxInlineWidth =
   getContext().toCharUnitsFromBits(MaxInlineWidthInBits);
-
   DiagnosticsEngine  = CGM.getDiags();
-
+  bool Misaligned = (Ptr.getAlignment() % TInfo.Width) != 0;
+  bool Oversized = getContext().toBits(TInfo.Width) > MaxInlineWidthInBits;
   if (Misaligned) {
 Diags.Report(E->getBeginLoc(), diag::warn_atomic_op_misaligned)
 << (int)TInfo.Width.getQuantity()
 << (int)Ptr.getAlignment().getQuantity();
   }
-
   if (Oversized) {
 Diags.Report(E->getBeginLoc(), diag::warn_atomic_op_oversized)
 << (int)TInfo.Width.getQuantity() << (int)MaxInlineWidth.getQuantity();
@@ -881,6 +852,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   llvm::Value *Order = EmitScalarExpr(E->getOrder());
   llvm::Value *Scope =
   E->getScopeModel() ? EmitScalarExpr(E->getScope()) : nullptr;
+  bool ShouldCastToIntPtrTy = true;
 
   switch (E->getOp()) {
   case AtomicExpr::AO__c11_atomic_init:
@@ -1047,122 +1019,25 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   Dest = Atomics.castToAtomicIntPointer(Dest);
   }
 
-  // Use a library call.  See: http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary .
+  bool PowerOf2Size = (Size & (Size - 1)) == 0;
+  bool UseLibcall = !PowerOf2Size || (Size > 16);
+
+  // For atomics larger than 16 bytes, emit a libcall from the frontend. This
+  // avoids the overhead 

[clang-tools-extra] [clang] [llvm] [AMDGPU] Reapply 'Sign extend simm16 in setreg intrinsic' (PR #78492)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Stanislav Mekhanoshin (rampitec)


Changes

We currently force users to use a negative contant in the intrinsic call. 
Changing it zext would break existing programs, so just sign extend an argument.

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


4 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/SIInstrInfo.td (+3-6) 
- (modified) llvm/lib/Target/AMDGPU/SIModeRegister.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/SOPInstructions.td (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.setreg.ll (+66) 


``diff
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.td 
b/llvm/lib/Target/AMDGPU/SIInstrInfo.td
index 1bd1d425573352..07572aa12e2c38 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.td
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.td
@@ -786,12 +786,9 @@ class bitextract_imm : SDNodeXFormgetTargetConstant(Bit, SDLoc(N), MVT::i1);
 }]>;
 
-def SIMM16bit : ImmLeaf (Imm);}]
->;
-
-def UIMM16bit : ImmLeaf (Imm);}]
+def SIMM16bit : TImmLeaf (Imm) || isUInt<16>(Imm);}],
+  as_i16timm
 >;
 
 def i64imm_32bit : ImmLeaf> AMDGPU::Hwreg::OFFSET_SHIFT_;
-  unsigned Mask = ((1 << Width) - 1) << Offset;
+  unsigned Mask = maskTrailingOnes(Width) << Offset;
 
   // If an InsertionPoint is set we will insert a setreg there.
   if (InsertionPoint) {
diff --git a/llvm/lib/Target/AMDGPU/SOPInstructions.td 
b/llvm/lib/Target/AMDGPU/SOPInstructions.td
index b78d900c9bbf42..d914c3d9032f5f 100644
--- a/llvm/lib/Target/AMDGPU/SOPInstructions.td
+++ b/llvm/lib/Target/AMDGPU/SOPInstructions.td
@@ -1124,7 +1124,7 @@ class S_SETREG_B32_Pseudo  pattern=[]> : 
SOPK_Pseudo <
   pattern>;
 
 def S_SETREG_B32 : S_SETREG_B32_Pseudo <
-  [(int_amdgcn_s_setreg (i32 timm:$simm16), i32:$sdst)]> {
+  [(int_amdgcn_s_setreg (i32 SIMM16bit:$simm16), i32:$sdst)]> {
   // Use custom inserter to optimize some cases to
   // S_DENORM_MODE/S_ROUND_MODE/S_SETREG_B32_mode.
   let usesCustomInserter = 1;
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.setreg.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.setreg.ll
index a2b7e9de70e82c..05186ac2aa28f6 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.setreg.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.setreg.ll
@@ -1433,6 +1433,72 @@ define amdgpu_kernel void 
@test_setreg_set_4_bits_straddles_round_and_denorm() {
   ret void
 }
 
+define amdgpu_ps void @test_63489(i32 inreg %var.mode) {
+; GFX6-LABEL: test_63489:
+; GFX6:   ; %bb.0:
+; GFX6-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x80,0xb9]
+; GFX6-NEXT:;;#ASMSTART
+; GFX6-NEXT:;;#ASMEND
+; GFX6-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX789-LABEL: test_63489:
+; GFX789:   ; %bb.0:
+; GFX789-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x00,0xb9]
+; GFX789-NEXT:;;#ASMSTART
+; GFX789-NEXT:;;#ASMEND
+; GFX789-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX10-LABEL: test_63489:
+; GFX10:   ; %bb.0:
+; GFX10-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x80,0xb9]
+; GFX10-NEXT:;;#ASMSTART
+; GFX10-NEXT:;;#ASMEND
+; GFX10-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX11-LABEL: test_63489:
+; GFX11:   ; %bb.0:
+; GFX11-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x00,0xb9]
+; GFX11-NEXT:;;#ASMSTART
+; GFX11-NEXT:;;#ASMEND
+; GFX11-NEXT:s_endpgm ; encoding: [0x00,0x00,0xb0,0xbf]
+  call void @llvm.amdgcn.s.setreg(i32 63489, i32 %var.mode)
+  call void asm sideeffect "", ""()
+  ret void
+}
+
+define amdgpu_ps void @test_minus_2047(i32 inreg %var.mode) {
+; GFX6-LABEL: test_minus_2047:
+; GFX6:   ; %bb.0:
+; GFX6-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x80,0xb9]
+; GFX6-NEXT:;;#ASMSTART
+; GFX6-NEXT:;;#ASMEND
+; GFX6-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX789-LABEL: test_minus_2047:
+; GFX789:   ; %bb.0:
+; GFX789-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x00,0xb9]
+; GFX789-NEXT:;;#ASMSTART
+; GFX789-NEXT:;;#ASMEND
+; GFX789-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX10-LABEL: test_minus_2047:
+; GFX10:   ; %bb.0:
+; GFX10-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x80,0xb9]
+; GFX10-NEXT:;;#ASMSTART
+; GFX10-NEXT:;;#ASMEND
+; GFX10-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX11-LABEL: test_minus_2047:
+; GFX11:   ; %bb.0:
+; GFX11-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x00,0xb9]
+; GFX11-NEXT:;;#ASMSTART
+; GFX11-NEXT:;;#ASMEND
+; GFX11-NEXT:s_endpgm ; encoding: [0x00,0x00,0xb0,0xbf]
+  call void @llvm.amdgcn.s.setreg(i32 -2047, i32 %var.mode)
+  call void asm sideeffect "", ""()
+  ret void
+}
+
 ; FIXME: Broken for DAG
 ; define void @test_setreg_roundingmode_var_vgpr(i32 %var.mode) {
 ;   call void 

[clang] [llvm] [clang-tools-extra] [AMDGPU] Reapply 'Sign extend simm16 in setreg intrinsic' (PR #78492)

2024-01-17 Thread Stanislav Mekhanoshin via cfe-commits

https://github.com/rampitec created 
https://github.com/llvm/llvm-project/pull/78492

We currently force users to use a negative contant in the intrinsic call. 
Changing it zext would break existing programs, so just sign extend an argument.

>From 01af6c9d8e80b810bbdec35dee38b1cf5d73cfe0 Mon Sep 17 00:00:00 2001
From: Stanislav Mekhanoshin 
Date: Fri, 12 Jan 2024 15:07:53 -0800
Subject: [PATCH 1/3] [AMDGPU] Sign extend simm16 in setreg intrinsic

We currently force users to use a negative contant in the
intrinsic call. Changing it zext would break existing programs,
so just sign extend an argument.
---
 llvm/lib/Target/AMDGPU/SOPInstructions.td | 11 ++--
 .../CodeGen/AMDGPU/llvm.amdgcn.s.setreg.ll| 66 +++
 2 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/SOPInstructions.td 
b/llvm/lib/Target/AMDGPU/SOPInstructions.td
index 46fa3d57a21cb2..5b35d4dcac2e4f 100644
--- a/llvm/lib/Target/AMDGPU/SOPInstructions.td
+++ b/llvm/lib/Target/AMDGPU/SOPInstructions.td
@@ -1117,14 +1117,12 @@ def S_GETREG_B32 : SOPK_Pseudo <
 let Defs = [MODE], Uses = [MODE] in {
 
 // FIXME: Need to truncate immediate to 16-bits.
-class S_SETREG_B32_Pseudo  pattern=[]> : SOPK_Pseudo <
+class S_SETREG_B32_Pseudo : SOPK_Pseudo <
   "s_setreg_b32",
   (outs), (ins SReg_32:$sdst, hwreg:$simm16),
-  "$simm16, $sdst",
-  pattern>;
+  "$simm16, $sdst">;
 
-def S_SETREG_B32 : S_SETREG_B32_Pseudo <
-  [(int_amdgcn_s_setreg (i32 timm:$simm16), i32:$sdst)]> {
+def S_SETREG_B32 : S_SETREG_B32_Pseudo {
   // Use custom inserter to optimize some cases to
   // S_DENORM_MODE/S_ROUND_MODE/S_SETREG_B32_mode.
   let usesCustomInserter = 1;
@@ -1160,6 +1158,9 @@ def S_SETREG_IMM32_B32_mode : S_SETREG_IMM32_B32_Pseudo {
 
 } // End Defs = [MODE], Uses = [MODE]
 
+def : GCNPat<(int_amdgcn_s_setreg (i32 timm:$simm16), i32:$sdst),
+ (S_SETREG_B32 $sdst, (as_i16timm $simm16))>;
+
 class SOPK_WAITCNT pat=[]> :
 SOPK_Pseudo<
 opName,
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.setreg.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.setreg.ll
index d2c14f2401fc35..99d80b5dd14b33 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.setreg.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.setreg.ll
@@ -1433,6 +1433,72 @@ define amdgpu_kernel void 
@test_setreg_set_4_bits_straddles_round_and_denorm() {
   ret void
 }
 
+define amdgpu_ps void @test_63489(i32 inreg %var.mode) {
+; GFX6-LABEL: test_63489:
+; GFX6:   ; %bb.0:
+; GFX6-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x80,0xb9]
+; GFX6-NEXT:;;#ASMSTART
+; GFX6-NEXT:;;#ASMEND
+; GFX6-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX789-LABEL: test_63489:
+; GFX789:   ; %bb.0:
+; GFX789-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x00,0xb9]
+; GFX789-NEXT:;;#ASMSTART
+; GFX789-NEXT:;;#ASMEND
+; GFX789-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX10-LABEL: test_63489:
+; GFX10:   ; %bb.0:
+; GFX10-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x80,0xb9]
+; GFX10-NEXT:;;#ASMSTART
+; GFX10-NEXT:;;#ASMEND
+; GFX10-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX11-LABEL: test_63489:
+; GFX11:   ; %bb.0:
+; GFX11-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x00,0xb9]
+; GFX11-NEXT:;;#ASMSTART
+; GFX11-NEXT:;;#ASMEND
+; GFX11-NEXT:s_endpgm ; encoding: [0x00,0x00,0xb0,0xbf]
+  call void @llvm.amdgcn.s.setreg(i32 63489, i32 %var.mode)
+  call void asm sideeffect "", ""()
+  ret void
+}
+
+define amdgpu_ps void @test_minus_2047(i32 inreg %var.mode) {
+; GFX6-LABEL: test_minus_2047:
+; GFX6:   ; %bb.0:
+; GFX6-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x80,0xb9]
+; GFX6-NEXT:;;#ASMSTART
+; GFX6-NEXT:;;#ASMEND
+; GFX6-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX789-LABEL: test_minus_2047:
+; GFX789:   ; %bb.0:
+; GFX789-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x00,0xb9]
+; GFX789-NEXT:;;#ASMSTART
+; GFX789-NEXT:;;#ASMEND
+; GFX789-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX10-LABEL: test_minus_2047:
+; GFX10:   ; %bb.0:
+; GFX10-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x80,0xb9]
+; GFX10-NEXT:;;#ASMSTART
+; GFX10-NEXT:;;#ASMEND
+; GFX10-NEXT:s_endpgm ; encoding: [0x00,0x00,0x81,0xbf]
+;
+; GFX11-LABEL: test_minus_2047:
+; GFX11:   ; %bb.0:
+; GFX11-NEXT:s_setreg_b32 hwreg(HW_REG_MODE), s0 ; encoding: 
[0x01,0xf8,0x00,0xb9]
+; GFX11-NEXT:;;#ASMSTART
+; GFX11-NEXT:;;#ASMEND
+; GFX11-NEXT:s_endpgm ; encoding: [0x00,0x00,0xb0,0xbf]
+  call void @llvm.amdgcn.s.setreg(i32 -2047, i32 %var.mode)
+  call void asm sideeffect "", ""()
+  ret void
+}
+
 ; FIXME: Broken for DAG
 ; define void @test_setreg_roundingmode_var_vgpr(i32 %var.mode) {
 ;   call void @llvm.amdgcn.s.setreg(i32 

[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread via cfe-commits

https://github.com/kelbon updated 
https://github.com/llvm/llvm-project/pull/78200

>From e8c799b54c3e0b8088dbc19aaac0ef066baf136e Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Mon, 15 Jan 2024 22:24:34 +0400
Subject: [PATCH 1/6] add warning and test

---
 clang/include/clang/Basic/DiagnosticGroups.td| 1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 7 +++
 clang/lib/Sema/SemaDecl.cpp  | 7 +++
 clang/test/Sema/incorrect_pure.cpp   | 7 +++
 4 files changed, 22 insertions(+)
 create mode 100644 clang/test/Sema/incorrect_pure.cpp

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c1..9fcf2be2e45458e 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -414,6 +414,7 @@ def : DiagGroup<"c++2a-compat", [CXX20Compat]>;
 def : DiagGroup<"c++2a-compat-pedantic", [CXX20CompatPedantic]>;
 
 def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
+def IncorrectAttributeUsage : DiagGroup<"incorrect-attribute-usage">;
 def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
 def FourByteMultiChar : DiagGroup<"four-char-constants">;
 def GlobalConstructors : DiagGroup<"global-constructors"> {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 03b0122d1c08f75..1df075119a482fb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -692,6 +692,13 @@ def warn_maybe_falloff_nonvoid_function : Warning<
 def warn_falloff_nonvoid_function : Warning<
   "non-void function does not return a value">,
   InGroup;
+def warn_pure_attr_on_cxx_constructor : Warning<
+  "constructor cannot be 'pure' (undefined behavior)">,
+  InGroup;
+def warn_pure_function_returns_void : Warning<
+  "'pure' attribute on function returning 'void'">,
+  InGroup;
+
 def err_maybe_falloff_nonvoid_block : Error<
   "non-void block does not return a value in all control paths">;
 def err_falloff_nonvoid_block : Error<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index dae98f3a7406e87..86dc022fbe055d8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11899,6 +11899,13 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 NewFD->setInvalidDecl();
   }
 
+  if (NewFD->hasAttr() || NewFD->hasAttr()) {
+if (isa(NewFD))
+  Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
+else if (NewFD->getReturnType()->isVoidType())
+  Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);
+  }
+
   // C++11 [dcl.constexpr]p8:
   //   A constexpr specifier for a non-static member function that is not
   //   a constructor declares that member function to be const.
diff --git a/clang/test/Sema/incorrect_pure.cpp 
b/clang/test/Sema/incorrect_pure.cpp
new file mode 100644
index 000..ce02309f0863863
--- /dev/null
+++ b/clang/test/Sema/incorrect_pure.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+[[gnu::pure]] void foo(); // expected-warning{{'pure' attribute on function 
returning 'void'}}
+
+struct A {
+[[gnu::pure]] A(); // expected-warning{{constructor cannot be 'pure' 
(undefined behavior)}}
+};

>From d152fa4881d6052bfad33c922f276d4909c305ec Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Tue, 16 Jan 2024 00:03:47 +0400
Subject: [PATCH 2/6] fix old incorrect test

---
 clang/test/Analysis/call-invalidation.cpp   | 8 
 clang/test/CodeGen/pragma-weak.c| 6 +++---
 clang/test/Interpreter/disambiguate-decl-stmt.cpp   | 4 ++--
 clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp | 2 +-
 clang/test/SemaCXX/warn-unused-value-cxx11.cpp  | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/clang/test/Analysis/call-invalidation.cpp 
b/clang/test/Analysis/call-invalidation.cpp
index ef6505e19cf803f..727217f228b0542 100644
--- a/clang/test/Analysis/call-invalidation.cpp
+++ b/clang/test/Analysis/call-invalidation.cpp
@@ -90,8 +90,8 @@ void testConstReferenceStruct() {
 }
 
 
-void usePointerPure(int * const *) __attribute__((pure));
-void usePointerConst(int * const *) __attribute__((const));
+int usePointerPure(int * const *) __attribute__((pure));
+int usePointerConst(int * const *) __attribute__((const));
 
 void testPureConst() {
   extern int global;
@@ -104,11 +104,11 @@ void testPureConst() {
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   clang_analyzer_eval(global == -5); // expected-warning{{TRUE}}
 
-  usePointerPure();
+  (void)usePointerPure();
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   clang_analyzer_eval(global == -5); // expected-warning{{TRUE}}
 
-  usePointerConst();
+  (void)usePointerConst();
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   

[clang] [llvm] [flang] [clang-tools-extra] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-17 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/74309

>From 14f8c3e38791cc6b06455b8beffe37a6f7105e03 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 4 Dec 2023 10:32:03 +
Subject: [PATCH 01/18] Add SYSTEM runtime and lowering intrinsic support

Calls std::system() function and pass the command,
cmd on Windows or shell on Linux.
Command parameter is required, exitstatus is optional.
call system(command)
call system(command, exitstatus)
---
 flang/docs/Intrinsics.md  |  2 +-
 .../flang/Optimizer/Builder/IntrinsicCall.h   |  1 +
 .../flang/Optimizer/Builder/Runtime/Command.h |  5 +++
 flang/include/flang/Runtime/command.h |  5 +++
 flang/lib/Evaluate/intrinsics.cpp | 16 +---
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 22 ++
 .../lib/Optimizer/Builder/Runtime/Command.cpp | 13 ++
 flang/runtime/command.cpp | 19 +
 flang/test/Lower/Intrinsics/system.f90| 39 ++
 flang/unittests/Runtime/CommandTest.cpp   | 41 +++
 10 files changed, 157 insertions(+), 6 deletions(-)
 create mode 100644 flang/test/Lower/Intrinsics/system.f90

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index fef2b4ea4dd8c8..871332399628e9 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, GETPID, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, 
FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h 
b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index 5065f11ae9e726..669d076c3e0e7d 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -321,6 +321,7 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genStorageSize(mlir::Type,
 llvm::ArrayRef);
   fir::ExtendedValue genSum(mlir::Type, llvm::ArrayRef);
+  void genSystem(mlir::ArrayRef args);
   void genSystemClock(llvm::ArrayRef);
   mlir::Value genTand(mlir::Type, llvm::ArrayRef);
   mlir::Value genTrailz(mlir::Type, llvm::ArrayRef);
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/Command.h 
b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
index 976fb3aa0b6fbb..9d6a39639844fc 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/Command.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
@@ -53,5 +53,10 @@ mlir::Value genGetEnvVariable(fir::FirOpBuilder &, 
mlir::Location,
   mlir::Value length, mlir::Value trimName,
   mlir::Value errmsg);
 
+/// Generate a call to System runtime function which implements
+/// the non-standard System GNU extension.
+void genSystem(fir::FirOpBuilder &, mlir::Location, mlir::Value command,
+   mlir::Value exitstat);
+
 } // namespace fir::runtime
 #endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_COMMAND_H
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index c67d171c8e2f1b..f325faa7bd09fa 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -55,6 +55,11 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor ,
 const Descriptor *value = nullptr, const Descriptor *length = nullptr,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
+
+// Calls std::system()
+void RTNAME(System)(const Descriptor *command = nullptr,
+const Descriptor *exitstat = nullptr, const char *sourceFile = nullptr,
+int line = 0);
 }
 } // namespace Fortran::runtime
 
diff 

[clang] [clang-tools-extra] [clangd] Support parsing comments without ASTContext (PR #78491)

2024-01-17 Thread Tom Praschan via cfe-commits

https://github.com/tom-anders updated 
https://github.com/llvm/llvm-project/pull/78491

>From 640318fcf475a82b5483889795e2bd906b7b3c9c Mon Sep 17 00:00:00 2001
From: Tom Praschan <13141438+tom-and...@users.noreply.github.com>
Date: Sat, 18 Feb 2023 15:54:09 +0100
Subject: [PATCH] [clangd] Support parsing comments without ASTContext

This is in preparation for implementing doxygen parsing, see discussion in 
https://github.com/clangd/clangd/issues/529.

Differential Revision: https://reviews.llvm.org/D143112
---
 .../clangd/CodeCompletionStrings.cpp  | 24 +++
 .../clangd/CodeCompletionStrings.h| 11 +
 clang/include/clang/Basic/SourceManager.h |  2 +-
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp 
b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
index 2075e5965f181ed..540eaa9a3eb6d74 100644
--- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -9,6 +9,9 @@
 #include "CodeCompletionStrings.h"
 #include "clang-c/Index.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/CommentLexer.h"
+#include "clang/AST/CommentParser.h"
+#include "clang/AST/CommentSema.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
@@ -316,5 +319,26 @@ std::string getReturnType(const CodeCompletionString ) 
{
   return "";
 }
 
+comments::FullComment *parseComment(llvm::StringRef Comment,
+llvm::BumpPtrAllocator ,
+comments::CommandTraits ) {
+  // The comment lexer expects markers, so add them back
+  auto CommentWithMarkers = "/*" + Comment.str() + "*/";
+
+  SourceManagerForFile SourceMgrForFile("mock_file.cpp", CommentWithMarkers);
+  SourceManager  = SourceMgrForFile.get();
+
+  comments::Lexer L(Allocator, SourceMgr.getDiagnostics(), Traits,
+SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()),
+CommentWithMarkers.data(),
+CommentWithMarkers.data() + CommentWithMarkers.size());
+  comments::Sema S(Allocator, SourceMgr, SourceMgr.getDiagnostics(), Traits,
+   nullptr);
+  comments::Parser P(L, S, Allocator, SourceMgr, SourceMgr.getDiagnostics(),
+ Traits);
+
+  return P.parseFullComment();
+}
+
 } // namespace clangd
 } // namespace clang
diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.h 
b/clang-tools-extra/clangd/CodeCompletionStrings.h
index fa81ad64d406c3b..b93420c68f32dba 100644
--- a/clang-tools-extra/clangd/CodeCompletionStrings.h
+++ b/clang-tools-extra/clangd/CodeCompletionStrings.h
@@ -19,6 +19,11 @@
 namespace clang {
 class ASTContext;
 
+namespace comments {
+class CommandTraits;
+class FullComment;
+} // namespace comments
+
 namespace clangd {
 
 /// Gets a minimally formatted documentation comment of \p Result, with comment
@@ -67,6 +72,12 @@ std::string formatDocumentation(const CodeCompletionString 
,
 /// is usually the return type of a function.
 std::string getReturnType(const CodeCompletionString );
 
+/// Parse the \p Comment, storing the result in \p Allocator, assuming
+/// that comment markers have already been stripped (e.g. via getDocComment())
+comments::FullComment *parseComment(llvm::StringRef Comment,
+llvm::BumpPtrAllocator ,
+comments::CommandTraits );
+
 } // namespace clangd
 } // namespace clang
 
diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index d2ece14da0b11ab..07e3fca1641c738 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1971,7 +1971,7 @@ class BeforeThanCompare {
 };
 
 /// SourceManager and necessary dependencies (e.g. VFS, FileManager) for a
-/// single in-memorty file.
+/// single in-memory file.
 class SourceManagerForFile {
 public:
   /// Creates SourceManager and necessary dependencies (e.g. VFS, FileManager).

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


[clang] [clang-tools-extra] [clangd] Support parsing comments without ASTContext (PR #78491)

2024-01-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clangd

Author: Tom Praschan (tom-anders)


Changes

This is in preparation for implementing doxygen parsing, see discussion in 
https://github.com/clangd/clangd/issues/529.

(Old Phabricator review: https://reviews.llvm.org/D143112)

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


3 Files Affected:

- (modified) clang-tools-extra/clangd/CodeCompletionStrings.cpp (+24) 
- (modified) clang-tools-extra/clangd/CodeCompletionStrings.h (+11) 
- (modified) clang/include/clang/Basic/SourceManager.h (+1-1) 


``diff
diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp 
b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
index 2075e5965f181e..540eaa9a3eb6d7 100644
--- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -9,6 +9,9 @@
 #include "CodeCompletionStrings.h"
 #include "clang-c/Index.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/CommentLexer.h"
+#include "clang/AST/CommentParser.h"
+#include "clang/AST/CommentSema.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
@@ -316,5 +319,26 @@ std::string getReturnType(const CodeCompletionString ) 
{
   return "";
 }
 
+comments::FullComment *parseComment(llvm::StringRef Comment,
+llvm::BumpPtrAllocator ,
+comments::CommandTraits ) {
+  // The comment lexer expects markers, so add them back
+  auto CommentWithMarkers = "/*" + Comment.str() + "*/";
+
+  SourceManagerForFile SourceMgrForFile("mock_file.cpp", CommentWithMarkers);
+  SourceManager  = SourceMgrForFile.get();
+
+  comments::Lexer L(Allocator, SourceMgr.getDiagnostics(), Traits,
+SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()),
+CommentWithMarkers.data(),
+CommentWithMarkers.data() + CommentWithMarkers.size());
+  comments::Sema S(Allocator, SourceMgr, SourceMgr.getDiagnostics(), Traits,
+   nullptr);
+  comments::Parser P(L, S, Allocator, SourceMgr, SourceMgr.getDiagnostics(),
+ Traits);
+
+  return P.parseFullComment();
+}
+
 } // namespace clangd
 } // namespace clang
diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.h 
b/clang-tools-extra/clangd/CodeCompletionStrings.h
index fa81ad64d406c3..b93420c68f32db 100644
--- a/clang-tools-extra/clangd/CodeCompletionStrings.h
+++ b/clang-tools-extra/clangd/CodeCompletionStrings.h
@@ -19,6 +19,11 @@
 namespace clang {
 class ASTContext;
 
+namespace comments {
+class CommandTraits;
+class FullComment;
+} // namespace comments
+
 namespace clangd {
 
 /// Gets a minimally formatted documentation comment of \p Result, with comment
@@ -67,6 +72,12 @@ std::string formatDocumentation(const CodeCompletionString 
,
 /// is usually the return type of a function.
 std::string getReturnType(const CodeCompletionString );
 
+/// Parse the \p Comment, storing the result in \p Allocator, assuming
+/// that comment markers have already been stripped (e.g. via getDocComment())
+comments::FullComment *parseComment(llvm::StringRef Comment,
+llvm::BumpPtrAllocator ,
+comments::CommandTraits );
+
 } // namespace clangd
 } // namespace clang
 
diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index d2ece14da0b11a..07e3fca1641c73 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1971,7 +1971,7 @@ class BeforeThanCompare {
 };
 
 /// SourceManager and necessary dependencies (e.g. VFS, FileManager) for a
-/// single in-memorty file.
+/// single in-memory file.
 class SourceManagerForFile {
 public:
   /// Creates SourceManager and necessary dependencies (e.g. VFS, FileManager).

``




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


[clang-tools-extra] [clang] [clangd] Support parsing comments without ASTContext (PR #78491)

2024-01-17 Thread Tom Praschan via cfe-commits

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


[clang-tools-extra] [clang] [clang] Support parsing comments without ASTContext (PR #78491)

2024-01-17 Thread Tom Praschan via cfe-commits

https://github.com/tom-anders created 
https://github.com/llvm/llvm-project/pull/78491

This is in preparation for implementing doxygen parsing, see discussion in 
https://github.com/clangd/clangd/issues/529.

(Old Phabricator review: https://reviews.llvm.org/D143112)

>From b5b4ddc967df436d0879cb8bd22a41acdf68819c Mon Sep 17 00:00:00 2001
From: Tom Praschan <13141438+tom-and...@users.noreply.github.com>
Date: Sat, 18 Feb 2023 15:54:09 +0100
Subject: [PATCH] [clang] Support parsing comments without ASTContext

This is in preparation for implementing doxygen parsing, see discussion in 
https://github.com/clangd/clangd/issues/529.

Differential Revision: https://reviews.llvm.org/D143112
---
 .../clangd/CodeCompletionStrings.cpp  | 24 +++
 .../clangd/CodeCompletionStrings.h| 11 +
 clang/include/clang/Basic/SourceManager.h |  2 +-
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp 
b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
index 2075e5965f181e..540eaa9a3eb6d7 100644
--- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -9,6 +9,9 @@
 #include "CodeCompletionStrings.h"
 #include "clang-c/Index.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/CommentLexer.h"
+#include "clang/AST/CommentParser.h"
+#include "clang/AST/CommentSema.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
@@ -316,5 +319,26 @@ std::string getReturnType(const CodeCompletionString ) 
{
   return "";
 }
 
+comments::FullComment *parseComment(llvm::StringRef Comment,
+llvm::BumpPtrAllocator ,
+comments::CommandTraits ) {
+  // The comment lexer expects markers, so add them back
+  auto CommentWithMarkers = "/*" + Comment.str() + "*/";
+
+  SourceManagerForFile SourceMgrForFile("mock_file.cpp", CommentWithMarkers);
+  SourceManager  = SourceMgrForFile.get();
+
+  comments::Lexer L(Allocator, SourceMgr.getDiagnostics(), Traits,
+SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()),
+CommentWithMarkers.data(),
+CommentWithMarkers.data() + CommentWithMarkers.size());
+  comments::Sema S(Allocator, SourceMgr, SourceMgr.getDiagnostics(), Traits,
+   nullptr);
+  comments::Parser P(L, S, Allocator, SourceMgr, SourceMgr.getDiagnostics(),
+ Traits);
+
+  return P.parseFullComment();
+}
+
 } // namespace clangd
 } // namespace clang
diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.h 
b/clang-tools-extra/clangd/CodeCompletionStrings.h
index fa81ad64d406c3..b93420c68f32db 100644
--- a/clang-tools-extra/clangd/CodeCompletionStrings.h
+++ b/clang-tools-extra/clangd/CodeCompletionStrings.h
@@ -19,6 +19,11 @@
 namespace clang {
 class ASTContext;
 
+namespace comments {
+class CommandTraits;
+class FullComment;
+} // namespace comments
+
 namespace clangd {
 
 /// Gets a minimally formatted documentation comment of \p Result, with comment
@@ -67,6 +72,12 @@ std::string formatDocumentation(const CodeCompletionString 
,
 /// is usually the return type of a function.
 std::string getReturnType(const CodeCompletionString );
 
+/// Parse the \p Comment, storing the result in \p Allocator, assuming
+/// that comment markers have already been stripped (e.g. via getDocComment())
+comments::FullComment *parseComment(llvm::StringRef Comment,
+llvm::BumpPtrAllocator ,
+comments::CommandTraits );
+
 } // namespace clangd
 } // namespace clang
 
diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index d2ece14da0b11a..07e3fca1641c73 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1971,7 +1971,7 @@ class BeforeThanCompare {
 };
 
 /// SourceManager and necessary dependencies (e.g. VFS, FileManager) for a
-/// single in-memorty file.
+/// single in-memory file.
 class SourceManagerForFile {
 public:
   /// Creates SourceManager and necessary dependencies (e.g. VFS, FileManager).

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


[clang] [Clang] Support MSPropertyRefExpr as placement arg to new-expression (PR #75883)

2024-01-17 Thread via cfe-commits

Sirraide wrote:

I’m curious, because I legitimately don’t know, is it common for CI on windows 
to take 9 hours?

![image](https://github.com/llvm/llvm-project/assets/74590115/203deb5a-b798-4ca2-8a6f-cc45a811d0f6)


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


[llvm] [lld] [clang-tools-extra] [lld/ELF] Hint if R_X86_64_PC32 overflows and references a SHF_X86_64_LARGE section (PR #73045)

2024-01-17 Thread Arthur Eubanks via cfe-commits

https://github.com/aeubanks updated 
https://github.com/llvm/llvm-project/pull/73045

>From 0145020ef2a803ec797e42f95bacde05dc32eac1 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks 
Date: Tue, 21 Nov 2023 14:01:04 -0800
Subject: [PATCH 1/2] [lld/ELF] Hint if R_X86_64_PC32 overflows and references
 a SHF_X86_64_LARGE section

Makes it clearer what the issue is when hand-written assembly doesn't follow 
medium code model assumptions in a medium code model build.

Alternative to #71248 by only hinting on an overflow.
---
 lld/ELF/Relocations.cpp   |  6 ++
 lld/test/ELF/x86-64-pc32-overflow-large.s | 25 +++
 2 files changed, 31 insertions(+)
 create mode 100644 lld/test/ELF/x86-64-pc32-overflow-large.s

diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index fe3d7f419e84aa..37a2363094020d 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -105,6 +105,12 @@ void elf::reportRangeError(uint8_t *loc, const Relocation 
, const Twine ,
   hint = "; references '" + lld::toString(*rel.sym) + '\'';
 else if (auto *d = dyn_cast(rel.sym))
   hint = ("; references section '" + d->section->name + "'").str();
+
+if (rel.type == R_X86_64_PC32 && rel.sym->getOutputSection() &&
+(rel.sym->getOutputSection()->flags & SHF_X86_64_LARGE)) {
+  hint += "; a R_X86_64_PC32 relocation should not reference a section "
+  "marked SHF_X86_64_LARGE";
+}
   }
   if (!errPlace.srcLoc.empty())
 hint += "\n>>> referenced by " + errPlace.srcLoc;
diff --git a/lld/test/ELF/x86-64-pc32-overflow-large.s 
b/lld/test/ELF/x86-64-pc32-overflow-large.s
new file mode 100644
index 00..54c20eddfd04c3
--- /dev/null
+++ b/lld/test/ELF/x86-64-pc32-overflow-large.s
@@ -0,0 +1,25 @@
+# REQUIRES: x86
+# RUN: split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
+# RUN: not ld.lld %t/a.o -T %t/lds -o /dev/null 2>&1 | FileCheck %s
+
+# CHECK: error: {{.*}}a.o:(.text+{{.*}}): relocation R_X86_64_PC32 out of 
range: {{.*}}; a R_X86_64_PC32 relocation should not reference a section marked 
SHF_X86_64_LARGE
+
+#--- a.s
+.text
+.globl _start
+.type _start, @function
+_start:
+  movq hello(%rip), %rax
+
+.section ldata,"awl",@progbits
+.type   hello, @object
+.globl  hello
+hello:
+.long   1
+
+#--- lds
+SECTIONS {
+  .text 0x10 : { *(.text) }
+  ldata 0x8020 : { *(ldata) }
+}

>From a4432ade194df8dedb7b4990a29efaa4e822d486 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks 
Date: Wed, 17 Jan 2024 19:20:39 +
Subject: [PATCH 2/2] check emachine

---
 lld/ELF/Relocations.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index e1e047c3d05242..10f62f21274239 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -106,7 +106,8 @@ void elf::reportRangeError(uint8_t *loc, const Relocation 
, const Twine ,
 else if (auto *d = dyn_cast(rel.sym))
   hint = ("; references section '" + d->section->name + "'").str();
 
-if (rel.type == R_X86_64_PC32 && rel.sym->getOutputSection() &&
+if (config->emachine == EM_X86_64 && rel.type == R_X86_64_PC32 &&
+rel.sym->getOutputSection() &&
 (rel.sym->getOutputSection()->flags & SHF_X86_64_LARGE)) {
   hint += "; a R_X86_64_PC32 relocation should not reference a section "
   "marked SHF_X86_64_LARGE";

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


[clang] [llvm] [CMake] Detect properly new linker introduced in Xcode 15 (PR #77806)

2024-01-17 Thread Louis Dionne via cfe-commits

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


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


[clang] [llvm] [CMake] Detect properly new linker introduced in Xcode 15 (PR #77806)

2024-01-17 Thread Louis Dionne via cfe-commits


@@ -211,10 +211,10 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
 )
 
   if(APPLE)
-if("${stderr}" MATCHES "PROJECT:ld64")
+if("${stderr}" MATCHES "PROGRAM:ld")

ldionne wrote:

Ahhh, now this all makes sense! I hadn't noticed that you switched to 
`PROGRAM:ld`.

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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread via cfe-commits

https://github.com/kelbon updated 
https://github.com/llvm/llvm-project/pull/78200

>From e8c799b54c3e0b8088dbc19aaac0ef066baf136e Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Mon, 15 Jan 2024 22:24:34 +0400
Subject: [PATCH 1/5] add warning and test

---
 clang/include/clang/Basic/DiagnosticGroups.td| 1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 7 +++
 clang/lib/Sema/SemaDecl.cpp  | 7 +++
 clang/test/Sema/incorrect_pure.cpp   | 7 +++
 4 files changed, 22 insertions(+)
 create mode 100644 clang/test/Sema/incorrect_pure.cpp

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..9fcf2be2e45458 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -414,6 +414,7 @@ def : DiagGroup<"c++2a-compat", [CXX20Compat]>;
 def : DiagGroup<"c++2a-compat-pedantic", [CXX20CompatPedantic]>;
 
 def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
+def IncorrectAttributeUsage : DiagGroup<"incorrect-attribute-usage">;
 def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
 def FourByteMultiChar : DiagGroup<"four-char-constants">;
 def GlobalConstructors : DiagGroup<"global-constructors"> {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 03b0122d1c08f7..1df075119a482f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -692,6 +692,13 @@ def warn_maybe_falloff_nonvoid_function : Warning<
 def warn_falloff_nonvoid_function : Warning<
   "non-void function does not return a value">,
   InGroup;
+def warn_pure_attr_on_cxx_constructor : Warning<
+  "constructor cannot be 'pure' (undefined behavior)">,
+  InGroup;
+def warn_pure_function_returns_void : Warning<
+  "'pure' attribute on function returning 'void'">,
+  InGroup;
+
 def err_maybe_falloff_nonvoid_block : Error<
   "non-void block does not return a value in all control paths">;
 def err_falloff_nonvoid_block : Error<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index dae98f3a7406e8..86dc022fbe055d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11899,6 +11899,13 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 NewFD->setInvalidDecl();
   }
 
+  if (NewFD->hasAttr() || NewFD->hasAttr()) {
+if (isa(NewFD))
+  Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
+else if (NewFD->getReturnType()->isVoidType())
+  Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);
+  }
+
   // C++11 [dcl.constexpr]p8:
   //   A constexpr specifier for a non-static member function that is not
   //   a constructor declares that member function to be const.
diff --git a/clang/test/Sema/incorrect_pure.cpp 
b/clang/test/Sema/incorrect_pure.cpp
new file mode 100644
index 00..ce02309f086386
--- /dev/null
+++ b/clang/test/Sema/incorrect_pure.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+[[gnu::pure]] void foo(); // expected-warning{{'pure' attribute on function 
returning 'void'}}
+
+struct A {
+[[gnu::pure]] A(); // expected-warning{{constructor cannot be 'pure' 
(undefined behavior)}}
+};

>From d152fa4881d6052bfad33c922f276d4909c305ec Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Tue, 16 Jan 2024 00:03:47 +0400
Subject: [PATCH 2/5] fix old incorrect test

---
 clang/test/Analysis/call-invalidation.cpp   | 8 
 clang/test/CodeGen/pragma-weak.c| 6 +++---
 clang/test/Interpreter/disambiguate-decl-stmt.cpp   | 4 ++--
 clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp | 2 +-
 clang/test/SemaCXX/warn-unused-value-cxx11.cpp  | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/clang/test/Analysis/call-invalidation.cpp 
b/clang/test/Analysis/call-invalidation.cpp
index ef6505e19cf803..727217f228b054 100644
--- a/clang/test/Analysis/call-invalidation.cpp
+++ b/clang/test/Analysis/call-invalidation.cpp
@@ -90,8 +90,8 @@ void testConstReferenceStruct() {
 }
 
 
-void usePointerPure(int * const *) __attribute__((pure));
-void usePointerConst(int * const *) __attribute__((const));
+int usePointerPure(int * const *) __attribute__((pure));
+int usePointerConst(int * const *) __attribute__((const));
 
 void testPureConst() {
   extern int global;
@@ -104,11 +104,11 @@ void testPureConst() {
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   clang_analyzer_eval(global == -5); // expected-warning{{TRUE}}
 
-  usePointerPure();
+  (void)usePointerPure();
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   clang_analyzer_eval(global == -5); // expected-warning{{TRUE}}
 
-  usePointerConst();
+  (void)usePointerConst();
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-17 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH 1/9] [clang] Fix parenthesized list initialization of arrays
 not working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all the nested initializer lists. This avoids
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c..71e420648ce7af 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1947,11 +1947,11 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool 
UseGlobal,
 }
 
 static bool isLegalArrayNewInitializer(CXXNewInitializationStyle Style,
-   

[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-01-17 Thread via cfe-commits

https://github.com/sethp updated https://github.com/llvm/llvm-project/pull/74852

>From f281d34a51f662c934f158e4770774b0dc3588a2 Mon Sep 17 00:00:00 2001
From: Seth Pellegrino 
Date: Thu, 7 Dec 2023 08:45:51 -0800
Subject: [PATCH 01/10] [Clang][Sema] Print more static_assert exprs

This change introspects more values involved in a static_assert, and
extends the supported set of operators for introspection to include
binary operator method calls.

It's intended to address the use-case where a small static_assert helper
looks something like this (via `constexpr-builtin-bit-cast.cpp`):

```c++
struct int_splicer {
  unsigned x;
  unsigned y;

  constexpr bool operator==(const int_splicer ) const {
return other.x == x && other.y == y;
  }
};
```

When used like so:

```c++
constexpr int_splicer got{1, 2};
constexpr int_splicer want{3, 4};
static_assert(got == want);
```

Then we'd expect to get the error:

```
Static assertion failed due to requirement 'got == want'
```

And this change adds the helpful note:

```
Expression evaluates to '{1, 2} == {3, 4}'
```
---
 clang/lib/Sema/SemaDeclCXX.cpp| 31 ++-
 .../CXX/class/class.compare/class.eq/p3.cpp   | 20 ++--
 .../CXX/class/class.compare/class.rel/p2.cpp  | 10 +++---
 .../over.match.oper/p9-2a.cpp |  2 +-
 clang/test/SemaCXX/static-assert-cxx17.cpp|  2 +-
 5 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c6218a491aecece..e3d46c3140741be 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17219,6 +17219,13 @@ static bool ConvertAPValueToString(const APValue , 
QualType T,
 OS << "i)";
   } break;
 
+  case APValue::ValueKind::Array:
+  case APValue::ValueKind::Vector:
+  case APValue::ValueKind::Struct: {
+llvm::raw_svector_ostream OS(Str);
+V.printPretty(OS, Context, T);
+  } break;
+
   default:
 return false;
   }
@@ -17256,11 +17263,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E);
-  Op && Op->getOpcode() != BO_LOr) {
-const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
-const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
-
+  const auto Diagnose = [&](const Expr *LHS, const Expr *RHS,
+const llvm::StringRef ) {
+LHS = LHS->IgnoreParenImpCasts();
+RHS = RHS->IgnoreParenImpCasts();
 // Ignore comparisons of boolean expressions with a boolean literal.
 if ((isa(LHS) && RHS->getType()->isBooleanType()) ||
 (isa(RHS) && LHS->getType()->isBooleanType()))
@@ -17287,10 +17293,19 @@ void Sema::DiagnoseStaticAssertDetails(const Expr *E) 
{
  DiagSide[I].ValueString, Context);
 }
 if (DiagSide[0].Print && DiagSide[1].Print) {
-  Diag(Op->getExprLoc(), diag::note_expr_evaluates_to)
-  << DiagSide[0].ValueString << Op->getOpcodeStr()
-  << DiagSide[1].ValueString << Op->getSourceRange();
+  Diag(E->getExprLoc(), diag::note_expr_evaluates_to)
+  << DiagSide[0].ValueString << OpStr << DiagSide[1].ValueString
+  << E->getSourceRange();
 }
+  };
+
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
+Diagnose(Op->getLHS(), Op->getRHS(), Op->getOpcodeStr());
+  } else if (const auto *Op = dyn_cast(E);
+ Op && Op->isInfixBinaryOp()) {
+Diagnose(Op->getArg(0), Op->getArg(1),
+ getOperatorSpelling(Op->getOperator()));
   }
 }
 
diff --git a/clang/test/CXX/class/class.compare/class.eq/p3.cpp 
b/clang/test/CXX/class/class.compare/class.eq/p3.cpp
index 04db022fe730217..53c4dda133301b4 100644
--- a/clang/test/CXX/class/class.compare/class.eq/p3.cpp
+++ b/clang/test/CXX/class/class.compare/class.eq/p3.cpp
@@ -6,11 +6,11 @@ struct A {
 };
 
 static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 4, 5});
-static_assert(A{1, 2, 3, 4, 5} == A{0, 2, 3, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 0, 3, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 0, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 0, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 4, 0}); // expected-error 
{{failed}}
+static_assert(A{1, 2, 3, 4, 5} == A{0, 2, 3, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 0, 3, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 0, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 0, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} 

[lldb] [flang] [libcxx] [lld] [clang] [compiler-rt] [libcxxabi] [libunwind] [libc] [llvm] [clang-tools-extra] Fix a bug in Smith's algorithm used in complex div/mul. (PR #78330)

2024-01-17 Thread Andy Kaylor via cfe-commits


@@ -2780,24 +2781,24 @@ static void RenderFloatingPointOptions(const ToolChain 
, const Driver ,
 case options::OPT_fcx_limited_range: {
   EmitComplexRangeDiag(D, Range, 
LangOptions::ComplexRangeKind::CX_Limited);
   Range = LangOptions::ComplexRangeKind::CX_Limited;
-  std::string ComplexRangeStr = RenderComplexRangeOption("limited");
-  if (!ComplexRangeStr.empty())
-CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
+  ComplexRangeStr = RenderComplexRangeOption("limited");

andykaylor wrote:

I think it would be better to move the rendering of this option to the bottom 
of this function (around line 3124) to avoid inserting multiple, conflicting 
options if more than one -f[no-]cx-* option is used.

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


[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-17 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH 1/8] [clang] Fix parenthesized list initialization of arrays
 not working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all the nested initializer lists. This avoids
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c..71e420648ce7af 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1947,11 +1947,11 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool 
UseGlobal,
 }
 
 static bool isLegalArrayNewInitializer(CXXNewInitializationStyle Style,
-   

[clang-tools-extra] [libc] [lld] [llvm] [flang] [libcxxabi] [clang] [libunwind] [libcxx] [compiler-rt] [lldb] Fix a bug in Smith's algorithm used in complex div/mul. (PR #78330)

2024-01-17 Thread John McCall via cfe-commits

https://github.com/rjmccall commented:

It's bad that we don't have a IR test that breaks when you change the IR output 
like this.  Please add one.

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


[libc] [lldb] [clang] [llvm] [libunwind] [flang] [lld] [libcxxabi] [clang-tools-extra] [libcxx] [compiler-rt] Fix a bug in Smith's algorithm used in complex div/mul. (PR #78330)

2024-01-17 Thread John McCall via cfe-commits


@@ -978,7 +978,11 @@ ComplexPairTy ComplexExprEmitter::EmitBinDiv(const 
BinOpInfo ) {
   return EmitRangeReductionDiv(LHSr, LHSi, RHSr, RHSi);
 else if (Op.FPFeatures.getComplexRange() == LangOptions::CX_Limited)
   return EmitAlgebraicDiv(LHSr, LHSi, RHSr, RHSi);
-else if (!CGF.getLangOpts().FastMath) {
+else if (!CGF.getLangOpts().FastMath ||
+ // '-ffast-math' is used in the command line but followed by an
+ // '-fno-cx-limited-range'.
+ (CGF.getLangOpts().FastMath &&
+  Op.FPFeatures.getComplexRange() == LangOptions::CX_Full)) {

rjmccall wrote:

`FastMath` is tautologically true here.

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


[libcxx] [flang] [lldb] [clang-tools-extra] [libc] [libunwind] [libcxxabi] [clang] [llvm] [compiler-rt] [lld] Fix a bug in Smith's algorithm used in complex div/mul. (PR #78330)

2024-01-17 Thread John McCall via cfe-commits

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


[flang] [llvm] [clang-tools-extra] [clang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-17 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/74309

>From 14f8c3e38791cc6b06455b8beffe37a6f7105e03 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 4 Dec 2023 10:32:03 +
Subject: [PATCH 01/18] Add SYSTEM runtime and lowering intrinsic support

Calls std::system() function and pass the command,
cmd on Windows or shell on Linux.
Command parameter is required, exitstatus is optional.
call system(command)
call system(command, exitstatus)
---
 flang/docs/Intrinsics.md  |  2 +-
 .../flang/Optimizer/Builder/IntrinsicCall.h   |  1 +
 .../flang/Optimizer/Builder/Runtime/Command.h |  5 +++
 flang/include/flang/Runtime/command.h |  5 +++
 flang/lib/Evaluate/intrinsics.cpp | 16 +---
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 22 ++
 .../lib/Optimizer/Builder/Runtime/Command.cpp | 13 ++
 flang/runtime/command.cpp | 19 +
 flang/test/Lower/Intrinsics/system.f90| 39 ++
 flang/unittests/Runtime/CommandTest.cpp   | 41 +++
 10 files changed, 157 insertions(+), 6 deletions(-)
 create mode 100644 flang/test/Lower/Intrinsics/system.f90

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index fef2b4ea4dd8c8..871332399628e9 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, GETPID, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, 
FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h 
b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index 5065f11ae9e726..669d076c3e0e7d 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -321,6 +321,7 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genStorageSize(mlir::Type,
 llvm::ArrayRef);
   fir::ExtendedValue genSum(mlir::Type, llvm::ArrayRef);
+  void genSystem(mlir::ArrayRef args);
   void genSystemClock(llvm::ArrayRef);
   mlir::Value genTand(mlir::Type, llvm::ArrayRef);
   mlir::Value genTrailz(mlir::Type, llvm::ArrayRef);
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/Command.h 
b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
index 976fb3aa0b6fbb..9d6a39639844fc 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/Command.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
@@ -53,5 +53,10 @@ mlir::Value genGetEnvVariable(fir::FirOpBuilder &, 
mlir::Location,
   mlir::Value length, mlir::Value trimName,
   mlir::Value errmsg);
 
+/// Generate a call to System runtime function which implements
+/// the non-standard System GNU extension.
+void genSystem(fir::FirOpBuilder &, mlir::Location, mlir::Value command,
+   mlir::Value exitstat);
+
 } // namespace fir::runtime
 #endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_COMMAND_H
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index c67d171c8e2f1b..f325faa7bd09fa 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -55,6 +55,11 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor ,
 const Descriptor *value = nullptr, const Descriptor *length = nullptr,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
+
+// Calls std::system()
+void RTNAME(System)(const Descriptor *command = nullptr,
+const Descriptor *exitstat = nullptr, const char *sourceFile = nullptr,
+int line = 0);
 }
 } // namespace Fortran::runtime
 
diff 

[clang] [clang] Upstream XROS support in Clang (PR #78392)

2024-01-17 Thread Jonas Devlieghere via cfe-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/78392

>From d7c431e0fbc0ad006b9d37a4e3a43c61ce1f50b7 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 16 Jan 2024 20:36:47 -0800
Subject: [PATCH] [clang] Upstream XROS support in Clang

Upstream XROS support in the clang frontend and driver.
---
 clang/lib/Basic/Targets/OSTargets.h   |  6 +-
 clang/lib/CodeGen/CGObjC.cpp  |  5 ++
 clang/lib/Driver/Driver.cpp   |  1 +
 clang/lib/Driver/ToolChains/Arch/AArch64.cpp  |  5 ++
 clang/lib/Driver/ToolChains/Arch/ARM.cpp  |  5 +-
 clang/lib/Driver/ToolChains/Darwin.cpp| 56 ++-
 clang/lib/Driver/ToolChains/Darwin.h  | 14 -
 .../Checkers/CheckSecuritySyntaxOnly.cpp  |  2 +
 clang/test/Driver/xros-driver.c   | 41 ++
 clang/test/Frontend/xros-version.c|  3 +
 10 files changed, 131 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Driver/xros-driver.c
 create mode 100644 clang/test/Frontend/xros-version.c

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 342af4bbc42b7bc..4366c1149e40530 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -74,7 +74,8 @@ class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo : public 
OSTargetInfo {
 this->TLSSupported = !Triple.isOSVersionLT(3);
 } else if (Triple.isDriverKit()) {
   // No TLS on DriverKit.
-}
+} else if (Triple.isXROS())
+  this->TLSSupported = true;
 
 this->MCountName = "\01mcount";
   }
@@ -109,6 +110,9 @@ class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo : public 
OSTargetInfo {
 case llvm::Triple::WatchOS: // Earliest supporting version is 5.0.0.
   MinVersion = llvm::VersionTuple(5U);
   break;
+case llvm::Triple::XROS:
+  MinVersion = llvm::VersionTuple(0);
+  break;
 default:
   // Conservatively return 8 bytes if OS is unknown.
   return 64;
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index acc85165a470be7..03fc0ec7ff54e1c 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -3941,6 +3941,8 @@ static unsigned getBaseMachOPlatformID(const llvm::Triple 
) {
 return llvm::MachO::PLATFORM_TVOS;
   case llvm::Triple::WatchOS:
 return llvm::MachO::PLATFORM_WATCHOS;
+  case llvm::Triple::XROS:
+return llvm::MachO::PLATFORM_XROS;
   case llvm::Triple::DriverKit:
 return llvm::MachO::PLATFORM_DRIVERKIT;
   default:
@@ -4024,6 +4026,9 @@ static bool isFoundationNeededForDarwinAvailabilityCheck(
   case llvm::Triple::MacOSX:
 FoundationDroppedInVersion = VersionTuple(/*Major=*/10, /*Minor=*/15);
 break;
+  case llvm::Triple::XROS:
+// XROS doesn't need Foundation.
+return false;
   case llvm::Triple::DriverKit:
 // DriverKit doesn't need Foundation.
 return false;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df10..35d563b9a87fac4 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6213,6 +6213,7 @@ const ToolChain ::getToolChain(const ArgList ,
 case llvm::Triple::IOS:
 case llvm::Triple::TvOS:
 case llvm::Triple::WatchOS:
+case llvm::Triple::XROS:
 case llvm::Triple::DriverKit:
   TC = std::make_unique(*this, Target, Args);
   break;
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 85f053dc8b6eab7..0cf96bb5c9cb02b 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -53,6 +53,11 @@ std::string aarch64::getAArch64TargetCPU(const ArgList ,
 return "apple-m1";
   }
 
+  if (Triple.isXROS()) {
+// The xrOS simulator runs on M1 as well, it should have been covered 
above.
+assert(!Triple.isSimulatorEnvironment() && "xrossim should be mac-like");
+return "apple-a12";
+  }
   // arm64e requires v8.3a and only runs on apple-a12 and later CPUs.
   if (Triple.isArm64e())
 return "apple-a12";
diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 25470db2b6cebd7..e6ee2f88a84edf2 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -367,6 +367,7 @@ arm::FloatABI arm::getDefaultFloatABI(const llvm::Triple 
) {
   case llvm::Triple::IOS:
   case llvm::Triple::TvOS:
   case llvm::Triple::DriverKit:
+  case llvm::Triple::XROS:
 // Darwin defaults to "softfp" for v6 and v7.
 if (Triple.isWatchABI())
   return FloatABI::Hard;
@@ -836,8 +837,8 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
,
 if (A->getOption().matches(options::OPT_mlong_calls))
   Features.push_back("+long-calls");
   } else if (KernelOrKext && (!Triple.isiOS() || Triple.isOSVersionLT(6)) &&
- !Triple.isWatchOS()) {
-  

[clang-tools-extra] [clang] [compiler-rt] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)

2024-01-17 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

It seems that either the precommit CI has some problems, or there are existing 
`compiler-rt` breakages. https://github.com/llvm/llvm-project/pull/78037 is 
also failing the same test cases. The changes in #78037 does not look harmful 
either. I took a brief look at the current buildbots and I don't see any 
similar failures. Additionally, I am not able to reproduce these failures 
locally. 

I will see what can be investigated next, but I suspect at this PR is not the 
root cause of the `dlopen.cpp` failures.  

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


[llvm] [clang-tools-extra] [clang] [AMDGPU][GFX12] Add Atomic cond_sub_u32 (PR #76224)

2024-01-17 Thread Mariusz Sikora via cfe-commits

https://github.com/mariusz-sikora-at-amd closed 
https://github.com/llvm/llvm-project/pull/76224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [llvm] [lld] [compiler-rt] [clang-tools-extra] [clang] [libc] [lldb] [flang] [AMDGPU] Use alias info to relax waitcounts for LDS DMA (PR #74537)

2024-01-17 Thread Stanislav Mekhanoshin via cfe-commits

rampitec wrote:

> > lgtm, but can still fix the -O0 thing
> 
> But where do I get TM in the getAnalysisUsage?

Found addUsedIfAvailable() which does the trick.

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


[libcxx] [llvm] [lld] [compiler-rt] [clang-tools-extra] [clang] [libc] [lldb] [flang] [AMDGPU] Use alias info to relax waitcounts for LDS DMA (PR #74537)

2024-01-17 Thread Stanislav Mekhanoshin via cfe-commits

https://github.com/rampitec updated 
https://github.com/llvm/llvm-project/pull/74537

>From 7e382620cdc5999c645ed0746f242595f0294c58 Mon Sep 17 00:00:00 2001
From: Stanislav Mekhanoshin 
Date: Mon, 4 Dec 2023 16:11:53 -0800
Subject: [PATCH 01/13] [AMDGPU] Use alias info to relax waitcounts for LDS DMA

LDA DMA loads increase VMCNT and a load from the LDS stored must
wait on this counter to only read memory after it is written.
Wait count insertion pass does not track memory dependencies, it
tracks register dependencies. To model the LDS dependency a
psuedo register is used in the scoreboard, acting like if LDS DMA
writes it and LDS load reads it.

This patch adds 8 more pseudo registers to use for independent LDS
locations if we can prove they are disjoint using alias analysis.

Fixes: SWDEV-433427
---
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp   |  16 +-
 llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp |  73 +-
 llvm/lib/Target/AMDGPU/SIInstrInfo.cpp  |   4 +-
 llvm/lib/Target/AMDGPU/SIInstrInfo.h|   8 +
 llvm/lib/Target/AMDGPU/lds-dma-waits.ll | 154 
 llvm/test/CodeGen/AMDGPU/llc-pipeline.ll|   2 +
 6 files changed, 241 insertions(+), 16 deletions(-)
 create mode 100644 llvm/lib/Target/AMDGPU/lds-dma-waits.ll

diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index a7f4d63229b7ef..2e079404b087fa 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -1128,11 +1128,10 @@ bool SITargetLowering::getTgtMemIntrinsic(IntrinsicInfo 
,
 MachineMemOperand::MOStore |
 MachineMemOperand::MODereferenceable;
 
-  // XXX - Should this be volatile without known ordering?
-  Info.flags |= MachineMemOperand::MOVolatile;
-
   switch (IntrID) {
   default:
+// XXX - Should this be volatile without known ordering?
+Info.flags |= MachineMemOperand::MOVolatile;
 break;
   case Intrinsic::amdgcn_raw_buffer_load_lds:
   case Intrinsic::amdgcn_raw_ptr_buffer_load_lds:
@@ -1140,6 +1139,7 @@ bool SITargetLowering::getTgtMemIntrinsic(IntrinsicInfo 
,
   case Intrinsic::amdgcn_struct_ptr_buffer_load_lds: {
 unsigned Width = 
cast(CI.getArgOperand(2))->getZExtValue();
 Info.memVT = EVT::getIntegerVT(CI.getContext(), Width * 8);
+Info.ptrVal = CI.getArgOperand(1);
 return true;
   }
   }
@@ -1268,8 +1268,8 @@ bool SITargetLowering::getTgtMemIntrinsic(IntrinsicInfo 
,
 Info.opc = ISD::INTRINSIC_VOID;
 unsigned Width = cast(CI.getArgOperand(2))->getZExtValue();
 Info.memVT = EVT::getIntegerVT(CI.getContext(), Width * 8);
-Info.flags |= MachineMemOperand::MOLoad | MachineMemOperand::MOStore |
-  MachineMemOperand::MOVolatile;
+Info.ptrVal = CI.getArgOperand(1);
+Info.flags |= MachineMemOperand::MOLoad | MachineMemOperand::MOStore;
 return true;
   }
   case Intrinsic::amdgcn_ds_bvh_stack_rtn: {
@@ -9084,7 +9084,9 @@ SDValue SITargetLowering::LowerINTRINSIC_VOID(SDValue Op,
 MachinePointerInfo LoadPtrI = LoadMMO->getPointerInfo();
 
 MachinePointerInfo StorePtrI = LoadPtrI;
-StorePtrI.V = nullptr;
+LoadPtrI.V = UndefValue::get(
+PointerType::get(*DAG.getContext(), AMDGPUAS::GLOBAL_ADDRESS));
+LoadPtrI.AddrSpace = AMDGPUAS::GLOBAL_ADDRESS;
 StorePtrI.AddrSpace = AMDGPUAS::LOCAL_ADDRESS;
 
 auto F = LoadMMO->getFlags() &
@@ -9162,6 +9164,8 @@ SDValue SITargetLowering::LowerINTRINSIC_VOID(SDValue Op,
 MachinePointerInfo LoadPtrI = LoadMMO->getPointerInfo();
 LoadPtrI.Offset = Op->getConstantOperandVal(5);
 MachinePointerInfo StorePtrI = LoadPtrI;
+LoadPtrI.V = UndefValue::get(
+PointerType::get(*DAG.getContext(), AMDGPUAS::GLOBAL_ADDRESS));
 LoadPtrI.AddrSpace = AMDGPUAS::GLOBAL_ADDRESS;
 StorePtrI.AddrSpace = AMDGPUAS::LOCAL_ADDRESS;
 auto F = LoadMMO->getFlags() &
diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp 
b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index ede4841b8a5fd7..50ad22130e939e 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -31,6 +31,7 @@
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/Sequence.h"
+#include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/CodeGen/MachineLoopInfo.h"
 #include "llvm/CodeGen/MachinePostDominators.h"
 #include "llvm/InitializePasses.h"
@@ -121,8 +122,13 @@ enum RegisterMapping {
   SQ_MAX_PGM_VGPRS = 512, // Maximum programmable VGPRs across all targets.
   AGPR_OFFSET = 256,  // Maximum programmable ArchVGPRs across all targets.
   SQ_MAX_PGM_SGPRS = 256, // Maximum programmable SGPRs across all targets.
-  NUM_EXTRA_VGPRS = 1,// A reserved slot for DS.
-  EXTRA_VGPR_LDS = 0, // An artificial register to track LDS writes.
+  NUM_EXTRA_VGPRS = 9,// Reserved slots for DS.
+  // 

[lldb] [clang] [clang] Upstream XROS support in Clang (PR #78392)

2024-01-17 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 5aea6ba8f5f06e06887fe5c5c8740895907f6540 
868dd57be1d046d2f66823662bca10323aec05a3 -- clang/test/Driver/xros-driver.c 
clang/test/Frontend/xros-version.c 
lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleXR.cpp 
lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleXR.h 
clang/lib/Basic/Targets/OSTargets.h clang/lib/CodeGen/CGObjC.cpp 
clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
clang/lib/Driver/ToolChains/Arch/ARM.cpp clang/lib/Driver/ToolChains/Darwin.cpp 
clang/lib/Driver/ToolChains/Darwin.h 
clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp 
lldb/include/lldb/Utility/XcodeSDK.h 
lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp 
lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp 
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp 
lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.h
 lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp 
lldb/source/Utility/XcodeSDK.cpp lldb/tools/debugserver/source/RNBRemote.cpp 
lldb/unittests/Utility/XcodeSDKTest.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 4128ac1cdf..fff08408cd 100644
--- 
a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -167,7 +167,7 @@ DynamicLoader 
*DynamicLoaderDarwinKernel::CreateInstance(Process *process,
 case llvm::Triple::TvOS:
 case llvm::Triple::WatchOS:
 case llvm::Triple::XROS:
-// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
+  // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
   if (triple_ref.getVendor() != llvm::Triple::Apple) {
 return nullptr;
   }
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
index 2615925580..d337de9a68 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
@@ -56,7 +56,7 @@ DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process 
*process,
   case llvm::Triple::TvOS:
   case llvm::Triple::WatchOS:
   case llvm::Triple::XROS:
-  // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
+// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
 create = triple_ref.getVendor() == llvm::Triple::Apple;
 break;
   default:
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index 7e589b0d7a..f8412aa72b 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -76,7 +76,7 @@ DynamicLoader 
*DynamicLoaderMacOSXDYLD::CreateInstance(Process *process,
   case llvm::Triple::TvOS:
   case llvm::Triple::WatchOS:
   case llvm::Triple::XROS:
-  // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
+// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
 create = triple_ref.getVendor() == llvm::Triple::Apple;
 break;
   default:
diff --git a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp 
b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
index b652ede9b1..3423fbe223 100644
--- a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
+++ b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
@@ -831,7 +831,7 @@ uint32_t 
EmulateInstructionARM::GetFramePointerRegisterNumber() const {
   case llvm::Triple::TvOS:
   case llvm::Triple::WatchOS:
   case llvm::Triple::XROS:
-  // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
+// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
 is_apple = true;
 break;
   default:
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp 
b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
index a97e51cc7b..ba0f68e47e 100644
--- 

[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-01-17 Thread via cfe-commits

cor3ntin wrote:

@zygoloid Can you take another crack at this? If you have time to confirm the 
design maybe we could try to land it in Clang 18. Otherwise the plan is to be 
conservative. Thanks!

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


[lldb] [clang] [clang] Upstream XROS support in Clang (PR #78392)

2024-01-17 Thread Jonas Devlieghere via cfe-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/78392

>From 6f6d93b6cc413d54dbdec05f30ede00ffdb4 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Wed, 10 Jan 2024 17:35:47 -0800
Subject: [PATCH 1/2] [lldb] Upstream xros support in lldb

Upstream support for debugging xros applications through LLDB.
---
 lldb/include/lldb/Utility/XcodeSDK.h  |   2 +
 .../Host/macosx/objcxx/HostInfoMacOSX.mm  |   3 +
 .../DynamicLoaderDarwinKernel.cpp |   1 +
 .../MacOSX-DYLD/DynamicLoaderMacOS.cpp|   1 +
 .../MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp   |   1 +
 .../Instruction/ARM/EmulateInstructionARM.cpp |   1 +
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp |  11 +-
 .../Plugins/Platform/MacOSX/CMakeLists.txt|   1 +
 .../MacOSX/PlatformAppleSimulator.cpp |  37 +
 .../Platform/MacOSX/PlatformDarwin.cpp|  17 +-
 .../Platform/MacOSX/PlatformMacOSX.cpp|   3 +
 .../Platform/MacOSX/PlatformRemoteAppleXR.cpp | 157 ++
 .../Platform/MacOSX/PlatformRemoteAppleXR.h   |  38 +
 ...PlatformiOSSimulatorCoreSimulatorSupport.h |   3 +-
 .../Process/MacOSX-Kernel/ProcessKDP.cpp  |   1 +
 .../GDBRemoteCommunicationClient.cpp  |   3 +-
 .../MacOSX/SystemRuntimeMacOSX.cpp|   1 +
 lldb/source/Utility/XcodeSDK.cpp  |  23 +++
 .../debugserver/source/MacOSX/MachProcess.mm  |  12 ++
 lldb/tools/debugserver/source/RNBRemote.cpp   |  11 +-
 lldb/unittests/Utility/XcodeSDKTest.cpp   |  22 +++
 21 files changed, 340 insertions(+), 9 deletions(-)
 create mode 100644 
lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleXR.cpp
 create mode 100644 lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleXR.h

diff --git a/lldb/include/lldb/Utility/XcodeSDK.h 
b/lldb/include/lldb/Utility/XcodeSDK.h
index f8528995d549c9..673ea578ffce85 100644
--- a/lldb/include/lldb/Utility/XcodeSDK.h
+++ b/lldb/include/lldb/Utility/XcodeSDK.h
@@ -34,6 +34,8 @@ class XcodeSDK {
 AppleTVOS,
 WatchSimulator,
 watchOS,
+XRSimulator,
+XROS,
 bridgeOS,
 Linux,
 unknown = -1
diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm 
b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index 110a01732b2473..f96e2cf80c5fac 100644
--- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -276,6 +276,9 @@ static void ParseOSVersion(llvm::VersionTuple , 
NSString *Key) {
 #elif defined(TARGET_OS_WATCHOS) && TARGET_OS_WATCHOS == 1
 arch_32.GetTriple().setOS(llvm::Triple::WatchOS);
 arch_64.GetTriple().setOS(llvm::Triple::WatchOS);
+#elif defined(TARGET_OS_XR) && TARGET_OS_XR == 1
+arch_32.GetTriple().setOS(llvm::Triple::XROS);
+arch_64.GetTriple().setOS(llvm::Triple::XROS);
 #elif defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1
 arch_32.GetTriple().setOS(llvm::Triple::MacOSX);
 arch_64.GetTriple().setOS(llvm::Triple::MacOSX);
diff --git 
a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 7df917d03ceeda..4128ac1cdf1bba 100644
--- 
a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -166,6 +166,7 @@ DynamicLoader 
*DynamicLoaderDarwinKernel::CreateInstance(Process *process,
 case llvm::Triple::IOS:
 case llvm::Triple::TvOS:
 case llvm::Triple::WatchOS:
+case llvm::Triple::XROS:
 // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
   if (triple_ref.getVendor() != llvm::Triple::Apple) {
 return nullptr;
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
index 4451d8c7689a28..261592558095b4 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
@@ -55,6 +55,7 @@ DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process 
*process,
   case llvm::Triple::IOS:
   case llvm::Triple::TvOS:
   case llvm::Triple::WatchOS:
+  case llvm::Triple::XROS:
   // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
 create = triple_ref.getVendor() == llvm::Triple::Apple;
 break;
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index 0bd465aba2d8a2..7e589b0d7af2c7 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -75,6 +75,7 @@ DynamicLoader 
*DynamicLoaderMacOSXDYLD::CreateInstance(Process *process,
   case llvm::Triple::IOS:
   case llvm::Triple::TvOS:
   case 

[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread via cfe-commits

https://github.com/kelbon updated 
https://github.com/llvm/llvm-project/pull/78200

>From e8c799b54c3e0b8088dbc19aaac0ef066baf136e Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Mon, 15 Jan 2024 22:24:34 +0400
Subject: [PATCH 1/4] add warning and test

---
 clang/include/clang/Basic/DiagnosticGroups.td| 1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 7 +++
 clang/lib/Sema/SemaDecl.cpp  | 7 +++
 clang/test/Sema/incorrect_pure.cpp   | 7 +++
 4 files changed, 22 insertions(+)
 create mode 100644 clang/test/Sema/incorrect_pure.cpp

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..9fcf2be2e45458 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -414,6 +414,7 @@ def : DiagGroup<"c++2a-compat", [CXX20Compat]>;
 def : DiagGroup<"c++2a-compat-pedantic", [CXX20CompatPedantic]>;
 
 def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
+def IncorrectAttributeUsage : DiagGroup<"incorrect-attribute-usage">;
 def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
 def FourByteMultiChar : DiagGroup<"four-char-constants">;
 def GlobalConstructors : DiagGroup<"global-constructors"> {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 03b0122d1c08f7..1df075119a482f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -692,6 +692,13 @@ def warn_maybe_falloff_nonvoid_function : Warning<
 def warn_falloff_nonvoid_function : Warning<
   "non-void function does not return a value">,
   InGroup;
+def warn_pure_attr_on_cxx_constructor : Warning<
+  "constructor cannot be 'pure' (undefined behavior)">,
+  InGroup;
+def warn_pure_function_returns_void : Warning<
+  "'pure' attribute on function returning 'void'">,
+  InGroup;
+
 def err_maybe_falloff_nonvoid_block : Error<
   "non-void block does not return a value in all control paths">;
 def err_falloff_nonvoid_block : Error<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index dae98f3a7406e8..86dc022fbe055d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11899,6 +11899,13 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 NewFD->setInvalidDecl();
   }
 
+  if (NewFD->hasAttr() || NewFD->hasAttr()) {
+if (isa(NewFD))
+  Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
+else if (NewFD->getReturnType()->isVoidType())
+  Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);
+  }
+
   // C++11 [dcl.constexpr]p8:
   //   A constexpr specifier for a non-static member function that is not
   //   a constructor declares that member function to be const.
diff --git a/clang/test/Sema/incorrect_pure.cpp 
b/clang/test/Sema/incorrect_pure.cpp
new file mode 100644
index 00..ce02309f086386
--- /dev/null
+++ b/clang/test/Sema/incorrect_pure.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+[[gnu::pure]] void foo(); // expected-warning{{'pure' attribute on function 
returning 'void'}}
+
+struct A {
+[[gnu::pure]] A(); // expected-warning{{constructor cannot be 'pure' 
(undefined behavior)}}
+};

>From d152fa4881d6052bfad33c922f276d4909c305ec Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Tue, 16 Jan 2024 00:03:47 +0400
Subject: [PATCH 2/4] fix old incorrect test

---
 clang/test/Analysis/call-invalidation.cpp   | 8 
 clang/test/CodeGen/pragma-weak.c| 6 +++---
 clang/test/Interpreter/disambiguate-decl-stmt.cpp   | 4 ++--
 clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp | 2 +-
 clang/test/SemaCXX/warn-unused-value-cxx11.cpp  | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/clang/test/Analysis/call-invalidation.cpp 
b/clang/test/Analysis/call-invalidation.cpp
index ef6505e19cf803..727217f228b054 100644
--- a/clang/test/Analysis/call-invalidation.cpp
+++ b/clang/test/Analysis/call-invalidation.cpp
@@ -90,8 +90,8 @@ void testConstReferenceStruct() {
 }
 
 
-void usePointerPure(int * const *) __attribute__((pure));
-void usePointerConst(int * const *) __attribute__((const));
+int usePointerPure(int * const *) __attribute__((pure));
+int usePointerConst(int * const *) __attribute__((const));
 
 void testPureConst() {
   extern int global;
@@ -104,11 +104,11 @@ void testPureConst() {
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   clang_analyzer_eval(global == -5); // expected-warning{{TRUE}}
 
-  usePointerPure();
+  (void)usePointerPure();
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   clang_analyzer_eval(global == -5); // expected-warning{{TRUE}}
 
-  usePointerConst();
+  (void)usePointerConst();
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   

[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread Vlad Serebrennikov via cfe-commits

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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread Vlad Serebrennikov via cfe-commits

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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread Vlad Serebrennikov via cfe-commits


@@ -11792,6 +11792,32 @@ static bool CheckMultiVersionFunction(Sema , 
FunctionDecl *NewFD,
  OldDecl, Previous);
 }
 
+static void CheckFunctionDeclarationAttributesUsage(Sema ,
+FunctionDecl *NewFD) {
+  const bool is_pure = NewFD->hasAttr();
+  const bool is_const = NewFD->hasAttr();
+
+  if (is_pure && is_const) {
+S.Diag(NewFD->getLocation(), diag::warn_const_attr_with_pure_attr);
+NewFD->dropAttr();
+  }
+  if (is_pure || is_const) {
+if (isa(NewFD)) {

Endilll wrote:

I wonder if start of a lifetime and end of the lifetime that is tied to 
constructor and destructor can be considered side effects in this context, 
preventing them from ever being pure functions.

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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread via cfe-commits

https://github.com/kelbon updated 
https://github.com/llvm/llvm-project/pull/78200

>From e8c799b54c3e0b8088dbc19aaac0ef066baf136e Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Mon, 15 Jan 2024 22:24:34 +0400
Subject: [PATCH 1/3] add warning and test

---
 clang/include/clang/Basic/DiagnosticGroups.td| 1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 7 +++
 clang/lib/Sema/SemaDecl.cpp  | 7 +++
 clang/test/Sema/incorrect_pure.cpp   | 7 +++
 4 files changed, 22 insertions(+)
 create mode 100644 clang/test/Sema/incorrect_pure.cpp

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..9fcf2be2e45458 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -414,6 +414,7 @@ def : DiagGroup<"c++2a-compat", [CXX20Compat]>;
 def : DiagGroup<"c++2a-compat-pedantic", [CXX20CompatPedantic]>;
 
 def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
+def IncorrectAttributeUsage : DiagGroup<"incorrect-attribute-usage">;
 def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
 def FourByteMultiChar : DiagGroup<"four-char-constants">;
 def GlobalConstructors : DiagGroup<"global-constructors"> {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 03b0122d1c08f7..1df075119a482f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -692,6 +692,13 @@ def warn_maybe_falloff_nonvoid_function : Warning<
 def warn_falloff_nonvoid_function : Warning<
   "non-void function does not return a value">,
   InGroup;
+def warn_pure_attr_on_cxx_constructor : Warning<
+  "constructor cannot be 'pure' (undefined behavior)">,
+  InGroup;
+def warn_pure_function_returns_void : Warning<
+  "'pure' attribute on function returning 'void'">,
+  InGroup;
+
 def err_maybe_falloff_nonvoid_block : Error<
   "non-void block does not return a value in all control paths">;
 def err_falloff_nonvoid_block : Error<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index dae98f3a7406e8..86dc022fbe055d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11899,6 +11899,13 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 NewFD->setInvalidDecl();
   }
 
+  if (NewFD->hasAttr() || NewFD->hasAttr()) {
+if (isa(NewFD))
+  Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
+else if (NewFD->getReturnType()->isVoidType())
+  Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);
+  }
+
   // C++11 [dcl.constexpr]p8:
   //   A constexpr specifier for a non-static member function that is not
   //   a constructor declares that member function to be const.
diff --git a/clang/test/Sema/incorrect_pure.cpp 
b/clang/test/Sema/incorrect_pure.cpp
new file mode 100644
index 00..ce02309f086386
--- /dev/null
+++ b/clang/test/Sema/incorrect_pure.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+[[gnu::pure]] void foo(); // expected-warning{{'pure' attribute on function 
returning 'void'}}
+
+struct A {
+[[gnu::pure]] A(); // expected-warning{{constructor cannot be 'pure' 
(undefined behavior)}}
+};

>From d152fa4881d6052bfad33c922f276d4909c305ec Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Tue, 16 Jan 2024 00:03:47 +0400
Subject: [PATCH 2/3] fix old incorrect test

---
 clang/test/Analysis/call-invalidation.cpp   | 8 
 clang/test/CodeGen/pragma-weak.c| 6 +++---
 clang/test/Interpreter/disambiguate-decl-stmt.cpp   | 4 ++--
 clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp | 2 +-
 clang/test/SemaCXX/warn-unused-value-cxx11.cpp  | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/clang/test/Analysis/call-invalidation.cpp 
b/clang/test/Analysis/call-invalidation.cpp
index ef6505e19cf803..727217f228b054 100644
--- a/clang/test/Analysis/call-invalidation.cpp
+++ b/clang/test/Analysis/call-invalidation.cpp
@@ -90,8 +90,8 @@ void testConstReferenceStruct() {
 }
 
 
-void usePointerPure(int * const *) __attribute__((pure));
-void usePointerConst(int * const *) __attribute__((const));
+int usePointerPure(int * const *) __attribute__((pure));
+int usePointerConst(int * const *) __attribute__((const));
 
 void testPureConst() {
   extern int global;
@@ -104,11 +104,11 @@ void testPureConst() {
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   clang_analyzer_eval(global == -5); // expected-warning{{TRUE}}
 
-  usePointerPure();
+  (void)usePointerPure();
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   clang_analyzer_eval(global == -5); // expected-warning{{TRUE}}
 
-  usePointerConst();
+  (void)usePointerConst();
   clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
   

[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

2024-01-17 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

Thanks for the patch!

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


[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

2024-01-17 Thread Ilya Biryukov via cfe-commits


@@ -15841,13 +15841,24 @@ static void diagnoseImplicitlyRetainedSelf(Sema ) {
   << FixItHint::CreateInsertion(P.first, "self->");
 }
 
+bool Sema::IsGetReturnObject(const FunctionDecl *FD) {
+  return isa(FD) && FD->param_empty() &&

ilya-biryukov wrote:

NIT: maybe share the code between two functions? 
I am also not sure whether `isa()` should also be added to the 
other check (aren't static functions also instances of `CXXMethodDecl`?)

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


[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

2024-01-17 Thread Ilya Biryukov via cfe-commits


@@ -11220,6 +11220,11 @@ class Sema final {
   VarDecl *buildCoroutinePromise(SourceLocation Loc);
   void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *);
 
+  // Heuristically tells if the function is get_return_object by matching

ilya-biryukov wrote:

I think it's useful to mention that `get_return_object` is coming from the 
coroutine's `promise_type` as defined by the C++ standard. (I think it might 
not be obvious).

Also, could we change the name to something like `CanBeReturnObject` to clearly 
indicate it's a heuristic to the users.



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


[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

2024-01-17 Thread Ilya Biryukov via cfe-commits

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


[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

2024-01-17 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov approved this pull request.

I'm ok with the changes, but I left a suggestion about naming the function that 
I think we should follow.

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


[clang] [libclang/python] Expose Rewriter to the python binding (PR #77269)

2024-01-17 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

Looks good overall.
It's good that you wrote your own tests, but it would also be nice to mirror 
tests in `clang/unittests/libclang/LibclangTest.cpp` which test the same API. 
This way we can identify issues in binding layer itself (when C++ tests pass, 
but Python tests don't, or vise versa,)

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


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2024-01-17 Thread Zixu Wang via cfe-commits

zixu-w wrote:

> > It looks like this breaks building at least `MultiSource` from 
> > https://github.com/llvm/llvm-test-suite/. The first failure I see is when 
> > building `llvm-test-suite/MultiSource/Applications/ClamAV/zlib_zutil.c`
> > ```
> > In file included from 
> > /llvm-test-suite/MultiSource/Applications/ClamAV/zlib_zutil.c:10:
> > In file included from 
> > test-suites/llvm-test-suite/MultiSource/Applications/ClamAV/zlib/gzguts.h:21:
> > ../usr/include/stdio.h:220:7: error: expected identifier or '('
> >   220 | FILE*fdopen(int, const char *) 
> > __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fdopen));
> >   |  ^
> > llvm-test-suite/MultiSource/Applications/ClamAV/zlib/zutil.h:140:33: note: 
> > expanded from macro 'fdopen'
> >   140 | #define fdopen(fd,mode) NULL /* No fdopen() */
> >   | ^
> > llvm-project/builds/release-with-assertions/ccache-stage1/lib/clang/18/include/__stddef_null.h:26:16:
> >  note: expanded from macro 'NULL'
> >26 | #define NULL ((void*)0)
> >   |^
> > ```
> 
> These are actually part of zlib, so apart from llvm test suite having been 
> broken by this (but was fixed), plain zlib has been broken too (although 
> arguably, zlib is where the real issue is).

We have provided a fix for zlib (https://github.com/madler/zlib/pull/895) which 
was accepted by @madler.

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


[clang] [Clang] Support MSPropertyRefExpr as placement arg to new-expression (PR #75883)

2024-01-17 Thread via cfe-commits

Sirraide wrote:

> I'll commit it when I see the CI done, and can do the release notes conflict. 
> I wont bother re-running after conflict resolution.

Alright, thanks!

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


[clang] [Clang] Support MSPropertyRefExpr as placement arg to new-expression (PR #75883)

2024-01-17 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > Nope! Once the CI is done, feel free to Squash & Merge.
> 
> I would but I don’t have commit access, so someone else would have to do that 
> for me. (Also, I do fear that in the time it takes for the CI jobs to 
> complete, we’ll have another merge conflict w/ the release notes because 
> they’re updated constantly.)

I'll commit it when I see the CI done, and can do the release notes conflict.  
I wont bother re-running after conflict resolution.

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


[clang] [Clang] Support MSPropertyRefExpr as placement arg to new-expression (PR #75883)

2024-01-17 Thread via cfe-commits

Sirraide wrote:

> Nope! Once the CI is done, feel free to Squash & Merge.

I would but I don’t have commit access, so someone else would have to do that 
for me. (Also, I do fear that in the time it takes for the CI jobs to complete, 
we’ll have another merge conflict w/ the release notes because they’re updated 
constantly.)

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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread via cfe-commits

https://github.com/kelbon updated 
https://github.com/llvm/llvm-project/pull/78200

>From b080d04eb30254502ccd5d59d76b5197db1fa88d Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Mon, 15 Jan 2024 22:24:34 +0400
Subject: [PATCH 01/11] add warning and test

---
 clang/include/clang/Basic/DiagnosticGroups.td| 1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 7 +++
 clang/lib/Sema/SemaDecl.cpp  | 7 +++
 clang/test/Sema/incorrect_pure.cpp   | 7 +++
 4 files changed, 22 insertions(+)
 create mode 100644 clang/test/Sema/incorrect_pure.cpp

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..9fcf2be2e45458 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -414,6 +414,7 @@ def : DiagGroup<"c++2a-compat", [CXX20Compat]>;
 def : DiagGroup<"c++2a-compat-pedantic", [CXX20CompatPedantic]>;
 
 def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
+def IncorrectAttributeUsage : DiagGroup<"incorrect-attribute-usage">;
 def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
 def FourByteMultiChar : DiagGroup<"four-char-constants">;
 def GlobalConstructors : DiagGroup<"global-constructors"> {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 414779a7970ab8..0ad3ea64503d81 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -692,6 +692,13 @@ def warn_maybe_falloff_nonvoid_function : Warning<
 def warn_falloff_nonvoid_function : Warning<
   "non-void function does not return a value">,
   InGroup;
+def warn_pure_attr_on_cxx_constructor : Warning<
+  "constructor cannot be 'pure' (undefined behavior)">,
+  InGroup;
+def warn_pure_function_returns_void : Warning<
+  "'pure' attribute on function returning 'void'">,
+  InGroup;
+
 def err_maybe_falloff_nonvoid_block : Error<
   "non-void block does not return a value in all control paths">;
 def err_falloff_nonvoid_block : Error<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4e7049571eeb7a..e340028703b3b3 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11889,6 +11889,13 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 NewFD->setInvalidDecl();
   }
 
+  if (NewFD->hasAttr() || NewFD->hasAttr()) {
+if (isa_and_nonnull(NewFD))
+  Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
+else if (NewFD->getReturnType()->isVoidType())
+  Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);
+  }
+
   // C++11 [dcl.constexpr]p8:
   //   A constexpr specifier for a non-static member function that is not
   //   a constructor declares that member function to be const.
diff --git a/clang/test/Sema/incorrect_pure.cpp 
b/clang/test/Sema/incorrect_pure.cpp
new file mode 100644
index 00..ce02309f086386
--- /dev/null
+++ b/clang/test/Sema/incorrect_pure.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+[[gnu::pure]] void foo(); // expected-warning{{'pure' attribute on function 
returning 'void'}}
+
+struct A {
+[[gnu::pure]] A(); // expected-warning{{constructor cannot be 'pure' 
(undefined behavior)}}
+};

>From d43afccb027ea0e02c97ab9fbe55a1ad6c9d71dd Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Mon, 15 Jan 2024 22:52:23 +0400
Subject: [PATCH 02/11] use precondition: NewFD is not null

---
 clang/lib/Sema/SemaDecl.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e340028703b3b3..dcbc5c3c842cca 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11890,7 +11890,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   }
 
   if (NewFD->hasAttr() || NewFD->hasAttr()) {
-if (isa_and_nonnull(NewFD))
+if (isa(NewFD))
   Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
 else if (NewFD->getReturnType()->isVoidType())
   Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);

>From 950ca9de1c05d561a1123c088455a3e21bd9795b Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Tue, 16 Jan 2024 00:03:47 +0400
Subject: [PATCH 03/11] fix old incorrect test

---
 clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp 
b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
index 9d68a0e5d358f6..6ae146f0d08c7d 100644
--- a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
+++ b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
@@ -194,7 +194,7 @@ struct except_spec_d_match : except_spec_a, except_spec_b {
 // gcc-compatibility: allow attributes on default definitions
 // (but not normal 

[clang-tools-extra] [lldb] [libc] [libcxx] [clang] [compiler-rt] [lld] [flang] [llvm] [AMDGPU] Use alias info to relax waitcounts for LDS DMA (PR #74537)

2024-01-17 Thread Stanislav Mekhanoshin via cfe-commits

rampitec wrote:

> lgtm, but can still fix the -O0 thing

But where do I get TM in the getAnalysisUsage?

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


[clang-tools-extra] [lldb] [libc] [libcxx] [clang] [compiler-rt] [lld] [flang] [llvm] [AMDGPU] Use alias info to relax waitcounts for LDS DMA (PR #74537)

2024-01-17 Thread Stanislav Mekhanoshin via cfe-commits


@@ -707,7 +723,40 @@ void WaitcntBrackets::updateByEvent(const SIInstrInfo *TII,
 (TII->isDS(Inst) || TII->mayWriteLDSThroughDMA(Inst))) {
   // MUBUF and FLAT LDS DMA operations need a wait on vmcnt before LDS
   // written can be accessed. A load from LDS to VMEM does not need a wait.
-  setRegScore(SQ_MAX_PGM_VGPRS + EXTRA_VGPR_LDS, T, CurrScore);
+  unsigned Slot = 0;
+  for (const auto *MemOp : Inst.memoperands()) {
+if (!MemOp->isStore() ||
+MemOp->getAddrSpace() != AMDGPUAS::LOCAL_ADDRESS)
+  continue;
+// Comparing just AA info does not guarantee memoperands are equal
+// in general, but this is so for LDS DMA in practice.
+auto AAI = MemOp->getAAInfo();
+// Alias scope information gives a way to definitely identify an
+// original memory object and practically produced in the module LDS
+// lowering pass. If there is no scope available we will not be able
+// to disambiguate LDS aliasing as after the module lowering all LDS
+// is squashed into a single big object. Do not attemt to use one of

rampitec wrote:

Done

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


[libcxx] [compiler-rt] [clang] [clang-tools-extra] [libc] [flang] [lldb] [lld] [llvm] [AMDGPU] Use alias info to relax waitcounts for LDS DMA (PR #74537)

2024-01-17 Thread Stanislav Mekhanoshin via cfe-commits

https://github.com/rampitec updated 
https://github.com/llvm/llvm-project/pull/74537

>From 7e382620cdc5999c645ed0746f242595f0294c58 Mon Sep 17 00:00:00 2001
From: Stanislav Mekhanoshin 
Date: Mon, 4 Dec 2023 16:11:53 -0800
Subject: [PATCH 01/12] [AMDGPU] Use alias info to relax waitcounts for LDS DMA

LDA DMA loads increase VMCNT and a load from the LDS stored must
wait on this counter to only read memory after it is written.
Wait count insertion pass does not track memory dependencies, it
tracks register dependencies. To model the LDS dependency a
psuedo register is used in the scoreboard, acting like if LDS DMA
writes it and LDS load reads it.

This patch adds 8 more pseudo registers to use for independent LDS
locations if we can prove they are disjoint using alias analysis.

Fixes: SWDEV-433427
---
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp   |  16 +-
 llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp |  73 +-
 llvm/lib/Target/AMDGPU/SIInstrInfo.cpp  |   4 +-
 llvm/lib/Target/AMDGPU/SIInstrInfo.h|   8 +
 llvm/lib/Target/AMDGPU/lds-dma-waits.ll | 154 
 llvm/test/CodeGen/AMDGPU/llc-pipeline.ll|   2 +
 6 files changed, 241 insertions(+), 16 deletions(-)
 create mode 100644 llvm/lib/Target/AMDGPU/lds-dma-waits.ll

diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index a7f4d63229b7ef..2e079404b087fa 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -1128,11 +1128,10 @@ bool SITargetLowering::getTgtMemIntrinsic(IntrinsicInfo 
,
 MachineMemOperand::MOStore |
 MachineMemOperand::MODereferenceable;
 
-  // XXX - Should this be volatile without known ordering?
-  Info.flags |= MachineMemOperand::MOVolatile;
-
   switch (IntrID) {
   default:
+// XXX - Should this be volatile without known ordering?
+Info.flags |= MachineMemOperand::MOVolatile;
 break;
   case Intrinsic::amdgcn_raw_buffer_load_lds:
   case Intrinsic::amdgcn_raw_ptr_buffer_load_lds:
@@ -1140,6 +1139,7 @@ bool SITargetLowering::getTgtMemIntrinsic(IntrinsicInfo 
,
   case Intrinsic::amdgcn_struct_ptr_buffer_load_lds: {
 unsigned Width = 
cast(CI.getArgOperand(2))->getZExtValue();
 Info.memVT = EVT::getIntegerVT(CI.getContext(), Width * 8);
+Info.ptrVal = CI.getArgOperand(1);
 return true;
   }
   }
@@ -1268,8 +1268,8 @@ bool SITargetLowering::getTgtMemIntrinsic(IntrinsicInfo 
,
 Info.opc = ISD::INTRINSIC_VOID;
 unsigned Width = cast(CI.getArgOperand(2))->getZExtValue();
 Info.memVT = EVT::getIntegerVT(CI.getContext(), Width * 8);
-Info.flags |= MachineMemOperand::MOLoad | MachineMemOperand::MOStore |
-  MachineMemOperand::MOVolatile;
+Info.ptrVal = CI.getArgOperand(1);
+Info.flags |= MachineMemOperand::MOLoad | MachineMemOperand::MOStore;
 return true;
   }
   case Intrinsic::amdgcn_ds_bvh_stack_rtn: {
@@ -9084,7 +9084,9 @@ SDValue SITargetLowering::LowerINTRINSIC_VOID(SDValue Op,
 MachinePointerInfo LoadPtrI = LoadMMO->getPointerInfo();
 
 MachinePointerInfo StorePtrI = LoadPtrI;
-StorePtrI.V = nullptr;
+LoadPtrI.V = UndefValue::get(
+PointerType::get(*DAG.getContext(), AMDGPUAS::GLOBAL_ADDRESS));
+LoadPtrI.AddrSpace = AMDGPUAS::GLOBAL_ADDRESS;
 StorePtrI.AddrSpace = AMDGPUAS::LOCAL_ADDRESS;
 
 auto F = LoadMMO->getFlags() &
@@ -9162,6 +9164,8 @@ SDValue SITargetLowering::LowerINTRINSIC_VOID(SDValue Op,
 MachinePointerInfo LoadPtrI = LoadMMO->getPointerInfo();
 LoadPtrI.Offset = Op->getConstantOperandVal(5);
 MachinePointerInfo StorePtrI = LoadPtrI;
+LoadPtrI.V = UndefValue::get(
+PointerType::get(*DAG.getContext(), AMDGPUAS::GLOBAL_ADDRESS));
 LoadPtrI.AddrSpace = AMDGPUAS::GLOBAL_ADDRESS;
 StorePtrI.AddrSpace = AMDGPUAS::LOCAL_ADDRESS;
 auto F = LoadMMO->getFlags() &
diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp 
b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index ede4841b8a5fd7..50ad22130e939e 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -31,6 +31,7 @@
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/Sequence.h"
+#include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/CodeGen/MachineLoopInfo.h"
 #include "llvm/CodeGen/MachinePostDominators.h"
 #include "llvm/InitializePasses.h"
@@ -121,8 +122,13 @@ enum RegisterMapping {
   SQ_MAX_PGM_VGPRS = 512, // Maximum programmable VGPRs across all targets.
   AGPR_OFFSET = 256,  // Maximum programmable ArchVGPRs across all targets.
   SQ_MAX_PGM_SGPRS = 256, // Maximum programmable SGPRs across all targets.
-  NUM_EXTRA_VGPRS = 1,// A reserved slot for DS.
-  EXTRA_VGPR_LDS = 0, // An artificial register to track LDS writes.
+  NUM_EXTRA_VGPRS = 9,// Reserved slots for DS.
+  // 

[clang] d525e2b - [Headers][X86] Add more descriptions to ia32intrin.h and immintrin.h (#77686)

2024-01-17 Thread via cfe-commits

Author: Paul T Robinson
Date: 2024-01-17T09:31:15-08:00
New Revision: d525e2b31b999fb2c989fb0986332066466c61c7

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

LOG: [Headers][X86] Add more descriptions to ia32intrin.h and immintrin.h 
(#77686)

ia32intrin.h gets descriptions for all remaining non-privileged
intrinsic functions; the macros providing alternate names are not
described. immintrin.h ditto, except for the InterlockedExchange
functions.

Added: 


Modified: 
clang/lib/Headers/ia32intrin.h
clang/lib/Headers/immintrin.h

Removed: 




diff  --git a/clang/lib/Headers/ia32intrin.h b/clang/lib/Headers/ia32intrin.h
index a8b59dfaad89801..7d5fede61ce8590 100644
--- a/clang/lib/Headers/ia32intrin.h
+++ b/clang/lib/Headers/ia32intrin.h
@@ -58,7 +58,7 @@ __bsrd(int __A) {
   return 31 - __builtin_clz((unsigned int)__A);
 }
 
-/// Swaps the bytes in the input. Converting little endian to big endian or
+/// Swaps the bytes in the input, converting little endian to big endian or
 ///vice versa.
 ///
 /// \headerfile 
@@ -73,6 +73,16 @@ __bswapd(int __A) {
   return (int)__builtin_bswap32((unsigned int)__A);
 }
 
+/// Swaps the bytes in the input, converting little endian to big endian or
+///vice versa.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c BSWAP instruction.
+///
+/// \param __A
+///A 32-bit integer operand.
+/// \returns A 32-bit integer containing the swapped bytes.
 static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
 _bswap(int __A) {
   return (int)__builtin_bswap32((unsigned int)__A);
@@ -173,12 +183,29 @@ __popcntq(unsigned long long __A)
 #endif /* __x86_64__ */
 
 #ifdef __x86_64__
+/// Returns the program status and control \c RFLAGS register with the \c VM
+///and \c RF flags cleared.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c PUSHFQ + \c POP instruction sequence.
+///
+/// \returns The 64-bit value of the RFLAGS register.
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
 __readeflags(void)
 {
   return __builtin_ia32_readeflags_u64();
 }
 
+/// Writes the specified value to the program status and control \c RFLAGS
+///register. Reserved bits are not affected.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c PUSH + \c POPFQ instruction sequence.
+///
+/// \param __f
+///The 64-bit value to write to \c RFLAGS.
 static __inline__ void __DEFAULT_FN_ATTRS
 __writeeflags(unsigned long long __f)
 {
@@ -186,12 +213,29 @@ __writeeflags(unsigned long long __f)
 }
 
 #else /* !__x86_64__ */
+/// Returns the program status and control \c EFLAGS register with the \c VM
+///and \c RF flags cleared.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c PUSHFD + \c POP instruction sequence.
+///
+/// \returns The 32-bit value of the EFLAGS register.
 static __inline__ unsigned int __DEFAULT_FN_ATTRS
 __readeflags(void)
 {
   return __builtin_ia32_readeflags_u32();
 }
 
+/// Writes the specified value to the program status and control \c EFLAGS
+///register. Reserved bits are not affected.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c PUSH + \c POPFD instruction sequence.
+///
+/// \param __f
+///The 32-bit value to write to \c EFLAGS.
 static __inline__ void __DEFAULT_FN_ATTRS
 __writeeflags(unsigned int __f)
 {
@@ -341,12 +385,32 @@ __crc32q(unsigned long long __C, unsigned long long __D)
 }
 #endif /* __x86_64__ */
 
+/// Reads the specified performance monitoring counter. Refer to your
+///processor's documentation to determine which performance counters are
+///supported.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c RDPMC instruction.
+///
+/// \param __A
+///The performance counter to read.
+/// \returns The 64-bit value read from the performance counter.
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
 __rdpmc(int __A) {
   return __builtin_ia32_rdpmc(__A);
 }
 
-/* __rdtscp */
+/// Reads the processor's time stamp counter and the \c IA32_TSC_AUX MSR
+///\c (0xc103).
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c RDTSCP instruction.
+///
+/// \param __A
+///Address of where to store the 32-bit \c IA32_TSC_AUX value.
+/// \returns The 64-bit value of the time stamp counter.
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
 __rdtscp(unsigned int *__A) {
   return __builtin_ia32_rdtscp(__A);
@@ -361,42 +425,146 @@ _wbinvd(void) {
   __builtin_ia32_wbinvd();
 }
 
+/// Rotates an 8-bit value to the left by the specified number of bits.
+///This operation is undefined if the number of bits exceeds the size of
+///the value.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c ROL instruction.
+///
+/// 

[clang] [Headers][X86] Add more descriptions to ia32intrin.h and immintrin.h (PR #77686)

2024-01-17 Thread Paul T Robinson via cfe-commits

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


[clang] Add Variadic 'dropAttrs' (PR #78476)

2024-01-17 Thread Aaron Ballman via cfe-commits

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

LGTM, that's a nice, easy change!

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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread Aaron Ballman via cfe-commits


@@ -11792,6 +11792,26 @@ static bool CheckMultiVersionFunction(Sema , 
FunctionDecl *NewFD,
  OldDecl, Previous);
 }
 
+static void CheckFunctionDeclarationAttributesUsage(Sema ,
+FunctionDecl *NewFD) {
+  bool IsPure = NewFD->hasAttr();
+  bool IsConst = NewFD->hasAttr();
+
+  if (IsPure && IsConst) {
+S.Diag(NewFD->getLocation(), diag::warn_const_attr_with_pure_attr);
+NewFD->dropAttr();
+  }
+  if (IsPure || IsConst) {
+// constructors and destructors also functions which returns void
+if (NewFD->getReturnType()->isVoidType()) {
+  S.Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void)
+  << IsConst;
+  NewFD->dropAttr();
+  NewFD->dropAttr();

AaronBallman wrote:

Ah shoot, you're right

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


[clang] Add Variadic 'dropAttrs' (PR #78476)

2024-01-17 Thread Aaron Ballman via cfe-commits

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


[clang] Add Variadic 'dropAttrs' (PR #78476)

2024-01-17 Thread Aaron Ballman via cfe-commits


@@ -7068,8 +7068,7 @@ static void checkAttributesAfterMerging(Sema , 
NamedDecl ) {
   if (WeakRefAttr *Attr = ND.getAttr()) {
 if (ND.isExternallyVisible()) {
   S.Diag(Attr->getLocation(), diag::err_attribute_weakref_not_static);
-  ND.dropAttr();
-  ND.dropAttr();
+  ND.dropAttrs();

AaronBallman wrote:

There are more instances you can modify in this file:

https://github.com/llvm/llvm-project/blob/a96b4671b97b167230986bd2811676064c608596/clang/lib/Sema/SemaDecl.cpp#L7264

https://github.com/llvm/llvm-project/blob/a96b4671b97b167230986bd2811676064c608596/clang/lib/Sema/SemaDecl.cpp#L7270

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


[clang] [clang-tools-extra] [Clang][NFC] Rename CXXMethodDecl::isPure -> is VirtualPure (PR #78463)

2024-01-17 Thread Erich Keane via cfe-commits

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


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


[clang] Add Variadic 'dropAttrs' (PR #78476)

2024-01-17 Thread Erich Keane via cfe-commits

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/78476

>From 6790e56b001a29e8bba012514eb3b12cd486d505 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Wed, 17 Jan 2024 09:03:14 -0800
Subject: [PATCH 1/2] Add Variadic 'dropAttrs'

As suggested in https://github.com/llvm/llvm-project/pull/78200

This adds a variadic 'dropAttrs', which drops all attributes of any of
the types specified.
---
 clang/include/clang/AST/DeclBase.h | 11 ---
 clang/lib/Sema/SemaDecl.cpp|  3 +--
 clang/lib/Sema/SemaDeclCXX.cpp |  3 +--
 clang/lib/Sema/SemaTemplate.cpp|  6 ++
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 5b1038582bc674..933249b4a1a05e 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -548,17 +548,22 @@ class alignas(8) Decl {
 return hasAttrs() ? getAttrs().end() : nullptr;
   }
 
-  template 
-  void dropAttr() {
+  template
+  void dropAttrs() {
 if (!HasAttrs) return;
 
 AttrVec  = getAttrs();
-llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
+llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
 if (Vec.empty())
   HasAttrs = false;
   }
 
+  template 
+  void dropAttr() {
+dropAttrs();
+  }
+
   template 
   llvm::iterator_range> specific_attrs() const {
 return llvm::make_range(specific_attr_begin(), specific_attr_end());
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index dae98f3a7406e8..5472b43aafd4f3 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7068,8 +7068,7 @@ static void checkAttributesAfterMerging(Sema , 
NamedDecl ) {
   if (WeakRefAttr *Attr = ND.getAttr()) {
 if (ND.isExternallyVisible()) {
   S.Diag(Attr->getLocation(), diag::err_attribute_weakref_not_static);
-  ND.dropAttr();
-  ND.dropAttr();
+  ND.dropAttrs();
 }
   }
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a2ce96188b4f16..62dc623d5af378 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -6545,8 +6545,7 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl 
*Class) {
   if ((Context.getTargetInfo().getCXXABI().isMicrosoft() ||
Context.getTargetInfo().getTriple().isPS()) &&
   (!Class->isExternallyVisible() && Class->hasExternalFormalLinkage())) {
-Class->dropAttr();
-Class->dropAttr();
+Class->dropAttrs();
 return;
   }
 
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c0dcbda1fd6221..b5be596b7dff32 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -9229,10 +9229,8 @@ void Sema::CheckConceptRedefinition(ConceptDecl *NewDecl,
 /// that has just been explicitly specialized.
 static void StripImplicitInstantiation(NamedDecl *D, bool MinGW) {
   if (MinGW || (isa(D) &&
-cast(D)->isFunctionTemplateSpecialization())) {
-D->dropAttr();
-D->dropAttr();
-  }
+cast(D)->isFunctionTemplateSpecialization()))
+D->dropAttrs< DLLImportAttr, DLLExportAttr>();
 
   if (FunctionDecl *FD = dyn_cast(D))
 FD->setInlineSpecified(false);

>From 52053f3b2cf01ddc1706e84e6e1fd9fdc3c9e966 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Wed, 17 Jan 2024 09:11:00 -0800
Subject: [PATCH 2/2] fix clang-format

---
 clang/include/clang/AST/DeclBase.h | 8 ++--
 clang/lib/Sema/SemaTemplate.cpp| 2 +-
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 933249b4a1a05e..d957ea24f6394a 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -548,8 +548,7 @@ class alignas(8) Decl {
 return hasAttrs() ? getAttrs().end() : nullptr;
   }
 
-  template
-  void dropAttrs() {
+  template  void dropAttrs() {
 if (!HasAttrs) return;
 
 AttrVec  = getAttrs();
@@ -559,10 +558,7 @@ class alignas(8) Decl {
   HasAttrs = false;
   }
 
-  template 
-  void dropAttr() {
-dropAttrs();
-  }
+  template  void dropAttr() { dropAttrs(); }
 
   template 
   llvm::iterator_range> specific_attrs() const {
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index b5be596b7dff32..0655d363352067 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -9230,7 +9230,7 @@ void Sema::CheckConceptRedefinition(ConceptDecl *NewDecl,
 static void StripImplicitInstantiation(NamedDecl *D, bool MinGW) {
   if (MinGW || (isa(D) &&
 cast(D)->isFunctionTemplateSpecialization()))
-D->dropAttrs< DLLImportAttr, DLLExportAttr>();
+D->dropAttrs();
 
   if (FunctionDecl *FD = dyn_cast(D))
 FD->setInlineSpecified(false);

___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] Add Variadic 'dropAttrs' (PR #78476)

2024-01-17 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 2cd013a7869a341a6536324c34f0c4e68bf01a38 
6790e56b001a29e8bba012514eb3b12cd486d505 -- clang/include/clang/AST/DeclBase.h 
clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp 
clang/lib/Sema/SemaTemplate.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 933249b4a1..d957ea24f6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -548,8 +548,7 @@ public:
 return hasAttrs() ? getAttrs().end() : nullptr;
   }
 
-  template
-  void dropAttrs() {
+  template  void dropAttrs() {
 if (!HasAttrs) return;
 
 AttrVec  = getAttrs();
@@ -559,10 +558,7 @@ public:
   HasAttrs = false;
   }
 
-  template 
-  void dropAttr() {
-dropAttrs();
-  }
+  template  void dropAttr() { dropAttrs(); }
 
   template 
   llvm::iterator_range> specific_attrs() const {
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index b5be596b7d..0655d36335 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -9230,7 +9230,7 @@ void Sema::CheckConceptRedefinition(ConceptDecl *NewDecl,
 static void StripImplicitInstantiation(NamedDecl *D, bool MinGW) {
   if (MinGW || (isa(D) &&
 cast(D)->isFunctionTemplateSpecialization()))
-D->dropAttrs< DLLImportAttr, DLLExportAttr>();
+D->dropAttrs();
 
   if (FunctionDecl *FD = dyn_cast(D))
 FD->setInlineSpecified(false);

``




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


[clang] [clang-tools-extra] [Clang][NFC] Rename CXXMethodDecl::isPure -> is VirtualPure (PR #78463)

2024-01-17 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/78463

>From 95545827ee940b962540b1bc7e23baea714f915e Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 17 Jan 2024 17:28:38 +0100
Subject: [PATCH] [Clang][NFC] Rename CXXMethodDecl::isPure -> isPureVirtual

To avoid any possible confusion with the notion of pure
function and the gnu::pure attribute.
---
 .../fuchsia/MultipleInheritanceCheck.cpp   |  6 +++---
 .../modernize/UseEqualsDeleteCheck.cpp |  5 +++--
 .../clangd/SemanticHighlighting.cpp|  2 +-
 clang-tools-extra/clangd/XRefs.cpp |  2 +-
 clang/include/clang/AST/Decl.h |  4 ++--
 clang/include/clang/AST/DeclBase.h |  2 +-
 clang/include/clang/AST/DeclCXX.h  |  4 ++--
 clang/include/clang/ASTMatchers/ASTMatchers.h  |  4 +---
 clang/lib/AST/ASTImporter.cpp  |  2 +-
 clang/lib/AST/ASTStructuralEquivalence.cpp |  2 +-
 clang/lib/AST/Decl.cpp |  6 +++---
 clang/lib/AST/DeclCXX.cpp  |  6 +++---
 clang/lib/AST/DeclPrinter.cpp  |  2 +-
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/lib/AST/Interp/Interp.cpp|  2 +-
 clang/lib/AST/JSONNodeDumper.cpp   |  2 +-
 clang/lib/AST/ODRDiagsEmitter.cpp  |  4 ++--
 clang/lib/AST/ODRHash.cpp  |  2 +-
 clang/lib/AST/RecordLayoutBuilder.cpp  |  4 ++--
 clang/lib/AST/TextNodeDumper.cpp   |  2 +-
 clang/lib/AST/VTableBuilder.cpp| 18 +-
 clang/lib/CodeGen/CGDebugInfo.cpp  |  2 +-
 clang/lib/CodeGen/CGVTables.cpp|  2 +-
 clang/lib/Sema/Sema.cpp|  2 +-
 clang/lib/Sema/SemaDecl.cpp|  9 +
 clang/lib/Sema/SemaDeclCXX.cpp |  9 +
 clang/lib/Sema/SemaExpr.cpp|  2 +-
 clang/lib/Sema/SemaOverload.cpp|  2 +-
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  2 +-
 clang/lib/Serialization/ASTReaderDecl.cpp  |  2 +-
 clang/lib/Serialization/ASTWriterDecl.cpp  |  2 +-
 .../Checkers/VirtualCallChecker.cpp|  2 +-
 clang/tools/libclang/CIndex.cpp|  2 +-
 33 files changed, 61 insertions(+), 60 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp 
b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
index 8aecd3ba27b2e3c..b5ce23ae8feda29 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -53,7 +53,7 @@ bool MultipleInheritanceCheck::isCurrentClassInterface(
 
   // Interfaces should have exclusively pure methods.
   return llvm::none_of(Node->methods(), [](const CXXMethodDecl *M) {
-return M->isUserProvided() && !M->isPure() && !M->isStatic();
+return M->isUserProvided() && !M->isPureVirtual() && !M->isStatic();
   });
 }
 
@@ -103,8 +103,8 @@ void MultipleInheritanceCheck::check(const 
MatchFinder::MatchResult ) {
   const auto *Base = cast(Ty->getDecl()->getDefinition());
   if (!isInterface(Base)) NumConcrete++;
 }
-
-// Check virtual bases to see if there is more than one concrete 
+
+// Check virtual bases to see if there is more than one concrete
 // non-virtual base.
 for (const auto  : D->vbases()) {
   const auto *Ty = V.getType()->getAs();
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
index 059a0af60d3ee84..9561cc71183d977 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
@@ -17,11 +17,12 @@ namespace clang::tidy::modernize {
 
 namespace {
 AST_MATCHER(FunctionDecl, hasAnyDefinition) {
-  if (Node.hasBody() || Node.isPure() || Node.isDefaulted() || 
Node.isDeleted())
+  if (Node.hasBody() || Node.isPureVirtual() || Node.isDefaulted() ||
+  Node.isDeleted())
 return true;
 
   if (const FunctionDecl *Definition = Node.getDefinition())
-if (Definition->hasBody() || Definition->isPure() ||
+if (Definition->hasBody() || Definition->isPureVirtual() ||
 Definition->isDefaulted() || Definition->isDeleted())
   return true;
 
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 37939d36425a970..ee3772e3d380c14 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -265,7 +265,7 @@ bool isStatic(const Decl *D) {
 
 bool isAbstract(const Decl *D) {
   if (const auto *CMD = llvm::dyn_cast(D))
-return CMD->isPure();
+return CMD->isPureVirtual();
   if (const auto *CRD = llvm::dyn_cast(D))
 return CRD->hasDefinition() && CRD->isAbstract();
   

[clang] [llvm] [clang-tools-extra] [flang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-17 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/74309

>From 14f8c3e38791cc6b06455b8beffe37a6f7105e03 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 4 Dec 2023 10:32:03 +
Subject: [PATCH 01/18] Add SYSTEM runtime and lowering intrinsic support

Calls std::system() function and pass the command,
cmd on Windows or shell on Linux.
Command parameter is required, exitstatus is optional.
call system(command)
call system(command, exitstatus)
---
 flang/docs/Intrinsics.md  |  2 +-
 .../flang/Optimizer/Builder/IntrinsicCall.h   |  1 +
 .../flang/Optimizer/Builder/Runtime/Command.h |  5 +++
 flang/include/flang/Runtime/command.h |  5 +++
 flang/lib/Evaluate/intrinsics.cpp | 16 +---
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 22 ++
 .../lib/Optimizer/Builder/Runtime/Command.cpp | 13 ++
 flang/runtime/command.cpp | 19 +
 flang/test/Lower/Intrinsics/system.f90| 39 ++
 flang/unittests/Runtime/CommandTest.cpp   | 41 +++
 10 files changed, 157 insertions(+), 6 deletions(-)
 create mode 100644 flang/test/Lower/Intrinsics/system.f90

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index fef2b4ea4dd8c8..871332399628e9 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, GETPID, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, 
FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h 
b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index 5065f11ae9e726..669d076c3e0e7d 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -321,6 +321,7 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genStorageSize(mlir::Type,
 llvm::ArrayRef);
   fir::ExtendedValue genSum(mlir::Type, llvm::ArrayRef);
+  void genSystem(mlir::ArrayRef args);
   void genSystemClock(llvm::ArrayRef);
   mlir::Value genTand(mlir::Type, llvm::ArrayRef);
   mlir::Value genTrailz(mlir::Type, llvm::ArrayRef);
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/Command.h 
b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
index 976fb3aa0b6fbb..9d6a39639844fc 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/Command.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
@@ -53,5 +53,10 @@ mlir::Value genGetEnvVariable(fir::FirOpBuilder &, 
mlir::Location,
   mlir::Value length, mlir::Value trimName,
   mlir::Value errmsg);
 
+/// Generate a call to System runtime function which implements
+/// the non-standard System GNU extension.
+void genSystem(fir::FirOpBuilder &, mlir::Location, mlir::Value command,
+   mlir::Value exitstat);
+
 } // namespace fir::runtime
 #endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_COMMAND_H
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index c67d171c8e2f1b..f325faa7bd09fa 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -55,6 +55,11 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor ,
 const Descriptor *value = nullptr, const Descriptor *length = nullptr,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
+
+// Calls std::system()
+void RTNAME(System)(const Descriptor *command = nullptr,
+const Descriptor *exitstat = nullptr, const char *sourceFile = nullptr,
+int line = 0);
 }
 } // namespace Fortran::runtime
 
diff 

[clang] Add Variadic 'dropAttrs' (PR #78476)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Erich Keane (erichkeane)


Changes

As suggested in https://github.com/llvm/llvm-project/pull/78200

This adds a variadic 'dropAttrs', which drops all attributes of any of the 
types specified.

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


4 Files Affected:

- (modified) clang/include/clang/AST/DeclBase.h (+8-3) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+2-4) 


``diff
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 5b1038582bc6747..933249b4a1a05e0 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -548,17 +548,22 @@ class alignas(8) Decl {
 return hasAttrs() ? getAttrs().end() : nullptr;
   }
 
-  template 
-  void dropAttr() {
+  template
+  void dropAttrs() {
 if (!HasAttrs) return;
 
 AttrVec  = getAttrs();
-llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
+llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
 if (Vec.empty())
   HasAttrs = false;
   }
 
+  template 
+  void dropAttr() {
+dropAttrs();
+  }
+
   template 
   llvm::iterator_range> specific_attrs() const {
 return llvm::make_range(specific_attr_begin(), specific_attr_end());
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index dae98f3a7406e87..5472b43aafd4f39 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7068,8 +7068,7 @@ static void checkAttributesAfterMerging(Sema , 
NamedDecl ) {
   if (WeakRefAttr *Attr = ND.getAttr()) {
 if (ND.isExternallyVisible()) {
   S.Diag(Attr->getLocation(), diag::err_attribute_weakref_not_static);
-  ND.dropAttr();
-  ND.dropAttr();
+  ND.dropAttrs();
 }
   }
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a2ce96188b4f161..62dc623d5af378c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -6545,8 +6545,7 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl 
*Class) {
   if ((Context.getTargetInfo().getCXXABI().isMicrosoft() ||
Context.getTargetInfo().getTriple().isPS()) &&
   (!Class->isExternallyVisible() && Class->hasExternalFormalLinkage())) {
-Class->dropAttr();
-Class->dropAttr();
+Class->dropAttrs();
 return;
   }
 
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c0dcbda1fd6221d..b5be596b7dff327 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -9229,10 +9229,8 @@ void Sema::CheckConceptRedefinition(ConceptDecl *NewDecl,
 /// that has just been explicitly specialized.
 static void StripImplicitInstantiation(NamedDecl *D, bool MinGW) {
   if (MinGW || (isa(D) &&
-cast(D)->isFunctionTemplateSpecialization())) {
-D->dropAttr();
-D->dropAttr();
-  }
+cast(D)->isFunctionTemplateSpecialization()))
+D->dropAttrs< DLLImportAttr, DLLExportAttr>();
 
   if (FunctionDecl *FD = dyn_cast(D))
 FD->setInlineSpecified(false);

``




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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread Erich Keane via cfe-commits


@@ -11792,6 +11792,26 @@ static bool CheckMultiVersionFunction(Sema , 
FunctionDecl *NewFD,
  OldDecl, Previous);
 }
 
+static void CheckFunctionDeclarationAttributesUsage(Sema ,
+FunctionDecl *NewFD) {
+  bool IsPure = NewFD->hasAttr();
+  bool IsConst = NewFD->hasAttr();
+
+  if (IsPure && IsConst) {
+S.Diag(NewFD->getLocation(), diag::warn_const_attr_with_pure_attr);
+NewFD->dropAttr();
+  }
+  if (IsPure || IsConst) {
+// constructors and destructors also functions which returns void
+if (NewFD->getReturnType()->isVoidType()) {
+  S.Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void)
+  << IsConst;
+  NewFD->dropAttr();
+  NewFD->dropAttr();

erichkeane wrote:

Done here: https://github.com/llvm/llvm-project/pull/78476

Note that the 2nd and the 3rd from your list are actually from different decls, 
so don't help.

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


[clang] Add Variadic 'dropAttrs' (PR #78476)

2024-01-17 Thread Erich Keane via cfe-commits

https://github.com/erichkeane created 
https://github.com/llvm/llvm-project/pull/78476

As suggested in https://github.com/llvm/llvm-project/pull/78200

This adds a variadic 'dropAttrs', which drops all attributes of any of the 
types specified.

>From 6790e56b001a29e8bba012514eb3b12cd486d505 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Wed, 17 Jan 2024 09:03:14 -0800
Subject: [PATCH] Add Variadic 'dropAttrs'

As suggested in https://github.com/llvm/llvm-project/pull/78200

This adds a variadic 'dropAttrs', which drops all attributes of any of
the types specified.
---
 clang/include/clang/AST/DeclBase.h | 11 ---
 clang/lib/Sema/SemaDecl.cpp|  3 +--
 clang/lib/Sema/SemaDeclCXX.cpp |  3 +--
 clang/lib/Sema/SemaTemplate.cpp|  6 ++
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 5b1038582bc6747..933249b4a1a05e0 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -548,17 +548,22 @@ class alignas(8) Decl {
 return hasAttrs() ? getAttrs().end() : nullptr;
   }
 
-  template 
-  void dropAttr() {
+  template
+  void dropAttrs() {
 if (!HasAttrs) return;
 
 AttrVec  = getAttrs();
-llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
+llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
 if (Vec.empty())
   HasAttrs = false;
   }
 
+  template 
+  void dropAttr() {
+dropAttrs();
+  }
+
   template 
   llvm::iterator_range> specific_attrs() const {
 return llvm::make_range(specific_attr_begin(), specific_attr_end());
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index dae98f3a7406e87..5472b43aafd4f39 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7068,8 +7068,7 @@ static void checkAttributesAfterMerging(Sema , 
NamedDecl ) {
   if (WeakRefAttr *Attr = ND.getAttr()) {
 if (ND.isExternallyVisible()) {
   S.Diag(Attr->getLocation(), diag::err_attribute_weakref_not_static);
-  ND.dropAttr();
-  ND.dropAttr();
+  ND.dropAttrs();
 }
   }
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a2ce96188b4f161..62dc623d5af378c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -6545,8 +6545,7 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl 
*Class) {
   if ((Context.getTargetInfo().getCXXABI().isMicrosoft() ||
Context.getTargetInfo().getTriple().isPS()) &&
   (!Class->isExternallyVisible() && Class->hasExternalFormalLinkage())) {
-Class->dropAttr();
-Class->dropAttr();
+Class->dropAttrs();
 return;
   }
 
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c0dcbda1fd6221d..b5be596b7dff327 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -9229,10 +9229,8 @@ void Sema::CheckConceptRedefinition(ConceptDecl *NewDecl,
 /// that has just been explicitly specialized.
 static void StripImplicitInstantiation(NamedDecl *D, bool MinGW) {
   if (MinGW || (isa(D) &&
-cast(D)->isFunctionTemplateSpecialization())) {
-D->dropAttr();
-D->dropAttr();
-  }
+cast(D)->isFunctionTemplateSpecialization()))
+D->dropAttrs< DLLImportAttr, DLLExportAttr>();
 
   if (FunctionDecl *FD = dyn_cast(D))
 FD->setInlineSpecified(false);

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


[flang] [clang] [llvm] [clang-tools-extra] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-17 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/74309

>From 14f8c3e38791cc6b06455b8beffe37a6f7105e03 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 4 Dec 2023 10:32:03 +
Subject: [PATCH 01/18] Add SYSTEM runtime and lowering intrinsic support

Calls std::system() function and pass the command,
cmd on Windows or shell on Linux.
Command parameter is required, exitstatus is optional.
call system(command)
call system(command, exitstatus)
---
 flang/docs/Intrinsics.md  |  2 +-
 .../flang/Optimizer/Builder/IntrinsicCall.h   |  1 +
 .../flang/Optimizer/Builder/Runtime/Command.h |  5 +++
 flang/include/flang/Runtime/command.h |  5 +++
 flang/lib/Evaluate/intrinsics.cpp | 16 +---
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 22 ++
 .../lib/Optimizer/Builder/Runtime/Command.cpp | 13 ++
 flang/runtime/command.cpp | 19 +
 flang/test/Lower/Intrinsics/system.f90| 39 ++
 flang/unittests/Runtime/CommandTest.cpp   | 41 +++
 10 files changed, 157 insertions(+), 6 deletions(-)
 create mode 100644 flang/test/Lower/Intrinsics/system.f90

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index fef2b4ea4dd8c8..871332399628e9 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, GETPID, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, 
FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h 
b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index 5065f11ae9e726..669d076c3e0e7d 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -321,6 +321,7 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genStorageSize(mlir::Type,
 llvm::ArrayRef);
   fir::ExtendedValue genSum(mlir::Type, llvm::ArrayRef);
+  void genSystem(mlir::ArrayRef args);
   void genSystemClock(llvm::ArrayRef);
   mlir::Value genTand(mlir::Type, llvm::ArrayRef);
   mlir::Value genTrailz(mlir::Type, llvm::ArrayRef);
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/Command.h 
b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
index 976fb3aa0b6fbb..9d6a39639844fc 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/Command.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
@@ -53,5 +53,10 @@ mlir::Value genGetEnvVariable(fir::FirOpBuilder &, 
mlir::Location,
   mlir::Value length, mlir::Value trimName,
   mlir::Value errmsg);
 
+/// Generate a call to System runtime function which implements
+/// the non-standard System GNU extension.
+void genSystem(fir::FirOpBuilder &, mlir::Location, mlir::Value command,
+   mlir::Value exitstat);
+
 } // namespace fir::runtime
 #endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_COMMAND_H
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index c67d171c8e2f1b..f325faa7bd09fa 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -55,6 +55,11 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor ,
 const Descriptor *value = nullptr, const Descriptor *length = nullptr,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
+
+// Calls std::system()
+void RTNAME(System)(const Descriptor *command = nullptr,
+const Descriptor *exitstat = nullptr, const char *sourceFile = nullptr,
+int line = 0);
 }
 } // namespace Fortran::runtime
 
diff 

[clang] [llvm] [RISCV] Add experimental support of Zaamo and Zalrsc (PR #77424)

2024-01-17 Thread James Y Knight via cfe-commits

jyknight wrote:

There's two sets of atomic functions:
`__atomic_*` are provided by libatomic, and might use locking, or not.
`__sync_*` should always be lock-free. These are only used on certain 
architectures where it's guaranteed that the operation _can_ be implemented 
lock-free, but it's desirable for whatever reason to not do so inline.

For this patch, I think the correct behavior is:
- If Zalrsc is present, but Zaamo is not, you may either emit an LR/SC loop 
(what I'd recommend), or emit an out-of-line call to `__sync_*` (which needs to 
be implemented with that LR/SC loop.)
- If Zaamo is present, but neither Zalrsc nor Zacas are present, I think 
there's no way to implement a cmpxchg operation. This means lock-free atomics 
cannot be supported, so it should `setMaxAtomicSizeInBitsSupported(0)`.

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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread Erich Keane via cfe-commits


@@ -11792,6 +11792,26 @@ static bool CheckMultiVersionFunction(Sema , 
FunctionDecl *NewFD,
  OldDecl, Previous);
 }
 
+static void CheckFunctionDeclarationAttributesUsage(Sema ,
+FunctionDecl *NewFD) {
+  bool IsPure = NewFD->hasAttr();
+  bool IsConst = NewFD->hasAttr();
+
+  if (IsPure && IsConst) {
+S.Diag(NewFD->getLocation(), diag::warn_const_attr_with_pure_attr);
+NewFD->dropAttr();
+  }
+  if (IsPure || IsConst) {
+// constructors and destructors also functions which returns void
+if (NewFD->getReturnType()->isVoidType()) {
+  S.Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void)
+  << IsConst;
+  NewFD->dropAttr();
+  NewFD->dropAttr();

erichkeane wrote:

We already have 'dropAttrs' that does 'drop all attrs', so I was worried about 
that.  

Perhaps I'll spend a little time writing up a variadic `dropAttrs` and `hasAttr`

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


[llvm] [clang] [CMake] Detect properly new linker introduced in Xcode 15 (PR #77806)

2024-01-17 Thread Eric Miotto via cfe-commits

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


[clang] [ASTMatchers] fix captureVars assertion failure on capturesVariables (PR #76619)

2024-01-17 Thread Aaron Ballman via cfe-commits

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

LGTM but please add a release note so users know about the bug fix.

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


[llvm] [clang-tools-extra] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-17 Thread Mircea Trofin via cfe-commits

mtrofin wrote:

> > Would it be also possible to remove the dependency on 
> > [Abseil](https://github.com/abseil/abseil-py)? None of the existing scripts 
> > in LLVM use it and I don't think we should be introducing this dependency. 
> > It looks like Abseil is only used for flag parsing, logging and testing; 
> > those should be straightforward to replace with standard libraries like 
> > `argparse`, `logging` or `unittest`.
> 
> Yes. My plan was to remove the dependency on abseil as well. My plan was to 
> get this landed with all the infrastructure setup and the code basically just 
> directly copied and then remove the abseil dependency in a follow-up patch so 
> that the different pieces get reviewed appropriately.

Ah, if you can drop the abseil dependency, the dependency problem for tests 
goes away. May be worth doing the abseil dropping bit in this patch, too?

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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread Aaron Ballman via cfe-commits


@@ -11792,6 +11792,26 @@ static bool CheckMultiVersionFunction(Sema , 
FunctionDecl *NewFD,
  OldDecl, Previous);
 }
 
+static void CheckFunctionDeclarationAttributesUsage(Sema ,
+FunctionDecl *NewFD) {
+  bool IsPure = NewFD->hasAttr();
+  bool IsConst = NewFD->hasAttr();
+
+  if (IsPure && IsConst) {
+S.Diag(NewFD->getLocation(), diag::warn_const_attr_with_pure_attr);
+NewFD->dropAttr();
+  }
+  if (IsPure || IsConst) {
+// constructors and destructors also functions which returns void
+if (NewFD->getReturnType()->isVoidType()) {
+  S.Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void)
+  << IsConst;
+  NewFD->dropAttr();
+  NewFD->dropAttr();

AaronBallman wrote:

I see the following cases where we'd use that:

https://github.com/llvm/llvm-project/blob/a96b4671b97b167230986bd2811676064c608596/clang/lib/Sema/SemaDecl.cpp#L7071
https://github.com/llvm/llvm-project/blob/a96b4671b97b167230986bd2811676064c608596/clang/lib/Sema/SemaDecl.cpp#L7264
https://github.com/llvm/llvm-project/blob/a96b4671b97b167230986bd2811676064c608596/clang/lib/Sema/SemaDecl.cpp#L7270
https://github.com/llvm/llvm-project/blob/5b65f6f5864ff23e4d87ab1d954a77be343b4c4b/clang/lib/Sema/SemaDeclCXX.cpp#L6548
https://github.com/llvm/llvm-project/blob/5b65f6f5864ff23e4d87ab1d954a77be343b4c4b/clang/lib/Sema/SemaTemplate.cpp#L9233

so it's not the most common pattern in the world but it would simplify some 
code. I would name it `dropAttrs()` though so it's clear that it drops all of 
the attributes, not just one of them. I wouldn't insist on introducing the API 
for this patch, but it would be a reasonable follow-up.

(FWIW, `hasAttr` would be a bigger win in terms of variadic template support.)

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


[llvm] [clang-tools-extra] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-17 Thread Mircea Trofin via cfe-commits


@@ -0,0 +1,6 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

mtrofin wrote:

Ack - thanks for clarifying the directory structure; looking around, there 
doesn't seem to be much of a precedent either; so... how about 
`llvm/utils/mlgo-utils/mlgo`? 

(tests moving to lit sounds perfect)

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


[clang-tools-extra] [clang] [Clang][NFC] Rename CXXMethodDecl::isPure -> is VirtualPure (PR #78463)

2024-01-17 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> I might suggest `isPureVirtual` as it better reflects the 'term of art' 
> (https://en.cppreference.com/w/cpp/language/abstract_class see 'A pure 
> virtual function is a).
> 
> Else LG and SG TM.

I have the same preference for `isPureVirtual` but otherwise LGTM.

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


<    1   2   3   4   5   6   >