[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Kees Cook via cfe-commits


@@ -1,13 +1,158 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
-// RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c -fsyntax-only
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -x c++
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c,gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=stock,c,microsoft -fsyntax-only 
-fms-compatibility -Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}

kees wrote:

Ah, no, checking initializer positions is needed too. I've added tests to 
`clang/test/CodeGen/flexible-array-init.c`.

https://github.com/llvm/llvm-project/pull/84428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

2024-03-18 Thread Ella Ma via cfe-commits

Snape3058 wrote:

Updated as suggested.

https://github.com/llvm/llvm-project/pull/85515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Kees Cook via cfe-commits

https://github.com/kees updated https://github.com/llvm/llvm-project/pull/84428

>From eb5138b45fa450737600050ad8dabdcb27513d42 Mon Sep 17 00:00:00 2001
From: Kees Cook 
Date: Thu, 7 Mar 2024 17:03:09 -0800
Subject: [PATCH 1/3] [Clang][Sema]: Allow flexible arrays in unions and alone
 in structs

GNU and MSVC have extensions where flexible array members (or their
equivalent) can be in unions or alone in structs. This is already fully
supported in Clang through the 0-sized array ("fake flexible array")
extension or when C99 flexible array members have been syntactically
obfuscated.

Clang needs to explicitly allow these extensions directly for C99
flexible arrays, since they are common code patterns in active use by the
Linux kernel (and other projects). Such projects have been using either
0-sized arrays (which is considered deprecated in favor of C99 flexible
array members) or via obfuscated syntax, both of which complicate their
code bases.

For example, these do not error by default:

union one {
int a;
int b[0];
};

union two {
int a;
struct {
struct { } __empty;
int b[];
};
};

But this does:

union three {
int a;
int b[];
};

Remove the default error diagnostics for this but continue to provide
warnings under Microsoft or GNU extensions checks. This will allow for
a seamless transition for code bases away from 0-sized arrays without
losing existing code patterns. Add explicit checking for the warnings
under various constructions.

Fixes #84565
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  5 --
 clang/lib/Sema/SemaDecl.cpp   |  8 +--
 clang/test/C/drs/dr5xx.c  |  2 +-
 clang/test/Sema/flexible-array-in-union.c | 53 +--
 clang/test/Sema/transparent-union.c   |  4 +-
 6 files changed, 57 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1b901a27fd19d1..960ab7e021cf2f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,6 +214,9 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
   Fixes #GH82512.
 
+- ``-Wmicrosoft`` or ``-Wgnu`` is now required to diagnose C99 flexible
+  array members in a union or alone in a struct.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c8dfdc08f5ea07..f09121b8c7ec8f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6447,9 +6447,6 @@ def ext_c99_flexible_array_member : Extension<
 def err_flexible_array_virtual_base : Error<
   "flexible array member %0 not allowed in "
   "%select{struct|interface|union|class|enum}1 which has a virtual base 
class">;
-def err_flexible_array_empty_aggregate : Error<
-  "flexible array member %0 not allowed in otherwise empty "
-  "%select{struct|interface|union|class|enum}1">;
 def err_flexible_array_has_nontrivial_dtor : Error<
   "flexible array member %0 of type %1 with non-trivial destruction">;
 def ext_flexible_array_in_struct : Extension<
@@ -6464,8 +6461,6 @@ def ext_flexible_array_empty_aggregate_ms : Extension<
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a Microsoft extension">,
   InGroup;
-def err_flexible_array_union : Error<
-  "flexible array member %0 in a union is not allowed">;
 def ext_flexible_array_union_ms : Extension<
   "flexible array member %0 in a union is a Microsoft extension">,
   InGroup;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 67e56a917a51de..053122b588246b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19357,15 +19357,11 @@ void Sema::ActOnFields(Scope *S, SourceLocation 
RecLoc, Decl *EnclosingDecl,
 } else if (Record->isUnion())
   DiagID = getLangOpts().MicrosoftExt
? diag::ext_flexible_array_union_ms
-   : getLangOpts().CPlusPlus
- ? diag::ext_flexible_array_union_gnu
- : diag::err_flexible_array_union;
+   : diag::ext_flexible_array_union_gnu;
 else if (NumNamedMembers < 1)
   DiagID = getLangOpts().MicrosoftExt
? diag::ext_flexible_array_empty_aggregate_ms
-   : getLangOpts().CPlusPlus
- ? diag::ext_flexible_array_empty_aggregate_gnu
- : diag::err_flexible_array_empty_aggregate;
+   : diag::ext_flexible_array_empty_aggregate_gnu;
 
 if (DiagID)
   

[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

2024-03-18 Thread Ella Ma via cfe-commits


@@ -1186,6 +1192,14 @@ def main():
 "displaying it, dump the rewritten dot file "
 "to stdout",
 )
+dump_conflict.add_argument(
+"--dump-html-only",
+action="store_const",
+dest="dump_html_only",
+const=True,
+default=False,
+help="do not open the generated HTML immediately",

Snape3058 wrote:

As it is presented directly after `--dump-dot-only`, I used to think the help 
message is enough to understand the option after reading the 
`--dump-dot-only`'s. Updated as suggested.

https://github.com/llvm/llvm-project/pull/85515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Kees Cook via cfe-commits

https://github.com/kees edited https://github.com/llvm/llvm-project/pull/84428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Kees Cook via cfe-commits


@@ -1,13 +1,158 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
-// RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c -fsyntax-only
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -x c++
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c,gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=stock,c,microsoft -fsyntax-only 
-fms-compatibility -Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}
+microsoft-warning {{flexible array member 'x' 
in a union is a Microsoft extension}}
+  */
+struct _name1 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1 = {
+  10,
+  42,/* initializes "b" */
+};
 
-// expected-no-diagnostics
+struct _name1i {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1i = {
+  .a = 10,
+  .b = 42,
+};
+
+/* Initialization of flexible array in a union is never allowed. */
+struct _name2 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+ stock-note {{initialized flexible array member 'x' is here}}
+   */
+  };
+} name2 = {
+  12,
+  13,
+  { 'c' },   /* stock-error {{initialization of flexible array member is not 
allowed}} */

kees wrote:

Yeah, I see what you mean. It looks like (when not using named initializers) a 
union initializer is applied to the first member. (i.e. when the type is 
anything other than a flexible array.) When it's a flex array, it processes it 
but only allows it to be zero initialized. Regardless, here's the results for 
unnamed initializers:

```
struct { int a; union { int b; short x; }; int c; int d; } h = {1, 2, {}, 3};
// @h = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, i32 0, 
i32 3 }
struct { int a; union { int b; short x[0]; }; int c; int d; } h0 = {1, 2, {}, 
3};
// @h0 = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, i32 0, 
i32 3 }
struct { int a; union { int b; short x[1]; }; int c; int d; } h1 = {1, 2, {}, 
3};
// @h1 = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, i32 0, 
i32 3 }
struct { int a; union { int b; short x[]; }; int c; int d; } hf = {1, 2, {}, 3};
// @hf = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, i32 3, 
i32 0 }
```

`hf` has clearly gone weird.

And here's what happens when using named initializers:

```
struct { int a; union { int b; short x; }; int c; int d; } hn = {.a = 1, .x = 
2, .c = 3};
// @hn = global { i32, { i16, [2 x i8] }, i32, i32 } { i32 1, { i16, [2 x i8] } 
{ i16 2, [2 x i8] undef }, i32 3, i32 0 }
struct { int a; union { int b; short x[0]; }; int c; int d; } hn0 = {.a = 1, .x 
= {2}, .c = 3};
// @hn0 = global { i32, { [0 x i16], [4 x i8] }, i32, i32 } { i32 1, { [0 x 
i16], [4 x i8] } { [0 x i16] zeroinitializer, [4 x i8] undef }, i32 3, i32 0 }
struct { int a; union { int b; short x[1]; }; int c; int d; } hn1 = {.a = 1, .x 
= {2}, .c = 3};
// @hn1 = global { i32, { [1 x i16], [2 x i8] }, i32, i32 } { i32 1, { [1 x 
i16], [2 x i8] } { [1 x i16] [i16 2], [2 x i8] undef }, i32 3, i32 0 }
```

The initialization of `x` in `hn0` just disappears, but it does generate the 
warning `excess elements in array initializer`, which I guess makes sense if 
it's not treating it as a fake flexible array?

Notably tttempting to initialize the flexible array by name will fail to build:
```
/srv/code/llvm-project/clang/test/CodeGen/flexible-array-init.c:48:82: error: 
initialization of flexible array member is not allowed  
  
   48 | struct { int a; union { int b; short x[]; }; int c; int d; } hnf = {.a 
= 1, .x = {2}, .c = 3 };
  
  |  

[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

2024-03-18 Thread Ella Ma via cfe-commits


@@ -479,12 +479,15 @@ def add_raw_line(self, raw_line):
 # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
 # syntax highlighing.
 class DotDumpVisitor:
-def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only):
+def __init__(
+self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only, 
dump_html_only
+):

Snape3058 wrote:

I used to consider merging these two options. But this would affect some test 
cases.
I am afraid of breaking some other places that I do not know, I hence added a 
new option in the first version.
If only the test cases will be affected, I can re-impl it in the merged way.

https://github.com/llvm/llvm-project/pull/85515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

2024-03-18 Thread Ella Ma via cfe-commits


@@ -479,12 +479,15 @@ def add_raw_line(self, raw_line):
 # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
 # syntax highlighing.
 class DotDumpVisitor:
-def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only):
+def __init__(
+self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only, 
dump_html_only
+):

Snape3058 wrote:

assert added to the constructor of `DotDumpVisitor`

https://github.com/llvm/llvm-project/pull/85515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

2024-03-18 Thread Ella Ma via cfe-commits

https://github.com/Snape3058 edited 
https://github.com/llvm/llvm-project/pull/85515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

2024-03-18 Thread Ella Ma via cfe-commits

https://github.com/Snape3058 updated 
https://github.com/llvm/llvm-project/pull/85515

>From 1d37cd1a7dac2ddb05fdcf125483991b3ac645d8 Mon Sep 17 00:00:00 2001
From: Ella Ma 
Date: Sat, 16 Mar 2024 18:25:12 +0800
Subject: [PATCH 1/3] allow egraph rewriter not to open html directly

---
 .../utils/analyzer/exploded-graph-rewriter.py | 20 ---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py 
b/clang/utils/analyzer/exploded-graph-rewriter.py
index c7c6315a0a27d1..ffec964d8ef09a 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -479,12 +479,14 @@ def add_raw_line(self, raw_line):
 # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
 # syntax highlighing.
 class DotDumpVisitor:
-def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only):
+def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only,
+dump_html_only):
 self._do_diffs = do_diffs
 self._dark_mode = dark_mode
 self._gray_mode = gray_mode
 self._topo_mode = topo_mode
 self._dump_dot_only = dump_dot_only
+self._dump_html_only = dump_html_only
 self._output = []
 
 def _dump_raw(self, s):
@@ -998,6 +1000,8 @@ def write_temp_file(suffix, prefix, data):
 '%s'
 % ("#1a1a1a" if self._dark_mode else "white", svg),
 )
+if self._dump_html_only:
+return
 if sys.platform == "win32":
 os.startfile(filename)
 elif sys.platform == "darwin":
@@ -1176,7 +1180,8 @@ def main():
 default=False,
 help="black-and-white mode",
 )
-parser.add_argument(
+dump_conflict = parser.add_mutually_exclusive_group()
+dump_conflict.add_argument(
 "--dump-dot-only",
 action="store_const",
 dest="dump_dot_only",
@@ -1186,6 +1191,14 @@ def main():
 "displaying it, dump the rewritten dot file "
 "to stdout",
 )
+dump_conflict.add_argument(
+"--dump-html-only",
+action="store_const",
+dest="dump_html_only",
+const=True,
+default=False,
+help="do not open the generated HTML immediately",
+)
 args = parser.parse_args()
 logging.basicConfig(level=args.loglevel)
 
@@ -1206,7 +1219,8 @@ def main():
 explorer = BasicExplorer()
 
 visitor = DotDumpVisitor(
-args.diff, args.dark, args.gray, args.topology, args.dump_dot_only
+args.diff, args.dark, args.gray, args.topology, args.dump_dot_only,
+args.dump_html_only
 )
 
 for trimmer in trimmers:

>From 3e44fb5936e37f234d601e4070c9da445a2e53ba Mon Sep 17 00:00:00 2001
From: Ella Ma 
Date: Sat, 16 Mar 2024 19:15:11 +0800
Subject: [PATCH 2/3] fix format issues

---
 clang/utils/analyzer/exploded-graph-rewriter.py | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py 
b/clang/utils/analyzer/exploded-graph-rewriter.py
index ffec964d8ef09a..1dc8a5337da598 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -479,8 +479,9 @@ def add_raw_line(self, raw_line):
 # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
 # syntax highlighing.
 class DotDumpVisitor:
-def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only,
-dump_html_only):
+def __init__(
+self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only, 
dump_html_only
+):
 self._do_diffs = do_diffs
 self._dark_mode = dark_mode
 self._gray_mode = gray_mode
@@ -1219,8 +1220,12 @@ def main():
 explorer = BasicExplorer()
 
 visitor = DotDumpVisitor(
-args.diff, args.dark, args.gray, args.topology, args.dump_dot_only,
-args.dump_html_only
+args.diff,
+args.dark,
+args.gray,
+args.topology,
+args.dump_dot_only,
+args.dump_html_only,
 )
 
 for trimmer in trimmers:

>From d06079789551f11a8aa03e06d286d20f434be0fc Mon Sep 17 00:00:00 2001
From: Ella Ma 
Date: Tue, 19 Mar 2024 13:23:10 +0800
Subject: [PATCH 3/3] add assert to check the conflict; add detailed help msg;
 swap the appearance dot and html

---
 .../utils/analyzer/exploded-graph-rewriter.py | 28 +++
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py 
b/clang/utils/analyzer/exploded-graph-rewriter.py
index 1dc8a5337da598..5eaa7738103f79 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -480,14 +480,19 @@ def add_raw_line(self, raw_line):
 # syntax highlighing.
 class DotDumpVisitor:
 def __init__(
-self, 

[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde updated 
https://github.com/llvm/llvm-project/pull/82084

>From 9e665d05743022350e06f4ea357ecfecde82efb8 Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Fri, 16 Feb 2024 16:39:10 -0800
Subject: [PATCH] Support sysroot-relative header search paths

Clang supported header searchpaths of the form `-I =/path`, relative to
the sysroot if one is passed, but did not implement that behavior for
`-iquote`, `-isystem`, or `-idirafter`.
---
 clang/lib/Frontend/CompilerInvocation.cpp | 43 +++
 clang/test/Preprocessor/sysroot-prefix.c  | 25 +
 2 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2a21a9d619dc0b..650e05b2bf33a0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3191,6 +3191,22 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
, ArgList ,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto PrefixHeaderPath = [IsSysrootSpecified,
+   ](const llvm::opt::Arg *A,
+  bool IsFramework = false) -> std::string {
+assert(A->getNumValues() != 0 && "Unexpected empty search path flag!");
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
+  SmallString<32> Buffer;
+  llvm::sys::path::append(Buffer, Opts.Sysroot,
+  llvm::StringRef(A->getValue()).substr(1));
+  return std::string(Buffer);
+}
+return A->getValue();
+  };
+
   for (const auto *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) {
 if (A->getOption().matches(OPT_index_header_map)) {
   // -index-header-map applies to the next -I or -F.
@@ -3202,16 +3218,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
, ArgList ,
 IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
 
 bool IsFramework = A->getOption().matches(OPT_F);
-std::string Path = A->getValue();
-
-if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
-  SmallString<32> Buffer;
-  llvm::sys::path::append(Buffer, Opts.Sysroot,
-  llvm::StringRef(A->getValue()).substr(1));
-  Path = std::string(Buffer);
-}
-
-Opts.AddPath(Path, Group, IsFramework,
+Opts.AddPath(PrefixHeaderPath(A, IsFramework), Group, IsFramework,
  /*IgnoreSysroot*/ true);
 IsIndexHeaderMap = false;
   }
@@ -3229,12 +3236,18 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
, ArgList ,
   }
 
   for (const auto *A : Args.filtered(OPT_idirafter))
-Opts.AddPath(A->getValue(), frontend::After, false, true);
+Opts.AddPath(PrefixHeaderPath(A), frontend::After, false, true);
   for (const auto *A : Args.filtered(OPT_iquote))
-Opts.AddPath(A->getValue(), frontend::Quoted, false, true);
-  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
-Opts.AddPath(A->getValue(), frontend::System, false,
- !A->getOption().matches(OPT_iwithsysroot));
+Opts.AddPath(PrefixHeaderPath(A), frontend::Quoted, false, true);
+
+  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot)) {
+if (A->getOption().matches(OPT_iwithsysroot)) {
+  Opts.AddPath(A->getValue(), frontend::System, false,
+   /*IgnoreSysRoot=*/false);
+  continue;
+}
+Opts.AddPath(PrefixHeaderPath(A), frontend::System, false, true);
+  }
   for (const auto *A : Args.filtered(OPT_iframework))
 Opts.AddPath(A->getValue(), frontend::System, true, true);
   for (const auto *A : Args.filtered(OPT_iframeworkwithsysroot))
diff --git a/clang/test/Preprocessor/sysroot-prefix.c 
b/clang/test/Preprocessor/sysroot-prefix.c
index 08c72f53b44e9f..eff71f5e3d5a36 100644
--- a/clang/test/Preprocessor/sysroot-prefix.c
+++ b/clang/test/Preprocessor/sysroot-prefix.c
@@ -4,6 +4,16 @@
 // RUN: %clang_cc1 -v -isysroot /var/empty -I =null -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty -isysroot /var/empty/root -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty/root -isysroot /var/empty -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SWAPPED_SYSROOT_NULL %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -isysroot /var/empty -E %s -o 
/dev/null 2>&1 | FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_SYSROOT %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_NO_SYSROOT %s
+// RUN: %clang_cc1 -v -iquote=/usr/include -isysroot /var/empty  -E %s -o 
/dev/null 2>&1 | 

[clang] [NFC] Refactor ConstantArrayType size storage (PR #85716)

2024-03-18 Thread Timm Baeder via cfe-commits


@@ -3182,34 +3182,98 @@ class ArrayType : public Type, public 
llvm::FoldingSetNode {
 /// For example, the canonical type for 'int A[4 + 4*100]' is a
 /// ConstantArrayType where the element type is 'int' and the size is 404.
 class ConstantArrayType final
-: public ArrayType,
-  private llvm::TrailingObjects {
+: public ArrayType {
   friend class ASTContext; // ASTContext creates these.
-  friend TrailingObjects;
 
-  llvm::APInt Size; // Allows us to unique the type.
+  struct ExternalSize {
+ExternalSize(const llvm::APInt , const Expr *SE)
+: Size(Sz), SizeExpr(SE) {}
+llvm::APInt Size; // Allows us to unique the type.
+const Expr *SizeExpr;
+  };
+  struct InlineSize {
+InlineSize(uint64_t TSz, uint64_t Sz) : ByteWidth(TSz), Size(Sz) {}
+uint64_t ByteWidth : 4;
+uint64_t Size : 60;
+  };
+  union {
+struct InlineSize I;
+ExternalSize *SizePtr;
+  };
 
-  ConstantArrayType(QualType et, QualType can, const llvm::APInt ,
-const Expr *sz, ArraySizeModifier sm, unsigned tq)
-  : ArrayType(ConstantArray, et, can, sm, tq, sz), Size(size) {
-ConstantArrayTypeBits.HasStoredSizeExpr = sz != nullptr;
-if (ConstantArrayTypeBits.HasStoredSizeExpr) {
-  assert(!can.isNull() && "canonical constant array should not have size");
-  *getTrailingObjects() = sz;
-}
+  ConstantArrayType(QualType Et, QualType Can, uint64_t Width, uint64_t Sz,
+ArraySizeModifier SM, unsigned TQ)
+  : ArrayType(ConstantArray, Et, Can, SM, TQ, nullptr), I(Width / 8, Sz) {
+ConstantArrayTypeBits.HasExternalSize = false;
+assert(Sz < 0x0FFF && "Size must fit in 60 bits");
+assert(Width < 0xFF && "Type width must fit in 8 bits");

tbaederr wrote:

8 or 4?

https://github.com/llvm/llvm-project/pull/85716
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

2024-03-18 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/76357

>From 28000eb88b54b02993107d4f222acc5d733c623f Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH 1/3] [RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.
---
 clang/docs/ReleaseNotes.rst|   1 +
 clang/test/Driver/riscv-profiles.c | 312 +
 llvm/lib/Support/RISCVISAInfo.cpp  |  64 ++
 3 files changed, 377 insertions(+)
 create mode 100644 clang/test/Driver/riscv-profiles.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 125d51c42d507f..08c6d45d60c4dc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -455,6 +455,7 @@ RISC-V Support
 ^^
 
 - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t 
types.
+- Profile names in ``-march`` option is now supported.
 
 CUDA/HIP Language Changes
 ^
diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..904f0c371f4442
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,312 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+ziccamoa"
+// RVA20U64: "-target-feature" "+ziccif"
+// RVA20U64: "-target-feature" "+zicclsm"
+// RVA20U64: "-target-feature" "+ziccrse"
+// RVA20U64: "-target-feature" "+zicntr"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-feature" "+za128rs"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+ziccamoa"
+// RVA20S64: "-target-feature" "+ziccif"
+// RVA20S64: "-target-feature" "+zicclsm"
+// RVA20S64: "-target-feature" "+ziccrse"
+// RVA20S64: "-target-feature" "+zicntr"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-feature" "+za128rs"
+// RVA20S64: "-target-feature" "+ssccptr"
+// RVA20S64: "-target-feature" "+sstvala"
+// RVA20S64: "-target-feature" "+sstvecd"
+// RVA20S64: "-target-feature" "+svade"
+// RVA20S64: "-target-feature" "+svbare"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zic64b"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+ziccamoa"
+// RVA22U64: "-target-feature" "+ziccif"
+// RVA22U64: "-target-feature" "+zicclsm"
+// RVA22U64: "-target-feature" "+ziccrse"
+// RVA22U64: "-target-feature" "+zicntr"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zihpm"
+// RVA22U64: "-target-feature" "+za64rs"
+// RVA22U64: "-target-feature" "+zfhmin"
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+zic64b"
+// RVA22S64: "-target-feature" "+zicbom"
+// RVA22S64: "-target-feature" "+zicbop"
+// RVA22S64: "-target-feature" "+zicboz"
+// RVA22S64: "-target-feature" "+ziccamoa"
+// RVA22S64: "-target-feature" "+ziccif"
+// RVA22S64: "-target-feature" "+zicclsm"
+// RVA22S64: "-target-feature" "+ziccrse"
+// RVA22S64: "-target-feature" 

[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

2024-03-18 Thread Craig Topper via cfe-commits

https://github.com/topperc approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/76357
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

2024-03-18 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/76357

>From 28000eb88b54b02993107d4f222acc5d733c623f Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH 1/2] [RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.
---
 clang/docs/ReleaseNotes.rst|   1 +
 clang/test/Driver/riscv-profiles.c | 312 +
 llvm/lib/Support/RISCVISAInfo.cpp  |  64 ++
 3 files changed, 377 insertions(+)
 create mode 100644 clang/test/Driver/riscv-profiles.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 125d51c42d507f..08c6d45d60c4dc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -455,6 +455,7 @@ RISC-V Support
 ^^
 
 - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t 
types.
+- Profile names in ``-march`` option is now supported.
 
 CUDA/HIP Language Changes
 ^
diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..904f0c371f4442
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,312 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+ziccamoa"
+// RVA20U64: "-target-feature" "+ziccif"
+// RVA20U64: "-target-feature" "+zicclsm"
+// RVA20U64: "-target-feature" "+ziccrse"
+// RVA20U64: "-target-feature" "+zicntr"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-feature" "+za128rs"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+ziccamoa"
+// RVA20S64: "-target-feature" "+ziccif"
+// RVA20S64: "-target-feature" "+zicclsm"
+// RVA20S64: "-target-feature" "+ziccrse"
+// RVA20S64: "-target-feature" "+zicntr"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-feature" "+za128rs"
+// RVA20S64: "-target-feature" "+ssccptr"
+// RVA20S64: "-target-feature" "+sstvala"
+// RVA20S64: "-target-feature" "+sstvecd"
+// RVA20S64: "-target-feature" "+svade"
+// RVA20S64: "-target-feature" "+svbare"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zic64b"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+ziccamoa"
+// RVA22U64: "-target-feature" "+ziccif"
+// RVA22U64: "-target-feature" "+zicclsm"
+// RVA22U64: "-target-feature" "+ziccrse"
+// RVA22U64: "-target-feature" "+zicntr"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zihpm"
+// RVA22U64: "-target-feature" "+za64rs"
+// RVA22U64: "-target-feature" "+zfhmin"
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+zic64b"
+// RVA22S64: "-target-feature" "+zicbom"
+// RVA22S64: "-target-feature" "+zicbop"
+// RVA22S64: "-target-feature" "+zicboz"
+// RVA22S64: "-target-feature" "+ziccamoa"
+// RVA22S64: "-target-feature" "+ziccif"
+// RVA22S64: "-target-feature" "+zicclsm"
+// RVA22S64: "-target-feature" "+ziccrse"
+// RVA22S64: "-target-feature" 

[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-18 Thread Owen Pan via cfe-commits

owenca wrote:

Can you provide more info about the failed use cases?

https://github.com/llvm/llvm-project/pull/84599
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (PR #85470)

2024-03-18 Thread Owen Pan via cfe-commits


@@ -11450,6 +11450,11 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) {
"void new (link p);\n"
"void delete (link p);");
 
+  verifyFormat("{ p->delete(); }\n"
+   "{ p->new(); }",
+   "{ p->delete (); }\n"
+   "{ p->new (); }");

owenca wrote:

My bad. Fixed in a2527e06d777.

https://github.com/llvm/llvm-project/pull/85470
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a2527e0 - [clang-format] Put erroneously removed braces back into a unit test

2024-03-18 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-03-18T20:22:42-07:00
New Revision: a2527e06d77766d00e83ecb7988844aae7088bb1

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

LOG: [clang-format] Put erroneously removed braces back into a unit test

See https://github.com/llvm/llvm-project/pull/85470#discussion_r1528904789

Added: 


Modified: 
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a14b002c37c631..bea989c8c306db 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11475,10 +11475,10 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) {
"void new (link p);\n"
"void delete (link p);");
 
-  verifyFormat("p->new();\n"
-   "p->delete();",
-   "p->new ();\n"
-   "p->delete ();");
+  verifyFormat("{ p->new(); }\n"
+   "{ p->delete(); }",
+   "{ p->new (); }\n"
+   "{ p->delete (); }");
 
   FormatStyle AfterPlacementOperator = getLLVMStyle();
   AfterPlacementOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom;



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


[clang] [X86_64] fix arg pass error in struct. (PR #85394)

2024-03-18 Thread Longsheng Mou via cfe-commits

https://github.com/CoTinker updated 
https://github.com/llvm/llvm-project/pull/85394

>From 57760b2bfe87c689030975d5914393fd29d7d1f5 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 15 Mar 2024 20:50:54 +0800
Subject: [PATCH] [X86_64] fix arg pass error in struct.

typedef long long ll __attribute__((aligned (4)));
struct S {
  int a;
  ll b;
};

when classify:
a: Lo = Integer, Hi = NoClass
b: Lo = Integer, Hi = NoClass
struct S: Lo = Integer, Hi = NoClass

In this case, only one i64 register is used when the structure
parameter is transferred, which is obviously incorrect.So we need
to treat the split case specially.
---
 clang/lib/CodeGen/Targets/X86.cpp |  6 ++
 clang/test/CodeGen/X86/x86_64-arguments.c | 18 ++
 2 files changed, 24 insertions(+)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 2291c991fb1107..c3e32e5ed63a97 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1787,6 +1787,8 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class ,
   Lo = Hi = NoClass;
 
   Class  = OffsetBase < 64 ? Lo : Hi;
+  bool IsSplit =
+  OffsetBase < 64 && (OffsetBase + getContext().getTypeSize(Ty)) > 64;
   Current = Memory;
 
   if (const BuiltinType *BT = Ty->getAs()) {
@@ -1799,9 +1801,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class ,
   Hi = Integer;
 } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
   Current = Integer;
+  if (IsSplit)
+Hi = Integer;
 } else if (k == BuiltinType::Float || k == BuiltinType::Double ||
k == BuiltinType::Float16 || k == BuiltinType::BFloat16) {
   Current = SSE;
+  if (IsSplit)
+Hi = SSE;
 } else if (k == BuiltinType::Float128) {
   Lo = SSE;
   Hi = SSEUp;
diff --git a/clang/test/CodeGen/X86/x86_64-arguments.c 
b/clang/test/CodeGen/X86/x86_64-arguments.c
index cf5636cfd518b6..92b0192658a555 100644
--- a/clang/test/CodeGen/X86/x86_64-arguments.c
+++ b/clang/test/CodeGen/X86/x86_64-arguments.c
@@ -533,6 +533,24 @@ typedef float t66 __attribute__((__vector_size__(128), 
__aligned__(128)));
 void f66(t66 a0) {
 }
 
+typedef long long t67 __attribute__((aligned (4)));
+struct s67 {
+  int a;
+  t67 b;
+};
+// CHECK-LABEL: define{{.*}} void @f67(i64 %x.coerce0, i32 %x.coerce1)
+void f67(struct s67 x) {
+}
+
+typedef double t68 __attribute__((aligned (4)));
+struct s68 {
+  int a;
+  t68 b;
+};
+// CHECK-LABEL: define{{.*}} void @f68(i64 %x.coerce0, double %x.coerce1)
+void f68(struct s68 x) {
+}
+
 /// The synthesized __va_list_tag does not have file/line fields.
 // CHECK:  = distinct !DICompositeType(tag: DW_TAG_structure_type, name: 
"__va_list_tag",
 // CHECK-NOT:  file:

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


[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-18 Thread Qizhi Hu via cfe-commits


@@ -13714,6 +13714,12 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 
 // Capturing 'this' is trivial.
 if (C->capturesThis()) {
+  // We need ThisType when build capture in CheckCXXThisCapture.

jcsxky wrote:

Thanks for your patience!

https://github.com/llvm/llvm-project/pull/85565
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Harald van Dijk via cfe-commits


@@ -1,13 +1,158 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
-// RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c -fsyntax-only
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -x c++
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c,gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=stock,c,microsoft -fsyntax-only 
-fms-compatibility -Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}
+microsoft-warning {{flexible array member 'x' 
in a union is a Microsoft extension}}
+  */
+struct _name1 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1 = {
+  10,
+  42,/* initializes "b" */
+};
 
-// expected-no-diagnostics
+struct _name1i {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1i = {
+  .a = 10,
+  .b = 42,
+};
+
+/* Initialization of flexible array in a union is never allowed. */
+struct _name2 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+ stock-note {{initialized flexible array member 'x' is here}}
+   */
+  };
+} name2 = {
+  12,
+  13,
+  { 'c' },   /* stock-error {{initialization of flexible array member is not 
allowed}} */

hvdijk wrote:

I think this is more than just a confusing error message. Consider `struct S { 
int a; union { int b; char x[]; }; int c; } s = {1, 2, 3};`. If `x` is given 
type `char[0]`, or `char[1]`, or `char[2]`, the `3` initializer applies to 
`s.c`. Yet inexplicably, if `x` has type `char[]`, the `3` initializer applies 
to `s.x` and any initializer is an error? That looks like a bug. We can even 
turn this into wrong-code: `struct S { int a; union { int b; char x[]; }; int 
c; int d; } s = {1, 2, {}, 3};`. This should initialise `a`, `b`, `c`, `d`, to 
`1`, `2`, `0`, `3`, but instead initialises them to `1`, `2`, `3`, `0`.

https://github.com/llvm/llvm-project/pull/84428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-18 Thread via cfe-commits

Sirraide wrote:

CI for the docs seems to be broken because of something clang-format related; 
the changes to the docs here are trivial, so we should just be able to ignore 
that.

https://github.com/llvm/llvm-project/pull/85565
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-18 Thread via cfe-commits

https://github.com/Sirraide approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/85565
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-18 Thread via cfe-commits


@@ -13714,6 +13714,12 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 
 // Capturing 'this' is trivial.
 if (C->capturesThis()) {
+  // We need ThisType when build capture in CheckCXXThisCapture.

Sirraide wrote:

No problem—writing descriptive comments is hard; I had to think a while about 
how to phrase this, and I don’t think the way I phrased it is ideal either, but 
it’s hopefully good enough.

https://github.com/llvm/llvm-project/pull/85565
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `__has_extension(swiftcc)` support (PR #85347)

2024-03-18 Thread Saleem Abdulrasool via cfe-commits

https://github.com/compnerd approved this pull request.

Might be nice to have a test for `swiftasynccc` as well.

https://github.com/llvm/llvm-project/pull/85347
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Kees Cook via cfe-commits


@@ -1,13 +1,158 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
-// RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c -fsyntax-only
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -x c++
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c,gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=stock,c,microsoft -fsyntax-only 
-fms-compatibility -Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}

kees wrote:

It looks like clang/test/CodeGen/object-size.c (via commit 
804af933f7310f78d91e13ad8a13b64b00249614) already covers a lot of this? I'll 
explicitly add unions to that test too.

https://github.com/llvm/llvm-project/pull/84428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] implemented a suggestion to avoid magic numbers (PR #85724)

2024-03-18 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/85724
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-18 Thread Qizhi Hu via cfe-commits


@@ -13714,6 +13714,12 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 
 // Capturing 'this' is trivial.
 if (C->capturesThis()) {
+  // We need ThisType when build capture in CheckCXXThisCapture.

jcsxky wrote:

Ah, I see. I didn't realize to combine test case with the comment to have a 
better illustration. Sorry for my poor English and expression! I have pushed 
your suggestion.

https://github.com/llvm/llvm-project/pull/85565
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] implemented a suggestion to avoid magic numbers (PR #85724)

2024-03-18 Thread via cfe-commits

https://github.com/matrixication created 
https://github.com/llvm/llvm-project/pull/85724

None

>From 17d806c308a7835aeb52aeb347bbfa1e3b135275 Mon Sep 17 00:00:00 2001
From: Matrix 
Date: Tue, 19 Mar 2024 00:59:06 +
Subject: [PATCH] [libclc] implemented a suggestion to avoid magic numbers

---
 libclc/amdgcn/lib/math/fmax.cl | 38 +-
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/libclc/amdgcn/lib/math/fmax.cl b/libclc/amdgcn/lib/math/fmax.cl
index cb796161010829..f82508e8a7e739 100644
--- a/libclc/amdgcn/lib/math/fmax.cl
+++ b/libclc/amdgcn/lib/math/fmax.cl
@@ -4,42 +4,42 @@
 
 _CLC_DEF _CLC_OVERLOAD float fmax(float x, float y)
 {
-   /* fcanonicalize removes sNaNs and flushes denormals if not enabled.
-* Otherwise fmax instruction flushes the values for comparison,
-* but outputs original denormal */
-   x = __builtin_canonicalizef(x);
-   y = __builtin_canonicalizef(y);
-   return __builtin_fmaxf(x, y);
+/* fcanonicalize removes sNaNs and flushes denormals if not enabled.
+ * Otherwise fmax instruction flushes the values for comparison,
+ _but outputs original denormal_ */
+x = __builtin_canonicalizef(x);
+y = __builtin_canonicalizef(y);
+return __builtin_fmaxf(x, y);
 }
+
 _CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, fmax, float, float)
 
 #ifdef cl_khr_fp64
-
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
-
 _CLC_DEF _CLC_OVERLOAD double fmax(double x, double y)
 {
-   x = __builtin_canonicalize(x);
-   y = __builtin_canonicalize(y);
-   return __builtin_fmax(x, y);
+x = __builtin_canonicalize(x);
+y = __builtin_canonicalize(y);
+return __builtin_fmax(x, y);
 }
 _CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, fmax, double, double)
-
 #endif
-#ifdef cl_khr_fp16
 
+#ifdef cl_khr_fp16
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
+#define HALF_ZERO 0.0h
+
 _CLC_DEF _CLC_OVERLOAD half fmax(half x, half y)
 {
-   if (isnan(x))
-  return y;
-   if (isnan(y))
-  return x;
-   return (y < x) ? x : y;
+if (isnan(x))
+return y;
+if (isnan(y))
+return x;
+return (y < x) ? x : y;
 }
-_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, fmax, half, half)
 
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, fmax, half, half)
 #endif
 
 #define __CLC_BODY <../../../generic/lib/math/fmax.inc>

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


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-18 Thread via cfe-commits

github-actions[bot] wrote:



@alexcrichton Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/84569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-18 Thread Dan Gohman via cfe-commits

https://github.com/sunfishcode closed 
https://github.com/llvm/llvm-project/pull/84569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d66121d - [WebAssembly] Change the default linker for `wasm32-wasip2` (#84569)

2024-03-18 Thread via cfe-commits

Author: Alex Crichton
Date: 2024-03-18T17:55:34-07:00
New Revision: d66121d74a458e098511b9de920d815440acaa1b

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

LOG: [WebAssembly] Change the default linker for `wasm32-wasip2` (#84569)

This commit changes the default linker in the WebAssembly toolchain for
the `wasm32-wasip2` target. This target is being added to the
WebAssembly/wasi-sdk and WebAssembly/wasi-libc projects to target the
Component Model by default, in contrast with the preexisting
`wasm32-wasi` target (in the process of being renamed to
`wasm32-wasip1`) which outputs a core WebAssembly module by default.

The `wasm-component-ld` project currently lives in my GitHub account at
https://github.com/alexcrichton/wasm-component-ld and isn't necessarily
"official" yet, but it's expected to continue to evolve as the
`wasm32-wasip2` target continues to shape up and evolve.

Added: 


Modified: 
clang/lib/Driver/ToolChains/WebAssembly.cpp
clang/lib/Driver/ToolChains/WebAssembly.h
clang/test/Driver/wasm-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index b8c2573d6265fb..b7c6efab83e806 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -44,8 +44,15 @@ std::string wasm::Linker::getLinkerPath(const ArgList ) 
const {
   llvm::sys::fs::can_execute(UseLinker))
 return std::string(UseLinker);
 
-  // Accept 'lld', and 'ld' as aliases for the default linker
-  if (UseLinker != "lld" && UseLinker != "ld")
+  // Interpret 'lld' as explicitly requesting `wasm-ld`, so look for that
+  // linker. Note that for `wasm32-wasip2` this overrides the default 
linker
+  // of `wasm-component-ld`.
+  if (UseLinker == "lld") {
+return ToolChain.GetProgramPath("wasm-ld");
+  }
+
+  // Allow 'ld' as an alias for the default linker
+  if (UseLinker != "ld")
 ToolChain.getDriver().Diag(diag::err_drv_invalid_linker_name)
 << A->getAsString(Args);
 }
@@ -73,6 +80,16 @@ void wasm::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (Args.hasArg(options::OPT_s))
 CmdArgs.push_back("--strip-all");
 
+  // On `wasip2` the default linker is `wasm-component-ld` which wraps the
+  // execution of `wasm-ld`. Find `wasm-ld` and pass it as an argument of where
+  // to find it to avoid it needing to hunt and rediscover or search `PATH` for
+  // where it is.
+  if (llvm::sys::path::stem(Linker).ends_with_insensitive(
+  "wasm-component-ld")) {
+CmdArgs.push_back("--wasm-ld-path");
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetProgramPath("wasm-ld")));
+  }
+
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
 
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
@@ -221,6 +238,12 @@ WebAssembly::WebAssembly(const Driver , const 
llvm::Triple ,
   }
 }
 
+const char *WebAssembly::getDefaultLinker() const {
+  if (getOS() == "wasip2")
+return "wasm-component-ld";
+  return "wasm-ld";
+}
+
 bool WebAssembly::IsMathErrnoDefault() const { return false; }
 
 bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; }

diff  --git a/clang/lib/Driver/ToolChains/WebAssembly.h 
b/clang/lib/Driver/ToolChains/WebAssembly.h
index ae60f464c10818..76e0ca39bd748d 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.h
+++ b/clang/lib/Driver/ToolChains/WebAssembly.h
@@ -67,7 +67,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly final : public 
ToolChain {
llvm::opt::ArgStringList ) const override;
   SanitizerMask getSupportedSanitizers() const override;
 
-  const char *getDefaultLinker() const override { return "wasm-ld"; }
+  const char *getDefaultLinker() const override;
 
   CXXStdlibType GetDefaultCXXStdlibType() const override {
 return ToolChain::CST_Libcxx;

diff  --git a/clang/test/Driver/wasm-toolchain.c 
b/clang/test/Driver/wasm-toolchain.c
index f950283ec42aa0..88590a3ba4c453 100644
--- a/clang/test/Driver/wasm-toolchain.c
+++ b/clang/test/Driver/wasm-toolchain.c
@@ -197,3 +197,27 @@
 // RUN: not %clang -### %s --target=wasm32-unknown-unknown 
--sysroot=%s/no-sysroot-there -fPIC -mno-mutable-globals %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=PIC_NO_MUTABLE_GLOBALS %s
 // PIC_NO_MUTABLE_GLOBALS: error: invalid argument '-fPIC' not allowed with 
'-mno-mutable-globals'
+
+// Test that `wasm32-wasip2` invokes the `wasm-component-ld` linker by default
+// instead of `wasm-ld`.
+
+// RUN: %clang -### -O2 --target=wasm32-wasip2 %s --sysroot /foo 2>&1 \
+// RUN:   | FileCheck -check-prefix=LINK_WASIP2 %s
+// LINK_WASIP2: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// LINK_WASIP2: wasm-component-ld{{.*}}" 

[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-18 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/85565

>From b286dcfb2ae59d650e6b49fee97f159e2e958dcc Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 17 Mar 2024 17:48:05 +0800
Subject: [PATCH] [Clang][Sema] Fix a crash in lambda instantiation

---
 clang/docs/ReleaseNotes.rst|  1 +
 clang/lib/Sema/TreeTransform.h | 10 ++
 clang/test/Sema/PR85343.cpp| 22 ++
 3 files changed, 33 insertions(+)
 create mode 100644 clang/test/Sema/PR85343.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 125d51c42d507f..a446fd203e0f8c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -394,6 +394,7 @@ Bug Fixes to C++ Support
   expression references to an entity declared outside of the lambda. (#GH64808)
 - Clang's __builtin_bit_cast will now produce a constant value for records 
with empty bases. See:
   (#GH82383)
+- Fix a crash when instantiating a lambda that captures ``this`` outside of 
its context. Fixes (#GH85343).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 2d22692f3ab750..f2f7d7ab9c7c38 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13714,6 +13714,16 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 
 // Capturing 'this' is trivial.
 if (C->capturesThis()) {
+  // If this is a lambda that is part of a default member initialiser
+  // and which we're instantiating outside the class that 'this' is
+  // supposed to refer to, adjust the type of 'this' accordingly.
+  //
+  // Otherwise, leave the type of 'this' as-is.
+  Sema::CXXThisScopeRAII ThisScope(
+  getSema(),
+  dyn_cast_if_present(
+  getSema().getFunctionLevelDeclContext()),
+  Qualifiers());
   getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
 /*BuildAndDiagnose*/ true, nullptr,
 C->getCaptureKind() == LCK_StarThis);
diff --git a/clang/test/Sema/PR85343.cpp b/clang/test/Sema/PR85343.cpp
new file mode 100644
index 00..d90ef19d423455
--- /dev/null
+++ b/clang/test/Sema/PR85343.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++14 -verify %s
+// expected-no-diagnostics
+
+template  auto ab() -> c ;
+
+template  struct e {};
+
+template  struct ac {
+  template  static e()(ab))> i;
+  decltype(i) j;
+};
+
+struct d {
+  template 
+  d(f) { 
+ac a;
+  }
+};
+struct a {
+  d b = [=](auto) { (void)[this] {}; };
+};
+void b() { new a; }

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


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Kees Cook via cfe-commits


@@ -1,13 +1,158 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
-// RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c -fsyntax-only
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -x c++
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c,gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=stock,c,microsoft -fsyntax-only 
-fms-compatibility -Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}
+microsoft-warning {{flexible array member 'x' 
in a union is a Microsoft extension}}
+  */
+struct _name1 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1 = {
+  10,
+  42,/* initializes "b" */
+};
 
-// expected-no-diagnostics
+struct _name1i {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1i = {
+  .a = 10,
+  .b = 42,
+};
+
+/* Initialization of flexible array in a union is never allowed. */
+struct _name2 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+ stock-note {{initialized flexible array member 'x' is here}}
+   */
+  };
+} name2 = {
+  12,
+  13,
+  { 'c' },   /* stock-error {{initialization of flexible array member is not 
allowed}} */

kees wrote:

I was surprised by this too, especially since using named initializers does 
produce a useful warning. Improving this message seems out of scope for this 
PR, though, yes?

https://github.com/llvm/llvm-project/pull/84428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Kees Cook via cfe-commits


@@ -1,13 +1,158 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
-// RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c -fsyntax-only
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -x c++
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c,gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=stock,c,microsoft -fsyntax-only 
-fms-compatibility -Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}
+microsoft-warning {{flexible array member 'x' 
in a union is a Microsoft extension}}
+  */
+struct _name1 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1 = {
+  10,
+  42,/* initializes "b" */
+};
 
-// expected-no-diagnostics
+struct _name1i {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1i = {
+  .a = 10,
+  .b = 42,
+};
+
+/* Initialization of flexible array in a union is never allowed. */
+struct _name2 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+ stock-note {{initialized flexible array member 'x' is here}}
+   */
+  };
+} name2 = {
+  12,
+  13,
+  { 'c' },   /* stock-error {{initialization of flexible array member is not 
allowed}} */
+};
+
+/* Initialization of flexible array in a union is never allowed. */
+struct _name2i {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+ stock-note {{initialized flexible array member 'x' is here}}
+   */
+  };
+} name2i = {
+  .a = 12,
+  .b = 13,  /* stock-note {{previous initialization is here}} */
+  .x = { 'c' }, /* stock-error {{initialization of flexible array member is 
not allowed}}
+   c-warning {{initializer overrides prior initialization of 
this subobject}}
+   cpp-error {{initializer partially overrides prior 
initialization of this subobject}}
+ */
+};
+
+/* Flexible array initialization always allowed when not in a union,
+   and when struct has another member.
+ */
+struct _okay {
+  int a;
+  char x[];
+} okay = {
+  22,
+  { 'x', 'y', 'z' },
+};
+
+struct _okayi {
+  int a;
+  char x[];
+} okayi = {
+  .a = 22,
+  .x = { 'x', 'y', 'z' },
+};
+
+struct _okay0 {
+  int a;
+  char x[];
+} okay0 = { };
+
+struct _flex_extension {
+  char x[]; /* gnu-warning {{flexible array member 'x' in otherwise empty 
struct is a GNU extension}}
+   microsoft-warning {{flexible array member 'x' in otherwise 
empty struct is a Microsoft extension}}
+ */
+} flex_extension = {
+  { 'x', 'y', 'z' },
+};
+
+struct _flex_extensioni {
+  char x[]; /* gnu-warning {{flexible array member 'x' in otherwise empty 
struct is a GNU extension}}
+   microsoft-warning {{flexible array member 'x' in otherwise 
empty struct is a Microsoft extension}}
+ */
+} flex_extensioni = {
+  .x = { 'x', 'y', 'z' },
+};
 
+struct already_hidden {
+  int a;
+  union {
+int b;
+struct {
+  struct { } __empty;  // gnu-warning {{empty struct is a GNU extension}}
+  char x[];
+};
+  };
+};
+
+struct still_zero_sized {
+  struct { } __unused;  // gnu-warning {{empty struct is a GNU extension}}
+  int x[];
+};
+
+struct warn1 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+};
+
+struct warn2 {
+  int x[];  /* gnu-warning {{flexible array member 'x' in otherwise empty 
struct is a GNU extension}}
+   microsoft-warning {{flexible array member 'x' in otherwise 
empty 

[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-03-18 Thread via cfe-commits


@@ -6375,12 +6383,16 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   ImmediateCallVisitor V(getASTContext());
   if (!NestedDefaultChecking)
 V.TraverseDecl(Field);
-  if (V.HasImmediateCalls) {
+  if (V.HasImmediateCalls || InLifetimeExtendingContext) {
 ExprEvalContexts.back().DelayedDefaultInitializationContext = {Loc, Field,
CurContext};
 ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
 NestedDefaultChecking;
 
+// Pass down lifetime extending flag, and collect temporaries in
+// CreateMaterializeTemporaryExpr when we rewrite the call argument.
+keepInLifetimeExtendingContext();
+keepInMaterializeTemporaryObjectContext();

yronglin wrote:

Many thanks for your information.

https://github.com/llvm/llvm-project/pull/76361
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -0,0 +1,24 @@
+/// attribute parsing error cases.
+
+// RUN: not llvm-mc -triple=hexagon -filetype=asm %s 2>&1 \
+// RUN:   | FileCheck %s
+
+  .attribute Tag_unknown_name, 0
+// CHECK: error: attribute name not recognized: Tag_unknown_name

quic-areg wrote:

Done

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -251,7 +251,10 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t 
Machine, unsigned Type) {
 }
 break;
   case ELF::EM_HEXAGON:
-switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_HEX_ORDERED); }
+switch (Type) {
+  STRINGIFY_ENUM_CASE(ELF, SHT_HEX_ORDERED);

quic-areg wrote:

Added 

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -0,0 +1,20 @@
+/// Enabled by default for assembly
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Can be forced on or off for assembly.
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mno-default-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mdefault-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Option ignored C/C++ (since we always emit hardware and ABI build 
attributes
+/// during codegen).
+// RUN: %clang -target hexagon-unknown-elf -### -x c %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### -x c++ %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+
+// CHECK-DISABLED-NOT: "-hexagon-add-build-attributes"
+// CHECK-ENABLED: "-hexagon-add-build-attributes"
+// expected-warning {{argument unused during compilation: 
'-mno-default-build-attributes'}}

quic-areg wrote:

Changed

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -395,7 +396,8 @@ template  class ELFObjectFile : public 
ELFObjectFileBase {
 
 for (const Elf_Shdr  : *SectionsOrErr) {
   if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES ||
-  Sec.sh_type == ELF::SHT_RISCV_ATTRIBUTES) {
+  Sec.sh_type == ELF::SHT_RISCV_ATTRIBUTES ||

quic-areg wrote:

Done

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -652,6 +660,57 @@ bool HexagonAsmParser::MatchAndEmitInstruction(SMLoc 
IDLoc, unsigned ,
 return finishBundle(IDLoc, Out);
   return false;
 }
+/// parseDirectiveAttribute
+///  ::= .attribute int, int
+///  ::= .attribute Tag_name, int
+bool HexagonAsmParser::parseDirectiveAttribute(SMLoc L) {
+  MCAsmParser  = getParser();
+  int64_t Tag;
+  SMLoc TagLoc = Parser.getTok().getLoc();
+  if (Parser.getTok().is(AsmToken::Identifier)) {
+StringRef Name = Parser.getTok().getIdentifier();
+std::optional Ret = ELFAttrs::attrTypeFromString(
+Name, HexagonAttrs::getHexagonAttributeTags());
+if (!Ret)
+  return Error(TagLoc, "attribute name not recognized: " + Name);
+Tag = *Ret;
+Parser.Lex();
+  } else {
+const MCExpr *AttrExpr;
+
+TagLoc = Parser.getTok().getLoc();
+if (Parser.parseExpression(AttrExpr))
+  return true;
+
+const MCConstantExpr *CE = dyn_cast(AttrExpr);
+if (check(!CE, TagLoc, "expected numeric constant"))
+  return true;
+
+Tag = CE->getValue();
+  }
+
+  if (Parser.parseComma())
+return true;
+
+  // We currently only have integer values.
+  int64_t IntegerValue = 0;
+  SMLoc ValueExprLoc = Parser.getTok().getLoc();
+  const MCExpr *ValueExpr;
+  if (Parser.parseExpression(ValueExpr))
+return true;
+
+  const MCConstantExpr *CE = dyn_cast(ValueExpr);
+  if (!CE)
+return Error(ValueExprLoc, "expected numeric constant");
+  IntegerValue = CE->getValue();
+
+  if (Parser.parseEOL())
+return true;
+
+  getTargetStreamer().emitAttribute(Tag, IntegerValue);
+

quic-areg wrote:

Removed

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

2024-03-18 Thread Craig Topper via cfe-commits


@@ -244,6 +249,42 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 };
 // clang-format on
 
+static const RISCVProfile SupportedProfiles[] = {

topperc wrote:

`const` -> `constexpr` to be sure the StringLiteral constexpr constructor gets 
invoked.

https://github.com/llvm/llvm-project/pull/76357
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -79,7 +80,8 @@ static cl::opt ErrorNoncontigiousRegister(
 "merror-noncontigious-register",
 cl::desc("Error for register names that aren't contigious"),
 cl::init(false));
-
+static cl::opt AddBuildAttributes("hexagon-add-build-attributes",
+cl::init(false));

quic-areg wrote:

Removed

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -0,0 +1,20 @@
+/// Enabled by default for assembly
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 \

quic-areg wrote:

Done

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits

https://github.com/quic-areg updated 
https://github.com/llvm/llvm-project/pull/85359

>From 997c2741ce4ca85e5e23d7e73b6894fd07b79b8d Mon Sep 17 00:00:00 2001
From: quic-areg 
Date: Thu, 14 Mar 2024 20:31:37 -0700
Subject: [PATCH 1/3] [Hexagon] ELF attributes for Hexagon

Defines a subset of attributes and emits them to a section called
.hexagon.attributes.

The current attributes recorded are the attributes needed by
llvm-objdump to automatically determine target features and eliminate
the need to manually pass features.
---
 clang/lib/Driver/ToolChains/Clang.cpp |  8 ++
 .../Driver/hexagon-default-build-attributes.s | 20 
 llvm/include/llvm/BinaryFormat/ELF.h  |  2 +
 llvm/include/llvm/Object/ELFObjectFile.h  |  1 +
 .../llvm/Support/HexagonAttributeParser.h | 36 +++
 llvm/include/llvm/Support/HexagonAttributes.h | 32 +++
 llvm/lib/Object/ELF.cpp   |  5 +-
 llvm/lib/Object/ELFObjectFile.cpp | 78 +++
 llvm/lib/ObjectYAML/ELFYAML.cpp   |  1 +
 llvm/lib/Support/CMakeLists.txt   |  2 +
 llvm/lib/Support/HexagonAttributeParser.cpp   | 55 +++
 llvm/lib/Support/HexagonAttributes.cpp| 27 ++
 .../Hexagon/AsmParser/HexagonAsmParser.cpp| 63 -
 llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp | 20 
 llvm/lib/Target/Hexagon/HexagonAsmPrinter.h   |  4 +
 .../Target/Hexagon/HexagonTargetStreamer.h|  9 ++
 .../MCTargetDesc/HexagonMCELFStreamer.cpp | 61 
 .../MCTargetDesc/HexagonMCTargetDesc.cpp  | 72 --
 .../MCTargetDesc/HexagonMCTargetDesc.h|  6 +-
 llvm/test/CodeGen/Hexagon/build-attributes.ll | 16 
 .../test/MC/Hexagon/directive-attribute-err.s | 24 +
 llvm/test/MC/Hexagon/directive-attribute.s| 41 
 llvm/test/MC/Hexagon/hexagon_attributes.s | 94 +++
 llvm/tools/llvm-readobj/ELFDumper.cpp |  6 ++
 24 files changed, 674 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/Driver/hexagon-default-build-attributes.s
 create mode 100644 llvm/include/llvm/Support/HexagonAttributeParser.h
 create mode 100644 llvm/include/llvm/Support/HexagonAttributes.h
 create mode 100644 llvm/lib/Support/HexagonAttributeParser.cpp
 create mode 100644 llvm/lib/Support/HexagonAttributes.cpp
 create mode 100644 llvm/test/CodeGen/Hexagon/build-attributes.ll
 create mode 100644 llvm/test/MC/Hexagon/directive-attribute-err.s
 create mode 100644 llvm/test/MC/Hexagon/directive-attribute.s
 create mode 100644 llvm/test/MC/Hexagon/hexagon_attributes.s

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 055884d275ce1b..bcdf2737bc7ae0 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8481,6 +8481,14 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);
 break;
+
+  case llvm::Triple::hexagon:
+if (Args.hasFlag(options::OPT_mdefault_build_attributes,
+ options::OPT_mno_default_build_attributes, true)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-hexagon-add-build-attributes");
+}
+break;
   }
 
   // Consume all the warning flags. Usually this would be handled more
diff --git a/clang/test/Driver/hexagon-default-build-attributes.s 
b/clang/test/Driver/hexagon-default-build-attributes.s
new file mode 100644
index 00..b83181d6d52e01
--- /dev/null
+++ b/clang/test/Driver/hexagon-default-build-attributes.s
@@ -0,0 +1,20 @@
+/// Enabled by default for assembly
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Can be forced on or off for assembly.
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mno-default-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mdefault-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Option ignored C/C++ (since we always emit hardware and ABI build 
attributes
+/// during codegen).
+// RUN: %clang -target hexagon-unknown-elf -### -x c %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### -x c++ %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+
+// CHECK-DISABLED-NOT: "-hexagon-add-build-attributes"
+// CHECK-ENABLED: "-hexagon-add-build-attributes"
+// expected-warning {{argument unused during compilation: 
'-mno-default-build-attributes'}}
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h 
b/llvm/include/llvm/BinaryFormat/ELF.h
index bace3a92677a82..877f3f7862c8ba 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1141,6 +1141,8 @@ enum : unsigned {
 
   SHT_CSKY_ATTRIBUTES = 

[clang] [NFC] Refactor ConstantArrayType size storage (PR #85716)

2024-03-18 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 4841858862df4b8ac4ac68922086f03c8bbd3dc2 
4a11a73b4dd41637b1d730489954c2994489d6be -- clang/include/clang/AST/Type.h 
clang/lib/AST/ASTContext.cpp clang/lib/AST/Decl.cpp 
clang/lib/AST/ExprConstant.cpp clang/lib/AST/Interp/ByteCodeExprGen.cpp 
clang/lib/AST/Interp/EvaluationResult.cpp clang/lib/AST/Interp/Program.cpp 
clang/lib/AST/JSONNodeDumper.cpp clang/lib/AST/MicrosoftMangle.cpp 
clang/lib/AST/ScanfFormatString.cpp clang/lib/AST/Type.cpp 
clang/lib/AST/TypePrinter.cpp clang/lib/Analysis/CFG.cpp 
clang/lib/Analysis/UnsafeBufferUsage.cpp clang/lib/CodeGen/ABIInfo.cpp 
clang/lib/CodeGen/ABIInfoImpl.cpp clang/lib/CodeGen/CGCall.cpp 
clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGExprCXX.cpp 
clang/lib/CodeGen/CGExprConstant.cpp clang/lib/CodeGen/CGObjCMac.cpp 
clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/CodeGen/CodeGenFunction.cpp 
clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenTypes.cpp 
clang/lib/CodeGen/SwiftCallingConv.cpp clang/lib/CodeGen/Targets/ARM.cpp 
clang/lib/CodeGen/Targets/LoongArch.cpp clang/lib/CodeGen/Targets/RISCV.cpp 
clang/lib/CodeGen/Targets/X86.cpp clang/lib/Sema/SemaChecking.cpp 
clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp 
clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp 
clang/lib/Sema/SemaInit.cpp clang/lib/Sema/SemaOpenMP.cpp 
clang/lib/Sema/SemaSYCL.cpp 
clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp 
clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp 
clang/lib/StaticAnalyzer/Core/MemRegion.cpp 
clang/lib/StaticAnalyzer/Core/RegionStore.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index f8739fd54f..f7d7b7f577 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3181,8 +3181,7 @@ public:
 /// Represents the canonical version of C arrays with a specified constant 
size.
 /// For example, the canonical type for 'int A[4 + 4*100]' is a
 /// ConstantArrayType where the element type is 'int' and the size is 404.
-class ConstantArrayType final
-: public ArrayType {
+class ConstantArrayType final : public ArrayType {
   friend class ASTContext; // ASTContext creates these.
 
   struct ExternalSize {
@@ -3242,21 +3241,19 @@ public:
   /// Return true if the size is zero.
   bool isZeroSize() const {
 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.isZero()
-   : 0 == I.Size;
+ : 0 == I.Size;
   }
 
   /// Return the size zero-extended as a uint64_t.
   uint64_t getZExtSize() const {
-return ConstantArrayTypeBits.HasExternalSize
-   ? SizePtr->Size.getZExtValue()
-   : I.Size;
+return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getZExtValue()
+ : I.Size;
   }
 
   /// Return the size zero-extended as a uint64_t.
   int64_t getSExtSize() const {
-return ConstantArrayTypeBits.HasExternalSize
-   ? SizePtr->Size.getSExtValue()
-   : static_cast(I.Size);
+return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getSExtValue()
+ : 
static_cast(I.Size);
   }
 
   /// Return the size zero-extended to uint64_t or UINT64_MAX if the value is
@@ -3269,9 +3266,7 @@ public:
 
   /// Return a pointer to the size expression.
   const Expr *getSizeExpr() const {
-return ConstantArrayTypeBits.HasExternalSize
-   ? SizePtr->SizeExpr
-   : nullptr;
+return ConstantArrayTypeBits.HasExternalSize ? SizePtr->SizeExpr : nullptr;
   }
 
   bool isSugared() const { return false; }
@@ -3295,9 +3290,8 @@ public:
   }
 
   static void Profile(llvm::FoldingSetNodeID , const ASTContext ,
-  QualType ET, uint64_t ArraySize,
-  const Expr *SizeExpr, ArraySizeModifier SizeMod,
-  unsigned TypeQuals);
+  QualType ET, uint64_t ArraySize, const Expr *SizeExpr,
+  ArraySizeModifier SizeMod, unsigned TypeQuals);
 
   static bool classof(const Type *T) {
 return T->getTypeClass() == ConstantArray;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7889dc00e5..c5bdff0df0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10996,8 +10996,7 @@ namespace {
 return Error(E);
   }
 
-  Result = APValue(APValue::UninitArray(), 0,
-   CAT->getZExtSize());
+  Result = APValue(APValue::UninitArray(), 0, CAT->getZExtSize());
   if (!Result.hasArrayFiller())
 return true;
 
diff --git 

[clang] [NFC] Refactor ConstantArrayType size storage (PR #85716)

2024-03-18 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-analysis
@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-backend-arm

Author: Chris B (llvm-beanz)


Changes

In PR #79382, I need to add a new type that derives from 
ConstantArrayType. This means that ConstantArrayType can no longer use 
`llvm::TrailingObjects` to store the trailing optional Expr*.

This change refactors ConstantArrayType to store a 60-bit integer and 4-bits 
for the integer size in bytes. This replaces the APInt field previously in the 
type but preserves enough information to recreate it where needed.

To reduce the number of places where the APInt is re-constructed I've also 
added some helper methods to the ConstantArrayType to allow some common use 
cases that operate on either the stored small integer or the APInt as 
appropriate.

Resolves #85124.

---

Patch is 55.62 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/85716.diff


42 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+84-20) 
- (modified) clang/lib/AST/ASTContext.cpp (+9-12) 
- (modified) clang/lib/AST/Decl.cpp (+1-1) 
- (modified) clang/lib/AST/ExprConstant.cpp (+15-15) 
- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+4-4) 
- (modified) clang/lib/AST/Interp/EvaluationResult.cpp (+1-1) 
- (modified) clang/lib/AST/Interp/Program.cpp (+1-1) 
- (modified) clang/lib/AST/JSONNodeDumper.cpp (+1-1) 
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+1-2) 
- (modified) clang/lib/AST/ScanfFormatString.cpp (+1-1) 
- (modified) clang/lib/AST/Type.cpp (+18-2) 
- (modified) clang/lib/AST/TypePrinter.cpp (+1-1) 
- (modified) clang/lib/Analysis/CFG.cpp (+2-2) 
- (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+4-4) 
- (modified) clang/lib/CodeGen/ABIInfo.cpp (+2-2) 
- (modified) clang/lib/CodeGen/ABIInfoImpl.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGExprCXX.cpp (+2-4) 
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+4-4) 
- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+3-3) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+1-1) 
- (modified) clang/lib/CodeGen/SwiftCallingConv.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/ARM.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/LoongArch.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/X86.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+4-4) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaInit.cpp (+10-10) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaSYCL.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/MemRegion.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/RegionStore.cpp (+4-4) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 10916053cdfbf5..f8739fd54f33d1 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1689,7 +1689,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 
 /// Whether we have a stored size expression.
 LLVM_PREFERRED_TYPE(bool)
-unsigned HasStoredSizeExpr : 1;
+unsigned HasExternalSize : 1;
   };
 
   class BuiltinTypeBitfields {
@@ -3182,34 +3182,98 @@ class ArrayType : public Type, public 
llvm::FoldingSetNode {
 /// For example, the canonical type for 'int A[4 + 4*100]' is a
 /// ConstantArrayType where the element type is 'int' and the size is 404.
 class ConstantArrayType final
-: public ArrayType,
-  private llvm::TrailingObjects {
+: public ArrayType {
   friend class ASTContext; // ASTContext creates these.
-  friend TrailingObjects;
 
-  llvm::APInt Size; // Allows us to unique the type.
+  struct ExternalSize {
+ExternalSize(const llvm::APInt , const Expr *SE)
+: Size(Sz), SizeExpr(SE) {}
+llvm::APInt Size; // Allows us to unique the type.
+const Expr *SizeExpr;
+  };
+  struct InlineSize {
+InlineSize(uint64_t TSz, uint64_t Sz) : ByteWidth(TSz), Size(Sz) {}
+uint64_t ByteWidth : 4;
+uint64_t Size : 60;
+  };
+  union {
+struct InlineSize I;
+ExternalSize *SizePtr;
+  };
 
-  ConstantArrayType(QualType et, QualType can, const llvm::APInt ,
-const Expr *sz, ArraySizeModifier sm, unsigned tq)
-  : ArrayType(ConstantArray, et, can, sm, tq, sz), Size(size) {
-ConstantArrayTypeBits.HasStoredSizeExpr = 

[clang] [NFC] Refactor ConstantArrayType size storage (PR #85716)

2024-03-18 Thread Chris B via cfe-commits

https://github.com/llvm-beanz created 
https://github.com/llvm/llvm-project/pull/85716

In PR #79382, I need to add a new type that derives from ConstantArrayType. 
This means that ConstantArrayType can no longer use `llvm::TrailingObjects` to 
store the trailing optional Expr*.

This change refactors ConstantArrayType to store a 60-bit integer and 4-bits 
for the integer size in bytes. This replaces the APInt field previously in the 
type but preserves enough information to recreate it where needed.

To reduce the number of places where the APInt is re-constructed I've also 
added some helper methods to the ConstantArrayType to allow some common use 
cases that operate on either the stored small integer or the APInt as 
appropriate.

Resolves #85124.

>From 4a11a73b4dd41637b1d730489954c2994489d6be Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Mon, 18 Mar 2024 17:30:41 -0500
Subject: [PATCH] [NFC] Refactor ConstantArrayType size storage

In PR #79382, I need to add a new type that derives from
ConstantArrayType. This means that ConstantArrayType can no longer use
`llvm::TrailingObjects` to store the trailing optional Expr*.

This change refactors ConstantArrayType to store a 60-bit integer and
4-bits for the integer size in bytes. This replaces the APInt field
previously in the type but preserves enough information to recreate it
where needed.

To reduce the number of places where the APInt is re-constructed I've
also added some helper methods to the ConstantArrayType to allow some
common use cases that operate on either the stored small integer or the
APInt as appropriate.

Resolves #85124.
---
 clang/include/clang/AST/Type.h| 104 ++
 clang/lib/AST/ASTContext.cpp  |  21 ++--
 clang/lib/AST/Decl.cpp|   2 +-
 clang/lib/AST/ExprConstant.cpp|  30 ++---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp  |   8 +-
 clang/lib/AST/Interp/EvaluationResult.cpp |   2 +-
 clang/lib/AST/Interp/Program.cpp  |   2 +-
 clang/lib/AST/JSONNodeDumper.cpp  |   2 +-
 clang/lib/AST/MicrosoftMangle.cpp |   3 +-
 clang/lib/AST/ScanfFormatString.cpp   |   2 +-
 clang/lib/AST/Type.cpp|  20 +++-
 clang/lib/AST/TypePrinter.cpp |   2 +-
 clang/lib/Analysis/CFG.cpp|   4 +-
 clang/lib/Analysis/UnsafeBufferUsage.cpp  |   8 +-
 clang/lib/CodeGen/ABIInfo.cpp |   4 +-
 clang/lib/CodeGen/ABIInfoImpl.cpp |   4 +-
 clang/lib/CodeGen/CGCall.cpp  |   4 +-
 clang/lib/CodeGen/CGDebugInfo.cpp |   2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   |   6 +-
 clang/lib/CodeGen/CGExprConstant.cpp  |   8 +-
 clang/lib/CodeGen/CGObjCMac.cpp   |   6 +-
 clang/lib/CodeGen/CGOpenMPRuntime.cpp |   4 +-
 clang/lib/CodeGen/CodeGenFunction.cpp |   4 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |   2 +-
 clang/lib/CodeGen/CodeGenTypes.cpp|   2 +-
 clang/lib/CodeGen/SwiftCallingConv.cpp|   2 +-
 clang/lib/CodeGen/Targets/ARM.cpp |   2 +-
 clang/lib/CodeGen/Targets/LoongArch.cpp   |   2 +-
 clang/lib/CodeGen/Targets/RISCV.cpp   |   2 +-
 clang/lib/CodeGen/Targets/X86.cpp |   4 +-
 clang/lib/Sema/SemaChecking.cpp   |   8 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   2 +-
 clang/lib/Sema/SemaExpr.cpp   |   4 +-
 clang/lib/Sema/SemaExprCXX.cpp|   2 +-
 clang/lib/Sema/SemaInit.cpp   |  20 ++--
 clang/lib/Sema/SemaOpenMP.cpp |   6 +-
 clang/lib/Sema/SemaSYCL.cpp   |   2 +-
 .../Checkers/CastSizeChecker.cpp  |   2 +-
 .../Checkers/PaddingChecker.cpp   |   2 +-
 clang/lib/StaticAnalyzer/Core/MemRegion.cpp   |   2 +-
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp |   8 +-
 42 files changed, 201 insertions(+), 127 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 10916053cdfbf5..f8739fd54f33d1 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1689,7 +1689,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 
 /// Whether we have a stored size expression.
 LLVM_PREFERRED_TYPE(bool)
-unsigned HasStoredSizeExpr : 1;
+unsigned HasExternalSize : 1;
   };
 
   class BuiltinTypeBitfields {
@@ -3182,34 +3182,98 @@ class ArrayType : public Type, public 
llvm::FoldingSetNode {
 /// For example, the canonical type for 'int A[4 + 4*100]' is a
 /// ConstantArrayType where the element type is 'int' and the size is 404.
 class ConstantArrayType final
-: public ArrayType,
-  private llvm::TrailingObjects {
+: public ArrayType {
   friend class ASTContext; // ASTContext creates these.
-  friend TrailingObjects;
 
-  llvm::APInt 

[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -3424,6 +3445,26 @@ llvm::DIMacroFile 
*CGDebugInfo::CreateTempMacroFile(llvm::DIMacroFile *Parent,
   return DBuilder.createTempMacroFile(Parent, Line, FName);
 }
 
+llvm::DILocation *CGDebugInfo::CreateTrapFailureMessageFor(

delcypher wrote:

@dwblaikie We currently use this function for `-fbounds-safety` internally. We 
are currently in the process of upstreaming this which is why the function 
should **not** hardcode the `Prefix`.

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits

https://github.com/delcypher deleted 
https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -std=c++20 -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s

delcypher wrote:

@ahatanak Any follow up?

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -602,6 +613,19 @@ class CGDebugInfo {
 return CoroutineParameterMappings;
   }
 
+  // Create a debug location from `TrapLocation` that adds an artificial inline
+  // frame where the frame name is
+  //
+  // * `: ` if `` is not empty.
+  // * `` if `` is empty. Note `` must
+  //   contain a space.
+  //
+  // Currently `` is always "__llvm_verbose_trap".
+  //
+  // This is used to store failure reasons for traps.

delcypher wrote:

@ahatanak Any follow up?

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -346,6 +348,15 @@ class CGDebugInfo {
   const FieldDecl *BitFieldDecl, const llvm::DIDerivedType *BitFieldDI,
   llvm::ArrayRef PreviousFieldsDI, const RecordDecl *RD);
 
+  // A cache that maps artificial inlined function names used for
+  // __builtin_verbose_trap to subprograms.

delcypher wrote:

@ahatanak Any follow up?

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -346,6 +348,15 @@ class CGDebugInfo {
   const FieldDecl *BitFieldDecl, const llvm::DIDerivedType *BitFieldDI,
   llvm::ArrayRef PreviousFieldsDI, const RecordDecl *RD);
 
+  // A cache that maps artificial inlined function names used for
+  // __builtin_verbose_trap to subprograms.
+  llvm::StringMap InlinedTrapFuncMap;
+
+  // A function that returns the subprogram corresponding to the artificial
+  // inlined function for traps.

delcypher wrote:

@ahatanak Any follow up?

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -3379,6 +3379,54 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_verbose_trap``
+--
+
+``__builtin_verbose_trap`` causes the program to stop its execution abnormally
+and shows a human-readable description of the reason for the termination when a
+debugger is attached or in a symbolicated crash log.
+
+**Syntax**:
+
+.. code-block:: c++
+
+__builtin_verbose_trap(const char *reason)
+
+**Description**
+
+``__builtin_verbose_trap`` is lowered to the ` ``llvm.trap`` 
`_ builtin.
+Additionally, clang emits debug metadata that represents an artificial inline
+frame whose name encodes the string passed to the builtin, prefixed by a 
"magic"
+prefix.
+
+For example, consider the following code:
+
+.. code-block:: c++
+
+void foo(int* p) {
+  if (p == nullptr)
+__builtin_verbose_trap("Argument_must_not_be_null");
+}
+
+The debug metadata would look as if it were produced for the following code:
+
+.. code-block:: c++
+
+__attribute__((always_inline))
+inline void "__llvm_verbose_trap: Argument_must_not_be_null"() {
+  __builtin_trap();
+}
+
+void foo(int* p) {
+  if (p == nullptr)
+"__llvm_verbose_trap: Argument_must_not_be_null"();
+}
+
+However, the LLVM IR would not actually contain a call to the artificial
+function — it only exists in the debug metadata.

delcypher wrote:

@ahatanak Any follow up?

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -3379,6 +3379,60 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_verbose_trap``
+--
+
+``__builtin_verbose_trap`` causes the program to stop its execution abnormally
+and shows a human-readable description of the reason for the termination when a
+debugger is attached or in a symbolicated crash log.
+
+**Syntax**:
+
+.. code-block:: c++
+
+__builtin_verbose_trap(const char *reason)
+
+**Description**
+
+``__builtin_verbose_trap`` is lowered to the ` ``llvm.trap`` 
`_ builtin.
+Additionally, clang emits debugging information that represents an artificial
+inline frame whose name encodes the string passed to the builtin, prefixed by a
+"magic" prefix.
+
+For example, consider the following code:
+
+.. code-block:: c++
+
+void foo(int* p) {
+  if (p == nullptr)
+__builtin_verbose_trap("Argument must not be null!");
+}
+
+The debugging information would look as if it were produced for the following 
code:
+
+.. code-block:: c++
+
+__attribute__((always_inline))
+inline void "__llvm_verbose_trap: Argument must not be null!"() {
+  __builtin_trap();
+}
+
+void foo(int* p) {
+  if (p == nullptr)
+"__llvm_verbose_trap: Argument must not be null!"();
+}
+
+However, the LLVM IR would not actually contain a call to the artificial

delcypher wrote:

```suggestion
However, the generated code would not actually contain a call to the artificial
```

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -3379,6 +3379,57 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_verbose_trap``
+--
+
+``__builtin_verbose_trap`` causes the program to stop its execution abnormally
+and shows a human-readable description of the reason for the termination when a
+debugger is attached or in a symbolicated crash log.
+
+**Syntax**:
+
+.. code-block:: c++
+
+__builtin_verbose_trap(const char *reason)
+
+**Description**
+
+``__builtin_verbose_trap`` is lowered to the ` ``llvm.trap`` 
`_ builtin.
+Additionally, clang emits debugging information that represents an artificial
+inline frame whose name encodes the string passed to the builtin, prefixed by a
+"magic" prefix.

delcypher wrote:

@ahatanak Any follow up?

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s
+
+#if !__has_builtin(__builtin_verbose_trap)
+#error
+#endif
+
+constexpr char const* constMsg1 = "hello";
+char const* const constMsg2 = "hello";
+char const constMsg3[] = "hello";
+
+template 
+void f(const char * arg) {
+  __builtin_verbose_trap("Argument_must_not_be_null");

delcypher wrote:

As long as the compiler isn't imposing an artificial limit then that seems fine 
to me.

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits

https://github.com/delcypher edited 
https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits

https://github.com/delcypher requested changes to this pull request.

It looks like there are still some unresolved discussions in this PR.

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -3424,6 +3447,24 @@ llvm::DIMacroFile 
*CGDebugInfo::CreateTempMacroFile(llvm::DIMacroFile *Parent,
   return DBuilder.createTempMacroFile(Parent, Line, FName);
 }
 
+llvm::DILocation *
+CGDebugInfo::CreateTrapFailureMessageFor(llvm::DebugLoc TrapLocation,
+ StringRef FailureMsg) {
+  // Create a debug location from `TrapLocation` that adds an artificial inline
+  // frame.
+  const char *Prefix = CLANG_VERBOSE_TRAP_PREFIX;

delcypher wrote:

The `Prefix` should not be hardcoded. It should be a parameter to 
`CreateTrapFailureMessageFor` so it can be re-used by other things like 
`-fbounds-safety`

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -3452,6 +3452,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_trap:
 EmitTrapCall(Intrinsic::trap);
 return RValue::get(nullptr);
+  case Builtin::BI__builtin_verbose_trap: {
+llvm::DILocation *TrapLocation = Builder.getCurrentDebugLocation();
+if (getDebugInfo()) {
+  std::string Str;
+  E->getArg(0)->tryEvaluateString(Str, getContext());
+  TrapLocation =
+  getDebugInfo()->CreateTrapFailureMessageFor(TrapLocation, Str);
+}
+ApplyDebugLocation ApplyTrapDI(*this, TrapLocation);
+EmitTrapCall(Intrinsic::trap);

delcypher wrote:

Please leave a comment in the code indicating that currently no attempt is made 
to prevent traps being merged.

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Eli Friedman via cfe-commits


@@ -1,13 +1,158 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
-// RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c -fsyntax-only
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -x c++
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c,gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=stock,c,microsoft -fsyntax-only 
-fms-compatibility -Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}
+microsoft-warning {{flexible array member 'x' 
in a union is a Microsoft extension}}
+  */
+struct _name1 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1 = {
+  10,
+  42,/* initializes "b" */
+};
 
-// expected-no-diagnostics
+struct _name1i {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1i = {
+  .a = 10,
+  .b = 42,
+};
+
+/* Initialization of flexible array in a union is never allowed. */
+struct _name2 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+ stock-note {{initialized flexible array member 'x' is here}}
+   */
+  };
+} name2 = {
+  12,
+  13,
+  { 'c' },   /* stock-error {{initialization of flexible array member is not 
allowed}} */

efriedma-quic wrote:

Why are we trying to initialize the flexible array member here?  The error 
should be something like "excess elements", I think.

https://github.com/llvm/llvm-project/pull/84428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Eli Friedman via cfe-commits


@@ -1,13 +1,158 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
-// RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c -fsyntax-only
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -x c++
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c,gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=stock,c,microsoft -fsyntax-only 
-fms-compatibility -Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}
+microsoft-warning {{flexible array member 'x' 
in a union is a Microsoft extension}}
+  */
+struct _name1 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1 = {
+  10,
+  42,/* initializes "b" */
+};
 
-// expected-no-diagnostics
+struct _name1i {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+} name1i = {
+  .a = 10,
+  .b = 42,
+};
+
+/* Initialization of flexible array in a union is never allowed. */
+struct _name2 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+ stock-note {{initialized flexible array member 'x' is here}}
+   */
+  };
+} name2 = {
+  12,
+  13,
+  { 'c' },   /* stock-error {{initialization of flexible array member is not 
allowed}} */
+};
+
+/* Initialization of flexible array in a union is never allowed. */
+struct _name2i {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+ stock-note {{initialized flexible array member 'x' is here}}
+   */
+  };
+} name2i = {
+  .a = 12,
+  .b = 13,  /* stock-note {{previous initialization is here}} */
+  .x = { 'c' }, /* stock-error {{initialization of flexible array member is 
not allowed}}
+   c-warning {{initializer overrides prior initialization of 
this subobject}}
+   cpp-error {{initializer partially overrides prior 
initialization of this subobject}}
+ */
+};
+
+/* Flexible array initialization always allowed when not in a union,
+   and when struct has another member.
+ */
+struct _okay {
+  int a;
+  char x[];
+} okay = {
+  22,
+  { 'x', 'y', 'z' },
+};
+
+struct _okayi {
+  int a;
+  char x[];
+} okayi = {
+  .a = 22,
+  .x = { 'x', 'y', 'z' },
+};
+
+struct _okay0 {
+  int a;
+  char x[];
+} okay0 = { };
+
+struct _flex_extension {
+  char x[]; /* gnu-warning {{flexible array member 'x' in otherwise empty 
struct is a GNU extension}}
+   microsoft-warning {{flexible array member 'x' in otherwise 
empty struct is a Microsoft extension}}
+ */
+} flex_extension = {
+  { 'x', 'y', 'z' },
+};
+
+struct _flex_extensioni {
+  char x[]; /* gnu-warning {{flexible array member 'x' in otherwise empty 
struct is a GNU extension}}
+   microsoft-warning {{flexible array member 'x' in otherwise 
empty struct is a Microsoft extension}}
+ */
+} flex_extensioni = {
+  .x = { 'x', 'y', 'z' },
+};
 
+struct already_hidden {
+  int a;
+  union {
+int b;
+struct {
+  struct { } __empty;  // gnu-warning {{empty struct is a GNU extension}}
+  char x[];
+};
+  };
+};
+
+struct still_zero_sized {
+  struct { } __unused;  // gnu-warning {{empty struct is a GNU extension}}
+  int x[];
+};
+
+struct warn1 {
+  int a;
+  union {
+int b;
+char x[]; /* gnu-warning {{flexible array member 'x' in a union is a GNU 
extension}}
+ microsoft-warning {{flexible array member 'x' in a union is a 
Microsoft extension}}
+   */
+  };
+};
+
+struct warn2 {
+  int x[];  /* gnu-warning {{flexible array member 'x' in otherwise empty 
struct is a GNU extension}}
+   microsoft-warning {{flexible array member 'x' in otherwise 
empty 

[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Eli Friedman via cfe-commits


@@ -1,13 +1,158 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
-// RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c -fsyntax-only
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -x c++
+// RUN: %clang_cc1 %s -verify=stock,cpp -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=stock,c,gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=stock,c,microsoft -fsyntax-only 
-fms-compatibility -Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}

efriedma-quic wrote:

Please add codegen tests to make sure `union { char x[]; } r = {0};` actually 
works.

https://github.com/llvm/llvm-project/pull/84428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -std=c++20 -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s

delcypher wrote:

Really? We don't test the generated IR in an optimized build? That seems like a 
bad idea given that code built for production use typically is optimized.

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-18 Thread Dan Liew via cfe-commits


@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -std=c++20 -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s

delcypher wrote:

Really? We don't test the generated IR in an optimized build? That seems like a 
bad idea given that code built for production use typically is optimized.

https://github.com/llvm/llvm-project/pull/79230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] RISCV vector calling convention (1/2) (PR #77560)

2024-03-18 Thread Craig Topper via cfe-commits

https://github.com/topperc approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/77560
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-18 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/5] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple ) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList , 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  if 

[clang] [clang] Better bitfield access units (PR #65742)

2024-03-18 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

Sorry to push another update, but I realized the LimitOffset computation could 
be sunk to the point of use, and therefore not computed in all cases.

https://github.com/llvm/llvm-project/pull/65742
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type convertible to `std::coroutine_handle<>` (PR #85684)

2024-03-18 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 edited 
https://github.com/llvm/llvm-project/pull/85684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CLANG] Full support of complex multiplication and division. (PR #81514)

2024-03-18 Thread Michael Toguchi via cfe-commits

https://github.com/mdtoguchi approved this pull request.


https://github.com/llvm/llvm-project/pull/81514
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][C23] N3006 Underspecified object declarations (PR #79845)

2024-03-18 Thread Nick Desaulniers via cfe-commits


@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c2x -verify %s
+
+/* WG14 N3006: Full
+ * Underspecified object declarations
+ */
+
+struct S1 { int x, y; };// expected-note {{previous definition is 
here}}
+union U1 { int a; double b; };  // expected-note {{previous definition is 
here}}
+enum E1 { FOO, BAR };   // expected-note {{previous definition is 
here}}
+
+auto normal_struct = (struct S1){ 1, 2 };

nickdesaulniers wrote:

consider adding a test using compound literals

```c
auto normal_struct2 = (struct S1) { .x = 1, .y = 2 };
```
(I'm surprised we don't currently support this (`normal_struct2` or 
`normal_struct`).  That alone seems like an improvement.

https://github.com/llvm/llvm-project/pull/79845
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver,AArch64] Remove AArch32-specific -m[no-]unaligned-access (PR #85441)

2024-03-18 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Thanks for the comment. I'll abandon this.

https://github.com/llvm/llvm-project/pull/85441
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver,AArch64] Remove AArch32-specific -m[no-]unaligned-access (PR #85441)

2024-03-18 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay closed 
https://github.com/llvm/llvm-project/pull/85441
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DXIL] implement dot intrinsic lowering for integers (PR #85662)

2024-03-18 Thread Xiang Li via cfe-commits

https://github.com/python3kgae approved this pull request.


https://github.com/llvm/llvm-project/pull/85662
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [WIP] clang driver: enable fast unaligned access for Android on RISCV64 (PR #85704)

2024-03-18 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo.
  Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account.
  See [LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.


https://github.com/llvm/llvm-project/pull/85704
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DXIL] implement dot intrinsic lowering for integers (PR #85662)

2024-03-18 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/85662
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [WIP] clang driver: enable fast unaligned access for Android on RISCV64 (PR #85704)

2024-03-18 Thread via cfe-commits

https://github.com/hiraditya created 
https://github.com/llvm/llvm-project/pull/85704

Android CTS test already requires fast unaligned access 
https://android-review.googlesource.com/c/platform/cts/+/2675633

Pending testcase

>From e9a5140853eb4a76765189f38fa31ee21be827ef Mon Sep 17 00:00:00 2001
From: AdityaK <1894981+hiradi...@users.noreply.github.com>
Date: Mon, 18 Mar 2024 14:09:13 -0700
Subject: [PATCH] clang driver: enable fast unaligned access for Android on
 RISCV64

Android CTS test already requires fast unaligned access
https://android-review.googlesource.com/c/platform/cts/+/2675633
---
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 5165bccc6d7e30..b1dd7c4372d475 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -167,6 +167,10 @@ void riscv::getRISCVTargetFeatures(const Driver , const 
llvm::Triple ,
 Features.push_back("-relax");
   }
 
+  // Android requires fast unaligned access on RISCV64.
+  if (Triple.isAndroid())
+Features.push_back("+fast-unaligned-access");
+
   // -mstrict-align is default, unless -mno-strict-align is specified.
   AddTargetFeature(Args, Features, options::OPT_mno_strict_align,
options::OPT_mstrict_align, "fast-unaligned-access");

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


[clang] [llvm] [DXIL] implement dot intrinsic lowering for integers (PR #85662)

2024-03-18 Thread Farzon Lotfi via cfe-commits


@@ -39,11 +39,44 @@ static bool isIntrinsicExpansion(Function ) {
   case Intrinsic::dx_uclamp:
   case Intrinsic::dx_lerp:
   case Intrinsic::dx_rcp:
+  case Intrinsic::dx_sdot:
+  case Intrinsic::dx_udot:
 return true;
   }
   return false;
 }
 
+static bool expandIntegerDot(CallInst *Orig, Intrinsic::ID DotIntrinsic) {
+  assert(DotIntrinsic == Intrinsic::dx_sdot ||
+ DotIntrinsic == Intrinsic::dx_udot);
+  Intrinsic::ID MadIntrinsic = DotIntrinsic == Intrinsic::dx_sdot
+   ? Intrinsic::dx_imad
+   : Intrinsic::dx_umad;
+  Value *A = Orig->getOperand(0);
+  Value *B = Orig->getOperand(1);
+  Type *ATy = A->getType();
+  Type *BTy = B->getType();
+  assert(ATy->isVectorTy() && BTy->isVectorTy());
+
+  IRBuilder<> Builder(Orig->getParent());
+  Builder.SetInsertPoint(Orig);
+
+  auto *AVec = dyn_cast(A->getType());
+  Value *Elt0 = Builder.CreateExtractElement(A, (uint64_t)0);
+  Value *Elt1 = Builder.CreateExtractElement(B, (uint64_t)0);
+  Value *Result = Builder.CreateMul(Elt0, Elt1);
+  for (unsigned I = 1; I < AVec->getNumElements(); I++) {
+Elt0 = Builder.CreateExtractElement(A, I);
+Elt1 = Builder.CreateExtractElement(B, I);
+Result = Builder.CreateIntrinsic(Result->getType(), MadIntrinsic,
+ ArrayRef{Elt0, Elt1, Result},
+ nullptr, "dx.mad");

farzonl wrote:

i thought about that, but then i would need to add a conditional to change the 
string and it didn't seem worth it.

https://github.com/llvm/llvm-project/pull/85662
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Kees Cook via cfe-commits


@@ -1,13 +1,58 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only
 // RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
 // RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=microsoft -fsyntax-only -fms-compatibility 
-Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}
+microsoft-warning {{flexible array member 'x' 
in a union is a Microsoft extension}}
+  */

kees wrote:

I've added a bunch more tests now.

https://github.com/llvm/llvm-project/pull/84428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-18 Thread Kees Cook via cfe-commits

https://github.com/kees updated https://github.com/llvm/llvm-project/pull/84428

>From eb5138b45fa450737600050ad8dabdcb27513d42 Mon Sep 17 00:00:00 2001
From: Kees Cook 
Date: Thu, 7 Mar 2024 17:03:09 -0800
Subject: [PATCH 1/2] [Clang][Sema]: Allow flexible arrays in unions and alone
 in structs

GNU and MSVC have extensions where flexible array members (or their
equivalent) can be in unions or alone in structs. This is already fully
supported in Clang through the 0-sized array ("fake flexible array")
extension or when C99 flexible array members have been syntactically
obfuscated.

Clang needs to explicitly allow these extensions directly for C99
flexible arrays, since they are common code patterns in active use by the
Linux kernel (and other projects). Such projects have been using either
0-sized arrays (which is considered deprecated in favor of C99 flexible
array members) or via obfuscated syntax, both of which complicate their
code bases.

For example, these do not error by default:

union one {
int a;
int b[0];
};

union two {
int a;
struct {
struct { } __empty;
int b[];
};
};

But this does:

union three {
int a;
int b[];
};

Remove the default error diagnostics for this but continue to provide
warnings under Microsoft or GNU extensions checks. This will allow for
a seamless transition for code bases away from 0-sized arrays without
losing existing code patterns. Add explicit checking for the warnings
under various constructions.

Fixes #84565
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  5 --
 clang/lib/Sema/SemaDecl.cpp   |  8 +--
 clang/test/C/drs/dr5xx.c  |  2 +-
 clang/test/Sema/flexible-array-in-union.c | 53 +--
 clang/test/Sema/transparent-union.c   |  4 +-
 6 files changed, 57 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1b901a27fd19d1..960ab7e021cf2f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,6 +214,9 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
   Fixes #GH82512.
 
+- ``-Wmicrosoft`` or ``-Wgnu`` is now required to diagnose C99 flexible
+  array members in a union or alone in a struct.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c8dfdc08f5ea07..f09121b8c7ec8f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6447,9 +6447,6 @@ def ext_c99_flexible_array_member : Extension<
 def err_flexible_array_virtual_base : Error<
   "flexible array member %0 not allowed in "
   "%select{struct|interface|union|class|enum}1 which has a virtual base 
class">;
-def err_flexible_array_empty_aggregate : Error<
-  "flexible array member %0 not allowed in otherwise empty "
-  "%select{struct|interface|union|class|enum}1">;
 def err_flexible_array_has_nontrivial_dtor : Error<
   "flexible array member %0 of type %1 with non-trivial destruction">;
 def ext_flexible_array_in_struct : Extension<
@@ -6464,8 +6461,6 @@ def ext_flexible_array_empty_aggregate_ms : Extension<
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a Microsoft extension">,
   InGroup;
-def err_flexible_array_union : Error<
-  "flexible array member %0 in a union is not allowed">;
 def ext_flexible_array_union_ms : Extension<
   "flexible array member %0 in a union is a Microsoft extension">,
   InGroup;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 67e56a917a51de..053122b588246b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19357,15 +19357,11 @@ void Sema::ActOnFields(Scope *S, SourceLocation 
RecLoc, Decl *EnclosingDecl,
 } else if (Record->isUnion())
   DiagID = getLangOpts().MicrosoftExt
? diag::ext_flexible_array_union_ms
-   : getLangOpts().CPlusPlus
- ? diag::ext_flexible_array_union_gnu
- : diag::err_flexible_array_union;
+   : diag::ext_flexible_array_union_gnu;
 else if (NumNamedMembers < 1)
   DiagID = getLangOpts().MicrosoftExt
? diag::ext_flexible_array_empty_aggregate_ms
-   : getLangOpts().CPlusPlus
- ? diag::ext_flexible_array_empty_aggregate_gnu
- : diag::err_flexible_array_empty_aggregate;
+   : diag::ext_flexible_array_empty_aggregate_gnu;
 
 if (DiagID)
   

[clang] [llvm] [DXIL] implement dot intrinsic lowering for integers (PR #85662)

2024-03-18 Thread Xiang Li via cfe-commits


@@ -39,11 +39,44 @@ static bool isIntrinsicExpansion(Function ) {
   case Intrinsic::dx_uclamp:
   case Intrinsic::dx_lerp:
   case Intrinsic::dx_rcp:
+  case Intrinsic::dx_sdot:
+  case Intrinsic::dx_udot:
 return true;
   }
   return false;
 }
 
+static bool expandIntegerDot(CallInst *Orig, Intrinsic::ID DotIntrinsic) {
+  assert(DotIntrinsic == Intrinsic::dx_sdot ||
+ DotIntrinsic == Intrinsic::dx_udot);
+  Intrinsic::ID MadIntrinsic = DotIntrinsic == Intrinsic::dx_sdot
+   ? Intrinsic::dx_imad
+   : Intrinsic::dx_umad;
+  Value *A = Orig->getOperand(0);
+  Value *B = Orig->getOperand(1);
+  Type *ATy = A->getType();
+  Type *BTy = B->getType();
+  assert(ATy->isVectorTy() && BTy->isVectorTy());
+
+  IRBuilder<> Builder(Orig->getParent());
+  Builder.SetInsertPoint(Orig);
+
+  auto *AVec = dyn_cast(A->getType());
+  Value *Elt0 = Builder.CreateExtractElement(A, (uint64_t)0);
+  Value *Elt1 = Builder.CreateExtractElement(B, (uint64_t)0);
+  Value *Result = Builder.CreateMul(Elt0, Elt1);
+  for (unsigned I = 1; I < AVec->getNumElements(); I++) {
+Elt0 = Builder.CreateExtractElement(A, I);
+Elt1 = Builder.CreateExtractElement(B, I);
+Result = Builder.CreateIntrinsic(Result->getType(), MadIntrinsic,
+ ArrayRef{Elt0, Elt1, Result},
+ nullptr, "dx.mad");

python3kgae wrote:

Do we want to mark "dx.imad", "dx.umad" here?

https://github.com/llvm/llvm-project/pull/85662
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CLANG] Full support of complex multiplication and division. (PR #81514)

2024-03-18 Thread Andy Kaylor via cfe-commits

https://github.com/andykaylor approved this pull request.

This looks good to me. Thanks for the updates!

https://github.com/llvm/llvm-project/pull/81514
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Refactor processing of terminator element (PR #84499)

2024-03-18 Thread Yitzhak Mandelbaum via cfe-commits


@@ -337,26 +274,33 @@ computeBlockInputState(const CFGBlock , 
AnalysisContext ) {
 AC.BlockStates[Pred->getBlockID()];
 if (!MaybePredState)
   continue;
-
-if (AC.Analysis.builtinOptions()) {
-  if (const Stmt *PredTerminatorStmt = Pred->getTerminatorStmt()) {
-// We have a terminator: we need to mutate an environment to describe
-// when the terminator is taken. Copy now.
+const TypeErasedDataflowAnalysisState  = *MaybePredState;
+
+if (const Stmt *PredTerminatorStmt = Pred->getTerminatorStmt()) {

ymand wrote:

Done

https://github.com/llvm/llvm-project/pull/84499
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Refactor processing of terminator element (PR #84499)

2024-03-18 Thread Yitzhak Mandelbaum via cfe-commits

https://github.com/ymand updated https://github.com/llvm/llvm-project/pull/84499

>From 3b20e1823753ab46e3e259d3d8c727dea91ce1d4 Mon Sep 17 00:00:00 2001
From: Yitzhak Mandelbaum 
Date: Fri, 8 Mar 2024 15:19:14 +
Subject: [PATCH 1/2] [clang][dataflow] Refactor processing of terminator
 element

This patch vastly simplifies the code handling terminators, without changing any
behavior. Additionally, the simplification unblocks our ability to address a
(simple) FIXME in the code to invoke `transferBranch`, even when builtin options
are disabled.
---
 .../TypeErasedDataflowAnalysis.cpp| 126 +-
 1 file changed, 35 insertions(+), 91 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 939247c047c66e..2d745231fd0758 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -11,7 +11,6 @@
 //
 
//===--===//
 
-#include 
 #include 
 #include 
 #include 
@@ -33,7 +32,6 @@
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallBitVector.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 
@@ -64,88 +62,27 @@ static bool isBackedgeNode(const CFGBlock ) {
 
 namespace {
 
-// The return type of the visit functions in TerminatorVisitor. The first
-// element represents the terminator expression (that is the conditional
-// expression in case of a path split in the CFG). The second element
-// represents whether the condition was true or false.
-using TerminatorVisitorRetTy = std::pair;
-
-/// Extends the flow condition of an environment based on a terminator
-/// statement.
+/// Extracts the condition expression.
 class TerminatorVisitor
-: public ConstStmtVisitor {
+: public ConstStmtVisitor {
 public:
-  TerminatorVisitor(Environment , int BlockSuccIdx)
-  : Env(Env), BlockSuccIdx(BlockSuccIdx) {}
-
-  TerminatorVisitorRetTy VisitIfStmt(const IfStmt *S) {
-auto *Cond = S->getCond();
-assert(Cond != nullptr);
-return extendFlowCondition(*Cond);
-  }
-
-  TerminatorVisitorRetTy VisitWhileStmt(const WhileStmt *S) {
-auto *Cond = S->getCond();
-assert(Cond != nullptr);
-return extendFlowCondition(*Cond);
-  }
-
-  TerminatorVisitorRetTy VisitDoStmt(const DoStmt *S) {
-auto *Cond = S->getCond();
-assert(Cond != nullptr);
-return extendFlowCondition(*Cond);
-  }
-
-  TerminatorVisitorRetTy VisitForStmt(const ForStmt *S) {
-auto *Cond = S->getCond();
-if (Cond != nullptr)
-  return extendFlowCondition(*Cond);
-return {nullptr, false};
-  }
-
-  TerminatorVisitorRetTy VisitCXXForRangeStmt(const CXXForRangeStmt *) {
+  TerminatorVisitor() = default;
+  const Expr *VisitIfStmt(const IfStmt *S) { return S->getCond(); }
+  const Expr *VisitWhileStmt(const WhileStmt *S) { return S->getCond(); }
+  const Expr *VisitDoStmt(const DoStmt *S) { return S->getCond(); }
+  const Expr *VisitForStmt(const ForStmt *S) { return S->getCond(); }
+  const Expr *VisitCXXForRangeStmt(const CXXForRangeStmt *) {
 // Don't do anything special for CXXForRangeStmt, because the condition
 // (being implicitly generated) isn't visible from the loop body.
-return {nullptr, false};
+return nullptr;
   }
-
-  TerminatorVisitorRetTy VisitBinaryOperator(const BinaryOperator *S) {
+  const Expr *VisitBinaryOperator(const BinaryOperator *S) {
 assert(S->getOpcode() == BO_LAnd || S->getOpcode() == BO_LOr);
-auto *LHS = S->getLHS();
-assert(LHS != nullptr);
-return extendFlowCondition(*LHS);
+return S->getLHS();
   }
-
-  TerminatorVisitorRetTy
-  VisitConditionalOperator(const ConditionalOperator *S) {
-auto *Cond = S->getCond();
-assert(Cond != nullptr);
-return extendFlowCondition(*Cond);
-  }
-
-private:
-  TerminatorVisitorRetTy extendFlowCondition(const Expr ) {
-auto *Val = Env.get(Cond);
-// In transferCFGBlock(), we ensure that we always have a `Value` for the
-// terminator condition, so assert this.
-// We consciously assert ourselves instead of asserting via `cast()` so
-// that we get a more meaningful line number if the assertion fails.
-assert(Val != nullptr);
-
-bool ConditionValue = true;
-// The condition must be inverted for the successor that encompasses the
-// "else" branch, if such exists.
-if (BlockSuccIdx == 1) {
-  Val = (*Val);
-  ConditionValue = false;
-}
-
-Env.assume(Val->formula());
-return {, ConditionValue};
+  const Expr *VisitConditionalOperator(const ConditionalOperator *S) {
+return S->getCond();
   }
-
-  Environment 
-  int BlockSuccIdx;
 };
 
 /// Holds data structures required for running dataflow analysis.
@@ -337,26 +274,33 @@ 

[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-18 Thread Danny Mösch via cfe-commits


@@ -454,11 +454,14 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  llvm::StringRef Cur = CheckGlob;

SimplyDanny wrote:

Should be empty at first.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-18 Thread Danny Mösch via cfe-commits


@@ -251,6 +251,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed ``--verify-check`` option not properly parsing checks when using the 
+  literal operator in the ``.clang-tidy`` config

SimplyDanny wrote:

```suggestion
  literal operator in the ``.clang-tidy`` config.
```

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-18 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny approved this pull request.

Seems like the parsing logic got duplicated. That eventually caused the 
misbehavior in verification. Alignment would be preferred.

From my point of view, the fix is okay for now though.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-18 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny edited 
https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-18 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/4] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple ) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList , 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  if 

[clang] [HIP] do not link runtime for -r (PR #85675)

2024-03-18 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/85675

>From 2e0967c0c606ad647185a739442647ab7d90ed52 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Mon, 18 Mar 2024 14:09:56 -0400
Subject: [PATCH] [HIP] do not link runtime for -r

since it will cause duplicate symbols when the partially
linked object is linked again.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp   | 2 +-
 clang/test/Driver/hip-partial-link.hip   | 2 +-
 clang/test/Driver/hip-runtime-libs-linux.hip | 5 +
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 83015b0cb81a6e..4478865313636d 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2830,7 +2830,7 @@ void tools::addHIPRuntimeLibArgs(const ToolChain , 
Compilation ,
  llvm::opt::ArgStringList ) {
   if ((C.getActiveOffloadKinds() & Action::OFK_HIP) &&
   !Args.hasArg(options::OPT_nostdlib) &&
-  !Args.hasArg(options::OPT_no_hip_rt)) {
+  !Args.hasArg(options::OPT_no_hip_rt) && !Args.hasArg(options::OPT_r)) {
 TC.AddHIPRuntimeLibArgs(Args, CmdArgs);
   } else {
 // Claim "no HIP libraries" arguments if any
diff --git a/clang/test/Driver/hip-partial-link.hip 
b/clang/test/Driver/hip-partial-link.hip
index faa185972abc33..c8451ec81ed37e 100644
--- a/clang/test/Driver/hip-partial-link.hip
+++ b/clang/test/Driver/hip-partial-link.hip
@@ -47,7 +47,7 @@
 // OBJ:  D __hip_gpubin_handle_[[ID2]]
 
 // RUN: %clang -v --target=x86_64-unknown-linux-gnu --no-offload-new-driver \
-// RUN:   --hip-link -no-hip-rt -fgpu-rdc --offload-arch=gfx906 \
+// RUN:   --hip-link -fgpu-rdc --offload-arch=gfx906 \
 // RUN:   -fuse-ld=lld -nostdlib -r %t.main.o %t.lib.o -o %t.final.o \
 // RUN:   2>&1 | FileCheck -check-prefix=LINK-O %s
 // LINK-O-NOT: Found undefined HIP {{.*}}symbol
diff --git a/clang/test/Driver/hip-runtime-libs-linux.hip 
b/clang/test/Driver/hip-runtime-libs-linux.hip
index 142582963c958f..a4cd2733114b69 100644
--- a/clang/test/Driver/hip-runtime-libs-linux.hip
+++ b/clang/test/Driver/hip-runtime-libs-linux.hip
@@ -43,6 +43,11 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
+// Test HIP runtime lib is not linked with -r.
+// RUN: %clang -### --hip-link -r --target=x86_64-linux-gnu \
+// RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
+// RUN:   | FileCheck -check-prefixes=NOHIPRT %s
+
 // Test HIP runtime lib is linked without hip-link if there is HIP input file.
 // RUN: %clang -### --target=x86_64-linux-gnu -nogpuinc -nogpulib \
 // RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \

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


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
, ArgList ,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,
+](const llvm::opt::Arg *A,
+   bool IsFramework = false) -> std::string {
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {

etcwilde wrote:

> I think that Prefix or Expand would both be better than Convert. We aren't 
> really converting this.

There, changed to `PrefixHeaderPath`.

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
, ArgList ,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,
+](const llvm::opt::Arg *A,
+   bool IsFramework = false) -> std::string {
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {

etcwilde wrote:

Maybe? The thing coming from `Args.filtered` should be populated though? Even 
if it isn't, we shouldn't be entering the `for`-loop though. Perhaps 
`Args.filtered` should result in iterator that emits a const reference? That 
seems like a bigger, unrelated change though.

Added an assert and a test case. The arg parser will error out earlier if 
nothing is passed to `-I`; `argument to '-I' is missing`. Is that sufficient?

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde edited 
https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits


@@ -3256,12 +3262,14 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
, ArgList ,
   }
 
   for (const auto *A : Args.filtered(OPT_idirafter))
-Opts.AddPath(A->getValue(), frontend::After, false, true);
+Opts.AddPath(ConvertHeaderPath(A), frontend::After, false, true);
   for (const auto *A : Args.filtered(OPT_iquote))
-Opts.AddPath(A->getValue(), frontend::Quoted, false, true);
-  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
+Opts.AddPath(ConvertHeaderPath(A), frontend::Quoted, false, true);
+  for (const auto *A : Args.filtered(OPT_iwithsysroot))
 Opts.AddPath(A->getValue(), frontend::System, false,
- !A->getOption().matches(OPT_iwithsysroot));
+ /*IgnoreSysRoot=*/false);
+  for (const auto *A : Args.filtered(OPT_isystem))

etcwilde wrote:

Fixed

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde updated 
https://github.com/llvm/llvm-project/pull/82084

>From 4c147d0508df51ca713b182dd8b85130cafb1f6c Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Fri, 16 Feb 2024 16:39:10 -0800
Subject: [PATCH] Support sysroot-relative header search paths

Clang supported header searchpaths of the form `-I =/path`, relative to
the sysroot if one is passed, but did not implement that behavior for
`-iquote`, `-isystem`, or `-idirafter`.
---
 clang/lib/Frontend/CompilerInvocation.cpp | 43 +++
 clang/test/Preprocessor/sysroot-prefix.c  | 25 +
 2 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2a21a9d619dc0b..650e05b2bf33a0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3191,6 +3191,22 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
, ArgList ,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto PrefixHeaderPath = [IsSysrootSpecified,
+   ](const llvm::opt::Arg *A,
+  bool IsFramework = false) -> std::string {
+assert(A->getNumValues() != 0 && "Unexpected empty search path flag!");
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
+  SmallString<32> Buffer;
+  llvm::sys::path::append(Buffer, Opts.Sysroot,
+  llvm::StringRef(A->getValue()).substr(1));
+  return std::string(Buffer);
+}
+return A->getValue();
+  };
+
   for (const auto *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) {
 if (A->getOption().matches(OPT_index_header_map)) {
   // -index-header-map applies to the next -I or -F.
@@ -3202,16 +3218,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
, ArgList ,
 IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
 
 bool IsFramework = A->getOption().matches(OPT_F);
-std::string Path = A->getValue();
-
-if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
-  SmallString<32> Buffer;
-  llvm::sys::path::append(Buffer, Opts.Sysroot,
-  llvm::StringRef(A->getValue()).substr(1));
-  Path = std::string(Buffer);
-}
-
-Opts.AddPath(Path, Group, IsFramework,
+Opts.AddPath(PrefixHeaderPath(A, IsFramework), Group, IsFramework,
  /*IgnoreSysroot*/ true);
 IsIndexHeaderMap = false;
   }
@@ -3229,12 +3236,18 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
, ArgList ,
   }
 
   for (const auto *A : Args.filtered(OPT_idirafter))
-Opts.AddPath(A->getValue(), frontend::After, false, true);
+Opts.AddPath(PrefixHeaderPath(A), frontend::After, false, true);
   for (const auto *A : Args.filtered(OPT_iquote))
-Opts.AddPath(A->getValue(), frontend::Quoted, false, true);
-  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
-Opts.AddPath(A->getValue(), frontend::System, false,
- !A->getOption().matches(OPT_iwithsysroot));
+Opts.AddPath(PrefixHeaderPath(A), frontend::Quoted, false, true);
+
+  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot)) {
+if (A->getOption().matches(OPT_iwithsysroot)) {
+  Opts.AddPath(A->getValue(), frontend::System, false,
+   /*IgnoreSysRoot=*/false);
+  continue;
+}
+Opts.AddPath(PrefixHeaderPath(A), frontend::System, false, true);
+  }
   for (const auto *A : Args.filtered(OPT_iframework))
 Opts.AddPath(A->getValue(), frontend::System, true, true);
   for (const auto *A : Args.filtered(OPT_iframeworkwithsysroot))
diff --git a/clang/test/Preprocessor/sysroot-prefix.c 
b/clang/test/Preprocessor/sysroot-prefix.c
index 08c72f53b44e9f..5c84380e5c6a07 100644
--- a/clang/test/Preprocessor/sysroot-prefix.c
+++ b/clang/test/Preprocessor/sysroot-prefix.c
@@ -4,6 +4,16 @@
 // RUN: %clang_cc1 -v -isysroot /var/empty -I =null -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty -isysroot /var/empty/root -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty/root -isysroot /var/empty -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SWAPPED_SYSROOT_NULL %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -isysroot /var/empty -E %s -o 
/dev/null 2>&1 | FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_SYSROOT %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_NO_SYSROOT %s
+// RUN: %clang_cc1 -v -iquote=/usr/include -isysroot /var/empty  -E %s -o 
/dev/null 2>&1 | 

[clang] [clang][NFC] Add documentation for `CastExpr::path()`. (PR #85623)

2024-03-18 Thread John McCall via cfe-commits


@@ -3552,6 +3552,15 @@ class CastExpr : public Expr {
   /// function that it invokes.
   NamedDecl *getConversionFunction() const;
 
+  /// Path through the class hierarchy taken by a `DerivedToBase` or
+  /// `UncheckedDerivedToBase` cast. For each derived-to-base edge in the path,
+  /// the path contains a `CXXBaseSpecifier` for the base class of that edge;
+  /// the entries are ordered from derived class to base class.

rjmccall wrote:

You can see in `CastConsistency` the set of cast kinds that require a base 
path; it's more than just these two.

https://github.com/llvm/llvm-project/pull/85623
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [openmp] [docs] Prefer --gcc-install-dir= to deprecated GCC_INSTALL_PREFIX (PR #85458)

2024-03-18 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay closed 
https://github.com/llvm/llvm-project/pull/85458
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   >