[clang] [libclang/python] Bump minimum compatibility to Python 3.6 (PR #77228)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Craig Hesling (linux4life798)


Changes

Remove Python 2 support and clean up code that conditions based on version.

Issue #76664.

---
Full diff: https://github.com/llvm/llvm-project/pull/77228.diff


2 Files Affected:

- (modified) clang/bindings/python/README.txt (+1-1) 
- (modified) clang/bindings/python/clang/cindex.py (+73-98) 


``diff
diff --git a/clang/bindings/python/README.txt b/clang/bindings/python/README.txt
index 44c715e5de56f7..3e509662144fac 100644
--- a/clang/bindings/python/README.txt
+++ b/clang/bindings/python/README.txt
@@ -10,7 +10,7 @@ runner. For example:
 --
 $ env PYTHONPATH=$(echo ~/llvm/clang/bindings/python/) \
   CLANG_LIBRARY_PATH=$(llvm-config --libdir) \
-  python -m unittest discover -v
+  python3 -m unittest discover -v
 tests.cindex.test_index.test_create ... ok
 ...
 
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index d780ee353a133c..754f03d718e882 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -66,81 +66,50 @@
 
 import clang.enumerations
 
+import collections.abc
 import os
-import sys
-
-if sys.version_info[0] == 3:
-# Python 3 strings are unicode, translate them to/from utf8 for C-interop.
-class c_interop_string(c_char_p):
-def __init__(self, p=None):
-if p is None:
-p = ""
-if isinstance(p, str):
-p = p.encode("utf8")
-super(c_char_p, self).__init__(p)
 
-def __str__(self):
-return self.value
-
-@property
-def value(self):
-if super(c_char_p, self).value is None:
-return None
-return super(c_char_p, self).value.decode("utf8")
-
-@classmethod
-def from_param(cls, param):
-if isinstance(param, str):
-return cls(param)
-if isinstance(param, bytes):
-return cls(param)
-if param is None:
-# Support passing null to C functions expecting char arrays
-return None
-raise TypeError(
-"Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
-)
-
-@staticmethod
-def to_python_string(x, *args):
-return x.value
 
-def b(x):
-if isinstance(x, bytes):
-return x
-return x.encode("utf8")
+# Python 3 strings are unicode, translate them to/from utf8 for C-interop.
+class c_interop_string(c_char_p):
+def __init__(self, p=None):
+if p is None:
+p = ""
+if isinstance(p, str):
+p = p.encode("utf8")
+super(c_char_p, self).__init__(p)
 
-elif sys.version_info[0] == 2:
-# Python 2 strings are utf8 byte strings, no translation is needed for
-# C-interop.
-c_interop_string = c_char_p
-
-def _to_python_string(x, *args):
-return x
-
-c_interop_string.to_python_string = staticmethod(_to_python_string)
+def __str__(self):
+return self.value
 
-def b(x):
-return x
+@property
+def value(self):
+if super(c_char_p, self).value is None:
+return None
+return super(c_char_p, self).value.decode("utf8")
 
+@classmethod
+def from_param(cls, param):
+if isinstance(param, str):
+return cls(param)
+if isinstance(param, bytes):
+return cls(param)
+if param is None:
+# Support passing null to C functions expecting char arrays
+return None
+raise TypeError(
+"Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
+)
 
-# Importing ABC-s directly from collections is deprecated since Python 3.7,
-# will stop working in Python 3.8.
-# See: https://docs.python.org/dev/whatsnew/3.7.html#id3
-if sys.version_info[:2] >= (3, 7):
-from collections import abc as collections_abc
-else:
-import collections as collections_abc
+@staticmethod
+def to_python_string(x, *args):
+return x.value
 
-# We only support PathLike objects on Python version with os.fspath present
-# to be consistent with the Python standard library. On older Python versions
-# we only support strings and we have dummy fspath to just pass them through.
-try:
-fspath = os.fspath
-except AttributeError:
 
-def fspath(x):
+def b(x):
+if isinstance(x, bytes):
 return x
+return x.encode("utf8")
 
 
 # ctypes doesn't implicitly convert c_void_p to the appropriate wrapper
@@ -202,7 +171,7 @@ def __init__(self, enumeration, message):
 ### Structures and Utility Classes ###
 
 
-class CachedProperty(object):
+class CachedProperty:
 """Decorator that lazy-loads the value of a property.
 
 The first time the property is accessed, the original property function is
@@ -392,7 +361,7 @@ def 

[clang] [libclang/python] Bump minimum compatibility to Python 3.6 (PR #77228)

2024-01-06 Thread Craig Hesling via cfe-commits

https://github.com/linux4life798 created 
https://github.com/llvm/llvm-project/pull/77228

Remove Python 2 support and clean up code that conditions based on version.

Issue #76664.

>From 1ce6508ee1052c46c44a0f8f5dfd424df83ce209 Mon Sep 17 00:00:00 2001
From: Craig Hesling 
Date: Sat, 2 Dec 2023 15:29:42 -0800
Subject: [PATCH 1/4] [libclang/python] Remove Python 2 support

This simply removes the Python 2 arm of this conditional logic
and unindents the Python 3 logic.
---
 clang/bindings/python/README.txt  |  2 +-
 clang/bindings/python/clang/cindex.py | 78 ---
 2 files changed, 34 insertions(+), 46 deletions(-)

diff --git a/clang/bindings/python/README.txt b/clang/bindings/python/README.txt
index 44c715e5de56f7..3e509662144fac 100644
--- a/clang/bindings/python/README.txt
+++ b/clang/bindings/python/README.txt
@@ -10,7 +10,7 @@ runner. For example:
 --
 $ env PYTHONPATH=$(echo ~/llvm/clang/bindings/python/) \
   CLANG_LIBRARY_PATH=$(llvm-config --libdir) \
-  python -m unittest discover -v
+  python3 -m unittest discover -v
 tests.cindex.test_index.test_create ... ok
 ...
 
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index d780ee353a133c..81aefcc8db6234 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -69,59 +69,47 @@
 import os
 import sys
 
-if sys.version_info[0] == 3:
-# Python 3 strings are unicode, translate them to/from utf8 for C-interop.
-class c_interop_string(c_char_p):
-def __init__(self, p=None):
-if p is None:
-p = ""
-if isinstance(p, str):
-p = p.encode("utf8")
-super(c_char_p, self).__init__(p)
 
-def __str__(self):
-return self.value
-
-@property
-def value(self):
-if super(c_char_p, self).value is None:
-return None
-return super(c_char_p, self).value.decode("utf8")
-
-@classmethod
-def from_param(cls, param):
-if isinstance(param, str):
-return cls(param)
-if isinstance(param, bytes):
-return cls(param)
-if param is None:
-# Support passing null to C functions expecting char arrays
-return None
-raise TypeError(
-"Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
-)
+# Python 3 strings are unicode, translate them to/from utf8 for C-interop.
+class c_interop_string(c_char_p):
+def __init__(self, p=None):
+if p is None:
+p = ""
+if isinstance(p, str):
+p = p.encode("utf8")
+super(c_char_p, self).__init__(p)
 
-@staticmethod
-def to_python_string(x, *args):
-return x.value
+def __str__(self):
+return self.value
 
-def b(x):
-if isinstance(x, bytes):
-return x
-return x.encode("utf8")
+@property
+def value(self):
+if super(c_char_p, self).value is None:
+return None
+return super(c_char_p, self).value.decode("utf8")
 
-elif sys.version_info[0] == 2:
-# Python 2 strings are utf8 byte strings, no translation is needed for
-# C-interop.
-c_interop_string = c_char_p
+@classmethod
+def from_param(cls, param):
+if isinstance(param, str):
+return cls(param)
+if isinstance(param, bytes):
+return cls(param)
+if param is None:
+# Support passing null to C functions expecting char arrays
+return None
+raise TypeError(
+"Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
+)
 
-def _to_python_string(x, *args):
-return x
+@staticmethod
+def to_python_string(x, *args):
+return x.value
 
-c_interop_string.to_python_string = staticmethod(_to_python_string)
 
-def b(x):
+def b(x):
+if isinstance(x, bytes):
 return x
+return x.encode("utf8")
 
 
 # Importing ABC-s directly from collections is deprecated since Python 3.7,

>From 46638d89c359fc635d30059638fdc7e1517776c8 Mon Sep 17 00:00:00 2001
From: Craig Hesling 
Date: Sat, 2 Dec 2023 15:25:24 -0800
Subject: [PATCH 2/4] [libclang/python] Remove inheritance from object

In Python3, inheriting from the object class is implicit.
---
 clang/bindings/python/clang/cindex.py | 40 +--
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 81aefcc8db6234..563bd11db795e8 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -190,7 +190,7 @@ def __init__(self, enumeration, message):
 ### Structures and Utility Classes ###
 
 
-class CachedProperty(object):
+class CachedProperty:
 """Decorator 

[clang] [llvm] [SpecialCaseList] Use glob by default (PR #74809)

2024-01-06 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> ah it's because we something like
> 
> ```
> [cfi-unrelated-cast|cfi-derived-cast]
> 
> src:*third_party/vulkan_memory_allocator/include/vk_mem_alloc.h
> ```
> 
> it seems like the new system doesn't match 
> `[cfi-unrelated-cast|cfi-derived-cast]`

The glob mode can use the section name `[cfi-*-cast]` or 
`[cfi-{unrelated,derived}-cast]`. 
https://clang.llvm.org/docs/SanitizerSpecialCaseList.html contains an example.

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


[clang-tools-extra] Fix #75686: add iter_swap and iter_move to the matched name (PR #76117)

2024-01-06 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/76117

>From 97eeda4684804229d9faad19ea7b7888dcd91786 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Thu, 21 Dec 2023 02:30:34 +
Subject: [PATCH 1/6] Fix #75686: add iter_swap and iter_move to the matched
 name

---
 .../bugprone/ExceptionEscapeCheck.cpp   | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
index 90bf523ffb00b6..18cd7150185a20 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -58,14 +58,15 @@ void 
ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap ) {
 
 void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(isDefinition(),
-   anyOf(isNoThrow(),
- allOf(anyOf(cxxDestructorDecl(),
- cxxConstructorDecl(isMoveConstructor()),
- cxxMethodDecl(isMoveAssignmentOperator()),
- isMain(), hasName("swap")),
-   unless(isExplicitThrow())),
- isEnabled(FunctionsThatShouldNotThrow)))
+  functionDecl(
+  isDefinition(),
+  anyOf(isNoThrow(),
+allOf(anyOf(cxxDestructorDecl(),
+cxxConstructorDecl(isMoveConstructor()),
+cxxMethodDecl(isMoveAssignmentOperator()), 
isMain(),
+hasAnyName("swap", "iter_swap", "iter_move")),
+  unless(isExplicitThrow())),
+isEnabled(FunctionsThatShouldNotThrow)))
   .bind("thrower"),
   this);
 }

>From c7cbf4c9bebbf450410c2679af188672257895aa Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Thu, 28 Dec 2023 01:30:35 +
Subject: [PATCH 2/6] [clang-tidy] Update documentation, release notes and
 tests for bugprone-exception-escape

---
 clang-tools-extra/docs/ReleaseNotes.rst|  4 
 .../clang-tidy/checks/bugprone/exception-escape.rst|  2 ++
 .../clang-tidy/checkers/bugprone/exception-escape.cpp  | 10 ++
 3 files changed, 16 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d91748e4cef18..967597cbba11b1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -242,6 +242,10 @@ Changes in existing checks
   casting during type conversions at variable initialization, now with improved
   compatibility for C++17 and later versions.
 
+- Improved :doc:`bugprone-exception-escape
+  ` check by extending the default
+  check function names to include ``iter_swap`` and ``iter_move``.
+
 - Improved :doc:`bugprone-lambda-function-name
   ` check by adding option
   `IgnoreMacros` to ignore warnings in macros.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
index e6aa8e001492a6..182fade7f47a03 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
@@ -11,6 +11,8 @@ should not. The functions which should not throw exceptions 
are the following:
 * Move assignment operators
 * The ``main()`` functions
 * ``swap()`` functions
+* ``iter_swap()`` functions
+* ``iter_move()`` functions
 * Functions marked with ``throw()`` or ``noexcept``
 * Other functions given as option
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
index 4a7149e81ce7e5..e20aa267392f55 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -586,6 +586,16 @@ void swap(int&, int&) {
   throw 1;
 }
 
+void iter_swap(int&, int&) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in 
function 'iter_swap' which should not throw exceptions
+  throw 1;
+}
+
+void iter_move(int&, int&) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in 
function 'iter_move' which should not throw exceptions
+  throw 1;
+}
+
 namespace std {
 class bad_alloc {};
 }

>From 0accdc7d74eda5719a1415588e704e2f8dff58c4 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 7 Jan 2024 02:25:47 +
Subject: [PATCH 3/6] [clang-tidy] exception-escape test: iter_move function
 should have only one parameter

---
 .../test/clang-tidy/checkers/bugprone/exception-escape.cpp  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 

[mlir] [llvm] [clang-tools-extra] [clang] [mlir][spirv] Support alias/restrict function argument decorations (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

antiagainst wrote:

> @kuhar @antiagainst Thanks for your comment and support to land this PR! If 
> you have any issues or TODO tasks in SPIR-V dialect, I would be happy if you 
> could share it with me. :)

Thanks for your further interest! Please feel free to take a look at issues 
with the `mlir:spirv` label to see if any one of them is interesting to you, 
especially those with the `good first issue` label at the same time!

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


[llvm] [clang] [libcxx] Reapply "[libc++][streams] P1759R6: Native handles and file streams" (PR #77190)

2024-01-06 Thread via cfe-commits

https://github.com/zeroomega commented:

I test run it with C++26 on Windows, it clears the test failures happened in 
the original PR.

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


[mlir] [clang-tools-extra] [llvm] [clang] [mlir][spirv] Support alias/restrict function argument decorations (PR #76353)

2024-01-06 Thread Kohei Yamaguchi via cfe-commits

sott0n wrote:

@kuhar @antiagainst Thanks for your comment and support to land this PR! If you 
have any issues or TODO tasks in SPIR-V dialect, I would be happy if you could 
share it with me.

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


[clang] [lldb] [clang-tools-extra] [compiler-rt] [mlir] [llvm] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread Jonas Devlieghere via cfe-commits

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


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


[lldb] [compiler-rt] [llvm] [mlir] [clang-tools-extra] [clang] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread Jonas Devlieghere via cfe-commits


@@ -108,13 +108,9 @@ else()
   linux/HostInfoLinux.cpp
   linux/LibcGlue.cpp
   linux/Support.cpp
+  android/HostInfoAndroid.cpp
+  android/LibcGlue.cpp
   )
-if (CMAKE_SYSTEM_NAME MATCHES "Android")

JDevlieghere wrote:

While Android might be Linux, the inverse isn't true. Amongst other things, 
this change would result in all Linux hosts reporting that they support Android 
triples. 

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


[clang] [mlir] [llvm] [compiler-rt] [lldb] [clang-tools-extra] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread Jonas Devlieghere via cfe-commits

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


[clang] [mlir] [llvm] [compiler-rt] [lldb] [clang-tools-extra] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits


@@ -108,13 +108,9 @@ else()
   linux/HostInfoLinux.cpp
   linux/LibcGlue.cpp
   linux/Support.cpp
+  android/HostInfoAndroid.cpp
+  android/LibcGlue.cpp
   )
-if (CMAKE_SYSTEM_NAME MATCHES "Android")

trcrsired wrote:

I will try to find a better solution.

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


[clang] [mlir] [llvm] [compiler-rt] [lldb] [clang-tools-extra] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits


@@ -108,13 +108,9 @@ else()
   linux/HostInfoLinux.cpp
   linux/LibcGlue.cpp
   linux/Support.cpp
+  android/HostInfoAndroid.cpp
+  android/LibcGlue.cpp
   )
-if (CMAKE_SYSTEM_NAME MATCHES "Android")

trcrsired wrote:

That is probably because cmake treats Android differently, despite it can be 
treated the same.

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


[clang] [mlir] [libc] [flang] [libcxx] [llvm] [compiler-rt] [clang-tools-extra] [mlir][Linalg] Support dynamic tiles in `lower_pack` transform (PR #76003)

2024-01-06 Thread via cfe-commits

srcarroll wrote:

I made a PR to extend UB cases in verifier 
https://github.com/llvm/llvm-project/pull/77217

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


[llvm] [clang] [mlir] [compiler-rt] [clang-tools-extra] [lldb] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread Anton Korobeynikov via cfe-commits


@@ -108,13 +108,9 @@ else()
   linux/HostInfoLinux.cpp
   linux/LibcGlue.cpp
   linux/Support.cpp
+  android/HostInfoAndroid.cpp
+  android/LibcGlue.cpp
   )
-if (CMAKE_SYSTEM_NAME MATCHES "Android")

asl wrote:

Not quite. It's distant enough in many aspects (from the toolchain perspective) 
to have a separate cmake system name.

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


[llvm] [clang] [mlir] [compiler-rt] [clang-tools-extra] [lldb] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits


@@ -108,13 +108,9 @@ else()
   linux/HostInfoLinux.cpp
   linux/LibcGlue.cpp
   linux/Support.cpp
+  android/HostInfoAndroid.cpp
+  android/LibcGlue.cpp
   )
-if (CMAKE_SYSTEM_NAME MATCHES "Android")

trcrsired wrote:

> Well, so this is not a cmake problem then.

but it still needs a solution tbh. android is linux.

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


[llvm] [clang] [mlir] [compiler-rt] [clang-tools-extra] [lldb] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits


@@ -46,64 +46,64 @@ class Triple {
   enum ArchType {
 UnknownArch,
 
-arm,// ARM (little endian): arm, armv.*, xscale

trcrsired wrote:

i will fix it later. but first pass CI with other things first to ensure it 
does not break anything.

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


[llvm] [clang] [mlir] [compiler-rt] [clang-tools-extra] [lldb] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread Anton Korobeynikov via cfe-commits


@@ -108,13 +108,9 @@ else()
   linux/HostInfoLinux.cpp
   linux/LibcGlue.cpp
   linux/Support.cpp
+  android/HostInfoAndroid.cpp
+  android/LibcGlue.cpp
   )
-if (CMAKE_SYSTEM_NAME MATCHES "Android")

asl wrote:

Well, so this is not a cmake problem then.

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


[llvm] [clang] [mlir] [compiler-rt] [clang-tools-extra] [lldb] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread Anton Korobeynikov via cfe-commits

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


[llvm] [clang] [mlir] [compiler-rt] [clang-tools-extra] [lldb] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread Anton Korobeynikov via cfe-commits


@@ -46,64 +46,64 @@ class Triple {
   enum ArchType {
 UnknownArch,
 
-arm,// ARM (little endian): arm, armv.*, xscale

asl wrote:

You can ignore these.

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


[llvm] [clang] [mlir] [compiler-rt] [clang-tools-extra] [lldb] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits


@@ -46,64 +46,64 @@ class Triple {
   enum ArchType {
 UnknownArch,
 
-arm,// ARM (little endian): arm, armv.*, xscale

trcrsired wrote:

without doing code formatting the CI won't pass.

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


[llvm] [clang] [mlir] [compiler-rt] [clang-tools-extra] [lldb] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits


@@ -108,13 +108,9 @@ else()
   linux/HostInfoLinux.cpp
   linux/LibcGlue.cpp
   linux/Support.cpp
+  android/HostInfoAndroid.cpp
+  android/LibcGlue.cpp
   )
-if (CMAKE_SYSTEM_NAME MATCHES "Android")

trcrsired wrote:

I use "Linux" to do canadian compilation from linux to android without using 
android NDK. That is why this is not correct.

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


[llvm] [clang] [mlir] [compiler-rt] [clang-tools-extra] [lldb] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread Anton Korobeynikov via cfe-commits


@@ -108,13 +108,9 @@ else()
   linux/HostInfoLinux.cpp
   linux/LibcGlue.cpp
   linux/Support.cpp
+  android/HostInfoAndroid.cpp
+  android/LibcGlue.cpp
   )
-if (CMAKE_SYSTEM_NAME MATCHES "Android")

asl wrote:

What is wrong with android detection? I doubt this is a proper solution

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


[llvm] [clang] [mlir] [compiler-rt] [clang-tools-extra] [lldb] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread Anton Korobeynikov via cfe-commits


@@ -46,64 +46,64 @@ class Triple {
   enum ArchType {
 UnknownArch,
 
-arm,// ARM (little endian): arm, armv.*, xscale

asl wrote:

Please do not do such large code reformatting. It makes impossible to review 
them

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


[clang] [lldb] [llvm] [mlir] [compiler-rt] [clang-tools-extra] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/77216

>From a1156a564c798192cb7608e28ce9b9ed846a8b1c Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Sat, 6 Jan 2024 20:21:06 -0500
Subject: [PATCH 1/2] Fix Multiple Build Errors on different platforms

Particularly for canadian compilation
---
 .../pseudo/include/CMakeLists.txt |  12 +-
 clang/lib/Tooling/CMakeLists.txt  |  10 +-
 compiler-rt/lib/builtins/fp_compare_impl.inc  |   3 +
 lldb/source/Host/android/HostInfoAndroid.cpp  |   4 +
 lldb/source/Host/android/LibcGlue.cpp |   2 +
 llvm/include/llvm/TargetParser/Triple.h   | 287 +++---
 llvm/lib/Support/Unix/Unix.h  |  17 +-
 mlir/lib/ExecutionEngine/CRunnerUtils.cpp |   4 +-
 8 files changed, 147 insertions(+), 192 deletions(-)

diff --git a/clang-tools-extra/pseudo/include/CMakeLists.txt 
b/clang-tools-extra/pseudo/include/CMakeLists.txt
index 2334cfa12e3376..605f17dd4591a0 100644
--- a/clang-tools-extra/pseudo/include/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -3,10 +3,18 @@ set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx/cxx.bnf)
 
 setup_host_tool(clang-pseudo-gen CLANG_PSEUDO_GEN pseudo_gen pseudo_gen_target)
 
+if(NOT DEFINED CLANG_PSEUDO_GEN)
+   if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_PSEUDO_GEN "${LLVM_NATIVE_TOOL_DIR}/clang_pseudo_gen")
+   else()
+  set(CLANG_PSEUDO_GEN "${pseudo_gen}")
+   endif()
+endif()
+
 # Generate inc files.
 set(cxx_symbols_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXSymbols.inc)
 add_custom_command(OUTPUT ${cxx_symbols_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-symbol-list
  -o ${cxx_symbols_inc}
@@ -16,7 +24,7 @@ add_custom_command(OUTPUT ${cxx_symbols_inc}
 
 set(cxx_bnf_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXBNF.inc)
 add_custom_command(OUTPUT ${cxx_bnf_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-grammar-content
  -o ${cxx_bnf_inc}
diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt
index aff39e4de13c0b..1510f5fb8a0810 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -53,6 +53,14 @@ else()
 list(APPEND implicitDirs -I ${implicitDir})
   endforeach()
 
+  if(NOT DEFINED CLANG_AST_DUMP)
+if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_AST_DUMP ${LLVM_NATIVE_TOOL_DIR}/clang-ast-dump)
+else()
+  set(CLANG_AST_DUMP $)
+endif()
+  endif()
+
   include(GetClangResourceDir)
   get_clang_resource_dir(resource_dir PREFIX ${LLVM_BINARY_DIR})
   add_custom_command(
@@ -60,7 +68,7 @@ else()
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
   DEPENDS clang-ast-dump clang-resource-headers
   COMMAND
-  $
+  ${CLANG_AST_DUMP}
 # Skip this in debug mode because parsing AST.h is too slow
 --skip-processing=${skip_expensive_processing}
 -I ${resource_dir}/include
diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..b2ebd0737df033 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -18,6 +18,9 @@ typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
 // LLP64 ABIs use long long instead of long.
 typedef long long CMP_RESULT;
+#elif defined(__wasm64__)
+// GCC uses int as CMP_RESULT
+typedef int CMP_RESULT;
 #elif __AVR__
 // AVR uses a single byte for the return value.
 typedef char CMP_RESULT;
diff --git a/lldb/source/Host/android/HostInfoAndroid.cpp 
b/lldb/source/Host/android/HostInfoAndroid.cpp
index 68440e016afe4b..5ba2f0e24a8d24 100644
--- a/lldb/source/Host/android/HostInfoAndroid.cpp
+++ b/lldb/source/Host/android/HostInfoAndroid.cpp
@@ -6,6 +6,8 @@
 //
 
//===--===//
 
+#ifdef __ANDROID__
+
 #include "lldb/Host/android/HostInfoAndroid.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/linux/HostInfoLinux.h"
@@ -92,3 +94,5 @@ bool HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec 
_spec) {
 
   return FileSystem::Instance().Exists(file_spec);
 }
+
+#endif
diff --git a/lldb/source/Host/android/LibcGlue.cpp 
b/lldb/source/Host/android/LibcGlue.cpp
index 877d735823feee..82b257719c2c8a 100644
--- a/lldb/source/Host/android/LibcGlue.cpp
+++ b/lldb/source/Host/android/LibcGlue.cpp
@@ -8,6 +8,7 @@
 
 // This files adds functions missing from libc on earlier versions of Android
 
+#ifdef __ANDROID__
 #include 
 
 #include 
@@ -26,3 +27,4 @@ time_t timegm(struct tm *t) { return (time_t)timegm64(t); }
 int posix_openpt(int flags) { return open("/dev/ptmx", flags); }
 
 #endif
+#endif
diff --git a/llvm/include/llvm/TargetParser/Triple.h 

[clang] [lldb] [llvm] [mlir] [compiler-rt] [clang-tools-extra] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/77216

>From a1156a564c798192cb7608e28ce9b9ed846a8b1c Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Sat, 6 Jan 2024 20:21:06 -0500
Subject: [PATCH 1/2] Fix Multiple Build Errors on different platforms

Particularly for canadian compilation
---
 .../pseudo/include/CMakeLists.txt |  12 +-
 clang/lib/Tooling/CMakeLists.txt  |  10 +-
 compiler-rt/lib/builtins/fp_compare_impl.inc  |   3 +
 lldb/source/Host/android/HostInfoAndroid.cpp  |   4 +
 lldb/source/Host/android/LibcGlue.cpp |   2 +
 llvm/include/llvm/TargetParser/Triple.h   | 287 +++---
 llvm/lib/Support/Unix/Unix.h  |  17 +-
 mlir/lib/ExecutionEngine/CRunnerUtils.cpp |   4 +-
 8 files changed, 147 insertions(+), 192 deletions(-)

diff --git a/clang-tools-extra/pseudo/include/CMakeLists.txt 
b/clang-tools-extra/pseudo/include/CMakeLists.txt
index 2334cfa12e3376..605f17dd4591a0 100644
--- a/clang-tools-extra/pseudo/include/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -3,10 +3,18 @@ set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx/cxx.bnf)
 
 setup_host_tool(clang-pseudo-gen CLANG_PSEUDO_GEN pseudo_gen pseudo_gen_target)
 
+if(NOT DEFINED CLANG_PSEUDO_GEN)
+   if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_PSEUDO_GEN "${LLVM_NATIVE_TOOL_DIR}/clang_pseudo_gen")
+   else()
+  set(CLANG_PSEUDO_GEN "${pseudo_gen}")
+   endif()
+endif()
+
 # Generate inc files.
 set(cxx_symbols_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXSymbols.inc)
 add_custom_command(OUTPUT ${cxx_symbols_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-symbol-list
  -o ${cxx_symbols_inc}
@@ -16,7 +24,7 @@ add_custom_command(OUTPUT ${cxx_symbols_inc}
 
 set(cxx_bnf_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXBNF.inc)
 add_custom_command(OUTPUT ${cxx_bnf_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-grammar-content
  -o ${cxx_bnf_inc}
diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt
index aff39e4de13c0b..1510f5fb8a0810 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -53,6 +53,14 @@ else()
 list(APPEND implicitDirs -I ${implicitDir})
   endforeach()
 
+  if(NOT DEFINED CLANG_AST_DUMP)
+if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_AST_DUMP ${LLVM_NATIVE_TOOL_DIR}/clang-ast-dump)
+else()
+  set(CLANG_AST_DUMP $)
+endif()
+  endif()
+
   include(GetClangResourceDir)
   get_clang_resource_dir(resource_dir PREFIX ${LLVM_BINARY_DIR})
   add_custom_command(
@@ -60,7 +68,7 @@ else()
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
   DEPENDS clang-ast-dump clang-resource-headers
   COMMAND
-  $
+  ${CLANG_AST_DUMP}
 # Skip this in debug mode because parsing AST.h is too slow
 --skip-processing=${skip_expensive_processing}
 -I ${resource_dir}/include
diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..b2ebd0737df033 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -18,6 +18,9 @@ typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
 // LLP64 ABIs use long long instead of long.
 typedef long long CMP_RESULT;
+#elif defined(__wasm64__)
+// GCC uses int as CMP_RESULT
+typedef int CMP_RESULT;
 #elif __AVR__
 // AVR uses a single byte for the return value.
 typedef char CMP_RESULT;
diff --git a/lldb/source/Host/android/HostInfoAndroid.cpp 
b/lldb/source/Host/android/HostInfoAndroid.cpp
index 68440e016afe4b..5ba2f0e24a8d24 100644
--- a/lldb/source/Host/android/HostInfoAndroid.cpp
+++ b/lldb/source/Host/android/HostInfoAndroid.cpp
@@ -6,6 +6,8 @@
 //
 
//===--===//
 
+#ifdef __ANDROID__
+
 #include "lldb/Host/android/HostInfoAndroid.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/linux/HostInfoLinux.h"
@@ -92,3 +94,5 @@ bool HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec 
_spec) {
 
   return FileSystem::Instance().Exists(file_spec);
 }
+
+#endif
diff --git a/lldb/source/Host/android/LibcGlue.cpp 
b/lldb/source/Host/android/LibcGlue.cpp
index 877d735823feee..82b257719c2c8a 100644
--- a/lldb/source/Host/android/LibcGlue.cpp
+++ b/lldb/source/Host/android/LibcGlue.cpp
@@ -8,6 +8,7 @@
 
 // This files adds functions missing from libc on earlier versions of Android
 
+#ifdef __ANDROID__
 #include 
 
 #include 
@@ -26,3 +27,4 @@ time_t timegm(struct tm *t) { return (time_t)timegm64(t); }
 int posix_openpt(int flags) { return open("/dev/ptmx", flags); }
 
 #endif
+#endif
diff --git a/llvm/include/llvm/TargetParser/Triple.h 

[clang] [lldb] [llvm] [mlir] [compiler-rt] [clang-tools-extra] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-execution-engine

Author: cqwrteur (trcrsired)


Changes

Particularly for canadian compilation

---

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


8 Files Affected:

- (modified) clang-tools-extra/pseudo/include/CMakeLists.txt (+10-2) 
- (modified) clang/lib/Tooling/CMakeLists.txt (+9-1) 
- (modified) compiler-rt/lib/builtins/fp_compare_impl.inc (+3) 
- (modified) lldb/source/Host/android/HostInfoAndroid.cpp (+4) 
- (modified) lldb/source/Host/android/LibcGlue.cpp (+2) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+107-180) 
- (modified) llvm/lib/Support/Unix/Unix.h (+10-7) 
- (modified) mlir/lib/ExecutionEngine/CRunnerUtils.cpp (+2-2) 


``diff
diff --git a/clang-tools-extra/pseudo/include/CMakeLists.txt 
b/clang-tools-extra/pseudo/include/CMakeLists.txt
index 2334cfa12e3376..605f17dd4591a0 100644
--- a/clang-tools-extra/pseudo/include/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -3,10 +3,18 @@ set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx/cxx.bnf)
 
 setup_host_tool(clang-pseudo-gen CLANG_PSEUDO_GEN pseudo_gen pseudo_gen_target)
 
+if(NOT DEFINED CLANG_PSEUDO_GEN)
+   if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_PSEUDO_GEN "${LLVM_NATIVE_TOOL_DIR}/clang_pseudo_gen")
+   else()
+  set(CLANG_PSEUDO_GEN "${pseudo_gen}")
+   endif()
+endif()
+
 # Generate inc files.
 set(cxx_symbols_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXSymbols.inc)
 add_custom_command(OUTPUT ${cxx_symbols_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-symbol-list
  -o ${cxx_symbols_inc}
@@ -16,7 +24,7 @@ add_custom_command(OUTPUT ${cxx_symbols_inc}
 
 set(cxx_bnf_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXBNF.inc)
 add_custom_command(OUTPUT ${cxx_bnf_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-grammar-content
  -o ${cxx_bnf_inc}
diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt
index aff39e4de13c0b..1510f5fb8a0810 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -53,6 +53,14 @@ else()
 list(APPEND implicitDirs -I ${implicitDir})
   endforeach()
 
+  if(NOT DEFINED CLANG_AST_DUMP)
+if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_AST_DUMP ${LLVM_NATIVE_TOOL_DIR}/clang-ast-dump)
+else()
+  set(CLANG_AST_DUMP $)
+endif()
+  endif()
+
   include(GetClangResourceDir)
   get_clang_resource_dir(resource_dir PREFIX ${LLVM_BINARY_DIR})
   add_custom_command(
@@ -60,7 +68,7 @@ else()
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
   DEPENDS clang-ast-dump clang-resource-headers
   COMMAND
-  $
+  ${CLANG_AST_DUMP}
 # Skip this in debug mode because parsing AST.h is too slow
 --skip-processing=${skip_expensive_processing}
 -I ${resource_dir}/include
diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..b2ebd0737df033 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -18,6 +18,9 @@ typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
 // LLP64 ABIs use long long instead of long.
 typedef long long CMP_RESULT;
+#elif defined(__wasm64__)
+// GCC uses int as CMP_RESULT
+typedef int CMP_RESULT;
 #elif __AVR__
 // AVR uses a single byte for the return value.
 typedef char CMP_RESULT;
diff --git a/lldb/source/Host/android/HostInfoAndroid.cpp 
b/lldb/source/Host/android/HostInfoAndroid.cpp
index 68440e016afe4b..5ba2f0e24a8d24 100644
--- a/lldb/source/Host/android/HostInfoAndroid.cpp
+++ b/lldb/source/Host/android/HostInfoAndroid.cpp
@@ -6,6 +6,8 @@
 //
 
//===--===//
 
+#ifdef __ANDROID__
+
 #include "lldb/Host/android/HostInfoAndroid.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/linux/HostInfoLinux.h"
@@ -92,3 +94,5 @@ bool HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec 
_spec) {
 
   return FileSystem::Instance().Exists(file_spec);
 }
+
+#endif
diff --git a/lldb/source/Host/android/LibcGlue.cpp 
b/lldb/source/Host/android/LibcGlue.cpp
index 877d735823feee..82b257719c2c8a 100644
--- a/lldb/source/Host/android/LibcGlue.cpp
+++ b/lldb/source/Host/android/LibcGlue.cpp
@@ -8,6 +8,7 @@
 
 // This files adds functions missing from libc on earlier versions of Android
 
+#ifdef __ANDROID__
 #include 
 
 #include 
@@ -26,3 +27,4 @@ time_t timegm(struct tm *t) { return (time_t)timegm64(t); }
 int posix_openpt(int flags) { return open("/dev/ptmx", flags); }
 
 #endif
+#endif
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 47904621c0967f..e022ad68c96511 

[mlir] [clang] [llvm] [clang-tools-extra] [lldb] [compiler-rt] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cqwrteur (trcrsired)


Changes

Particularly for canadian compilation

---

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


8 Files Affected:

- (modified) clang-tools-extra/pseudo/include/CMakeLists.txt (+10-2) 
- (modified) clang/lib/Tooling/CMakeLists.txt (+9-1) 
- (modified) compiler-rt/lib/builtins/fp_compare_impl.inc (+3) 
- (modified) lldb/source/Host/android/HostInfoAndroid.cpp (+4) 
- (modified) lldb/source/Host/android/LibcGlue.cpp (+2) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+107-180) 
- (modified) llvm/lib/Support/Unix/Unix.h (+10-7) 
- (modified) mlir/lib/ExecutionEngine/CRunnerUtils.cpp (+2-2) 


``diff
diff --git a/clang-tools-extra/pseudo/include/CMakeLists.txt 
b/clang-tools-extra/pseudo/include/CMakeLists.txt
index 2334cfa12e3376..605f17dd4591a0 100644
--- a/clang-tools-extra/pseudo/include/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -3,10 +3,18 @@ set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx/cxx.bnf)
 
 setup_host_tool(clang-pseudo-gen CLANG_PSEUDO_GEN pseudo_gen pseudo_gen_target)
 
+if(NOT DEFINED CLANG_PSEUDO_GEN)
+   if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_PSEUDO_GEN "${LLVM_NATIVE_TOOL_DIR}/clang_pseudo_gen")
+   else()
+  set(CLANG_PSEUDO_GEN "${pseudo_gen}")
+   endif()
+endif()
+
 # Generate inc files.
 set(cxx_symbols_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXSymbols.inc)
 add_custom_command(OUTPUT ${cxx_symbols_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-symbol-list
  -o ${cxx_symbols_inc}
@@ -16,7 +24,7 @@ add_custom_command(OUTPUT ${cxx_symbols_inc}
 
 set(cxx_bnf_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXBNF.inc)
 add_custom_command(OUTPUT ${cxx_bnf_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-grammar-content
  -o ${cxx_bnf_inc}
diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt
index aff39e4de13c0b..1510f5fb8a0810 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -53,6 +53,14 @@ else()
 list(APPEND implicitDirs -I ${implicitDir})
   endforeach()
 
+  if(NOT DEFINED CLANG_AST_DUMP)
+if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_AST_DUMP ${LLVM_NATIVE_TOOL_DIR}/clang-ast-dump)
+else()
+  set(CLANG_AST_DUMP $)
+endif()
+  endif()
+
   include(GetClangResourceDir)
   get_clang_resource_dir(resource_dir PREFIX ${LLVM_BINARY_DIR})
   add_custom_command(
@@ -60,7 +68,7 @@ else()
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
   DEPENDS clang-ast-dump clang-resource-headers
   COMMAND
-  $
+  ${CLANG_AST_DUMP}
 # Skip this in debug mode because parsing AST.h is too slow
 --skip-processing=${skip_expensive_processing}
 -I ${resource_dir}/include
diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..b2ebd0737df033 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -18,6 +18,9 @@ typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
 // LLP64 ABIs use long long instead of long.
 typedef long long CMP_RESULT;
+#elif defined(__wasm64__)
+// GCC uses int as CMP_RESULT
+typedef int CMP_RESULT;
 #elif __AVR__
 // AVR uses a single byte for the return value.
 typedef char CMP_RESULT;
diff --git a/lldb/source/Host/android/HostInfoAndroid.cpp 
b/lldb/source/Host/android/HostInfoAndroid.cpp
index 68440e016afe4b..5ba2f0e24a8d24 100644
--- a/lldb/source/Host/android/HostInfoAndroid.cpp
+++ b/lldb/source/Host/android/HostInfoAndroid.cpp
@@ -6,6 +6,8 @@
 //
 
//===--===//
 
+#ifdef __ANDROID__
+
 #include "lldb/Host/android/HostInfoAndroid.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/linux/HostInfoLinux.h"
@@ -92,3 +94,5 @@ bool HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec 
_spec) {
 
   return FileSystem::Instance().Exists(file_spec);
 }
+
+#endif
diff --git a/lldb/source/Host/android/LibcGlue.cpp 
b/lldb/source/Host/android/LibcGlue.cpp
index 877d735823feee..82b257719c2c8a 100644
--- a/lldb/source/Host/android/LibcGlue.cpp
+++ b/lldb/source/Host/android/LibcGlue.cpp
@@ -8,6 +8,7 @@
 
 // This files adds functions missing from libc on earlier versions of Android
 
+#ifdef __ANDROID__
 #include 
 
 #include 
@@ -26,3 +27,4 @@ time_t timegm(struct tm *t) { return (time_t)timegm64(t); }
 int posix_openpt(int flags) { return open("/dev/ptmx", flags); }
 
 #endif
+#endif
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 47904621c0967f..e022ad68c96511 100644
--- 

[clang] [llvm] [lldb] [clang-tools-extra] [mlir] [compiler-rt] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: cqwrteur (trcrsired)


Changes

Particularly for canadian compilation

---

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


8 Files Affected:

- (modified) clang-tools-extra/pseudo/include/CMakeLists.txt (+10-2) 
- (modified) clang/lib/Tooling/CMakeLists.txt (+9-1) 
- (modified) compiler-rt/lib/builtins/fp_compare_impl.inc (+3) 
- (modified) lldb/source/Host/android/HostInfoAndroid.cpp (+4) 
- (modified) lldb/source/Host/android/LibcGlue.cpp (+2) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+107-180) 
- (modified) llvm/lib/Support/Unix/Unix.h (+10-7) 
- (modified) mlir/lib/ExecutionEngine/CRunnerUtils.cpp (+2-2) 


``diff
diff --git a/clang-tools-extra/pseudo/include/CMakeLists.txt 
b/clang-tools-extra/pseudo/include/CMakeLists.txt
index 2334cfa12e3376..605f17dd4591a0 100644
--- a/clang-tools-extra/pseudo/include/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -3,10 +3,18 @@ set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx/cxx.bnf)
 
 setup_host_tool(clang-pseudo-gen CLANG_PSEUDO_GEN pseudo_gen pseudo_gen_target)
 
+if(NOT DEFINED CLANG_PSEUDO_GEN)
+   if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_PSEUDO_GEN "${LLVM_NATIVE_TOOL_DIR}/clang_pseudo_gen")
+   else()
+  set(CLANG_PSEUDO_GEN "${pseudo_gen}")
+   endif()
+endif()
+
 # Generate inc files.
 set(cxx_symbols_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXSymbols.inc)
 add_custom_command(OUTPUT ${cxx_symbols_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-symbol-list
  -o ${cxx_symbols_inc}
@@ -16,7 +24,7 @@ add_custom_command(OUTPUT ${cxx_symbols_inc}
 
 set(cxx_bnf_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXBNF.inc)
 add_custom_command(OUTPUT ${cxx_bnf_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-grammar-content
  -o ${cxx_bnf_inc}
diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt
index aff39e4de13c0b..1510f5fb8a0810 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -53,6 +53,14 @@ else()
 list(APPEND implicitDirs -I ${implicitDir})
   endforeach()
 
+  if(NOT DEFINED CLANG_AST_DUMP)
+if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_AST_DUMP ${LLVM_NATIVE_TOOL_DIR}/clang-ast-dump)
+else()
+  set(CLANG_AST_DUMP $)
+endif()
+  endif()
+
   include(GetClangResourceDir)
   get_clang_resource_dir(resource_dir PREFIX ${LLVM_BINARY_DIR})
   add_custom_command(
@@ -60,7 +68,7 @@ else()
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
   DEPENDS clang-ast-dump clang-resource-headers
   COMMAND
-  $
+  ${CLANG_AST_DUMP}
 # Skip this in debug mode because parsing AST.h is too slow
 --skip-processing=${skip_expensive_processing}
 -I ${resource_dir}/include
diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..b2ebd0737df033 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -18,6 +18,9 @@ typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
 // LLP64 ABIs use long long instead of long.
 typedef long long CMP_RESULT;
+#elif defined(__wasm64__)
+// GCC uses int as CMP_RESULT
+typedef int CMP_RESULT;
 #elif __AVR__
 // AVR uses a single byte for the return value.
 typedef char CMP_RESULT;
diff --git a/lldb/source/Host/android/HostInfoAndroid.cpp 
b/lldb/source/Host/android/HostInfoAndroid.cpp
index 68440e016afe4b..5ba2f0e24a8d24 100644
--- a/lldb/source/Host/android/HostInfoAndroid.cpp
+++ b/lldb/source/Host/android/HostInfoAndroid.cpp
@@ -6,6 +6,8 @@
 //
 
//===--===//
 
+#ifdef __ANDROID__
+
 #include "lldb/Host/android/HostInfoAndroid.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/linux/HostInfoLinux.h"
@@ -92,3 +94,5 @@ bool HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec 
_spec) {
 
   return FileSystem::Instance().Exists(file_spec);
 }
+
+#endif
diff --git a/lldb/source/Host/android/LibcGlue.cpp 
b/lldb/source/Host/android/LibcGlue.cpp
index 877d735823feee..82b257719c2c8a 100644
--- a/lldb/source/Host/android/LibcGlue.cpp
+++ b/lldb/source/Host/android/LibcGlue.cpp
@@ -8,6 +8,7 @@
 
 // This files adds functions missing from libc on earlier versions of Android
 
+#ifdef __ANDROID__
 #include 
 
 #include 
@@ -26,3 +27,4 @@ time_t timegm(struct tm *t) { return (time_t)timegm64(t); }
 int posix_openpt(int flags) { return open("/dev/ptmx", flags); }
 
 #endif
+#endif
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 47904621c0967f..e022ad68c96511 100644
--- 

[mlir] [clang] [llvm] [clang-tools-extra] [lldb] [compiler-rt] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 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/77216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [clang] [llvm] [clang-tools-extra] [lldb] [compiler-rt] Fix Multiple Build Errors on different platforms (PR #77216)

2024-01-06 Thread via cfe-commits

https://github.com/trcrsired created 
https://github.com/llvm/llvm-project/pull/77216

Particularly for canadian compilation

>From a1156a564c798192cb7608e28ce9b9ed846a8b1c Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Sat, 6 Jan 2024 20:21:06 -0500
Subject: [PATCH] Fix Multiple Build Errors on different platforms

Particularly for canadian compilation
---
 .../pseudo/include/CMakeLists.txt |  12 +-
 clang/lib/Tooling/CMakeLists.txt  |  10 +-
 compiler-rt/lib/builtins/fp_compare_impl.inc  |   3 +
 lldb/source/Host/android/HostInfoAndroid.cpp  |   4 +
 lldb/source/Host/android/LibcGlue.cpp |   2 +
 llvm/include/llvm/TargetParser/Triple.h   | 287 +++---
 llvm/lib/Support/Unix/Unix.h  |  17 +-
 mlir/lib/ExecutionEngine/CRunnerUtils.cpp |   4 +-
 8 files changed, 147 insertions(+), 192 deletions(-)

diff --git a/clang-tools-extra/pseudo/include/CMakeLists.txt 
b/clang-tools-extra/pseudo/include/CMakeLists.txt
index 2334cfa12e3376..605f17dd4591a0 100644
--- a/clang-tools-extra/pseudo/include/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -3,10 +3,18 @@ set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx/cxx.bnf)
 
 setup_host_tool(clang-pseudo-gen CLANG_PSEUDO_GEN pseudo_gen pseudo_gen_target)
 
+if(NOT DEFINED CLANG_PSEUDO_GEN)
+   if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_PSEUDO_GEN "${LLVM_NATIVE_TOOL_DIR}/clang_pseudo_gen")
+   else()
+  set(CLANG_PSEUDO_GEN "${pseudo_gen}")
+   endif()
+endif()
+
 # Generate inc files.
 set(cxx_symbols_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXSymbols.inc)
 add_custom_command(OUTPUT ${cxx_symbols_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-symbol-list
  -o ${cxx_symbols_inc}
@@ -16,7 +24,7 @@ add_custom_command(OUTPUT ${cxx_symbols_inc}
 
 set(cxx_bnf_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXBNF.inc)
 add_custom_command(OUTPUT ${cxx_bnf_inc}
-   COMMAND "${pseudo_gen}"
+   COMMAND "${CLANG_PSEUDO_GEN}"
  --grammar ${cxx_bnf}
  --emit-grammar-content
  -o ${cxx_bnf_inc}
diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt
index aff39e4de13c0b..1510f5fb8a0810 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -53,6 +53,14 @@ else()
 list(APPEND implicitDirs -I ${implicitDir})
   endforeach()
 
+  if(NOT DEFINED CLANG_AST_DUMP)
+if(DEFINED LLVM_NATIVE_TOOL_DIR AND NOT LLVM_NATIVE_TOOL_DIR STREQUAL "")
+  set(CLANG_AST_DUMP ${LLVM_NATIVE_TOOL_DIR}/clang-ast-dump)
+else()
+  set(CLANG_AST_DUMP $)
+endif()
+  endif()
+
   include(GetClangResourceDir)
   get_clang_resource_dir(resource_dir PREFIX ${LLVM_BINARY_DIR})
   add_custom_command(
@@ -60,7 +68,7 @@ else()
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
   DEPENDS clang-ast-dump clang-resource-headers
   COMMAND
-  $
+  ${CLANG_AST_DUMP}
 # Skip this in debug mode because parsing AST.h is too slow
 --skip-processing=${skip_expensive_processing}
 -I ${resource_dir}/include
diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..b2ebd0737df033 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -18,6 +18,9 @@ typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
 // LLP64 ABIs use long long instead of long.
 typedef long long CMP_RESULT;
+#elif defined(__wasm64__)
+// GCC uses int as CMP_RESULT
+typedef int CMP_RESULT;
 #elif __AVR__
 // AVR uses a single byte for the return value.
 typedef char CMP_RESULT;
diff --git a/lldb/source/Host/android/HostInfoAndroid.cpp 
b/lldb/source/Host/android/HostInfoAndroid.cpp
index 68440e016afe4b..5ba2f0e24a8d24 100644
--- a/lldb/source/Host/android/HostInfoAndroid.cpp
+++ b/lldb/source/Host/android/HostInfoAndroid.cpp
@@ -6,6 +6,8 @@
 //
 
//===--===//
 
+#ifdef __ANDROID__
+
 #include "lldb/Host/android/HostInfoAndroid.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/linux/HostInfoLinux.h"
@@ -92,3 +94,5 @@ bool HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec 
_spec) {
 
   return FileSystem::Instance().Exists(file_spec);
 }
+
+#endif
diff --git a/lldb/source/Host/android/LibcGlue.cpp 
b/lldb/source/Host/android/LibcGlue.cpp
index 877d735823feee..82b257719c2c8a 100644
--- a/lldb/source/Host/android/LibcGlue.cpp
+++ b/lldb/source/Host/android/LibcGlue.cpp
@@ -8,6 +8,7 @@
 
 // This files adds functions missing from libc on earlier versions of Android
 
+#ifdef __ANDROID__
 #include 
 
 #include 
@@ -26,3 +27,4 @@ time_t timegm(struct tm *t) { return (time_t)timegm64(t); }
 int posix_openpt(int flags) { return open("/dev/ptmx", flags); }
 
 #endif
+#endif
diff --git 

[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-06 Thread Hana Dusíková via cfe-commits

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-06 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/77214

From 8f1370aae4db2048c35516a85fb72c742557942b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sun, 7 Jan 2024 00:13:08 +0100
Subject: [PATCH] [coverage] fix incorrect coverage reporting for "if
 constexpr" and "if consteval"

---
 clang/include/clang/AST/Stmt.h   |  6 --
 clang/lib/CodeGen/CoverageMappingGen.cpp | 13 +++--
 clang/lib/Sema/TreeTransform.h   |  7 ++-
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211..e1fde24e647789 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1631,8 +1631,10 @@ class CompoundStmt final
   SourceLocation RB);
 
   // Build an empty compound statement with a location.
-  explicit CompoundStmt(SourceLocation Loc)
-  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
+  explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
+
+  CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
+  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
 CompoundStmtBits.NumStmts = 0;
 CompoundStmtBits.HasFPFeatures = 0;
   }
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index bf227386a71b78..b245abd16c3f4a 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1712,7 +1712,11 @@ struct CounterCoverageMappingBuilder
   extendRegion(S->getCond());
 
 Counter ParentCount = getRegion().getCounter();
-Counter ThenCount = getRegionCounter(S);
+
+// If this is "if !consteval" the then-branch will never be taken, we don't
+// need to change counter
+Counter ThenCount =
+S->isNegatedConsteval() ? ParentCount : getRegionCounter(S);
 
 if (!S->isConsteval()) {
   // Emitting a counter for the condition makes it easier to interpret the
@@ -1729,7 +1733,12 @@ struct CounterCoverageMappingBuilder
 extendRegion(S->getThen());
 Counter OutCount = propagateCounts(ThenCount, S->getThen());
 
-Counter ElseCount = subtractCounters(ParentCount, ThenCount);
+// If this is "if consteval" the else-branch will never be taken, we don't
+// need to change counter
+Counter ElseCount = S->isNonNegatedConsteval()
+? ParentCount
+: subtractCounters(ParentCount, ThenCount);
+
 if (const Stmt *Else = S->getElse()) {
   bool ThenHasTerminateStmt = HasTerminateStmt;
   HasTerminateStmt = false;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c8c5a51bf9f94e..0033c851b618a1 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7732,7 +7732,8 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 if (Then.isInvalid())
   return StmtError();
   } else {
-Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
+Then = new (getSema().Context)
+CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
   }
 
   // Transform the "else" branch.
@@ -7741,6 +7742,10 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 Else = getDerived().TransformStmt(S->getElse());
 if (Else.isInvalid())
   return StmtError();
+  } else if (S->getElse() && ConstexprConditionValue &&
+ *ConstexprConditionValue) {
+Else = new (getSema().Context)
+CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
   }
 
   if (!getDerived().AlwaysRebuild() &&

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/77045

>From d9cbbe48b96d27bff3fc926b60d039ed05f00489 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 5 Jan 2024 01:23:16 -0300
Subject: [PATCH 1/5] [clang-format] Fix crash involving array designators and
 dangling comma Fixes llvm/llvm-project#76716 Added a check to prevent null
 deferencing

---
 clang/lib/Format/WhitespaceManager.cpp | 3 ++-
 clang/unittests/Format/FormatTest.cpp  | 6 ++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 3bc6915b8df0a7..95693f4588c631 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1444,7 +1444,8 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+const FormatToken *Next = C.Tok->getNextNonComment();
+if (Next && Next->isNot(tok::r_brace)) // dangling comma
   ++Cell;
   }
 } else if (Depth == 1) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..c9f91953c13f52 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21084,6 +21084,12 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   "};",
   Style);
 
+  verifyNoCrash("Foo f[] = {\n"
+"[0] = { 1, },\n"
+"[1] { 1, },\n"
+"};",
+Style);
+
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\", {\"x\", 
"
"\"dy\"}   },\n"

>From 78e006de352cb801f6c07ac7f6bd0ab881560406 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 5 Jan 2024 11:32:37 -0300
Subject: [PATCH 2/5] Addresses comments

---
 clang/lib/Format/WhitespaceManager.cpp | 6 --
 clang/unittests/Format/FormatTest.cpp  | 6 ++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 95693f4588c631..aeac0ba0c6d03c 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1444,9 +1444,11 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-const FormatToken *Next = C.Tok->getNextNonComment();
-if (Next && Next->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // dangling comma
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index c9f91953c13f52..d6f561e822d08a 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20842,6 +20842,12 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
   "};",
   Style);
 
+  verifyNoCrash("Foo f[] = {\n"
+"[0] = { 1, },\n"
+"[1] { 1, },\n"
+"};",
+Style);
+
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\",  "
"  {\"x\", \"dy\"}},\n"

>From 3f82d6664de1ea06589393ff27aced4e4177a72c Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 5 Jan 2024 16:21:33 -0300
Subject: [PATCH 3/5] Fix real problem

---
 clang/lib/Format/WhitespaceManager.cpp |  7 +--
 clang/unittests/Format/FormatTest.cpp  | 10 ++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index aeac0ba0c6d03c..e91ec6afec74af 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1455,8 +1455,11 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+!MatchingParen->MatchingParen->Previous->is(tok::equal)
+? Cell + 1
+: Cell);
 // Go to the next non-comment and ensure there is a break in front
 const auto *NextNonComment = 

[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-06 Thread Hana Dusíková via cfe-commits

hanickadot wrote:

https://github.com/llvm/llvm-project/assets/6557263/47ff77c0-9101-44cf-b2d5-ffea514bfc0c;>

(notice wrong coverage "if constexpr" for positive one, and completely missing 
for negative one, also notice "if consteval" marking always the same branch as 
uncovered)



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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-06 Thread Hana Dusíková via cfe-commits

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Hana Dusíková (hanickadot)


Changes

It was a while since I noticed coverage report is broken for "if constexpr" and 
"if consteval" (as shown on first picture).
img width="453" alt="Screenshot 2024-01-07 at 00 29 17" 
src="https://github.com/llvm/llvm-project/assets/6557263/dbdbc8a6-ad16-44da-882d-8e229ee69093";
(notice wrong coverage "if constexpr" for positive one, and completely missing 
for negative one, also notice "if consteval" marking always the same branch as 
uncovered)

Report after this change:
img width="453" alt="Screenshot 2024-01-07 at 00 25 32" 
src="https://github.com/llvm/llvm-project/assets/6557263/d7ca85b0-34c7-40b5-9cc7-4efd8c18649b";

Main problem was replacement of non-taken "if constexpr" branch with `NullStmt` 
but such object doesn't have begin/end for source location properly. So I 
introduce a new constructor for empty `CompoundStmt` and used it.

With "if consteval" I'm no longer introducing new branch counter for non-taken 
"branch". But in future it would be useful to mark whole gap there as skipped 
instead. If there is interest I would do it in another PR.

---
Full diff: https://github.com/llvm/llvm-project/pull/77214.diff


3 Files Affected:

- (modified) clang/include/clang/AST/Stmt.h (+4-2) 
- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+11-2) 
- (modified) clang/lib/Sema/TreeTransform.h (+6-1) 


``diff
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211..fb50212083316e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1631,8 +1631,10 @@ class CompoundStmt final
   SourceLocation RB);
 
   // Build an empty compound statement with a location.
-  explicit CompoundStmt(SourceLocation Loc)
-  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
+  explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
+
+  explicit CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
+  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
 CompoundStmtBits.NumStmts = 0;
 CompoundStmtBits.HasFPFeatures = 0;
   }
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index bf227386a71b78..b245abd16c3f4a 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1712,7 +1712,11 @@ struct CounterCoverageMappingBuilder
   extendRegion(S->getCond());
 
 Counter ParentCount = getRegion().getCounter();
-Counter ThenCount = getRegionCounter(S);
+
+// If this is "if !consteval" the then-branch will never be taken, we don't
+// need to change counter
+Counter ThenCount =
+S->isNegatedConsteval() ? ParentCount : getRegionCounter(S);
 
 if (!S->isConsteval()) {
   // Emitting a counter for the condition makes it easier to interpret the
@@ -1729,7 +1733,12 @@ struct CounterCoverageMappingBuilder
 extendRegion(S->getThen());
 Counter OutCount = propagateCounts(ThenCount, S->getThen());
 
-Counter ElseCount = subtractCounters(ParentCount, ThenCount);
+// If this is "if consteval" the else-branch will never be taken, we don't
+// need to change counter
+Counter ElseCount = S->isNonNegatedConsteval()
+? ParentCount
+: subtractCounters(ParentCount, ThenCount);
+
 if (const Stmt *Else = S->getElse()) {
   bool ThenHasTerminateStmt = HasTerminateStmt;
   HasTerminateStmt = false;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c8c5a51bf9f94e..0033c851b618a1 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7732,7 +7732,8 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 if (Then.isInvalid())
   return StmtError();
   } else {
-Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
+Then = new (getSema().Context)
+CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
   }
 
   // Transform the "else" branch.
@@ -7741,6 +7742,10 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 Else = getDerived().TransformStmt(S->getElse());
 if (Else.isInvalid())
   return StmtError();
+  } else if (S->getElse() && ConstexprConditionValue &&
+ *ConstexprConditionValue) {
+Else = new (getSema().Context)
+CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
   }
 
   if (!getDerived().AlwaysRebuild() &&

``




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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-06 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot created 
https://github.com/llvm/llvm-project/pull/77214

It was a while since I noticed coverage report is broken for "if constexpr" and 
"if consteval" (as shown on first picture).
https://github.com/llvm/llvm-project/assets/6557263/dbdbc8a6-ad16-44da-882d-8e229ee69093;>
(notice wrong coverage "if constexpr" for positive one, and completely missing 
for negative one, also notice "if consteval" marking always the same branch as 
uncovered)

Report after this change:
https://github.com/llvm/llvm-project/assets/6557263/d7ca85b0-34c7-40b5-9cc7-4efd8c18649b;>

Main problem was replacement of non-taken "if constexpr" branch with `NullStmt` 
but such object doesn't have begin/end for source location properly. So I 
introduce a new constructor for empty `CompoundStmt` and used it.

With "if consteval" I'm no longer introducing new branch counter for non-taken 
"branch". But in future it would be useful to mark whole gap there as skipped 
instead. If there is interest I would do it in another PR.

From 5c6d6b34e544fba61188ab64363cfb1dd29e50ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sun, 7 Jan 2024 00:13:08 +0100
Subject: [PATCH] [coverage] fix incorrect coverage reporting for "if
 constexpr" and "if consteval"

---
 clang/include/clang/AST/Stmt.h   |  6 --
 clang/lib/CodeGen/CoverageMappingGen.cpp | 13 +++--
 clang/lib/Sema/TreeTransform.h   |  7 ++-
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211..fb50212083316e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1631,8 +1631,10 @@ class CompoundStmt final
   SourceLocation RB);
 
   // Build an empty compound statement with a location.
-  explicit CompoundStmt(SourceLocation Loc)
-  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
+  explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
+
+  explicit CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
+  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
 CompoundStmtBits.NumStmts = 0;
 CompoundStmtBits.HasFPFeatures = 0;
   }
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index bf227386a71b78..b245abd16c3f4a 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1712,7 +1712,11 @@ struct CounterCoverageMappingBuilder
   extendRegion(S->getCond());
 
 Counter ParentCount = getRegion().getCounter();
-Counter ThenCount = getRegionCounter(S);
+
+// If this is "if !consteval" the then-branch will never be taken, we don't
+// need to change counter
+Counter ThenCount =
+S->isNegatedConsteval() ? ParentCount : getRegionCounter(S);
 
 if (!S->isConsteval()) {
   // Emitting a counter for the condition makes it easier to interpret the
@@ -1729,7 +1733,12 @@ struct CounterCoverageMappingBuilder
 extendRegion(S->getThen());
 Counter OutCount = propagateCounts(ThenCount, S->getThen());
 
-Counter ElseCount = subtractCounters(ParentCount, ThenCount);
+// If this is "if consteval" the else-branch will never be taken, we don't
+// need to change counter
+Counter ElseCount = S->isNonNegatedConsteval()
+? ParentCount
+: subtractCounters(ParentCount, ThenCount);
+
 if (const Stmt *Else = S->getElse()) {
   bool ThenHasTerminateStmt = HasTerminateStmt;
   HasTerminateStmt = false;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c8c5a51bf9f94e..0033c851b618a1 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7732,7 +7732,8 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 if (Then.isInvalid())
   return StmtError();
   } else {
-Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
+Then = new (getSema().Context)
+CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
   }
 
   // Transform the "else" branch.
@@ -7741,6 +7742,10 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 Else = getDerived().TransformStmt(S->getElse());
 if (Else.isInvalid())
   return StmtError();
+  } else if (S->getElse() && ConstexprConditionValue &&
+ *ConstexprConditionValue) {
+Else = new (getSema().Context)
+CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
   }
 
   if (!getDerived().AlwaysRebuild() &&

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


[clang] [llvm] [clang-tools-extra] [compiler-rt] fix wrong links in documentation (PR #76502)

2024-01-06 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/76502

From 93e8cc7c4310f8b91be4d72f4862f5ed7c06c33b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Thu, 28 Dec 2023 14:30:35 +0100
Subject: [PATCH] [llvm] fix wrong links in documentation

---
 llvm/docs/SphinxQuickstartTemplate.rst| 2 +-
 llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/docs/SphinxQuickstartTemplate.rst 
b/llvm/docs/SphinxQuickstartTemplate.rst
index 956adabce78c24..8d21b43c050d75 100644
--- a/llvm/docs/SphinxQuickstartTemplate.rst
+++ b/llvm/docs/SphinxQuickstartTemplate.rst
@@ -170,7 +170,7 @@ Generating the documentation
 
 You can generate the HTML documentation from the sources locally if you want to
 see what they would look like. In addition to the normal
-`build tools `_
+`build tools `_
 you need to install `Sphinx`_ and the necessary extensions
 using the following command inside the ``llvm-project`` checkout:
 
diff --git a/llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst 
b/llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst
index 17bf8a47c84c78..2e3d4ed0a30873 100644
--- a/llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst
+++ b/llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst
@@ -122,7 +122,7 @@ Configuring the Module
 
 We're now ready to configure our module, to specify the target and
 data layout. This isn't strictly necessary, but the `frontend
-performance guide <../Frontend/PerformanceTips.html>`_ recommends
+performance guide <../../Frontend/PerformanceTips.html>`_ recommends
 this. Optimizations benefit from knowing about the target and data
 layout.
 

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


[clang] [clang-format] Handle templated elaborated type specifier in function… (PR #77013)

2024-01-06 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread Björn Schäpers via cfe-commits


@@ -1444,16 +1444,26 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // dangling comma

HazardyKnusperkeks wrote:

```suggestion
Next && Next->isNot(tok::r_brace)) { // Dangling comma.
```

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread Björn Schäpers via cfe-commits


@@ -1444,16 +1444,26 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // dangling comma
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+// When dealing with C array designators. There is a
+// possibility of some nested array not having an `=`.
+// When this happens we make the cells non retangular,

HazardyKnusperkeks wrote:

```suggestion
// When this happens we make the cells non rectangular,
```

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread Björn Schäpers via cfe-commits

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


[clang] fix wrong links in documentation (PR #76502)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Hana Dusíková (hanickadot)


Changes

Hi, I noticed some links in documentation is pointing to bad url (there were 
two wrong paths)

I also noticed file `llvm/docs/tutorial/BuildingAJIT5.htm` is missing and it's 
pointed from `BuildingAJIT4.htm` but I can fix it :(

---
Full diff: https://github.com/llvm/llvm-project/pull/76502.diff


3 Files Affected:

- (modified) clang/include/clang/AST/Stmt.h (+4-2) 
- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+11-2) 
- (modified) clang/lib/Sema/TreeTransform.h (+6-1) 


``diff
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211..fb50212083316e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1631,8 +1631,10 @@ class CompoundStmt final
   SourceLocation RB);
 
   // Build an empty compound statement with a location.
-  explicit CompoundStmt(SourceLocation Loc)
-  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
+  explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
+
+  explicit CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
+  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
 CompoundStmtBits.NumStmts = 0;
 CompoundStmtBits.HasFPFeatures = 0;
   }
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index bf227386a71b78..b245abd16c3f4a 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1712,7 +1712,11 @@ struct CounterCoverageMappingBuilder
   extendRegion(S->getCond());
 
 Counter ParentCount = getRegion().getCounter();
-Counter ThenCount = getRegionCounter(S);
+
+// If this is "if !consteval" the then-branch will never be taken, we don't
+// need to change counter
+Counter ThenCount =
+S->isNegatedConsteval() ? ParentCount : getRegionCounter(S);
 
 if (!S->isConsteval()) {
   // Emitting a counter for the condition makes it easier to interpret the
@@ -1729,7 +1733,12 @@ struct CounterCoverageMappingBuilder
 extendRegion(S->getThen());
 Counter OutCount = propagateCounts(ThenCount, S->getThen());
 
-Counter ElseCount = subtractCounters(ParentCount, ThenCount);
+// If this is "if consteval" the else-branch will never be taken, we don't
+// need to change counter
+Counter ElseCount = S->isNonNegatedConsteval()
+? ParentCount
+: subtractCounters(ParentCount, ThenCount);
+
 if (const Stmt *Else = S->getElse()) {
   bool ThenHasTerminateStmt = HasTerminateStmt;
   HasTerminateStmt = false;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c8c5a51bf9f94e..0033c851b618a1 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7732,7 +7732,8 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 if (Then.isInvalid())
   return StmtError();
   } else {
-Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
+Then = new (getSema().Context)
+CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
   }
 
   // Transform the "else" branch.
@@ -7741,6 +7742,10 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 Else = getDerived().TransformStmt(S->getElse());
 if (Else.isInvalid())
   return StmtError();
+  } else if (S->getElse() && ConstexprConditionValue &&
+ *ConstexprConditionValue) {
+Else = new (getSema().Context)
+CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
   }
 
   if (!getDerived().AlwaysRebuild() &&

``




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


[clang] fix wrong links in documentation (PR #76502)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Hana Dusíková (hanickadot)


Changes

Hi, I noticed some links in documentation is pointing to bad url (there were 
two wrong paths)

I also noticed file `llvm/docs/tutorial/BuildingAJIT5.htm` is missing and it's 
pointed from `BuildingAJIT4.htm` but I can fix it :(

---
Full diff: https://github.com/llvm/llvm-project/pull/76502.diff


3 Files Affected:

- (modified) clang/include/clang/AST/Stmt.h (+4-2) 
- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+11-2) 
- (modified) clang/lib/Sema/TreeTransform.h (+6-1) 


``diff
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211..fb50212083316e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1631,8 +1631,10 @@ class CompoundStmt final
   SourceLocation RB);
 
   // Build an empty compound statement with a location.
-  explicit CompoundStmt(SourceLocation Loc)
-  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
+  explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
+
+  explicit CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
+  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
 CompoundStmtBits.NumStmts = 0;
 CompoundStmtBits.HasFPFeatures = 0;
   }
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index bf227386a71b78..b245abd16c3f4a 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1712,7 +1712,11 @@ struct CounterCoverageMappingBuilder
   extendRegion(S->getCond());
 
 Counter ParentCount = getRegion().getCounter();
-Counter ThenCount = getRegionCounter(S);
+
+// If this is "if !consteval" the then-branch will never be taken, we don't
+// need to change counter
+Counter ThenCount =
+S->isNegatedConsteval() ? ParentCount : getRegionCounter(S);
 
 if (!S->isConsteval()) {
   // Emitting a counter for the condition makes it easier to interpret the
@@ -1729,7 +1733,12 @@ struct CounterCoverageMappingBuilder
 extendRegion(S->getThen());
 Counter OutCount = propagateCounts(ThenCount, S->getThen());
 
-Counter ElseCount = subtractCounters(ParentCount, ThenCount);
+// If this is "if consteval" the else-branch will never be taken, we don't
+// need to change counter
+Counter ElseCount = S->isNonNegatedConsteval()
+? ParentCount
+: subtractCounters(ParentCount, ThenCount);
+
 if (const Stmt *Else = S->getElse()) {
   bool ThenHasTerminateStmt = HasTerminateStmt;
   HasTerminateStmt = false;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c8c5a51bf9f94e..0033c851b618a1 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7732,7 +7732,8 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 if (Then.isInvalid())
   return StmtError();
   } else {
-Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
+Then = new (getSema().Context)
+CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
   }
 
   // Transform the "else" branch.
@@ -7741,6 +7742,10 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 Else = getDerived().TransformStmt(S->getElse());
 if (Else.isInvalid())
   return StmtError();
+  } else if (S->getElse() && ConstexprConditionValue &&
+ *ConstexprConditionValue) {
+Else = new (getSema().Context)
+CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
   }
 
   if (!getDerived().AlwaysRebuild() &&

``




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


[clang] fix wrong links in documentation (PR #76502)

2024-01-06 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/76502

From b72e9299c957bd73744605e12d52b229fc289d5b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sun, 7 Jan 2024 00:13:08 +0100
Subject: [PATCH] [coverage] fix incorrect coverage reporting for "if
 constexpr" and "if consteval"

---
 clang/include/clang/AST/Stmt.h   |  6 --
 clang/lib/CodeGen/CoverageMappingGen.cpp | 13 +++--
 clang/lib/Sema/TreeTransform.h   |  7 ++-
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211..fb50212083316e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1631,8 +1631,10 @@ class CompoundStmt final
   SourceLocation RB);
 
   // Build an empty compound statement with a location.
-  explicit CompoundStmt(SourceLocation Loc)
-  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
+  explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
+
+  explicit CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
+  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
 CompoundStmtBits.NumStmts = 0;
 CompoundStmtBits.HasFPFeatures = 0;
   }
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index bf227386a71b78..b245abd16c3f4a 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1712,7 +1712,11 @@ struct CounterCoverageMappingBuilder
   extendRegion(S->getCond());
 
 Counter ParentCount = getRegion().getCounter();
-Counter ThenCount = getRegionCounter(S);
+
+// If this is "if !consteval" the then-branch will never be taken, we don't
+// need to change counter
+Counter ThenCount =
+S->isNegatedConsteval() ? ParentCount : getRegionCounter(S);
 
 if (!S->isConsteval()) {
   // Emitting a counter for the condition makes it easier to interpret the
@@ -1729,7 +1733,12 @@ struct CounterCoverageMappingBuilder
 extendRegion(S->getThen());
 Counter OutCount = propagateCounts(ThenCount, S->getThen());
 
-Counter ElseCount = subtractCounters(ParentCount, ThenCount);
+// If this is "if consteval" the else-branch will never be taken, we don't
+// need to change counter
+Counter ElseCount = S->isNonNegatedConsteval()
+? ParentCount
+: subtractCounters(ParentCount, ThenCount);
+
 if (const Stmt *Else = S->getElse()) {
   bool ThenHasTerminateStmt = HasTerminateStmt;
   HasTerminateStmt = false;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c8c5a51bf9f94e..0033c851b618a1 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7732,7 +7732,8 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 if (Then.isInvalid())
   return StmtError();
   } else {
-Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
+Then = new (getSema().Context)
+CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
   }
 
   // Transform the "else" branch.
@@ -7741,6 +7742,10 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 Else = getDerived().TransformStmt(S->getElse());
 if (Else.isInvalid())
   return StmtError();
+  } else if (S->getElse() && ConstexprConditionValue &&
+ *ConstexprConditionValue) {
+Else = new (getSema().Context)
+CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
   }
 
   if (!getDerived().AlwaysRebuild() &&

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread via cfe-commits

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


[clang] [clang][NFC] Refactor Builtins.def to be a tablegen file (PR #68324)

2024-01-06 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,333 @@
+//=- ClangDiagnosticsEmitter.cpp - Generate Clang diagnostics tables -*- C++ 
-*-
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// These tablegen backends emit Clang diagnostics tables.
+//
+//===--===//
+
+#include "TableGenBackends.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/TableGenBackend.h"
+
+using namespace llvm;
+
+namespace {
+enum class BuiltinType {
+  Builtin,
+  AtomicBuiltin,
+  LibBuiltin,
+  LangBuiltin,
+  TargetBuiltin,
+};
+
+class PrototypeParser {
+public:
+  PrototypeParser(StringRef Substitution, const Record *Builtin)
+  : Loc(Builtin->getFieldLoc("Prototype")), Substitution(Substitution) {
+ParsePrototype(Builtin->getValueAsString("Prototype"));
+  }
+
+private:
+  void ParsePrototype(StringRef Prototype) {
+Prototype = Prototype.trim();
+Prototype = Prototype.trim();

philnik777 wrote:

I don't know. It's probably just a leftover.

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread via cfe-commits

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


[clang] [clang-format] Handle templated elaborated type specifier in function… (PR #77013)

2024-01-06 Thread via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/77013

>From 45d01cbc7ec958518b1739daa9e9b0dc35c2d194 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Thu, 4 Jan 2024 19:04:21 -0300
Subject: [PATCH 1/4] [clang-format] Handle templated elaborated type specifier
 in function return type. The behaviour now is consistent with the non
 templated version

---
 clang/lib/Format/UnwrappedLineParser.cpp | 8 
 clang/unittests/Format/FormatTest.cpp| 4 +---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 684609747a5513..aaff6319dd45ef 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3914,7 +3914,15 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   // (this would still leave us with an ambiguity between template function
   // and class declarations).
   if (FormatTok->isOneOf(tok::colon, tok::less)) {
+int AngleNestingLevel = 0;
 do {
+  if (FormatTok->is(tok::less))
+++AngleNestingLevel;
+  else if (FormatTok->is(tok::greater))
+--AngleNestingLevel;
+
+  if (AngleNestingLevel == 0 && FormatTok->is(tok::r_paren))
+break;
   if (FormatTok->is(tok::l_brace)) {
 calculateBraceTypes(/*ExpectClassBody=*/true);
 if (!tryToParseBracedList())
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 762fc8254bdfc9..f304407d0ce2f4 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -14583,9 +14583,7 @@ TEST_F(FormatTest, 
UnderstandContextOfRecordTypeKeywords) {
   verifyFormat("template <> struct X < 15, i<3 && 42 < 50 && 33 < 28> {};");
   verifyFormat("int i = SomeFunction(a b);");
 
-  // FIXME:
-  // This now gets parsed incorrectly as class definition.
-  // verifyFormat("class A f() {\n}\nint n;");
+  verifyFormat("class A f() {}\nint n;");
 
   // Elaborate types where incorrectly parsing the structural element would
   // break the indent.

>From 7a7d298c1e25940cc0607ba55eac5677b3b02f46 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Thu, 4 Jan 2024 21:53:11 -0300
Subject: [PATCH 2/4] Fix edge case in template specialization

---
 clang/lib/Format/UnwrappedLineParser.cpp | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index aaff6319dd45ef..dc6ece09059b5d 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3903,6 +3903,15 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   parseParens();
   }
 
+  auto IsTemplate = [&] {
+FormatToken *Tok = InitialToken.Previous;
+while (Tok) {
+  if (Tok->is(tok::kw_template))
+return true;
+  Tok = Tok->Previous;
+}
+return false;
+  };
   // Note that parsing away template declarations here leads to incorrectly
   // accepting function declarations as record declarations.
   // In general, we cannot solve this problem. Consider:
@@ -3921,8 +3930,10 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   else if (FormatTok->is(tok::greater))
 --AngleNestingLevel;
 
-  if (AngleNestingLevel == 0 && FormatTok->is(tok::r_paren))
+  if (AngleNestingLevel == 0 && !IsTemplate() &&
+  FormatTok->is(tok::r_paren)) {
 break;
+  }
   if (FormatTok->is(tok::l_brace)) {
 calculateBraceTypes(/*ExpectClassBody=*/true);
 if (!tryToParseBracedList())

>From 019992a0e227755015bc46e637d406fee911b9b5 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Thu, 4 Jan 2024 22:13:15 -0300
Subject: [PATCH 3/4] Add test

---
 clang/unittests/Format/FormatTest.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f304407d0ce2f4..6ac290b64ca450 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -14584,6 +14584,7 @@ TEST_F(FormatTest, 
UnderstandContextOfRecordTypeKeywords) {
   verifyFormat("int i = SomeFunction(a b);");
 
   verifyFormat("class A f() {}\nint n;");
+  verifyFormat("template <> class Foo F() {\n} n;");
 
   // Elaborate types where incorrectly parsing the structural element would
   // break the indent.

>From e41076ed7799dc7867d8bb9854298da396307090 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Sat, 6 Jan 2024 19:54:57 -0300
Subject: [PATCH 4/4] Add test

---
 clang/unittests/Format/TokenAnnotatorTest.cpp | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 2cafc0438ffb46..396ed1c003e975 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2453,6 +2453,13 @@ 

[clang] [libc] [lldb] [mlir] [llvm] [NFC][ObjectSizeOffset] Use classes instead of std::pair (PR #76882)

2024-01-06 Thread via cfe-commits

dyung wrote:

Hi @bwendling, your change to MemoryBuiltins.h is hitting an error in the 
version of Visual Studio 2019 that we use internally to build:
```
C:\j\w\779ddbee\p\llvm\include\llvm/Analysis/MemoryBuiltins.h(217): error 
C2990: 'llvm::SizeOffsetType': non-class template has already been declared as 
a class template
C:\j\w\779ddbee\p\llvm\include\llvm/Analysis/MemoryBuiltins.h(193): note: see 
declaration of 'llvm::SizeOffsetType'
C:\j\w\779ddbee\p\llvm\include\llvm/Analysis/MemoryBuiltins.h(279): error 
C2990: 'llvm::SizeOffsetType': non-class template has already been declared as 
a class template
C:\j\w\779ddbee\p\llvm\include\llvm/Analysis/MemoryBuiltins.h(193): note: see 
declaration of 'llvm::SizeOffsetType'
C:\j\w\779ddbee\p\llvm\include\llvm/Analysis/MemoryBuiltins.h(292): error 
C2990: 'llvm::SizeOffsetType': non-class template has already been declared as 
a class template
C:\j\w\779ddbee\p\llvm\include\llvm/Analysis/MemoryBuiltins.h(193): note: see 
declaration of 'llvm::SizeOffsetType'
```
>From the Visual Studio documentation for the error, it appears that we should 
>be able to work around this error by modifying the friend declaration like 
>this:
```c++
-  friend class SizeOffsetType;
+  template  friend class SizeOffsetType;
```
When I made this change to the 3 locations that caused the error (lines 
217/279/292), I was able to build successfully with Visual Studio. Could we 
update the friend declaration so that it also works with the version of Visual 
Studio that we are using internally to build?

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread via cfe-commits


@@ -1444,16 +1444,22 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // dangling comma
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+!MatchingParen->MatchingParen->Previous->is(tok::equal)

XDeme wrote:

I hope the comment is helpful.

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/77045

>From d9cbbe48b96d27bff3fc926b60d039ed05f00489 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 5 Jan 2024 01:23:16 -0300
Subject: [PATCH 1/4] [clang-format] Fix crash involving array designators and
 dangling comma Fixes llvm/llvm-project#76716 Added a check to prevent null
 deferencing

---
 clang/lib/Format/WhitespaceManager.cpp | 3 ++-
 clang/unittests/Format/FormatTest.cpp  | 6 ++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 3bc6915b8df0a7..95693f4588c631 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1444,7 +1444,8 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+const FormatToken *Next = C.Tok->getNextNonComment();
+if (Next && Next->isNot(tok::r_brace)) // dangling comma
   ++Cell;
   }
 } else if (Depth == 1) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..c9f91953c13f52 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21084,6 +21084,12 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   "};",
   Style);
 
+  verifyNoCrash("Foo f[] = {\n"
+"[0] = { 1, },\n"
+"[1] { 1, },\n"
+"};",
+Style);
+
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\", {\"x\", 
"
"\"dy\"}   },\n"

>From 78e006de352cb801f6c07ac7f6bd0ab881560406 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 5 Jan 2024 11:32:37 -0300
Subject: [PATCH 2/4] Addresses comments

---
 clang/lib/Format/WhitespaceManager.cpp | 6 --
 clang/unittests/Format/FormatTest.cpp  | 6 ++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 95693f4588c631..aeac0ba0c6d03c 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1444,9 +1444,11 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-const FormatToken *Next = C.Tok->getNextNonComment();
-if (Next && Next->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // dangling comma
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index c9f91953c13f52..d6f561e822d08a 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20842,6 +20842,12 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
   "};",
   Style);
 
+  verifyNoCrash("Foo f[] = {\n"
+"[0] = { 1, },\n"
+"[1] { 1, },\n"
+"};",
+Style);
+
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\",  "
"  {\"x\", \"dy\"}},\n"

>From 3f82d6664de1ea06589393ff27aced4e4177a72c Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 5 Jan 2024 16:21:33 -0300
Subject: [PATCH 3/4] Fix real problem

---
 clang/lib/Format/WhitespaceManager.cpp |  7 +--
 clang/unittests/Format/FormatTest.cpp  | 10 ++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index aeac0ba0c6d03c..e91ec6afec74af 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1455,8 +1455,11 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+!MatchingParen->MatchingParen->Previous->is(tok::equal)
+? Cell + 1
+: Cell);
 // Go to the next non-comment and ensure there is a break in front
 const auto *NextNonComment = 

[llvm] [clang] [SpecialCaseList] Use glob by default (PR #74809)

2024-01-06 Thread Arthur Eubanks via cfe-commits

aeubanks wrote:

ah it's because we something like

```
[cfi-unrelated-cast|cfi-derived-cast]

src:*third_party/vulkan_memory_allocator/include/vk_mem_alloc.h
```

it seems like the new system doesn't match 
`[cfi-unrelated-cast|cfi-derived-cast]`

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-06 Thread Owen Pan via cfe-commits


@@ -2499,6 +2499,15 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, StreamOperator) {
+  auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_FALSE(Tokens[1]->MustBreakBefore);
+  EXPECT_FALSE(Tokens[3]->MustBreakBefore);
+  // Only break between string literals if the former ends with \n.
+  EXPECT_TRUE(Tokens[5]->MustBreakBefore);
+}
+

owenca wrote:

Ok, let’s keep it then.

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


[llvm] [clang] [SpecialCaseList] Use glob by default (PR #74809)

2024-01-06 Thread Arthur Eubanks via cfe-commits

aeubanks wrote:

the file name is `vk_mem_alloc.h` so that shouldn't be the issue

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


[libunwind] [libc] [clang-tools-extra] [libcxx] [llvm] [lldb] [compiler-rt] [clang] [flang] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits

jamesETsmith wrote:

@cjdb, thanks for taking a look! I've addressed some of your comments already 
and will try to wrap up the rest early next week. I've got plenty of time to 
work on this over the next couple of weeks so I shouldn't have a problem 
wrapping this up before the end of January

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


[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support alias/restrict function argument decorations (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

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


[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support alias/restrict function argument decorations (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

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


[clang] [llvm] [flang] [libcxx] [libc] [clang-tools-extra] [compiler-rt] [lldb] [libunwind] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits

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


[clang] [llvm] [flang] [libcxx] [libc] [clang-tools-extra] [compiler-rt] [lldb] [libunwind] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits


@@ -13,7 +13,7 @@
 // Range algorithms should return `std::ranges::dangling` when given a 
dangling range.
 

jamesETsmith wrote:

This should be resolved with 
[be7faa6](https://github.com/llvm/llvm-project/pull/68494/commits/be7faa6fb11c09822a9a855c7cf1aecab4f4c773)

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


[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-01-06 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/74852

>From f281d34a51f662c934f158e4770774b0dc3588a2 Mon Sep 17 00:00:00 2001
From: Seth Pellegrino 
Date: Thu, 7 Dec 2023 08:45:51 -0800
Subject: [PATCH 1/4] [Clang][Sema] Print more static_assert exprs

This change introspects more values involved in a static_assert, and
extends the supported set of operators for introspection to include
binary operator method calls.

It's intended to address the use-case where a small static_assert helper
looks something like this (via `constexpr-builtin-bit-cast.cpp`):

```c++
struct int_splicer {
  unsigned x;
  unsigned y;

  constexpr bool operator==(const int_splicer ) const {
return other.x == x && other.y == y;
  }
};
```

When used like so:

```c++
constexpr int_splicer got{1, 2};
constexpr int_splicer want{3, 4};
static_assert(got == want);
```

Then we'd expect to get the error:

```
Static assertion failed due to requirement 'got == want'
```

And this change adds the helpful note:

```
Expression evaluates to '{1, 2} == {3, 4}'
```
---
 clang/lib/Sema/SemaDeclCXX.cpp| 31 ++-
 .../CXX/class/class.compare/class.eq/p3.cpp   | 20 ++--
 .../CXX/class/class.compare/class.rel/p2.cpp  | 10 +++---
 .../over.match.oper/p9-2a.cpp |  2 +-
 clang/test/SemaCXX/static-assert-cxx17.cpp|  2 +-
 5 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c6218a491aecec..e3d46c3140741b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17219,6 +17219,13 @@ static bool ConvertAPValueToString(const APValue , 
QualType T,
 OS << "i)";
   } break;
 
+  case APValue::ValueKind::Array:
+  case APValue::ValueKind::Vector:
+  case APValue::ValueKind::Struct: {
+llvm::raw_svector_ostream OS(Str);
+V.printPretty(OS, Context, T);
+  } break;
+
   default:
 return false;
   }
@@ -17256,11 +17263,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E);
-  Op && Op->getOpcode() != BO_LOr) {
-const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
-const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
-
+  const auto Diagnose = [&](const Expr *LHS, const Expr *RHS,
+const llvm::StringRef ) {
+LHS = LHS->IgnoreParenImpCasts();
+RHS = RHS->IgnoreParenImpCasts();
 // Ignore comparisons of boolean expressions with a boolean literal.
 if ((isa(LHS) && RHS->getType()->isBooleanType()) ||
 (isa(RHS) && LHS->getType()->isBooleanType()))
@@ -17287,10 +17293,19 @@ void Sema::DiagnoseStaticAssertDetails(const Expr *E) 
{
  DiagSide[I].ValueString, Context);
 }
 if (DiagSide[0].Print && DiagSide[1].Print) {
-  Diag(Op->getExprLoc(), diag::note_expr_evaluates_to)
-  << DiagSide[0].ValueString << Op->getOpcodeStr()
-  << DiagSide[1].ValueString << Op->getSourceRange();
+  Diag(E->getExprLoc(), diag::note_expr_evaluates_to)
+  << DiagSide[0].ValueString << OpStr << DiagSide[1].ValueString
+  << E->getSourceRange();
 }
+  };
+
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
+Diagnose(Op->getLHS(), Op->getRHS(), Op->getOpcodeStr());
+  } else if (const auto *Op = dyn_cast(E);
+ Op && Op->isInfixBinaryOp()) {
+Diagnose(Op->getArg(0), Op->getArg(1),
+ getOperatorSpelling(Op->getOperator()));
   }
 }
 
diff --git a/clang/test/CXX/class/class.compare/class.eq/p3.cpp 
b/clang/test/CXX/class/class.compare/class.eq/p3.cpp
index 04db022fe73021..53c4dda133301b 100644
--- a/clang/test/CXX/class/class.compare/class.eq/p3.cpp
+++ b/clang/test/CXX/class/class.compare/class.eq/p3.cpp
@@ -6,11 +6,11 @@ struct A {
 };
 
 static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 4, 5});
-static_assert(A{1, 2, 3, 4, 5} == A{0, 2, 3, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 0, 3, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 0, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 0, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 4, 0}); // expected-error 
{{failed}}
+static_assert(A{1, 2, 3, 4, 5} == A{0, 2, 3, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 0, 3, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 0, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 0, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == 

[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support function argument decorations for ptr in the PhysicalStorageBuffer (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks a lot for the contribution and bearing with me for the nitpicking. :) To 
avoid burden you further, I rebased and revised some comment/error message 
slightly. :) I'll land once bots are happy.

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


[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support function argument decorations for ptr in the PhysicalStorageBuffer (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst updated 
https://github.com/llvm/llvm-project/pull/76353

>From ebd9634057e9417905d7fcd27bac829c5d0889e0 Mon Sep 17 00:00:00 2001
From: Kohei Yamaguchi 
Date: Fri, 22 Dec 2023 17:22:25 +
Subject: [PATCH 01/10] [mlir][spirv] Support function argument decorations for
 ptr in the PhysicalStorageBuffer

---
 .../Dialect/SPIRV/IR/SPIRVStructureOps.td |  8 +++
 mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp| 37 ++
 mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp| 69 ++-
 .../spirv-storage-class-mapping.mlir  |  2 +-
 mlir/test/Dialect/SPIRV/IR/cast-ops.mlir  |  2 +-
 mlir/test/Dialect/SPIRV/IR/structure-ops.mlir | 42 +++
 .../SPIRV/Transforms/vce-deduction.mlir   |  2 +-
 mlir/test/Target/SPIRV/cast-ops.mlir  |  2 +-
 8 files changed, 145 insertions(+), 19 deletions(-)

diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td 
b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
index 5fd25e3b576f2a..0afe508b4db013 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
@@ -267,6 +267,11 @@ def SPIRV_FuncOp : SPIRV_Op<"func", [
 This op itself takes no operands and generates no results. Its region
 can take zero or more arguments and return zero or one values.
 
+From `SPV_KHR_physical_storage_buffer`:
+If a parameter of function is
+- a pointer (or contains a pointer) in the PhysicalStorageBuffer storage 
class, the function parameter must be decorated with exactly one of `Aliased` 
or `Restrict`.
+- a pointer (or contains a pointer) and the type it points to is a pointer 
in the PhysicalStorageBuffer storage class, the function parameter must be 
decorated with exactly one of `AliasedPointer` or `RestrictPointer`.
+
 
 
 ```
@@ -280,6 +285,9 @@ def SPIRV_FuncOp : SPIRV_Op<"func", [
 ```mlir
 spirv.func @foo() -> () "None" { ... }
 spirv.func @bar() -> () "Inline|Pure" { ... }
+
+spirv.func @baz(%arg0: !spirv.ptr { 
spirv.decoration = #spirv.decoration}) -> () "None" { ... }
+spirv.func @qux(%arg0: !spirv.ptr, 
Generic> { spirv.decoration = 
#spirv.decoration}) "None)
 ```
   }];
 
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp 
b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
index 8a68decc5878c8..66ec520cfeca31 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
@@ -992,19 +992,25 @@ static LogicalResult verifyRegionAttribute(Location loc, 
Type valueType,
   StringRef symbol = attribute.getName().strref();
   Attribute attr = attribute.getValue();
 
-  if (symbol != spirv::getInterfaceVarABIAttrName())
+  if (symbol == spirv::getInterfaceVarABIAttrName()) {
+auto varABIAttr = llvm::dyn_cast(attr);
+if (!varABIAttr)
+  return emitError(loc, "'")
+ << symbol << "' must be a spirv::InterfaceVarABIAttr";
+
+if (varABIAttr.getStorageClass() && !valueType.isIntOrIndexOrFloat())
+  return emitError(loc, "'") << symbol
+ << "' attribute cannot specify storage class "
+"when attaching to a non-scalar value";
+  } else if (symbol == spirv::DecorationAttr::name) {
+auto decAttr = llvm::dyn_cast(attr);
+if (!decAttr)
+  return emitError(loc, "'")
+ << symbol << "' must be a spirv::DecorationAttr";
+  } else {
 return emitError(loc, "found unsupported '")
<< symbol << "' attribute on region argument";
-
-  auto varABIAttr = llvm::dyn_cast(attr);
-  if (!varABIAttr)
-return emitError(loc, "'")
-   << symbol << "' must be a spirv::InterfaceVarABIAttr";
-
-  if (varABIAttr.getStorageClass() && !valueType.isIntOrIndexOrFloat())
-return emitError(loc, "'") << symbol
-   << "' attribute cannot specify storage class "
-  "when attaching to a non-scalar value";
+  }
 
   return success();
 }
@@ -1013,9 +1019,12 @@ LogicalResult 
SPIRVDialect::verifyRegionArgAttribute(Operation *op,
  unsigned regionIndex,
  unsigned argIndex,
  NamedAttribute attribute) 
{
-  return verifyRegionAttribute(
-  op->getLoc(), op->getRegion(regionIndex).getArgument(argIndex).getType(),
-  attribute);
+  auto funcOp = dyn_cast(op);
+  if (!funcOp)
+return success();
+  Type argType = funcOp.getArgumentTypes()[argIndex];
+
+  return verifyRegionAttribute(op->getLoc(), argType, attribute);
 }
 
 LogicalResult SPIRVDialect::verifyRegionResultAttribute(
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp 
b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index 2a1d083308282a..d6064f446b4454 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ 

[clang] [clang] Reword apologetic Clang diagnostic messages (PR #76310)

2024-01-06 Thread Pavel Gueorguiev via cfe-commits

https://github.com/pav-code updated 
https://github.com/llvm/llvm-project/pull/76310

>From 82fe20f1ccc2e9129282c71bf5bdfd6cfd4fadf3 Mon Sep 17 00:00:00 2001
From: Pavel Gueorguiev 
Date: Sat, 23 Dec 2023 14:19:50 -0500
Subject: [PATCH 1/2] [clang] Reword apologetic Clang diagnostic messages

Fixes Issue: https://github.com/llvm/llvm-project/issues/61256
---
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  4 ++--
 clang/include/clang/Basic/DiagnosticSemaKinds.td   | 10 +-
 clang/test/CXX/drs/dr16xx.cpp  |  2 +-
 clang/test/CXX/drs/dr18xx.cpp  |  2 +-
 clang/test/Lexer/SourceLocationsOverflow.c |  2 +-
 clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp |  4 ++--
 clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp | 12 ++--
 7 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 65a33f61a6948a..aceaa518d55ea9 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -355,9 +355,9 @@ def err_cannot_open_file : Error<"cannot open file '%0': 
%1">, DefaultFatal;
 def err_file_modified : Error<
   "file '%0' modified since it was first processed">, DefaultFatal;
 def err_file_too_large : Error<
-  "sorry, unsupported: file '%0' is too large for Clang to process">;
+  "file '%0' is too large for Clang to process">;
 def err_sloc_space_too_large : Error<
-  "sorry, the translation unit is too large for Clang to process: ran out of 
source locations">, DefaultFatal;
+  "translation unit is too large for Clang to process: ran out of source 
locations">, DefaultFatal;
 def err_unsupported_bom : Error<"%0 byte order mark detected in '%1', but "
   "encoding is not supported">, DefaultFatal;
 def err_unable_to_rename_temp : Error<
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index aebb7d9b945c33..dbe2b16b5fc39f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5135,7 +5135,7 @@ def err_non_type_template_arg_subobject : Error<
 def err_non_type_template_arg_addr_label_diff : Error<
   "template argument / label address difference / what did you expect?">;
 def err_non_type_template_arg_unsupported : Error<
-  "sorry, non-type template argument of type %0 is not yet supported">;
+  "non-type template argument of type %0 is not yet supported">;
 def err_template_arg_not_convertible : Error<
   "non-type template argument of type %0 cannot be converted to a value "
   "of type %1">;
@@ -5188,7 +5188,7 @@ def err_template_arg_not_object_or_func : Error<
 def err_template_arg_not_pointer_to_member_form : Error<
   "non-type template argument is not a pointer to member constant">;
 def err_template_arg_member_ptr_base_derived_not_supported : Error<
-  "sorry, non-type template argument of pointer-to-member type %1 that refers "
+  "non-type template argument of a pointer to member type %1, that refers "
   "to member %q0 of a different class is not supported yet">;
 def err_template_arg_invalid : Error<
   "non-type template argument '%0' is invalid">;
@@ -9913,11 +9913,11 @@ def warn_new_dangling_initializer_list : Warning<
   "will be destroyed at the end of the full-expression">,
   InGroup;
 def warn_unsupported_lifetime_extension : Warning<
-  "sorry, lifetime extension of "
+  "lifetime extension of "
   "%select{temporary|backing array of initializer list}0 created "
-  "by aggregate initialization using default member initializer "
+  "by aggregate initialization using a default member initializer "
   "is not supported; lifetime of %select{temporary|backing array}0 "
-  "will end at the end of the full-expression">, InGroup;
+  "will terminate at the end of the full-expression">, InGroup;
 
 // For non-floating point, expressions of the form x == x or x != x
 // should result in a warning, since these always evaluate to a constant.
diff --git a/clang/test/CXX/drs/dr16xx.cpp b/clang/test/CXX/drs/dr16xx.cpp
index 3f074c4d57354a..2ffeb5372ec1d2 100644
--- a/clang/test/CXX/drs/dr16xx.cpp
+++ b/clang/test/CXX/drs/dr16xx.cpp
@@ -472,7 +472,7 @@ namespace dr1696 { // dr1696: 7
 const A  = A(); // #dr1696-D1-a
   };
   D1 d1 = {}; // #dr1696-d1
-  // since-cxx14-warning@-1 {{sorry, lifetime extension of temporary created 
by aggregate initialization using default member initializer is not supported; 
lifetime of temporary will end at the end of the full-expression}}
+  // since-cxx14-warning@-1 {{lifetime extension of temporary created by 
aggregate initialization using a default member initializer is not supported; 
lifetime of temporary will terminate at the end of the full-expression}}
   //   since-cxx14-note@#dr1696-D1-a {{initializing field 'a' with default 
member initializer}}
 
   struct D2 {
diff --git 

[compiler-rt] [clang-tools-extra] [flang] [lldb] [llvm] [libcxx] [libunwind] [libc] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits


@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {
+struct __iota_fn {
+private:
+  // Private helper function
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
__iota_impl(_Out __first, _Sent __last, _Tp __value) {
+while (__first != __last) {
+  *__first = std::as_const(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__value)};
+  }
+
+public:
+  // Public facing interfaces
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
operator()(_Out __first, _Sent __last, _Tp __value) {
+return __iota_impl(std::move(__first), std::move(__last), 
std::move(__value));
+  }
+
+  template  _Range>
+  _LIBCPP_HIDE_FROM_ABI static constexpr 
iota_result, _Tp>
+  operator()(_Range&& __r, _Tp __value) {
+return __iota_impl(ranges::begin(__r), ranges::end(__r), 
std::move(__value));
+  }
+};
+} // namespace __ranges_iota
+
+inline namespace __cpo {

jamesETsmith wrote:

Like the other namespace, this is easy enough so I'll just remove it now.

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


[compiler-rt] [clang-tools-extra] [flang] [lldb] [llvm] [libcxx] [libunwind] [libc] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits


@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {

jamesETsmith wrote:

It's easy enough, I'll just remove it.

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


[compiler-rt] [clang-tools-extra] [flang] [lldb] [llvm] [libcxx] [libunwind] [libc] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits


@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {
+struct __iota_fn {
+private:
+  // Private helper function
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
__iota_impl(_Out __first, _Sent __last, _Tp __value) {
+while (__first != __last) {
+  *__first = std::as_const(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__value)};
+  }

jamesETsmith wrote:

That's a fair point about the extra moves. I added a helper function at 
@philnik777's suggestion to fix problems in the `robust_against_*` tests caused 
by my initial implementation (see discussion 
[here](https://github.com/llvm/llvm-project/pull/68494#discussion_r1349577530)).
 Is there a way we could satisfy both requirements?

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


[libcxx] [clang] [llvm] Reapply "[libc++][streams] P1759R6: Native handles and file streams" (PR #77190)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Hristo Hristov (H-G-Hristov)


Changes

Fixes build on Windows in C++26 mode.

Reverted in: 
https://github.com/llvm/llvm-project/commit/40c07b559aa6ab4bac074c943967d3207bc07ae0
Original PR: https://github.com/llvm/llvm-project/pull/76632

---

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


25 Files Affected:

- (modified) libcxx/docs/FeatureTestMacroTable.rst (+1-1) 
- (modified) libcxx/docs/ReleaseNotes/18.rst (+1) 
- (modified) libcxx/docs/Status/Cxx2cPapers.csv (+1-1) 
- (modified) libcxx/include/fstream (+50) 
- (modified) libcxx/include/version (+1-1) 
- (modified) libcxx/src/CMakeLists.txt (+1) 
- (added) libcxx/src/fstream.cpp (+37) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/filebuf.members/native_handle.assert.pass.cpp
 (+32) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/filebuf.members/native_handle.pass.cpp
 (+58) 
- (modified) 
libcxx/test/std/input.output/file.streams/fstreams/filebuf/types.pass.cpp 
(+8-1) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/fstream.members/native_handle.assert.pass.cpp
 (+32) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/fstream.members/native_handle.pass.cpp
 (+27) 
- (modified) 
libcxx/test/std/input.output/file.streams/fstreams/fstream/types.pass.cpp 
(+8-1) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/native_handle.assert.pass.cpp
 (+32) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/native_handle.pass.cpp
 (+27) 
- (modified) 
libcxx/test/std/input.output/file.streams/fstreams/ifstream/types.pass.cpp 
(+8-1) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/native_handle_assert_test_helpers.h
 (+28) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/native_handle_test_helpers.h 
(+84) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/ofstream.members/native_handle.assert.pass.cpp
 (+32) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/ofstream.members/native_handle.pass.cpp
 (+27) 
- (modified) 
libcxx/test/std/input.output/file.streams/fstreams/ofstream/types.pass.cpp 
(+8-1) 
- (modified) libcxx/test/std/input.output/file.streams/fstreams/types.h (+10) 
- (modified) 
libcxx/test/std/language.support/support.limits/support.limits.general/fstream.version.compile.pass.cpp
 (+5-11) 
- (modified) 
libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
 (+5-11) 
- (modified) libcxx/utils/generate_feature_test_macro_components.py (-1) 


``diff
diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index 8ce5ec9f64ef9a..893a3b13ca06e0 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index cae2347be5fd61..882f53b8d9f83f 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -59,6 +59,7 @@ Implemented Papers
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P2821R5 - span.at()
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index fa4a112d143673..5701717f39766c 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
 

[libcxx] [clang] [llvm] Reapply "[libc++][streams] P1759R6: Native handles and file streams" (PR #77190)

2024-01-06 Thread Hristo Hristov via cfe-commits

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


[compiler-rt] [mlir] [clang-tools-extra] [flang] [lldb] [llvm] [libcxx] [libunwind] [lld] [libc] [clang] [libcxxabi] [clang] static operators should evaluate object argument (PR #68485)

2024-01-06 Thread Tianlan Zhou via cfe-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 01/11] [clang] static operators should evaluate object
 argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c..a6c81f467fbe01 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac73..19406ff174dea1 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b63..a580c635998510 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo  =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, , Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c9..42de125e748991 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCallExpr *CE,
+

[flang] [clang] [libunwind] [compiler-rt] [libc] [libcxx] [clang-tools-extra] [lldb] [llvm] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits


@@ -1149,9 +1171,11 @@ struct Proxy {
   // Calling swap(Proxy{}, Proxy{}) would fail (pass prvalues)
 
   // Compare operators are defined for the convenience of the tests
-  friend constexpr bool operator==(const Proxy&, const Proxy&)
-requires (std::equality_comparable && !std::is_reference_v)
-  = default;
+  friend constexpr bool operator==(const Proxy& lhs, const Proxy& rhs)
+requires(std::equality_comparable && !std::is_reference_v)
+  {
+return lhs.data == rhs.data;
+  };

jamesETsmith wrote:

For this operator and the spaceship operator below, the default functions do 
not satisfy the requirements on the functions (e.g. `std::equality_comparable`) 
(see the previous discussion about it 
[here](https://github.com/llvm/llvm-project/pull/68494#issuecomment-1783604000)).
 

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


[clang-tools-extra] [clang-tidy] Add support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Support detecting redundant in-class initializers. 
Moved from https://reviews.llvm.org/D157262

Fixes: #62525

---
Full diff: https://github.com/llvm/llvm-project/pull/77206.diff


4 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp (+51-22) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.rst 
(+2-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-member-init.cpp
 (+52) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
index b5d407773bb732..015347ee9294ce 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "RedundantMemberInitCheck.h"
+#include "../utils/LexerUtils.h"
 #include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -18,33 +19,64 @@ using namespace clang::tidy::matchers;
 
 namespace clang::tidy::readability {
 
+static SourceRange
+getFullInitRangeInclWhitespaces(SourceRange Range, const SourceManager ,
+const LangOptions ) {
+  const Token PrevToken =
+  utils::lexer::getPreviousToken(Range.getBegin(), SM, LangOpts, false);
+  if (PrevToken.is(tok::unknown))
+return Range;
+
+  if (PrevToken.isNot(tok::equal))
+return {PrevToken.getEndLoc(), Range.getEnd()};
+
+  return getFullInitRangeInclWhitespaces(
+  {PrevToken.getLocation(), Range.getEnd()}, SM, LangOpts);
+}
+
 void RedundantMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap ) 
{
   Options.store(Opts, "IgnoreBaseInCopyConstructors",
 IgnoreBaseInCopyConstructors);
 }
 
 void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
+  auto ConstructorMatcher =
+  cxxConstructExpr(argumentCountIs(0),
+   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
+   unless(isTriviallyDefaultConstructible()))
+  .bind("construct");
+
   Finder->addMatcher(
   cxxConstructorDecl(
   unless(isDelegatingConstructor()), ofClass(unless(isUnion())),
   forEachConstructorInitializer(
-  cxxCtorInitializer(
-  withInitializer(
-  cxxConstructExpr(
-  hasDeclaration(
-  cxxConstructorDecl(ofClass(cxxRecordDecl(
-  
unless(isTriviallyDefaultConstructible()))
-  .bind("construct")),
-  unless(forField(hasType(isConstQualified(,
-  unless(forField(hasParent(recordDecl(isUnion())
+  cxxCtorInitializer(withInitializer(ConstructorMatcher),
+ unless(forField(fieldDecl(
+ anyOf(hasType(isConstQualified()),
+   
hasParent(recordDecl(isUnion(
   .bind("init")))
   .bind("constructor"),
   this);
+
+  Finder->addMatcher(fieldDecl(hasInClassInitializer(ConstructorMatcher),
+   unless(hasParent(recordDecl(isUnion()
+ .bind("field"),
+ this);
 }
 
 void RedundantMemberInitCheck::check(const MatchFinder::MatchResult ) {
-  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *Construct = 
Result.Nodes.getNodeAs("construct");
+
+  if (const auto *Field = Result.Nodes.getNodeAs("field")) {
+const Expr *Init = Field->getInClassInitializer();
+diag(Construct->getExprLoc(), "initializer for member %0 is redundant")
+<< Field
+<< FixItHint::CreateRemoval(getFullInitRangeInclWhitespaces(
+   Init->getSourceRange(), *Result.SourceManager, getLangOpts()));
+return;
+  }
+
+  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *ConstructorDecl =
   Result.Nodes.getNodeAs("constructor");
 
@@ -52,18 +84,15 @@ void RedundantMemberInitCheck::check(const 
MatchFinder::MatchResult ) {
   Init->isBaseInitializer())
 return;
 
-  if (Construct->getNumArgs() == 0 ||
-  Construct->getArg(0)->isDefaultArgument()) {
-if (Init->isAnyMemberInitializer()) {
-  diag(Init->getSourceLocation(), "initializer for member %0 is redundant")
-  << Init->getAnyMember()
-  << FixItHint::CreateRemoval(Init->getSourceRange());
-} else {
-  diag(Init->getSourceLocation(),
-   "initializer for base class %0 is redundant")
-  

[clang-tools-extra] [clang-tidy] Add support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-06 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/77206

Support detecting redundant in-class initializers. Moved from 
https://reviews.llvm.org/D157262

Fixes: #62525

>From 66e4026ff568fbd805ddd777596102381e4e0066 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sat, 6 Jan 2024 18:04:57 +
Subject: [PATCH] [clang-tidy] Add support for in-class initializers in
 readability-redundant-member-init

Support detecting redundant in-class initializers.
Moved from https://reviews.llvm.org/D157262

Fixes: #62525
---
 .../readability/RedundantMemberInitCheck.cpp  | 73 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 +-
 .../readability/redundant-member-init.rst |  3 +-
 .../readability/redundant-member-init.cpp | 52 +
 4 files changed, 110 insertions(+), 24 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
index b5d407773bb732..015347ee9294ce 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "RedundantMemberInitCheck.h"
+#include "../utils/LexerUtils.h"
 #include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -18,33 +19,64 @@ using namespace clang::tidy::matchers;
 
 namespace clang::tidy::readability {
 
+static SourceRange
+getFullInitRangeInclWhitespaces(SourceRange Range, const SourceManager ,
+const LangOptions ) {
+  const Token PrevToken =
+  utils::lexer::getPreviousToken(Range.getBegin(), SM, LangOpts, false);
+  if (PrevToken.is(tok::unknown))
+return Range;
+
+  if (PrevToken.isNot(tok::equal))
+return {PrevToken.getEndLoc(), Range.getEnd()};
+
+  return getFullInitRangeInclWhitespaces(
+  {PrevToken.getLocation(), Range.getEnd()}, SM, LangOpts);
+}
+
 void RedundantMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap ) 
{
   Options.store(Opts, "IgnoreBaseInCopyConstructors",
 IgnoreBaseInCopyConstructors);
 }
 
 void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
+  auto ConstructorMatcher =
+  cxxConstructExpr(argumentCountIs(0),
+   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
+   unless(isTriviallyDefaultConstructible()))
+  .bind("construct");
+
   Finder->addMatcher(
   cxxConstructorDecl(
   unless(isDelegatingConstructor()), ofClass(unless(isUnion())),
   forEachConstructorInitializer(
-  cxxCtorInitializer(
-  withInitializer(
-  cxxConstructExpr(
-  hasDeclaration(
-  cxxConstructorDecl(ofClass(cxxRecordDecl(
-  
unless(isTriviallyDefaultConstructible()))
-  .bind("construct")),
-  unless(forField(hasType(isConstQualified(,
-  unless(forField(hasParent(recordDecl(isUnion())
+  cxxCtorInitializer(withInitializer(ConstructorMatcher),
+ unless(forField(fieldDecl(
+ anyOf(hasType(isConstQualified()),
+   
hasParent(recordDecl(isUnion(
   .bind("init")))
   .bind("constructor"),
   this);
+
+  Finder->addMatcher(fieldDecl(hasInClassInitializer(ConstructorMatcher),
+   unless(hasParent(recordDecl(isUnion()
+ .bind("field"),
+ this);
 }
 
 void RedundantMemberInitCheck::check(const MatchFinder::MatchResult ) {
-  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *Construct = 
Result.Nodes.getNodeAs("construct");
+
+  if (const auto *Field = Result.Nodes.getNodeAs("field")) {
+const Expr *Init = Field->getInClassInitializer();
+diag(Construct->getExprLoc(), "initializer for member %0 is redundant")
+<< Field
+<< FixItHint::CreateRemoval(getFullInitRangeInclWhitespaces(
+   Init->getSourceRange(), *Result.SourceManager, getLangOpts()));
+return;
+  }
+
+  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *ConstructorDecl =
   Result.Nodes.getNodeAs("constructor");
 
@@ -52,18 +84,15 @@ void RedundantMemberInitCheck::check(const 
MatchFinder::MatchResult ) {
   Init->isBaseInitializer())
 return;
 
-  if (Construct->getNumArgs() == 0 ||
-  Construct->getArg(0)->isDefaultArgument()) {
-if (Init->isAnyMemberInitializer()) {
-  diag(Init->getSourceLocation(), "initializer for member %0 is redundant")
-  << Init->getAnyMember()
- 

[clang-tools-extra] [clang-tidy] Fix false-positives in misc-static-assert caused by non-constexpr variables (PR #77203)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Ignore false-positives when referring to non-constexpr variables in 
non-unevaluated context (like decltype, sizeof, ...).

Moved from https://reviews.llvm.org/D158657

Fixes: #24066

---
Full diff: https://github.com/llvm/llvm-project/pull/77203.diff


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp (+9-1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5-1) 
- (modified) clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp 
(+42) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index 77763a9f429f2b..35536b47700a65 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "StaticAssertCheck.h"
+#include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -45,13 +46,20 @@ void StaticAssertCheck::registerMatchers(MatchFinder 
*Finder) {
   IsAlwaysFalse);
   auto NonConstexprFunctionCall =
   callExpr(hasDeclaration(functionDecl(unless(isConstexpr();
+  auto NonConstexprVariableReference =
+  declRefExpr(to(varDecl(unless(isConstexpr(,
+  unless(hasAncestor(expr(matchers::hasUnevaluatedContext(,
+  unless(hasAncestor(typeLoc(;
+
+  auto NonConstexprCode =
+  expr(anyOf(NonConstexprFunctionCall, NonConstexprVariableReference));
   auto AssertCondition =
   expr(
   anyOf(expr(ignoringParenCasts(anyOf(
 AssertExprRoot, unaryOperator(hasUnaryOperand(
 
ignoringParenCasts(AssertExprRoot)),
 anything()),
-  unless(findAll(NonConstexprFunctionCall)))
+  unless(NonConstexprCode), unless(hasDescendant(NonConstexprCode)))
   .bind("condition");
   auto Condition =
   anyOf(ignoringParenImpCasts(callExpr(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 08ade306b5a077..1a6f25cd226f7c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -119,7 +119,7 @@ Improvements to clang-tidy
 
 - Improved `--dump-config` to print check options in alphabetical order.
 
-- Improved :program:`clang-tidy-diff.py` script. 
+- Improved :program:`clang-tidy-diff.py` script.
 * Return exit code `1` if any :program:`clang-tidy` subprocess exits with
   a non-zero code or if exporting fixes fails.
 
@@ -376,6 +376,10 @@ Changes in existing checks
   ` check to ignore
   false-positives in unevaluated context (e.g., ``decltype``).
 
+- Improved :doc:`misc-static-assert
+  ` check to ignore false-positives when
+  referring to non-``constexpr`` variables in non-unevaluated context.
+
 - Improved :doc:`misc-unused-using-decls
   ` check to avoid false positive 
when
   using in elaborated type.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
index da4ab9baa3948a..16c6ba60c1925f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
@@ -20,6 +20,48 @@ void print(...);
 #define my_macro() assert(0 == 1)
 // CHECK-FIXES: #define my_macro() assert(0 == 1)
 
+namespace PR24066 {
+
+void referenceMember() {
+  struct {
+int A;
+int B;
+  } S;
+  assert( -  == 1);
+}
+
+const int X = 1;
+void referenceVariable() {
+  assert(X > 0);
+}
+
+
+constexpr int Y = 1;
+void referenceConstexprVariable() {
+  assert(Y > 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by static_assert() [misc-static-assert]
+  // CHECK-FIXES-CXX11: {{^  }}static_assert(Y > 0, "");
+  // CHECK-FIXES-CXX17: {{^  }}static_assert(Y > 0);
+}
+
+void useInSizeOf() {
+  char a = 0;
+  assert(sizeof(a) == 1U);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by static_assert() [misc-static-assert]
+  // CHECK-FIXES-CXX11: {{^  }}static_assert(sizeof(a) == 1U, "");
+  // CHECK-FIXES-CXX17: {{^  }}static_assert(sizeof(a) == 1U);
+}
+
+void useInDecltype() {
+  char a = 0;
+  assert(static_cast(256) == 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by static_assert() [misc-static-assert]
+  // CHECK-FIXES-CXX11: {{^  }}static_assert(static_cast(256) == 
0, "");
+  // CHECK-FIXES-CXX17: {{^  }}static_assert(static_cast(256) == 
0);
+}
+
+}
+
 constexpr bool myfunc(int a, int b) { return a * b == 0; }
 
 typedef __SIZE_TYPE__ size_t;

``





[clang-tools-extra] [clang-tidy] Fix false-positives in misc-static-assert caused by non-constexpr variables (PR #77203)

2024-01-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/77203

Ignore false-positives when referring to non-constexpr variables in 
non-unevaluated context (like decltype, sizeof, ...).

Moved from https://reviews.llvm.org/D158657

Fixes: #24066

>From 66900e4518b439cb9190e29fdb40f8adaeba8466 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sat, 6 Jan 2024 17:36:01 +
Subject: [PATCH] [clang-tidy] Fix false-positives in misc-static-assert caused
 by non-constexpr variables

Ignore false-positives when referring to non-constexpr variables
in non-unevaluated context (like decltype, sizeof, ...).

Moved from https://reviews.llvm.org/D158657

Fixes: #24066
---
 .../clang-tidy/misc/StaticAssertCheck.cpp | 10 -
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++-
 .../checkers/misc/static-assert.cpp   | 42 +++
 3 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index 77763a9f429f2b..35536b47700a65 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "StaticAssertCheck.h"
+#include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -45,13 +46,20 @@ void StaticAssertCheck::registerMatchers(MatchFinder 
*Finder) {
   IsAlwaysFalse);
   auto NonConstexprFunctionCall =
   callExpr(hasDeclaration(functionDecl(unless(isConstexpr();
+  auto NonConstexprVariableReference =
+  declRefExpr(to(varDecl(unless(isConstexpr(,
+  unless(hasAncestor(expr(matchers::hasUnevaluatedContext(,
+  unless(hasAncestor(typeLoc(;
+
+  auto NonConstexprCode =
+  expr(anyOf(NonConstexprFunctionCall, NonConstexprVariableReference));
   auto AssertCondition =
   expr(
   anyOf(expr(ignoringParenCasts(anyOf(
 AssertExprRoot, unaryOperator(hasUnaryOperand(
 
ignoringParenCasts(AssertExprRoot)),
 anything()),
-  unless(findAll(NonConstexprFunctionCall)))
+  unless(NonConstexprCode), unless(hasDescendant(NonConstexprCode)))
   .bind("condition");
   auto Condition =
   anyOf(ignoringParenImpCasts(callExpr(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 08ade306b5a077..1a6f25cd226f7c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -119,7 +119,7 @@ Improvements to clang-tidy
 
 - Improved `--dump-config` to print check options in alphabetical order.
 
-- Improved :program:`clang-tidy-diff.py` script. 
+- Improved :program:`clang-tidy-diff.py` script.
 * Return exit code `1` if any :program:`clang-tidy` subprocess exits with
   a non-zero code or if exporting fixes fails.
 
@@ -376,6 +376,10 @@ Changes in existing checks
   ` check to ignore
   false-positives in unevaluated context (e.g., ``decltype``).
 
+- Improved :doc:`misc-static-assert
+  ` check to ignore false-positives when
+  referring to non-``constexpr`` variables in non-unevaluated context.
+
 - Improved :doc:`misc-unused-using-decls
   ` check to avoid false positive 
when
   using in elaborated type.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
index da4ab9baa3948a..16c6ba60c1925f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
@@ -20,6 +20,48 @@ void print(...);
 #define my_macro() assert(0 == 1)
 // CHECK-FIXES: #define my_macro() assert(0 == 1)
 
+namespace PR24066 {
+
+void referenceMember() {
+  struct {
+int A;
+int B;
+  } S;
+  assert( -  == 1);
+}
+
+const int X = 1;
+void referenceVariable() {
+  assert(X > 0);
+}
+
+
+constexpr int Y = 1;
+void referenceConstexprVariable() {
+  assert(Y > 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by static_assert() [misc-static-assert]
+  // CHECK-FIXES-CXX11: {{^  }}static_assert(Y > 0, "");
+  // CHECK-FIXES-CXX17: {{^  }}static_assert(Y > 0);
+}
+
+void useInSizeOf() {
+  char a = 0;
+  assert(sizeof(a) == 1U);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by static_assert() [misc-static-assert]
+  // CHECK-FIXES-CXX11: {{^  }}static_assert(sizeof(a) == 1U, "");
+  // CHECK-FIXES-CXX17: {{^  }}static_assert(sizeof(a) == 1U);
+}
+
+void useInDecltype() {
+  char a = 0;
+  assert(static_cast(256) == 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by 

[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify

Endilll wrote:

As written, tests checks only default language mode for C (which is `gnu99` 
AFAIK). Maybe we want to check other modes as well? 

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */

Endilll wrote:

On line 6 we issue a diagnostic that `const` qualifier doesn't have effect on 
return type, yet we issue a diagnostic here telling that this makes function 
pointer type incompatible. It feels like we fail to make up our minds on the 
matter, or that we are overly pedantic without pedantic warnings enabled.

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

I think this PR moves things in the right direction, but I'm not well-versed in 
C enough to approve.

> This should have a release note and I think this is a potentially breaking 
> change since folks using Wextra may get this diagnostic now.

I agree that release note should be added, but I'm not sure we break people 
with this. We ship new versions with new on-by-default diagnostics. How is this 
different? Not to say that this improves GCC compatibility (more on this later).

Out of 7 warning we expect in the test, GCC 13.1 issues a warning only for 
`f2`, `f4`, and `f6` cases: https://godbolt.org/z/18Eqnsqba. Same goes for GCC 
trunk. I'm not qualified enough in C to be sure which compiler gets this right. 
@AaronBallman would be very welcome here. 

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */

Endilll wrote:

```suggestion
const int v(int i); /* expected-warning {{'const' type qualifier on return type 
has no effect}} */
```

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [compiler-rt] [flang] [libc] [libunwind] [llvm] [lld] [libcxxabi] [mlir] [libcxx] [lldb] [clang-tools-extra] [clang] static operators should evaluate object argument (PR #68485)

2024-01-06 Thread Tianlan Zhou via cfe-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 01/10] [clang] static operators should evaluate object
 argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c..a6c81f467fbe01 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac73..19406ff174dea1 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b63..a580c635998510 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo  =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, , Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c9..42de125e748991 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCallExpr *CE,
+

[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-01-06 Thread via cfe-commits


@@ -0,0 +1,117 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+struct A {
+  int a, b[3], c;
+  bool operator==(const A&) const = default;
+};
+
+constexpr auto a0 = A{0, 0, 3, 4, 5};
+
+// expected-note@+1 {{evaluates to '{0, {0, 3, 4}, 5} == {1, {2, 3, 4}, 5}'}}
+static_assert(a0 == A{1, {2, 3, 4}, 5}); // expected-error {{failed}}
+
+struct _arr {
+  const int b[3];
+  constexpr bool operator==(const int rhs[3]) const {
+for (unsigned i = 0; i < sizeof(b) / sizeof(int); i++)
+  if (b[i] != rhs[i])
+return false;
+return true;
+  }
+};
+
+// TODO[seth] syntactically sort of valid but almost entirely unusuable
+// (it's an int *, not an int [3] )
+// constexpr int _[3] = {...}; would work, but that's not piecewise 
substitutable
+// maybe it's ok? I mean, not like we can do better really...
+constexpr auto _ = (int[3]){2, 3, 4};
+
+// output: '{{2, 3, 4}} == {0, 3, 4}'  (the `{{` breaks 
VerifyDiagnosticConsumer::ParseDirective)

sethp wrote:

Well, my bad idea [worked out easily 
enough](https://github.com/sethp/llvm-project/commit/153d36338a73d8fbbb6087b2cf07e671b7aa660a).
 I'm happy to roll that in to (or out of) this change: whatever y'all think is 
best.

(I also seem to have confused the 'hub with an immaculately timed interrupt to 
the `git push`; that commit is on the appropriate branch in my fork, but hasn't 
shown up here on the PR yet. Maybe it will eventually? ¯\\_(ツ)_/¯ )

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-06 Thread Björn Schäpers via cfe-commits


@@ -2499,6 +2499,15 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, StreamOperator) {
+  auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_FALSE(Tokens[1]->MustBreakBefore);
+  EXPECT_FALSE(Tokens[3]->MustBreakBefore);
+  // Only break between string literals if the former ends with \n.
+  EXPECT_TRUE(Tokens[5]->MustBreakBefore);
+}
+

HazardyKnusperkeks wrote:

It hasn't been done. But I think it's the right place. The formatting test just 
tests that it breaks at a position. This here intents to test that it the flag 
`MustBreakBefore` is set.

I'm in favor of this kind of test, but don't insist on it.

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread Björn Schäpers via cfe-commits


@@ -1444,16 +1444,22 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // dangling comma
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+!MatchingParen->MatchingParen->Previous->is(tok::equal)

HazardyKnusperkeks wrote:

```suggestion
MatchingParen->MatchingParen->Previous->isNot(tok::equal)
```
`MatchingParen->MatchingParen` shouldn't we be back where we started? Whatever 
is going on here, I think a comment would be helpful.

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


[clang] [clang-format] Handle templated elaborated type specifier in function… (PR #77013)

2024-01-06 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks commented:

Ok, one last thing. From what I figured it was wrongly detected as class 
definition. So you could add a token annotator test, which verifies that the 
`{` is not an `ClassLBrace`?

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


[flang] [clang] [llvm] [compiler-rt] [libc] [clang-tools-extra] [lldb] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

I reverted the commit.

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


[llvm] [libcxx] [clang] Reapply "[libc++][streams] P1759R6: Native handles and file streams" (PR #77190)

2024-01-06 Thread Hristo Hristov via cfe-commits

https://github.com/Zingam updated 
https://github.com/llvm/llvm-project/pull/77190

>From 1d2c365efe493b4d62cb84a517d00a7d9dbd58b7 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sat, 6 Jan 2024 12:47:23 +0200
Subject: [PATCH 1/2] Revert "Revert "[libc++][streams] P1759R6: Native handles
 and file streams (#76632)""

This reverts commit 40c07b559aa6ab4bac074c943967d3207bc07ae0.
---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/ReleaseNotes/18.rst   |  1 +
 libcxx/docs/Status/Cxx2cPapers.csv|  2 +-
 libcxx/include/fstream| 50 ++
 libcxx/include/version|  2 +-
 libcxx/src/CMakeLists.txt |  1 +
 libcxx/src/fstream.cpp| 37 +++
 .../native_handle.assert.pass.cpp | 32 ++
 .../filebuf.members/native_handle.pass.cpp| 58 +++
 .../fstreams/filebuf/types.pass.cpp   |  9 +-
 .../native_handle.assert.pass.cpp | 32 ++
 .../fstream.members/native_handle.pass.cpp| 27 ++
 .../fstreams/fstream/types.pass.cpp   |  9 +-
 .../native_handle.assert.pass.cpp | 32 ++
 .../ifstream.members/native_handle.pass.cpp   | 27 ++
 .../fstreams/ifstream/types.pass.cpp  |  9 +-
 .../fstreams/native_handle_test_helpers.h | 97 +++
 .../native_handle.assert.pass.cpp | 32 ++
 .../ofstream.members/native_handle.pass.cpp   | 27 ++
 .../fstreams/ofstream/types.pass.cpp  |  9 +-
 .../file.streams/fstreams/types.h | 10 ++
 .../fstream.version.compile.pass.cpp  | 16 +--
 .../version.version.compile.pass.cpp  | 16 +--
 .../generate_feature_test_macro_components.py |  1 -
 24 files changed, 508 insertions(+), 30 deletions(-)
 create mode 100644 libcxx/src/fstream.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/filebuf.members/native_handle.assert.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/filebuf.members/native_handle.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/fstream.members/native_handle.assert.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/fstream.members/native_handle.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/native_handle.assert.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/native_handle.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/native_handle_test_helpers.h
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/ofstream.members/native_handle.assert.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/ofstream.members/native_handle.pass.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index 8ce5ec9f64ef9a..893a3b13ca06e0 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index cae2347be5fd61..882f53b8d9f83f 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -59,6 +59,7 @@ Implemented Papers
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P2821R5 - span.at()
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index fa4a112d143673..5701717f39766c 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 

[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2024-01-06 Thread via cfe-commits


@@ -836,6 +837,70 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
,
   if (Opts.RWPI)
 Builder.defineMacro("__ARM_RWPI", "1");
 
+  // Macros for enabling co-proc intrinsics
+  uint64_t FeatureCoprocBF = 0;
+  switch (ArchKind) {
+  default:
+break;
+  case llvm::ARM::ArchKind::ARMV4:
+// Filter __arm_ldcl and __arm_stcl in acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARM5T:
+FeatureCoprocBF = isThumb() ? 0 : FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARMV5TE:
+  case llvm::ARM::ArchKind::ARMV5TEJ:
+if (!isThumb())
+  FeatureCoprocBF =
+  FEATURE_COPROC_B1 | FEATURE_COPROC_B2 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV6:
+  case llvm::ARM::ArchKind::ARMV6K:
+  case llvm::ARM::ArchKind::ARMV6KZ:
+  case llvm::ARM::ArchKind::ARMV6T2:
+if (!isThumb() || ArchKind == llvm::ARM::ArchKind::ARMV6T2)
+  FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV7A:
+  case llvm::ARM::ArchKind::ARMV7R:
+  case llvm::ARM::ArchKind::ARMV7M:
+  case llvm::ARM::ArchKind::ARMV7S:
+  case llvm::ARM::ArchKind::ARMV7EM:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV8A:
+  case llvm::ARM::ArchKind::ARMV8R:
+  case llvm::ARM::ArchKind::ARMV8_1A:
+  case llvm::ARM::ArchKind::ARMV8_2A:
+  case llvm::ARM::ArchKind::ARMV8_3A:
+  case llvm::ARM::ArchKind::ARMV8_4A:
+  case llvm::ARM::ArchKind::ARMV8_5A:
+  case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
+  case llvm::ARM::ArchKind::ARMV8_8A:
+  case llvm::ARM::ArchKind::ARMV8_9A:
+// Filter __arm_cdp, __arm_ldcl, __arm_stcl in arm_acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV8MMainline:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV9A:
+  case llvm::ARM::ArchKind::ARMV9_1A:
+  case llvm::ARM::ArchKind::ARMV9_2A:
+  case llvm::ARM::ArchKind::ARMV9_3A:
+  case llvm::ARM::ArchKind::ARMV9_4A:

hstk30-hw wrote:

In this https://gist.github.com/davemgreen/e7ade833274a60e975e67a66eda7cb44, 
not have  test cases on ARMV9. According to the code logic, ARMV9 seem support 
all Coprocessor Instrinsics. This is different from ARMV8, I'm not sure, so the 
default case is 0 for now.

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


[clang-tools-extra] [compiler-rt] [lldb] [llvm] [libc] [flang] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread Kai Luo via cfe-commits
Thorsten =?utf-8?q?Schütt?= ,
Thorsten =?utf-8?q?Schütt?= ,
Thorsten =?utf-8?q?Schütt?= 
Message-ID:
In-Reply-To: 


bzEq wrote:

It's also exhausting memory when `llvm-lit 
llvm-project/llvm/test/CodeGen/AMDGPU/llvm.exp2.ll`.
See https://lab.llvm.org/buildbot/#/builders/249/builds/13786.

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


[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2024-01-06 Thread via cfe-commits


@@ -836,6 +837,70 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
,
   if (Opts.RWPI)
 Builder.defineMacro("__ARM_RWPI", "1");
 
+  // Macros for enabling co-proc intrinsics
+  uint64_t FeatureCoprocBF = 0;
+  switch (ArchKind) {
+  default:
+break;
+  case llvm::ARM::ArchKind::ARMV4:
+// Filter __arm_ldcl and __arm_stcl in acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARM5T:
+FeatureCoprocBF = isThumb() ? 0 : FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARMV5TE:
+  case llvm::ARM::ArchKind::ARMV5TEJ:
+if (!isThumb())
+  FeatureCoprocBF =
+  FEATURE_COPROC_B1 | FEATURE_COPROC_B2 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV6:
+  case llvm::ARM::ArchKind::ARMV6K:
+  case llvm::ARM::ArchKind::ARMV6KZ:
+  case llvm::ARM::ArchKind::ARMV6T2:
+if (!isThumb() || ArchKind == llvm::ARM::ArchKind::ARMV6T2)
+  FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV7A:
+  case llvm::ARM::ArchKind::ARMV7R:
+  case llvm::ARM::ArchKind::ARMV7M:
+  case llvm::ARM::ArchKind::ARMV7S:
+  case llvm::ARM::ArchKind::ARMV7EM:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV8A:
+  case llvm::ARM::ArchKind::ARMV8R:
+  case llvm::ARM::ArchKind::ARMV8_1A:
+  case llvm::ARM::ArchKind::ARMV8_2A:
+  case llvm::ARM::ArchKind::ARMV8_3A:
+  case llvm::ARM::ArchKind::ARMV8_4A:
+  case llvm::ARM::ArchKind::ARMV8_5A:
+  case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
+  case llvm::ARM::ArchKind::ARMV8_8A:
+  case llvm::ARM::ArchKind::ARMV8_9A:
+// Filter __arm_cdp, __arm_ldcl, __arm_stcl in arm_acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV8MMainline:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV9A:
+  case llvm::ARM::ArchKind::ARMV9_1A:
+  case llvm::ARM::ArchKind::ARMV9_2A:
+  case llvm::ARM::ArchKind::ARMV9_3A:
+  case llvm::ARM::ArchKind::ARMV9_4A:

hstk30-hw wrote:

We need defined ARMV9_5A in ARMTargetParser.def first.

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


[clang-tools-extra] [compiler-rt] [lldb] [llvm] [libc] [flang] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

The file was not changed by this PR and there is no `select` in the file.

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


[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2024-01-06 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/75440

>From 18af0ae248707b7c33b24065cdbab5399337f8bc Mon Sep 17 00:00:00 2001
From: hstk30-hw 
Date: Thu, 14 Dec 2023 15:40:03 +0800
Subject: [PATCH] feat: arm_acle.h add Coprocessor Instrinsics

---
 clang/lib/Basic/Targets/ARM.cpp   |  67 
 clang/lib/Basic/Targets/ARM.h |  13 +
 clang/lib/Headers/arm_acle.h  |  59 +++
 clang/test/CodeGen/arm-acle-coproc.c  | 365 ++
 .../Preprocessor/aarch64-target-features.c|   1 +
 5 files changed, 505 insertions(+)
 create mode 100644 clang/test/CodeGen/arm-acle-coproc.c

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index ce7e4d4639ceac..d9844b3a837554 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -17,6 +17,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/TargetParser/ARMTargetParser.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -836,6 +837,72 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
,
   if (Opts.RWPI)
 Builder.defineMacro("__ARM_RWPI", "1");
 
+  // Macros for enabling co-proc intrinsics
+  uint64_t FeatureCoprocBF = 0;
+  switch (ArchKind) {
+  default:
+break;
+  case llvm::ARM::ArchKind::ARMV4:
+  case llvm::ARM::ArchKind::ARMV4T:
+// Filter __arm_ldcl and __arm_stcl in acle.h
+FeatureCoprocBF = isThumb() ? 0 : FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARMV5T:
+FeatureCoprocBF = isThumb() ? 0 : FEATURE_COPROC_B1 | FEATURE_COPROC_B2;
+break;
+  case llvm::ARM::ArchKind::ARMV5TE:
+  case llvm::ARM::ArchKind::ARMV5TEJ:
+if (!isThumb())
+  FeatureCoprocBF =
+  FEATURE_COPROC_B1 | FEATURE_COPROC_B2 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV6:
+  case llvm::ARM::ArchKind::ARMV6K:
+  case llvm::ARM::ArchKind::ARMV6KZ:
+  case llvm::ARM::ArchKind::ARMV6T2:
+if (!isThumb() || ArchKind == llvm::ARM::ArchKind::ARMV6T2)
+  FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV7A:
+  case llvm::ARM::ArchKind::ARMV7R:
+  case llvm::ARM::ArchKind::ARMV7M:
+  case llvm::ARM::ArchKind::ARMV7S:
+  case llvm::ARM::ArchKind::ARMV7EM:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV8A:
+  case llvm::ARM::ArchKind::ARMV8R:
+  case llvm::ARM::ArchKind::ARMV8_1A:
+  case llvm::ARM::ArchKind::ARMV8_2A:
+  case llvm::ARM::ArchKind::ARMV8_3A:
+  case llvm::ARM::ArchKind::ARMV8_4A:
+  case llvm::ARM::ArchKind::ARMV8_5A:
+  case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
+  case llvm::ARM::ArchKind::ARMV8_8A:
+  case llvm::ARM::ArchKind::ARMV8_9A:
+// Filter __arm_cdp, __arm_ldcl, __arm_stcl in arm_acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV8MMainline:
+  case llvm::ARM::ArchKind::ARMV8_1MMainline:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV9A:
+  case llvm::ARM::ArchKind::ARMV9_1A:
+  case llvm::ARM::ArchKind::ARMV9_2A:
+  case llvm::ARM::ArchKind::ARMV9_3A:
+  case llvm::ARM::ArchKind::ARMV9_4A:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  }
+  Builder.defineMacro("__ARM_FEATURE_COPROC",
+  "0x" + Twine::utohexstr(FeatureCoprocBF));
+
   if (ArchKind == llvm::ARM::ArchKind::XSCALE)
 Builder.defineMacro("__XSCALE__");
 
diff --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index b1aa2794c7e4c3..9802eb01abf3c4 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -100,6 +100,19 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public 
TargetInfo {
   };
   uint32_t HW_FP;
 
+  enum {
+/// __arm_cdp __arm_ldc, __arm_ldcl, __arm_stc,
+/// __arm_stcl, __arm_mcr and __arm_mrc
+FEATURE_COPROC_B1 = (1 << 0),
+/// __arm_cdp2, __arm_ldc2, __arm_stc2, __arm_ldc2l,
+/// __arm_stc2l, __arm_mcr2 and __arm_mrc2
+FEATURE_COPROC_B2 = (1 << 1),
+/// __arm_mcrr, __arm_mrrc
+FEATURE_COPROC_B3 = (1 << 2),
+/// __arm_mcrr2,  __arm_mrrc2
+FEATURE_COPROC_B4 = (1 << 3),
+  };
+
   void setABIAAPCS();
   void setABIAPCS(bool IsAAPCS16);
 
diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 61d80258d166a1..9aae2285aeb1d8 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -756,6 +756,65 @@ __arm_st64bv0(void *__addr, data512_t __value) {
   

[clang-tools-extra] [compiler-rt] [lldb] [llvm] [libc] [flang] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

I had also issues with this test. There is also a GH issue: 
https://github.com/llvm/llvm-project/issues/76821.

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


[clang-tools-extra] [compiler-rt] [lldb] [llvm] [libc] [flang] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread via cfe-commits
Thorsten =?utf-8?q?Schütt?= ,
Thorsten =?utf-8?q?Schütt?= ,
Thorsten =?utf-8?q?Schütt?= 
Message-ID:
In-Reply-To: 


ronlieb wrote:

@jhuber6 @jplehrthis may also be failing in staging libc bot 
https://lab.llvm.org/staging/#/builders/134

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


[clang-tools-extra] [compiler-rt] [lldb] [llvm] [libc] [flang] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread via cfe-commits
Thorsten =?utf-8?q?Sch=C3=BCtt?= ,
Thorsten =?utf-8?q?Sch=C3=BCtt?= ,
Thorsten =?utf-8?q?Sch=C3=BCtt?= 
Message-ID:
In-Reply-To: 


ronlieb wrote:

this lit test is now taking a very long time after this patch landed
 ./bin/llvm-lit ../llvm/test/CodeGen/AMDGPU/llvm.log2.ll 

relevant cmake settings:
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_PROJECTS="clang;lld;llvm;flang" \
  -DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" \
  -DLLVM_ENABLE_ASSERTIONS=ON\
  -DLLVM_ENABLE_RUNTIMES="openmp;compiler-rt" \
  -DCLANG_DEFAULT_LINKER=lld \


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


[llvm] [clang] [RFC] Introducing `__builtin_consistent` to generate AArch64 BC.cond … (PR #72175)

2024-01-06 Thread Nikita Popov via cfe-commits

nikic wrote:

@davidbolvansky The semantics of this builtin are slightly different, see the 
discussion at 
https://discourse.llvm.org/t/rfc-consistent-branches-support-in-llvm/74889. But 
yes, the consensus is that adding this builtin is not worthwhile.

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


[clang] 0c7d46a - [Clang] Correctly construct template arguments for template template parameters (#76811)

2024-01-06 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-01-06T22:26:34+08:00
New Revision: 0c7d46a7fd5b7956e285d385a6945153d6a06eb0

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

LOG: [Clang] Correctly construct template arguments for template template 
parameters (#76811)

This fixes the bug introduced by

https://github.com/llvm/llvm-project/commit/6db007a0654ed7a6ed5c3aa3b61a937c19a6bc6b.

We construct placeholder template arguments for template-template
parameters to avoid mismatching argument substitution since they have
different depths with their corresponding template arguments. In this
case,

```cpp
template  class T> void foo(T);
```

T lies at the depth 0, and C lies at 1. The corresponding argument, of
which there is exactly one, int, is at depth 0. If we consider the
argument as the outermost one, then we would end up substituting 'int'
into the wrong parameter T.

We used to perform such placeholder construction during the context
walk-up. In the previous patch, we slipped through that inadvertently
because we would walk up to the parent, which is precisely a FileContext
for template-template parameters, after adding innermost arguments.

Besides, this patch moves the sanity check up to the context switch.
That way, we avoid dereferencing null pointers if ND is unspecified.

Closes https://github.com/llvm/llvm-project/issues/57410.
Closes https://github.com/llvm/llvm-project/issues/76604. (The case is
slightly different than that in #57410. We should *not* assume the
surrounding context to be a file-scope one.)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9b6e00b231216b..154412144ef97a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -857,6 +857,11 @@ Bug Fixes to C++ Support
   (`#64607 `_)
   (`#64086 `_)
 
+- Fixed a regression where clang forgets how to substitute into constraints on 
template-template
+  parameters. Fixes: 
+  (`#57410 `_) and
+  (`#76604 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 09dd119ed1b948..7f20413c104e97 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -344,15 +344,26 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
 
   using namespace TemplateInstArgsHelpers;
   const Decl *CurDecl = ND;
+
+  if (!CurDecl)
+CurDecl = Decl::castFromDeclContext(DC);
+
   if (Innermost) {
 Result.addOuterTemplateArguments(const_cast(ND),
  Innermost->asArray(), Final);
-CurDecl = Response::UseNextDecl(ND).NextDecl;
+// Populate placeholder template arguments for TemplateTemplateParmDecls.
+// This is essential for the case e.g.
+//
+// template  concept Concept = false;
+// template  class T> void foo(T)
+//
+// where parameter C has a depth of 1 but the substituting argument `int`
+// has a depth of 0.
+if (const auto *TTP = dyn_cast(CurDecl))
+  HandleDefaultTempArgIntoTempTempParam(TTP, Result);
+CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
   }
 
-  if (!ND)
-CurDecl = Decl::castFromDeclContext(DC);
-
   while (!CurDecl->isFileContextDecl()) {
 Response R;
 if (const auto *VarTemplSpec =
@@ -380,10 +391,8 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
   R = Response::ChangeDecl(CTD->getLexicalDeclContext());
 } else if (!isa(CurDecl)) {
   R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
-  if (CurDecl->getDeclContext()->isTranslationUnit()) {
-if (const auto *TTP = dyn_cast(CurDecl)) {
-  R = HandleDefaultTempArgIntoTempTempParam(TTP, Result);
-}
+  if (const auto *TTP = dyn_cast(CurDecl)) {
+R = HandleDefaultTempArgIntoTempTempParam(TTP, Result);
   }
 } else {
   R = HandleGenericDeclContext(CurDecl);

diff  --git a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp 
b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
index 449b6232542e24..f586069638614b 100644
--- a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -59,3 +59,32 @@ struct Nothing {};
 
 // FIXME: Wait the standard 

  1   2   >