[clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)

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


@@ -6771,6 +6771,9 @@ def warn_pointer_sub_null_ptr : Warning<
 def warn_floatingpoint_eq : Warning<
   "comparing floating point with == or != is unsafe">,
   InGroup>, DefaultIgnore;
+def warn_fast_floatingpoint_eq : Warning<
+  "explicit comparison with %0 when the program is assumed to not use or 
produce %0">,

AaronBallman wrote:

```suggestion
  "explicit comparison with %select{infinity|NaN}0 will always return 
'%select{false|true}1' because %select{infinity|NaN}0 will not be produced 
according to the currently enabled floating-point options">,
```
How about something along these lines? I mostly want to replace the `%0` with a 
`select` so we don't have to pass in constant strings at the use sites, and I 
want to explicitly tell the user whether the comparison will always be true or 
always be false.

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


[clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)

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

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


[clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)

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

https://github.com/AaronBallman commented:

The changes also need a release note.

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


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 9ede4ecbd65ee35cd2f2f81fb251debf2df189ee Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 +++-
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 87 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9443fecf9b7946..cd1a0b6a130ff0 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   usesSEHExceptions =

[flang] [clang] [flang] Fix fveclib on Darwin (PR #77605)

2024-01-10 Thread Leandro Lupori via cfe-commits

https://github.com/luporl updated 
https://github.com/llvm/llvm-project/pull/77605

>From 3e165d363b6211e4625056671d548037533ed819 Mon Sep 17 00:00:00 2001
From: Leandro Lupori 
Date: Wed, 10 Jan 2024 10:24:52 -0300
Subject: [PATCH 1/2] [flang] Fix fveclib on Darwin

Fixes fveclib.f90 and fveclib-codegen.f90 tests, that were failing
on Darwin.
---
 clang/lib/Driver/ToolChains/Flang.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 41eaad3bbad0a3..3de5cf946bc9a8 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -352,12 +352,10 @@ void Flang::addTargetOptions(const ArgList ,
 if (A->getValue() == StringRef{"Accelerate"}) {
   CmdArgs.push_back("-framework");
   CmdArgs.push_back("Accelerate");
-  A->render(Args, CmdArgs);
 }
   }
-} else {
-  A->render(Args, CmdArgs);
 }
+A->render(Args, CmdArgs);
   }
 
   if (Triple.isKnownWindowsMSVCEnvironment()) {

>From 76f70a21bec0fbec6bb57fa73b44f2035b6e78c2 Mon Sep 17 00:00:00 2001
From: Leandro Lupori 
Date: Wed, 10 Jan 2024 10:58:42 -0300
Subject: [PATCH 2/2] Test -fveclib on Darwin

---
 flang/test/Driver/fveclib.f90 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/flang/test/Driver/fveclib.f90 b/flang/test/Driver/fveclib.f90
index 898c65b0c850af..14c59b0616f828 100644
--- a/flang/test/Driver/fveclib.f90
+++ b/flang/test/Driver/fveclib.f90
@@ -5,6 +5,7 @@
 ! RUN: %flang -### -c -fveclib=Darwin_libsystem_m %s 2>&1 | FileCheck 
-check-prefix CHECK-DARWIN_LIBSYSTEM_M %s
 ! RUN: %flang -### -c --target=aarch64-none-none -fveclib=SLEEF %s 2>&1 | 
FileCheck -check-prefix CHECK-SLEEF %s
 ! RUN: %flang -### -c --target=aarch64-none-none -fveclib=ArmPL %s 2>&1 | 
FileCheck -check-prefix CHECK-ARMPL %s
+! RUN: %flang -### -c --target=aarch64-apple-darwin -fveclib=none %s 2>&1 | 
FileCheck -check-prefix CHECK-NOLIB-DARWIN %s
 ! RUN: not %flang -c -fveclib=something %s 2>&1 | FileCheck -check-prefix 
CHECK-INVALID %s
 
 ! CHECK-NOLIB: "-fveclib=none"
@@ -14,6 +15,7 @@
 ! CHECK-DARWIN_LIBSYSTEM_M: "-fveclib=Darwin_libsystem_m"
 ! CHECK-SLEEF: "-fveclib=SLEEF"
 ! CHECK-ARMPL: "-fveclib=ArmPL"
+! CHECK-NOLIB-DARWIN: "-fveclib=none"
 
 ! CHECK-INVALID: error: invalid value 'something' in '-fveclib=something'
 

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


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 4d41874bd13cda572105239c0a26f1667c556085 Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 +++-
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 87 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9443fecf9b7946..ef78ec2dff43a7 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   usesSEHExceptions =

[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

2024-01-10 Thread via cfe-commits

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


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread David Chisnall via cfe-commits

davidchisnall wrote:

It looks as if three tests are failing in CI:

  Clang :: CodeGenObjC/2007-04-03-ObjcEH.m
  Clang :: CodeGenObjC/exceptions-personality.m
  Clang :: Coverage/codegen-gnu.m


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


[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

2024-01-10 Thread via cfe-commits


@@ -5697,6 +5698,39 @@ QualType ASTContext::getDecltypeType(Expr *e, QualType 
UnderlyingType) const {
   return QualType(dt, 0);
 }
 
+QualType ASTContext::getPackIndexingType(QualType Pattern, Expr *IndexExpr,
+ bool FullyExpanded,
+ ArrayRef Expansions,
+ int Index) const {
+  QualType Canonical;
+  if (FullyExpanded && Index != -1) {

cor3ntin wrote:

given ```cpp

auto f(auto... a) -> decltype(a...[0]);

auto g(auto b...) {
   return f(b...);
}
```

We end up in a situation where we have some expansion for `a...` because 
explicit parameters (int) are substituted, but we still have a pack. 

We seem to use "Partially substituted" in some other places, would that be more 
clear?




https://github.com/llvm/llvm-project/pull/72644
___
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-10 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 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-10 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 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-10 Thread Utkarsh Saxena via cfe-commits


@@ -7575,15 +7577,27 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath , Expr *Call,
 Path.pop_back();
   };
 
-  if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
-VisitLifetimeBoundArg(Callee, ObjectArg);
-
   bool CheckCoroCall = false;
   if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
 CheckCoroCall = RD->hasAttr() &&
 RD->hasAttr() &&
 !Callee->hasAttr();
   }
+
+  if (ObjectArg) {
+bool CheckCoroObjArg = CheckCoroCall;
+// Ignore `__promise.get_return_object()` as it is not lifetimebound.
+if (CheckCoroObjArg && Callee->getDeclName().isIdentifier() &&
+Callee->getName() == "get_return_object")
+  CheckCoroObjArg = false;

usx95 wrote:

I have refactored the check. The check still uses hardcoded names though.

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] [flang] Fix fveclib on Darwin (PR #77605)

2024-01-10 Thread Kiran Chandramohan via cfe-commits

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

LG. Please add a test if possible.

Assuming the issue was that the Argument was not `rendered` if it is `veclib`.

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


[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

2024-01-10 Thread via cfe-commits


@@ -1061,6 +1070,59 @@ ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S,
 RParenLoc);
 }
 
+static bool isParameterPack(Expr *PackExpression) {
+  if (auto D = dyn_cast(PackExpression); D) {
+ValueDecl *VD = D->getDecl();
+return VD->isParameterPack();
+  }
+  return false;
+}
+
+ExprResult Sema::ActOnPackIndexingExpr(Scope *S, Expr *PackExpression,
+   SourceLocation EllipsisLoc,
+   SourceLocation LSquareLoc,
+   Expr *IndexExpr,
+   SourceLocation RSquareLoc) {
+  bool isParameterPack = ::isParameterPack(PackExpression);
+  if (!isParameterPack) {
+CorrectDelayedTyposInExpr(IndexExpr);
+Diag(PackExpression->getBeginLoc(), diag::err_expected_name_of_pack)
+<< PackExpression;
+return ExprError();
+  }
+  return BuildPackIndexingExpr(PackExpression, EllipsisLoc, IndexExpr,
+   RSquareLoc);
+}
+
+ExprResult
+Sema::BuildPackIndexingExpr(Expr *PackExpression, SourceLocation EllipsisLoc,
+Expr *IndexExpr, SourceLocation RSquareLoc,
+ArrayRef ExpandedExprs, bool EmptyPack) {
+
+  std::optional Index;
+  if (!IndexExpr->isValueDependent() && !IndexExpr->isTypeDependent()) {
+llvm::APSInt Value(Context.getIntWidth(Context.getSizeType()));
+// TODO: do we need a new enumerator instead of CCEK_ArrayBound?
+ExprResult Res = CheckConvertedConstantExpression(
+IndexExpr, Context.getSizeType(), Value, CCEK_ArrayBound);
+if (!Res.isUsable())
+  return ExprError();
+Index = Value.getExtValue();
+  }
+
+  if (Index && (!ExpandedExprs.empty() || EmptyPack)) {

cor3ntin wrote:

I think once we have an index, it's always a ConstantExpr so presumably we 
could extract the value from that.
I suppose keeping the expression is best if people want to do funny things with 
matchers? 

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


[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

2024-01-10 Thread via cfe-commits


@@ -4193,6 +4194,13 @@ void CXXNameMangler::mangleType(const PackExpansionType 
*T) {
   mangleType(T->getPattern());
 }
 
+void CXXNameMangler::mangleType(const PackIndexingType *T) {

cor3ntin wrote:

This is a good question: do we need specific mangling, and if so, how do we 
process?
I don't think so, but then again I'm always confused that we sometime mangle 
dependent names

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


[clang] [flang] Fix fveclib on Darwin (PR #77605)

2024-01-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Leandro Lupori (luporl)


Changes

Fixes fveclib.f90 and fveclib-codegen.f90 tests, that were failing
on Darwin.


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


1 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+1-3) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 41eaad3bbad0a3..3de5cf946bc9a8 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -352,12 +352,10 @@ void Flang::addTargetOptions(const ArgList ,
 if (A->getValue() == StringRef{"Accelerate"}) {
   CmdArgs.push_back("-framework");
   CmdArgs.push_back("Accelerate");
-  A->render(Args, CmdArgs);
 }
   }
-} else {
-  A->render(Args, CmdArgs);
 }
+A->render(Args, CmdArgs);
   }
 
   if (Triple.isKnownWindowsMSVCEnvironment()) {

``




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


[clang] [lld] [llvm] [flang] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (PR #76955)

2024-01-10 Thread Pierre van Houtryve via cfe-commits


@@ -1260,13 +1261,9 @@ def FeatureISAVersion9_0_8 : FeatureSet<
  FeatureImageGather4D16Bug])>;
 
 def FeatureISAVersion9_0_9 : FeatureSet<
-  !listconcat(FeatureISAVersion9_0_Common.Features,
-[FeatureGDS,
- FeatureMadMixInsts,
- FeatureDsSrc2Insts,
- FeatureExtendedImageInsts,
- FeatureImageInsts,
- FeatureImageGather4D16Bug])>;
+  !listconcat(FeatureISAVersion9_0_Consumer_Common.Features,
+[FeatureMadMixInsts,
+ FeatureImageInsts])>;

Pierre-vh wrote:

todo: remove ImageInsts, it's already included

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


[clang] [flang] Fix fveclib on Darwin (PR #77605)

2024-01-10 Thread Leandro Lupori via cfe-commits

https://github.com/luporl created 
https://github.com/llvm/llvm-project/pull/77605

Fixes fveclib.f90 and fveclib-codegen.f90 tests, that were failing
on Darwin.


>From 3e165d363b6211e4625056671d548037533ed819 Mon Sep 17 00:00:00 2001
From: Leandro Lupori 
Date: Wed, 10 Jan 2024 10:24:52 -0300
Subject: [PATCH] [flang] Fix fveclib on Darwin

Fixes fveclib.f90 and fveclib-codegen.f90 tests, that were failing
on Darwin.
---
 clang/lib/Driver/ToolChains/Flang.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 41eaad3bbad0a3..3de5cf946bc9a8 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -352,12 +352,10 @@ void Flang::addTargetOptions(const ArgList ,
 if (A->getValue() == StringRef{"Accelerate"}) {
   CmdArgs.push_back("-framework");
   CmdArgs.push_back("Accelerate");
-  A->render(Args, CmdArgs);
 }
   }
-} else {
-  A->render(Args, CmdArgs);
 }
+A->render(Args, CmdArgs);
   }
 
   if (Triple.isKnownWindowsMSVCEnvironment()) {

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


[lldb] [clang] [lld] [clang-tools-extra] [openmp] [flang] [mlir] [llvm] [libunwind] [GVNSink] Fix #77415: GVNSink fails to optimize LLVM IR with debug info (PR #77602)

2024-01-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Shan Huang (Apochens)


Changes

This PR fixes issue #77415 and is revised from PR #77419 .

PR #77419 breaks the newly added test in the same PR on windows, 
because GVNSink is non-deterministic when sorting `BasicBlock*` pointers. This 
is reflected in the failure report.

```
# | 
C:\src\llvm-project\llvm\test\Transforms\GVNSink\sink-ignore-dbg-intrinsics.ll:28:10:
 error: CHECK: expected string not found in input
# | ; CHECK: %a.sink = phi i32 [ %a, %if.then ], [ %b, %if.else ]
# |  ^
# | stdin:24:8: note: scanning from here
# | if.end: ; preds = %if.else, %if.then
# |^
# | stdin:25:2: note: possible intended match here
# |  %b.sink = phi i32 [ %b, %if.else ], [ %a, %if.then ]
# |  ^
# | 
# | Input file: stdin
# | Check file: 
C:\src\llvm-project\llvm\test\Transforms\GVNSink\sink-ignore-dbg-intrinsics.ll
```

According to the report, what the CheckFile wants to match is the `%a.sink`, 
however there is `%b.sink`. But this mismatch does not mean that this commit is 
wrong, since the occurrence of either `%a.sink` or `%b.sink` is correct. The 
root cause of this test failure is the strict check rule in the regression test 
committed.

So I refined the regression test with a more general check rule to only detect 
whether there is an instruction with suffix `.sink` in the `if.end` block. Hope 
this won't fail the test. If this PR still fails to build, I will close this PR 
and try to find another right way to fix this.

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


2 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/GVNSink.cpp (+3-3) 
- (added) llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll (+86) 


``diff
diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp 
b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index 2b38831139a580..9db66b3793b8dd 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -132,7 +132,7 @@ class LockstepReverseIterator {
 ActiveBlocks.remove(BB);
 continue;
   }
-  Insts.push_back(BB->getTerminator()->getPrevNode());
+  Insts.push_back(BB->getTerminator()->getPrevNonDebugInstruction());
 }
 if (Insts.empty())
   Fail = true;
@@ -168,7 +168,7 @@ class LockstepReverseIterator {
   if (Inst == >getParent()->front())
 ActiveBlocks.remove(Inst->getParent());
   else
-NewInsts.push_back(Inst->getPrevNode());
+NewInsts.push_back(Inst->getPrevNonDebugInstruction());
 }
 if (NewInsts.empty()) {
   Fail = true;
@@ -834,7 +834,7 @@ void GVNSink::sinkLastInstruction(ArrayRef 
Blocks,
   BasicBlock *BBEnd) {
   SmallVector Insts;
   for (BasicBlock *BB : Blocks)
-Insts.push_back(BB->getTerminator()->getPrevNode());
+Insts.push_back(BB->getTerminator()->getPrevNonDebugInstruction());
   Instruction *I0 = Insts.front();
 
   SmallVector NewOperands;
diff --git a/llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll 
b/llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll
new file mode 100644
index 00..ee6039a0d806ab
--- /dev/null
+++ b/llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll
@@ -0,0 +1,86 @@
+; RUN: opt < %s -passes=gvn-sink -S | FileCheck %s
+
+; Function Attrs: noinline nounwind uwtable
+define dso_local i32 @fun(i32 noundef %a, i32 noundef %b) #0 !dbg !10 {
+entry:
+  tail call void @llvm.dbg.value(metadata i32 %a, metadata !15, metadata 
!DIExpression()), !dbg !16
+  tail call void @llvm.dbg.value(metadata i32 %b, metadata !17, metadata 
!DIExpression()), !dbg !16
+  %cmp = icmp sgt i32 %b, 10, !dbg !18
+  br i1 %cmp, label %if.then, label %if.else, !dbg !20
+
+if.then:  ; preds = %entry
+  %add = add nsw i32 %a, 1, !dbg !21
+  tail call void @llvm.dbg.value(metadata i32 %add, metadata !23, metadata 
!DIExpression()), !dbg !24
+  %xor = xor i32 %add, 1, !dbg !25
+  tail call void @llvm.dbg.value(metadata i32 %xor, metadata !26, metadata 
!DIExpression()), !dbg !24
+  tail call void @llvm.dbg.value(metadata i32 %xor, metadata !27, metadata 
!DIExpression()), !dbg !16
+  br label %if.end, !dbg !28
+
+if.else:  ; preds = %entry
+  %add1 = add nsw i32 %b, 1, !dbg !29
+  tail call void @llvm.dbg.value(metadata i32 %add1, metadata !31, metadata 
!DIExpression()), !dbg !32
+  %xor2 = xor i32 %add1, 1, !dbg !33
+  tail call void @llvm.dbg.value(metadata i32 %xor2, metadata !34, metadata 
!DIExpression()), !dbg !32
+  tail call void @llvm.dbg.value(metadata i32 %xor2, metadata !27, metadata 
!DIExpression()), !dbg !16
+  br label %if.end
+
+; CHECK-LABEL: if.end:
+; CHECK: [[SINK:%.*.sink]] = phi i32 [ %a, %if.then ], [ %b, %if.else ]
+; CHECK: %add = add nsw i32 [[SINK]], 1
+; CHECK: %xor = xor i32 %add, 1
+if.end:   ; preds = %if.else, %if.then
+  

[lldb] [clang] [lld] [clang-tools-extra] [openmp] [flang] [mlir] [llvm] [libunwind] [GVNSink] Fix #77415: GVNSink fails to optimize LLVM IR with debug info (PR #77602)

2024-01-10 Thread Shan Huang via cfe-commits

https://github.com/Apochens created 
https://github.com/llvm/llvm-project/pull/77602

This PR fixes issue #77415 and is revised from PR #77419 .

PR #77419 breaks the newly added test in the same PR on windows, because 
GVNSink is non-deterministic when sorting `BasicBlock*` pointers. This is 
reflected in the failure report.

```
# | 
C:\src\llvm-project\llvm\test\Transforms\GVNSink\sink-ignore-dbg-intrinsics.ll:28:10:
 error: CHECK: expected string not found in input
# | ; CHECK: %a.sink = phi i32 [ %a, %if.then ], [ %b, %if.else ]
# |  ^
# | :24:8: note: scanning from here
# | if.end: ; preds = %if.else, %if.then
# |^
# | :25:2: note: possible intended match here
# |  %b.sink = phi i32 [ %b, %if.else ], [ %a, %if.then ]
# |  ^
# | 
# | Input file: 
# | Check file: 
C:\src\llvm-project\llvm\test\Transforms\GVNSink\sink-ignore-dbg-intrinsics.ll
```

According to the report, what the CheckFile wants to match is the `%a.sink`, 
however there is `%b.sink`. But this mismatch does not mean that this commit is 
wrong, since the occurrence of either `%a.sink` or `%b.sink` is correct. The 
root cause of this test failure is the strict check rule in the regression test 
committed.

So I refined the regression test with a more general check rule to only detect 
whether there is an instruction with suffix `.sink` in the `if.end` block. Hope 
this won't fail the test. If this PR still fails to build, I will close this PR 
and try to find another right way to fix this.

>From d08af0b38d28726bc78c8da675ea01d7c188c446 Mon Sep 17 00:00:00 2001
From: Apochens <52285902...@stu.ecnu.edu.cn>
Date: Wed, 10 Jan 2024 07:10:22 +
Subject: [PATCH] [GVNSink] Fix #77415: GVNSink fails to optimize LLVM IR with
 debug info

---
 llvm/lib/Transforms/Scalar/GVNSink.cpp|  6 +-
 .../GVNSink/sink-ignore-dbg-intrinsics.ll | 86 +++
 2 files changed, 89 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll

diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp 
b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index 2b38831139a580..9db66b3793b8dd 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -132,7 +132,7 @@ class LockstepReverseIterator {
 ActiveBlocks.remove(BB);
 continue;
   }
-  Insts.push_back(BB->getTerminator()->getPrevNode());
+  Insts.push_back(BB->getTerminator()->getPrevNonDebugInstruction());
 }
 if (Insts.empty())
   Fail = true;
@@ -168,7 +168,7 @@ class LockstepReverseIterator {
   if (Inst == >getParent()->front())
 ActiveBlocks.remove(Inst->getParent());
   else
-NewInsts.push_back(Inst->getPrevNode());
+NewInsts.push_back(Inst->getPrevNonDebugInstruction());
 }
 if (NewInsts.empty()) {
   Fail = true;
@@ -834,7 +834,7 @@ void GVNSink::sinkLastInstruction(ArrayRef 
Blocks,
   BasicBlock *BBEnd) {
   SmallVector Insts;
   for (BasicBlock *BB : Blocks)
-Insts.push_back(BB->getTerminator()->getPrevNode());
+Insts.push_back(BB->getTerminator()->getPrevNonDebugInstruction());
   Instruction *I0 = Insts.front();
 
   SmallVector NewOperands;
diff --git a/llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll 
b/llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll
new file mode 100644
index 00..ee6039a0d806ab
--- /dev/null
+++ b/llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll
@@ -0,0 +1,86 @@
+; RUN: opt < %s -passes=gvn-sink -S | FileCheck %s
+
+; Function Attrs: noinline nounwind uwtable
+define dso_local i32 @fun(i32 noundef %a, i32 noundef %b) #0 !dbg !10 {
+entry:
+  tail call void @llvm.dbg.value(metadata i32 %a, metadata !15, metadata 
!DIExpression()), !dbg !16
+  tail call void @llvm.dbg.value(metadata i32 %b, metadata !17, metadata 
!DIExpression()), !dbg !16
+  %cmp = icmp sgt i32 %b, 10, !dbg !18
+  br i1 %cmp, label %if.then, label %if.else, !dbg !20
+
+if.then:  ; preds = %entry
+  %add = add nsw i32 %a, 1, !dbg !21
+  tail call void @llvm.dbg.value(metadata i32 %add, metadata !23, metadata 
!DIExpression()), !dbg !24
+  %xor = xor i32 %add, 1, !dbg !25
+  tail call void @llvm.dbg.value(metadata i32 %xor, metadata !26, metadata 
!DIExpression()), !dbg !24
+  tail call void @llvm.dbg.value(metadata i32 %xor, metadata !27, metadata 
!DIExpression()), !dbg !16
+  br label %if.end, !dbg !28
+
+if.else:  ; preds = %entry
+  %add1 = add nsw i32 %b, 1, !dbg !29
+  tail call void @llvm.dbg.value(metadata i32 %add1, metadata !31, metadata 
!DIExpression()), !dbg !32
+  %xor2 = xor i32 %add1, 1, !dbg !33
+  tail call void @llvm.dbg.value(metadata i32 %xor2, metadata !34, metadata 
!DIExpression()), !dbg !32
+  tail call void @llvm.dbg.value(metadata i32 %xor2, metadata !27, metadata 
!DIExpression()), !dbg !16
+  br label %if.end
+
+; CHECK-LABEL: 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From d0d2e2f72965961712dd2df6fe34bd0f7e2befe8 Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 36 -
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 87 insertions(+), 19 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9443fecf9b7946..3902bf3db9a8c0 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   usesSEHExceptions 

[llvm] [clang] [flang] [clang-tools-extra] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

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


@@ -0,0 +1,206 @@
+//===-- runtime/execute.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "flang/Runtime/execute.h"
+#include "environment.h"
+#include "stat.h"
+#include "terminator.h"
+#include "tools.h"
+#include "flang/Runtime/descriptor.h"
+#include 
+#include 
+#include 
+#ifdef _WIN32
+#define LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#else
+#include 
+#include 
+#endif
+
+namespace Fortran::runtime {
+
+// cmdstat specified in 16.9.73
+// −1 if the processor does not support command line execution,
+// a processor-dependent positive value if an error condition occurs
+// −2 if no error condition occurs but WAIT is present with the value false
+// and the processor does not support asynchronous execution. Otherwise it is
+// assigned the value 0
+enum CMD_STAT {
+  ASYNC_NO_SUPPORT_ERR = -2,
+  NO_SUPPORT_ERR = -1,
+  CMD_EXECUTED = 0,
+  FORK_ERR = 1,
+  EXECL_ERR = 2,
+  INVALID_CL_ERR = 3,
+  SIGNAL_ERR = 4
+};
+
+// Override CopyCharsToDescriptor in tools.h, pass string directly
+void CopyCharsToDescriptor(const Descriptor , const char *rawValue) {
+  CopyCharsToDescriptor(value, rawValue, std::strlen(rawValue));
+}
+
+void CheckAndCopyCharsToDescriptor(
+const Descriptor *value, const char *rawValue) {
+  if (value) {
+CopyCharsToDescriptor(*value, rawValue);
+  }
+}
+
+void CheckAndStoreIntToDescriptor(
+const Descriptor *intVal, std::int64_t value, Terminator ) {
+  if (intVal) {
+StoreIntToDescriptor(intVal, value, terminator);
+  }
+}
+
+// If a condition occurs that would assign a nonzero value to CMDSTAT but
+// the CMDSTAT variable is not present, error termination is initiated.
+int TerminationCheck(int status, const Descriptor *cmdstat,
+const Descriptor *cmdmsg, Terminator ) {
+  if (status == -1) {
+if (!cmdstat) {
+  terminator.Crash("Execution error with system status code: %d", status);
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, EXECL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "Execution error");
+}
+  }
+#ifdef _WIN32
+  // On WIN32 API std::system returns exit status directly
+  int exitStatusVal{status};
+  if (exitStatusVal == 1) {
+#else
+  int exitStatusVal{WEXITSTATUS(status)};
+  if (exitStatusVal == 127 || exitStatusVal == 126) {
+#endif
+if (!cmdstat) {
+  terminator.Crash(
+  "Invalid command quit with exit status code: %d", exitStatusVal);
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, INVALID_CL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "Invalid command line");
+}
+  }
+#if defined(WIFSIGNALED) && defined(WTERMSIG)
+  if (WIFSIGNALED(status)) {
+if (!cmdstat) {
+  terminator.Crash("killed by signal: %d", WTERMSIG(status));
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, SIGNAL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "killed by signal");
+}
+  }
+#endif
+#if defined(WIFSTOPPED) && defined(WSTOPSIG)
+  if (WIFSTOPPED(status)) {
+if (!cmdstat) {
+  terminator.Crash("stopped by signal: %d", WSTOPSIG(status));
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, SIGNAL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "stopped by signal");
+}
+  }
+#endif
+  return exitStatusVal;
+}
+
+void RTNAME(ExecuteCommandLine)(const Descriptor , bool wait,
+const Descriptor *exitstat, const Descriptor *cmdstat,
+const Descriptor *cmdmsg, const char *sourceFile, int line) {
+  Terminator terminator{sourceFile, line};
+  const char *newCmd{EnsureNullTerminated(
+  command.OffsetElement(), command.ElementBytes(), terminator)};
+
+  if (exitstat) {
+RUNTIME_CHECK(terminator, IsValidIntDescriptor(exitstat));
+  }
+
+  if (cmdstat) {
+RUNTIME_CHECK(terminator, IsValidIntDescriptor(cmdstat));
+// Assigned 0 as specifed in standard, if error then overwrite
+StoreIntToDescriptor(cmdstat, CMD_EXECUTED, terminator);
+  }
+
+  if (cmdmsg) {
+RUNTIME_CHECK(terminator, IsValidCharDescriptor(cmdmsg));
+  }
+
+  if (wait) {
+// either wait is not specified or wait is true: synchronous mode
+int status{std::system(newCmd)};
+int exitStatusVal{TerminationCheck(status, cmdstat, cmdmsg, terminator)};
+// If sync, assigned processor-dependent exit status. Otherwise unchanged
+CheckAndStoreIntToDescriptor(exitstat, exitStatusVal, terminator);
+  } else {
+// Asynchronous mode
+#ifdef _WIN32
+STARTUPINFO si;
+PROCESS_INFORMATION pi;
+ZeroMemory(, sizeof(si));
+si.cb = sizeof(si);
+ZeroMemory(, sizeof(pi));
+
+// add "cmd.exe /c " to the beginning of command
+const char *prefix{"cmd.exe /c "};
+char *newCmdWin{(char 

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

2024-01-10 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/77066

>From 3e0d0ab6c4fc6cba68285816a95e423bc18e8e55 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Fri, 5 Jan 2024 10:11:20 +0100
Subject: [PATCH 1/3] [coroutines] Detect lifetime issues with coroutine lambda
 captures

---
 clang/lib/Sema/SemaInit.cpp   | 20 +--
 clang/test/SemaCXX/coro-lifetimebound.cpp | 64 +--
 2 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 60c0e3e74204ec..c100bf11454786 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
@@ -33,6 +34,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -7575,15 +7577,27 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath , Expr *Call,
 Path.pop_back();
   };
 
-  if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
-VisitLifetimeBoundArg(Callee, ObjectArg);
-
   bool CheckCoroCall = false;
   if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
 CheckCoroCall = RD->hasAttr() &&
 RD->hasAttr() &&
 !Callee->hasAttr();
   }
+
+  if (ObjectArg) {
+bool CheckCoroObjArg = CheckCoroCall;
+// Ignore `__promise.get_return_object()` as it not lifetimebound.
+if (Callee->getDeclName().isIdentifier() &&
+Callee->getName() == "get_return_object")
+  CheckCoroObjArg = false;
+// Coroutine lambda objects with empty capture list are not lifetimebound.
+if (auto *LE = dyn_cast(ObjectArg->IgnoreImplicit());
+LE && LE->captures().empty())
+  CheckCoroObjArg = false;
+if (implicitObjectParamIsLifetimeBound(Callee) || CheckCoroObjArg)
+  VisitLifetimeBoundArg(Callee, ObjectArg);
+  }
+
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp 
b/clang/test/SemaCXX/coro-lifetimebound.cpp
index 3fc7ca70a14a12..319134450e4b6f 100644
--- a/clang/test/SemaCXX/coro-lifetimebound.cpp
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -64,6 +64,10 @@ Co bar_coro(const int , int c) {
   : bar_coro(0, 1); // expected-warning {{returning address of local 
temporary object}}
 }
 
+// 
=
+// Lambdas
+// 
=
+namespace lambdas {
 void lambdas() {
   auto unsafe_lambda = [] [[clang::coro_wrapper]] (int b) {
 return foo_coro(b); // expected-warning {{address of stack memory 
associated with parameter}}
@@ -84,15 +88,47 @@ void lambdas() {
 co_return x + co_await foo_coro(b);
   };
 }
+
+Co lambda_captures() {
+  int a = 1;
+  // Temporary lambda object dies.
+  auto lamb = [a](int x, const int& y) -> Co { // expected-warning 
{{temporary whose address is used as value of local variable 'lamb'}}
+co_return x + y + a;
+  }(1, a);
+  // Object dies but it has no capture.
+  auto no_capture = []() -> Co { co_return 1; }();
+  auto bad_no_capture = [](const int& a) -> Co { co_return a; }(1); // 
expected-warning {{temporary}}
+  // Temporary lambda object with lifetime extension under co_await.
+  int res = co_await [a](int x, const int& y) -> Co {
+co_return x + y + a;
+  }(1, a);
+  co_return 1;
+}
+} // namespace lambdas
+
 // 
=
-// Safe usage when parameters are value
+// Member coroutines
 // 
=
-namespace by_value {
-Co value_coro(int b) { co_return co_await foo_coro(b); }
-[[clang::coro_wrapper]] Co wrapper1(int b) { return value_coro(b); }
-[[clang::coro_wrapper]] Co wrapper2(const int& b) { return value_coro(b); 
}
+namespace member_coroutines{
+struct S {
+  Co member(const int& a) { co_return a; }  
+};
+
+Co use() {
+  S s;
+  int a = 1;
+  auto test1 = s.member(1);  // expected-warning {{temporary whose address is 
used as value of local variable}}
+  auto test2 = s.member(a);
+  auto test3 = S{}.member(a);  // expected-warning {{temporary whose address 
is used as value of local variable}}
+  co_return 1;
 }
 
+[[clang::coro_wrapper]] Co wrapper(const int& a) {
+  S s;
+  return s.member(a); // expected-warning {{address of stack memory}}
+}
+} // member_coroutines
+
 // 
=
 // Lifetime bound but not a Coroutine Return Type: No 

[libc] [compiler-rt] [libclc] [clang] [llvm] [clang-tools-extra] [lld] [flang] [lldb] [libunwind] [libcxx] [clang] Add tests for DRs about complete-class context (PR #77444)

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

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/77444

>From 1cbf8eec15112cd6871fcfb69425c62f08c8f681 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Tue, 9 Jan 2024 14:17:21 +0300
Subject: [PATCH 1/2] [clang] Add tests for DRs about complete-class context
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

[P1787](https://wg21.link/p1787): The intent for CWG2335 (contra those of the 
older CWG1890, CWG1626, CWG1255, and CWG287) is supported by retaining the 
unrestricted forward lookup in complete-class contexts (despite current 
implementation behavior for non-templates).
Wording: The declaration set is the result of a single search in the scope of C 
for N from immediately after the class-specifier of C if P is in a 
complete-class context of C or from P otherwise. [Drafting note: The plan for 
CWG2335 is to describe forbidden dependency cycles among the complete-class 
contexts of a class. — end drafting note] ([class.member.lookup]/4)

Complete-class context is described in [class.mem.general] 
[p7](http://eel.is/c++draft/class#mem.general-7) and 
[p8](http://eel.is/c++draft/class#mem.general-8). In this patch I add tests 
only for CWG issues that fall under current definition of complete-class 
context, because I'm not sure how CWG1255 and CWG287 are going to work. That's 
why I skip over them, but mark CWG1308 as superseded by CWG1330.
---
 clang/test/CXX/drs/dr13xx.cpp |  2 ++
 clang/test/CXX/drs/dr16xx.cpp | 22 
 clang/test/CXX/drs/dr18xx.cpp | 38 +++
 clang/test/CXX/drs/dr2335.cpp | 48 +++
 clang/www/cxx_dr_status.html  |  8 +++---
 5 files changed, 109 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr2335.cpp

diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index 359c04b3e0f3d4..81a8a8a361700a 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -40,6 +40,8 @@ void caller() {
 #endif // __cplusplus >= 201103L
 } // namespace dr1307
 
+// dr1308: sup 1330
+
 namespace dr1310 { // dr1310: 5
   struct S {} * sp = new S::S;
   // expected-error@-1 {{qualified reference to 'S' is a constructor name 
rather than a type in this context}}
diff --git a/clang/test/CXX/drs/dr16xx.cpp b/clang/test/CXX/drs/dr16xx.cpp
index 3f074c4d57354a..342240cdc7a43d 100644
--- a/clang/test/CXX/drs/dr16xx.cpp
+++ b/clang/test/CXX/drs/dr16xx.cpp
@@ -42,6 +42,28 @@ namespace dr1611 { // dr1611: dup 1658
   C c;
 }
 
+namespace dr1626 { // dr1626: no open
+// FIXME: current consensus for CWG2335 is that the examples are well-formed.
+#if __cplusplus >= 201103L
+namespace ex1 {
+template  struct C {
+  template  static constexpr bool _S_chk() { return false; }
+  static const bool __value = _S_chk();
+};
+template struct C;
+} // namespace ex1
+
+namespace ex2 {
+struct C {
+  static constexpr bool _S_chk() { return false; }
+  static const bool __value = _S_chk();
+  // expected-error@-1 {{in-class initializer for static data member is not a 
constant expression}}
+};
+C c;
+} // namespace ex2
+#endif
+} // namespace dr1626
+
 namespace dr1631 {  // dr1631: 3.7
 #if __cplusplus >= 201103L
   // Incorrect overload resolution for single-element initializer-list
diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index fbe67bd0c2f6db..0a0213c28595fd 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx98 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx11-17,since-cxx11 -fexceptions -Wno-deprecated-builtins 
-fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx11-17,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx11-17,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx20,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx20,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx20,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx14,cxx11-17,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins 

[clang] [llvm] [RISCV] Add support for new unprivileged extensions defined in profiles spec (PR #77458)

2024-01-10 Thread Alex Bradbury via cfe-commits

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

LGTM, but please add a release note too.

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


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 7048dcba9440bb38ddab6140d6a83839938dae8d Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH 1/2] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 36 -
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 88 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9443fecf9b7946..9fc0986b05010e 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   

[llvm] [clang] [flang] [clang-tools-extra] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

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

https://github.com/yi-wu-arm edited 
https://github.com/llvm/llvm-project/pull/74077
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

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

AaronBallman wrote:

> I'm not fan about this check. For me there is no use case for it.

Yeah, I don't see much motivation for the check. I know that once upon a time 
(my grey beard is showing, lol) there were compiler bugs in some 
implementations where a missing return statement in `main` would not return 0 
as the standard required. However, I did some cursory searching on the web and 
don't see evidence that this problem exists in the wild any longer.

Do any of the current coding style guides we have checks for explicitly require 
the return in `main` or require it not be present? Maybe that would be more 
motivating?

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


[clang] [clang] Add tests for DRs about complete-class context (PR #77444)

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

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


[clang] [clang] Add tests for DRs about complete-class context (PR #77444)

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


@@ -42,6 +42,28 @@ namespace dr1611 { // dr1611: dup 1658
   C c;
 }
 
+namespace dr1626 { // dr1626: no open
+// FIXME: current consensus for CWG2335 is that the examples are well-formed.

Endilll wrote:

Intent expressed in P1787 in PR description seems rather clear to me, as well 
as its application to CWG1626, but I don't insist.

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


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 7048dcba9440bb38ddab6140d6a83839938dae8d Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH 1/2] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 36 -
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 88 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9443fecf9b7946..9fc0986b05010e 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   

[clang-tools-extra] [clang] [flang] [llvm] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

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

https://github.com/yi-wu-arm edited 
https://github.com/llvm/llvm-project/pull/74077
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [flang] [llvm] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

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


@@ -0,0 +1,206 @@
+//===-- runtime/execute.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "flang/Runtime/execute.h"
+#include "environment.h"
+#include "stat.h"
+#include "terminator.h"
+#include "tools.h"
+#include "flang/Runtime/descriptor.h"
+#include 
+#include 
+#include 
+#ifdef _WIN32
+#define LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#else
+#include 
+#include 
+#endif
+
+namespace Fortran::runtime {
+
+// cmdstat specified in 16.9.73
+// −1 if the processor does not support command line execution,
+// a processor-dependent positive value if an error condition occurs
+// −2 if no error condition occurs but WAIT is present with the value false
+// and the processor does not support asynchronous execution. Otherwise it is
+// assigned the value 0
+enum CMD_STAT {
+  ASYNC_NO_SUPPORT_ERR = -2,
+  NO_SUPPORT_ERR = -1,
+  CMD_EXECUTED = 0,
+  FORK_ERR = 1,
+  EXECL_ERR = 2,
+  INVALID_CL_ERR = 3,
+  SIGNAL_ERR = 4
+};
+
+// Override CopyCharsToDescriptor in tools.h, pass string directly
+void CopyCharsToDescriptor(const Descriptor , const char *rawValue) {
+  CopyCharsToDescriptor(value, rawValue, std::strlen(rawValue));
+}
+
+void CheckAndCopyCharsToDescriptor(
+const Descriptor *value, const char *rawValue) {
+  if (value) {
+CopyCharsToDescriptor(*value, rawValue);
+  }
+}
+
+void CheckAndStoreIntToDescriptor(
+const Descriptor *intVal, std::int64_t value, Terminator ) {
+  if (intVal) {
+StoreIntToDescriptor(intVal, value, terminator);
+  }
+}
+
+// If a condition occurs that would assign a nonzero value to CMDSTAT but
+// the CMDSTAT variable is not present, error termination is initiated.
+int TerminationCheck(int status, const Descriptor *cmdstat,
+const Descriptor *cmdmsg, Terminator ) {
+  if (status == -1) {
+if (!cmdstat) {
+  terminator.Crash("Execution error with system status code: %d", status);
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, EXECL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "Execution error");
+}
+  }
+#ifdef _WIN32
+  // On WIN32 API std::system returns exit status directly
+  int exitStatusVal{status};
+  if (exitStatusVal == 1) {
+#else
+  int exitStatusVal{WEXITSTATUS(status)};
+  if (exitStatusVal == 127 || exitStatusVal == 126) {
+#endif
+if (!cmdstat) {
+  terminator.Crash(
+  "Invalid command quit with exit status code: %d", exitStatusVal);
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, INVALID_CL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "Invalid command line");
+}
+  }
+#if defined(WIFSIGNALED) && defined(WTERMSIG)
+  if (WIFSIGNALED(status)) {
+if (!cmdstat) {
+  terminator.Crash("killed by signal: %d", WTERMSIG(status));
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, SIGNAL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "killed by signal");
+}
+  }
+#endif
+#if defined(WIFSTOPPED) && defined(WSTOPSIG)
+  if (WIFSTOPPED(status)) {
+if (!cmdstat) {
+  terminator.Crash("stopped by signal: %d", WSTOPSIG(status));
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, SIGNAL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "stopped by signal");
+}
+  }
+#endif
+  return exitStatusVal;
+}
+
+void RTNAME(ExecuteCommandLine)(const Descriptor , bool wait,
+const Descriptor *exitstat, const Descriptor *cmdstat,
+const Descriptor *cmdmsg, const char *sourceFile, int line) {
+  Terminator terminator{sourceFile, line};
+  const char *newCmd{EnsureNullTerminated(
+  command.OffsetElement(), command.ElementBytes(), terminator)};
+
+  if (exitstat) {
+RUNTIME_CHECK(terminator, IsValidIntDescriptor(exitstat));
+  }
+
+  if (cmdstat) {
+RUNTIME_CHECK(terminator, IsValidIntDescriptor(cmdstat));
+// Assigned 0 as specifed in standard, if error then overwrite
+StoreIntToDescriptor(cmdstat, CMD_EXECUTED, terminator);
+  }
+
+  if (cmdmsg) {
+RUNTIME_CHECK(terminator, IsValidCharDescriptor(cmdmsg));
+  }
+
+  if (wait) {
+// either wait is not specified or wait is true: synchronous mode
+int status{std::system(newCmd)};
+int exitStatusVal{TerminationCheck(status, cmdstat, cmdmsg, terminator)};
+// If sync, assigned processor-dependent exit status. Otherwise unchanged
+CheckAndStoreIntToDescriptor(exitstat, exitStatusVal, terminator);
+  } else {
+// Asynchronous mode
+#ifdef _WIN32
+STARTUPINFO si;
+PROCESS_INFORMATION pi;
+ZeroMemory(, sizeof(si));
+si.cb = sizeof(si);
+ZeroMemory(, sizeof(pi));
+
+// add "cmd.exe /c " to the beginning of command
+const char *prefix{"cmd.exe /c "};
+char *newCmdWin{(char 

[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #73017)

2024-01-10 Thread Egor Zhdan via cfe-commits

egorzhdan wrote:

@compnerd pinging again :)

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


[clang] [clang-format] Optimize processing .clang-format-ignore files (PR #76733)

2024-01-10 Thread Nico Weber via cfe-commits

nico wrote:

This still breaks tests on win: http://45.33.8.238/win/88113/step_7.txt

Please take a look and revert for now if it takes a while to fix.

(Maybe it's possible to rewrite the test to not need grep -Fx – none of the 
other tests seem to need it.)

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


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

> I'm not fan about this check. For me there is no use case for it. For sure 
> it's not readability, simply because explicit return is more readable, and 
> people who do not know that main by default will return 0 may even consider 
> this check a bug, as why all functions got return but not this. Other issue 
> is that many projects enable all readability checks, and as this one is 
> controversial and not common it shouldn't be under readability, more like 
> misc. There are many things that aren't needed, for example compiler is able 
> to generate destructor, but still rule of 3/5 require it in some cases to be 
> done explicitly, same is with return 0, there could be easily a check that 
> could enforce explicit return in all functions, and that would also be 
> readability.
> 
> As for the check:
> 
> * wrong name
> * wrong category, it should be more a 'misc' for me
> * in current form it will catch also 'return 1';
>   I would say that if this check had to exists (i still cannot find use case 
> for it), then it should be configurable to enforce 'return 0' or enforce lack 
> of 'return 0'. And left configured to an most safe/common approach. What if 
> someone wanted to do 'return 1', but forget to put return, and compiler 
> didn't warn.

Sure I will Look into these and will update it accordingly. I added it into 
readability category as It was mentioned by author on the issue #61957 , also 
can you please suggest the name that would be more suitable.

> The check could be placed under readability-* category.

As a new contributor to LLVM, I am willing to take to your guidance and 
suggestions.
Thank you

https://github.com/llvm/llvm-project/pull/77586
___
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] GETLOG runtime and extension implementation: get login username (PR #74628)

2024-01-10 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch broke the Solaris build:
```
FAILED: tools/flang/runtime/CMakeFiles/obj.FortranRuntime.dir/extensions.cpp.o 
[...]
/vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:60:24: error: use 
of undeclared identifier 'LOGIN_NAME_MAX'
   60 |   const int nameMaxLen{LOGIN_NAME_MAX + 1};
  |^
/vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:61:12: warning: 
variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   61 |   char str[nameMaxLen];
  |^~
/vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:61:12: note: 
initializer of 'nameMaxLen' is unknown
/vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:60:13: note: 
declared here
   60 |   const int nameMaxLen{LOGIN_NAME_MAX + 1};
  | ^
1 warning and 1 error generated.
```
and
```
FAILED: 
tools/flang/unittests/Runtime/CMakeFiles/FlangRuntimeTests.dir/CommandTest.cpp.o
[...]
/vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:530:21: 
error: use of undeclared identifier 'LOGIN_NAME_MAX' 
  530 |   const int charLen{LOGIN_NAME_MAX + 2};
  | ^
/vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:531:14: 
warning: variable length arrays in C++ are a Clang extension 
[-Wvla-cxx-extension]
  531 |   char input[charLen];
  |  ^~~
/vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:531:14: 
note: initializer of 'charLen' is unknown
/vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:530:13: 
note: declared here
  530 |   const int charLen{LOGIN_NAME_MAX + 2};
  | ^
```
As documented in Solaris `limits.h(3HEAD)` (and exactly matching XPG7), 
`LOGIN_NAME_MAX` not being defined is an allowed configuration:
```
   Runtime Invariant Values (Possibly Indeterminate)
   A definition of one of the symbolic names  in  the  following  list  is
   omitted  fromon specific implementations where the corre-
   sponding value is equal to or greater than the stated minimum,  but  is
   unspecified.

   This  indetermination  might  depend  on the amount of available memory
   space on a specific instance of a specific implementation.  The  actual
   value  supported  by  a  specific  instance  will  be  provided  by the
   sysconf() function.
[...]
   LOGIN_NAME_MAX

   Maximum length of a login name.
```
So the code needs to fall back to `sysconf(_SC_LOGIN_NAME_MAX)` if 
`LOGIN_NAME_MAX` is not defined.

I've used the attached patch to implement this, which allowed the build and 
`ninja check-all` to finish.  I'm uncertain if support for `syscconf() == -1` 
is really necessary, though.
[lnm.txt](https://github.com/llvm/llvm-project/files/13887475/lnm.txt)


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


[llvm] [clang] [clang][AArch64] Add a -mbranch-protection option to enable GCS (PR #75486)

2024-01-10 Thread Jonathan Thackray via cfe-commits

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

I'm not an expert in this area, but this code LGTM.

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


[llvm] [clang] [clang-tools-extra] [mlir] [emacs] Fix Emacs library formatting (PR #76110)

2024-01-10 Thread Benjamin Kramer via cfe-commits

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


[clang] 5b4abae - [emacs] Fix Emacs library formatting (#76110)

2024-01-10 Thread via cfe-commits

Author: darkfeline
Date: 2024-01-10T13:14:21+01:00
New Revision: 5b4abae7630572c96a736faa1f09b1a3c37201a2

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

LOG: [emacs] Fix Emacs library formatting (#76110)

This makes it easier to ship/install these using the builtin Emacs
package format (in particular, a Version is required).

Added: 


Modified: 
clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el
clang/tools/clang-format/clang-format.el
clang/tools/clang-rename/clang-rename.el
llvm/utils/emacs/tablegen-mode.el
mlir/utils/emacs/mlir-lsp-client.el
mlir/utils/emacs/mlir-mode.el

Removed: 




diff  --git a/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el 
b/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el
index 272f282c47f5fc..f3a949f8c1b552 100644
--- a/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el
+++ b/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el
@@ -1,5 +1,6 @@
 ;;; clang-include-fixer.el --- Emacs integration of the clang include fixer  
-*- lexical-binding: t; -*-
 
+;; Version: 0.1.0
 ;; Keywords: tools, c
 ;; Package-Requires: ((cl-lib "0.5") (json "1.2") (let-alist "1.0.4"))
 

diff  --git a/clang/tools/clang-format/clang-format.el 
b/clang/tools/clang-format/clang-format.el
index 30ac7501afcb61..f43bf063c62970 100644
--- a/clang/tools/clang-format/clang-format.el
+++ b/clang/tools/clang-format/clang-format.el
@@ -1,5 +1,6 @@
 ;;; clang-format.el --- Format code using clang-format  -*- lexical-binding: 
t; -*-
 
+;; Version: 0.1.0
 ;; Keywords: tools, c
 ;; Package-Requires: ((cl-lib "0.3"))
 ;; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

diff  --git a/clang/tools/clang-rename/clang-rename.el 
b/clang/tools/clang-rename/clang-rename.el
index b6c3ed4c686b76..3f47c11e2c752e 100644
--- a/clang/tools/clang-rename/clang-rename.el
+++ b/clang/tools/clang-rename/clang-rename.el
@@ -1,5 +1,6 @@
 ;;; clang-rename.el --- Renames every occurrence of a symbol found at 
.  -*- lexical-binding: t; -*-
 
+;; Version: 0.1.0
 ;; Keywords: tools, c
 
 ;;; Commentary:

diff  --git a/llvm/utils/emacs/tablegen-mode.el 
b/llvm/utils/emacs/tablegen-mode.el
index 330da465887053..b1cc1cb36c06e5 100644
--- a/llvm/utils/emacs/tablegen-mode.el
+++ b/llvm/utils/emacs/tablegen-mode.el
@@ -1,6 +1,7 @@
 ;;; tablegen-mode.el --- Major mode for TableGen description files (part of 
LLVM project)
 
 ;; Maintainer:  The LLVM team, http://llvm.org/
+;; Version: 1.0
 
 ;;; Commentary:
 ;; A major mode for TableGen description files in LLVM.

diff  --git a/mlir/utils/emacs/mlir-lsp-client.el 
b/mlir/utils/emacs/mlir-lsp-client.el
index 09dfa835deccdc..4397a55e7206ac 100644
--- a/mlir/utils/emacs/mlir-lsp-client.el
+++ b/mlir/utils/emacs/mlir-lsp-client.el
@@ -14,6 +14,8 @@
 ;; See the License for the specific language governing permissions and
 ;; limitations under the License.
 
+;; Version: 0.1.0
+
 ;;; Commentary:
 
 ;; LSP clinet to use with `mlir-mode' that uses `mlir-lsp-server' or any

diff  --git a/mlir/utils/emacs/mlir-mode.el b/mlir/utils/emacs/mlir-mode.el
index 69056ba3620eb8..e5947df03f86c8 100644
--- a/mlir/utils/emacs/mlir-mode.el
+++ b/mlir/utils/emacs/mlir-mode.el
@@ -14,6 +14,8 @@
 ;; See the License for the specific language governing permissions and
 ;; limitations under the License.
 
+;; Version: 0.1.0
+
 ;;; Commentary:
 
 ;; Major mode for editing MLIR files.
@@ -96,5 +98,4 @@
 (add-to-list 'auto-mode-alist (cons "\\.mlirbc\\'" 'mlir-mode))
 
 (provide 'mlir-mode)
-
 ;;; mlir-mode.el ends here



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


[clang-tools-extra] 5b4abae - [emacs] Fix Emacs library formatting (#76110)

2024-01-10 Thread via cfe-commits

Author: darkfeline
Date: 2024-01-10T13:14:21+01:00
New Revision: 5b4abae7630572c96a736faa1f09b1a3c37201a2

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

LOG: [emacs] Fix Emacs library formatting (#76110)

This makes it easier to ship/install these using the builtin Emacs
package format (in particular, a Version is required).

Added: 


Modified: 
clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el
clang/tools/clang-format/clang-format.el
clang/tools/clang-rename/clang-rename.el
llvm/utils/emacs/tablegen-mode.el
mlir/utils/emacs/mlir-lsp-client.el
mlir/utils/emacs/mlir-mode.el

Removed: 




diff  --git a/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el 
b/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el
index 272f282c47f5fc..f3a949f8c1b552 100644
--- a/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el
+++ b/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.el
@@ -1,5 +1,6 @@
 ;;; clang-include-fixer.el --- Emacs integration of the clang include fixer  
-*- lexical-binding: t; -*-
 
+;; Version: 0.1.0
 ;; Keywords: tools, c
 ;; Package-Requires: ((cl-lib "0.5") (json "1.2") (let-alist "1.0.4"))
 

diff  --git a/clang/tools/clang-format/clang-format.el 
b/clang/tools/clang-format/clang-format.el
index 30ac7501afcb61..f43bf063c62970 100644
--- a/clang/tools/clang-format/clang-format.el
+++ b/clang/tools/clang-format/clang-format.el
@@ -1,5 +1,6 @@
 ;;; clang-format.el --- Format code using clang-format  -*- lexical-binding: 
t; -*-
 
+;; Version: 0.1.0
 ;; Keywords: tools, c
 ;; Package-Requires: ((cl-lib "0.3"))
 ;; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

diff  --git a/clang/tools/clang-rename/clang-rename.el 
b/clang/tools/clang-rename/clang-rename.el
index b6c3ed4c686b76..3f47c11e2c752e 100644
--- a/clang/tools/clang-rename/clang-rename.el
+++ b/clang/tools/clang-rename/clang-rename.el
@@ -1,5 +1,6 @@
 ;;; clang-rename.el --- Renames every occurrence of a symbol found at 
.  -*- lexical-binding: t; -*-
 
+;; Version: 0.1.0
 ;; Keywords: tools, c
 
 ;;; Commentary:

diff  --git a/llvm/utils/emacs/tablegen-mode.el 
b/llvm/utils/emacs/tablegen-mode.el
index 330da465887053..b1cc1cb36c06e5 100644
--- a/llvm/utils/emacs/tablegen-mode.el
+++ b/llvm/utils/emacs/tablegen-mode.el
@@ -1,6 +1,7 @@
 ;;; tablegen-mode.el --- Major mode for TableGen description files (part of 
LLVM project)
 
 ;; Maintainer:  The LLVM team, http://llvm.org/
+;; Version: 1.0
 
 ;;; Commentary:
 ;; A major mode for TableGen description files in LLVM.

diff  --git a/mlir/utils/emacs/mlir-lsp-client.el 
b/mlir/utils/emacs/mlir-lsp-client.el
index 09dfa835deccdc..4397a55e7206ac 100644
--- a/mlir/utils/emacs/mlir-lsp-client.el
+++ b/mlir/utils/emacs/mlir-lsp-client.el
@@ -14,6 +14,8 @@
 ;; See the License for the specific language governing permissions and
 ;; limitations under the License.
 
+;; Version: 0.1.0
+
 ;;; Commentary:
 
 ;; LSP clinet to use with `mlir-mode' that uses `mlir-lsp-server' or any

diff  --git a/mlir/utils/emacs/mlir-mode.el b/mlir/utils/emacs/mlir-mode.el
index 69056ba3620eb8..e5947df03f86c8 100644
--- a/mlir/utils/emacs/mlir-mode.el
+++ b/mlir/utils/emacs/mlir-mode.el
@@ -14,6 +14,8 @@
 ;; See the License for the specific language governing permissions and
 ;; limitations under the License.
 
+;; Version: 0.1.0
+
 ;;; Commentary:
 
 ;; Major mode for editing MLIR files.
@@ -96,5 +98,4 @@
 (add-to-list 'auto-mode-alist (cons "\\.mlirbc\\'" 'mlir-mode))
 
 (provide 'mlir-mode)
-
 ;;; mlir-mode.el ends here



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


[llvm] [clang] [clang-tools-extra] [mlir] [emacs] Fix Emacs library formatting (PR #76110)

2024-01-10 Thread Benjamin Kramer via cfe-commits

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

I don't know anything about Emacs, but if the version field is required I see 
no harm in adding it.

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


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL requested changes to this pull request.

I'm not fan about this check. For me there is no use case for it.
For sure it's not readability, simply because explicit return is more readable, 
and people who do not know that main by default will return 0 may even consider 
this check a bug, as why all functions got return but not this. Other issue is 
that many projects enable all readability checks, and as this one is 
controversial and not common it shouldn't be under readability, more like misc. 
There are many things that aren't needed, for example compiler is able to 
generate destructor, but still rule of 3/5 require it in some cases to be done 
explicitly, same is with return 0, there could be easily a check that could 
enforce explicit return in all functions, and that would also be readability. 

As for the check:
- wrong name
- wrong category, it should be more a 'misc' for me
- in current form it will catch also 'return 1';
I would say that if this check had to exists (i still cannot find use case for 
it), then it should be configurable to enforce 'return 0' or enforce lack of 
'return 0'. And left configured to an most safe/common approach. What if 
someone wanted to do 'return 1', but forget to put return, and compiler didn't 
warn.

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


[flang] [clang] [flang][driver] Add support for -isysroot in the frontend (PR #77365)

2024-01-10 Thread Leandro Lupori via cfe-commits




luporl wrote:

I guess I was so focused on testing executables on Darwin that I forgot this 
test also applies to other targets.
Let's hope it doesn't introduce a failure on any target.

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


[clang] [Clang][SME2] Fix PSEL builtin predicates (PR #77097)

2024-01-10 Thread Dinar Temirbulatov via cfe-commits

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


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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-10 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From 5d8204ef66bea614d614b5c16a2ddf765402f710 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH] [clang] Fix behavior of __is_trivially_relocatable(volatile
 int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

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

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  9 ++---
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37f8bbc89d8949..0fc10a77a73964 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -664,9 +664,6 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
-- ``__is_trivially_relocatable`` no longer returns true for non-object types
-  such as references and functions.
-  Fixes (`#67498 `_)
 - Fix crash when the object used as a ``static_assert`` message has ``size`` 
or ``data`` members
   which are not member functions.
 - Support UDLs in ``static_assert`` message.
@@ -699,6 +696,12 @@ Bug Fixes in This Version
 - Clang now accepts recursive non-dependent calls to functions with deduced
   return type.
   Fixes (`#71015 `_)
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
+
 - Fix assertion failure when initializing union containing struct with
   flexible array member using empty initializer list.
   Fixes (`#77085 `_)
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index b419fc8836b032..aa797de099b0c9 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2669,6 +2669,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index c5d196a2590f8d..492f08142591a9 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3092,6 +3092,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3103,7 +3105,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // 

[flang] [clang] [flang][driver] Add support for -isysroot in the frontend (PR #77365)

2024-01-10 Thread Leandro Lupori via cfe-commits

luporl wrote:

Thanks for the review and all the suggestions!

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


[flang] [clang] [flang][driver] Add support for -isysroot in the frontend (PR #77365)

2024-01-10 Thread Leandro Lupori via cfe-commits

https://github.com/luporl updated 
https://github.com/llvm/llvm-project/pull/77365

>From 01a2a8d315af2edb9fe3f0c9b57b5c74935521f1 Mon Sep 17 00:00:00 2001
From: Leandro Lupori 
Date: Mon, 8 Jan 2024 16:37:54 -0300
Subject: [PATCH 1/7] [flang][driver] Add support for -isysroot in the frontend

If DEFAULT_SYSROOT is not specfied when building flang, then the
-isysroot flag is needed to link binaries against system libraries
on Darwin. It's also needed when linking against a non-default
sysroot.
---
 clang/include/clang/Driver/Options.td|  2 +-
 flang/test/Driver/driver-help-hidden.f90 |  1 +
 flang/test/Driver/driver-help.f90|  1 +
 flang/test/Driver/isysroot.f90   | 12 
 4 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/isysroot.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6aff37f1336871..f42e9c7eb92a67 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4265,7 +4265,7 @@ def iquote : JoinedOrSeparate<["-"], "iquote">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Add directory to QUOTE include search path">, 
MetaVarName<"">;
 def isysroot : JoinedOrSeparate<["-"], "isysroot">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption]>,
   HelpText<"Set the system root directory (usually /)">, MetaVarName<"">,
   MarshallingInfoString, [{"/"}]>;
 def isystem : JoinedOrSeparate<["-"], "isystem">, Group,
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 9a11a7a571ffcc..aca043d0ea 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -111,6 +111,7 @@
 ! CHECK-NEXT: -g  Generate source-level debug information
 ! CHECK-NEXT: --help-hidden   Display help for hidden options
 ! CHECK-NEXT: -help   Display available options
+! CHECK-NEXT: -isysroot  Set the system root directory (usually /)
 ! CHECK-NEXT: -I Add directory to the end of the list of 
include search paths
 ! CHECK-NEXT: -L Add directory to library search path
 ! CHECK-NEXT: -march=  For a list of available architectures 
for the target use '-mcpu=help'
diff --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index e0e74dc56f331e..07189264104592 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -97,6 +97,7 @@
 ! HELP-NEXT: -g  Generate source-level debug information
 ! HELP-NEXT: --help-hidden   Display help for hidden options
 ! HELP-NEXT: -help   Display available options
+! HELP-NEXT: -isysroot  Set the system root directory (usually /)
 ! HELP-NEXT: -I Add directory to the end of the list of 
include search paths
 ! HELP-NEXT: -L Add directory to library search path
 ! HELP-NEXT: -march=  For a list of available architectures for 
the target use '-mcpu=help'
diff --git a/flang/test/Driver/isysroot.f90 b/flang/test/Driver/isysroot.f90
new file mode 100644
index 00..70d2fc0345ce50
--- /dev/null
+++ b/flang/test/Driver/isysroot.f90
@@ -0,0 +1,12 @@
+! Verify that the -isysroot flag is known to the frontend and, on Darwin,
+! is passed on to the linker.
+
+! RUN: %flang -### --target=aarch64-apple-darwin -isysroot /path/to/sysroot \
+! RUN:%s 2>&1 | FileCheck %s --check-prefix=CHECK-DARWIN
+! RUN: %flang -### --target=aarch64-linux-gnu -isysroot /path/to/sysroot \
+! RUN:%s 2>&1 | FileCheck %s --check-prefix=CHECK-LINUX
+
+! CHECK-DARWIN: "{{.*}}/ld" {{.*}}"-syslibroot" "/path/to/sysroot"
+! Unused on Linux.
+! CHECK-LINUX: warning: argument unused during compilation: '-isysroot 
/path/to/sysroot'
+! CHECK-LINUX-NOT: /path/to/sysroot

>From b12c6abdffcdf1972db6b1ec59c910c92eb38f9d Mon Sep 17 00:00:00 2001
From: Leandro Lupori 
Date: Tue, 9 Jan 2024 08:45:10 -0300
Subject: [PATCH 2/7] Fix test on Windows

---
 flang/test/Driver/isysroot.f90 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/test/Driver/isysroot.f90 b/flang/test/Driver/isysroot.f90
index 70d2fc0345ce50..b3871b352fcfb2 100644
--- a/flang/test/Driver/isysroot.f90
+++ b/flang/test/Driver/isysroot.f90
@@ -6,7 +6,7 @@
 ! RUN: %flang -### --target=aarch64-linux-gnu -isysroot /path/to/sysroot \
 ! RUN:%s 2>&1 | FileCheck %s --check-prefix=CHECK-LINUX
 
-! CHECK-DARWIN: "{{.*}}/ld" {{.*}}"-syslibroot" "/path/to/sysroot"
+! CHECK-DARWIN: "{{.*[\/]}}ld" {{.*}}"-syslibroot" "/path/to/sysroot"
 ! Unused on Linux.
 ! CHECK-LINUX: warning: argument unused during compilation: '-isysroot 
/path/to/sysroot'
 ! CHECK-LINUX-NOT: /path/to/sysroot

>From c47d15b3e947e4a55de8b7c276dca1eacfa7caa4 Mon Sep 17 00:00:00 2001
From: Leandro Lupori 
Date: Tue, 9 Jan 2024 

[clang] [Clang][SME2] Fix PSEL builtin predicates (PR #77097)

2024-01-10 Thread Dinar Temirbulatov via cfe-commits

dtemirbulatov wrote:

LGTM.

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


[clang-tools-extra] [llvm] [clang] [AMDGPU][GFX12] Default component broadcast store (PR #76212)

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

mariusz-sikora-at-amd wrote:

ping @arsenm 

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


[clang] [AArch64][SME2] Fix SME2 mla/mls tests (PR #76711)

2024-01-10 Thread Matthew Devereau via cfe-commits


@@ -494,7 +494,7 @@ void test_svmls_lane1_f16(uint32_t slice_base, svfloat16_t 
zn, svfloat16_t zm) _
 //
 void test_svmls_lane1_bf16(uint32_t slice_base, svbfloat16_t zn, svbfloat16_t 
zm) __arm_streaming __arm_shared_za
 {
-   SVE_ACLE_FUNC(svmls_lane_za32,,_bf16,,_vg2x1)(slice_base, zn, zm, 7);
+   SVE_ACLE_FUNC(svmls_lane_za32,_bf16,_vg2x1,,)(slice_base, zn, zm, 7);

MDevereau wrote:

Oops. Fixed.

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


[clang] [AArch64][SME2] Fix SME2 mla/mls tests (PR #76711)

2024-01-10 Thread Matthew Devereau via cfe-commits


@@ -460,7 +460,7 @@ void test_svmla_single4_u16(uint32_t slice_base, 
svuint16x4_t zn, svuint16_t zm)
 //
 void test_svmla_single4_s16(uint32_t slice_base, svint16x4_t zn, svint16_t zm) 
__arm_streaming __arm_shared_za
 {
-   SVE_ACLE_FUNC(svmla_single_za32,,_s16,,_vg2x4)(slice_base, zn, zm);
+   SVE_ACLE_FUNC(svmla,_single,_za32,_s16,_vg2x4)(slice_base, zn, zm);
 }

MDevereau wrote:

It was trivial to change them so I just went ahead and did it.

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


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Congcong Cai via cfe-commits


@@ -0,0 +1,50 @@
+//===--- DonotreturnzerocheckCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DonotreturnzerocheckCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+bool isCPlusPlusOrC99(const LangOptions ) {
+  return LangOpts.CPlusPlus || LangOpts.C99;
+}
+
+void DonotreturnzerocheckCheck::registerMatchers(MatchFinder *Finder) {
+  // FIXME: Add matchers.
+  Finder->addMatcher(
+  functionDecl(isMain(), returns(asString("int"))).bind("main"), this);
+}
+
+void DonotreturnzerocheckCheck::check(const MatchFinder::MatchResult ) {
+  // FIXME: Add callback implementation.
+  const auto *MatchedDecl = Result.Nodes.getNodeAs("main");
+  if (isCPlusPlusOrC99(Result.Context->getLangOpts())) {
+SourceLocation ReturnLoc;
+if (MatchedDecl->hasBody()) {
+  const CompoundStmt *Body = 
dyn_cast(MatchedDecl->getBody());
+  if (Body && !Body->body_empty()) {
+const Stmt *LastStmt = Body->body_back();
+if (const auto *Return = dyn_cast(LastStmt)) {
+  ReturnLoc = Return->getReturnLoc();
+}

HerrCai0907 wrote:

redundant brace

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


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Congcong Cai via cfe-commits


@@ -0,0 +1,50 @@
+//===--- DonotreturnzerocheckCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DonotreturnzerocheckCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+bool isCPlusPlusOrC99(const LangOptions ) {
+  return LangOpts.CPlusPlus || LangOpts.C99;
+}
+
+void DonotreturnzerocheckCheck::registerMatchers(MatchFinder *Finder) {
+  // FIXME: Add matchers.
+  Finder->addMatcher(
+  functionDecl(isMain(), returns(asString("int"))).bind("main"), this);
+}
+
+void DonotreturnzerocheckCheck::check(const MatchFinder::MatchResult ) {
+  // FIXME: Add callback implementation.
+  const auto *MatchedDecl = Result.Nodes.getNodeAs("main");
+  if (isCPlusPlusOrC99(Result.Context->getLangOpts())) {

HerrCai0907 wrote:

move it to `bool isLanguageVersionSupported(const LangOptions ) const 
override`

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


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Congcong Cai via cfe-commits


@@ -0,0 +1,30 @@
+//===--- DonotreturnzerocheckCheck.h - clang-tidy ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DONOTRETURNZEROCHECKCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DONOTRETURNZEROCHECKCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::readability {
+
+/// FIXME: Write a short description.

HerrCai0907 wrote:

Copy description from docs

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


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Congcong Cai via cfe-commits


@@ -0,0 +1,50 @@
+//===--- DonotreturnzerocheckCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DonotreturnzerocheckCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+bool isCPlusPlusOrC99(const LangOptions ) {
+  return LangOpts.CPlusPlus || LangOpts.C99;
+}
+
+void DonotreturnzerocheckCheck::registerMatchers(MatchFinder *Finder) {
+  // FIXME: Add matchers.
+  Finder->addMatcher(
+  functionDecl(isMain(), returns(asString("int"))).bind("main"), this);
+}
+
+void DonotreturnzerocheckCheck::check(const MatchFinder::MatchResult ) {
+  // FIXME: Add callback implementation.

HerrCai0907 wrote:

clean code

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


[clang] [AArch64][SME2] Fix SME2 mla/mls tests (PR #76711)

2024-01-10 Thread Matthew Devereau via cfe-commits

https://github.com/MDevereau updated 
https://github.com/llvm/llvm-project/pull/76711

>From 908da224bd01e4758392a98ba2191185d7296c6a Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Tue, 2 Jan 2024 11:36:33 +
Subject: [PATCH 1/4] [AArch64][SME2] Fix SME2 mla/mls tests

The ACLE defines these builtins as svmla[_single]_za32[_f32]_vg1x2,
which means the SVE_ACLE_FUNC macro should test the overloaded forms as

SVE_ACLE_FUNC(svmla,_single,_za32,_f32,_vg1x2)

https://github.com/ARM-software/acle/blob/b88cbf7e9c104100bb5016c848763171494dee44/main/acle.md?plain=1#L10170-L10205
---
 .../test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c  | 8 
 .../test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mls.c  | 8 
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c
index f52edd9888daa9..2679f9cc8dfd0c 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c
@@ -86,7 +86,7 @@ void test_svmla4_f32(uint32_t slice_base, svfloat32x4_t zn, 
svfloat32x4_t zm) __
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmla_single2_f32(uint32_t slice_base, svfloat32x2_t zn, svfloat32_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmla_single_za32,,_f32,,_vg1x2)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmla,_single,_za32,_f32,_vg1x2)(slice_base, zn, zm);
 }
 
 // CHECK-LABEL: @test_svmla_single4_f32(
@@ -108,7 +108,7 @@ void test_svmla_single2_f32(uint32_t slice_base, 
svfloat32x2_t zn, svfloat32_t z
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmla_single4_f32(uint32_t slice_base, svfloat32x4_t zn, svfloat32_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmla_single_za32,,_f32,,_vg1x4)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmla,_single,_za32,_f32,_vg1x4)(slice_base, zn, zm);
 }
 
 //
@@ -224,7 +224,7 @@ void test_svmla4_f64(uint32_t slice_base, svfloat64x4_t zn, 
svfloat64x4_t zm) __
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmla_single2_f64(uint32_t slice_base, svfloat64x2_t zn, svfloat64_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmla_single_za64,,_f64,,_vg1x2)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmla,_single,_za64,_f64,_vg1x2)(slice_base, zn, zm);
 }
 
 // CHECK-LABEL: @test_svmla_single4_f64(
@@ -246,7 +246,7 @@ void test_svmla_single2_f64(uint32_t slice_base, 
svfloat64x2_t zn, svfloat64_t z
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmla_single4_f64(uint32_t slice_base, svfloat64x4_t zn, svfloat64_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmla_single_za64,,_f64,,_vg1x4)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmla,_single,_za64,_f64,_vg1x4)(slice_base, zn, zm);
 }
 
 //
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mls.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mls.c
index 6830a399e91d64..bb4cbbd5308c06 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mls.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mls.c
@@ -86,7 +86,7 @@ void test_svmls4_f32(uint32_t slice_base, svfloat32x4_t zn, 
svfloat32x4_t zm) __
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmls_single2_f32(uint32_t slice_base, svfloat32x2_t zn, svfloat32_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmls_single_za32,,_f32,,_vg1x2)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmls,_single,_za32,_f32,_vg1x2)(slice_base, zn, zm);
 }
 
 // CHECK-LABEL: @test_svmls_single4_f32(
@@ -108,7 +108,7 @@ void test_svmls_single2_f32(uint32_t slice_base, 
svfloat32x2_t zn, svfloat32_t z
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmls_single4_f32(uint32_t slice_base, svfloat32x4_t zn, svfloat32_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmls_single_za32,,_f32,,_vg1x4)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmls,_single,_za32,_f32,_vg1x4)(slice_base, zn, zm);
 }
 
 //
@@ -224,7 +224,7 @@ void test_svmls4_f64(uint32_t slice_base, svfloat64x4_t zn, 
svfloat64x4_t zm) __
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmls_single2_f64(uint32_t slice_base, svfloat64x2_t zn, svfloat64_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmls_single_za64,,_f64,,_vg1x2)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmls,_single,_za64,_f64,_vg1x2)(slice_base, zn, zm);
 }
 
 // CHECK-LABEL: @test_svmls_single4_f64(
@@ -246,7 +246,7 @@ void test_svmls_single2_f64(uint32_t slice_base, 
svfloat64x2_t zn, svfloat64_t z
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmls_single4_f64(uint32_t slice_base, svfloat64x4_t zn, svfloat64_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmls_single_za64,,_f64,,_vg1x4)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmls,_single,_za64,_f64,_vg1x4)(slice_base, zn, zm);
 }
 
 //

>From e09efe2659db596a60b61f984648fd9fb37b2a9c Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Thu, 4 Jan 2024 16:47:17 +
Subject: [PATCH 2/4] Update acle_sme2_mlal.c, 

[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-01-10 Thread Amirreza Ashouri via cfe-commits

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


[clang] [AArch64][SME2] Fix SME2 mla/mls tests (PR #76711)

2024-01-10 Thread Matthew Devereau via cfe-commits

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


[clang] [AArch64][SME2] Fix SME2 mla/mls tests (PR #76711)

2024-01-10 Thread Matthew Devereau via cfe-commits

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


[clang] [AArch64][SME2] Fix SME2 mla/mls tests (PR #76711)

2024-01-10 Thread Matthew Devereau via cfe-commits


@@ -460,7 +460,7 @@ void test_svmla_single4_u16(uint32_t slice_base, 
svuint16x4_t zn, svuint16_t zm)
 //
 void test_svmla_single4_s16(uint32_t slice_base, svint16x4_t zn, svint16_t zm) 
__arm_streaming __arm_shared_za
 {
-   SVE_ACLE_FUNC(svmla_single_za32,,_s16,,_vg2x4)(slice_base, zn, zm);
+   SVE_ACLE_FUNC(svmla,_single,_za32,_s16,_vg2x4)(slice_base, zn, zm);
 }

MDevereau wrote:

Since `SVE_ACLE_FUNC` is defined as 
`SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED,A5) A1##A3##A5` The svmla_lane test
`SVE_ACLE_FUNC(svmla_lane_za32,,,_s16,_vg2x4)(slice_base, zn, zm, 7);`
is functionally the same as
`SVE_ACLE_FUNC(svmla_lane_za32,_s16,_vg2x4,,,)(slice_base, zn, zm, 7);`
which is why I didn't update these tests earlier. Do we still want the commas 
to be pushed to the back?

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


[clang] [flang] [Flang] Support -mrvv-vector-bits flag (PR #77588)

2024-01-10 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-flang-driver

@llvm/pr-subscribers-clang

Author: Luke Lau (lukel97)


Changes

This patch adds support for the -mrvv-vector-bits flag in the Flang driver, and
translates them to -mvscale-min/-mvscale-max.

The code was copied from the Clang toolchain (similarly to what was done for
AArch64's -msve-vector-bits flag) so it also supports the same
-mrvv-vector-bits=zvl mode.

Note that Flang doesn't yet define the __riscv_v_fixed_vlen macro, so the help
text has been updated to highlight that it's only defined for Clang.


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


6 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+4-2) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+51) 
- (modified) clang/lib/Driver/ToolChains/Flang.h (+7) 
- (modified) flang/test/Driver/driver-help-hidden.f90 (+2) 
- (modified) flang/test/Driver/driver-help.f90 (+2) 
- (added) flang/test/Driver/riscv-rvv-vector-bits.f90 (+51) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bffdddc28aac60..4de738ef27ae8b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4585,11 +4585,13 @@ let Flags = [TargetSpecific] in {
 def menable_experimental_extensions : Flag<["-"], 
"menable-experimental-extensions">, Group,
   HelpText<"Enable use of experimental RISC-V extensions.">;
 def mrvv_vector_bits_EQ : Joined<["-"], "mrvv-vector-bits=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Specify the size in bits of an RVV vector register. Defaults to "
"the vector length agnostic value of \"scalable\". Accepts power of 
"
"2 values between 64 and 65536. Also accepts \"zvl\" "
-   "to use the value implied by -march/-mcpu. Value will be reflected "
-   "in __riscv_v_fixed_vlen preprocessor define (RISC-V only)">;
+   "to use the value implied by -march/-mcpu. On Clang, value will be "
+   "reflected in __riscv_v_fixed_vlen preprocessor define (RISC-V "
+   "only)">;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group,
   HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 41eaad3bbad0a3..ccb9f75e21e558 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "Flang.h"
+#include "Arch/RISCV.h"
 #include "CommonArgs.h"
 
 #include "clang/Basic/CodeGenOptions.h"
@@ -14,6 +15,8 @@
 #include "llvm/Frontend/Debug/Options.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 
 #include 
 
@@ -203,6 +206,51 @@ void Flang::AddAArch64TargetArgs(const ArgList ,
   }
 }
 
+void Flang::AddRISCVTargetArgs(const ArgList ,
+   ArgStringList ) const {
+  const llvm::Triple  = getToolChain().getTriple();
+  // Handle -mrvv-vector-bits=
+  if (Arg *A = Args.getLastArg(options::OPT_mrvv_vector_bits_EQ)) {
+StringRef Val = A->getValue();
+const Driver  = getToolChain().getDriver();
+
+// Get minimum VLen from march.
+unsigned MinVLen = 0;
+StringRef Arch = riscv::getRISCVArch(Args, Triple);
+auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
+Arch, /*EnableExperimentalExtensions*/ true);
+// Ignore parsing error.
+if (!errorToBool(ISAInfo.takeError()))
+  MinVLen = (*ISAInfo)->getMinVLen();
+
+// If the value is "zvl", use MinVLen from march. Otherwise, try to parse
+// as integer as long as we have a MinVLen.
+unsigned Bits = 0;
+if (Val.equals("zvl") && MinVLen >= llvm::RISCV::RVVBitsPerBlock) {
+  Bits = MinVLen;
+} else if (!Val.getAsInteger(10, Bits)) {
+  // Only accept power of 2 values beteen RVVBitsPerBlock and 65536 that
+  // at least MinVLen.
+  if (Bits < MinVLen || Bits < llvm::RISCV::RVVBitsPerBlock ||
+  Bits > 65536 || !llvm::isPowerOf2_32(Bits))
+Bits = 0;
+}
+
+// If we got a valid value try to use it.
+if (Bits != 0) {
+  unsigned VScaleMin = Bits / llvm::RISCV::RVVBitsPerBlock;
+  CmdArgs.push_back(
+  Args.MakeArgString("-mvscale-max=" + llvm::Twine(VScaleMin)));
+  CmdArgs.push_back(
+  Args.MakeArgString("-mvscale-min=" + llvm::Twine(VScaleMin)));
+} else if (!Val.equals("scalable")) {
+  // Handle the unsupported values passed to mrvv-vector-bits.
+  D.Diag(diag::err_drv_unsupported_option_argument)
+  << A->getSpelling() << Val;
+}
+  }
+}
+
 static void addVSDefines(const ToolChain , const ArgList ,
  ArgStringList ) {
 
@@ -321,6 +369,9 @@ void 

[clang] [flang] [Flang] Support -mrvv-vector-bits flag (PR #77588)

2024-01-10 Thread Luke Lau via cfe-commits

https://github.com/lukel97 created 
https://github.com/llvm/llvm-project/pull/77588

This patch adds support for the -mrvv-vector-bits flag in the Flang driver, and
translates them to -mvscale-min/-mvscale-max.

The code was copied from the Clang toolchain (similarly to what was done for
AArch64's -msve-vector-bits flag) so it also supports the same
-mrvv-vector-bits=zvl mode.

Note that Flang doesn't yet define the __riscv_v_fixed_vlen macro, so the help
text has been updated to highlight that it's only defined for Clang.


>From 66f47b300afa5f68934c93fed0b16d7a389cf49d Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Wed, 10 Jan 2024 18:22:03 +0700
Subject: [PATCH] [Flang] Support -mrvv-vector-bits flag

This patch adds support for the -mrvv-vector-bits flag in the Flang driver, and
translates them to -mvscale-min/-mvscale-max.

The code was copied from the Clang toolchain (similarly to what was done for
AArch64's -msve-vector-bits flag) so it also supports the same
-mrvv-vector-bits=zvl mode.

Note that Flang doesn't yet define the __riscv_v_fixed_vlen macro, so the help
text has been updated to highlight that it's only defined for Clang.
---
 clang/include/clang/Driver/Options.td   |  6 ++-
 clang/lib/Driver/ToolChains/Flang.cpp   | 51 +
 clang/lib/Driver/ToolChains/Flang.h |  7 +++
 flang/test/Driver/driver-help-hidden.f90|  2 +
 flang/test/Driver/driver-help.f90   |  2 +
 flang/test/Driver/riscv-rvv-vector-bits.f90 | 51 +
 6 files changed, 117 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Driver/riscv-rvv-vector-bits.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bffdddc28aac60..4de738ef27ae8b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4585,11 +4585,13 @@ let Flags = [TargetSpecific] in {
 def menable_experimental_extensions : Flag<["-"], 
"menable-experimental-extensions">, Group,
   HelpText<"Enable use of experimental RISC-V extensions.">;
 def mrvv_vector_bits_EQ : Joined<["-"], "mrvv-vector-bits=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Specify the size in bits of an RVV vector register. Defaults to "
"the vector length agnostic value of \"scalable\". Accepts power of 
"
"2 values between 64 and 65536. Also accepts \"zvl\" "
-   "to use the value implied by -march/-mcpu. Value will be reflected "
-   "in __riscv_v_fixed_vlen preprocessor define (RISC-V only)">;
+   "to use the value implied by -march/-mcpu. On Clang, value will be "
+   "reflected in __riscv_v_fixed_vlen preprocessor define (RISC-V "
+   "only)">;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group,
   HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 41eaad3bbad0a3..ccb9f75e21e558 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "Flang.h"
+#include "Arch/RISCV.h"
 #include "CommonArgs.h"
 
 #include "clang/Basic/CodeGenOptions.h"
@@ -14,6 +15,8 @@
 #include "llvm/Frontend/Debug/Options.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 
 #include 
 
@@ -203,6 +206,51 @@ void Flang::AddAArch64TargetArgs(const ArgList ,
   }
 }
 
+void Flang::AddRISCVTargetArgs(const ArgList ,
+   ArgStringList ) const {
+  const llvm::Triple  = getToolChain().getTriple();
+  // Handle -mrvv-vector-bits=
+  if (Arg *A = Args.getLastArg(options::OPT_mrvv_vector_bits_EQ)) {
+StringRef Val = A->getValue();
+const Driver  = getToolChain().getDriver();
+
+// Get minimum VLen from march.
+unsigned MinVLen = 0;
+StringRef Arch = riscv::getRISCVArch(Args, Triple);
+auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
+Arch, /*EnableExperimentalExtensions*/ true);
+// Ignore parsing error.
+if (!errorToBool(ISAInfo.takeError()))
+  MinVLen = (*ISAInfo)->getMinVLen();
+
+// If the value is "zvl", use MinVLen from march. Otherwise, try to parse
+// as integer as long as we have a MinVLen.
+unsigned Bits = 0;
+if (Val.equals("zvl") && MinVLen >= llvm::RISCV::RVVBitsPerBlock) {
+  Bits = MinVLen;
+} else if (!Val.getAsInteger(10, Bits)) {
+  // Only accept power of 2 values beteen RVVBitsPerBlock and 65536 that
+  // at least MinVLen.
+  if (Bits < MinVLen || Bits < llvm::RISCV::RVVBitsPerBlock ||
+  Bits > 65536 || !llvm::isPowerOf2_32(Bits))
+Bits = 0;
+}
+
+// If we got a valid value try to use it.
+if (Bits != 0) {
+  

[clang] [clang]not lookup name containing a dependent type (PR #77587)

2024-01-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Congcong Cai (HerrCai0907)


Changes

Fixes: #77583
bcd51aaaf8bde4b0ae7a4155d9ce3dec78fe2598 fixed part of template instantiation 
dependent name issues but still missing some cases This patch want to enhance 
the dependent name check

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaExprMember.cpp (+2-1) 
- (modified) clang/test/SemaCXX/conversion-function.cpp (+11-3) 


``diff
diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 2abec3d86a27d9..32998ae60eafe2 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -782,7 +782,8 @@ Sema::BuildMemberReferenceExpr(Expr *Base, QualType 
BaseType,
const Scope *S,
ActOnMemberAccessExtraArgs *ExtraArgs) {
   if (BaseType->isDependentType() ||
-  (SS.isSet() && isDependentScopeSpecifier(SS)))
+  (SS.isSet() && isDependentScopeSpecifier(SS)) ||
+  NameInfo.getName().isDependentName())
 return ActOnDependentMemberExpr(Base, BaseType,
 IsArrow, OpLoc,
 SS, TemplateKWLoc, FirstQualifierInScope,
diff --git a/clang/test/SemaCXX/conversion-function.cpp 
b/clang/test/SemaCXX/conversion-function.cpp
index b6e6142d179066..220ae78f2d8246 100644
--- a/clang/test/SemaCXX/conversion-function.cpp
+++ b/clang/test/SemaCXX/conversion-function.cpp
@@ -475,13 +475,21 @@ struct S {
 
 #if __cplusplus >= 201103L
 namespace dependent_conversion_function_id_lookup {
-  template struct A {
+  struct A1 {
+operator int();
+  };
+  template struct C {
+template  using Lookup = decltype(T{}.operator U());
+  };
+  C v{};
+
+  template struct A2 {
 operator T();
   };
-  template struct B : A {
+  template struct B : A2 {
 template using Lookup = decltype(::operator U);
   };
   using Result = B::Lookup;
-  using Result = int (A::*)();
+  using Result = int (A2::*)();
 }
 #endif

``




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


[clang] [clang]not lookup name containing a dependent type (PR #77587)

2024-01-10 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/77587

Fixes: #77583
bcd51aaaf8bde4b0ae7a4155d9ce3dec78fe2598 fixed part of template instantiation 
dependent name issues but still missing some cases This patch want to enhance 
the dependent name check

>From f6b9afa26fabb5f9dcea5615c92914bed93ef474 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 10 Jan 2024 19:27:31 +0800
Subject: [PATCH] [clang]not lookup name containing a dependent type

Fixes: #77583
bcd51aaaf8bde4b0ae7a4155d9ce3dec78fe2598 fixed part of template instantiation 
dependent name issues but still missing some cases
This patch want to enhance the dependent name check
---
 clang/lib/Sema/SemaExprMember.cpp  |  3 ++-
 clang/test/SemaCXX/conversion-function.cpp | 14 +++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 2abec3d86a27d9..32998ae60eafe2 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -782,7 +782,8 @@ Sema::BuildMemberReferenceExpr(Expr *Base, QualType 
BaseType,
const Scope *S,
ActOnMemberAccessExtraArgs *ExtraArgs) {
   if (BaseType->isDependentType() ||
-  (SS.isSet() && isDependentScopeSpecifier(SS)))
+  (SS.isSet() && isDependentScopeSpecifier(SS)) ||
+  NameInfo.getName().isDependentName())
 return ActOnDependentMemberExpr(Base, BaseType,
 IsArrow, OpLoc,
 SS, TemplateKWLoc, FirstQualifierInScope,
diff --git a/clang/test/SemaCXX/conversion-function.cpp 
b/clang/test/SemaCXX/conversion-function.cpp
index b6e6142d179066..220ae78f2d8246 100644
--- a/clang/test/SemaCXX/conversion-function.cpp
+++ b/clang/test/SemaCXX/conversion-function.cpp
@@ -475,13 +475,21 @@ struct S {
 
 #if __cplusplus >= 201103L
 namespace dependent_conversion_function_id_lookup {
-  template struct A {
+  struct A1 {
+operator int();
+  };
+  template struct C {
+template  using Lookup = decltype(T{}.operator U());
+  };
+  C v{};
+
+  template struct A2 {
 operator T();
   };
-  template struct B : A {
+  template struct B : A2 {
 template using Lookup = decltype(::operator U);
   };
   using Result = B::Lookup;
-  using Result = int (A::*)();
+  using Result = int (A2::*)();
 }
 #endif

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


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 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 8f78dd4b92b44c490d263a4d161850853874859d 
bae95013cd7f937a5496cafcd40a77cc563addb0 -- 
clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp 
clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h 
clang-tools-extra/test/clang-tidy/checkers/readability/DoNotReturnZeroCheck.cpp 
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
index 66ea29be3c..4a741940bf 100644
--- a/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
@@ -12,24 +12,21 @@
 
 using namespace clang::ast_matchers;
 
-
-
 namespace clang::tidy::readability {
-  bool isCPlusPlusOrC99(const LangOptions ) {
+bool isCPlusPlusOrC99(const LangOptions ) {
   return LangOpts.CPlusPlus || LangOpts.C99;
-  }
+}
 
 void DonotreturnzerocheckCheck::registerMatchers(MatchFinder *Finder) {
   // FIXME: Add matchers.
-  Finder->addMatcher(functionDecl(
-isMain(),returns(asString("int"))
-  ).bind("main"), this);
+  Finder->addMatcher(
+  functionDecl(isMain(), returns(asString("int"))).bind("main"), this);
 }
 
 void DonotreturnzerocheckCheck::check(const MatchFinder::MatchResult ) {
   // FIXME: Add callback implementation.
   const auto *MatchedDecl = Result.Nodes.getNodeAs("main");
-  if(isCPlusPlusOrC99(Result.Context->getLangOpts())){
+  if (isCPlusPlusOrC99(Result.Context->getLangOpts())) {
 SourceLocation ReturnLoc;
 if (MatchedDecl->hasBody()) {
   const CompoundStmt *Body = 
dyn_cast(MatchedDecl->getBody());
@@ -44,11 +41,10 @@ void DonotreturnzerocheckCheck::check(const 
MatchFinder::MatchResult ) {
 if (ReturnLoc.isValid()) {
   // Suggest removal of the redundant return statement.
   diag(ReturnLoc, "redundant 'return 0;' at the end of main")
-  << 
FixItHint::CreateRemoval(CharSourceRange::getTokenRange(ReturnLoc));
+  << FixItHint::CreateRemoval(
+ CharSourceRange::getTokenRange(ReturnLoc));
 }
-
   }
-
 }
 
-}
\ No newline at end of file
+} // namespace clang::tidy::readability
\ No newline at end of file

``




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


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/77586

>From bae95013cd7f937a5496cafcd40a77cc563addb0 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Wed, 10 Jan 2024 16:48:43 +0530
Subject: [PATCH 1/2] Added check for redundant return statement

Signed-off-by: 11happy 
---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/DonotreturnzerocheckCheck.cpp | 54 +++
 .../readability/DonotreturnzerocheckCheck.h   | 30 +++
 .../readability/ReadabilityTidyModule.cpp |  3 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  8 +++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../readability/DoNotReturnZeroCheck.rst  | 25 +
 .../readability/DoNotReturnZeroCheck.cpp  |  8 +++
 8 files changed, 130 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/DoNotReturnZeroCheck.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/DoNotReturnZeroCheck.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 408c822b861c5f..cb7741d6f56ce7 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -14,6 +14,7 @@ add_clang_library(clangTidyReadabilityModule
   ContainerSizeEmptyCheck.cpp
   ConvertMemberFunctionsToStatic.cpp
   DeleteNullPointerCheck.cpp
+  DonotreturnzerocheckCheck.cpp
   DuplicateIncludeCheck.cpp
   ElseAfterReturnCheck.cpp
   FunctionCognitiveComplexityCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
new file mode 100644
index 00..66ea29be3c54a8
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
@@ -0,0 +1,54 @@
+//===--- DonotreturnzerocheckCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DonotreturnzerocheckCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+
+
+namespace clang::tidy::readability {
+  bool isCPlusPlusOrC99(const LangOptions ) {
+  return LangOpts.CPlusPlus || LangOpts.C99;
+  }
+
+void DonotreturnzerocheckCheck::registerMatchers(MatchFinder *Finder) {
+  // FIXME: Add matchers.
+  Finder->addMatcher(functionDecl(
+isMain(),returns(asString("int"))
+  ).bind("main"), this);
+}
+
+void DonotreturnzerocheckCheck::check(const MatchFinder::MatchResult ) {
+  // FIXME: Add callback implementation.
+  const auto *MatchedDecl = Result.Nodes.getNodeAs("main");
+  if(isCPlusPlusOrC99(Result.Context->getLangOpts())){
+SourceLocation ReturnLoc;
+if (MatchedDecl->hasBody()) {
+  const CompoundStmt *Body = 
dyn_cast(MatchedDecl->getBody());
+  if (Body && !Body->body_empty()) {
+const Stmt *LastStmt = Body->body_back();
+if (const auto *Return = dyn_cast(LastStmt)) {
+  ReturnLoc = Return->getReturnLoc();
+}
+  }
+}
+
+if (ReturnLoc.isValid()) {
+  // Suggest removal of the redundant return statement.
+  diag(ReturnLoc, "redundant 'return 0;' at the end of main")
+  << 
FixItHint::CreateRemoval(CharSourceRange::getTokenRange(ReturnLoc));
+}
+
+  }
+
+}
+
+}
\ No newline at end of file
diff --git 
a/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h 
b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h
new file mode 100644
index 00..1407b8c1831c9d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h
@@ -0,0 +1,30 @@
+//===--- DonotreturnzerocheckCheck.h - clang-tidy ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DONOTRETURNZEROCHECKCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DONOTRETURNZEROCHECKCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::readability {
+
+/// FIXME: Write a short description.
+///
+/// For the user-facing documentation see:
+/// 

[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Bhuminjay Soni (11happy)


Changes

**Overview:**
This pull request fixes #38469 where the issue proposes a new static 
analysis check in C++ to discourage the explicit return 0; statement at the end 
of the main() function. As C++ automatically assumes a return 0; in this 
context, having the explicit statement is redundant. The suggested change aims 
to enhance code readability by eliminating unnecessary lines in the main() 
function.

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.
![Screenshot from 2024-01-10 
16-53-31](https://github.com/llvm/llvm-project/assets/76656712/818d347e-7325-4d4d-aa0c-bcc611f46931)



**Dependencies:**
- No dependencies on other pull requests.

**CC:**
- @kirillbobyrev  , @AaronBallman 


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


8 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/CMakeLists.txt (+1) 
- (added) 
clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp (+54) 
- (added) clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h 
(+30) 
- (modified) clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
(+3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+8) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/readability/DoNotReturnZeroCheck.rst 
(+25) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/DoNotReturnZeroCheck.cpp 
(+8) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 408c822b861c5f..cb7741d6f56ce7 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -14,6 +14,7 @@ add_clang_library(clangTidyReadabilityModule
   ContainerSizeEmptyCheck.cpp
   ConvertMemberFunctionsToStatic.cpp
   DeleteNullPointerCheck.cpp
+  DonotreturnzerocheckCheck.cpp
   DuplicateIncludeCheck.cpp
   ElseAfterReturnCheck.cpp
   FunctionCognitiveComplexityCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
new file mode 100644
index 00..66ea29be3c54a8
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
@@ -0,0 +1,54 @@
+//===--- DonotreturnzerocheckCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DonotreturnzerocheckCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+
+
+namespace clang::tidy::readability {
+  bool isCPlusPlusOrC99(const LangOptions ) {
+  return LangOpts.CPlusPlus || LangOpts.C99;
+  }
+
+void DonotreturnzerocheckCheck::registerMatchers(MatchFinder *Finder) {
+  // FIXME: Add matchers.
+  Finder->addMatcher(functionDecl(
+isMain(),returns(asString("int"))
+  ).bind("main"), this);
+}
+
+void DonotreturnzerocheckCheck::check(const MatchFinder::MatchResult ) {
+  // FIXME: Add callback implementation.
+  const auto *MatchedDecl = Result.Nodes.getNodeAs("main");
+  if(isCPlusPlusOrC99(Result.Context->getLangOpts())){
+SourceLocation ReturnLoc;
+if (MatchedDecl->hasBody()) {
+  const CompoundStmt *Body = 
dyn_cast(MatchedDecl->getBody());
+  if (Body && !Body->body_empty()) {
+const Stmt *LastStmt = Body->body_back();
+if (const auto *Return = dyn_cast(LastStmt)) {
+  ReturnLoc = Return->getReturnLoc();
+}
+  }
+}
+
+if (ReturnLoc.isValid()) {
+  // Suggest removal of the redundant return statement.
+  diag(ReturnLoc, "redundant 'return 0;' at the end of main")
+  << 
FixItHint::CreateRemoval(CharSourceRange::getTokenRange(ReturnLoc));
+}
+
+  }
+
+}
+
+}
\ No newline at end of file
diff --git 
a/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h 
b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h
new file mode 100644
index 00..1407b8c1831c9d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h
@@ -0,0 +1,30 @@
+//===--- DonotreturnzerocheckCheck.h - clang-tidy ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//

[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy created 
https://github.com/llvm/llvm-project/pull/77586

**Overview:**
This pull request fixes #38469 where the issue proposes a new static analysis 
check in C++ to discourage the explicit return 0; statement at the end of the 
main() function. As C++ automatically assumes a return 0; in this context, 
having the explicit statement is redundant. The suggested change aims to 
enhance code readability by eliminating unnecessary lines in the main() 
function.

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.
![Screenshot from 2024-01-10 
16-53-31](https://github.com/llvm/llvm-project/assets/76656712/818d347e-7325-4d4d-aa0c-bcc611f46931)



**Dependencies:**
- No dependencies on other pull requests.

**CC:**
- @kirillbobyrev  , @AaronBallman 


>From bae95013cd7f937a5496cafcd40a77cc563addb0 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Wed, 10 Jan 2024 16:48:43 +0530
Subject: [PATCH] Added check for redundant return statement

Signed-off-by: 11happy 
---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/DonotreturnzerocheckCheck.cpp | 54 +++
 .../readability/DonotreturnzerocheckCheck.h   | 30 +++
 .../readability/ReadabilityTidyModule.cpp |  3 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  8 +++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../readability/DoNotReturnZeroCheck.rst  | 25 +
 .../readability/DoNotReturnZeroCheck.cpp  |  8 +++
 8 files changed, 130 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/DoNotReturnZeroCheck.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/DoNotReturnZeroCheck.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 408c822b861c5f..cb7741d6f56ce7 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -14,6 +14,7 @@ add_clang_library(clangTidyReadabilityModule
   ContainerSizeEmptyCheck.cpp
   ConvertMemberFunctionsToStatic.cpp
   DeleteNullPointerCheck.cpp
+  DonotreturnzerocheckCheck.cpp
   DuplicateIncludeCheck.cpp
   ElseAfterReturnCheck.cpp
   FunctionCognitiveComplexityCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
new file mode 100644
index 00..66ea29be3c54a8
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
@@ -0,0 +1,54 @@
+//===--- DonotreturnzerocheckCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DonotreturnzerocheckCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+
+
+namespace clang::tidy::readability {
+  bool isCPlusPlusOrC99(const LangOptions ) {
+  return LangOpts.CPlusPlus || LangOpts.C99;
+  }
+
+void DonotreturnzerocheckCheck::registerMatchers(MatchFinder *Finder) {
+  // FIXME: Add matchers.
+  Finder->addMatcher(functionDecl(
+isMain(),returns(asString("int"))
+  ).bind("main"), this);
+}
+
+void DonotreturnzerocheckCheck::check(const MatchFinder::MatchResult ) {
+  // FIXME: Add callback implementation.
+  const auto *MatchedDecl = Result.Nodes.getNodeAs("main");
+  if(isCPlusPlusOrC99(Result.Context->getLangOpts())){
+SourceLocation ReturnLoc;
+if (MatchedDecl->hasBody()) {
+  const CompoundStmt *Body = 
dyn_cast(MatchedDecl->getBody());
+  if (Body && !Body->body_empty()) {
+const Stmt *LastStmt = Body->body_back();
+if (const auto *Return = dyn_cast(LastStmt)) {
+  ReturnLoc = Return->getReturnLoc();
+}
+  }
+}
+
+if (ReturnLoc.isValid()) {
+  // Suggest removal of the redundant return statement.
+  diag(ReturnLoc, "redundant 'return 0;' at the end of main")
+  << 
FixItHint::CreateRemoval(CharSourceRange::getTokenRange(ReturnLoc));
+}
+
+  }
+
+}
+
+}
\ No newline at end of file
diff --git 
a/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h 
b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h
new file mode 100644
index 00..1407b8c1831c9d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h
@@ -0,0 +1,30 @@
+//===--- DonotreturnzerocheckCheck.h - clang-tidy 

[clang] [libc++][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-01-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amirreza Ashouri (AMP999)


Changes



---

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


1 Files Affected:

- (modified) clang/test/SemaCXX/type-traits.cpp (+1672-1683) 


``diff
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index c5d196a2590f8d..a0ba0f781e0d0d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3,8 +3,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=gnu++17 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted 
%s
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=gnu++20 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted 
%s
 
-#define T(b) (b) ? 1 : -1
-#define F(b) (b) ? -1 : 1
 
 struct NonPOD { NonPOD(int); };
 typedef NonPOD NonPODAr[10];
@@ -214,56 +212,56 @@ struct HasVirtBase : virtual ACompleteType {};
 
 void is_pod()
 {
-  { int arr[T(__is_pod(int))]; }
-  { int arr[T(__is_pod(Enum))]; }
-  { int arr[T(__is_pod(POD))]; }
-  { int arr[T(__is_pod(Int))]; }
-  { int arr[T(__is_pod(IntAr))]; }
-  { int arr[T(__is_pod(Statics))]; }
-  { int arr[T(__is_pod(Empty))]; }
-  { int arr[T(__is_pod(EmptyUnion))]; }
-  { int arr[T(__is_pod(Union))]; }
-  { int arr[T(__is_pod(HasFunc))]; }
-  { int arr[T(__is_pod(HasOp))]; }
-  { int arr[T(__is_pod(HasConv))]; }
-  { int arr[T(__is_pod(HasAssign))]; }
-  { int arr[T(__is_pod(IntArNB))]; }
-  { int arr[T(__is_pod(HasAnonymousUnion))]; }
-  { int arr[T(__is_pod(Vector))]; }
-  { int arr[T(__is_pod(VectorExt))]; }
-  { int arr[T(__is_pod(Derives))]; }
-  { int arr[T(__is_pod(DerivesAr))]; }
-  { int arr[T(__is_pod(DerivesArNB))]; }
-  { int arr[T(__is_pod(DerivesEmpty))]; }
-  { int arr[T(__is_pod(HasPriv))]; }
-  { int arr[T(__is_pod(HasProt))]; }
-  { int arr[T(__is_pod(DerivesHasPriv))]; }
-  { int arr[T(__is_pod(DerivesHasProt))]; }
-
-  { int arr[F(__is_pod(HasCons))]; }
-  { int arr[F(__is_pod(HasCopyAssign))]; }
-  { int arr[F(__is_pod(HasMoveAssign))]; }
-  { int arr[F(__is_pod(HasDest))]; }
-  { int arr[F(__is_pod(HasRef))]; }
-  { int arr[F(__is_pod(HasVirt))]; }
-  { int arr[F(__is_pod(DerivesHasCons))]; }
-  { int arr[F(__is_pod(DerivesHasCopyAssign))]; }
-  { int arr[F(__is_pod(DerivesHasMoveAssign))]; }
-  { int arr[F(__is_pod(DerivesHasDest))]; }
-  { int arr[F(__is_pod(DerivesHasRef))]; }
-  { int arr[F(__is_pod(DerivesHasVirt))]; }
-  { int arr[F(__is_pod(NonPOD))]; }
-  { int arr[F(__is_pod(HasNonPOD))]; }
-  { int arr[F(__is_pod(NonPODAr))]; }
-  { int arr[F(__is_pod(NonPODArNB))]; }
-  { int arr[F(__is_pod(void))]; }
-  { int arr[F(__is_pod(cvoid))]; }
-// { int arr[F(__is_pod(NonPODUnion))]; }
-
-  { int arr[T(__is_pod(ACompleteType))]; }
-  { int arr[F(__is_pod(AnIncompleteType))]; } // expected-error {{incomplete 
type}}
-  { int arr[F(__is_pod(AnIncompleteType[]))]; } // expected-error {{incomplete 
type}}
-  { int arr[F(__is_pod(AnIncompleteType[1]))]; } // expected-error 
{{incomplete type}}
+  static_assert(__is_pod(int), "");
+  static_assert(__is_pod(Enum), "");
+  static_assert(__is_pod(POD), "");
+  static_assert(__is_pod(Int), "");
+  static_assert(__is_pod(IntAr), "");
+  static_assert(__is_pod(Statics), "");
+  static_assert(__is_pod(Empty), "");
+  static_assert(__is_pod(EmptyUnion), "");
+  static_assert(__is_pod(Union), "");
+  static_assert(__is_pod(HasFunc), "");
+  static_assert(__is_pod(HasOp), "");
+  static_assert(__is_pod(HasConv), "");
+  static_assert(__is_pod(HasAssign), "");
+  static_assert(__is_pod(IntArNB), "");
+  static_assert(__is_pod(HasAnonymousUnion), "");
+  static_assert(__is_pod(Vector), "");
+  static_assert(__is_pod(VectorExt), "");
+  static_assert(__is_pod(Derives), "");
+  static_assert(__is_pod(DerivesAr), "");
+  static_assert(__is_pod(DerivesArNB), "");
+  static_assert(__is_pod(DerivesEmpty), "");
+  static_assert(__is_pod(HasPriv), "");
+  static_assert(__is_pod(HasProt), "");
+  static_assert(__is_pod(DerivesHasPriv), "");
+  static_assert(__is_pod(DerivesHasProt), "");
+
+  static_assert(!__is_pod(HasCons), "");
+  static_assert(!__is_pod(HasCopyAssign), "");
+  static_assert(!__is_pod(HasMoveAssign), "");
+  static_assert(!__is_pod(HasDest), "");
+  static_assert(!__is_pod(HasRef), "");
+  static_assert(!__is_pod(HasVirt), "");
+  static_assert(!__is_pod(DerivesHasCons), "");
+  static_assert(!__is_pod(DerivesHasCopyAssign), "");
+  static_assert(!__is_pod(DerivesHasMoveAssign), "");
+  static_assert(!__is_pod(DerivesHasDest), "");
+  static_assert(!__is_pod(DerivesHasRef), "");
+  static_assert(!__is_pod(DerivesHasVirt), "");
+  static_assert(!__is_pod(NonPOD), "");
+  static_assert(!__is_pod(HasNonPOD), "");
+  static_assert(!__is_pod(NonPODAr), "");
+  static_assert(!__is_pod(NonPODArNB), "");
+  static_assert(!__is_pod(void), "");
+  static_assert(!__is_pod(cvoid), 

[flang] [mlir] [llvm] [clang] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #77328)

2024-01-10 Thread Matthias Springer via cfe-commits


@@ -105,6 +106,161 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partialIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up. Returns failure if the loop can not
+/// be split and no new partialIteration is created.
+static LogicalResult splitLoopHelper(RewriterBase , scf::ForOp forOp,
+ scf::ForOp ,
+ Value splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  IRMapping map;
+  auto constStepOp =
+  b.create(forOp.getLoc(), *stepInt / 2);
+  // The new for loop for the remaining iterations has half the step size
+  // as continuous peeling requires the step size to diminish exponentially
+  // across subsequent loops.
+  map.map(forOp.getStep(), constStepOp);

matthias-springer wrote:

Generally speaking, for whatever modification you make to the loop body, you 
have to be sure that the loop body is still computing the same thing as before. 
Just blanket replacing all occurrences of the old step size (even if it's just 
in `affine.min/max` ops) with the new step size may change the semantics of the 
loop.

The only safe way of canonicalizing the loop body that we have at the moment is 
`rewritePeeledMinMaxOp`. This function will look for `affine.min/max` ops and 
select one of the provided options if it can prove that doing so would always 
be correct in the peeled or partial loop.



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


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-10 Thread via cfe-commits

llvmbot wrote:




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

Author: Ben Shi (benshi001)


Changes



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


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+4) 
- (modified) clang/test/Analysis/Inputs/system-header-simulator.h (+3) 
- (modified) clang/test/Analysis/stream-error.c (+82) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index fbfa101257d5e1..f6e6f3122f3aa7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -268,8 +268,12 @@ class StreamChecker : public Checker= 0)) {
+clang_analyzer_eval(Ret == -1L); // expected-warning {{TRUE}}
+  }
+  fclose(F);
+}
+
+void error_ftello(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  off_t Ret = ftello(F);
+  if (!(Ret == -1)) {
+clang_analyzer_eval(Ret >= 0);   // expected-warning {{TRUE}}
+  }
+  fclose(F);
+}
+
 void error_fflush_after_fclose(void) {
   FILE *F = tmpfile();
   int Ret;

``




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


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-10 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/77580

None

>From cb79cad6837dba5d33476c65923ec714507a3fef Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 10 Jan 2024 19:00:27 +0800
Subject: [PATCH] [clang][analyzer] Support 'tello' and 'fseeko' in the
 StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp |  4 +
 .../Analysis/Inputs/system-header-simulator.h |  3 +
 clang/test/Analysis/stream-error.c| 82 +++
 3 files changed, 89 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index fbfa101257d5e1..f6e6f3122f3aa7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -268,8 +268,12 @@ class StreamChecker : public Checker= 0)) {
+clang_analyzer_eval(Ret == -1L); // expected-warning {{TRUE}}
+  }
+  fclose(F);
+}
+
+void error_ftello(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  off_t Ret = ftello(F);
+  if (!(Ret == -1)) {
+clang_analyzer_eval(Ret >= 0);   // expected-warning {{TRUE}}
+  }
+  fclose(F);
+}
+
 void error_fflush_after_fclose(void) {
   FILE *F = tmpfile();
   int Ret;

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


[llvm] [clang] [clang][AArch64] Add a -mbranch-protection option to enable GCS (PR #75486)

2024-01-10 Thread John Brawn via cfe-commits

john-brawn-arm wrote:

Ping.

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


[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-01-10 Thread via cfe-commits

NorthBlue333 wrote:

Currently fixing the tests.

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


[clang] [Clang] Rename and enable boolean get, set, create and undef for sme2 (PR #77338)

2024-01-10 Thread Kerry McLaughlin via cfe-commits


@@ -1321,12 +1321,17 @@ def SVSET_3_BF16 : SInst<"svset3[_{d}]", "33id", "b", 
MergeNone, "", [IsTupleSet
 def SVSET_4_BF16 : SInst<"svset4[_{d}]", "44id", "b", MergeNone, "", 
[IsTupleSet], [ImmCheck<1, ImmCheck0_3>]>;
 }
 
-let TargetGuard = "sve2p1" in {
-  def SVGET_2_B : SInst<"svget2[_{d}]", "d2i", "Pc", MergeNone, "", 
[IsTupleGet], [ImmCheck<1, ImmCheck0_1>]>;
-  def SVGET_4_B : SInst<"svget4[_{d}]", "d4i", "Pc", MergeNone, "", 
[IsTupleGet], [ImmCheck<1, ImmCheck0_3>]>;
+let TargetGuard = "sve2p1|sme2" in {
+  def SVGET_2_B : SInst<"svget2_b", "d2i", "Pc", MergeNone, "", [IsTupleGet], 
[ImmCheck<1, ImmCheck0_1>]>;
+  def SVGET_4_B : SInst<"svget4_b", "d4i", "Pc", MergeNone, "", [IsTupleGet], 
[ImmCheck<1, ImmCheck0_3>]>;

kmclaughlin-arm wrote:

Does the `_b` still need to be in square brackets? I think this part of the 
name is optional for get, set & create (but not undef).

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


[clang-tools-extra] [libc] [mlir] [lld] [libcxx] [libclc] [llvm] [clang] [flang] [libunwind] [lldb] [compiler-rt] [AMDGPU] Fix broken sign-extended subword buffer load combine (PR #77470)

2024-01-10 Thread Jay Foad via cfe-commits

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


[clang] [clang-repl] Enable native CPU detection by default (PR #77491)

2024-01-10 Thread Stefan Gränitz via cfe-commits

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


[clang] 5cc0344 - [clang-repl] Enable native CPU detection by default (#77491)

2024-01-10 Thread via cfe-commits

Author: Stefan Gränitz
Date: 2024-01-10T11:49:01+01:00
New Revision: 5cc03442d392693d0d2457f571cc8fa1736bfe5e

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

LOG: [clang-repl] Enable native CPU detection by default (#77491)

We can pass `-mcpu=native` to the clang driver to let it consider the
host CPU when choosing the compile target for `clang-repl`. We can
already achieve this behavior with `clang-repl -Xcc -mcpu=native`, but
it seems like a reasonable default actually.

The trade-off between optimizing for a specific CPU and maximum
compatibility often leans towards the latter for static binaries,
because distributing many versions is cumbersome. However, when
compiling at runtime, we know the exact target CPU and we can use that
to optimize the generated code.

This patch makes a difference especially for "scattered" architectures
like ARM. When cross-compiling for a Raspberry Pi for example, we may
use a stock toolchain like arm-linux-gnueabihf-gcc. The resulting binary
will be compatible with all hardware versions. This is handy, but they
will all have `arm-linux-gnueabihf` as their host triple. Previously,
this caused the clang driver to select triple `armv6kz-linux-gnueabihf`
and CPU `arm1176jzf-s` as the REPL target. After this patch the default
triple and CPU on Raspberry Pi 4b will be `armv8a-linux-gnueabihf` and
`cortex-a72` respectively.

With this patch clang-repl matches the host detection in Orc.

Added: 


Modified: 
clang/lib/Interpreter/Interpreter.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index c9fcef5b5b5af1..734fe90d0d89b4 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -148,6 +148,7 @@ IncrementalCompilerBuilder::create(std::vector ) {
   // We do C++ by default; append right after argv[0] if no "-x" given
   ClangArgv.insert(ClangArgv.end(), "-Xclang");
   ClangArgv.insert(ClangArgv.end(), "-fincremental-extensions");
+  ClangArgv.insert(ClangArgv.end(), "-mcpu=native");
   ClangArgv.insert(ClangArgv.end(), "-c");
 
   // Put a dummy C++ file on to ensure there's at least one compile job for the



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


[clang] [mlir] [llvm] [flang] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #77328)

2024-01-10 Thread via cfe-commits


@@ -105,6 +106,161 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partialIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up. Returns failure if the loop can not
+/// be split and no new partialIteration is created.
+static LogicalResult splitLoopHelper(RewriterBase , scf::ForOp forOp,
+ scf::ForOp ,
+ Value splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  IRMapping map;
+  auto constStepOp =
+  b.create(forOp.getLoc(), *stepInt / 2);
+  // The new for loop for the remaining iterations has half the step size
+  // as continuous peeling requires the step size to diminish exponentially
+  // across subsequent loops.
+  map.map(forOp.getStep(), constStepOp);

muneebkhan85 wrote:

Yes, the purpose is to canonicalize min/max ops inside the new loop body. This 
requires the affine.min/max ops to have the correct step given the step size 
has changed (halved) for the partialIteraton loop.

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


[clang] [clang-repl] Enable native CPU detection by default (PR #77491)

2024-01-10 Thread Stefan Gränitz via cfe-commits

weliveindetail wrote:

Thanks for the quick review!

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


[lld] [flang] [llvm] [clang] [AMDGPU] Introduce Code Object V6 (PR #76954)

2024-01-10 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh updated 
https://github.com/llvm/llvm-project/pull/76954

>From 6368d8210e211948b5a03ab326b996695b8d Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 4 Jan 2024 14:12:00 +0100
Subject: [PATCH] [AMDGPU] Introduce Code Object V6

Introduce Code Object V6 in Clang, LLD, Flang and LLVM.
This is the same as V5 except a new "generic version" flag can be present in 
EFLAGS. This is related to new generic targets that'll be added in a follow-up 
patch. It's also likely V6 will have new changes (possibly new metadata 
entries) added later.

Docs change are not included, I'm planning to do them in a follow-up patch all 
at once (when generic targets land too).
---
 clang/include/clang/Driver/Options.td |   4 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |   6 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp|   2 +-
 .../amdgpu-code-object-version-linking.cu |  37 +++
 .../CodeGenCUDA/amdgpu-code-object-version.cu |   4 +
 .../test/CodeGenCUDA/amdgpu-workgroup-size.cu |   4 +
 .../amdgcn/bitcode/oclc_abi_version_600.bc|   0
 clang/test/Driver/hip-code-object-version.hip |  12 +
 clang/test/Driver/hip-device-libs.hip |  18 +-
 flang/lib/Frontend/CompilerInvocation.cpp |   2 +
 flang/test/Lower/AMD/code-object-version.f90  |   3 +-
 lld/ELF/Arch/AMDGPU.cpp   |  21 ++
 lld/test/ELF/amdgpu-tid.s |  16 ++
 llvm/include/llvm/BinaryFormat/ELF.h  |   9 +-
 llvm/include/llvm/Support/AMDGPUMetadata.h|   5 +
 llvm/include/llvm/Support/ScopedPrinter.h |   4 +-
 llvm/include/llvm/Target/TargetOptions.h  |   1 +
 llvm/lib/ObjectYAML/ELFYAML.cpp   |   9 +
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |   3 +
 .../AMDGPU/AMDGPUHSAMetadataStreamer.cpp  |  10 +
 .../Target/AMDGPU/AMDGPUHSAMetadataStreamer.h |  11 +-
 .../MCTargetDesc/AMDGPUTargetStreamer.cpp |  27 +++
 .../MCTargetDesc/AMDGPUTargetStreamer.h   |   1 +
 .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp|  13 +
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h |   5 +-
 ...licit-kernarg-backend-usage-global-isel.ll |   2 +
 .../AMDGPU/call-graph-register-usage.ll   |   1 +
 .../AMDGPU/codegen-internal-only-func.ll  |   2 +
 llvm/test/CodeGen/AMDGPU/elf-header-osabi.ll  |   4 +
 .../enable-scratch-only-dynamic-stack.ll  |   1 +
 .../AMDGPU/implicit-kernarg-backend-usage.ll  |   2 +
 .../AMDGPU/implicitarg-offset-attributes.ll   |  46 
 .../AMDGPU/llvm.amdgcn.implicitarg.ptr.ll |   1 +
 llvm/test/CodeGen/AMDGPU/non-entry-alloca.ll  |   1 +
 llvm/test/CodeGen/AMDGPU/recursion.ll |   1 +
 .../AMDGPU/resource-usage-dead-function.ll|   1 +
 .../AMDGPU/tid-mul-func-xnack-all-any.ll  |   6 +
 .../tid-mul-func-xnack-all-not-supported.ll   |   6 +
 .../AMDGPU/tid-mul-func-xnack-all-off.ll  |   6 +
 .../AMDGPU/tid-mul-func-xnack-all-on.ll   |   6 +
 .../AMDGPU/tid-mul-func-xnack-any-off-1.ll|   6 +
 .../AMDGPU/tid-mul-func-xnack-any-off-2.ll|   6 +
 .../AMDGPU/tid-mul-func-xnack-any-on-1.ll |   6 +
 .../AMDGPU/tid-mul-func-xnack-any-on-2.ll |   6 +
 .../tid-one-func-xnack-not-supported.ll   |   6 +
 .../CodeGen/AMDGPU/tid-one-func-xnack-off.ll  |   6 +
 .../CodeGen/AMDGPU/tid-one-func-xnack-on.ll   |   6 +
 .../MC/AMDGPU/hsa-v5-uses-dynamic-stack.s |   5 +
 .../elf-headers.test} |   0
 .../ELF/AMDGPU/generic_versions.s |  16 ++
 .../ELF/AMDGPU/generic_versions.test  |  26 ++
 llvm/tools/llvm-readobj/ELFDumper.cpp | 224 --
 52 files changed, 491 insertions(+), 135 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/rocm/amdgcn/bitcode/oclc_abi_version_600.bc
 rename llvm/test/tools/llvm-readobj/ELF/{amdgpu-elf-headers.test => 
AMDGPU/elf-headers.test} (100%)
 create mode 100644 llvm/test/tools/llvm-readobj/ELF/AMDGPU/generic_versions.s
 create mode 100644 
llvm/test/tools/llvm-readobj/ELF/AMDGPU/generic_versions.test

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bffdddc28aac60..f9381d0706f447 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4761,9 +4761,9 @@ defm amdgpu_ieee : BoolOption<"m", "amdgpu-ieee",
 def mcode_object_version_EQ : Joined<["-"], "mcode-object-version=">, 
Group,
   HelpText<"Specify code object ABI version. Defaults to 4. (AMDGPU only)">,
   Visibility<[ClangOption, FlangOption, CC1Option, FC1Option]>,
-  Values<"none,4,5">,
+  Values<"none,4,5,6">,
   NormalizedValuesScope<"llvm::CodeObjectVersionKind">,
-  NormalizedValues<["COV_None", "COV_4", "COV_5"]>,
+  NormalizedValues<["COV_None", "COV_4", "COV_5", "COV_6"]>,
   MarshallingInfoEnum, "COV_4">;
 
 defm cumode : SimpleMFlag<"cumode",
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f71dbf1729a1d6..be86731ed912ea 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ 

[clang] [clang][analyzer] Fix incorrect range of 'ftell' in the StdLibraryFunctionsChecker (PR #77576)

2024-01-10 Thread Ben Shi via cfe-commits

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

2024-01-10 Thread via cfe-commits

https://github.com/r4nt updated https://github.com/llvm/llvm-project/pull/76245

>From 52cb11f0279dbd9f65f15e81f44869cfac00d544 Mon Sep 17 00:00:00 2001
From: Manuel Klimek 
Date: Thu, 2 Mar 2023 14:00:35 +
Subject: [PATCH 1/3] [ClangFormat] Fix formatting bugs.

1. There are multiple calls to addFakeParenthesis; move the guard to not
   assign fake parenthesis into the function to make sure we cover all
   calls.
2. MustBreakBefore can be set on a token in two cases: either during
   unwrapped line parsing, or later, during token annotation. We must
   keep the latter, but reset the former.
3. Added a test to document that the intended behavior of preferring not to
   break between a return type and a function identifier.
   For example, with MOCK_METHOD(r, n, a)=r n a, the code
   MOCK_METHOD(void, f, (int a, int b)) should prefer the same breaks as
   the expanded void f(int a, int b).
---
 clang/lib/Format/FormatToken.h| 26 +
 clang/lib/Format/TokenAnnotator.cpp   | 13 +++
 clang/lib/Format/UnwrappedLineFormatter.cpp   | 10 +++--
 clang/lib/Format/UnwrappedLineParser.cpp  |  2 +
 .../Format/FormatTestMacroExpansion.cpp   | 38 +++
 5 files changed, 70 insertions(+), 19 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 3f9664f8f78a3e..b1e3ae8ab303d6 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -275,14 +275,15 @@ class AnnotatedLine;
 struct FormatToken {
   FormatToken()
   : HasUnescapedNewline(false), IsMultiline(false), IsFirst(false),
-MustBreakBefore(false), IsUnterminatedLiteral(false),
-CanBreakBefore(false), ClosesTemplateDeclaration(false),
-StartsBinaryExpression(false), EndsBinaryExpression(false),
-PartOfMultiVariableDeclStmt(false), ContinuesLineCommentSection(false),
-Finalized(false), ClosesRequiresClause(false),
-EndsCppAttributeGroup(false), BlockKind(BK_Unknown),
-Decision(FD_Unformatted), PackingKind(PPK_Inconclusive),
-TypeIsFinalized(false), Type(TT_Unknown) {}
+MustBreakBefore(false), MustBreakBeforeFinalized(false),
+IsUnterminatedLiteral(false), CanBreakBefore(false),
+ClosesTemplateDeclaration(false), StartsBinaryExpression(false),
+EndsBinaryExpression(false), PartOfMultiVariableDeclStmt(false),
+ContinuesLineCommentSection(false), Finalized(false),
+ClosesRequiresClause(false), EndsCppAttributeGroup(false),
+BlockKind(BK_Unknown), Decision(FD_Unformatted),
+PackingKind(PPK_Inconclusive), TypeIsFinalized(false),
+Type(TT_Unknown) {}
 
   /// The \c Token.
   Token Tok;
@@ -318,6 +319,10 @@ struct FormatToken {
   /// before the token.
   unsigned MustBreakBefore : 1;
 
+  /// Whether MustBreakBefore is finalized during parsing and must not
+  /// be reset between runs.
+  unsigned MustBreakBeforeFinalized : 1;
+
   /// Set to \c true if this token is an unterminated literal.
   unsigned IsUnterminatedLiteral : 1;
 
@@ -416,10 +421,15 @@ struct FormatToken {
   /// to another one please use overwriteFixedType, or even better remove the
   /// need to reassign the type.
   void setFinalizedType(TokenType T) {
+if (MacroCtx && MacroCtx->Role == MR_UnexpandedArg)
+  return;
+
 Type = T;
 TypeIsFinalized = true;
   }
   void overwriteFixedType(TokenType T) {
+if (MacroCtx && MacroCtx->Role == MR_UnexpandedArg)
+  return;
 TypeIsFinalized = false;
 setType(T);
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f3551af3424396..c26b248a3b2d40 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2769,13 +2769,6 @@ class ExpressionParser {
   // Consume operators with higher precedence.
   parse(Precedence + 1);
 
-  // Do not assign fake parenthesis to tokens that are part of an
-  // unexpanded macro call. The line within the macro call contains
-  // the parenthesis and commas, and we will not find operators within
-  // that structure.
-  if (Current && Current->MacroParent)
-break;
-
   int CurrentPrecedence = getCurrentPrecedence();
 
   if (Precedence == CurrentPrecedence && Current &&
@@ -2919,6 +2912,12 @@ class ExpressionParser {
 
   void addFakeParenthesis(FormatToken *Start, prec::Level Precedence,
   FormatToken *End = nullptr) {
+// Do not assign fake parenthesis to tokens that are part of an
+// unexpanded macro call. The line within the macro call contains
+// the parenthesis and commas, and we will not find operators within
+// that structure.
+if (Start->MacroParent) return;
+
 Start->FakeLParens.push_back(Precedence);
 if (Precedence > prec::Unknown)
   Start->StartsBinaryExpression = true;
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 

[clang] [clang][analyzer] Fix incorrect range of 'ftell' in the StdLibraryFunctionsChecker (PR #77576)

2024-01-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes

According to https://pubs.opengroup.org/onlinepubs/9699919799/, the return 
value of 'ftell' is not restricted to  0, and may return 0 in real world.

And the corresponding unit test also show `Ret = 0` not `Ret  0`.

https://github.com/llvm/llvm-project/blob/main/clang/test/Analysis/stream-errno.c#L194

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


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+1-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 32a2deab871c79..3b36565681a7f3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2274,7 +2274,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 addToFunctionSummaryMap(
 "ftell", Signature(ArgTypes{FilePtrTy}, RetType{LongTy}),
 Summary(NoEvalCall)
-.Case({ReturnValueCondition(WithinRange, Range(1, LongMax))},
+.Case({ReturnValueCondition(WithinRange, Range(0, LongMax))},
   ErrnoUnchanged, GenericSuccessMsg)
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;

``




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


[clang] [clang][analyzer] Fix incorrect range of 'ftell' in the StdLibraryFunctionsChecker (PR #77576)

2024-01-10 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/77576

According to https://pubs.opengroup.org/onlinepubs/9699919799/, the return 
value of 'ftell' is not restricted to > 0, and may return 0 in real world.

And the corresponding unit test also show `Ret >= 0` not `Ret > 0`.

https://github.com/llvm/llvm-project/blob/main/clang/test/Analysis/stream-errno.c#L194

>From e33d2bce007ac6009870a4dbd5227b62c3d6ba41 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 10 Jan 2024 18:28:30 +0800
Subject: [PATCH] [clang][analyzer] Fix incorrect range of 'ftell' in the
 StdLibraryFunctionsChecker

According to https://pubs.opengroup.org/onlinepubs/9699919799/, the return value
of 'ftell' is not restricted to > 0, and may return 0 in real world.
---
 .../lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 32a2deab871c79..3b36565681a7f3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2274,7 +2274,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 addToFunctionSummaryMap(
 "ftell", Signature(ArgTypes{FilePtrTy}, RetType{LongTy}),
 Summary(NoEvalCall)
-.Case({ReturnValueCondition(WithinRange, Range(1, LongMax))},
+.Case({ReturnValueCondition(WithinRange, Range(0, LongMax))},
   ErrnoUnchanged, GenericSuccessMsg)
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;

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


[lld] [flang] [llvm] [clang] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (PR #76955)

2024-01-10 Thread Pierre van Houtryve via cfe-commits

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


[lld] [flang] [llvm] [clang] [AMDGPU] Introduce Code Object V6 (PR #76954)

2024-01-10 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 40236257ea9d1e451daee5c0938bd23abd5d1450 
df3227d73e03b5d013e14293013e54da120c0b77 -- clang/lib/CodeGen/CGBuiltin.cpp 
clang/lib/Driver/ToolChains/CommonArgs.cpp 
flang/lib/Frontend/CompilerInvocation.cpp lld/ELF/Arch/AMDGPU.cpp 
llvm/include/llvm/BinaryFormat/ELF.h llvm/include/llvm/Support/AMDGPUMetadata.h 
llvm/include/llvm/Support/ScopedPrinter.h 
llvm/include/llvm/Target/TargetOptions.h llvm/lib/ObjectYAML/ELFYAML.cpp 
llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp 
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h 
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp 
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.h 
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp 
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h 
llvm/tools/llvm-readobj/ELFDumper.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 7e3426aa8e..ff7151e016 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -621,9 +621,12 @@ void ScalarBitSetTraits::bitset(IO ,
   BCase(EF_AMDGPU_FEATURE_SRAMECC_V3);
   break;
 case ELF::ELFABIVERSION_AMDGPU_HSA_V6:
-  for(unsigned K = ELF::EF_AMDGPU_GENERIC_VERSION_MIN; K <= 
ELF::EF_AMDGPU_GENERIC_VERSION_MAX; ++K) {
+  for (unsigned K = ELF::EF_AMDGPU_GENERIC_VERSION_MIN;
+   K <= ELF::EF_AMDGPU_GENERIC_VERSION_MAX; ++K) {
 std::string Key = "EF_AMDGPU_GENERIC_VERSION_V" + std::to_string(K);
-IO.maskedBitSetCase(Value, Key.c_str(), K << 
ELF::EF_AMDGPU_GENERIC_VERSION_OFFSET, ELF::EF_AMDGPU_GENERIC_VERSION);
+IO.maskedBitSetCase(Value, Key.c_str(),
+K << ELF::EF_AMDGPU_GENERIC_VERSION_OFFSET,
+ELF::EF_AMDGPU_GENERIC_VERSION);
   }
   [[fallthrough]];
 case ELF::ELFABIVERSION_AMDGPU_HSA_V4:
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp 
b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 8f19873de1..88eef3f343 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -3641,8 +3641,10 @@ template  void 
GNUELFDumper::printFileHeaders() {
  unsigned(ELF::EF_AMDGPU_FEATURE_XNACK_V4),
  unsigned(ELF::EF_AMDGPU_FEATURE_SRAMECC_V4),
  unsigned(ELF::EF_AMDGPU_GENERIC_VERSION));
-  if(auto GenericV = e.e_flags & ELF::EF_AMDGPU_GENERIC_VERSION) {
-ElfFlags += ", generic_v" + to_string(GenericV >> 
ELF::EF_AMDGPU_GENERIC_VERSION_OFFSET);
+  if (auto GenericV = e.e_flags & ELF::EF_AMDGPU_GENERIC_VERSION) {
+ElfFlags +=
+", generic_v" +
+to_string(GenericV >> ELF::EF_AMDGPU_GENERIC_VERSION_OFFSET);
   }
   break;
 }

``




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


[mlir] [flang] [llvm] [clang] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #77328)

2024-01-10 Thread Matthias Springer via cfe-commits


@@ -105,6 +106,161 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partialIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up. Returns failure if the loop can not
+/// be split and no new partialIteration is created.
+static LogicalResult splitLoopHelper(RewriterBase , scf::ForOp forOp,
+ scf::ForOp ,
+ Value splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  IRMapping map;
+  auto constStepOp =
+  b.create(forOp.getLoc(), *stepInt / 2);
+  // The new for loop for the remaining iterations has half the step size
+  // as continuous peeling requires the step size to diminish exponentially
+  // across subsequent loops.
+  map.map(forOp.getStep(), constStepOp);

matthias-springer wrote:

I think this won't work. The SSA value of `forOp.getStep()` could be used in 
different ways inside of the loop and you don't want to change that.

E.g.:
```mlir
scf.for ... step %c16 {
  // This op should not be changed as part of loop peeling.
  "test.foo"(%c16) : () -> ()
}
```

What's the purpose of this `map.map`? Is it meant to canonicalize 
`affine.min/max` ops, taking into account the fact that the loop was peeled?


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


[clang-tools-extra] [llvm] [clang] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)

2024-01-10 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/67302

>From a1567f579531c3abbd1f4e9b7c7edd2f95ead42c Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Mon, 25 Sep 2023 17:10:51 +0800
Subject: [PATCH 1/7] [PowerPC] Implement llvm.set.rounding intrinsic

According to LangRef, llvm.set.rounding sets rounding mode by integer argument:

0 - toward zero
1 - to nearest, ties to even
2 - toward positive infinity
3 - toward negative infinity
4 - to nearest, ties away from zero

While PowerPC ISA says:

0 - to nearest
1 - toward zero
2 - toward positive infinity
3 - toward negative infinity

This patch maps the argument and write into last two bits of FPSCR (rounding 
mode).
---
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp |  80 
 llvm/lib/Target/PowerPC/PPCISelLowering.h   |   1 +
 llvm/test/CodeGen/PowerPC/frounds.ll| 194 +++-
 3 files changed, 274 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp 
b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index f4e3531980d165..4e5ff0cb716966 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -426,6 +426,7 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine 
,
 setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f32, Expand);
 
   setOperationAction(ISD::GET_ROUNDING, MVT::i32, Custom);
+  setOperationAction(ISD::SET_ROUNDING, MVT::Other, Custom);
 
   // If we're enabling GP optimizations, use hardware square root
   if (!Subtarget.hasFSQRT() &&
@@ -8898,6 +8899,83 @@ SDValue PPCTargetLowering::LowerINT_TO_FP(SDValue Op,
   return FP;
 }
 
+SDValue PPCTargetLowering::LowerSET_ROUNDING(SDValue Op,
+ SelectionDAG ) const {
+  SDLoc Dl(Op);
+  MachineFunction  = DAG.getMachineFunction();
+  EVT PtrVT = getPointerTy(MF.getDataLayout());
+  SDValue Chain = Op.getOperand(0);
+
+  // If requested mode is constant, just use simpler mtfsb.
+  if (auto *CVal = dyn_cast(Op.getOperand(1))) {
+uint64_t Mode = CVal->getZExtValue();
+if (Mode >= 4)
+  llvm_unreachable("Unsupported rounding mode!");
+unsigned InternalRnd = Mode ^ (~(Mode >> 1) & 1);
+SDNode *SetHi = DAG.getMachineNode(
+(InternalRnd & 2) ? PPC::MTFSB1 : PPC::MTFSB0, Dl, MVT::Other,
+{DAG.getConstant(30, Dl, MVT::i32, true), Chain});
+SDNode *SetLo = DAG.getMachineNode(
+(InternalRnd & 1) ? PPC::MTFSB1 : PPC::MTFSB0, Dl, MVT::Other,
+{DAG.getConstant(31, Dl, MVT::i32, true), SDValue(SetHi, 0)});
+return SDValue(SetLo, 0);
+  }
+
+  // Use x ^ (~(x >> 1) & 1) to transform LLVM rounding mode to Power format.
+  SDValue One = DAG.getConstant(1, Dl, MVT::i32);
+  SDValue SrcFlag = DAG.getNode(ISD::AND, Dl, MVT::i32, Op.getOperand(1),
+DAG.getConstant(3, Dl, MVT::i32));
+  SDValue DstFlag = DAG.getNode(
+  ISD::XOR, Dl, MVT::i32, SrcFlag,
+  DAG.getNode(ISD::AND, Dl, MVT::i32,
+  DAG.getNOT(Dl,
+ DAG.getNode(ISD::SRL, Dl, MVT::i32, SrcFlag, One),
+ MVT::i32),
+  One));
+  SDValue MFFS = DAG.getNode(PPCISD::MFFS, Dl, {MVT::f64, MVT::Other}, Chain);
+  Chain = MFFS.getValue(1);
+  SDValue NewFPSCR;
+  if (isTypeLegal(MVT::i64)) {
+// Set the last two bits (rounding mode) of bitcasted FPSCR.
+NewFPSCR = DAG.getNode(
+ISD::OR, Dl, MVT::i64,
+DAG.getNode(ISD::AND, Dl, MVT::i64,
+DAG.getNode(ISD::BITCAST, Dl, MVT::i64, MFFS),
+DAG.getNOT(Dl, DAG.getConstant(3, Dl, MVT::i64), 
MVT::i64)),
+DAG.getNode(ISD::ZERO_EXTEND, Dl, MVT::i64, DstFlag));
+NewFPSCR = DAG.getNode(ISD::BITCAST, Dl, MVT::f64, NewFPSCR);
+  } else {
+// In 32-bit mode, store f64, load and update the lower half.
+int SSFI = MF.getFrameInfo().CreateStackObject(8, Align(8), false);
+SDValue StackSlot = DAG.getFrameIndex(SSFI, PtrVT);
+Chain = DAG.getStore(Chain, Dl, MFFS, StackSlot, MachinePointerInfo());
+SDValue Addr;
+if (Subtarget.isLittleEndian())
+  Addr = StackSlot;
+else
+  Addr = DAG.getNode(ISD::ADD, Dl, PtrVT, StackSlot,
+ DAG.getConstant(4, Dl, PtrVT));
+SDValue Tmp = DAG.getLoad(MVT::i32, Dl, Chain, Addr, MachinePointerInfo());
+Chain = Tmp.getValue(1);
+
+Tmp = DAG.getNode(
+ISD::OR, Dl, MVT::i32,
+DAG.getNode(ISD::AND, Dl, MVT::i32, Tmp,
+DAG.getNOT(Dl, DAG.getConstant(3, Dl, MVT::i32), 
MVT::i32)),
+DstFlag);
+
+Chain = DAG.getStore(Chain, Dl, Tmp, Addr, MachinePointerInfo());
+NewFPSCR =
+DAG.getLoad(MVT::f64, Dl, Chain, StackSlot, MachinePointerInfo());
+Chain = NewFPSCR.getValue(1);
+  }
+  SDValue Zero = DAG.getConstant(0, Dl, MVT::i32, true);
+  SDNode *MTFSF = DAG.getMachineNode(
+  PPC::MTFSF, Dl, 

[mlir] [flang] [llvm] [clang] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #77328)

2024-01-10 Thread Matthias Springer via cfe-commits

matthias-springer wrote:

Can you re-open the old PR and force-push the contents of this PR to the old 
PR? Ideally, we'd keep using the old PR, so that we don't loose the review 
comments.


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


[clang] [clang-tools-extra] [flang] [llvm] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

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

https://github.com/yi-wu-arm closed 
https://github.com/llvm/llvm-project/pull/74077
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-10 Thread via cfe-commits

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


[clang] a26cc75 - [clang][coverage] Fix "if constexpr" and "if consteval" coverage report (#77214)

2024-01-10 Thread via cfe-commits

Author: Hana Dusíková
Date: 2024-01-10T11:01:23+01:00
New Revision: a26cc759ae5a8018e2c328cf53173992340b995a

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

LOG: [clang][coverage] Fix "if constexpr" and "if consteval" coverage report 
(#77214)

Replace the discarded statement by an empty compound statement so we can keep 
track of the
whole source range we need to skip in coverage

Fixes #54419

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Stmt.h
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CoverageMapping/if.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 20872f7ddb81e9..37f8bbc89d8949 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -705,6 +705,9 @@ Bug Fixes in This Version
 - Fix assertion crash due to failed scope restoring caused by too-early VarDecl
   invalidation by invalid initializer Expr.
   Fixes (`#30908 `_)
+- Clang now emits correct source location for code-coverage regions in `if 
constexpr`
+  and `if consteval` branches.
+  Fixes (`#54419 `_)
 
 
 Bug Fixes to Compiler Builtins

diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211..e1fde24e647789 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1631,8 +1631,10 @@ class CompoundStmt final
   SourceLocation RB);
 
   // Build an empty compound statement with a location.
-  explicit CompoundStmt(SourceLocation Loc)
-  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
+  explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
+
+  CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
+  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
 CompoundStmtBits.NumStmts = 0;
 CompoundStmtBits.HasFPFeatures = 0;
   }

diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index bf227386a71b78..b245abd16c3f4a 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1712,7 +1712,11 @@ struct CounterCoverageMappingBuilder
   extendRegion(S->getCond());
 
 Counter ParentCount = getRegion().getCounter();
-Counter ThenCount = getRegionCounter(S);
+
+// If this is "if !consteval" the then-branch will never be taken, we don't
+// need to change counter
+Counter ThenCount =
+S->isNegatedConsteval() ? ParentCount : getRegionCounter(S);
 
 if (!S->isConsteval()) {
   // Emitting a counter for the condition makes it easier to interpret the
@@ -1729,7 +1733,12 @@ struct CounterCoverageMappingBuilder
 extendRegion(S->getThen());
 Counter OutCount = propagateCounts(ThenCount, S->getThen());
 
-Counter ElseCount = subtractCounters(ParentCount, ThenCount);
+// If this is "if consteval" the else-branch will never be taken, we don't
+// need to change counter
+Counter ElseCount = S->isNonNegatedConsteval()
+? ParentCount
+: subtractCounters(ParentCount, ThenCount);
+
 if (const Stmt *Else = S->getElse()) {
   bool ThenHasTerminateStmt = HasTerminateStmt;
   HasTerminateStmt = false;

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index e7a6550b1c993c..1a1bc87d2b3203 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7739,7 +7739,11 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 if (Then.isInvalid())
   return StmtError();
   } else {
-Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
+// Discarded branch is replaced with empty CompoundStmt so we can keep
+// proper source location for start and end of original branch, so
+// subsequent transformations like CoverageMapping work properly
+Then = new (getSema().Context)
+CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
   }
 
   // Transform the "else" branch.
@@ -7748,6 +7752,13 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 Else = getDerived().TransformStmt(S->getElse());
 if (Else.isInvalid())
   return StmtError();
+  } else if (S->getElse() && ConstexprConditionValue &&
+ *ConstexprConditionValue) {
+// Same thing here as with  branch, we are discarding it, we can't
+// replace it with NULL nor NullStmt as we need to keep for source location
+// range, for CoverageMapping
+Else = new (getSema().Context)
+CompoundStmt(S->getElse()->getBeginLoc(), 

[clang] [Clang][doc] Add blank line before lists (PR #77573)

2024-01-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Wang Pengcheng (wangpc-pp)


Changes

The doc is not correctly rendered with missing blank lines.


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


1 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+2) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 23a7f4f5d5b926..c1420079f75118 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -829,6 +829,7 @@ to ``float``; see below for more information on this 
emulation.
   see below.
 
 * ``_Float16`` is supported on the following targets:
+
   * 32-bit ARM (natively on some architecture versions)
   * 64-bit ARM (AArch64) (natively on ARMv8.2a and above)
   * AMDGPU (natively)
@@ -837,6 +838,7 @@ to ``float``; see below for more information on this 
emulation.
   * RISC-V (natively if Zfh or Zhinx is available)
 
 * ``__bf16`` is supported on the following targets (currently never natively):
+
   * 32-bit ARM
   * 64-bit ARM (AArch64)
   * RISC-V

``




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


[clang] [Clang][doc] Add blank line before lists (PR #77573)

2024-01-10 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp created 
https://github.com/llvm/llvm-project/pull/77573

The doc is not correctly rendered with missing blank lines.


>From 2d249aefa1bfa91f41a3866c4203eff041415546 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Wed, 10 Jan 2024 17:54:27 +0800
Subject: [PATCH] [Clang][doc] Add blank line before lists

The doc is not correctly rendered with missing blank lines.
---
 clang/docs/LanguageExtensions.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 23a7f4f5d5b926..c1420079f75118 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -829,6 +829,7 @@ to ``float``; see below for more information on this 
emulation.
   see below.
 
 * ``_Float16`` is supported on the following targets:
+
   * 32-bit ARM (natively on some architecture versions)
   * 64-bit ARM (AArch64) (natively on ARMv8.2a and above)
   * AMDGPU (natively)
@@ -837,6 +838,7 @@ to ``float``; see below for more information on this 
emulation.
   * RISC-V (natively if Zfh or Zhinx is available)
 
 * ``__bf16`` is supported on the following targets (currently never natively):
+
   * 32-bit ARM
   * 64-bit ARM (AArch64)
   * RISC-V

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


[clang] Revert "[clang][dataflow] Add an early-out to `flowConditionImplies()` / `flowConditionAllows()`." (PR #77570)

2024-01-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (martinboehme)


Changes

Reverts llvm/llvm-project#77453

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


2 Files Affected:

- (modified) clang/include/clang/Analysis/FlowSensitive/Formula.h (-4) 
- (modified) clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp (-6) 


``diff
diff --git a/clang/include/clang/Analysis/FlowSensitive/Formula.h 
b/clang/include/clang/Analysis/FlowSensitive/Formula.h
index 0e6352403a832f..982e400c1deff1 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Formula.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Formula.h
@@ -75,10 +75,6 @@ class alignas(const Formula *) Formula {
 return static_cast(Value);
   }
 
-  bool isLiteral(bool b) const {
-return kind() == Literal && static_cast(Value) == b;
-  }
-
   ArrayRef operands() const {
 return ArrayRef(reinterpret_cast(this + 1),
 numOperands(kind()));
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index 500fbb39955d20..fa114979c8e326 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -174,9 +174,6 @@ Solver::Result DataflowAnalysisContext::querySolver(
 
 bool DataflowAnalysisContext::flowConditionImplies(Atom Token,
const Formula ) {
-  if (F.isLiteral(true))
-return true;
-
   // Returns true if and only if truth assignment of the flow condition implies
   // that `F` is also true. We prove whether or not this property holds by
   // reducing the problem to satisfiability checking. In other words, we 
attempt
@@ -191,9 +188,6 @@ bool DataflowAnalysisContext::flowConditionImplies(Atom 
Token,
 
 bool DataflowAnalysisContext::flowConditionAllows(Atom Token,
   const Formula ) {
-  if (F.isLiteral(true))
-return true;
-
   llvm::SetVector Constraints;
   Constraints.insert(().makeAtomRef(Token));
   Constraints.insert();

``




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


[clang] Revert "[clang][dataflow] Add an early-out to `flowConditionImplies()` / `flowConditionAllows()`." (PR #77570)

2024-01-10 Thread via cfe-commits

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


[clang] 7ce010f - Revert "[clang][dataflow] Add an early-out to `flowConditionImplies()` / `flowConditionAllows()`." (#77570)

2024-01-10 Thread via cfe-commits

Author: martinboehme
Date: 2024-01-10T10:50:16+01:00
New Revision: 7ce010f2fb01341ab253547324e126d81d47f794

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

LOG: Revert "[clang][dataflow] Add an early-out to `flowConditionImplies()` / 
`flowConditionAllows()`." (#77570)

Reverts llvm/llvm-project#77453

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/Formula.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/Formula.h 
b/clang/include/clang/Analysis/FlowSensitive/Formula.h
index 0e6352403a832f..982e400c1deff1 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Formula.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Formula.h
@@ -75,10 +75,6 @@ class alignas(const Formula *) Formula {
 return static_cast(Value);
   }
 
-  bool isLiteral(bool b) const {
-return kind() == Literal && static_cast(Value) == b;
-  }
-
   ArrayRef operands() const {
 return ArrayRef(reinterpret_cast(this + 1),
 numOperands(kind()));

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index 500fbb39955d20..fa114979c8e326 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -174,9 +174,6 @@ Solver::Result DataflowAnalysisContext::querySolver(
 
 bool DataflowAnalysisContext::flowConditionImplies(Atom Token,
const Formula ) {
-  if (F.isLiteral(true))
-return true;
-
   // Returns true if and only if truth assignment of the flow condition implies
   // that `F` is also true. We prove whether or not this property holds by
   // reducing the problem to satisfiability checking. In other words, we 
attempt
@@ -191,9 +188,6 @@ bool DataflowAnalysisContext::flowConditionImplies(Atom 
Token,
 
 bool DataflowAnalysisContext::flowConditionAllows(Atom Token,
   const Formula ) {
-  if (F.isLiteral(true))
-return true;
-
   llvm::SetVector Constraints;
   Constraints.insert(().makeAtomRef(Token));
   Constraints.insert();



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


[clang] Revert "[clang][dataflow] Add an early-out to `flowConditionImplies()` / `flowConditionAllows()`." (PR #77570)

2024-01-10 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/77570

Reverts llvm/llvm-project#77453

>From 038c85ca9733404a67c0f328f268ca0124cf5b17 Mon Sep 17 00:00:00 2001
From: martinboehme 
Date: Wed, 10 Jan 2024 10:49:45 +0100
Subject: [PATCH] Revert "[clang][dataflow] Add an early-out to
 `flowConditionImplies()` / `flowConditionAllows()`. (#77453)"

This reverts commit 03a0bfa96a6eb09c4bbae344ac3aa062339aa730.
---
 clang/include/clang/Analysis/FlowSensitive/Formula.h| 4 
 .../lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp  | 6 --
 2 files changed, 10 deletions(-)

diff --git a/clang/include/clang/Analysis/FlowSensitive/Formula.h 
b/clang/include/clang/Analysis/FlowSensitive/Formula.h
index 0e6352403a832f..982e400c1deff1 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Formula.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Formula.h
@@ -75,10 +75,6 @@ class alignas(const Formula *) Formula {
 return static_cast(Value);
   }
 
-  bool isLiteral(bool b) const {
-return kind() == Literal && static_cast(Value) == b;
-  }
-
   ArrayRef operands() const {
 return ArrayRef(reinterpret_cast(this + 1),
 numOperands(kind()));
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index 500fbb39955d20..fa114979c8e326 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -174,9 +174,6 @@ Solver::Result DataflowAnalysisContext::querySolver(
 
 bool DataflowAnalysisContext::flowConditionImplies(Atom Token,
const Formula ) {
-  if (F.isLiteral(true))
-return true;
-
   // Returns true if and only if truth assignment of the flow condition implies
   // that `F` is also true. We prove whether or not this property holds by
   // reducing the problem to satisfiability checking. In other words, we 
attempt
@@ -191,9 +188,6 @@ bool DataflowAnalysisContext::flowConditionImplies(Atom 
Token,
 
 bool DataflowAnalysisContext::flowConditionAllows(Atom Token,
   const Formula ) {
-  if (F.isLiteral(true))
-return true;
-
   llvm::SetVector Constraints;
   Constraints.insert(().makeAtomRef(Token));
   Constraints.insert();

___
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   >