[PATCH] D121663: reland: [clang] Don't append the working directory to absolute paths

2022-03-14 Thread Keith Smiley via Phabricator via cfe-commits
keith created this revision.
keith added a reviewer: aprantl.
Herald added a project: All.
keith requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes a bug that happens when using -fdebug-prefix-map to remap an
absolute path to a relative path. Since the path was absolute before
remapping, it is safe to assume that concatenating the remapped working
directory would be wrong.

This was originally submitted as https://reviews.llvm.org/D113718, but
reverted because when testing with dwarf 6 enabled, the tests were too
strict.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121663

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-prefix-map.c


Index: clang/test/CodeGen/debug-prefix-map.c
===
--- clang/test/CodeGen/debug-prefix-map.c
+++ clang/test/CodeGen/debug-prefix-map.c
@@ -6,6 +6,9 @@
 // RUN: %clang -g 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s 
-emit-llvm -o - | FileCheck %s
 // RUN: %clang -g 
-ffile-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s 
-emit-llvm -o - | FileCheck %s
 
+// RUN: %clang -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+// RUN: %clang -g -ffile-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+
 #include "Inputs/stdio.h"
 
 int main(int argc, char **argv) {
@@ -40,3 +43,7 @@
 // CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}Inputs{{/|}}stdio.h", 
directory: "{{/|.:}}UNLIKELY_PATH{{/|}}empty")
 // CHECK-COMPILATION-DIR-NOT: !DIFile(filename:
 // CHECK-SYSROOT: !DICompileUnit({{.*}}sysroot: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty"
+
+// CHECK-REL: !DIFile(filename: "./UNLIKELY_PATH/empty{{/|}}{{.*}}",
+// CHECK-REL: !DIFile(filename: 
"./UNLIKELY_PATH/empty{{/|}}{{.*}}Inputs/stdio.h",
+// CHECK-REL-SAME:directory: ""
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -444,7 +444,8 @@
   File = FileBuf;
 }
   } else {
-Dir = CurDir;
+if (!llvm::sys::path::is_absolute(FileName))
+  Dir = CurDir;
 File = RemappedFile;
   }
   llvm::DIFile *F = DBuilder.createFile(File, Dir, CSInfo, Source);


Index: clang/test/CodeGen/debug-prefix-map.c
===
--- clang/test/CodeGen/debug-prefix-map.c
+++ clang/test/CodeGen/debug-prefix-map.c
@@ -6,6 +6,9 @@
 // RUN: %clang -g -fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s -emit-llvm -o - | FileCheck %s
 // RUN: %clang -g -ffile-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s -emit-llvm -o - | FileCheck %s
 
+// RUN: %clang -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+// RUN: %clang -g -ffile-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+
 #include "Inputs/stdio.h"
 
 int main(int argc, char **argv) {
@@ -40,3 +43,7 @@
 // CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}Inputs{{/|}}stdio.h", directory: "{{/|.:}}UNLIKELY_PATH{{/|}}empty")
 // CHECK-COMPILATION-DIR-NOT: !DIFile(filename:
 // CHECK-SYSROOT: !DICompileUnit({{.*}}sysroot: "{{/|.:}}UNLIKELY_PATH{{/|}}empty"
+
+// CHECK-REL: !DIFile(filename: "./UNLIKELY_PATH/empty{{/|}}{{.*}}",
+// CHECK-REL: !DIFile(filename: "./UNLIKELY_PATH/empty{{/|}}{{.*}}Inputs/stdio.h",
+// CHECK-REL-SAME:directory: ""
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -444,7 +444,8 @@
   File = FileBuf;
 }
   } else {
-Dir = CurDir;
+if (!llvm::sys::path::is_absolute(FileName))
+  Dir = CurDir;
 File = RemappedFile;
   }
   llvm::DIFile *F = DBuilder.createFile(File, Dir, CSInfo, Source);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111587: re-land: [clang] Fix absolute file paths with -fdebug-prefix-map

2022-03-14 Thread Keith Smiley via Phabricator via cfe-commits
keith updated this revision to Diff 415307.
keith added a comment.

Fix tests with dwarf 6


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111587

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/relative-debug-prefix-map.c
  clang/test/Modules/module-debuginfo-prefix.m


Index: clang/test/Modules/module-debuginfo-prefix.m
===
--- clang/test/Modules/module-debuginfo-prefix.m
+++ clang/test/Modules/module-debuginfo-prefix.m
@@ -4,7 +4,7 @@
 // Modules:
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -x objective-c -fmodules -fmodule-format=obj \
-// RUN:   -fdebug-prefix-map=%S/Inputs=/OVERRIDE \
+// RUN:   -fdebug-prefix-map=%S%{fs-sep}Inputs=%{fs-src-root}OVERRIDE \
 // RUN:   -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s \
 // RUN:   -I %S/Inputs -I %t -emit-llvm -o %t.ll \
 // RUN:   -mllvm -debug-only=pchcontainer &>%t-mod.ll
@@ -12,7 +12,7 @@
 
 // PCH:
 // RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs \
-// RUN:   -fdebug-prefix-map=%S/Inputs=/OVERRIDE \
+// RUN:   -fdebug-prefix-map=%S%{fs-sep}Inputs=%{fs-src-root}OVERRIDE \
 // RUN:   -o %t.pch %S/Inputs/DebugObjC.h \
 // RUN:   -mllvm -debug-only=pchcontainer &>%t-pch.ll
 // RUN: cat %t-pch.ll | FileCheck %s
@@ -21,6 +21,4 @@
 @import DebugObjC;
 #endif
 
-// Dir should always be empty, but on Windows we can't recognize /var
-// as being an absolute path.
-// CHECK: !DIFile(filename: "/OVERRIDE/DebugObjC.h", directory: 
"{{()|(.*:.*)}}")
+// CHECK: !DIFile(filename: "{{/|.:}}OVERRIDE{{/|}}DebugObjC.h", 
directory: "")
Index: clang/test/CodeGen/relative-debug-prefix-map.c
===
--- /dev/null
+++ clang/test/CodeGen/relative-debug-prefix-map.c
@@ -0,0 +1,17 @@
+// RUN: mkdir -p %t.nested/dir && cd %t.nested/dir
+// RUN: cp %s %t.nested/dir/main.c
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%t.nested=. 
%t.nested/dir/main.c -emit-llvm -o - | FileCheck %s
+//
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=. %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-DIRECT
+//
+// RUN: cd %p
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-compilation-dir=. 
relative-debug-prefix-map.c -emit-llvm -o - | FileCheck %s 
--check-prefix=CHECK-DIRECT
+
+// CHECK: !DIFile(filename: "main.c", directory: "./dir"
+// CHECK-DIRECT: !DIFile(filename: "relative-debug-prefix-map.c", directory: 
"."
+
+int main(int argc, char **argv) {
+  (void)argc;
+  (void)argv;
+  return 0;
+}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -443,6 +443,9 @@
   Dir = DirBuf;
   File = FileBuf;
 }
+  } else if (llvm::sys::path::is_absolute(FileName)) {
+Dir = llvm::sys::path::parent_path(RemappedFile);
+File = llvm::sys::path::filename(RemappedFile);
   } else {
 Dir = CurDir;
 File = RemappedFile;


Index: clang/test/Modules/module-debuginfo-prefix.m
===
--- clang/test/Modules/module-debuginfo-prefix.m
+++ clang/test/Modules/module-debuginfo-prefix.m
@@ -4,7 +4,7 @@
 // Modules:
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -x objective-c -fmodules -fmodule-format=obj \
-// RUN:   -fdebug-prefix-map=%S/Inputs=/OVERRIDE \
+// RUN:   -fdebug-prefix-map=%S%{fs-sep}Inputs=%{fs-src-root}OVERRIDE \
 // RUN:   -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s \
 // RUN:   -I %S/Inputs -I %t -emit-llvm -o %t.ll \
 // RUN:   -mllvm -debug-only=pchcontainer &>%t-mod.ll
@@ -12,7 +12,7 @@
 
 // PCH:
 // RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs \
-// RUN:   -fdebug-prefix-map=%S/Inputs=/OVERRIDE \
+// RUN:   -fdebug-prefix-map=%S%{fs-sep}Inputs=%{fs-src-root}OVERRIDE \
 // RUN:   -o %t.pch %S/Inputs/DebugObjC.h \
 // RUN:   -mllvm -debug-only=pchcontainer &>%t-pch.ll
 // RUN: cat %t-pch.ll | FileCheck %s
@@ -21,6 +21,4 @@
 @import DebugObjC;
 #endif
 
-// Dir should always be empty, but on Windows we can't recognize /var
-// as being an absolute path.
-// CHECK: !DIFile(filename: "/OVERRIDE/DebugObjC.h", directory: "{{()|(.*:.*)}}")
+// CHECK: !DIFile(filename: "{{/|.:}}OVERRIDE{{/|}}DebugObjC.h", directory: "")
Index: clang/test/CodeGen/relative-debug-prefix-map.c
===
--- /dev/null
+++ clang/test/CodeGen/relative-debug-prefix-map.c
@@ -0,0 +1,17 @@
+// RUN: mkdir -p %t.nested/dir && cd %t.nested/dir
+// RUN: cp %s %t.nested/dir/main.c
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%t.nested=. %t.nested/dir/main.c -emit-llvm -o - | FileCheck %s
+//
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=. %s 

[PATCH] D119409: [C++20] [Modules] Remain dynamic initializing internal-linkage variables in module interface unit

2022-03-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

ping


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

https://reviews.llvm.org/D119409

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


[PATCH] D120397: [C++20] [Modules] Make the linkage consistent for template and its specialization

2022-03-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a subscriber: urnathan.
ChuanqiXu added a comment.

Oh, @urnathan resigned from all my patches and I don't know why. @iains 
@dblaikie could you help to review this one?


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

https://reviews.llvm.org/D120397

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


[PATCH] D120540: [Driver] Enable to use C++20 modules standalone by -fcxx-modules

2022-03-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@iains ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120540

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


[PATCH] D121271: [C++20] [Modules] Don't generate strong function of a partition in importing modules

2022-03-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@iains ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121271

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


[PATCH] D120874: [C++20] [Modules] Use '-' as the separator of partitions when searching in filesystems

2022-03-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

@iains ping


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

https://reviews.llvm.org/D120874

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


[PATCH] D121591: [C++20][Modules][Driver][HU 4/N] Add fdirectives-only mode for preprocessing output.

2022-03-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

Oh, I found all the series of patches looks confusing to me. Maybe due to that 
I lack a use experience with header unit. I really couldn't judge if it is 
necessary or useful. Could you elaborate more **end** use cases? For example, I 
could understand the sentence:

> Thus it preserves macros that are still live after such processing.
> This output can be consumed by a second compilation to produce a header unit.

But where could it be useful? I think this is worth mentioning.

---

Note: After the 2 series of patches, I think it is necessary to edit the 
Release Note and the command line documents.




Comment at: clang/test/Driver/cxx20-fdirectives-only.cpp:10
+// RUN: %clang++ -### -std=c++20 -E -fmodule-header=user foo.hh  2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-HU %s
+

Maybe it's worth to add a test:
```
%clang++ -### -std=c++20 -fmodule-header=user foo.hh  2>&1
```

And check not for `-fdirectives-only`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121591

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


[PATCH] D121658: Use llvm::sys::path::append to fix FIXME

2022-03-14 Thread Paul Pluzhnikov via Phabricator via cfe-commits
ppluzhnikov abandoned this revision.
ppluzhnikov added a comment.

Breaks Windows tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121658

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


[PATCH] D121590: [C++20][Modules][Driver][HU 3/N] Handle foo.h with -fmodule-header and/or C++ invocation.

2022-03-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

This looks a little bit odd. Is this consistent with GCC too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121590

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


[PATCH] D121589: [C++20][Modules][Driver][HU 2/N] Add fmodule-header, fmodule-header=

2022-03-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

> It's not practical to recognise a header without any suffix so

-fmodule-header=system foo isn't going to happen.

May I ask the reason? It looks not so good with `-fmodule-header=system 
-xc++-header vector`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121589

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


[PATCH] D121345: [RISCV] Add +experimental-zvfh extension to cover half types in vectors.

2022-03-14 Thread Zakk Chen via Phabricator via cfe-commits
khchen added a comment.

LGTM. wait @kito-cheng  to approve it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121345

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


[PATCH] D111579: [clang] Fix DIFile directory root on Windows

2022-03-14 Thread Keith Smiley via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcb22d71806b7: [clang] Fix DIFile directory root on Windows 
(authored by keith).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111579

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-prefix-map.c


Index: clang/test/CodeGen/debug-prefix-map.c
===
--- clang/test/CodeGen/debug-prefix-map.c
+++ clang/test/CodeGen/debug-prefix-map.c
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - | FileCheck %s 
-check-prefix CHECK-NO-MAIN-FILE-NAME
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s 
-check-prefix CHECK-EVIL
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -main-file-name 
debug-prefix-map.c | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - 
-fdebug-compilation-dir %p | FileCheck %s -check-prefix CHECK-COMPILATION-DIR
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -isysroot %p 
-debugger-tuning=lldb | FileCheck %s -check-prefix CHECK-SYSROOT
-// RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s
-// RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - | FileCheck %s -check-prefix CHECK-NO-MAIN-FILE-NAME
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH=empty %s -emit-llvm -o - | 
FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - -main-file-name debug-prefix-map.c | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - -fdebug-compilation-dir %p | FileCheck %s -check-prefix 
CHECK-COMPILATION-DIR
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - -isysroot %p -debugger-tuning=lldb | FileCheck %s -check-prefix 
CHECK-SYSROOT
+// RUN: %clang -g 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang -g 
-ffile-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s 
-emit-llvm -o - | FileCheck %s
 
 #include "Inputs/stdio.h"
 
@@ -19,26 +19,24 @@
   vprintf("string", argp);
 }
 
-// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"/UNLIKELY_PATH/empty{{/|}}"
-// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"/UNLIKELY_PATH/empty{{/|}}{{.*}}",
-// On POSIX systems "Dir" should actually be empty, but on Windows we
-// can't recognize "/UNLIKELY_PATH" as being an absolute path.
-// CHECK-NO-MAIN-FILE-NAME-SAME:directory: "{{()|(.*:.*)}}")
-// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"/UNLIKELY_PATH/empty{{/|}}Inputs/stdio.h",
-// CHECK-NO-MAIN-FILE-NAME-SAME:directory: "{{()|(.*:.*)}}")
+// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty{{/|}}",
+// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty{{/|}}{{.*}}",
+// CHECK-NO-MAIN-FILE-NAME-SAME:directory: "")
+// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty{{/|}}Inputs{{/|}}stdio.h",
+// CHECK-NO-MAIN-FILE-NAME-SAME:directory: "")
 // CHECK-NO-MAIN-FILE-NAME-NOT: !DIFile(filename:
 
-// CHECK-EVIL: !DIFile(filename: "/UNLIKELY_PATH=empty{{/|}}{{.*}}"
-// CHECK-EVIL: !DIFile(filename: 
"/UNLIKELY_PATH=empty{{/|}}{{.*}}Inputs/stdio.h",
-// CHECK-EVIL-SAME:directory: "{{()|(.*:.*)}}")
+// CHECK-EVIL: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH=empty{{/|}}{{.*}}"
+// CHECK-EVIL: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH=empty{{/|}}{{.*}}Inputs{{/|}}stdio.h",
+// CHECK-EVIL-SAME:directory: "")
 // CHECK-EVIL-NOT: !DIFile(filename:
 
-// CHECK: !DIFile(filename: "/UNLIKELY_PATH/empty{{/|}}{{.*}}"
-// CHECK: !DIFile(filename: 
"/UNLIKELY_PATH/empty{{/|}}{{.*}}Inputs/stdio.h",
-// CHECK-SAME:directory: "{{()|(.*:.*)}}")
+// CHECK: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty{{/|}}{{.*}}",
+// CHECK: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty{{/|}}{{.*}}Inputs{{/|}}stdio.h",
+// CHECK-SAME:directory: ""
 // CHECK-NOT: !DIFile(filename:
 
-// CHECK-COMPILATION-DIR: !DIFile(filename: 

[clang] cb22d71 - [clang] Fix DIFile directory root on Windows

2022-03-14 Thread Keith Smiley via cfe-commits

Author: Keith Smiley
Date: 2022-03-14T20:07:01-07:00
New Revision: cb22d71806b784a9105803f38b2740ca6888392a

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

LOG: [clang] Fix DIFile directory root on Windows

On unix systems this logic would not separate the file and directory of
the DIFile unless they shared more components at the start than just the
root path character. The logic to do this was unix specific so it didn't
work on Windows. Now we check if the entire root_path is the same as
what you were going to set as the Dir and use the full filepath in that
case.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-prefix-map.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 2203f0aec5c7c..06501b34cbaef 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -424,16 +424,16 @@ CGDebugInfo::createFile(StringRef FileName,
   SmallString<128> DirBuf;
   SmallString<128> FileBuf;
   if (llvm::sys::path::is_absolute(RemappedFile)) {
-// Strip the common prefix (if it is more than just "/") from current
-// directory and FileName for a more space-efficient encoding.
+// Strip the common prefix (if it is more than just "/" or "C:\") from
+// current directory and FileName for a more space-efficient encoding.
 auto FileIt = llvm::sys::path::begin(RemappedFile);
 auto FileE = llvm::sys::path::end(RemappedFile);
 auto CurDirIt = llvm::sys::path::begin(CurDir);
 auto CurDirE = llvm::sys::path::end(CurDir);
 for (; CurDirIt != CurDirE && *CurDirIt == *FileIt; ++CurDirIt, ++FileIt)
   llvm::sys::path::append(DirBuf, *CurDirIt);
-if (std::distance(llvm::sys::path::begin(CurDir), CurDirIt) == 1) {
-  // Don't strip the common prefix if it is only the root "/"
+if (llvm::sys::path::root_path(DirBuf) == DirBuf) {
+  // Don't strip the common prefix if it is only the root ("/" or "C:\")
   // since that would make LLVM diagnostic locations confusing.
   Dir = {};
   File = RemappedFile;

diff  --git a/clang/test/CodeGen/debug-prefix-map.c 
b/clang/test/CodeGen/debug-prefix-map.c
index 1c5d3a6e78bb2..fb2c1d39a1522 100644
--- a/clang/test/CodeGen/debug-prefix-map.c
+++ b/clang/test/CodeGen/debug-prefix-map.c
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - | FileCheck %s 
-check-prefix CHECK-NO-MAIN-FILE-NAME
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s 
-check-prefix CHECK-EVIL
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -main-file-name 
debug-prefix-map.c | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - 
-fdebug-compilation-dir %p | FileCheck %s -check-prefix CHECK-COMPILATION-DIR
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -isysroot %p 
-debugger-tuning=lldb | FileCheck %s -check-prefix CHECK-SYSROOT
-// RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s
-// RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - | FileCheck %s -check-prefix CHECK-NO-MAIN-FILE-NAME
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH=empty %s -emit-llvm -o - | 
FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - -main-file-name debug-prefix-map.c | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - -fdebug-compilation-dir %p | FileCheck %s -check-prefix 
CHECK-COMPILATION-DIR
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - -isysroot %p -debugger-tuning=lldb | FileCheck %s -check-prefix 
CHECK-SYSROOT
+// RUN: %clang -g 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang -g 
-ffile-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s 
-emit-llvm -o - | FileCheck %s
 
 #include "Inputs/stdio.h"
 
@@ -19,26 +19,24 @@ void test_rewrite_includes(void) {
   

[PATCH] D119788: [AArch64] Add support for -march=native for Apple M1 CPU

2022-03-14 Thread Keith Smiley via Phabricator via cfe-commits
keith added a comment.

Bump, I think I've covered everything here, let me know if not!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119788

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


[PATCH] D111457: [test] Add lit helper for windows paths

2022-03-14 Thread Keith Smiley 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 rG6541d3e979c1: [test] Add lit helper for windows paths 
(authored by keith).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111457

Files:
  llvm/docs/CommandGuide/lit.rst
  llvm/docs/TestingGuide.rst
  llvm/utils/lit/lit/TestRunner.py


Index: llvm/utils/lit/lit/TestRunner.py
===
--- llvm/utils/lit/lit/TestRunner.py
+++ llvm/utils/lit/lit/TestRunner.py
@@ -6,6 +6,7 @@
 import os, signal, subprocess, sys
 import re
 import stat
+import pathlib
 import platform
 import shutil
 import tempfile
@@ -1121,6 +1122,12 @@
   ('%basename_t', baseName),
   ('%T', tmpDir)])
 
+substitutions.extend([
+('%{fs-src-root}', pathlib.Path(sourcedir).anchor),
+('%{fs-tmp-root}', pathlib.Path(tmpBase).anchor),
+('%{fs-sep}', os.path.sep),
+])
+
 # "%/[STpst]" should be normalized.
 substitutions.extend([
 ('%/s', sourcepath.replace('\\', '/')),
Index: llvm/docs/TestingGuide.rst
===
--- llvm/docs/TestingGuide.rst
+++ llvm/docs/TestingGuide.rst
@@ -569,6 +569,18 @@
 
Expands to the path separator, i.e. ``:`` (or ``;`` on Windows).
 
+``${fs-src-root}``
+   Expands to the root component of file system paths for the source directory,
+   i.e. ``/`` on Unix systems or ``C:\`` (or another drive) on Windows.
+
+``${fs-tmp-root}``
+   Expands to the root component of file system paths for the test's temporary
+   directory, i.e. ``/`` on Unix systems or ``C:\`` (or another drive) on
+   Windows.
+
+``${fs-sep}``
+   Expands to the file system separator, i.e. ``/`` or ``\`` on Windows.
+
 ``%/s, %/S, %/t, %/T:``
 
   Act like the corresponding substitution above but replace any ``\``
Index: llvm/docs/CommandGuide/lit.rst
===
--- llvm/docs/CommandGuide/lit.rst
+++ llvm/docs/CommandGuide/lit.rst
@@ -523,6 +523,9 @@
  %S  source dir (directory of the file currently being run)
  %p  same as %S
  %{pathsep}  path separator
+ %{fs-src-root}  root component of file system paths pointing to the 
LLVM checkout
+ %{fs-tmp-root}  root component of file system paths pointing to the 
test's temporary directory
+ %{fs-sep}   file system path separator
  %t  temporary file name unique to the test
  %basename_t The last path component of %t but without the 
``.tmp`` extension
  %T  parent directory of %t (not unique, deprecated, do 
not use)


Index: llvm/utils/lit/lit/TestRunner.py
===
--- llvm/utils/lit/lit/TestRunner.py
+++ llvm/utils/lit/lit/TestRunner.py
@@ -6,6 +6,7 @@
 import os, signal, subprocess, sys
 import re
 import stat
+import pathlib
 import platform
 import shutil
 import tempfile
@@ -1121,6 +1122,12 @@
   ('%basename_t', baseName),
   ('%T', tmpDir)])
 
+substitutions.extend([
+('%{fs-src-root}', pathlib.Path(sourcedir).anchor),
+('%{fs-tmp-root}', pathlib.Path(tmpBase).anchor),
+('%{fs-sep}', os.path.sep),
+])
+
 # "%/[STpst]" should be normalized.
 substitutions.extend([
 ('%/s', sourcepath.replace('\\', '/')),
Index: llvm/docs/TestingGuide.rst
===
--- llvm/docs/TestingGuide.rst
+++ llvm/docs/TestingGuide.rst
@@ -569,6 +569,18 @@
 
Expands to the path separator, i.e. ``:`` (or ``;`` on Windows).
 
+``${fs-src-root}``
+   Expands to the root component of file system paths for the source directory,
+   i.e. ``/`` on Unix systems or ``C:\`` (or another drive) on Windows.
+
+``${fs-tmp-root}``
+   Expands to the root component of file system paths for the test's temporary
+   directory, i.e. ``/`` on Unix systems or ``C:\`` (or another drive) on
+   Windows.
+
+``${fs-sep}``
+   Expands to the file system separator, i.e. ``/`` or ``\`` on Windows.
+
 ``%/s, %/S, %/t, %/T:``
 
   Act like the corresponding substitution above but replace any ``\``
Index: llvm/docs/CommandGuide/lit.rst
===
--- llvm/docs/CommandGuide/lit.rst
+++ llvm/docs/CommandGuide/lit.rst
@@ -523,6 +523,9 @@
  %S  source dir (directory of the file currently being run)
  %p  same as %S
  %{pathsep}  path separator
+ %{fs-src-root}  root component of file system paths pointing to the LLVM checkout
+ %{fs-tmp-root}  root component of file system paths pointing to 

[PATCH] D121588: [C++20][Modules][Driver][HU 1/N] Initial handling for -xc++-{system,user}-header.

2022-03-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added a comment.
This revision is now accepted and ready to land.

LGTM. Although I don't like these option names, it is more important to keep 
consistent with GCC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121588

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


[PATCH] D121661: [WebAssembly] Fix names of SIMD instructions containing '_zero'

2022-03-14 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: wingo, ecnelises, sunfish, hiraditya, 
jgravelle-google, sbc100.
Herald added a project: All.
tlively requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Fix the instruction names to match the WebAssembly spec:

- `i32x4.trunc_sat_zero_f64x2_{s,u}` => `i32x4.trunc_sat_f64x2_{s,u}_zero`
- `f32x4.demote_zero_f64x2` => `f32x4.demote_f64x2_zero`

Also rename related things like intrinsics, builtins, and test functions to
match.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121661

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/wasm_simd128.h
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-conversions.ll
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
  llvm/test/MC/WebAssembly/simd-encodings.s

Index: llvm/test/MC/WebAssembly/simd-encodings.s
===
--- llvm/test/MC/WebAssembly/simd-encodings.s
+++ llvm/test/MC/WebAssembly/simd-encodings.s
@@ -313,8 +313,8 @@
 # CHECK: v128.load64_zero 32 # encoding: [0xfd,0x5d,0x03,0x20]
 v128.load64_zero 32
 
-# CHECK: f32x4.demote_zero_f64x2 # encoding: [0xfd,0x5e]
-f32x4.demote_zero_f64x2
+# CHECK: f32x4.demote_f64x2_zero # encoding: [0xfd,0x5e]
+f32x4.demote_f64x2_zero
 
 # CHECK: f64x2.promote_low_f32x4 # encoding: [0xfd,0x5f]
 f64x2.promote_low_f32x4
@@ -767,11 +767,11 @@
 # CHECK: f32x4.convert_i32x4_u # encoding: [0xfd,0xfb,0x01]
 f32x4.convert_i32x4_u
 
-# CHECK: i32x4.trunc_sat_zero_f64x2_s # encoding: [0xfd,0xfc,0x01]
-i32x4.trunc_sat_zero_f64x2_s
+# CHECK: i32x4.trunc_sat_f64x2_s_zero # encoding: [0xfd,0xfc,0x01]
+i32x4.trunc_sat_f64x2_s_zero
 
-# CHECK: i32x4.trunc_sat_zero_f64x2_u # encoding: [0xfd,0xfd,0x01]
-i32x4.trunc_sat_zero_f64x2_u
+# CHECK: i32x4.trunc_sat_f64x2_u_zero # encoding: [0xfd,0xfd,0x01]
+i32x4.trunc_sat_f64x2_u_zero
 
 # CHECK: f64x2.convert_low_i32x4_s # encoding: [0xfd,0xfe,0x01]
 f64x2.convert_low_i32x4_s
Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -466,48 +466,48 @@
   ret <4 x i32> %a
 }
 
-; CHECK-LABEL: trunc_sat_zero_s_v4i32:
-; CHECK-NEXT: .functype trunc_sat_zero_s_v4i32 (v128) -> (v128){{$}}
-; CHECK-NEXT: i32x4.trunc_sat_zero_f64x2_s $push[[R:[0-9]+]]=, $0{{$}}
+; CHECK-LABEL: trunc_sat_s_zero_v4i32:
+; CHECK-NEXT: .functype trunc_sat_s_zero_v4i32 (v128) -> (v128){{$}}
+; CHECK-NEXT: i32x4.trunc_sat_f64x2_s_zero $push[[R:[0-9]+]]=, $0{{$}}
 ; CHECK-NEXT: return $pop[[R]]{{$}}
 declare <2 x i32> @llvm.fptosi.sat.v2i32.v2f64(<2 x double>)
-define <4 x i32> @trunc_sat_zero_s_v4i32(<2 x double> %x) {
+define <4 x i32> @trunc_sat_s_zero_v4i32(<2 x double> %x) {
   %v = call <2 x i32> @llvm.fptosi.sat.v2i32.v2f64(<2 x double> %x)
   %a = shufflevector <2 x i32> %v, <2 x i32> ,
<4 x i32> 
   ret <4 x i32> %a
 }
 
-; CHECK-LABEL: trunc_sat_zero_s_v4i32_2:
-; CHECK-NEXT: .functype trunc_sat_zero_s_v4i32_2 (v128) -> (v128){{$}}
-; SLOW-NEXT: i32x4.trunc_sat_zero_f64x2_s $push[[R:[0-9]+]]=, $0{{$}}
+; CHECK-LABEL: trunc_sat_s_zero_v4i32_2:
+; CHECK-NEXT: .functype trunc_sat_s_zero_v4i32_2 (v128) -> (v128){{$}}
+; SLOW-NEXT: i32x4.trunc_sat_f64x2_s_zero $push[[R:[0-9]+]]=, $0{{$}}
 ; SLOW-NEXT: return $pop[[R]]{{$}}
 declare <4 x i32> @llvm.fptosi.sat.v4i32.v4f64(<4 x double>)
-define <4 x i32> @trunc_sat_zero_s_v4i32_2(<2 x double> %x) {
+define <4 x i32> @trunc_sat_s_zero_v4i32_2(<2 x double> %x) {
   %v = shufflevector <2 x double> %x, <2 x double> zeroinitializer,
<4 x i32> 
   %a = call <4 x i32> @llvm.fptosi.sat.v4i32.v4f64(<4 x double> %v)
   ret <4 x i32> %a
 }
 
-; CHECK-LABEL: trunc_sat_zero_u_v4i32:
-; CHECK-NEXT: .functype trunc_sat_zero_u_v4i32 (v128) -> (v128){{$}}
-; CHECK-NEXT: i32x4.trunc_sat_zero_f64x2_u $push[[R:[0-9]+]]=, $0{{$}}
+; CHECK-LABEL: trunc_sat_u_zero_v4i32:
+; CHECK-NEXT: .functype trunc_sat_u_zero_v4i32 (v128) -> (v128){{$}}
+; CHECK-NEXT: i32x4.trunc_sat_f64x2_u_zero $push[[R:[0-9]+]]=, $0{{$}}
 ; CHECK-NEXT: return $pop[[R]]{{$}}
 declare <2 x i32> @llvm.fptoui.sat.v2i32.v2f64(<2 x double>)
-define <4 x i32> @trunc_sat_zero_u_v4i32(<2 x double> %x) {
+define <4 x i32> @trunc_sat_u_zero_v4i32(<2 x double> %x) {
   %v = call <2 x i32> @llvm.fptoui.sat.v2i32.v2f64(<2 x double> %x)
   %a = shufflevector <2 x i32> %v, <2 x i32> ,
<4 x i32> 
   ret <4 x i32> %a
 }
 
-; CHECK-LABEL: trunc_sat_zero_u_v4i32_2:
-; CHECK-NEXT: .functype trunc_sat_zero_u_v4i32_2 (v128) -> 

[PATCH] D121576: [clang-format] Don't unwrap lines preceded by line comments

2022-03-14 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D121576#3378934 , @MyDeveloperDay 
wrote:

> I'm wondering if the presence of the comment would impact the CellCount, I 
> might go back and add some more unit tests for the "non rectangular" change I 
> made.
>
> So this fixes the "}" going up onto the comment line, but not the indentation 
> right?

Right. I think we should have a specification (including when not to align the 
cells) and re-design the entire thing. It's not maintainable as is. I have some 
ideas but need to remove/change some of the existing test cases, e.g., those 
involving concatenated string literals. If you (and @curdeius and 
@HazardyKnusperkeks) agree, I can give it a shot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121576

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


[PATCH] D121659: [CMake][Fuchsia] Use correct architecture for iossim

2022-03-14 Thread Petr Hosek 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 rG1b6ff3f4f89e: [CMake][Fuchsia] Use correct architecture for 
iossim (authored by phosek).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121659

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -71,7 +71,7 @@
   set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
   set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
   set(DARWIN_ios_ARCHS arm64 CACHE STRING "")
-  set(DARWIN_iossim_ARCHS arm64 CACHE STRING "")
+  set(DARWIN_iossim_ARCHS x86_64 CACHE STRING "")
   set(DARWIN_osx_ARCHS arm64;x86_64 CACHE STRING "")
 endif()
 


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -71,7 +71,7 @@
   set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
   set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
   set(DARWIN_ios_ARCHS arm64 CACHE STRING "")
-  set(DARWIN_iossim_ARCHS arm64 CACHE STRING "")
+  set(DARWIN_iossim_ARCHS x86_64 CACHE STRING "")
   set(DARWIN_osx_ARCHS arm64;x86_64 CACHE STRING "")
 endif()
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1b6ff3f - [CMake][Fuchsia] Use correct architecture for iossim

2022-03-14 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2022-03-14T19:21:09-07:00
New Revision: 1b6ff3f4f89e06af17575627fba3e6d90d1abbc5

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

LOG: [CMake][Fuchsia] Use correct architecture for iossim

We should be building iossim for x86_64, not arm64.

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 8c593e4c6310c..0706c3046fb1d 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -71,7 +71,7 @@ if(APPLE)
   set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
   set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
   set(DARWIN_ios_ARCHS arm64 CACHE STRING "")
-  set(DARWIN_iossim_ARCHS arm64 CACHE STRING "")
+  set(DARWIN_iossim_ARCHS x86_64 CACHE STRING "")
   set(DARWIN_osx_ARCHS arm64;x86_64 CACHE STRING "")
 endif()
 



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


[PATCH] D121576: [clang-format] Don't unwrap lines preceded by line comments

2022-03-14 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0a0cc3c58a74: [clang-format] Dont unwrap lines 
preceded by line comments (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121576

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19176,6 +19176,14 @@
" {init1, init2, init3, init4}}\n"
"};",
Style);
+  // TODO: Fix the indentations below when this option is fully functional.
+  verifyFormat("int a[][] = {\n"
+   "{\n"
+   " {0, 2}, //\n"
+   " {1, 2}  //\n"
+   "}\n"
+   "};",
+   Style);
   Style.ColumnLimit = 100;
   EXPECT_EQ(
   "test demo[] = {\n"
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -1079,13 +1079,15 @@
   // So in here we want to see if there is a brace that falls
   // on a line that was split. If so on that line we make sure that
   // the spaces in front of the brace are enough.
-  Changes[CellIter->Index].NewlinesBefore = 0;
-  Changes[CellIter->Index].Spaces = 0;
-  for (const auto *Next = CellIter->NextColumnElement; Next != nullptr;
-   Next = Next->NextColumnElement) {
-Changes[Next->Index].Spaces = 0;
-Changes[Next->Index].NewlinesBefore = 0;
-  }
+  const auto *Next = CellIter;
+  do {
+const FormatToken *Previous = Changes[Next->Index].Tok->Previous;
+if (Previous && Previous->isNot(TT_LineComment)) {
+  Changes[Next->Index].Spaces = 0;
+  Changes[Next->Index].NewlinesBefore = 0;
+}
+Next = Next->NextColumnElement;
+  } while (Next);
   // Unless the array is empty, we need the position of all the
   // immediately adjacent cells
   if (CellIter != Cells.begin()) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19176,6 +19176,14 @@
" {init1, init2, init3, init4}}\n"
"};",
Style);
+  // TODO: Fix the indentations below when this option is fully functional.
+  verifyFormat("int a[][] = {\n"
+   "{\n"
+   " {0, 2}, //\n"
+   " {1, 2}  //\n"
+   "}\n"
+   "};",
+   Style);
   Style.ColumnLimit = 100;
   EXPECT_EQ(
   "test demo[] = {\n"
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -1079,13 +1079,15 @@
   // So in here we want to see if there is a brace that falls
   // on a line that was split. If so on that line we make sure that
   // the spaces in front of the brace are enough.
-  Changes[CellIter->Index].NewlinesBefore = 0;
-  Changes[CellIter->Index].Spaces = 0;
-  for (const auto *Next = CellIter->NextColumnElement; Next != nullptr;
-   Next = Next->NextColumnElement) {
-Changes[Next->Index].Spaces = 0;
-Changes[Next->Index].NewlinesBefore = 0;
-  }
+  const auto *Next = CellIter;
+  do {
+const FormatToken *Previous = Changes[Next->Index].Tok->Previous;
+if (Previous && Previous->isNot(TT_LineComment)) {
+  Changes[Next->Index].Spaces = 0;
+  Changes[Next->Index].NewlinesBefore = 0;
+}
+Next = Next->NextColumnElement;
+  } while (Next);
   // Unless the array is empty, we need the position of all the
   // immediately adjacent cells
   if (CellIter != Cells.begin()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0a0cc3c - [clang-format] Don't unwrap lines preceded by line comments

2022-03-14 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2022-03-14T19:16:29-07:00
New Revision: 0a0cc3c58a74f9574d9f4df244e3bd0a8e805945

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

LOG: [clang-format] Don't unwrap lines preceded by line comments

Fixes #53495

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

Added: 


Modified: 
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 6a46d850c3d5e..de6cdf4afd729 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1079,13 +1079,15 @@ void 
WhitespaceManager::alignArrayInitializersRightJustified(
   // So in here we want to see if there is a brace that falls
   // on a line that was split. If so on that line we make sure that
   // the spaces in front of the brace are enough.
-  Changes[CellIter->Index].NewlinesBefore = 0;
-  Changes[CellIter->Index].Spaces = 0;
-  for (const auto *Next = CellIter->NextColumnElement; Next != nullptr;
-   Next = Next->NextColumnElement) {
-Changes[Next->Index].Spaces = 0;
-Changes[Next->Index].NewlinesBefore = 0;
-  }
+  const auto *Next = CellIter;
+  do {
+const FormatToken *Previous = Changes[Next->Index].Tok->Previous;
+if (Previous && Previous->isNot(TT_LineComment)) {
+  Changes[Next->Index].Spaces = 0;
+  Changes[Next->Index].NewlinesBefore = 0;
+}
+Next = Next->NextColumnElement;
+  } while (Next);
   // Unless the array is empty, we need the position of all the
   // immediately adjacent cells
   if (CellIter != Cells.begin()) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 05427c6249749..354b60e27a5c7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -19176,6 +19176,14 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
" {init1, init2, init3, init4}}\n"
"};",
Style);
+  // TODO: Fix the indentations below when this option is fully functional.
+  verifyFormat("int a[][] = {\n"
+   "{\n"
+   " {0, 2}, //\n"
+   " {1, 2}  //\n"
+   "}\n"
+   "};",
+   Style);
   Style.ColumnLimit = 100;
   EXPECT_EQ(
   "test demo[] = {\n"



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


[PATCH] D121550: [clang-format] Fix crash on invalid requires expression

2022-03-14 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

After applying this patch, we got a different assertion failure on a bunch of 
files in `clang/test`, e.g.:

  ~/llvm-project/clang$ for f in $(find . -name \*.cpp -o -name \*.c) ; do 
clang-format $f > /dev/null ; done
  Assertion failed: (OpeningParen.is(tok::l_paren)), function parseParens, file 
TokenAnnotator.cpp, line 216.
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace.
  Stack dump:
  0.Program arguments: cf ./test/Driver/ignore-xcoff-visibility.cpp
  ...




Comment at: clang/lib/Format/TokenAnnotator.cpp:216
 FormatToken  = *CurrentToken->Previous;
 assert(OpeningParen.is(tok::l_paren));
 FormatToken *PrevNonComment = OpeningParen.getPreviousNonComment();

This patch either uncovers or causes an assertion failure here on a bunch of 
files in `clang/test`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121550

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


[PATCH] D121659: [CMake][Fuchsia] Use correct architecture for iossim

2022-03-14 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: abrachet, haowei, leonardchan.
Herald added subscribers: pengfei, kristof.beyls, mgorny.
Herald added a project: All.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We should be building iossim for x86_64, not arm64.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121659

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -71,7 +71,7 @@
   set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
   set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
   set(DARWIN_ios_ARCHS arm64 CACHE STRING "")
-  set(DARWIN_iossim_ARCHS arm64 CACHE STRING "")
+  set(DARWIN_iossim_ARCHS x86_64 CACHE STRING "")
   set(DARWIN_osx_ARCHS arm64;x86_64 CACHE STRING "")
 endif()
 


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -71,7 +71,7 @@
   set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
   set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
   set(DARWIN_ios_ARCHS arm64 CACHE STRING "")
-  set(DARWIN_iossim_ARCHS arm64 CACHE STRING "")
+  set(DARWIN_iossim_ARCHS x86_64 CACHE STRING "")
   set(DARWIN_osx_ARCHS arm64;x86_64 CACHE STRING "")
 endif()
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121658: Use llvm::sys::path::append to fix FIXME

2022-03-14 Thread Paul Pluzhnikov via Phabricator via cfe-commits
ppluzhnikov created this revision.
Herald added a project: All.
ppluzhnikov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121658

Files:
  clang/lib/Lex/HeaderSearch.cpp


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -883,10 +883,8 @@
   const FileEntry *Includer = IncluderAndDir.first;
 
   // Concatenate the requested file onto the directory.
-  // FIXME: Portability.  Filename concatenation should be in sys::Path.
   TmpDir = IncluderAndDir.second->getName();
-  TmpDir.push_back('/');
-  TmpDir.append(Filename.begin(), Filename.end());
+  llvm::sys::path::append(TmpDir, Filename);
 
   // FIXME: We don't cache the result of getFileInfo across the call to
   // getFileAndSuggestModule, because it's a reference to an element of


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -883,10 +883,8 @@
   const FileEntry *Includer = IncluderAndDir.first;
 
   // Concatenate the requested file onto the directory.
-  // FIXME: Portability.  Filename concatenation should be in sys::Path.
   TmpDir = IncluderAndDir.second->getName();
-  TmpDir.push_back('/');
-  TmpDir.append(Filename.begin(), Filename.end());
+  llvm::sys::path::append(TmpDir, Filename);
 
   // FIXME: We don't cache the result of getFileInfo across the call to
   // getFileAndSuggestModule, because it's a reference to an element of
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f1388b6 - [OpenMP][Fix] Fix test failing after patch

2022-03-14 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-03-14T21:51:38-04:00
New Revision: f1388b616ab83b1022cb967ab8a868cf36d83161

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

LOG: [OpenMP][Fix] Fix test failing after patch

Added: 


Modified: 
clang/test/Driver/amdgpu-openmp-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index 4d90c73034503..d3551ca50eb3a 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -79,4 +79,4 @@
 // CHECK-LIB-DEVICE: 
{{.*}}llvm-link{{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"
 
 // RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp 
-fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa 
-march=gfx803 -lm --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode 
-fopenmp-new-driver %s 2>&1 | FileCheck %s --check-prefix=CHECK-LIB-DEVICE-NEW
-// CHECK-LIB-DEVICE-NEW: 
{{.*}}clang-linker-wrapper{{.*}}-target-library=amdgcn-amd-amdhsa-gfx803={{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"
+// CHECK-LIB-DEVICE-NEW: 
{{.*}}clang-linker-wrapper{{.*}}-target-library=openmp-amdgcn-amd-amdhsa-gfx803={{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"



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


[PATCH] D120952: [clang][AST matchers] adding submatchers under cudaKernelCallExpr to match kernel launch config

2022-03-14 Thread Alister Johnson via Phabricator via cfe-commits
ajohnson-uoregon added a comment.

I still need to write tests but: I do have a use case for these over here: 
https://github.com/ajohnson-uoregon/llvm-project/blob/feature-ajohnson/clang-tools-extra/clang-rewrite/ConstructMatchers.cpp#L472
 
tl;dr, we'd like to match the kernel launch arguments (i.e., the arguments to 
`__cudaPushCallConfiguration()`) and these matchers made writing the code to 
generate those AST matchers much easier.

Without at least the `hasKernelConfig()` matcher, it's actually currently 
impossible to match the kernel launch args. (I wasn't able to find a way after 
quite a while poking at the AST, at least.) As for the others, it's not clear 
how to match the kernel launch args without exposing the fact that there's a 
second CallExpr inside the CUDAKernelCallExpr to the user and writing a pretty 
messy matcher, along the lines of 
`cudaKernelCallExpr(hasKernelConfig(callExpr(hasArgument(0, expr()` for the 
grid dim. `cudaKernelCallExpr(cudaGridDim())` is a lot cleaner and easier to 
understand.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120952

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


[clang] 670438e - [OpenMP][Fix] Add offloading kind to AMDGPU libraries

2022-03-14 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-03-14T21:18:19-04:00
New Revision: 670438e55dc265dc0b25567e62a6e328d91f30a0

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

LOG: [OpenMP][Fix] Add offloading kind to AMDGPU libraries

Summary:
A previous patch added the offloading kind to the triple format we used.
I forgot to update the line where we add the AMDGPU libraries.

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5c2b720b0872a..d942ec25f409c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8263,9 +8263,9 @@ void LinkerWrapper::ConstructJob(Compilation , const 
JobAction ,
 RocmTC.getCommonDeviceLibNames(TCArgs, Arch.str());
 
 for (StringRef LibName : BCLibs)
-  CmdArgs.push_back(
-  Args.MakeArgString("-target-library=" + TC->getTripleString() + "-" +
- Arch + "=" + LibName));
+  CmdArgs.push_back(Args.MakeArgString(
+  "-target-library=" + Action::GetOffloadKindName(Action::OFK_OpenMP) +
+  "-" + TC->getTripleString() + "-" + Arch + "=" + LibName));
   }
 
   if (D.isUsingLTO(/* IsOffload */ true)) {



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


[PATCH] D111587: re-land: [clang] Fix absolute file paths with -fdebug-prefix-map

2022-03-14 Thread Keith Smiley via Phabricator via cfe-commits
keith updated this revision to Diff 415292.
keith added a comment.
Herald added a project: All.

Update subsitutions with slashes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111587

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/relative-debug-prefix-map.c
  clang/test/Modules/module-debuginfo-prefix.m


Index: clang/test/Modules/module-debuginfo-prefix.m
===
--- clang/test/Modules/module-debuginfo-prefix.m
+++ clang/test/Modules/module-debuginfo-prefix.m
@@ -4,7 +4,7 @@
 // Modules:
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -x objective-c -fmodules -fmodule-format=obj \
-// RUN:   -fdebug-prefix-map=%S/Inputs=/OVERRIDE \
+// RUN:   -fdebug-prefix-map=%S%{fs-sep}Inputs=%{fs-src-root}OVERRIDE \
 // RUN:   -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s \
 // RUN:   -I %S/Inputs -I %t -emit-llvm -o %t.ll \
 // RUN:   -mllvm -debug-only=pchcontainer &>%t-mod.ll
@@ -12,7 +12,7 @@
 
 // PCH:
 // RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs \
-// RUN:   -fdebug-prefix-map=%S/Inputs=/OVERRIDE \
+// RUN:   -fdebug-prefix-map=%S%{fs-sep}Inputs=%{fs-src-root}OVERRIDE \
 // RUN:   -o %t.pch %S/Inputs/DebugObjC.h \
 // RUN:   -mllvm -debug-only=pchcontainer &>%t-pch.ll
 // RUN: cat %t-pch.ll | FileCheck %s
@@ -21,6 +21,4 @@
 @import DebugObjC;
 #endif
 
-// Dir should always be empty, but on Windows we can't recognize /var
-// as being an absolute path.
-// CHECK: !DIFile(filename: "/OVERRIDE/DebugObjC.h", directory: 
"{{()|(.*:.*)}}")
+// CHECK: !DIFile(filename: "{{/|.:}}OVERRIDE{{/|}}DebugObjC.h", 
directory: "")
Index: clang/test/CodeGen/relative-debug-prefix-map.c
===
--- /dev/null
+++ clang/test/CodeGen/relative-debug-prefix-map.c
@@ -0,0 +1,17 @@
+// RUN: mkdir -p %t.nested/dir && cd %t.nested/dir
+// RUN: cp %s %t.nested/dir/main.c
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%t.nested=. 
%t.nested/dir/main.c -emit-llvm -o - | FileCheck %s
+//
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=. %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-DIRECT
+//
+// RUN: cd %p
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-compilation-dir=. 
relative-debug-prefix-map.c -emit-llvm -o - | FileCheck %s 
--check-prefix=CHECK-DIRECT
+
+// CHECK: !DIFile(filename: "main.c", directory: "./dir")
+// CHECK-DIRECT: !DIFile(filename: "relative-debug-prefix-map.c", directory: 
".")
+
+int main(int argc, char **argv) {
+  (void)argc;
+  (void)argv;
+  return 0;
+}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -443,6 +443,9 @@
   Dir = DirBuf;
   File = FileBuf;
 }
+  } else if (llvm::sys::path::is_absolute(FileName)) {
+Dir = llvm::sys::path::parent_path(RemappedFile);
+File = llvm::sys::path::filename(RemappedFile);
   } else {
 Dir = CurDir;
 File = RemappedFile;


Index: clang/test/Modules/module-debuginfo-prefix.m
===
--- clang/test/Modules/module-debuginfo-prefix.m
+++ clang/test/Modules/module-debuginfo-prefix.m
@@ -4,7 +4,7 @@
 // Modules:
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -x objective-c -fmodules -fmodule-format=obj \
-// RUN:   -fdebug-prefix-map=%S/Inputs=/OVERRIDE \
+// RUN:   -fdebug-prefix-map=%S%{fs-sep}Inputs=%{fs-src-root}OVERRIDE \
 // RUN:   -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s \
 // RUN:   -I %S/Inputs -I %t -emit-llvm -o %t.ll \
 // RUN:   -mllvm -debug-only=pchcontainer &>%t-mod.ll
@@ -12,7 +12,7 @@
 
 // PCH:
 // RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs \
-// RUN:   -fdebug-prefix-map=%S/Inputs=/OVERRIDE \
+// RUN:   -fdebug-prefix-map=%S%{fs-sep}Inputs=%{fs-src-root}OVERRIDE \
 // RUN:   -o %t.pch %S/Inputs/DebugObjC.h \
 // RUN:   -mllvm -debug-only=pchcontainer &>%t-pch.ll
 // RUN: cat %t-pch.ll | FileCheck %s
@@ -21,6 +21,4 @@
 @import DebugObjC;
 #endif
 
-// Dir should always be empty, but on Windows we can't recognize /var
-// as being an absolute path.
-// CHECK: !DIFile(filename: "/OVERRIDE/DebugObjC.h", directory: "{{()|(.*:.*)}}")
+// CHECK: !DIFile(filename: "{{/|.:}}OVERRIDE{{/|}}DebugObjC.h", directory: "")
Index: clang/test/CodeGen/relative-debug-prefix-map.c
===
--- /dev/null
+++ clang/test/CodeGen/relative-debug-prefix-map.c
@@ -0,0 +1,17 @@
+// RUN: mkdir -p %t.nested/dir && cd %t.nested/dir
+// RUN: cp %s %t.nested/dir/main.c
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%t.nested=. %t.nested/dir/main.c -emit-llvm -o - | FileCheck %s
+//
+// RUN: %clang_cc1 

[PATCH] D111579: [clang] Fix DIFile directory root on Windows

2022-03-14 Thread Keith Smiley via Phabricator via cfe-commits
keith updated this revision to Diff 415291.
keith marked an inline comment as done.
keith added a comment.

Update subsitutions with dashes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111579

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-prefix-map.c


Index: clang/test/CodeGen/debug-prefix-map.c
===
--- clang/test/CodeGen/debug-prefix-map.c
+++ clang/test/CodeGen/debug-prefix-map.c
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - | FileCheck %s 
-check-prefix CHECK-NO-MAIN-FILE-NAME
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s 
-check-prefix CHECK-EVIL
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -main-file-name 
debug-prefix-map.c | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - 
-fdebug-compilation-dir %p | FileCheck %s -check-prefix CHECK-COMPILATION-DIR
-// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -isysroot %p 
-debugger-tuning=lldb | FileCheck %s -check-prefix CHECK-SYSROOT
-// RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s
-// RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - | FileCheck %s -check-prefix CHECK-NO-MAIN-FILE-NAME
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH=empty %s -emit-llvm -o - | 
FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - -main-file-name debug-prefix-map.c | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - -fdebug-compilation-dir %p | FileCheck %s -check-prefix 
CHECK-COMPILATION-DIR
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty %s -emit-llvm 
-o - -isysroot %p -debugger-tuning=lldb | FileCheck %s -check-prefix 
CHECK-SYSROOT
+// RUN: %clang -g 
-fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang -g 
-ffile-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s 
-emit-llvm -o - | FileCheck %s
 
 #include "Inputs/stdio.h"
 
@@ -19,26 +19,24 @@
   vprintf("string", argp);
 }
 
-// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"/UNLIKELY_PATH/empty{{/|}}"
-// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"/UNLIKELY_PATH/empty{{/|}}{{.*}}",
-// On POSIX systems "Dir" should actually be empty, but on Windows we
-// can't recognize "/UNLIKELY_PATH" as being an absolute path.
-// CHECK-NO-MAIN-FILE-NAME-SAME:directory: "{{()|(.*:.*)}}")
-// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"/UNLIKELY_PATH/empty{{/|}}Inputs/stdio.h",
-// CHECK-NO-MAIN-FILE-NAME-SAME:directory: "{{()|(.*:.*)}}")
+// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty{{/|}}",
+// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty{{/|}}{{.*}}",
+// CHECK-NO-MAIN-FILE-NAME-SAME:directory: "")
+// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty{{/|}}Inputs{{/|}}stdio.h",
+// CHECK-NO-MAIN-FILE-NAME-SAME:directory: "")
 // CHECK-NO-MAIN-FILE-NAME-NOT: !DIFile(filename:
 
-// CHECK-EVIL: !DIFile(filename: "/UNLIKELY_PATH=empty{{/|}}{{.*}}"
-// CHECK-EVIL: !DIFile(filename: 
"/UNLIKELY_PATH=empty{{/|}}{{.*}}Inputs/stdio.h",
-// CHECK-EVIL-SAME:directory: "{{()|(.*:.*)}}")
+// CHECK-EVIL: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH=empty{{/|}}{{.*}}"
+// CHECK-EVIL: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH=empty{{/|}}{{.*}}Inputs{{/|}}stdio.h",
+// CHECK-EVIL-SAME:directory: "")
 // CHECK-EVIL-NOT: !DIFile(filename:
 
-// CHECK: !DIFile(filename: "/UNLIKELY_PATH/empty{{/|}}{{.*}}"
-// CHECK: !DIFile(filename: 
"/UNLIKELY_PATH/empty{{/|}}{{.*}}Inputs/stdio.h",
-// CHECK-SAME:directory: "{{()|(.*:.*)}}")
+// CHECK: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty{{/|}}{{.*}}",
+// CHECK: !DIFile(filename: 
"{{/|.:}}UNLIKELY_PATH{{/|}}empty{{/|}}{{.*}}Inputs{{/|}}stdio.h",
+// CHECK-SAME:directory: ""
 // CHECK-NOT: !DIFile(filename:
 
-// CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}", directory: 

[PATCH] D111457: [test] Add lit helper for windows paths

2022-03-14 Thread Keith Smiley via Phabricator via cfe-commits
keith updated this revision to Diff 415290.
keith added a comment.

Update substitutions to use dashes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111457

Files:
  llvm/docs/CommandGuide/lit.rst
  llvm/docs/TestingGuide.rst
  llvm/utils/lit/lit/TestRunner.py


Index: llvm/utils/lit/lit/TestRunner.py
===
--- llvm/utils/lit/lit/TestRunner.py
+++ llvm/utils/lit/lit/TestRunner.py
@@ -6,6 +6,7 @@
 import os, signal, subprocess, sys
 import re
 import stat
+import pathlib
 import platform
 import shutil
 import tempfile
@@ -1121,6 +1122,12 @@
   ('%basename_t', baseName),
   ('%T', tmpDir)])
 
+substitutions.extend([
+('%{fs-src-root}', pathlib.Path(sourcedir).anchor),
+('%{fs-tmp-root}', pathlib.Path(tmpBase).anchor),
+('%{fs-sep}', os.path.sep),
+])
+
 # "%/[STpst]" should be normalized.
 substitutions.extend([
 ('%/s', sourcepath.replace('\\', '/')),
Index: llvm/docs/TestingGuide.rst
===
--- llvm/docs/TestingGuide.rst
+++ llvm/docs/TestingGuide.rst
@@ -569,6 +569,18 @@
 
Expands to the path separator, i.e. ``:`` (or ``;`` on Windows).
 
+``${fs-src-root}``
+   Expands to the root component of file system paths for the source directory,
+   i.e. ``/`` on Unix systems or ``C:\`` (or another drive) on Windows.
+
+``${fs-tmp-root}``
+   Expands to the root component of file system paths for the test's temporary
+   directory, i.e. ``/`` on Unix systems or ``C:\`` (or another drive) on
+   Windows.
+
+``${fs-sep}``
+   Expands to the file system separator, i.e. ``/`` or ``\`` on Windows.
+
 ``%/s, %/S, %/t, %/T:``
 
   Act like the corresponding substitution above but replace any ``\``
Index: llvm/docs/CommandGuide/lit.rst
===
--- llvm/docs/CommandGuide/lit.rst
+++ llvm/docs/CommandGuide/lit.rst
@@ -523,6 +523,9 @@
  %S  source dir (directory of the file currently being run)
  %p  same as %S
  %{pathsep}  path separator
+ %{fs-src-root}  root component of file system paths pointing to the 
LLVM checkout
+ %{fs-tmp-root}  root component of file system paths pointing to the 
test's temporary directory
+ %{fs-sep}   file system path separator
  %t  temporary file name unique to the test
  %basename_t The last path component of %t but without the 
``.tmp`` extension
  %T  parent directory of %t (not unique, deprecated, do 
not use)


Index: llvm/utils/lit/lit/TestRunner.py
===
--- llvm/utils/lit/lit/TestRunner.py
+++ llvm/utils/lit/lit/TestRunner.py
@@ -6,6 +6,7 @@
 import os, signal, subprocess, sys
 import re
 import stat
+import pathlib
 import platform
 import shutil
 import tempfile
@@ -1121,6 +1122,12 @@
   ('%basename_t', baseName),
   ('%T', tmpDir)])
 
+substitutions.extend([
+('%{fs-src-root}', pathlib.Path(sourcedir).anchor),
+('%{fs-tmp-root}', pathlib.Path(tmpBase).anchor),
+('%{fs-sep}', os.path.sep),
+])
+
 # "%/[STpst]" should be normalized.
 substitutions.extend([
 ('%/s', sourcepath.replace('\\', '/')),
Index: llvm/docs/TestingGuide.rst
===
--- llvm/docs/TestingGuide.rst
+++ llvm/docs/TestingGuide.rst
@@ -569,6 +569,18 @@
 
Expands to the path separator, i.e. ``:`` (or ``;`` on Windows).
 
+``${fs-src-root}``
+   Expands to the root component of file system paths for the source directory,
+   i.e. ``/`` on Unix systems or ``C:\`` (or another drive) on Windows.
+
+``${fs-tmp-root}``
+   Expands to the root component of file system paths for the test's temporary
+   directory, i.e. ``/`` on Unix systems or ``C:\`` (or another drive) on
+   Windows.
+
+``${fs-sep}``
+   Expands to the file system separator, i.e. ``/`` or ``\`` on Windows.
+
 ``%/s, %/S, %/t, %/T:``
 
   Act like the corresponding substitution above but replace any ``\``
Index: llvm/docs/CommandGuide/lit.rst
===
--- llvm/docs/CommandGuide/lit.rst
+++ llvm/docs/CommandGuide/lit.rst
@@ -523,6 +523,9 @@
  %S  source dir (directory of the file currently being run)
  %p  same as %S
  %{pathsep}  path separator
+ %{fs-src-root}  root component of file system paths pointing to the LLVM checkout
+ %{fs-tmp-root}  root component of file system paths pointing to the test's temporary directory
+ %{fs-sep}   file system path separator
  %t  temporary 

[PATCH] D120952: [clang][AST matchers] adding submatchers under cudaKernelCallExpr to match kernel launch config

2022-03-14 Thread Alister Johnson via Phabricator via cfe-commits
ajohnson-uoregon updated this revision to Diff 415289.
ajohnson-uoregon added a comment.

fixing clang-format things and adding docs; also making docs a bit more clear


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120952

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp

Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -177,7 +177,11 @@
   REGISTER_MATCHER(continueStmt);
   REGISTER_MATCHER(coreturnStmt);
   REGISTER_MATCHER(coyieldExpr);
+  REGISTER_MATCHER(cudaBlockDim);
+  REGISTER_MATCHER(cudaGridDim);
   REGISTER_MATCHER(cudaKernelCallExpr);
+  REGISTER_MATCHER(cudaSharedMemPerBlock);
+  REGISTER_MATCHER(cudaStream);
   REGISTER_MATCHER(cxxBaseSpecifier);
   REGISTER_MATCHER(cxxBindTemporaryExpr);
   REGISTER_MATCHER(cxxBoolLiteral);
@@ -320,6 +324,7 @@
   REGISTER_MATCHER(hasInit);
   REGISTER_MATCHER(hasInitializer);
   REGISTER_MATCHER(hasInitStatement);
+  REGISTER_MATCHER(hasKernelConfig);
   REGISTER_MATCHER(hasKeywordSelector);
   REGISTER_MATCHER(hasLHS);
   REGISTER_MATCHER(hasLocalQualifiers);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7848,6 +7848,80 @@
 extern const internal::VariadicDynCastAllOfMatcher
 cudaKernelCallExpr;
 
+/// Matches the kernel launch config (in <<<>>>) on CUDA kernel calls.
+///
+/// Example: cudaKernelCallExpr(hasKernelConfig()) will match <<>> in
+/// \code
+///   kernel<<>>();
+/// \endcode
+AST_MATCHER_P(CUDAKernelCallExpr, hasKernelConfig, internal::Matcher,
+  InnerMatcher) {
+  if (const CallExpr *Config = Node.getConfig()) {
+return InnerMatcher.matches(*Config, Finder, Builder);
+  }
+  return false;
+}
+
+/// Matches the first argument (grid dim) in <<<>>> on CUDA kernel calls.
+///
+/// Example: cudaKernelCallExpr(cudaGridDim()) will match i in
+/// \code
+///   kernel<<>>();
+/// \endcode
+AST_MATCHER_P(CUDAKernelCallExpr, cudaGridDim, internal::Matcher,
+  InnerMatcher) {
+  const CallExpr *Config = Node.getConfig();
+  if (Config && Config->getNumArgs() > 0) {
+return InnerMatcher.matches(*(Config->getArg(0)), Finder, Builder);
+  }
+  return false;
+}
+
+/// Matches the second argument (block dim) in <<<>>> on CUDA kernel calls.
+///
+/// Example: cudaKernelCallExpr(cudaBlockDim()) will match j in
+/// \code
+///   kernel<<>>();
+/// \endcode
+AST_MATCHER_P(CUDAKernelCallExpr, cudaBlockDim, internal::Matcher,
+  InnerMatcher) {
+  const CallExpr *Config = Node.getConfig();
+  if (Config && Config->getNumArgs() > 1) {
+return InnerMatcher.matches(*(Config->getArg(1)), Finder, Builder);
+  }
+  return false;
+}
+
+/// Matches the third argument (shared mem size) in <<<>>> on CUDA kernel calls.
+///
+/// Example: cudaKernelCallExpr(cudaSharedMemPerBlock()) will match mem in
+/// \code
+///   kernel<<>>();
+/// \endcode
+AST_MATCHER_P(CUDAKernelCallExpr, cudaSharedMemPerBlock,
+  internal::Matcher, InnerMatcher) {
+  const CallExpr *Config = Node.getConfig();
+  if (Config && Config->getNumArgs() > 2) {
+return InnerMatcher.matches(*(Config->getArg(2)), Finder, Builder);
+  }
+  return false;
+}
+
+/// Matches the fourth argument (CUDA stream) in <<<>>> on CUDA kernel calls.
+///
+/// Example: cudaKernelCallExpr(cudaStream()) will match 0 in
+/// \code
+///   kernel<<>>();
+/// \endcode
+AST_MATCHER_P(CUDAKernelCallExpr, cudaStream, internal::Matcher,
+  InnerMatcher) {
+  const CallExpr *Config = Node.getConfig();
+  if (Config && Config->getNumArgs() > 3) {
+return InnerMatcher.matches(*(Config->getArg(3)), Finder, Builder);
+  }
+  return false;
+}
+
 /// Matches expressions that resolve to a null pointer constant, such as
 /// GNU's __null, C++11's nullptr, or C's NULL macro.
 ///
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -6426,6 +6426,46 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CUDAKernelCallExpr.html;>CUDAKernelCallExprcudaBlockDimMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr InnerMatcher
+Matches the second argument (block dim) in  on CUDA kernel calls.
+
+Example: cudaKernelCallExpr(cudaBlockDim()) will match j in
+  kerneli,j();
+
+
+
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CUDAKernelCallExpr.html;>CUDAKernelCallExprcudaGridDimMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr InnerMatcher
+Matches the first 

[PATCH] D121327: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO

2022-03-14 Thread Julian Lettner via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
yln marked an inline comment as done.
Closed by commit rG9c542a5a4e1b: Lower `@llvm.global_dtors` using 
`__cxa_atexit` on MachO (authored by yln).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121327

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/docs/Passes.rst
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
  llvm/include/llvm/Transforms/Utils.h
  llvm/include/llvm/Transforms/Utils/LowerGlobalDtors.h
  llvm/lib/CodeGen/CodeGen.cpp
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Target/WebAssembly/CMakeLists.txt
  llvm/lib/Target/WebAssembly/WebAssembly.h
  llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/lib/Transforms/Utils/CMakeLists.txt
  llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp
  llvm/test/CodeGen/ARM/ctors_dtors.ll
  llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
  llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll

Index: llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll
===
--- /dev/null
+++ llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll
@@ -0,0 +1,156 @@
+; RUN: opt-lower-global-dtors -S < %s | FileCheck %s --implicit-check-not=llvm.global_dtors
+; RUN: opt -passes=lower-global-dtors -S < %s | FileCheck %s --implicit-check-not=llvm.global_dtors
+
+; Test that @llvm.global_dtors is properly lowered into @llvm.global_ctors,
+; grouping dtor calls by priority and associated symbol.
+
+declare void @orig_ctor()
+declare void @orig_dtor0()
+declare void @orig_dtor1a()
+declare void @orig_dtor1b()
+declare void @orig_dtor1c0()
+declare void @orig_dtor1c1a()
+declare void @orig_dtor1c1b()
+declare void @orig_dtor1c2a()
+declare void @orig_dtor1c2b()
+declare void @orig_dtor1c3()
+declare void @orig_dtor1d()
+declare void @orig_dtor65535()
+declare void @orig_dtor65535c0()
+declare void @after_the_null()
+
+@associatedc0 = external global i8
+@associatedc1 = external global i8
+@associatedc2 = global i8 42
+@associatedc3 = global i8 84
+
+@llvm.global_ctors = appending global
+[1 x { i32, void ()*, i8* }]
+[
+  { i32, void ()*, i8* } { i32 200, void ()* @orig_ctor, i8* null }
+]
+
+@llvm.global_dtors = appending global
+[14 x { i32, void ()*, i8* }]
+[
+  { i32, void ()*, i8* } { i32 0, void ()* @orig_dtor0, i8* null },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1a, i8* null },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1b, i8* null },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c0, i8* @associatedc0 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c1a, i8* @associatedc1 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c1b, i8* @associatedc1 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c2a, i8* @associatedc2 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c2b, i8* @associatedc2 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c3, i8* @associatedc3 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1d, i8* null },
+  { i32, void ()*, i8* } { i32 65535, void ()* @orig_dtor65535c0, i8* @associatedc0 },
+  { i32, void ()*, i8* } { i32 65535, void ()* @orig_dtor65535, i8* null },
+  { i32, void ()*, i8* } { i32 65535, void ()* null, i8* null },
+  { i32, void ()*, i8* } { i32 65535, void ()* @after_the_null, i8* null }
+]
+
+; CHECK: @associatedc0 = external global i8
+; CHECK: @associatedc1 = external global i8
+; CHECK: @associatedc2 = global i8 42
+; CHECK: @associatedc3 = global i8 84
+; CHECK: @__dso_handle = extern_weak hidden constant i8
+
+; CHECK-LABEL: @llvm.global_ctors = appending global [10 x { i32, void ()*, i8* }] [
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 200, void ()* @orig_ctor, i8* null },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 0, void ()* @register_call_dtors.0, i8* null },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$0", i8* null },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$1.associatedc0", i8* @associatedc0 },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$2.associatedc1", i8* @associatedc1 },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$3.associatedc2", i8* @associatedc2 },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* 

[clang] 9c542a5 - Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO

2022-03-14 Thread Julian Lettner via cfe-commits

Author: Julian Lettner
Date: 2022-03-14T17:51:18-07:00
New Revision: 9c542a5a4e1ba36c24e48185712779df52b7f7a6

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

LOG: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO

For MachO, lower `@llvm.global_dtors` into `@llvm_global_ctors` with
`__cxa_atexit` calls to avoid emitting the deprecated `__mod_term_func`.

Reuse the existing `WebAssemblyLowerGlobalDtors.cpp` to accomplish this.

Enable fallback to the old behavior via Clang driver flag
(`-fregister-global-dtors-with-atexit`) or llc / code generation flag
(`-lower-global-dtors-via-cxa-atexit`).  This escape hatch will be
removed in the future.

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

Added: 
llvm/include/llvm/Transforms/Utils/LowerGlobalDtors.h
llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp
llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll

Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/docs/Passes.rst
llvm/include/llvm/CodeGen/CommandFlags.h
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/include/llvm/Target/TargetOptions.h
llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
llvm/include/llvm/Transforms/Utils.h
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Target/WebAssembly/CMakeLists.txt
llvm/lib/Target/WebAssembly/WebAssembly.h
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
llvm/lib/Transforms/Utils/CMakeLists.txt
llvm/test/CodeGen/ARM/ctors_dtors.ll
llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll

Removed: 
llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp



diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 490f5b3de1ff3..716a565ee7871 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -546,6 +546,8 @@ static bool initTargetOptions(DiagnosticsEngine ,
   Options.BinutilsVersion =
   llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.BinutilsVersion);
   Options.UseInitArray = CodeGenOpts.UseInitArray;
+  Options.LowerGlobalDtorsViaCxaAtExit =
+  CodeGenOpts.RegisterGlobalDtorsWithAtExit;
   Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
   Options.CompressDebugSections = CodeGenOpts.getCompressDebugSections();
   Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;

diff  --git a/llvm/docs/Passes.rst b/llvm/docs/Passes.rst
index 92f06496b4ef9..7c0666992e8f5 100644
--- a/llvm/docs/Passes.rst
+++ b/llvm/docs/Passes.rst
@@ -876,6 +876,14 @@ This pass expects :ref:`LICM ` to be run 
before it to hoist
 invariant conditions out of the loop, to make the unswitching opportunity
 obvious.
 
+``-lower-global-dtors``: Lower global destructors
+
+
+This pass lowers global module destructors (``llvm.global_dtors``) by creating
+wrapper functions that are registered as global constructors in
+``llvm.global_ctors`` and which contain a call to ``__cxa_atexit`` to register
+their destructor functions.
+
 ``-loweratomic``: Lower atomic intrinsics to non-atomic form
 
 

diff  --git a/llvm/include/llvm/CodeGen/CommandFlags.h 
b/llvm/include/llvm/CodeGen/CommandFlags.h
index aa91367f65b80..4424db4aa2e41 100644
--- a/llvm/include/llvm/CodeGen/CommandFlags.h
+++ b/llvm/include/llvm/CodeGen/CommandFlags.h
@@ -95,6 +95,8 @@ std::string getTrapFuncName();
 
 bool getUseCtors();
 
+bool getLowerGlobalDtorsViaCxaAtExit();
+
 bool getRelaxELFRelocations();
 
 bool getDataSections();

diff  --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h 
b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
index 2a35987507446..26bda8d5d239d 100644
--- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -119,6 +119,9 @@ class TargetLoweringObjectFileMachO : public 
TargetLoweringObjectFile {
 
   void Initialize(MCContext , const TargetMachine ) override;
 
+  MCSection *getStaticDtorSection(unsigned Priority,
+  const MCSymbol *KeySym) const override;
+
   /// Emit the module flags that specify the garbage collection information.
   void emitModuleMetadata(MCStreamer , Module ) const override;
 

diff  --git a/llvm/include/llvm/InitializePasses.h 
b/llvm/include/llvm/InitializePasses.h
index 3a98bacef81d0..82aafe2744184 100644
--- 

[PATCH] D121327: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO

2022-03-14 Thread Julian Lettner via Phabricator via cfe-commits
yln marked 2 inline comments as done.
yln added inline comments.



Comment at: llvm/lib/CodeGen/TargetPassConfig.cpp:900
+  // __cxa_atexit calls to avoid emitting the deprecated __mod_term_func.
+  if (TM->getTargetTriple().isOSBinFormatMachO())
+addPass(createLowerGlobalDtorsLegacyPass());

delcypher wrote:
> yln wrote:
> > yln wrote:
> > > delcypher wrote:
> > > > Random thought. Do we want to support the legacy way of calling 
> > > > destructors, rather than removing it entirely? If we were to do such a 
> > > > thing I'd suspect we'd guard using the legacy way on the OS deployment 
> > > > target.
> > > > 
> > > > Just to be clear. I'm happy with the patch the way it is. I'm just 
> > > > wondering if we should consider allowing the legacy way as well. I 
> > > > can't see an obvious use case for it because the new way should work on 
> > > > older OSs too but maybe there's a use case I haven't thought about?
> > > Having a way to explicitly request the old behavior sounds like a good 
> > > idea.  I will look into it.
> > I added an escape hatch to fallback to the old behavior:
> > * via Clang driver flag `-fregister-global-dtors-with-atexit`
> > * llc / code generation flag -lower-global-dtors-via-cxa-atexit.
> > This escape hatch will be removed in the future.
> @yln I don't see any modifications to the driver. How is 
> `-fregister-global-dtors-with-atexit` added as a driver flag?
This is an existing flag in the frontend added as part of this change: D45578
```
Add a command line option `fregister_global_dtors_with_atexit` to register 
destructor functions annotated with __attribute__((destructor)) using 
__cxa_atexit or atexit.
```

It's on by default on Darwin:
```
  if (Args.hasFlag(options::OPT_fregister_global_dtors_with_atexit,
   options::OPT_fno_register_global_dtors_with_atexit,
   RawTriple.isOSDarwin() && !KernelOrKext))
CmdArgs.push_back("-fregister-global-dtors-with-atexit");
```

Essentially we switched over the frontend to avoid emitting the deprecated 
`__mod_term_func` section a long time ago and now I am using the same technique 
to lower `.llvm.global_dtors` in the backend.  So we could say the flag is 
exactly what we wanted to express (it makes sense to key off it), but now it 
applies more fully.

Before D45578, destructor functions annotated with 
`__attribute__((destructor))` were added to `.llvm.global_dtor`.  I do not know 
why we decided to lower them in the frontend (where it didn't apply to 
`.llvm.global_dtors`) instead of the backend (this change).

There is certainly an opportunity here to refactor this and make the frontend 
use `llvm.global_dtor` again to reduce code duplication (after making sure we 
cover all the necessary cases).  That's a big and wide-reaching change and  I 
am not intending to do this as part of this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121327

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


[PATCH] D121327: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO

2022-03-14 Thread Dan Gohman via Phabricator via cfe-commits
sunfish added a comment.

In D121327#3381123 , @yln wrote:

> @sunfish 
> Hi Dan, I hope you are still happy with this change.  I didn't change any 
> WebAssembly tests, but rather added a new IR-level test, so all existing 
> WebAssembly behavior should stay the same.  Let me know if you have any 
> concerns.

Yes, the change looks good to me!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121327

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


[PATCH] D120949: [clang][AST matchers] adding attributedStmt AST matcher

2022-03-14 Thread Alister Johnson via Phabricator via cfe-commits
ajohnson-uoregon added a comment.

(.. I just figured out where the 'submit' button is. My comment on 
2713-2714 is from like, 5 days ago. Oops.  )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120949

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


[PATCH] D120949: [clang][AST matchers] adding attributedStmt AST matcher

2022-03-14 Thread Alister Johnson via Phabricator via cfe-commits
ajohnson-uoregon added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2733
+/// \endcode
+AST_MATCHER_P(AttributedStmt, isAttr, attr::Kind, AttrKind) {
+  return llvm::any_of(Node.getAttrs(),

aaron.ballman wrote:
> sammccall wrote:
> > This definitely seems more like `hasAttr` than `isAttr` to me. An 
> > AttributedStmt *is* the (sugar) statement, and *has* the attribute(s).
> > 
> > Maybe rather `describesAttr` so people don't confuse this for one that 
> > walks up, though?
> Good point on the `isAttr` name!
> 
> I'm not sure `describeAttr` works (the statement doesn't describe attributes, 
> it... has/contains/uses the attribute). Maybe.. `specifiesAttr()`?
> 
> Or are we making this harder than it needs to be and we should use 
> `hasAttr()` for parity with other things that have attributes associated with 
> them?
Yeah I wasn't sure on the name, I just picked something that wouldn't make me 
figure out polymorphic matcher declarations because this was the first AST 
matcher I'd written. :)  

I like `containsAttr()` or `specifiesAttr()`, since it could have multiple 
attributes. `hasAttr()` makes the most sense to me though. If y'all think we 
should go with that, the new `hasAttr()` definition would look something like 
this, right? (To make sure I do in fact understand polymorphic matchers.)


```
AST_POLYMORPHIC_MATCHER_P(
hasAttr,
AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, AttributedStmt),
attr::Kind, AttrKind) {
  return llvm::any_of(Node.getAttrs(),
  [&](const Attr *A) { return A->getKind() == AttrKind; });
}
```

Original `hasAttr()` for reference:
```
AST_MATCHER_P(Decl, hasAttr, attr::Kind, AttrKind) {
  for (const auto *Attr : Node.attrs()) {
if (Attr->getKind() == AttrKind)
  return true;
  }
  return false;
}
```



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2713-2714
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher
+attributedStmt;
+

jdoerfert wrote:
> aaron.ballman wrote:
> > Design-wise, I'm on the fence here. AST matchers match the AST nodes that 
> > Clang produces, and from that perspective, this makes a lot of sense. But 
> > `AttributedStmt` is a bit of a hack in some ways, and do we want to expose 
> > that hack to AST matcher users? e.g., is there a reason we shouldn't make 
> > `returnStmt(hasAttr(attr::Likely))` work directly rather than making the 
> > user pick their way through the `AttributedStmt`? This is more in line with 
> > how you check for a declaration with a particular attribute and seems like 
> > the more natural way to surface this.
> > 
> > For the moment, since this is following the current AST structure in Clang, 
> > I think this is fine. But I'm curious if @klimek or perhaps @sammccall has 
> > an opinion here.
> I think a way to find any kind of statement (or expression) that has a 
> specific attribute is very useful. How that should look, idk.
I think both would be useful. Because sometimes you might want to look for all 
statements of a particular kind (eg, returnStmts) that have an attributed, and 
then 'returnStmt(hasAttr())` should work. But there are also cases (like the 
one I'm working on: 
https://github.com/ajohnson-uoregon/llvm-project/tree/feature-ajohnson/clang-tools-extra/clang-rewrite)
 where we want to find all statements with an attribute, but we don't really 
care what kind of statement it is, in which case looking for AttributedStmts is 
easier.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120949

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


[PATCH] D121327: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO

2022-03-14 Thread Julian Lettner via Phabricator via cfe-commits
yln updated this revision to Diff 415282.
yln added a comment.

Report fatal error when we can, instead of never.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121327

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/docs/Passes.rst
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
  llvm/include/llvm/Transforms/Utils.h
  llvm/include/llvm/Transforms/Utils/LowerGlobalDtors.h
  llvm/lib/CodeGen/CodeGen.cpp
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Target/WebAssembly/CMakeLists.txt
  llvm/lib/Target/WebAssembly/WebAssembly.h
  llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/lib/Transforms/Utils/CMakeLists.txt
  llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp
  llvm/test/CodeGen/ARM/ctors_dtors.ll
  llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
  llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll

Index: llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll
===
--- /dev/null
+++ llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll
@@ -0,0 +1,156 @@
+; RUN: opt-lower-global-dtors -S < %s | FileCheck %s --implicit-check-not=llvm.global_dtors
+; RUN: opt -passes=lower-global-dtors -S < %s | FileCheck %s --implicit-check-not=llvm.global_dtors
+
+; Test that @llvm.global_dtors is properly lowered into @llvm.global_ctors,
+; grouping dtor calls by priority and associated symbol.
+
+declare void @orig_ctor()
+declare void @orig_dtor0()
+declare void @orig_dtor1a()
+declare void @orig_dtor1b()
+declare void @orig_dtor1c0()
+declare void @orig_dtor1c1a()
+declare void @orig_dtor1c1b()
+declare void @orig_dtor1c2a()
+declare void @orig_dtor1c2b()
+declare void @orig_dtor1c3()
+declare void @orig_dtor1d()
+declare void @orig_dtor65535()
+declare void @orig_dtor65535c0()
+declare void @after_the_null()
+
+@associatedc0 = external global i8
+@associatedc1 = external global i8
+@associatedc2 = global i8 42
+@associatedc3 = global i8 84
+
+@llvm.global_ctors = appending global
+[1 x { i32, void ()*, i8* }]
+[
+  { i32, void ()*, i8* } { i32 200, void ()* @orig_ctor, i8* null }
+]
+
+@llvm.global_dtors = appending global
+[14 x { i32, void ()*, i8* }]
+[
+  { i32, void ()*, i8* } { i32 0, void ()* @orig_dtor0, i8* null },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1a, i8* null },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1b, i8* null },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c0, i8* @associatedc0 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c1a, i8* @associatedc1 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c1b, i8* @associatedc1 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c2a, i8* @associatedc2 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c2b, i8* @associatedc2 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c3, i8* @associatedc3 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1d, i8* null },
+  { i32, void ()*, i8* } { i32 65535, void ()* @orig_dtor65535c0, i8* @associatedc0 },
+  { i32, void ()*, i8* } { i32 65535, void ()* @orig_dtor65535, i8* null },
+  { i32, void ()*, i8* } { i32 65535, void ()* null, i8* null },
+  { i32, void ()*, i8* } { i32 65535, void ()* @after_the_null, i8* null }
+]
+
+; CHECK: @associatedc0 = external global i8
+; CHECK: @associatedc1 = external global i8
+; CHECK: @associatedc2 = global i8 42
+; CHECK: @associatedc3 = global i8 84
+; CHECK: @__dso_handle = extern_weak hidden constant i8
+
+; CHECK-LABEL: @llvm.global_ctors = appending global [10 x { i32, void ()*, i8* }] [
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 200, void ()* @orig_ctor, i8* null },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 0, void ()* @register_call_dtors.0, i8* null },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$0", i8* null },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$1.associatedc0", i8* @associatedc0 },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$2.associatedc1", i8* @associatedc1 },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$3.associatedc2", i8* @associatedc2 },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$4.associatedc3", i8* @associatedc3 },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$5", i8* null },
+; 

[PATCH] D121653: Implement __cpuid intrinsic WIP

2022-03-14 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao created this revision.
Herald added a subscriber: pengfei.
Herald added a project: All.
ayzhao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

cpuid implementation complete, still have a cannot compile this function yet

WORK IN PROGRESS
DO NOT REVIEW
DO NOT MERGE


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121653

Files:
  clang/include/clang/Basic/BuiltinsX86.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/intrin.h
  clang/test/CodeGen/X86/ms-x86-intrinsics.c

Index: clang/test/CodeGen/X86/ms-x86-intrinsics.c
===
--- clang/test/CodeGen/X86/ms-x86-intrinsics.c
+++ clang/test/CodeGen/X86/ms-x86-intrinsics.c
@@ -63,6 +63,14 @@
 // CHECK: [[RES:%[0-9]+]] = mul nuw i64 [[Y]], [[X]]
 // CHECK: ret i64 [[RES]]
 
+void test__cpuid(int cpuInfo[4], int function_id) {
+  return __cpuid(cpuInfo, function_id);
+}
+
+void test__cpuidex(int cpuInfo[4], int function_id, int subfunction_id) {
+  return __cpuidex(cpuInfo, function_id, subfunction_id);
+}
+
 #if defined(__x86_64__)
 
 char test__readgsbyte(unsigned long Offset) {
Index: clang/lib/Headers/intrin.h
===
--- clang/lib/Headers/intrin.h
+++ clang/lib/Headers/intrin.h
@@ -548,13 +548,6 @@
 : "=a"(__eax), "=r"(__ebx), "=c"(__ecx), "=d"(__edx)   \
 : "0"(__leaf), "2"(__count))
 #endif
-static __inline__ void __DEFAULT_FN_ATTRS __cpuid(int __info[4], int __level) {
-  __cpuid_count(__level, 0, __info[0], __info[1], __info[2], __info[3]);
-}
-static __inline__ void __DEFAULT_FN_ATTRS __cpuidex(int __info[4], int __level,
-int __ecx) {
-  __cpuid_count(__level, __ecx, __info[0], __info[1], __info[2], __info[3]);
-}
 static __inline__ void __DEFAULT_FN_ATTRS __halt(void) {
   __asm__ volatile("hlt");
 }
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -14912,6 +14912,45 @@
 return EmitX86Select(*this, Ops[2], Res, Ops[1]);
   }
 
+  case X86::BI__cpuid:
+  case X86::BI__cpuidex: {
+Value *FuncIdArg = EmitScalarExpr(E->getArg(1));
+Value *SubFuncIdArg = BuiltinID == X86::BI__cpuidex
+  ? EmitScalarExpr(E->getArg(2))
+  : llvm::ConstantInt::get(Int32Ty, 0);
+
+// Build the assembly for the cpuid instruction
+SmallString<5> Asm("cpuid");
+std::string Constraints = "={ax},={bx},={cx},={dx},{ax},{cx}";
+std::string MachineClobbers = getTarget().getClobbers();
+if (!MachineClobbers.empty()) {
+  Constraints += ',';
+  Constraints += MachineClobbers;
+}
+
+llvm::StructType *CpuidRetTy =
+llvm::StructType::get(Int32Ty, Int32Ty, Int32Ty, Int32Ty);
+llvm::FunctionType *FTy =
+llvm::FunctionType::get(CpuidRetTy, {Int32Ty, Int32Ty}, false);
+
+llvm::InlineAsm *IA =
+llvm::InlineAsm::get(FTy, Asm, Constraints, /*hasSideEffects=*/true);
+llvm::Value *IACall = Builder.CreateCall(IA, {FuncIdArg, SubFuncIdArg});
+
+Value *BasePtr = EmitScalarExpr(E->getArg(0));
+
+for (uint32_t i = 0; i < 4; i++) {
+  Value *Extracted = Builder.CreateExtractValue(IACall, {i});
+  Value *StorePtr =
+  i == 0 ? BasePtr
+ : Builder.CreateInBoundsGEP(
+   Int32Ty, BasePtr, llvm::ConstantInt::get(Int32Ty, i));
+  Builder.CreateAlignedStore(Extracted, StorePtr, getIntAlign());
+}
+
+return nullptr;
+  }
+
   case X86::BI__emul:
   case X86::BI__emulu: {
 llvm::Type *Int64Ty = llvm::IntegerType::get(getLLVMContext(), 64);
Index: clang/include/clang/Basic/BuiltinsX86.def
===
--- clang/include/clang/Basic/BuiltinsX86.def
+++ clang/include/clang/Basic/BuiltinsX86.def
@@ -2071,6 +2071,9 @@
 TARGET_HEADER_BUILTIN(_ReadBarrier,  "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_WriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
+TARGET_HEADER_BUILTIN(__cpuid,   "vi*i",  "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__cpuidex, "vi*ii", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+
 TARGET_HEADER_BUILTIN(__emul,  "LLiii","nch", "intrin.h", ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__emulu, "ULLiUiUi", "nch", "intrin.h", ALL_MS_LANGUAGES, "")
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121327: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO

2022-03-14 Thread Dan Liew via Phabricator via cfe-commits
delcypher added inline comments.



Comment at: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:1181
+unsigned Priority, const MCSymbol *KeySym) const {
+  // TODO(yln): Remove -lower-global-dtors-via-cxa-atexit fallback flag
+  // (LowerGlobalDtorsViaCxaAtExit) and issue a fatal error here.

If you have access to `Options.LowerGlobalDtorsViaCxaAtExit` then you could do 
something like

```
if (Options.LowerGlobalDtorsViaCxaAtExit)
  report_fatal_error("@llvm.global_dtors should have been lowered already");
```

so that we error when appropriate.

I'm not sure if you have easy access to the option from this class, so if it's 
difficult then we can ignore this problem.



Comment at: llvm/lib/CodeGen/TargetPassConfig.cpp:900
+  // __cxa_atexit calls to avoid emitting the deprecated __mod_term_func.
+  if (TM->getTargetTriple().isOSBinFormatMachO())
+addPass(createLowerGlobalDtorsLegacyPass());

yln wrote:
> yln wrote:
> > delcypher wrote:
> > > Random thought. Do we want to support the legacy way of calling 
> > > destructors, rather than removing it entirely? If we were to do such a 
> > > thing I'd suspect we'd guard using the legacy way on the OS deployment 
> > > target.
> > > 
> > > Just to be clear. I'm happy with the patch the way it is. I'm just 
> > > wondering if we should consider allowing the legacy way as well. I can't 
> > > see an obvious use case for it because the new way should work on older 
> > > OSs too but maybe there's a use case I haven't thought about?
> > Having a way to explicitly request the old behavior sounds like a good 
> > idea.  I will look into it.
> I added an escape hatch to fallback to the old behavior:
> * via Clang driver flag `-fregister-global-dtors-with-atexit`
> * llc / code generation flag -lower-global-dtors-via-cxa-atexit.
> This escape hatch will be removed in the future.
@yln I don't see any modifications to the driver. How is 
`-fregister-global-dtors-with-atexit` added as a driver flag?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121327

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


[PATCH] D121327: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO

2022-03-14 Thread Julian Lettner via Phabricator via cfe-commits
yln added a comment.

@sunfish 
Hi Dan, I hope you are still happy with this change.  I didn't change any 
WebAssembly tests, but rather added a new IR-level test, so all existing 
WebAssembly behavior should stay the same.  Let me know if you have any 
concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121327

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


[PATCH] D120934: [OpenMP][NFC] Refactor new driver to be more general

2022-03-14 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG23d885b3a2e8: [OpenMP][NFC] Refactor new driver to be more 
general (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120934

Files:
  clang/include/clang/Driver/Compilation.h
  clang/lib/Driver/Driver.cpp

Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -3873,11 +3873,6 @@
   // Builder to be used to build offloading actions.
   OffloadingActionBuilder OffloadBuilder(C, Args, Inputs);
 
-  // Offload kinds active for this compilation.
-  unsigned OffloadKinds = Action::OFK_None;
-  if (C.hasOffloadToolChain())
-OffloadKinds |= Action::OFK_OpenMP;
-
   // Construct the actions to perform.
   HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr;
   ActionList LinkerInputs;
@@ -3978,7 +3973,7 @@
 if (!Args.hasArg(options::OPT_fopenmp_new_driver))
   OffloadBuilder.appendTopLevelActions(Actions, Current, InputArg);
 else if (Current)
-  Current->propagateHostOffloadInfo(OffloadKinds,
+  Current->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
 /*BoundArch=*/nullptr);
   }
 
@@ -3999,9 +3994,9 @@
 if (ShouldEmitStaticLibrary(Args)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
 } else if (Args.hasArg(options::OPT_fopenmp_new_driver) &&
-   OffloadKinds != Action::OFK_None) {
+   C.getActiveOffloadKinds() != Action::OFK_None) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-  LA->propagateHostOffloadInfo(OffloadKinds,
+  LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
/*BoundArch=*/nullptr);
 } else {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
@@ -4100,53 +4095,60 @@
   if (!isa(HostAction))
 return HostAction;
 
-  SmallVector ToolChains;
-  ActionList DeviceActions;
+  OffloadAction::DeviceDependences DDeps;
 
   types::ID InputType = Input.first;
   const Arg *InputArg = Input.second;
 
-  auto OpenMPTCRange = C.getOffloadToolChains();
-  for (auto TI = OpenMPTCRange.first, TE = OpenMPTCRange.second; TI != TE; ++TI)
-ToolChains.push_back(TI->second);
+  const Action::OffloadKind OffloadKinds[] = {Action::OFK_OpenMP};
 
-  for (unsigned I = 0; I < ToolChains.size(); ++I)
-DeviceActions.push_back(C.MakeAction(*InputArg, InputType));
+  for (Action::OffloadKind Kind : OffloadKinds) {
+SmallVector ToolChains;
+ActionList DeviceActions;
 
-  if (DeviceActions.empty())
-return HostAction;
+auto TCRange = C.getOffloadToolChains(Kind);
+for (auto TI = TCRange.first, TE = TCRange.second; TI != TE; ++TI)
+  ToolChains.push_back(TI->second);
 
-  auto PL = types::getCompilationPhases(*this, Args, InputType);
+if (ToolChains.empty())
+  continue;
 
-  for (phases::ID Phase : PL) {
-if (Phase == phases::Link) {
-  assert(Phase == PL.back() && "linking must be final compilation step.");
-  break;
-}
+for (unsigned I = 0; I < ToolChains.size(); ++I)
+  DeviceActions.push_back(C.MakeAction(*InputArg, InputType));
 
-auto TC = ToolChains.begin();
-for (Action * : DeviceActions) {
-  A = ConstructPhaseAction(C, Args, Phase, A, Action::OFK_OpenMP);
+if (DeviceActions.empty())
+  return HostAction;
 
-  if (isa(A)) {
-HostAction->setCannotBeCollapsedWithNextDependentAction();
-OffloadAction::HostDependence HDep(
-*HostAction, *C.getSingleOffloadToolChain(),
-/*BourdArch=*/nullptr, Action::OFK_OpenMP);
-OffloadAction::DeviceDependences DDep;
-DDep.add(*A, **TC, /*BoundArch=*/nullptr, Action::OFK_OpenMP);
-A = C.MakeAction(HDep, DDep);
+auto PL = types::getCompilationPhases(*this, Args, InputType);
+
+for (phases::ID Phase : PL) {
+  if (Phase == phases::Link) {
+assert(Phase == PL.back() && "linking must be final compilation step.");
+break;
   }
-  ++TC;
-}
-  }
 
-  OffloadAction::DeviceDependences DDeps;
+  auto TC = ToolChains.begin();
+  for (Action * : DeviceActions) {
+A = ConstructPhaseAction(C, Args, Phase, A, Kind);
+
+if (isa(A) && Kind == Action::OFK_OpenMP) {
+  HostAction->setCannotBeCollapsedWithNextDependentAction();
+  OffloadAction::HostDependence HDep(
+  *HostAction, *C.getSingleOffloadToolChain(),
+  /*BourdArch=*/nullptr, Action::OFK_OpenMP);
+  OffloadAction::DeviceDependences DDep;
+  DDep.add(*A, **TC, /*BoundArch=*/nullptr, Kind);
+  A = C.MakeAction(HDep, DDep);
+}
+++TC;
+  }
+}
 
-  auto TC = ToolChains.begin();
-  for (Action *A : DeviceActions) {
-DDeps.add(*A, **TC, 

[PATCH] D120271: [Clang] Add offload kind to embedded offload object

2022-03-14 Thread Joseph Huber 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 rG9f89769cd775: [Clang] Add offload kind to embedded offload 
object (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120271

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/openmp-offload-gpu.c
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -151,9 +151,11 @@
 
 /// Information for a device offloading file extracted from the host.
 struct DeviceFile {
-  DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
-  : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
+  DeviceFile(StringRef Kind, StringRef TheTriple, StringRef Arch,
+ StringRef Filename)
+  : Kind(Kind), TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
 
+  std::string Kind;
   std::string TheTriple;
   std::string Arch;
   std::string Filename;
@@ -164,11 +166,13 @@
 template <> struct DenseMapInfo {
   static DeviceFile getEmptyKey() {
 return {DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
 DenseMapInfo::getEmptyKey(),
 DenseMapInfo::getEmptyKey()};
   }
   static DeviceFile getTombstoneKey() {
 return {DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
 DenseMapInfo::getTombstoneKey(),
 DenseMapInfo::getTombstoneKey()};
   }
@@ -213,12 +217,13 @@
   return sys::path::parent_path(COWPath).str();
 }
 
-/// Extract the device file from the string '-=.bc'.
+/// Extract the device file from the string '--='.
 DeviceFile getBitcodeLibrary(StringRef LibraryStr) {
   auto DeviceAndPath = StringRef(LibraryStr).split('=');
-  auto TripleAndArch = DeviceAndPath.first.rsplit('-');
-  return DeviceFile(TripleAndArch.first, TripleAndArch.second,
-DeviceAndPath.second);
+  auto StringAndArch = DeviceAndPath.first.rsplit('-');
+  auto KindAndTriple = StringAndArch.first.split('-');
+  return DeviceFile(KindAndTriple.first, KindAndTriple.second,
+StringAndArch.second, DeviceAndPath.second);
 }
 
 /// Get a temporary filename suitable for output.
@@ -299,16 +304,17 @@
 
 SmallVector SectionFields;
 Name->split(SectionFields, '.');
-StringRef DeviceTriple = SectionFields[3];
-StringRef Arch = SectionFields[4];
+StringRef Kind = SectionFields[3];
+StringRef DeviceTriple = SectionFields[4];
+StringRef Arch = SectionFields[5];
 
 if (Expected Contents = Sec.getContents()) {
   SmallString<128> TempFile;
   StringRef DeviceExtension = getDeviceFileExtension(
   DeviceTriple, identify_magic(*Contents) == file_magic::bitcode);
-  if (Error Err =
-  createOutputFile(Prefix + "-device-" + DeviceTriple + "-" + Arch,
-   DeviceExtension, TempFile))
+  if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" +
+   DeviceTriple + "-" + Arch,
+   DeviceExtension, TempFile))
 return std::move(Err);
 
   Expected> OutputOrErr =
@@ -320,7 +326,7 @@
   if (Error E = Output->commit())
 return std::move(E);
 
-  DeviceFiles.emplace_back(DeviceTriple, Arch, TempFile);
+  DeviceFiles.emplace_back(Kind, DeviceTriple, Arch, TempFile);
   ToBeStripped.push_back(*Name);
 }
   }
@@ -412,16 +418,17 @@
 
 SmallVector SectionFields;
 GV.getSection().split(SectionFields, '.');
-StringRef DeviceTriple = SectionFields[3];
-StringRef Arch = SectionFields[4];
+StringRef Kind = SectionFields[3];
+StringRef DeviceTriple = SectionFields[4];
+StringRef Arch = SectionFields[5];
 
 StringRef Contents = CDS->getAsString();
 SmallString<128> TempFile;
 StringRef DeviceExtension = getDeviceFileExtension(
 DeviceTriple, identify_magic(Contents) == file_magic::bitcode);
-if (Error Err =
-createOutputFile(Prefix + "-device-" + DeviceTriple + "-" + Arch,
- DeviceExtension, TempFile))
+if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" + DeviceTriple +
+ "-" + Arch,
+ DeviceExtension, TempFile))
   return std::move(Err);
 
 Expected> OutputOrErr =
@@ -433,7 +440,7 @@
 if (Error E = Output->commit())
   return std::move(E);
 
-DeviceFiles.emplace_back(DeviceTriple, Arch, TempFile);
+DeviceFiles.emplace_back(Kind, DeviceTriple, Arch, TempFile);
 ToBeDeleted.push_back();
   }

[PATCH] D120288: [OpenMP] Implement dense map info for device file

2022-03-14 Thread Joseph Huber 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 rG06b336c4cd2c: [OpenMP] Implement dense map info for device 
file (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120288

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -154,12 +154,33 @@
   DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
   : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
 
-  const std::string TheTriple;
-  const std::string Arch;
-  const std::string Filename;
+  std::string TheTriple;
+  std::string Arch;
+  std::string Filename;
+};
 
-  operator std::string() const { return TheTriple + "-" + Arch; }
+namespace llvm {
+/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+template <> struct DenseMapInfo {
+  static DeviceFile getEmptyKey() {
+return {DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey()};
+  }
+  static DeviceFile getTombstoneKey() {
+return {DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey()};
+  }
+  static unsigned getHashValue(const DeviceFile ) {
+return DenseMapInfo::getHashValue(I.TheTriple) ^
+   DenseMapInfo::getHashValue(I.Arch);
+  }
+  static bool isEqual(const DeviceFile , const DeviceFile ) {
+return LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+  }
 };
+} // namespace llvm
 
 namespace {
 
@@ -1063,28 +1084,28 @@
 Error linkDeviceFiles(ArrayRef DeviceFiles,
   SmallVectorImpl ) {
   // Get the list of inputs for a specific device.
-  StringMap> LinkerInputMap;
+  DenseMap> LinkerInputMap;
   for (auto  : DeviceFiles)
-LinkerInputMap[StringRef(File)].push_back(File.Filename);
+LinkerInputMap[File].push_back(File.Filename);
 
   // Try to link each device toolchain.
   for (auto  : LinkerInputMap) {
-auto TargetFeatures = LinkerInput.getKey().rsplit('-');
-Triple TheTriple(TargetFeatures.first);
-StringRef Arch(TargetFeatures.second);
+DeviceFile  = LinkerInput.getFirst();
+Triple TheTriple = Triple(File.TheTriple);
 
 // Run LTO on any bitcode files and replace the input with the result.
-if (Error Err = linkBitcodeFiles(LinkerInput.getValue(), TheTriple, Arch))
+if (Error Err =
+linkBitcodeFiles(LinkerInput.getSecond(), TheTriple, File.Arch))
   return Err;
 
 // If we are embedding bitcode for JIT, skip the final device linking.
 if (EmbedBitcode) {
-  assert(!LinkerInput.getValue().empty() && "No bitcode image to embed");
-  LinkedImages.push_back(LinkerInput.getValue().front());
+  assert(!LinkerInput.getSecond().empty() && "No bitcode image to embed");
+  LinkedImages.push_back(LinkerInput.getSecond().front());
   continue;
 }
 
-auto ImageOrErr = linkDevice(LinkerInput.getValue(), TheTriple, Arch);
+auto ImageOrErr = linkDevice(LinkerInput.getSecond(), TheTriple, 
File.Arch);
 if (!ImageOrErr)
   return ImageOrErr.takeError();
 


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -154,12 +154,33 @@
   DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
   : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
 
-  const std::string TheTriple;
-  const std::string Arch;
-  const std::string Filename;
+  std::string TheTriple;
+  std::string Arch;
+  std::string Filename;
+};
 
-  operator std::string() const { return TheTriple + "-" + Arch; }
+namespace llvm {
+/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+template <> struct DenseMapInfo {
+  static DeviceFile getEmptyKey() {
+return {DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey()};
+  }
+  static DeviceFile getTombstoneKey() {
+return {DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey()};
+  }
+  static unsigned getHashValue(const DeviceFile ) {
+return DenseMapInfo::getHashValue(I.TheTriple) ^
+   DenseMapInfo::getHashValue(I.Arch);
+  }
+  static bool isEqual(const DeviceFile , const DeviceFile ) {
+return LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+  }
 };
+} // namespace llvm
 
 namespace {
 
@@ -1063,28 +1084,28 @@
 Error 

[PATCH] D120270: [OpenMP] Try to embed offloading objects after codegen

2022-03-14 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG806bbc49dc07: [OpenMP] Try to embed offloading objects after 
codegen (authored by jhuber6).
Herald added a project: All.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120270

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Frontend/embed-object.c


Index: clang/test/Frontend/embed-object.c
===
--- /dev/null
+++ clang/test/Frontend/embed-object.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -x c -triple x86_64-unknown-linux-gnu -emit-llvm 
-fembed-offload-object=%S/Inputs/empty.h,section
+
+// CHECK: @[[OBJECT:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading.section"
+// CHECK: @llvm.compiler.used = appending global [3 x i8*] [i8* getelementptr 
inbounds ([0 x i8], [0 x i8]* @[[OBJECT1]]], section "llvm.metadata"
+
+void foo(void) {}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -43,6 +43,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
+#include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -876,6 +877,9 @@
 
   EmitBackendOptionsMetadata(getCodeGenOpts());
 
+  // If there is device offloading code embed it in the host now.
+  EmbedObject((), CodeGenOpts, getDiags());
+
   // Set visibility from DLL storage class
   // We do this at the end of LLVM IR generation; after any operation
   // that might affect the DLL storage class or the visibility, and


Index: clang/test/Frontend/embed-object.c
===
--- /dev/null
+++ clang/test/Frontend/embed-object.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -x c -triple x86_64-unknown-linux-gnu -emit-llvm -fembed-offload-object=%S/Inputs/empty.h,section
+
+// CHECK: @[[OBJECT:.+]] = private constant [0 x i8] zeroinitializer, section ".llvm.offloading.section"
+// CHECK: @llvm.compiler.used = appending global [3 x i8*] [i8* getelementptr inbounds ([0 x i8], [0 x i8]* @[[OBJECT1]]], section "llvm.metadata"
+
+void foo(void) {}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -43,6 +43,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
+#include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -876,6 +877,9 @@
 
   EmitBackendOptionsMetadata(getCodeGenOpts());
 
+  // If there is device offloading code embed it in the host now.
+  EmbedObject((), CodeGenOpts, getDiags());
+
   // Set visibility from DLL storage class
   // We do this at the end of LLVM IR generation; after any operation
   // that might affect the DLL storage class or the visibility, and
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 06b336c - [OpenMP] Implement dense map info for device file

2022-03-14 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-03-14T20:08:26-04:00
New Revision: 06b336c4cd2c91e0dec877cca1303eddaeb4ef79

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

LOG: [OpenMP] Implement dense map info for device file

This patch implements a DenseMap info struct for the device file type.
This is used to help grouping device files that have the same triple and
architecture. Because of this the filename, which will always be unique
for each file, is not used.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 5807181426459..9ab3cedbc357f 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -154,12 +154,33 @@ struct DeviceFile {
   DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
   : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
 
-  const std::string TheTriple;
-  const std::string Arch;
-  const std::string Filename;
+  std::string TheTriple;
+  std::string Arch;
+  std::string Filename;
+};
 
-  operator std::string() const { return TheTriple + "-" + Arch; }
+namespace llvm {
+/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+template <> struct DenseMapInfo {
+  static DeviceFile getEmptyKey() {
+return {DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey()};
+  }
+  static DeviceFile getTombstoneKey() {
+return {DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey()};
+  }
+  static unsigned getHashValue(const DeviceFile ) {
+return DenseMapInfo::getHashValue(I.TheTriple) ^
+   DenseMapInfo::getHashValue(I.Arch);
+  }
+  static bool isEqual(const DeviceFile , const DeviceFile ) {
+return LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+  }
 };
+} // namespace llvm
 
 namespace {
 
@@ -1063,28 +1084,28 @@ Error linkBitcodeFiles(SmallVectorImpl 
,
 Error linkDeviceFiles(ArrayRef DeviceFiles,
   SmallVectorImpl ) {
   // Get the list of inputs for a specific device.
-  StringMap> LinkerInputMap;
+  DenseMap> LinkerInputMap;
   for (auto  : DeviceFiles)
-LinkerInputMap[StringRef(File)].push_back(File.Filename);
+LinkerInputMap[File].push_back(File.Filename);
 
   // Try to link each device toolchain.
   for (auto  : LinkerInputMap) {
-auto TargetFeatures = LinkerInput.getKey().rsplit('-');
-Triple TheTriple(TargetFeatures.first);
-StringRef Arch(TargetFeatures.second);
+DeviceFile  = LinkerInput.getFirst();
+Triple TheTriple = Triple(File.TheTriple);
 
 // Run LTO on any bitcode files and replace the input with the result.
-if (Error Err = linkBitcodeFiles(LinkerInput.getValue(), TheTriple, Arch))
+if (Error Err =
+linkBitcodeFiles(LinkerInput.getSecond(), TheTriple, File.Arch))
   return Err;
 
 // If we are embedding bitcode for JIT, skip the final device linking.
 if (EmbedBitcode) {
-  assert(!LinkerInput.getValue().empty() && "No bitcode image to embed");
-  LinkedImages.push_back(LinkerInput.getValue().front());
+  assert(!LinkerInput.getSecond().empty() && "No bitcode image to embed");
+  LinkedImages.push_back(LinkerInput.getSecond().front());
   continue;
 }
 
-auto ImageOrErr = linkDevice(LinkerInput.getValue(), TheTriple, Arch);
+auto ImageOrErr = linkDevice(LinkerInput.getSecond(), TheTriple, 
File.Arch);
 if (!ImageOrErr)
   return ImageOrErr.takeError();
 



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


[clang] 23d885b - [OpenMP][NFC] Refactor new driver to be more general

2022-03-14 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-03-14T20:08:29-04:00
New Revision: 23d885b3a2e8a1e0c22cfcbccec410865e7653c9

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

LOG: [OpenMP][NFC] Refactor new driver to be more general

This path refactors the new driver to be less dependent on OpenMP. This
is done in preparation for the new driver to be able to handle other
offloading kinds and compile them together.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/include/clang/Driver/Compilation.h
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Compilation.h 
b/clang/include/clang/Driver/Compilation.h
index 89a43b5b7dc0b..260e2a34ed5a7 100644
--- a/clang/include/clang/Driver/Compilation.h
+++ b/clang/include/clang/Driver/Compilation.h
@@ -143,6 +143,8 @@ class Compilation {
 return ActiveOffloadMask & Kind;
   }
 
+  unsigned getActiveOffloadKinds() const { return ActiveOffloadMask; }
+
   /// Iterator that visits device toolchains of a given kind.
   using const_offload_toolchains_iterator =
   const std::multimap bool hasOffloadToolChain() const {
 return OrderedOffloadingToolchains.find(Kind) !=

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 488f0164c7336..70822490e63b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3873,11 +3873,6 @@ void Driver::BuildActions(Compilation , DerivedArgList 
,
   // Builder to be used to build offloading actions.
   OffloadingActionBuilder OffloadBuilder(C, Args, Inputs);
 
-  // Offload kinds active for this compilation.
-  unsigned OffloadKinds = Action::OFK_None;
-  if (C.hasOffloadToolChain())
-OffloadKinds |= Action::OFK_OpenMP;
-
   // Construct the actions to perform.
   HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr;
   ActionList LinkerInputs;
@@ -3978,7 +3973,7 @@ void Driver::BuildActions(Compilation , DerivedArgList 
,
 if (!Args.hasArg(options::OPT_fopenmp_new_driver))
   OffloadBuilder.appendTopLevelActions(Actions, Current, InputArg);
 else if (Current)
-  Current->propagateHostOffloadInfo(OffloadKinds,
+  Current->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
 /*BoundArch=*/nullptr);
   }
 
@@ -3999,9 +3994,9 @@ void Driver::BuildActions(Compilation , DerivedArgList 
,
 if (ShouldEmitStaticLibrary(Args)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
 } else if (Args.hasArg(options::OPT_fopenmp_new_driver) &&
-   OffloadKinds != Action::OFK_None) {
+   C.getActiveOffloadKinds() != Action::OFK_None) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-  LA->propagateHostOffloadInfo(OffloadKinds,
+  LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
/*BoundArch=*/nullptr);
 } else {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
@@ -4100,53 +4095,60 @@ Action *Driver::BuildOffloadingActions(Compilation ,
   if (!isa(HostAction))
 return HostAction;
 
-  SmallVector ToolChains;
-  ActionList DeviceActions;
+  OffloadAction::DeviceDependences DDeps;
 
   types::ID InputType = Input.first;
   const Arg *InputArg = Input.second;
 
-  auto OpenMPTCRange = C.getOffloadToolChains();
-  for (auto TI = OpenMPTCRange.first, TE = OpenMPTCRange.second; TI != TE; 
++TI)
-ToolChains.push_back(TI->second);
+  const Action::OffloadKind OffloadKinds[] = {Action::OFK_OpenMP};
 
-  for (unsigned I = 0; I < ToolChains.size(); ++I)
-DeviceActions.push_back(C.MakeAction(*InputArg, InputType));
+  for (Action::OffloadKind Kind : OffloadKinds) {
+SmallVector ToolChains;
+ActionList DeviceActions;
 
-  if (DeviceActions.empty())
-return HostAction;
+auto TCRange = C.getOffloadToolChains(Kind);
+for (auto TI = TCRange.first, TE = TCRange.second; TI != TE; ++TI)
+  ToolChains.push_back(TI->second);
 
-  auto PL = types::getCompilationPhases(*this, Args, InputType);
+if (ToolChains.empty())
+  continue;
 
-  for (phases::ID Phase : PL) {
-if (Phase == phases::Link) {
-  assert(Phase == PL.back() && "linking must be final compilation step.");
-  break;
-}
+for (unsigned I = 0; I < ToolChains.size(); ++I)
+  DeviceActions.push_back(C.MakeAction(*InputArg, InputType));
 
-auto TC = ToolChains.begin();
-for (Action * : DeviceActions) {
-  A = ConstructPhaseAction(C, Args, Phase, A, Action::OFK_OpenMP);
+if (DeviceActions.empty())
+  return HostAction;
 
-  if (isa(A)) {
-HostAction->setCannotBeCollapsedWithNextDependentAction();
-OffloadAction::HostDependence HDep(
-*HostAction, 

[clang] 9f89769 - [Clang] Add offload kind to embedded offload object

2022-03-14 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-03-14T20:08:27-04:00
New Revision: 9f89769cd775ce6dc27cad0fbfdd94bf94bc8f99

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

LOG: [Clang] Add offload kind to embedded offload object

This patch adds the offload kind to the embedded section name in
preparation for offloading to different kinda like CUDA or HIP.

Depends on D120288

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/openmp-offload-gpu.c
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 89d8b0c4dc413..5c2b720b0872a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6977,7 +6977,9 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   StringRef InputName = Clang::getBaseInputStem(Args, Inputs);
 
   CmdArgs.push_back(Args.MakeArgString(
-  "-fembed-offload-object=" + File + "," + TC->getTripleString() + "." 
+
+  "-fembed-offload-object=" + File + "," +
+  Action::GetOffloadKindName(Action::OFK_OpenMP) + "." +
+  TC->getTripleString() + "." +
   TCArgs.getLastArgValue(options::OPT_march_EQ) + "." + InputName));
 }
   }
@@ -8297,9 +8299,10 @@ void LinkerWrapper::ConstructJob(Compilation , const 
JobAction ,
  TC->getTriple());
 
   if (!BitcodeLibrary.empty())
-CmdArgs.push_back(
-Args.MakeArgString("-target-library=" + TC->getTripleString() +
-   "-" + Arch + "=" + BitcodeLibrary.back()));
+CmdArgs.push_back(Args.MakeArgString(
+"-target-library=" +
+Action::GetOffloadKindName(Action::OFK_OpenMP) + "-" +
+TC->getTripleString() + "-" + Arch + "=" + BitcodeLibrary.back()));
 }
 
 // Pass in the optimization level to use for LTO.

diff  --git a/clang/test/Driver/openmp-offload-gpu.c 
b/clang/test/Driver/openmp-offload-gpu.c
index 810f6ca2bcffa..7438d6470c795 100644
--- a/clang/test/Driver/openmp-offload-gpu.c
+++ b/clang/test/Driver/openmp-offload-gpu.c
@@ -345,4 +345,4 @@
 // RUN:  -fopenmp-new-driver -no-canonical-prefixes -nogpulib %s -o 
openmp-offload-gpu 2>&1 \
 // RUN:   | FileCheck -check-prefix=NEW_DRIVER_EMBEDDING %s
 
-// NEW_DRIVER_EMBEDDING: 
-fembed-offload-object=[[CUBIN:.*\.cubin]],nvptx64-nvidia-cuda.sm_70
+// NEW_DRIVER_EMBEDDING: 
-fembed-offload-object=[[CUBIN:.*\.cubin]],openmp.nvptx64-nvidia-cuda.sm_70

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 9ab3cedbc357f..a64648e6fe155 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -151,9 +151,11 @@ static codegen::RegisterCodeGenFlags CodeGenFlags;
 
 /// Information for a device offloading file extracted from the host.
 struct DeviceFile {
-  DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
-  : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
+  DeviceFile(StringRef Kind, StringRef TheTriple, StringRef Arch,
+ StringRef Filename)
+  : Kind(Kind), TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
 
+  std::string Kind;
   std::string TheTriple;
   std::string Arch;
   std::string Filename;
@@ -164,11 +166,13 @@ namespace llvm {
 template <> struct DenseMapInfo {
   static DeviceFile getEmptyKey() {
 return {DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
 DenseMapInfo::getEmptyKey(),
 DenseMapInfo::getEmptyKey()};
   }
   static DeviceFile getTombstoneKey() {
 return {DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
 DenseMapInfo::getTombstoneKey(),
 DenseMapInfo::getTombstoneKey()};
   }
@@ -213,12 +217,13 @@ std::string getMainExecutable(const char *Name) {
   return sys::path::parent_path(COWPath).str();
 }
 
-/// Extract the device file from the string '-=.bc'.
+/// Extract the device file from the string '--='.
 DeviceFile getBitcodeLibrary(StringRef LibraryStr) {
   auto DeviceAndPath = StringRef(LibraryStr).split('=');
-  auto TripleAndArch = DeviceAndPath.first.rsplit('-');
-  return DeviceFile(TripleAndArch.first, TripleAndArch.second,
-DeviceAndPath.second);
+  auto StringAndArch = DeviceAndPath.first.rsplit('-');
+  auto KindAndTriple = StringAndArch.first.split('-');
+  return DeviceFile(KindAndTriple.first, KindAndTriple.second,
+StringAndArch.second, 

[clang] 806bbc4 - [OpenMP] Try to embed offloading objects after codegen

2022-03-14 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-03-14T20:08:24-04:00
New Revision: 806bbc49dc07465eddc883b09d48dd93fb64d147

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

LOG: [OpenMP] Try to embed offloading objects after codegen

Currently we use the `-fembed-offload-object` option to embed a binary
file into the host as a named section. This is currently only used as a
codegen action, meaning we only handle this option correctly when the
input is a bitcode file. This patch adds the same handling to embed an
offloading object after we complete code generation. This allows us to
embed the object correctly if the input file is source or bitcode.

Reviewed By: jdoerfert

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

Added: 
clang/test/Frontend/embed-object.c

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ad52c0df9b7ed..3da51261e2299 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -43,6 +43,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
+#include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -876,6 +877,9 @@ void CodeGenModule::Release() {
 
   EmitBackendOptionsMetadata(getCodeGenOpts());
 
+  // If there is device offloading code embed it in the host now.
+  EmbedObject((), CodeGenOpts, getDiags());
+
   // Set visibility from DLL storage class
   // We do this at the end of LLVM IR generation; after any operation
   // that might affect the DLL storage class or the visibility, and

diff  --git a/clang/test/Frontend/embed-object.c 
b/clang/test/Frontend/embed-object.c
new file mode 100644
index 0..f438aa37311b1
--- /dev/null
+++ b/clang/test/Frontend/embed-object.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -x c -triple x86_64-unknown-linux-gnu -emit-llvm 
-fembed-offload-object=%S/Inputs/empty.h,section
+
+// CHECK: @[[OBJECT:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading.section"
+// CHECK: @llvm.compiler.used = appending global [3 x i8*] [i8* getelementptr 
inbounds ([0 x i8], [0 x i8]* @[[OBJECT1]]], section "llvm.metadata"
+
+void foo(void) {}



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


[PATCH] D121327: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO

2022-03-14 Thread Julian Lettner via Phabricator via cfe-commits
yln marked an inline comment as done.
yln added inline comments.



Comment at: llvm/lib/CodeGen/TargetPassConfig.cpp:900
+  // __cxa_atexit calls to avoid emitting the deprecated __mod_term_func.
+  if (TM->getTargetTriple().isOSBinFormatMachO())
+addPass(createLowerGlobalDtorsLegacyPass());

yln wrote:
> delcypher wrote:
> > Random thought. Do we want to support the legacy way of calling 
> > destructors, rather than removing it entirely? If we were to do such a 
> > thing I'd suspect we'd guard using the legacy way on the OS deployment 
> > target.
> > 
> > Just to be clear. I'm happy with the patch the way it is. I'm just 
> > wondering if we should consider allowing the legacy way as well. I can't 
> > see an obvious use case for it because the new way should work on older OSs 
> > too but maybe there's a use case I haven't thought about?
> Having a way to explicitly request the old behavior sounds like a good idea.  
> I will look into it.
I added an escape hatch to fallback to the old behavior:
* via Clang driver flag `-fregister-global-dtors-with-atexit`
* llc / code generation flag -lower-global-dtors-via-cxa-atexit.
This escape hatch will be removed in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121327

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


[PATCH] D121327: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO

2022-03-14 Thread Julian Lettner via Phabricator via cfe-commits
yln updated this revision to Diff 415273.
yln added a comment.
Herald added subscribers: cfe-commits, ormris.
Herald added a project: clang.

Add support for an escape hatch to fallback to the old behavior: via Clang 
driver flag
(`-fregister-global-dtors-with-atexit`) or llc / code generation flag
(`-lower-global-dtors-via-cxa-atexit`).  This escape hatch will be
removed in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121327

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/docs/Passes.rst
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
  llvm/include/llvm/Transforms/Utils.h
  llvm/include/llvm/Transforms/Utils/LowerGlobalDtors.h
  llvm/lib/CodeGen/CodeGen.cpp
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Target/WebAssembly/CMakeLists.txt
  llvm/lib/Target/WebAssembly/WebAssembly.h
  llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/lib/Transforms/Utils/CMakeLists.txt
  llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp
  llvm/test/CodeGen/ARM/ctors_dtors.ll
  llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
  llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll

Index: llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll
===
--- /dev/null
+++ llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll
@@ -0,0 +1,156 @@
+; RUN: opt-lower-global-dtors -S < %s | FileCheck %s --implicit-check-not=llvm.global_dtors
+; RUN: opt -passes=lower-global-dtors -S < %s | FileCheck %s --implicit-check-not=llvm.global_dtors
+
+; Test that @llvm.global_dtors is properly lowered into @llvm.global_ctors,
+; grouping dtor calls by priority and associated symbol.
+
+declare void @orig_ctor()
+declare void @orig_dtor0()
+declare void @orig_dtor1a()
+declare void @orig_dtor1b()
+declare void @orig_dtor1c0()
+declare void @orig_dtor1c1a()
+declare void @orig_dtor1c1b()
+declare void @orig_dtor1c2a()
+declare void @orig_dtor1c2b()
+declare void @orig_dtor1c3()
+declare void @orig_dtor1d()
+declare void @orig_dtor65535()
+declare void @orig_dtor65535c0()
+declare void @after_the_null()
+
+@associatedc0 = external global i8
+@associatedc1 = external global i8
+@associatedc2 = global i8 42
+@associatedc3 = global i8 84
+
+@llvm.global_ctors = appending global
+[1 x { i32, void ()*, i8* }]
+[
+  { i32, void ()*, i8* } { i32 200, void ()* @orig_ctor, i8* null }
+]
+
+@llvm.global_dtors = appending global
+[14 x { i32, void ()*, i8* }]
+[
+  { i32, void ()*, i8* } { i32 0, void ()* @orig_dtor0, i8* null },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1a, i8* null },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1b, i8* null },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c0, i8* @associatedc0 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c1a, i8* @associatedc1 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c1b, i8* @associatedc1 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c2a, i8* @associatedc2 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c2b, i8* @associatedc2 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c3, i8* @associatedc3 },
+  { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1d, i8* null },
+  { i32, void ()*, i8* } { i32 65535, void ()* @orig_dtor65535c0, i8* @associatedc0 },
+  { i32, void ()*, i8* } { i32 65535, void ()* @orig_dtor65535, i8* null },
+  { i32, void ()*, i8* } { i32 65535, void ()* null, i8* null },
+  { i32, void ()*, i8* } { i32 65535, void ()* @after_the_null, i8* null }
+]
+
+; CHECK: @associatedc0 = external global i8
+; CHECK: @associatedc1 = external global i8
+; CHECK: @associatedc2 = global i8 42
+; CHECK: @associatedc3 = global i8 84
+; CHECK: @__dso_handle = extern_weak hidden constant i8
+
+; CHECK-LABEL: @llvm.global_ctors = appending global [10 x { i32, void ()*, i8* }] [
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 200, void ()* @orig_ctor, i8* null },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 0, void ()* @register_call_dtors.0, i8* null },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$0", i8* null },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$1.associatedc0", i8* @associatedc0 },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* @"register_call_dtors.1$2.associatedc1", i8* @associatedc1 },
+; CHECK-SAME:  { i32, void ()*, i8* } { i32 1, void ()* 

[PATCH] D111579: [clang] Fix DIFile directory root on Windows

2022-03-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/CodeGen/debug-prefix-map.c:7
+// RUN: %clang -g -fdebug-prefix-map=%p=%{fssrcroot}UNLIKELY_PATH%{fssep}empty 
-S -c %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang -g -ffile-prefix-map=%p=%{fssrcroot}UNLIKELY_PATH%{fssep}empty 
-S -c %s -emit-llvm -o - | FileCheck %s
 

I think that this illustrates my point on the base differential.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111579

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


[PATCH] D111457: [test] Add lit helper for windows paths

2022-03-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added a comment.
This revision is now accepted and ready to land.

Seems reasonable, though I'm not a fan of the variable names - they seem a bit 
difficult to read due to no separation (e.g., `%fs-src-root` or `%fs_src_root` 
vs `%fssrcroot`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111457

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


[PATCH] D120271: [Clang] Add offload kind to embedded offload object

2022-03-14 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

Adjust commit message. LG, we can address outstanding comments for different 
encodings as we go.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120271

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


[clang] 56e7d6b - [Clang] noinline stmt attribute - emit warnings rather than errors

2022-03-14 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-14T23:40:17+01:00
New Revision: 56e7d6bd444cef8d879adc35dcf461cb4d2ed6d5

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

LOG: [Clang] noinline stmt attribute - emit warnings rather than errors

Compatible behaviour with always_inline stmt attribute

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/Parser/stmt-attributes.c
clang/test/Sema/attr-noinline.c
clang/test/Sema/attr-noinline.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index e28044646080e..a35b2fcbc4fb5 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1770,7 +1770,7 @@ def NoInline : DeclOrStmtAttr {
   let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">,
 C2x<"clang", "noinline">]>];
   let Documentation = [NoInlineDocs];
-  let Subjects = SubjectList<[Function, Stmt], ErrorDiag,
+  let Subjects = SubjectList<[Function, Stmt], WarnDiag,
  "functions and statements">;
   let SimpleHandler = 1;
 }

diff  --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index ebb10da9ab6ea..02776278827c0 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -217,14 +217,13 @@ static Attr *handleNoMergeAttr(Sema , Stmt *St, const 
ParsedAttr ,
 static Attr *handleNoInlineAttr(Sema , Stmt *St, const ParsedAttr ,
 SourceRange Range) {
   NoInlineAttr NIA(S.Context, A);
-  CallExprFinder CEF(S, St);
-
   if (!NIA.isClangNoInline()) {
 S.Diag(St->getBeginLoc(), diag::warn_function_attribute_ignored_in_stmt)
 << "[[clang::noinline]]";
 return nullptr;
   }
 
+  CallExprFinder CEF(S, St);
   if (!CEF.foundCallExpr()) {
 S.Diag(St->getBeginLoc(), diag::warn_attribute_ignored_no_calls_in_stmt)
 << A;

diff  --git a/clang/test/Parser/stmt-attributes.c 
b/clang/test/Parser/stmt-attributes.c
index 4a8c2c1d2a74d..ccd206e70a225 100644
--- a/clang/test/Parser/stmt-attributes.c
+++ b/clang/test/Parser/stmt-attributes.c
@@ -45,7 +45,7 @@ void foo(int i) {
   }
 
   __attribute__((fastcall)) goto there; // expected-error {{'fastcall' 
attribute cannot be applied to a statement}}
-  __attribute__((noinline)) there : // expected-error {{'noinline' 
attribute only applies to functions and statements}}
+  __attribute__((noinline)) there : // expected-warning {{'noinline' 
attribute only applies to functions and statements}}
 
 __attribute__((weakref)) return; // 
expected-error {{'weakref' attribute only applies to variables and functions}}
 

diff  --git a/clang/test/Sema/attr-noinline.c b/clang/test/Sema/attr-noinline.c
index 065e8fad716aa..2a3532df4b34b 100644
--- a/clang/test/Sema/attr-noinline.c
+++ b/clang/test/Sema/attr-noinline.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only
 
-int a __attribute__((noinline)); // expected-error {{'noinline' attribute only 
applies to functions and statements}}
+int a __attribute__((noinline)); // expected-warning {{'noinline' attribute 
only applies to functions and statements}}
 
 void t1(void) __attribute__((noinline));
 

diff  --git a/clang/test/Sema/attr-noinline.cpp 
b/clang/test/Sema/attr-noinline.cpp
index 97c894a3f2f0c..d35782f11adbb 100644
--- a/clang/test/Sema/attr-noinline.cpp
+++ b/clang/test/Sema/attr-noinline.cpp
@@ -13,7 +13,7 @@ void foo() {
   int x;
   [[clang::noinline]] x = 0; // expected-warning {{'noinline' attribute is 
ignored because there exists no call expression inside the statement}}
   [[clang::noinline]] { asm("nop"); } // expected-warning {{'noinline' 
attribute is ignored because there exists no call expression inside the 
statement}}
-  [[clang::noinline]] label: x = 1; // expected-error {{'noinline' attribute 
only applies to functions and statements}}
+  [[clang::noinline]] label: x = 1; // expected-warning {{'noinline' attribute 
only applies to functions and statements}}
 
 
   [[clang::noinline]] always_inline_fn(); // expected-warning {{statement 
attribute 'noinline' has higher precedence than function attribute 
'always_inline'}}
@@ -24,4 +24,4 @@ void foo() {
   __attribute__((noinline)) bar(); // expected-warning {{attribute is ignored 
on this statement as it only applies to functions; use '[[clang::noinline]]' on 
statements}}
 }
 
-[[clang::noinline]] static int i = bar(); // expected-error {{'noinline' 
attribute only applies to functions and statements}}
+[[clang::noinline]] static int i = bar(); // expected-warning {{'noinline' 
attribute only applies to functions and statements}}




[PATCH] D121646: [Concepts] Fix an assertion failure while diagnosing constrained function candidates

2022-03-14 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 415251.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121646

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -208,3 +208,17 @@
 return (int*)nullptr; // FIXME: should error
   }
 }
+
+namespace PR54379 {
+template 
+struct A {
+  static void f() requires (N == 0) { return; } // expected-note {{candidate 
template ignored: constraints not satisfied}} expected-note {{evaluated to 
false}}
+  static void f() requires (N == 1) { return; } // expected-note {{candidate 
template ignored: constraints not satisfied}} expected-note {{evaluated to 
false}}
+};
+void (*f1)() = A<2>::f; // expected-error {{address of overloaded function 'f' 
does not match required type}}
+
+struct B {
+  template  static void f() requires (N2 == 0) { return; }  // 
expected-note {{candidate template ignored: constraints not satisfied [with N2 
= 1]}} expected-note {{evaluated to false}}
+};
+void (*f2)() = B::f; // expected-error {{address of overloaded function 'f' 
does not match required type}}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10256,10 +10256,19 @@
   return false;
 if (!Satisfaction.IsSatisfied) {
   if (Complain) {
-if (InOverloadResolution)
+if (InOverloadResolution) {
+  SmallString<128> TemplateArgString;
+  if (FunctionTemplateDecl *FunTmpl = FD->getPrimaryTemplate()) {
+TemplateArgString += " ";
+TemplateArgString += S.getTemplateArgumentBindingsText(
+FunTmpl->getTemplateParameters(),
+*FD->getTemplateSpecializationArgs());
+  }
+
   S.Diag(FD->getBeginLoc(),
- diag::note_ovl_candidate_unsatisfied_constraints);
-else
+ diag::note_ovl_candidate_unsatisfied_constraints)
+  << TemplateArgString;
+} else
   S.Diag(Loc, diag::err_addrof_function_constraints_not_satisfied)
   << FD;
 S.DiagnoseUnsatisfiedConstraint(Satisfaction);


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -208,3 +208,17 @@
 return (int*)nullptr; // FIXME: should error
   }
 }
+
+namespace PR54379 {
+template 
+struct A {
+  static void f() requires (N == 0) { return; } // expected-note {{candidate template ignored: constraints not satisfied}} expected-note {{evaluated to false}}
+  static void f() requires (N == 1) { return; } // expected-note {{candidate template ignored: constraints not satisfied}} expected-note {{evaluated to false}}
+};
+void (*f1)() = A<2>::f; // expected-error {{address of overloaded function 'f' does not match required type}}
+
+struct B {
+  template  static void f() requires (N2 == 0) { return; }  // expected-note {{candidate template ignored: constraints not satisfied [with N2 = 1]}} expected-note {{evaluated to false}}
+};
+void (*f2)() = B::f; // expected-error {{address of overloaded function 'f' does not match required type}}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10256,10 +10256,19 @@
   return false;
 if (!Satisfaction.IsSatisfied) {
   if (Complain) {
-if (InOverloadResolution)
+if (InOverloadResolution) {
+  SmallString<128> TemplateArgString;
+  if (FunctionTemplateDecl *FunTmpl = FD->getPrimaryTemplate()) {
+TemplateArgString += " ";
+TemplateArgString += S.getTemplateArgumentBindingsText(
+FunTmpl->getTemplateParameters(),
+*FD->getTemplateSpecializationArgs());
+  }
+
   S.Diag(FD->getBeginLoc(),
- diag::note_ovl_candidate_unsatisfied_constraints);
-else
+ diag::note_ovl_candidate_unsatisfied_constraints)
+  << TemplateArgString;
+} else
   S.Diag(Loc, diag::err_addrof_function_constraints_not_satisfied)
   << FD;
 S.DiagnoseUnsatisfiedConstraint(Satisfaction);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121646: [Concepts] Fix an assertion failure while diagnosing constrained function candidates

2022-03-14 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D121646#3380893 , @erichkeane 
wrote:

> This seems acceptable to me. Though, I wonder if 
> `getTemplateArgumentBindingsText` should produce the leading space, that way 
> we could just pass the result of it directly, rather than have to create a 
> SmallString everywhere.  WDYT?

There are other places (outside SemaOverload) that use this function and don't 
need a space, though.
I thought about just putting the space in the diagnostic itself, but then 
sometimes you don't get template arguments and it fails.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121646

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


[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp:55
   // CHECK-NEXT:%[[ALIGNMENT_RELOADED:.*]] = load i64, 
i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 noundef 
%[[ALIGNMENT_RELOADED]])
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64
-  // CHECK-SANITIZE-NEXT:   %[[MASK:.*]] = sub i64 
%[[ALIGNMENT_RELOADED]], 1
-  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 
%[[PTRINT]], %[[MASK]]
-  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 
%[[MASKEDPTR]], 0
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64, !nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label 
%[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
-  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
-  // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 
23){{.*}}, !nosanitize
-  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
-  // CHECK-SANITIZE:  [[CONT]]:
-  // CHECK-NEXT:call void @llvm.assume(i1 true) [ 
"align"(i8** %[[X_RETURNED]], i64 %1) ]
+  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 allocalign noundef 
%[[ALIGNMENT_RELOADED]])
   // CHECK-NEXT:ret i8** %[[X_RETURNED]]

jyknight wrote:
> lebedev.ri wrote:
> > durin42 wrote:
> > > lebedev.ri wrote:
> > > > durin42 wrote:
> > > > > lebedev.ri wrote:
> > > > > > This is a regression, the old behavior was correct.
> > > > > I don't think so: we now (as of D121629) check the alignment of the 
> > > > > returned pointer in the callee instead of the caller, and LLVM knows 
> > > > > about allocalign implying an alignment at the callsite. So I think 
> > > > > it's correctly optimizing away the sanitizer checks here.
> > > > > 
> > > > > You or @jyknight will need to correct me if my understanding is 
> > > > > incorrect here, but my understanding was that this change was what 
> > > > > motivated D121629 in the first place.
> > > > I'm saying that as the author of said test and it's behavior.
> > > How is this wrong though? Are you concerned because the `allocalign` 
> > > isn't being asserted upon by the sanitizer in the caller? How this a 
> > > problem given that the callee code now does the assertions in sanitizer 
> > > mode?
> > > 
> > > (If I'm not understanding please elaborate: this is my first nontrivial 
> > > work on LLVM, so I'm going to need more than "I wrote this, and you are 
> > > wrong" by way of help understanding my error.)
> > The original code was not relying on the happenstance that the called code 
> > would have been
> > compiled with sanitizers, and this new code does make such an assumption. 
> > This is a regression.
> > As i have said, we simply should not be emitting `allocalign` in such 
> > situation,
> > that would defeat the sanitizer check that should be emitted here.
> I suggested this change, which I think reasonable given that it's the same 
> thing we are doing for null sanitization.
> 
> E.g. `clang -fsanitize=null -emit-llvm -O2 -o - -S /tmp/test.cc` on:
> ```
> int (int *x);
> 
> int bar(int*x) {
>   return foo(x);
> }
> ```
> ->
> ```
> define dso_local noundef i32 @_Z3barPi(i32* noundef %x) local_unnamed_addr #0 
> {
> entry:
>   %call = tail call noundef nonnull align 4 dereferenceable(4) i32* 
> @_Z3fooPi(i32* noundef %x)
>   %0 = load i32, i32* %call, align 4, !tbaa !3
>   ret i32 %0
> }
> ```
> 
> There, too, we validate it in the callee before returning.
> 
> 
That may be your view on the situation, but i'm not sure i agree with it.
I think that is simply a bug. More concretely, now you will have a discrepancy 
with
e.g. `catch-alignment-assumption-attribute-assume_aligned-on-function.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D121646: [Concepts] Fix an assertion failure while diagnosing constrained function candidates

2022-03-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This seems acceptable to me. Though, I wonder if 
`getTemplateArgumentBindingsText` should produce the leading space, that way we 
could just pass the result of it directly, rather than have to create a 
SmallString everywhere.  WDYT?




Comment at: clang/lib/Sema/SemaOverload.cpp:10261
+  SmallString<128> TemplateArgString;
+  TemplateArgString.clear();
+  if (FunctionTemplateDecl *FunTmpl = FD->getPrimaryTemplate()) {

.clear shouldn't be required as you just constructed it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121646

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


[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp:55
   // CHECK-NEXT:%[[ALIGNMENT_RELOADED:.*]] = load i64, 
i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 noundef 
%[[ALIGNMENT_RELOADED]])
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64
-  // CHECK-SANITIZE-NEXT:   %[[MASK:.*]] = sub i64 
%[[ALIGNMENT_RELOADED]], 1
-  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 
%[[PTRINT]], %[[MASK]]
-  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 
%[[MASKEDPTR]], 0
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64, !nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label 
%[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
-  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
-  // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 
23){{.*}}, !nosanitize
-  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
-  // CHECK-SANITIZE:  [[CONT]]:
-  // CHECK-NEXT:call void @llvm.assume(i1 true) [ 
"align"(i8** %[[X_RETURNED]], i64 %1) ]
+  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 allocalign noundef 
%[[ALIGNMENT_RELOADED]])
   // CHECK-NEXT:ret i8** %[[X_RETURNED]]

lebedev.ri wrote:
> durin42 wrote:
> > lebedev.ri wrote:
> > > durin42 wrote:
> > > > lebedev.ri wrote:
> > > > > This is a regression, the old behavior was correct.
> > > > I don't think so: we now (as of D121629) check the alignment of the 
> > > > returned pointer in the callee instead of the caller, and LLVM knows 
> > > > about allocalign implying an alignment at the callsite. So I think it's 
> > > > correctly optimizing away the sanitizer checks here.
> > > > 
> > > > You or @jyknight will need to correct me if my understanding is 
> > > > incorrect here, but my understanding was that this change was what 
> > > > motivated D121629 in the first place.
> > > I'm saying that as the author of said test and it's behavior.
> > How is this wrong though? Are you concerned because the `allocalign` isn't 
> > being asserted upon by the sanitizer in the caller? How this a problem 
> > given that the callee code now does the assertions in sanitizer mode?
> > 
> > (If I'm not understanding please elaborate: this is my first nontrivial 
> > work on LLVM, so I'm going to need more than "I wrote this, and you are 
> > wrong" by way of help understanding my error.)
> The original code was not relying on the happenstance that the called code 
> would have been
> compiled with sanitizers, and this new code does make such an assumption. 
> This is a regression.
> As i have said, we simply should not be emitting `allocalign` in such 
> situation,
> that would defeat the sanitizer check that should be emitted here.
I suggested this change, which I think reasonable given that it's the same 
thing we are doing for null sanitization.

E.g. `clang -fsanitize=null -emit-llvm -O2 -o - -S /tmp/test.cc` on:
```
int (int *x);

int bar(int*x) {
  return foo(x);
}
```
->
```
define dso_local noundef i32 @_Z3barPi(i32* noundef %x) local_unnamed_addr #0 {
entry:
  %call = tail call noundef nonnull align 4 dereferenceable(4) i32* 
@_Z3fooPi(i32* noundef %x)
  %0 = load i32, i32* %call, align 4, !tbaa !3
  ret i32 %0
}
```

There, too, we validate it in the callee before returning.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D121646: [Concepts] Fix an assertion failure while diagnosing constrained function candidates

2022-03-14 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added a reviewer: erichkeane.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

See: https://github.com/llvm/llvm-project/issues/54379

I tried to see if I can reuse `ResolveAddressOfOverloadedFunction` for explicit 
function instantiation and so I managed to hit this ICE.

Bug was the diagnostic required an argument (%0) and specific code path didn't 
pass an argument.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121646

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -208,3 +208,17 @@
 return (int*)nullptr; // FIXME: should error
   }
 }
+
+namespace PR54379 {
+template 
+struct A {
+  static void f() requires (N == 0) { return; } // expected-note {{candidate 
template ignored: constraints not satisfied}} expected-note {{evaluated to 
false}}
+  static void f() requires (N == 1) { return; } // expected-note {{candidate 
template ignored: constraints not satisfied}} expected-note {{evaluated to 
false}}
+};
+void (*f1)() = A<2>::f; // expected-error {{address of overloaded function 'f' 
does not match required type}}
+
+struct B {
+  template  static void f() requires (N2 == 0) { return; }  // 
expected-note {{candidate template ignored: constraints not satisfied [with N2 
= 1]}} expected-note {{evaluated to false}}
+};
+void (*f2)() = B::f; // expected-error {{address of overloaded function 'f' 
does not match required type}}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10256,10 +10256,19 @@
   return false;
 if (!Satisfaction.IsSatisfied) {
   if (Complain) {
-if (InOverloadResolution)
+if (InOverloadResolution) {
+  SmallString<128> TemplateArgString;
+  TemplateArgString.clear();
+  if (FunctionTemplateDecl *FunTmpl = FD->getPrimaryTemplate()) {
+TemplateArgString += " ";
+TemplateArgString += S.getTemplateArgumentBindingsText(
+  FunTmpl->getTemplateParameters(), 
*FD->getTemplateSpecializationArgs());
+  }
+
   S.Diag(FD->getBeginLoc(),
- diag::note_ovl_candidate_unsatisfied_constraints);
-else
+ diag::note_ovl_candidate_unsatisfied_constraints)
+  << TemplateArgString;
+} else
   S.Diag(Loc, diag::err_addrof_function_constraints_not_satisfied)
   << FD;
 S.DiagnoseUnsatisfiedConstraint(Satisfaction);


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -208,3 +208,17 @@
 return (int*)nullptr; // FIXME: should error
   }
 }
+
+namespace PR54379 {
+template 
+struct A {
+  static void f() requires (N == 0) { return; } // expected-note {{candidate template ignored: constraints not satisfied}} expected-note {{evaluated to false}}
+  static void f() requires (N == 1) { return; } // expected-note {{candidate template ignored: constraints not satisfied}} expected-note {{evaluated to false}}
+};
+void (*f1)() = A<2>::f; // expected-error {{address of overloaded function 'f' does not match required type}}
+
+struct B {
+  template  static void f() requires (N2 == 0) { return; }  // expected-note {{candidate template ignored: constraints not satisfied [with N2 = 1]}} expected-note {{evaluated to false}}
+};
+void (*f2)() = B::f; // expected-error {{address of overloaded function 'f' does not match required type}}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10256,10 +10256,19 @@
   return false;
 if (!Satisfaction.IsSatisfied) {
   if (Complain) {
-if (InOverloadResolution)
+if (InOverloadResolution) {
+  SmallString<128> TemplateArgString;
+  TemplateArgString.clear();
+  if (FunctionTemplateDecl *FunTmpl = FD->getPrimaryTemplate()) {
+TemplateArgString += " ";
+TemplateArgString += S.getTemplateArgumentBindingsText(
+  FunTmpl->getTemplateParameters(), *FD->getTemplateSpecializationArgs());
+  }
+
   S.Diag(FD->getBeginLoc(),
- diag::note_ovl_candidate_unsatisfied_constraints);
-else
+ diag::note_ovl_candidate_unsatisfied_constraints)
+  << TemplateArgString;
+} else
   S.Diag(Loc, 

[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp:55
   // CHECK-NEXT:%[[ALIGNMENT_RELOADED:.*]] = load i64, 
i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 noundef 
%[[ALIGNMENT_RELOADED]])
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64
-  // CHECK-SANITIZE-NEXT:   %[[MASK:.*]] = sub i64 
%[[ALIGNMENT_RELOADED]], 1
-  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 
%[[PTRINT]], %[[MASK]]
-  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 
%[[MASKEDPTR]], 0
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64, !nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label 
%[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
-  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
-  // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 
23){{.*}}, !nosanitize
-  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
-  // CHECK-SANITIZE:  [[CONT]]:
-  // CHECK-NEXT:call void @llvm.assume(i1 true) [ 
"align"(i8** %[[X_RETURNED]], i64 %1) ]
+  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 allocalign noundef 
%[[ALIGNMENT_RELOADED]])
   // CHECK-NEXT:ret i8** %[[X_RETURNED]]

durin42 wrote:
> lebedev.ri wrote:
> > durin42 wrote:
> > > lebedev.ri wrote:
> > > > This is a regression, the old behavior was correct.
> > > I don't think so: we now (as of D121629) check the alignment of the 
> > > returned pointer in the callee instead of the caller, and LLVM knows 
> > > about allocalign implying an alignment at the callsite. So I think it's 
> > > correctly optimizing away the sanitizer checks here.
> > > 
> > > You or @jyknight will need to correct me if my understanding is incorrect 
> > > here, but my understanding was that this change was what motivated 
> > > D121629 in the first place.
> > I'm saying that as the author of said test and it's behavior.
> How is this wrong though? Are you concerned because the `allocalign` isn't 
> being asserted upon by the sanitizer in the caller? How this a problem given 
> that the callee code now does the assertions in sanitizer mode?
> 
> (If I'm not understanding please elaborate: this is my first nontrivial work 
> on LLVM, so I'm going to need more than "I wrote this, and you are wrong" by 
> way of help understanding my error.)
The original code was not relying on the happenstance that the called code 
would have been
compiled with sanitizers, and this new code does make such an assumption. This 
is a regression.
As i have said, we simply should not be emitting `allocalign` in such situation,
that would defeat the sanitizer check that should be emitted here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added inline comments.



Comment at: 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp:55
   // CHECK-NEXT:%[[ALIGNMENT_RELOADED:.*]] = load i64, 
i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 noundef 
%[[ALIGNMENT_RELOADED]])
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64
-  // CHECK-SANITIZE-NEXT:   %[[MASK:.*]] = sub i64 
%[[ALIGNMENT_RELOADED]], 1
-  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 
%[[PTRINT]], %[[MASK]]
-  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 
%[[MASKEDPTR]], 0
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64, !nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label 
%[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
-  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
-  // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 
23){{.*}}, !nosanitize
-  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
-  // CHECK-SANITIZE:  [[CONT]]:
-  // CHECK-NEXT:call void @llvm.assume(i1 true) [ 
"align"(i8** %[[X_RETURNED]], i64 %1) ]
+  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 allocalign noundef 
%[[ALIGNMENT_RELOADED]])
   // CHECK-NEXT:ret i8** %[[X_RETURNED]]

lebedev.ri wrote:
> durin42 wrote:
> > lebedev.ri wrote:
> > > This is a regression, the old behavior was correct.
> > I don't think so: we now (as of D121629) check the alignment of the 
> > returned pointer in the callee instead of the caller, and LLVM knows about 
> > allocalign implying an alignment at the callsite. So I think it's correctly 
> > optimizing away the sanitizer checks here.
> > 
> > You or @jyknight will need to correct me if my understanding is incorrect 
> > here, but my understanding was that this change was what motivated D121629 
> > in the first place.
> I'm saying that as the author of said test and it's behavior.
How is this wrong though? Are you concerned because the `allocalign` isn't 
being asserted upon by the sanitizer in the caller? How this a problem given 
that the callee code now does the assertions in sanitizer mode?

(If I'm not understanding please elaborate: this is my first nontrivial work on 
LLVM, so I'm going to need more than "I wrote this, and you are wrong" by way 
of help understanding my error.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp:55
   // CHECK-NEXT:%[[ALIGNMENT_RELOADED:.*]] = load i64, 
i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 noundef 
%[[ALIGNMENT_RELOADED]])
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64
-  // CHECK-SANITIZE-NEXT:   %[[MASK:.*]] = sub i64 
%[[ALIGNMENT_RELOADED]], 1
-  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 
%[[PTRINT]], %[[MASK]]
-  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 
%[[MASKEDPTR]], 0
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64, !nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label 
%[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
-  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
-  // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 
23){{.*}}, !nosanitize
-  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
-  // CHECK-SANITIZE:  [[CONT]]:
-  // CHECK-NEXT:call void @llvm.assume(i1 true) [ 
"align"(i8** %[[X_RETURNED]], i64 %1) ]
+  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 allocalign noundef 
%[[ALIGNMENT_RELOADED]])
   // CHECK-NEXT:ret i8** %[[X_RETURNED]]

durin42 wrote:
> lebedev.ri wrote:
> > This is a regression, the old behavior was correct.
> I don't think so: we now (as of D121629) check the alignment of the returned 
> pointer in the callee instead of the caller, and LLVM knows about allocalign 
> implying an alignment at the callsite. So I think it's correctly optimizing 
> away the sanitizer checks here.
> 
> You or @jyknight will need to correct me if my understanding is incorrect 
> here, but my understanding was that this change was what motivated D121629 in 
> the first place.
I'm saying that as the author of said test and it's behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added inline comments.



Comment at: 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp:55
   // CHECK-NEXT:%[[ALIGNMENT_RELOADED:.*]] = load i64, 
i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 noundef 
%[[ALIGNMENT_RELOADED]])
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64
-  // CHECK-SANITIZE-NEXT:   %[[MASK:.*]] = sub i64 
%[[ALIGNMENT_RELOADED]], 1
-  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 
%[[PTRINT]], %[[MASK]]
-  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 
%[[MASKEDPTR]], 0
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64, !nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label 
%[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
-  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
-  // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 
23){{.*}}, !nosanitize
-  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
-  // CHECK-SANITIZE:  [[CONT]]:
-  // CHECK-NEXT:call void @llvm.assume(i1 true) [ 
"align"(i8** %[[X_RETURNED]], i64 %1) ]
+  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 allocalign noundef 
%[[ALIGNMENT_RELOADED]])
   // CHECK-NEXT:ret i8** %[[X_RETURNED]]

lebedev.ri wrote:
> This is a regression, the old behavior was correct.
I don't think so: we now (as of D121629) check the alignment of the returned 
pointer in the callee instead of the caller, and LLVM knows about allocalign 
implying an alignment at the callsite. So I think it's correctly optimizing 
away the sanitizer checks here.

You or @jyknight will need to correct me if my understanding is incorrect here, 
but my understanding was that this change was what motivated D121629 in the 
first place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D111400: [Clang] Implement P2242R3

2022-03-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 415240.
cor3ntin added a comment.

clamg-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111400

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/SemaCXX/constant-expression-cxx14.cpp
  clang/test/SemaCXX/constant-expression-cxx2b.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1361,7 +1361,7 @@
 
   Non-literal variables (and labels and gotos) in constexpr functions
   https://wg21.link/P2242R3;>P2242R3
-  No
+  Clang 15
 
 
   Character encoding of diagnostic text
Index: clang/test/SemaCXX/constant-expression-cxx2b.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constant-expression-cxx2b.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify %s -fcxx-exceptions -triple=x86_64-linux-gnu -Wpre-c++2b-compat
+
+constexpr int f(int n) {  // expected-error {{constexpr function never produces a constant expression}}
+  static const int m = n; // expected-warning {{definition of a static variable in a constexpr function is incompatible with C++ standards before C++2b}} \
+  // expected-note {{control flows through the declaration of a static variable}}
+  return m;
+}
+constexpr int g(int n) {//  expected-error {{constexpr function never produces a constant expression}}
+  thread_local const int m = n; //  expected-warning {{definition of a thread_local variable in a constexpr function is incompatible with C++ standards before C++2b}} \
+// expected-note {{control flows through the declaration of a thread_local variable}}
+  return m;
+}
+
+constexpr int h(int n) {  // expected-error {{constexpr function never produces a constant expression}}
+  static const int m = n; // expected-warning {{definition of a static variable in a constexpr function is incompatible with C++ standards before C++2b}} \
+  // expected-note {{control flows through the declaration of a static variable}}
+  return  - 
+}
+constexpr int i(int n) {//  expected-error {{constexpr function never produces a constant expression}}
+  thread_local const int m = n; //  expected-warning {{definition of a thread_local variable in a constexpr function is incompatible with C++ standards before C++2b}} \
+// expected-note {{control flows through the declaration of a thread_local variable}}
+  return  - 
+}
+
+constexpr int j(int n) {
+  if (!n)
+return 0;
+  static const int m = n; // expected-warning{{definition of a static variable in a constexpr function is incompatible with C++ standards before C++2b}}
+  return m;
+}
+
+constexpr int k(int n) {
+  if (!n)
+return 0;
+  thread_local const int m = n; // expected-warning{{definition of a thread_local variable in a constexpr function is incompatible with C++ standards before C++2b}} \
+
+  return m;
+}
+
+constexpr int j_evaluated(int n) {
+  if (!n)
+return 0;
+  static const int m = n; // expected-warning{{definition of a static variable in a constexpr function is incompatible with C++ standards before C++2b}} \
+  // expected-note {{control flows through the declaration of a static variable}}
+  return m;
+}
+
+constexpr int je = j_evaluated(1); // expected-error {{constexpr variable 'je' must be initialized by a constant expression}}  \
+   // expected-note {{in call}}
+
+constexpr int k_evaluated(int n) {
+  if (!n)
+return 0;
+  thread_local const int m = n; // expected-warning{{definition of a thread_local variable in a constexpr function is incompatible with C++ standards before C++2b}} \
+// expected-note {{control flows through the declaration of a thread_local variable}}
+
+  return m;
+}
+
+constexpr int ke = k_evaluated(1); //expected-error {{constexpr variable 'ke' must be initialized by a constant expression}} \
+   //expected-note {{in call}}
+
+namespace eval_goto {
+
+constexpr int f(int x) {
+  if (x) {
+return 0;
+  } else {
+goto test; // expected-note {{subexpression not valid in a constant expression}} \
+// expected-warning {{use of this statement in a constexpr function is incompatible with C++ 

[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a reviewer: lebedev.ri.
lebedev.ri added inline comments.



Comment at: 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp:55
   // CHECK-NEXT:%[[ALIGNMENT_RELOADED:.*]] = load i64, 
i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 noundef 
%[[ALIGNMENT_RELOADED]])
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64
-  // CHECK-SANITIZE-NEXT:   %[[MASK:.*]] = sub i64 
%[[ALIGNMENT_RELOADED]], 1
-  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 
%[[PTRINT]], %[[MASK]]
-  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 
%[[MASKEDPTR]], 0
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64, !nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label 
%[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
-  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
-  // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 
23){{.*}}, !nosanitize
-  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
-  // CHECK-SANITIZE:  [[CONT]]:
-  // CHECK-NEXT:call void @llvm.assume(i1 true) [ 
"align"(i8** %[[X_RETURNED]], i64 %1) ]
+  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 allocalign noundef 
%[[ALIGNMENT_RELOADED]])
   // CHECK-NEXT:ret i8** %[[X_RETURNED]]

This is a regression, the old behavior was correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D121532: [Clang][WIP] Fix Unevaluated Lambdas

2022-03-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D121532#3380580 , @shafik wrote:

> Can you add a test to `ASTImpoterTest.cpp` that checks that we import the 
> `LambdaDependencyKind` correctly?

Sure, if we agree that the direction is sufficiently palatable (I'm not 
convince it is yet), I can add such a test (and more generally cleanup the test)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121532

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


[PATCH] D121629: clang: also check alloc_alignment claims in return

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

In D121629#3380191 , @durin42 wrote:

> In D121629#3380175 , @lebedev.ri 
> wrote:
>
>> Please can you pose the next patch itself?
>> I suspect that propagation should simply not be done when sanitizer is 
>> enabled.
>
> I'm working on the next patch. Sadly we can't omit `allocalign`s into the IR 
> layer when sanitizers are enabled because nothing will (when I'm done 
> cleaning up MemoryBuiltins.cpp) have a way to know anything about the 
> alignment of returned pointers.

The rest of the stack is now implemented and uploaded.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121629

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


[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 retitled this revision from "CGCall: also emit LLVM `allocalign` 
attribute when handling AllocAlign" to "clang: emit allocalign to LLVM for 
alloc_align attributes".
durin42 edited the summary of this revision.
durin42 updated this revision to Diff 415230.
Herald added a project: All.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c

[PATCH] D121629: clang: also check alloc_alignment claims in return

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 415226.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121629

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp

Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
@@ -8,15 +8,38 @@
 
 char **__attribute__((alloc_align(2)))
 passthrough(char **x, unsigned long alignment) {
-  // CHECK:  define{{.*}} i8** @[[PASSTHROUGH:.*]](i8** noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
-  // CHECK-NEXT: entry:
-  // CHECK-NEXT:   %[[X_ADDR:.*]] = alloca i8**, align 8
-  // CHECK-NEXT:   %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
-  // CHECK-NEXT:   store i8** %[[X]], i8*** %[[X_ADDR]], align 8
-  // CHECK-NEXT:   store i64 %[[ALIGNMENT]], i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:   %[[X_RELOADED:.*]] = load i8**, i8*** %[[X_ADDR]], align 8
-  // CHECK-NEXT:   ret i8** %[[X_RELOADED]]
-  // CHECK-NEXT: }
+  // CHECK:define{{.*}} i8** @[[PASSTHROUGH:.*]](i8** noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
+  // CHECK-NEXT:   entry:
+  // CHECK-SANITIZE-NEXT:%return.sloc.ptr = alloca i8*, align 8
+  // CHECK-NEXT: %[[X_ADDR:.*]] = alloca i8**, align 8
+  // CHECK-NEXT: %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
+  // CHECK-SANITIZE-NEXT:store i8* null, i8** %return.sloc.ptr, align 8
+  // CHECK-NEXT: store i8** %[[X]], i8*** %[[X_ADDR]], align 8
+  // CHECK-NEXT: store i64 %[[ALIGNMENT]], i64* %[[ALIGNMENT_ADDR]], align 8
+  // CHECK-SANITIZE-NEXT:store i8* bitcast ({ [151 x i8]*, i32, i32 }* @0 to i8*), i8** %return.sloc.ptr, align 8
+  // CHECK-NEXT: %[[X_RELOADED:.*]] = load i8**, i8*** %[[X_ADDR]], align 8
+  // CHECK-SANITIZE-NEXT:%ptrint = ptrtoint i8** %0 to i64
+  // CHECK-SANITIZE-NEXT:%1 = sub i64 %alignment, 1
+  // CHECK-SANITIZE-NEXT:%maskedptr = and i64 %ptrint, %1
+  // CHECK-SANITIZE-NEXT:%maskcond = icmp eq i64 %maskedptr, 0
+  // CHECK-SANITIZE-NEXT:%2 = ptrtoint i8** %0 to i64, !nosanitize !2
+  // CHECK-SANITIZE-ANYRECOVER-NEXT: br i1 %maskcond, label %cont, label %handler.alignment_assumption, !prof !3, !nosanitize !2
+  // CHECK-SANITIZE-TRAP-NEXT:   br i1 %maskcond, label %cont, label %trap, !nosanitize !2
+
+  // CHECK-SANITIZE-ANYRECOVER:handler.alignment_assumption:
+  // CHECK-SANITIZE-NORECOVER-NEXT:  call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ { [151 x i8]*, i32, i32 }, { [151 x i8]*, i32, i32 }, { i16, i16, [10 x i8] }* }* @2 to i8*), i64 %2, i64 %alignment, i64 0) #3, !nosanitize !2
+  // CHECK-SANITIZE-NORECOVER-NEXT:  unreachable, !nosanitize !2
+  // CHECK-SANITIZE-RECOVER-NEXT:call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ { [151 x i8]*, i32, i32 }, { [151 x i8]*, i32, i32 }, { i16, i16, [10 x i8] }* }* @2 to i8*), i64 %2, i64 %alignment, i64 0) #3, !nosanitize !2
+  // CHECK-SANITIZE-RECOVER-NEXT:br label %cont, !nosanitize !2
+
+  // CHECK-SANITIZE-TRAP:  trap:
+  // CHECK-SANITIZE-TRAP-NEXT:   call void @llvm.ubsantrap(i8 23) #3, !nosanitize !2
+  // CHECK-SANITIZE-TRAP-NEXT:   unreachable, !nosanitize !2
+
+  // CHECK-SANITIZE:   cont:
+  // CHECK-SANITIZE-NEXT:call void @llvm.assume(i1 true) [ "align"(i8** %[[X_RELOADED]], i64 %[[ALIGNMENT]]) ]
+  // CHECK-NEXT: ret i8** %[[X_RELOADED]]
+  // CHECK-NEXT:   }
   return x;
 }
 
Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
@@ -8,15 +8,37 @@
 
 char **__attribute__((alloc_align(2)))
 passthrough(char **x, unsigned long alignment) {
-  // CHECK:  define{{.*}} i8** @[[PASSTHROUGH:.*]](i8** noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
-  // CHECK-NEXT: entry:
-  // CHECK-NEXT:   %[[X_ADDR:.*]] = alloca i8**, align 8
-  // CHECK-NEXT:   %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
-  // CHECK-NEXT:   store i8** 

[clang] a717e9d - [AttrDocs] try to fix build

2022-03-14 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-14T22:19:55+01:00
New Revision: a717e9d47e64682bf45e6a998d11d76f47454f12

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

LOG: [AttrDocs] try to fix build

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index ee5be4c0bc412..d7cd31174bc5b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6260,7 +6260,11 @@ attribute associated with it (the attribute applies to 
the declaration, not the
 statement in that case). So this use case will not work:
 
 .. code-block:: c
-  [[clang::always_inline]] int i = bar();
+
+  int example(void) {
+[[clang::always_inline]] int i = bar();
+return i;
+  }
 
 This attribute does not guarantee that inline substitution actually occurs.
 



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


[PATCH] D121532: [Clang][WIP] Fix Unevaluated Lambdas

2022-03-14 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

Can you add a test to `ASTImpoterTest.cpp` that checks that we import the 
`LambdaDependencyKind` correctly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121532

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


[PATCH] D120717: [Clang] always_inline statement attribute

2022-03-14 Thread Dávid Bolvanský 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 rG003c0b9307bc: [Clang] always_inline statement  attribute 
(authored by xbolva00).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120717

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/CodeGen/attr-alwaysinline.cpp
  clang/test/Parser/objc-implementation-attrs.m
  clang/test/Sema/attr-alwaysinline.cpp

Index: clang/test/Sema/attr-alwaysinline.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-alwaysinline.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+int bar();
+
+[[gnu::always_inline]] void always_inline_fn(void) {}
+[[gnu::flatten]] void flatten_fn(void) {}
+
+[[gnu::noinline]] void noinline_fn(void) {}
+
+void foo() {
+  [[clang::always_inline]] bar();
+  [[clang::always_inline(0)]] bar(); // expected-error {{'always_inline' attribute takes no arguments}}
+  int x;
+  [[clang::always_inline]] int i = bar();  // expected-warning {{'always_inline' attribute only applies to functions and statements}}
+  [[clang::always_inline]] x = 0;  // expected-warning {{'always_inline' attribute is ignored because there exists no call expression inside the statement}}
+  [[clang::always_inline]] { asm("nop"); } // expected-warning {{'always_inline' attribute is ignored because there exists no call expression inside the statement}}
+  [[clang::always_inline]] label : x = 1;  // expected-warning {{'always_inline' attribute only applies to functions and statements}}
+
+  [[clang::always_inline]] always_inline_fn();
+  [[clang::always_inline]] noinline_fn(); // expected-warning {{statement attribute 'always_inline' has higher precedence than function attribute 'noinline'}}
+  [[clang::always_inline]] flatten_fn();  // expected-warning {{statement attribute 'always_inline' has higher precedence than function attribute 'flatten'}}
+
+  [[gnu::always_inline]] bar(); // expected-warning {{attribute is ignored on this statement as it only applies to functions; use '[[clang::always_inline]]' on statements}}
+  __attribute__((always_inline)) bar(); // expected-warning {{attribute is ignored on this statement as it only applies to functions; use '[[clang::always_inline]]' on statements}}
+}
+
+[[clang::always_inline]] static int i = bar(); // expected-warning {{'always_inline' attribute only applies to functions and statements}}
Index: clang/test/Parser/objc-implementation-attrs.m
===
--- clang/test/Parser/objc-implementation-attrs.m
+++ clang/test/Parser/objc-implementation-attrs.m
@@ -2,15 +2,15 @@
 
 @interface I1 @end
 
-// expected-warning@+1 {{'always_inline' attribute only applies to functions}}
+// expected-warning@+1 {{'always_inline' attribute only applies to functions and statements}}
 __attribute__((always_inline))
 @implementation I1 @end
 
-// expected-warning@+1 {{'always_inline' attribute only applies to functions}}
+// expected-warning@+1 {{'always_inline' attribute only applies to functions and statements}}
 __attribute__((always_inline))
 @implementation I1 (MyCat) @end
 
-// expected-warning@+1 {{'always_inline' attribute only applies to functions}}
+// expected-warning@+1 {{'always_inline' attribute only applies to functions and statements}}
 __attribute__((always_inline))
 // expected-warning@+1 {{cannot find interface declaration for 'I2'}}
 @implementation I2 @end
Index: clang/test/CodeGen/attr-alwaysinline.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-alwaysinline.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -S -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
+
+bool bar();
+void f(bool, bool);
+void g(bool);
+
+void foo(int i) {
+  [[clang::always_inline]] bar();
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[ALWAYSINLINEATTR:[0-9]+]]
+  [[clang::always_inline]] (i = 4, bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[ALWAYSINLINEATTR]]
+  [[clang::always_inline]] (void)(bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[ALWAYSINLINEATTR]]
+  [[clang::always_inline]] f(bar(), bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[ALWAYSINLINEATTR]]
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[ALWAYSINLINEATTR]]
+// CHECK: call void @_Z1fbb({{.*}}) #[[ALWAYSINLINEATTR]]
+  [[clang::always_inline]] for (bar(); bar(); bar()) {}
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[ALWAYSINLINEATTR]]
+// CHECK: call 

[clang] 003c0b9 - [Clang] always_inline statement attribute

2022-03-14 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-14T21:45:31+01:00
New Revision: 003c0b9307bc52605fc93c599dfe36849839ded5

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

LOG: [Clang] always_inline statement  attribute

Motivation:

```
int test(int x, int y) {
int r = 0;
[[clang::always_inline]] r += foo(x, y); // force compiler to inline this 
function here
return r;
}
```

In 2018, @kuhar proposed "Introduce per-callsite inline intrinsics" in 
https://reviews.llvm.org/D51200 to solve this motivation case (and many others).

This patch solves this problem with call site attribute. "noinline" statement 
attribute already landed in D119061. Also, some LLVM Inliner fixes landed so 
call site attribute is stronger than function attribute.

Reviewed By: aaron.ballman

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

Added: 
clang/test/CodeGen/attr-alwaysinline.cpp
clang/test/Sema/attr-alwaysinline.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/Parser/objc-implementation-attrs.m

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index cd2e2ca8bbf5a..e28044646080e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -706,9 +706,13 @@ def AlignNatural : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
-def AlwaysInline : InheritableAttr {
-  let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">];
-  let Subjects = SubjectList<[Function]>;
+def AlwaysInline : DeclOrStmtAttr {
+  let Spellings = [GCC<"always_inline">, CXX11<"clang", "always_inline">,
+   C2x<"clang", "always_inline">, Keyword<"__forceinline">];
+  let Accessors = [Accessor<"isClangAlwaysInline", [CXX11<"clang", 
"always_inline">,
+C2x<"clang", 
"always_inline">]>];
+  let Subjects = SubjectList<[Function, Stmt], WarnDiag,
+ "functions and statements">;
   let Documentation = [AlwaysInlineDocs];
 }
 

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 5f50b49ee2373..ee5be4c0bc412 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6241,7 +6241,28 @@ def AlwaysInlineDocs : Documentation {
 Inlining heuristics are disabled and inlining is always attempted regardless of
 optimization level.
 
-Does not guarantee that inline substitution actually occurs.
+``[[clang::always_inline]]`` spelling can be used as a statement attribute; 
other
+spellings of the attribute are not supported on statements. If a statement is
+marked ``[[clang::always_inline]]`` and contains calls, the compiler attempts
+to inline those calls.
+
+.. code-block:: c
+
+  int example(void) {
+int i;
+[[clang::always_inline]] foo(); // attempts to inline foo
+[[clang::always_inline]] i = bar(); // attempts to inline bar
+[[clang::always_inline]] return f(42, baz(bar())); // attempts to inline 
everything
+  }
+
+A declaration statement, which is a statement, is not a statement that can 
have an
+attribute associated with it (the attribute applies to the declaration, not the
+statement in that case). So this use case will not work:
+
+.. code-block:: c
+  [[clang::always_inline]] int i = bar();
+
+This attribute does not guarantee that inline substitution actually occurs.
 
 Note: applying this attribute to a coroutine at the `-O0` optimization 
level
 has no effect; other optimization levels may only partially inline and result 
in a

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index db4adbbb6e1e6..e17b018937fb4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4052,7 +4052,7 @@ def warn_attribute_nonnull_parm_no_args : Warning<
   InGroup;
 def warn_function_stmt_attribute_precedence : Warning<
   "statement attribute %0 has higher precedence than function attribute "
-  "'%select{always_inline|flatten}1'">,
+  "'%select{always_inline|flatten|noinline}1'">,
   InGroup;
 def note_declared_nonnull : Note<
   "declared %select{'returns_nonnull'|'nonnull'}0 here">;

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index ab84d133de84e..8331d1ba215e9 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5248,6 +5248,11 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
,
   if 

[PATCH] D121637: [PowerPC] Fix EmitPPCBuiltinExpr to emit arguments once

2022-03-14 Thread Quinn Pham via Phabricator via cfe-commits
quinnp created this revision.
Herald added subscribers: shchenz, kbarton, nemanjai.
Herald added a project: All.
quinnp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch refactors `EmitPPCBuiltinExpr` in `CGBuiltin.cpp` to remove
the loop at the begining of the function that emits the arguments and
to delay emitting the arguments until inside the switch statement. This
refactor will put `EmitPPCBuiltinExpr` in line with the strategy of the
target independent function `EmitBuiltinExpr`. Also, this refactor
ensures that arguments are only emitted once.

Tests that included builtins affected by the refactor have been modified
to match expected behaviour.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121637

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/PowerPC/builtins-ppc-fastmath.c
  clang/test/CodeGen/PowerPC/builtins-ppc-int128.c
  clang/test/CodeGen/PowerPC/builtins-ppc-vsx.c
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-cas.c
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-fetch.c
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-fp.c
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-sync.c

Index: clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-sync.c
===
--- clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-sync.c
+++ clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-sync.c
@@ -14,13 +14,11 @@
 
 // CHECK-LABEL: @test_popcntb(
 // CHECK:[[TMP0:%.*]] = load i64, i64* @a, align 8
-// CHECK-NEXT:[[TMP1:%.*]] = load i64, i64* @a, align 8
 // CHECK-NEXT:[[POPCNTB:%.*]] = call i64 @llvm.ppc.popcntb.i64.i64(i64 [[TMP0]])
 // CHECK-NEXT:ret i64 [[POPCNTB]]
 //
 // CHECK-32-LABEL: @test_popcntb(
 // CHECK-32:[[TMP0:%.*]] = load i32, i32* @a, align 4
-// CHECK-32-NEXT:[[TMP1:%.*]] = load i32, i32* @a, align 4
 // CHECK-32-NEXT:[[POPCNTB:%.*]] = call i32 @llvm.ppc.popcntb.i32.i32(i32 [[TMP0]])
 // CHECK-32-NEXT:ret i32 [[POPCNTB]]
 //
@@ -198,13 +196,11 @@
 
 // CHECK-LABEL: @test_builtin_ppc_popcntb(
 // CHECK:[[TMP0:%.*]] = load i64, i64* @a, align 8
-// CHECK-NEXT:[[TMP1:%.*]] = load i64, i64* @a, align 8
 // CHECK-NEXT:[[POPCNTB:%.*]] = call i64 @llvm.ppc.popcntb.i64.i64(i64 [[TMP0]])
 // CHECK-NEXT:ret i64 [[POPCNTB]]
 //
 // CHECK-32-LABEL: @test_builtin_ppc_popcntb(
 // CHECK-32:[[TMP0:%.*]] = load i32, i32* @a, align 4
-// CHECK-32-NEXT:[[TMP1:%.*]] = load i32, i32* @a, align 4
 // CHECK-32-NEXT:[[POPCNTB:%.*]] = call i32 @llvm.ppc.popcntb.i32.i32(i32 [[TMP0]])
 // CHECK-32-NEXT:ret i32 [[POPCNTB]]
 //
Index: clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
===
--- clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
+++ clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
@@ -15,11 +15,11 @@
   // CHECK-LABEL: test_builtin_ppc_rldimi
   // CHECK:   %res = alloca i64, align 8
   // CHECK-NEXT:  [[RA:%[0-9]+]] = load i64, i64* @ull, align 8
-  // CHECK-NEXT:  [[RB:%[0-9]+]] = load i64, i64* @ull, align 8
-  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i64 @llvm.fshl.i64(i64 [[RA]], i64 [[RA]], i64 63)
-  // CHECK-NEXT:  [[RD:%[0-9]+]] = and i64 [[RC]], 72057593769492480
-  // CHECK-NEXT:  [[RE:%[0-9]+]] = and i64 [[RB]], -72057593769492481
-  // CHECK-NEXT:  [[RF:%[0-9]+]] = or i64 [[RD]], [[RE]]
+  // CHECK-NEXT:  [[RB:%[0-9]+]] = call i64 @llvm.fshl.i64(i64 [[RA]], i64 [[RA]], i64 63)
+  // CHECK-NEXT:  [[RC:%[0-9]+]] = and i64 [[RB]], 72057593769492480
+  // CHECK-NEXT:  [[RD:%[0-9]+]] = load i64, i64* @ull, align 8
+  // CHECK-NEXT:  [[RE:%[0-9]+]] = and i64 [[RD]], -72057593769492481
+  // CHECK-NEXT:  [[RF:%[0-9]+]] = or i64 [[RC]], [[RE]]
   // CHECK-NEXT:  store i64 [[RF]], i64* %res, align 8
   // CHECK-NEXT:  ret void
 
@@ -31,11 +31,11 @@
   // CHECK-LABEL: test_builtin_ppc_rlwimi
   // CHECK:   %res = alloca i32, align 4
   // CHECK-NEXT:  [[RA:%[0-9]+]] = load i32, i32* @ui, align 4
-  // CHECK-NEXT:  [[RB:%[0-9]+]] = load i32, i32* @ui, align 4
-  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i32 @llvm.fshl.i32(i32 [[RA]], i32 [[RA]], i32 31)
-  // CHECK-NEXT:  [[RD:%[0-9]+]] = and i32 [[RC]], 16776960
-  // CHECK-NEXT:  [[RE:%[0-9]+]] = and i32 [[RB]], -16776961
-  // CHECK-NEXT:  [[RF:%[0-9]+]] = or i32 [[RD]], [[RE]]
+  // CHECK-NEXT:  [[RB:%[0-9]+]] = call i32 @llvm.fshl.i32(i32 [[RA]], i32 [[RA]], i32 31)
+  // CHECK-NEXT:  [[RC:%[0-9]+]] = and i32 [[RB]], 16776960
+  // CHECK-NEXT:  [[RD:%[0-9]+]] = load i32, i32* @ui, align 4
+  // CHECK-NEXT:  [[RE:%[0-9]+]] = and i32 [[RD]], -16776961
+  // CHECK-NEXT:  [[RF:%[0-9]+]] = or i32 [[RC]], [[RE]]
   // CHECK-NEXT:  store i32 [[RF]], i32* %res, align 4
   // CHECK-NEXT:  ret void
 
Index: clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-fp.c

[PATCH] D119477: Ignore FullExpr when traversing cast sub-expressions

2022-03-14 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

@aaron.ballman Friendly Monday ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119477

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


[PATCH] D119476: Generalize and harmonize sub-expression traversal

2022-03-14 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

@aaron.ballman Friendly Monday ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119476

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


[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-14 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 415199.
egorzhdan added a comment.

- Only allow one attribute syntax style per directive
- Adjust documentation
- Add a release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/AttrSubjectMatchRules.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/test/AST/pragma-multiple-attributes-declspec.cpp
  clang/test/AST/pragma-multiple-attributes.cpp
  clang/test/FixIt/fixit-pragma-attribute.c
  clang/test/FixIt/fixit-pragma-attribute.cpp
  clang/test/Parser/pragma-attribute-declspec.cpp
  clang/test/Parser/pragma-attribute.cpp
  clang/test/Parser/pragma-multiple-attributes.cpp

Index: clang/test/Parser/pragma-multiple-attributes.cpp
===
--- /dev/null
+++ clang/test/Parser/pragma-multiple-attributes.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -Wno-pragma-clang-attribute -verify %s
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls, annotate("test"))), apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls,)), apply_to = function) // expected-error {{expected identifier that represents an attribute name}}
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{expected ','}}
Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -154,9 +154,6 @@
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=any(function))
 #pragma clang attribute pop
 
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=namespace)
 #pragma clang attribute pop
 
Index: clang/test/Parser/pragma-attribute-declspec.cpp
===
--- clang/test/Parser/pragma-attribute-declspec.cpp
+++ clang/test/Parser/pragma-attribute-declspec.cpp
@@ -6,7 +6,8 @@
 
 #pragma clang attribute pop
 
-#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
+#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function)
+#pragma clang attribute pop
 
 #pragma clang attribute push(__declspec(align), apply_to = variable) // expected-error {{attribute 'align' is not supported by '#pragma clang attribute'}}
 
Index: clang/test/FixIt/fixit-pragma-attribute.cpp
===
--- clang/test/FixIt/fixit-pragma-attribute.cpp
+++ clang/test/FixIt/fixit-pragma-attribute.cpp
@@ -39,7 +39,7 @@
 #pragma clang attribute pop
 
 #pragma clang attribute push (__attribute__((abi_tag("a"
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) apply_to=function)
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", "
 #pragma clang attribute push (__attribute__((abi_tag("a"))) = function)
@@ -48,35 +48,35 @@
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = "
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))) 22)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) function)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) (function))
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:71}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: 

[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-14 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

In D121283#3379225 , @aaron.ballman 
wrote:

> As a thought experiment, would it make sense to lift the restriction on the 
> number of attributes allowed in a pragma, but not allow multiple attribute 
> specifiers?

I think this is reasonable, and as you've mentioned, it also leaves the 
opportunity to extend this syntax later should the need arise.
I will adjust this patch shortly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

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


[PATCH] D121602: [clang][dataflow] Model the behavior of non-standard optional constructors

2022-03-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added inline comments.



Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:264
+  +[](const CXXMemberCallExpr *E, LatticeTransferState ) {
+assignOptionalValue(*E->getImplicitObjectArgument(), State,
+State.Env.getBoolLiteralValue(true));

sgatev wrote:
> ymandel wrote:
> > I realize this is consistent with the previous version, but just noticed 
> > this issue. By using `assignOptionalValue` for `emplace` (and `reset`), 
> > does that break the following case?
> > 
> > ```
> > optional opt;
> > if (p) opt.emplace(3);
> > someCode();
> > if (p) use(*opt);
> > ```
> This isn't supported yet. Still, I don't think `assignOptionalValue` breaks 
> it because this seems more related to the way information from different 
> branches is joined than the way values are initialized. I'll add this case 
> (and others) in a following patch that adds support for joining.
Sounds good. I think we can discuss further in the next patch as needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121602

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


[PATCH] D121245: [clang][parser] Allow GNU attributes before namespace identifier

2022-03-14 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! Might be worth adding a release note for it (does this close any bugs in 
the bug database? If so, it'd be worth mentioning those in the commit message 
and release note).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121245

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


[PATCH] D121532: [Clang][WIP] Fix Unevaluated Lambdas

2022-03-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 415187.
cor3ntin added a comment.

Remove prior attempt at fixing this bug (good catch Aaron!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121532

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp

Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -30,6 +30,27 @@
 auto e = g(0); // expected-error{{no matching function for call}}
 // expected-note@-2 {{substitution failure}}
 
+template 
+auto foo(decltype([] {
+  return [] { return T(); }();
+})) {}
+
+void test() {
+  foo({});
+}
+
+template 
+struct C {
+  template 
+  auto foo(decltype([] {
+return [] { return T(); }();
+  })) {}
+};
+
+void test2() {
+  C{}.foo({});
+}
+
 namespace PR52073 {
 // OK, these are distinct functions not redefinitions.
 template void f(decltype([]{})) {} // expected-note {{candidate}}
@@ -40,6 +61,62 @@
 template void g(const char (*)[([]{ return N; })()]) {} // expected-note {{candidate}}
 template void g(const char (*)[([]{ return N; })()]) {} // expected-note {{candidate}}
 // FIXME: We instantiate the lambdas into the context of the function template,
-// so we think they're dependent and can't evaluate a call to them.
+//  so we think they're dependent and can't evaluate a call to them.
 void use_g() { g<6>(&"hello"); } // expected-error {{no matching function}}
 }
+
+namespace GH51416 {
+
+template 
+struct A {
+  void spam(decltype([] {}));
+};
+
+template 
+void A::spam(decltype([] {})) // expected-error{{out-of-line definition of 'spam' does not match}}
+{}
+
+struct B {
+  template 
+  void spam(decltype([] {}));
+};
+
+template 
+void B::spam(decltype([] {})) {} // expected-error{{out-of-line definition of 'spam' does not match}}
+
+} // namespace GH51416
+
+namespace GH50376 {
+
+template 
+struct foo_t {// expected-note 2{{candidate constructor}}
+  foo_t(T ptr) {} // expected-note{{candidate constructor}}
+};
+
+template 
+using alias = foo_t;
+
+template 
+auto fun(T const ) -> alias {
+  return alias{t}; // expected-error{{no viable conversion from returned value of type 'alias<...>'}}
+}
+
+void f() {
+  int i;
+  auto const error = fun(i); // expected-note{{in instantiation}}
+}
+
+} // namespace GH50376
+
+namespace GH51414 {
+template  void spam(decltype([] {}) (*s)[sizeof(T)] = nullptr) {}
+void foo() {
+  spam();
+}
+} // namespace GH51414
+
+namespace GH51641 {
+template 
+void foo(decltype(+[](T) {}) lambda, T param);
+static_assert(!__is_same(decltype(foo), void));
+} // namespace GH51641
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -5727,7 +5727,7 @@
   // Add lambda-specific data.
   if (Data.IsLambda) {
 auto  = D->getLambdaData();
-Record->push_back(Lambda.Dependent);
+Record->push_back(Lambda.DependencyKind);
 Record->push_back(Lambda.IsGenericLambda);
 Record->push_back(Lambda.CaptureDefault);
 Record->push_back(Lambda.NumCaptures);
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1801,7 +1801,7 @@
 using Capture = LambdaCapture;
 
 auto  = static_cast(Data);
-Lambda.Dependent = Record.readInt();
+Lambda.DependencyKind = Record.readInt();
 Lambda.IsGenericLambda = Record.readInt();
 Lambda.CaptureDefault = Record.readInt();
 Lambda.NumCaptures = Record.readInt();
@@ -1917,8 +1917,8 @@
   // allocate the appropriate DefinitionData structure.
   bool IsLambda = Record.readInt();
   if (IsLambda)
-DD = new (C) CXXRecordDecl::LambdaDefinitionData(D, nullptr, false, false,
- LCD_None);
+DD = new (C) CXXRecordDecl::LambdaDefinitionData(
+D, nullptr, CXXRecordDecl::LDKUnknown, false, LCD_None);
   else
 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
 
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -12927,14 +12927,24 @@
 NewTrailingRequiresClause = getDerived().TransformExpr(TRC);
 
   // Create the local class that will describe the lambda.
-  // FIXME: KnownDependent below is 

[PATCH] D110641: Implement P0857R0 -Part B: requires clause for template-template params

2022-03-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/SemaTemplate/concepts.cpp:63
   template concept C = true;
-  template requires C typename U> struct X {}; // 
expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};

erichkeane wrote:
> Seemingly if "X" contains U, the constraint should be checked (according 
> to EWG).
> 
> Based on reflector conversations, it seems this should ALSO be checked in:
> 
> http://eel.is/c++draft/temp.arg.template#3
> and 
> http://eel.is/c++draft/temp.arg.template#4
> , particularly the 'rewrite to function templates in /4 should produce a 
> constrained function template, and the 'at least as specialized' check takes 
> these into consideration.
> 
> They are ALSO considered in partial ordering.
That example(X has a U in it) asserts against `main` since it causes us to 
not properly instantiate the constraints.  On top of my 'deferred constraints 
instantiation' patch (https://reviews.llvm.org/D119544 ) it fails to diagnose 
(consistent with GCC, but not EDG).


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

https://reviews.llvm.org/D110641

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


[PATCH] D110641: Implement P0857R0 -Part B: requires clause for template-template params

2022-03-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Comment based on @rsmith and EWG reflector feedback as to where this should be 
checked.




Comment at: clang/test/SemaTemplate/concepts.cpp:63
   template concept C = true;
-  template requires C typename U> struct X {}; // 
expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};

Seemingly if "X" contains U, the constraint should be checked (according 
to EWG).

Based on reflector conversations, it seems this should ALSO be checked in:

http://eel.is/c++draft/temp.arg.template#3
and 
http://eel.is/c++draft/temp.arg.template#4
, particularly the 'rewrite to function templates in /4 should produce a 
constrained function template, and the 'at least as specialized' check takes 
these into consideration.

They are ALSO considered in partial ordering.


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

https://reviews.llvm.org/D110641

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


[PATCH] D121602: [clang][dataflow] Model the behavior of non-standard optional constructors

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



Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:118
+/// function will be 2.
+int countOptionalWrappers(const ASTContext , QualType Type) {
+  if (!IsOptionalType(Type))

Nit: some of these functions are static and some not. Should we have one big 
anonymous namespace instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121602

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


[PATCH] D121602: [clang][dataflow] Model the behavior of non-standard optional constructors

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



Comment at: clang/include/clang/Analysis/FlowSensitive/MatchSwitch.h:146
+  std::vector>
+  Actions;

Nit: looks like we need to repeat the action type. Should we restore the using 
above?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121602

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


[PATCH] D121602: [clang][dataflow] Model the behavior of non-standard optional constructors

2022-03-14 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev marked 2 inline comments as done.
sgatev added inline comments.



Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:264
+  +[](const CXXMemberCallExpr *E, LatticeTransferState ) {
+assignOptionalValue(*E->getImplicitObjectArgument(), State,
+State.Env.getBoolLiteralValue(true));

ymandel wrote:
> I realize this is consistent with the previous version, but just noticed this 
> issue. By using `assignOptionalValue` for `emplace` (and `reset`), does that 
> break the following case?
> 
> ```
> optional opt;
> if (p) opt.emplace(3);
> someCode();
> if (p) use(*opt);
> ```
This isn't supported yet. Still, I don't think `assignOptionalValue` breaks it 
because this seems more related to the way information from different branches 
is joined than the way values are initialized. I'll add this case (and others) 
in a following patch that adds support for joining.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121602

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


[PATCH] D120296: [Attr] Fix a btf_type_tag AST generation bug

2022-03-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/TypeLoc.h:923
+  void initializeLocal(ASTContext , SourceLocation loc) {}
+
+  QualType getInnerType() const { return getTypePtr()->getWrappedType(); }

yonghong-song wrote:
> aaron.ballman wrote:
> > Do we also need something like this? 
> > https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/TypeLoc.h#L1187
> I didn't see getLocalDataSize() in AttributedTypeLoc so it is not needed for 
> AttributedTypeLoc. BTFTagAttributedTypeLoc usage is very similar to 
> AttributedTypeLoc, so I think we are fine here.
The main difference is that `AttributedLocInfo` has a member and 
`BTFTagAttributedLocInfo` is empty. This is why I think it's closer to an 
`AdjustedLocInfo` object which also is an empty struct.



Comment at: clang/test/Sema/attr-btf_type_tag.c:29
+int g1 = _Generic((int *)0, int __tag1 *: 0);
+int g2 = _Generic((int __tag1 *)0, int *: 0);
+

I'd like a third test case:
```
int g3 = _Generic(0, int __tag1 * : 0, int * : 0, default : 0); // 
expected-error {{something about duplicate compatible associations}}
```



Comment at: clang/test/Sema/attr-btf_type_tag.c:31-37
+// The btf_type_tag attribute will be ignored during overloadable type matching
+void __attribute__((overloadable)) bar1(int __tag1 *a);
+void __attribute__((overloadable)) bar2(int *a);
+void foo2(int *a, int __tag1 *b) {
+  bar1(a);
+  bar2(b);
+}

yonghong-song wrote:
> aaron.ballman wrote:
> > This test looks confused -- those functions have different names, so 
> > they're not overloading one another. Even if they were named with the same 
> > identifier, it wouldn't be sufficient to test which gets called (you can 
> > redeclare overloads as in https://godbolt.org/z/aebMbY1aM).
> > 
> > I think this case needs a codegen test to see which function is actually 
> > dispatched to.
> sorry for confusion. the test is bad. For the example in the above 
> godbolt.org link, we have
> ```
> __attribute__((overloadable)) void func(int a);
> __attribute__((overloadable)) void func(int a);
> ```
> Such multiple declarations are actually okay since we allow duplicated 
> declarations. As you mentioned, we really want to know which function 
> definition it picks with overloadable attribute.
> I tried a few examples:
> ```
> $ cat test.c
> #if 1
> #define __attr __attribute__((btf_type_tag("tag1")))
> #else
> #define __attr __attribute__((noderef))
> #endif
> 
> void bar1(int __attr *);
> void bar2(int *);
> void isdigit1(int __attr *a) __attribute__((overloadable)) {
>   bar1(a);
> }
> void isdigit1(int *a) __attribute__((overloadable)) {
>   bar2(a);
> }
> 
> void foo(int __attr *a, int *b) {
>   isdigit1(a);
>   isdigit1(b);
> }
> 
> $ clang -g -std=c2x test.c -S -O2 -emit-llvm -DUSE_TAG
> test.c:12:6: error: redefinition of 'isdigit1'
> void isdigit1(int *a) __attribute__((overloadable)) {
>  ^
> test.c:9:6: note: previous definition is here
> void isdigit1(int __attr *a) __attribute__((overloadable)) {
>  ^
> 1 error generated.
> $ clang -g -std=c2x test.c -S -O2 -emit-llvm
> test.c:12:6: error: redefinition of 'isdigit1'
> void isdigit1(int *a) __attribute__((overloadable)) {
>  ^
> test.c:9:6: note: previous definition is here
> void isdigit1(int __attr *a) __attribute__((overloadable)) {
>  ^
> 1 error generated.
> $
> ```
> 
> so just attribute itself cannot differentiate overloadable functions. In the 
> above test.c, if I changed one of isdigle1 and corresponding bar?() function 
> from 'int' to 'float', compilation can succeed.
> 
> So I will add overloadable failure and success case in Sema/ directory. I am 
> not sure whether a codegen case is needed for the case like
> ```
> void bar1(float __attr *);
> void bar2(int *);
> void isdigit1(float __attr *a) __attribute__((overloadable)) {
>   bar1(a);
> }
> void isdigit1(int *a) __attribute__((overloadable)) {
>   bar2(a);
> }
> ```
> or not. But if you think it is necessary, I am happy to add it.
Okay, I am fine with that behavior. CodeGen tests are only necessary if the 
overloads can actually be defined -- since they can't, I think the Sema tests 
are sufficient to show that these are redeclarations and not independent 
overloads.


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

https://reviews.llvm.org/D120296

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


[PATCH] D121602: [clang][dataflow] Model the behavior of non-standard optional constructors

2022-03-14 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 415178.
sgatev marked 2 inline comments as done.
sgatev added a comment.

Add a FIXME.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121602

Files:
  clang/include/clang/Analysis/FlowSensitive/MatchSwitch.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -31,8 +31,8 @@
 
 // FIXME: Move header definitions in separate file(s).
 static constexpr char StdTypeTraitsHeader[] = R"(
-#ifndef TYPE_TRAITS_H
-#define TYPE_TRAITS_H
+#ifndef STD_TYPE_TRAITS_H
+#define STD_TYPE_TRAITS_H
 
 namespace std {
 
@@ -127,6 +127,9 @@
   typedef T type;
 };
 
+template 
+using remove_cv_t = typename remove_cv::type;
+
 template 
 struct decay {
  private:
@@ -139,9 +142,196 @@
typename remove_cv::type>::type>::type type;
 };
 
+template 
+struct enable_if {};
+
+template 
+struct enable_if {
+  typedef T type;
+};
+
+template 
+using enable_if_t = typename enable_if::type;
+
+template 
+struct is_same : false_type {};
+
+template 
+struct is_same : true_type {};
+
+template 
+struct is_void : is_same::type> {};
+
+namespace detail {
+
+template 
+auto try_add_rvalue_reference(int) -> type_identity;
+template 
+auto try_add_rvalue_reference(...) -> type_identity;
+
+}  // namespace detail
+
+template 
+struct add_rvalue_reference : decltype(detail::try_add_rvalue_reference(0)) {
+};
+
+template 
+typename add_rvalue_reference::type declval() noexcept;
+
+namespace detail {
+
+template 
+auto test_returnable(int)
+-> decltype(void(static_cast(nullptr)), true_type{});
+template 
+auto test_returnable(...) -> false_type;
+
+template 
+auto test_implicitly_convertible(int)
+-> decltype(void(declval()(declval())), true_type{});
+template 
+auto test_implicitly_convertible(...) -> false_type;
+
+}  // namespace detail
+
+template 
+struct is_convertible
+: integral_constant(0))::value &&
+ decltype(detail::test_implicitly_convertible(
+ 0))::value) ||
+(is_void::value && is_void::value)> {};
+
+template 
+inline constexpr bool is_convertible_v = is_convertible::value;
+
+template 
+using void_t = void;
+
+template 
+struct is_constructible_ : false_type {};
+
+template 
+struct is_constructible_()...))>, T, Args...>
+: true_type {};
+
+template 
+using is_constructible = is_constructible_, T, Args...>;
+
+template 
+inline constexpr bool is_constructible_v = is_constructible::value;
+
+template 
+struct __uncvref {
+  typedef typename remove_cv::type>::type type;
+};
+
+template 
+using __uncvref_t = typename __uncvref<_Tp>::type;
+
+template 
+using _BoolConstant = integral_constant;
+
+template 
+using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
+
+template 
+using _IsNotSame = _BoolConstant;
+
+template 
+struct _MetaBase;
+template <>
+struct _MetaBase {
+  template 
+  using _SelectImpl = _Tp;
+  template  class _FirstFn, template  class,
+class... _Args>
+  using _SelectApplyImpl = _FirstFn<_Args...>;
+  template 
+  using _FirstImpl = _First;
+  template 
+  using _SecondImpl = _Second;
+  template 
+  using _OrImpl =
+  typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::
+  template _OrImpl<_First, _Rest...>;
+};
+
+template <>
+struct _MetaBase {
+  template 
+  using _SelectImpl = _Up;
+  template  class, template  class _SecondFn,
+class... _Args>
+  using _SelectApplyImpl = _SecondFn<_Args...>;
+  template 
+  using _OrImpl = _Result;
+};
+
+template 
+using _If = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
+
+template 
+using _Or = typename _MetaBase::template _OrImpl;
+
+template 
+using __enable_if_t = typename enable_if<_Bp, _Tp>::type;
+
+template 
+using __expand_to_true = true_type;
+template 
+__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
+template 
+false_type __and_helper(...);
+template 
+using _And = decltype(__and_helper<_Pred...>(0));
+
+struct __check_tuple_constructor_fail {
+  static constexpr bool __enable_explicit_default() { return false; }
+  static constexpr bool __enable_implicit_default() { return false; }
+  template 
+  static constexpr bool __enable_explicit() {
+return false;
+  }
+  template 
+  static constexpr bool __enable_implicit() {
+return false;
+  }
+};
+
 } // namespace std
 
-#endif // TYPE_TRAITS_H
+#endif // 

[PATCH] D114382: [clang] Fix wrong -Wunused-local-typedef warning within a template function

2022-03-14 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: clang/test/SemaCXX/warn-unused-local-typedef.cpp:246
+  typedef int Int; // no-diag
+  typedef char Char; // expected-warning {{unused typedef 'Char'}}
+  Int m;

krisb wrote:
> Quuxplusone wrote:
> > I haven't tried to understand the main point of this PR, but FWIW, have you 
> > seen https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61596 ? This looks 
> > suspiciously like that exact case. (I just filed its dup 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104792 the other day.)
> This patch prevents clang from warning on used typedefs (`Int` case), if 
> those typedefs are defined within a local class of a templated function or a 
> member function of a templated class.
> For `Char` case, which is unused in this example, the patch changes nothing.
> 
> Regarding https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104792, those typedefs 
> seem well known, so could we just make clang skipping any checks for those 
> particular names?
> Alternatively, we would likely need to stop warning on any typedefs defined 
> within a function-local class (but those warnings may still be useful like in 
> the test from this patch).
@Quuxplusone if you do not have objections for this patch, I'd land it now. 
It'll make things a bit better and do not prevent us from relaxing conditions 
for the warning further.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


[PATCH] D121602: [clang][dataflow] Model the behavior of non-standard optional constructors

2022-03-14 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 415177.
sgatev marked 2 inline comments as done.
sgatev added a comment.

Address reviewers' comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121602

Files:
  clang/include/clang/Analysis/FlowSensitive/MatchSwitch.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -31,8 +31,8 @@
 
 // FIXME: Move header definitions in separate file(s).
 static constexpr char StdTypeTraitsHeader[] = R"(
-#ifndef TYPE_TRAITS_H
-#define TYPE_TRAITS_H
+#ifndef STD_TYPE_TRAITS_H
+#define STD_TYPE_TRAITS_H
 
 namespace std {
 
@@ -127,6 +127,9 @@
   typedef T type;
 };
 
+template 
+using remove_cv_t = typename remove_cv::type;
+
 template 
 struct decay {
  private:
@@ -139,9 +142,196 @@
typename remove_cv::type>::type>::type type;
 };
 
+template 
+struct enable_if {};
+
+template 
+struct enable_if {
+  typedef T type;
+};
+
+template 
+using enable_if_t = typename enable_if::type;
+
+template 
+struct is_same : false_type {};
+
+template 
+struct is_same : true_type {};
+
+template 
+struct is_void : is_same::type> {};
+
+namespace detail {
+
+template 
+auto try_add_rvalue_reference(int) -> type_identity;
+template 
+auto try_add_rvalue_reference(...) -> type_identity;
+
+}  // namespace detail
+
+template 
+struct add_rvalue_reference : decltype(detail::try_add_rvalue_reference(0)) {
+};
+
+template 
+typename add_rvalue_reference::type declval() noexcept;
+
+namespace detail {
+
+template 
+auto test_returnable(int)
+-> decltype(void(static_cast(nullptr)), true_type{});
+template 
+auto test_returnable(...) -> false_type;
+
+template 
+auto test_implicitly_convertible(int)
+-> decltype(void(declval()(declval())), true_type{});
+template 
+auto test_implicitly_convertible(...) -> false_type;
+
+}  // namespace detail
+
+template 
+struct is_convertible
+: integral_constant(0))::value &&
+ decltype(detail::test_implicitly_convertible(
+ 0))::value) ||
+(is_void::value && is_void::value)> {};
+
+template 
+inline constexpr bool is_convertible_v = is_convertible::value;
+
+template 
+using void_t = void;
+
+template 
+struct is_constructible_ : false_type {};
+
+template 
+struct is_constructible_()...))>, T, Args...>
+: true_type {};
+
+template 
+using is_constructible = is_constructible_, T, Args...>;
+
+template 
+inline constexpr bool is_constructible_v = is_constructible::value;
+
+template 
+struct __uncvref {
+  typedef typename remove_cv::type>::type type;
+};
+
+template 
+using __uncvref_t = typename __uncvref<_Tp>::type;
+
+template 
+using _BoolConstant = integral_constant;
+
+template 
+using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
+
+template 
+using _IsNotSame = _BoolConstant;
+
+template 
+struct _MetaBase;
+template <>
+struct _MetaBase {
+  template 
+  using _SelectImpl = _Tp;
+  template  class _FirstFn, template  class,
+class... _Args>
+  using _SelectApplyImpl = _FirstFn<_Args...>;
+  template 
+  using _FirstImpl = _First;
+  template 
+  using _SecondImpl = _Second;
+  template 
+  using _OrImpl =
+  typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::
+  template _OrImpl<_First, _Rest...>;
+};
+
+template <>
+struct _MetaBase {
+  template 
+  using _SelectImpl = _Up;
+  template  class, template  class _SecondFn,
+class... _Args>
+  using _SelectApplyImpl = _SecondFn<_Args...>;
+  template 
+  using _OrImpl = _Result;
+};
+
+template 
+using _If = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
+
+template 
+using _Or = typename _MetaBase::template _OrImpl;
+
+template 
+using __enable_if_t = typename enable_if<_Bp, _Tp>::type;
+
+template 
+using __expand_to_true = true_type;
+template 
+__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
+template 
+false_type __and_helper(...);
+template 
+using _And = decltype(__and_helper<_Pred...>(0));
+
+struct __check_tuple_constructor_fail {
+  static constexpr bool __enable_explicit_default() { return false; }
+  static constexpr bool __enable_implicit_default() { return false; }
+  template 
+  static constexpr bool __enable_explicit() {
+return false;
+  }
+  template 
+  static constexpr bool __enable_implicit() {
+return false;
+  }
+};
+
 } // namespace std
 
-#endif // 

[PATCH] D121512: [Support] Change zlib::compress to return void

2022-03-14 Thread Fangrui Song 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 rG407c721ceb93: [Support] Change zlib::compress to return void 
(authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121512

Files:
  clang-tools-extra/clangd/index/Serialization.cpp
  clang/lib/Serialization/ASTWriter.cpp
  llvm/include/llvm/ProfileData/SampleProf.h
  llvm/include/llvm/Support/Compression.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  llvm/lib/ObjCopy/ELF/ELFObject.h
  llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/SampleProf.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Support/Compression.cpp
  llvm/unittests/Support/CompressionTest.cpp

Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -27,13 +27,10 @@
   SmallString<32> Compressed;
   SmallString<32> Uncompressed;
 
-  Error E = zlib::compress(Input, Compressed, Level);
-  EXPECT_FALSE(E);
-  consumeError(std::move(E));
+  zlib::compress(Input, Compressed, Level);
 
   // Check that uncompressed buffer is the same as original.
-  E = zlib::uncompress(Compressed, Uncompressed, Input.size());
-  EXPECT_FALSE(E);
+  Error E = zlib::uncompress(Compressed, Uncompressed, Input.size());
   consumeError(std::move(E));
 
   EXPECT_EQ(Input, Uncompressed);
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -46,18 +46,20 @@
 
 bool zlib::isAvailable() { return true; }
 
-Error zlib::compress(StringRef InputBuffer,
- SmallVectorImpl , int Level) {
+void zlib::compress(StringRef InputBuffer,
+SmallVectorImpl , int Level) {
   unsigned long CompressedSize = ::compressBound(InputBuffer.size());
   CompressedBuffer.resize_for_overwrite(CompressedSize);
   int Res =
   ::compress2((Bytef *)CompressedBuffer.data(), ,
   (const Bytef *)InputBuffer.data(), InputBuffer.size(), Level);
+  if (Res == Z_MEM_ERROR)
+report_bad_alloc_error("Allocation failed");
+  assert(Res == Z_OK);
   // Tell MemorySanitizer that zlib output buffer is fully initialized.
   // This avoids a false report when running LLVM with uninstrumented ZLib.
   __msan_unpoison(CompressedBuffer.data(), CompressedSize);
   CompressedBuffer.truncate(CompressedSize);
-  return Res ? createError(convertZlibCodeToString(Res)) : Error::success();
 }
 
 Error zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
@@ -87,8 +89,8 @@
 
 #else
 bool zlib::isAvailable() { return false; }
-Error zlib::compress(StringRef InputBuffer,
- SmallVectorImpl , int Level) {
+void zlib::compress(StringRef InputBuffer,
+SmallVectorImpl , int Level) {
   llvm_unreachable("zlib::compress is unavailable");
 }
 Error zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
Index: llvm/lib/ProfileData/SampleProfWriter.cpp
===
--- llvm/lib/ProfileData/SampleProfWriter.cpp
+++ llvm/lib/ProfileData/SampleProfWriter.cpp
@@ -86,10 +86,8 @@
 return sampleprof_error::success;
   auto  = *OutputStream;
   SmallString<128> CompressedStrings;
-  llvm::Error E = zlib::compress(UncompressedStrings, CompressedStrings,
- zlib::BestSizeCompression);
-  if (E)
-return sampleprof_error::compress_failed;
+  zlib::compress(UncompressedStrings, CompressedStrings,
+ zlib::BestSizeCompression);
   encodeULEB128(UncompressedStrings.size(), OS);
   encodeULEB128(CompressedStrings.size(), OS);
   OS << CompressedStrings.str();
Index: llvm/lib/ProfileData/SampleProf.cpp
===
--- llvm/lib/ProfileData/SampleProf.cpp
+++ llvm/lib/ProfileData/SampleProf.cpp
@@ -85,8 +85,6 @@
   return "Counter overflow";
 case sampleprof_error::ostream_seek_unsupported:
   return "Ostream does not support seek";
-case sampleprof_error::compress_failed:
-  return "Compress failure";
 case sampleprof_error::uncompress_failed:
   return "Uncompress failure";
 case sampleprof_error::zlib_unavailable:
Index: llvm/lib/ProfileData/InstrProf.cpp
===
--- llvm/lib/ProfileData/InstrProf.cpp
+++ llvm/lib/ProfileData/InstrProf.cpp
@@ -467,12 +467,8 @@
   }
 
   SmallString<128> CompressedNameStrings;
-  Error E = zlib::compress(StringRef(UncompressedNameStrings),
-   CompressedNameStrings, 

[clang] 407c721 - [Support] Change zlib::compress to return void

2022-03-14 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-03-14T11:38:04-07:00
New Revision: 407c721ceb93863b2cb3851a6aa7686f31657e6b

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

LOG: [Support] Change zlib::compress to return void

With a sufficiently large output buffer, the only failure is Z_MEM_ERROR.
Check it and call the noreturn report_bad_alloc_error if applicable.
resize_for_overwrite may call report_bad_alloc_error as well.

Now that there is no other error type, we can replace the return type with void
and simplify call sites.

Reviewed By: ikudrin

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

Added: 


Modified: 
clang-tools-extra/clangd/index/Serialization.cpp
clang/lib/Serialization/ASTWriter.cpp
llvm/include/llvm/ProfileData/SampleProf.h
llvm/include/llvm/Support/Compression.h
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/ObjCopy/ELF/ELFObject.cpp
llvm/lib/ObjCopy/ELF/ELFObject.h
llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/ProfileData/SampleProf.cpp
llvm/lib/ProfileData/SampleProfWriter.cpp
llvm/lib/Support/Compression.cpp
llvm/unittests/Support/CompressionTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/Serialization.cpp 
b/clang-tools-extra/clangd/index/Serialization.cpp
index 8ceecb6072360..f7045f0be3fde 100644
--- a/clang-tools-extra/clangd/index/Serialization.cpp
+++ b/clang-tools-extra/clangd/index/Serialization.cpp
@@ -192,7 +192,7 @@ class StringTableOut {
 }
 if (llvm::zlib::isAvailable()) {
   llvm::SmallString<1> Compressed;
-  llvm::cantFail(llvm::zlib::compress(RawTable, Compressed));
+  llvm::zlib::compress(RawTable, Compressed);
   write32(RawTable.size(), OS);
   OS << Compressed;
 } else {

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 63fcc1eaa5509..69c9d61c52276 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -2007,15 +2007,11 @@ static void emitBlob(llvm::BitstreamWriter , 
StringRef Blob,
   // consumers will not want its contents.
   SmallString<0> CompressedBuffer;
   if (llvm::zlib::isAvailable()) {
-llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer);
-if (!E) {
-  RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED,
- Blob.size() - 1};
-  Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
-CompressedBuffer);
-  return;
-}
-llvm::consumeError(std::move(E));
+llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer);
+RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, Blob.size() - 
1};
+Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
+  CompressedBuffer);
+return;
   }
 
   RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB};

diff  --git a/llvm/include/llvm/ProfileData/SampleProf.h 
b/llvm/include/llvm/ProfileData/SampleProf.h
index 23052ae30032e..178bfced88a0c 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -55,7 +55,6 @@ enum class sampleprof_error {
   not_implemented,
   counter_overflow,
   ostream_seek_unsupported,
-  compress_failed,
   uncompress_failed,
   zlib_unavailable,
   hash_mismatch

diff  --git a/llvm/include/llvm/Support/Compression.h 
b/llvm/include/llvm/Support/Compression.h
index 5bc0e56913fe2..e6f898229412e 100644
--- a/llvm/include/llvm/Support/Compression.h
+++ b/llvm/include/llvm/Support/Compression.h
@@ -29,8 +29,8 @@ static constexpr int BestSizeCompression = 9;
 
 bool isAvailable();
 
-Error compress(StringRef InputBuffer, SmallVectorImpl ,
-   int Level = DefaultCompression);
+void compress(StringRef InputBuffer, SmallVectorImpl ,
+  int Level = DefaultCompression);
 
 Error uncompress(StringRef InputBuffer, char *UncompressedBuffer,
  size_t );

diff  --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index abcd3bb2b8496..00d18cd35ab40 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -864,13 +864,8 @@ void ELFWriter::writeSectionData(const MCAssembler , 
MCSection ,
   Asm.writeSectionData(VecOS, , Layout);
 
   SmallVector CompressedContents;
-  if (Error E = zlib::compress(
-  StringRef(UncompressedData.data(), UncompressedData.size()),
-  CompressedContents)) {
-consumeError(std::move(E));
-W.OS << UncompressedData;
-return;
-  }
+  zlib::compress(StringRef(UncompressedData.data(), UncompressedData.size()),
+ CompressedContents);
 
   bool ZlibStyle = 

[PATCH] D121629: clang: also check alloc_alignment claims in return

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

In D121629#3380175 , @lebedev.ri 
wrote:

> Please can you pose the next patch itself?
> I suspect that propagation should simply not be done when sanitizer is 
> enabled.

I'm working on the next patch. Sadly we can't omit `allocalign`s into the IR 
layer when sanitizers are enabled because nothing will (when I'm done cleaning 
up MemoryBuiltins.cpp) have a way to know anything about the alignment of 
returned pointers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121629

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


[PATCH] D121629: clang: also check alloc_alignment claims in return

2022-03-14 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a reviewer: lebedev.ri.
lebedev.ri added a comment.

Please can you pose the next patch itself?
I suspect that propagation should simply not be done when sanitizer is enabled.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121629

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


[PATCH] D121368: [pseudo][WIP] Build Ambiguous forest node in the GLR Parser.

2022-03-14 Thread Alex Tsao via Phabricator via cfe-commits
alextsao1999 added inline comments.



Comment at: clang/lib/Tooling/Syntax/Pseudo/GLRParser.cpp:318
 Bases.push_back(
-{Base, ParsingTable.getGoToState(Base->State, ReduceRule.Target)});
+{Base, ParsingTable.getGoToState(Base->State, ReduceSymbolID)});
   llvm::sort(Bases, [](const BaseInfo , const BaseInfo ) {

Maybe we can make goto more clear? like `performGoto` after every GLR reduction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121368

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


[PATCH] D121512: [Support] Change zlib::compress to return void

2022-03-14 Thread Igor Kudrin via Phabricator via cfe-commits
ikudrin accepted this revision.
ikudrin 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/D121512/new/

https://reviews.llvm.org/D121512

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


  1   2   3   >