[PATCH] D149361: [profiling] Improve error message for raw profile header mismatches

2023-04-28 Thread Christian Ulmann via Phabricator via cfe-commits
Dinistro added inline comments.



Comment at: llvm/unittests/ProfileData/InstrProfTest.cpp:1359
   auto RawProfileReaderOrErr = InstrProfReader::create(std::move(RawProfile));
   ASSERT_TRUE(InstrProfError::take(RawProfileReaderOrErr.takeError()) ==
   instrprof_error::unrecognized_format);

It seems that this and the following similar line do not compile. I assume that 
the necessary flags to activate this test were not provided in the CI executed 
for this revision. 

Crashing build: 
https://lab.llvm.org/buildbot/#/builders/104/builds/11668/steps/6/logs/stdio


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149361

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-28 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 517829.
junaire added a comment.

fix windows buildbots


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,11 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+// JIT reports symbol not found on Windows without the visibility attribute.
+REPL_EXTERNAL_VISIBILITY int getGlobal() { return Global; }
+REPL_EXTERNAL_VISIBILITY void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +282,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -315,4 +320,55 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_TRUE(V1.isValid());
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+  EXPECT_EQ(V1.getKind(), Value::K_Int);
+  EXPECT_FALSE(V1.isManuallyAlloc());
+  EXPECT_FALSE(V1.isPointerOrObjectType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_TRUE(V2.isValid());
+  EXPECT_EQ(V2.getDouble(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.getKind(), Value::K_Double);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+  EXPECT_FALSE(V2.isPointerOrObjectType());
+
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute(
+  "struct S { int* p; S() { p = new int(42); } ~S() { delete p; }};"));
+  llvm::cantFail(Interp->ParseAndExecute("S{}", &V3));
+  EXPECT_TRUE(V3.isValid());
+  EXPECT_TRUE(V3.getType()->isRecordType());
+  EXPECT_EQ(V3.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V3.isManuallyAlloc());
+  EXPECT_TRUE(V3.isPointerOrObjectType());
+
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 42);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  Value V5;
+  // Change the global from the compiled code.
+  setGlobal(43);
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V5));
+  EXPECT_EQ(V5.getInt(), 43);
+  EXPECT_TRUE(V5.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Interpreter/Value.cpp
===
--- /dev/null
+++ clang/lib/Interpreter/Value.cpp
@@ -0,0 +1,260 @@
+//===--- Interpreter.h - Incremental Compiation and Execution---*- C++ -*-===//
+//
+// Part of the

[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

2023-04-28 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

This patch is part of D141215 . I split it as 
some jit people requested. I don't know if there's a good way to test the 
patch, please leave a comment if you have an idea. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

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


[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

2023-04-28 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:7219
 void CodeGenModule::moveLazyEmissionStates(CodeGenModule *NewBuilder) {
-  assert(DeferredDeclsToEmit.empty() &&
- "Should have emitted all decls deferred to emit.");
+  // FIXME: Re-enable the assertions once we fix regular codegen to not leave
+  // weak references behind.

I'll removed the change after https://reviews.llvm.org/D148435 landed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

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


[PATCH] D149259: [analyzer][NFC] Use std::optional instead of custom "empty" state

2023-04-28 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy updated this revision to Diff 517831.
donat.nagy edited the summary of this revision.
donat.nagy added a comment.

As I was finalizing this commit, I noticed that the logic of 
`RegionRawOffsetV2::computeOffset()` is presented in a ~~crazy~~ unconventional 
way; so I rewrote it (while preserving the original behavior).

The most convoluted part was that the old code initialized the `offset` 
variable to `UnknownVal()`, then compensated for this choice by introducing a 
function `getValue` that always substituted zero when it encountered //this// 
`UnknownVal()` (no other effect placed `UnknownVal()` into that variable 
without immediately returning afterwards). I suspect that this initial value 
was introduced to avoid the analysis of load expressions that do not involve 
any array indexing (i.e. don't have `ElementRegion` layers), but that logic was 
broken by a commit in 2011.

@steakhal Can you provide another review for this extended version of the patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149259

Files:
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp

Index: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -51,21 +51,17 @@
 class RegionRawOffsetV2 {
 private:
   const SubRegion *baseRegion;
-  SVal byteOffset;
-
-  RegionRawOffsetV2()
-: baseRegion(nullptr), byteOffset(UnknownVal()) {}
+  NonLoc byteOffset;
 
 public:
   RegionRawOffsetV2(const SubRegion *base, NonLoc offset)
   : baseRegion(base), byteOffset(offset) { assert(base); }
 
-  NonLoc getByteOffset() const { return byteOffset.castAs(); }
+  NonLoc getByteOffset() const { return byteOffset; }
   const SubRegion *getRegion() const { return baseRegion; }
 
-  static RegionRawOffsetV2 computeOffset(ProgramStateRef state,
- SValBuilder &svalBuilder,
- SVal location);
+  static std::optional
+  computeOffset(ProgramStateRef State, SValBuilder &SVB, SVal Location);
 
   void dump() const;
   void dumpToStream(raw_ostream &os) const;
@@ -158,16 +154,16 @@
   ProgramStateRef state = checkerContext.getState();
 
   SValBuilder &svalBuilder = checkerContext.getSValBuilder();
-  const RegionRawOffsetV2 &rawOffset =
-RegionRawOffsetV2::computeOffset(state, svalBuilder, location);
+  const std::optional &RawOffset =
+  RegionRawOffsetV2::computeOffset(state, svalBuilder, location);
 
-  if (!rawOffset.getRegion())
+  if (!RawOffset)
 return;
 
-  NonLoc ByteOffset = rawOffset.getByteOffset();
+  NonLoc ByteOffset = RawOffset->getByteOffset();
 
   // CHECK LOWER BOUND
-  const MemSpaceRegion *SR = rawOffset.getRegion()->getMemorySpace();
+  const MemSpaceRegion *SR = RawOffset->getRegion()->getMemorySpace();
   if (!llvm::isa(SR)) {
 // A pointer to UnknownSpaceRegion may point to the middle of
 // an allocated region.
@@ -188,7 +184,7 @@
 
   // CHECK UPPER BOUND
   DefinedOrUnknownSVal Size =
-  getDynamicExtent(state, rawOffset.getRegion(), svalBuilder);
+  getDynamicExtent(state, RawOffset->getRegion(), svalBuilder);
   if (auto KnownSize = Size.getAs()) {
 auto [state_withinUpperBound, state_exceedsUpperBound] =
 compareValueToThreshold(state, ByteOffset, *KnownSize, svalBuilder);
@@ -277,84 +273,55 @@
 }
 #endif
 
-// Lazily computes a value to be used by 'computeOffset'.  If 'val'
-// is unknown or undefined, we lazily substitute '0'.  Otherwise,
-// return 'val'.
-static inline SVal getValue(SVal val, SValBuilder &svalBuilder) {
-  return val.isUndef() ? svalBuilder.makeZeroArrayIndex() : val;
-}
-
-// Scale a base value by a scaling factor, and return the scaled
-// value as an SVal.  Used by 'computeOffset'.
-static inline SVal scaleValue(ProgramStateRef state,
-  NonLoc baseVal, CharUnits scaling,
-  SValBuilder &sb) {
-  return sb.evalBinOpNN(state, BO_Mul, baseVal,
-sb.makeArrayIndex(scaling.getQuantity()),
-sb.getArrayIndexType());
-}
-
-// Add an SVal to another, treating unknown and undefined values as
-// summing to UnknownVal.  Used by 'computeOffset'.
-static SVal addValue(ProgramStateRef state, SVal x, SVal y,
- SValBuilder &svalBuilder) {
-  // We treat UnknownVals and UndefinedVals the same here because we
-  // only care about computing offsets.
-  if (x.isUnknownOrUndef() || y.isUnknownOrUndef())
-return UnknownVal();
-
-  return svalBuilder.evalBinOpNN(state, BO_Add, x.castAs(),
- y.castAs(),
- svalBuilder.getArrayIndexType());
-}
-
-/// Compute a raw byte offset from a base region.  Used for ar

[PATCH] D148712: [clang] Diagnose shadowing of lambda's template parameter by a capture

2023-04-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 517834.
Fznamznon added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148712

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp


Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow 
-Wshadow-uncaptured-local %s
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow-all %s
 // RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only -Wshadow-all %s
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -Wshadow-all %s
 
 void foo(int param) { // expected-note 1+ {{previous declaration is here}}
   int var = 0; // expected-note 1+ {{previous declaration is here}}
@@ -146,3 +147,22 @@
 int b = 0; // expected-error {{redefinition of 'b'}}
   };
 }
+
+namespace GH61105 {
+void f() {
+  int y = 0;
+  int x = 0;
+#if __cplusplus >= 202002L
+  auto l1 = [y](y) { return 0; }; // expected-error {{declaration 
of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+  auto l2 = [=]() { int a = y; return 0; }; // expected-error 
{{'y' does not refer to a value}} \
+// expected-note 
{{declared here}}
+  auto l3 = [&, y](y) { int a = x; return 0; }; // 
expected-error {{declaration of 'y' shadows template parameter}} \
+  // 
expected-note {{template parameter is declared here}}
+  auto l4 = [x, y]() { return 0; }; // expected-error 
{{declaration of 'y' shadows template parameter}} \
+   // expected-error 
{{declaration of 'x' shadows template parameter}} \
+   // expected-note 
2{{template parameter is declared here}}
+  auto l5 = [](y) { return 0; }; // No diagnostic
+#endif
+}
+}
Index: 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
===
--- /dev/null
+++ 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+void f() {
+  int x = 0;
+  auto g = [x](int x) { return 0; }; // expected-error {{a lambda parameter 
cannot shadow an explicitly captured entity}} \
+ // expected-note {{variable 'x' is 
explicitly captured here}}
+  auto h = [y = 0](y) { return 0; };  // expected-error 
{{declaration of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+
+}
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1365,6 +1365,26 @@
 PushOnScopeChains(P, CurScope);
   }
 
+  // C++23 [expr.prim.lambda.capture]p5:
+  // If an identifier in a capture appears as the declarator-id of a parameter
+  // of the lambda-declarator's parameter-declaration-clause or as the name of 
a
+  // template parameter of the lambda-expression's template-parameter-list, the
+  // program is ill-formed.
+  TemplateParameterList *TemplateParams =
+  getGenericLambdaTemplateParameterList(LSI, *this);
+  if (TemplateParams) {
+for (const auto *TP : TemplateParams->asArray()) {
+  if (!TP->getIdentifier())
+continue;
+  for (const auto &Capture : Intro.Captures) {
+if (Capture.Id == TP->getIdentifier()) {
+  Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
+  Diag(TP->getLocation(), diag::note_template_param_here);
+}
+  }
+}
+  }
+
   // C++20: dcl.decl.general p4:
   // The optional requires-clause ([temp.pre]) in an init-declarator or
   // member-declarator shall be present only if the declarator declares a
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -233,6 +233,8 @@
 - ``-Wformat`` now recognizes ``%lb`` for the ``printf``/``scanf`` family of
   functions.
   (`#62247: `_).
+- Clang now diagnoses shadowing of lambda's template parameter by a capture.
+  (`#61105: `_).
 
 Bug Fixes in This Version
 -


Index: clang/test/SemaCXX/warn-shadow-in-lambdas

[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D149276#4302700 , @aaron.ballman 
wrote:

> The changes generally LGTM, but:
>
>> in a way consistent with the proposed resolution to CWG1223.
>
> What are the chances that CWG changes their mind and picks a different 
> direction?

CWG acts in mysterious ways, so it's hard to tell. but i think anything else 
than this resolution could potentially break code?




Comment at: clang/lib/Parse/ParseTentative.cpp:1067
+bool mayHaveDirectInit,
+bool mayHaveTrailingReturnType) {
   // declarator:

aaron.ballman wrote:
> tbaeder wrote:
> > Not part of this commit I guess, but //four// bool parameters is truly 
> > horrific :/
> Yeah, a refactoring here would not be amiss (but outside of this patch, I 
> think).
Agreed, we probably want an enum there instead, i could follow up


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

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


[PATCH] D147197: [llvm-docs] Added documentation for the 'neg' operation

2023-04-28 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs added a comment.

Since the instruction's don't exist now, would you mind abandoning this 
revision?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147197

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


[clang] e5d98c1 - Revert "[flang][driver] Allow main program to be in an archive"

2023-04-28 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2023-04-28T09:39:27+01:00
New Revision: e5d98c15cb7ba467c5f93b5ef08ac9b18d390133

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

LOG: Revert "[flang][driver] Allow main program to be in an archive"

This reverts commit 876df74dd47196a9ca3b4fff21ffb5441491a0a0.

My understanding (based on https://reviews.llvm.org/D149429) is that
this patch has caused all of Flang's buildbots to fail. I'm not really
able to verify 100% as the buildbot UI is incredibly slow ATM. I am
reverting either way so that we can discuss the right solution offline.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
flang/docs/FlangDriver.md
flang/test/CMakeLists.txt
flang/test/Driver/linker-flags.f90

Removed: 
flang/test/Driver/link-c-main.c
flang/test/Driver/link-f90-main.f90



diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index c4a276126b653..b0716322bc141 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -598,14 +598,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // these dependencies need to be listed before the C runtime below (i.e.
   // AddRuntTimeLibs).
   if (D.IsFlangMode()) {
-// A Fortran main program will be lowered to a function named _QQmain. Make
-// _QQmain an undefined symbol, so that it's correctly resolved even when
-// creating executable from archives. This is a workaround for how and 
where
-// Flang's `main` is defined. For more context, see:
-//   *  https://github.com/llvm/llvm-project/issues/54787
-if (!Args.hasArg(options::OPT_shared))
-  CmdArgs.push_back("--undefined=_QQmain");
-
 addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
 addFortranRuntimeLibs(ToolChain, CmdArgs);
 CmdArgs.push_back("-lm");

diff  --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index 9522e223b17b5..6c2a473820634 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -149,6 +149,13 @@ flang-new -ccc-print-phases -c file.f
 +- 3: backend, {2}, assembler
 4: assembler, {3}, object
 ```
+Note that currently Flang does not support code-generation and `flang-new` will
+fail during the second step above with the following error:
+```bash
+error: code-generation is not available yet
+```
+The other phases are printed nonetheless when using `-ccc-print-phases`, as
+that reflects what `clangDriver`, the library, will try to create and run.
 
 For actions specific to the frontend (e.g. preprocessing or code generation), a
 command to call the frontend driver is generated (more specifically, an
@@ -198,41 +205,6 @@ is `ParseSyntaxOnlyAction`, which corresponds to 
`-fsyntax-only`. In other
 words, `flang-new -fc1 ` is equivalent to `flang-new -fc1 
-fsyntax-only
 `.
 
-## Linker invocation
-> **_NOTE:_**  Linker invocation through the `flang-new` driver is so far
-> experimental. This section describes the currently intended design, and not
-> necessarily what is implemented.
-
-Calling
-```bash
-flang-new -flang-experimental-exec prog.f90
-```
-will, on a high level, do two things:
-* call the frontend driver, `flang-new -fc1`, to build the object file `prog.o`
-* call the system linker to build the executable `a.out`.
-
-In both invocations, `flang-new` will add default options to the frontend 
driver
-and the linker invocations. To see the exact invocations on your system, you 
can
-call
-```bash
-flang-new -### prog.f90
-```
-The link line will contain a fair number of options, which will depend on your
-system. Compared to when linking a C program with `clang`, the main additions
-are (on GNU/linux),
-* `--undefined=_QQmain`: A Fortran main program will appear in the 
corresponding
-  object file as a function called `_QQmain`. This flag makes sure that an
-  object file containing a Fortran main program (i.e., a symbol `_QQmain`) be
-  included in the linking also when it is bundled in an archive.
-* `-lFortran_main`: The Fortran_main archive is part of Flang's runtime. It
-  exports the symbol `main`, i.e., a c main function, which will make some
-  initial configuration before calling `_QQmain`, and clean up before 
returning.
-* `-lFortranRuntime`: Flang's Fortran runtime, containing, for example,
-  implementations of intrinsic functions.
-* `-lFortranDecimal`: Part of Flang's runtime, containing routines for parsing
-  and formatting decimal numbers.
-* `-lm`: Link with the math library, on which Flang's runtime depends.
-
 ## The `flang-to-external-fc` script
 The `flang-to-external-fc` wrapper script for `flang-new` was introduced as a
 development tool and to facilitate testing. The `flang-to-external-fc` wrapper

diff  --git a/flang/test

[PATCH] D146809: [WIP][clang-repl] Implement Value pretty printing

2023-04-28 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 517836.
junaire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146809

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_interpreter_runtime_printvalue.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Interpreter/ValuePrinter.cpp
  clang/test/Interpreter/pretty-print.cpp

Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,104 @@
+// 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
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) 'a'
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2f
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.210
+
+struct S{};
+S s;
+s
+// CHECK-NEXT: (S &) [[Addr:@0x.*]]
+
+S{}
+// CHECK-NEXT: (S) [[Addr:@0x.*]]
+
+struct C {int d;} E = {22};
+E
+// CHECK-NEXT: [[Addr:@0x.*]]
+E.d
+// CHECK-NEXT: (int) 22
+
+struct SS { int* p; SS() { p = new int(42); } ~SS() { delete p; } };
+SS{}
+// CHECK-NEXT: (SS) [[Addr:@0x.*]]
+SS ss;
+ss
+// CHECK-NEXT: (SS &) [[Addr:@0x.*]]
+
+enum Enum{ e1 = -12, e2, e3=33, e4, e5 = 33};
+e2
+// CHECK-NEXT: (Enum) (e2) : int -11
+::e1
+// CHECK-NEXT: (Enum) (e1) : int -12
+
+enum class Color { Black = 0, Red, Green };
+Color::Black
+// CHECK-NEXT: (Color) (Color::Black) : int 0
+
+int arr[3] = {1,2,3};
+arr
+// CHECK-NEXT: (int[3]) { 1, 2, 3 }
+
+#include 
+
+auto p1 = std::make_shared(42);
+p1
+// CHECK-NEXT: (shared_ptr &) std::shared_ptr -> [[Addr:@0x.*]]
+
+#include 
+std::array a{1, 2, 3};
+a
+// CHECK-NEXT: (std::array &) { 1, 2, 3 }
+
+#include 
+std::vector v = {7, 5, 16, 8};
+v
+// CHECK-NEXT: (std::vector &) { 7, 5, 16, 8 }
+
+#include 
+std::deque dq = {7, 5, 16, 8};
+dq
+// CHECK-NEXT: (std::deque &) { 7, 5, 16, 8 }
+
+#include 
+std::forward_list fl {3,4,5,6};
+fl
+// CHECK-NEXT: (std::forward_list &) { 3, 4, 5, 6 }
+
+#include 
+std::set z = {2,4,6,8};
+z
+// CHECK-NEXT: (std::set &) { 2, 4, 6, 8 }
+
+std::multiset e {3,2,1,2,4,7,3};
+e
+// CHECK-NEXT: (std::multiset &) { 1, 2, 2, 3, 3, 4, 7 }
+
+#include 
+std::string std_str = "Hello, world!";
+std_str
+// CHECK-NEXT: (std::string &) "Hello, world!"
+
+const char* c_str = "Goodbye, world!";
+c_str
+// CHECK-NEXT: (const char *) "Goodbye, world!"
+%quit
+
Index: clang/lib/Interpreter/ValuePrinter.cpp
===
--- /dev/null
+++ clang/lib/Interpreter/ValuePrinter.cpp
@@ -0,0 +1,497 @@
+#include "InterpreterUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Interpreter/Value.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+
+using namespace clang;
+
+static std::string PrintDeclType(const QualType &QT, NamedDecl *D) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  if (QT.hasQualifiers())
+SS << QT.getQualifiers().getAsString() << " ";
+  SS << D->getQualifiedNameAsString();
+  return Str;
+}
+
+static std::string PrintQualType(ASTContext &Ctx, QualType QT) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  PrintingPolicy Policy(Ctx.getPrintingPolicy());
+  // Print the Allocator in STL containers, for instance.
+  Policy.SuppressDefaultTemplateArgs = false;
+  Policy.SuppressUnwrittenScope = true;
+  // Print 'a >' rather than 'a>'.
+  Policy.SplitTemplateClosers = true;
+
+  struct LocalPrintingPolicyRAII {
+ASTContext &Context;
+PrintingPolicy Policy;
+
+LocalPrintingPolicyRAII(ASTContext &Ctx, PrintingPolicy &PP)
+: Context(Ctx), Policy(Ctx.getPrintingPolicy()) {
+  Context.setPrintingPolicy(PP);
+}
+~LocalPrintingPolicyRAII() { Context.setPrintingPolicy(Policy); }
+  } X(Ctx, Policy);
+
+  const QualType NonRefTy = QT.getNonReferenceType();
+
+  if (const auto *TTy = llvm::dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TTy->getDecl());
+  else if (const auto *TRy = dyn_cast(NonRefTy))
+

[PATCH] D134821: [flang][driver] Allow main program to be in an archive

2023-04-28 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

I've just reverted this patch - for context please see 
https://reviews.llvm.org/D149429.

@sunshaoce This was committed 
 without 
acknowledging @ekieri 's contribution, so didn't follow the official 
guidelines: Attribution of Changes 
. IMHO, we 
should keep Emil as the author of this change (he has done the lion share of 
this highly non-trivial work) and add you as a co-author 
.
 Unless @ekieri has some other preference :) (I am happy as long as we follow 
the guidelines).

Either way, thank you **both** for contributing! Now, lets try to figure out 
what caused the issue with the bots.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134821

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


[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

2023-04-28 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 517844.
skatrak added a comment.

Remove leftover unit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147218

Files:
  flang/include/flang/Lower/OpenMP.h
  flang/lib/Lower/Bridge.cpp
  flang/lib/Lower/OpenMP.cpp
  flang/test/Lower/OpenMP/requires-notarget.f90
  flang/test/Lower/OpenMP/requires.f90

Index: flang/test/Lower/OpenMP/requires.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires.f90
@@ -0,0 +1,14 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks the lowering of requires into MLIR
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.atomic_default_mem_order = #omp
+!CHECK-SAME: omp.requires = #omp
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
+
+subroutine f
+  !$omp declare target
+end subroutine f
Index: flang/test/Lower/OpenMP/requires-notarget.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires-notarget.f90
@@ -0,0 +1,12 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks that requires lowering into MLIR skips creating the
+! omp.requires attribute with target-related clauses if there are no device
+! functions in the compilation unit
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.atomic_default_mem_order = #omp
+!CHECK-NOT:  omp.requires
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
Index: flang/lib/Lower/OpenMP.cpp
===
--- flang/lib/Lower/OpenMP.cpp
+++ flang/lib/Lower/OpenMP.cpp
@@ -24,7 +24,9 @@
 #include "flang/Semantics/tools.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Dialect/SCF/IR/SCF.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
 
 using namespace mlir;
 
@@ -2239,11 +2241,13 @@
   converter.bindSymbol(sym, symThreadprivateExv);
 }
 
-void handleDeclareTarget(Fortran::lower::AbstractConverter &converter,
- Fortran::lower::pft::Evaluation &eval,
- const Fortran::parser::OpenMPDeclareTargetConstruct
- &declareTargetConstruct) {
-  llvm::SmallVector symbols;
+/// Extract the list of function and variable symbols affected by the given
+/// 'declare target' directive and return the intended device type for them.
+static mlir::omp::DeclareTargetDeviceType getDeclareTargetInfo(
+Fortran::lower::pft::Evaluation &eval,
+const Fortran::parser::OpenMPDeclareTargetConstruct &declareTargetConstruct,
+SmallVectorImpl &symbols) {
+  // Gather the symbols
   auto findFuncAndVarSyms = [&](const Fortran::parser::OmpObjectList &objList) {
 for (const auto &ompObject : objList.v) {
   Fortran::common::visit(
@@ -2261,12 +2265,11 @@
 }
   };
 
+  // The default capture type
+  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   const auto &spec{std::get(
   declareTargetConstruct.t)};
-  auto mod = converter.getFirOpBuilder().getModule();
 
-  // The default capture type
-  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   if (const auto *objectList{
   Fortran::parser::Unwrap(spec.u)}) {
 // Case: declare target(func, var1, var2)
@@ -2288,8 +2291,7 @@
  std::get_if(
  &clause.u)}) {
 // Case: declare target link(var1, var2)...
-TODO(converter.getCurrentLocation(),
- "the link clause is currently unsupported");
+TODO_NOLOC("the link clause is currently unsupported");
   } else if (const auto *deviceClause{
  std::get_if(
  &clause.u)}) {
@@ -2299,6 +2301,24 @@
 }
   }
 
+  switch (deviceType) {
+  case Fortran::parser::OmpDeviceTypeClause::Type::Any:
+return mlir::omp::DeclareTargetDeviceType::any;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Host:
+return mlir::omp::DeclareTargetDeviceType::host;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Nohost:
+return mlir::omp::DeclareTargetDeviceType::nohost;
+  }
+}
+
+void handleDeclareTarget(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ const Fortran::parser::OpenMPDeclareTargetConstruct
+ &declareTargetConstruct) {
+  SmallVector symbols;
+  auto deviceType = getDeclareTargetInfo(eval, declareTargetConstruct, symbols);
+
+  auto mod = converter.getFirOpBuilder().getModule();
   for (auto sym : symbols) {
 auto *op = mod.lookupSymbol(converter.mangleName(sym));
 
@@ -2309,20 +2329,6 @@

[PATCH] D148944: [clang][Driver] Fix crash with unsupported architectures in MinGW and CrossWindows.

2023-04-28 Thread Florian Hahn via Phabricator via cfe-commits
fhahn resigned from this revision.
fhahn added a comment.

Sorry, I am not familiar at all with this code. Perhaps @shafik could suggest 
more appropriate reviewers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148944

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


[PATCH] D149006: [llvm][Support] Replace `%` operator with `&` in `Align::isAligned(...)`

2023-04-28 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

> it is easier to check reminder by conjunction with mask, which is (Pow2Value 
> - 1).

Hmm, easier in what respect? Isn't the original code more straight-forward?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149006

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


[PATCH] D148944: [clang][Driver] Fix crash with unsupported architectures in MinGW and CrossWindows.

2023-04-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

I think the code changes make sense; these are trivial to hit by a user, so 
they shouldn't be `llvm_unreachable`.




Comment at: clang/test/Driver/unsupported-target-arch.c:33
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-CROSSWINDOWS 
%s
+// CHECK-NOARCH-CROSSWINDOWS: error: unknown target triple 
'noarch-unknown-windows-itanium', please use -triple or -arch

Separate side note; the suggested option `-triple` isn't really a clang driver 
level option, and `-arch` is only relevant for darwin targets (AFAIK) - so 
maybe the error message text should be revised?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148944

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


[clang] 8dec295 - Reapply D146987 "[Assignment Tracking] Enable by default"

2023-04-28 Thread via cfe-commits

Author: OCHyams
Date: 2023-04-28T11:34:53+01:00
New Revision: 8dec295af0352fccb5825dc08e4ec21cb9ffe010

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

LOG: Reapply D146987 "[Assignment Tracking] Enable by default"

See https://discourse.llvm.org/t/rfc-enable-assignment-tracking/69399

This sets the -Xclang -fexperimental-assignment-tracking flag to the value
enabled which means it will be enabled so long as none of the following are
true: it's an LTO build, LLDB debugger tuning has been specified, or it's an O0
build (no work is done in any case if -g is not specified or -gmlt is used).

This reverts commit 0ba922f600469df273c753f873668e41025487c0 which reverts
https://reviews.llvm.org/D146987

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/CodeGen/assignment-tracking/flag.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 592584ab625c9..e945c96e653d9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5816,7 +5816,7 @@ def fexperimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignme
   Group, CodeGenOpts<"EnableAssignmentTracking">,
   NormalizedValuesScope<"CodeGenOptions::AssignmentTrackingOpts">,
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
-  MarshallingInfoEnum, "Disabled">;
+  MarshallingInfoEnum, "Enabled">;
 
 } // let Flags = [CC1Option, NoDriverOption]
 

diff  --git a/clang/test/CodeGen/assignment-tracking/flag.cpp 
b/clang/test/CodeGen/assignment-tracking/flag.cpp
index aa1f054dae4d7..3bd974fe07c6c 100644
--- a/clang/test/CodeGen/assignment-tracking/flag.cpp
+++ b/clang/test/CodeGen/assignment-tracking/flag.cpp
@@ -8,10 +8,10 @@
 // RUN: -emit-llvm  %s -o - -fexperimental-assignment-tracking=disabled 
-O1\
 // RUN: | FileCheck %s --check-prefixes=DISABLE
 
- Disabled by default:
+ Enabled by default:
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\
 // RUN: -emit-llvm  %s -o - -O1
\
-// RUN: | FileCheck %s --check-prefixes=DISABLE
+// RUN: | FileCheck %s --check-prefixes=ENABLE
 
  Disabled at O0 unless forced.
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\



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


[PATCH] D146987: [Assignment Tracking] Enable by default

2023-04-28 Thread Orlando Cazalet-Hyams via Phabricator via cfe-commits
Orlando added a comment.

Great, thanks @paulkirth!

I've just landed this again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146987

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


[PATCH] D149006: [llvm][Support] Replace `%` operator with `&` in `Align::isAligned(...)`

2023-04-28 Thread Sviatoslav Osipov via Phabricator via cfe-commits
Stoorx added a comment.

> easier in what respect?

I mean, easier for CPU :-)

The division operation reasonably seems to be more complex than bitwise AND. 
And since this function is pretty hot it can save a bit of performance.
(Actually that's just my assumption. I did not make benchmark really.)

Side thought: I suspect some advanced CPUs can optimize such kind of divisions 
by powers of 2 by themselves.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149006

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


[PATCH] D134821: [flang][driver] Allow main program to be in an archive

2023-04-28 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce added a comment.

In D134821#4304690 , @awarzynski 
wrote:

> I've just reverted this patch - for context please see 
> https://reviews.llvm.org/D149429.
>
> @sunshaoce This was committed 
>  without 
> acknowledging @ekieri 's contribution, so didn't follow the official 
> guidelines: Attribution of Changes 
> . IMHO, we 
> should keep Emil as the author of this change (he has done the lion share of 
> this highly non-trivial work) and add you as a co-author 
> .
>  Unless @ekieri has some other preference :) (I am happy as long as we follow 
> the guidelines).
>
> Either way, thank you **both** for contributing! Now, lets try to figure out 
> what caused the issue with the bots.

Sorry for not following the official attribution guidelines. I agree with your 
suggestion to keep @ekieri as the main author. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134821

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


[PATCH] D149436: [clang] Do not attempt to zero-extend _BitInt(1) when not required

2023-04-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`ConvertTypeForMem` doesn't return wider type for _BitInt unless it is
used in a bitfield, so no need to extend when trying to initialize a
global variable.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149436

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGen/ext-int.c


Index: clang/test/CodeGen/ext-int.c
===
--- clang/test/CodeGen/ext-int.c
+++ clang/test/CodeGen/ext-int.c
@@ -3,6 +3,10 @@
 // RUN: %clang_cc1 -triple i386-gnu-linux -O3 -disable-llvm-passes -emit-llvm 
-o - %s | FileCheck %s --check-prefixes=CHECK,LIN32
 // RUN: %clang_cc1 -triple i386-windows-pc -O3 -disable-llvm-passes -emit-llvm 
-o - %s | FileCheck %s --check-prefixes=CHECK,WIN32
 
+//GH62207
+unsigned _BitInt(1) GlobSize1 = 0;
+// CHECK: @GlobSize1 = {{.*}}global i1 false
+
 void GenericTest(_BitInt(3) a, unsigned _BitInt(3) b, _BitInt(4) c) {
   // CHECK: define {{.*}}void @GenericTest
   int which = _Generic(a, _BitInt(3): 1, unsigned _BitInt(3) : 2, _BitInt(4) : 
3);
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1730,7 +1730,7 @@
   }
 
   // Zero-extend bool.
-  if (C->getType()->isIntegerTy(1)) {
+  if (C->getType()->isIntegerTy(1) && !destType->isBitIntType()) {
 llvm::Type *boolTy = CGM.getTypes().ConvertTypeForMem(destType);
 return llvm::ConstantExpr::getZExt(C, boolTy);
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -336,6 +336,9 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix the assertion hit when generating code for global variable initializer of
+  _BitInt(1) type.
+  (`#62207 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGen/ext-int.c
===
--- clang/test/CodeGen/ext-int.c
+++ clang/test/CodeGen/ext-int.c
@@ -3,6 +3,10 @@
 // RUN: %clang_cc1 -triple i386-gnu-linux -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LIN32
 // RUN: %clang_cc1 -triple i386-windows-pc -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WIN32
 
+//GH62207
+unsigned _BitInt(1) GlobSize1 = 0;
+// CHECK: @GlobSize1 = {{.*}}global i1 false
+
 void GenericTest(_BitInt(3) a, unsigned _BitInt(3) b, _BitInt(4) c) {
   // CHECK: define {{.*}}void @GenericTest
   int which = _Generic(a, _BitInt(3): 1, unsigned _BitInt(3) : 2, _BitInt(4) : 3);
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1730,7 +1730,7 @@
   }
 
   // Zero-extend bool.
-  if (C->getType()->isIntegerTy(1)) {
+  if (C->getType()->isIntegerTy(1) && !destType->isBitIntType()) {
 llvm::Type *boolTy = CGM.getTypes().ConvertTypeForMem(destType);
 return llvm::ConstantExpr::getZExt(C, boolTy);
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -336,6 +336,9 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix the assertion hit when generating code for global variable initializer of
+  _BitInt(1) type.
+  (`#62207 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-04-28 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 517865.
zyounan added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148457

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
@@ -529,6 +529,8 @@
[](HoverInfo &HI) {
  HI.Name = "MACRO";
  HI.Kind = index::SymbolKind::Macro;
+ HI.Value = "41 (0x29)";
+ HI.Type = "int";
  HI.Definition = "#define MACRO 41\n\n"
  "// Expands to\n"
  "41";
@@ -1792,6 +1794,8 @@
   )cpp",
   [](HoverInfo &HI) {
 HI.Name = "MACRO";
+HI.Value = "0";
+HI.Type = "int";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0\n\n"
 "// Expands to\n"
@@ -3746,6 +3750,140 @@
   EXPECT_EQ(H->Type->Type, "int");
   EXPECT_EQ(H->Definition, "using foo = type");
 }
+
+TEST(Hover, EvaluateMacros) {
+  Annotations CXX(R"cpp(
+  #define X 42
+  #define SizeOf sizeof
+  #define AlignOf alignof
+
+  using u64 = unsigned long long;
+  // calculate (a ** b) % p
+  constexpr u64 pow_with_mod(u64 a, u64 b, u64 p) {
+u64 ret = 1;
+while (b) {
+  if (b & 1)
+ret = (ret * a) % p;
+  a = (a * a) % p;
+  b >>= 1;
+}
+return ret;
+  }
+  #define last_n_digit(x, y, n)  \
+pow_with_mod(x, y, pow_with_mod(10, n, 2147483647))
+  #define declare_struct(X, name, value) \
+struct X {   \
+  constexpr auto name() { return value; }\
+}
+  #define gnu_statement_expression(value)\
+({   \
+  declare_struct(Widget, getter, value); \
+  Widget().getter(); \
+})
+  #define define_lambda_begin(lambda, ...)   \
+[&](__VA_ARGS__) {
+  #define define_lambda_end() }
+
+  #define plus_42 +40
+
+void check() {
+  X$1^;
+  Size$2^Of(int);
+  struct Y {
+int y;
+double z;
+  };
+  Alig$3^nOf(Y);
+  // 2**32 == 4294967296
+  last_n_di$4^git(2, 32, 6);
+  gnu_statement_exp$5^ression(42);
+
+  constexpr auto value = define_lamb$6^da_begin(lambda, int, char)
+// Check if the expansion range is right.
+return $7^last_n_digit(10, 3, 3)$8^;
+  define_lam$9^bda_end();
+  2 pl$10^us_42;
+}
+  )cpp");
+
+  Config Cfg;
+  Cfg.Hover.ShowAKA = false;
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+
+  auto TU = TestTU::withCode(CXX.code());
+  TU.ExtraArgs.push_back("-std=c++17");
+  auto GetHoverAt = [AST(TU.build()), CXX](llvm::StringRef Point) mutable {
+return getHover(AST, CXX.point(Point), format::getLLVMStyle(), nullptr);
+  };
+
+  std::optional H;
+
+  H = GetHoverAt("1");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "42 (0x2a)");
+  EXPECT_EQ(H->Type, HoverInfo::PrintedType("int"));
+
+  H = GetHoverAt("2");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "4");
+  // Don't validate type of `sizeof` and `alignof` as we're getting different
+  // desugared types on different platforms. Same as below.
+
+  H = GetHoverAt("3");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "8");
+
+  H = GetHoverAt("4");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "967296 (0xec280)");
+  EXPECT_EQ(H->Type, HoverInfo::PrintedType("u64"));
+
+  H = GetHoverAt("5");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "42 (0x2a)");
+  EXPECT_EQ(H->Type, HoverInfo::PrintedType("int"));
+
+  H = GetHoverAt("6");
+  ASSERT_TRUE(H);
+  EXPECT_FALSE(H->Value) << H->Value;
+  EXPECT_EQ(H->Type, HoverInfo::PrintedType("class (lambda)")) << H->Type;
+
+  H = GetHoverAt("7");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "0");
+  EXPECT_EQ(H->Type, HoverInfo::PrintedType("u64"));
+
+  H = GetHoverAt("8");
+  ASSERT_FALSE(H);
+
+  H = GetHoverAt("9");
+  ASSERT_FALSE(H->Value) << H->Value;
+  ASSERT_FALSE(H->Type) << H->Type;
+
+  H = GetHoverAt("10");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Type, HoverInfo::PrintedType("int"));
+  EXPECT_EQ(H->Value, "40 (0x28)");
+
+  Annotations C(R"c(
+#define alignof _Alignof
+void foo() {
+  al^ignof(struct { int x; char y[10]; });
+}
+  )c");
+
+  TU = TestTU::withCode(C.code());
+  TU.Filename = "TestTU.c";
+  TU.ExtraArgs = {
+  "-std=c17",
+  };
+  auto AST = TU.build(

[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-04-28 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Sorry for responding late and thank you for the good catch!
I've updated the code and please feel free to leave comments. :)




Comment at: clang-tools-extra/clangd/Hover.cpp:728
   }
+  SelectionTree::createEach(
+  AST.getASTContext(), AST.getTokens(), SM.getFileOffset(Tok.location()),

nridge wrote:
> Why `createEach()` when the [non-macro 
> case](https://searchfox.org/llvm/rev/be9c91843bab5bb46574c27836bfcd9ad6fc9ef5/clang-tools-extra/clangd/Hover.cpp#1270)
>  uses `createRight()`?
TBH, I didn't notice that we're using `createRight()` before and I'm not quite 
sure if there exists such case, that yields nothing with the right selection 
tree (which is exactly the 1st tree produced by `createEach()`) but could be 
evaluated with falling back to the left selection tree.
I'll change it to `createEach` anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148457

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


[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-04-28 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Oops, an inline comment disappears accidentally.

>   #define PLUS_TWO + 2
>   int x = 40 PLUS_TW^O;  // huh, the value of "+ 2" is "42"?

The reason is we're getting a `SelectionNode` with a wider range. Here is the 
layout of the tree:

  txt
  Built selection tree
   TranslationUnitDecl 
 FunctionDecl void check()
   CompoundStmt { …
.BinaryOperator 40 + 2
  *IntegerLiteral 2

The dot prior to AST node kind indicates partial selection and the asterisk 
indicates complete selection according to SelectionTree::print 
.

By invoking `Tree.commonAncestor()` it would stop at `BinaryOperator` despite 
the fact that we're expecting `IntegerLiteral`, that represents the number 
being accordance with the macro expansion.

In order to address such case, I think we could go down the `SelectionTree` a 
little further and start evaluating at the node with complete selection.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148457

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


[PATCH] D146101: [clang-format] Add BracedInitializerIndentWidth option.

2023-04-28 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 updated this revision to Diff 517868.
jp4a50 added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4855,6 +4855,191 @@
"[5] = ee};");
 }
 
+TEST_F(FormatTest, BracedInitializerIndentWidth) {
+  auto Style = getLLVMStyleWithColumns(60);
+  Style.BinPackArguments = true;
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  Style.BracedInitializerIndentWidth = 6;
+
+  // Non-initializing braces are unaffected by BracedInitializerIndentWidth.
+  verifyFormat("enum class {\n"
+   "  One,\n"
+   "  Two,\n"
+   "};\n",
+   Style);
+  verifyFormat("class Foo {\n"
+   "  Foo() {}\n"
+   "  void bar();\n"
+   "};\n",
+   Style);
+  verifyFormat("void foo() {\n"
+   "  auto bar = baz;\n"
+   "  return baz;\n"
+   "};\n",
+   Style);
+  verifyFormat("auto foo = [&] {\n"
+   "  auto bar = baz;\n"
+   "  return baz;\n"
+   "};\n",
+   Style);
+  verifyFormat("{\n"
+   "  auto bar = baz;\n"
+   "  return baz;\n"
+   "};\n",
+   Style);
+  // Non-brace initialization is unaffected by BracedInitializerIndentWidth.
+  verifyFormat("SomeClass clazz(\n"
+   "\"xx\", \"yy\",\n"
+   "\"zz\");\n",
+   Style);
+
+  // The following types of initialization are all affected by
+  // BracedInitializerIndentWidth. Aggregate initialization.
+  verifyFormat("int LongVariable[2] = {\n"
+   "  1000, 2000};",
+   Style);
+  verifyFormat("SomeStruct s{\n"
+   "  \"\", \"\",\n"
+   "  \"\"};\n",
+   Style);
+  // Designated initializers.
+  verifyFormat("int LongVariable[1] = {\n"
+   "  [0] = 1000, [1] = 2000};",
+   Style);
+  verifyFormat("SomeStruct s{\n"
+   "  .foo = \"x\",\n"
+   "  .bar = \"y\",\n"
+   "  .baz = \"z\"};\n",
+   Style);
+  // List initialization.
+  verifyFormat("SomeStruct s{\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"z\",\n"
+   "};\n",
+   Style);
+  verifyFormat("SomeStruct{\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"z\",\n"
+   "};\n",
+   Style);
+  verifyFormat("new SomeStruct{\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"z\",\n"
+   "};\n",
+   Style);
+  // Member initializer.
+  verifyFormat("class SomeClass {\n"
+   "  SomeStruct s{\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "  };\n"
+   "};\n",
+   Style);
+  // Constructor member initializer.
+  verifyFormat("SomeClass::SomeClass : strct{\n"
+   " \"x\",\n"
+   " \"y\",\n"
+   " \"z\",\n"
+   "   } {}\n",
+   Style);
+  // Copy initialization.
+  verifyFormat("SomeStruct s = SomeStruct{\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"z\",\n"
+   "};\n",
+   Style);
+  // Copy list initialization.
+  verifyFormat("SomeStruct s = {\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"z\",\n"
+   "};\n",
+   Style);
+  // Assignment operand initialization.
+  verifyFormat("s = {\n"
+   "  \"x\",\n"
+   "  \"

[PATCH] D146101: [clang-format] Add BracedInitializerIndentWidth option.

2023-04-28 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

In D146101#4270509 , @owenpan wrote:

> In D146101#4268487 , @jp4a50 wrote:
>
>> Would appreciate someone committing for me.
>
> Can you rebase it? I got a conflict in ReleaseNotes.rst.

@owenpan apologies for the delay. I've rebased now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D149437: [clangd] Emit ChangeAnnotation label and description for include-cleaner diagnostics.

2023-04-28 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149437

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/test/include-cleaner-batch-fix.test

Index: clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
===
--- clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -152,11 +152,13 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "changeAnnotations": {
 # CHECK-NEXT:"AddAllMissingIncludes0": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "description": "Line 2: {{.*}}",
+# CHECK-NEXT:  "label": "Add {{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"AddAllMissingIncludes1": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "description": "Line 2: {{.*}}",
+# CHECK-NEXT:  "label": "Add {{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:}
 # CHECK-NEXT:  },
@@ -208,19 +210,21 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "changeAnnotations": {
 # CHECK-NEXT:"AddAllMissingIncludes0": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "description": "Line 2: ' Foo* foo; Bar* bar;'",
+# CHECK-NEXT:  "label": "Add {{.*}}bar.h{{.*}} for symbol 'Bar'",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"AddAllMissingIncludes1": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "description": "Line 2: ' Foo* foo; Bar* bar;'",
+# CHECK-NEXT:  "label": "Add {{.*}}foo.h{{.*}} for symbol 'Foo'",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"RemoveAllUnusedIncludes0": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "label": "Remove {{.*}}all1.h{{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"RemoveAllUnusedIncludes1": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "label": "Remove {{.*}}all2.h{{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:}
 # CHECK-NEXT:  },
@@ -337,11 +341,11 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "changeAnnotations": {
 # CHECK-NEXT:"RemoveAllUnusedIncludes0": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "label": "Remove {{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"RemoveAllUnusedIncludes1": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "label": "Remove {{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:}
 # CHECK-NEXT:  },
@@ -393,19 +397,21 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "changeAnnotations": {
 # CHECK-NEXT:"AddAllMissingIncludes0": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "description": "Line 2: {{.*}}",
+# CHECK-NEXT:  "label": "Add {{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"AddAllMissingIncludes1": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "description": "Line 2: {{.*}}",
+# CHECK-NEXT:  "label": "Add {{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"RemoveAllUnusedIncludes0": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "label": "Remove {{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"RemoveAllUnusedIncludes1": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "label": "Remove {{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:}
 # CHECK-NEXT:  },
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -163,10 +163,14 @@
   llvm_unreachable("Unknown symbol kind");
 }
 
-std::vector generateMissingIncludeDiagnostics(
+struct MissingIncludeDiag {
+  Diag D;
+  const MissingIncludeDiagInfo * DInfo = nullptr;
+};
+std::vector generateMissingIncludeDiagnostics(
 ParsedAST &AST, llvm::ArrayRef MissingIncludes,
 llvm::Str

[clang] 0fb84bc - [clang] Diagnose shadowing of lambda's template parameter by a capture

2023-04-28 Thread Mariya Podchishchaeva via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-04-28T07:26:30-04:00
New Revision: 0fb84bc7fdec1c20c2461e54d5c994939fe5b47f

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

LOG: [clang] Diagnose shadowing of lambda's template parameter by a capture

expr.prim.lambda.capture p5 says:
If an identifier in a capture appears as the declarator-id of a parameter of
the lambda-declarator's parameter-declaration-clause or as the name of a
template parameter of the lambda-expression's template-parameter-list,
the program is ill-formed.
and also has the following example:
```
auto h = [y = 0](y) { return 0; };
```
which now results in
```
error: declaration of 'y' shadows template parameter
  auto l1 = [y = 0](y) { return 0; };
 ^
note: template parameter is declared here
  auto l1 = [y = 0](y) { return 0; };
 ^
```

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

Reviewed By: shafik, cor3ntin

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

Added: 

clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaLambda.cpp
clang/test/SemaCXX/warn-shadow-in-lambdas.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8082e9d9f323e..a61e6615b9371 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -233,6 +233,8 @@ Improvements to Clang's diagnostics
 - ``-Wformat`` now recognizes ``%lb`` for the ``printf``/``scanf`` family of
   functions.
   (`#62247: `_).
+- Clang now diagnoses shadowing of lambda's template parameter by a capture.
+  (`#61105: `_).
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 7f9bec2f7627e..730f70e732579 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1365,6 +1365,26 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
 PushOnScopeChains(P, CurScope);
   }
 
+  // C++23 [expr.prim.lambda.capture]p5:
+  // If an identifier in a capture appears as the declarator-id of a parameter
+  // of the lambda-declarator's parameter-declaration-clause or as the name of 
a
+  // template parameter of the lambda-expression's template-parameter-list, the
+  // program is ill-formed.
+  TemplateParameterList *TemplateParams =
+  getGenericLambdaTemplateParameterList(LSI, *this);
+  if (TemplateParams) {
+for (const auto *TP : TemplateParams->asArray()) {
+  if (!TP->getIdentifier())
+continue;
+  for (const auto &Capture : Intro.Captures) {
+if (Capture.Id == TP->getIdentifier()) {
+  Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
+  Diag(TP->getLocation(), diag::note_template_param_here);
+}
+  }
+}
+  }
+
   // C++20: dcl.decl.general p4:
   // The optional requires-clause ([temp.pre]) in an init-declarator or
   // member-declarator shall be present only if the declarator declares a

diff  --git 
a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
 
b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
new file mode 100644
index 0..f0d337e5dd565
--- /dev/null
+++ 
b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+void f() {
+  int x = 0;
+  auto g = [x](int x) { return 0; }; // expected-error {{a lambda parameter 
cannot shadow an explicitly captured entity}} \
+ // expected-note {{variable 'x' is 
explicitly captured here}}
+  auto h = [y = 0](y) { return 0; };  // expected-error 
{{declaration of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+
+}

diff  --git a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp 
b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
index 9dddbf8b5f3b7..e5d4c69dcee06 100644
--- a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow 
-Wshadow-uncaptured-local %s
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow-all %s
 // RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only -Wshadow-all %s
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -Wshadow-all %s
 
 void foo(int param) { // expected-note 1+ {{previous declaration is here}}
   int var = 0; // expected-note 1+ {{previous declaration is here}}
@@ -146,3 +147

[PATCH] D148712: [clang] Diagnose shadowing of lambda's template parameter by a capture

2023-04-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0fb84bc7fdec: [clang] Diagnose shadowing of lambda's 
template parameter by a capture (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148712

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp


Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow 
-Wshadow-uncaptured-local %s
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow-all %s
 // RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only -Wshadow-all %s
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -Wshadow-all %s
 
 void foo(int param) { // expected-note 1+ {{previous declaration is here}}
   int var = 0; // expected-note 1+ {{previous declaration is here}}
@@ -146,3 +147,22 @@
 int b = 0; // expected-error {{redefinition of 'b'}}
   };
 }
+
+namespace GH61105 {
+void f() {
+  int y = 0;
+  int x = 0;
+#if __cplusplus >= 202002L
+  auto l1 = [y](y) { return 0; }; // expected-error {{declaration 
of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+  auto l2 = [=]() { int a = y; return 0; }; // expected-error 
{{'y' does not refer to a value}} \
+// expected-note 
{{declared here}}
+  auto l3 = [&, y](y) { int a = x; return 0; }; // 
expected-error {{declaration of 'y' shadows template parameter}} \
+  // 
expected-note {{template parameter is declared here}}
+  auto l4 = [x, y]() { return 0; }; // expected-error 
{{declaration of 'y' shadows template parameter}} \
+   // expected-error 
{{declaration of 'x' shadows template parameter}} \
+   // expected-note 
2{{template parameter is declared here}}
+  auto l5 = [](y) { return 0; }; // No diagnostic
+#endif
+}
+}
Index: 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
===
--- /dev/null
+++ 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+void f() {
+  int x = 0;
+  auto g = [x](int x) { return 0; }; // expected-error {{a lambda parameter 
cannot shadow an explicitly captured entity}} \
+ // expected-note {{variable 'x' is 
explicitly captured here}}
+  auto h = [y = 0](y) { return 0; };  // expected-error 
{{declaration of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+
+}
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1365,6 +1365,26 @@
 PushOnScopeChains(P, CurScope);
   }
 
+  // C++23 [expr.prim.lambda.capture]p5:
+  // If an identifier in a capture appears as the declarator-id of a parameter
+  // of the lambda-declarator's parameter-declaration-clause or as the name of 
a
+  // template parameter of the lambda-expression's template-parameter-list, the
+  // program is ill-formed.
+  TemplateParameterList *TemplateParams =
+  getGenericLambdaTemplateParameterList(LSI, *this);
+  if (TemplateParams) {
+for (const auto *TP : TemplateParams->asArray()) {
+  if (!TP->getIdentifier())
+continue;
+  for (const auto &Capture : Intro.Captures) {
+if (Capture.Id == TP->getIdentifier()) {
+  Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
+  Diag(TP->getLocation(), diag::note_template_param_here);
+}
+  }
+}
+  }
+
   // C++20: dcl.decl.general p4:
   // The optional requires-clause ([temp.pre]) in an init-declarator or
   // member-declarator shall be present only if the declarator declares a
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -233,6 +233,8 @@
 - ``-Wformat`` now recognizes ``%lb`` for the ``printf``/``scanf`` family of
   functions.
   (`#62247: `_).
+- Clang now diagnoses shadowing of lambda's template parameter by a capture.
+  (`#61105: 

[PATCH] D146389: [clang-repl][CUDA] Initial interactive CUDA support for clang-repl

2023-04-28 Thread Simeon Ehrig via Phabricator via cfe-commits
SimeonEhrig added a comment.

In D146389#4292984 , @tra wrote:

> lib/CodeGen changes look OK to me.

I can confirm the code change in CodeGen works as expected. `clang-repl` does 
not generate temporary files anymore, if a CUDA kernel is compiled.

Compiling a simple CUDA application still working and saving the generated PTX 
and fatbin code via `clang++ ../helloWorld.cu -o helloWorld 
-L/usr/local/cuda/lib64 -lcudart_static --save-temps` is also still working.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146389

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


[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-04-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

(This looks really cool, nice work! only a driveby comment from me I'm afraid)

In D148457#4304915 , @zyounan wrote:

> The dot prior to AST node kind indicates partial selection and the asterisk 
> indicates complete selection according to SelectionTree::print 
> .
>
> By invoking `Tree.commonAncestor()` it would stop at `BinaryOperator` despite 
> the fact that we're expecting `IntegerLiteral`, that represents the number 
> being accordance with the macro expansion.
>
> In order to address such case, I think we could go down the `SelectionTree` a 
> little further and start evaluating at the node with complete selection.

I think rather if the common ancestor isn't completely selected, evaluation 
shouldn't happen. (I think this is what Nathan was suggesting by "strict"?)

(Here, "+ 2" doesn't have a value, the + is binary rather than unary)

The partial/fully selected concept in SelectionTree was originally intended for 
exactly this kind of thing, so I'm happy to see it get some use :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148457

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


[PATCH] D149437: [clangd] Emit ChangeAnnotation label and description for include-cleaner diagnostics.

2023-04-28 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

VSCode UI:

- missing-include

F27261997: image.png 

- unused-include

F27262002: image.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149437

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


[PATCH] D148131: Avoid unnecessarily aggressive line-breaking when using "LambdaBodyIndentation: OuterScope" with argument bin-packing.

2023-04-28 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

Hey @MyDeveloperDay @owenpan . I'd appreciate if you guys have time to consider 
this change. It's the last significant issue my team and I are tracking that's 
blocking our adoption of clang-format for multiple codebases that use KJ 
 :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148131

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


[PATCH] D148462: [clang-tidy] Ignore declarations in bugprone-exception-escape

2023-04-28 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs accepted this revision.
isuckatcs added a comment.
This revision is now accepted and ready to land.

I think there's no point of holding back this patch. Even though I'm not 100% 
sure we want this change, I say let's merge it and see how our users react.

It's a one line change anyway, so if we receive a lot of complaints, it will be 
easy to revert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148462

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


[PATCH] D146054: [RISCV] Add --print-supported-extensions and -march=help support

2023-04-28 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added inline comments.



Comment at: clang/tools/driver/cc1_main.cpp:187-188
+/// Print supported extensions of the given target.
+static int PrintSupportedExtensions(std::string TargetStr) {
+  llvm::riscvMarchHelp();
+

Plz make sure only RISC-V print that, x86 or other target print RISC-V's ext is 
really weird. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146054

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


[PATCH] D148223: [SiFive] Support C intrinsics for xsfvcp extension.

2023-04-28 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng added a comment.

LGTM, but IMO the title should still contain [RISCV][clang]


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148223

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


[PATCH] D148308: [RISCV] Split out SiFive VCIX C intrinsics from riscv_vector.td

2023-04-28 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148308

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


[PATCH] D149144: [clang][dataflow] Eliminate intermediate `ReferenceValue`s from `Environment::DeclToLoc`.

2023-04-28 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.

Really nice patch. Thanks for this improvement!




Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:307-311
+  auto &ParamLoc =
+  createStorageLocation(ParamDecl->getType().getNonReferenceType());
   setStorageLocation(*ParamDecl, ParamLoc);
-  if (Value *ParamVal = createValue(ParamDecl->getType()))
-setValue(ParamLoc, *ParamVal);
+  if (Value *ParamVal =
+  createValue(ParamDecl->getType().getNonReferenceType()))

Maybe comment as to why we're not use the `VarDecl` overloads of 
`createStorageLocation` and why we're specifically using `getNonReferenceType` 
for `createValue`.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:610
   assert(!DeclToLoc.contains(&D));
+  assert(dyn_cast_or_null(getValue(Loc)) == nullptr);
   DeclToLoc[&D] = &Loc;





Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:631
+
+  assert(dyn_cast_or_null(getValue(*Loc)) == nullptr);
+

would `isa_and_nonnull` work?



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:279-281
+  if (auto *InitExprVal = Env.getValue(*InitExpr, SkipPast::None)) {
+Env.setValue(Loc, *InitExprVal);
+  }





Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:329
+  // against this above.
+  ProcessVarDecl(*VD);
+  auto *VDLoc = Env.getStorageLocation(*VD);

why the recursive call rather than relying on what we know about their 
structure?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149144

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


[PATCH] D149361: [profiling] Improve error message for raw profile header mismatches

2023-04-28 Thread Christian Ulmann via Phabricator via cfe-commits
Dinistro added inline comments.



Comment at: llvm/unittests/ProfileData/InstrProfTest.cpp:1359
   auto RawProfileReaderOrErr = InstrProfReader::create(std::move(RawProfile));
   ASSERT_TRUE(InstrProfError::take(RawProfileReaderOrErr.takeError()) ==
   instrprof_error::unrecognized_format);

Dinistro wrote:
> It seems that this and the following similar line do not compile. I assume 
> that the necessary flags to activate this test were not provided in the CI 
> executed for this revision. 
> 
> Crashing build: 
> https://lab.llvm.org/buildbot/#/builders/104/builds/11668/steps/6/logs/stdio
I creatred and landed a revision that fixes this 
https://reviews.llvm.org/D149434


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149361

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Hey! I wish you'd given me a chance to review this fix version before 
committing!  I don't have concerns now looking at it, however please add a 
release note, since this is fixing a whole-bunch of regressions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

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


[clang] d75e70d - [AArch64] Add preserve_all calling convention.

2023-04-28 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2023-04-28T14:55:38+02:00
New Revision: d75e70d7ae1f84cea71f0be5fbee836bdc22138a

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

LOG: [AArch64] Add preserve_all calling convention.

Clang accepts preserve_all for AArch64 while it is missing form the backed.

Fixes #58145

Reviewed By: efriedma

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

Added: 
llvm/test/CodeGen/AArch64/arm64-preserve-all.ll
llvm/test/CodeGen/AArch64/preserve.ll
llvm/test/CodeGen/AArch64/tailcall-ccmismatch2.ll

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/AttrDocs.td
llvm/docs/LangRef.rst
llvm/docs/ReleaseNotes.rst
llvm/lib/Target/AArch64/AArch64CallingConvention.td
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
llvm/lib/Target/ARM/ARMISelLowering.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a61e6615b9371..87db8cedd6a7b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -432,6 +432,9 @@ Arm and AArch64 Support
  // int a = foo(); int* b = bar();
  asm("ands %w[a], %w[a], #3" : [a] "+r"(a), "=@cceq"(*b));
 
+- Fix a crash when ``preserve_all`` calling convention is used on AArch64.
+  `Issue 58145 `_
+
 Windows Support
 ^^^
 

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index dae12624a822b..0a0afe619ec2c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5182,6 +5182,9 @@ apply for values returned in callee-saved registers.
   R11. R11 can be used as a scratch register. Floating-point registers
   (XMMs/YMMs) are not preserved and need to be saved by the caller.
 
+- On AArch64 the callee preserve all general purpose registers, except X0-X8 
and
+  X16-X18.
+
 The idea behind this convention is to support calls to runtime functions
 that have a hot path and a cold path. The hot path is usually a small piece
 of code that doesn't use many registers. The cold path might need to call out 
to
@@ -5222,6 +5225,10 @@ returned in callee-saved registers.
   R11. R11 can be used as a scratch register. Furthermore it also preserves
   all floating-point registers (XMMs/YMMs).
 
+- On AArch64 the callee preserve all general purpose registers, except X0-X8 
and
+  X16-X18. Furthermore it also preserves lower 128 bits of V8-V31 SIMD - 
floating
+  point registers.
+
 The idea behind this convention is to support calls to runtime functions
 that don't need to call out to any other functions.
 

diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index a0d012d3a14f5..48e658d08e7b3 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -370,6 +370,9 @@ added in the future:
   Floating-point registers (XMMs/YMMs) are not preserved and need to be
   saved by the caller.
 
+- On AArch64 the callee preserve all general purpose registers, except 
X0-X8
+  and X16-X18.
+
 The idea behind this convention is to support calls to runtime functions
 that have a hot path and a cold path. The hot path is usually a small piece
 of code that doesn't use many registers. The cold path might need to call 
out to
@@ -404,6 +407,10 @@ added in the future:
   R11. R11 can be used as a scratch register. Furthermore it also preserves
   all floating-point registers (XMMs/YMMs).
 
+- On AArch64 the callee preserve all general purpose registers, except 
X0-X8
+  and X16-X18. Furthermore it also preserves lower 128 bits of V8-V31 SIMD 
-
+  floating point registers.
+
 The idea behind this convention is to support calls to runtime functions
 that don't need to call out to any other functions.
 

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index c5bf6cbeb6fde..334365fa0a8a4 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -84,6 +84,7 @@ Changes to the AArch64 Backend
 
 * Added Assembly Support for the 2022 A-profile extensions FEAT_GCS (Guarded
   Control Stacks), FEAT_CHK (Check Feature Status), and FEAT_ATS1A.
+* Support for preserve_all calling convention is added.
 
 Changes to the AMDGPU Backend
 -

diff  --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.td 
b/llvm/lib/Target/AArch64/AArch64CallingConvention.td
index 853975c6193d9..ce087be79202e 100644
--- a/llvm/lib/Target/AArch64/AArch64CallingConvention.td
+++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.td
@@ -489,6 +489,9 @@ def CS

[PATCH] D135652: [AArch64] Add preserve_all calling convention.

2023-04-28 Thread Daniel Kiss 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 rGd75e70d7ae1f: [AArch64] Add preserve_all calling convention. 
(authored by danielkiss).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135652

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/AttrDocs.td
  llvm/docs/LangRef.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Target/AArch64/AArch64CallingConvention.td
  llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
  llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/test/CodeGen/AArch64/arm64-preserve-all.ll
  llvm/test/CodeGen/AArch64/preserve.ll
  llvm/test/CodeGen/AArch64/tailcall-ccmismatch2.ll

Index: llvm/test/CodeGen/AArch64/tailcall-ccmismatch2.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/tailcall-ccmismatch2.ll
@@ -0,0 +1,25 @@
+; RUN: llc -o - %s | FileCheck %s
+; RUN: llc -global-isel -verify-machineinstrs -o - %s | FileCheck %s
+target triple="aarch64--"
+
+declare void @somefunc()
+define preserve_allcc void @test_ccmismatch_notail() {
+; Ensure that no tail call is used here, as the called function somefunc does
+; not preserve enough registers for preserve_allcc.
+; CHECK-LABEL: test_ccmismatch_notail:
+; CHECK-NOT: b somefunc
+; CHECK: bl somefunc
+  tail call void @somefunc()
+  ret void
+}
+
+declare preserve_allcc void @some_preserve_all_func()
+define void @test_ccmismatch_tail() {
+; We can perform a tail call here, because some_preserve_all_func preserves
+; all registers necessary for test_ccmismatch_tail.
+; CHECK-LABEL: test_ccmismatch_tail:
+; CHECK-NOT: bl some_preserve_all_func
+; CHECK: b some_preserve_all_func
+  tail call preserve_allcc void @some_preserve_all_func()
+  ret void
+}
Index: llvm/test/CodeGen/AArch64/preserve.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/preserve.ll
@@ -0,0 +1,22 @@
+
+; RUN: llc -enable-ipra -print-regusage -o /dev/null 2>&1 < %s | FileCheck %s
+
+target triple = "aarch64-unknown-unknown"
+declare void @bar1()
+define preserve_mostcc void @baz() #0 {
+; CHECK: baz Clobbered Registers: $ffr $fpcr $nzcv $sp $vg $wsp $za $b0 $b1 $b2 $b3 $b4 $b5 $b6 $b7 $b16 $b17 $b18 $b19 $b20 $b21 $b22 $b23 $b24 $b25 $b26 $b27 $b28 $b29 $b30 $b31 $d0 $d1 $d2 $d3 $d4 $d5 $d6 $d7 $d16 $d17 $d18 $d19 $d20 $d21 $d22 $d23 $d24 $d25 $d26 $d27 $d28 $d29 $d30 $d31 $h0 $h1 $h2 $h3 $h4 $h5 $h6 $h7 $h16 $h17 $h18 $h19 $h20 $h21 $h22 $h23 $h24 $h25 $h26 $h27 $h28 $h29 $h30 $h31 $p0 $p1 $p2 $p3 $p4 $p5 $p6 $p7 $p8 $p9 $p10 $p11 $p12 $p13 $p14 $p15 $q0 $q1 $q2 $q3 $q4 $q5 $q6 $q7 $q8 $q9 $q10 $q11 $q12 $q13 $q14 $q15 $q16 $q17 $q18 $q19 $q20 $q21 $q22 $q23 $q24 $q25 $q26 $q27 $q28 $q29 $q30 $q31 $s0 $s1 $s2 $s3 $s4 $s5 $s6 $s7 $s16 $s17 $s18 $s19 $s20 $s21 $s22 $s23 $s24 $s25 $s26 $s27 $s28 $s29 $s30 $s31 $w0 $w1 $w2 $w3 $w4 $w5 $w6 $w7 $w8 $w16 $w17 $w18 $x0 $x1 $x2 $x3 $x4 $x5 $x6 $x7 $x8 $x16 $x17 $x18 $z0 $z1 $z2 $z3 $z4 $z5 $z6 $z7 $z8 $z9 $z10 $z11 $z12 $z13 $z14 $z15 $z16 $z17 $z18 $z19 $z20 $z21 $z22 $z23 $z24 $z25 $z26 $z27 $z28 $z29 $z30 $z31 $zab0 $zad0 $zad1 $zad2 $zad3 $zad4 $zad5 $zad6 $zad7 $zah0 $zah1 $zaq0 $zaq1 $zaq2 $zaq3 $zaq4 $zaq5 $zaq6 $zaq7 $zaq8 $zaq9 $zaq10 $zaq11 $zaq12 $zaq13 $zaq14 $zaq15 $zas0 $zas1 $zas2 $zas3 $zt0 $z0_hi $z1_hi $z2_hi $z3_hi $z4_hi $z5_hi $z6_hi $z7_hi $z8_hi $z9_hi $z10_hi $z11_hi $z12_hi $z13_hi $z14_hi $z15_hi $z16_hi $z17_hi $z18_hi $z19_hi $z20_hi $z21_hi $z22_hi $z23_hi $z24_hi $z25_hi $z26_hi $z27_hi $z28_hi $z29_hi $z30_hi $z31_hi $d0_d1 $d1_d2 $d2_d3 $d3_d4 $d4_d5 $d5_d6 $d6_d7 $d7_d8 $d15_d16 $d16_d17 $d17_d18 $d18_d19 $d19_d20 $d20_d21 $d21_d22 $d22_d23 $d23_d24 $d24_d25 $d25_d26 $d26_d27 $d27_d28 $d28_d29 $d29_d30 $d30_d31 $d31_d0 $d0_d1_d2_d3 $d1_d2_d3_d4 $d2_d3_d4_d5 $d3_d4_d5_d6 $d4_d5_d6_d7 $d5_d6_d7_d8 $d6_d7_d8_d9 $d7_d8_d9_d10 $d13_d14_d15_d16 $d14_d15_d16_d17 $d15_d16_d17_d18 $d16_d17_d18_d19 $d17_d18_d19_d20 $d18_d19_d20_d21 $d19_d20_d21_d22 $d20_d21_d22_d23 $d21_d22_d23_d24 $d22_d23_d24_d25 $d23_d24_d25_d26 $d24_d25_d26_d27 $d25_d26_d27_d28 $d26_d27_d28_d29 $d27_d28_d29_d30 $d28_d29_d30_d31 $d29_d30_d31_d0 $d30_d31_d0_d1 $d31_d0_d1_d2 $d0_d1_d2 $d1_d2_d3 $d2_d3_d4 $d3_d4_d5 $d4_d5_d6 $d5_d6_d7 $d6_d7_d8 $d7_d8_d9 $d14_d15_d16 $d15_d16_d17 $d16_d17_d18 $d17_d18_d19 $d18_d19_d20 $d19_d20_d21 $d20_d21_d22 $d21_d22_d23 $d22_d23_d24 $d23_d24_d25 $d24_d25_d26 $d25_d26_d27 $d26_d27_d28 $d27_d28_d29 $d28_d29_d30 $d29_d30_d31 $d30_d31_d0 $d31_d0_d1 $p0_p1 $p1_p2 $p2_p3 $p3_p4 $p4_p5 $p5_p6 $p6_p7 $p7_p8 $p8_p9 $p9_p10 $p10_p11 $p11_p12 $p12_p13 $p13_p14 $p14_p15 $p15_p0

[PATCH] D149163: [NFC][CLANG] Fix coverity remarks about large copy by values

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
Manna marked 4 inline comments as done.
Manna added inline comments.



Comment at: clang/lib/CodeGen/CGGPUBuiltin.cpp:128
 
-bool containsNonScalarVarargs(CodeGenFunction *CGF, CallArgList Args) {
+bool containsNonScalarVarargs(CodeGenFunction *CGF, const CallArgList &Args) {
   return llvm::any_of(llvm::drop_begin(Args), [&](const CallArg &A) {

tahonermann wrote:
> This looks like a good change; `CallArgList` derives from 
> `SmallVector` and holds a few other `SmallVector` specializations 
> as data members.
>>CallArgList derives from SmallVector and holds a few other 
>>SmallVector specializations as data members.

Yes



Comment at: clang/lib/CodeGen/CodeGenModule.h:1714
   /// the backend to LLVM.
-  void EmitBackendOptionsMetadata(const CodeGenOptions CodeGenOpts);
+  void EmitBackendOptionsMetadata(const CodeGenOptions &CodeGenOpts);
 

tahonermann wrote:
> This is definitely a good change; it seems likely that the omission of the 
> `&` was not intentional.
Agreed 



Comment at: clang/lib/Sema/SemaType.cpp:4556
 
-static bool IsNoDerefableChunk(DeclaratorChunk Chunk) {
+static bool IsNoDerefableChunk(const DeclaratorChunk &Chunk) {
   return (Chunk.Kind == DeclaratorChunk::Pointer ||

tahonermann wrote:
> The definition of `DeclaratorChunk` has this comment:
>   /// This is intended to be a small value object.
> 
> However, it contains what looks likely to be a sizable anonymous union. See 
> `clang/include/clang/Sema/DeclSpec.h` lines 1587-1595 and the definition of 
> `FunctionTypeInfo` in that same file. I don't see other pass-by-value uses of 
> this type. Perhaps the above comment should be removed.
Thanks @tahonermann for reviews and feedbacks. 

>>See clang/include/clang/Sema/DeclSpec.h lines 1587-1595 and the definition of 
>>FunctionTypeInfo in that same file. I don't see other pass-by-value uses of 
>>this type. 

Yes, this is what i saw in same file 
(https://clang.llvm.org/doxygen/SemaType_8cpp_source.html) while investigating 
this bug - it is usually passing by const references.


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

https://reviews.llvm.org/D149163

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


[PATCH] D148822: [clang][BFloat] Avoid redefining bfloat16_t in arm_neon.h

2023-04-28 Thread Simon Butcher via Phabricator via cfe-commits
simonbutcher added a comment.

I can't see anything wrong with this patch and it looks pretty straightforward 
to me, but is it necessary?

'-Wtypedef-redefinition' is documented as not applying to system headers 
,
 and I couldn't reproduce the issue unless I changed the headers to not be 
system headers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148822

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


[PATCH] D148663: [RFC][clangd] Use interpolation for CDB pushed via LSP protocol

2023-04-28 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D148663#4301589 , @DmitryPolukhin 
wrote:

> And, if they do so, this diff will just does nothing because there is an 
> exact match. It starts playing only if client provided partial CDB and 
> inference is required.

(hypothesising below)
I think this depends on a client at question. If I were writing one and had an 
idea what I want to do for headers, e.g. I might have a project system that 
knows which build targets headers belong to,
I would rather see no compile errors for a header (if I have bugs in my 
integration) than for Clangd to kick in with interpolation and silently hide 
the bug.

From what I can recollect, your case is different and you just want to "pipe" 
`compile_commands.json` to Clangd provided by some build system, but without 
`clangd` actually reading it.
I don't actually write an LSP client, though, would let @kadircet decide which 
path is preferable.

> Pushing command via LSP might be preferable in comparison with file based 
> approach to avoid race condition with updating the file and clangd reading it

Ideally this should be handled with atomic writes (write to temp file and move 
to destination), at least on Linux and Mac. I'm not sure if build systems do 
that, though.
Does Clangd ever re-read the compilation database now? It used to load it only 
once, so rereading would require a restart of clangd anyway. Race on just one 
read is very unlikely (although not impossible).
However, the `compile_commands.json` file is parsed lazily, when the command 
for a particular file is actually requested, if you see crashes or 
inconsistencies in your scenarios, it highly likely due to this.

> + it works better with build systems that can generate compiles commands on 
> the fly for files and generating all of them in advance may not be possible.

FYI, there is separate support for pushing command per-file in Clangd via an 
LSP extension 
.
I think this should cover build systems that generate commands on the fly 
better, but this also does not use interpolation.

A meta-comment: it would be really useful to understand how you use Clangd a 
bit better. Would it be hard to write down which kind of client you have and 
what are requirements for Clangd? Which build systems are at play, how does the 
client use them, etc?
To validate whether patches like this one are a good fit to solve the problem 
or there are better ways, it's really useful to have a higher level overview of 
how Clangd is being used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148663

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


[PATCH] D149444: [ARM] Allow codegen for Armv6m eXecute-Only (XO) sections

2023-04-28 Thread Ties Stuij via Phabricator via cfe-commits
stuij created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
stuij requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

This patch moves the overall lower-bound arch restriction for Arm XO sections
from v8m to v6m. Actual implementation of code-gen for v6m will follow in
follow-up patches, which will include an implementation of relocations needed to
support this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149444

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  llvm/lib/Target/ARM/ARMSubtarget.cpp


Index: llvm/lib/Target/ARM/ARMSubtarget.cpp
===
--- llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -191,7 +191,7 @@
   // Execute only support requires movt support
   if (genExecuteOnly()) {
 NoMovt = false;
-assert(hasV8MBaselineOps() && "Cannot generate execute-only code for this 
target");
+assert(hasV6MOps() && "Cannot generate execute-only code for this target");
   }
 
   // Keep a pointer to static instruction cost data for the specified CPU.
@@ -431,7 +431,7 @@
   // NOTE Windows on ARM needs to use mov.w/mov.t pairs to materialise 32-bit
   // immediates as it is inherently position independent, and may be out of
   // range otherwise.
-  return !NoMovt && hasV8MBaselineOps() &&
+  return !NoMovt && hasV6MOps() &&
  (isTargetWindows() || !OptMinSize || genExecuteOnly());
 }
 
Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -779,7 +779,8 @@
 if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, 
options::OPT_mno_execute_only)) {
   if (A->getOption().matches(options::OPT_mexecute_only)) {
 if (getARMSubArchVersionNumber(Triple) < 7 &&
-llvm::ARM::parseArch(Triple.getArchName()) != 
llvm::ARM::ArchKind::ARMV6T2)
+llvm::ARM::parseArch(Triple.getArchName()) != 
llvm::ARM::ArchKind::ARMV6T2 &&
+ llvm::ARM::parseArch(Triple.getArchName()) != 
llvm::ARM::ArchKind::ARMV6M)
   D.Diag(diag::err_target_unsupported_execute_only) << 
Triple.getArchName();
 else if (Arg *B = Args.getLastArg(options::OPT_mno_movt))
   D.Diag(diag::err_opt_not_valid_with_opt)


Index: llvm/lib/Target/ARM/ARMSubtarget.cpp
===
--- llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -191,7 +191,7 @@
   // Execute only support requires movt support
   if (genExecuteOnly()) {
 NoMovt = false;
-assert(hasV8MBaselineOps() && "Cannot generate execute-only code for this target");
+assert(hasV6MOps() && "Cannot generate execute-only code for this target");
   }
 
   // Keep a pointer to static instruction cost data for the specified CPU.
@@ -431,7 +431,7 @@
   // NOTE Windows on ARM needs to use mov.w/mov.t pairs to materialise 32-bit
   // immediates as it is inherently position independent, and may be out of
   // range otherwise.
-  return !NoMovt && hasV8MBaselineOps() &&
+  return !NoMovt && hasV6MOps() &&
  (isTargetWindows() || !OptMinSize || genExecuteOnly());
 }
 
Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -779,7 +779,8 @@
 if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, options::OPT_mno_execute_only)) {
   if (A->getOption().matches(options::OPT_mexecute_only)) {
 if (getARMSubArchVersionNumber(Triple) < 7 &&
-llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::ArchKind::ARMV6T2)
+llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::ArchKind::ARMV6T2 &&
+ llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::ArchKind::ARMV6M)
   D.Diag(diag::err_target_unsupported_execute_only) << Triple.getArchName();
 else if (Arg *B = Args.getLastArg(options::OPT_mno_movt))
   D.Diag(diag::err_opt_not_valid_with_opt)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146269: MIPS: allow o32 abi with 64bit CPU and 64 abi with 32bit triple

2023-04-28 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa updated this revision to Diff 517903.

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

https://reviews.llvm.org/D146269

Files:
  clang/lib/Basic/Targets/Mips.cpp
  clang/test/Driver/mips-abi.c
  clang/test/Driver/mips-cpu64abi32.c
  llvm/lib/Target/Mips/MipsSubtarget.cpp

Index: llvm/lib/Target/Mips/MipsSubtarget.cpp
===
--- llvm/lib/Target/Mips/MipsSubtarget.cpp
+++ llvm/lib/Target/Mips/MipsSubtarget.cpp
@@ -104,8 +104,7 @@
 report_fatal_error("Code generation for MIPS-V is not implemented", false);
 
   // Check if Architecture and ABI are compatible.
-  assert(((!isGP64bit() && isABI_O32()) ||
-  (isGP64bit() && (isABI_N32() || isABI_N64( &&
+  assert(((!isGP64bit() && isABI_O32()) || isGP64bit()) &&
  "Invalid  Arch & ABI pair.");
 
   if (hasMSA() && !isFP64bit())
Index: clang/test/Driver/mips-cpu64abi32.c
===
--- /dev/null
+++ clang/test/Driver/mips-cpu64abi32.c
@@ -0,0 +1,68 @@
+/// Check handling the CPU is 64bit while ABI is O32.
+/// when build for MIPS platforms.
+
+/// abi-n32
+// RUN: %clang -### -c %s --target=mips-linux-gnu -mabi=n32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABI-N32 %s
+// CHECK-ABI-N32: "-target-abi" "n32"
+
+/// abi-64
+// RUN: %clang -### -c %s --target=mips-linux-gnu -mabi=64 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABI-64 %s
+// CHECK-ABI-64: "-target-abi" "n64"
+
+
+/// -march=mips3
+// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips3 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPS3 %s
+// CHECK-MIPS-MIPS3: "-target-cpu" "mips3" {{.*}} "-target-abi" "o32"
+
+/// -march=mips4
+// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips4 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPS4 %s
+// CHECK-MIPS-MIPS4: "-target-cpu" "mips4" {{.*}} "-target-abi" "o32"
+
+/// FIXME: MIPS V is not implemented yet.
+
+/// -march=mips64
+/// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips64 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPS64 %s
+// CHECK-MIPS-MIPS64: "-target-cpu" "mips64" {{.*}} "-target-abi" "o32"
+
+/// -march=mips64r2
+/// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips64r2 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPS64R2 %s
+// CHECK-MIPS-MIPS64R2: "-target-cpu" "mips64r2" {{.*}} "-target-abi" "o32"
+
+/// -march=mips64r6
+// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips64r6 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPS64R6 %s
+// CHECK-MIPS-MIPS64R6: "-target-cpu" "mips64r6" {{.*}} "-target-abi" "o32"
+
+
+/// mipsisa3
+// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips3 -mabi=32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPSISA3 %s
+// CHECK-MIPS-MIPSISA3: "-target-cpu" "mips3" {{.*}} "-target-abi" "o32"
+
+/// mipsisa4
+// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips4 -mabi=32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPSISA4 %s
+// CHECK-MIPS-MIPSISA4: "-target-cpu" "mips4" {{.*}} "-target-abi" "o32"
+
+/// FIXME: MIPS V is not implemented yet.
+
+/// mipsisa64
+// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips64 -mabi=32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPSISA64 %s
+// CHECK-MIPS-MIPSISA64: "-target-cpu" "mips64" {{.*}} "-target-abi" "o32"
+
+/// mipsisa64r2
+// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips64r2 -mabi=32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPSISA64R2 %s
+// CHECK-MIPS-MIPSISA64R2: "-target-cpu" "mips64r2" {{.*}} "-target-abi" "o32"
+
+/// mipsisa64r6
+// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips64r6 -mabi=32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPSISA64R6 %s
+// CHECK-MIPS-MIPSISA64R6: "-target-cpu" "mips64r6" {{.*}} "-target-abi" "o32"
Index: clang/test/Driver/mips-abi.c
===
--- clang/test/Driver/mips-abi.c
+++ clang/test/Driver/mips-abi.c
@@ -9,13 +9,6 @@
 // MIPS32R2-O32: "-target-cpu" "mips32r2"
 // MIPS32R2-O32: "-target-abi" "o32"
 //
-// FIXME: This is a valid combination of options but we reject it at the moment
-//because the backend can't handle it.
-// RUN: not %clang -target mips-linux-gnu -c %s \
-// RUN:-march=mips64r2 -mabi=32 2>&1 \
-// RUN:   | FileCheck -check-prefix=MIPS64R2-O32 %s
-// MIPS64R2-O32: error: ABI 'o32' is not supported on CPU 'mips64r2'
-//
 // RUN: %clang -target mips64-linux-gnu -### -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS64R2-N64 %s
 // RUN: %clang -target mips-img-linux-gnu -mips64r2 -### -c %s 2>&1 \
Index: clang/lib/Basic/Targets/Mips.cpp
===
--- clang/lib/Basic/Targets/Mips.cpp
+++ clang/lib/Basic/Targets/Mips.cpp
@@ -238,12 +238,6 @@
 Diags.Report(diag::err_target_u

[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-04-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

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


[PATCH] D149447: [clang][analyzer] Improve documentation of StdCLibraryFunctionArgs checker (NFC)

2023-04-28 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Documentation is made more exact, term "constraint" is removed entirely,
description of checker option is corrected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149447

Files:
  clang/docs/analyzer/checkers.rst

Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -2434,7 +2434,7 @@
 
   void test_alnum_concrete(int v) {
 int ret = isalnum(256); // \
-// warning: Function argument constraint is not satisfied
+// warning: Function argument outside of allowed range
 (void)ret;
   }
 
@@ -2456,24 +2456,25 @@
 If the user disables the checker then the argument violation warning is
 suppressed. However, the assumption about the argument is still modeled. This
 is because exploring an execution path that already contains undefined behavior
-is not valuable.
+is not valuable. This applies to all the restrictions that are listed below.
 
-There are different kind of constraints modeled: range constraint, not null
-constraint, buffer size constraint. A **range constraint** requires the
-argument's value to be in a specific range, see ``isalnum`` as an example above.
-A **not null constraint** requires the pointer argument to be non-null.
-
-A **buffer size** constraint specifies the minimum size of the buffer
-argument. The size might be a known constant. For example, ``asctime_r`` requires
-that the buffer argument's size must be greater than or equal to ``26`` bytes. In
-other cases, the size is denoted by another argument or as a multiplication of
-two arguments.
-For instance, ``size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)``.
-Here, ``ptr`` is the buffer, and its minimum size is ``size * nmemb``
+There may be different restrictions about values passed as function arguments.
+ - The argument has an allowed range (or multiple ranges) of values. The checker
+   can detect if a passed value is outside of the allowed range and show the
+   actual and allowed values.
+ - The argument has pointer type and is not allowed to be null pointer. Many
+   (but not all) standard functions can produce undefined behavior if a null
+   pointer is passed, these cases can be detected by the checker.
+ - The argument is a pointer to a memory block and the minimal size of this
+   buffer is determined by another argument to the function, or by
+   multiplication of two arguments (like at function ``fread``), or is a fixed
+   value (for example ``asctime_r`` requires at least a buffer of size 26). The
+   checker can detect if the buffer size is too small and in optimal case show
+   the size of the buffer and the values of the corresponding arguments.
 
 .. code-block:: c
 
-  void buffer_size_constraint_violation(FILE *file) {
+  void buffer_size_violation(FILE *file) {
 enum { BUFFER_SIZE = 1024 };
 wchar_t wbuf[BUFFER_SIZE];
 
@@ -2486,22 +2487,62 @@
 fread(wbuf, size, nitems, file);
   }
 
+**List of checked functions**
+
+``fgetc``, ``fread``, ``fwrite``, ``getc``, ``getchar``, ``getdelim``,
+``getenv``, ``getline``, ``isalnum``, ``isalpha``, ``isascii``, ``isblank``,
+``isdigit``, ``isgraph``, ``islower``, ``isprint``, ``ispunct``, ``isspace``,
+``isupper``, ``isxdigit``, ``read``, ``toascii``, ``tolower``, ``toupper``,
+``write``
+
+Additional functions in POSIX mode (see Parameters below):
+
+``a64l``, ``accept``, ``access``, ``alarm``, ``asctime_r``, ``bind``, ``chdir``,
+``chmod``, ``chown``, ``clock_gettime``, ``close``, ``closedir``, ``connect``,
+``creat``, ``ctime_r``, ``dirfd``, ``dup``, ``dup2``, ``execv``, ``execvp``,
+``faccessat``, ``fchmod``, ``fchmodat``, ``fchown``, ``fchownat``, ``fclose``,
+``fdatasync``, ``fdopen``, ``fdopendir``, ``fileno``, ``fileno``, ``fnmatch``,
+``fopen``, ``fpathconf``, ``freopen``, ``fseek``, ``fseeko``, ``fstat``,
+``fstatat``, ``fsync``, ``ftello``, ``futimens``, ``getcwd``, ``getitimer``,
+``getnameinfo``, ``getopt``, ``getpeername``, ``getsockname``, ``getsockopt``,
+``gmtime``, ``gmtime_r``, ``isatty``, ``l64a``, ``lchown``, ``link``,
+``linkat``, ``listen``, ``localtime``, ``localtime_r``, ``lockf``, ``lseek``,
+``lstat``, ``mkdir``, ``mkdirat``, ``mkdtemp``, ``mknod``, ``mknodat``,
+``mkstemp``, ``mmap``, ``mmap64``, ``nanosleep``, ``opendir``, ``pathconf``,
+``pclose``, ``pipe``, ``popen``, ``pthread_attr_destroy``,
+``pthread_attr_getguardsize``, ``pthread_attr_getstacksize``,
+``pthread_attr_init``, ``pthread_attr_setguardsize``,
+``pthread_attr_setstacksize``, ``pthread_cond_broadcast``,
+``pthread_cond_signal``, ``pthread_c

[PATCH] D149436: [clang] Do not attempt to zero-extend _BitInt(1) when not required

2023-04-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

This looks right to me, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149436

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


[PATCH] D148663: [RFC][clangd] Use interpolation for CDB pushed via LSP protocol

2023-04-28 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

In D148663#4305202 , @ilya-biryukov 
wrote:

> In D148663#4301589 , 
> @DmitryPolukhin wrote:
>
>> And, if they do so, this diff will just does nothing because there is an 
>> exact match. It starts playing only if client provided partial CDB and 
>> inference is required.
>
> (hypothesising below)
> I think this depends on a client at question. If I were writing one and had 
> an idea what I want to do for headers, e.g. I might have a project system 
> that knows which build targets headers belong to,
> I would rather see no compile errors for a header (if I have bugs in my 
> integration) than for Clangd to kick in with interpolation and silently hide 
> the bug.
>
> From what I can recollect, your case is different and you just want to "pipe" 
> `compile_commands.json` to Clangd provided by some build system, but without 
> `clangd` actually reading it.
> I don't actually write an LSP client, though, would let @kadircet decide 
> which path is preferable.

We have LSP client that works like a proxy and exposes LSP protocol to higher 
level. Now we do very deep processing of CDB and partially replicates logic 
clangd about command inference.
Clangd usually does good job in command inference and we would like to use this 
feature instead of keep our logic up-to-date. I can put this inference logic 
for LSP behind some command line flag
if you think that it might really break some good use case. Please let me know.

>> Pushing command via LSP might be preferable in comparison with file based 
>> approach to avoid race condition with updating the file and clangd reading it
>
> Ideally this should be handled with atomic writes (write to temp file and 
> move to destination), at least on Linux and Mac. I'm not sure if build 
> systems do that, though.
> Does Clangd ever re-read the compilation database now? It used to load it 
> only once, so rereading would require a restart of clangd anyway. Race on 
> just one read is very unlikely (although not impossible).
> However, the `compile_commands.json` file is parsed lazily, when the command 
> for a particular file is actually requested, if you see crashes or 
> inconsistencies in your scenarios, it highly likely due to this.

Yes, clangd re-read CDB in some cases but it won't try to read CDB again from a 
directory if there was none before for performance reasons I think. I think 
synchronisation here is hard we cannot control when
clangd will actually read CDB so it might use wrong flags. Also we run multiple 
clangd behind multiplexing proxy and they might need different CDBs. Also CDB 
tends to become large and hard to manage so
per-file LSP protocol has lots of advantages for us.

>> + it works better with build systems that can generate compiles commands on 
>> the fly for files and generating all of them in advance may not be possible.
>
> FYI, there is separate support for pushing command per-file in Clangd via an 
> LSP extension 
> .
> I think this should cover build systems that generate commands on the fly 
> better, but this also does not use interpolation.

It is exactly the LSP protocol we are using and I added inference.

> A meta-comment: it would be really useful to understand how you use Clangd a 
> bit better. Would it be hard to write down which kind of client you have and 
> what are requirements for Clangd? Which build systems are at play, how does 
> the client use them, etc?
> To validate whether patches like this one are a good fit to solve the problem 
> or there are better ways, it's really useful to have a higher level overview 
> of how Clangd is being used.

We use Buck  and Buck2  as our main 
build system + some projects uses other build systems like CMake, and in 
general we don't limit build systems that subproject might use.
Therefore we cannot limit ourself to any particular clangd version and had to 
support multiple of them simultaneously because individual projects might might 
use incompatible features. So we have a LSP multiplexing proxy that 
encapsulates build system specifics and combines results from several clangds. 
Changes in clangd that we would like to put in upstream in our understanding 
should be usable not only in our setup but should also improve clangd for all 
users.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148663

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


[PATCH] D149364: [CUDA] Temporarily undefine __noinline__ when including bits/shared_ptr_base.h

2023-04-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.

LGTM.

This issue does not affect HIP as HIP headers have removed `__noinline__` as a 
macro since https://reviews.llvm.org/D124866 and 
`__attribute__((__noinline__))` is equivalent to `__attribute__((noinline))` 
for HIP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149364

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 517921.
TIFitis added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -12,28 +12,24 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
 // CHECK-LABEL: define void @_QPopenmp_target_data() {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   [[VAL_4]]:
+// CHECK: %[[VAL_2:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
 // CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_5]], align 8
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_5]], align 8
 // CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_7]], align 4
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_8]], ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_12:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_13:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_11]], ptr %[[VAL_12]], ptr %[[VAL_13]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[VAL_2]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
 // CHECK: ret void
 
 // -
@@ -52,34 +48,30 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4096]
 // CHECK-LABEL: define void @_QPopenmp_target_data_region
 // CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: br label %[[VAL_3:.*]]
-// CHECK:   [[VAL_3]]:
+// CHECK: br label %[[VAL_2:.*]]
+// CHECK:   entry:; preds = %[[VAL_3:.*]]
 // CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_5:.*]], ptr %[[VAL_

[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis planned changes to this revision.
TIFitis added a comment.

@kiranchandramohan I am in the process of submitting a new patch for review 
which moves the map processing from Clang Codegen to OMPIRBuilder. Once that is 
moved we can just use that for dealing with the map operands.
Thus putting this patch on hold for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

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


[PATCH] D148822: [clang][BFloat] Avoid redefining bfloat16_t in arm_neon.h

2023-04-28 Thread Dimitry Andric via Phabricator via cfe-commits
dim added a comment.

In D148822#4305188 , @simonbutcher 
wrote:

> I can't see anything wrong with this patch and it looks pretty 
> straightforward to me, but is it necessary?
>
> '-Wtypedef-redefinition' is documented as not applying to system headers 
> ,
>  and I couldn't reproduce the issue unless I changed the headers to not be 
> system headers.

I think this due to the way some parts of FreeBSD get compiled, where we 
definitely use -Wsystem-headers. It is likely that this warning (which was 
turned into an error because parts of the tree also get compiled with -Werror) 
came through because of that. In any case, there is no need to redefine 
bfloat16_t, at least not here. Another option is to add yet another define like 
`__bfloat_16_defined` and test for that, but it only makes things uglier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148822

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Interpreter/Interpreter.h:96
+
+  size_t getEffectivePTUSize() const;
+

It looks like this can be private?

Also, just a note (not something you have to deal with in this review), the 
local naming convention seems to have decided that if the function starts with 
`get` then it's camel case and otherwise the name is pascal case.



Comment at: clang/include/clang/Interpreter/Value.h:104-108
+  void setKind(Kind K) { ValueKind = K; }
+  void setOpaqueType(void *Ty) { OpaqueType = Ty; }
+
+  void *getPtr() const;
+  void setPtr(void *Ptr) { Data.m_Ptr = Ptr; }

If we can't get type safety through construction, should we consider adding 
assertions here that a value's kind and opaque type agree, or that we're not 
changing the type or kind without also changing the pointer?



Comment at: clang/include/clang/Interpreter/Value.h:46
+
+#define REPL_BUILTIN_TYPES 
\
+  X(bool, Bool)
\

v.g.vassilev wrote:
> aaron.ballman wrote:
> > Is this expected to be a complete list of builtin types? e.g., should this 
> > have `char8_t` and `void` and `wchar_t`, etc? Should this be including 
> > `clang/include/clang/AST/BuiltinTypes.def` instead of manually maintaining 
> > the list?
> This is used for various things including storing the bits into a big-endian 
> agnostic way. For `void` we have a special case in the Value and we cannot 
> define a union of a `void` type. We can include the others that you suggest. 
> All the relevant ones are described in `clang::BuiltinType::getName`.
> 
> We cannot use `BuiltinTypes.def` because we want to have a mapping between 
> the type as written in the language (eg, `bool`, `unsigned`, etc) and its 
> underlying type name. That mapping is not available in `BuiltinTypes.def`. 
> Ideally we should extend `BuiltinTypes.def` somehow but I'd prefer outside of 
> this patch. One of the challenges is that some of the types depend on the 
> language options (eg. `_Bool` vs `bool`) and I am not sure this can be 
> resolved by tablegen.
> 
> On a broader perspective, the `Value` class is responsible for two things: 
> (a) get a value from the interpreter to compiled code (see test case); (b) 
> set a value from compiled code to the interpreter. The second case is not yet 
> covered (I can open soon another patch). The major use-case is calling at 
> runtime functions and taking input parameters from compiled code.
> 
> FWIW, we should probably move all of these entities in a separate namespace. 
> I'd suggest `caas` (compiler-as-a-service) and possibly rename the `Value` to 
> `InterpreterValue` since `Value` is very generic and there are already a 
> couple of classes with that name in llvm and clang. 
> We can include the others that you suggest. All the relevant ones are 
> described in clang::BuiltinType::getName.

Okay, so the plan is to handle all the builtin types (`_BitInt`, `_Complex`, 
various floating point formats, etc)? Will that be part of this patch or in 
follow-up work? (My intuition is that we should consider it up front because 
some of the builtin types are interesting -- like `_BitInt` because it's 
parameterized, which makes it novel compared to the other types.)

> We cannot use BuiltinTypes.def because we want to have a mapping between the 
> type as written in the language (eg, bool, unsigned, etc) and its underlying 
> type name. That mapping is not available in BuiltinTypes.def. Ideally we 
> should extend BuiltinTypes.def somehow but I'd prefer outside of this patch. 
> One of the challenges is that some of the types depend on the language 
> options (eg. _Bool vs bool) and I am not sure this can be resolved by 
> tablegen.

Thanks for the explanation! BuiltinTypes.def works well enough for times when 
we want to use macros and include the file to generate switch cases and the 
likes, but you're right that it's not well-suited for this. One thing to 
consider is whether we should change `BuiltinTypes.def` to be `BuiltinTypes.td` 
instead and use tablegen to generate the macro/include dance form as well as 
other output (such as for your needs, that can then consider language options 
or more complex predicates).

> FWIW, we should probably move all of these entities in a separate namespace. 
> I'd suggest caas (compiler-as-a-service) and possibly rename the Value to 
> InterpreterValue since Value is very generic and there are already a couple 
> of classes with that name in llvm and clang.

I'm not in love with the name `caas` because that's not really a common acronym 
or abbreviation (and it looks like a typo due to `aa`). However, we already 
have an `interp` namespace in Clang for one of the other interpreters (constant 
expression evaluation), so that's not available for use. 

[PATCH] D149259: [analyzer][NFC] Use std::optional instead of custom "empty" state

2023-04-28 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Sure, Ill look at this on Tuesday.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149259

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


[PATCH] D149456: Basic documentation of -mrecip=... option

2023-04-28 Thread Tim Schmielau via Phabricator via cfe-commits
tim.schmielau created this revision.
Herald added a project: All.
tim.schmielau requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The documentation is still rather terse because it needs to fit
onto a single line of clang --help output.
But at least it lists what the user can specify and documents the
non-obvious syntax.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149456

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3957,8 +3957,12 @@
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
   HelpText<"Don't generate implicit floating point or vector instructions">;
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
-def mrecip : Flag<["-"], "mrecip">, Group;
+def mrecip : Flag<["-"], "mrecip">, Group,
+  HelpText<"Equivalent to '-mrecip=all'">;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Control use of approximate reciprocal and reciprocal square root 
instructions followed by  iterations of "
+   "Newton-Raphson refinement. "
+   " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] 
) | 'all' | 'default' | 'none'">,
   MarshallingInfoStringVector>;
 def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, 
Group, Flags<[CC1Option]>,
   HelpText<"Specifies preferred vector width for auto-vectorization. Defaults 
to 'none' which allows target specific decisions.">,


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3957,8 +3957,12 @@
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
   HelpText<"Don't generate implicit floating point or vector instructions">;
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
-def mrecip : Flag<["-"], "mrecip">, Group;
+def mrecip : Flag<["-"], "mrecip">, Group,
+  HelpText<"Equivalent to '-mrecip=all'">;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, Flags<[CC1Option]>,
+  HelpText<"Control use of approximate reciprocal and reciprocal square root instructions followed by  iterations of "
+   "Newton-Raphson refinement. "
+   " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">,
   MarshallingInfoStringVector>;
 def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group, Flags<[CC1Option]>,
   HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a subscriber: rsmith.
cor3ntin added a comment.

@rsmith @hubert.reinterpretcast do you see any reason not to go ahead with this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

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


[PATCH] D142967: [clangd] Introduce source.organizeImports code action.

2023-04-28 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 517948.
hokein added a comment.

rebase and polish the implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142967

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/test/include-cleaner-batch-fix.test

Index: clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
===
--- clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -112,7 +112,7 @@
 # CHECK-NEXT: "version": 0
 # CHECK-NEXT:   }
 ---
-{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///simple.cpp"},"range":{"start":{"line":2,"character":1},"end":{"line":2,"character":4}},"context":{"diagnostics":[{"range":{"start": {"line": 2, "character": 1}, "end": {"line": 2, "character": 4}},"severity":2,"message":"No header providing \"Foo\" is directly included (fixes available)", "code": "missing-includes", "source": "clangd"}]}}}
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///simple.cpp"},"range":{"start":{"line":2,"character":1},"end":{"line":2,"character":4}},"context":{"only":["quickfix"], "diagnostics":[{"range":{"start": {"line": 2, "character": 1}, "end": {"line": 2, "character": 4}},"severity":2,"message":"No header providing \"Foo\" is directly included (fixes available)", "code": "missing-includes", "source": "clangd"}]}}}
 #  CHECK:  "id": 2,
 # CHECK-NEXT:  "jsonrpc": "2.0",
 # CHECK-NEXT:  "result": [
@@ -297,7 +297,7 @@
 # CHECK-NEXT:}
 # CHECK-NEXT:  ]
 ---
-{"jsonrpc":"2.0","id":3,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///simple.cpp"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":17}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 17}},"severity":2,"message":"Included header all1.h is not used directly (fixes available)", "code": "unused-includes", "source": "clangd"}]}}}
+{"jsonrpc":"2.0","id":3,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///simple.cpp"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":17}},"context":{"only":["quickfix"], "diagnostics":[{"range":{"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 17}},"severity":2,"message":"Included header all1.h is not used directly (fixes available)", "code": "unused-includes", "source": "clangd"}]}}}
 #  CHECK:  "id": 3,
 # CHECK-NEXT:  "jsonrpc": "2.0",
 # CHECK-NEXT:  "result": [
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -1076,6 +1076,7 @@
   const static llvm::StringLiteral QUICKFIX_KIND;
   const static llvm::StringLiteral REFACTOR_KIND;
   const static llvm::StringLiteral INFO_KIND;
+  const static llvm::StringLiteral SOURCE_ORGANIZE_IMPORT;
 
   /// The diagnostics that this code action resolves.
   std::optional> diagnostics;
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -867,6 +867,7 @@
 const llvm::StringLiteral CodeAction::QUICKFIX_KIND = "quickfix";
 const llvm::StringLiteral CodeAction::REFACTOR_KIND = "refactor";
 const llvm::StringLiteral CodeAction::INFO_KIND = "info";
+const llvm::StringLiteral CodeAction::SOURCE_ORGANIZE_IMPORT = "source.organizeImports";
 
 llvm::json::Value toJSON(const CodeAction &CA) {
   auto CodeAction = llvm::json::Object{{"title", CA.title}};
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -23,6 +23,7 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include 
 #include 
@@ -46,6 +47,11 @@
   std::vector UnusedIncludes;
   std::vector MissingIncludes;
 };
+inline constexpr llvm::StringLiteral RemoveAllUnusedMessage =
+"remove all unused includes";
+inline constexpr llvm::StringLiteral AddAllMissingIncludesMessage =
+"add all missing includes";
+inline constexpr llvm::StringLiteral FixAllIncludesMessage = "fix all includes";
 
 /// Retrieves headers that are referenced from the main file but not used.
 /// In unclear cases, headers are not marked as unused.
Index: clang-tools-e

[PATCH] D149259: [analyzer][NFC] Use std::optional instead of custom "empty" state

2023-04-28 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy marked an inline comment as done.
donat.nagy added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149259

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


[PATCH] D149458: [Driver] Pass --target2= to linker from baremetal toolchain

2023-04-28 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki created this revision.
miyuki added reviewers: peter.smith, phosek, michaelplatings.
Herald added subscribers: abidh, kristof.beyls.
Herald added a project: All.
miyuki requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

According to the GNU ld manual
https://sourceware.org/binutils/docs/ld/ARM.html#ARM the R_ARM_TARGET2
relocation (used in exception handling tables) is treated differently
depending on the target. By default, LLD treats R_ARM_TARGET2 as
R_ARM_GOT_PREL (--target2=got-rel), which is correct for Linux but not
for embedded targets.

This patch adds --target2=rel to linker options in the baremetal
toolchain driver so that on baremetal targets, R_ARM_TARGET2 is
treated as R_ARM_REL32. Such behavior is compatible with GNU ld and
unwinding libraries (e.g., libuwind).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149458

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" 
"-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"{{.*}}.tmp.out"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" 
"-o" "{{.*}}.tmp.out"
 
 // RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 
2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBINC %s
@@ -42,7 +42,7 @@
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi -stdlib=libc++ 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBCXX %s
@@ -53,7 +53,7 @@
 // CHECK-V6M-LIBCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "a.out"
+// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
@@ -66,7 +66,7 @@
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
-// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -342,6 +342,12 @@
   if (TC.getTriple().isRISCV())
 CmdArgs.push_back("-X");
 
+  // The R_ARM_TARGET2 relocation must be treated as R_ARM_REL32 on arm*-*-elf
+  // and arm*-*-eabi (the default is R_ARM_GOT_PREL, used on arm*-*-linux and
+  // arm*-*-*bsd).
+  if (isARMBareMetal(TC.getTriple()))
+CmdArgs.push_back("--target2=rel");
+
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "{{.*}}.tmp.out"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" "-o" "{{.*}}.tmp.out"
 
 // RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck --check-prefix=CHECK-V6M-LIBINC

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

2023-04-28 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 517958.
agozillon added a comment.

- [Clang][OpenMP][IRBuilder] Tidy up function calls with helpful reviewer advice
- [Clang][OpenMP][IRBuilder] Replace all getTargetEntryUniqueInfo with 
IRBuilder version
- [Clang][OpenMP][IRBuilder] Run clang-format and tidy up files
- Run clang-format on offending file breaking build process


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149162

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

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -32,6 +32,7 @@
 #include "llvm/IR/Value.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -5081,7 +5082,8 @@
   static_cast(
   CE->getFlags());
   switch (Flags) {
-  case OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo: {
+  case OffloadEntriesInfoManager::OMPTargetGlobalVarEntryEnter:
+  case OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo:
 if (Config.isEmbedded() && Config.hasRequiresUnifiedSharedMemory())
   continue;
 if (!CE->getAddress()) {
@@ -5092,7 +5094,6 @@
 if (CE->getVarSize() == 0)
   continue;
 break;
-  }
   case OffloadEntriesInfoManager::OMPTargetGlobalVarEntryLink:
 assert(((Config.isEmbedded() && !CE->getAddress()) ||
 (!Config.isEmbedded() && CE->getAddress())) &&
@@ -5104,6 +5105,8 @@
   continue;
 }
 break;
+  default:
+break;
   }
 
   // Hidden or internal symbols on the device are not externally visible.
@@ -5140,6 +5143,157 @@
   EntryInfo.Line, NewCount);
 }
 
+TargetRegionEntryInfo
+OpenMPIRBuilder::getTargetEntryUniqueInfo(StringRef FileName, uint64_t Line,
+  StringRef ParentName) {
+  llvm::sys::fs::UniqueID ID;
+  if (auto EC = llvm::sys::fs::getUniqueID(FileName, ID)) {
+assert(EC &&
+   "Unable to get unique ID for file, during getTargetEntryUniqueInfo");
+  }
+  return llvm::TargetRegionEntryInfo(ParentName, ID.getDevice(), ID.getFile(),
+ Line);
+}
+
+Constant *OpenMPIRBuilder::getAddrOfDeclareTargetVar(
+OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
+OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
+bool IsDeclaration, bool IsExternallyVisible,
+TargetRegionEntryInfo EntryInfo, StringRef MangledName, Module *LlvmModule,
+std::vector &GeneratedRefs, bool OpenMPSIMD,
+std::vector TargetTriple, Type *LlvmPtrTy,
+std::function GlobalInitializer,
+std::function VariableLinkage) {
+  // TODO: convert this to utilise the IRBuilder Config rather than
+  // a passed down argument.
+  if (OpenMPSIMD)
+return nullptr;
+
+  if (CaptureClause == OffloadEntriesInfoManager::OMPTargetGlobalVarEntryLink ||
+  ((CaptureClause == OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo ||
+CaptureClause ==
+OffloadEntriesInfoManager::OMPTargetGlobalVarEntryEnter) &&
+   Config.hasRequiresUnifiedSharedMemory())) {
+SmallString<64> PtrName;
+{
+  llvm::raw_svector_ostream OS(PtrName);
+  OS << MangledName;
+  if (!IsExternallyVisible)
+OS << llvm::format("_%x", EntryInfo.FileID);
+  OS << "_decl_tgt_ref_ptr";
+}
+
+llvm::Value *Ptr = LlvmModule->getNamedValue(PtrName);
+
+if (!Ptr) {
+  llvm::GlobalValue *GlobalValue = LlvmModule->getNamedValue(MangledName);
+  Ptr = getOrCreateInternalVariable(LlvmPtrTy, PtrName);
+
+  auto *GV = cast(Ptr);
+  GV->setLinkage(llvm::GlobalValue::WeakAnyLinkage);
+
+  if (!Config.isEmbedded()) {
+if (GlobalInitializer)
+  GV->setInitializer(GlobalInitializer());
+else
+  GV->setInitializer(GlobalValue);
+  }
+
+  registerTargetGlobalVariable(
+  CaptureClause, DeviceClause, IsDeclaration, IsExternallyVisible,
+  EntryInfo, MangledName, LlvmModule, GeneratedRefs, OpenMPSIMD,
+  TargetTriple, GlobalInitializer, VariableLinkage, LlvmPtrTy,
+  cast(Ptr));
+}
+
+return cast(Ptr);
+  }
+
+  return nullptr;
+}
+
+void OpenMPIRBuilder::registerTargetGlobalVariable(
+OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
+OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
+bool IsDeclaration, bool IsExternallyVisible,
+TargetRegionEntryInfo EntryInfo, llvm::StringRef Man

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

2023-04-28 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

rebased and clang-formatted the *hopefully* final file clang-format is angry at.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149162

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


[PATCH] D149458: [Driver] Pass --target2= to linker from baremetal toolchain

2023-04-28 Thread Peter Smith via Phabricator via cfe-commits
peter.smith accepted this revision.
peter.smith added a comment.
This revision is now accepted and ready to land.

LGTM. This is consistent with the target2 support that I added to LLD several 
years ago in https://reviews.llvm.org/D25684 will be good to give some time for 
other reviewers to add any comments/objections before committing.

Other references:

- aaelf32 
https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst#5617static-miscellaneous-relocations
- ehabi32 
https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst#542relocations

The latter states that ABS is the right value for bare-metal, but I think it 
ended up being implemented as REL for the GNU bare-metal personality routines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149458

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


[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-04-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:58
   Clang will only search for std::coroutine_traits for coroutines then.
+- Clang doesn't accept flexible array members in unions in C++ anymore.
 





Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6241-6244
 def ext_flexible_array_empty_aggregate_ms : Extension<
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a Microsoft extension">,
   InGroup;

Should this be updated to remove the union case?



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6252
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a GNU extension">,
   InGroup;

Same question here



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6255
-def ext_flexible_array_union_gnu : Extension<
-  "flexible array member %0 in a union is a GNU extension">, 
InGroup;
 

This was the last use of this diagnostic group, so we can remove it from 
`DiagnosticGroups.td` as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

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


[PATCH] D149460: [analyzer] ArrayBoundCheckerV2: suppress false positives from ctype macros

2023-04-28 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy created this revision.
donat.nagy added reviewers: gamesh411, Szelethus, steakhal, dkrupp.
Herald added subscribers: manas, ASDenysPetrov, martong, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
donat.nagy requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The checker `alpha.security.ArrayBoundV2` created bug reports in situations 
when the (tainted) result of `fgetc()` or `getchar()` was passed to one of the 
`isX()` macros from ctype.h. This is a common input handling pattern 
(within the limited toolbox of the C language) and several open source projects 
contained code where it led to false positive reports; so this commit 
suppresses ArrayBoundV2 reports generated within the `isX()` macros. (Note 
that here even true positive reports would be difficult to understand, as 
they'd refer to the implementation details of these macros.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149460

Files:
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
  clang/test/Analysis/taint-generic.c


Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -156,6 +156,28 @@
   Buffer[m] = 1;  //expected-warning {{Out of bound memory access (index is 
tainted)}}
 }
 
+extern const unsigned short int **__ctype_b_loc (void);
+enum { _ISdigit = 2048 };
+# define isdigit(c) ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) 
_ISdigit)
+
+int isdigitImplFalsePositive(void) {
+  // If this code no longer produces a bug report, then consider removing the
+  // special case that disables buffer overflow reports coming from the isX
+  // macros in ctypes.h.
+  int c = getchar();
+  return ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) _ISdigit);
+  //expected-warning@-1 {{Out of bound memory access (index is tainted)}}
+}
+
+int isdigitSuppressed(void) {
+  // Same code as above, but reports are suppressed based on macro name:
+  int c = getchar();
+  return isdigit(c); //no-warning
+}
+
+// Some later tests use isdigit as a function, so we need to undef it:
+#undef isdigit
+
 void testUncontrolledFormatString(char **p) {
   char s[80];
   fscanf(stdin, "%s", s);
Index: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -42,8 +42,10 @@
   void reportTaintOOB(CheckerContext &C, ProgramStateRef errorState,
   SVal TaintedSVal) const;
 
+  static bool isFromCtypeMacro(const Stmt *S, ASTContext &AC);
+
 public:
-  void checkLocation(SVal l, bool isLoad, const Stmt*S,
+  void checkLocation(SVal l, bool isLoad, const Stmt *S,
  CheckerContext &C) const;
 };
 
@@ -155,6 +157,15 @@
   // memory access is within the extent of the base region.  Since we
   // have some flexibility in defining the base region, we can achieve
   // various levels of conservatism in our buffer overflow checking.
+
+  // The header ctype.h (from e.g. glibc) implements the isX() macros as
+  //   #define isX(arg) (LOOKUP_TABLE[arg] & BITMASK_FOR_X)
+  // and incomplete analysis of these leads to false positives. As even
+  // accurate reports would be confusing for the users, just disable reports
+  // from these macros:
+  if (isFromCtypeMacro(LoadS, checkerContext.getASTContext()))
+return;
+
   ProgramStateRef state = checkerContext.getState();
 
   SValBuilder &svalBuilder = checkerContext.getSValBuilder();
@@ -267,6 +278,25 @@
   checkerContext.emitReport(std::move(BR));
 }
 
+bool ArrayBoundCheckerV2::isFromCtypeMacro(const Stmt *S, ASTContext &ACtx) {
+  SourceLocation Loc = S->getBeginLoc();
+  if (!Loc.isMacroID())
+return false;
+
+  StringRef MacroName = Lexer::getImmediateMacroName(
+  Loc, ACtx.getSourceManager(), ACtx.getLangOpts());
+
+  if (MacroName.size() < 7 || MacroName[0] != 'i' || MacroName[1] != 's')
+return false;
+
+  return ((MacroName == "isalnum") || (MacroName == "isalpha") ||
+  (MacroName == "isblank") || (MacroName == "isdigit") ||
+  (MacroName == "isgraph") || (MacroName == "islower") ||
+  (MacroName == "isnctrl") || (MacroName == "isprint") ||
+  (MacroName == "ispunct") || (MacroName == "isspace") ||
+  (MacroName == "isupper") || (MacroName == "isxdigit"));
+}
+
 #ifndef NDEBUG
 LLVM_DUMP_METHOD void RegionRawOffsetV2::dump() const {
   dumpToStream(llvm::errs());


Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -156,6 +156,28 @@
   Buf

[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-28 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I see that we do have an issue but so far the examples in the tests don't feel 
very natural and so I would like to understand if there is a larger motivation 
here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

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


[PATCH] D149193: [Driver] Add -dumpdir and change -gsplit-dwarf .dwo names for linking

2023-04-28 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D149193#4302981 , @scott.linder 
wrote:

> I am OK to give LGTM, assuming the other reviewers don't still have 
> reservations?

Some - planning to get to this next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149193

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


[PATCH] D149461: [NFC] ][CLANG] Fix static code analyzer concerns

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added a reviewer: tahonermann.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Manna requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: jplehr, sstefan1.
Herald added a project: clang.

Reported by Coverity:

Inside "ASTReader.cpp" file,  in 
clang::​ASTReader::​FindExternalLexicalDecls(clang::​DeclContext const *, 
llvm::​function_ref, 
llvm::​SmallVectorImpl &): Using the auto keyword without an & 
causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type pair.

2. Inside "ASTReader.cpp" file, in 
clang::​ASTReader::​ReadAST(llvm::​StringRef, 
clang::​serialization::​ModuleKind, clang::​SourceLocation, unsigned int, 
llvm::​SmallVectorImpl *): Using the 
auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type DenseMapPair.

3. Inside "CGOpenMPRuntimeGPU.cpp" file, in 
clang::​CodeGen::​CGOpenMPRuntimeGPU::​emitGenericVarsEpilog(clang::​CodeGen::​CodeGenFunction
 &, bool): Using the auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type pair.

4. In clang::​ASTWriter::​WriteHeaderSearch(clang::​HeaderSearch const &): 
Using the auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type UnresolvedHeaderDirective.

5. Inside "ASTWriter.cpp" file, in 
::​HeaderFileInfoTrait::​EmitData(llvm::​raw_ostream &, 
::​HeaderFileInfoTrait::​key_type const &, 
::​HeaderFileInfoTrait::​data_type const &, unsigned int): Using the 
auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type KnownHeader.

6. Inside "ASTWriter.cpp" file, In 
::​HeaderFileInfoTrait::​EmitKeyDataLength(llvm::​raw_ostream &, 
::​HeaderFileInfoTrait::​key_type const &, 
::​HeaderFileInfoTrait::​data_type const &): Using the auto keyword 
without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type KnownHeader.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149461

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp


Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1778,7 +1778,7 @@
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   unsigned DataLen = 1 + 4 + 4;
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto &ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
   if (Data.Unresolved.getPointer())
@@ -1839,7 +1839,7 @@
 }
   };
 
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto &ModInfo : Data.KnownHeaders)
 EmitModule(ModInfo.getModule(), ModInfo.getRole());
   if (Data.Unresolved.getPointer())
 EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt());
@@ -1884,7 +1884,7 @@
 
   // If the file didn't exist, we can still create a module if we were 
given
   // enough information in the module map.
-  for (auto U : M->MissingHeaders) {
+  for (const auto &U : M->MissingHeaders) {
 // Check that we were given enough information to build a module
 // without this file existing on disk.
 if (!U.Size || (!U.ModTime && IncludeTimestamps)) {
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4425,7 +4425,7 @@
   Id->second->setOutOfDate(true);
   }
   // Mark selectors as out of date.
-  for (auto Sel : SelectorGeneration)
+  for (const auto &Sel : SelectorGeneration)
 SelectorOutOfDate[Sel.first] = true;
 
   // Resolve any unresolved module exports.
@@ -7693,7 +7693,7 @@
   };
 
   if (isa(DC)) {
-for (auto Lexical : TULexicalDecls)
+for (const auto &Lexical : TULexicalDecls)
   Visit(Lexical.first, Lexical.second);
   } else {
 auto I = LexicalDecls.find(DC);
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1128,7 +1128,7 @@
   const auto I = FunctionGlobalizedDecls.find(CGF.CurFn);
   if (I != FunctionGlobalizedDecls.end()) {
 // Deallocate the memory for each globalized VLA object
-for (auto Addr

[PATCH] D149461: [NFC] ][CLANG] Fix static code analyzer concerns

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
Manna updated this revision to Diff 517964.

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

https://reviews.llvm.org/D149461

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp


Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1778,7 +1778,7 @@
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   unsigned DataLen = 1 + 4 + 4;
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto &ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
   if (Data.Unresolved.getPointer())
@@ -1839,7 +1839,7 @@
 }
   };
 
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto &ModInfo : Data.KnownHeaders)
 EmitModule(ModInfo.getModule(), ModInfo.getRole());
   if (Data.Unresolved.getPointer())
 EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt());
@@ -1884,7 +1884,7 @@
 
   // If the file didn't exist, we can still create a module if we were 
given
   // enough information in the module map.
-  for (auto U : M->MissingHeaders) {
+  for (const auto &U : M->MissingHeaders) {
 // Check that we were given enough information to build a module
 // without this file existing on disk.
 if (!U.Size || (!U.ModTime && IncludeTimestamps)) {
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4425,7 +4425,7 @@
   Id->second->setOutOfDate(true);
   }
   // Mark selectors as out of date.
-  for (auto Sel : SelectorGeneration)
+  for (const auto &Sel : SelectorGeneration)
 SelectorOutOfDate[Sel.first] = true;
 
   // Resolve any unresolved module exports.
@@ -7693,7 +7693,7 @@
   };
 
   if (isa(DC)) {
-for (auto Lexical : TULexicalDecls)
+for (const auto &Lexical : TULexicalDecls)
   Visit(Lexical.first, Lexical.second);
   } else {
 auto I = LexicalDecls.find(DC);
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1128,7 +1128,7 @@
   const auto I = FunctionGlobalizedDecls.find(CGF.CurFn);
   if (I != FunctionGlobalizedDecls.end()) {
 // Deallocate the memory for each globalized VLA object
-for (auto AddrSizePair :
+for (const auto &AddrSizePair :
  llvm::reverse(I->getSecond().EscapedVariableLengthDeclsAddrs)) {
   CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
   CGM.getModule(), OMPRTL___kmpc_free_shared),


Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1778,7 +1778,7 @@
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   unsigned DataLen = 1 + 4 + 4;
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto &ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
   if (Data.Unresolved.getPointer())
@@ -1839,7 +1839,7 @@
 }
   };
 
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto &ModInfo : Data.KnownHeaders)
 EmitModule(ModInfo.getModule(), ModInfo.getRole());
   if (Data.Unresolved.getPointer())
 EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt());
@@ -1884,7 +1884,7 @@
 
   // If the file didn't exist, we can still create a module if we were given
   // enough information in the module map.
-  for (auto U : M->MissingHeaders) {
+  for (const auto &U : M->MissingHeaders) {
 // Check that we were given enough information to build a module
 // without this file existing on disk.
 if (!U.Size || (!U.ModTime && IncludeTimestamps)) {
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4425,7 +4425,7 @@
   Id->second->setOutOfDate(true);
   }
   // Mark selectors as out of date.
-  for (auto Sel : SelectorGeneration)
+  for (const auto &Sel : SelectorGeneration)
 SelectorOutOfDate[Sel.first] = true;
 
   // Resolve any unresolved module exports.
@@ -7693,7 +7693,7 @@
   };
 
   if (isa(DC)) {
-for (auto Lexical : TULexicalDecls)
+fo

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

2023-04-28 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:4170
+private:
+  mutable SmallVector CountFieldRanges;
+public:

`mutable`...my least favorite keyword in C++.  If you drop `const` from 
`addCountFieldSourceRange` then you don't need `mutable`.



Comment at: clang/include/clang/Basic/AttrDocs.td:7010
+/* ... */
+struct bar *fam[] __attribute__((element_count(bork, num_fam_elements)));
+  };

Question: does `bork` need to occur before `fam` for this substructure 
reference to work?

Does that mean that `element_count` is essentially variadic with this syntax?



Comment at: clang/lib/CodeGen/CGExpr.cpp:954
+if (const auto *MD = dyn_cast(ME->getMemberDecl())) {
+  if (const auto ECA = MD->getAttr()) {
+const RecordDecl *RD = MD->getParent();

`const auto *ECA = ...`



Comment at: clang/lib/CodeGen/CGExpr.cpp:961-963
+  for (FieldDecl *FD : RD->fields()) {
+if (FD->getName() != CountField->getName())
+  continue;

What happens if we never find the field? I guess that's checked below in 
`CheckElementCountAttr`? Do we need a diagnostic though?



Comment at: clang/lib/Sema/SemaDecl.cpp:17689-17701
+static const FieldDecl *FindFieldWithElementCountAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D))
+  if (FD->hasAttr())
+return FD;
+
+if (const auto *SubRD = dyn_cast(D))

I think if you made this static function instead be a method of RecordDecl, you 
could reuse it in clang/lib/CodeGen/CGExpr.cpp (in that for loop where you 
iterate `RD->fields`.

`FieldDecl *RecordDecl::getFieldWithName(StringRef Name);`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D149276#4305780 , @shafik wrote:

> I see that we do have an issue but so far the examples in the tests don't 
> feel very natural and so I would like to understand if there is a larger 
> motivation here.

The context is that a user realized we fail to implement P0849 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0849r8.html
and as a result we fail to compile simple range code 
https://godbolt.org/z/3ajj1c135 (this was observed by a user on the llvm 
discord and i don't think they made a github issue, unfortunately)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

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


[PATCH] D149458: [Driver] Pass --target2= to linker from baremetal toolchain

2023-04-28 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149458

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


[PATCH] D149405: [Clang][Doc] Added an open project for improving command line docs

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

Thank you, this is a great suggestion! Just some minor wording changes, but 
otherwise LGTM.




Comment at: clang/www/OpenProjects.html:40-44
   other relevant information), or
+  improve existing and add missing documentation for
+  https://clang.llvm.org/docs/ClangCommandLineReference.html";>
+  clang command line flags, generated from https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td";>
+  clang/Driver/Options.td,




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149405

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


[PATCH] D148370: [Clang][Flang][OpenMP] Add loadOffloadInfoMetadata and createOffloadEntriesAndInfoMetadata into OMPIRBuilder's finalize and initialize

2023-04-28 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 517968.
agozillon added a comment.

- Move hostIRFilePath initialize invocation to ModuleTranslation.cpp to respect 
TargetOp patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148370

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/CMakeLists.txt
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1259,19 +1259,23 @@
 llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() {
   if (!ompBuilder) {
 ompBuilder = std::make_unique(*llvmModule);
-ompBuilder->initialize();
 
 bool isDevice = false;
+llvm::StringRef hostIRFilePath = "";
 if (auto offloadMod =
-dyn_cast(mlirModule))
+dyn_cast(mlirModule)) {
   isDevice = offloadMod.getIsDevice();
+  hostIRFilePath = offloadMod.getHostIRFilePath();
+}
+
+ompBuilder->initialize(hostIRFilePath);
 
 // TODO: set the flags when available
-llvm::OpenMPIRBuilderConfig Config(
+llvm::OpenMPIRBuilderConfig config(
 isDevice, /* IsTargetCodegen */ false,
 /* HasRequiresUnifiedSharedMemory */ false,
 /* OpenMPOffloadMandatory */ false);
-ompBuilder->setConfig(Config);
+ompBuilder->setConfig(config);
   }
   return ompBuilder.get();
 }
Index: mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
===
--- mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -15,6 +15,7 @@
 #define MLIR_TARGET_LLVMIR_MODULETRANSLATION_H
 
 #include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/IR/Operation.h"
 #include "mlir/IR/SymbolTable.h"
 #include "mlir/IR/Value.h"
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DebugInfoMetadata.h"
@@ -445,7 +446,28 @@
   return Fn;
 }
 
-void OpenMPIRBuilder::initialize() { initializeTypes(M); }
+void OpenMPIRBuilder::initialize(StringRef HostFilePath) {
+  initializeTypes(M);
+
+  if (!HostFilePath.empty()) {
+auto Buf = llvm::MemoryBuffer::getFile(HostFilePath);
+if (auto Err = Buf.getError())
+  assert(false && ("error opening host file from host file path inside of "
+   "OpenMPIRBuilder" +
+   Err.message())
+  .c_str());
+
+llvm::LLVMContext Ctx;
+auto M = llvm::expectedToErrorOrAndEmitErrors(
+Ctx, llvm::parseBitcodeFile(Buf.get()->getMemBufferRef(), Ctx));
+if (auto Err = M.getError())
+  assert(false && ("error parsing host file inside of OpenMPIRBuilder " +
+   Err.message())
+  .c_str());
+
+loadOffloadInfoMetadata(*M.get());
+  }
+}
 
 void OpenMPIRBuilder::finalize(Function *Fn) {
   SmallPtrSet ParallelRegionBlockSet;
@@ -534,6 +556,17 @@
 
   // Remove work items that have been completed.
   OutlineInfos = std::move(DeferredOutlines);
+
+  llvm::OpenMPIRBuilder::EmitMetadataErrorReportFunctionTy &&errorReportFn =
+  [](llvm::OpenMPIRBuilder::EmitMetadataErrorKind kind,
+ const llvm::TargetRegionEntryInfo &entryInfo) -> void {
+llvm::errs() << "Error of kind: " << kind
+ << " when emitting offload entries and metadata during "
+"OMPIRBuilder finalization \n";
+  };
+
+  if (!OffloadInfoManager.empty())
+createOffloadEntriesAndInfoMetadata(errorReportFn);
 }
 
 OpenMPIRBuilder::~OpenMPIRBuilder() {
Index: llvm/lib/Frontend/OpenMP/CMakeLists.txt
===
--- llvm/lib/Frontend/OpenMP/CMakeLists.txt
+++ llvm/lib/Frontend/OpenMP/CMakeLists.txt
@@ -19,4 +19,5 @@
   Analysis
   MC
   Scalar
+  BitReader
   )
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -419,7 +419,7 @@
   /// Initialize the internal state, this will put structures types and
  

[PATCH] D149464: [clang][dataflow] Expose DataflowAnalysisContext from DataflowEnvironment.

2023-04-28 Thread Samira Bazuzi via Phabricator via cfe-commits
bazuzi created this revision.
bazuzi added reviewers: ymandel, gribozavr2.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
bazuzi requested review of this revision.
Herald added a project: clang.

This will eliminate the need for more pass-through APIs. Also replace 
pass-through usages with this exposure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149464

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -53,9 +53,10 @@
   [UseBuiltinModel = Options.BuiltinOpts.has_value()](ASTContext &C,
   Environment &Env) {
 return NoopAnalysis(
-C, DataflowAnalysisOptions{UseBuiltinModel
-   ? Env.getAnalysisOptions()
-   : std::optional()});
+C,
+DataflowAnalysisOptions{
+UseBuiltinModel ? Env.getDataflowAnalysisContext().getOptions()
+: std::optional()});
   });
   AI.ASTBuildArgs = ASTBuildArgs;
   if (Options.BuiltinOpts)
Index: clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -37,14 +37,16 @@
 
   static TestLattice initialElement() { return TestLattice{}; }
   void transfer(const CFGElement &, TestLattice &L, Environment &E) {
-E.logger().log([](llvm::raw_ostream &OS) { OS << "transfer()"; });
+E.getDataflowAnalysisContext().getOptions().Log->log(
+[](llvm::raw_ostream &OS) { OS << "transfer()"; });
 ++L.Elements;
   }
   void transferBranch(bool Branch, const Stmt *S, TestLattice &L,
   Environment &E) {
-E.logger().log([&](llvm::raw_ostream &OS) {
-  OS << "transferBranch(" << Branch << ")";
-});
+E.getDataflowAnalysisContext().getOptions().Log->log(
+[&](llvm::raw_ostream &OS) {
+  OS << "transferBranch(" << Branch << ")";
+});
 ++L.Branches;
   }
 };
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -168,7 +168,8 @@
   llvm::ArrayRef>
   BlockStates)
   : CFCtx(CFCtx), Analysis(Analysis), InitEnv(InitEnv),
-Log(InitEnv.logger()), BlockStates(BlockStates) {
+Log(*InitEnv.getDataflowAnalysisContext().getOptions().Log),
+BlockStates(BlockStates) {
 Log.beginAnalysis(CFCtx, Analysis);
   }
   ~AnalysisContext() { Log.endAnalysis(); }
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -496,7 +496,7 @@
   }
 
   void VisitReturnStmt(const ReturnStmt *S) {
-if (!Env.getAnalysisOptions().ContextSensitiveOpts)
+if (!Env.getDataflowAnalysisContext().getOptions().ContextSensitiveOpts)
   return;
 
 auto *Ret = S->getRetValue();
@@ -863,12 +863,13 @@
   // `F` of `S`. The type `E` must be either `CallExpr` or `CXXConstructExpr`.
   template 
   void transferInlineCall(const E *S, const FunctionDecl *F) {
-const auto &Options = Env.getAnalysisOptions();
+const auto &Options = Env.getDataflowAnalysisContext().getOptions();
 if (!(Options.ContextSensitiveOpts &&
   Env.canDescend(Options.ContextSensitiveOpts->Depth, F)))
   return;
 
-const ControlFlowContext *CFCtx = Env.getControlFlowContext(F);
+const ControlFlowContext *CFCtx =
+Env.getDataflowAnalysisContext().getControlFlowContext(F);
 if (!CFCtx)
   return;
 
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -381,7 +381,7 @@
 
 QualType ParamType = Param->getType();
 if (ParamType->isReferenceType()) {
-  auto &Val = arena().create(*ArgLoc);
+  auto &Val = DACtx->arena().create(*ArgLoc);

[PATCH] D148370: [Clang][Flang][OpenMP] Add loadOffloadInfoMetadata and createOffloadEntriesAndInfoMetadata into OMPIRBuilder's finalize and initialize

2023-04-28 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

rebase to see if it clears up the buildbot issue (currently the failing test 
appears to be unrelated and passes on my machine after a rebase)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148370

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


[PATCH] D149464: [clang][dataflow] Expose DataflowAnalysisContext from DataflowEnvironment.

2023-04-28 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.
This revision is now accepted and ready to land.

Thanks and welcome! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149464

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


[clang] 15f0491 - [NFC] Fix a mem-sanitizer found issue in AutoType

2023-04-28 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2023-04-28T10:09:26-07:00
New Revision: 15f0491d3963d91202aef659acc20f59aa83fae7

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

LOG: [NFC] Fix a mem-sanitizer found issue in AutoType

We only need the list of constriant template arguments when we have a
valid constraint.  We give up on merging the auto-type constraints if
the template arguments don't match, but neglected to clear the
collection of template arguments.  The result was we had an AutoType
where we initialized the number of template arguments, but never
initialized the template arguments themselves.

This patch adds an assert to catch this in the future, plus ensures we
clear out the vector so we don't try to create the AutoType incorrectly.

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e331df86235b2..6bc202ecd5b02 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12982,8 +12982,10 @@ static QualType getCommonSugarTypeNode(ASTContext 
&Ctx, const Type *X,
 SmallVector As;
 if (CD &&
 getCommonTemplateArguments(Ctx, As, AX->getTypeConstraintArguments(),
-   AY->getTypeConstraintArguments()))
+   AY->getTypeConstraintArguments())) {
   CD = nullptr; // The arguments 
diff er, so make it unconstrained.
+  As.clear();
+}
 
 // Both auto types can't be dependent, otherwise they wouldn't have been
 // sugar. This implies they can't contain unexpanded packs either.

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index e1686a7c69d52..c0d225034be89 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4630,6 +4630,7 @@ AutoType::AutoType(QualType DeducedAsType, 
AutoTypeKeyword Keyword,
   AutoTypeBits.Keyword = (unsigned)Keyword;
   AutoTypeBits.NumArgs = TypeConstraintArgs.size();
   this->TypeConstraintConcept = TypeConstraintConcept;
+  assert(TypeConstraintConcept || AutoTypeBits.NumArgs == 0);
   if (TypeConstraintConcept) {
 auto *ArgBuffer =
 const_cast(getTypeConstraintArguments().data());



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


[PATCH] D149361: [profiling] Improve error message for raw profile header mismatches

2023-04-28 Thread Jessica Paquette via Phabricator via cfe-commits
paquette added a comment.

Sorry for the inconvenience and thanks for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149361

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


[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-04-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6241-6244
 def ext_flexible_array_empty_aggregate_ms : Extension<
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a Microsoft extension">,
   InGroup;

aaron.ballman wrote:
> Should this be updated to remove the union case?
Sounds reasonable, but what is unfortunate is that this diagnostic exactly 
matches TagTypeKind enum, so now it can be emitted with `Diag(...) << ... << 
SomeTagDecl->getTagKind().` Once I remove `union` from there, this neat thing 
fails.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

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


[PATCH] D149461: [NFC] ][CLANG] Fix static code analyzer concerns

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
Manna added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:4428
   // Mark selectors as out of date.
-  for (auto Sel : SelectorGeneration)
+  for (const auto &Sel : SelectorGeneration)
 SelectorOutOfDate[Sel.first] = true;

Here Object of type is `DenseMapPair`.  `SelectorGeneration`  returns 
`llvm::DenseMap' in `ASTReader.h' file.



Comment at: clang/lib/Serialization/ASTWriter.cpp:1781
   unsigned DataLen = 1 + 4 + 4;
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto &ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))

Object of type `KnownHeader` returns ` ArrayRef` in 
`ASTWriter.cpp` file.



Comment at: clang/lib/Serialization/ASTWriter.cpp:1887
   // enough information in the module map.
-  for (auto U : M->MissingHeaders) {
+  for (const auto &U : M->MissingHeaders) {
 // Check that we were given enough information to build a module

This returns ` SmallVector` in `Module.h' file





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

https://reviews.llvm.org/D149461

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


[PATCH] D149458: [Driver] Pass --target2= to linker from baremetal toolchain

2023-04-28 Thread Mikhail Maltsev 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 rG024bb62ffd07: [Driver] Pass --target2= to linker from 
baremetal toolchain (authored by miyuki).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149458

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" 
"-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"{{.*}}.tmp.out"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" 
"-o" "{{.*}}.tmp.out"
 
 // RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 
2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBINC %s
@@ -42,7 +42,7 @@
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi -stdlib=libc++ 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBCXX %s
@@ -53,7 +53,7 @@
 // CHECK-V6M-LIBCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "a.out"
+// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
@@ -66,7 +66,7 @@
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
-// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -342,6 +342,12 @@
   if (TC.getTriple().isRISCV())
 CmdArgs.push_back("-X");
 
+  // The R_ARM_TARGET2 relocation must be treated as R_ARM_REL32 on arm*-*-elf
+  // and arm*-*-eabi (the default is R_ARM_GOT_PREL, used on arm*-*-linux and
+  // arm*-*-*bsd).
+  if (isARMBareMetal(TC.getTriple()))
+CmdArgs.push_back("--target2=rel");
+
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "{{.*}}.tmp.out"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" "-o" "{{.*}}.tmp.out"
 
 // RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
@@ -42,7 +42,7 @@
 // CHECK-V6M-DEFAULTCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "a.out"
+// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi -stdlib=libc++ 2>&1 \
 // RUN: --sysr

[clang] 024bb62 - [Driver] Pass --target2= to linker from baremetal toolchain

2023-04-28 Thread Mikhail Maltsev via cfe-commits

Author: Mikhail Maltsev
Date: 2023-04-28T18:30:49+01:00
New Revision: 024bb62ffd072e9a90343e88c92e40b5849c2632

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

LOG: [Driver] Pass --target2= to linker from baremetal toolchain

According to the GNU ld manual
https://sourceware.org/binutils/docs/ld/ARM.html#ARM the R_ARM_TARGET2
relocation (used in exception handling tables) is treated differently
depending on the target. By default, LLD treats R_ARM_TARGET2 as
R_ARM_GOT_PREL (--target2=got-rel), which is correct for Linux but not
for embedded targets.

This patch adds --target2=rel to linker options in the baremetal
toolchain driver so that on baremetal targets, R_ARM_TARGET2 is
treated as R_ARM_REL32. Such behavior is compatible with GNU ld and
unwinding libraries (e.g., libuwind).

Reviewed By: peter.smith, phosek

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/test/Driver/baremetal.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 38f26d0176471..3232394007bc3 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -342,6 +342,12 @@ void baremetal::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (TC.getTriple().isRISCV())
 CmdArgs.push_back("-X");
 
+  // The R_ARM_TARGET2 relocation must be treated as R_ARM_REL32 on arm*-*-elf
+  // and arm*-*-eabi (the default is R_ARM_GOT_PREL, used on arm*-*-linux and
+  // arm*-*-*bsd).
+  if (isARMBareMetal(TC.getTriple()))
+CmdArgs.push_back("--target2=rel");
+
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 

diff  --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp
index 7f2334493c529..c00713a5d30fb 100644
--- a/clang/test/Driver/baremetal.cpp
+++ b/clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" 
"-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"{{.*}}.tmp.out"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" 
"-o" "{{.*}}.tmp.out"
 
 // RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 
2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBINC %s
@@ -42,7 +42,7 @@
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi -stdlib=libc++ 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBCXX %s
@@ -53,7 +53,7 @@
 // CHECK-V6M-LIBCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "a.out"
+// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
@@ -66,7 +66,7 @@
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
-// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \



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


[PATCH] D149461: [NFC] ][CLANG] Fix static code analyzer concerns

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
Manna added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:7696
   if (isa(DC)) {
-for (auto Lexical : TULexicalDecls)
+for (const auto &Lexical : TULexicalDecls)
   Visit(Lexical.first, Lexical.second);

This returns `std::vector` in 
'ASTReader.h` file


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

https://reviews.llvm.org/D149461

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


[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-04-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 517985.
Fznamznon edited the summary of this revision.
Fznamznon added a comment.

Apply some of the comments, rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/Layout/aix-power-alignment-typedef.cpp
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/Sema/init.c
  clang/test/SemaCXX/flexible-array-test.cpp
  clang/test/SemaCXX/gnu-flags.cpp
  clang/test/SemaObjCXX/flexible-array.mm

Index: clang/test/SemaObjCXX/flexible-array.mm
===
--- clang/test/SemaObjCXX/flexible-array.mm
+++ clang/test/SemaObjCXX/flexible-array.mm
@@ -4,7 +4,7 @@
 
 union VariableSizeUnion {
   int s;
-  char c[];
+  char c[]; //expected-error {{flexible array member 'c' in a union is not allowed}}
 };
 
 @interface LastUnionIvar {
Index: clang/test/SemaCXX/gnu-flags.cpp
===
--- clang/test/SemaCXX/gnu-flags.cpp
+++ clang/test/SemaCXX/gnu-flags.cpp
@@ -8,34 +8,27 @@
 
 // RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wno-gnu \
 // RUN:   -Wgnu-anonymous-struct -Wredeclared-class-member \
-// RUN:   -Wgnu-flexible-array-union-member -Wgnu-folding-constant \
-// RUN:   -Wgnu-empty-struct
+// RUN:   -Wgnu-folding-constant -Wgnu-empty-struct
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s -DALL -Wno-gnu \
 // RUN:   -Wgnu-anonymous-struct -Wredeclared-class-member \
-// RUN:   -Wgnu-flexible-array-union-member -Wgnu-folding-constant \
-// RUN:   -Wgnu-empty-struct
+// RUN:   -Wgnu-folding-constant -Wgnu-empty-struct
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -DALL -Wno-gnu \
 // RUN:   -Wgnu-anonymous-struct -Wredeclared-class-member \
-// RUN:   -Wgnu-flexible-array-union-member -Wgnu-folding-constant \
-// RUN:   -Wgnu-empty-struct
+// RUN:   -Wgnu-folding-constant -Wgnu-empty-struct
 
 // RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wgnu \
 // RUN:   -Wno-gnu-anonymous-struct -Wno-redeclared-class-member \
-// RUN:   -Wno-gnu-flexible-array-union-member -Wno-gnu-folding-constant \
-// RUN:   -Wno-gnu-empty-struct
+// RUN:   -Wno-gnu-folding-constant -Wno-gnu-empty-struct
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s -DNONE -Wgnu \
 // RUN:   -Wno-gnu-anonymous-struct -Wno-redeclared-class-member \
-// RUN:   -Wno-gnu-flexible-array-union-member -Wno-gnu-folding-constant \
-// RUN:   -Wno-gnu-empty-struct
+// RUN:   -Wno-gnu-folding-constant -Wno-gnu-empty-struct
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -DNONE -Wgnu \
 // RUN:   -Wno-gnu-anonymous-struct -Wno-redeclared-class-member \
-// RUN:   -Wno-gnu-flexible-array-union-member -Wno-gnu-folding-constant \
-// RUN:   -Wno-gnu-empty-struct
+// RUN:   -Wno-gnu-folding-constant -Wno-gnu-empty-struct
 
 // Additional disabled tests:
 // %clang_cc1 -fsyntax-only -verify %s -DANONYMOUSSTRUCT -Wno-gnu -Wgnu-anonymous-struct
 // %clang_cc1 -fsyntax-only -verify %s -DREDECLAREDCLASSMEMBER -Wno-gnu -Wredeclared-class-member
-// %clang_cc1 -fsyntax-only -verify %s -DFLEXIBLEARRAYUNIONMEMBER -Wno-gnu -Wgnu-flexible-array-union-member
 // %clang_cc1 -fsyntax-only -verify %s -DFOLDINGCONSTANT -Wno-gnu -Wgnu-folding-constant
 // %clang_cc1 -fsyntax-only -verify %s -DEMPTYSTRUCT -Wno-gnu -Wgnu-empty-struct
 
@@ -70,19 +63,6 @@
   };
 }
 
-
-#if ALL || FLEXIBLEARRAYUNIONMEMBER
-// expected-warning@+6 {{flexible array member 'c1' in a union is a GNU extension}}
-#endif
-
-struct faum {
-   int l;
-   union {
-   int c1[];
-   };
-};
-
-
 #if (ALL || FOLDINGCONSTANT) && (__cplusplus <= 199711L) // C++03 or earlier modes
 // expected-warning@+4 {{in-class initializer for static data member is not a constant expression; folding it to a constant is a GNU extension}}
 #endif
Index: clang/test/SemaCXX/flexible-array-test.cpp
===
--- clang/test/SemaCXX/flexible-array-test.cpp
+++ clang/test/SemaCXX/flexible-array-test.cpp
@@ -16,7 +16,7 @@
 
 struct Rec {
   union { // expected-warning-re {{variable sized type '{{.*}}' not at the end of a struct or class is a GNU extension}}
-int u0[];
+int u0[]; // expected-error {{flexible array member 'u0' in a union is not allowed}}
   };
   int x;
 } rec;
@@ -63,7 +63,7 @@
 
 union B {
   int s;
-  char c[];
+  char c[]; // expected-error {{flexible array member 'c' in a union is not allowed}}
 };
 
 class C {
Index: clang/test/Sema/init.c
===
--- clang/test/Sema/init.c
+++ clang/test/Sema/init.c
@@ -164,3 +164,6 @@
 
 typedef struct { uintptr_t x : 2; } StructWithBitfield;
 StructWithBitfield bitfieldvar = { (uin

[clang-tools-extra] a7b4fd9 - [clangd] Hover: resolve forwarding parameters for CalleeArgInfo

2023-04-28 Thread Tom Praschan via cfe-commits

Author: Tom Praschan
Date: 2023-04-28T21:46:32+02:00
New Revision: a7b4fd953f44b790f8832a5b57d7598bd12adfb2

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

LOG: [clangd] Hover: resolve forwarding parameters for CalleeArgInfo

This uses the logic added in D124690

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 3eb0900715744..f59642dbf721d 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -996,13 +996,15 @@ void maybeAddCalleeArgInfo(const SelectionTree::Node *N, 
HoverInfo &HI,
 
   HoverInfo::PassType PassType;
 
+  auto Parameters = resolveForwardingParameters(FD);
+
   // Find argument index for N.
-  for (unsigned I = 0; I < CE->getNumArgs() && I < FD->getNumParams(); ++I) {
+  for (unsigned I = 0; I < CE->getNumArgs() && I < Parameters.size(); ++I) {
 if (CE->getArg(I) != OuterNode.ASTNode.get())
   continue;
 
 // Extract matching argument from function declaration.
-if (const ParmVarDecl *PVD = FD->getParamDecl(I)) {
+if (const ParmVarDecl *PVD = Parameters[I]) {
   HI.CalleeArgInfo.emplace(toHoverInfoParam(PVD, PP));
   if (N == &OuterNode)
 PassType.PassBy = getPassMode(PVD->getType());

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 5ad9d69cb0dc2..5bf089fbbfeca 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -906,6 +906,35 @@ class Foo final {})cpp";
  HI.CalleeArgInfo->Type = "int &";
  HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
}},
+  {// make_unique-like function call
+   R"cpp(
+  struct Foo {
+explicit Foo(int arg_a) {}
+  };
+  template
+  T make(Args&&... args)
+  {
+  return T(args...);
+  }
+
+  void code() {
+int a = 1;
+auto foo = make([[^a]]);
+  }
+  )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "a";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.Definition = "int a = 1";
+ HI.LocalScope = "code::";
+ HI.Value = "1";
+ HI.Type = "int";
+ HI.CalleeArgInfo.emplace();
+ HI.CalleeArgInfo->Name = "arg_a";
+ HI.CalleeArgInfo->Type = "int";
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, false};
+   }},
   {
   R"cpp(
   void foobar(const float &arg);



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


[PATCH] D147846: [clangd] Hover: resolve forwarding parameters for CalleeArgInfo

2023-04-28 Thread Tom Praschan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa7b4fd953f44: [clangd] Hover: resolve forwarding parameters 
for CalleeArgInfo (authored by tom-anders).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147846

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
@@ -906,6 +906,35 @@
  HI.CalleeArgInfo->Type = "int &";
  HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
}},
+  {// make_unique-like function call
+   R"cpp(
+  struct Foo {
+explicit Foo(int arg_a) {}
+  };
+  template
+  T make(Args&&... args)
+  {
+  return T(args...);
+  }
+
+  void code() {
+int a = 1;
+auto foo = make([[^a]]);
+  }
+  )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "a";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.Definition = "int a = 1";
+ HI.LocalScope = "code::";
+ HI.Value = "1";
+ HI.Type = "int";
+ HI.CalleeArgInfo.emplace();
+ HI.CalleeArgInfo->Name = "arg_a";
+ HI.CalleeArgInfo->Type = "int";
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, false};
+   }},
   {
   R"cpp(
   void foobar(const float &arg);
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -996,13 +996,15 @@
 
   HoverInfo::PassType PassType;
 
+  auto Parameters = resolveForwardingParameters(FD);
+
   // Find argument index for N.
-  for (unsigned I = 0; I < CE->getNumArgs() && I < FD->getNumParams(); ++I) {
+  for (unsigned I = 0; I < CE->getNumArgs() && I < Parameters.size(); ++I) {
 if (CE->getArg(I) != OuterNode.ASTNode.get())
   continue;
 
 // Extract matching argument from function declaration.
-if (const ParmVarDecl *PVD = FD->getParamDecl(I)) {
+if (const ParmVarDecl *PVD = Parameters[I]) {
   HI.CalleeArgInfo.emplace(toHoverInfoParam(PVD, PP));
   if (N == &OuterNode)
 PassType.PassBy = getPassMode(PVD->getType());


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -906,6 +906,35 @@
  HI.CalleeArgInfo->Type = "int &";
  HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
}},
+  {// make_unique-like function call
+   R"cpp(
+  struct Foo {
+explicit Foo(int arg_a) {}
+  };
+  template
+  T make(Args&&... args)
+  {
+  return T(args...);
+  }
+
+  void code() {
+int a = 1;
+auto foo = make([[^a]]);
+  }
+  )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "a";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.Definition = "int a = 1";
+ HI.LocalScope = "code::";
+ HI.Value = "1";
+ HI.Type = "int";
+ HI.CalleeArgInfo.emplace();
+ HI.CalleeArgInfo->Name = "arg_a";
+ HI.CalleeArgInfo->Type = "int";
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, false};
+   }},
   {
   R"cpp(
   void foobar(const float &arg);
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -996,13 +996,15 @@
 
   HoverInfo::PassType PassType;
 
+  auto Parameters = resolveForwardingParameters(FD);
+
   // Find argument index for N.
-  for (unsigned I = 0; I < CE->getNumArgs() && I < FD->getNumParams(); ++I) {
+  for (unsigned I = 0; I < CE->getNumArgs() && I < Parameters.size(); ++I) {
 if (CE->getArg(I) != OuterNode.ASTNode.get())
   continue;
 
 // Extract matching argument from function declaration.
-if (const ParmVarDecl *PVD = FD->getParamDecl(I)) {
+if (const ParmVarDecl *PVD = Parameters[I]) {
   HI.CalleeArgInfo.emplace(toHoverInfoParam(PVD, PP));
   if (N == &OuterNode)
 PassType.PassBy = getPassMode(PVD->getType());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

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

LGTM, but please add a release note when landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

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


[PATCH] D147847: [clangd] Hover: Add CalleeArgInfo for constructor expressions

2023-04-28 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders updated this revision to Diff 517994.
tom-anders marked an inline comment as done.
tom-anders added a comment.

Use ArrayRef instead of SmallVector to avoid copy (also fix 2 typos in the 
comment below)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147847

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
@@ -956,6 +956,29 @@
 HI.CalleeArgInfo->Type = "const float &";
 HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
   }},
+  {
+  R"cpp(
+  struct Foo {
+explicit Foo(const float& arg) {}
+  };
+  int main() {
+int a = 0;
+Foo foo([[^a]]);
+  }
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Name = "a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Definition = "int a = 0";
+HI.LocalScope = "main::";
+HI.Value = "0";
+HI.Type = "int";
+HI.CalleeArgInfo.emplace();
+HI.CalleeArgInfo->Name = "arg";
+HI.CalleeArgInfo->Type = "const float &";
+HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
+  }},
   {// Literal passed to function call
R"cpp(
   void fun(int arg_a, const int &arg_b) {};
@@ -1342,6 +1365,7 @@
   CustomClass(const Base &x) {}
   CustomClass(int &x) {}
   CustomClass(float x) {}
+  CustomClass(int x, int y) {}
 };
 
 void int_by_ref(int &x) {}
@@ -1388,6 +1412,11 @@
   {"base_by_ref([[^derived]]);", PassMode::Ref, false},
   {"base_by_const_ref([[^derived]]);", PassMode::ConstRef, false},
   {"base_by_value([[^derived]]);", PassMode::Value, false},
+  // Custom class constructor tests
+  {"CustomClass c1([[^base]]);", PassMode::ConstRef, false},
+  {"auto c2 = new CustomClass([[^base]]);", PassMode::ConstRef, false},
+  {"CustomClass c3([[^int_x]]);", PassMode::Ref, false},
+  {"CustomClass c3(int_x, [[^int_x]]);", PassMode::Value, false},
   // Converted tests
   {"float_by_value([[^int_x]]);", PassMode::Value, true},
   {"float_by_value([[^int_ref]]);", PassMode::Value, true},
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -981,12 +981,23 @@
   const auto &OuterNode = N->outerImplicit();
   if (!OuterNode.Parent)
 return;
-  const auto *CE = OuterNode.Parent->ASTNode.get();
-  if (!CE)
+
+  const FunctionDecl *FD = nullptr;
+  llvm::ArrayRef Args;
+
+  if (const auto *CE = OuterNode.Parent->ASTNode.get()) {
+FD = CE->getDirectCallee();
+Args = {CE->getArgs(), CE->getNumArgs()};
+  } else if (const auto *CE =
+ OuterNode.Parent->ASTNode.get()) {
+FD = CE->getConstructor();
+Args = {CE->getArgs(), CE->getNumArgs()};
+  }
+  if (!FD)
 return;
-  const FunctionDecl *FD = CE->getDirectCallee();
-  // For non-function-call-like operatators (e.g. operator+, operator<<) it's
-  // not immediattely obvious what the "passed as" would refer to and, given
+
+  // For non-function-call-like operators (e.g. operator+, operator<<) it's
+  // not immediately obvious what the "passed as" would refer to and, given
   // fixed function signature, the value would be very low anyway, so we choose
   // to not support that.
   // Both variadic functions and operator() (especially relevant for lambdas)
@@ -999,8 +1010,8 @@
   auto Parameters = resolveForwardingParameters(FD);
 
   // Find argument index for N.
-  for (unsigned I = 0; I < CE->getNumArgs() && I < Parameters.size(); ++I) {
-if (CE->getArg(I) != OuterNode.ASTNode.get())
+  for (unsigned I = 0; I < Args.size() && I < Parameters.size(); ++I) {
+if (Args[I] != OuterNode.ASTNode.get())
   continue;
 
 // Extract matching argument from function declaration.


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -956,6 +956,29 @@
 HI.CalleeArgInfo->Type = "const float &";
 HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
   }},
+  {
+  R"cpp(
+  struct Foo {
+explicit Foo(const float& arg) {}
+  };
+  int main() {
+int a = 0;
+Foo foo([[^a]]);
+  }
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Name = "a";
+ 

[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-04-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6241-6244
 def ext_flexible_array_empty_aggregate_ms : Extension<
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a Microsoft extension">,
   InGroup;

Fznamznon wrote:
> aaron.ballman wrote:
> > Should this be updated to remove the union case?
> Sounds reasonable, but what is unfortunate is that this diagnostic exactly 
> matches TagTypeKind enum, so now it can be emitted with `Diag(...) << ... << 
> SomeTagDecl->getTagKind().` Once I remove `union` from there, this neat thing 
> fails.
Oh, that might be worth leaving alone then, but put a comment next to the 
diagnostic definition to explain the relationship to `TagTypeKind`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

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


[PATCH] D147847: [clangd] Hover: Add CalleeArgInfo for constructor expressions

2023-04-28 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:986
+  const FunctionDecl *FD = nullptr;
+  llvm::SmallVector Args;
+

nridge wrote:
> tom-anders wrote:
> > Unfortunately, while CallExpr and CXXConstructExpr basically have the same 
> > API for getting Args, they're not related by a common base class.
> > 
> > Is there a more elegant solution than temporarily storing the Args in a 
> > SmallVector here?
> You can use `ArrayRef` instead of `SmallVector` and avoid copying the 
> arguments (compare 
> [process_call](https://searchfox.org/llvm/rev/b34ca0851a5209a10c0ca285c000a18073677891/clang-tools-extra/clangd/InlayHints.cpp#239,265)
>  in `InlayHintVisitor`).
Ah perfect, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147847

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


[PATCH] D143112: [clang] Support parsing comments without ASTContext

2023-04-28 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

(ping) Does this make sense or are more adjustments needed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143112

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


[PATCH] D149405: [Clang][Doc] Added an open project for improving command line docs

2023-04-28 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 517996.
xgupta added a comment.

address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149405

Files:
  clang/www/OpenProjects.html


Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -38,6 +38,8 @@
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td";>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td";>
+  command line options, or
   help with completing other missing documentation.
 
 These projects are independent of each other.


Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -38,6 +38,8 @@
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td";>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td";>
+  command line options, or
   help with completing other missing documentation.
 
 These projects are independent of each other.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a704854 - [Clang][Doc] Added an open project for improving command line docs

2023-04-28 Thread Shivam Gupta via cfe-commits

Author: Shivam Gupta
Date: 2023-04-28T23:32:37+05:30
New Revision: a70485493803d2e22cbc79184b78861b098ba416

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

LOG: [Clang][Doc] Added an open project for improving command line docs

There seems to be a lot of documentation is missing
for different command line flags uses.
This create confusion with same looking options, better to
document clearly their uses.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/www/OpenProjects.html

Removed: 




diff  --git a/clang/www/OpenProjects.html b/clang/www/OpenProjects.html
index 4b6b0283767c0..77f04160700fc 100755
--- a/clang/www/OpenProjects.html
+++ b/clang/www/OpenProjects.html
@@ -38,6 +38,8 @@ Open Clang Projects
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td";>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td";>
+  command line options, or
   help with completing other missing documentation.
 
 These projects are independent of each other.



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


[PATCH] D149405: [Clang][Doc] Added an open project for improving command line docs

2023-04-28 Thread Shivam Gupta via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
xgupta marked an inline comment as done.
Closed by commit rGa70485493803: [Clang][Doc] Added an open project for 
improving command line docs (authored by xgupta).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149405

Files:
  clang/www/OpenProjects.html


Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -38,6 +38,8 @@
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td";>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td";>
+  command line options, or
   help with completing other missing documentation.
 
 These projects are independent of each other.


Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -38,6 +38,8 @@
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td";>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td";>
+  command line options, or
   help with completing other missing documentation.
 
 These projects are independent of each other.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149405: [Clang][Doc] Added an open project for improving command line docs

2023-04-28 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

In D149405#4305856 , @aaron.ballman 
wrote:

> Thank you, this is a great suggestion! Just some minor wording changes, but 
> otherwise LGTM.

Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149405

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


[PATCH] D146654: [clang] replaces numeric SARIF ids with heirarchical names

2023-04-28 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added inline comments.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:51-52
+  Diag->getDiags()->getDiagnosticIDs()->getStableName(Diag->getID()).str();
+  std::replace(StableName.begin(), StableName.end(), '_', '.');
+  SarifRule Rule = SarifRule::create().setRuleId(StableName);
 

vaibhav.y wrote:
> cjdb wrote:
> > denik wrote:
> > > §3.5.4 says that the hierarchical strings are separated by "/".
> > > 
> > > But more generally, are diagnostic names really fall under "hierarchical" 
> > > definition?
> > > Words between underscores should be treated as components. And $3.27.5 
> > > says that the leading components have to be the identifier of the rule.
> > > In some cases they look like valid components, e.g. `err_access`, 
> > > `err_access_dtor`, `err_access_dtor_exception`.
> > > But in cases like `err_cannot_open_file` neither of the leading 
> > > components exists.
> > > 
> > > Theoretically we could use groups as the leading component for warnings 
> > > for example. For errors the leading components are probably not even 
> > > necessary, since if I understood correctly they are needed to suppress 
> > > subsets of violations on the SARIF consumer side.
> > > Or we just could keep the names with underscores as is. WDYT?
> > I think in light of what you've said, changing back to underscores is 
> > probably best.
> > But more generally, are diagnostic names really fall under "hierarchical" 
> > definition?
> 
> I have the same concern, but this is okay for a first pass as a "flat 
> hierarchy" :)
> 
> If we want a deeper structure, we'll need some extra metadata in 
> `DiagnosticSemaKinds.td`'s `Error<...>`  to add cluster names as a follow up 
> to this.
> 
> WDYT about something like `clang/visibility/err_access` or 
> `clang/syntax/err_stmtexpr_file_scope`.
> 
> Alternatively: we could draw from the c++ standard structure: 
> https://eel.is/c++draft/basic.def.odr#term.odr.use and say the error code for 
> an ODR violation could be `clang/basic/def/odr`, again I'm unsure how well 
> this meshes with clang's diagnostic model.
> Alternatively: we could draw from the c++ standard structure: 
> https://eel.is/c++draft/basic.def.odr#term.odr.use and say the error code for 
> an ODR violation could be clang/basic/def/odr, again I'm unsure how well this 
> meshes with clang's diagnostic model.

The only reliable thing there are stable clause names like `[namespace.udecl]`, 
because there are precedents of them being rearranged in the table of contents 
([[ 
https://github.com/cplusplus/draft/commit/982a456f176ca00409c6e514af932051dce2485f
 | 1 ]], [[ 
https://github.com/cplusplus/draft/commit/3c580cd204fde95a21de1830ace75d14d429f845
 | 2 ]]). We've got bitten by that in C++ conformance tests, which use table of 
contents for directory hierarchy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146654

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


[PATCH] D146654: [clang] replaces numeric SARIF ids with heirarchical names

2023-04-28 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:51-52
+  Diag->getDiags()->getDiagnosticIDs()->getStableName(Diag->getID()).str();
+  std::replace(StableName.begin(), StableName.end(), '_', '.');
+  SarifRule Rule = SarifRule::create().setRuleId(StableName);
 

Endill wrote:
> vaibhav.y wrote:
> > cjdb wrote:
> > > denik wrote:
> > > > §3.5.4 says that the hierarchical strings are separated by "/".
> > > > 
> > > > But more generally, are diagnostic names really fall under 
> > > > "hierarchical" definition?
> > > > Words between underscores should be treated as components. And $3.27.5 
> > > > says that the leading components have to be the identifier of the rule.
> > > > In some cases they look like valid components, e.g. `err_access`, 
> > > > `err_access_dtor`, `err_access_dtor_exception`.
> > > > But in cases like `err_cannot_open_file` neither of the leading 
> > > > components exists.
> > > > 
> > > > Theoretically we could use groups as the leading component for warnings 
> > > > for example. For errors the leading components are probably not even 
> > > > necessary, since if I understood correctly they are needed to suppress 
> > > > subsets of violations on the SARIF consumer side.
> > > > Or we just could keep the names with underscores as is. WDYT?
> > > I think in light of what you've said, changing back to underscores is 
> > > probably best.
> > > But more generally, are diagnostic names really fall under "hierarchical" 
> > > definition?
> > 
> > I have the same concern, but this is okay for a first pass as a "flat 
> > hierarchy" :)
> > 
> > If we want a deeper structure, we'll need some extra metadata in 
> > `DiagnosticSemaKinds.td`'s `Error<...>`  to add cluster names as a follow 
> > up to this.
> > 
> > WDYT about something like `clang/visibility/err_access` or 
> > `clang/syntax/err_stmtexpr_file_scope`.
> > 
> > Alternatively: we could draw from the c++ standard structure: 
> > https://eel.is/c++draft/basic.def.odr#term.odr.use and say the error code 
> > for an ODR violation could be `clang/basic/def/odr`, again I'm unsure how 
> > well this meshes with clang's diagnostic model.
> > Alternatively: we could draw from the c++ standard structure: 
> > https://eel.is/c++draft/basic.def.odr#term.odr.use and say the error code 
> > for an ODR violation could be clang/basic/def/odr, again I'm unsure how 
> > well this meshes with clang's diagnostic model.
> 
> The only reliable thing there are stable clause names like 
> `[namespace.udecl]`, because there are precedents of them being rearranged in 
> the table of contents ([[ 
> https://github.com/cplusplus/draft/commit/982a456f176ca00409c6e514af932051dce2485f
>  | 1 ]], [[ 
> https://github.com/cplusplus/draft/commit/3c580cd204fde95a21de1830ace75d14d429f845
>  | 2 ]]). We've got bitten by that in C++ conformance tests, which use table 
> of contents for directory hierarchy.
> WDYT about something like `clang/visibility/err_access` or 
> `clang/syntax/err_stmtexpr_file_scope`.

I think this might work!

> > Alternatively: we could draw from the c++ standard structure: 
> > https://eel.is/c++draft/basic.def.odr#term.odr.use and say the error code 
> > for an ODR violation could be clang/basic/def/odr, again I'm unsure how 
> > well this meshes with clang's diagnostic model.
> 
> The only reliable thing there are stable clause names like 
> `[namespace.udecl]`, because there are precedents of them being rearranged in 
> the table of contents ([[ 
> https://github.com/cplusplus/draft/commit/982a456f176ca00409c6e514af932051dce2485f
>  | 1 ]], [[ 
> https://github.com/cplusplus/draft/commit/3c580cd204fde95a21de1830ace75d14d429f845
>  | 2 ]]). We've got bitten by that in C++ conformance tests, which use table 
> of contents for directory hierarchy.

Right. Given that section names aren't actually stable, relying on those would 
be brittle at best.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146654

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


[PATCH] D149464: [clang][dataflow] Expose DataflowAnalysisContext from DataflowEnvironment.

2023-04-28 Thread Samira Bazuzi via Phabricator via cfe-commits
bazuzi added a comment.

Thanks! Seems like you have commit access, Yitzie; could you commit this for me 
as "Samira Bazuzi "?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149464

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


  1   2   >