[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

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



Comment at: clang/lib/AST/Interp/Interp.cpp:264-270
+  const Function *Func = S.Current->getFunction();
+  if (Func && Func->isConstructor()) {
+// The This pointer is writable in constructors, even if
+// isConst() returns true.
+if (Ptr.block() == S.Current->getThis().block())
+  return true;
+  }

shafik wrote:
> shafik wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > The same is true for destructors as well: 
> > > > https://godbolt.org/z/a49aEErz8
> > > Oh, good catch, thanks.
> > Interesting case: https://godbolt.org/z/5r5fdh9jr
> > 
> > Implementation divergence, have to figure out who is correct here.
> I believe clang is correct: https://eel.is/c++draft/expr.const#4.8
The output is the same with the new constant interpreter; that case is probably 
handled before it's constant evaluated.


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

https://reviews.llvm.org/D136751

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


[PATCH] D141672: [RISCV] Support vector crypto extension ISA string and assembly

2023-02-16 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat updated this revision to Diff 498253.
4vtomat marked 2 inline comments as done.
4vtomat added a comment.

Update to v20230206


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141672

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rvv/zvkb.s
  llvm/test/MC/RISCV/rvv/zvkg.s
  llvm/test/MC/RISCV/rvv/zvknh.s
  llvm/test/MC/RISCV/rvv/zvkns-invalid.s
  llvm/test/MC/RISCV/rvv/zvkns.s
  llvm/test/MC/RISCV/rvv/zvksed-invalid.s
  llvm/test/MC/RISCV/rvv/zvksed.s
  llvm/test/MC/RISCV/rvv/zvksh.s

Index: llvm/test/MC/RISCV/rvv/zvksh.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvksh.s
@@ -0,0 +1,21 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding --mattr=+zve32x --mattr=+experimental-zvksh %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+zve32x --mattr=+experimental-zvksh %s \
+# RUN:| llvm-objdump -d --mattr=+zve32x --mattr=+experimental-zvksh  - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+zve32x --mattr=+experimental-zvksh %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+vsm3c.vi v10, v9, 7
+# CHECK-INST: vsm3c.vi v10, v9, 7
+# CHECK-ENCODING: [0x77,0xa5,0x93,0xae]
+# CHECK-ERROR: instruction requires the following: 'Zvksh'
+# CHECK-UNKNOWN: 77 a5 93 ae   
+
+vsm3me.vv v10, v9, v8
+# CHECK-INST: vsm3me.vv v10, v9, v8
+# CHECK-ENCODING: [0x77,0x25,0x94,0x82]
+# CHECK-ERROR: instruction requires the following: 'Zvksh'
+# CHECK-UNKNOWN: 77 25 94 82   
Index: llvm/test/MC/RISCV/rvv/zvksed.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvksed.s
@@ -0,0 +1,27 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding --mattr=+zve32x --mattr=+experimental-zvksed %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+zve32x --mattr=+experimental-zvksed %s \
+# RUN:| llvm-objdump -d --mattr=+zve32x --mattr=+experimental-zvksed  - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+zve32x --mattr=+experimental-zvksed %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+vsm4k.vi v10, v9, 7
+# CHECK-INST: vsm4k.vi v10, v9, 7
+# CHECK-ENCODING: [0x77,0xa5,0x93,0x86]
+# CHECK-ERROR: instruction requires the following: 'Zvksed'
+# CHECK-UNKNOWN: 77 a5 93 86   
+
+vsm4r.vv v10, v9
+# CHECK-INST: vsm4r.vv v10, v9
+# CHECK-ENCODING: [0x77,0x25,0x98,0xa2]
+# CHECK-ERROR: instruction requires the following: 'Zvksed'
+# CHECK-UNKNOWN: 77 25 98 a2   
+
+vsm4r.vs v10, v9
+# CHECK-INST: vsm4r.vs v10, v9
+# CHECK-ENCODING: [0x77,0x25,0x98,0xa6]
+# CHECK-ERROR: instruction requires the following: 'Zvksed'
+# CHECK-UNKNOWN: 77 25 98 a6   
Index: llvm/test/MC/RISCV/rvv/zvksed-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvksed-invalid.s
@@ -0,0 +1,5 @@
+# RUN: not llvm-mc -triple=riscv32 --mattr=+zve32x --mattr=+experimental-zvksed -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+
+vsm4k.vi v10, v9, 8
+# CHECK-ERROR: immediate must be an integer in the range [0, 7]
Index: llvm/test/MC/RISCV/rvv/zvkns.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvkns.s
@@ -0,0 +1,75 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding --mattr=+zve32x --mattr=+experimental-zvkned %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+zve32x --mattr=+experimental-zvkned %s \
+# RUN:| llvm-objdump -d --mattr=+zve32x --mattr=+experimental-zvkned  - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj 

[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

2023-02-16 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: llvm/docs/LangRef.rst:2166
+
+If the mode is ``"dynamic"``, the behavior is derived from the
+dynamic state of the floating-point environment. Transformations

1. Does it mean users must specify `dynamic` when they change FTZ/DAZ in a 
function?
2. If 1) is true, is there a way to partially set on functions in its call 
stack, e.g.,
```
main
  f0
  f1
f10
  setFtzDaz(true);
  f2
  f3
```
Ideally, users may want to tell compiler `main`, `f1`, `f10` is `dynamic`, 
while `f0` is `ieee` and `f2`, `f3` is `positive-zero`, rather than `dynamic` 
for all.
3. If 2) is true, it looks silly to do it one by one manually. Should compiler 
help to deduce this information itself?


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

https://reviews.llvm.org/D142907

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


[PATCH] D144157: Add 128-bit integer support to enum element

2023-02-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

We also need a codegen test. `clang/test/CodeGen/enum2.c` may be a good one. It 
tests that debug information is correct as well.


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

https://reviews.llvm.org/D144157

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


[PATCH] D143919: [Clang] Copy strictfp attribute from pattern to instantiation

2023-02-16 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:824
+  continue;
+}
+

efriedma wrote:
> sepavloff wrote:
> > efriedma wrote:
> > > Is this necessary?  The non-delayed-parsed case seems to work correctly 
> > > on trunk without any changes, so I suspect the autogenerated 
> > > sema::instantiateTemplateAttribute is doing the right thing.
> > Yes, it is necessary. Without it the code from the added test crashes, as 
> > constrained intrinsic is used in a function without strictfp attribute.
> https://godbolt.org/z/MvPrejY75 indicates this is only an issue with 
> -fdelayed-template-parsing; am I missing something?
Indeed. I used Windows where this flag is on by default. Thank you for the 
catch.
Removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143919

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


[PATCH] D143919: [Clang] Copy strictfp attribute from pattern to instantiation

2023-02-16 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 498248.
sepavloff added a comment.

Remove copying StrictFPAttr from InstantiateAttrs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143919

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGen/fp-template.cpp


Index: clang/test/CodeGen/fp-template.cpp
===
--- /dev/null
+++ clang/test/CodeGen/fp-template.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm 
-fdelayed-template-parsing -o - %s | FileCheck %s
+
+template 
+T templ_01(T x, T y) {
+#pragma STDC FENV_ACCESS ON
+  return x + y;
+}
+
+float func_01(float x, float y) {
+  return templ_01(x, y);
+}
+
+// CHECK-LABEL: define {{.*}} @_Z8templ_01IfET_S0_S0_
+// CHECK-SAME:  (float noundef %{{.*}}, float noundef %{{.*}}) 
#[[ATTR01:[0-9]+]]{{.*}} {
+// CHECK:   call float @llvm.experimental.constrained.fadd.f32
+
+// CHECK: attributes #[[ATTR01]] = { {{.*}}strictfp
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -834,6 +834,22 @@
   }
 }
 
+/// Update instantiation attributes after template was late parsed.
+///
+/// Some attributes are evaluated based on the body of template. If it is
+/// late parsed, such attributes cannot be evaluated when declaration is
+/// instantiated. This function is used to update instantiation attributes when
+/// template definition is ready.
+void Sema::updateAttrsForLateParsedTemplate(const Decl *Pattern, Decl *Inst) {
+  for (const auto *Attr : Pattern->attrs()) {
+if (auto *A = dyn_cast(Attr)) {
+  if (!Inst->hasAttr())
+Inst->addAttr(A->clone(getASTContext()));
+  continue;
+}
+  }
+}
+
 /// In the MS ABI, we need to instantiate default arguments of dllexported
 /// default constructors along with the constructor definition. This allows IR
 /// gen to emit a constructor closure which calls the default constructor with
@@ -4916,6 +4932,7 @@
"missing LateParsedTemplate");
 LateTemplateParser(OpaqueParser, *LPTIter->second);
 Pattern = PatternDecl->getBody(PatternDecl);
+updateAttrsForLateParsedTemplate(PatternDecl, Function);
   }
 
   // Note, we should never try to instantiate a deleted function template.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10072,6 +10072,7 @@
 const Decl *Pattern, Decl *Inst,
 LateInstantiatedAttrVec *LateAttrs = nullptr,
 LocalInstantiationScope *OuterMostScope = nullptr);
+  void updateAttrsForLateParsedTemplate(const Decl *Pattern, Decl *Inst);
 
   void
   InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList ,


Index: clang/test/CodeGen/fp-template.cpp
===
--- /dev/null
+++ clang/test/CodeGen/fp-template.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -fdelayed-template-parsing -o - %s | FileCheck %s
+
+template 
+T templ_01(T x, T y) {
+#pragma STDC FENV_ACCESS ON
+  return x + y;
+}
+
+float func_01(float x, float y) {
+  return templ_01(x, y);
+}
+
+// CHECK-LABEL: define {{.*}} @_Z8templ_01IfET_S0_S0_
+// CHECK-SAME:  (float noundef %{{.*}}, float noundef %{{.*}}) #[[ATTR01:[0-9]+]]{{.*}} {
+// CHECK:   call float @llvm.experimental.constrained.fadd.f32
+
+// CHECK: attributes #[[ATTR01]] = { {{.*}}strictfp
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -834,6 +834,22 @@
   }
 }
 
+/// Update instantiation attributes after template was late parsed.
+///
+/// Some attributes are evaluated based on the body of template. If it is
+/// late parsed, such attributes cannot be evaluated when declaration is
+/// instantiated. This function is used to update instantiation attributes when
+/// template definition is ready.
+void Sema::updateAttrsForLateParsedTemplate(const Decl *Pattern, Decl *Inst) {
+  for (const auto *Attr : Pattern->attrs()) {
+if (auto *A = dyn_cast(Attr)) {
+  if (!Inst->hasAttr())
+Inst->addAttr(A->clone(getASTContext()));
+  continue;
+}
+  }
+}
+
 /// In the MS ABI, we need to instantiate default arguments of dllexported
 /// default constructors along with the constructor definition. This allows IR
 /// gen 

[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-16 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

poke - anyone mind reviewing this?

I used this tool to fix two small cases of missing move in the llvm project:
https://reviews.llvm.org/D142824
https://reviews.llvm.org/D142825


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D143755: [clang-format] Add a space between an overloaded operator and '>'

2023-02-16 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb05dc1b8766a: [clang-format] Add a space between an 
overloaded operator and  (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143755

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -574,6 +574,71 @@
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
 }
 
+TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {
+  struct {
+const char *Text;
+tok::TokenKind Kind;
+  } Operators[] = {{"+", tok::plus},
+   {"-", tok::minus},
+   // FIXME:
+   // {"*", tok::star},
+   {"/", tok::slash},
+   {"%", tok::percent},
+   {"^", tok::caret},
+   // FIXME:
+   // {"&", tok::amp},
+   {"|", tok::pipe},
+   {"~", tok::tilde},
+   {"!", tok::exclaim},
+   {"=", tok::equal},
+   // FIXME:
+   // {"<", tok::less},
+   {">", tok::greater},
+   {"+=", tok::plusequal},
+   {"-=", tok::minusequal},
+   {"*=", tok::starequal},
+   {"/=", tok::slashequal},
+   {"%=", tok::percentequal},
+   {"^=", tok::caretequal},
+   {"&=", tok::ampequal},
+   {"|=", tok::pipeequal},
+   {"<<", tok::lessless},
+   {">>", tok::greatergreater},
+   {">>=", tok::greatergreaterequal},
+   {"<<=", tok::lesslessequal},
+   {"==", tok::equalequal},
+   {"!=", tok::exclaimequal},
+   {"<=", tok::lessequal},
+   {">=", tok::greaterequal},
+   {"<=>", tok::spaceship},
+   {"&&", tok::ampamp},
+   {"||", tok::pipepipe},
+   {"++", tok::plusplus},
+   {"--", tok::minusminus},
+   {",", tok::comma},
+   {"->*", tok::arrowstar},
+   {"->", tok::arrow}};
+
+  for (const auto  : Operators) {
+std::string Input("C<");
+Input += Operator.Text;
+Input += " > a;";
+auto Tokens = annotate(std::string(Input));
+ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+EXPECT_TOKEN(Tokens[1], tok::less, TT_TemplateOpener);
+EXPECT_TOKEN(Tokens[4], Operator.Kind, TT_OverloadedOperator);
+EXPECT_TOKEN(Tokens[5], tok::greater, TT_TemplateCloser);
+  }
+
+  auto Tokens = annotate("C<< > lt;");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[4], tok::less, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[5], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[8], tok::greater, TT_TemplateCloser);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
   auto Tokens = annotate("template \n"
  "concept C = (Foo && Bar) && (Bar && Baz);");
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10663,6 +10663,14 @@
   verifyFormat("foo() { ::operator new(n * sizeof(foo)); }");
 }
 
+TEST_F(FormatTest, SpaceBeforeTemplateCloser) {
+  verifyFormat("C< > minus;");
+  verifyFormat("C<> > gt;");
+  verifyFormat("C<>= > ge;");
+  verifyFormat("C<<= > le;");
+  verifyFormat("C<< > lt;");
+}
+
 TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
   verifyFormat("void A::b() && {}");
   verifyFormat("void A::b() && noexcept {}");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1219,19 +1219,25 @@
  !CurrentToken->isOneOf(tok::l_paren, tok::semi, tok::r_paren)) {
 if (CurrentToken->isOneOf(tok::star, tok::amp))
   CurrentToken->setType(TT_PointerOrReference);
-consumeToken();
-if (!CurrentToken)
-  continue;
-if (CurrentToken->is(tok::comma) &&
-CurrentToken->Previous->isNot(tok::kw_operator)) {
+auto Next = 

[clang] b05dc1b - [clang-format] Add a space between an overloaded operator and '>'

2023-02-16 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-02-16T20:25:39-08:00
New Revision: b05dc1b8766a47482cae432011fd2faa04c83a3e

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

LOG: [clang-format] Add a space between an overloaded operator and '>'

The token annotator doesn't annotate the template opener and closer
as such if they enclose an overloaded operator. This causes the
space between the operator and the closer to be removed, resulting
in invalid C++ code.

Fixes #58602.

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

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index f3349a4dc2df..d5a2a39094be 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -743,8 +743,8 @@ struct FormatToken {
   }
 
   /// Returns the next token ignoring comments.
-  [[nodiscard]] const FormatToken *getNextNonComment() const {
-const FormatToken *Tok = Next;
+  [[nodiscard]] FormatToken *getNextNonComment() const {
+FormatToken *Tok = Next;
 while (Tok && Tok->is(tok::comment))
   Tok = Tok->Next;
 return Tok;

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index f06f9fb9949d..ae54de93daf5 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -103,6 +103,8 @@ void FormatTokenLexer::tryMergePreviousTokens() {
 return;
   if (tryMergeLessLess())
 return;
+  if (tryMergeGreaterGreater())
+return;
   if (tryMergeForEach())
 return;
   if (Style.isCpp() && tryTransformTryUsageForC())
@@ -460,12 +462,11 @@ bool FormatTokenLexer::tryMergeLessLess() {
 return false;
 
   auto X = Tokens.size() > 3 ? First[-1] : nullptr;
-  auto Y = First[2];
-  if ((X && X->is(tok::less)) || Y->is(tok::less))
+  if (X && X->is(tok::less))
 return false;
 
-  // Do not remove a whitespace between the two "<" e.g. "operator< <>".
-  if (X && X->is(tok::kw_operator) && Y->is(tok::greater))
+  auto Y = First[2];
+  if ((!X || X->isNot(tok::kw_operator)) && Y->is(tok::less))
 return false;
 
   First[0]->Tok.setKind(tok::lessless);
@@ -475,6 +476,30 @@ bool FormatTokenLexer::tryMergeLessLess() {
   return true;
 }
 
+bool FormatTokenLexer::tryMergeGreaterGreater() {
+  // Merge kw_operator,greater,greater into kw_operator,greatergreater.
+  if (Tokens.size() < 2)
+return false;
+
+  auto First = Tokens.end() - 2;
+  if (First[0]->isNot(tok::greater) || First[1]->isNot(tok::greater))
+return false;
+
+  // Only merge if there currently is no whitespace between the first two ">".
+  if (First[1]->hasWhitespaceBefore())
+return false;
+
+  auto Tok = Tokens.size() > 2 ? First[-1] : nullptr;
+  if (Tok && Tok->isNot(tok::kw_operator))
+return false;
+
+  First[0]->Tok.setKind(tok::greatergreater);
+  First[0]->TokenText = ">>";
+  First[0]->ColumnWidth += 1;
+  Tokens.erase(Tokens.end() - 1);
+  return true;
+}
+
 bool FormatTokenLexer::tryMergeTokens(ArrayRef Kinds,
   TokenType NewType) {
   if (Tokens.size() < Kinds.size())

diff  --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 950305a37d68..0a8123fed293 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -51,6 +51,7 @@ class FormatTokenLexer {
   void tryMergePreviousTokens();
 
   bool tryMergeLessLess();
+  bool tryMergeGreaterGreater();
   bool tryMergeNSStringLiteral();
   bool tryMergeJSPrivateIdentifier();
   bool tryMergeCSharpStringLiteral();

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 2bafa48b5336..34c51c240cd3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1219,19 +1219,25 @@ class AnnotatingParser {
  !CurrentToken->isOneOf(tok::l_paren, tok::semi, tok::r_paren)) {
 if (CurrentToken->isOneOf(tok::star, tok::amp))
   CurrentToken->setType(TT_PointerOrReference);
-consumeToken();
-if (!CurrentToken)
-  continue;
-if (CurrentToken->is(tok::comma) &&
-CurrentToken->Previous->isNot(tok::kw_operator)) {
+auto Next = CurrentToken->getNextNonComment();
+if (!Next)
   break;
-}
-if (CurrentToken->Previous->isOneOf(TT_BinaryOperator, 
TT_UnaryOperator,
-tok::comma, tok::star, tok::arrow,
- 

[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

2023-02-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/Interp/Interp.cpp:264-270
+  const Function *Func = S.Current->getFunction();
+  if (Func && Func->isConstructor()) {
+// The This pointer is writable in constructors, even if
+// isConst() returns true.
+if (Ptr.block() == S.Current->getThis().block())
+  return true;
+  }

shafik wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > The same is true for destructors as well: https://godbolt.org/z/a49aEErz8
> > Oh, good catch, thanks.
> Interesting case: https://godbolt.org/z/5r5fdh9jr
> 
> Implementation divergence, have to figure out who is correct here.
I believe clang is correct: https://eel.is/c++draft/expr.const#4.8


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

https://reviews.llvm.org/D136751

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


[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

2023-02-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/Interp/Interp.cpp:264-270
+  const Function *Func = S.Current->getFunction();
+  if (Func && Func->isConstructor()) {
+// The This pointer is writable in constructors, even if
+// isConst() returns true.
+if (Ptr.block() == S.Current->getThis().block())
+  return true;
+  }

tbaeder wrote:
> aaron.ballman wrote:
> > The same is true for destructors as well: https://godbolt.org/z/a49aEErz8
> Oh, good catch, thanks.
Interesting case: https://godbolt.org/z/5r5fdh9jr

Implementation divergence, have to figure out who is correct here.


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

https://reviews.llvm.org/D136751

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


[PATCH] D144232: [PowerPC] Correctly use ELFv2 ABI on FreeBSD/powerpc64

2023-02-16 Thread Alfredo Dal'Ava Júnior via Phabricator via cfe-commits
adalava added a comment.

Nice catch! 
I'm not a LLVM maintainer but from FreeBSD PowerPC side I agree with the 
changes, only added two suggestions that could improve code readability




Comment at: clang/lib/Basic/Targets/PPC.h:428
   ABI = "elfv2";
+} else if (Triple.isOSFreeBSD() && (Triple.getOSMajorVersion() == 0 ||
+Triple.getOSMajorVersion() >= 13)) {

The comparison `Triple.getOSMajorVersion() == 0` works, but I think 
`Triple.getOSVersion().empty()`  would better describe the intent



Comment at: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp:237
+  if (TT.isOSFreeBSD() && TT.getArch() == Triple::ppc64 &&
+  (TT.getOSMajorVersion() == 0 || TT.getOSMajorVersion() >= 13)) {
+return PPCTargetMachine::PPC_ABI_ELFv2;

Same here, it could be `TT.getOSVersion().empty()` instead of 
`TT.getOSMajorVersion() == 0`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144232

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


[PATCH] D141591: [clang][Interp] Properly identify not-yet-defined functions

2023-02-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1486
   bool IsBeingCompiled = Func && !Func->isFullyCompiled();
-  bool WasNotDefined = Func && !Func->hasBody();
+  bool WasNotDefined = Func && !Func->isConstexpr() && !Func->hasBody();
 

Why the check for `isContexpr()`?


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

https://reviews.llvm.org/D141591

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


[PATCH] D144016: [Sema] Relax a failing assertion in TransformBlockExpr

2023-02-16 Thread Akira Hatanaka 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 rGcda4a0e918b5: [Sema] Relax a failing assertion in 
TransformBlockExpr (authored by ahatanak).

Changed prior to commit:
  https://reviews.llvm.org/D144016?vs=497776=498232#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144016

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp


Index: clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp
===
--- clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp
+++ clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -o - | FileCheck %s 
--implicit-check-not=should_not_be_used
+// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -fblocks -triple 
x86_64-apple-darwin10 -o - | FileCheck %s 
--implicit-check-not=should_not_be_used
 
 void should_be_used_1();
 void should_be_used_2();
@@ -32,3 +32,20 @@
 // CHECK: should_be_used_1
 // CHECK: should_be_used_2
 // CHECK: should_be_used_3
+
+namespace BlockThisCapture {
+  void foo();
+  struct S {
+template 
+void m() {
+  ^{ if constexpr(b) (void)this; else foo();  }();
+}
+  };
+
+  void test() {
+S().m();
+  }
+}
+
+// CHECK-LABEL: define internal void 
@___ZN16BlockThisCapture1S1mILb0EEEvv_block_invoke(
+// CHECK: call void @_ZN16BlockThisCapture3fooEv(
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -14598,7 +14598,12 @@
  oldCapture));
   assert(blockScope->CaptureMap.count(newCapture));
 }
-assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
+
+// The this pointer may not be captured by the instantiated block, even 
when
+// it's captured by the original block, if the expression causing the
+// capture is in the discarded branch of a constexpr if statement.
+assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
+   "this pointer isn't captured in the old block");
   }
 #endif
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -141,6 +141,9 @@
   driver mode and emit an error which suggests using ``/TC`` or ``/TP``
   ``clang-cl`` options instead.
   (`#59307 `_)
+- Fix assert that fails when the expression causing the this pointer to be
+  captured by a block is part of a constexpr if statement's branch and
+  instantiation of the enclosing method causes the branch to be discarded.
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp
===
--- clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp
+++ clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -o - | FileCheck %s --implicit-check-not=should_not_be_used
+// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -fblocks -triple x86_64-apple-darwin10 -o - | FileCheck %s --implicit-check-not=should_not_be_used
 
 void should_be_used_1();
 void should_be_used_2();
@@ -32,3 +32,20 @@
 // CHECK: should_be_used_1
 // CHECK: should_be_used_2
 // CHECK: should_be_used_3
+
+namespace BlockThisCapture {
+  void foo();
+  struct S {
+template 
+void m() {
+  ^{ if constexpr(b) (void)this; else foo();  }();
+}
+  };
+
+  void test() {
+S().m();
+  }
+}
+
+// CHECK-LABEL: define internal void @___ZN16BlockThisCapture1S1mILb0EEEvv_block_invoke(
+// CHECK: call void @_ZN16BlockThisCapture3fooEv(
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -14598,7 +14598,12 @@
  oldCapture));
   assert(blockScope->CaptureMap.count(newCapture));
 }
-assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
+
+// The this pointer may not be captured by the instantiated block, even when
+// it's captured by the original block, if the expression causing the
+// capture is in the discarded branch of a constexpr if statement.
+assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
+   "this pointer isn't captured in the old block");
   }
 #endif
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -141,6 +141,9 @@
   driver 

[clang] cda4a0e - [Sema] Relax a failing assertion in TransformBlockExpr

2023-02-16 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2023-02-16T18:40:26-08:00
New Revision: cda4a0e918b591be9ae0732f7df07678efb75047

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

LOG: [Sema] Relax a failing assertion in TransformBlockExpr

The assertion fails when the expression causing the this pointer to be
captured is part of a constexpr if statement's branch and the branch
gets discarded when the enclosing method is instantiated.

Note that the test case is added to CodeGen instead of Sema since the
translation unit has to be free of errors in order for the assertion to
be checked.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/TreeTransform.h
clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4f2007fcf5715..70a91bab0cb21 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -141,6 +141,9 @@ Bug Fixes in This Version
   driver mode and emit an error which suggests using ``/TC`` or ``/TP``
   ``clang-cl`` options instead.
   (`#59307 `_)
+- Fix assert that fails when the expression causing the this pointer to be
+  captured by a block is part of a constexpr if statement's branch and
+  instantiation of the enclosing method causes the branch to be discarded.
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 25b3034a5efac..cca0383568201 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -14598,7 +14598,12 @@ TreeTransform::TransformBlockExpr(BlockExpr 
*E) {
  oldCapture));
   assert(blockScope->CaptureMap.count(newCapture));
 }
-assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
+
+// The this pointer may not be captured by the instantiated block, even 
when
+// it's captured by the original block, if the expression causing the
+// capture is in the discarded branch of a constexpr if statement.
+assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
+   "this pointer isn't captured in the old block");
   }
 #endif
 

diff  --git a/clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp 
b/clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp
index 14695363b331c..d14e36406a45e 100644
--- a/clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp
+++ b/clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -o - | FileCheck %s 
--implicit-check-not=should_not_be_used
+// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -fblocks -triple 
x86_64-apple-darwin10 -o - | FileCheck %s 
--implicit-check-not=should_not_be_used
 
 void should_be_used_1();
 void should_be_used_2();
@@ -32,3 +32,20 @@ foo: should_not_be_used();
 // CHECK: should_be_used_1
 // CHECK: should_be_used_2
 // CHECK: should_be_used_3
+
+namespace BlockThisCapture {
+  void foo();
+  struct S {
+template 
+void m() {
+  ^{ if constexpr(b) (void)this; else foo();  }();
+}
+  };
+
+  void test() {
+S().m();
+  }
+}
+
+// CHECK-LABEL: define internal void 
@___ZN16BlockThisCapture1S1mILb0EEEvv_block_invoke(
+// CHECK: call void @_ZN16BlockThisCapture3fooEv(



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


[PATCH] D141194: [clang][Interp] Implement bitcasts

2023-02-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I think `VisitCastExpr` is the right place to start looking for what to do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141194

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


[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-02-16 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: clang/lib/CodeGen/Address.h:67
   return;
-// Currently the max supported alignment is much less than 1 << 63 and is
+// Currently the max supported alignment is much less than 1 << 32 and is
 // guaranteed to be a power of 2, so we can store the log of the alignment

ahatanak wrote:
> efriedma wrote:
> > ahatanak wrote:
> > > efriedma wrote:
> > > > ahatanak wrote:
> > > > > efriedma wrote:
> > > > > > This comment isn't right.  The max alignment is, as far as I can 
> > > > > > tell, 1<<32 exactly.  (But there's something weird going on with 
> > > > > > very large values... somehow `int a[1LL<<32] 
> > > > > > __attribute((aligned(1ULL<<32))) = {};` ignores the alignment.)
> > > > > The following function generated by tablegen (and a few others 
> > > > > directly or indirectly calling the function) returns a 32-bit int, 
> > > > > but it should be returning a 64-bit int.
> > > > > 
> > > > > https://github.com/llvm/llvm-project/blob/main/clang/utils/TableGen/ClangAttrEmitter.cpp#L532
> > > > Filed https://github.com/llvm/llvm-project/issues/60752 so we don't 
> > > > lose track of this.
> > > I just realized we can't reduce the number of bits used for alignment 
> > > here as we need 6 bits for alignment of `1 << 32`.
> > > 
> > > Should we allocate additional memory when `AlignLog` is either 31 or 32? 
> > > If the 5-bit alignment is equal to `0b1`, it would mean that there is 
> > > an out-of-line storage large enough to hold the alignment and any other 
> > > extra information that is needed. I think 
> > > https://reviews.llvm.org/D117262#3267899 proposes a similar idea.
> > How much does `sizeof(Address)` actually matter, anyway?  If it's going to 
> > get that nasty to implement the packing, I'm not sure it's worth the effort 
> > to optimize.
> I'm not sure, but apparently https://reviews.llvm.org/D117262 was needed to 
> reduce the memory usage.
> 
> I don't see a significant increase in stack usage (a little over 1%) in the 
> files in `clang/lib/CodeGen` when I build clang with `-fstack-usage`.
@aeubanks do we have to use the specialization `AddressImpl`?

https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/Address.h#L31


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

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


[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-02-16 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a subscriber: aeubanks.
ahatanak added inline comments.



Comment at: clang/lib/CodeGen/Address.h:67
   return;
-// Currently the max supported alignment is much less than 1 << 63 and is
+// Currently the max supported alignment is much less than 1 << 32 and is
 // guaranteed to be a power of 2, so we can store the log of the alignment

efriedma wrote:
> ahatanak wrote:
> > efriedma wrote:
> > > ahatanak wrote:
> > > > efriedma wrote:
> > > > > This comment isn't right.  The max alignment is, as far as I can 
> > > > > tell, 1<<32 exactly.  (But there's something weird going on with very 
> > > > > large values... somehow `int a[1LL<<32] 
> > > > > __attribute((aligned(1ULL<<32))) = {};` ignores the alignment.)
> > > > The following function generated by tablegen (and a few others directly 
> > > > or indirectly calling the function) returns a 32-bit int, but it should 
> > > > be returning a 64-bit int.
> > > > 
> > > > https://github.com/llvm/llvm-project/blob/main/clang/utils/TableGen/ClangAttrEmitter.cpp#L532
> > > Filed https://github.com/llvm/llvm-project/issues/60752 so we don't lose 
> > > track of this.
> > I just realized we can't reduce the number of bits used for alignment here 
> > as we need 6 bits for alignment of `1 << 32`.
> > 
> > Should we allocate additional memory when `AlignLog` is either 31 or 32? If 
> > the 5-bit alignment is equal to `0b1`, it would mean that there is an 
> > out-of-line storage large enough to hold the alignment and any other extra 
> > information that is needed. I think 
> > https://reviews.llvm.org/D117262#3267899 proposes a similar idea.
> How much does `sizeof(Address)` actually matter, anyway?  If it's going to 
> get that nasty to implement the packing, I'm not sure it's worth the effort 
> to optimize.
I'm not sure, but apparently https://reviews.llvm.org/D117262 was needed to 
reduce the memory usage.

I don't see a significant increase in stack usage (a little over 1%) in the 
files in `clang/lib/CodeGen` when I build clang with `-fstack-usage`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

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


[PATCH] D139741: [clang][CodeGen] Use base subobject type layout for potentially-overlapping fields

2023-02-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139741

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


[PATCH] D140508: [clang] fix -Wuninitialized for asm goto outputs on indirect edges.

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf6656338db3: [clang] fix -Wuninitialized for asm goto 
outputs on indirect edges. (authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140508

Files:
  clang/lib/Analysis/UninitializedValues.cpp
  clang/test/Analysis/uninit-asm-goto.cpp

Index: clang/test/Analysis/uninit-asm-goto.cpp
===
--- clang/test/Analysis/uninit-asm-goto.cpp
+++ clang/test/Analysis/uninit-asm-goto.cpp
@@ -9,9 +9,9 @@
 return -1;
 }
 
+// test2: Expect no diagnostics
 int test2(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   if (x < 42)
 asm goto("" : "+S"(x), "+D"(y) : "r"(x) :: indirect_1, indirect_2);
   else
@@ -20,29 +20,29 @@
 indirect_1:
   return -42;
 indirect_2:
-  return y; // expected-note {{uninitialized use occurs here}}
+  return y;
 }
 
+// test3: Expect no diagnostics
 int test3(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   asm goto("" : "="(y) : "r"(x) : : fail);
 normal:
   y += x;
   return y;
   if (x) {
 fail:
-return y; // expected-note {{uninitialized use occurs here}}
+return y;
   }
   return 0;
 }
 
+// test4: Expect no diagnostics
 int test4(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   goto forward;
 backward:
-  return y; // expected-note {{uninitialized use occurs here}}
+  return y;
 forward:
   asm goto("" : "=r"(y) : "r"(x) : : backward);
   return y;
@@ -70,23 +70,40 @@
   return -1;
 }
 
+// test7: Expect no diagnostics.
 int test7(int z) {
-int x; // expected-warning {{variable 'x' is used uninitialized whenever its declaration is reached}}
-   // expected-note@-1 {{initialize the variable 'x' to silence this warning}}
+int x;
 if (z)
   asm goto ("":"=r"(x):::A1,A2);
 return 0;
 A1:
 A2:
-return x; // expected-note {{uninitialized use occurs here}}
+return x;
 }
 
+// test8: Expect no diagnostics
 int test8() {
-int x = 0; // expected-warning {{variable 'x' is used uninitialized whenever its declaration is reached}}
-   // expected-note@-1 {{variable 'x' is declared here}}
+int x = 0;
 asm goto ("":"=r"(x):::A1,A2);
 return 0;
 A1:
 A2:
-return x; // expected-note {{uninitialized use occurs here}}
+return x;
+}
+
+// test9: Expect no diagnostics
+int test9 (int x) {
+int y;
+asm goto("": "=r"(y) :::out);
+return 42;
+out:
+return y;
+}
+
+int test10() {
+  int y; // expected-note {{initialize the variable 'y' to silence this warning}}
+  asm goto(""out);
+  return 42;
+out:
+  return y; // expected-warning {{variable 'y' is uninitialized when used here}}
 }
Index: clang/lib/Analysis/UninitializedValues.cpp
===
--- clang/lib/Analysis/UninitializedValues.cpp
+++ clang/lib/Analysis/UninitializedValues.cpp
@@ -586,28 +586,6 @@
   continue;
 }
 
-if (AtPredExit == MayUninitialized) {
-  // If the predecessor's terminator is an "asm goto" that initializes
-  // the variable, then don't count it as "initialized" on the indirect
-  // paths.
-  CFGTerminator term = Pred->getTerminator();
-  if (const auto *as = dyn_cast_or_null(term.getStmt())) {
-const CFGBlock *fallthrough = *Pred->succ_begin();
-if (as->isAsmGoto() &&
-llvm::any_of(as->outputs(), [&](const Expr *output) {
-return vd == findVar(output).getDecl() &&
-llvm::any_of(as->labels(),
- [&](const AddrLabelExpr *label) {
-  return label->getLabel()->getStmt() == B->Label &&
-  B != fallthrough;
-});
-})) {
-  Use.setUninitAfterDecl();
-  continue;
-}
-  }
-}
-
 unsigned  = SuccsVisited[Pred->getBlockID()];
 if (!SV) {
   // When visiting the first successor of a block, mark all NULL
@@ -820,7 +798,8 @@
 // it's used on an indirect path, where it's not guaranteed to be
 // defined.
 if (const VarDecl *VD = findVar(Ex).getDecl())
-  vals[VD] = MayUninitialized;
+  if (vals[VD] != Initialized)
+vals[VD] = MayUninitialized;
   }
 }
 
___
cfe-commits mailing list

[PATCH] D143205: [clang] add __has_extension(gnu_asm_goto_with_outputs_full)

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG54186d33c3a0: [clang] add 
__has_extension(gnu_asm_goto_with_outputs_full) (authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143205

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Features.def
  clang/test/Parser/asm-goto.c


Index: clang/test/Parser/asm-goto.c
===
--- clang/test/Parser/asm-goto.c
+++ clang/test/Parser/asm-goto.c
@@ -7,6 +7,9 @@
 #if !__has_extension(gnu_asm_goto_with_outputs)
 #error Extension 'gnu_asm_goto_with_outputs' should be available by default
 #endif
+#if !__has_extension(gnu_asm_goto_with_outputs_full)
+#error Extension 'gnu_asm_goto_with_outputs_full' should be available by 
default
+#endif
 
 int a, b, c, d, e, f, g, h, i, j, k, l;
 
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -268,6 +268,7 @@
 EXTENSION(statement_attributes_with_gnu_syntax, true)
 EXTENSION(gnu_asm, LangOpts.GNUAsm)
 EXTENSION(gnu_asm_goto_with_outputs, LangOpts.GNUAsm)
+EXTENSION(gnu_asm_goto_with_outputs_full, LangOpts.GNUAsm)
 EXTENSION(matrix_types, LangOpts.MatrixTypes)
 EXTENSION(matrix_types_scalar_division, true)
 EXTENSION(cxx_attributes_on_using_declarations, LangOpts.CPlusPlus11)
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1591,6 +1591,12 @@
 Outputs may be used along any branches from the ``asm goto`` whether the
 branches are taken or not.
 
+Query for this feature with ``__has_extension(gnu_asm_goto_with_outputs)``.
+
+Prior to clang-16, the output may only be used safely when the indirect
+branches are not taken.  Query for this difference with
+``__has_extension(gnu_asm_goto_with_outputs_full)``.
+
 When using tied-outputs (i.e. outputs that are inputs and outputs, not just
 outputs) with the `+r` constraint, there is a hidden input that's created
 before the label, so numeric references to operands must account for that.
@@ -1618,8 +1624,6 @@
   return -1;
   }
 
-Query for this feature with ``__has_extension(gnu_asm_goto_with_outputs)``.
-
 Objective-C Features
 
 


Index: clang/test/Parser/asm-goto.c
===
--- clang/test/Parser/asm-goto.c
+++ clang/test/Parser/asm-goto.c
@@ -7,6 +7,9 @@
 #if !__has_extension(gnu_asm_goto_with_outputs)
 #error Extension 'gnu_asm_goto_with_outputs' should be available by default
 #endif
+#if !__has_extension(gnu_asm_goto_with_outputs_full)
+#error Extension 'gnu_asm_goto_with_outputs_full' should be available by default
+#endif
 
 int a, b, c, d, e, f, g, h, i, j, k, l;
 
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -268,6 +268,7 @@
 EXTENSION(statement_attributes_with_gnu_syntax, true)
 EXTENSION(gnu_asm, LangOpts.GNUAsm)
 EXTENSION(gnu_asm_goto_with_outputs, LangOpts.GNUAsm)
+EXTENSION(gnu_asm_goto_with_outputs_full, LangOpts.GNUAsm)
 EXTENSION(matrix_types, LangOpts.MatrixTypes)
 EXTENSION(matrix_types_scalar_division, true)
 EXTENSION(cxx_attributes_on_using_declarations, LangOpts.CPlusPlus11)
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1591,6 +1591,12 @@
 Outputs may be used along any branches from the ``asm goto`` whether the
 branches are taken or not.
 
+Query for this feature with ``__has_extension(gnu_asm_goto_with_outputs)``.
+
+Prior to clang-16, the output may only be used safely when the indirect
+branches are not taken.  Query for this difference with
+``__has_extension(gnu_asm_goto_with_outputs_full)``.
+
 When using tied-outputs (i.e. outputs that are inputs and outputs, not just
 outputs) with the `+r` constraint, there is a hidden input that's created
 before the label, so numeric references to operands must account for that.
@@ -1618,8 +1624,6 @@
   return -1;
   }
 
-Query for this feature with ``__has_extension(gnu_asm_goto_with_outputs)``.
-
 Objective-C Features
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136497: [Clang] support for outputs along indirect edges of asm goto

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG329ef60f3e21: [Clang] support for outputs along indirect 
edges of asm goto (authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136497

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/asm-goto.c
  clang/test/CodeGen/asm-goto2.c
  clang/test/Modules/asm-goto.c

Index: clang/test/Modules/asm-goto.c
===
--- clang/test/Modules/asm-goto.c
+++ clang/test/Modules/asm-goto.c
@@ -5,7 +5,7 @@
 
 // CHECK-LABEL: define {{.*}} @foo(
 // CHECK: callbr {{.*}} "=r,!i{{.*}}()
-// CHECK-NEXT: to label %asm.fallthrough [label %indirect]
+// CHECK-NEXT: to label %asm.fallthrough [label %indirect.split]
 
 int bar(void) {
   return foo();
Index: clang/test/CodeGen/asm-goto2.c
===
--- /dev/null
+++ clang/test/CodeGen/asm-goto2.c
@@ -0,0 +1,156 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -O0 -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: @test0(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr i32 asm "", "=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1:[0-9]+]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !2
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:store i32 [[TMP0]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 42, ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+// CHECK:   z.split:
+// CHECK-NEXT:store i32 [[TMP0]], ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z]]
+//
+int test0 (void) {
+  int ret;
+  asm goto ("" : "=r"(ret):::z);
+  ret = 42;
+z:
+  return ret;
+}
+
+// CHECK-LABEL: @test1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !3
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:[[ASMRESULT:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT1:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT1]], ptr [[B]], align 4
+// CHECK-NEXT:store i32 42, ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+// CHECK:   z.split:
+// CHECK-NEXT:[[ASMRESULT2:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT3:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT2]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT3]], ptr [[B]], align 4
+// CHECK-NEXT:br label [[Z]]
+//
+int test1 (void) {
+  int ret, b;
+  asm goto ("" : "=r"(ret), "=r"(b):::z);
+  ret = 42;
+z:
+  return ret;
+}
+
+// CHECK-LABEL: @test2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !4
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:[[ASMRESULT:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT1:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT1]], ptr [[B]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH4:%.*]] [label %z.split9], !srcloc !5
+// CHECK:   asm.fallthrough4:
+// CHECK-NEXT:[[ASMRESULT5:%.*]] = extractvalue { i32, i32 } [[TMP1]], 0
+// CHECK-NEXT:[[ASMRESULT6:%.*]] = extractvalue { i32, i32 } [[TMP1]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT5]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT6]], ptr [[B]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP2]]
+// CHECK:   z.split:
+// CHECK-NEXT:[[ASMRESULT2:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:

[PATCH] D137113: [Clang] refactor CodeGenFunction::EmitAsmStmt NFC

2023-02-16 Thread Nick Desaulniers 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 rGb1bc723dfe97: [Clang] refactor CodeGenFunction::EmitAsmStmt 
NFC (authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137113

Files:
  clang/lib/CodeGen/CGStmt.cpp

Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Assumptions.h"
@@ -2327,6 +2328,93 @@
   }
 }
 
+static void
+EmitAsmStores(CodeGenFunction , const AsmStmt ,
+  const llvm::ArrayRef RegResults,
+  const llvm::ArrayRef ResultRegTypes,
+  const llvm::ArrayRef ResultTruncRegTypes,
+  const llvm::ArrayRef ResultRegDests,
+  const llvm::ArrayRef ResultRegQualTys,
+  const llvm::BitVector ,
+  const llvm::BitVector ) {
+  CGBuilderTy  = CGF.Builder;
+  CodeGenModule  = CGF.CGM;
+  llvm::LLVMContext  = CGF.getLLVMContext();
+
+  assert(RegResults.size() == ResultRegTypes.size());
+  assert(RegResults.size() == ResultTruncRegTypes.size());
+  assert(RegResults.size() == ResultRegDests.size());
+  // ResultRegDests can be also populated by addReturnRegisterOutputs() above,
+  // in which case its size may grow.
+  assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
+  assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
+
+  for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
+llvm::Value *Tmp = RegResults[i];
+llvm::Type *TruncTy = ResultTruncRegTypes[i];
+
+if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
+  // Target must guarantee the Value `Tmp` here is lowered to a boolean
+  // value.
+  llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2);
+  llvm::Value *IsBooleanValue =
+  Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, Two);
+  llvm::Function *FnAssume = CGM.getIntrinsic(llvm::Intrinsic::assume);
+  Builder.CreateCall(FnAssume, IsBooleanValue);
+}
+
+// If the result type of the LLVM IR asm doesn't match the result type of
+// the expression, do the conversion.
+if (ResultRegTypes[i] != TruncTy) {
+
+  // Truncate the integer result to the right size, note that TruncTy can be
+  // a pointer.
+  if (TruncTy->isFloatingPointTy())
+Tmp = Builder.CreateFPTrunc(Tmp, TruncTy);
+  else if (TruncTy->isPointerTy() && Tmp->getType()->isIntegerTy()) {
+uint64_t ResSize = CGM.getDataLayout().getTypeSizeInBits(TruncTy);
+Tmp = Builder.CreateTrunc(
+Tmp, llvm::IntegerType::get(CTX, (unsigned)ResSize));
+Tmp = Builder.CreateIntToPtr(Tmp, TruncTy);
+  } else if (Tmp->getType()->isPointerTy() && TruncTy->isIntegerTy()) {
+uint64_t TmpSize =
+CGM.getDataLayout().getTypeSizeInBits(Tmp->getType());
+Tmp = Builder.CreatePtrToInt(
+Tmp, llvm::IntegerType::get(CTX, (unsigned)TmpSize));
+Tmp = Builder.CreateTrunc(Tmp, TruncTy);
+  } else if (TruncTy->isIntegerTy()) {
+Tmp = Builder.CreateZExtOrTrunc(Tmp, TruncTy);
+  } else if (TruncTy->isVectorTy()) {
+Tmp = Builder.CreateBitCast(Tmp, TruncTy);
+  }
+}
+
+LValue Dest = ResultRegDests[i];
+// ResultTypeRequiresCast elements correspond to the first
+// ResultTypeRequiresCast.size() elements of RegResults.
+if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
+  unsigned Size = CGF.getContext().getTypeSize(ResultRegQualTys[i]);
+  Address A =
+  Builder.CreateElementBitCast(Dest.getAddress(CGF), ResultRegTypes[i]);
+  if (CGF.getTargetHooks().isScalarizableAsmOperand(CGF, TruncTy)) {
+Builder.CreateStore(Tmp, A);
+continue;
+  }
+
+  QualType Ty =
+  CGF.getContext().getIntTypeForBitwidth(Size, /*Signed=*/false);
+  if (Ty.isNull()) {
+const Expr *OutExpr = S.getOutputExpr(i);
+CGM.getDiags().Report(OutExpr->getExprLoc(),
+  diag::err_store_value_to_reg);
+return;
+  }
+  Dest = CGF.MakeAddrLValue(A, Ty);
+}
+CGF.EmitStoreThroughLValue(RValue::get(Tmp), Dest);
+  }
+}
+
 void CodeGenFunction::EmitAsmStmt(const AsmStmt ) {
   // Pop all cleanup blocks at the end of the asm statement.
   CodeGenFunction::RunCleanupsScope Cleanups(*this);
@@ -2627,7 +2715,7 @@
   SmallVector Transfer;
   llvm::BasicBlock *Fallthrough = nullptr;
   bool IsGCCAsmGoto = false;
-  if (const auto *GS =  dyn_cast()) {
+  if 

[clang] af66563 - [clang] fix -Wuninitialized for asm goto outputs on indirect edges.

2023-02-16 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2023-02-16T17:58:35-08:00
New Revision: af6656338db365fde6c0b0e53db8f98aa8ed59d4

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

LOG: [clang] fix -Wuninitialized for asm goto outputs on indirect edges.

Now that we support outputs from asm goto along indirect edges, we can
remove/revert some code that was added to help warn about the previous
limitation that outputs were not supported along indirect edges.

Reverts some code added in:
commit 72aa619a7fe0 ("Warn of uninitialized variables on asm goto's indirect 
branch")
commit 3a604fdbcd5f ("[Clang][CFG] check children statements of asm goto")
But keeps+updates the tests.

Link: https://github.com/llvm/llvm-project/issues/53562

Reviewed By: void

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

Added: 


Modified: 
clang/lib/Analysis/UninitializedValues.cpp
clang/test/Analysis/uninit-asm-goto.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UninitializedValues.cpp 
b/clang/lib/Analysis/UninitializedValues.cpp
index 2437095a22cf5..87765db0c5b2f 100644
--- a/clang/lib/Analysis/UninitializedValues.cpp
+++ b/clang/lib/Analysis/UninitializedValues.cpp
@@ -586,28 +586,6 @@ class TransferFunctions : public 
StmtVisitor {
   continue;
 }
 
-if (AtPredExit == MayUninitialized) {
-  // If the predecessor's terminator is an "asm goto" that initializes
-  // the variable, then don't count it as "initialized" on the indirect
-  // paths.
-  CFGTerminator term = Pred->getTerminator();
-  if (const auto *as = dyn_cast_or_null(term.getStmt())) {
-const CFGBlock *fallthrough = *Pred->succ_begin();
-if (as->isAsmGoto() &&
-llvm::any_of(as->outputs(), [&](const Expr *output) {
-return vd == findVar(output).getDecl() &&
-llvm::any_of(as->labels(),
- [&](const AddrLabelExpr *label) {
-  return label->getLabel()->getStmt() == B->Label &&
-  B != fallthrough;
-});
-})) {
-  Use.setUninitAfterDecl();
-  continue;
-}
-  }
-}
-
 unsigned  = SuccsVisited[Pred->getBlockID()];
 if (!SV) {
   // When visiting the first successor of a block, mark all NULL
@@ -820,7 +798,8 @@ void TransferFunctions::VisitGCCAsmStmt(GCCAsmStmt *as) {
 // it's used on an indirect path, where it's not guaranteed to be
 // defined.
 if (const VarDecl *VD = findVar(Ex).getDecl())
-  vals[VD] = MayUninitialized;
+  if (vals[VD] != Initialized)
+vals[VD] = MayUninitialized;
   }
 }
 

diff  --git a/clang/test/Analysis/uninit-asm-goto.cpp 
b/clang/test/Analysis/uninit-asm-goto.cpp
index 1b9d1689b036f..be1a2b3b01dd4 100644
--- a/clang/test/Analysis/uninit-asm-goto.cpp
+++ b/clang/test/Analysis/uninit-asm-goto.cpp
@@ -9,9 +9,9 @@ int test1(int x) {
 return -1;
 }
 
+// test2: Expect no diagnostics
 int test2(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its 
declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   if (x < 42)
 asm goto("" : "+S"(x), "+D"(y) : "r"(x) :: indirect_1, indirect_2);
   else
@@ -20,29 +20,29 @@ int test2(int x) {
 indirect_1:
   return -42;
 indirect_2:
-  return y; // expected-note {{uninitialized use occurs here}}
+  return y;
 }
 
+// test3: Expect no diagnostics
 int test3(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its 
declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   asm goto("" : "="(y) : "r"(x) : : fail);
 normal:
   y += x;
   return y;
   if (x) {
 fail:
-return y; // expected-note {{uninitialized use occurs here}}
+return y;
   }
   return 0;
 }
 
+// test4: Expect no diagnostics
 int test4(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its 
declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   goto forward;
 backward:
-  return y; // expected-note {{uninitialized use occurs here}}
+  return y;
 forward:
   asm goto("" : "=r"(y) : "r"(x) : : backward);
   return y;
@@ -70,23 +70,40 @@ int test6(unsigned int *x) {
   return -1;
 }
 
+// test7: Expect no diagnostics.
 int test7(int z) {
-int x; // expected-warning {{variable 'x' is used uninitialized whenever 
its declaration is reached}}
-   // expected-note@-1 {{initialize the variable 'x' to silence this 
warning}}
+int x;
 if (z)
   asm goto ("":"=r"(x):::A1,A2);
 return 0;
 A1:
 

[clang] 54186d3 - [clang] add __has_extension(gnu_asm_goto_with_outputs_full)

2023-02-16 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2023-02-16T17:58:35-08:00
New Revision: 54186d33c3a0d4834d2e5f95640b63677f5b5142

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

LOG: [clang] add __has_extension(gnu_asm_goto_with_outputs_full)

Also move the line about __has_extension(gnu_asm_goto_with_outputs) so
that it is more generally about asm goto, not the paragraph on symbolic
references.

Reviewed By: efriedma, void

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/Features.def
clang/test/Parser/asm-goto.c

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 0e3aec0584126..2d1b8af40bbb6 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1591,6 +1591,12 @@ ASM Goto with Output Constraints
 Outputs may be used along any branches from the ``asm goto`` whether the
 branches are taken or not.
 
+Query for this feature with ``__has_extension(gnu_asm_goto_with_outputs)``.
+
+Prior to clang-16, the output may only be used safely when the indirect
+branches are not taken.  Query for this 
diff erence with
+``__has_extension(gnu_asm_goto_with_outputs_full)``.
+
 When using tied-outputs (i.e. outputs that are inputs and outputs, not just
 outputs) with the `+r` constraint, there is a hidden input that's created
 before the label, so numeric references to operands must account for that.
@@ -1618,8 +1624,6 @@ references can be used instead of numeric references.
   return -1;
   }
 
-Query for this feature with ``__has_extension(gnu_asm_goto_with_outputs)``.
-
 Objective-C Features
 
 

diff  --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 0581c61dcba3b..56f0b04c6a467 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -268,6 +268,7 @@ EXTENSION(pragma_clang_attribute_external_declaration, true)
 EXTENSION(statement_attributes_with_gnu_syntax, true)
 EXTENSION(gnu_asm, LangOpts.GNUAsm)
 EXTENSION(gnu_asm_goto_with_outputs, LangOpts.GNUAsm)
+EXTENSION(gnu_asm_goto_with_outputs_full, LangOpts.GNUAsm)
 EXTENSION(matrix_types, LangOpts.MatrixTypes)
 EXTENSION(matrix_types_scalar_division, true)
 EXTENSION(cxx_attributes_on_using_declarations, LangOpts.CPlusPlus11)

diff  --git a/clang/test/Parser/asm-goto.c b/clang/test/Parser/asm-goto.c
index f9ad6c5ee9a40..c4cb967907bf2 100644
--- a/clang/test/Parser/asm-goto.c
+++ b/clang/test/Parser/asm-goto.c
@@ -7,6 +7,9 @@
 #if !__has_extension(gnu_asm_goto_with_outputs)
 #error Extension 'gnu_asm_goto_with_outputs' should be available by default
 #endif
+#if !__has_extension(gnu_asm_goto_with_outputs_full)
+#error Extension 'gnu_asm_goto_with_outputs_full' should be available by 
default
+#endif
 
 int a, b, c, d, e, f, g, h, i, j, k, l;
 



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


[clang] 329ef60 - [Clang] support for outputs along indirect edges of asm goto

2023-02-16 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2023-02-16T17:58:34-08:00
New Revision: 329ef60f3e21fd6845e8e8b0da405cae7eb27267

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

LOG: [Clang] support for outputs along indirect edges of asm goto

Initial support for asm goto w/ outputs (D69876) only supported outputs
along the "default" (aka "fallthrough") edge.

We can support outputs along all edges by repeating the same pattern of
stores along the indirect edges that we allready do for the default
edge.  One complication is that these indirect edges may be critical
edges which would need to be split. Another issue is that mid-codgen of
LLVM IR, the control flow graph might not reflect the control flow of
the final function.

To avoid this "chicken and the egg" problem assume that any given
indirect edge may become a critical edge, and pro-actively split it.
This is unnecessary if the edge does not become critical, but LLVM will
optimize such cases via tail duplication.

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

Reviewed By: void

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

Added: 
clang/test/CodeGen/asm-goto2.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CGStmt.cpp
clang/test/CodeGen/asm-goto.c
clang/test/Modules/asm-goto.c

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index faebc024df118..0e3aec0584126 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1588,25 +1588,8 @@ Query for this feature with ``__has_extension(blocks)``.
 ASM Goto with Output Constraints
 
 
-.. note::
-
-  Clang's implementation of ASM goto 
diff ers from `GCC's
-  implementation `_ in
-  that Clang doesn't yet support outputs on the indirect branch. Use of an
-  output on the indirect branch may result in undefined behavior and should be
-  avoided. E.g., in the following `z` isn't valid when used and may have
-  
diff erent values depending on optimization levels. (Clang may not warn about
-  such constructs.)
-
-  .. code-block:: c++
-
-int foo(int x) {
-  int y, z;
-  asm goto(... : "=r"(y), "=r"(z): "r"(x) : : err);
-  return y;
-err:
-  return z;
-}
+Outputs may be used along any branches from the ``asm goto`` whether the
+branches are taken or not.
 
 When using tied-outputs (i.e. outputs that are inputs and outputs, not just
 outputs) with the `+r` constraint, there is a hidden input that's created

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b91a973b9a666..4f2007fcf5715 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -40,6 +40,16 @@ code bases.
 
 C/C++ Language Potentially Breaking Changes
 ---
+- Indirect edges of asm goto statements under certain circumstances may now be
+  split. In previous releases of clang, that means for the following code the
+  two inputs may have compared equal in the inline assembly.  This is no longer
+  guaranteed (and necessary to support outputs along indirect edges, which is
+  now supported as of this release). This change is more consistent with the
+  behavior of GCC.
+
+  .. code-block:: c
+
+foo: asm goto ("# %0 %1"::"i"(&)::foo);
 
 C++ Specific Potentially Breaking Changes
 -
@@ -71,6 +81,9 @@ Resolutions to C++ Defect Reports
 
 C Language Changes
 --
+- Support for outputs from asm goto statements along indirect edges has been
+  added. This fixes
+  `Issue 53562 
+  CBRRegResults;
   if (IsGCCAsmGoto) {
-llvm::CallBrInst *Result =
-Builder.CreateCallBr(IA, Fallthrough, Transfer, Args);
+CBR = Builder.CreateCallBr(IA, Fallthrough, Transfer, Args);
 EmitBlock(Fallthrough);
-

[clang] b1bc723 - [Clang] refactor CodeGenFunction::EmitAsmStmt NFC

2023-02-16 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2023-02-16T17:58:34-08:00
New Revision: b1bc723dfe9734a8b3157dbf50328b5d62436bd6

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

LOG: [Clang] refactor CodeGenFunction::EmitAsmStmt NFC

Prerequisite to further modifications in D136497.

Basically, there is a large body of code in CodeGenFunction::EmitAsmStmt
for emitting stores of outputs. We want to be able to repeat this logic,
for each destination of a callbr (rather than just the default
destination which is what the code currently does).

Also does some smaller cleanups like whitespace cleanups, and removing
pointless casts.

Reviewed By: void, jyknight

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmt.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 248ffb5440147..dfe5abcfe2761 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Assumptions.h"
@@ -2327,6 +2328,93 @@ static void UpdateAsmCallInst(llvm::CallBase , 
bool HasSideEffect,
   }
 }
 
+static void
+EmitAsmStores(CodeGenFunction , const AsmStmt ,
+  const llvm::ArrayRef RegResults,
+  const llvm::ArrayRef ResultRegTypes,
+  const llvm::ArrayRef ResultTruncRegTypes,
+  const llvm::ArrayRef ResultRegDests,
+  const llvm::ArrayRef ResultRegQualTys,
+  const llvm::BitVector ,
+  const llvm::BitVector ) {
+  CGBuilderTy  = CGF.Builder;
+  CodeGenModule  = CGF.CGM;
+  llvm::LLVMContext  = CGF.getLLVMContext();
+
+  assert(RegResults.size() == ResultRegTypes.size());
+  assert(RegResults.size() == ResultTruncRegTypes.size());
+  assert(RegResults.size() == ResultRegDests.size());
+  // ResultRegDests can be also populated by addReturnRegisterOutputs() above,
+  // in which case its size may grow.
+  assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
+  assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
+
+  for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
+llvm::Value *Tmp = RegResults[i];
+llvm::Type *TruncTy = ResultTruncRegTypes[i];
+
+if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
+  // Target must guarantee the Value `Tmp` here is lowered to a boolean
+  // value.
+  llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2);
+  llvm::Value *IsBooleanValue =
+  Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, Two);
+  llvm::Function *FnAssume = CGM.getIntrinsic(llvm::Intrinsic::assume);
+  Builder.CreateCall(FnAssume, IsBooleanValue);
+}
+
+// If the result type of the LLVM IR asm doesn't match the result type of
+// the expression, do the conversion.
+if (ResultRegTypes[i] != TruncTy) {
+
+  // Truncate the integer result to the right size, note that TruncTy can 
be
+  // a pointer.
+  if (TruncTy->isFloatingPointTy())
+Tmp = Builder.CreateFPTrunc(Tmp, TruncTy);
+  else if (TruncTy->isPointerTy() && Tmp->getType()->isIntegerTy()) {
+uint64_t ResSize = CGM.getDataLayout().getTypeSizeInBits(TruncTy);
+Tmp = Builder.CreateTrunc(
+Tmp, llvm::IntegerType::get(CTX, (unsigned)ResSize));
+Tmp = Builder.CreateIntToPtr(Tmp, TruncTy);
+  } else if (Tmp->getType()->isPointerTy() && TruncTy->isIntegerTy()) {
+uint64_t TmpSize =
+CGM.getDataLayout().getTypeSizeInBits(Tmp->getType());
+Tmp = Builder.CreatePtrToInt(
+Tmp, llvm::IntegerType::get(CTX, (unsigned)TmpSize));
+Tmp = Builder.CreateTrunc(Tmp, TruncTy);
+  } else if (TruncTy->isIntegerTy()) {
+Tmp = Builder.CreateZExtOrTrunc(Tmp, TruncTy);
+  } else if (TruncTy->isVectorTy()) {
+Tmp = Builder.CreateBitCast(Tmp, TruncTy);
+  }
+}
+
+LValue Dest = ResultRegDests[i];
+// ResultTypeRequiresCast elements correspond to the first
+// ResultTypeRequiresCast.size() elements of RegResults.
+if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
+  unsigned Size = CGF.getContext().getTypeSize(ResultRegQualTys[i]);
+  Address A =
+  Builder.CreateElementBitCast(Dest.getAddress(CGF), 
ResultRegTypes[i]);
+  if (CGF.getTargetHooks().isScalarizableAsmOperand(CGF, TruncTy)) {
+Builder.CreateStore(Tmp, A);
+continue;
+  }
+
+  QualType Ty =
+  CGF.getContext().getIntTypeForBitwidth(Size, /*Signed=*/false);
+ 

[PATCH] D143919: [Clang] Copy strictfp attribute from pattern to instantiation

2023-02-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:824
+  continue;
+}
+

sepavloff wrote:
> efriedma wrote:
> > Is this necessary?  The non-delayed-parsed case seems to work correctly on 
> > trunk without any changes, so I suspect the autogenerated 
> > sema::instantiateTemplateAttribute is doing the right thing.
> Yes, it is necessary. Without it the code from the added test crashes, as 
> constrained intrinsic is used in a function without strictfp attribute.
https://godbolt.org/z/MvPrejY75 indicates this is only an issue with 
-fdelayed-template-parsing; am I missing something?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143919

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


[PATCH] D144188: Tighten up a modules test

2023-02-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


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

https://reviews.llvm.org/D144188

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


[PATCH] D137113: [Clang] refactor CodeGenFunction::EmitAsmStmt NFC

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 498209.
nickdesaulniers marked an inline comment as done.
nickdesaulniers added a comment.

- fix bugprone-argument-comment as per @shafik


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137113

Files:
  clang/lib/CodeGen/CGStmt.cpp

Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Assumptions.h"
@@ -2327,6 +2328,93 @@
   }
 }
 
+static void
+EmitAsmStores(CodeGenFunction , const AsmStmt ,
+  const llvm::ArrayRef RegResults,
+  const llvm::ArrayRef ResultRegTypes,
+  const llvm::ArrayRef ResultTruncRegTypes,
+  const llvm::ArrayRef ResultRegDests,
+  const llvm::ArrayRef ResultRegQualTys,
+  const llvm::BitVector ,
+  const llvm::BitVector ) {
+  CGBuilderTy  = CGF.Builder;
+  CodeGenModule  = CGF.CGM;
+  llvm::LLVMContext  = CGF.getLLVMContext();
+
+  assert(RegResults.size() == ResultRegTypes.size());
+  assert(RegResults.size() == ResultTruncRegTypes.size());
+  assert(RegResults.size() == ResultRegDests.size());
+  // ResultRegDests can be also populated by addReturnRegisterOutputs() above,
+  // in which case its size may grow.
+  assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
+  assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
+
+  for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
+llvm::Value *Tmp = RegResults[i];
+llvm::Type *TruncTy = ResultTruncRegTypes[i];
+
+if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
+  // Target must guarantee the Value `Tmp` here is lowered to a boolean
+  // value.
+  llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2);
+  llvm::Value *IsBooleanValue =
+  Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, Two);
+  llvm::Function *FnAssume = CGM.getIntrinsic(llvm::Intrinsic::assume);
+  Builder.CreateCall(FnAssume, IsBooleanValue);
+}
+
+// If the result type of the LLVM IR asm doesn't match the result type of
+// the expression, do the conversion.
+if (ResultRegTypes[i] != TruncTy) {
+
+  // Truncate the integer result to the right size, note that TruncTy can be
+  // a pointer.
+  if (TruncTy->isFloatingPointTy())
+Tmp = Builder.CreateFPTrunc(Tmp, TruncTy);
+  else if (TruncTy->isPointerTy() && Tmp->getType()->isIntegerTy()) {
+uint64_t ResSize = CGM.getDataLayout().getTypeSizeInBits(TruncTy);
+Tmp = Builder.CreateTrunc(
+Tmp, llvm::IntegerType::get(CTX, (unsigned)ResSize));
+Tmp = Builder.CreateIntToPtr(Tmp, TruncTy);
+  } else if (Tmp->getType()->isPointerTy() && TruncTy->isIntegerTy()) {
+uint64_t TmpSize =
+CGM.getDataLayout().getTypeSizeInBits(Tmp->getType());
+Tmp = Builder.CreatePtrToInt(
+Tmp, llvm::IntegerType::get(CTX, (unsigned)TmpSize));
+Tmp = Builder.CreateTrunc(Tmp, TruncTy);
+  } else if (TruncTy->isIntegerTy()) {
+Tmp = Builder.CreateZExtOrTrunc(Tmp, TruncTy);
+  } else if (TruncTy->isVectorTy()) {
+Tmp = Builder.CreateBitCast(Tmp, TruncTy);
+  }
+}
+
+LValue Dest = ResultRegDests[i];
+// ResultTypeRequiresCast elements correspond to the first
+// ResultTypeRequiresCast.size() elements of RegResults.
+if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
+  unsigned Size = CGF.getContext().getTypeSize(ResultRegQualTys[i]);
+  Address A =
+  Builder.CreateElementBitCast(Dest.getAddress(CGF), ResultRegTypes[i]);
+  if (CGF.getTargetHooks().isScalarizableAsmOperand(CGF, TruncTy)) {
+Builder.CreateStore(Tmp, A);
+continue;
+  }
+
+  QualType Ty =
+  CGF.getContext().getIntTypeForBitwidth(Size, /*Signed=*/false);
+  if (Ty.isNull()) {
+const Expr *OutExpr = S.getOutputExpr(i);
+CGM.getDiags().Report(OutExpr->getExprLoc(),
+  diag::err_store_value_to_reg);
+return;
+  }
+  Dest = CGF.MakeAddrLValue(A, Ty);
+}
+CGF.EmitStoreThroughLValue(RValue::get(Tmp), Dest);
+  }
+}
+
 void CodeGenFunction::EmitAsmStmt(const AsmStmt ) {
   // Pop all cleanup blocks at the end of the asm statement.
   CodeGenFunction::RunCleanupsScope Cleanups(*this);
@@ -2627,7 +2715,7 @@
   SmallVector Transfer;
   llvm::BasicBlock *Fallthrough = nullptr;
   bool IsGCCAsmGoto = false;
-  if (const auto *GS =  dyn_cast()) {
+  if (const auto *GS = dyn_cast()) {
 IsGCCAsmGoto = 

[PATCH] D144169: [WebAssembly] Fix simd bit shift intrinsics codegen

2023-02-16 Thread JunMa via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf253bb640d97: [WebAssembly] Fix simd bit shift intrinsics 
codegen (authored by junparser).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144169

Files:
  clang/lib/Headers/wasm_simd128.h
  clang/test/Headers/wasm.c

Index: clang/test/Headers/wasm.c
===
--- clang/test/Headers/wasm.c
+++ clang/test/Headers/wasm.c
@@ -1584,11 +1584,12 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <16 x i8>
 // CHECK-NEXT:[[TMP1:%.*]] = trunc i32 [[B:%.*]] to i8
-// CHECK-NEXT:[[TMP2:%.*]] = insertelement <16 x i8> undef, i8 [[TMP1]], i64 0
-// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP2]], <16 x i8> poison, <16 x i32> zeroinitializer
+// CHECK-NEXT:[[TMP2:%.*]] = and i8 [[TMP1]], 7
+// CHECK-NEXT:[[TMP3:%.*]] = insertelement <16 x i8> undef, i8 [[TMP2]], i64 0
+// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP3]], <16 x i8> poison, <16 x i32> zeroinitializer
 // CHECK-NEXT:[[SHL_I:%.*]] = shl <16 x i8> [[TMP0]], [[SH_PROM_I]]
-// CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[SHL_I]] to <4 x i32>
-// CHECK-NEXT:ret <4 x i32> [[TMP3]]
+// CHECK-NEXT:[[TMP4:%.*]] = bitcast <16 x i8> [[SHL_I]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP4]]
 //
 v128_t test_i8x16_shl(v128_t a, uint32_t b) {
   return wasm_i8x16_shl(a, b);
@@ -1598,11 +1599,12 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <16 x i8>
 // CHECK-NEXT:[[TMP1:%.*]] = trunc i32 [[B:%.*]] to i8
-// CHECK-NEXT:[[TMP2:%.*]] = insertelement <16 x i8> undef, i8 [[TMP1]], i64 0
-// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP2]], <16 x i8> poison, <16 x i32> zeroinitializer
+// CHECK-NEXT:[[TMP2:%.*]] = and i8 [[TMP1]], 7
+// CHECK-NEXT:[[TMP3:%.*]] = insertelement <16 x i8> undef, i8 [[TMP2]], i64 0
+// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP3]], <16 x i8> poison, <16 x i32> zeroinitializer
 // CHECK-NEXT:[[SHR_I:%.*]] = ashr <16 x i8> [[TMP0]], [[SH_PROM_I]]
-// CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[SHR_I]] to <4 x i32>
-// CHECK-NEXT:ret <4 x i32> [[TMP3]]
+// CHECK-NEXT:[[TMP4:%.*]] = bitcast <16 x i8> [[SHR_I]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP4]]
 //
 v128_t test_i8x16_shr(v128_t a, uint32_t b) {
   return wasm_i8x16_shr(a, b);
@@ -1612,11 +1614,12 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <16 x i8>
 // CHECK-NEXT:[[TMP1:%.*]] = trunc i32 [[B:%.*]] to i8
-// CHECK-NEXT:[[TMP2:%.*]] = insertelement <16 x i8> undef, i8 [[TMP1]], i64 0
-// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP2]], <16 x i8> poison, <16 x i32> zeroinitializer
+// CHECK-NEXT:[[TMP2:%.*]] = and i8 [[TMP1]], 7
+// CHECK-NEXT:[[TMP3:%.*]] = insertelement <16 x i8> undef, i8 [[TMP2]], i64 0
+// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP3]], <16 x i8> poison, <16 x i32> zeroinitializer
 // CHECK-NEXT:[[SHR_I:%.*]] = lshr <16 x i8> [[TMP0]], [[SH_PROM_I]]
-// CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[SHR_I]] to <4 x i32>
-// CHECK-NEXT:ret <4 x i32> [[TMP3]]
+// CHECK-NEXT:[[TMP4:%.*]] = bitcast <16 x i8> [[SHR_I]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP4]]
 //
 v128_t test_u8x16_shr(v128_t a, uint32_t b) {
   return wasm_u8x16_shr(a, b);
@@ -1801,11 +1804,12 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <8 x i16>
 // CHECK-NEXT:[[TMP1:%.*]] = trunc i32 [[B:%.*]] to i16
-// CHECK-NEXT:[[TMP2:%.*]] = insertelement <8 x i16> undef, i16 [[TMP1]], i64 0
-// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <8 x i16> [[TMP2]], <8 x i16> poison, <8 x i32> zeroinitializer
+// CHECK-NEXT:[[TMP2:%.*]] = and i16 [[TMP1]], 15
+// CHECK-NEXT:[[TMP3:%.*]] = insertelement <8 x i16> undef, i16 [[TMP2]], i64 0
+// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <8 x i16> [[TMP3]], <8 x i16> poison, <8 x i32> zeroinitializer
 // CHECK-NEXT:[[SHL_I:%.*]] = shl <8 x i16> [[TMP0]], [[SH_PROM_I]]
-// CHECK-NEXT:[[TMP3:%.*]] = bitcast <8 x i16> [[SHL_I]] to <4 x i32>
-// CHECK-NEXT:ret <4 x i32> [[TMP3]]
+// CHECK-NEXT:[[TMP4:%.*]] = bitcast <8 x i16> [[SHL_I]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP4]]
 //
 v128_t test_i16x8_shl(v128_t a, uint32_t b) {
   return wasm_i16x8_shl(a, b);
@@ -1815,11 +1819,12 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <8 x i16>
 // CHECK-NEXT:[[TMP1:%.*]] = trunc i32 [[B:%.*]] to i16
-// CHECK-NEXT:[[TMP2:%.*]] = insertelement <8 x i16> undef, i16 [[TMP1]], i64 0
-// CHECK-NEXT:[[SH_PROM_I:%.*]] = 

[clang] f253bb6 - [WebAssembly] Fix simd bit shift intrinsics codegen

2023-02-16 Thread Jun Ma via cfe-commits

Author: Jun Ma
Date: 2023-02-17T09:17:47+08:00
New Revision: f253bb640d97756d2808bb7c7b2bb31b1090a654

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

LOG: [WebAssembly] Fix simd bit shift intrinsics codegen

According to github.com/WebAssembly/simd/blob/main/proposals/simd/SIMD.md,
the shift count of bit shift instructions is taken modulo lane width.
This patch adds such operation.

Fixes PR#60655

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

Added: 


Modified: 
clang/lib/Headers/wasm_simd128.h
clang/test/Headers/wasm.c

Removed: 




diff  --git a/clang/lib/Headers/wasm_simd128.h 
b/clang/lib/Headers/wasm_simd128.h
index f93de129f9577..a099ab57dc68b 100644
--- a/clang/lib/Headers/wasm_simd128.h
+++ b/clang/lib/Headers/wasm_simd128.h
@@ -961,17 +961,17 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS 
wasm_i8x16_popcnt(v128_t __a) {
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_shl(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__i8x16)__a << __b);
+  return (v128_t)((__i8x16)__a << (__b & 0x7));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_shr(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__i8x16)__a >> __b);
+  return (v128_t)((__i8x16)__a >> (__b & 0x7));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_shr(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__u8x16)__a >> __b);
+  return (v128_t)((__u8x16)__a >> (__b & 0x7));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_add(v128_t __a,
@@ -1047,17 +1047,17 @@ static __inline__ uint32_t __DEFAULT_FN_ATTRS 
wasm_i16x8_bitmask(v128_t __a) {
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_shl(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__i16x8)__a << __b);
+  return (v128_t)((__i16x8)__a << (__b & 0xF));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_shr(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__i16x8)__a >> __b);
+  return (v128_t)((__i16x8)__a >> (__b & 0xF));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u16x8_shr(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__u16x8)__a >> __b);
+  return (v128_t)((__u16x8)__a >> (__b & 0xF));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_add(v128_t __a,
@@ -1138,17 +1138,17 @@ static __inline__ uint32_t __DEFAULT_FN_ATTRS 
wasm_i32x4_bitmask(v128_t __a) {
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i32x4_shl(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__i32x4)__a << __b);
+  return (v128_t)((__i32x4)__a << (__b & 0x1F));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i32x4_shr(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__i32x4)__a >> __b);
+  return (v128_t)((__i32x4)__a >> (__b & 0x1F));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u32x4_shr(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__u32x4)__a >> __b);
+  return (v128_t)((__u32x4)__a >> (__b & 0x1F));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i32x4_add(v128_t __a,
@@ -1209,17 +1209,17 @@ static __inline__ uint32_t __DEFAULT_FN_ATTRS 
wasm_i64x2_bitmask(v128_t __a) {
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i64x2_shl(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__i64x2)__a << (int64_t)__b);
+  return (v128_t)((__i64x2)__a << ((int64_t)__b & 0x3F));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i64x2_shr(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__i64x2)__a >> (int64_t)__b);
+  return (v128_t)((__i64x2)__a >> ((int64_t)__b & 0x3F));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u64x2_shr(v128_t __a,
uint32_t __b) {
-  return (v128_t)((__u64x2)__a >> (int64_t)__b);
+  return (v128_t)((__u64x2)__a >> ((int64_t)__b & 0x3F));
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i64x2_add(v128_t __a,

diff  --git a/clang/test/Headers/wasm.c b/clang/test/Headers/wasm.c
index 42e11e412ea4a..a755499c6c797 100644
--- a/clang/test/Headers/wasm.c
+++ b/clang/test/Headers/wasm.c
@@ -1584,11 +1584,12 @@ v128_t test_i8x16_popcnt(v128_t a) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> 

[clang] e073de8 - [WebAssembly] Update wasm.c with update_cc_test_checks.py. NFC

2023-02-16 Thread Jun Ma via cfe-commits

Author: Jun Ma
Date: 2023-02-17T09:17:47+08:00
New Revision: e073de833671159f89d72a1018d335cc042d

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

LOG: [WebAssembly] Update wasm.c with update_cc_test_checks.py. NFC

Added: 


Modified: 
clang/test/Headers/wasm.c

Removed: 




diff  --git a/clang/test/Headers/wasm.c b/clang/test/Headers/wasm.c
index 8913a273aaeb1..42e11e412ea4a 100644
--- a/clang/test/Headers/wasm.c
+++ b/clang/test/Headers/wasm.c
@@ -1,4 +1,4 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --force-update
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: webassembly-registered-target, asserts
 
 // FIXME: This should not be using -O2 and implicitly testing the entire IR 
opt pipeline.
@@ -1462,8 +1462,8 @@ v128_t test_f64x2_ge(v128_t a, v128_t b) {
 
 // CHECK-LABEL: @test_v128_not(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[NEG_I:%.*]] = xor <4 x i32> [[A:%.*]], 
-// CHECK-NEXT:ret <4 x i32> [[NEG_I]]
+// CHECK-NEXT:[[NOT_I:%.*]] = xor <4 x i32> [[A:%.*]], 
+// CHECK-NEXT:ret <4 x i32> [[NOT_I]]
 //
 v128_t test_v128_not(v128_t a) {
   return wasm_v128_not(a);
@@ -1498,8 +1498,8 @@ v128_t test_v128_xor(v128_t a, v128_t b) {
 
 // CHECK-LABEL: @test_v128_andnot(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[NEG_I:%.*]] = xor <4 x i32> [[B:%.*]], 
-// CHECK-NEXT:[[AND_I:%.*]] = and <4 x i32> [[NEG_I]], [[A:%.*]]
+// CHECK-NEXT:[[NOT_I:%.*]] = xor <4 x i32> [[B:%.*]], 
+// CHECK-NEXT:[[AND_I:%.*]] = and <4 x i32> [[NOT_I]], [[A:%.*]]
 // CHECK-NEXT:ret <4 x i32> [[AND_I]]
 //
 v128_t test_v128_andnot(v128_t a, v128_t b) {
@@ -1529,9 +1529,9 @@ v128_t test_v128_bitselect(v128_t a, v128_t b, v128_t 
mask) {
 // CHECK-LABEL: @test_i8x16_abs(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <16 x i8>
-// CHECK-NEXT:[[TMP1:%.*]] = tail call <16 x i8> @llvm.abs.v16i8(<16 x i8> 
[[TMP0]], i1 false)
-// CHECK-NEXT:[[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <4 x i32>
-// CHECK-NEXT:ret <4 x i32> [[TMP2]]
+// CHECK-NEXT:[[ABS_I:%.*]] = tail call <16 x i8> @llvm.abs.v16i8(<16 x 
i8> [[TMP0]], i1 false)
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <16 x i8> [[ABS_I]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP1]]
 //
 v128_t test_i8x16_abs(v128_t a) {
   return wasm_i8x16_abs(a);
@@ -1757,9 +1757,9 @@ v128_t test_u8x16_avgr(v128_t a, v128_t b) {
 // CHECK-LABEL: @test_i16x8_abs(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <8 x i16>
-// CHECK-NEXT:[[TMP1:%.*]] = tail call <8 x i16> @llvm.abs.v8i16(<8 x i16> 
[[TMP0]], i1 false)
-// CHECK-NEXT:[[TMP2:%.*]] = bitcast <8 x i16> [[TMP1]] to <4 x i32>
-// CHECK-NEXT:ret <4 x i32> [[TMP2]]
+// CHECK-NEXT:[[ABS_I:%.*]] = tail call <8 x i16> @llvm.abs.v8i16(<8 x 
i16> [[TMP0]], i1 false)
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <8 x i16> [[ABS_I]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP1]]
 //
 v128_t test_i16x8_abs(v128_t a) {
   return wasm_i16x8_abs(a);
@@ -1985,8 +1985,8 @@ v128_t test_u16x8_avgr(v128_t a, v128_t b) {
 
 // CHECK-LABEL: @test_i32x4_abs(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call <4 x i32> @llvm.abs.v4i32(<4 x i32> 
[[A:%.*]], i1 false)
-// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+// CHECK-NEXT:[[ABS_I:%.*]] = tail call <4 x i32> @llvm.abs.v4i32(<4 x 
i32> [[A:%.*]], i1 false)
+// CHECK-NEXT:ret <4 x i32> [[ABS_I]]
 //
 v128_t test_i32x4_abs(v128_t a) {
   return wasm_i32x4_abs(a);
@@ -2130,9 +2130,9 @@ v128_t test_i32x4_dot_i16x8(v128_t a, v128_t b) {
 // CHECK-LABEL: @test_i64x2_abs(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <2 x i64>
-// CHECK-NEXT:[[TMP1:%.*]] = tail call <2 x i64> @llvm.abs.v2i64(<2 x i64> 
[[TMP0]], i1 false)
-// CHECK-NEXT:[[TMP2:%.*]] = bitcast <2 x i64> [[TMP1]] to <4 x i32>
-// CHECK-NEXT:ret <4 x i32> [[TMP2]]
+// CHECK-NEXT:[[ABS_I:%.*]] = tail call <2 x i64> @llvm.abs.v2i64(<2 x 
i64> [[TMP0]], i1 false)
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <2 x i64> [[ABS_I]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP1]]
 //
 v128_t test_i64x2_abs(v128_t a) {
   return wasm_i64x2_abs(a);



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


[PATCH] D143704: [Flang] Part one of Feature List action

2023-02-16 Thread Ethan Luis McDonough via Phabricator via cfe-commits
elmcdonough added a comment.

Thank you all for your feedback.  We're putting the second part off for now and 
I'm going to retool this as a plugin.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143704

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


[PATCH] D144003: [clang][analyzer] Improve bug reports of StdLibraryFunctionsChecker.

2023-02-16 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.

Looks like a massive improvement. Yes, the warning text traditionally focuses 
on what exactly is wrong. Describing why it's wrong is important as well, but 
usually less important. We're making an extraordinary statement that the 
program is wrong, so warning with path notes should look like a proof of that:

> "Indeed, let's assume 'x' is greater than 0, Then the program takes true 
> branch on this if-statement. Then it assigns value '0' to pointer 'p'. Which 
> brings us to the statement '*p = 1' three lines below. Pointer 'p' is null, 
> so the program will crash. **// Therefore your code is broken, Q.E.D.**

It should not end with a general recommendation:

> "Indeed, let's assume 'x' is greater than 0. Then the program takes true 
> branch on this if-statement. Then it assigns value '0' to pointer 'p'. Which 
> brings us to the statement '*p = 1' three lines below. Null pointers should 
> not be dereferenced." **// I already know that, so what?**

This is especially important because people read reports from bottom to top: 
"Ok, if this happens it's indeed bad, now why do you think this happens?". So 
if they don't understand what happens (in your case, what value *is* there), 
they can't even start asking this question. So this is why I think this patch 
is amazing and it should have been like this from the start.

So if I was to come up with a full warning text myself, I'd probably suggest 
something along the lines of

> `Value 3 passed as 1st parameter of '__range_1_2__4_6', which expects 1 or 2, 
> or 4, 5 or 6`
> `Negative value passed as 1st parameter of '__range_1_2__4_6', which expects 
> 1 or 2, or 4, 5 or 6`

or maybe even

> `Variable 'x' passed as 1st parameter to '__range_1_2__4_6' takes values in 
> range [7, 10] whereas expected values for the parameter are 1 or 2, or 4, 5 
> or 6`

so that to explain what happens first, then explain why this is bad later. But 
even without such further improvements, this patch is great.




Comment at: 
clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp:210
+if (x == 3)
+  __range_1_2__4_6(x); // expected-warning{{should be 1 or 2 or 4, 5 or 6 
but is 3 [}}
+return;

I'm definitely not an expert on [[ https://en.wikipedia.org/wiki/Serial_comma | 
Oxford commas ]] but adding one between individual ranges looks valuable as it 
helps the reader understand what makes `5` so special.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144003

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


[PATCH] D142822: [clang] ASTImporter: Fix importing of va_list types and declarations

2023-02-16 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/test/AST/ast-dump-overloaded-operators.cpp:27
 // CHECK-NEXT: | `-ParmVarDecl {{.*}}  col:19{{( imported)?}} 'E'
-// CHECK-NEXT: `-FunctionDecl {{.*}}  line:14:6{{( 
imported)?}} test 'void ()'
+// CHECK-NEXT:  -FunctionDecl {{.*}}  line:14:6{{( 
imported)?}} test 'void ()'
 // CHECK-NEXT:   `-CompoundStmt {{.*}} 

vabridgers wrote:
> donat.nagy wrote:
> > Why did a backtick disappear here and in many other locations? Is this 
> > somehow related to va_list handling?
> this backspace appeared in the original patch submitted by @mizvekov in 
> review https://reviews.llvm.org/D136886, discussed for the test case 
> clang/test/AST/ast-dump-overloaded-operators.cpp between @aaron.ballman and 
> @mizvekov. 
> 
> Comments from that review from @mizvekov
> 
> 
> What is happening here (and in all the other such instances) is that on the 
> import case, this declaration stops being the last one on the TU. So the 
> beginning of the line would match on |- instead of `-, but the non-import 
> case this remains the last one.
> 
> So I simply relaxed the match.
> 
Then make this abundantly clear with
```
{{\||`}}
```
or whatever the right escaping is (which, incidentally, I can't figure out how 
to do as inline code in Phabricator...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142822

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


[PATCH] D143670: Stop claiming we support [[carries_dependency]]

2023-02-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Until or unless a C++ DR permits us to define 
`__has_cpp_attribute(carries_dependency)` to any value other than `200809L`, we 
have a conformance requirement to macro-expand this to that value. CWG2695 only 
adds a note, so it changes nothing in this regard. Similarly, we have a 
conformance requirement to emit a diagnostic on invalid uses of the attribute, 
and per our policy for `-pedantic`, we should produce an error for invalid uses 
under `-pedantic-errors` and not reject valid uses in that mode. So I think we 
still need all of the functionality that this patch removes for conformance 
reasons, for now at least. Maybe WG21 would be receptive to a paper making 
support of `[[carries_dependency]]` optional.

Conformance aside, the meaning of `[[carries_dependency]]` on a particular 
platform is an ABI requirement. On every platform that we support, the psABI 
does not specify any different handling for `[[carries_dependency]]` functions, 
so we *are* implementing the attribute completely and correctly on those 
targets, it just happens to be vacuous. If there were a target that defined a 
different ABI rule, or was anticipated to add such a different ABI rule (eg, 
due to some future PowerPC or ARM ABI change), then it would make sense to stop 
claiming support on those platforms until we implemented the behavior (I have 
the behavior of `[[no_unique_address]]` on MS ABI in mind here particularly). 
But I think it's not helpful to users to say we don't support it because it 
doesn't happen to make a difference on the current target, just it's not 
helpful to say we don't support `[[no_unique_address]]` just because it doesn't 
affect struct layout on a particular target, or -- more to the point -- it 
wouldn't be helpful to say we don't support `consume` memory ordering just 
because we don't get any benefit from it on the current target compared to 
`acquire` (and as a result, we lower `consume` to `acquire`). I think it's much 
better to let people unconditionally add `[[carries_dependency]]` (or 
`[[no_unique_address]]`, or to use `consume`) when they mean it; that way, if 
they compile their code on both Clang and some other compiler that supports a 
target where the attribute does something, then they'll get the behavior they 
asked for. We shouldn't be encouraging people to wrap uses of standard 
attributes in macros.

That said, even though I think we should claim (vacuous) support for such 
cases, I think it would be reasonable to warn developers that they have no 
effect. For example, we could add a special-case sub-group of 
`-Wignored-attribute` to tell developers that "carries_dependency attribute has 
no effect", because they might be combining it with `consume` and expecting 
improved performance. It's probably even reasonable to turn such a warning on 
by default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143670

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


[PATCH] D144216: [clang-tidy] Extract string header from redundant-string-cstr checker

2023-02-16 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

May be you could use heard in other test in same patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144216

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


[PATCH] D142822: [clang] ASTImporter: Fix importing of va_list types and declarations

2023-02-16 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

@donat.nagy , regarding the namespace leaking, there was a change -> 
https://reviews.llvm.org/D116774 that modified the behavior for aarch64 and 
arm. While not incorrect, it may offer some historical view or examples of how 
to address the current cases.

@whisperity , I'll try your advice and post the results.




Comment at: clang/test/AST/ast-dump-overloaded-operators.cpp:27
 // CHECK-NEXT: | `-ParmVarDecl {{.*}}  col:19{{( imported)?}} 'E'
-// CHECK-NEXT: `-FunctionDecl {{.*}}  line:14:6{{( 
imported)?}} test 'void ()'
+// CHECK-NEXT:  -FunctionDecl {{.*}}  line:14:6{{( 
imported)?}} test 'void ()'
 // CHECK-NEXT:   `-CompoundStmt {{.*}} 

donat.nagy wrote:
> Why did a backtick disappear here and in many other locations? Is this 
> somehow related to va_list handling?
this backspace appeared in the original patch submitted by @mizvekov in review 
https://reviews.llvm.org/D136886, discussed for the test case 
clang/test/AST/ast-dump-overloaded-operators.cpp between @aaron.ballman and 
@mizvekov. 

Comments from that review from @mizvekov


What is happening here (and in all the other such instances) is that on the 
import case, this declaration stops being the last one on the TU. So the 
beginning of the line would match on |- instead of `-, but the non-import case 
this remains the last one.

So I simply relaxed the match.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142822

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


[PATCH] D143680: [WIP][-Wunsafe-buffer-usage] Improve fix-its for local variable declarations with null pointer initializers

2023-02-16 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1034-1035
+assert(!InitFixIts.empty() &&
+   "Expected at least one fix-it for an initializer of an unsafe "
+   "variable declaration.");
 // The loc right before the initializer:

NoQ wrote:
> The old check was saying "`populateInitializerFixItWithSpan()` returns `{}` 
> on error". So the new check is additionally saying 
> "`populateInitializerFixItWithSpan()` isn't allowed to have errors anymore", 
> which is arguably the more important message 樂
yeah, I think we are being consistent on using `std::nullopt` to represent 
"something wrong, no fix" and using `{ }` to represent a no-op fix.  So the old 
code is incorrect.


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

https://reviews.llvm.org/D143680

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


[PATCH] D144232: [PowerPC] Correctly use ELFv2 ABI on FreeBSD/powerpc64

2023-02-16 Thread Piotr Kubaj via Phabricator via cfe-commits
pkubaj updated this revision to Diff 498185.
pkubaj added a comment.

Fix indenting according to clang-format suggestions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144232

Files:
  clang/lib/Basic/Targets/PPC.h
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp


Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -233,6 +233,11 @@
   assert(Options.MCOptions.getABIName().empty() &&
  "Unknown target-abi option!");
 
+  if (TT.isOSFreeBSD() && TT.getArch() == Triple::ppc64 &&
+  (TT.getOSMajorVersion() == 0 || TT.getOSMajorVersion() >= 13)) {
+return PPCTargetMachine::PPC_ABI_ELFv2;
+  }
+
   switch (TT.getArch()) {
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -425,6 +425,10 @@
 } else if ((Triple.getArch() == llvm::Triple::ppc64le)) {
   DataLayout = "e-m:e-i64:64-n32:64";
   ABI = "elfv2";
+} else if (Triple.isOSFreeBSD() && (Triple.getOSMajorVersion() == 0 ||
+Triple.getOSMajorVersion() >= 13)) {
+  DataLayout = "E-m:e-i64:64-n32:64";
+  ABI = "elfv2";
 } else {
   DataLayout = "E-m:e-i64:64-n32:64";
   ABI = "elfv1";


Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -233,6 +233,11 @@
   assert(Options.MCOptions.getABIName().empty() &&
  "Unknown target-abi option!");
 
+  if (TT.isOSFreeBSD() && TT.getArch() == Triple::ppc64 &&
+  (TT.getOSMajorVersion() == 0 || TT.getOSMajorVersion() >= 13)) {
+return PPCTargetMachine::PPC_ABI_ELFv2;
+  }
+
   switch (TT.getArch()) {
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -425,6 +425,10 @@
 } else if ((Triple.getArch() == llvm::Triple::ppc64le)) {
   DataLayout = "e-m:e-i64:64-n32:64";
   ABI = "elfv2";
+} else if (Triple.isOSFreeBSD() && (Triple.getOSMajorVersion() == 0 ||
+Triple.getOSMajorVersion() >= 13)) {
+  DataLayout = "E-m:e-i64:64-n32:64";
+  ABI = "elfv2";
 } else {
   DataLayout = "E-m:e-i64:64-n32:64";
   ABI = "elfv1";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144232: [PowerPC] Correctly use ELFv2 ABI on FreeBSD/powerpc64

2023-02-16 Thread Piotr Kubaj via Phabricator via cfe-commits
pkubaj created this revision.
pkubaj added reviewers: dim, nemanjai, adalava.
Herald added subscribers: shchenz, kbarton, hiraditya.
Herald added a project: All.
pkubaj requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Currently ELFv2 is mostly set, but some places still default to ELFv1.
While this mostly works, it breaks in particular when lld is used with LTO,
as reported in https://github.com/llvm/llvm-project/issues/46697.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144232

Files:
  clang/lib/Basic/Targets/PPC.h
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp


Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -233,6 +233,10 @@
   assert(Options.MCOptions.getABIName().empty() &&
  "Unknown target-abi option!");
 
+  if (TT.isOSFreeBSD() && TT.getArch() == Triple::ppc64 && 
(TT.getOSMajorVersion() == 0 || TT.getOSMajorVersion() >= 13)) {
+return PPCTargetMachine::PPC_ABI_ELFv2;
+  }
+
   switch (TT.getArch()) {
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -425,6 +425,9 @@
 } else if ((Triple.getArch() == llvm::Triple::ppc64le)) {
   DataLayout = "e-m:e-i64:64-n32:64";
   ABI = "elfv2";
+} else if (Triple.isOSFreeBSD() && (Triple.getOSMajorVersion() == 0 || 
Triple.getOSMajorVersion() >= 13)) {
+  DataLayout = "E-m:e-i64:64-n32:64";
+  ABI = "elfv2";
 } else {
   DataLayout = "E-m:e-i64:64-n32:64";
   ABI = "elfv1";


Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -233,6 +233,10 @@
   assert(Options.MCOptions.getABIName().empty() &&
  "Unknown target-abi option!");
 
+  if (TT.isOSFreeBSD() && TT.getArch() == Triple::ppc64 && (TT.getOSMajorVersion() == 0 || TT.getOSMajorVersion() >= 13)) {
+return PPCTargetMachine::PPC_ABI_ELFv2;
+  }
+
   switch (TT.getArch()) {
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -425,6 +425,9 @@
 } else if ((Triple.getArch() == llvm::Triple::ppc64le)) {
   DataLayout = "e-m:e-i64:64-n32:64";
   ABI = "elfv2";
+} else if (Triple.isOSFreeBSD() && (Triple.getOSMajorVersion() == 0 || Triple.getOSMajorVersion() >= 13)) {
+  DataLayout = "E-m:e-i64:64-n32:64";
+  ABI = "elfv2";
 } else {
   DataLayout = "E-m:e-i64:64-n32:64";
   ABI = "elfv1";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143301: [flang] Handle unsupported warning flags

2023-02-16 Thread Ethan Luis McDonough via Phabricator via cfe-commits
elmcdonough updated this revision to Diff 498164.
elmcdonough added a comment.

Change multiclass name for the sake of clarity.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143301

Files:
  clang/include/clang/Driver/Options.td
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/werror-all.f90
  flang/test/Driver/wextra-ok.f90

Index: flang/test/Driver/wextra-ok.f90
===
--- /dev/null
+++ flang/test/Driver/wextra-ok.f90
@@ -0,0 +1,11 @@
+! Ensure that supplying -Wextra into flang-new does not raise error
+! The first check should be changed if -Wextra is implemented
+
+! RUN: %flang -std=f2018 -Wextra %s 2>&1 | FileCheck %s --check-prefix=CHECK-OK
+! RUN: not %flang -std=f2018 -Wblah -Wextra %s 2>&1 | FileCheck %s --check-prefix=WRONG
+
+! CHECK-OK: argument unused during compilation: '-Wextra'
+! WRONG: Only `-Werror` is supported currently.
+
+program wextra_ok
+end program wextra_ok
Index: flang/test/Driver/werror-all.f90
===
--- /dev/null
+++ flang/test/Driver/werror-all.f90
@@ -0,0 +1,13 @@
+! Ensures that -Werror is read regardless of whether or not other -W
+! flags are present in the CLI args
+
+! RUN: not %flang -std=f2018 -Werror -Wextra %s 2>&1 | FileCheck %s --check-prefix=WRONG 
+! RUN: %flang -std=f2018 -Wextra -Wall %s 2>&1 | FileCheck %s --check-prefix=CHECK-OK
+
+! WRONG: Semantic errors in
+! CHECK-OK: FORALL index variable
+
+program werror_check_all
+  integer :: a(3)
+  forall (j=1:n) a(i) = 1
+end program werror_check_all
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -604,14 +604,17 @@
   // TODO: Currently throws a Diagnostic for anything other than -W,
   // this has to change when other -W's are supported.
   if (args.hasArg(clang::driver::options::OPT_W_Joined)) {
-if (args.getLastArgValue(clang::driver::options::OPT_W_Joined)
-.equals("error")) {
-  res.setWarnAsErr(true);
-} else {
-  const unsigned diagID =
-  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
-"Only `-Werror` is supported currently.");
-  diags.Report(diagID);
+const auto  =
+args.getAllArgValues(clang::driver::options::OPT_W_Joined);
+for (const auto  : wArgs) {
+  if (wArg == "error") {
+res.setWarnAsErr(true);
+  } else {
+const unsigned diagID =
+diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only `-Werror` is supported currently.");
+diags.Report(diagID);
+  }
 }
   }
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -235,6 +235,10 @@
 def clang_ignored_m_Group : OptionGroup<"">,
   Group, Flags<[Ignored]>;
 
+// Unsupported flang groups
+def flang_ignored_w_Group : OptionGroup<"">,
+  Group, Flags<[FlangOnlyOption, Ignored]>;
+
 // Group for clang options in the process of deprecation.
 // Please include the version that deprecated the flag as comment to allow
 // easier garbage collection.
@@ -4874,6 +4878,10 @@
   def fno_#NAME : Flag<["-"], "fno-"#name>;
 }
 
+multiclass FlangIgnoredDiagOpt {
+  def unsupported_warning_w#NAME : Flag<["-", "--"], "W"#name>, Group;
+}
+
 defm : BooleanFFlag<"keep-inline-functions">, Group;
 
 def fprofile_dir : Joined<["-"], "fprofile-dir=">, Group;
@@ -5034,6 +5042,34 @@
 defm underscoring : BooleanFFlag<"underscoring">, Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
 
+// Unsupported flang W options
+defm : FlangIgnoredDiagOpt<"extra">;
+defm : FlangIgnoredDiagOpt<"aliasing">;
+defm : FlangIgnoredDiagOpt<"ampersand">;
+defm : FlangIgnoredDiagOpt<"array-bounds">;
+defm : FlangIgnoredDiagOpt<"c-binding-type">;
+defm : FlangIgnoredDiagOpt<"character-truncation">;
+defm : FlangIgnoredDiagOpt<"conversion">;
+defm : FlangIgnoredDiagOpt<"do-subscript">;
+defm : FlangIgnoredDiagOpt<"function-elimination">;
+defm : FlangIgnoredDiagOpt<"implicit-interface">;
+defm : FlangIgnoredDiagOpt<"implicit-procedure">;
+defm : FlangIgnoredDiagOpt<"intrinsic-shadow">;
+defm : FlangIgnoredDiagOpt<"use-without-only">;
+defm : FlangIgnoredDiagOpt<"intrinsics-std">;
+defm : FlangIgnoredDiagOpt<"line-truncation">;
+defm : FlangIgnoredDiagOpt<"no-align-commons">;
+defm : FlangIgnoredDiagOpt<"no-overwrite-recursive">;
+defm : FlangIgnoredDiagOpt<"no-tabs">;
+defm : FlangIgnoredDiagOpt<"real-q-constant">;
+defm : FlangIgnoredDiagOpt<"surprising">;
+defm : FlangIgnoredDiagOpt<"underflow">;
+defm : FlangIgnoredDiagOpt<"unused-parameter">;
+defm : 

[PATCH] D143670: Stop claiming we support [[carries_dependency]]

2023-02-16 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/Preprocessor/has_attribute.cpp:51
 // FIXME(201806L) CHECK: assert: 0
-// CHECK: carries_dependency: 200809L
+// CHECK: carries_dependency: 0
 // CHECK: deprecated: 201309L

aaron.ballman wrote:
> hubert.reinterpretcast wrote:
> > I'd trust this when I see the change to [cpp.cond]/6 arrive in CWG.
> This is consistent with how we handle `[[no_unique_address]]` (see line 59).
Is that driven by compatibility concerns on the platform though? For example, 
we might be doing something on line 59 to match MSVC.

Do we know if GCC intends to make a similar change for `carries_dependency`? It 
may help to be more explicit about why our situation is different from GCC's.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143670

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


[PATCH] D143205: [clang] add __has_extension(gnu_asm_goto_with_outputs_full)

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 498159.
nickdesaulniers added a comment.

- final rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143205

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Features.def
  clang/test/Parser/asm-goto.c


Index: clang/test/Parser/asm-goto.c
===
--- clang/test/Parser/asm-goto.c
+++ clang/test/Parser/asm-goto.c
@@ -7,6 +7,9 @@
 #if !__has_extension(gnu_asm_goto_with_outputs)
 #error Extension 'gnu_asm_goto_with_outputs' should be available by default
 #endif
+#if !__has_extension(gnu_asm_goto_with_outputs_full)
+#error Extension 'gnu_asm_goto_with_outputs_full' should be available by 
default
+#endif
 
 int a, b, c, d, e, f, g, h, i, j, k, l;
 
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -268,6 +268,7 @@
 EXTENSION(statement_attributes_with_gnu_syntax, true)
 EXTENSION(gnu_asm, LangOpts.GNUAsm)
 EXTENSION(gnu_asm_goto_with_outputs, LangOpts.GNUAsm)
+EXTENSION(gnu_asm_goto_with_outputs_full, LangOpts.GNUAsm)
 EXTENSION(matrix_types, LangOpts.MatrixTypes)
 EXTENSION(matrix_types_scalar_division, true)
 EXTENSION(cxx_attributes_on_using_declarations, LangOpts.CPlusPlus11)
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1591,6 +1591,12 @@
 Outputs may be used along any branches from the ``asm goto`` whether the
 branches are taken or not.
 
+Query for this feature with ``__has_extension(gnu_asm_goto_with_outputs)``.
+
+Prior to clang-16, the output may only be used safely when the indirect
+branches are not taken.  Query for this difference with
+``__has_extension(gnu_asm_goto_with_outputs_full)``.
+
 When using tied-outputs (i.e. outputs that are inputs and outputs, not just
 outputs) with the `+r` constraint, there is a hidden input that's created
 before the label, so numeric references to operands must account for that.
@@ -1618,8 +1624,6 @@
   return -1;
   }
 
-Query for this feature with ``__has_extension(gnu_asm_goto_with_outputs)``.
-
 Objective-C Features
 
 


Index: clang/test/Parser/asm-goto.c
===
--- clang/test/Parser/asm-goto.c
+++ clang/test/Parser/asm-goto.c
@@ -7,6 +7,9 @@
 #if !__has_extension(gnu_asm_goto_with_outputs)
 #error Extension 'gnu_asm_goto_with_outputs' should be available by default
 #endif
+#if !__has_extension(gnu_asm_goto_with_outputs_full)
+#error Extension 'gnu_asm_goto_with_outputs_full' should be available by default
+#endif
 
 int a, b, c, d, e, f, g, h, i, j, k, l;
 
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -268,6 +268,7 @@
 EXTENSION(statement_attributes_with_gnu_syntax, true)
 EXTENSION(gnu_asm, LangOpts.GNUAsm)
 EXTENSION(gnu_asm_goto_with_outputs, LangOpts.GNUAsm)
+EXTENSION(gnu_asm_goto_with_outputs_full, LangOpts.GNUAsm)
 EXTENSION(matrix_types, LangOpts.MatrixTypes)
 EXTENSION(matrix_types_scalar_division, true)
 EXTENSION(cxx_attributes_on_using_declarations, LangOpts.CPlusPlus11)
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1591,6 +1591,12 @@
 Outputs may be used along any branches from the ``asm goto`` whether the
 branches are taken or not.
 
+Query for this feature with ``__has_extension(gnu_asm_goto_with_outputs)``.
+
+Prior to clang-16, the output may only be used safely when the indirect
+branches are not taken.  Query for this difference with
+``__has_extension(gnu_asm_goto_with_outputs_full)``.
+
 When using tied-outputs (i.e. outputs that are inputs and outputs, not just
 outputs) with the `+r` constraint, there is a hidden input that's created
 before the label, so numeric references to operands must account for that.
@@ -1618,8 +1624,6 @@
   return -1;
   }
 
-Query for this feature with ``__has_extension(gnu_asm_goto_with_outputs)``.
-
 Objective-C Features
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140508: [clang] fix -Wuninitialized for asm goto outputs on indirect edges.

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 498158.
nickdesaulniers added a comment.

- final rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140508

Files:
  clang/lib/Analysis/UninitializedValues.cpp
  clang/test/Analysis/uninit-asm-goto.cpp

Index: clang/test/Analysis/uninit-asm-goto.cpp
===
--- clang/test/Analysis/uninit-asm-goto.cpp
+++ clang/test/Analysis/uninit-asm-goto.cpp
@@ -9,9 +9,9 @@
 return -1;
 }
 
+// test2: Expect no diagnostics
 int test2(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   if (x < 42)
 asm goto("" : "+S"(x), "+D"(y) : "r"(x) :: indirect_1, indirect_2);
   else
@@ -20,29 +20,29 @@
 indirect_1:
   return -42;
 indirect_2:
-  return y; // expected-note {{uninitialized use occurs here}}
+  return y;
 }
 
+// test3: Expect no diagnostics
 int test3(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   asm goto("" : "="(y) : "r"(x) : : fail);
 normal:
   y += x;
   return y;
   if (x) {
 fail:
-return y; // expected-note {{uninitialized use occurs here}}
+return y;
   }
   return 0;
 }
 
+// test4: Expect no diagnostics
 int test4(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   goto forward;
 backward:
-  return y; // expected-note {{uninitialized use occurs here}}
+  return y;
 forward:
   asm goto("" : "=r"(y) : "r"(x) : : backward);
   return y;
@@ -70,23 +70,40 @@
   return -1;
 }
 
+// test7: Expect no diagnostics.
 int test7(int z) {
-int x; // expected-warning {{variable 'x' is used uninitialized whenever its declaration is reached}}
-   // expected-note@-1 {{initialize the variable 'x' to silence this warning}}
+int x;
 if (z)
   asm goto ("":"=r"(x):::A1,A2);
 return 0;
 A1:
 A2:
-return x; // expected-note {{uninitialized use occurs here}}
+return x;
 }
 
+// test8: Expect no diagnostics
 int test8() {
-int x = 0; // expected-warning {{variable 'x' is used uninitialized whenever its declaration is reached}}
-   // expected-note@-1 {{variable 'x' is declared here}}
+int x = 0;
 asm goto ("":"=r"(x):::A1,A2);
 return 0;
 A1:
 A2:
-return x; // expected-note {{uninitialized use occurs here}}
+return x;
+}
+
+// test9: Expect no diagnostics
+int test9 (int x) {
+int y;
+asm goto("": "=r"(y) :::out);
+return 42;
+out:
+return y;
+}
+
+int test10() {
+  int y; // expected-note {{initialize the variable 'y' to silence this warning}}
+  asm goto(""out);
+  return 42;
+out:
+  return y; // expected-warning {{variable 'y' is uninitialized when used here}}
 }
Index: clang/lib/Analysis/UninitializedValues.cpp
===
--- clang/lib/Analysis/UninitializedValues.cpp
+++ clang/lib/Analysis/UninitializedValues.cpp
@@ -586,28 +586,6 @@
   continue;
 }
 
-if (AtPredExit == MayUninitialized) {
-  // If the predecessor's terminator is an "asm goto" that initializes
-  // the variable, then don't count it as "initialized" on the indirect
-  // paths.
-  CFGTerminator term = Pred->getTerminator();
-  if (const auto *as = dyn_cast_or_null(term.getStmt())) {
-const CFGBlock *fallthrough = *Pred->succ_begin();
-if (as->isAsmGoto() &&
-llvm::any_of(as->outputs(), [&](const Expr *output) {
-return vd == findVar(output).getDecl() &&
-llvm::any_of(as->labels(),
- [&](const AddrLabelExpr *label) {
-  return label->getLabel()->getStmt() == B->Label &&
-  B != fallthrough;
-});
-})) {
-  Use.setUninitAfterDecl();
-  continue;
-}
-  }
-}
-
 unsigned  = SuccsVisited[Pred->getBlockID()];
 if (!SV) {
   // When visiting the first successor of a block, mark all NULL
@@ -820,7 +798,8 @@
 // it's used on an indirect path, where it's not guaranteed to be
 // defined.
 if (const VarDecl *VD = findVar(Ex).getDecl())
-  vals[VD] = MayUninitialized;
+  if (vals[VD] != Initialized)
+vals[VD] = MayUninitialized;
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136497: [Clang] support for outputs along indirect edges of asm goto

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 498157.
nickdesaulniers added a comment.

- final rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136497

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/asm-goto.c
  clang/test/CodeGen/asm-goto2.c
  clang/test/Modules/asm-goto.c

Index: clang/test/Modules/asm-goto.c
===
--- clang/test/Modules/asm-goto.c
+++ clang/test/Modules/asm-goto.c
@@ -5,7 +5,7 @@
 
 // CHECK-LABEL: define {{.*}} @foo(
 // CHECK: callbr {{.*}} "=r,!i{{.*}}()
-// CHECK-NEXT: to label %asm.fallthrough [label %indirect]
+// CHECK-NEXT: to label %asm.fallthrough [label %indirect.split]
 
 int bar(void) {
   return foo();
Index: clang/test/CodeGen/asm-goto2.c
===
--- /dev/null
+++ clang/test/CodeGen/asm-goto2.c
@@ -0,0 +1,156 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -O0 -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: @test0(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr i32 asm "", "=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1:[0-9]+]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !2
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:store i32 [[TMP0]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 42, ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+// CHECK:   z.split:
+// CHECK-NEXT:store i32 [[TMP0]], ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z]]
+//
+int test0 (void) {
+  int ret;
+  asm goto ("" : "=r"(ret):::z);
+  ret = 42;
+z:
+  return ret;
+}
+
+// CHECK-LABEL: @test1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !3
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:[[ASMRESULT:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT1:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT1]], ptr [[B]], align 4
+// CHECK-NEXT:store i32 42, ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+// CHECK:   z.split:
+// CHECK-NEXT:[[ASMRESULT2:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT3:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT2]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT3]], ptr [[B]], align 4
+// CHECK-NEXT:br label [[Z]]
+//
+int test1 (void) {
+  int ret, b;
+  asm goto ("" : "=r"(ret), "=r"(b):::z);
+  ret = 42;
+z:
+  return ret;
+}
+
+// CHECK-LABEL: @test2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !4
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:[[ASMRESULT:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT1:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT1]], ptr [[B]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH4:%.*]] [label %z.split9], !srcloc !5
+// CHECK:   asm.fallthrough4:
+// CHECK-NEXT:[[ASMRESULT5:%.*]] = extractvalue { i32, i32 } [[TMP1]], 0
+// CHECK-NEXT:[[ASMRESULT6:%.*]] = extractvalue { i32, i32 } [[TMP1]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT5]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT6]], ptr [[B]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP2]]
+// CHECK:   z.split:
+// CHECK-NEXT:[[ASMRESULT2:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT3:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT2]], ptr 

[PATCH] D137113: [Clang] refactor CodeGenFunction::EmitAsmStmt NFC

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 498156.
nickdesaulniers added a comment.

- final rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137113

Files:
  clang/lib/CodeGen/CGStmt.cpp

Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Assumptions.h"
@@ -2327,6 +2328,93 @@
   }
 }
 
+static void
+EmitAsmStores(CodeGenFunction , const AsmStmt ,
+  const llvm::ArrayRef RegResults,
+  const llvm::ArrayRef ResultRegTypes,
+  const llvm::ArrayRef ResultTruncRegTypes,
+  const llvm::ArrayRef ResultRegDests,
+  const llvm::ArrayRef ResultRegQualTys,
+  const llvm::BitVector ,
+  const llvm::BitVector ) {
+  CGBuilderTy  = CGF.Builder;
+  CodeGenModule  = CGF.CGM;
+  llvm::LLVMContext  = CGF.getLLVMContext();
+
+  assert(RegResults.size() == ResultRegTypes.size());
+  assert(RegResults.size() == ResultTruncRegTypes.size());
+  assert(RegResults.size() == ResultRegDests.size());
+  // ResultRegDests can be also populated by addReturnRegisterOutputs() above,
+  // in which case its size may grow.
+  assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
+  assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
+
+  for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
+llvm::Value *Tmp = RegResults[i];
+llvm::Type *TruncTy = ResultTruncRegTypes[i];
+
+if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
+  // Target must guarantee the Value `Tmp` here is lowered to a boolean
+  // value.
+  llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2);
+  llvm::Value *IsBooleanValue =
+  Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, Two);
+  llvm::Function *FnAssume = CGM.getIntrinsic(llvm::Intrinsic::assume);
+  Builder.CreateCall(FnAssume, IsBooleanValue);
+}
+
+// If the result type of the LLVM IR asm doesn't match the result type of
+// the expression, do the conversion.
+if (ResultRegTypes[i] != TruncTy) {
+
+  // Truncate the integer result to the right size, note that TruncTy can be
+  // a pointer.
+  if (TruncTy->isFloatingPointTy())
+Tmp = Builder.CreateFPTrunc(Tmp, TruncTy);
+  else if (TruncTy->isPointerTy() && Tmp->getType()->isIntegerTy()) {
+uint64_t ResSize = CGM.getDataLayout().getTypeSizeInBits(TruncTy);
+Tmp = Builder.CreateTrunc(
+Tmp, llvm::IntegerType::get(CTX, (unsigned)ResSize));
+Tmp = Builder.CreateIntToPtr(Tmp, TruncTy);
+  } else if (Tmp->getType()->isPointerTy() && TruncTy->isIntegerTy()) {
+uint64_t TmpSize =
+CGM.getDataLayout().getTypeSizeInBits(Tmp->getType());
+Tmp = Builder.CreatePtrToInt(
+Tmp, llvm::IntegerType::get(CTX, (unsigned)TmpSize));
+Tmp = Builder.CreateTrunc(Tmp, TruncTy);
+  } else if (TruncTy->isIntegerTy()) {
+Tmp = Builder.CreateZExtOrTrunc(Tmp, TruncTy);
+  } else if (TruncTy->isVectorTy()) {
+Tmp = Builder.CreateBitCast(Tmp, TruncTy);
+  }
+}
+
+LValue Dest = ResultRegDests[i];
+// ResultTypeRequiresCast elements correspond to the first
+// ResultTypeRequiresCast.size() elements of RegResults.
+if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
+  unsigned Size = CGF.getContext().getTypeSize(ResultRegQualTys[i]);
+  Address A =
+  Builder.CreateElementBitCast(Dest.getAddress(CGF), ResultRegTypes[i]);
+  if (CGF.getTargetHooks().isScalarizableAsmOperand(CGF, TruncTy)) {
+Builder.CreateStore(Tmp, A);
+continue;
+  }
+
+  QualType Ty =
+  CGF.getContext().getIntTypeForBitwidth(Size, /*Signed*/ false);
+  if (Ty.isNull()) {
+const Expr *OutExpr = S.getOutputExpr(i);
+CGM.getDiags().Report(OutExpr->getExprLoc(),
+  diag::err_store_value_to_reg);
+return;
+  }
+  Dest = CGF.MakeAddrLValue(A, Ty);
+}
+CGF.EmitStoreThroughLValue(RValue::get(Tmp), Dest);
+  }
+}
+
 void CodeGenFunction::EmitAsmStmt(const AsmStmt ) {
   // Pop all cleanup blocks at the end of the asm statement.
   CodeGenFunction::RunCleanupsScope Cleanups(*this);
@@ -2627,7 +2715,7 @@
   SmallVector Transfer;
   llvm::BasicBlock *Fallthrough = nullptr;
   bool IsGCCAsmGoto = false;
-  if (const auto *GS =  dyn_cast()) {
+  if (const auto *GS = dyn_cast()) {
 IsGCCAsmGoto = GS->isAsmGoto();
 if (IsGCCAsmGoto) {
   for (const auto *E : GS->labels()) {
@@ 

[PATCH] D144047: [CUDA][SPIRV] Match builtin types and __GCC_ATOMIC_XXX_LOCK_FREE macros on host/device

2023-02-16 Thread Shangwu Yao via Phabricator via cfe-commits
shangwuyao updated this revision to Diff 498145.
shangwuyao added a comment.

Run clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144047

Files:
  clang/lib/Basic/Targets/SPIR.h
  clang/test/CodeGenCUDASPIRV/cuda-types.cu

Index: clang/test/CodeGenCUDASPIRV/cuda-types.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDASPIRV/cuda-types.cu
@@ -0,0 +1,56 @@
+// Check that types, widths, __CLANG_ATOMIC* macros, etc. match on the host and
+// device sides of CUDA compilations. Note that we filter out long double and
+// maxwidth of _BitInt(), as this is intentionally different on host and device.
+//
+// Also ignore __CLANG_ATOMIC_LLONG_LOCK_FREE on i386. The default host CPU for
+// an i386 triple is typically at least an i586, which has cmpxchg8b (Clang
+// feature, "cx8"). Therefore, __CLANG_ATOMIC_LLONG_LOCK_FREE is 2 on the host,
+// but the value should be 1 for the device.
+//
+// Unlike CUDA, the width of SPIR-V POINTER type could differ between host and
+// device, because SPIR-V explicitly sets POINTER type width. So it is the
+// user's responsibility to choose the offload with the right POINTER size,
+// otherwise the values for __CLANG_ATOMIC_POINTER_LOCK_FREE could be different.
+
+// RUN: mkdir -p %t
+
+// RUN: %clang --cuda-host-only -nocudainc -nocudalib --offload=spirv32 -target i386-unknown-linux-gnu -x cuda -emit-llvm -E -dM -o - /dev/null \
+// RUN:   | grep -E '__CLANG_ATOMIC' \
+// RUN:   | grep -Ev '_ATOMIC_LLONG_LOCK_FREE' > %t/i386-host-defines-filtered
+// RUN: %clang --cuda-device-only -nocudainc -nocudalib --offload=spirv32 -target i386-unknown-linux-gnu -x cuda -emit-llvm -E -dM -o - /dev/null \
+// RUN:   | grep -E '__CLANG_ATOMIC' \
+// RUN:   | grep -Ev '_ATOMIC_LLONG_LOCK_FREE' > %t/i386-device-defines-filtered
+// RUN: diff %t/i386-host-defines-filtered %t/i386-device-defines-filtered
+
+// RUN: %clang --cuda-host-only -nocudainc -nocudalib --offload=spirv32 -target i386-windows-msvc -x cuda -emit-llvm -E -dM -o - /dev/null \
+// RUN:   | grep -E '__CLANG_ATOMIC' \
+// RUN:   | grep -Ev '_ATOMIC_LLONG_LOCK_FREE' > %t/i386-msvc-host-defines-filtered
+// RUN: %clang --cuda-device-only -nocudainc -nocudalib --offload=spirv32 -target i386-windows-msvc -x cuda -emit-llvm -E -dM -o - /dev/null \
+// RUN:   | grep -E '__CLANG_ATOMIC' \
+// RUN:   | grep -Ev '_ATOMIC_LLONG_LOCK_FREE' > %t/i386-msvc-device-defines-filtered
+// RUN: diff %t/i386-msvc-host-defines-filtered %t/i386-msvc-device-defines-filtered
+
+// RUN: %clang --cuda-host-only -nocudainc -nocudalib --offload=spirv64 -target x86_64-unknown-linux-gnu -x cuda -emit-llvm -E -dM -o - /dev/null \
+// RUN:   | grep -E '__CLANG_ATOMIC' \
+// RUN:   | grep -Ev '_ATOMIC_LLONG_LOCK_FREE' > %t/x86_64-host-defines-filtered
+// RUN: %clang --cuda-device-only -nocudainc -nocudalib --offload=spirv64 -target x86_64-unknown-linux-gnu -x cuda -emit-llvm -E -dM -o - /dev/null \
+// RUN:   | grep -E '__CLANG_ATOMIC' \
+// RUN:   | grep -Ev '_ATOMIC_LLONG_LOCK_FREE' > %t/x86_64-device-defines-filtered
+// RUN: diff %t/x86_64-host-defines-filtered %t/x86_64-device-defines-filtered
+
+// RUN: %clang --cuda-host-only -nocudainc -nocudalib --offload=spirv64 -target powerpc64-unknown-linux-gnu -x cuda -emit-llvm -E -dM -o - /dev/null \
+// RUN:   | grep -E '__CLANG_ATOMIC' \
+// RUN:   | grep -Ev '_ATOMIC_LLONG_LOCK_FREE' > %t/powerpc64-host-defines-filtered
+// RUN: %clang --cuda-device-only -nocudainc -nocudalib --offload=spirv64 -target powerpc64-unknown-linux-gnu -x cuda -emit-llvm -E -dM -o - /dev/null \
+// RUN:   | grep -E '__CLANG_ATOMIC' \
+// RUN:   | grep -Ev '_ATOMIC_LLONG_LOCK_FREE' > %t/powerpc64-device-defines-filtered
+// RUN: diff %t/powerpc64-host-defines-filtered %t/powerpc64-device-defines-filtered
+
+// RUN: %clang --cuda-host-only -nocudainc -nocudalib --offload=spirv64 -target x86_64-windows-msvc -x cuda -emit-llvm -E -dM -o - /dev/null \
+// RUN:   | grep -E '__CLANG_ATOMIC' \
+// RUN:   | grep -Ev '_ATOMIC_LLONG_LOCK_FREE' > %t/x86_64-msvc-host-defines-filtered
+// RUN: %clang --cuda-device-only -nocudainc -nocudalib --offload=spirv64 -target x86_64-windows-msvc -x cuda -emit-llvm -E -dM -o - /dev/null \
+// RUN:   | grep -E '__CLANG_ATOMIC' \
+// RUN:   | grep -Ev '_ATOMIC_LLONG_LOCK_FREE' > %t/x86_64-msvc-device-defines-filtered
+// RUN: diff %t/x86_64-msvc-host-defines-filtered %t/x86_64-msvc-device-defines-filtered
+
Index: clang/lib/Basic/Targets/SPIR.h
===
--- clang/lib/Basic/Targets/SPIR.h
+++ clang/lib/Basic/Targets/SPIR.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
 #define LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
 
+#include "Targets.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
@@ -79,8 +80,10 @@
 
 // Base 

[PATCH] D140723: [clang][Interp] Only check constructors for global variables

2023-02-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik 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/D140723/new/

https://reviews.llvm.org/D140723

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


[PATCH] D140723: [clang][Interp] Only check constructors for global variables

2023-02-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

So we are only checking global constructors b/c it is valid in a constant 
expression context to initialize a record and not initialize all their fields 
as long as we don't use any of those fields.

Note, cases that stem from this has been discussed as part of 
https://github.com/cplusplus/papers/issues/1380 but the issue is not resolved 
yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140723

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


[PATCH] D144192: GH60642: Fix ICE when checking a lambda defined in a concept definition

2023-02-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:4572
: Sema::ExpressionEvaluationContext::ConstantEvaluated,
-/*LambdaContextDecl=*/nullptr, /*ExprContext=*/
+Sema::ReuseLambdaContextDecl, /*ExprContext=*/
 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);

shafik wrote:
> Not for this PR but I am looking at other place we use 
> `EnterExpressionEvaluationContext` and it is not obvious to me when we should 
> be using `Sema::ReuseLambdaContextDecl` or not. So might be worth looking at 
> other uses as well.
Yeah, its unfortunately not particularly clear to me either. We should be 
re-using that context any time we're going "down" in code (that is, if we are 
potentially in a context where a lambda is defined inside of something its 
actual declcontext doesn't match), but should NOT reuse the context in a case 
where we are 'swapping' contexts to do something like instantiate a function 
required by the current context/etc.


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

https://reviews.llvm.org/D144192

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


[PATCH] D143436: [clangd] Apply standard adaptors to CDBs pushed from LSP

2023-02-16 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 498140.
DmitryPolukhin added a comment.

Update test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/Inputs/did-change-configuration-params.args
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/Tooling.cpp

Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -299,6 +300,31 @@
   }
 }
 
+void addExpandedResponseFiles(std::vector ,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem ) {
+  bool SeenRSPFile = false;
+  llvm::SmallVector Argv;
+  Argv.reserve(CommandLine.size());
+  for (auto  : CommandLine) {
+Argv.push_back(Arg.c_str());
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
+  }
+  if (!SeenRSPFile)
+return;
+  llvm::BumpPtrAllocator Alloc;
+  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
+  llvm::Error Err =
+  ECtx.setVFS().setCurrentDir(WorkingDir).expandResponseFiles(Argv);
+  if (Err)
+llvm::errs() << Err;
+  // Don't assign directly, Argv aliases CommandLine.
+  std::vector ExpandedArgv(Argv.begin(), Argv.end());
+  CommandLine = std::move(ExpandedArgv);
+}
+
 } // namespace tooling
 } // namespace clang
 
@@ -684,7 +710,7 @@
 
   if (!Invocation.run())
 return nullptr;
- 
+
   assert(ASTs.size() == 1);
   return std::move(ASTs[0]);
 }
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -48,28 +49,9 @@
 
 private:
   std::vector expand(std::vector Cmds) const {
-for (auto  : Cmds) {
-  bool SeenRSPFile = false;
-  llvm::SmallVector Argv;
-  Argv.reserve(Cmd.CommandLine.size());
-  for (auto  : Cmd.CommandLine) {
-Argv.push_back(Arg.c_str());
-if (!Arg.empty())
-  SeenRSPFile |= Arg.front() == '@';
-  }
-  if (!SeenRSPFile)
-continue;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
-  llvm::Error Err = ECtx.setVFS(FS.get())
-.setCurrentDir(Cmd.Directory)
-.expandResponseFiles(Argv);
-  if (Err)
-llvm::errs() << Err;
-  // Don't assign directly, Argv aliases CommandLine.
-  std::vector ExpandedArgv(Argv.begin(), Argv.end());
-  Cmd.CommandLine = std::move(ExpandedArgv);
-}
+for (auto  : Cmds)
+  tooling::addExpandedResponseFiles(Cmd.CommandLine, Cmd.Directory,
+Tokenizer, *FS);
 return Cmds;
   }
 
Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -506,6 +506,12 @@
 void addTargetAndModeForProgramName(std::vector ,
 StringRef InvokedAs);
 
+/// Helper function that expands response files in command line.
+void addExpandedResponseFiles(std::vector ,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem );
+
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
   ArrayRef CC1Args,
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -49,7 +49,7 @@
   Cmd.CommandLine = 

[PATCH] D143691: Fix clang-formats IncludeCategory to match the documentation

2023-02-16 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe added inline comments.



Comment at: clang/unittests/Format/SortIncludesTest.cpp:548
+  EXPECT_EQ("#include \"a.h\"\n"
+"#include \"llvm/a.h\"\n"
+"#include \"b.h\"\n"

HazardyKnusperkeks wrote:
> Febbe wrote:
> > HazardyKnusperkeks wrote:
> > > While I may accept there are more than one //main// header, this should 
> > > not happen in my opinion.
> > Yes, that is a conflict of interests. There is no perfect way of 
> > implementing this, without the help of clang-tidy / the clang language 
> > server:
> > 
> > To arguably define a file as a main include, all declarations must be 
> > analyzed, whether they are predeclared in the include or not.
> > But we don't have the help of the clang AST.
> > 
> > My expectation is, that when I randomly shuffle the includes, that they are 
> > always sorted to the same result.
> > Currently, this is not the case, and depending on the rules it can 
> > furthermore happen, that a main include "a.h" is exchanged with the 
> > "llvm/a.h". 
> > This should also not happen, but it does, and it is not covered by the 
> > tests.
> > 
> > I consider the false negative of a correct main include worse than a false 
> > positive.
> > Therefore, I changed it. 
> > In addition, my approach has the advantage that all includes are sorted in 
> > the same way, regardless of the order.
> > 
> > But if you want, we could introduce a new Option like: `enum 
> > FindMainIncludes{FMI_First, FMI_All, FMI_Off = 0};`
> > With `First` to match the current behavior, `All` for the new behavior.
> > But then matched includes with a negative priority would be swapped with 
> > the other possible main_include at each run.
> > I don't know how to prevent this.
> > The best solution I can imagine, is still a comment of the programmer, that 
> > the respective include is or is not a main include.
> > E.g. `// clang-format pragma: no_main_include`
> > 
> > Another idea would be, to insert all main includes into a list with the 
> > matchers' priority, and then take the last negative or the first positive, 
> > but only if it is not partially sortable with the neighbors.
> > This might be a good heuristic, whether the include was previously detected 
> > as main include.
> > But I don't know if this is implementable with the current algorithm.
> > 
> > 
> It is very unfortunate that `llvm/a.h` would be detected as a main header, 
> but would currently the relative order be kept and thus `a.h` always be 
> //the// main header?
> 
> I don't think you will find someone (of the usual reviewers) to be in favor 
> of the pragma, and I certainly don't want such a thing in my code.
> 
> A heuristic seems to be a good way. I'd say from all the candidates we take 
> the one without any directories in it.
> but would currently the relative order be kept and thus a.h always be the 
> main header?

No, unfortunately, clang-format never sorted the path after its dept, 
std::filesystem::path would do that, but clang-format uses the std::less 
operator of StringRef which is a lexicographical comparison.
Therefore, `m.h` will always be ordered after `llvm/m.h`. Changing that would 
reorder nearly all headers in all projects using clang-format. But I could do 
this only for the main-include candidates.

Nevertheless, I don't think this would be a good heuristic either, because me, 
and many others are using an extra `include` folder for public headers (API) 
and the `src` directory for private headers:

```
my-lib/
├─ include/
│  ├─ public_headers.md
│  ├─ a.h
├─ src/
│  ├─ private_headers_and_source.md
│  ├─ a_priv.h
│  ├─ a.cpp
```

With your proposed solution, the primary main header is ordered after the main 
include.
Let me implement my heuristic first, maybe it will work well enough to prevent 
the reordering, when the main header is sorted by hand (just like before, but 
now it also should work for negative priorities).

Otherwise, we must reconsider which tradeoff we choose (maybe a completely new 
one).



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143691

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


[PATCH] D144192: GH60642: Fix ICE when checking a lambda defined in a concept definition

2023-02-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:4572
: Sema::ExpressionEvaluationContext::ConstantEvaluated,
-/*LambdaContextDecl=*/nullptr, /*ExprContext=*/
+Sema::ReuseLambdaContextDecl, /*ExprContext=*/
 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);

Not for this PR but I am looking at other place we use 
`EnterExpressionEvaluationContext` and it is not obvious to me when we should 
be using `Sema::ReuseLambdaContextDecl` or not. So might be worth looking at 
other uses as well.


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

https://reviews.llvm.org/D144192

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


[PATCH] D144218: [Clang] [AVR] Fix USHRT_MAX for 16-bit int.

2023-02-16 Thread Daniel Thornburgh via Phabricator via cfe-commits
mysterymath created this revision.
mysterymath added reviewers: aaron.ballman, aykevl, dylanmckay.
Herald added a subscriber: Jim.
Herald added a project: All.
mysterymath requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For AVR, the definition of USHRT_MAX overflows.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144218

Files:
  clang/lib/Headers/limits.h


Index: clang/lib/Headers/limits.h
===
--- clang/lib/Headers/limits.h
+++ clang/lib/Headers/limits.h
@@ -52,7 +52,7 @@
 #define LONG_MIN  (-__LONG_MAX__ -1L)
 
 #define UCHAR_MAX (__SCHAR_MAX__*2  +1)
-#define USHRT_MAX (__SHRT_MAX__ *2  +1)
+#define USHRT_MAX (__SHRT_MAX__ * 2U + 1U)
 #define UINT_MAX  (__INT_MAX__  *2U +1U)
 #define ULONG_MAX (__LONG_MAX__ *2UL+1UL)
 


Index: clang/lib/Headers/limits.h
===
--- clang/lib/Headers/limits.h
+++ clang/lib/Headers/limits.h
@@ -52,7 +52,7 @@
 #define LONG_MIN  (-__LONG_MAX__ -1L)
 
 #define UCHAR_MAX (__SCHAR_MAX__*2  +1)
-#define USHRT_MAX (__SHRT_MAX__ *2  +1)
+#define USHRT_MAX (__SHRT_MAX__ * 2U + 1U)
 #define UINT_MAX  (__INT_MAX__  *2U +1U)
 #define ULONG_MAX (__LONG_MAX__ *2UL+1UL)
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143436: [clangd] Apply standard adaptors to CDBs pushed from LSP

2023-02-16 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

@nridge I'm sorry, I pushed version without all tests. Now I added test case 
for response files, it seems that clangd hasn't had it before this patch.




Comment at: clang-tools-extra/clangd/CompileCommands.cpp:222
+  tooling::addExpandedResponseFiles(Cmd, Command.Directory, Tokenizer, *FS);
+  tooling::addTargetAndModeForProgramName(Cmd, Cmd.front());
   auto  = clang::driver::getDriverOptTable();

nridge wrote:
> nridge wrote:
> > The target needs to be added **after** the call to `SystemIncludeExtractor` 
> > later in this function (this is what D138546 is trying to fix). The reason 
> > is that `SystemIncludeExtractor` includes any `--target` flag in the 
> > compiler driver being queried for system includes, which may be gcc, which 
> > does not support `--target`.
> (I guess we could make that change separately in D138546, but if we're 
> changing the place where the `--target` is added in this patch, I figure we 
> might as well move it directly to the desired place.)
I think there are order problems here:
- we need `--driver-mode=cl` injected here to make check on line #229 work as 
expected
- if we don't inject it driver mode here, command line edits won't see the 
change; see how I modified test clangd/unittests/CompileCommandsTests.cpp line 
#203, with D138546 edits were not applied properly to driver mode

I'll double check how it works on Windows but I expect that moving it after 
SystemIncludeExtractor will break proper driver mode detection.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

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


[PATCH] D143436: [clangd] Apply standard adaptors to CDBs pushed from LSP

2023-02-16 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 498138.
DmitryPolukhin added a comment.

Add test for expanded response files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/Inputs/did-change-configuration-params.args
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/Tooling.cpp

Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -299,6 +300,31 @@
   }
 }
 
+void addExpandedResponseFiles(std::vector ,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem ) {
+  bool SeenRSPFile = false;
+  llvm::SmallVector Argv;
+  Argv.reserve(CommandLine.size());
+  for (auto  : CommandLine) {
+Argv.push_back(Arg.c_str());
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
+  }
+  if (!SeenRSPFile)
+return;
+  llvm::BumpPtrAllocator Alloc;
+  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
+  llvm::Error Err =
+  ECtx.setVFS().setCurrentDir(WorkingDir).expandResponseFiles(Argv);
+  if (Err)
+llvm::errs() << Err;
+  // Don't assign directly, Argv aliases CommandLine.
+  std::vector ExpandedArgv(Argv.begin(), Argv.end());
+  CommandLine = std::move(ExpandedArgv);
+}
+
 } // namespace tooling
 } // namespace clang
 
@@ -684,7 +710,7 @@
 
   if (!Invocation.run())
 return nullptr;
- 
+
   assert(ASTs.size() == 1);
   return std::move(ASTs[0]);
 }
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -48,28 +49,9 @@
 
 private:
   std::vector expand(std::vector Cmds) const {
-for (auto  : Cmds) {
-  bool SeenRSPFile = false;
-  llvm::SmallVector Argv;
-  Argv.reserve(Cmd.CommandLine.size());
-  for (auto  : Cmd.CommandLine) {
-Argv.push_back(Arg.c_str());
-if (!Arg.empty())
-  SeenRSPFile |= Arg.front() == '@';
-  }
-  if (!SeenRSPFile)
-continue;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
-  llvm::Error Err = ECtx.setVFS(FS.get())
-.setCurrentDir(Cmd.Directory)
-.expandResponseFiles(Argv);
-  if (Err)
-llvm::errs() << Err;
-  // Don't assign directly, Argv aliases CommandLine.
-  std::vector ExpandedArgv(Argv.begin(), Argv.end());
-  Cmd.CommandLine = std::move(ExpandedArgv);
-}
+for (auto  : Cmds)
+  tooling::addExpandedResponseFiles(Cmd.CommandLine, Cmd.Directory,
+Tokenizer, *FS);
 return Cmds;
   }
 
Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -506,6 +506,12 @@
 void addTargetAndModeForProgramName(std::vector ,
 StringRef InvokedAs);
 
+/// Helper function that expands response files in command line.
+void addExpandedResponseFiles(std::vector ,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem );
+
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
   ArrayRef CC1Args,
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -49,7 +49,7 @@
  

[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-02-16 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe marked 2 inline comments as done.
mikecrowe added a comment.

I ended up splitting out the std::format and std::print tests to their own file 
which meant that I didn't need to modify the existing 
`redundant-string-cstr.cpp` file in this commit. (Though of course I had to 
extract the  header in D144216  
first.) Let me know if you don't like the split.

I also slightly re-ordered the tests and removed a few incorrect comments that 
incorrectly survived the switch to using `forEachArgumentWithParam`.


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

https://reviews.llvm.org/D143342

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


[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-02-16 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 498136.
mikecrowe edited the summary of this revision.

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

https://reviews.llvm.org/D143342

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp
@@ -0,0 +1,214 @@
+// RUN: %check_clang_tidy -check-suffix=STDFORMAT -std=c++20 %s readability-redundant-string-cstr %t -- --  -isystem %clang_tidy_headers -DTEST_STDFORMAT
+// RUN: %check_clang_tidy -check-suffixes=STDFORMAT,STDPRINT -std=c++2b %s readability-redundant-string-cstr %t -- --  -isystem %clang_tidy_headers -DTEST_STDFORMAT -DTEST_STDPRINT
+#include 
+
+namespace std {
+  template
+struct type_identity { using type = T; };
+  template
+using type_identity_t = typename type_identity::type;
+
+  template 
+  struct basic_format_string {
+consteval basic_format_string(const CharT *format) : str(format) {}
+basic_string_view> str;
+  };
+
+  template
+using format_string = basic_format_string...>;
+
+  template
+using wformat_string = basic_format_string...>;
+
+#if defined(TEST_STDFORMAT)
+  template
+  std::string format(format_string, Args &&...);
+  template
+  std::string format(wformat_string, Args &&...);
+#endif // TEST_STDFORMAT
+
+#if defined(TEST_STDPRINT)
+  template
+  void print(format_string, Args &&...);
+  template
+  void print(wformat_string, Args &&...);
+#endif // TEST_STDPRINT
+}
+
+namespace notstd {
+#if defined(TEST_STDFORMAT)
+  template
+  std::string format(const char *, Args &&...);
+  template
+  std::string format(const wchar_t *, Args &&...);
+#endif // TEST_STDFORMAT
+#if defined(TEST_STDPRINT)
+  template
+  void print(const char *, Args &&...);
+  template
+  void print(const wchar_t *, Args &&...);
+#endif // TEST_STDPRINT
+}
+
+std::string return_temporary();
+std::wstring return_wtemporary();
+
+#if defined(TEST_STDFORMAT)
+void std_format(const std::string , const std::string , const std::string ) {
+  auto r1 = std::format("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:37: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r1 = std::format("One:{}\n", s1);
+
+  auto r2 = std::format("One:{} Two:{} Three:{} Four:{}\n", s1.c_str(), s2, s3.c_str(), return_temporary().c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:61: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-2]]:77: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-3]]:89: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r2 = std::format("One:{} Two:{} Three:{} Four:{}\n", s1, s2, s3, return_temporary());
+
+  using namespace std;
+  auto r3 = format("Four:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:33: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r3 = format("Four:{}\n", s1);
+}
+
+void std_format_wide(const std::wstring , const std::wstring , const std::wstring ) {
+  auto r1 = std::format(L"One:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:38: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r1 = std::format(L"One:{}\n", s1);
+
+  auto r2 = std::format(L"One:{} Two:{} Three:{} Four:{}\n", s1.c_str(), s2, s3.c_str(), return_wtemporary().c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:62: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-2]]:78: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-3]]:90: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r2 = std::format(L"One:{} Two:{} Three:{} Four:{}\n", s1, s2, s3, return_wtemporary());
+
+  using namespace std;
+  auto r3 = format(L"Four:{}\n", s1.c_str());
+  // CHECK-MESSAGES-STDFORMAT: :[[@LINE-1]]:34: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES-STDFORMAT: {{^  }}auto r3 = format(L"Four:{}\n", s1);
+}
+
+// There's are c_str() calls here, so it shouldn't be touched.
+std::string std_format_no_cstr(const std::string , const std::string ) {
+  return std::format("One: {}, Two: {}\n", s1, s2);
+}
+
+// There's are 

[PATCH] D144216: [clang-tidy] Extract string header from redundant-string-cstr checker

2023-02-16 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe created this revision.
mikecrowe added a reviewer: njames93.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
mikecrowe requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

In preparation for using the implementation of basic_string and
basic_string_view from redundant-string-cstr.cpp in other checks, let's
extract it to a header.


https://reviews.llvm.org/D144216

Files:
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -1,71 +1,5 @@
-// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t
-
-typedef unsigned __INT16_TYPE__ char16;
-typedef unsigned __INT32_TYPE__ char32;
-typedef __SIZE_TYPE__ size;
-
-namespace std {
-template 
-class allocator {};
-template 
-class char_traits {};
-template 
-struct basic_string {
-  typedef basic_string _Type;
-  basic_string();
-  basic_string(const C *p, const A  = A());
-
-  ~basic_string();
-
-  const C *c_str() const;
-  const C *data() const;
-
-  _Type& append(const C *s);
-  _Type& append(const C *s, size n);
-  _Type& assign(const C *s);
-  _Type& assign(const C *s, size n);
-
-  int compare(const _Type&) const;
-  int compare(const C* s) const;
-  int compare(size pos, size len, const _Type&) const;
-  int compare(size pos, size len, const C* s) const;
-
-  size find(const _Type& str, size pos = 0) const;
-  size find(const C* s, size pos = 0) const;
-  size find(const C* s, size pos, size n) const;
-
-  _Type& insert(size pos, const _Type& str);
-  _Type& insert(size pos, const C* s);
-  _Type& insert(size pos, const C* s, size n);
-
-  _Type& operator+=(const _Type& str);
-  _Type& operator+=(const C* s);
-  _Type& operator=(const _Type& str);
-  _Type& operator=(const C* s);
-};
-
-typedef basic_string, std::allocator> string;
-typedef basic_string, std::allocator> wstring;
-typedef basic_string, std::allocator> u16string;
-typedef basic_string, std::allocator> u32string;
-
-template 
-struct basic_string_view {
-  basic_string_view(const C* s);
-};
-typedef basic_string_view> string_view;
-typedef basic_string_view> wstring_view;
-typedef basic_string_view> u16string_view;
-typedef basic_string_view> u32string_view;
-}
-
-std::string operator+(const std::string&, const std::string&);
-std::string operator+(const std::string&, const char*);
-std::string operator+(const char*, const std::string&);
-
-bool operator==(const std::string&, const std::string&);
-bool operator==(const std::string&, const char*);
-bool operator==(const char*, const std::string&);
+// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t -- -- -isystem %clang_tidy_headers
+#include 
 
 namespace llvm {
 struct StringRef {
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -0,0 +1,71 @@
+#ifndef _STRING_
+#define _STRING_
+
+typedef unsigned __INT16_TYPE__ char16;
+typedef unsigned __INT32_TYPE__ char32;
+typedef __SIZE_TYPE__ size;
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template 
+struct basic_string {
+  typedef basic_string _Type;
+  basic_string();
+  basic_string(const C *p, const A  = A());
+
+  ~basic_string();
+
+  const C *c_str() const;
+  const C *data() const;
+
+  _Type& append(const C *s);
+  _Type& append(const C *s, size n);
+  _Type& assign(const C *s);
+  _Type& assign(const C *s, size n);
+
+  int compare(const _Type&) const;
+  int compare(const C* s) const;
+  int compare(size pos, size len, const _Type&) const;
+  int compare(size pos, size len, const C* s) const;
+
+  size find(const _Type& str, size pos = 0) const;
+  size find(const C* s, size pos = 0) const;
+  size find(const C* s, size pos, size n) const;
+
+  _Type& insert(size pos, const _Type& str);
+  _Type& insert(size pos, const C* s);
+  _Type& insert(size pos, const C* s, size n);
+
+  _Type& operator+=(const _Type& str);
+  _Type& operator+=(const C* s);
+  _Type& operator=(const _Type& str);
+  _Type& operator=(const C* s);
+};
+
+typedef basic_string, std::allocator> string;
+typedef basic_string, std::allocator> wstring;
+typedef basic_string, std::allocator> u16string;
+typedef basic_string, std::allocator> u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
+typedef basic_string_view> wstring_view;
+typedef basic_string_view> u16string_view;
+typedef 

[PATCH] D144181: [clang][DebugInfo] Add abi-tags on constructors/destructors as LLVM annotations

2023-02-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D144181#4133025 , @dblaikie wrote:

> Ah, accidentally posted to the lldb part of this stack... instead:
>
> Any chance we can make these work more like member functions (could the ctors 
> include their mangled names, for instance)? Or is it the innate nature of 
> ctors having the various C1 /C2/etc versions?

Initially we tried that in https://reviews.llvm.org/D143652. The existence of 
multiple constructor definitions which aren't linked to the `DISubprogram` 
declaration makes it tough. We need to start with a pretty expensive search 
through the index for all the possible definitions. But then we need to somehow 
choose the right one to take the linkage name from. And that context isn't 
available at the point where LLDB parses DWARF.

I'll post some numbers of how much space this would take with Adrian's 
suggestion and go from there


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144181

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


[PATCH] D144181: [clang][DebugInfo] Add abi-tags on constructors/destructors as LLVM annotations

2023-02-16 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ah, accidentally posted to the lldb part of this stack... instead:

Any chance we can make these work more like member functions (could the ctors 
include their mangled names, for instance)? Or is it the innate nature of ctors 
having the various C1 /C2/etc versions?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144181

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


[PATCH] D144206: [clang-tidy] Fix false-positive in cppcoreguidelines-slicing

2023-02-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
Herald added subscribers: carlosgalvezp, shchenz, kbarton, xazax.hun, nemanjai.
Herald added a reviewer: njames93.
Herald added a project: All.
PiotrZSL published this revision for review.
PiotrZSL added a comment.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Ready for review.


When warning would be emitted in constructor for virtual base class
initialization.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144206

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/slicing.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/slicing.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/slicing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/slicing.cpp
@@ -98,3 +98,20 @@
   a = h;
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 
'DerivedThatOverridesH' to 'Base' discards override 'h'
 }
+
+struct BaseA {
+virtual ~BaseA() {}
+virtual void foo() {}
+
+int i;
+};
+
+struct BaseB : virtual BaseA {
+virtual void foo() {}
+};
+
+struct ClassWithVirtualBases : BaseB {
+  ClassWithVirtualBases(const BaseB& other) : BaseA(other), BaseB(other) {}
+  ClassWithVirtualBases(const ClassWithVirtualBases& other) : BaseA(other), 
BaseB(other) {}
+};
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -130,6 +130,10 @@
 Changes in existing checks
 ^^
 
+- Fixed a false positive in :doc:`cppcoreguidelines-slicing
+  ` check when warning would be
+  emitted in constructor for virtual base class initialization.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
@@ -40,12 +40,15 @@
   const auto HasTypeDerivedFromBaseDecl =
   anyOf(hasType(IsDerivedFromBaseDecl),
 hasType(references(IsDerivedFromBaseDecl)));
-  const auto IsWithinDerivedCtor =
-  hasParent(cxxConstructorDecl(ofClass(equalsBoundNode("DerivedDecl";
+  const auto IsCallToBaseClass = hasParent(cxxConstructorDecl(
+  ofClass(isSameOrDerivedFrom(equalsBoundNode("DerivedDecl"))),
+  hasAnyConstructorInitializer(allOf(
+  isBaseInitializer(), withInitializer(equalsBoundNode("Call"));
 
   // Assignment slicing: "a = b;" and "a = std::move(b);" variants.
   const auto SlicesObjectInAssignment =
-  callExpr(callee(cxxMethodDecl(anyOf(isCopyAssignmentOperator(),
+  callExpr(expr().bind("Call"),
+   callee(cxxMethodDecl(anyOf(isCopyAssignmentOperator(),
   isMoveAssignmentOperator()),
 OfBaseClass)),
hasArgument(1, HasTypeDerivedFromBaseDecl));
@@ -53,17 +56,17 @@
   // Construction slicing: "A a{b};" and "f(b);" variants. Note that in case of
   // slicing the letter will create a temporary and therefore call a ctor.
   const auto SlicesObjectInCtor = cxxConstructExpr(
+  expr().bind("Call"),
   hasDeclaration(cxxConstructorDecl(
   anyOf(isCopyConstructor(), isMoveConstructor()), OfBaseClass)),
   hasArgument(0, HasTypeDerivedFromBaseDecl),
   // We need to disable matching on the call to the base copy/move
   // constructor in DerivedDecl's constructors.
-  unless(IsWithinDerivedCtor));
+  unless(IsCallToBaseClass));
 
-  Finder->addMatcher(traverse(TK_AsIs, expr(anyOf(SlicesObjectInAssignment,
-  SlicesObjectInCtor))
-   .bind("Call")),
- this);
+  Finder->addMatcher(
+  traverse(TK_AsIs, expr(SlicesObjectInAssignment).bind("Call")), this);
+  Finder->addMatcher(traverse(TK_AsIs, SlicesObjectInCtor), this);
 }
 
 /// Warns on methods overridden in DerivedDecl with respect to BaseDecl.


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/slicing.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/slicing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/slicing.cpp
@@ -98,3 +98,20 @@
   a = h;
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'DerivedThatOverridesH' to 'Base' discards override 'h'
 }
+
+struct BaseA {
+virtual ~BaseA() {}
+virtual void foo() {}
+
+int i;
+};
+

[PATCH] D144136: Add a "remark" to report on array accesses

2023-02-16 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D144136#4131825 , @aaron.ballman 
wrote:

> I'd like to understand what the overhead is for this. How much overhead does 
> this add when the remark is disabled? How much overhead does this add when 
> the remark is enabled?
>
>> This will report a ton of information. It's basically only good for piping 
>> to a file and using Perl to gather any useful information.
>
> This is why I'm worried about overhead -- there can be *a lot* of array 
> accesses in a complex TU and spitting data out to (potentially) stdout/stderr 
> is *slow*.

I should have indicated that I'm not expecting this to go into mainline Clang. 
As you mentioned, this would be a lot of overhead and is really only useful in 
the way @kees mentioned. I created this "arc" patch to make it easier for him 
to import it. :-) Sorry for the confusion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144136

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


[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-02-16 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 498118.
qiongsiwu1 added a comment.

Rebase to resolve clang release note conflict.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/PowerPC/aix-roptr.c
  clang/test/Driver/ppc-roptr.c

Index: clang/test/Driver/ppc-roptr.c
===
--- /dev/null
+++ clang/test/Driver/ppc-roptr.c
@@ -0,0 +1,18 @@
+// RUN: %clang -### -target powerpc-ibm-aix-xcoff -mroptr %s 2>&1 | FileCheck %s
+// RUN: %clang -### -target powerpc-ibm-aix-xcoff -mroptr -mno-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=ROPTR
+// RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mroptr %s 2>&1 | FileCheck %s
+// RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mroptr -mno-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=ROPTR
+// CHECK: "-mroptr"
+// CHECK: "-bforceimprw"
+// ROPTR-NOT: "-mroptr"
+// ROPTR-NOT: "-bforceimprw"
+
+char c1 = 10;
+char c2 = 20;
+char* const c1_ptr = 
+
+int main() {
+*(char**)_ptr = 
+}
Index: clang/test/CodeGen/PowerPC/aix-roptr.c
===
--- /dev/null
+++ clang/test/CodeGen/PowerPC/aix-roptr.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mroptr -fdata-sections \
+// RUN: -S <%s | FileCheck %s --check-prefix=CHECK32
+// RUN: %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mroptr -fdata-sections \
+// RUN: -S <%s | FileCheck %s --check-prefix=CHECK64
+// RUN: not %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mroptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: not %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mroptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: not %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -mroptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=TARGET_ERR
+// RUN: not %clang -Xclang -triple=powerpc-ibm-aix-xcoff -mroptr -shared \
+// RUN: -S %s 2>&1 | FileCheck %s --check-prefix=SHARED_ERR
+// RUN: not %clang -Xclang -triple=powerpc64-ibm-aix-xcoff -mroptr -shared \
+// RUN: -S %s 2>&1 | FileCheck %s --check-prefix=SHARED_ERR
+
+char c1 = 10;
+char c2 = 20;
+char* const c1_ptr = 
+// CHECK32: .csect c1_ptr[RO],2
+// CHECK32-NEXT:	.globl	c1_ptr[RO]
+// CHECK32-NEXT:	.align	2
+// CHECK32-NEXT:	.vbyte	4, c1[RW]
+
+// CHECK64: .csect c1_ptr[RO],3
+// CHECK64-NEXT:	.globl	c1_ptr[RO]
+// CHECK64-NEXT:	.align	3
+// CHECK64-NEXT:	.vbyte	8, c1[RW]
+
+// DATA_SECTION_ERR: error: -mroptr is supported only with -fdata-sections
+// TARGET_ERR: error: unsupported option '-mroptr' for target 'powerpc64le-unknown-linux-gnu'
+// SHARED_ERR: error: -mroptr is not suppored with -shared
+
+int main() {
+*(char**)_ptr = 
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1560,6 +1560,9 @@
   if (Opts.EnableAIXExtendedAltivecABI)
 GenerateArg(Args, OPT_mabi_EQ_vec_extabi, SA);
 
+  if (Opts.ReadOnlyPointers)
+GenerateArg(Args, OPT_mroptr, SA);
+
   if (!Opts.OptRecordPasses.empty())
 GenerateArg(Args, OPT_opt_record_passes, Opts.OptRecordPasses, SA);
 
@@ -1949,6 +1952,17 @@
 Opts.EnableAIXExtendedAltivecABI = O.matches(OPT_mabi_EQ_vec_extabi);
   }
 
+  if (Arg *A = Args.getLastArg(OPT_mroptr)) {
+if (!T.isOSAIX())
+  Diags.Report(diag::err_drv_unsupported_opt_for_target)
+  << A->getSpelling() << T.str();
+
+if (!Args.hasFlag(OPT_fdata_sections, OPT_fno_data_sections, false))
+  Diags.Report(diag::err_roptr_requires_data_sections);
+
+Opts.ReadOnlyPointers = true;
+  }
+
   if (Arg *A = Args.getLastArg(OPT_mabi_EQ_quadword_atomics)) {
 if (!T.isOSAIX() || T.isPPC32())
   Diags.Report(diag::err_drv_unsupported_opt_for_target)
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5248,6 +5248,17 @@
   << A->getSpelling() << RawTriple.str();
   }
 
+  if (Args.hasFlag(options::OPT_mroptr, options::OPT_mno_roptr, false)) {
+if (!Triple.isOSAIX())
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << "-mroptr" << RawTriple.str();
+
+if (Args.hasArg(options::OPT_shared))
+  D.Diag(diag::err_roptr_cannot_build_shared);
+
+CmdArgs.push_back("-mroptr");
+  }
+
   if (Arg *A 

[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

2023-02-16 Thread Joshua Cranmer via Phabricator via cfe-commits
jcranmer-intel added a comment.

In D142907#4132430 , @arsenm wrote:

> I was thinking of changing the default in general to dynamic. I was going to 
> at least change the strictfp default in a follow up

I had the same thought too, but I reflected a little further that the default 
fp model implying that the environment being in the default state means we can 
assume the FTZ/DAZ are also in a default (IEEE) state.

In D142907#4132543 , @kpn wrote:

> What's the plan for tying this to strictfp? Because I don't it should be tied 
> to cases where we use the constrained intrinsics but the exceptions are 
> ignored and the default rounding is in stated. Those instructions are 
> supposed to behave the same as the non-constrained instructions. So keying 
> off the presence of the strictfp attribute on the function definition, or the 
> (equivalent) presence of constrained intrinsics, would be too simple.

The way I see it, `strictfp` is an assertion that every FP instruction has a 
dependency on the FP environment, which is largely orthogonal to the 
`denormal-mode` attribute asserting that the FTZ/DAZ bits in the FP environment 
have a particular value. The constrained intrinsics also have the ability to 
assert some properties of the FP environment (specifically, rounding mode and 
exception behavior) on individual instructions. By not adding any metadata to 
constrained intrinsics at the same time, we don't get the ability to set the 
denormal-mode on a per-instruction basis-but I don't think there's much value 
to be gained by doing so (giving that we already have it at a per-function 
level).

> Would we get different denormal behavior with a clang flag vs using a #pragma 
> at the top of a source file? That seems surprising as well.

One of the consequences of having so many different ways of controlling 
compiler FP environment assumptions is that there's a crazy amount of 
interactions to consider. But I think there is ultimately a workable solution 
for the clang frontend to generate interactions that make sense.


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

https://reviews.llvm.org/D142907

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


[PATCH] D143691: Fix clang-formats IncludeCategory to match the documentation

2023-02-16 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/unittests/Format/SortIncludesTest.cpp:548
+  EXPECT_EQ("#include \"a.h\"\n"
+"#include \"llvm/a.h\"\n"
+"#include \"b.h\"\n"

Febbe wrote:
> HazardyKnusperkeks wrote:
> > While I may accept there are more than one //main// header, this should not 
> > happen in my opinion.
> Yes, that is a conflict of interests. There is no perfect way of implementing 
> this, without the help of clang-tidy / the clang language server:
> 
> To arguably define a file as a main include, all declarations must be 
> analyzed, whether they are predeclared in the include or not.
> But we don't have the help of the clang AST.
> 
> My expectation is, that when I randomly shuffle the includes, that they are 
> always sorted to the same result.
> Currently, this is not the case, and depending on the rules it can 
> furthermore happen, that a main include "a.h" is exchanged with the 
> "llvm/a.h". 
> This should also not happen, but it does, and it is not covered by the tests.
> 
> I consider the false negative of a correct main include worse than a false 
> positive.
> Therefore, I changed it. 
> In addition, my approach has the advantage that all includes are sorted in 
> the same way, regardless of the order.
> 
> But if you want, we could introduce a new Option like: `enum 
> FindMainIncludes{FMI_First, FMI_All, FMI_Off = 0};`
> With `First` to match the current behavior, `All` for the new behavior.
> But then matched includes with a negative priority would be swapped with the 
> other possible main_include at each run.
> I don't know how to prevent this.
> The best solution I can imagine, is still a comment of the programmer, that 
> the respective include is or is not a main include.
> E.g. `// clang-format pragma: no_main_include`
> 
> Another idea would be, to insert all main includes into a list with the 
> matchers' priority, and then take the last negative or the first positive, 
> but only if it is not partially sortable with the neighbors.
> This might be a good heuristic, whether the include was previously detected 
> as main include.
> But I don't know if this is implementable with the current algorithm.
> 
> 
It is very unfortunate that `llvm/a.h` would be detected as a main header, but 
would currently the relative order be kept and thus `a.h` always be //the// 
main header?

I don't think you will find someone (of the usual reviewers) to be in favor of 
the pragma, and I certainly don't want such a thing in my code.

A heuristic seems to be a good way. I'd say from all the candidates we take the 
one without any directories in it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143691

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


[PATCH] D143096: [clangd] Provide patched diagnostics with preamble patch

2023-02-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/Preamble.cpp:625
+// same spelling.
+static std::vector patchDiags(llvm::ArrayRef BaselineDiags,
+const ScannedPreamble ,

I think this function is too long with too many local lambdas, consider 
converting it to a class instead (call me old-fashioned!)



Comment at: clang-tools-extra/clangd/Preamble.cpp:645
+auto ModifiedStartIt =
+ModifiedContentsToLine.find(BaselineScan.Lines[BaselineStart]);
+if (ModifiedStartIt == ModifiedContentsToLine.end())

we're assuming that the ranges are within the preamble and everyone agrees 
about the bounds. If not, BaselineStart may not be a valid index into 
BaselineScan.Lines

This assumption seems broadly reasonable, but is *very much* not locally 
enforced. I'd suggest a defensive check or at least an assert.



Comment at: clang-tools-extra/clangd/Preamble.cpp:648
+  return std::nullopt;
+int Closest = ModifiedStartIt->second.front();
+for (auto AlternateLine : ModifiedStartIt->second) {

this doesn't look right: you're first deciding which possible starting point is 
closest, and then deciding whether it matches. So a range that matches can be 
masked by a range where only the first line matches, if the latter is closer.



Comment at: clang-tools-extra/clangd/Preamble.cpp:683
+  NewFix.Edits.emplace_back(E);
+  NewFix.Edits.back().range = *NewRange;
+}

probably doesn't matter, but you're inconsistent about moving vs copying range



Comment at: clang-tools-extra/clangd/Preamble.cpp:706
+Diag NewDiag;
+// Copy all fields but Notes, Fixes, Name and Tags.
+static_cast(NewDiag) = static_cast(D);

reasoning about the fields you're *not* rewriting feels fragile. (Here and in 
TranslateFix).

Consider copying the whole object and mutating in place (`bool 
TranslateDiag(Diag&)` together with `erase_if`)



Comment at: clang-tools-extra/clangd/Preamble.h:162
+  /// Returns diag locations for Modified contents.
+  llvm::ArrayRef patchedDiags() const { return PatchedDiags; }
   static constexpr llvm::StringLiteral HeaderName = "__preamble_patch__.h";

nit: blank line after



Comment at: clang-tools-extra/clangd/unittests/PreambleTests.cpp:820
+  {
+// Note is also dropped if diag is gone.
+Annotations Code(R"(

i'm confused about what this comment is getting at - a note without a diag is 
not even representable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143096

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


[PATCH] D142609: [Clang] Fix -Wconstant-logical-operand when LHS is a constant

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/SemaCXX/expressions.cpp:146-148
   #define Y2 2
   bool r2 = X || Y2; // expected-warning {{use of logical '||' with constant 
operand}} \
  // expected-note {{use '|' for a bitwise operation}}

nickdesaulniers wrote:
> So I think we'll want to change this test.
> 
> See commit d6eb2b9f4d4fc236376e3a5a7b8faa31e8dd427d that introduced it.
> 
> If we have a constant that was defined via macro, we DONT want to warn for it.
Another related issue is that sometimes we set these constants via `-D` flags. 
I wonder if that's a clang bug that those aren't considered as having a valid 
macro id?

See also https://github.com/ClangBuiltLinux/linux/issues/1806


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142609

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


[PATCH] D142609: [Clang] Fix -Wconstant-logical-operand when LHS is a constant

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

Hmm...looking at some of the commits to the related code, it might be very 
intentional that we don't warn symmetrically:

938533db602b32ab435078e723b656ac6e779a1b
e54ff6cc3e479523b71e4c7eb4bd13707d84de0f




Comment at: clang/test/SemaCXX/expressions.cpp:146-148
   #define Y2 2
   bool r2 = X || Y2; // expected-warning {{use of logical '||' with constant 
operand}} \
  // expected-note {{use '|' for a bitwise operation}}

So I think we'll want to change this test.

See commit d6eb2b9f4d4fc236376e3a5a7b8faa31e8dd427d that introduced it.

If we have a constant that was defined via macro, we DONT want to warn for it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142609

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


[PATCH] D143953: [RISCV] Accept zicsr and zifencei command line options

2023-02-16 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

LGTM, and the summary of the discussion in the sync-up call matches my 
understanding.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143953

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


[clang] 22e199e - [RISCV] Accept zicsr and zifencei command line options

2023-02-16 Thread Philip Reames via cfe-commits

Author: Philip Reames
Date: 2023-02-16T10:41:41-08:00
New Revision: 22e199e6afb1263c943c0c0d4498694e15bf8a16

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

LOG: [RISCV] Accept zicsr and zifencei command line options

This change adds the definition of the two extensions, but does not either a) 
make any instruction conditional on them or b) enabled the extensions by 
default. (The *instructions* do remain enabled by default per ISA version 2.0 
which is our current default.)

This is meant to be a building block towards something like 
https://reviews.llvm.org/D141666, and in the meantime, address one of the most 
surprising of the current user experience warts. The current behavior of 
rejecting the extensions at the command line despite emitting code which 
appears to use them is surprising to anyone not deeply versed in the details of 
this situation.

Between versions 2.0 and 2.1 of the base I specification, a backwards 
incompatible change was made to remove selected instructions and CSRs from the 
base ISA. These instructions were grouped into a set of new extensions (these), 
but were no longer required by the base ISA. This change is described in 
“Preface to Document Version 20190608-Base-Ratified” from the specification 
document.

As LLVM currently implements only version 2.0 of the base specification, 
accepting these extensions at the command line introduces a configuration which 
doesn't actually match any spec version. It's a pretty harmless variant since 
the 2.0 extension definitions, to my knowledge, exactly match the text from the 
2.0 I text before they were moved into standalone extensions in 2.1 of I. (The 
version numbering in that sentence is a tad confusing to say the least. 
Hopefully I got it right.)

It is worth noting that we already have numerous examples of accepting 
extensions in the march string which didn't exist in version of the spec 
document corresponding to our current base I version, so this doesn't set any 
new precedent.

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

Added: 


Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 31bddb97d7fbf..da87e6b112a6e 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -494,3 +494,15 @@
 // RUN: %clang -target riscv32 -march=rv32izcf1p0 
-menable-experimental-extensions \
 // RUN: -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-ZCF-EXT %s
 // CHECK-ZCF-EXT: __riscv_zcf 100{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32izicsr2p0 -x c -E 
-dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICSR-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64izicsr2p0 -x c -E 
-dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICSR-EXT %s
+// CHECK-ZICSR-EXT: __riscv_zicsr 200{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32izifencei2p0 -x c 
-E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZIFENCEI-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64izifencei2p0 -x c 
-E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZIFENCEI-EXT %s
+// CHECK-ZIFENCEI-EXT: __riscv_zifencei 200{{$}}

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 8242707348385..5932523df391e 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -130,7 +130,7 @@ Supported
 .. _riscv-i2p1-note:
 
 ``zicsr``, ``zifencei``
-  Between versions 2.0 and 2.1 of the base I specification, a backwards 
incompatible change was made to remove selected instructions and CSRs from the 
base ISA.  These instructions were grouped into a set of new extensions, but 
were no longer required by the base ISA.  This change is described in "Preface 
to Document Version 20190608-Base-Ratified" from the specification document.  
LLVM currently implements version 2.0 of the base specification.  Thus, 
instructions from these extensions are accepted as part of the base ISA, but 
attempts to explicitly enable the extensions will error.
+  Between versions 2.0 and 2.1 of the base I specification, a backwards 
incompatible change was made to remove selected instructions and CSRs from the 
base ISA.  These instructions were grouped into a set of new extensions, but 
were no longer required by the base ISA.  This change is described in "Preface 
to Document Version 20190608-Base-Ratified" from the specification 

[PATCH] D143953: [RISCV] Accept zicsr and zifencei command line options

2023-02-16 Thread Philip Reames 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 rG22e199e6afb1: [RISCV] Accept zicsr and zifencei command line 
options (authored by reames).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143953

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -193,3 +193,9 @@
 
 .attribute arch, "rv32iztso0p1"
 # CHECK: attribute  5, "rv32i2p0_ztso0p1"
+
+.attribute arch, "rv32izicsr2p0"
+# CHECK: attribute  5, "rv32i2p0_zicsr2p0"
+
+.attribute arch, "rv32izifencei2p0"
+# CHECK: attribute  5, "rv32i2p0_zifencei2p0"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -46,6 +46,8 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcb %s -o - | FileCheck --check-prefixes=CHECK,RV32ZCB %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcd %s -o - | FileCheck --check-prefixes=CHECK,RV32ZCD %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcf %s -o - | FileCheck --check-prefixes=CHECK,RV32ZCF %s
+; RUN: llc -mtriple=riscv32 -mattr=+zicsr %s -o - | FileCheck --check-prefixes=CHECK,RV32ZICSR %s
+; RUN: llc -mtriple=riscv32 -mattr=+zifencei %s -o - | FileCheck --check-prefixes=CHECK,RV32ZIFENCEI %s
 
 ; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefixes=CHECK,RV64M %s
@@ -99,6 +101,8 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zca %s -o - | FileCheck --check-prefixes=CHECK,RV64ZCA %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zcb %s -o - | FileCheck --check-prefixes=CHECK,RV64ZCB %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zcd %s -o - | FileCheck --check-prefixes=CHECK,RV64ZCD %s
+; RUN: llc -mtriple=riscv64 -mattr=+zicsr %s -o - | FileCheck --check-prefixes=CHECK,RV64ZICSR %s
+; RUN: llc -mtriple=riscv64 -mattr=+zifencei %s -o - | FileCheck --check-prefixes=CHECK,RV64ZIFENCEI %s
 
 ; CHECK: .attribute 4, 16
 
@@ -147,6 +151,8 @@
 ; RV32ZCB: .attribute 5, "rv32i2p0_zca1p0_zcb1p0"
 ; RV32ZCD: .attribute 5, "rv32i2p0_zcd1p0"
 ; RV32ZCF: .attribute 5, "rv32i2p0_zcf1p0"
+; RV32ZICSR: .attribute 5, "rv32i2p0_zicsr2p0"
+; RV32ZIFENCEI: .attribute 5, "rv32i2p0_zifencei2p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -199,6 +205,8 @@
 ; RV64ZCA: .attribute 5, "rv64i2p0_zca1p0"
 ; RV64ZCB: .attribute 5, "rv64i2p0_zca1p0_zcb1p0"
 ; RV64ZCD: .attribute 5, "rv64i2p0_zcd1p0"
+; RV64ZICSR: .attribute 5, "rv64i2p0_zicsr2p0"
+; RV64ZIFENCEI: .attribute 5, "rv64i2p0_zifencei2p0"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1
Index: llvm/lib/Target/RISCV/RISCVFeatures.td
===
--- llvm/lib/Target/RISCV/RISCVFeatures.td
+++ llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -71,6 +71,20 @@
 AssemblerPredicate<(all_of FeatureStdExtZihintntl),
 "'Zihintntl' (Non-Temporal Locality Hints)">;
 
+def FeatureStdExtZicsr
+: SubtargetFeature<"zicsr", "HasStdExtZicsr", "true",
+   "'zicsr' (CSRs)">;
+def HasStdExtZicsr : Predicate<"Subtarget->hasStdExtZicsr()">,
+AssemblerPredicate<(all_of FeatureStdExtZicsr),
+"'Zicsr' (CSRs)">;
+
+def FeatureStdExtZifencei
+: SubtargetFeature<"zifencei", "HasStdExtZifencei", "true",
+   "'zifencei' (fence.i)">;
+def HasStdExtZifencei : Predicate<"Subtarget->hasStdExtZifencei()">,
+   AssemblerPredicate<(all_of FeatureStdExtZifencei),
+   "'Zifencei' (fence.i)">;
+
 def FeatureStdExtZfhmin
 : SubtargetFeature<"zfhmin", "HasStdExtZfhmin", "true",
"'Zfhmin' (Half-Precision Floating-Point Minimal)",
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -103,6 +103,8 @@
 {"zicbom", RISCVExtensionVersion{1, 0}},
 {"zicboz", RISCVExtensionVersion{1, 0}},
 {"zicbop", RISCVExtensionVersion{1, 0}},
+{"zicsr", RISCVExtensionVersion{2, 0}},
+{"zifencei", RISCVExtensionVersion{2, 0}},
 
 {"svnapot", RISCVExtensionVersion{1, 0}},
 {"svpbmt", RISCVExtensionVersion{1, 0}},
Index: 

[libunwind] 372820b - [libunwind][PowerPC] Fix saving/restoring VSX registers on LE systems

2023-02-16 Thread Nemanja Ivanovic via cfe-commits

Author: Nemanja Ivanovic
Date: 2023-02-16T13:37:58-05:00
New Revision: 372820bf571c8d32c8165cfc74b0439c7bb397f9

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

LOG: [libunwind][PowerPC] Fix saving/restoring VSX registers on LE systems

Currently, libunwind just uses stxvd2x/lxvd2x to save/restore
VSX registers respectively. This puts the registers in
doubleword-reversed order into memory on little endian systems.
If both the save and restore are done the same way, this
isn't a problem. However if the unwinder is just restoring
a callee-saved register, it will restore it in the wrong
order (since function prologues save them in the correct order).
This patch adds the necessary swaps before the saves and after
the restores.

Differential revision: https://reviews.llvm.org/D137599

Added: 
libcxxabi/test/vendor/ibm/vec_reg_restore-le.pass.cpp

Modified: 
libunwind/src/UnwindRegistersRestore.S
libunwind/src/UnwindRegistersSave.S

Removed: 




diff  --git a/libcxxabi/test/vendor/ibm/vec_reg_restore-le.pass.cpp 
b/libcxxabi/test/vendor/ibm/vec_reg_restore-le.pass.cpp
new file mode 100644
index 0..413d248a9886b
--- /dev/null
+++ b/libcxxabi/test/vendor/ibm/vec_reg_restore-le.pass.cpp
@@ -0,0 +1,90 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Check that the PowerPC vector registers are restored properly during
+// unwinding.
+
+// REQUIRES: target=powerpc{{(64)?}}le-unknown-linux-gnu
+// UNSUPPORTED: no-exceptions
+
+// Callee-saved VSR's 62 and 63 (vr30, vr31 respectively) are set to 16 bytes
+// with values 1, 2 respectively in main. In order to ensure the two 
doublewords
+// in each register are 
diff erent, they are merged. Then they are reset to 16
+// bytes with values 9 and 12 respectively in a callee and an exception is
+// thrown. When catching an exception in main, the values in the two registers
+// need to be the original ones (including the correct doubleword order).
+
+#include 
+#include 
+
+int __attribute__((noinline)) test2(int i) {
+  if (i > 3)
+throw i;
+  srand(i);
+  return rand();
+}
+
+int __attribute__((noinline)) test(int i) {
+  // Clobber VS63 and VS62 in the function body.
+  // Set VS63 to 16 bytes each with value 9
+  asm volatile("vspltisb 31, 9" : : : "v31");
+
+  // Set VS62 to 16 bytes each with value 12
+  asm volatile("vspltisb 30, 12" : : : "v30");
+  return test2(i);
+}
+
+#define cmpVS63(vec, result)   
\
+  {
\
+vector unsigned char gbg;  
\
+asm volatile("vcmpequb. %[gbg], 31, %[veca];"  
\
+ "mfocrf %[res], 2;"   
\
+ "rlwinm %[res], %[res], 25, 31, 31"   
\
+ : [res] "=r"(result), [gbg] "=v"(gbg) 
\
+ : [veca] "v"(vec) 
\
+ : "cr6"); 
\
+  }
+
+#define cmpVS62(vec, result)   
\
+  {
\
+vector unsigned char gbg;  
\
+asm volatile("vcmpequb. %[gbg], 30, %[veca];"  
\
+ "mfocrf %[res], 2;"   
\
+ "rlwinm %[res], %[res], 25, 31, 31"   
\
+ : [res] "=r"(result), [gbg] "=v"(gbg) 
\
+ : [veca] "v"(vec) 
\
+ : "cr6"); 
\
+  }
+
+int main(int, char **) {
+  // Set VS63 to 16 bytes each with value 1.
+  asm volatile("vspltisb 31, 1" : : : "v31");
+
+  // Set VS62 to 16 bytes each with value 2.
+  asm volatile("vspltisb 30, 2" : : : "v30");
+
+  // Mix doublewords for both VS62 and VS63.
+  asm volatile("xxmrghd 63, 63, 62");
+  asm volatile("xxmrghd 62, 63, 62");
+
+  vector unsigned long long expectedVS63Value = {0x202020202020202,
+ 0x101010101010101};
+  vector unsigned long long expectedVS62Value = 

[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

2023-02-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D142907#4132543 , @kpn wrote:

> What's the plan for tying this to strictfp? Because I don't it should be tied 
> to cases where we use the constrained intrinsics but the exceptions are 
> ignored and the default rounding is in stated. Those instructions are 
> supposed to behave the same as the non-constrained instructions. So keying 
> off the presence of the strictfp attribute on the function definition, or the 
> (equivalent) presence of constrained intrinsics, would be too simple.

The denormal mode is exactly parallel to the rounding mode, we just don't have 
a mirrored field in the constrained intrinsic metadata operands. If we 
defaulted to using the dynamic mode if you were to use strictfp, everything 
would be OK. You just couldn't optimize based on knowledge of the denormal 
mode. I don't really think it's worth putting in the same optimization effort 
as the rounding mode.


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

https://reviews.llvm.org/D142907

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


[PATCH] D144179: [Clang] Added functionality to provide config file name via env variable

2023-02-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Behaviors due to a new environment variable should be very careful. Why is this 
useful? If you want this, you can add a wrapper around `clang` to specify 
`--config=` by yourself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144179

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


[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-02-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/Address.h:67
   return;
-// Currently the max supported alignment is much less than 1 << 63 and is
+// Currently the max supported alignment is much less than 1 << 32 and is
 // guaranteed to be a power of 2, so we can store the log of the alignment

ahatanak wrote:
> efriedma wrote:
> > ahatanak wrote:
> > > efriedma wrote:
> > > > This comment isn't right.  The max alignment is, as far as I can tell, 
> > > > 1<<32 exactly.  (But there's something weird going on with very large 
> > > > values... somehow `int a[1LL<<32] __attribute((aligned(1ULL<<32))) = 
> > > > {};` ignores the alignment.)
> > > The following function generated by tablegen (and a few others directly 
> > > or indirectly calling the function) returns a 32-bit int, but it should 
> > > be returning a 64-bit int.
> > > 
> > > https://github.com/llvm/llvm-project/blob/main/clang/utils/TableGen/ClangAttrEmitter.cpp#L532
> > Filed https://github.com/llvm/llvm-project/issues/60752 so we don't lose 
> > track of this.
> I just realized we can't reduce the number of bits used for alignment here as 
> we need 6 bits for alignment of `1 << 32`.
> 
> Should we allocate additional memory when `AlignLog` is either 31 or 32? If 
> the 5-bit alignment is equal to `0b1`, it would mean that there is an 
> out-of-line storage large enough to hold the alignment and any other extra 
> information that is needed. I think https://reviews.llvm.org/D117262#3267899 
> proposes a similar idea.
How much does `sizeof(Address)` actually matter, anyway?  If it's going to get 
that nasty to implement the packing, I'm not sure it's worth the effort to 
optimize.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

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


[PATCH] D142890: [clangd] Add config option for fast diagnostics mode

2023-02-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/unittests/PreambleTests.cpp:235
   MockFS FS;
-  auto TU = TestTU::withCode(Modified);
+  auto  = PreambleTU;
+  TU.Code = Modified.str();

now there's only one variable used for both - just rename it instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142890

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


[PATCH] D142609: [Clang] Fix -Wconstant-logical-operand when LHS is a constant

2023-02-16 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

I did kernel builds of x86_64 and aarch64 defconfigs. This found new instance:
https://github.com/ClangBuiltLinux/linux/issues/1806
which looks like something we can fix in the kernel sources.  Our CI will 
probably find more instances once this lands, but I'm happy with it.




Comment at: clang/lib/Sema/SemaExpr.cpp:13584
+// the other is a constant.
+void Sema::diagnoseLogicalInsteadOfBitwise(ExprResult , ExprResult ,
SourceLocation Loc,

Every reference to Op1 and Op2 immediately calls `.get()` on it. That's 
annoying. How about `Sema::diagnoseLogicalInsteadOfBitwise` accepts `Expr*` (or 
whatever ExprResult::get returns), and we call `.get()` in the caller?



Comment at: clang/lib/Sema/SemaExpr.cpp:13588
+   bool EnumConstantInBoolContext) {
+  if (!EnumConstantInBoolContext && Op1.get()->getType()->isIntegerType() &&
+  !Op1.get()->getType()->isBooleanType() &&

This is the only use of `EnumConstantInBoolContext` in 
`Sema::diagnoseLogicalInsteadOfBitwise`. It's being used to elide the entirety 
of the method.  In that case, it seems wasteful to bother to pass it as a 
parameter.  Instead, I don't think `Sema::diagnoseLogicalInsteadOfBitwise` 
should be called if `EnumConstantInBoolContext` is `true`.

If you remove the parameter `EnumConstantInBoolContext` then...



Comment at: clang/lib/Sema/SemaExpr.cpp:13588
+   bool EnumConstantInBoolContext) {
+  if (!EnumConstantInBoolContext && Op1.get()->getType()->isIntegerType() &&
+  !Op1.get()->getType()->isBooleanType() &&

nickdesaulniers wrote:
> This is the only use of `EnumConstantInBoolContext` in 
> `Sema::diagnoseLogicalInsteadOfBitwise`. It's being used to elide the 
> entirety of the method.  In that case, it seems wasteful to bother to pass it 
> as a parameter.  Instead, I don't think 
> `Sema::diagnoseLogicalInsteadOfBitwise` should be called if 
> `EnumConstantInBoolContext` is `true`.
> 
> If you remove the parameter `EnumConstantInBoolContext` then...
Do you mind pulling the types into dedicated variables, then reusing them? I 
kind of hate seeing verbose OpX.get()->getType() so much in this method.

Type T1 = Op1.get()->getType();
Type T2 = Op2.get()->getType();

if (T1->isIntegerType() && !T1->isBooleanType() ...
  ...



Comment at: clang/lib/Sema/SemaExpr.cpp:13640-13648
+  if (EnumConstantInBoolContext)
+Diag(Loc, diag::warn_enum_constant_in_bool_context);
+
+  // Diagnose cases where the user write a logical and/or but probably meant a
+  // bitwise one.
+  diagnoseLogicalInsteadOfBitwise(LHS, RHS, Loc, Opc,
+  EnumConstantInBoolContext);

...this can become:

```
if (EnumConstantInBoolContext) {
  Diag(...
} else {
  diagnoseLogicalInsteadOfBitwise(...
  diagnoseLogicalInsteadOfBitwise(...
}
```
```
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e61b9252901d..47cfd0884911 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12569,8 +12569,7 @@ public:
   BinaryOperatorKind Opc);
   void diagnoseLogicalInsteadOfBitwise(ExprResult , ExprResult ,
SourceLocation Loc,
-   BinaryOperatorKind Opc,
-   bool EnumConstantInBoolContext);
+   BinaryOperatorKind Opc);
   QualType CheckLogicalOperands( // C99 6.5.[13,14]
 ExprResult , ExprResult , SourceLocation Loc,
 BinaryOperatorKind Opc);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 7acf6f41625e..fa64b0cdbe94 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13583,9 +13583,8 @@ inline QualType Sema::CheckBitwiseOperands(ExprResult 
, ExprResult ,
 // the other is a constant.
 void Sema::diagnoseLogicalInsteadOfBitwise(ExprResult , ExprResult ,
SourceLocation Loc,
-   BinaryOperatorKind Opc,
-   bool EnumConstantInBoolContext) {
-  if (!EnumConstantInBoolContext && Op1.get()->getType()->isIntegerType() &&
+   BinaryOperatorKind Opc) {
+  if (Op1.get()->getType()->isIntegerType() &&
   !Op1.get()->getType()->isBooleanType() &&
   Op2.get()->getType()->isIntegerType() && !Op2.get()->isValueDependent() 
&&
   // Don't warn in macros or template instantiations.
@@ -13639,13 +13638,12 @@ inline QualType Sema::CheckLogicalOperands(ExprResult 
, ExprResult ,
 
   if (EnumConstantInBoolContext)
 Diag(Loc, diag::warn_enum_constant_in_bool_context);
-
-  // Diagnose cases where the user write a logical and/or 

[PATCH] D143953: [RISCV] Accept zicsr and zifencei command line options

2023-02-16 Thread Philip Reames via Phabricator via cfe-commits
reames added a comment.

This was discussed at today's RISCV sync-up call.  We have a large conversion 
pending on the topic of isa compatibility checking, but there was a consensus 
that this was reasonable and could move forward.  I'm going to be landing this 
change in the near future.


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

https://reviews.llvm.org/D143953

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


[PATCH] D143670: Stop claiming we support [[carries_dependency]]

2023-02-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked an inline comment as done.
aaron.ballman added a comment.

In D143670#4116858 , @erichkeane 
wrote:

> The guidance from EWG this week and in the past was that we are always 
> required to 'parse and diagnose appertainment' of standard attributes, but 
> not to enable __has_cpp_attribute unless we actually 'do' something with it.  
> I intend/suggest we add a condition to the CXX tag of 'is supported' with 
> some sort of conditional for checking diagnostic and O level (or just 
> straight 'false' in this case).

I'm aware of EWG's guidance, and EWG (and WG21) are aware of Clang's position 
regarding conformance in this area. It's unfortunate that EWG didn't consider 
implementer feedback or sibling committee feedback to be sufficiently 
compelling, but at the end of the day, we are the implementers not EWG, and we 
need to do what's best for us. This implementation is conforming to what the 
standard says. We're obligated to issue a diagnostic for the situations you 
identified and we do -- "attribute ignored" is a diagnostic that conveys 
exactly what we intend it to convey. Maybe someday we will improve conformance 
in this area but it is explicitly not a priority given that we're still trying 
to work on C++20 features three years after that standard was released. I 
suspect we'll get around to this particular "issue" roughly never (given the 
work, risks, and benefits) which is why WG21 was told this was a burden for us 
and that we would be conforming in this manner.

To be clear about this change specifically -- this is a consistency change. Our 
existing policy has always been that we do not silently ignore attributes 
unless they're actively harmful to diagnose as being ignored. 
`[[carries_dependency]]` isn't even used in practice, so it does not fall into 
the "harmful to diagnose" category. To date, we've silently accepted it without 
any intention of implementing the performance improvements it suggests are 
possible, and that's against our usual policy. What's more, this makes our 
behavior more self-consistent -- we already do syntactic ignorability of other 
standard attributes, like `[[no_unique_address]]` on some targets.

As we saw when we switched our default mode to C++17, compile time overhead is 
only getting worse with every release of C++. We do not need to keep the 
(admittedly small) compile time overhead on every C++ compilation to check for 
requirements of an attribute we will then ignore entirely. "You're using this 
wrong but we do nothing with it" is user-hostile behavior for attributes which 
are inherently non-portable (even the standard ones). I don't expect this to 
have a measurable impact on compile time overhead in practice, but it's hard to 
argue that there's value in testing every function parameter of every function 
declaration to see if it perhaps is using `[[carries_dependency]]` wrong. 
However, for future attributes like `[[assume]]`, the expense of syntactic 
checking the argument expression is significant and nontrivial, and we should 
be self-consistent. (I expect we'll be one of the later C++ implementations to 
adopt that attribute given it cannot be *semantically* ignored due to potential 
for template instantiations, changing ABI, etc. We were bitten by WG21 adopting 
`[[no_unique_address]]` for C++20 and `[[assume]]` has already had at least one 
implementer push back on implementing it, so there's a very real chance we'll 
be in the same boat again.)

There's ample evidence that total ignorability is not unexpected behavior in 
practice, either -- the idiomatic way of using attributes is to use feature 
testing macros to provide various levels of fallback behavior. Note how the 
fallback clauses do not provide any syntactic checking for the attribute 
arguments and are defined in a way that semantic appertainment issues are 
silently ignored as well:

https://github.com/mozilla/gecko-dev/blob/master/third_party/highway/hwy/base.h#L159
https://github.com/pytorch/pytorch/blob/master/c10/util/Deprecated.h#L22
https://github.com/boostorg/config/blob/master/include/boost/config/detail/suffix.hpp#L701

Mozilla, pytorch, and boost are not doing anything unusual here and they are 
all examples of quite popular C++ projects; it seems to be rare that fallback 
code ever checks that the syntax of the argument is valid or that it’s being 
applied to the correct thing.

Given that these changes are conforming, make us more self-consistent with 
other C++ standard attributes we don't implement, and makes it less likely to 
introduce header incompatibilities with C (which has reaffirmed the need for 
syntactic ignorability of attribute for more than one of their implementations 
as well), I think we should move forward with these changes to 
`[[carries_dependency]]` regardless of EWG's guidance. We're following what 
we're obligated to follow for the standard requirements and WG21 is aware of 
this. 

[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

2023-02-16 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn added a comment.

What's the plan for tying this to strictfp? Because I don't it should be tied 
to cases where we use the constrained intrinsics but the exceptions are ignored 
and the default rounding is in stated. Those instructions are supposed to 
behave the same as the non-constrained instructions. So keying off the presence 
of the strictfp attribute on the function definition, or the (equivalent) 
presence of constrained intrinsics, would be too simple.

I don't see an obvious connection between denormals and exception behavior, and 
the rounding mode has the same problem. It would be surprising if changing the 
rounding mode changed denormal handling or optimization even when the new 
rounding mode would have identical results. It would also be surprising if 
changing the rounding mode back to the default round-to-nearest changed how 
denormals are handled.

Would we get different denormal behavior with a clang flag vs using a #pragma 
at the top of a source file? That seems surprising as well.

In the abstract I can see lumping in denormal handing with the rest of the FP 
environment handling. But in the LLVM context I don't see how we can tie use of 
the constrained intrinsics to denormals.


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

https://reviews.llvm.org/D142907

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


[PATCH] D141307: [WIP] Add -f[no-]loop-versioning option

2023-02-16 Thread Mats Petersson via Phabricator via cfe-commits
Leporacanthicus updated this revision to Diff 498065.
Leporacanthicus added a comment.

Rebased and updated help-message

Also using different type of template for the option


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141307

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.def
  flang/include/flang/Tools/CLOptions.inc
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90

Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -41,9 +41,11 @@
 ! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
+! HELP-NEXT: -floop-versioning  Create unit-strided versions of loops
 ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! HELP-NEXT: -fno-color-diagnostics  Disable colors in diagnostics
 ! HELP-NEXT: -fno-integrated-as  Disable the integrated assembler
+! HELP-NEXT: -fno-loop-versioning   Do not create unit-strided loops (default)
 ! HELP-NEXT: -fno-signed-zeros  Allow optimizations that ignore the sign of floating point zeros
 ! HELP-NEXT: -fno-stack-arrays  Allocate array temporaries on the heap (default)
 ! HELP-NEXT: -fopenacc  Enable OpenACC
@@ -129,10 +131,12 @@
 ! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
+! HELP-FC1-NEXT: -floop-versioning  Create unit-strided versions of loops
 ! HELP-FC1-NEXT: -fno-analyzed-objects-for-unparse
 ! HELP-FC1-NEXT:Do not use the analyzed objects when unparsing
 ! HELP-FC1-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! HELP-FC1-NEXT: -fno-debug-pass-manager Disables debug printing for the new pass manager
+! HELP-FC1-NEXT: -fno-loop-versioning   Do not create unit-strided loops (default)
 ! HELP-FC1-NEXT: -fno-reformat  Dump the cooked character stream in -E mode
 ! HELP-FC1-NEXT: -fno-signed-zeros  Allow optimizations that ignore the sign of floating point zeros
 ! HELP-FC1-NEXT: -fno-stack-arrays  Allocate array temporaries on the heap (default)
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -43,9 +43,11 @@
 ! CHECK-NEXT:Enable support for generating executables (experimental)
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
+! CHECK-NEXT: -floop-versioning  Create unit-strided versions of loops
 ! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! CHECK-NEXT: -fno-color-diagnostics  Disable colors in diagnostics
 ! CHECK-NEXT: -fno-integrated-as Disable the integrated assembler
+! CHECK-NEXT: -fno-loop-versioning   Do not create unit-strided loops (default)
 ! CHECK-NEXT: -fno-signed-zeros  Allow optimizations that ignore the sign of floating point zeros
 ! CHECK-NEXT: -fno-stack-arrays  Allocate array temporaries on the heap (default)
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -545,7 +545,8 @@
   pm.enableVerifier(/*verifyPasses=*/true);
 
   // Create the pass pipeline
-  fir::createMLIRToLLVMPassPipeline(pm, level, opts.StackArrays);
+  fir::createMLIRToLLVMPassPipeline(pm, level, opts.StackArrays,
+opts.LoopVersioning);
   mlir::applyPassManagerCLOptions(pm);
 
   // run the pass manager
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -130,6 +130,10 @@
clang::driver::options::OPT_fno_stack_arrays, false)) {
 opts.StackArrays = 1;
   }
+  if 

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-02-16 Thread Raghu via Phabricator via cfe-commits
raghavendhra accepted this revision.
raghavendhra 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/D142914/new/

https://reviews.llvm.org/D142914

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


[PATCH] D144120: [HLSL] add log library functions

2023-02-16 Thread Joshua Batista 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 rGf842b7a6b8f4: [HLSL] add log library functions (authored by 
bob80905).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144120

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/log.hlsl
  clang/test/CodeGenHLSL/builtins/log10.hlsl
  clang/test/CodeGenHLSL/builtins/log2.hlsl

Index: clang/test/CodeGenHLSL/builtins/log2.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/log2.hlsl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.log2.f16(
+// NO_HALF: define noundef float @"?test_log2_half@@YA$halff@$halff@@Z"(
+// NO_HALF: call float @llvm.log2.f32(
+half test_log2_half ( half p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.log2.v2f16
+// NO_HALF: define noundef <2 x float> @"?test_log2_float2@@YAT?$__vector@M$01@__clang@@T12@@Z"(
+// NO_HALF: call <2 x float> @llvm.log2.v2f32(
+half2 test_log2_half2 ( half2 p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.log2.v3f16
+// NO_HALF: define noundef <3 x float> @"?test_log2_float3@@YAT?$__vector@M$02@__clang@@T12@@Z"(
+// NO_HALF: call <3 x float> @llvm.log2.v3f32(
+half3 test_log2_half3 ( half3 p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <4 x half> @
+// CHECK: call <4 x half> @llvm.log2.v4f16
+// NO_HALF: define noundef <4 x float> @"?test_log2_float4@@YAT?$__vector@M$03@__clang@@T12@@Z"(
+// NO_HALF: call <4 x float> @llvm.log2.v4f32(
+half4 test_log2_half4 ( half4 p0 ) {
+  return log2 ( p0 );
+}
+
+// CHECK: define noundef float @
+// CHECK: call float @llvm.log2.f32(
+float test_log2_float ( float p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <2 x float> @
+// CHECK: call <2 x float> @llvm.log2.v2f32
+float2 test_log2_float2 ( float2 p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <3 x float> @
+// CHECK: call <3 x float> @llvm.log2.v3f32
+float3 test_log2_float3 ( float3 p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <4 x float> @
+// CHECK: call <4 x float> @llvm.log2.v4f32
+float4 test_log2_float4 ( float4 p0 ) {
+  return log2 ( p0 );
+}
Index: clang/test/CodeGenHLSL/builtins/log10.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/log10.hlsl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.log10.f16(
+// NO_HALF: define noundef float @"?test_log10_half@@YA$halff@$halff@@Z"(
+// NO_HALF: call float @llvm.log10.f32(
+half test_log10_half ( half p0 ) {
+  return log10 ( p0 );
+}
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.log10.v2f16
+// NO_HALF: define noundef <2 x float> @"?test_log10_float2@@YAT?$__vector@M$01@__clang@@T12@@Z"(
+// NO_HALF: call <2 x float> @llvm.log10.v2f32(
+half2 test_log10_half2 ( half2 p0 ) {
+  return log10 ( p0 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.log10.v3f16
+// NO_HALF: define noundef <3 x float> @"?test_log10_float3@@YAT?$__vector@M$02@__clang@@T12@@Z"(
+// NO_HALF: call <3 x float> @llvm.log10.v3f32(
+half3 test_log10_half3 ( half3 p0 ) {
+  return log10 ( p0 );
+}
+// CHECK: define noundef <4 x half> @
+// CHECK: call <4 x half> @llvm.log10.v4f16
+// NO_HALF: define noundef <4 x float> @"?test_log10_float4@@YAT?$__vector@M$03@__clang@@T12@@Z"(
+// NO_HALF: call <4 x float> @llvm.log10.v4f32(
+half4 test_log10_half4 ( half4 p0 ) {
+  return log10 ( p0 );
+}
+
+// CHECK: define noundef float @
+// CHECK: call float @llvm.log10.f32(
+float test_log10_float ( float p0 ) {
+  return log10 ( p0 );
+}
+// CHECK: define noundef <2 x float> @
+// CHECK: call <2 x float> @llvm.log10.v2f32
+float2 test_log10_float2 ( float2 p0 ) {
+  return log10 ( p0 );
+}
+// CHECK: 

[clang] f842b7a - [HLSL] add log library functions

2023-02-16 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-02-16T09:50:12-08:00
New Revision: f842b7a6b8f40d817d6d43143e09521bd586a756

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

LOG: [HLSL] add log library functions

This change exposes the log library functions for HLSL,excluding long, int, and 
long long doubles. The log functions are supported for all scalar, vector, and 
matrix types.
Long and long long double support is missing in this patch because those types
don't exist in HLSL. Int is missing because the log functions only work on 
floating type arguments.

The full documentation of the HLSL log functions are available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-log
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-log2
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-log10

Reviewed By: python3kgae

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

Added: 
clang/test/CodeGenHLSL/builtins/log.hlsl
clang/test/CodeGenHLSL/builtins/log10.hlsl
clang/test/CodeGenHLSL/builtins/log2.hlsl

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

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d811a28a43350..570552367215b 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -219,5 +219,94 @@ double3 trunc(double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
 double4 trunc(double4);
 
+// log builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_log))) half log(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+half2 log(half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+half3 log(half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+half4 log(half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log))) float
+log(float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+float2 log(float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+float3 log(float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+float4 log(float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log))) double
+log(double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+double2 log(double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+double3 log(double3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+double4 log(double4);
+
+// log2 builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+half log2(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+half2 log2(half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+half3 log2(half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+half4 log2(half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2))) float
+log2(float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+float2 log2(float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+float3 log2(float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+float4 log2(float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2))) double
+log2(double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+double2 log2(double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+double3 log2(double3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+double4 log2(double4);
+
+// log10 builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+half log10(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+half2 log10(half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+half3 log10(half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+half4 log10(half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10))) float
+log10(float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+float2 log10(float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+float3 log10(float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+float4 log10(float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10))) double
+log10(double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+double2 log10(double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+double3 

[PATCH] D144181: [clang][DebugInfo] Add abi-tags on constructors/destructors as LLVM annotations

2023-02-16 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

Size-wise this looks like an acceptable increase. If we created a new 
DW_AT_LLVM_abi_tag, we could save an extra 4 bytes (assuming DW_FORM_strp) per 
DIE. That might be worth it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144181

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


[PATCH] D144120: [HLSL] add log library functions

2023-02-16 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 498051.
bob80905 added a comment.

- add newline


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144120

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/log.hlsl
  clang/test/CodeGenHLSL/builtins/log10.hlsl
  clang/test/CodeGenHLSL/builtins/log2.hlsl

Index: clang/test/CodeGenHLSL/builtins/log2.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/log2.hlsl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.log2.f16(
+// NO_HALF: define noundef float @"?test_log2_half@@YA$halff@$halff@@Z"(
+// NO_HALF: call float @llvm.log2.f32(
+half test_log2_half ( half p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.log2.v2f16
+// NO_HALF: define noundef <2 x float> @"?test_log2_float2@@YAT?$__vector@M$01@__clang@@T12@@Z"(
+// NO_HALF: call <2 x float> @llvm.log2.v2f32(
+half2 test_log2_half2 ( half2 p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.log2.v3f16
+// NO_HALF: define noundef <3 x float> @"?test_log2_float3@@YAT?$__vector@M$02@__clang@@T12@@Z"(
+// NO_HALF: call <3 x float> @llvm.log2.v3f32(
+half3 test_log2_half3 ( half3 p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <4 x half> @
+// CHECK: call <4 x half> @llvm.log2.v4f16
+// NO_HALF: define noundef <4 x float> @"?test_log2_float4@@YAT?$__vector@M$03@__clang@@T12@@Z"(
+// NO_HALF: call <4 x float> @llvm.log2.v4f32(
+half4 test_log2_half4 ( half4 p0 ) {
+  return log2 ( p0 );
+}
+
+// CHECK: define noundef float @
+// CHECK: call float @llvm.log2.f32(
+float test_log2_float ( float p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <2 x float> @
+// CHECK: call <2 x float> @llvm.log2.v2f32
+float2 test_log2_float2 ( float2 p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <3 x float> @
+// CHECK: call <3 x float> @llvm.log2.v3f32
+float3 test_log2_float3 ( float3 p0 ) {
+  return log2 ( p0 );
+}
+// CHECK: define noundef <4 x float> @
+// CHECK: call <4 x float> @llvm.log2.v4f32
+float4 test_log2_float4 ( float4 p0 ) {
+  return log2 ( p0 );
+}
Index: clang/test/CodeGenHLSL/builtins/log10.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/log10.hlsl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.log10.f16(
+// NO_HALF: define noundef float @"?test_log10_half@@YA$halff@$halff@@Z"(
+// NO_HALF: call float @llvm.log10.f32(
+half test_log10_half ( half p0 ) {
+  return log10 ( p0 );
+}
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.log10.v2f16
+// NO_HALF: define noundef <2 x float> @"?test_log10_float2@@YAT?$__vector@M$01@__clang@@T12@@Z"(
+// NO_HALF: call <2 x float> @llvm.log10.v2f32(
+half2 test_log10_half2 ( half2 p0 ) {
+  return log10 ( p0 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.log10.v3f16
+// NO_HALF: define noundef <3 x float> @"?test_log10_float3@@YAT?$__vector@M$02@__clang@@T12@@Z"(
+// NO_HALF: call <3 x float> @llvm.log10.v3f32(
+half3 test_log10_half3 ( half3 p0 ) {
+  return log10 ( p0 );
+}
+// CHECK: define noundef <4 x half> @
+// CHECK: call <4 x half> @llvm.log10.v4f16
+// NO_HALF: define noundef <4 x float> @"?test_log10_float4@@YAT?$__vector@M$03@__clang@@T12@@Z"(
+// NO_HALF: call <4 x float> @llvm.log10.v4f32(
+half4 test_log10_half4 ( half4 p0 ) {
+  return log10 ( p0 );
+}
+
+// CHECK: define noundef float @
+// CHECK: call float @llvm.log10.f32(
+float test_log10_float ( float p0 ) {
+  return log10 ( p0 );
+}
+// CHECK: define noundef <2 x float> @
+// CHECK: call <2 x float> @llvm.log10.v2f32
+float2 test_log10_float2 ( float2 p0 ) {
+  return log10 ( p0 );
+}
+// CHECK: define noundef <3 x float> @
+// CHECK: call <3 x float> @llvm.log10.v3f32
+float3 test_log10_float3 ( float3 p0 ) {
+  return log10 ( 

[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

2023-02-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D142907#4132318 , @jcranmer-intel 
wrote:

> Not entirely sure where the best place to effect this (I think somewhere in 
> the clang driver code?), but on further reflection, it feels like strict 
> fp-model in clang should set the denormal mode to dynamic.

I was thinking of changing the default in general to dynamic. I was going to at 
least change the strictfp default in a follow up


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

https://reviews.llvm.org/D142907

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


[PATCH] D142822: [clang] ASTImporter: Fix importing of va_list types and declarations

2023-02-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

With this fix the `std::__va_list` is created at initialization of Sema, 
previously it was not there. Function `CreateAArch64ABIBuiltinVaListDecl` 
(ASTContext.cpp) makes the namespace `std` and `__va_list` record. This change 
fixes the problem with `ASTImporter` probably because the __va_list record 
exists before start of AST import, this way it is found and added to 
`ASTImporterLookupTable` at initialization (the original problem was caused 
because `std::__va_list` is missing from `ASTImporterLookupTable`). But I was 
thinking of other ways to fix the problem. My old fix for the problem may still 
work without any test failures:

In D136886#3892261 , @balazske wrote:

> `ASTImporterLookupTable` do not contain an entry for `__va_list_tag`, I do 
> not know why it is missing. If it is added "manually" the crash disappears 
> (without fix in `VisitTypedefType`). Following code was used to add 
> VaListTagDecl:
>
>   ASTImporterLookupTable::ASTImporterLookupTable(TranslationUnitDecl ) {
> Builder B(*this);
> B.TraverseDecl();
> // Add __va_list_tag to the table, it is not visited by the builder.
> if (NamedDecl *D = 
> dyn_cast_or_null(TU.getASTContext().getVaListTagDecl()))
>   add(, D);
>   }
>
> The problem probably existed before but did not have visible effect until the 
> new assertion was added.

It can happen (without any of the new fixes) that `std::__va_list` is created 
during the AST import process, it is created at first access. This can be the 
reason why it is missing from the lookup table: It is created implicitly by 
`ASTContext` code in the "to" context during import. To fix this problem, I 
think the above quoted code is a good solution: The va_list declaration is 
created at start of AST import (if it did not exist yet) (by the get function) 
and added to the lookup table. Probably it can be a problem that the va_list 
declaration and std namespace appears in a TU by just importing any code into 
it, but probably no tests will fail for this case. Another way to fix the 
problem is to add special handling of `std::__va_list` at least on the affected 
platforms to `ASTImporterLookupTable` but I did not check of this can be done. 
I do not like to change function `ASTImporter::VisitTypedefType` like in the 
very first fix of @vabridgers because it affects how every typedef is imported, 
and that can be incorrect. Probably some special handling of a record called 
`__va_list` at AST import can be a good fix too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142822

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


[PATCH] D143436: [clangd] Apply standard adaptors to CDBs pushed from LSP

2023-02-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:222
+  tooling::addExpandedResponseFiles(Cmd, Command.Directory, Tokenizer, *FS);
+  tooling::addTargetAndModeForProgramName(Cmd, Cmd.front());
   auto  = clang::driver::getDriverOptTable();

nridge wrote:
> The target needs to be added **after** the call to `SystemIncludeExtractor` 
> later in this function (this is what D138546 is trying to fix). The reason is 
> that `SystemIncludeExtractor` includes any `--target` flag in the compiler 
> driver being queried for system includes, which may be gcc, which does not 
> support `--target`.
(I guess we could make that change separately in D138546, but if we're changing 
the place where the `--target` is added in this patch, I figure we might as 
well move it directly to the desired place.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

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


[PATCH] D143436: [clangd] Apply standard adaptors to CDBs pushed from LSP

2023-02-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:222
+  tooling::addExpandedResponseFiles(Cmd, Command.Directory, Tokenizer, *FS);
+  tooling::addTargetAndModeForProgramName(Cmd, Cmd.front());
   auto  = clang::driver::getDriverOptTable();

The target needs to be added **after** the call to `SystemIncludeExtractor` 
later in this function (this is what D138546 is trying to fix). The reason is 
that `SystemIncludeExtractor` includes any `--target` flag in the compiler 
driver being queried for system includes, which may be gcc, which does not 
support `--target`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

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


[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

2023-02-16 Thread Joshua Cranmer via Phabricator via cfe-commits
jcranmer-intel added a comment.

Not entirely sure where the best place to effect this (I think somewhere in the 
clang driver code?), but on further reflection, it feels like strict fp-model 
in clang should set the denormal mode to dynamic.


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

https://reviews.llvm.org/D142907

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


[PATCH] D143509: Move the BySpelling map to IncludeStructure.

2023-02-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Headers.h:167
+  // Spelling should include brackets or quotes, e.g. .
+  llvm::SmallVector
+  mainFileIncludesWithSpelling(llvm::StringRef Spelling) const {

we're still returning just the `HeaderID`, the suggestion was to return 
`llvm::SmallVector` so that applications can work with other 
information available in the `Inclusion`. we also won't have any requirements 
around include being resolved that way. the application should figure out what 
to do if `HeaderID` is missing.

also can you move this function body to source file instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143509

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


[PATCH] D143436: [clangd] Apply standard adaptors to CDBs pushed from LSP

2023-02-16 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 498038.
DmitryPolukhin added a comment.

Move standard adaptors to CommandMangler


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/Tooling.cpp

Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -299,6 +300,31 @@
   }
 }
 
+void addExpandedResponseFiles(std::vector ,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem ) {
+  bool SeenRSPFile = false;
+  llvm::SmallVector Argv;
+  Argv.reserve(CommandLine.size());
+  for (auto  : CommandLine) {
+Argv.push_back(Arg.c_str());
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
+  }
+  if (!SeenRSPFile)
+return;
+  llvm::BumpPtrAllocator Alloc;
+  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
+  llvm::Error Err =
+  ECtx.setVFS().setCurrentDir(WorkingDir).expandResponseFiles(Argv);
+  if (Err)
+llvm::errs() << Err;
+  // Don't assign directly, Argv aliases CommandLine.
+  std::vector ExpandedArgv(Argv.begin(), Argv.end());
+  CommandLine = std::move(ExpandedArgv);
+}
+
 } // namespace tooling
 } // namespace clang
 
@@ -684,7 +710,7 @@
 
   if (!Invocation.run())
 return nullptr;
- 
+
   assert(ASTs.size() == 1);
   return std::move(ASTs[0]);
 }
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -48,28 +49,9 @@
 
 private:
   std::vector expand(std::vector Cmds) const {
-for (auto  : Cmds) {
-  bool SeenRSPFile = false;
-  llvm::SmallVector Argv;
-  Argv.reserve(Cmd.CommandLine.size());
-  for (auto  : Cmd.CommandLine) {
-Argv.push_back(Arg.c_str());
-if (!Arg.empty())
-  SeenRSPFile |= Arg.front() == '@';
-  }
-  if (!SeenRSPFile)
-continue;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
-  llvm::Error Err = ECtx.setVFS(FS.get())
-.setCurrentDir(Cmd.Directory)
-.expandResponseFiles(Argv);
-  if (Err)
-llvm::errs() << Err;
-  // Don't assign directly, Argv aliases CommandLine.
-  std::vector ExpandedArgv(Argv.begin(), Argv.end());
-  Cmd.CommandLine = std::move(ExpandedArgv);
-}
+for (auto  : Cmds)
+  tooling::addExpandedResponseFiles(Cmd.CommandLine, Cmd.Directory,
+Tokenizer, *FS);
 return Cmds;
   }
 
Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -506,6 +506,12 @@
 void addTargetAndModeForProgramName(std::vector ,
 StringRef InvokedAs);
 
+/// Helper function that expands response files in command line.
+void addExpandedResponseFiles(std::vector ,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem );
+
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
   ArrayRef CC1Args,
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -49,7 +49,7 @@
   Cmd.CommandLine = {"clang++", "--", "foo.cc", "bar.cc"};
   

[PATCH] D144195: [XCore] Adapt Clang tests to opaque pointers.

2023-02-16 Thread Nigel Perks 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 rG0871337d97f7: [XCore] Adapt Clang tests to opaque pointers. 
(authored by nigelp-xmos).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144195

Files:
  clang/test/CodeGen/xcore-abi.c
  clang/test/CodeGen/xcore-stringtype.c

Index: clang/test/CodeGen/xcore-stringtype.c
===
--- clang/test/CodeGen/xcore-stringtype.c
+++ clang/test/CodeGen/xcore-stringtype.c
@@ -1,5 +1,5 @@
 // REQUIRES: xcore-registered-target
-// RUN: %clang_cc1 -no-opaque-pointers -triple xcore-unknown-unknown -fno-signed-char -fno-common -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple xcore-unknown-unknown -fno-signed-char -fno-common -emit-llvm -o - %s | FileCheck %s
 
 // CHECK: target triple = "xcore-unknown-unknown"
 
@@ -23,8 +23,7 @@
 
 
 // test BuiltinType
-// CHECK: !{{[0-9]+}} = !{void (i1, i8, i8, i8, i16, i16, i16, i32, i32, i32,
-// CHECK:  i32, i32, i32, i64, i64, i64, float, double, double)*
+// CHECK: !{{[0-9]+}} = !{ptr
 // CHECK:  @builtinType, !"f{0}(b,uc,uc,sc,ss,us,ss,si,ui,si,sl,
 // CHECK:  ul,sl,sll,ull,sll,ft,d,ld)"}
 void builtinType(_Bool B, char C, unsigned char UC, signed char SC, short S,
@@ -36,14 +35,14 @@
 
 
 // test FunctionType & Qualifiers
-// CHECK: !{{[0-9]+}} = !{void ()* @gI, !"f{0}()"}
-// CHECK: !{{[0-9]+}} = !{void (...)* @eI, !"f{0}()"}
-// CHECK: !{{[0-9]+}} = !{void ()* @gV, !"f{0}(0)"}
-// CHECK: !{{[0-9]+}} = !{void ()* @eV, !"f{0}(0)"}
-// CHECK: !{{[0-9]+}} = !{void (i32, ...)* @gVA, !"f{0}(si,va)"}
-// CHECK: !{{[0-9]+}} = !{void (i32, ...)* @eVA, !"f{0}(si,va)"}
-// CHECK: !{{[0-9]+}} = !{i32* (i32*)* @gQ, !"f{crv:p(cv:si)}(p(cv:si))"}
-// CHECK: !{{[0-9]+}} = !{i32* (i32*)* @eQ, !"f{crv:p(cv:si)}(p(cv:si))"}
+// CHECK: !{{[0-9]+}} = !{ptr @gI, !"f{0}()"}
+// CHECK: !{{[0-9]+}} = !{ptr @eI, !"f{0}()"}
+// CHECK: !{{[0-9]+}} = !{ptr @gV, !"f{0}(0)"}
+// CHECK: !{{[0-9]+}} = !{ptr @eV, !"f{0}(0)"}
+// CHECK: !{{[0-9]+}} = !{ptr @gVA, !"f{0}(si,va)"}
+// CHECK: !{{[0-9]+}} = !{ptr @eVA, !"f{0}(si,va)"}
+// CHECK: !{{[0-9]+}} = !{ptr @gQ, !"f{crv:p(cv:si)}(p(cv:si))"}
+// CHECK: !{{[0-9]+}} = !{ptr @eQ, !"f{crv:p(cv:si)}(p(cv:si))"}
 extern void eI();
 void gI() {eI();};
 extern void eV(void);
@@ -57,10 +56,10 @@
 
 
 // test PointerType
-// CHECK: !{{[0-9]+}} = !{i32* (i32*, i32* (i32*)*)*
+// CHECK: !{{[0-9]+}} = !{ptr
 // CHECK:   @pointerType, !"f{p(si)}(p(si),p(f{p(si)}(p(si"}
-// CHECK: !{{[0-9]+}} = !{i32** @EP, !"p(si)"}
-// CHECK: !{{[0-9]+}} = !{i32** @GP, !"p(si)"}
+// CHECK: !{{[0-9]+}} = !{ptr @EP, !"p(si)"}
+// CHECK: !{{[0-9]+}} = !{ptr @GP, !"p(si)"}
 extern int* EP;
 int* GP;
 int* pointerType(int *I, int * (*FP)(int *)) {
@@ -68,19 +67,19 @@
 }
 
 // test ArrayType
-// CHECK: !{{[0-9]+}} = !{[2 x i32]* (i32*, i32*, [2 x i32]*, [2 x i32]*, i32*)*
+// CHECK: !{{[0-9]+}} = !{ptr
 // CHECK:   @arrayType, !"f{p(a(2:si))}(p(si),p(cv:si),p(a(2:si)),
 // CHECK:   p(a(2:si)),p(si))"}
-// CHECK: !{{[0-9]+}} = !{[0 x i32]* @EA1, !"a(*:cv:si)"}
-// CHECK: !{{[0-9]+}} = !{[2 x i32]* @EA2, !"a(2:si)"}
-// CHECK: !{{[0-9]+}} = !{[0 x [2 x i32]]* @EA3, !"a(*:a(2:si))"}
-// CHECK: !{{[0-9]+}} = !{[3 x [2 x i32]]* @EA4, !"a(3:a(2:si))"}
-// CHECK: !{{[0-9]+}} = !{[2 x i32]* @GA1, !"a(2:cv:si)"}
-// CHECK: !{{[0-9]+}} = !{void ([2 x i32]*)* @arrayTypeVariable1,
+// CHECK: !{{[0-9]+}} = !{ptr @EA1, !"a(*:cv:si)"}
+// CHECK: !{{[0-9]+}} = !{ptr @EA2, !"a(2:si)"}
+// CHECK: !{{[0-9]+}} = !{ptr @EA3, !"a(*:a(2:si))"}
+// CHECK: !{{[0-9]+}} = !{ptr @EA4, !"a(3:a(2:si))"}
+// CHECK: !{{[0-9]+}} = !{ptr @GA1, !"a(2:cv:si)"}
+// CHECK: !{{[0-9]+}} = !{ptr @arrayTypeVariable1,
 // CHECK:   !"f{0}(p(a(2:si)))"}
-// CHECK: !{{[0-9]+}} = !{void (void ([2 x i32]*)*)* @arrayTypeVariable2,
+// CHECK: !{{[0-9]+}} = !{ptr @arrayTypeVariable2,
 // CHECK:   !"f{0}(p(f{0}(p(a(2:si)"}
-// CHECK: !{{[0-9]+}} = !{[3 x [2 x i32]]* @GA2, !"a(3:a(2:si))"}
+// CHECK: !{{[0-9]+}} = !{ptr @GA2, !"a(3:a(2:si))"}
 extern int GA2[3][2];
 extern const volatile int EA1[];
 extern int EA2[2];
@@ -108,16 +107,16 @@
 
 
 // test StructureType
-// CHECK: !{{[0-9]+}} = !{void (%struct.S1*)* @structureType1,
+// CHECK: !{{[0-9]+}} = !{ptr @structureType1,
 // CHECK:   !"f{0}(s(S1){m(ps2){p(s(S2){m(ps3){p(s(S3){m(s1){s(S1){}}})}})}})"}
-// CHECK: !{{[0-9]+}} = !{void (%struct.S2*)* @structureType2,
+// CHECK: !{{[0-9]+}} = !{ptr @structureType2,
 // CHECK:   !"f{0}(s(S2){m(ps3){p(s(S3){m(s1){s(S1){m(ps2){p(s(S2){}))}})"}
-// CHECK: !{{[0-9]+}} = !{void (%struct.S3*)* @structureType3,
+// CHECK: !{{[0-9]+}} = !{ptr @structureType3,
 // CHECK:   !"f{0}(s(S3){m(s1){s(S1){m(ps2){p(s(S2){m(ps3){p(s(S3){})}}))"}
-// CHECK: !{{[0-9]+}} = !{void (%struct.S4*)* 

[clang] 0871337 - [XCore] Adapt Clang tests to opaque pointers.

2023-02-16 Thread Nigel Perks via cfe-commits

Author: Nigel Perks
Date: 2023-02-16T16:32:29Z
New Revision: 0871337d97f71cac2dbc9cce33c0ecca3c5e5f9c

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

LOG: [XCore] Adapt Clang tests to opaque pointers.

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

Added: 


Modified: 
clang/test/CodeGen/xcore-abi.c
clang/test/CodeGen/xcore-stringtype.c

Removed: 




diff  --git a/clang/test/CodeGen/xcore-abi.c b/clang/test/CodeGen/xcore-abi.c
index 28fdae57de72..4dd0f221533b 100644
--- a/clang/test/CodeGen/xcore-abi.c
+++ b/clang/test/CodeGen/xcore-abi.c
@@ -1,12 +1,12 @@
 // REQUIRES: xcore-registered-target
-// RUN: %clang_cc1 -no-opaque-pointers -triple xcore -verify %s
+// RUN: %clang_cc1 -triple xcore -verify %s
 _Static_assert(sizeof(long long) == 8, "sizeof long long is wrong");
 _Static_assert(_Alignof(long long) == 4, "alignof long long is wrong");
 
 _Static_assert(sizeof(double) == 8, "sizeof double is wrong");
 _Static_assert(_Alignof(double) == 4, "alignof double is wrong");
 
-// RUN: %clang_cc1 -no-opaque-pointers -triple xcore-unknown-unknown 
-fno-signed-char -fno-common -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple xcore-unknown-unknown -fno-signed-char -fno-common 
-emit-llvm -o - %s | FileCheck %s
 
 // CHECK: target triple = "xcore-unknown-unknown"
 
@@ -25,91 +25,77 @@ void testva (int n, ...) {
   // CHECK-LABEL: testva
   va_list ap;
   va_start(ap,n);
-  // CHECK: [[AP:%[a-z0-9]+]] = alloca i8*, align 4
-  // CHECK: [[AP1:%[a-z0-9]+]] = bitcast i8** [[AP]] to i8*
-  // CHECK: call void @llvm.va_start(i8* [[AP1]])
+  // CHECK: [[AP:%[a-z0-9]+]] = alloca ptr, align 4
+  // CHECK: [[V5:%[a-z0-9]+]] = alloca %struct.x, align 4
+  // CHECK: [[TMP:%[a-z0-9]+]] = alloca [4 x i32], align 4
+  // CHECK: call void @llvm.va_start(ptr [[AP]])
 
   char* v1 = va_arg (ap, char*);
   f(v1);
-  // CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
-  // CHECK: [[P:%[a-z0-9]+]] = bitcast i8* [[I]] to i8**
-  // CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 4
-  // CHECK: store i8* [[IN]], i8** [[AP]]
-  // CHECK: [[V1:%[a-z0-9]+]] = load i8*, i8** [[P]]
-  // CHECK: store i8* [[V1]], i8** [[V:%[a-z0-9]+]], align 4
-  // CHECK: [[V2:%[a-z0-9]+]] = load i8*, i8** [[V]], align 4
-  // CHECK: call void @f(i8* noundef [[V2]])
+  // CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]]
+  // CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, ptr [[I]], i32 4
+  // CHECK: store ptr [[IN]], ptr [[AP]]
+  // CHECK: [[V1:%[a-z0-9]+]] = load ptr, ptr [[I]]
+  // CHECK: store ptr [[V1]], ptr [[V:%[a-z0-9]+]], align 4
+  // CHECK: [[V2:%[a-z0-9]+]] = load ptr, ptr [[V]], align 4
+  // CHECK: call void @f(ptr noundef [[V2]])
 
   char v2 = va_arg (ap, char); // expected-warning{{second argument to 
'va_arg' is of promotable type 'char'}}
   f();
-  // CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
-  // CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 4
-  // CHECK: store i8* [[IN]], i8** [[AP]]
-  // CHECK: [[V1:%[a-z0-9]+]] = load i8, i8* [[I]]
-  // CHECK: store i8 [[V1]], i8* [[V:%[a-z0-9]+]], align 1
-  // CHECK: call void @f(i8* noundef [[V]])
+  // CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]]
+  // CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, ptr [[I]], i32 4
+  // CHECK: store ptr [[IN]], ptr [[AP]]
+  // CHECK: [[V1:%[a-z0-9]+]] = load i8, ptr [[I]]
+  // CHECK: store i8 [[V1]], ptr [[V:%[a-z0-9]+]], align 1
+  // CHECK: call void @f(ptr noundef [[V]])
 
   int v3 = va_arg (ap, int);
   f();
-  // CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
-  // CHECK: [[P:%[a-z0-9]+]] = bitcast i8* [[I]] to i32*
-  // CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 4
-  // CHECK: store i8* [[IN]], i8** [[AP]]
-  // CHECK: [[V1:%[a-z0-9]+]] = load i32, i32* [[P]]
-  // CHECK: store i32 [[V1]], i32* [[V:%[a-z0-9]+]], align 4
-  // CHECK: [[V2:%[a-z0-9]+]] = bitcast i32* [[V]] to i8*
-  // CHECK: call void @f(i8* noundef [[V2]])
+  // CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]]
+  // CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, ptr [[I]], i32 4
+  // CHECK: store ptr [[IN]], ptr [[AP]]
+  // CHECK: [[V1:%[a-z0-9]+]] = load i32, ptr [[I]]
+  // CHECK: store i32 [[V1]], ptr [[V:%[a-z0-9]+]], align 4
+  // CHECK: call void @f(ptr noundef [[V]])
 
   long long int v4 = va_arg (ap, long long int);
   f();
-  // CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
-  // CHECK: [[P:%[a-z0-9]+]] = bitcast i8* [[I]] to i64*
-  // CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 8
-  // CHECK: store i8* [[IN]], i8** [[AP]]
-  // CHECK: [[V1:%[a-z0-9]+]] = load i64, i64* [[P]]
-  // CHECK: store i64 [[V1]], i64* [[V:%[a-z0-9]+]], align 4
-  // CHECK:[[V2:%[a-z0-9]+]] = bitcast i64* [[V]] 

[PATCH] D144196: [C2x] Remove the ATOMIC_VAR_INIT macro from stdatomic.h

2023-02-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: clang-language-wg, jyknight, libc++.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This implements WG14 N2886 
(https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2886.htm) which removed the 
macro entirely. (NB the macro was deprecated in C17.) As the paper is not 
particularly clear on what alternative was picked, here are my notes from the 
May 2022 meeting:

Does WG14 wish to adopt variant 1, change 3.2, 3.3, and 3.4 from N2886 into 
C23? 14/2/2 (consensus).
Does WG14 want to exchange Variant 1 with Variant 2 in N2886 in C23? 9/3/6 
(consensus).
(There was no sentiment in the room for either Variant 3 or Variant 4 so those 
were not voted on.)
Does WG14 want to integrate change 3.5 in N2886 into C23? 8/1/9 (consensus).
Does WG14 want to integrate change 3.6 in N2886 into C23? 2/5/9 (no consensus).

I've added the libc++ reviewers to ensure this doesn't negatively impact 
 and the clang-vendors group for early awareness about a potentially 
breaking change. Any code that is broken by the removal can remove the use of 
`ATOMIC_VAR_INIT` and use regular initialization instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144196

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/stdatomic.h
  clang/test/C/C2x/n2886.c
  clang/www/c_status.html


Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1131,7 +1131,7 @@
 
   Remove ATOMIC_VAR_INIT v2
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2886.htm;>N2886
-  No
+  Clang 17
 
 
   Require exact-width integer type interfaces v2
Index: clang/test/C/C2x/n2886.c
===
--- /dev/null
+++ clang/test/C/C2x/n2886.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify=okay -std=c11 -ffreestanding %s
+// RUN: %clang_cc1 -verify -std=c17 -ffreestanding %s
+// RUN: %clang_cc1 -verify -std=c2x -ffreestanding %s
+
+/* WG14 N2886: yes
+ * Remove ATOMIC_VAR_INIT v2
+ */
+
+/* okay-no-diagnostics */
+#include 
+
+_Atomic int a = ATOMIC_VAR_INIT(0); /* #diag */
+#if __STDC_VERSION__ <= 201710L
+/* expected-warning@#diag {{macro 'ATOMIC_VAR_INIT' has been marked as 
deprecated}}
+   expected-note@stdatomic.h:* {{macro marked 'deprecated' here}}
+*/
+#else
+/* expected-error@#diag {{use of undeclared identifier 'ATOMIC_VAR_INIT'}} */
+#endif
+
Index: clang/lib/Headers/stdatomic.h
===
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -45,9 +45,16 @@
 #define ATOMIC_POINTER_LOCK_FREE__CLANG_ATOMIC_POINTER_LOCK_FREE
 
 /* 7.17.2 Initialization */
-
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+   in C2x mode; switch to the correct values once they've been published. */
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 202000L) ||   
\
+defined(__cplusplus)
+/* ATOMIC_VAR_INIT was removed in C2x, but still remains in C++2b. */
 #define ATOMIC_VAR_INIT(value) (value)
-#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L) || 
\
+#endif
+
+#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L &&  
\
+  __STDC_VERSION__ < 202000L) ||   
\
  (defined(__cplusplus) && __cplusplus >= 202002L)) &&  
\
 !defined(_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS)
 /* ATOMIC_VAR_INIT was deprecated in C17 and C++20. */
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -77,6 +77,9 @@
 - Implemented the ``unreachable`` macro in freestanding  for
   `WG14 N2826 `_
 
+- Removed the ``ATOMIC_VAR_INIT`` macro in C2x and later standards modes, which
+  implements `WG14 N2886 
`_
+
 Non-comprehensive list of changes in this release
 -
 - Clang now saves the address of ABI-indirect function parameters on the stack,


Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1131,7 +1131,7 @@
 
   Remove ATOMIC_VAR_INIT v2
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2886.htm;>N2886
-  No
+  Clang 17
 
 
   Require exact-width integer type interfaces v2
Index: clang/test/C/C2x/n2886.c
===
--- /dev/null
+++ clang/test/C/C2x/n2886.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify=okay 

[PATCH] D144195: [XCore] Adapt Clang tests to opaque pointers.

2023-02-16 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic 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/D144195/new/

https://reviews.llvm.org/D144195

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


  1   2   >