[clang] [clang][dataflow] Add synthetic fields to `RecordStorageLocation` (PR #73860)

2023-12-03 Thread via cfe-commits


@@ -367,3 +394,14 @@ clang::dataflow::FieldSet 
clang::dataflow::getObjectFields(QualType Type) {
   getFieldsFromClassHierarchy(Type, Fields);
   return Fields;
 }
+
+bool clang::dataflow::containsSameFields(
+const clang::dataflow::FieldSet ,
+const clang::dataflow::RecordStorageLocation::FieldToLoc ) {
+  if (Fields.size() != FieldLocs.size())
+return false;
+  for ([[maybe_unused]] auto [Field, Loc] : FieldLocs)
+if (!Fields.contains(cast_or_null(Field)))

martinboehme wrote:

This can happen for fields of reference type in the cases discussed 
[here](https://github.com/llvm/llvm-project/blob/c9c1b3c37fa5d5c617068afe67afcafacd58a241/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h#L78).

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


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/74199

>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH 1/5] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+Builder.defineMacro("__CCMP__");
+  if (HasCF)
+Builder.defineMacro("__CF__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1122,6 +1144,12 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("xsavec", true)
   .Case("xsaves", true)
   .Case("xsaveopt", true)
+  .Case("egpr", true)
+  .Case("push2pop2", true)
+  .Case("ppx", true)
+  .Case("ndd", true)
+  .Case("ccmp", true)
+  .Case("cf", true)
   .Default(false);
 }
 
@@ -1238,6 +1266,12 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("xsaves", HasXSAVES)
   .Case("xsaveopt", HasXSAVEOPT)
   .Case("fullbf16", HasFullBFloat16)
+  .Case("egpr", HasEGPR)
+  .Case("push2pop2", HasPush2Pop2)
+  .Case("ppx", HasPPX)
+  .Case("ndd", HasNDD)
+  .Case("ccmp", HasCCMP)
+  .Case("cf", HasCF)
   

[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits


@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)

KanRobert wrote:

Yes, done.

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


[libcxx] [clang] [llvm] [mlir] [compiler-rt] [flang] [clang-tools-extra] [mlir] Fix a zero stride canonicalizer crash (PR #74200)

2023-12-03 Thread Rik Huijzer via cfe-commits

rikhuijzer wrote:

> Is it possible to add the test case (or minimal similar example) with 
> `--inline` option so that we can confirm the original issue is resolved.
> 
> #73383

Thanks for the review and fixing the typos that I've made! I've added a test in 
a new `MemRef/inlining.mlir` file, which is in line with the other files:
```
$ rg -l '\-inline' mlir/test
mlir/test/Dialect/MemRef/inlining.mlir
mlir/test/Dialect/Vector/inlining.mlir
mlir/test/Dialect/UB/inlining.mlir
mlir/test/Dialect/Async/async-parallel-for-compute-fn.mlir
mlir/test/Dialect/Async/async-parallel-for-canonicalize.mlir
mlir/test/Dialect/Affine/inlining.mlir
mlir/test/Dialect/LLVMIR/inline-byval-huge.mlir
mlir/test/Dialect/Bufferization/inlining.mlir
mlir/test/Dialect/LLVMIR/inlining-alias-scopes.mlir
mlir/test/Dialect/LLVMIR/inlining.mlir
mlir/test/Dialect/Linalg/inline-scalar-operands.mlir
mlir/test/Dialect/Tosa/inlining.mlir
mlir/test/Dialect/Linalg/inlining.mlir
mlir/test/lib/Transforms/TestInlining.cpp
mlir/test/Transforms/inlining.mlir
mlir/test/Transforms/inlining-repeated-use.mlir
mlir/test/Transforms/inlining-recursive.mlir
mlir/test/Transforms/inlining-dce.mlir
mlir/test/Transforms/test-inlining.mlir
```
(Also test additions can always be reverted of course so it shouldn't be too 
bad.) Also I double checked that 
https://github.com/llvm/llvm-project/issues/73383 doesn't crash on this PR.

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


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Phoebe Wang via cfe-commits


@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;

phoebewang wrote:

You should comment in code for record not commit message.

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


[libcxx] [clang] [llvm] [mlir] [compiler-rt] [flang] [clang-tools-extra] [mlir] Fix a zero stride canonicalizer crash (PR #74200)

2023-12-03 Thread Rik Huijzer via cfe-commits

https://github.com/rikhuijzer updated 
https://github.com/llvm/llvm-project/pull/74200

>From 22928e7e5da508d8d9dc8d4b7e54f84cccadef06 Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Mon, 20 Nov 2023 09:02:41 +0100
Subject: [PATCH 1/7] [mlir][tensor] Fix canon via `hasNegativeDimension`

---
 mlir/include/mlir/Dialect/Tensor/IR/Tensor.h |  6 ++
 mlir/lib/Dialect/Tensor/IR/TensorOps.cpp | 15 +++
 mlir/test/Dialect/Tensor/canonicalize.mlir   | 10 ++
 3 files changed, 31 insertions(+)

diff --git a/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h 
b/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h
index 06642adda42b3..0d027057b3a95 100644
--- a/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h
+++ b/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h
@@ -150,6 +150,12 @@ LogicalResult getOrCreateDestinations(OpBuilder , 
Location loc, Operation *op,
 /// Tests if types are the same when ignoring encoding on ranked tensors.
 bool isSameTypeWithoutEncoding(Type tp1, Type tp2);
 
+/// Helper function to check whether the dimensions are non-negative. This
+/// check also occurs in the verifier, but we need it at later stages too
+/// because the verifier ignores dynamic dimensions, but later stages might
+/// have constant folded those to (negative) constants.
+bool hasNegativeDimension(SmallVector shape);
+
 /// Function to control the folding of constant and extract slice.
 using ControlConstantExtractSliceFusionFn = 
std::function;
 
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp 
b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
index e469815496e18..3297ef673ca2e 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
@@ -125,6 +125,12 @@ bool tensor::isSameTypeWithoutEncoding(Type tp1, Type tp2) 
{
   return tp1 == tp2; // default implementation
 }
 
+bool tensor::hasNegativeDimension(SmallVector shape) {
+  return llvm::any_of(shape, [](int64_t dim) {
+return !ShapedType::isDynamic(dim) && dim < 0;
+  });
+}
+
 /// Compute the dropped dimensions of a rank-reducing tensor.extract_slice op 
or
 /// rank-extending tensor.insert_slice op.
 static llvm::SmallBitVector getDroppedDims(ArrayRef reducedShape,
@@ -1801,6 +1807,10 @@ RankedTensorType 
ExtractSliceOp::inferCanonicalRankReducedResultType(
   dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets);
   dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes);
   dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides);
+  if (hasNegativeDimension(staticOffsets))
+return {};
+  if (hasNegativeDimension(staticSizes))
+return {};
   return ExtractSliceOp::inferCanonicalRankReducedResultType(
   desiredResultRank, sourceRankedTensorType, staticOffsets, staticSizes,
   staticStrides);
@@ -2370,6 +2380,8 @@ class InsertSliceOpConstantArgumentFolder final
 auto sourceType = ExtractSliceOp::inferCanonicalRankReducedResultType(
 insertSliceOp.getSourceType().getRank(), insertSliceOp.getDestType(),
 mixedOffsets, mixedSizes, mixedStrides);
+if (!sourceType)
+  return failure();
 Value toInsert = insertSliceOp.getSource();
 if (sourceType != insertSliceOp.getSourceType()) {
   OpBuilder::InsertionGuard g(rewriter);
@@ -2500,6 +2512,8 @@ struct InsertSliceOpSourceCastInserter final
   getConstantIntValue(insertSliceOp.getMixedSizes()[i]))
 newSrcShape[i] = *constInt;
 }
+// if (hasNegativeDimension(newSrcShape))
+//  return failure();
 
 RankedTensorType newSrcType =
 RankedTensorType::get(newSrcShape, srcType.getElementType());
@@ -2521,6 +2535,7 @@ struct InsertSliceOpSourceCastInserter final
   rewriter.setInsertionPoint(insertSliceOp->getParentOp());
 Value cast = rewriter.create(
 insertSliceOp.getLoc(), newSrcType, insertSliceOp.getSource());
+
 rewriter.replaceOpWithNewOp(
 insertSliceOp, cast, insertSliceOp.getDest(),
 insertSliceOp.getMixedOffsets(), insertSliceOp.getMixedSizes(),
diff --git a/mlir/test/Dialect/Tensor/canonicalize.mlir 
b/mlir/test/Dialect/Tensor/canonicalize.mlir
index ea8c17640d7c1..88f27d3d36b04 100644
--- a/mlir/test/Dialect/Tensor/canonicalize.mlir
+++ b/mlir/test/Dialect/Tensor/canonicalize.mlir
@@ -1102,6 +1102,16 @@ func.func @no_fold_collapse_of_expand_empty_expr(%arg0: 
tensor<3x2x2xf32>)
 
 // -
 
+func.func @no_fold_extract_slice_negative_offset(%arg0: tensor<8xf32>) -> 
tensor {
+  %c-1 = arith.constant -1 : index
+  %e = tensor.extract_slice %arg0[1] [%c-1] [1] : tensor<8xf32> to 
tensor
+  return %e : tensor
+}
+// CHECK-LABEL: func @no_fold_extract_slice_negative_offset
+// CHECK: tensor.extract_slice
+
+// -
+
 func.func @reshape_splat_constant_int32() -> tensor<2x4x2xi32> {
   %c0 = arith.constant dense<42> : tensor<2x8xi32>
   %0 = tensor.expand_shape %c0 [[0], [1, 2]]

>From ecef5428c160cb72103e06a160c450440ce1f416 Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Mon, 20 Nov 2023 16:27:53 +0100

[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/74199

>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH 1/4] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+Builder.defineMacro("__CCMP__");
+  if (HasCF)
+Builder.defineMacro("__CF__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1122,6 +1144,12 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("xsavec", true)
   .Case("xsaves", true)
   .Case("xsaveopt", true)
+  .Case("egpr", true)
+  .Case("push2pop2", true)
+  .Case("ppx", true)
+  .Case("ndd", true)
+  .Case("ccmp", true)
+  .Case("cf", true)
   .Default(false);
 }
 
@@ -1238,6 +1266,12 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("xsaves", HasXSAVES)
   .Case("xsaveopt", HasXSAVEOPT)
   .Case("fullbf16", HasFullBFloat16)
+  .Case("egpr", HasEGPR)
+  .Case("push2pop2", HasPush2Pop2)
+  .Case("ppx", HasPPX)
+  .Case("ndd", HasNDD)
+  .Case("ccmp", HasCCMP)
+  .Case("cf", HasCF)
   

[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Phoebe Wang via cfe-commits


@@ -422,3 +422,28 @@
 
 // RUN: touch %t.o
 // RUN: %clang -fdriver-only -Werror --target=x86_64-pc-linux-gnu 
-mharden-sls=all %t.o -o /dev/null 2>&1 | count 0
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=APXF %s

phoebewang wrote:

Missing tests for macro defines

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


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Phoebe Wang via cfe-commits


@@ -422,3 +422,28 @@
 
 // RUN: touch %t.o
 // RUN: %clang -fdriver-only -Werror --target=x86_64-pc-linux-gnu 
-mharden-sls=all %t.o -o /dev/null 2>&1 | count 0
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=APXF %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apxf %s -### -o %t.o 2>&1 
| FileCheck -check-prefix=NO-APXF %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apxf -mapxf %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=APXF %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapxf -mno-apxf %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=NO-APXF %s
+//
+// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx"
+// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx"
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr,ndd %s 
-### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr 
-mapx-features=ndd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apx-features=egpr 
-mno-apx-features=ndd %s -### -o %t.o 2>&1 | FileCheck 
-check-prefix=NO-EGPR-NO-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apx-features=egpr 
-mapx-features=egpr,ndd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD 
%s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apx-features=egpr,ndd 
-mapx-features=egpr %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NO-NDD 
%s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr,ndd 
-mno-apx-features=egpr %s -### -o %t.o 2>&1 | FileCheck 
-check-prefix=NO-EGPR-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr 
-mno-apx-features=egpr,ndd %s -### -o %t.o 2>&1 | FileCheck 
-check-prefix=NO-EGPR-NO-NDD %s
+//
+// EGPR-NDD: "-target-feature" "+egpr" "-target-feature" "+ndd"
+// EGPR-NO-NDD: "-target-feature" "-ndd" "-target-feature" "+egpr"
+// NO-EGPR-NDD: "-target-feature" "+ndd" "-target-feature" "-egpr"
+// NO-EGPR-NO-NDD: "-target-feature" "-egpr" "-target-feature" "-ndd"
+

phoebewang wrote:

Missing tests for "push2pop2", "ppx", "ccmp" and "cf"

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


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits


@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;

KanRobert wrote:

Explained in the description.

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


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits

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


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Phoebe Wang via cfe-commits


@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)

phoebewang wrote:

Missing PPX?

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


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Phoebe Wang via cfe-commits


@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;

phoebewang wrote:

The commit message mentions `alias of -m[no-]apx-features=< all APX features 
covered by CPUID APX_F>`, why only 3 here?

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


[llvm] [clang] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (PR #72849)

2023-12-03 Thread Sander de Smalen via cfe-commits


@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// Spill and fill of ZT0
+//
+let TargetGuard = "sme2" in {
+  def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;

sdesmalen-arm wrote:

Just noticed this after you landed it, but LDR does not preserve ZT0 because 
it's currently modelled as part of ZA.
This will be modelled differently with 
https://github.com/ARM-software/acle/pull/276, but it would be good to fix the 
attribute for now.

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


[clang-tools-extra] [mlir] [llvm] [clang] [mlir] Fix a zero stride canonicalizer crash (PR #74200)

2023-12-03 Thread Rik Huijzer via cfe-commits

https://github.com/rikhuijzer updated 
https://github.com/llvm/llvm-project/pull/74200

>From 22928e7e5da508d8d9dc8d4b7e54f84cccadef06 Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Mon, 20 Nov 2023 09:02:41 +0100
Subject: [PATCH 1/6] [mlir][tensor] Fix canon via `hasNegativeDimension`

---
 mlir/include/mlir/Dialect/Tensor/IR/Tensor.h |  6 ++
 mlir/lib/Dialect/Tensor/IR/TensorOps.cpp | 15 +++
 mlir/test/Dialect/Tensor/canonicalize.mlir   | 10 ++
 3 files changed, 31 insertions(+)

diff --git a/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h 
b/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h
index 06642adda42b3..0d027057b3a95 100644
--- a/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h
+++ b/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h
@@ -150,6 +150,12 @@ LogicalResult getOrCreateDestinations(OpBuilder , 
Location loc, Operation *op,
 /// Tests if types are the same when ignoring encoding on ranked tensors.
 bool isSameTypeWithoutEncoding(Type tp1, Type tp2);
 
+/// Helper function to check whether the dimensions are non-negative. This
+/// check also occurs in the verifier, but we need it at later stages too
+/// because the verifier ignores dynamic dimensions, but later stages might
+/// have constant folded those to (negative) constants.
+bool hasNegativeDimension(SmallVector shape);
+
 /// Function to control the folding of constant and extract slice.
 using ControlConstantExtractSliceFusionFn = 
std::function;
 
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp 
b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
index e469815496e18..3297ef673ca2e 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
@@ -125,6 +125,12 @@ bool tensor::isSameTypeWithoutEncoding(Type tp1, Type tp2) 
{
   return tp1 == tp2; // default implementation
 }
 
+bool tensor::hasNegativeDimension(SmallVector shape) {
+  return llvm::any_of(shape, [](int64_t dim) {
+return !ShapedType::isDynamic(dim) && dim < 0;
+  });
+}
+
 /// Compute the dropped dimensions of a rank-reducing tensor.extract_slice op 
or
 /// rank-extending tensor.insert_slice op.
 static llvm::SmallBitVector getDroppedDims(ArrayRef reducedShape,
@@ -1801,6 +1807,10 @@ RankedTensorType 
ExtractSliceOp::inferCanonicalRankReducedResultType(
   dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets);
   dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes);
   dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides);
+  if (hasNegativeDimension(staticOffsets))
+return {};
+  if (hasNegativeDimension(staticSizes))
+return {};
   return ExtractSliceOp::inferCanonicalRankReducedResultType(
   desiredResultRank, sourceRankedTensorType, staticOffsets, staticSizes,
   staticStrides);
@@ -2370,6 +2380,8 @@ class InsertSliceOpConstantArgumentFolder final
 auto sourceType = ExtractSliceOp::inferCanonicalRankReducedResultType(
 insertSliceOp.getSourceType().getRank(), insertSliceOp.getDestType(),
 mixedOffsets, mixedSizes, mixedStrides);
+if (!sourceType)
+  return failure();
 Value toInsert = insertSliceOp.getSource();
 if (sourceType != insertSliceOp.getSourceType()) {
   OpBuilder::InsertionGuard g(rewriter);
@@ -2500,6 +2512,8 @@ struct InsertSliceOpSourceCastInserter final
   getConstantIntValue(insertSliceOp.getMixedSizes()[i]))
 newSrcShape[i] = *constInt;
 }
+// if (hasNegativeDimension(newSrcShape))
+//  return failure();
 
 RankedTensorType newSrcType =
 RankedTensorType::get(newSrcShape, srcType.getElementType());
@@ -2521,6 +2535,7 @@ struct InsertSliceOpSourceCastInserter final
   rewriter.setInsertionPoint(insertSliceOp->getParentOp());
 Value cast = rewriter.create(
 insertSliceOp.getLoc(), newSrcType, insertSliceOp.getSource());
+
 rewriter.replaceOpWithNewOp(
 insertSliceOp, cast, insertSliceOp.getDest(),
 insertSliceOp.getMixedOffsets(), insertSliceOp.getMixedSizes(),
diff --git a/mlir/test/Dialect/Tensor/canonicalize.mlir 
b/mlir/test/Dialect/Tensor/canonicalize.mlir
index ea8c17640d7c1..88f27d3d36b04 100644
--- a/mlir/test/Dialect/Tensor/canonicalize.mlir
+++ b/mlir/test/Dialect/Tensor/canonicalize.mlir
@@ -1102,6 +1102,16 @@ func.func @no_fold_collapse_of_expand_empty_expr(%arg0: 
tensor<3x2x2xf32>)
 
 // -
 
+func.func @no_fold_extract_slice_negative_offset(%arg0: tensor<8xf32>) -> 
tensor {
+  %c-1 = arith.constant -1 : index
+  %e = tensor.extract_slice %arg0[1] [%c-1] [1] : tensor<8xf32> to 
tensor
+  return %e : tensor
+}
+// CHECK-LABEL: func @no_fold_extract_slice_negative_offset
+// CHECK: tensor.extract_slice
+
+// -
+
 func.func @reshape_splat_constant_int32() -> tensor<2x4x2xi32> {
   %c0 = arith.constant dense<42> : tensor<2x8xi32>
   %0 = tensor.expand_shape %c0 [[0], [1, 2]]

>From ecef5428c160cb72103e06a160c450440ce1f416 Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Mon, 20 Nov 2023 16:27:53 +0100

[clang] [clang-format] Remove duplicates in @property using std::set (PR #74235)

2023-12-03 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/74235

>From 7323d9261fe8c876fe3a656a98e186af3dd0b2a0 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 3 Dec 2023 01:41:57 -0800
Subject: [PATCH 1/2] [clang-format] Remove duplicates in @property using
 std::set

Re-implement ObjCPropertyAttributeOrder using std::set for sorting and
removing duplicates. (We can't use llvm::SmallSet because it's unordered.)
---
 .../ObjCPropertyAttributeOrderFixer.cpp   | 116 ++
 .../Format/ObjCPropertyAttributeOrderFixer.h  |   4 +-
 .../ObjCPropertyAttributeOrderFixerTest.cpp   |  12 +-
 3 files changed, 75 insertions(+), 57 deletions(-)

diff --git a/clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp 
b/clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
index 20108306f1039..57b19a62154d1 100644
--- a/clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
+++ b/clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
@@ -15,8 +15,6 @@
 
 #include "ObjCPropertyAttributeOrderFixer.h"
 
-#include "llvm/ADT/Sequence.h"
-
 #include 
 
 namespace clang {
@@ -25,11 +23,10 @@ namespace format {
 ObjCPropertyAttributeOrderFixer::ObjCPropertyAttributeOrderFixer(
 const Environment , const FormatStyle )
 : TokenAnalyzer(Env, Style) {
-
   // Create an "order priority" map to use to sort properties.
-  unsigned index = 0;
+  unsigned Index = 0;
   for (const auto  : Style.ObjCPropertyAttributeOrder)
-SortOrderMap[Property] = index++;
+SortOrderMap[Property] = Index++;
 }
 
 struct ObjCPropertyEntry {
@@ -37,14 +34,9 @@ struct ObjCPropertyEntry {
   StringRef Value; // eg, the "foo" of the attribute "getter=foo"
 };
 
-static bool isObjCPropertyAttribute(const FormatToken *Tok) {
-  // Most attributes look like identifiers, but `class` is a keyword.
-  return Tok->isOneOf(tok::identifier, tok::kw_class);
-}
-
 void ObjCPropertyAttributeOrderFixer::sortPropertyAttributes(
 const SourceManager , tooling::Replacements ,
-const FormatToken *BeginTok, const FormatToken *EndTok) const {
+const FormatToken *BeginTok, const FormatToken *EndTok) {
   assert(BeginTok);
   assert(EndTok);
   assert(EndTok->Previous);
@@ -53,8 +45,16 @@ void ObjCPropertyAttributeOrderFixer::sortPropertyAttributes(
   if (BeginTok == EndTok || BeginTok->Next == EndTok)
 return;
 
+  // Use a set to sort attributes and remove duplicates.
+  std::set Ordinals;
+
+  // Create a "remapping index" on how to reorder the attributes.
+  SmallVector Indices;
+
   // Collect the attributes.
-  SmallVector PropertyAttributes;
+  SmallVector PropertyAttributes;
+  bool HasDuplicates = false;
+  int Index = 0;
   for (auto Tok = BeginTok; Tok != EndTok; Tok = Tok->Next) {
 assert(Tok);
 if (Tok->is(tok::comma)) {
@@ -62,13 +62,14 @@ void 
ObjCPropertyAttributeOrderFixer::sortPropertyAttributes(
   continue;
 }
 
-if (!isObjCPropertyAttribute(Tok)) {
+// Most attributes look like identifiers, but `class` is a keyword.
+if (!Tok->isOneOf(tok::identifier, tok::kw_class)) {
   // If we hit any other kind of token, just bail.
   return;
 }
 
-// Memoize the attribute. (Note that 'class' is a legal attribute!)
-PropertyAttributes.push_back({Tok->TokenText, StringRef{}});
+const StringRef Attribute{Tok->TokenText};
+StringRef Value;
 
 // Also handle `getter=getFoo` attributes.
 // (Note: no check needed against `EndTok`, since its type is not
@@ -82,49 +83,66 @@ void 
ObjCPropertyAttributeOrderFixer::sortPropertyAttributes(
 return;
   }
   Tok = Tok->Next;
-  PropertyAttributes.back().Value = Tok->TokenText;
+  Value = Tok->TokenText;
+}
+
+auto It = SortOrderMap.find(Attribute);
+if (It == SortOrderMap.end())
+  It = SortOrderMap.insert({Attribute, SortOrderMap.size()}).first;
+
+// Sort the indices based on the priority stored in 'SortOrderMap'.
+const auto Ordinal = It->second;
+if (!Ordinals.insert(Ordinal).second) {
+  HasDuplicates = true;
+  continue;
 }
+
+if (Ordinal >= Indices.size())
+  Indices.resize(Ordinal + 1);
+Indices[Ordinal] = Index++;
+
+// Memoize the attribute.
+PropertyAttributes.push_back({Attribute, Value});
   }
 
-  // There's nothing to do unless there's more than one attribute.
-  if (PropertyAttributes.size() < 2)
-return;
+  if (!HasDuplicates) {
+// There's nothing to do unless there's more than one attribute.
+if (PropertyAttributes.size() < 2)
+  return;
 
-  // Create a "remapping index" on how to reorder the attributes.
-  SmallVector Indices =
-  llvm::to_vector<8>(llvm::seq(0, PropertyAttributes.size()));
-
-  // Sort the indices based on the priority stored in 'SortOrderMap'; use Max
-  // for missing values.
-  const auto SortOrderMax = Style.ObjCPropertyAttributeOrder.size();
-  auto SortIndex = [&](const StringRef ) -> unsigned {
-auto I = SortOrderMap.find(Needle);
-return (I == 

[clang] [llvm] [RISCV] Update the interface of sifive vqmaccqoq (PR #74284)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Brandon Wu (4vtomat)


Changes

The 
spec(https://sifive.cdn.prismic.io/sifive/60d5a660-3af0-49a3-a904-d2bbb1a21517_int8-matmul-spec.pdf)
 is updated.


---

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


23 Files Affected:

- (modified) clang/include/clang/Basic/riscv_sifive_vector.td (+17-9) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) clang/test/Sema/rvv-required-features.c (+2-16) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td (+38-23) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmacc_4x8x4.ll (+28-30) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmaccsu_4x8x4.ll (+28-30) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmaccu_4x8x4.ll (+28-30) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmaccus_4x8x4.ll (+28-30) 


``diff
diff --git a/clang/include/clang/Basic/riscv_sifive_vector.td 
b/clang/include/clang/Basic/riscv_sifive_vector.td
index bb54e26641861..61c2ff52d9f7c 100644
--- a/clang/include/clang/Basic/riscv_sifive_vector.td
+++ b/clang/include/clang/Basic/riscv_sifive_vector.td
@@ -112,7 +112,7 @@ multiclass RVVVFWMACCBuiltinSet> 
suffixes_prototypes> {
 defm NAME : RVVOutOp1Op2BuiltinSet;
 }
 
-multiclass RVVVQMACCBuiltinSet> suffixes_prototypes> {
+multiclass RVVVQMACCDODBuiltinSet> suffixes_prototypes> {
   let OverloadedName = NAME,
   Name = NAME,
   HasMasked = false,
@@ -120,6 +120,14 @@ multiclass RVVVQMACCBuiltinSet> 
suffixes_prototypes> {
 defm NAME : RVVOutOp1Op2BuiltinSet;
 }
 
+multiclass RVVVQMACCQOQBuiltinSet> suffixes_prototypes> {
+   let OverloadedName = NAME,
+   Name = NAME,
+   HasMasked = false,
+   Log2LMUL = [-1, 0, 1, 2] in
+ defm NAME : RVVOutOp1Op2BuiltinSet;
+}
+
 multiclass RVVVFNRCLIPBuiltinSet {
   let Log2LMUL = [-3, -2, -1, 0, 1, 2],
   Name = NAME,
@@ -130,18 +138,18 @@ multiclass RVVVFNRCLIPBuiltinSet;
-defm sf_vqmacc_2x8x2 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
-defm sf_vqmaccus_2x8x2 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
-defm sf_vqmaccsu_2x8x2 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)Uv"]]>;
+defm sf_vqmaccu_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)Uv"]]>;
+defm sf_vqmacc_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
+defm sf_vqmaccus_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
+defm sf_vqmaccsu_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)Uv"]]>;
   }
 
 let UnMaskedPolicyScheme = HasPolicyOperand in
   let RequiredFeatures = ["Xsfvqmaccqoq"] in {
-defm sf_vqmaccu_4x8x4 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)Uv"]]>;
-defm sf_vqmacc_4x8x4 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
-defm sf_vqmaccus_4x8x4 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
-defm sf_vqmaccsu_4x8x4 : 

[llvm] [clang] [RISCV] Update the interface of sifive vqmaccqoq (PR #74284)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Brandon Wu (4vtomat)


Changes

The 
spec(https://sifive.cdn.prismic.io/sifive/60d5a660-3af0-49a3-a904-d2bbb1a21517_int8-matmul-spec.pdf)
 is updated.


---

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


23 Files Affected:

- (modified) clang/include/clang/Basic/riscv_sifive_vector.td (+17-9) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmacc_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccsu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccu_4x8x4.c
 (+12-12) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccus_4x8x4.c
 (+12-12) 
- (modified) clang/test/Sema/rvv-required-features.c (+2-16) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td (+38-23) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmacc_4x8x4.ll (+28-30) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmaccsu_4x8x4.ll (+28-30) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmaccu_4x8x4.ll (+28-30) 
- (modified) llvm/test/CodeGen/RISCV/rvv/sf_vqmaccus_4x8x4.ll (+28-30) 


``diff
diff --git a/clang/include/clang/Basic/riscv_sifive_vector.td 
b/clang/include/clang/Basic/riscv_sifive_vector.td
index bb54e26641861..61c2ff52d9f7c 100644
--- a/clang/include/clang/Basic/riscv_sifive_vector.td
+++ b/clang/include/clang/Basic/riscv_sifive_vector.td
@@ -112,7 +112,7 @@ multiclass RVVVFWMACCBuiltinSet> 
suffixes_prototypes> {
 defm NAME : RVVOutOp1Op2BuiltinSet;
 }
 
-multiclass RVVVQMACCBuiltinSet> suffixes_prototypes> {
+multiclass RVVVQMACCDODBuiltinSet> suffixes_prototypes> {
   let OverloadedName = NAME,
   Name = NAME,
   HasMasked = false,
@@ -120,6 +120,14 @@ multiclass RVVVQMACCBuiltinSet> 
suffixes_prototypes> {
 defm NAME : RVVOutOp1Op2BuiltinSet;
 }
 
+multiclass RVVVQMACCQOQBuiltinSet> suffixes_prototypes> {
+   let OverloadedName = NAME,
+   Name = NAME,
+   HasMasked = false,
+   Log2LMUL = [-1, 0, 1, 2] in
+ defm NAME : RVVOutOp1Op2BuiltinSet;
+}
+
 multiclass RVVVFNRCLIPBuiltinSet {
   let Log2LMUL = [-3, -2, -1, 0, 1, 2],
   Name = NAME,
@@ -130,18 +138,18 @@ multiclass RVVVFNRCLIPBuiltinSet;
-defm sf_vqmacc_2x8x2 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
-defm sf_vqmaccus_2x8x2 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
-defm sf_vqmaccsu_2x8x2 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)Uv"]]>;
+defm sf_vqmaccu_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)Uv"]]>;
+defm sf_vqmacc_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
+defm sf_vqmaccus_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
+defm sf_vqmaccsu_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)Uv"]]>;
   }
 
 let UnMaskedPolicyScheme = HasPolicyOperand in
   let RequiredFeatures = ["Xsfvqmaccqoq"] in {
-defm sf_vqmaccu_4x8x4 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)Uv"]]>;
-defm sf_vqmacc_4x8x4 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
-defm sf_vqmaccus_4x8x4 : RVVVQMACCBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
-defm sf_vqmaccsu_4x8x4 : 

[clang] [llvm] [AMDGPU] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-12-03 Thread Vikram Hegde via cfe-commits

vikramRH wrote:

> Is there a separate PR open for "Add vector processing support to AMDGPU 
> printf"? I think it's easiest to move this part forward first

@arsenm , you are right. I just want to make sure we are good on runtime 
changes too now since there seems to be a blocker. The changes here are not 
necessary unless we are okay with runtime changes.

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


[clang] [llvm] [SimplifyCFG] Not folding branch in loop header with constant iterations (PR #74268)

2023-12-03 Thread via cfe-commits

bcl5980 wrote:

> > We should add TTI check for the condition. I believe don't unroll on X86 is 
> > a correct decision. Only like AMDGPU or NVPTX these GPU backend with heavy 
> > stack cost need this.
> > And I think you need to precommit tests first.
> 
> In fact, there is no direct/strong relation with stack cost, it mostly base 
> on unroll or not (or other loop optimizations). Maybe we should check 
> "unroll" info (e.g #pragma unroll, any targets with this hint should try best 
> to unroll too) before do or not do this folding. A little trouble is loop 
> info is not well established now.

Yeah, it is a problem we unroll or not. But this case generally I believe we 
don't want to unroll it.

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


[clang-tools-extra] [mlir] [clang] [llvm] [mlir] Fix a zero stride canonicalizer crash (PR #74200)

2023-12-03 Thread Kai Sasaki via cfe-commits

https://github.com/Lewuathe commented:

Is it possible to add the test case (or minimal similar example) with 
`--inline` option so that we can confirm the original issue is resolved.

https://github.com/llvm/llvm-project/issues/73383

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


[clang-tools-extra] [llvm] [clang] [mlir] [mlir] Fix a zero stride canonicalizer crash (PR #74200)

2023-12-03 Thread Kai Sasaki via cfe-commits


@@ -139,12 +139,36 @@ SmallVector
 getValuesSortedByKey(ArrayRef keys, ArrayRef values,
  llvm::function_ref compare);
 
+/// Helper function to check whether the passed in `sizes` or `values` are
+/// valid. This can be used to re-check whether dimensions are still valid
+/// after constant folding the dynamic dimensions.
+bool hasValidSizesOffsets(SmallVector sizesOrOffsets);
+
+/// Helper function to check whether the passed in `strides` are valid. This
+/// can be used to re-check whether dimensions are still valid after constant
+/// folding the dynamic dimensions.
+bool hasValidStrides(SmallVector strides);
+
 /// Returns "success" when any of the elements in `ofrs` is a constant value. 
In
 /// that case the value is replaced by an attribute. Returns "failure" when no
-/// folding happened. If `onlyNonNegative` is set, only non-negative constant
-/// values are folded.
+/// folding happened. If `onlyNonNegative` and `onlyNonZero` are set, only
+/// non-negative and non-zero constant values are folded respectively.
 LogicalResult foldDynamicIndexList(SmallVectorImpl ,
-   bool onlyNonNegative = false);
+   bool onlyNonNegative = false,
+   bool onlyNonZero = false);
+
+/// Returns "success" when any of the elements in `OffsetsOrSizes` is a

Lewuathe wrote:

```suggestion
/// Returns "success" when any of the elements in `offsetsOrSizes` is a
```

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


[mlir] [clang-tools-extra] [llvm] [clang] [mlir] Fix a zero stride canonicalizer crash (PR #74200)

2023-12-03 Thread Kai Sasaki via cfe-commits

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


[llvm] [mlir] [clang-tools-extra] [clang] [mlir] Fix a zero stride canonicalizer crash (PR #74200)

2023-12-03 Thread Kai Sasaki via cfe-commits


@@ -139,12 +139,36 @@ SmallVector
 getValuesSortedByKey(ArrayRef keys, ArrayRef values,
  llvm::function_ref compare);
 
+/// Helper function to check whether the passed in `sizes` or `values` are

Lewuathe wrote:

```suggestion
/// Helper function to check whether the passed in `sizes` or `offsets` are
```

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


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/74199

>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH 1/3] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+Builder.defineMacro("__CCMP__");
+  if (HasCF)
+Builder.defineMacro("__CF__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1122,6 +1144,12 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("xsavec", true)
   .Case("xsaves", true)
   .Case("xsaveopt", true)
+  .Case("egpr", true)
+  .Case("push2pop2", true)
+  .Case("ppx", true)
+  .Case("ndd", true)
+  .Case("ccmp", true)
+  .Case("cf", true)
   .Default(false);
 }
 
@@ -1238,6 +1266,12 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("xsaves", HasXSAVES)
   .Case("xsaveopt", HasXSAVEOPT)
   .Case("fullbf16", HasFullBFloat16)
+  .Case("egpr", HasEGPR)
+  .Case("push2pop2", HasPush2Pop2)
+  .Case("ppx", HasPPX)
+  .Case("ndd", HasNDD)
+  .Case("ccmp", HasCCMP)
+  .Case("cf", HasCF)
   

[clang] [clang-format] Fix a bug in `git-clang-format --binary` (PR #74176)

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

JOE1994 wrote:

I've been using `git clang-format` without the `--bin` flag using the following 
setting

1. `PATH=$PATH:~/llvm-project/build/bin:~/llvm-project/clang/tools/clang-format`
2. Run `git clang-format HEAD~1` at `~/llvm-project` directory

After this revision, I get the following error:
```
error: cannot find executable 
"/llvm-project/clang-format"
```
( = full path to the parent directory of 
`llvm-project` directory)

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


[llvm] [clang] [SimplifyCFG] Not folding branch in loop header with constant iterations (PR #74268)

2023-12-03 Thread via cfe-commits

xiangzh1 wrote:

> We should add TTI check for the condition. I believe don't unroll on X86 is a 
> correct decision. Only like AMDGPU or NVPTX these GPU backend with heavy 
> stack cost need this.
> 
> And I think you need to precommit tests first.

In fact, there is no direct/strong relation with stack cost, it mostly base on 
unroll or not (or other loop optimizations). Maybe we should check "unroll" 
info (e.g #pragma unroll) before do or not do this folding. A little trouble is 
loop info is not well established now.

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


[clang] [clang][CGOpenMPRuntimeGPU] Merge consecutive AddrSpaceCasts (NFC) (PR #74279)

2023-12-03 Thread Matt Arsenault via cfe-commits

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


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


[clang] [RISCV][NFC] Use AddTargetFeature to add fast-unaligned-access (PR #74280)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Wang Pengcheng (wangpc-pp)


Changes

We can reduce some code.


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


1 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+2-7) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 5d990ba78e5cc..0b696111e7d71 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -171,13 +171,8 @@ void riscv::getRISCVTargetFeatures(const Driver , const 
llvm::Triple ,
 Features.push_back("-save-restore");
 
   // -mno-unaligned-access is default, unless -munaligned-access is specified.
-  if (const Arg *A = Args.getLastArg(options::OPT_munaligned_access,
- options::OPT_mno_unaligned_access)) {
-if (A->getOption().matches(options::OPT_munaligned_access))
-  Features.push_back("+fast-unaligned-access");
-else
-  Features.push_back("-fast-unaligned-access");
-  }
+  AddTargetFeature(Args, Features, options::OPT_munaligned_access,
+   options::OPT_mno_unaligned_access, "fast-unaligned-access");
 
   // Now add any that the user explicitly requested on the command line,
   // which may override the defaults.

``




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


[clang] [RISCV][NFC] Use AddTargetFeature to add fast-unaligned-access (PR #74280)

2023-12-03 Thread Wang Pengcheng via cfe-commits

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

We can reduce some code.


>From 1a9364a8b1e0eae320774253ac98a445daf7ec9f Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 4 Dec 2023 14:11:19 +0800
Subject: [PATCH] [RISCV][NFC] Use AddTargetFeature to add
 fast-unaligned-access

We can reduce some code.
---
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 5d990ba78e5cc..0b696111e7d71 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -171,13 +171,8 @@ void riscv::getRISCVTargetFeatures(const Driver , const 
llvm::Triple ,
 Features.push_back("-save-restore");
 
   // -mno-unaligned-access is default, unless -munaligned-access is specified.
-  if (const Arg *A = Args.getLastArg(options::OPT_munaligned_access,
- options::OPT_mno_unaligned_access)) {
-if (A->getOption().matches(options::OPT_munaligned_access))
-  Features.push_back("+fast-unaligned-access");
-else
-  Features.push_back("-fast-unaligned-access");
-  }
+  AddTargetFeature(Args, Features, options::OPT_munaligned_access,
+   options::OPT_mno_unaligned_access, "fast-unaligned-access");
 
   // Now add any that the user explicitly requested on the command line,
   // which may override the defaults.

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


[clang] [clang][CGOpenMPRuntimeGPU] Merge consecutive AddrSpaceCasts (NFC) (PR #74279)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Youngsuk Kim (JOE1994)


Changes

Merge consecutive AddrSpaceCasts into a single AddrSpaceCast.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+2-9) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 5b9dbbf7e83a9..293ccaa3413cd 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3017,11 +3017,7 @@ CGOpenMPRuntimeGPU::getParameterAddress(CodeGenFunction 
,
   QualType TargetTy = TargetParam->getType();
   llvm::Value *TargetAddr = CGF.EmitLoadOfScalar(LocalAddr, /*Volatile=*/false,
  TargetTy, SourceLocation());
-  // First cast to generic.
-  TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-  TargetAddr,
-  llvm::PointerType::get(CGF.getLLVMContext(), /*AddrSpace=*/0));
-  // Cast from generic to native address space.
+  // Cast to native address space.
   TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
   TargetAddr,
   llvm::PointerType::get(CGF.getLLVMContext(), NativePointeeAddrSpace));
@@ -3048,11 +3044,8 @@ void CGOpenMPRuntimeGPU::emitOutlinedFunctionCall(
   TargetArgs.emplace_back(NativeArg);
   continue;
 }
-llvm::Value *TargetArg = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-NativeArg,
-llvm::PointerType::get(CGF.getLLVMContext(), /*AddrSpace*/ 0));
 TargetArgs.emplace_back(
-CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(TargetArg, 
TargetType));
+CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(NativeArg, 
TargetType));
   }
   CGOpenMPRuntime::emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, TargetArgs);
 }

``




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


[clang] [clang][CGOpenMPRuntimeGPU] Merge consecutive AddrSpaceCasts (NFC) (PR #74279)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Youngsuk Kim (JOE1994)


Changes

Merge consecutive AddrSpaceCasts into a single AddrSpaceCast.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+2-9) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 5b9dbbf7e83a9..293ccaa3413cd 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3017,11 +3017,7 @@ CGOpenMPRuntimeGPU::getParameterAddress(CodeGenFunction 
,
   QualType TargetTy = TargetParam->getType();
   llvm::Value *TargetAddr = CGF.EmitLoadOfScalar(LocalAddr, /*Volatile=*/false,
  TargetTy, SourceLocation());
-  // First cast to generic.
-  TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-  TargetAddr,
-  llvm::PointerType::get(CGF.getLLVMContext(), /*AddrSpace=*/0));
-  // Cast from generic to native address space.
+  // Cast to native address space.
   TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
   TargetAddr,
   llvm::PointerType::get(CGF.getLLVMContext(), NativePointeeAddrSpace));
@@ -3048,11 +3044,8 @@ void CGOpenMPRuntimeGPU::emitOutlinedFunctionCall(
   TargetArgs.emplace_back(NativeArg);
   continue;
 }
-llvm::Value *TargetArg = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-NativeArg,
-llvm::PointerType::get(CGF.getLLVMContext(), /*AddrSpace*/ 0));
 TargetArgs.emplace_back(
-CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(TargetArg, 
TargetType));
+CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(NativeArg, 
TargetType));
   }
   CGOpenMPRuntime::emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, TargetArgs);
 }

``




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


[clang] [clang][CGOpenMPRuntimeGPU] Merge consecutive AddrSpaceCasts (NFC) (PR #74279)

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

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/74279

Merge consecutive AddrSpaceCasts into a single AddrSpaceCast.

>From 4e86272d980b26bf1240df94cbc894e7ded0d018 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sun, 3 Dec 2023 23:52:33 -0600
Subject: [PATCH] [clang][CGOpenMPRuntimeGPU] Merge consecutive AddrSpaceCasts
 (NFC)

Merge consecutive AddrSpaceCasts into a single AddrSpaceCast.
---
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 5b9dbbf7e83a9..293ccaa3413cd 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3017,11 +3017,7 @@ CGOpenMPRuntimeGPU::getParameterAddress(CodeGenFunction 
,
   QualType TargetTy = TargetParam->getType();
   llvm::Value *TargetAddr = CGF.EmitLoadOfScalar(LocalAddr, /*Volatile=*/false,
  TargetTy, SourceLocation());
-  // First cast to generic.
-  TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-  TargetAddr,
-  llvm::PointerType::get(CGF.getLLVMContext(), /*AddrSpace=*/0));
-  // Cast from generic to native address space.
+  // Cast to native address space.
   TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
   TargetAddr,
   llvm::PointerType::get(CGF.getLLVMContext(), NativePointeeAddrSpace));
@@ -3048,11 +3044,8 @@ void CGOpenMPRuntimeGPU::emitOutlinedFunctionCall(
   TargetArgs.emplace_back(NativeArg);
   continue;
 }
-llvm::Value *TargetArg = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-NativeArg,
-llvm::PointerType::get(CGF.getLLVMContext(), /*AddrSpace*/ 0));
 TargetArgs.emplace_back(
-CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(TargetArg, 
TargetType));
+CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(NativeArg, 
TargetType));
   }
   CGOpenMPRuntime::emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, TargetArgs);
 }

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


[clang] [clang-format] Add "three dot" diff option to git-clang-format (PR #74230)

2023-12-03 Thread via cfe-commits

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

LGTM. 
Please give some time for clang-format folks to review the change as it is not 
my area of expertise.

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


[clang] Remove warnings from -Wchar-subscripts for known positive constants (PR #69061)

2023-12-03 Thread via cfe-commits

cor3ntin wrote:

Thanks for your first contribution. Maybe the first of many :D

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


[clang] Remove warnings from -Wchar-subscripts for known positive constants (PR #69061)

2023-12-03 Thread via cfe-commits

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


[clang] 0031efe - Remove warnings from -Wchar-subscripts for known positive constants (#69061)

2023-12-03 Thread via cfe-commits

Author: wheatman
Date: 2023-12-04T06:49:37+01:00
New Revision: 0031efe6be19735402656a76b64a173d17f1f935

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

LOG: Remove warnings from -Wchar-subscripts for known positive constants 
(#69061)

Fixes #18763

Remove warnings when using a signed char as an array bound if the char is a 
known positive constant.

This goes one step farther than gcc does.

For example given the following code
```c++
char upper[300];

int main() {
  upper['a'] = 'A';
  char b = 'a';
  upper[b] = 'A';
  const char c = 'a';
  upper[c] = 'A';
  constexpr char d = 'a';
  upper[d] = 'A';
  char e = -1;
  upper[e] = 'A';
  const char f = -1;
  upper[f] = 'A';
  constexpr char g = -1;
  upper[g] = 'A';
  return 1;
}
```

clang currently gives warnings for all cases, while gcc gives warnings
for all cases except for 'a' (https://godbolt.org/z/5ahjETTv3)

With the change there is no longer any warning for 'a', 'c', or 'd'.

Added: 
clang/test/Sema/warn-char-subscripts.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/warn-char-subscripts.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7a948fd3fae5..683d0026bb345 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -651,6 +651,8 @@ Bug Fixes in This Version
 - Fixed false positive error emitted by clang when performing qualified name
   lookup and the current class instantiation has dependent bases.
   Fixes (`#13826 `_)
+- Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are 
known non-negative constants.
+  Fixes (`#18763 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index d1b2b8084b8ff..d629be083d8c3 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6053,9 +6053,14 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
  << IndexExpr->getSourceRange());
 
   if ((IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_S) ||
-   IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U))
- && !IndexExpr->isTypeDependent())
-Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange();
+   IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U)) &&
+  !IndexExpr->isTypeDependent()) {
+std::optional IntegerContantExpr =
+IndexExpr->getIntegerConstantExpr(getASTContext());
+if (!IntegerContantExpr.has_value() ||
+IntegerContantExpr.value().isNegative())
+  Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange();
+  }
 
   // C99 6.5.2.1p1: "shall have type "pointer to *object* type". Similarly,
   // C++ [expr.sub]p1: The type "T" shall be a completely-defined object

diff  --git a/clang/test/Sema/warn-char-subscripts.c 
b/clang/test/Sema/warn-char-subscripts.c
index 2e72d90fa612a..0a012f68feae0 100644
--- a/clang/test/Sema/warn-char-subscripts.c
+++ b/clang/test/Sema/warn-char-subscripts.c
@@ -62,3 +62,28 @@ void t10(void) {
   UnsignedCharTy subscript = 0;
   int val = array[subscript]; // no warning for unsigned char
 }
+
+void t11(void) {
+  int array[256] = { 0 };
+  int val = array['a']; // no warning for char with known positive value
+}
+
+void t12(void) {
+  int array[256] = { 0 };
+  char b = 'a';
+  int val = array[b]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t13(void) {
+  int array[256] = { 0 };
+  const char b = 'a';
+  int val = array[b]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t14(void) {
+  int array[256] = { 0 }; // expected-note {{array 'array' declared here}}
+  const char b = -1;
+  // expected-warning@+2 {{array subscript is of type 'char'}}
+  // expected-warning@+1 {{array index -1 is before the beginning of the 
array}}
+  int val = array[b];
+}

diff  --git a/clang/test/Sema/warn-char-subscripts.cpp 
b/clang/test/Sema/warn-char-subscripts.cpp
new file mode 100644
index 0..929fb372c5173
--- /dev/null
+++ b/clang/test/Sema/warn-char-subscripts.cpp
@@ -0,0 +1,103 @@
+// RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s
+
+void t1(void) {
+  int array[1] = { 0 };
+  char subscript = 0;
+  int val = array[subscript]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+void t2(void) {
+  int array[1] = { 0 };
+  char subscript = 0;
+  int val = subscript[array]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+void t3(void) {
+  int *array = 0;
+  char subscript = 0;
+  int val = array[subscript]; // 

[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

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

ChuanqiXu9 wrote:

@sam-mccall ping

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


[libcxx] [compiler-rt] [clang] [libc] [clang-tools-extra] [flang] [llvm] [clang][AMDGPU] fix the return type for ballot (PR #73906)

2023-12-03 Thread Sameer Sahasrabuddhe via cfe-commits

https://github.com/ssahasra updated 
https://github.com/llvm/llvm-project/pull/73906

>From 8ecb6310a4912de50628cf3db5ff8488fa919bb1 Mon Sep 17 00:00:00 2001
From: Sameer Sahasrabuddhe 
Date: Fri, 1 Dec 2023 14:24:30 +0530
Subject: [PATCH 1/2] [clang][AMDGPU] precommit test for ballot on Windows

The Clang declaration of the wave-64 builtin uses "UL" as the return type, which
is interpreted as a 32-bit unsigned integer on Windows. This emits an incorrect
LLVM declaration with i32 return type instead of i64. The clang declaration
needs to be fixed to use "WU" instead.
---
 clang/test/CodeGenHIP/ballot.cpp | 27 +++
 1 file changed, 27 insertions(+)
 create mode 100644 clang/test/CodeGenHIP/ballot.cpp

diff --git a/clang/test/CodeGenHIP/ballot.cpp b/clang/test/CodeGenHIP/ballot.cpp
new file mode 100644
index 0..6e1cbbdfc7af1
--- /dev/null
+++ b/clang/test/CodeGenHIP/ballot.cpp
@@ -0,0 +1,27 @@
+// REQUIRES: amdgpu-registered-target
+// XFAIL: *
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-pc-windows-msvc -target-cpu gfx900 -x hip -emit-llvm -fcuda-is-device -o 
- %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-pc-windows-msvc -target-cpu gfx900 -x hip -S -fcuda-is-device -o - %s | 
FileCheck %s --check-prefix=GFX9
+
+// Unlike OpenCL, HIP depends on the C++ interpration of "unsigned long", which
+// is 64 bits long on Linux and 32 bits long on Windows. The return type of the
+// ballot intrinsic needs to be a 64 bit integer on both platforms. This test
+// cross-compiles to Windows to confirm that the return type is indeed 64 bits
+// on Windows.
+
+// FIXME: The Clang declaration of the wave-64 builtin uses "UL" as the return
+// type, which is interpreted as a 32-bit unsigned integer on Windows. This
+// emits an incorrect LLVM declaration with i32 return type instead of i64. The
+// clang declaration needs to be fixed to use "WU" instead.
+
+// CHECK-LABEL: @_Z3fooi
+// CHECK: call i64 @llvm.amdgcn.ballot.i64
+
+// GFX9-LABEL: _Z3fooi:
+// GFX9: v_cmp_ne_u32_e64
+
+#define __device__ __attribute__((device))
+
+__device__ unsigned long long foo(int p) {
+  return __builtin_amdgcn_ballot_w64(p);
+}

>From bfcff343a601923da554cafda26568a445fc39b0 Mon Sep 17 00:00:00 2001
From: Sameer Sahasrabuddhe 
Date: Thu, 30 Nov 2023 12:14:38 +0530
Subject: [PATCH 2/2] [clang][AMDGPU] fix the return type for ballot

In the builtins declaration, "ULi" is a 32-bit integer on Windows. Use "WUi"
instead to ensure a 64-bit integer on all platforms.
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def | 4 ++--
 clang/test/CodeGenHIP/ballot.cpp | 6 --
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index a19c8bd5f219e..8b59b3790d7bc 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -150,8 +150,8 @@ BUILTIN(__builtin_amdgcn_mqsad_u32_u8, "V4UiWUiUiV4Ui", 
"nc")
 // Ballot builtins.
 
//===--===//
 
-TARGET_BUILTIN(__builtin_amdgcn_ballot_w32, "Uib", "nc", "wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_ballot_w64, "LUib", "nc", "wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_ballot_w32, "ZUib", "nc", "wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_ballot_w64, "WUib", "nc", "wavefrontsize64")
 
 // Deprecated intrinsics in favor of __builtin_amdgn_ballot_{w32|w64}
 BUILTIN(__builtin_amdgcn_uicmp, "WUiUiUiIi", "nc")
diff --git a/clang/test/CodeGenHIP/ballot.cpp b/clang/test/CodeGenHIP/ballot.cpp
index 6e1cbbdfc7af1..a1c23e2136c71 100644
--- a/clang/test/CodeGenHIP/ballot.cpp
+++ b/clang/test/CodeGenHIP/ballot.cpp
@@ -1,5 +1,4 @@
 // REQUIRES: amdgpu-registered-target
-// XFAIL: *
 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-pc-windows-msvc -target-cpu gfx900 -x hip -emit-llvm -fcuda-is-device -o 
- %s | FileCheck %s
 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-pc-windows-msvc -target-cpu gfx900 -x hip -S -fcuda-is-device -o - %s | 
FileCheck %s --check-prefix=GFX9
 
@@ -9,11 +8,6 @@
 // cross-compiles to Windows to confirm that the return type is indeed 64 bits
 // on Windows.
 
-// FIXME: The Clang declaration of the wave-64 builtin uses "UL" as the return
-// type, which is interpreted as a 32-bit unsigned integer on Windows. This
-// emits an incorrect LLVM declaration with i32 return type instead of i64. The
-// clang declaration needs to be fixed to use "WU" instead.
-
 // CHECK-LABEL: @_Z3fooi
 // CHECK: call i64 @llvm.amdgcn.ballot.i64
 

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


[clang] [clang][AMDGPU] precommit test for ballot on Windows (PR #73920)

2023-12-03 Thread Sameer Sahasrabuddhe via cfe-commits

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


[clang] 0f8681b - [clang][AMDGPU] precommit test for ballot on Windows (#73920)

2023-12-03 Thread via cfe-commits

Author: Sameer Sahasrabuddhe
Date: 2023-12-04T10:43:16+05:30
New Revision: 0f8681b38e51e8a68894042e638eba681f7737f1

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

LOG: [clang][AMDGPU] precommit test for ballot on Windows (#73920)

The Clang declaration of the wave-64 builtin uses "UL" as the return
type, which is interpreted as a 32-bit unsigned integer on Windows. This
emits an incorrect LLVM declaration with i32 return type instead of i64.
The clang declaration needs to be fixed to use "WU" instead.

Added: 
clang/test/CodeGenHIP/ballot.cpp

Modified: 


Removed: 




diff  --git a/clang/test/CodeGenHIP/ballot.cpp 
b/clang/test/CodeGenHIP/ballot.cpp
new file mode 100644
index 0..6e1cbbdfc7af1
--- /dev/null
+++ b/clang/test/CodeGenHIP/ballot.cpp
@@ -0,0 +1,27 @@
+// REQUIRES: amdgpu-registered-target
+// XFAIL: *
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-pc-windows-msvc -target-cpu gfx900 -x hip -emit-llvm -fcuda-is-device -o 
- %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-pc-windows-msvc -target-cpu gfx900 -x hip -S -fcuda-is-device -o - %s | 
FileCheck %s --check-prefix=GFX9
+
+// Unlike OpenCL, HIP depends on the C++ interpration of "unsigned long", which
+// is 64 bits long on Linux and 32 bits long on Windows. The return type of the
+// ballot intrinsic needs to be a 64 bit integer on both platforms. This test
+// cross-compiles to Windows to confirm that the return type is indeed 64 bits
+// on Windows.
+
+// FIXME: The Clang declaration of the wave-64 builtin uses "UL" as the return
+// type, which is interpreted as a 32-bit unsigned integer on Windows. This
+// emits an incorrect LLVM declaration with i32 return type instead of i64. The
+// clang declaration needs to be fixed to use "WU" instead.
+
+// CHECK-LABEL: @_Z3fooi
+// CHECK: call i64 @llvm.amdgcn.ballot.i64
+
+// GFX9-LABEL: _Z3fooi:
+// GFX9: v_cmp_ne_u32_e64
+
+#define __device__ __attribute__((device))
+
+__device__ unsigned long long foo(int p) {
+  return __builtin_amdgcn_ballot_w64(p);
+}



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


[clang] [clang][RISCVVEmitter] Remove no-op ptr-to-ptr bitcast (NFC) (PR #74179)

2023-12-03 Thread Wang Pengcheng via cfe-commits


@@ -180,13 +180,10 @@ void emitCodeGenSwitchBody(const RVVIntrinsic *RVVI, 
raw_ostream ) {
 return;
   }
 
-  // Cast pointer operand of vector load intrinsic.
   for (const auto  : enumerate(RVVI->getInputTypes())) {

wangpc-pp wrote:

Why not remove this `for` totally?

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


[clang] [llvm] [SimplifyCFG] Not folding branch in loop header with constant iterations (PR #74268)

2023-12-03 Thread via cfe-commits

bcl5980 wrote:

We should add TTI check for the condition. I believe don't unroll on X86 is a 
correct decision.
Only like AMDGPU or NVPTX these GPU target with heavy stack cost backend target 
need this.

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


[clang] fix: C++ empty record with align lead to va_list out of sync (PR #72197)

2023-12-03 Thread via cfe-commits

hstk30-hw wrote:

I guess the `i8` is from 
https://github.com/ARM-software/abi-aa/blob/2a70c42d62e9c3eb5887fa50b71257f20daca6f9/cppabi64/cppabi64.rst#41summary-of-differences-from-and-additions-to-the-generic-c-abi

> The GC++ABI defines the way in which empty class types are laid out. For the 
> purposes of parameter passing in 
> [[AAPCS64](https://github.com/ARM-software/abi-aa/releases)], a parameter 
> whose type is an empty class shall be treated as if its type were an 
> aggregate with a single member of type unsigned byte.

and in 
[gcppabi](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#empty-parameters)

> Arguments of empty class types that are not non-trivial for the purposes of 
> calls are passed no differently from ordinary classes.

I guess I should fix in `va_arg` instead of `classifyArgumentType`, right? 
@rjmccall 

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


[clang] 239bcba - Fix [[clang::coro_wrapper]] documentation.

2023-12-03 Thread via cfe-commits

Author: Utkarsh Saxena
Date: 2023-12-04T04:11:05+01:00
New Revision: 239bcba65099558e2ec4f57d14ef6ce46b1ae74e

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

LOG: Fix [[clang::coro_wrapper]] documentation.

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f2c4eb51b443d..b45ec6bbb8d37 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7547,7 +7547,7 @@ For example,
   Task foo() { return increment(1); } // Error. foo is not a coroutine.
 
   // Fine for a coroutine wrapper to return a CRT.
-  Task [[clang::coro_wrapper]] foo() { return increment(1); }
+  [[clang::coro_wrapper]] Task foo() { return increment(1); }
 
   void bar() {
 // Invalid. This intantiates a function which returns a CRT but is not 
marked as



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


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/74199

>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH 1/2] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+Builder.defineMacro("__CCMP__");
+  if (HasCF)
+Builder.defineMacro("__CF__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1122,6 +1144,12 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("xsavec", true)
   .Case("xsaves", true)
   .Case("xsaveopt", true)
+  .Case("egpr", true)
+  .Case("push2pop2", true)
+  .Case("ppx", true)
+  .Case("ndd", true)
+  .Case("ccmp", true)
+  .Case("cf", true)
   .Default(false);
 }
 
@@ -1238,6 +1266,12 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("xsaves", HasXSAVES)
   .Case("xsaveopt", HasXSAVEOPT)
   .Case("fullbf16", HasFullBFloat16)
+  .Case("egpr", HasEGPR)
+  .Case("push2pop2", HasPush2Pop2)
+  .Case("ppx", HasPPX)
+  .Case("ndd", HasNDD)
+  .Case("ccmp", HasCCMP)
+  .Case("cf", HasCF)
   

[llvm] [clang] [SimplifyCFG] Not folding branch in loop header with constant iterations (PR #74268)

2023-12-03 Thread via cfe-commits

xiangzh1 wrote:

Seems the check fail "dr2xx.cpp Line 1297: conversion from 'T' to 'unsigned 
long long' is ambiguous" has no relation with this change.

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


[clang] [clang][dataflow] Add synthetic fields to `RecordStorageLocation` (PR #73860)

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

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


[clang] [clang][dataflow] Add synthetic fields to `RecordStorageLocation` (PR #73860)

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

https://github.com/Xazax-hun approved this pull request.

Overall, I love it! I have some comments on some features in the future, but 
those are probably not going to be addressed any time soon. First of all, I 
think in the future when we reason about the values of the pointers, synthetic 
fields might need to have offsets to be able to know things like 
`() != ()`. Offsets might also be a way to 
support unions, multiple synthetic fields starting at the same offset might 
express just that.

Another big item is properly supporting inheritance. Consider:
```
struct B { int a; };
struct D : /*virtual*/ B {};
struct E : /*virtual*/  B {};
struct F: D, E {
void m() {
int* l = &(D::a);
int* m = &(E::a);
}
};

``` 

Here, whether we have the same or different memory locations for `D::a` and 
`E::a` depends on whether we are doing virtual inheritance. This is something 
that should work both for regular fields and synthetic fields.

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


[clang] [clang][dataflow] Add synthetic fields to `RecordStorageLocation` (PR #73860)

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


@@ -367,3 +394,14 @@ clang::dataflow::FieldSet 
clang::dataflow::getObjectFields(QualType Type) {
   getFieldsFromClassHierarchy(Type, Fields);
   return Fields;
 }
+
+bool clang::dataflow::containsSameFields(
+const clang::dataflow::FieldSet ,
+const clang::dataflow::RecordStorageLocation::FieldToLoc ) {
+  if (Fields.size() != FieldLocs.size())
+return false;
+  for ([[maybe_unused]] auto [Field, Loc] : FieldLocs)
+if (!Fields.contains(cast_or_null(Field)))

Xazax-hun wrote:

What are the cases when we expect to see a null pointer here?

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


[clang] [clang][dataflow] Add synthetic fields to `RecordStorageLocation` (PR #73860)

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

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


[clang] [clang] assert fail when number of arguments in pack exceed implement… (PR #74220)

2023-12-03 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Please make sure before you commit that you update the description with more 
details. This is what will show up in the git log and we want to make sure that 
is detailed enough to allow folks to debug build issues etc without having to 
examine each commit in detail.

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


[clang] [clang] assert fail when number of arguments in pack exceed implement… (PR #74220)

2023-12-03 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

> Thanks for this PR! Emitting a diag in `TransformTemplateParmRefExpr` would 
> probably a better way to go about it. It's not clear to me that the assert` 
> is an improvement , and adding a diag would not be a lot more work. Would 
> that be something you would be willing to explore?

Agreed.

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


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-03 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

> > Can you add a release note?
> 
> Do you think this small diagnostic wording change is worth noting in relnotes?

Yes, we have a `Improvments to clang diagnostics` section. 

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


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-03 Thread Shafik Yaghmour via cfe-commits

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

LGTM

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


[clang] [flang] [flang] Add MSC_VER and target arch defines when targeting the MSVC ABI (PR #73250)

2023-12-03 Thread David Truby via cfe-commits

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


[clang] dff5bb9 - [flang] Add MSC_VER and target arch defines when targeting the MSVC ABI (#73250)

2023-12-03 Thread via cfe-commits

Author: David Truby
Date: 2023-12-04T02:20:03Z
New Revision: dff5bb92d47ef226319ba1b70a334785d7896de8

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

LOG: [flang] Add MSC_VER and target arch defines when targeting the MSVC ABI 
(#73250)

Fixes #67675

Added: 
flang/test/Driver/msvc-defines.f90

Modified: 
clang/lib/Driver/ToolChains/Flang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 98b337e60e4ff..c4cd26adb5a09 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -205,6 +205,30 @@ void Flang::AddAArch64TargetArgs(const ArgList ,
   }
 }
 
+static void addVSDefines(const ToolChain , const ArgList ,
+ ArgStringList ) {
+
+  unsigned ver = 0;
+  const VersionTuple vt = TC.computeMSVCVersion(nullptr, Args);
+  ver = vt.getMajor() * 1000 + vt.getMinor().value_or(0) * 10 +
+vt.getSubminor().value_or(0);
+  CmdArgs.push_back(Args.MakeArgString("-D_MSC_VER=" + Twine(ver / 10)));
+  CmdArgs.push_back(Args.MakeArgString("-D_MSC_FULL_VER=" + Twine(ver)));
+  CmdArgs.push_back(Args.MakeArgString("-D_WIN32"));
+
+  llvm::Triple triple = TC.getTriple();
+  if (triple.isAArch64()) {
+CmdArgs.push_back("-D_M_ARM64=1");
+  } else if (triple.isX86() && triple.isArch32Bit()) {
+CmdArgs.push_back("-D_M_IX86=600");
+  } else if (triple.isX86() && triple.isArch64Bit()) {
+CmdArgs.push_back("-D_M_X64=100");
+  } else {
+llvm_unreachable(
+"Flang on Windows only supports X86_32, X86_64 and AArch64");
+  }
+}
+
 static void processVSRuntimeLibrary(const ToolChain , const ArgList ,
 ArgStringList ) {
   assert(TC.getTriple().isKnownWindowsMSVCEnvironment() &&
@@ -334,6 +358,7 @@ void Flang::addTargetOptions(const ArgList ,
 
   if (Triple.isKnownWindowsMSVCEnvironment()) {
 processVSRuntimeLibrary(TC, Args, CmdArgs);
+addVSDefines(TC, Args, CmdArgs);
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.

diff  --git a/flang/test/Driver/msvc-defines.f90 
b/flang/test/Driver/msvc-defines.f90
new file mode 100644
index 0..a05df666ac09a
--- /dev/null
+++ b/flang/test/Driver/msvc-defines.f90
@@ -0,0 +1,10 @@
+! RUN: %flang -### --target=aarch64-windows-msvc %S/Inputs/hello.f90 -v 2>&1 | 
FileCheck %s --check-prefixes=MSVC,MSVC-AARCH64
+! RUN: %flang -### --target=i386-windows-msvc %S/Inputs/hello.f90 -v 2>&1 | 
FileCheck %s --check-prefixes=MSVC,MSVC-X86_32
+! RUN: %flang -### --target=x86_64-windows-msvc %S/Inputs/hello.f90 -v 2>&1 | 
FileCheck %s --check-prefixes=MSVC,MSVC-X86_64
+
+! MSVC: -fc1
+! MSVC-SAME: -D_MSC_VER={{[0-9]*}}
+! MSVC-SAME: -D_MSC_FULL_VER={{[0-9]*}}
+! MSVC-AARCH64-SAME: -D_M_ARM64=1
+! MSVC-X86_32-SAME: -D_M_IX86=600
+! MSVC-X86_64-SAME: -D_M_X64=100



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


[llvm] [clang] [SimplifyCFG] Not folding branch in loop header with constant iterations (PR #74268)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (xiangzh1)


Changes

Loop header with constant usually can be optimized in unroll, folding branch in 
such loop header at SimplifyCFG will break unroll optimization.
for example:
 Escape folding "I  ConstNum" with "Cond2" due to loops of constant  
iterations can be easily optimized (e.g unroll).
 for (int I = 0; I  ConstNum; ++I) { // ConstNum  1
  if (Cond2) {
 break;
   }
xxx loop body;
  }
 Folding these conditional branches may break loop optimizations.

---

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


3 Files Affected:

- (added) clang/test/CodeGenCUDA/simplify-cfg-unroll.cu (+364) 
- (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (+43) 
- (modified) llvm/test/Transforms/LoopVectorize/if-pred-non-void.ll (+46-45) 


``diff
diff --git a/clang/test/CodeGenCUDA/simplify-cfg-unroll.cu 
b/clang/test/CodeGenCUDA/simplify-cfg-unroll.cu
new file mode 100644
index 0..ecb421f9fc85c
--- /dev/null
+++ b/clang/test/CodeGenCUDA/simplify-cfg-unroll.cu
@@ -0,0 +1,364 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// REQUIRES: amdgpu-registered-target
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -O2 "-aux-triple" "x86_64-unknown-linux-gnu" "-triple" 
"amdgcn-amd-amdhsa" \
+// RUN:-fcuda-is-device "-aux-target-cpu" "x86-64" -emit-llvm -o - %s | 
FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// CHECK-LABEL: define dso_local void @_Z4funciPPiiS_(
+// CHECK-SAME: i32 noundef [[IDX:%.*]], ptr nocapture noundef readonly 
[[ARR:%.*]], i32 noundef [[DIMS:%.*]], ptr nocapture noundef [[OUT:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[DIMS]], 0
+// CHECK-NEXT:br i1 [[CMP1]], label [[CLEANUP:%.*]], label [[IF_END:%.*]]
+// CHECK:   if.end:
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[ARR]], align 8, !tbaa 
[[TBAA3:![0-9]+]]
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4, !tbaa 
[[TBAA7:![0-9]+]]
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[OUT]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ADD14:%.*]] = add nsw i32 [[TMP2]], [[TMP1]]
+// CHECK-NEXT:store i32 [[ADD14]], ptr [[OUT]], align 4, !tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_1:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 1
+// CHECK-NEXT:[[TMP3:%.*]] = load i32, ptr [[ARRAYIDX11_1]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX13_1:%.*]] = getelementptr inbounds i32, ptr 
[[OUT]], i64 1
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[ARRAYIDX13_1]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_1:%.*]] = add nsw i32 [[TMP4]], [[TMP3]]
+// CHECK-NEXT:store i32 [[ADD14_1]], ptr [[ARRAYIDX13_1]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_2:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 2
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, ptr [[ARRAYIDX11_2]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX13_2:%.*]] = getelementptr inbounds i32, ptr 
[[OUT]], i64 2
+// CHECK-NEXT:[[TMP6:%.*]] = load i32, ptr [[ARRAYIDX13_2]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_2:%.*]] = add nsw i32 [[TMP6]], [[TMP5]]
+// CHECK-NEXT:store i32 [[ADD14_2]], ptr [[ARRAYIDX13_2]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_3:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 3
+// CHECK-NEXT:[[TMP7:%.*]] = load i32, ptr [[ARRAYIDX11_3]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX13_3:%.*]] = getelementptr inbounds i32, ptr 
[[OUT]], i64 3
+// CHECK-NEXT:[[TMP8:%.*]] = load i32, ptr [[ARRAYIDX13_3]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_3:%.*]] = add nsw i32 [[TMP8]], [[TMP7]]
+// CHECK-NEXT:store i32 [[ADD14_3]], ptr [[ARRAYIDX13_3]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[CMP1_1:%.*]] = icmp eq i32 [[DIMS]], 1
+// CHECK-NEXT:br i1 [[CMP1_1]], label [[CLEANUP]], label [[IF_END_1:%.*]]
+// CHECK:   if.end.1:
+// CHECK-NEXT:[[ARRAYIDX_1:%.*]] = getelementptr inbounds ptr, ptr 
[[ARR]], i64 1
+// CHECK-NEXT:[[TMP9:%.*]] = load ptr, ptr [[ARRAYIDX_1]], align 8, !tbaa 
[[TBAA3]]
+// CHECK-NEXT:[[TMP10:%.*]] = load i32, ptr [[TMP9]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ADD14_129:%.*]] = add nsw i32 [[ADD14]], [[TMP10]]
+// CHECK-NEXT:store i32 [[ADD14_129]], ptr [[OUT]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_1_1:%.*]] = getelementptr inbounds i32, ptr 
[[TMP9]], i64 1
+// CHECK-NEXT:[[TMP11:%.*]] = load i32, ptr [[ARRAYIDX11_1_1]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_1_1:%.*]] = add nsw i32 [[ADD14_1]], [[TMP11]]
+// CHECK-NEXT:store i32 [[ADD14_1_1]], ptr [[ARRAYIDX13_1]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_2_1:%.*]] = getelementptr inbounds i32, ptr 
[[TMP9]], i64 2
+// CHECK-NEXT:  

[llvm] [clang] [SimplifyCFG] Not folding branch in loop header with constant iterations (PR #74268)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: None (xiangzh1)


Changes

Loop header with constant usually can be optimized in unroll, folding branch in 
such loop header at SimplifyCFG will break unroll optimization.
for example:
 Escape folding "I  ConstNum" with "Cond2" due to loops of constant  
iterations can be easily optimized (e.g unroll).
 for (int I = 0; I  ConstNum; ++I) { // ConstNum  1
  if (Cond2) {
 break;
   }
xxx loop body;
  }
 Folding these conditional branches may break loop optimizations.

---

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


3 Files Affected:

- (added) clang/test/CodeGenCUDA/simplify-cfg-unroll.cu (+364) 
- (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (+43) 
- (modified) llvm/test/Transforms/LoopVectorize/if-pred-non-void.ll (+46-45) 


``diff
diff --git a/clang/test/CodeGenCUDA/simplify-cfg-unroll.cu 
b/clang/test/CodeGenCUDA/simplify-cfg-unroll.cu
new file mode 100644
index 0..ecb421f9fc85c
--- /dev/null
+++ b/clang/test/CodeGenCUDA/simplify-cfg-unroll.cu
@@ -0,0 +1,364 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// REQUIRES: amdgpu-registered-target
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -O2 "-aux-triple" "x86_64-unknown-linux-gnu" "-triple" 
"amdgcn-amd-amdhsa" \
+// RUN:-fcuda-is-device "-aux-target-cpu" "x86-64" -emit-llvm -o - %s | 
FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// CHECK-LABEL: define dso_local void @_Z4funciPPiiS_(
+// CHECK-SAME: i32 noundef [[IDX:%.*]], ptr nocapture noundef readonly 
[[ARR:%.*]], i32 noundef [[DIMS:%.*]], ptr nocapture noundef [[OUT:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[DIMS]], 0
+// CHECK-NEXT:br i1 [[CMP1]], label [[CLEANUP:%.*]], label [[IF_END:%.*]]
+// CHECK:   if.end:
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[ARR]], align 8, !tbaa 
[[TBAA3:![0-9]+]]
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4, !tbaa 
[[TBAA7:![0-9]+]]
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[OUT]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ADD14:%.*]] = add nsw i32 [[TMP2]], [[TMP1]]
+// CHECK-NEXT:store i32 [[ADD14]], ptr [[OUT]], align 4, !tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_1:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 1
+// CHECK-NEXT:[[TMP3:%.*]] = load i32, ptr [[ARRAYIDX11_1]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX13_1:%.*]] = getelementptr inbounds i32, ptr 
[[OUT]], i64 1
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[ARRAYIDX13_1]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_1:%.*]] = add nsw i32 [[TMP4]], [[TMP3]]
+// CHECK-NEXT:store i32 [[ADD14_1]], ptr [[ARRAYIDX13_1]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_2:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 2
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, ptr [[ARRAYIDX11_2]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX13_2:%.*]] = getelementptr inbounds i32, ptr 
[[OUT]], i64 2
+// CHECK-NEXT:[[TMP6:%.*]] = load i32, ptr [[ARRAYIDX13_2]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_2:%.*]] = add nsw i32 [[TMP6]], [[TMP5]]
+// CHECK-NEXT:store i32 [[ADD14_2]], ptr [[ARRAYIDX13_2]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_3:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 3
+// CHECK-NEXT:[[TMP7:%.*]] = load i32, ptr [[ARRAYIDX11_3]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX13_3:%.*]] = getelementptr inbounds i32, ptr 
[[OUT]], i64 3
+// CHECK-NEXT:[[TMP8:%.*]] = load i32, ptr [[ARRAYIDX13_3]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_3:%.*]] = add nsw i32 [[TMP8]], [[TMP7]]
+// CHECK-NEXT:store i32 [[ADD14_3]], ptr [[ARRAYIDX13_3]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[CMP1_1:%.*]] = icmp eq i32 [[DIMS]], 1
+// CHECK-NEXT:br i1 [[CMP1_1]], label [[CLEANUP]], label [[IF_END_1:%.*]]
+// CHECK:   if.end.1:
+// CHECK-NEXT:[[ARRAYIDX_1:%.*]] = getelementptr inbounds ptr, ptr 
[[ARR]], i64 1
+// CHECK-NEXT:[[TMP9:%.*]] = load ptr, ptr [[ARRAYIDX_1]], align 8, !tbaa 
[[TBAA3]]
+// CHECK-NEXT:[[TMP10:%.*]] = load i32, ptr [[TMP9]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ADD14_129:%.*]] = add nsw i32 [[ADD14]], [[TMP10]]
+// CHECK-NEXT:store i32 [[ADD14_129]], ptr [[OUT]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_1_1:%.*]] = getelementptr inbounds i32, ptr 
[[TMP9]], i64 1
+// CHECK-NEXT:[[TMP11:%.*]] = load i32, ptr [[ARRAYIDX11_1_1]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_1_1:%.*]] = add nsw i32 [[ADD14_1]], [[TMP11]]
+// CHECK-NEXT:store i32 [[ADD14_1_1]], ptr [[ARRAYIDX13_1]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_2_1:%.*]] = getelementptr inbounds i32, ptr 
[[TMP9]], i64 2
+// 

[llvm] [clang] [SimplifyCFG] Not folding branch in loop header with constant iterations (PR #74268)

2023-12-03 Thread via cfe-commits

https://github.com/xiangzh1 created 
https://github.com/llvm/llvm-project/pull/74268

Loop header with constant usually can be optimized in unroll, folding branch in 
such loop header at SimplifyCFG will break unroll optimization.
for example:
 Escape folding "I < ConstNum" with "Cond2" due to loops of constant  
iterations can be easily optimized (e.g unroll).
 for (int I = 0; I < ConstNum; ++I) { // ConstNum > 1
  if (Cond2) {
 break;
   }
xxx loop body;
  }
 Folding these conditional branches may break loop optimizations.

>From 9f3ff6f8e542e33d9bc63f628b658e93ffe8a687 Mon Sep 17 00:00:00 2001
From: Zhang Xiang 
Date: Sun, 3 Dec 2023 09:40:19 +0800
Subject: [PATCH] [SimplifyCFG] Not folding branch in loop header with constant
 iterations Loop header with constant usually can be optimized in unroll,
 folding branch in such loop header at SimplifyCFG will break unroll
 optimization.

---
 clang/test/CodeGenCUDA/simplify-cfg-unroll.cu | 364 ++
 llvm/lib/Transforms/Utils/SimplifyCFG.cpp |  43 +++
 .../LoopVectorize/if-pred-non-void.ll |  91 ++---
 3 files changed, 453 insertions(+), 45 deletions(-)
 create mode 100644 clang/test/CodeGenCUDA/simplify-cfg-unroll.cu

diff --git a/clang/test/CodeGenCUDA/simplify-cfg-unroll.cu 
b/clang/test/CodeGenCUDA/simplify-cfg-unroll.cu
new file mode 100644
index 0..ecb421f9fc85c
--- /dev/null
+++ b/clang/test/CodeGenCUDA/simplify-cfg-unroll.cu
@@ -0,0 +1,364 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// REQUIRES: amdgpu-registered-target
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -O2 "-aux-triple" "x86_64-unknown-linux-gnu" "-triple" 
"amdgcn-amd-amdhsa" \
+// RUN:-fcuda-is-device "-aux-target-cpu" "x86-64" -emit-llvm -o - %s | 
FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// CHECK-LABEL: define dso_local void @_Z4funciPPiiS_(
+// CHECK-SAME: i32 noundef [[IDX:%.*]], ptr nocapture noundef readonly 
[[ARR:%.*]], i32 noundef [[DIMS:%.*]], ptr nocapture noundef [[OUT:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[DIMS]], 0
+// CHECK-NEXT:br i1 [[CMP1]], label [[CLEANUP:%.*]], label [[IF_END:%.*]]
+// CHECK:   if.end:
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[ARR]], align 8, !tbaa 
[[TBAA3:![0-9]+]]
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4, !tbaa 
[[TBAA7:![0-9]+]]
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[OUT]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ADD14:%.*]] = add nsw i32 [[TMP2]], [[TMP1]]
+// CHECK-NEXT:store i32 [[ADD14]], ptr [[OUT]], align 4, !tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_1:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 1
+// CHECK-NEXT:[[TMP3:%.*]] = load i32, ptr [[ARRAYIDX11_1]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX13_1:%.*]] = getelementptr inbounds i32, ptr 
[[OUT]], i64 1
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[ARRAYIDX13_1]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_1:%.*]] = add nsw i32 [[TMP4]], [[TMP3]]
+// CHECK-NEXT:store i32 [[ADD14_1]], ptr [[ARRAYIDX13_1]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_2:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 2
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, ptr [[ARRAYIDX11_2]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX13_2:%.*]] = getelementptr inbounds i32, ptr 
[[OUT]], i64 2
+// CHECK-NEXT:[[TMP6:%.*]] = load i32, ptr [[ARRAYIDX13_2]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_2:%.*]] = add nsw i32 [[TMP6]], [[TMP5]]
+// CHECK-NEXT:store i32 [[ADD14_2]], ptr [[ARRAYIDX13_2]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_3:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 3
+// CHECK-NEXT:[[TMP7:%.*]] = load i32, ptr [[ARRAYIDX11_3]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX13_3:%.*]] = getelementptr inbounds i32, ptr 
[[OUT]], i64 3
+// CHECK-NEXT:[[TMP8:%.*]] = load i32, ptr [[ARRAYIDX13_3]], align 4, 
!tbaa [[TBAA7]]
+// CHECK-NEXT:[[ADD14_3:%.*]] = add nsw i32 [[TMP8]], [[TMP7]]
+// CHECK-NEXT:store i32 [[ADD14_3]], ptr [[ARRAYIDX13_3]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[CMP1_1:%.*]] = icmp eq i32 [[DIMS]], 1
+// CHECK-NEXT:br i1 [[CMP1_1]], label [[CLEANUP]], label [[IF_END_1:%.*]]
+// CHECK:   if.end.1:
+// CHECK-NEXT:[[ARRAYIDX_1:%.*]] = getelementptr inbounds ptr, ptr 
[[ARR]], i64 1
+// CHECK-NEXT:[[TMP9:%.*]] = load ptr, ptr [[ARRAYIDX_1]], align 8, !tbaa 
[[TBAA3]]
+// CHECK-NEXT:[[TMP10:%.*]] = load i32, ptr [[TMP9]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ADD14_129:%.*]] = add nsw i32 [[ADD14]], [[TMP10]]
+// CHECK-NEXT:store i32 [[ADD14_129]], ptr [[OUT]], align 4, !tbaa 
[[TBAA7]]
+// CHECK-NEXT:[[ARRAYIDX11_1_1:%.*]] = getelementptr inbounds i32, ptr 
[[TMP9]], i64 1
+// CHECK-NEXT:[[TMP11:%.*]] = load i32, ptr 

[clang] [clang] Exclude non-template classes when checking if constraint refers to containing template arguments (PR #74265)

2023-12-03 Thread via cfe-commits

https://github.com/antangelo updated 
https://github.com/llvm/llvm-project/pull/74265

>From a8e841657b9816a78f6eb1520c8513454fe0008b Mon Sep 17 00:00:00 2001
From: Antonio Abbatangelo 
Date: Tue, 28 Nov 2023 21:19:13 -0500
Subject: [PATCH 1/2] [clang] Exclude non-template classes when checking if
 constraint refers to containing template arguments

---
 clang/docs/ReleaseNotes.rst |  3 +++
 clang/lib/Sema/SemaTemplate.cpp |  2 ++
 clang/test/SemaTemplate/GH71595.cpp | 34 +
 3 files changed, 39 insertions(+)
 create mode 100644 clang/test/SemaTemplate/GH71595.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7a948fd3fae5..852b908dd1594 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -651,6 +651,9 @@ Bug Fixes in This Version
 - Fixed false positive error emitted by clang when performing qualified name
   lookup and the current class instantiation has dependent bases.
   Fixes (`#13826 `_)
+- Fix a ``clang-17`` regression where a templated friend with constraints is 
not 
+  properly applied when its parameters reference an enclosing non-template 
class.
+  Fixes (`#71595 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 09bbf14d39af5..aec802b289a2d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1714,6 +1714,8 @@ class ConstraintRefersToContainingTemplateChecker
   // Friend, likely because it was referred to without its template arguments.
   void CheckIfContainingRecord(const CXXRecordDecl *CheckingRD) {
 CheckingRD = CheckingRD->getMostRecentDecl();
+if (!CheckingRD->isTemplated())
+  return;
 
 for (const DeclContext *DC = Friend->getLexicalDeclContext();
  DC && !DC->isFileContext(); DC = DC->getParent())
diff --git a/clang/test/SemaTemplate/GH71595.cpp 
b/clang/test/SemaTemplate/GH71595.cpp
new file mode 100644
index 0..7d34d1bf054e4
--- /dev/null
+++ b/clang/test/SemaTemplate/GH71595.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+template
+concept C = true;
+
+class non_temp {
+template T>
+friend void f();
+
+non_temp();
+};
+
+template T>
+void f() {
+auto v = non_temp();
+}
+
+template
+class temp {
+template T>
+friend void g();
+
+temp(); // expected-note {{implicitly declared private here}}
+};
+
+template> T>
+void g() {
+auto v = temp(); // expected-error {{calling a private constructor of 
class 'temp'}}
+}
+
+void h() {
+f();
+g(); // expected-note {{in instantiation of function template 
specialization 'g' requested here}}
+}

>From 7c27cd73781b64855b652ff18cd0fc3a0fb3dfac Mon Sep 17 00:00:00 2001
From: Antonio Abbatangelo 
Date: Sun, 3 Dec 2023 20:22:31 -0500
Subject: [PATCH 2/2] Fix trailing whitespace in release notes

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 852b908dd1594..b7ebd17051be4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -651,7 +651,7 @@ Bug Fixes in This Version
 - Fixed false positive error emitted by clang when performing qualified name
   lookup and the current class instantiation has dependent bases.
   Fixes (`#13826 `_)
-- Fix a ``clang-17`` regression where a templated friend with constraints is 
not 
+- Fix a ``clang-17`` regression where a templated friend with constraints is 
not
   properly applied when its parameters reference an enclosing non-template 
class.
   Fixes (`#71595 `_)
 

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


[clang] [clang] Exclude non-template classes when checking if constraint refers to containing template arguments (PR #74265)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (antangelo)


Changes

When checking if the constraint uses any enclosing template parameters for 
[temp.friend]p9, if a containing record is used as argument, we assume that the 
constraint depends on enclosing template parameters without checking if the 
record is templated. The reproducer from the bug is included as a test case.

I would appreciate if someone could double check my interpretation of the 
standard here as I'm not the most experienced with it.

Fixes #71595

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+2) 
- (added) clang/test/SemaTemplate/GH71595.cpp (+34) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7a948fd3fae5..852b908dd1594 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -651,6 +651,9 @@ Bug Fixes in This Version
 - Fixed false positive error emitted by clang when performing qualified name
   lookup and the current class instantiation has dependent bases.
   Fixes (`#13826 `_)
+- Fix a ``clang-17`` regression where a templated friend with constraints is 
not 
+  properly applied when its parameters reference an enclosing non-template 
class.
+  Fixes (`#71595 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 09bbf14d39af5..aec802b289a2d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1714,6 +1714,8 @@ class ConstraintRefersToContainingTemplateChecker
   // Friend, likely because it was referred to without its template arguments.
   void CheckIfContainingRecord(const CXXRecordDecl *CheckingRD) {
 CheckingRD = CheckingRD->getMostRecentDecl();
+if (!CheckingRD->isTemplated())
+  return;
 
 for (const DeclContext *DC = Friend->getLexicalDeclContext();
  DC && !DC->isFileContext(); DC = DC->getParent())
diff --git a/clang/test/SemaTemplate/GH71595.cpp 
b/clang/test/SemaTemplate/GH71595.cpp
new file mode 100644
index 0..7d34d1bf054e4
--- /dev/null
+++ b/clang/test/SemaTemplate/GH71595.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+template
+concept C = true;
+
+class non_temp {
+template T>
+friend void f();
+
+non_temp();
+};
+
+template T>
+void f() {
+auto v = non_temp();
+}
+
+template
+class temp {
+template T>
+friend void g();
+
+temp(); // expected-note {{implicitly declared private here}}
+};
+
+template> T>
+void g() {
+auto v = temp(); // expected-error {{calling a private constructor of 
class 'temp'}}
+}
+
+void h() {
+f();
+g(); // expected-note {{in instantiation of function template 
specialization 'g' requested here}}
+}

``




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


[clang] [clang] Exclude non-template classes when checking if constraint refers to containing template arguments (PR #74265)

2023-12-03 Thread via cfe-commits

https://github.com/antangelo created 
https://github.com/llvm/llvm-project/pull/74265

When checking if the constraint uses any enclosing template parameters for 
[temp.friend]p9, if a containing record is used as argument, we assume that the 
constraint depends on enclosing template parameters without checking if the 
record is templated. The reproducer from the bug is included as a test case.

I would appreciate if someone could double check my interpretation of the 
standard here as I'm not the most experienced with it.

Fixes #71595

>From a8e841657b9816a78f6eb1520c8513454fe0008b Mon Sep 17 00:00:00 2001
From: Antonio Abbatangelo 
Date: Tue, 28 Nov 2023 21:19:13 -0500
Subject: [PATCH] [clang] Exclude non-template classes when checking if
 constraint refers to containing template arguments

---
 clang/docs/ReleaseNotes.rst |  3 +++
 clang/lib/Sema/SemaTemplate.cpp |  2 ++
 clang/test/SemaTemplate/GH71595.cpp | 34 +
 3 files changed, 39 insertions(+)
 create mode 100644 clang/test/SemaTemplate/GH71595.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7a948fd3fae5..852b908dd1594 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -651,6 +651,9 @@ Bug Fixes in This Version
 - Fixed false positive error emitted by clang when performing qualified name
   lookup and the current class instantiation has dependent bases.
   Fixes (`#13826 `_)
+- Fix a ``clang-17`` regression where a templated friend with constraints is 
not 
+  properly applied when its parameters reference an enclosing non-template 
class.
+  Fixes (`#71595 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 09bbf14d39af5..aec802b289a2d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1714,6 +1714,8 @@ class ConstraintRefersToContainingTemplateChecker
   // Friend, likely because it was referred to without its template arguments.
   void CheckIfContainingRecord(const CXXRecordDecl *CheckingRD) {
 CheckingRD = CheckingRD->getMostRecentDecl();
+if (!CheckingRD->isTemplated())
+  return;
 
 for (const DeclContext *DC = Friend->getLexicalDeclContext();
  DC && !DC->isFileContext(); DC = DC->getParent())
diff --git a/clang/test/SemaTemplate/GH71595.cpp 
b/clang/test/SemaTemplate/GH71595.cpp
new file mode 100644
index 0..7d34d1bf054e4
--- /dev/null
+++ b/clang/test/SemaTemplate/GH71595.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+template
+concept C = true;
+
+class non_temp {
+template T>
+friend void f();
+
+non_temp();
+};
+
+template T>
+void f() {
+auto v = non_temp();
+}
+
+template
+class temp {
+template T>
+friend void g();
+
+temp(); // expected-note {{implicitly declared private here}}
+};
+
+template> T>
+void g() {
+auto v = temp(); // expected-error {{calling a private constructor of 
class 'temp'}}
+}
+
+void h() {
+f();
+g(); // expected-note {{in instantiation of function template 
specialization 'g' requested here}}
+}

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


[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-03 Thread Aaron Puchert via cfe-commits

aaronpuchert wrote:

In the end it probably boils down to how you view an enumeration type. Is it a 
type with the declared enumerators as inhabitants, or is it an integer type of 
some length with associated symbolic constants of that type? In other words, is 
an enumeration a "strong" type or a "weak" type?

The standard itself seems more in the "weak" camp. Yes, it does not allow 
integer values larger than what the largest enumeration value requires (if the 
underlying integer type isn't declared), but otherwise integer values that 
don't correspond to enumeration values can be cast to the enumeration type just 
fine. In [[dcl.enum]p8](https://eel.is/c++draft/enum#dcl.enum-8):

> [For an enumeration whose underlying type is not fixed,] the values of the 
> enumeration are the values representable by a hypothetical integer type with 
> minimal width _M_ such that all enumerators can be represented.

However, nothing prevents a developer from assuming a stricter model, where 
only the declared enumeration values are allowed and everything else is 
undefined behavior. (If not in terms of the language, then in terms of the 
program.) That is what we have done in the LLVM code base, and it's also the 
model that I personally prefer.

But it is probably legitimate to follow the weaker model implied by the 
standard and assume that enumerations can have non-enumerator values, which 
requires a default label, enforced by this warning.

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


[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-03 Thread Aaron Puchert via cfe-commits

aaronpuchert wrote:

> There is one clang-tidy check (bugprone-switch-missing-default-case) also for 
> this feature.

This excludes enumeration types though, while GCC `-Wswitch-default` warns on 
them as well. (Even if all enumeration values are covered.)

> whether switch statements should have a default is not something the industry 
> seem to agree on, so it would be a very opinionated warning.

Yes. Though I have to say, even though I'm squarely in the 
`-Wcovered-switch-default` camp (i.e. no `default` label in switches that cover 
all enumeration values), I think it's still valuable to have this warning 
because some style guides/policies demand a `default`, and it is very little 
effort on our side to maintain this.

I understand the policy against off-by-default warnings to avoid crowding the 
core compiler, but this is essentially just two lines of code, and if GCC has 
it we're not going out on a limb here. And since we already seem to support the 
flag for GCC compatibility, we might as well make it work if it's that easy.

> LLVM development heavily relies on `-Wswitch-enum`, for example.

I think we're using `-Wswitch`, as `-Wswitch-enum` requires to cover all 
enumeration values even if there is a default label. Our policy is: cover all 
enumeration values or have a `default`. This is "enforced" by `-Wswitch` in 
combination with `-Wcovered-switch-default`.

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


[clang] Thread safety analysis: Fix a bug in handling temporary constructors (PR #74020)

2023-12-03 Thread Aaron Puchert via cfe-commits


@@ -1718,6 +1720,13 @@ struct TestScopedLockable {
 MutexLock{}, a = 5;
   }
 
+  void temporary2(int x) {
+if (check(MutexLock{}) || x) {
+
+}

aaronpuchert wrote:

The `if` is probably not needed here, right? We could just write
```suggestion
check(MutexLock{}) || x;
```
and should have the same CFG artifact.

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


[clang] Thread safety analysis: Fix a bug in handling temporary constructors (PR #74020)

2023-12-03 Thread Aaron Puchert via cfe-commits


@@ -2392,6 +2397,8 @@ void 
ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext ) {
   for (const auto  : LocksReleased)
 ExpectedFunctionExitSet.removeLock(FactMan, Lock);
 
+  ConstructedObjectMapTy ConstructedObjects;

aaronpuchert wrote:

I wonder if we should put it into the `ThreadSafetyAnalyzer`, where we already 
have the similar `LocalVariableMap`. Then we don't need to pass it into 
`BuildLockset`, because that already has a pointer to the 
`ThreadSafetyAnalyzer`.

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


[clang] Thread safety analysis: Fix a bug in handling temporary constructors (PR #74020)

2023-12-03 Thread Aaron Puchert via cfe-commits

https://github.com/aaronpuchert commented:

I have some suggestions, but in principle this is absolutely right. Thanks for 
finding this and providing a fix!

>  The issue is that the map lives within a CFG block.

It didn't cross my mind to check how long `BuildLockset` lived, I always 
assumed it lived for the entire function. But you're right, it does not, and is 
therefore an unsuitable home for the map.

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


[clang] Thread safety analysis: Fix a bug in handling temporary constructors (PR #74020)

2023-12-03 Thread Aaron Puchert via cfe-commits


@@ -1718,6 +1720,13 @@ struct TestScopedLockable {
 MutexLock{}, a = 5;
   }
 
+  void temporary2(int x) {

aaronpuchert wrote:

I would suggest a speaking name for the test, like `temporary_cfg`.

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


[clang] Thread safety analysis: Fix a bug in handling temporary constructors (PR #74020)

2023-12-03 Thread Aaron Puchert via cfe-commits


@@ -1718,6 +1720,13 @@ struct TestScopedLockable {
 MutexLock{}, a = 5;
   }
 
+  void temporary2(int x) {
+if (check(MutexLock{}) || x) {
+
+}
+check(MutexLock{});

aaronpuchert wrote:

The `check` here doesn't do anything, right?

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


[clang] Thread safety analysis: Fix a bug in handling temporary constructors (PR #74020)

2023-12-03 Thread Aaron Puchert via cfe-commits

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


[clang] Thread safety analysis: Fix a bug in handling temporary constructors (PR #74020)

2023-12-03 Thread Aaron Puchert via cfe-commits


@@ -1544,7 +1544,10 @@ class BuildLockset : public 
ConstStmtVisitor {
   // The fact set for the function on exit.
   const FactSet 
   /// Maps constructed objects to `this` placeholder prior to initialization.
-  llvm::SmallDenseMap ConstructedObjects;
+  /// The map lives longer than this builder so this is a reference to an
+  /// existing one. The map lives so long as the CFG while this builder is for
+  /// one CFG block.

aaronpuchert wrote:

It's probably sufficient to explain this in the commit message.

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


[clang] [clang-format] Remove duplicates in @property using std::set (PR #74235)

2023-12-03 Thread Jared Grubb via cfe-commits

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


[clang] [clang-format] Remove duplicates in @property using std::set (PR #74235)

2023-12-03 Thread Jared Grubb via cfe-commits


@@ -171,18 +171,18 @@ TEST_F(ObjCPropertyAttributeOrderFixerTest, 
HandlesDuplicatedAttributes) {
   Style.ObjCPropertyAttributeOrder = {"a", "b", "c"};
 
   // Just a dup and nothing else.
-  verifyFormat("@property(a, a) int p;", Style);
+  verifyFormat("@property(a) int p;", "@property(a, a) int p;", Style);
 
   // A dup and something else.
-  verifyFormat("@property(a, a, b) int p;", "@property(a, b, a) int p;", 
Style);
+  verifyFormat("@property(a, b) int p;", "@property(a, b, a) int p;", Style);
 
   // Duplicates using `=`: stable-sort irrespective of their value.

jaredgrubb wrote:

Nit: the comment about stable-sort isn't really applicable now.

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


[clang] [clang-format] Remove duplicates in @property using std::set (PR #74235)

2023-12-03 Thread Jared Grubb via cfe-commits

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

Looks good to me!

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


[clang] Fix documentation on PGO/coverage related options. (PR #73845)

2023-12-03 Thread David Li via cfe-commits

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


[clang] 7882f38 - Fix documentation on PGO/coverage related options. (#73845)

2023-12-03 Thread via cfe-commits

Author: David Li
Date: 2023-12-03T14:10:57-08:00
New Revision: 7882f380a234a8c0260b79290406967c851a0df2

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

LOG: Fix documentation on PGO/coverage related options. (#73845)

Update the user manual to provide guidance on the usage for different
flavors of instrumentations.

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 2e658557b0e31..9d64195ee338e 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2348,9 +2348,10 @@ 
diff erences between the two:
 
 1. Profile data generated with one cannot be used by the other, and there is no
conversion tool that can convert one to the other. So, a profile generated
-   via ``-fprofile-instr-generate`` must be used with ``-fprofile-instr-use``.
-   Similarly, sampling profiles generated by external profilers must be
-   converted and used with ``-fprofile-sample-use``.
+   via ``-fprofile-generate`` or ``-fprofile-instr-generate`` must be used with
+   ``-fprofile-use`` or ``-fprofile-instr-use``.  Similarly, sampling profiles
+   generated by external profilers must be converted and used with 
``-fprofile-sample-use``
+   or ``-fauto-profile``.
 
 2. Instrumentation profile data can be used for code coverage analysis and
optimization.
@@ -2598,6 +2599,8 @@ Of those, 31,977 were spent inside the body of ``bar``. 
The last line
 of the profile (``2: 0``) corresponds to line 2 inside ``main``. No
 samples were collected there.
 
+.. _prof_instr:
+
 Profiling with Instrumentation
 ^^
 
@@ -2607,11 +2610,25 @@ overhead during the profiling, but it provides more 
detailed results than a
 sampling profiler. It also provides reproducible results, at least to the
 extent that the code behaves consistently across runs.
 
+Clang supports two types of instrumentation: frontend-based and IR-based.
+Frontend-based instrumentation can be enabled with the option 
``-fprofile-instr-generate``,
+and IR-based instrumentation can be enabled with the option 
``-fprofile-generate``.
+For best performance with PGO, IR-based instrumentation should be used. It has
+the benefits of lower instrumentation overhead, smaller raw profile size, and
+better runtime performance. Frontend-based instrumentation, on the other hand,
+has better source correlation, so it should be used with source line-based
+coverage testing.
+
+The flag ``-fcs-profile-generate`` also instruments programs using the same
+instrumentation method as ``-fprofile-generate``. However, it performs a
+post-inline late instrumentation and can produce context-sensitive profiles.
+
+
 Here are the steps for using profile guided optimization with
 instrumentation:
 
 1. Build an instrumented version of the code by compiling and linking with the
-   ``-fprofile-instr-generate`` option.
+   ``-fprofile-generate`` or ``-fprofile-instr-generate`` option.
 
.. code-block:: console
 
@@ -2674,8 +2691,8 @@ instrumentation:
Note that this step is necessary even when there is only one "raw" profile,
since the merge operation also changes the file format.
 
-4. Build the code again using the ``-fprofile-instr-use`` option to specify the
-   collected profile data.
+4. Build the code again using the ``-fprofile-use`` or ``-fprofile-instr-use``
+   option to specify the collected profile data.
 
.. code-block:: console
 
@@ -2685,13 +2702,10 @@ instrumentation:
profile. As you make changes to your code, clang may no longer be able to
use the profile data. It will warn you when this happens.
 
-Profile generation using an alternative instrumentation method can be
-controlled by the GCC-compatible flags ``-fprofile-generate`` and
-``-fprofile-use``. Although these flags are semantically equivalent to
-their GCC counterparts, they *do not* handle GCC-compatible profiles.
-They are only meant to implement GCC's semantics with respect to
-profile creation and use. Flag ``-fcs-profile-generate`` also instruments
-programs using the same instrumentation method as ``-fprofile-generate``.
+Note that ``-fprofile-use`` option is semantically equivalent to
+its GCC counterpart, it *does not* handle profile formats produced by GCC.
+Both ``-fprofile-use`` and ``-fprofile-instr-use`` accept profiles in the
+indexed format, regardeless whether it is produced by frontend or the IR pass.
 
 .. option:: -fprofile-generate[=]
 
@@ -4401,13 +4415,21 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   Instrument only functions from files where names 
don't match all the regexes separated by a semi-colon
   -fprofile-filter-files=
   Instrument 

[libc] [llvm] [clang] [libcxx] [compiler-rt] [flang] Ensure `lli --force-interpreter` disables the OrcJIT too (PR #73717)

2023-12-03 Thread via cfe-commits

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

LGTM too. Thanks @allight!

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


[clang] [clang-format] Add "three dot" diff option to git-clang-format (PR #74230)

2023-12-03 Thread Aiden Grossman via cfe-commits


@@ -153,7 +157,10 @@ def main():
   else:
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
-  changed_lines = compute_diff_and_extract_lines(commits, files, opts.staged)
+  changed_lines = compute_diff_and_extract_lines(commits,

boomanaiden154 wrote:

Fixed. Thanks for the suggestion!

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


[clang] [clang-format] Add "three dot" diff option to git-clang-format (PR #74230)

2023-12-03 Thread Aiden Grossman via cfe-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/74230

>From ae4097b53b90e31802be0be5c8a81fb74c81efc9 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 2 Dec 2023 23:46:58 -0800
Subject: [PATCH 1/2] [clang-format] Add "three dot" diff option to
 git-clang-format

This patch adds in the ability to do a "three dot" git-clang-format
between two commits. This looks at the diff between the second commit
and the common merge base rather than comparing at the point of the
specified commits. This is needed to improve the reliability of the LLVM
code formatting CI action which currently breaks in some cases where
files have been modified in the upstream tree and when the person
created their branch, leaving phantom formatting diffs that weren't
touched by the PR author.

Part of a fix for #73873
---
 clang/tools/clang-format/git-clang-format | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 6e827e17b4ee2..4fe4671482e3f 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -132,6 +132,10 @@ def main():
  help='passed to clang-format'),
   p.add_argument('-v', '--verbose', action='count', default=0,
  help='print extra information')
+  p.add_argument('--diff_from_common_commit', action='store_true',
+ help=('diff from the last common commit for commits in '
+  'separate branches rather than the exact point of the '
+  'commits'))
   # We gather all the remaining positional arguments into 'args' since we need
   # to use some heuristics to determine whether or not  was present.
   # However, to print pretty messages, we make use of metavar and help.
@@ -154,7 +158,10 @@ def main():
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
   opts.binary=os.path.abspath(opts.binary)
-  changed_lines = compute_diff_and_extract_lines(commits, files, opts.staged)
+  changed_lines = compute_diff_and_extract_lines(commits,
+ files,
+ opts.staged,
+ opts.diff_from_common_commit)
   if opts.verbose >= 1:
 ignored_files = set(changed_lines)
   filter_by_extension(changed_lines, opts.extensions.lower().split(','))
@@ -302,9 +309,9 @@ def get_object_type(value):
   return convert_string(stdout.strip())
 
 
-def compute_diff_and_extract_lines(commits, files, staged):
+def compute_diff_and_extract_lines(commits, files, staged, diff_common_commit):
   """Calls compute_diff() followed by extract_lines()."""
-  diff_process = compute_diff(commits, files, staged)
+  diff_process = compute_diff(commits, files, staged, diff_common_commit)
   changed_lines = extract_lines(diff_process.stdout)
   diff_process.stdout.close()
   diff_process.wait()
@@ -314,7 +321,7 @@ def compute_diff_and_extract_lines(commits, files, staged):
   return changed_lines
 
 
-def compute_diff(commits, files, staged):
+def compute_diff(commits, files, staged, diff_common_commit):
   """Return a subprocess object producing the diff from `commits`.
 
   The return value's `stdin` file object will produce a patch with the
@@ -328,6 +335,10 @@ def compute_diff(commits, files, staged):
 git_tool = 'diff-tree'
   elif staged:
 extra_args += ['--cached']
+
+  if len(commits) > 1 and diff_common_commit:
+commits = [f'{commits[0]}...{commits[1]}']
+
   cmd = ['git', git_tool, '-p', '-U0'] + extra_args + commits + ['--']
   cmd.extend(files)
   p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

>From 4584ebc58337f04290a5c753f585426c8c6f739f Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sun, 3 Dec 2023 13:08:16 -0800
Subject: [PATCH 2/2] Add early exit when flag is specified with invalid
 parameters

---
 clang/tools/clang-format/git-clang-format | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 4fe4671482e3f..51ae8739bee0e 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -157,6 +157,8 @@ def main():
   else:
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
+  if len(commits) < 2 and opts.diff_from_common_commit:
+die('--diff_from_common_commit is only allowed when two commits are given')
   opts.binary=os.path.abspath(opts.binary)
   changed_lines = compute_diff_and_extract_lines(commits,
  files,

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


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

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


@@ -128,169 +128,169 @@ void foo(){
 
 const auto Actually2 = 2;
 bar::sqrt(Actually2);
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::sqrt2' 
math constant [modernize-use-std-numbers]
 // CHECK-FIXES: std::numbers::sqrt2;
 
 exp(1);
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::e' math 
constant [modernize-use-std-numbers]
 // CHECK-FIXES: std::numbers::e;
 
 exp(One);
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::e' math 
constant [modernize-use-std-numbers]
 // CHECK-FIXES: std::numbers::e;
 
 exp(1.01);
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::e' math 
constant [modernize-use-std-numbers]
 // CHECK-FIXES: std::numbers::e;
 
 log2(exp(1));
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
-// CHECK-MESSAGES: :[[@LINE-2]]:10: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log2e' 
math constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-2]]:10: warning: prefer 'std::numbers::e' math 
constant [modernize-use-std-numbers]
 // CHECK-FIXES: std::numbers::log2e;
 
 log2(Euler);
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log2e' 
math constant [modernize-use-std-numbers]
 // CHECK-FIXES: std::numbers::log2e;
 
 log2(bar::e);
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log2e' 
math constant [modernize-use-std-numbers]
 // CHECK-FIXES: std::numbers::log2e;
 
 log2(Euler5);
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log2e' 
math constant [modernize-use-std-numbers]
 // CHECK-FIXES: std::numbers::log2e;
 
 log2(Euler6);
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 
'std::numbers::log2e_v' math constant [modernize-use-std-numbers]
 // CHECK-FIXES: std::numbers::log2e_v;
 
 log2(NotEuler7);
 
 auto log2e = 1.4426950;
-// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: prefer 'std::numbers::log2e' 
math constant [modernize-use-std-numbers]
 // CHECK-FIXES: auto log2e = std::numbers::log2e;
 
 floatSink(log2(Euler));
-// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 
'std::numbers::log2e_v' math constant [modernize-use-std-numbers]
 // CHECK-FIXES: floatSink(std::numbers::log2e_v);
 
 floatSink(static_cast(log2(Euler)));
-// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
-// CHECK-MESSAGES: :[[@LINE-2]]:34: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 
'std::numbers::log2e_v' math constant [modernize-use-std-numbers]
 // CHECK-FIXES: floatSink(std::numbers::log2e_v);
 
 floatSink(1.4426950);
-// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 
'std::numbers::log2e_v' math constant [modernize-use-std-numbers]
 // CHECK-FIXES: floatSink(std::numbers::log2e_v);
 
 floatSink(static_cast(1.4426950));
-// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
-// CHECK-MESSAGES: :[[@LINE-2]]:34: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 
'std::numbers::log2e_v' math constant [modernize-use-std-numbers]
 // CHECK-FIXES: floatSink(std::numbers::log2e_v);
 
 floatSink(log2(static_cast(Euler)));
-// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math 
constant 

[clang] [clang-format] Add "three dot" diff option to git-clang-format (PR #74230)

2023-12-03 Thread Aiden Grossman via cfe-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/74230

>From ae4097b53b90e31802be0be5c8a81fb74c81efc9 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 2 Dec 2023 23:46:58 -0800
Subject: [PATCH] [clang-format] Add "three dot" diff option to
 git-clang-format

This patch adds in the ability to do a "three dot" git-clang-format
between two commits. This looks at the diff between the second commit
and the common merge base rather than comparing at the point of the
specified commits. This is needed to improve the reliability of the LLVM
code formatting CI action which currently breaks in some cases where
files have been modified in the upstream tree and when the person
created their branch, leaving phantom formatting diffs that weren't
touched by the PR author.

Part of a fix for #73873
---
 clang/tools/clang-format/git-clang-format | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 6e827e17b4ee2..4fe4671482e3f 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -132,6 +132,10 @@ def main():
  help='passed to clang-format'),
   p.add_argument('-v', '--verbose', action='count', default=0,
  help='print extra information')
+  p.add_argument('--diff_from_common_commit', action='store_true',
+ help=('diff from the last common commit for commits in '
+  'separate branches rather than the exact point of the '
+  'commits'))
   # We gather all the remaining positional arguments into 'args' since we need
   # to use some heuristics to determine whether or not  was present.
   # However, to print pretty messages, we make use of metavar and help.
@@ -154,7 +158,10 @@ def main():
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
   opts.binary=os.path.abspath(opts.binary)
-  changed_lines = compute_diff_and_extract_lines(commits, files, opts.staged)
+  changed_lines = compute_diff_and_extract_lines(commits,
+ files,
+ opts.staged,
+ opts.diff_from_common_commit)
   if opts.verbose >= 1:
 ignored_files = set(changed_lines)
   filter_by_extension(changed_lines, opts.extensions.lower().split(','))
@@ -302,9 +309,9 @@ def get_object_type(value):
   return convert_string(stdout.strip())
 
 
-def compute_diff_and_extract_lines(commits, files, staged):
+def compute_diff_and_extract_lines(commits, files, staged, diff_common_commit):
   """Calls compute_diff() followed by extract_lines()."""
-  diff_process = compute_diff(commits, files, staged)
+  diff_process = compute_diff(commits, files, staged, diff_common_commit)
   changed_lines = extract_lines(diff_process.stdout)
   diff_process.stdout.close()
   diff_process.wait()
@@ -314,7 +321,7 @@ def compute_diff_and_extract_lines(commits, files, staged):
   return changed_lines
 
 
-def compute_diff(commits, files, staged):
+def compute_diff(commits, files, staged, diff_common_commit):
   """Return a subprocess object producing the diff from `commits`.
 
   The return value's `stdin` file object will produce a patch with the
@@ -328,6 +335,10 @@ def compute_diff(commits, files, staged):
 git_tool = 'diff-tree'
   elif staged:
 extra_args += ['--cached']
+
+  if len(commits) > 1 and diff_common_commit:
+commits = [f'{commits[0]}...{commits[1]}']
+
   cmd = ['git', git_tool, '-p', '-U0'] + extra_args + commits + ['--']
   cmd.extend(files)
   p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

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


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

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

5chmidti wrote:

It looks like GitHub decided to not list all new commits in the conversation 
view... there are a few more in the commits tab.
The newly pushed changes start at commit [refactor from using transformer to a 
normal 
check](https://github.com/llvm/llvm-project/pull/66583/commits/b1adc10d5a0b1456725979a1f480a517b37b6b2f).

The reason I found the issue I have created is what I had to change/remove in 
this commit:
[fix literal in template problem in exchange for not resolving implicit 
casts](https://github.com/llvm/llvm-project/pull/66583/commits/01d6b2e4e01e06e894710756ee83c668995bafbb)
I wanted the replacements to resolve implicit casts, like they do for explicit 
casts currently. The test shows the (IMO) degraded quality of the replacements.
After my findings/comment in that issue, I decided to push my changes this way 
to maybe move forward with this check and leave the implicit cast matching for 
another pr in the future. What do you think?

> Looks like having this check implemented as an multiple matchers isn't a good 
> idea, simply because we pickup first one that match instead a nearest one. 
> This leads to bugs when dealing with proper values.

There is a single matcher that matches literals and formulas. Formulas are 
applied as soon as a matched pattern is found. All matched literals are 
collected and sorted, if no formula was matched and the literal that differs 
the least from its constant is selected. 

> In ideal conditions something like x* 3.14 should be even detected as PI.

and

> also this precision 0.001 should be put into configuration option.

This is now configurable with the config value `DiffThreshold`. The default 
value is `0.001`, like it was before. Should this default be lower to detect 
your `3.14` example?

> Also warning message should already say what from std::numbers should be used 
> and how far are current and proposed values from them self.

The messages now follow the following format:

- `prefer 'std::numbers::pi' to this literal, differs by '2.34e-2'` (using 
scientific notation to be more compact than printing `0.123456789`)
- `prefer 'std::numbers::pi_v' to this formula` (the message uses the 
replacement code from the fix-it hint)
- `prefer 'std::numbers::pi' to this macro, differs by '2.34e-2'` (if we are 
replacing a macro that is just a literal)
- `prefer 'std::numbers::inv_sqrt3' to this macro` (for things like `#define 
INV_SQRT3 1 / bar::sqrt(3)`)

So the messages include what kind of symbol/code is being replaced, the 
inserted code, and the difference to the inserted value if the replaced code is 
a literal or a macro that is a literal. The difference that is being printed is 
the absolute difference. Does the sign matter?

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


[flang] [clang] [flang] (Re-)Enable alias tags pass by default (PR #74250)

2023-12-03 Thread Tom Eccles via cfe-commits

tblah wrote:

@banach-space once this is in, I'll remove `-f[no-]alias-analysis` in a 
separate patch, as it didn't turn out to be as useful for debugging as I 
expected (the `-mllvm` option is more specific), and as you mentioned - these 
arguments are non-standard.

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


[flang] [clang] [flang] (Re-)Enable alias tags pass by default (PR #74250)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Tom Eccles (tblah)


Changes

Enable by default for optimization levels higher than 0 (same behavior as 
clang).

For simplicity, only forward the flag to the frontend driver when it 
contradicts what is implied by the optimization level.

This was first landed in
https://github.com/llvm/llvm-project/pull/73111 but was later reverted due to a 
performance regression. That regression was fixed by 
https://github.com/llvm/llvm-project/pull/74065.

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


8 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+20) 
- (modified) flang/include/flang/Tools/CLOptions.inc (+3-3) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+6-4) 
- (modified) flang/test/Driver/falias-analysis.f90 (+15-1) 
- (modified) flang/test/Driver/mlir-pass-pipeline.f90 (+2) 
- (modified) flang/test/Driver/optimization-remark.f90 (+9-13) 
- (modified) flang/test/Fir/basic-program.fir (+4) 
- (modified) flang/tools/tco/tco.cpp (+1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 98b337e60e4ff..0319f1a117111 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -143,6 +143,26 @@ void Flang::addCodegenOptions(const ArgList ,
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
 
+  Arg *aliasAnalysis = Args.getLastArg(options::OPT_falias_analysis,
+   options::OPT_fno_alias_analysis);
+  // only pass on the argument if it does not match that implied by the
+  // optimization level: so if optimization is requested, only forward
+  // -fno-alias-analysis. If optimization is not requested, only forward
+  // -falias-analysis.
+  Arg *optLevel =
+  Args.getLastArg(options::OPT_Ofast, options::OPT_O, options::OPT_O4);
+  if (aliasAnalysis) {
+bool faliasAnalysis =
+aliasAnalysis->getOption().matches(options::OPT_falias_analysis);
+if (optLevel && !faliasAnalysis) {
+  CmdArgs.push_back("-fno-alias-analysis");
+} else {
+  if (faliasAnalysis)
+// requested alias analysis but no optimization enabled
+CmdArgs.push_back("-falias-analysis");
+}
+  }
+
   Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
 options::OPT_flang_deprecated_no_hlfir,
 options::OPT_flang_experimental_polymorphism,
diff --git a/flang/include/flang/Tools/CLOptions.inc 
b/flang/include/flang/Tools/CLOptions.inc
index c452c023b4a80..d3e4dc6cd4a24 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -158,10 +158,10 @@ inline void addDebugFoundationPass(mlir::PassManager ) 
{
 }
 
 inline void addFIRToLLVMPass(
-mlir::PassManager , llvm::OptimizationLevel optLevel = defaultOptLevel) 
{
+mlir::PassManager , const MLIRToLLVMPassPipelineConfig ) {
   fir::FIRToLLVMPassOptions options;
   options.ignoreMissingTypeDescriptors = ignoreMissingTypeDescriptors;
-  options.applyTBAA = optLevel.isOptimizingForSpeed();
+  options.applyTBAA = config.AliasAnalysis;
   options.forceUnifiedTBAATree = useOldAliasTags;
   addPassConditionally(pm, disableFirToLlvmIr,
   [&]() { return fir::createFIRToLLVMPass(options); });
@@ -311,7 +311,7 @@ inline void createDefaultFIRCodeGenPassPipeline(
   if (config.VScaleMin != 0)
 pm.addPass(fir::createVScaleAttrPass({config.VScaleMin, 
config.VScaleMax}));
 
-  fir::addFIRToLLVMPass(pm, config.OptLevel);
+  fir::addFIRToLLVMPass(pm, config);
 }
 
 /// Create a pass pipeline for lowering from MLIR to LLVM IR
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index e7730d50dc1bd..ec04727fb2641 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -242,10 +242,12 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions ,
clang::driver::options::OPT_fno_loop_versioning, false))
 opts.LoopVersioning = 1;
 
-  opts.AliasAnalysis =
-  args.hasFlag(clang::driver::options::OPT_falias_analysis,
-   clang::driver::options::OPT_fno_alias_analysis,
-   /*default=*/false);
+  opts.AliasAnalysis = opts.OptimizationLevel > 0;
+  if (auto *arg =
+  args.getLastArg(clang::driver::options::OPT_falias_analysis,
+  clang::driver::options::OPT_fno_alias_analysis))
+opts.AliasAnalysis =
+arg->getOption().matches(clang::driver::options::OPT_falias_analysis);
 
   for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
 opts.LLVMPassPlugins.push_back(a->getValue());
diff --git a/flang/test/Driver/falias-analysis.f90 
b/flang/test/Driver/falias-analysis.f90
index f2c5dbde6d2c8..3bd389c33dbc5 100644
--- a/flang/test/Driver/falias-analysis.f90

[clang] [flang] [flang] (Re-)Enable alias tags pass by default (PR #74250)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Tom Eccles (tblah)


Changes

Enable by default for optimization levels higher than 0 (same behavior as 
clang).

For simplicity, only forward the flag to the frontend driver when it 
contradicts what is implied by the optimization level.

This was first landed in
https://github.com/llvm/llvm-project/pull/73111 but was later reverted due to a 
performance regression. That regression was fixed by 
https://github.com/llvm/llvm-project/pull/74065.

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


8 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+20) 
- (modified) flang/include/flang/Tools/CLOptions.inc (+3-3) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+6-4) 
- (modified) flang/test/Driver/falias-analysis.f90 (+15-1) 
- (modified) flang/test/Driver/mlir-pass-pipeline.f90 (+2) 
- (modified) flang/test/Driver/optimization-remark.f90 (+9-13) 
- (modified) flang/test/Fir/basic-program.fir (+4) 
- (modified) flang/tools/tco/tco.cpp (+1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 98b337e60e4ff..0319f1a117111 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -143,6 +143,26 @@ void Flang::addCodegenOptions(const ArgList ,
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
 
+  Arg *aliasAnalysis = Args.getLastArg(options::OPT_falias_analysis,
+   options::OPT_fno_alias_analysis);
+  // only pass on the argument if it does not match that implied by the
+  // optimization level: so if optimization is requested, only forward
+  // -fno-alias-analysis. If optimization is not requested, only forward
+  // -falias-analysis.
+  Arg *optLevel =
+  Args.getLastArg(options::OPT_Ofast, options::OPT_O, options::OPT_O4);
+  if (aliasAnalysis) {
+bool faliasAnalysis =
+aliasAnalysis->getOption().matches(options::OPT_falias_analysis);
+if (optLevel && !faliasAnalysis) {
+  CmdArgs.push_back("-fno-alias-analysis");
+} else {
+  if (faliasAnalysis)
+// requested alias analysis but no optimization enabled
+CmdArgs.push_back("-falias-analysis");
+}
+  }
+
   Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
 options::OPT_flang_deprecated_no_hlfir,
 options::OPT_flang_experimental_polymorphism,
diff --git a/flang/include/flang/Tools/CLOptions.inc 
b/flang/include/flang/Tools/CLOptions.inc
index c452c023b4a80..d3e4dc6cd4a24 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -158,10 +158,10 @@ inline void addDebugFoundationPass(mlir::PassManager ) 
{
 }
 
 inline void addFIRToLLVMPass(
-mlir::PassManager , llvm::OptimizationLevel optLevel = defaultOptLevel) 
{
+mlir::PassManager , const MLIRToLLVMPassPipelineConfig ) {
   fir::FIRToLLVMPassOptions options;
   options.ignoreMissingTypeDescriptors = ignoreMissingTypeDescriptors;
-  options.applyTBAA = optLevel.isOptimizingForSpeed();
+  options.applyTBAA = config.AliasAnalysis;
   options.forceUnifiedTBAATree = useOldAliasTags;
   addPassConditionally(pm, disableFirToLlvmIr,
   [&]() { return fir::createFIRToLLVMPass(options); });
@@ -311,7 +311,7 @@ inline void createDefaultFIRCodeGenPassPipeline(
   if (config.VScaleMin != 0)
 pm.addPass(fir::createVScaleAttrPass({config.VScaleMin, 
config.VScaleMax}));
 
-  fir::addFIRToLLVMPass(pm, config.OptLevel);
+  fir::addFIRToLLVMPass(pm, config);
 }
 
 /// Create a pass pipeline for lowering from MLIR to LLVM IR
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index e7730d50dc1bd..ec04727fb2641 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -242,10 +242,12 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions ,
clang::driver::options::OPT_fno_loop_versioning, false))
 opts.LoopVersioning = 1;
 
-  opts.AliasAnalysis =
-  args.hasFlag(clang::driver::options::OPT_falias_analysis,
-   clang::driver::options::OPT_fno_alias_analysis,
-   /*default=*/false);
+  opts.AliasAnalysis = opts.OptimizationLevel > 0;
+  if (auto *arg =
+  args.getLastArg(clang::driver::options::OPT_falias_analysis,
+  clang::driver::options::OPT_fno_alias_analysis))
+opts.AliasAnalysis =
+arg->getOption().matches(clang::driver::options::OPT_falias_analysis);
 
   for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
 opts.LLVMPassPlugins.push_back(a->getValue());
diff --git a/flang/test/Driver/falias-analysis.f90 
b/flang/test/Driver/falias-analysis.f90
index f2c5dbde6d2c8..3bd389c33dbc5 100644
--- a/flang/test/Driver/falias-analysis.f90
+++ 

[flang] [clang] [flang] (Re-)Enable alias tags pass by default (PR #74250)

2023-12-03 Thread Tom Eccles via cfe-commits

https://github.com/tblah created https://github.com/llvm/llvm-project/pull/74250

Enable by default for optimization levels higher than 0 (same behavior as 
clang).

For simplicity, only forward the flag to the frontend driver when it 
contradicts what is implied by the optimization level.

This was first landed in
https://github.com/llvm/llvm-project/pull/73111 but was later reverted due to a 
performance regression. That regression was fixed by 
https://github.com/llvm/llvm-project/pull/74065.

>From 9a0ebf53f58cb77663c3ebd8fcba1ca1d163e706 Mon Sep 17 00:00:00 2001
From: Tom Eccles 
Date: Mon, 27 Nov 2023 15:10:21 +
Subject: [PATCH] [flang] (Re-)Enable alias tags pass by default

Enable by default for optimization levels higher than 0 (same behavior
as clang).

For simplicity, only forward the flag to the frontend driver when it
contradicts what is implied by the optimization level.

This was first landed in
https://github.com/llvm/llvm-project/pull/73111 but was later reverted
due to a performance regression. That regression was fixed by
https://github.com/llvm/llvm-project/pull/74065.
---
 clang/lib/Driver/ToolChains/Flang.cpp | 20 
 flang/include/flang/Tools/CLOptions.inc   |  6 +++---
 flang/lib/Frontend/CompilerInvocation.cpp | 10 ++
 flang/test/Driver/falias-analysis.f90 | 16 +++-
 flang/test/Driver/mlir-pass-pipeline.f90  |  2 ++
 flang/test/Driver/optimization-remark.f90 | 22 +-
 flang/test/Fir/basic-program.fir  |  4 
 flang/tools/tco/tco.cpp   |  1 +
 8 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 98b337e60e4ff..0319f1a117111 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -143,6 +143,26 @@ void Flang::addCodegenOptions(const ArgList ,
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
 
+  Arg *aliasAnalysis = Args.getLastArg(options::OPT_falias_analysis,
+   options::OPT_fno_alias_analysis);
+  // only pass on the argument if it does not match that implied by the
+  // optimization level: so if optimization is requested, only forward
+  // -fno-alias-analysis. If optimization is not requested, only forward
+  // -falias-analysis.
+  Arg *optLevel =
+  Args.getLastArg(options::OPT_Ofast, options::OPT_O, options::OPT_O4);
+  if (aliasAnalysis) {
+bool faliasAnalysis =
+aliasAnalysis->getOption().matches(options::OPT_falias_analysis);
+if (optLevel && !faliasAnalysis) {
+  CmdArgs.push_back("-fno-alias-analysis");
+} else {
+  if (faliasAnalysis)
+// requested alias analysis but no optimization enabled
+CmdArgs.push_back("-falias-analysis");
+}
+  }
+
   Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
 options::OPT_flang_deprecated_no_hlfir,
 options::OPT_flang_experimental_polymorphism,
diff --git a/flang/include/flang/Tools/CLOptions.inc 
b/flang/include/flang/Tools/CLOptions.inc
index c452c023b4a80..d3e4dc6cd4a24 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -158,10 +158,10 @@ inline void addDebugFoundationPass(mlir::PassManager ) 
{
 }
 
 inline void addFIRToLLVMPass(
-mlir::PassManager , llvm::OptimizationLevel optLevel = defaultOptLevel) 
{
+mlir::PassManager , const MLIRToLLVMPassPipelineConfig ) {
   fir::FIRToLLVMPassOptions options;
   options.ignoreMissingTypeDescriptors = ignoreMissingTypeDescriptors;
-  options.applyTBAA = optLevel.isOptimizingForSpeed();
+  options.applyTBAA = config.AliasAnalysis;
   options.forceUnifiedTBAATree = useOldAliasTags;
   addPassConditionally(pm, disableFirToLlvmIr,
   [&]() { return fir::createFIRToLLVMPass(options); });
@@ -311,7 +311,7 @@ inline void createDefaultFIRCodeGenPassPipeline(
   if (config.VScaleMin != 0)
 pm.addPass(fir::createVScaleAttrPass({config.VScaleMin, 
config.VScaleMax}));
 
-  fir::addFIRToLLVMPass(pm, config.OptLevel);
+  fir::addFIRToLLVMPass(pm, config);
 }
 
 /// Create a pass pipeline for lowering from MLIR to LLVM IR
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index e7730d50dc1bd..ec04727fb2641 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -242,10 +242,12 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions ,
clang::driver::options::OPT_fno_loop_versioning, false))
 opts.LoopVersioning = 1;
 
-  opts.AliasAnalysis =
-  args.hasFlag(clang::driver::options::OPT_falias_analysis,
-   clang::driver::options::OPT_fno_alias_analysis,
-   /*default=*/false);
+  opts.AliasAnalysis = opts.OptimizationLevel > 0;
+  if (auto *arg =
+  

[flang] [clang] [flang][driver] Add -fno-fortran-main (link time) option to remove Fortran_main from link line (PR #74139)

2023-12-03 Thread Michael Klemm via cfe-commits

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


[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-03 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Could you please rebase this patch on 
https://github.com/llvm/llvm-project/pull/74246 and add a test for 
https://github.com/llvm/llvm-project/issues/74242?


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


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-03 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/71077

>From ff1b0d96e7beef51a082d59548c49b9c02d79eb0 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Thu, 2 Nov 2023 19:20:27 +0300
Subject: [PATCH] [clang] Improve bit-field in ref NTTP diagnostic

Prior to this, attempts to bind a bit-field to an NTTP of reference type
produced an error because references to subobjects in NTTPs are
disallowed. But C++20 allows references to subobjects in NTTPs generally
(see P1907R1). Without this change, implementing P1907R1 would cause
a bug allowing bit-fields to be bound to reference template arguments.

Extracted from https://reviews.llvm.org/D140996
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td   |  2 ++
 clang/lib/Sema/SemaOverload.cpp| 10 ++
 clang/test/CXX/drs/dr12xx.cpp  |  2 +-
 clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp |  6 ++
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6dfb2d7195203..b95d2bea00a5e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2251,6 +2251,8 @@ def warn_cxx17_compat_aggregate_init_paren_list : Warning<
 def err_reference_bind_to_bitfield : Error<
   "%select{non-const|volatile}0 reference cannot bind to "
   "bit-field%select{| %1}2">;
+def err_reference_bind_to_bitfield_in_cce : Error<
+  "reference cannot bind to bit-field in converted constant expression">;
 def err_reference_bind_to_vector_element : Error<
   "%select{non-const|volatile}0 reference cannot bind to vector element">;
 def err_reference_bind_to_matrix_element : Error<
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 5026e1d603e5e..ebbd4f48b57f8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6056,6 +6056,16 @@ static ExprResult BuildConvertedConstantExpression(Sema 
, Expr *From,
   diag::err_typecheck_converted_constant_expression_indirect)
<< From->getType() << From->getSourceRange() << T;
   }
+  // 'TryCopyInitialization' returns incorrect info for attempts to bind
+  // a reference to a bit-field due to C++ [over.ics.ref]p4. Namely,
+  // 'SCS->DirectBinding' occurs to be set to 'true' despite it is not
+  // the direct binding according to C++ [dcl.init.ref]p5. Hence, check this
+  // case explicitly.
+  if (From->refersToBitField() && T.getTypePtr()->isReferenceType()) {
+return S.Diag(From->getBeginLoc(),
+  diag::err_reference_bind_to_bitfield_in_cce)
+   << From->getSourceRange();
+  }
 
   // Usually we can simply apply the ImplicitConversionSequence we formed
   // earlier, but that's not guaranteed to work when initializing an object of
diff --git a/clang/test/CXX/drs/dr12xx.cpp b/clang/test/CXX/drs/dr12xx.cpp
index c23a515ba56cb..81c113d4c1c5a 100644
--- a/clang/test/CXX/drs/dr12xx.cpp
+++ b/clang/test/CXX/drs/dr12xx.cpp
@@ -138,7 +138,7 @@ namespace dr1295 { // dr1295: 4
 #if __cplusplus <= 201402L
   // expected-error@-2 {{does not refer to any declaration}} expected-note@-3 
{{here}}
 #else
-  // expected-error@-4 {{refers to subobject}}
+  // expected-error@-4 {{reference cannot bind to bit-field in converted 
constant expression}}
 #endif
 
 #if __cplusplus >= 201103L
diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
index 792dc78464b2a..982f6ec221570 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -93,6 +93,12 @@ namespace ConvertedConstant {
   template  struct X {};
   void f(X<1.0f>) {}
   void g(X<2>) {}
+
+  struct {
+int i : 2;
+  } b;
+  template  struct Y {};
+  void f(Y) {} // expected-error {{reference cannot bind to bit-field in 
converted constant expression}}
 }
 
 namespace CopyCounting {

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


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-03 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -5992,6 +5992,15 @@ static ExprResult BuildConvertedConstantExpression(Sema 
, Expr *From,
   /*InOverloadResolution=*/false,
   /*AllowObjCWritebackConversion=*/false,
   /*AllowExplicit=*/false);
+
+  // TryCopyInitialization returns incorrect info for attempts to bind 
reference
+  // to bit-field due to C++ [over.ics.ref]p4, so check it here.
+  if (From->refersToBitField() && T.getTypePtr()->isReferenceType()) {
+return S.Diag(From->getBeginLoc(),
+  diag::err_reference_bind_to_bitfield_in_cce)
+   << From->getSourceRange();
+  }

bolshakov-a wrote:

This citation is already present here. I've moved the new code closer to the 
last cited piece.

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


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-03 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

> Can you add a release note?

Do you think this small diagnostic wording change is worth noting in relnotes?

> Do we need more tests in other contexts where a converted constant expression 
> is used?

Seems like constant expressions converted to references may currently only 
appear in non-type template arguments. Added a case into 
`SemaTemplate/temp_arg_nontype_cxx20.cpp`.

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


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-03 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 9f78edbd20ed922cced9482f7791deb9899a6d82 
bc2ea1ab74b613f700b11390a4715a0f2bec10e7 -- clang/lib/Sema/SemaOverload.cpp 
clang/test/CXX/drs/dr12xx.cpp clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index befc27811e..739951fd48 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -123,43 +123,21 @@ CompareDerivedToBaseConversions(Sema , SourceLocation 
Loc,
 /// GetConversionRank - Retrieve the implicit conversion rank
 /// corresponding to the given implicit conversion kind.
 ImplicitConversionRank clang::GetConversionRank(ImplicitConversionKind Kind) {
-  static const ImplicitConversionRank
-Rank[] = {
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Promotion,
-ICR_Promotion,
-ICR_Promotion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_OCL_Scalar_Widening,
-ICR_Complex_Real_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Writeback_Conversion,
-ICR_Exact_Match, // NOTE(gbiv): This may not be completely right --
- // it was omitted by the patch that added
- // ICK_Zero_Event_Conversion
-ICR_Exact_Match, // NOTE(ctopper): This may not be completely right --
- // it was omitted by the patch that added
- // ICK_Zero_Queue_Conversion
-ICR_C_Conversion,
-ICR_C_Conversion_Extension
-  };
+  static const ImplicitConversionRank Rank[] = {
+  ICR_Exact_Match, ICR_Exact_Match, ICR_Exact_Match, ICR_Exact_Match,
+  ICR_Exact_Match, ICR_Exact_Match, ICR_Promotion, ICR_Promotion,
+  ICR_Promotion, ICR_Conversion, ICR_Conversion, ICR_Conversion,
+  ICR_Conversion, ICR_Conversion, ICR_Conversion, ICR_Conversion,
+  ICR_Conversion, ICR_Conversion, ICR_Conversion, ICR_Conversion,
+  ICR_Conversion, ICR_OCL_Scalar_Widening, ICR_Complex_Real_Conversion,
+  ICR_Conversion, ICR_Conversion, ICR_Writeback_Conversion,
+  ICR_Exact_Match, // NOTE(gbiv): This may not be completely right --
+   // it was omitted by the patch that added
+   // ICK_Zero_Event_Conversion
+  ICR_Exact_Match, // NOTE(ctopper): This may not be completely right --
+   // it was omitted by the patch that added
+   // ICK_Zero_Queue_Conversion
+  ICR_C_Conversion, ICR_C_Conversion_Extension};
   static_assert(std::size(Rank) == (int)ICK_Num_Conversion_Kinds);
   return Rank[(int)Kind];
 }
@@ -167,38 +145,36 @@ ImplicitConversionRank 
clang::GetConversionRank(ImplicitConversionKind Kind) {
 /// GetImplicitConversionName - Return the name of this kind of
 /// implicit conversion.
 static const char* GetImplicitConversionName(ImplicitConversionKind Kind) {
-  static const char* const Name[] = {
-"No conversion",
-"Lvalue-to-rvalue",
-"Array-to-pointer",
-"Function-to-pointer",
-"Function pointer conversion",
-"Qualification",
-"Integral promotion",
-"Floating point promotion",
-"Complex promotion",
-"Integral conversion",
-"Floating conversion",
-"Complex conversion",
-"Floating-integral conversion",
-"Pointer conversion",
-"Pointer-to-member conversion",
-"Boolean conversion",
-"Compatible-types conversion",
-"Derived-to-base conversion",
-"Vector conversion",
-"SVE Vector conversion",
-"RVV Vector conversion",
-"Vector splat",
-"Complex-real conversion",
-"Block Pointer conversion",
-"Transparent Union Conversion",
-"Writeback conversion",
-"OpenCL Zero Event Conversion",
-"OpenCL Zero Queue Conversion",
-"C specific type conversion",
-"Incompatible pointer conversion"
-  };
+  static const char *const Name[] = {"No conversion",
+ "Lvalue-to-rvalue",
+ "Array-to-pointer",
+ "Function-to-pointer",
+ "Function pointer conversion",
+ "Qualification",
+ "Integral promotion",
+ "Floating point promotion",
+ "Complex promotion",
+ "Integral conversion",
+ 

[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-03 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/71077

>From bc2ea1ab74b613f700b11390a4715a0f2bec10e7 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Thu, 2 Nov 2023 19:20:27 +0300
Subject: [PATCH] [clang] Improve bit-field in ref NTTP diagnostic

Prior to this, attempts to bind a bit-field to an NTTP of reference type
produced an error because references to subobjects in NTTPs are
disallowed. But C++20 allows references to subobjects in NTTPs generally
(see P1907R1). Without this change, implementing P1907R1 would cause
a bug allowing bit-fields to be bound to reference template arguments.

Extracted from https://reviews.llvm.org/D140996
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td   |  2 ++
 clang/lib/Sema/SemaOverload.cpp| 10 ++
 clang/test/CXX/drs/dr12xx.cpp  |  2 +-
 clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp |  6 ++
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 474afc2fb99c1..94b836252eda5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2251,6 +2251,8 @@ def warn_cxx17_compat_aggregate_init_paren_list : Warning<
 def err_reference_bind_to_bitfield : Error<
   "%select{non-const|volatile}0 reference cannot bind to "
   "bit-field%select{| %1}2">;
+def err_reference_bind_to_bitfield_in_cce : Error<
+  "reference cannot bind to bit-field in converted constant expression">;
 def err_reference_bind_to_vector_element : Error<
   "%select{non-const|volatile}0 reference cannot bind to vector element">;
 def err_reference_bind_to_matrix_element : Error<
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index d3d2dfed2ce0c..befc27811ef45 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6028,6 +6028,16 @@ static ExprResult BuildConvertedConstantExpression(Sema 
, Expr *From,
   diag::err_typecheck_converted_constant_expression_indirect)
<< From->getType() << From->getSourceRange() << T;
   }
+  // 'TryCopyInitialization' returns incorrect info for attempts to bind
+  // a reference to a bit-field due to C++ [over.ics.ref]p4. Namely,
+  // 'SCS->DirectBinding' occurs to be set to 'true' despite it is not
+  // the direct binding according to C++ [dcl.init.ref]p5. Hence, check this
+  // case explicitly.
+  if (From->refersToBitField() && T.getTypePtr()->isReferenceType()) {
+return S.Diag(From->getBeginLoc(),
+  diag::err_reference_bind_to_bitfield_in_cce)
+   << From->getSourceRange();
+  }
 
   // Usually we can simply apply the ImplicitConversionSequence we formed
   // earlier, but that's not guaranteed to work when initializing an object of
diff --git a/clang/test/CXX/drs/dr12xx.cpp b/clang/test/CXX/drs/dr12xx.cpp
index c23a515ba56cb..81c113d4c1c5a 100644
--- a/clang/test/CXX/drs/dr12xx.cpp
+++ b/clang/test/CXX/drs/dr12xx.cpp
@@ -138,7 +138,7 @@ namespace dr1295 { // dr1295: 4
 #if __cplusplus <= 201402L
   // expected-error@-2 {{does not refer to any declaration}} expected-note@-3 
{{here}}
 #else
-  // expected-error@-4 {{refers to subobject}}
+  // expected-error@-4 {{reference cannot bind to bit-field in converted 
constant expression}}
 #endif
 
 #if __cplusplus >= 201103L
diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
index 9f9aad604d5f1..cd65a20bbf679 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -92,6 +92,12 @@ namespace ConvertedConstant {
   template  struct X {};
   void f(X<1.0f>) {} // OK, user-defined conversion
   void f(X<2>) {} // expected-error {{conversion from 'int' to 'A' is not 
allowed in a converted constant expression}}
+
+  struct {
+int i : 2;
+  } b;
+  template  struct Y {};
+  void f(Y) {} // expected-error {{reference cannot bind to bit-field in 
converted constant expression}}
 }
 
 namespace CopyCounting {

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


[openmp] [clang] [mlir] [llvm] [OpenMP] Introduce the KernelLaunchEnvironment as implicit argument (PR #70401)

2023-12-03 Thread via cfe-commits

ronlieb wrote:

original perf regressions seem recovered enough, thx.
appreciate the info message being added for future triage...

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


[clang] [clang][NFC] Refactor expected directives in C++ DRs 300-399 (PR #74243)

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

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


[clang] bc51a36 - [clang][NFC] Refactor expected directives in C++ DRs 300-399 (#74243)

2023-12-03 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-12-03T18:35:49+04:00
New Revision: bc51a36fd67c9ef08259612a1a04db6be51a8b76

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

LOG: [clang][NFC] Refactor expected directives in C++ DRs 300-399 (#74243)

This patch continues the work started with 
ea5b1ef016d020c37f903d6c7d4f623be975dab8. See that commit and its corresponding 
PR for details.

Added: 


Modified: 
clang/test/CXX/drs/dr3xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr3xx.cpp b/clang/test/CXX/drs/dr3xx.cpp
index d12e0aea5f5ac..b1fcf709c2273 100644
--- a/clang/test/CXX/drs/dr3xx.cpp
+++ b/clang/test/CXX/drs/dr3xx.cpp
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_23,cxx23-triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 -verify=expected,cxx98_20,cxx20_23 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++17 -verify=expected,cxx98_17,cxx98_20 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++14 -verify=expected,cxx98_17,cxx98_20 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++11 -verify=expected,cxx98_17,cxx98_20 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++98 -verify=expected,cxx98_17,cxx98_20 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 
-verify=expected,cxx20-23,cxx23,since-cxx11,since-cxx17,since-cxx23 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 
-verify=expected,cxx98-20,cxx20-23,since-cxx11,since-cxx17 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 
-verify=expected,cxx98-17,cxx98-20,since-cxx11,since-cxx17 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++14 
-verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx11-14,since-cxx11 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 
-verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx11-14,since-cxx11 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++98 
-verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx98 -triple %itanium_abi_triple 
%s -fexceptions -fcxx-exceptions -pedantic-errors
 
 namespace dr300 { // dr300: yes
   template void f(R (&)(A)) {}
@@ -18,50 +18,81 @@ namespace dr301 { // dr301: 3.5
   void operator-(S, S);
 
   void f() {
-bool a = (void(*)(S, S))operator+ < // expected-warning {{ordered 
comparison of function pointers}}
- (void(*)(S, S))operator+;
-bool b = (void(*)(S, S))operator- < // cxx20_23-note {{to match this '<'}} 
cxx98_17-warning {{ordered comparison of function pointers}}
- (void(*)(S, S))operator-; // cxx20_23-error {{expected '>'}}
-bool c = (void(*)(S, S))operator+ < // expected-note {{to match this '<'}}
- (void(*)(S, S))operator-; // expected-error {{expected '>'}}
+bool a = (void(*)(S, S))operator+ < (void(*)(S, S))operator+;
+// expected-warning@-1 {{ordered comparison of function pointers ('void 
(*)(S, S)' and 'void (*)(S, S)')}}
+bool b = (void(*)(S, S))operator- < (void(*)(S, S))operator-;
+// cxx98-17-warning@-1 {{ordered comparison of function pointers ('void 
(*)(S, S)' and 'void (*)(S, S)')}}
+// cxx20-23-error@-2 {{expected '>'}}
+//   cxx20-23-note@-3 {{to match this '<'}} 
+bool c = (void(*)(S, S))operator+ < (void(*)(S, S))operator-;
+// expected-error@-1 {{expected '>'}}
+// expected-note@-2 {{to match this '<'}}
   }
 
   template void f() {
-typename T::template operator+ a; // expected-error {{typename 
specifier refers to a non-type template}} expected-error +{{}}
+// FIXME: We are emitting a lot of bogus diagnostics here.
+typename T::template operator+ a;
+// expected-error@-1 {{typename specifier refers to a non-type template}}
+// expected-error@-2 {{'template' keyword not permitted here}}
+// expected-error@-3 {{a type specifier is required for all declarations}}
+// expected-error@-4 {{'operator+' cannot be the name of a variable or 
data member}}
+// expected-error@-5 {{expected ';' at end of declaration}}
 // FIXME: This shouldn't say (null).
-class T::template operator+ b; // expected-error {{identifier 
followed by '<' indicates a class template specialization but (null) refers to 
a function template}}
-enum T::template operator+ c; // expected-error {{expected 

[clang] Remove warnings from -Wchar-subscripts for known positive constants (PR #69061)

2023-12-03 Thread via cfe-commits

wheatman wrote:

@cor3ntin done, thanks for taking a look 

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


[clang] [clang][NFC] Refactor expected directives in C++ DRs 300-399 (PR #74243)

2023-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch continues the work started with 
ea5b1ef016d020c37f903d6c7d4f623be975dab8. See that commit and its corresponding 
PR for details.

---

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


1 Files Affected:

- (modified) clang/test/CXX/drs/dr3xx.cpp (+594-345) 


``diff
diff --git a/clang/test/CXX/drs/dr3xx.cpp b/clang/test/CXX/drs/dr3xx.cpp
index d12e0aea5f5a..b1fcf709c227 100644
--- a/clang/test/CXX/drs/dr3xx.cpp
+++ b/clang/test/CXX/drs/dr3xx.cpp
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_23,cxx23-triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 -verify=expected,cxx98_20,cxx20_23 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++17 -verify=expected,cxx98_17,cxx98_20 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++14 -verify=expected,cxx98_17,cxx98_20 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++11 -verify=expected,cxx98_17,cxx98_20 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++98 -verify=expected,cxx98_17,cxx98_20 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 
-verify=expected,cxx20-23,cxx23,since-cxx11,since-cxx17,since-cxx23 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 
-verify=expected,cxx98-20,cxx20-23,since-cxx11,since-cxx17 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 
-verify=expected,cxx98-17,cxx98-20,since-cxx11,since-cxx17 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++14 
-verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx11-14,since-cxx11 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 
-verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx11-14,since-cxx11 -triple 
%itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++98 
-verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx98 -triple %itanium_abi_triple 
%s -fexceptions -fcxx-exceptions -pedantic-errors
 
 namespace dr300 { // dr300: yes
   template void f(R (&)(A)) {}
@@ -18,50 +18,81 @@ namespace dr301 { // dr301: 3.5
   void operator-(S, S);
 
   void f() {
-bool a = (void(*)(S, S))operator+ < // expected-warning {{ordered 
comparison of function pointers}}
- (void(*)(S, S))operator+;
-bool b = (void(*)(S, S))operator- < // cxx20_23-note {{to match this '<'}} 
cxx98_17-warning {{ordered comparison of function pointers}}
- (void(*)(S, S))operator-; // cxx20_23-error {{expected '>'}}
-bool c = (void(*)(S, S))operator+ < // expected-note {{to match this '<'}}
- (void(*)(S, S))operator-; // expected-error {{expected '>'}}
+bool a = (void(*)(S, S))operator+ < (void(*)(S, S))operator+;
+// expected-warning@-1 {{ordered comparison of function pointers ('void 
(*)(S, S)' and 'void (*)(S, S)')}}
+bool b = (void(*)(S, S))operator- < (void(*)(S, S))operator-;
+// cxx98-17-warning@-1 {{ordered comparison of function pointers ('void 
(*)(S, S)' and 'void (*)(S, S)')}}
+// cxx20-23-error@-2 {{expected '>'}}
+//   cxx20-23-note@-3 {{to match this '<'}} 
+bool c = (void(*)(S, S))operator+ < (void(*)(S, S))operator-;
+// expected-error@-1 {{expected '>'}}
+// expected-note@-2 {{to match this '<'}}
   }
 
   template void f() {
-typename T::template operator+ a; // expected-error {{typename 
specifier refers to a non-type template}} expected-error +{{}}
+// FIXME: We are emitting a lot of bogus diagnostics here.
+typename T::template operator+ a;
+// expected-error@-1 {{typename specifier refers to a non-type template}}
+// expected-error@-2 {{'template' keyword not permitted here}}
+// expected-error@-3 {{a type specifier is required for all declarations}}
+// expected-error@-4 {{'operator+' cannot be the name of a variable or 
data member}}
+// expected-error@-5 {{expected ';' at end of declaration}}
 // FIXME: This shouldn't say (null).
-class T::template operator+ b; // expected-error {{identifier 
followed by '<' indicates a class template specialization but (null) refers to 
a function template}}
-enum T::template operator+ c; // expected-error {{expected 
identifier}}
-enum T::template operator+::E d; // expected-error {{qualified name 
refers into a specialization of function template 'T::template operator +'}} 
expected-error {{forward reference}}
+class T::template 

[clang] [clang][NFC] Refactor expected directives in C++ DRs 300-399 (PR #74243)

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

Endilll wrote:

This PR is created only for CI purposes.

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


  1   2   >