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

2023-02-11 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 496670.
owenpan added a comment.

Added `tryMergeGreaterGreater()` to and fixed `tryMergerLessLess()` of 
`FormatTokenLexer`.


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 &Operator : Operators) {
+std::string Input("C<&operator");
+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<&operator< > 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<&operator- > minus;");
+  verifyFormat("C<&operator> > gt;");
+  verifyFormat("C<&operator>= > ge;");
+  verifyFormat("C<&operator<= > le;");
+  verifyFormat("C<&operator< > 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 = CurrentToken->getNextNonComment();
+if (!Next)
 

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

2023-02-11 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D143755#4118802 , @vedgy wrote:

> Hi @owenpan. Thank you for fixing this bug!
> Have you noticed this paragraph in my bug report?
>
>> I believe `clang_getTypeSpelling()`, or more likely `QualType::print()` used 
>> by it, should insert a tab character between such tokens to pretty-print 
>> compilable code. The tab character is preferable to the space character 
>> here, because the users may rely on the fact that pretty-printed binary 
>> operators are surrounded by spaces to distinguish them from angle brackets.

Yes, but I'm not familiar with these functions.

> KDevelop parses the result of `clang_getTypeSpelling()` when libclang API is 
> lacking. Since this recent commit 
> 
>  KDevelop's parsing relies on the empirical fact that only operators are 
> surrounded by spaces to distinguish them from angle brackets. Does this 
> revision introduce angle brackets surrounded by spaces? Can tab characters be 
> used instead? If not, do you know how else such angle brackets can be 
> distinguished from operators?

This patch should fix the reported invalid-code-generation bug by leaving a 
space between the overloaded operator and the closing angle bracket. 
clang-format doesn't insert tabs in the middle of a line (except when doing 
alignment if `UseTab` is set to `Always`).


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

https://reviews.llvm.org/D143755

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


[PATCH] D143657: [Clang][RISCV] Guard vector float16 type correctly with semantic analysis

2023-02-11 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 496680.
eopXD added a comment.

Address comment from Craig.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143657

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/test/Sema/riscv-vector-float16-check.c
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -368,14 +368,13 @@
   }
 }
   }
-  OS << "#if defined(__riscv_zvfh)\n";
+
   for (int Log2LMUL : Log2LMULs) {
 auto T = TypeCache.computeType(BasicType::Float16, Log2LMUL,
PrototypeDescriptor::Vector);
 if (T)
   printType(*T);
   }
-  OS << "#endif\n";
 
   OS << "#if (__riscv_v_elen_fp >= 32)\n";
   for (int Log2LMUL : Log2LMULs) {
Index: clang/test/Sema/riscv-vector-float16-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-float16-check.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vfloat16m1_t foo() { /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -171,7 +171,6 @@
   const TargetInfo &TI = Context.getTargetInfo();
   bool HasVectorFloat32 = TI.hasFeature("zve32f");
   bool HasVectorFloat64 = TI.hasFeature("zve64d");
-  bool HasZvfh = TI.hasFeature("experimental-zvfh");
   bool HasRV64 = TI.hasFeature("64bit");
   bool HasFullMultiply = TI.hasFeature("v");
 
@@ -223,9 +222,6 @@
 continue;
 
   // Check requirement.
-  if (BaseType == BasicType::Float16 && !HasZvfh)
-continue;
-
   if (BaseType == BasicType::Float32 && !HasVectorFloat32)
 continue;
 
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -2046,6 +2046,12 @@
 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
 }
 
+if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ true) &&
+!Context.getTargetInfo().hasFeature("experimental-zvfh")) {
+  Diag(Loc, diag::err_riscv_type_requires_extension, FD)
+  << Ty << "zvfh";
+}
+
 // Don't allow SVE types in functions without a SVE target.
 if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
   llvm::StringMap CallerFeatureMap;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11738,6 +11738,9 @@
   "builtin requires%select{| at least one of the following extensions to be enabled}0: %1">;
 def err_riscv_builtin_invalid_lmul : Error<
   "LMUL argument must be in the range [0,3] or [5,7]">;
+def err_riscv_type_requires_extension : Error<
+  "RISC-V type %0 requires the '%1' extension"
+>;
 
 def err_std_source_location_impl_not_found : Error<
   "'std::source_location::__impl' was not found; it must be defined before '__builtin_source_location' is called">;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -2279,6 +2279,8 @@
 
   bool isRVVType() const;
 
+  bool isRVVType(unsigned Bitwidth, bool IsFloat) const;
+
   /// Return the implicit lifetime for this type, which must not be dependent.
   Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
 
@@ -7160,6 +7162,17 @@
 false; // end of boolean or operation.
 }
 
+inline bool Type::isRVVType(unsigned Bitwidth, bool IsFloat) const {
+  bool Ret = false;
+#define RVV_TYPE(Name, Id, SingletonId)
+#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   \
+IsFP)  \
+  if (ElBits == Bitwidth && IsFloat == IsFP)   \
+Ret |= isSpecificBuiltinType(BuiltinType::Id);
+#include "clang/Basic/RISCVVTypes.def"
+  return Ret;
+}
+
 inline bool Type::isTemplateTypeParmType() const {
   return isa(CanonicalType);
 }
___
cf

[PATCH] D143768: [Clang] Add options to disable direct linking of arch tools

2023-02-11 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

Actually, I might want to optionally link this stuff in the `libc` project in 
the future as well. That would be a dependency only required for tests but it 
might be compelling then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143768

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


[PATCH] D143768: [Clang] Add options to disable direct linking of arch tools

2023-02-11 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

FWIW, there are methods in CMake to check if features (such as if a struct 
contains specific data member, or if a library contains APIs). I think that 
would be the right way to fix the issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143768

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


[PATCH] D137527: [C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20 Named Modules in P1689 format (2/4)

2023-02-11 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

I'm still seeing random crashes today on a linux buildbot in the test you added 
P1689 .cppm. Can you either fix or revert?

- https://lab.llvm.org/buildbot/#/builders/139/builds/35899
- https://lab.llvm.org/buildbot/#/builders/139/builds/35886

  corrupted size vs. prev_size while consolidating
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace.
   #0 0x55baf810283f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang-scan-deps+0x3f)
   #1 0x55baf8100214 SignalHandler(int) Signals.cpp:0:0
   #2 0x7fa226358420 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
   #3 0x7fa225e2500b raise 
/build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
   #4 0x7fa225e04859 abort 
/build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
   #5 0x7fa225e6f26e __libc_message 
/build/glibc-SzIz7B/glibc-2.31/libio/../sysdeps/posix/libc_fatal.c:155:5
   #6 0x7fa225e772fc /build/glibc-SzIz7B/glibc-2.31/malloc/malloc.c:5348:3
   #7 0x7fa225e7904e _int_free 
/build/glibc-SzIz7B/glibc-2.31/malloc/malloc.c:4245:6
   #8 0x7fa225e7c88d tcache_thread_shutdown 
/build/glibc-SzIz7B/glibc-2.31/malloc/malloc.c:2960:33
   #9 0x7fa225e7c88d __malloc_arena_thread_freeres 
/build/glibc-SzIz7B/glibc-2.31/malloc/arena.c:951:3
  #10 0x7fa22634c62f start_thread 
/build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:496:7
  #11 0x7fa225f01133 __clone 
/build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:97:0


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137527

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


[PATCH] D143825: [clang-format] Put ports on separate lines in Verilog module headers

2023-02-11 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan, 
rymiel.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

New:

  module mh1
  (input var int in1,
   input var in2, in3,
   output tagged_st out);
  endmodule

Old:

  module mh1
  (input var int in1, input var in2, in3, output tagged_st out);
  endmodule

`getNextNonComment` was modified to return a non-const pointer because
we needed to use it that way in `verilogGroupDecl`.

The comment on line 2620 was a typo.  We corrected it while modifying
the function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143825

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -275,6 +275,76 @@
 "x = x;"));
 }
 
+TEST_F(FormatTestVerilog, Headers) {
+  // Test headers with multiple ports.
+  verifyFormat("module mh1\n"
+   "(input var int in1,\n"
+   " input var shortreal in2,\n"
+   " output tagged_st out);\n"
+   "endmodule");
+  // Ports should be grouped by types.
+  verifyFormat("module test\n"
+   "(input [7 : 0] a,\n"
+   " input signed [7 : 0] b, c, d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input [7 : 0] a,\n"
+   " (* x = x *) input signed [7 : 0] b, c, d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input [7 : 0] a = 0,\n"
+   " input signed [7 : 0] b = 0, c = 0, d = 0);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "#(parameter x)\n"
+   "(input [7 : 0] a,\n"
+   " input signed [7 : 0] b, c, d);\n"
+   "endmodule");
+  // When a line needs to be broken, ports of the same type should be aligned to
+  // the same column.
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b, c, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "((* x = x *) input signed [7 : 0] b, c, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b = 0, c, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b, c = 0, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b, c, //\n"
+   "  d = 0);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input wire logic signed [7 : 0][0 : 1] b, c, //\n"
+   "d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b, //\n"
+   "  c, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input [7 : 0] a,\n"
+   " input signed [7 : 0] b, //\n"
+   "  c, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b, //\n"
+   "  c, //\n"
+   "  d,\n"
+   " output signed [7 : 0] h);\n"
+   "endmodule");
+}
+
 TEST_F(FormatTestVerilog, Hierarchy) {
   verifyFormat("module x;\n"
"endmodule");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2590,8 +2590,21 @@
 FormatToken *Start = Current;
 FormatToken *LatestOperator = nullptr;
 unsigned OperatorIndex = 0;
+// The first name of the current type in a port list.
+FormatToken *VerilogFirstOfType = nullptr;
 
 while (Current) {
+  // In Verilog ports in a module header that don't have a type take the
+  // type of the previous one.  For example,
+  //   module a(output b,
+  //   c,
+  //output d);
+  // In this case there need to be fake parentheses around b and c.
+  if (Style.is

[PATCH] D143831: [clang-format] Don't rewrite the input file if already formatted

2023-02-11 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, rymiel.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If `IntegerLiteralSeparator` is set but the integer literals are already 
formatted, don't rewrite the input file.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143831

Files:
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp


Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -132,8 +132,11 @@
   continue;
 if (Start > 0)
   Location = Location.getLocWithOffset(Start);
-cantFail(Result.add(tooling::Replacement(SourceMgr, Location, Length,
- format(Text, DigitsPerGroup;
+if (const auto &Formatted = format(Text, DigitsPerGroup);
+Formatted != Text) {
+  cantFail(Result.add(
+  tooling::Replacement(SourceMgr, Location, Length, Formatted)));
+}
   }
 
   return {Result, 0};


Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -132,8 +132,11 @@
   continue;
 if (Start > 0)
   Location = Location.getLocWithOffset(Start);
-cantFail(Result.add(tooling::Replacement(SourceMgr, Location, Length,
- format(Text, DigitsPerGroup;
+if (const auto &Formatted = format(Text, DigitsPerGroup);
+Formatted != Text) {
+  cantFail(Result.add(
+  tooling::Replacement(SourceMgr, Location, Length, Formatted)));
+}
   }
 
   return {Result, 0};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143301: Emit warning for unsupported gfortran flags

2023-02-11 Thread Ethan Luis McDonough via Phabricator via cfe-commits
elmcdonough updated this revision to Diff 496730.
elmcdonough retitled this revision from "Emit warning for `-Wextra` instead of 
error" to "Emit warning for unsupported gfortran flags".
elmcdonough added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This update adds other unsupported gfortran options to Options.td.


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,18 @@
   // 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 wArgs =
+args.getAllArgValues(clang::driver::options::OPT_W_Joined);
+for (const auto &wArg : wArgs) {
+  if (wArg == "error") {
+res.setWarnAsErr(true);
+  } else {
+const unsigned diagID =
+diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only `-Werror` is supported currently.");
+diags.Report(diagID);
+break;
+  }
 }
   }
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4988,6 +4988,8 @@
 defm aggressive_function_elimination : BooleanFFlag<"aggressive-function-elimination">, Group;
 defm align_commons : BooleanFFlag<"align-commons">, Group;
 defm all_intrinsics : BooleanFFlag<"all-intrinsics">, Group;
+defm allow_argument_mismatch : BooleanFFlag<"allow-argument-mismatch">, Group;
+defm allow_invalid_boz : BooleanFFlag<"allow-invalid-boz">, Group;
 def fautomatic : Flag<["-"], "fautomatic">; // -fno-automatic is significant
 defm backtrace : BooleanFFlag<"backtrace">, Group;
 defm bounds_check : BooleanFFlag<"bounds-check">, Group;
@@ -4995,6 +4997,17 @@
 defm cray_pointer : BooleanFFlag<"cray-pointer">, Group;
 defm d_lines_as_code : BooleanFFlag<"d-lines-as-code">, Group;
 defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, Group;
+defm dec : BooleanFFlag<"dec">, Group;
+defm dec_char_conversions : BooleanFFlag<"dec-char-conversions">, Group;
+defm dec_structure : BooleanFFlag<"dec-structure">, Group;
+defm dec_intrinsic_ints : BooleanFFlag<"dec-intrinsic-ints">, Group;
+defm dec_static : BooleanFFlag<"dec-static">, Group;
+defm dec_math : BooleanFFlag<"dec-math">, Group;
+defm dec_include : BooleanFFlag<"dec-include">, Group;
+defm dec_format_defaults : BooleanFFlag<"dec-format-defaults">, Group;
+defm dec_blank_format_item : BooleanFFlag<"dec-blank-format-item">, Group;
+defm default_real_10 : BooleanFFlag<"default-real-10">, Group;
+defm default_real_16 : BooleanFFlag<"default-real-16">, Group;
 defm dollar_ok : BooleanFFlag<"dollar-ok">, Group;
 defm dump_fortran_optimized : BooleanFFlag<"dump-fortran-optimized">, Group;
 defm dump_fortran_original : BooleanFFlag<"dump-for

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

2023-02-11 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Note that D138546  is removing the call to 
`inferTargetAndDriverMode()` from `GlobalCompilationDatabase.cpp`. It adds 
equivalent logic too `CommandMangler` which is used for CDBs pushed from LSP as 
well, so it accomplishes objective of this patch with respect to 
`inferTargetAndDriverMode` (but not `inferMissingCompileCommands`).


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


[clang] 6a75aec - [Clang][perf-training] Remove trailing whitespace in perf-helper

2023-02-11 Thread Amir Ayupov via cfe-commits

Author: Amir Ayupov
Date: 2023-02-11T21:10:27-08:00
New Revision: 6a75aec090986d3c897af7cfed8836ff36b38181

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

LOG: [Clang][perf-training] Remove trailing whitespace in perf-helper

Added: 


Modified: 
clang/utils/perf-training/perf-helper.py

Removed: 




diff  --git a/clang/utils/perf-training/perf-helper.py 
b/clang/utils/perf-training/perf-helper.py
index abbdc77b23724..f28eb0b731dd3 100644
--- a/clang/utils/perf-training/perf-helper.py
+++ b/clang/utils/perf-training/perf-helper.py
@@ -21,7 +21,7 @@
 
 def findFilesWithExtension(path, extension):
   filenames = []
-  for root, dirs, files in os.walk(path): 
+  for root, dirs, files in os.walk(path):
 for filename in files:
   if filename.endswith(f".{extension}"):
 filenames.append(os.path.join(root, filename))
@@ -102,7 +102,7 @@ def dtrace(args):
   dtrace_args.extend((
   'dtrace', '-xevaltime=exec',
   '-xbufsize=%dm' % (opts.buffer_size),
-  '-q', '-n', dtrace_script, 
+  '-q', '-n', dtrace_script,
   '-c', ' '.join(cmd)))
 
   if sys.platform == "darwin":
@@ -244,7 +244,7 @@ def get_symbols_with_prefix(symbol):
 # If we found too many possible symbols, ignore this as a prefix.
 if len(possible_symbols) > 100:
   print( "warning: ignoring symbol %r " % symbol +
-"(no match and too many possible suffixes)", file=sys.stderr) 
+"(no match and too many possible suffixes)", file=sys.stderr)
   continue
 
 # Report that we resolved a missing symbol.
@@ -284,7 +284,7 @@ def form_by_call_order_fair(symbol_lists):
   succs[a] = items = succs.get(a, [])
   if b not in items:
 items.append(b)
-  
+
   # Emit all the symbols, but make sure to always emit all successors from any
   # call list whenever we see a symbol.
   #
@@ -295,11 +295,11 @@ def form_by_call_order_fair(symbol_lists):
 for symbols in symbol_lists
 for node in symbols
 for s in ([node] + succs.get(node,[])))
- 
+
 def form_by_frequency(symbol_lists):
   # Form the order file by just putting the most commonly occurring symbols
   # first. This assumes the data files didn't use the oneshot dtrace method.
- 
+
   counts = {}
   for symbols in symbol_lists:
 for a in symbols:
@@ -308,14 +308,14 @@ def form_by_frequency(symbol_lists):
   by_count = list(counts.items())
   by_count.sort(key = lambda __n: -__n[1])
   return [s for s,n in by_count]
- 
+
 def form_by_random(symbol_lists):
   # Randomize the symbols.
   merged_symbols = uniq(s for symbols in symbol_lists
   for s in symbols)
   random.shuffle(merged_symbols)
   return merged_symbols
- 
+
 def form_by_alphabetical(symbol_lists):
   # Alphabetize the symbols.
   merged_symbols = list(set(s for symbols in symbol_lists for s in symbols))



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


[PATCH] D143840: [clang] Add the check of membership for the issue #58674 and improve the lookup process

2023-02-11 Thread Liming Liu via Phabricator via cfe-commits
lime created this revision.
lime added reviewers: aaron.ballman, erichkeane, cor3ntin, clang-language-wg.
Herald added a subscriber: yaxunl.
Herald added a project: All.
lime requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch includes the commit 01adf96ebc86 
 and a fix 
that makes the commit
crash due to unhandled declaration references.

When looking up base classes, Clang first checks whether a base class is a
template and takes the specialized template base on it. However, the base class
might be instantiated, and the above behavior can lose information.

This patch fixes the problem by first checking whether a base class is a record
declarations, so the instantiated one will be taken.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143840

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/lib/AST/CXXInheritance.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenCXX/decl-ref-inheritance.cpp
  clang/test/SemaCXX/decltype.cpp

Index: clang/test/SemaCXX/decltype.cpp
===
--- clang/test/SemaCXX/decltype.cpp
+++ clang/test/SemaCXX/decltype.cpp
@@ -101,6 +101,44 @@
   template void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
 }
 
+namespace GH58674 {
+  struct Foo {
+float value_;
+struct nested {
+  float value_;
+};
+  };
+
+  template 
+  struct TemplateFoo {
+float value_;
+  };
+
+  float bar;
+
+  template 
+  struct Animal{};
+
+  template 
+  class Cat : Animal {
+using okay = decltype(Foo::value_);
+using also_okay = decltype(bar);
+using okay2 = decltype(Foo::nested::value_);
+using okay3 = decltype(TemplateFoo::value_);
+  public:
+void meow() {
+  using okay = decltype(Foo::value_);
+  using also_okay = decltype(bar);
+  using okay2 = decltype(Foo::nested::value_);
+  using okay3 = decltype(TemplateFoo::value_);
+}
+  };
+
+  void baz() {
+  Cat{}.meow();
+  }
+}
+
 template
 class conditional {
 };
Index: clang/test/CodeGenCXX/decl-ref-inheritance.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/decl-ref-inheritance.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: [[FOO:%.+]] = type { i32 }
+struct foo {
+  int val;
+};
+
+template  struct bar : T {
+};
+
+struct baz : bar {
+  // CHECK-LABEL: define{{.*}} i32 @_ZN3baz3getEv
+  // CHECK: {{%.+}} = getelementptr inbounds [[FOO]], ptr {{%.+}}, i32 0, i32 0
+  int get() {
+return val;
+  }
+};
+
+int qux() {
+  auto f = baz{};
+  return f.get();
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -2693,20 +2693,36 @@
   // to get this right here so that we don't end up making a
   // spuriously dependent expression if we're inside a dependent
   // instance method.
+  //
+  // We also don't need to do this if R resolved to a member in another
+  // class, which can happen in an unevaluated operand:
+  //
+  // C++ [expr.prim.id]p3.3:
+  //   If that id-expression denotes a non-static data member and it
+  //   appears in an unevaluated operand.
   if (!R.empty() && (*R.begin())->isCXXClassMember()) {
-bool MightBeImplicitMember;
-if (!IsAddressOfOperand)
-  MightBeImplicitMember = true;
-else if (!SS.isEmpty())
-  MightBeImplicitMember = false;
-else if (R.isOverloadedResult())
-  MightBeImplicitMember = false;
-else if (R.isUnresolvableResult())
-  MightBeImplicitMember = true;
-else
-  MightBeImplicitMember = isa(R.getFoundDecl()) ||
-  isa(R.getFoundDecl()) ||
-  isa(R.getFoundDecl());
+bool MightBeImplicitMember = true, CheckField = true;
+if (IsAddressOfOperand) {
+  MightBeImplicitMember = SS.isEmpty() && !R.isOverloadedResult();
+  CheckField = !R.isUnresolvableResult();
+}
+if (MightBeImplicitMember && CheckField) {
+  if (R.isSingleResult() &&
+  isa(R.getFoundDecl())) {
+auto Class = cast((*R.begin())->getDeclContext());
+for (auto Curr = S->getLookupEntity(); Curr && !Curr->isFileContext();
+ Curr = Curr->getParent()) {
+  if (auto ThisClass = dyn_cast_if_present(Curr)) {
+if ((MightBeImplicitMember =
+ ThisClass->Equals(Class) ||
+ ThisClass->isDerivedFrom(Class,
+  /*LookupIndependent=*/true)))
+  break;
+  }
+}
+  } else if (IsAddressOfOperand)
+MightBeImplicitMember = false;
+}
 
 if (MightBeImplicitMember)
   return BuildPossibleImplicitMemberExpr(S

[PATCH] D143840: [clang] Add the check of membership for the issue #58674 and improve the lookup process

2023-02-11 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 496742.

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

https://reviews.llvm.org/D143840

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/lib/AST/CXXInheritance.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenCXX/decl-ref-inheritance.cpp
  clang/test/SemaCXX/decltype.cpp

Index: clang/test/SemaCXX/decltype.cpp
===
--- clang/test/SemaCXX/decltype.cpp
+++ clang/test/SemaCXX/decltype.cpp
@@ -101,6 +101,44 @@
   template void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
 }
 
+namespace GH58674 {
+  struct Foo {
+float value_;
+struct nested {
+  float value_;
+};
+  };
+
+  template 
+  struct TemplateFoo {
+float value_;
+  };
+
+  float bar;
+
+  template 
+  struct Animal{};
+
+  template 
+  class Cat : Animal {
+using okay = decltype(Foo::value_);
+using also_okay = decltype(bar);
+using okay2 = decltype(Foo::nested::value_);
+using okay3 = decltype(TemplateFoo::value_);
+  public:
+void meow() {
+  using okay = decltype(Foo::value_);
+  using also_okay = decltype(bar);
+  using okay2 = decltype(Foo::nested::value_);
+  using okay3 = decltype(TemplateFoo::value_);
+}
+  };
+
+  void baz() {
+  Cat{}.meow();
+  }
+}
+
 template
 class conditional {
 };
Index: clang/test/CodeGenCXX/decl-ref-inheritance.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/decl-ref-inheritance.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: [[FOO:%.+]] = type { i32 }
+struct foo {
+  int val;
+};
+
+template  struct bar : T {
+};
+
+struct baz : bar {
+  // CHECK-LABEL: define{{.*}} i32 @_ZN3baz3getEv
+  // CHECK: {{%.+}} = getelementptr inbounds [[FOO]], ptr {{%.+}}, i32 0, i32 0
+  int get() {
+return val;
+  }
+};
+
+int qux() {
+  auto f = baz{};
+  return f.get();
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -2693,20 +2693,36 @@
   // to get this right here so that we don't end up making a
   // spuriously dependent expression if we're inside a dependent
   // instance method.
+  //
+  // We also don't need to do this if R resolved to a member in another
+  // class, which can happen in an unevaluated operand:
+  //
+  // C++ [expr.prim.id]p3.3:
+  //   If that id-expression denotes a non-static data member and it
+  //   appears in an unevaluated operand.
   if (!R.empty() && (*R.begin())->isCXXClassMember()) {
-bool MightBeImplicitMember;
-if (!IsAddressOfOperand)
-  MightBeImplicitMember = true;
-else if (!SS.isEmpty())
-  MightBeImplicitMember = false;
-else if (R.isOverloadedResult())
-  MightBeImplicitMember = false;
-else if (R.isUnresolvableResult())
-  MightBeImplicitMember = true;
-else
-  MightBeImplicitMember = isa(R.getFoundDecl()) ||
-  isa(R.getFoundDecl()) ||
-  isa(R.getFoundDecl());
+bool MightBeImplicitMember = true, CheckField = true;
+if (IsAddressOfOperand) {
+  MightBeImplicitMember = SS.isEmpty() && !R.isOverloadedResult();
+  CheckField = !R.isUnresolvableResult();
+}
+if (MightBeImplicitMember && CheckField) {
+  if (R.isSingleResult() &&
+  isa(R.getFoundDecl())) {
+auto Class = cast((*R.begin())->getDeclContext());
+for (auto Curr = S->getLookupEntity(); Curr && !Curr->isFileContext();
+ Curr = Curr->getParent()) {
+  if (auto ThisClass = dyn_cast_if_present(Curr)) {
+if ((MightBeImplicitMember =
+ ThisClass->Equals(Class) ||
+ ThisClass->isDerivedFrom(Class,
+  /*LookupIndependent=*/true)))
+  break;
+  }
+}
+  } else if (IsAddressOfOperand)
+MightBeImplicitMember = false;
+}
 
 if (MightBeImplicitMember)
   return BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc,
Index: clang/lib/AST/CXXInheritance.cpp
===
--- clang/lib/AST/CXXInheritance.cpp
+++ clang/lib/AST/CXXInheritance.cpp
@@ -63,15 +63,16 @@
   std::swap(DetectVirtual, Other.DetectVirtual);
   std::swap(DetectedVirtual, Other.DetectedVirtual);
 }
-
-bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base) const {
+bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base,
+  bool LookupIndependent) const {
   CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/false,
  /*DetectVirtual=*/false);
-  return isDerivedFrom(Base, Paths);
+  return isDerivedFrom(Base, Paths, LookupIndependent);
 }
 
 bool CXXRecordDe

[PATCH] D143840: [clang] Add the check of membership for the issue #58674 and improve the lookup process

2023-02-11 Thread Liming Liu via Phabricator via cfe-commits
lime added inline comments.



Comment at: clang/lib/AST/CXXInheritance.cpp:84
   [BaseDecl](const CXXBaseSpecifier *Specifier, CXXBasePath &Path) {
 return Specifier->getType()->getAsRecordDecl() &&
FindBaseClass(Specifier, Path, BaseDecl);

BTW, I forgot to revert this condition last time.


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

https://reviews.llvm.org/D143840

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