[PATCH] D140462: [clangd] Add schema for `.clangd` config

2023-01-09 Thread Edwin Kofler via Phabricator via cfe-commits
hyperupcall marked 2 inline comments as done.
hyperupcall added a comment.

In D140462#4018983 , @sammccall wrote:

> The difficulty in testing is that:
>
> - JSON-schema is totally unknown in llvm-project, so there are no tools but 
> also no expectation that contributors understand it
> - llvm-project doesn't like dependencies, particularly those that aren't in 
> C++ or python
> - having done some digging, interop seems really poor...
>
> I tried 3 consumers (`ajv-cli`, `yaml-language-server`, and `yajsv`) and 
> **hit different blocking bugs in all of them** when using obvious, 
> spec-compliant approaches to writing schemas. I only have experience with 
> `ajv`, so I suppose it means



> It has the "python problem", where it's readable and you can see at a glance 
> why the code is correct - even if it isn't.
> (Having spent a couple of days with json-schema now, I **don't** think it's 
> straightforward. That file seems simple so far, but there are simple C++ 
> programs too! And it carefully dodges the interop issues, which is *subtle*).

I appreciate that you took the time to experiment with those three 
implementations of JSON-schema - perhaps I was naive in thinking that the 
different implementations were more mature. On my side, this makes me want to 
validate the various schemas in SchemaStore with more implementations than just 
`ajv` to improve the experience for everyone.

> ---
>
> Fixing this is an unreasonable burden to place on a new contributor, I've 
> taken a shot at this and have something almost working: 
> https://reviews.llvm.org/D140745.
>
> It's pretty draft-ish:
>
> - That patch just checks in the generated files {`Fragment.inc`, `YAML.inc`, 
> `doc.md`, `schema.json`}, (maybe) that belongs in the build system
> - the schema is correct but `yaml-language-server` chokes on it due to 
> https://github.com/redhat-developer/yaml-language-server/issues/823, so need 
> to restructure
> - files would need to be moved around etc
> - tests need to be added/updated
> - i'm not sure whether having a json-schema for `schema.yaml` is actually a 
> good idea, it was mostly a learning exercise

This looks pretty neat! I think something like that revision would be a better 
way forward. I will go ahead and upload a new Diff, I suppose just for 
completeness, but I don't expect anything to change much since it doesn't 
address your points about syncing with documentation or the obscurity of the 
specification.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140462

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


[PATCH] D141226: [clangd] support expanding `decltype(expr)`

2023-01-09 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 487704.
v1nh1shungry added a comment.

avoid expanding pointer to an array


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141226

Files:
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandDeducedType.cpp
  clang-tools-extra/clangd/test/check-fail.test
  clang-tools-extra/clangd/test/check-lines.test
  clang-tools-extra/clangd/test/check.test
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/test/request-reply.test
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
  clang/docs/tools/clang-formatted-files.txt
  llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
@@ -129,7 +129,7 @@
 "tweaks/DumpASTTests.cpp",
 "tweaks/DumpRecordLayoutTests.cpp",
 "tweaks/DumpSymbolTests.cpp",
-"tweaks/ExpandAutoTypeTests.cpp",
+"tweaks/ExpandDeducedTypeTests.cpp",
 "tweaks/ExpandMacroTests.cpp",
 "tweaks/ExtractFunctionTests.cpp",
 "tweaks/ExtractVariableTests.cpp",
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
@@ -18,7 +18,7 @@
 "DefineInline.cpp",
 "DefineOutline.cpp",
 "DumpAST.cpp",
-"ExpandAutoType.cpp",
+"ExpandDeducedType.cpp",
 "ExpandMacro.cpp",
 "ExtractFunction.cpp",
 "ExtractVariable.cpp",
Index: clang/docs/tools/clang-formatted-files.txt
===
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -1611,7 +1611,7 @@
 clang-tools-extra/clangd/unittests/tweaks/DumpASTTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/DumpRecordLayoutTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/DumpSymbolTests.cpp
-clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/ExpandMacroTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
Index: clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
===
--- clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
+++ clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
@@ -25,9 +25,9 @@
 // Fixture base for testing tweaks. Intended to be subclassed for each tweak.
 //
 // Usage:
-// TWEAK_TEST(ExpandAutoType);
+// TWEAK_TEST(ExpandDeducedType);
 //
-// TEST_F(ExpandAutoTypeTest, ShortensTypes) {
+// TEST_F(ExpandDeducedTypeTest, ShortensTypes) {
 //   Header = R"cpp(
 // namespace foo { template class X{}; }
 // using namespace foo;
Index: clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
@@ -1,4 +1,4 @@
-//===-- ExpandAutoTypeTests.cpp -*- C++ -*-===//
+//===-- ExpandDeducedTypeTests.cpp --*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -16,9 +16,9 @@
 namespace clangd {
 namespace {
 
-TWEAK_TEST(ExpandAutoType);
+TWEAK_TEST(ExpandDeducedType);
 
-TEST_F(ExpandAutoTypeTest, Test) {
+TEST_F(ExpandDeducedTypeTest, Test) {
   Header = R"cpp(
 namespace ns {
   struct Class {
@@ -50,7 +50,10 @@
   StartsWith("fail: Could not deduce type for 'auto' type"));
   // function pointers should not be replaced
   EXPECT_THAT(apply("au^to x = ::Func;"),
-  StartsWith("fail: Could not expand type of function pointer"));
+  StartsWith("fail: Could not expand type of function"));
+  // function references should not be replaced
+  EXPECT_THAT(apply("au^to  = ns::Func;"),
+  

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-01-09 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 487702.
pmatos added a comment.

Rebase on top of main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/TypeBitCodes.def
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGValue.h
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/builtins-table.c
  clang/test/CodeGen/WebAssembly/table.c
  clang/test/Sema/builtins-wasm.c
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaCXX/wasm-refs.cpp
  llvm/include/llvm/CodeGen/WasmAddressSpaces.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
@@ -62,8 +62,9 @@
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
 PtrToIntInst *PTI = dyn_cast(&*I);
 IntToPtrInst *ITP = dyn_cast(&*I);
-if (!(PTI && WebAssembly::isRefType(PTI->getPointerOperand()->getType())) &&
-!(ITP && WebAssembly::isRefType(ITP->getDestTy(
+if (!(PTI &&
+  PTI->getPointerOperand()->getType()->isWebAssemblyReferenceType()) &&
+!(ITP && ITP->getDestTy()->isWebAssemblyReferenceType()))
   continue;
 
 UndefValue *U = UndefValue::get(I->getType());
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1202,7 +1202,7 @@
   // Lastly, if this is a call to a funcref we need to add an instruction
   // table.set to the chain and transform the call.
   if (CLI.CB &&
-  WebAssembly::isFuncrefType(CLI.CB->getCalledOperand()->getType())) {
+  CLI.CB->getCalledOperand()->getType()->isWebAssemblyFuncrefType()) {
 // In the absence of function references proposal where a funcref call is
 // lowered to call_ref, using reference types we generate a table.set to set
 // the funcref to a special table used solely for this purpose, followed by
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -45,43 +45,6 @@
   Multivalue = 0x,
 };
 
-enum WasmAddressSpace : unsigned {
-  // Default address space, for pointers to linear memory (stack, heap, data).
-  WASM_ADDRESS_SPACE_DEFAULT = 0,
-  // A non-integral address space for pointers to named objects outside of
-  // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
-  // to these pointers are lowered to global.get / global.set or local.get /
-  // local.set, as appropriate.
-  WASM_ADDRESS_SPACE_VAR = 1,
-  // A non-integral address space for externref values
-  WASM_ADDRESS_SPACE_EXTERNREF = 10,
-  // A non-integral address space for funcref values
-  WASM_ADDRESS_SPACE_FUNCREF = 20,
-};
-
-inline bool isDefaultAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_DEFAULT;
-}
-inline bool isWasmVarAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_VAR;
-}
-inline bool isValidAddressSpace(unsigned AS) {
-  return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
-}
-inline bool isFuncrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
-}
-inline bool isExternrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- 

[PATCH] D128440: [WebAssembly] Initial support for reference type funcref in clang

2023-01-09 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 487700.
pmatos added a comment.

Rebase on top of main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128440

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Format/FormatToken.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/wasm-funcref.c
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388586)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x7FFFEA>();
+  correct<0x7FFFE9>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650L>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/CodeGen/WebAssembly/wasm-funcref.c
===
--- /dev/null
+++ clang/test/CodeGen/WebAssembly/wasm-funcref.c
@@ -0,0 +1,84 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -o - -emit-llvm %s | FileCheck %s
+
+typedef void (*__funcref funcref_t)();
+typedef int (*__funcref fn_funcref_t)(int);
+typedef int (*fn_t)(int);
+
+// Null funcref builtin call
+// CHECK-LABEL: @get_null(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+funcref_t get_null() {
+  return __builtin_wasm_ref_null_func();
+}
+
+// Call to null funcref builtin but requires cast since
+// default return value for builtin is a funcref with function type () -> ().
+// CHECK-LABEL: @get_null_ii(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+fn_funcref_t get_null_ii() {
+  return (fn_funcref_t) __builtin_wasm_ref_null_func();
+}
+
+// Identity function for funcref.
+// CHECK-LABEL: @identity(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT:store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+funcref_t identity(funcref_t fn) {
+  return fn;
+}
+
+void helper(funcref_t);
+
+// Pass funcref ref as an argument to a helper function.
+// CHECK-LABEL: @handle(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT:store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:call void @helper(ptr addrspace(20) noundef [[TMP0]])
+// CHECK-NEXT:ret i32 0
+//
+int handle(funcref_t fn) {
+  helper(fn);
+  return 0;
+}
+
+// Return funcref from function pointer.
+// CHECK-LABEL: @get_ref(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FNPTR_ADDR:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:store ptr [[FNPTR:%.*]], ptr [[FNPTR_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[FNPTR_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = addrspacecast ptr [[TMP0]] to ptr addrspace(20)
+// CHECK-NEXT:ret ptr addrspace(20) 

[PATCH] D140307: [clang-tidy] Match derived types in in modernize-loop-convert

2023-01-09 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Hi! I'm finding merge conflicts when rebasing the patch on latest trunk, would 
you mind uploading a rebased version? Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140307

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


[PATCH] D139168: [C++20] [Modules] [ClangScanDeps] Enable to print make-style dependency file within P1689 format (4/4)

2023-01-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D139168#4036850 , @tahonermann 
wrote:

>> Header units have even more need to be involved in the build graph than 
>> named units. ODR violations and cache invalidation problems await anyone 
>> just winging it on header units (at least that's the understanding I've 
>> gotten from SG15 meetings).
>
> I think that latter claim applies equally to all module units. The ODR 
> violation and cache invalidation concerns sometimes associated with header 
> units occur in implicit module build systems in which a header unit might be 
> built multiple times with different sets of options that result in an ODR 
> violation. The same problem can occur with other kinds of module units if 
> they are built multiple times with different options and then imported by 
> distinct TUs that are then linked together. The general rule is, given a set 
> of TUs that will be linked together, all imported module units should be 
> built exactly one time.

I think the option set will be naturally a unique set for a single module-unit 
since a module-unit is an actual translation unit. But the header units are 
synthesized units so it is not the same case.

I am pretty interested about the topic indeed but I guess we'd better to find 
another place to discuss this.




Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:775
+static llvm::StringMap OSs;
+std::unique_lock LockGuard(Lock);
+

jansvoboda11 wrote:
> How will this work when a different process tries to write the same file? 
> Could we write into a temporary file and then do atomic rename?
It may be problematic if another process tries to write the same file at the 
same time. But I feel it is an overkill to defend such cases otherwise many 
existing codes need to be refactored.


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

https://reviews.llvm.org/D139168

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked 3 inline comments as done.
ChuanqiXu added a comment.

> I originally investigated (and ended up lost) for something like GCC where 
> P1689  information is extracted via -E 
> -fdep-file=p1689.json -fdep-output=module.o -fdep-format=p1689 (which is 
> "abusing" -E, but works), but using clang-scan-deps was where we ended up 
> after a more-knowledgeable LLVM developer took over knowing what needed to be 
> done.

Yeah, I believe the clang-scan-deps would be the better option and according to 
the talk of `clang-scan-deps` 
(https://llvm.org/devmtg/2019-04/slides/TechTalk-Lorenz-clang-scan-deps_Fast_dependency_scanning_for_explicit_modules.pdf),
 it is also the goal of `clang-scan-deps` to support c++20 modules.




Comment at: clang/test/ClangScanDeps/P1689.cppm:11
+// RUN: clang-scan-deps -format=p1689 \
+// RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/M.cppm -o 
%t/M.o \
+// RUN:   | FileCheck %t/M.cppm -DPREFIX=%/t

jansvoboda11 wrote:
> I'm fairly happy with the `clang-scan-deps` interface now (besides the 
> performance aspect mentioned in another comment).
> 
> @ChuanqiXu what would happen if you run this Clang command line directly?
> what would happen if you run this Clang command line directly?

I remember this refers to `%clang++ -std=c++20 -c -fprebuilt-module-path=%t 
%t/M.cppm -o %t/M.o` previously. 

And if we run this clang command line directly, it will compile the module-unit 
`M.cppm` into object files if all its dependent precompiled module files lives 
in the directory `%t`. The command line should be what will run actually.



Comment at: clang/test/ClangScanDeps/P1689.cppm:9
+//
+// Check the seperated dependency format.
+// RUN: clang-scan-deps -format=p1689 --p1689-targeted-file-name=%t/M.cppm 
--p1689-targeted-output=%t/M.o \

jansvoboda11 wrote:
> ben.boeckel wrote:
> > jansvoboda11 wrote:
> > > What does "separated" mean in this context?
> > Yeah, this isn't the right term. There are two things being done:
> > 
> > - discovering dependencies for a future compile (P1689)
> > - collecting deps for the scanning itself to know that "if included file X 
> > changes, I need to rescan"
> > 
> > Both are required for correct builds.
> @ChuanqiXu Can you write up a better comment here?
I've updated the comments to tell it is required for non-exist and potentially 
out-of-date files.


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

https://reviews.llvm.org/D137534

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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2023-01-09 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 487693.
pmatos added a comment.

Rebasing on top of main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/SemaCXX/wasm-refs.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/include/llvm/Transforms/Utils.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/lib/Transforms/Utils/Mem2Reg.cpp

Index: llvm/lib/Transforms/Utils/Mem2Reg.cpp
===
--- llvm/lib/Transforms/Utils/Mem2Reg.cpp
+++ llvm/lib/Transforms/Utils/Mem2Reg.cpp
@@ -74,15 +74,19 @@
 struct PromoteLegacyPass : public FunctionPass {
   // Pass identification, replacement for typeid
   static char ID;
+  bool ForcePass; /// If true, forces pass to execute, instead of skipping.
 
-  PromoteLegacyPass() : FunctionPass(ID) {
+  PromoteLegacyPass() : FunctionPass(ID), ForcePass(false) {
+initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry());
+  }
+  PromoteLegacyPass(bool IsForced) : FunctionPass(ID), ForcePass(IsForced) {
 initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry());
   }
 
   // runOnFunction - To run this pass, first we calculate the alloca
   // instructions that are safe for promotion, then we promote each one.
   bool runOnFunction(Function ) override {
-if (skipFunction(F))
+if (!ForcePass && skipFunction(F))
   return false;
 
 DominatorTree  = getAnalysis().getDomTree();
@@ -96,6 +100,7 @@
 AU.addRequired();
 AU.setPreservesCFG();
   }
+
 };
 
 } // end anonymous namespace
@@ -111,6 +116,6 @@
 false, false)
 
 // createPromoteMemoryToRegister - Provide an entry point to create this pass.
-FunctionPass *llvm::createPromoteMemoryToRegisterPass() {
-  return new PromoteLegacyPass();
+FunctionPass *llvm::createPromoteMemoryToRegisterPass(bool IsForced) {
+  return new PromoteLegacyPass(IsForced);
 }
Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -16,6 +16,7 @@
 #include "TargetInfo/WebAssemblyTargetInfo.h"
 #include "Utils/WebAssemblyUtilities.h"
 #include "WebAssembly.h"
+#include "WebAssemblyISelLowering.h"
 #include "WebAssemblyMachineFunctionInfo.h"
 #include "WebAssemblyTargetObjectFile.h"
 #include "WebAssemblyTargetTransformInfo.h"
@@ -464,6 +465,14 @@
 }
 
 void WebAssemblyPassConfig::addISelPrepare() {
+  WebAssemblyTargetMachine *WasmTM = static_cast(TM);
+  const WebAssemblySubtarget *Subtarget = WasmTM
+->getSubtargetImpl(std::string(WasmTM->getTargetCPU()),
+   std::string(WasmTM->getTargetFeatureString()));
+  if(Subtarget->hasReferenceTypes()) {
+// We need to remove allocas for reference types
+addPass(createPromoteMemoryToRegisterPass(true));
+  }
   // Lower atomics and TLS if necessary
   addPass(new CoalesceFeaturesAndStripAtomics(()));
 
Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -306,6 +306,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type *Type::getWasm_ExternrefTy(LLVMContext ) {
+  // opaque pointer in addrspace(10)
+ 

[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 487692.
ChuanqiXu added a comment.

Address comments:

- Add more comments in the test.
- Avoid ad-hoc parsing `-o` option manually.


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

https://reviews.llvm.org/D137534

Files:
  clang/test/ClangScanDeps/P1689.cppm
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Tooling/CommonOptionsParser.h"
@@ -17,6 +18,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/Program.h"
@@ -167,9 +169,14 @@
 
 llvm::cl::opt
 CompilationDB("compilation-database",
-  llvm::cl::desc("Compilation database"), llvm::cl::Required,
+  llvm::cl::desc("Compilation database"), llvm::cl::Optional,
   llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::opt P1689TargettedCommand(
+llvm::cl::Positional, llvm::cl::ZeroOrMore,
+llvm::cl::desc("The command line flags for the target of which "
+   "the dependencies are to be computed."));
+
 llvm::cl::opt ModuleName(
 "module-name", llvm::cl::Optional,
 llvm::cl::desc("the module of which the dependencies are to be computed"),
@@ -522,19 +529,109 @@
   return std::string(Path);
 }
 
-int main(int argc, const char **argv) {
+// getCompilationDataBase - If -compilation-database is set, load the
+// compilation database from the specified file. Otherwise if the we're
+// generating P1689 format, trying to generate the compilation database
+// form specified command line after the positional parameter "--".
+static std::unique_ptr
+getCompilationDataBase(int argc, const char **argv, std::string ) {
   llvm::InitLLVM X(argc, argv);
   llvm::cl::HideUnrelatedOptions(DependencyScannerCategory);
   if (!llvm::cl::ParseCommandLineOptions(argc, argv))
-return 1;
+return nullptr;
+
+  if (!CompilationDB.empty())
+return tooling::JSONCompilationDatabase::loadFromFile(
+CompilationDB, ErrorMessage,
+tooling::JSONCommandLineSyntax::AutoDetect);
+
+  if (Format != ScanningOutputFormat::P1689) {
+llvm::errs() << "the --compilation-database option: must be specified at "
+"least once!";
+return nullptr;
+  }
+
+  // Trying to get the input file, the output file and the command line options
+  // from the positional parameter "--".
+  const char **DoubleDash = std::find(argv, argv + argc, StringRef("--"));
+  if (DoubleDash == argv + argc) {
+llvm::errs() << "The command line arguments is required after '--' in "
+"P1689 per file mode.";
+return nullptr;
+  }
+  std::vector CommandLine(DoubleDash + 1, argv + argc);
+
+  llvm::IntrusiveRefCntPtr Diags =
+  CompilerInstance::createDiagnostics(new DiagnosticOptions);
+  driver::Driver TheDriver(CommandLine[0], llvm::sys::getDefaultTargetTriple(),
+   *Diags);
+  std::unique_ptr C(
+  TheDriver.BuildCompilation(CommandLine));
+  if (!C)
+return nullptr;
+
+  auto Cmd = C->getJobs().begin();
+  auto CI = std::make_unique();
+  CompilerInvocation::CreateFromArgs(*CI, Cmd->getArguments(), *Diags,
+ CommandLine[0]);
+  if (!CI)
+return nullptr;
+
+  FrontendOptions  = CI->getFrontendOpts();
+  if (FEOpts.Inputs.size() != 1) {
+llvm::errs() << "Only one input file is allowed in P1689 per file mode.";
+return nullptr;
+  }
+
+  // There might be multiple jobs for a compilation. Extract the specified
+  // output filename from the last job.
+  auto LastCmd = C->getJobs().end();
+  LastCmd--;
+  if (LastCmd->getOutputFilenames().size() != 1) {
+llvm::errs() << "The command line should provide exactly one output file "
+"in P1689 per file mode.\n";
+  }
+  StringRef OutputFile = LastCmd->getOutputFilenames().front();
+
+  class InplaceCompilationDatabase : public tooling::CompilationDatabase {
+  public:
+InplaceCompilationDatabase(StringRef InputFile, StringRef OutputFile,
+   ArrayRef CommandLine)
+: Command(".", InputFile, {}, OutputFile) {
+  for (auto *C : CommandLine)
+Command.CommandLine.push_back(C);
+}
 
+std::vector
+getCompileCommands(StringRef FilePath) const override {
+  if (FilePath != Command.Filename)
+return {};
+  return {Command};
+}
+
+std::vector 

[PATCH] D141288: [clang-format] Inherit RightAlign options across scopes

2023-01-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141288

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


[PATCH] D141226: [WIP][clangd] support expanding `decltype(expr)`

2023-01-09 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 487688.
v1nh1shungry added a comment.

- avoid expanding dependent types
- avoid expanding reference to a function
- avoid expanding array type and reference to an array


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141226

Files:
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandDeducedType.cpp
  clang-tools-extra/clangd/test/check-fail.test
  clang-tools-extra/clangd/test/check-lines.test
  clang-tools-extra/clangd/test/check.test
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/test/request-reply.test
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
  clang/docs/tools/clang-formatted-files.txt
  llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
@@ -129,7 +129,7 @@
 "tweaks/DumpASTTests.cpp",
 "tweaks/DumpRecordLayoutTests.cpp",
 "tweaks/DumpSymbolTests.cpp",
-"tweaks/ExpandAutoTypeTests.cpp",
+"tweaks/ExpandDeducedTypeTests.cpp",
 "tweaks/ExpandMacroTests.cpp",
 "tweaks/ExtractFunctionTests.cpp",
 "tweaks/ExtractVariableTests.cpp",
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
@@ -18,7 +18,7 @@
 "DefineInline.cpp",
 "DefineOutline.cpp",
 "DumpAST.cpp",
-"ExpandAutoType.cpp",
+"ExpandDeducedType.cpp",
 "ExpandMacro.cpp",
 "ExtractFunction.cpp",
 "ExtractVariable.cpp",
Index: clang/docs/tools/clang-formatted-files.txt
===
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -1611,7 +1611,7 @@
 clang-tools-extra/clangd/unittests/tweaks/DumpASTTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/DumpRecordLayoutTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/DumpSymbolTests.cpp
-clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/ExpandMacroTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
Index: clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
===
--- clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
+++ clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
@@ -25,9 +25,9 @@
 // Fixture base for testing tweaks. Intended to be subclassed for each tweak.
 //
 // Usage:
-// TWEAK_TEST(ExpandAutoType);
+// TWEAK_TEST(ExpandDeducedType);
 //
-// TEST_F(ExpandAutoTypeTest, ShortensTypes) {
+// TEST_F(ExpandDeducedTypeTest, ShortensTypes) {
 //   Header = R"cpp(
 // namespace foo { template class X{}; }
 // using namespace foo;
Index: clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
@@ -1,4 +1,4 @@
-//===-- ExpandAutoTypeTests.cpp -*- C++ -*-===//
+//===-- ExpandDeducedTypeTests.cpp --*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -16,9 +16,9 @@
 namespace clangd {
 namespace {
 
-TWEAK_TEST(ExpandAutoType);
+TWEAK_TEST(ExpandDeducedType);
 
-TEST_F(ExpandAutoTypeTest, Test) {
+TEST_F(ExpandDeducedTypeTest, Test) {
   Header = R"cpp(
 namespace ns {
   struct Class {
@@ -50,7 +50,10 @@
   StartsWith("fail: Could not deduce type for 'auto' type"));
   // function pointers should not be replaced
   EXPECT_THAT(apply("au^to x = ::Func;"),
-  StartsWith("fail: Could not expand type of function pointer"));
+  StartsWith("fail: Could not expand type of function"));
+  // function 

[PATCH] D141198: [Clang][RISCV][NFC] Reorganize test case for rvv intrinsics

2023-01-09 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 487683.
eopXD added a comment.

Address comment from Craig.

Also separate test case according to their mnemonics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141198

Files:
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaaddu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vadc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vand.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vasub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vasubu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vcompress.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vcpop.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vdivu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfabs.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfclass.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfcvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfirst.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmax.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmerge.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmin.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfncvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfneg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrec7.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredmax.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredmin.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredosum.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredusum.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrsqrt7.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnj.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnjn.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnjx.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfslide1down.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfslide1up.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsqrt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwcvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwmacc.c
  

[PATCH] D139185: [clang][Interp] Use placement new to construct opcode args into vector

2023-01-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


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

https://reviews.llvm.org/D139185

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


[PATCH] D137381: [clang][compiler-rt] Exception escape out of an non-unwinding function is an undefined behaviour

2023-01-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I am unfamiliar with Clang codegen so I am just commenting about what a user 
may feel about this feature.

`compiler-rt/test/ubsan/TestCases/Misc/exception-escape.cpp` cannot demonstrate 
the value of the new UBSan check `-fsanitize=exception-escape`, as the 
executable will fail anyway (Clang emits `call` instead of `invoke` for a 
nounwind function call, and there is no LSDA information, libgcc/libunwind will 
call terminate; it's trivial to get more diagnostic with a SIBABRT signal 
handler).
To demonstrate the value, `footgun` and its caller need to be in different TUs 
and the caller does not know `footgun` is nounwind.
In such a setup, I think people likely care more about 
`-fno-exceptions`/`-fexceptions` exception propagation instead of 
`__attribute__((pure))` and find `-fsanitize=exception-escape` not do what it 
may advertise.

The more common `-fno-exceptions`/`-fexceptions` exception propagation dilemma 
can be detected today with `-fno-asynchronous-unwind-tables`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137381

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


[PATCH] D141283: [clang] Improve diagnostic for "initializer-string for char array is too long"

2023-01-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

When grepping `clang/test/` for "for char array is too long", I get a bunch of 
other hits for this diagnostic, are the those tests not failing for you (e.g. 
`clang/test/Sema/array-init.c:149`)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141283

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


[PATCH] D141350: Fix runtime problem for base class member data used in target region.

2023-01-09 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D141350#4038619 , @ye-luo wrote:

> Does this patch work when there are more than one level of inheritance? For 
> example `class B: public A; class C: public B`

Yes, that works.  For that we emit this[:1] instead.   I can add more test that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141350

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


[PATCH] D141350: Fix runtime problem for base class member data used in target region.

2023-01-09 Thread Ye Luo via Phabricator via cfe-commits
ye-luo added a comment.

Does this patch work when there are more than one level of inheritance? For 
example `class B: public A; class C: public B`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141350

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


[PATCH] D141350: Fix runtime problem for base class member data used in target region.

2023-01-09 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, jdoerfert, mikerice.
jyu2 added a project: OpenMP.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, sstefan1.
Herald added a project: clang.

The problem is happened when base class member field is used in target
region , the size is wrong, cause runtime to fail. Currently the size of
calculation is depended on index of field, since field is in base class,
the calculation is wrong.

According OpenMP 5.2 148:21:
If the target construct is within a class non-static member function,
and a variable is an accessible data member of the object for which the
non-static data member function is invoked, the variable is treated as
if the this[:1] expression had appeared in a map clause with a map-type
of tofrom.

One way to fix this is emitting code to generate this[:1] instead only
when class has any base class.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141350

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Index: openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
@@ -0,0 +1,35 @@
+// RUN: %libomptarget-compile-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+extern "C" int printf(const char *, ...);
+template  class A {
+protected:
+  T X;
+  T Y;
+
+public:
+  A(T x, T y) : X{x}, Y{y} {};
+};
+
+template  class B : public A {
+  using A::X;
+  using A::Y;
+
+public:
+  T res;
+
+  B(T x, T y) : A(x, y), res{0} {};
+
+  void run(void) {
+#pragma omp target map(res)
+{ res = X + Y; }
+  }
+};
+
+int main(int argc, char *argv[]) {
+  B b(2, 3);
+  b.run();
+  // CHECK: 5
+  printf("b.res = %d \n", b.res);
+}
Index: clang/test/OpenMP/target_map_member_expr_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -0,0 +1,122 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu  \
+// RUN:  -x c++ -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - \
+// RUN:   | FileCheck %s
+
+// expected-no-diagnostics
+
+// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
+// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
+
+// CHECK-LABEL: define {{[^@]+}}@_Z3foov(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
+// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
+// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 dereferenceable(12) [[B]])
+// CHECK-NEXT:ret void
+//
+class A {
+protected:
+  int X;
+  int Y;
+
+public:
+  A (int x, int y) : X { x }, Y { y } { };
+};
+
+class B : public A {
+  using A::X;
+  using A::Y;
+public:
+  int res;
+// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:store i32 [[X:%.*]], ptr [[X_ADDR]], align 4
+// CHECK-NEXT:store i32 [[Y:%.*]], ptr [[Y_ADDR]], align 4
+// CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[Y_ADDR]], align 4
+// CHECK-NEXT:call void @_ZN1BC2Eii(ptr noundef nonnull align 4 dereferenceable(12) [[THIS1]], i32 noundef [[TMP0]], i32 noundef [[TMP1]])
+// CHECK-NEXT:ret void
+//
+  B (int x, int y) : A(x,y), res{0} {}
+// CHECK-LABEL: define {{[^@]+}}@_ZN1B3runEv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK-NOT: sdiv exact i64 {{.*}}, ptrtoint
+// CHECK-NEXT:[[RES:%.*]] = getelementptr inbounds [[CLASS_B:%.*]], ptr [[THIS1]], i32 0, i32 1
+// CHECK-NEXT:[[X:%.*]] = getelementptr inbounds [[CLASS_A:%.*]], ptr [[THIS1]], i32 0, i32 0
+// CHECK-NEXT:[[Y:%.*]] = getelementptr inbounds [[CLASS_A]], ptr [[THIS1]], i32 0, i32 1
+// 

[PATCH] D141288: [clang-format] Inherit RightAlign options across scopes

2023-01-09 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141288

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


[clang] eded23d - [Clang] Silence a "unused variable" warning when building with MSVC

2023-01-09 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2023-01-09T23:45:20-05:00
New Revision: eded23dfdaf050793b70351d5f42400016d57c15

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

LOG: [Clang] Silence a "unused variable" warning when building with MSVC

Added: 


Modified: 
clang/lib/Lex/LiteralSupport.cpp

Removed: 




diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index 05575e8d6e2a7..fb2b14601a6ae 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -515,8 +515,9 @@ static void DiagnoseInvalidUnicodeCharacterName(
 
 std::string Str;
 llvm::UTF32 V = Match.Value;
-LLVM_ATTRIBUTE_UNUSED bool Converted =
+bool Converted =
 llvm::convertUTF32ToUTF8String(llvm::ArrayRef(, 1), 
Str);
+(void)Converted;
 assert(Converted && "Found a match wich is not a unicode character");
 
 Diag(Diags, Features, Loc, TokBegin, TokRangeBegin, TokRangeEnd,



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


[PATCH] D140794: [ASTMatcher] Add coroutineBodyStmt matcher

2023-01-09 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 487661.
ccotter marked an inline comment as not done.
ccotter added a comment.

- Add hasBody matcher support for coroutineBodyStmt
- update doc
- Sort list
- clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140794

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -678,6 +678,48 @@
   EXPECT_TRUE(matchesConditionally(CoYieldCode, 
coyieldExpr(isExpansionInMainFile()), 
true, {"-std=c++20", "-I/"}, M));
+
+  StringRef NonCoroCode = R"cpp(
+#include 
+void non_coro_function() {
+}
+)cpp";
+
+  EXPECT_TRUE(matchesConditionally(CoReturnCode, coroutineBodyStmt(), true,
+   {"-std=c++20", "-I/"}, M));
+  EXPECT_TRUE(matchesConditionally(CoAwaitCode, coroutineBodyStmt(), true,
+   {"-std=c++20", "-I/"}, M));
+  EXPECT_TRUE(matchesConditionally(CoYieldCode, coroutineBodyStmt(), true,
+   {"-std=c++20", "-I/"}, M));
+
+  EXPECT_FALSE(matchesConditionally(NonCoroCode, coroutineBodyStmt(), true,
+{"-std=c++20", "-I/"}, M));
+
+  StringRef CoroWithDeclCode = R"cpp(
+#include 
+void coro() {
+  int thevar;
+  co_return 1;
+}
+)cpp";
+  EXPECT_TRUE(matchesConditionally(
+  CoroWithDeclCode,
+  coroutineBodyStmt(hasBody(compoundStmt(
+  has(declStmt(containsDeclaration(0, varDecl(hasName("thevar",
+  true, {"-std=c++20", "-I/"}, M));
+
+  StringRef CoroWithTryCatchDeclCode = R"cpp(
+#include 
+void coro() try {
+  int thevar;
+  co_return 1;
+} catch (...) {}
+)cpp";
+  EXPECT_TRUE(matchesConditionally(
+  CoroWithTryCatchDeclCode,
+  coroutineBodyStmt(hasBody(cxxTryStmt(has(compoundStmt(has(
+  declStmt(containsDeclaration(0, varDecl(hasName("thevar")),
+  true, {"-std=c++20", "-I/"}, M));
 }
 
 TEST(Matcher, isClassMessage) {
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -175,6 +175,7 @@
   REGISTER_MATCHER(containsDeclaration);
   REGISTER_MATCHER(continueStmt);
   REGISTER_MATCHER(coreturnStmt);
+  REGISTER_MATCHER(coroutineBodyStmt);
   REGISTER_MATCHER(coyieldExpr);
   REGISTER_MATCHER(cudaKernelCallExpr);
   REGISTER_MATCHER(cxxBaseSpecifier);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -909,6 +909,8 @@
 const internal::VariadicDynCastAllOfMatcher caseStmt;
 const internal::VariadicDynCastAllOfMatcher defaultStmt;
 const internal::VariadicDynCastAllOfMatcher compoundStmt;
+const internal::VariadicDynCastAllOfMatcher
+coroutineBodyStmt;
 const internal::VariadicDynCastAllOfMatcher cxxCatchStmt;
 const internal::VariadicDynCastAllOfMatcher cxxTryStmt;
 const internal::VariadicDynCastAllOfMatcher cxxThrowExpr;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2449,6 +2449,17 @@
 extern const internal::VariadicDynCastAllOfMatcher
 coyieldExpr;
 
+/// Matches coroutine body statements.
+///
+/// coroutineBodyStmt() matches the coroutine below
+/// \code
+///   generator gen() {
+/// co_return;
+///   }
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher
+coroutineBodyStmt;
+
 /// Matches nullptr literal.
 extern const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;
@@ -5460,9 +5471,9 @@
 }
 
 /// Matches a 'for', 'while', 'do while' statement or a function
-/// definition that has a given body. Note that in case of functions
-/// this matcher only matches the definition itself and not the other
-/// declarations of the same function.
+/// or coroutine definition that has a given body. Note that in case of
+/// functions this matcher only matches the definition itself and not
+/// the other declarations of the same function.
 ///
 /// Given
 /// \code
@@ -5484,12 +5495,11 @@
 ///   matching '{}'
 ///   but does not match 'void f();'
 
-AST_POLYMORPHIC_MATCHER_P(hasBody,
-  

[PATCH] D140794: [ASTMatcher] Add coroutineBodyStmt matcher

2023-01-09 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:5503
+  FunctionDecl,
+  CoroutineBodyStmt),
   internal::Matcher, InnerMatcher) {

aaron.ballman wrote:
> I'm not certain it makes sense to me to add `CoroutineBodyStmt` to `hasBody` 
> -- in this case, it doesn't *have* a body, it *is* the body.
With respect to `hasBody()`, my intent was to treat the CoroutineBodyStmt node 
as analogous to a FunctionDecl or WhileStmt. WhileStmts have information like 
the loop condition expression, as CoroutineBodyStmts contain the synthesized 
expressions such as the initial suspend Stmt. Both WhileStmts and 
CoroutineBodyStmts then have the `getBody()` methods, usually a CompoundStmt 
for WhileStmts and either a CompoundStmt or TryStmt for CoroutineBodyStmts.

Ultimately, I wanted to be able to match the CoroutineBodyStmt's 
`function-body` (using the grammar) from the standard, e.g., 
`coroutineBodyStmt(hasBody(compoundStmt().bind(...)))`. If there is a different 
approach you'd recommend that's in line with the AST matcher design strategy, I 
can use that instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140794

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


[PATCH] D141349: Remove the ThreadLocal template from LLVM.

2023-01-09 Thread Owen Anderson via Phabricator via cfe-commits
resistor added a comment.

Incorporated build fixes for GCC. Waiting for buildbots to complete.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141349

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


[PATCH] D141349: Remove the ThreadLocal template from LLVM.

2023-01-09 Thread Owen Anderson via Phabricator via cfe-commits
resistor created this revision.
Herald added subscribers: Moerafaat, zero9178, bzcheeseman, sdasgup3, 
wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, 
Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini, kadircet, arphaman, hiraditya.
Herald added a project: All.
resistor requested review of this revision.
Herald added subscribers: cfe-commits, llvm-commits, stephenneuendorffer, 
nicolasvasilache.
Herald added projects: MLIR, LLVM, clang-tools-extra.

This has been obsoleted by C++ thread_local for a long time.
As far as I know, Xcode was the last supported toolchain to add
support for C++ thread_local in 2016.

As a precaution, use LLVM_THREAD_LOCAL which provides even greater
backwards compatibility, allowing this to function even pre-C++11
versions of GCC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141349

Files:
  clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
  llvm/include/llvm/Support/ThreadLocal.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CrashRecoveryContext.cpp
  llvm/lib/Support/ThreadLocal.cpp
  llvm/lib/Support/Unix/ThreadLocal.inc
  llvm/lib/Support/Windows/ThreadLocal.inc
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/ThreadLocalTest.cpp
  mlir/include/mlir/Support/ThreadLocalCache.h

Index: mlir/include/mlir/Support/ThreadLocalCache.h
===
--- mlir/include/mlir/Support/ThreadLocalCache.h
+++ mlir/include/mlir/Support/ThreadLocalCache.h
@@ -18,7 +18,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/ThreadLocal.h"
 
 namespace mlir {
 /// This class provides support for defining a thread local object with non
Index: llvm/unittests/Support/ThreadLocalTest.cpp
===
--- llvm/unittests/Support/ThreadLocalTest.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-//===- llvm/unittest/Support/ThreadLocalTest.cpp - ThreadLocal tests --===//
-//
-// 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 "llvm/Support/ThreadLocal.h"
-#include "gtest/gtest.h"
-#include 
-
-using namespace llvm;
-using namespace sys;
-
-namespace {
-
-class ThreadLocalTest : public ::testing::Test {
-};
-
-struct S {
-  int i;
-};
-
-TEST_F(ThreadLocalTest, Basics) {
-  ThreadLocal x;
-
-  static_assert(std::is_const_v>,
-"ThreadLocal::get didn't return a pointer to const object");
-
-  EXPECT_EQ(nullptr, x.get());
-
-  S s;
-  x.set();
-  EXPECT_EQ(, x.get());
-
-  x.erase();
-  EXPECT_EQ(nullptr, x.get());
-
-  ThreadLocal y;
-
-  static_assert(!std::is_const_v>,
-"ThreadLocal::get returned a pointer to const object");
-
-  EXPECT_EQ(nullptr, y.get());
-
-  y.set();
-  EXPECT_EQ(, y.get());
-
-  y.erase();
-  EXPECT_EQ(nullptr, y.get());
-}
-
-}
Index: llvm/unittests/Support/CMakeLists.txt
===
--- llvm/unittests/Support/CMakeLists.txt
+++ llvm/unittests/Support/CMakeLists.txt
@@ -80,7 +80,6 @@
   SymbolRemappingReaderTest.cpp
   TarWriterTest.cpp
   TaskQueueTest.cpp
-  ThreadLocalTest.cpp
   ThreadPool.cpp
   Threading.cpp
   TimerTest.cpp
Index: llvm/lib/Support/Windows/ThreadLocal.inc
===
--- llvm/lib/Support/Windows/ThreadLocal.inc
+++ /dev/null
@@ -1,50 +0,0 @@
-//= llvm/Support/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++
-//-*-===//
-//
-// 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
-//
-//===--===//
-//
-// This file implements the Win32 specific (non-pthread) ThreadLocal class.
-//
-//===--===//
-
-//===--===//
-//=== WARNING: Implementation here must contain only generic Win32 code that
-//===  is guaranteed to work on *all* Win32 variants.
-//===--===//
-
-#include "llvm/Support/ThreadLocal.h"
-#include "llvm/Support/Windows/WindowsSupport.h"
-
-namespace llvm {
-
-sys::ThreadLocalImpl::ThreadLocalImpl() : data() {
-  static_assert(sizeof(DWORD) <= sizeof(data), "size too big");
-  DWORD *tls = reinterpret_cast();
-  *tls = TlsAlloc();
-  assert(*tls != TLS_OUT_OF_INDEXES);
-}
-
-sys::ThreadLocalImpl::~ThreadLocalImpl() {
- 

[clang-tools-extra] ef9aa34 - Revert "Remove the ThreadLocal template from LLVM."

2023-01-09 Thread Owen Anderson via cfe-commits

Author: Owen Anderson
Date: 2023-01-09T21:21:38-07:00
New Revision: ef9aa34f0274cdbfa82c47f8ab99f02679fd0d13

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

LOG: Revert "Remove the ThreadLocal template from LLVM."

This reverts commit 54d78b639b9c18b42abd4fac5c6e76105f06b3ef.

Added: 
llvm/include/llvm/Support/ThreadLocal.h
llvm/lib/Support/ThreadLocal.cpp
llvm/lib/Support/Unix/ThreadLocal.inc
llvm/lib/Support/Windows/ThreadLocal.inc
llvm/unittests/Support/ThreadLocalTest.cpp

Modified: 
clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
llvm/lib/Support/CMakeLists.txt
llvm/lib/Support/CrashRecoveryContext.cpp
llvm/unittests/Support/CMakeLists.txt
mlir/include/mlir/Support/ThreadLocalCache.h

Removed: 




diff  --git a/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp 
b/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
index 9551bbfda43c1..05afb3b25f28e 100644
--- a/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
+++ b/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "support/ThreadCrashReporter.h"
+#include "llvm/Support/ThreadLocal.h"
 #include 
 
 namespace clang {

diff  --git a/llvm/include/llvm/Support/ThreadLocal.h 
b/llvm/include/llvm/Support/ThreadLocal.h
new file mode 100644
index 0..d6838c15fc345
--- /dev/null
+++ b/llvm/include/llvm/Support/ThreadLocal.h
@@ -0,0 +1,62 @@
+//===- llvm/Support/ThreadLocal.h - Thread Local Data *- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file declares the llvm::sys::ThreadLocal class.
+//
+//===--===//
+
+#ifndef LLVM_SUPPORT_THREADLOCAL_H
+#define LLVM_SUPPORT_THREADLOCAL_H
+
+#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/Threading.h"
+#include 
+
+namespace llvm {
+  namespace sys {
+// ThreadLocalImpl - Common base class of all ThreadLocal instantiations.
+// YOU SHOULD NEVER USE THIS DIRECTLY.
+class ThreadLocalImpl {
+  typedef uint64_t ThreadLocalDataTy;
+  /// Platform-specific thread local data.
+  ///
+  /// This is embedded in the class and we avoid malloc'ing/free'ing it,
+  /// to make this class more safe for use along with CrashRecoveryContext.
+  union {
+char data[sizeof(ThreadLocalDataTy)];
+ThreadLocalDataTy align_data;
+  };
+public:
+  ThreadLocalImpl();
+  virtual ~ThreadLocalImpl();
+  void setInstance(const void* d);
+  void *getInstance();
+  void removeInstance();
+};
+
+/// ThreadLocal - A class used to abstract thread-local storage.  It holds,
+/// for each thread, a pointer a single object of type T.
+template
+class ThreadLocal : public ThreadLocalImpl {
+public:
+  ThreadLocal() : ThreadLocalImpl() { }
+
+  /// get - Fetches a pointer to the object associated with the current
+  /// thread.  If no object has yet been associated, it returns NULL;
+  T* get() { return static_cast(getInstance()); }
+
+  // set - Associates a pointer to an object with the current thread.
+  void set(T* d) { setInstance(d); }
+
+  // erase - Removes the pointer associated with the current thread.
+  void erase() { removeInstance(); }
+};
+  }
+}
+
+#endif

diff  --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 9b5402fa54f0f..46469c6e9e624 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -260,6 +260,7 @@ add_llvm_component_library(LLVMSupport
   Program.cpp
   RWMutex.cpp
   Signals.cpp
+  ThreadLocal.cpp
   Threading.cpp
   Valgrind.cpp
   Watchdog.cpp

diff  --git a/llvm/lib/Support/CrashRecoveryContext.cpp 
b/llvm/lib/Support/CrashRecoveryContext.cpp
index 9e792d1f51777..c7c384c9edc22 100644
--- a/llvm/lib/Support/CrashRecoveryContext.cpp
+++ b/llvm/lib/Support/CrashRecoveryContext.cpp
@@ -11,6 +11,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ExitCodes.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/ThreadLocal.h"
 #include "llvm/Support/thread.h"
 #include 
 #include 
@@ -20,7 +21,11 @@ using namespace llvm;
 namespace {
 
 struct CrashRecoveryContextImpl;
-LLVM_THREAD_LOCAL static const CrashRecoveryContextImpl *CurrentContext;
+
+sys::ThreadLocal () {
+  static sys::ThreadLocal CurrentContext;
+  return CurrentContext;

[PATCH] D141347: Remove the ThreadLocal template from LLVM.

2023-01-09 Thread Owen Anderson 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 rG54d78b639b9c: Remove the ThreadLocal template from LLVM. 
(authored by resistor).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141347

Files:
  clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
  llvm/include/llvm/Support/ThreadLocal.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CrashRecoveryContext.cpp
  llvm/lib/Support/ThreadLocal.cpp
  llvm/lib/Support/Unix/ThreadLocal.inc
  llvm/lib/Support/Windows/ThreadLocal.inc
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/ThreadLocalTest.cpp
  mlir/include/mlir/Support/ThreadLocalCache.h

Index: mlir/include/mlir/Support/ThreadLocalCache.h
===
--- mlir/include/mlir/Support/ThreadLocalCache.h
+++ mlir/include/mlir/Support/ThreadLocalCache.h
@@ -18,7 +18,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/ThreadLocal.h"
 
 namespace mlir {
 /// This class provides support for defining a thread local object with non
Index: llvm/unittests/Support/ThreadLocalTest.cpp
===
--- llvm/unittests/Support/ThreadLocalTest.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-//===- llvm/unittest/Support/ThreadLocalTest.cpp - ThreadLocal tests --===//
-//
-// 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 "llvm/Support/ThreadLocal.h"
-#include "gtest/gtest.h"
-#include 
-
-using namespace llvm;
-using namespace sys;
-
-namespace {
-
-class ThreadLocalTest : public ::testing::Test {
-};
-
-struct S {
-  int i;
-};
-
-TEST_F(ThreadLocalTest, Basics) {
-  ThreadLocal x;
-
-  static_assert(std::is_const_v>,
-"ThreadLocal::get didn't return a pointer to const object");
-
-  EXPECT_EQ(nullptr, x.get());
-
-  S s;
-  x.set();
-  EXPECT_EQ(, x.get());
-
-  x.erase();
-  EXPECT_EQ(nullptr, x.get());
-
-  ThreadLocal y;
-
-  static_assert(!std::is_const_v>,
-"ThreadLocal::get returned a pointer to const object");
-
-  EXPECT_EQ(nullptr, y.get());
-
-  y.set();
-  EXPECT_EQ(, y.get());
-
-  y.erase();
-  EXPECT_EQ(nullptr, y.get());
-}
-
-}
Index: llvm/unittests/Support/CMakeLists.txt
===
--- llvm/unittests/Support/CMakeLists.txt
+++ llvm/unittests/Support/CMakeLists.txt
@@ -80,7 +80,6 @@
   SymbolRemappingReaderTest.cpp
   TarWriterTest.cpp
   TaskQueueTest.cpp
-  ThreadLocalTest.cpp
   ThreadPool.cpp
   Threading.cpp
   TimerTest.cpp
Index: llvm/lib/Support/Windows/ThreadLocal.inc
===
--- llvm/lib/Support/Windows/ThreadLocal.inc
+++ /dev/null
@@ -1,50 +0,0 @@
-//= llvm/Support/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++
-//-*-===//
-//
-// 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
-//
-//===--===//
-//
-// This file implements the Win32 specific (non-pthread) ThreadLocal class.
-//
-//===--===//
-
-//===--===//
-//=== WARNING: Implementation here must contain only generic Win32 code that
-//===  is guaranteed to work on *all* Win32 variants.
-//===--===//
-
-#include "llvm/Support/ThreadLocal.h"
-#include "llvm/Support/Windows/WindowsSupport.h"
-
-namespace llvm {
-
-sys::ThreadLocalImpl::ThreadLocalImpl() : data() {
-  static_assert(sizeof(DWORD) <= sizeof(data), "size too big");
-  DWORD *tls = reinterpret_cast();
-  *tls = TlsAlloc();
-  assert(*tls != TLS_OUT_OF_INDEXES);
-}
-
-sys::ThreadLocalImpl::~ThreadLocalImpl() {
-  DWORD *tls = reinterpret_cast();
-  TlsFree(*tls);
-}
-
-void *sys::ThreadLocalImpl::getInstance() {
-  DWORD *tls = reinterpret_cast();
-  return TlsGetValue(*tls);
-}
-
-void sys::ThreadLocalImpl::setInstance(const void *d) {
-  DWORD *tls = reinterpret_cast();
-  int errorcode = TlsSetValue(*tls, const_cast(d));
-  assert(errorcode != 0);
-  (void)errorcode;
-}
-
-void sys::ThreadLocalImpl::removeInstance() { setInstance(0); }
-
-} // namespace llvm
Index: llvm/lib/Support/Unix/ThreadLocal.inc

[clang-tools-extra] 54d78b6 - Remove the ThreadLocal template from LLVM.

2023-01-09 Thread Owen Anderson via cfe-commits

Author: Owen Anderson
Date: 2023-01-09T21:12:27-07:00
New Revision: 54d78b639b9c18b42abd4fac5c6e76105f06b3ef

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

LOG: Remove the ThreadLocal template from LLVM.

This has been obsoleted by C++ thread_local for a long time.
As far as I know, Xcode was the last supported toolchain to add
support for C++ thread_local in 2016.

As a precaution, use LLVM_THREAD_LOCAL which provides even greater
backwards compatibility, allowing this to function even pre-C++11
versions of GCC.

Reviewed By: majnemer

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

Added: 


Modified: 
clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
llvm/lib/Support/CMakeLists.txt
llvm/lib/Support/CrashRecoveryContext.cpp
llvm/unittests/Support/CMakeLists.txt
mlir/include/mlir/Support/ThreadLocalCache.h

Removed: 
llvm/include/llvm/Support/ThreadLocal.h
llvm/lib/Support/ThreadLocal.cpp
llvm/lib/Support/Unix/ThreadLocal.inc
llvm/lib/Support/Windows/ThreadLocal.inc
llvm/unittests/Support/ThreadLocalTest.cpp



diff  --git a/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp 
b/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
index 05afb3b25f28e..9551bbfda43c1 100644
--- a/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
+++ b/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
@@ -7,7 +7,6 @@
 
//===--===//
 
 #include "support/ThreadCrashReporter.h"
-#include "llvm/Support/ThreadLocal.h"
 #include 
 
 namespace clang {

diff  --git a/llvm/include/llvm/Support/ThreadLocal.h 
b/llvm/include/llvm/Support/ThreadLocal.h
deleted file mode 100644
index d6838c15fc345..0
--- a/llvm/include/llvm/Support/ThreadLocal.h
+++ /dev/null
@@ -1,62 +0,0 @@
-//===- llvm/Support/ThreadLocal.h - Thread Local Data *- C++ 
-*-===//
-//
-// 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
-//
-//===--===//
-//
-// This file declares the llvm::sys::ThreadLocal class.
-//
-//===--===//
-
-#ifndef LLVM_SUPPORT_THREADLOCAL_H
-#define LLVM_SUPPORT_THREADLOCAL_H
-
-#include "llvm/Support/DataTypes.h"
-#include "llvm/Support/Threading.h"
-#include 
-
-namespace llvm {
-  namespace sys {
-// ThreadLocalImpl - Common base class of all ThreadLocal instantiations.
-// YOU SHOULD NEVER USE THIS DIRECTLY.
-class ThreadLocalImpl {
-  typedef uint64_t ThreadLocalDataTy;
-  /// Platform-specific thread local data.
-  ///
-  /// This is embedded in the class and we avoid malloc'ing/free'ing it,
-  /// to make this class more safe for use along with CrashRecoveryContext.
-  union {
-char data[sizeof(ThreadLocalDataTy)];
-ThreadLocalDataTy align_data;
-  };
-public:
-  ThreadLocalImpl();
-  virtual ~ThreadLocalImpl();
-  void setInstance(const void* d);
-  void *getInstance();
-  void removeInstance();
-};
-
-/// ThreadLocal - A class used to abstract thread-local storage.  It holds,
-/// for each thread, a pointer a single object of type T.
-template
-class ThreadLocal : public ThreadLocalImpl {
-public:
-  ThreadLocal() : ThreadLocalImpl() { }
-
-  /// get - Fetches a pointer to the object associated with the current
-  /// thread.  If no object has yet been associated, it returns NULL;
-  T* get() { return static_cast(getInstance()); }
-
-  // set - Associates a pointer to an object with the current thread.
-  void set(T* d) { setInstance(d); }
-
-  // erase - Removes the pointer associated with the current thread.
-  void erase() { removeInstance(); }
-};
-  }
-}
-
-#endif

diff  --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 46469c6e9e624..9b5402fa54f0f 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -260,7 +260,6 @@ add_llvm_component_library(LLVMSupport
   Program.cpp
   RWMutex.cpp
   Signals.cpp
-  ThreadLocal.cpp
   Threading.cpp
   Valgrind.cpp
   Watchdog.cpp

diff  --git a/llvm/lib/Support/CrashRecoveryContext.cpp 
b/llvm/lib/Support/CrashRecoveryContext.cpp
index c7c384c9edc22..9e792d1f51777 100644
--- a/llvm/lib/Support/CrashRecoveryContext.cpp
+++ b/llvm/lib/Support/CrashRecoveryContext.cpp
@@ -11,7 +11,6 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ExitCodes.h"
 #include "llvm/Support/Signals.h"
-#include 

[PATCH] D141347: Remove the ThreadLocal template from LLVM.

2023-01-09 Thread Owen Anderson via Phabricator via cfe-commits
resistor updated this revision to Diff 487655.
resistor added a comment.

Fix nit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141347

Files:
  clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
  llvm/include/llvm/Support/ThreadLocal.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CrashRecoveryContext.cpp
  llvm/lib/Support/ThreadLocal.cpp
  llvm/lib/Support/Unix/ThreadLocal.inc
  llvm/lib/Support/Windows/ThreadLocal.inc
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/ThreadLocalTest.cpp
  mlir/include/mlir/Support/ThreadLocalCache.h

Index: mlir/include/mlir/Support/ThreadLocalCache.h
===
--- mlir/include/mlir/Support/ThreadLocalCache.h
+++ mlir/include/mlir/Support/ThreadLocalCache.h
@@ -18,7 +18,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/ThreadLocal.h"
 
 namespace mlir {
 /// This class provides support for defining a thread local object with non
Index: llvm/unittests/Support/ThreadLocalTest.cpp
===
--- llvm/unittests/Support/ThreadLocalTest.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-//===- llvm/unittest/Support/ThreadLocalTest.cpp - ThreadLocal tests --===//
-//
-// 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 "llvm/Support/ThreadLocal.h"
-#include "gtest/gtest.h"
-#include 
-
-using namespace llvm;
-using namespace sys;
-
-namespace {
-
-class ThreadLocalTest : public ::testing::Test {
-};
-
-struct S {
-  int i;
-};
-
-TEST_F(ThreadLocalTest, Basics) {
-  ThreadLocal x;
-
-  static_assert(std::is_const_v>,
-"ThreadLocal::get didn't return a pointer to const object");
-
-  EXPECT_EQ(nullptr, x.get());
-
-  S s;
-  x.set();
-  EXPECT_EQ(, x.get());
-
-  x.erase();
-  EXPECT_EQ(nullptr, x.get());
-
-  ThreadLocal y;
-
-  static_assert(!std::is_const_v>,
-"ThreadLocal::get returned a pointer to const object");
-
-  EXPECT_EQ(nullptr, y.get());
-
-  y.set();
-  EXPECT_EQ(, y.get());
-
-  y.erase();
-  EXPECT_EQ(nullptr, y.get());
-}
-
-}
Index: llvm/unittests/Support/CMakeLists.txt
===
--- llvm/unittests/Support/CMakeLists.txt
+++ llvm/unittests/Support/CMakeLists.txt
@@ -80,7 +80,6 @@
   SymbolRemappingReaderTest.cpp
   TarWriterTest.cpp
   TaskQueueTest.cpp
-  ThreadLocalTest.cpp
   ThreadPool.cpp
   Threading.cpp
   TimerTest.cpp
Index: llvm/lib/Support/Windows/ThreadLocal.inc
===
--- llvm/lib/Support/Windows/ThreadLocal.inc
+++ /dev/null
@@ -1,50 +0,0 @@
-//= llvm/Support/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++
-//-*-===//
-//
-// 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
-//
-//===--===//
-//
-// This file implements the Win32 specific (non-pthread) ThreadLocal class.
-//
-//===--===//
-
-//===--===//
-//=== WARNING: Implementation here must contain only generic Win32 code that
-//===  is guaranteed to work on *all* Win32 variants.
-//===--===//
-
-#include "llvm/Support/ThreadLocal.h"
-#include "llvm/Support/Windows/WindowsSupport.h"
-
-namespace llvm {
-
-sys::ThreadLocalImpl::ThreadLocalImpl() : data() {
-  static_assert(sizeof(DWORD) <= sizeof(data), "size too big");
-  DWORD *tls = reinterpret_cast();
-  *tls = TlsAlloc();
-  assert(*tls != TLS_OUT_OF_INDEXES);
-}
-
-sys::ThreadLocalImpl::~ThreadLocalImpl() {
-  DWORD *tls = reinterpret_cast();
-  TlsFree(*tls);
-}
-
-void *sys::ThreadLocalImpl::getInstance() {
-  DWORD *tls = reinterpret_cast();
-  return TlsGetValue(*tls);
-}
-
-void sys::ThreadLocalImpl::setInstance(const void *d) {
-  DWORD *tls = reinterpret_cast();
-  int errorcode = TlsSetValue(*tls, const_cast(d));
-  assert(errorcode != 0);
-  (void)errorcode;
-}
-
-void sys::ThreadLocalImpl::removeInstance() { setInstance(0); }
-
-} // namespace llvm
Index: llvm/lib/Support/Unix/ThreadLocal.inc
===
--- llvm/lib/Support/Unix/ThreadLocal.inc
+++ /dev/null
@@ -1,57 +0,0 @@
-//=== llvm/Support/Unix/ThreadLocal.inc - Unix Thread Local Data -*- 

[PATCH] D141347: Remove the ThreadLocal template from LLVM.

2023-01-09 Thread David Majnemer via Phabricator via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: llvm/lib/Support/CrashRecoveryContext.cpp:23
 struct CrashRecoveryContextImpl;
-
-sys::ThreadLocal () {
-  static sys::ThreadLocal CurrentContext;
-  return CurrentContext;
-}
+LLVM_THREAD_LOCAL static const  CrashRecoveryContextImpl *CurrentContext;
 

nit: Extra space after const


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141347

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


[PATCH] D141347: Remove the ThreadLocal template from LLVM.

2023-01-09 Thread Owen Anderson via Phabricator via cfe-commits
resistor created this revision.
Herald added subscribers: Moerafaat, zero9178, bzcheeseman, sdasgup3, 
wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, 
Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini, kadircet, arphaman, hiraditya.
Herald added a project: All.
resistor requested review of this revision.
Herald added subscribers: cfe-commits, llvm-commits, stephenneuendorffer, 
nicolasvasilache.
Herald added projects: MLIR, LLVM, clang-tools-extra.

This has been obsoleted by C++ thread_local for a long time.
As far as I know, Xcode was the last supported toolchain to add
support for C++ thread_local in 2016.

As a precaution, use LLVM_THREAD_LOCAL which provides even greater
backwards compatibility, allowing this to function even pre-C++11
versions of GCC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141347

Files:
  clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
  llvm/include/llvm/Support/ThreadLocal.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CrashRecoveryContext.cpp
  llvm/lib/Support/ThreadLocal.cpp
  llvm/lib/Support/Unix/ThreadLocal.inc
  llvm/lib/Support/Windows/ThreadLocal.inc
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/ThreadLocalTest.cpp
  mlir/include/mlir/Support/ThreadLocalCache.h

Index: mlir/include/mlir/Support/ThreadLocalCache.h
===
--- mlir/include/mlir/Support/ThreadLocalCache.h
+++ mlir/include/mlir/Support/ThreadLocalCache.h
@@ -18,7 +18,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/ThreadLocal.h"
 
 namespace mlir {
 /// This class provides support for defining a thread local object with non
Index: llvm/unittests/Support/ThreadLocalTest.cpp
===
--- llvm/unittests/Support/ThreadLocalTest.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-//===- llvm/unittest/Support/ThreadLocalTest.cpp - ThreadLocal tests --===//
-//
-// 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 "llvm/Support/ThreadLocal.h"
-#include "gtest/gtest.h"
-#include 
-
-using namespace llvm;
-using namespace sys;
-
-namespace {
-
-class ThreadLocalTest : public ::testing::Test {
-};
-
-struct S {
-  int i;
-};
-
-TEST_F(ThreadLocalTest, Basics) {
-  ThreadLocal x;
-
-  static_assert(std::is_const_v>,
-"ThreadLocal::get didn't return a pointer to const object");
-
-  EXPECT_EQ(nullptr, x.get());
-
-  S s;
-  x.set();
-  EXPECT_EQ(, x.get());
-
-  x.erase();
-  EXPECT_EQ(nullptr, x.get());
-
-  ThreadLocal y;
-
-  static_assert(!std::is_const_v>,
-"ThreadLocal::get returned a pointer to const object");
-
-  EXPECT_EQ(nullptr, y.get());
-
-  y.set();
-  EXPECT_EQ(, y.get());
-
-  y.erase();
-  EXPECT_EQ(nullptr, y.get());
-}
-
-}
Index: llvm/unittests/Support/CMakeLists.txt
===
--- llvm/unittests/Support/CMakeLists.txt
+++ llvm/unittests/Support/CMakeLists.txt
@@ -80,7 +80,6 @@
   SymbolRemappingReaderTest.cpp
   TarWriterTest.cpp
   TaskQueueTest.cpp
-  ThreadLocalTest.cpp
   ThreadPool.cpp
   Threading.cpp
   TimerTest.cpp
Index: llvm/lib/Support/Windows/ThreadLocal.inc
===
--- llvm/lib/Support/Windows/ThreadLocal.inc
+++ /dev/null
@@ -1,50 +0,0 @@
-//= llvm/Support/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++
-//-*-===//
-//
-// 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
-//
-//===--===//
-//
-// This file implements the Win32 specific (non-pthread) ThreadLocal class.
-//
-//===--===//
-
-//===--===//
-//=== WARNING: Implementation here must contain only generic Win32 code that
-//===  is guaranteed to work on *all* Win32 variants.
-//===--===//
-
-#include "llvm/Support/ThreadLocal.h"
-#include "llvm/Support/Windows/WindowsSupport.h"
-
-namespace llvm {
-
-sys::ThreadLocalImpl::ThreadLocalImpl() : data() {
-  static_assert(sizeof(DWORD) <= sizeof(data), "size too big");
-  DWORD *tls = reinterpret_cast();
-  *tls = TlsAlloc();
-  assert(*tls != TLS_OUT_OF_INDEXES);
-}
-
-sys::ThreadLocalImpl::~ThreadLocalImpl() {
- 

[PATCH] D140867: [C++20] [Modules] Don't generate global ctors/dtors for variables which are available externally

2023-01-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D140867#4036239 , @Jake-Egan wrote:

> Hi, this test is failing on AIX, could you take a look please? 
> https://lab.llvm.org/buildbot/#/builders/214/builds/5242/steps/6/logs/FAIL__Clang__pr59765-modules-global-ctor-dtor_cppm

I fixed the failure by restricting the targets in 
https://github.com/llvm/llvm-project/commit/9cb1298dcc85c357eb97ed0bdc3c82c5d011f6f6.
 And the best approach is to add a separate test for AIX but I don't have an 
AIX machine. You can add it if you are interested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140867

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


[clang] 9cb1298 - [NFC] Fix a test faliing in AIX

2023-01-09 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-10T10:41:21+08:00
New Revision: 9cb1298dcc85c357eb97ed0bdc3c82c5d011f6f6

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

LOG: [NFC] Fix a test faliing in AIX

See https://reviews.llvm.org/D140867.

The signature of the constructor/destrucor of the global variables is
different in different targets. And the CHECKs in the test is
unavailable in other targets (e.g., AIX). So the patch tries to avoid
the test failure by requiring the target type.

Added: 


Modified: 
clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm

Removed: 




diff  --git a/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm 
b/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
index 6080786ecd391..64d0b606c6f4f 100644
--- a/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
+++ b/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
@@ -1,4 +1,11 @@
 // https://github.com/llvm/llvm-project/issues/59765
+//
+// FIXME: Since the signature of the constructors/destructors is
+// 
diff erent in 
diff erent targets. The current CHECK can't work
+// well for other targets like AIX. So here is the REQUIRES.
+// It would be better to add the corresponding test for other test.
+// REQUIRES: x86-registered-target,aarch64-registered-target
+//
 // RUN: rm -rf %t
 // RUN: mkdir %t
 // RUN: split-file %s %t



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


[PATCH] D141342: [perf-training] Check extension in findFilesWithExtension

2023-01-09 Thread Amir Ayupov via Phabricator via cfe-commits
Amir created this revision.
Amir added reviewers: phosek, beanz.
Herald added a subscriber: pengfei.
Herald added a project: All.
Amir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`findFilesWithExtension` helper checks for `endswith(extension)` instead of
exactly matching the file extension. This causes it to match unrelated files,
for example, `.profdata` files while matching `.fdata` files:

http://157.230.108.44:8011/#/builders/56/builds/247

  Merging data from 
/worker/worker/bolt-x86_64-ubuntu-clang-bolt-gcc/build/tools/clang/prof.fdata.1124569.fdata...
  Merging data from 
/worker/worker/bolt-x86_64-ubuntu-clang-bolt-gcc/build/tools/clang/test/Frontend/Output/optimization-remark-with-hotness-new-pm.c.tmp.profdata...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141342

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


Index: clang/utils/perf-training/perf-helper.py
===
--- clang/utils/perf-training/perf-helper.py
+++ clang/utils/perf-training/perf-helper.py
@@ -23,7 +23,7 @@
   filenames = []
   for root, dirs, files in os.walk(path): 
 for filename in files:
-  if filename.endswith(extension):
+  if os.path.splitext(filename)[1] == extension:
 filenames.append(os.path.join(root, filename))
   return filenames
 


Index: clang/utils/perf-training/perf-helper.py
===
--- clang/utils/perf-training/perf-helper.py
+++ clang/utils/perf-training/perf-helper.py
@@ -23,7 +23,7 @@
   filenames = []
   for root, dirs, files in os.walk(path): 
 for filename in files:
-  if filename.endswith(extension):
+  if os.path.splitext(filename)[1] == extension:
 filenames.append(os.path.join(root, filename))
   return filenames
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135488: [codegen] Add a remarks based Stack Layout Analysis pass

2023-01-09 Thread Francis Visoiu Mistrih via Phabricator via cfe-commits
thegameg added a comment.

I don't think I understand why we can't achieve B with remarks? In C and D you 
generate one remark for each line, can't we generate a single multi-line remark 
instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135488

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


[PATCH] D136817: [RISCV] Add H extension

2023-01-09 Thread Kito Cheng 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 rGf4c887c3a840: [RISCV] Add H extension (authored by 
kito-cheng).

Changed prior to commit:
  https://reviews.llvm.org/D136817?vs=485360=487624#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136817

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/priv-aliases-valid.s
  llvm/test/MC/RISCV/priv-rv64-valid.s
  llvm/test/MC/RISCV/priv-valid.s
  llvm/test/MC/RISCV/rv32h-invalid.s
  llvm/test/MC/RISCV/rv32ih-aliases-valid.s
  llvm/test/MC/RISCV/rv32ih-valid.s
  llvm/test/MC/RISCV/rv64h-invalid.s
  llvm/test/MC/RISCV/rv64ih-valid.s
  llvm/test/MC/RISCV/rvi-aliases-valid.s

Index: llvm/test/MC/RISCV/rvi-aliases-valid.s
===
--- llvm/test/MC/RISCV/rvi-aliases-valid.s
+++ llvm/test/MC/RISCV/rvi-aliases-valid.s
@@ -256,18 +256,6 @@
 # CHECK-S-OBJ-NOALIAS: sfence.vma a0, zero
 # CHECK-S-OBJ: sfence.vma a0
 sfence.vma a0
-# CHECK-S-OBJ-NOALIAS: hfence.gvma zero, zero
-# CHECK-S-OBJ: hfence.gvma
-hfence.gvma
-# CHECK-S-OBJ-NOALIAS: hfence.gvma a0, zero
-# CHECK-S-OBJ: hfence.gvma a0
-hfence.gvma a0
-# CHECK-S-OBJ-NOALIAS: hfence.vvma zero, zero
-# CHECK-S-OBJ: hfence.vvma
-hfence.vvma
-# CHECK-S-OBJ-NOALIAS: hfence.vvma a0, zero
-# CHECK-S-OBJ: hfence.vvma a0
-hfence.vvma a0
 
 # The following aliases are accepted as input but the canonical form
 # of the instruction will always be printed.
Index: llvm/test/MC/RISCV/rv64ih-valid.s
===
--- llvm/test/MC/RISCV/rv64ih-valid.s
+++ llvm/test/MC/RISCV/rv64ih-valid.s
@@ -1,10 +1,10 @@
-# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+h -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -mattr=+h -triple riscv64 < %s \
+# RUN: | llvm-objdump --mattr=+h -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
 
-# RUN: not llvm-mc -triple riscv32 < %s 2>&1 \
+# RUN: not llvm-mc -triple riscv32 -mattr=+h < %s 2>&1 \
 # RUN: | FileCheck -check-prefix=CHECK-RV32 %s
 
 # CHECK-INST: hlv.wu a0, (a1)
Index: llvm/test/MC/RISCV/rv64h-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64h-invalid.s
@@ -0,0 +1,12 @@
+# RUN: not llvm-mc -triple riscv64 -mattr=+h < %s 2>&1 \
+# RUN: | FileCheck %s -check-prefixes=CHECK-OFFSET
+# RUN: not llvm-mc -triple riscv64 < %s 2>&1 \
+# RUN: | FileCheck %s -check-prefixes=CHECK,CHECK-OFFSET
+
+hfence.vvma zero, zero # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'H' (Hypervisor)
+
+hlv.h   a0, 0(a1) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'H' (Hypervisor)
+
+hlv.wu   a0, 0(a1) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'H' (Hypervisor)
+
+hlv.b   a0, 100(a1) # CHECK-OFFSET: :[[@LINE]]:13: error: optional integer offset must be 0
Index: llvm/test/MC/RISCV/rv32ih-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32ih-valid.s
@@ -0,0 +1,66 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+h -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+h -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+h < %s \
+# RUN: | llvm-objdump --mattr=+h -M no-aliases -d - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+h < %s \
+# RUN: | llvm-objdump --mattr=+h -M no-aliases -d - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+
+# CHECK-INST: hfence.vvma zero, zero
+# CHECK: encoding: [0x73,0x00,0x00,0x22]
+hfence.vvma zero, zero
+
+# CHECK-INST: hfence.vvma a0, a1
+# CHECK: encoding: [0x73,0x00,0xb5,0x22]
+hfence.vvma a0, a1
+
+# CHECK-INST: hfence.gvma zero, zero
+# CHECK: encoding: [0x73,0x00,0x00,0x62]
+hfence.gvma zero, zero
+
+# CHECK-INST: hfence.gvma a0, a1
+# CHECK: encoding: [0x73,0x00,0xb5,0x62]
+hfence.gvma a0, a1
+
+# CHECK-INST: hlv.b a0, (a1)
+# CHECK: encoding: [0x73,0xc5,0x05,0x60]
+hlv.b   a0, (a1)
+
+# CHECK-INST: hlv.bu a0, (a1)
+# CHECK: encoding: [0x73,0xc5,0x15,0x60]
+hlv.bu  a0, (a1)
+
+# CHECK-INST: hlv.h a1, (a2)
+# CHECK: encoding: [0xf3,0x45,0x06,0x64]
+hlv.h   a1, (a2)
+

[clang] f4c887c - [RISCV] Add H extension

2023-01-09 Thread Kito Cheng via cfe-commits

Author: Kito Cheng
Date: 2023-01-10T09:52:03+08:00
New Revision: f4c887c3a8406d85f4f942c8350f10026994f4d8

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

LOG: [RISCV] Add H extension

`h` was the prefix of multi-letter extension name, but it become a
extension name in later RISC-V isa spec.

Fortunately we don't have any extension really defined is prefixed
with `h`, so we can just change that.

Reviewed By: reames

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

Added: 
llvm/test/MC/RISCV/rv32h-invalid.s
llvm/test/MC/RISCV/rv32ih-aliases-valid.s
llvm/test/MC/RISCV/rv32ih-valid.s
llvm/test/MC/RISCV/rv64h-invalid.s
llvm/test/MC/RISCV/rv64ih-valid.s

Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCV.td
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/priv-valid.s
llvm/test/MC/RISCV/rvi-aliases-valid.s

Removed: 
llvm/test/MC/RISCV/priv-aliases-valid.s
llvm/test/MC/RISCV/priv-rv64-valid.s



diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index c514ad889d0b2..91ab4219ea344 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -46,6 +46,7 @@
 // CHECK-NOT: __riscv_xventanacondops
 // CHECK-NOT: __riscv_zcd
 // CHECK-NOT: __riscv_zcf
+// CHECK-NOT: __riscv_h
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
@@ -449,6 +450,12 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-SVINVAL-EXT %s
 // CHECK-SVINVAL-EXT: __riscv_svinval 100{{$}}
 
+// RUN: %clang -target riscv32 -march=rv32ih -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-H-EXT %s
+// RUN: %clang -target riscv64 -march=rv64ih -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-H-EXT %s
+// CHECK-H-EXT: __riscv_h 100{{$}}
+
 // RUN: %clang -target riscv64 -march=rv64ixventanacondops -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-XVENTANACONDOPS-EXT %s
 // CHECK-XVENTANACONDOPS-EXT: __riscv_xventanacondops 100{{$}}

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 25dc17d44c89e..3ba0d887ca77e 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -51,6 +51,7 @@ on support follow.
  ``C``Supported
  ``D``Supported
  ``F``Supported
+ ``H``Assembly Support
  ``M``Supported
  ``Svinval``  Assembly Support
  ``Svnapot``  Assembly Support

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 7a55837aa3f80..d82f337feb534 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -37,7 +37,7 @@ struct RISCVSupportedExtension {
 
 } // end anonymous namespace
 
-static constexpr StringLiteral AllStdExts = "mafdqlcbkjtpvn";
+static constexpr StringLiteral AllStdExts = "mafdqlcbkjtpvnh";
 
 static const RISCVSupportedExtension SupportedExtensions[] = {
 {"i", RISCVExtensionVersion{2, 0}},
@@ -48,6 +48,8 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
 {"d", RISCVExtensionVersion{2, 0}},
 {"c", RISCVExtensionVersion{2, 0}},
 
+{"h", RISCVExtensionVersion{1, 0}},
+
 {"zihintpause", RISCVExtensionVersion{2, 0}},
 
 {"zfhmin", RISCVExtensionVersion{1, 0}},
@@ -284,17 +286,14 @@ static int multiLetterExtensionRank(const std::string 
) {
   case 's':
 HighOrder = 0;
 break;
-  case 'h':
-HighOrder = 1;
-break;
   case 'z':
-HighOrder = 2;
+HighOrder = 1;
 // `z` extension must be sorted by canonical order of second letter.
 // e.g. zmx has higher rank than zax.
 LowOrder = singleLetterExtensionRank(ExtName[1]);
 break;
   case 'x':
-HighOrder = 3;
+HighOrder = 2;
 break;
   default:
 llvm_unreachable("Unknown prefix for multi-char extension");
@@ -611,8 +610,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
 
 // The order is OK, then push it into features.
 // TODO: Use version number when setting target features
-// Currently LLVM supports only "mafdcv".
-StringRef SupportedStandardExtension = "mafdcv";
+// Currently LLVM supports only "mafdcvh".
+StringRef SupportedStandardExtension = "mafdcvh";
 if (!SupportedStandardExtension.contains(C))
   return createStringError(errc::invalid_argument,
"unsupported standard user-level extension 
'%c'",

diff  --git 

[PATCH] D135488: [codegen] Add a remarks based Stack Layout Analysis pass

2023-01-09 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added a comment.

I think ideally I'd like to surface something like this:

A:
F26139353: image.png 

or

B:
F26139363: image.png 

The first image uses stdout, and the second uses remarks, but prints everything 
from the function as a single string. This provides some output that is pretty 
easy for a human to consume, and wouldn't be too hard to parse for an external 
tool. It isn't as nice from a machine readable perspective as something like 
JSON or YAML.

The big issue that I'm seeing is that printing multiple remarks ends up 
printing the path to the source file given as provided on the commandline. If 
that's from a build system, it will likely be a full path and a user is likely 
going to have a similar issue. The following examples are, IMO, much harder to 
make sense of. I see similar issues, even if I make my terminal full screen 
width.

C: 
F26139426: image.png 

or (if I format things as suggested)

D: 
F26139432: image.png 

I'm a bit stumped on how to make this work nicely w/ remarks and provide good 
support for both the CLI and YAML...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135488

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


[PATCH] D141338: [-Wunsafe-buffer-usage] Filter out conflicting fix-its

2023-01-09 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 created this revision.
ziqingluo-90 added reviewers: NoQ, jkorous, t-rasmud, malavikasamak.
Herald added a subscriber: mgrang.
Herald added a project: All.
ziqingluo-90 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Two fix-its conflict if they have overlapping source ranges.  We shall not emit 
conflicting fix-its.
This patch adds a class to find all conflicting fix-its (as well as their 
associated gadgets or declarations).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141338

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
@@ -71,3 +71,22 @@
   // crash at runtime after applying the fix-it,
   foo(p[5], q[5]);  // expected-warning2{{unchecked operation on raw buffer in expression}}
 }
+
+void fixits_conflict() {
+  // no fix-its will be emitted since fixits of `a` and `b` conflict in source locations:
+  // CHECK: int * a = new int[10],
+  // CHECK:   * b = new int[10];
+  // CHECK: foo(a[5], b[5]);
+  int * a = new int[10], // expected-warning{{variable 'a' participates in unchecked buffer operations}} \
+			 expected-warning{{variable 'b' participates in unchecked buffer operations}}
+* b = new int[10];
+
+  foo(a[5], b[5]); // expected-warning2{{unchecked operation on raw buffer in expression}}
+
+
+  // CHECK: std::span c{new int [10], 10};
+  // CHECK: foo(c[5]);
+  int * c = new int[10]; // expected-warning{{variable 'c' participates in unchecked buffer operations}}
+
+  foo(c[5]); // expected-warning{{unchecked operation on raw buffer in expression}}
+}
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -109,8 +109,8 @@
 
 AST_MATCHER_P(Stmt, forEveryDescendant, internal::Matcher, innerMatcher) {
   const DynTypedMatcher  = static_cast(innerMatcher);
-  
-  MatchDescendantVisitor Visitor(, Finder, Builder, ASTMatchFinder::BK_All);  
+
+  MatchDescendantVisitor Visitor(, Finder, Builder, ASTMatchFinder::BK_All);
   return Visitor.findMatch(DynTypedNode::create(Node));
 }
 } // namespace clang::ast_matchers
@@ -123,6 +123,16 @@
 // Convenience typedef.
 using FixItList = SmallVector;
 
+// To bind each `FixItList` with the `FixableGadget` which it will fix:
+// FIXME: for now declarations are not Gadgets so a FixItList is associated to
+// either a Gadget or a VarDecl (only one of them is significant).
+using GadgetFix =
+std::tuple;
+// naming component indexes of `GadgetFix`:
+constexpr const int GFFixItList = 0;
+// constexpr const int GFGadget = 1;  //unused for now
+constexpr const int GFVarDecl = 2;
+
 // Defined below.
 class Strategy;
 } // namespace
@@ -360,6 +370,115 @@
 } // namespace
 
 namespace {
+// This class represents all fixes generated in one function declaration, and
+// allows to iterate over the non-conflicting subset as well as its'
+// complementary subset (i.e., conflicting subset).  Any fix in the
+// non-conflicting subset does not conflict with any other generated fix.  Two
+// fixes conflict if their source ranges overlap.
+class NonConflictingFixes {
+private:
+  // All Fix-its:
+  const GadgetFix * const FixIts;
+
+  // Number of Fix-its;
+  const int NumFixIts;
+
+  // Indices of Fix-its in `FixIts` that shall not be emitted:
+  BitVector ConflictingFixIts;
+
+public:
+  /// \return the range of the non-conflicting `GadgetFixIt`s
+  auto nonConflictingFixIts() const {
+const GadgetFix *Begin = FixIts;
+const GadgetFix *End = FixIts + NumFixIts;
+const BitVector  = ConflictingFixIts;
+
+return llvm::make_filter_range(llvm::make_range(Begin, End),
+   [, Begin](const GadgetFix ) {
+ return !BV.test( - Begin);
+   });
+  }
+
+  /// \return the range of the conflicting `GadgetFixIt`s
+  auto conflictingFixIts() const {
+const GadgetFix *Begin = FixIts;
+const GadgetFix *End = FixIts + NumFixIts;
+std::vector Result;
+const BitVector  = ConflictingFixIts;
+
+return llvm::make_filter_range(
+llvm::make_range(Begin, End),
+[, Begin](const GadgetFix ) { return BV.test( - Begin); });
+  }
+
+  // The constructor. Populating `ConflictingFixIts` and `ConflictingGroups`:
+  NonConflictingFixes(const SourceManager ,
+   const std::vector &)
+  : FixIts(FixIts.data()), NumFixIts(FixIts.size()) {
+// To find out all conflicting hints (i.e., `FixItHint`s), we sorts the
+// source ranges of all hints and keeps "merging" adjacent ones if 

[clang] 900e807 - [OpenMP][FIX] Remove version specific check lines

2023-01-09 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2023-01-09T17:04:56-08:00
New Revision: 900e80737efd834fa034d5905f14b94c8032ed5a

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

LOG: [OpenMP][FIX] Remove version specific check lines

Added: 


Modified: 
clang/test/OpenMP/irbuilder_safelen.cpp
clang/test/OpenMP/irbuilder_safelen_order_concurrent.cpp
clang/test/OpenMP/irbuilder_simd_aligned.cpp
clang/test/OpenMP/irbuilder_simdlen.cpp
clang/test/OpenMP/irbuilder_simdlen_safelen.cpp

Removed: 




diff  --git a/clang/test/OpenMP/irbuilder_safelen.cpp 
b/clang/test/OpenMP/irbuilder_safelen.cpp
index d58ed56ba19ed..4a75b18141b58 100644
--- a/clang/test/OpenMP/irbuilder_safelen.cpp
+++ b/clang/test/OpenMP/irbuilder_safelen.cpp
@@ -242,18 +242,3 @@ void simple(float *a, float *b, int *c) {
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[LOOPVAR_ADDR]], align 8
 // CHECK-NEXT:store i32 [[ADD]], ptr [[TMP4]], align 4
 // CHECK-NEXT:ret void
-//
-//.
-// CHECK: attributes #0 = { mustprogress noinline nounwind optnone 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" 
}
-// CHECK: attributes #1 = { noinline nounwind optnone 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" 
}
-//.
-// CHECK: !0 = !{i32 1, !"wchar_size", i32 4}
-// CHECK: !1 = !{i32 7, !"openmp", i32 45}
-// CHECK: !2 = !{!"clang version 16.0.0"}
-// CHECK: !3 = distinct !{!3, !4, !5}
-// CHECK: !4 = !{!"llvm.loop.vectorize.enable", i1 true}
-// CHECK: !5 = !{!"llvm.loop.vectorize.width", i32 3}
-// CHECK: !6 = distinct !{}
-// CHECK: !7 = distinct !{!7, !8, !4}
-// CHECK: !8 = !{!"llvm.loop.parallel_accesses", !6}
-//.

diff  --git a/clang/test/OpenMP/irbuilder_safelen_order_concurrent.cpp 
b/clang/test/OpenMP/irbuilder_safelen_order_concurrent.cpp
index 9cee854748f14..16bdb9aed58a8 100644
--- a/clang/test/OpenMP/irbuilder_safelen_order_concurrent.cpp
+++ b/clang/test/OpenMP/irbuilder_safelen_order_concurrent.cpp
@@ -242,20 +242,3 @@ void simple(float *a, float *b, int *c) {
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[LOOPVAR_ADDR]], align 8
 // CHECK-NEXT:store i32 [[ADD]], ptr [[TMP4]], align 4
 // CHECK-NEXT:ret void
-//
-//.
-// CHECK: attributes #0 = { mustprogress noinline nounwind optnone 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" 
}
-// CHECK: attributes #1 = { noinline nounwind optnone 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" 
}
-//.
-// CHECK: !0 = !{i32 1, !"wchar_size", i32 4}
-// CHECK: !1 = !{i32 7, !"openmp", i32 50}
-// CHECK: !2 = !{!"clang version 16.0.0"}
-// CHECK: !3 = distinct !{}
-// CHECK: !4 = distinct !{!4, !5, !6, !7}
-// CHECK: !5 = !{!"llvm.loop.parallel_accesses", !3}
-// CHECK: !6 = !{!"llvm.loop.vectorize.enable", i1 true}
-// CHECK: !7 = !{!"llvm.loop.vectorize.width", i32 3}
-// CHECK: !8 = distinct !{}
-// CHECK: !9 = distinct !{!9, !10, !6}
-// CHECK: !10 = !{!"llvm.loop.parallel_accesses", !8}
-//.

diff  --git a/clang/test/OpenMP/irbuilder_simd_aligned.cpp 
b/clang/test/OpenMP/irbuilder_simd_aligned.cpp
index fbe54ae38bfab..b113e29d8a5d3 100644
--- a/clang/test/OpenMP/irbuilder_simd_aligned.cpp
+++ b/clang/test/OpenMP/irbuilder_simd_aligned.cpp
@@ -280,22 +280,3 @@ void simple(float *a, float *b, int *c) {
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[LOOPVAR_ADDR]], align 8
 // CHECK-NEXT:store i32 [[ADD]], ptr [[TMP4]], align 4
 // CHECK-NEXT:ret void
-//
-//.
-// CHECK: attributes #0 = { mustprogress noinline nounwind optnone 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" 
}
-// CHECK: attributes #1 = { noinline nounwind optnone 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" 
}
-// CHECK: attributes #2 = { nocallback nofree nosync nounwind willreturn 
memory(inaccessiblemem: readwrite) }
-//.
-// CHECK: !0 = !{i32 1, !"wchar_size", i32 4}
-// CHECK: !1 = !{i32 7, !"openmp", i32 50}
-// CHECK: !2 = !{!"clang version 16.0.0"}
-// CHECK: !3 = distinct !{!3, !4}
-// CHECK: !4 = !{!"llvm.loop.mustprogress"}
-// CHECK: !5 = distinct !{}
-// CHECK: !6 = distinct !{!6, !7, !8}
-// CHECK: !7 = !{!"llvm.loop.parallel_accesses", !5}
-// CHECK: !8 = !{!"llvm.loop.vectorize.enable", i1 true}
-// CHECK: !9 = distinct !{}
-// CHECK: !10 = distinct !{!10, !11, !8}
-// CHECK: !11 = !{!"llvm.loop.parallel_accesses", !9}
-//.


[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2023-01-09 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D137058#4030331 , @ChuanqiXu wrote:

> @dblaikie would you like to take a look at this?

Yep, this is still on my radar - sorry for the delays. I'll get to it.


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

https://reviews.llvm.org/D137058

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


[PATCH] D140860: [Diagnostics][NFC] Fix -Wlogical-op-parentheses warning inconsistency for const and constexpr values

2023-01-09 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D140860#4033530 , @hazohelet wrote:

> I have yet to do thorough checks using this patched clang to build 
> significant code bases.
> It will likely take quite a bit of time as I am not used to editing build 
> tool files.

FWIW a lot of build systems support setting CXXFLAGS/CFLAGS before invoking the 
build system/build generator (cmake, for instance) and respects those - so 
might be relatively easy to add a new warning flag to the build (& CXX/CC to 
set the compiler to point to your local build with the patch/changes)

> Instead, I used `grep` to find potentially newly-warned codes.
> The `grep` command is shown below. It is intended to match C/C++ codes with 
> both `&&` and `||` within which 0, 1, or 2 matching parentheses exist in a 
> single line.
> `grep -r --include=\*.cpp --include=\*.cc  --include=\*.c -e "&&[^()]*||" -e 
> "||[^()]*&&" -e "&&[^()]*([^()]*)[^()]*||" -e "||[^()]*([^()]*)[^()]*&&" -e 
> "&&[^()]*([^()]*([^()]*)[^()]*)[^()]*||" -e 
> "||[^()]*([^()]*([^()]*)[^()]*)[^()]*&&"`
>
> I applied this `grep` command to the following popular GitHub repositories 
> `NVIDIA/TensorRT`, `bulletphysics/bullet3`, `apple/foundationdb`, 
> `grpc/grpc`, `microsoft/lightgbm`, `rui314/mold`, `oneapi-src/oneTBB`, 
> `SerenityOS/serenity`, `tensorflow/tensorflow`.
> I found the 7 examples of missing parentheses at `&&` within `||` in the 
> matched strings (many of the matchings exist in preprocessor conditionals, 
> which is out of the scope of this patch)
> They are listed at the end of this comment.
> The last case in tensorflow is an `assert(a || b && "reason for the assert")` 
> known idiom and is handled correctly.
> Because the newly-warned constants are compile-time constants not dependent 
> on function arguments, the other 6 cases will also get warnings from the 
> clang before this patch.
>
> It suggests that this patch does not generate extensive new warnings in 
> existent codebases.
>
> oneTBB:
> https://github.com/oneapi-src/oneTBB/blob/e6e493f96ec8b7e2e2b4d048ed49356eb54ec2a0/examples/common/gui/xvideo.cpp#L359
> https://github.com/oneapi-src/oneTBB/blob/e6e493f96ec8b7e2e2b4d048ed49356eb54ec2a0/src/tbbmalloc/frontend.cpp#L1266
> tensorflow:
> https://github.com/tensorflow/tensorflow/blob/fb2c3b1e3140af73f949981d8428379cbb28228b/tensorflow/compiler/tf2tensorrt/convert/convert_nodes_test.cc#L4130
> https://github.com/tensorflow/tensorflow/blob/fb2c3b1e3140af73f949981d8428379cbb28228b/tensorflow/compiler/tf2tensorrt/convert/convert_nodes_test.cc#L4074
> https://github.com/tensorflow/tensorflow/blob/fb2c3b1e3140af73f949981d8428379cbb28228b/tensorflow/compiler/tf2tensorrt/convert/convert_nodes_test.cc#L9456
> https://github.com/tensorflow/tensorflow/blob/fb2c3b1e3140af73f949981d8428379cbb28228b/tensorflow/compiler/jit/deadness_analysis.cc#L1423
> https://github.com/tensorflow/tensorflow/blob/fb2c3b1e3140af73f949981d8428379cbb28228b/tensorflow/core/ir/tf_op_wrapper.cc#L25

So, based on best guess at least from grepping - you don't find any new 
instances of the warning in these code bases?


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

https://reviews.llvm.org/D140860

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


[PATCH] D139052: [NFC][Profile] Access profile through VirtualFileSystem

2023-01-09 Thread Steven Wu via Phabricator via cfe-commits
steven_wu updated this revision to Diff 487597.
steven_wu added a comment.

Address review feedback. Remove NFC from title.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139052

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/CodeGen/MIRSampleProfile.h
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
  llvm/include/llvm/ProfileData/InstrProfReader.h
  llvm/include/llvm/ProfileData/SampleProfReader.h
  llvm/include/llvm/Support/PGOOptions.h
  llvm/include/llvm/Transforms/IPO/SampleProfile.h
  llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
  llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
  llvm/lib/CodeGen/MIRSampleProfile.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Passes/PassBuilderPipelines.cpp
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/InstrProfReader.cpp
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/PGOOptions.cpp
  llvm/lib/Target/X86/X86InsertPrefetch.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/tools/llvm-cov/CodeCoverage.cpp
  llvm/tools/llvm-profdata/llvm-profdata.cpp
  llvm/tools/llvm-profgen/llvm-profgen.cpp
  llvm/tools/opt/NewPMDriver.cpp
  llvm/unittests/ProfileData/SampleProfTest.cpp

Index: llvm/unittests/ProfileData/SampleProfTest.cpp
===
--- llvm/unittests/ProfileData/SampleProfTest.cpp
+++ llvm/unittests/ProfileData/SampleProfTest.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
 #include "gtest/gtest.h"
@@ -57,8 +58,9 @@
 
   void readProfile(const Module , StringRef Profile,
StringRef RemapFile = "") {
+auto FS = vfs::getRealFileSystem();
 auto ReaderOrErr = SampleProfileReader::create(
-std::string(Profile), Context, FSDiscriminatorPass::Base,
+std::string(Profile), Context, *FS, FSDiscriminatorPass::Base,
 std::string(RemapFile));
 ASSERT_TRUE(NoError(ReaderOrErr.getError()));
 Reader = std::move(ReaderOrErr.get());
Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -31,6 +31,7 @@
 #include "llvm/Passes/StandardInstrumentations.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
@@ -333,22 +334,25 @@
bool EnableDebugify, bool VerifyDIPreserve) {
   bool VerifyEachPass = VK == VK_VerifyEachPass;
 
+  auto FS = vfs::getRealFileSystem();
   std::optional P;
   switch (PGOKindFlag) {
   case InstrGen:
-P = PGOOptions(ProfileFile, "", "", PGOOptions::IRInstr);
+P = PGOOptions(ProfileFile, "", "", FS, PGOOptions::IRInstr);
 break;
   case InstrUse:
-P = PGOOptions(ProfileFile, "", ProfileRemappingFile, PGOOptions::IRUse);
+P = PGOOptions(ProfileFile, "", ProfileRemappingFile, FS,
+   PGOOptions::IRUse);
 break;
   case SampleUse:
-P = PGOOptions(ProfileFile, "", ProfileRemappingFile,
+P = PGOOptions(ProfileFile, "", ProfileRemappingFile, FS,
PGOOptions::SampleUse);
 break;
   case NoPGO:
 if (DebugInfoForProfiling || PseudoProbeForProfiling)
-  P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
- DebugInfoForProfiling, PseudoProbeForProfiling);
+  P = PGOOptions("", "", "", nullptr, PGOOptions::NoAction,
+ PGOOptions::NoCSAction, DebugInfoForProfiling,
+ PseudoProbeForProfiling);
 else
   P = std::nullopt;
   }
@@ -363,7 +367,7 @@
 P->CSAction = PGOOptions::CSIRInstr;
 P->CSProfileGenFile = CSProfileGenFile;
   } else
-P = PGOOptions("", CSProfileGenFile, ProfileRemappingFile,
+P = PGOOptions("", CSProfileGenFile, ProfileRemappingFile, FS,
PGOOptions::NoAction, PGOOptions::CSIRInstr);
 } else /* CSPGOKindFlag == CSInstrUse */ {
   if (!P)
Index: llvm/tools/llvm-profgen/llvm-profgen.cpp

[PATCH] D141218: [clangd] Include the correct header for typeid()

2023-01-09 Thread Nathan Ridge 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 rG056d4dca7764: [clangd] Include the correct header for 
typeid() (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141218

Files:
  clang-tools-extra/clangd/IncludeFixer.cpp


Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -225,7 +225,7 @@
   case diag::err_implied_std_initializer_list_not_found:
 return only(insertHeader(""));
   case diag::err_need_header_before_typeid:
-return only(insertHeader(""));
+return only(insertHeader(""));
   case diag::err_need_header_before_placement_new:
   case diag::err_implicit_coroutine_std_nothrow_type_not_found:
 return only(insertHeader(""));


Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -225,7 +225,7 @@
   case diag::err_implied_std_initializer_list_not_found:
 return only(insertHeader(""));
   case diag::err_need_header_before_typeid:
-return only(insertHeader(""));
+return only(insertHeader(""));
   case diag::err_need_header_before_placement_new:
   case diag::err_implicit_coroutine_std_nothrow_type_not_found:
 return only(insertHeader(""));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 056d4dc - [clangd] Include the correct header for typeid()

2023-01-09 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2023-01-09T18:07:07-05:00
New Revision: 056d4dca7764d92870f717906e7edb4a9563d3cb

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

LOG: [clangd] Include the correct header for typeid()

Fixes https://github.com/clangd/clangd/issues/1449

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

Added: 


Modified: 
clang-tools-extra/clangd/IncludeFixer.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeFixer.cpp 
b/clang-tools-extra/clangd/IncludeFixer.cpp
index 25e5919b00c30..0c4d011b80372 100644
--- a/clang-tools-extra/clangd/IncludeFixer.cpp
+++ b/clang-tools-extra/clangd/IncludeFixer.cpp
@@ -225,7 +225,7 @@ std::vector IncludeFixer::fix(DiagnosticsEngine::Level 
DiagLevel,
   case diag::err_implied_std_initializer_list_not_found:
 return only(insertHeader(""));
   case diag::err_need_header_before_typeid:
-return only(insertHeader(""));
+return only(insertHeader(""));
   case diag::err_need_header_before_placement_new:
   case diag::err_implicit_coroutine_std_nothrow_type_not_found:
 return only(insertHeader(""));



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


[PATCH] D141218: [clangd] Include the correct header for typeid()

2023-01-09 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 487571.
nridge added a comment.

Remove test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141218

Files:
  clang-tools-extra/clangd/IncludeFixer.cpp


Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -225,7 +225,7 @@
   case diag::err_implied_std_initializer_list_not_found:
 return only(insertHeader(""));
   case diag::err_need_header_before_typeid:
-return only(insertHeader(""));
+return only(insertHeader(""));
   case diag::err_need_header_before_placement_new:
   case diag::err_implicit_coroutine_std_nothrow_type_not_found:
 return only(insertHeader(""));


Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -225,7 +225,7 @@
   case diag::err_implied_std_initializer_list_not_found:
 return only(insertHeader(""));
   case diag::err_need_header_before_typeid:
-return only(insertHeader(""));
+return only(insertHeader(""));
   case diag::err_need_header_before_placement_new:
   case diag::err_implicit_coroutine_std_nothrow_type_not_found:
 return only(insertHeader(""));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139737: [-Wunsafe-buffer-usage] Initiate Fix-it generation for local variable declarations

2023-01-09 Thread Jan Korous via Phabricator via cfe-commits
jkorous added inline comments.



Comment at: clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h:46
+/// The text indicating that the user needs to provide input there:
+constexpr static const char *const UserFillPlaceHolder = "...";
 } // end namespace clang

Should we rather pick something that is syntactically incorrect in C++ in order 
to prevent accidental silent corruption of the sources?
FWIW Xcode uses `<#placeholder#>` syntax.



Comment at: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp:1
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -verify %s
+// RUN: cp %s %t.cpp

I am starting to think we should split up our tests to allow for less conflicts 
between patches.
Could we please rename the file to a more specific name e. g. 
`warn-unsafe-buffer-usage-fixits-local-var-span.cpp`?



Comment at: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp:1
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -verify %s
+// RUN: cp %s %t.cpp

jkorous wrote:
> I am starting to think we should split up our tests to allow for less 
> conflicts between patches.
> Could we please rename the file to a more specific name e. g. 
> `warn-unsafe-buffer-usage-fixits-local-var-span.cpp`?
Also, let's check only correctness of the FixIts in this test.
I would remove `RUN` lines with `-verify` and `expected-warnings`.


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

https://reviews.llvm.org/D139737

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


[PATCH] D141206: [clang] [MinGW] Avoid adding /include and /lib when cross compiling

2023-01-09 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D141206#4037160 , @alvinhochun 
wrote:

> The idea sounds reasonable. I don't know mingw-w64 toolchains well enough, 
> but I'll try:
>
> How does it interact with the following conditions (lines 469-475)? They look 
> like they may be looking for a mingw-w64 sysroot, which may be ignored by the 
> new check.
>
>   else if (llvm::ErrorOr TargetSubdir = findClangRelativeSysroot(
>getDriver(), LiteralTriple, getTriple(), SubdirName))
> Base = std::string(llvm::sys::path::parent_path(TargetSubdir.get()));
>   else if (llvm::ErrorOr GPPName =
>findGcc(LiteralTriple, getTriple()))
> Base = std::string(llvm::sys::path::parent_path(
> llvm::sys::path::parent_path(GPPName.get(;

Thanks for having a look!

Those cases are taken into account here; for the case of 
`findClangRelativeSysroot`, if clang is executing in e.g. 
`/llvm-mingw/bin/clang` and it finds 
`/llvm-mingw/x86_64-w64-mingw32`, then it doesn't pick that as 
``, but it picks `/llvm-mingw`, and gets the 
`x86_64-w64-mingw32` subdir prefix included via the `SubdirName` variable.

Likewise, if `findClangRelativeSysroot` failed, but `findGcc` found 
`/usr/bin/x86_64-w64-mingw32-gcc` in `$PATH`, then it also picks `/usr` as 
`` (which is needed for finding libgcc things under `/lib/gcc`).

So for these reasons, the search can't stay entirely within `/` - and we may want to skip `/include` and `/lib` when we 
believe that's meant for a different target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141206

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


[PATCH] D138958: [clang] Better UX for Clang’s unwind-affecting attributes

2023-01-09 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 487548.
lebedev.ri marked 2 inline comments as done.
lebedev.ri added a comment.

In D138958#4037526 , @erichkeane 
wrote:

> 2 quick nits, otherwise  LFTM.

@erichkeane thank you for the review!
@aaron.ballman would you like to stamp this too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138958

Files:
  clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Builtins.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Analysis/CFG.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/CodeGen/function-attributes.c
  clang/test/CodeGen/struct-passing.c
  clang/test/CodeGenCXX/2009-05-04-PureConstNounwind.cpp
  clang/test/CodeGenCXX/exception-escape-RAII-codegen.cpp
  clang/test/CodeGenCXX/exception-escape-codegen.cpp
  clang/test/CodeGenCXX/pr58798.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCXX/warn-throw-out-noexcept-func.cpp

Index: clang/test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- clang/test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ clang/test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -9,12 +9,12 @@
   int i;
   ~B_ShouldDiag() noexcept(true) {} //no disg, no throw stmt
 };
-struct R_ShouldDiag : A_ShouldDiag {
+struct R_ShouldDiag_NoThrow : A_ShouldDiag {
   B_ShouldDiag b;
-  ~R_ShouldDiag() { // expected-note  {{destructor has a implicit non-throwing exception specification}}
+  ~R_ShouldDiag_NoThrow() { // expected-note  {{destructor has a implicit non-throwing exception specification}}
 throw 1; // expected-warning {{has a non-throwing exception specification but}}
   }
-  __attribute__((nothrow)) R_ShouldDiag() {// expected-note {{function declared non-throwing here}}
+  __attribute__((nothrow)) R_ShouldDiag_NoThrow() {// expected-note {{function declared non-throwing here}}
 throw 1;// expected-warning {{has a non-throwing exception specification but}}
   }
   void __attribute__((nothrow)) SomeThrow() {// expected-note {{function declared non-throwing here}}
@@ -24,6 +24,18 @@
throw 1; // expected-warning {{has a non-throwing exception specification but}}
   }
 };
+struct R_ShouldDiag_NoUnwind : A_ShouldDiag {
+  B_ShouldDiag b;
+  ~R_ShouldDiag_NoUnwind() { // expected-note  {{destructor has a implicit non-throwing exception specification}}
+throw 1; // expected-warning {{has a non-throwing exception specification but}}
+  }
+  __attribute__((nounwind)) R_ShouldDiag_NoUnwind() {// expected-note {{function declared non-throwing here}}
+throw 1;// expected-warning {{has a non-throwing exception specification but}}
+  }
+  void __attribute__((nounwind)) SomeThrow() {// expected-note {{function declared non-throwing here}}
+   throw 1; // expected-warning {{has a non-throwing exception specification but}}
+  }
+};
 
 struct M_ShouldNotDiag {
   B_ShouldDiag b;
@@ -240,7 +252,7 @@
   }
 }
 // As seen in p34973, this should not throw the warning.  If there is an active
-// exception, catch(...) catches everything. 
+// exception, catch(...) catches everything.
 void o_ShouldNotDiag() noexcept {
   try {
 throw;
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -115,6 +115,7 @@
 // CHECK-NEXT: NoStackProtector (SubjectMatchRule_function)
 // CHECK-NEXT: NoThreadSafetyAnalysis (SubjectMatchRule_function)
 // CHECK-NEXT: NoThrow (SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: NoUnwind (SubjectMatchRule_function)
 // CHECK-NEXT: NoUwtable (SubjectMatchRule_hasType_functionType)
 // CHECK-NEXT: NotTailCalled (SubjectMatchRule_function)
 // CHECK-NEXT: OSConsumed (SubjectMatchRule_variable_is_parameter)
Index: clang/test/CodeGenCXX/pr58798.cpp
===
--- clang/test/CodeGenCXX/pr58798.cpp
+++ /dev/null
@@ -1,186 +0,0 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --check-attributes
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-linux-gnu -fexceptions -fcxx-exceptions | FileCheck %s
-
-// CHECK: 

[PATCH] D140703: [clang][dataflow] Unify `TransferOptions` and `DataflowAnalysisContext::Options`.

2023-01-09 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h:89
+ ? DataflowAnalysisContext::Options{}
+ : llvm::Optional()}) {}
 

If we already change this code, I think we can consider replacing this with 
`std::optional` but feel free to ignore.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140703

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


[PATCH] D141324: [clang] extend external_source_symbol attribute with the USR clause

2023-01-09 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: bnbarham, ravikandhadai.
Herald added a subscriber: ributzka.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
arphaman requested review of this revision.

Allow the user to specify a concrete USR in the `external_source_symbol` 
attribute. That will let Clang's indexer to use Swift USRs for Swift 
declarations that are represented with C++ declarations.

To allow the sources to conditionally enable this new extension,  
`__has_feature` is extended in Clang:

  __has_feature(attribute_external_source_symbol_with_usr)


https://reviews.llvm.org/D141324

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Parse/Parser.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/Index/Core/external-source-symbol-attr.m
  clang/test/Parser/attr-external-source-symbol.m
  clang/test/Sema/attr-external-source-symbol.c

Index: clang/test/Sema/attr-external-source-symbol.c
===
--- clang/test/Sema/attr-external-source-symbol.c
+++ clang/test/Sema/attr-external-source-symbol.c
@@ -4,7 +4,9 @@
 
 void twoClauses(void) __attribute__((external_source_symbol(language="Swift", defined_in="module")));
 
-void fourClauses(void) __attribute__((external_source_symbol(language="Swift", defined_in="module", generated_declaration, generated_declaration))); // expected-error {{duplicate 'generated_declaration' clause in an 'external_source_symbol' attribute}}
+void fourClauses(void) __attribute__((external_source_symbol(language="Swift", defined_in="module", generated_declaration, USR="test")));
+
+void fiveClauses(void) __attribute__((external_source_symbol(language="Swift", defined_in="module", generated_declaration, generated_declaration, USR="test"))); // expected-error {{duplicate 'generated_declaration' clause in an 'external_source_symbol' attribute}}
 
 void oneClause(void) __attribute__((external_source_symbol(generated_declaration)));
 
@@ -22,8 +24,8 @@
 
 [[clang::external_source_symbol(language="Swift", defined_in="module")]] void twoClauses2(void);
 
-[[clang::external_source_symbol(language="Swift", defined_in="module", generated_declaration, generated_declaration)]] // expected-error {{duplicate 'generated_declaration' clause in an 'external_source_symbol' attribute}}
-void fourClauses2(void);
+[[clang::external_source_symbol(language="Swift", defined_in="module", USR="test", generated_declaration, generated_declaration)]] // expected-error {{duplicate 'generated_declaration' clause in an 'external_source_symbol' attribute}}
+void fiveClauses2(void);
 
 [[clang::external_source_symbol(generated_declaration)]] void oneClause2(void);
 
Index: clang/test/Parser/attr-external-source-symbol.m
===
--- clang/test/Parser/attr-external-source-symbol.m
+++ clang/test/Parser/attr-external-source-symbol.m
@@ -14,10 +14,14 @@
   CaseB __attribute__((external_source_symbol(generated_declaration, language="Swift")))
 } __attribute__((external_source_symbol(language = "Swift")));
 
+void functionCustomUSR(void) __attribute__((external_source_symbol(language="Swift", defined_in="module", generated_declaration, USR="s:6module17functionCustomUSRyyF")));
+
+void functionCustomUSR2(void) __attribute__((external_source_symbol(language="Swift", defined_in="module", USR="s:6module18functionCustomUSR2yyF", generated_declaration)));
+
 void f2(void)
-__attribute__((external_source_symbol())); // expected-error {{expected 'language', 'defined_in', or 'generated_declaration'}}
+__attribute__((external_source_symbol())); // expected-error {{expected 'language', 'defined_in', 'generated_declaration', or 'USR'}}
 void f3(void)
-__attribute__((external_source_symbol(invalid))); // expected-error {{expected 'language', 'defined_in', or 'generated_declaration'}}
+__attribute__((external_source_symbol(invalid))); // expected-error {{expected 'language', 'defined_in', 'generated_declaration', or 'USR'}}
 void f4(void)
 __attribute__((external_source_symbol(language))); // expected-error {{expected '=' after language}}
 void f5(void)
@@ -31,6 +35,8 @@
 __attribute__((external_source_symbol(language="Swift", language="Swift"))); // expected-error {{duplicate 'language' clause in an 'external_source_symbol' attribute}}
 void f9(void)
 __attribute__((external_source_symbol(defined_in="module", language="Swift", defined_in="foo"))); // expected-error {{duplicate 'defined_in' clause in an 'external_source_symbol' attribute}}
+__attribute__((external_source_symbol(defined_in="module", language="Swift", 

[PATCH] D141319: [clang][dataflow][NFC] Refine names and comments for field filtering.

2023-01-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: xazax.hun, gribozavr2, sgatev.
Herald added subscribers: martong, rnkovacs.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

Tweaks elements of the new API for filtering the set of modeled fields.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141319

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  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
@@ -253,7 +253,7 @@
 initVars(Vars);
 // These have to be set before the lines that follow to ensure that create*
 // work correctly for structs.
-DACtx.addFieldsReferencedInScope(std::move(Fields));
+DACtx.addModeledFields(Fields);
 
 for (const auto *ParamDecl : FuncDecl->parameters()) {
   assert(ParamDecl != nullptr);
@@ -342,7 +342,7 @@
   }
   getFieldsAndGlobalVars(*FuncDecl->getBody(), Fields, Vars);
   initVars(Vars);
-  DACtx->addFieldsReferencedInScope(std::move(Fields));
+  DACtx->addModeledFields(Fields);
 
   const auto *ParamIt = FuncDecl->param_begin();
 
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -25,15 +25,15 @@
 namespace clang {
 namespace dataflow {
 
-void DataflowAnalysisContext::addFieldsReferencedInScope(
-llvm::DenseSet Fields) {
-  llvm::set_union(FieldsReferencedInScope, Fields);
+void DataflowAnalysisContext::addModeledFields(
+const llvm::DenseSet ) {
+  llvm::set_union(ModeledFields, Fields);
 }
 
 llvm::DenseSet
 DataflowAnalysisContext::getReferencedFields(QualType Type) {
   llvm::DenseSet Fields = getObjectFields(Type);
-  llvm::set_intersect(Fields, FieldsReferencedInScope);
+  llvm::set_intersect(Fields, ModeledFields);
   return Fields;
 }
 
@@ -46,7 +46,7 @@
 // the allocation. Since we only collect fields used in the function where
 // the allocation occurs, we can't apply that filter when performing
 // context-sensitive analysis. But, this only applies to storage locations,
-// since fields access it not allowed to fail. In contrast, field *values*
+// since field access it not allowed to fail. In contrast, field *values*
 // don't need this allowance, since the API allows for uninitialized 
fields.
 auto Fields = Opts.ContextSensitiveOpts ? getObjectFields(Type)
 : getReferencedFields(Type);
Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -269,8 +269,6 @@
   /// returns null.
   const ControlFlowContext *getControlFlowContext(const FunctionDecl *F);
 
-  void addFieldsReferencedInScope(llvm::DenseSet Fields);
-
   const Options () { return Opts; }
 
 private:
@@ -287,8 +285,11 @@
 using DenseMapInfo::isEqual;
   };
 
-  /// Returns the subset of fields of `Type` that are referenced in the scope 
of
-  /// the analysis.
+  // Extends the set of modeled field declarations.
+  void addModeledFields(const llvm::DenseSet );
+
+  /// Returns the fields of `Type`, limited to the set of fields modeled by 
this
+  /// context.
   llvm::DenseSet getReferencedFields(QualType Type);
 
   /// Adds all constraints of the flow condition identified by `Token` and all
@@ -388,8 +389,8 @@
 
   llvm::DenseMap FunctionContexts;
 
-  // All fields referenced (statically) in the scope of the analysis.
-  llvm::DenseSet FieldsReferencedInScope;
+  // Fields modeled by environments covered by this context.
+  llvm::DenseSet ModeledFields;
 };
 
 } // namespace dataflow


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -253,7 +253,7 @@
 initVars(Vars);
 // These have to be set before the lines that follow to ensure that create*
 // work correctly for structs.
-DACtx.addFieldsReferencedInScope(std::move(Fields));
+DACtx.addModeledFields(Fields);
 
 for (const auto *ParamDecl : FuncDecl->parameters()) {
   assert(ParamDecl != nullptr);
@@ -342,7 +342,7 @@
   }
   getFieldsAndGlobalVars(*FuncDecl->getBody(), Fields, Vars);
   

[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-01-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 487539.
cor3ntin marked 24 inline comments as done.
cor3ntin added a comment.

- Address Aaron's comments (except renaming ActOnLambdaIntroducer as we pounder 
on it)
- Delete an aditional outdated comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/Scope.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1358,7 +1358,7 @@
 
   Change scope of lambda trailing-return-type
   https://wg21.link/P2036R3;>P2036R3
-  No
+  Clang 16
 
 
   https://wg21.link/P2579R0;>P2579R0
Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -95,7 +95,7 @@
 #ifdef AVOID
   auto l4 = [var = param] (int param) { ; }; // no warning
 #else
-  auto l4 = [var = param] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+  auto l4 = [var = param](int param) { ; }; // expected-warning 2{{declaration shadows a local variable}}
 #endif
 
   // Make sure that inner lambdas work as well.
Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -0,0 +1,243 @@
+// RUN: %clang_cc1 -std=c++2b -verify -fsyntax-only %s
+
+template 
+constexpr bool is_same = false;
+
+template 
+constexpr bool is_same = true;
+
+void f() {
+
+  int y;
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  auto ref = [ = y](
+ decltype([&](decltype(x)) { return 0; }) y) {
+return x;
+  };
+}
+
+void test_noexcept() {
+
+  int y;
+
+  static_assert(noexcept([x = 1] noexcept(is_same) {}()));
+  static_assert(noexcept([x = 1] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([y] noexcept(is_same) {}()));
+  static_assert(noexcept([y] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([=] noexcept(is_same) {}()));
+  static_assert(noexcept([=] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([&] noexcept(is_same) {}()));
+  static_assert(noexcept([&] mutable noexcept(is_same) {}()));
+}
+
+void test_requires() {
+
+  int x;
+
+  [x = 1]() requires is_same {}
+  ();
+  [x = 1]() mutable requires is_same {}
+  ();
+  [x]() requires is_same {}
+  ();
+  [x]() mutable requires is_same {}
+  ();
+  [=]() requires is_same {}
+  ();
+  [=]() mutable requires is_same {}
+  ();
+  [&]() requires is_same {}
+  ();
+  [&]() mutable requires is_same {}
+  ();
+  []() requires is_same {}
+  ();
+  []() mutable requires is_same {}
+  ();
+
+  [x = 1]() requires is_same {} ();
+  [x = 1]() mutable requires is_same {} ();
+}
+
+void err() {
+  int y, z;
+  (void)[x = 1]
+  requires(is_same) {};
+
+  (void)[x = 1]{};
+
+  (void)[=]{};
+
+  (void)[z]{};
+}
+
+void gnu_attributes() {
+  int y;
+  (void)[=]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))){}();
+  // expected-warning@-1 {{wrong type}} expected-note@-1{{'diagnose_if' attribute on 'operator()'}}
+  (void)[=]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))){}();
+
+  (void)[=]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))) mutable {}();
+  (void)[=]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))) mutable {}();
+  // expected-warning@-1 {{wrong type}} expected-note@-1{{'diagnose_if' attribute on 'operator()'}}
+
+
+  (void)[x=1]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))){}();
+  // expected-warning@-1 {{wrong type}} expected-note@-1{{'diagnose_if' attribute on 'operator()'}}
+  (void)[x=1]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))){}();
+
+  

[PATCH] D140703: [clang][dataflow] Unify `TransferOptions` and `DataflowAnalysisContext::Options`.

2023-01-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 487538.
ymandel added a comment.

Initialize AnalysisOptions as a struct, avoiding a use-after-move bug from 
incorrect use of the fluent (rvalue-ref) API.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140703

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

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
@@ -34,6 +35,8 @@
 using ::testing::NotNull;
 using ::testing::UnorderedElementsAre;
 
+using BuiltinOptions = DataflowAnalysisContext::Options;
+
 template 
 void runDataflow(llvm::StringRef Code, Matcher Match,
  DataflowAnalysisOptions Options,
@@ -44,15 +47,18 @@
   "-fsyntax-only", "-fno-delayed-template-parsing",
   "-std=" +
   std::string(LangStandard::getLangStandardForKind(Std).getName())};
-  auto AI =
-  AnalysisInputs(Code, hasName(TargetFun),
-   [](ASTContext , Environment &) {
- return NoopAnalysis(C, Options);
-   })
-  .withASTBuildArgs(ASTBuildArgs);
-  if (Options.BuiltinTransferOpts &&
-  Options.BuiltinTransferOpts->ContextSensitiveOpts)
-(void)std::move(AI).withContextSensitivity();
+  AnalysisInputs AI(
+  Code, hasName(TargetFun),
+  [UseBuiltinModel = Options.BuiltinOpts.has_value()](ASTContext ,
+  Environment ) {
+return NoopAnalysis(
+C, DataflowAnalysisOptions{UseBuiltinModel
+   ? Env.getAnalysisOptions()
+   : llvm::Optional()});
+  });
+  AI.ASTBuildArgs = ASTBuildArgs;
+  if (Options.BuiltinOpts)
+AI.BuiltinOptions = *Options.BuiltinOpts;
   ASSERT_THAT_ERROR(
   checkDataflow(
   std::move(AI),
@@ -69,8 +75,8 @@
  bool ApplyBuiltinTransfer = true,
  llvm::StringRef TargetFun = "target") {
   runDataflow(Code, std::move(Match),
-  {ApplyBuiltinTransfer ? TransferOptions{}
-: llvm::Optional()},
+  {ApplyBuiltinTransfer ? BuiltinOptions{}
+: llvm::Optional()},
   Std, TargetFun);
 }
 
@@ -4123,7 +4129,7 @@
 EXPECT_FALSE(Env.flowConditionImplies(FooVal));
 EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
   },
-  {TransferOptions{/*.ContextSensitiveOpts=*/std::nullopt}});
+  {BuiltinOptions{/*.ContextSensitiveOpts=*/std::nullopt}});
 }
 
 // This test is a regression test, based on a real crash.
@@ -4152,7 +4158,7 @@
 
 EXPECT_THAT(Env.getValue(*Loc), IsNull());
   },
-  {TransferOptions{ContextSensitiveOptions{}}});
+  {BuiltinOptions{ContextSensitiveOptions{}}});
 }
 
 TEST(TransferTest, ContextSensitiveDepthZero) {
@@ -4180,7 +4186,7 @@
 EXPECT_FALSE(Env.flowConditionImplies(FooVal));
 EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
   },
-  {TransferOptions{ContextSensitiveOptions{/*.Depth=*/0}}});
+  {BuiltinOptions{ContextSensitiveOptions{/*.Depth=*/0}}});
 }
 
 TEST(TransferTest, ContextSensitiveSetTrue) {
@@ -4207,7 +4213,7 @@
 auto  = *cast(Env.getValue(*FooDecl, SkipPast::None));
 EXPECT_TRUE(Env.flowConditionImplies(FooVal));
   },
-  {TransferOptions{ContextSensitiveOptions{}}});
+  {BuiltinOptions{ContextSensitiveOptions{}}});
 }
 
 TEST(TransferTest, ContextSensitiveSetFalse) {
@@ -4234,7 +4240,7 @@
 auto  = *cast(Env.getValue(*FooDecl, SkipPast::None));
 EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(FooVal)));
   },
-  {TransferOptions{ContextSensitiveOptions{}}});
+  

[PATCH] D140584: [Clang] Refactor "Designators" into a unified implementation [NFC]

2023-01-09 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: clang/include/clang/AST/Designator.h:88
+  /// An array designator, e.g., "[42] = 0" and "[42 ... 50] = 1".
+  template  struct ArrayDesignatorInfo {
+/// Location of the first and last index expression within the designated

void wrote:
> rsmith wrote:
> > Can we move the templating out from here to the whole `Designator` and 
> > `Designation` classes? It shouldn't be possible to mix the two kinds in the 
> > same `Designation`.
> Grr...My previous comment was eaten.
> 
> I'll give it a shot.
> 
> However, I'm a bit surprised at how designators are handled by Clang. I 
> expected that a `Designation` would be an `Expr` with the `Designator`s being 
> L-values (e.g. `MemberExpr`s / `ArraySubscriptExpr`s), but instead the 
> `Designation` exists just long enough to be turned into an explicit 
> initialization list. Is there a reason to do it that way instead of using 
> expressions?
So it looks like moving the template outside of the class won't work. The 
ability to switch between `Expr` and `unsigned` while retaining the same 
overall type is hardwired into things like the `ASTImporter`.

This is kind of a massive mess. Maybe we shouldn't even allow them to use both 
`Expr` and `unsigned` but instead require them to use one or the other? Maybe 
we could require `unsigned` with the understanding that the `Expr` can be 
converted into a constant?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140584

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


[PATCH] D141172: [ModuleUtils][KCFI] Set patchable-function-prefix for synthesized functions

2023-01-09 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen updated this revision to Diff 487536.
samitolvanen marked an inline comment as done.
samitolvanen added a comment.

Addressed feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141172

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/kcfi.c
  llvm/lib/Transforms/Utils/ModuleUtils.cpp
  llvm/test/Instrumentation/AddressSanitizer/kcfi-offset.ll


Index: llvm/test/Instrumentation/AddressSanitizer/kcfi-offset.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/AddressSanitizer/kcfi-offset.ll
@@ -0,0 +1,15 @@
+;; Test that we set patchable-function-prefix for asan.module_ctor when 
kcfi-offset is defined.
+
+; RUN: opt < %s -passes=asan -S | FileCheck %s
+
+; CHECK: @llvm.global_ctors = {{.*}}{ i32 1, ptr @asan.module_ctor, ptr 
@asan.module_ctor }
+
+; CHECK: define internal void @asan.module_ctor()
+; CHECK-SAME: #[[#ATTR:]]
+; CHECK-SAME: !kcfi_type
+
+; CHECK: attributes #[[#ATTR]] = { {{.*}} "patchable-function-prefix"="3" }
+
+!llvm.module.flags = !{!0, !1}
+!0 = !{i32 4, !"kcfi", i32 1}
+!1 = !{i32 4, !"kcfi-offset", i32 3}
Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp
===
--- llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -161,6 +161,13 @@
   MDNode::get(Ctx, MDB.createConstant(ConstantInt::get(
Type::getInt32Ty(Ctx),
static_cast(xxHash64(MangledType));
+  // If the module was compiled with -fpatchable-function-entry, ensure
+  // we use the same patchable-function-prefix.
+  if (auto *MD = mdconst::extract_or_null(
+  M.getModuleFlag("kcfi-offset"))) {
+if (unsigned Offset = MD->getZExtValue())
+  F.addFnAttr("patchable-function-prefix", std::to_string(Offset));
+  }
 }
 
 FunctionCallee
Index: clang/test/CodeGen/kcfi.c
===
--- clang/test/CodeGen/kcfi.c
+++ clang/test/CodeGen/kcfi.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi 
-o - %s | FileCheck %s
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi 
-x c++ -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi 
-fpatchable-function-entry-offset=3 -o - %s | FileCheck %s 
--check-prefixes=CHECK,OFFSET
 #if !__has_feature(kcfi)
 #error Missing kcfi?
 #endif
@@ -54,5 +55,6 @@
 }
 
 // CHECK-DAG: ![[#]] = !{i32 4, !"kcfi", i32 1}
+// OFFSET-DAG: ![[#]] = !{i32 4, !"kcfi-offset", i32 3}
 // CHECK-DAG: ![[#TYPE]] = !{i32 [[#HASH]]}
 // CHECK-DAG: ![[#TYPE2]] = !{i32 [[#%d,HASH2:]]}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -758,8 +758,14 @@
   CodeGenOpts.SanitizeCfiCanonicalJumpTables);
   }
 
-  if (LangOpts.Sanitize.has(SanitizerKind::KCFI))
+  if (LangOpts.Sanitize.has(SanitizerKind::KCFI)) {
 getModule().addModuleFlag(llvm::Module::Override, "kcfi", 1);
+// KCFI assumes patchable-function-prefix is the same for all indirectly
+// called functions. Store the expected offset for code generation.
+if (CodeGenOpts.PatchableFunctionEntryOffset)
+  getModule().addModuleFlag(llvm::Module::Override, "kcfi-offset",
+CodeGenOpts.PatchableFunctionEntryOffset);
+  }
 
   if (CodeGenOpts.CFProtectionReturn &&
   Target.checkCFProtectionReturnSupported(getDiags())) {


Index: llvm/test/Instrumentation/AddressSanitizer/kcfi-offset.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/AddressSanitizer/kcfi-offset.ll
@@ -0,0 +1,15 @@
+;; Test that we set patchable-function-prefix for asan.module_ctor when kcfi-offset is defined.
+
+; RUN: opt < %s -passes=asan -S | FileCheck %s
+
+; CHECK: @llvm.global_ctors = {{.*}}{ i32 1, ptr @asan.module_ctor, ptr @asan.module_ctor }
+
+; CHECK: define internal void @asan.module_ctor()
+; CHECK-SAME: #[[#ATTR:]]
+; CHECK-SAME: !kcfi_type
+
+; CHECK: attributes #[[#ATTR]] = { {{.*}} "patchable-function-prefix"="3" }
+
+!llvm.module.flags = !{!0, !1}
+!0 = !{i32 4, !"kcfi", i32 1}
+!1 = !{i32 4, !"kcfi-offset", i32 3}
Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp
===
--- llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -161,6 +161,13 @@
   MDNode::get(Ctx, MDB.createConstant(ConstantInt::get(
Type::getInt32Ty(Ctx),
static_cast(xxHash64(MangledType));
+  // If the module was compiled with 

[PATCH] D141172: [ModuleUtils][KCFI] Set patchable-function-prefix for synthesized functions

2023-01-09 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added inline comments.



Comment at: llvm/test/Instrumentation/AddressSanitizer/kcfi-offset.ll:1
+;; Test that we set patchable-function-prefix for asan.module_ctor when 
kcfi-offset is defined.
+

MaskRay wrote:
> `test/Transforms/KCFI/kcfi-patchable-function-prefix.ll` or a new file is 
> perhaps a better place for this test. It's mainly about kcfi's requirement 
> and less about asan.
That also occurred to me, but the `Transforms/KCFI` directory only contains 
tests for the KCFI pass, which doesn't support prefix nops, and this test is 
about `asan.module_ctor` with KCFI, so I thought keeping the test with 
`AddressSanitizer` tests would be more appropriate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141172

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


[PATCH] D138958: [clang] Better UX for Clang’s unwind-affecting attributes

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

2 quick nits, otherwise  LFTM.




Comment at: clang/include/clang/Basic/AttrDocs.td:558
+  let Content = [{
+A stronger version of ``__attribute__((pure))`` attribute.
+





Comment at: clang/include/clang/Basic/AttrDocs.td:565
+returning a value. They can not write to memory, but may read memory that is
+immutable between invocations of the function.
+

A quick sentence somewhere saying HOW this is a 'stronger' version of pure 
would be a good addition here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138958

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


[PATCH] D137381: [clang][compiler-rt] Exception escape out of an non-unwinding function is an undefined behaviour

2023-01-09 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137381

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


[PATCH] D138958: [clang] Better UX for Clang’s unwind-affecting attributes

2023-01-09 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.
Herald added a subscriber: StephenFan.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138958

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


[PATCH] D139737: [-Wunsafe-buffer-usage] Initiate Fix-it generation for local variable declarations

2023-01-09 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 487527.
ziqingluo-90 added a comment.

Rebase the patch with respect to the re-architecture: 
https://reviews.llvm.org/D140062.

Since we do not have any `FixableGadget` to trigger fix-its at this point,  I 
let fix-its of local variable declarations always be emitted for the purpose of 
testing.


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

https://reviews.llvm.org/D139737

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
@@ -67,21 +67,21 @@
 void testArraySubscriptsWithAuto(int *p, int **pp) {
   int a[10];
 
-  auto ap1 = a;
+  auto ap1 = a; // expected-warning{{'ap1' participates in unchecked buffer operations}}
 
   foo(ap1[1]);  // expected-warning{{unchecked operation on raw buffer in expression}}
 
-  auto ap2 = p;
+  auto ap2 = p; // expected-warning{{'ap2' participates in unchecked buffer operations}}
 
   foo(ap2[1]);  // expected-warning{{unchecked operation on raw buffer in expression}}
 
-  auto ap3 = pp;
+  auto ap3 = pp; // expected-warning{{'ap3' participates in unchecked buffer operations}}
 
   foo(ap3[1][1]); // expected-warning2{{unchecked operation on raw buffer in expression}}
 
-  auto ap4 = *pp;
+  auto ap4 = *pp; // expected-warning{{'ap4' participates in unchecked buffer operations}}
 
-  foo(ap4[1]);  // expected-warning{{unchecked operation on raw buffer in expression}}
+  foo(ap4[1]);   // expected-warning{{unchecked operation on raw buffer in expression}}
 }
 
 void testUnevaluatedContext(int * p) {
@@ -176,7 +176,7 @@
 template
 void testPointerArithmetic(int * p, const int **q, T * x) {
   int a[10];
-  auto y = [0];
+  auto y = [0];   // expected-warning{{variable 'y' participates in unchecked buffer operations}}
 
   foo(p + 1, 1 + p, p - 1,  // expected-warning3{{unchecked operation on raw buffer in expression}}
   *q + 1, 1 + *q, *q - 1,   // expected-warning3{{unchecked operation on raw buffer in expression}}
@@ -227,23 +227,23 @@
 
 void innerInner(int * p) {
   auto Lam = [p]() {
-int * q = p;
-q++;   // expected-warning{{unchecked operation on raw buffer in expression}}
+int * q = p;   // expected-warning{{variable 'q' participates in unchecked buffer operations}}
+q++;   // expected-warning{{unchecked operation on raw buffer in expression}}
 return *q;
   };
 }
   };
 
   auto Lam = [p]() {
-int * q = p;
-q++;  // expected-warning{{unchecked operation on raw buffer in expression}}
+int * q = p;  // expected-warning{{variable 'q' participates in unchecked buffer operations}}
+q++;  // expected-warning{{unchecked operation on raw buffer in expression}}
 return *q;
   };
 
   auto LamLam = [p]() {
 auto Lam = [p]() {
-  int * q = p;
-  q++;  // expected-warning{{unchecked operation on raw buffer in expression}}
+  int * q = p;  // expected-warning{{variable 'q' participates in unchecked buffer operations}}
+  q++;  // expected-warning{{unchecked operation on raw buffer in expression}}
   return *q;
 };
   };
@@ -260,8 +260,8 @@
   };
 
   // lambda and block as call arguments...
-  foo( [p]() { int * q = p;
-  q++;  // expected-warning{{unchecked operation on raw buffer in expression}}
+  foo( [p]() { int * q = p;  // expected-warning{{variable 'q' participates in unchecked buffer operations}}
+  q++;   // expected-warning{{unchecked operation on raw buffer in expression}}
   return *q;
},
^(int *p) { p++;   // expected-warning{{unchecked operation on raw buffer in expression}}
Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -verify %s
+// RUN: cp %s %t.cpp
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fixit %t.cpp
+// RUN: grep -v CHECK %t.cpp | FileCheck %s
+
+void foo(...);
+typedef int * Int_ptr_t;
+typedef int Int_t;
+
+void local_array_subscript_simple() {
+// CHECK: std::span p{new int [10], 10};
+// CHECK: p[5] = 5;
+  int *p = new int[10]; // expected-warning{{variable 'p' participates in unchecked buffer operations}}
+  p[5] = 5; // expected-warning{{unchecked operation on raw buffer in expression}}
+
+// CHECK: std::span q{new int [10], 10};
+// CHECK: std::span x{new int [10], 10};
+// CHECK: std::span y{new int, 1};
+// CHECK: std::span z{new int [10], 10};

[PATCH] D140455: [Clang] Diagnose undefined behavior in a constant expression while evaluating a compound assignment with remainder as operand

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

LGTM aside from some style nits. Can you also add a release note for the fix?




Comment at: clang/lib/AST/ExprConstant.cpp:2759-2760
   APSInt ) {
+  bool HandleOverflowResult = true;
   switch (Opcode) {
   default:





Comment at: clang/lib/AST/ExprConstant.cpp:2777-2789
   case BO_Rem:
 if (RHS == 0) {
   Info.FFDiag(E, diag::note_expr_divide_by_zero);
   return false;
 }
-Result = (Opcode == BO_Rem ? LHS % RHS : LHS / RHS);
 // Check for overflow case: INT_MIN / -1 or INT_MIN % -1. APSInt supports
 // this operation and gives the two's complement result.





Comment at: clang/test/CXX/expr/expr.const/p2-0x.cpp:304
+namespace CompoundAssignment {
+int constexpr rem() { // expected-error {{constexpr function never produces a 
constant expression}}
+int x = ~__INT_MAX__;




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

https://reviews.llvm.org/D140455

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


[PATCH] D137244: [Clang] Correctly capture bindings in dependent lambdas.

2023-01-09 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee2056e7: [Clang] Correctly capture bindings in 
dependent lambdas. (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137244

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaLambda.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/ScopeInfo.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/cxx20-decomposition.cpp

Index: clang/test/SemaCXX/cxx20-decomposition.cpp
===
--- clang/test/SemaCXX/cxx20-decomposition.cpp
+++ clang/test/SemaCXX/cxx20-decomposition.cpp
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify -Wunused-variable %s
 
 template 
 constexpr bool is_same = false;
@@ -80,7 +79,17 @@
 namespace std {
 
 template 
-struct tuple_size {
+struct tuple_size;
+
+template 
+struct tuple_size : tuple_size{};
+
+template 
+requires requires { tuple_size::value; }
+struct tuple_size : tuple_size{};
+
+template <>
+struct tuple_size {
   static constexpr unsigned long value = 2;
 };
 
@@ -139,3 +148,37 @@
 };
   }
 }
+
+namespace ODRUseTests {
+  struct P { int a; int b; };
+  void GH57826() {
+const auto [a, b] = P{1, 2}; //expected-note 2{{'b' declared here}} \
+ //expected-note 3{{'a' declared here}}
+(void)[&](auto c) { return b + [] {
+return a;
+}(); }(0);
+(void)[&](auto c) { return b + [](auto) {
+return a;
+}(0); }(0);
+(void)[=](auto c) { return b + [](auto) {
+return a;
+}(0); }(0);
+(void)[,](auto c) { return b + [](auto) {
+return a;
+}(0); }(0);
+(void)[,](auto c) { return b + [a](auto) {
+return a;
+}(0); }(0);
+(void)[](auto c) { return b + [](auto) { // expected-error 2{{variable 'b' cannot be implicitly captured}} \
+ // expected-note 2{{lambda expression begins here}} \
+ // expected-note 4{{capture 'b'}}
+return a;
+}(0); }(0); // expected-note {{in instantiation}}
+(void)[](auto c) { return b + [](auto) {   // expected-note 3{{lambda expression begins here}} \
+ // expected-note 6{{capture 'a'}} \
+ // expected-note 6{{default capture}} \
+ // expected-note {{in instantiation}}
+return a;  // expected-error 3{{variable 'a' cannot be implicitly captured}}
+}(0); }(0); // expected-note 2{{in instantiation}}
+  }
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -13399,9 +13399,8 @@
 }
 
 // Transform the captured variable.
-VarDecl *CapturedVar
-  = cast_or_null(getDerived().TransformDecl(C->getLocation(),
- C->getCapturedVar()));
+auto *CapturedVar = cast_or_null(
+getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
   Invalid = true;
   continue;
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -62,7 +62,7 @@
 static inline Optional
 getStackIndexOfNearestEnclosingCaptureReadyLambda(
 ArrayRef FunctionScopes,
-VarDecl *VarToCapture) {
+ValueDecl *VarToCapture) {
   // Label failure to capture.
   const Optional NoLambdaIsCaptureReady;
 
@@ -172,7 +172,7 @@
 
 Optional clang::getStackIndexOfNearestEnclosingCaptureCapableLambda(
 ArrayRef FunctionScopes,
-VarDecl *VarToCapture, Sema ) {
+ValueDecl *VarToCapture, Sema ) {
 
   const Optional NoLambdaIsCaptureCapable;
 
@@ -1232,11 +1232,7 @@
 if (Var->isInvalidDecl())
   continue;
 
-VarDecl *Underlying;
-if (auto *BD = dyn_cast(Var))
-  Underlying = dyn_cast(BD->getDecomposedDecl());
-else
-  Underlying = cast(Var);
+VarDecl *Underlying = Var->getPotentiallyDecomposedVarDecl();
 
 if (!Underlying->hasLocalStorage()) {
   Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ 

[clang] e1111e2 - [Clang] Correctly capture bindings in dependent lambdas.

2023-01-09 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-01-09T21:20:57+01:00
New Revision: ee2056e7245b21e24816f6f7ef5ac016ed6f

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

LOG: [Clang] Correctly capture bindings in dependent lambdas.

Structured bindings were not properly marked odr-used
and therefore captured in generic lambddas.

Fixes #57826

It is unclear to me if further simplification can be gained
through the allowance described in
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0588r1.html.

Either way, I think this makes support for P0588 completes,
but we probably want to add test for that in a separate PR.
(and I lack confidence I understand P0588 sufficiently to assert
the completeness of our cnformance).

Reviewed By: aaron.ballman, #clang-language-wg

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

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/SemaLambda.h
clang/lib/AST/DeclCXX.cpp
clang/lib/Sema/ScopeInfo.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaCXX/cxx20-decomposition.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 3ae2703a406ee..7a710b36c91f2 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -695,6 +695,8 @@ class NamespaceDecl : public NamedDecl, public DeclContext,
   }
 };
 
+class VarDecl;
+
 /// Represent the declaration of a variable (in which case it is
 /// an lvalue) a function (in which case it is a function designator) or
 /// an enum constant.
@@ -721,6 +723,13 @@ class ValueDecl : public NamedDecl {
   /// can be captured.
   bool isInitCapture() const;
 
+  // If this is a VarDecl, or a BindindDecl with an
+  // associated decomposed VarDecl, return that VarDecl.
+  VarDecl *getPotentiallyDecomposedVarDecl();
+  const VarDecl *getPotentiallyDecomposedVarDecl() const {
+return const_cast(this)->getPotentiallyDecomposedVarDecl();
+  }
+
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }

diff  --git a/clang/include/clang/Sema/ScopeInfo.h 
b/clang/include/clang/Sema/ScopeInfo.h
index 613749f2da3ff..363fbf454879d 100644
--- a/clang/include/clang/Sema/ScopeInfo.h
+++ b/clang/include/clang/Sema/ScopeInfo.h
@@ -1028,7 +1028,7 @@ class LambdaScopeInfo final :
   }
 
   void visitPotentialCaptures(
-  llvm::function_ref Callback) const;
+  llvm::function_ref Callback) const;
 };
 
 FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6c0d950eb929c..fd60a1f9ac43e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5409,7 +5409,7 @@ class Sema final {
   void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr);
   void MarkMemberReferenced(MemberExpr *E);
   void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E);
-  void MarkCaptureUsedInEnclosingContext(VarDecl *Capture, SourceLocation Loc,
+  void MarkCaptureUsedInEnclosingContext(ValueDecl *Capture, SourceLocation 
Loc,
  unsigned CapturingScopeIndex);
 
   ExprResult CheckLValueToRValueConversionOperand(Expr *E);

diff  --git a/clang/include/clang/Sema/SemaLambda.h 
b/clang/include/clang/Sema/SemaLambda.h
index e8eaa46b88a20..494568722d9f7 100644
--- a/clang/include/clang/Sema/SemaLambda.h
+++ b/clang/include/clang/Sema/SemaLambda.h
@@ -32,7 +32,7 @@ class Sema;
 
 Optional getStackIndexOfNearestEnclosingCaptureCapableLambda(
 ArrayRef FunctionScopes,
-VarDecl *VarToCapture, Sema );
+ValueDecl *VarToCapture, Sema );
 
 } // clang
 

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1576c27a463fe..3cf355714107c 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -3249,6 +3249,16 @@ StaticAssertDecl 
*StaticAssertDecl::CreateDeserialized(ASTContext ,
   nullptr, SourceLocation(), false);
 }
 
+VarDecl *ValueDecl::getPotentiallyDecomposedVarDecl() {
+  assert((isa(this)) &&
+ "expected a VarDecl or a BindingDecl");
+  if (auto *Var = llvm::dyn_cast(this))
+return Var;
+  if (auto *BD = llvm::dyn_cast(this))
+return llvm::dyn_cast(BD->getDecomposedDecl());
+  return nullptr;
+}
+
 void BindingDecl::anchor() {}
 
 BindingDecl *BindingDecl::Create(ASTContext , DeclContext *DC,

diff  --git 

[PATCH] D140794: [ASTMatcher] Add coroutineBodyStmt matcher

2023-01-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for this! FWIW, it looks like precommit CI found some issues that 
need to be resolved.




Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:5503
+  FunctionDecl,
+  CoroutineBodyStmt),
   internal::Matcher, InnerMatcher) {

I'm not certain it makes sense to me to add `CoroutineBodyStmt` to `hasBody` -- 
in this case, it doesn't *have* a body, it *is* the body.



Comment at: clang/lib/ASTMatchers/Dynamic/Registry.cpp:171
   REGISTER_MATCHER(compoundStmt);
+  REGISTER_MATCHER(coroutineBodyStmt);
   REGISTER_MATCHER(coawaitExpr);

Please keep this sorted alphabetically.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140794

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


[PATCH] D141226: [WIP][clangd] support expanding `decltype(expr)`

2023-01-09 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 487519.
v1nh1shungry added a comment.
Herald added projects: clang, LLVM.
Herald added a subscriber: llvm-commits.

rename the tweak `ExpandAutoType` to `ExpandDeducedType`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141226

Files:
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandDeducedType.cpp
  clang-tools-extra/clangd/test/check-fail.test
  clang-tools-extra/clangd/test/check-lines.test
  clang-tools-extra/clangd/test/check.test
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/test/request-reply.test
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
  clang/docs/tools/clang-formatted-files.txt
  llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
@@ -129,7 +129,7 @@
 "tweaks/DumpASTTests.cpp",
 "tweaks/DumpRecordLayoutTests.cpp",
 "tweaks/DumpSymbolTests.cpp",
-"tweaks/ExpandAutoTypeTests.cpp",
+"tweaks/ExpandDeducedTypeTests.cpp",
 "tweaks/ExpandMacroTests.cpp",
 "tweaks/ExtractFunctionTests.cpp",
 "tweaks/ExtractVariableTests.cpp",
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/refactor/tweaks/BUILD.gn
@@ -18,7 +18,7 @@
 "DefineInline.cpp",
 "DefineOutline.cpp",
 "DumpAST.cpp",
-"ExpandAutoType.cpp",
+"ExpandDeducedType.cpp",
 "ExpandMacro.cpp",
 "ExtractFunction.cpp",
 "ExtractVariable.cpp",
Index: clang/docs/tools/clang-formatted-files.txt
===
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -1611,7 +1611,7 @@
 clang-tools-extra/clangd/unittests/tweaks/DumpASTTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/DumpRecordLayoutTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/DumpSymbolTests.cpp
-clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/ExpandMacroTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
 clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
Index: clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
===
--- clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
+++ clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
@@ -25,9 +25,9 @@
 // Fixture base for testing tweaks. Intended to be subclassed for each tweak.
 //
 // Usage:
-// TWEAK_TEST(ExpandAutoType);
+// TWEAK_TEST(ExpandDeducedType);
 //
-// TEST_F(ExpandAutoTypeTest, ShortensTypes) {
+// TEST_F(ExpandDeducedTypeTest, ShortensTypes) {
 //   Header = R"cpp(
 // namespace foo { template class X{}; }
 // using namespace foo;
Index: clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp
@@ -1,4 +1,4 @@
-//===-- ExpandAutoTypeTests.cpp -*- C++ -*-===//
+//===-- ExpandDeducedTypeTests.cpp --*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -16,9 +16,9 @@
 namespace clangd {
 namespace {
 
-TWEAK_TEST(ExpandAutoType);
+TWEAK_TEST(ExpandDeducedType);
 
-TEST_F(ExpandAutoTypeTest, Test) {
+TEST_F(ExpandDeducedTypeTest, Test) {
   Header = R"cpp(
 namespace ns {
   struct Class {
@@ -50,7 +50,10 @@
   StartsWith("fail: Could not deduce type for 'auto' type"));
   // function pointers should not be replaced
   EXPECT_THAT(apply("au^to x = ::Func;"),
-  StartsWith("fail: Could not expand type of function pointer"));
+  StartsWith("fail: Could not expand type of function"));
+  // function 

[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2023-01-09 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

ping.


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

https://reviews.llvm.org/D137107

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


[PATCH] D141158: [OpenMP] Introduce '-f[no-]openmp-target-jit' flag to control JIT for offloading

2023-01-09 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141158

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


[PATCH] D140584: [Clang] Refactor "Designators" into a unified implementation [NFC]

2023-01-09 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: clang/include/clang/AST/Designator.h:88
+  /// An array designator, e.g., "[42] = 0" and "[42 ... 50] = 1".
+  template  struct ArrayDesignatorInfo {
+/// Location of the first and last index expression within the designated

rsmith wrote:
> Can we move the templating out from here to the whole `Designator` and 
> `Designation` classes? It shouldn't be possible to mix the two kinds in the 
> same `Designation`.
Grr...My previous comment was eaten.

I'll give it a shot.

However, I'm a bit surprised at how designators are handled by Clang. I 
expected that a `Designation` would be an `Expr` with the `Designator`s being 
L-values (e.g. `MemberExpr`s / `ArraySubscriptExpr`s), but instead the 
`Designation` exists just long enough to be turned into an explicit 
initialization list. Is there a reason to do it that way instead of using 
expressions?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140584

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


[PATCH] D140703: [clang][dataflow] Unify `TransferOptions` and `DataflowAnalysisContext::Options`.

2023-01-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 487516.
ymandel added a comment.

rebasing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140703

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

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
@@ -34,6 +35,8 @@
 using ::testing::NotNull;
 using ::testing::UnorderedElementsAre;
 
+using BuiltinOptions = DataflowAnalysisContext::Options;
+
 template 
 void runDataflow(llvm::StringRef Code, Matcher Match,
  DataflowAnalysisOptions Options,
@@ -45,14 +48,18 @@
   "-std=" +
   std::string(LangStandard::getLangStandardForKind(Std).getName())};
   auto AI =
-  AnalysisInputs(Code, hasName(TargetFun),
-   [](ASTContext , Environment &) {
- return NoopAnalysis(C, Options);
-   })
+  AnalysisInputs(
+  Code, hasName(TargetFun),
+  [UseBuiltinModel = Options.BuiltinOpts.has_value()](
+  ASTContext , Environment ) {
+return NoopAnalysis(C, DataflowAnalysisOptions{
+   UseBuiltinModel
+   ? Env.getAnalysisOptions()
+   : llvm::Optional()});
+  })
   .withASTBuildArgs(ASTBuildArgs);
-  if (Options.BuiltinTransferOpts &&
-  Options.BuiltinTransferOpts->ContextSensitiveOpts)
-(void)std::move(AI).withContextSensitivity();
+  if (Options.BuiltinOpts)
+(void)std::move(AI).withBuiltinOptions(*Options.BuiltinOpts);
   ASSERT_THAT_ERROR(
   checkDataflow(
   std::move(AI),
@@ -69,8 +76,8 @@
  bool ApplyBuiltinTransfer = true,
  llvm::StringRef TargetFun = "target") {
   runDataflow(Code, std::move(Match),
-  {ApplyBuiltinTransfer ? TransferOptions{}
-: llvm::Optional()},
+  {ApplyBuiltinTransfer ? BuiltinOptions{}
+: llvm::Optional()},
   Std, TargetFun);
 }
 
@@ -4123,7 +4130,7 @@
 EXPECT_FALSE(Env.flowConditionImplies(FooVal));
 EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
   },
-  {TransferOptions{/*.ContextSensitiveOpts=*/std::nullopt}});
+  {BuiltinOptions{/*.ContextSensitiveOpts=*/std::nullopt}});
 }
 
 // This test is a regression test, based on a real crash.
@@ -4152,7 +4159,7 @@
 
 EXPECT_THAT(Env.getValue(*Loc), IsNull());
   },
-  {TransferOptions{ContextSensitiveOptions{}}});
+  {BuiltinOptions{ContextSensitiveOptions{}}});
 }
 
 TEST(TransferTest, ContextSensitiveDepthZero) {
@@ -4180,7 +4187,7 @@
 EXPECT_FALSE(Env.flowConditionImplies(FooVal));
 EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
   },
-  {TransferOptions{ContextSensitiveOptions{/*.Depth=*/0}}});
+  {BuiltinOptions{ContextSensitiveOptions{/*.Depth=*/0}}});
 }
 
 TEST(TransferTest, ContextSensitiveSetTrue) {
@@ -4207,7 +4214,7 @@
 auto  = *cast(Env.getValue(*FooDecl, SkipPast::None));
 EXPECT_TRUE(Env.flowConditionImplies(FooVal));
   },
-  {TransferOptions{ContextSensitiveOptions{}}});
+  {BuiltinOptions{ContextSensitiveOptions{}}});
 }
 
 TEST(TransferTest, ContextSensitiveSetFalse) {
@@ -4234,7 +4241,7 @@
 auto  = *cast(Env.getValue(*FooDecl, SkipPast::None));
 EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(FooVal)));
   },
-  {TransferOptions{ContextSensitiveOptions{}}});
+  {BuiltinOptions{ContextSensitiveOptions{}}});
 }
 
 TEST(TransferTest, ContextSensitiveSetBothTrueAndFalse) {
@@ -4271,7 +4278,7 @@
 EXPECT_FALSE(Env.flowConditionImplies(BarVal));

[PATCH] D140694: [clang][dataflow] Only model struct fields that are used in the function being analyzed.

2023-01-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel closed this revision.
ymandel added a comment.

Committed: https://reviews.llvm.org/rG01ccf7b3cee58dbe02fd97696cae1781746b6137


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140694

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


[clang] 01ccf7b - Revert "Revert "[clang][dataflow] Only model struct fields that are used in the function being analyzed.""

2023-01-09 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2023-01-09T19:32:10Z
New Revision: 01ccf7b3cee58dbe02fd97696cae1781746b6137

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

LOG: Revert "Revert "[clang][dataflow] Only model struct fields that are used 
in the function being analyzed.""

This reverts commit 2b1a517a92bfdfa3b692a660e19a2bb22513a567. It's a fix forward
with two memory errors fixed, one of which was the cause of the build breakage
in the buildbots.

Original message:

Previously, the model for structs modeled all fields in a struct when
`createValue` was called for that type. This patch adds a prepass on the
function under analysis to discover the fields referenced in the scope and then
limits modeling to only those fields. This reduces wasted memory usage
(modeling unused fields) which can be important for programs that use large
structs.

Note: This patch obviates the need for https://reviews.llvm.org/D123032.

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index f8ee5864482b..98135508aabb 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -54,14 +54,21 @@ llvm::DenseSet getObjectFields(QualType 
Type);
 /// is used during dataflow analysis.
 class DataflowAnalysisContext {
 public:
+  // FIXME: merge with TransferOptions from Transfer.h.
+  struct Options {
+bool EnableContextSensitiveAnalysis;
+  };
+
   /// Constructs a dataflow analysis context.
   ///
   /// Requirements:
   ///
   ///  `S` must not be null.
-  DataflowAnalysisContext(std::unique_ptr S)
+  DataflowAnalysisContext(std::unique_ptr S,
+  Options Opts = {
+  /*EnableContextSensitiveAnalysis=*/false})
   : S(std::move(S)), TrueVal(createAtomicBoolValue()),
-FalseVal(createAtomicBoolValue()) {
+FalseVal(createAtomicBoolValue()), Options(Opts) {
 assert(this->S != nullptr);
   }
 
@@ -253,7 +260,11 @@ class DataflowAnalysisContext {
   /// returns null.
   const ControlFlowContext *getControlFlowContext(const FunctionDecl *F);
 
+  void addFieldsReferencedInScope(llvm::DenseSet Fields);
+
 private:
+  friend class Environment;
+
   struct NullableQualTypeDenseMapInfo : private llvm::DenseMapInfo {
 static QualType getEmptyKey() {
   // Allow a NULL `QualType` by using a 
diff erent value as the empty key.
@@ -265,6 +276,10 @@ class DataflowAnalysisContext {
 using DenseMapInfo::isEqual;
   };
 
+  /// Returns the subset of fields of `Type` that are referenced in the scope 
of
+  /// the analysis.
+  llvm::DenseSet getReferencedFields(QualType Type);
+
   /// Adds all constraints of the flow condition identified by `Token` and all
   /// of its transitive dependencies to `Constraints`. `VisitedTokens` is used
   /// to track tokens of flow conditions that were already visited by recursive
@@ -330,6 +345,8 @@ class DataflowAnalysisContext {
   AtomicBoolValue 
   AtomicBoolValue 
 
+  Options Options;
+
   // Indices that are used to avoid recreating the same composite boolean
   // values.
   llvm::DenseMap, ConjunctionValue *>
@@ -359,6 +376,9 @@ class DataflowAnalysisContext {
   llvm::DenseMap FlowConditionConstraints;
 
   llvm::DenseMap FunctionContexts;
+
+  // All fields referenced (statically) in the scope of the analysis.
+  llvm::DenseSet FieldsReferencedInScope;
 };
 
 } // namespace dataflow

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index c1653c2ab4ed..fbc5f6d2c889 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -452,6 +452,9 @@ class Environment {
   void pushCallInternal(const FunctionDecl *FuncDecl,
 ArrayRef Args);
 
+  /// Assigns storage locations and values to all variables in `Vars`.
+  void initVars(llvm::DenseSet Vars);
+
   // `DACtx` is not null and not owned by this object.
   DataflowAnalysisContext *DACtx;
 

diff  --git 

[PATCH] D141310: [clang] add -Wcompare-function-pointers

2023-01-09 Thread Adrian Dole via Phabricator via cfe-commits
adriandole updated this revision to Diff 487511.
adriandole added a comment.

Release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141310

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/compare-function-pointer.cpp


Index: clang/test/SemaCXX/compare-function-pointer.cpp
===
--- clang/test/SemaCXX/compare-function-pointer.cpp
+++ clang/test/SemaCXX/compare-function-pointer.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify 
-Wcompare-function-pointers %s
 
 using fp0_t = void (*)();
 using fp1_t = int (*)();
@@ -6,16 +6,16 @@
 extern fp0_t a, b;
 extern fp1_t c;
 
-bool eq0 = a == b;
-bool ne0 = a != b;
+bool eq0 = a == b;  // expected-warning {{comparison of function pointers}}
+bool ne0 = a != b;  // expected-warning {{comparison of function pointers}}
 bool lt0 = a < b;   // expected-warning {{ordered comparison of function 
pointers ('fp0_t' (aka 'void (*)()') and 'fp0_t')}}
 bool le0 = a <= b;  // expected-warning {{ordered comparison of function 
pointers}}
 bool gt0 = a > b;   // expected-warning {{ordered comparison of function 
pointers}}
 bool ge0 = a >= b;  // expected-warning {{ordered comparison of function 
pointers}}
 auto tw0 = a <=> b; // expected-error {{ordered comparison of function 
pointers}}
 
-bool eq1 = a == c;  // expected-error {{comparison of distinct pointer types}}
-bool ne1 = a != c;  // expected-error {{comparison of distinct pointer types}}
+bool eq1 = a == c;  // expected-error {{comparison of distinct pointer types}} 
expected-warning {{comparison of function pointers}}
+bool ne1 = a != c;  // expected-error {{comparison of distinct pointer types}} 
expected-warning {{comparison of function pointers}}
 bool lt1 = a < c;   // expected-warning {{ordered comparison of function 
pointers ('fp0_t' (aka 'void (*)()') and 'fp1_t' (aka 'int (*)()'))}}
 // expected-error@-1 {{comparison of distinct pointer 
types}}
 bool le1 = a <= c;  // expected-warning {{ordered comparison of function 
pointers}}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -12711,6 +12711,13 @@
LHS.get()->getSourceRange());
   }
 
+  if (!IsOrdered && LHSType->isFunctionPointerType() &&
+  RHSType->isFunctionPointerType() && !LHSIsNull && !RHSIsNull) {
+Diag(Loc, diag::warn_typecheck_comparison_of_function_pointers)
+  << LHSType << 0
+  << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
+  }
+
   if (IsOrdered && LHSType->isFunctionPointerType() &&
   RHSType->isFunctionPointerType()) {
 // Valid unless a relational comparison of function pointers
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7002,6 +7002,9 @@
   "%0 is %select{|in}2complete and "
   "%1 is %select{|in}3complete">,
   InGroup;
+def warn_typecheck_comparison_of_function_pointers : Warning<
+  "comparison of function pointers (%0 and %1)">,
+  InGroup, DefaultIgnore;
 def warn_typecheck_ordered_comparison_of_function_pointers : Warning<
   "ordered comparison of function pointers (%0 and %1)">,
   InGroup;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -561,6 +561,7 @@
 def UnderalignedExceptionObject : DiagGroup<"underaligned-exception-object">;
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
+def CompareFunctionPointers : DiagGroup<"compare-function-pointers">;
 def OrderedCompareFunctionPointers : 
DiagGroup<"ordered-compare-function-pointers">;
 def PackedNonPod : DiagGroup<"packed-non-pod">;
 def Packed : DiagGroup<"packed", [PackedNonPod]>;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -447,6 +447,8 @@
   ``#pragma clang __debug sloc_usage`` can also be used to request this report.
 - Clang no longer permits the keyword 'bool' in a concept declaration as a
   concepts-ts compatibility extension.
+- Add ``-Wcompare-function-pointers`` to warn about comparisons that may have
+  their behavior change when using ``icf=all``.
 
 Non-comprehensive list of changes in this release
 

[PATCH] D140694: [clang][dataflow] Only model struct fields that are used in the function being analyzed.

2023-01-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 487506.
ymandel added a comment.

fix memory error that cause buildbot failures

Fixes a self-move assign. This operation should be safe, but is known to cause
problems in some implementations of the standard library. The patch drops the
assignment, which was unnecessary since the object is modified in place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140694

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -16,6 +16,7 @@
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Basic/LangStandard.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Testing/Support/Error.h"
@@ -39,17 +40,22 @@
  LangStandard::Kind Std = LangStandard::lang_cxx17,
  llvm::StringRef TargetFun = "target") {
   using ast_matchers::hasName;
+  llvm::SmallVector ASTBuildArgs = {
+  "-fsyntax-only", "-fno-delayed-template-parsing",
+  "-std=" +
+  std::string(LangStandard::getLangStandardForKind(Std).getName())};
+  auto AI =
+  AnalysisInputs(Code, hasName(TargetFun),
+   [](ASTContext , Environment &) {
+ return NoopAnalysis(C, Options);
+   })
+  .withASTBuildArgs(ASTBuildArgs);
+  if (Options.BuiltinTransferOpts &&
+  Options.BuiltinTransferOpts->ContextSensitiveOpts)
+(void)std::move(AI).withContextSensitivity();
   ASSERT_THAT_ERROR(
   checkDataflow(
-  AnalysisInputs(Code, hasName(TargetFun),
-   [Options](ASTContext , Environment &) {
- return NoopAnalysis(C, Options);
-   })
-  .withASTBuildArgs(
-  {"-fsyntax-only", "-fno-delayed-template-parsing",
-   "-std=" +
-   std::string(LangStandard::getLangStandardForKind(Std)
-   .getName())}),
+  std::move(AI),
   /*VerifyResults=*/
   [](const llvm::StringMap>
,
@@ -151,6 +157,7 @@
 
 void target() {
   A Foo;
+  (void)Foo.Bar;
   // [[p]]
 }
   )";
@@ -198,6 +205,7 @@
 
 void target() {
   A Foo = Gen();
+  (void)Foo.Bar;
   // [[p]]
 }
   )";
@@ -238,11 +246,13 @@
 TEST(TransferTest, ClassVarDecl) {
   std::string Code = R"(
 class A {
+ public:
   int Bar;
 };
 
 void target() {
   A Foo;
+  (void)Foo.Bar;
   // [[p]]
 }
   )";
@@ -336,6 +346,10 @@
 
 void target() {
   A  = getA();
+  (void)Foo.Bar.FooRef;
+  (void)Foo.Bar.FooPtr;
+  (void)Foo.Bar.BazRef;
+  (void)Foo.Bar.BazPtr;
   // [[p]]
 }
   )";
@@ -478,6 +492,10 @@
 
 void target() {
   A *Foo = getA();
+  (void)Foo->Bar->FooRef;
+  (void)Foo->Bar->FooPtr;
+  (void)Foo->Bar->BazRef;
+  (void)Foo->Bar->BazPtr;
   // [[p]]
 }
   )";
@@ -891,7 +909,7 @@
 };
 
 void target(A Foo) {
-  (void)0;
+  (void)Foo.Bar;
   // [[p]]
 }
   )";
@@ -1052,6 +1070,9 @@
   int APrivate;
 public:
   int APublic;
+
+private:
+  friend void target();
 };
 
 class B : public A {
@@ -1060,10 +1081,20 @@
   int BProtected;
 private:
   int BPrivate;
+
+private:
+  friend void target();
 };
 
 void target() {
   B Foo;
+  (void)Foo.ADefault;
+  (void)Foo.AProtected;
+  (void)Foo.APrivate;
+  (void)Foo.APublic;
+  (void)Foo.BDefault;
+  (void)Foo.BProtected;
+  (void)Foo.BPrivate;
   // [[p]]
 }
   )";
@@ -1202,6 +1233,7 @@
 
 void target() {
   B Foo;
+  (void)Foo.Bar;
   // [[p]]
 }
   )";
@@ -1525,7 +1557,11 @@
   int Bar;
 
   void target() {
-(void)0; // [[p]]
+A a;
+// Mention the fields to ensure they're included in the analysis.
+(void)a.Foo;
+(void)a.Bar;
+// [[p]]
   }
 };
   )";
@@ -1777,6 +1813,7 @@
 
 void target() {
   A Foo 

[PATCH] D141310: [clang] add -Wcompare-function-pointers

2023-01-09 Thread Adrian Dole via Phabricator via cfe-commits
adriandole created this revision.
Herald added a project: All.
adriandole requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Using `icf=all` with lld can cause comparisons between function pointers that 
previously compared as unequal to compare as equal. This warning is disabled by 
default, since it's only relevant if ICF is explicitly enabled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141310

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/compare-function-pointer.cpp


Index: clang/test/SemaCXX/compare-function-pointer.cpp
===
--- clang/test/SemaCXX/compare-function-pointer.cpp
+++ clang/test/SemaCXX/compare-function-pointer.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify 
-Wcompare-function-pointers %s
 
 using fp0_t = void (*)();
 using fp1_t = int (*)();
@@ -6,16 +6,16 @@
 extern fp0_t a, b;
 extern fp1_t c;
 
-bool eq0 = a == b;
-bool ne0 = a != b;
+bool eq0 = a == b;  // expected-warning {{comparison of function pointers}}
+bool ne0 = a != b;  // expected-warning {{comparison of function pointers}}
 bool lt0 = a < b;   // expected-warning {{ordered comparison of function 
pointers ('fp0_t' (aka 'void (*)()') and 'fp0_t')}}
 bool le0 = a <= b;  // expected-warning {{ordered comparison of function 
pointers}}
 bool gt0 = a > b;   // expected-warning {{ordered comparison of function 
pointers}}
 bool ge0 = a >= b;  // expected-warning {{ordered comparison of function 
pointers}}
 auto tw0 = a <=> b; // expected-error {{ordered comparison of function 
pointers}}
 
-bool eq1 = a == c;  // expected-error {{comparison of distinct pointer types}}
-bool ne1 = a != c;  // expected-error {{comparison of distinct pointer types}}
+bool eq1 = a == c;  // expected-error {{comparison of distinct pointer types}} 
expected-warning {{comparison of function pointers}}
+bool ne1 = a != c;  // expected-error {{comparison of distinct pointer types}} 
expected-warning {{comparison of function pointers}}
 bool lt1 = a < c;   // expected-warning {{ordered comparison of function 
pointers ('fp0_t' (aka 'void (*)()') and 'fp1_t' (aka 'int (*)()'))}}
 // expected-error@-1 {{comparison of distinct pointer 
types}}
 bool le1 = a <= c;  // expected-warning {{ordered comparison of function 
pointers}}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -12711,6 +12711,13 @@
LHS.get()->getSourceRange());
   }
 
+  if (!IsOrdered && LHSType->isFunctionPointerType() &&
+  RHSType->isFunctionPointerType() && !LHSIsNull && !RHSIsNull) {
+Diag(Loc, diag::warn_typecheck_comparison_of_function_pointers)
+  << LHSType << 0
+  << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
+  }
+
   if (IsOrdered && LHSType->isFunctionPointerType() &&
   RHSType->isFunctionPointerType()) {
 // Valid unless a relational comparison of function pointers
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7002,6 +7002,9 @@
   "%0 is %select{|in}2complete and "
   "%1 is %select{|in}3complete">,
   InGroup;
+def warn_typecheck_comparison_of_function_pointers : Warning<
+  "comparison of function pointers (%0 and %1)">,
+  InGroup, DefaultIgnore;
 def warn_typecheck_ordered_comparison_of_function_pointers : Warning<
   "ordered comparison of function pointers (%0 and %1)">,
   InGroup;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -561,6 +561,7 @@
 def UnderalignedExceptionObject : DiagGroup<"underaligned-exception-object">;
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
+def CompareFunctionPointers : DiagGroup<"compare-function-pointers">;
 def OrderedCompareFunctionPointers : 
DiagGroup<"ordered-compare-function-pointers">;
 def PackedNonPod : DiagGroup<"packed-non-pod">;
 def Packed : DiagGroup<"packed", [PackedNonPod]>;


Index: clang/test/SemaCXX/compare-function-pointer.cpp
===
--- clang/test/SemaCXX/compare-function-pointer.cpp
+++ clang/test/SemaCXX/compare-function-pointer.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify 

[PATCH] D141051: [CUDA][HIP] Add support for `--offload-arch=native` to CUDA and refactor

2023-01-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 487503.
jhuber6 added a comment.

Fix typo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141051

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/test/Driver/Inputs/nvptx-arch/nvptx_arch_fail
  clang/test/Driver/Inputs/nvptx-arch/nvptx_arch_sm_70
  clang/test/Driver/amdgpu-hip-system-arch.c
  clang/test/Driver/amdgpu-openmp-system-arch-fail.c
  clang/test/Driver/nvptx-cuda-system-arch.c

Index: clang/test/Driver/nvptx-cuda-system-arch.c
===
--- /dev/null
+++ clang/test/Driver/nvptx-cuda-system-arch.c
@@ -0,0 +1,27 @@
+// REQUIRES: system-linux
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+// REQUIRES: shell
+
+// RUN: mkdir -p %t
+// RUN: cp %S/Inputs/nvptx-arch/nvptx_arch_fail %t/
+// RUN: cp %S/Inputs/nvptx-arch/nvptx_arch_sm_70 %t/
+// RUN: echo '#!/bin/sh' > %t/nvptx_arch_empty
+// RUN: chmod +x %t/nvptx_arch_fail
+// RUN: chmod +x %t/nvptx_arch_sm_70
+// RUN: chmod +x %t/nvptx_arch_empty
+
+// case when nvptx-arch returns nothing or fails
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib --offload-arch=native --nvptx-arch-tool=%t/nvptx_arch_fail -x cuda %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=NO-OUTPUT-ERROR
+// NO-OUTPUT-ERROR: error: cannot determine nvptx64 architecture{{.*}}; consider passing it via '--offload-arch'
+
+// case when nvptx-arch does not return anything with successful execution
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib --offload-arch=native --nvptx-arch-tool=%t/nvptx_arch_empty -x cuda %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=EMPTY-OUTPUT
+// EMPTY-OUTPUT: error: cannot determine nvptx64 architecture: No NVIDIA GPU detected in the system; consider passing it via '--offload-arch'
+
+// case when nvptx-arch does not return anything with successful execution
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib --offload-arch=native --nvptx-arch-tool=%t/nvptx_arch_sm_70 -x cuda %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=ARCH-sm_70
+// ARCH-sm_70: "-cc1" "-triple" "nvptx64-nvidia-cuda"{{.*}}"-target-cpu" "sm_70"
Index: clang/test/Driver/amdgpu-openmp-system-arch-fail.c
===
--- clang/test/Driver/amdgpu-openmp-system-arch-fail.c
+++ clang/test/Driver/amdgpu-openmp-system-arch-fail.c
@@ -15,14 +15,14 @@
 // case when amdgpu_arch returns nothing or fails
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib --amdgpu-arch-tool=%t/amdgpu_arch_fail %s 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=NO-OUTPUT-ERROR
-// NO-OUTPUT-ERROR: error: cannot determine AMDGPU architecture{{.*}}Exited with error code 1; consider passing it via '--march'
+// NO-OUTPUT-ERROR: error: cannot determine amdgcn architecture{{.*}}; consider passing it via '-march'
 
 // case when amdgpu_arch returns multiple gpus but all are different
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib --amdgpu-arch-tool=%t/amdgpu_arch_different %s 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=MULTIPLE-OUTPUT-ERROR
-// MULTIPLE-OUTPUT-ERROR: error: cannot determine AMDGPU architecture: Multiple AMD GPUs found with different archs; consider passing it via '--march'
+// MULTIPLE-OUTPUT-ERROR: error: cannot determine amdgcn architecture: Multiple AMD GPUs found with different archs; consider passing it via '-march'
 
 // case when amdgpu_arch does not return anything with successful execution
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib --amdgpu-arch-tool=%t/amdgpu_arch_empty %s 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=EMPTY-OUTPUT
-// EMPTY-OUTPUT: error: cannot determine AMDGPU architecture: No AMD GPU detected in the system; consider passing it via '--march'
+// EMPTY-OUTPUT: error: cannot determine amdgcn architecture: No AMD GPU detected in the system; consider passing it via '-march'
Index: clang/test/Driver/amdgpu-hip-system-arch.c
===
--- /dev/null
+++ clang/test/Driver/amdgpu-hip-system-arch.c
@@ -0,0 +1,27 @@
+// REQUIRES: system-linux
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+// REQUIRES: shell
+
+// RUN: mkdir -p %t
+// RUN: cp %S/Inputs/amdgpu-arch/amdgpu_arch_fail %t/
+// RUN: cp 

[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-01-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/DeclCXX.h:1834-1846
+  void setLambdaTypeInfo(TypeSourceInfo *TS) {
+auto *DD = DefinitionData;
+assert(DD && DD->IsLambda && "setting lambda property of non-lambda 
class");
+auto  = static_cast(*DD);
+DL.MethodTyInfo = TS;
+  }
+

Minor simplification



Comment at: clang/include/clang/Sema/Scope.h:148
+/// This is the scope for a lambda, after the lambda introducer.
+/// Lambdas need 2 FunctionPrototypeScope scopes (because there is a
+/// template scope in between), the outer scope does not increase the





Comment at: clang/include/clang/Sema/ScopeInfo.h:854-857
   /// Whether this is a mutable lambda.
-  bool Mutable = false;
+  /// Until the mutable keyword is parsed,
+  /// we assume the lambda is mutable
+  bool Mutable = true;

Re-flow comment (I might have gotten that wrong) and add a full stop at the end 
of the comment.



Comment at: clang/include/clang/Sema/Sema.h:7115-7119
+  /// Once the Lambdas capture are known, we can
+  /// start to create the closure, call operator method,
+  /// and keep track of the captures.
+  /// We do the capture lookup here, but they are not actually captured
+  /// until after we know what the qualifiers of the call operator are.

You can re-flow this comment to 80 col as well.



Comment at: clang/include/clang/Sema/Sema.h:7238
+  /// Introduce the instantiated captures of the lambda into the local
+  /// instantiation scope
+  bool addInstantiatedCapturesToScope(





Comment at: clang/lib/Parse/ParseExprCXX.cpp:1293
   Actions.PushLambdaScope();
+  Actions.ActOnLambdaIntroducer(Intro, getCurScope());
 

Typically, we call an `ActOn` method after having parsed the construct; in this 
case, we're calling `ActOnLambdaIntroducer()` when it was parsed elsewhere 
(this is the parsing code for after the introducer). So perhaps this should be 
moved elsewhere or renamed?



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1381
+  SourceLocation MutableLoc;
+  LateParsedAttrList LateParsedAttrs(true);
+

This isn't being used?



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1387-1393
+// However, because GNU attributes could refer to captured variables,
+// which only become visible after the mutable keyword is parsed
+// we delay the parsing of gnu attributes - by reusing the mechanism used
+// for C++ late method parsing. Note, __declspec attributes do not make
+// use of late parsing (expressions cannot appear in __declspec arguments),
+// so only GNU style attributes are affected here.
+MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);

The comment doesn't seem to match the code -- this isn't parsing into the late 
parsed attribute list?



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1521-1523
+  if (HasParentheses || HasSpecifiers) {
+ParseConstexprAndMutableSpecifiers();
   }





Comment at: clang/lib/Parse/ParseExprCXX.cpp:1527-1529
+  if (!HasParentheses) {
+Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
+  }





Comment at: clang/lib/Sema/SemaConcept.cpp:503-505
+  const CXXRecordDecl *LambdaClass = 
cast(Function)->getParent();
+  const CXXRecordDecl *LambdaPattern =
+  cast(PatternDecl)->getParent();





Comment at: clang/lib/Sema/SemaConcept.cpp:508-509
+  unsigned Instantiated = 0;
+  for (unsigned I = 0; I < LambdaPattern->capture_size(); I++) {
+const LambdaCapture *CapturePattern = LambdaPattern->getCapture(I);
+if (!CapturePattern->capturesVariable()) {





Comment at: clang/lib/Sema/SemaConcept.cpp:584-588
+  if (isLambdaCallOperator(FD)) {
+if (addInstantiatedCapturesToScope(FD, 
FromMemTempl->getTemplatedDecl(),
+   Scope, MLTAL))
+  return true;
+  }





Comment at: clang/lib/Sema/SemaConcept.cpp:615-618
+if (isLambdaCallOperator(FD)) {
+  if (addInstantiatedCapturesToScope(FD, InstantiatedFrom, Scope, MLTAL))
+return true;
+}





Comment at: clang/lib/Sema/SemaLambda.cpp:449-452
+if (!LSI->ReturnType->isDependentType() && !LSI->ReturnType->isVoidType()) 
{
+  S.RequireCompleteType(CallOperator->getBeginLoc(), LSI->ReturnType,
+diag::err_lambda_incomplete_result);
+}





Comment at: clang/lib/Sema/SemaLambda.cpp:875-877
 if (!FTI.hasMutableQualifier() && !IsLambdaStatic) {
-  FTI.getOrCreateMethodQualifiers().SetTypeQual(DeclSpec::TQ_const,
-  

[PATCH] D133289: [C2X] N3007 Type inference for object definitions

2023-01-09 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

It surprised me that there are no type inference messages? The type of this 
auto is double. I only found warnings of misuse of auto and codegen tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133289

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


[PATCH] D141051: [CUDA][HIP] Add support for `--offload-arch=native` to CUDA and refactor

2023-01-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/test/Driver/amdgpu-hip-system-arch.c:24
+
+// case when amdgpu_arch does not return anything with successful execution
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib 
--offload-arch=native --amdgpu-arch-tool=%t/amdgpu_arch_gfx906 -x hip %s 2>&1 \

yaxunl wrote:
> comment incorrect?
Yes, thanks for catching that. I'll fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141051

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


[PATCH] D141206: [clang] [MinGW] Avoid adding /include and /lib when cross compiling

2023-01-09 Thread Alvin Wong via Phabricator via cfe-commits
alvinhochun added a comment.

The idea sounds reasonable. I don't know mingw-w64 toolchains well enough, but 
I'll try:

How does it interact with the following conditions (lines 469-475)? They look 
like they may be looking for a mingw-w64 sysroot, which may be ignored by the 
new check.

  else if (llvm::ErrorOr TargetSubdir = findClangRelativeSysroot(
   getDriver(), LiteralTriple, getTriple(), SubdirName))
Base = std::string(llvm::sys::path::parent_path(TargetSubdir.get()));
  else if (llvm::ErrorOr GPPName =
   findGcc(LiteralTriple, getTriple()))
Base = std::string(llvm::sys::path::parent_path(
llvm::sys::path::parent_path(GPPName.get(;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141206

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


[PATCH] D141051: [CUDA][HIP] Add support for `--offload-arch=native` to CUDA and refactor

2023-01-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/Driver/amdgpu-hip-system-arch.c:24
+
+// case when amdgpu_arch does not return anything with successful execution
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib 
--offload-arch=native --amdgpu-arch-tool=%t/amdgpu_arch_gfx906 -x hip %s 2>&1 \

comment incorrect?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141051

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-09 Thread Ben Boeckel via Phabricator via cfe-commits
ben.boeckel added a comment.

In D137534#4037064 , @jansvoboda11 
wrote:

> Another thing to be aware of is that the scanner is tuned for scanning 
> multiple TUs. Single `clang-scan-deps` invocation maintains a shared 
> in-memory cache of the filesystem between its threads for all TUs it's given. 
> This means invoking `clang-scan-deps` once for each TU is not as efficient as 
> it could be. At Apple, we only use `clang-scan-deps` for the in-tree tests. 
> In production, we actually wrap the C++ interface and expose a libclang API 
> that is able to take advantage of caching to improve performance. To be 
> honest, I'm surprised `clang-scan-deps` is being integrated into build 
> systems as-is, especially without utilizing the cache. How's the performance 
> looking for larger projects?

I originally investigated (and ended up lost) for something like GCC where 
P1689  information is extracted via `-E 
-fdep-file=p1689.json -fdep-output=module.o -fdep-format=p1689` (which is 
"abusing" `-E`, but works), but using `clang-scan-deps` was where we ended up 
after a more-knowledgeable LLVM developer took over knowing what needed to be 
done.

>> - because it is a rule that can itself read extra files that affect the 
>> scanning; this is the `-MF`-style output so that make/ninja can know "oh, 
>> frabnitz.h changed, it can affect the scan results in glom.ddi, so I will 
>> rescan")
>
> I see. So the P1689  output is the primary 
> scanner output, but you're also relying on emitting `.d` files to track the 
> actual FS dependencies.

Yes, that's exactly it. It'd be great if *every* command had `-MF`-style 
information for more accurate builds, but I'll roll that rock up another hill 
some other day.

>> The object can be obtained from the `-o` on the command line, but the rest 
>> is "lying" if it is extracted from the clang command line and not given to 
>> `clang-scan-deps` directly.
>
> I see your point. But since `clang-scan-deps` is built around reusing the 
> same FS cache for scanning multiple TUs, you'd need to specify these 
> arguments (that we currently extract from Clang command line) for all of 
> those TUs. That's not very convenient, neither through the command line nor 
> via a separate config file.

While batch scanning is probably better for one-shot (basically, CI) builds, I 
suspect the excess work during development/incremental builds will cause that 
to "lose" over a long enough time span.


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

https://reviews.llvm.org/D137534

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


[PATCH] D139534: [analyzer] Don't escape local static memregions on bind

2023-01-09 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.

In D139534#4036783 , @steakhal wrote:

> In D139534#4034719 , @xazax.hun 
> wrote:
>
>>> Here is the gist of one *new* TP:
>>
>> Where would `sprops` get escaped? Did I miss that or was that reduced out of 
>> the example?
>
> You are right, it 'never' escapes, yet in the past we modelled all stores to 
> local statics as an 'immediate escape'.
> This is what I think we should not do. And this is what this patch removes.

Oh, now I understand. Yeah, I guess the idea was that we only have escape 
information for the current path, but the static's address might have escaped 
in another path that we did not process. Overall, I think those cases should be 
rare, so I do support this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139534

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


[PATCH] D141307: [WIP] Add -f[no-]loop-versioning option

2023-01-09 Thread Mats Petersson via Phabricator via cfe-commits
Leporacanthicus created this revision.
Herald added a reviewer: awarzynski.
Herald added projects: Flang, All.
Leporacanthicus requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert, MaskRay.
Herald added a project: clang.

Posted to satisfy depenences of another patch. Still work in progress.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141307

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.def
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/tools/bbc/bbc.cpp
  flang/tools/tco/tco.cpp

Index: flang/tools/tco/tco.cpp
===
--- flang/tools/tco/tco.cpp
+++ flang/tools/tco/tco.cpp
@@ -122,7 +122,7 @@
   fir::createDefaultFIRCodeGenPassPipeline(pm);
 } else {
   // Run tco with O2 by default.
-  fir::createMLIRToLLVMPassPipeline(pm, llvm::OptimizationLevel::O2);
+  fir::createMLIRToLLVMPassPipeline(pm, false, llvm::OptimizationLevel::O2);
 }
 fir::addLLVMDialectToLLVMPass(pm, out.os());
   }
Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -273,7 +273,8 @@
 pm.addPass(std::make_unique());
 
 // Add O2 optimizer pass pipeline.
-fir::createDefaultFIROptimizerPassPipeline(pm, llvm::OptimizationLevel::O2);
+fir::createDefaultFIROptimizerPassPipeline(pm, false,
+   llvm::OptimizationLevel::O2);
   }
 
   if (mlir::succeeded(pm.run(mlirModule))) {
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -541,7 +541,7 @@
   pm.enableVerifier(/*verifyPasses=*/true);
 
   // Create the pass pipeline
-  fir::createMLIRToLLVMPassPipeline(pm, level);
+  fir::createMLIRToLLVMPassPipeline(pm, opts.LoopVersioning, level);
   mlir::applyPassManagerCLOptions(pm);
 
   // run the pass manager
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -126,6 +126,11 @@
clang::driver::options::OPT_fno_debug_pass_manager, false))
 opts.DebugPassManager = 1;
 
+  if (args.hasFlag(clang::driver::options::OPT_floop_versioning,
+   clang::driver::options::OPT_fno_loop_versioning, false)) {
+opts.LoopVersioning = 1;
+  }
+
   for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
 opts.LLVMPassPlugins.push_back(a->getValue());
 
Index: flang/include/flang/Frontend/CodeGenOptions.def
===
--- flang/include/flang/Frontend/CodeGenOptions.def
+++ flang/include/flang/Frontend/CodeGenOptions.def
@@ -24,6 +24,7 @@
 CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
///< pass manager.
 
+CODEGENOPT(LoopVersioning, 1, 0) ///< PIC level of the LLVM module.
 CODEGENOPT(PICLevel, 2, 0) ///< PIC level of the LLVM module.
 CODEGENOPT(IsPIE, 1, 0) ///< PIE level is the same as PIC Level.
 
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -57,6 +57,12 @@
options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
options::OPT_std_EQ, options::OPT_W_Joined,
options::OPT_fconvert_EQ, options::OPT_fpass_plugin_EQ});
+  Arg *loopVersioning =
+  Args.getLastArg(options::OPT_Ofast, options::OPT_floop_versioning,
+  options::OPT_fno_loop_versioning);
+  if (loopVersioning &&
+  !loopVersioning->getOption().matches(options::OPT_fno_loop_versioning))
+CmdArgs.push_back("-floop-versioning");
 }
 
 void Flang::addPicOptions(const ArgList , ArgStringList ) const {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5052,6 +5052,11 @@
 def fno_automatic : Flag<["-"], "fno-automatic">, Group,
   HelpText<"Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE">;
 
+def floop_versioning : Flag<["-"], "floop-versioning">, Group,
+  HelpText<"Attempt to version loops">;
+def fno_loop_versioning : Flag<["-"], "fno-loop-versioning">, Group,
+  HelpText<"Do not version loops (default)">;
+
 } // let Flags = [FC1Option, FlangOption, FlangOnlyOption]
 
 def J : JoinedOrSeparate<["-"], "J">,

[PATCH] D139168: [C++20] [Modules] [ClangScanDeps] Enable to print make-style dependency file within P1689 format (4/4)

2023-01-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:775
+static llvm::StringMap OSs;
+std::unique_lock LockGuard(Lock);
+

How will this work when a different process tries to write the same file? Could 
we write into a temporary file and then do atomic rename?


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

https://reviews.llvm.org/D139168

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


[PATCH] D140547: Perform access checking to private members in simple requirement.

2023-01-09 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

I think the only major problem is not checking for error case when accessing 
`TransReq`, the rest are NITs.
Thanks for the change! Will be happy to LGTM it as soon as the access to 
`TransReq` is fixed.




Comment at: clang/lib/Parse/ParseExprCXX.cpp:3512
   ParseScope BodyScope(this, Scope::DeclScope);
+  ParsingDeclRAIIObject ParsingBodyDecl(*this, 
ParsingDeclRAIIObject::NoParent);
   RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(

NIT: could you add a comment explaining that we need this helper in order to 
capture dependent diagnostics properly?



Comment at: clang/lib/Sema/SemaConcept.cpp:1005
   } else if (auto *RE = dyn_cast(SubstExpr)) {
+// TODO(usx): Store and diagnose dependent diagnositcs here.
 for (concepts::Requirement *Req : RE->getRequirements())

NIT: `s/Store/RequiresExpr should store dependent diagnostics`. I was confused 
at first and thought we need to store something in this function rather than 
the other place.
NIT2: Use of `FIXME` is more common in LLVM.
NIT3:  Google LDAP `usx` might be trickier to find in LLVM communication 
channels, I suggest removing it completely or using a full name instead.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:1373
+SemaRef.PerformDependentDiagnostics(E->getBody(), TemplateArgs);
+// TODO(usx): Store SFINAE diagnostics in RequiresExpr for diagnosis.
+if (Trap.hasErrorOccurred())

NIT: LLVM uses FIXME more often. 



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:1375
+if (Trap.hasErrorOccurred())
+  TransReq.getAs()->setSatisfied(false);
+  }

`TransReq` may be `ExprError` and this will cause a crash. Worth adding a test 
too.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:1375
+if (Trap.hasErrorOccurred())
+  TransReq.getAs()->setSatisfied(false);
+  }

ilya-biryukov wrote:
> `TransReq` may be `ExprError` and this will cause a crash. Worth adding a 
> test too.
Could you please add `assert(!TransReq || *TransReq != E)`.
The common optimization in TreeTransform is to avoid rebuilding the AST nodes 
if nothing changes. There is no optimization like this for `RequireExpr` right 
now, but it would not be unexpected if this gets implemented in the future.

In those situations, the current code can potentially change value of 
`isSatisfied` for an existing expression rather than for a newly created, which 
seems like asking for trouble. It would be nice to give an early warning to 
implementors of this optimization that they should think how to handle this 
case.



Comment at: 
clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp:235
+void test() {
+  // TODO: Propagate diagnostic.
+  Use::foo(); //expected-error {{invalid reference to function 'foo': 
constraints not satisfied}}

NIT: FIXME


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140547

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D137534#4025898 , @ben.boeckel 
wrote:

> - the format supports doing this for a set of object files (but given the way 
> it tangles the dep graph, is unlikely to be a perf win for 
> incremental/developer builds; CI may prefer it, but that can be future work)

Another thing to be aware of is that the scanner is tuned for scanning multiple 
TUs. Single `clang-scan-deps` invocation maintains a shared in-memory cache of 
the filesystem between its threads for all TUs it's given. This means invoking 
`clang-scan-deps` once for each TU is not as efficient as it could be. At 
Apple, we only use `clang-scan-deps` for the in-tree tests. In production, we 
actually wrap the C++ interface and expose a libclang API that is able to take 
advantage of caching to improve performance. To be honest, I'm surprised 
`clang-scan-deps` is being integrated into build systems as-is, especially 
without utilizing the cache. How's the performance looking for larger projects?

> - because it is a rule that can itself read extra files that affect the 
> scanning; this is the `-MF`-style output so that make/ninja can know "oh, 
> frabnitz.h changed, it can affect the scan results in glom.ddi, so I will 
> rescan")

I see. So the P1689  output is the primary 
scanner output, but you're also relying on emitting `.d` files to track the 
actual FS dependencies.

> The object can be obtained from the `-o` on the command line, but the rest is 
> "lying" if it is extracted from the clang command line and not given to 
> `clang-scan-deps` directly.

I see your point. But since `clang-scan-deps` is built around reusing the same 
FS cache for scanning multiple TUs, you'd need to specify these arguments (that 
we currently extract from Clang command line) for all of those TUs. That's not 
very convenient, neither through the command line nor via a separate config 
file.




Comment at: clang/test/ClangScanDeps/P1689.cppm:11
+// RUN: clang-scan-deps -format=p1689 \
+// RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/M.cppm -o 
%t/M.o \
+// RUN:   | FileCheck %t/M.cppm -DPREFIX=%/t

I'm fairly happy with the `clang-scan-deps` interface now (besides the 
performance aspect mentioned in another comment).

@ChuanqiXu what would happen if you run this Clang command line directly?


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

https://reviews.llvm.org/D137534

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


[PATCH] D131306: [llvm][misexpect] Track provenance of branch weights

2023-01-09 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added a comment.

@tejohnson @xur I kind of dropped the ball on these patches, but what are your 
thoughts on this approach over the old(more invasive) change to the profdata 
format I had prototyped before? the patch will obviously need to be rebased, 
but other than that, do we see a downside to handling provenance tracking for 
branch weights this way?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131306

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/ClangScanDeps/P1689.cppm:9
+//
+// Check the seperated dependency format.
+// RUN: clang-scan-deps -format=p1689 --p1689-targeted-file-name=%t/M.cppm 
--p1689-targeted-output=%t/M.o \

ben.boeckel wrote:
> jansvoboda11 wrote:
> > What does "separated" mean in this context?
> Yeah, this isn't the right term. There are two things being done:
> 
> - discovering dependencies for a future compile (P1689)
> - collecting deps for the scanning itself to know that "if included file X 
> changes, I need to rescan"
> 
> Both are required for correct builds.
@ChuanqiXu Can you write up a better comment here?



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:571-581
+
+  // FIXME: createInvocation will drop the `-o` option since it requires
+  // `-fsyntax-only`. So here we try to parse the output file manually.
+  auto CommandLineIter =
+  std::find(CommandLine.rbegin(), CommandLine.rend(), StringRef("-o"));
+  if (CommandLineIter == CommandLine.rend() ||
+  --CommandLineIter == CommandLine.rend()) {

ChuanqiXu wrote:
> ChuanqiXu wrote:
> > Here is the corresponding code: 
> > https://github.com/llvm/llvm-project/blob/0e11d65a58da32311b562ecea2b5ba9d4d655659/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp#L39-L43.
> >  There is another FIXME.
> > 
> > Simply, we will lost the output file by using `createInvocation` and I feel 
> > it is not easy to fix. Then I feel it is not too bad to parse `-o` manually 
> > here if we document it clearly.  I understand the current style will miss 
> > some cases like using `-output=`, `-output` instead of `-o` or missing 
> > `-o`. But I don't feel too bad for it.
> `createInvocation` will be helpful to recognize many cases, e.g., `-MF` in 
> https://reviews.llvm.org/D139168. I feel it'll be worse if we don't use 
> `createInvocation `.
This is again doing ad-hoc parsing of the command-line. `clang-cl` accepts 
output file path in the `/o` argument, which this code will not recognize. You 
should be able to use `CompilerInvocation::CreateFromArgs()` to avoid having 
the `-fsyntax-only` option injected.


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

https://reviews.llvm.org/D137534

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


[PATCH] D137244: [Clang] Correctly capture bindings in dependent lambdas.

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

LGTM assuming precommit CI doesn't discover any problems from the latest 
changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137244

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


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

2023-01-09 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

@nikic : gentle ping :-)


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

https://reviews.llvm.org/D140800

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


[PATCH] D140699: [OptTable] Make ValuesCode initialisation of Options constexpr

2023-01-09 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.
Herald added a subscriber: StephenFan.

@nikic: gentle ping


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

https://reviews.llvm.org/D140699

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


[PATCH] D141298: Move from llvm::makeArrayRef to ArrayRef deduction guides - last part

2023-01-09 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

Seems mechanical, and if it build everywhere LGTM :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141298

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


[PATCH] D141198: [Clang][RISCV][NFC] Reorganize test case for rvv intrinsics

2023-01-09 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Please split vmulh* from vmul.c. Remove the vmul tests from the handcrafted 
vmul.c and vmul-eew64.c. Rename those to vmulh.c and vmulh-eew64.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141198

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


[PATCH] D139168: [C++20] [Modules] [ClangScanDeps] Enable to print make-style dependency file within P1689 format (4/4)

2023-01-09 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added a comment.

> Header units have even more need to be involved in the build graph than named 
> units. ODR violations and cache invalidation problems await anyone just 
> winging it on header units (at least that's the understanding I've gotten 
> from SG15 meetings).

I think that latter claim applies equally to all module units. The ODR 
violation and cache invalidation concerns sometimes associated with header 
units occur in implicit module build systems in which a header unit might be 
built multiple times with different sets of options that result in an ODR 
violation. The same problem can occur with other kinds of module units if they 
are built multiple times with different options and then imported by distinct 
TUs that are then linked together. The general rule is, given a set of TUs that 
will be linked together, all imported module units should be built exactly one 
time.


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

https://reviews.llvm.org/D139168

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


[PATCH] D72103: [Sema] Avoid using an invalid InsertPos

2023-01-09 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.
Herald added a project: All.

It looks like the original bug no longer reproduces: 
https://github.com/llvm/llvm-project/issues/42566

Is this PR still needed?


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

https://reviews.llvm.org/D72103

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


[PATCH] D141298: Move from llvm::makeArrayRef to ArrayRef deduction guides - last part

2023-01-09 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.
Herald added subscribers: Michael137, JDevlieghere.

Once that patch lands, I'll mark `makeArrayRef` as deprecated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141298

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


[PATCH] D139774: [libclang] Add API to set temporary directory location

2023-01-09 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy marked an inline comment as not done.
vedgy added a comment.

In D139774#4036496 , @aaron.ballman 
wrote:

> In terms of the C API, I think it'd make more sense to name in terms of 
> "override" rather than "set", but I don't feel as strongly about it given the 
> other setters. In terms of the C++ file system API, I think "override" makes 
> the most sense though (we don't have setters to follow the naming convention 
> for) because some systems do allow you to set the system directory.

Let's keep the naming in C and C++ APIs consistent: 
`clang_overrideTemporaryDirectory()` and 
`override_system_temp_directory_erased_on_reboot()`.

> In terms of memory ownership, WDYT of requiring the caller to handle this? 
> e.g., calling `set_system_temp_directory_erased_on_reboot` will `strdup` a 
> nonnull pointer and `free` the stored pointer when given nullptr.

I like this idea. libclang-user code would become easier to use than it is now 
(though less easy compared to libclang managing memory itself). The libclang 
API documentation can require overriding the temp directory before creating an 
index and un-overriding it with `nullptr` after calling `clang_disposeIndex()`.
Now in order to make this libclang API harder to misuse, I lean towards passing 
the temporary directory in `clang_createIndexWithTempDir()` and letting 
`clang_disposeIndex()` handle the un-overriding (call 
`override_system_temp_directory_erased_on_reboot(nullptr)`) automatically. 
Makes sense? I feel that the `clang_createIndexWithTempDir()` name could be 
improved, but don't know how...

What memory [de]allocation method should 
`override_system_temp_directory_erased_on_reboot()` use? `new[]` and 
`delete[]`? Or should `strdup()` from POSIX be used because it is defined as 
`_strdup` on Windows? (along with standard `free()`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139774

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


[PATCH] D140086: [analyzer][solver] Improve reasoning for not equal to operator

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

Sorry, I don't have the time this week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140086

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


[PATCH] D141297: [OpenCL] Allow undefining header-only features

2023-01-09 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: Anastasia, FMarno.
Herald added subscribers: Naghasan, ldrumm, yaxunl.
Herald added a project: All.
svenvh requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`opencl-c-base.h` always defines 5 particular feature macros for
SPIR-V, making it impossible to disable those features.

To allow disabling any of those features, let the header recognize
`__undef_` macros.  The user can then pass the
`-D__undef_` flag on the command line to disable a specific
feature.  The `__undef` macro could potentially also be set from
`-cl-ext=-feature`, but for now only change the header and only
provide `__undef` macros for the 5 features that are always enabled in
`opencl-c-base.h`.

This is an alternative to https://reviews.llvm.org/D137652


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141297

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/test/SemaOpenCL/features.cl


Index: clang/test/SemaOpenCL/features.cl
===
--- clang/test/SemaOpenCL/features.cl
+++ clang/test/SemaOpenCL/features.cl
@@ -26,6 +26,15 @@
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=clc++1.0 \
 // RUN:   | FileCheck -match-full-lines %s  --check-prefix=NO-FEATURES
 
+// For OpenCL C 3.0, header-only features can be disabled using macros.
+// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header \
+// RUN:-D__undef___opencl_c_work_group_collective_functions=1 \
+// RUN:-D__undef___opencl_c_atomic_order_seq_cst=1 \
+// RUN:-D__undef___opencl_c_atomic_scope_device=1 \
+// RUN:-D__undef___opencl_c_atomic_scope_all_devices=1 \
+// RUN:-D__undef___opencl_c_read_write_images=1 \
+// RUN:   | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES
+
 // Note that __opencl_c_int64 is always defined assuming
 // always compiling for FULL OpenCL profile
 
@@ -43,14 +52,20 @@
 // FEATURES: #define __opencl_c_subgroups 1
 
 // NO-FEATURES: #define __opencl_c_int64 1
-// NO-FEATURES-NOT: __opencl_c_3d_image_writes
-// NO-FEATURES-NOT: __opencl_c_atomic_order_acq_rel
-// NO-FEATURES-NOT: __opencl_c_atomic_order_seq_cst
-// NO-FEATURES-NOT: __opencl_c_device_enqueue
-// NO-FEATURES-NOT: __opencl_c_fp64
-// NO-FEATURES-NOT: __opencl_c_generic_address_space
-// NO-FEATURES-NOT: __opencl_c_images
-// NO-FEATURES-NOT: __opencl_c_pipes
-// NO-FEATURES-NOT: __opencl_c_program_scope_global_variables
-// NO-FEATURES-NOT: __opencl_c_read_write_images
-// NO-FEATURES-NOT: __opencl_c_subgroups
+// NO-FEATURES-NOT: #define __opencl_c_3d_image_writes
+// NO-FEATURES-NOT: #define __opencl_c_atomic_order_acq_rel
+// NO-FEATURES-NOT: #define __opencl_c_atomic_order_seq_cst
+// NO-FEATURES-NOT: #define __opencl_c_device_enqueue
+// NO-FEATURES-NOT: #define __opencl_c_fp64
+// NO-FEATURES-NOT: #define __opencl_c_generic_address_space
+// NO-FEATURES-NOT: #define __opencl_c_images
+// NO-FEATURES-NOT: #define __opencl_c_pipes
+// NO-FEATURES-NOT: #define __opencl_c_program_scope_global_variables
+// NO-FEATURES-NOT: #define __opencl_c_read_write_images
+// NO-FEATURES-NOT: #define __opencl_c_subgroups
+
+// NO-HEADERONLY-FEATURES-NOT: #define 
__opencl_c_work_group_collective_functions
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_atomic_order_seq_cst
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_atomic_scope_device
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_atomic_scope_all_devices
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_read_write_images
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -74,6 +74,25 @@
 #define __opencl_c_atomic_scope_all_devices 1
 #define __opencl_c_read_write_images 1
 #endif // defined(__SPIR__)
+
+// Undefine any feature macros that have been explicitly disabled using
+// an __undef_ macro.
+#ifdef __undef___opencl_c_work_group_collective_functions
+#undef __opencl_c_work_group_collective_functions
+#endif
+#ifdef __undef___opencl_c_atomic_order_seq_cst
+#undef __opencl_c_atomic_order_seq_cst
+#endif
+#ifdef __undef___opencl_c_atomic_scope_device
+#undef __opencl_c_atomic_scope_device
+#endif
+#ifdef __undef___opencl_c_atomic_scope_all_devices
+#undef __opencl_c_atomic_scope_all_devices
+#endif
+#ifdef __undef___opencl_c_read_write_images
+#undef __opencl_c_read_write_images
+#endif
+
 #endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
 
 #if !defined(__opencl_c_generic_address_space)


Index: clang/test/SemaOpenCL/features.cl
===
--- clang/test/SemaOpenCL/features.cl
+++ clang/test/SemaOpenCL/features.cl
@@ -26,6 +26,15 @@
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl 

[PATCH] D139534: [analyzer] Don't escape local static memregions on bind

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

In D139534#4034719 , @xazax.hun wrote:

>> Here is the gist of one *new* TP:
>
> Where would `sprops` get escaped? Did I miss that or was that reduced out of 
> the example?

You are right, it 'never' escapes, yet in the past we modelled all stores to 
local statics as an 'immediate escape'.
This is what I think we should not do. And this is what this patch removes.

> Overall, this looks like a hard nut to crack. Escaping too much or too little 
> are both problematic, and we don't have the information we need to make the 
> decision. The question is whether we want to make an absolute decision or 
> come up with a heuristic like:
>
>   static int* p;
>   MyStruct reachable();
>   
>   indirect();
>   direct();
>
> escaping when `direct` is called, but not escaping when `indirect` is called.
>
> Do you see any patterns in the real-world results that would show a pattern? 
> I am not opposed to making a change, but I wonder if we should start 
> documenting these decisions somewhere that are likely need revision in the 
> future when we have more data.  What do you think?

I've seen only those 3 diffs: 2 new 1 absent issues. But there could be 
projects which make use of local static variables a lot. It was the case with 
one of our customers, but I cannot comment on that. I could somehow find 
open-source projects affected, but I'm not sure if it would be easy unless you 
have projects in mind.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139534

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


  1   2   >