[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

2023-05-11 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

In D150124#4329163 , @ilya-biryukov 
wrote:

> In `clangd` we also have `findExplicitReferences` and `targetDecl` functions 
> that seem to handle the `GoToStmt`.

According to the commit message of the patch that added this, it was for "go to 
definition" functionality (which did indeed work already).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150124

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


[PATCH] D150364: [clang][Interp] Add 'Invalid' opcode and use it for throw/asm stmts

2023-05-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/records.cpp:341
+
+/// FIXME: Wrong source location below.
+return 12; // expected-note {{in call to '&S{}->~S()'}}

aaron.ballman wrote:
> Oh interesting -- does the old constexpr interpreter think the destructor is 
> called at the end of the block as opposed to at the end of the full 
> expression with the temporary?
I think it's the other way around and the new one does that (`expected` is the 
new one). Need to investigate that.


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

https://reviews.llvm.org/D150364

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


[PATCH] D150427: [AMDGPU] Non hostcall printf support for HIP

2023-05-11 Thread Vikram Hegde via Phabricator via cfe-commits
vikramRH created this revision.
vikramRH added reviewers: sameerds, b-sumner, yaxunl, arsenm.
Herald added subscribers: hoy, kerbowa, hiraditya, Anastasia, tpr, dstuttard, 
jvesely, kzhuravl.
Herald added a project: All.
vikramRH requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay, wdng.
Herald added projects: clang, LLVM.

This is an alternative to currently existing hostcall implementation and uses 
printf buffer similar to OpenCL,
The data stored in the buffer (i.e the data frame) for each printf call are as 
follows,

1. Control DWord - contains info regarding stream, format string constness and 
size of data frame
2. Hash of the format string (if constant) else the format string itself
3. Printf arguments (each aligned to 8 byte boundary)

The format string Hash is generated using LLVM's MD5 Message-Digest Algorithm 
implementation and only low 64 bits are used.
The implementation still uses amdhsa metadata and hash is stored as part of 
format string itself to ensure
minimal changes in runtime.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150427

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenHIP/printf_nonhostcall.cpp
  clang/test/Driver/hip-options.hip
  llvm/include/llvm/Transforms/Utils/AMDGPUEmitPrintf.h
  llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp

Index: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
===
--- llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
+++ llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
@@ -17,6 +17,8 @@
 #include "llvm/Transforms/Utils/AMDGPUEmitPrintf.h"
 #include "llvm/ADT/SparseBitVector.h"
 #include "llvm/Analysis/ValueTracking.h"
+#include "llvm/Support/DataExtractor.h"
+#include "llvm/Support/MD5.h"
 
 using namespace llvm;
 
@@ -179,9 +181,8 @@
 
 // Scan the format string to locate all specifiers, and mark the ones that
 // specify a string, i.e, the "%s" specifier with optional '*' characters.
-static void locateCStrings(SparseBitVector<8> &BV, Value *Fmt) {
-  StringRef Str;
-  if (!getConstantStringInfo(Fmt, Str) || Str.empty())
+static void locateCStrings(SparseBitVector<8> &BV, Value *Fmt, StringRef &FmtStr) {
+  if (!getConstantStringInfo(Fmt, FmtStr) || FmtStr.empty())
 return;
 
   static const char ConvSpecifiers[] = "diouxXfFeEgGaAcspn";
@@ -189,17 +190,17 @@
   // Skip the first argument, the format string.
   unsigned ArgIdx = 1;
 
-  while ((SpecPos = Str.find_first_of('%', SpecPos)) != StringRef::npos) {
-if (Str[SpecPos + 1] == '%') {
+  while ((SpecPos = FmtStr.find_first_of('%', SpecPos)) != StringRef::npos) {
+if (FmtStr[SpecPos + 1] == '%') {
   SpecPos += 2;
   continue;
 }
-auto SpecEnd = Str.find_first_of(ConvSpecifiers, SpecPos);
+auto SpecEnd = FmtStr.find_first_of(ConvSpecifiers, SpecPos);
 if (SpecEnd == StringRef::npos)
   return;
-auto Spec = Str.slice(SpecPos, SpecEnd + 1);
+auto Spec = FmtStr.slice(SpecPos, SpecEnd + 1);
 ArgIdx += Spec.count('*');
-if (Str[SpecEnd] == 's') {
+if (FmtStr[SpecEnd] == 's') {
   BV.set(ArgIdx);
 }
 SpecPos = SpecEnd + 1;
@@ -207,14 +208,312 @@
   }
 }
 
+// helper struct to package the string related data
+typedef struct S {
+  std::string Str;
+  bool isConst;
+  Value *RealSize;
+  Value *AlignedSize;
+
+  S(std::string str = "", bool IC = true, Value *RS = nullptr,
+Value *AS = nullptr)
+  : Str(str), isConst(IC), RealSize(RS), AlignedSize(AS) {}
+} StringData;
+
+static size_t alignUp(size_t Value, uint alignment) {
+  return (Value + alignment - 1) & ~(alignment - 1);
+}
+
+// Calculates frame size required for current printf expansion and allocates
+// space on printf buffer. Printf frame includes following contents
+// [ ControlDWord , format string/Hash , Arguments (each aligned to 8 byte) ]
+static Value *callBufferedPrintfStart(IRBuilder<> &Builder,
+ ArrayRef &Args, Value *Fmt,
+ StringRef &FmtStr,
+ SparseBitVector<8> &SpecIsCString,
+ SmallVector &StringContents,
+ Value *&ArgSize) {
+  Value *NonConstStrLen = nullptr;
+
+  // First 8 bytes to be reserved for control dword
+  size_t BufSize = 4;
+  if (!FmtStr.empty())
+// First 8 bytes of MD5 hash
+BufSize += 8;
+  else {
+auto LenWithNull = getStrlenWithNull(Builder, Fmt);
+
+// Align the computed length to next 8 byte boundary
+auto TempAdd = Builder.CreateAdd(
+LenWithNull, ConstantInt::get(LenWithNull->getType(), 7U));
+NonConstStrLen = Builder.CreateAnd(
+TempAdd, ConstantInt::get(LenWithNull->getType(), ~7U));
+
+StringContents.

[clang] cf47e9f - [Serialization] Don't try to complete the redeclaration chain in

2023-05-11 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-05-12T14:28:58+08:00
New Revision: cf47e9fe86aa65b74b0476a5ad4d036dd7463bfb

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

LOG: [Serialization] Don't try to complete the redeclaration chain in
ASTReader after we start writing

This is intended to mitigate
https://github.com/llvm/llvm-project/issues/61447.

Before the patch, it takes 5s to compile test.cppm in the above
reproducer. After the patch it takes 3s to compile it. Although this
patch didn't solve the problem completely, it should mitigate the
problem for sure. Noted that the behavior of the patch is consistent
with the comment of the originally empty function
ASTReader::finalizeForWriting. So the change should be consistent with
the original design.

Added: 


Modified: 
clang/include/clang/Serialization/ASTReader.h
clang/lib/Serialization/ASTReader.cpp
clang/test/Modules/polluted-operator.cppm

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 1360ee1877c1..af01bacbfdc4 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -988,6 +988,9 @@ class ASTReader
   ///Whether we are currently processing update records.
   bool ProcessingUpdateRecords = false;
 
+  /// Whether we are going to write modules.
+  bool FinalizedForWriting = false;
+
   using SwitchCaseMapTy = llvm::DenseMap;
 
   /// Mapping from switch-case IDs in the chain to switch-case statements

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index bdf476cf128a..93409df3d4fc 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -5089,7 +5089,8 @@ void ASTReader::InitializeContext() {
 }
 
 void ASTReader::finalizeForWriting() {
-  // Nothing to do for now.
+  assert(!NumCurrentElementsDeserializing && "deserializing when reading");
+  FinalizedForWriting = true;
 }
 
 /// Reads and return the signature record from \p PCH's control block, or
@@ -7328,6 +7329,12 @@ Decl *ASTReader::GetExternalDecl(uint32_t ID) {
 }
 
 void ASTReader::CompleteRedeclChain(const Decl *D) {
+  // We don't need to complete declaration chain after we start writing.
+  // We loses more chances to find ODR violation in the writing place and
+  // we get more efficient writing process.
+  if (FinalizedForWriting)
+return;
+
   if (NumCurrentElementsDeserializing) {
 // We arrange to not care about the complete redeclaration chain while 
we're
 // deserializing. Just remember that the AST has marked this one as 
complete

diff  --git a/clang/test/Modules/polluted-operator.cppm 
b/clang/test/Modules/polluted-operator.cppm
index b24464aa6ad2..9b45734432db 100644
--- a/clang/test/Modules/polluted-operator.cppm
+++ b/clang/test/Modules/polluted-operator.cppm
@@ -51,7 +51,20 @@ module;
 export module b;
 import a;
 
+void b() {
+  std::variant v;
+}
+
 // expected-error@* {{has 
diff erent definitions in 
diff erent modules; first 
diff erence is defined here found data member '_S_copy_ctor' with an 
initializer}}
 // expected-note@* {{but in 'a.' found data member '_S_copy_ctor' with 
a 
diff erent initializer}}
 // expected-error@* {{from module 'a.' is not present in definition of 
'variant<_Types...>' provided earlier}}
 // expected-note@* {{declaration of 'swap' does not match}}
+
+//--- c.cppm
+module;
+#include "bar.h"
+export module c;
+import a;
+
+// expected-error@* {{has 
diff erent definitions in 
diff erent modules; first 
diff erence is defined here found data member '_S_copy_ctor' with an 
initializer}}
+// expected-note@* {{but in 'a.' found data member '_S_copy_ctor' with 
a 
diff erent initializer}}



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


[PATCH] D150364: [clang][Interp] Add 'Unsupported' opcode and use it for throw stmts

2023-05-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 521568.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D150364

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/records.cpp
  clang/test/AST/Interp/unsupported.cpp

Index: clang/test/AST/Interp/unsupported.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/unsupported.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -verify=ref %s
+
+namespace Throw {
+
+  constexpr int ConditionalThrow(bool t) {
+if (t)
+  throw 4; // expected-note {{subexpression not valid in a constant expression}} \
+   // ref-note {{subexpression not valid in a constant expression}}
+
+return 0;
+  }
+
+  static_assert(ConditionalThrow(false) == 0, "");
+  static_assert(ConditionalThrow(true) == 0, ""); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to 'ConditionalThrow(true)'}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to 'ConditionalThrow(true)'}}
+
+  constexpr int Throw() { // expected-error {{never produces a constant expression}} \
+  // ref-error {{never produces a constant expression}}
+throw 5; // expected-note {{subexpression not valid in a constant expression}} \
+ // ref-note {{subexpression not valid in a constant expression}}
+return 0;
+  }
+}
+
+namespace Asm {
+  constexpr int ConditionalAsm(bool t) {
+if (t)
+  asm(""); // expected-note {{subexpression not valid in a constant expression}} \
+   // ref-note {{subexpression not valid in a constant expression}}
+
+return 0;
+  }
+  static_assert(ConditionalAsm(false) == 0, "");
+  static_assert(ConditionalAsm(true) == 0, ""); // expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'ConditionalAsm(true)'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'ConditionalAsm(true)'}}
+
+
+  constexpr int Asm() { // expected-error {{never produces a constant expression}} \
+// ref-error {{never produces a constant expression}}
+__asm volatile(""); // expected-note {{subexpression not valid in a constant expression}} \
+// ref-note {{subexpression not valid in a constant expression}}
+return 0;
+  }
+}
Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -328,7 +328,8 @@
   struct S {
 constexpr S() {}
 constexpr ~S() noexcept(false) { throw 12; } // expected-error {{cannot use 'throw'}} \
- // expected-note {{declared here}} \
+ // expected-error {{never produces a constant expression}} \
+ // expected-note 2{{subexpression not valid}} \
  // ref-error {{cannot use 'throw'}} \
  // ref-error {{never produces a constant expression}} \
  // ref-note 2{{subexpression not valid}}
@@ -336,7 +337,9 @@
 
   constexpr int f() {
 S{}; // ref-note {{in call to '&S{}->~S()'}}
-return 12; // expected-note {{undefined function '~S'}}
+
+/// FIXME: Wrong source location below.
+return 12; // expected-note {{in call to '&S{}->~S()'}}
   }
   static_assert(f() == 12); // expected-error {{not an integral constant expression}} \
 // expected-note {{in call to 'f()'}} \
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -627,3 +627,6 @@
   let Types = [AllTypeClass];
   let HasGroup = 1;
 }
+
+// [] -> []
+def Invalid : Opcode {}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1823,6 +1823,14 @@
   return true;
 }
 
+/// Just emit a diagnostic. The expression that caused emission o

[PATCH] D150364: [clang][Interp] Add 'Unsupported' opcode and use it for throw stmts

2023-05-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D150364#4335282 , @aaron.ballman 
wrote:

> In D150364#4335261 , @tbaeder wrote:
>
>> In D150364#4335221 , 
>> @aaron.ballman wrote:
>>
>>> "Unsupported" is a bit of a loaded term -- it could mean "this operation is 
>>> not supported, YET" or it could mean "this operation is not and will not be 
>>> supported, EVER". Perhaps something more like "InvalidInConstantExpr" would 
>>> be more descriptive?
>>
>> I guess it would be more descriptive, but it could still mean that it is 
>> "not yet valid in a constant expression", so I guess I don't see the upside 
>> of using a longer opcode name.
>
> I don't feel strongly; it's easy enough to rename if we think it's causing 
> confusion. FWIW, my first thought was "Oh, we're planning to support throw 
> expressions in constant expressions? Please don't tell WG21." I'm used to 
> seeing "invalid" for things that are never valid and "unsupported" for things 
> that aren't supported but might be someday. However, I also see we use 
> "unsupported" in the same sense you're using it here in some of our 
> diagnostics, so I'm fine with whatever you want to go with.

I didn't know about that distinction, renaming to `invalid` is fine with me.


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

https://reviews.llvm.org/D150364

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


[PATCH] D136436: [Clang][LoongArch] Add GPR alias handling without `$` prefix

2023-05-11 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

LGTM now, thanks for updating this patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136436

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


[PATCH] D147266: [AArch64] Sink operands to allow for bitselect instructions

2023-05-11 Thread Pranav Kant via Phabricator via cfe-commits
pranavk updated this revision to Diff 521545.
pranavk added a comment.

More concise pattern matching


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll


Index: llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
===
--- llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
+++ llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
@@ -144,3 +144,30 @@
   %or = or <16 x i8> %and, %and1
   ret <16 x i8> %or
 }
+
+define <4 x i32> @test_bit_sink_operand(<4 x i32> %src, <4 x i32> %dst, <4 x 
i32> %mask, i32 %scratch) {
+; CHECK-LABEL: test_bit_sink_operand
+; CHECK: // %do.body
+; CHECK: bit v1.16b, v0.16b, v2.16b
+
+entry:
+  %0 = xor <4 x i32> %mask, 
+  %div = sdiv i32 %scratch, 2
+  br label %do.body
+
+do.body: 
+  %dst.addr.0 = phi <4 x i32> [ %dst, %entry ], [ %vecins, %do.body ]
+  %src.addr.0 = phi <4 x i32> [ %src, %entry ], [ %vecins1, %do.body ]
+  %i.0 = phi i32 [ 0, %entry ], [ %inc, %do.body ]
+  %vbsl3.i = and <4 x i32> %src.addr.0, %mask
+  %vbsl4.i = and <4 x i32> %dst.addr.0, %0
+  %vbsl5.i = or <4 x i32> %vbsl3.i, %vbsl4.i
+  %vecins = insertelement <4 x i32> %vbsl5.i, i32 %scratch, i32 %i.0
+  %vecins1 = insertelement <4 x i32> %src.addr.0, i32 %div, i32 %i.0
+  %inc = add nuw nsw i32 %i.0, 1
+  %exitcond.not = icmp eq i32 %inc, 5
+  br i1 %exitcond.not, label %do.end, label %do.body
+
+do.end:
+  ret <4 x i32> %vecins
+}
\ No newline at end of file
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -14332,6 +14332,47 @@
 
 return true;
   }
+  case Instruction::Or: {
+// Pattern: Or(And(MaskValue, A), And(Not(MaskValue), B)) ->
+// bitselect(MaskValue, A, B) where Not(MaskValue) = Xor(MaskValue, -1)
+if (Subtarget->hasNEON()) {
+  Instruction *OtherAnd, *IA, *IB;
+  Value *MaskValue;
+  // MainAnd refers to And instruction that has 'Not' as one of its 
operands
+  if (match(I, m_c_Or(m_OneUse(m_Instruction(OtherAnd)),
+  m_OneUse(m_c_And(m_OneUse(m_Not(m_Value(MaskValue))),
+   m_Instruction(IA)) {
+if (match(OtherAnd,
+  m_c_And(m_Specific(MaskValue), m_Instruction(IB {
+  Instruction *MainAnd = I->getOperand(0) == OtherAnd
+ ? cast(I->getOperand(1))
+ : cast(I->getOperand(0));
+
+  // Both Ands should be in same basic block as Or
+  if (I->getParent() != MainAnd->getParent() ||
+  I->getParent() != OtherAnd->getParent())
+return false;
+
+  // Non-mask operands of both Ands should also be in same basic block
+  if (I->getParent() != IA->getParent() ||
+  I->getParent() != IB->getParent())
+return false;
+
+  for (unsigned Idx = 0; Idx < MainAnd->getNumOperands(); Idx++) {
+if (MainAnd->getOperand(Idx) != IA) {
+  Ops.push_back(&MainAnd->getOperandUse(Idx));
+  Ops.push_back(&I->getOperandUse(0));
+  Ops.push_back(&I->getOperandUse(1));
+
+  return true;
+}
+  }
+}
+  }
+}
+
+return false;
+  }
   case Instruction::Mul: {
 int NumZExts = 0, NumSExts = 0;
 for (auto &Op : I->operands()) {


Index: llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
===
--- llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
+++ llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
@@ -144,3 +144,30 @@
   %or = or <16 x i8> %and, %and1
   ret <16 x i8> %or
 }
+
+define <4 x i32> @test_bit_sink_operand(<4 x i32> %src, <4 x i32> %dst, <4 x i32> %mask, i32 %scratch) {
+; CHECK-LABEL: test_bit_sink_operand
+; CHECK: // %do.body
+; CHECK: bit v1.16b, v0.16b, v2.16b
+
+entry:
+  %0 = xor <4 x i32> %mask, 
+  %div = sdiv i32 %scratch, 2
+  br label %do.body
+
+do.body: 
+  %dst.addr.0 = phi <4 x i32> [ %dst, %entry ], [ %vecins, %do.body ]
+  %src.addr.0 = phi <4 x i32> [ %src, %entry ], [ %vecins1, %do.body ]
+  %i.0 = phi i32 [ 0, %entry ], [ %inc, %do.body ]
+  %vbsl3.i = and <4 x i32> %src.addr.0, %mask
+  %vbsl4.i = and <4 x i32> %dst.addr.0, %0
+  %vbsl5.i = or <4 x i32> %vbsl3.i, %vbsl4.i
+  %vecins = insertelement <4 x i32> %vbsl5.i, i32 %scratch, i32 %i.0
+  %vecins1 = insertelement <4 x i32> %src.addr.0, i32 %div, i32 %i.0
+  %inc = add nuw nsw i32 %i.0, 1
+  %exitcond.not = icmp eq i32 %inc, 5
+  br i1 %exitcond.not, label %do.end, label %do.body
+
+do.end:
+  ret <4 x i32> %vecins

[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-11 Thread Brittany Blue Gaston via Phabricator via cfe-commits
thetruestblue added inline comments.



Comment at: compiler-rt/test/asan_abi/lit.cfg.py:83
+# Only run the tests on supported OSs.
+if config.host_os not in ['Darwin']:
+  config.unsupported = True

MaskRay wrote:
> `!=`
The thought here was to leave basic lit patterns in-tact to expand to other OSs 
if others want to in the future. But if there's no desire for that, it doesn't 
make a big difference to me. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-05-11 Thread Sam James via Phabricator via cfe-commits
thesamesam added a comment.

Adding to the concerns raised above, I don't think we're there yet. See 
https://bugs.gentoo.org/buglist.cgi?quicksearch=enum-constexpr-conversion&list_id=6843355
 and keep in mind that a bunch of stuff isn't buildable with Clang 16 yet 
anyway so I expect a bunch more to be broken on top of that.

Also, e.g. gdb isn't fixed in a release yet.


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

https://reviews.llvm.org/D150226

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


[PATCH] D136436: [Clang][LoongArch] Add register alias handling without `$` prefix

2023-05-11 Thread Lu Weining via Phabricator via cfe-commits
SixWeining updated this revision to Diff 521541.
SixWeining added a comment.

Only allow non-prefixed names for GPRs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136436

Files:
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
  clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c

Index: clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c
===
--- clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c
+++ clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c
@@ -7,56 +7,72 @@
 // CHECK: call void asm sideeffect "", "{$r0}"(i32 undef)
 void test_r0() {
 register int a asm ("$r0");
+register int b asm ("r0");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_r12
 // CHECK: call void asm sideeffect "", "{$r12}"(i32 undef)
 void test_r12() {
 register int a asm ("$r12");
+register int b asm ("r12");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_r31
 // CHECK: call void asm sideeffect "", "{$r31}"(i32 undef)
 void test_r31() {
 register int a asm ("$r31");
+register int b asm ("r31");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_zero
 // CHECK: call void asm sideeffect "", "{$r0}"(i32 undef)
 void test_zero() {
 register int a asm ("$zero");
+register int b asm ("zero");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_a0
 // CHECK: call void asm sideeffect "", "{$r4}"(i32 undef)
 void test_a0() {
 register int a asm ("$a0");
+register int b asm ("a0");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_t1
 // CHECK: call void asm sideeffect "", "{$r13}"(i32 undef)
 void test_t1() {
 register int a asm ("$t1");
+register int b asm ("t1");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_fp
 // CHECK: call void asm sideeffect "", "{$r22}"(i32 undef)
 void test_fp() {
 register int a asm ("$fp");
+register int b asm ("fp");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_s2
 // CHECK: call void asm sideeffect "", "{$r25}"(i32 undef)
 void test_s2() {
 register int a asm ("$s2");
+register int b asm ("s2");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_f0
Index: clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
===
--- clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
+++ clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
@@ -11,10 +11,6 @@
 
 /// Names not prefixed with '$' are invalid.
 
-// CHECK: :[[#@LINE+1]]:24: error: unknown register name 'r4' in asm
-  register int a3 asm ("r4");
-// CHECK: :[[#@LINE+1]]:24: error: unknown register name 'a0' in asm
-  register int a4 asm ("a0");
 // CHECK: :[[#@LINE+1]]:26: error: unknown register name 'f0' in asm
   register float a5 asm ("f0");
 // CHECK: :[[#@LINE+1]]:26: error: unknown register name 'fa0' in asm
Index: clang/lib/Basic/Targets/LoongArch.cpp
===
--- clang/lib/Basic/Targets/LoongArch.cpp
+++ clang/lib/Basic/Targets/LoongArch.cpp
@@ -40,27 +40,70 @@
 ArrayRef
 LoongArchTargetInfo::getGCCRegAliases() const {
   static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
-  {{"$zero"}, "$r0"},   {{"$ra"}, "$r1"},{{"$tp"}, "$r2"},
-  {{"$sp"}, "$r3"}, {{"$a0"}, "$r4"},{{"$a1"}, "$r5"},
-  {{"$a2"}, "$r6"}, {{"$a3"}, "$r7"},{{"$a4"}, "$r8"},
-  {{"$a5"}, "$r9"}, {{"$a6"}, "$r10"},   {{"$a7"}, "$r11"},
-  {{"$t0"}, "$r12"},{{"$t1"}, "$r13"},   {{"$t2"}, "$r14"},
-  {{"$t3"}, "$r15"},{{"$t4"}, "$r16"},   {{"$t5"}, "$r17"},
-  {{"$t6"}, "$r18"},{{"$t7"}, "$r19"},   {{"$t8"}, "$r20"},
-  {{"$fp", "$s9"}, "$r22"}, {{"$s0"}, "$r23"},   {{"$s1"}, "$r24"},
-  {{"$s2"}, "$r25"},{{"$s3"}, "$r26"},   {{"$s4"}, "$r27"},
-  {{"$s5"}, "$r28"},{{"$s6"}, "$r29"},   {{"$s7"}, "$r30"},
-  {{"$s8"}, "$r31"},{{"$fa0"}, "$f0"},   {{"$fa1"}, "$f1"},
-  {{"$fa2"}, "$f2"},{{"$fa3"}, "$f3"},   {{"$fa4"}, "$f4"},
-  {{"$fa5"}, "$f5"},{{"$fa6"}, "$f6"},   {{"$fa7"}, "$f7"},
-  {{"$ft0"}, "$f8"},{{"$ft1"}, "$f9"},   {{"$ft2"}, "$f10"},
-  {{"$ft3"}, "$f11"},   {{"$ft4"}, "$f12"},  {{"$ft5"}, "$f13"},
-  {{"$ft6"}, "$f14"},   {{"$ft7"}, "$f15"},  {{"$ft8"}, "$f16"},
-  {{"$ft9"}, "$f17"},   {{"$ft10"}, "$f18"}, {{"$ft11"}, "$f19"},
-  {{"$ft12"}, "$f20"},  {{"$ft13"}, "$f21"}, {{"$ft14"}, "$f22"},
-  {{"$ft15"}, "$f23"},  {{"$fs0"}, "$f24"},  {{"$fs1"}, "$f25"},
-  {{"$fs2"}, "$f26"},   {{"$fs3"}, "$f27"},  {{"$fs4"}, "$f28"},
-  

[PATCH] D146188: [Clang][DOC] Add documentation in for __builtin_flt_rounds and __builtin_set_flt_rounds

2023-05-11 Thread xiongji90 via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
xiongji90 marked an inline comment as done.
Closed by commit rG2ed77846a916: This patch adds doc for __builtin_flt_rounds 
and __builtin_set_flt_rounds (authored by xiongji90).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146188

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/UsersManual.rst


Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -1787,6 +1787,48 @@
* ``16`` - Forces ``_Float16`` operations to be emitted without using excess
  precision arithmetic.
 
+.. _floating-point-environment:
+
+Accessing the floating point environment
+
+Many targets allow floating point operations to be configured to control things
+such as how inexact results should be rounded and how exceptional conditions
+should be handled. This configuration is called the floating point environment.
+C and C++ restrict access to the floating point environment by default, and the
+compiler is allowed to assume that all operations are performed in the default
+environment. When code is compiled in this default mode, operations that depend
+on the environment (such as floating-point arithmetic and `FLT_ROUNDS`) may 
have
+undefined behavior if the dynamic environment is not the default environment; 
for
+example, `FLT_ROUNDS` may or may not simply return its default value for the 
target
+instead of reading the dynamic environment, and floating-point operations may 
be
+optimized as if the dynamic environment were the default.  Similarly, it is 
undefined
+behavior to change the floating point environment in this default mode, for 
example
+by calling the `fesetround` function.
+C provides two pragmas to allow code to dynamically modify the floating point 
environment:
+
+- ``#pragma STDC FENV_ACCESS ON`` allows dynamic changes to the entire floating
+  point environment.
+
+- ``#pragma STDC FENV_ROUND FE_DYNAMIC`` allows dynamic changes to just the 
floating
+  point rounding mode.  This may be more optimizable than ``FENV_ACCESS ON`` 
because
+  the compiler can still ignore the possibility of floating-point exceptions 
by default.
+
+Both of these can be used either at the start of a block scope, in which case
+they cover all code in that scope (unless they're turned off in a child scope),
+or at the top level in a file, in which case they cover all subsequent function
+bodies until they're turned off.  Note that it is undefined behavior to enter
+code that is *not* covered by one of these pragmas from code that *is* covered
+by one of these pragmas unless the floating point environment has been restored
+to its default state.  See the C standard for more information about these 
pragmas.
+
+The command line option ``-frounding-math`` behaves as if the translation unit
+began with ``#pragma STDC FENV_ROUND FE_DYNAMIC``. The command line option
+``-ffp-model=strict`` behaves as if the translation unit began with ``#pragma 
STDC FENV_ACCESS ON``.
+
+Code that just wants to use a specific rounding mode for specific floating 
point
+operations can avoid most of the hazards of the dynamic floating point 
environment
+by using ``#pragma STDC FENV_ROUND`` with a value other than ``FE_DYNAMIC``.
+
 .. _crtfastmath.o:
 
 A note about ``crtfastmath.o``
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -3324,7 +3324,7 @@
 
double __builtin_canonicalize(double);
float __builtin_canonicalizef(float);
-   long double__builtin_canonicalizel(long double);
+   long double __builtin_canonicalizel(long double);
 
 Returns the platform specific canonical encoding of a floating point
 number. This canonicalization is useful for implementing certain
@@ -3332,6 +3332,28 @@
 `_ for
 more information on the semantics.
 
+``__builtin_flt_rounds`` and ``__builtin_set_flt_rounds``
+-
+
+.. code-block:: c
+
+   int __builtin_flt_rounds();
+   void __builtin_set_flt_rounds(int);
+
+Returns and sets current floating point rounding mode. The encoding of returned
+values and input parameters is same as the result of FLT_ROUNDS, specified by C
+standard:
+- ``0``  - toward zero
+- ``1``  - to nearest, ties to even
+- ``2``  - toward positive infinity
+- ``3``  - toward negative infinity
+- ``4``  - to nearest, ties away from zero
+The effect of passing some other value to ``__builtin_flt_rounds`` is
+implementation-defined. ``__builtin_set_flt_rounds`` is currently only 
supported
+to work on x86, x86_64, Arm and AArch64 targets. These builtins read and modify
+the floatin

[clang] 2ed7784 - This patch adds doc for __builtin_flt_rounds and __builtin_set_flt_rounds

2023-05-11 Thread via cfe-commits

Author: jinge90
Date: 2023-05-12T11:12:36+08:00
New Revision: 2ed77846a9161106a26d1efa9b68a3122856b434

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

LOG: This patch adds doc for __builtin_flt_rounds and __builtin_set_flt_rounds
and also adds description for default fp environment.

Reviewed By:rjmccall, sepavloff
Differential Revision: https://reviews.llvm.org/D146188

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 64ed3ae6ab90..f50f2f287735 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3324,7 +3324,7 @@ Floating point builtins
 
double __builtin_canonicalize(double);
float __builtin_canonicalizef(float);
-   long double__builtin_canonicalizel(long double);
+   long double __builtin_canonicalizel(long double);
 
 Returns the platform specific canonical encoding of a floating point
 number. This canonicalization is useful for implementing certain
@@ -3332,6 +3332,28 @@ numeric primitives such as frexp. See `LLVM canonicalize 
intrinsic
 `_ for
 more information on the semantics.
 
+``__builtin_flt_rounds`` and ``__builtin_set_flt_rounds``
+-
+
+.. code-block:: c
+
+   int __builtin_flt_rounds();
+   void __builtin_set_flt_rounds(int);
+
+Returns and sets current floating point rounding mode. The encoding of returned
+values and input parameters is same as the result of FLT_ROUNDS, specified by C
+standard:
+- ``0``  - toward zero
+- ``1``  - to nearest, ties to even
+- ``2``  - toward positive infinity
+- ``3``  - toward negative infinity
+- ``4``  - to nearest, ties away from zero
+The effect of passing some other value to ``__builtin_flt_rounds`` is
+implementation-defined. ``__builtin_set_flt_rounds`` is currently only 
supported
+to work on x86, x86_64, Arm and AArch64 targets. These builtins read and modify
+the floating-point environment, which is not always allowed and may have 
unexpected
+behavior. Please see the section on `Accessing the floating point environment 
`_
 for more information.
+
 String builtins
 ---
 

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 193ba4786a48..5de8e6c70dca 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1787,6 +1787,48 @@ floating point semantic models: precise (the default), 
strict, and fast.
* ``16`` - Forces ``_Float16`` operations to be emitted without using excess
  precision arithmetic.
 
+.. _floating-point-environment:
+
+Accessing the floating point environment
+
+Many targets allow floating point operations to be configured to control things
+such as how inexact results should be rounded and how exceptional conditions
+should be handled. This configuration is called the floating point environment.
+C and C++ restrict access to the floating point environment by default, and the
+compiler is allowed to assume that all operations are performed in the default
+environment. When code is compiled in this default mode, operations that depend
+on the environment (such as floating-point arithmetic and `FLT_ROUNDS`) may 
have
+undefined behavior if the dynamic environment is not the default environment; 
for
+example, `FLT_ROUNDS` may or may not simply return its default value for the 
target
+instead of reading the dynamic environment, and floating-point operations may 
be
+optimized as if the dynamic environment were the default.  Similarly, it is 
undefined
+behavior to change the floating point environment in this default mode, for 
example
+by calling the `fesetround` function.
+C provides two pragmas to allow code to dynamically modify the floating point 
environment:
+
+- ``#pragma STDC FENV_ACCESS ON`` allows dynamic changes to the entire floating
+  point environment.
+
+- ``#pragma STDC FENV_ROUND FE_DYNAMIC`` allows dynamic changes to just the 
floating
+  point rounding mode.  This may be more optimizable than ``FENV_ACCESS ON`` 
because
+  the compiler can still ignore the possibility of floating-point exceptions 
by default.
+
+Both of these can be used either at the start of a block scope, in which case
+they cover all code in that scope (unless they're turned off in a child scope),
+or at the top level in a file, in which case they cover all subsequent function
+bodies until they're turned off.  Note that it is undefined behavior to enter
+code that is *not* covered by one of these pragmas from code th

[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-05-11 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

We also use Wno-enum-constexpr-conversion in ChromeOS. There are many packages 
that break with this warning. One of them is boost which is used in many other 
packages.

The errors in boost were:

  ./boost/mpl/aux_/integral_wrapper.hpp:73:31: error: integer value -1 is 
outside the valid range of values [0, 3] for this enumeration type 
[-Wenum-constexpr-conversion]
  ./boost/mpl/aux_/static_cast.hpp:24:47: note: expanded from macro 
'BOOST_MPL_AUX_STATIC_CAST'
  #   define BOOST_MPL_AUX_STATIC_CAST(T, expr) static_cast(expr)
^

I do not think boost upstream has updated these files, I see they were last 
updated 3 years back.
https://github.com/boostorg/mpl/blob/master/include/boost/mpl/aux_/static_cast.hpp
and 
https://github.com/boostorg/mpl/blob/master/include/boost/mpl/aux_/integral_wrapper.hpp


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

https://reviews.llvm.org/D150226

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


[PATCH] D150411: [NFC][Clang][Coverity] Fix Static Code Analysis Concerns with copy without assign

2023-05-11 Thread Soumi Manna via Phabricator via cfe-commits
Manna added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:1789-1791
+SemaDiagnosticBuilder &operator=(SemaDiagnosticBuilder &&D) = delete;
 SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default;
+SemaDiagnosticBuilder &operator=(const SemaDiagnosticBuilder &) = delete;

@tahonermann This is follow-up comments from 
https://reviews.llvm.org/D149718?id=519331#inline-1452044. 

>>This change still declares a move assignment operator, but doesn't provide a 
>>definition. The move constructor is implemented in clang/lib/Sema/Sema.cpp, 
>>so I would expect to see the move assignment operator definition provided 
>>there as well.

I tried to define move assignment operator in ` clang/lib/Sema/Sema.cpp` but it 
failed because class Sema has deleted implicit copy assignment operator.

```
/// Sema - This implements semantic analysis and AST building for C.
class Sema final {
  Sema(const Sema &) = delete;
  void operator=(const Sema &) = delete;
```
It seems like support for assignment is not desired, We probably need deleted 
copy/move assignment operator.



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

https://reviews.llvm.org/D150411

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


[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-05-11 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht added a comment.

We're still using `-Wno-enum-constexpr-conversion`, although I'm not sure if we 
need that or if we just forgot to remove it after doing some cleanup. I'm 
trying it out now. (Sorry, I'm not sure we were aware that having a way to turn 
this off was just temporary).

BTW, LLVM itself still uses this flag in openmp: 
https://github.com/llvm/llvm-project/blob/c2ce2a509f74a85a3c0ef4b9d6d79fbacc7e8bdf/openmp/cmake/HandleOpenMPOptions.cmake#L34


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

https://reviews.llvm.org/D150226

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


[PATCH] D150411: [NFC][Clang] Fix Static Code Analysis Concerns

2023-05-11 Thread Soumi Manna via Phabricator via cfe-commits
Manna updated this revision to Diff 521529.

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

https://reviews.llvm.org/D150411

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Analysis/Analyses/Consumed.h
  clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
  clang/include/clang/Analysis/Analyses/ThreadSafetyUtil.h
  clang/include/clang/Analysis/Support/BumpVector.h
  clang/include/clang/Rewrite/Core/RewriteRope.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/EHScopeStack.h
  clang/lib/Sema/SemaAccess.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -654,6 +654,9 @@
   O.Root = nullptr;
 }
 
+DiagText(const DiagText &) = delete;
+DiagText &operator=(const DiagText &) = delete;
+
 ~DiagText() {
   for (Piece *P : AllocatedPieces)
 delete P;
Index: clang/lib/Sema/SemaAccess.cpp
===
--- clang/lib/Sema/SemaAccess.cpp
+++ clang/lib/Sema/SemaAccess.cpp
@@ -199,6 +199,13 @@
 : Target(S.Target), Has(S.Has) {
   S.Target = nullptr;
 }
+
+SavedInstanceContext &operator=(SavedInstanceContext &&S) {
+  Target = S.Target;
+  Has = S.Has;
+  return *this;
+}
+
 ~SavedInstanceContext() {
   if (Target)
 Target->HasInstanceContext = Has;
Index: clang/lib/CodeGen/EHScopeStack.h
===
--- clang/lib/CodeGen/EHScopeStack.h
+++ clang/lib/CodeGen/EHScopeStack.h
@@ -147,7 +147,9 @@
 
   public:
 Cleanup(const Cleanup &) = default;
+Cleanup &operator=(const Cleanup &) = delete;
 Cleanup(Cleanup &&) {}
+Cleanup &operator=(Cleanup &&) = delete;
 Cleanup() = default;
 
 virtual bool isRedundantBeforeReturn() { return false; }
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -829,7 +829,12 @@
   ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
 Other.CGF = nullptr;
   }
-  ApplyDebugLocation &operator=(ApplyDebugLocation &&) = default;
+
+  ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
+CGF = Other.CGF;
+Other.CGF = nullptr;
+return *this;
+  }
 
   ~ApplyDebugLocation();
 
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -670,7 +670,9 @@
 public:
   SymbolVisitor() = default;
   SymbolVisitor(const SymbolVisitor &) = default;
+  SymbolVisitor &operator=(const SymbolVisitor &) = delete;
   SymbolVisitor(SymbolVisitor &&) {}
+  SymbolVisitor &operator=(SymbolVisitor &&) = delete;
 
   /// A visitor method invoked by ProgramStateManager::scanReachableSymbols.
   ///
Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
===
--- clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
+++ clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
@@ -50,7 +50,9 @@
 public:
   BugReporterVisitor() = default;
   BugReporterVisitor(const BugReporterVisitor &) = default;
+  BugReporterVisitor &operator=(const BugReporterVisitor &) = delete;
   BugReporterVisitor(BugReporterVisitor &&) {}
+  BugReporterVisitor &operator=(BugReporterVisitor &&) = delete;
   virtual ~BugReporterVisitor();
 
   /// Return a diagnostic piece which should be associated with the
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1786,7 +1786,9 @@
 SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID,
   const FunctionDecl *Fn, Sema &S);
 SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D);
+SemaDiagnosticBuilder &operator=(SemaDiagnosticBuilder &&D) = delete;
 SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default;
+SemaDiagnosticBuilder &operator=(const SemaDiagnosticBuilder &) = delete;
 ~SemaDiagnosticBuilder();
 
 bool isImmediate() const { return ImmediateDiag.has_value(); }
Index: clang/include/clang/Sema/Lookup.h
===
--- clang/in

[PATCH] D149162: [Clang][OpenMP][IRBuilder] Move registerTargetGlobalVariable & getAddrOfDeclareTargetVar into the OMPIRBuilder

2023-05-11 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

In the last commit I believe I addressed the last review comments and I added 
an OMPIRBuilderTest testing some of the functionality of the 
registerTargetGlobalVariable and getAddrOfDeclareTargetVar functionality! Just 
to maintain the standard of making tests for things added to the OMPIRBuilder 
(the functions are also tested rather profusely by Clang and LLVM already).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149162

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


[PATCH] D136436: [Clang][LoongArch] Add register alias handling without `$` prefix

2023-05-11 Thread Youling Tang via Phabricator via cfe-commits
tangyouling added a comment.

The patch will continue to be updated by @SixWeining .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136436

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


[PATCH] D149162: [Clang][OpenMP][IRBuilder] Move registerTargetGlobalVariable & getAddrOfDeclareTargetVar into the OMPIRBuilder

2023-05-11 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 521528.
agozillon added a comment.

- [Clang][OpenMP][IRBuilder] Tidy up function calls with helpful reviewer advice
- [Clang][OpenMP][IRBuilder] Replace all getTargetEntryUniqueInfo with 
IRBuilder version
- [Clang][OpenMP][IRBuilder] Run clang-format and tidy up files
- Run clang-format on offending file breaking build process
- Address reviewers comments
- Add a new OpenMPIRBuilder that utilises registerTargetGlobalVariable (and by 
extension getAddrOfDeclareTargetVar) to generate host declare target data


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149162

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -5766,4 +5766,84 @@
   GlobalValue::WeakAnyLinkage);
   EXPECT_TRUE(InfoManager.hasDeviceGlobalVarEntryInfo("gvar"));
 }
+
+// Tests both registerTargetGlobalVariable and getAddrOfDeclareTargetVar as they
+// call each other (recursively in some cases). The test case test these
+// functions by utilising them for host code generation for declare target
+// global variables
+TEST_F(OpenMPIRBuilderTest, registerTargetGlobalVariable) {
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize();
+  OpenMPIRBuilderConfig Config(false, false, false, false);
+  OMPBuilder.setConfig(Config);
+
+  std::vector TargetTriple;
+  TargetTriple.emplace_back("amdgcn-amd-amdhsa");
+
+  TargetRegionEntryInfo EntryInfo("", 42, 4711, 17);
+  std::vector RefsGathered;
+
+  std::vector Globals;
+  auto *IntTy = Type::getInt32Ty(Ctx);
+  for (int I = 0; I < 2; ++I) {
+Globals.push_back(M->getOrInsertGlobal(
+"test_data_int_" + std::to_string(I), IntTy, [&]() -> GlobalVariable * {
+  return new GlobalVariable(
+  *M, IntTy, false, GlobalValue::LinkageTypes::WeakAnyLinkage,
+  ConstantInt::get(IntTy, I), "test_data_int_" + std::to_string(I));
+}));
+  }
+
+  OMPBuilder.registerTargetGlobalVariable(
+  OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo,
+  OffloadEntriesInfoManager::OMPTargetDeviceClauseAny, false, true,
+  EntryInfo, Globals[0]->getName(), RefsGathered, false, TargetTriple,
+  nullptr, nullptr, Globals[0]->getType(), Globals[0]);
+
+  OMPBuilder.registerTargetGlobalVariable(
+  OffloadEntriesInfoManager::OMPTargetGlobalVarEntryLink,
+  OffloadEntriesInfoManager::OMPTargetDeviceClauseAny, false, true,
+  EntryInfo, Globals[1]->getName(), RefsGathered, false, TargetTriple,
+  nullptr, nullptr, Globals[1]->getType(), Globals[1]);
+
+  llvm::OpenMPIRBuilder::EmitMetadataErrorReportFunctionTy &&ErrorReportfn =
+  [](llvm::OpenMPIRBuilder::EmitMetadataErrorKind Kind,
+ const llvm::TargetRegionEntryInfo &EntryInfo) -> void {
+// If this is invoked, then we want to emit an error, even if it is not
+// neccesarily the most readable, as something has went wrong. The
+// test-suite unfortunately eats up all error output
+ASSERT_EQ(Kind, Kind);
+  };
+
+  OMPBuilder.createOffloadEntriesAndInfoMetadata(ErrorReportfn);
+
+  // Clauses for data_int_0 with To + Any clauses for the host
+  std::vector OffloadEntries;
+  OffloadEntries.push_back(M->getNamedGlobal(".omp_offloading.entry_name"));
+  OffloadEntries.push_back(
+  M->getNamedGlobal(".omp_offloading.entry.test_data_int_0"));
+
+  // Clauses for data_int_1 with Link + Any clauses for the host
+  OffloadEntries.push_back(
+  M->getNamedGlobal("test_data_int_1_decl_tgt_ref_ptr"));
+  OffloadEntries.push_back(M->getNamedGlobal(".omp_offloading.entry_name.1"));
+  OffloadEntries.push_back(M->getNamedGlobal(
+  ".omp_offloading.entry.test_data_int_1_decl_tgt_ref_ptr"));
+
+  for (unsigned I = 0; I < OffloadEntries.size(); ++I)
+EXPECT_NE(OffloadEntries[I], nullptr);
+
+  // Metadata generated for the host offload module
+  NamedMDNode *OffloadMetadata = M->getNamedMetadata("omp_offload.info");
+  EXPECT_NE(OffloadMetadata, nullptr);
+  if (OffloadMetadata) {
+EXPECT_EQ(OffloadMetadata->getOperand(0)->getOperand(1).equalsStr(
+  "test_data_int_0"),
+  true);
+EXPECT_EQ(OffloadMetadata->getOperand(1)->getOperand(1).equalsStr(
+  "test_data_int_1_decl_tgt_ref_ptr"),
+  true);
+  }
+}
+
 } // namespace
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -32,6 +32,7 @@
 #include "llvm/IR/Value.h"
 #include "llvm/MC/TargetRegistry.

[PATCH] D148654: Modify BoundsSan to improve debuggability

2023-05-11 Thread Oskar Wirga via Phabricator via cfe-commits
oskarwirga updated this revision to Diff 521525.
oskarwirga added a comment.

clang-format 😺


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148654

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/bounds-checking.c
  llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp

Index: llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
===
--- llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
+++ llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
@@ -39,6 +39,10 @@
 static cl::opt SingleTrapBB("bounds-checking-single-trap",
   cl::desc("Use one trap block per function"));
 
+static cl::opt
+DebugTrapBB("bounds-checking-debug-trap",
+cl::desc("Use one trap block per check despite optimizations"));
+
 STATISTIC(ChecksAdded, "Bounds checks added");
 STATISTIC(ChecksSkipped, "Bounds checks skipped");
 STATISTIC(ChecksUnable, "Bounds checks unable to add");
@@ -182,24 +186,39 @@
   // will create a fresh block every time it is called.
   BasicBlock *TrapBB = nullptr;
   auto GetTrapBB = [&TrapBB](BuilderTy &IRB) {
-if (TrapBB && SingleTrapBB)
-  return TrapBB;
-
-Function *Fn = IRB.GetInsertBlock()->getParent();
-// FIXME: This debug location doesn't make a lot of sense in the
-// `SingleTrapBB` case.
-auto DebugLoc = IRB.getCurrentDebugLocation();
-IRBuilder<>::InsertPointGuard Guard(IRB);
-TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
-IRB.SetInsertPoint(TrapBB);
-
-auto *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap);
-CallInst *TrapCall = IRB.CreateCall(F, {});
-TrapCall->setDoesNotReturn();
-TrapCall->setDoesNotThrow();
-TrapCall->setDebugLoc(DebugLoc);
-IRB.CreateUnreachable();
-
+if (DebugTrapBB) {
+  Function *Fn = IRB.GetInsertBlock()->getParent();
+  auto DebugLoc = IRB.getCurrentDebugLocation();
+  IRBuilder<>::InsertPointGuard Guard(IRB);
+  TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
+  IRB.SetInsertPoint(TrapBB);
+  auto *F =
+  Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::ubsantrap);
+  CallInst *TrapCall =
+  IRB.CreateCall(F, ConstantInt::get(IRB.getInt8Ty(), Fn->size()));
+  TrapCall->setDoesNotReturn();
+  TrapCall->setDoesNotThrow();
+  TrapCall->setDebugLoc(DebugLoc);
+  IRB.CreateUnreachable();
+} else {
+  if (TrapBB && SingleTrapBB)
+return TrapBB;
+
+  Function *Fn = IRB.GetInsertBlock()->getParent();
+  // FIXME: This debug location doesn't make a lot of sense in the
+  // `SingleTrapBB` case.
+  auto DebugLoc = IRB.getCurrentDebugLocation();
+  IRBuilder<>::InsertPointGuard Guard(IRB);
+  TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
+  IRB.SetInsertPoint(TrapBB);
+
+  auto *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap);
+  CallInst *TrapCall = IRB.CreateCall(F, {});
+  TrapCall->setDoesNotReturn();
+  TrapCall->setDoesNotThrow();
+  TrapCall->setDebugLoc(DebugLoc);
+  IRB.CreateUnreachable();
+}
 return TrapBB;
   };
 
Index: clang/test/CodeGen/bounds-checking.c
===
--- clang/test/CodeGen/bounds-checking.c
+++ clang/test/CodeGen/bounds-checking.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fsanitize=local-bounds -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fsanitize=array-bounds -O -fsanitize-trap=array-bounds -emit-llvm -triple x86_64-apple-darwin10 -DNO_DYNAMIC %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=local-bounds -fsanitize-trap=local-bounds -O3 -mllvm -bounds-checking-debug-trap -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s --check-prefixes=NOOPTLOCAL
+// RUN: %clang_cc1 -fsanitize=array-bounds -fsanitize-trap=array-bounds -O3 -mllvm -sanitizer-de-opt-traps -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s --check-prefixes=NOOPTARRAY
 //
 // REQUIRES: x86-registered-target
 
@@ -66,3 +68,16 @@
   // CHECK-NOT: @llvm.ubsantrap
   return u->c[i];
 }
+
+char B[10];
+char B2[10];
+// CHECK-LABEL: @f8
+void f8(int i, int k) {
+  // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3)
+  // NOOPTARRAY: call void @llvm.ubsantrap(i8 2)
+  B[i] = '\0';
+
+  // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5)
+  // NOOPTARRAY: call void @llvm.ubsantrap(i8 4)
+  B2[k] = '\0';
+}
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -48,6 +48,11 @@
 using namespace clang;
 using namespace CodeGen;
 
+// Experiment to make sanitizers easier to debug
+static llvm::cl::opt ClSanitizeDebugDeoptimization(
+"sanitizer-de-opt-traps", llvm::cl::Optional,
+   

[PATCH] D150411: [NFC][Clang] Fix Static Code Analysis Concerns

2023-05-11 Thread Soumi Manna via Phabricator via cfe-commits
Manna abandoned this revision.
Manna added a comment.

Wrong patch. Closing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150411

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


[PATCH] D139837: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

2023-05-11 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

Sorry for the long delay guys. I'll update the patch this weekend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139837

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


[PATCH] D150411: [NFC][Clang] Fix Static Code Analysis Concerns

2023-05-11 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added a reviewer: tahonermann.
Herald added subscribers: steakhal, arphaman.
Herald added a reviewer: NoQ.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.

This patch adds missing assignment operator to the class which has user-defined 
copy/move constructor.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150411

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Analysis/Analyses/Consumed.h
  clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
  clang/include/clang/Analysis/Analyses/ThreadSafetyUtil.h
  clang/include/clang/Analysis/Support/BumpVector.h
  clang/include/clang/Rewrite/Core/RewriteRope.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/EHScopeStack.h
  clang/lib/Sema/SemaAccess.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -654,6 +654,9 @@
   O.Root = nullptr;
 }
 
+DiagText(const DiagText &) = delete;
+DiagText &operator=(const DiagText &) = delete;
+
 ~DiagText() {
   for (Piece *P : AllocatedPieces)
 delete P;
Index: clang/lib/Sema/SemaAccess.cpp
===
--- clang/lib/Sema/SemaAccess.cpp
+++ clang/lib/Sema/SemaAccess.cpp
@@ -199,6 +199,13 @@
 : Target(S.Target), Has(S.Has) {
   S.Target = nullptr;
 }
+
+SavedInstanceContext &operator=(SavedInstanceContext &&S) {
+  Target = S.Target;
+  Has = S.Has;
+  return *this;
+}
+
 ~SavedInstanceContext() {
   if (Target)
 Target->HasInstanceContext = Has;
Index: clang/lib/CodeGen/EHScopeStack.h
===
--- clang/lib/CodeGen/EHScopeStack.h
+++ clang/lib/CodeGen/EHScopeStack.h
@@ -147,7 +147,9 @@
 
   public:
 Cleanup(const Cleanup &) = default;
+Cleanup &operator=(const Cleanup &) = delete;
 Cleanup(Cleanup &&) {}
+Cleanup &operator=(Cleanup &&) = delete;
 Cleanup() = default;
 
 virtual bool isRedundantBeforeReturn() { return false; }
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -829,7 +829,12 @@
   ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
 Other.CGF = nullptr;
   }
-  ApplyDebugLocation &operator=(ApplyDebugLocation &&) = default;
+
+  ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
+CGF = Other.CGF;
+Other.CGF = nullptr;
+return *this;
+  }
 
   ~ApplyDebugLocation();
 
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -670,7 +670,9 @@
 public:
   SymbolVisitor() = default;
   SymbolVisitor(const SymbolVisitor &) = default;
+  SymbolVisitor &operator=(const SymbolVisitor &) = delete;
   SymbolVisitor(SymbolVisitor &&) {}
+  SymbolVisitor &operator=(SymbolVisitor &&) = delete;
 
   /// A visitor method invoked by ProgramStateManager::scanReachableSymbols.
   ///
Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
===
--- clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
+++ clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
@@ -50,7 +50,9 @@
 public:
   BugReporterVisitor() = default;
   BugReporterVisitor(const BugReporterVisitor &) = default;
+  BugReporterVisitor &operator=(const BugReporterVisitor &) = delete;
   BugReporterVisitor(BugReporterVisitor &&) {}
+  BugReporterVisitor &operator=(BugReporterVisitor &&) = delete;
   virtual ~BugReporterVisitor();
 
   /// Return a diagnostic piece which should be associated with the
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1786,7 +1786,9 @@
 SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID,
   const FunctionDecl *Fn, Sema &S);
 SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D);
+SemaDiagnosticBuilder &operator=(SemaDiagnosticBuilder &&D) = delete;
 SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default;
+SemaDiagnosticBuild

[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D143675#4310904 , @vitalybuka 
wrote:

> In D143675#4310734 , @rsundahl 
> wrote:
>
>> @kcc @eugenis @MaskRay @vitalybuka Ok to go with this? All new functionality 
>> is under the added flag so not expecting any surprises. Rename 
>> asabi->asan_abi as suggested.
>
> Thanks, asan_abi LGTM.
>
> I don't have good reasons to object that patch, but I suspect it's 
> sub-optimal. But we may get a valuable expirience.
>
>> Rather than adding a lot of conditional code to the LLVM instrumentation 
>> phase
>
> We do this for hwasan for Android, and to some extent msan for Chromium. 
> @eugenis maybe can share more info.
>
>> Based on previous discussions about this topic, our understanding is that 
>> freezing the present ABI would impose an excessive burden on other sanitizer 
>> developers and for unrelated platforms.
>
> I guess we just have no way to enforce that. A couple of buildbots with 
> "stable clang" + "HEAD runtime" and "HEAD clang" + "stable runtime" which do 
> some non-tivial build, e.g. clang bootstrap can enforce that. We can at list 
> to enforce default set of flags.

Very sorry for my belated response. I feel that I am not a decision maker, so I 
am waiting on the maintainers.
I do care about driver options (as a code owner) and sanitizer maintainability 
(my interest), though. I have left some comments and will be happy when they 
are resolved.

The documentation `compiler-rt/docs/asan_abi.md` probably needs more polishing. 
The current style is like seeking for RFC, not for something already in tree.




Comment at: compiler-rt/docs/asan_abi.md:3
+
+We wish to make it possible to include the AddressSanitizer (ASan) runtime 
implementation in OSes and for this we need a stable ASan ABI. Based on 
previous discussions about this topic, our understanding is that freezing the 
present ABI would impose an excessive burden on other sanitizer developers and 
for unrelated platforms. Therefore, we propose adding a secondary stable ABI 
for our use and anyone else in the community seeking the same. We believe that 
we can define a stable ABI with minimal burden on the community, expecting only 
to keep existing tests running and implementing stubs when new features are 
added. We are okay with trading performance for stability with no impact for 
existing users of ASan while minimizing the maintenance burden for ASan 
maintainers. We wish to commit this functionality to the LLVM project to 
maintain it there. This new and stable ABI will abstract away the 
implementation details allowing new and novel approaches to ASan for 
developers, researchers and others.
+

The introductory paragraph is written in a style like the RFC, but not for the 
official documentation.
The official documentation should be written in a style that this has been 
accepted.
For sentences like maintenance costs, they can be moved to the `Maintenance` 
chapter.

I have an simplified introductory paragraph:

> Some OSes like Darwin want to include the AddressSanitizer runtime by 
> establishing a stable ASan ABI. `lib/asan_abi` contains a secondary stable 
> ABI for our use and others in the community. This new ABI will have minimal 
> impact on the community, prioritizing stability over performance.

Feel free to add more sentences if you feel too simplified.

Note that `.rst` uses two backsticks for what Markdown uses one backstick for.




Comment at: compiler-rt/docs/asan_abi.md:7
+
+Rather than adding a lot of conditional code to the LLVM instrumentation 
phase, which would incur excessive complexity and maintenance cost of adding 
conditional code into all places that emit a runtime call, we propose a “shim” 
layer which will map the unstable ABI to the stable ABI:
+

Similarly, words like "propose" are RFC-style wording, not for the official 
documentation. For the official documentation, you just say what this is.



Comment at: compiler-rt/docs/asan_abi.md:14
+* `void __asan_poison_cxx_array_cookie(uptr p) { __asan_abi_pac(p); }`
+* This “shim” library would only be used by people who opt in: A compilation 
flag in the Clang driver will be used to gate the use of the stable ABI 
workflow.
+* Utilize the existing ability for the ASan instrumentation to prefer runtime 
calls instead of inlined direct shadow memory accesses.

This “shim” library will only be used when `-fsanitize-stable-abi` is specified 
in the Clang driver.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D143675#4336365 , @rsundahl wrote:

> In D143675#4310903 , @eugenis wrote:
>
>> I'm fine with it in general. Is asan_abi.cpp meant as a temporary stub? It's 
>> not even link anywhere in the current version.
>
> We now use it during testing to close the loop on the question of whether the 
> file is "complete" in the sense that it satisfies the minimal "no-op" 
> implementation of the abi. We also moved from having a hand-curated include 
> file to using the actual interface file which should be the root truth for 
> what needs to be in there. We discovered a few additional functions that were 
> in asan_interface.h but aren't strictly part of the interface between the 
> instrumentation and the runtime but rather are used intra-runtime. Some other 
> routines living in asan_interface.h are really documented "helper" functions. 
> Maybe these should be aggregated somewhere else and/or under a different 
> namespace. For now we ignore those entrypoints by listing them in 
> compiler-rt/lib/asan_abi/darwin_exclude_symbols.inc

How is `compiler-rt/lib/asan_abi/darwin_exclude_symbols.inc` used in the 
upstream and downstream build system?
In this patch this file is only used by one test?




Comment at: clang/include/clang/Driver/Options.td:1785
HelpText<"Use default code 
inlining logic for the address sanitizer">;
+def fsanitize_address_stable_abi : Flag<["-"], "fsanitize-address-stable-abi">,
+Group,

rsundahl wrote:
> vitalybuka wrote:
> > how likely you will need thus for  other sanitizers in future
> > should this be rather -fsanitize-stable-abi which is ignore for now for 
> > other sanitizers?
> Thanks @vitalybuka. I agree and made this change. For now I still only 
> consume the flag if sanitizer=address so that we continue to get the unused 
> option warning in the other cases and left the test for that warning intact.
See `BooleanFFlag`. Some existing sanitizer options are not written with the 
best practice.

If `-fno-sanitize-stable-abi` is the default, there is usually no need to have 
a duplicate help message `Disable ...`. Documenting the non-default boolean 
option suffices.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:918
+options::OPT_fno_sanitize_stable_abi,
+StableABI);
+

Existing code unnecessarily reads the previous value (false) of the variable. 
No need to copy that for new code.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:1292
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-asan-instrumentation-with-call-threshold=0");
+CmdArgs.push_back("-mllvm");

Optional nit: I added `-mllvm=` as an alias in `D143325`. You can use 
`-mllvm=-asan-instrumentation-with-call-threshold=0` to decrease the 
number/length of cc1 options.

Add some comments before `if (StableABI) {` why the two `cl::opt` options are 
specified.



Comment at: clang/test/Driver/fsanitize.c:266
 
+// RUN: %clang --target=x86_64-linux-gnu -fsanitize-stable-abi %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-ASAN-STABLE-WARN

I think the tests should go to a new file `fsanitize-stable-abi.c`. The checks 
are different enough from the rest of `fsanitize.c` (which can be split).



Comment at: clang/test/Driver/fsanitize.c:269
+// CHECK-ASAN-STABLE-WARN: warning: argument unused during compilation: 
'-fsanitize-stable-abi'
+// RUN: %clang --target=x86_64-linux-gnu -fsanitize=address 
-fsanitize-stable-abi %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-ASAN-STABLE-OK

I presume that you want to test the positive forms with Darwin triples like 
`arm64-apple-darwin`?

We can even argue that the option should lead to an error for non-Darwin 
triples.



Comment at: compiler-rt/docs/asan_abi.md:1
+# Darwin Sanitizers Stable ABI
+

The existing compiler-rt/docs docs use `.rst`. Better to use `.rst` to not 
introduce more than one format for one subproject.

`.rst` is used much more than `.md` in llvm-project anyway.



Comment at: compiler-rt/lib/asan_abi/asan_abi.h:13
+#include 
+#include 
+#include 

use clang-format to sort the headers. I'd expect that stdbool and stddef are 
placed together for any sorting behavior.



Comment at: compiler-rt/lib/asan_abi/asan_abi.h:15
+#include 
+extern "C" {
+void __asan_abi_register_image_globals(void);

add a blank line before `extern "C" {`



Comment at: compiler-rt/test/asan_abi/lit.cfg.py:9
+
+# Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if
+# it's not available.

This workaround is unneeded. 

[PATCH] D150352: [clang][dataflow] Don't analyze templated declarations.

2023-05-11 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:2537
 
-TEST(TransferTest, DerefDependentPtr) {
   std::string Code = R"(

This `DerefDependentPtr` test was originally added in 
https://reviews.llvm.org/D117567 and re-landed in 
https://github.com/llvm/llvm-project/commit/acd4b0359097dd8ad166d569a4566879e82a2793

Could you try to revert the effects of those commits? Specifically:

- remove reference skipping from the transfer function for `UO_Deref` (and the 
comment),

- remove the `-fno-delayed-template-parsing` flag from 
`clang/unittests/Analysis/FlowSensitive/TransferTest.cpp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150352

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


[PATCH] D149816: [clang][Interp] Implement __builtin_strcmp

2023-05-11 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.




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

https://reviews.llvm.org/D149816

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


[PATCH] D149816: [clang][Interp] Implement __builtin_strcmp

2023-05-11 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/test/AST/Interp/builtin-functions.cpp:8
+
+  static_assert(__builtin_strcmp("abab", "abab") == 0);
+  static_assert(__builtin_strcmp("abab", "abba") == -1);

Both empty strings `""` would be good as well.


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

https://reviews.llvm.org/D149816

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


[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: compiler-rt/lib/asan_abi/asan_abi_shim.cpp:14
+extern "C" {
+// Globals
+void __asan_register_image_globals(uptr *flag) {

Comments are usually a complete sentence with a period. There are exceptions, 
but a "Globals" needs elaboration to make it better understandable by a reader.



Comment at: compiler-rt/lib/asan_abi/asan_abi_shim.cpp:16
+void __asan_register_image_globals(uptr *flag) {
+__asan_abi_register_image_globals();
+}

2-space indentation, here and throughout.



Comment at: compiler-rt/lib/asan_abi/asan_abi_shim.cpp:41
+
+void __asan_after_dynamic_init(void) {
+__asan_abi_after_dynamic_init();

C++ prefers `()` instead of `(void)`.



Comment at: compiler-rt/lib/asan_abi/asan_abi_shim.cpp:486
+// TBD: Fail here
+return (void *) 0;
+}

You may apply `clang-format`, which may turn this into `(void *)0`, but 
`nullptr` likely works better.



Comment at: 
compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp:1
+// RUN: %clang_asan_abi  -O2 -c -fsanitize-stable-abi -fsanitize=address -O0 
%s -o %t.o
+// RUN: %clangxx -c %p/../../../../lib/asan_abi/asan_abi.cpp -o asan_abi.o

excess spaces

`-O2 ... -O0`?



Comment at: 
compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp:4
+// RUN: %clangxx -dead_strip -o %t %t.o %libasan_abi asan_abi.o && %run %t 2>&1
+
+

One blank line suffices.



Comment at: 
compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp:9
+
+// RUN: nm -g %libasan_abi \
+// RUN:  | grep " [TU] "   \

We generally prefer llvm counterparts to the system binary utilities. Use 
`llvm-nm`



Comment at: 
compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp:15
+// RUN:  > %t.exports
+//
+// RUN:  sed -e ':a' -e 'N' -e '$!ba'  
   \

unneeded `^//$` lines, here and throughout.



Comment at: 
compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp:16
+//
+// RUN:  sed -e ':a' -e 'N' -e '$!ba'  
   \
+// RUN:  -e 's/ //g'   
   \

Does Darwin sed accept `;` to combine multiple `-e` into one `-e` with `;`?



Comment at: 
compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp:21
+// RUN:  %t.asan_interface.inc 
   \
+// RUN:  | grep  -v -f %p/../../../../lib/asan_abi/darwin_exclude_symbols.inc  
   \
+// RUN:  | grep -e "INTERFACE_\(WEAK_\)\?FUNCTION" 
   \

2-space indentation for `|` continuation lines as well



Comment at: 
compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp:26
+//
+// RUN: cat %t.imports | sort | uniq > %t.imports-sorted
+// RUN: cat %t.exports | sort | uniq > %t.exports-sorted

`sort %t.imports`. See `Useless use of cat`



Comment at: compiler-rt/test/asan_abi/TestCases/linkstaticlibrary.cpp:1
+// RUN: %clang_asan_abi  -O2 -c -fsanitize-stable-abi -fsanitize=address -O0 
%s -o %t.o
+// RUN: %clangxx -c %p/../../../lib/asan_abi/asan_abi.cpp -o asan_abi.o

`-O2 ... -O0`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-05-11 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 521507.
shafik added a comment.

- Adding release note


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

https://reviews.llvm.org/D150226

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -900,12 +900,12 @@
 namespace GH50055 {
 enum E {e1=0, e2=1};
 consteval int testDefaultArgForParam(E eParam = (E)-1) {
-// expected-error@-1 {{integer value -1 is outside the valid range of values [0, 1] for this enumeration type}}
+// expected-note@-1 {{integer value -1 is outside the valid range of values [0, 1] for this enumeration type}}
   return (int)eParam;
 }
 
 int test() {
-  return testDefaultArgForParam() + testDefaultArgForParam((E)1);
+  return testDefaultArgForParam() + testDefaultArgForParam((E)1); // expected-error {{call to consteval function 'GH50055::testDefaultArgForParam' is not a constant expression}}
 }
 }
 
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2439,39 +2439,39 @@
 
 void testValueInRangeOfEnumerationValues() {
   constexpr E1 x1 = static_cast(-8);
-  constexpr E1 x2 = static_cast(8);
-  // expected-error@-1 {{integer value 8 is outside the valid range of values [-8, 7] for this enumeration type}}
+  constexpr E1 x2 = static_cast(8); // expected-error {{constexpr variable 'x2' must be initialized by a constant expression}}
+  // expected-note@-1 {{integer value 8 is outside the valid range of values [-8, 7] for this enumeration type}}
   E1 x2b = static_cast(8); // ok, not a constant expression context
 
-  constexpr E2 x3 = static_cast(-8);
-  // expected-error@-1 {{integer value -8 is outside the valid range of values [0, 7] for this enumeration type}}
+  constexpr E2 x3 = static_cast(-8); // expected-error {{constexpr variable 'x3' must be initialized by a constant expression}}
+  // expected-note@-1 {{integer value -8 is outside the valid range of values [0, 7] for this enumeration type}}
   constexpr E2 x4 = static_cast(0);
-  constexpr E2 x5 = static_cast(8);
-  // expected-error@-1 {{integer value 8 is outside the valid range of values [0, 7] for this enumeration type}}
+  constexpr E2 x5 = static_cast(8); // expected-error {{constexpr variable 'x5' must be initialized by a constant expression}}
+  // expected-note@-1 {{integer value 8 is outside the valid range of values [0, 7] for this enumeration type}}
 
   constexpr E3 x6 = static_cast(-2048);
   constexpr E3 x7 = static_cast(-8);
   constexpr E3 x8 = static_cast(0);
   constexpr E3 x9 = static_cast(8);
-  constexpr E3 x10 = static_cast(2048);
-  // expected-error@-1 {{integer value 2048 is outside the valid range of values [-2048, 2047] for this enumeration type}}
+  constexpr E3 x10 = static_cast(2048); // expected-error {{constexpr variable 'x10' must be initialized by a constant expression}}
+  // expected-note@-1 {{integer value 2048 is outside the valid range of values [-2048, 2047] for this enumeration type}}
 
   constexpr E4 x11 = static_cast(0);
   constexpr E4 x12 = static_cast(1);
-  constexpr E4 x13 = static_cast(2);
-  // expected-error@-1 {{integer value 2 is outside the valid range of values [0, 1] for this enumeration type}}
+  constexpr E4 x13 = static_cast(2); // expected-error {{constexpr variable 'x13' must be initialized by a constant expression}}
+  // expected-note@-1 {{integer value 2 is outside the valid range of values [0, 1] for this enumeration type}}
 
   constexpr EEmpty x14 = static_cast(0);
   constexpr EEmpty x15 = static_cast(1);
-  constexpr EEmpty x16 = static_cast(2);
-  // expected-error@-1 {{integer value 2 is outside the valid range of values [0, 1] for this enumeration type}}
+  constexpr EEmpty x16 = static_cast(2);  // expected-error {{constexpr variable 'x16' must be initialized by a constant expression}}
+  // expected-note@-1 {{integer value 2 is outside the valid range of values [0, 1] for this enumeration type}}
 
   constexpr EFixed x17 = static_cast(100);
   constexpr EScoped x18 = static_cast(100);
 
   constexpr EMaxInt x19 = static_cast(__INT_MAX__-1);
-  constexpr EMaxInt x20 = static_cast((long)__INT_MAX__+1);
-  // expected-error@-1 {{integer value 2147483648 is outside the valid range of values [-2147483648, 2147483647] for this enumeration type}}
+  constexpr EMaxInt x20 = static_cast((long)__INT_MAX__+1); // expected-error {{constexpr variable 'x20' must be initialized by a constant expression}}
+  // expected-note@-1 {{integer value 2147483648 is outside the valid ran

[clang] ba566ff - [NFC][AST] Return void from setUseQualifiedLookup

2023-05-11 Thread Vitaly Buka via cfe-commits

Author: Vitaly Buka
Date: 2023-05-11T17:13:19-07:00
New Revision: ba566fffb205a338c0a6e382b64d84b3a1e21fb6

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

LOG: [NFC][AST] Return void from setUseQualifiedLookup

It uses to initialize the class. If so, it returns uninitalized value.
This is UB and msan with -fno-inline will complain.

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 65215dbf70551..f7d5b3a83141a 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -2540,10 +2540,8 @@ class DeclContext {
  D == LastDecl);
   }
 
-  bool setUseQualifiedLookup(bool use = true) const {
-bool old_value = DeclContextBits.UseQualifiedLookup;
+  void setUseQualifiedLookup(bool use = true) const {
 DeclContextBits.UseQualifiedLookup = use;
-return old_value;
   }
 
   bool shouldUseQualifiedLookup() const {

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 537c09723919d..5a2a3616d1136 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -2424,8 +2424,9 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 bool oldVal;
 DeclContext *Context;
 // Set flag in DeclContext informing debugger that we're looking for 
qualified name
-QualifiedLookupInScope(DeclContext *ctx) : Context(ctx) {
-  oldVal = ctx->setUseQualifiedLookup();
+QualifiedLookupInScope(DeclContext *ctx)
+: oldVal(ctx->shouldUseQualifiedLookup()), Context(ctx) {
+  ctx->setUseQualifiedLookup();
 }
 ~QualifiedLookupInScope() {
   Context->setUseQualifiedLookup(oldVal);



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


[PATCH] D147266: [AArch64] Sink operands to allow for bitselect instructions

2023-05-11 Thread Pranav Kant via Phabricator via cfe-commits
pranavk updated this revision to Diff 521505.
pranavk added a comment.

add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll


Index: llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
===
--- llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
+++ llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
@@ -144,3 +144,30 @@
   %or = or <16 x i8> %and, %and1
   ret <16 x i8> %or
 }
+
+define <4 x i32> @test_bit_sink_operand(<4 x i32> %src, <4 x i32> %dst, <4 x 
i32> %mask, i32 %scratch) {
+; CHECK-LABEL: test_bit_sink_operand
+; CHECK: // %do.body
+; CHECK: bit v1.16b, v0.16b, v2.16b
+
+entry:
+  %0 = xor <4 x i32> %mask, 
+  %div = sdiv i32 %scratch, 2
+  br label %do.body
+
+do.body: 
+  %dst.addr.0 = phi <4 x i32> [ %dst, %entry ], [ %vecins, %do.body ]
+  %src.addr.0 = phi <4 x i32> [ %src, %entry ], [ %vecins1, %do.body ]
+  %i.0 = phi i32 [ 0, %entry ], [ %inc, %do.body ]
+  %vbsl3.i = and <4 x i32> %src.addr.0, %mask
+  %vbsl4.i = and <4 x i32> %dst.addr.0, %0
+  %vbsl5.i = or <4 x i32> %vbsl3.i, %vbsl4.i
+  %vecins = insertelement <4 x i32> %vbsl5.i, i32 %scratch, i32 %i.0
+  %vecins1 = insertelement <4 x i32> %src.addr.0, i32 %div, i32 %i.0
+  %inc = add nuw nsw i32 %i.0, 1
+  %exitcond.not = icmp eq i32 %inc, 5
+  br i1 %exitcond.not, label %do.end, label %do.body
+
+do.end:
+  ret <4 x i32> %vecins
+}
\ No newline at end of file
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -14332,6 +14332,52 @@
 
 return true;
   }
+  case Instruction::Or: {
+// Pattern: Or(And(MaskValue, A), And(Not(MaskValue), B)) ->
+// bitselect(MaskValue, A, B) where Not(MaskValue) = Xor(MaskValue, -1)
+if (Subtarget->hasNEON()) {
+  // If any of the intermediate Ands have uses other than Or, don't fold
+  if (!I->getOperand(0)->hasOneUse() || !I->getOperand(0)->hasOneUse())
+return false;
+
+  Instruction *OtherAnd, *IA, *IB;
+  Value *MaskValue;
+  // MainAnd refers to And instruction that has 'Not' as one of its 
operands
+  if (match(I, m_c_Or(m_Instruction(OtherAnd),
+  m_c_And(m_Not(m_Value(MaskValue)),
+  m_Instruction(IA) {
+if (match(OtherAnd,
+  m_c_And(m_Specific(MaskValue), m_Instruction(IB {
+  Instruction *MainAnd = I->getOperand(0) == OtherAnd
+ ? cast(I->getOperand(1))
+ : cast(I->getOperand(0));
+
+  // Both Ands should be in same basic block as Or
+  if (I->getParent() != MainAnd->getParent() ||
+  I->getParent() != OtherAnd->getParent())
+return false;
+
+  // Non-mask operands of both Ands should also be in same basic block
+  if (I->getParent() != IA->getParent() ||
+  I->getParent() != IB->getParent())
+return false;
+
+  for (unsigned Idx = 0; Idx < MainAnd->getNumOperands(); Idx++) {
+if (MainAnd->getOperand(Idx) != IA &&
+MainAnd->getOperand(Idx)->hasOneUse()) {
+  Ops.push_back(&MainAnd->getOperandUse(Idx));
+  Ops.push_back(&I->getOperandUse(0));
+  Ops.push_back(&I->getOperandUse(1));
+
+  return true;
+}
+  }
+}
+  }
+}
+
+return false;
+  }
   case Instruction::Mul: {
 int NumZExts = 0, NumSExts = 0;
 for (auto &Op : I->operands()) {


Index: llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
===
--- llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
+++ llvm/test/CodeGen/AArch64/aarch64-bit-gen.ll
@@ -144,3 +144,30 @@
   %or = or <16 x i8> %and, %and1
   ret <16 x i8> %or
 }
+
+define <4 x i32> @test_bit_sink_operand(<4 x i32> %src, <4 x i32> %dst, <4 x i32> %mask, i32 %scratch) {
+; CHECK-LABEL: test_bit_sink_operand
+; CHECK: // %do.body
+; CHECK: bit v1.16b, v0.16b, v2.16b
+
+entry:
+  %0 = xor <4 x i32> %mask, 
+  %div = sdiv i32 %scratch, 2
+  br label %do.body
+
+do.body: 
+  %dst.addr.0 = phi <4 x i32> [ %dst, %entry ], [ %vecins, %do.body ]
+  %src.addr.0 = phi <4 x i32> [ %src, %entry ], [ %vecins1, %do.body ]
+  %i.0 = phi i32 [ 0, %entry ], [ %inc, %do.body ]
+  %vbsl3.i = and <4 x i32> %src.addr.0, %mask
+  %vbsl4.i = and <4 x i32> %dst.addr.0, %0
+  %vbsl5.i = or <4 x i32> %vbsl3.i, %vbsl4.i
+  %vecins = insertelement <4 x i32> %vbsl5.i, i32 %scratch, i32 %i.0
+  %vecins1 = insertelement <4 x i32> %src.addr.0, i32

[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-11 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: compiler-rt/lib/asan_abi/asan_abi_shim.cpp:62
+void __asan_init(void) {
+assert(sizeof(uptr) == 8);
+assert(sizeof(u64) == 8);

static_assert


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-11 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl added a comment.

In D143675#4310903 , @eugenis wrote:

> I'm fine with it in general. Is asan_abi.cpp meant as a temporary stub? It's 
> not even link anywhere in the current version.

We now use it during testing to close the loop on the question of whether the 
file is "complete" in the sense that it satisfies the minimal "no-op" 
implementation of the abi. We also moved from having a hand-curated include 
file to using the actual interface file which should be the root truth for what 
needs to be in there. We discovered a few additional functions that were in 
asan_interface.h but aren't strictly part of the interface between the 
instrumentation and the runtime but rather are used intra-runtime. Some other 
routines living in asan_interface.h are really documented "helper" functions. 
Maybe these should be aggregated somewhere else and/or under a different 
namespace. For now we ignore those entrypoints by listing them in 
compiler-rt/lib/asan_abi/darwin_exclude_symbols.inc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


[PATCH] D147266: [AArch64] Sink operands to allow for bitselect instructions

2023-05-11 Thread Pranav Kant via Phabricator via cfe-commits
pranavk added a comment.

tests coming


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

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


[PATCH] D148490: [AIX] use system assembler for assembly files

2023-05-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D148490#4334476 , @shchenz wrote:

>> I am not sure you need 6 RUN lines to test this. Whether a target uses 
>> integrated assembler has an existing test file and you can reuse that.
>
> I don't have strong prefer which one we should use, a new file or reuse file. 
> Since you point out, I change to reuse a legacy one in same dir. Please 
> notice that there are some other targets that has their own assembler test 
> file, like mips-as.s, systemz-as.s, arm64-as.s.

Thanks. It makes sense to check whether reusing a test file (possibly renaming 
it) makes sense.
https://maskray.me/blog/2021-08-08-toolchain-testing "an existing test can be 
enhanced"

Some existing tests can be improved. You may improve the testing without cargo 
culting:)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148490

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


[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-11 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl updated this revision to Diff 521482.
rsundahl added a comment.

Fixed nits (missing newlines at end of files)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/docs/asan_abi.md
  compiler-rt/lib/asan_abi/CMakeLists.txt
  compiler-rt/lib/asan_abi/asan_abi.cpp
  compiler-rt/lib/asan_abi/asan_abi.h
  compiler-rt/lib/asan_abi/asan_abi_shim.cpp
  compiler-rt/lib/asan_abi/darwin_exclude_symbols.inc
  compiler-rt/test/asan_abi/CMakeLists.txt
  compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
  compiler-rt/test/asan_abi/TestCases/linkstaticlibrary.cpp
  compiler-rt/test/asan_abi/lit.cfg.py
  compiler-rt/test/asan_abi/lit.site.cfg.py.in

Index: compiler-rt/test/asan_abi/lit.site.cfg.py.in
===
--- /dev/null
+++ compiler-rt/test/asan_abi/lit.site.cfg.py.in
@@ -0,0 +1,18 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+# Tool-specific config options.
+config.name_suffix = "@ASAN_ABI_TEST_CONFIG_SUFFIX@"
+config.target_cflags = "@ASAN_ABI_TEST_TARGET_CFLAGS@"
+config.clang = "@ASAN_ABI_TEST_TARGET_CC@"
+config.bits = "@ASAN_ABI_TEST_BITS@"
+config.arm_thumb = "@COMPILER_RT_ARM_THUMB@"
+config.apple_platform = "@ASAN_ABI_TEST_APPLE_PLATFORM@"
+config.apple_platform_min_deployment_target_flag = "@ASAN_ABI_TEST_MIN_DEPLOYMENT_TARGET_FLAG@"
+config.asan_abi_dynamic = @ASAN_ABI_TEST_DYNAMIC@
+config.target_arch = "@ASAN_ABI_TEST_TARGET_ARCH@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@ASAN_ABI_LIT_SOURCE_DIR@/lit.cfg.py")
Index: compiler-rt/test/asan_abi/lit.cfg.py
===
--- /dev/null
+++ compiler-rt/test/asan_abi/lit.cfg.py
@@ -0,0 +1,84 @@
+# -*- Python -*-
+
+import os
+import platform
+import re
+
+import lit.formats
+
+# Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if
+# it's not available.
+try:
+  import shlex
+  sh_quote = shlex.quote
+except:
+  import pipes
+  sh_quote = pipes.quote
+
+def get_required_attr(config, attr_name):
+  attr_value = getattr(config, attr_name, None)
+  if attr_value == None:
+lit_config.fatal(
+  "No attribute %r in test configuration! You may need to run "
+  "tests from your build directory or add this attribute "
+  "to lit.site.cfg.py " % attr_name)
+  return attr_value
+
+# Setup config name.
+config.name = 'AddressSanitizerABI' + config.name_suffix
+
+# Platform-specific default ASAN_ABI_OPTIONS for lit tests.
+default_asan_abi_opts = list(config.default_sanitizer_opts)
+
+default_asan_abi_opts_str = ':'.join(default_asan_abi_opts)
+if default_asan_abi_opts_str:
+  config.environment['ASAN_ABI_OPTIONS'] = default_asan_abi_opts_str
+  default_asan_abi_opts_str += ':'
+config.substitutions.append(('%env_asan_abi_opts=',
+ 'env ASAN_ABI_OPTIONS=' + default_asan_abi_opts_str))
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# GCC-ASan doesn't link in all the necessary libraries automatically, so
+# we have to do it ourselves.
+extra_link_flags = []
+
+# Setup default compiler flags used with -fsanitize=address option.
+# FIXME: Review the set of required flags and check if it can be reduced.
+target_cflags = [get_required_attr(config, "target_cflags")] + extra_link_flags
+target_cxxflags = config.cxx_mode_flags + target_cflags
+clang_asan_abi_static_cflags = (["-fsanitize=address",
+"-fsanitize-stable-abi",
+"-mno-omit-leaf-frame-pointer",
+"-fno-omit-frame-pointer",
+"-fno-optimize-sibling-calls"] +
+config.debug_info_flags + target_cflags)
+clang_asan_abi_static_cxxflags = config.cxx_mode_flags + clang_asan_abi_static_cflags
+
+config.available_features.add("asan_abi-static-runtime")
+clang_asan_abi_cflags = clang_asan_abi_static_cflags
+clang_asan_abi_cxxflags = clang_asan_abi_static_cxxflags
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+config.substitutions.append( ("%clang ", build_invocation(target_cflags)) )
+config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) )
+config.substitutions.append( ("%clang_asan_abi ", build_invocation(clang_asan_abi_cflags)) )
+config.substitutions.append( ("%clangxx_asan_abi ", build_invocation(clang_asan_abi_cxxflags)) )
+
+libasan_abi_path = os.path.join(config.compiler_rt_libdir, 'libclang_rt.asan_ab

[PATCH] D146342: [-Wunsafe-buffer-usage] Move the whole analysis to the end of a translation unit

2023-05-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Ok looks great to me now!




Comment at: clang/lib/Sema/AnalysisBasedWarnings.cpp:2364
+ Node->getBeginLoc())) {
+  UnsafeBufferUsageReporter R(S);
+  clang::checkUnsafeBufferUsage(Node, R, UnsafeBufferEmitFixits);

So WDYT about capturing the reporter from outside lambda instead?


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

https://reviews.llvm.org/D146342

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


[PATCH] D149809: [Clang][Docs] Fix man page build

2023-05-11 Thread Tom Stellard via Phabricator via cfe-commits
tstellar accepted this revision.
tstellar added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149809

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


[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-11 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl updated this revision to Diff 521479.
rsundahl added a comment.

Added testing. Removed asan_abi_shim.h.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/docs/asan_abi.md
  compiler-rt/lib/asan_abi/CMakeLists.txt
  compiler-rt/lib/asan_abi/asan_abi.cpp
  compiler-rt/lib/asan_abi/asan_abi.h
  compiler-rt/lib/asan_abi/asan_abi_shim.cpp
  compiler-rt/lib/asan_abi/darwin_exclude_symbols.inc
  compiler-rt/test/asan_abi/CMakeLists.txt
  compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
  compiler-rt/test/asan_abi/TestCases/linkstaticlibrary.cpp
  compiler-rt/test/asan_abi/lit.cfg.py
  compiler-rt/test/asan_abi/lit.site.cfg.py.in

Index: compiler-rt/test/asan_abi/lit.site.cfg.py.in
===
--- /dev/null
+++ compiler-rt/test/asan_abi/lit.site.cfg.py.in
@@ -0,0 +1,18 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+# Tool-specific config options.
+config.name_suffix = "@ASAN_ABI_TEST_CONFIG_SUFFIX@"
+config.target_cflags = "@ASAN_ABI_TEST_TARGET_CFLAGS@"
+config.clang = "@ASAN_ABI_TEST_TARGET_CC@"
+config.bits = "@ASAN_ABI_TEST_BITS@"
+config.arm_thumb = "@COMPILER_RT_ARM_THUMB@"
+config.apple_platform = "@ASAN_ABI_TEST_APPLE_PLATFORM@"
+config.apple_platform_min_deployment_target_flag = "@ASAN_ABI_TEST_MIN_DEPLOYMENT_TARGET_FLAG@"
+config.asan_abi_dynamic = @ASAN_ABI_TEST_DYNAMIC@
+config.target_arch = "@ASAN_ABI_TEST_TARGET_ARCH@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@ASAN_ABI_LIT_SOURCE_DIR@/lit.cfg.py")
Index: compiler-rt/test/asan_abi/lit.cfg.py
===
--- /dev/null
+++ compiler-rt/test/asan_abi/lit.cfg.py
@@ -0,0 +1,84 @@
+# -*- Python -*-
+
+import os
+import platform
+import re
+
+import lit.formats
+
+# Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if
+# it's not available.
+try:
+  import shlex
+  sh_quote = shlex.quote
+except:
+  import pipes
+  sh_quote = pipes.quote
+
+def get_required_attr(config, attr_name):
+  attr_value = getattr(config, attr_name, None)
+  if attr_value == None:
+lit_config.fatal(
+  "No attribute %r in test configuration! You may need to run "
+  "tests from your build directory or add this attribute "
+  "to lit.site.cfg.py " % attr_name)
+  return attr_value
+
+# Setup config name.
+config.name = 'AddressSanitizerABI' + config.name_suffix
+
+# Platform-specific default ASAN_ABI_OPTIONS for lit tests.
+default_asan_abi_opts = list(config.default_sanitizer_opts)
+
+default_asan_abi_opts_str = ':'.join(default_asan_abi_opts)
+if default_asan_abi_opts_str:
+  config.environment['ASAN_ABI_OPTIONS'] = default_asan_abi_opts_str
+  default_asan_abi_opts_str += ':'
+config.substitutions.append(('%env_asan_abi_opts=',
+ 'env ASAN_ABI_OPTIONS=' + default_asan_abi_opts_str))
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# GCC-ASan doesn't link in all the necessary libraries automatically, so
+# we have to do it ourselves.
+extra_link_flags = []
+
+# Setup default compiler flags used with -fsanitize=address option.
+# FIXME: Review the set of required flags and check if it can be reduced.
+target_cflags = [get_required_attr(config, "target_cflags")] + extra_link_flags
+target_cxxflags = config.cxx_mode_flags + target_cflags
+clang_asan_abi_static_cflags = (["-fsanitize=address",
+"-fsanitize-stable-abi",
+"-mno-omit-leaf-frame-pointer",
+"-fno-omit-frame-pointer",
+"-fno-optimize-sibling-calls"] +
+config.debug_info_flags + target_cflags)
+clang_asan_abi_static_cxxflags = config.cxx_mode_flags + clang_asan_abi_static_cflags
+
+config.available_features.add("asan_abi-static-runtime")
+clang_asan_abi_cflags = clang_asan_abi_static_cflags
+clang_asan_abi_cxxflags = clang_asan_abi_static_cxxflags
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+config.substitutions.append( ("%clang ", build_invocation(target_cflags)) )
+config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) )
+config.substitutions.append( ("%clang_asan_abi ", build_invocation(clang_asan_abi_cflags)) )
+config.substitutions.append( ("%clangxx_asan_abi ", build_invocation(clang_asan_abi_cxxflags)) )
+
+libasan_abi_path = os.path.join(config.compiler_rt_libdir, 'libclang_rt.asan_abi_osx.

[PATCH] D149809: [Clang][Docs] Fix man page build

2023-05-11 Thread Aiden Grossman via Phabricator via cfe-commits
aidengrossman added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149809

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


[PATCH] D147266: [AArch64] Sink operands to allow for bitselect instructions

2023-05-11 Thread Pranav Kant via Phabricator via cfe-commits
pranavk updated this revision to Diff 521474.
pranavk edited the summary of this revision.
pranavk added a comment.

Address reviewer comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp


Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -14332,6 +14332,48 @@
 
 return true;
   }
+  case Instruction::Or: {
+// Pattern: Or(And(MaskValue, A), And(Not(MaskValue), B)) ->
+// bitselect(MaskValue, A, B) where Not(MaskValue) = Xor(MaskValue, -1)
+if (Subtarget->hasNEON()) {
+  // If any of the intermediate Ands have uses other than Or, don't fold
+  if (!I->getOperand(0)->hasOneUse() || !I->getOperand(0)->hasOneUse())
+return false;
+
+  Instruction *OtherAnd, *IA, *IB;
+  Value *MaskValue;
+  // MainAnd refers to And instruction that has 'Not' as one of its 
operands
+  if (match(I, m_c_Or(m_Instruction(OtherAnd),
+  m_c_And(m_Not(m_Value(MaskValue)),
+  m_Instruction(IA) {
+if (match(OtherAnd,
+  m_c_And(m_Specific(MaskValue), m_Instruction(IB {
+  Instruction *MainAnd = I->getOperand(0) == OtherAnd
+ ? cast(I->getOperand(1))
+ : cast(I->getOperand(0));
+
+  // Both Ands should be in same basic block as Or
+  if (I->getParent() != MainAnd->getParent() ||
+  I->getParent() != OtherAnd->getParent())
+return false;
+
+  // Non-mask operands of both Ands should also be in same basic block
+  if (I->getParent() != IA->getParent() ||
+  I->getParent() != IB->getParent())
+return false;
+
+  Ops.push_back(&MainAnd->getOperandUse(0));
+  Ops.push_back(&MainAnd->getOperandUse(1));
+  Ops.push_back(&I->getOperandUse(0));
+  Ops.push_back(&I->getOperandUse(1));
+
+  return true;
+}
+  }
+}
+
+return false;
+  }
   case Instruction::Mul: {
 int NumZExts = 0, NumSExts = 0;
 for (auto &Op : I->operands()) {


Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -14332,6 +14332,48 @@
 
 return true;
   }
+  case Instruction::Or: {
+// Pattern: Or(And(MaskValue, A), And(Not(MaskValue), B)) ->
+// bitselect(MaskValue, A, B) where Not(MaskValue) = Xor(MaskValue, -1)
+if (Subtarget->hasNEON()) {
+  // If any of the intermediate Ands have uses other than Or, don't fold
+  if (!I->getOperand(0)->hasOneUse() || !I->getOperand(0)->hasOneUse())
+return false;
+
+  Instruction *OtherAnd, *IA, *IB;
+  Value *MaskValue;
+  // MainAnd refers to And instruction that has 'Not' as one of its operands
+  if (match(I, m_c_Or(m_Instruction(OtherAnd),
+  m_c_And(m_Not(m_Value(MaskValue)),
+  m_Instruction(IA) {
+if (match(OtherAnd,
+  m_c_And(m_Specific(MaskValue), m_Instruction(IB {
+  Instruction *MainAnd = I->getOperand(0) == OtherAnd
+ ? cast(I->getOperand(1))
+ : cast(I->getOperand(0));
+
+  // Both Ands should be in same basic block as Or
+  if (I->getParent() != MainAnd->getParent() ||
+  I->getParent() != OtherAnd->getParent())
+return false;
+
+  // Non-mask operands of both Ands should also be in same basic block
+  if (I->getParent() != IA->getParent() ||
+  I->getParent() != IB->getParent())
+return false;
+
+  Ops.push_back(&MainAnd->getOperandUse(0));
+  Ops.push_back(&MainAnd->getOperandUse(1));
+  Ops.push_back(&I->getOperandUse(0));
+  Ops.push_back(&I->getOperandUse(1));
+
+  return true;
+}
+  }
+}
+
+return false;
+  }
   case Instruction::Mul: {
 int NumZExts = 0, NumSExts = 0;
 for (auto &Op : I->operands()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147266: [AArch64] Sink operands to allow for bitselect instructions

2023-05-11 Thread Pranav Kant via Phabricator via cfe-commits
pranavk planned changes to this revision.
pranavk marked 2 inline comments as done.
pranavk added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:14343
+// passed to this function. Starting pattern matching with any other
+// instruction (such as Or) would lead to malformed IR
+

dmgreen wrote:
> That sounds like it might be a bug that happens if it tries to sink too many 
> operands? From what I remember the order they are put into Ops might matter. 
> And if it is sinking to the Or it might need to add both the And as well as 
> the Not.
When I tried to sink Or, I didn't add both Ands in the Vector. So it was 
sinking it just before Or even though it was used by And one instruction before 
the location where it sunk it. So, I don't think it's a bug. I just forgot to 
add Ands to the vector. I tried adding Ands to the vector and it works. So I 
have changed my implementation to switch-case under Instruction::Or as I think 
that makes it easier to read this code.



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:14364
+for (unsigned AndOpIndex = 0; AndOpIndex < 2; ++AndOpIndex) {
+  if (const Instruction *XI =
+  dyn_cast(Ands[AndIndex][AndOpIndex]);

dmgreen wrote:
> Can this be simplified with a m_Not matcher? In general instructions will be 
> canonicalized so that constants are on the RHS.
> 
> If we are sinking the Not, I feel this should want to test that the pattern 
> makes up a bsl, and if it does then sink the operand of I. i.e. something 
> like checking that OI is 
> `m_c_Or(m_c_And(m_Value(A),m_Value(B)),m_specific(I))`, and then checking 
> that `I` is `m_c_And(m_Not(m_Specific(A)),m_Value(D))` or the other way 
> around.
Absolutely. I didn't look close enough it seems in PatternMatcher.h file. After 
discovering whole bunch of pattern matchers, I have shortened/simplified this 
implementation using m_not, etc. Please look at the latest patch.

I have additionally added more guards/checks to prevent this from happening 
when one of the And, or its operands are not available in same basic block.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

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


[PATCH] D150282: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-11 Thread Mészáros Gergely via Phabricator via cfe-commits
Maetveis accepted this revision.
Maetveis added a comment.
This revision is now accepted and ready to land.

I don't see anything in here that would block later extension for supporting 
offloading, so LGTM from my POV.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150282

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


[PATCH] D150340: [SEH]:Fix assertion when try is used inside catch(...) block with /EHa

2023-05-11 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 521465.
jyu2 added a comment.

Address Eli's comment.  Thanks for review!.

:-( Sorry, You are right!! It is seems EmitSehTryScopeBegin is not called 
anywhere.

Changed. Thanks for the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150340

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp


Index: clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
+++ clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
@@ -9,11 +9,21 @@
 // CHECK: %[[dst1:[0-9-]+]] = catchpad within %[[dst]] [ptr null, i32 0, ptr 
null]
 // CHECK: "funclet"(token %[[dst1]])
 
+// CHECK: define dso_local void @"?bar@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @_CxxThrowException
+// CHECK: %[[dst:[0-9-]+]] = catchpad within %0 [ptr null, i32 0, ptr null]
+// CHECK: invoke void @llvm.seh.try.begin() [ "funclet"(token %[[dst]]) ]
+
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
 // CHECK-NEXT: invoke void @"?crash@@YAXH@Z"(i32 noundef %[[src]])
 // CHECK: invoke void @llvm.seh.try.end()
 
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @"?bar@@YAXXZ"()
+// CHECK: invoke void @llvm.seh.try.end()
+
 // 
*
 // Abstract: Test CPP catch(...) under SEH -EHa option
 
@@ -46,6 +56,18 @@
   }
 }
 
+void bar() {
+  try {
+throw 1;
+  } catch(...) {
+try {
+  *NullPtr = 0;
+} catch (...) {
+   throw 1;
+}
+  }
+}
+
 int main() {
   for (int i = 0; i < 2; i++) {
 __try {
@@ -54,5 +76,10 @@
   printf(" Test CPP unwind: in except handler i = %d \n", i);
 }
   }
+  __try {
+   bar();
+  } __except (1) {
+printf("Test CPP unwind: in except handler \n");
+  }
   return 0;
 }
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -646,7 +646,7 @@
   // Under async exceptions, catch(...) need to catch HW exception too
   // Mark scope with SehTryBegin as a SEH __try scope
   if (getLangOpts().EHAsynch)
-EmitRuntimeCallOrInvoke(getSehTryBeginFn(CGM));
+EmitSehTryScopeBegin();
 }
   }
 }


Index: clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
+++ clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
@@ -9,11 +9,21 @@
 // CHECK: %[[dst1:[0-9-]+]] = catchpad within %[[dst]] [ptr null, i32 0, ptr null]
 // CHECK: "funclet"(token %[[dst1]])
 
+// CHECK: define dso_local void @"?bar@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @_CxxThrowException
+// CHECK: %[[dst:[0-9-]+]] = catchpad within %0 [ptr null, i32 0, ptr null]
+// CHECK: invoke void @llvm.seh.try.begin() [ "funclet"(token %[[dst]]) ]
+
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
 // CHECK-NEXT: invoke void @"?crash@@YAXH@Z"(i32 noundef %[[src]])
 // CHECK: invoke void @llvm.seh.try.end()
 
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @"?bar@@YAXXZ"()
+// CHECK: invoke void @llvm.seh.try.end()
+
 // *
 // Abstract: Test CPP catch(...) under SEH -EHa option
 
@@ -46,6 +56,18 @@
   }
 }
 
+void bar() {
+  try {
+throw 1;
+  } catch(...) {
+try {
+  *NullPtr = 0;
+} catch (...) {
+   throw 1;
+}
+  }
+}
+
 int main() {
   for (int i = 0; i < 2; i++) {
 __try {
@@ -54,5 +76,10 @@
   printf(" Test CPP unwind: in except handler i = %d \n", i);
 }
   }
+  __try {
+   bar();
+  } __except (1) {
+printf("Test CPP unwind: in except handler \n");
+  }
   return 0;
 }
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -646,7 +646,7 @@
   // Under async exceptions, catch(...) need to catch HW exception too
   // Mark scope with SehTryBegin as a SEH __try scope
   if (getLangOpts().EHAsynch)
-EmitRuntimeCallOrInvoke(getSehTryBeginFn(CGM));
+EmitSehTryScopeBegin();
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150403: [clang-format] Adjust braced list detection (try 2)

2023-05-11 Thread Galen Elias via Phabricator via cfe-commits
galenelias created this revision.
galenelias added reviewers: cpplearner, HazardyKnusperkeks, MyDeveloperDay.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, owenpan.
galenelias requested review of this revision.

This is a retry of https://reviews.llvm.org/D114583, which was backed
out for regressions. This fixes
https://github.com/llvm/llvm-project/issues/33891.

Clang Format is detecting a nested scope followed by another open brace
as a braced initializer list due to incorrectly thinking it's matching a
braced initializer at the end of a constructor initializer list which is
followed by the body open brace.

Unfortunately, UnwrappedLineParser isn't doing a very detailed parse, so
it's not super straightforward to distinguish these cases given the
current structure of calculateBraceTypes. My current hypothesis is that
these can be disambiguated by looking at the token preceding the
l_brace, as initializer list parameters will be preceded by an
identifier, but a scope block generally will not (barring the MACRO
wildcard).

To this end, I am tracking the previous token type in a stack parallel
to LBraceStack to help scope this particular case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150403

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13731,6 +13731,26 @@
"  struct Dummy {};\n"
"  f(v);\n"
"}");
+  verifyFormat("void foo() {\n"
+   "  { // asdf\n"
+   "{ int a; }\n"
+   "  }\n"
+   "  {\n"
+   "{ int b; }\n"
+   "  }\n"
+   "}");
+  verifyFormat("namespace n {\n"
+   "void foo() {\n"
+   "  {\n"
+   "{\n"
+   "  statement();\n"
+   "  if (false) {\n"
+   "  }\n"
+   "}\n"
+   "  }\n"
+   "  {}\n"
+   "}\n"
+   "} // namespace n");
 
   // Long lists should be formatted in columns even if they are nested.
   verifyFormat(
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -492,6 +492,9 @@
   // update information about whether an lbrace starts a
   // braced init list or a different block during the loop.
   SmallVector LBraceStack;
+  // Track the previous token type corresponding to our lbraces // to help
+  // detect brace types
+  SmallVector PrevTokenKindStack;
   assert(Tok->is(tok::l_brace));
   do {
 // Get next non-comment token.
@@ -522,6 +525,8 @@
 Tok->setBlockKind(BK_Unknown);
   }
   LBraceStack.push_back(Tok);
+  PrevTokenKindStack.push_back(PrevTok ? PrevTok->Tok.getKind()
+   : tok::unknown);
   break;
 case tok::r_brace:
   if (LBraceStack.empty())
@@ -570,8 +575,13 @@
   ProbablyBracedList =
   ProbablyBracedList ||
   NextTok->isOneOf(tok::comma, tok::period, tok::colon,
-   tok::r_paren, tok::r_square, tok::l_brace,
-   tok::ellipsis);
+   tok::r_paren, tok::r_square, tok::ellipsis);
+
+  // Distinguish between braced list in a constructor initializer list
+  // followed by constructor body, or just adjacent blocks
+  ProbablyBracedList = ProbablyBracedList ||
+   NextTok->is(tok::l_brace) &&
+   PrevTokenKindStack.back() == 
tok::identifier;
 
   ProbablyBracedList =
   ProbablyBracedList ||
@@ -602,6 +612,7 @@
 }
   }
   LBraceStack.pop_back();
+  PrevTokenKindStack.pop_back();
   break;
 case tok::identifier:
   if (!Tok->is(TT_StatementMacro))


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13731,6 +13731,26 @@
"  struct Dummy {};\n"
"  f(v);\n"
"}");
+  verifyFormat("void foo() {\n"
+   "  { // asdf\n"
+   "{ int a; }\n"
+   "  }\n"
+   "  {\n"
+   "{ int b; }\n"
+   "  }\n"
+   "}");
+  verifyFormat("namespace n {\n"
+   "void foo() {\n"
+   "  {\n"
+   "{\n"
+   "  statement();\n"
+   "  if (false) {\n"
+  

[PATCH] D150340: [SEH]:Fix assertion when try is used inside catch(...) block with /EHa

2023-05-11 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGException.cpp:650
+llvm::FunctionCallee SehCppScope = getSehTryBeginFn(CGM);
+EmitSehScope(SehCppScope);
+  }

jyu2 wrote:
> efriedma wrote:
> > Do we need to make the same change in EmitSEHTryStmt/ExitSEHTryStmt?
> > 
> > Is there some reason not to just call EmitSehTryScopeBegin here?
> EmitSehTryScopeBegin:  it is emit seh.scope.begin
> 
> In here we want to emit seh.try.begin.  call EmitSehSCope with different 
> function.
> 
> For EmitSEHTryStmt/ExitSEHTryStmt if is for __try /__except/__finally and it 
> is for C code.  I thought about that.  And tried some test(BTW, try and __try 
> can not be in same construct), I don't see the problem.  So I did not add 
> that. 
Not sure I understand what you're saying about EmitSehTryScopeBegin.  
CGException.cpp:45 refers to "llvm.seh.try.begin".  CGCleanup.cpp:1370 also 
refers to "llvm.seh.try.begin"

For EmitSEHTryStmt/ExitSEHTryStmt, I guess __try codegen can't generate a 
construct quite like the given testcase, so thta's fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150340

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


[clang] 62c4c61 - Remove outdated sentence in SourceBasedCodeCoverage.rst

2023-05-11 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2023-05-11T17:17:57-04:00
New Revision: 62c4c614eea8078918d04cb33ce54ef8f9987766

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

LOG: Remove outdated sentence in SourceBasedCodeCoverage.rst

https://reviews.llvm.org/rGc5b94ea265133a4a28006929643155fc8fbeafe6 allows N >= 
10.

Added: 


Modified: 
clang/docs/SourceBasedCodeCoverage.rst

Removed: 




diff  --git a/clang/docs/SourceBasedCodeCoverage.rst 
b/clang/docs/SourceBasedCodeCoverage.rst
index d1d819bf0b69..710f9e9dba0a 100644
--- a/clang/docs/SourceBasedCodeCoverage.rst
+++ b/clang/docs/SourceBasedCodeCoverage.rst
@@ -86,9 +86,8 @@ directory structure will be created.  Additionally, the 
following special
   is specified, the runtime creates a pool of N raw profiles which are used for
   on-line profile merging. The runtime takes care of selecting a raw profile
   from the pool, locking it, and updating it before the program exits.  If N is
-  not specified (i.e the pattern is "%m"), it's assumed that ``N = 1``. N must
-  be between 1 and 9. The merge pool specifier can only occur once per filename
-  pattern.
+  not specified (i.e the pattern is "%m"), it's assumed that ``N = 1``. The 
+  merge pool specifier can only occur once per filename pattern.
 
 * "%c" expands out to nothing, but enables a mode in which profile counter
   updates are continuously synced to a file. This means that if the



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


[PATCH] D149800: [WIP][PGO] Add ability to mark cold functions as optsize/minsize/optnone

2023-05-11 Thread Hiroshi Yamauchi via Phabricator via cfe-commits
yamauchi added a comment.

In D149800#4330831 , @davidxl wrote:

> This patch uses a cleaner method than the previous effort. There is some 
> differences:
>
> 1. yamauchi's patch works for both iFDO and autoFDO, while this patch limits 
> to iFDO
> 2. yamauchi's patch also handles size optimization (IIRC) at granularity 
> smaller than function
>
> Longer term, the previous functionality should fold into the new framework.

IIRC 1) and 2) are correct. I don't have a strong preference on which folds 
into which.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149800

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


[PATCH] D150282: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-11 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added inline comments.



Comment at: clang/include/clang/Driver/Compilation.h:279
+  void addTimeTraceFile(const char *Name, const JobAction *JA) {
+TimeTraceFiles[JA] = Name;
+  }

MaskRay wrote:
> scott.linder wrote:
> > If this is overriding previous paths should it be called `setTimeTraceFile`?
> The naming is to match `add*File` above.
> Do you want an assert that the entry hasn't been inserted before?
If you think it is useful; otherwise consistency with the other options seems 
like a good enough reason



Comment at: clang/lib/Driver/Driver.cpp:5253
+Path = DumpDir->getValue();
+Path += llvm::sys::path::filename(BaseInput);
+  } else {

MaskRay wrote:
> scott.linder wrote:
> > Why `+=` instead of `append`? Do we just know the value of `dumpdir` is 
> > terminated with the path separator?
> `-dumpdir ` is a bit misnomer that it may or may not end with a path 
> separator.
> 
> `clang -c -ftime-trace d/a.c -o e/xa.o -dumpdir f/` is intended to create 
> `fa.json`
> 
> I updated a test and the description to give an example.
Thanks, I just forgot this point since the previous discussions! LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150282

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


[PATCH] D150013: [Clang] Respect `-L` options when compiling directly for AMDGPU

2023-05-11 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG027aeec7da67: [Clang] Respect `-L` options when compiling 
directly for AMDGPU (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150013

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/amdgpu-toolchain.c


Index: clang/test/Driver/amdgpu-toolchain.c
===
--- clang/test/Driver/amdgpu-toolchain.c
+++ clang/test/Driver/amdgpu-toolchain.c
@@ -11,6 +11,6 @@
 // DWARF_VER: "-dwarf-version=5"
 
 // RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
-// RUN:   -flto -fconvergent-functions %s 2>&1 | FileCheck -check-prefix=LTO %s
+// RUN:   -L. -flto -fconvergent-functions %s 2>&1 | FileCheck 
-check-prefix=LTO %s
 // LTO: clang{{.*}} "-flto=full"{{.*}}"-fconvergent-functions"
-// LTO: ld.lld{{.*}}-plugin-opt=mcpu=gfx906
+// LTO: ld.lld{{.*}}"-L."{{.*}}"-plugin-opt=mcpu=gfx906"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -232,9 +232,11 @@
   Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
 
   // LIBRARY_PATH are included before user inputs and only supported on native
-  // toolchains.
+  // toolchains. Otherwise only add the '-L' arguments requested by the user.
   if (!TC.isCrossCompiling())
 addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
+  else
+Args.AddAllArgs(CmdArgs, options::OPT_L);
 
   for (const auto &II : Inputs) {
 // If the current tool chain refers to an OpenMP offloading host, we


Index: clang/test/Driver/amdgpu-toolchain.c
===
--- clang/test/Driver/amdgpu-toolchain.c
+++ clang/test/Driver/amdgpu-toolchain.c
@@ -11,6 +11,6 @@
 // DWARF_VER: "-dwarf-version=5"
 
 // RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
-// RUN:   -flto -fconvergent-functions %s 2>&1 | FileCheck -check-prefix=LTO %s
+// RUN:   -L. -flto -fconvergent-functions %s 2>&1 | FileCheck -check-prefix=LTO %s
 // LTO: clang{{.*}} "-flto=full"{{.*}}"-fconvergent-functions"
-// LTO: ld.lld{{.*}}-plugin-opt=mcpu=gfx906
+// LTO: ld.lld{{.*}}"-L."{{.*}}"-plugin-opt=mcpu=gfx906"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -232,9 +232,11 @@
   Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
 
   // LIBRARY_PATH are included before user inputs and only supported on native
-  // toolchains.
+  // toolchains. Otherwise only add the '-L' arguments requested by the user.
   if (!TC.isCrossCompiling())
 addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
+  else
+Args.AddAllArgs(CmdArgs, options::OPT_L);
 
   for (const auto &II : Inputs) {
 // If the current tool chain refers to an OpenMP offloading host, we
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 027aeec - [Clang] Respect `-L` options when compiling directly for AMDGPU

2023-05-11 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-05-11T16:02:54-05:00
New Revision: 027aeec7da67afe33b159f5e42dec57488897454

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

LOG: [Clang] Respect `-L` options when compiling directly for AMDGPU

The AMDGPU linker is `lld`, which has full support for standard features
like static libraries. Previously the AMDGPU toolchain did not forward
`-L` arguments so we could not tell it where to find certain libraries.
This patch simply forwards it like the other toolchains.

Reviewed By: yaxunl, MaskRay

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/amdgpu-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index a6247b4cbe4ea..189c99e18572a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -232,9 +232,11 @@ void tools::AddLinkerInputs(const ToolChain &TC, const 
InputInfoList &Inputs,
   Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
 
   // LIBRARY_PATH are included before user inputs and only supported on native
-  // toolchains.
+  // toolchains. Otherwise only add the '-L' arguments requested by the user.
   if (!TC.isCrossCompiling())
 addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
+  else
+Args.AddAllArgs(CmdArgs, options::OPT_L);
 
   for (const auto &II : Inputs) {
 // If the current tool chain refers to an OpenMP offloading host, we

diff  --git a/clang/test/Driver/amdgpu-toolchain.c 
b/clang/test/Driver/amdgpu-toolchain.c
index b8b6667333d81..288dbbedd49d5 100644
--- a/clang/test/Driver/amdgpu-toolchain.c
+++ b/clang/test/Driver/amdgpu-toolchain.c
@@ -11,6 +11,6 @@
 // DWARF_VER: "-dwarf-version=5"
 
 // RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
-// RUN:   -flto -fconvergent-functions %s 2>&1 | FileCheck -check-prefix=LTO %s
+// RUN:   -L. -flto -fconvergent-functions %s 2>&1 | FileCheck 
-check-prefix=LTO %s
 // LTO: clang{{.*}} "-flto=full"{{.*}}"-fconvergent-functions"
-// LTO: ld.lld{{.*}}-plugin-opt=mcpu=gfx906
+// LTO: ld.lld{{.*}}"-L."{{.*}}"-plugin-opt=mcpu=gfx906"



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


[PATCH] D150340: [SEH]:Fix assertion when try is used inside catch(...) block with /EHa

2023-05-11 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGException.cpp:650
+llvm::FunctionCallee SehCppScope = getSehTryBeginFn(CGM);
+EmitSehScope(SehCppScope);
+  }

efriedma wrote:
> Do we need to make the same change in EmitSEHTryStmt/ExitSEHTryStmt?
> 
> Is there some reason not to just call EmitSehTryScopeBegin here?
EmitSehTryScopeBegin:  it is emit seh.scope.begin

In here we want to emit seh.try.begin.  call EmitSehSCope with different 
function.

For EmitSEHTryStmt/ExitSEHTryStmt if is for __try /__except/__finally and it is 
for C code.  I thought about that.  And tried some test(BTW, try and __try can 
not be in same construct), I don't see the problem.  So I did not add that. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150340

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


[PATCH] D150282: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D150282#4335568 , @scott.linder 
wrote:

> Does GCC have the same `-ftime-trace=` option? It seems like it doesn't, as 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92396 is still open?

You found it!

I am trying to collect other auxiliary output file features in Clang and add 
them to https://maskray.me/blog/2023-04-25-compiler-output-files

> If so, I am happy with unifying more of the dump/aux handling, and I imagine 
> when/if GCC adds the option it will behave similarly.

Thanks.




Comment at: clang/include/clang/Driver/Compilation.h:279
+  void addTimeTraceFile(const char *Name, const JobAction *JA) {
+TimeTraceFiles[JA] = Name;
+  }

scott.linder wrote:
> If this is overriding previous paths should it be called `setTimeTraceFile`?
The naming is to match `add*File` above.
Do you want an assert that the entry hasn't been inserted before?



Comment at: clang/lib/Driver/Driver.cpp:5253
+Path = DumpDir->getValue();
+Path += llvm::sys::path::filename(BaseInput);
+  } else {

scott.linder wrote:
> Why `+=` instead of `append`? Do we just know the value of `dumpdir` is 
> terminated with the path separator?
`-dumpdir ` is a bit misnomer that it may or may not end with a path separator.

`clang -c -ftime-trace d/a.c -o e/xa.o -dumpdir f/` is intended to create 
`fa.json`

I updated a test and the description to give an example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150282

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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-05-11 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:117
+
+.. option:: PrintFunction
+

Is `PrintFunction` (and the soon-to-arrive `PrintlnFunction`) distinct enough 
from `PrintfLikeFunctions` and `FprintfLikeFunctions`? Should I use 
`ReplacementPrintFunction` instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D150282: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 521427.
MaskRay marked an inline comment as done.
MaskRay edited the summary of this revision.
MaskRay added a comment.

add an assert to addTimeTraceFile.
improve a -dumpdir test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150282

Files:
  clang/include/clang/Driver/Compilation.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ftime-trace.cpp
  clang/tools/driver/cc1_main.cpp

Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -213,9 +213,7 @@
   bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(),
 Argv, Diags, Argv0);
 
-  if (Clang->getFrontendOpts().TimeTrace ||
-  !Clang->getFrontendOpts().TimeTracePath.empty()) {
-Clang->getFrontendOpts().TimeTrace = 1;
+  if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
 llvm::timeTraceProfilerInitialize(
 Clang->getFrontendOpts().TimeTraceGranularity, Argv0);
   }
@@ -257,16 +255,6 @@
   llvm::TimerGroup::clearAll();
 
   if (llvm::timeTraceProfilerEnabled()) {
-SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-llvm::sys::path::replace_extension(Path, "json");
-if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
-  // replace the suffix to '.json' directly
-  SmallString<128> TracePath(Clang->getFrontendOpts().TimeTracePath);
-  if (llvm::sys::fs::is_directory(TracePath))
-llvm::sys::path::append(TracePath, llvm::sys::path::filename(Path));
-  Path.assign(TracePath);
-}
-
 // It is possible that the compiler instance doesn't own a file manager here
 // if we're compiling a module unit. Since the file manager are owned by AST
 // when we're compiling a module unit. So the file manager may be invalid
@@ -280,7 +268,8 @@
   Clang->getInvocation(), Clang->getDiagnostics()));
 
 if (auto profilerOutput = Clang->createOutputFile(
-Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
+Clang->getFrontendOpts().TimeTracePath, /*Binary=*/false,
+/*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {
   llvm::timeTraceProfilerWrite(*profilerOutput);
   profilerOutput.reset();
Index: clang/test/Driver/ftime-trace.cpp
===
--- clang/test/Driver/ftime-trace.cpp
+++ clang/test/Driver/ftime-trace.cpp
@@ -31,6 +31,35 @@
 // CHECK:  "name": "process_name"
 // CHECK:  "name": "thread_name"
 
+// RUN: mkdir d e f && cp %s d/a.cpp && touch d/b.c
+
+// RUN: %clang -### -c -ftime-trace -ftime-trace-granularity=0 d/a.cpp -o e/a.o 2>&1 | FileCheck %s --check-prefix=COMPILE1
+// COMPILE1: -cc1{{.*}} "-ftime-trace=e/a.json" "-ftime-trace-granularity=0"
+
+// RUN: %clang -### -c -ftime-trace -ftime-trace-granularity=0 d/a.cpp d/b.c -dumpdir f/ 2>&1 | FileCheck %s --check-prefix=COMPILE2
+// COMPILE2: -cc1{{.*}} "-ftime-trace=f/a.json" "-ftime-trace-granularity=0"
+// COMPILE2: -cc1{{.*}} "-ftime-trace=f/b.json" "-ftime-trace-granularity=0"
+
+/// -o specifies the link output. Create ${output}-${basename}.json.
+// RUN: %clang -### -ftime-trace -ftime-trace-granularity=0 d/a.cpp d/b.c -o e/x 2>&1 | FileCheck %s --check-prefix=LINK1
+// LINK1: -cc1{{.*}} "-ftime-trace=e/x-a.json" "-ftime-trace-granularity=0"
+// LINK1: -cc1{{.*}} "-ftime-trace=e/x-b.json" "-ftime-trace-granularity=0"
+
+/// -dumpdir is f/g, not ending with a path separator. We create f/g${basename}.json.
+// RUN: %clang -### -ftime-trace -ftime-trace-granularity=0 d/a.cpp d/b.c -o e/x -dumpdir f/g 2>&1 | FileCheck %s --check-prefix=LINK2
+// LINK2: -cc1{{.*}} "-ftime-trace=f/ga.json" "-ftime-trace-granularity=0"
+// LINK2: -cc1{{.*}} "-ftime-trace=f/gb.json" "-ftime-trace-granularity=0"
+
+// RUN: %clang -### -ftime-trace=e -ftime-trace-granularity=0 d/a.cpp d/b.c -o f/x -dumpdir f/ 2>&1 | FileCheck %s --check-prefix=LINK3
+// LINK3: -cc1{{.*}} "-ftime-trace=e/a-{{[^.]*}}.json" "-ftime-trace-granularity=0"
+// LINK3: -cc1{{.*}} "-ftime-trace=e/b-{{[^.]*}}.json" "-ftime-trace-granularity=0"
+
+// RUN: %clang -### -ftime-trace -ftime-trace=e -ftime-trace-granularity=1 -xassembler d/a.cpp 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=UNUSED --implicit-check-not=warning:
+// UNUSED: warning: argument unused during compilation: '-ftime-trace'
+// UNUSED: warning: argument unused during compilation: '-ftime-trace=e'
+// UNUSED: warning: argument unused during compilation: '-ftime-trace-granularity=1'
+
 template 
 struct Struct {
   T Num;
Index: clang/lib/Driver/ToolChains/Clang.cpp

[PATCH] D150352: [clang][dataflow] Don't analyze templated declarations.

2023-05-11 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h:36
+  /// `S` resides. `D.isTemplated()` must be false.
+  static llvm::Expected build(const Decl &D, Stmt &S,
+  ASTContext &C);

Maybe this is too much for a drive-by fix, but since you are changing this API 
anyway, I have to ask - now that D is nonnull, isn't S strictly redundant? 
Isn't D always a FunctionDecl, and S its body?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150352

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


[PATCH] D150340: [SEH]:Fix assertion when try is used inside catch(...) block with /EHa

2023-05-11 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGException.cpp:650
+llvm::FunctionCallee SehCppScope = getSehTryBeginFn(CGM);
+EmitSehScope(SehCppScope);
+  }

Do we need to make the same change in EmitSEHTryStmt/ExitSEHTryStmt?

Is there some reason not to just call EmitSehTryScopeBegin here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150340

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


[PATCH] D150258: [clang][parser] Fix namespace dropping after malformed declarations

2023-05-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for working on this! FWIW, I verified that the precommit CI failures 
are unrelated to this patch.

Can you add a release note to `clang/docs/ReleaseNotes.rst` about the fix?




Comment at: clang/lib/Parse/ParseDecl.cpp:2179-2180
 
-if (isDeclarationSpecifier(ImplicitTypenameContext::No)) {
+if (isDeclarationSpecifier(ImplicitTypenameContext::No) ||
+Tok.is(tok::kw_namespace)) {
   // If there is an invalid declaration specifier right after the

It'd help to update the comment below since it doesn't mention why namespaces 
are handled specially.



Comment at: clang/lib/Parse/ParseDecl.cpp:2306-2310
 // Otherwise things are very confused and we skip to recover.
 if (!isDeclarationSpecifier(ImplicitTypenameContext::No)) {
-  SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
-  TryConsumeToken(tok::semi);
+  SkipMalformedDecl();
 }
   }

Changes for our coding style.

There seems to be some unfortunate interplay here though. Consider:
```
void bar() namespace foo { int i; }

int main() {
  foo::i = 12;
}
```
Calling `SkipMalformedDecl()` changes the behavior for this test case because 
we don't recover as well. With your patch applied, this gives us two 
diagnostics:
```
C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp:1:11: error: 
expected ';' after top level declarator
void bar() namespace foo { int i; }
  ^
  ;
C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp:4:3: error: use 
of undeclared identifier 'foo'
  foo::i = 12;
  ^
2 errors generated.
```
If the `namespace` keyword is on its own line, then we recover gracefully and 
don't emit the "use of undeclared identifier" warning.

While this is technically a regression in behavior for this test case, I think 
the overall changes are still an improvement. I suspect not a whole lot of code 
puts `namespace` somewhere other than the start of a line (same for `inline 
namespace` which has the same behavior with your patch).



Comment at: clang/lib/Parse/ParseTemplate.cpp:278
   if (!DeclaratorInfo.hasName()) {
-// If so, skip until the semi-colon or a }.
-SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
-if (Tok.is(tok::semi))
-  ConsumeToken();
+SkipMalformedDecl();
 return nullptr;

We'll have the same sort of recovery issues here unless the namespace is on its 
own line, but that also seems like a highly unlikely scenario.



Comment at: clang/test/Parser/cxx-namespace-after-missing-semicolon.cpp:1
+// RUN: %clang_cc1 -verify %s
+





Comment at: clang/test/Parser/cxx-template-recovery.cpp:1
+// RUN: %clang_cc1 -verify %s
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150258

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


[PATCH] D146342: [-Wunsafe-buffer-usage] Move the whole analysis to the end of a translation unit

2023-05-11 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 521409.
ziqingluo-90 added a comment.

Address comments:   refactor the callable-definition visitor to take a lambda 
Callback, who calls various analyses that need whole-TU information.If one 
needs to add a new such analysis later,  just add a call in the Callback 
function.


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

https://reviews.llvm.org/D146342

Files:
  clang/include/clang/Sema/AnalysisBasedWarnings.h
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
@@ -220,11 +220,11 @@
 void testTemplate(int * p) {
   int *a[10];
   foo(f(p, &p, a, a)[1]); // expected-warning{{unsafe buffer access}}
-  // expected-note@-1{{in instantiation of function template specialization 'f' requested here}}
+  // FIXME: expected note@-1{{in instantiation of function template specialization 'f' requested here}}
 
   const int **q = const_cast(&p);
 
-  testPointerArithmetic(p, q, p); //expected-note{{in instantiation of}}
+  testPointerArithmetic(p, q, p); //FIXME: expected note{{in instantiation of}}
 }
 
 void testPointerToMember() {
@@ -315,7 +315,7 @@
   foo(ar[5]);   // expected-note{{used in buffer access here}}
 }
 
-template void fArr(int t[]); // expected-note {{in instantiation of}}
+template void fArr(int t[]); // FIXME: expected note {{in instantiation of}}
 
 int testReturn(int t[]) {
   // expected-warning@-1{{'t' is an unsafe pointer used for buffer access}}
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1426,6 +1426,8 @@
 }
   }
 
+  AnalysisWarnings.IssueWarnings(Context.getTranslationUnitDecl());
+
   // Check we've noticed that we're no longer parsing the initializer for every
   // variable. If we miss cases, then at best we have a performance issue and
   // at worst a rejects-valid bug.
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "clang/Sema/AnalysisBasedWarnings.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/EvaluatedExprVisitor.h"
@@ -25,6 +26,8 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
 #include "clang/Analysis/Analyses/CalledOnceCheck.h"
 #include "clang/Analysis/Analyses/Consumed.h"
@@ -35,6 +38,7 @@
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CFGStmtMap.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Preprocessor.h"
@@ -43,6 +47,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -2290,6 +2295,88 @@
 S.Diag(D.Loc, D.PD);
 }
 
+// An AST Visitor that calls a callback function on each callable DEFINITION
+// that is NOT in a dependent context:
+class CallableVisitor : public RecursiveASTVisitor {
+private:
+  llvm::function_ref Callback;
+
+public:
+  CallableVisitor(llvm::function_ref Callback)
+  : Callback(Callback) {}
+
+  bool VisitFunctionDecl(FunctionDecl *Node) {
+if (cast(Node)->isDependentContext())
+  return true; // Not to analyze dependent decl
+// `FunctionDecl->hasBody()` returns true if the function has a body
+// somewhere defined.  But we want to know if this `Node` has a body
+// child.  So we use `doesThisDeclarationHaveABody`:
+if (Node->doesThisDeclarationHaveABody())
+  Callback(Node);
+return true;
+  }
+
+  bool VisitBlockDecl(BlockDecl *Node) {
+if (cast(Node)->isDependentContext())
+  return true; // Not to analyze dependent decl
+Callback(Node);
+return true;
+  }
+
+  bool VisitObjCMethodDecl(ObjCMethodDecl *Node) {
+if (cast(Node)->isDependentContext())
+  return true; // Not to analyze dependent decl
+if (Node->hasBody())
+  Callback(Node);
+return true;
+  }
+
+  bool VisitLambdaExpr(LambdaExpr *Node) {
+return VisitFunctionDecl(Node->getCallOperator());
+  }
+
+  bool shouldVisitTem

[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-05-11 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 521406.
void added a comment.

Use strings for the attribute argument.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -61,6 +61,7 @@
 // CHECK-NEXT: DiagnoseAsBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: DisableSanitizerInstrumentation (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: DisableTailCalls (SubjectMatchRule_function, SubjectMatchRule_objc_method)
+// CHECK-NEXT: ElementCount (SubjectMatchRule_field)
 // CHECK-NEXT: EnableIf (SubjectMatchRule_function)
 // CHECK-NEXT: EnforceTCB (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: EnforceTCBLeaf (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8238,6 +8238,29 @@
   D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
 }
 
+static void handleElementCountAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  // TODO: Probably needs more processing here. See Sema::AddAlignValueAttr.
+  SmallVector Names;
+  SmallVector Ranges;
+
+  for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
+StringRef Field;
+SourceLocation FieldLoc;
+
+if (!S.checkStringLiteralArgumentAttr(AL, I, Field, &FieldLoc))
+  return;
+
+Names.push_back(Field);
+Ranges.push_back(FieldLoc);
+  }
+
+  ElementCountAttr *ECA = ::new (S.Context) ElementCountAttr(S.Context, AL,
+ Names.data(),
+ Names.size());
+  ECA->addCountFieldSourceRange(Ranges);
+  D->addAttr(ECA);
+}
+
 static void handleFunctionReturnThunksAttr(Sema &S, Decl *D,
const ParsedAttr &AL) {
   StringRef KindStr;
@@ -9136,6 +9159,9 @@
   case ParsedAttr::AT_FunctionReturnThunks:
 handleFunctionReturnThunksAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ElementCount:
+handleElementCountAttr(S, D, AL);
+break;
 
   // Microsoft attributes:
   case ParsedAttr::AT_LayoutVersion:
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -17692,6 +17692,44 @@
  "Broken injected-class-name");
 }
 
+static const FieldDecl *FindFieldWithElementCountAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D))
+  if (FD->hasAttr())
+return FD;
+
+if (const auto *SubRD = dyn_cast(D))
+  if (const FieldDecl *FD = FindFieldWithElementCountAttr(SubRD))
+return FD;
+  }
+
+  return nullptr;
+}
+
+static StringRef
+CheckElementCountAttr(const RecordDecl *RD, const FieldDecl *FD,
+  SourceRange &Loc) {
+  const ElementCountAttr *ECA = FD->getAttr();
+  unsigned Idx = 0;
+
+  for (StringRef Field : ECA->elementCountFields()) {
+Loc = ECA->getCountFieldSourceRange(Idx++);
+
+auto DeclIter = llvm::find_if(
+RD->fields(), [&](const FieldDecl *FD){
+  return Field == FD->getName();
+});
+
+if (DeclIter == RD->field_end())
+  return Field;
+
+if (auto *SubRD = DeclIter->getType()->getAsRecordDecl())
+  RD = SubRD;
+  }
+
+  return StringRef();
+}
+
 void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD,
 SourceRange BraceRange) {
   AdjustDeclIfTemplate(TagD);
@@ -17749,6 +17787,19 @@
  [](const FieldDecl *FD) { return FD->isBitField(); }))
   Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible);
   }
+
+  // Check the "element_count" attribute to ensure that the count field exists
+  // in the struct.
+  if (const RecordDecl *RD = dyn_cast(Tag)) {
+if (const FieldDecl *FD = FindFieldWithElementCountAttr(RD)) {
+  SourceRange SR;
+  StringRef Unknown = CheckElementCountAttr(RD, FD, SR);
+
+  if (!Unknown.empty())
+Diag(SR.getBegin(), diag::warn_element_count_placeholder)
+<< Unknown << SR;
+}
+  }
 }
 
 void Sema::ActOnObjCContainerFinishDefinition() {
Index: 

[PATCH] D150321: [clang] Document extensions from later standards

2023-05-11 Thread Nikolas Klauser via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
philnik marked an inline comment as done.
Closed by commit rGb09fad7f8e9c: [clang] Document extensions from later 
standards (authored by philnik).

Changed prior to commit:
  https://reviews.llvm.org/D150321?vs=521375&id=521402#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150321

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1370,6 +1370,41 @@
 
 More information could be found `here 
`_.
 
+Language Extensions Back-ported to Previous Standards
+=
+
+===  
= = ==
+Feature Feature Test Macro   
Introduced In Backported To Required Flags
+===  
= = ==
+variadic templates  __cpp_variadic_templates C++11 
C++03
+Alias templates __cpp_alias_templatesC++11 
C++03
+Non-static data member initializers __cpp_nsdmi  C++11 
C++03
+Range-based ``for`` loop__cpp_range_based_forC++11 
C++03
+RValue references   __cpp_rvalue_references  C++11 
C++03
+Attributes  __cpp_attributes C++11 
C++03 -fdouble-square-bracket-attributes
+variable templates  __cpp_variable_templates C++14 
C++03
+Binary literals __cpp_binary_literalsC++14 
C++03
+Relaxed constexpr   __cpp_constexpr  C++14 
C++11
+``if constexpr``__cpp_if_constexpr   C++17 
C++11
+fold expressions__cpp_fold_expressions   C++17 
C++03
+Lambda capture of \*this by value   __cpp_capture_star_this  C++17 
C++11
+Attributes on enums __cpp_enumerator_attributes  C++17 
C++11
+Guaranteed copy elision __cpp_guaranteed_copy_elisionC++17 
C++03
+Hexadecimal floating literals   __cpp_hex_float  C++17 
C++03
+``inline`` variables__cpp_inline_variables   C++17 
C++03
+Attributes on namespaces__cpp_namespace_attributes   C++17 
C++11
+Structured bindings __cpp_structured_bindingsC++17 
C++03
+template template arguments __cpp_template_template_args C++17 
C++03
+``static operator[]``   __cpp_multidimensional_subscript C++20 
C++03
+Designated initializers __cpp_designated_initializersC++20 
C++03
+Conditional ``explicit``__cpp_conditional_explicit   C++20 
C++03
+``using enum``  __cpp_using_enum C++20 
C++03
+``if consteval``__cpp_if_consteval   C++23 
C++20
+``static operator()``   __cpp_static_call_operator   C++23 
C++03
+---  
- - --
+Designated initializers  C99   
C89
+===  
= = ==
+
 Type Trait Primitives
 =
 


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1370,6 +1370,41 @@
 
 More information could be found `here `_.
 
+Language Extensions Back-ported to Previous Standards
+=
+
+===  = = ==
+Feature Feature Test Macro   Introduced In Backported To Required Flags
+===  = = ==
+variadic templates  __cpp_variadic_templates C++11 C++03
+Alias templates __cpp_alias_temp

[clang] b09fad7 - [clang] Document extensions from later standards

2023-05-11 Thread Nikolas Klauser via cfe-commits

Author: Nikolas Klauser
Date: 2023-05-11T11:54:46-07:00
New Revision: b09fad7f8e9ce5b88fb467be012ea379efa3659d

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

LOG: [clang] Document extensions from later standards

Reviewed By: aaron.ballman

Spies: H-G-Hristov, cfe-commits

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index ddd366b637e59..64ed3ae6ab907 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1370,6 +1370,41 @@ For example, compiling code with ``-fmodules`` enables 
the use of Modules.
 
 More information could be found `here 
`_.
 
+Language Extensions Back-ported to Previous Standards
+=
+
+===  
= = ==
+Feature Feature Test Macro   
Introduced In Backported To Required Flags
+===  
= = ==
+variadic templates  __cpp_variadic_templates C++11 
C++03
+Alias templates __cpp_alias_templatesC++11 
C++03
+Non-static data member initializers __cpp_nsdmi  C++11 
C++03
+Range-based ``for`` loop__cpp_range_based_forC++11 
C++03
+RValue references   __cpp_rvalue_references  C++11 
C++03
+Attributes  __cpp_attributes C++11 
C++03 -fdouble-square-bracket-attributes
+variable templates  __cpp_variable_templates C++14 
C++03
+Binary literals __cpp_binary_literalsC++14 
C++03
+Relaxed constexpr   __cpp_constexpr  C++14 
C++11
+``if constexpr``__cpp_if_constexpr   C++17 
C++11
+fold expressions__cpp_fold_expressions   C++17 
C++03
+Lambda capture of \*this by value   __cpp_capture_star_this  C++17 
C++11
+Attributes on enums __cpp_enumerator_attributes  C++17 
C++11
+Guaranteed copy elision __cpp_guaranteed_copy_elisionC++17 
C++03
+Hexadecimal floating literals   __cpp_hex_float  C++17 
C++03
+``inline`` variables__cpp_inline_variables   C++17 
C++03
+Attributes on namespaces__cpp_namespace_attributes   C++17 
C++11
+Structured bindings __cpp_structured_bindingsC++17 
C++03
+template template arguments __cpp_template_template_args C++17 
C++03
+``static operator[]``   __cpp_multidimensional_subscript C++20 
C++03
+Designated initializers __cpp_designated_initializersC++20 
C++03
+Conditional ``explicit``__cpp_conditional_explicit   C++20 
C++03
+``using enum``  __cpp_using_enum C++20 
C++03
+``if consteval``__cpp_if_consteval   C++23 
C++20
+``static operator()``   __cpp_static_call_operator   C++23 
C++03
+---  
- - --
+Designated initializers  C99   
C89
+===  
= = ==
+
 Type Trait Primitives
 =
 



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


[PATCH] D145343: [AMDGPU] Emit predefined macro `__AMDGCN_CUMODE__`

2023-05-11 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 521396.
yaxunl retitled this revision from "[AMDGPU] Emit predefined macro 
`__AMDGCN_CUMODE`" to "[AMDGPU] Emit predefined macro `__AMDGCN_CUMODE__`".
yaxunl edited the summary of this revision.
yaxunl added a comment.

rename the macro to be consistent with most existing predefined macros for 
amdgcn target


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

https://reviews.llvm.org/D145343

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/Hexagon.h
  clang/test/CodeGenHIP/hip-cumode.hip
  clang/test/Driver/amdgpu-macros.cl
  clang/test/Driver/hip-macros.hip
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/TargetParser/TargetParser.cpp

Index: llvm/lib/TargetParser/TargetParser.cpp
===
--- llvm/lib/TargetParser/TargetParser.cpp
+++ llvm/lib/TargetParser/TargetParser.cpp
@@ -107,21 +107,21 @@
   {{"gfx940"},{"gfx940"},  GK_GFX940,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
   {{"gfx941"},{"gfx941"},  GK_GFX941,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
   {{"gfx942"},{"gfx942"},  GK_GFX942,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
-  {{"gfx1010"},   {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK},
-  {{"gfx1011"},   {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK},
-  {{"gfx1012"},   {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK},
-  {{"gfx1013"},   {"gfx1013"}, GK_GFX1013, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK},
-  {{"gfx1030"},   {"gfx1030"}, GK_GFX1030, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1031"},   {"gfx1031"}, GK_GFX1031, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1032"},   {"gfx1032"}, GK_GFX1032, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1033"},   {"gfx1033"}, GK_GFX1033, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1034"},   {"gfx1034"}, GK_GFX1034, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1035"},   {"gfx1035"}, GK_GFX1035, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1036"},   {"gfx1036"}, GK_GFX1036, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1100"},   {"gfx1100"}, GK_GFX1100, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1101"},   {"gfx1101"}, GK_GFX1101, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1102"},   {"gfx1102"}, GK_GFX1102, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1103"},   {"gfx1103"}, GK_GFX1103, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
+  {{"gfx1010"},   {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
+  {{"gfx1011"},   {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
+  {{"gfx1012"},   {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
+  {{"gfx1013"},   {"gfx1013"}, GK_GFX1013, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
+  {{"gfx1030"},   {"gfx1030"}, GK_GFX1030, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1031"},   {"gfx1031"}, GK_GFX1031, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1032"},   {"gfx1032"}, GK_GFX1032, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1033"},   {"gfx1033"}, GK_GFX1033, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1034"},   {"gfx1034"}, GK_GFX1034, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1035"},   {"gfx1035"}, GK_GFX1035, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1036"},   {"gfx1036"}, GK_GFX1036, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1100"},   {"gfx1100"}, GK_GFX1100, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1101"},   {"gfx1101"}, GK_GFX1101, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1102"},   {"gfx1102"}, G

[PATCH] D150321: [clang] Document extensions from later standards

2023-05-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, this is awesome -- thank you for the improved docs!




Comment at: clang/docs/LanguageExtensions.rst:1373
 
+Language extensions back-ported to previous standards
+=

Seems to be the style we're using for this level of heading.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150321

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


[PATCH] D149986: AMDGPU: Force sc0 and sc1 on stores for gfx940 and gfx941

2023-05-11 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp:517-529
+  bool tryForceStoreSC0SC1(const SIMemOpInfo &MOI,
+   MachineBasicBlock::iterator &MI) const override {
+if (ST.hasForceStoreSC0SC1() &&
+(MOI.getInstrAddrSpace() & (SIAtomicAddrSpace::SCRATCH |
+SIAtomicAddrSpace::GLOBAL |
+SIAtomicAddrSpace::OTHER)) !=
+ SIAtomicAddrSpace::NONE) {

It may be a bit more verbose, but I would suggest just having a `bool Changed` 
variable, like other (admittedly more complicated) functions in the unit do. I 
don't think any future maintainer will mis-interpret this, even without the 
comment


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

https://reviews.llvm.org/D149986

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


[PATCH] D149158: [clang][analyzer] Cleanup tests of StdCLibraryFunctionsChecker (NFC)

2023-05-11 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

LGTM, premerge checks are green AFAICT. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149158

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


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-11 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D147844#4329497 , @aaron.ballman 
wrote:

> In general, I think this is incremental progress on the diagnostic behavior. 
> However, it's clear that there is room for interpretation on what is or is 
> not a false positive diagnostic for this,

I hope we can agree on what a false positive is here - when the warning fires 
but the code is what the developer intended (ie: the existing code with the 
existing language semantics produce the desired result, the "fix" is to add 
parentheses that explicitly encode the language's existing rules/behavior 
anyway).

Not that we don't have warnings that do this - that encourage parens to 
reinforce what the language already does to be more explicit/intentional about 
it, and in some cases it's not that uncommon that the user will be adding 
parens that reinforce the precedence rules anyway.

Like, I think all the fixes in libc++, llvm, etc, are false positives? (none of 
them found bugs/unintended behavior) Are there any examples of bugs being found 
by this warning in a codebase? (& how many false positives in such a codebase 
did it also flag?)

> so we should pay close attention to user feedback during the 17.x release 
> cycle. If it seems we're getting significant push back, we may need to come 
> back and rethink.
>
> Specifically, I think we've improved the situation for code like this:
>
>   // `p` is a pointer, `x` is an `int`, and `b` is a `bool`
>   p + x ? 1 : 2; // previously didn't warn, now warns
>   p + b ? 1 : 2; // always warned
>
> Does anyone feel we should not move forward with accepting the patch in its 
> current form?

*goes to look*

Mixed feelings - you're right, incremental improvement/adding missed cases to 
an existing warning (especially if that warning's already stylistic in nature) 
is a lower bar/doesn't necessarily need the false positive assessment. But it 
looks like this case might've been intentionally suppressed in the initial 
warning implementation? (anyone linked to the original warning 
implementation/review/design to check if this was intentional?)

But, yeah, seems marginal enough I don't have strong feelings either way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

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


[PATCH] D150139: [clang-repl] Enable basic multiline support.

2023-05-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang/test/Interpreter/multiline.cpp:12-17
+void f(int x) \ 
+{   \
+  printf("x=\
+  %d", x); \
+}
+f(i);

v.g.vassilev wrote:
> aaron.ballman wrote:
> > Another fun test case:
> > ```
> > // Requires -ftrigraphs but the following line ends with a backslash 
> > (surprise!)
> > i=??/
> >   12;
> > ```
> Yes, the implementation of the multiline support here is actually rather 
> rudimentary. It intentionally does not include deeper language understanding 
> but provides a way for the users typing "well-behaved" code to tell 
> clang-repl that more is coming before it could compile it. In theory we could 
> check for the `??/` trigraph and do the same but I don't think that would be 
> used people use clang-repl on things like IBM 3270 terminals which seem not 
> to have some characters and trigraphs could help there ;) 
> 
> Our full-fledged solution is described here 
> https://discourse.llvm.org/t/rfc-flexible-lexer-buffering-for-handling-incomplete-input-in-interactive-c-c/64180/9
> 
> Until that lands we can have this to unblock work on things like OpenMP 
> support.
Okay, that's reasonable enough for the initial commit. Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D150139

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


[PATCH] D149642: [RISCV] Support vreinterpret intrinsics between vector boolean type and m1 vector integer type

2023-05-11 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:2042
+
+  SmallVector Operands;
+  if (ResultType->isIntOrIntVectorTy(1)) {

This SmallVector is unused


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149642

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


[PATCH] D150282: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-11 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Does GCC have the same `-ftime-trace=` option? It seems like it doesn't, as 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92396 is still open?

If so, I am happy with unifying more of the dump/aux handling, and I imagine 
when/if GCC adds the option it will behave similarly.




Comment at: clang/include/clang/Driver/Compilation.h:279
+  void addTimeTraceFile(const char *Name, const JobAction *JA) {
+TimeTraceFiles[JA] = Name;
+  }

If this is overriding previous paths should it be called `setTimeTraceFile`?



Comment at: clang/lib/Driver/Driver.cpp:5253
+Path = DumpDir->getValue();
+Path += llvm::sys::path::filename(BaseInput);
+  } else {

Why `+=` instead of `append`? Do we just know the value of `dumpdir` is 
terminated with the path separator?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150282

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


[PATCH] D150282: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 521379.
MaskRay marked an inline comment as done.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Add a warning test. Report -Wunused-command-line-argument warning for 
-ftime-trace-granularity=0 if unused as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150282

Files:
  clang/include/clang/Driver/Compilation.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ftime-trace.cpp
  clang/tools/driver/cc1_main.cpp

Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -213,9 +213,7 @@
   bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(),
 Argv, Diags, Argv0);
 
-  if (Clang->getFrontendOpts().TimeTrace ||
-  !Clang->getFrontendOpts().TimeTracePath.empty()) {
-Clang->getFrontendOpts().TimeTrace = 1;
+  if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
 llvm::timeTraceProfilerInitialize(
 Clang->getFrontendOpts().TimeTraceGranularity, Argv0);
   }
@@ -257,16 +255,6 @@
   llvm::TimerGroup::clearAll();
 
   if (llvm::timeTraceProfilerEnabled()) {
-SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-llvm::sys::path::replace_extension(Path, "json");
-if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
-  // replace the suffix to '.json' directly
-  SmallString<128> TracePath(Clang->getFrontendOpts().TimeTracePath);
-  if (llvm::sys::fs::is_directory(TracePath))
-llvm::sys::path::append(TracePath, llvm::sys::path::filename(Path));
-  Path.assign(TracePath);
-}
-
 // It is possible that the compiler instance doesn't own a file manager here
 // if we're compiling a module unit. Since the file manager are owned by AST
 // when we're compiling a module unit. So the file manager may be invalid
@@ -280,7 +268,8 @@
   Clang->getInvocation(), Clang->getDiagnostics()));
 
 if (auto profilerOutput = Clang->createOutputFile(
-Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
+Clang->getFrontendOpts().TimeTracePath, /*Binary=*/false,
+/*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {
   llvm::timeTraceProfilerWrite(*profilerOutput);
   profilerOutput.reset();
Index: clang/test/Driver/ftime-trace.cpp
===
--- clang/test/Driver/ftime-trace.cpp
+++ clang/test/Driver/ftime-trace.cpp
@@ -31,6 +31,31 @@
 // CHECK:  "name": "process_name"
 // CHECK:  "name": "thread_name"
 
+// RUN: mkdir d e f && cp %s d/a.cpp && touch d/b.c
+
+// RUN: %clang -### -c -ftime-trace -ftime-trace-granularity=0 d/a.cpp -o e/a.o 2>&1 | FileCheck %s --check-prefix=COMPILE1
+// COMPILE1: -cc1{{.*}} "-ftime-trace=e/a.json"
+
+// RUN: %clang -### -c -ftime-trace -ftime-trace-granularity=0 d/a.cpp d/b.c -dumpdir f/ 2>&1 | FileCheck %s --check-prefix=COMPILE2
+// COMPILE2: -cc1{{.*}} "-ftime-trace=f/a.json"
+// COMPILE2: -cc1{{.*}} "-ftime-trace=f/b.json"
+
+// RUN: %clang -### -ftime-trace -ftime-trace-granularity=0 d/a.cpp d/b.c -o e/x 2>&1 | FileCheck %s --check-prefix=LINK1
+// LINK1: -cc1{{.*}} "-ftime-trace=e/x-a.json"
+// LINK1: -cc1{{.*}} "-ftime-trace=e/x-b.json"
+
+// RUN: %clang -### -ftime-trace -ftime-trace-granularity=0 d/a.cpp d/b.c -o e/x -dumpdir f/ 2>&1 | FileCheck %s --check-prefix=LINK2
+// LINK2: -cc1{{.*}} "-ftime-trace=f/a.json"
+// LINK2: -cc1{{.*}} "-ftime-trace=f/b.json"
+
+// RUN: %clang -### -ftime-trace=e -ftime-trace-granularity=0 d/a.cpp d/b.c -o f/x -dumpdir f/ 2>&1 | FileCheck %s --check-prefix=LINK3
+// LINK3: -cc1{{.*}} "-ftime-trace=e/a-{{[^.]*}}.json"
+// LINK3: -cc1{{.*}} "-ftime-trace=e/b-{{[^.]*}}.json"
+
+// RUN: %clang -### -ftime-trace=e -ftime-trace-granularity=1 -xassembler d/a.cpp 2>&1 | FileCheck %s --check-prefix=UNUSED
+// UNUSED: warning: argument unused during compilation: '-ftime-trace=e'
+// UNUSED: warning: argument unused during compilation: '-ftime-trace-granularity=1'
+
 template 
 struct Struct {
   T Num;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6344,13 +6344,15 @@
   Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
-  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
-  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
-  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_EQ);
 

[PATCH] D150191: [clang][Diagnostics] Provide a source range for 'use of undeclared identifier' diagnostics

2023-05-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:2187
 else
-  SemaRef.Diag(TypoLoc, DiagnosticID) << Typo;
+  SemaRef.Diag(TypoRange.getEnd(), DiagnosticID) << Typo;
 return;

tbaeder wrote:
> I'm not passing the `TypoRange` here now, which regresses the test case I 
> posted. Apparently the handling of `-fmacro-backtrace-limit` depends on the 
> range passed here? That seems weird.
Is it failing within `checkRangesForMacroArgExpansion()` in 
DiagnosticRenderer.cpp? It looks like this change effectively undoes the work 
from ecd36ee80b7a6ac73c84da19f8a75c4c025a7625



Comment at: clang/test/Misc/reduced-diags-macros-backtrace.cpp:30-38
+// ALL-NEXT: {{.*}}:6:20: note: expanded from macro 'ADD'
+// ALL-NEXT: #define ADD(x,y) G(x) + y
+// ALL-NEXT:^
+// ALL-NEXT: {{.*}}:5:16: note: expanded from macro 'G'
+// ALL-NEXT: #define G(x) F(x) + 2
+// ALL-NEXT:^
+// ALL-NEXT: {{.*}}:4:14: note: expanded from macro 'F'

These notes make it harder to read the diagnostic instead of easier, I think 
they should remain suppressed.



Comment at: clang/test/Misc/reduced-diags-macros-backtrace.cpp:42-56
+// ALL-NEXT: {{.*}}:10:26: note: expanded from macro 'LEVEL1'
+// ALL-NEXT: #define LEVEL1(x) LEVEL2(x)
+// ALL-NEXT:  ^
+// ALL-NEXT: {{.*}}:9:26: note: expanded from macro 'LEVEL2'
+// ALL-NEXT: #define LEVEL2(x) LEVEL3(x)
+// ALL-NEXT:  ^
+// ALL-NEXT: {{.*}}:8:26: note: expanded from macro 'LEVEL3'

Same here.


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

https://reviews.llvm.org/D150191

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


[PATCH] D150321: [clang] Document extensions from later standards

2023-05-11 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 521375.
philnik marked 5 inline comments as done.
philnik added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150321

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1370,6 +1370,41 @@
 
 More information could be found `here 
`_.
 
+Language extensions back-ported to previous standards
+=
+
+===  
= = ==
+Feature Feature Test Macro   
Introduced In Backported To Required Flags
+===  
= = ==
+variadic templates  __cpp_variadic_templates C++11 
C++03
+Alias templates __cpp_alias_templatesC++11 
C++03
+Non-static data member initializers __cpp_nsdmi  C++11 
C++03
+Range-based ``for`` loop__cpp_range_based_forC++11 
C++03
+RValue references   __cpp_rvalue_references  C++11 
C++03
+Attributes  __cpp_attributes C++11 
C++03 -fdouble-square-bracket-attributes
+variable templates  __cpp_variable_templates C++14 
C++03
+Binary literals __cpp_binary_literalsC++14 
C++03
+Relaxed constexpr   __cpp_constexpr  C++14 
C++11
+``if constexpr``__cpp_if_constexpr   C++17 
C++11
+fold expressions__cpp_fold_expressions   C++17 
C++03
+Lambda capture of \*this by value   __cpp_capture_star_this  C++17 
C++11
+Attributes on enums __cpp_enumerator_attributes  C++17 
C++11
+Guaranteed copy elision __cpp_guaranteed_copy_elisionC++17 
C++03
+Hexadecimal floating literals   __cpp_hex_float  C++17 
C++03
+``inline`` variables__cpp_inline_variables   C++17 
C++03
+Attributes on namespaces__cpp_namespace_attributes   C++17 
C++11
+Structured bindings __cpp_structured_bindingsC++17 
C++03
+template template arguments __cpp_template_template_args C++17 
C++03
+``static operator[]``   __cpp_multidimensional_subscript C++20 
C++03
+Designated initializers __cpp_designated_initializersC++20 
C++03
+Conditional ``explicit``__cpp_conditional_explicit   C++20 
C++03
+``using enum``  __cpp_using_enum C++20 
C++03
+``if consteval``__cpp_if_consteval   C++23 
C++20
+``static operator()``   __cpp_static_call_operator   C++23 
C++03
+---  
- - --
+Designated initializers  C99   
C89
+===  
= = ==
+
 Type Trait Primitives
 =
 


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1370,6 +1370,41 @@
 
 More information could be found `here `_.
 
+Language extensions back-ported to previous standards
+=
+
+===  = = ==
+Feature Feature Test Macro   Introduced In Backported To Required Flags
+===  = = ==
+variadic templates  __cpp_variadic_templates C++11 C++03
+Alias templates __cpp_alias_templatesC++11 C++03
+Non-static data member initializers __cpp_nsdmi  C++11 C++03
+Range-based ``for`` loop__cpp_range_based_forC++11 C++03
+RValue refere

[PATCH] D150282: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added a comment.

In D150282#4334927 , @Maetveis wrote:

> LGTM, but I don't feel like I have the experience to "formally" approve. I 
> left a nice-to have suggestion too, but feel free to ignore, if you feel its 
> out of scope.

Thanks. You can certainly give your review opinion as you've studied and 
discussed the feature a lot! 
(https://llvm.org/docs/Phabricator.html#:~:text=participated%20might)
If we land a change like this patch, D133662  
can be turned to address the offloading side issue.

It doesn't work without or with this patch; there is only one single JSON 
output file.
I think supporting offloading will make some extensive changes to 
`GetNamedOutputPath`, so I avoid doing that in this patch.
I am not an offloading user and don't understand its behavior well enough.




Comment at: clang/lib/Driver/Driver.cpp:5514
BaseInput);
+handleTimeTrace(C, Args, JA, BaseInput, Result);
   }

Maetveis wrote:
> One thing D133662 had that this change doesn't is that `--ftime-trace` was 
> reported as unused when there was no job that invoked clang (e.g. if using 
> the driver to link object files only).
> 
> I am not sure its worth the effort, but it would be nice. IIRC in D133662 I 
> did this by having a method (`supportsTimeTrace`) on Tools to query support.
> 
> I can also do this if you feel its out of scope here, and if there's no 
> objection to it.
Thanks! This is a worthy change. I'll add a test separately.
I think we can reuse `canEmitIR` instead of adding `supportsTimeTrace`.

Another frontend flang-new defines `canEmitIR` to true as well. It's a 
work-in-progress and can support `-ftime-trace` later.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150282

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


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-05-11 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a added a subscriber: efriedma.
bolshakov-a added inline comments.



Comment at: clang/lib/AST/ItaniumMangle.cpp:4397
+// argument.
+// As proposed in https://github.com/itanium-cxx-abi/cxx-abi/issues/111.
+auto *SNTTPE = cast(E);

erichkeane wrote:
> erichkeane wrote:
> > aaron.ballman wrote:
> > > We should get this nailed down. It was proposed in Nov 2020 and the issue 
> > > is still open. CC @rjmccall 
> > This definitely needs to happen.  @rjmccall or @eli.friedman ^^ Any idea 
> > what the actual mangling should be?
> This is still an open, and we need @rjmccall @eli.friedman or @asl to help 
> out here.
Ping @efriedma, @rjmccall, @asl.


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

https://reviews.llvm.org/D140996

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


[PATCH] D150209: [clang][Interp] Add more shift error checking

2023-05-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/AST/Interp/shifts.cpp:165-171
+  constexpr int negativeShift() { // cxx17-error {{never produces a constant 
expression}} \
+  // ref-cxx17-error {{never produces a 
constant expression}}
+return -1 << 2; // cxx17-warning {{shifting a negative signed value is 
undefined}} \
+// ref-cxx17-warning {{shifting a negative signed value is 
undefined}} \
+// cxx17-note {{left shift of negative value -1}} \
+// ref-cxx17-note {{left shift of negative value -1}}
+  }

I'd like a test along the lines of:
```
constexpr int foo(int a) {
  return -a << 2;
}
static_assert(foo(10)); // Should fail
constexpr int a = -2;
static_assert(foo(a)); // Should be fine
static_assert(foo(-a)); // Should fail
```


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

https://reviews.llvm.org/D150209

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


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D147844#4333407 , @ldionne wrote:

> Code changes in libc++ and libc++abi LGTM. I am neutral on whether the 
> diagnostic is worth adding, but don't consider libc++ and libc++abi as 
> blockers for this patch.

Thank you @ldionne! My plan is to accept & land this if we hear no objections 
by next Thur (May 18).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

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


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-11 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs added a comment.

In D150291#4335352 , @tahonermann 
wrote:

> Thanks for all the updates @codemzs! I'm going to go ahead and accept. But 
> please wait a few days for recently subscribed folks to have a chance to 
> comment before landing this.

Thank you, @tahonermann, for the review. I will hold off on landing this until 
next week to allow sufficient time for others who are subscribed to review as 
well.


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

https://reviews.llvm.org/D150291

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


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-11 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs updated this revision to Diff 521363.
codemzs marked an inline comment as done.
codemzs added a comment.

Addressing feedback from @barannikov88


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

https://reviews.llvm.org/D150291

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/BuiltinTypes.def
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Basic/arm_neon_incl.td
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/tools/libclang/CXType.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4909,7 +4909,7 @@
 case clang::BuiltinType::Float128:
 case clang::BuiltinType::Double:
 case clang::BuiltinType::LongDouble:
-case clang::BuiltinType::BFloat16:
+case clang::BuiltinType::BF16:
 case clang::BuiltinType::Ibm128:
   return lldb::eEncodingIEEE754;
 
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -618,7 +618,7 @@
 TKIND(Pipe);
 TKIND(Attributed);
 TKIND(BTFTagAttributed);
-TKIND(BFloat16);
+TKIND(BF16);
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) TKIND(Id);
 #include "clang/Basic/OpenCLImageTypes.def"
 #undef IMAGE_TYPE
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -7024,8 +7024,8 @@
 case PREDEF_TYPE_INT128_ID:
   T = Context.Int128Ty;
   break;
-case PREDEF_TYPE_BFLOAT16_ID:
-  T = Context.BFloat16Ty;
+case PREDEF_TYPE_BF16_ID:
+  T = Context.BF16Ty;
   break;
 case PREDEF_TYPE_HALF_ID:
   T = Context.HalfTy;
Index: clang/lib/Serialization/ASTCommon.cpp
===
--- clang/lib/Serialization/ASTCommon.cpp
+++ clang/lib/Serialization/ASTCommon.cpp
@@ -270,8 +270,8 @@
   case BuiltinType::OMPIterator:
 ID = PREDEF_TYPE_OMP_ITERATOR;
 break;
-  case BuiltinType::BFloat16:
-ID = PREDEF_TYPE_BFLOAT16_ID;
+  case BuiltinType::BF16:
+ID = PREDEF_TYPE_BF16_ID;
 break;
   }
 
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1518,12 +1518,12 @@
 Result = Context.Float16Ty;
 break;
   case DeclSpec::TST_half:Result = Context.HalfTy; break;
-  case DeclSpec::TST_BFloat16:
-if (!S.Context.getTargetInfo().hasBFloat16Type() &&
+  case DeclSpec::TST_BF16:
+if (!S.Context.getTargetInfo().hasBF16Type() &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice) &&
 !S.getLangOpts().SYCLIsDevice)
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__bf16";
-Result = Context.BFloat16Ty;
+Result = Context.BF16Ty;
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;
   case DeclSpec::TST_double:
@@ -8133,7 +8133,7 @@
  BTy->getKind() == BuiltinType::ULongLong ||
  BTy->getKind() == BuiltinType::Float ||
  BTy->getKind() == BuiltinType::Half ||
- BTy->getKind() == BuiltinType::BF

[PATCH] D144943: [clang][Interp] Implement bitcasts (WIP)

2023-05-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D144943#4334500 , @tbaeder wrote:

> Pig

🐷




Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:74
+  // FIXME: Diagnostics.
+  if (ToType->isArrayType() || ToType->isPointerType())
+return false;

Member pointer types? Unions? volatile-qualified types? There's quite a few 
restrictions here for constexpr contexts.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:87
+  if (!ToT) {
+// Conversion to an array or record type.
+return this->emitBitCastPtr(E);

We returned earlier if `ToType` is an array, so this comment is a bit 
suspicious.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:101
+  // Conversion to a primitive type. FromType can be another
+  // primitive type, or a record/array.
+  //

All the same restrictions for `ToType` apply to `FromType`: 
http://eel.is/c++draft/bit.cast#3



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:92
+  // FIXME: Diagnostics.
+  if (*ToT == PT_Ptr)
+return false;

tbaeder wrote:
> One of the problems here is that right now, //all// diagnostics are emitted 
> during interpretation time.
Didn't we early return in this case as well?



Comment at: clang/lib/AST/Interp/Integral.h:179
+
+memcpy(&V, Buff, sizeof(ReprT));
+return Integral(V);

Consistency with below.



Comment at: clang/lib/AST/Interp/Interp.h:1366
+  size_t BuffSize = APFloat::semanticsSizeInBits(*Sem) / 8;
+  std::byte Buff[BuffSize];
+

tbaeder wrote:
> This is a variable sized array. That needs to go of course, but is the best 
> way to heap allocate? Or can we actually use `alloca` in clang code?
We usually go with:
```
std::vector Buff(BuffSize);
if (!DoBitCast(S, FromPtr, Buff.data(), BuffSize))
  return false;
```



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:35
+  std::byte *Buff;
+  unsigned Offset;
+  size_t BuffSize;

We should probably be consistent about using `size_t` in this class so there's 
no chance of size conversion between types.



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:33
 
+struct Foo {
+  std::byte *Buff;

tbaeder wrote:
> This needs to be renamed obviously, but I was wondering if this already 
> exists somewhere in the llvm/clang codebase...
I'm not aware of one, but perhaps this exists in LLVM somewhere?



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:81
+/// Rotate things around for big endian targets.
+static void fiddleMemory(std::byte *M, size_t N) {
+  for (size_t I = 0; I != (N / 2); ++I)

tbaeder wrote:
> Same here, I feel like this should already be available?
See 
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/SwapByteOrder.h


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

https://reviews.llvm.org/D144943

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


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-11 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

In D150291#4335414 , @codemzs wrote:

> I've provided the git log message that I see on my end below. I ensured that 
> it is split into multiple lines, with each line not exceeding the character 
> limit. Please let me know if this isn't inline with the LLVM contribution 
> standards.
>
> F27408097: image.png 

Looks great, thanks.
One note: if you are going to land the changes via arcanist, you will need to 
update the
message in the web form. (arc ignores git commit message and takes it from the 
web.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150291

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


[PATCH] D150318: [clang][deps] NFC: Pass around the whole scanning service

2023-05-11 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added inline comments.



Comment at: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h:69
+  /// The preprocessing mode used for scanning.
+  ScanningMode Mode;
+  /// The output format.

jansvoboda11 wrote:
> benlangmuir wrote:
> > Why drop `const`?
> I don't think it adds much, since the members are private and only ever 
> accessed in functions already marked `const`. I'm fine with keeping the 
> `const` here if you think there's value in it.
It's fine, just wanted to check I didn't misunderstand this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150318

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


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-11 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs marked an inline comment as done.
codemzs added a comment.

In D150291#4335360 , @barannikov88 
wrote:

> The summary as it is will be hard to read in git log. Please split it into 
> multiple lines 72~80 chars each.
> https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html

I've provided the git log message that I see on my end below. I ensured that it 
is split into multiple lines, with each line not exceeding the character limit. 
Please let me know if this isn't inline with the LLVM contribution standards.

F27408097: image.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150291

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


[PATCH] D150318: [clang][deps] NFC: Pass around the whole scanning service

2023-05-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h:69
+  /// The preprocessing mode used for scanning.
+  ScanningMode Mode;
+  /// The output format.

benlangmuir wrote:
> Why drop `const`?
I don't think it adds much, since the members are private and only ever 
accessed in functions already marked `const`. I'm fine with keeping the `const` 
here if you think there's value in it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150318

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


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-11 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

The summary as it is will be hard to read in git log. Please split it into 
multiple lines 72~80 chars each.
https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150291

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


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-11 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann accepted this revision.
tahonermann added a comment.
This revision is now accepted and ready to land.

Thanks for all the updates @codemzs! I'm going to go ahead and accept. But 
please wait a few days for recently subscribed folks to have a chance to 
comment before landing this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150291

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


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-11 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: clang/lib/AST/Type.cpp:2187
+ BT->getKind() <= BuiltinType::Ibm128 &&
+ BT->getKind() != BuiltinType::BF16;
   if (const auto *ET = dyn_cast(CanonicalType))

Looks like another clang-format quirk.




Comment at: clang/lib/CodeGen/TargetInfo.cpp:5568
 
   bool allowBFloatArgsAndRet() const override {
+return getTarget().hasBF16Type();

Should the name of the method be updated?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150291

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


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-11 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs updated this revision to Diff 521353.
codemzs marked 2 inline comments as done.
codemzs set the repository for this revision to rG LLVM Github Monorepo.
codemzs added a comment.

Update comments as per feedback from @tahonermann


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150291

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/BuiltinTypes.def
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Basic/arm_neon_incl.td
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/tools/libclang/CXType.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4909,7 +4909,7 @@
 case clang::BuiltinType::Float128:
 case clang::BuiltinType::Double:
 case clang::BuiltinType::LongDouble:
-case clang::BuiltinType::BFloat16:
+case clang::BuiltinType::BF16:
 case clang::BuiltinType::Ibm128:
   return lldb::eEncodingIEEE754;
 
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -618,7 +618,7 @@
 TKIND(Pipe);
 TKIND(Attributed);
 TKIND(BTFTagAttributed);
-TKIND(BFloat16);
+TKIND(BF16);
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) TKIND(Id);
 #include "clang/Basic/OpenCLImageTypes.def"
 #undef IMAGE_TYPE
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -7024,8 +7024,8 @@
 case PREDEF_TYPE_INT128_ID:
   T = Context.Int128Ty;
   break;
-case PREDEF_TYPE_BFLOAT16_ID:
-  T = Context.BFloat16Ty;
+case PREDEF_TYPE_BF16_ID:
+  T = Context.BF16Ty;
   break;
 case PREDEF_TYPE_HALF_ID:
   T = Context.HalfTy;
Index: clang/lib/Serialization/ASTCommon.cpp
===
--- clang/lib/Serialization/ASTCommon.cpp
+++ clang/lib/Serialization/ASTCommon.cpp
@@ -270,8 +270,8 @@
   case BuiltinType::OMPIterator:
 ID = PREDEF_TYPE_OMP_ITERATOR;
 break;
-  case BuiltinType::BFloat16:
-ID = PREDEF_TYPE_BFLOAT16_ID;
+  case BuiltinType::BF16:
+ID = PREDEF_TYPE_BF16_ID;
 break;
   }
 
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1518,12 +1518,12 @@
 Result = Context.Float16Ty;
 break;
   case DeclSpec::TST_half:Result = Context.HalfTy; break;
-  case DeclSpec::TST_BFloat16:
-if (!S.Context.getTargetInfo().hasBFloat16Type() &&
+  case DeclSpec::TST_BF16:
+if (!S.Context.getTargetInfo().hasBF16Type() &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice) &&
 !S.getLangOpts().SYCLIsDevice)
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__bf16";
-Result = Context.BFloat16Ty;
+Result = Context.BF16Ty;
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;
   case DeclSpec::TST_double:
@@ -8133,7 +8133,7 @@
  BTy->getKind() == BuiltinType::ULongLong ||
  BTy->getKind() == BuiltinType::Float ||

[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-11 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added a subscriber: clang-vendors.
tahonermann added a comment.

Heads up @clang-vendors. This patch changes the names of many internal 
identifiers for enumerators, class data members, and functions (including 
virtual functions) that are related to support for the `__bf16` type. The 
changes are roughly to replace "bfloat16" with "bf16" to make the association 
obvious and to avoid confusion when support for the C++ `std::bfloat16_t` type 
lands (and to make room for a potential matching `_BFloat16` type in C in the 
future). There are no changes to ABI or code generation; mangling continues to 
use the same names even where those have "bfloat16" in them. These changes will 
likely cause compilation failures in downstream projects that will require 
(simple) identifier updates to resolve.


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

https://reviews.llvm.org/D150291

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


[PATCH] D149816: [clang][Interp] Implement __builtin_strcmp

2023-05-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:22-23
+
+static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
+   InterpFrame *Frame) {
+  const Pointer &A = getParam(Frame, 0);

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > Thought: it would be nice if we could hoist as much of this 
> > > > implementation as we can into a helper function so that we can share 
> > > > most of the guts with `__builtin_memcmp()` as well.
> > > > 
> > > > Also, it would be good to generalize this so it works for 
> > > > `__builtin_wcscmp()` and `__builtin_wmemcmp()` as well.
> > > Definitely, but I think it makes more sense to do that when we implement 
> > > those functions.
> > I guess I was mostly wondering why we don't generalize that now given that 
> > we know the need exists. In fact, it seems like you could be handling 
> > `__builtin_strncmp` and others at the same time with one generalized 
> > implementation.
> Because smaller patches get reviewed faster :)
LoL fair.


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

https://reviews.llvm.org/D149816

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


[PATCH] D150364: [clang][Interp] Add 'Unsupported' opcode and use it for throw stmts

2023-05-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D150364#4335261 , @tbaeder wrote:

> In D150364#4335221 , @aaron.ballman 
> wrote:
>
>> "Unsupported" is a bit of a loaded term -- it could mean "this operation is 
>> not supported, YET" or it could mean "this operation is not and will not be 
>> supported, EVER". Perhaps something more like "InvalidInConstantExpr" would 
>> be more descriptive?
>
> I guess it would be more descriptive, but it could still mean that it is "not 
> yet valid in a constant expression", so I guess I don't see the upside of 
> using a longer opcode name.

I don't feel strongly; it's easy enough to rename if we think it's causing 
confusion. FWIW, my first thought was "Oh, we're planning to support throw 
expressions in constant expressions? Please don't tell WG21." I'm used to 
seeing "invalid" for things that are never valid and "unsupported" for things 
that aren't supported but might be someday. However, I also see we use 
"unsupported" in the same sense you're using it here in some of our 
diagnostics, so I'm fine with whatever you want to go with.




Comment at: clang/test/AST/Interp/records.cpp:341
+
+/// FIXME: Wrong source location below.
+return 12; // expected-note {{in call to '&S{}->~S()'}}

Oh interesting -- does the old constexpr interpreter think the destructor is 
called at the end of the block as opposed to at the end of the full expression 
with the temporary?


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

https://reviews.llvm.org/D150364

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


[PATCH] D149816: [clang][Interp] Implement __builtin_strcmp

2023-05-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:22-23
+
+static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
+   InterpFrame *Frame) {
+  const Pointer &A = getParam(Frame, 0);

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > Thought: it would be nice if we could hoist as much of this 
> > > implementation as we can into a helper function so that we can share most 
> > > of the guts with `__builtin_memcmp()` as well.
> > > 
> > > Also, it would be good to generalize this so it works for 
> > > `__builtin_wcscmp()` and `__builtin_wmemcmp()` as well.
> > Definitely, but I think it makes more sense to do that when we implement 
> > those functions.
> I guess I was mostly wondering why we don't generalize that now given that we 
> know the need exists. In fact, it seems like you could be handling 
> `__builtin_strncmp` and others at the same time with one generalized 
> implementation.
Because smaller patches get reviewed faster :)


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

https://reviews.llvm.org/D149816

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


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-11 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added subscribers: lenary, foad.
tahonermann added a comment.

> I was following the LLVM contribution guidelines to use git clang-format, but 
> I understand the importance of maintaining existing code styles that may be 
> altered by git-clang format.

The guidelines are slightly in conflict in that regard so, yeah, its a 
judgement call.

I added two more suggested edits targeting some comments.

This looks good to me, but I think we should make sure AMD and ARM folks are 
aware of the change. @foad, @lenary, any concerns?




Comment at: clang/include/clang/Basic/TargetInfo.h:650
 
-  /// Determine whether the _BFloat16 type is supported on this target.
-  virtual bool hasBFloat16Type() const { return HasBFloat16; }
+  /// Determine whether the _BF16 type is supported on this target.
+  virtual bool hasBF16Type() const { return HasBF16; }





Comment at: clang/include/clang/Basic/arm_neon_incl.td:240
 // F: change to floating category.
-// B: change to BFloat16
+// B: change to BF16
 // P: change to polynomial category.




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

https://reviews.llvm.org/D150291

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


[PATCH] D150364: [clang][Interp] Add 'Unsupported' opcode and use it for throw stmts

2023-05-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 521346.

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

https://reviews.llvm.org/D150364

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/records.cpp
  clang/test/AST/Interp/unsupported.cpp

Index: clang/test/AST/Interp/unsupported.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/unsupported.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -verify=ref %s
+
+namespace Throw {
+
+  constexpr int ConditionalThrow(bool t) {
+if (t)
+  throw 4; // expected-note {{subexpression not valid in a constant expression}} \
+   // ref-note {{subexpression not valid in a constant expression}}
+
+return 0;
+  }
+
+  static_assert(ConditionalThrow(false) == 0, "");
+  static_assert(ConditionalThrow(true) == 0, ""); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to 'ConditionalThrow(true)'}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to 'ConditionalThrow(true)'}}
+
+  constexpr int Throw() { // expected-error {{never produces a constant expression}} \
+  // ref-error {{never produces a constant expression}}
+throw 5; // expected-note {{subexpression not valid in a constant expression}} \
+ // ref-note {{subexpression not valid in a constant expression}}
+return 0;
+  }
+}
+
+namespace Asm {
+  constexpr int ConditionalAsm(bool t) {
+if (t)
+  asm(""); // expected-note {{subexpression not valid in a constant expression}} \
+   // ref-note {{subexpression not valid in a constant expression}}
+
+return 0;
+  }
+  static_assert(ConditionalAsm(false) == 0, "");
+  static_assert(ConditionalAsm(true) == 0, ""); // expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'ConditionalAsm(true)'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'ConditionalAsm(true)'}}
+
+
+  constexpr int Asm() { // expected-error {{never produces a constant expression}} \
+// ref-error {{never produces a constant expression}}
+__asm volatile(""); // expected-note {{subexpression not valid in a constant expression}} \
+// ref-note {{subexpression not valid in a constant expression}}
+return 0;
+  }
+}
Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -328,7 +328,8 @@
   struct S {
 constexpr S() {}
 constexpr ~S() noexcept(false) { throw 12; } // expected-error {{cannot use 'throw'}} \
- // expected-note {{declared here}} \
+ // expected-error {{never produces a constant expression}} \
+ // expected-note 2{{subexpression not valid}} \
  // ref-error {{cannot use 'throw'}} \
  // ref-error {{never produces a constant expression}} \
  // ref-note 2{{subexpression not valid}}
@@ -336,7 +337,9 @@
 
   constexpr int f() {
 S{}; // ref-note {{in call to '&S{}->~S()'}}
-return 12; // expected-note {{undefined function '~S'}}
+
+/// FIXME: Wrong source location below.
+return 12; // expected-note {{in call to '&S{}->~S()'}}
   }
   static_assert(f() == 12); // expected-error {{not an integral constant expression}} \
 // expected-note {{in call to 'f()'}} \
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -627,3 +627,6 @@
   let Types = [AllTypeClass];
   let HasGroup = 1;
 }
+
+// [] -> []
+def Unsupported : Opcode {}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1823,6 +1823,14 @@
   return true;
 }
 
+/// Just emit a diagnostic. The expression that caused emission of this
+/// op is not valid in a const

[PATCH] D149816: [clang][Interp] Implement __builtin_strcmp

2023-05-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:22-23
+
+static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
+   InterpFrame *Frame) {
+  const Pointer &A = getParam(Frame, 0);

tbaeder wrote:
> aaron.ballman wrote:
> > Thought: it would be nice if we could hoist as much of this implementation 
> > as we can into a helper function so that we can share most of the guts with 
> > `__builtin_memcmp()` as well.
> > 
> > Also, it would be good to generalize this so it works for 
> > `__builtin_wcscmp()` and `__builtin_wmemcmp()` as well.
> Definitely, but I think it makes more sense to do that when we implement 
> those functions.
I guess I was mostly wondering why we don't generalize that now given that we 
know the need exists. In fact, it seems like you could be handling 
`__builtin_strncmp` and others at the same time with one generalized 
implementation.


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

https://reviews.llvm.org/D149816

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


[PATCH] D150364: [clang][Interp] Add 'Unsupported' opcode and use it for throw stmts

2023-05-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D150364#4335221 , @aaron.ballman 
wrote:

> "Unsupported" is a bit of a loaded term -- it could mean "this operation is 
> not supported, YET" or it could mean "this operation is not and will not be 
> supported, EVER". Perhaps something more like "InvalidInConstantExpr" would 
> be more descriptive?

I guess it would be more descriptive, but it could still mean that it is "not 
yet valid in a constant expression", so I guess I don't see the upside of using 
a longer opcode name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150364

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


[PATCH] D150326: [WPD] Update llvm.public.type.test after importing functions

2023-05-11 Thread Teresa Johnson 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 rGa40b0c3e77a2: [WPD] Update llvm.public.type.test after 
importing functions (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150326

Files:
  clang/test/CodeGenCXX/thinlto_public_type_test_distributed.ll
  lld/test/ELF/lto/update_public_type_test.ll
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/ThinLTO/X86/public-type-test.ll

Index: llvm/test/ThinLTO/X86/public-type-test.ll
===
--- llvm/test/ThinLTO/X86/public-type-test.ll
+++ llvm/test/ThinLTO/X86/public-type-test.ll
@@ -1,16 +1,40 @@
-; Test to ensure that the legacy LTO API lowers @llvm.public.type.test.
+; Test to ensure that the LTO API (legacy and new) lowers @llvm.public.type.test.
 
-; RUN: opt -module-summary %s -o %t.bc
-; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t.bc --thinlto-save-temps=%t2
-; RUN: llvm-dis -o - %t20.2.internalized.bc | FileCheck %s --check-prefix=PUBLIC
-; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t.bc --thinlto-save-temps=%t2 --whole-program-visibility
-; RUN: llvm-dis -o - %t20.2.internalized.bc | FileCheck %s --check-prefix=HIDDEN
+; RUN: split-file %s %t
+
+; RUN: opt -module-summary %t/main.ll -o %t/main.bc
+; RUN: opt -module-summary %t/foo.ll -o %t/foo.bc
+; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t/main.bc %t/foo.bc --thinlto-save-temps=%t2.
+; RUN: llvm-dis -o - %t2.0.3.imported.bc | FileCheck %s --check-prefix=PUBLIC
+; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t/main.bc %t/foo.bc --thinlto-save-temps=%t2. --whole-program-visibility
+; RUN: llvm-dis -o - %t2.0.3.imported.bc | FileCheck %s --check-prefix=HIDDEN
+
+; RUN: llvm-lto2 run %t/main.bc %t/foo.bc -save-temps -pass-remarks=. \
+; RUN:   -whole-program-visibility \
+; RUN:   -o %t3 \
+; RUN:   -r=%t/main.bc,_main,px \
+; RUN:   -r=%t/main.bc,_bar,px \
+; RUN:   -r=%t/main.bc,_foo, \
+; RUN:   -r=%t/foo.bc,_foo,px
+; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=HIDDEN
+; RUN: llvm-lto2 run %t/main.bc %t/foo.bc -save-temps -pass-remarks=. \
+; RUN:   -o %t3 \
+; RUN:   -r=%t/main.bc,_main,px \
+; RUN:   -r=%t/main.bc,_bar,px \
+; RUN:   -r=%t/main.bc,_foo, \
+; RUN:   -r=%t/foo.bc,_foo,px
+; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=PUBLIC
 
 ; PUBLIC-NOT: call {{.*}}@llvm.public.type.test
 ; PUBLIC-NOT: call {{.*}}@llvm.type.test
+;; We should have converted the type tests from both main and the imported
+;; copy of foo to non-public.
+; HIDDEN-NOT: call {{.*}}@llvm.public.type.test
+; HIDDEN: call {{.*}}@llvm.type.test
 ; HIDDEN-NOT: call {{.*}}@llvm.public.type.test
 ; HIDDEN: call {{.*}}@llvm.type.test
 
+;--- main.ll
 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.9"
 
@@ -18,8 +42,31 @@
 entry:
   %p = call i1 @llvm.public.type.test(ptr %vtable, metadata !"_ZTS1A")
   call void @llvm.assume(i1 %p)
+  call void @bar(ptr %vtable)
   ret i32 0
 }
 
+define void @bar(ptr %vtable) {
+entry:
+  call void @foo(ptr %vtable)
+  ret void
+}
+
+declare void @foo(ptr %vtable)
+
+declare void @llvm.assume(i1)
+declare i1 @llvm.public.type.test(ptr, metadata)
+
+;--- foo.ll
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.9"
+
+define void @foo(ptr %vtable) {
+entry:
+  %p = call i1 @llvm.public.type.test(ptr %vtable, metadata !"_ZTS1A")
+  call void @llvm.assume(i1 %p)
+  ret void
+}
+
 declare void @llvm.assume(i1)
 declare i1 @llvm.public.type.test(ptr, metadata)
Index: llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
===
--- llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
+++ llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
@@ -18,7 +18,7 @@
 ; RUN:   -r=%t2.o,_ZTV1B,px \
 ; RUN:   -r=%t2.o,_ZTV1C,px \
 ; RUN:   -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK
-; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT
+; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT
 ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ; Hybrid WPD
@@ -43,7 +43,7 @@
 ; RUN:   -r=%t.o,_ZTV1B,px \
 ; RUN:   -r=%t.o,_ZTV1C,px \
 ; RUN:   -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK --dump-input=fail
-; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT
+; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT
 ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ; Reg

[PATCH] D150326: [WPD] Update llvm.public.type.test after importing functions

2023-05-11 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 521340.
tejohnson marked an inline comment as done.
tejohnson added a comment.

Address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150326

Files:
  clang/test/CodeGenCXX/thinlto_public_type_test_distributed.ll
  lld/test/ELF/lto/update_public_type_test.ll
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/ThinLTO/X86/public-type-test.ll

Index: llvm/test/ThinLTO/X86/public-type-test.ll
===
--- llvm/test/ThinLTO/X86/public-type-test.ll
+++ llvm/test/ThinLTO/X86/public-type-test.ll
@@ -1,16 +1,40 @@
-; Test to ensure that the legacy LTO API lowers @llvm.public.type.test.
+; Test to ensure that the LTO API (legacy and new) lowers @llvm.public.type.test.
 
-; RUN: opt -module-summary %s -o %t.bc
-; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t.bc --thinlto-save-temps=%t2
-; RUN: llvm-dis -o - %t20.2.internalized.bc | FileCheck %s --check-prefix=PUBLIC
-; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t.bc --thinlto-save-temps=%t2 --whole-program-visibility
-; RUN: llvm-dis -o - %t20.2.internalized.bc | FileCheck %s --check-prefix=HIDDEN
+; RUN: split-file %s %t
+
+; RUN: opt -module-summary %t/main.ll -o %t/main.bc
+; RUN: opt -module-summary %t/foo.ll -o %t/foo.bc
+; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t/main.bc %t/foo.bc --thinlto-save-temps=%t2.
+; RUN: llvm-dis -o - %t2.0.3.imported.bc | FileCheck %s --check-prefix=PUBLIC
+; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t/main.bc %t/foo.bc --thinlto-save-temps=%t2. --whole-program-visibility
+; RUN: llvm-dis -o - %t2.0.3.imported.bc | FileCheck %s --check-prefix=HIDDEN
+
+; RUN: llvm-lto2 run %t/main.bc %t/foo.bc -save-temps -pass-remarks=. \
+; RUN:   -whole-program-visibility \
+; RUN:   -o %t3 \
+; RUN:   -r=%t/main.bc,_main,px \
+; RUN:   -r=%t/main.bc,_bar,px \
+; RUN:   -r=%t/main.bc,_foo, \
+; RUN:   -r=%t/foo.bc,_foo,px
+; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=HIDDEN
+; RUN: llvm-lto2 run %t/main.bc %t/foo.bc -save-temps -pass-remarks=. \
+; RUN:   -o %t3 \
+; RUN:   -r=%t/main.bc,_main,px \
+; RUN:   -r=%t/main.bc,_bar,px \
+; RUN:   -r=%t/main.bc,_foo, \
+; RUN:   -r=%t/foo.bc,_foo,px
+; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=PUBLIC
 
 ; PUBLIC-NOT: call {{.*}}@llvm.public.type.test
 ; PUBLIC-NOT: call {{.*}}@llvm.type.test
+;; We should have converted the type tests from both main and the imported
+;; copy of foo to non-public.
+; HIDDEN-NOT: call {{.*}}@llvm.public.type.test
+; HIDDEN: call {{.*}}@llvm.type.test
 ; HIDDEN-NOT: call {{.*}}@llvm.public.type.test
 ; HIDDEN: call {{.*}}@llvm.type.test
 
+;--- main.ll
 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.9"
 
@@ -18,8 +42,31 @@
 entry:
   %p = call i1 @llvm.public.type.test(ptr %vtable, metadata !"_ZTS1A")
   call void @llvm.assume(i1 %p)
+  call void @bar(ptr %vtable)
   ret i32 0
 }
 
+define void @bar(ptr %vtable) {
+entry:
+  call void @foo(ptr %vtable)
+  ret void
+}
+
+declare void @foo(ptr %vtable)
+
+declare void @llvm.assume(i1)
+declare i1 @llvm.public.type.test(ptr, metadata)
+
+;--- foo.ll
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.9"
+
+define void @foo(ptr %vtable) {
+entry:
+  %p = call i1 @llvm.public.type.test(ptr %vtable, metadata !"_ZTS1A")
+  call void @llvm.assume(i1 %p)
+  ret void
+}
+
 declare void @llvm.assume(i1)
 declare i1 @llvm.public.type.test(ptr, metadata)
Index: llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
===
--- llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
+++ llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
@@ -18,7 +18,7 @@
 ; RUN:   -r=%t2.o,_ZTV1B,px \
 ; RUN:   -r=%t2.o,_ZTV1C,px \
 ; RUN:   -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK
-; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT
+; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT
 ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ; Hybrid WPD
@@ -43,7 +43,7 @@
 ; RUN:   -r=%t.o,_ZTV1B,px \
 ; RUN:   -r=%t.o,_ZTV1C,px \
 ; RUN:   -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK --dump-input=fail
-; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT
+; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT
 ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ; Regular LTO WPD
@@ -83,7 +83,7 @@
 ; RUN:   -r=%t2.o,_ZTV1B,px \
 ; RUN:   -r=%t2.o,_ZTV1C,px \
 ; RUN:   -r=%t2.o,_

  1   2   >