[PATCH] D137894: [clangd] Add extension for adding context (enclosing function or class) in references results

2022-12-31 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

LGTM, and it looks like Sam's comments have been substantially addressed as 
well, so I'm going to go ahead and approve this, hope that's cool.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137894

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


[PATCH] D140795: [Flang] Add user option -funderscoring/-fnounderscoring to enable/disable ExternalNameConversionPass

2022-12-31 Thread Valentin Clement via Phabricator via cfe-commits
clementval requested changes to this revision.
clementval added a comment.
This revision now requires changes to proceed.

You need to update the driver-help tests.




Comment at: flang/include/flang/Tools/CLOptions.inc:194
 #if !defined(FLANG_EXCLUDE_CODEGEN)
-inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm) {
+inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm, bool 
Underscoring = 1) {
   fir::addBoxedProcedurePass(pm);

Please follow the same formatting in this file. 



Comment at: flang/include/flang/Tools/CLOptions.inc:213
+inline void createMLIRToLLVMPassPipeline(mlir::PassManager &pm,
+llvm::OptimizationLevel optLevel = defaultOptLevel, bool Underscoring = 1) 
{
   // Add default optimizer pass pipeline.

Doesn't follow the formatting here. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140795

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


[PATCH] D140775: [clangd] Hover: show CalleeArgInfo for literals

2022-12-31 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:779
 
-HoverInfo getStringLiteralContents(const StringLiteral *SL,
-   const PrintingPolicy &PP) {
-  HoverInfo HI;
-
+void addStringLiteralContents(const StringLiteral *SL, const PrintingPolicy 
&PP,
+  HoverInfo &HI) {

nit: "contents" seems a bit strange now that this is no longer necessarily the 
entirety of the hover contents (nor is it the string literal's contents)

maybe name it `addStringLiteralInfo`?



Comment at: clang-tools-extra/clangd/Hover.cpp:826
+if (const StringLiteral *SL = dyn_cast(E)) {
+  addStringLiteralContents(SL, PP, HI);
+  return HI;

nit: for consistency with non-literal expressions, maybe the CalleeArgInfo 
should come //after// the other contents of the hover?



Comment at: clang-tools-extra/clangd/Hover.cpp:830
+if (HI.CalleeArgInfo) {
+  HI.Name = "literal";
+  return HI;

tom-anders wrote:
> `HoverInfo::present` has an assertion that the `Name` has to be non-empty. 
> I'm open for other name suggestions here (Or we could of course adjust 
> `HoverInfo::present` instead)
It at least seems no worse than `"expression"` for other expressions.

I think the expression's value would be more useful (and despite the "not much 
value" comment above, I think there //can// be value in showing this if e.g. 
the expression is written as hex and the hover shows you the decimal value), 
but that can be left for a later change.



Comment at: clang-tools-extra/clangd/Hover.cpp:843
   // evaluatable.
   if (auto Val = printExprValue(E, AST.getASTContext())) {
 HI.Type = printType(E->getType(), AST.getASTContext(), PP);

Any reason not to also add CalleeArgInfo in this branch?

I know this branch is not for literals so I'm suggesting to expand the scope of 
the patch, feel free to leave this for later, but conceptually I don't see why 
the CalleeArgInfo would be any less useful for non-literal expressions that 
take this branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140775

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


[PATCH] D140775: [clangd] Hover: show CalleeArgInfo for literals

2022-12-31 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders updated this revision to Diff 485761.
tom-anders marked 4 inline comments as done.
tom-anders added a comment.

Refactor getHoverContents to add CalleeArgInfo for all kinds of expression


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140775

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -900,6 +900,22 @@
  HI.CalleeArgInfo->Type = "int &";
  HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
}},
+  {// Literal passed to function call
+   R"cpp(
+  void fun(int arg_a, const int &arg_b) {};
+  void code() {
+int a = 1;
+fun(a, [[^2]]);
+  }
+  )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "literal";
+ HI.Kind = index::SymbolKind::Unknown;
+ HI.CalleeArgInfo.emplace();
+ HI.CalleeArgInfo->Name = "arg_b";
+ HI.CalleeArgInfo->Type = "const int &";
+ HI.CallPassType = HoverInfo::PassType{PassMode::ConstRef, false};
+   }},
   {// Extra info for method call.
R"cpp(
   class C {
@@ -1226,8 +1242,10 @@
   } Tests[] = {
   // Integer tests
   {"int_by_value([[^int_x]]);", PassMode::Value, false},
+  {"int_by_value([[^123]]);", PassMode::Value, false},
   {"int_by_ref([[^int_x]]);", PassMode::Ref, false},
   {"int_by_const_ref([[^int_x]]);", PassMode::ConstRef, false},
+  {"int_by_const_ref([[^123]]);", PassMode::ConstRef, false},
   {"int_by_value([[^int_ref]]);", PassMode::Value, false},
   {"int_by_const_ref([[^int_ref]]);", PassMode::ConstRef, false},
   {"int_by_const_ref([[^int_ref]]);", PassMode::ConstRef, false},
@@ -1245,6 +1263,8 @@
   {"float_by_value([[^int_x]]);", PassMode::Value, true},
   {"float_by_value([[^int_ref]]);", PassMode::Value, true},
   {"float_by_value([[^int_const_ref]]);", PassMode::Value, true},
+  {"float_by_value([[^123.0f]]);", PassMode::Value, false},
+  {"float_by_value([[^123]]);", PassMode::Value, true},
   {"custom_by_value([[^int_x]]);", PassMode::Ref, true},
   {"custom_by_value([[^float_x]]);", PassMode::Value, true},
   {"custom_by_value([[^base]]);", PassMode::ConstRef, true},
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -795,7 +795,7 @@
  llvm::isa(E) ||
  llvm::isa(E) || llvm::isa(E) ||
  llvm::isa(E) || llvm::isa(E) ||
- llvm::isa(E);
+ llvm::isa(E) || llvm::isa(E);
 }
 
 llvm::StringLiteral getNameForExpr(const Expr *E) {
@@ -809,34 +809,53 @@
   return llvm::StringLiteral("expression");
 }
 
+void maybeAddCalleeArgInfo(const SelectionTree::Node *N, HoverInfo &HI,
+   const PrintingPolicy &PP);
+
 // Generates hover info for `this` and evaluatable expressions.
 // FIXME: Support hover for literals (esp user-defined)
-std::optional getHoverContents(const Expr *E, ParsedAST &AST,
+std::optional getHoverContents(const SelectionTree::Node *N,
+  const Expr *E, ParsedAST &AST,
   const PrintingPolicy &PP,
   const SymbolIndex *Index) {
-  // There's not much value in hovering over "42" and getting a hover card
-  // saying "42 is an int", similar for other literals.
-  if (isLiteral(E))
+  std::optional HI;
+
+  if (const StringLiteral *SL = dyn_cast(E)) {
+// Print the type and the size for string literals
+HI = getStringLiteralContents(SL, PP);
+  } else if (isLiteral(E)) {
+// There's not much value in hovering over "42" and getting a hover card
+// saying "42 is an int", similar for most other literals.
+// However, if we have CalleeArgInfo, it's still useful to show it.
+maybeAddCalleeArgInfo(N, HI.emplace(), PP);
+if (HI->CalleeArgInfo) {
+  // FIXME Might want to show the expression's value here instead?
+  // E.g. if the literal is in hex it might be useful to show the decimal
+  // value here.
+  HI->Name = "literal";
+  return HI;
+}
 return std::nullopt;
+  }
 
-  HoverInfo HI;
-  // Print the type and the size for string literals
-  if (const StringLiteral *SL = dyn_cast(E))
-return getStringLiteralContents(SL, PP);
   // For `this` expr we currently generate hover with pointee type.
   if (const CXXThisExpr *CTE = dyn_cast(E))
-return getThisExprHoverContents(CTE, AST.getASTContext(), PP);
+HI = getThisExprHoverContents(CTE, AST.getASTContext(), PP);
   if (co

[PATCH] D140775: [clangd] Hover: show CalleeArgInfo for literals

2022-12-31 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:779
 
-HoverInfo getStringLiteralContents(const StringLiteral *SL,
-   const PrintingPolicy &PP) {
-  HoverInfo HI;
-
+void addStringLiteralContents(const StringLiteral *SL, const PrintingPolicy 
&PP,
+  HoverInfo &HI) {

nridge wrote:
> nit: "contents" seems a bit strange now that this is no longer necessarily 
> the entirety of the hover contents (nor is it the string literal's contents)
> 
> maybe name it `addStringLiteralInfo`?
Changed back to the previous signature in current patch version



Comment at: clang-tools-extra/clangd/Hover.cpp:830
+if (HI.CalleeArgInfo) {
+  HI.Name = "literal";
+  return HI;

nridge wrote:
> tom-anders wrote:
> > `HoverInfo::present` has an assertion that the `Name` has to be non-empty. 
> > I'm open for other name suggestions here (Or we could of course adjust 
> > `HoverInfo::present` instead)
> It at least seems no worse than `"expression"` for other expressions.
> 
> I think the expression's value would be more useful (and despite the "not 
> much value" comment above, I think there //can// be value in showing this if 
> e.g. the expression is written as hex and the hover shows you the decimal 
> value), but that can be left for a later change.
Added a FIXME for that



Comment at: clang-tools-extra/clangd/Hover.cpp:843
   // evaluatable.
   if (auto Val = printExprValue(E, AST.getASTContext())) {
 HI.Type = printType(E->getType(), AST.getASTContext(), PP);

nridge wrote:
> Any reason not to also add CalleeArgInfo in this branch?
> 
> I know this branch is not for literals so I'm suggesting to expand the scope 
> of the patch, feel free to leave this for later, but conceptually I don't see 
> why the CalleeArgInfo would be any less useful for non-literal expressions 
> that take this branch.
Good point, I refactored the logic here a bit, now CalleeArgInfo is added for 
this branch, and also the two branches above. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140775

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


[PATCH] D140800: Precompute OptTable prefixes union table through tablegen

2022-12-31 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added a reviewer: nikic.
Herald added subscribers: pmatos, asb, jhenderson, ormris, mstorsjo, steven_wu, 
hiraditya, arichardson, sbc100, emaste.
Herald added a reviewer: JDevlieghere.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
serge-sans-paille requested review of this revision.
Herald added subscribers: llvm-commits, lldb-commits, cfe-commits, StephenFan, 
aheejin.
Herald added projects: clang, LLDB, LLVM.

This avoid rediscovering this table when reading each options, providing
a sensible 2% speedup when processing and empty file, and a measurable
speedup on typical workloads, see:

https://llvm-compile-time-tracker.com/compare.php?from=4da6cb3202817ee2897d6b690e4af950459caea4&to=dffbe8638a92bfc73dff5494144d5ef9a73c0acc&stat=instructions:u


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140800

Files:
  clang/lib/Driver/DriverOptions.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  lld/COFF/DriverUtils.cpp
  lld/ELF/DriverUtils.cpp
  lld/MachO/DriverUtils.cpp
  lld/MinGW/Driver.cpp
  lld/wasm/Driver.cpp
  lldb/tools/driver/Driver.cpp
  lldb/tools/lldb-server/lldb-gdbserver.cpp
  lldb/tools/lldb-vscode/lldb-vscode.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.cpp
  llvm/lib/Option/OptTable.cpp
  llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp
  llvm/tools/llvm-ifs/llvm-ifs.cpp
  llvm/tools/llvm-lipo/llvm-lipo.cpp
  llvm/tools/llvm-ml/llvm-ml.cpp
  llvm/tools/llvm-mt/llvm-mt.cpp
  llvm/tools/llvm-nm/llvm-nm.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/tools/llvm-objdump/llvm-objdump.cpp
  llvm/tools/llvm-rc/llvm-rc.cpp
  llvm/tools/llvm-readobj/llvm-readobj.cpp
  llvm/tools/llvm-size/llvm-size.cpp
  llvm/tools/llvm-strings/llvm-strings.cpp
  llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
  llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
  llvm/unittests/Option/OptionParsingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -237,8 +237,14 @@
   CurPrefix = NewPrefix;
   }
 
-  // Dump prefixes.
+  DenseSet PrefixesUnionSet;
+  for (const auto &Prefix : Prefixes)
+PrefixesUnionSet.insert(Prefix.first.begin(), Prefix.first.end());
+  SmallVector PrefixesUnion(PrefixesUnionSet.begin(),
+   PrefixesUnionSet.end());
+  array_pod_sort(PrefixesUnion.begin(), PrefixesUnion.end());
 
+  // Dump prefixes.
   OS << "/\n";
   OS << "// Prefixes\n\n";
   OS << "#ifdef PREFIX\n";
@@ -259,6 +265,20 @@
   OS << "#undef COMMA\n";
   OS << "#endif // PREFIX\n\n";
 
+  // Dump prefix unions.
+  OS << "/\n";
+  OS << "// Prefix Union\n\n";
+  OS << "#ifdef PREFIX_UNION\n";
+  OS << "#define COMMA ,\n";
+  OS << "PREFIX_UNION({\n";
+  for (const auto &Prefix : PrefixesUnion) {
+OS << "llvm::StringLiteral(\"" << Prefix << "\") COMMA ";
+  }
+  OS << "llvm::StringLiteral(\"\")})\n";
+  OS << "#undef COMMA\n";
+  OS << "#endif // PREFIX_UNION\n\n";
+
+  // Dump groups.
   OS << "/\n";
   OS << "// ValuesCode\n\n";
   OS << "#ifdef OPTTABLE_VALUES_CODE\n";
Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -32,6 +32,14 @@
 #include "Opts.inc"
 #undef PREFIX
 
+static constexpr const StringLiteral PrefixTable_init[] =
+#define PREFIX_UNION(VALUES) VALUES
+#include "Opts.inc"
+#undef PREFIX_UNION
+;
+static constexpr const ArrayRef
+PrefixTable(PrefixTable_init, std::size(PrefixTable_init) - 1);
+
 enum OptionFlags {
   OptFlag1 = (1 << 4),
   OptFlag2 = (1 << 5),
@@ -51,7 +59,7 @@
 class TestOptTable : public OptTable {
 public:
   TestOptTable(bool IgnoreCase = false)
-: OptTable(InfoTable, IgnoreCase) {}
+  : OptTable(InfoTable, PrefixTable, IgnoreCase) {}
 };
 }
 
Index: llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
===
--- llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
+++ llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
@@ -42,6 +42,14 @@
 #include "Opts.inc"
 #undef PREFIX
 
+static constexpr const StringLiteral PrefixTable_init[] =
+#define PREFIX_UNION(VALUES) VALUES
+#include "Opts.inc"
+#undef PREFIX_UNION
+;
+static constexpr const ArrayRef
+PrefixTable(PrefixTable_init, std

[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-31 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

I think it would be better to have a meeting to discuss this further instead of 
posting in this review. I propose to do it after everybody's back from their 
holidays. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

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


[PATCH] D137894: [clangd] Add extension for adding context (enclosing function or class) in references results

2022-12-31 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

Thanks both of you for reviewing!

I added documentation to the website here: 
https://github.com/llvm/clangd-www/pull/77


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137894

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


[PATCH] D140668: [clang][Interp] Implement remaining bits for MaterializeTemporaryExprs

2022-12-31 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 485769.

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

https://reviews.llvm.org/D140668

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/literals.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -50,9 +50,6 @@
 static_assert(ints2.b == -30, "");
 static_assert(!ints2.c, "");
 
-#if __cplusplus >= 201703L
-// FIXME: In c++14, this uses a MaterializeTemporaryExpr,
-//   which the new interpreter doesn't support yet.
 constexpr Ints getInts() {
   return {64, 128, true};
 }
@@ -60,7 +57,6 @@
 static_assert(ints3.a == 64, "");
 static_assert(ints3.b == 128, "");
 static_assert(ints3.c, "");
-#endif
 
 constexpr Ints ints4 = {
   .a = 40 * 50,
@@ -88,9 +84,9 @@
   int a = 10;
   int b;
 };
-// FIXME: Broken in the new constant interpreter.
-//   Should be rejected, but without asan errors.
-//constexpr Ints2 ints2;
+constexpr Ints2 ints22; // expected-error {{without a user-provided default constructor}} \
+// expected-error {{must be initialized by a constant expression}} \
+// ref-error {{without a user-provided default constructor}}
 
 class C {
   public:
@@ -124,9 +120,6 @@
 }
 static_assert(getPointer()->a == 100, "");
 
-#if __cplusplus >= 201703L
-// FIXME: In c++14, this uses a MaterializeTemporaryExpr,
-//   which the new interpreter doesn't support yet.
 constexpr C RVOAndParams(const C *c) {
   return C();
 }
@@ -137,7 +130,6 @@
   return C();
 }
 constexpr C RVOAndParamsResult2 = RVOAndParams(12);
-#endif
 
 class Bar { // expected-note {{definition of 'Bar' is not complete}} \
 // ref-note {{definition of 'Bar' is not complete}}
@@ -158,16 +150,16 @@
   c.a = 10;
 
   // Assignment, not an initializer.
-  // c = C(); FIXME
+  c = C();
   c.a = 10;
 
 
   // Assignment, not an initializer.
-  //c = RVOAndParams(&c); FIXME
+  c = RVOAndParams(&c);
 
   return c.a;
 }
-static_assert(locals() == 10, "");
+static_assert(locals() == 100, "");
 
 namespace thisPointer {
   struct S {
@@ -234,10 +226,7 @@
 this->a; // expected-warning {{expression result unused}} \
  // ref-warning {{expression result unused}}
 get5();
-#if __cplusplus >= 201703L
-// FIXME: Enable once we support MaterializeConstantExpr properly.
 getInts();
-#endif
   }
 
   constexpr int m() const {
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -665,3 +665,27 @@
   // ref-note {{in call to 'IntMul}}
 };
 #endif
+
+namespace CompoundLiterals {
+  constexpr int get5() {
+return (int[]){1,2,3,4,5}[4];
+  }
+  static_assert(get5() == 5, "");
+
+  constexpr int get6(int f = (int[]){1,2,6}[2]) { // ref-note {{subexpression not valid in a constant expression}} \
+  // ref-note {{declared here}}
+return f;
+  }
+  static_assert(get6(6) == 6, "");
+  // FIXME: Who's right here?
+  static_assert(get6() == 6, ""); // ref-error {{not an integral constant expression}}
+
+#if __cplusplus >= 202002L
+  constexpr int get3() {
+int m;
+m = (int){3};
+return m;
+  }
+  static_assert(get3() == 3, "");
+#endif
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -88,6 +88,7 @@
   bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
+  bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
@@ -385,7 +386,10 @@
   BlockScope(ByteCodeExprGen *Ctx) : LocalScope(Ctx) {}
 
   void addExtended(const Scope::Local &Local) override {
-llvm_unreachable("Cannot create temporaries in full scopes");
+// If we to this point, just add the variable as a normal local
+// variable. It will be destroyed at the end of the block just
+// like all others.
+this->addLocal(Local);
   }
 };
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -736,19 +736,10 @@
 template 
 bool ByteCodeExprGen::VisitMaterializeTemporaryExpr(
 const MaterializeTemporaryExpr *E) {
-  StorageDuration SD = E->getStorageDuration();
-
-  // We conservatively only support these for now.
-  if (SD != SD_Static && SD != SD_Automa

[PATCH] D140803: [clang][Interp] Implement C++ Range-for loops

2022-12-31 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140803

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/test/AST/Interp/loops.cpp

Index: clang/test/AST/Interp/loops.cpp
===
--- clang/test/AST/Interp/loops.cpp
+++ clang/test/AST/Interp/loops.cpp
@@ -274,3 +274,48 @@
 #endif
 
 };
+
+namespace RangeForLoop {
+  constexpr int localArray() {
+int a[] = {1,2,3,4};
+int s = 0;
+for(int i : a) {
+  s += i;
+}
+return s;
+  }
+  static_assert(localArray() == 10, "");
+
+  constexpr int localArray2() {
+int a[] = {1,2,3,4};
+int s = 0;
+for(const int &i : a) {
+  s += i;
+}
+return s;
+  }
+  static_assert(localArray2() == 10, "");
+
+  constexpr int nested() {
+int s = 0;
+for (const int i : (int[]){1,2,3,4}) {
+  int a[] = {i, i};
+  for(int m : a) {
+s += m;
+  }
+}
+return s;
+  }
+  static_assert(nested() == 20, "");
+
+  constexpr int withBreak() {
+int s = 0;
+for (const int &i: (bool[]){false, true}) {
+  if (i)
+break;
+  s++;
+}
+return s;
+  }
+  static_assert(withBreak() == 1, "");
+}
Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -60,6 +60,7 @@
   bool visitWhileStmt(const WhileStmt *S);
   bool visitDoStmt(const DoStmt *S);
   bool visitForStmt(const ForStmt *S);
+  bool visitCXXForRangeStmt(const CXXForRangeStmt *S);
   bool visitBreakStmt(const BreakStmt *S);
   bool visitContinueStmt(const ContinueStmt *S);
   bool visitSwitchStmt(const SwitchStmt *S);
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -172,6 +172,8 @@
 return visitDoStmt(cast(S));
   case Stmt::ForStmtClass:
 return visitForStmt(cast(S));
+  case Stmt::CXXForRangeStmtClass:
+return visitCXXForRangeStmt(cast(S));
   case Stmt::BreakStmtClass:
 return visitBreakStmt(cast(S));
   case Stmt::ContinueStmtClass:
@@ -369,6 +371,59 @@
   return true;
 }
 
+template 
+bool ByteCodeStmtGen::visitCXXForRangeStmt(const CXXForRangeStmt *S) {
+  const Stmt *Init = S->getInit();
+  const Expr *Cond = S->getCond();
+  const Expr *Inc = S->getInc();
+  const Stmt *Body = S->getBody();
+  const Stmt *BeginStmt = S->getBeginStmt();
+  const Stmt *RangeStmt = S->getRangeStmt();
+  const Stmt *EndStmt = S->getEndStmt();
+  const VarDecl *LoopVar = S->getLoopVariable();
+
+  LabelTy EndLabel = this->getLabel();
+  LabelTy CondLabel = this->getLabel();
+  LabelTy IncLabel = this->getLabel();
+  ExprScope ES(this);
+  LoopScope LS(this, EndLabel, IncLabel);
+
+  // Emit declarations needed in the loop.
+  if (Init && !this->visitStmt(Init))
+return false;
+  if (!this->visitStmt(RangeStmt))
+return false;
+  if (!this->visitStmt(BeginStmt))
+return false;
+  if (!this->visitStmt(EndStmt))
+return false;
+
+  // Now the condition as well as the loop variable assignment.
+  this->emitLabel(CondLabel);
+
+  if (Cond) {
+if (!this->visitBool(Cond))
+  return false;
+if (!this->jumpFalse(EndLabel))
+  return false;
+  }
+
+  if (!this->visitVarDecl(LoopVar))
+return false;
+
+  // Body.
+  if (Body && !this->visitStmt(Body))
+return false;
+  this->emitLabel(IncLabel);
+  if (Inc && !this->discard(Inc))
+return false;
+  if (!this->jump(CondLabel))
+return false;
+
+  this->emitLabel(EndLabel);
+  return true;
+}
+
 template 
 bool ByteCodeStmtGen::visitBreakStmt(const BreakStmt *S) {
   if (!BreakLabel)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D91000: [clang-tidy] Add bugprone-unsafe-functions checker.

2022-12-31 Thread Fütő Gergely via Phabricator via cfe-commits
futogergely updated this revision to Diff 485774.
futogergely marked 5 inline comments as done.
futogergely removed a reviewer: ktomi996.
futogergely added a comment.

Addressing review comments.


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

https://reviews.llvm.org/D91000

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unsafe-functions.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c
@@ -0,0 +1,155 @@
+// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K%s bugprone-unsafe-functions %t -- -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__   -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -D__STDC_LIB_EXT1__=1 -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__   -D__STDC_WANT_LIB_EXT1__=1
+// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K-CERT-ONLY  %s bugprone-unsafe-functions %t -- \
+// RUN:   -config="{CheckOptions: [{key: bugprone-unsafe-functions.ReportMoreUnsafeFunctions, value: false}]}" \
+// RUN:-- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
+
+typedef __SIZE_TYPE__ size_t;
+typedef char wchar_t;
+
+char *gets(char *s);
+size_t strlen(const char *s);
+size_t wcslen(const wchar_t *s);
+
+void f1(char *s) {
+  gets(s);
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:3: warning: function 'gets' is insecure, and it is removed from C11; 'gets_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'gets' is insecure, and it is removed from C11; 'gets_s' should be used instead
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K::[[@LINE-3]]:3: warning: function 'gets' is insecure, and it is removed from C11; 'fgets' should be used instead
+
+  strlen(s);
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:3: warning: function 'strlen' is not bounds-checking; 'strnlen_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'strlen' is not bounds-checking; 'strnlen_s' should be used instead
+  // no-warning WITHOUT-ANNEX-K
+
+  wcslen(s);
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:3: warning: function 'wcslen' is not bounds-checking; 'wcsnlen_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'wcslen' is not bounds-checking; 'wcsnlen_s' should be used instead
+  // no-warning WITHOUT-ANNEX-K
+}
+
+struct tm;
+char *asctime(const struct tm *timeptr);
+
+void f2(const struct tm *timeptr) {
+  asctime(timeptr);
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:3: warning: function 'asctime' is not bounds-checking and non-reentrant; 'asctime_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'asctime' is not bounds-checking and non-reentrant; 'asctime_s' should be used instead
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K::[[@LINE-3]]:3: warning: function 'asctime' is not bounds-checking and non-reentrant; 'strftime' should be used instead
+
+  char *(*f_ptr1)(const struct tm *) = asctime;
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:40: warning: function 'asctime' is not bounds-checking and non-reentrant; 'asctime_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:40: warning: function 'asctime' is not bounds-checking and non-reentrant; 'asctime_s' should be used instead
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K::[[@LINE-3]]:40: warning: function 'asctime' is not bounds-checking and non-reentrant; 'strftime' should be used instead
+
+  char *(*f_ptr2)(const struct tm *) = &asctime;
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:41: warning: function 'asctime' is not bounds-checking and non-reentrant; 'asctime_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:41: warning: function 'asctime' is not bounds-checking and non-reentrant; 'asctime_s' should be used instead
+  // CHECK-MESSAGES-WITHOUT-ANNEX

[PATCH] D91000: [clang-tidy] Add bugprone-unsafe-functions checker.

2022-12-31 Thread Fütő Gergely via Phabricator via cfe-commits
futogergely added a comment.

In D91000#3862210 , @whisperity wrote:

> In D91000#3861942 , @aaron.ballman 
> wrote:
>
>> My concern with that approach was that we pay the full expense of doing the 
>> matches only get get into the `check()` function to bail out on all the 
>> Annex K functions, but now that there are replacements outside of Annex K, I 
>> don't see a way around paying that expense, so I think my concern has been 
>> addressed as well as it could have been.
>
> I think that Clang-Tidy checks are instantiated per AST. I will look into 
> whether we can somehow do the disabling of the check as early as possible! 
> (In that case, we could simply NOT register the matcher related to Annex-K 
> functions.) Either way, I'll do a rebase, re-run the tests and etc., and 
> likely take over the check.

I checked, and I think that at the point of ClangTidyCheck::registerMatchers 
the preprocessor has not been executed yet... (and we need the value of macros 
__STDC_LIB_EXT1__ and __STDC_WANT_LIB_EXT1__ to decide if we need to register 
some matchers or not) @whisperity could you maybe double-check it please?
What we could do is:

1. add a new checker option to decide if we suggest replacements from AnnexK. 
We could avoid registering matchers this way, but I don't really like this, 
having an option for something we could decide from the defined macros.
2. As a TODO, we could make possible to register checkers AFTER the 
preprocessor is executed. I have not looked into this, so I don't really know 
if it is possible at all in the current architecture.


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

https://reviews.llvm.org/D91000

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


[PATCH] D140805: [clang][Interp] Add ArrayElemPtr{,Pop} opcode

2022-12-31 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  We usually access array elements in the same pattern, which uses
  narrow(). Add an extra opcode for this. This saves us quite some
  instructions and makes the bytecode easier to read.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140805

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td

Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -300,6 +300,9 @@
 def NarrowPtr : Opcode;
 // [Pointer] -> [Pointer]
 def ExpandPtr : Opcode;
+// [Pointer, Offset] -> [Pointer]
+def ArrayElemPtr : AluOpcode;
+def ArrayElemPtrPop : AluOpcode;
 
 //===--===//
 // Direct field accessors
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1369,6 +1369,36 @@
   return true;
 }
 
+// 1) Pops an integral value from the stack
+// 2) Peeks a pointer
+// 3) Pushes a new pointer that's a narrowed array
+//   element of the peeked pointer with the value
+//   from 1) added as offset.
+//
+// This leaves the original pointer on the stack and pushes a new one
+// with the offset applied and narrowed.
+template ::T>
+inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) {
+  const T &Offset = S.Stk.pop();
+  const Pointer &Ptr = S.Stk.peek();
+
+  if (!OffsetHelper(S, OpPC, Offset, Ptr))
+return false;
+
+  return NarrowPtr(S, OpPC);
+}
+
+template ::T>
+inline bool ArrayElemPtrPop(InterpState &S, CodePtr OpPC) {
+  const T &Offset = S.Stk.pop();
+  const Pointer &Ptr = S.Stk.pop();
+
+  if (!OffsetHelper(S, OpPC, Offset, Ptr))
+return false;
+
+  return NarrowPtr(S, OpPC);
+}
+
 inline bool CheckGlobalCtor(InterpState &S, CodePtr &PC) {
   const Pointer &Obj = S.Stk.peek();
   return CheckCtorCall(S, PC, Obj);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -365,7 +365,7 @@
   const Expr *Index = E->getIdx();
   PrimType IndexT = classifyPrim(Index->getType());
 
-  // Take pointer of LHS, add offset from RHS, narrow result.
+  // Take pointer of LHS, add offset from RHS.
   // What's left on the stack after this is a pointer.
   if (!this->visit(Base))
 return false;
@@ -373,10 +373,7 @@
   if (!this->visit(Index))
 return false;
 
-  if (!this->emitAddOffset(IndexT, E))
-return false;
-
-  if (!this->emitNarrowPtr(E))
+  if (!this->emitArrayElemPtrPop(IndexT, E))
 return false;
 
   if (DiscardResult)
@@ -1115,16 +1112,11 @@
   return false;
   } else {
 // Advance the pointer currently on the stack to the given
-// dimension and narrow().
-if (!this->emitDupPtr(Init))
-  return false;
+// dimension.
 if (!this->emitConstUint32(ElementIndex, Init))
   return false;
-if (!this->emitAddOffsetUint32(Init))
+if (!this->emitArrayElemPtrUint32(Init))
   return false;
-if (!this->emitNarrowPtr(Init))
-  return false;
-
 if (!visitInitializer(Init))
   return false;
 if (!this->emitPopPtr(Init))
@@ -1150,31 +1142,22 @@
 for (size_t I = 0; I != Size; ++I) {
   ArrayIndexScope IndexScope(this, I);
 
-  if (!this->emitDupPtr(SubExpr)) // LHS
-return false;
-
   if (ElemT) {
 if (!this->visit(SubExpr))
   return false;
 if (!this->emitInitElem(*ElemT, I, Initializer))
   return false;
   } else {
-// Narrow to our array element and recurse into visitInitializer()
+// Get to our array element and recurse into visitInitializer()
 if (!this->emitConstUint64(I, SubExpr))
   return false;
-
-if (!this->emitAddOffsetUint64(SubExpr))
-  return false;
-
-if (!this->emitNarrowPtr(SubExpr))
+if (!this->emitArrayElemPtrUint64(SubExpr))
   return false;
-
 if (!visitInitializer(SubExpr))
   return false;
+if (!this->emitPopPtr(Initializer))
+  return false;
   }
-
-  if (!this->emitPopPtr(Initializer))
-return false;
 }
 return true;
   } else if (const auto *IVIE = dyn_cast(Initializer)) {
@@ -1210,13 +1193,9 @@
 // FIXME(perf): We're calling the constructor once per array element here,
 //   in the old intepreter we had a special-case for trivial constructors.
 for (size_t I = 0; I != NumElems; 

[PATCH] D140807: [clang][Interp] Skip calling simple destructors

2022-12-31 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Calling them isn't needed if I understand correctly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140807

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.h


Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -364,14 +364,16 @@
   if (!RDecl)
 continue;
 
-  if (const auto *DtorDecl = RDecl->getDestructor()) {
-const Function *Dtor = this->Ctx->getFunction(DtorDecl);
-if (Dtor && Dtor->isConstexpr()) {
-  assert(Dtor->hasThisPointer());
-  assert(Dtor->getNumParams() == 1);
-  // Emit destructor call.
-  this->Ctx->emitGetPtrLocal(Local.Offset, DtorDecl);
-  this->Ctx->emitCall(Dtor, DtorDecl);
+  if (!RDecl->hasSimpleDestructor()) {
+if (const auto *DtorDecl = RDecl->getDestructor()) {
+  const Function *Dtor = this->Ctx->getFunction(DtorDecl);
+  if (Dtor && Dtor->isConstexpr()) {
+assert(Dtor->hasThisPointer());
+assert(Dtor->getNumParams() == 1);
+// Emit destructor call.
+this->Ctx->emitGetPtrLocal(Local.Offset, DtorDecl);
+this->Ctx->emitCall(Dtor, DtorDecl);
+  }
 }
   }
 }


Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -364,14 +364,16 @@
   if (!RDecl)
 continue;
 
-  if (const auto *DtorDecl = RDecl->getDestructor()) {
-const Function *Dtor = this->Ctx->getFunction(DtorDecl);
-if (Dtor && Dtor->isConstexpr()) {
-  assert(Dtor->hasThisPointer());
-  assert(Dtor->getNumParams() == 1);
-  // Emit destructor call.
-  this->Ctx->emitGetPtrLocal(Local.Offset, DtorDecl);
-  this->Ctx->emitCall(Dtor, DtorDecl);
+  if (!RDecl->hasSimpleDestructor()) {
+if (const auto *DtorDecl = RDecl->getDestructor()) {
+  const Function *Dtor = this->Ctx->getFunction(DtorDecl);
+  if (Dtor && Dtor->isConstexpr()) {
+assert(Dtor->hasThisPointer());
+assert(Dtor->getNumParams() == 1);
+// Emit destructor call.
+this->Ctx->emitGetPtrLocal(Local.Offset, DtorDecl);
+this->Ctx->emitCall(Dtor, DtorDecl);
+  }
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7a8cb6c - [clang][NFC] Fix warning due to initializing a pointer with `false`

2022-12-31 Thread Markus Böck via cfe-commits

Author: Markus Böck
Date: 2022-12-31T18:07:03+01:00
New Revision: 7a8cb6cd4e3ff8aaadebff2b9d3ee9e2a326d444

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

LOG: [clang][NFC] Fix warning due to initializing a pointer with `false`

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index efc3274ce7d3c..d6ca63745f171 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9150,7 +9150,7 @@ ExprResult InitializationSequence::Perform(Sema &S,
   break;
 }
 case SK_ParenthesizedListInit: {
-  CurInit = false;
+  CurInit = nullptr;
   TryOrBuildParenListInitialization(S, Entity, Kind, Args, *this,
 /*VerifyOnly=*/false, &CurInit);
   if (CurInit.get() && ResultType)



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


[PATCH] D140808: [clang][Interp] Handle record initialization via CastExpr

2022-12-31 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In particular, via a `CXXFunctionalCastExpr`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140808

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -88,6 +88,10 @@
 // expected-error {{must be initialized by a constant 
expression}} \
 // ref-error {{without a user-provided default 
constructor}}
 
+constexpr Ints2 I2 = Ints2{12, 25};
+static_assert(I2.a == 12, "");
+static_assert(I2.b == 25, "");
+
 class C {
   public:
 int a;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1318,6 +1318,8 @@
 }
   } else if (const auto *DIE = dyn_cast(Initializer)) {
 return this->visitInitializer(DIE->getExpr());
+  } else if (const auto *CE = dyn_cast(Initializer)) {
+return this->visitInitializer(CE->getSubExpr());
   }
 
   return false;


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -88,6 +88,10 @@
 // expected-error {{must be initialized by a constant expression}} \
 // ref-error {{without a user-provided default constructor}}
 
+constexpr Ints2 I2 = Ints2{12, 25};
+static_assert(I2.a == 12, "");
+static_assert(I2.b == 25, "");
+
 class C {
   public:
 int a;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1318,6 +1318,8 @@
 }
   } else if (const auto *DIE = dyn_cast(Initializer)) {
 return this->visitInitializer(DIE->getExpr());
+  } else if (const auto *CE = dyn_cast(Initializer)) {
+return this->visitInitializer(CE->getSubExpr());
   }
 
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140793: [clang-tidy] Implement CppCoreGuideline CP.53

2022-12-31 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 485782.
ccotter added a comment.

- run clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140793

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.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-reference-coroutine-parameters.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp
@@ -0,0 +1,84 @@
+// RUN: %check_clang_tidy -std=c++20 %s cppcoreguidelines-avoid-reference-coroutine-parameters %t
+
+// NOLINTBEGIN
+namespace std {
+  template 
+  struct coroutine_traits {
+using promise_type = typename T::promise_type;
+  };
+  template 
+  struct coroutine_handle;
+  template <>
+  struct coroutine_handle {
+coroutine_handle() noexcept;
+coroutine_handle(decltype(nullptr)) noexcept;
+static constexpr coroutine_handle from_address(void*);
+  };
+  template 
+  struct coroutine_handle {
+coroutine_handle() noexcept;
+coroutine_handle(decltype(nullptr)) noexcept;
+static constexpr coroutine_handle from_address(void*);
+operator coroutine_handle<>() const noexcept;
+  };
+} // namespace std
+
+struct Awaiter {
+  bool await_ready() noexcept;
+  void await_suspend(std::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct Coro {
+  struct promise_type {
+Awaiter initial_suspend();
+Awaiter final_suspend() noexcept;
+void return_void();
+Coro get_return_object();
+void unhandled_exception();
+  };
+};
+// NOLINTEND
+
+struct Obj {};
+
+Coro no_args() {
+  co_return;
+}
+
+Coro no_references(int x, int* y, Obj z, const Obj w) {
+  co_return;
+}
+
+Coro accepts_references(int& x, const int &y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  co_return;
+}
+
+Coro accepts_references_and_non_references(int& x, int y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  co_return;
+}
+
+Coro accepts_references_to_objects(Obj& x) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  co_return;
+}
+
+Coro non_coro_accepts_references(int& x) {
+  if (x);
+  return Coro{};
+}
+
+void defines_a_lambda() {
+  auto NoArgs = [](int x) -> Coro { co_return; };
+
+  auto NoReferences = [](int x) -> Coro { co_return; };
+
+  auto WithReferences = [](int& x) -> Coro { co_return; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+
+  auto WithReferences2 = [](int&) -> Coro { co_return; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -182,6 +182,7 @@
`cppcoreguidelines-avoid-do-while `_,
`cppcoreguidelines-avoid-goto `_,
`cppcoreguidelines-avoid-non-const-global-variables `_,
+   `cppcoreguidelines-avoid-reference-coroutine-parameters `_, "Yes"
`cppcoreguidelines-init-variables `_, "Yes"
`cppcoreguidelines-interfaces-global-init `_,
`cppcoreguidelines-macro-usage `_,
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - cppcoreguidelines-avoid-reference-coroutine-parameters
+
+cppcoreguidelines-avoid-reference-coroutine-parameters
+==
+
+Warns w

[PATCH] D140793: [clang-tidy] Implement CppCoreGuideline CP.53

2022-12-31 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 485783.
ccotter added a comment.

- Does not offer fixes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140793

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.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-reference-coroutine-parameters.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp
@@ -0,0 +1,84 @@
+// RUN: %check_clang_tidy -std=c++20 %s cppcoreguidelines-avoid-reference-coroutine-parameters %t
+
+// NOLINTBEGIN
+namespace std {
+  template 
+  struct coroutine_traits {
+using promise_type = typename T::promise_type;
+  };
+  template 
+  struct coroutine_handle;
+  template <>
+  struct coroutine_handle {
+coroutine_handle() noexcept;
+coroutine_handle(decltype(nullptr)) noexcept;
+static constexpr coroutine_handle from_address(void*);
+  };
+  template 
+  struct coroutine_handle {
+coroutine_handle() noexcept;
+coroutine_handle(decltype(nullptr)) noexcept;
+static constexpr coroutine_handle from_address(void*);
+operator coroutine_handle<>() const noexcept;
+  };
+} // namespace std
+
+struct Awaiter {
+  bool await_ready() noexcept;
+  void await_suspend(std::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct Coro {
+  struct promise_type {
+Awaiter initial_suspend();
+Awaiter final_suspend() noexcept;
+void return_void();
+Coro get_return_object();
+void unhandled_exception();
+  };
+};
+// NOLINTEND
+
+struct Obj {};
+
+Coro no_args() {
+  co_return;
+}
+
+Coro no_references(int x, int* y, Obj z, const Obj w) {
+  co_return;
+}
+
+Coro accepts_references(int& x, const int &y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  co_return;
+}
+
+Coro accepts_references_and_non_references(int& x, int y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  co_return;
+}
+
+Coro accepts_references_to_objects(Obj& x) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  co_return;
+}
+
+Coro non_coro_accepts_references(int& x) {
+  if (x);
+  return Coro{};
+}
+
+void defines_a_lambda() {
+  auto NoArgs = [](int x) -> Coro { co_return; };
+
+  auto NoReferences = [](int x) -> Coro { co_return; };
+
+  auto WithReferences = [](int& x) -> Coro { co_return; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+
+  auto WithReferences2 = [](int&) -> Coro { co_return; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -182,6 +182,7 @@
`cppcoreguidelines-avoid-do-while `_,
`cppcoreguidelines-avoid-goto `_,
`cppcoreguidelines-avoid-non-const-global-variables `_,
+   `cppcoreguidelines-avoid-reference-coroutine-parameters `_,
`cppcoreguidelines-init-variables `_, "Yes"
`cppcoreguidelines-interfaces-global-init `_,
`cppcoreguidelines-macro-usage `_,
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - cppcoreguidelines-avoid-reference-coroutine-parameters
+
+cppcoreguidelines-avoid-reference-coroutine-parameters
+==
+
+Warns whe

[PATCH] D140809: [clang][Interp] Implement logical and/or operators

2022-12-31 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140809

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/cond.cpp

Index: clang/test/AST/Interp/cond.cpp
===
--- clang/test/AST/Interp/cond.cpp
+++ clang/test/AST/Interp/cond.cpp
@@ -9,3 +9,29 @@
 return a - b;
   }
 }
+
+constexpr int dontCallMe(unsigned m) {
+  if (m == 0) return 0;
+  return dontCallMe(m - 2);
+}
+
+// Can't call this because it will run into infinite recursion.
+constexpr int assertNotReached() {
+  return dontCallMe(3);
+}
+
+static_assert(true || true, "");
+static_assert(true || false, "");
+static_assert(false || true, "");
+static_assert(!(false || false), "");
+
+static_assert(true || assertNotReached(), "");
+static_assert(true || true || true || false, "");
+
+static_assert(true && true, "");
+static_assert(!(true && false), "");
+static_assert(!(false && true), "");
+static_assert(!(false && false), "");
+
+static_assert(!(false && assertNotReached()), "");
+static_assert(!(true && true && true && false), "");
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -61,6 +61,7 @@
   bool VisitFloatingLiteral(const FloatingLiteral *E);
   bool VisitParenExpr(const ParenExpr *E);
   bool VisitBinaryOperator(const BinaryOperator *E);
+  bool VisitLogicalBinOp(const BinaryOperator *E);
   bool VisitPointerArithBinOp(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -203,6 +203,10 @@
 
 template 
 bool ByteCodeExprGen::VisitBinaryOperator(const BinaryOperator *BO) {
+  // Need short-circuiting for these.
+  if (BO->isLogicalOp())
+return this->VisitLogicalBinOp(BO);
+
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
@@ -286,8 +290,9 @@
 return Discard(this->emitShr(*LT, *RT, BO));
   case BO_Xor:
 return Discard(this->emitBitXor(*T, BO));
-  case BO_LAnd:
   case BO_LOr:
+  case BO_LAnd:
+llvm_unreachable("Already handled earlier");
   default:
 return this->bail(BO);
   }
@@ -345,6 +350,65 @@
   return this->bail(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitLogicalBinOp(const BinaryOperator *E) {
+  assert(E->isLogicalOp());
+  BinaryOperatorKind Op = E->getOpcode();
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+
+  if (Op == BO_LOr) {
+// Logical OR. Visit LHS and only evaluate RHS if LHS was FALSE.
+LabelTy LabelTrue = this->getLabel();
+LabelTy LabelEnd = this->getLabel();
+
+if (!this->visit(LHS))
+  return false;
+if (!this->jumpTrue(LabelTrue))
+  return false;
+
+if (!this->visit(RHS))
+  return false;
+if (!this->jump(LabelEnd))
+  return false;
+
+this->emitLabel(LabelTrue);
+this->emitConstBool(true, E);
+this->fallthrough(LabelEnd);
+this->emitLabel(LabelEnd);
+
+if (DiscardResult)
+  return this->emitPopBool(E);
+
+return true;
+  }
+
+  // Logical AND.
+  // Visit LHS. Only visit RHS is LHS was TRUE.
+  LabelTy LabelFalse = this->getLabel();
+  LabelTy LabelEnd = this->getLabel();
+
+  if (!this->visit(LHS))
+return false;
+  if (!this->jumpFalse(LabelFalse))
+return false;
+
+  if (!this->visit(RHS))
+return false;
+  if (!this->jump(LabelEnd))
+return false;
+
+  this->emitLabel(LabelFalse);
+  this->emitConstBool(false, E);
+  this->fallthrough(LabelEnd);
+  this->emitLabel(LabelEnd);
+
+  if (DiscardResult)
+return this->emitPopBool(E);
+
+  return true;
+}
+
 template 
 bool ByteCodeExprGen::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
   std::optional T = classify(E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140767: [clang-format] Require space before noexcept qualifier

2022-12-31 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

But please wait for at least one of the others.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140767

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


[PATCH] D140543: [clang-format] Add an option to format integer literal separators

2022-12-31 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp:81-82
+
+  llvm::SpecificBumpPtrAllocator Allocator;
+  auto Tok = new (Allocator.Allocate()) Token;
+  Lex->LexFromRawLexer(*Tok);

owenpan wrote:
> HazardyKnusperkeks wrote:
> > owenpan wrote:
> > > I should allocate memory for the `Token` object as shown but instead had 
> > > `Token Tok;` before.
> > But why? What is different?
> Thanks for asking! It made me find the real cause.
No problem! ;)


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

https://reviews.llvm.org/D140543

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


[clang] 89aad1e - Reland [clang-format] Add an option to format integer literal separators

2022-12-31 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2022-12-31T17:57:33-08:00
New Revision: 89aad1e6a397447f9574bb088f4de1d9044b5812

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

LOG: Reland [clang-format] Add an option to format integer literal separators

Previously committed in 46c94e5067b5 which was reverted in f0756e086010
due to a memory bug.

Closes #58949.

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

Added: 
clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
clang/lib/Format/IntegerLiteralSeparatorFixer.h
clang/unittests/Format/IntegerLiteralSeparatorTest.cpp

Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/CMakeLists.txt
clang/lib/Format/Format.cpp
clang/unittests/Format/CMakeLists.txt

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index cac0afe0bffcc..989c91e9a3efe 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3159,6 +3159,37 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+**IntegerLiteralSeparator** (``IntegerLiteralSeparatorStyle``) 
:versionbadge:`clang-format 16`
+  Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,
+  and JavaScript).
+
+  Nested configuration flags:
+
+  Separator format of integer literals of 
diff erent bases.
+  <0: Remove separators.
+   0: Leave the literal as is.
+  >0: Insert separators between digits, starting from the rightmost digit.
+
+  * ``int8_t Binary`` .. code-block:: c++
+
+   -1: 0b10001101
+0: 0b10011'11'0110'1
+3: 0b100'111'101'101
+4: 0b1001'1110'1101
+
+  * ``int8_t Decimal`` .. code-block:: c++
+
+   -1: 18446744073709550592ull
+0: 184467'440737'0'95505'92ull
+3: 18'446'744'073'709'550'592ull
+
+  * ``int8_t Hex`` .. code-block:: c++
+
+   -1: 0xDEADBEEFDEADBEEFuz
+0: 0xDEAD'BEEF'DE'AD'BEE'Fuz
+2: 0xDE'AD'BE'EF'DE'AD'BE'EFuz
+
+
 **JavaImportGroups** (``List of Strings``) :versionbadge:`clang-format 8`
   A vector of prefixes ordered by the desired groups for Java imports.
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 776f0a97d2500..a06f409d78d97 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -867,6 +867,8 @@ clang-format
 - Add ``RequiresExpressionIndentation`` option for configuring the alignment 
of requires-expressions.
   The default value of this option is ``OuterScope``, which 
diff ers in behavior from clang-format 15.
   To match the default behavior of clang-format 15, use the ``Keyword`` value.
+- Add ``IntegerLiteralSeparator`` option for fixing integer literal separators
+  in C++, C#, Java, and JavaScript.
 
 clang-extdef-mapping
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 8949520f87b01..9162028c53ede 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2450,6 +2450,37 @@ struct FormatStyle {
   /// \version 11
   TrailingCommaStyle InsertTrailingCommas;
 
+  /// Separator format of integer literals of 
diff erent bases.
+  /// <0: Remove separators.
+  ///  0: Leave the literal as is.
+  /// >0: Insert separators between digits, starting from the rightmost digit.
+  struct IntegerLiteralSeparatorStyle {
+/// \code
+///-1: 0b10001101
+/// 0: 0b10011'11'0110'1
+/// 3: 0b100'111'101'101
+/// 4: 0b1001'1110'1101
+/// \endcode
+int8_t Binary;
+/// \code
+///-1: 18446744073709550592ull
+/// 0: 184467'440737'0'95505'92ull
+/// 3: 18'446'744'073'709'550'592ull
+/// \endcode
+int8_t Decimal;
+/// \code
+///-1: 0xDEADBEEFDEADBEEFuz
+/// 0: 0xDEAD'BEEF'DE'AD'BEE'Fuz
+/// 2: 0xDE'AD'BE'EF'DE'AD'BE'EFuz
+/// \endcode
+int8_t Hex;
+  };
+
+  /// Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,
+  /// and JavaScript).
+  /// \version 16
+  IntegerLiteralSeparatorStyle IntegerLiteralSeparator;
+
   /// A vector of prefixes ordered by the desired groups for Java imports.
   ///
   /// One group's prefix can be a subset of another - the longest prefix is
@@ -4089,6 +4120,10 @@ struct FormatStyle {
IndentWidth == R.IndentWidth &&
IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
InsertBraces == R.InsertBraces &&
+   IntegerLiteralSeparator.Binary == R.IntegerLiteralSeparator.Binary 
&&
+   IntegerLiteralSeparator.Decimal ==
+   R.IntegerLiteralSeparator.Decimal &&
+   IntegerLiteralSeparator.Hex == R.IntegerLit

[PATCH] D140543: [clang-format] Add an option to format integer literal separators

2022-12-31 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG89aad1e6a397: Reland [clang-format] Add an option to format 
integer literal separators (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140543

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
  clang/lib/Format/IntegerLiteralSeparatorFixer.h
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/IntegerLiteralSeparatorTest.cpp

Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -0,0 +1,228 @@
+//===- unittest/Format/IntegerLiteralSeparatorTest.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 "clang/Format/Format.h"
+
+#include "../Tooling/ReplacementTest.h"
+#include "FormatTestUtils.h"
+
+#define DEBUG_TYPE "integer-literal-separator-test"
+
+namespace clang {
+namespace format {
+namespace {
+
+// TODO:
+// Refactor the class declaration, which is copied from BracesInserterTest.cpp.
+class IntegerLiteralSeparatorTest : public ::testing::Test {
+protected:
+  std::string format(llvm::StringRef Code, const FormatStyle &Style,
+ const std::vector &Ranges) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+auto NonEmptyRanges = Ranges;
+if (Ranges.empty())
+  NonEmptyRanges = {1, tooling::Range(0, Code.size())};
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, NonEmptyRanges, "", &Status);
+EXPECT_EQ(true, Status.FormatComplete) << Code << "\n\n";
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ const std::vector &Ranges = {}) {
+testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style, Ranges))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style, Ranges));
+if (Style.Language == FormatStyle::LK_Cpp && Ranges.empty()) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle, Ranges));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ const std::vector &Ranges = {}) {
+_verifyFormat(File, Line, Code, Code, Style, Ranges);
+  }
+
+  int ReplacementCount;
+};
+
+#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
+
+TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(Style.Language, FormatStyle::LK_Cpp);
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Binary, 0);
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Decimal, 0);
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Hex, 0);
+
+  const StringRef Binary("b = 0b10011'11'0110'1u;");
+  verifyFormat(Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = -1;
+  verifyFormat("b = 0b10001101u;", Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = 1;
+  verifyFormat("b = 0b1'0'0'1'1'1'1'0'1'1'0'1u;", Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = 4;
+  verifyFormat("b = 0b1001'1110'1101u;", Binary, Style);
+
+  const StringRef Decimal("d = 184467'440737'0'95505'92Ull;");
+  verifyFormat(Decimal, Style);
+  Style.IntegerLiteralSeparator.Decimal = -1;
+  verifyFormat("d = 18446744073709550592Ull;", Decimal, Style);
+  Style.IntegerLiteralSeparator.Decimal = 3;
+  verifyFormat("d = 18'446'744'073'709'550'592Ull;", Decimal, Style);
+
+  const StringRef Hex("h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;");
+  verifyFormat(Hex, Style);
+  Style.IntegerLiteralSeparator.Hex = -1;
+  verifyFormat("h = 0xDEADBEEFDEADBEEFuz;", Hex, Style);
+  S

[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2022-12-31 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa updated this revision to Diff 485793.
wzssyqa retitled this revision from "MIPS: emit .module and .nan directives 
only for first function" to "MIPS: fix build from IR files, nan2008 and FpAbi".
wzssyqa edited the summary of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

Files:
  clang/lib/Driver/ToolChains/Arch/Mips.cpp
  clang/test/Driver/mips-as.c
  clang/test/Driver/mips-integrated-as.s
  llvm/lib/Target/Mips/MipsAsmPrinter.cpp
  llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll

Index: llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
@@ -0,0 +1,13 @@
+; RUN: llc %s -o - | FileCheck %s
+
+target triple = "mipsel-unknown-linux-gnu"
+
+define dso_local void @test() #0 {
+  ret void
+}
+
+attributes #0 = { "target-cpu"="mips32r2" "target-features"="+fp64,+mips32r2,+nan2008" }
+
+
+; CHECK: .nan2008
+; CHECK: .module fp=64
Index: llvm/lib/Target/Mips/MipsAsmPrinter.cpp
===
--- llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -777,14 +777,18 @@
   // around it by re-initializing the PIC state here.
   TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
 
+  // Try to get target-features from the first function.
+  StringRef FS = TM.getTargetFeatureString();
+  Module::iterator F = M.begin();
+  if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
+FS = F->getFnAttribute("target-features").getValueAsString();
+
   // Compute MIPS architecture attributes based on the default subtarget
-  // that we'd have constructed. Module level directives aren't LTO
-  // clean anyhow.
+  // that we'd have constructed.
   // FIXME: For ifunc related functions we could iterate over and look
   // for a feature string that doesn't match the default one.
   const Triple &TT = TM.getTargetTriple();
   StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
-  StringRef FS = TM.getTargetFeatureString();
   const MipsTargetMachine &MTM = static_cast(TM);
   const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM, std::nullopt);
 
Index: clang/test/Driver/mips-integrated-as.s
===
--- clang/test/Driver/mips-integrated-as.s
+++ clang/test/Driver/mips-integrated-as.s
@@ -160,8 +160,8 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=FPXX-DEFAULT %s
 // FPXX-DEFAULT: -cc1as
-// FPXX-DEFAULT-NOT: "-target-feature" "+fpxx"
-// FPXX-DEFAULT-NOT: "-target-feature" "+nooddspreg"
+// FPXX-DEFAULT: "-target-feature" "+fpxx"
+// FPXX-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -mfp32 2>&1 | \
 // RUN:   FileCheck -check-prefix=FP32 %s
@@ -182,7 +182,7 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-DEFAULT %s
 // ODDSPREG-DEFAULT: -cc1as
-// ODDSPREG-DEFAULT-NOT: "-target-feature" "{{[+-]}}nooddspreg"
+// ODDSPREG-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -modd-spreg 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-ON %s
Index: clang/test/Driver/mips-as.c
===
--- clang/test/Driver/mips-as.c
+++ clang/test/Driver/mips-as.c
@@ -196,7 +196,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-mips16 -mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-16 %s
-// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mips16"
+// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mips16"
 //
 // RUN: %clang -target mips-linux-gnu -mips16 -mno-mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -207,7 +207,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-micromips -mmicromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-MICRO %s
-// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmicromips"
+// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mmicromips"
 //
 // RUN: %clang -target mips-linux-gnu -mmicromips -mno-micromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -218,7 +218,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-dsp -mdsp -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-DSP %s
-// MIPS-DSP: as{{(.exe)?}}" 

[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2022-12-31 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa added a comment.

@nathanchance can you have a try this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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


[PATCH] D140814: [clangd] show underlying type in type hint for `decltype(expr)`

2022-12-31 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry created this revision.
v1nh1shungry added a reviewer: nridge.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
v1nh1shungry requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140814

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1364,7 +1364,6 @@
 TEST(TypeHints, Decltype) {
   assertTypeHints(R"cpp(
 $a[[decltype(0)]] a;
-// FIXME: will be nice to show `: int` instead
 $b[[decltype(a)]] b;
 const $c[[decltype(0)]] &c = b;
 
@@ -1377,11 +1376,13 @@
 
 template  struct Foo;
 using G = Foo<$g[[decltype(0)]], float>;
+
+auto $h[[h]] = $i[[decltype(0)]]{};
   )cpp",
-  ExpectedHint{": int", "a"},
-  ExpectedHint{": decltype(0)", "b"},
+  ExpectedHint{": int", "a"}, ExpectedHint{": int", "b"},
   ExpectedHint{": int", "c"}, ExpectedHint{": int", "e"},
-  ExpectedHint{": int", "f"}, ExpectedHint{": int", "g"});
+  ExpectedHint{": int", "f"}, ExpectedHint{": int", "g"},
+  ExpectedHint{": int", "h"}, ExpectedHint{": int", "i"});
 }
 
 TEST(DesignatorHints, Basic) {
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -663,7 +663,14 @@
   }
 
   void addTypeHint(SourceRange R, QualType T, llvm::StringRef Prefix) {
+// print the underlying type for `decltype(expr)`
+if (T->isDecltypeType())
+  TypeHintPolicy.PrintCanonicalTypes = true;
+else if (const AutoType *AT = T->getContainedAutoType();
+ AT && AT->getDeducedType()->isDecltypeType())
+  TypeHintPolicy.PrintCanonicalTypes = true;
 addTypeHint(R, T, Prefix, TypeHintPolicy);
+TypeHintPolicy.PrintCanonicalTypes = false;
   }
 
   void addTypeHint(SourceRange R, QualType T, llvm::StringRef Prefix,


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1364,7 +1364,6 @@
 TEST(TypeHints, Decltype) {
   assertTypeHints(R"cpp(
 $a[[decltype(0)]] a;
-// FIXME: will be nice to show `: int` instead
 $b[[decltype(a)]] b;
 const $c[[decltype(0)]] &c = b;
 
@@ -1377,11 +1376,13 @@
 
 template  struct Foo;
 using G = Foo<$g[[decltype(0)]], float>;
+
+auto $h[[h]] = $i[[decltype(0)]]{};
   )cpp",
-  ExpectedHint{": int", "a"},
-  ExpectedHint{": decltype(0)", "b"},
+  ExpectedHint{": int", "a"}, ExpectedHint{": int", "b"},
   ExpectedHint{": int", "c"}, ExpectedHint{": int", "e"},
-  ExpectedHint{": int", "f"}, ExpectedHint{": int", "g"});
+  ExpectedHint{": int", "f"}, ExpectedHint{": int", "g"},
+  ExpectedHint{": int", "h"}, ExpectedHint{": int", "i"});
 }
 
 TEST(DesignatorHints, Basic) {
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -663,7 +663,14 @@
   }
 
   void addTypeHint(SourceRange R, QualType T, llvm::StringRef Prefix) {
+// print the underlying type for `decltype(expr)`
+if (T->isDecltypeType())
+  TypeHintPolicy.PrintCanonicalTypes = true;
+else if (const AutoType *AT = T->getContainedAutoType();
+ AT && AT->getDeducedType()->isDecltypeType())
+  TypeHintPolicy.PrintCanonicalTypes = true;
 addTypeHint(R, T, Prefix, TypeHintPolicy);
+TypeHintPolicy.PrintCanonicalTypes = false;
   }
 
   void addTypeHint(SourceRange R, QualType T, llvm::StringRef Prefix,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 83cec14 - [clang] Change CodeGenOptions::RelaxELFRelocations/assembler defaults to match MC default

2022-12-31 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-12-31T22:24:37-08:00
New Revision: 83cec143c76f4c76fe8ae28d6d836e8f7bd67891

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

LOG: [clang] Change CodeGenOptions::RelaxELFRelocations/assembler defaults to 
match MC default

MC default was flipped in 2016.
CMake ENABLE_X86_RELAX_RELOCATIONS defaults to on in 2020 
(c41a18cf61790fc898dcda1055c3efbf442c14c0).
It makes sense for the CodeGenOptions::RelaxELFRelocations to match, so
that most -cc1/-cc1as command lines won't have this option.

This also fixes a minor issue: -fno-plt -S will now use GOT for
__tls_get_addr calls, matching -fno-plt -c.

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/relax.c
clang/test/Driver/fuchsia.c
clang/test/Driver/ps4-ps5-relax-relocations.c
clang/test/Driver/relax.c
clang/test/Driver/relax.s
clang/tools/driver/cc1as_main.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 0545a4d2d17fe..436226c6f178f 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -30,7 +30,7 @@ CODEGENOPT(Name, Bits, Default)
 CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
 ENUM_CODEGENOPT(CompressDebugSections, llvm::DebugCompressionType, 2,
 llvm::DebugCompressionType::None)
-CODEGENOPT(RelaxELFRelocations, 1, 0) ///< -Wa,--mrelax-relocations
+CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
 CODEGENOPT(AsmVerbose, 1, 0) ///< -dA, -fverbose-asm.
 CODEGENOPT(Dwarf64   , 1, 0) ///< -gdwarf64.
 CODEGENOPT(Dwarf32   , 1, 1) ///< -gdwarf32.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f6f8e08712dab..cf204ae6b441a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5384,9 +5384,9 @@ def massembler_no_warn : Flag<["-"], 
"massembler-no-warn">,
 def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
   HelpText<"Make assembler warnings fatal">,
   MarshallingInfoFlag>;
-def mrelax_relocations : Flag<["--"], "mrelax-relocations">,
-HelpText<"Use relaxable elf relocations">,
-MarshallingInfoFlag>;
+def mrelax_relocations_no : Flag<["-"], "mrelax-relocations=no">,
+HelpText<"Disable x86 relax relocations">,
+MarshallingInfoNegativeFlag>;
 def msave_temp_labels : Flag<["-"], "msave-temp-labels">,
   HelpText<"Save temporary labels in the symbol table. "
"Note this may change .s semantics and shouldn't generally be used "

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 199796ea7570d..3635748ab9aa1 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2641,8 +2641,8 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   }
   if (ImplicitIt.size())
 AddARMImplicitITArgs(Args, CmdArgs, ImplicitIt);
-  if (UseRelaxRelocations)
-CmdArgs.push_back("--mrelax-relocations");
+  if (!UseRelaxRelocations)
+CmdArgs.push_back("-mrelax-relocations=no");
   if (UseNoExecStack)
 CmdArgs.push_back("-mnoexecstack");
   if (MipsTargetFeature != nullptr) {

diff  --git a/clang/test/CodeGen/relax.c b/clang/test/CodeGen/relax.c
index 07b7589be9753..b9ed5031b4ed3 100644
--- a/clang/test/CodeGen/relax.c
+++ b/clang/test/CodeGen/relax.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-obj --mrelax-relocations 
%s -mrelocation-model pic -o %t
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-obj %s -mrelocation-model 
pic -o %t
 // RUN: llvm-readobj -r %t | FileCheck  %s
 
 // CHECK: R_X86_64_REX_GOTPCRELX foo

diff  --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c
index 9c023329edb5f..25a2f841a9cb0 100644
--- a/clang/test/Driver/fuchsia.c
+++ b/clang/test/Driver/fuchsia.c
@@ -26,7 +26,6 @@
 // CHECK-X86_64: "-triple" "x86_64-unknown-fuchsia"
 // CHECK-AARCH64: "-triple" "aarch64-unknown-fuchsia"
 // CHECK-RISCV64: "-triple" "riscv64-unknown-fuchsia"
-// CHECK: "--mrelax-relocations"
 // CHECK: "-funwind-tables=2"
 // CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"

diff  --git a/clang/test/Driver/ps4-ps5-relax-relocations.c 
b/clang/test/Driver/ps4-ps5-relax-relocations.c
index 22490e486052f..41ed3f22b19c8 100644
--- a/clang/test/Driver/ps4-ps5-relax-relocations.c
+++ b/clang/test/Driver/ps4-ps5-relax-relocations.c
@@ -24,6 +24,6 @@
 // RUN: %clang -### -x assembler -target x86_64-s

[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2022-12-31 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll:1
+; RUN: llc %s -o - | FileCheck %s
+

Add `;; ` file-level comment what this test does. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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