[clang] [RISCV] Add sched model for XiangShan-NanHu (PR #70232)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -20,6 +20,17 @@
 // MCPU-SYNTACORE-SCR1-MAX: "-target-feature" "+zicsr" "-target-feature" 
"+zifencei"
 // MCPU-SYNTACORE-SCR1-MAX: "-target-abi" "ilp32"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=xiangshan-nanhu | 
FileCheck -check-prefix=MCPU-XIANGSHAN-NANHU %s
+// MCPU-XIANGSHAN-NANHU: "-nostdsysteminc" "-target-cpu" "xiangshan-nanhu"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+f" "-target-feature" "+d"

MaskRay wrote:

Prefer `-SAME` for strings on the same line

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


[clang] [RISCV] Add sched model for XiangShan-NanHu (PR #70232)

2023-10-25 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

> Can you separate out the basic processor definition (using NoSchedModel), and 
> a patch which adds the scheduling model? We can at least get the processor 
> definition landed while we iterate on the scheduling related pieces.
> 
> edit: For clarity, I'm requesting that the basic processor definition and 
> test updates be made into its own pull request, and that this pull request be 
> reserved for adding the schedule model on top.

Posted as #70294.

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -1360,6 +1372,9 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const 
MCAsmLayout ) {
 
   // Calculate indices for undefined symbols.
   for (auto  : UndefinedCsects) {
+// AIX does not need to emit for the _$TLSML symbol.
+if (Csect.getSymbolTableName().equals(StringRef("_$TLSML")))

MaskRay wrote:

`== "..."`

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -649,6 +649,14 @@ void XCOFFObjectWriter::recordRelocation(MCAssembler ,
  uint64_t ) {
   auto getIndex = [this](const MCSymbol *Sym,
  const MCSectionXCOFF *ContainingCsect) {
+// Fixup relocation flag for AIX TLS local-dynamic mode.
+if (Sym->getName().equals("_Renamed..5f24__TLSML[UA]")) {

MaskRay wrote:

We generally prefer `==` over `equals`

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -145,9 +160,78 @@ namespace {
   .addImm(0);
 
 if (IsAIX) {
-  // The variable offset and region handle are copied in r4 and r3. The
-  // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-  if (!IsTLSTPRelMI) {
+  if (IsTLSLDAIXMI) {
+// The relative order between the LoadOffset@toc node, and the
+// ._tls_get_mod node is being tuned here. It is better to put the
+// LoadOffset@toc node after the call, since the LoadOffset@toc 
node
+// can use clobbers r4/r5. Search for the pattern of two Load@toc
+// nodes, and then move the LoadOffset@toc node right before the
+// node that uses the OutReg of the ._tls_get_mod node.
+unsigned LDTocOp =
+Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
+: (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
+if (!RegInfo.use_empty(OutReg)) {
+  std::set Uses;
+  // Collect all instructions that use the OutReg.
+  for (MachineOperand  : RegInfo.use_operands(OutReg))
+Uses.insert(MO.getParent());
+  // Find the first user (e.g.: lwax/stfdx) within the current BB.
+  MachineBasicBlock::iterator UseIter = MBB.begin();
+  for (MachineBasicBlock::iterator IE = MBB.end(); UseIter != IE;
+   ++UseIter)
+if (Uses.count(&*UseIter))
+  break;
+
+  if (UseIter != MBB.end()) {
+// Collect associated Load@toc nodes.
+std::set LoadFromTocs;
+for (MachineOperand  : UseIter->operands())
+  if (MO.isReg() && MO.isUse()) {
+if (RegInfo.hasOneDef(MO.getReg())) {
+  MachineInstr *Temp =
+  RegInfo.getOneDef(MO.getReg())->getParent();
+  if (Temp ==  && RegInfo.hasOneDef(InReg))
+Temp = RegInfo.getOneDef(InReg)->getParent();
+  if (Temp->getOpcode() == LDTocOp)
+LoadFromTocs.insert(Temp);
+} else {
+  // FIXME: analyze this scenario if there is one.
+  LoadFromTocs.clear();
+  break;
+}
+  }
+
+// Check the two Load@toc: one should be _$TLSML, and the other
+// will be moved before the node that uses the OutReg of the
+// ._tls_get_mod node.
+if (LoadFromTocs.size() == 2) {
+  MachineBasicBlock::iterator TLSMLIter = MBB.end();
+  MachineBasicBlock::iterator OffsetIter = MBB.end();
+  for (MachineBasicBlock::iterator I = MBB.begin(),
+   IE = MBB.end();
+   I != IE; ++I)
+if (LoadFromTocs.count(&*I)) {
+  if (I->getOperand(1).isGlobal() &&
+  I->getOperand(1).getGlobal()->getName().equals(

MaskRay wrote:

`== ...`

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


[clang] [RISCV] Add processor definition for XiangShan-NanHu (PR #70294)

2023-10-25 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw created 
https://github.com/llvm/llvm-project/pull/70294

This PR adds the processor definition for XiangShan-NanHu, an open-source 
high-performance RISC-V processor.

According to the official 
[documentation](https://xiangshan-doc.readthedocs.io/zh-cn/latest/arch/), NanHu 
core supports 
`RV64IMAFDC_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh_zksed_zksh_svinval`. 
I found that NanHu also supports `zicbom` and `zicboz`. You can find them in 
the [source 
code](https://github.com/OpenXiangShan/XiangShan/blob/5931ace35325a644a12f8ea27830a2de7489e7e7/src/main/scala/xiangshan/backend/decode/DecodeUnit.scala#L426-L436).
 Features supported by NanHu have been confirmed by @poemonsense.

See also #70232.


>From a4e46c81c5235754bf7b4e0b3dd3ff8805b3e56d Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Thu, 26 Oct 2023 13:47:39 +0800
Subject: [PATCH] [RISCV] Add processor definition for XiangShan-NanHu

Co-authored-by: SForeKeeper 
---
 clang/test/Driver/riscv-cpus.c| 14 ++
 clang/test/Misc/target-invalid-cpu-note.c |  4 ++--
 llvm/lib/Target/RISCV/RISCVProcessors.td  | 21 +
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index 3eaceedce685fc6..70f0a63336bd478 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -20,6 +20,17 @@
 // MCPU-SYNTACORE-SCR1-MAX: "-target-feature" "+zicsr" "-target-feature" 
"+zifencei"
 // MCPU-SYNTACORE-SCR1-MAX: "-target-abi" "ilp32"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=xiangshan-nanhu | 
FileCheck -check-prefix=MCPU-XIANGSHAN-NANHU %s
+// MCPU-XIANGSHAN-NANHU: "-nostdsysteminc" "-target-cpu" "xiangshan-nanhu"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+f" "-target-feature" "+d"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+c"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+zicbom" "-target-feature" 
"+zicboz" "-target-feature" "+zicsr" "-target-feature" "+zifencei"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+zba" "-target-feature" "+zbb" 
"-target-feature" "+zbc"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+zbkb" "-target-feature" "+zbkc" 
"-target-feature" "+zbkx" "-target-feature" "+zbs"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+zkn" "-target-feature" "+zknd" 
"-target-feature" "+zkne" "-target-feature" "+zknh"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+zks" "-target-feature" "+zksed" 
"-target-feature" "+zksh" "-target-feature" "+svinval"
+// MCPU-XIANGSHAN-NANHU: "-target-abi" "lp64d"
+
 // We cannot check much for -mcpu=native, but it should be replaced by a valid 
CPU string.
 // RUN: %clang --target=riscv64 -### -c %s -mcpu=native 2> %t.err || true
 // RUN: FileCheck --input-file=%t.err -check-prefix=MCPU-NATIVE %s
@@ -62,6 +73,9 @@
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=veyron-v1 | FileCheck 
-check-prefix=MTUNE-VEYRON-V1 %s
 // MTUNE-VEYRON-V1: "-tune-cpu" "veyron-v1"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-nanhu | 
FileCheck -check-prefix=MTUNE-XIANGSHAN-NANHU %s
+// MTUNE-XIANGSHAN-NANHU: "-tune-cpu" "xiangshan-nanhu"
+
 // Check mtune alias CPU has resolved to the right CPU according XLEN.
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=generic | FileCheck 
-check-prefix=MTUNE-GENERIC-32 %s
 // MTUNE-GENERIC-32: "-tune-cpu" "generic"
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index b2a04ebdbce628f..8e91eb4c62dd259 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -85,7 +85,7 @@
 
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
-// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, 
sifive-x280, veyron-v1{{$}}
+// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, 
sifive-x280, veyron-v1, xiangshan-nanhu{{$}}
 
 // RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
 // TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
@@ -93,4 +93,4 @@
 
 // RUN: not %clang_cc1 -triple riscv64 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV64
 // TUNE-RISCV64: error: unknown target CPU 'not-a-cpu'
-// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, 
rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, 
sifive-u74, sifive-x280, veyron-v1, generic, rocket, sifive-7-series{{$}}
+// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, 
rocket-rv64, sifive-s21, sifive-s51, sifive-s54, 

[clang] [RecursiveASTVisitor] Fix RecursiveASTVisitor (RAV) fails to visit the initializer of a bitfield (PR #69557)

2023-10-25 Thread via cfe-commits

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

LGTM, thanks!

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


[clang] [RecursiveASTVisitor] Fix RecursiveASTVisitor (RAV) fails to visit the initializer of a bitfield (PR #69557)

2023-10-25 Thread via cfe-commits


@@ -650,6 +650,9 @@ Bug Fixes to AST Handling
   `Issue 64170 `_
 - Fixed ``hasAnyBase`` not binding nodes in its submatcher.
   (`#65421 `_)
+- Fixed a bug where RecursiveASTVisitor (RAV) fails to visit the

cor3ntin wrote:

```suggestion
- Fixed a bug where RecursiveASTVisitor fails to visit the
```

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


[clang] Adding Separate OpenMP Offloading Backend to `libcxx/include/__algorithm/pstl_backends` (PR #66968)

2023-10-25 Thread Anton Rydahl via cfe-commits

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Thanks for the cleanup!

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


[clang] [AIX][TOC] Add -mtocdata/-mno-tocdata options on AIX (PR #67999)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -3426,6 +3426,29 @@ def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">,
   MetaVarName<"">,
   HelpText<"Load pass plugin from a dynamic shared object file (only with new 
pass manager).">,
   MarshallingInfoStringVector>;
+def mtocdata : Flag<["-"], "mtocdata">,
+  Visibility<[ClangOption, CLOption, DXCOption, CC1Option]>,

MaskRay wrote:

cl/dxc don't use Power ISA. Remove them.

Use `BoolOption<"m", "tocdata", ...`

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


[clang] [AIX][TOC] Add -mtocdata/-mno-tocdata options on AIX (PR #67999)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -93,6 +93,8 @@ def err_fe_backend_error_attr :
 def warn_fe_backend_warning_attr :
   Warning<"call to '%0' declared with 'warning' attribute: %1">, BackendInfo,
   InGroup;
+def warn_toc_unsupported_type : Warning<"The -mtocdata option is ignored "

MaskRay wrote:

Please check the existing diagnostic style. They do not use capitalization or 
trailing period.
"the" is often omitted.

-mtocdata is ignored for ... because ...

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -525,6 +525,11 @@
 // CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
 // CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
 
+// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-VERIFY-MACHINE-CODE %s
+// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s

MaskRay wrote:

If you want to strengthen this RUN line, `-fverify-machine-code 
-fno-verify-machine-code`

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Fangrui Song via cfe-commits

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Fangrui Song via cfe-commits

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


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


[clang] [clang] Language to String function (PR #69487)

2023-10-25 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

What is the intended use for this?

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


[clang-tools-extra] f5063bf - [clang-tidy][NFC]refactor PreferMemberInitializerCheck for readability

2023-10-25 Thread Congcong Cai via cfe-commits

Author: Congcong Cai
Date: 2023-10-26T13:37:50+08:00
New Revision: f5063bf7edbb6368deb7354b4340eb62b8329d2e

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

LOG: [clang-tidy][NFC]refactor PreferMemberInitializerCheck for readability

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index aac824f15fa5707..0ef13ae29803325 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -178,140 +178,140 @@ void PreferMemberInitializerCheck::check(
 const FieldDecl *Field = nullptr;
 const Expr *InitValue = nullptr;
 std::tie(Field, InitValue) = isAssignmentToMemberOf(Class, S, Ctor);
-if (Field) {
-  if (IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
-  Ctor->isDefaultConstructor() &&
-  (getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
-  !Field->hasInClassInitializer() &&
-  (!isa(Class->getDeclContext()) ||
-   !cast(Class->getDeclContext())->isUnion()) &&
-  shouldBeDefaultMemberInitializer(InitValue)) {
-
-bool InvalidFix = false;
-SourceLocation FieldEnd =
-Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
-   *Result.SourceManager, getLangOpts());
-InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
-SourceLocation SemiColonEnd;
-if (auto NextToken = Lexer::findNextToken(
-S->getEndLoc(), *Result.SourceManager, getLangOpts()))
-  SemiColonEnd = NextToken->getEndLoc();
-else
-  InvalidFix = true;
-auto Diag =
-diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
-   " default member initializer")
-<< Field;
-if (InvalidFix)
+if (!Field)
+  continue;
+const bool IsInDefaultMemberInitializer =
+IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
+Ctor->isDefaultConstructor() &&
+(getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
+!Field->hasInClassInitializer() &&
+(!isa(Class->getDeclContext()) ||
+ !cast(Class->getDeclContext())->isUnion()) &&
+shouldBeDefaultMemberInitializer(InitValue);
+if (IsInDefaultMemberInitializer) {
+  bool InvalidFix = false;
+  SourceLocation FieldEnd =
+  Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
+ *Result.SourceManager, getLangOpts());
+  InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
+  SourceLocation SemiColonEnd;
+  if (auto NextToken = Lexer::findNextToken(
+  S->getEndLoc(), *Result.SourceManager, getLangOpts()))
+SemiColonEnd = NextToken->getEndLoc();
+  else
+InvalidFix = true;
+  auto Diag =
+  diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
+ " default member initializer")
+  << Field;
+  if (InvalidFix)
+continue;
+  CharSourceRange StmtRange =
+  CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);
+
+  SmallString<128> Insertion(
+  {UseAssignment ? " = " : "{",
+   Lexer::getSourceText(
+   CharSourceRange(InitValue->getSourceRange(), true),
+   *Result.SourceManager, getLangOpts()),
+   UseAssignment ? "" : "}"});
+
+  Diag << FixItHint::CreateInsertion(FieldEnd, Insertion)
+   << FixItHint::CreateRemoval(StmtRange);
+
+} else {
+  StringRef InsertPrefix = "";
+  bool HasInitAlready = false;
+  SourceLocation InsertPos;
+  SourceRange ReplaceRange;
+  bool AddComma = false;
+  bool InvalidFix = false;
+  unsigned Index = Field->getFieldIndex();
+  const CXXCtorInitializer *LastInListInit = nullptr;
+  for (const CXXCtorInitializer *Init : Ctor->inits()) {
+if (!Init->isWritten() || Init->isInClassMemberInitializer())
   continue;
-CharSourceRange StmtRange =
-CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);
-
-SmallString<128> Insertion(
-{UseAssignment ? " = " : "{",
- Lexer::getSourceText(
- CharSourceRange(InitValue->getSourceRange(), true),
- *Result.SourceManager, getLangOpts()),
- UseAssignment ? "" : "}"});

[clang] [clang] Bail out if the result of function template instantiation is not a function type. (PR #69459)

2023-10-25 Thread Shafik Yaghmour via cfe-commits


@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s
+
+template 
+using Type = typename A::NestedType; // expected-error {{type 'float' cannot 
be used prior to '::' because it has no members}}
+
+template 
+void Func() {
+  using MyType = Type(); // expected-note {{in instantiation of template 
type alias 'Type' requested here}}
+  // This is a function declaration, not a variable declaration!
+  // After substitution, we do not have a valid function type, and used to 
crash.
+  MyType var;
+}
+
+void Test() {
+  Func(); // expected-note {{in instantiation of function template 
specialization 'Func' requested here}}
+}

shafik wrote:

Files should have newlines at the end.

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


[clang] [clang] Bail out if the result of function template instantiation is not a function type. (PR #69459)

2023-10-25 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Please next time add a detailed description to your PR. This is key for 
reviewers to fully understand at a glance what the fix is for.

This is also key for users of git log to be able to understand changes at a 
glance without having to dig in. Folks often use git log to track down recent 
changes to explain changes in behavior.

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


[clang] [PassBuilder] Add a mechanism for adding passbuilder callbacks for static builds (PR #70171)

2023-10-25 Thread William Moses via cfe-commits

https://github.com/wsmoses updated 
https://github.com/llvm/llvm-project/pull/70171

>From 227a494be06d8cb3b590c78f52f717bd781a8f0e Mon Sep 17 00:00:00 2001
From: "William S. Moses" 
Date: Wed, 25 Oct 2023 02:10:32 -0500
Subject: [PATCH] [PassBuilder] Add a mechanism for adding passbuilder
 callbacks without an extension mechanism or dlopen of plugin

---
 clang/include/clang/Basic/CodeGenOptions.h|  6 ++
 clang/lib/CodeGen/BackendUtil.cpp |  3 +
 clang/test/CMakeLists.txt |  1 +
 clang/test/DriverPlugin/plugintest.c  |  6 ++
 clang/tools/CMakeLists.txt|  1 +
 .../clang-hello-plugin-test/CMakeLists.txt| 59 +
 .../clang-hello-plugin-test/helloplugin.cpp   | 66 +++
 clang/tools/driver/cc1_main.cpp   |  9 +++
 llvm/include/llvm/Passes/PassBuilder.h|  5 ++
 9 files changed, 156 insertions(+)
 create mode 100644 clang/test/DriverPlugin/plugintest.c
 create mode 100644 clang/tools/clang-hello-plugin-test/CMakeLists.txt
 create mode 100644 clang/tools/clang-hello-plugin-test/helloplugin.cpp

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 12be4e0025a7054..c8e2544f891cc2b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -26,6 +26,9 @@
 #include 
 #include 
 
+namespace llvm {
+class PassBuilder;
+}
 namespace clang {
 
 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
@@ -408,6 +411,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// List of dynamic shared object files to be loaded as pass plugins.
   std::vector PassPlugins;
 
+  /// List of pass builder callbacks.
+  std::vector> PassBuilderCallbacks;
+
   /// Path to allowlist file specifying which objects
   /// (files, functions) should exclusively be instrumented
   /// by sanitizer coverage pass.
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..a8db38fce6425fb 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -906,6 +906,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   << PluginFN << toString(PassPlugin.takeError());
 }
   }
+  for (auto PassCallback : CodeGenOpts.PassBuilderCallbacks) {
+PassCallback(PB);
+  }
 #define HANDLE_EXTENSION(Ext)  
\
   get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
 #include "llvm/Support/Extension.def"
diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 31b494f39cce577..a64dfe467c43abc 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -62,6 +62,7 @@ list(APPEND CLANG_TEST_DEPS
   apinotes-test
   c-index-test
   clang
+  clang-hello-plugin-test
   clang-fuzzer-dictionary
   clang-resource-headers
   clang-format
diff --git a/clang/test/DriverPlugin/plugintest.c 
b/clang/test/DriverPlugin/plugintest.c
new file mode 100644
index 000..e80866f0d1dd2fe
--- /dev/null
+++ b/clang/test/DriverPlugin/plugintest.c
@@ -0,0 +1,6 @@
+// RUN: clang-hello-plugin-test %s -o /dev/null -S | FileCheck %s
+
+int myfunction() { return 0; }
+
+// CHECK: [HelloPass] Found function: myfunction
+
diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt
index f60db6ef0ba3454..9742e2a155a0d30 100644
--- a/clang/tools/CMakeLists.txt
+++ b/clang/tools/CMakeLists.txt
@@ -2,6 +2,7 @@ create_subdirectory_options(CLANG TOOL)
 
 add_clang_subdirectory(diagtool)
 add_clang_subdirectory(driver)
+add_clang_subdirectory(clang-hello-plugin-test)
 add_clang_subdirectory(apinotes-test)
 add_clang_subdirectory(clang-diff)
 add_clang_subdirectory(clang-format)
diff --git a/clang/tools/clang-hello-plugin-test/CMakeLists.txt 
b/clang/tools/clang-hello-plugin-test/CMakeLists.txt
new file mode 100644
index 000..2b951677542c217
--- /dev/null
+++ b/clang/tools/clang-hello-plugin-test/CMakeLists.txt
@@ -0,0 +1,59 @@
+set( LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Analysis
+  CodeGen
+  Core
+  IPO
+  AggressiveInstCombine
+  InstCombine
+  Instrumentation
+  MC
+  MCParser
+  ObjCARCOpts
+  Option
+  ScalarOpts
+  Support
+  TargetParser
+  TransformUtils
+  Vectorize
+  )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  set(support_plugins SUPPORT_PLUGINS)
+endif()
+
+add_clang_tool(clang-hello-plugin-test
+  ../driver/driver.cpp
+  ../driver/cc1_main.cpp
+  ../driver/cc1as_main.cpp
+  ../driver/cc1gen_reproducer_main.cpp
+  helloplugin.cpp
+  DEPENDS
+  intrinsics_gen
+  ${support_plugins}
+  GENERATE_DRIVER
+  )
+
+clang_target_link_libraries(clang-hello-plugin-test
+  PRIVATE
+  clangBasic
+  clangCodeGen
+  clangDriver
+  clangFrontend
+  clangFrontendTool
+  clangSerialization
+  )
+
+if(WIN32 AND NOT CYGWIN)
+  # Prevent versioning if the buildhost is targeting for Win32.
+else()
+  set_target_properties(clang-hello-plugin-test 

[clang] [Clang][Sema] Skip RecordDecl when checking scope of declarations (PR #69432)

2023-10-25 Thread Shafik Yaghmour via cfe-commits


@@ -19,4 +19,8 @@ void f2(void) {
   struct U u;
 }
 
-
+void f3(void) {

shafik wrote:

So unlike the original test case this one does not seem to cause a crash. Can 
we add a test case for that as well to verify we are fixing that issue as well.

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


[clang-tools-extra] [clang-tidy] Add StrictMode to cppcoreguidelines-pro-type-static-cast-downcast (PR #69529)

2023-10-25 Thread Piotr Zegar via cfe-commits


@@ -14,3 +14,11 @@ unrelated type ``Z``.
 This rule is part of the `Type safety (Type.2)
 
`_
 profile from the C++ Core Guidelines.
+
+Options
+---
+
+.. option:: StrictMode
+
+  When set to `false`, no warnings are emitted for casts on non-polymorphic
+  types. Default is `true`.

PiotrZSL wrote:

StrictMode=true, result in more warnings being produced (this is current 
behavior).
StickMode=false, will cause casts on non-polymorphic types to be ignored.


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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes (PR #69242)

2023-10-25 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] fd06155 - [clang-tidy] Improved cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes (#69242)

2023-10-25 Thread via cfe-commits

Author: Piotr Zegar
Date: 2023-10-26T07:16:25+02:00
New Revision: fd06155acb620b047fa1d586383f8738e17dbec3

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

LOG: [clang-tidy] Improved 
cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes (#69242)

Extended IgnoreConversionFromTypes option to include
types without a declaration, such as built-in types.

Added: 


Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
index 1b858db511f50a2..45fef9471d5211e 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -14,6 +14,7 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 
@@ -23,6 +24,26 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+namespace {
+
+AST_MATCHER_P(QualType, hasAnyType, std::vector, Names) {
+  if (Names.empty())
+return false;
+
+  std::string Name = Node.getLocalUnqualifiedType().getAsString();
+  return llvm::any_of(Names, [](StringRef Ref) { return Ref == Name; });
+}
+
+AST_MATCHER(FieldDecl, hasIntBitwidth) {
+  assert(Node.isBitField());
+  const ASTContext  = Node.getASTContext();
+  unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
+  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
+  return IntBitWidth == CurrentBitWidth;
+}
+
+} // namespace
+
 NarrowingConversionsCheck::NarrowingConversionsCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -53,25 +74,22 @@ void NarrowingConversionsCheck::storeOptions(
   Options.store(Opts, "PedanticMode", PedanticMode);
 }
 
-AST_MATCHER(FieldDecl, hasIntBitwidth) {
-  assert(Node.isBitField());
-  const ASTContext  = Node.getASTContext();
-  unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
-  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
-  return IntBitWidth == CurrentBitWidth;
-}
-
 void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
   // ceil() and floor() are guaranteed to return integers, even though the type
   // is not integral.
   const auto IsCeilFloorCallExpr = expr(callExpr(callee(functionDecl(
   hasAnyName("::ceil", "::std::ceil", "::floor", "::std::floor");
 
+  std::vector IgnoreConversionFromTypesVec =
+  utils::options::parseStringList(IgnoreConversionFromTypes);
+
   // We may want to exclude other types from the checks, such as `size_type`
   // and `
diff erence_type`. These are often used to count elements, represented
   // in 64 bits and assigned to `int`. Rarely are people counting >2B elements.
-  const auto IsConversionFromIgnoredType = hasType(namedDecl(
-  hasAnyName(utils::options::parseStringList(IgnoreConversionFromTypes;
+  const auto IsConversionFromIgnoredType =
+  anyOf(hasType(namedDecl(hasAnyName(IgnoreConversionFromTypesVec))),
+allOf(unless(hasType(namedDecl())),
+  
hasType(qualType(hasAnyType(IgnoreConversionFromTypesVec);
 
   // `IsConversionFromIgnoredType` will ignore narrowing calls from those 
types,
   // but not expressions that are promoted to an ignored type as a result of a

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 13003a118c36a51..c93775beb8aeaf5 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -243,6 +243,11 @@ Changes in existing checks
   coroutine functions and increase issue detection for cases involving type
   aliases with references.
 
+- Improved :doc:`cppcoreguidelines-narrowing-conversions
+  ` check by
+  extending the `IgnoreConversionFromTypes` option to include types without a
+  declaration, such as built-in types.
+
 - Improved :doc:`cppcoreguidelines-prefer-member-initializer
   ` check to
   ignore delegate constructors.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
index ab9aabf44ff68c5..91e908f535a0d40 

[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (PR #69501)

2023-10-25 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] af07d7b - [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (#69501)

2023-10-25 Thread via cfe-commits

Author: Piotr Zegar
Date: 2023-10-26T07:11:01+02:00
New Revision: af07d7ba883b6e4921820d88b6679f294a0b9fa5

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

LOG: [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (#69501)

Improved cppcoreguidelines-pro-type-const-cast check to ignore casts to
const type (controlled by option) and casts in implicitly invoked code.

Fixes #69319

Added: 


Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-const-cast.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-const-cast.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nonstandard-file-extension.test

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp
index ef803ab85fa0841..8c44c1bfb62b6c7 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp
@@ -14,13 +14,60 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+static bool hasConstQualifier(QualType Type) {
+  const QualType PtrType = Type->getPointeeType();
+  if (!PtrType.isNull())
+return hasConstQualifier(PtrType);
+
+  return Type.isConstQualified();
+}
+
+static bool hasVolatileQualifier(QualType Type) {
+  const QualType PtrType = Type->getPointeeType();
+  if (!PtrType.isNull())
+return hasVolatileQualifier(PtrType);
+  return Type.isVolatileQualified();
+}
+
+ProTypeConstCastCheck::ProTypeConstCastCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", false)) {}
+
+void ProTypeConstCastCheck::storeOptions(ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "StrictMode", StrictMode);
+}
+
 void ProTypeConstCastCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(cxxConstCastExpr().bind("cast"), this);
 }
 
 void ProTypeConstCastCheck::check(const MatchFinder::MatchResult ) {
   const auto *MatchedCast = Result.Nodes.getNodeAs("cast");
-  diag(MatchedCast->getOperatorLoc(), "do not use const_cast");
+  if (StrictMode) {
+diag(MatchedCast->getOperatorLoc(), "do not use const_cast");
+return;
+  }
+
+  const QualType TargetType = MatchedCast->getType().getCanonicalType();
+  const QualType SourceType =
+  MatchedCast->getSubExpr()->getType().getCanonicalType();
+
+  const bool RemovingConst =
+  hasConstQualifier(SourceType) && !hasConstQualifier(TargetType);
+  const bool RemovingVolatile =
+  hasVolatileQualifier(SourceType) && !hasVolatileQualifier(TargetType);
+
+  if (!RemovingConst && !RemovingVolatile) {
+// Cast is doing nothing.
+return;
+  }
+
+  diag(MatchedCast->getOperatorLoc(),
+   "do not use const_cast to remove%select{| const}0%select{| "
+   "and}2%select{| volatile}1 qualifier")
+  << RemovingConst << RemovingVolatile
+  << (RemovingConst && RemovingVolatile);
 }
 
 } // namespace clang::tidy::cppcoreguidelines

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h
index f7ae9bbb60dcda3..8d93633a321b53f 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h
@@ -13,19 +13,25 @@
 
 namespace clang::tidy::cppcoreguidelines {
 
-/// This check flags all instances of const_cast
+/// Imposes limitations on the use of const_cast within C++ code.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/pro-type-const-cast.html
 class ProTypeConstCastCheck : public ClangTidyCheck {
 public:
-  ProTypeConstCastCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  ProTypeConstCastCheck(StringRef Name, ClangTidyContext *Context);
   bool isLanguageVersionSupported(const LangOptions ) const override {
 return LangOpts.CPlusPlus;
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
+
+private:
+  const bool StrictMode;
 };
 

[clang-tools-extra] [clang-tidy] Support functional cast in bugprone-dangling-handle (PR #69067)

2023-10-25 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] 1097c71 - [clang-tidy] Support functional cast in bugprone-dangling-handle (#69067)

2023-10-25 Thread via cfe-commits

Author: Piotr Zegar
Date: 2023-10-26T07:10:39+02:00
New Revision: 1097c71dbeefaff0c353c90cb57bc07b6ede6383

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

LOG: [clang-tidy] Support functional cast in bugprone-dangling-handle (#69067)

Add support for constructor conversion based functional
cast. Allows to detect issues like:
const std::string_view test1 = std::string(a);

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
index 9ded699ba78e66b..d55df3a6d7b741b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -33,14 +33,20 @@ handleFrom(const 
ast_matchers::internal::Matcher ,
 
 ast_matchers::internal::Matcher handleFromTemporaryValue(
 const ast_matchers::internal::Matcher ) {
+
+  const auto TemporaryExpr = anyOf(
+  cxxBindTemporaryExpr(),
+  cxxFunctionalCastExpr(
+  hasCastKind(CK_ConstructorConversion),
+  hasSourceExpression(ignoringParenImpCasts(cxxBindTemporaryExpr();
   // If a ternary operator returns a temporary value, then both branches hold a
   // temporary value. If one of them is not a temporary then it must be copied
   // into one to satisfy the type of the operator.
   const auto TemporaryTernary = conditionalOperator(
-  hasTrueExpression(ignoringParenImpCasts(cxxBindTemporaryExpr())),
-  hasFalseExpression(ignoringParenImpCasts(cxxBindTemporaryExpr(;
+  hasTrueExpression(ignoringParenImpCasts(TemporaryExpr)),
+  hasFalseExpression(ignoringParenImpCasts(TemporaryExpr)));
 
-  return handleFrom(IsAHandle, anyOf(cxxBindTemporaryExpr(), 
TemporaryTernary));
+  return handleFrom(IsAHandle, anyOf(TemporaryExpr, TemporaryTernary));
 }
 
 ast_matchers::internal::Matcher isASequence() {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d1992e12130d65..ac95afd782e1dbe 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -207,6 +207,11 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`bugprone-dangling-handle
+  ` check to support functional
+  casting during type conversions at variable initialization, now with improved
+  compatibility for C++17 and later versions.
+
 - Improved :doc:`bugprone-lambda-function-name
   ` check by adding option
   `IgnoreMacros` to ignore warnings in macros.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
index 23cda5321764383..96c812617038a37 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
@@ -108,6 +108,14 @@ void Positives() {
   std::string_view view4(ReturnsAString());
   // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view 
outlives
   // CHECK-MESSAGES-CXX17: [[@LINE-2]]:26: warning: std::basic_string_view 
outlives
+
+  std::string_view view5 = std::string("test");
+  // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view 
outlives its value [bugprone-dangling-handle]
+  // CHECK-MESSAGES-CXX17: [[@LINE-2]]:28: warning: std::basic_string_view 
outlives its value [bugprone-dangling-handle]
+
+  std::string_view view6 = std::string{"test"};
+  // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view 
outlives its value [bugprone-dangling-handle]
+  // CHECK-MESSAGES-CXX17: [[@LINE-2]]:28: warning: std::basic_string_view 
outlives its value [bugprone-dangling-handle]
 }
 
 void OtherTypes() {



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


[clang] [PassBuilder] Add a mechanism for adding passbuilder callbacks for static builds (PR #70171)

2023-10-25 Thread William Moses via cfe-commits

https://github.com/wsmoses updated 
https://github.com/llvm/llvm-project/pull/70171

>From 5119368d060c886c6cb9c4209169604d191e6b4c Mon Sep 17 00:00:00 2001
From: "William S. Moses" 
Date: Wed, 25 Oct 2023 02:10:32 -0500
Subject: [PATCH] [PassBuilder] Add a mechanism for adding passbuilder
 callbacks without an extension mechanism or dlopen of plugin

---
 clang/include/clang/Basic/CodeGenOptions.h|  6 ++
 clang/lib/CodeGen/BackendUtil.cpp |  3 +
 clang/test/DriverPlugin/plugintest.c  |  6 ++
 clang/tools/CMakeLists.txt|  1 +
 .../driver-static-plugin-test/CMakeLists.txt  | 59 +
 .../driver-static-plugin-test/helloplugin.cpp | 66 +++
 clang/tools/driver/cc1_main.cpp   |  9 +++
 llvm/include/llvm/Passes/PassBuilder.h|  5 ++
 8 files changed, 155 insertions(+)
 create mode 100644 clang/test/DriverPlugin/plugintest.c
 create mode 100644 clang/tools/driver-static-plugin-test/CMakeLists.txt
 create mode 100644 clang/tools/driver-static-plugin-test/helloplugin.cpp

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 12be4e0025a7054..c8e2544f891cc2b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -26,6 +26,9 @@
 #include 
 #include 
 
+namespace llvm {
+class PassBuilder;
+}
 namespace clang {
 
 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
@@ -408,6 +411,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// List of dynamic shared object files to be loaded as pass plugins.
   std::vector PassPlugins;
 
+  /// List of pass builder callbacks.
+  std::vector> PassBuilderCallbacks;
+
   /// Path to allowlist file specifying which objects
   /// (files, functions) should exclusively be instrumented
   /// by sanitizer coverage pass.
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..a8db38fce6425fb 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -906,6 +906,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   << PluginFN << toString(PassPlugin.takeError());
 }
   }
+  for (auto PassCallback : CodeGenOpts.PassBuilderCallbacks) {
+PassCallback(PB);
+  }
 #define HANDLE_EXTENSION(Ext)  
\
   get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
 #include "llvm/Support/Extension.def"
diff --git a/clang/test/DriverPlugin/plugintest.c 
b/clang/test/DriverPlugin/plugintest.c
new file mode 100644
index 000..060eb43e10baef3
--- /dev/null
+++ b/clang/test/DriverPlugin/plugintest.c
@@ -0,0 +1,6 @@
+// RUN: clang-hello-plugin %s -o /dev/null -S | FileCheck %s
+
+int myfunction() { return 0; }
+
+// CHECK: [HelloPass] Found function: myfunction
+
diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt
index f60db6ef0ba3454..69c8cd413a6293b 100644
--- a/clang/tools/CMakeLists.txt
+++ b/clang/tools/CMakeLists.txt
@@ -2,6 +2,7 @@ create_subdirectory_options(CLANG TOOL)
 
 add_clang_subdirectory(diagtool)
 add_clang_subdirectory(driver)
+add_clang_subdirectory(driver-static-plugin-test)
 add_clang_subdirectory(apinotes-test)
 add_clang_subdirectory(clang-diff)
 add_clang_subdirectory(clang-format)
diff --git a/clang/tools/driver-static-plugin-test/CMakeLists.txt 
b/clang/tools/driver-static-plugin-test/CMakeLists.txt
new file mode 100644
index 000..61891ff7eb9e95b
--- /dev/null
+++ b/clang/tools/driver-static-plugin-test/CMakeLists.txt
@@ -0,0 +1,59 @@
+set( LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Analysis
+  CodeGen
+  Core
+  IPO
+  AggressiveInstCombine
+  InstCombine
+  Instrumentation
+  MC
+  MCParser
+  ObjCARCOpts
+  Option
+  ScalarOpts
+  Support
+  TargetParser
+  TransformUtils
+  Vectorize
+  )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  set(support_plugins SUPPORT_PLUGINS)
+endif()
+
+add_clang_tool(clang-hello-plugin
+  ../driver/driver.cpp
+  ../driver/cc1_main.cpp
+  ../driver/cc1as_main.cpp
+  ../driver/cc1gen_reproducer_main.cpp
+  helloplugin.cpp
+  DEPENDS
+  intrinsics_gen
+  ${support_plugins}
+  GENERATE_DRIVER
+  )
+
+clang_target_link_libraries(clang-hello-plugin
+  PRIVATE
+  clangBasic
+  clangCodeGen
+  clangDriver
+  clangFrontend
+  clangFrontendTool
+  clangSerialization
+  )
+
+if(WIN32 AND NOT CYGWIN)
+  # Prevent versioning if the buildhost is targeting for Win32.
+else()
+  set_target_properties(clang-hello-plugin PROPERTIES VERSION 
${CLANG_EXECUTABLE_VERSION})
+endif()
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(clang-hello-plugin)
+endif()
+
+add_dependencies(clang-hello-plugin clang-resource-headers)
diff --git a/clang/tools/driver-static-plugin-test/helloplugin.cpp 
b/clang/tools/driver-static-plugin-test/helloplugin.cpp
new file mode 100644
index 000..52551d12af0a350

[clang] [PassBuilder] Add a mechanism for adding passbuilder callbacks for static builds (PR #70171)

2023-10-25 Thread William Moses via cfe-commits

wsmoses wrote:

@jdoerfert added the example test

@efriedma-quic I've reworked the mechanism to not create a global variable 
within LLVM. Here this only applies to clang and enables two things:
1) Users of clang as a library can add a custom passbuilder callback by adding 
to codegenoptions
2) Those who want to modify clang codegen passes can statically link the 
requisite code (like in the example) to enable their functionality, without 
forking clang. This still requires a global variable, but here it is limited to 
the clang driver itself, so it should not create any version conflicts since 
the clang driver should not load a second clang driver.

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


[clang] [PassBuilder] Add a mechanism for adding passbuilder callbacks for static builds (PR #70171)

2023-10-25 Thread William Moses via cfe-commits

https://github.com/wsmoses updated 
https://github.com/llvm/llvm-project/pull/70171

>From ad9ed0260b1288efc3e8c7794f4de4592657474b Mon Sep 17 00:00:00 2001
From: "William S. Moses" 
Date: Wed, 25 Oct 2023 02:10:32 -0500
Subject: [PATCH] [PassBuilder] Add a mechanism for adding passbuilder
 callbacks without an extension mechanism or dlopen of plugin

---
 clang/include/clang/Basic/CodeGenOptions.h|  6 ++
 clang/lib/CodeGen/BackendUtil.cpp |  3 +
 clang/test/DriverPlugin/plugintest.c  |  3 +
 clang/tools/CMakeLists.txt|  1 +
 .../driver-static-plugin-test/CMakeLists.txt  | 59 +
 .../driver-static-plugin-test/helloplugin.cpp | 66 +++
 clang/tools/driver/cc1_main.cpp   |  9 +++
 llvm/include/llvm/Passes/PassBuilder.h|  5 ++
 8 files changed, 152 insertions(+)
 create mode 100644 clang/test/DriverPlugin/plugintest.c
 create mode 100644 clang/tools/driver-static-plugin-test/CMakeLists.txt
 create mode 100644 clang/tools/driver-static-plugin-test/helloplugin.cpp

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 12be4e0025a7054..c8e2544f891cc2b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -26,6 +26,9 @@
 #include 
 #include 
 
+namespace llvm {
+class PassBuilder;
+}
 namespace clang {
 
 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
@@ -408,6 +411,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// List of dynamic shared object files to be loaded as pass plugins.
   std::vector PassPlugins;
 
+  /// List of pass builder callbacks.
+  std::vector> PassBuilderCallbacks;
+
   /// Path to allowlist file specifying which objects
   /// (files, functions) should exclusively be instrumented
   /// by sanitizer coverage pass.
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..a8db38fce6425fb 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -906,6 +906,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   << PluginFN << toString(PassPlugin.takeError());
 }
   }
+  for (auto PassCallback : CodeGenOpts.PassBuilderCallbacks) {
+PassCallback(PB);
+  }
 #define HANDLE_EXTENSION(Ext)  
\
   get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
 #include "llvm/Support/Extension.def"
diff --git a/clang/test/DriverPlugin/plugintest.c 
b/clang/test/DriverPlugin/plugintest.c
new file mode 100644
index 000..cb96749ef8f2888
--- /dev/null
+++ b/clang/test/DriverPlugin/plugintest.c
@@ -0,0 +1,3 @@
+// RUN: clang-hello-plugin %s -o /dev/null -S | FileCheck %s
+
+int myfunction() { return 0; }
diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt
index f60db6ef0ba3454..69c8cd413a6293b 100644
--- a/clang/tools/CMakeLists.txt
+++ b/clang/tools/CMakeLists.txt
@@ -2,6 +2,7 @@ create_subdirectory_options(CLANG TOOL)
 
 add_clang_subdirectory(diagtool)
 add_clang_subdirectory(driver)
+add_clang_subdirectory(driver-static-plugin-test)
 add_clang_subdirectory(apinotes-test)
 add_clang_subdirectory(clang-diff)
 add_clang_subdirectory(clang-format)
diff --git a/clang/tools/driver-static-plugin-test/CMakeLists.txt 
b/clang/tools/driver-static-plugin-test/CMakeLists.txt
new file mode 100644
index 000..61891ff7eb9e95b
--- /dev/null
+++ b/clang/tools/driver-static-plugin-test/CMakeLists.txt
@@ -0,0 +1,59 @@
+set( LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Analysis
+  CodeGen
+  Core
+  IPO
+  AggressiveInstCombine
+  InstCombine
+  Instrumentation
+  MC
+  MCParser
+  ObjCARCOpts
+  Option
+  ScalarOpts
+  Support
+  TargetParser
+  TransformUtils
+  Vectorize
+  )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  set(support_plugins SUPPORT_PLUGINS)
+endif()
+
+add_clang_tool(clang-hello-plugin
+  ../driver/driver.cpp
+  ../driver/cc1_main.cpp
+  ../driver/cc1as_main.cpp
+  ../driver/cc1gen_reproducer_main.cpp
+  helloplugin.cpp
+  DEPENDS
+  intrinsics_gen
+  ${support_plugins}
+  GENERATE_DRIVER
+  )
+
+clang_target_link_libraries(clang-hello-plugin
+  PRIVATE
+  clangBasic
+  clangCodeGen
+  clangDriver
+  clangFrontend
+  clangFrontendTool
+  clangSerialization
+  )
+
+if(WIN32 AND NOT CYGWIN)
+  # Prevent versioning if the buildhost is targeting for Win32.
+else()
+  set_target_properties(clang-hello-plugin PROPERTIES VERSION 
${CLANG_EXECUTABLE_VERSION})
+endif()
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(clang-hello-plugin)
+endif()
+
+add_dependencies(clang-hello-plugin clang-resource-headers)
diff --git a/clang/tools/driver-static-plugin-test/helloplugin.cpp 
b/clang/tools/driver-static-plugin-test/helloplugin.cpp
new file mode 100644
index 000..52551d12af0a350
--- /dev/null
+++ 

[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-25 Thread Rana Pratap Reddy via cfe-commits

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


[clang] 13ea114 - [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (#69567)

2023-10-25 Thread via cfe-commits

Author: Rana Pratap Reddy
Date: 2023-10-26T10:26:11+05:30
New Revision: 13ea1146a78ef1e00d88b50fd0f903f336751003

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

LOG: [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (#69567)

Currently __builtin_amdgcn_read_exec_hi lowers to llvm.read_register,
this patch lowers it to use amdgcn_ballot.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
clang/test/CodeGenOpenCL/builtins-amdgcn.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..85be8bdd00516cb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7995,15 +7995,23 @@ enum SpecialRegisterAccessKind {
   Write,
 };
 
+// Generates the IR for __builtin_read_exec_*.
+// Lowers the builtin to amdgcn_ballot intrinsic.
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction , const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy  = CGF.Builder;
   CodeGen::CodeGenModule  = CGF.CGM;
 
-  llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
   llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+
+  if (isExecHi) {
+Value *Rt2 = Builder.CreateLShr(Call, 32);
+Rt2 = Builder.CreateTrunc(Rt2, CGF.Int32Ty);
+return Rt2;
+  }
+
   return Call;
 }
 
@@ -17857,10 +17865,11 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
   case AMDGPU::BI__builtin_amdgcn_read_exec:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
-  case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
-return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty);
-  }
+return EmitAMDGCNBallotForExec(*this, E, Int32Ty, Int32Ty, false);
+  case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, true);
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
index a4d14cf1f6cf0bd..43553131f63c549 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
@@ -13,6 +13,8 @@ void test_ballot_wave32(global uint* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave32_target_attr(
 // CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 %{{.+}})
 __attribute__((target("wavefrontsize32")))
@@ -21,6 +23,28 @@ void test_ballot_wave32_target_attr(global uint* out, int a, 
int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK-LABEL: @test_read_exec(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+void test_read_exec(global uint* out) {
+  *out = __builtin_amdgcn_read_exec();
+}
+
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
+// CHECK-LABEL: @test_read_exec_lo(
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
+void test_read_exec_lo(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_lo();
+}
+
+// CHECK-LABEL: @test_read_exec_hi(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+// CHECK: lshr i64 [[A:%.*]], 32
+// CHECK: trunc i64 [[B:%.*]] to i32
+void test_read_exec_hi(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_hi();
+}
+
 #if __AMDGCN_WAVEFRONT_SIZE != 32
 #error Wrong wavesize detected
 #endif

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
index 563c9a2a240c1dc..53f34c6a44ae7dc 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
@@ -13,6 +13,8 @@ void test_ballot_wave64(global ulong* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave64_target_attr(
 // CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 %{{.+}})
 

[clang] [Clang][Driver][LTO] Change the filename format for LTO'd stats file (PR #70242)

2023-10-25 Thread Fangrui Song via cfe-commits

MaskRay wrote:

I can understand the rationale, but adding this special case feels stranger to 
me..

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits


@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;

mizvekov wrote:

Ops nevermind the separate fix, you beat me to it :)

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/70282

>From b2006f46ebfd1da17014cf6c577da4700c355d00 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 4 Oct 2023 12:09:15 +0200
Subject: [PATCH] [Clang][Driver] Add new flags to control machine instruction
 verification

---
 clang/docs/ReleaseNotes.rst   | 7 +++
 clang/include/clang/Driver/Options.td | 6 ++
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/clang_f_opts.c  | 5 +
 4 files changed, 26 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2eb86caa6e6d40e..bda5312d016d231 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1925,6 +1925,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   // Discard value names in assert builds unless otherwise specified.
   if (Args.hasFlag(options::OPT_fdiscard_value_names,
options::OPT_fno_discard_value_names, !IsAssertBuild)) {
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index ebe8a0520bf0fca..e6bb6f80f00368b 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -525,6 +525,11 @@
 // CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
 // CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
 
+// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-VERIFY-MACHINE-CODE %s
+// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s
+// CHECK-VERIFY-MACHINE-CODE: "-mllvm" "-verify-machineinstrs"
+// CHECK-NO-VERIFY-MACHINE-CODE-NOT: "-mllvm" "-verify-machineinstrs"
+
 // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-DISCARD-NAMES %s
 // RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-DISCARD-NAMES %s
 // CHECK-DISCARD-NAMES: "-discard-value-names"

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits


@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;

mizvekov wrote:

Done. I also fixed in a separate commit the related flag above it, which I 
added recently.

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/70282

>From 9f3711c112159c57becae105561bc988a0caaeb5 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 26 Oct 2023 06:07:57 +0200
Subject: [PATCH 1/2] [clang][driver] remove accidentally added NoXarchOption
 flag

This flag was accidentally added in 6da382d27bb5c21dfce8ae5239ab5797bc191cab
Explained in 
https://github.com/llvm/llvm-project/pull/70282#discussion_r1372537230
---
 clang/include/clang/Driver/Options.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..f9bf170c32ba25e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1922,10 +1922,10 @@ defm safe_buffer_usage_suggestions : 
BoolFOption<"safe-buffer-usage-suggestions"
   NegFlag>;
 def fverify_intermediate_code : Flag<["-"], "fverify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
-  HelpText<"Enable verification of LLVM IR">, Flags<[NoXarchOption]>;
+  HelpText<"Enable verification of LLVM IR">;
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
-  HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+  HelpText<"Disable verification of LLVM IR">;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;

>From c4b858b791792626e0a5584a0a2aeb877a0151c9 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 4 Oct 2023 12:09:15 +0200
Subject: [PATCH 2/2] [Clang][Driver] Add new flags to control machine
 instruction verification

---
 clang/docs/ReleaseNotes.rst   | 7 +++
 clang/include/clang/Driver/Options.td | 6 ++
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/clang_f_opts.c  | 5 +
 4 files changed, 26 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f9bf170c32ba25e..092b54967ccdab0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   // 

[clang] [RISCV] Support predefined macro __riscv_misaligned_[fast,avoid]. (PR #65756)

2023-10-25 Thread Craig Topper via cfe-commits

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


[clang] [RISCV] Support predefined marcro __riscv_misaligned_[fast,avoid]. (PR #65756)

2023-10-25 Thread Yeting Kuo via cfe-commits

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


[clang] fa18827 - [Driver] Remove some misused NoXarchOption

2023-10-25 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-10-25T20:59:29-07:00
New Revision: fa18827754ebdd144f41fd4a889016c8ae1caf0c

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

LOG: [Driver] Remove some misused NoXarchOption

If an option has the `NoXarchOption` flag, ClangDriver will emit an error if the
option is used after `-Xarch_*` (originally for universal macOS binary, reused
by offloading purposes `-Xarch_host`/etc). The error checking only applies to a
small set of options (e.g. `-o`) and is not very useful for most options, but
`NoXarchOption` was improperly named `DriverOption` (commit
aabb0b11a3c1d8a6bb859db80400cffdcc9b336f) and lured some contributors to add
`NoXarchOption` to options that should not have the flag.

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..2eb86caa6e6d40e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1573,12 +1573,12 @@ def fprofile_sample_use : Flag<["-"], 
"fprofile-sample-use">, Group,
 def fno_profile_sample_use : Flag<["-"], "fno-profile-sample-use">, 
Group,
 Visibility<[ClangOption, CLOption]>;
 def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">,
-Group, Flags<[NoXarchOption]>,
+Group,
 Visibility<[ClangOption, CC1Option]>,
 HelpText<"Enable sample-based profile guided optimizations">,
 MarshallingInfoString>;
 def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">,
-Group, Flags<[NoXarchOption]>,
+Group,
 Visibility<[ClangOption, CC1Option]>,
 HelpText<"Specifies that the sample profile is accurate">,
 DocBrief<[{Specifies that the sample profile is accurate. If the sample
@@ -1587,15 +1587,14 @@ def fprofile_sample_accurate : Flag<["-"], 
"fprofile-sample-accurate">,
we have no profile}]>,
MarshallingInfoFlag>;
 def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
-Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
+Visibility<[ClangOption, CC1Option]>,
 Group,
 HelpText<"Use profi to infer block and edge counts">,
 DocBrief<[{Infer block and edge counts. If the profiles have errors or 
missing
blocks caused by sampling, profile inference (profi) can convert
basic block counts to branch probabilites to fix them by 
extended
and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
-def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">,
-  Group, Flags<[NoXarchOption]>;
+def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, 
Group;
 def fauto_profile : Flag<["-"], "fauto-profile">, Group,
 Alias;
 def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group,
@@ -1666,7 +1665,7 @@ def fcs_profile_generate_EQ : Joined<["-"], 
"fcs-profile-generate=">,
 def fprofile_use : Flag<["-"], "fprofile-use">, Group,
 Visibility<[ClangOption, CLOption]>, Alias;
 def fprofile_use_EQ : Joined<["-"], "fprofile-use=">,
-Group, Flags<[NoXarchOption]>,
+Group,
 Visibility<[ClangOption, CLOption]>,
 MetaVarName<"">,
 HelpText<"Use instrumentation data for profile-guided optimization. If 
pathname is a directory, it reads from /default.profdata. Otherwise, 
it reads from file .">;
@@ -1704,7 +1703,7 @@ defm pseudo_probe_for_profiling : 
BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
   PosFlag,
   NegFlag,
-  BothFlags<[NoXarchOption], [ClangOption, CC1Option],
+  BothFlags<[], [ClangOption, CC1Option],
   " pseudo probes for sample profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
@@ -1750,7 +1749,7 @@ defm borland_extensions : 
BoolFOption<"borland-extensions",
 def fbuiltin : Flag<["-"], "fbuiltin">, Group,
   Visibility<[ClangOption, CLOption, DXCOption]>;
 def fbuiltin_module_map : Flag <["-"], "fbuiltin-module-map">, Group,
-  Flags<[NoXarchOption]>, HelpText<"Load the clang builtins module map file.">;
+  Flags<[]>, HelpText<"Load the clang builtins module map file.">;
 defm caret_diagnostics : BoolFOption<"caret-diagnostics",
   DiagnosticOpts<"ShowCarets">, DefaultTrue,
   NegFlag,
@@ -1868,7 +1867,7 @@ defm cxx_modules : BoolFOption<"cxx-modules",
   LangOpts<"CPlusPlusModules">, Default,
   NegFlag,
   PosFlag,
-  BothFlags<[NoXarchOption], [], " modules for C++">>,
+  BothFlags<[], [], " modules for C++">>,
   ShouldParseIf;
 def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, 
Group;
 def fdebug_pass_structure : 

[clang] [mlir][doc] Improve Destination-passing-style documentation (PR #70283)

2023-10-25 Thread Mehdi Amini via cfe-commits

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


[clang] [mlir][doc] Improve Destination-passing-style documentation (PR #70283)

2023-10-25 Thread Mehdi Amini via cfe-commits

https://github.com/joker-eph updated 
https://github.com/llvm/llvm-project/pull/70283

>From 0bdf7a0bc1c1e3b5fc3280e9ba5f5cacfeeb5f7f Mon Sep 17 00:00:00 2001
From: Mehdi Amini 
Date: Wed, 25 Oct 2023 19:17:32 -0700
Subject: [PATCH 1/3] Update Bufferization.md

---
 mlir/docs/Bufferization.md | 39 --
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index d9d0751cae8c9dd..ea3593549ca1563 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -101,10 +101,28 @@ bufferization strategy would be unacceptable for 
high-performance codegen. When
 choosing an already existing buffer, we must be careful not to accidentally
 overwrite data that is still needed later in the program.
 
-To simplify this problem, One-Shot Bufferize was designed for ops that are in
-*destination-passing style*. For every tensor result, such ops have a tensor
-operand, whose buffer could be utilized for storing the result of the op in the
-absence of other conflicts. We call such tensor operands the *destination*.
+To simplify this problem, One-Shot Bufferize was designed to take advantage of
+*destination-passing style*. This form exists in itself independently of
+bufferization and is tied to SSA semantics: many ops are “updating” part of
+their input SSA variable. For example the LLVM instruction
+[`insertelement`](https://llvm.org/docs/LangRef.html#insertelement-instruction)
+is inserting an element inside a vector. Since SSA values are immutable, the
+operation returns a copy of the input vector with the element inserted.
+Another example in MLIR is `linalg.generic`, which always has an extra `outs`
+operand which provides the initial values to update (for example when the
+operation is doing a reduction). 
+
+This input is referred to as "destination" in the following (quotes are
+important are this operand isn't modified in place but copied) and come into
+place in the context of bufferization as a possible "anchor" for the
+bufferization algorithm. This allows the user to shape the input in a form that
+guarantees close to optimal bufferization result when carefully choosing the
+SSA value used as "destination".
+
+For every tensor result, a "destination-passing" style op has a corresponding
+tensor operand. If there aren't any other uses of this tensor, the 
bufferization
+can alias it with the op result and perform the operation "in-place" by reusing
+the buffer allocated for this "destination" input.
 
 As an example, consider the following op: `%0 = tensor.insert %cst into
 %t[%idx] : tensor`
@@ -112,15 +130,16 @@ As an example, consider the following op: `%0 = 
tensor.insert %cst into
 `%t` is the destination in this example. When choosing a buffer for the result
 `%0`, One-Shot Bufferize considers only two options:
 
-1.  buffer(`%0`) = buffer(`%t`).
-2.  buffer(`%0`) is a newly allocated buffer.
+1.  buffer(`%0`) = buffer(`%t`): alias the destination tensor with the
+result and perform the operation in-place.
+3.  buffer(`%0`) is a newly allocated buffer.
 
 There may be other buffers in the same function that could potentially be used
 for buffer(`%0`), but those are not considered by One-Shot Bufferize to keep 
the
 bufferization simple. One-Shot Bufferize could be extended to consider such
 buffers in the future to achieve a better quality of bufferization.
 
-Tensor ops that are not in destination-passing style always bufferize to a
+Tensor ops that are not in destination-passing style always bufferized to a
 memory allocation. E.g.:
 
 ```mlir
@@ -159,9 +178,9 @@ slice of a tensor:
 ```
 
 The above example bufferizes to a `memref.subview`, followed by a
-"`linalg.generic` on memrefs" that overwrites the memory of the subview. The
-`tensor.insert_slice` bufferizes to a no-op (in the absence of RaW conflicts
-such as a subsequent read of `%s`).
+"`linalg.generic` on memrefs" that overwrites the memory of the subview, 
assuming
+that the slice `%t` has no other user. The `tensor.insert_slice` then 
bufferizes
+to a no-op (in the absence of RaW conflicts such as a subsequent read of `%s`).
 
 RaW conflicts are detected with an analysis of SSA use-def chains (details
 later). One-Shot Bufferize works best if there is a single SSA use-def chain,

>From a06bcdde0c75dbab260d7d31d4dcaf0b169d8811 Mon Sep 17 00:00:00 2001
From: Mehdi Amini 
Date: Wed, 25 Oct 2023 20:42:41 -0700
Subject: [PATCH 2/3] Update Bufferization.md

---
 mlir/docs/Bufferization.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index ea3593549ca1563..88a2e50e85d938d 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -113,7 +113,7 @@ operand which provides the initial values to update (for 
example when the
 operation is doing a reduction). 
 
 This input is referred to as "destination" in the following (quotes are

[clang] [mlir][doc] Improve Destination-passing-style documentation (PR #70283)

2023-10-25 Thread Mehdi Amini via cfe-commits

https://github.com/joker-eph updated 
https://github.com/llvm/llvm-project/pull/70283

>From 0bdf7a0bc1c1e3b5fc3280e9ba5f5cacfeeb5f7f Mon Sep 17 00:00:00 2001
From: Mehdi Amini 
Date: Wed, 25 Oct 2023 19:17:32 -0700
Subject: [PATCH 1/2] Update Bufferization.md

---
 mlir/docs/Bufferization.md | 39 --
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index d9d0751cae8c9dd..ea3593549ca1563 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -101,10 +101,28 @@ bufferization strategy would be unacceptable for 
high-performance codegen. When
 choosing an already existing buffer, we must be careful not to accidentally
 overwrite data that is still needed later in the program.
 
-To simplify this problem, One-Shot Bufferize was designed for ops that are in
-*destination-passing style*. For every tensor result, such ops have a tensor
-operand, whose buffer could be utilized for storing the result of the op in the
-absence of other conflicts. We call such tensor operands the *destination*.
+To simplify this problem, One-Shot Bufferize was designed to take advantage of
+*destination-passing style*. This form exists in itself independently of
+bufferization and is tied to SSA semantics: many ops are “updating” part of
+their input SSA variable. For example the LLVM instruction
+[`insertelement`](https://llvm.org/docs/LangRef.html#insertelement-instruction)
+is inserting an element inside a vector. Since SSA values are immutable, the
+operation returns a copy of the input vector with the element inserted.
+Another example in MLIR is `linalg.generic`, which always has an extra `outs`
+operand which provides the initial values to update (for example when the
+operation is doing a reduction). 
+
+This input is referred to as "destination" in the following (quotes are
+important are this operand isn't modified in place but copied) and come into
+place in the context of bufferization as a possible "anchor" for the
+bufferization algorithm. This allows the user to shape the input in a form that
+guarantees close to optimal bufferization result when carefully choosing the
+SSA value used as "destination".
+
+For every tensor result, a "destination-passing" style op has a corresponding
+tensor operand. If there aren't any other uses of this tensor, the 
bufferization
+can alias it with the op result and perform the operation "in-place" by reusing
+the buffer allocated for this "destination" input.
 
 As an example, consider the following op: `%0 = tensor.insert %cst into
 %t[%idx] : tensor`
@@ -112,15 +130,16 @@ As an example, consider the following op: `%0 = 
tensor.insert %cst into
 `%t` is the destination in this example. When choosing a buffer for the result
 `%0`, One-Shot Bufferize considers only two options:
 
-1.  buffer(`%0`) = buffer(`%t`).
-2.  buffer(`%0`) is a newly allocated buffer.
+1.  buffer(`%0`) = buffer(`%t`): alias the destination tensor with the
+result and perform the operation in-place.
+3.  buffer(`%0`) is a newly allocated buffer.
 
 There may be other buffers in the same function that could potentially be used
 for buffer(`%0`), but those are not considered by One-Shot Bufferize to keep 
the
 bufferization simple. One-Shot Bufferize could be extended to consider such
 buffers in the future to achieve a better quality of bufferization.
 
-Tensor ops that are not in destination-passing style always bufferize to a
+Tensor ops that are not in destination-passing style always bufferized to a
 memory allocation. E.g.:
 
 ```mlir
@@ -159,9 +178,9 @@ slice of a tensor:
 ```
 
 The above example bufferizes to a `memref.subview`, followed by a
-"`linalg.generic` on memrefs" that overwrites the memory of the subview. The
-`tensor.insert_slice` bufferizes to a no-op (in the absence of RaW conflicts
-such as a subsequent read of `%s`).
+"`linalg.generic` on memrefs" that overwrites the memory of the subview, 
assuming
+that the slice `%t` has no other user. The `tensor.insert_slice` then 
bufferizes
+to a no-op (in the absence of RaW conflicts such as a subsequent read of `%s`).
 
 RaW conflicts are detected with an analysis of SSA use-def chains (details
 later). One-Shot Bufferize works best if there is a single SSA use-def chain,

>From a06bcdde0c75dbab260d7d31d4dcaf0b169d8811 Mon Sep 17 00:00:00 2001
From: Mehdi Amini 
Date: Wed, 25 Oct 2023 20:42:41 -0700
Subject: [PATCH 2/2] Update Bufferization.md

---
 mlir/docs/Bufferization.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index ea3593549ca1563..88a2e50e85d938d 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -113,7 +113,7 @@ operand which provides the initial values to update (for 
example when the
 operation is doing a reduction). 
 
 This input is referred to as "destination" in the following (quotes are

[clang-tools-extra] [clangd] Support `-specs` arguments when querying the driver. (PR #70285)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Chris Carlon (cjc25)


Changes

Similarly to commit 3935a29, forward spec file arguments to the driver if they 
appear in the compile database. Spec files can affect the include search path.

fixes clangd/clangd#1410

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


2 Files Affected:

- (modified) clang-tools-extra/clangd/SystemIncludeExtractor.cpp (+26-4) 
- (modified) clang-tools-extra/clangd/test/system-include-extractor.test (+7-2) 


``diff
diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index a86f152c3bf364e..ea98c7d948a2f6d 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -89,13 +89,14 @@ struct DriverArgs {
   std::string ISysroot;
   std::string Target;
   std::string Stdlib;
+  llvm::SmallVector Specs;
 
   bool operator==(const DriverArgs ) const {
 return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
-Sysroot, ISysroot, Target, Stdlib) ==
+Sysroot, ISysroot, Target, Stdlib, Specs) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target,
-RHS.Stdlib);
+RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target, 
RHS.Stdlib,
+RHS.Specs);
   }
 
   DriverArgs(const tooling::CompileCommand , llvm::StringRef File) {
@@ -145,6 +146,17 @@ struct DriverArgs {
   Stdlib = Cmd.CommandLine[I + 1];
   } else if (Arg.consume_front("-stdlib=")) {
 Stdlib = Arg.str();
+  } else if (Arg.startswith("-specs=")) {
+// clang requires a single token like `-specs=file` or `--specs=file`,
+// but gcc will accept two tokens like `--specs file`. Since the
+// compilation database is presumably correct, we just forward the 
flags
+// as-is.
+Specs.push_back(Arg.str());
+  } else if (Arg.startswith("--specs=")) {
+Specs.push_back(Arg.str());
+  } else if (Arg == "--specs" && I + 1 < E) {
+Specs.push_back(Arg.str());
+Specs.push_back(Cmd.CommandLine[I + 1]);
   }
 }
 
@@ -186,6 +198,11 @@ struct DriverArgs {
   Args.append({"-target", Target});
 if (!Stdlib.empty())
   Args.append({"--stdlib", Stdlib});
+
+for (llvm::StringRef Spec : Specs) {
+  Args.push_back(Spec);
+}
+
 return Args;
   }
 
@@ -210,7 +227,7 @@ template <> struct DenseMapInfo {
 return Driver;
   }
   static unsigned getHashValue(const DriverArgs ) {
-return llvm::hash_value(std::tuple{
+unsigned FixedFieldsHash = llvm::hash_value(std::tuple{
 Val.Driver,
 Val.StandardIncludes,
 Val.StandardCXXIncludes,
@@ -220,6 +237,11 @@ template <> struct DenseMapInfo {
 Val.Target,
 Val.Stdlib,
 });
+
+unsigned SpecsHash =
+llvm::hash_combine_range(Val.Specs.begin(), Val.Specs.end());
+
+return llvm::hash_combine(FixedFieldsHash, SpecsHash);
   }
   static bool isEqual(const DriverArgs , const DriverArgs ) {
 return LHS == RHS;
diff --git a/clang-tools-extra/clangd/test/system-include-extractor.test 
b/clang-tools-extra/clangd/test/system-include-extractor.test
index cbb3018b2fa7349..4ff6f946ffa73d4 100644
--- a/clang-tools-extra/clangd/test/system-include-extractor.test
+++ b/clang-tools-extra/clangd/test/system-include-extractor.test
@@ -19,6 +19,11 @@
 # RUN: echo '[ -z "${args##*"-isysroot /isysroot"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"-target arm-linux-gnueabihf"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"--stdlib libc++"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"-specs=test.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--specs=test2.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--specs test3.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# Check that clangd drops other flags like -lc++, which don't affect includes
+# RUN: echo '[ -n "${args##*"-lc++"*}" ] || exit' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
@@ -38,7 +43,7 @@
 
 # Generate a compile_commands.json that will query the mock driver we've
 # created. Which should add a.h and b.h into include search path.
-# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp 
--target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path 
-isysroot/isysroot -stdlib=libc++", "file": "the-file.cpp"}]' > 
%t.dir/compile_commands.json
+# RUN: echo '[{"directory": 

[clang-tools-extra] [clangd] Support `-specs` arguments when querying the driver. (PR #70285)

2023-10-25 Thread Chris Carlon via cfe-commits

https://github.com/cjc25 created https://github.com/llvm/llvm-project/pull/70285

Similarly to commit 3935a29, forward spec file arguments to the driver if they 
appear in the compile database. Spec files can affect the include search path.

fixes clangd/clangd#1410

>From f171053854f3926641ecc450e35a625b5850a4be Mon Sep 17 00:00:00 2001
From: Chris Carlon 
Date: Tue, 24 Oct 2023 22:21:59 -0400
Subject: [PATCH] [clangd] Support `-specs` arguments when querying the driver.

Similarly to commit 3935a29, forward spec file arguments to the driver if they
appear in the compile database. Spec files can affect the include search path.

fixes clangd/clangd#1410
---
 .../clangd/SystemIncludeExtractor.cpp | 30 ---
 .../clangd/test/system-include-extractor.test |  9 --
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index a86f152c3bf364e..ea98c7d948a2f6d 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -89,13 +89,14 @@ struct DriverArgs {
   std::string ISysroot;
   std::string Target;
   std::string Stdlib;
+  llvm::SmallVector Specs;
 
   bool operator==(const DriverArgs ) const {
 return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
-Sysroot, ISysroot, Target, Stdlib) ==
+Sysroot, ISysroot, Target, Stdlib, Specs) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target,
-RHS.Stdlib);
+RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target, 
RHS.Stdlib,
+RHS.Specs);
   }
 
   DriverArgs(const tooling::CompileCommand , llvm::StringRef File) {
@@ -145,6 +146,17 @@ struct DriverArgs {
   Stdlib = Cmd.CommandLine[I + 1];
   } else if (Arg.consume_front("-stdlib=")) {
 Stdlib = Arg.str();
+  } else if (Arg.startswith("-specs=")) {
+// clang requires a single token like `-specs=file` or `--specs=file`,
+// but gcc will accept two tokens like `--specs file`. Since the
+// compilation database is presumably correct, we just forward the 
flags
+// as-is.
+Specs.push_back(Arg.str());
+  } else if (Arg.startswith("--specs=")) {
+Specs.push_back(Arg.str());
+  } else if (Arg == "--specs" && I + 1 < E) {
+Specs.push_back(Arg.str());
+Specs.push_back(Cmd.CommandLine[I + 1]);
   }
 }
 
@@ -186,6 +198,11 @@ struct DriverArgs {
   Args.append({"-target", Target});
 if (!Stdlib.empty())
   Args.append({"--stdlib", Stdlib});
+
+for (llvm::StringRef Spec : Specs) {
+  Args.push_back(Spec);
+}
+
 return Args;
   }
 
@@ -210,7 +227,7 @@ template <> struct DenseMapInfo {
 return Driver;
   }
   static unsigned getHashValue(const DriverArgs ) {
-return llvm::hash_value(std::tuple{
+unsigned FixedFieldsHash = llvm::hash_value(std::tuple{
 Val.Driver,
 Val.StandardIncludes,
 Val.StandardCXXIncludes,
@@ -220,6 +237,11 @@ template <> struct DenseMapInfo {
 Val.Target,
 Val.Stdlib,
 });
+
+unsigned SpecsHash =
+llvm::hash_combine_range(Val.Specs.begin(), Val.Specs.end());
+
+return llvm::hash_combine(FixedFieldsHash, SpecsHash);
   }
   static bool isEqual(const DriverArgs , const DriverArgs ) {
 return LHS == RHS;
diff --git a/clang-tools-extra/clangd/test/system-include-extractor.test 
b/clang-tools-extra/clangd/test/system-include-extractor.test
index cbb3018b2fa7349..4ff6f946ffa73d4 100644
--- a/clang-tools-extra/clangd/test/system-include-extractor.test
+++ b/clang-tools-extra/clangd/test/system-include-extractor.test
@@ -19,6 +19,11 @@
 # RUN: echo '[ -z "${args##*"-isysroot /isysroot"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"-target arm-linux-gnueabihf"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"--stdlib libc++"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"-specs=test.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--specs=test2.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--specs test3.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# Check that clangd drops other flags like -lc++, which don't affect includes
+# RUN: echo '[ -n "${args##*"-lc++"*}" ] || exit' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
@@ -38,7 +43,7 @@
 
 # Generate a compile_commands.json that will query the mock driver we've
 # created. Which should add 

[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;

MaskRay wrote:

Remove NoXarchOption

If an option has the `NoXarchOption` flag, ClangDriver will emit an error if 
the option is used after `-Xarch_*` (originally for universal macOS binary, 
reused by offloading purposes `-Xarch_host`/etc).
The error checking only applies to a small set of options (e.g. `-o`) and is 
not very useful for most options, but `NoXarchOption` was improperly named 
`DriverOption` (commit aabb0b11a3c1d8a6bb859db80400cffdcc9b336f) and lured some 
contributors to add `NoXarchOption` to options that should not have the flag.



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


[clang] [RecursiveASTVisitor] Fix RecursiveASTVisitor (RAV) fails to visit the initializer of a bitfield (PR #69557)

2023-10-25 Thread Shivam Gupta via cfe-commits

https://github.com/xgupta updated 
https://github.com/llvm/llvm-project/pull/69557

>From 2e363be5e79e2aeeb219628db0c917e530e04d99 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Thu, 19 Oct 2023 09:06:43 +0530
Subject: [PATCH 1/3] [RecursiveASTVisitor] Fix RecursiveASTVisitor (RAV) fails
 to visit the initializer of a bitfield

Patch by Scott McPeak
---
 clang/include/clang/AST/RecursiveASTVisitor.h |  2 +-
 clang/unittests/Tooling/CMakeLists.txt|  1 +
 .../BitfieldInitializer.cpp   | 34 +++
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 
clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp

diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 3dd23eb38eeabfc..53bc15e1b19f668 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2103,7 +2103,7 @@ DEF_TRAVERSE_DECL(FieldDecl, {
   TRY_TO(TraverseDeclaratorHelper(D));
   if (D->isBitField())
 TRY_TO(TraverseStmt(D->getBitWidth()));
-  else if (D->hasInClassInitializer())
+  if (D->hasInClassInitializer())
 TRY_TO(TraverseStmt(D->getInClassInitializer()));
 })
 
diff --git a/clang/unittests/Tooling/CMakeLists.txt 
b/clang/unittests/Tooling/CMakeLists.txt
index 2fbe78e3fab7528..5a10a6b285390e9 100644
--- a/clang/unittests/Tooling/CMakeLists.txt
+++ b/clang/unittests/Tooling/CMakeLists.txt
@@ -25,6 +25,7 @@ add_clang_unittest(ToolingTests
   QualTypeNamesTest.cpp
   RangeSelectorTest.cpp
   RecursiveASTVisitorTests/Attr.cpp
+  RecursiveASTVisitorTests/BitfieldInitializer.cpp
   RecursiveASTVisitorTests/CallbacksLeaf.cpp
   RecursiveASTVisitorTests/CallbacksUnaryOperator.cpp
   RecursiveASTVisitorTests/CallbacksBinaryOperator.cpp
diff --git 
a/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
new file mode 100644
index 000..676a491a43040ea
--- /dev/null
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
@@ -0,0 +1,34 @@
+//===- unittest/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include 
+
+using namespace clang;
+
+namespace {
+
+// Check to ensure that bitfield initializers are visited.
+class BitfieldInitializerVisitor : public 
ExpectedLocationVisitor {
+public:
+  bool VisitIntegerLiteral(IntegerLiteral *IL) {
+Match(std::to_string(IL->getValue().getSExtValue()), IL->getLocation());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, BitfieldInitializerIsVisited) {
+  BitfieldInitializerVisitor Visitor;
+  Visitor.ExpectMatch("123", 2, 15); 
+  EXPECT_TRUE(Visitor.runOver(
+"struct S {\n"
+"  int x : 8 = 123;\n"
+"};\n"));
+}
+
+} // end anonymous namespace

>From a6fa113206562f373f3aba81ce81acd5d9dcf9d1 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Thu, 19 Oct 2023 09:24:38 +0530
Subject: [PATCH 2/3] clang-format

---
 .../RecursiveASTVisitorTests/BitfieldInitializer.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git 
a/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
index 676a491a43040ea..c11e726fe855284 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
@@ -14,7 +14,8 @@ using namespace clang;
 namespace {
 
 // Check to ensure that bitfield initializers are visited.
-class BitfieldInitializerVisitor : public 
ExpectedLocationVisitor {
+class BitfieldInitializerVisitor
+: public ExpectedLocationVisitor {
 public:
   bool VisitIntegerLiteral(IntegerLiteral *IL) {
 Match(std::to_string(IL->getValue().getSExtValue()), IL->getLocation());
@@ -24,11 +25,10 @@ class BitfieldInitializerVisitor : public 
ExpectedLocationVisitorFrom 1ce8c2ca7bf5110e4bfb11eeaaa891183e73f2e5 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Wed, 25 Oct 2023 22:16:34 +0530
Subject: [PATCH 3/3] Added release note

---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..a1f373b167a33cb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -650,6 +650,9 @@ Bug Fixes to AST Handling
   `Issue 64170 `_
 - Fixed ``hasAnyBase`` not binding nodes in its submatcher.
   (`#65421 `_)
+- Fixed 

[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-25 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}.

The majority of patches don't add a trailing period in the title.

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


[clang] f40ed13 - [Driver] Use StringSet::contains (NFC)

2023-10-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-10-25T20:14:35-07:00
New Revision: f40ed134b485db5f950f51a0d175caffe607b2f1

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

LOG: [Driver] Use StringSet::contains (NFC)

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f5fd900a6447fe3..30ae2201ab8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2593,7 +2593,7 @@ void Driver::BuildInputs(const ToolChain , 
DerivedArgList ,
   // Warn -x after last input file has no effect
   auto LastXArg = Args.getLastArgValue(options::OPT_x);
   const llvm::StringSet<> ValidXArgs = {"cuda", "hip", "cui", "hipi"};
-  if (!IsCLMode() || ValidXArgs.find(LastXArg) != ValidXArgs.end()) {
+  if (!IsCLMode() || ValidXArgs.contains(LastXArg)) {
 Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x);
 Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT);
 if (LastXArg && LastInputArg &&



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


[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -1228,3 +1228,15 @@
 // RUN: -march=rv64i_zve32x_zvkt1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZVKT-EXT %s
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
+
+// RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \

MaskRay wrote:

Remove `-x c` (redundant) and indent the continuation lines by 2

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


[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-25 Thread Fangrui Song via cfe-commits

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


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


[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-25 Thread Fangrui Song via cfe-commits

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


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2023-10-25 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja updated 
https://github.com/llvm/llvm-project/pull/68846

>From 07007c384ee57a20ad1dd1b0422c93152bb7f18e Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Tue, 17 Oct 2023 10:41:18 +0800
Subject: [PATCH] [Docs][Clang] DR status in cxx_status.html

---
 clang/www/cxx_status.html | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index e2cf9ab25465214..8e2869d3fdf8ac6 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -190,7 +190,7 @@ C++23 implementation status
 
 
   Allow duplicate attributes
-  https://wg21.link/P2156R1;>P2156R1
+  https://wg21.link/P2156R1;>P2156R1 (DR)
   Clang 13
 
 
@@ -210,7 +210,7 @@ C++23 implementation status
 
 
   C++ identifier syntax using UAX 31
-  https://wg21.link/P1949R7;>P1949R7
+  https://wg21.link/P1949R7;>P1949R7 (DR)
   Clang 14
 
 
@@ -230,11 +230,11 @@ C++23 implementation status
 
 
   Change scope of lambda trailing-return-type
-  https://wg21.link/P2036R3;>P2036R3
+  https://wg21.link/P2036R3;>P2036R3 (DR)
   Clang 17
 
 
-  https://wg21.link/P2579R0;>P2579R0
+  https://wg21.link/P2579R0;>P2579R0 (DR)
 
 
   Multidimensional subscript operator
@@ -303,12 +303,12 @@ C++23 implementation status
 
 
   The Equality Operator You Are Looking For
-  https://wg21.link/P2468R2;>P2468R2
+  https://wg21.link/P2468R2;>P2468R2 (DR)
   Clang 16
 
 
   De-deprecating volatile compound operations
-  https://wg21.link/P2327R1;>P2327R1
+  https://wg21.link/P2327R1;>P2327R1 (DR)
   Clang 15
 
 
@@ -380,7 +380,7 @@ C++23 implementation status
 
 
   char8_t Compatibility and Portability Fix
-  https://wg21.link/P2513R3;>P2513R3
+  https://wg21.link/P2513R3;>P2513R3 (DR)
   Clang 16
 
 
@@ -522,7 +522,7 @@ C++20 implementation status
 https://wg21.link/p2103r0;>P2103R0
   

-https://wg21.link/p2493r0;>P2493R0
+https://wg21.link/p2493r0;>P2493R0 (DR)
   
   
 https://wg21.link/p2092r0;>P2092R0

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

> While the change itself looks neat, I am curious about the reason how this 
> interact with modules.

IIUC modules is incidental to the problem, it is just a way we run into an 
underlying issue that we are not dealing with full-expressions properly in this 
case.

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

I think this change makes sense but I am not crazy about how we deal w/ 
full-expressions right now with these `FullExpressionRAII`, it feels very 
ad-hoc and it takes a bunch of time to understand why they are needed where 
they are.

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


[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-25 Thread Rana Pratap Reddy via cfe-commits

https://github.com/ranapratap55 updated 
https://github.com/llvm/llvm-project/pull/69567

>From bd6e1449bd098d8348cf1402ad875e79cbc274b5 Mon Sep 17 00:00:00 2001
From: ranapratap55 
Date: Thu, 19 Oct 2023 12:52:13 +0530
Subject: [PATCH] [AMDGPU] Lower __builtin_read_exec_hi to use amdgcn_ballot

---
 clang/lib/CodeGen/CGBuiltin.cpp   | 21 +++-
 .../CodeGenOpenCL/builtins-amdgcn-wave32.cl   | 24 +++
 .../CodeGenOpenCL/builtins-amdgcn-wave64.cl   | 23 ++
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  4 +++-
 4 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..85be8bdd00516cb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7995,15 +7995,23 @@ enum SpecialRegisterAccessKind {
   Write,
 };
 
+// Generates the IR for __builtin_read_exec_*.
+// Lowers the builtin to amdgcn_ballot intrinsic.
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction , const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy  = CGF.Builder;
   CodeGen::CodeGenModule  = CGF.CGM;
 
-  llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
   llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+
+  if (isExecHi) {
+Value *Rt2 = Builder.CreateLShr(Call, 32);
+Rt2 = Builder.CreateTrunc(Rt2, CGF.Int32Ty);
+return Rt2;
+  }
+
   return Call;
 }
 
@@ -17857,10 +17865,11 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
   case AMDGPU::BI__builtin_amdgcn_read_exec:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
-  case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
-return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty);
-  }
+return EmitAMDGCNBallotForExec(*this, E, Int32Ty, Int32Ty, false);
+  case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, true);
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
index a4d14cf1f6cf0bd..43553131f63c549 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
@@ -13,6 +13,8 @@ void test_ballot_wave32(global uint* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave32_target_attr(
 // CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 %{{.+}})
 __attribute__((target("wavefrontsize32")))
@@ -21,6 +23,28 @@ void test_ballot_wave32_target_attr(global uint* out, int a, 
int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK-LABEL: @test_read_exec(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+void test_read_exec(global uint* out) {
+  *out = __builtin_amdgcn_read_exec();
+}
+
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
+// CHECK-LABEL: @test_read_exec_lo(
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
+void test_read_exec_lo(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_lo();
+}
+
+// CHECK-LABEL: @test_read_exec_hi(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+// CHECK: lshr i64 [[A:%.*]], 32
+// CHECK: trunc i64 [[B:%.*]] to i32
+void test_read_exec_hi(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_hi();
+}
+
 #if __AMDGCN_WAVEFRONT_SIZE != 32
 #error Wrong wavesize detected
 #endif
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
index 563c9a2a240c1dc..53f34c6a44ae7dc 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
@@ -13,6 +13,8 @@ void test_ballot_wave64(global ulong* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave64_target_attr(
 // CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 %{{.+}})
 __attribute__((target("wavefrontsize64")))
@@ -21,6 +23,27 @@ void test_ballot_wave64_target_attr(global ulong* out, int 
a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK-LABEL: 

[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Please make sure you write a more complete description of the problem and why 
this solves the problem. The description is usually what goes into the git log 
and that is very useful for quickly understanding commits and tracking down 
problems. 

I know some folks edit the description on commit but honestly it is very 
helpful for the reviewers of your PR to have a full description up front.

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Shafik Yaghmour via cfe-commits


@@ -15604,10 +15604,13 @@ bool Expr::EvaluateAsInitializer(APValue , 
const ASTContext ,
 LValue LVal;
 LVal.set(VD);
 
-if (!EvaluateInPlace(Value, Info, LVal, this,
- /*AllowNonLiteralTypes=*/true) ||
-EStatus.HasSideEffects)
-  return false;
+{
+  FullExpressionRAII Scope(Info);

shafik wrote:

I think we need to add a comment here similar to the one in 
`EvaluateAsConstexpr(...)` in this case it would be `A full-expression is ... 
an init-declarator ([dcl.decl]) or a mem-initializer` see 
https://eel.is/c++draft/intro.execution#5.4

CC @cor3ntin for second look

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


[clang] [AArch64] Stack probing for function prologues (PR #66524)

2023-10-25 Thread Oskar Wirga via cfe-commits

oskarwirga wrote:

Apologies for still not being able to create a reproducible example I can share 
but what I am seeing is the stack probe write overwriting the value at  the tip 
of the stack when I step debug execution:
```
str xzr, [sp, #-0x10 {var_70}]!  {0x0}
...
sturx8, [x29, #-0x10 {var_70}]
...
from the inlined function:
str xzr, [x20]  {0x0}
mov sp, x20
...
ldurx8, [x29, #-0x10 {var_70}] << null deref
```

I also was able to isolate the issue to the non-fast register allocators. When 
building with optimized code, the greedy register allocator and the basic 
register allocator ended up choosing registers that were being clobbered (? 
don't know the term) by the stack probe write. 

> All the stack probing should have already finished before the call to 
> `malloc`.

Only for the containing function, the functions which have their stack probes 
inlined will be in the middle of the function which then results in this 
null-deref. I think there's some re-arranging happening during optimization and 
inlining which causes the registers not to be expired (? don't know the term 
here)

> Just to make things simpler, can you try disabling the shrink-wrapping and 
> see what happens?

I haven't seen noticeable difference with this, I tried passing it in with 
`-Wl,-mllvm,-enable-shrink-wrap=false`  

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-10-25 Thread Felix via cfe-commits


@@ -649,6 +649,14 @@ void XCOFFObjectWriter::recordRelocation(MCAssembler ,
  uint64_t ) {
   auto getIndex = [this](const MCSymbol *Sym,
  const MCSectionXCOFF *ContainingCsect) {
+// Fixup relocation flag for AIX TLS local-dynamic mode.

orcguru wrote:

I will look into alternative approach to handle this fixup.

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

Present shortcomings are that this only works for non-LTO builds, and that this 
new pass doesn't work quite the same as the IR verification flag, as it runs 
between every machine pass and is thus much more expensive.

Though I recently discussed this with @aeubanks during the US devmtg 
and we think this is worthwhile as a first step.

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+7) 
- (modified) clang/include/clang/Driver/Options.td (+6) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+8) 
- (modified) clang/test/Driver/clang_f_opts.c (+5) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..c190af69d1e1145 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">, 
Flags<[NoXarchOption]>;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   // Discard value names in assert builds unless otherwise specified.
   if (Args.hasFlag(options::OPT_fdiscard_value_names,
options::OPT_fno_discard_value_names, !IsAssertBuild)) {
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index ebe8a0520bf0fca..e6bb6f80f00368b 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -525,6 +525,11 @@
 // CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
 // CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
 
+// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-VERIFY-MACHINE-CODE %s
+// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s
+// CHECK-VERIFY-MACHINE-CODE: "-mllvm" "-verify-machineinstrs"
+// CHECK-NO-VERIFY-MACHINE-CODE-NOT: "-mllvm" "-verify-machineinstrs"
+
 // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-DISCARD-NAMES %s
 // RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-DISCARD-NAMES %s
 // CHECK-DISCARD-NAMES: "-discard-value-names"

``




https://github.com/llvm/llvm-project/pull/70282

[clang] [clang][Sema] Resolving Inconsistent Arguments Panic in Variadic Template Variables (PR #70280)

2023-10-25 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 04ca1b6bd938646874b6518067f03515d88c3b5b 
e26572e5cf6ce85221bf25f74a1ace05240e910d -- clang/lib/Sema/SemaOverload.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 187922a86116..4e89f4f50b8a 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11045,8 +11045,8 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   }
 
   bool isVariadic = false;
-  for(unsigned N = 0 ; N < Fn->getNumParams(); N++) {
-if( Fn->getParamDecl(N)->isParameterPack()) {
+  for (unsigned N = 0; N < Fn->getNumParams(); N++) {
+if (Fn->getParamDecl(N)->isParameterPack()) {
   isVariadic = true;
   break;
 }
@@ -11060,8 +11060,9 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument && !isVariadic ? Fn->getParamDecl(I)->getSourceRange() 
: SourceRange();
+  SourceRange ToParamRange = !isObjectArgument && !isVariadic
+ ? Fn->getParamDecl(I)->getSourceRange()
+ : SourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");

``




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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/70282

Present shortcomings are that this only works for non-LTO builds, and that this 
new pass doesn't work quite the same as the IR verification flag, as it runs 
between every machine pass and is thus much more expensive.

Though I recently discussed this with @aeubanks during the US devmtg and we 
think this is worthwhile as a first step.

>From 8015101a24e302fae53fe19683024d47e9ae4d8d Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 4 Oct 2023 12:09:15 +0200
Subject: [PATCH] [Clang][Driver] Add new flags to control machine instruction
 verification

---
 clang/docs/ReleaseNotes.rst   | 7 +++
 clang/include/clang/Driver/Options.td | 6 ++
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/clang_f_opts.c  | 5 +
 4 files changed, 26 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..c190af69d1e1145 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">, 
Flags<[NoXarchOption]>;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   // Discard value names in assert builds unless otherwise specified.
   if (Args.hasFlag(options::OPT_fdiscard_value_names,
options::OPT_fno_discard_value_names, !IsAssertBuild)) {
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index ebe8a0520bf0fca..e6bb6f80f00368b 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -525,6 +525,11 @@
 // CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
 // CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
 
+// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-VERIFY-MACHINE-CODE %s
+// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s
+// CHECK-VERIFY-MACHINE-CODE: "-mllvm" "-verify-machineinstrs"
+// CHECK-NO-VERIFY-MACHINE-CODE-NOT: "-mllvm" "-verify-machineinstrs"
+
 // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-DISCARD-NAMES %s
 // RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck 

[clang] [clang][Sema] Resolving Inconsistent Arguments Panic in Variadic Template Variables (PR #70280)

2023-10-25 Thread via cfe-commits

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


[clang] [clang][Sema] Resolving Inconsistent Arguments Panic in Variadic Template Variables (PR #70280)

2023-10-25 Thread via cfe-commits

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


[clang] [clang][deps] Skip slow `UNHASHED_CONTROL_BLOCK` records (PR #69975)

2023-10-25 Thread Chuanqi Xu via cfe-commits


@@ -219,6 +219,12 @@ class HeaderSearchOptions {
 
   unsigned ModulesValidateDiagnosticOptions : 1;
 
+  /// Whether to entirely skip writing diagnostic options.
+  unsigned ModulesSkipDiagnosticOptions : 1;
+
+  /// Whether to entirely skip writing header search paths.

ChuanqiXu9 wrote:

Then let's try to add comments about these two options are primarily used for 
deps scanning. It is helpful for future developers.

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


[clang] [clang][Sema] Resolving Panic Caused by Inconsistent Arguments in Var… (PR #70280)

2023-10-25 Thread via cfe-commits

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


[clang] [clang][Sema] Resolving Panic Caused by Inconsistent Arguments in Var… (PR #70280)

2023-10-25 Thread via cfe-commits

https://github.com/knightXun created 
https://github.com/llvm/llvm-project/pull/70280

…iadic Template Variables

When template variables are variadic, sema may panic, potentially leading to a 
situation
 where the number of function variables exceeds the number of template 
variables.
The sema compares the template signature and function signature parameters one 
by one,
 which can trigger an assertion error. This PR, when encountering variadic 
templates,
avoids comparing the template signature and function signature parameters one 
by one.

issue: https://github.com/llvm/llvm-project/issues/70191

>From e26572e5cf6ce85221bf25f74a1ace05240e910d Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Thu, 26 Oct 2023 09:25:58 +0800
Subject: [PATCH] [clang][Sema] Resolving Panic Caused by Inconsistent
 Arguments in Variadic Template Variables

When template variables are variadic, sema may panic, potentially leading to a 
situation
 where the number of function variables exceeds the number of template 
variables.
The sema compares the template signature and function signature parameters one 
by one,
 which can trigger an assertion error. This PR, when encountering variadic 
templates,
avoids comparing the template signature and function signature parameters one 
by one.

issue: https://github.com/llvm/llvm-project/issues/70191
---
 clang/lib/Sema/SemaOverload.cpp | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index db386fef0661c05..187922a8611614e 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11044,6 +11044,14 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   I--;
   }
 
+  bool isVariadic = false;
+  for(unsigned N = 0 ; N < Fn->getNumParams(); N++) {
+if( Fn->getParamDecl(N)->isParameterPack()) {
+  isVariadic = true;
+  break;
+}
+  }
+
   std::string FnDesc;
   std::pair FnKindPair =
   ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, Cand->getRewriteKind(),
@@ -11053,7 +11061,7 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
   SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  !isObjectArgument && !isVariadic ? Fn->getParamDecl(I)->getSourceRange() 
: SourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Ed Maste via cfe-commits

https://github.com/emaste commented:

overall looks fine, no objection from FreeBSD.
one open question.

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Ed Maste via cfe-commits


@@ -191,11 +191,6 @@
 // RUN:   | FileCheck -check-prefix=CHECK-MIPS64-CPU %s
 // CHECK-MIPS64-CPU: "-target-cpu" "mips3"
 
-// Check that the integrated assembler is enabled for SPARC64

emaste wrote:

why is this part here (before sparc64 is removed from FreeBSD)? It is not 
covered by the commit message anyway, afaict

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Ed Maste via cfe-commits


@@ -163,9 +163,9 @@
 // CHECK-ARM-EABIHF-NOT: as{{.*}}" "-mfpu=softvfp"
 // CHECK-ARM-EABIHF-NOT: as{{.*}}" "-matpcs"
 
-// RUN: %clang --target=sparc-unknown-freebsd -### %s -fpic -no-integrated-as 
2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-SPARC-PIE %s
-// CHECK-SPARC-PIE: as{{.*}}" "-KPIC
+// RUN: %clang --target=sparc64-unknown-freebsd -### %s -fpic 
-no-integrated-as 2>&1 \

emaste wrote:

fwiw sparc64 is still supported in FreeBSD 12.x, but that is EOL at the end of 
the year, so this could go before too long as well

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Ed Maste via cfe-commits


@@ -247,12 +247,8 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 switch (os) {
 case llvm::Triple::Linux:
   return std::make_unique>(Triple, Opts);
-case llvm::Triple::FreeBSD:

emaste wrote:

OK - there are no supported FreeBSD releases left that support armeb, and it 
was uncommon enough that I can't imagine anyone wants to use contemporary clang 
to target unsupported releases.

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


[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-25 Thread Craig Topper via cfe-commits

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

LGTM

https://github.com/llvm/llvm-project/pull/65756
___
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 misc-unused-using-decls false positive false for using in elaborated type (PR #70230)

2023-10-25 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] 04ca1b6 - [clang-tidy]fix misc-unused-using-decls false positive false for using in elaborated type (#70230)

2023-10-25 Thread via cfe-commits

Author: Congcong Cai
Date: 2023-10-26T09:24:17+08:00
New Revision: 04ca1b6bd938646874b6518067f03515d88c3b5b

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

LOG: [clang-tidy]fix misc-unused-using-decls false positive false for using in 
elaborated type (#70230)

`ElaboratedType` including tag keywords and any nested-name-specifiers.
We should ignore nested-name-specifiers case but consider tag keywords
case for `misc-unused-using-decls` check
Fixes: #69714

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 14b6aca6f3b8fac..051375263e53c3f 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -8,6 +8,7 @@
 
 #include "UnusedUsingDeclsCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
 
@@ -71,6 +72,10 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder 
*Finder) {
  templateArgument().bind("used",
  this);
   Finder->addMatcher(userDefinedLiteral().bind("used"), this);
+  Finder->addMatcher(
+  loc(elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
+ 
hasUnqualifiedDesugaredType(type().bind("usedType",
+  this);
   // Cases where we can identify the UsingShadowDecl directly, rather than
   // just its target.
   // FIXME: cover more cases in this way, as the AST supports it.
@@ -145,6 +150,12 @@ void UnusedUsingDeclsCheck::check(const 
MatchFinder::MatchResult ) {
 return;
   }
 
+  if (const auto *T = Result.Nodes.getNodeAs("usedType")) {
+if (const auto *ND = T->getAsTagDecl())
+  RemoveNamedDecl(ND);
+return;
+  }
+
   if (const auto *UsedShadow =
   Result.Nodes.getNodeAs("usedShadow")) {
 removeFromFoundDecls(UsedShadow->getTargetDecl());

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fb2226f15045996..6d1992e12130d65 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -291,6 +291,10 @@ Changes in existing checks
   ` check to ignore
   false-positives in unevaluated context (e.g., ``decltype``).
 
+- Improved :doc:`misc-unused-using-decls
+  ` check to avoid false positive 
when
+  using in elaborated type.
+
 - Improved :doc:`modernize-avoid-bind
   ` check to
   not emit a ``return`` for fixes when the function returns ``void``.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
index 7d02aa4d2e2bf90..12fc18f340f2130 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -213,3 +213,12 @@ template  class U> class 
Bar {};
 // We used to report Q unsued, because we only checked the first template
 // argument.
 Bar *bar;
+
+namespace gh69714 {
+struct StructGH69714_1 {};
+struct StructGH69714_2 {};
+} // namespace gh69714
+using gh69714::StructGH69714_1;
+using gh69714::StructGH69714_2;
+struct StructGH69714_1 a;
+struct StructGH69714_2 *b;



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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes (PR #69242)

2023-10-25 Thread Congcong Cai via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Add StrictMode to cppcoreguidelines-pro-type-static-cast-downcast (PR #69529)

2023-10-25 Thread Congcong Cai via cfe-commits


@@ -14,3 +14,11 @@ unrelated type ``Z``.
 This rule is part of the `Type safety (Type.2)
 
`_
 profile from the C++ Core Guidelines.
+
+Options
+---
+
+.. option:: StrictMode
+
+  When set to `false`, no warnings are emitted for casts on non-polymorphic
+  types. Default is `true`.

HerrCai0907 wrote:

Why "Default is `true`"? I think Default false will keep the same behavior as 
old version.

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


[clang-tools-extra] [clang-tidy] Support functional cast in bugprone-dangling-handle (PR #69067)

2023-10-25 Thread Congcong Cai via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (PR #69501)

2023-10-25 Thread Congcong Cai via cfe-commits

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


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


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

2023-10-25 Thread Chen Zheng via cfe-commits


@@ -80,6 +80,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool IsISA3_0 = false;
   bool IsISA3_1 = false;
   bool HasQuadwordAtomics = false;
+  bool FullRegisterNames = false;

chenzheng1030 wrote:

Using a target feature bit for assembly printing seems not match other bits. 
IIUC, all the bits here should control the available instructions on a 
subtarget.

Could we use an option in `TargetMachine::Options::MCOptions`? this looks like 
the way where clang can accept an option and control the code generation in the 
backend. The current option `Options.MCOptions.PreserveAsmComments` seems a 
little similar with this functionality.

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


[clang] [OpenMP] Unify the min/max thread/teams pathways (PR #70273)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Johannes Doerfert (jdoerfert)


Changes

We used to pass the min/max threads/teams values through different paths
  from the frontend to the middle end. This simplifies the situation by
  passing the values once, only when we will create the KernelEnvironment,
  which contains the values. At that point we also manifest the metadata,
  as appropriate. Some footguns have also been removed, e.g., our target
  check is now triple-based, not calling convention-based, as the latter
  is dependent on the ordering of operations. The types of the values have
  been unified to int32_t.

---

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


50 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+59-35) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.h (+11-2) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+20-10) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.h (+2-2) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+11-3) 
- (modified) clang/lib/CodeGen/Targets/AMDGPU.cpp (+8-2) 
- (modified) clang/lib/CodeGen/Targets/NVPTX.cpp (+33-13) 
- (modified) clang/test/OpenMP/ompx_attributes_codegen.cpp (+22-12) 
- (modified) clang/test/OpenMP/target_num_teams_num_threads_attributes.cpp 
(+11-98) 
- (modified) clang/test/OpenMP/target_parallel_codegen.cpp (+62-62) 
- (modified) clang/test/OpenMP/target_parallel_debug_codegen.cpp (+420-420) 
- (modified) clang/test/OpenMP/target_parallel_for_codegen.cpp (+122-122) 
- (modified) clang/test/OpenMP/target_parallel_for_debug_codegen.cpp (+589-589) 
- (modified) clang/test/OpenMP/target_parallel_for_simd_codegen.cpp (+136-136) 
- (modified) clang/test/OpenMP/target_parallel_generic_loop_codegen-3.cpp 
(+589-589) 
- (modified) clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp 
(+998-998) 
- (modified) clang/test/OpenMP/teams_distribute_simd_codegen.cpp (+206-206) 
- (modified) clang/test/OpenMP/thread_limit_nvptx.c (+4-4) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h (+37-12) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (+1-1) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+152-88) 
- (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+31) 
- (modified) llvm/test/Transforms/OpenMP/always_inline_device.ll (+3-3) 
- (modified) llvm/test/Transforms/OpenMP/custom_state_machines.ll (+41-41) 
- (modified) llvm/test/Transforms/OpenMP/custom_state_machines_pre_lto.ll 
(+57-57) 
- (modified) llvm/test/Transforms/OpenMP/custom_state_machines_remarks.ll 
(+3-3) 
- (modified) llvm/test/Transforms/OpenMP/deduplication_target.ll (+2-2) 
- (modified) 
llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll (+7-7) 
- (modified) llvm/test/Transforms/OpenMP/global_constructor.ll (+2-2) 
- (modified) llvm/test/Transforms/OpenMP/globalization_remarks.ll (+2-2) 
- (modified) 
llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll 
(+2-2) 
- (modified) llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll (+9-9) 
- (modified) llvm/test/Transforms/OpenMP/nested_parallelism.ll (+5-5) 
- (modified) llvm/test/Transforms/OpenMP/parallel_deletion.ll (+25-25) 
- (modified) llvm/test/Transforms/OpenMP/parallel_level_fold.ll (+7-7) 
- (modified) llvm/test/Transforms/OpenMP/remove_globalization.ll (+4-4) 
- (modified) llvm/test/Transforms/OpenMP/replace_globalization.ll (+7-7) 
- (modified) llvm/test/Transforms/OpenMP/single_threaded_execution.ll (+2-2) 
- (modified) llvm/test/Transforms/OpenMP/spmdization.ll (+43-43) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_assumes.ll (+3-3) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_constant_prop.ll (+3-3) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_guarding.ll (+4-4) 
- (modified) 
llvm/test/Transforms/OpenMP/spmdization_guarding_two_reaching_kernels.ll (+7-7) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_indirect.ll (+13-13) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_kernel_env_dep.ll (+3-3) 
- (modified) 
llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll 
(+7-7) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_remarks.ll (+3-3) 
- (modified) llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll (+3-3) 
- (modified) llvm/test/Transforms/PhaseOrdering/openmp-opt-module.ll (+2-2) 
- (modified) openmp/libomptarget/include/Environment.h (+7) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index aae1a0ea250eea2..640780812052380 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6002,6 +6002,42 @@ void 
CGOpenMPRuntime::emitUsesAllocatorsFini(CodeGenFunction ,
   {ThreadId, AllocatorVal});
 }
 
+void CGOpenMPRuntime::computeMinAndMaxThreadsAndTeams(
+const OMPExecutableDirective , CodeGenFunction ,
+

[clang] [OpenMP] Unify the min/max thread/teams pathways (PR #70273)

2023-10-25 Thread Johannes Doerfert via cfe-commits

jdoerfert wrote:

This contains two other commits that are in two other PRs and will be committed 
first.

https://github.com/llvm/llvm-project/pull/70273
___
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 misc-unused-using-decls false positive false for using in elaborated type (PR #70230)

2023-10-25 Thread Congcong Cai via cfe-commits

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

>From 7ba5e132f50730b9e9cb392df7a2756066a7e909 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 23 Oct 2023 09:00:26 +0800
Subject: [PATCH 1/2] [clang-tidy]fix misc-unused-using-decls false positive
 false for using in elaborated type

---
 .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 11 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../clang-tidy/checkers/misc/unused-using-decls.cpp   |  9 +
 3 files changed, 24 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 14b6aca6f3b8fac..14f822c1c086ab9 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -8,6 +8,7 @@
 
 #include "UnusedUsingDeclsCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
 
@@ -71,6 +72,10 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder 
*Finder) {
  templateArgument().bind("used",
  this);
   Finder->addMatcher(userDefinedLiteral().bind("used"), this);
+  Finder->addMatcher(
+  elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
+ hasUnqualifiedDesugaredType(type().bind("usedType"))),
+  this);
   // Cases where we can identify the UsingShadowDecl directly, rather than
   // just its target.
   // FIXME: cover more cases in this way, as the AST supports it.
@@ -145,6 +150,12 @@ void UnusedUsingDeclsCheck::check(const 
MatchFinder::MatchResult ) {
 return;
   }
 
+  if (const auto *T = Result.Nodes.getNodeAs("usedType")) {
+if (const auto *ND = T->getAsTagDecl())
+  RemoveNamedDecl(ND);
+return;
+  }
+
   if (const auto *UsedShadow =
   Result.Nodes.getNodeAs("usedShadow")) {
 removeFromFoundDecls(UsedShadow->getTargetDecl());
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b5348384e965ab5..3227e2ef9d81c83 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -290,6 +290,10 @@ Changes in existing checks
   ` check to ignore
   false-positives in unevaluated context (e.g., ``decltype``).
 
+- Improved :doc:`misc-unused-using-decls
+  ` check to avoid false positive 
when
+  using in elaborated type.
+
 - Improved :doc:`modernize-avoid-bind
   ` check to
   not emit a ``return`` for fixes when the function returns ``void``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
index 7d02aa4d2e2bf90..12fc18f340f2130 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -213,3 +213,12 @@ template  class U> class 
Bar {};
 // We used to report Q unsued, because we only checked the first template
 // argument.
 Bar *bar;
+
+namespace gh69714 {
+struct StructGH69714_1 {};
+struct StructGH69714_2 {};
+} // namespace gh69714
+using gh69714::StructGH69714_1;
+using gh69714::StructGH69714_2;
+struct StructGH69714_1 a;
+struct StructGH69714_2 *b;

>From 8ebd9194788e1d57dc46ed710d932a10db301d67 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 26 Oct 2023 08:36:19 +0800
Subject: [PATCH 2/2] fix

---
 clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 14f822c1c086ab9..051375263e53c3f 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -73,8 +73,8 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder 
*Finder) {
  this);
   Finder->addMatcher(userDefinedLiteral().bind("used"), this);
   Finder->addMatcher(
-  elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
- hasUnqualifiedDesugaredType(type().bind("usedType"))),
+  loc(elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
+ 
hasUnqualifiedDesugaredType(type().bind("usedType",
   this);
   // Cases where we can identify the UsingShadowDecl directly, rather than
   // just its target.

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


[clang] 265ed68 - [clang-format] Fix a JavaScript import order bug

2023-10-25 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-10-25T17:06:53-07:00
New Revision: 265ed6819409a9d76f112a601d48b971904921c8

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

LOG: [clang-format] Fix a JavaScript import order bug

When the imported symbol is exactly "template" the sorting is disabled.
"import {template} from x;" is not recognized as an import.

Differential Revision: https://reviews.llvm.org/D61663

Added: 


Modified: 
clang/lib/Format/SortJavaScriptImports.cpp
clang/unittests/Format/SortImportsTestJS.cpp

Removed: 




diff  --git a/clang/lib/Format/SortJavaScriptImports.cpp 
b/clang/lib/Format/SortJavaScriptImports.cpp
index 9afe85aeed437ef..8c6722e915344fb 100644
--- a/clang/lib/Format/SortJavaScriptImports.cpp
+++ b/clang/lib/Format/SortJavaScriptImports.cpp
@@ -548,10 +548,12 @@ class JavaScriptImportSorter : public TokenAnalyzer {
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  bool isTypeOnly =
-  Current->is(Keywords.kw_type) && Current->Next &&
-  Current->Next->isOneOf(tok::identifier, tok::kw_default);
-  if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
+  auto IsIdentifier = [](const auto *Tok) {
+return Tok->isOneOf(tok::identifier, tok::kw_default, 
tok::kw_template);
+  };
+  bool isTypeOnly = Current->is(Keywords.kw_type) && Current->Next &&
+IsIdentifier(Current->Next);
+  if (!isTypeOnly && !IsIdentifier(Current))
 return false;
 
   JsImportedSymbol Symbol;
@@ -565,7 +567,7 @@ class JavaScriptImportSorter : public TokenAnalyzer {
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (!Current->isOneOf(tok::identifier, tok::kw_default))
+if (!IsIdentifier(Current))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();

diff  --git a/clang/unittests/Format/SortImportsTestJS.cpp 
b/clang/unittests/Format/SortImportsTestJS.cpp
index 2778d6efcdf9a3f..c724fcc073f59e2 100644
--- a/clang/unittests/Format/SortImportsTestJS.cpp
+++ b/clang/unittests/Format/SortImportsTestJS.cpp
@@ -514,6 +514,14 @@ TEST_F(SortImportsTestJS, ImportExportType) {
  "export {Y};\n");
 }
 
+TEST_F(SortImportsTestJS, TemplateKeyword) {
+  // Reproduces issue where importing "template" disables imports sorting.
+  verifySort("import {template} from './a';\n"
+ "import {b} from './b';\n",
+ "import {b} from './b';\n"
+ "import {template} from './a';");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang



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


[PATCH] D61663: [clang-format] Fix a JavaScript import order bug.

2023-10-25 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG265ed6819409: [clang-format] Fix a JavaScript import order 
bug (authored by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D61663?vs=557879=557888#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61663

Files:
  clang/lib/Format/SortJavaScriptImports.cpp
  clang/unittests/Format/SortImportsTestJS.cpp


Index: clang/unittests/Format/SortImportsTestJS.cpp
===
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -514,6 +514,14 @@
  "export {Y};\n");
 }
 
+TEST_F(SortImportsTestJS, TemplateKeyword) {
+  // Reproduces issue where importing "template" disables imports sorting.
+  verifySort("import {template} from './a';\n"
+ "import {b} from './b';\n",
+ "import {b} from './b';\n"
+ "import {template} from './a';");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/SortJavaScriptImports.cpp
===
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -548,10 +548,12 @@
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  bool isTypeOnly =
-  Current->is(Keywords.kw_type) && Current->Next &&
-  Current->Next->isOneOf(tok::identifier, tok::kw_default);
-  if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
+  auto IsIdentifier = [](const auto *Tok) {
+return Tok->isOneOf(tok::identifier, tok::kw_default, 
tok::kw_template);
+  };
+  bool isTypeOnly = Current->is(Keywords.kw_type) && Current->Next &&
+IsIdentifier(Current->Next);
+  if (!isTypeOnly && !IsIdentifier(Current))
 return false;
 
   JsImportedSymbol Symbol;
@@ -565,7 +567,7 @@
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (!Current->isOneOf(tok::identifier, tok::kw_default))
+if (!IsIdentifier(Current))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();


Index: clang/unittests/Format/SortImportsTestJS.cpp
===
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -514,6 +514,14 @@
  "export {Y};\n");
 }
 
+TEST_F(SortImportsTestJS, TemplateKeyword) {
+  // Reproduces issue where importing "template" disables imports sorting.
+  verifySort("import {template} from './a';\n"
+ "import {b} from './b';\n",
+ "import {b} from './b';\n"
+ "import {template} from './a';");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/SortJavaScriptImports.cpp
===
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -548,10 +548,12 @@
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  bool isTypeOnly =
-  Current->is(Keywords.kw_type) && Current->Next &&
-  Current->Next->isOneOf(tok::identifier, tok::kw_default);
-  if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
+  auto IsIdentifier = [](const auto *Tok) {
+return Tok->isOneOf(tok::identifier, tok::kw_default, tok::kw_template);
+  };
+  bool isTypeOnly = Current->is(Keywords.kw_type) && Current->Next &&
+IsIdentifier(Current->Next);
+  if (!isTypeOnly && !IsIdentifier(Current))
 return false;
 
   JsImportedSymbol Symbol;
@@ -565,7 +567,7 @@
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (!Current->isOneOf(tok::identifier, tok::kw_default))
+if (!IsIdentifier(Current))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][OpenMP] Fix target data if/logical expression assert fail (PR #70268)

2023-10-25 Thread Akash Banerjee via cfe-commits

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

Thanks for the fix and also adding a test

LGTM 

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


[clang-tools-extra] [mlir] Add config for PDL (PR #69927)

2023-10-25 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

Can you expand on the motivation? Why is it a problem that PDL is always 
included? Your description isn’t very explicit on the impact.

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


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

2023-10-25 Thread Stefan Pintilie via cfe-commits

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

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

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

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

[clang-tools-extra] [libc++] Fix the behavior of throwing `operator new` under -fno-exceptions (PR #69498)

2023-10-25 Thread via cfe-commits

EricWF wrote:

@ldionne  You've fully convinced me on this approach. Thank you for the 
explanation. 

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


[clang] [Clang][OpenMP] Emit unsupported directive error (PR #70233)

2023-10-25 Thread Shilei Tian via cfe-commits

shiltian wrote:

Can you add a small test to check the error message is correctly emitted? You 
can refer to those diagnosis tests under `clang/test/OpenMP`.

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


[clang] [Clang][OpenMP] Emit unsupported directive error (PR #70233)

2023-10-25 Thread Shilei Tian via cfe-commits

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Brad Smith via cfe-commits

brad0 wrote:

ping.

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


[clang] [Driver][Solaris][NFC] A little bit of clean up (PR #69867)

2023-10-25 Thread Brad Smith via cfe-commits

brad0 wrote:

ping.

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


[clang] [clang][OpenMP] Fix target data if/logical expression assert fail (PR #70268)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David Pagan (ddpagan)


Changes

Fixed assertion failure

  Basic Block in function 'main' does not have terminator!
  label %land.end

caused by premature setting of CodeGenIP upon entry to emitTargetDataCalls, 
where subsequent evaluation of logical expression created new basic blocks, 
leaving CodeGenIP pointing to the wrong basic block. CodeGenIP is now set near 
the end of the function, just prior to generating a comparison of the logical 
expression result (from the if clause) which uses CodeGenIP to insert new IR.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+5-5) 
- (added) clang/test/OpenMP/target_data_if_logical_codegen.cpp (+120) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index aae1a0ea250eea2..75fad160b716207 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -10230,11 +10230,6 @@ void CGOpenMPRuntime::emitTargetDataCalls(
   PrePostActionTy NoPrivAction;
 
   using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
-  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
- CGF.AllocaInsertPt->getIterator());
-  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
-  CGF.Builder.GetInsertPoint());
-  llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CodeGenIP);
 
   llvm::Value *IfCondVal = nullptr;
   if (IfCond)
@@ -10314,6 +10309,11 @@ void CGOpenMPRuntime::emitTargetDataCalls(
   // Source location for the ident struct
   llvm::Value *RTLoc = emitUpdateLocation(CGF, D.getBeginLoc());
 
+  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
+ CGF.AllocaInsertPt->getIterator());
+  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
+  CGF.Builder.GetInsertPoint());
+  llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CodeGenIP);
   CGF.Builder.restoreIP(OMPBuilder.createTargetData(
   OmpLoc, AllocaIP, CodeGenIP, DeviceID, IfCondVal, Info, GenMapInfoCB,
   /*MapperFunc=*/nullptr, BodyCB, DeviceAddrCB, CustomMapperCB, RTLoc));
diff --git a/clang/test/OpenMP/target_data_if_logical_codegen.cpp 
b/clang/test/OpenMP/target_data_if_logical_codegen.cpp
new file mode 100644
index 000..85d98b0c3bcd4d8
--- /dev/null
+++ b/clang/test/OpenMP/target_data_if_logical_codegen.cpp
@@ -0,0 +1,120 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _ --version 3
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+
+// Check same results after serialization round-trip
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -include-pch %t -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+extern bool foo(bool);
+
+int if_logical() {
+  bool a = foo(true);
+  bool b = foo(true);
+  int pp = 42;
+  int *p = 
+  #pragma omp target data if(a && b) map(to: p[0])
+  {
+p[0]++;
+  }
+  if (p[0])
+return 1;
+  return 0;
+}
+
+int main() {
+  return if_logical();
+}
+
+#endif
+// CHECK-LABEL: define dso_local noundef i32 @_Z10if_logicalv(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[A:%.*]] = alloca i8, align 1
+// CHECK-NEXT:[[B:%.*]] = alloca i8, align 1
+// CHECK-NEXT:[[PP:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[P:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [1 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [1 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [1 x ptr], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noundef zeroext i1 @_Z3foob(i1 noundef 
zeroext true)
+// CHECK-NEXT:[[FROMBOOL:%.*]] = zext i1 [[CALL]] to i8
+// CHECK-NEXT:store i8 [[FROMBOOL]], ptr [[A]], align 1
+// CHECK-NEXT:[[CALL1:%.*]] = call noundef zeroext i1 @_Z3foob(i1 noundef 
zeroext true)
+// CHECK-NEXT:[[FROMBOOL2:%.*]] = zext i1 [[CALL1]] to i8
+// CHECK-NEXT:store i8 [[FROMBOOL2]], ptr [[B]], align 1
+// CHECK-NEXT:store i32 42, ptr [[PP]], align 4
+// CHECK-NEXT:store ptr [[PP]], ptr [[P]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, ptr [[A]], align 1
+// CHECK-NEXT:[[TOBOOL:%.*]] = trunc i8 [[TMP0]] to i1
+// 

[clang] [clang][OpenMP] Fix target data if/logical expression assert fail (PR #70268)

2023-10-25 Thread David Pagan via cfe-commits

https://github.com/ddpagan created 
https://github.com/llvm/llvm-project/pull/70268

Fixed assertion failure

  Basic Block in function 'main' does not have terminator!
  label %land.end

caused by premature setting of CodeGenIP upon entry to emitTargetDataCalls, 
where subsequent evaluation of logical expression created new basic blocks, 
leaving CodeGenIP pointing to the wrong basic block. CodeGenIP is now set near 
the end of the function, just prior to generating a comparison of the logical 
expression result (from the if clause) which uses CodeGenIP to insert new IR.

>From d027a1c75322c7158560630d382f8ab01726a728 Mon Sep 17 00:00:00 2001
From: Dave Pagan 
Date: Tue, 24 Oct 2023 14:12:56 -0500
Subject: [PATCH] [clang][OpenMP] Fix target data if/logical expression assert
 fail

Fixed assertion failure

  Basic Block in function 'main' does not have terminator!
  label %land.end

caused by premature setting of CodeGenIP upon entry to
emitTargetDataCalls, where subsequent evaluation of logical
expression created new basic blocks, leaving CodeGenIP pointing to
the wrong basic block. CodeGenIP is now set near the end of the
function, just prior to generating a comparison of the logical
expression result (from the if clause) which uses CodeGenIP to
insert new IR.
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp |  10 +-
 .../OpenMP/target_data_if_logical_codegen.cpp | 120 ++
 2 files changed, 125 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/OpenMP/target_data_if_logical_codegen.cpp

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index aae1a0ea250eea2..75fad160b716207 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -10230,11 +10230,6 @@ void CGOpenMPRuntime::emitTargetDataCalls(
   PrePostActionTy NoPrivAction;
 
   using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
-  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
- CGF.AllocaInsertPt->getIterator());
-  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
-  CGF.Builder.GetInsertPoint());
-  llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CodeGenIP);
 
   llvm::Value *IfCondVal = nullptr;
   if (IfCond)
@@ -10314,6 +10309,11 @@ void CGOpenMPRuntime::emitTargetDataCalls(
   // Source location for the ident struct
   llvm::Value *RTLoc = emitUpdateLocation(CGF, D.getBeginLoc());
 
+  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
+ CGF.AllocaInsertPt->getIterator());
+  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
+  CGF.Builder.GetInsertPoint());
+  llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CodeGenIP);
   CGF.Builder.restoreIP(OMPBuilder.createTargetData(
   OmpLoc, AllocaIP, CodeGenIP, DeviceID, IfCondVal, Info, GenMapInfoCB,
   /*MapperFunc=*/nullptr, BodyCB, DeviceAddrCB, CustomMapperCB, RTLoc));
diff --git a/clang/test/OpenMP/target_data_if_logical_codegen.cpp 
b/clang/test/OpenMP/target_data_if_logical_codegen.cpp
new file mode 100644
index 000..85d98b0c3bcd4d8
--- /dev/null
+++ b/clang/test/OpenMP/target_data_if_logical_codegen.cpp
@@ -0,0 +1,120 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _ --version 3
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+
+// Check same results after serialization round-trip
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -include-pch %t -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+extern bool foo(bool);
+
+int if_logical() {
+  bool a = foo(true);
+  bool b = foo(true);
+  int pp = 42;
+  int *p = 
+  #pragma omp target data if(a && b) map(to: p[0])
+  {
+p[0]++;
+  }
+  if (p[0])
+return 1;
+  return 0;
+}
+
+int main() {
+  return if_logical();
+}
+
+#endif
+// CHECK-LABEL: define dso_local noundef i32 @_Z10if_logicalv(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[A:%.*]] = alloca i8, align 1
+// CHECK-NEXT:[[B:%.*]] = alloca i8, align 1
+// CHECK-NEXT:[[PP:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[P:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [1 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [1 x ptr], align 8
+// CHECK-NEXT:

[clang] [OpenMP 5.2] Deprecate old syntax of linear clause (PR #70152)

2023-10-25 Thread Fazlay Rabbi via cfe-commits

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


[clang] 9237ce4 - [OpenMP 5.2] Deprecate old syntax of linear clause (#70152)

2023-10-25 Thread via cfe-commits

Author: Fazlay Rabbi
Date: 2023-10-25T15:36:36-07:00
New Revision: 9237ce46138c311849e7de19a9a3ea930f1dbd6d

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

LOG: [OpenMP 5.2] Deprecate old syntax of linear clause (#70152)

The syntax of the linear clause that specifies its argument and
linear-modifier as linear-modifier(list) was deprecated since OpenMP 5.2
and the step modifier was added for specifying the linear step.

Reference: OpenMP 5.2 Spec, Page 627, Line 15

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseOpenMP.cpp
clang/test/OpenMP/for_ast_print.cpp
clang/test/OpenMP/for_linear_messages.cpp
clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/master_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/parallel_masked_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/parallel_master_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/simd_linear_messages.cpp
clang/test/OpenMP/taskloop_simd_linear_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 902fbf4a0d692c0..de180344fcc5c74 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1350,6 +1350,8 @@ def warn_omp_extra_tokens_at_eol : Warning<
   InGroup;
 def err_omp_multiple_step_or_linear_modifier : Error<
   "multiple %select{'step size'|'linear modifier'}0 found in linear clause">;
+def err_omp_deprecate_old_syntax: Error<
+  "old syntax '%0' on '%1' clause was deprecated, use new syntax '%2'">;
 def warn_pragma_expected_colon_r_paren : Warning<
   "missing ':' or ')' after %0 - ignoring">, InGroup;
 def err_omp_unknown_directive : Error<

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 4f3b8a28ee47ef3..3e7d8274aeefc52 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4573,6 +4573,10 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind 
DKind,
   Data.ExtraModifierLoc = ConsumeToken();
   LinearT.consumeOpen();
   NeedRParenForLinear = true;
+  if (getLangOpts().OpenMP >= 52)
+Diag(Data.ExtraModifierLoc, diag::err_omp_deprecate_old_syntax)
+<< "linear-modifier(list)" << getOpenMPClauseName(Kind)
+<< "linear(list: [linear-modifier,] step(step-size))";
 }
   } else if (Kind == OMPC_lastprivate) {
 // Try to parse modifier if any.

diff  --git a/clang/test/OpenMP/for_ast_print.cpp 
b/clang/test/OpenMP/for_ast_print.cpp
index 0a3c694ba162dab..abc27caa9ae8d4f 100644
--- a/clang/test/OpenMP/for_ast_print.cpp
+++ b/clang/test/OpenMP/for_ast_print.cpp
@@ -48,7 +48,11 @@ class S7 : public T {
 #pragma omp for lastprivate(a) lastprivate(this->a) lastprivate(T::a)
 for (int k = 0; k < a.a; ++k)
   ++this->a.a;
+#if defined(OMP52)
+#pragma omp for linear(c: val)
+#else
 #pragma omp for linear(val(c))
+#endif
 for (int k = 0; k < a.a; ++k)
   ++this->a.a;
   }
@@ -59,7 +63,11 @@ class S7 : public T {
 #pragma omp for lastprivate(a) lastprivate(this->a)
 for (int k = 0; k < s.a.a; ++k)
   ++s.a.a;
+#if defined(OMP52)
+#pragma omp for linear(this->b: uval)
+#else
 #pragma omp for linear(uval(this->b))
+#endif
 for (int k = 0; k < s.a.a; ++k)
   ++s.a.a;
 return *this;
@@ -87,7 +95,11 @@ class S8 : public S7 {
 #pragma omp for lastprivate(a) lastprivate(this->a) lastprivate(S7::a)
 for (int k = 0; k < a.a; ++k)
   ++this->a.a;
+#if defined(OMP52)
+#pragma omp for linear(S7::d: ref)
+#else
 #pragma omp for linear(ref(S7::d))
+#endif
 for (int k = 0; k < a.a; ++k)
   ++this->a.a;
   }

diff  --git a/clang/test/OpenMP/for_linear_messages.cpp 
b/clang/test/OpenMP/for_linear_messages.cpp
index 03c5c763d7b5c1d..d8d3391c0c27150 100644
--- a/clang/test/OpenMP/for_linear_messages.cpp
+++ b/clang/test/OpenMP/for_linear_messages.cpp
@@ -215,6 +215,8 @@ int main(int argc, char **argv) {
 int i;
 #pragma omp for linear(i)
 for (int k = 0; k < argc; ++k) ++k;
+#pragma omp for linear(val(i)) // omp52-error {{old syntax 
'linear-modifier(list)' on 'linear' clause was deprecated, use new syntax 
'linear(list: [linear-modifier,] step(step-size))'}}
+for (int k = 0; k < argc; ++k) ++k;
 #ifdef OMP52
 #pragma omp for linear(i : step(4))
 #else

diff  --git a/clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp 
b/clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp
index 0bfca489ad5d151..50d2da7e8fd4da1 100644
--- a/clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp
+++ b/clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp
@@ -131,11 +131,11 @@ 

[clang] [clang][deps] Skip slow `UNHASHED_CONTROL_BLOCK` records (PR #69975)

2023-10-25 Thread Jan Svoboda via cfe-commits

jansvoboda11 wrote:

> Besides deps scanning, have you tried to enable these option to compile with 
> clang modules? I mean, if it is safe to enable such options at compilation 
> times, it looks a valid optimization for C++20 modules too.

I did not. I suspect it won't show in profiles of compiles the same way it does 
for scans, where this kind of overhead gets exacerbated.

> If it is not safe to do so, I think we need to document it explicitly.

This is a `-cc1`-only flag, so I don't think documenting the 
nuances/implications is super important.

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


[clang] [clang][deps] Skip slow `UNHASHED_CONTROL_BLOCK` records (PR #69975)

2023-10-25 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/69975

>From 0270c76e779457486ee89f100db2b7151832c290 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Tue, 10 Oct 2023 14:16:13 -0700
Subject: [PATCH 1/4] [clang][modules] Make `DIAGNOSTIC_OPTIONS` skippable

---
 clang/include/clang/Driver/Options.td |  4 ++
 clang/include/clang/Lex/HeaderSearchOptions.h |  6 ++-
 clang/lib/Serialization/ASTWriter.cpp |  4 ++
 .../Modules/diagnostic-options-mismatch.c | 41 +++
 4 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Modules/diagnostic-options-mismatch.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5415b18d3f406df..68ec32bdf56a555 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2944,6 +2944,10 @@ def fno_modules_validate_textual_header_includes :
   
MarshallingInfoNegativeFlag>,
   HelpText<"Do not enforce -fmodules-decluse and private header restrictions 
for textual headers. "
"This flag will be removed in a future Clang release.">;
+defm modules_skip_diagnostic_options : 
BoolFOption<"modules-skip-diagnostic-options",
+HeaderSearchOpts<"ModulesSkipDiagnosticOptions">, DefaultFalse,
+PosFlag,
+NegFlag, BothFlags<[], [CC1Option]>>;
 
 def fincremental_extensions :
   Flag<["-"], "fincremental-extensions">,
diff --git a/clang/include/clang/Lex/HeaderSearchOptions.h 
b/clang/include/clang/Lex/HeaderSearchOptions.h
index c7d95006bb779ad..d6dd94fe9466299 100644
--- a/clang/include/clang/Lex/HeaderSearchOptions.h
+++ b/clang/include/clang/Lex/HeaderSearchOptions.h
@@ -219,6 +219,9 @@ class HeaderSearchOptions {
 
   unsigned ModulesValidateDiagnosticOptions : 1;
 
+  /// Whether to entirely skip writing diagnostic options.
+  unsigned ModulesSkipDiagnosticOptions : 1;
+
   unsigned ModulesHashContent : 1;
 
   /// Whether we should include all things that could impact the module in the
@@ -238,7 +241,8 @@ class HeaderSearchOptions {
 ModulesValidateSystemHeaders(false),
 ValidateASTInputFilesContent(false),
 ForceCheckCXX20ModulesInputFiles(false), UseDebugInfo(false),
-ModulesValidateDiagnosticOptions(true), ModulesHashContent(false),
+ModulesValidateDiagnosticOptions(true),
+ModulesSkipDiagnosticOptions(false), ModulesHashContent(false),
 ModulesStrictContextHash(false) {}
 
   /// AddPath - Add the \p Path path to the specified \p Group list.
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 27700c711d52fdd..e063f8d6acc295a 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1215,6 +1215,9 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor 
,
   // Diagnostic options.
   const auto  = Context.getDiagnostics();
   const DiagnosticOptions  = Diags.getDiagnosticOptions();
+  if (!PP.getHeaderSearchInfo()
+   .getHeaderSearchOpts()
+   .ModulesSkipDiagnosticOptions) {
 #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name);
 #define ENUM_DIAGOPT(Name, Type, Bits, Default)
\
   Record.push_back(static_cast(DiagOpts.get##Name()));
@@ -1229,6 +1232,7 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor 
,
   // are generally transient files and will almost always be overridden.
   Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record);
   Record.clear();
+  }
 
   // Header search paths.
   Record.clear();
diff --git a/clang/test/Modules/diagnostic-options-mismatch.c 
b/clang/test/Modules/diagnostic-options-mismatch.c
new file mode 100644
index 000..cdd6f897729a9d8
--- /dev/null
+++ b/clang/test/Modules/diagnostic-options-mismatch.c
@@ -0,0 +1,41 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: split-file %s %t
+
+//--- module.modulemap
+module Mod { header "mod.h" }
+//--- mod.h
+//--- tu.c
+#include "mod.h"
+
+// Without any extra compiler flags, mismatched diagnostic options trigger 
recompilation of modules.
+//
+// RUN: %clang_cc1 -fmodules -fmodule-map-file=%t/module.modulemap 
-fmodules-cache-path=%t/cache1 -fdisable-module-hash \
+// RUN:   -fsyntax-only %t/tu.c -Wnon-modular-include-in-module
+// RUN: %clang_cc1 -fmodules -fmodule-map-file=%t/module.modulemap 
-fmodules-cache-path=%t/cache1 -fdisable-module-hash \
+// RUN:   -fsyntax-only %t/tu.c -Werror=non-modular-include-in-module 
-Rmodule-build 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DID-REBUILD
+// DID-REBUILD: remark: building module 'Mod'
+
+// When skipping serialization of diagnostic options, mismatches cannot be 
detected, old PCM file gets reused.
+//
+// RUN: %clang_cc1 -fmodules -fmodule-map-file=%t/module.modulemap 
-fmodules-cache-path=%t/cache2 -fdisable-module-hash \
+// RUN:   -fsyntax-only %t/tu.c -fmodules-skip-diagnostic-options 
-Wnon-modular-include-in-module
+// RUN: %clang_cc1 

  1   2   3   4   5   6   >