[clang] 97afce0 - [clang] Don't use Optional::hasValue (NFC)

2022-06-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-06-25T22:26:24-07:00
New Revision: 97afce08cbbb1390cf8ddab8bf398f3ff5b39676

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

LOG: [clang] Don't use Optional::hasValue (NFC)

This patch replaces Optional::hasValue with the implicit cast to bool
in conditionals only.

Added: 


Modified: 
clang/include/clang/Analysis/PathDiagnostic.h
clang/include/clang/Sema/Sema.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
clang/lib/AST/AttrImpl.cpp
clang/lib/ASTMatchers/Dynamic/Parser.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/lib/Analysis/BodyFarm.cpp
clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/lib/Analysis/PathDiagnostic.cpp
clang/lib/Analysis/UninitializedValues.cpp
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/ToolChains/AVR.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Edit/RewriteObjCFoundationAPI.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/lib/Lex/MacroInfo.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Lex/PreprocessingRecord.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
clang/lib/Support/RISCVVIntrinsicUtils.cpp
clang/lib/Tooling/Core/Replacement.cpp
clang/tools/driver/driver.cpp
clang/tools/libclang/CIndex.cpp
clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
clang/unittests/Tooling/RefactoringTest.cpp
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/PathDiagnostic.h 
b/clang/include/clang/Analysis/PathDiagnostic.h
index 47cb549c8e669..9877f1e3d01fd 100644
--- a/clang/include/clang/Analysis/PathDiagnostic.h
+++ b/clang/include/clang/Analysis/PathDiagnostic.h
@@ -544,8 +544,8 @@ class PathDiagnosticEventPiece : public 
PathDiagnosticSpotPiece {
   /// flag may have been previously set, at which point it will not
   /// be reset unless one specifies to do so.
   void setPrunable(bool isPrunable, bool override = false) {
-if (IsPrunable.hasValue() && !override)
- return;
+if (IsPrunable && !override)
+  return;
 IsPrunable = isPrunable;
   }
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ba4d0bb8f4354..8b8b1b2e2e864 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1766,9 +1766,9 @@ class Sema final {
 template 
 friend const SemaDiagnosticBuilder &
 operator<<(const SemaDiagnosticBuilder , const T ) {
-  if (Diag.ImmediateDiag.hasValue())
+  if (Diag.ImmediateDiag)
 *Diag.ImmediateDiag << Value;
-  else if (Diag.PartialDiagId.hasValue())
+  else if (Diag.PartialDiagId)
 Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second
 << Value;
   return Diag;
@@ -1780,26 +1780,26 @@ class Sema final {
 template ::value>::type>
 const SemaDiagnosticBuilder <<(T &) const {
-  if (ImmediateDiag.hasValue())
+  if (ImmediateDiag)
 *ImmediateDiag << std::move(V);
-  else if (PartialDiagId.hasValue())
+  else if (PartialDiagId)
 S.DeviceDeferredDiags[Fn][*PartialDiagId].second << std::move(V);
   return *this;
 }
 
 friend const SemaDiagnosticBuilder &
 operator<<(const SemaDiagnosticBuilder , const PartialDiagnostic ) 
{
-  if (Diag.ImmediateDiag.hasValue())
+  if (Diag.ImmediateDiag)
 PD.Emit(*Diag.ImmediateDiag);
-  else if (Diag.PartialDiagId.hasValue())
+  else if (Diag.PartialDiagId)
 Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD;
   return Diag;
 }
 
 void AddFixItHint(const FixItHint ) const {
-  if (ImmediateDiag.hasValue())
+  if (ImmediateDiag)
 ImmediateDiag->AddFixItHint(Hint);
-  else if (PartialDiagId.hasValue())
+  else if (PartialDiagId)
 S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint);
 }
 

diff  --git 

[PATCH] D126682: [Interpreter][ClangRepl] Implement undo command

2022-06-25 Thread Jun Zhang via Phabricator via cfe-commits
junaire marked 3 inline comments as done.
junaire added inline comments.



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:281
 
+void IncrementalParser::Restore(PartialTranslationUnit ) {
+  TranslationUnitDecl *MostRecentTU = PTU.TUPart;

v.g.vassilev wrote:
> I think we can merge this function with `Undo` where we can conditionally 
> check if we have a llvm::Module to recover.
I'm not sure I understand you correctly, do you mean to merge 
`Interpreter::Restore` with `Interpreter::Undo`? I think 
`IncrementalParser::Restore` is used above?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

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


[PATCH] D126682: [Interpreter][ClangRepl] Implement undo command

2022-06-25 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 440027.
junaire added a comment.

Address @v.g.vassilev 's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/code-undo.cpp
  clang/test/Interpreter/execute.cpp
  clang/test/Interpreter/plugins.cpp
  clang/test/Interpreter/sanity.c
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -128,6 +128,50 @@
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 }
 
+TEST(InterpreterTest, UndoCommand) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  // Fail to undo.
+  auto Err1 = Interp->Undo();
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err1)));
+  auto Err2 = Interp->Parse("int foo = 42;");
+  EXPECT_TRUE(!!Err2);
+  auto Err3 = Interp->Undo(2);
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err3)));
+
+  // Succeed to undo.
+  auto Err4 = Interp->Parse("int x = 42;");
+  EXPECT_TRUE(!!Err4);
+  auto Err5 = Interp->Undo();
+  EXPECT_FALSE(!!Err5);
+  auto Err6 = Interp->Parse("int x = 24;");
+  EXPECT_TRUE(!!Err6);
+  auto Err7 = Interp->Parse("#define X 42");
+  EXPECT_TRUE(!!Err7);
+  auto Err8 = Interp->Undo();
+  EXPECT_FALSE(!!Err8);
+  auto Err9 = Interp->Parse("#define X 24");
+  EXPECT_TRUE(!!Err9);
+
+  // Undo input contains errors.
+  auto Err10 = Interp->Parse("int y = ;");
+  EXPECT_FALSE(!!Err10);
+  auto Err11 = Interp->Parse("int y = 42;");
+  EXPECT_TRUE(!!Err11);
+  auto Err12 = Interp->Undo();
+  EXPECT_FALSE(!!Err12);
+}
+
 static std::string MangleName(NamedDecl *ND) {
   ASTContext  = ND->getASTContext();
   std::unique_ptr MangleC(C.createMangleContext());
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -92,8 +92,14 @@
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
-  if (*Line == "quit")
+  if (*Line == R"(%quit)")
 break;
+  if (*Line == R"(%undo)") {
+if (auto Err = Interp->Undo())
+  llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+continue;
+  }
+
   if (auto Err = Interp->ParseAndExecute(*Line))
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
 }
Index: clang/test/Interpreter/sanity.c
===
--- clang/test/Interpreter/sanity.c
+++ clang/test/Interpreter/sanity.c
@@ -15,4 +15,4 @@
 // CHECK-NEXT: UnaryOperator{{.*}} 'int' lvalue prefix '++'
 // CHECK-NEXT:   DeclRefExpr{{.*}} 'int' lvalue Var [[var_ptr]] 'TestVar' 'int'
 
-quit
+%quit
Index: clang/test/Interpreter/plugins.cpp
===
--- clang/test/Interpreter/plugins.cpp
+++ clang/test/Interpreter/plugins.cpp
@@ -6,8 +6,7 @@
 int i = 10;
 extern "C" int printf(const char*,...);
 auto r1 = printf("i = %d\n", i);
-quit
-
+%quit
 
 // CHECK: top-level-decl: "i"
 // CHECK-NEXT: top-level-decl: "r1"
Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -18,4 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-quit
+%quit
Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -1,4 +1,3 @@
-// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
@@ -6,16 +5,19 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const 

[PATCH] D128133: [Driver] Support linking to compiler-rt for target AVR

2022-06-25 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

A gentle ping ...


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

https://reviews.llvm.org/D128133

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


[PATCH] D103313: [RISCV][Clang] Add support for Zmmul extension

2022-06-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCV.td:25
+   "'M' (Integer Multiplication and Division)",
+   [FeatureStdExtZmmul]>;
 def HasStdExtM : Predicate<"Subtarget->hasStdExtM()">,

This will cause Zmmul to appear in the ELF attributes any time is M is enabled. 
Is that what we want?



Comment at: llvm/test/CodeGen/RISCV/attributes.ll:76
 
-; RV32M: .attribute 5, "rv32i2p0_m2p0"
+; RV32M: .attribute 5, "rv32i2p0_m2p0_zmmul0p1"
 ; RV32A: .attribute 5, "rv32i2p0_a2p0"

Is this a backwards compatibility issue?


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

https://reviews.llvm.org/D103313

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


[PATCH] D124749: [clang-format] Handle Verilog preprocessor directives

2022-06-25 Thread sstwcw via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e32ff106e74: [clang-format] Handle Verilog preprocessor 
directives (authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124749

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

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -30,7 +30,9 @@
 return *Result;
   }
 
-  static std::string format(llvm::StringRef Code, const FormatStyle ) {
+  static std::string
+  format(llvm::StringRef Code,
+ const FormatStyle  = getLLVMStyle(FormatStyle::LK_Verilog)) {
 return format(Code, 0, Code.size(), Style);
   }
 
@@ -43,6 +45,29 @@
   }
 };
 
+TEST_F(FormatTestVerilog, Delay) {
+  // Delay by the default unit.
+  verifyFormat("#0;");
+  verifyFormat("#1;");
+  verifyFormat("#10;");
+  verifyFormat("#1.5;");
+  // Explicit unit.
+  verifyFormat("#1fs;");
+  verifyFormat("#1.5fs;");
+  verifyFormat("#1ns;");
+  verifyFormat("#1.5ns;");
+  verifyFormat("#1us;");
+  verifyFormat("#1.5us;");
+  verifyFormat("#1ms;");
+  verifyFormat("#1.5ms;");
+  verifyFormat("#1s;");
+  verifyFormat("#1.5s;");
+  // The following expression should be on the same line.
+  verifyFormat("#1 x = x;");
+  EXPECT_EQ("#1 x = x;", format("#1\n"
+"x = x;"));
+}
+
 TEST_F(FormatTestVerilog, If) {
   verifyFormat("if (x)\n"
"  x = x;");
@@ -114,5 +139,113 @@
"  {x} = {x};");
 }
 
+TEST_F(FormatTestVerilog, Preprocessor) {
+  auto Style = getLLVMStyle(FormatStyle::LK_Verilog);
+  Style.ColumnLimit = 20;
+
+  // Macro definitions.
+  EXPECT_EQ("`define X  \\\n"
+"  if (x)   \\\n"
+"x = x;",
+format("`define X if(x)x=x;", Style));
+  EXPECT_EQ("`define X(x)   \\\n"
+"  if (x)   \\\n"
+"x = x;",
+format("`define X(x) if(x)x=x;", Style));
+  EXPECT_EQ("`define X  \\\n"
+"  x = x;   \\\n"
+"  x = x;",
+format("`define X x=x;x=x;", Style));
+  // Macro definitions with invocations inside.
+  EXPECT_EQ("`define LIST   \\\n"
+"  `ENTRY   \\\n"
+"  `ENTRY",
+format("`define LIST \\\n"
+   "`ENTRY \\\n"
+   "`ENTRY",
+   Style));
+  EXPECT_EQ("`define LIST   \\\n"
+"  `x = `x; \\\n"
+"  `x = `x;",
+format("`define LIST \\\n"
+   "`x = `x; \\\n"
+   "`x = `x;",
+   Style));
+  EXPECT_EQ("`define LIST   \\\n"
+"  `x = `x; \\\n"
+"  `x = `x;",
+format("`define LIST `x=`x;`x=`x;", Style));
+  // Macro invocations.
+  verifyFormat("`x = (`x1 + `x2 + x);");
+  // Lines starting with a preprocessor directive should not be indented.
+  std::string Directives[] = {
+  "begin_keywords",
+  "celldefine",
+  "default_nettype",
+  "define",
+  "else",
+  "elsif",
+  "end_keywords",
+  "endcelldefine",
+  "endif",
+  "ifdef",
+  "ifndef",
+  "include",
+  "line",
+  "nounconnected_drive",
+  "pragma",
+  "resetall",
+  "timescale",
+  "unconnected_drive",
+  "undef",
+  "undefineall",
+  };
+  for (auto  : Directives) {
+EXPECT_EQ("if (x)\n"
+  "`" +
+  Name +
+  "\n"
+  "  ;",
+  format("if (x)\n"
+ "`" +
+ Name +
+ "\n"
+ ";",
+ Style));
+  }
+  // Lines starting with a regular macro invocation should be indented as a
+  // normal line.
+  EXPECT_EQ("if (x)\n"
+"  `x = `x;\n"
+"`timescale 1ns / 1ps",
+format("if (x)\n"
+   "`x = `x;\n"
+   "`timescale 1ns / 1ps",
+   Style));
+  EXPECT_EQ("if (x)\n"
+"`timescale 1ns / 1ps\n"
+"  `x = `x;",
+format("if (x)\n"
+   "`timescale 1ns / 1ps\n"
+   "`x = `x;",
+   Style));
+  std::string NonDirectives[] = {
+  // For `__FILE__` and `__LINE__`, although the standard classifies them as
+  // preprocessor directives, they are used like regular macros.
+  "__FILE__", "__LINE__", "elif", "foo", "x",
+  };
+  for (auto  : NonDirectives) {
+EXPECT_EQ("if (x)\n"
+  

[clang] 2e32ff1 - [clang-format] Handle Verilog preprocessor directives

2022-06-25 Thread via cfe-commits

Author: sstwcw
Date: 2022-06-26T02:02:29Z
New Revision: 2e32ff106e740c76601004493816d0ed7c483056

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

LOG: [clang-format] Handle Verilog preprocessor directives

Verilog uses the backtick instead of the hash.  In this revision
backticks are lexed manually and then get labeled as hashes so the logic
for handling C preprocessor stuff don't have to change.  Hashes get
labeled as identifiers for Verilog-specific stuff like delays.

Reviewed By: HazardyKnusperkeks

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

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestVerilog.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 92fa0798f699..b6cc021affae 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -988,6 +988,7 @@ struct AdditionalKeywords {
 kw_automatic = ("automatic");
 kw_before = ("before");
 kw_begin = ("begin");
+kw_begin_keywords = ("begin_keywords");
 kw_bins = ("bins");
 kw_binsof = ("binsof");
 kw_casex = ("casex");
@@ -999,10 +1000,20 @@ struct AdditionalKeywords {
 kw_cover = ("cover");
 kw_covergroup = ("covergroup");
 kw_coverpoint = ("coverpoint");
+kw_default_decay_time = ("default_decay_time");
+kw_default_nettype = ("default_nettype");
+kw_default_trireg_strength = ("default_trireg_strength");
+kw_delay_mode_distributed = ("delay_mode_distributed");
+kw_delay_mode_path = ("delay_mode_path");
+kw_delay_mode_unit = ("delay_mode_unit");
+kw_delay_mode_zero = ("delay_mode_zero");
 kw_disable = ("disable");
 kw_dist = ("dist");
+kw_elsif = ("elsif");
 kw_end = ("end");
+kw_end_keywords = ("end_keywords");
 kw_endcase = ("endcase");
+kw_endcelldefine = ("endcelldefine");
 kw_endchecker = ("endchecker");
 kw_endclass = ("endclass");
 kw_endclocking = ("endclocking");
@@ -1043,6 +1054,7 @@ struct AdditionalKeywords {
 kw_macromodule = ("macromodule");
 kw_matches = ("matches");
 kw_medium = ("medium");
+kw_nounconnected_drive = ("nounconnected_drive");
 kw_output = ("output");
 kw_packed = ("packed");
 kw_parameter = ("parameter");
@@ -1058,6 +1070,7 @@ struct AdditionalKeywords {
 kw_randcase = ("randcase");
 kw_randsequence = ("randsequence");
 kw_repeat = ("repeat");
+kw_resetall = ("resetall");
 kw_sample = ("sample");
 kw_scalared = ("scalared");
 kw_sequence = ("sequence");
@@ -1073,12 +1086,15 @@ struct AdditionalKeywords {
 kw_table = ("table");
 kw_tagged = ("tagged");
 kw_task = ("task");
+kw_timescale = ("timescale");
 kw_tri = ("tri");
 kw_tri0 = ("tri0");
 kw_tri1 = ("tri1");
 kw_triand = ("triand");
 kw_trior = ("trior");
 kw_trireg = ("trireg");
+kw_unconnected_drive = ("unconnected_drive");
+kw_undefineall = ("undefineall");
 kw_unique = ("unique");
 kw_unique0 = ("unique0");
 kw_uwire = ("uwire");
@@ -1091,6 +1107,10 @@ struct AdditionalKeywords {
 kw_with = ("with");
 kw_wor = ("wor");
 
+// Symbols that are treated as keywords.
+kw_verilogHash = ("#");
+kw_verilogHashHash = ("##");
+
 // Keep this at the end of the constructor to make sure everything here
 // is
 // already initialized.
@@ -1118,38 +1138,132 @@ struct AdditionalKeywords {
 // Some keywords are not included here because they don't need special
 // treatment like `showcancelled` or they should be treated as identifiers
 // like `int` and `logic`.
-VerilogExtraKeywords = std::unordered_set(
-{kw_always,   kw_always_comb,  kw_always_ff,kw_always_latch,
- kw_assert,   kw_assign,   kw_assume,   kw_automatic,
- kw_before,   kw_begin,kw_bins, kw_binsof,
- kw_casex,kw_casez,kw_celldefine,   kw_checker,
- kw_clocking, kw_constraint,   kw_cover,kw_covergroup,
- kw_coverpoint,   kw_disable,  kw_dist, kw_end,
- kw_endcase,  kw_endchecker,   kw_endclass, kw_endclocking,
- kw_endfunction,  kw_endgenerate,  kw_endgroup, kw_endinterface,
- kw_endmodule,kw_endpackage,   kw_endprimitive, kw_endprogram,
- kw_endproperty,  kw_endsequence,  kw_endspecify,   kw_endtable,
- kw_endtask,  kw_extends,  kw_final,kw_foreach,
- kw_forever,  kw_fork, kw_function, kw_generate,
- 

[PATCH] D123450: [clang-format] Parse Verilog if statements

2022-06-25 Thread sstwcw 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 rG9ed2e68c9ae5: [clang-format] Parse Verilog if statements 
(authored by sstwcw).

Changed prior to commit:
  https://reviews.llvm.org/D123450?vs=435777=440021#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123450

Files:
  clang/docs/ClangFormat.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTestUtils.h
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- /dev/null
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -0,0 +1,118 @@
+//===- unittest/Format/FormatTestVerilog.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "FormatTestUtils.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "format-test"
+
+namespace clang {
+namespace format {
+
+class FormatTestVerilog : public ::testing::Test {
+protected:
+  static std::string format(llvm::StringRef Code, unsigned Offset,
+unsigned Length, const FormatStyle ) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(Offset, Length));
+tooling::Replacements Replaces = reformat(Style, Code, Ranges);
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  static std::string format(llvm::StringRef Code, const FormatStyle ) {
+return format(Code, 0, Code.size(), Style);
+  }
+
+  static void verifyFormat(
+  llvm::StringRef Code,
+  const FormatStyle  = getLLVMStyle(FormatStyle::LK_Verilog)) {
+EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
+EXPECT_EQ(Code.str(),
+  format(test::messUp(Code, /*HandleHash=*/false), Style));
+  }
+};
+
+TEST_F(FormatTestVerilog, If) {
+  verifyFormat("if (x)\n"
+   "  x = x;");
+  verifyFormat("if (x)\n"
+   "  x = x;\n"
+   "x = x;");
+
+  // Test else
+  verifyFormat("if (x)\n"
+   "  x = x;\n"
+   "else if (x)\n"
+   "  x = x;\n"
+   "else\n"
+   "  x = x;");
+  verifyFormat("if (x) begin\n"
+   "  x = x;\n"
+   "end else if (x) begin\n"
+   "  x = x;\n"
+   "end else begin\n"
+   "  x = x;\n"
+   "end");
+  verifyFormat("if (x) begin : x\n"
+   "  x = x;\n"
+   "end : x else if (x) begin : x\n"
+   "  x = x;\n"
+   "end : x else begin : x\n"
+   "  x = x;\n"
+   "end : x");
+
+  // Test block keywords.
+  verifyFormat("if (x) begin\n"
+   "  x = x;\n"
+   "end");
+  verifyFormat("if (x) begin : x\n"
+   "  x = x;\n"
+   "end : x");
+  verifyFormat("if (x) begin\n"
+   "  x = x;\n"
+   "  x = x;\n"
+   "end");
+  verifyFormat("disable fork;\n"
+   "x = x;");
+  verifyFormat("rand join x x;\n"
+   "x = x;");
+  verifyFormat("if (x) fork\n"
+   "  x = x;\n"
+   "join");
+  verifyFormat("if (x) fork\n"
+   "  x = x;\n"
+   "join_any");
+  verifyFormat("if (x) fork\n"
+   "  x = x;\n"
+   "join_none");
+  verifyFormat("if (x) generate\n"
+   "  x = x;\n"
+   "endgenerate");
+  verifyFormat("if (x) generate : x\n"
+   "  x = x;\n"
+   "endgenerate : x");
+
+  // Test that concatenation braces don't get regarded as blocks.
+  verifyFormat("if (x)\n"
+   "  {x} = x;");
+  verifyFormat("if (x)\n"
+   "  x = {x};");
+  verifyFormat("if (x)\n"
+   "  x = {x};\n"
+   "else\n"
+   "  {x} = {x};");
+}
+
+} // namespace format
+} // end namespace clang
Index: clang/unittests/Format/FormatTestUtils.h
===
--- clang/unittests/Format/FormatTestUtils.h
+++ clang/unittests/Format/FormatTestUtils.h
@@ -19,7 +19,10 @@
 namespace format {
 namespace test 

[clang] 9ed2e68 - [clang-format] Parse Verilog if statements

2022-06-25 Thread via cfe-commits

Author: sstwcw
Date: 2022-06-26T01:52:15Z
New Revision: 9ed2e68c9ae5cf346f938cc095e5448c1ff60f51

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

LOG: [clang-format] Parse Verilog if statements

This patch mainly handles treating `begin` as block openers.

While and for statements will be handled in another patch.

Reviewed By: HazardyKnusperkeks

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

Added: 
clang/unittests/Format/FormatTestVerilog.cpp

Modified: 
clang/docs/ClangFormat.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/UnwrappedLineParser.cpp
clang/tools/clang-format/ClangFormat.cpp
clang/unittests/Format/CMakeLists.txt
clang/unittests/Format/FormatTestUtils.h

Removed: 




diff  --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 745c66efa9e0e..16b316cdf0667 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -43,6 +43,17 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# 
code.
 --assume-filename= - Override filename used to determine the 
language.
  When reading from stdin, clang-format 
assumes this
  filename to determine the language.
+ Unrecognized filenames are treated as C++.
+ supported:
+   CSharp: .cs
+   Java: .java
+   JavaScript: .mjs .js .ts
+   Json: .json
+   Objective-C: .m .mm
+   Proto: .proto .protodevel
+   TableGen: .td
+   TextProto: .textpb .pb.txt .textproto 
.asciipb
+   Verilog: .sv .svh .v .vh
 --cursor=- The position of the cursor when invoking
  clang-format from an editor integration
 --dry-run  - If set, do not actually make the 
formatting changes

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 8249060dc7c04..f8a4b069b2e75 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2589,12 +2589,17 @@ struct FormatStyle {
 LK_TableGen,
 /// Should be used for Protocol Buffer messages in text format
 /// (https://developers.google.com/protocol-buffers/).
-LK_TextProto
+LK_TextProto,
+/// Should be used for Verilog and SystemVerilog.
+/// https://standards.ieee.org/ieee/1800/6700/
+/// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
+LK_Verilog
   };
   bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
   bool isCSharp() const { return Language == LK_CSharp; }
   bool isJson() const { return Language == LK_Json; }
   bool isJavaScript() const { return Language == LK_JavaScript; }
+  bool isVerilog() const { return Language == LK_Verilog; }
 
   /// Language, this format style is targeted at.
   /// \version 3.5
@@ -4285,6 +4290,8 @@ inline StringRef 
getLanguageName(FormatStyle::LanguageKind Language) {
 return "TableGen";
   case FormatStyle::LK_TextProto:
 return "TextProto";
+  case FormatStyle::LK_Verilog:
+return "Verilog";
   default:
 return "Unknown";
   }

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index df1aa9da16e39..51526dc2a6817 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3471,6 +3471,12 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
 return FormatStyle::LK_CSharp;
   if (FileName.endswith_insensitive(".json"))
 return FormatStyle::LK_Json;
+  if (FileName.endswith_insensitive(".sv") ||
+  FileName.endswith_insensitive(".svh") ||
+  FileName.endswith_insensitive(".v") ||
+  FileName.endswith_insensitive(".vh")) {
+return FormatStyle::LK_Verilog;
+  }
   return FormatStyle::LK_Cpp;
 }
 

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 145ae39ddb62c..92fa0798f699e 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -979,6 +979,118 @@ struct AdditionalKeywords {
 kw_when = ("when");
 kw_where = ("where");
 
+kw_always = ("always");
+kw_always_comb = ("always_comb");
+kw_always_ff = ("always_ff");
+kw_always_latch = ("always_latch");
+kw_assign = ("assign");
+kw_assume = ("assume");
+kw_automatic = ("automatic");
+kw_before = ("before");
+   

[clang] 370bee4 - [clang-format] Fix whitespace counting stuff

2022-06-25 Thread via cfe-commits

Author: sstwcw
Date: 2022-06-26T01:27:27Z
New Revision: 370bee480139bd37fe8c0c8c03ecd19ed9223f01

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

LOG: [clang-format] Fix whitespace counting stuff

The current way of counting whitespace would count backticks as
whitespace.  For Verilog stuff we need backticks to be handled
correctly.  For JavaScript the current way is to compare the entire
token text to see if it's a backtick.  However, when the backtick is the
first token following an escaped newline, the escaped newline will be
part of the tok::unknown token.  Verilog has macros and escaped newlines
unlike JavaScript.  So we can't regard an entire tok::unknown token as
whitespace.  Previously, the start of every token would be matched for
newlines.  Now, it is all whitespace instead of just newlines.

The column counting problem has already been fixed for JavaScript in
e71b4cbdd140f059667f84464bd0ac0ebc348387 by counting columns elsewhere.

Reviewed By: HazardyKnusperkeks

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

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 214a52780888b..8aee794b3f4f7 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -840,6 +840,56 @@ FormatToken *FormatTokenLexer::getStashedToken() {
   return FormatTok;
 }
 
+/// Truncate the current token to the new length and make the lexer continue
+/// from the end of the truncated token. Used for other languages that have
+/// 
diff erent token boundaries, like JavaScript in which a comment ends at a
+/// line break regardless of whether the line break follows a backslash. Also
+/// used to set the lexer to the end of whitespace if the lexer regards
+/// whitespace and an unrecognized symbol as one token.
+void FormatTokenLexer::truncateToken(size_t NewLen) {
+  assert(NewLen <= FormatTok->TokenText.size());
+  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(
+  Lex->getBufferLocation() - FormatTok->TokenText.size() + NewLen)));
+  FormatTok->TokenText = FormatTok->TokenText.substr(0, NewLen);
+  FormatTok->ColumnWidth = encoding::columnWidthWithTabs(
+  FormatTok->TokenText, FormatTok->OriginalColumn, Style.TabWidth,
+  Encoding);
+  FormatTok->Tok.setLength(NewLen);
+}
+
+/// Count the length of leading whitespace in a token.
+static size_t countLeadingWhitespace(StringRef Text) {
+  // Basically counting the length matched by this regex.
+  // "^([\n\r\f\v \t]|(|\\?\\?/)[\n\r])+"
+  // Directly using the regex turned out to be slow. With the regex
+  // version formatting all files in this directory took about 1.25
+  // seconds. This version took about 0.5 seconds.
+  const char *Cur = Text.begin();
+  while (Cur < Text.end()) {
+if (isspace(Cur[0])) {
+  ++Cur;
+} else if (Cur[0] == '\\' && (Cur[1] == '\n' || Cur[1] == '\r')) {
+  // A '\' followed by a newline always escapes the newline, regardless
+  // of whether there is another '\' before it.
+  // The source has a null byte at the end. So the end of the entire input
+  // isn't reached yet. Also the lexer doesn't break apart an escaped
+  // newline.
+  assert(Text.end() - Cur >= 2);
+  Cur += 2;
+} else if (Cur[0] == '?' && Cur[1] == '?' && Cur[2] == '/' &&
+   (Cur[3] == '\n' || Cur[3] == '\r')) {
+  // Newlines can also be escaped by a '?' '?' '/' trigraph. By the way, 
the
+  // characters are quoted individually in this comment because if we write
+  // them together some compilers warn that we have a trigraph in the code.
+  assert(Text.end() - Cur >= 4);
+  Cur += 4;
+} else {
+  break;
+}
+  }
+  return Cur - Text.begin();
+}
+
 FormatToken *FormatTokenLexer::getNextToken() {
   if (StateStack.top() == LexerState::TOKEN_STASHED) {
 StateStack.pop();
@@ -854,34 +904,33 @@ FormatToken *FormatTokenLexer::getNextToken() {
   IsFirstToken = false;
 
   // Consume and record whitespace until we find a significant token.
+  // Some tok::unknown tokens are not just whitespace, e.g. whitespace
+  // followed by a symbol such as backtick. Those symbols may be
+  // significant in other languages.
   unsigned WhitespaceLength = TrailingWhitespace;
-  while (FormatTok->is(tok::unknown)) {
+  while (FormatTok->isNot(tok::eof)) {
+auto LeadingWhitespace = countLeadingWhitespace(FormatTok->TokenText);
+if (LeadingWhitespace == 0)
+  break;
+if (LeadingWhitespace < FormatTok->TokenText.size())
+  truncateToken(LeadingWhitespace);
 StringRef Text = FormatTok->TokenText;
-auto EscapesNewline = 

[PATCH] D124748: [clang-format] Fix whitespace counting stuff

2022-06-25 Thread sstwcw via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG370bee480139: [clang-format] Fix whitespace counting stuff 
(authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124748

Files:
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h

Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -92,6 +92,8 @@
 
   bool tryMergeConflictMarkers();
 
+  void truncateToken(size_t NewLen);
+
   FormatToken *getStashedToken();
 
   FormatToken *getNextToken();
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -840,6 +840,56 @@
   return FormatTok;
 }
 
+/// Truncate the current token to the new length and make the lexer continue
+/// from the end of the truncated token. Used for other languages that have
+/// different token boundaries, like JavaScript in which a comment ends at a
+/// line break regardless of whether the line break follows a backslash. Also
+/// used to set the lexer to the end of whitespace if the lexer regards
+/// whitespace and an unrecognized symbol as one token.
+void FormatTokenLexer::truncateToken(size_t NewLen) {
+  assert(NewLen <= FormatTok->TokenText.size());
+  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(
+  Lex->getBufferLocation() - FormatTok->TokenText.size() + NewLen)));
+  FormatTok->TokenText = FormatTok->TokenText.substr(0, NewLen);
+  FormatTok->ColumnWidth = encoding::columnWidthWithTabs(
+  FormatTok->TokenText, FormatTok->OriginalColumn, Style.TabWidth,
+  Encoding);
+  FormatTok->Tok.setLength(NewLen);
+}
+
+/// Count the length of leading whitespace in a token.
+static size_t countLeadingWhitespace(StringRef Text) {
+  // Basically counting the length matched by this regex.
+  // "^([\n\r\f\v \t]|(|\\?\\?/)[\n\r])+"
+  // Directly using the regex turned out to be slow. With the regex
+  // version formatting all files in this directory took about 1.25
+  // seconds. This version took about 0.5 seconds.
+  const char *Cur = Text.begin();
+  while (Cur < Text.end()) {
+if (isspace(Cur[0])) {
+  ++Cur;
+} else if (Cur[0] == '\\' && (Cur[1] == '\n' || Cur[1] == '\r')) {
+  // A '\' followed by a newline always escapes the newline, regardless
+  // of whether there is another '\' before it.
+  // The source has a null byte at the end. So the end of the entire input
+  // isn't reached yet. Also the lexer doesn't break apart an escaped
+  // newline.
+  assert(Text.end() - Cur >= 2);
+  Cur += 2;
+} else if (Cur[0] == '?' && Cur[1] == '?' && Cur[2] == '/' &&
+   (Cur[3] == '\n' || Cur[3] == '\r')) {
+  // Newlines can also be escaped by a '?' '?' '/' trigraph. By the way, the
+  // characters are quoted individually in this comment because if we write
+  // them together some compilers warn that we have a trigraph in the code.
+  assert(Text.end() - Cur >= 4);
+  Cur += 4;
+} else {
+  break;
+}
+  }
+  return Cur - Text.begin();
+}
+
 FormatToken *FormatTokenLexer::getNextToken() {
   if (StateStack.top() == LexerState::TOKEN_STASHED) {
 StateStack.pop();
@@ -854,34 +904,33 @@
   IsFirstToken = false;
 
   // Consume and record whitespace until we find a significant token.
+  // Some tok::unknown tokens are not just whitespace, e.g. whitespace
+  // followed by a symbol such as backtick. Those symbols may be
+  // significant in other languages.
   unsigned WhitespaceLength = TrailingWhitespace;
-  while (FormatTok->is(tok::unknown)) {
+  while (FormatTok->isNot(tok::eof)) {
+auto LeadingWhitespace = countLeadingWhitespace(FormatTok->TokenText);
+if (LeadingWhitespace == 0)
+  break;
+if (LeadingWhitespace < FormatTok->TokenText.size())
+  truncateToken(LeadingWhitespace);
 StringRef Text = FormatTok->TokenText;
-auto EscapesNewline = [&](int pos) {
-  // A '\r' here is just part of '\r\n'. Skip it.
-  if (pos >= 0 && Text[pos] == '\r')
---pos;
-  // See whether there is an odd number of '\' before this.
-  // FIXME: This is wrong. A '\' followed by a newline is always removed,
-  // regardless of whether there is another '\' before it.
-  // FIXME: Newlines can also be escaped by a '?' '?' '/' trigraph.
-  unsigned count = 0;
-  for (; pos >= 0; --pos, ++count)
-if (Text[pos] != '\\')
-  break;
-  return count & 1;
-};
-// FIXME: This miscounts tok:unknown tokens that are not just
-// whitespace, e.g. a '`' character.
+bool InEscape = false;
 for (int i = 0, e = Text.size(); i != e; ++i) {
   switch 

[PATCH] D103313: [RISCV][Clang] Add support for Zmmul extension

2022-06-25 Thread ksyx via Phabricator via cfe-commits
ksyx updated this revision to Diff 440017.
ksyx retitled this revision from "[RISCV][Clang] Implement support for 
zmmul-experimental" to "[RISCV][Clang] Add support for Zmmul extension".
ksyx edited the summary of this revision.
ksyx added a comment.
Herald added subscribers: sunshaoce, StephenFan, arichardson.

The Zmmul extension has just ratified 
.
 Update patch to rebase to current main.


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

https://reviews.llvm.org/D103313

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoM.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/CodeGen/RISCV/zmmul.ll
  llvm/test/MC/RISCV/rv32i-invalid.s
  llvm/test/MC/RISCV/rv32zmmul-invaild.s
  llvm/test/MC/RISCV/rv32zmmul-valid.s
  llvm/test/MC/RISCV/rv64zmmul-invalid.s
  llvm/test/MC/RISCV/rv64zmmul-valid.s

Index: llvm/test/MC/RISCV/rv64zmmul-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zmmul-valid.s
@@ -0,0 +1,5 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+zmmul -riscv-no-aliases 2>&1 \
+# RUN:  | FileCheck -check-prefixes=CHECK-INST %s
+
+# CHECK-INST: mulw ra, sp, gp
+mulw ra, sp, gp
Index: llvm/test/MC/RISCV/rv64zmmul-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zmmul-invalid.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc %s -triple=riscv64 -mattr=+zmmul -riscv-no-aliases 2>&1 \
+# RUN:  | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: 5:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+divw tp, t0, t1
+
+# CHECK-ERROR: 8:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+divuw t2, s0, s2
+
+# CHECK-ERROR: 11:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+remw a0, a1, a2
+
+# CHECK-ERROR: 14:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+remuw a3, a4, a5
Index: llvm/test/MC/RISCV/rv32zmmul-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zmmul-valid.s
@@ -0,0 +1,14 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+zmmul -riscv-no-aliases 2>&1 \
+# RUN:  | FileCheck -check-prefixes=CHECK-INST %s
+
+# CHECK-INST: mul a4, ra, s0
+mul a4, ra, s0
+
+# CHECK-INST: mulh ra, zero, zero
+mulh x1, x0, x0
+
+# CHECK-INST: mulhsu t0, t2, t1
+mulhsu t0, t2, t1
+
+# CHECK-INST: mulhu a5, a4, a3
+mulhu a5, a4, a3
Index: llvm/test/MC/RISCV/rv32zmmul-invaild.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zmmul-invaild.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc %s -triple=riscv32 -mattr=+zmmul -riscv-no-aliases 2>&1 \
+# RUN:  | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: 5:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+div s0, s0, s0
+
+# CHECK-ERROR: 8:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+divu gp, a0, a1
+
+# CHECK-ERROR: 11:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+rem s2, s2, s8
+
+# CHECK-ERROR: 14:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+remu x18, x18, x24
Index: llvm/test/MC/RISCV/rv32i-invalid.s
===
--- llvm/test/MC/RISCV/rv32i-invalid.s
+++ llvm/test/MC/RISCV/rv32i-invalid.s
@@ -169,7 +169,7 @@
 xor s2, s2 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
 
 # Instruction not in the base ISA
-mul a4, ra, s0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+div a4, ra, s0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
 amomaxu.w s5, s4, (s3) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'A' (Atomic Instructions)
 fadd.s ft0, ft1, ft2 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'F' (Single-Precision Floating-Point){{$}}
 fadd.h ft0, ft1, ft2 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point)
Index: llvm/test/CodeGen/RISCV/zmmul.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/zmmul.ll
@@ -0,0 +1,41 @@
+; RUN: llc -mtriple=riscv32 -mattr=+zmmul -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-DIV %s
+; RUN: llc -mtriple=riscv64 -mattr=+zmmul 

[PATCH] D128571: [X86] Support `_Float16` on SSE2 and up

2022-06-25 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 440016.
pengfei marked 3 inline comments as done.
pengfei added a comment.

Address review comments. Thanks @rjmccall !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128571

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/X86/Float16-arithmetic.c
  clang/test/CodeGen/X86/Float16-complex.c
  clang/test/CodeGen/X86/avx512fp16-complex.c
  clang/test/Sema/Float16.c
  clang/test/Sema/conversion-target-dep.c
  clang/test/SemaCXX/Float16.cpp

Index: clang/test/SemaCXX/Float16.cpp
===
--- clang/test/SemaCXX/Float16.cpp
+++ clang/test/SemaCXX/Float16.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-pc %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-pc -target-feature +sse2 %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE
Index: clang/test/Sema/conversion-target-dep.c
===
--- clang/test/Sema/conversion-target-dep.c
+++ clang/test/Sema/conversion-target-dep.c
@@ -6,7 +6,7 @@
 
 long double ld;
 double d;
-_Float16 f16; // x86-error {{_Float16 is not supported on this target}}
+_Float16 f16;
 
 int main(void) {
   ld = d; // x86-warning {{implicit conversion increases floating-point precision: 'double' to 'long double'}}
Index: clang/test/Sema/Float16.c
===
--- clang/test/Sema/Float16.c
+++ clang/test/Sema/Float16.c
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
-// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc -target-feature +avx512fp16 %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-pc %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-pc -target-feature +sse2 %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE
Index: clang/test/CodeGen/X86/Float16-complex.c
===
--- clang/test/CodeGen/X86/Float16-complex.c
+++ clang/test/CodeGen/X86/Float16-complex.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -target-feature +avx512fp16 -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -o - | FileCheck %s --check-prefix=X86
 
 _Float16 _Complex add_half_rr(_Float16 a, _Float16 b) {
   // X86-LABEL: @add_half_rr(
Index: clang/test/CodeGen/X86/Float16-arithmetic.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/Float16-arithmetic.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple  x86_64-unknown-unknown \
+// RUN: -emit-llvm -o - %s  | FileCheck %s --check-prefixes=CHECK
+
+// CHECK-NOT: fpext
+// CHECK-NOT: fptrunc
+
+_Float16 add1(_Float16 a, _Float16 b) {
+  return a + b;
+}
+
+_Float16 add2(_Float16 a, _Float16 b, _Float16 c) {
+  return a + b + c;
+}
+
+_Float16 div(_Float16 a, _Float16 b) {
+  return a / b;
+}
+
+_Float16 mul(_Float16 a, _Float16 b) {
+  return a * b;
+}
+
+_Float16 add_and_mul1(_Float16 a, _Float16 b, _Float16 c, _Float16 d) {
+  return a * b + c * d;
+}
+
+_Float16 add_and_mul2(_Float16 a, _Float16 b, _Float16 c, _Float16 d) {
+  return (a - 6 * b) + c;
+}
Index: clang/lib/Basic/Targets/X86.cpp
===
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targets/X86.cpp
@@ -239,7 +239,6 @@
   HasAVX512ER = true;
 } else if (Feature == "+avx512fp16") {
   HasAVX512FP16 = true;
-  HasFloat16 = true;
 } else if (Feature == "+avx512pf") {
   HasAVX512PF = true;
 } else if (Feature == "+avx512dq") {
@@ -355,6 +354,9 @@
.Default(NoSSE);
 SSELevel = std::max(SSELevel, Level);
 
+// Turn on _float16 for x86 (feature sse2)
+HasFloat16 = SSELevel >= SSE2;
+
 MMX3DNowEnum ThreeDNowLevel = llvm::StringSwitch(Feature)
   .Case("+3dnowa", AMD3DNowAthlon)
   .Case("+3dnow", AMD3DNow)
Index: clang/docs/ReleaseNotes.rst

[clang-tools-extra] b2cb7e8 - [clang-tidy] cppcoreguidelines-virtual-class-destructor: Fix crash when "virtual" keyword is expanded from a macro

2022-06-25 Thread via cfe-commits

Author: Joachim Priesner
Date: 2022-06-25T15:50:13-06:00
New Revision: b2cb7e81f8978ccce5c5e7b316480b88785ca9cc

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

LOG: [clang-tidy] cppcoreguidelines-virtual-class-destructor: Fix crash when 
"virtual" keyword is expanded from a macro

Check llvm::Optional before dereferencing it.

Compute VirtualEndLoc differently to avoid an assertion failure
in clang::SourceManager::getFileIDLoaded:

Assertion `0 && "Invalid SLocOffset or bad function choice"' failed

Added: 


Modified: 

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

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/virtual-class-destructor.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
index e730fb6fa01d..92b38bcfd81d 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -54,13 +54,17 @@ getVirtualKeywordRange(const CXXDestructorDecl ,
 return None;
 
   SourceLocation VirtualBeginLoc = Destructor.getBeginLoc();
-  SourceLocation VirtualEndLoc = VirtualBeginLoc.getLocWithOffset(
-  Lexer::MeasureTokenLength(VirtualBeginLoc, SM, LangOpts));
+  SourceLocation VirtualBeginSpellingLoc =
+  SM.getSpellingLoc(Destructor.getBeginLoc());
+  SourceLocation VirtualEndLoc = VirtualBeginSpellingLoc.getLocWithOffset(
+  Lexer::MeasureTokenLength(VirtualBeginSpellingLoc, SM, LangOpts));
 
   /// Range ends with \c StartOfNextToken so that any whitespace after \c
   /// virtual is included.
-  SourceLocation StartOfNextToken =
-  Lexer::findNextToken(VirtualEndLoc, SM, LangOpts)->getLocation();
+  Optional NextToken = Lexer::findNextToken(VirtualEndLoc, SM, 
LangOpts);
+  if (!NextToken)
+return None;
+  SourceLocation StartOfNextToken = NextToken->getLocation();
 
   return CharSourceRange::getCharRange(VirtualBeginLoc, StartOfNextToken);
 }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/virtual-class-destructor.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/virtual-class-destructor.cpp
index fcf558dcac8e..61e565075b15 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/virtual-class-destructor.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/virtual-class-destructor.cpp
@@ -272,6 +272,7 @@ DerivedFromTemplateNonVirtualBaseStruct2Typedef 
InstantiationWithPublicNonVirtua
 } // namespace Bugzilla_51912
 
 namespace macro_tests {
+#define MY_VIRTUAL virtual
 #define CONCAT(x, y) x##y
 
 // CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar1' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
@@ -317,8 +318,17 @@ class FooBar5 {
 protected:
   XMACRO(CONCAT(vir, tual), ~CONCAT(Foo, Bar5());) // no-crash, no-fixit
 };
+
+// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar6' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual
+class FooBar6 {
+protected:
+  MY_VIRTUAL ~FooBar6(); // FIXME: We should have a fixit for this.
+};
+
 #undef XMACRO
 #undef CONCAT
+#undef MY_VIRTUAL
 } // namespace macro_tests
 
 namespace FinalClassCannotBeBaseClass {



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


[PATCH] D128157: [clang-tidy] cppcoreguidelines-virtual-class-destructor: Fix crash when "virtual" keyword is expanded from a macro

2022-06-25 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood accepted this revision.
LegalizeAdulthood added a comment.
This revision is now accepted and ready to land.

Well, it must have been unrelated to your change or some weird interaction on 
my machine because I rebased and ran `check-clang-extra` again and it passed 
this time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128157

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


[PATCH] D127873: [clang-format] Fix misplacement of `*` in declaration of pointer to struct

2022-06-25 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

But for now you should wait for @MyDeveloperDay that he at least removes the 
changes needed, or state what you have to change, or even better accept it.


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

https://reviews.llvm.org/D127873

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


[PATCH] D127873: [clang-format] Fix misplacement of `*` in declaration of pointer to struct

2022-06-25 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D127873#3610106 , @jackhong12 
wrote:

> Hi. I passed the unit tests on my computer. But the build status here is 
> failed. The build log only shows the issue is related to `git reset --hard`. 
> So, I don't know where the bug is. Could you give me some hints to fix this 
> issue? Thanks!

If everything is fine on your side, and you can't see a problem related to you 
on the build bot, just push it. If it really breaks something you will notice. 
:)


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

https://reviews.llvm.org/D127873

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


[PATCH] D118996: [clang-tidy] Support C++14 in bugprone-signal-handler.

2022-06-25 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:282
+// These are all class names in ExprCXX.h without 'CXX' prefix.
+#define CXXStmts \
+  ArrayTypeTraitExpr,\

I'm not a fan of this macro, and we're only using it once as the argument to 
`isa<>`; is there some problem with writing it inline?



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:246
 
+- Improved :doc:`bugprone-signal-handler
+  ` check. Partial

Please keep the section sorted by check, so this should be inserted before 
`bugprone-use-after-move`



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.cpp:1
+// RUN: %check_clang_tidy -std=c++14 %s bugprone-signal-handler %t -- -- 
-isystem %S/../Inputs/Headers -isystem %S/Inputs/signal-handler
+

Prefer `-isystem %clang_tidy_headers`  instead of `-isystem 
%S/../Inputs/Headers`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118996

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


[PATCH] D128554: [Driver][Minix] -r: imply -nostdlib like GCC

2022-06-25 Thread Brad Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG066043c84fdb: [Driver][Minix] -r: imply -nostdlib like GCC 
(authored by brad).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128554

Files:
  clang/lib/Driver/ToolChains/Minix.cpp
  clang/test/Driver/minix.c


Index: clang/test/Driver/minix.c
===
--- /dev/null
+++ clang/test/Driver/minix.c
@@ -0,0 +1,6 @@
+// -r suppresses default -l and crt*.o like -nostdlib.
+// RUN: %clang -### %s --target=i386-unknown-minix -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
+// CHECK-RELOCATABLE: "-r"
+// CHECK-RELOCATABLE-NOT: "-l
+// CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
Index: clang/lib/Driver/ToolChains/Minix.cpp
===
--- clang/lib/Driver/ToolChains/Minix.cpp
+++ clang/lib/Driver/ToolChains/Minix.cpp
@@ -56,7 +56,8 @@
 assert(Output.isNothing() && "Invalid output.");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
 
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
 CmdArgs.push_back(
@@ -71,7 +72,8 @@
 
   getToolChain().addProfileRTLibs(Args, CmdArgs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+   options::OPT_r)) {
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
@@ -79,7 +81,8 @@
 }
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 if (Args.hasArg(options::OPT_pthread))
   CmdArgs.push_back("-lpthread");
 CmdArgs.push_back("-lc");


Index: clang/test/Driver/minix.c
===
--- /dev/null
+++ clang/test/Driver/minix.c
@@ -0,0 +1,6 @@
+// -r suppresses default -l and crt*.o like -nostdlib.
+// RUN: %clang -### %s --target=i386-unknown-minix -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
+// CHECK-RELOCATABLE: "-r"
+// CHECK-RELOCATABLE-NOT: "-l
+// CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
Index: clang/lib/Driver/ToolChains/Minix.cpp
===
--- clang/lib/Driver/ToolChains/Minix.cpp
+++ clang/lib/Driver/ToolChains/Minix.cpp
@@ -56,7 +56,8 @@
 assert(Output.isNothing() && "Invalid output.");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
 CmdArgs.push_back(
@@ -71,7 +72,8 @@
 
   getToolChain().addProfileRTLibs(Args, CmdArgs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+   options::OPT_r)) {
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
@@ -79,7 +81,8 @@
 }
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 if (Args.hasArg(options::OPT_pthread))
   CmdArgs.push_back("-lpthread");
 CmdArgs.push_back("-lc");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 066043c - [Driver][Minix] -r: imply -nostdlib like GCC

2022-06-25 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2022-06-25T16:16:38-04:00
New Revision: 066043c84fdb0ee0d719fd80b0ff9e0f853850d0

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

LOG: [Driver][Minix] -r: imply -nostdlib like GCC

Similar to D116843 for Gnu.cpp

Reviewed By: MaskRay

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

Added: 
clang/test/Driver/minix.c

Modified: 
clang/lib/Driver/ToolChains/Minix.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Minix.cpp 
b/clang/lib/Driver/ToolChains/Minix.cpp
index 5bceb9aba3e96..4b8670a79012e 100644
--- a/clang/lib/Driver/ToolChains/Minix.cpp
+++ b/clang/lib/Driver/ToolChains/Minix.cpp
@@ -56,7 +56,8 @@ void tools::minix::Linker::ConstructJob(Compilation , const 
JobAction ,
 assert(Output.isNothing() && "Invalid output.");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
 
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
 CmdArgs.push_back(
@@ -71,7 +72,8 @@ void tools::minix::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   getToolChain().addProfileRTLibs(Args, CmdArgs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+   options::OPT_r)) {
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
@@ -79,7 +81,8 @@ void tools::minix::Linker::ConstructJob(Compilation , const 
JobAction ,
 }
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 if (Args.hasArg(options::OPT_pthread))
   CmdArgs.push_back("-lpthread");
 CmdArgs.push_back("-lc");

diff  --git a/clang/test/Driver/minix.c b/clang/test/Driver/minix.c
new file mode 100644
index 0..54f261d53809d
--- /dev/null
+++ b/clang/test/Driver/minix.c
@@ -0,0 +1,6 @@
+// -r suppresses default -l and crt*.o like -nostdlib.
+// RUN: %clang -### %s --target=i386-unknown-minix -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
+// CHECK-RELOCATABLE: "-r"
+// CHECK-RELOCATABLE-NOT: "-l
+// CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o



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


[PATCH] D128372: [Clang-Tidy] Empty Check

2022-06-25 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood requested changes to this revision.
LegalizeAdulthood added inline comments.
This revision now requires changes to proceed.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-standalone-empty.cpp:1
+// RUN: %check_clang_tidy %s bugprone-standalone-empty %t
+

This file should be removed from the changelist


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

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


[PATCH] D37797: Fix crash in Sema when wrongly assuming VarDecl init is not value dependent.

2022-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev resigned from this revision.
v.g.vassilev added a comment.
Herald added a project: All.

According to godbolt this example does not crash anymore.


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

https://reviews.llvm.org/D37797

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


[PATCH] D128402: [clang-tidy] Don't treat invalid branches as identical

2022-06-25 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood requested changes to this revision.
LegalizeAdulthood added a comment.
This revision now requires changes to proceed.

Rebase against main to get updated docs


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

https://reviews.llvm.org/D128402

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


[PATCH] D125944: Template instantiation error recovery

2022-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

In D125944#3544341 , @v.g.vassilev 
wrote:

> @Purva-Chaudhari, can you rebase this patch, seems that it is not buildable.
>
> @rsmith, we need to do something similar in cling to handle pending template 
> instantiations, I guess the question is if we can avoid instantiating the 
> templates we don't need and still survive.

@rsmith, ping.




Comment at: clang/test/Interpreter/execute.cpp:2
+// RUN: clang-repl "template T f() { return T(); }" "auto ptu2 = 
f(); err;" \
+// RUN: "auto ptu2 = f();" "int i = 0;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \

Can you move this test into a separate file which is dedicated for testing 
recovery of templates?


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

https://reviews.llvm.org/D125944

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


[PATCH] D125946: Handles failing driver tests of clang

2022-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/test/Interpreter/clangtests.cpp:1
+// RUN: clang-repl %S/../Lexer/badstring_in_if0.c -Xcc -E -Xcc -verify
+// RUN: clang-repl %S/../Lexer/unknown-char.c -Xcc -E -Xcc -verify

dblaikie wrote:
> v.g.vassilev wrote:
> > dblaikie wrote:
> > > dblaikie wrote:
> > > > v.g.vassilev wrote:
> > > > > @rsmith, would it be acceptable to have a test that refers other 
> > > > > tests from the repo in that manner?
> > > > Generally that's not done - and the inputs should be moved into an 
> > > > "Inputs" subdirectory and shared from there. Tests that are in 
> > > > different subdirectories - not sure if there's a good way to share 
> > > > those, maybe with an "Inputs" directory in a parent directory of both 
> > > > tests? We might not have precednt for that
> > > But more broadly, could you explain what the goal of these tests are? 
> > > Generally I would discourage what I think of as "shotgun" testing - 
> > > taking some existing comprehensive test for a particular feature and 
> > > using it to test a mostly orthogonal feature. The orthogonal feature 
> > > should have more targeted tests/it shouldn't be using such broad testing 
> > > in the regression suite here.
> > My take is that `clang-repl` is basically clang that takes inputs 
> > incrementally. Being that, means that we should be in a position to process 
> > whatever clang processes and thus we run against all of the existing tests. 
> > We planned to add the ones which we did not support as regression tests.
> > 
> > We can add more targeted tests but they would be copies or simplifications 
> > of already existing ones. Hence there is my hesitation - reuse or 
> > duplication...
> > 
> > My take is that clang-repl is basically clang that takes inputs 
> > incrementally. Being that, means that we should be in a position to process 
> > whatever clang processes and thus we run against all of the existing tests.
> 
> Yeah, that's sort of the "proof by absurdity" - we wouldn't want every clang 
> test running in both ahead of time and incremental mode in the usual 
> "check-clang" regression suite (I wouldn't mind having a separate mode for 
> testing - more of an integration test that some buildbots or those working on 
> more comprehensive clang-repl support could run, but most people/especially 
> fast bots would not). So then the question for me is which tests should we 
> have running all the time in "check-clang" - and my general answer is: 
> Situations that have motivated code changes/support in clang-repl: If no code 
> was added/changed/etc to clang-repl, then no test should be added to 
> "check-clang" for that test case.
> 
> If that "run everything under check-clang run under clang-repl to find 
> missing functionality" found some clang test that didn't work with 
> clang-repl, yeah, I'd generally be in favour of not reusing an input or 
> duplicating in its entirety - but reducing the test case to test only the 
> specific clang-repl functionality issue, and testing that in particular.
> 
> Like we shouldn't test every feature of static-assert with clang-repl and 
> clang in every "clang-check" if most of those features aren't distinctly 
> interesting in both cases. Just enough in clang-repl to test what makes 
> static-assert interesting in clang-repl.
@dblaikie, that makes sense to me.

@Purva-Chaudhari, can you address it by having just something like 
`// RUN: clang-repl  -Xcc -E` to exercise the -E and likewise for the `EmitBC` 
case?


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

https://reviews.llvm.org/D125946

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


[PATCH] D54986: Make CodeGen choose when to emit vtables.

2022-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev resigned from this revision.
v.g.vassilev added a comment.
Herald added a project: All.

I think this landed in a different form.


Repository:
  rC Clang

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

https://reviews.llvm.org/D54986

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


[PATCH] D128589: [clang-repl] Support destructors of global objects.

2022-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

LGTM, modulo the comment.




Comment at: clang/lib/Interpreter/IncrementalExecutor.h:46
   llvm::Error runCtors() const;
+  llvm::Error cleanUp();
   llvm::Expected

Can you document this function?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128589

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


[clang] b8df409 - [clang, clang-tools-extra] Don't use Optional::{hasValue,getValue} (NFC)

2022-06-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-06-25T11:55:33-07:00
New Revision: b8df4093e4d82c67a419911a46b63482043643e5

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

LOG: [clang, clang-tools-extra] Don't use Optional::{hasValue,getValue} (NFC)

Added: 


Modified: 
clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/clangd/unittests/DumpASTTests.cpp
clang-tools-extra/clangd/unittests/FileIndexTests.cpp
clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
clang-tools-extra/clangd/unittests/HeadersTests.cpp
clang-tools-extra/clangd/unittests/LSPClient.cpp
clang-tools-extra/clangd/unittests/Matchers.h
clang-tools-extra/clangd/unittests/SerializationTests.cpp
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
clang-tools-extra/clangd/unittests/SyncAPI.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp
clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Basic/DarwinSDKInfoTest.cpp
clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
clang/unittests/Lex/LexerTest.cpp
clang/unittests/Tooling/SourceCodeTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp 
b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
index 722a5fb699f61..c3ad1b8cfb666 100644
--- a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -46,7 +46,7 @@ class LSPTest : public ::testing::Test {
   }
 
   LSPClient () {
-EXPECT_FALSE(Server.hasValue()) << "Already initialized";
+EXPECT_FALSE(Server) << "Already initialized";
 Server.emplace(Client.transport(), FS, Opts);
 ServerThread.emplace([&] { EXPECT_TRUE(Server->run()); });
 Client.call("initialize", llvm::json::Object{});

diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 88698d3177168..f962c3f4ff336 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -92,7 +92,7 @@ Matcher &> has(std::string 
Name,
  CompletionItemKind K) {
   return Contains(AllOf(named(std::move(Name)), kind(K)));
 }
-MATCHER(isDocumented, "") { return arg.Documentation.hasValue(); }
+MATCHER(isDocumented, "") { return arg.Documentation.has_value(); }
 MATCHER(deprecated, "") { return arg.Deprecated; }
 
 std::unique_ptr memIndex(std::vector Symbols) {

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 45ceee01ea9a1..0a24f3c0c69b2 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -892,8 +892,7 @@ void bar(int *Y);
   ASSERT_TRUE(X->getOriginalType()->getNullability(X->getASTContext()) ==
   NullabilityKind::NonNull);
   const auto *Y = cast(findDecl(AST, "bar")).getParamDecl(0);
-  ASSERT_FALSE(
-  Y->getOriginalType()->getNullability(X->getASTContext()).hasValue());
+  ASSERT_FALSE(Y->getOriginalType()->getNullability(X->getASTContext()));
 }
 
 TEST(DiagnosticsTest, InsideMacros) {

diff  --git a/clang-tools-extra/clangd/unittests/DumpASTTests.cpp 
b/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
index f316eedfbf605..e7b368fd25522 100644
--- a/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
@@ -172,8 +172,7 @@ TEST(DumpASTTests, NoRange) {
   ASSERT_THAT(Node.children, Contains(withDetail("varFromSource")));
   ASSERT_THAT(Node.children, Not(Contains(withDetail("funcFromHeader";
   EXPECT_THAT(Node.arcana, testing::StartsWith("TranslationUnitDecl "));
-  ASSERT_FALSE(Node.range.hasValue())
-  << "Expected no range for translation unit";
+  ASSERT_FALSE(Node.range) << "Expected no range for translation unit";
 }
 
 TEST(DumpASTTests, Arcana) {

diff  --git a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp 

[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-06-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@aaron.ballman @tahonermann Thanks for the review. I landed the change after 
confirming with Aaron he was happy with it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

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


[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-06-25 Thread Corentin Jabot 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 rGc92056d03881: [Clang][C++23] P2071 Named universal character 
escapes (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/FixIt/fixit-unicode-named-escape-sequences.c
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Lexer/unicode.c
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c
  llvm/CMakeLists.txt
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/CMakeLists.txt
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D128257: invalidateCache in addModule and removeModules

2022-06-25 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak added a comment.

https://github.com/llvm/llvm-project/commit/ca39214f4e9fddf247e880ef9562865be850fce6#diff-a59fa24a712b79c57b4d922d0d407b8f63a9a88fa79ba0d85b0063e1a2a6fda3L157

closing, now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128257

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-06-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D126864#3609965 , @xbolva00 wrote:

>>> -fsanitize=array-bounds workaround for size-1 array as the last member of a 
>>> structure
>
> Could you provide option for that (to enable stricker bound checks introduced 
> with this patch) ?

My commit just restored the previous -fsanitize=array-bounds behavior (as if 
the default is -fstrict-flex-arrays=1, different from Sema).
`-fstrict-flex-arrays=2` or above can make -fsanitize=array-bounds stricter.


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

https://reviews.llvm.org/D126864

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


[PATCH] D128554: [Driver][Minix] -r: imply -nostdlib like GCC

2022-06-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128554

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


[PATCH] D126266: Mark the file entry invalid, until reread. Invalidate SLocEntry cache, readd it on reread. Do not use translateFile, because it pulls in parts of the pch.

2022-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

After landing https://reviews.llvm.org/D126682 we might be able to write a test 
in clang-repl such as:

  cpp
  clang-repl> #include 
  clang-repl> #include 
  clang-repl>using namespace std;
  clang-repl> int write_str (const char* str) {
ofstream myfile;
myfile.open ("a.h");
myfile << str<<"\n";
myfile.close();
return 0;
  }
  clang-repl> auto r1 = write_str("int i = 42");
  clang-repl> extern "C" int printf(const char*,...);
  clang-repl> #include "a.h"
  clang-repl> auto r2 = printf("i=%d\n", i);
  clang-repl>%undo
  clang-repl>%undo 
  clang-repl> auto r3 = write_str("int i = 0");
  clang-repl> #include "a.h"
  clang-repl> auto r2 = printf("i=%d\n", i);
  // Here we should print `i=0`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126266

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


[PATCH] D128257: invalidateCache in addModule and removeModules

2022-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

I think this patch is not needed in the `main` branch as 
https://github.com/llvm/llvm-project/commit/f91b6f8159b101688eef87c75179209699c0d405
 removes the need of calling `invalidateCache` altogether.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128257

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


[PATCH] D128319: Survive #pragma once from virtual file.

2022-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a reviewer: rsmith.
v.g.vassilev added a comment.

Can we write a test for this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128319

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


[PATCH] D126682: [Interpreter][ClangRepl] Implement undo command

2022-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/include/clang/Interpreter/Interpreter.h:72
 
+  void Restore(PartialTranslationUnit );
+

v.g.vassilev wrote:
> I am not sure if that's the best function. We 
Please ignore this comment it was superseded by another one and I forgot to 
delete it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

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


[PATCH] D126682: [Interpreter][ClangRepl] Implement undo command

2022-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

Thanks for working on this. Here are some more comments.




Comment at: clang/include/clang/Interpreter/Interpreter.h:72
 
+  void Restore(PartialTranslationUnit );
+

I am not sure if that's the best function. We 



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:281
 
+void IncrementalParser::Restore(PartialTranslationUnit ) {
+  TranslationUnitDecl *MostRecentTU = PTU.TUPart;

I think we can merge this function with `Undo` where we can conditionally check 
if we have a llvm::Module to recover.



Comment at: clang/lib/Interpreter/Interpreter.cpp:273
+llvm::Error Err = llvm::Error::success();
+IncrExecutor = std::make_unique(*TSCtx, Err, Triple);
+

I am not sure how feasible is this usecase but in `-fsyntax-only` mode we can 
still need undo. That means somebody created an Interpreter instance for 
frontend-only operations, such as lookups or template instantiations. In that 
case I think it also would make sense to support the undo operation.



Comment at: clang/lib/Interpreter/Interpreter.cpp:278
+  }
+  if (N > IncrExecutor->getAvailableModuleSize())
+return llvm::make_error("Operation failed, "

In some cases we can have PTU's that do not generate code. For example, `define 
A 1` will not produce a corresponding llvm::Module. I think here we should 
count the size of the PartialTranslationUnitDecls.



Comment at: clang/test/Interpreter/code-undo.cpp:7
+// RUN: cat %s | clang-repl | FileCheck %s
+extern "C" int printf(const char *, ...);
+int x1 = 42;

Can you add here something like `int j = 0` and print its value after the 
`undo`. This way we will make sure we do not undo too much.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

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


[PATCH] D128571: [X86] Support `_Float16` on SSE2 and up

2022-06-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:746
 * SPIR
-* X86 (Only available under feature AVX512-FP16)
+* X86 (Enabled with feature SSE2 and up)
 

Could you take the wording I suggested from the other patch?  You'll need to 
drop the part about avoiding intermediate truncations, but it's important to 
still document the practical/performance difference when AVX512-FP16 is not 
available, even if the observable behavior is the same.



Comment at: clang/docs/ReleaseNotes.rst:517
 
+- Support for ``_Float16`` type has been added.
+





Comment at: clang/test/SemaCXX/Float16.cpp:4
+// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s
 

This test (and Float16.c) should continue to have positive and negative 
examples even if generic x86_64 is no longer negative.  Generic i386 should 
still be negative, for example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128571

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


[PATCH] D126845: [clang-format] Handle Verilog numbers and operators

2022-06-25 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 439981.
sstwcw added a comment.

- address comments
- add token annotator tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126845

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

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -38,6 +38,8 @@
   EXPECT_EQ((FormatTok)->Tok.getKind(), Kind) << *(FormatTok)
 #define EXPECT_TOKEN_TYPE(FormatTok, Type) \
   EXPECT_EQ((FormatTok)->getType(), Type) << *(FormatTok)
+#define EXPECT_TOKEN_PRECEDENCE(FormatTok, Prec)   \
+  EXPECT_EQ((FormatTok)->getPrecedence(), Prec) << *(FormatTok)
 #define EXPECT_TOKEN(FormatTok, Kind, Type)\
   do { \
 EXPECT_TOKEN_KIND(FormatTok, Kind);\
@@ -801,6 +803,67 @@
   EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_ObjCBlockLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
+  auto Annotate = [this](llvm::StringRef Code) {
+return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog));
+  };
+  // Test that unary operators get labeled as such and that operators like '++'
+  // don't get split.
+  tok::TokenKind Unary[] = {tok::plus,  tok::minus,tok::exclaim,
+tok::tilde, tok::amp,  tok::pipe,
+tok::caret, tok::plusplus, tok::minusminus};
+  for (auto Kind : Unary) {
+auto Tokens =
+Annotate(std::string("x = ") + tok::getPunctuatorSpelling(Kind) + "x;");
+ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+EXPECT_TOKEN(Tokens[2], Kind, TT_UnaryOperator);
+  }
+  // Operators formed by joining two operators like '^~'. For some of these
+  // joined operators, we don't have a separate type, so we only test for their
+  // precedence.
+  std::pair JoinedBinary[] = {
+  {prec::Comma, "<->"},   {prec::Assignment, "+="},
+  {prec::Assignment, "-="},   {prec::Assignment, "*="},
+  {prec::Assignment, "/="},   {prec::Assignment, "%="},
+  {prec::Assignment, "&="},   {prec::Assignment, "^="},
+  {prec::Assignment, "<<="},  {prec::Assignment, ">>="},
+  {prec::Assignment, "<<<="}, {prec::Assignment, ">>>="},
+  {prec::LogicalOr, "||"},{prec::LogicalAnd, "&&"},
+  {prec::Equality, "=="}, {prec::Equality, "!="},
+  {prec::Equality, "==="},{prec::Equality, "!=="},
+  {prec::Equality, "==?"},{prec::Equality, "!=?"},
+  {prec::ExclusiveOr, "~^"},  {prec::ExclusiveOr, "^~"},
+  };
+  for (auto Operator : JoinedBinary) {
+auto Tokens = Annotate(std::string("x = x ") + Operator.second + " x;");
+ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+EXPECT_TOKEN_TYPE(Tokens[3], TT_BinaryOperator);
+EXPECT_TOKEN_PRECEDENCE(Tokens[3], Operator.first);
+  }
+  // '~^' and '^~' can be unary as well as binary operators.
+  auto Tokens = Annotate("x = ~^x;");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN_TYPE(Tokens[2], TT_UnaryOperator);
+  Tokens = Annotate("x = ^~x;");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN_TYPE(Tokens[2], TT_UnaryOperator);
+  // The unary operators '~&' and '~|' can only be unary operators. The current
+  // implementation treats each of them as separate unary '~' and '&' or '|'
+  // operators, which is enough for formatting purposes. In FormatTestVerilog,
+  // there is a test that there is no space in between. And even if a new line
+  // is inserted between the '~' and '|', the semantic meaning is the same as
+  // the joined operator, so the CanBreakBefore property doesn't need to be
+  // false for the second operator.
+  Tokens = Annotate("x = ~");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::tilde, TT_UnaryOperator);
+  EXPECT_TOKEN(Tokens[3], tok::amp, TT_UnaryOperator);
+  Tokens = Annotate("x = ~|x;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::tilde, TT_UnaryOperator);
+  EXPECT_TOKEN(Tokens[3], tok::pipe, TT_UnaryOperator);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -45,6 +45,27 @@
   }
 };
 
+TEST_F(FormatTestVerilog, BasedLiteral) {
+  verifyFormat("x = '0;");
+  verifyFormat("x = '1;");
+  verifyFormat("x = 'X;");
+  

[PATCH] D127873: [clang-format] Fix misplacement of `*` in declaration of pointer to struct

2022-06-25 Thread Jack Huang via Phabricator via cfe-commits
jackhong12 marked 2 inline comments as done.
jackhong12 added a comment.

Hi. I passed the unit tests on my computer. But the build status here is 
failed. The build log only shows the issue is related to `git reset --hard`. 
So, I don't know where the bug is. Could you give me some hints to fix this 
issue? Thanks!


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

https://reviews.llvm.org/D127873

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


[PATCH] D128569: Start support for HLSL `RWBuffer`

2022-06-25 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added inline comments.



Comment at: clang/include/clang/Basic/Builtins.def:1703
 LANGBUILTIN(WaveActiveCountBits, "Uib", "nc", HLSL_LANG)
+LANGBUILTIN(__builtin_hlsl_get_resource_pointer, "v*", "i", HLSL_LANG)
+LANGBUILTIN(__builtin_hlsl_get_resource_status, "Ui", "i", HLSL_LANG)

Is it possible to return a ptr with special address space so we know it is from 
a resource?



Comment at: clang/test/AST/HLSL/ResourceStruct.hlsl:1
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl 
-fsyntax-only -ast-dump %s | FileCheck %s 
+

lib profile starts from shader model 6.3.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128569

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


[PATCH] D126934: [clang-format] NFC Sort names of format token types

2022-06-25 Thread sstwcw 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 rG1f69f7ea9af4: [clang-format] NFC Sort names of format token 
types (authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126934

Files:
  clang/lib/Format/FormatToken.h


Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -46,6 +46,13 @@
   /* l_brace of if/for/while */
\
   TYPE(ControlStatementLBrace) 
\
   TYPE(CppCastLParen)  
\
+  TYPE(CSharpGenericTypeConstraint)
\
+  TYPE(CSharpGenericTypeConstraintColon)   
\
+  TYPE(CSharpGenericTypeConstraintComma)   
\
+  TYPE(CSharpNamedArgumentColon)   
\
+  TYPE(CSharpNullable) 
\
+  TYPE(CSharpNullConditionalLSquare)   
\
+  TYPE(CSharpStringLiteral)
\
   TYPE(CtorInitializerColon)   
\
   TYPE(CtorInitializerComma)   
\
   TYPE(DesignatedInitializerLSquare)   
\
@@ -68,6 +75,7 @@
   TYPE(InlineASMColon) 
\
   TYPE(InlineASMSymbolicNameLSquare)   
\
   TYPE(JavaAnnotation) 
\
+  TYPE(JsAndAndEqual)  
\
   TYPE(JsComputedPropertyName) 
\
   TYPE(JsExponentiation)   
\
   TYPE(JsExponentiationEqual)  
\
@@ -76,7 +84,6 @@
   TYPE(JsTypeColon)
\
   TYPE(JsTypeOperator) 
\
   TYPE(JsTypeOptionalQuestion) 
\
-  TYPE(JsAndAndEqual)  
\
   TYPE(LambdaArrow)
\
   TYPE(LambdaLBrace)   
\
   TYPE(LambdaLSquare)  
\
@@ -101,6 +108,7 @@
   TYPE(OverloadedOperator) 
\
   TYPE(OverloadedOperatorLParen)   
\
   TYPE(PointerOrReference) 
\
+  TYPE(ProtoExtensionLSquare)  
\
   TYPE(PureVirtualSpecifier)   
\
   TYPE(RangeBasedForLoopColon) 
\
   TYPE(RecordLBrace)   
\
@@ -119,7 +127,6 @@
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
   TYPE(TemplateString) 
\
-  TYPE(ProtoExtensionLSquare)  
\
   TYPE(TrailingAnnotation) 
\
   TYPE(TrailingReturnArrow)
\
   TYPE(TrailingUnaryOperator)  
\
@@ -128,13 +135,6 @@
   TYPE(UnaryOperator)  
\
   TYPE(UnionLBrace)
\
   TYPE(UntouchableMacroFunc)   
\
-  TYPE(CSharpStringLiteral)
\
-  TYPE(CSharpNamedArgumentColon)   
\
-  TYPE(CSharpNullable) 
\
-  TYPE(CSharpNullConditionalLSquare)   
\
-  TYPE(CSharpGenericTypeConstraint)
\
-  TYPE(CSharpGenericTypeConstraintColon)   
\
-  TYPE(CSharpGenericTypeConstraintComma)   
\
   TYPE(Unknown)
 
 /// Determines the semantic type 

[clang] 1f69f7e - [clang-format] NFC Sort names of format token types

2022-06-25 Thread via cfe-commits

Author: sstwcw
Date: 2022-06-25T12:09:49Z
New Revision: 1f69f7ea9af4bd4e8001a25044aa026557f366f7

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

LOG: [clang-format] NFC Sort names of format token types

Suggested by HazardyKnusperkeks in D126845.

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 


Modified: 
clang/lib/Format/FormatToken.h

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 71acdf2f094ba..145ae39ddb62c 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -46,6 +46,13 @@ namespace format {
   /* l_brace of if/for/while */
\
   TYPE(ControlStatementLBrace) 
\
   TYPE(CppCastLParen)  
\
+  TYPE(CSharpGenericTypeConstraint)
\
+  TYPE(CSharpGenericTypeConstraintColon)   
\
+  TYPE(CSharpGenericTypeConstraintComma)   
\
+  TYPE(CSharpNamedArgumentColon)   
\
+  TYPE(CSharpNullable) 
\
+  TYPE(CSharpNullConditionalLSquare)   
\
+  TYPE(CSharpStringLiteral)
\
   TYPE(CtorInitializerColon)   
\
   TYPE(CtorInitializerComma)   
\
   TYPE(DesignatedInitializerLSquare)   
\
@@ -68,6 +75,7 @@ namespace format {
   TYPE(InlineASMColon) 
\
   TYPE(InlineASMSymbolicNameLSquare)   
\
   TYPE(JavaAnnotation) 
\
+  TYPE(JsAndAndEqual)  
\
   TYPE(JsComputedPropertyName) 
\
   TYPE(JsExponentiation)   
\
   TYPE(JsExponentiationEqual)  
\
@@ -76,7 +84,6 @@ namespace format {
   TYPE(JsTypeColon)
\
   TYPE(JsTypeOperator) 
\
   TYPE(JsTypeOptionalQuestion) 
\
-  TYPE(JsAndAndEqual)  
\
   TYPE(LambdaArrow)
\
   TYPE(LambdaLBrace)   
\
   TYPE(LambdaLSquare)  
\
@@ -101,6 +108,7 @@ namespace format {
   TYPE(OverloadedOperator) 
\
   TYPE(OverloadedOperatorLParen)   
\
   TYPE(PointerOrReference) 
\
+  TYPE(ProtoExtensionLSquare)  
\
   TYPE(PureVirtualSpecifier)   
\
   TYPE(RangeBasedForLoopColon) 
\
   TYPE(RecordLBrace)   
\
@@ -119,7 +127,6 @@ namespace format {
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
   TYPE(TemplateString) 
\
-  TYPE(ProtoExtensionLSquare)  
\
   TYPE(TrailingAnnotation) 
\
   TYPE(TrailingReturnArrow)
\
   TYPE(TrailingUnaryOperator)  
\
@@ -128,13 +135,6 @@ namespace format {
   TYPE(UnaryOperator)  
\
   TYPE(UnionLBrace)
\
   TYPE(UntouchableMacroFunc)   
\
-  TYPE(CSharpStringLiteral)
\
-  TYPE(CSharpNamedArgumentColon)   
\
-  TYPE(CSharpNullable) 
\
-  

[PATCH] D128571: [X86] Support `_Float16` on SSE2 and up

2022-06-25 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128571

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


[PATCH] D128501: [CodeGen] Make uninitialized Lvalue bit-field stores poison compatible

2022-06-25 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes added a comment.

In D128501#3608846 , @efriedma wrote:

> Under this scheme, is it illegal to link together object files built with 
> -ffine-grained-bitfield-accesses and object files built with 
> -fno-fine-grained-bitfield-accesses?

No, you can still link those. There's no ABI change nor any interference at IR 
level.
Thanks for the pointer, I wasn't aware of that option. What we can do is to 
optimize away the freezes with -ffine-grained-bitfield-accesses. The freeze is 
only needed when a struct field is shared between more than one bitfield.

Regarding perf, it's looking good, but @jmciver will post here a summary later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128501

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


[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-06-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

@LegalizeAdulthood I've addressed your comments, thanks for the clear 
instructions! One thing I didn't manage to do is build the target 
`docs-clang-tools-html`, it says it doesn't exist. I've enabled 
`LLVM_BUILD_DOCS=ON` in the CMake call - do you know if I need to enable 
something else?

PS: also the `test-clang-extra` doesn't exist, I typically run 
`check-clang-tools-extra`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126880

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


[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-06-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 439974.
carlosgalvezp added a comment.

Fix test name


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126880

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
@@ -0,0 +1,152 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-const-or-ref-data-members %t
+namespace std {
+template 
+struct reference_wrapper {};
+} // namespace std
+
+namespace gsl {
+template 
+struct not_null {};
+} // namespace gsl
+
+struct Ok {
+  int i;
+  int *p;
+  const int *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember {
+  const int c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct LvalueRefMember {
+  int 
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+};
+
+struct ConstRefMember {
+  const int 
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+};
+
+struct RvalueRefMember {
+  int &
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstAndRefMembers {
+  int const c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  int 
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+  const int 
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+  int &
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct Foo {};
+
+struct Ok2 {
+  Foo i;
+  Foo *p;
+  const Foo *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+};
+
+struct LvalueRefMember2 {
+  Foo 
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+};
+
+struct ConstRefMember2 {
+  const Foo 
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+};
+
+struct RvalueRefMember2 {
+  Foo &
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstAndRefMembers2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  Foo 
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+  const Foo 
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+  Foo &
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+using ConstType = const int;
+using RefType = int &;
+using ConstRefType = const int &;
+using RefRefType = int &&;
+
+struct WithAlias {
+  ConstType c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  RefType lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: member 'lr' is a reference
+  ConstRefType cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: member 'cr' is a reference
+  RefRefType rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+using Array = int[N];
+
+struct ConstArrayMember {
+  const Array<1> c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: member 'c' is const qualified
+};
+
+struct LvalueRefArrayMember {
+  Array<2> 
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'lr' is a reference
+};
+
+struct ConstLvalueRefArrayMember {
+  Array<3> const 
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: member 'cr' is a reference
+};
+
+struct RvalueRefArrayMember {
+  Array<4> &
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+struct TemplatedOk {
+  T t;
+};
+
+template 
+struct TemplatedConst {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is const qualified
+};
+
+template 
+struct TemplatedRef {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is a reference
+};
+
+TemplatedOk t1{};
+TemplatedConst t2{123};
+TemplatedRef t3{123};
+TemplatedRef t4{123};
+TemplatedRef t5{t1.t};
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===

[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-06-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 439973.
carlosgalvezp added a comment.

Rebase and fix directory structure for doc and test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126880

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/cppcoreguidelines-avoid-const-or-ref-data-members.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
@@ -0,0 +1,152 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-const-or-ref-data-members %t
+namespace std {
+template 
+struct reference_wrapper {};
+} // namespace std
+
+namespace gsl {
+template 
+struct not_null {};
+} // namespace gsl
+
+struct Ok {
+  int i;
+  int *p;
+  const int *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember {
+  const int c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct LvalueRefMember {
+  int 
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+};
+
+struct ConstRefMember {
+  const int 
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+};
+
+struct RvalueRefMember {
+  int &
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstAndRefMembers {
+  int const c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  int 
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+  const int 
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+  int &
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct Foo {};
+
+struct Ok2 {
+  Foo i;
+  Foo *p;
+  const Foo *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+};
+
+struct LvalueRefMember2 {
+  Foo 
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+};
+
+struct ConstRefMember2 {
+  const Foo 
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+};
+
+struct RvalueRefMember2 {
+  Foo &
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstAndRefMembers2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  Foo 
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+  const Foo 
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+  Foo &
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+using ConstType = const int;
+using RefType = int &;
+using ConstRefType = const int &;
+using RefRefType = int &&;
+
+struct WithAlias {
+  ConstType c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  RefType lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: member 'lr' is a reference
+  ConstRefType cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: member 'cr' is a reference
+  RefRefType rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+using Array = int[N];
+
+struct ConstArrayMember {
+  const Array<1> c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: member 'c' is const qualified
+};
+
+struct LvalueRefArrayMember {
+  Array<2> 
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'lr' is a reference
+};
+
+struct ConstLvalueRefArrayMember {
+  Array<3> const 
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: member 'cr' is a reference
+};
+
+struct RvalueRefArrayMember {
+  Array<4> &
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+struct TemplatedOk {
+  T t;
+};
+
+template 
+struct TemplatedConst {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is const qualified
+};
+
+template 
+struct TemplatedRef {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is a reference
+};
+
+TemplatedOk t1{};
+TemplatedConst t2{123};
+TemplatedRef t3{123};
+TemplatedRef t4{123};
+TemplatedRef t5{t1.t};
Index: 

[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-06-25 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

>> -fsanitize=array-bounds workaround for size-1 array as the last member of a 
>> structure

Could you provide option for that (to enable stricker bound checks introduced 
with this patch) ?


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

https://reviews.llvm.org/D126864

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