[clang] [clang][analyzer] Fix StreamChecker `ftell` and `fgetpos` at indeterminate file position. (PR #84191)

2024-03-07 Thread Balázs Kéri via cfe-commits

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


[clang] d72b7f9 - [clang][analyzer] Fix StreamChecker `ftell` and `fgetpos` at indeterminate file position. (#84191)

2024-03-07 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-03-08T08:56:10+01:00
New Revision: d72b7f913300493480f78d4f23104d0f51d50b62

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

LOG: [clang][analyzer] Fix StreamChecker `ftell` and `fgetpos` at indeterminate 
file position. (#84191)

These functions should not be allowed if the file position is
indeterminate (they return the file position).
This condition is now checked, and tests are improved to check it.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
clang/test/Analysis/stream-error.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 2ec47bf55df76b..10972158f39862 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -307,64 +307,64 @@ class StreamChecker : public Checker FnTestDescriptions = {
   {{{"StreamTesterChecker_make_feof_stream"}, 1},
{nullptr,
-std::bind(::evalSetFeofFerror, _1, _2, _3, _4, 
ErrorFEof),
+std::bind(::evalSetFeofFerror, _1, _2, _3, _4, ErrorFEof,
+  false),
 0}},
   {{{"StreamTesterChecker_make_ferror_stream"}, 1},
{nullptr,
 std::bind(::evalSetFeofFerror, _1, _2, _3, _4,
-  ErrorFError),
+  ErrorFError, false),
+0}},
+  {{{"StreamTesterChecker_make_ferror_indeterminate_stream"}, 1},
+   {nullptr,
+std::bind(::evalSetFeofFerror, _1, _2, _3, _4,
+  ErrorFError, true),
 0}},
   };
 
@@ -415,8 +421,11 @@ class StreamChecker : public CheckerStreamArgNo), C,
@@ -865,11 +873,6 @@ void StreamChecker::preReadWrite(const FnDescription *Desc,
   if (!State)
 return;
 
-  if (!IsRead) {
-C.addTransition(State);
-return;
-  }
-
   SymbolRef Sym = StreamVal.getAsSymbol();
   if (Sym && State->get(Sym)) {
 const StreamState *SS = State->get(Sym);
@@ -880,6 +883,24 @@ void StreamChecker::preReadWrite(const FnDescription *Desc,
   }
 }
 
+void StreamChecker::preWrite(const FnDescription *Desc, const CallEvent ,
+ CheckerContext ) const {
+  ProgramStateRef State = C.getState();
+  SVal StreamVal = getStreamArg(Desc, Call);
+  State = ensureStreamNonNull(StreamVal, Call.getArgExpr(Desc->StreamArgNo), C,
+  State);
+  if (!State)
+return;
+  State = ensureStreamOpened(StreamVal, C, State);
+  if (!State)
+return;
+  State = ensureNoFilePositionIndeterminate(StreamVal, C, State);
+  if (!State)
+return;
+
+  C.addTransition(State);
+}
+
 void StreamChecker::evalFreadFwrite(const FnDescription *Desc,
 const CallEvent , CheckerContext ,
 bool IsFread) const {
@@ -1496,14 +1517,16 @@ void StreamChecker::preDefault(const FnDescription 
*Desc, const CallEvent ,
 
 void StreamChecker::evalSetFeofFerror(const FnDescription *Desc,
   const CallEvent , CheckerContext ,
-  const StreamErrorState ) const 
{
+  const StreamErrorState ,
+  bool Indeterminate) const {
   ProgramStateRef State = C.getState();
   SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
   assert(StreamSym && "Operation not permitted on non-symbolic stream value.");
   const StreamState *SS = State->get(StreamSym);
   assert(SS && "Stream should be tracked by the checker.");
   State = State->set(
-  StreamSym, StreamState::getOpened(SS->LastOperation, ErrorKind));
+  StreamSym,
+  StreamState::getOpened(SS->LastOperation, ErrorKind, Indeterminate));
   C.addTransition(State);
 }
 

diff  --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index ac31083bfc691f..88f7de4234ffb4 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -11,6 +11,7 @@ void clang_analyzer_dump(int);
 void clang_analyzer_warnIfReached(void);
 void StreamTesterChecker_make_feof_stream(FILE *);
 void StreamTesterChecker_make_ferror_stream(FILE *);
+void StreamTesterChecker_make_ferror_indeterminate_stream(FILE *);
 
 void error_fopen(void) {
   FILE *F = fopen("file", "r");
@@ -52,6 +53,8 @@ void stream_error_feof(void) {
   clearerr(F);
   clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
   clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  StreamTesterChecker_make_ferror_indeterminate_stream(F);
+  clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
   fclose(F);
 }
 
@@ -65,6 +68,8 @@ void stream_error_ferror(void) {
   clearerr(F);
   

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

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


@@ -840,6 +886,33 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
  "string must be lowercase");
   }
 
+  bool IsProfile = Arch.starts_with("rvi") || Arch.starts_with("rva") ||
+   Arch.starts_with("rvb") || Arch.starts_with("rvm");
+  std::string NewArch;
+  std::string ProfileName;
+  if (IsProfile) {
+const auto *FoundProfile =
+llvm::find_if(SupportedProfiles, [&](const RISCVProfile ) {
+  return Arch.starts_with(Profile.Name);
+});
+
+if (FoundProfile == adl_end(SupportedProfiles))

topperc wrote:

Can we use std::end instead of adl_end?

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


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

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


@@ -0,0 +1,189 @@
+//===-- RISCVProfiles.td - RISC-V Profiles -*- tablegen 
-*-===//
+//
+// 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
+//
+//===--===//
+
+class RISCVProfile features>

topperc wrote:

I don't think profiles need to be part of subtarget features. They should just 
be expanded to extensions in RISCVISAInfo.cpp

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


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

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


@@ -138,6 +150,8 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
   /// initializeProperties().
   RISCVProcFamilyEnum getProcFamily() const { return RISCVProcFamily; }
 
+  RISCVProfileEnum getRISCVProfile() const { return RISCVProfile; }

topperc wrote:

Were you going to remove it?

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


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

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

wangpc-pp wrote:

Ping.

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


[clang] [clang] Respect field alignment in layout compatibility of structs (PR #84313)

2024-03-07 Thread Vlad Serebrennikov via cfe-commits

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


[clang] b6a3400 - [clang] Respect field alignment in layout compatibility of structs (#84313)

2024-03-07 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-03-08T11:31:00+04:00
New Revision: b6a340023d383d1e77cb8d91d92c096f791fa8c0

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

LOG: [clang] Respect field alignment in layout compatibility of structs (#84313)

This patch implements
[CWG2586](https://cplusplus.github.io/CWG/issues/2583.html) "Common
initial sequence should consider over-alignment". Note that alignment of
union members doesn't have to match, as layout compatibility of unions
is not defined in terms of common initial sequence
(http://eel.is/c++draft/class.mem.general#25).

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaChecking.cpp
clang/test/CXX/drs/dr25xx.cpp
clang/test/SemaCXX/type-traits.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fa23c215790f11..fe7bbe437831ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -115,6 +115,10 @@ Resolutions to C++ Defect Reports
   of two types.
   (`CWG1719: Layout compatibility and cv-qualification revisited 
`_).
 
+- Alignment of members is now respected when evaluating layout compatibility
+  of structs.
+  (`CWG2583: Common initial sequence should consider over-alignment 
`_).
+
 - ``[[no_unique_address]]`` is now respected when evaluating layout
   compatibility of two types.
   (`CWG2759: [[no_unique_address] and common initial sequence  
`_).

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3597f93a017136..b34b8df0020137 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -19184,8 +19184,22 @@ static bool isLayoutCompatible(ASTContext , EnumDecl 
*ED1, EnumDecl *ED2) {
 }
 
 /// Check if two fields are layout-compatible.
+/// Can be used on union members, which are exempt from alignment requirement
+/// of common initial sequence.
 static bool isLayoutCompatible(ASTContext , FieldDecl *Field1,
-   FieldDecl *Field2) {
+   FieldDecl *Field2,
+   bool AreUnionMembers = false) {
+  const Type *Field1Parent = Field1->getParent()->getTypeForDecl();
+  const Type *Field2Parent = Field2->getParent()->getTypeForDecl();
+  assert(((Field1Parent->isStructureOrClassType() &&
+   Field2Parent->isStructureOrClassType()) ||
+  (Field1Parent->isUnionType() && Field2Parent->isUnionType())) &&
+ "Can't evaluate layout compatibility between a struct field and a "
+ "union field.");
+  assert(((!AreUnionMembers && Field1Parent->isStructureOrClassType()) ||
+  (AreUnionMembers && Field1Parent->isUnionType())) &&
+ "AreUnionMembers should be 'true' for union fields (only).");
+
   if (!isLayoutCompatible(C, Field1->getType(), Field2->getType()))
 return false;
 
@@ -19204,6 +19218,11 @@ static bool isLayoutCompatible(ASTContext , 
FieldDecl *Field1,
   if (Field1->hasAttr() ||
   Field2->hasAttr())
 return false;
+
+  if (!AreUnionMembers &&
+  Field1->getMaxAlignment() != Field2->getMaxAlignment())
+return false;
+
   return true;
 }
 
@@ -19265,7 +19284,7 @@ static bool isLayoutCompatibleUnion(ASTContext , 
RecordDecl *RD1,
 E = UnmatchedFields.end();
 
 for ( ; I != E; ++I) {
-  if (isLayoutCompatible(C, Field1, *I)) {
+  if (isLayoutCompatible(C, Field1, *I, /*IsUnionMember=*/true)) {
 bool Result = UnmatchedFields.erase(*I);
 (void) Result;
 assert(Result);

diff  --git a/clang/test/CXX/drs/dr25xx.cpp b/clang/test/CXX/drs/dr25xx.cpp
index 9fc7cf59485caa..46532486e50e53 100644
--- a/clang/test/CXX/drs/dr25xx.cpp
+++ b/clang/test/CXX/drs/dr25xx.cpp
@@ -211,6 +211,32 @@ namespace dr2565 { // dr2565: 16 open 2023-06-07
 #endif
 }
 
+namespace dr2583 { // dr2583: 19
+#if __cplusplus >= 201103L
+struct A {
+  int i;
+  char c;
+};
+
+struct B {
+  int i;
+  alignas(8) char c;
+};
+
+union U {
+  A a;
+  B b;
+};
+
+union V {
+  A a;
+  alignas(64) B b;
+};
+
+static_assert(!__is_layout_compatible(A, B), "");
+static_assert(__is_layout_compatible(U, V), "");
+#endif
+} // namespace dr2583
 
 namespace dr2598 { // dr2598: 18
 #if __cplusplus >= 201103L

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 23c339ebdf0826..831de2589dcb9e 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1681,6 +1681,16 @@ union UnionLayout3 {
   [[no_unique_address]] CEmptyStruct d;
 };
 
+union UnionNoOveralignedMembers {
+  int a;
+  

[clang] [Clang][Sema] Allow access to a public template alias declaration that refers to friend's private nested type (PR #83847)

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

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

>From a38ad9098c7f4dcffaa22b269bc2a36b5eb0fc4e Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Mon, 4 Mar 2024 21:51:07 +0800
Subject: [PATCH] [Clang][Sema] Allow access to a public template alias
 declaration that refers to friend's private nested type

---
 clang/docs/ReleaseNotes.rst |  3 +++
 clang/lib/Sema/SemaAccess.cpp   |  6 ++
 clang/test/SemaTemplate/PR25708.cpp | 23 +++
 3 files changed, 32 insertions(+)
 create mode 100644 clang/test/SemaTemplate/PR25708.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8300a8484585ae..945a21f61abc61 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -239,6 +239,9 @@ Bug Fixes in This Version
   for variables created through copy initialization having side-effects in 
C++17 and later.
   Fixes (#GH64356) (#GH79518).
 
+- Allow access to a public template alias declaration that refers to friend's
+  private nested type (`#25708 
`).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 4af3c0f30a8e8a..ab4580b39a3ae8 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -1481,6 +1481,12 @@ static Sema::AccessResult CheckAccess(Sema , 
SourceLocation Loc,
   }
 
   EffectiveContext EC(S.CurContext);
+  auto  = S.CodeSynthesisContexts.back();
+  if (Active.Entity)
+if (auto *RD =
+dyn_cast_or_null(Active.Entity->getDeclContext()))
+  EC.Records.push_back(RD);
+
   switch (CheckEffectiveAccess(S, EC, Loc, Entity)) {
   case AR_accessible: return Sema::AR_accessible;
   case AR_inaccessible: return Sema::AR_inaccessible;
diff --git a/clang/test/SemaTemplate/PR25708.cpp 
b/clang/test/SemaTemplate/PR25708.cpp
new file mode 100644
index 00..cc2e7551a6abaa
--- /dev/null
+++ b/clang/test/SemaTemplate/PR25708.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// RUN: %clang_cc1 -std=c++14 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+struct FooAccessor
+{
+template 
+using Foo = typename T::Foo;
+};
+
+class Type
+{
+friend struct FooAccessor;
+
+using Foo = int;
+};
+
+int main()
+{
+FooAccessor::Foo t;
+}

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


[clang] [clang][dataflow] Add context-sensitive test for returning a record by value. (PR #84317)

2024-03-07 Thread via cfe-commits

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


[clang] 9b74c43 - [clang][dataflow] Add context-sensitive test for returning a record by value. (#84317)

2024-03-07 Thread via cfe-commits

Author: martinboehme
Date: 2024-03-08T08:19:41+01:00
New Revision: 9b74c43d70f4b39d6fea7b542d77f2b652e4d651

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

LOG: [clang][dataflow] Add context-sensitive test for returning a record by 
value. (#84317)

I'm making some changes to `Environment::getResultObjectLocation()`,
with the
ultimate goal of eliminating `RecordValue` entirely, and I'd like to
make sure
I don't break this behavior (and I've realized we don't have a test for
it yet).

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 9fde4179db1c49..a8c282f140b4cd 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5735,6 +5735,39 @@ TEST(TransferTest, ContextSensitiveReturnInt) {
   {BuiltinOptions{ContextSensitiveOptions{}}});
 }
 
+TEST(TransferTest, ContextSensitiveReturnRecord) {
+  std::string Code = R"(
+struct S {
+  bool B;
+};
+
+S makeS(bool BVal) { return {BVal}; }
+
+void target() {
+  S FalseS = makeS(false);
+  S TrueS = makeS(true);
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+
+auto  =
+getLocForDecl(ASTCtx, Env, "FalseS");
+auto  =
+getLocForDecl(ASTCtx, Env, "TrueS");
+
+EXPECT_EQ(getFieldValue(, "B", ASTCtx, Env),
+  (false));
+EXPECT_EQ(getFieldValue(, "B", ASTCtx, Env),
+  (true));
+  },
+  {BuiltinOptions{ContextSensitiveOptions{}}});
+}
+
 TEST(TransferTest, ContextSensitiveMethodLiteral) {
   std::string Code = R"(
 class MyClass {



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


[clang] [clang][dataflow] When analyzing ctors, don't initialize fields of `*this` with values. (PR #84164)

2024-03-07 Thread via cfe-commits

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


[clang] 2d539db - [clang][dataflow] When analyzing ctors, don't initialize fields of `*this` with values. (#84164)

2024-03-07 Thread via cfe-commits

Author: martinboehme
Date: 2024-03-08T08:19:02+01:00
New Revision: 2d539db246fd9d26201255b84d04dacf2782eddf

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

LOG: [clang][dataflow] When analyzing ctors, don't initialize fields of `*this` 
with values. (#84164)

This is the constructor's job, and we want to be able to test that it
does this.

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index e8f009ef6c7913..2330697299fdd7 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -445,6 +445,11 @@ class Environment {
 return createObjectInternal(, D.getType(), InitExpr);
   }
 
+  /// Initializes the fields (including synthetic fields) of `Loc` with values,
+  /// unless values of the field type are not supported or we hit one of the
+  /// limits at which we stop producing values.
+  void initializeFieldsWithValues(RecordStorageLocation );
+
   /// Assigns `Val` as the value of `Loc` in the environment.
   void setValue(const StorageLocation , Value );
 

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 62332a18c44a4a..1d2bd9a9b08af3 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -432,8 +432,15 @@ void Environment::initialize() {
   }
 } else if (MethodDecl->isImplicitObjectMemberFunction()) {
   QualType ThisPointeeType = MethodDecl->getFunctionObjectParameterType();
-  setThisPointeeStorageLocation(
-  cast(createObject(ThisPointeeType)));
+  auto  =
+  cast(createStorageLocation(ThisPointeeType));
+  setThisPointeeStorageLocation(ThisLoc);
+  refreshRecordValue(ThisLoc, *this);
+  // Initialize fields of `*this` with values, but only if we're not
+  // analyzing a constructor; after all, it's the constructor's job to do
+  // this (and we want to be able to test that).
+  if (!isa(MethodDecl))
+initializeFieldsWithValues(ThisLoc);
 }
   }
 }
@@ -819,6 +826,16 @@ PointerValue 
::getOrCreateNullPointerValue(QualType PointeeType) {
   return DACtx->getOrCreateNullPointerValue(PointeeType);
 }
 
+void Environment::initializeFieldsWithValues(RecordStorageLocation ) {
+  llvm::DenseSet Visited;
+  int CreatedValuesCount = 0;
+  initializeFieldsWithValues(Loc, Visited, 0, CreatedValuesCount);
+  if (CreatedValuesCount > MaxCompositeValueSize) {
+llvm::errs() << "Attempting to initialize a huge value of type: "
+ << Loc.getType() << '\n';
+  }
+}
+
 void Environment::setValue(const StorageLocation , Value ) {
   assert(!isa() || ()->getLoc() == 
);
 

diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index a9f39e153d0ce1..939247c047c66e 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -406,7 +406,6 @@ builtinTransferInitializer(const CFGInitializer ,
 }
   }
   assert(Member != nullptr);
-  assert(MemberLoc != nullptr);
 
   // FIXME: Instead of these case distinctions, we would ideally want to be 
able
   // to simply use `Environment::createObject()` here, the same way that we do
@@ -422,6 +421,7 @@ builtinTransferInitializer(const CFGInitializer ,
 
 ParentLoc->setChild(*Member, InitExprLoc);
   } else if (auto *InitExprVal = Env.getValue(*InitExpr)) {
+assert(MemberLoc != nullptr);
 if (Member->getType()->isRecordType()) {
   auto *InitValStruct = cast(InitExprVal);
   // FIXME: Rather than performing a copy here, we should really be

diff  --git a/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp 
b/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
index 09f5524e152c9f..5c4d42c6ccdcf8 100644
--- a/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
@@ -179,7 +179,10 @@ llvm::Error test::checkDataflowWithNoopAnalysis(
   // -fnodelayed-template-parsing is the default everywhere but on Windows.
   // Set it explicitly so that tests behave the same on Windows as on 

[clang-tools-extra] [clang-tidy]avoid bugprone-unused-return-value false positive for function with the same prefix as the default argument (PR #84333)

2024-03-07 Thread Congcong Cai via cfe-commits

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

>From aaa9ea1db21b5de5d8be454ce1b1d05b219cccfc Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 7 Mar 2024 23:28:40 +0800
Subject: [PATCH 1/2] [clang-tidy]avoid bugprone-unused-return-value false
 negative for function with the same prefix as the default argument

string without `$` end will cause incorrectly match results.
Fixes: #84314.
---
 .../bugprone/UnusedReturnValueCheck.cpp   | 184 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |   4 +-
 .../checkers/bugprone/unused-return-value.cpp |  14 ++
 3 files changed, 109 insertions(+), 93 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index b4bf85c912c3ca..1252b2f23805a1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -34,102 +34,102 @@ 
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   CheckedFunctions(utils::options::parseStringList(
-  Options.get("CheckedFunctions", "::std::async;"
-  "::std::launder;"
-  "::std::remove;"
-  "::std::remove_if;"
-  "::std::unique;"
-  "::std::unique_ptr::release;"
-  "::std::basic_string::empty;"
-  "::std::vector::empty;"
-  "::std::back_inserter;"
-  "::std::distance;"
-  "::std::find;"
-  "::std::find_if;"
-  "::std::inserter;"
-  "::std::lower_bound;"
-  "::std::make_pair;"
-  "::std::map::count;"
-  "::std::map::find;"
-  "::std::map::lower_bound;"
-  "::std::multimap::equal_range;"
-  "::std::multimap::upper_bound;"
-  "::std::set::count;"
-  "::std::set::find;"
-  "::std::setfill;"
-  "::std::setprecision;"
-  "::std::setw;"
-  "::std::upper_bound;"
-  "::std::vector::at;"
+  Options.get("CheckedFunctions", "::std::async$;"
+  "::std::launder$;"
+  "::std::remove$;"
+  "::std::remove_if$;"
+  "::std::unique$;"
+  "::std::unique_ptr::release$;"
+  "::std::basic_string::empty$;"
+  "::std::vector::empty$;"
+  "::std::back_inserter$;"
+  "::std::distance$;"
+  "::std::find$;"
+  "::std::find_if$;"
+  "::std::inserter$;"
+  "::std::lower_bound$;"
+  "::std::make_pair$;"
+  "::std::map::count$;"
+  "::std::map::find$;"
+  "::std::map::lower_bound$;"
+  "::std::multimap::equal_range$;"
+  "::std::multimap::upper_bound$;"
+  "::std::set::count$;"
+  "::std::set::find$;"
+  "::std::setfill$;"
+  "::std::setprecision$;"
+  "::std::setw$;"
+  "::std::upper_bound$;"
+  "::std::vector::at$;"
   // C standard library
-  "::bsearch;"
-  "::ferror;"
- 

[clang] [alpha.webkit.UncountedCallArgsChecker] Don't assume local variables are safe & treat guarded local variable as safe function arguments (PR #82305)

2024-03-07 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

haha, sorry for the confusion. I don't have any outstanding PR at this point. 
Thanks for all the reviews :)

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Don't assume local variables are safe & treat guarded local variable as safe function arguments (PR #82305)

2024-03-07 Thread Artem Dergachev via cfe-commits

haoNoQ wrote:

I just thought two PRs, accepted 1, then there were 0 left, and I was confused 
 

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Don't assume local variables are safe & treat guarded local variable as safe function arguments (PR #82305)

2024-03-07 Thread Artem Dergachev via cfe-commits

haoNoQ wrote:

Oh right right right, so it's closed without committing, nvm then!

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Don't assume local variables are safe & treat guarded local variable as safe function arguments (PR #82305)

2024-03-07 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

So this PR turned out to be not really correct because we can't get rid of 
local variable checker when calling a non-trivial function.

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


[clang] [HIP] Make the HIP default architecture use the enum value (PR #84400)

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

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


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


[clang] [llvm] ADT] Add implementations for avgFloor and ceilFloor to APInt (PR #84427)

2024-03-07 Thread Atousa Duprat via cfe-commits

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


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

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

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


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

2024-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Kees Cook (kees)


Changes

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

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

For example, these do not error by default:

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

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

But this does:

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

Add -fflex-array-extensions so that C99 flexible array members can be fully 
supported in these scenarios without errors, allowing for a seamless transition 
for code bases away from 0-sized arrays without losing existing code patterns.

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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+6) 
- (modified) clang/include/clang/Basic/LangOptions.def (+1) 
- (modified) clang/include/clang/Driver/Options.td (+5) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+10-9) 
- (added) clang/test/Sema/flex-array-extensions.c (+43) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1b901a27fd19d1..c15ff98c60b8b2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -164,6 +164,12 @@ New Compiler Flags
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
   like it did before Clang 18.x. Fixes (`#56628 
`_)
 
+- ``-fflex-array-extensions``. Allows for the use of extensions to flexible 
array members
+  syntax so they can be directly used in unions and alone in structs. This 
construction is
+  already fully supported by Clang under certain conditions, so this provide 
support for
+  codebases that would otherwise not be able to migrate from 0-sized "fake" 
flexible array
+  members to C99 flexible array members.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 2b42b521a30363..c5c810f63d93d1 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -453,6 +453,7 @@ LANGOPT(MatrixTypes, 1, 0, "Enable or disable the builtin 
matrix type")
 ENUM_LANGOPT(StrictFlexArraysLevel, StrictFlexArraysLevelKind, 2,
  StrictFlexArraysLevelKind::Default,
  "Rely on strict definition of flexible arrays")
+COMPATIBLE_LANGOPT(FlexArrayExtensions, 1, 0, "Enable flexible array 
extensions")
 
 COMPATIBLE_VALUE_LANGOPT(MaxTokens, 32, 0, "Max number of tokens per TU or 0")
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..bde7ba456fd27d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2819,6 +2819,11 @@ defm fine_grained_bitfield_accesses : BoolOption<"f", 
"fine-grained-bitfield-acc
   BothFlags<[], [ClangOption, CC1Option]>>,
   Group;
 
+def fflex_array_extensions : Flag<["-"], "fflex-array-extensions">, 
Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Enable flexible array extensions from GNU and MSVC">,
+  MarshallingInfoFlag>;
+
 def fexperimental_relative_cxx_abi_vtables :
   Flag<["-"], "fexperimental-relative-c++-abi-vtables">,
   Group, Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index fa17f6295d6ea7..356129b452514b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6663,6 +6663,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   options::OPT_fno_unroll_loops);
 
   Args.AddLastArg(CmdArgs, options::OPT_fstrict_flex_arrays_EQ);
+  Args.AddLastArg(CmdArgs, options::OPT_fflex_array_extensions);
 
   Args.AddLastArg(CmdArgs, options::OPT_pthread);
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 67e56a917a51de..1fd6200d4876e4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19355,17 +19355,18 @@ void Sema::ActOnFields(Scope *S, SourceLocation 
RecLoc, Decl *EnclosingDecl,
   EnclosingDecl->setInvalidDecl();
   continue;
 } else if (Record->isUnion())
-  DiagID = 

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

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

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

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

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

For example, these do not error by default:

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

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

But this does:

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

Add -fflex-array-extensions so that C99 flexible array members can be fully 
supported in these scenarios without errors, allowing for a seamless transition 
for code bases away from 0-sized arrays without losing existing code patterns.

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

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

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

For example, these do not error by default:

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

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

But this does:

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

Add -fflex-array-extensions so that C99 flexible array members can
be fully supported in these scenarios without errors, allowing for a
seamless transition for code bases away from 0-sized arrays without
losing existing code patterns.
---
 clang/docs/ReleaseNotes.rst   |  6 
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/include/clang/Driver/Options.td |  5 +++
 clang/lib/Driver/ToolChains/Clang.cpp |  1 +
 clang/lib/Sema/SemaDecl.cpp   | 19 +-
 clang/test/Sema/flex-array-extensions.c   | 43 +++
 6 files changed, 66 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/Sema/flex-array-extensions.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1b901a27fd19d1..c15ff98c60b8b2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -164,6 +164,12 @@ New Compiler Flags
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
   like it did before Clang 18.x. Fixes (`#56628 
`_)
 
+- ``-fflex-array-extensions``. Allows for the use of extensions to flexible 
array members
+  syntax so they can be directly used in unions and alone in structs. This 
construction is
+  already fully supported by Clang under certain conditions, so this provide 
support for
+  codebases that would otherwise not be able to migrate from 0-sized "fake" 
flexible array
+  members to C99 flexible array members.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 2b42b521a30363..c5c810f63d93d1 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -453,6 +453,7 @@ LANGOPT(MatrixTypes, 1, 0, "Enable or disable the builtin 
matrix type")
 ENUM_LANGOPT(StrictFlexArraysLevel, StrictFlexArraysLevelKind, 2,
  StrictFlexArraysLevelKind::Default,
  "Rely on strict definition of flexible arrays")
+COMPATIBLE_LANGOPT(FlexArrayExtensions, 1, 0, "Enable flexible array 
extensions")
 
 COMPATIBLE_VALUE_LANGOPT(MaxTokens, 32, 0, "Max number of tokens per TU or 0")
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..bde7ba456fd27d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2819,6 +2819,11 @@ defm fine_grained_bitfield_accesses : BoolOption<"f", 

[clang] [llvm] ADT] Add implementations for avgFloor and ceilFloor to APInt (PR #84427)

2024-03-07 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa created 
https://github.com/llvm/llvm-project/pull/84427

Supports both signed and unsigned expansions.
SelectionDAG now calls the APInt implementation of these functions.

>From ac75fc2873fc7b8eec6c24ba97f4673e94457c8e Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH 1/8] [clang] Use separator for large numeric values in
 overflow diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp  |   6 +-
 clang/test/AST/Interp/c.c   |   4 +-
 clang/test/C/drs/dr0xx.c|   2 +-
 clang/test/C/drs/dr2xx.c|   2 +-
 clang/test/Sema/integer-overflow.c  | 100 -
 clang/test/Sema/switch-1.c  |   6 +-
 clang/test/SemaCXX/enum.cpp |   4 +-
 clang/test/SemaCXX/integer-overflow.cpp | 112 ++--
 clang/test/SemaObjC/integer-overflow.m  |   4 +-
 clang/test/SemaObjC/objc-literal-nsnumber.m |   2 +-
 llvm/include/llvm/ADT/APInt.h   |   3 +-
 llvm/include/llvm/ADT/StringExtras.h|   5 +-
 llvm/lib/Support/APInt.cpp  |  24 -
 llvm/unittests/ADT/APIntTest.cpp|  35 ++
 14 files changed, 185 insertions(+), 124 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..d9037072c6767f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo , const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
@@ -13852,7 +13853,8 @@ bool IntExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   if (Info.checkingForUndefinedBehavior())
 Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
  diag::warn_integer_constant_overflow)
-<< toString(Value, 10) << E->getType() << E->getSourceRange();
+<< toString(Value, 10, Value.isSigned(), false, true, true)
+<< E->getType() << E->getSourceRange();
 
   if (!HandleOverflow(Info, E, -Value.extend(Value.getBitWidth() + 1),
   E->getType()))
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 9ab271a82aeef9..aa067b0bc74831 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -109,9 +109,9 @@ int somefunc(int i) {
  // pedantic-expected-warning {{left operand of 
comma operator has no effect}} \
  // pedantic-expected-warning {{overflow in 
expression; result is 131073}} \
  // ref-warning {{left operand of comma operator 
has no effect}} \
- // ref-warning {{overflow in expression; result 
is 131073}} \
+ // ref-warning {{overflow in expression; result 
is 131'073}} \
  // pedantic-ref-warning {{left operand of comma 
operator has no effect}} \
- // pedantic-ref-warning {{overflow in expression; 
result is 131073}}
+ // pedantic-ref-warning {{overflow in expression; 
result is 131'073}}
 
 }
 
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index d9c1fbe4ee40ab..c93cfb63d604cf 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -214,7 +214,7 @@ _Static_assert(__builtin_types_compatible_p(struct S { int 
a; }, union U { int a
  */
 void dr031(int i) {
   switch (i) {
-  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   #pragma clang diagnostic push
   #pragma clang diagnostic ignored "-Wswitch"
   /* Silence the targets which issue:
diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 9c8d77518ab55e..1b68b65acca6af 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -277,7 +277,7 @@ void dr258(void) {
 void dr261(void) {
   /* This is still an integer constant expression despite the overflow. */
   enum e1 {
-ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow 

[clang] [alpha.webkit.UncountedCallArgsChecker] Don't assume local variables are safe & treat guarded local variable as safe function arguments (PR #82305)

2024-03-07 Thread Artem Dergachev via cfe-commits


@@ -27,6 +28,13 @@ tryToFindPtrOrigin(const Expr *E, bool 
StopAtFirstRefCountedObj) {
   E = tempExpr->getSubExpr();
   continue;
 }
+if (auto *DRE = dyn_cast(E)) {
+  auto *decl = DRE->getFoundDecl();

haoNoQ wrote:

Is this really better than `getDecl()`? For variables I don't think there could 
be many of those, and even if there are, it's probably easier to deal with the 
default one.

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Don't assume local variables are safe & treat guarded local variable as safe function arguments (PR #82305)

2024-03-07 Thread Artem Dergachev via cfe-commits

https://github.com/haoNoQ commented:

Hi, looks like I never got to properly review this one! I don't have major 
objections but I have some things to consider fixing in follow-up patches.

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Don't assume local variables are safe & treat guarded local variable as safe function arguments (PR #82305)

2024-03-07 Thread Artem Dergachev via cfe-commits


@@ -95,11 +103,136 @@ tryToFindPtrOrigin(const Expr *E, bool 
StopAtFirstRefCountedObj) {
   return {E, false};
 }
 
+bool isGuardedScopeEmbeddedInGuardianScope(const VarDecl *Guarded,
+   const VarDecl *MaybeGuardian) {
+  assert(Guarded);
+  assert(MaybeGuardian);
+
+  if (!MaybeGuardian->isLocalVarDecl())
+return false;
+
+  const CompoundStmt *guardiansClosestCompStmtAncestor = nullptr;
+
+  ASTContext  = MaybeGuardian->getASTContext();
+
+  for (DynTypedNodeList guardianAncestors = ctx.getParents(*MaybeGuardian);

haoNoQ wrote:

I haven't spent nearly enough time in such code but I suspect that instead of 
dealing with `Stmt`s, you should be dealing with `DeclContext`s. Decl contexts 
represent all the places where something can potentially be declared. Unlike 
statements, decl contexts naturally have parent pointers (so you don't have to 
invoke the Parent Map), and they should get you straight to the point without 
figuring out how many statements of which kind do you need to skip.

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Don't assume local variables are safe & treat guarded local variable as safe function arguments (PR #82305)

2024-03-07 Thread Artem Dergachev via cfe-commits

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


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

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


@@ -226,6 +226,47 @@ HLSLToolChain::TranslateArgs(const DerivedArgList , 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
+  // Translate -HV into -std for llvm
+  // depending on the value given
+  llvm::StringRef value(A->getValue());
+  llvm::StringRef acceptedValues(
+  Opts.getOptionValues(options::OPT_dxc_hlsl_version));
+  llvm::SmallVector validValues;
+  acceptedValues.split(validValues, ", ");
+  if (value == validValues[0]) {

python3kgae wrote:

Why not just check value == "2016" here so we don't need to getOptionValues?
And the code will be easier to understand.

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


[clang] [Driver,BareMetal] Replace -lclang_rt.builtins{,-$arch}.a with an absolute path (PR #82424)

2024-03-07 Thread Petr Hosek via cfe-commits

petrhosek wrote:

I agree with @MaskRay that prior to this change the BareMetal driver was using 
a logic that was inconsistent with all other drivers and not something we 
intend to support. The correct solution is to extend the BareMetal driver to 
support `multilib.yaml` for Clang runtime libraries; this includes not only 
compiler-rt builtins but also LLVM libc and libc++.

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


[clang] [Offload] Move HIP and CUDA to new driver by default (PR #84420)

2024-03-07 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> > > There are many `--no-offload-new-driver` test changes. They can be 
> > > pre-committed to make this default flip modify fewer files.
> > 
> > 
> > I think it's much easier to keep these in a single patch, both for writing 
> > and with any potential reverting that it may require.
> 
> Since llvm is moving rapidly, reverting a commit that modifies many tests is 
> quite risky, since these tests could have been modified by other changes or 
> just cause merge conflicts for others. I assume that the merit of this patch 
> is obvious (a new feature is in development for quite some time, then it 
> matures and replaces the old feature), so adding `--no-offload-new-driver` 
> (to mark "these tests are old, please update them when the new default has 
> been stable for a while") is non-contentious. Pre-committing the test (which 
> is not risky at all) would make this default flip patch much safer to land or 
> revert.
> 
> If you think showing the difference is important, you can add to the 
> description the test commits.

I'll try to pull out the files that are purely keeping the old behavior, since 
it'll be a no-op without this patch.

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


[clang] [Headers][X86] Add specific results to comparisons (PR #83316)

2024-03-07 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 updated 
https://github.com/llvm/llvm-project/pull/83316

>From 2afca3e91d96cc77f43556bbf71b6e60a22e45f2 Mon Sep 17 00:00:00 2001
From: Paul Robinson 
Date: Wed, 28 Feb 2024 11:04:41 -0800
Subject: [PATCH 1/3] [Headers][X86] Add specific results to comparisons

Comparison intrinsics were described as returning the "result" without
specifying how. The "cmp" intrinsics return zero or all 1's in the
corresponding elements of a returned vector; the "com" intrinsics return
an integer 0 or 1.

Also removed some redundant information.
---
 clang/lib/Headers/smmintrin.h |   6 +-
 clang/lib/Headers/xmmintrin.h | 146 +++---
 2 files changed, 85 insertions(+), 67 deletions(-)

diff --git a/clang/lib/Headers/smmintrin.h b/clang/lib/Headers/smmintrin.h
index 005d7db9c3c308..ba593835b9b3dc 100644
--- a/clang/lib/Headers/smmintrin.h
+++ b/clang/lib/Headers/smmintrin.h
@@ -1186,7 +1186,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_testnzc_si128(__m128i __M,
 
 /* SSE4 64-bit Packed Integer Comparisons.  */
 /// Compares each of the corresponding 64-bit values of the 128-bit
-///integer vectors for equality.
+///integer vectors for equality. Returns zero for false and all 1's for
+///true in corresponding elements of the result.
 ///
 /// \headerfile 
 ///
@@ -2303,7 +2304,8 @@ static __inline__ __m128i __DEFAULT_FN_ATTRS 
_mm_minpos_epu16(__m128i __V) {
 /* SSE4.2 Compare Packed Data -- Greater Than.  */
 /// Compares each of the corresponding 64-bit values of the 128-bit
 ///integer vectors to determine if the values in the first operand are
-///greater than those in the second operand.
+///greater than those in the second operand. Returns zero for false and
+///all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile 
 ///
diff --git a/clang/lib/Headers/xmmintrin.h b/clang/lib/Headers/xmmintrin.h
index 47368f3c23d2d6..d8ad5ae526a45f 100644
--- a/clang/lib/Headers/xmmintrin.h
+++ b/clang/lib/Headers/xmmintrin.h
@@ -474,8 +474,8 @@ _mm_xor_ps(__m128 __a, __m128 __b)
 }
 
 /// Compares two 32-bit float values in the low-order bits of both
-///operands for equality and returns the result of the comparison in the
-///low-order bits of a vector [4 x float].
+///operands for equality and returns the result of the comparison (zero for
+///false, all 1's for true) in the low-order bits of a vector [4 x float].
 ///
 /// \headerfile 
 ///
@@ -496,7 +496,8 @@ _mm_cmpeq_ss(__m128 __a, __m128 __b)
 }
 
 /// Compares each of the corresponding 32-bit float values of the
-///128-bit vectors of [4 x float] for equality.
+///128-bit vectors of [4 x float] for equality. Returns zero for false and
+///all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile 
 ///
@@ -516,7 +517,8 @@ _mm_cmpeq_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///operands to determine if the value in the first operand is less than the
 ///corresponding value in the second operand and returns the result of the
-///comparison in the low-order bits of a vector of [4 x float].
+///comparison (zero for false, all 1's for true) in the low-order bits of a
+///vector of [4 x float].
 ///
 /// \headerfile 
 ///
@@ -538,7 +540,8 @@ _mm_cmplt_ss(__m128 __a, __m128 __b)
 
 /// Compares each of the corresponding 32-bit float values of the
 ///128-bit vectors of [4 x float] to determine if the values in the first
-///operand are less than those in the second operand.
+///operand are less than those in the second operand. Returns zero for
+///false and all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile 
 ///
@@ -558,8 +561,8 @@ _mm_cmplt_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///operands to determine if the value in the first operand is less than or
 ///equal to the corresponding value in the second operand and returns the
-///result of the comparison in the low-order bits of a vector of
-///[4 x float].
+///result of the comparison (zero for false, all 1's for true) in the
+///low-order bits of a vector of [4 x float].
 ///
 /// \headerfile 
 ///
@@ -581,7 +584,9 @@ _mm_cmple_ss(__m128 __a, __m128 __b)
 
 /// Compares each of the corresponding 32-bit float values of the
 ///128-bit vectors of [4 x float] to determine if the values in the first
-///operand are less than or equal to those in the second operand.
+///operand are less than or equal to those in the second operand. Returns
+///zero for false and all 1's for true in corresponding elements of the
+///result.
 ///
 /// \headerfile 
 ///
@@ -601,7 +606,8 @@ _mm_cmple_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///operands to determine if the value in the first operand is greater than
 ///

[clang] [Headers][X86] Add specific results to comparisons (PR #83316)

2024-03-07 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 b334664f9f3a098b6f3fd9cfd17b856a9edfe446 
1d691620a0ef9632d85e4691dc644352d4abf2b2 -- clang/lib/Headers/emmintrin.h 
clang/lib/Headers/smmintrin.h clang/lib/Headers/xmmintrin.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 43ec61bbe8..f3e6843b93 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -1093,8 +1093,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_comineq_sd(__m128d __a,
 /// Compares the lower double-precision floating-point values in each of
 ///the two 128-bit floating-point vectors of [2 x double] for equality.
 ///
-///The comparison returns 0 for false, 1 for true. If either of the two 
lower
-///double-precision values is NaN, returns 0.
+///The comparison returns 0 for false, 1 for true. If either of the two
+///lower double-precision values is NaN, returns 0.
 ///
 /// \headerfile 
 ///
@@ -1117,8 +1117,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_ucomieq_sd(__m128d __a,
 ///the value in the first parameter is less than the corresponding value in
 ///the second parameter.
 ///
-///The comparison returns 0 for false, 1 for true. If either of the two 
lower
-///double-precision values is NaN, returns 0.
+///The comparison returns 0 for false, 1 for true. If either of the two
+///lower double-precision values is NaN, returns 0.
 ///
 /// \headerfile 
 ///
@@ -1141,8 +1141,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_ucomilt_sd(__m128d __a,
 ///the value in the first parameter is less than or equal to the
 ///corresponding value in the second parameter.
 ///
-///The comparison returns 0 for false, 1 for true. If either of the two 
lower
-///double-precision values is NaN, returns 0.
+///The comparison returns 0 for false, 1 for true. If either of the two
+///lower double-precision values is NaN, returns 0.
 ///
 /// \headerfile 
 ///
@@ -1165,8 +1165,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_ucomile_sd(__m128d __a,
 ///the value in the first parameter is greater than the corresponding value
 ///in the second parameter.
 ///
-///The comparison returns 0 for false, 1 for true. If either of the two 
lower
-///double-precision values is NaN, returns 0.
+///The comparison returns 0 for false, 1 for true. If either of the two
+///lower double-precision values is NaN, returns 0.
 ///
 /// \headerfile 
 ///
@@ -1213,8 +1213,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_ucomige_sd(__m128d __a,
 ///the value in the first parameter is unequal to the corresponding value 
in
 ///the second parameter.
 ///
-///The comparison returns 0 for false, 1 for true. If either of the two 
lower
-///double-precision values is NaN, 1 is returned.
+///The comparison returns 0 for false, 1 for true. If either of the two
+///lower double-precision values is NaN, 1 is returned.
 ///
 /// \headerfile 
 ///
diff --git a/clang/lib/Headers/xmmintrin.h b/clang/lib/Headers/xmmintrin.h
index 5151ff6a45..ae7529c129 100644
--- a/clang/lib/Headers/xmmintrin.h
+++ b/clang/lib/Headers/xmmintrin.h
@@ -1046,8 +1046,8 @@ _mm_cmpunord_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///operands for equality.
 ///
-///The comparison returns 0 for false, 1 for true. If either of the two 
lower
-///floating-point values is NaN, returns 0.
+///The comparison returns 0 for false, 1 for true. If either of the two
+///lower floating-point values is NaN, returns 0.
 ///
 /// \headerfile 
 ///
@@ -1071,8 +1071,8 @@ _mm_comieq_ss(__m128 __a, __m128 __b)
 ///operands to determine if the first operand is less than the second
 ///operand.
 ///
-///The comparison returns 0 for false, 1 for true. If either of the two 
lower
-///floating-point values is NaN, returns 0.
+///The comparison returns 0 for false, 1 for true. If either of the two
+///lower floating-point values is NaN, returns 0.
 ///
 /// \headerfile 
 ///
@@ -1096,8 +1096,8 @@ _mm_comilt_ss(__m128 __a, __m128 __b)
 ///operands to determine if the first operand is less than or equal to the
 ///second operand.
 ///
-///The comparison returns 0 for false, 1 for true. If either of the two 
lower
-///floating-point values is NaN, returns 0.
+///The comparison returns 0 for false, 1 for true. If either of the two
+///lower floating-point values is NaN, returns 0.
 ///
 /// \headerfile 
 ///
@@ -1120,8 +1120,8 @@ _mm_comile_ss(__m128 __a, __m128 __b)
 ///operands to determine if the first operand is greater than the second
 ///operand.
 ///
-///The comparison returns 0 for false, 1 for 

[clang] [Headers][X86] Add specific results to comparisons (PR #83316)

2024-03-07 Thread Paul T Robinson via cfe-commits

pogo59 wrote:

@RKSimon note this will affect what the tooltips show. Is that okay?

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


[clang] [Headers][X86] Add specific results to comparisons (PR #83316)

2024-03-07 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 updated 
https://github.com/llvm/llvm-project/pull/83316

>From 2afca3e91d96cc77f43556bbf71b6e60a22e45f2 Mon Sep 17 00:00:00 2001
From: Paul Robinson 
Date: Wed, 28 Feb 2024 11:04:41 -0800
Subject: [PATCH 1/2] [Headers][X86] Add specific results to comparisons

Comparison intrinsics were described as returning the "result" without
specifying how. The "cmp" intrinsics return zero or all 1's in the
corresponding elements of a returned vector; the "com" intrinsics return
an integer 0 or 1.

Also removed some redundant information.
---
 clang/lib/Headers/smmintrin.h |   6 +-
 clang/lib/Headers/xmmintrin.h | 146 +++---
 2 files changed, 85 insertions(+), 67 deletions(-)

diff --git a/clang/lib/Headers/smmintrin.h b/clang/lib/Headers/smmintrin.h
index 005d7db9c3c308..ba593835b9b3dc 100644
--- a/clang/lib/Headers/smmintrin.h
+++ b/clang/lib/Headers/smmintrin.h
@@ -1186,7 +1186,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_testnzc_si128(__m128i __M,
 
 /* SSE4 64-bit Packed Integer Comparisons.  */
 /// Compares each of the corresponding 64-bit values of the 128-bit
-///integer vectors for equality.
+///integer vectors for equality. Returns zero for false and all 1's for
+///true in corresponding elements of the result.
 ///
 /// \headerfile 
 ///
@@ -2303,7 +2304,8 @@ static __inline__ __m128i __DEFAULT_FN_ATTRS 
_mm_minpos_epu16(__m128i __V) {
 /* SSE4.2 Compare Packed Data -- Greater Than.  */
 /// Compares each of the corresponding 64-bit values of the 128-bit
 ///integer vectors to determine if the values in the first operand are
-///greater than those in the second operand.
+///greater than those in the second operand. Returns zero for false and
+///all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile 
 ///
diff --git a/clang/lib/Headers/xmmintrin.h b/clang/lib/Headers/xmmintrin.h
index 47368f3c23d2d6..d8ad5ae526a45f 100644
--- a/clang/lib/Headers/xmmintrin.h
+++ b/clang/lib/Headers/xmmintrin.h
@@ -474,8 +474,8 @@ _mm_xor_ps(__m128 __a, __m128 __b)
 }
 
 /// Compares two 32-bit float values in the low-order bits of both
-///operands for equality and returns the result of the comparison in the
-///low-order bits of a vector [4 x float].
+///operands for equality and returns the result of the comparison (zero for
+///false, all 1's for true) in the low-order bits of a vector [4 x float].
 ///
 /// \headerfile 
 ///
@@ -496,7 +496,8 @@ _mm_cmpeq_ss(__m128 __a, __m128 __b)
 }
 
 /// Compares each of the corresponding 32-bit float values of the
-///128-bit vectors of [4 x float] for equality.
+///128-bit vectors of [4 x float] for equality. Returns zero for false and
+///all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile 
 ///
@@ -516,7 +517,8 @@ _mm_cmpeq_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///operands to determine if the value in the first operand is less than the
 ///corresponding value in the second operand and returns the result of the
-///comparison in the low-order bits of a vector of [4 x float].
+///comparison (zero for false, all 1's for true) in the low-order bits of a
+///vector of [4 x float].
 ///
 /// \headerfile 
 ///
@@ -538,7 +540,8 @@ _mm_cmplt_ss(__m128 __a, __m128 __b)
 
 /// Compares each of the corresponding 32-bit float values of the
 ///128-bit vectors of [4 x float] to determine if the values in the first
-///operand are less than those in the second operand.
+///operand are less than those in the second operand. Returns zero for
+///false and all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile 
 ///
@@ -558,8 +561,8 @@ _mm_cmplt_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///operands to determine if the value in the first operand is less than or
 ///equal to the corresponding value in the second operand and returns the
-///result of the comparison in the low-order bits of a vector of
-///[4 x float].
+///result of the comparison (zero for false, all 1's for true) in the
+///low-order bits of a vector of [4 x float].
 ///
 /// \headerfile 
 ///
@@ -581,7 +584,9 @@ _mm_cmple_ss(__m128 __a, __m128 __b)
 
 /// Compares each of the corresponding 32-bit float values of the
 ///128-bit vectors of [4 x float] to determine if the values in the first
-///operand are less than or equal to those in the second operand.
+///operand are less than or equal to those in the second operand. Returns
+///zero for false and all 1's for true in corresponding elements of the
+///result.
 ///
 /// \headerfile 
 ///
@@ -601,7 +606,8 @@ _mm_cmple_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///operands to determine if the value in the first operand is greater than
 ///

[clang] [Offload] Move HIP and CUDA to new driver by default (PR #84420)

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

MaskRay wrote:

> > There are many `--no-offload-new-driver` test changes. They can be 
> > pre-committed to make this default flip modify fewer files.
> 
> I think it's much easier to keep these in a single patch, both for writing 
> and with any potential reverting that it may require.

Since llvm is moving rapidly, reverting a commit that modifies many tests is 
quite risky, since these tests could have been modified by other changes or 
just cause merge conflicts for others. I assume that the merit of this patch is 
obvious (a new feature is in development for quite some time, then it matures 
and replaces the old feature), so adding `--no-offload-new-driver` (to mark 
"these tests are old, please update them when the new default has been stable 
for a while") is non-contentious. Pre-committing the test (which is not risky 
at all) would make this default flip patch much safer to land or revert.

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


[clang] [Clang][Sema] Fix type of enumerators in incomplete enumerations (PR #84068)

2024-03-07 Thread via cfe-commits

Kupa-Martin wrote:

> Should we also have a C++ test for this fix?

clang/test/Sema/warn-compare-enum-types-mismatch.c should cover both C and C++. 
Or do you mean some other kind of test? 

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


[clang] [Offload] Move HIP and CUDA to new driver by default (PR #84420)

2024-03-07 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

I could possibly precommit the basic checks for the ones that just check the 
phases / bindings.

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


[clang] [llvm] [IR] Change representation of getelementptr inrange (PR #84341)

2024-03-07 Thread Nicolai Hähnle via cfe-commits

nhaehnle wrote:

Have you thought about the implications for dynamic (non-constant) indices? 
Stuff like
```
  %gep = getelementptr [50 x {i32, [10 x i32]}], ptr %base, i32 0, i32 
%outer_idx, i32 1, i32 %inner_idx
```
The current representation allows an `inrange` on the second-to-last index 
which to my understanding restricts the range to the `[10 x i32]` into which 
`%gep` falls structurally.

It seems like neither proposed representation is able to capture that in a 
single `ptradd` (it could be captured with a sequence of two `ptradd`s, but 
that's an awkward tradeoff).

The first proposed representation at least allows handling the case when there 
is only a single dynamic index, and the `inrange` is to the right of it.

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


[clang] [Driver,BareMetal] Replace -lclang_rt.builtins{,-$arch}.a with an absolute path (PR #82424)

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

MaskRay wrote:

> Hi, this broke our downstream. What is the motivation for this, and how is 
> this intended to be used with compiler-rt locations being set by 
> multilib.yaml? We have something similar to what ARM does for multilibs.yaml 
> but with different paths, and this prevents the driver from knowing anything 
> about a singular path at which it should find the correct compiler-rt. What 
> makes compiler-rt special in a way that other target libraries aren't? Here's 
> how a part of our deliverable looks like:
> 
> ```
> riscv/lib/rv32imafc/ilp32f/
> ├── except
> │   ├── libc.a
> │   └── libm.a
> ├── libclang_rt.builtins-riscv32.a
> └── noexcept
> ├── libc.a
> └── libm.a
> ```
> 
> and there are several such `/` directories

* The preferred filename has changed from `clang_rt.builtins{,-$arch}.a` to 
`$triple/clang_rt.builtins.a`. BareMetal hadn't been fixed before this PR.
* All other ToolChains use an absolute path, while BareMetal inappropriately 
used `-lxxx`.
* This was a necessary change to do #81037

I think you'll need to switch to LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on 
hierarchy, which is quite different from the older off hierarchy.

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


[clang] [Clang][Sema] Fix type of enumerators in incomplete enumerations (PR #84068)

2024-03-07 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Should we also have a C++ test for this fix?

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


[clang] [Offload] Move HIP and CUDA to new driver by default (PR #84420)

2024-03-07 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> There are many `--no-offload-new-driver` test changes. They can be 
> pre-committed to make this default flip modify fewer files.

I think it's much easier to keep these in a single patch, both for writing and 
with any potential reverting that it may require.

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


[clang] [NFC] [C++20] [Modules] [P1689] [Scanner] Don't use thread pool in P1689 per file mode (PR #84285)

2024-03-07 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/84285

>From dd9711be2368a299b408d0ff06ec9c1c0540083b Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Thu, 7 Mar 2024 15:19:28 +0800
Subject: [PATCH 1/3] [NFC] [C++20] [Modules] [P1689] [Scanner] Don't use
 thread pool in P1689 per file mode

I suddenly found that the clang scan deps may use all concurrent threads
to scan the files. It makes sense in the batch mode. But in P1689
per file mode, it simply wastes times.
---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 204 +-
 1 file changed, 108 insertions(+), 96 deletions(-)

diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index d042fecc3dbe63..843816a8ed6515 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -744,6 +744,9 @@ getCompilationDataBase(int argc, char **argv, std::string 
) {
 return nullptr;
   }
 
+  // Only 1 threads is required if P1689 per file mode.
+  NumThreads = 1;
+
   // There might be multiple jobs for a compilation. Extract the specified
   // output filename from the last job.
   auto LastCmd = C->getJobs().end();
@@ -867,13 +870,6 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   // Print out the dependency results to STDOUT by default.
   SharedStream DependencyOS(llvm::outs());
 
-  DependencyScanningService Service(ScanMode, Format, OptimizeArgs,
-EagerLoadModules);
-  llvm::DefaultThreadPool Pool(llvm::hardware_concurrency(NumThreads));
-  std::vector> WorkerTools;
-  for (unsigned I = 0; I < Pool.getMaxConcurrency(); ++I)
-WorkerTools.push_back(std::make_unique(Service));
-
   std::vector Inputs =
   AdjustingCompilations->getAllCompileCommands();
 
@@ -893,102 +889,118 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   if (Format == ScanningOutputFormat::Full)
 FD.emplace(ModuleName.empty() ? Inputs.size() : 0);
 
-  if (Verbose) {
-llvm::outs() << "Running clang-scan-deps on " << Inputs.size()
- << " files using " << Pool.getMaxConcurrency() << " 
workers\n";
-  }
-
-  llvm::Timer T;
-  T.startTimer();
-
-  for (unsigned I = 0; I < Pool.getMaxConcurrency(); ++I) {
-Pool.async([&, I]() {
-  llvm::DenseSet AlreadySeenModules;
-  while (auto MaybeInputIndex = GetNextInputIndex()) {
-size_t LocalIndex = *MaybeInputIndex;
-const tooling::CompileCommand *Input = [LocalIndex];
-std::string Filename = std::move(Input->Filename);
-std::string CWD = std::move(Input->Directory);
-
-std::optional MaybeModuleName;
-if (!ModuleName.empty())
-  MaybeModuleName = ModuleName;
-
-std::string OutputDir(ModuleFilesDir);
-if (OutputDir.empty())
-  OutputDir = getModuleCachePath(Input->CommandLine);
-auto LookupOutput = [&](const ModuleID , ModuleOutputKind MOK) {
-  return ::lookupModuleOutput(MID, MOK, OutputDir);
-};
-
-// Run the tool on it.
-if (Format == ScanningOutputFormat::Make) {
-  auto MaybeFile =
-  WorkerTools[I]->getDependencyFile(Input->CommandLine, CWD);
-  if (handleMakeDependencyToolResult(Filename, MaybeFile, DependencyOS,
- Errs))
-HadErrors = true;
-} else if (Format == ScanningOutputFormat::P1689) {
-  // It is useful to generate the make-format dependency output during
-  // the scanning for P1689. Otherwise the users need to scan again for
-  // it. We will generate the make-format dependency output if we find
-  // `-MF` in the command lines.
-  std::string MakeformatOutputPath;
-  std::string MakeformatOutput;
-
-  auto MaybeRule = WorkerTools[I]->getP1689ModuleDependencyFile(
-  *Input, CWD, MakeformatOutput, MakeformatOutputPath);
-
-  if (handleP1689DependencyToolResult(Filename, MaybeRule, PD, Errs))
-HadErrors = true;
+  std::vector> WorkerTools;
 
-  if (!MakeformatOutputPath.empty() && !MakeformatOutput.empty() &&
-  !HadErrors) {
-static std::mutex Lock;
-// With compilation database, we may open different files
-// concurrently or we may write the same file concurrently. So we
-// use a map here to allow multiple compile commands to write to 
the
-// same file. Also we need a lock here to avoid data race.
-static llvm::StringMap OSs;
-std::unique_lock LockGuard(Lock);
-
-auto OSIter = OSs.find(MakeformatOutputPath);
-if (OSIter == OSs.end()) {
-  std::error_code EC;
-  OSIter = OSs.try_emplace(MakeformatOutputPath,
-   MakeformatOutputPath, EC)
- 

[clang] [NFC] [C++20] [Modules] [P1689] [Scanner] Don't use thread pool in P1689 per file mode (PR #84285)

2024-03-07 Thread Chuanqi Xu via cfe-commits


@@ -893,102 +889,118 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   if (Format == ScanningOutputFormat::Full)
 FD.emplace(ModuleName.empty() ? Inputs.size() : 0);
 
-  if (Verbose) {
-llvm::outs() << "Running clang-scan-deps on " << Inputs.size()
- << " files using " << Pool.getMaxConcurrency() << " 
workers\n";
-  }
-
-  llvm::Timer T;
-  T.startTimer();
-
-  for (unsigned I = 0; I < Pool.getMaxConcurrency(); ++I) {
-Pool.async([&, I]() {
-  llvm::DenseSet AlreadySeenModules;
-  while (auto MaybeInputIndex = GetNextInputIndex()) {
-size_t LocalIndex = *MaybeInputIndex;
-const tooling::CompileCommand *Input = [LocalIndex];
-std::string Filename = std::move(Input->Filename);
-std::string CWD = std::move(Input->Directory);
-
-std::optional MaybeModuleName;
-if (!ModuleName.empty())
-  MaybeModuleName = ModuleName;
-
-std::string OutputDir(ModuleFilesDir);
-if (OutputDir.empty())
-  OutputDir = getModuleCachePath(Input->CommandLine);
-auto LookupOutput = [&](const ModuleID , ModuleOutputKind MOK) {
-  return ::lookupModuleOutput(MID, MOK, OutputDir);
-};
-
-// Run the tool on it.
-if (Format == ScanningOutputFormat::Make) {
-  auto MaybeFile =
-  WorkerTools[I]->getDependencyFile(Input->CommandLine, CWD);
-  if (handleMakeDependencyToolResult(Filename, MaybeFile, DependencyOS,
- Errs))
-HadErrors = true;
-} else if (Format == ScanningOutputFormat::P1689) {
-  // It is useful to generate the make-format dependency output during
-  // the scanning for P1689. Otherwise the users need to scan again for
-  // it. We will generate the make-format dependency output if we find
-  // `-MF` in the command lines.
-  std::string MakeformatOutputPath;
-  std::string MakeformatOutput;
-
-  auto MaybeRule = WorkerTools[I]->getP1689ModuleDependencyFile(
-  *Input, CWD, MakeformatOutput, MakeformatOutputPath);
-
-  if (handleP1689DependencyToolResult(Filename, MaybeRule, PD, Errs))
-HadErrors = true;
+  std::vector> WorkerTools;

ChuanqiXu9 wrote:

Done by moving this into the `ThreadPool` only branch and get rid of 
`std::unique_ptr`. It looks like we can't remove the vector entirely. Since the 
parameter type of `ScanningTask` is `DependencyScanningTool &` instead of 
`const DependencyScanningTool &`, so we may face lifetime issues if we 
construct DependencyScanningTool in place.

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


[clang] [NFC] [C++20] [Modules] [P1689] [Scanner] Don't use thread pool in P1689 per file mode (PR #84285)

2024-03-07 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 da4957be2365831c94eab0b52612367c29f1d299 
e875b07ad16c7c66d8d9dd70efca30276981f639 -- 
clang/tools/clang-scan-deps/ClangScanDeps.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 2fd85c8e65..832be0df64 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -910,8 +910,7 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
 
   // Run the tool on it.
   if (Format == ScanningOutputFormat::Make) {
-auto MaybeFile =
-WorkerTool.getDependencyFile(Input->CommandLine, CWD);
+auto MaybeFile = WorkerTool.getDependencyFile(Input->CommandLine, CWD);
 if (handleMakeDependencyToolResult(Filename, MaybeFile, DependencyOS,
Errs))
   HadErrors = true;
@@ -996,9 +995,8 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
 }
 
 for (unsigned I = 0; I < Pool.getMaxConcurrency(); ++I) {
-  Pool.async([ScanningTask, , I]() {
-ScanningTask(WorkerTools[I]);
-  });
+  Pool.async(
+  [ScanningTask, , I]() { ScanningTask(WorkerTools[I]); });
 }
 Pool.wait();
   }

``




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


[clang] [Offload] Move HIP and CUDA to new driver by default (PR #84420)

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

MaskRay wrote:

There are many `--no-offload-new-driver` test changes. They can be 
pre-committed to make this default flip modify fewer files.

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


[clang] [NFC] [C++20] [Modules] [P1689] [Scanner] Don't use thread pool in P1689 per file mode (PR #84285)

2024-03-07 Thread Chuanqi Xu via cfe-commits


@@ -893,102 +889,118 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   if (Format == ScanningOutputFormat::Full)
 FD.emplace(ModuleName.empty() ? Inputs.size() : 0);
 
-  if (Verbose) {
-llvm::outs() << "Running clang-scan-deps on " << Inputs.size()
- << " files using " << Pool.getMaxConcurrency() << " 
workers\n";
-  }
-
-  llvm::Timer T;
-  T.startTimer();
-
-  for (unsigned I = 0; I < Pool.getMaxConcurrency(); ++I) {
-Pool.async([&, I]() {
-  llvm::DenseSet AlreadySeenModules;
-  while (auto MaybeInputIndex = GetNextInputIndex()) {
-size_t LocalIndex = *MaybeInputIndex;
-const tooling::CompileCommand *Input = [LocalIndex];
-std::string Filename = std::move(Input->Filename);
-std::string CWD = std::move(Input->Directory);
-
-std::optional MaybeModuleName;
-if (!ModuleName.empty())
-  MaybeModuleName = ModuleName;
-
-std::string OutputDir(ModuleFilesDir);
-if (OutputDir.empty())
-  OutputDir = getModuleCachePath(Input->CommandLine);
-auto LookupOutput = [&](const ModuleID , ModuleOutputKind MOK) {
-  return ::lookupModuleOutput(MID, MOK, OutputDir);
-};
-
-// Run the tool on it.
-if (Format == ScanningOutputFormat::Make) {
-  auto MaybeFile =
-  WorkerTools[I]->getDependencyFile(Input->CommandLine, CWD);
-  if (handleMakeDependencyToolResult(Filename, MaybeFile, DependencyOS,
- Errs))
-HadErrors = true;
-} else if (Format == ScanningOutputFormat::P1689) {
-  // It is useful to generate the make-format dependency output during
-  // the scanning for P1689. Otherwise the users need to scan again for
-  // it. We will generate the make-format dependency output if we find
-  // `-MF` in the command lines.
-  std::string MakeformatOutputPath;
-  std::string MakeformatOutput;
-
-  auto MaybeRule = WorkerTools[I]->getP1689ModuleDependencyFile(
-  *Input, CWD, MakeformatOutput, MakeformatOutputPath);
-
-  if (handleP1689DependencyToolResult(Filename, MaybeRule, PD, Errs))
-HadErrors = true;
+  std::vector> WorkerTools;
 
-  if (!MakeformatOutputPath.empty() && !MakeformatOutput.empty() &&
-  !HadErrors) {
-static std::mutex Lock;
-// With compilation database, we may open different files
-// concurrently or we may write the same file concurrently. So we
-// use a map here to allow multiple compile commands to write to 
the
-// same file. Also we need a lock here to avoid data race.
-static llvm::StringMap OSs;
-std::unique_lock LockGuard(Lock);
-
-auto OSIter = OSs.find(MakeformatOutputPath);
-if (OSIter == OSs.end()) {
-  std::error_code EC;
-  OSIter = OSs.try_emplace(MakeformatOutputPath,
-   MakeformatOutputPath, EC)
-   .first;
-  if (EC)
-llvm::errs()
-<< "Failed to open P1689 make format output file \""
-<< MakeformatOutputPath << "\" for " << EC.message()
-<< "\n";
-}
+  auto ScanningTask = [&](unsigned I) {

ChuanqiXu9 wrote:

Done. It looks indeed better.

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


[clang] [NFC] [C++20] [Modules] [P1689] [Scanner] Don't use thread pool in P1689 per file mode (PR #84285)

2024-03-07 Thread Chuanqi Xu via cfe-commits


@@ -744,6 +744,9 @@ getCompilationDataBase(int argc, char **argv, std::string 
) {
 return nullptr;
   }
 
+  // Only 1 threads is required if P1689 per file mode.
+  NumThreads = 1;

ChuanqiXu9 wrote:

Makes sense. Done.

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


[clang] [NFC] [C++20] [Modules] [P1689] [Scanner] Don't use thread pool in P1689 per file mode (PR #84285)

2024-03-07 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/84285

>From dd9711be2368a299b408d0ff06ec9c1c0540083b Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Thu, 7 Mar 2024 15:19:28 +0800
Subject: [PATCH 1/2] [NFC] [C++20] [Modules] [P1689] [Scanner] Don't use
 thread pool in P1689 per file mode

I suddenly found that the clang scan deps may use all concurrent threads
to scan the files. It makes sense in the batch mode. But in P1689
per file mode, it simply wastes times.
---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 204 +-
 1 file changed, 108 insertions(+), 96 deletions(-)

diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index d042fecc3dbe63..843816a8ed6515 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -744,6 +744,9 @@ getCompilationDataBase(int argc, char **argv, std::string 
) {
 return nullptr;
   }
 
+  // Only 1 threads is required if P1689 per file mode.
+  NumThreads = 1;
+
   // There might be multiple jobs for a compilation. Extract the specified
   // output filename from the last job.
   auto LastCmd = C->getJobs().end();
@@ -867,13 +870,6 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   // Print out the dependency results to STDOUT by default.
   SharedStream DependencyOS(llvm::outs());
 
-  DependencyScanningService Service(ScanMode, Format, OptimizeArgs,
-EagerLoadModules);
-  llvm::DefaultThreadPool Pool(llvm::hardware_concurrency(NumThreads));
-  std::vector> WorkerTools;
-  for (unsigned I = 0; I < Pool.getMaxConcurrency(); ++I)
-WorkerTools.push_back(std::make_unique(Service));
-
   std::vector Inputs =
   AdjustingCompilations->getAllCompileCommands();
 
@@ -893,102 +889,118 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   if (Format == ScanningOutputFormat::Full)
 FD.emplace(ModuleName.empty() ? Inputs.size() : 0);
 
-  if (Verbose) {
-llvm::outs() << "Running clang-scan-deps on " << Inputs.size()
- << " files using " << Pool.getMaxConcurrency() << " 
workers\n";
-  }
-
-  llvm::Timer T;
-  T.startTimer();
-
-  for (unsigned I = 0; I < Pool.getMaxConcurrency(); ++I) {
-Pool.async([&, I]() {
-  llvm::DenseSet AlreadySeenModules;
-  while (auto MaybeInputIndex = GetNextInputIndex()) {
-size_t LocalIndex = *MaybeInputIndex;
-const tooling::CompileCommand *Input = [LocalIndex];
-std::string Filename = std::move(Input->Filename);
-std::string CWD = std::move(Input->Directory);
-
-std::optional MaybeModuleName;
-if (!ModuleName.empty())
-  MaybeModuleName = ModuleName;
-
-std::string OutputDir(ModuleFilesDir);
-if (OutputDir.empty())
-  OutputDir = getModuleCachePath(Input->CommandLine);
-auto LookupOutput = [&](const ModuleID , ModuleOutputKind MOK) {
-  return ::lookupModuleOutput(MID, MOK, OutputDir);
-};
-
-// Run the tool on it.
-if (Format == ScanningOutputFormat::Make) {
-  auto MaybeFile =
-  WorkerTools[I]->getDependencyFile(Input->CommandLine, CWD);
-  if (handleMakeDependencyToolResult(Filename, MaybeFile, DependencyOS,
- Errs))
-HadErrors = true;
-} else if (Format == ScanningOutputFormat::P1689) {
-  // It is useful to generate the make-format dependency output during
-  // the scanning for P1689. Otherwise the users need to scan again for
-  // it. We will generate the make-format dependency output if we find
-  // `-MF` in the command lines.
-  std::string MakeformatOutputPath;
-  std::string MakeformatOutput;
-
-  auto MaybeRule = WorkerTools[I]->getP1689ModuleDependencyFile(
-  *Input, CWD, MakeformatOutput, MakeformatOutputPath);
-
-  if (handleP1689DependencyToolResult(Filename, MaybeRule, PD, Errs))
-HadErrors = true;
+  std::vector> WorkerTools;
 
-  if (!MakeformatOutputPath.empty() && !MakeformatOutput.empty() &&
-  !HadErrors) {
-static std::mutex Lock;
-// With compilation database, we may open different files
-// concurrently or we may write the same file concurrently. So we
-// use a map here to allow multiple compile commands to write to 
the
-// same file. Also we need a lock here to avoid data race.
-static llvm::StringMap OSs;
-std::unique_lock LockGuard(Lock);
-
-auto OSIter = OSs.find(MakeformatOutputPath);
-if (OSIter == OSs.end()) {
-  std::error_code EC;
-  OSIter = OSs.try_emplace(MakeformatOutputPath,
-   MakeformatOutputPath, EC)
- 

[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

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


@@ -0,0 +1,11 @@
+// Note: %s must be preceded by --, otherwise it may be interpreted as a
+// command-line option, e.g. on Mac where %s is commonly under /Users.
+//
+// Note: see also cl-zc.cpp
+
+// RUN: %clang_cl /TC /dev/null /E -Xclang -dM /Zc:__STDC__- 2>&1 | FileCheck 
%s --check-prefix=ZCSTDCIGNORED
+// ZCSTDCIGNORED-NOT: #define __STDC__ 1
+// ZCSTDCIGNORED: argument unused during compilation
+
+// RUN: not %clang -Xclang -fno-ms-define-stdc %s 2>&1 | FileCheck %s 
--check-prefix="NOARG"

MaskRay wrote:

This tests that -fno-ms-define-stdc is not a cc1 option. We almost never do it. 
There could be a value to test whether the driver -fno-ms-define-stdc option is 
present.

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

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


@@ -123,6 +123,15 @@
 // CHECK-CHAR8_T_: "-fno-char8_t"
 
 
+// RUN: %clang_cl /TC /dev/null /E -Xclang -dM 2> /dev/null | FileCheck 
-match-full-lines %s --check-prefix=NOSTDC

MaskRay wrote:

Driver tests usually only do `-###` and check the generated cc1 options. This 
command runs the preprocessor, which can be moved to clang/test/Preprocessor 
using `%clang_cc1`

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


[clang] [clang] Factor out OpenACC part of `Sema` (PR #84184)

2024-03-07 Thread Shafik Yaghmour via cfe-commits

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


[clang] [clang] Factor out OpenACC part of `Sema` (PR #84184)

2024-03-07 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

I think this makes sense.

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


[clang] [clang] Factor out OpenACC part of `Sema` (PR #84184)

2024-03-07 Thread Shafik Yaghmour via cfe-commits


@@ -0,0 +1,67 @@
+//===- SemaOpenACC.h - Semantic Analysis for OpenACC constructs 
---===//
+//
+// 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
+//
+//===--===//
+/// \file
+/// This file declares semantic analysis for OpenACC constructs and
+/// clauses.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_SEMA_SEMAOPENACC_H
+#define LLVM_CLANG_SEMA_SEMAOPENACC_H
+
+#include "clang/AST/DeclGroup.h"
+#include "clang/Basic/OpenACCKinds.h"

shafik wrote:

I would have thought we could remove this include from `Sema.h` above.

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


[clang] [Headers][X86] Add specific results to comparisons (PR #83316)

2024-03-07 Thread Paul T Robinson via cfe-commits

pogo59 wrote:

@RKSimon I was not aware of the comparison intrinsics in emmintrin.h. I will 
follow that pattern.

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


[clang] [clang-tools-extra] [llvm] [llvm][Support] Add and use errnoAsErrorCode (PR #84423)

2024-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-binary-utilities

Author: Michael Spencer (Bigcheese)


Changes

LLVM is inconsistent about how it converts `errno` to `std::error_code`. This 
can cause problems because values outside of `std::errc` compare differently if 
one is system and one is generic on POSIX systems.

This is even more of a problem on Windows where use of the system category is 
just wrong, as that is for Windows errors, which have a completely different 
mapping than POSIX/generic errors. This patch fixes one instance of this 
mistake in `JSONTransport.cpp`.

This patch adds `errnoAsErrorCode()` which makes it so people do not need to 
think about this issue in the future. It also cleans up a lot of usage of errno 
in LLVM and Clang.

---

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


17 Files Affected:

- (modified) clang-tools-extra/clangd/JSONTransport.cpp (+1-2) 
- (modified) clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp (+3-6) 
- (modified) llvm/include/llvm/Support/Error.h (+14) 
- (modified) llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp (+3-6) 
- (modified) 
llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
 (+5-6) 
- (modified) llvm/lib/Object/ArchiveWriter.cpp (+1-1) 
- (modified) llvm/lib/Support/AutoConvert.cpp (+4-4) 
- (modified) llvm/lib/Support/LockFileManager.cpp (+1-1) 
- (modified) llvm/lib/Support/Path.cpp (+7-12) 
- (modified) llvm/lib/Support/RandomNumberGenerator.cpp (+4-3) 
- (modified) llvm/lib/Support/Unix/Memory.inc (+5-5) 
- (modified) llvm/lib/Support/Unix/Path.inc (+33-34) 
- (modified) llvm/lib/Support/Unix/Process.inc (+6-6) 
- (modified) llvm/lib/Support/Windows/Process.inc (+1-1) 
- (modified) llvm/lib/Support/Windows/Program.inc (+2-2) 
- (modified) llvm/lib/Support/raw_ostream.cpp (+3-3) 
- (modified) llvm/lib/Support/raw_socket_stream.cpp (+1-1) 


``diff
diff --git a/clang-tools-extra/clangd/JSONTransport.cpp 
b/clang-tools-extra/clangd/JSONTransport.cpp
index 346c7dfb66a1db..3c0e198433f360 100644
--- a/clang-tools-extra/clangd/JSONTransport.cpp
+++ b/clang-tools-extra/clangd/JSONTransport.cpp
@@ -107,8 +107,7 @@ class JSONTransport : public Transport {
 return error(std::make_error_code(std::errc::operation_canceled),
  "Got signal, shutting down");
   if (ferror(In))
-return llvm::errorCodeToError(
-std::error_code(errno, std::system_category()));
+return llvm::errorCodeToError(llvm::errnoAsErrorCode());
   if (readRawMessage(JSON)) {
 ThreadCrashReporter ScopedReporter([]() {
   auto  = llvm::errs();
diff --git a/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp 
b/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
index beca9586988b52..2ffbc1a226958a 100644
--- a/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
+++ b/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
@@ -333,8 +333,7 @@ llvm::Expected> 
clang::DirectoryWatcher::creat
   const int InotifyFD = inotify_init1(IN_CLOEXEC);
   if (InotifyFD == -1)
 return llvm::make_error(
-std::string("inotify_init1() error: ") + strerror(errno),
-llvm::inconvertibleErrorCode());
+llvm::errnoAsErrorCode(), std::string(": inotify_init1()"));
 
   const int InotifyWD = inotify_add_watch(
   InotifyFD, Path.str().c_str(),
@@ -346,15 +345,13 @@ llvm::Expected> 
clang::DirectoryWatcher::creat
   );
   if (InotifyWD == -1)
 return llvm::make_error(
-std::string("inotify_add_watch() error: ") + strerror(errno),
-llvm::inconvertibleErrorCode());
+llvm::errnoAsErrorCode(), std::string(": inotify_add_watch()"));
 
   auto InotifyPollingStopper = SemaphorePipe::create();
 
   if (!InotifyPollingStopper)
 return llvm::make_error(
-std::string("SemaphorePipe::create() error: ") + strerror(errno),
-llvm::inconvertibleErrorCode());
+llvm::errnoAsErrorCode(), std::string(": SemaphorePipe::create()"));
 
   return std::make_unique(
   Path, Receiver, WaitForInitialSync, InotifyFD, InotifyWD,
diff --git a/llvm/include/llvm/Support/Error.h 
b/llvm/include/llvm/Support/Error.h
index bb4f38f7ec355e..894b6484336aef 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -1180,6 +1180,20 @@ Error errorCodeToError(std::error_code EC);
 /// will trigger a call to abort().
 std::error_code errorToErrorCode(Error Err);
 
+/// Helper to get errno as an std::error_code.
+///
+/// errno should always be represented using the generic category as that's 
what
+/// both libc++ and libstdc++ do. On POSIX systems you can also represent them
+/// using the system category, however this makes them compare differently for
+/// values outside of those used by `std::errc` if one is generic and the other
+/// is system.
+///
+/// See the libc++ and libstdc++ 

[clang] [clang-tools-extra] [llvm] [llvm][Support] Add and use errnoAsErrorCode (PR #84423)

2024-03-07 Thread Michael Spencer via cfe-commits

https://github.com/Bigcheese created 
https://github.com/llvm/llvm-project/pull/84423

LLVM is inconsistent about how it converts `errno` to `std::error_code`. This 
can cause problems because values outside of `std::errc` compare differently if 
one is system and one is generic on POSIX systems.

This is even more of a problem on Windows where use of the system category is 
just wrong, as that is for Windows errors, which have a completely different 
mapping than POSIX/generic errors. This patch fixes one instance of this 
mistake in `JSONTransport.cpp`.

This patch adds `errnoAsErrorCode()` which makes it so people do not need to 
think about this issue in the future. It also cleans up a lot of usage of errno 
in LLVM and Clang.

>From 858effb8f8225e9ca7c367037046f07b576a3348 Mon Sep 17 00:00:00 2001
From: Michael Spencer 
Date: Thu, 7 Mar 2024 17:36:33 -0800
Subject: [PATCH] [llvm][Support] Add and use errnoAsErrorCode

LLVM is inconsistent about how it converts `errno` to
`std::error_code`. This can cause problems because values outside of
`std::errc` compare differently if one is system and one is generic on
POSIX systems.

This is even more of a problem on Windows where use of the system
category is just wrong, as that is for Windows errors, which have a
completely different mapping than POSIX/generic errors. This patch
fixes one instance of this mistake in `JSONTransport.cpp`.

This patch adds `errnoAsErrorCode()` which makes it so people do not
need to think about this issue in the future. It also cleans up a lot
of usage of errno in LLVM and Clang.
---
 clang-tools-extra/clangd/JSONTransport.cpp|  3 +-
 .../linux/DirectoryWatcher-linux.cpp  |  9 +--
 llvm/include/llvm/Support/Error.h | 14 
 llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp |  9 +--
 .../ExecutorSharedMemoryMapperService.cpp | 11 ++-
 llvm/lib/Object/ArchiveWriter.cpp |  2 +-
 llvm/lib/Support/AutoConvert.cpp  |  8 +--
 llvm/lib/Support/LockFileManager.cpp  |  2 +-
 llvm/lib/Support/Path.cpp | 19 ++
 llvm/lib/Support/RandomNumberGenerator.cpp|  7 +-
 llvm/lib/Support/Unix/Memory.inc  | 10 +--
 llvm/lib/Support/Unix/Path.inc| 67 +--
 llvm/lib/Support/Unix/Process.inc | 12 ++--
 llvm/lib/Support/Windows/Process.inc  |  2 +-
 llvm/lib/Support/Windows/Program.inc  |  4 +-
 llvm/lib/Support/raw_ostream.cpp  |  6 +-
 llvm/lib/Support/raw_socket_stream.cpp|  2 +-
 17 files changed, 94 insertions(+), 93 deletions(-)

diff --git a/clang-tools-extra/clangd/JSONTransport.cpp 
b/clang-tools-extra/clangd/JSONTransport.cpp
index 346c7dfb66a1db..3c0e198433f360 100644
--- a/clang-tools-extra/clangd/JSONTransport.cpp
+++ b/clang-tools-extra/clangd/JSONTransport.cpp
@@ -107,8 +107,7 @@ class JSONTransport : public Transport {
 return error(std::make_error_code(std::errc::operation_canceled),
  "Got signal, shutting down");
   if (ferror(In))
-return llvm::errorCodeToError(
-std::error_code(errno, std::system_category()));
+return llvm::errorCodeToError(llvm::errnoAsErrorCode());
   if (readRawMessage(JSON)) {
 ThreadCrashReporter ScopedReporter([]() {
   auto  = llvm::errs();
diff --git a/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp 
b/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
index beca9586988b52..2ffbc1a226958a 100644
--- a/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
+++ b/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
@@ -333,8 +333,7 @@ llvm::Expected> 
clang::DirectoryWatcher::creat
   const int InotifyFD = inotify_init1(IN_CLOEXEC);
   if (InotifyFD == -1)
 return llvm::make_error(
-std::string("inotify_init1() error: ") + strerror(errno),
-llvm::inconvertibleErrorCode());
+llvm::errnoAsErrorCode(), std::string(": inotify_init1()"));
 
   const int InotifyWD = inotify_add_watch(
   InotifyFD, Path.str().c_str(),
@@ -346,15 +345,13 @@ llvm::Expected> 
clang::DirectoryWatcher::creat
   );
   if (InotifyWD == -1)
 return llvm::make_error(
-std::string("inotify_add_watch() error: ") + strerror(errno),
-llvm::inconvertibleErrorCode());
+llvm::errnoAsErrorCode(), std::string(": inotify_add_watch()"));
 
   auto InotifyPollingStopper = SemaphorePipe::create();
 
   if (!InotifyPollingStopper)
 return llvm::make_error(
-std::string("SemaphorePipe::create() error: ") + strerror(errno),
-llvm::inconvertibleErrorCode());
+llvm::errnoAsErrorCode(), std::string(": SemaphorePipe::create()"));
 
   return std::make_unique(
   Path, Receiver, WaitForInitialSync, InotifyFD, InotifyWD,
diff --git a/llvm/include/llvm/Support/Error.h 
b/llvm/include/llvm/Support/Error.h
index bb4f38f7ec355e..894b6484336aef 100644
--- 

[clang] a4703e5 - [clang] Remove std::move in GenerateModuleAction::CreateMultiplexConsumer (NFC)

2024-03-07 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2024-03-08T10:19:07+08:00
New Revision: a4703e5bccc63eca45e0e4bff8f04f82d8622ebe

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

LOG: [clang] Remove std::move in GenerateModuleAction::CreateMultiplexConsumer 
(NFC)

llvm-project/clang/lib/Frontend/FrontendActions.cpp:213:10:
error: moving a local object in a return statement prevents copy elision 
[-Werror,-Wpessimizing-move]
  213 |   return std::move(Consumers);
  |  ^
/Users/jiefu/llvm-project/clang/lib/Frontend/FrontendActions.cpp:213:10: note: 
remove std::move call here
  213 |   return std::move(Consumers);
  |  ^~ ~
1 error generated.

Added: 


Modified: 
clang/lib/Frontend/FrontendActions.cpp

Removed: 




diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index cd9b9923421c69..50338bfa670f83 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -210,7 +210,7 @@ 
GenerateModuleAction::CreateMultiplexConsumer(CompilerInstance ,
   +CI.getFrontendOpts().BuildingImplicitModule));
   Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
   CI, std::string(InFile), OutputFile, std::move(OS), Buffer));
-  return std::move(Consumers);
+  return Consumers;
 }
 
 std::unique_ptr



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


[clang] [Offload] Move HIP and CUDA to new driver by default (PR #84420)

2024-03-07 Thread Joseph Huber via cfe-commits

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


[clang] [Offload] Move HIP and CUDA to new driver by default (PR #84420)

2024-03-07 Thread Joseph Huber via cfe-commits

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


[clang] [Offload] Move HIP and CUDA to new driver by default (PR #84420)

2024-03-07 Thread Joseph Huber via cfe-commits

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


[clang] DefaultNewDriver (PR #84420)

2024-03-07 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)


Changes

- [HIP] Make the HIP default architecture use the enum value
- [Offload] Move HIP and CUDA to new driver by default


---

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


50 Files Affected:

- (modified) clang/include/clang/Basic/Cuda.h (+1-1) 
- (modified) clang/lib/Driver/Driver.cpp (+4-4) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+6-4) 
- (modified) clang/test/Driver/cl-offload.cu (+2-3) 
- (modified) clang/test/Driver/cuda-arch-translation.cu (+13-13) 
- (modified) clang/test/Driver/cuda-bad-arch.cu (+2-2) 
- (modified) clang/test/Driver/cuda-bindings.cu (+12-12) 
- (modified) clang/test/Driver/cuda-external-tools.cu (+7-7) 
- (modified) clang/test/Driver/cuda-options.cu (+12-11) 
- (modified) clang/test/Driver/cuda-output-asm.cu (-4) 
- (modified) clang/test/Driver/cuda-phases.cu (+12-12) 
- (modified) clang/test/Driver/cuda-version-check.cu (+3-3) 
- (modified) clang/test/Driver/hip-binding.hip (+5-5) 
- (modified) clang/test/Driver/hip-cuid-hash.hip (+4-4) 
- (modified) clang/test/Driver/hip-cuid.hip (+5) 
- (modified) clang/test/Driver/hip-dependent-options.hip (+2-2) 
- (modified) clang/test/Driver/hip-device-compile.hip (+11-11) 
- (modified) clang/test/Driver/hip-gz-options.hip (-1) 
- (modified) clang/test/Driver/hip-invalid-target-id.hip (+2-2) 
- (modified) clang/test/Driver/hip-link-bc-to-bc.hip (+2-2) 
- (modified) clang/test/Driver/hip-link-bundle-archive.hip (+11-11) 
- (modified) clang/test/Driver/hip-link-save-temps.hip (+4-4) 
- (modified) clang/test/Driver/hip-link-shared-library.hip (+1-2) 
- (modified) clang/test/Driver/hip-link-static-library.hip (+3-3) 
- (modified) clang/test/Driver/hip-macros.hip (-3) 
- (modified) clang/test/Driver/hip-offload-arch.hip (+1-1) 
- (modified) clang/test/Driver/hip-offload-compress-zlib.hip (+3-3) 
- (modified) clang/test/Driver/hip-offload-compress-zstd.hip (+3-3) 
- (modified) clang/test/Driver/hip-options.hip (+2-6) 
- (modified) clang/test/Driver/hip-output-file-name.hip (+13-13) 
- (modified) clang/test/Driver/hip-partial-link.hip (+7-7) 
- (modified) clang/test/Driver/hip-phases.hip (+53-53) 
- (modified) clang/test/Driver/hip-rdc-device-only.hip (+7-7) 
- (modified) clang/test/Driver/hip-sanitize-options.hip (+1-1) 
- (modified) clang/test/Driver/hip-save-temps.hip (+6-6) 
- (modified) clang/test/Driver/hip-target-id.hip (+5-5) 
- (modified) clang/test/Driver/hip-toolchain-device-only.hip (-4) 
- (modified) clang/test/Driver/hip-toolchain-features.hip (+12-12) 
- (modified) clang/test/Driver/hip-toolchain-mllvm.hip (-2) 
- (modified) clang/test/Driver/hip-toolchain-rdc-separate.hip (+4-4) 
- (modified) clang/test/Driver/hip-toolchain-rdc-static-lib.hip (+1-1) 
- (modified) clang/test/Driver/hip-toolchain-rdc.hip (+2-2) 
- (modified) clang/test/Driver/hip-unbundle-preproc.hipi (+3-3) 
- (modified) clang/test/Driver/hipspv-toolchain-rdc.hip (+1-1) 
- (modified) clang/test/Driver/hipspv-toolchain.hip (+1-1) 
- (modified) clang/test/Driver/invalid-offload-options.cpp (+1-1) 
- (modified) clang/test/Driver/lto.cu (+11-11) 
- (modified) clang/test/Driver/thinlto.cu (+2-2) 
- (modified) clang/test/Preprocessor/cuda-preprocess.cu (+4-4) 
- (modified) clang/unittests/Tooling/ToolingTest.cpp (+3-3) 


``diff
diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index 916cb4b7ef34a7..3e77a74c7c0092 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -123,7 +123,7 @@ enum class CudaArch {
   LAST,
 
   CudaDefault = CudaArch::SM_52,
-  HIPDefault = CudaArch::GFX803,
+  HIPDefault = CudaArch::GFX906,
 };
 
 static inline bool IsNVIDIAGpuArch(CudaArch A) {
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 96e6ad77f5e50d..e85a3e675408e4 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3373,7 +3373,7 @@ class OffloadingActionBuilder final {
  const Driver::InputList )
 : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_HIP) {
 
-  DefaultCudaArch = CudaArch::GFX906;
+  DefaultCudaArch = CudaArch::HIPDefault;
 
   if (Args.hasArg(options::OPT_fhip_emit_relocatable,
   options::OPT_fno_hip_emit_relocatable)) {
@@ -4115,9 +4115,9 @@ void Driver::BuildActions(Compilation , DerivedArgList 
,
   handleArguments(C, Args, Inputs, Actions);
 
   bool UseNewOffloadingDriver =
-  C.isOffloadingHostKind(Action::OFK_OpenMP) ||
+  C.getActiveOffloadKinds() != Action::OFK_None &&
   Args.hasFlag(options::OPT_offload_new_driver,
-   options::OPT_no_offload_new_driver, false);
+   options::OPT_no_offload_new_driver, true);
 
   // Builder to be used to build offloading actions.
   std::unique_ptr OffloadBuilder =
@@ -4802,7 +4802,7 @@ 

[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2024-03-07 Thread Chuanqi Xu via cfe-commits

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


[clang] [X86] Finally handle target of __builtin_ia32_cmp[p|s][s|d] from avx into sse/sse2/avx (PR #84136)

2024-03-07 Thread Freddy Ye via cfe-commits

FreddyLeaf wrote:

ping for review

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


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-07 Thread Paul T Robinson via cfe-commits


@@ -2180,7 +2180,8 @@ _mm256_cvtepi32_pd(__m128i __a)
   return (__m256d)__builtin_convertvector((__v4si)__a, __v4df);
 }
 
-/// Converts a vector of [8 x i32] into a vector of [8 x float].
+/// Converts a vector of [8 x i32] into a vector of [8 x float]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.

pogo59 wrote:

Discussed this internally and agreed that it is not necessary.

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


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-07 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 updated 
https://github.com/llvm/llvm-project/pull/83447

>From 64cdd358d0bf359383a5dd3d1da236a219644c9e Mon Sep 17 00:00:00 2001
From: Paul Robinson 
Date: Thu, 29 Feb 2024 08:59:26 -0800
Subject: [PATCH 1/2] [Headers][X86] Add rounding and exception notes to
 conversions

Consistently describe rounding/truncating on convert intrinsics.
Add notes where an out-of-range result can raise an exception.
---
 clang/lib/Headers/avxintrin.h |  36 +++---
 clang/lib/Headers/emmintrin.h |  91 ++---
 clang/lib/Headers/xmmintrin.h | 125 --
 3 files changed, 182 insertions(+), 70 deletions(-)

diff --git a/clang/lib/Headers/avxintrin.h b/clang/lib/Headers/avxintrin.h
index f116d8bc3a94c7..51c7d76e75ca1a 100644
--- a/clang/lib/Headers/avxintrin.h
+++ b/clang/lib/Headers/avxintrin.h
@@ -2180,7 +2180,8 @@ _mm256_cvtepi32_pd(__m128i __a)
   return (__m256d)__builtin_convertvector((__v4si)__a, __v4df);
 }
 
-/// Converts a vector of [8 x i32] into a vector of [8 x float].
+/// Converts a vector of [8 x i32] into a vector of [8 x float]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2196,7 +2197,8 @@ _mm256_cvtepi32_ps(__m256i __a)
 }
 
 /// Converts a 256-bit vector of [4 x double] into a 128-bit vector of
-///[4 x float].
+///[4 x float]. Rounds inexact results according to the rounding control
+///bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2211,7 +2213,12 @@ _mm256_cvtpd_ps(__m256d __a)
   return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
 }
 
-/// Converts a vector of [8 x float] into a vector of [8 x i32].
+/// Converts a vector of [8 x float] into a vector of [8 x i32]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2243,8 +2250,11 @@ _mm256_cvtps_pd(__m128 __a)
 }
 
 /// Converts a 256-bit vector of [4 x double] into a 128-bit vector of [4
-///x i32], truncating the result by rounding towards zero when it is
-///inexact.
+///x i32], truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2259,9 +2269,13 @@ _mm256_cvttpd_epi32(__m256d __a)
   return (__m128i)__builtin_ia32_cvttpd2dq256((__v4df) __a);
 }
 
-/// Converts a 256-bit vector of [4 x double] into a 128-bit vector of [4
-///x i32]. When a conversion is inexact, the value returned is rounded
-///according to the rounding control bits in the MXCSR register.
+/// Converts a 256-bit vector of [4 x double] into a 128-bit vector of
+///[4 x i32]. Rounds inexact results according to the rounding control bits
+///in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2277,7 +2291,11 @@ _mm256_cvtpd_epi32(__m256d __a)
 }
 
 /// Converts a vector of [8 x float] into a vector of [8 x i32],
-///truncating the result by rounding towards zero when it is inexact.
+///truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 96e3ebdecbdf83..9ae7fe2c809ac6 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -1245,7 +1245,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_ucomineq_sd(__m128d __a,
 /// Converts the two double-precision floating-point elements of a
 ///128-bit vector of [2 x double] into two single-precision floating-point
 ///values, returned in the lower 64 bits of a 128-bit vector of [4 x 
float].
-///The upper 64 bits of the result vector are set to zero.
+///Rounds inexact results according to the rounding control bits in the
+///MXCSR register. The upper 64 bits of the result vector are set to zero.
 ///
 /// \headerfile 
 ///
@@ -1300,9 +1301,13 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS 
_mm_cvtepi32_pd(__m128i __a) {
 }
 
 /// Converts the two double-precision floating-point elements of a
-///128-bit vector of [2 x double] into two signed 32-bit integer values,
-///returned in the lower 64 bits of a 128-bit vector of [4 x i32]. The 
upper
-///64 bits of the result vector are set to zero.
+///128-bit vector of [2 

[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-07 Thread YAMAMOTO Takashi via cfe-commits


@@ -999,25 +1002,42 @@ bool 
WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module ) {
   // Register __wasm_longjmp function, which calls __builtin_wasm_longjmp.
   FunctionType *FTy = FunctionType::get(
   IRB.getVoidTy(), {Int8PtrTy, IRB.getInt32Ty()}, false);
-  WasmLongjmpF = getEmscriptenFunction(FTy, "__wasm_longjmp", );
+  if (EnableWasmAltSjLj) {
+WasmLongjmpF = getEmscriptenFunction(FTy, "__wasm_sjlj_longjmp", );
+  } else {
+WasmLongjmpF = getEmscriptenFunction(FTy, "__wasm_longjmp", );
+  }
   WasmLongjmpF->addFnAttr(Attribute::NoReturn);
 }
 
 if (SetjmpF) {
   Type *Int8PtrTy = IRB.getPtrTy();
   Type *Int32PtrTy = IRB.getPtrTy();
   Type *Int32Ty = IRB.getInt32Ty();
-  // Register saveSetjmp function
-  FunctionType *SetjmpFTy = SetjmpF->getFunctionType();
-  FunctionType *FTy = FunctionType::get(
-  Int32PtrTy,
-  {SetjmpFTy->getParamType(0), Int32Ty, Int32PtrTy, Int32Ty}, false);
-  SaveSetjmpF = getEmscriptenFunction(FTy, "saveSetjmp", );
 
   // Register testSetjmp function

yamt wrote:

oops. fixed. thank you.

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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-07 Thread YAMAMOTO Takashi via cfe-commits

https://github.com/yamt updated https://github.com/llvm/llvm-project/pull/84137

>From 1283ae6b5536810f8fbe183eda80997aa9f5cdc3 Mon Sep 17 00:00:00 2001
From: YAMAMOTO Takashi 
Date: Fri, 9 Feb 2024 15:49:55 +0900
Subject: [PATCH 1/3] [WebAssembly] Implement an alternative translation for
 -wasm-enable-sjlj

Instead of maintaining per-function-invocation malloc()'ed tables to
track which functions each label belongs to, store the equivalent info
in jump buffers (jmp_buf) themselves.

Also, use a less emscripten-looking ABI symbols:

saveSetjmp -> __wasm_sjlj_setjmp
testSetjmp -> __wasm_sjlj_test
getTempRet0-> (removed)
__wasm_longjmp -> __wasm_sjlj_longjmp

Enabled with:

-mllvm -wasm-enable-sjlj -mllvm -experimental-wasm-enable-alt-sjlj

(-experimental-wasm-enable-alt-sjlj is the new option this change
introduces.)

While I want to use this for WASI, it should work for emscripten as well.

An example runtime and a few tests:
https://github.com/yamt/garbage/tree/wasm-sjlj-alt2/wasm/longjmp

Discussion:
https://docs.google.com/document/d/1ZvTPT36K5jjiedF8MCXbEmYjULJjI723aOAks1IdLLg/edit
---
 clang/lib/Driver/ToolChains/WebAssembly.cpp   |  14 ++
 .../MCTargetDesc/WebAssemblyMCTargetDesc.cpp  |   3 +
 .../MCTargetDesc/WebAssemblyMCTargetDesc.h|   1 +
 .../WebAssemblyLowerEmscriptenEHSjLj.cpp  | 174 +++---
 .../WebAssembly/WebAssemblyTargetMachine.cpp  |   4 +
 5 files changed, 131 insertions(+), 65 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index b8c2573d6265fb..2e7c8e6e8d13f7 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -386,6 +386,20 @@ void WebAssembly::addClangTargetOptions(const ArgList 
,
   // Backend needs '-exception-model=wasm' to use Wasm EH instructions
   CC1Args.push_back("-exception-model=wasm");
 }
+
+if (Opt.starts_with("-experimental-wasm-enable-alt-sjlj")) {
+  // '-mllvm -experimental-wasm-enable-alt-sjlj'  should be used with
+  // '-mllvm -wasm-enable-sjlj'
+  bool HasWasmEnableSjlj = false;
+  for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
+if (StringRef(A->getValue(0)) == "-wasm-enable-sjlj")
+  HasWasmEnableSjlj = true;
+  }
+  if (!HasWasmEnableSjlj)
+getDriver().Diag(diag::err_drv_argument_only_allowed_with)
+<< "-mllvm -experimental-wasm-enable-alt-sjlj"
+<< "-mllvm -wasm-enable-sjlj";
+}
   }
 }
 
diff --git 
a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp 
b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp
index e8f58a19d25e3b..7f15742367be09 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp
@@ -54,6 +54,9 @@ cl::opt
 // setjmp/longjmp handling using wasm EH instrutions
 cl::opt WebAssembly::WasmEnableSjLj(
 "wasm-enable-sjlj", cl::desc("WebAssembly setjmp/longjmp handling"));
+cl::opt WebAssembly::WasmEnableAltSjLj(
+"experimental-wasm-enable-alt-sjlj",
+cl::desc("Use experimental alternate ABI for --wasm-enable-sjlj"));
 
 static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
   const Triple ,
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h 
b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
index 15aeaaeb8c4a4e..d23de9d407d894 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
@@ -44,6 +44,7 @@ extern cl::opt WasmEnableEmEH;   // asm.js-style EH
 extern cl::opt WasmEnableEmSjLj; // asm.js-style SjLJ
 extern cl::opt WasmEnableEH; // EH using Wasm EH instructions
 extern cl::opt WasmEnableSjLj;   // SjLj using Wasm EH instructions
+extern cl::opt WasmEnableAltSjLj; // Alt ABI for WasmEnableSjLj
 
 enum OperandType {
   /// Basic block label in a branch construct.
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
index 77e6640d5a8224..fc76757011f5d8 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -300,6 +300,7 @@ class WebAssemblyLowerEmscriptenEHSjLj final : public 
ModulePass {
   bool EnableEmEH; // Enable Emscripten exception handling
   bool EnableEmSjLj;   // Enable Emscripten setjmp/longjmp handling
   bool EnableWasmSjLj; // Enable Wasm setjmp/longjmp handling
+  bool EnableWasmAltSjLj; // Alt ABI for EnableWasmSjLj
   bool DoSjLj; // Whether we actually perform setjmp/longjmp handling
 
   GlobalVariable *ThrewGV = nullptr;  // __THREW__ (Emscripten)
@@ -368,7 +369,8 @@ class 

[clang] [Clang] [Sema] No longer diagnose type definitions in `offsetof` in C23 mode (PR #84169)

2024-03-07 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Should we verify that we diagnose the case where the definition includes a 
comma?

https://github.com/llvm/llvm-project/pull/84169
___
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 bugprone-suspicious-stringview-data-usage check (PR #83716)

2024-03-07 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,101 @@
+//===--- SuspiciousStringviewDataUsageCheck.cpp - clang-tidy 
--===//
+//
+// 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 "SuspiciousStringviewDataUsageCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+SuspiciousStringviewDataUsageCheck::SuspiciousStringviewDataUsageCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringViewTypes(utils::options::parseStringList(Options.get(
+  "StringViewTypes", "::std::basic_string_view;::llvm::StringRef"))),
+  AllowedCallees(
+  utils::options::parseStringList(Options.get("AllowedCallees", ""))) 
{}
+
+void SuspiciousStringviewDataUsageCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "StringViewTypes",
+utils::options::serializeStringList(StringViewTypes));
+  Options.store(Opts, "AllowedCallees",
+utils::options::serializeStringList(AllowedCallees));
+}
+
+bool SuspiciousStringviewDataUsageCheck::isLanguageVersionSupported(
+const LangOptions ) const {
+  return LangOpts.CPlusPlus;
+}
+
+std::optional
+SuspiciousStringviewDataUsageCheck::getCheckTraversalKind() const {
+  return TK_AsIs;
+}
+
+void SuspiciousStringviewDataUsageCheck::registerMatchers(MatchFinder *Finder) 
{
+
+  auto AncestorCall = anyOf(
+  cxxConstructExpr(), callExpr(unless(cxxOperatorCallExpr())), 
lambdaExpr(),
+  initListExpr(
+  hasType(qualType(hasCanonicalType(hasDeclaration(recordDecl()));
+
+  auto DataMethod =
+  cxxMethodDecl(hasName("data"),
+ofClass(matchers::matchesAnyListedName(StringViewTypes)));
+
+  auto DataWithSelfCall =
+  cxxMemberCallExpr(on(ignoringParenImpCasts(expr().bind("self"))),
+callee(DataMethod))
+  .bind("data-call");

5chmidti wrote:

This is unused

https://github.com/llvm/llvm-project/pull/83716
___
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 bugprone-suspicious-stringview-data-usage check (PR #83716)

2024-03-07 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/83716
___
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 bugprone-suspicious-stringview-data-usage check (PR #83716)

2024-03-07 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.

Found something unused, otherwise LGTM

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


[clang] [clang][test] Fix constant __builtin_popcountg test requiring __int128 (PR #84412)

2024-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: OverMighty (overmighty)


Changes

See 
https://lab.llvm.org/buildbot/#/builders/245/builds/21611/steps/5/logs/FAIL__Clang__constant-builtins-2_c.


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


1 Files Affected:

- (modified) clang/test/Sema/constant-builtins-2.c (+2) 


``diff
diff --git a/clang/test/Sema/constant-builtins-2.c 
b/clang/test/Sema/constant-builtins-2.c
index 0935abe4c65fbe..6dd1d88759c751 100644
--- a/clang/test/Sema/constant-builtins-2.c
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -242,7 +242,9 @@ char popcount12[__builtin_popcountg(0xF0F0U) == 8 ? 1 : -1];
 char popcount13[__builtin_popcountg(~0U) == BITSIZE(int) ? 1 : -1];
 char popcount14[__builtin_popcountg(~0UL) == BITSIZE(long) ? 1 : -1];
 char popcount15[__builtin_popcountg(~0ULL) == BITSIZE(long long) ? 1 : -1];
+#ifdef __SIZEOF_INT128__
 char popcount16[__builtin_popcountg(~(unsigned __int128)0) == 
BITSIZE(__int128) ? 1 : -1];
+#endif
 char popcount17[__builtin_popcountg(~(unsigned _BitInt(128))0) == 
BITSIZE(_BitInt(128)) ? 1 : -1];
 
 char parity1[__builtin_parity(0) == 0 ? 1 : -1];

``




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


[clang] [clang][test] Fix constant __builtin_popcountg test requiring __int128 (PR #84412)

2024-03-07 Thread via cfe-commits

overmighty wrote:

cc @Sirraide 

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


[clang] [clang][test] Fix constant __builtin_popcountg test requiring __int128 (PR #84412)

2024-03-07 Thread via cfe-commits

https://github.com/overmighty created 
https://github.com/llvm/llvm-project/pull/84412

See 
https://lab.llvm.org/buildbot/#/builders/245/builds/21611/steps/5/logs/FAIL__Clang__constant-builtins-2_c.


>From ba035f2a40260398c439d6e34b7ed3a5fe6a10d0 Mon Sep 17 00:00:00 2001
From: OverMighty 
Date: Fri, 8 Mar 2024 00:54:32 +
Subject: [PATCH] [clang][test] Fix constant __builtin_popcountg test requiring
 __int128

---
 clang/test/Sema/constant-builtins-2.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/Sema/constant-builtins-2.c 
b/clang/test/Sema/constant-builtins-2.c
index 0935abe4c65fbe..6dd1d88759c751 100644
--- a/clang/test/Sema/constant-builtins-2.c
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -242,7 +242,9 @@ char popcount12[__builtin_popcountg(0xF0F0U) == 8 ? 1 : -1];
 char popcount13[__builtin_popcountg(~0U) == BITSIZE(int) ? 1 : -1];
 char popcount14[__builtin_popcountg(~0UL) == BITSIZE(long) ? 1 : -1];
 char popcount15[__builtin_popcountg(~0ULL) == BITSIZE(long long) ? 1 : -1];
+#ifdef __SIZEOF_INT128__
 char popcount16[__builtin_popcountg(~(unsigned __int128)0) == 
BITSIZE(__int128) ? 1 : -1];
+#endif
 char popcount17[__builtin_popcountg(~(unsigned _BitInt(128))0) == 
BITSIZE(_BitInt(128)) ? 1 : -1];
 
 char parity1[__builtin_parity(0) == 0 ? 1 : -1];

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-03-07 Thread Phoebe Wang via cfe-commits


@@ -18543,7 +18552,19 @@ GetTLSADDR(SelectionDAG , SDValue Chain, 
GlobalAddressSDNode *GA,
   MFI.setHasCalls(true);
 
   SDValue Glue = Chain.getValue(1);
-  return DAG.getCopyFromReg(Chain, dl, ReturnReg, PtrVT, Glue);
+  SDValue Ret = DAG.getCopyFromReg(Chain, dl, ReturnReg, PtrVT, Glue);
+
+  if (!UseTLSDESC)
+return Ret;
+
+  const X86Subtarget  = DAG.getSubtarget();
+  unsigned Seg = Subtarget.is64Bit() ? X86AS::FS : X86AS::GS;
+
+  Value *Ptr = Constant::getNullValue(PointerType::get(*DAG.getContext(), 
Seg));
+  SDValue Offset =
+  DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), DAG.getIntPtrConstant(0, dl),

phoebewang wrote:

Quote from https://www.fsfla.org/~lxoliva/writeups/TLS/RFC-TLSDESC-x86.txt

> An alternate design in which the function called through the TLS
descriptor returns not the TP offset, but rather the address of the
variable of interest, could refrain from adding %gs:0 to the value
returned by the call to compute the address of a symbol, and from
using the %gs: prefix when accessing the variable, but it would
require the use of a longer call instruction to enable proper
relaxation.  The call instruction would have to be 7, instead of 2
bytes long, such that the linker could relax it to `addl %gs:0, %eax'.
This would make code that accesses the variable 4 bytes longer on
average (5 bytes minus one used by the %gs prefix), whereas code that
computes its address would be shorter by only two bytes.  It's not
clear such a change would be profitable.

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-03-07 Thread Phoebe Wang via cfe-commits


@@ -18522,13 +18522,21 @@ GetTLSADDR(SelectionDAG , SDValue Chain, 
GlobalAddressSDNode *GA,
   MachineFrameInfo  = DAG.getMachineFunction().getFrameInfo();
   SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
   SDLoc dl(GA);
-  SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl,
-   GA->getValueType(0),
-   GA->getOffset(),
-   OperandFlags);
+  SDValue TGA;
+  bool UseTLSDESC = DAG.getTarget().useTLSDESC();
+  if (LocalDynamic && UseTLSDESC) {
+TGA = DAG.getTargetExternalSymbol("_TLS_MODULE_BASE_", PtrVT, 
OperandFlags);
+auto UI = TGA->use_begin();
+if (UI != TGA->use_end())
+  return SDValue(*UI->use_begin()->use_begin(), 0);

phoebewang wrote:

Done.

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


[clang] [llvm] BPF address space insn (PR #84410)

2024-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (4ast)


Changes



---

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


23 Files Affected:

- (modified) clang/lib/Basic/Targets/BPF.cpp (+3) 
- (modified) clang/test/Preprocessor/bpf-predefined-macros.c (+8) 
- (modified) llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp (+1) 
- (modified) llvm/lib/Target/BPF/BPF.h (+8) 
- (added) llvm/lib/Target/BPF/BPFASpaceCastSimplifyPass.cpp (+92) 
- (modified) llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp (+116) 
- (modified) llvm/lib/Target/BPF/BPFISelLowering.cpp (+32) 
- (modified) llvm/lib/Target/BPF/BPFISelLowering.h (+3-1) 
- (modified) llvm/lib/Target/BPF/BPFInstrInfo.td (+21) 
- (modified) llvm/lib/Target/BPF/BPFTargetMachine.cpp (+5) 
- (modified) llvm/lib/Target/BPF/CMakeLists.txt (+1) 
- (added) llvm/test/CodeGen/BPF/addr-space-auto-casts.ll (+78) 
- (added) llvm/test/CodeGen/BPF/addr-space-cast.ll (+22) 
- (added) llvm/test/CodeGen/BPF/addr-space-gep-chain.ll (+25) 
- (added) llvm/test/CodeGen/BPF/addr-space-globals.ll (+30) 
- (added) llvm/test/CodeGen/BPF/addr-space-globals2.ll (+25) 
- (added) llvm/test/CodeGen/BPF/addr-space-phi.ll (+52) 
- (added) llvm/test/CodeGen/BPF/addr-space-simplify-1.ll (+19) 
- (added) llvm/test/CodeGen/BPF/addr-space-simplify-2.ll (+21) 
- (added) llvm/test/CodeGen/BPF/addr-space-simplify-3.ll (+26) 
- (added) llvm/test/CodeGen/BPF/addr-space-simplify-4.ll (+21) 
- (added) llvm/test/CodeGen/BPF/addr-space-simplify-5.ll (+25) 
- (modified) llvm/test/CodeGen/BPF/assembler-disassembler.s (+7) 


``diff
diff --git a/clang/lib/Basic/Targets/BPF.cpp b/clang/lib/Basic/Targets/BPF.cpp
index e3fbbb720d0694..26a54f631fcfc4 100644
--- a/clang/lib/Basic/Targets/BPF.cpp
+++ b/clang/lib/Basic/Targets/BPF.cpp
@@ -35,6 +35,9 @@ void BPFTargetInfo::getTargetDefines(const LangOptions ,
 Builder.defineMacro("__BPF_CPU_VERSION__", "0");
 return;
   }
+
+  Builder.defineMacro("__BPF_FEATURE_ARENA_CAST");
+
   if (CPU.empty() || CPU == "generic" || CPU == "v1") {
 Builder.defineMacro("__BPF_CPU_VERSION__", "1");
 return;
diff --git a/clang/test/Preprocessor/bpf-predefined-macros.c 
b/clang/test/Preprocessor/bpf-predefined-macros.c
index ff4d00ac3bcfcc..fea24d1ea0ff7b 100644
--- a/clang/test/Preprocessor/bpf-predefined-macros.c
+++ b/clang/test/Preprocessor/bpf-predefined-macros.c
@@ -61,6 +61,9 @@ int r;
 #ifdef __BPF_FEATURE_ST
 int s;
 #endif
+#ifdef __BPF_FEATURE_ARENA_CAST
+int t;
+#endif
 
 // CHECK: int b;
 // CHECK: int c;
@@ -90,6 +93,11 @@ int s;
 // CPU_V4: int r;
 // CPU_V4: int s;
 
+// CPU_V1: int t;
+// CPU_V2: int t;
+// CPU_V3: int t;
+// CPU_V4: int t;
+
 // CPU_GENERIC: int g;
 
 // CPU_PROBE: int f;
diff --git a/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp 
b/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
index 90697c6645be2f..3fbd14facaf804 100644
--- a/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
+++ b/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
@@ -270,6 +270,7 @@ struct BPFOperand : public MCParsedAsmOperand {
 .Case("xchg32_32", true)
 .Case("cmpxchg_64", true)
 .Case("cmpxchg32_32", true)
+.Case("addr_space_cast", true)
 .Default(false);
   }
 };
diff --git a/llvm/lib/Target/BPF/BPF.h b/llvm/lib/Target/BPF/BPF.h
index 5c77d183e1ef3d..bbdbdbbde53228 100644
--- a/llvm/lib/Target/BPF/BPF.h
+++ b/llvm/lib/Target/BPF/BPF.h
@@ -66,6 +66,14 @@ class BPFIRPeepholePass : public 
PassInfoMixin {
   static bool isRequired() { return true; }
 };
 
+class BPFASpaceCastSimplifyPass
+: public PassInfoMixin {
+public:
+  PreservedAnalyses run(Function , FunctionAnalysisManager );
+
+  static bool isRequired() { return true; }
+};
+
 class BPFAdjustOptPass : public PassInfoMixin {
 public:
   PreservedAnalyses run(Module , ModuleAnalysisManager );
diff --git a/llvm/lib/Target/BPF/BPFASpaceCastSimplifyPass.cpp 
b/llvm/lib/Target/BPF/BPFASpaceCastSimplifyPass.cpp
new file mode 100644
index 00..d32cecc073fab9
--- /dev/null
+++ b/llvm/lib/Target/BPF/BPFASpaceCastSimplifyPass.cpp
@@ -0,0 +1,92 @@
+//=== BPFIRPeephole.cpp - IR Peephole Transformation 
--===//
+//
+// 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 "BPF.h"
+#include 
+
+#define DEBUG_TYPE "bpf-aspace-simplify"
+
+using namespace llvm;
+
+namespace {
+
+struct CastGEPCast {
+  AddrSpaceCastInst *OuterCast;
+
+  // Match chain of instructions:
+  //   %inner = addrspacecast N->M
+  //   %gep   = getelementptr %inner, ...
+  //   %outer = addrspacecast M->N %gep
+  // Where I is %outer.
+  static std::optional match(Value *I) {
+auto *OuterCast = dyn_cast(I);
+if (!OuterCast)
+  return 

[clang] [llvm] BPF address space insn (PR #84410)

2024-03-07 Thread via cfe-commits

https://github.com/4ast created https://github.com/llvm/llvm-project/pull/84410

None

>From dd19f019066852dba15259cd201ce1b94fa5b6e6 Mon Sep 17 00:00:00 2001
From: Eduard Zingerman 
Date: Fri, 26 Jan 2024 04:18:32 +0200
Subject: [PATCH 1/4] [BPF] Add addr_space_cast BPF instruction

This commit aims to support BPF arena kernel side feature [0]:
- arena is a memory region accessible from both
  BPF program and userspace;
- base pointers for this memory region differ between
  kernel and user spaces;
- `dst_reg = addr_space_cast(src_reg, dst_addr_space, src_addr_space)`
  translates src_reg, a pointer in src_addr_space
  to dst_reg, equivalent pointer in dst_addr_space,
  {src,dst}_addr_space are immediate constants;
- number 0 is assigned to kernel address space;
- number 1 is assigned to user address space.

On the LLVM side, the goal is to make load and store operations on
arena pointers "transparent" for BPF programs:
- assume that pointers with non-zero address space are pointers to
  arena memory;
- assume that arena is identified by address space number;
- assume that address space zero corresponds to kernel address space;
- assume that every BPF-side load or store from arena is done via
  pointer in user address space, thus convert base pointers using
  `addr_space_cast(src_reg, 0, 1)`;

Only load, store, cmpxchg and atomicrmw IR instructions are handled by
this transformation.

For example, the following C code:

   #define __as __attribute__((address_space(1)))
   void copy(int __as *from, int __as *to) { *to = *from; }

Compiled to the following IR:

define void @copy(ptr addrspace(1) %from, ptr addrspace(1) %to) {
entry:
  %0 = load i32, ptr addrspace(1) %from, align 4
  store i32 %0, ptr addrspace(1) %to, align 4
  ret void
}

Is transformed to:

%to2 = addrspacecast ptr addrspace(1) %to to ptr ;; !
%from1 = addrspacecast ptr addrspace(1) %from to ptr ;; !
%0 = load i32, ptr %from1, align 4, !tbaa !3
store i32 %0, ptr %to2, align 4, !tbaa !3
ret void

And compiled as:

r2 = addr_space_cast(r2, 0, 1)
r1 = addr_space_cast(r1, 0, 1)
r1 = *(u32 *)(r1 + 0)
*(u32 *)(r2 + 0) = r1
exit

Internally:
- piggy-back `BPFCheckAndAdjustIR` pass to insert address space casts
  for base pointer of memory access instructions, when base pointer
  has non-zero address space;
- modify `BPFInstrInfo.td` and `BPFIselLowering.cpp` to allow
  translation of `addrspacecast` instruction:
  - define new SDNode type `BPFAddrSpaceCast`;
  - lower `addrspacecast` as such SDNode;
  - define new machine instruction: `ADDR_SPACE_CAST`;
  - define pattern to select `ADDR_SPACE_CAST` for `BPFAddrSpaceCast` nodes.

[0] 
https://lore.kernel.org/bpf/20240206220441.38311-1-alexei.starovoi...@gmail.com/
---
 .../lib/Target/BPF/AsmParser/BPFAsmParser.cpp |   1 +
 llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp   | 104 ++
 llvm/lib/Target/BPF/BPFISelLowering.cpp   |  32 ++
 llvm/lib/Target/BPF/BPFISelLowering.h |   4 +-
 llvm/lib/Target/BPF/BPFInstrInfo.td   |  21 
 .../test/CodeGen/BPF/addr-space-auto-casts.ll |  78 +
 llvm/test/CodeGen/BPF/addr-space-cast.ll  |  22 
 llvm/test/CodeGen/BPF/addr-space-gep-chain.ll |  25 +
 llvm/test/CodeGen/BPF/addr-space-phi.ll   |  52 +
 .../test/CodeGen/BPF/assembler-disassembler.s |   7 ++
 10 files changed, 345 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/BPF/addr-space-auto-casts.ll
 create mode 100644 llvm/test/CodeGen/BPF/addr-space-cast.ll
 create mode 100644 llvm/test/CodeGen/BPF/addr-space-gep-chain.ll
 create mode 100644 llvm/test/CodeGen/BPF/addr-space-phi.ll

diff --git a/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp 
b/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
index 90697c6645be2f..3fbd14facaf804 100644
--- a/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
+++ b/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
@@ -270,6 +270,7 @@ struct BPFOperand : public MCParsedAsmOperand {
 .Case("xchg32_32", true)
 .Case("cmpxchg_64", true)
 .Case("cmpxchg32_32", true)
+.Case("addr_space_cast", true)
 .Default(false);
   }
 };
diff --git a/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp 
b/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
index 81effc9b1db46c..d39a6b57aafed4 100644
--- a/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
+++ b/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
@@ -14,6 +14,8 @@
 // optimizations are done and those builtins can be removed.
 //   - remove llvm.bpf.getelementptr.and.load builtins.
 //   - remove llvm.bpf.getelementptr.and.store builtins.
+//   - for loads and stores with base addresses from non-zero address space
+// cast base address to zero address space (support for BPF arenas).
 //
 
//===--===//
 
@@ -55,6 +57,7 @@ class BPFCheckAndAdjustIR final : public ModulePass {
   bool 

[clang] [clang][analyzer] Fix StreamChecker `ftell` and `fgetpos` at indeterminate file position. (PR #84191)

2024-03-07 Thread Ben Shi via cfe-commits

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

After eliminating `std::bind`, I hope there can be further solutions to reduce 
duplications.

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


[clang] [clang] Implement constexpr support for __builtin_popcountg (PR #84318)

2024-03-07 Thread via cfe-commits

overmighty wrote:

Usage of `__int128` in the test broke the clang-armv8-quick build: 
https://lab.llvm.org/buildbot/#/builders/245/builds/21611/steps/5/logs/FAIL__Clang__constant-builtins-2_c.

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


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

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


@@ -8545,6 +8545,11 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">,
+ Values<"2016, 2017, 2018, 2021, 202x">;

bob80905 wrote:

No, I need the change in OptTable.h to have access to the set of valid values 
to the argument. With it, I can then loop through the valid values and 
determine which transformation to apply. And, if there are 0 matches, I know 
that the given value is invalid, so I emit a diagnostic. I need some place to 
store all valid values, and I figured that the option object would be the most 
convenient.

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


[clang] [clang-repl] Expose RuntimeInterfaceBuilder to allow customization (PR #83126)

2024-03-07 Thread Stefan Gränitz via cfe-commits

weliveindetail wrote:

Squashed, rebased, polished and tested

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


[clang] [clang-repl] Expose RuntimeInterfaceBuilder to allow customization (PR #83126)

2024-03-07 Thread Stefan Gränitz via cfe-commits

https://github.com/weliveindetail updated 
https://github.com/llvm/llvm-project/pull/83126

From 8ba5253b20d1aef0a542506a667f6b66b84ac5b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Fri, 8 Mar 2024 00:08:56 +0100
Subject: [PATCH] [clang-repl] Expose RuntimeInterfaceBuilder for
 customizations

---
 clang/include/clang/Interpreter/Interpreter.h |  35 ++-
 clang/lib/Interpreter/Interpreter.cpp | 247 ++
 clang/unittests/Interpreter/CMakeLists.txt|   1 +
 .../Interpreter/InterpreterExtensionsTest.cpp |  79 ++
 4 files changed, 253 insertions(+), 109 deletions(-)
 create mode 100644 clang/unittests/Interpreter/InterpreterExtensionsTest.cpp

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index c8f932e95c4798..d972d960dcb7cd 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -18,6 +18,7 @@
 #include "clang/AST/GlobalDecl.h"
 #include "clang/Interpreter/PartialTranslationUnit.h"
 #include "clang/Interpreter/Value.h"
+#include "clang/Sema/Ownership.h"
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
@@ -75,17 +76,26 @@ class IncrementalCompilerBuilder {
   llvm::StringRef CudaSDKPath;
 };
 
+/// Generate glue code between the Interpreter's built-in runtime and user 
code.
+class RuntimeInterfaceBuilder {
+public:
+  virtual ~RuntimeInterfaceBuilder() = default;
+
+  using TransformExprFunction = ExprResult(RuntimeInterfaceBuilder *Builder,
+   Expr *, ArrayRef);
+  virtual TransformExprFunction *getPrintValueTransformer() = 0;
+};
+
 /// Provides top-level interfaces for incremental compilation and execution.
 class Interpreter {
   std::unique_ptr TSCtx;
   std::unique_ptr IncrParser;
   std::unique_ptr IncrExecutor;
+  std::unique_ptr RuntimeIB;
 
   // An optional parser for CUDA offloading
   std::unique_ptr DeviceParser;
 
-  Interpreter(std::unique_ptr CI, llvm::Error );
-
   llvm::Error CreateExecutor();
   unsigned InitPTUSize = 0;
 
@@ -94,8 +104,25 @@ class Interpreter {
   // printing happens, it's in an invalid state.
   Value LastValue;
 
+  // Add a call to an Expr to report its result. We query the function from
+  // RuntimeInterfaceBuilder once and store it as a function pointer to avoid
+  // frequent virtual function calls.
+  RuntimeInterfaceBuilder::TransformExprFunction *AddPrintValueCall = nullptr;
+
+protected:
+  // Derived classes can make use an extended interface of the Interpreter.
+  // That's useful for testing and out-of-tree clients.
+  Interpreter(std::unique_ptr CI, llvm::Error );
+
+  // Lazily construct the RuntimeInterfaceBuilder. The provided instance will 
be
+  // used for the entire lifetime of the interpreter. The default 
implementation
+  // targets the in-process __clang_Interpreter runtime. Override this to use a
+  // custom runtime.
+  virtual std::unique_ptr FindRuntimeInterface();
+
 public:
-  ~Interpreter();
+  virtual ~Interpreter();
+
   static llvm::Expected>
   create(std::unique_ptr CI);
   static llvm::Expected>
@@ -143,8 +170,6 @@ class Interpreter {
 private:
   size_t getEffectivePTUSize() const;
 
-  bool FindRuntimeInterface();
-
   llvm::DenseMap Dtors;
 
   llvm::SmallVector ValuePrintingInfo;
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 37696b28976428..3485da8196683a 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -507,9 +507,13 @@ static constexpr llvm::StringRef MagicRuntimeInterface[] = 
{
 "__clang_Interpreter_SetValueWithAlloc",
 "__clang_Interpreter_SetValueCopyArr", "__ci_newtag"};
 
-bool Interpreter::FindRuntimeInterface() {
+static std::unique_ptr
+createInProcessRuntimeInterfaceBuilder(Interpreter , ASTContext ,
+   Sema );
+
+std::unique_ptr Interpreter::FindRuntimeInterface() {
   if (llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E != nullptr; }))
-return true;
+return nullptr;
 
   Sema  = getCompilerInstance()->getSema();
   ASTContext  = S.getASTContext();
@@ -528,120 +532,34 @@ bool Interpreter::FindRuntimeInterface() {
 
   if (!LookupInterface(ValuePrintingInfo[NoAlloc],
MagicRuntimeInterface[NoAlloc]))
-return false;
+return nullptr;
   if (!LookupInterface(ValuePrintingInfo[WithAlloc],
MagicRuntimeInterface[WithAlloc]))
-return false;
+return nullptr;
   if (!LookupInterface(ValuePrintingInfo[CopyArray],
MagicRuntimeInterface[CopyArray]))
-return false;
+return nullptr;
   if (!LookupInterface(ValuePrintingInfo[NewTag],
MagicRuntimeInterface[NewTag]))
-return false;
-  return true;
+return nullptr;
+
+  return createInProcessRuntimeInterfaceBuilder(*this, Ctx, S);
 }
 
 namespace {
 
-class 

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

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


@@ -8545,6 +8545,11 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">,
+ Values<"2016, 2017, 2018, 2021, 202x">;

python3kgae wrote:

Will you remove the change in OptTable.h then?

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


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-07 Thread Alexandros Lamprineas via cfe-commits


@@ -85,7 +85,21 @@ int hoo(void) {
 }
 
 
+// This should generate one target version but no resolver.
+__attribute__((target_version("default"))) int 
unused_with_forward_default_decl(void);
+__attribute__((target_version("mops"))) int 
unused_with_forward_default_decl(void) { return 0; }
 
+// FIXME: If the default declaration follows the non-default definition,

labrinea wrote:

This bug (if we consider it as such) seems unrelated to this patch, but since I 
found it it deserves a test at least to monitor what we are currently 
generating for it.

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


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Alexandros Lamprineas (labrinea)


Changes

We would like the resolver to be generated eagerly, even if the versioned 
function is not called from the current translation unit. Fixes #81494.

---

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+5-2) 
- (modified) clang/test/CodeGen/attr-target-version.c (+239-164) 
- (modified) clang/test/CodeGenCXX/attr-target-version.cpp (+120-52) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 967319bdfc4571..ee688a4c17c1d4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3969,8 +3969,11 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
-  } else if (FD->hasAttr()) {
-GetOrCreateMultiVersionResolver(GD);
+  } else if (auto *TVA = FD->getAttr()) {
+EmitGlobalFunctionDefinition(GD, GV);
+// Emit the resolver alongside with the default version definition.
+if (TVA->isDefaultVersion() && FD->doesThisDeclarationHaveABody())
+  GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
 }
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index b7112c783da913..cb425b12702db3 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -85,7 +85,21 @@ int hoo(void) {
 }
 
 
+// This should generate one target version but no resolver.
+__attribute__((target_version("default"))) int 
unused_with_forward_default_decl(void);
+__attribute__((target_version("mops"))) int 
unused_with_forward_default_decl(void) { return 0; }
 
+// FIXME: If the default declaration follows the non-default definition,
+//then target versioning does not trigger.
+__attribute__((target_version("aes"))) int unused_with_default_decl(void) { 
return 0; }
+__attribute__((target_version("default"))) int unused_with_default_decl(void);
+
+// This should generate two target versions and the resolver.
+__attribute__((target_version("sve"))) int unused_with_default_def(void) { 
return 0; }
+__attribute__((target_version("default"))) int unused_with_default_def(void) { 
return 1; }
+
+// This should generate a normal function.
+__attribute__((target_version("rdm"))) int unused_without_default(void) { 
return 0; }
 
 
 //.
@@ -97,6 +111,7 @@ int hoo(void) {
 // CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
 // CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
 // CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
+// CHECK: @unused_with_default_def.ifunc = weak_odr alias i32 (), ptr 
@unused_with_default_def
 // CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
 // CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
 // CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
@@ -104,6 +119,7 @@ int hoo(void) {
 // CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 // CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
 // CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @unused_with_default_def = weak_odr ifunc i32 (), ptr 
@unused_with_default_def.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv._MflagmMfp16fmlMrng
@@ -113,29 +129,66 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_one._Mls64Msimd
+// CHECK-LABEL: define {{[^@]+}}@fmv._Mflagm2Msme-i16i64
 // CHECK-SAME: () #[[ATTR1:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:ret i32 1
+// CHECK-NEXT:ret i32 2
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_two._Mfp
-// CHECK-SAME: () #[[ATTR1]] {
+// CHECK-LABEL: define {{[^@]+}}@fmv._MlseMsha2
+// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:ret i32 1
+// CHECK-NEXT:ret i32 3
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@foo
-// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
+// CHECK-LABEL: define {{[^@]+}}@fmv._MdotprodMls64_accdata
+// CHECK-SAME: () #[[ATTR3:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[CALL:%.*]] = call i32 @fmv()
-// CHECK-NEXT:[[CALL1:%.*]] = call i32 @fmv_one()
-// CHECK-NEXT:[[ADD:%.*]] = add nsw i32 [[CALL]], [[CALL1]]
-// CHECK-NEXT:[[CALL2:%.*]] = call i32 @fmv_two()
-// CHECK-NEXT:[[ADD3:%.*]] = add nsw i32 [[ADD]], [[CALL2]]
-// CHECK-NEXT:ret i32 [[ADD3]]
+// CHECK-NEXT:ret i32 4
+//
+//
+// CHECK: Function Attrs: noinline 

[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-07 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/84405

We would like the resolver to be generated eagerly, even if the versioned 
function is not called from the current translation unit. Fixes #81494.

>From d2572439a8e130c03febd60366962c96b5b4501d Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 7 Mar 2024 22:25:13 +
Subject: [PATCH] [FMV] Emit the resolver along with the default version
 definition.

We would like the resolver to be generated eagerly, even if the
versioned function is not called from the current translation
unit. Fixes #81494.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |   7 +-
 clang/test/CodeGen/attr-target-version.c  | 403 +++---
 clang/test/CodeGenCXX/attr-target-version.cpp | 172 +---
 3 files changed, 364 insertions(+), 218 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 967319bdfc4571..ee688a4c17c1d4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3969,8 +3969,11 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
-  } else if (FD->hasAttr()) {
-GetOrCreateMultiVersionResolver(GD);
+  } else if (auto *TVA = FD->getAttr()) {
+EmitGlobalFunctionDefinition(GD, GV);
+// Emit the resolver alongside with the default version definition.
+if (TVA->isDefaultVersion() && FD->doesThisDeclarationHaveABody())
+  GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
 }
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index b7112c783da913..cb425b12702db3 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -85,7 +85,21 @@ int hoo(void) {
 }
 
 
+// This should generate one target version but no resolver.
+__attribute__((target_version("default"))) int 
unused_with_forward_default_decl(void);
+__attribute__((target_version("mops"))) int 
unused_with_forward_default_decl(void) { return 0; }
 
+// FIXME: If the default declaration follows the non-default definition,
+//then target versioning does not trigger.
+__attribute__((target_version("aes"))) int unused_with_default_decl(void) { 
return 0; }
+__attribute__((target_version("default"))) int unused_with_default_decl(void);
+
+// This should generate two target versions and the resolver.
+__attribute__((target_version("sve"))) int unused_with_default_def(void) { 
return 0; }
+__attribute__((target_version("default"))) int unused_with_default_def(void) { 
return 1; }
+
+// This should generate a normal function.
+__attribute__((target_version("rdm"))) int unused_without_default(void) { 
return 0; }
 
 
 //.
@@ -97,6 +111,7 @@ int hoo(void) {
 // CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
 // CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
 // CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
+// CHECK: @unused_with_default_def.ifunc = weak_odr alias i32 (), ptr 
@unused_with_default_def
 // CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
 // CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
 // CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
@@ -104,6 +119,7 @@ int hoo(void) {
 // CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 // CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
 // CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @unused_with_default_def = weak_odr ifunc i32 (), ptr 
@unused_with_default_def.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv._MflagmMfp16fmlMrng
@@ -113,29 +129,66 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_one._Mls64Msimd
+// CHECK-LABEL: define {{[^@]+}}@fmv._Mflagm2Msme-i16i64
 // CHECK-SAME: () #[[ATTR1:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:ret i32 1
+// CHECK-NEXT:ret i32 2
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_two._Mfp
-// CHECK-SAME: () #[[ATTR1]] {
+// CHECK-LABEL: define {{[^@]+}}@fmv._MlseMsha2
+// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:ret i32 1
+// CHECK-NEXT:ret i32 3
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@foo
-// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
+// CHECK-LABEL: define {{[^@]+}}@fmv._MdotprodMls64_accdata
+// CHECK-SAME: () #[[ATTR3:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[CALL:%.*]] = call i32 @fmv()
-// CHECK-NEXT:[[CALL1:%.*]] = call i32 @fmv_one()
-// CHECK-NEXT:[[ADD:%.*]] = add nsw i32 [[CALL]], 

[clang] [clang] Implement constexpr support for __builtin_popcountg (PR #84318)

2024-03-07 Thread via cfe-commits

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


[clang] 487cfbe - [Clang] Implement constexpr support for `__builtin_popcountg` (#84318)

2024-03-07 Thread via cfe-commits

Author: OverMighty
Date: 2024-03-08T01:01:37+01:00
New Revision: 487cfbe494413e12123b55dead5ef8742ef49fb2

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

LOG: [Clang] Implement constexpr support for `__builtin_popcountg` (#84318)

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.td
clang/lib/AST/ExprConstant.cpp
clang/test/Sema/constant-builtins-2.c

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 2b54dffd058a35..06af93fd3c15ca 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -5378,6 +5378,7 @@ The following builtin intrinsics can be used in constant 
expressions:
 * ``__builtin_popcount``
 * ``__builtin_popcountl``
 * ``__builtin_popcountll``
+* ``__builtin_popcountg``
 * ``__builtin_rotateleft8``
 * ``__builtin_rotateleft16``
 * ``__builtin_rotateleft32``

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42c4a7c4d4bd14..fa23c215790f11 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ Non-comprehensive list of changes in this release
 - ``__builtin_addc``, ``__builtin_subc``, and the other sizes of those
   builtins are now constexpr and may be used in constant expressions.
 
+- Added ``__builtin_popcountg`` as a type-generic alternative to
+  ``__builtin_popcount{,l,ll}`` with support for any unsigned integer type. 
Like
+  the previous builtins, this new builtin is constexpr and may be used in
+  constant expressions.
+
 New Compiler Flags
 --
 

diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index a81131d82c4cb4..9c703377ca8d3e 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -706,7 +706,7 @@ def Popcount : Builtin, BitInt_Long_LongLongTemplate {
 
 def Popcountg : Builtin {
   let Spellings = ["__builtin_popcountg"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
   let Prototype = "int(...)";
 }
 

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d8ca35740fbc35..4a7c7755e1d6fd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12483,6 +12483,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   case Builtin::BI__builtin_popcount:
   case Builtin::BI__builtin_popcountl:
   case Builtin::BI__builtin_popcountll:
+  case Builtin::BI__builtin_popcountg:
   case Builtin::BI__popcnt16: // Microsoft variants of popcount
   case Builtin::BI__popcnt:
   case Builtin::BI__popcnt64: {

diff  --git a/clang/test/Sema/constant-builtins-2.c 
b/clang/test/Sema/constant-builtins-2.c
index 2bdd7b06daabfe..0935abe4c65fbe 100644
--- a/clang/test/Sema/constant-builtins-2.c
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -237,6 +237,13 @@ char popcount7[__builtin_popcountl(~0L) == BITSIZE(long) ? 
1 : -1];
 char popcount8[__builtin_popcountll(0LL) == 0 ? 1 : -1];
 char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
 char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
+char popcount11[__builtin_popcountg(0U) == 0 ? 1 : -1];
+char popcount12[__builtin_popcountg(0xF0F0U) == 8 ? 1 : -1];
+char popcount13[__builtin_popcountg(~0U) == BITSIZE(int) ? 1 : -1];
+char popcount14[__builtin_popcountg(~0UL) == BITSIZE(long) ? 1 : -1];
+char popcount15[__builtin_popcountg(~0ULL) == BITSIZE(long long) ? 1 : -1];
+char popcount16[__builtin_popcountg(~(unsigned __int128)0) == 
BITSIZE(__int128) ? 1 : -1];
+char popcount17[__builtin_popcountg(~(unsigned _BitInt(128))0) == 
BITSIZE(_BitInt(128)) ? 1 : -1];
 
 char parity1[__builtin_parity(0) == 0 ? 1 : -1];
 char parity2[__builtin_parity(0xb821) == 0 ? 1 : -1];



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


[clang] [InstallAPI] Collect C++ Decls (PR #84403)

2024-03-07 Thread Cyndy Ishida via cfe-commits

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


[clang] [InstallAPI] Add support for C++ headers (PR #84403)

2024-03-07 Thread Cyndy Ishida via cfe-commits

cyndyishida wrote:

Looks like I made the mistake of deleting the target branch for PR: 
https://github.com/llvm/llvm-project/pull/83953 before updating it. Anyway, I 
applied @ributzka's forward declaration's suggestion. 

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


[clang] [InstallAPI] Add support for C++ headers (PR #84403)

2024-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Cyndy Ishida (cyndyishida)


Changes

This includes capturing symbols for global variables, functions, classes, and 
templated defintions. As pre-determing what symbols are generated from C++ 
declarations can be non-trivial, InstallAPI only parses select declarations for 
symbol generation when parsing c++.

For example, installapi only looks at explicit template instantiations or full 
template specializations, instead of general function or class templates, for 
symbol emittion.

---

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


6 Files Affected:

- (modified) clang/include/clang/InstallAPI/Visitor.h (+14) 
- (modified) clang/lib/InstallAPI/Frontend.cpp (+2-2) 
- (modified) clang/lib/InstallAPI/Visitor.cpp (+423-3) 
- (added) clang/test/InstallAPI/cpp.test (+530) 
- (modified) clang/tools/clang-installapi/Options.cpp (+32-1) 
- (modified) clang/tools/clang-installapi/Options.h (+7) 


``diff
diff --git a/clang/include/clang/InstallAPI/Visitor.h 
b/clang/include/clang/InstallAPI/Visitor.h
index 71d4d9894f4205..9ac948ded3e332 100644
--- a/clang/include/clang/InstallAPI/Visitor.h
+++ b/clang/include/clang/InstallAPI/Visitor.h
@@ -21,6 +21,7 @@
 #include "llvm/ADT/Twine.h"
 
 namespace clang {
+struct AvailabilityInfo;
 namespace installapi {
 
 /// ASTVisitor for collecting declarations that represent global symbols.
@@ -33,6 +34,7 @@ class InstallAPIVisitor final : public ASTConsumer,
 MC(ItaniumMangleContext::create(ASTCtx, ASTCtx.getDiagnostics())),
 Layout(ASTCtx.getTargetInfo().getDataLayoutString()) {}
   void HandleTranslationUnit(ASTContext ) override;
+  bool shouldVisitTemplateInstantiations() const { return true; }
 
   /// Collect global variables.
   bool VisitVarDecl(const VarDecl *D);
@@ -51,9 +53,19 @@ class InstallAPIVisitor final : public ASTConsumer,
   /// is therefore itself not collected.
   bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
 
+  /// Collect global c++ declarations.
+  bool VisitCXXRecordDecl(const CXXRecordDecl *D);
+
 private:
   std::string getMangledName(const NamedDecl *D) const;
   std::string getBackendMangledName(llvm::Twine Name) const;
+  std::string getMangledCXXVTableName(const CXXRecordDecl *D) const;
+  std::string getMangledCXXThunk(const GlobalDecl ,
+ const ThunkInfo ) const;
+  std::string getMangledCXXRTTI(const CXXRecordDecl *D) const;
+  std::string getMangledCXXRTTIName(const CXXRecordDecl *D) const;
+  std::string getMangledCtorDtor(const CXXMethodDecl *D, int Type) const;
+
   std::optional getAccessForDecl(const NamedDecl *D) const;
   void recordObjCInstanceVariables(
   const ASTContext , llvm::MachO::ObjCContainerRecord *Record,
@@ -61,6 +73,8 @@ class InstallAPIVisitor final : public ASTConsumer,
   const llvm::iterator_range<
   DeclContext::specific_decl_iterator>
   Ivars);
+  void emitVTableSymbols(const CXXRecordDecl *D, const AvailabilityInfo ,
+ const HeaderType Access, bool EmittedVTable = false);
 
   InstallAPIContext 
   SourceManager 
diff --git a/clang/lib/InstallAPI/Frontend.cpp 
b/clang/lib/InstallAPI/Frontend.cpp
index 1edbdf5bb98360..0d526fe1da6667 100644
--- a/clang/lib/InstallAPI/Frontend.cpp
+++ b/clang/lib/InstallAPI/Frontend.cpp
@@ -137,9 +137,9 @@ std::unique_ptr 
createInputBuffer(InstallAPIContext ) {
 else
   OS << "#import ";
 if (H.useIncludeName())
-  OS << "<" << H.getIncludeName() << ">";
+  OS << "<" << H.getIncludeName() << ">\n";
 else
-  OS << "\"" << H.getPath() << "\"";
+  OS << "\"" << H.getPath() << "\"\n";
 
 Ctx.addKnownHeader(H);
   }
diff --git a/clang/lib/InstallAPI/Visitor.cpp b/clang/lib/InstallAPI/Visitor.cpp
index 1f2ef08e5aa252..aded94f7a94a32 100644
--- a/clang/lib/InstallAPI/Visitor.cpp
+++ b/clang/lib/InstallAPI/Visitor.cpp
@@ -7,7 +7,9 @@
 
//===--===//
 
 #include "clang/InstallAPI/Visitor.h"
+#include "clang/AST/Availability.h"
 #include "clang/AST/ParentMapContext.h"
+#include "clang/AST/VTableBuilder.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/InstallAPI/Frontend.h"
 #include "llvm/ADT/SmallString.h"
@@ -18,6 +20,15 @@
 using namespace llvm;
 using namespace llvm::MachO;
 
+namespace {
+enum class CXXLinkage {
+  ExternalLinkage,
+  LinkOnceODRLinkage,
+  WeakODRLinkage,
+  PrivateLinkage,
+};
+}
+
 namespace clang::installapi {
 
 // Exported NamedDecl needs to have external linkage and
@@ -53,7 +64,7 @@ static bool isInlined(const FunctionDecl *D) {
   return true;
 }
 
-static SymbolFlags getFlags(bool WeakDef, bool ThreadLocal) {
+static SymbolFlags getFlags(bool WeakDef, bool ThreadLocal = false) {
   SymbolFlags Result = SymbolFlags::None;
   if (WeakDef)
 Result |= SymbolFlags::WeakDefined;
@@ -277,8 +288,417 @@ bool 

[clang] [InstallAPI] Add support for C++ headers (PR #84403)

2024-03-07 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/84403

This includes capturing symbols for global variables, functions, classes, and 
templated defintions. As pre-determing what symbols are generated from C++ 
declarations can be non-trivial, InstallAPI only parses select declarations for 
symbol generation when parsing c++.

For example, installapi only looks at explicit template instantiations or full 
template specializations, instead of general function or class templates, for 
symbol emittion.

>From 9068f8283df18ca8b3e39da67b9afa494847b6bf Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 4 Mar 2024 14:44:56 -0800
Subject: [PATCH] [InstallAPI] Add support for C++ headers

This includes capturing symbols for global variables, functions, classes, and 
templated defintions.
As pre-determing what symbols are generated from C++ declarations can be
non-trivial, InstallAPI only parses select declarations for symbol
generation when parsing c++.

For example, installapi only looks at explicit template instantiations
or full template specializations, instead of general function or class 
templates, for
symbol emittion.
---
 clang/include/clang/InstallAPI/Visitor.h |  14 +
 clang/lib/InstallAPI/Frontend.cpp|   4 +-
 clang/lib/InstallAPI/Visitor.cpp | 426 +-
 clang/test/InstallAPI/cpp.test   | 530 +++
 clang/tools/clang-installapi/Options.cpp |  33 +-
 clang/tools/clang-installapi/Options.h   |   7 +
 6 files changed, 1008 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/InstallAPI/cpp.test

diff --git a/clang/include/clang/InstallAPI/Visitor.h 
b/clang/include/clang/InstallAPI/Visitor.h
index 71d4d9894f4205..9ac948ded3e332 100644
--- a/clang/include/clang/InstallAPI/Visitor.h
+++ b/clang/include/clang/InstallAPI/Visitor.h
@@ -21,6 +21,7 @@
 #include "llvm/ADT/Twine.h"
 
 namespace clang {
+struct AvailabilityInfo;
 namespace installapi {
 
 /// ASTVisitor for collecting declarations that represent global symbols.
@@ -33,6 +34,7 @@ class InstallAPIVisitor final : public ASTConsumer,
 MC(ItaniumMangleContext::create(ASTCtx, ASTCtx.getDiagnostics())),
 Layout(ASTCtx.getTargetInfo().getDataLayoutString()) {}
   void HandleTranslationUnit(ASTContext ) override;
+  bool shouldVisitTemplateInstantiations() const { return true; }
 
   /// Collect global variables.
   bool VisitVarDecl(const VarDecl *D);
@@ -51,9 +53,19 @@ class InstallAPIVisitor final : public ASTConsumer,
   /// is therefore itself not collected.
   bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
 
+  /// Collect global c++ declarations.
+  bool VisitCXXRecordDecl(const CXXRecordDecl *D);
+
 private:
   std::string getMangledName(const NamedDecl *D) const;
   std::string getBackendMangledName(llvm::Twine Name) const;
+  std::string getMangledCXXVTableName(const CXXRecordDecl *D) const;
+  std::string getMangledCXXThunk(const GlobalDecl ,
+ const ThunkInfo ) const;
+  std::string getMangledCXXRTTI(const CXXRecordDecl *D) const;
+  std::string getMangledCXXRTTIName(const CXXRecordDecl *D) const;
+  std::string getMangledCtorDtor(const CXXMethodDecl *D, int Type) const;
+
   std::optional getAccessForDecl(const NamedDecl *D) const;
   void recordObjCInstanceVariables(
   const ASTContext , llvm::MachO::ObjCContainerRecord *Record,
@@ -61,6 +73,8 @@ class InstallAPIVisitor final : public ASTConsumer,
   const llvm::iterator_range<
   DeclContext::specific_decl_iterator>
   Ivars);
+  void emitVTableSymbols(const CXXRecordDecl *D, const AvailabilityInfo ,
+ const HeaderType Access, bool EmittedVTable = false);
 
   InstallAPIContext 
   SourceManager 
diff --git a/clang/lib/InstallAPI/Frontend.cpp 
b/clang/lib/InstallAPI/Frontend.cpp
index 1edbdf5bb98360..0d526fe1da6667 100644
--- a/clang/lib/InstallAPI/Frontend.cpp
+++ b/clang/lib/InstallAPI/Frontend.cpp
@@ -137,9 +137,9 @@ std::unique_ptr 
createInputBuffer(InstallAPIContext ) {
 else
   OS << "#import ";
 if (H.useIncludeName())
-  OS << "<" << H.getIncludeName() << ">";
+  OS << "<" << H.getIncludeName() << ">\n";
 else
-  OS << "\"" << H.getPath() << "\"";
+  OS << "\"" << H.getPath() << "\"\n";
 
 Ctx.addKnownHeader(H);
   }
diff --git a/clang/lib/InstallAPI/Visitor.cpp b/clang/lib/InstallAPI/Visitor.cpp
index 1f2ef08e5aa252..aded94f7a94a32 100644
--- a/clang/lib/InstallAPI/Visitor.cpp
+++ b/clang/lib/InstallAPI/Visitor.cpp
@@ -7,7 +7,9 @@
 
//===--===//
 
 #include "clang/InstallAPI/Visitor.h"
+#include "clang/AST/Availability.h"
 #include "clang/AST/ParentMapContext.h"
+#include "clang/AST/VTableBuilder.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/InstallAPI/Frontend.h"
 #include "llvm/ADT/SmallString.h"
@@ -18,6 +20,15 @@
 using namespace llvm;
 using namespace llvm::MachO;

[clang] [llvm] [Clang] CGCoroutine: Skip moving parameters if the allocation decision is false (PR #81195)

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

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/81195

>From 23aca1a0130eeb7162484a13a26cb2fbc98f5cde Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Wed, 7 Feb 2024 16:05:42 -0800
Subject: [PATCH] Skip moving parameters if the allocation decision is false

---
 clang/lib/CodeGen/CGCoroutine.cpp| 120 ++--
 clang/test/CodeGenCoroutines/coro-gro.cpp|   6 +-
 clang/test/CodeGenCoroutines/coro-params.cpp |  48 +++-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp | 277 ---
 4 files changed, 371 insertions(+), 80 deletions(-)

diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 888d30bfb3e1d6..b2933650367c12 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -389,25 +389,12 @@ namespace {
 ParamReferenceReplacerRAII(CodeGenFunction::DeclMapTy )
 : LocalDeclMap(LocalDeclMap) {}
 
-void addCopy(DeclStmt const *PM) {
-  // Figure out what param it refers to.
-
-  assert(PM->isSingleDecl());
-  VarDecl const*VD = static_cast(PM->getSingleDecl());
-  Expr const *InitExpr = VD->getInit();
-  GetParamRef Visitor;
-  Visitor.Visit(const_cast(InitExpr));
-  assert(Visitor.Expr);
-  DeclRefExpr *DREOrig = Visitor.Expr;
-  auto *PD = DREOrig->getDecl();
-
-  auto it = LocalDeclMap.find(PD);
-  assert(it != LocalDeclMap.end() && "parameter is not found");
-  SavedLocals.insert({ PD, it->second });
-
-  auto copyIt = LocalDeclMap.find(VD);
-  assert(copyIt != LocalDeclMap.end() && "parameter copy is not found");
-  it->second = copyIt->getSecond();
+void substAddress(ValueDecl *D, Address Addr) {
+  auto it = LocalDeclMap.find(D);
+  assert(it != LocalDeclMap.end() && "original decl is not found");
+  SavedLocals.insert({D, it->second});
+
+  it->second = Addr;
 }
 
 ~ParamReferenceReplacerRAII() {
@@ -629,6 +616,63 @@ struct GetReturnObjectManager {
 Builder.CreateStore(Builder.getTrue(), GroActiveFlag);
   }
 };
+
+static ValueDecl *getOriginalParamDeclForParamMove(VarDecl const *VD) {
+  Expr const *InitExpr = VD->getInit();
+  GetParamRef Visitor;
+  Visitor.Visit(const_cast(InitExpr));
+  assert(Visitor.Expr);
+  return Visitor.Expr->getDecl();
+}
+
+struct ParamMoveManager {
+  ParamMoveManager(CodeGenFunction ,
+   llvm::ArrayRef ParamMoves)
+  : CGF(CGF), ParamMovesVarDecls() {
+ParamMovesVarDecls.reserve(ParamMoves.size());
+for (auto *S : ParamMoves) {
+  auto *PMStmt = cast(S);
+  assert(PMStmt->isSingleDecl());
+  auto *ParamMoveVD = static_cast(PMStmt->getSingleDecl());
+  ParamMovesVarDecls.push_back(ParamMoveVD);
+}
+  }
+
+  // Because we wrap param moves in the coro.alloc block. It's not always
+  // necessary to run the corresponding cleanups in the branches.
+  // We would need to know when to (conditionally) clean them up.
+  void EmitMovesWithCleanup(Address PMCleanupActiveFlag) {
+// Create parameter copies. We do it before creating a promise, since an
+// evolution of coroutine TS may allow promise constructor to observe
+// parameter copies.
+for (auto *VD : ParamMovesVarDecls) {
+  auto Emission = CGF.EmitAutoVarAlloca(*VD);
+  CGF.EmitAutoVarInit(Emission);
+  auto OldTop = CGF.EHStack.stable_begin();
+  CGF.EmitAutoVarCleanups(Emission);
+  auto Top = CGF.EHStack.stable_begin();
+
+  for (auto I = CGF.EHStack.find(Top), E = CGF.EHStack.find(OldTop); I != 
E;
+   I++) {
+if (auto *Cleanup = dyn_cast(&*I)) {
+  assert(!Cleanup->hasActiveFlag() &&
+ "cleanup already has active flag?");
+  Cleanup->setActiveFlag(PMCleanupActiveFlag);
+  Cleanup->setTestFlagInEHCleanup();
+  Cleanup->setTestFlagInNormalCleanup();
+}
+  }
+}
+  }
+
+  llvm::ArrayRef GetParamMovesVarDecls() {
+return ParamMovesVarDecls;
+  }
+
+private:
+  CodeGenFunction 
+  SmallVector ParamMovesVarDecls;
+};
 } // namespace
 
 static void emitBodyAndFallthrough(CodeGenFunction ,
@@ -648,6 +692,8 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
   auto *EntryBB = Builder.GetInsertBlock();
   auto *AllocBB = createBasicBlock("coro.alloc");
   auto *InitBB = createBasicBlock("coro.init");
+  auto *ParamMoveBB = createBasicBlock("coro.param.move");
+  auto *AfterParamMoveBB = createBasicBlock("coro.after.param.move");
   auto *FinalBB = createBasicBlock("coro.final");
   auto *RetBB = createBasicBlock("coro.ret");
 
@@ -664,6 +710,9 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
   auto *CoroAlloc = Builder.CreateCall(
   CGM.getIntrinsic(llvm::Intrinsic::coro_alloc), {CoroId});
 
+  auto PMCleanupActiveFlag = CreateTempAlloca(
+  Builder.getInt1Ty(), CharUnits::One(), "param.move.cleanup.active");
+  Builder.CreateStore(CoroAlloc, PMCleanupActiveFlag);
   

[clang] [llvm] [InstallAPI] Collect global functions (PR #83952)

2024-03-07 Thread Cyndy Ishida via cfe-commits

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


[clang] 50ae8a2 - [InstallAPI] Collect global functions (#83952)

2024-03-07 Thread via cfe-commits

Author: Cyndy Ishida
Date: 2024-03-07T15:32:44-08:00
New Revision: 50ae8a2a38b618d76193bed04b1d7df6890d5c8a

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

LOG: [InstallAPI] Collect global functions (#83952)

* Include whether functions are inlinable as they impact whether to add
them into the tbd file and for future verification.
* Fix how clang arguments got passed along, previously spacing was
passed along to CC1 causing search path inputs to look non-existent.

Added: 
clang/test/InstallAPI/functions.test

Modified: 
clang/include/clang/InstallAPI/Frontend.h
clang/include/clang/InstallAPI/Visitor.h
clang/lib/InstallAPI/Frontend.cpp
clang/lib/InstallAPI/Visitor.cpp
clang/tools/clang-installapi/Options.cpp
llvm/include/llvm/TextAPI/Record.h
llvm/include/llvm/TextAPI/RecordsSlice.h
llvm/lib/TextAPI/RecordsSlice.cpp
llvm/unittests/TextAPI/RecordTests.cpp

Removed: 




diff  --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
index 8774321e990c13..cbc2b159ebd17a 100644
--- a/clang/include/clang/InstallAPI/Frontend.h
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -50,12 +50,15 @@ class FrontendRecordsSlice : public 
llvm::MachO::RecordsSlice {
   /// \param D The pointer to the declaration from traversing AST.
   /// \param Access The intended access level of symbol.
   /// \param Flags The flags that describe attributes of the symbol.
+  /// \param Inlined Whether declaration is inlined, only applicable to
+  /// functions.
   /// \return The non-owning pointer to added record in slice.
   GlobalRecord *addGlobal(StringRef Name, RecordLinkage Linkage,
   GlobalRecord::Kind GV,
   const clang::AvailabilityInfo Avail, const Decl *D,
   const HeaderType Access,
-  SymbolFlags Flags = SymbolFlags::None);
+  SymbolFlags Flags = SymbolFlags::None,
+  bool Inlined = false);
 
   /// Add ObjC Class record with attributes from AST.
   ///

diff  --git a/clang/include/clang/InstallAPI/Visitor.h 
b/clang/include/clang/InstallAPI/Visitor.h
index ff0a9957aa86bc..71d4d9894f4205 100644
--- a/clang/include/clang/InstallAPI/Visitor.h
+++ b/clang/include/clang/InstallAPI/Visitor.h
@@ -37,6 +37,9 @@ class InstallAPIVisitor final : public ASTConsumer,
   /// Collect global variables.
   bool VisitVarDecl(const VarDecl *D);
 
+  /// Collect global functions.
+  bool VisitFunctionDecl(const FunctionDecl *D);
+
   /// Collect Objective-C Interface declarations.
   /// Every Objective-C class has an interface declaration that lists all the
   /// ivars, properties, and methods of the class.

diff  --git a/clang/lib/InstallAPI/Frontend.cpp 
b/clang/lib/InstallAPI/Frontend.cpp
index 240a80e1d3d82c..1edbdf5bb98360 100644
--- a/clang/lib/InstallAPI/Frontend.cpp
+++ b/clang/lib/InstallAPI/Frontend.cpp
@@ -19,9 +19,10 @@ namespace clang::installapi {
 GlobalRecord *FrontendRecordsSlice::addGlobal(
 StringRef Name, RecordLinkage Linkage, GlobalRecord::Kind GV,
 const clang::AvailabilityInfo Avail, const Decl *D, const HeaderType 
Access,
-SymbolFlags Flags) {
+SymbolFlags Flags, bool Inlined) {
 
-  auto *GR = llvm::MachO::RecordsSlice::addGlobal(Name, Linkage, GV, Flags);
+  auto *GR =
+  llvm::MachO::RecordsSlice::addGlobal(Name, Linkage, GV, Flags, Inlined);
   FrontendRecords.insert({GR, FrontendAttrs{Avail, D, Access}});
   return GR;
 }

diff  --git a/clang/lib/InstallAPI/Visitor.cpp 
b/clang/lib/InstallAPI/Visitor.cpp
index fbe6f1dabe005d..1f2ef08e5aa252 100644
--- a/clang/lib/InstallAPI/Visitor.cpp
+++ b/clang/lib/InstallAPI/Visitor.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/InstallAPI/Visitor.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/InstallAPI/Frontend.h"
 #include "llvm/ADT/SmallString.h"
@@ -27,6 +28,31 @@ static bool isExported(const NamedDecl *D) {
  (LV.getVisibility() == DefaultVisibility);
 }
 
+static bool isInlined(const FunctionDecl *D) {
+  bool HasInlineAttribute = false;
+  bool NoCXXAttr =
+  (!D->getASTContext().getLangOpts().CPlusPlus &&
+   !D->getASTContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+   !D->hasAttr());
+
+  // Check all redeclarations to find an inline attribute or keyword.
+  for (const auto *RD : D->redecls()) {
+if (!RD->isInlined())
+  continue;
+HasInlineAttribute = true;
+if (!(NoCXXAttr || RD->hasAttr()))
+  continue;
+if (RD->doesThisDeclarationHaveABody() &&
+RD->isInlineDefinitionExternallyVisible())
+  return false;
+  }
+

[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-03-07 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

Friendly reminder that I require someone to commit on my behalf since I do not 
have write access :).

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


[clang] [HIP] Make the HIP default architecture use the enum value (PR #84400)

2024-03-07 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Joseph Huber (jhuber6)


Changes

Summary:
This default enum is used in other places, we should keep it consistent.


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


2 Files Affected:

- (modified) clang/include/clang/Basic/Cuda.h (+1-1) 
- (modified) clang/lib/Driver/Driver.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index 916cb4b7ef34a7..3e77a74c7c0092 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -123,7 +123,7 @@ enum class CudaArch {
   LAST,
 
   CudaDefault = CudaArch::SM_52,
-  HIPDefault = CudaArch::GFX803,
+  HIPDefault = CudaArch::GFX906,
 };
 
 static inline bool IsNVIDIAGpuArch(CudaArch A) {
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 96e6ad77f5e50d..fce43430a91374 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3373,7 +3373,7 @@ class OffloadingActionBuilder final {
  const Driver::InputList )
 : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_HIP) {
 
-  DefaultCudaArch = CudaArch::GFX906;
+  DefaultCudaArch = CudaArch::HIPDefault;
 
   if (Args.hasArg(options::OPT_fhip_emit_relocatable,
   options::OPT_fno_hip_emit_relocatable)) {

``




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


[clang] [HIP] Make the HIP default architecture use the enum value (PR #84400)

2024-03-07 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/84400

Summary:
This default enum is used in other places, we should keep it consistent.


>From 4f791a35e775842e758e7be60fef6e3669986c7d Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 7 Mar 2024 17:20:58 -0600
Subject: [PATCH] [HIP] Make the HIP default architecture use the enum value

Summary:
This default enum is used in other places, we should keep it consistent.
---
 clang/include/clang/Basic/Cuda.h | 2 +-
 clang/lib/Driver/Driver.cpp  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index 916cb4b7ef34a7..3e77a74c7c0092 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -123,7 +123,7 @@ enum class CudaArch {
   LAST,
 
   CudaDefault = CudaArch::SM_52,
-  HIPDefault = CudaArch::GFX803,
+  HIPDefault = CudaArch::GFX906,
 };
 
 static inline bool IsNVIDIAGpuArch(CudaArch A) {
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 96e6ad77f5e50d..fce43430a91374 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3373,7 +3373,7 @@ class OffloadingActionBuilder final {
  const Driver::InputList )
 : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_HIP) {
 
-  DefaultCudaArch = CudaArch::GFX906;
+  DefaultCudaArch = CudaArch::HIPDefault;
 
   if (Args.hasArg(options::OPT_fhip_emit_relocatable,
   options::OPT_fno_hip_emit_relocatable)) {

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


  1   2   3   4   5   >