[clang-tools-extra] [clangd] Augment code completion results with documentation from the index. (PR #120099)

2024-12-17 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 02328e0465c256293950542f1a85eb55bcbc9d45 
ace8121506029e9016df9ec3bffa9d465334e97d --extensions cpp -- 
clang-tools-extra/clangd/CodeComplete.cpp 
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 827b64c882..607236c5b0 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1130,9 +1130,8 @@ int x = a.^
   auto CompletionList =
   llvm::cantFail(runCodeComplete(Server, File, Test.point(), {}));
 
-  EXPECT_THAT(
-  CompletionList.Completions,
-  Contains(AllOf(named("gamma"), doc("This is a member field.";
+  EXPECT_THAT(CompletionList.Completions,
+  Contains(AllOf(named("gamma"), doc("This is a member field.";
   EXPECT_THAT(
   CompletionList.Completions,
   Contains(AllOf(named("delta"), doc("This is a member function.";

``




https://github.com/llvm/llvm-project/pull/120099
___
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 readability-string-view-substr check (PR #120055)

2024-12-17 Thread Helmut Januschka via cfe-commits

https://github.com/hjanuschka ready_for_review 
https://github.com/llvm/llvm-project/pull/120055
___
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 readability-string-view-substr check (PR #120055)

2024-12-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Helmut Januschka (hjanuschka)


Changes

Add a new check that suggests using `string_view::remove_prefix()` and 
`remove_suffix()` instead of `substr()` when the intent is to remove characters 
from either end of a string_view.


edit: have not found an existing check, if there is any, please let me know


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


7 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/CMakeLists.txt (+1) 
- (modified) clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
(+3) 
- (added) clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp 
(+201) 
- (added) clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.h 
(+39) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+7) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/readability/string-view-substr.rst 
(+18) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/stringview_substr.cpp 
(+108) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 8f303c51e1b0da..8b44fc339441ac 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -53,6 +53,7 @@ add_clang_library(clangTidyReadabilityModule STATIC
   StaticAccessedThroughInstanceCheck.cpp
   StaticDefinitionInAnonymousNamespaceCheck.cpp
   StringCompareCheck.cpp
+  StringViewSubstrCheck.cpp
   SuspiciousCallArgumentCheck.cpp
   UniqueptrDeleteReleaseCheck.cpp
   UppercaseLiteralSuffixCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index d61c0ba39658e5..f36ec8f95ede60 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -56,6 +56,7 @@
 #include "StaticAccessedThroughInstanceCheck.h"
 #include "StaticDefinitionInAnonymousNamespaceCheck.h"
 #include "StringCompareCheck.h"
+#include "StringViewSubstrCheck.h"
 #include "SuspiciousCallArgumentCheck.h"
 #include "UniqueptrDeleteReleaseCheck.h"
 #include "UppercaseLiteralSuffixCheck.h"
@@ -146,6 +147,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-static-definition-in-anonymous-namespace");
 CheckFactories.registerCheck(
 "readability-string-compare");
+CheckFactories.registerCheck(
+"readability-stringview-substr");
 CheckFactories.registerCheck(
 "readability-named-parameter");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
new file mode 100644
index 00..5c079e3203c989
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
@@ -0,0 +1,201 @@
+//===--- StringViewSubstrCheck.cpp - clang-tidy--*- 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
+//
+//===--===//
+
+#include "StringViewSubstrCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void StringViewSubstrCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasStringViewType = 
hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(recordDecl(hasName("::std::basic_string_view"));
+
+  // Match assignment to string_view's substr
+  Finder->addMatcher(
+  cxxOperatorCallExpr(
+  hasOverloadedOperatorName("="),
+  hasArgument(0, expr(HasStringViewType).bind("target")),
+  hasArgument(
+  1, cxxMemberCallExpr(callee(memberExpr(hasDeclaration(
+   cxxMethodDecl(hasName("substr"),
+   on(expr(HasStringViewType).bind("source")))
+ .bind("substr_call")))
+  .bind("assignment"),
+  this);
+}
+
+void StringViewSubstrCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Assignment =
+  Result.Nodes.getNodeAs("assignment");
+  const auto *Target = Result.Nodes.getNodeAs("target");
+  const auto *Source = Result.Nodes.getNodeAs("source");
+  const auto *SubstrCall =
+  Result.Nodes.getNodeAs("substr_call");
+
+  if (!Assignment || !Target || !Source || !SubstrCall) {
+return;
+  }
+
+  // Get the DeclRefExpr for the target and source
+  const auto *TargetDRE = dyn_cast(Target->IgnoreParenImpCasts());
+  const a

[clang-tools-extra] [clang-tidy] Add readability-string-view-substr check (PR #120055)

2024-12-17 Thread Helmut Januschka via cfe-commits

https://github.com/hjanuschka edited 
https://github.com/llvm/llvm-project/pull/120055
___
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 readability-string-view-substr check (PR #120055)

2024-12-17 Thread Helmut Januschka via cfe-commits

https://github.com/hjanuschka updated 
https://github.com/llvm/llvm-project/pull/120055

>From 8b2dc9adf4fae2065823e5beb3a1cd851686913c Mon Sep 17 00:00:00 2001
From: Helmut Januschka 
Date: Mon, 16 Dec 2024 08:24:14 +0100
Subject: [PATCH 1/5] [clang-tidy] Add readability-string-view-substr check

Add a new check that suggests using string_view::remove_prefix() and
remove_suffix() instead of substr() when the intent is to remove
characters from either end of a string_view.
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../readability/StringViewSubstrCheck.cpp | 132 ++
 .../readability/StringViewSubstrCheck.h   |  39 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   7 +
 .../checks/readability/string-view-substr.rst |  16 +++
 .../readability/stringview_substr.cpp |  55 
 7 files changed, 253 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/string-view-substr.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/stringview_substr.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 8f303c51e1b0da..8b44fc339441ac 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -53,6 +53,7 @@ add_clang_library(clangTidyReadabilityModule STATIC
   StaticAccessedThroughInstanceCheck.cpp
   StaticDefinitionInAnonymousNamespaceCheck.cpp
   StringCompareCheck.cpp
+  StringViewSubstrCheck.cpp
   SuspiciousCallArgumentCheck.cpp
   UniqueptrDeleteReleaseCheck.cpp
   UppercaseLiteralSuffixCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index d61c0ba39658e5..f36ec8f95ede60 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -56,6 +56,7 @@
 #include "StaticAccessedThroughInstanceCheck.h"
 #include "StaticDefinitionInAnonymousNamespaceCheck.h"
 #include "StringCompareCheck.h"
+#include "StringViewSubstrCheck.h"
 #include "SuspiciousCallArgumentCheck.h"
 #include "UniqueptrDeleteReleaseCheck.h"
 #include "UppercaseLiteralSuffixCheck.h"
@@ -146,6 +147,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-static-definition-in-anonymous-namespace");
 CheckFactories.registerCheck(
 "readability-string-compare");
+CheckFactories.registerCheck(
+"readability-stringview-substr");
 CheckFactories.registerCheck(
 "readability-named-parameter");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
new file mode 100644
index 00..e86a971695a835
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
@@ -0,0 +1,132 @@
+//===--- StringViewSubstrCheck.cpp - clang-tidy--*- 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
+//
+//===--===//
+
+#include "StringViewSubstrCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void StringViewSubstrCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasStringViewType = 
hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(recordDecl(hasName("::std::basic_string_view"));
+
+  // Match assignment to string_view's substr
+  Finder->addMatcher(
+  cxxOperatorCallExpr(
+  hasOverloadedOperatorName("="),
+  hasArgument(0, expr(HasStringViewType).bind("target")),
+  hasArgument(
+  1, cxxMemberCallExpr(callee(memberExpr(hasDeclaration(
+   cxxMethodDecl(hasName("substr"),
+   on(expr(HasStringViewType).bind("source")))
+ .bind("substr_call")))
+  .bind("assignment"),
+  this);
+}
+
+void StringViewSubstrCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Assignment =
+  Result.Nodes.getNodeAs("assignment");
+  const auto *Target = Result.Nodes.getNodeAs("target");
+  const auto *Source = Result.Nodes.getNodeAs("source");
+  const auto *SubstrCall =
+  Result.Nod

[clang] [analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) (PR #116462)

2024-12-17 Thread Vinay Deshmukh via cfe-commits

https://github.com/vinay-deshmukh edited 
https://github.com/llvm/llvm-project/pull/116462
___
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 readability-string-view-substr check (PR #120055)

2024-12-17 Thread Helmut Januschka via cfe-commits

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


[libunwind] [Libunwind] Try to fix msan failures (PR #120013)

2024-12-17 Thread Dmitry Chestnykh via cfe-commits

chestnykh wrote:

I've debugged msan errors. On CI there were stack overflows caused by 'wrong' 
msan reports and circular calls libunwind -> libmsan -> libunwind.

For example:
```
#4234 0x55587eb2 in __msan_warning_with_origin_noreturn () at 
/home/dima/work/llvm-project/compiler-rt/lib/msan/msan.cpp:422
#4235 0x77f7828e in libunwind::Registers_x86_64::getRegister 
(this=0x7fa07cc0, regNum=-1) at 
/home/dima/work/llvm-project/libunwind/src/Registers.hpp:412
#4236 0x77f72b5c in 
libunwind::UnwindCursor::getReg (this=0x7fa07cb0, regNum=-1)
at /home/dima/work/llvm-project/libunwind/src/UnwindCursor.hpp:1353
#4237 0x77f741a3 in 
libunwind::UnwindCursor::setInfoBasedOnIPRegister (this=0x7fa07cb0, 
isReturnAddress=false)
at /home/dima/work/llvm-project/libunwind/src/UnwindCursor.hpp:2561
#4238 0x77f6477f in __unw_init_local (cursor=0x7fa07cb0, 
context=0x7fa07c08) at 
/home/dima/work/llvm-project/libunwind/src/libunwind.cpp:91
#4239 0x77fb2f48 in _Unwind_Backtrace (callback=0x5561be20 
, ref=0x7fa07de8) at 
/home/dima/work/llvm-project/libunwind/src/UnwindLevel1-gcc-ext.c:137
#4240 0x5561bdcb in UnwindSlow () at 
/home/dima/work/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cpp:130
#4241 0x55615455 in __sanitizer::BufferedStackTrace::Unwind(unsigned 
int, unsigned long, unsigned long, void*, unsigned long, unsigned long, bool) ()
at 
/home/dima/work/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp:158
#4242 0x55587985 in UnwindImpl () at 
/home/dima/work/llvm-project/compiler-rt/lib/msan/msan.cpp:342
#4243 0x55587578 in Unwind () at 
/home/dima/work/llvm-project/compiler-rt/lib/msan/../sanitizer_common/sanitizer_stacktrace.h:130
#4244 PrintWarningWithOrigin () at 
/home/dima/work/llvm-project/compiler-rt/lib/msan/msan.cpp:247
#4245 0x55587eb2 in __msan_warning_with_origin_noreturn () at 
/home/dima/work/llvm-project/compiler-rt/lib/msan/msan.cpp:422

```

There were also regular msan reports fixed by modifying tests srcs to add 
explicit initialization of unw_cursor_t and unw_context_t variables:

```
# .---command stderr
# | ==152363==WARNING: MemorySanitizer: use-of-uninitialized-value
# | #0 0x77fa6564  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test-suite-install/lib/x86_64-unknown-linux-gnu/libunwind.so.1+0x6564)
# | #1 0x77fa6bee  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test-suite-install/lib/x86_64-unknown-linux-gnu/libunwind.so.1+0x6bee)
# | #2 0x77fa28f9  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test-suite-install/lib/x86_64-unknown-linux-gnu/libunwind.so.1+0x28f9)
# | #3 0x5562481d  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test/Output/unw_resume.pass.cpp.dir/t.tmp.exe+0xd081d)
# | #4 0x556248a6  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test/Output/unw_resume.pass.cpp.dir/t.tmp.exe+0xd08a6)
# | #5 0x77945e07  (/usr/lib/libc.so.6+0x25e07) (BuildId: 
98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
# | #6 0x77945ecb  (/usr/lib/libc.so.6+0x25ecb) (BuildId: 
98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
# | #7 0x55587334  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test/Output/unw_resume.pass.cpp.dir/t.tmp.exe+0x4)
# | 
# |   Uninitialized value was stored to memory at
# | #0 0x5558e52d  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test/Output/unw_resume.pass.cpp.dir/t.tmp.exe+0x3a52d)
# | #1 0x77fa28dc  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test-suite-install/lib/x86_64-unknown-linux-gnu/libunwind.so.1+0x28dc)
# | #2 0x5562481d  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test/Output/unw_resume.pass.cpp.dir/t.tmp.exe+0xd081d)
# | #3 0x556248a6  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test/Output/unw_resume.pass.cpp.dir/t.tmp.exe+0xd08a6)
# | #4 0x77945e07  (/usr/lib/libc.so.6+0x25e07) (BuildId: 
98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
# | #5 0x77945ecb  (/usr/lib/libc.so.6+0x25ecb) (BuildId: 
98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
# | #6 0x55587334  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test/Output/unw_resume.pass.cpp.dir/t.tmp.exe+0x4)
# | 
# |   Uninitialized value was created by an allocation of 'context' in the 
stack frame
# | #0 0x556247bc  
(/home/dima/work/llvm-project/build/runtimes/runtimes-bins/libunwind/test/Output/unw_resume.pass.cpp.dir/t.tmp.exe+0xd07bc)

```

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

[clang] 514580b - [MTE] Apply alignment / size in AsmPrinter rather than IR (#111918)

2024-12-17 Thread via cfe-commits

Author: Florian Mayer
Date: 2024-12-17T00:47:02-08:00
New Revision: 514580b43898921cc95659de47b383bd2c9b4b12

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

LOG: [MTE] Apply alignment / size in AsmPrinter rather than IR (#111918)

This makes sure no optimizations are applied that assume the
bigger alignment or size, which could be incorrect if we link
together with non-instrumented code.

Added: 


Modified: 
clang/lib/CodeGen/SanitizerMetadata.cpp
clang/test/CodeGen/memtag-globals.cpp
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Target/AArch64/AArch64.h
llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
llvm/lib/Target/AArch64/CMakeLists.txt
llvm/test/CodeGen/AArch64/O0-pipeline.ll
llvm/test/CodeGen/AArch64/O3-pipeline.ll
llvm/unittests/IR/VerifierTest.cpp
llvm/utils/gn/secondary/llvm/lib/Target/AArch64/BUILD.gn

Removed: 
llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp



diff  --git a/clang/lib/CodeGen/SanitizerMetadata.cpp 
b/clang/lib/CodeGen/SanitizerMetadata.cpp
index c1a6b223480a19..cf4f74d1c50afa 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -31,6 +31,37 @@ static SanitizerMask 
expandKernelSanitizerMasks(SanitizerMask Mask) {
   return Mask;
 }
 
+static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
+  // For now, don't instrument constant data, as it'll be in .rodata anyway. It
+  // may be worth instrumenting these in future to stop them from being used as
+  // gadgets.
+  if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant())
+return false;
+
+  // Globals can be placed implicitly or explicitly in sections. There's two
+  // 
diff erent types of globals that meet this criteria that cause problems:
+  //  1. Function pointers that are going into various init arrays (either
+  // explicitly through `__attribute__((section()))` or implicitly
+  // through `__attribute__((constructor)))`, such as ".(pre)init(_array)",
+  // ".fini(_array)", ".ctors", and ".dtors". These function pointers end 
up
+  // overaligned and overpadded, making iterating over them problematic, 
and
+  // each function pointer is individually tagged (so the iteration over
+  // them causes SIGSEGV/MTE[AS]ERR).
+  //  2. Global variables put into an explicit section, where the section's 
name
+  // is a valid C-style identifier. The linker emits a `__start_` and
+  // `__stop_` symbol for the section, so that you can iterate over
+  // globals within this section. Unfortunately, again, these globals would
+  // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR.
+  //
+  // To mitigate both these cases, and because specifying a section is rare
+  // outside of these two cases, disable MTE protection for globals in any
+  // section.
+  if (G.hasSection())
+return false;
+
+  return true;
+}
+
 void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV,
  SourceLocation Loc, StringRef Name,
  QualType Ty,
@@ -57,11 +88,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable 
*GV,
   Meta.NoHWAddress |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty);
 
-  Meta.Memtag |=
-  static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals);
-  Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
-  Meta.Memtag &= !CGM.isInNoSanitizeList(
-  FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  if (shouldTagGlobal(*GV)) {
+Meta.Memtag |= static_cast(FsanitizeArgument.Mask &
+ SanitizerKind::MemtagGlobals);
+Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
+Meta.Memtag &= !CGM.isInNoSanitizeList(
+FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  } else {
+Meta.Memtag = false;
+  }
 
   Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
FsanitizeArgument.has(SanitizerKind::Address) &&

diff  --git a/clang/test/CodeGen/memtag-globals.cpp 
b/clang/test/CodeGen/memtag-globals.cpp
index ae2d32ae8a56d9..0d7fe22a7b0f07 100644
--- a/clang/test/CodeGen/memtag-globals.cpp
+++ b/clang/test/CodeGen/memtag-globals.cpp
@@ -10,6 +10,7 @@
 // RUN:   FileCheck %s --check-prefix=IGNORELIST
 
 int global;
+int __attribute__((__section__("my_section"))) section_global;
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;
 int ignorelisted_global;
@@ -24,6 +25,8 @@ void func() {
 // CHECK: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
 // CHEC

[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-12-17 Thread Florian Mayer via cfe-commits

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


[clang] Reland [Clang] skip default argument instantiation for non-defining friend declarations to meet [dcl.fct.default] p4 (PR #115487)

2024-12-17 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/115487

>From 5e24d212f797b5fa1b6da1526c807046373d3c21 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 8 Nov 2024 16:13:17 +0200
Subject: [PATCH 1/6] [Clang] skip default argument instantiation for
 non-defining friend declarations to meet [dcl.fct.default] p4

---
 clang/docs/ReleaseNotes.rst   |  2 +
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  4 ++
 clang/test/CXX/temp/temp.res/p4.cpp   | 43 +++
 3 files changed, 49 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0c43ff11f7bae..e8cf6fc50a1290 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -636,6 +636,8 @@ Bug Fixes to C++ Support
   an implicitly instantiated class template specialization. (#GH51051)
 - Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 - Name independent data members were not correctly initialized from default 
member initializers. (#GH114069)
+- Fixed an assertion failure caused by invalid default argument substitutions 
in non-defining
+  friend declarations. (#GH113324).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5a001843e2ba46..200519c71c57ab 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4694,6 +4694,10 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  if (FD->getFriendObjectKind() != Decl::FOK_None &&
+  !FD->getTemplateInstantiationPattern())
+return true;
+
   // Instantiate the expression.
   //
   // FIXME: Pass in a correct Pattern argument, otherwise
diff --git a/clang/test/CXX/temp/temp.res/p4.cpp 
b/clang/test/CXX/temp/temp.res/p4.cpp
index f54d8649f5da88..cf6c45b4c351c5 100644
--- a/clang/test/CXX/temp/temp.res/p4.cpp
+++ b/clang/test/CXX/temp/temp.res/p4.cpp
@@ -185,3 +185,46 @@ template struct S {
   friend void X::f(T::type);
 };
 }
+
+namespace GH113324 {
+template  struct S1 {
+  friend void f1(S1, int = 0); // expected-error {{friend declaration 
specifying a default argument must be a definition}}
+  friend void f2(S1 a, S1 = decltype(a){}); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+template  using alias = int;
+template  struct S2 {
+  // FIXME: We miss diagnosing the default argument instantiation failure
+  // (forming reference to void)
+  friend void f3(S2, int a = alias(1)); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+struct S3 {
+  friend void f4(S3, int = 42) { }
+};
+
+template  using __enable_if_t = int;
+template  struct S4 {
+  static const int value = v;
+};
+struct S5 {
+  template <__enable_if_t::value, int> = 0>
+  S5(const char *);
+};
+struct S6 {
+  template 
+  friend void f5(int, S6, a, b, S5 = "") { }
+};
+
+void test() {
+  f1(S1<>{});
+  f2(S1<>{});
+  f3(S2());
+
+  S3 s3;
+  f4(s3);
+
+  S6 s6;
+  auto result = f5(0, s6, [] {}, [] {}); // expected-error {{variable has 
incomplete type 'void}}
+}
+} // namespace GH113324

>From 3ad3b6c5f35730be32f4f6ba2dc8d19f53be0442 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 8 Nov 2024 16:53:39 +0200
Subject: [PATCH 2/6] update comments

---
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 200519c71c57ab..0bbab95001ad8e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4694,6 +4694,13 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  // FIXME: We don't track member specialization info for non-defining
+  // friend declarations, so we will not be able to later find the function
+  // pattern. As a workaround, don't instantiate the default argument in this
+  // case. This is correct per wording and only an error recovery issue, as per
+  // [dcl.fct.default]p4:
+  //   if a friend declaration D specifies a default argument expression,
+  //   that declaration shall be a definition.
   if (FD->getFriendObjectKind() != Decl::FOK_None &&
   !FD->getTemplateInstantiationPattern())
 return true;

>From 09215dea0212368ef54956d8464788cc4b88cc02 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 21 Nov 2024 16:56:11 +0200
Subject: [PATCH 3/6] move cases that cause code generation failures to the
 appropriate folder

---
 clang/test/CXX/temp/temp.res/p4.cpp | 23

[clang] [Static analysis] Encodes a filename before inserting it into a URL. (PR #120123)

2024-12-17 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-msan` running on `sanitizer-buildbot9` while 
building `clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/94/builds/2949


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 85520 tests, 72 workers --
Testing: 
FAIL: Clang :: Analysis/scan-build/cxx-name.test (1228 of 85520)
 TEST 'Clang :: Analysis/scan-build/cxx-name.test' FAILED 

Exit Code: 2

Command Output (stdout):
--
# RUN: at line 3
'/usr/bin/perl' 
'/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/tools/scan-build/bin/scan-build'
 
--use-analyzer=/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang-20
  sh -c 'echo "CLANG_CXX=/$(basename "$CLANG_CXX")/"' | 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/test/Analysis/scan-build/cxx-name.test
# executed command: /usr/bin/perl 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/tools/scan-build/bin/scan-build
 
--use-analyzer=/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang-20
 sh -c 'echo "CLANG_CXX=/$(basename "$CLANG_CXX")/"'
# .---command stderr
# | Can't locate URI/Escape.pm in @INC (you may need to install the URI::Escape 
module) (@INC entries checked: /etc/perl 
/usr/local/lib/aarch64-linux-gnu/perl/5.38.2 /usr/local/share/perl/5.38.2 
/usr/lib/aarch64-linux-gnu/perl5/5.38 /usr/share/perl5 
/usr/lib/aarch64-linux-gnu/perl-base /usr/lib/aarch64-linux-gnu/perl/5.38 
/usr/share/perl/5.38 /usr/local/lib/site_perl) at 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/tools/scan-build/bin/scan-build
 line 26.
# | BEGIN failed--compilation aborted at 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/tools/scan-build/bin/scan-build
 line 26.
# `-
# error: command failed with exit status: 2
# executed command: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/test/Analysis/scan-build/cxx-name.test
# .---command stderr
# | FileCheck error: '' is empty.
# | FileCheck command line:  
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build_msan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/test/Analysis/scan-build/cxx-name.test
# `-
# error: command failed with exit status: 2

--


Testing: 
FAIL: Clang :: Analysis/scan-build/help.test (1229 of 85520)
 TEST 'Clang :: Analysis/scan-build/help.test' FAILED 

Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
'/usr/bin/perl' 
'/home/b/saniti

[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-12-17 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`cross-project-tests-sie-ubuntu` running on `doug-worker-1a` while building 
`clang,llvm` at step 2 "checkout".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/181/builds/10481


Here is the relevant piece of the build log for the reference

```
Step 2 (checkout) failure: update (failure)
git version 2.25.1
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': HTTP/2 
stream 0 was not closed cleanly: CANCEL (err 8)
fatal: the remote end hung up upon initial contact

```



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


[libunwind] [Libunwind] Try to fix msan failures (PR #120013)

2024-12-17 Thread Dmitry Chestnykh via cfe-commits

https://github.com/chestnykh updated 
https://github.com/llvm/llvm-project/pull/120013

>From 9422b097ff80f5501dcf4fa3d41176b9439ab3f6 Mon Sep 17 00:00:00 2001
From: Dmitry Chestnykh 
Date: Sun, 15 Dec 2024 21:18:23 +0300
Subject: [PATCH 1/4] [Libunwind] Don't XFAIL tests with msan

---
 libunwind/test/forceunwind.pass.cpp | 3 ---
 libunwind/test/libunwind_01.pass.cpp| 3 ---
 libunwind/test/libunwind_02.pass.cpp| 3 ---
 libunwind/test/signal_frame.pass.cpp| 3 ---
 libunwind/test/signal_unwind.pass.cpp   | 3 ---
 libunwind/test/unw_resume.pass.cpp  | 3 ---
 libunwind/test/unwind_leaffunction.pass.cpp | 3 ---
 7 files changed, 21 deletions(-)

diff --git a/libunwind/test/forceunwind.pass.cpp 
b/libunwind/test/forceunwind.pass.cpp
index 344034e1ea5f5e..e8333eb74a979a 100644
--- a/libunwind/test/forceunwind.pass.cpp
+++ b/libunwind/test/forceunwind.pass.cpp
@@ -9,9 +9,6 @@
 
 // REQUIRES: linux
 
-// TODO: Figure out why this fails with Memory Sanitizer.
-// XFAIL: msan
-
 // Basic test for _Unwind_ForcedUnwind.
 // See libcxxabi/test/forced_unwind* tests too.
 
diff --git a/libunwind/test/libunwind_01.pass.cpp 
b/libunwind/test/libunwind_01.pass.cpp
index 838df6b5897204..82fb66d665c259 100644
--- a/libunwind/test/libunwind_01.pass.cpp
+++ b/libunwind/test/libunwind_01.pass.cpp
@@ -10,9 +10,6 @@
 // TODO: Investigate this failure on x86_64 macOS back deployment
 // XFAIL: stdlib=system && 
target=x86_64-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0|12.0}}
 
-// TODO: Figure out why this fails with Memory Sanitizer.
-// XFAIL: msan
-
 #include 
 #include 
 #include 
diff --git a/libunwind/test/libunwind_02.pass.cpp 
b/libunwind/test/libunwind_02.pass.cpp
index 9fd8e5d7159c96..5f2d2b43bddc1c 100644
--- a/libunwind/test/libunwind_02.pass.cpp
+++ b/libunwind/test/libunwind_02.pass.cpp
@@ -7,9 +7,6 @@
 //
 
//===--===//
 
-// TODO: Figure out why this fails with Memory Sanitizer.
-// XFAIL: msan
-
 // This test fails on older llvm, when built with picolibc.
 // XFAIL: clang-16 && LIBCXX-PICOLIBC-FIXME
 
diff --git a/libunwind/test/signal_frame.pass.cpp 
b/libunwind/test/signal_frame.pass.cpp
index 004029cfe1e90b..67b862c98fbfc7 100644
--- a/libunwind/test/signal_frame.pass.cpp
+++ b/libunwind/test/signal_frame.pass.cpp
@@ -12,9 +12,6 @@
 // TODO: Investigate this failure on Apple
 // XFAIL: target={{.+}}-apple-{{.+}}
 
-// TODO: Figure out why this fails with Memory Sanitizer.
-// XFAIL: msan
-
 // UNSUPPORTED: libunwind-arm-ehabi
 
 // The AIX assembler does not support CFI directives, which
diff --git a/libunwind/test/signal_unwind.pass.cpp 
b/libunwind/test/signal_unwind.pass.cpp
index 1c1566415a4d4b..8ba0c8b2859ac4 100644
--- a/libunwind/test/signal_unwind.pass.cpp
+++ b/libunwind/test/signal_unwind.pass.cpp
@@ -10,9 +10,6 @@
 // Ensure that the unwinder can cope with the signal handler.
 // REQUIRES: target={{(aarch64|riscv64|s390x|x86_64)-.+linux.*}}
 
-// TODO: Figure out why this fails with Memory Sanitizer.
-// XFAIL: msan
-
 // Note: this test fails on musl because:
 //
 //  (a) musl disables emission of unwind information for its build, and
diff --git a/libunwind/test/unw_resume.pass.cpp 
b/libunwind/test/unw_resume.pass.cpp
index 2b7470b5cad0eb..ca6068a828e0ac 100644
--- a/libunwind/test/unw_resume.pass.cpp
+++ b/libunwind/test/unw_resume.pass.cpp
@@ -10,9 +10,6 @@
 // Ensure that unw_resume() resumes execution at the stack frame identified by
 // cursor.
 
-// TODO: Figure out why this fails with Memory Sanitizer.
-// XFAIL: msan
-
 #include 
 
 __attribute__((noinline)) void test_unw_resume() {
diff --git a/libunwind/test/unwind_leaffunction.pass.cpp 
b/libunwind/test/unwind_leaffunction.pass.cpp
index 98de7dc43260c2..4259406cc493d1 100644
--- a/libunwind/test/unwind_leaffunction.pass.cpp
+++ b/libunwind/test/unwind_leaffunction.pass.cpp
@@ -10,9 +10,6 @@
 // Ensure that leaf function can be unwund.
 // REQUIRES: target={{(aarch64|riscv64|s390x|x86_64)-.+linux.*}}
 
-// TODO: Figure out why this fails with Memory Sanitizer.
-// XFAIL: msan
-
 // Note: this test fails on musl because:
 //
 //  (a) musl disables emission of unwind information for its build, and

>From 0a4a0e12d7b4daf72dd4461962fbf6cc5114347f Mon Sep 17 00:00:00 2001
From: Dmitry Chestnykh 
Date: Mon, 16 Dec 2024 21:40:46 +0300
Subject: [PATCH 2/4] Try to remove -lunwind from link flags

The possible reason why tests fail is that
MAYBE there are another libunwind on the testing host
which is loaded(?) instead of libunwind from llvm.
clang passes 'right' libunwind (-lunwind) to the linker
if -unwindlib=libunwind is passed to the driver
---
 libunwind/test/configs/llvm-libunwind-shared.cfg.in | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libunwind/test/configs/llvm-libunwind-shared.cfg.in 
b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
index f3e40928b525da..256f8111948bd3 100644
--

[libunwind] [Libunwind] Try to fix msan failures (PR #120013)

2024-12-17 Thread Dmitry Chestnykh via cfe-commits

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


[libunwind] [Libunwind] Try to fix msan failures (PR #120013)

2024-12-17 Thread Alexander Richardson via cfe-commits

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


[libunwind] [Libunwind] Try to fix msan failures (PR #120013)

2024-12-17 Thread Alexander Richardson via cfe-commits


@@ -133,6 +133,10 @@ _LIBUNWIND_EXPORT _Unwind_Reason_Code
 _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {
   unw_cursor_t cursor;
   unw_context_t uc;
+#if __has_feature(memory_sanitizer)
+  __builtin_memset(&cursor, 0, sizeof(cursor));

arichardson wrote:

I'm not keen on working around the missing msan annotations on every call. This 
seems fragile.

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


[libunwind] [Libunwind] Try to fix msan failures (PR #120013)

2024-12-17 Thread Alexander Richardson via cfe-commits

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

We shouldn't need to initialize these structures to silence sanitizer errors. I 
had a draft pr last year to fix this properly but forgot about it since other 
things came up: https://github.com/llvm/llvm-project/pull/67860

I'd prefer something like that. Alternatively I can update my change once I'm 
back in the office in January.

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


[libunwind] [Libunwind] Try to fix msan failures (PR #120013)

2024-12-17 Thread Dmitry Chestnykh via cfe-commits

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


[libunwind] [Libunwind] Try to fix msan failures (PR #120013)

2024-12-17 Thread Dmitry Chestnykh via cfe-commits


@@ -133,6 +133,10 @@ _LIBUNWIND_EXPORT _Unwind_Reason_Code
 _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {
   unw_cursor_t cursor;
   unw_context_t uc;
+#if __has_feature(memory_sanitizer)
+  __builtin_memset(&cursor, 0, sizeof(cursor));

chestnykh wrote:

It's better to create a bug on msan?

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


[clang] [clang-format] extend clang-format directive with options to prevent formatting for one line (PR #118566)

2024-12-17 Thread Paul Hoad via cfe-commits

phoad107185 wrote:

> > I struggle with changes that encourage people to not be fully 
> > clang-formatted, I would prefer to ask why we need this feature, can we 
> > have some examples of where this would be used?
> 
> This makes it so only one line isn't formatted instead of the current 
> solution which is 2 lines unformatted. Additionally, if you start writing 
> code in between the unformatted region you inherit the unformatted scope. 
> Being able to disable the formatter for only a single line means the 
> formatter will be disabled for the shortest amount of code possible.

While I understand the reason I would ask again, what exactly are you disabling 
on a single line and why? Does the clang-format team really want to maintain 
more reasons to "not" format code? I would rather put the effort into 
understanding why you are having to use the // clang-format off in the first 
place

I work on a project (in my day job) with millions of lines of code, EVERY file 
is 100% clang-formatted, without any // clang-format off statements. When I hit 
a problem I report it against clang-format or even submit a fix. 

So again to reiterate my question why do we need this feature? what is the 
reason and why doesn't the current capabilities support what you need.


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


[clang] [compiler-rt] [flang] [libc] [llvm] [polly] [cmake] Drop `AddFileDependencies` and `CMakeParseArguments` (PR #120002)

2024-12-17 Thread via cfe-commits

https://github.com/paperchalice closed 
https://github.com/llvm/llvm-project/pull/120002
___
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 readability-string-view-substr check (PR #120055)

2024-12-17 Thread Helmut Januschka via cfe-commits

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


[clang] 449af81 - [Clang] Fix crash for incompatible types in inline assembly (#119098)

2024-12-17 Thread via cfe-commits

Author: AdUhTkJm
Date: 2024-12-17T18:44:25+07:00
New Revision: 449af81f922cdb7a1f24b4c1e989f30848e1d762

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

LOG: [Clang] Fix crash for incompatible types in inline assembly (#119098)

Fixed issue #118892.

Added: 


Modified: 
clang/lib/Sema/SemaStmtAsm.cpp
clang/test/Sema/asm.c

Removed: 




diff  --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..a0b203fbdfec21 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -664,11 +664,16 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
   SmallerValueMentioned |= OutSize < InSize;
 }
 
+// If the input is an integer register while the output is floating point,
+// or vice-versa, there is no way they can work together.
+bool FPTiedToInt = (InputDomain == AD_FP) ^ (OutputDomain == AD_FP);
+
 // If the smaller value wasn't mentioned in the asm string, and if the
 // output was a register, just extend the shorter one to the size of the
 // larger one.
-if (!SmallerValueMentioned && InputDomain != AD_Other &&
+if (!SmallerValueMentioned && !FPTiedToInt && InputDomain != AD_Other &&
 OutputConstraintInfos[TiedTo].allowsRegister()) {
+
   // FIXME: GCC supports the OutSize to be 128 at maximum. Currently 
codegen
   // crash when the size larger than the register size. So we limit it 
here.
   if (OutTy->isStructureType() &&

diff  --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c
index a9cff5947ef5d0..a666b45b3150ca 100644
--- a/clang/test/Sema/asm.c
+++ b/clang/test/Sema/asm.c
@@ -365,3 +365,24 @@ void test19(long long x)
   // FIXME: This case should be supported by codegen, but it fails now.
   asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: 
input with type 'st_size128' (aka 'struct _st_size128') matching output with 
type 'long long'}}
 }
+
+typedef int int2 __attribute__((ext_vector_type(2)));
+
+// GH118892
+void test20(char x) {
+  double d;
+  float f;
+
+  asm ("fabs" : "=t" (d): "0" (x)); // expected-error {{unsupported inline 
asm: input with type 'char' matching output with type 'double'}}
+  asm ("fabs" : "=t" (x): "0" (d)); // expected-error {{unsupported inline 
asm: input with type 'double' matching output with type 'char'}}
+  asm ("fabs" : "=t" (f): "0" (d)); // no-error
+  asm ("fabs" : "=t" (d): "0" (f)); // no-error
+
+  st_size64 a;
+  asm ("fabs" : "=t" (d): "0" (a)); // expected-error {{unsupported inline 
asm: input with type 'st_size64' (aka 'struct _st_size64') matching output with 
type 'double'}}
+  asm ("fabs" : "=t" (a): "0" (d)); // expected-error {{unsupported inline 
asm: input with type 'double' matching output with type 'st_size64' (aka 
'struct _st_size64')}}
+
+  int2 v;
+  asm ("fabs" : "=t" (d): "0" (v)); // expected-error {{unsupported inline 
asm: input with type 'int2' (vector of 2 'int' values) matching output with 
type 'double'}}
+  asm ("fabs" : "=t" (v): "0" (d)); // expected-error {{unsupported inline 
asm: input with type 'double' matching output with type 'int2' (vector of 2 
'int' values)}}
+}



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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-17 Thread Matt Arsenault via cfe-commits

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


[clang] [analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) (PR #116462)

2024-12-17 Thread Vinay Deshmukh via cfe-commits

vinay-deshmukh wrote:

> I was thinking about the case, and I think it's okay to have state-splits in 
> the subexpressions coming from an assume expression - given that the assume 
> expression has no side effects. This way we should have 2 paths after the 
> assume expression (but still before the first if statement).
> 
> 1. where `a > 10` is true
> 2. where `a > 10` is false, aka. `a <= 10`.
> 
> This is I think the current behavior of your proposed implementation. Could 
> you demonstrate it in tests?
> 
> Something like this should prove it:
> 
> ```c++
> int ternary_in_assume(int a, int b) {
>   [[assume(a > 10 ? b == 4 : b == 10)]];
>   clang_analyzer_value(a); // we should have 2 dumps here.
>   clang_analyzer_dump(b); // This should be either 4 or 10.
>   if (a > 20) {
> clang_analyzer_dump(b + 100); // expecting 104
> return;
>   }
>   if (a > 10) {
> clang_analyzer_dump(b + 200); // expecting 204
> return;
>   }
>   clang_analyzer_dump(b + 300); // expecting 310
> }
> ```

Summary for the latest commit: 

In the current implementation, when we run `clang_analyzer_dump`,  it prints 
the actual constrained values (i.e. `b == 4` or `b == 10`),  but it will 
**also** print `reg_$2`. As far as I can tell, this is exactly how it 
works for the `__builtin_assume` as well, except the difference is that when 
`core.BuiltinChecker` is run, it will eliminate the `ExplodedNode`(s) where the 
expression is false / "unconstrained".

To pass the tests for now, I've added a `FIXME` that also "expects" the 
symbolic print as follows so `lit` tests "pass" :


```c++
clang_analyzer_dump(b + 100); // expected-warning{{104}} FIXME: 
expected-warning{{(reg_$2) + 100}}
```

As far as I know, to eliminate the warning emitted corresponding to the FIXME 
comment, we need to implement a new Checker for attributes; we can do this in a 
second PR to avoid scope creep for this issue/PR.

P.S. I needed to add a check to `ExprEngine::VisitGuardedExpr` to "continue" if 
the ProgramPoint is a `StmtPoint`, because without it, the `getAs` 
runs into undefined behavior. Added an `assert` for that as well to be careful 
in the future.

https://github.com/llvm/llvm-project/blob/eabbef2be6a4f956171a21632d8cf07b4a48e162/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp#L799-L810

now working on getting the tests to pass locally, might need some more minor 
fixes.

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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-17 Thread Matt Arsenault via cfe-commits

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


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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-17 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] [flang] [flang] Support -f[no-]realloc-lhs. (PR #120165)

2024-12-17 Thread Kiran Chandramohan via cfe-commits

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

LG. Thanks.

Just a comment, no action required. I see some hits for realloc-lhs in the 
gfortran testsuite. Will some of these tests start behaving differently?

```
CMakeLists.txt:  -fno-realloc-lhs
CMakeLists.txt:  -Wrealloc-lhs
CMakeLists.txt:  -Wrealloc-lhs-all
regression/inline_matmul_13.f90:! { dg-options "-ffrontend-optimize 
-fdump-tree-original -Wrealloc-lhs" }
regression/tests.cmake:compile;realloc_on_assign_14.f90;;-Wrealloc-lhs-all 
-Wrealloc-lhs;;
regression/tests.cmake:compile;realloc_on_assign_21.f90;xfail;-fno-realloc-lhs;;
regression/tests.cmake:run;cshift_bounds_2.f90;xfail;-fbounds-check 
-fno-realloc-lhs;;
regression/tests.cmake:run;inline_matmul_1.f90;;-ffrontend-optimize 
-fdump-tree-optimized -Wrealloc-lhs;;
regression/tests.cmake:run;inline_matmul_13.f90;;-ffrontend-optimize 
-fdump-tree-original -Wrealloc-lhs;;
regression/tests.cmake:run;inline_matmul_16.f90;;-ffrontend-optimize 
-fdump-tree-optimized -Wrealloc-lhs -finline-matmul-limit=1000 -O;;
regression/tests.cmake:run;inline_matmul_20.f90;;-fno-realloc-lhs 
-ffrontend-optimize;;
regression/tests.cmake:run;matmul_bounds_10.f90;xfail;-fno-backtrace 
-fbounds-check -fno-realloc-lhs;;
regression/tests.cmake:run;matmul_bounds_14.f 
blas_gemm_routines.f;xfail;-fno-realloc-lhs -fdump-tree-optimized 
-fcheck=bounds -fblas-matmul-limit=1 -O -fexternal-blas;;
regression/tests.cmake:run;matmul_bounds_2.f90;xfail;-fbounds-check 
-fno-realloc-lhs;;
regression/tests.cmake:run;matmul_bounds_3.f90;xfail;-fbounds-check 
-fno-realloc-lhs;;
regression/tests.cmake:run;matmul_bounds_4.f90;xfail;-fbounds-check 
-fno-realloc-lhs;;
regression/tests.cmake:run;matmul_bounds_5.f90;xfail;-fbounds-check 
-fno-realloc-lhs;;
regression/tests.cmake:run;matmul_bounds_8.f90;xfail;-fno-backtrace 
-fbounds-check -fno-realloc-lhs;;
regression/tests.cmake:run;transpose_2.f90;xfail;-fbounds-check 
-fno-realloc-lhs;;
regression/tests.cmake:run;unpack_bounds_1.f90;xfail;-fbounds-check 
-fno-realloc-lhs;;
regression/matmul_bounds_3.f90:! { dg-options "-fbounds-check -fno-realloc-lhs" 
}
regression/realloc_on_assign_14.f90:! { dg-options "-Wrealloc-lhs-all 
-Wrealloc-lhs" }
regression/realloc_on_assign_21.f90:! { dg-options "-fno-realloc-lhs" }
regression/realloc_on_assign_21.f90:var = t() ! { dg-error "Assignment to an 
allocatable polymorphic variable at .1. requires '-frealloc-lhs'" }
regression/matmul_bounds_5.f90:! { dg-options "-fbounds-check -fno-realloc-lhs" 
}
regression/matmul_bounds_14.f:C { dg-options "-fno-realloc-lhs 
-fdump-tree-optimized -fcheck=bounds -fblas-matmul-limit=1 -O -fexternal-blas" }
regression/matmul_bounds_10.f90:! { dg-options "-fno-backtrace -fbounds-check 
-fno-realloc-lhs" }
regression/transpose_2.f90:! { dg-options "-fbounds-check -fno-realloc-lhs" }
regression/matmul_bounds_2.f90:! { dg-options "-fbounds-check -fno-realloc-lhs" 
}
regression/matmul_bounds_8.f90:! { dg-options "-fno-backtrace -fbounds-check 
-fno-realloc-lhs" }
regression/cshift_bounds_2.f90:! { dg-options "-fbounds-check -fno-realloc-lhs" 
}
regression/DisabledFiles.cmake:  # Require -fno-realloc-lhs or similar.
regression/unpack_bounds_1.f90:! { dg-options "-fbounds-check -fno-realloc-lhs" 
}
regression/inline_matmul_1.f90:! { dg-options "-ffrontend-optimize 
-fdump-tree-optimized -Wrealloc-lhs" }
regression/matmul_bounds_4.f90:! { dg-options "-fbounds-check -fno-realloc-lhs" 
}
regression/inline_matmul_20.f90:! { dg-additional-options "-fno-realloc-lhs 
-ffrontend-optimize" }
regression/inline_matmul_16.f90:! { dg-options "-ffrontend-optimize 
-fdump-tree-optimized -Wrealloc-lhs -finline-matmul-limit=1000 -O" }
```

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


[clang] [clang] Add sincos builtin using `llvm.sincos` intrinsic (PR #114086)

2024-12-17 Thread Matt Arsenault via cfe-commits


@@ -3232,6 +3264,22 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
+case Builtin::BI__builtin_sincos:
+case Builtin::BI__builtin_sincosf:
+case Builtin::BI__builtin_sincosl:
+  // Only use the llvm.sincos.* builtin on AArch64 with optimizations.
+  // Currently, getting codegen that is no worse than the direct call
+  // requires using AA during codegen. This is not done at optlevel=none,
+  // and not all targets support this (AArch64 is one of the few known to).
+  if (!getTarget().getTriple().isAArch64() ||
+  CGM.getCodeGenOpts().OptimizationLevel == 0)
+break;

arsenm wrote:

```suggestion
```

No, unconditional codegen 

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Nick Sarnie via cfe-commits


@@ -0,0 +1,38 @@
+//==- SPIRVOpenMP.cpp - SPIR-V OpenMP Tool Implementations *- 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
+//
+//====//
+#include "SPIRVOpenMP.h"
+#include "CommonArgs.h"
+
+using namespace clang::driver;
+using namespace clang::driver::toolchains;
+using namespace clang::driver::tools;
+using namespace llvm::opt;
+
+namespace clang::driver::toolchains {
+SPIRVOpenMPToolChain::SPIRVOpenMPToolChain(const Driver &D,

sarnex wrote:

Right now the only thing we are doing here is pulling in the OpenMP device RTL, 
but in the future I expect the final version of Intel's OpenMP support to have 
somewhat complicated logic here pulling in various things, so I think it makes 
sense to have a new toolchain for now to not bog down the generic SPIR-V 
toolchain.

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Nick Sarnie via cfe-commits


@@ -735,11 +736,15 @@ wrapDeviceImages(ArrayRef> 
Buffers,
 }
 
 Expected>>
-bundleOpenMP(ArrayRef Images) {
+bundleOpenMP(SmallVectorImpl &Images) {

sarnex wrote:

It's mutable because we modify it inside `bundleOpenMP` if the vendor is 
`Intel`, where we call `containerizeOpenMPSPIRVImage` to put the device image 
into an ELF (which we can't do using clang because there's no SPIR-V linker). I 
agree it's not ideal to have to modify the image here, if you have a better 
spot to do that ELF packaging, let me know. Thanks

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


[clang] [compiler-rt] [libcxx] [libcxxabi] [llvm] [libc++] Replace LIBCXX_ENABLE_STATIC_ABI_LIBRARY & friends by a new LIBCXX_CXX_ABI choice (PR #112978)

2024-12-17 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/112978

>From 7b8f1538b452d6c16874d0f076baa2d54abb66b0 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Fri, 13 May 2022 09:26:01 -0400
Subject: [PATCH 1/3] [libc++] Replace LIBCXX_ENABLE_STATIC_ABI_LIBRARY &
 friends by a new LIBCXX_CXX_ABI choice

Instead of having complicated options like LIBCXX_ENABLE_STATIC_ABI_LIBRARY
and LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY, introduce a more general
mechanism to select the ABI library used by libc++. The new mechanism allows
specifying the ABI library for the static libc++ and the shared libc++
separately, and allows selecting a "merged" flavor of libc++ for both
the in-tree libc++abi and any external static ABI library.

As an example, one can now specify arbitrary combinations like
   -DLIBCXX_ABILIB_FOR_SHARED="shared-libcxxabi"
   -DLIBCXX_ABILIB_FOR_STATIC="merged-libcxxabi"

which would have been impossible or very brittle in the past. In theory,
one can even select an entirely different ABI library for the static and
the shared libc++ (e.g. libc++abi vs libsupc++), although supporting that
is not a primary goal of this patch but merely a result of the general
mechanism.

Closes #77655
Fixes #57759

Differential Revision: https://reviews.llvm.org/D125683
---
 clang/cmake/caches/Android.cmake  |   4 +-
 clang/cmake/caches/CrossWinToARMLinux.cmake   |  12 +-
 clang/cmake/caches/Fuchsia-stage2.cmake   |   8 +-
 clang/cmake/caches/Fuchsia.cmake  |   4 +-
 compiler-rt/cmake/Modules/AddCompilerRT.cmake |   3 +-
 libcxx/CMakeLists.txt |  68 +++--
 libcxx/cmake/Modules/HandleLibCXXABI.cmake| 279 +-
 libcxx/cmake/caches/AMDGPU.cmake  |   4 +-
 libcxx/cmake/caches/AndroidNDK.cmake  |   2 +-
 libcxx/cmake/caches/Generic-merged.cmake  |   3 +-
 libcxx/cmake/caches/MinGW.cmake   |   4 +-
 libcxx/cmake/caches/NVPTX.cmake   |   4 +-
 libcxx/docs/ReleaseNotes/20.rst   |   6 +-
 libcxx/docs/VendorDocumentation.rst   |  24 +-
 libcxx/include/CMakeLists.txt |   2 +-
 libcxx/src/CMakeLists.txt |  19 +-
 libcxx/utils/ci/run-buildbot  |   4 -
 libcxxabi/src/CMakeLists.txt  |  15 +
 .../docs/HowToBuildWindowsItaniumPrograms.rst |  28 +-
 19 files changed, 252 insertions(+), 241 deletions(-)

diff --git a/clang/cmake/caches/Android.cmake b/clang/cmake/caches/Android.cmake
index d5ca6b50d4ada7..dbf66539591394 100644
--- a/clang/cmake/caches/Android.cmake
+++ b/clang/cmake/caches/Android.cmake
@@ -21,8 +21,8 @@ if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
   list(APPEND EXTRA_ARGS 
-DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=${LIBCXX_ENABLE_ABI_LINKER_SCRIPT})
 endif()
 
-if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
-  list(APPEND EXTRA_ARGS 
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
+if (LIBCXX_CXX_ABI)
+  list(APPEND EXTRA_ARGS -DLIBCXX_CXX_ABI=${LIBCXX_CXX_ABI})
 endif()
 
 if (LLVM_BUILD_EXTERNAL_COMPILER_RT)
diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index c47c4ac3bb73ec..411315a2d38b23 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -21,7 +21,7 @@
 #  cmake -G Ninja ^
 #   -DTOOLCHAIN_TARGET_TRIPLE=aarch64-unknown-linux-gnu ^
 #   -DTOOLCHAIN_TARGET_SYSROOTFS= ^
-#   -DTOOLCHAIN_SHARED_LIBS=OFF ^ 
+#   -DTOOLCHAIN_SHARED_LIBS=OFF ^
 #   -DCMAKE_INSTALL_PREFIX=../install ^
 #   -DCMAKE_CXX_FLAGS="-D__OPTIMIZE__" ^
 #   -DREMOTE_TEST_HOST="" ^
@@ -205,7 +205,7 @@ 
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CXX_LIBRARY
 # The compiler-rt tests disable the clang configuration files during the 
execution by setting CLANG_NO_DEFAULT_CONFIG=1
 # and drops out the --sysroot from there. Provide it explicity via the test 
flags here if target sysroot has been specified.
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS   
   "--stdlib=libc++ ${sysroot_flags}" CACHE STRING "")
-  
+
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT  
   ON CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED
   ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
 
@@ -218,10 +218,12 @@ 
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT 
   ON CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED   
   ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION 
   ${LIBCXX_ABI_VERSION} CACHE STRING "")
-set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI 
   "libcxxabi" CACHE STRING "")#!!!
+if (TOOLCHAIN_USE_STATIC_LIBS)
+  set(RUNTIMES_${TOOLCHAI

[clang] [clang] Add sincos builtin using `llvm.sincos` intrinsic (PR #114086)

2024-12-17 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue updated 
https://github.com/llvm/llvm-project/pull/114086

>From 5e6e49cf8bceed6d137ea67abe81a8a425d5aed8 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 9 Sep 2024 10:15:20 +
Subject: [PATCH 1/5] [clang] Add sincos builtin using `llvm.sincos` intrinsic

This registers `sincos[f|l]` as a clang builtin and updates GCBuiltin
to emit the `llvm.sincos.*` intrinsic when `-fno-math-errno` is set.
---
 clang/include/clang/Basic/Builtins.td| 13 +++
 clang/lib/CodeGen/CGBuiltin.cpp  | 43 
 clang/test/CodeGen/AArch64/sincos.c  | 33 ++
 clang/test/CodeGen/X86/math-builtins.c   | 35 +++
 clang/test/OpenMP/declare_simd_aarch64.c |  4 +--
 5 files changed, 126 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/AArch64/sincos.c

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 32a09e2ceb3857..d0e09e735c39d3 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -3568,6 +3568,19 @@ def Frexp : FPMathTemplate, LibBuiltin<"math.h"> {
   let AddBuiltinPrefixedAlias = 1;
 }
 
+def Sincos : FPMathTemplate, GNULibBuiltin<"math.h"> {
+  let Spellings = ["sincos"];
+  let Attributes = [NoThrow];
+  let Prototype = "void(T, T*, T*)";
+  let AddBuiltinPrefixedAlias = 1;
+}
+
+def SincosF16F128 : F16F128MathTemplate, Builtin {
+  let Spellings = ["__builtin_sincos"];
+  let Attributes = [FunctionWithBuiltinPrefix, NoThrow];
+  let Prototype = "void(T, T*, T*)";
+}
+
 def Ldexp : FPMathTemplate, LibBuiltin<"math.h"> {
   let Spellings = ["ldexp"];
   let Attributes = [NoThrow, ConstIgnoringErrnoAndExceptions];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 84048a4beac2c5..bdf797440d36a2 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -835,6 +835,38 @@ static Value *emitFrexpBuiltin(CodeGenFunction &CGF, const 
CallExpr *E,
   return CGF.Builder.CreateExtractValue(Call, 0);
 }
 
+static void emitSincosBuiltin(CodeGenFunction &CGF, const CallExpr *E,
+  llvm::Intrinsic::ID IntrinsicID) {
+  llvm::Value *Val = CGF.EmitScalarExpr(E->getArg(0));
+  llvm::Value *Dest0 = CGF.EmitScalarExpr(E->getArg(1));
+  llvm::Value *Dest1 = CGF.EmitScalarExpr(E->getArg(2));
+
+  llvm::Function *F = CGF.CGM.getIntrinsic(IntrinsicID, {Val->getType()});
+  llvm::Value *Call = CGF.Builder.CreateCall(F, Val);
+
+  llvm::Value *SinResult = CGF.Builder.CreateExtractValue(Call, 0);
+  llvm::Value *CosResult = CGF.Builder.CreateExtractValue(Call, 1);
+
+  QualType DestPtrType = E->getArg(1)->getType()->getPointeeType();
+  LValue SinLV = CGF.MakeNaturalAlignAddrLValue(Dest0, DestPtrType);
+  LValue CosLV = CGF.MakeNaturalAlignAddrLValue(Dest1, DestPtrType);
+
+  llvm::StoreInst *StoreSin =
+  CGF.Builder.CreateStore(SinResult, SinLV.getAddress());
+  llvm::StoreInst *StoreCos =
+  CGF.Builder.CreateStore(CosResult, CosLV.getAddress());
+
+  // Mark the two stores as non-aliasing with eachother. The order of stores
+  // emitted by this builtin is arbitrary, enforcing a particular order will
+  // prevent optimizations later on.
+  llvm::MDBuilder MDHelper(CGF.getLLVMContext());
+  MDNode *Domain = MDHelper.createAnonymousAliasScopeDomain();
+  MDNode *AliasScope = MDHelper.createAnonymousAliasScope(Domain);
+  MDNode *AliasScopeList = MDNode::get(Call->getContext(), AliasScope);
+  StoreSin->setMetadata(LLVMContext::MD_alias_scope, AliasScopeList);
+  StoreCos->setMetadata(LLVMContext::MD_noalias, AliasScopeList);
+}
+
 /// EmitFAbs - Emit a call to @llvm.fabs().
 static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
   Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
@@ -3232,6 +3264,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
+case Builtin::BI__builtin_sincos:
+case Builtin::BI__builtin_sincosf:
+case Builtin::BI__builtin_sincosl:
+case Builtin::BI__builtin_sincosf128:
+case Builtin::BI__builtin_sincosf16:
+  emitSincosBuiltin(*this, E, Intrinsic::sincos);
+  return RValue::get(nullptr);
+
 case Builtin::BIsqrt:
 case Builtin::BIsqrtf:
 case Builtin::BIsqrtl:
diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
new file mode 100644
index 00..240d921b2b7034
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm %s -o - | FileCheck 
--check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | 
FileCheck --check-prefix=MATH-

[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Joseph Huber via cfe-commits


@@ -735,11 +736,15 @@ wrapDeviceImages(ArrayRef> 
Buffers,
 }
 
 Expected>>
-bundleOpenMP(ArrayRef Images) {
+bundleOpenMP(SmallVectorImpl &Images) {

jhuber6 wrote:

But this function's job is to return a new list of binary files after 
serializing the input, can't it just be put in the output?

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Nick Sarnie via cfe-commits


@@ -2829,10 +2829,13 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
 LibraryPaths.emplace_back(LibPath);
 
   OptSpecifier LibomptargetBCPathOpt =
-  Triple.isAMDGCN() ? options::OPT_libomptarget_amdgpu_bc_path_EQ
-: options::OPT_libomptarget_nvptx_bc_path_EQ;
+  Triple.isAMDGCN()  ? options::OPT_libomptarget_amdgpu_bc_path_EQ

sarnex wrote:

Yes, we're linking the DeviceRTL using `mlink-builtin-bitcode` today, but we 
definitely want to use LTO in the future, both for OpenMP and SYCL.

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Nick Sarnie via cfe-commits


@@ -4256,6 +4256,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, 
ArgList &Args,
 
   if (TT.getArch() == llvm::Triple::UnknownArch ||
   !(TT.getArch() == llvm::Triple::aarch64 || TT.isPPC() ||
+TT.getArch() == llvm::Triple::spirv64 ||

sarnex wrote:

Right now it's at least throwing an error if the triple doesn't match the list, 
so there might be some case where removing the error will break something, so 
I'd prefer to not introduce a bug in a possibly untested area.

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


[clang] c135f6f - [TySan] Add initial Type Sanitizer support to Clang) (#76260)

2024-12-17 Thread via cfe-commits

Author: Florian Hahn
Date: 2024-12-17T15:13:42Z
New Revision: c135f6ffe2542bdde5a2a3e1d6515a6fc7031967

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

LOG: [TySan] Add initial Type Sanitizer support to Clang) (#76260)

This patch introduces the Clang components of type sanitizer: a
sanitizer for type-based aliasing violations.

It is based on Hal Finkel's https://reviews.llvm.org/D32198.

The Clang changes are mostly formulaic, the one specific change being
that when the TBAA sanitizer is enabled, TBAA is always generated, even
at -O0.

It goes together with the corresponding LLVM changes
(https://github.com/llvm/llvm-project/pull/76259) and compiler-rt
changes (https://github.com/llvm/llvm-project/pull/76261)

PR: https://github.com/llvm/llvm-project/pull/76260

Added: 
clang/test/CodeGen/sanitize-type-attr.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Features.def
clang/include/clang/Basic/Sanitizers.def
clang/include/clang/Driver/SanitizerArgs.h
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenTBAA.cpp
clang/lib/CodeGen/SanitizerMetadata.cpp
clang/lib/Driver/SanitizerArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/sanitizer-ld.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 596f3b5142d663..6129cb2d4bd058 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1176,6 +1176,10 @@ Sanitizers
   `_. See that link
   for examples.
 
+- Introduced an experimental Type Sanitizer, activated by using the
+  ``-fsanitize=type`` flag. This sanitizer detects violations of C/C++ 
type-based
+  aliasing rules.
+
 Python Binding Changes
 --
 - Fixed an issue that led to crashes when calling 
``Type.get_exception_specification_kind``.

diff  --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 15c59c6bcdf29c..c82b6d9b5f6c10 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -102,6 +102,7 @@ FEATURE(numerical_stability_sanitizer, 
LangOpts.Sanitize.has(SanitizerKind::Nume
 FEATURE(memory_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Memory |
SanitizerKind::KernelMemory))
+FEATURE(type_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Type))
 FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
 FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
 FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))

diff  --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index 9223f62b3639a7..f234488eaa80cf 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -73,6 +73,9 @@ SANITIZER("fuzzer", Fuzzer)
 // libFuzzer-required instrumentation, no linking.
 SANITIZER("fuzzer-no-link", FuzzerNoLink)
 
+// TypeSanitizer
+SANITIZER("type", Type)
+
 // ThreadSanitizer
 SANITIZER("thread", Thread)
 

diff  --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 0c6f3869549ef7..4f08ea2b260179 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -87,6 +87,7 @@ class SanitizerArgs {
   bool needsHwasanAliasesRt() const {
 return needsHwasanRt() && HwasanUseAliases;
   }
+  bool needsTysanRt() const { return Sanitizers.has(SanitizerKind::Type); }
   bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
   bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
   bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 2ef098172c01f5..f3b7c23d9c248d 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -77,6 +77,7 @@
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
+#include "llvm/Transforms/Instrumentation/TypeSanitizer.h"
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
@@ -735,6 +736,11 @@ static void addSanitizers(const Triple &TargetTriple,
   MPM.addPass(createModuleToFunctionPassAdap

[clang] [compiler-rt] [llvm] [TySan] A Type Sanitizer (Runtime Library) (PR #76261)

2024-12-17 Thread Florian Hahn via cfe-commits

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


[clang] [llvm] [TySan] A Type Sanitizer (Clang) (PR #76260)

2024-12-17 Thread Florian Hahn via cfe-commits

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Nick Sarnie via cfe-commits


@@ -28,8 +28,11 @@ void SPIRV::constructTranslateCommand(Compilation &C, const 
Tool &T,
 
   if (Input.getType() == types::TY_PP_Asm)
 CmdArgs.push_back("-to-binary");
+
+  // The text output from spirv-dis is not in the format expected
+  // by llvm-spirv, so use the text output from llvm-spirv.
   if (Output.getType() == types::TY_PP_Asm)
-CmdArgs.push_back("--spirv-tools-dis");
+CmdArgs.push_back("--spirv-text");

sarnex wrote:

Sure, will drop this, thanks.

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Nick Sarnie via cfe-commits

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Joseph Huber via cfe-commits


@@ -2829,10 +2829,13 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
 LibraryPaths.emplace_back(LibPath);
 
   OptSpecifier LibomptargetBCPathOpt =
-  Triple.isAMDGCN() ? options::OPT_libomptarget_amdgpu_bc_path_EQ
-: options::OPT_libomptarget_nvptx_bc_path_EQ;
+  Triple.isAMDGCN()  ? options::OPT_libomptarget_amdgpu_bc_path_EQ

jhuber6 wrote:

Is there a patch for the DeviceRTL build? I've been meaning to gut a lot of 
that starting with https://github.com/llvm/llvm-project/pull/119091 and soon 
removing the whole bundling thing so it's more like `libc.a`. ideally we'd have 
`lib/spirv64-intel-unknown/libomp.a` and the driver just passes 
`-Xoffload-linker -lomp`.

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2024-12-17 Thread via cfe-commits

b-sumner wrote:

@JonChesterfield I think I agree with you.  And OpenCL source should not be 
calling builtins to begin with since they're not officially part of the OpenCL 
language.

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2024-12-17 Thread via cfe-commits


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

b-sumner wrote:

> > less friction to just leave it there.
> 
> This is how we just end up with an ever-growing pile of garbage nobody 
> understands. Just rip it out.

We'd better make sure we're not breaking OpenCL conformance before we do any 
ripping.

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2024-12-17 Thread via cfe-commits

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


[clang] [clang] Fix dangling false positives for conditional operators. (PR #120233)

2024-12-17 Thread Haojian Wu via cfe-commits


@@ -582,6 +582,15 @@ static void visitFunctionCallArguments(IndirectLocalPath 
&Path, Expr *Call,
 //   Temp().ptr; // Here ptr might not dangle.
 if (isa(Arg->IgnoreImpCasts()))
   return;
+// Avoid false positives when the object is constructed from a conditional
+// operator argument. A common case is:
+//   // 'ptr' might not be owned by the Owner object.
+//   std::string_view s = cond() ? Owner().ptr : sv;

hokein wrote:

> I am a bit confused to be honest. Are there any other contexts where 
> `Owner().ptr` is problematic? I'd expect our analysis to behave the same for 
> a subexpression like that regardless the context. So I am surprised we need 
> to insert special logic for the ternary operator.

Possibly, but I don’t know of any concrete examples (it’s hard to judge). We 
have another ad-hoc filter at the end, `IsGslPtrValueFromGslTempOwner`, which 
filters out cases where the GSL pointer doesn’t originate from a GSL owner. 
This works well for simple and common cases, but when combined with 
`lifetimebound`, the behavior becomes tricky. 

The current fix extends the `MemberExpr` logic (L583) to handle cases like 
`GSLPointer pointer(Owner().ptr);`, but it doesn’t yet address cases like 
`GSLPointer pointer(Cond ? Owner().ptr : GSLPointer());`. I think this fix is a 
reasonable extension to address the issue.


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


[clang] [clang] Add sincos builtin using `llvm.sincos` intrinsic (PR #114086)

2024-12-17 Thread Benjamin Maxwell via cfe-commits


@@ -3232,6 +3264,22 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
+case Builtin::BI__builtin_sincos:
+case Builtin::BI__builtin_sincosf:
+case Builtin::BI__builtin_sincosl:
+  // Only use the llvm.sincos.* builtin on AArch64 with optimizations.
+  // Currently, getting codegen that is no worse than the direct call
+  // requires using AA during codegen. This is not done at optlevel=none,
+  // and not all targets support this (AArch64 is one of the few known to).
+  if (!getTarget().getTriple().isAArch64() ||
+  CGM.getCodeGenOpts().OptimizationLevel == 0)
+break;

MacDue wrote:

Okay, I've removed this. Universally using AA would be nice, but I don't know 
if/when that would happen. 

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


[clang] [clang][dataflow] Add matchers for smart pointer accessors to be cached (PR #120102)

2024-12-17 Thread Jan Voung via cfe-commits

https://github.com/jvoung updated 
https://github.com/llvm/llvm-project/pull/120102

>From f9b8cbaed4c01c2051cdcde105d6a9bca1684388 Mon Sep 17 00:00:00 2001
From: Jan Voung 
Date: Mon, 16 Dec 2024 16:06:43 +
Subject: [PATCH 1/2] [clang][dataflow] Add matchers for smart pointer
 accessors to be cached

This is part 1 of caching for smart pointer accessors, building on top
of the CachedConstAccessorsLattice, which caches "normal" accessors.

Smart pointer accessors are a bit different in that they may:
- have aliases to access the same underlying data (but potentially
  returning slightly different types like `&` vs `*`). Within a
  "checked" sequence users may mix uses of the different aliases and the
  check should apply to any of the spellings.
- may have non-const overloads in addition to the const version, where
  the non-const doesn't actually modify the container

Part 2 will follow and add transfer functions utilities. It will also
add a user UncheckedOptionalAccessModel. We'd seen false positives when
nesting StatusOr> and optional>, etc. which this
can help address.
---
 .../SmartPointerAccessorCaching.h |  63 ++
 .../lib/Analysis/FlowSensitive/CMakeLists.txt |   1 +
 .../SmartPointerAccessorCaching.cpp   | 134 
 .../Analysis/FlowSensitive/CMakeLists.txt |   1 +
 .../SmartPointerAccessorCachingTest.cpp   | 194 ++
 5 files changed, 393 insertions(+)
 create mode 100644 
clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h
 create mode 100644 
clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
 create mode 100644 
clang/unittests/Analysis/FlowSensitive/SmartPointerAccessorCachingTest.cpp

diff --git 
a/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h 
b/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h
new file mode 100644
index 00..1adb63af4e724b
--- /dev/null
+++ b/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h
@@ -0,0 +1,63 @@
+//===-- SmartPointerAccessorCaching.h ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines utilities to help cache accessors for smart pointer
+// like objects.
+//
+// These should be combined with CachedConstAccessorsLattice.
+// Beyond basic const accessors, smart pointers may have the following two
+// additional issues:
+//
+// 1) There may be multiple accessors for the same underlying object, e.g.
+//`operator->`, `operator*`, and `get`. Users may use a mixture of these
+//accessors, so the cache should unify them.
+//
+// 2) There may be non-const overloads of accessors. They are still safe to
+//cache, as they don't modify the container object.
+//===--===//
+
+#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H
+#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H
+
+#include 
+
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+namespace clang::dataflow {
+
+/// Matchers:
+/// For now, these match on any class with an `operator*` or `operator->`
+/// where the return types have a similar shape as std::unique_ptr
+/// and std::optional.
+///
+/// - `*` returns a reference to a type `T`
+/// - `->` returns a pointer to `T`
+/// - `get` returns a pointer to `T`
+/// - `value` returns a reference `T`
+///
+/// (1) The `T` should all match across the accessors (ignoring qualifiers).
+///
+/// (2) The specific accessor used in a call isn't required to be const,
+/// but the class must have a const overload of each accessor.
+///
+/// For now, we don't have customization to ignore certain classes.
+/// For example, if writing a ClangTidy check for `std::optional`, these
+/// would also match `std::optional`. In order to have special handling
+/// for `std::optional`, we assume the (Matcher, TransferFunction) case
+/// with custom handling is ordered early so that these generic cases
+/// do not trigger.
+ast_matchers::internal::Matcher isSmartPointerLikeOperatorStar();
+ast_matchers::internal::Matcher isSmartPointerLikeOperatorArrow();
+ast_matchers::internal::Matcher isSmartPointerLikeValueMethodCall();
+ast_matchers::internal::Matcher isSmartPointerLikeGetMethodCall();
+
+} // namespace clang::dataflow
+
+#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H
diff --git a/clang/lib/Analysis/FlowSensitive/CMakeLists.txt 
b/clang/lib/Analysis/FlowSensitive/CMakeLists.txt
index 05cdaa7e27823d..0c30df8b4b194f 100644
--- a/clang/lib/Analysis/FlowSensitive/CMakeLists.txt
+++ b/clang/lib/Analysis/

[clang] [llvm] [TySan] A Type Sanitizer (Clang) (PR #76260)

2024-12-17 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime` running on `omp-vega20-0` while building 
`clang` at step 7 "Add check check-offload".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/30/builds/12442


Here is the relevant piece of the build log for the reference

```
Step 7 (Add check check-offload) failure: test (failure)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
sanitizer/kernel_crash_async.c' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
 -fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
-fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# note: command had no output on stdout or stderr
# RUN: at line 3
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# note: command had no output on stdout or stderr
# RUN: at line 4
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=CHECK
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
/home/ompworker/bbot/o

[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Nick Sarnie via cfe-commits


@@ -2829,10 +2829,13 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
 LibraryPaths.emplace_back(LibPath);
 
   OptSpecifier LibomptargetBCPathOpt =
-  Triple.isAMDGCN() ? options::OPT_libomptarget_amdgpu_bc_path_EQ
-: options::OPT_libomptarget_nvptx_bc_path_EQ;
+  Triple.isAMDGCN()  ? options::OPT_libomptarget_amdgpu_bc_path_EQ

sarnex wrote:

Not yet, we hit some issues in the front end generating OpenMP device code with 
the SPIR-V target, so we can't build it yet because it doesn't make it through 
the compiler. Any change should be with fine with us, we should be able to 
adapt to whatever infrastructure there is to build the DeviceRTL. thanks.

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2024-12-17 Thread via cfe-commits

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Nick Sarnie via cfe-commits


@@ -735,11 +736,15 @@ wrapDeviceImages(ArrayRef> 
Buffers,
 }
 
 Expected>>
-bundleOpenMP(ArrayRef Images) {
+bundleOpenMP(SmallVectorImpl &Images) {

sarnex wrote:

Somehow I convinced myself it might be more performant to do it this way, but 
I'm not so sure that's true, let me try to just modified the serialized input.

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Nick Sarnie via cfe-commits

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


[clang-tools-extra] [clang-tidy][NFC] swap cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions (PR #120245)

2024-12-17 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/120245

According to #116591.
> Coding guidelines should "cherry-pick" (and posddsibly configure/harden/make 
> more strict) base checks.
We should move narrowing conversion to bugprone and keep alias in 
cppcoreguidelines


>From c32e19f4f5dc15cf272acc54d7c574bd685a4870 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 17 Dec 2024 23:31:52 +0800
Subject: [PATCH] [clang-tidy][NFC] swap
 cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions

According to #116591.
> Coding guidelines should "cherry-pick" (and posddsibly configure/harden/make 
> more strict) base checks.
We should move narrowing conversion to bugprone and keep alias in 
cppcoreguidelines
---
 .../bugprone/BugproneTidyModule.cpp   |  4 +-
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../NarrowingConversionsCheck.cpp |  2 +-
 .../NarrowingConversionsCheck.h   |  2 +-
 .../cppcoreguidelines/CMakeLists.txt  |  1 -
 .../CppCoreGuidelinesTidyModule.cpp   |  4 +-
 .../checks/bugprone/narrowing-conversions.rst | 95 --
 .../narrowing-conversions.rst | 93 ++
 .../narrowing-conversions-bitfields.cpp   |  4 +-
 ...-conversions-equivalentbitwidth-option.cpp | 20 ++--
 ...sions-ignoreconversionfromtypes-option.cpp | 28 +++---
 ...rrowing-conversions-intemplates-option.cpp | 12 +--
 .../narrowing-conversions-long-is-32bits.cpp  |  6 +-
 ...versions-narrowingfloatingpoint-option.cpp | 24 ++---
 ...ng-conversions-narrowinginteger-option.cpp | 16 +--
 ...narrowingintegertofloatingpoint-option.cpp | 19 
 ...rowing-conversions-pedanticmode-option.cpp | 12 +--
 .../narrowing-conversions-unsigned-char.cpp   | 22 ++---
 .../narrowing-conversions.cpp | 98 +--
 ...narrowingintegertofloatingpoint-option.cpp | 19 
 20 files changed, 242 insertions(+), 240 deletions(-)
 rename clang-tools-extra/clang-tidy/{cppcoreguidelines => 
bugprone}/NarrowingConversionsCheck.cpp (99%)
 rename clang-tools-extra/clang-tidy/{cppcoreguidelines => 
bugprone}/NarrowingConversionsCheck.h (99%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-bitfields.cpp (97%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-equivalentbitwidth-option.cpp (66%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-ignoreconversionfromtypes-option.cpp (75%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-intemplates-option.cpp (73%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-long-is-32bits.cpp (84%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-narrowingfloatingpoint-option.cpp (70%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-narrowinginteger-option.cpp (59%)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-narrowingintegertofloatingpoint-option.cpp
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-pedanticmode-option.cpp (52%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-unsigned-char.cpp (80%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions.cpp (77%)
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingintegertofloatingpoint-option.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 33ac65e715ce81..c55acf0f4e1803 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -9,7 +9,6 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "../cppcoreguidelines/NarrowingConversionsCheck.h"
 #include "ArgumentCommentCheck.h"
 #include "AssertSideEffectCheck.h"
 #include "AssignmentInIfConditionCheck.h"
@@ -17,6 +16,7 @@
 #include "BitwisePointerCastCheck.h"
 #include "BoolPointerImplicitConversionCheck.h"
 #include "BranchCloneCheck.h"
+#include "NarrowingConversionsCheck.h"
 #include "CastingThroughVoidCheck.h"
 #include "ChainedComparisonCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
@@ -183,7 +183,7 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-pointer-arithmetic-on-polymorphic-object");
 CheckFactories.registerCheck(
 "bugprone-redundant-branch-condition");
-CheckFactories.regist

[clang-tools-extra] [clang-tidy][NFC] swap cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions (PR #120245)

2024-12-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes

According to #116591.
> Coding guidelines should "cherry-pick" (and posddsibly 
configure/harden/make more strict) base checks.
We should move narrowing conversion to bugprone and keep alias in 
cppcoreguidelines


---

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


20 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
(+2-2) 
- (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1) 
- (renamed) clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
(+1-1) 
- (renamed) clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h 
(+1-1) 
- (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt (-1) 
- (modified) 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp 
(+2-2) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/bugprone/narrowing-conversions.rst 
(+89-6) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/narrowing-conversions.rst
 (+6-87) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-bitfields.cpp
 (+2-2) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-equivalentbitwidth-option.cpp
 (+10-10) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-ignoreconversionfromtypes-option.cpp
 (+14-14) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-intemplates-option.cpp
 (+6-6) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-long-is-32bits.cpp
 (+3-3) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-narrowingfloatingpoint-option.cpp
 (+12-12) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-narrowinginteger-option.cpp
 (+8-8) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-narrowingintegertofloatingpoint-option.cpp
 (+19) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-pedanticmode-option.cpp
 (+6-6) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-unsigned-char.cpp
 (+11-11) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions.cpp 
(+49-49) 
- (removed) 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingintegertofloatingpoint-option.cpp
 (-19) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 33ac65e715ce81..c55acf0f4e1803 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -9,7 +9,6 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "../cppcoreguidelines/NarrowingConversionsCheck.h"
 #include "ArgumentCommentCheck.h"
 #include "AssertSideEffectCheck.h"
 #include "AssignmentInIfConditionCheck.h"
@@ -17,6 +16,7 @@
 #include "BitwisePointerCastCheck.h"
 #include "BoolPointerImplicitConversionCheck.h"
 #include "BranchCloneCheck.h"
+#include "NarrowingConversionsCheck.h"
 #include "CastingThroughVoidCheck.h"
 #include "ChainedComparisonCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
@@ -183,7 +183,7 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-pointer-arithmetic-on-polymorphic-object");
 CheckFactories.registerCheck(
 "bugprone-redundant-branch-condition");
-CheckFactories.registerCheck(
+CheckFactories.registerCheck(
 "bugprone-narrowing-conversions");
 CheckFactories.registerCheck("bugprone-no-escape");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 13adad7c3dadbd..73ab22381631c8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   MultiLevelImplicitPointerConversionCheck.cpp
   MultipleNewInOneExpressionCheck.cpp
   MultipleStatementMacroCheck.cpp
+  NarrowingConversionsCheck.cpp
   NoEscapeCheck.cpp
   NonZeroEnumToBoolConversionCheck.cpp
   NondeterministicPointerIterationOrderCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
similarity index 99%
rename from 
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
rename to clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index 45fe

[clang] [clang][dataflow] Add matchers for smart pointer accessors to be cached (PR #120102)

2024-12-17 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 3c3094b60d3587b1db8ef35b3bf54e73ac5894d9 
4b21305cbe0da07faa57f05856edd9369d4f4ed5 --extensions cpp,h -- 
clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h 
clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp 
clang/unittests/Analysis/FlowSensitive/SmartPointerAccessorCachingTest.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang/unittests/Analysis/FlowSensitive/SmartPointerAccessorCachingTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/SmartPointerAccessorCachingTest.cpp
index 1b52f13b82..3f75dff60e 100644
--- a/clang/unittests/Analysis/FlowSensitive/SmartPointerAccessorCachingTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/SmartPointerAccessorCachingTest.cpp
@@ -192,4 +192,3 @@ TEST(SmartPointerAccessorCachingTest, 
MatchesWithValueAndNonConstOverloads) {
 
 } // namespace
 } // namespace clang::dataflow
-

``




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


[clang] [llvm] [NFC][AMDGPU] Pre-commit clang and llvm tests for dynamic allocas (PR #120063)

2024-12-17 Thread via cfe-commits


@@ -0,0 +1,532 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -x hip -emit-llvm 
-fcuda-is-device -o - %s | FileCheck %s

easyonaadit wrote:

I will follow up on the llvm-test-suite separately. For now, I'll keep all 
these tests. 

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #120223)

2024-12-17 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/120223

>From e53dfbc9b2c6b7f30c1378731d7de284fa99d568 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Tue, 11 Jun 2024 14:26:38 +0100
Subject: [PATCH 01/13] [Clang] Implement CWG2813

---
 clang/docs/ReleaseNotes.rst   |  5 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/lib/Sema/SemaExprMember.cpp | 64 +++---
 clang/lib/Sema/SemaOverload.cpp   | 11 +--
 clang/lib/Sema/SemaStmt.cpp   | 14 ++-
 .../test/AST/ast-dump-for-range-lifetime.cpp  | 12 +--
 .../dcl.attr/dcl.attr.nodiscard/p2.cpp| 86 ++-
 clang/test/CXX/drs/cwg28xx.cpp| 17 
 clang/test/CodeGenCXX/cxx2b-deducing-this.cpp |  1 -
 clang/www/cxx_dr_status.html  |  2 +-
 10 files changed, 164 insertions(+), 51 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cf1ba02cbc4b2f..36bf1fdea36020 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -260,6 +260,11 @@ Resolutions to C++ Defect Reports
 - Clang now requires a template argument list after a template keyword.
   (`CWG96: Syntactic disambiguation using the template keyword 
`_).
 
+- Clang now allows calling explicit object member functions directly with 
prvalues
+  instead of always materializing a temporary, meaning by-value explicit 
object parameters
+  do not need to move from a temporary.
+  (`CWG2813: Class member access with prvalues 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 193eae3bc41d61..008bf5fa0ccfc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9182,6 +9182,9 @@ def warn_unused_constructor : Warning<
 def warn_unused_constructor_msg : Warning<
   "ignoring temporary created by a constructor declared with %0 attribute: 
%1">,
   InGroup;
+def warn_discarded_class_member_access : Warning<
+  "left operand of dot in this class member access is discarded and has no 
effect">,
+  InGroup;
 def warn_side_effects_unevaluated_context : Warning<
   "expression with side effects has no effect in an unevaluated context">,
   InGroup;
diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 3ae1af26d0096f..4679fe529ac91d 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1015,15 +1015,6 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType 
BaseExprType,
   : !isDependentScopeSpecifier(SS) || computeDeclContext(SS)) &&
  "dependent lookup context that isn't the current instantiation?");
 
-  // C++1z [expr.ref]p2:
-  //   For the first option (dot) the first expression shall be a glvalue [...]
-  if (!IsArrow && BaseExpr && BaseExpr->isPRValue()) {
-ExprResult Converted = TemporaryMaterializationConversion(BaseExpr);
-if (Converted.isInvalid())
-  return ExprError();
-BaseExpr = Converted.get();
-  }
-
   const DeclarationNameInfo &MemberNameInfo = R.getLookupNameInfo();
   DeclarationName MemberName = MemberNameInfo.getName();
   SourceLocation MemberLoc = MemberNameInfo.getLoc();
@@ -1140,26 +1131,68 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType 
BaseExprType,
 BaseExpr = BuildCXXThisExpr(Loc, BaseExprType, /*IsImplicit=*/true);
   }
 
+  // C++17 [expr.ref]p2, per CWG2813:
+  //   For the first option (dot), if the id-expression names a static member 
or
+  //   an enumerator, the first expression is a discarded-value expression; if
+  //   the id-expression names a non-static data member, the first expression
+  //   shall be a glvalue.
+  auto MakeDiscardedValue = [&BaseExpr, IsArrow, this] {
+assert(getLangOpts().CPlusPlus &&
+   "Static member / member enumerator outside of C++");
+if (IsArrow)
+  return false;
+ExprResult Converted = IgnoredValueConversions(BaseExpr);
+if (Converted.isInvalid())
+  return true;
+BaseExpr = Converted.get();
+DiagnoseUnusedExprResult(BaseExpr,
+ diag::warn_discarded_class_member_access);
+return false;
+  };
+  auto MakeGLValue = [&BaseExpr, IsArrow, this] {
+if (IsArrow || !BaseExpr->isPRValue())
+  return false;
+ExprResult Converted = TemporaryMaterializationConversion(BaseExpr);
+if (Converted.isInvalid())
+  return true;
+BaseExpr = Converted.get();
+return false;
+  };
+
   // Check the use of this member.
   if (DiagnoseUseOfDecl(MemberDecl, MemberLoc))
 return ExprError();
 
-  if (FieldDecl *FD = dyn_cast(MemberDecl))
+  if (FieldDecl *FD = dyn_cast(MemberDecl)) {
+if (MakeGLValue())
+  return ExprError();
 return BuildFieldRefe

[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #120223)

2024-12-17 Thread via cfe-commits


@@ -1162,6 +1195,9 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType 
BaseExprType,
   valueKind = VK_PRValue;
   type = Context.BoundMemberTy;

cor3ntin wrote:

Good catch. This fixed the weird changes to the for loop materializations tests

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #120223)

2024-12-17 Thread via cfe-commits


@@ -1162,6 +1195,9 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType 
BaseExprType,
   valueKind = VK_PRValue;
   type = Context.BoundMemberTy;

Sirraide wrote:

That makes sense; I was wondering what was going on w/ those.

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


[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-17 Thread via cfe-commits

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

Thanks!

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2024-12-17 Thread Matt Arsenault via cfe-commits


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

arsenm wrote:

The primary concern here would be performance loss

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


[clang] [llvm] [LLVM][Clang][AArch64] Implement AArch64 build attributes (PR #118771)

2024-12-17 Thread via cfe-commits

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2024-12-17 Thread Joseph Huber via cfe-commits


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

jhuber6 wrote:

Can we leave ripping it out completely until after we fix the issues that this 
causes for C/C++?

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


[clang-tools-extra] [clang-tidy][NFC] swap cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions (PR #120245)

2024-12-17 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/120245

>From 9e47698969dc59df1abaa8abd243b97e8fa038c3 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 17 Dec 2024 23:31:52 +0800
Subject: [PATCH] [clang-tidy][NFC] swap
 cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions

According to #116591.
> Coding guidelines should "cherry-pick" (and posddsibly configure/harden/make 
> more strict) base checks.
We should move narrowing conversion to bugprone and keep alias in 
cppcoreguidelines
---
 .../bugprone/BugproneTidyModule.cpp   |  4 +-
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../NarrowingConversionsCheck.cpp |  2 +-
 .../NarrowingConversionsCheck.h   |  2 +-
 .../cppcoreguidelines/CMakeLists.txt  |  1 -
 .../CppCoreGuidelinesTidyModule.cpp   |  4 +-
 .../checks/bugprone/narrowing-conversions.rst | 93 +-
 .../narrowing-conversions.rst | 91 +
 .../narrowing-conversions-bitfields.cpp   |  4 +-
 ...-conversions-equivalentbitwidth-option.cpp | 20 ++--
 ...sions-ignoreconversionfromtypes-option.cpp | 28 +++---
 ...rrowing-conversions-intemplates-option.cpp | 12 +--
 .../narrowing-conversions-long-is-32bits.cpp  |  6 +-
 ...versions-narrowingfloatingpoint-option.cpp | 24 ++---
 ...ng-conversions-narrowinginteger-option.cpp | 16 +--
 ...narrowingintegertofloatingpoint-option.cpp | 19 
 ...rowing-conversions-pedanticmode-option.cpp | 12 +--
 .../narrowing-conversions-unsigned-char.cpp   | 22 ++---
 .../narrowing-conversions.cpp | 98 +--
 ...narrowingintegertofloatingpoint-option.cpp | 19 
 20 files changed, 240 insertions(+), 238 deletions(-)
 rename clang-tools-extra/clang-tidy/{cppcoreguidelines => 
bugprone}/NarrowingConversionsCheck.cpp (99%)
 rename clang-tools-extra/clang-tidy/{cppcoreguidelines => 
bugprone}/NarrowingConversionsCheck.h (99%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-bitfields.cpp (97%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-equivalentbitwidth-option.cpp (66%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-ignoreconversionfromtypes-option.cpp (75%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-intemplates-option.cpp (73%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-long-is-32bits.cpp (84%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-narrowingfloatingpoint-option.cpp (70%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-narrowinginteger-option.cpp (59%)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-narrowingintegertofloatingpoint-option.cpp
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-pedanticmode-option.cpp (52%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions-unsigned-char.cpp (80%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => 
bugprone}/narrowing-conversions.cpp (77%)
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingintegertofloatingpoint-option.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 33ac65e715ce81..c55acf0f4e1803 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -9,7 +9,6 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "../cppcoreguidelines/NarrowingConversionsCheck.h"
 #include "ArgumentCommentCheck.h"
 #include "AssertSideEffectCheck.h"
 #include "AssignmentInIfConditionCheck.h"
@@ -17,6 +16,7 @@
 #include "BitwisePointerCastCheck.h"
 #include "BoolPointerImplicitConversionCheck.h"
 #include "BranchCloneCheck.h"
+#include "NarrowingConversionsCheck.h"
 #include "CastingThroughVoidCheck.h"
 #include "ChainedComparisonCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
@@ -183,7 +183,7 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-pointer-arithmetic-on-polymorphic-object");
 CheckFactories.registerCheck(
 "bugprone-redundant-branch-condition");
-CheckFactories.registerCheck(
+CheckFactories.registerCheck(
 "bugprone-narrowing-conversions");
 CheckFactories.registerCheck("bugprone-no-escape");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-t

[clang] [clang] Add sincos builtin using `llvm.sincos` intrinsic (PR #114086)

2024-12-17 Thread Matt Arsenault via cfe-commits

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


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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2024-12-17 Thread Nick Sarnie via cfe-commits


@@ -133,6 +133,11 @@ Error getAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer,
  StringMap 
&KernelInfoMap,
  uint16_t &ELFABIVersion);
 } // namespace amdgpu
+namespace intel {
+/// Containerizes an offloading image into the ELF binary format expected by
+/// the Intel runtime offload plugin.
+void containerizeOpenMPSPIRVImage(object::OffloadBinary::OffloadingImage &Img);

sarnex wrote:

Sure, will drop this for now and address your other feedback in a separate 
patch, thanks.

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


[clang-tools-extra] [clang-tidy][NFC] swap cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions (PR #120245)

2024-12-17 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 8b02d809d284c8e10b38087431def52c86e3e9e6 
c32e19f4f5dc15cf272acc54d7c574bd685a4870 --extensions h,cpp -- 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-narrowingintegertofloatingpoint-option.cpp
 clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp 
clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-bitfields.cpp
 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-equivalentbitwidth-option.cpp
 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-ignoreconversionfromtypes-option.cpp
 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-intemplates-option.cpp
 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-long-is-32bits.cpp
 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-narrowingfloatingpoint-option.cpp
 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-narrowinginteger-option.cpp
 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-pedanticmode-option.cpp
 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-unsigned-char.cpp
 clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index c55acf0f4e..b27616f3dc 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -16,7 +16,6 @@
 #include "BitwisePointerCastCheck.h"
 #include "BoolPointerImplicitConversionCheck.h"
 #include "BranchCloneCheck.h"
-#include "NarrowingConversionsCheck.h"
 #include "CastingThroughVoidCheck.h"
 #include "ChainedComparisonCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
@@ -47,6 +46,7 @@
 #include "MultiLevelImplicitPointerConversionCheck.h"
 #include "MultipleNewInOneExpressionCheck.h"
 #include "MultipleStatementMacroCheck.h"
+#include "NarrowingConversionsCheck.h"
 #include "NoEscapeCheck.h"
 #include "NonZeroEnumToBoolConversionCheck.h"
 #include "NondeterministicPointerIterationOrderCheck.h"
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index 7c9903c20a..a950704208 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -614,4 +614,4 @@ void NarrowingConversionsCheck::check(const 
MatchFinder::MatchResult &Result) {
 return handleImplicitCast(*Result.Context, *Cast);
   llvm_unreachable("must be binary operator or cast expression");
 }
-} // namespace clang::tidy::cppcoreguidelines
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
index eb7b920c1a..87348c924b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
@@ -104,6 +104,6 @@ private:
   const bool PedanticMode;
 };
 
-} // namespace clang::tidy::cppcoreguidelines
+} // namespace clang::tidy::bugprone
 
 #endif // 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NARROWING_CONVERSIONS_H
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
index 4dded38482..6adef04264 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "../bugprone/NarrowingConversionsCheck.h"
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
@@ -30,7 +31,6 @@
 #include "MacroUsageCheck.h"
 #include "MisleadingCaptureDefaultByValueCheck.h"
 #include "MissingStdForwardCheck.h"
-#include "../bugprone/NarrowingConversionsCheck.h"
 #include "NoMallocCheck.h"
 #include "NoSuspendWithLockCheck.h"
 #include "OwningMemoryCheck.h"

``




https://github.com/llvm/llvm-project/pull/12

[clang] [clang] Add sincos builtin using `llvm.sincos` intrinsic (PR #114086)

2024-12-17 Thread Matt Arsenault via cfe-commits


@@ -3232,6 +3264,22 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
+case Builtin::BI__builtin_sincos:
+case Builtin::BI__builtin_sincosf:
+case Builtin::BI__builtin_sincosl:
+  // Only use the llvm.sincos.* builtin on AArch64 with optimizations.
+  // Currently, getting codegen that is no worse than the direct call
+  // requires using AA during codegen. This is not done at optlevel=none,
+  // and not all targets support this (AArch64 is one of the few known to).
+  if (!getTarget().getTriple().isAArch64() ||
+  CGM.getCodeGenOpts().OptimizationLevel == 0)
+break;

arsenm wrote:

That control has been sitting there for years. This is the problem, people 
introduce stuff like this and are afraid of touching anything other than what 
they care about and it gets stuck forever 

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


[clang] [llvm] [LLVM][Clang][AArch64] Implement AArch64 build attributes (PR #118771)

2024-12-17 Thread via cfe-commits

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


[clang] [clang][dataflow] Use smart pointer caching in unchecked optional accessor (PR #120249)

2024-12-17 Thread Jan Voung via cfe-commits

https://github.com/jvoung created 
https://github.com/llvm/llvm-project/pull/120249

Part 2 (and final part) following 
https://github.com/llvm/llvm-project/pull/120102
Allows users to do things like:

```
if (o->x.has_value()) {
  ((*o).x).value();
}
```
where the `->` and `*` are operator overload calls.

A user could instead extract the nested optional into a local variable
once instead of doing two accessor calls back to back, but currently
they are unsure why the code is flagged.


>From c526263a7accc434dbf6e93c2995ceb2f95873b8 Mon Sep 17 00:00:00 2001
From: Jan Voung 
Date: Tue, 17 Dec 2024 15:38:19 +
Subject: [PATCH] [clang][dataflow] Use smart pointer caching in unchecked
 optional accessor

Part 2 (and final part) following 
https://github.com/llvm/llvm-project/pull/120102
Allows users to do things like:

```
if (o->x.has_value()) {
  ((*o).x).value();
}
```
where the `->` and `*` are operator overload calls.

A user could instead extract the nested optional into a local variable
once instead of doing two accessor calls back to back, but currently
they are unsure why the code is flagged.
---
 .../CachedConstAccessorsLattice.h |  41 
 .../SmartPointerAccessorCaching.h | 168 +++
 .../lib/Analysis/FlowSensitive/CMakeLists.txt |   1 +
 .../Models/UncheckedOptionalAccessModel.cpp   |  58 +-
 .../SmartPointerAccessorCaching.cpp   | 153 ++
 .../Analysis/FlowSensitive/CMakeLists.txt |   1 +
 .../CachedConstAccessorsLatticeTest.cpp   |  32 +++
 .../SmartPointerAccessorCachingTest.cpp   | 194 ++
 .../UncheckedOptionalAccessModelTest.cpp  |  50 +
 9 files changed, 692 insertions(+), 6 deletions(-)
 create mode 100644 
clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h
 create mode 100644 
clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
 create mode 100644 
clang/unittests/Analysis/FlowSensitive/SmartPointerAccessorCachingTest.cpp

diff --git 
a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h 
b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
index 48c5287367739a..6b5dacf9f66d2d 100644
--- a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
+++ b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
@@ -13,7 +13,9 @@
 #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H
 #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H
 
+#include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
@@ -71,10 +73,28 @@ template  class CachedConstAccessorsLattice 
: public Base {
   /// Requirements:
   ///
   ///  - `CE` should return a location (GLValue or a record type).
+  ///
+  /// DEPRECATED: switch users to the below overload which takes Callee and 
Type
+  /// directly.
   StorageLocation *getOrCreateConstMethodReturnStorageLocation(
   const RecordStorageLocation &RecordLoc, const CallExpr *CE,
   Environment &Env, llvm::function_ref 
Initialize);
 
+  /// Creates or returns a previously created `StorageLocation` associated with
+  /// a const method call `obj.getFoo()` where `RecordLoc` is the
+  /// `RecordStorageLocation` of `obj`, `Callee` is the decl for `getFoo`,
+  /// and `Type` is the return type of `getFoo`.
+  ///
+  /// The callback `Initialize` runs on the storage location if newly created.
+  ///
+  /// Requirements:
+  ///
+  ///  - `Type` should return a location (GLValue or a record type).
+  StorageLocation &getOrCreateConstMethodReturnStorageLocation(
+  const RecordStorageLocation &RecordLoc, const FunctionDecl *Callee,
+  QualType Type, Environment &Env,
+  llvm::function_ref Initialize);
+
   void clearConstMethodReturnValues(const RecordStorageLocation &RecordLoc) {
 ConstMethodReturnValues.erase(&RecordLoc);
   }
@@ -212,6 +232,27 @@ 
CachedConstAccessorsLattice::getOrCreateConstMethodReturnStorageLocation(
   return &Loc;
 }
 
+template 
+StorageLocation &
+CachedConstAccessorsLattice::getOrCreateConstMethodReturnStorageLocation(
+const RecordStorageLocation &RecordLoc, const FunctionDecl *Callee,
+QualType Type, Environment &Env,
+llvm::function_ref Initialize) {
+  assert(Callee != nullptr);
+  assert(!Type.isNull());
+  assert(Type->isReferenceType() || Type->isRecordType());
+  auto &ObjMap = ConstMethodReturnStorageLocations[&RecordLoc];
+  auto it = ObjMap.find(Callee);
+  if (it != ObjMap.end())
+return *it->second;
+
+  StorageLocation &Loc = Env.createStorageLocation(Type.getNonReferenceType());
+  Initialize(Loc);
+
+  ObjMap.insert({Callee, &Loc});
+  return Loc;
+}
+
 } // namespace dataflow
 } // namespace clang
 
diff --git 
a/clang/include/clang/Analysis/Flow

[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #120149)

2024-12-17 Thread Cyndy Ishida via cfe-commits


@@ -0,0 +1,26 @@
+// UNSUPPORTED: system-windows
+//   Windows is unsupported because we use the Unix path separator `/` in the 
test.
+
+// Add default directories before running clang to check default
+// search paths.
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: cp -R %S/Inputs/MacOSX15.1.sdk %t/
+// RUN: mkdir -p %t/MacOSX15.1.sdk/System/Library/Frameworks
+// RUN: mkdir -p %t/MacOSX15.1.sdk/System/Library/SubFrameworks
+// RUN: mkdir -p %t/MacOSX15.1.sdk/usr/include
+
+// RUN: %clang -xc %s -target arm64-apple-darwin13.0 -isysroot 
%t/MacOSX15.1.sdk -E -v 2>&1 | FileCheck --check-prefix=CHECK-C %s

cyndyishida wrote:

There is already 
https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/driverkit-path.c
 
Are you thinking of adding to it?

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


[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #120149)

2024-12-17 Thread Cyndy Ishida via cfe-commits

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


[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #120149)

2024-12-17 Thread Cyndy Ishida via cfe-commits


@@ -2539,6 +2550,18 @@ void DarwinClang::AddClangSystemIncludeArgs(const 
llvm::opt::ArgList &DriverArgs
 llvm::sys::path::append(P, "usr", "include");
 addExternCSystemInclude(DriverArgs, CC1Args, P.str());
   }
+
+  // Add default framework search paths
+  auto addFrameworkInclude = [&](auto ...Path) {
+SmallString<128> P(Sysroot);
+llvm::sys::path::append(P, Path...);
+
+CC1Args.push_back("-internal-iframework");
+CC1Args.push_back(DriverArgs.MakeArgString(P));
+  };
+  addFrameworkInclude("System", "Library", "Frameworks");

cyndyishida wrote:

Do you think it's possible to have the same string input style for linker 
search paths as header search paths? It would make sharing common the paths 
simpler, as a future cleanup.

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


[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #120149)

2024-12-17 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida commented:

Thank you for cleaning this up!!

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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-17 Thread via cfe-commits

https://github.com/AdUhTkJm updated 
https://github.com/llvm/llvm-project/pull/119098

>From 56670608becf2032867405778fa7b2b1a36fb3cf Mon Sep 17 00:00:00 2001
From: AdUhTkJm <2292398...@qq.com>
Date: Sun, 8 Dec 2024 08:07:59 +0800
Subject: [PATCH] [Clang] Fix crash for incompatible types in inline assembly

---
 clang/lib/Sema/SemaStmtAsm.cpp |  7 ++-
 clang/test/Sema/asm.c  | 21 +
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..a0b203fbdfec21 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -664,11 +664,16 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
   SmallerValueMentioned |= OutSize < InSize;
 }
 
+// If the input is an integer register while the output is floating point,
+// or vice-versa, there is no way they can work together.
+bool FPTiedToInt = (InputDomain == AD_FP) ^ (OutputDomain == AD_FP);
+
 // If the smaller value wasn't mentioned in the asm string, and if the
 // output was a register, just extend the shorter one to the size of the
 // larger one.
-if (!SmallerValueMentioned && InputDomain != AD_Other &&
+if (!SmallerValueMentioned && !FPTiedToInt && InputDomain != AD_Other &&
 OutputConstraintInfos[TiedTo].allowsRegister()) {
+
   // FIXME: GCC supports the OutSize to be 128 at maximum. Currently 
codegen
   // crash when the size larger than the register size. So we limit it 
here.
   if (OutTy->isStructureType() &&
diff --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c
index a9cff5947ef5d0..a666b45b3150ca 100644
--- a/clang/test/Sema/asm.c
+++ b/clang/test/Sema/asm.c
@@ -365,3 +365,24 @@ void test19(long long x)
   // FIXME: This case should be supported by codegen, but it fails now.
   asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: 
input with type 'st_size128' (aka 'struct _st_size128') matching output with 
type 'long long'}}
 }
+
+typedef int int2 __attribute__((ext_vector_type(2)));
+
+// GH118892
+void test20(char x) {
+  double d;
+  float f;
+
+  asm ("fabs" : "=t" (d): "0" (x)); // expected-error {{unsupported inline 
asm: input with type 'char' matching output with type 'double'}}
+  asm ("fabs" : "=t" (x): "0" (d)); // expected-error {{unsupported inline 
asm: input with type 'double' matching output with type 'char'}}
+  asm ("fabs" : "=t" (f): "0" (d)); // no-error
+  asm ("fabs" : "=t" (d): "0" (f)); // no-error
+
+  st_size64 a;
+  asm ("fabs" : "=t" (d): "0" (a)); // expected-error {{unsupported inline 
asm: input with type 'st_size64' (aka 'struct _st_size64') matching output with 
type 'double'}}
+  asm ("fabs" : "=t" (a): "0" (d)); // expected-error {{unsupported inline 
asm: input with type 'double' matching output with type 'st_size64' (aka 
'struct _st_size64')}}
+
+  int2 v;
+  asm ("fabs" : "=t" (d): "0" (v)); // expected-error {{unsupported inline 
asm: input with type 'int2' (vector of 2 'int' values) matching output with 
type 'double'}}
+  asm ("fabs" : "=t" (v): "0" (d)); // expected-error {{unsupported inline 
asm: input with type 'double' matching output with type 'int2' (vector of 2 
'int' values)}}
+}

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


[clang] [llvm] [NFC][AMDGPU] Pre-commit clang and llvm tests for dynamic allocas (PR #120063)

2024-12-17 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,532 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -x hip -emit-llvm 
-fcuda-is-device -o - %s | FileCheck %s

arsenm wrote:

I guess 51a014cb2d9c6f8303f9b11ffc035d69cbeb9e21 didn't add any hip tests, so I 
guess we need some.

> We have plans of adding hip-tests, or do you want the code to be exercised in 
> the llvm-test-suite

llvm-test-suite would be better 

https://github.com/llvm/llvm-project/pull/120063
___
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 readability-string-view-substr check (PR #120055)

2024-12-17 Thread Helmut Januschka via cfe-commits

https://github.com/hjanuschka updated 
https://github.com/llvm/llvm-project/pull/120055

>From 8b2dc9adf4fae2065823e5beb3a1cd851686913c Mon Sep 17 00:00:00 2001
From: Helmut Januschka 
Date: Mon, 16 Dec 2024 08:24:14 +0100
Subject: [PATCH 1/5] [clang-tidy] Add readability-string-view-substr check

Add a new check that suggests using string_view::remove_prefix() and
remove_suffix() instead of substr() when the intent is to remove
characters from either end of a string_view.
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../readability/StringViewSubstrCheck.cpp | 132 ++
 .../readability/StringViewSubstrCheck.h   |  39 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   7 +
 .../checks/readability/string-view-substr.rst |  16 +++
 .../readability/stringview_substr.cpp |  55 
 7 files changed, 253 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/string-view-substr.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/stringview_substr.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 8f303c51e1b0da..8b44fc339441ac 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -53,6 +53,7 @@ add_clang_library(clangTidyReadabilityModule STATIC
   StaticAccessedThroughInstanceCheck.cpp
   StaticDefinitionInAnonymousNamespaceCheck.cpp
   StringCompareCheck.cpp
+  StringViewSubstrCheck.cpp
   SuspiciousCallArgumentCheck.cpp
   UniqueptrDeleteReleaseCheck.cpp
   UppercaseLiteralSuffixCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index d61c0ba39658e5..f36ec8f95ede60 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -56,6 +56,7 @@
 #include "StaticAccessedThroughInstanceCheck.h"
 #include "StaticDefinitionInAnonymousNamespaceCheck.h"
 #include "StringCompareCheck.h"
+#include "StringViewSubstrCheck.h"
 #include "SuspiciousCallArgumentCheck.h"
 #include "UniqueptrDeleteReleaseCheck.h"
 #include "UppercaseLiteralSuffixCheck.h"
@@ -146,6 +147,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-static-definition-in-anonymous-namespace");
 CheckFactories.registerCheck(
 "readability-string-compare");
+CheckFactories.registerCheck(
+"readability-stringview-substr");
 CheckFactories.registerCheck(
 "readability-named-parameter");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
new file mode 100644
index 00..e86a971695a835
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
@@ -0,0 +1,132 @@
+//===--- StringViewSubstrCheck.cpp - clang-tidy--*- 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
+//
+//===--===//
+
+#include "StringViewSubstrCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void StringViewSubstrCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasStringViewType = 
hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(recordDecl(hasName("::std::basic_string_view"));
+
+  // Match assignment to string_view's substr
+  Finder->addMatcher(
+  cxxOperatorCallExpr(
+  hasOverloadedOperatorName("="),
+  hasArgument(0, expr(HasStringViewType).bind("target")),
+  hasArgument(
+  1, cxxMemberCallExpr(callee(memberExpr(hasDeclaration(
+   cxxMethodDecl(hasName("substr"),
+   on(expr(HasStringViewType).bind("source")))
+ .bind("substr_call")))
+  .bind("assignment"),
+  this);
+}
+
+void StringViewSubstrCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Assignment =
+  Result.Nodes.getNodeAs("assignment");
+  const auto *Target = Result.Nodes.getNodeAs("target");
+  const auto *Source = Result.Nodes.getNodeAs("source");
+  const auto *SubstrCall =
+  Result.Nod

[clang] [HLSL][NFC] Fix static analyzer concerns (PR #120090)

2024-12-17 Thread via cfe-commits

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

LGTM modulo nit

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


[clang] [clang][dataflow] Add matchers for smart pointer accessors to be cached (PR #120102)

2024-12-17 Thread Florian Mayer via cfe-commits


@@ -0,0 +1,194 @@
+//===- unittests/Analysis/FlowSensitive/SmartPointerAccessorCachingTest.cpp 
==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h"
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/StringRef.h"
+#include "gtest/gtest.h"
+
+namespace clang::dataflow {
+namespace {
+
+using clang::ast_matchers::match;
+
+template 
+bool matches(llvm::StringRef Decls, llvm::StringRef TestInput,
+ MatcherT Matcher) {
+  TestAST InputAST(Decls.str() + TestInput.str());
+  return !match(Matcher, InputAST.context()).empty();
+}
+
+TEST(SmartPointerAccessorCachingTest, MatchesClassWithStarArrowGet) {
+  llvm::StringRef Decls(R"cc(
+namespace std {
+template 
+struct unique_ptr {
+  T* operator->() const;
+  T& operator*() const;
+  T* get() const;
+};
+}  // namespace std
+
+template 
+using UniquePtrAlias = std::unique_ptr;
+
+struct S { int i; };
+  )cc");
+
+  EXPECT_TRUE(matches(Decls,
+  "int target(std::unique_ptr P) { return (*P).i; }",
+  isSmartPointerLikeOperatorStar()));
+  EXPECT_TRUE(matches(Decls,
+  "int target(std::unique_ptr P) { return P->i; }",
+  isSmartPointerLikeOperatorArrow()));
+  EXPECT_TRUE(matches(Decls,
+  "int target(std::unique_ptr P) { return P.get()->i; 
}",
+  isSmartPointerLikeGetMethodCall()));
+
+  EXPECT_TRUE(matches(Decls, "int target(UniquePtrAlias P) { return P->i; 
}",
+  isSmartPointerLikeOperatorArrow()));
+}
+
+TEST(SmartPointerAccessorCachingTest, NoMatchIfUnexpectedReturnTypes) {
+  llvm::StringRef Decls(R"cc(
+namespace std {
+// unique_ptr isn't really like this, but we aren't matching by name
+template 
+struct unique_ptr {
+  U* operator->() const;
+  T& operator*() const;
+  T* get() const;
+};
+}  // namespace std
+
+struct S { int i; };
+struct T { int j; };
+  )cc");
+
+  EXPECT_FALSE(matches(Decls,
+   "int target(std::unique_ptr P) { return (*P).i; 
}",
+   isSmartPointerLikeOperatorStar()));
+  EXPECT_FALSE(matches(Decls,
+   "int target(std::unique_ptr P) { return P->j; }",
+   isSmartPointerLikeOperatorArrow()));
+  // The class matching arguably accidentally matches, just because the
+  // instantiation is with S, S. Hopefully doesn't happen too much in real code
+  // with such operator* and operator-> overloads.
+  EXPECT_TRUE(matches(Decls,
+  "int target(std::unique_ptr P) { return P->i; }",
+  isSmartPointerLikeOperatorArrow()));
+}
+
+TEST(SmartPointerAccessorCachingTest, NoMatchIfBinaryStar) {
+  llvm::StringRef Decls(R"cc(
+namespace std {
+template 
+struct unique_ptr {
+  T* operator->() const;
+  T& operator*(int x) const;
+  T* get() const;
+};
+}  // namespace std
+
+struct S { int i; };
+  )cc");
+
+  EXPECT_FALSE(
+  matches(Decls, "int target(std::unique_ptr P) { return (P * 10).i; }",
+  isSmartPointerLikeOperatorStar()));
+}
+
+TEST(SmartPointerAccessorCachingTest, NoMatchIfNoConstOverloads) {
+  llvm::StringRef Decls(R"cc(
+namespace std {
+template 
+struct unique_ptr {
+  T* operator->();
+  T& operator*();
+  T* get();
+};
+}  // namespace std
+
+struct S { int i; };
+  )cc");
+
+  EXPECT_FALSE(matches(Decls,
+   "int target(std::unique_ptr P) { return (*P).i; }",
+   isSmartPointerLikeOperatorStar()));
+  EXPECT_FALSE(matches(Decls,
+   "int target(std::unique_ptr P) { return P->i; }",
+   isSmartPointerLikeOperatorArrow()));
+  EXPECT_FALSE(
+  matches(Decls, "int target(std::unique_ptr P) { return P.get()->i; }",
+  isSmartPointerLikeGetMethodCall()));
+}
+
+TEST(SmartPointerAccessorCachingTest, NoMatchIfNoStarMethod) {
+  llvm::StringRef Decls(R"cc(
+namespace std {
+template 
+struct unique_ptr {
+  T* operator->();
+  T* get();
+};
+}  // namespace std
+
+struct S { int i; };
+  )cc");
+
+  EXPECT_FALSE(matches(Decls,
+   "int target(std::unique_ptr P) { return P->i; }",
+   isSmartPointerLikeOperatorArrow()));
+  EXPECT_FALSE(matches(Decls,
+   "int target(std::unique_ptr P) { return P->i; }",
+   isSmartPointerLikeGetMethodCall()));
+}
+
+TEST(SmartPointerAccessorCachingTest, MatchesWithValueAnd

[clang] [clang][dataflow] Add matchers for smart pointer accessors to be cached (PR #120102)

2024-12-17 Thread Florian Mayer via cfe-commits


@@ -0,0 +1,134 @@
+#include "clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h"
+
+#include "clang/AST/CanonicalType.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/OperatorKinds.h"
+
+namespace clang::dataflow {
+
+namespace {
+
+using ast_matchers::callee;
+using ast_matchers::cxxMemberCallExpr;
+using ast_matchers::cxxMethodDecl;
+using ast_matchers::cxxOperatorCallExpr;
+using ast_matchers::hasName;
+using ast_matchers::hasOverloadedOperatorName;
+using ast_matchers::ofClass;
+using ast_matchers::parameterCountIs;
+using ast_matchers::pointerType;
+using ast_matchers::referenceType;
+using ast_matchers::returns;
+
+bool hasSmartPointerClassShape(const CXXRecordDecl &RD, bool &HasGet,
+   bool &HasValue) {
+  // We may want to cache this search, but in current profiles it hasn't shown
+  // up as a hot spot (possibly because there aren't many hits, relatively).
+  bool HasArrow = false;
+  bool HasStar = false;
+  CanQualType StarReturnType, ArrowReturnType, GetReturnType, ValueReturnType;
+  for (const auto *MD : RD.methods()) {
+// We only consider methods that are const and have zero parameters.
+// It may be that there is a non-const overload for the method, but
+// there should at least be a const overload as well.
+if (!MD->isConst() || MD->getNumParams() != 0) {

fmayer wrote:

nit: for consistency, drop `{}`

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


[clang] [llvm] [Offload] Add support for loongarch64 to host plugin (PR #120173)

2024-12-17 Thread via cfe-commits

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


[clang] [Feature]: support for the BC library file into the compile dependencies (PR #119513)

2024-12-17 Thread via cfe-commits

zhouronghua wrote:

ping

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


[clang] [clang] Add sincos builtin using `llvm.sincos` intrinsic (PR #114086)

2024-12-17 Thread Matt Arsenault via cfe-commits


@@ -3232,6 +3264,22 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
+case Builtin::BI__builtin_sincos:
+case Builtin::BI__builtin_sincosf:
+case Builtin::BI__builtin_sincosl:
+  // Only use the llvm.sincos.* builtin on AArch64 with optimizations.
+  // Currently, getting codegen that is no worse than the direct call
+  // requires using AA during codegen. This is not done at optlevel=none,
+  // and not all targets support this (AArch64 is one of the few known to).
+  if (!getTarget().getTriple().isAArch64() ||
+  CGM.getCodeGenOpts().OptimizationLevel == 0)
+break;

arsenm wrote:

Doesn't matter, just emit the intrinsic. Also we should just universally turn 
on AA

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


[clang] [clang] Recover necessary AddrSpaceCast (PR #119246)

2024-12-17 Thread Youngsuk Kim via cfe-commits


@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-unknown-linux-gnu -target-cpu gfx906 -fopenmp -nogpulib 
-fopenmp-is-target-device -emit-llvm %s -o - | FileCheck %s
+
+// Don't crash with assertions build.
+
+// CHECK:   @MyGlobVar = external thread_local addrspace(1) global i32, 
align 4
+// CHECK:   define weak_odr hidden noundef ptr @_ZTW9MyGlobVar() #0 comdat 
{
+// CHECK-NEXT:%1 = call align 4 ptr addrspace(1) 
@llvm.threadlocal.address.p1(ptr addrspace(1) align 4 @MyGlobVar)

JOE1994 wrote:

(For AMDGPU codegen) Doesn't seem so to me.

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


[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-17 Thread via cfe-commits


@@ -2903,7 +2903,10 @@ TargetOMPContext::TargetOMPContext(
 const FunctionDecl *CurrentFunctionDecl,
 ArrayRef ConstructTraits)
 : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice,
- ASTCtx.getTargetInfo().getTriple()),
+ ASTCtx.getTargetInfo().getTriple(),
+ ASTCtx.getLangOpts().OMPTargetTriples.empty()
+ ? llvm::Triple()
+ : ASTCtx.getLangOpts().OMPTargetTriples[0]),

Ritanya-B-Bharadwaj wrote:

As per my understanding, in the current implementation of OpenMP offloading, 
only the first non-host target specified via the `-fopenmp-targets` option is 
actively supported during offloading. Hence, I have considered only the first 
target triple. 

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #120223)

2024-12-17 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/120223

>From e53dfbc9b2c6b7f30c1378731d7de284fa99d568 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Tue, 11 Jun 2024 14:26:38 +0100
Subject: [PATCH 01/14] [Clang] Implement CWG2813

---
 clang/docs/ReleaseNotes.rst   |  5 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/lib/Sema/SemaExprMember.cpp | 64 +++---
 clang/lib/Sema/SemaOverload.cpp   | 11 +--
 clang/lib/Sema/SemaStmt.cpp   | 14 ++-
 .../test/AST/ast-dump-for-range-lifetime.cpp  | 12 +--
 .../dcl.attr/dcl.attr.nodiscard/p2.cpp| 86 ++-
 clang/test/CXX/drs/cwg28xx.cpp| 17 
 clang/test/CodeGenCXX/cxx2b-deducing-this.cpp |  1 -
 clang/www/cxx_dr_status.html  |  2 +-
 10 files changed, 164 insertions(+), 51 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cf1ba02cbc4b2f..36bf1fdea36020 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -260,6 +260,11 @@ Resolutions to C++ Defect Reports
 - Clang now requires a template argument list after a template keyword.
   (`CWG96: Syntactic disambiguation using the template keyword 
`_).
 
+- Clang now allows calling explicit object member functions directly with 
prvalues
+  instead of always materializing a temporary, meaning by-value explicit 
object parameters
+  do not need to move from a temporary.
+  (`CWG2813: Class member access with prvalues 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 193eae3bc41d61..008bf5fa0ccfc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9182,6 +9182,9 @@ def warn_unused_constructor : Warning<
 def warn_unused_constructor_msg : Warning<
   "ignoring temporary created by a constructor declared with %0 attribute: 
%1">,
   InGroup;
+def warn_discarded_class_member_access : Warning<
+  "left operand of dot in this class member access is discarded and has no 
effect">,
+  InGroup;
 def warn_side_effects_unevaluated_context : Warning<
   "expression with side effects has no effect in an unevaluated context">,
   InGroup;
diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 3ae1af26d0096f..4679fe529ac91d 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1015,15 +1015,6 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType 
BaseExprType,
   : !isDependentScopeSpecifier(SS) || computeDeclContext(SS)) &&
  "dependent lookup context that isn't the current instantiation?");
 
-  // C++1z [expr.ref]p2:
-  //   For the first option (dot) the first expression shall be a glvalue [...]
-  if (!IsArrow && BaseExpr && BaseExpr->isPRValue()) {
-ExprResult Converted = TemporaryMaterializationConversion(BaseExpr);
-if (Converted.isInvalid())
-  return ExprError();
-BaseExpr = Converted.get();
-  }
-
   const DeclarationNameInfo &MemberNameInfo = R.getLookupNameInfo();
   DeclarationName MemberName = MemberNameInfo.getName();
   SourceLocation MemberLoc = MemberNameInfo.getLoc();
@@ -1140,26 +1131,68 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType 
BaseExprType,
 BaseExpr = BuildCXXThisExpr(Loc, BaseExprType, /*IsImplicit=*/true);
   }
 
+  // C++17 [expr.ref]p2, per CWG2813:
+  //   For the first option (dot), if the id-expression names a static member 
or
+  //   an enumerator, the first expression is a discarded-value expression; if
+  //   the id-expression names a non-static data member, the first expression
+  //   shall be a glvalue.
+  auto MakeDiscardedValue = [&BaseExpr, IsArrow, this] {
+assert(getLangOpts().CPlusPlus &&
+   "Static member / member enumerator outside of C++");
+if (IsArrow)
+  return false;
+ExprResult Converted = IgnoredValueConversions(BaseExpr);
+if (Converted.isInvalid())
+  return true;
+BaseExpr = Converted.get();
+DiagnoseUnusedExprResult(BaseExpr,
+ diag::warn_discarded_class_member_access);
+return false;
+  };
+  auto MakeGLValue = [&BaseExpr, IsArrow, this] {
+if (IsArrow || !BaseExpr->isPRValue())
+  return false;
+ExprResult Converted = TemporaryMaterializationConversion(BaseExpr);
+if (Converted.isInvalid())
+  return true;
+BaseExpr = Converted.get();
+return false;
+  };
+
   // Check the use of this member.
   if (DiagnoseUseOfDecl(MemberDecl, MemberLoc))
 return ExprError();
 
-  if (FieldDecl *FD = dyn_cast(MemberDecl))
+  if (FieldDecl *FD = dyn_cast(MemberDecl)) {
+if (MakeGLValue())
+  return ExprError();
 return BuildFieldRefe

[clang] [HLSL][NFC] Fix static analyzer concerns (PR #120090)

2024-12-17 Thread Mariya Podchishchaeva via cfe-commits

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


[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)

2024-12-17 Thread via cfe-commits

https://github.com/4m4n-x-B4w4ne updated 
https://github.com/llvm/llvm-project/pull/120087

>From 03f536888ddc5b7be2514c2d880c6d3119b7f4ee Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:43:42 +0530
Subject: [PATCH 1/4] Update ImplicitBoolConversionCheck.cpp

Added new options in ImplicitBoolConversionCheck CheckConversionToBool and 
CheckConversionFromBool.
---
 .../readability/ImplicitBoolConversionCheck.cpp   | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index f9fd1d903e231e..517a5d2b982751 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -258,14 +258,17 @@ ImplicitBoolConversionCheck::ImplicitBoolConversionCheck(
 : ClangTidyCheck(Name, Context),
   AllowIntegerConditions(Options.get("AllowIntegerConditions", false)),
   AllowPointerConditions(Options.get("AllowPointerConditions", false)),
-  UseUpperCaseLiteralSuffix(
-  Options.get("UseUpperCaseLiteralSuffix", false)) {}
+  UseUpperCaseLiteralSuffix(Options.get("UseUpperCaseLiteralSuffix", 
false)),
+  CheckConversionsToBool(Options.get("CheckConversionsToBool",true)),
+  CheckConversionsFromBool(Options.get("CheckConversionsFromBool",true)) {}
 
 void ImplicitBoolConversionCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AllowIntegerConditions", AllowIntegerConditions);
   Options.store(Opts, "AllowPointerConditions", AllowPointerConditions);
   Options.store(Opts, "UseUpperCaseLiteralSuffix", UseUpperCaseLiteralSuffix);
+  Options.store(Opts,"CheckConversionsToBool",CheckConversionsToBool);
+  Options.store(Opts,"CheckConversionsFromBool",CheckConversionsFromBool);
 }
 
 void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
@@ -358,14 +361,14 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
 void ImplicitBoolConversionCheck::check(
 const MatchFinder::MatchResult &Result) {
 
-  if (const auto *CastToBool =
-  Result.Nodes.getNodeAs("implicitCastToBool")) {
+  if (CheckConversionsToBool && (const auto *CastToBool =
+  Result.Nodes.getNodeAs("implicitCastToBool"))) {
 const auto *Parent = Result.Nodes.getNodeAs("parentStmt");
 return handleCastToBool(CastToBool, Parent, *Result.Context);
   }
 
-  if (const auto *CastFromBool =
-  Result.Nodes.getNodeAs("implicitCastFromBool")) {
+  if (CheckConversionsFromBool && (const auto *CastFromBool =
+  Result.Nodes.getNodeAs("implicitCastFromBool"))) {
 const auto *NextImplicitCast =
 Result.Nodes.getNodeAs("furtherImplicitCast");
 return handleCastFromBool(CastFromBool, NextImplicitCast, *Result.Context);

>From 16c7c95939b4c0c38ebccbbc6cd1da3739244a24 Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:45:37 +0530
Subject: [PATCH 2/4] Update ImplicitBoolConversionCheck.h

Added CheckConversionToBool and CheckConversionFromBool Options in the header
---
 .../clang-tidy/readability/ImplicitBoolConversionCheck.h| 2 ++
 1 file changed, 2 insertions(+)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
index 5947f7316e67cc..b0c3c2943e649c 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
@@ -37,6 +37,8 @@ class ImplicitBoolConversionCheck : public ClangTidyCheck {
   const bool AllowIntegerConditions;
   const bool AllowPointerConditions;
   const bool UseUpperCaseLiteralSuffix;
+  const bool CheckConversionsToBool;
+  const bool CheckConversionsFromBool;
 };
 
 } // namespace clang::tidy::readability

>From 0d6fae8b08a4a365c9295ac8a96de2aba9974c98 Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:48:48 +0530
Subject: [PATCH 3/4] Create implicit-bool-conversion-check.cpp

Added new test to check the new options added in the 
ImplicitBoolConversionCheck.cpp
---
 .../implicit-bool-conversion-check.cpp| 92 +++
 1 file changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp
new file mode 100644
index 00..506769d5a57322
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/reada

[clang] b4c1ded - [clang] Recover necessary AddrSpaceCast (#119246)

2024-12-17 Thread via cfe-commits

Author: Youngsuk Kim
Date: 2024-12-17T08:38:31-05:00
New Revision: b4c1ded7d54858972c27250f4b6b882e74da1444

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

LOG: [clang] Recover necessary AddrSpaceCast (#119246)

A necessary AddrSpaceCast was wrongfully deleted in
5c91b2886f6bf400b60ca7839069839ac3980f8f . Recover the AddrSpaceCast.

This fixes #86791 .

Added: 
clang/test/OpenMP/amdgpu_threadprivate.cpp

Modified: 
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 8cbd09d02c7556..cf9e338236e556 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3302,6 +3302,7 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
   CharUnits Align = CGM.getContext().getDeclAlign(VD);
   Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
 }
+Val = Builder.CreateAddrSpaceCast(Val, Wrapper->getReturnType());
 
 Builder.CreateRet(Val);
   }

diff  --git a/clang/test/OpenMP/amdgpu_threadprivate.cpp 
b/clang/test/OpenMP/amdgpu_threadprivate.cpp
new file mode 100644
index 00..f7061f42bbe7cb
--- /dev/null
+++ b/clang/test/OpenMP/amdgpu_threadprivate.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-unknown-linux-gnu -target-cpu gfx906 -fopenmp -nogpulib 
-fopenmp-is-target-device -emit-llvm %s -o - | FileCheck %s
+
+// Don't crash with assertions build.
+
+// CHECK:   @MyGlobVar = external thread_local addrspace(1) global i32, 
align 4
+// CHECK:   define weak_odr hidden noundef ptr @_ZTW9MyGlobVar() #0 comdat 
{
+// CHECK-NEXT:%1 = call align 4 ptr addrspace(1) 
@llvm.threadlocal.address.p1(ptr addrspace(1) align 4 @MyGlobVar)
+// CHECK-NEXT:%2 = addrspacecast ptr addrspace(1) %1 to ptr
+// CHECK-NEXT:ret ptr %2
+// CHECK-NEXT:  }
+int MyGlobVar;
+#pragma omp threadprivate(MyGlobVar)
+int main() {
+  MyGlobVar = 1;
+}
+



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


[clang] fbbf1be - [HLSL][NFC] Fix static analyzer concerns (#120090)

2024-12-17 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2024-12-17T14:37:48+01:00
New Revision: fbbf1bed746c335b970aee7bd135676e534ffa05

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

LOG: [HLSL][NFC] Fix static analyzer concerns (#120090)

Class BuiltinTypeMethodBuilder has a user-defined destructor so likely
compiler generated special functions may behave incorrectly. Delete
explicitly copy constructor and copy assignment operator to avoid
potential errors.

Added: 


Modified: 
clang/lib/Sema/HLSLExternalSemaSource.cpp

Removed: 




diff  --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 09fced1115687b..f3362fb619afc1 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -559,6 +559,10 @@ struct BuiltinTypeMethodBuilder {
 public:
   ~BuiltinTypeMethodBuilder() { finalizeMethod(); }
 
+  BuiltinTypeMethodBuilder(const BuiltinTypeMethodBuilder &Other) = delete;
+  BuiltinTypeMethodBuilder &
+  operator=(const BuiltinTypeMethodBuilder &Other) = delete;
+
   Expr *getResourceHandleExpr() {
 // The first statement added to a method or access to 'this' creates the
 // declaration.



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


[clang] [clang] Recover necessary AddrSpaceCast (PR #119246)

2024-12-17 Thread Youngsuk Kim via cfe-commits

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


[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-17 Thread Shilei Tian via cfe-commits


@@ -2903,7 +2903,10 @@ TargetOMPContext::TargetOMPContext(
 const FunctionDecl *CurrentFunctionDecl,
 ArrayRef ConstructTraits)
 : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice,
- ASTCtx.getTargetInfo().getTriple()),
+ ASTCtx.getTargetInfo().getTriple(),
+ ASTCtx.getLangOpts().OMPTargetTriples.empty()
+ ? llvm::Triple()
+ : ASTCtx.getLangOpts().OMPTargetTriples[0]),

shiltian wrote:

There is `--offload-arch` available to support multiple targets. Does it apply 
to host?

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


[clang] [clang] Recover necessary AddrSpaceCast (PR #119246)

2024-12-17 Thread Youngsuk Kim via cfe-commits

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


[clang] [clang] Fix dangling false positives for conditional operators. (PR #120233)

2024-12-17 Thread Haojian Wu via cfe-commits


@@ -582,6 +582,15 @@ static void visitFunctionCallArguments(IndirectLocalPath 
&Path, Expr *Call,
 //   Temp().ptr; // Here ptr might not dangle.
 if (isa(Arg->IgnoreImpCasts()))
   return;
+// Avoid false positives when the object is constructed from a conditional
+// operator argument. A common case is:
+//   // 'ptr' might not be owned by the Owner object.
+//   std::string_view s = cond() ? Owner().ptr : sv;

hokein wrote:

note: I keep the code simple here, and heuristic logic is not perfect and may 
lead to false negatives, as it filters out more cases than intended. The major 
case `std::string_view sv = cond ? "123" : std::string();` is still covered, I 
think this is a right tradeoff.

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


[clang] [llvm] [NFC][AMDGPU] Pre-commit clang and llvm tests for dynamic allocas (PR #120063)

2024-12-17 Thread via cfe-commits

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


[clang] [llvm] [NFC][AMDGPU] Pre-commit clang and llvm tests for dynamic allocas (PR #120063)

2024-12-17 Thread via cfe-commits

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


[clang] [llvm] [NFC][AMDGPU] Pre-commit clang and llvm tests for dynamic allocas (PR #120063)

2024-12-17 Thread via cfe-commits


@@ -5,8 +5,46 @@ target datalayout = "A5"
 
 ; CHECK: in function test_dynamic_stackalloc{{.*}}: unsupported dynamic alloca
 
-define amdgpu_kernel void @test_dynamic_stackalloc(ptr addrspace(1) %out, i32 
%n) {
+define amdgpu_kernel void @test_dynamic_stackalloc(i32 %n) {
   %alloca = alloca i32, i32 %n, addrspace(5)
-  store volatile i32 0, ptr addrspace(5) %alloca
+  store volatile i32 123, ptr addrspace(5) %alloca
   ret void
 }
+
+; CHECK: in function test_dynamic_stackalloc{{.*}}: unsupported dynamic alloca
+
+define amdgpu_kernel void @test_dynamic_stackalloc_multiple_allocas(i32 %n) {
+  %alloca1 = alloca i32, i32 8, addrspace(5)
+  %alloca2 = alloca i32, i32 %n, addrspace(5)
+  %alloca3 = alloca i32, i32 10, addrspace(5)
+  store volatile i32 1, ptr addrspace(5) %alloca1
+  store volatile i32 2, ptr addrspace(5) %alloca2
+  store volatile i32 3, ptr addrspace(5) %alloca3
+  ret void
+}
+
+; CHECK: in function test_dynamic_stackalloc{{.*}}: unsupported dynamic alloca
+
+define amdgpu_kernel void @test_dynamic_stackalloc_custom_alignment(i32 %n) {

easyonaadit wrote:

Noted.

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


[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-17 Thread via cfe-commits


@@ -2903,7 +2903,10 @@ TargetOMPContext::TargetOMPContext(
 const FunctionDecl *CurrentFunctionDecl,
 ArrayRef ConstructTraits)
 : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice,
- ASTCtx.getTargetInfo().getTriple()),
+ ASTCtx.getTargetInfo().getTriple(),
+ ASTCtx.getLangOpts().OMPTargetTriples.empty()
+ ? llvm::Triple()
+ : ASTCtx.getLangOpts().OMPTargetTriples[0]),

Ritanya-B-Bharadwaj wrote:

>From what I understand, the --offload-arch option is mostly for non-host 
>devices like GPUs and doesn’t apply to the host. For the host, the 
>architecture is determined by the default target triple. Since the host isn’t 
>treated as an offloading target, --offload-arch doesn’t affect its code 
>generation.

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


  1   2   3   4   5   >