[PATCH] D147295: [clang-format] Don't misannotate left squares as lambda introducers

2023-03-31 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147295

___
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-marchs and -march=help support

2023-03-31 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

I would support have `-march=help`, but I know it's really not make scene to 
alias `-march=help` to `--print-supported-extensions` for other targets, what 
about redirect that in `Driver.cpp` for RISC-V only?


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] D135171: FreeBSD: enable __float128 on x86

2023-03-31 Thread Brooks Davis via Phabricator via cfe-commits
brooks updated this revision to Diff 509934.
brooks added a comment.

- Rebase
- Add powerpc64le


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135171

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/CodeGenCXX/float128-declarations.cpp


Index: clang/test/CodeGenCXX/float128-declarations.cpp
===
--- clang/test/CodeGenCXX/float128-declarations.cpp
+++ clang/test/CodeGenCXX/float128-declarations.cpp
@@ -2,6 +2,8 @@
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -triple powerpc64le-unknown-unknown \
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple i386-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu -std=c++11 \
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -234,15 +234,24 @@
 // setting this to 1 is conforming even if all the basic source
 // character literals have the same encoding as char and wchar_t.
 Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
+
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
   }
 
 public:
   FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : OSTargetInfo(Triple, Opts) {
 switch (Triple.getArch()) {
-default:
+case llvm::Triple::ppc64le:
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+}
+switch (Triple.getArch()) {
+case llvm::Triple::x86:
+case llvm::Triple::x86_64:
+default:
   this->MCountName = ".mcount";
   break;
 case llvm::Triple::mips:


Index: clang/test/CodeGenCXX/float128-declarations.cpp
===
--- clang/test/CodeGenCXX/float128-declarations.cpp
+++ clang/test/CodeGenCXX/float128-declarations.cpp
@@ -2,6 +2,8 @@
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -triple powerpc64le-unknown-unknown \
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple i386-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu -std=c++11 \
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -234,15 +234,24 @@
 // setting this to 1 is conforming even if all the basic source
 // character literals have the same encoding as char and wchar_t.
 Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
+
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
   }
 
 public:
   FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : OSTargetInfo(Triple, Opts) {
 switch (Triple.getArch()) {
-default:
+case llvm::Triple::ppc64le:
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+}
+switch (Triple.getArch()) {
+case llvm::Triple::x86:
+case llvm::Triple::x86_64:
+default:
   this->MCountName = ".mcount";
   break;
 case llvm::Triple::mips:
___
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-03-31 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

Overall it looks like we are heading in a good direction. Here are some initial 
comments from my partial review.




Comment at: clang/include/clang/Interpreter/Interpreter.h:109
+  std::list &getPTUs();
+  std::unique_ptr GenModule();
+

Do we need to expose this function to the outside world?



Comment at: clang/lib/Interpreter/ASTHelpers.cpp:1
+#include "ASTHelpers.h"
+

Likewise.



Comment at: clang/lib/Interpreter/ASTHelpers.h:1
+#ifndef LLVM_CLANG_INTERPRETER_AST_HELPERS_H
+#define LLVM_CLANG_INTERPRETER_AST_HELPERS_H

We are missing the standard llvm header preamble. Clang seems to have slight 
preference to using `Utils` in the name. How about renaming this file to 
`InterpreterUtils.h`



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:22
 #include "clang/FrontendTool/Utils.h"
+#include "clang/Interpreter/Interpreter.h"
 #include "clang/Parse/Parser.h"

This introduces a layering violation. Can we avoid it?



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:162
+  if (P->getCurToken().is(tok::annot_input_end)) {
+P->ConsumeAnyToken();
 // FIXME: Clang does not call ExitScope on finalizing the regular TU, we

Why `ConsumeToken` is not sufficient for an `annot_input_end`?



Comment at: clang/lib/Interpreter/IncrementalParser.h:82
+
+  CodeGenerator *GetCodeGen() const;
+  std::unique_ptr GenModule();

Do we need to expose CodeGen in this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

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


[PATCH] D135171: FreeBSD: enable __float128 on x86 and powerpc64le

2023-03-31 Thread Dimitry Andric via Phabricator via cfe-commits
dim accepted this revision.
dim added a comment.

LGTM again :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135171

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


[PATCH] D145264: [OpenMP][MLIR][Flang][Driver][bbc] Lower and apply Module FlagsAttr

2023-03-31 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski accepted this revision.
awarzynski added a comment.
This revision is now accepted and ready to land.

@agozillon Thanks for the updates, LGTM! Please wait for somebody to review the 
OpenMP changes before merging.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

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


[PATCH] D145965: [C++20][Modules] Fix incorrect visibilities in implementation units.

2023-03-31 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

Just took a quick look.




Comment at: clang/lib/Sema/SemaLookup.cpp:2082
+Module *DeclModule = SemaRef.getOwningModule(D);
+if (DeclModule && !DeclModule->isModuleMapModule() &&
+!SemaRef.isModuleUnitOfCurrentTU(DeclModule) &&

We should check header units here.



Comment at: clang/lib/Sema/SemaLookup.cpp:2101
+  if (isVisible(SemaRef, ND)) {
+if (SemaRef.getLangOpts().CPlusPlusModules && ND->isFromASTFile()) {
+  // The module that owns the decl is visible; However

Let's not use `isFromASTFile()`. It is a low level API without higher level 
semantics. I think it is good enough to check the module of ND.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145965

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


[PATCH] D147307: [clang] Consider artificial always inline builtin as inline builtins

2023-03-31 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added reviewers: aaron.ballman, tstellar, efriedma.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix #61691


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147307

Files:
  clang/lib/AST/Decl.cpp
  clang/test/CodeGen/memcpy-inline-builtin.c

Index: clang/test/CodeGen/memcpy-inline-builtin.c
===
--- clang/test/CodeGen/memcpy-inline-builtin.c
+++ clang/test/CodeGen/memcpy-inline-builtin.c
@@ -3,18 +3,27 @@
 // RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -o - %s | FileCheck %s
 //
 // Verifies that clang detects memcpy inline version and uses it instead of the builtin.
+// Checks alternate version with the `artificial` attribute.
 
 typedef unsigned long size_t;
 
 // Clang requires these attributes for a function to be redefined.
 #define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) __attribute__((gnu_inline))
 
+#define AVAILABLE_EXTERNALLY_ALTERNATE extern inline __attribute__((__always_inline__)) __attribute__((__artificial__))
+
 // Clang recognizes an inline builtin and renames it to prevent conflict with builtins.
 AVAILABLE_EXTERNALLY void *memcpy(void *a, const void *b, size_t c) {
   asm("# memcpy.inline marker");
   return __builtin_memcpy(a, b, c);
 }
 
+// Clang recognizes an inline builtin and renames it to prevent conflict with builtins.
+AVAILABLE_EXTERNALLY_ALTERNATE void *memmove(void *a, const void *b, size_t c) {
+  asm("# memmove.inline marker");
+  return __builtin_memmove(a, b, c);
+}
+
 // CHECK-LABEL: @foo(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[A_ADDR_I:%.*]] = alloca ptr, align 8
@@ -43,6 +52,34 @@
   return memcpy(a, b, c);
 }
 
+// CHECK-LABEL: @foo_alt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR_I:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[B_ADDR_I:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[C_ADDR_I:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[C_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store ptr [[A:%.*]], ptr [[A_ADDR]], align 8
+// CHECK-NEXT:store ptr [[B:%.*]], ptr [[B_ADDR]], align 8
+// CHECK-NEXT:store i64 [[C:%.*]], ptr [[C_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[A_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP2:%.*]] = load i64, ptr [[C_ADDR]], align 8
+// CHECK-NEXT:store ptr [[TMP0]], ptr [[A_ADDR_I]], align 8
+// CHECK-NEXT:store ptr [[TMP1]], ptr [[B_ADDR_I]], align 8
+// CHECK-NEXT:store i64 [[TMP2]], ptr [[C_ADDR_I]], align 8
+// CHECK-NEXT:call void asm sideeffect "# memmove.inline marker", "~{dirflag},~{fpsr},~{flags}"() #[[ATTR3]], !srcloc !3
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[A_ADDR_I]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[B_ADDR_I]], align 8
+// CHECK-NEXT:[[TMP5:%.*]] = load i64, ptr [[C_ADDR_I]], align 8
+// CHECK-NEXT:call void @llvm.memmove.p0.p0.i64(ptr align 1 [[TMP3]], ptr align 1 [[TMP4]], i64 [[TMP5]], i1 false)
+// CHECK-NEXT:ret ptr [[TMP3]]
+//
+void *foo_alt(void *a, const void *b, size_t c) {
+  return memmove(a, b, c);
+}
+
 // CHECK-LABEL: @bar(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[A_ADDR:%.*]] = alloca ptr, align 8
@@ -68,3 +105,29 @@
   void *(*cpy)(void *, const void *, size_t) = c > 10 ? memcpy : foo;
   cpy(a, b, c);
 }
+
+// CHECK-LABEL: @bar_alt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[C_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[CPY:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:store ptr [[A:%.*]], ptr [[A_ADDR]], align 8
+// CHECK-NEXT:store ptr [[B:%.*]], ptr [[B_ADDR]], align 8
+// CHECK-NEXT:store i64 [[C:%.*]], ptr [[C_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr [[C_ADDR]], align 8
+// CHECK-NEXT:[[CMP:%.*]] = icmp ugt i64 [[TMP0]], 10
+// CHECK-NEXT:[[TMP1:%.*]] = zext i1 [[CMP]] to i64
+// CHECK-NEXT:[[COND:%.*]] = select i1 [[CMP]], ptr @memmove, ptr @foo_alt
+// CHECK-NEXT:store ptr [[COND]], ptr [[CPY]], align 8
+// CHECK-NEXT:[[TMP2:%.*]] = load ptr, ptr [[CPY]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[A_ADDR]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP5:%.*]] = load i64, ptr [[C_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call ptr [[TMP2]](ptr noundef [[TMP3]], ptr noundef [[TMP4]], i64 noundef [[TMP5]])
+// CHECK-NEXT:ret void
+//
+void bar_alt(void *a, const void *b, size_t c) {
+  void *(*cpy)(void *, const void *, size_t) = c > 10 ? memmove : foo_alt;
+  cpy(a, b, c);
+}
Index:

[PATCH] D135171: FreeBSD: enable __float128 on x86 and powerpc64le

2023-03-31 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.

My comments are minor nits that don't require another review, so LGTM.




Comment at: clang/lib/Basic/Targets/OSTargets.h:245-250
 switch (Triple.getArch()) {
-default:
+case llvm::Triple::ppc64le:
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+}

Seems a bit odd to have a separate switch on the same value for `__float128` 
rather than using fallthrough.



Comment at: clang/test/CodeGenCXX/float128-declarations.cpp:5-6
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple i386-unknown-linux-gnu -std=c++11 \

Now that you added `ppc64le`, did you mean to also add a line with that triple 
without the explicit `-target-feature`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135171

___
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-03-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 509958.
junaire added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.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,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,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"
@@ -314,4 +318,38 @@
   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_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_EQ(V2.getAs(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.castAs(), 3);
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 42);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 43);
+  EXPECT_TRUE(V4.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/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for incremental
   // processing
-  if (PP.isIncrementalProcess

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

2023-03-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire marked 3 inline comments as done.
junaire added inline comments.



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:162
+  if (P->getCurToken().is(tok::annot_input_end)) {
+P->ConsumeAnyToken();
 // FIXME: Clang does not call ExitScope on finalizing the regular TU, we

v.g.vassilev wrote:
> Why `ConsumeToken` is not sufficient for an `annot_input_end`?
No, we can't. `ConsumeToken` can't eat special tokens. See 
https://github.com/llvm/llvm-project/blob/fc6e91fe8184129d2395b79ce42f4495b95b0d0d/clang/include/clang/Parse/Parser.h#L494-L501


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

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


[PATCH] D145264: [OpenMP][MLIR][Flang][Driver][bbc] Lower and apply Module FlagsAttr

2023-03-31 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan requested changes to this revision.
kiranchandramohan added a comment.
This revision now requires changes to proceed.

Please split this patch into three:

1. Code changes and testing for the driver and the FIR+OpenMP dialect generated.
2. Code changes and test for FIR+OpenMP to LLVM+OpenMP dialect.
3. Code changes and testing for the translation from LLVM + OpenMP dialect to 
LLVM IR. Code in OpenMPToLLVMIRTranslation.cpp should be tested with 
`mlir-translate`.

In D145264#4233358 , @agozillon wrote:

> Unfortunately I do not believe an mlir-translate test that tests if the 
> OffloadModuleInterface is accessible when directly utilizing mlir-translate 
> is possible for this patch... I forgot I removed the is device check as it is 
> already done at the initial creation of the attribute. However, I do have a 
> future patch that it will be utilised in and when @jsjodin's initial TargetOp 
> work is in I can likely create a test around that functionality.

You may delay the translation code till then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

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


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

2023-03-31 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 updated this revision to Diff 509982.
jp4a50 added a comment.

Replace DesignatedInitializerIndentWidth with BracedInitializerIndentWidth 
which applies to a broader range of initializers.


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 initia

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

2023-03-31 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

I've implemented BracedInitializerIndentWidth now with significantly extended 
test coverage (including checking that it is not applied *too* broadly). The 
actual implementation is just as simple as that for 
`DesignatedInitializerIndentWidth`.

> For the yaml stuff, I for one like to define everything (even it has the 
> default value), thus I'd like the -1 or something on output. But if that 
> leads to messing around with the yaml code just use what it does.

Pretty sure I would have to modify the YAML code in order to get it to output 
something when `std::optional` is set to `std::nullopt` so I have 
left it as-is.

PTAL.


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] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-03-31 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added a reviewer: LegalizeAdulthood.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

fixed 60810 
add matcher for `enumConstantDecl`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147315

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -1,10 +1,21 @@
 // RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t -- -- -isystem %S/Inputs/static-accessed-through-instance
 #include <__clang_cuda_builtin_vars.h>
 
+enum OutEnum {
+  E0,
+};
+
 struct C {
   static void foo();
   static int x;
   int nsx;
+  enum {
+Anonymous,
+  };
+  enum E {
+E1,
+  };
+  using enum OutEnum;
   void mf() {
 (void)&x;// OK, x is accessed inside the struct.
 (void)&C::x; // OK, x is accessed using a qualified-id.
@@ -144,6 +155,16 @@
   c1->x; // 2
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
   // CHECK-FIXES: {{^}}  C::x; // 2{{$}}
+  c1->Anonymous; // 3
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::Anonymous; // 3{{$}}
+  c1->E1; // 4
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::E1; // 4{{$}}
+  c1->E0; // 5
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::E0; // 5{{$}}
+
   c1->nsx; // OK, nsx is a non-static member.
 
   const C *c2 = new C();
Index: clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
@@ -15,11 +15,15 @@
   struct C {
 static void foo();
 static int x;
+enum { E1 };
+enum E { E2 };
   };
 
   C *c1 = new C();
   c1->foo();
   c1->x;
+  c1->E1;
+  c1->E2;
 
 is changed to:
 
@@ -28,4 +32,6 @@
   C *c1 = new C();
   C::foo();
   C::x;
+  C::E1;
+  C::E2;
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -261,6 +261,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to 
+  support unscoped enumerations through instances.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -39,7 +39,8 @@
 void StaticAccessedThroughInstanceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStaticStorageClass()),
-  varDecl(hasStaticStorageDuration()
+  varDecl(hasStaticStorageDuration()),
+  enumConstantDecl(
   .bind("memberExpression"),
   this);
 }
@@ -64,15 +65,15 @@
   : BaseExpr->getType().getUnqualifiedType();
 
   const ASTContext *AstContext = Result.Context;
-  PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
-  PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
-  PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
+  PrintingPolicy PrintingPolicyWithSuppressedTag(AstContext->getLangOpts());
+  PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
+  PrintingPolicyWithSuppressedTag.SuppressUnwrittenScope = true;
 
-  PrintingPolicyWithSupressedTag.PrintCanonicalTypes =
+  PrintingPolicyWithSuppressedTag.PrintCanonicalTypes =
   !BaseExpr->getType()->isTypedefNameType();
 
   std::string BaseTypeName =
-  BaseType.getAsString(PrintingPolicyWithSupressedTag);
+  BaseType.getAsString(P

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

2023-03-31 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added inline comments.



Comment at: clang/docs/tools/dump_format_style.py:72
 
-  subtype, napplied = re.subn(r'^std::vector<(.*)>$', r'\1', typestr)
-  if napplied == 1:
-return 'List of ' + pluralize(to_yaml_type(subtype))
+  match = re.match(r'std::vector<(.*)>$', typestr)
+  if match:

I changed this from `subn` to `match` here since it's just a simpler way of 
expressing the same thing.


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


[clang] cef69ce - [clang][Interp] Fix record initialization via CallExpr subclasses

2023-03-31 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-31T13:16:49+02:00
New Revision: cef69ce7791f2b6415ef3991347904381717a1ec

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

LOG: [clang][Interp] Fix record initialization via CallExpr subclasses

We can't just use VisitCallExpr() here, as that doesn't handle CallExpr
subclasses such as CXXMemberCallExpr.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 1e61bc992448..afa5372a5112 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1413,7 +1413,7 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
 if (!this->emitDupPtr(Initializer))
   return false;
 
-return this->VisitCallExpr(CE);
+return this->visit(CE);
   } else if (const auto *DIE = dyn_cast(Initializer)) {
 return this->visitInitializer(DIE->getExpr());
   } else if (const auto *CE = dyn_cast(Initializer)) {

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index c0bfdeb090eb..448e1c0eb722 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -98,12 +98,20 @@ class C {
 int b;
 
   constexpr C() : a(100), b(200) {}
+
+  constexpr C get() const {
+return *this;
+  }
 };
 
 constexpr C c;
 static_assert(c.a == 100, "");
 static_assert(c.b == 200, "");
 
+constexpr C c2 = C().get();
+static_assert(c.a == 100, "");
+static_assert(c.b == 200, "");
+
 constexpr int getB() {
   C c;
   int &j = c.b;



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


[PATCH] D141772: [clang][Interp] Fix record initialization via CallExpr subclasses

2023-03-31 Thread Timm Bäder 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 rGcef69ce7791f: [clang][Interp] Fix record initialization via 
CallExpr subclasses (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D141772?vs=489280&id=509985#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141772

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


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -98,12 +98,20 @@
 int b;
 
   constexpr C() : a(100), b(200) {}
+
+  constexpr C get() const {
+return *this;
+  }
 };
 
 constexpr C c;
 static_assert(c.a == 100, "");
 static_assert(c.b == 200, "");
 
+constexpr C c2 = C().get();
+static_assert(c.a == 100, "");
+static_assert(c.b == 200, "");
+
 constexpr int getB() {
   C c;
   int &j = c.b;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1413,7 +1413,7 @@
 if (!this->emitDupPtr(Initializer))
   return false;
 
-return this->VisitCallExpr(CE);
+return this->visit(CE);
   } else if (const auto *DIE = dyn_cast(Initializer)) {
 return this->visitInitializer(DIE->getExpr());
   } else if (const auto *CE = dyn_cast(Initializer)) {


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -98,12 +98,20 @@
 int b;
 
   constexpr C() : a(100), b(200) {}
+
+  constexpr C get() const {
+return *this;
+  }
 };
 
 constexpr C c;
 static_assert(c.a == 100, "");
 static_assert(c.b == 200, "");
 
+constexpr C c2 = C().get();
+static_assert(c.a == 100, "");
+static_assert(c.b == 200, "");
+
 constexpr int getB() {
   C c;
   int &j = c.b;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1413,7 +1413,7 @@
 if (!this->emitDupPtr(Initializer))
   return false;
 
-return this->VisitCallExpr(CE);
+return this->visit(CE);
   } else if (const auto *DIE = dyn_cast(Initializer)) {
 return this->visitInitializer(DIE->getExpr());
   } else if (const auto *CE = dyn_cast(Initializer)) {
___
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-03-31 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/include/clang/Format/Format.h:949
+  /// If unset, ``ContinuationIndentWidth`` is used.
+  /// \code
+  ///   AlignAfterOpenBracket: AlwaysBreak

did you check generating the html from the rst? I can never remember if we need 
a newline before the \code



Comment at: clang/include/clang/Format/Format.h:4289
DerivePointerAlignment == R.DerivePointerAlignment &&
+   BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
DisableFormat == R.DisableFormat &&

can this be alphabetic



Comment at: clang/lib/Format/Format.cpp:905
 IO.mapOptional("DerivePointerAlignment", Style.DerivePointerAlignment);
+IO.mapOptional("BracedInitializerIndentWidth",
+   Style.BracedInitializerIndentWidth);

also alphabetic



Comment at: clang/lib/Format/Format.cpp:1373
   LLVMStyle.DerivePointerAlignment = false;
+  LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
   LLVMStyle.DisableFormat = false;

ditto alphabetic


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


[clang] aa32490 - [Assignment Tracking] Enable by default

2023-03-31 Thread via cfe-commits

Author: OCHyams
Date: 2023-03-31T12:38:48+01:00
New Revision: aa32490bfe0b957c4f5583e14304f5e34b2b9bce

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

LOG: [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).

Reviewed By: jmorse

Differential Revision: 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 0cc7052b67105..11007c99aa691 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5800,7 +5800,7 @@ def experimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignmen
   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-03-31 Thread Orlando Cazalet-Hyams 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 rGaa32490bfe0b: [Assignment Tracking] Enable by default 
(authored by Orlando).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146987

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


Index: clang/test/CodeGen/assignment-tracking/flag.cpp
===
--- clang/test/CodeGen/assignment-tracking/flag.cpp
+++ 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   
\
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5800,7 +5800,7 @@
   Group, CodeGenOpts<"EnableAssignmentTracking">,
   NormalizedValuesScope<"CodeGenOptions::AssignmentTrackingOpts">,
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
-  MarshallingInfoEnum, "Disabled">;
+  MarshallingInfoEnum, "Enabled">;
 
 } // let Flags = [CC1Option, NoDriverOption]
 


Index: clang/test/CodeGen/assignment-tracking/flag.cpp
===
--- clang/test/CodeGen/assignment-tracking/flag.cpp
+++ 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   \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5800,7 +5800,7 @@
   Group, CodeGenOpts<"EnableAssignmentTracking">,
   NormalizedValuesScope<"CodeGenOptions::AssignmentTrackingOpts">,
   Values<"disabled,enabled,forced">, NormalizedValues<["Disabled","Enabled","Forced"]>,
-  MarshallingInfoEnum, "Disabled">;
+  MarshallingInfoEnum, "Enabled">;
 
 } // let Flags = [CC1Option, NoDriverOption]
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-03-31 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Add test with scoped enums, to validate that it works correctly.
In theory this change should suport them also.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147315

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


[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-03-31 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

And update commit message to be more descriptive...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147315

___
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-03-31 Thread Orlando Cazalet-Hyams via Phabricator via cfe-commits
Orlando added a comment.

> The expected compile-time regression on ReleaseLTO-g is roughly 1.2% right, 
> in exchange for greater variable location coverage?

The compile time tracker is currently reporting around 1.5% for an LTO build. 
However, it's disabled for LTO at the moment until that can be improved.


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] D141215: [clang-repl] Introduce Value to capture expression results

2023-03-31 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/include/clang/Interpreter/Interpreter.h:20
+#include "clang/Interpreter/PartialTranslationUnit.h"
+#include "clang/Interpreter/Value.h"
 

We can forward declare `Value`.



Comment at: clang/include/clang/Interpreter/Interpreter.h:39
+class Parser;
+class CodeGenerator;
 class CompilerInstance;

We probably do not need these forward declarations.



Comment at: clang/include/clang/Interpreter/Interpreter.h:101
+
+  Parser &getParser() const;
+

This seems to be not needed as well.



Comment at: clang/include/clang/Interpreter/Interpreter.h:106
+  Expr *RuntimeAllocInterface = nullptr;
+  Expr *RuntimeCopyArrInterface = nullptr;
+

Maybe these can go in a separate data structure called `ValuePrintingInfo` or 
similar.



Comment at: clang/include/clang/Interpreter/Interpreter.h:119
+
+  std::unique_ptr GenModule();
+

We should not need this interface.



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:162
+  if (P->getCurToken().is(tok::annot_input_end)) {
+P->ConsumeAnyToken();
 // FIXME: Clang does not call ExitScope on finalizing the regular TU, we

junaire wrote:
> v.g.vassilev wrote:
> > Why `ConsumeToken` is not sufficient for an `annot_input_end`?
> No, we can't. `ConsumeToken` can't eat special tokens. See 
> https://github.com/llvm/llvm-project/blob/fc6e91fe8184129d2395b79ce42f4495b95b0d0d/clang/include/clang/Parse/Parser.h#L494-L501
Ok, thanks!



Comment at: clang/lib/Interpreter/Interpreter.cpp:35
 
+#include "ASTHelpers.h"
+#include "clang/Sema/Lookup.h"

This seems to be pointing to the old filename.



Comment at: clang/lib/Interpreter/Interpreter.cpp:226
 return std::move(Err);
+  llvm::cantFail(Interp->ParseAndExecute(Runtimes));
+  // FIXME: This is a ugly hack. Undo command checks its availability by 
looking

We should avoid `cantFail` here and propagate the error as we do a few lines 
above.



Comment at: clang/lib/Interpreter/Value.cpp:1
+#include "clang/Interpreter/Value.h"
+#include "clang/AST/ASTContext.h"

We are missing the llvm preamble here as well.



Comment at: clang/lib/Parse/ParseStmt.cpp:551
+ConsumeAnyToken();
+setPrettyPrintMode();
+  } else {

I think the cleaner solution here is to remove the global flag and pass it 
`handleExprStmt` and extend `Sema::ActOnExprStmt`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

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


[PATCH] D147318: [clang-format] Don't format typename template parameters as expression

2023-03-31 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel created this revision.
rymiel added a project: clang-format.
rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay.
Herald added projects: All, clang.
Herald added a subscriber: cfe-commits.
rymiel requested review of this revision.

bb4f6c4dca98a47054117708015bb2724256ee83 
 made it 
so that template
parameter defaults are seen akin to assignments and formatted as
expressions, however, the patch did this for all template parameters,
even for `typename` template parameters.

This patch formats `typename` and `class` template parameters as types.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147318

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -261,6 +261,15 @@
   Tokens = annotate("template  struct S {};");
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionTypeLParen);
+  EXPECT_TOKEN(Tokens[7], tok::star, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1723,10 +1723,13 @@
   return false;
 }
 
-// This is the default value of a non-template type parameter, so treat
-// it as an expression.
-if (Contexts.back().ContextKind == tok::less)
-  return true;
+// This is the default value of a template parameter, determine if it's
+// type or non-type.
+if (Contexts.back().ContextKind == tok::less) {
+  assert(Current.Previous->Previous);
+  return !Current.Previous->Previous->isOneOf(tok::kw_typename,
+  tok::kw_class);
+}
 
 Tok = Tok->MatchingParen;
 if (!Tok)


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -261,6 +261,15 @@
   Tokens = annotate("template  struct S {};");
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionTypeLParen);
+  EXPECT_TOKEN(Tokens[7], tok::star, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1723,10 +1723,13 @@
   return false;
 }
 
-// This is the default value of a non-template type parameter, so treat
-// it as an expression.
-if (Contexts.back().ContextKind == tok::less)
-  return true;
+// This is the default value of a template parameter, determine if it's
+// type or non-type.
+if (Contexts.back().ContextKind == tok::less) {
+  assert(Current.Previous->Previous);
+  return !Current.Previous->Previous->isOneOf(tok::kw_typename,
+  tok::kw_class);
+}
 
 Tok = Tok->MatchingParen;
 if (!Tok)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41416: [modules] [pch] Do not deserialize all lazy template specializations when looking for one.

2023-03-31 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 509998.
v.g.vassilev added a comment.
Herald added a subscriber: mgrang.

Rebase.


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

https://reviews.llvm.org/D41416

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp

Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -177,11 +177,11 @@
   Record.AddSourceLocation(typeParams->getRAngleLoc());
 }
 
-/// Add to the record the first declaration from each module file that
-/// provides a declaration of D. The intent is to provide a sufficient
-/// set such that reloading this set will load all current redeclarations.
-void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
-  llvm::MapVector Firsts;
+/// Collect the first declaration from each module file that provides a
+/// declaration of D.
+void CollectFirstDeclFromEachModule(const Decl *D, bool IncludeLocal,
+llvm::MapVector &Firsts) {
+
   // FIXME: We can skip entries that we know are implied by others.
   for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
 if (R->isFromASTFile())
@@ -189,10 +189,49 @@
 else if (IncludeLocal)
   Firsts[nullptr] = R;
   }
+}
+
+/// Add to the record the first declaration from each module file that
+/// provides a declaration of D. The intent is to provide a sufficient
+/// set such that reloading this set will load all current redeclarations.
+void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
+  llvm::MapVector Firsts;
+  CollectFirstDeclFromEachModule(D, IncludeLocal, Firsts);
+
   for (const auto &F : Firsts)
 Record.AddDeclRef(F.second);
 }
 
+/// Add to the record the first template specialization from each module
+/// file that provides a declaration of D. We store the DeclId and an
+/// ODRHash of the template arguments of D which should provide enough
+/// information to load D only if the template instantiator needs it.
+void AddFirstSpecializationDeclFromEachModule(const Decl *D,
+  bool IncludeLocal) {
+  assert(isa(D) ||
+ isa(D) || isa(D) &&
+ "Must not be called with other decls");
+  llvm::MapVector Firsts;
+  CollectFirstDeclFromEachModule(D, IncludeLocal, Firsts);
+
+  for (const auto &F : Firsts) {
+Record.AddDeclRef(F.second);
+ArrayRef Args;
+if (auto *CTSD = dyn_cast(D))
+  Args = CTSD->getTemplateArgs().asArray();
+else if (auto *VTSD = dyn_cast(D))
+  Args = VTSD->getTemplateArgs().asArray();
+else if (auto *FD = dyn_cast(D))
+  Args = FD->getTemplateSpecializationArgs()->asArray();
+assert(Args.size());
+Record.push_back(TemplateArgumentList::ComputeODRHash(Args));
+bool IsPartialSpecialization
+  = isa(D) ||
+  isa(D);
+Record.push_back(IsPartialSpecialization);
+  }
+}
+
 /// Get the specialization decl from an entry in the specialization list.
 template 
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
@@ -205,7 +244,9 @@
 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
   return Common->PartialSpecializations;
 }
-ArrayRef getPartialSpecializations(FunctionTemplateDecl::Common *) {
+
+MutableArrayRef
+getPartialSpecializations(FunctionTemplateDecl::Common *) {
   return std::nullopt;
 }
 
@@ -222,9 +263,11 @@
 assert(!Common->LazySpecializations);
   }
 
-  ArrayRef LazySpecializations;
+  using LazySpecializationInfo
+= RedeclarableTemplateDecl::LazySpecializationInfo;
+  ArrayRef LazySpecializations;
   if (auto *LS = Common->LazySpecializations)
-LazySpecializations = llvm::ArrayRef(LS + 1, LS[0]);
+LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0].DeclID);
 
   // Add a slot to the record for the number of specializations.
   unsigned I = Record.size();
@@ -240,12 +283,20 @@
 
   for (auto *D : Specs) {
 assert(D->isCanonicalDecl() && "non-canonical decl in set");
-AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
+AddFirstSpecializationDeclFromEachModule(D, /*IncludeLocal*/true);
+  }
+  for (auto &SpecInfo : LazySpecializations) {
+Record.push_back(SpecInfo.DeclID);
+Record.push_back(SpecInfo.ODRHash);
+Record.push_back(SpecInfo.IsPartial);
   }
-  Record.app

[PATCH] D147319: [clang-repl] Consider the scope spec in template lookups for deduction guides

2023-03-31 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.
v.g.vassilev added reviewers: aaron.ballman, rsmith.
Herald added a project: All.
v.g.vassilev requested review of this revision.

`isDeductionGuideName` looks up the underlying template and if the template 
name is qualified we miss that qualification resulting in an error. This issue 
resurfaced in clang-repl where we call `isDeductionGuideName` more often to 
distinguish between if we had a statement or declaration.

This patch passes the `CXXScopeSpec` information down to `LookupTemplateName` 
to make the lookup more precise.


Repository:
  rC Clang

https://reviews.llvm.org/D147319

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/Interpreter/disambiguate-decl-stmt.cpp


Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===
--- clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -7,6 +7,10 @@
 
 // Decls which are hard to disambiguate
 
+// Templates
+namespace ns1 { template void tmplt(T &) {}}
+int arg_tmplt = 12; ns1::tmplt(arg_tmplt);
+
 // ParseStatementOrDeclaration returns multiple statements.
 #ifdef MS
 int g_bFlag = 1;
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -315,9 +315,8 @@
 }
 
 bool Sema::isDeductionGuideName(Scope *S, const IdentifierInfo &Name,
-SourceLocation NameLoc,
-ParsedTemplateTy *Template) {
-  CXXScopeSpec SS;
+SourceLocation NameLoc, CXXScopeSpec &SS,
+ParsedTemplateTy *Template/*=nullptr*/) {
   bool MemberOfUnknownSpecialization = false;
 
   // We could use redeclaration lookup here, but we don't need to: the
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -76,7 +76,7 @@
 IdentifierInfo *II = Tok.getIdentifierInfo();
 bool isDeductionGuide =
 Actions.isDeductionGuideName(getCurScope(), *II, Tok.getLocation(),
- /*Template=*/nullptr);
+ SS, /*Template=*/nullptr);
 if (Actions.isCurrentClassName(*II, getCurScope(), &SS) ||
 isDeductionGuide) {
   if (isConstructorDeclarator(/*Unqualified=*/SS.isEmpty(),
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2912,7 +2912,7 @@
   Result.setConstructorName(Ty, IdLoc, IdLoc);
 } else if (getLangOpts().CPlusPlus17 &&
AllowDeductionGuide && SS.isEmpty() &&
-   Actions.isDeductionGuideName(getCurScope(), *Id, IdLoc,
+   Actions.isDeductionGuideName(getCurScope(), *Id, IdLoc, SS,
 &TemplateName)) {
   // We have parsed a template-name naming a deduction guide.
   Result.setDeductionGuideName(TemplateName, IdLoc);
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3702,11 +3702,12 @@
 
   // Likewise, if this is a context where the identifier could be a 
template
   // name, check whether this is a deduction guide declaration.
+  CXXScopeSpec SS;
   if (getLangOpts().CPlusPlus17 &&
   (DSContext == DeclSpecContext::DSC_class ||
DSContext == DeclSpecContext::DSC_top_level) &&
   Actions.isDeductionGuideName(getCurScope(), *Tok.getIdentifierInfo(),
-   Tok.getLocation()) &&
+   Tok.getLocation(), SS) &&
   isConstructorDeclarator(/*Unqualified*/ true,
   /*DeductionGuide*/ true))
 goto DoneWithDeclSpec;
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -8074,7 +8074,7 @@
   /// Determine whether a particular identifier might be the name in a C++1z
   /// deduction-guide declaration.
   bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name,
-SourceLocation NameLoc,
+SourceLocation NameLoc, CXXScopeSpec &SS,
 ParsedTemplateTy *Template = nullptr);
 
   bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,


Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp

[clang] 8d7ded3 - Fix a simple think-o; NFC

2023-03-31 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-03-31T08:20:59-04:00
New Revision: 8d7ded37a693b9d6f9d4d887560a8e2f1ca05bd3

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

LOG: Fix a simple think-o; NFC

This was using a bitwise OR of two boolean member variables, now it's
using a logical OR instead.

Added: 


Modified: 
clang/include/clang/Lex/MacroInfo.h

Removed: 




diff  --git a/clang/include/clang/Lex/MacroInfo.h 
b/clang/include/clang/Lex/MacroInfo.h
index 75c9ca70dfbbf..00c1c3866bbd9 100644
--- a/clang/include/clang/Lex/MacroInfo.h
+++ b/clang/include/clang/Lex/MacroInfo.h
@@ -206,7 +206,7 @@ class MacroInfo {
   void setIsGNUVarargs() { IsGNUVarargs = true; }
   bool isC99Varargs() const { return IsC99Varargs; }
   bool isGNUVarargs() const { return IsGNUVarargs; }
-  bool isVariadic() const { return IsC99Varargs | IsGNUVarargs; }
+  bool isVariadic() const { return IsC99Varargs || IsGNUVarargs; }
 
   /// Return true if this macro requires processing before expansion.
   ///



___
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-03-31 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added inline comments.



Comment at: clang/docs/tools/dump_format_style.py:72
 
-  subtype, napplied = re.subn(r'^std::vector<(.*)>$', r'\1', typestr)
-  if napplied == 1:
-return 'List of ' + pluralize(to_yaml_type(subtype))
+  match = re.match(r'std::vector<(.*)>$', typestr)
+  if match:

jp4a50 wrote:
> I changed this from `subn` to `match` here since it's just a simpler way of 
> expressing the same thing.
(Just FYI, those pythons sources are pretty ancient and untouched, I planned on 
refactoring the whole thing using more modern, idiomatic Python but then 
concluded that it's not really necessary)


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] D146101: [clang-format] Add BracedInitializerIndentWidth option.

2023-03-31 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added inline comments.



Comment at: clang/include/clang/Format/Format.h:949
+  /// If unset, ``ContinuationIndentWidth`` is used.
+  /// \code
+  ///   AlignAfterOpenBracket: AlwaysBreak

MyDeveloperDay wrote:
> did you check generating the html from the rst? I can never remember if we 
> need a newline before the \code
Nope - how do I do that exactly? I would guess a newline is not needed based on 
other examples.


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


[clang] d29f706 - [clang][Interp] Fix binary comma operators

2023-03-31 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-31T14:54:51+02:00
New Revision: d29f70670db8ca43a49b6df9112035dc4b646182

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

LOG: [clang][Interp] Fix binary comma operators

We left the result of RHS on the stack in case DiscardResult was true.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/SemaCXX/constexpr-duffs-device.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index afa5372a5112c..1b605a9e09278 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -198,18 +198,6 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
-  // Deal with operations which have composite or void types.
-  switch (BO->getOpcode()) {
-  case BO_Comma:
-if (!discard(LHS))
-  return false;
-if (!this->visit(RHS))
-  return false;
-return true;
-  default:
-break;
-  }
-
   // Typecheck the args.
   std::optional LT = classify(LHS->getType());
   std::optional RT = classify(RHS->getType());
@@ -224,6 +212,13 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
 return DiscardResult ? this->emitPop(*T, BO) : true;
   };
 
+  // Deal with operations which have composite or void types.
+  if (BO->isCommaOp()) {
+if (!discard(LHS))
+  return false;
+return Discard(this->visit(RHS));
+  }
+
   // Pointer arithmetic special case.
   if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
 if (*T == PT_Ptr || (*LT == PT_Ptr && *RT == PT_Ptr))

diff  --git a/clang/test/SemaCXX/constexpr-duffs-device.cpp 
b/clang/test/SemaCXX/constexpr-duffs-device.cpp
index f77d989b9d36f..3c643cbb2af4b 100644
--- a/clang/test/SemaCXX/constexpr-duffs-device.cpp
+++ b/clang/test/SemaCXX/constexpr-duffs-device.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1y -verify %s
+// RUN: %clang_cc1 -std=c++1y -verify -fexperimental-new-constant-interpreter 
%s
 
 // expected-no-diagnostics
 constexpr void copy(const char *from, unsigned long count, char *to) {



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


[PATCH] D141784: [clang][Interp] Fix binary comma operators

2023-03-31 Thread Timm Bäder 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 rGd29f70670db8: [clang][Interp] Fix binary comma operators 
(authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141784

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/SemaCXX/constexpr-duffs-device.cpp


Index: clang/test/SemaCXX/constexpr-duffs-device.cpp
===
--- clang/test/SemaCXX/constexpr-duffs-device.cpp
+++ clang/test/SemaCXX/constexpr-duffs-device.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1y -verify %s
+// RUN: %clang_cc1 -std=c++1y -verify -fexperimental-new-constant-interpreter 
%s
 
 // expected-no-diagnostics
 constexpr void copy(const char *from, unsigned long count, char *to) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -198,18 +198,6 @@
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
-  // Deal with operations which have composite or void types.
-  switch (BO->getOpcode()) {
-  case BO_Comma:
-if (!discard(LHS))
-  return false;
-if (!this->visit(RHS))
-  return false;
-return true;
-  default:
-break;
-  }
-
   // Typecheck the args.
   std::optional LT = classify(LHS->getType());
   std::optional RT = classify(RHS->getType());
@@ -224,6 +212,13 @@
 return DiscardResult ? this->emitPop(*T, BO) : true;
   };
 
+  // Deal with operations which have composite or void types.
+  if (BO->isCommaOp()) {
+if (!discard(LHS))
+  return false;
+return Discard(this->visit(RHS));
+  }
+
   // Pointer arithmetic special case.
   if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
 if (*T == PT_Ptr || (*LT == PT_Ptr && *RT == PT_Ptr))


Index: clang/test/SemaCXX/constexpr-duffs-device.cpp
===
--- clang/test/SemaCXX/constexpr-duffs-device.cpp
+++ clang/test/SemaCXX/constexpr-duffs-device.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1y -verify %s
+// RUN: %clang_cc1 -std=c++1y -verify -fexperimental-new-constant-interpreter %s
 
 // expected-no-diagnostics
 constexpr void copy(const char *from, unsigned long count, char *to) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -198,18 +198,6 @@
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
-  // Deal with operations which have composite or void types.
-  switch (BO->getOpcode()) {
-  case BO_Comma:
-if (!discard(LHS))
-  return false;
-if (!this->visit(RHS))
-  return false;
-return true;
-  default:
-break;
-  }
-
   // Typecheck the args.
   std::optional LT = classify(LHS->getType());
   std::optional RT = classify(RHS->getType());
@@ -224,6 +212,13 @@
 return DiscardResult ? this->emitPop(*T, BO) : true;
   };
 
+  // Deal with operations which have composite or void types.
+  if (BO->isCommaOp()) {
+if (!discard(LHS))
+  return false;
+return Discard(this->visit(RHS));
+  }
+
   // Pointer arithmetic special case.
   if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
 if (*T == PT_Ptr || (*LT == PT_Ptr && *RT == PT_Ptr))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147321: [Flang][OMPIRBuilder] Add nounwind attribute to the LLVM IR

2023-03-31 Thread Dominik Adamski via Phabricator via cfe-commits
domada created this revision.
domada added reviewers: dpalermo, skatrak, TIFitis, RogerV-AMD, 
kiranchandramohan, agozillon, kiranktp, NimishMishra.
domada added projects: Flang, OpenMP.
Herald added subscribers: sunshaoce, Moerafaat, zero9178, bzcheeseman, 
awarzynski, sdasgup3, wenzhicui, wrengr, cota, teijeong, rdzhabarov, 
tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, 
mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini, jdoerfert, 
thopre, hiraditya.
Herald added a reviewer: ftynse.
Herald added a reviewer: dcaballe.
Herald added a project: All.
domada requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1, 
stephenneuendorffer, nicolasvasilache.
Herald added projects: clang, MLIR, LLVM.

Check if generated code can be marked as the code which does not throw an 
exception.

If LLVM IR does not throw an exception, add nounwind function attribute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147321

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/IR/IRBuilder.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/openmp-llvm.mlir

Index: mlir/test/Target/LLVMIR/openmp-llvm.mlir
===
--- mlir/test/Target/LLVMIR/openmp-llvm.mlir
+++ mlir/test/Target/LLVMIR/openmp-llvm.mlir
@@ -2464,7 +2464,7 @@
   }
 }
 
-// CHECK: attributes #0 = { "target-cpu"="gfx908"
+// CHECK: attributes #0 = { nounwind "target-cpu"="gfx908"
 // CHECK-SAME: "target-features"="+dot3-insts,+dot4-insts,+s-memtime-inst,
 // CHECK-SAME: +16-bit-insts,+s-memrealtime,+dot6-insts,+dl-insts,
 // CHECK-SAME: +wavefrontsize64,+gfx9-insts,+gfx8-insts,+ci-insts,+dot10-insts,
@@ -2484,7 +2484,7 @@
   llvm.return
   }
 }
-// CHECK: attributes #0 = { "target-cpu"="gfx908"
+// CHECK: attributes #0 = {  nounwind "target-cpu"="gfx908"
 // CHECK-SAME: "target-features"="+dot3-insts,+dot4-insts,+s-memtime-inst,
 // CHECK-SAME: +16-bit-insts,+s-memrealtime,+dot6-insts,+dl-insts,
 // CHECK-SAME: +wavefrontsize64,+gfx9-insts,+gfx8-insts,+ci-insts,+dot10-insts,
Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -1582,6 +1582,9 @@
 Operation *op, NamedAttribute attribute,
 LLVM::ModuleTranslation &moduleTranslation) const {
 
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  ompBuilder->tryMarkNoThrowModuleFunctions();
+
   return llvm::TypeSwitch(attribute.getValue())
   .Case([&](omp::TargetAttr targetAttr) {
 return setLLVMFunctionTargetAttr(op, targetAttr, moduleTranslation);
Index: llvm/lib/IR/IRBuilder.cpp
===
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -1410,6 +1410,20 @@
   return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
 }
 
+void IRBuilderBase::TryMarkNoThrow(llvm::Function *F) {
+  // LLVM treats 'nounwind' on a function as part of the type, so we
+  // can't do this on functions that can be overwritten.
+  if (F->isInterposable())
+return;
+
+  for (llvm::BasicBlock &BB : *F)
+for (llvm::Instruction &I : BB)
+  if (I.mayThrow())
+return;
+
+  F->setDoesNotThrow();
+}
+
 IRBuilderDefaultInserter::~IRBuilderDefaultInserter() = default;
 IRBuilderCallbackInserter::~IRBuilderCallbackInserter() = default;
 IRBuilderFolder::~IRBuilderFolder() = default;
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -5052,6 +5052,16 @@
   }
 }
 
+void OpenMPIRBuilder::tryMarkNoThrowModuleFunctions() {
+  for (Function &f : M.functions()) {
+if (f.isDeclaration())
+  continue;
+if (f.hasFnAttribute(Attribute::NoUnwind))
+  continue;
+IRBuilderBase::TryMarkNoThrow(&f);
+  }
+}
+
 void TargetRegionEntryInfo::getTargetRegionEntryFnName(
 SmallVectorImpl &Name, StringRef ParentName, unsigned DeviceID,
 unsigned FileID, unsigned Line, unsigned Count) {
Index: llvm/include/llvm/IR/IRBuilder.h
===
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -2543,6 +2543,11 @@
   CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
   Value *Alignment,
   Value *Off

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-03-31 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Thanks for working on this!

The `-ffile-reproducible` flag name refers to making `#file` directives 
reproducible, but `LangOptions.UseTargetPathSeparator` sounds a lot broader :) 
I don't know what others think, but it would be nice to not have to introduce 
any more flags at least.




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:544
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);

Do we want to fix absolute filenames too?
I can see arguments for and against:
- Using what the user provided makes sense
- Some build systems might use absolute paths for everything. But on the other 
hand such builds have larger determinism problems (including the full paths).
So the current decision probably makes sense.



Comment at: clang/test/CodeGen/debug-info-slash.c:5
+
+// WIN:   !DIFile(filename: "{{.*}}clang/test/CodeGen\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}clang/test/CodeGen/debug-info-slash.c"

Does the test runner write the 'clang/test/CodeGen' path with forward slashes 
also on Windows?



Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:787
 
   StringRef PathRef(Asm->TM.Options.ObjectFilenameForDebug);
   llvm::SmallString<256> PathStore(PathRef);

This handles codeview. Does anything need to be done for dwarf on windows? 
mstorsjo might have input on that.



Comment at: llvm/test/DebugInfo/COFF/build-info.ll:13
 
+; Test path is canalized to windows backslash style when output object file 
name
+; is not starting with '/'.

s/canalized/canonicalized/



Comment at: llvm/test/DebugInfo/COFF/build-info.ll:18
+; RUN: cd %t-dir
+; RUN: llc -filetype=obj -mtriple i686-pc-windows-msvc %s -o ../build-info.o
+; RUN: llvm-readobj --codeview ../build-info.o | FileCheck %s 
--check-prefix=OBJ

Does this write the .o file into the test directory? I don't think that's 
allowed (it may be read-only). But the test could create another subdirectory 
under `%t-dir`.



Comment at: llvm/test/DebugInfo/COFF/build-info.ll:21
+
+; OBJ: ObjectName: ..\build-info.o
+

But in the `llc` invocation, the user wrote a relative path with a forward 
slash. What behavior do we want? What should happen if there are more then one 
slash - I think remove_dots just works on the first one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

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


[PATCH] D144522: [clang-tidy] Add readability-operators-representation check

2023-03-31 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for the check! Please fix the missing space comment before landing.




Comment at: 
clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.h:17
+
+/// Enforcesconsistent token representation for invoked binary, unary
+/// and overloaded operators in C++ code.

Missing space


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144522

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


[PATCH] D145264: [OpenMP][MLIR][Flang][Driver][bbc] Lower and apply Module FlagsAttr

2023-03-31 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

In D145264#4236173 , 
@kiranchandramohan wrote:

> Please split this patch into three:
>
> 1. Code changes and testing for the driver and the FIR+OpenMP dialect 
> generated.
> 2. Code changes and test for FIR+OpenMP to LLVM+OpenMP dialect.
> 3. Code changes and testing for the translation from LLVM + OpenMP dialect to 
> LLVM IR. Code in OpenMPToLLVMIRTranslation.cpp should be tested with 
> `mlir-translate`.

More than happy to do all of the above, however, there is no code for step 2 in 
this case as it undergoes no rewriting or transformation when going from 
FIR+OpenMP -> LLVM+OpenMP. However, I am happy to make a test to assure it is 
retained during the conversion, but I believe it would just be a test in the 
patch, would it be okay to merge patch 2 and 3 from your comment? Meaning there 
would be two patches, the driver additions and the attribute generation from 
the flags. And then the lowering of the attribute to LLVM-IR (with additional 
mlir-translate tests for LLVM+OpenMP -> LLVM-IR and FIR+OpenMP -> LLVM+OpenMP).

> In D145264#4233358 , @agozillon 
> wrote:
>
>> Unfortunately I do not believe an mlir-translate test that tests if the 
>> OffloadModuleInterface is accessible when directly utilizing mlir-translate 
>> is possible for this patch... I forgot I removed the is device check as it 
>> is already done at the initial creation of the attribute. However, I do have 
>> a future patch that it will be utilised in and when @jsjodin's initial 
>> TargetOp work is in I can likely create a test around that functionality.
>
> You may delay the translation code till then.

Thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

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


[clang] d472c55 - [clang][Interp] Fix double-printing InterpFrame::describe()

2023-03-31 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-31T15:25:30+02:00
New Revision: d472c55fa28a249e1845908b47a1be6f2e05a1cd

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

LOG: [clang][Interp] Fix double-printing InterpFrame::describe()

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

Added: 


Modified: 
clang/lib/AST/Interp/InterpFrame.cpp
clang/test/AST/Interp/constexpr-nqueens.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 584cf1a9a69e6..897d420e91a3a 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -126,6 +126,9 @@ void print(llvm::raw_ostream &OS, const Pointer &P, 
ASTContext &Ctx,
 F = F.isArrayElement() ? F.getArray().expand() : F.getBase();
   }
 
+  // Drop the first pointer since we print it unconditionally anyway.
+  Levels.erase(Levels.begin());
+
   printDesc(P.getDeclDesc());
   for (const auto &It : Levels) {
 if (It.inArray()) {

diff  --git a/clang/test/AST/Interp/constexpr-nqueens.cpp 
b/clang/test/AST/Interp/constexpr-nqueens.cpp
index ffe8553a944b0..5aeb7afcd79ce 100644
--- a/clang/test/AST/Interp/constexpr-nqueens.cpp
+++ b/clang/test/AST/Interp/constexpr-nqueens.cpp
@@ -6,9 +6,6 @@
 /// Board constructors.
 /// This tests that InterpFrame::describe().
 
-// FIXME: With the new interpreter, most of the described frames are
-//  currently broken in one way or another.
-
 typedef unsigned long uint64_t;
 
 struct Board {



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


[PATCH] D141831: [clang][Interp] Fix double-printing in InterpFrame::describe()

2023-03-31 Thread Timm Bäder 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 rGd472c55fa28a: [clang][Interp] Fix double-printing 
InterpFrame::describe() (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D141831?vs=489469&id=510010#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141831

Files:
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/test/AST/Interp/constexpr-nqueens.cpp


Index: clang/test/AST/Interp/constexpr-nqueens.cpp
===
--- clang/test/AST/Interp/constexpr-nqueens.cpp
+++ clang/test/AST/Interp/constexpr-nqueens.cpp
@@ -6,9 +6,6 @@
 /// Board constructors.
 /// This tests that InterpFrame::describe().
 
-// FIXME: With the new interpreter, most of the described frames are
-//  currently broken in one way or another.
-
 typedef unsigned long uint64_t;
 
 struct Board {
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -126,6 +126,9 @@
 F = F.isArrayElement() ? F.getArray().expand() : F.getBase();
   }
 
+  // Drop the first pointer since we print it unconditionally anyway.
+  Levels.erase(Levels.begin());
+
   printDesc(P.getDeclDesc());
   for (const auto &It : Levels) {
 if (It.inArray()) {


Index: clang/test/AST/Interp/constexpr-nqueens.cpp
===
--- clang/test/AST/Interp/constexpr-nqueens.cpp
+++ clang/test/AST/Interp/constexpr-nqueens.cpp
@@ -6,9 +6,6 @@
 /// Board constructors.
 /// This tests that InterpFrame::describe().
 
-// FIXME: With the new interpreter, most of the described frames are
-//  currently broken in one way or another.
-
 typedef unsigned long uint64_t;
 
 struct Board {
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -126,6 +126,9 @@
 F = F.isArrayElement() ? F.getArray().expand() : F.getBase();
   }
 
+  // Drop the first pointer since we print it unconditionally anyway.
+  Levels.erase(Levels.begin());
+
   printDesc(P.getDeclDesc());
   for (const auto &It : Levels) {
 if (It.inArray()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143467: [PowerPC] Add target feature requirement to builtins

2023-03-31 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added subscribers: maryammo, kamaub, stefanp.
nemanjai added a comment.
This revision is now accepted and ready to land.

This looks fine to me. I'd like some of the devs that have added builtins with 
Sema checking in the past to have a look here as well. @amyk @maryammo @kamaub 
@stefanp Can you have a look at this as well please?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143467

___
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-03-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 510014.
junaire added a comment.

Address more comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.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,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,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"
@@ -314,4 +318,38 @@
   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_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_EQ(V2.getAs(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.castAs(), 3);
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 42);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 43);
+  EXPECT_TRUE(V4.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/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for incremental
   // processing
-  if (PP.isIncrementalPro

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

2023-03-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire marked 9 inline comments as done.
junaire added inline comments.



Comment at: clang/include/clang/Interpreter/Interpreter.h:119
+
+  std::unique_ptr GenModule();
+

v.g.vassilev wrote:
> We should not need this interface.
`Interpreter::CompileDecl` needs it. So we don't have to do a dummy 
`Interp.Parse("")` to get a llvm::Module.



Comment at: clang/lib/Parse/ParseStmt.cpp:551
+ConsumeAnyToken();
+setPrettyPrintMode();
+  } else {

v.g.vassilev wrote:
> I think the cleaner solution here is to remove the global flag and pass it 
> `handleExprStmt` and extend `Sema::ActOnExprStmt`.
I dont understand, can you elaborate a bit?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

___
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-03-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 510017.
junaire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.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,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,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"
@@ -314,4 +318,38 @@
   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_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_EQ(V2.getAs(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.castAs(), 3);
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 42);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 43);
+  EXPECT_TRUE(V4.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/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for incremental
   // processing
-  if (PP.isIncrementalProcessingEnabled(

[clang] 8d2899a - [clang][Interp] Handle TypeTraitExprs

2023-03-31 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-31T15:54:44+02:00
New Revision: 8d2899acbcf1b8ce120bc219aeb30207d4422042

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

LOG: [clang][Interp] Handle TypeTraitExprs

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 1b605a9e0927..733247787d76 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -897,6 +897,11 @@ bool ByteCodeExprGen::VisitCompoundLiteralExpr(
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitTypeTraitExpr(const TypeTraitExpr *E) {
+  return this->emitConstBool(E->getValue(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 03d2eb87b5e1..4baf5d433c9e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -92,6 +92,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
+  bool VisitTypeTraitExpr(const TypeTraitExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index fc36c13ed07b..5883c1879b92 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -743,3 +743,26 @@ namespace CompoundLiterals {
   static_assert(get3() == 3, "");
 #endif
 };
+
+namespace TypeTraits {
+  static_assert(__is_trivial(int), "");
+  static_assert(__is_trivial(float), "");
+  static_assert(__is_trivial(E), "");
+  struct S{};
+  static_assert(__is_trivial(S), "");
+  struct S2 {
+S2() {}
+  };
+  static_assert(!__is_trivial(S2), "");
+
+  template 
+  struct S3 {
+constexpr bool foo() const { return __is_trivial(T); }
+  };
+  struct T {
+~T() {}
+  };
+  struct U {};
+  static_assert(S3{}.foo(), "");
+  static_assert(!S3{}.foo(), "");
+}



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


[PATCH] D142448: [clang][Interp] Handle TypeTraitExprs

2023-03-31 Thread Timm Bäder 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 rG8d2899acbcf1: [clang][Interp] Handle TypeTraitExprs 
(authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142448

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


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -743,3 +743,26 @@
   static_assert(get3() == 3, "");
 #endif
 };
+
+namespace TypeTraits {
+  static_assert(__is_trivial(int), "");
+  static_assert(__is_trivial(float), "");
+  static_assert(__is_trivial(E), "");
+  struct S{};
+  static_assert(__is_trivial(S), "");
+  struct S2 {
+S2() {}
+  };
+  static_assert(!__is_trivial(S2), "");
+
+  template 
+  struct S3 {
+constexpr bool foo() const { return __is_trivial(T); }
+  };
+  struct T {
+~T() {}
+  };
+  struct U {};
+  static_assert(S3{}.foo(), "");
+  static_assert(!S3{}.foo(), "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -92,6 +92,7 @@
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
+  bool VisitTypeTraitExpr(const TypeTraitExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -897,6 +897,11 @@
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitTypeTraitExpr(const TypeTraitExpr *E) {
+  return this->emitConstBool(E->getValue(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -743,3 +743,26 @@
   static_assert(get3() == 3, "");
 #endif
 };
+
+namespace TypeTraits {
+  static_assert(__is_trivial(int), "");
+  static_assert(__is_trivial(float), "");
+  static_assert(__is_trivial(E), "");
+  struct S{};
+  static_assert(__is_trivial(S), "");
+  struct S2 {
+S2() {}
+  };
+  static_assert(!__is_trivial(S2), "");
+
+  template 
+  struct S3 {
+constexpr bool foo() const { return __is_trivial(T); }
+  };
+  struct T {
+~T() {}
+  };
+  struct U {};
+  static_assert(S3{}.foo(), "");
+  static_assert(!S3{}.foo(), "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -92,6 +92,7 @@
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
+  bool VisitTypeTraitExpr(const TypeTraitExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -897,6 +897,11 @@
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitTypeTraitExpr(const TypeTraitExpr *E) {
+  return this->emitConstBool(E->getValue(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) {
   if (E->containsErrors())
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144522: [clang-tidy] Add readability-operators-representation check

2023-03-31 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

@carlosgalvezp
Thank you, by any chance would you be able to look into other reviews ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144522

___
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-03-31 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 updated this revision to Diff 510022.
jp4a50 added a comment.

Alphabetical ordering.


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] D147324: [OpenMP][MLIR][Flang][bbc][Driver] Add OpenMP RTL Flags to Flang and generate omp.FlagsAttr from them

2023-03-31 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon created this revision.
Herald added subscribers: sunshaoce, bzcheeseman, rriddle, guansong, yaxunl.
Herald added a reviewer: sscalpone.
Herald added a reviewer: awarzynski.
Herald added a reviewer: kiranchandramohan.
Herald added projects: Flang, All.
agozillon requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1, stephenneuendorffer, 
jdoerfert, MaskRay.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

This patch ports OpenMP RTL flags from the shared Clang compiler
options to Flang. As well as adding a limited subset to bbc.

This patch enables the flags below (and any equals or inverse variants)
for Flang that exist in Clang:

-fopenmp-target-debug
-fopenmp-assume-threads-oversubscription
-fopenmp-assume-teams-oversubscription
-fopenmp-assume-no-nested-parallelism
-fopenmp-assume-no-thread-state

For the bbc tool it only utilises the primary variants to minimize
additional complexity in the tool.

The patch also provides FlagAttr generation from these flags. Which
will be lowered to LLVM-IR in a subsequent patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147324

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/LangOptions.def
  flang/include/flang/Tools/CrossToolHelpers.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/omp-frontend-forwarding.f90
  flang/test/Lower/OpenMP/rtl-flags.f90
  flang/tools/bbc/bbc.cpp

Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -129,6 +129,38 @@
llvm::cl::desc("enable openmp device compilation"),
llvm::cl::init(false));
 
+// A simplified subset of the OpenMP RTL Flags from Flang, only the primary
+// positive options are available, no negative options e.g. fopen_assume* vs
+// fno_open_assume*
+static llvm::cl::opt setOpenMPTargetDebug(
+"fopenmp-target-debug",
+llvm::cl::desc("Enable debugging in the OpenMP offloading device RTL"),
+llvm::cl::init(0));
+
+static llvm::cl::opt setOpenMPThreadSubscription(
+"fopenmp-assume-threads-oversubscription",
+llvm::cl::desc("Assume work-shared loops do not have more "
+   "iterations than participating threads."),
+llvm::cl::init(false));
+
+static llvm::cl::opt setOpenMPTeamSubscription(
+"fopenmp-assume-teams-oversubscription",
+llvm::cl::desc("Assume distributed loops do not have more iterations than "
+   "participating teams."),
+llvm::cl::init(false));
+
+static llvm::cl::opt setOpenMPNoThreadState(
+"fopenmp-assume-no-thread-state",
+llvm::cl::desc(
+"Assume that no thread in a parallel region will modify an ICV."),
+llvm::cl::init(false));
+
+static llvm::cl::opt setOpenMPNoNestedParallelism(
+"fopenmp-assume-no-nested-parallelism",
+llvm::cl::desc("Assume that no thread in a parallel region will encounter "
+   "a parallel region."),
+llvm::cl::init(false));
+
 static llvm::cl::opt enableOpenACC("fopenacc",
  llvm::cl::desc("enable openacc"),
  llvm::cl::init(false));
@@ -244,8 +276,13 @@
   kindMap, loweringOptions, {});
   burnside.lower(parseTree, semanticsContext);
   mlir::ModuleOp mlirModule = burnside.getModule();
-  if (enableOpenMP)
-setOffloadModuleInterfaceAttributes(mlirModule, enableOpenMPDevice);
+  if (enableOpenMP) {
+auto offloadModuleOpts =
+OffloadModuleOpts(setOpenMPTargetDebug, setOpenMPTeamSubscription,
+  setOpenMPThreadSubscription, setOpenMPNoThreadState,
+  setOpenMPNoNestedParallelism, enableOpenMPDevice);
+setOffloadModuleInterfaceAttributes(mlirModule, offloadModuleOpts);
+  }
   std::error_code ec;
   std::string outputName = outputFilename;
   if (!outputName.size())
Index: flang/test/Lower/OpenMP/rtl-flags.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/rtl-flags.f90
@@ -0,0 +1,29 @@
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DEFAULT-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefix=DEFAULT-HOST-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-target-debug -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DBG-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-target-debug=111 -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DBG-EQ-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-teams-oversubscription -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=TEAMS-OSUB-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-thread

[PATCH] D147324: [OpenMP][MLIR][Flang][bbc][Driver] Add OpenMP RTL Flags to Flang and generate omp.FlagsAttr from them

2023-03-31 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

The flag addition and FlagsAttr generation component of: 
https://reviews.llvm.org/D145264 the LLVM-IR generation will come in a 
subsequent phabricator patch once I have created some additional tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147324

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


[clang] 943ef06 - [clang][Interp] Check This pointer without creating InterpFrame

2023-03-31 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-31T16:18:15+02:00
New Revision: 943ef06420105cad23e3caea24d6a274cdb0316f

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

LOG: [clang][Interp] Check This pointer without creating InterpFrame

The InterpFrame was only created so early so we could use getThis().
However, we need to know the Function when creating the InterpFrame and
in the case of virtual functions, we need to determine what function to
call at interpretation time.

Get the This pointer ourselves and just create the InterpFrame later.

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

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpStack.cpp
clang/lib/AST/Interp/InterpStack.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index bb34737e018b..afc5f24baf73 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1492,10 +1492,11 @@ inline bool CheckGlobalCtor(InterpState &S, CodePtr 
&PC) {
 }
 
 inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
-  auto NewFrame = std::make_unique(S, Func, PC);
-  Pointer ThisPtr;
   if (Func->hasThisPointer()) {
-ThisPtr = NewFrame->getThis();
+size_t ThisOffset =
+Func->getArgSize() + (Func->hasRVO() ? primSize(PT_Ptr) : 0);
+const Pointer &ThisPtr = S.Stk.peek(ThisOffset);
+
 if (!CheckInvoke(S, PC, ThisPtr))
   return false;
 
@@ -1506,6 +1507,7 @@ inline bool Call(InterpState &S, CodePtr &PC, const 
Function *Func) {
   if (!CheckCallable(S, PC, Func))
 return false;
 
+  auto NewFrame = std::make_unique(S, Func, PC);
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 

diff  --git a/clang/lib/AST/Interp/InterpStack.cpp 
b/clang/lib/AST/Interp/InterpStack.cpp
index 7fe678e62192..63a088be6705 100644
--- a/clang/lib/AST/Interp/InterpStack.cpp
+++ b/clang/lib/AST/Interp/InterpStack.cpp
@@ -46,7 +46,7 @@ void *InterpStack::grow(size_t Size) {
   return Object;
 }
 
-void *InterpStack::peek(size_t Size) const {
+void *InterpStack::peekData(size_t Size) const {
   assert(Chunk && "Stack is empty!");
 
   StackChunk *Ptr = Chunk;

diff  --git a/clang/lib/AST/Interp/InterpStack.h 
b/clang/lib/AST/Interp/InterpStack.h
index e625ffd8e421..435120d0e441 100644
--- a/clang/lib/AST/Interp/InterpStack.h
+++ b/clang/lib/AST/Interp/InterpStack.h
@@ -64,11 +64,16 @@ class InterpStack final {
 
   /// Returns a reference to the value on the top of the stack.
   template  T &peek() const {
-return *reinterpret_cast(peek(aligned_size()));
+return *reinterpret_cast(peekData(aligned_size()));
+  }
+
+  template  T &peek(size_t Offset) const {
+assert(aligned(Offset));
+return *reinterpret_cast(peekData(Offset));
   }
 
   /// Returns a pointer to the top object.
-  void *top() const { return Chunk ? peek(0) : nullptr; }
+  void *top() const { return Chunk ? peekData(0) : nullptr; }
 
   /// Returns the size of the stack in bytes.
   size_t size() const { return StackSize; }
@@ -90,7 +95,7 @@ class InterpStack final {
   /// Grows the stack to accommodate a value and returns a pointer to it.
   void *grow(size_t Size);
   /// Returns a pointer from the top of the stack.
-  void *peek(size_t Size) const;
+  void *peekData(size_t Size) const;
   /// Shrinks the stack.
   void shrink(size_t Size);
 



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


[PATCH] D142617: [clang][Interp] Check This pointer without creating InterpFrame

2023-03-31 Thread Timm Bäder 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 rG943ef0642010: [clang][Interp] Check This pointer without 
creating InterpFrame (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142617

Files:
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.cpp
  clang/lib/AST/Interp/InterpStack.h


Index: clang/lib/AST/Interp/InterpStack.h
===
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -64,11 +64,16 @@
 
   /// Returns a reference to the value on the top of the stack.
   template  T &peek() const {
-return *reinterpret_cast(peek(aligned_size()));
+return *reinterpret_cast(peekData(aligned_size()));
+  }
+
+  template  T &peek(size_t Offset) const {
+assert(aligned(Offset));
+return *reinterpret_cast(peekData(Offset));
   }
 
   /// Returns a pointer to the top object.
-  void *top() const { return Chunk ? peek(0) : nullptr; }
+  void *top() const { return Chunk ? peekData(0) : nullptr; }
 
   /// Returns the size of the stack in bytes.
   size_t size() const { return StackSize; }
@@ -90,7 +95,7 @@
   /// Grows the stack to accommodate a value and returns a pointer to it.
   void *grow(size_t Size);
   /// Returns a pointer from the top of the stack.
-  void *peek(size_t Size) const;
+  void *peekData(size_t Size) const;
   /// Shrinks the stack.
   void shrink(size_t Size);
 
Index: clang/lib/AST/Interp/InterpStack.cpp
===
--- clang/lib/AST/Interp/InterpStack.cpp
+++ clang/lib/AST/Interp/InterpStack.cpp
@@ -46,7 +46,7 @@
   return Object;
 }
 
-void *InterpStack::peek(size_t Size) const {
+void *InterpStack::peekData(size_t Size) const {
   assert(Chunk && "Stack is empty!");
 
   StackChunk *Ptr = Chunk;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1492,10 +1492,11 @@
 }
 
 inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
-  auto NewFrame = std::make_unique(S, Func, PC);
-  Pointer ThisPtr;
   if (Func->hasThisPointer()) {
-ThisPtr = NewFrame->getThis();
+size_t ThisOffset =
+Func->getArgSize() + (Func->hasRVO() ? primSize(PT_Ptr) : 0);
+const Pointer &ThisPtr = S.Stk.peek(ThisOffset);
+
 if (!CheckInvoke(S, PC, ThisPtr))
   return false;
 
@@ -1506,6 +1507,7 @@
   if (!CheckCallable(S, PC, Func))
 return false;
 
+  auto NewFrame = std::make_unique(S, Func, PC);
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 


Index: clang/lib/AST/Interp/InterpStack.h
===
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -64,11 +64,16 @@
 
   /// Returns a reference to the value on the top of the stack.
   template  T &peek() const {
-return *reinterpret_cast(peek(aligned_size()));
+return *reinterpret_cast(peekData(aligned_size()));
+  }
+
+  template  T &peek(size_t Offset) const {
+assert(aligned(Offset));
+return *reinterpret_cast(peekData(Offset));
   }
 
   /// Returns a pointer to the top object.
-  void *top() const { return Chunk ? peek(0) : nullptr; }
+  void *top() const { return Chunk ? peekData(0) : nullptr; }
 
   /// Returns the size of the stack in bytes.
   size_t size() const { return StackSize; }
@@ -90,7 +95,7 @@
   /// Grows the stack to accommodate a value and returns a pointer to it.
   void *grow(size_t Size);
   /// Returns a pointer from the top of the stack.
-  void *peek(size_t Size) const;
+  void *peekData(size_t Size) const;
   /// Shrinks the stack.
   void shrink(size_t Size);
 
Index: clang/lib/AST/Interp/InterpStack.cpp
===
--- clang/lib/AST/Interp/InterpStack.cpp
+++ clang/lib/AST/Interp/InterpStack.cpp
@@ -46,7 +46,7 @@
   return Object;
 }
 
-void *InterpStack::peek(size_t Size) const {
+void *InterpStack::peekData(size_t Size) const {
   assert(Chunk && "Stack is empty!");
 
   StackChunk *Ptr = Chunk;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1492,10 +1492,11 @@
 }
 
 inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
-  auto NewFrame = std::make_unique(S, Func, PC);
-  Pointer ThisPtr;
   if (Func->hasThisPointer()) {
-ThisPtr = NewFrame->getThis();
+size_t ThisOffset =
+Func->getArgSize() + (Func->hasRVO() ? primSize(PT_Ptr) : 0);
+const Pointer &ThisPtr = S.Stk.peek(ThisOffset);
+
 if (!CheckInvoke(S, PC, ThisPtr))
   return false;
 
@@ 

[PATCH] D147325: Implement cross reference request for #include lines.

2023-03-31 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147325

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -43,6 +43,10 @@
 using ::testing::UnorderedElementsAreArray;
 using ::testing::UnorderedPointwise;
 
+std::string guard(llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 MATCHER_P2(FileRange, File, Range, "") {
   return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
 }
@@ -2293,6 +2297,51 @@
 checkFindRefs(Test);
 }
 
+TEST(FindReferences, UsedSymbolsFromInclude) {
+  const char *Tests[] = {
+  R"cpp([[#include ^"bar.h"]]
+#include 
+int fstBar = [[bar1]]();
+int sndBar = [[bar2]]();
+[[Bar]] bar;
+int macroBar = [[BAR]];
+std::vector vec;
+  )cpp",
+
+  R"cpp([[#in^clude ]]
+std::[[vector]] vec;
+  )cpp"};
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto TU = TestTU::withCode(T.code());
+TU.ExtraArgs.push_back("-std=c++20");
+TU.AdditionalFiles["bar.h"] = guard(R"cpp(
+  #define BAR 5
+  int bar1();
+  int bar2();
+  class Bar {};
+)cpp");
+TU.AdditionalFiles["system/vector"] = guard(R"cpp(
+  namespace std {
+template
+class vector{};
+  }
+)cpp");
+TU.ExtraArgs.push_back("-isystem" + testPath("system"));
+
+auto AST = TU.build();
+std::vector> ExpectedLocations;
+for (const auto &R : T.ranges())
+  ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
+for (const auto &P : T.points()) {
+  EXPECT_THAT(findReferences(AST, P, 0).References,
+  UnorderedElementsAreArray(ExpectedLocations))
+  << "Failed for Refs at " << P << "\n"
+  << Test;
+}
+  }
+}
+
 TEST(FindReferences, NeedsIndexForSymbols) {
   const char *Header = "int foo();";
   Annotations Main("int main() { [[f^oo]](); }");
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -10,12 +10,15 @@
 #include "FindSymbols.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -48,6 +51,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,6 +65,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1312,6 +1317,63 @@
 }
 } // namespace
 
+ReferencesResult maybeFindIncludeReferences(ParsedAST &AST, Position Pos,
+URIForFile URIMainFile) {
+  ReferencesResult Results;
+  const SourceManager &SM = AST.getSourceManager();
+  auto Includes = AST.getIncludeStructure().MainFileIncludes;
+  auto ConvertedMainFileIncludes = convertIncludes(SM, Includes);
+  for (auto &Inc : Includes) {
+if (Inc.HashLine != Pos.line)
+  continue;
+
+auto ReferencedInclude = convertIncludes(SM, Inc);
+include_cleaner::walkUsed(
+AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
+AST.getPragmaIncludes(), SM,
+[&](const include_cleaner::SymbolReference &Ref,
+llvm::ArrayRef Providers) {
+  if (Ref.RT != include_cleaner::RefType::Explicit)
+return;
+
+  auto Provider =
+  firstSatisfiedProvider(ConvertedMainFileIncludes, Providers);
+  if (!Provider)
+return;
+
+  // Check if the referenced include matches this provider.
+  if (ReferencedInclude.match(*Provider).empty())
+return;
+
+  auto Loc = SM.getFileLoc(Ref.RefLocation);
+  // File locations can be outside of the main file if macro is
+  // expanded through an #include.
+  while (SM.getFileID(Loc) != SM.getMainFil

[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-03-31 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 510027.
VitaNuo marked 10 inline comments as done.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -43,6 +43,10 @@
 using ::testing::UnorderedElementsAreArray;
 using ::testing::UnorderedPointwise;
 
+std::string guard(llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 MATCHER_P2(FileRange, File, Range, "") {
   return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
 }
@@ -2293,6 +2297,51 @@
 checkFindRefs(Test);
 }
 
+TEST(FindReferences, UsedSymbolsFromInclude) {
+  const char *Tests[] = {
+  R"cpp([[#include ^"bar.h"]]
+#include 
+int fstBar = [[bar1]]();
+int sndBar = [[bar2]]();
+[[Bar]] bar;
+int macroBar = [[BAR]];
+std::vector vec;
+  )cpp",
+
+  R"cpp([[#in^clude ]]
+std::[[vector]] vec;
+  )cpp"};
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto TU = TestTU::withCode(T.code());
+TU.ExtraArgs.push_back("-std=c++20");
+TU.AdditionalFiles["bar.h"] = guard(R"cpp(
+  #define BAR 5
+  int bar1();
+  int bar2();
+  class Bar {};
+)cpp");
+TU.AdditionalFiles["system/vector"] = guard(R"cpp(
+  namespace std {
+template
+class vector{};
+  }
+)cpp");
+TU.ExtraArgs.push_back("-isystem" + testPath("system"));
+
+auto AST = TU.build();
+std::vector> ExpectedLocations;
+for (const auto &R : T.ranges())
+  ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
+for (const auto &P : T.points()) {
+  EXPECT_THAT(findReferences(AST, P, 0).References,
+  UnorderedElementsAreArray(ExpectedLocations))
+  << "Failed for Refs at " << P << "\n"
+  << Test;
+}
+  }
+}
+
 TEST(FindReferences, NeedsIndexForSymbols) {
   const char *Header = "int foo();";
   Annotations Main("int main() { [[f^oo]](); }");
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -10,12 +10,15 @@
 #include "FindSymbols.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -48,6 +51,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,6 +65,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1312,6 +1317,63 @@
 }
 } // namespace
 
+ReferencesResult maybeFindIncludeReferences(ParsedAST &AST, Position Pos,
+URIForFile URIMainFile) {
+  ReferencesResult Results;
+  const SourceManager &SM = AST.getSourceManager();
+  auto Includes = AST.getIncludeStructure().MainFileIncludes;
+  auto ConvertedMainFileIncludes = convertIncludes(SM, Includes);
+  for (auto &Inc : Includes) {
+if (Inc.HashLine != Pos.line)
+  continue;
+
+auto ReferencedInclude = convertIncludes(SM, Inc);
+include_cleaner::walkUsed(
+AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
+AST.getPragmaIncludes(), SM,
+[&](const include_cleaner::SymbolReference &Ref,
+llvm::ArrayRef Providers) {
+  if (Ref.RT != include_cleaner::RefType::Explicit)
+return;
+
+  auto Provider =
+  firstSatisfiedProvider(ConvertedMainFileIncludes, Providers);
+  if (!Provider)
+return;
+
+  // Check if the referenced include matches this provider.
+  if (ReferencedInclude.match(*Provider).empty())
+return;
+
+  auto Loc = SM.getFileLoc(Ref.RefLocation);
+  // File locations can be outside of the main file if macro is
+  // expanded through an #include.
+  while (SM.getFileID(Loc) != SM.getMainFileID())
+Loc 

[PATCH] D147325: Implement cross reference request for #include lines.

2023-03-31 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo abandoned this revision.
VitaNuo added a comment.

Erroneously created patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147325

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


[PATCH] D147326: [clang][dataflow][NFC] Share code between Environment ctor and pushCallInternal().

2023-03-31 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The deduplicated code is moved into initVars().

As an added bonus, pushCallInternal() now also gets the "Add all fields
mentioned in default member initializers" behavior, which apparently had been
added to the Environment ctor but not pushCallInternal().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147326

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -203,7 +203,33 @@
 
 // FIXME: Add support for resetting globals after function calls to enable
 // the implementation of sound analyses.
-void Environment::initVars(llvm::DenseSet Vars) {
+void Environment::initVars(const FunctionDecl *FuncDecl) {
+  assert(FuncDecl->getBody() != nullptr);
+
+  llvm::DenseSet Fields;
+  llvm::DenseSet Vars;
+
+  // Look for global variable and field references in the
+  // constructor-initializers.
+  if (const auto *CtorDecl = dyn_cast(FuncDecl)) {
+for (const auto *Init : CtorDecl->inits()) {
+  if (const auto *M = Init->getAnyMember())
+  Fields.insert(M);
+  const Expr *E = Init->getInit();
+  assert(E != nullptr);
+  getFieldsAndGlobalVars(*E, Fields, Vars);
+}
+// Add all fields mentioned in default member initializers.
+for (const FieldDecl *F : CtorDecl->getParent()->fields())
+  if (const auto *I = F->getInClassInitializer())
+  getFieldsAndGlobalVars(*I, Fields, Vars);
+  }
+  getFieldsAndGlobalVars(*FuncDecl->getBody(), Fields, Vars);
+
+  // These have to be added before the lines that follow to ensure that
+  // `create*` work correctly for structs.
+  DACtx->addModeledFields(Fields);
+
   for (const VarDecl *D : Vars) {
 if (getStorageLocation(*D, SkipPast::None) != nullptr)
   continue;
@@ -239,31 +265,7 @@
   if (const auto *FuncDecl = dyn_cast(&DeclCtx)) {
 assert(FuncDecl->getBody() != nullptr);
 
-llvm::DenseSet Fields;
-llvm::DenseSet Vars;
-
-// Look for global variable and field references in the
-// constructor-initializers.
-if (const auto *CtorDecl = dyn_cast(&DeclCtx)) {
-  for (const auto *Init : CtorDecl->inits()) {
-if (const auto *M = Init->getAnyMember())
-  Fields.insert(M);
-const Expr *E = Init->getInit();
-assert(E != nullptr);
-getFieldsAndGlobalVars(*E, Fields, Vars);
-  }
-  // Add all fields mentioned in default member initializers.
-  for (const FieldDecl *F  : CtorDecl->getParent()->fields())
-if (const auto *I = F->getInClassInitializer())
-  getFieldsAndGlobalVars(*I, Fields, Vars);
-}
-getFieldsAndGlobalVars(*FuncDecl->getBody(), Fields, Vars);
-
-// These have to be added before the lines that follow to ensure that
-// `create*` work correctly for structs.
-DACtx.addModeledFields(Fields);
-
-initVars(Vars);
+initVars(FuncDecl);
 
 for (const auto *ParamDecl : FuncDecl->parameters()) {
   assert(ParamDecl != nullptr);
@@ -337,26 +339,7 @@
ArrayRef Args) {
   CallStack.push_back(FuncDecl);
 
-  // FIXME: Share this code with the constructor, rather than duplicating it.
-  llvm::DenseSet Fields;
-  llvm::DenseSet Vars;
-  // Look for global variable references in the constructor-initializers.
-  if (const auto *CtorDecl = dyn_cast(FuncDecl)) {
-for (const auto *Init : CtorDecl->inits()) {
-  if (const auto *M = Init->getAnyMember())
-Fields.insert(M);
-  const Expr *E = Init->getInit();
-  assert(E != nullptr);
-  getFieldsAndGlobalVars(*E, Fields, Vars);
-}
-  }
-  getFieldsAndGlobalVars(*FuncDecl->getBody(), Fields, Vars);
-
-  // These have to be added before the lines that follow to ensure that
-  // `create*` work correctly for structs.
-  DACtx->addModeledFields(Fields);
-
-  initVars(Vars);
+  initVars(FuncDecl);
 
   const auto *ParamIt = FuncDecl->param_begin();
 
Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -460,8 +460,9 @@
   void pushCallInternal(const FunctionDecl *FuncDecl,
 ArrayRef Args);
 
-  /// Assigns storage locations and values to all variables in `Vars`.
-  void initVars(llvm::DenseSet Vars);
+  /// Assigns storage locations and values to all 

[PATCH] D147327: [clang-format] Add option for having one port on a line in Verilog

2023-03-31 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
sstwcw requested review of this revision.
Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

Your review contains a change to clang/include/clang/Format/Format.h but does 
not contain an update to ClangFormatStyleOptions.rst

ClangFormatStyleOptions.rst is generated via 
clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html


We added the option `VerilogBreakBetweenInstancePorts` to put ports on
separate lines in module instantiations.  We made it default to true
because style guides mostly recommend it that way for example:

https://github.com/lowRISC/style-guides/blob/master/VerilogCodingStyle.md#module-instantiation


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147327

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

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -659,6 +659,77 @@
"  x = x;");
 }
 
+TEST_F(FormatTestVerilog, Instantiation) {
+  // Without ports.
+  verifyFormat("ffnand ff1;");
+  // With named ports.
+  verifyFormat("ffnand ff1(.qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  // With wildcard.
+  verifyFormat("ffnand ff1(.qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2),\n"
+   "   .*);");
+  verifyFormat("ffnand ff1(.*,\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  // With unconnected ports.
+  verifyFormat("ffnand ff1(.q(),\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  verifyFormat("ffnand ff1(.q(),\n"
+   "   .qbar(),\n"
+   "   .clear(),\n"
+   "   .preset());");
+  verifyFormat("ffnand ff1(,\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  // With positional ports.
+  verifyFormat("ffnand ff1(out1,\n"
+   "   in1,\n"
+   "   in2);");
+  verifyFormat("ffnand ff1(,\n"
+   "   out1,\n"
+   "   in1,\n"
+   "   in2);");
+  // Multiple instantiations.
+  verifyFormat("ffnand ff1(.q(),\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2)),\n"
+   "   ff1(.q(),\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  verifyFormat("ffnand //\n"
+   "ff1(.q(),\n"
+   ".qbar(out1),\n"
+   ".clear(in1),\n"
+   ".preset(in2)),\n"
+   "ff1(.q(),\n"
+   ".qbar(out1),\n"
+   ".clear(in1),\n"
+   ".preset(in2));");
+  // With breaking between instance ports disabled.
+  auto Style = getDefaultStyle();
+  Style.VerilogBreakBetweenInstancePorts = false;
+  verifyFormat("ffnand ff1;", Style);
+  verifyFormat("ffnand ff1(.qbar(out1), .clear(in1), .preset(in2), .*);",
+   Style);
+  verifyFormat("ffnand ff1(out1, in1, in2);", Style);
+  verifyFormat("ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2)),\n"
+   "   ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));",
+   Style);
+  verifyFormat("ffnand //\n"
+   "ff1(.q(), .qbar(out1), .clear(in1), .preset(in2)),\n"
+   "ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));",
+   Style);
+}
+
 TEST_F(FormatTestVerilog, Operators) {
   // Test that unary operators are not followed by space.
   verifyFormat("x = +x;");
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -192,6 +192,7 @@
   CHECK_PARSE_BOOL(SpaceBeforeJsonColon);
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
   CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
+  CHECK_PARSE_BOOL(Ver

[PATCH] D147328: [clang-format] Handle enum in Verilog

2023-03-31 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
sstwcw requested review of this revision.

Verilog has enum just like C.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147328

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestVerilog.cpp


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -338,6 +338,20 @@
 "x = x;");
 }
 
+TEST_F(FormatTestVerilog, Enum) {
+  verifyFormat("enum { x } x;");
+  verifyFormat("typedef enum { x } x;");
+  verifyFormat("enum { red, yellow, green } x;");
+  verifyFormat("typedef enum { red, yellow, green } x;");
+  verifyFormat("enum integer { x } x;");
+  verifyFormat("typedef enum { x = 0 } x;");
+  verifyFormat("typedef enum { red = 0, yellow = 1, green = 2 } x;");
+  verifyFormat("typedef enum integer { x } x;");
+  verifyFormat("typedef enum bit [0 : 1] { x } x;");
+  verifyFormat("typedef enum { add = 10, sub[5], jmp[6 : 8] } E1;");
+  verifyFormat("typedef enum { add = 10, sub[5] = 0, jmp[6 : 8] = 1 } E1;");
+}
+
 TEST_F(FormatTestVerilog, Headers) {
   // Test headers with multiple ports.
   verifyFormat("module mh1\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1709,8 +1709,8 @@
   // enum definition can start a structural element.
   if (!parseEnum())
 break;
-  // This only applies for C++.
-  if (!Style.isCpp()) {
+  // This only applies for C++ and Verilog.
+  if (!Style.isCpp() && !Style.isVerilog()) {
 addUnwrappedLine();
 return;
   }
@@ -3541,7 +3541,15 @@
  FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less,
 tok::greater, tok::comma, tok::question,
 tok::l_square, tok::r_square)) {
-nextToken();
+if (Style.isVerilog()) {
+  FormatTok->setFinalizedType(TT_VerilogDimensionedTypeName);
+  nextToken();
+  // In Verilog the base type can have dimensions.
+  while (FormatTok->is(tok::l_square))
+parseSquare();
+} else {
+  nextToken();
+}
 // We can have macros or attributes in between 'enum' and the enum name.
 if (FormatTok->is(tok::l_paren))
   parseParens();


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -338,6 +338,20 @@
 "x = x;");
 }
 
+TEST_F(FormatTestVerilog, Enum) {
+  verifyFormat("enum { x } x;");
+  verifyFormat("typedef enum { x } x;");
+  verifyFormat("enum { red, yellow, green } x;");
+  verifyFormat("typedef enum { red, yellow, green } x;");
+  verifyFormat("enum integer { x } x;");
+  verifyFormat("typedef enum { x = 0 } x;");
+  verifyFormat("typedef enum { red = 0, yellow = 1, green = 2 } x;");
+  verifyFormat("typedef enum integer { x } x;");
+  verifyFormat("typedef enum bit [0 : 1] { x } x;");
+  verifyFormat("typedef enum { add = 10, sub[5], jmp[6 : 8] } E1;");
+  verifyFormat("typedef enum { add = 10, sub[5] = 0, jmp[6 : 8] = 1 } E1;");
+}
+
 TEST_F(FormatTestVerilog, Headers) {
   // Test headers with multiple ports.
   verifyFormat("module mh1\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1709,8 +1709,8 @@
   // enum definition can start a structural element.
   if (!parseEnum())
 break;
-  // This only applies for C++.
-  if (!Style.isCpp()) {
+  // This only applies for C++ and Verilog.
+  if (!Style.isCpp() && !Style.isVerilog()) {
 addUnwrappedLine();
 return;
   }
@@ -3541,7 +3541,15 @@
  FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less,
 tok::greater, tok::comma, tok::question,
 tok::l_square, tok::r_square)) {
-nextToken();
+if (Style.isVerilog()) {
+  FormatTok->setFinalizedType(TT_VerilogDimensionedTypeName);
+  nextToken();
+  // In Verilog the base type can have dimensions.
+  while (FormatTok->is(tok::l_square))
+parseSquare();
+} else {
+  nextToken();
+}
 // We can have macros or attributes in between 'enum' and the enum name.
 if (FormatTok->is(tok::l_paren))
   parseParens();
___
cfe-commits mailing list
c

[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-03-31 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 510032.
VitaNuo added a comment.

Simplify.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -43,6 +43,10 @@
 using ::testing::UnorderedElementsAreArray;
 using ::testing::UnorderedPointwise;
 
+std::string guard(llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 MATCHER_P2(FileRange, File, Range, "") {
   return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
 }
@@ -2293,6 +2297,51 @@
 checkFindRefs(Test);
 }
 
+TEST(FindReferences, UsedSymbolsFromInclude) {
+  const char *Tests[] = {
+  R"cpp([[#include ^"bar.h"]]
+#include 
+int fstBar = [[bar1]]();
+int sndBar = [[bar2]]();
+[[Bar]] bar;
+int macroBar = [[BAR]];
+std::vector vec;
+  )cpp",
+
+  R"cpp([[#in^clude ]]
+std::[[vector]] vec;
+  )cpp"};
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto TU = TestTU::withCode(T.code());
+TU.ExtraArgs.push_back("-std=c++20");
+TU.AdditionalFiles["bar.h"] = guard(R"cpp(
+  #define BAR 5
+  int bar1();
+  int bar2();
+  class Bar {};
+)cpp");
+TU.AdditionalFiles["system/vector"] = guard(R"cpp(
+  namespace std {
+template
+class vector{};
+  }
+)cpp");
+TU.ExtraArgs.push_back("-isystem" + testPath("system"));
+
+auto AST = TU.build();
+std::vector> ExpectedLocations;
+for (const auto &R : T.ranges())
+  ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
+for (const auto &P : T.points()) {
+  EXPECT_THAT(findReferences(AST, P, 0).References,
+  UnorderedElementsAreArray(ExpectedLocations))
+  << "Failed for Refs at " << P << "\n"
+  << Test;
+}
+  }
+}
+
 TEST(FindReferences, NeedsIndexForSymbols) {
   const char *Header = "int foo();";
   Annotations Main("int main() { [[f^oo]](); }");
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -10,12 +10,15 @@
 #include "FindSymbols.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -48,6 +51,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,6 +65,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1312,6 +1317,63 @@
 }
 } // namespace
 
+ReferencesResult maybeFindIncludeReferences(ParsedAST &AST, Position Pos,
+URIForFile URIMainFile) {
+  ReferencesResult Results;
+  const SourceManager &SM = AST.getSourceManager();
+  auto Includes = AST.getIncludeStructure().MainFileIncludes;
+  auto ConvertedMainFileIncludes = convertIncludes(SM, Includes);
+  for (auto &Inc : Includes) {
+if (Inc.HashLine != Pos.line)
+  continue;
+
+auto ReferencedInclude = convertIncludes(SM, Inc);
+include_cleaner::walkUsed(
+AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
+AST.getPragmaIncludes(), SM,
+[&](const include_cleaner::SymbolReference &Ref,
+llvm::ArrayRef Providers) {
+  if (Ref.RT != include_cleaner::RefType::Explicit)
+return;
+
+  auto Provider =
+  firstSatisfiedProvider(ConvertedMainFileIncludes, Providers);
+  if (!Provider)
+return;
+
+  // Check if the referenced include matches this provider.
+  if (ReferencedInclude.match(*Provider).empty())
+return;
+
+  auto Loc = SM.getFileLoc(Ref.RefLocation);
+  // File locations can be outside of the main file if macro is
+  // expanded through an #include.
+  while (SM.getFileID(Loc) != SM.getMainFileID())
+Loc = SM.getIncludeLoc(SM.getFileID(Loc));
+
+  Refere

[PATCH] D147329: [clang-format] Handle Verilog struct literals

2023-03-31 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
Herald added subscribers: cfe-commits, ctetreau.
Herald added projects: All, clang, clang-format.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
sstwcw requested review of this revision.

Previously `isVerilogIdentifier` was mistaking the apostrophe used in
struct literals as an identifier.  It is fixed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147329

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


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -902,6 +902,25 @@
   verifyFormat("{

[PATCH] D146042: [clang-format] Fix numerous issues with "LambdaBodyIndentation: OuterScope" option

2023-03-31 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

Could I get a re-review on this one please?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146042

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


[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-03-31 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 510036.
VitaNuo added a comment.

Remove extra formatting changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -43,6 +43,10 @@
 using ::testing::UnorderedElementsAreArray;
 using ::testing::UnorderedPointwise;
 
+std::string guard(llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 MATCHER_P2(FileRange, File, Range, "") {
   return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
 }
@@ -2293,6 +2297,51 @@
 checkFindRefs(Test);
 }
 
+TEST(FindReferences, UsedSymbolsFromInclude) {
+  const char *Tests[] = {
+  R"cpp([[#include ^"bar.h"]]
+#include 
+int fstBar = [[bar1]]();
+int sndBar = [[bar2]]();
+[[Bar]] bar;
+int macroBar = [[BAR]];
+std::vector vec;
+  )cpp",
+
+  R"cpp([[#in^clude ]]
+std::[[vector]] vec;
+  )cpp"};
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto TU = TestTU::withCode(T.code());
+TU.ExtraArgs.push_back("-std=c++20");
+TU.AdditionalFiles["bar.h"] = guard(R"cpp(
+  #define BAR 5
+  int bar1();
+  int bar2();
+  class Bar {};
+)cpp");
+TU.AdditionalFiles["system/vector"] = guard(R"cpp(
+  namespace std {
+template
+class vector{};
+  }
+)cpp");
+TU.ExtraArgs.push_back("-isystem" + testPath("system"));
+
+auto AST = TU.build();
+std::vector> ExpectedLocations;
+for (const auto &R : T.ranges())
+  ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
+for (const auto &P : T.points()) {
+  EXPECT_THAT(findReferences(AST, P, 0).References,
+  UnorderedElementsAreArray(ExpectedLocations))
+  << "Failed for Refs at " << P << "\n"
+  << Test;
+}
+  }
+}
+
 TEST(FindReferences, NeedsIndexForSymbols) {
   const char *Header = "int foo();";
   Annotations Main("int main() { [[f^oo]](); }");
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -10,12 +10,15 @@
 #include "FindSymbols.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -48,6 +51,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,6 +65,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1312,6 +1317,63 @@
 }
 } // namespace
 
+ReferencesResult maybeFindIncludeReferences(ParsedAST &AST, Position Pos,
+URIForFile URIMainFile) {
+  ReferencesResult Results;
+  const SourceManager &SM = AST.getSourceManager();
+  auto Includes = AST.getIncludeStructure().MainFileIncludes;
+  auto ConvertedMainFileIncludes = convertIncludes(SM, Includes);
+  for (auto &Inc : Includes) {
+if (Inc.HashLine != Pos.line)
+  continue;
+
+auto ReferencedInclude = convertIncludes(SM, Inc);
+include_cleaner::walkUsed(
+AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
+AST.getPragmaIncludes(), SM,
+[&](const include_cleaner::SymbolReference &Ref,
+llvm::ArrayRef Providers) {
+  if (Ref.RT != include_cleaner::RefType::Explicit)
+return;
+
+  auto Provider =
+  firstSatisfiedProvider(ConvertedMainFileIncludes, Providers);
+  if (!Provider)
+return;
+
+  // Check if the referenced include matches this provider.
+  if (ReferencedInclude.match(*Provider).empty())
+return;
+
+  auto Loc = SM.getFileLoc(Ref.RefLocation);
+  // File locations can be outside of the main file if macro is
+  // expanded through an #include.
+  while (SM.getFileID(Loc) != SM.getMainFileID())
+Loc = SM.getIncludeLoc(SM.getFileID(Loc

[PATCH] D147327: [clang-format] Add option for having one port per line in Verilog

2023-03-31 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 510038.
sstwcw added a comment.

Generate doc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147327

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -659,6 +659,77 @@
"  x = x;");
 }
 
+TEST_F(FormatTestVerilog, Instantiation) {
+  // Without ports.
+  verifyFormat("ffnand ff1;");
+  // With named ports.
+  verifyFormat("ffnand ff1(.qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  // With wildcard.
+  verifyFormat("ffnand ff1(.qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2),\n"
+   "   .*);");
+  verifyFormat("ffnand ff1(.*,\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  // With unconnected ports.
+  verifyFormat("ffnand ff1(.q(),\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  verifyFormat("ffnand ff1(.q(),\n"
+   "   .qbar(),\n"
+   "   .clear(),\n"
+   "   .preset());");
+  verifyFormat("ffnand ff1(,\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  // With positional ports.
+  verifyFormat("ffnand ff1(out1,\n"
+   "   in1,\n"
+   "   in2);");
+  verifyFormat("ffnand ff1(,\n"
+   "   out1,\n"
+   "   in1,\n"
+   "   in2);");
+  // Multiple instantiations.
+  verifyFormat("ffnand ff1(.q(),\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2)),\n"
+   "   ff1(.q(),\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  verifyFormat("ffnand //\n"
+   "ff1(.q(),\n"
+   ".qbar(out1),\n"
+   ".clear(in1),\n"
+   ".preset(in2)),\n"
+   "ff1(.q(),\n"
+   ".qbar(out1),\n"
+   ".clear(in1),\n"
+   ".preset(in2));");
+  // With breaking between instance ports disabled.
+  auto Style = getDefaultStyle();
+  Style.VerilogBreakBetweenInstancePorts = false;
+  verifyFormat("ffnand ff1;", Style);
+  verifyFormat("ffnand ff1(.qbar(out1), .clear(in1), .preset(in2), .*);",
+   Style);
+  verifyFormat("ffnand ff1(out1, in1, in2);", Style);
+  verifyFormat("ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2)),\n"
+   "   ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));",
+   Style);
+  verifyFormat("ffnand //\n"
+   "ff1(.q(), .qbar(out1), .clear(in1), .preset(in2)),\n"
+   "ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));",
+   Style);
+}
+
 TEST_F(FormatTestVerilog, Operators) {
   // Test that unary operators are not followed by space.
   verifyFormat("x = +x;");
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -192,6 +192,7 @@
   CHECK_PARSE_BOOL(SpaceBeforeJsonColon);
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
   CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
+  CHECK_PARSE_BOOL(VerilogBreakBetweenInstancePorts);
 
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterCaseLabel);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterClass);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -311,6 +311,9 @@
   bool OperatorCalledAsMemberFunction =
   Prev->Previous && Prev->Previous->isOneOf(tok::period, tok::arrow);
   Contexts.back().IsExpression = OperatorCalledAsMemberFunction;
+} else if (OpeningParen.is(TT_VerilogInstancePortLParen)) {
+  Contexts.back().IsExpression = true;
+  Contexts.back().ContextType = Context::VerilogInstancePortList;
 } else if (Style.isJavaScript() &&
(Line.startsWith(Keywords.kw_type, tok

[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-03-31 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 510039.
VitaNuo added a comment.

Rename function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -43,6 +43,10 @@
 using ::testing::UnorderedElementsAreArray;
 using ::testing::UnorderedPointwise;
 
+std::string guard(llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 MATCHER_P2(FileRange, File, Range, "") {
   return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
 }
@@ -2293,6 +2297,50 @@
 checkFindRefs(Test);
 }
 
+TEST(FindReferences, UsedSymbolsFromInclude) {
+  const char *Tests[] = {
+  R"cpp([[#include ^"bar.h"]]
+#include 
+int fstBar = [[bar1]]();
+int sndBar = [[bar2]]();
+[[Bar]] bar;
+int macroBar = [[BAR]];
+std::vector vec;
+  )cpp",
+
+  R"cpp([[#in^clude ]]
+std::[[vector]] vec;
+  )cpp"};
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto TU = TestTU::withCode(T.code());
+TU.ExtraArgs.push_back("-std=c++20");
+TU.AdditionalFiles["bar.h"] = guard(R"cpp(
+  #define BAR 5
+  int bar1();
+  int bar2();
+  class Bar {};
+)cpp");
+TU.AdditionalFiles["system/vector"] = guard(R"cpp(
+  namespace std {
+template
+class vector{};
+  }
+)cpp");
+TU.ExtraArgs.push_back("-isystem" + testPath("system"));
+
+auto AST = TU.build();
+std::vector> ExpectedLocations;
+for (const auto &R : T.ranges())
+  ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
+for (const auto &P : T.points()) 
+  EXPECT_THAT(findReferences(AST, P, 0).References,
+  UnorderedElementsAreArray(ExpectedLocations))
+  << "Failed for Refs at " << P << "\n"
+  << Test;
+  }
+}
+
 TEST(FindReferences, NeedsIndexForSymbols) {
   const char *Header = "int foo();";
   Annotations Main("int main() { [[f^oo]](); }");
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -10,12 +10,15 @@
 #include "FindSymbols.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -48,6 +51,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,6 +65,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1312,6 +1317,63 @@
 }
 } // namespace
 
+ReferencesResult maybeFindIncludeReferences(ParsedAST &AST, Position Pos,
+URIForFile URIMainFile) {
+  ReferencesResult Results;
+  const SourceManager &SM = AST.getSourceManager();
+  auto Includes = AST.getIncludeStructure().MainFileIncludes;
+  auto ConvertedMainFileIncludes = convertIncludes(SM, Includes);
+  for (auto &Inc : Includes) {
+if (Inc.HashLine != Pos.line)
+  continue;
+
+auto ReferencedInclude = convertIncludes(SM, Inc);
+include_cleaner::walkUsed(
+AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
+AST.getPragmaIncludes(), SM,
+[&](const include_cleaner::SymbolReference &Ref,
+llvm::ArrayRef Providers) {
+  if (Ref.RT != include_cleaner::RefType::Explicit)
+return;
+
+  auto Provider =
+  firstMatchedProvider(ConvertedMainFileIncludes, Providers);
+  if (!Provider)
+return;
+
+  // Check if the referenced include matches this provider.
+  if (ReferencedInclude.match(*Provider).empty())
+return;
+
+  auto Loc = SM.getFileLoc(Ref.RefLocation);
+  // File locations can be outside of the main file if macro is
+  // expanded through an #include.
+  while (SM.getFileID(Loc) != SM.getMainFileID())
+Loc = SM.getIncludeLoc(SM.getFileID(Loc));
+
+  Reference

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

2023-03-31 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added inline comments.



Comment at: clang/test/Driver/ppc-roptr.c:37
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"

qiongsiwu1 wrote:
> hubert.reinterpretcast wrote:
> > This needs the backend option also renamed. Has a commit for that landed 
> > yet?
> No the commit has not landed. The patch is up 
> https://reviews.llvm.org/D147161. 
> This needs the backend option also renamed. Has a commit for that landed yet?

Thanks so much for the fast review Hubert! The commit has now landed. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

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


[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-03-31 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

Thanks for the comments!




Comment at: clang-tools-extra/clangd/XRefs.cpp:1348
+  auto Loc = SM.getFileLoc(Ref.RefLocation);
+  for (const auto &H : Providers) {
+auto MatchingIncludes = ConvertedMainFileIncludes.match(H);

kadircet wrote:
> we're implementing and testing this logic twice now, once in here and once in 
> hover. can we instead have a helper in `IncludeCleaner.h` that looks like:
> ```
> std::optional firstSatisfiedProvider(const 
> include_cleaner::Includes& Includes, llvm::ArrayRef 
> Providers);
> // I'd actually return the matching `std::vector` (the 
> highest ranked provider that matched some includes in main file), and check 
> if the include of interest is part of that set for rest of the operations.
> // Since it represents both the provider and the include in the main file. 
> whereas the provider on it's own doesn't say anything about which include in 
> main file triggered satisfaction.
> ```
> and turn these call sites into
> ```
> auto Provider = firstSatisfiedProvider(ConvertedMainFileIncludes, Providers);
> if(!Provider || ReferencedInclude.match(Provider).empty())
>   return;
> // Include in question provides the symbol, do magic.
> ```
Is the comment under the code in the first snippet a mistake/outdated content? 
It confused me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

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


[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-03-31 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:264
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to 

Please keep alphabetical order (by check name) in this section.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147315

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


[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-03-31 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 510042.
VitaNuo added a comment.

Simplify.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -43,6 +43,10 @@
 using ::testing::UnorderedElementsAreArray;
 using ::testing::UnorderedPointwise;
 
+std::string guard(llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 MATCHER_P2(FileRange, File, Range, "") {
   return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
 }
@@ -2293,6 +2297,50 @@
 checkFindRefs(Test);
 }
 
+TEST(FindReferences, UsedSymbolsFromInclude) {
+  const char *Tests[] = {
+  R"cpp([[#include ^"bar.h"]]
+#include 
+int fstBar = [[bar1]]();
+int sndBar = [[bar2]]();
+[[Bar]] bar;
+int macroBar = [[BAR]];
+std::vector vec;
+  )cpp",
+
+  R"cpp([[#in^clude ]]
+std::[[vector]] vec;
+  )cpp"};
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto TU = TestTU::withCode(T.code());
+TU.ExtraArgs.push_back("-std=c++20");
+TU.AdditionalFiles["bar.h"] = guard(R"cpp(
+  #define BAR 5
+  int bar1();
+  int bar2();
+  class Bar {};
+)cpp");
+TU.AdditionalFiles["system/vector"] = guard(R"cpp(
+  namespace std {
+template
+class vector{};
+  }
+)cpp");
+TU.ExtraArgs.push_back("-isystem" + testPath("system"));
+
+auto AST = TU.build();
+std::vector> ExpectedLocations;
+for (const auto &R : T.ranges())
+  ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
+for (const auto &P : T.points()) 
+  EXPECT_THAT(findReferences(AST, P, 0).References,
+  UnorderedElementsAreArray(ExpectedLocations))
+  << "Failed for Refs at " << P << "\n"
+  << Test;
+  }
+}
+
 TEST(FindReferences, NeedsIndexForSymbols) {
   const char *Header = "int foo();";
   Annotations Main("int main() { [[f^oo]](); }");
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -10,12 +10,15 @@
 #include "FindSymbols.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -48,6 +51,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,6 +65,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1312,6 +1317,59 @@
 }
 } // namespace
 
+ReferencesResult maybeFindIncludeReferences(ParsedAST &AST, Position Pos,
+URIForFile URIMainFile) {
+  ReferencesResult Results;
+  const SourceManager &SM = AST.getSourceManager();
+  auto Includes = AST.getIncludeStructure().MainFileIncludes;
+  auto ConvertedMainFileIncludes = convertIncludes(SM, Includes);
+  for (auto &Inc : Includes) {
+if (Inc.HashLine != Pos.line)
+  continue;
+
+auto ReferencedInclude = convertIncludes(SM, Inc);
+include_cleaner::walkUsed(
+AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
+AST.getPragmaIncludes(), SM,
+[&](const include_cleaner::SymbolReference &Ref,
+llvm::ArrayRef Providers) {
+  if (Ref.RT != include_cleaner::RefType::Explicit)
+return;
+
+  auto Provider =
+  firstMatchedProvider(ConvertedMainFileIncludes, Providers);
+  if (!Provider || ReferencedInclude.match(*Provider).empty())
+return;
+
+  auto Loc = SM.getFileLoc(Ref.RefLocation);
+  // File locations can be outside of the main file if macro is
+  // expanded through an #include.
+  while (SM.getFileID(Loc) != SM.getMainFileID())
+Loc = SM.getIncludeLoc(SM.getFileID(Loc));
+
+  ReferencesResult::Reference Result;
+  const auto *Token = AST.getTokens().spelledTokenAt(Loc);
+  Result

[PATCH] D141389: [DFSAN] Add support for strnlen, strncat, strsep, sscanf and _tolower

2023-03-31 Thread Tomasz Kuchta via Phabricator via cfe-commits
tkuchta updated this revision to Diff 510041.
tkuchta marked an inline comment as done.
tkuchta added a comment.

Hello, I applied the review comments for strsep.


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

https://reviews.llvm.org/D141389

Files:
  compiler-rt/lib/dfsan/dfsan_custom.cpp
  compiler-rt/test/dfsan/custom.cpp

Index: compiler-rt/test/dfsan/custom.cpp
===
--- compiler-rt/test/dfsan/custom.cpp
+++ compiler-rt/test/dfsan/custom.cpp
@@ -1636,80 +1636,38 @@
   char *p_delim = delim;
 
   // taint delim bytes
-  dfsan_set_label(n_label, p_delim, strlen(p_delim));
+  dfsan_set_label(i_label, p_delim, strlen(p_delim));
   // taint delim pointer
-  dfsan_set_label(i_label, &p_delim, sizeof(&p_delim));
+  dfsan_set_label(j_label, &p_delim, sizeof(&p_delim));
+  // taint the string data bytes
+  dfsan_set_label(k_label, s, 5);
+  // taint the string pointer
+  dfsan_set_label(m_label, &p_s, sizeof(&p_s));
 
   char *rv = strsep(&p_s, p_delim);
   assert(rv == &base[0]);
 #ifdef STRICT_DATA_DEPENDENCIES
-  ASSERT_ZERO_LABEL(rv);
-  ASSERT_READ_ZERO_LABEL(rv, strlen(rv));
+  ASSERT_LABEL(rv, k_label);
+  ASSERT_READ_LABEL(rv, strlen(rv), k_label);
 #else
-  ASSERT_LABEL(rv, dfsan_union(i_label, n_label));
-  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, *p_delim);
+  ASSERT_LABEL(rv, dfsan_union(dfsan_union(i_label, j_label), k_label));
+  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, *s);
 #endif
 
-  // taint the remaining string's bytes
-  dfsan_set_label(m_label, p_s, strlen(p_s));
   // taint the remaining string's pointer
   char **pp_s = &p_s;
-  dfsan_set_label(j_label, &pp_s, sizeof(&p_s));
+  char **pp_s_base = pp_s;
+  dfsan_set_label(n_label, &pp_s, sizeof(&pp_s));
 
   rv = strsep(pp_s, p_delim);
 
   assert(rv == &base[6]);
-#ifdef STRICT_DATA_DEPENDENCIES
-  ASSERT_READ_LABEL(rv, strlen(rv), m_label);
-  ASSERT_LABEL(rv, j_label);
-  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, pp_s);
-#else
-  ASSERT_LABEL(
-  rv, dfsan_union(j_label,
-  dfsan_union(i_label, dfsan_union(m_label, n_label;
-  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, base[6]);
-#endif
-
-  free(s);
-  s = strdup("Hello world/");
-  base = s;
-  free(delim);
-  delim = strdup(" /");
-  p_delim = delim;
-
-  dfsan_set_label(j_label, &delim[0], 1);
-
-  rv = strsep(&s, delim);
-  assert(rv == &base[0]);
 #ifdef STRICT_DATA_DEPENDENCIES
   ASSERT_ZERO_LABEL(rv);
+  ASSERT_ZERO_ORIGIN(rv);
 #else
-  ASSERT_LABEL(rv, j_label);
-  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, delim[1]);
-#endif
-
-  char *ps = s;
-  pp_s = &ps;
-  dfsan_set_label(i_label, &pp_s, sizeof(&pp_s));
-  dfsan_set_label(i_label, ps, strlen(ps));
-  dfsan_set_label(dfsan_union(j_label, dfsan_read_label(ps, strlen(ps))), ps,
-  strlen(ps));
-  rv = strsep(pp_s, " /");
-  assert(rv == &base[6]);
-#ifdef STRICT_DATA_DEPENDENCIES
-  ASSERT_LABEL(rv, i_label);
-#else
-  ASSERT_LABEL(rv, i_j_label);
-  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, base[6]);
-#endif
-  rv = strsep(&ps, " /");
-  assert(strlen(rv) == 0);
-#ifdef STRICT_DATA_DEPENDENCIES
-  ASSERT_ZERO_LABEL(ps);
-#else
-  ASSERT_ZERO_LABEL(rv);
-  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, 0);
-
+  ASSERT_LABEL(rv, dfsan_union(i_label, dfsan_union(j_label, n_label)));
+  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, *p_delim);
 #endif
 }
 
Index: compiler-rt/lib/dfsan/dfsan_custom.cpp
===
--- compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -218,11 +218,10 @@
   }
 
   if (flags().strict_data_dependencies) {
-*ret_label = res ? s_label : 0;
+*ret_label = res ? dfsan_read_label(base, sizeof(base)) : 0;
   } else {
-size_t s_bytes_read = (res ? strlen(res) : strlen(base)) + 1;
 *ret_label =
-dfsan_union(dfsan_read_label(base, s_bytes_read),
+dfsan_union(dfsan_read_label(base, sizeof(base)),
 dfsan_union(dfsan_read_label(delim, strlen(delim) + 1),
 dfsan_union(s_label, delim_label)));
   }
@@ -238,11 +237,10 @@
   char *res = __dfsw_strsep(s, delim, s_label, delim_label, ret_label);
   if (flags().strict_data_dependencies) {
 if (res)
-  *ret_origin = s_origin;
+  *ret_origin = dfsan_read_origin_of_first_taint(base, strlen(base));
   } else {
 if (*ret_label) {
-  size_t s_bytes_read = (res ? strlen(res) : strlen(base)) + 1;
-  dfsan_origin o = dfsan_read_origin_of_first_taint(base, s_bytes_read);
+  dfsan_origin o = dfsan_read_origin_of_first_taint(base, strlen(base));
   if (o) {
 *ret_origin = o;
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141389: [DFSAN] Add support for strnlen, strncat, strsep, sscanf and _tolower

2023-03-31 Thread Tomasz Kuchta via Phabricator via cfe-commits
tkuchta updated this revision to Diff 510047.
tkuchta added a comment.

Updates after the review of strsep.


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

https://reviews.llvm.org/D141389

Files:
  compiler-rt/lib/dfsan/dfsan_custom.cpp
  compiler-rt/lib/dfsan/done_abilist.txt
  compiler-rt/test/dfsan/custom.cpp

Index: compiler-rt/test/dfsan/custom.cpp
===
--- compiler-rt/test/dfsan/custom.cpp
+++ compiler-rt/test/dfsan/custom.cpp
@@ -1627,6 +1627,50 @@
 #endif
 }
 
+void test_strsep() {
+  char *s = strdup("Hello world/");
+  char *delim = strdup(" /");
+
+  char *p_s = s;
+  char *base = s;
+  char *p_delim = delim;
+
+  // taint delim bytes
+  dfsan_set_label(i_label, p_delim, strlen(p_delim));
+  // taint delim pointer
+  dfsan_set_label(j_label, &p_delim, sizeof(&p_delim));
+  // taint the string data bytes
+  dfsan_set_label(k_label, s, 5);
+  // taint the string pointer
+  dfsan_set_label(m_label, &p_s, sizeof(&p_s));
+
+  char *rv = strsep(&p_s, p_delim);
+  assert(rv == &base[0]);
+#ifdef STRICT_DATA_DEPENDENCIES
+  ASSERT_LABEL(rv, k_label);
+  ASSERT_READ_LABEL(rv, strlen(rv), k_label);
+#else
+  ASSERT_LABEL(rv, dfsan_union(dfsan_union(i_label, j_label), k_label));
+  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, *s);
+#endif
+
+  // taint the remaining string's pointer
+  char **pp_s = &p_s;
+  char **pp_s_base = pp_s;
+  dfsan_set_label(n_label, &pp_s, sizeof(&pp_s));
+
+  rv = strsep(pp_s, p_delim);
+
+  assert(rv == &base[6]);
+#ifdef STRICT_DATA_DEPENDENCIES
+  ASSERT_ZERO_LABEL(rv);
+  ASSERT_ZERO_ORIGIN(rv);
+#else
+  ASSERT_LABEL(rv, dfsan_union(i_label, dfsan_union(j_label, n_label)));
+  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, *p_delim);
+#endif
+}
+
 void test_memchr() {
   char str1[] = "str1";
   dfsan_set_label(i_label, &str1[3], 1);
@@ -2041,6 +2085,7 @@
   test_strncmp();
   test_strncpy();
   test_strpbrk();
+  test_strsep();
   test_strrchr();
   test_strstr();
   test_strtod();
Index: compiler-rt/lib/dfsan/done_abilist.txt
===
--- compiler-rt/lib/dfsan/done_abilist.txt
+++ compiler-rt/lib/dfsan/done_abilist.txt
@@ -283,6 +283,7 @@
 fun:strpbrk=custom
 fun:strrchr=custom
 fun:strstr=custom
+fun:strsep=custom
 
 # Functions which take action based on global state, such as running a callback
 # set by a separate function.
Index: compiler-rt/lib/dfsan/dfsan_custom.cpp
===
--- compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -204,6 +204,55 @@
   return const_cast(ret);
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_strsep(char **s, const char *delim,
+  dfsan_label s_label,
+  dfsan_label delim_label,
+  dfsan_label *ret_label) {
+  char *base = *s;
+  char *res = strsep(s, delim);
+  if (res != *s) {
+char *token_start = res;
+int token_length = strlen(res);
+// the delimiter byte has been set to NULL
+dfsan_set_label(0, token_start + token_length, 1);
+  }
+
+  if (flags().strict_data_dependencies) {
+*ret_label = res ? dfsan_read_label(base, sizeof(base)) : 0;
+  } else {
+*ret_label =
+dfsan_union(dfsan_read_label(base, sizeof(base)),
+dfsan_union(dfsan_read_label(delim, strlen(delim) + 1),
+dfsan_union(s_label, delim_label)));
+  }
+
+  return res;
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE char *__dfso_strsep(
+char **s, const char *delim, dfsan_label s_label, dfsan_label delim_label,
+dfsan_label *ret_label, dfsan_origin s_origin, dfsan_origin delim_origin,
+dfsan_origin *ret_origin) {
+  char *base = *s;
+  char *res = __dfsw_strsep(s, delim, s_label, delim_label, ret_label);
+  if (flags().strict_data_dependencies) {
+if (res)
+  *ret_origin = dfsan_read_origin_of_first_taint(base, strlen(base));
+  } else {
+if (*ret_label) {
+  dfsan_origin o = dfsan_read_origin_of_first_taint(base, strlen(base));
+  if (o) {
+*ret_origin = o;
+  } else {
+o = dfsan_read_origin_of_first_taint(delim, strlen(delim) + 1);
+*ret_origin = o ? o : (s_label ? s_origin : delim_origin);
+  }
+}
+  }
+
+  return res;
+}
+
 static int dfsan_memcmp_bcmp(const void *s1, const void *s2, size_t n,
  size_t *bytes_read) {
   const char *cs1 = (const char *) s1, *cs2 = (const char *) s2;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147326: [clang][dataflow][NFC] Share code between Environment ctor and pushCallInternal().

2023-03-31 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:465
+  /// referenced in `FuncDecl`. `FuncDecl` must have a body.
+  void initVars(const FunctionDecl *FuncDecl);
 

I wonder if we should rename this to something like `initFieldAndGlobals`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147326

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


[PATCH] D147302: [clang][dataflow] Add `create()` methods to `Environment` and `DataflowAnalysisContext`.

2023-03-31 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:100
+// used `StorageLocation` subclasses and make them use a 
`BumpPtrAllocator`.
+Locs.push_back(std::make_unique(std::forward(args)...));
+return *cast(Locs.back().get());

Would emplace back work? That returns a reference to the just emplaced element 
saving us the call to `back` making the code a bit more concise.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:328
+  template 
+  std::enable_if_t::value, T &>
+  create(Args &&...args) {

Just curious, what is the reason for repeating the `enable_if` here in addition 
to the one in the called function? Do we get better error messages?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147302

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


[PATCH] D141389: [DFSAN] Add support for strnlen, strncat, strsep, sscanf and _tolower

2023-03-31 Thread Tomasz Kuchta via Phabricator via cfe-commits
tkuchta added a comment.

there is a strange build error which seems unrelated to my change - please let 
me know if that's an issue, I will try to rebase to newest master then


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

https://reviews.llvm.org/D141389

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


[PATCH] D144522: [clang-tidy] Add readability-operators-representation check

2023-03-31 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa084854266ca: [clang-tidy] Add 
readability-operators-representation check (authored by PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D144522?vs=508310&id=510055#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144522

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp
  clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-alternative.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp
@@ -0,0 +1,177 @@
+// RUN: %check_clang_tidy %s readability-operators-representation %t -- -config="{CheckOptions: [\
+// RUN: {key: readability-operators-representation.BinaryOperators, value: '&&;&=;&;|;~;!;!=;||;|=;^;^='}, \
+// RUN: {key: readability-operators-representation.OverloadedOperators, value: '&&;&=;&;|;~;!;!=;||;|=;^;^='}]}" --
+
+void testAllTokensToAlternative(int a, int b) {
+  int value = 0;
+
+  value = a or b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'or' is an alternative token spelling, consider using a traditional token '||' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a || b;{{$}}
+
+  value = a and b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'and' is an alternative token spelling, consider using a traditional token '&&' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a && b;{{$}}
+
+  value = a bitor b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitor' is an alternative token spelling, consider using a traditional token '|' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a | b;{{$}}
+
+  value = a bitand b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitand' is an alternative token spelling, consider using a traditional token '&' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a & b;{{$}}
+
+  value = not a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'not' is an alternative token spelling, consider using a traditional token '!' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = ! a;{{$}}
+
+  value = a xor b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'xor' is an alternative token spelling, consider using a traditional token '^' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a ^ b;{{$}}
+
+  value = compl b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'compl' is an alternative token spelling, consider using a traditional token '~' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = ~ b;{{$}}
+
+  value and_eq b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'and_eq' is an alternative token spelling, consider using a traditional token '&=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value &= b;{{$}}
+
+  value or_eq b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'or_eq' is an alternative token spelling, consider using a traditional token '|=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value |= b;{{$}}
+
+  value = a not_eq b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'not_eq' is an alternative token spelling, consider using a traditional token '!=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a != b;{{$}}
+
+  value xor_eq a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'xor_eq' is an alternative token spelling, consider using a traditional token '^=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value ^= a;{{$}}
+}
+
+struct Class {
+  bool operator!() const;
+  Class operator~() const;
+  bool operator&&(const Class&) const;
+  Class operator&(const Class&) const;
+  bool operator||(const Class&) const;
+  Class operator|(const Class&) const;
+  Class operator^(const Class&) const;
+  Class& operator&=(const Class&) const;
+  Class& operator|=(const Class&) const;
+  Class& operator^=(const Class&) const;
+  bool operator!=(const Class&) const;
+};
+

[clang-tools-extra] a084854 - [clang-tidy] Add readability-operators-representation check

2023-03-31 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-03-31T16:07:16Z
New Revision: a084854266ca60748982228a4c98d036bca5f762

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

LOG: [clang-tidy] Add readability-operators-representation check

Check helps enforce consistent token representation for binary, unary and
overloaded operators in C++ code. The check supports both traditional and
alternative representations of operators.

Reviewed By: carlosgalvezp

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

Added: 
clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp
clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.h

clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst

clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-alternative.cpp

clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 2306641ca9215..421698cd615f9 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -29,6 +29,7 @@ add_clang_library(clangTidyReadabilityModule
   NamedParameterCheck.cpp
   NamespaceCommentCheck.cpp
   NonConstParameterCheck.cpp
+  OperatorsRepresentationCheck.cpp
   QualifiedAutoCheck.cpp
   ReadabilityTidyModule.cpp
   RedundantAccessSpecifiersCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp
new file mode 100644
index 0..ab45dab71689a
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp
@@ -0,0 +1,335 @@
+//===--- OperatorsRepresentationCheck.cpp - clang-tidy
+//--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "OperatorsRepresentationCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/STLExtras.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static StringRef getOperatorSpelling(SourceLocation Loc, ASTContext &Context) {
+  if (Loc.isInvalid())
+return {};
+
+  SourceManager &SM = Context.getSourceManager();
+
+  Loc = SM.getSpellingLoc(Loc);
+  if (Loc.isInvalid())
+return {};
+
+  const CharSourceRange TokenRange = CharSourceRange::getTokenRange(Loc);
+  return Lexer::getSourceText(TokenRange, SM, Context.getLangOpts());
+}
+
+namespace {
+
+AST_MATCHER_P2(BinaryOperator, hasInvalidBinaryOperatorRepresentation,
+   BinaryOperatorKind, Kind, llvm::StringRef,
+   ExpectedRepresentation) {
+  if (Node.getOpcode() != Kind || ExpectedRepresentation.empty())
+return false;
+
+  StringRef Spelling =
+  getOperatorSpelling(Node.getOperatorLoc(), Finder->getASTContext());
+  return !Spelling.empty() && Spelling != ExpectedRepresentation;
+}
+
+AST_MATCHER_P2(UnaryOperator, hasInvalidUnaryOperatorRepresentation,
+   UnaryOperatorKind, Kind, llvm::StringRef,
+   ExpectedRepresentation) {
+  if (Node.getOpcode() != Kind || ExpectedRepresentation.empty())
+return false;
+
+  StringRef Spelling =
+  getOperatorSpelling(Node.getOperatorLoc(), Finder->getASTContext());
+  return !Spelling.empty() && Spelling != ExpectedRepresentation;
+}
+
+AST_MATCHER_P2(CXXOperatorCallExpr, hasInvalidOverloadedOperatorRepresentation,
+   OverloadedOperatorKind, Kind, llvm::StringRef,
+   ExpectedRepresentation) {
+  if (Node.getOperator() != Kind || ExpectedRepresentation.empty())
+return false;
+
+  StringRef Spelling =
+  getOperatorSpelling(Node.getOperatorLoc(), Finder->getASTContext());
+  return !Spelling.empty() && Spelling != ExpectedRepresentation;
+}
+
+} // namespace
+
+constexpr std::array, 2U>
+UnaryRepresentation{{{"!", "not"}, {"~", "compl"}}};
+
+constexpr std::array, 9U>
+OperatorsRepresentation{{{"&&", "and"},
+ {"||", "

[PATCH] D31308: [clang-tidy] new check readability-no-alternative-tokens

2023-03-31 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL abandoned this revision.
PiotrZSL added a comment.

Obsolete by D144522 


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

https://reviews.llvm.org/D31308

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


[PATCH] D107294: [clang-tidy] adds warning to suggest users replace symbols with words

2023-03-31 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL abandoned this revision.
PiotrZSL added a comment.

Obsolete by D144522 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107294

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


[PATCH] D145441: [AMDGPU] Define data layout entries for buffers

2023-03-31 Thread Krzysztof Drewniak via Phabricator via cfe-commits
krzysz00 updated this revision to Diff 510056.
krzysz00 edited the summary of this revision.
krzysz00 added a comment.

Per discussion on the s.buffer.load revision, don't make those changes, and so 
revert this patch back to what it used to be.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145441

Files:
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/test/CodeGen/target-data.c
  clang/test/CodeGenOpenCL/amdgpu-env-amdgcn.cl
  llvm/docs/AMDGPUUsage.rst
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/AMDGPU/AMDGPU.h
  llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/test/CodeGen/AMDGPU/GlobalISel/buffer-atomic-fadd.f32-no-rtn.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/buffer-atomic-fadd.f32-rtn.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/buffer-atomic-fadd.f64.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/buffer-atomic-fadd.v2f16-no-rtn.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/buffer-atomic-fadd.v2f16-rtn.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-non-integral-address-spaces.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.atomic.dim.a16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.dim.a16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.load.2d.d16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.load.2d.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.load.2darraymsaa.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.load.3d.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.sample.a16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.sample.d.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.sample.g16.a16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.sample.g16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.store.2d.d16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.image.atomic.dim.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.buffer.atomic.add.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.buffer.atomic.cmpswap.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.buffer.atomic.fadd-with-ret.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.buffer.atomic.fadd.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.buffer.load.format.f16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.buffer.load.format.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.buffer.load.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.buffer.store.format.f16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.buffer.store.format.f32.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.buffer.store.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.tbuffer.load.f16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.tbuffer.load.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.tbuffer.store.f16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.tbuffer.store.i8.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.raw.tbuffer.store.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.buffer.atomic.add.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.buffer.atomic.cmpswap.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.buffer.atomic.fadd-with-ret.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.buffer.atomic.fadd.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.buffer.load.format.f16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.buffer.load.format.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.buffer.load.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.buffer.store.format.f16.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.buffer.store.format.f32.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.buffer.store.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.tbuffer.load.f16.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.struct.tbuffer.load.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.image.load.1d.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.image.sample.1d.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.raw.buffer.load.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.struct.buffer.load.ll
  
llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.struct.buffer.store.ll
  llvm/test/CodeGen/AMDGPU/addrspacecast-captured.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa.ll
  llvm/test/CodeGen/AMDGPU/buffer-atomic-fadd.f32-no-rtn.ll
  llvm/test/CodeGen/AMDGPU/buffer-atomic-fadd.f32-rtn.ll
  llvm/test/CodeGen/AMDGPU/buffer-atomic-fadd.f64.ll
  llvm/test/CodeGen/AMDGPU/buffer-atomic-fadd

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-03-31 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 510057.
zequanwu marked 2 inline comments as done.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-slash.c
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/build-info.ll

Index: llvm/test/DebugInfo/COFF/build-info.ll
===
--- llvm/test/DebugInfo/COFF/build-info.ll
+++ llvm/test/DebugInfo/COFF/build-info.ll
@@ -10,6 +10,16 @@
 
 ; CHECK: {{.*}} | S_BUILDINFO [size = 8] BuildId = `[[INFO_IDX]]`
 
+; Test path is canonicalized to windows backslash style when output object file
+; name is not starting with '/'.
+; RUN: rm -rf %t-dir
+; RUN: mkdir %t-dir
+; RUN: cd %t-dir
+; RUN: llc -filetype=obj -mtriple i686-pc-windows-msvc %s -o ../build-info.o
+; RUN: llvm-readobj --codeview ../build-info.o | FileCheck %s --check-prefix=OBJ
+
+; OBJ: ObjectName: ..\build-info.o
+
 ; ModuleID = 'D:\src\scopes\foo.cpp'
 source_filename = "D:\5Csrc\5Cscopes\5Cfoo.cpp"
 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,11 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
+llvm::sys::path::Style Style =
+llvm::sys::path::is_absolute(PathRef, llvm::sys::path::Style::posix)
+? llvm::sys::path::Style::posix
+: llvm::sys::path::Style::windows_backslash;
+llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true, Style);
 PathRef = PathStore;
   }
 
Index: clang/test/CodeGen/debug-info-slash.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-pc-win32  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=WIN %s
+// RUN: %clang -target x86_64-linux-gnu  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=LINUX %s
+int main() { return 0; }
+
+// WIN:   !DIFile(filename: "{{.*}}\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}/debug-info-slash.c"
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -528,6 +528,7 @@
   // Get absolute path name.
   SourceManager &SM = CGM.getContext().getSourceManager();
   auto &CGO = CGM.getCodeGenOpts();
+  const LangOptions &LO = CGM.getLangOpts();
   std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
@@ -542,9 +543,15 @@
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
-  llvm::sys::path::append(MainFileDirSS, MainFileName);
-  MainFileName =
-  std::string(llvm::sys::path::remove_leading_dotslash(MainFileDirSS));
+  llvm::sys::path::Style Style =
+  LO.UseTargetPathSeparator
+  ? (CGM.getTarget().getTriple().isOSWindows()
+ ? llvm::sys::path::Style::windows_backslash
+ : llvm::sys::path::Style::posix)
+  : llvm::sys::path::Style::native;
+  llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
+  MainFileName = std::string(
+  llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
 }
 // If the main file name provided is identical to the input file name, and
 // if the input file is a preprocessed source, use the module name for
@@ -560,7 +567,6 @@
   }
 
   llvm::dwarf::SourceLanguage LangTag;
-  const LangOptions &LO = CGM.getLangOpts();
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
Index: clang/include/clang/Basic/LangOptions.h
===
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/LangOptions.h
@@ -479,9 +479,9 @@
   /// The seed used by the randomize structure layout feature.
   std::string RandstructSeed;
 
-  /// Indicates whether the __FILE__ macro should use the target's
-  /// platform-specific file separator or whether it should use the build
-  /// environment's platform-specific file separator.
+  /// Indicates whether to use target's platform-specific file separator when
+  /// __FILE__ macro is used and when concatenating filename with dire

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-03-31 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D147256#4236522 , @hans wrote:

> Thanks for working on this!
>
> The `-ffile-reproducible` flag name refers to making `#file` directives 
> reproducible, but `LangOptions.UseTargetPathSeparator` sounds a lot broader 
> :) I don't know what others think, but it would be nice to not have to 
> introduce any more flags at least.

Oh, I was already using `LangOptions.UseTargetPathSeparator`. Updated the 
comment on UseTargetPathSeparator.




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:544
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);

hans wrote:
> Do we want to fix absolute filenames too?
> I can see arguments for and against:
> - Using what the user provided makes sense
> - Some build systems might use absolute paths for everything. But on the 
> other hand such builds have larger determinism problems (including the full 
> paths).
> So the current decision probably makes sense.
Yeah. If it's already absolute filename, it will just use that one user 
provided. 



Comment at: clang/test/CodeGen/debug-info-slash.c:5
+
+// WIN:   !DIFile(filename: "{{.*}}clang/test/CodeGen\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}clang/test/CodeGen/debug-info-slash.c"

hans wrote:
> Does the test runner write the 'clang/test/CodeGen' path with forward slashes 
> also on Windows?
No, it uses `clang\\test\\CodeGen`. Removed this part.



Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:787
 
   StringRef PathRef(Asm->TM.Options.ObjectFilenameForDebug);
   llvm::SmallString<256> PathStore(PathRef);

hans wrote:
> This handles codeview. Does anything need to be done for dwarf on windows? 
> mstorsjo might have input on that.
It looks like `TM.Options.ObjectFilenameForDebug` is only used for codeview. I 
guess dwarf doesn't store the object file path.



Comment at: llvm/test/DebugInfo/COFF/build-info.ll:18
+; RUN: cd %t-dir
+; RUN: llc -filetype=obj -mtriple i686-pc-windows-msvc %s -o ../build-info.o
+; RUN: llvm-readobj --codeview ../build-info.o | FileCheck %s 
--check-prefix=OBJ

hans wrote:
> Does this write the .o file into the test directory? I don't think that's 
> allowed (it may be read-only). But the test could create another subdirectory 
> under `%t-dir`.
It writes the .o file into the parent directory of the temporary dir %t-dir. It 
will just be the directory path of a normal `%t`, not the source test 
directory. The reason I'm not using `%t-dir/build-info.o` in the parent dir is 
because it will be translated into an absolute address. That will remain 
unchanged in ObjectName.



Comment at: llvm/test/DebugInfo/COFF/build-info.ll:21
+
+; OBJ: ObjectName: ..\build-info.o
+

hans wrote:
> But in the `llc` invocation, the user wrote a relative path with a forward 
> slash. What behavior do we want? What should happen if there are more then 
> one slash - I think remove_dots just works on the first one?
Yeah, the input uses forward slash but we convert it into backslash. When there 
are multiple slashs, they will all be converted into backslashs, which is done 
by `llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true, 
llvm::sys::path::Style::windows_backslash);`. `remove_dots` not only remove 
redundant dots but also canonicalize path separator based on the style.

I think ideally we want just take what user provided as the ObjectName with the 
redundant dots removed. But `remove_dots` always canonicalizes the path 
separator based on the style. I don't find any function that doesn't 
canonicalize the path. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

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


[PATCH] D144522: [clang-tidy] Add readability-operators-representation check

2023-03-31 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

Thanks so much for seeing this through; I'm unusually looking forward to 
rebuilding LLVM this weekend!




Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst:82
+
+.. option:: OverloadedOperators
+

This is a great solution for ranges pipelines, which I've struggled to work out 
a good automated policy on for years.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144522

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


[clang] 758bca6 - [clang][deps] Remove -coverage-data-file and -coverage-notes-file from modules

2023-03-31 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2023-03-31T09:43:22-07:00
New Revision: 758bca6483853a743297b68bd88a5dba9d5247f2

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

LOG: [clang][deps] Remove -coverage-data-file and -coverage-notes-file from 
modules

When not performing codegen, we can strip the coverage-data-file and
coverage-notes-file options to improve canonicalization.

rdar://107443796

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

Added: 


Modified: 
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
clang/test/ClangScanDeps/removed-args.c

Removed: 




diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 8cac033742a8c..3d41e78dfc7c7 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -100,6 +100,8 @@ 
ModuleDepCollector::makeInvocationForModuleBuildWithoutOutputs(
   if (!CI.getLangOpts()->ModulesCodegen) {
 CI.getCodeGenOpts().DebugCompilationDir.clear();
 CI.getCodeGenOpts().CoverageCompilationDir.clear();
+CI.getCodeGenOpts().CoverageDataFile.clear();
+CI.getCodeGenOpts().CoverageNotesFile.clear();
   }
 
   // Map output paths that affect behaviour to "-" so their existence is in the

diff  --git a/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template 
b/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
index 2bdc340a3fccd..7ae3c88aedd8d 100644
--- a/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
+++ b/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
@@ -1,7 +1,7 @@
 [
   {
 "directory": "DIR",
-"command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps 
-fmodules-validate-once-per-build-session 
-fbuild-session-file=DIR/build-session -fmodules-prune-interval=123 
-fmodules-prune-after=123 -fmodules-cache-path=DIR/cache -include DIR/header.h 
-grecord-command-line -fdebug-compilation-dir=DIR/debug 
-fcoverage-compilation-dir=DIR/coverage -o DIR/tu.o -serialize-diagnostics 
DIR/tu.diag -MT tu -MD -MF DIR/tu.d",
+"command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps 
-fmodules-validate-once-per-build-session 
-fbuild-session-file=DIR/build-session -fmodules-prune-interval=123 
-fmodules-prune-after=123 -fmodules-cache-path=DIR/cache -include DIR/header.h 
-grecord-command-line -fdebug-compilation-dir=DIR/debug 
-fcoverage-compilation-dir=DIR/coverage -ftest-coverage -o DIR/tu.o 
-serialize-diagnostics DIR/tu.diag -MT tu -MD -MF DIR/tu.d",
 "file": "DIR/tu.c"
   }
 ]

diff  --git a/clang/test/ClangScanDeps/removed-args.c 
b/clang/test/ClangScanDeps/removed-args.c
index 02fbb8cacff2c..9a4ef25838e46 100644
--- a/clang/test/ClangScanDeps/removed-args.c
+++ b/clang/test/ClangScanDeps/removed-args.c
@@ -23,6 +23,8 @@
 // CHECK-NEXT: "-cc1"
 // CHECK-NOT:  "-fdebug-compilation-dir="
 // CHECK-NOT:  "-fcoverage-compilation-dir="
+// CHECK-NOT:  "-coverage-notes-file
+// CHECK-NOT:  "-coverage-data-file
 // CHECK-NOT:  "-dwarf-debug-flags"
 // CHECK-NOT:  "-main-file-name"
 // CHECK-NOT:  "-include"
@@ -46,6 +48,8 @@
 // CHECK-NEXT: "-cc1"
 // CHECK-NOT:  "-fdebug-compilation-dir=
 // CHECK-NOT:  "-fcoverage-compilation-dir=
+// CHECK-NOT:  "-coverage-notes-file
+// CHECK-NOT:  "-coverage-data-file
 // CHECK-NOT:  "-dwarf-debug-flags"
 // CHECK-NOT:  "-main-file-name"
 // CHECK-NOT:  "-include"



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


[PATCH] D147282: [clang][deps] Remove -coverage-data-file and -coverage-notes-file from modules

2023-03-31 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG758bca648385: [clang][deps] Remove -coverage-data-file and 
-coverage-notes-file from modules (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147282

Files:
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
  clang/test/ClangScanDeps/removed-args.c


Index: clang/test/ClangScanDeps/removed-args.c
===
--- clang/test/ClangScanDeps/removed-args.c
+++ clang/test/ClangScanDeps/removed-args.c
@@ -23,6 +23,8 @@
 // CHECK-NEXT: "-cc1"
 // CHECK-NOT:  "-fdebug-compilation-dir="
 // CHECK-NOT:  "-fcoverage-compilation-dir="
+// CHECK-NOT:  "-coverage-notes-file
+// CHECK-NOT:  "-coverage-data-file
 // CHECK-NOT:  "-dwarf-debug-flags"
 // CHECK-NOT:  "-main-file-name"
 // CHECK-NOT:  "-include"
@@ -46,6 +48,8 @@
 // CHECK-NEXT: "-cc1"
 // CHECK-NOT:  "-fdebug-compilation-dir=
 // CHECK-NOT:  "-fcoverage-compilation-dir=
+// CHECK-NOT:  "-coverage-notes-file
+// CHECK-NOT:  "-coverage-data-file
 // CHECK-NOT:  "-dwarf-debug-flags"
 // CHECK-NOT:  "-main-file-name"
 // CHECK-NOT:  "-include"
Index: clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
===
--- clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
+++ clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
@@ -1,7 +1,7 @@
 [
   {
 "directory": "DIR",
-"command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps 
-fmodules-validate-once-per-build-session 
-fbuild-session-file=DIR/build-session -fmodules-prune-interval=123 
-fmodules-prune-after=123 -fmodules-cache-path=DIR/cache -include DIR/header.h 
-grecord-command-line -fdebug-compilation-dir=DIR/debug 
-fcoverage-compilation-dir=DIR/coverage -o DIR/tu.o -serialize-diagnostics 
DIR/tu.diag -MT tu -MD -MF DIR/tu.d",
+"command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps 
-fmodules-validate-once-per-build-session 
-fbuild-session-file=DIR/build-session -fmodules-prune-interval=123 
-fmodules-prune-after=123 -fmodules-cache-path=DIR/cache -include DIR/header.h 
-grecord-command-line -fdebug-compilation-dir=DIR/debug 
-fcoverage-compilation-dir=DIR/coverage -ftest-coverage -o DIR/tu.o 
-serialize-diagnostics DIR/tu.diag -MT tu -MD -MF DIR/tu.d",
 "file": "DIR/tu.c"
   }
 ]
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -100,6 +100,8 @@
   if (!CI.getLangOpts()->ModulesCodegen) {
 CI.getCodeGenOpts().DebugCompilationDir.clear();
 CI.getCodeGenOpts().CoverageCompilationDir.clear();
+CI.getCodeGenOpts().CoverageDataFile.clear();
+CI.getCodeGenOpts().CoverageNotesFile.clear();
   }
 
   // Map output paths that affect behaviour to "-" so their existence is in the


Index: clang/test/ClangScanDeps/removed-args.c
===
--- clang/test/ClangScanDeps/removed-args.c
+++ clang/test/ClangScanDeps/removed-args.c
@@ -23,6 +23,8 @@
 // CHECK-NEXT: "-cc1"
 // CHECK-NOT:  "-fdebug-compilation-dir="
 // CHECK-NOT:  "-fcoverage-compilation-dir="
+// CHECK-NOT:  "-coverage-notes-file
+// CHECK-NOT:  "-coverage-data-file
 // CHECK-NOT:  "-dwarf-debug-flags"
 // CHECK-NOT:  "-main-file-name"
 // CHECK-NOT:  "-include"
@@ -46,6 +48,8 @@
 // CHECK-NEXT: "-cc1"
 // CHECK-NOT:  "-fdebug-compilation-dir=
 // CHECK-NOT:  "-fcoverage-compilation-dir=
+// CHECK-NOT:  "-coverage-notes-file
+// CHECK-NOT:  "-coverage-data-file
 // CHECK-NOT:  "-dwarf-debug-flags"
 // CHECK-NOT:  "-main-file-name"
 // CHECK-NOT:  "-include"
Index: clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
===
--- clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
+++ clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
@@ -1,7 +1,7 @@
 [
   {
 "directory": "DIR",
-"command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps -fmodules-validate-once-per-build-session -fbuild-session-file=DIR/build-session -fmodules-prune-interval=123 -fmodules-prune-after=123 -fmodules-cache-path=DIR/cache -include DIR/header.h -grecord-command-line -fdebug-compilation-dir=DIR/debug -fcoverage-compilation-dir=DIR/coverage -o DIR/tu.o -serialize-di

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-03-31 Thread Paul Robinson via Phabricator via cfe-commits
probinson added subscribers: debug-info, probinson.
probinson added a comment.

I think we cannot be 100% sure about source paths in a cross-compile situation. 
Cross-compiling on platform A targeting platform B does not mean your sources 
and debugger UI are on platform B. My users keep source and debugger UI on 
platform A, debugging target B remotely. We need to preserve the host 
pathnames. It is not clear to me that this patch does so.




Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:787
 
   StringRef PathRef(Asm->TM.Options.ObjectFilenameForDebug);
   llvm::SmallString<256> PathStore(PathRef);

zequanwu wrote:
> hans wrote:
> > This handles codeview. Does anything need to be done for dwarf on windows? 
> > mstorsjo might have input on that.
> It looks like `TM.Options.ObjectFilenameForDebug` is only used for codeview. 
> I guess dwarf doesn't store the object file path.
Right, DWARF only stores the source path.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

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


[PATCH] D147326: [clang][dataflow][NFC] Share code between Environment ctor and pushCallInternal().

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

Thank you!




Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:465
+  /// referenced in `FuncDecl`. `FuncDecl` must have a body.
+  void initVars(const FunctionDecl *FuncDecl);
 

xazax.hun wrote:
> I wonder if we should rename this to something like `initFieldAndGlobals`.
+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147326

___
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-03-31 Thread Haowei Wu via Phabricator via cfe-commits
haowei added a comment.

This patch (which enables assignment tracking) and D147312 
 breaks llvm runtime build for 
`runtimes-armv7-unknown-linux-gnueabihf`

Error message:

  FAILED: libcxx/src/CMakeFiles/cxx_static.dir/charconv.cpp.o 
  /b/s/w/ir/cache/goma/client/gomacc 
/b/s/w/ir/x/w/staging/llvm_build/./bin/clang++ 
--target=armv7-unknown-linux-gnueabihf --sysroot=/b/s/w/ir/x/w/cipd/linux 
-DLIBCXX_BUILDING_LIBCXXABI -D_GLIBCXX_ASSERTIONS -D_LIBCPP_BUILDING_LIBRARY 
-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS -D_LIBCPP_ENABLE_ASSERTIONS 
-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_LINK_PTHREAD_LIB 
-D_LIBCPP_LINK_RT_LIB -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/b/s/w/ir/x/w/llvm-llvm-project/libcxx/src 
-I/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1 
-I/b/s/w/ir/x/w/staging/llvm_build/include/armv7-unknown-linux-gnueabihf/c++/v1 
-I/b/s/w/ir/x/w/llvm-llvm-project/libcxxabi/include 
--target=armv7-unknown-linux-gnueabihf -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type 
-Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported 
-fdiagnostics-color -ffunction-sections -fdata-sections 
-ffile-prefix-map=/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-armv7-unknown-linux-gnueabihf-bins=../staging/llvm_build/runtimes/runtimes-armv7-unknown-linux-gnueabihf-bins
 -ffile-prefix-map=/b/s/w/ir/x/w/llvm-llvm-project/= -no-canonical-prefixes -O2 
-g -DNDEBUG -std=c++20 -fPIC -UNDEBUG -faligned-allocation -nostdinc++ 
-fvisibility-inlines-hidden -fvisibility=hidden -Wall -Wextra -Wnewline-eof 
-Wshadow -Wwrite-strings -Wno-unused-parameter -Wno-long-long 
-Werror=return-type -Wextra-semi -Wundef -Wunused-template -Wformat-nonliteral 
-Wno-user-defined-literals -Wno-covered-switch-default -Wno-suggest-override 
-Wno-error -MD -MT libcxx/src/CMakeFiles/cxx_static.dir/charconv.cpp.o -MF 
libcxx/src/CMakeFiles/cxx_static.dir/charconv.cpp.o.d -o 
libcxx/src/CMakeFiles/cxx_static.dir/charconv.cpp.o -c 
/b/s/w/ir/x/w/llvm-llvm-project/libcxx/src/charconv.cpp
  fragment covers entire variable
call void @llvm.dbg.value(metadata i32 %0, metadata !3116, metadata 
!DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !3130
  !3116 = !DILocalVariable(name: "__pred", arg: 3, scope: !3117, file: !3118, 
line: 23, type: !3121)
  fragment covers entire variable
call void @llvm.dbg.value(metadata i64 %0, metadata !3652, metadata 
!DIExpression(DW_OP_LLVM_fragment, 0, 64)), !dbg !3665
  !3652 = !DILocalVariable(name: "__pred", arg: 3, scope: !3653, file: !3118, 
line: 23, type: !3656)
  fragment covers entire variable
call void @llvm.dbg.value(metadata i32 %0, metadata !3116, metadata 
!DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !3130
  !3116 = !DILocalVariable(name: "__pred", arg: 3, scope: !3117, file: !3118, 
line: 23, type: !3121)
  fragment covers entire variable
call void @llvm.dbg.value(metadata i64 %0, metadata !3651, metadata 
!DIExpression(DW_OP_LLVM_fragment, 0, 64)), !dbg !3664
  !3651 = !DILocalVariable(name: "__pred", arg: 3, scope: !3652, file: !3118, 
line: 23, type: !3655)
  fatal error: error in backend: Broken module found, compilation aborted!
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.Program arguments: /b/s/w/ir/x/w/staging/llvm_build/./bin/clang++ 
--target=armv7-unknown-linux-gnueabihf --sysroot=/b/s/w/ir/x/w/cipd/linux 
-DLIBCXX_BUILDING_LIBCXXABI -D_GLIBCXX_ASSERTIONS -D_LIBCPP_BUILDING_LIBRARY 
-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS -D_LIBCPP_ENABLE_ASSERTIONS 
-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_LINK_PTHREAD_LIB 
-D_LIBCPP_LINK_RT_LIB -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/b/s/w/ir/x/w/llvm-llvm-project/libcxx/src 
-I/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1 
-I/b/s/w/ir/x/w/staging/llvm_build/include/armv7-unknown-linux-gnueabihf/c++/v1 
-I/b/s/w/ir/x/w/llvm-llvm-project/libcxxabi/include 
--target=armv7-unknown-linux-gnueabihf -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type 
-Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported 
-fdiagnostics-color -ffunction-sections -fdata-sections 
-ffile-prefix-map=/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-armv7-unknown-linux-gnueabihf-bins=

[PATCH] D147324: [OpenMP][MLIR][Flang][bbc][Driver] Add OpenMP RTL Flags to Flang and generate omp.FlagsAttr from them

2023-03-31 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 510080.
agozillon added a comment.

- Add FIR -> LLVM Dialect test here, more fitting than the other patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147324

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/LangOptions.def
  flang/include/flang/Tools/CrossToolHelpers.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/omp-frontend-forwarding.f90
  flang/test/Lower/OpenMP/rtl-flags.f90
  flang/tools/bbc/bbc.cpp

Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -129,6 +129,38 @@
llvm::cl::desc("enable openmp device compilation"),
llvm::cl::init(false));
 
+// A simplified subset of the OpenMP RTL Flags from Flang, only the primary
+// positive options are available, no negative options e.g. fopen_assume* vs
+// fno_open_assume*
+static llvm::cl::opt setOpenMPTargetDebug(
+"fopenmp-target-debug",
+llvm::cl::desc("Enable debugging in the OpenMP offloading device RTL"),
+llvm::cl::init(0));
+
+static llvm::cl::opt setOpenMPThreadSubscription(
+"fopenmp-assume-threads-oversubscription",
+llvm::cl::desc("Assume work-shared loops do not have more "
+   "iterations than participating threads."),
+llvm::cl::init(false));
+
+static llvm::cl::opt setOpenMPTeamSubscription(
+"fopenmp-assume-teams-oversubscription",
+llvm::cl::desc("Assume distributed loops do not have more iterations than "
+   "participating teams."),
+llvm::cl::init(false));
+
+static llvm::cl::opt setOpenMPNoThreadState(
+"fopenmp-assume-no-thread-state",
+llvm::cl::desc(
+"Assume that no thread in a parallel region will modify an ICV."),
+llvm::cl::init(false));
+
+static llvm::cl::opt setOpenMPNoNestedParallelism(
+"fopenmp-assume-no-nested-parallelism",
+llvm::cl::desc("Assume that no thread in a parallel region will encounter "
+   "a parallel region."),
+llvm::cl::init(false));
+
 static llvm::cl::opt enableOpenACC("fopenacc",
  llvm::cl::desc("enable openacc"),
  llvm::cl::init(false));
@@ -244,8 +276,13 @@
   kindMap, loweringOptions, {});
   burnside.lower(parseTree, semanticsContext);
   mlir::ModuleOp mlirModule = burnside.getModule();
-  if (enableOpenMP)
-setOffloadModuleInterfaceAttributes(mlirModule, enableOpenMPDevice);
+  if (enableOpenMP) {
+auto offloadModuleOpts =
+OffloadModuleOpts(setOpenMPTargetDebug, setOpenMPTeamSubscription,
+  setOpenMPThreadSubscription, setOpenMPNoThreadState,
+  setOpenMPNoNestedParallelism, enableOpenMPDevice);
+setOffloadModuleInterfaceAttributes(mlirModule, offloadModuleOpts);
+  }
   std::error_code ec;
   std::string outputName = outputFilename;
   if (!outputName.size())
Index: flang/test/Lower/OpenMP/rtl-flags.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/rtl-flags.f90
@@ -0,0 +1,64 @@
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DEFAULT-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefix=DEFAULT-HOST-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-target-debug -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DBG-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-target-debug=111 -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DBG-EQ-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-teams-oversubscription -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=TEAMS-OSUB-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-threads-oversubscription -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=THREAD-OSUB-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-no-thread-state -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=THREAD-STATE-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-no-nested-parallelism -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=NEST-PAR-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-target-debug -fopenmp-assume-teams-oversubscription -fopenmp-assume-no-nested-parallelism -fopenmp-assume-threads-oversubscription -fopenmp-assume-no-thread-state -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=ALL-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | fir-opt --fir-to-llvm-ir | FileCheck %s  --check-prefix=DEFAULT-HOST-LLVMDIALECT
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | fir-opt -

[PATCH] D141389: [DFSAN] Add support for strnlen, strncat, strsep, sscanf and _tolower

2023-03-31 Thread Andrew via Phabricator via cfe-commits
browneee added a comment.

We're getting really close!

Yes, that build error looks unrelated. Someone should fix it soon.




Comment at: compiler-rt/lib/dfsan/dfsan_custom.cpp:221
+  if (flags().strict_data_dependencies) {
+*ret_label = res ? dfsan_read_label(base, sizeof(base)) : 0;
+  } else {

`base, sizeof(base)` does not make sense - the size does not correspond to the 
pointer used.

Either
```
dfsan_read_label(base, sizeof(*base))   // first byte pointed to by base
dfsan_read_label(base, strlen(base)) // whole string pointed to by base
dfsan_read_label(&base, sizeof(base))  // the base pointer
```

In this case I think we want the base pointer.

`dfsan_read_label(&base, sizeof(base))`  // the base pointer
should be equivalent to doing
`dfsan_label base_label = dfsan_read_label(s, sizeof(*s))`  up at the start of 
the function, just after we declare base then use `base_label` here.

Lets go with the second option to avoid taking the address of a variable.

This is semantically equivalent to my first suggestion: `dfsan_get_label(base) 
== dfsan_read_label(&base, sizeof(base)) == base_label`.
Sorry I didn't consider the other constraints (no dfsan_get_label in this file 
because the pass is not run on this code; avoid taking address of variable) and 
suggest this in the first place.



Comment at: compiler-rt/lib/dfsan/dfsan_custom.cpp:224
+*ret_label =
+dfsan_union(dfsan_read_label(base, sizeof(base)),
+dfsan_union(dfsan_read_label(delim, strlen(delim) + 1),

Also use `base_label` here.



Comment at: compiler-rt/lib/dfsan/dfsan_custom.cpp:240
+if (res)
+  *ret_origin = dfsan_read_origin_of_first_taint(base, strlen(base));
+  } else {

`dfsan_get_origin(base) == dfsan_read_origin_of_first_taint(&base, 
sizeof(base))`

As noted above `base, strlen(base)` is a meaningfully valid pointer, length - 
but it is not the level of indirection we want here.

I think we want the same solution as above.

`dfsan_origin base_origin = dfsan_read_origin_of_first_taint(s, sizeof(*s))` at 
the start of the function, just after declaring and assigning base.



Comment at: compiler-rt/lib/dfsan/dfsan_custom.cpp:243
+if (*ret_label) {
+  dfsan_origin o = dfsan_read_origin_of_first_taint(base, strlen(base));
+  if (o) {

Also use `base_origin` here.



Comment at: compiler-rt/test/dfsan/custom.cpp:1641
+  // taint delim pointer
+  dfsan_set_label(j_label, &p_delim, sizeof(&p_delim));
+  // taint the string data bytes

remove the &

It still works because `sizeof(pointer_var) == sizeof(&pointer_var)`, but it 
doesn't logically match up like it should.

(Sorry, this one is my fault - I made this mistake giving an example in an 
earlier comment.)



Comment at: compiler-rt/test/dfsan/custom.cpp:1645
+  // taint the string pointer
+  dfsan_set_label(m_label, &p_s, sizeof(&p_s));
+

remove & in sizeof



Comment at: compiler-rt/test/dfsan/custom.cpp:1650
+#ifdef STRICT_DATA_DEPENDENCIES
+  ASSERT_LABEL(rv, k_label);
+  ASSERT_READ_LABEL(rv, strlen(rv), k_label);

The value `rv` has a data flow from the the string pointer, not the string 
bytes.
It should have `m_label` not `k_label`.

This is related to line 221 (using `base` instead of `&base`) in the other file.



Comment at: compiler-rt/test/dfsan/custom.cpp:1654
+  ASSERT_LABEL(rv, dfsan_union(dfsan_union(i_label, j_label), k_label));
+  ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, *s);
+#endif

rv is a pointer, and I think it's origin should match the pointer s, not the 
bytes in the string.

I think this should be:

`ASSERT_INIT_ORIGIN_EQ_ORIGIN(&rv, s);`

This is related to line 240 (`*ret_origin = 
dfsan_read_origin_of_first_taint(base, strlen(base));`) in the other file being 
the wrong level of indirection.


(Side note: the existing ASSERT_INIT_ORIGIN_EQ_ORIGIN macro feels a bit odd in 
that the arguments are at different levels of indirection - but not something 
to fix as part of this change)



Comment at: compiler-rt/test/dfsan/custom.cpp:1660
+  char **pp_s_base = pp_s;
+  dfsan_set_label(n_label, &pp_s, sizeof(&pp_s));
+

remove & in sizeof


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

https://reviews.llvm.org/D141389

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-03-31 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D147256#4237099 , @probinson wrote:

> I think we cannot be 100% sure about source paths in a cross-compile 
> situation. Cross-compiling on platform A targeting platform B does not mean 
> your sources and debugger UI are on platform B. My users keep source and 
> debugger UI on platform A, debugging target B remotely. We need to preserve 
> the host pathnames. It is not clear to me that this patch does so.

I believe the idea is to preserve host pathnames as long as 
`LangOptions.UseTargetPathSeparator` is unset. But I see that might not be the 
case for `CodeViewDebug::emitObjName()` in the current version of the patch. 
Could we make clang handle that path instead depending on the flag?




Comment at: llvm/test/DebugInfo/COFF/build-info.ll:18
+; RUN: cd %t-dir
+; RUN: llc -filetype=obj -mtriple i686-pc-windows-msvc %s -o ../build-info.o
+; RUN: llvm-readobj --codeview ../build-info.o | FileCheck %s 
--check-prefix=OBJ

zequanwu wrote:
> hans wrote:
> > Does this write the .o file into the test directory? I don't think that's 
> > allowed (it may be read-only). But the test could create another 
> > subdirectory under `%t-dir`.
> It writes the .o file into the parent directory of the temporary dir %t-dir. 
> It will just be the directory path of a normal `%t`, not the source test 
> directory. The reason I'm not using `%t-dir/build-info.o` in the parent dir 
> is because it will be translated into an absolute address. That will remain 
> unchanged in ObjectName.
Right, I'm just thinking that we can't be sure that we can (or should) write 
files into the parent of `%t-dir`.

Would it work if you instead create `%t-dir/subdir`, `cd` into that, and then 
do `-o ../build-info.o`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

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


[PATCH] D145264: [OpenMP][MLIR][Flang][Driver][bbc] Lower and apply Module FlagsAttr

2023-03-31 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

Fragmented this patch into https://reviews.llvm.org/D147344 (lowering) and 
https://reviews.llvm.org/D147324 (driver/tool changes and application of 
attribute). I will keep this patch open until the others are closed to give a 
big picture for easier reference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

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


[PATCH] D146595: [clang] Add "transparent_stepping" attribute

2023-03-31 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

I think `debug_trampoline` both captures the semantics and makes it clear that 
this is related to debugging.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146595

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


[PATCH] D143467: [PowerPC] Add target feature requirement to builtins

2023-03-31 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp added a comment.

Overall I think that this looks fine to me as well.
I had a couple of minor comments and you may decide that you don't need to do 
either one so if that's the case just mention why in a comment and I will 
approve the patch.




Comment at: clang/include/clang/Basic/BuiltinsPPC.def:987
+
+UNALIASED_CUSTOM_BUILTIN(mma_assemble_acc, "vW512*", false, "mma")
+UNALIASED_CUSTOM_BUILTIN(mma_disassemble_acc, "vv*W512*", false, "mma")

Based on the original implementation in `SemaBuiltinPPCMMACall` all of the 
`mma` builtins also require `paired-vector-memops`. 
Is this something that we still need?



Comment at: clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-test.c:47
 
-int test_test_data_class_f() {
-// CHECK-LABEL:   @test_test_data_class_f
-// CHECK: [[TMP:%.*]] = call i32 
@llvm.ppc.test.data.class.f32(float %0, i32 127)
-// CHECK-NEXT:ret i32 [[TMP]]
-// CHECK-NONPWR9-ERR: error: this builtin is only valid on POWER9 or later CPUs
-// CHECK-NOVSX-ERR: error: this builtin requires VSX to be enabled
-  return __test_data_class(f, 127);
+// CHECK-NOVSX-ERR: error: '__builtin_ppc_compare_exp_uo' needs target feature 
isa-v30-instructions,vsx
+// CHECK-NOVSX-ERR: error: '__builtin_ppc_compare_exp_lt' needs target feature 
isa-v30-instructions,vsx

nit:
Should this be 
```
... needs target feature vsx
```
Instead of listing them both?

Fixing this might be more trouble than it's worth because you would have to 
edit `CodeGenFunction::checkTargetFeatures`. I just thought I would mention it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143467

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


[clang] 43825d1 - Revert "[Assignment Tracking] Enable by default"

2023-03-31 Thread Haowei Wu via cfe-commits

Author: Haowei Wu
Date: 2023-03-31T11:27:18-07:00
New Revision: 43825d19318695be48abe6f042369da00fbb808b

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

LOG: Revert "[Assignment Tracking] Enable by default"

This reverts commit aa32490bfe0b957c4f5583e14304f5e34b2b9bce, which
breaks llvm runtimes builds on armv7 linux.

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 11007c99aa691..0cc7052b67105 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5800,7 +5800,7 @@ def experimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignmen
   Group, CodeGenOpts<"EnableAssignmentTracking">,
   NormalizedValuesScope<"CodeGenOptions::AssignmentTrackingOpts">,
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
-  MarshallingInfoEnum, "Enabled">;
+  MarshallingInfoEnum, "Disabled">;
 
 } // let Flags = [CC1Option, NoDriverOption]
 

diff  --git a/clang/test/CodeGen/assignment-tracking/flag.cpp 
b/clang/test/CodeGen/assignment-tracking/flag.cpp
index 3bd974fe07c6c..aa1f054dae4d7 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
 
- Enabled by default:
+ Disabled 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=ENABLE
+// RUN: | FileCheck %s --check-prefixes=DISABLE
 
  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] D143467: [PowerPC] Add target feature requirement to builtins

2023-03-31 Thread Amy Kwan via Phabricator via cfe-commits
amyk added a comment.

Overall looks OK to me, as well. I just had two questions that I wanted to ask.




Comment at: clang/include/clang/Basic/BuiltinsPPC.def:444
+TARGET_BUILTIN(__builtin_altivec_vcmpnew_p, "iiV4iV4i", "", "power9-vector")
+TARGET_BUILTIN(__builtin_altivec_vcmpned_p, "iiV2LLiV2LLi", "", "altivec")
+

Does this need to be `vsx`?



Comment at: clang/include/clang/Basic/BuiltinsPPC.def:820
+TARGET_BUILTIN(__builtin_vsx_xvcvspbf16, "V16UcV16Uc", "", "power10-vector")
+TARGET_BUILTIN(__builtin_vsx_xvcvbf16spn, "V16UcV16Uc", "", "vsx")
 

Should this be `power10-vector`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143467

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


[PATCH] D144603: Disable compiler launcher on external projects and multi stage clang

2023-03-31 Thread David Fang via Phabricator via cfe-commits
fangism added a comment.

What's the current status of this changeset?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144603

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


[PATCH] D147349: [C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

2023-03-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: jyknight, efriedma, erichkeane, cor3ntin, 
clang-language-wg.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

This implements support for allowing `{}` to consistently zero initialize 
objects. We already supported most of this work as a GNU extension, but the C2x 
feature goes beyond what the GNU extension allowed.

The changes in this patch are:

- Removed the `-Wgnu-empty-initializer` warning group. The extension is now a 
C2x extension warning instead. Note that use of `-Wno-gnu-empty-initializer` 
seems to be quite low in the wild 
(https://sourcegraph.com/search?q=context%3Aglobal+-file%3A.*test.*+%22-Wno-gnu-empty-initializer%22&patternType=standard&sm=1&groupBy=repo
 which currently only gives 8 hits total), so this is not expected to be an 
overly disruptive change. But I'm adding the clang vendors review group just in 
case this expectation is wrong.
- Reworded the diagnostic wording to be about a C2x extension, added a pre-C2x 
compat warning
- Allow `{}` to zero initialize a VLA

This functionality is exposed as an extension in all older C modes (same as the 
GNU extension was), but does *not* allow the extension for VLA initialization 
in C++ due to concern about handling non-trivially constructible types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147349

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/C/C2x/n2900_n3011.c
  clang/test/C/C2x/n2900_n3011_2.c
  clang/test/Sema/complex-init-list.c
  clang/test/Sema/flexible-array-init.c
  clang/test/Sema/gnu-flags.c
  clang/test/Sema/sizeless-1.c
  clang/test/Sema/vla.c
  clang/test/SemaObjC/property.m
  clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1083,11 +1083,11 @@
 

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2900.htm";>N2900
-Unknown
+Clang 17
   

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3011.htm";>N3011
-Unknown
+Clang 17
   
 
   Not-so-magic: typeof
Index: clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
===
--- clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
+++ clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
@@ -28,37 +28,34 @@
   intel_sub_group_avc_sic_result_t result_sic = ss;
   intel_sub_group_avc_ime_result_single_reference_streamout_t sstreamout = v;
   intel_sub_group_avc_ime_result_dual_reference_streamout_t dstreamin_list = {0x0, 0x1};
-  intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list2 = {};
   intel_sub_group_avc_ime_single_reference_streamin_t dstreamin_list3 = {c};
   intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list4 = {1};
 #ifdef EXT
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_result_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_result_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_single_reference_streamout_t' with an expression of incompatible type '__private void *__private'}}
-// expected-warning@-14 {{excess elements in struct initializer}}
-// expected-error@-14 {{scalar initializer cannot be empty}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_single_reference_streamin_t' with an expression of incompatible type '__private char'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_dual_reference_streamin_t' with an exp

[PATCH] D147349: [C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

2023-03-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 510099.
aaron.ballman added a comment.

Oops, previous diff missed a change that was only locally staged. Fixed.


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

https://reviews.llvm.org/D147349

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/C/C2x/n2900_n3011.c
  clang/test/C/C2x/n2900_n3011_2.c
  clang/test/Sema/complex-init-list.c
  clang/test/Sema/flexible-array-init.c
  clang/test/Sema/gnu-flags.c
  clang/test/Sema/sizeless-1.c
  clang/test/Sema/vla.c
  clang/test/SemaObjC/property.m
  clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1083,11 +1083,11 @@
 

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2900.htm";>N2900
-Unknown
+Clang 17
   

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3011.htm";>N3011
-Unknown
+Clang 17
   
 
   Not-so-magic: typeof
Index: clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
===
--- clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
+++ clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
@@ -28,37 +28,34 @@
   intel_sub_group_avc_sic_result_t result_sic = ss;
   intel_sub_group_avc_ime_result_single_reference_streamout_t sstreamout = v;
   intel_sub_group_avc_ime_result_dual_reference_streamout_t dstreamin_list = {0x0, 0x1};
-  intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list2 = {};
   intel_sub_group_avc_ime_single_reference_streamin_t dstreamin_list3 = {c};
   intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list4 = {1};
 #ifdef EXT
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_result_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_result_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_single_reference_streamout_t' with an expression of incompatible type '__private void *__private'}}
-// expected-warning@-14 {{excess elements in struct initializer}}
-// expected-error@-14 {{scalar initializer cannot be empty}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_single_reference_streamin_t' with an expression of incompatible type '__private char'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_dual_reference_streamin_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ref_result_t' with an expression of incompatible type '__private float'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_sic_result_t' with an expression of incompatible type '__private struct st'}}
+// expected-error@-13 {{initializing '

[PATCH] D143467: [PowerPC] Add target feature requirement to builtins

2023-03-31 Thread Maryam Moghadas via Phabricator via cfe-commits
maryammo added a comment.

It looks good to me, just added a minor question as I was not able to verify 
that.




Comment at: clang/include/clang/Basic/BuiltinsPPC.def:444
+TARGET_BUILTIN(__builtin_altivec_vcmpnew_p, "iiV4iV4i", "", "power9-vector")
+TARGET_BUILTIN(__builtin_altivec_vcmpned_p, "iiV2LLiV2LLi", "", "altivec")
+

amyk wrote:
> Does this need to be `vsx`?
How do we find the appropriate FEATURE for the above 4 builtins?  (first 3 are 
p9 and the 4th one is altivec)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143467

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


[PATCH] D147288: [clang][NFC] updates cxx_status for P2113R0

2023-03-31 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

There was some discussion of this last year in this review: 
https://reviews.llvm.org/D128750

It's such an edge case that I don't think we should lose sleep about it 
until/unless the committee finds time to clarify the issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147288

___
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-03-31 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/include/clang/Format/Format.h:949
+  /// If unset, ``ContinuationIndentWidth`` is used.
+  /// \code
+  ///   AlignAfterOpenBracket: AlwaysBreak

jp4a50 wrote:
> MyDeveloperDay wrote:
> > did you check generating the html from the rst? I can never remember if we 
> > need a newline before the \code
> Nope - how do I do that exactly? I would guess a newline is not needed based 
> on other examples.
> did you check generating the html from the rst? I can never remember if we 
> need a newline before the \code





Comment at: clang/lib/Format/ContinuationIndenter.cpp:1659
   opensProtoMessageField(Current, Style)) {
+const FormatToken *NextNonComment = Current.getNextNonComment();
 if (Current.opensBlockOrBlockTypeList(Style)) {

Why did you move it?



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1664-1668
+  const auto BracedInitializerIndentWidth =
+  Style.BracedInitializerIndentWidth
+  ? *Style.BracedInitializerIndentWidth
+  : Style.ContinuationIndentWidth;
+  NewIndent = CurrentState.LastSpace + BracedInitializerIndentWidth;

You can keep the local variable if you want, but please use `value_or`, it 
expresses the intent better.


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] D147327: [clang-format] Add option for having one port per line in Verilog

2023-03-31 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks requested changes to this revision.
HazardyKnusperkeks added inline comments.
This revision now requires changes to proceed.



Comment at: clang/include/clang/Format/Format.h:4185
+  /// For Verilog, put each port on its own line in module instantiations.
+  /// \code
+  ///ffnand ff1(.q(),

Can you put the true vs. false in the doc, like on other options?



Comment at: clang/include/clang/Format/Format.h:4192
+  /// \version 17
+  bool VerilogBreakBetweenInstancePorts;
+

V after U



Comment at: clang/lib/Format/TokenAnnotator.cpp:1150
+  if (Style.isVerilog()) {
+const FormatToken *Prev = Tok->getPreviousNonComment(), *Prev2;
+// Identify the parameter list and port list in a module instantiation.





Comment at: clang/lib/Format/TokenAnnotator.cpp:1156-1163
+if (Prev && (Prev2 = Prev->getPreviousNonComment()) &&
+((Prev->is(tok::hash) && Keywords.isVerilogIdentifier(*Prev2)) ||
+ (Keywords.isVerilogIdentifier(*Prev) &&
+  (Prev2->is(tok::r_paren) ||
+   Keywords.isVerilogIdentifier(*Prev2) ||
+   (Prev2->endsSequence(tok::comma, tok::r_paren) &&
+(Prev2 = Prev2->getPreviousNonComment()->MatchingParen) &&

I won't read that.

I think you should go with multiple if statements.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147327

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


  1   2   >