[clang] [clang][AArch64] multilib: fix deduction of "-march=" option (PR #81474)

2024-02-14 Thread Dominik Wójt via cfe-commits

https://github.com/domin144 updated 
https://github.com/llvm/llvm-project/pull/81474

From 9ffef2685c2766c6944e368a739b8c94e9b68092 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20W=C3=B3jt?= 
Date: Mon, 12 Feb 2024 13:38:14 +0100
Subject: [PATCH 1/2] [clang][AArch64] multilib: fix deduction of "-march="
 option

The deduced "-march=" option always started with aarch64, which is not a
valid value. There was also no way to distinguish between armv8-r and
armv8-a. After this commit, the deduced "-march=" option will start with
greatest available "armv*-a" value or "armv8-r".
---
 clang/lib/Driver/ToolChain.cpp | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 657577cea6c7d8..623d52e9471f23 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -191,7 +191,11 @@ static void getAArch64MultilibFlags(const Driver &D,
   for (const auto &Ext : AArch64::Extensions)
 if (FeatureSet.contains(Ext.NegFeature))
   MArch.push_back(("no" + Ext.Name).str());
-  MArch.insert(MArch.begin(), ("-march=" + Triple.getArchName()).str());
+  StringRef ArchName;
+  for (const auto &ArchInfo : AArch64::ArchInfos)
+if (FeatureSet.contains(ArchInfo->ArchFeature))
+  ArchName = ArchInfo->Name;
+  MArch.insert(MArch.begin(), ("-march=" + ArchName).str());
   Result.push_back(llvm::join(MArch, "+"));
 }
 

From 548e0f8d53096cb945e4807bf4898e193fde854d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20W=C3=B3jt?= 
Date: Mon, 12 Feb 2024 14:46:26 +0100
Subject: [PATCH 2/2] fix tests

---
 clang/test/Driver/print-multi-selection-flags.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/print-multi-selection-flags.c 
b/clang/test/Driver/print-multi-selection-flags.c
index 248d9a3cdf49b2..06a12db9d97792 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -51,9 +51,10 @@
 // CHECK-M85_NO_FP_DP: -mfpu=fp-armv8-fullfp16-sp-d16
 
 // RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf 
-march=armv8-a+lse | FileCheck --check-prefix=CHECK-LSE %s
-// CHECK-LSE: -march=aarch64{{.*}}+lse{{.*}}
+// CHECK-LSE: --target=aarch64-none-unknown-elf
+// CHECK-LSE: -march=armv8-a{{.*}}+lse{{.*}}
 
 // RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf 
-march=armv8.5-a+sve+sve2 | FileCheck --check-prefix=CHECK-SVE2 %s
 // RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf 
-march=armv9-a| FileCheck --check-prefix=CHECK-SVE2 %s
 // CHECK-SVE2: --target=aarch64-none-unknown-elf
-// CHECK-SVE2: -march=aarch64{{.*}}+simd{{.*}}+sve{{.*}}+sve2{{.*}}
+// CHECK-SVE2: -march=armv{{.*}}-a{{.*}}+simd{{.*}}+sve{{.*}}+sve2{{.*}}

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


[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

2024-02-14 Thread via cfe-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/81591

>From a40215e93b3d27f77d9e5f7ff38883ab1d4fde9a Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Tue, 13 Feb 2024 21:09:57 +1030
Subject: [PATCH 1/2] [clang-format][NFC] Drop "Always" in
 "AlwaysBreakAfterReturnType".

---
 clang/include/clang/Format/Format.h   |  6 +--
 clang/lib/Format/ContinuationIndenter.cpp |  6 +--
 clang/lib/Format/Format.cpp   | 20 +-
 clang/lib/Format/TokenAnnotator.cpp   |  7 ++--
 clang/unittests/Format/ConfigParseTest.cpp| 40 +--
 .../Format/DefinitionBlockSeparatorTest.cpp   |  2 +-
 clang/unittests/Format/FormatTest.cpp | 16 
 clang/unittests/Format/FormatTestCSharp.cpp   |  2 +-
 8 files changed, 47 insertions(+), 52 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 737cbfced9e9ce..e9b2160a7b9243 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1013,7 +1013,7 @@ struct FormatStyle {
   /// This option is renamed to ``BreakAfterReturnType``.
   /// \version 3.8
   /// @deprecated
-  ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
+  // ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
 
   /// If ``true``, always break before multiline string literals.
   ///
@@ -1579,7 +1579,7 @@ struct FormatStyle {
 
   /// The function declaration return type breaking style to use.
   /// \version 19
-  // ReturnTypeBreakingStyle BreakAfterReturnType;
+  ReturnTypeBreakingStyle BreakAfterReturnType;
 
   /// If ``true``, clang-format will always break after a Json array ``[``
   /// otherwise it will scan until the closing ``]`` to determine if it should
@@ -4824,7 +4824,6 @@ struct FormatStyle {
R.AllowShortIfStatementsOnASingleLine &&
AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine 
&&
AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
-   AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
AlwaysBreakBeforeMultilineStrings ==
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
@@ -4835,6 +4834,7 @@ struct FormatStyle {
BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
BreakAfterAttributes == R.BreakAfterAttributes &&
BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations 
&&
+   BreakAfterReturnType == R.BreakAfterReturnType &&
BreakArrays == R.BreakArrays &&
BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
BreakBeforeBraces == R.BreakBeforeBraces &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..159d130cb67332 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -329,12 +329,12 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
   // Don't break after very short return types (e.g. "void") as that is often
   // unexpected.
   if (Current.is(TT_FunctionDeclarationName)) {
-if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None &&
+if (Style.BreakAfterReturnType == FormatStyle::RTBS_None &&
 State.Column < 6) {
   return false;
 }
 
-if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_ExceptShortType) 
{
+if (Style.BreakAfterReturnType == FormatStyle::RTBS_ExceptShortType) {
   assert(State.Column >= State.FirstIndent);
   if (State.Column - State.FirstIndent < 6)
 return false;
@@ -597,7 +597,7 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   !State.Line->ReturnTypeWrapped &&
   // Don't break before a C# function when no break after return type.
   (!Style.isCSharp() ||
-   Style.AlwaysBreakAfterReturnType > FormatStyle::RTBS_ExceptShortType) &&
+   Style.BreakAfterReturnType > FormatStyle::RTBS_ExceptShortType) &&
   // Don't always break between a JavaScript `function` and the function
   // name.
   !Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 8efc42e0576cf9..9e49406046bfef 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -877,8 +877,7 @@ template <> struct MappingTraits {
 if (!IO.outputting()) {
   IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
   IO.mapOptional("AllowAllConstructorInitializersOnNextLine", OnNextLine);
-  IO.mapOptional("AlwaysBreakAfterReturnType",
- Style.AlwaysBreakAfterReturnType);
+  IO.mapOptional("AlwaysBreakAfterReturnType", Style.BreakAfterReturnType);
   IO.mapOptional("AlwaysBreakTemplateDeclarations",
  Style.BreakTemplateDeclarations);
   IO.mapOp

[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

2024-02-14 Thread via cfe-commits


@@ -1871,10 +1869,10 @@ FormatStyle getWebKitStyle() {
 FormatStyle getGNUStyle() {
   FormatStyle Style = getLLVMStyle();
   Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
-  Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
   Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
   Style.BreakBeforeBraces = FormatStyle::BS_GNU;
   Style.BreakBeforeTernaryOperators = true;
+  Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;

rmarker wrote:

Done.

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


[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

2024-02-14 Thread via cfe-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/81591

>From a40215e93b3d27f77d9e5f7ff38883ab1d4fde9a Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Tue, 13 Feb 2024 21:09:57 +1030
Subject: [PATCH 1/3] [clang-format][NFC] Drop "Always" in
 "AlwaysBreakAfterReturnType".

---
 clang/include/clang/Format/Format.h   |  6 +--
 clang/lib/Format/ContinuationIndenter.cpp |  6 +--
 clang/lib/Format/Format.cpp   | 20 +-
 clang/lib/Format/TokenAnnotator.cpp   |  7 ++--
 clang/unittests/Format/ConfigParseTest.cpp| 40 +--
 .../Format/DefinitionBlockSeparatorTest.cpp   |  2 +-
 clang/unittests/Format/FormatTest.cpp | 16 
 clang/unittests/Format/FormatTestCSharp.cpp   |  2 +-
 8 files changed, 47 insertions(+), 52 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 737cbfced9e9ce..e9b2160a7b9243 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1013,7 +1013,7 @@ struct FormatStyle {
   /// This option is renamed to ``BreakAfterReturnType``.
   /// \version 3.8
   /// @deprecated
-  ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
+  // ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
 
   /// If ``true``, always break before multiline string literals.
   ///
@@ -1579,7 +1579,7 @@ struct FormatStyle {
 
   /// The function declaration return type breaking style to use.
   /// \version 19
-  // ReturnTypeBreakingStyle BreakAfterReturnType;
+  ReturnTypeBreakingStyle BreakAfterReturnType;
 
   /// If ``true``, clang-format will always break after a Json array ``[``
   /// otherwise it will scan until the closing ``]`` to determine if it should
@@ -4824,7 +4824,6 @@ struct FormatStyle {
R.AllowShortIfStatementsOnASingleLine &&
AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine 
&&
AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
-   AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
AlwaysBreakBeforeMultilineStrings ==
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
@@ -4835,6 +4834,7 @@ struct FormatStyle {
BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
BreakAfterAttributes == R.BreakAfterAttributes &&
BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations 
&&
+   BreakAfterReturnType == R.BreakAfterReturnType &&
BreakArrays == R.BreakArrays &&
BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
BreakBeforeBraces == R.BreakBeforeBraces &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..159d130cb67332 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -329,12 +329,12 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
   // Don't break after very short return types (e.g. "void") as that is often
   // unexpected.
   if (Current.is(TT_FunctionDeclarationName)) {
-if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None &&
+if (Style.BreakAfterReturnType == FormatStyle::RTBS_None &&
 State.Column < 6) {
   return false;
 }
 
-if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_ExceptShortType) 
{
+if (Style.BreakAfterReturnType == FormatStyle::RTBS_ExceptShortType) {
   assert(State.Column >= State.FirstIndent);
   if (State.Column - State.FirstIndent < 6)
 return false;
@@ -597,7 +597,7 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   !State.Line->ReturnTypeWrapped &&
   // Don't break before a C# function when no break after return type.
   (!Style.isCSharp() ||
-   Style.AlwaysBreakAfterReturnType > FormatStyle::RTBS_ExceptShortType) &&
+   Style.BreakAfterReturnType > FormatStyle::RTBS_ExceptShortType) &&
   // Don't always break between a JavaScript `function` and the function
   // name.
   !Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 8efc42e0576cf9..9e49406046bfef 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -877,8 +877,7 @@ template <> struct MappingTraits {
 if (!IO.outputting()) {
   IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
   IO.mapOptional("AllowAllConstructorInitializersOnNextLine", OnNextLine);
-  IO.mapOptional("AlwaysBreakAfterReturnType",
- Style.AlwaysBreakAfterReturnType);
+  IO.mapOptional("AlwaysBreakAfterReturnType", Style.BreakAfterReturnType);
   IO.mapOptional("AlwaysBreakTemplateDeclarations",
  Style.BreakTemplateDeclarations);
   IO.mapOp

[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

2024-02-14 Thread via cfe-commits


@@ -1130,14 +1129,13 @@ template <> struct MappingTraits {
 // AlwaysBreakAfterReturnType was not, initialize the latter from the
 // former for backwards compatibility.

rmarker wrote:

Done.

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


[clang] clangCodeGen: Introduce `MCDC::State` with `MCDCState.h` (PR #81497)

2024-02-14 Thread NAKAMURA Takumi via cfe-commits

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


[clang] 5c8985e - clangCodeGen: Introduce `MCDC::State` with `MCDCState.h` (#81497)

2024-02-14 Thread via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-02-14T17:27:53+09:00
New Revision: 5c8985e7703b013c5df0612c3cbc1d333f4c5fa1

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

LOG: clangCodeGen: Introduce `MCDC::State` with `MCDCState.h` (#81497)

This packs;
* `BitmapBytes`
* `BitmapMap`
* `CondIDMap`

into `MCDC::State`.

Added: 
clang/lib/CodeGen/MCDCState.h

Modified: 
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/CodeGen/CodeGenPGO.h
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/CodeGen/CoverageMappingGen.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index 5d7c3847745762..b5ce1aad7ea1e5 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -165,8 +165,7 @@ struct MapRegionCounters : public 
RecursiveASTVisitor {
   llvm::DenseMap &CounterMap;
   /// The next bitmap byte index to assign.
   unsigned NextMCDCBitmapIdx;
-  /// The map of statements to MC/DC bitmap coverage objects.
-  llvm::DenseMap &MCDCBitmapMap;
+  MCDC::State &MCDCState;
   /// Maximum number of supported MC/DC conditions in a boolean expression.
   unsigned MCDCMaxCond;
   /// The profile version.
@@ -176,11 +175,11 @@ struct MapRegionCounters : public 
RecursiveASTVisitor {
 
   MapRegionCounters(PGOHashVersion HashVersion, uint64_t ProfileVersion,
 llvm::DenseMap &CounterMap,
-llvm::DenseMap &MCDCBitmapMap,
-unsigned MCDCMaxCond, DiagnosticsEngine &Diag)
+MCDC::State &MCDCState, unsigned MCDCMaxCond,
+DiagnosticsEngine &Diag)
   : NextCounter(0), Hash(HashVersion), CounterMap(CounterMap),
-NextMCDCBitmapIdx(0), MCDCBitmapMap(MCDCBitmapMap),
-MCDCMaxCond(MCDCMaxCond), ProfileVersion(ProfileVersion), Diag(Diag) {}
+NextMCDCBitmapIdx(0), MCDCState(MCDCState), MCDCMaxCond(MCDCMaxCond),
+ProfileVersion(ProfileVersion), Diag(Diag) {}
 
   // Blocks and lambdas are handled as separate functions, so we need not
   // traverse them in the parent context.
@@ -309,7 +308,7 @@ struct MapRegionCounters : public 
RecursiveASTVisitor {
 
   // Otherwise, allocate the number of bytes required for the bitmap
   // based on the number of conditions. Must be at least 1-byte long.
-  MCDCBitmapMap[BinOp] = NextMCDCBitmapIdx;
+  MCDCState.BitmapMap[BinOp] = NextMCDCBitmapIdx;
   unsigned SizeInBits = std::max(1L << NumCond, CHAR_BIT);
   NextMCDCBitmapIdx += SizeInBits / CHAR_BIT;
 }
@@ -987,10 +986,9 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
   unsigned MCDCMaxConditions = (CGM.getCodeGenOpts().MCDCCoverage) ? 6 : 0;
 
   RegionCounterMap.reset(new llvm::DenseMap);
-  RegionMCDCBitmapMap.reset(new llvm::DenseMap);
+  RegionMCDCState.reset(new MCDC::State);
   MapRegionCounters Walker(HashVersion, ProfileVersion, *RegionCounterMap,
-   *RegionMCDCBitmapMap, MCDCMaxConditions,
-   CGM.getDiags());
+   *RegionMCDCState, MCDCMaxConditions, 
CGM.getDiags());
   if (const FunctionDecl *FD = dyn_cast_or_null(D))
 Walker.TraverseDecl(const_cast(FD));
   else if (const ObjCMethodDecl *MD = dyn_cast_or_null(D))
@@ -1001,7 +999,7 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
 Walker.TraverseDecl(const_cast(CD));
   assert(Walker.NextCounter > 0 && "no entry counter mapped for decl");
   NumRegionCounters = Walker.NextCounter;
-  MCDCBitmapBytes = Walker.NextMCDCBitmapIdx;
+  RegionMCDCState->BitmapBytes = Walker.NextMCDCBitmapIdx;
   FunctionHash = Walker.Hash.finalize();
 }
 
@@ -1033,11 +1031,10 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl 
*D) {
 
   std::string CoverageMapping;
   llvm::raw_string_ostream OS(CoverageMapping);
-  RegionCondIDMap.reset(new llvm::DenseMap);
+  RegionMCDCState->CondIDMap.clear();
   CoverageMappingGen MappingGen(
   *CGM.getCoverageMapping(), CGM.getContext().getSourceManager(),
-  CGM.getLangOpts(), RegionCounterMap.get(), RegionMCDCBitmapMap.get(),
-  RegionCondIDMap.get());
+  CGM.getLangOpts(), RegionCounterMap.get(), RegionMCDCState.get());
   MappingGen.emitCounterMapping(D, OS);
   OS.flush();
 
@@ -1119,7 +1116,7 @@ bool CodeGenPGO::canEmitMCDCCoverage(const CGBuilderTy 
&Builder) {
 }
 
 void CodeGenPGO::emitMCDCParameters(CGBuilderTy &Builder) {
-  if (!canEmitMCDCCoverage(Builder) || !RegionMCDCBitmapMap)
+  if (!canEmitMCDCCoverage(Builder) || !RegionMCDCState)
 return;
 
   auto *I8PtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
@@ -1129,7 +1126,7 @@ void CodeGenPGO::emitMCDCParameters(CGBuilderTy &Builder) 
{
   // anything.
   llvm::Value *Args[3] = {llvm::ConstantExpr

[clang] clangCodeGen: Introduce `MCDC::State` with `MCDCState.h` (PR #81497)

2024-02-14 Thread NAKAMURA Takumi via cfe-commits

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-02-14 Thread Sander de Smalen via cfe-commits


@@ -7517,34 +7517,37 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
 
 auto *CallerFD = dyn_cast(CurContext);
-if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") &&
-!FD->getBuiltinID()) {
+bool IsCalleeStreaming = ((ExtInfo.AArch64SMEAttributes &
+   FunctionType::SME_PStateSMEnabledMask) ||
+  (ExtInfo.AArch64SMEAttributes &
+   FunctionType::SME_PStateSMCompatibleMask));
+bool IsBuiltin = (FD && FD->getBuiltinID());
+
+if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) {
   // If the callee has an AArch64 SME __arm_locally_streaming attribute
   // warn if this function returns VL-based value or pass any such 
argument,
   // the streaming and non-streaming vector lengths may be different.
-  ArmStreamingType CalleeFnType = getArmStreamingFnType(FD);
   ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD);
   // If the caller is a non-streaming function and the callee has a
   // streaming attribute. If it passed any VL-based arguments or return
   // VL-based value, then warn that the streaming and non-streaming vector
   // lengths may be different.
   if (CallerFnType != ArmStreaming) {
-if (CalleeFnType == ArmStreaming) {
+if (IsCalleeStreaming) {
   if (AnyScalableArgs)
-Diag(Loc,
- diag::warn_sme_non_streaming_caller_pass_args_to_streaming);
-  if (FD->getReturnType()->isSizelessVectorType())
-Diag(Loc, 
diag::warn_sme_non_streaming_caller_returns_to_streaming);
+Diag(Loc, 
diag::warn_sme_streaming_pass_return_vl_to_non_streaming);
+  if (Proto->getReturnType()->isSizelessVectorType())
+Diag(Loc, 
diag::warn_sme_streaming_pass_return_vl_to_non_streaming);

sdesmalen-arm wrote:

Do you think this could be simplified further?

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-02-14 Thread Sander de Smalen via cfe-commits


@@ -3717,6 +3717,14 @@ def err_sme_definition_using_za_in_non_sme_target : 
Error<
   "function using ZA state requires 'sme'">;
 def err_sme_definition_using_zt0_in_non_sme2_target : Error<
   "function using ZT0 state requires 'sme2'">;
+def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning<
+  "passing a VL-dependent argument to/from a function that has a different"
+  " streaming-mode, is undefined behaviour">,

sdesmalen-arm wrote:

it is only undefined behaviour if the streaming VL != non-streaming VL.

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-02-14 Thread Sander de Smalen via cfe-commits


@@ -7513,6 +7516,41 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);
+bool IsCalleeStreaming = ((ExtInfo.AArch64SMEAttributes &
+   FunctionType::SME_PStateSMEnabledMask) ||
+  (ExtInfo.AArch64SMEAttributes &
+   FunctionType::SME_PStateSMCompatibleMask));
+bool IsBuiltin = (FD && FD->getBuiltinID());
+
+if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) {
+  // If the callee has an AArch64 SME __arm_locally_streaming attribute
+  // warn if this function returns VL-based value or pass any such 
argument,
+  // the streaming and non-streaming vector lengths may be different.
+  ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD);
+  // If the caller is a non-streaming function and the callee has a
+  // streaming attribute. If it passed any VL-based arguments or return
+  // VL-based value, then warn that the streaming and non-streaming vector
+  // lengths may be different.
+  if (CallerFnType != ArmStreaming) {
+if (IsCalleeStreaming) {
+  if (AnyScalableArgs)
+Diag(Loc, 
diag::warn_sme_streaming_pass_return_vl_to_non_streaming);
+  if (Proto->getReturnType()->isSizelessVectorType())
+Diag(Loc, 
diag::warn_sme_streaming_pass_return_vl_to_non_streaming);
+}
+  } else if (!IsCalleeStreaming) {
+// If the callee is a non-streaming function and the caller has
+// streaming attribute. If it passed any VL-based arguments or return
+// VL-based value, then warn that the streaming and non-streaming 
vector
+// lengths may be different.
+if (AnyScalableArgs)
+  Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming);
+if (Proto->getReturnType()->isSizelessVectorType())
+  Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming);
+  }

sdesmalen-arm wrote:

Does this code support the following case:

```
void test_sc_to_n(sv_ty arg) __arm_streaming_compatible { n(arg); } // expect a 
diagnostic
```

?

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-02-14 Thread Sander de Smalen via cfe-commits


@@ -12236,6 +12236,23 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 bool UsesSM = NewFD->hasAttr();
 bool UsesZA = Attr && Attr->isNewZA();
 bool UsesZT0 = Attr && Attr->isNewZT0();
+
+if (UsesSM) {
+  if (NewFD->getReturnType()->isSizelessVectorType())
+Diag(NewFD->getLocation(),
+ diag::warn_sme_locally_streaming_has_vl_args_returns);
+  auto *FPT = NewFD->getType()->castAs();

sdesmalen-arm wrote:

Is `FunctionPrototype` correct here? That means the check does not happen on 
unprototyped functions, such as `__arm_locally_streaming void foo() { ... }` in 
C (not C++).

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-02-14 Thread Sander de Smalen via cfe-commits


@@ -445,3 +448,54 @@ void conflicting_state_attrs_preserves_out_zt0(void) 
__arm_preserves("zt0") __ar
 // expected-cpp-error@+2 {{conflicting attributes for state 'zt0'}}
 // expected-error@+1 {{conflicting attributes for state 'zt0'}}
 void conflicting_state_attrs_preserves_inout_zt0(void) __arm_preserves("zt0") 
__arm_inout("zt0");
+

sdesmalen-arm wrote:

I don't see all cases I suggested covered in the tests below.

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-02-14 Thread Sander de Smalen via cfe-commits


@@ -12236,6 +12236,23 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 bool UsesSM = NewFD->hasAttr();
 bool UsesZA = Attr && Attr->isNewZA();
 bool UsesZT0 = Attr && Attr->isNewZT0();
+
+if (UsesSM) {
+  if (NewFD->getReturnType()->isSizelessVectorType())
+Diag(NewFD->getLocation(),
+ diag::warn_sme_locally_streaming_has_vl_args_returns);
+  auto *FPT = NewFD->getType()->castAs();
+  bool AnyScalableArgs = false;
+  for (QualType T : FPT->param_types()) {
+if (T->isSizelessVectorType()) {
+  AnyScalableArgs = true;
+  break;
+}
+  }
+  if (AnyScalableArgs)
+Diag(NewFD->getLocation(),
+ diag::warn_sme_locally_streaming_has_vl_args_returns);

sdesmalen-arm wrote:

Can this be written like something along the lines of:
```
if (NewFD->getReturnType()->isSizelessVectorType() ||
llvm::any_of(FPT->param_types(), [](QualType T) { return 
T->isSizelessVectorType(); }))
 Diag();
```
?

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-02-14 Thread Sander de Smalen via cfe-commits


@@ -12239,7 +12239,8 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 
 if (UsesSM) {

sdesmalen-arm wrote:

The comment on line 12232-12233 needs an update.

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-02-14 Thread Sander de Smalen via cfe-commits


@@ -7513,6 +7516,41 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);
+bool IsCalleeStreaming = ((ExtInfo.AArch64SMEAttributes &
+   FunctionType::SME_PStateSMEnabledMask) ||
+  (ExtInfo.AArch64SMEAttributes &
+   FunctionType::SME_PStateSMCompatibleMask));

sdesmalen-arm wrote:

Streaming-compatible and streaming are not the same thing. i.e. if the callee 
is 'streaming-compatible', `IsCalleeStreaming` should be `false`.

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


[clang] Multilib support for libraries with exceptions (PR #75031)

2024-02-14 Thread via cfe-commits

https://github.com/pwprzybyla updated 
https://github.com/llvm/llvm-project/pull/75031

>From ea4d54f574bbceafcd45a108a8688b0a5cfeb0a4 Mon Sep 17 00:00:00 2001
From: Piotr Przybyla 
Date: Wed, 29 Nov 2023 14:05:00 +
Subject: [PATCH] Multilib support for libraries with exceptions and rtti

---
 clang/include/clang/Driver/ToolChain.h | 10 ++
 clang/lib/Driver/ToolChain.cpp | 23 ++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 2d0c1f826c1728..fbe2e8fe8e88d8 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -120,6 +120,11 @@ class ToolChain {
 RM_Disabled,
   };
 
+  enum ExceptionsMode {
+EM_Enabled,
+EM_Disabled,
+  };
+
   struct BitCodeLibraryInfo {
 std::string Path;
 bool ShouldInternalize;
@@ -141,6 +146,8 @@ class ToolChain {
 
   const RTTIMode CachedRTTIMode;
 
+  const ExceptionsMode CachedExceptionsMode;
+
   /// The list of toolchain specific path prefixes to search for libraries.
   path_list LibraryPaths;
 
@@ -318,6 +325,9 @@ class ToolChain {
   // Returns the RTTIMode for the toolchain with the current arguments.
   RTTIMode getRTTIMode() const { return CachedRTTIMode; }
 
+  // Returns the ExceptionsMode for the toolchain with the current arguments.
+  ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; }
+
   /// Return any implicit target and/or mode flag for an invocation of
   /// the compiler driver as `ProgName`.
   ///
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 657577cea6c7d8..15f8294a8785dd 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -77,10 +77,19 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList 
&Args,
   return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled;
 }
 
+static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) {
+  if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
+   true)) {
+return ToolChain::EM_Enabled;
+  }
+  return ToolChain::EM_Disabled;
+}
+
 ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
  const ArgList &Args)
 : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
-  CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
+  CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)),
+  CachedExceptionsMode(CalculateExceptionsMode(Args)) {
   auto addIfExists = [this](path_list &List, const std::string &Path) {
 if (getVFS().exists(Path))
   List.push_back(Path);
@@ -264,6 +273,18 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList 
&Args) const {
 break;
   }
 
+  // Include fno-exceptions and fno-rtti
+  // to improve multilib selection
+  if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled)
+Result.push_back("-fno-rtti");
+  else
+Result.push_back("-frtti");
+
+  if (getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled)
+Result.push_back("-fno-exceptions");
+  else
+Result.push_back("-fexceptions");
+
   // Sort and remove duplicates.
   std::sort(Result.begin(), Result.end());
   Result.erase(std::unique(Result.begin(), Result.end()), Result.end());

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


[clang] 5932f3f - [clangCodeGen] Fix the build failure for 5c8985e7703b013c5df0612c3cbc1d333f4c5fa1

2024-02-14 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2024-02-14T09:54:44+01:00
New Revision: 5932f3f861f84305bd01050d0af8e0dcb232a8b3

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

LOG: [clangCodeGen] Fix the build failure for 
5c8985e7703b013c5df0612c3cbc1d333f4c5fa1

Added: 


Modified: 
clang/lib/CodeGen/MCDCState.h

Removed: 




diff  --git a/clang/lib/CodeGen/MCDCState.h b/clang/lib/CodeGen/MCDCState.h
index dfb0d99921e87e..e6e39237a1b41a 100644
--- a/clang/lib/CodeGen/MCDCState.h
+++ b/clang/lib/CodeGen/MCDCState.h
@@ -16,6 +16,10 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ProfileData/Coverage/MCDCTypes.h"
 
+namespace clang {
+class Stmt;
+} // namespace clang
+
 namespace clang::CodeGen::MCDC {
 
 using namespace llvm::coverage::mcdc;



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


[clang] [clang] Allow builtin addc/subc to be constant evaluated (PR #81656)

2024-02-14 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

Sorry for the confusion, but the codegen test showed it makes sense what you 
are doing.

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


[clang] [clang] Allow builtin addc/subc to be constant evaluated (PR #81656)

2024-02-14 Thread Thorsten Schütt via cfe-commits


@@ -12696,6 +12696,56 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return BuiltinOp == Builtin::BI__atomic_always_lock_free ?
 Success(0, E) : Error(E);
   }
+  case Builtin::BI__builtin_addcb:
+  case Builtin::BI__builtin_addcs:
+  case Builtin::BI__builtin_addc:
+  case Builtin::BI__builtin_addcl:
+  case Builtin::BI__builtin_addcll:
+  case Builtin::BI__builtin_subcb:
+  case Builtin::BI__builtin_subcs:
+  case Builtin::BI__builtin_subc:
+  case Builtin::BI__builtin_subcl:
+  case Builtin::BI__builtin_subcll: {
+LValue CarryOutLValue;
+APSInt LHS, RHS, CarryIn, Result;

tschuett wrote:

If you search the internet for `llvm APSInt`, you will find the `S` means 
signed. You will also find `llvm APInt`. The latter is the unsigned version.

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


[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

2024-02-14 Thread Owen Pan via cfe-commits

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


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


[clang] [llvm] [AMDGPU] Replace '.' with '-' in generic target names (PR #81718)

2024-02-14 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh created 
https://github.com/llvm/llvm-project/pull/81718

The dot is too confusing for tools. Output temporaries would have 
'10.3-generic' so tools could parse it as an extension, device libs & the 
associated clang driver logic are also confused by the dot.

After discussions, we decided it's better to just remove the '.' from the 
target name than fix each issue one by one.

>From e5f11b4912bb74d7d71d20fc5dc853dedd593b97 Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Wed, 14 Feb 2024 10:50:14 +0100
Subject: [PATCH] [AMDGPU] Replace '.' with '-' in generic target names

The dot is too confusing for tools. Output temporaries would have 
'10.3-generic' so tools could parse it as an extension, device libs & the 
associated clang driver logic are also confused by the dot.

After discussions, we decided it's better to just remove the '.' from the 
target name than fix each issue one by one.
---
 clang/lib/Basic/Targets/AMDGPU.cpp   |  3 +--
 clang/test/Driver/amdgpu-macros.cl   |  4 ++--
 clang/test/Driver/amdgpu-mcpu.cl |  8 
 clang/test/Misc/target-invalid-cpu-note.c|  2 +-
 llvm/docs/AMDGPUUsage.rst|  8 
 llvm/lib/Object/ELFObjectFile.cpp|  4 ++--
 llvm/lib/Target/AMDGPU/GCNProcessors.td  |  4 ++--
 llvm/lib/TargetParser/TargetParser.cpp   |  4 ++--
 .../CodeGen/AMDGPU/directive-amdgcn-target.ll| 12 ++--
 .../test/CodeGen/AMDGPU/elf-header-flags-mach.ll |  4 ++--
 .../CodeGen/AMDGPU/generic-targets-require-v6.ll | 12 ++--
 .../AMDGPU/hsa-generic-target-features.ll| 16 
 .../AMDGPU/llvm.amdgcn.image.gather4.d16.dim.ll  |  2 +-
 .../AMDGPU/llvm.amdgcn.image.sample.dim.ll   |  2 +-
 .../tools/llvm-objdump/ELF/AMDGPU/subtarget.ll   |  8 
 llvm/tools/llvm-readobj/ELFDumper.cpp|  4 ++--
 16 files changed, 48 insertions(+), 49 deletions(-)

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 10cba6b7eac5cc..5742885df0461b 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -285,10 +285,9 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions 
&Opts,
  : getArchNameR600(GPUKind));
 
   // Sanitize the name of generic targets.
-  // e.g. gfx10.1-generic -> gfx10_1_generic
+  // e.g. gfx10-1-generic -> gfx10_1_generic
   if (GPUKind >= llvm::AMDGPU::GK_AMDGCN_GENERIC_FIRST &&
   GPUKind <= llvm::AMDGPU::GK_AMDGCN_GENERIC_LAST) {
-std::replace(CanonName.begin(), CanonName.end(), '.', '_');
 std::replace(CanonName.begin(), CanonName.end(), '-', '_');
   }
 
diff --git a/clang/test/Driver/amdgpu-macros.cl 
b/clang/test/Driver/amdgpu-macros.cl
index 3b10444ef71d36..004619321b271f 100644
--- a/clang/test/Driver/amdgpu-macros.cl
+++ b/clang/test/Driver/amdgpu-macros.cl
@@ -132,8 +132,8 @@
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1201 
-DFAMILY=GFX12
 
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx9_generic 
-DFAMILY=GFX9
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_1_generic -DFAMILY=GFX10
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_3_generic -DFAMILY=GFX10
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10-1-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_1_generic -DFAMILY=GFX10
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10-3-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_3_generic -DFAMILY=GFX10
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx11_generic 
-DFAMILY=GFX11
 
 // ARCH-GCN-DAG: #define FP_FAST_FMA 1
diff --git a/clang/test/Driver/amdgpu-mcpu.cl b/clang/test/Driver/amdgpu-mcpu.cl
index 6f18ea0615cb69..915fa6473ac07f 100644
--- a/clang/test/Driver/amdgpu-mcpu.cl
+++ b/clang/test/Driver/amdgpu-mcpu.cl
@@ -116,8 +116,8 @@
 // RUN: %clang -### -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck 
--check-prefix=GFX1201 %s
 
 // RUN: %clang -### -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck 
--check-prefix=GFX9_GENERIC %s
-// RUN: %clang -### -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_1_GENERIC %s
-// RUN: %clang -### -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_3_GENERIC %s
+// RUN: %clang -### -target amdgcn -mcpu=gfx10-1-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_1_GENERIC %s
+// 

[clang] [llvm] [AMDGPU] Replace '.' with '-' in generic target names (PR #81718)

2024-02-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Pierre van Houtryve (Pierre-vh)


Changes

The dot is too confusing for tools. Output temporaries would have 
'10.3-generic' so tools could parse it as an extension, device libs & the 
associated clang driver logic are also confused by the dot.

After discussions, we decided it's better to just remove the '.' from the 
target name than fix each issue one by one.

---

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


16 Files Affected:

- (modified) clang/lib/Basic/Targets/AMDGPU.cpp (+1-2) 
- (modified) clang/test/Driver/amdgpu-macros.cl (+2-2) 
- (modified) clang/test/Driver/amdgpu-mcpu.cl (+4-4) 
- (modified) clang/test/Misc/target-invalid-cpu-note.c (+1-1) 
- (modified) llvm/docs/AMDGPUUsage.rst (+4-4) 
- (modified) llvm/lib/Object/ELFObjectFile.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/GCNProcessors.td (+2-2) 
- (modified) llvm/lib/TargetParser/TargetParser.cpp (+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll (+6-6) 
- (modified) llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll (+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/generic-targets-require-v6.ll (+6-6) 
- (modified) llvm/test/CodeGen/AMDGPU/hsa-generic-target-features.ll (+8-8) 
- (modified) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.image.gather4.d16.dim.ll 
(+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.image.sample.dim.ll (+1-1) 
- (modified) llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll (+4-4) 
- (modified) llvm/tools/llvm-readobj/ELFDumper.cpp (+2-2) 


``diff
diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 10cba6b7eac5cc..5742885df0461b 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -285,10 +285,9 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions 
&Opts,
  : getArchNameR600(GPUKind));
 
   // Sanitize the name of generic targets.
-  // e.g. gfx10.1-generic -> gfx10_1_generic
+  // e.g. gfx10-1-generic -> gfx10_1_generic
   if (GPUKind >= llvm::AMDGPU::GK_AMDGCN_GENERIC_FIRST &&
   GPUKind <= llvm::AMDGPU::GK_AMDGCN_GENERIC_LAST) {
-std::replace(CanonName.begin(), CanonName.end(), '.', '_');
 std::replace(CanonName.begin(), CanonName.end(), '-', '_');
   }
 
diff --git a/clang/test/Driver/amdgpu-macros.cl 
b/clang/test/Driver/amdgpu-macros.cl
index 3b10444ef71d36..004619321b271f 100644
--- a/clang/test/Driver/amdgpu-macros.cl
+++ b/clang/test/Driver/amdgpu-macros.cl
@@ -132,8 +132,8 @@
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1201 
-DFAMILY=GFX12
 
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx9_generic 
-DFAMILY=GFX9
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_1_generic -DFAMILY=GFX10
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_3_generic -DFAMILY=GFX10
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10-1-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_1_generic -DFAMILY=GFX10
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10-3-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_3_generic -DFAMILY=GFX10
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx11_generic 
-DFAMILY=GFX11
 
 // ARCH-GCN-DAG: #define FP_FAST_FMA 1
diff --git a/clang/test/Driver/amdgpu-mcpu.cl b/clang/test/Driver/amdgpu-mcpu.cl
index 6f18ea0615cb69..915fa6473ac07f 100644
--- a/clang/test/Driver/amdgpu-mcpu.cl
+++ b/clang/test/Driver/amdgpu-mcpu.cl
@@ -116,8 +116,8 @@
 // RUN: %clang -### -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck 
--check-prefix=GFX1201 %s
 
 // RUN: %clang -### -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck 
--check-prefix=GFX9_GENERIC %s
-// RUN: %clang -### -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_1_GENERIC %s
-// RUN: %clang -### -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_3_GENERIC %s
+// RUN: %clang -### -target amdgcn -mcpu=gfx10-1-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_1_GENERIC %s
+// RUN: %clang -### -target amdgcn -mcpu=gfx10-3-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_3_GENERIC %s
 // RUN: %clang -### -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck 
--check-prefix=GFX11_GENERIC %s
 
 // GCNDEFAULT-NOT: -target-cpu
@@ -167,6 +167,6 @@
 // GFX1201:   "-target-cpu" "gfx1201"
 
 // GFX9_GENERIC:  "-target-

[clang] [llvm] [AMDGPU] Replace '.' with '-' in generic target names (PR #81718)

2024-02-14 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-llvm-binary-utilities

Author: Pierre van Houtryve (Pierre-vh)


Changes

The dot is too confusing for tools. Output temporaries would have 
'10.3-generic' so tools could parse it as an extension, device libs & the 
associated clang driver logic are also confused by the dot.

After discussions, we decided it's better to just remove the '.' from the 
target name than fix each issue one by one.

---

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


16 Files Affected:

- (modified) clang/lib/Basic/Targets/AMDGPU.cpp (+1-2) 
- (modified) clang/test/Driver/amdgpu-macros.cl (+2-2) 
- (modified) clang/test/Driver/amdgpu-mcpu.cl (+4-4) 
- (modified) clang/test/Misc/target-invalid-cpu-note.c (+1-1) 
- (modified) llvm/docs/AMDGPUUsage.rst (+4-4) 
- (modified) llvm/lib/Object/ELFObjectFile.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/GCNProcessors.td (+2-2) 
- (modified) llvm/lib/TargetParser/TargetParser.cpp (+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll (+6-6) 
- (modified) llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll (+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/generic-targets-require-v6.ll (+6-6) 
- (modified) llvm/test/CodeGen/AMDGPU/hsa-generic-target-features.ll (+8-8) 
- (modified) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.image.gather4.d16.dim.ll 
(+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.image.sample.dim.ll (+1-1) 
- (modified) llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll (+4-4) 
- (modified) llvm/tools/llvm-readobj/ELFDumper.cpp (+2-2) 


``diff
diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 10cba6b7eac5cc..5742885df0461b 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -285,10 +285,9 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions 
&Opts,
  : getArchNameR600(GPUKind));
 
   // Sanitize the name of generic targets.
-  // e.g. gfx10.1-generic -> gfx10_1_generic
+  // e.g. gfx10-1-generic -> gfx10_1_generic
   if (GPUKind >= llvm::AMDGPU::GK_AMDGCN_GENERIC_FIRST &&
   GPUKind <= llvm::AMDGPU::GK_AMDGCN_GENERIC_LAST) {
-std::replace(CanonName.begin(), CanonName.end(), '.', '_');
 std::replace(CanonName.begin(), CanonName.end(), '-', '_');
   }
 
diff --git a/clang/test/Driver/amdgpu-macros.cl 
b/clang/test/Driver/amdgpu-macros.cl
index 3b10444ef71d36..004619321b271f 100644
--- a/clang/test/Driver/amdgpu-macros.cl
+++ b/clang/test/Driver/amdgpu-macros.cl
@@ -132,8 +132,8 @@
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1201 
-DFAMILY=GFX12
 
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx9_generic 
-DFAMILY=GFX9
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_1_generic -DFAMILY=GFX10
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_3_generic -DFAMILY=GFX10
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10-1-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_1_generic -DFAMILY=GFX10
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10-3-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_3_generic -DFAMILY=GFX10
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx11_generic 
-DFAMILY=GFX11
 
 // ARCH-GCN-DAG: #define FP_FAST_FMA 1
diff --git a/clang/test/Driver/amdgpu-mcpu.cl b/clang/test/Driver/amdgpu-mcpu.cl
index 6f18ea0615cb69..915fa6473ac07f 100644
--- a/clang/test/Driver/amdgpu-mcpu.cl
+++ b/clang/test/Driver/amdgpu-mcpu.cl
@@ -116,8 +116,8 @@
 // RUN: %clang -### -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck 
--check-prefix=GFX1201 %s
 
 // RUN: %clang -### -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck 
--check-prefix=GFX9_GENERIC %s
-// RUN: %clang -### -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_1_GENERIC %s
-// RUN: %clang -### -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_3_GENERIC %s
+// RUN: %clang -### -target amdgcn -mcpu=gfx10-1-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_1_GENERIC %s
+// RUN: %clang -### -target amdgcn -mcpu=gfx10-3-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_3_GENERIC %s
 // RUN: %clang -### -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck 
--check-prefix=GFX11_GENERIC %s
 
 // GCNDEFAULT-NOT: -target-cpu
@@ -167,6 +167,6 @@
 // G

[clang] [llvm] [transforms] Inline simple variadic functions (PR #81058)

2024-02-14 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

Why have the x86 tests been placed in test\CodeGen\X86 instead of something 
like test\Transforms\ExpandVariadics\X86 ?

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


[clang] [flang] [clang][flang][driver] Correct program names in option group descriptions (PR #81726)

2024-02-14 Thread David Spickett via cfe-commits

https://github.com/DavidSpickett created 
https://github.com/llvm/llvm-project/pull/81726

Currently https://flang.llvm.org/docs/FlangCommandLineReference.html refers to 
"Clang" in several of the group descriptions for example:
```
Compilation options

Flags controlling the behavior of Clang during compilation...
```

This is pretty confusing. I'm fixing this by making use of `Program` from the 
existing GlobalDocumentation object to substitute in the program name to these 
descriptions.

This `Program` has been changed to a proper noun given that it's easier to 
lower case a string than capitalise one character (syntax wise). The tablegen 
backend has been changed to lower it so that links in the RST/HTML remain the 
same as they were before.

To make sure the file is valid when not generating docs, I'm checking a #define 
and providing a default GlobalDocumentation if it's not defined. (I looked for 
a way to check if a def exists, but tablegen doesn't seem to have one)

This means that if the DocBrief are used outside of documentation, they'll say 
"Clang", which is the same as it always was.

This change does not aim fix option descriptions that refer to clang. Though we 
can use parts of this for that, there is only one driver library so it needs a 
different approach.

>From 74fe9a47aecac7f7d16485d11781c9cc92229429 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Wed, 14 Feb 2024 11:20:51 +
Subject: [PATCH] [clang][flang][driver] Correct program names in option group
 descriptions

Currently https://flang.llvm.org/docs/FlangCommandLineReference.html
refers to "Clang" in several of the group descriptions for example:
```
Compilation options

Flags controlling the behavior of Clang during compilation...
```

This is pretty confusing. I'm fixing this by making use of `Program` from
the existing GlobalDocumentation object to substitute in the program name
to these descriptions.

This `Program` has been changed to a proper noun given that it's easier
to lower case a string than capitalise one character (syntax wise). The
tablegen backend has been changed to lower it so that links in the RST/HTML
remain the same as they were before.

To make sure the file is valid when not generating docs, I'm checking
a #define and providing a default GlobalDocumentation if it's not defined.
(I looked for a way to check if a def exists, but tablegen doesn't seem
to have one)

This means that if the DocBrief are used outside of documentation, they'll
say "Clang", which is the same as it always was.

This change does not aim fix option descriptions that refer to clang.
Though we can use parts of this for that, there is only one driver library
so it needs a different approach.
---
 clang/include/clang/Driver/ClangOptionDocs.td |  3 +-
 clang/include/clang/Driver/Options.td | 37 +++
 .../utils/TableGen/ClangOptionDocEmitter.cpp  |  9 +++--
 flang/docs/FlangOptionsDocs.td|  4 +-
 4 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Driver/ClangOptionDocs.td 
b/clang/include/clang/Driver/ClangOptionDocs.td
index a5ee577c5f45db..dea6a7ccb12c9a 100644
--- a/clang/include/clang/Driver/ClangOptionDocs.td
+++ b/clang/include/clang/Driver/ClangOptionDocs.td
@@ -27,11 +27,12 @@ GCC-compatible ``clang`` and ``clang++`` drivers.
 
 }];
 
-  string Program = "clang";
+  string Program = "Clang";
   // Note: We *must* use DefaultVis and not ClangOption, since that's
   // the name of the actual TableGen record. The alias will not work.
   list VisibilityMask = ["DefaultVis"];
   list IgnoreFlags = ["HelpHidden", "Unsupported", "Ignored"];
 }
 
+#define GENERATING_DOCS
 include "Options.td"
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 95b464e7d61834..375ea6f5f6979c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -13,6 +13,25 @@
 // Include the common option parsing interfaces.
 include "llvm/Option/OptParser.td"
 
+// When generating documentation, we expect there to be a GlobalDocumentation
+// def containing the program name that we are generating documentation for.
+// This object should only be used by things that are used in documentation,
+// such as the group descriptions.
+#ifndef GENERATING_DOCS
+// So that this file can still be parsed without such a def, define one if 
there
+// isn't one provided.
+def GlobalDocumentation {
+  // Sensible default in case of mistakes.
+  string Program = "Clang";
+}
+#endif
+
+// Use this to generate program specific documentation, for example:
+// StringForProgram<"Control how %Program behaves.">.str
+class StringForProgram {
+  string str = !subst("%Program", GlobalDocumentation.Program, _str);
+}
+
 /
 // Flags
 
@@ -100,14 +119,16 @@ def Action_Group : OptionGroup<"">, 
DocName<"Actions">,
 // Meta-group for options which are only used for compilation,
 // and not linking etc.
 def CompileOnly_Group : 

[clang] [flang] [clang][flang][driver] Correct program names in option group descriptions (PR #81726)

2024-02-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David Spickett (DavidSpickett)


Changes

Currently https://flang.llvm.org/docs/FlangCommandLineReference.html refers to 
"Clang" in several of the group descriptions for example:
```
Compilation options

Flags controlling the behavior of Clang during compilation...
```

This is pretty confusing. I'm fixing this by making use of `Program` from the 
existing GlobalDocumentation object to substitute in the program name to these 
descriptions.

This `Program` has been changed to a proper noun given that it's easier to 
lower case a string than capitalise one character (syntax wise). The tablegen 
backend has been changed to lower it so that links in the RST/HTML remain the 
same as they were before.

To make sure the file is valid when not generating docs, I'm checking a #define 
and providing a default GlobalDocumentation if it's not defined. (I looked for 
a way to check if a def exists, but tablegen doesn't seem to have one)

This means that if the DocBrief are used outside of documentation, they'll say 
"Clang", which is the same as it always was.

This change does not aim fix option descriptions that refer to clang. Though we 
can use parts of this for that, there is only one driver library so it needs a 
different approach.

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


4 Files Affected:

- (modified) clang/include/clang/Driver/ClangOptionDocs.td (+2-1) 
- (modified) clang/include/clang/Driver/Options.td (+29-8) 
- (modified) clang/utils/TableGen/ClangOptionDocEmitter.cpp (+5-4) 
- (modified) flang/docs/FlangOptionsDocs.td (+2-2) 


``diff
diff --git a/clang/include/clang/Driver/ClangOptionDocs.td 
b/clang/include/clang/Driver/ClangOptionDocs.td
index a5ee577c5f45db..dea6a7ccb12c9a 100644
--- a/clang/include/clang/Driver/ClangOptionDocs.td
+++ b/clang/include/clang/Driver/ClangOptionDocs.td
@@ -27,11 +27,12 @@ GCC-compatible ``clang`` and ``clang++`` drivers.
 
 }];
 
-  string Program = "clang";
+  string Program = "Clang";
   // Note: We *must* use DefaultVis and not ClangOption, since that's
   // the name of the actual TableGen record. The alias will not work.
   list VisibilityMask = ["DefaultVis"];
   list IgnoreFlags = ["HelpHidden", "Unsupported", "Ignored"];
 }
 
+#define GENERATING_DOCS
 include "Options.td"
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 95b464e7d61834..375ea6f5f6979c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -13,6 +13,25 @@
 // Include the common option parsing interfaces.
 include "llvm/Option/OptParser.td"
 
+// When generating documentation, we expect there to be a GlobalDocumentation
+// def containing the program name that we are generating documentation for.
+// This object should only be used by things that are used in documentation,
+// such as the group descriptions.
+#ifndef GENERATING_DOCS
+// So that this file can still be parsed without such a def, define one if 
there
+// isn't one provided.
+def GlobalDocumentation {
+  // Sensible default in case of mistakes.
+  string Program = "Clang";
+}
+#endif
+
+// Use this to generate program specific documentation, for example:
+// StringForProgram<"Control how %Program behaves.">.str
+class StringForProgram {
+  string str = !subst("%Program", GlobalDocumentation.Program, _str);
+}
+
 /
 // Flags
 
@@ -100,14 +119,16 @@ def Action_Group : OptionGroup<"">, 
DocName<"Actions">,
 // Meta-group for options which are only used for compilation,
 // and not linking etc.
 def CompileOnly_Group : OptionGroup<"">,
-DocName<"Compilation options">, DocBrief<[{
-Flags controlling the behavior of Clang during compilation. These flags have
-no effect during actions that do not perform compilation.}]>;
+DocName<"Compilation options">,
+DocBrief.str>;
 
 def Preprocessor_Group : OptionGroup<"">,
  Group,
- DocName<"Preprocessor options">, DocBrief<[{
-Flags controlling the behavior of the Clang preprocessor.}]>;
+ DocName<"Preprocessor options">,
+ DocBrief.str>;
 
 def IncludePath_Group : OptionGroup<"">, Group,
 DocName<"Include path management">,
@@ -128,9 +149,9 @@ def d_Group : OptionGroup<"">, 
Group,
 Flags allowing the state of the preprocessor to be dumped in various ways.}]>;
 
 def Diag_Group : OptionGroup<"">, Group,
- DocName<"Diagnostic options">, DocBrief<[{
-Flags controlling which warnings, errors, and remarks Clang will generate.
-See the :doc:`full list of warning and remark flags 
`.}]>;
+ DocName<"Diagnostic options">, DocBrief`.}]>.str>;
 
 def R_Group : OptionGroup<"">, Group, DocFlatten;
 def R_value_Group : OptionGroup<"">, Group,
diff --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp 

[clang] [flang] [clang][flang][driver] Correct program names in option group descriptions (PR #81726)

2024-02-14 Thread David Spickett via cfe-commits

DavidSpickett wrote:

To add program specific option help, my idea is to store mutliple strings in 
the driver and select based on who's asking for the help.

I think that warrants its own change so I'm not attempting that here. Also, 
there's only 2 flang options that refer to clang so it's not the priority here.

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


[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV ba… (PR #81727)

2024-02-14 Thread Garvit Gupta via cfe-commits

https://github.com/quic-garvgupt created 
https://github.com/llvm/llvm-project/pull/81727

The below culprit patch enabled the generation of asynchronous unwind tables 
(-funwind-tables=2) by default for RISCV for both linux and RISCVToolChain 
baremetal object. However, since there are 2 baremetal toolchain objects for 
RISCV, this created a discrepancy between their behavior. Moreover, enabling 
the generation of asynchronous unwind tables based on whether `-gcc-toolchain` 
option is present or not doesn't seem to be the best criteria to decide on the 
same. This patch make the behavior consistent by disabling the unwind tables in 
RISCVToolChain Baremetal object.

Culprit Patch - https://reviews.llvm.org/D145164


>From 42211bccd8ffc60751234ab5695be135ea8b6373 Mon Sep 17 00:00:00 2001
From: Garvit Gupta 
Date: Wed, 14 Feb 2024 03:00:20 -0800
Subject: [PATCH] [RISCV] Disable generation of asynchronous unwind tables for
 RISCV baremetal

The below culprit patch enabled the generation of asynchronous unwind tables
(-funwind-tables=2) by default for RISCV for both linux and RISCVToolChain
baremetal object. However, since there are 2 baremetal toolchain objects for
RISCV, this created a discrepancy between their behavior. Moreover, enabling
the generation of asynchronous unwind tables based on whether `-gcc-toolchain`
option is present or not doesn't seem to be the best criteria to decide on
the same.

Culprit Patch - https://reviews.llvm.org/D145164
---
 clang/lib/Driver/ToolChains/RISCVToolchain.cpp | 5 +
 clang/lib/Driver/ToolChains/RISCVToolchain.h   | 2 ++
 clang/test/Driver/clang-translation.c  | 8 
 3 files changed, 15 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index 85beb945cbf6fc..624099d21ae124 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -86,6 +86,11 @@ RISCVToolChain::GetUnwindLibType(const llvm::opt::ArgList 
&Args) const {
   return ToolChain::UNW_None;
 }
 
+ToolChain::UnwindTableLevel RISCVToolChain::getDefaultUnwindTableLevel(
+const llvm::opt::ArgList &Args) const {
+  return UnwindTableLevel::None;
+}
+
 void RISCVToolChain::addClangTargetOptions(
 const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args,
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h 
b/clang/lib/Driver/ToolChains/RISCVToolchain.h
index cec817ef7190be..fa0aa265d842bb 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.h
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h
@@ -28,6 +28,8 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public 
Generic_ELF {
   RuntimeLibType GetDefaultRuntimeLibType() const override;
   UnwindLibType
   GetUnwindLibType(const llvm::opt::ArgList &Args) const override;
+  UnwindTableLevel
+  getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override;
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args) const override;
diff --git a/clang/test/Driver/clang-translation.c 
b/clang/test/Driver/clang-translation.c
index a7343ea18b2135..64d55f1b88ea6d 100644
--- a/clang/test/Driver/clang-translation.c
+++ b/clang/test/Driver/clang-translation.c
@@ -421,3 +421,11 @@
 // MIPSN32R6EL: "-target-cpu" "mips64r6"
 // MIPSN32R6EL: "-target-abi" "n32"
 // MIPSN32R6EL: "-mfloat-abi" "hard"
+
+// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -### %s 2>&1 | 
FileCheck %s -check-prefix=NOUWTABLE
+// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" 
-fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE
+// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -### %s 2>&1 | 
FileCheck %s -check-prefix=NOUWTABLE
+// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" 
-fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE
+//
+// UWTABLE: "-funwind-tables=2"
+// NOUWTABLE-NOT: "-funwind-tables=2"
\ No newline at end of file

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


[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV ba… (PR #81727)

2024-02-14 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV ba… (PR #81727)

2024-02-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Garvit Gupta (quic-garvgupt)


Changes

The below culprit patch enabled the generation of asynchronous unwind tables 
(-funwind-tables=2) by default for RISCV for both linux and RISCVToolChain 
baremetal object. However, since there are 2 baremetal toolchain objects for 
RISCV, this created a discrepancy between their behavior. Moreover, enabling 
the generation of asynchronous unwind tables based on whether `-gcc-toolchain` 
option is present or not doesn't seem to be the best criteria to decide on the 
same. This patch make the behavior consistent by disabling the unwind tables in 
RISCVToolChain Baremetal object.

Culprit Patch - https://reviews.llvm.org/D145164


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


3 Files Affected:

- (modified) clang/lib/Driver/ToolChains/RISCVToolchain.cpp (+5) 
- (modified) clang/lib/Driver/ToolChains/RISCVToolchain.h (+2) 
- (modified) clang/test/Driver/clang-translation.c (+8) 


``diff
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index 85beb945cbf6fc..624099d21ae124 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -86,6 +86,11 @@ RISCVToolChain::GetUnwindLibType(const llvm::opt::ArgList 
&Args) const {
   return ToolChain::UNW_None;
 }
 
+ToolChain::UnwindTableLevel RISCVToolChain::getDefaultUnwindTableLevel(
+const llvm::opt::ArgList &Args) const {
+  return UnwindTableLevel::None;
+}
+
 void RISCVToolChain::addClangTargetOptions(
 const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args,
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h 
b/clang/lib/Driver/ToolChains/RISCVToolchain.h
index cec817ef7190be..fa0aa265d842bb 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.h
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h
@@ -28,6 +28,8 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public 
Generic_ELF {
   RuntimeLibType GetDefaultRuntimeLibType() const override;
   UnwindLibType
   GetUnwindLibType(const llvm::opt::ArgList &Args) const override;
+  UnwindTableLevel
+  getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override;
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args) const override;
diff --git a/clang/test/Driver/clang-translation.c 
b/clang/test/Driver/clang-translation.c
index a7343ea18b2135..64d55f1b88ea6d 100644
--- a/clang/test/Driver/clang-translation.c
+++ b/clang/test/Driver/clang-translation.c
@@ -421,3 +421,11 @@
 // MIPSN32R6EL: "-target-cpu" "mips64r6"
 // MIPSN32R6EL: "-target-abi" "n32"
 // MIPSN32R6EL: "-mfloat-abi" "hard"
+
+// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -### %s 2>&1 | 
FileCheck %s -check-prefix=NOUWTABLE
+// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" 
-fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE
+// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -### %s 2>&1 | 
FileCheck %s -check-prefix=NOUWTABLE
+// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" 
-fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE
+//
+// UWTABLE: "-funwind-tables=2"
+// NOUWTABLE-NOT: "-funwind-tables=2"
\ No newline at end of file

``




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


[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV ba… (PR #81727)

2024-02-14 Thread Garvit Gupta via cfe-commits

quic-garvgupt wrote:

Hi
@jonathonpenix  @apazos @kito-cheng @asb @MaskRay - Requesting for adding as 
reviewers to review the PR. Thanks in advance!

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


[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)

2024-02-14 Thread Yingwei Zheng via cfe-commits

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


[clang] [Clang][CodeGen] Loose the cast check when emitting builtins (PR #81669)

2024-02-14 Thread Pierre van Houtryve via cfe-commits

Pierre-vh wrote:

> > Sorry, I should have clearly mentioned that. Yes, it is for my followup 
> > change #80908. In #80908, we changed the type of LLVM builtin but kept the 
> > corresponding clang builtin unchanged to avoid breaking existing uses.
> 
> Don't see how that could be related; you can losslessly bitconvert between 
> i16 and bfloat

I guess it's an oversight from that function to not allow FP <-> INT casts when 
they have the same width?
It seems like it'd let `<4 x i16>` to  `<4 x bf16>` pass.

I think the right fix is teaching that function about FP <-> INT casts. 
What do you think @nikic ?



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


[clang] [compiler-rt] [asan][windows] Eliminate the static asan runtime on windows (PR #81677)

2024-02-14 Thread Tobias Hieta via cfe-commits

tru wrote:

cc @sylvain-audi 

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


[clang] [clang][NFC] Use "notable" for "interesting" identifiers in `IdentifierInfo` (PR #81542)

2024-02-14 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang][NFC] Use "notable" for "interesting" identifiers in `IdentifierInfo` (PR #81542)

2024-02-14 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 5027569 - [clang][NFC] Use "notable" for "interesting" identifiers in `IdentifierInfo` (#81542)

2024-02-14 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-14T16:39:00+04:00
New Revision: 502756905c7de5f6217a071b73adda72c46ffd1c

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

LOG: [clang][NFC] Use "notable" for "interesting" identifiers in 
`IdentifierInfo` (#81542)

This patch expands notion of "interesting" in `IdentifierInto` it to
also cover ObjC keywords and builtins, which matches notion of
"interesting" in serialization layer. What was previously "interesting"
in `IdentifierInto` is now called "notable".

Beyond clearing confusion between serialization and the rest of the
compiler, it also resolved a naming problem: ObjC keywords, notable
identifiers, and builtin IDs are all stored in the same bit-field. Now
we can use "interesting" to name it and its corresponding type, instead
of `ObjCKeywordOrInterestingOrBuiltin` abomination.

Added: 


Modified: 
clang/include/clang/Basic/IdentifierTable.h
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Basic/TokenKinds.h
clang/lib/Basic/IdentifierTable.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index fa8969eb73ddbf..a091639bfa2542 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -84,28 +84,28 @@ using IdentifierLocPair = std::pair;
 /// of a pointer to one of these classes.
 enum { IdentifierInfoAlignment = 8 };
 
-static constexpr int ObjCOrBuiltinIDBits = 16;
+static constexpr int InterestingIdentifierBits = 16;
 
-/// The "layout" of ObjCOrBuiltinID is:
+/// The "layout" of InterestingIdentifier is:
 ///  - ObjCKeywordKind enumerators
-///  - InterestingIdentifierKind enumerators
+///  - NotableIdentifierKind enumerators
 ///  - Builtin::ID enumerators
-///  - NonSpecialIdentifier
-enum class ObjCKeywordOrInterestingOrBuiltin {
+///  - NotInterestingIdentifier
+enum class InterestingIdentifier {
 #define OBJC_AT_KEYWORD(X) objc_##X,
 #include "clang/Basic/TokenKinds.def"
   NUM_OBJC_KEYWORDS,
 
-#define INTERESTING_IDENTIFIER(X) X,
+#define NOTABLE_IDENTIFIER(X) X,
 #include "clang/Basic/TokenKinds.def"
-  NUM_OBJC_KEYWORDS_AND_INTERESTING_IDENTIFIERS,
+  NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS,
 
   NotBuiltin,
 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
 #include "clang/Basic/Builtins.inc"
   FirstTSBuiltin,
 
-  NonSpecialIdentifier = 65534
+  NotInterestingIdentifier = 65534
 };
 
 /// One of these records is kept for each identifier that
@@ -121,8 +121,8 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   LLVM_PREFERRED_TYPE(tok::TokenKind)
   unsigned TokenID : 9;
 
-  LLVM_PREFERRED_TYPE(ObjCKeywordOrInterestingOrBuiltin)
-  unsigned ObjCOrBuiltinID : ObjCOrBuiltinIDBits;
+  LLVM_PREFERRED_TYPE(InterestingIdentifier)
+  unsigned InterestingIdentifierID : InterestingIdentifierBits;
 
   // True if there is a #define for this.
   LLVM_PREFERRED_TYPE(bool)
@@ -205,8 +205,8 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
 
   IdentifierInfo()
   : TokenID(tok::identifier),
-ObjCOrBuiltinID(llvm::to_underlying(
-ObjCKeywordOrInterestingOrBuiltin::NonSpecialIdentifier)),
+InterestingIdentifierID(llvm::to_underlying(
+InterestingIdentifier::NotInterestingIdentifier)),
 HasMacro(false), HadMacro(false), IsExtension(false),
 IsFutureCompatKeyword(false), IsPoisoned(false),
 IsCPPOperatorKeyword(false), NeedsHandleIdentifier(false),
@@ -341,71 +341,63 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   ///
   /// For example, 'class' will return tok::objc_class if ObjC is enabled.
   tok::ObjCKeywordKind getObjCKeywordID() const {
-assert(0 == llvm::to_underlying(
-ObjCKeywordOrInterestingOrBuiltin::objc_not_keyword));
-auto Value =
-static_cast(ObjCOrBuiltinID);
-if (Value < ObjCKeywordOrInterestingOrBuiltin::NUM_OBJC_KEYWORDS)
-  return static_cast(ObjCOrBuiltinID);
+assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
+auto Value = static_cast(InterestingIdentifierID);
+if (Value < InterestingIdentifier::NUM_OBJC_KEYWORDS)
+  return static_cast(InterestingIdentifierID);
 return tok::objc_not_keyword;
   }
   void setObjCKeywordID(tok::ObjCKeywordKind ID) {
-assert(0 == llvm::to_underlying(
-ObjCKeywordOrInterestingOrBuiltin::objc_not_keyword));
-ObjCOrBuiltinID = ID;
+assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
+InterestingIdentifierID = ID;
 assert(getObjCKeywordID() == ID && "ID too large for field!");
   }
 

[clang] [flang] [clang][flang][driver] Correct program names in option group descriptions (PR #81726)

2024-02-14 Thread David Spickett via cfe-commits

DavidSpickett wrote:

@llvm/pr-subscribers-flang-driver 

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


[clang] c5e1384 - [clang][docs] Remove trailing whitespace

2024-02-14 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2024-02-14T12:51:30Z
New Revision: c5e13840fdc20adce51673a63d5703bf1ed02aba

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

LOG: [clang][docs] Remove trailing whitespace

Which is causing CI checks to fail.

clang/docs/LanguageExtensions.rst:2794:takes no arguments and produces an 
unsigned long long result. The builtin does
clang/docs/LanguageExtensions.rst:2795:not guarantee any particular frequency, 
only that it is stable. Knowledge of the
+ echo '*** Trailing whitespace has been found in Clang source files as 
described above ***'

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index ee1d25396ca865..1db80262b8fb8e 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2791,8 +2791,8 @@ frequency is fixed, making it suitable for measuring 
elapsed time.
 
 The ``__builtin_readsteadycounter()`` builtin returns the frequency counter 
value.
 When not supported by the target, the return value is always zero. This builtin
-takes no arguments and produces an unsigned long long result. The builtin does 
-not guarantee any particular frequency, only that it is stable. Knowledge of 
the 
+takes no arguments and produces an unsigned long long result. The builtin does
+not guarantee any particular frequency, only that it is stable. Knowledge of 
the
 counter's true frequency will need to be provided by the user.
 
 Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``.



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


[clang] [flang] [clang][flang][driver] Correct program names in option group descriptions (PR #81726)

2024-02-14 Thread Kiran Chandramohan via cfe-commits

kiranchandramohan wrote:

Unrelated, but just wanted to bring this up since you are working in this area 
and distinguishing between Flang and Clang. Flang does not generate the 
Diagnostics Reference and hence ends up with the warning (see below) in the 
docs CI (https://lab.llvm.org/buildbot/#/builders/89/builds/57357). Is it 
possible to conditionally mention this in the FlangCommandLineReference?

/home/buildbot/as-worker-4/publish-sphinx-docs/build/tools/flang/docs/Source/FlangCommandLineReference.rst:194:
 WARNING: unknown document: 'DiagnosticsReference'


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


[clang] [Clang][CodeGen] Loose the cast check when emitting builtins (PR #81669)

2024-02-14 Thread Nikita Popov via cfe-commits

nikic wrote:

> I think the right fix is teaching that function about FP <-> INT casts.

The documentation for that function says:
```
  /// Return true if this type could be converted with a lossless BitCast to
  /// type 'Ty'. For example, i8* to i32*. BitCasts are valid for types of the
  /// same size only where no re-interpretation of the bits is done.
```
A cast between float and int sounds like "re-interpretation of the bits" to me. 
Though the function already allows it if it's a vector of int/float.

TBH I don't really understand what the purpose of this function is. One of the 
main uses seems to be to restrict what the `returned` attribute can be used 
for, but in that case we probably should stop accepting casts at all -- these 
don't really seem useful, and we've had crashes/miscompiles due to allowing 
them in the past.

For the purposes of this specific change, I think that just dropping the assert 
is indeed the right thing to do. The cast in the bitcast itself is sufficient.

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


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-14 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/81611

>From 7ee4b35f0aed434053b6fd6329ef39de97bc22db Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 13 Feb 2024 23:50:15 +0900
Subject: [PATCH 1/4] [clang-format] Support of TableGen basic format
 restrictions.

- Allow/force to break the line or not.
- Allow to insert space or not.
---
 clang/lib/Format/ContinuationIndenter.cpp |  14 +-
 clang/lib/Format/TokenAnnotator.cpp   |  56 
 clang/unittests/Format/FormatTestTableGen.cpp | 263 ++
 3 files changed, 331 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..1879af94f6da49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d353388a862b56..636d098881c97e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::greater) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires space before '{' or ':', the case in name 
values.
+// Not before ';', the case in normal values.
+   

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-14 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/81611

>From 7ee4b35f0aed434053b6fd6329ef39de97bc22db Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 13 Feb 2024 23:50:15 +0900
Subject: [PATCH 1/4] [clang-format] Support of TableGen basic format
 restrictions.

- Allow/force to break the line or not.
- Allow to insert space or not.
---
 clang/lib/Format/ContinuationIndenter.cpp |  14 +-
 clang/lib/Format/TokenAnnotator.cpp   |  56 
 clang/unittests/Format/FormatTestTableGen.cpp | 263 ++
 3 files changed, 331 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..1879af94f6da49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d353388a862b56..636d098881c97e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::greater) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires space before '{' or ':', the case in name 
values.
+// Not before ';', the case in normal values.
+   

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-14 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 ea8de6e4336cf82aa541c6ad951b62585c3ea55c 
43ad7755bf78df4141baf53dad977379482d1e94 -- 
clang/lib/Format/ContinuationIndenter.cpp clang/lib/Format/TokenAnnotator.cpp 
clang/unittests/Format/FormatTestTableGen.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/unittests/Format/FormatTestTableGen.cpp 
b/clang/unittests/Format/FormatTestTableGen.cpp
index 72df48644e..675e88d6e5 100644
--- a/clang/unittests/Format/FormatTestTableGen.cpp
+++ b/clang/unittests/Format/FormatTestTableGen.cpp
@@ -126,7 +126,8 @@ TEST_F(FormatTestTableGen, SimpleValue1_MultilineString) {
   std::string DefWithCodeMessedUp =
   "def SimpleValueCode {  let  \n"
   "Code=   \n"
-  "   [{ A TokCode is  nothing more than a multi-line string 
literal "
+  "   [{ A TokCode is  nothing more than a multi-line string "
+  "literal "
   "delimited by \\[{ and }\\]. It  can break across lines and the line "
   "breaks are retained in the string. \n"
   "(https://llvm.org/docs/TableGen/ProgRef.html#grammar-token-TokCode)}] 
\n"

``




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


[clang] [flang] [clang][flang][driver] Correct program names in option group descriptions (PR #81726)

2024-02-14 Thread David Spickett via cfe-commits

DavidSpickett wrote:

Yes I had to disable sphix -Werr for that, I will try to fix it.

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


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-14 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/81611

>From 7ee4b35f0aed434053b6fd6329ef39de97bc22db Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 13 Feb 2024 23:50:15 +0900
Subject: [PATCH 1/5] [clang-format] Support of TableGen basic format
 restrictions.

- Allow/force to break the line or not.
- Allow to insert space or not.
---
 clang/lib/Format/ContinuationIndenter.cpp |  14 +-
 clang/lib/Format/TokenAnnotator.cpp   |  56 
 clang/unittests/Format/FormatTestTableGen.cpp | 263 ++
 3 files changed, 331 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..1879af94f6da49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d353388a862b56..636d098881c97e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::greater) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires space before '{' or ':', the case in name 
values.
+// Not before ';', the case in normal values.
+   

[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-02-14 Thread Axel Lundberg via cfe-commits


@@ -122,6 +122,26 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
+- ``-fsanitize=implicit-unsigned-bitfield-truncation`` catches implicit
+  unsigned conversions involving bitfields.
+- ``-fsanitize=implicit-signed-bitfield-truncation`` catches implicit
+  signed conversions involving bitfields.
+- ``-fsanitize=implicit-bitfield-sign-change`` catches implicit
+  conversions involving bitfields that result in a sign change.
+- ``-fsanitize=implicit-bitfield-truncation`` a group to include both
+  ``-fsanitize=implicit-unsigned-bitfield-truncation`` and
+  ``-fsanitize=implicit-signed-bitfield-truncation``.
+- ``-fsanitize=implicit-bitfield-arithmetic-value-change`` a group to
+  include both ``implicit-signed-bitfield-truncation`` and
+  ``implicit-bitfield-sign-change``.
+- ``-fsanitize=implicit-bitfield-conversion`` a group to include
+  ``-fsanitize=implicit-unsigned-bitfield-truncation``,
+  ``-fsanitize=implicit-signed-bitfield-truncation`` and
+  ``implicit-bitfield-sign-change``.
+- ``-fsanitize=implicit-integer-conversion`` a group to include
+  ``-fsanitize=implicit-unsigned-integer-truncation``,
+  ``-fsanitize=implicit-signed-integer-truncation`` and
+  ``implicit-integer-sign-change``.

Zonotora wrote:

This was my first thought as well, it just seemed intuitive to use the same 
flags as for integer conversion. I think all checks included in 
`implicit-conversion` are not UB. Anyway, I will revert to only having 
`-fsanitize=implicit-bitfield-conversion`!

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


[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-02-14 Thread Axel Lundberg via cfe-commits


@@ -5570,11 +5570,44 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const 
BinaryOperator *E) {
   break;
 }
 
-RValue RV = EmitAnyExpr(E->getRHS());
+llvm::Value *Previous = nullptr;
+RValue RV;
+QualType SrcType = E->getRHS()->getType();
+// If LHS refers to a bitfield we want to retrieve the value before
+// implicit conversion between the bitfield type and the RHS type
+// and evaluate RHS without integer sanitizer checks (if passed)
+if (auto *ICE = RetrieveImplicitCastExprForBitfieldSanitizer(E)) {

Zonotora wrote:

Sounds good!

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


[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-02-14 Thread Axel Lundberg via cfe-commits


@@ -1097,6 +1112,27 @@ void ScalarExprEmitter::EmitIntegerTruncationCheck(Value 
*Src, QualType SrcType,
 {Src, Dst});
 }
 
+static llvm::Value *EmitIsNegativeTestHelper(Value *V, QualType VType,
+ const char *Name,
+ CGBuilderTy &Builder) {
+  // NOTE: zero value is considered to be non-negative.

Zonotora wrote:

Leftover comment from previous patches, will update.

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


[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-02-14 Thread Axel Lundberg via cfe-commits


@@ -1097,6 +1112,27 @@ void ScalarExprEmitter::EmitIntegerTruncationCheck(Value 
*Src, QualType SrcType,
 {Src, Dst});
 }
 
+static llvm::Value *EmitIsNegativeTestHelper(Value *V, QualType VType,
+ const char *Name,
+ CGBuilderTy &Builder) {
+  // NOTE: zero value is considered to be non-negative.
+  // Is this value a signed type?
+  bool VSigned = VType->isSignedIntegerOrEnumerationType();
+  llvm::Type *VTy = V->getType();
+  if (!VSigned) {
+// If the value is unsigned, then it is never negative.
+// FIXME: can we encounter non-scalar VTy here?

Zonotora wrote:

Leftover comment from previous patches, will update.

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


[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-02-14 Thread Axel Lundberg via cfe-commits


@@ -1035,7 +1050,7 @@ EmitIntegerTruncationCheckHelper(Value *Src, QualType 
SrcType, Value *Dst,
   }
 
   llvm::Value *Check = nullptr;
-  // 1. Extend the truncated value back to the same width as the Src.
+  // 1. Convert the Dst back to the same type as Src.

Zonotora wrote:

You are correct 😃

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


[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-02-14 Thread Axel Lundberg via cfe-commits


@@ -324,6 +326,19 @@ class ScalarExprEmitter
   void EmitIntegerSignChangeCheck(Value *Src, QualType SrcType, Value *Dst,
   QualType DstType, SourceLocation Loc);
 
+  /// Emit a check that an [implicit] truncation of a bitfield does not
+  /// discard any bits. It is not UB, so we use the value after truncation.

Zonotora wrote:

👍

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


[clang] [llvm] [clang] Add fixed point precision macros (PR #81207)

2024-02-14 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,67 @@
+/// Assert the fixed point precision macros according to N1169 7.18a.3 are
+/// defined when -ffixed-point is provided.
+
+// RUN: %clang_cc1 -triple=x86_64 -E -dM -ffixed-point -x c < /dev/null | 
FileCheck -match-full-lines %s
+// RUN: %clang_cc1 -triple=x86_64 -E -dM -ffixed-point -x c++ < /dev/null | 
FileCheck -match-full-lines %s
+
+/// These are the implementation-defined values for x86_64.
+// CHECK-DAG:#define __SFRACT_EPSILON__ 0.0078125hr
+// CHECK-DAG:#define __SFRACT_FBIT__ 7
+// CHECK-DAG:#define __SFRACT_MAX__ 0.9921875hr
+// CHECK-DAG:#define __SFRACT_MIN__ (-0.5hr-0.5hr)
+
+// CHECK-DAG:#define __USFRACT_EPSILON__ 0.00390625uhr
+// CHECK-DAG:#define __USFRACT_FBIT__ 8
+// CHECK-DAG:#define __USFRACT_MAX__ 0.99609375uhr

AaronBallman wrote:

I understood that they were implementation-defined, but I had missed we were 
pulling the values from `A.3`. Thanks for the explanation!

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


[clang] [llvm] [clang] Add fixed point precision macros (PR #81207)

2024-02-14 Thread Aaron Ballman via cfe-commits

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


[clang] [llvm] [clang] Add fixed point precision macros (PR #81207)

2024-02-14 Thread Aaron Ballman via cfe-commits


@@ -297,6 +297,12 @@ DWARF Support in Clang
 Floating Point Support in Clang
 ---
 
+Fixed Point Support in Clang
+---

AaronBallman wrote:

```suggestion
Fixed Point Support in Clang
-
```


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


[clang] [llvm] [clang] Add fixed point precision macros (PR #81207)

2024-02-14 Thread Aaron Ballman via cfe-commits

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

Aside from a minor nit with the documentation, LGTM!

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


[clang] [C23] Do not diagnose binary literals as an extension (PR #81658)

2024-02-14 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> We could consider keeping the warning group, not actually guarding any 
> warning, so we don't warn on `-Wno-gnu-binary-literal`.

That's a good idea, I've done that and updated the release notes accordingly.

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


[clang] [C23] Do not diagnose binary literals as an extension (PR #81658)

2024-02-14 Thread Aaron Ballman via cfe-commits

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


[clang] [llvm] [MC/DC] Refactor: Introduce `ConditionIDs` as `std::array<2>` (PR #81221)

2024-02-14 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/81221

>From 66bb6cc3fd339360c16c6a98ce08f34978f665e0 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 9 Feb 2024 07:56:51 +0900
Subject: [PATCH 1/4] [MC/DC] Refactor: Introduce `ConditionIDs` as
 `std::array<2>`

Its 0th element corresponds to `FalseID` and 1st to `TrueID`.

CoverageMappingGen.cpp: `DecisionIDPair` is replaced with `ConditionIDs`
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 50 +++
 .../ProfileData/Coverage/CoverageMapping.h|  9 ++--
 .../ProfileData/Coverage/CoverageMapping.cpp  | 31 ++--
 .../Coverage/CoverageMappingReader.cpp|  7 +--
 .../Coverage/CoverageMappingWriter.cpp|  4 +-
 .../ProfileData/CoverageMappingTest.cpp   | 24 -
 6 files changed, 56 insertions(+), 69 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 0c43317642bca4..54559af47e63dc 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -95,7 +95,6 @@ void CoverageSourceInfo::updateNextTokLoc(SourceLocation Loc) 
{
 }
 
 namespace {
-using MCDCConditionID = CounterMappingRegion::MCDCConditionID;
 using MCDCParameters = CounterMappingRegion::MCDCParameters;
 
 /// A region of source code that can be mapped to a counter.
@@ -586,11 +585,6 @@ struct EmptyCoverageMappingBuilder : public 
CoverageMappingBuilder {
 /// creation.
 struct MCDCCoverageBuilder {
 
-  struct DecisionIDPair {
-MCDCConditionID TrueID = 0;
-MCDCConditionID FalseID = 0;
-  };
-
   /// The AST walk recursively visits nested logical-AND or logical-OR binary
   /// operator nodes and then visits their LHS and RHS children nodes.  As this
   /// happens, the algorithm will assign IDs to each operator's LHS and RHS 
side
@@ -681,14 +675,14 @@ struct MCDCCoverageBuilder {
 private:
   CodeGenModule &CGM;
 
-  llvm::SmallVector DecisionStack;
+  llvm::SmallVector DecisionStack;
   llvm::DenseMap &CondIDs;
   llvm::DenseMap &MCDCBitmapMap;
   MCDCConditionID NextID = 1;
   bool NotMapped = false;
 
   /// Represent a sentinel value of [0,0] for the bottom of DecisionStack.
-  static constexpr DecisionIDPair DecisionStackSentinel{0, 0};
+  static constexpr MCDCConditionIDs DecisionStackSentinel{0, 0};
 
   /// Is this a logical-AND operation?
   bool isLAnd(const BinaryOperator *E) const {
@@ -727,7 +721,7 @@ struct MCDCCoverageBuilder {
   }
 
   /// Return the LHS Decision ([0,0] if not set).
-  const DecisionIDPair &back() const { return DecisionStack.back(); }
+  const MCDCConditionIDs &back() const { return DecisionStack.back(); }
 
   /// Push the binary operator statement to track the nest level and assign IDs
   /// to the operator's LHS and RHS.  The RHS may be a larger subtree that is
@@ -744,7 +738,7 @@ struct MCDCCoverageBuilder {
 if (NotMapped)
   return;
 
-const DecisionIDPair &ParentDecision = DecisionStack.back();
+const MCDCConditionIDs &ParentDecision = DecisionStack.back();
 
 // If the operator itself has an assigned ID, this means it represents a
 // larger subtree.  In this case, assign that ID to its LHS node.  Its RHS
@@ -760,18 +754,18 @@ struct MCDCCoverageBuilder {
 
 // Push the LHS decision IDs onto the DecisionStack.
 if (isLAnd(E))
-  DecisionStack.push_back({RHSid, ParentDecision.FalseID});
+  DecisionStack.push_back({ParentDecision[0], RHSid});
 else
-  DecisionStack.push_back({ParentDecision.TrueID, RHSid});
+  DecisionStack.push_back({RHSid, ParentDecision[1]});
   }
 
   /// Pop and return the LHS Decision ([0,0] if not set).
-  DecisionIDPair pop() {
+  MCDCConditionIDs pop() {
 if (!CGM.getCodeGenOpts().MCDCCoverage || NotMapped)
   return DecisionStack.front();
 
 assert(DecisionStack.size() > 1);
-DecisionIDPair D = DecisionStack.back();
+MCDCConditionIDs D = DecisionStack.back();
 DecisionStack.pop_back();
 return D;
   }
@@ -865,8 +859,7 @@ struct CounterCoverageMappingBuilder
 std::optional StartLoc = std::nullopt,
 std::optional EndLoc = std::nullopt,
 std::optional FalseCount = std::nullopt,
-MCDCConditionID ID = 0, MCDCConditionID TrueID = 0,
-MCDCConditionID FalseID = 0) {
+MCDCConditionID ID = 0, MCDCConditionIDs Conds = {}) {
 
 if (StartLoc && !FalseCount) {
   MostRecentLocation = *StartLoc;
@@ -885,8 +878,7 @@ struct CounterCoverageMappingBuilder
   StartLoc = std::nullopt;
 if (EndLoc && EndLoc->isInvalid())
   EndLoc = std::nullopt;
-RegionStack.emplace_back(Count, FalseCount,
- MCDCParameters{0, 0, ID, TrueID, FalseID},
+RegionStack.emplace_back(Count, FalseCount, MCDCParameters{0, 0, ID, 
Conds},
  StartLoc, EndLoc);
 
 return RegionStack.size() - 1;

[clang] [flang] [clang][flang][driver] Correct program names in option group descriptions (PR #81726)

2024-02-14 Thread David Spickett via cfe-commits

https://github.com/DavidSpickett updated 
https://github.com/llvm/llvm-project/pull/81726

>From 74fe9a47aecac7f7d16485d11781c9cc92229429 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Wed, 14 Feb 2024 11:20:51 +
Subject: [PATCH 1/2] [clang][flang][driver] Correct program names in option
 group descriptions

Currently https://flang.llvm.org/docs/FlangCommandLineReference.html
refers to "Clang" in several of the group descriptions for example:
```
Compilation options

Flags controlling the behavior of Clang during compilation...
```

This is pretty confusing. I'm fixing this by making use of `Program` from
the existing GlobalDocumentation object to substitute in the program name
to these descriptions.

This `Program` has been changed to a proper noun given that it's easier
to lower case a string than capitalise one character (syntax wise). The
tablegen backend has been changed to lower it so that links in the RST/HTML
remain the same as they were before.

To make sure the file is valid when not generating docs, I'm checking
a #define and providing a default GlobalDocumentation if it's not defined.
(I looked for a way to check if a def exists, but tablegen doesn't seem
to have one)

This means that if the DocBrief are used outside of documentation, they'll
say "Clang", which is the same as it always was.

This change does not aim fix option descriptions that refer to clang.
Though we can use parts of this for that, there is only one driver library
so it needs a different approach.
---
 clang/include/clang/Driver/ClangOptionDocs.td |  3 +-
 clang/include/clang/Driver/Options.td | 37 +++
 .../utils/TableGen/ClangOptionDocEmitter.cpp  |  9 +++--
 flang/docs/FlangOptionsDocs.td|  4 +-
 4 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Driver/ClangOptionDocs.td 
b/clang/include/clang/Driver/ClangOptionDocs.td
index a5ee577c5f45db..dea6a7ccb12c9a 100644
--- a/clang/include/clang/Driver/ClangOptionDocs.td
+++ b/clang/include/clang/Driver/ClangOptionDocs.td
@@ -27,11 +27,12 @@ GCC-compatible ``clang`` and ``clang++`` drivers.
 
 }];
 
-  string Program = "clang";
+  string Program = "Clang";
   // Note: We *must* use DefaultVis and not ClangOption, since that's
   // the name of the actual TableGen record. The alias will not work.
   list VisibilityMask = ["DefaultVis"];
   list IgnoreFlags = ["HelpHidden", "Unsupported", "Ignored"];
 }
 
+#define GENERATING_DOCS
 include "Options.td"
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 95b464e7d61834..375ea6f5f6979c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -13,6 +13,25 @@
 // Include the common option parsing interfaces.
 include "llvm/Option/OptParser.td"
 
+// When generating documentation, we expect there to be a GlobalDocumentation
+// def containing the program name that we are generating documentation for.
+// This object should only be used by things that are used in documentation,
+// such as the group descriptions.
+#ifndef GENERATING_DOCS
+// So that this file can still be parsed without such a def, define one if 
there
+// isn't one provided.
+def GlobalDocumentation {
+  // Sensible default in case of mistakes.
+  string Program = "Clang";
+}
+#endif
+
+// Use this to generate program specific documentation, for example:
+// StringForProgram<"Control how %Program behaves.">.str
+class StringForProgram {
+  string str = !subst("%Program", GlobalDocumentation.Program, _str);
+}
+
 /
 // Flags
 
@@ -100,14 +119,16 @@ def Action_Group : OptionGroup<"">, 
DocName<"Actions">,
 // Meta-group for options which are only used for compilation,
 // and not linking etc.
 def CompileOnly_Group : OptionGroup<"">,
-DocName<"Compilation options">, DocBrief<[{
-Flags controlling the behavior of Clang during compilation. These flags have
-no effect during actions that do not perform compilation.}]>;
+DocName<"Compilation options">,
+DocBrief.str>;
 
 def Preprocessor_Group : OptionGroup<"">,
  Group,
- DocName<"Preprocessor options">, DocBrief<[{
-Flags controlling the behavior of the Clang preprocessor.}]>;
+ DocName<"Preprocessor options">,
+ DocBrief.str>;
 
 def IncludePath_Group : OptionGroup<"">, Group,
 DocName<"Include path management">,
@@ -128,9 +149,9 @@ def d_Group : OptionGroup<"">, 
Group,
 Flags allowing the state of the preprocessor to be dumped in various ways.}]>;
 
 def Diag_Group : OptionGroup<"">, Group,
- DocName<"Diagnostic options">, DocBrief<[{
-Flags controlling which warnings, errors, and remarks Clang will generate.
-See the :doc:`full list of warning and remark flags 
`.}]>;
+ DocName<"Diagnostic options">, DocBrief`.}]>.str>;
 
 d

[clang] [llvm] [AMDGPU] Add an option to disable unsafe uses of atomic xor (PR #69229)

2024-02-14 Thread Matt Arsenault via cfe-commits

arsenm wrote:

We're gradually converging on something that looks like this, subject to bike 
shedding the name 

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


[clang] [flang] [clang][flang][driver] Correct program names in option group descriptions (PR #81726)

2024-02-14 Thread David Spickett via cfe-commits

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


[clang] [flang] [clang][flang][driver] Correct program names in option group descriptions (PR #81726)

2024-02-14 Thread David Spickett via cfe-commits

DavidSpickett wrote:

Fixed the warning.

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


[clang] [clang-tools-extra] [codegen] Emit missing cleanups when an expression contains a branch (PR #80698)

2024-02-14 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

> Is there a valid use for having "EHCleanup" that _doesn't_ handle branches 
> across it? That is, do we _ever_ need a cleanup to be called only for an 
> exception thrown, and not otherwise leaving the scope? I'm just wondering if 
> we can simplify things conceptually here and remove an option.

@jyknight Previously, I had tried using all the `EHCleanup` in the EHStack for 
these purposes. I found the `CallCoroEnd` cleanup problematic because the 
suspension cleanup jump destination does not include `CallCoroEnd` cleanup in 
its scope. So we might emit it on jumping to this destination.
```cpp
CurCoro.Data->CleanupJD = getJumpDestInCurrentScope(RetBB);
...
GroManager.EmitGroInit();
EHStack.pushCleanup(EHCleanup);
```

I will try to juggle the `CallCoroEnd` cleanup and jump destination and make it 
work.

Another problem of relying on `EHCleanup` would be that many (and not all) 
EHOnly cleanups are added to the EHStack only when exceptions are enabled. We 
would need to restructure this to add them to EHStack "always" but only emit 
them with `-fexceptions`.

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


[clang] 8e24bc0 - [C23] Do not diagnose binary literals as an extension (#81658)

2024-02-14 Thread via cfe-commits

Author: Aaron Ballman
Date: 2024-02-14T09:08:28-05:00
New Revision: 8e24bc096dcd0013d802e59a45803c51796dec0a

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

LOG: [C23] Do not diagnose binary literals as an extension (#81658)

We previously would diagnose them as a GNU extension in C mode, but they
are now a feature of C23. The -Wgnu-binary-literal warning group no
longer controls any diagnostics as this is no longer a GNU extension.
The warning group is retained as a noop to help avoid "unknown warning"
diagnostics.

This also adds the companion compatibility warning which existed for C++
but not for C.

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

Added: 
clang/test/C/C2x/n2549.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/LiteralSupport.cpp
clang/test/Lexer/gnu-flags.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e12a802e2e9ede..6cf48d63dd512e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -56,6 +56,12 @@ Clang Frontend Potentially Breaking Changes
   ``ArrayRef`` reduces AST memory usage by 0.4% when 
compiling clang, and is
   expected to show similar improvements on other workloads.
 
+- The ``-Wgnu-binary-literal`` diagnostic group no longer controls any
+  diagnostics. Binary literals are no longer a GNU extension, they're now a C23
+  extension which is controlled via ``-pedantic`` or ``-Wc23-extensions``. Use
+  of ``-Wno-gnu-binary-literal`` will no longer silence this pedantic warning,
+  which may break existing uses with ``-Werror``.
+
 Target OS macros extension
 ^^
 A new Clang extension (see :ref:`here `) is enabled for
@@ -113,6 +119,8 @@ C Language Changes
 
 C23 Feature Support
 ^^^
+- No longer diagnose use of binary literals as an extension in C23 mode. Fixes
+  `#72017 `_.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 975eca0ad9b642..7679b8528a4197 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -44,10 +44,8 @@ def DeprecatedModuleDotMap : 
DiagGroup<"deprecated-module-dot-map">;
 def FrameworkHdrAtImport : DiagGroup<"atimport-in-framework-header">;
 def CXX14BinaryLiteral : DiagGroup<"c++14-binary-literal">;
 def CXXPre14CompatBinaryLiteral : 
DiagGroup<"c++98-c++11-compat-binary-literal">;
-def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 def BinaryLiteral : DiagGroup<"binary-literal", [CXX14BinaryLiteral,
- CXXPre14CompatBinaryLiteral,
- GNUBinaryLiteral]>;
+ CXXPre14CompatBinaryLiteral]>;
 def GNUCompoundLiteralInitializer : 
DiagGroup<"gnu-compound-literal-initializer">;
 def SingleBitBitFieldConstantConversion :
   DiagGroup<"single-bit-bitfield-constant-conversion">;
@@ -1176,10 +1174,13 @@ def C23 : DiagGroup<"c23-extensions">;
 
 def : DiagGroup<"c2x-extensions", [C23]>;
 
+// Previously supported warning group which is no longer pertinent as binary
+// literals are a C++14 and C23 extension now instead of a GNU extension.
+def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
+
 // A warning group for warnings about GCC extensions.
 def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType,
-GNUBinaryLiteral, GNUCaseRange,
+GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
 GNUComplexInteger, GNUCompoundLiteralInitializer,
 GNUConditionalOmittedOperand, GNUDesignator,
 GNUEmptyStruct,

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 75ca2fa16d3485..1354543612b9fb 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -246,7 +246,10 @@ def warn_cxx17_hex_literal : Warning<
   "C++ standards before C++17">,
   InGroup, DefaultIgnore;
 def ext_binary_literal : Extension<
-  "binary integer literals are a GNU extension">, InGroup;
+  "binary integer literals are a C23 extension">, InGroup;
+def warn_c23_compat_binary_literal : Warning<
+  "binary integer literals are incompatible with C standards before C23">,
+  InGroup, DefaultIgnore;
 def ext_bina

[clang] [C23] Do not diagnose binary literals as an extension (PR #81658)

2024-02-14 Thread Aaron Ballman via cfe-commits

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


[clang] 1a1fcac - [MC/DC] Refactor: Introduce `ConditionIDs` as `std::array<2>` (#81221)

2024-02-14 Thread via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-02-14T23:17:00+09:00
New Revision: 1a1fcacbce805e3c409d9d41de61413e3fd8aa36

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

LOG: [MC/DC] Refactor: Introduce `ConditionIDs` as `std::array<2>` (#81221)

Its 0th element corresponds to `FalseID` and 1st to `TrueID`.

CoverageMappingGen.cpp: `DecisionIDPair` is replaced with `ConditionIDs`

Added: 


Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp
llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
llvm/unittests/ProfileData/CoverageMappingTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 3b711c05e92754..93c3c31e71fa83 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -593,11 +593,6 @@ struct EmptyCoverageMappingBuilder : public 
CoverageMappingBuilder {
 /// creation.
 struct MCDCCoverageBuilder {
 
-  struct DecisionIDPair {
-mcdc::ConditionID TrueID = 0;
-mcdc::ConditionID FalseID = 0;
-  };
-
   /// The AST walk recursively visits nested logical-AND or logical-OR binary
   /// operator nodes and then visits their LHS and RHS children nodes.  As this
   /// happens, the algorithm will assign IDs to each operator's LHS and RHS 
side
@@ -688,14 +683,14 @@ struct MCDCCoverageBuilder {
 private:
   CodeGenModule &CGM;
 
-  llvm::SmallVector DecisionStack;
+  llvm::SmallVector DecisionStack;
   MCDC::State &MCDCState;
   llvm::DenseMap &CondIDs;
   mcdc::ConditionID NextID = 1;
   bool NotMapped = false;
 
   /// Represent a sentinel value of [0,0] for the bottom of DecisionStack.
-  static constexpr DecisionIDPair DecisionStackSentinel{0, 0};
+  static constexpr mcdc::ConditionIDs DecisionStackSentinel{0, 0};
 
   /// Is this a logical-AND operation?
   bool isLAnd(const BinaryOperator *E) const {
@@ -732,7 +727,7 @@ struct MCDCCoverageBuilder {
   }
 
   /// Return the LHS Decision ([0,0] if not set).
-  const DecisionIDPair &back() const { return DecisionStack.back(); }
+  const mcdc::ConditionIDs &back() const { return DecisionStack.back(); }
 
   /// Push the binary operator statement to track the nest level and assign IDs
   /// to the operator's LHS and RHS.  The RHS may be a larger subtree that is
@@ -750,7 +745,7 @@ struct MCDCCoverageBuilder {
 if (NotMapped)
   return;
 
-const DecisionIDPair &ParentDecision = DecisionStack.back();
+const mcdc::ConditionIDs &ParentDecision = DecisionStack.back();
 
 // If the operator itself has an assigned ID, this means it represents a
 // larger subtree.  In this case, assign that ID to its LHS node.  Its RHS
@@ -766,18 +761,18 @@ struct MCDCCoverageBuilder {
 
 // Push the LHS decision IDs onto the DecisionStack.
 if (isLAnd(E))
-  DecisionStack.push_back({RHSid, ParentDecision.FalseID});
+  DecisionStack.push_back({ParentDecision[false], RHSid});
 else
-  DecisionStack.push_back({ParentDecision.TrueID, RHSid});
+  DecisionStack.push_back({RHSid, ParentDecision[true]});
   }
 
   /// Pop and return the LHS Decision ([0,0] if not set).
-  DecisionIDPair pop() {
+  mcdc::ConditionIDs pop() {
 if (!CGM.getCodeGenOpts().MCDCCoverage || NotMapped)
   return DecisionStack.front();
 
 assert(DecisionStack.size() > 1);
-DecisionIDPair D = DecisionStack.back();
+mcdc::ConditionIDs D = DecisionStack.back();
 DecisionStack.pop_back();
 return D;
   }
@@ -1026,15 +1021,12 @@ struct CounterCoverageMappingBuilder
 return (Cond->EvaluateAsInt(Result, CVM.getCodeGenModule().getContext()));
   }
 
-  using MCDCDecisionIDPair = MCDCCoverageBuilder::DecisionIDPair;
-
   /// Create a Branch Region around an instrumentable condition for coverage
   /// and add it to the function's SourceRegions.  A branch region tracks a
   /// "True" counter and a "False" counter for boolean expressions that
   /// result in the generation of a branch.
-  void
-  createBranchRegion(const Expr *C, Counter TrueCnt, Counter FalseCnt,
- const MCDCDecisionIDPair &IDPair = MCDCDecisionIDPair()) {
+  void createBranchRegion(const Expr *C, Counter TrueCnt, Counter FalseCnt,
+  const mcdc::ConditionIDs &Conds = {}) {
 // Check for NULL conditions.
 if (!C)
   return;
@@ -1047,8 +1039,7 @@ struct CounterCoverageMappingBuilder
   mcdc::Parameters BranchParams;
   mcdc::ConditionID ID = MCDCBuilder.getCondID(C);
   if (ID > 0)
-BranchParams =
-mcdc::

[clang] [llvm] [MC/DC] Refactor: Introduce `ConditionIDs` as `std::array<2>` (PR #81221)

2024-02-14 Thread NAKAMURA Takumi via cfe-commits

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


[clang] [llvm] [AMDGPU] Replace '.' with '-' in generic target names (PR #81718)

2024-02-14 Thread Konstantin Zhuravlyov via cfe-commits

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

Thanks!

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


[clang] 43c7eb5 - [AMDGPU] Replace '.' with '-' in generic target names (#81718)

2024-02-14 Thread via cfe-commits

Author: Pierre van Houtryve
Date: 2024-02-14T15:19:04+01:00
New Revision: 43c7eb5d7b237bc18385f0a5529f1e4b8bf4d6a3

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

LOG: [AMDGPU] Replace '.' with '-' in generic target names (#81718)

The dot is too confusing for tools. Output temporaries would have
'10.3-generic' so tools could parse it as an extension, device libs &
the associated clang driver logic are also confused by the dot.

After discussions, we decided it's better to just remove the '.' from
the target name than fix each issue one by one.

Added: 


Modified: 
clang/lib/Basic/Targets/AMDGPU.cpp
clang/test/Driver/amdgpu-macros.cl
clang/test/Driver/amdgpu-mcpu.cl
clang/test/Misc/target-invalid-cpu-note.c
llvm/docs/AMDGPUUsage.rst
llvm/lib/Object/ELFObjectFile.cpp
llvm/lib/Target/AMDGPU/GCNProcessors.td
llvm/lib/TargetParser/TargetParser.cpp
llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll
llvm/test/CodeGen/AMDGPU/generic-targets-require-v6.ll
llvm/test/CodeGen/AMDGPU/hsa-generic-target-features.ll
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.image.gather4.d16.dim.ll
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.image.sample.dim.ll
llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 10cba6b7eac5cc..5742885df0461b 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -285,10 +285,9 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions 
&Opts,
  : getArchNameR600(GPUKind));
 
   // Sanitize the name of generic targets.
-  // e.g. gfx10.1-generic -> gfx10_1_generic
+  // e.g. gfx10-1-generic -> gfx10_1_generic
   if (GPUKind >= llvm::AMDGPU::GK_AMDGCN_GENERIC_FIRST &&
   GPUKind <= llvm::AMDGPU::GK_AMDGCN_GENERIC_LAST) {
-std::replace(CanonName.begin(), CanonName.end(), '.', '_');
 std::replace(CanonName.begin(), CanonName.end(), '-', '_');
   }
 

diff  --git a/clang/test/Driver/amdgpu-macros.cl 
b/clang/test/Driver/amdgpu-macros.cl
index 3b10444ef71d36..004619321b271f 100644
--- a/clang/test/Driver/amdgpu-macros.cl
+++ b/clang/test/Driver/amdgpu-macros.cl
@@ -132,8 +132,8 @@
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1201 
-DFAMILY=GFX12
 
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx9_generic 
-DFAMILY=GFX9
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_1_generic -DFAMILY=GFX10
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_3_generic -DFAMILY=GFX10
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10-1-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_1_generic -DFAMILY=GFX10
+// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10-3-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 
-DCPU=gfx10_3_generic -DFAMILY=GFX10
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx11_generic 
-DFAMILY=GFX11
 
 // ARCH-GCN-DAG: #define FP_FAST_FMA 1

diff  --git a/clang/test/Driver/amdgpu-mcpu.cl 
b/clang/test/Driver/amdgpu-mcpu.cl
index 6f18ea0615cb69..915fa6473ac07f 100644
--- a/clang/test/Driver/amdgpu-mcpu.cl
+++ b/clang/test/Driver/amdgpu-mcpu.cl
@@ -116,8 +116,8 @@
 // RUN: %clang -### -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck 
--check-prefix=GFX1201 %s
 
 // RUN: %clang -### -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck 
--check-prefix=GFX9_GENERIC %s
-// RUN: %clang -### -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_1_GENERIC %s
-// RUN: %clang -### -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_3_GENERIC %s
+// RUN: %clang -### -target amdgcn -mcpu=gfx10-1-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_1_GENERIC %s
+// RUN: %clang -### -target amdgcn -mcpu=gfx10-3-generic %s 2>&1 | FileCheck 
--check-prefix=GFX10_3_GENERIC %s
 // RUN: %clang -### -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck 
--check-prefix=GFX11_GENERIC %s
 
 // GCNDEFAULT-NOT: -target-cpu
@@ -167,6 +167,6 @@
 // GFX1201:   "-target-cpu" "gfx1201"
 
 // GFX9_GENERIC:  "-target-cpu" "gfx9-generic"
-// GFX10_1_GENERIC: 

[clang] [llvm] [AMDGPU] Replace '.' with '-' in generic target names (PR #81718)

2024-02-14 Thread Pierre van Houtryve via cfe-commits

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


[clang] [llvm] [BPF] add cast_{user,kern} instructions (PR #79902)

2024-02-14 Thread via cfe-commits


@@ -416,11 +419,124 @@ bool BPFCheckAndAdjustIR::removeGEPBuiltins(Module &M) {
   return Changed;
 }
 
+// Wrap ToWrap with cast to address space zero:
+// - if ToWrap is a getelementptr,
+//   wrap it's base pointer instead and return a copy;
+// - if ToWrap is Instruction, insert address space cast
+//   immediately after ToWrap;
+// - if ToWrap is not an Instruction (function parameter
+//   or a global value), insert address space cast at the
+//   beginning of the Function F;
+// - use Cache to avoid inserting too many casts;
+static Value *aspaceWrapValue(DenseMap &Cache, Function *F,
+  Value *ToWrap) {
+  auto It = Cache.find(ToWrap);
+  if (It != Cache.end())
+return It->getSecond();
+
+  if (auto *GEP = dyn_cast(ToWrap)) {
+Value *Ptr = GEP->getPointerOperand();
+Value *WrappedPtr = aspaceWrapValue(Cache, F, Ptr);
+auto *GEPTy = cast(GEP->getType());
+auto *NewGEP = GEP->clone();
+NewGEP->insertAfter(GEP);
+NewGEP->mutateType(GEPTy->getPointerTo(0));
+NewGEP->setOperand(GEP->getPointerOperandIndex(), WrappedPtr);
+NewGEP->setName(GEP->getName());
+Cache[ToWrap] = NewGEP;
+return NewGEP;
+  }
+
+  IRBuilder IB(F->getContext());
+  if (Instruction *InsnPtr = dyn_cast(ToWrap))
+IB.SetInsertPoint(*InsnPtr->getInsertionPointAfterDef());
+  else
+IB.SetInsertPoint(F->getEntryBlock().getFirstInsertionPt());
+  auto *PtrTy = cast(ToWrap->getType());
+  auto *ASZeroPtrTy = PtrTy->getPointerTo(0);
+  auto *ACast = IB.CreateAddrSpaceCast(ToWrap, ASZeroPtrTy, ToWrap->getName());
+  Cache[ToWrap] = ACast;
+  return ACast;
+}
+
+// Wrap a pointer operand OpNum of instruction I
+// with cast to address space zero
+static void aspaceWrapOperand(DenseMap &Cache, Instruction 
*I,
+  unsigned OpNum) {
+  Value *OldOp = I->getOperand(OpNum);
+  if (OldOp->getType()->getPointerAddressSpace() == 0)
+return;
+
+  Value *NewOp = aspaceWrapValue(Cache, I->getFunction(), OldOp);
+  I->setOperand(OpNum, NewOp);
+  // Check if there are any remaining users of old GEP,
+  // delete those w/o users
+  for (;;) {
+auto *OldGEP = dyn_cast(OldOp);
+if (!OldGEP)
+  break;
+if (!OldGEP->use_empty())
+  break;
+OldOp = OldGEP->getPointerOperand();
+OldGEP->eraseFromParent();
+  }
+}
+
+// Support for BPF arenas:
+// - for each function in the module M, update pointer operand of
+//   each memory access instruction (load/store/cmpxchg/atomicrmw)
+//   by casting it from non-zero address space to zero address space, e.g:
+//
+//   (load (ptr addrspace (N) %p) ...)
+// -> (load (addrspacecast ptr addrspace (N) %p to ptr))
+//
+// - assign section with name .arena.N for globals defined in
+//   non-zero address space N
+bool BPFCheckAndAdjustIR::insertASpaceCasts(Module &M) {
+  bool Changed = false;
+  for (Function &F : M) {
+DenseMap CastsCache;

eddyz87 wrote:

I don't think this would be a problem:
- the cache is for wrapped Value, and each Value is defined only once
- the cast instruction, put into cache, is placed right after Value definition 
(if it is an instruction, otherwise it is put at the beginning of the 
function), so it dominates same set of instructions as wrapped value did before 
the transformation

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


[clang] [clang] Allow builtin addc/subc to be constant evaluated (PR #81656)

2024-02-14 Thread Bryce Wilson via cfe-commits


@@ -12696,6 +12696,56 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return BuiltinOp == Builtin::BI__atomic_always_lock_free ?
 Success(0, E) : Error(E);
   }
+  case Builtin::BI__builtin_addcb:
+  case Builtin::BI__builtin_addcs:
+  case Builtin::BI__builtin_addc:
+  case Builtin::BI__builtin_addcl:
+  case Builtin::BI__builtin_addcll:
+  case Builtin::BI__builtin_subcb:
+  case Builtin::BI__builtin_subcs:
+  case Builtin::BI__builtin_subc:
+  case Builtin::BI__builtin_subcl:
+  case Builtin::BI__builtin_subcll: {
+LValue CarryOutLValue;
+APSInt LHS, RHS, CarryIn, Result;

Bryce-MW wrote:

IIRC, APSInt isn't always signed, it just knows if it is or not. 
`EvaluateInteger` always takes an APSInt

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


[clang] [Clang][CodeGen] Loose the cast check when emitting builtins (PR #81669)

2024-02-14 Thread Shilei Tian via cfe-commits

shiltian wrote:

> Don't see how that could be related; you can losslessly bitconvert between 
> i16 and bfloat

Yes, `canLosslesslyBitCastTo` doesn't allow cast between `i16` and `bfloat`, 
but it does between two vectors, as long as their sizes are the same.

> A cast between float and int sounds like "re-interpretation of the bits" to 
> me. Though the function already allows it if it's a vector of int/float.

Yeah. I was reluctant to allow it in `canLosslesslyBitCastTo` also because of 
that. Since it allows vector conversion, it already breaks the purpose.


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


[clang] b37bd78 - [clang][Interp][NFC] Add missing special cases for implicit functions

2024-02-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-14T15:58:37+01:00
New Revision: b37bd78e411ce642a4ca9e0c2394cef8c2f389c1

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

LOG: [clang][Interp][NFC] Add missing special cases for implicit functions

We have this special case in getSource() and getRange(), but we
were missing it in getExpr() and getLocation().

Added: 


Modified: 
clang/lib/AST/Interp/InterpFrame.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index dd05dac1703fd6..bf2cca733b66bb 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -228,10 +228,16 @@ SourceInfo InterpFrame::getSource(CodePtr PC) const {
 }
 
 const Expr *InterpFrame::getExpr(CodePtr PC) const {
+  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+return Caller->getExpr(RetPC);
+
   return S.getExpr(Func, PC);
 }
 
 SourceLocation InterpFrame::getLocation(CodePtr PC) const {
+  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+return Caller->getLocation(RetPC);
+
   return S.getLocation(Func, PC);
 }
 



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


[clang] [llvm] [RFC][AMDGPU] Use `bf16` instead of `i16` for bfloat (PR #80908)

2024-02-14 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/80908

>From 1488b4e54982be4d3f5bc7f35617effcab52be48 Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Wed, 14 Feb 2024 09:41:00 -0500
Subject: [PATCH] [RFC][WIP][AMDGPU] Use `bf16` instead of `i16` for bfloat

Currently it looks like we generally use `i16` to represent `bf16` in those 
tablegen
files. I'm not sure of the reason behind it. My wild guess is the type `bf16` 
was
not available when we enabled the support. This patch is trying to use `bf16`
directly in those tablegen files, aiming at fixing #79369. Of course for #79369
a workaround can be to treat all `INT16` variants as `BFloat` in 
`getOpFltSemantics`,
but it doesn't look good IMHO.

Since I'm fairly new to AMDGPU backend, I'd appreciate it if you can point out
where I don't understand correctly.
---
 clang/lib/CodeGen/CGBuiltin.cpp   |  4 -
 .../builtins-amdgcn-dl-insts-gfx11.cl |  5 +-
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |  8 +-
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp  | 92 +++
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp | 57 
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h   |  2 +
 .../MCTargetDesc/AMDGPUMCCodeEmitter.cpp  | 39 
 llvm/lib/Target/AMDGPU/SIDefines.h|  7 ++
 llvm/lib/Target/AMDGPU/SIInstrInfo.cpp| 15 +++
 llvm/lib/Target/AMDGPU/SIInstrInfo.td | 58 ++--
 llvm/lib/Target/AMDGPU/SIRegisterInfo.td  | 21 -
 .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp| 54 +++
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h | 16 
 llvm/lib/Target/AMDGPU/VOP3Instructions.td|  2 +-
 .../AMDGPU/llvm.amdgcn.fdot2.bf16.bf16.ll | 39 
 llvm/test/MC/AMDGPU/bf16_imm.s|  8 ++
 llvm/test/MC/Disassembler/AMDGPU/bf16_imm.txt |  8 ++
 17 files changed, 379 insertions(+), 56 deletions(-)
 create mode 100644 llvm/test/MC/AMDGPU/bf16_imm.s
 create mode 100644 llvm/test/MC/Disassembler/AMDGPU/bf16_imm.txt

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ee0b7504769622..9bc60466d09be6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5912,8 +5912,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   }
 }
 
-assert(ArgValue->getType()->canLosslesslyBitCastTo(PTy) &&
-   "Must be able to losslessly bit cast to param");
 // Cast vector type (e.g., v256i32) to x86_amx, this only happen
 // in amx intrinsics.
 if (PTy->isX86_AMXTy())
@@ -5943,8 +5941,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 }
   }
 
-  assert(V->getType()->canLosslesslyBitCastTo(RetTy) &&
- "Must be able to losslessly bit cast result type");
   // Cast x86_amx to vector type (e.g., v256i32), this only happen
   // in amx intrinsics.
   if (V->getType()->isX86_AMXTy())
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx11.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx11.cl
index dc7069decaaa61..7688dfa55a78e3 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx11.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx11.cl
@@ -11,7 +11,10 @@ typedef unsigned short __attribute__((ext_vector_type(2))) 
ushort2;
 // CHECK: call float @llvm.amdgcn.fdot2(<2 x half> %v2hA, <2 x half> %v2hB, 
float %fC, i1 false)
 // CHECK: call float @llvm.amdgcn.fdot2(<2 x half> %v2hA, <2 x half> %v2hB, 
float %fC, i1 true)
 // CHECK: call half @llvm.amdgcn.fdot2.f16.f16(<2 x half> %v2hA, <2 x half> 
%v2hB, half %hC)
-// CHECK: call i16 @llvm.amdgcn.fdot2.bf16.bf16(<2 x i16> %v2ssA, <2 x i16> 
%v2ssB, i16 %sC)
+// CHECK: [[s1:%[0-9]+]] = bitcast <2 x i16> %v2ssA to <2 x bfloat>
+// CHECK-NEXT: [[s2:%[0-9]+]] = bitcast <2 x i16> %v2ssB to <2 x bfloat>
+// CHECK-NEXT: [[s3:%[0-9]+]] = bitcast i16 %sC to bfloat
+// CHECK-NEXT: [[d:%[0-9]+]] = tail call bfloat 
@llvm.amdgcn.fdot2.bf16.bf16(<2 x bfloat> [[s1]], <2 x bfloat> [[s2]], bfloat 
[[s3]])
 // CHECK: call float @llvm.amdgcn.fdot2.f32.bf16(<2 x i16> %v2ssA, <2 x i16> 
%v2ssB, float %fC, i1 false)
 // CHECK: call float @llvm.amdgcn.fdot2.f32.bf16(<2 x i16> %v2ssA, <2 x i16> 
%v2ssB, float %fC, i1 true)
 // CHECK: call i32 @llvm.amdgcn.udot4(i32 %uiA, i32 %uiB, i32 %uiC, i1 false)
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 202fa4e8f4ea81..6795fb7aa0edb8 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -2819,11 +2819,11 @@ def int_amdgcn_fdot2_f16_f16 :
 def int_amdgcn_fdot2_bf16_bf16 :
   ClangBuiltin<"__builtin_amdgcn_fdot2_bf16_bf16">,
   DefaultAttrsIntrinsic<
-[llvm_i16_ty],   // %r
+[llvm_bfloat_ty],   // %r
 [
-  llvm_v2i16_ty, // %a
-  llvm_v2i16_ty, // %b
-  llvm_i16_ty// %c
+  ll

[clang] [ObjC] Check entire chain of superclasses to see if class layout can be statically known (PR #81335)

2024-02-14 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/81335

>From 79ffb626e113b74d934b5322eb76f2b97e1dbee5 Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Fri, 9 Feb 2024 17:51:15 -0500
Subject: [PATCH 1/2] [ObjC] Add pre-commit tests [NFC]

---
 .../constant-non-fragile-ivar-offset.m| 56 +++
 1 file changed, 56 insertions(+)

diff --git a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m 
b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
index 788b3220af3067..44e5af28cdbe02 100644
--- a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
+++ b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
@@ -1,6 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -emit-llvm %s -o - | 
FileCheck %s
 
 // CHECK: @"OBJC_IVAR_$_StaticLayout.static_layout_ivar" = hidden constant i64 
20
+// CHECK: @"OBJC_IVAR_$_SuperClass.superClassIvar" = hidden constant i64 20
+// CHECK: @"OBJC_IVAR_$_SuperClass._superClassProperty" = hidden constant i64 
24
+// CHECK: @"OBJC_IVAR_$_IntermediateClass.intermediateClassIvar" = global i64 
32
+// CHECK: @"OBJC_IVAR_$_IntermediateClass.intermediateClassIvar2" = global i64 
40
+// CHECK: @"OBJC_IVAR_$_IntermediateClass._intermediateProperty" = hidden 
global i64 48
+// CHECK: @"OBJC_IVAR_$_SubClass.subClassIvar" = global i64 56
 // CHECK: @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar" = hidden 
global i64 12
 
 @interface NSObject {
@@ -20,6 +26,56 @@ -(void)meth {
 }
 @end
 
+// Ivars declared in the @interface
+@interface SuperClass : NSObject
+@property (nonatomic, assign) int superClassProperty;
+@end
+
+@implementation SuperClass {
+  int superClassIvar; // Declare an ivar
+}
+- (void)superClassMethod {
+_superClassProperty = 42;
+superClassIvar = 10;
+// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_SuperClass
+}
+@end
+
+// Inheritance and Ivars
+@interface IntermediateClass : SuperClass
+{
+double intermediateClassIvar;
+
+@protected
+int intermediateClassIvar2;
+}
+@property (nonatomic, strong) SuperClass *intermediateProperty;
+@end
+
+@implementation IntermediateClass
+@synthesize intermediateProperty = _intermediateProperty;
+- (void)intermediateClassMethod {
+intermediateClassIvar = 3.14;
+_intermediateProperty = 0;
+// CHECK: load i64, ptr @"OBJC_IVAR_$_IntermediateClass
+}
+@end
+
+@interface SubClass : IntermediateClass
+{
+double subClassIvar;
+}
+@end
+
+@implementation SubClass
+- (void)subclassVar {
+intermediateClassIvar = 3.14;
+subClassIvar = 6.28;
+// CHECK: load i64, ptr @"OBJC_IVAR_$_IntermediateClass
+// CHECK: load i64, ptr @"OBJC_IVAR_$_SubClass
+}
+@end
+
 @interface NotNSObject {
   int these, might, change;
 }

>From 9555bf52beb784bec384e6eb4cc781c3389762e0 Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 13 Feb 2024 14:52:49 -0500
Subject: [PATCH 2/2] [ObjC] Check entire chain of superclasses to see if class
 layout can be statically known

As of now, we only check if a class directly inherits from NSObject to 
determine if said class has fixed offsets and can therefore have its memory 
layout statically known.

However, if an NSObject subclass has fixed offsets, then so must the subclasses 
of that subclass, so this allows us to optimize instances of subclasses of 
subclasses that inherit from NSObject and so on.

To determine this, we need to find that the compiler can see the implementation 
of each intermediate class, as that means it is statically linked.
---
 clang/lib/CodeGen/CGObjCMac.cpp   | 22 ++-
 .../constant-non-fragile-ivar-offset.m| 14 ++--
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..b3d6c3ba314cc2 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1593,12 +1593,22 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   }
 
   bool isClassLayoutKnownStatically(const ObjCInterfaceDecl *ID) {
-// NSObject is a fixed size. If we can see the @implementation of a class
-// which inherits from NSObject then we know that all it's offsets also 
must
-// be fixed. FIXME: Can we do this if see a chain of super classes with
-// implementations leading to NSObject?
-return ID->getImplementation() && ID->getSuperClass() &&
-   ID->getSuperClass()->getName() == "NSObject";
+// Test a class by checking its superclasses up to its base class if it has
+// one
+while (ID) {
+  // The base class NSObject is a fixed size
+  if (ID->getName() == "NSObject")
+return true;
+
+  // If we cannot see the @implementation of a class, we cannot statically
+  // know the class layout
+  if (!ID->getImplementation())
+return false;
+
+  // Test superclass
+  ID =

[clang] [ObjC] Defer to the LLVM backend for unaligned atomic load and stores (PR #79191)

2024-02-14 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/79191

>From 6644009297d1024a14fe27c941217add323079ea Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 23 Jan 2024 13:59:05 -0500
Subject: [PATCH] [ObjC] Defer to the LLVM backend for unaligned atomic load
 and stores

LLVM can codegen correctly for atomics of any alignment in IR, on any 
architecture (via using libcalls when necessary).

So, the ObjC code's hasUnalignedAtomics can be removed. We can use copyStruct 
if the size is too big.
---
 clang/lib/CodeGen/CGObjC.cpp| 17 -
 clang/test/CodeGenObjC/objc_copyStruct.m|  3 +--
 clang/test/CodeGenObjC/property-aggregate.m | 15 ++-
 3 files changed, 3 insertions(+), 32 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index f3a948cf13f9c9..ccda7ce8f41b9f 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -842,15 +842,6 @@ static void emitStructGetterCall(CodeGenFunction &CGF, 
ObjCIvarDecl *ivar,
callee, ReturnValueSlot(), args);
 }
 
-/// Determine whether the given architecture supports unaligned atomic
-/// accesses.  They don't have to be fast, just faster than a function
-/// call and a mutex.
-static bool hasUnalignedAtomics(llvm::Triple::ArchType arch) {
-  // FIXME: Allow unaligned atomic load/store on x86.  (It is not
-  // currently supported by the backend.)
-  return false;
-}
-
 /// Return the maximum size that permits atomic accesses for the given
 /// architecture.
 static CharUnits getMaxAtomicAccessSize(CodeGenModule &CGM,
@@ -1023,14 +1014,6 @@ PropertyImplStrategy::PropertyImplStrategy(CodeGenModule 
&CGM,
   llvm::Triple::ArchType arch =
 CGM.getTarget().getTriple().getArch();
 
-  // Most architectures require memory to fit within a single cache
-  // line, so the alignment has to be at least the size of the access.
-  // Otherwise we have to grab a lock.
-  if (IvarAlignment < IvarSize && !hasUnalignedAtomics(arch)) {
-Kind = CopyStruct;
-return;
-  }
-
   // If the ivar's size exceeds the architecture's maximum atomic
   // access size, we have to use CopyStruct.
   if (IvarSize > getMaxAtomicAccessSize(CGM, arch)) {
diff --git a/clang/test/CodeGenObjC/objc_copyStruct.m 
b/clang/test/CodeGenObjC/objc_copyStruct.m
index 7bbad866e2b1fb..8e52815a308abc 100644
--- a/clang/test/CodeGenObjC/objc_copyStruct.m
+++ b/clang/test/CodeGenObjC/objc_copyStruct.m
@@ -2,7 +2,7 @@
 // RUN: %clang -target x86_64-apple-ios -fobjc-runtime=ios 
-Wno-objc-root-class -S -o - -emit-llvm %s | FileCheck %s
 
 struct S {
-  float f, g;
+  double f, g;
 };
 
 @interface I
@@ -13,4 +13,3 @@ @implementation I
 @end
 
 // CHECK: declare {{.*}}void @objc_copyStruct(ptr, ptr, i64, i1, i1)
-
diff --git a/clang/test/CodeGenObjC/property-aggregate.m 
b/clang/test/CodeGenObjC/property-aggregate.m
index f4211b6b62bd50..4c8c8893f920f4 100644
--- a/clang/test/CodeGenObjC/property-aggregate.m
+++ b/clang/test/CodeGenObjC/property-aggregate.m
@@ -1,13 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck 
%s
 
-// This structure's size is not a power of two, so the property does
-// not get native atomics, even though x86-64 can do unaligned atomics
-// with a lock prefix.
 struct s3 { char c[3]; };
 
 // This structure's size is, so it does, because it can.
-// FIXME: But we don't at the moment; the backend doesn't know how to generate
-// correct code.
 struct s4 { char c[4]; };
 
 @interface Test0
@@ -18,14 +13,8 @@ @implementation Test0
 @synthesize s3, s4;
 @end
 
-// CHECK: define internal i24 @"\01-[Test0 s3]"(
-// CHECK: call void @objc_copyStruct
 
-// CHECK: define internal void @"\01-[Test0 setS3:]"(
-// CHECK: call void @objc_copyStruct
 
-// CHECK: define internal i32 @"\01-[Test0 s4]"(
-// CHECK: call void @objc_copyStruct
 
-// CHECK: define internal void @"\01-[Test0 setS4:]"(
-// CHECK: call void @objc_copyStruct
+ NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
+// CHECK: {{.*}}

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


[clang] [ObjC] Defer to the LLVM backend for unaligned atomic load and stores (PR #79191)

2024-02-14 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/79191

>From 1c54c1e9767e9a53fde23e5717b834b30b228867 Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 23 Jan 2024 13:59:05 -0500
Subject: [PATCH] [ObjC] Defer to the LLVM backend for unaligned atomic load
 and stores

LLVM can codegen correctly for atomics of any alignment in IR, on any 
architecture (via using libcalls when necessary).

So, the ObjC code's hasUnalignedAtomics can be removed. We can use copyStruct 
if the size is too big.
---
 clang/lib/CodeGen/CGObjC.cpp| 17 -
 clang/test/CodeGenObjC/objc_copyStruct.m|  3 +--
 clang/test/CodeGenObjC/property-aggregate.m | 15 ++-
 3 files changed, 3 insertions(+), 32 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index f3a948cf13f9c9..ccda7ce8f41b9f 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -842,15 +842,6 @@ static void emitStructGetterCall(CodeGenFunction &CGF, 
ObjCIvarDecl *ivar,
callee, ReturnValueSlot(), args);
 }
 
-/// Determine whether the given architecture supports unaligned atomic
-/// accesses.  They don't have to be fast, just faster than a function
-/// call and a mutex.
-static bool hasUnalignedAtomics(llvm::Triple::ArchType arch) {
-  // FIXME: Allow unaligned atomic load/store on x86.  (It is not
-  // currently supported by the backend.)
-  return false;
-}
-
 /// Return the maximum size that permits atomic accesses for the given
 /// architecture.
 static CharUnits getMaxAtomicAccessSize(CodeGenModule &CGM,
@@ -1023,14 +1014,6 @@ PropertyImplStrategy::PropertyImplStrategy(CodeGenModule 
&CGM,
   llvm::Triple::ArchType arch =
 CGM.getTarget().getTriple().getArch();
 
-  // Most architectures require memory to fit within a single cache
-  // line, so the alignment has to be at least the size of the access.
-  // Otherwise we have to grab a lock.
-  if (IvarAlignment < IvarSize && !hasUnalignedAtomics(arch)) {
-Kind = CopyStruct;
-return;
-  }
-
   // If the ivar's size exceeds the architecture's maximum atomic
   // access size, we have to use CopyStruct.
   if (IvarSize > getMaxAtomicAccessSize(CGM, arch)) {
diff --git a/clang/test/CodeGenObjC/objc_copyStruct.m 
b/clang/test/CodeGenObjC/objc_copyStruct.m
index 7bbad866e2b1fb..8e52815a308abc 100644
--- a/clang/test/CodeGenObjC/objc_copyStruct.m
+++ b/clang/test/CodeGenObjC/objc_copyStruct.m
@@ -2,7 +2,7 @@
 // RUN: %clang -target x86_64-apple-ios -fobjc-runtime=ios 
-Wno-objc-root-class -S -o - -emit-llvm %s | FileCheck %s
 
 struct S {
-  float f, g;
+  double f, g;
 };
 
 @interface I
@@ -13,4 +13,3 @@ @implementation I
 @end
 
 // CHECK: declare {{.*}}void @objc_copyStruct(ptr, ptr, i64, i1, i1)
-
diff --git a/clang/test/CodeGenObjC/property-aggregate.m 
b/clang/test/CodeGenObjC/property-aggregate.m
index f4211b6b62bd50..4c8c8893f920f4 100644
--- a/clang/test/CodeGenObjC/property-aggregate.m
+++ b/clang/test/CodeGenObjC/property-aggregate.m
@@ -1,13 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck 
%s
 
-// This structure's size is not a power of two, so the property does
-// not get native atomics, even though x86-64 can do unaligned atomics
-// with a lock prefix.
 struct s3 { char c[3]; };
 
 // This structure's size is, so it does, because it can.
-// FIXME: But we don't at the moment; the backend doesn't know how to generate
-// correct code.
 struct s4 { char c[4]; };
 
 @interface Test0
@@ -18,14 +13,8 @@ @implementation Test0
 @synthesize s3, s4;
 @end
 
-// CHECK: define internal i24 @"\01-[Test0 s3]"(
-// CHECK: call void @objc_copyStruct
 
-// CHECK: define internal void @"\01-[Test0 setS3:]"(
-// CHECK: call void @objc_copyStruct
 
-// CHECK: define internal i32 @"\01-[Test0 s4]"(
-// CHECK: call void @objc_copyStruct
 
-// CHECK: define internal void @"\01-[Test0 setS4:]"(
-// CHECK: call void @objc_copyStruct
+ NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
+// CHECK: {{.*}}

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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-14 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa updated 
https://github.com/llvm/llvm-project/pull/80939

>From ac75fc2873fc7b8eec6c24ba97f4673e94457c8e Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH 1/5] [clang] Use separator for large numeric values in
 overflow diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp  |   6 +-
 clang/test/AST/Interp/c.c   |   4 +-
 clang/test/C/drs/dr0xx.c|   2 +-
 clang/test/C/drs/dr2xx.c|   2 +-
 clang/test/Sema/integer-overflow.c  | 100 -
 clang/test/Sema/switch-1.c  |   6 +-
 clang/test/SemaCXX/enum.cpp |   4 +-
 clang/test/SemaCXX/integer-overflow.cpp | 112 ++--
 clang/test/SemaObjC/integer-overflow.m  |   4 +-
 clang/test/SemaObjC/objc-literal-nsnumber.m |   2 +-
 llvm/include/llvm/ADT/APInt.h   |   3 +-
 llvm/include/llvm/ADT/StringExtras.h|   5 +-
 llvm/lib/Support/APInt.cpp  |  24 -
 llvm/unittests/ADT/APIntTest.cpp|  35 ++
 14 files changed, 185 insertions(+), 124 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..d9037072c6767f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo &Info, const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
@@ -13852,7 +13853,8 @@ bool IntExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   if (Info.checkingForUndefinedBehavior())
 Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
  diag::warn_integer_constant_overflow)
-<< toString(Value, 10) << E->getType() << E->getSourceRange();
+<< toString(Value, 10, Value.isSigned(), false, true, true)
+<< E->getType() << E->getSourceRange();
 
   if (!HandleOverflow(Info, E, -Value.extend(Value.getBitWidth() + 1),
   E->getType()))
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 9ab271a82aeef9..aa067b0bc74831 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -109,9 +109,9 @@ int somefunc(int i) {
  // pedantic-expected-warning {{left operand of 
comma operator has no effect}} \
  // pedantic-expected-warning {{overflow in 
expression; result is 131073}} \
  // ref-warning {{left operand of comma operator 
has no effect}} \
- // ref-warning {{overflow in expression; result 
is 131073}} \
+ // ref-warning {{overflow in expression; result 
is 131'073}} \
  // pedantic-ref-warning {{left operand of comma 
operator has no effect}} \
- // pedantic-ref-warning {{overflow in expression; 
result is 131073}}
+ // pedantic-ref-warning {{overflow in expression; 
result is 131'073}}
 
 }
 
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index d9c1fbe4ee40ab..c93cfb63d604cf 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -214,7 +214,7 @@ _Static_assert(__builtin_types_compatible_p(struct S { int 
a; }, union U { int a
  */
 void dr031(int i) {
   switch (i) {
-  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   #pragma clang diagnostic push
   #pragma clang diagnostic ignored "-Wswitch"
   /* Silence the targets which issue:
diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 9c8d77518ab55e..1b68b65acca6af 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -277,7 +277,7 @@ void dr258(void) {
 void dr261(void) {
   /* This is still an integer constant expression despite the overflow. */
   enum e1 {
-ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   };
 
   /* This is not an integer constant ex

[clang] [ObjC] Check entire chain of superclasses to see if class layout can be statically known (PR #81335)

2024-02-14 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/81335

>From 2cf00f6ddf7be0e51fdb1a27668f3c4c92a8 Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Fri, 9 Feb 2024 17:51:15 -0500
Subject: [PATCH 1/2] [ObjC] Add pre-commit tests [NFC]

---
 .../constant-non-fragile-ivar-offset.m| 56 +++
 1 file changed, 56 insertions(+)

diff --git a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m 
b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
index 788b3220af3067..44e5af28cdbe02 100644
--- a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
+++ b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
@@ -1,6 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -emit-llvm %s -o - | 
FileCheck %s
 
 // CHECK: @"OBJC_IVAR_$_StaticLayout.static_layout_ivar" = hidden constant i64 
20
+// CHECK: @"OBJC_IVAR_$_SuperClass.superClassIvar" = hidden constant i64 20
+// CHECK: @"OBJC_IVAR_$_SuperClass._superClassProperty" = hidden constant i64 
24
+// CHECK: @"OBJC_IVAR_$_IntermediateClass.intermediateClassIvar" = global i64 
32
+// CHECK: @"OBJC_IVAR_$_IntermediateClass.intermediateClassIvar2" = global i64 
40
+// CHECK: @"OBJC_IVAR_$_IntermediateClass._intermediateProperty" = hidden 
global i64 48
+// CHECK: @"OBJC_IVAR_$_SubClass.subClassIvar" = global i64 56
 // CHECK: @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar" = hidden 
global i64 12
 
 @interface NSObject {
@@ -20,6 +26,56 @@ -(void)meth {
 }
 @end
 
+// Ivars declared in the @interface
+@interface SuperClass : NSObject
+@property (nonatomic, assign) int superClassProperty;
+@end
+
+@implementation SuperClass {
+  int superClassIvar; // Declare an ivar
+}
+- (void)superClassMethod {
+_superClassProperty = 42;
+superClassIvar = 10;
+// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_SuperClass
+}
+@end
+
+// Inheritance and Ivars
+@interface IntermediateClass : SuperClass
+{
+double intermediateClassIvar;
+
+@protected
+int intermediateClassIvar2;
+}
+@property (nonatomic, strong) SuperClass *intermediateProperty;
+@end
+
+@implementation IntermediateClass
+@synthesize intermediateProperty = _intermediateProperty;
+- (void)intermediateClassMethod {
+intermediateClassIvar = 3.14;
+_intermediateProperty = 0;
+// CHECK: load i64, ptr @"OBJC_IVAR_$_IntermediateClass
+}
+@end
+
+@interface SubClass : IntermediateClass
+{
+double subClassIvar;
+}
+@end
+
+@implementation SubClass
+- (void)subclassVar {
+intermediateClassIvar = 3.14;
+subClassIvar = 6.28;
+// CHECK: load i64, ptr @"OBJC_IVAR_$_IntermediateClass
+// CHECK: load i64, ptr @"OBJC_IVAR_$_SubClass
+}
+@end
+
 @interface NotNSObject {
   int these, might, change;
 }

>From 25d1bb9d4997768577dde1a7e243d2d268b342c2 Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 13 Feb 2024 14:52:49 -0500
Subject: [PATCH 2/2] [ObjC] Check entire chain of superclasses to see if class
 layout can be statically known

As of now, we only check if a class directly inherits from NSObject to 
determine if said class has fixed offsets and can therefore have its memory 
layout statically known.

However, if an NSObject subclass has fixed offsets, then so must the subclasses 
of that subclass, so this allows us to optimize instances of subclasses of 
subclasses that inherit from NSObject and so on.

To determine this, we need to find that the compiler can see the implementation 
of each intermediate class, as that means it is statically linked.
---
 clang/lib/CodeGen/CGObjCMac.cpp   | 22 ++-
 .../constant-non-fragile-ivar-offset.m| 14 ++--
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..b3d6c3ba314cc2 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1593,12 +1593,22 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   }
 
   bool isClassLayoutKnownStatically(const ObjCInterfaceDecl *ID) {
-// NSObject is a fixed size. If we can see the @implementation of a class
-// which inherits from NSObject then we know that all it's offsets also 
must
-// be fixed. FIXME: Can we do this if see a chain of super classes with
-// implementations leading to NSObject?
-return ID->getImplementation() && ID->getSuperClass() &&
-   ID->getSuperClass()->getName() == "NSObject";
+// Test a class by checking its superclasses up to its base class if it has
+// one
+while (ID) {
+  // The base class NSObject is a fixed size
+  if (ID->getName() == "NSObject")
+return true;
+
+  // If we cannot see the @implementation of a class, we cannot statically
+  // know the class layout
+  if (!ID->getImplementation())
+return false;
+
+  // Test superclass
+  ID =

[clang] [Clang] Unify interface for accessing template arguments as written for class/variable template specializations (PR #81642)

2024-02-14 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/81642

>From 0834af0d1fcd2a87656fabdb7b0aee0f42b9b52f Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Fri, 9 Feb 2024 14:00:49 -0500
Subject: [PATCH 1/2] [Clang] Unify interface for accessing template arguments
 as written for class/variable template specializations

---
 clang/include/clang/AST/DeclTemplate.h| 186 --
 clang/include/clang/AST/RecursiveASTVisitor.h |  27 +--
 clang/include/clang/ASTMatchers/ASTMatchers.h |   7 +-
 .../clang/ASTMatchers/ASTMatchersInternal.h   |   4 -
 clang/lib/AST/ASTImporter.cpp |  55 +++---
 clang/lib/AST/DeclPrinter.cpp |  15 +-
 clang/lib/AST/DeclTemplate.cpp| 145 --
 clang/lib/AST/TypePrinter.cpp |  24 +--
 clang/lib/Index/IndexDecl.cpp |   9 +-
 clang/lib/Sema/Sema.cpp   |   2 +-
 clang/lib/Sema/SemaTemplate.cpp   |  47 ++---
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 155 ++-
 clang/lib/Serialization/ASTReaderDecl.cpp |  20 +-
 clang/lib/Serialization/ASTWriterDecl.cpp |  16 +-
 clang/test/AST/ast-dump-template-decls.cpp|  18 +-
 clang/test/Index/Core/index-source.cpp|  11 --
 clang/test/Index/index-refs.cpp   |   1 -
 clang/tools/libclang/CIndex.cpp   |  29 ++-
 .../ASTMatchers/ASTMatchersNodeTest.cpp   |  12 --
 .../ASTMatchers/ASTMatchersTraversalTest.cpp  |  18 +-
 20 files changed, 360 insertions(+), 441 deletions(-)

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index e3b6a7efb1127a..b5c2d459715120 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -1792,10 +1792,9 @@ class ClassTemplateSpecializationDecl
   llvm::PointerUnion
 SpecializedTemplate;
 
-  /// Further info for explicit template specialization/instantiation.
-  struct ExplicitSpecializationInfo {
-/// The type-as-written.
-TypeSourceInfo *TypeAsWritten = nullptr;
+  struct ExplicitInstantiationInfo {
+/// The template arguments as written..
+const ASTTemplateArgumentListInfo *TemplateArgsAsWritten = nullptr;
 
 /// The location of the extern keyword.
 SourceLocation ExternLoc;
@@ -1803,12 +1802,14 @@ class ClassTemplateSpecializationDecl
 /// The location of the template keyword.
 SourceLocation TemplateKeywordLoc;
 
-ExplicitSpecializationInfo() = default;
+ExplicitInstantiationInfo() = default;
   };
 
   /// Further info for explicit template specialization/instantiation.
   /// Does not apply to implicit specializations.
-  ExplicitSpecializationInfo *ExplicitInfo = nullptr;
+  llvm::PointerUnion
+  ExplicitInfo = nullptr;
 
   /// The template arguments used to describe this specialization.
   const TemplateArgumentList *TemplateArgs;
@@ -1985,44 +1986,45 @@ class ClassTemplateSpecializationDecl
 SpecializedTemplate = TemplDecl;
   }
 
-  /// Sets the type of this specialization as it was written by
-  /// the user. This will be a class template specialization type.
-  void setTypeAsWritten(TypeSourceInfo *T) {
-if (!ExplicitInfo)
-  ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
-ExplicitInfo->TypeAsWritten = T;
-  }
-
-  /// Gets the type of this specialization as it was written by
-  /// the user, if it was so written.
-  TypeSourceInfo *getTypeAsWritten() const {
-return ExplicitInfo ? ExplicitInfo->TypeAsWritten : nullptr;
+  const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
+if (auto *Info = ExplicitInfo.dyn_cast())
+  return Info->TemplateArgsAsWritten;
+return ExplicitInfo.get();
   }
 
   /// Gets the location of the extern keyword, if present.
   SourceLocation getExternLoc() const {
-return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation();
+if (auto *Info = ExplicitInfo.dyn_cast())
+  return Info->ExternLoc;
+return SourceLocation();
   }
 
-  /// Sets the location of the extern keyword.
-  void setExternLoc(SourceLocation Loc) {
-if (!ExplicitInfo)
-  ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
-ExplicitInfo->ExternLoc = Loc;
+  /// Gets the location of the template keyword, if present.
+  SourceLocation getTemplateKeywordLoc() const {
+if (auto *Info = ExplicitInfo.dyn_cast())
+  return Info->TemplateKeywordLoc;
+return SourceLocation();
   }
 
-  /// Sets the location of the template keyword.
-  void setTemplateKeywordLoc(SourceLocation Loc) {
-if (!ExplicitInfo)
-  ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
-ExplicitInfo->TemplateKeywordLoc = Loc;
+  void
+  setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten) {
+if (auto *Info = ExplicitInfo.dyn_cast())
+  Info->TemplateArgsAsWritten = ArgsWritten;
+else
+  ExplicitInfo = ArgsWri

[clang] [NFC] Add API documentation and annotations (PR #78635)

2024-02-14 Thread Chris B via cfe-commits


@@ -570,7 +716,13 @@ double4 sin(double4);
 
//===--===//
 // sqrt builtins
 
//===--===//
+
+/// \fn T sqrt(T Val)
+/// \brief Returns the square root of the input value, \a Val.
+/// \param Val The input value.
+
 #ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)

llvm-beanz wrote:

That's a good catch. I think we're missing all the vector overloads for `sqrt`. 
I also have another fix coming that specifically adjusts the `half` handling.

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


[clang] 457c179 - [NFC] Add API documentation and annotations (#78635)

2024-02-14 Thread via cfe-commits

Author: Chris B
Date: 2024-02-14T09:15:21-06:00
New Revision: 457c17944c6eb3d89ae6a765e4795c1cc3148506

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

LOG: [NFC] Add API documentation and annotations (#78635)

This change adds SM 6.2 availability annotation to 16-bit APIs (16-bit
types require SM 6.2), and adds Doxygen API documentation.

Added: 


Modified: 
clang/lib/Headers/hlsl/hlsl_basic_types.h
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h 
b/clang/lib/Headers/hlsl/hlsl_basic_types.h
index 9ea605cfa840a6..e96fa90b1ce469 100644
--- a/clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -12,6 +12,13 @@
 namespace hlsl {
 // built-in scalar data types:
 
+/// \typedef template using vector = Ty
+/// __attribute__((ext_vector_type(Size)))
+///
+/// \tparam Ty The base type of the vector may be any builtin integral or
+/// floating point type.
+/// \tparam Size The size of the vector may be any value between 1 and 4.
+
 #ifdef __HLSL_ENABLE_16_BIT
 // 16-bit integer.
 typedef unsigned short uint16_t;

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index da153d8f8e0349..a8b36d29c78607 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -24,22 +24,35 @@ namespace hlsl {
 
//===--===//
 // abs builtins
 
//===--===//
+
+/// \fn T abs(T Val)
+/// \brief Returns the absolute value of the input value, \a Val.
+/// \param Val The input value.
+
 #ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int16_t abs(int16_t);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int16_t2 abs(int16_t2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int16_t3 abs(int16_t3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int16_t4 abs(int16_t4);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half abs(half);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half2 abs(half2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half3 abs(half3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half4 abs(half4);
 #endif
@@ -83,13 +96,23 @@ double4 abs(double4);
 
//===--===//
 // ceil builtins
 
//===--===//
+
+/// \fn T ceil(T Val)
+/// \brief Returns the smallest integer value that is greater than or equal to
+/// the input value, \a Val.
+/// \param Val The input value.
+
 #ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half ceil(half);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half2 ceil(half2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half3 ceil(half3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half4 ceil(half4);
 #endif
@@ -115,13 +138,22 @@ double4 ceil(double4);
 
//===--===//
 // cos builtins
 
//===--===//
+
+/// \fn T cos(T Val)
+/// \brief Returns the cosine of the input value, \a Val.
+/// \param Val The input value.
+
 #ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 half cos(half);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 half2 cos(half2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 half3 cos(half3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 half4 cos(half4);
 #endif
@@ -147,13 +179,23 @@ double4 cos(double4);
 
//===--===//
 // floor builtins
 
//===--===//
+
+/// \fn T floor(T Val)
+/// \brief Returns the largest integer that is less than or equal to the input
+/// value, \a Val.
+/// \param Val The input value.
+
 #ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shaderm

[clang] [NFC] Add API documentation and annotations (PR #78635)

2024-02-14 Thread Chris B via cfe-commits

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


[clang-tools-extra] [clang-tidy] fix incorrect hint for InitListExpr in prefer-member-initializer (PR #81560)

2024-02-14 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/81560

>From 35dba54b1d6d158118c34d0f1bd8038b64c9bda4 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 13 Feb 2024 09:11:06 +0800
Subject: [PATCH 1/2] [clang-tidy] fix incorrect hint for InitListExpr in
 prefer-member-initializer

Fixes: #77684.
---
 .../PreferMemberInitializerCheck.cpp  |  5 
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 ++-
 .../prefer-member-initializer.cpp | 23 +++
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index de96c3dc4efef7..7ede900d7ba7b1 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -203,6 +203,7 @@ void PreferMemberInitializerCheck::check(
 SourceLocation InsertPos;
 SourceRange ReplaceRange;
 bool AddComma = false;
+bool AddBracket = false;
 bool InvalidFix = false;
 unsigned Index = Field->getFieldIndex();
 const CXXCtorInitializer *LastInListInit = nullptr;
@@ -216,6 +217,7 @@ void PreferMemberInitializerCheck::check(
 else {
   ReplaceRange = Init->getInit()->getSourceRange();
 }
+AddBracket = isa(Init->getInit());
 break;
   }
   if (Init->isMemberInitializer() &&
@@ -279,6 +281,9 @@ void PreferMemberInitializerCheck::check(
 if (HasInitAlready) {
   if (InsertPos.isValid())
 Diag << FixItHint::CreateInsertion(InsertPos, NewInit);
+  else if (AddBracket)
+Diag << FixItHint::CreateReplacement(ReplaceRange,
+ ("{" + NewInit + "}").str());
   else
 Diag << FixItHint::CreateReplacement(ReplaceRange, NewInit);
 } else {
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ee68c8f49b3df2..f8bc85d78315bf 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -127,7 +127,8 @@ Changes in existing checks
   
`_,
   which was deprecated since :program:`clang-tidy` 17. This rule is now covered
   by :doc:`cppcoreguidelines-use-default-member-init
-  `.
+  ` and fixes
+  incorrect hints when using list-initialization.
 
 - Improved :doc:`google-build-namespaces
   ` check by replacing the local
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
index 8086caa2aa6f2c..63b4919608ff18 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
@@ -616,3 +616,26 @@ class Foo {
 #undef INVALID_HANDLE_VALUE
 #undef RGB
 }
+
+namespace GH77684 {
+struct S1 {
+// CHECK-MESSAGES: :[[@LINE+1]]:16: warning: 'M' should be initialized in a 
member initializer of the constructor 
[cppcoreguidelines-prefer-member-initializer]
+  S1() : M{} { M = 0; }
+// CHECK-FIXES: {{ S1.+M\{0\} }}
+  int M;
+};
+struct S2 {
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: 'M' should be initialized in a 
member initializer of the constructor 
[cppcoreguidelines-prefer-member-initializer]
+  S2() : M{2} { M = 1; }
+// CHECK-FIXES: {{ S2.+M\{1\} }}
+  int M;
+};
+struct T { int a; int b; int c; };
+T v;
+struct S3 {
+// CHECK-MESSAGES: :[[@LINE+1]]:21: warning: 'M' should be initialized in a 
member initializer of the constructor 
[cppcoreguidelines-prefer-member-initializer]
+  S3() : M{1,2,3} { M = v; }
+// CHECK-FIXES: {{ S3.+M\{v\} }}
+  T M;
+};
+}

>From 03ae7072afdf426406a4afd6e1e0a6b31c6ac00b Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 14 Feb 2024 23:17:12 +0800
Subject: [PATCH 2/2] fix comment

---
 .../cppcoreguidelines/PreferMemberInitializerCheck.cpp  | 6 +++---
 .../cppcoreguidelines/prefer-member-initializer.cpp | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index 7ede900d7ba7b1..5f046c502eb383 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -203,7 +203,7 @@ void PreferMemberInitializerCheck::check(
 SourceLocation InsertPos;
 SourceRange ReplaceRange;
 bool AddComma = false;
-bool AddBracket = fa

[clang] [llvm] [MC/DC] Refactor: Let MCDCConditionID int16_t with zero-origin (PR #81257)

2024-02-14 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/81257

>From b2e8b3eaa067844a5fa5643aca17dbb0f237182e Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Sat, 10 Feb 2024 00:08:36 +0900
Subject: [PATCH 1/2] [MC/DC] Refactor: Let MCDCConditionID int16_t with
 zero-origin

Also, Let NumConditions uint16_t
---
 clang/lib/CodeGen/CodeGenPGO.cpp  |  8 ++---
 clang/lib/CodeGen/CodeGenPGO.h|  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 30 +--
 clang/lib/CodeGen/CoverageMappingGen.h|  4 +--
 .../ProfileData/Coverage/CoverageMapping.h| 10 +++
 .../ProfileData/Coverage/CoverageMapping.cpp  | 25 
 .../Coverage/CoverageMappingReader.cpp| 17 ++-
 .../Coverage/CoverageMappingWriter.cpp|  6 ++--
 .../ProfileData/CoverageMappingTest.cpp   | 18 +--
 9 files changed, 61 insertions(+), 59 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 5d7c3847745762..9025889f443b88 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -1033,7 +1033,7 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) {
 
   std::string CoverageMapping;
   llvm::raw_string_ostream OS(CoverageMapping);
-  RegionCondIDMap.reset(new llvm::DenseMap);
+  RegionCondIDMap.reset(new llvm::DenseMap);
   CoverageMappingGen MappingGen(
   *CGM.getCoverageMapping(), CGM.getContext().getSourceManager(),
   CGM.getLangOpts(), RegionCounterMap.get(), RegionMCDCBitmapMap.get(),
@@ -1198,8 +1198,8 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy 
&Builder, const Expr *S,
 return;
 
   // Extract the ID of the condition we are setting in the bitmap.
-  unsigned CondID = ExprMCDCConditionIDMapIterator->second;
-  assert(CondID > 0 && "Condition has no ID!");
+  auto CondID = ExprMCDCConditionIDMapIterator->second;
+  assert(CondID >= 0 && "Condition has no ID!");
 
   auto *I8PtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
 
@@ -1208,7 +1208,7 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy 
&Builder, const Expr *S,
   // the resulting value is used to update the boolean expression's bitmap.
   llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
   Builder.getInt64(FunctionHash),
-  Builder.getInt32(CondID - 1),
+  Builder.getInt32(CondID),
   MCDCCondBitmapAddr.getPointer(), Val};
   Builder.CreateCall(
   CGM.getIntrinsic(llvm::Intrinsic::instrprof_mcdc_condbitmap_update),
diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h
index 6596b6c3527764..5f2941cfb2e95e 100644
--- a/clang/lib/CodeGen/CodeGenPGO.h
+++ b/clang/lib/CodeGen/CodeGenPGO.h
@@ -37,7 +37,7 @@ class CodeGenPGO {
   uint64_t FunctionHash;
   std::unique_ptr> RegionCounterMap;
   std::unique_ptr> RegionMCDCBitmapMap;
-  std::unique_ptr> RegionCondIDMap;
+  std::unique_ptr> RegionCondIDMap;
   std::unique_ptr> StmtCountMap;
   std::unique_ptr ProfRecord;
   std::vector RegionCounts;
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 0c43317642bca4..d918acd951dd8c 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -587,8 +587,8 @@ struct EmptyCoverageMappingBuilder : public 
CoverageMappingBuilder {
 struct MCDCCoverageBuilder {
 
   struct DecisionIDPair {
-MCDCConditionID TrueID = 0;
-MCDCConditionID FalseID = 0;
+MCDCConditionID TrueID = -1;
+MCDCConditionID FalseID = -1;
   };
 
   /// The AST walk recursively visits nested logical-AND or logical-OR binary
@@ -684,11 +684,11 @@ struct MCDCCoverageBuilder {
   llvm::SmallVector DecisionStack;
   llvm::DenseMap &CondIDs;
   llvm::DenseMap &MCDCBitmapMap;
-  MCDCConditionID NextID = 1;
+  MCDCConditionID NextID = 0;
   bool NotMapped = false;
 
   /// Represent a sentinel value of [0,0] for the bottom of DecisionStack.
-  static constexpr DecisionIDPair DecisionStackSentinel{0, 0};
+  static constexpr DecisionIDPair DecisionStackSentinel{-1, -1};
 
   /// Is this a logical-AND operation?
   bool isLAnd(const BinaryOperator *E) const {
@@ -705,12 +705,12 @@ struct MCDCCoverageBuilder {
   /// Return whether the build of the control flow map is at the top-level
   /// (root) of a logical operator nest in a boolean expression prior to the
   /// assignment of condition IDs.
-  bool isIdle() const { return (NextID == 1 && !NotMapped); }
+  bool isIdle() const { return (NextID == 0 && !NotMapped); }
 
   /// Return whether any IDs have been assigned in the build of the control
   /// flow map, indicating that the map is being generated for this boolean
   /// expression.
-  bool isBuilding() const { return (NextID > 1); }
+  bool isBuilding() const { return (NextID > 0); }
 
   /// Set the given condition's ID.
   

[clang] [llvm] [AArch64] Add soft-float ABI (PR #74460)

2024-02-14 Thread Ties Stuij via cfe-commits

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

This seems like a sensible and unobtrusive solution to me. Also the change is 
backed by a change in the Arm ABI, and it looks like the other review comments 
have been addressed. I've also built this change locally and ran the lit tests, 
and everything passes.

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


[clang] [llvm] [AMDGPU] Add an option to disable unsafe uses of atomic xor (PR #69229)

2024-02-14 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

> We're gradually converging on something that looks like this, subject to bike 
> shedding the name

I did not know about this PR. It is interesting that our other discussions lead 
to similar solution.

I agree that per-instruction metadata is needed, and the metadata should convey 
separate control for fp atomic and unsupported integer atomic across PCIE.

The reason to use per-instruction metadata instead of per-function metadata or 
attribute is that per-function attribute does not work well for inlined 
functions.

As for controlling FE emitting this metadata, a more-fine-grained control e.g. 
pragma is desirable, however, for this patch, a clang option is probably 
sufficient. We could consider pragma control later.

We need to coin some good concise name for the metadata:

For unsafe fp atomic - unsafe_fp ?

For unsupported integer atomic across PCIE - unsafe_pcie ? fine_grained may not 
be suitable since fine_grained memory accessed across XGMI supports integer 
atomic AND/OR/XOR ops etc

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


[clang] [llvm] [AMDGPU] Add an option to disable unsafe uses of atomic xor (PR #69229)

2024-02-14 Thread via cfe-commits

b-sumner wrote:

We're aware of the concerns regarding atomics handling.   We're trying to find 
the approach which is least distasteful to all parties.  I expect we will 
address the concern raised here, but not necessarily in the same way.

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


[clang] [HIP] Allow partial linking for `-fgpu-rdc` (PR #81700)

2024-02-14 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/81700

>From 6006975bbff9fc0f6fb9b8e24a52d4963ceb774c Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Tue, 13 Feb 2024 10:00:21 -0500
Subject: [PATCH] [HIP] Allow partial linking for `-fgpu-rdc`

`-fgpu-rdc` mode allows device functions call device functions
in different TU. However, currently all device objects
have to be linked together since only one fat binary
is supported. This is time consuming for AMDGPU backend
since it only supports LTO.

There are use cases that objects can be divided into groups
in which device functions are self-contained but host functions
are not. It is desirable to link/optimize/codegen the device
code and generate a fatbin for each group, whereas partially
link the host code with `ld -r` or generate a static library
by using the `-emit-static-lib` option of clang. This avoids
linking all device code together, therefore decreases
the linking time for `-fgpu-rdc`.

Previously, clang emits an external symbol `__hip_fatbin`
for all objects for `-fgpu-rdc`. With this patch, clang
emits an unique external symbol `__hip_fatbin_{cuid}`
for the fat binary for each object. When a group of objects
are linked together to generate a fatbin, the symbols
are merged by alias and point to the same fat binary.
Each group has its own fat binary. One executable or
shared library can have multiple fat binaries. Device
linking is done for undefined fab binary symbols only
to avoid repeated linking. `__hip_gpubin_handle` is also
uniquefied and merged to avoid repeated registering.
Symbol `__hip_cuid_{cuid}` is introduced to facilitate
debugging and tooling.

Fixes: https://github.com/llvm/llvm-project/issues/77018
Change-Id: Ia16ac3ddb05b66e6149288aacb0ba4a80120ad8c
---
 clang/lib/CodeGen/CGCUDANV.cpp|  22 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |  10 +-
 clang/lib/Driver/ToolChains/HIPUtility.cpp| 237 +-
 clang/test/CodeGenCUDA/device-stub.cu |  10 +-
 .../test/CodeGenCUDA/host-used-device-var.cu  |   5 +-
 clang/test/Driver/hip-toolchain-rdc.hip   |  38 ++-
 6 files changed, 278 insertions(+), 44 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 5b43272bfa62f4..49f93451db7bbb 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -760,10 +760,10 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() 
{
   // to contain the fat binary but will be populated somewhere else,
   // e.g. by lld through link script.
   FatBinStr = new llvm::GlobalVariable(
-CGM.getModule(), CGM.Int8Ty,
-/*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr,
-"__hip_fatbin", nullptr,
-llvm::GlobalVariable::NotThreadLocal);
+  CGM.getModule(), CGM.Int8Ty,
+  /*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr,
+  "__hip_fatbin_" + CGM.getContext().getCUIDHash(), nullptr,
+  llvm::GlobalVariable::NotThreadLocal);
   cast(FatBinStr)->setSection(FatbinConstantName);
 }
 
@@ -816,8 +816,8 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
   // thread safety of the loaded program. Therefore we can assume sequential
   // execution of constructor functions here.
   if (IsHIP) {
-auto Linkage = CudaGpuBinary ? llvm::GlobalValue::InternalLinkage :
-llvm::GlobalValue::LinkOnceAnyLinkage;
+auto Linkage = CudaGpuBinary ? llvm::GlobalValue::InternalLinkage
+ : llvm::GlobalValue::ExternalLinkage;
 llvm::BasicBlock *IfBlock =
 llvm::BasicBlock::Create(Context, "if", ModuleCtorFunc);
 llvm::BasicBlock *ExitBlock =
@@ -826,11 +826,11 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() 
{
 // of HIP ABI.
 GpuBinaryHandle = new llvm::GlobalVariable(
 TheModule, PtrTy, /*isConstant=*/false, Linkage,
-/*Initializer=*/llvm::ConstantPointerNull::get(PtrTy),
-"__hip_gpubin_handle");
-if (Linkage == llvm::GlobalValue::LinkOnceAnyLinkage)
-  GpuBinaryHandle->setComdat(
-  CGM.getModule().getOrInsertComdat(GpuBinaryHandle->getName()));
+/*Initializer=*/
+CudaGpuBinary ? llvm::ConstantPointerNull::get(PtrTy) : nullptr,
+CudaGpuBinary
+? "__hip_gpubin_handle"
+: "__hip_gpubin_handle_" + CGM.getContext().getCUIDHash());
 GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getAsAlign());
 // Prevent the weak symbol in different shared libraries being merged.
 if (Linkage != llvm::GlobalValue::InternalLinkage)
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c984260b082cd1..218066bced6c19 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -919,7 +919,15 @@ void CodeGenModule::Release() {
 llvm::ConstantArray::get(ATy, UsedArray), "__cla

[clang] bad error message on incorrect string literal #18079 (PR #81670)

2024-02-14 Thread Jon Roelofs via cfe-commits

jroelofs wrote:

Feel free to keep it open and push more commits to the branch.

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


[clang] [clang][Interp] Do r-to-l conversion immediately when returning (PR #80662)

2024-02-14 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -119,12 +121,26 @@ template  bool 
EvalEmitter::emitRet(const SourceInfo &Info) {
 template <> bool EvalEmitter::emitRet(const SourceInfo &Info) {
   if (!isActive())
 return true;
-  EvalResult.setPointer(S.Stk.pop());
+
+  const Pointer &Ptr = S.Stk.pop();
+  // Implicitly convert lvalue to rvalue, if requested.
+  if (ConvertResultToRValue) {
+if (std::optional V = Ptr.toRValue(Ctx)) {
+  EvalResult.setValue(*V);
+} else {
+  return false;
+}
+  } else {
+EvalResult.setPointer(Ptr);
+  }
+
   return true;
 }
 template <> bool EvalEmitter::emitRet(const SourceInfo &Info) {
   if (!isActive())
 return true;
+  // Function pointers are always lvalues to us and cannot be converted
+  // to rvalues, so don't do any conversion here.

tbaederr wrote:

I've reworded the comment.

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


[clang] [clang][Interp] Do r-to-l conversion immediately when returning (PR #80662)

2024-02-14 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/80662

>From c10713b9a6494aa052541c4ac3a296d83a890867 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 14 Feb 2024 15:29:18 +0100
Subject: [PATCH 1/3] [clang][Interp][NFC] Make a local variable const

---
 clang/lib/AST/Interp/Source.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/Source.cpp b/clang/lib/AST/Interp/Source.cpp
index 4e032c92d26df1..45cd0ad4fd4273 100644
--- a/clang/lib/AST/Interp/Source.cpp
+++ b/clang/lib/AST/Interp/Source.cpp
@@ -33,7 +33,7 @@ SourceRange SourceInfo::getRange() const {
 }
 
 const Expr *SourceInfo::asExpr() const {
-  if (auto *S = Source.dyn_cast())
+  if (const auto *S = Source.dyn_cast())
 return dyn_cast(S);
   return nullptr;
 }

>From beccd36e34a067a7193b32c27656dca1a38116d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 14 Feb 2024 15:29:47 +0100
Subject: [PATCH 2/3] [clang][Interp] Fix variadic member functions

For variadic member functions, the way we calculated the instance
pointer and RVO pointer offsts on the stack was incorrect, due
to Func->getArgSize() not returning the full size of all the
passed arguments. When calling variadic functions, we need
to pass the size of the passed (variadic) arguments to the Call*
ops, so they can use that information to properly check the
instance pointer, etc.

This patch adds a bit of code duplication in Interp.h, which I
will get rid of in later cleanup NFC patches.
---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 45 +++---
 clang/lib/AST/Interp/ByteCodeStmtGen.cpp |  2 +-
 clang/lib/AST/Interp/Context.cpp |  3 +-
 clang/lib/AST/Interp/EvalEmitter.cpp |  2 +-
 clang/lib/AST/Interp/Function.h  | 10 
 clang/lib/AST/Interp/Interp.cpp  | 25 +---
 clang/lib/AST/Interp/Interp.h| 76 
 clang/lib/AST/Interp/InterpFrame.cpp | 11 ++--
 clang/lib/AST/Interp/InterpFrame.h   |  5 +-
 clang/lib/AST/Interp/Opcodes.td  | 11 +++-
 clang/test/AST/Interp/functions.cpp  | 75 +++
 11 files changed, 226 insertions(+), 39 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 91b9985eefbd30..988765972a36e6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1829,8 +1829,19 @@ bool ByteCodeExprGen::VisitCXXConstructExpr(
 return false;
 }
 
-if (!this->emitCall(Func, E))
-  return false;
+if (Func->isVariadic()) {
+  uint32_t VarArgSize = 0;
+  unsigned NumParams = Func->getNumWrittenParams();
+  for (unsigned I = NumParams, N = E->getNumArgs(); I != N; ++I) {
+VarArgSize +=
+
align(primSize(classify(E->getArg(I)->getType()).value_or(PT_Ptr)));
+  }
+  if (!this->emitCallVar(Func, VarArgSize, E))
+return false;
+} else {
+  if (!this->emitCall(Func, 0, E))
+return false;
+}
 
 // Immediately call the destructor if we have to.
 if (DiscardResult) {
@@ -1863,7 +1874,7 @@ bool ByteCodeExprGen::VisitCXXConstructExpr(
   return false;
   }
 
-  if (!this->emitCall(Func, E))
+  if (!this->emitCall(Func, 0, E))
 return false;
 }
 return true;
@@ -2049,7 +2060,7 @@ bool 
ByteCodeExprGen::VisitCXXInheritedCtorInitExpr(
 Offset += align(primSize(PT));
   }
 
-  return this->emitCall(F, E);
+  return this->emitCall(F, 0, E);
 }
 
 template 
@@ -2846,20 +2857,38 @@ bool ByteCodeExprGen::VisitCallExpr(const 
CallExpr *E) {
 // and if the function has RVO, we already have the pointer on the stack to
 // write the result into.
 if (IsVirtual && !HasQualifier) {
-  if (!this->emitCallVirt(Func, E))
+  uint32_t VarArgSize = 0;
+  unsigned NumParams = Func->getNumWrittenParams();
+  for (unsigned I = NumParams, N = E->getNumArgs(); I != N; ++I)
+VarArgSize += align(primSize(classify(E->getArg(I)).value_or(PT_Ptr)));
+
+  if (!this->emitCallVirt(Func, VarArgSize, E))
+return false;
+} else if (Func->isVariadic()) {
+  uint32_t VarArgSize = 0;
+  unsigned NumParams = Func->getNumWrittenParams();
+  for (unsigned I = NumParams, N = E->getNumArgs(); I != N; ++I)
+VarArgSize += align(primSize(classify(E->getArg(I)).value_or(PT_Ptr)));
+  if (!this->emitCallVar(Func, VarArgSize, E))
 return false;
 } else {
-  if (!this->emitCall(Func, E))
+  if (!this->emitCall(Func, 0, E))
 return false;
 }
   } else {
 // Indirect call. Visit the callee, which will leave a FunctionPointer on
 // the stack. Cleanup of the returned value if necessary will be done after
 // the function call completed.
+
+// Sum the size of all args from the call 

[clang] 2347a47 - [clang][Interp][NFC] Make a local variable const

2024-02-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-14T17:34:07+01:00
New Revision: 2347a47622718259c95993c1cab604ad82854b6c

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

LOG: [clang][Interp][NFC] Make a local variable const

Added: 


Modified: 
clang/lib/AST/Interp/Source.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Source.cpp b/clang/lib/AST/Interp/Source.cpp
index 4e032c92d26df1..45cd0ad4fd4273 100644
--- a/clang/lib/AST/Interp/Source.cpp
+++ b/clang/lib/AST/Interp/Source.cpp
@@ -33,7 +33,7 @@ SourceRange SourceInfo::getRange() const {
 }
 
 const Expr *SourceInfo::asExpr() const {
-  if (auto *S = Source.dyn_cast())
+  if (const auto *S = Source.dyn_cast())
 return dyn_cast(S);
   return nullptr;
 }



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


[clang] [C23] No longer assert on huge enumerator values (PR #81760)

2024-02-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)


Changes

C23 added the wb and uwb suffixes to generate a bit-precise integer value. 
These values can be larger than what is representable in intmax_t or uintmax_t.

We were asserting that an enumerator constant could not have a value larger 
than unsigned long long but that's now a possibility. This patch turns the 
assertion into a "value too large" diagnostic.

Note, we do not yet implement WG14 N3029 and so the behavior of this patch will 
cause the enumerator to be cast to unsigned long long, but this behavior may 
change in the future. GCC selects __uint128_t as the underlying type for such 
an enumeration and we may want to match that behavior in the future. This patch 
has several FIXME comments related to this and the release notes call out the 
possibility of a change in behavior in the future.

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

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+8) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+7-2) 
- (modified) clang/test/Sema/enum.c (+23) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6cf48d63dd512e..31fd161c65fc32 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -169,6 +169,14 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses friend declarations with an ``enum`` 
elaborated-type-specifier in language modes after C++98.
 
+- Now diagnoses an enumeration constant whose value is larger than can be
+  represented by ``unsigned long long``, which can happen with a large constant
+  using the ``wb`` or ``uwb`` suffix. The maximal underlying type is currently
+  ``unsigned long long``, but this behavior may change in the future when Clang
+  implements
+  `WG14 N3029 `_.
+  Fixes `#69352 `_.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 09a35fddba1954..52cb2c838c6e47 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -20317,8 +20317,13 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, 
SourceRange BraceRange,
? Context.UnsignedLongTy : Context.LongTy;
 } else {
   BestWidth = Context.getTargetInfo().getLongLongWidth();
-  assert(NumPositiveBits <= BestWidth &&
- "How could an initializer get larger than ULL?");
+  if (NumPositiveBits > BestWidth) {
+// This can happen with bit-precise integer types, but those are not
+// allowed as the type for an enumerator per C23 6.7.2.2p4 and p12.
+// FIXME: GCC uses __int128_t and __uint128_t for cases that fit within
+// a 128-bit integer, we should consider doing the same.
+Diag(Enum->getLocation(), diag::ext_enum_too_large);
+  }
   BestType = Context.UnsignedLongLongTy;
   BestPromotionType
 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index f8e380bd62d1ea..c5255dfdf16faf 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify 
-pedantic
+// RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -std=c23 
-verify -pedantic
 enum e {A,
 B = 42LL << 32,// expected-warning {{ISO C restricts 
enumerator values to range of 'int'}}
   C = -4, D = 12456 };
@@ -167,3 +168,25 @@ enum struct GH42372_1 { // expected-error {{expected 
identifier or '{'}}
 enum class GH42372_2 {
   One
 };
+
+#if __STDC_VERSION__ >= 202311L
+// FIXME: GCC picks __uint128_t as the underlying type for the enumeration
+// value and Clang picks unsigned long long.
+// FIXME: Clang does not yet implement WG14 N3029, so the warning about
+// restricting enumerator values to 'int' is not correct.
+enum GH59352 { // expected-warning {{enumeration values exceed range of 
largest integer}}
+ BigVal = wb // expected-warning {{ISO C restricts 
enumerator values to range of 'int' ( is too large)}}
+};
+_Static_assert(BigVal == wb); /* expected-error {{static 
assertion failed due to requirement 'BigVal == wb'}}
+ expected-note 
{{expression evaluates to '11326434445538011818 == '}}
+   */
+_Static_assert(
+_Generic(BigVal, // expected-error {{static 
assertion failed}}
+_BitInt(67) : 0,
+__INTMAX_TYPE__ : 0,
+__UINTMAX_TYPE__ : 0,
+__int128_t : 0,
+__uint128_t : 1
+)
+);
+#endif // __STDC

[clang] [clang][Interp] Do r-to-l conversion immediately when returning (PR #80662)

2024-02-14 Thread Aaron Ballman via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


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

LGTM!

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


[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

2024-02-14 Thread via cfe-commits

Sirraide wrote:

@cor3ntin ping

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


[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread Nick Desaulniers via cfe-commits

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

I think this patch is good to go. Thanks for working on it!

cc @AaronBallman @efriedma-quic @rjmccall @nikic in case there's any last 
minute concerns.  I'm happy to sign off on this, but consider giving folks some 
time to speak up before landing this.

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


  1   2   3   4   >