[clang] [AMDGPU] Change the representation of double literals in operands (PR #68740)

2023-10-13 Thread Stanislav Mekhanoshin via cfe-commits

rampitec wrote:

> I suppose left shift of negative values is undefined because if you shift out 
> the sign bit you can overflow and get a positive value.

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

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


[clang] 411ceac - [Clang] Fix tautological assertion in `Sema::CheckX86BuiltinTileDuplicate`

2023-10-13 Thread Yingwei Zheng via cfe-commits

Author: Yingwei Zheng
Date: 2023-10-13T15:19:35+08:00
New Revision: 411ceacf4351bd3af9db75b859063864b19e71e1

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

LOG: [Clang] Fix tautological assertion in `Sema::CheckX86BuiltinTileDuplicate`

Closes #68958.

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 1b2f8cf296d16b6..cd61459cfbb13d6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -6047,7 +6047,7 @@ bool Sema::CheckX86BuiltinTileDuplicate(CallExpr *TheCall,
 if (SemaBuiltinConstantArg(TheCall, ArgNum, Result))
   return true;
 int ArgExtValue = Result.getExtValue();
-assert((ArgExtValue >= TileRegLow || ArgExtValue <= TileRegHigh) &&
+assert((ArgExtValue >= TileRegLow && ArgExtValue <= TileRegHigh) &&
"Incorrect tile register num.");
 if (ArgValues.test(ArgExtValue))
   return Diag(TheCall->getBeginLoc(),



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


[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)

2023-10-13 Thread Nikita Popov via cfe-commits

nikic wrote:

This also breaks the clang standalone build. You need to `include(config-ix)` 
in order to use `llvm_find_program`.

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-13 Thread antoine moynault via cfe-commits

antmox wrote:

Hi!
This commit broke some armv8/armv7 bots:
https://lab.llvm.org/buildbot/#/builders/245/builds/15263
https://lab.llvm.org/buildbot/#/builders/187/builds/13069
Int & Void* have the same size there, so no warning on bitfield-width.c:20.


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


[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)

2023-10-13 Thread Nikita Popov via cfe-commits

nikic wrote:

Actually no, that's not possible as config-ix modules are explicitly private to 
their subproject and should not be used outside them. I'm going to revert this 
change due to this layering violation.

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-13 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

Friendly ping @AaronBallman @shafik 

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


[clang] ac32d7b - Revert "Add Documentation for Execution Results Handling in Clang-Repl (#65650)"

2023-10-13 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-10-13T09:39:00+02:00
New Revision: ac32d7b87f4d4b546eea96b9b722e88fdb3a5b49

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

LOG: Revert "Add Documentation for Execution Results Handling in Clang-Repl 
(#65650)"

This reverts commit b9b8fc4878b6f7708f2ca2df6036a9c7bb5077b0.

This uses a function defined in LLVM's config-ix inside clang.
config-ix is a non-exported cmake module, so this is a layering
violation.

Added: 


Modified: 
clang/docs/CMakeLists.txt
clang/docs/ClangRepl.rst
clang/docs/conf.py

Removed: 




diff  --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt
index 356814f994c32cd..4163dd2d90ad5b3 100644
--- a/clang/docs/CMakeLists.txt
+++ b/clang/docs/CMakeLists.txt
@@ -103,13 +103,6 @@ function (gen_rst_file_from_td output_file td_option 
source docs_targets)
 endfunction()
 
 if (LLVM_ENABLE_SPHINX)
-  llvm_find_program(dot)
-  if (HAVE_DOT)
-set(DOT ${LLVM_PATH_DOT})
-  else()
-message(FATAL_ERROR "Cannot find DOT")
-  endif()
-
   include(AddSphinxTarget)
   if (SPHINX_FOUND AND (${SPHINX_OUTPUT_HTML} OR ${SPHINX_OUTPUT_MAN}))
 # Copy rst files to build directory before generating the html

diff  --git a/clang/docs/ClangRepl.rst b/clang/docs/ClangRepl.rst
index 5399036c123fbbf..bd99bc82f17 100644
--- a/clang/docs/ClangRepl.rst
+++ b/clang/docs/ClangRepl.rst
@@ -213,411 +213,6 @@ concept helps support advanced use cases such as template 
instantiations on dema
 automatic language interoperability. It also helps static languages such as 
C/C++ become
 apt for data science.
 
-Execution Results Handling in Clang-Repl
-
-
-Execution Results Handling features discussed below help extend the Clang-Repl
-functionality by creating an interface between the execution results of a
-program and the compiled program.
-
-1. **Capture Execution Results**: This feature helps capture the execution 
results
-of a program and bring them back to the compiled program.
-
-2. **Dump Captured Execution Results**: This feature helps create a temporary 
dump
-for Value Printing/Automatic Printf, that is, to display the value and type of
-the captured data.
-
-
-1. Capture Execution Results
-
-
-In many cases, it is useful to bring back the program execution result to the
-compiled program. This result can be stored in an object of type **Value**.
-
-How Execution Results are captured (Value Synthesis):
--
-
-The synthesizer chooses which expression to synthesize, and then it replaces
-the original expression with the synthesized expression. Depending on the
-expression type, it may choose to save an object (``LastValue``) of type 
'value'
-while allocating memory to it (``SetValueWithAlloc()``), or not (
-``SetValueNoAlloc()``).
-
-.. graphviz::
-:name: valuesynthesis
-:caption: Value Synthesis
-:alt: Shows how an object of type 'Value' is synthesized
-:align: center
-
- digraph "valuesynthesis" {
- rankdir="LR";
- graph [fontname="Verdana", fontsize="12"];
- node [fontname="Verdana", fontsize="12"];
- edge [fontname="Sans", fontsize="9"];
-
- start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", 
shape="note", fontcolor=white, fillcolor="#ff", style=filled];
- assign [label=" Assign the result \n to the 'LastValue' \n (based on 
respective \n Memory Allocation \n scenario) ", shape="box"]
- print [label=" Pretty Print \n the Value Object ", shape="Msquare", 
fillcolor="yellow", style=filled];
- start -> assign;
- assign -> print;
-
-   subgraph SynthesizeExpression {
- synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, 
fillcolor="#ff", style=filled];
- mem [label=" New Memory \n Allocation? ", shape="diamond"];
- withaloc [label=" SetValueWithAlloc() ", shape="box"];
- noaloc [label=" SetValueNoAlloc() ", shape="box"];
- right [label=" 1. RValue Structure \n (a temporary value)", 
shape="box"];
- left2 [label=" 2. LValue Structure \n (a variable with \n an 
address)", shape="box"];
- left3 [label=" 3. Built-In Type \n (int, float, etc.)", 
shape="box"];
- output [label=" move to 'Assign' step ", shape="box"];
-
- synth -> mem;
- mem -> withaloc [label="Yes"];
- mem -> noaloc [label="No"];
- withaloc -> right;
- noaloc -> left2;
- noaloc -> left3;
- right -> output;
- left2 -> output;
- left3 -> output;
-  }
-output -> assign
-  }
-
-Where is th

[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)

2023-10-13 Thread Jun Zhang via cfe-commits


@@ -213,6 +213,411 @@ concept helps support advanced use cases such as template 
instantiations on dema
 automatic language interoperability. It also helps static languages such as 
C/C++ become
 apt for data science.
 
+Execution Results Handling in Clang-Repl
+
+
+Execution Results Handling features discussed below help extend the Clang-Repl
+functionality by creating an interface between the execution results of a
+program and the compiled program.
+
+1. **Capture Execution Results**: This feature helps capture the execution 
results
+of a program and bring them back to the compiled program.
+
+2. **Dump Captured Execution Results**: This feature helps create a temporary 
dump
+for Value Printing/Automatic Printf, that is, to display the value and type of
+the captured data.
+
+
+1. Capture Execution Results
+
+
+In many cases, it is useful to bring back the program execution result to the
+compiled program. This result can be stored in an object of type **Value**.
+
+How Execution Results are captured (Value Synthesis):
+-
+
+The synthesizer chooses which expression to synthesize, and then it replaces
+the original expression with the synthesized expression. Depending on the
+expression type, it may choose to save an object (``LastValue``) of type 
'value'
+while allocating memory to it (``SetValueWithAlloc()``), or not (
+``SetValueNoAlloc()``).
+
+.. graphviz::
+:name: valuesynthesis
+:caption: Value Synthesis
+:alt: Shows how an object of type 'Value' is synthesized
+:align: center
+
+ digraph "valuesynthesis" {
+ rankdir="LR";
+ graph [fontname="Verdana", fontsize="12"];
+ node [fontname="Verdana", fontsize="12"];
+ edge [fontname="Sans", fontsize="9"];
+
+ start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", 
shape="note", fontcolor=white, fillcolor="#ff", style=filled];
+ assign [label=" Assign the result \n to the 'LastValue' \n (based on 
respective \n Memory Allocation \n scenario) ", shape="box"]
+ print [label=" Pretty Print \n the Value Object ", shape="Msquare", 
fillcolor="yellow", style=filled];
+ start -> assign;
+ assign -> print;
+
+   subgraph SynthesizeExpression {
+ synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, 
fillcolor="#ff", style=filled];
+ mem [label=" New Memory \n Allocation? ", shape="diamond"];
+ withaloc [label=" SetValueWithAlloc() ", shape="box"];
+ noaloc [label=" SetValueNoAlloc() ", shape="box"];
+ right [label=" 1. RValue Structure \n (a temporary value)", 
shape="box"];
+ left2 [label=" 2. LValue Structure \n (a variable with \n an 
address)", shape="box"];
+ left3 [label=" 3. Built-In Type \n (int, float, etc.)", 
shape="box"];
+ output [label=" move to 'Assign' step ", shape="box"];
+
+ synth -> mem;
+ mem -> withaloc [label="Yes"];
+ mem -> noaloc [label="No"];
+ withaloc -> right;
+ noaloc -> left2;
+ noaloc -> left3;
+ right -> output;
+ left2 -> output;
+ left3 -> output;
+  }
+output -> assign
+  }
+
+Where is the captured result stored?
+
+
+``LastValue`` holds the last result of the value printing. It is a class member
+because it can be accessed even after subsequent inputs.
+
+**Note:** If no value printing happens, then it is in an invalid state.
+
+Improving Efficiency and User Experience
+
+
+The Value object is essentially used to create a mapping between an expression
+'type' and the allocated 'memory'. Built-in types (bool, char, int,
+float, double, etc.) are copyable. Their memory allocation size is known
+and the Value object can introduce a small-buffer optimization.
+In case of objects, the ``Value`` class provides reference-counted memory
+management.
+
+The implementation maps the type as written and the Clang Type to be able to 
use
+the preprocessor to synthesize the relevant cast operations. For example,
+``X(char, Char_S)``, where ``char`` is the type from the language's type system
+and ``Char_S`` is the Clang builtin type which represents it. This mapping 
helps
+to import execution results from the interpreter in a compiled program and vice
+versa. The ``Value.h`` header file can be included at runtime and this is why 
it
+has a very low token count and was developed with strict constraints in mind.
+
+This also enables the user to receive the computed 'type' back in their code
+and then transform the type into something else (e.g., re-cast a double into
+a float). Normally, the compiler can handle these conversions transparently,
+but in interpreter mode, the c

[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-13 Thread via cfe-commits


@@ -64,6 +64,10 @@ C/C++ Language Potentially Breaking Changes
 ``__has_c_attribute(warn_unused_result)``,  202003, 0
 ``__has_c_attribute(gnu::warn_unused_result)``, 202003, 1
 
+- Fixed a bug in finding matching `operator!=` while adding reveresed 
`operator==` as

cor3ntin wrote:

```suggestion
- Fixed a bug in finding matching `operator!=` while adding reversed 
`operator==` as
```

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


[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-13 Thread via cfe-commits

https://github.com/cor3ntin commented:

Looks reasonable, but i found a typo

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


[clang] [clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-10-13 Thread via cfe-commits

https://github.com/mzyKi updated https://github.com/llvm/llvm-project/pull/68774

>From 67f878a270d159d5d09d1dd029f862443125b511 Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Wed, 11 Oct 2023 15:45:36 +0800
Subject: [PATCH] [clang][ASTImporter] Fix crash when template class static
 member imported to other translation unit. Fixes: #68769

---
 clang/docs/ReleaseNotes.rst |  4 +++
 clang/lib/AST/ASTImporter.cpp   | 11 
 clang/unittests/AST/ASTImporterTest.cpp | 34 +
 3 files changed, 49 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..3be9e60c82a18d0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -497,6 +497,10 @@ Bug Fixes to C++ Support
   rather than prefer the non-templated constructor as specified in
   [standard.group]p3.
 
+- Fix crash when template class static member imported to other translation 
unit.
+  Fixes:
+  (`#68769 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 72e70427161bb0e..2a8add84f55dc3b 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -4475,6 +4475,17 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
 auto ToVTOrErr = import(D->getDescribedVarTemplate());
 if (!ToVTOrErr)
   return ToVTOrErr.takeError();
+  } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) 
{
+TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
+VarDecl *FromInst = D->getInstantiatedFromStaticDataMember();
+if (Expected ToInstOrErr = import(FromInst))
+  ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
+else
+  return ToInstOrErr.takeError();
+if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
+  ToVar->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+else
+  return POIOrErr.takeError();
   }
 
   if (Error Err = ImportInitializer(D, ToVar))
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 393ed44de3f1831..746c4f7a765876b 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -1373,6 +1373,40 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportCorrectTemplatedDecl) {
   ASSERT_EQ(ToTemplated1, ToTemplated);
 }
 
+
+TEST_P(ASTImporterOptionSpecificTestBase, 
ImportTemplateSpecializationStaticMember) {
+  auto FromCode = R"(
+  template  class Test{
+  public:
+ static const unsigned int length;
+  };
+
+  template<> const unsigned int Test::length;
+  template<> const unsigned int Test::length = 0;
+  )";
+  auto ToCode = R"(
+template  class Test
+{
+public:
+   static const unsigned int length;
+};
+template<> const unsigned int Test::length;
+
+void foo(){
+int i = 1 / Test::length;
+}
+)";
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX14);
+  auto FromDecl =
+  FirstDeclMatcher().match(FromTU, 
varDecl(hasName("length"),isDefinition()));
+  Decl *ToTu = getToTuDecl(ToCode,Lang_CXX14);
+  auto ToX = Import(FromDecl, Lang_CXX03);
+  auto ToDecl =
+  
FirstDeclMatcher().match(ToTu,varDecl(hasName("length"),isDefinition()));
+  EXPECT_TRUE(ToX);
+  EXPECT_EQ(ToX,ToDecl);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportChooseExpr) {
   // This tests the import of isConditionTrue directly to make sure the 
importer
   // gets it right.

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


[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

2023-10-13 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/67095

>From a7c2b5a2834ef6dc345257e8d67caae909abbe20 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 22 Sep 2023 08:42:05 +0200
Subject: [PATCH 1/3] [clang][TSA] Make RequiresCapability a DeclOrType
 attribute

---
 clang/include/clang/Basic/Attr.td |  6 +++---
 clang/test/Sema/warn-thread-safety-analysis.c | 11 +++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 7a6ec77ae84b15a..fc094c8caf23901 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3317,7 +3317,7 @@ def ReleaseCapability : InheritableAttr {
   let Documentation = [ReleaseCapabilityDocs];
 }
 
-def RequiresCapability : InheritableAttr {
+def RequiresCapability : DeclOrTypeAttr {
   let Spellings = [Clang<"requires_capability", 0>,
Clang<"exclusive_locks_required", 0>,
Clang<"requires_shared_capability", 0>,
@@ -3326,8 +3326,8 @@ def RequiresCapability : InheritableAttr {
   let LateParsed = 1;
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
-  let InheritEvenIfAlreadyPresent = 1;
-  let Subjects = SubjectList<[Function]>;
+  /*let InheritEvenIfAlreadyPresent = 1;*/
+  /*let Subjects = SubjectList<[Function]>;*/
   let Accessors = [Accessor<"isShared", [Clang<"requires_shared_capability", 
0>,
  Clang<"shared_locks_required", 0>]>];
   let Documentation = [Undocumented];
diff --git a/clang/test/Sema/warn-thread-safety-analysis.c 
b/clang/test/Sema/warn-thread-safety-analysis.c
index 642ea88ec3c96f7..cd852efac21cb81 100644
--- a/clang/test/Sema/warn-thread-safety-analysis.c
+++ b/clang/test/Sema/warn-thread-safety-analysis.c
@@ -136,6 +136,17 @@ int main(void) {
 // Cleanup happens automatically -> no warning.
   }
 
+  /// Function pointers
+  {
+int __attribute__((requires_capability(&mu1))) (*function_ptr)(int) = 
Foo_fun1;
+
+function_ptr(5); // expected-warning {{calling function 'function_ptr' 
requires holding mutex 'mu1'}}
+
+mutex_exclusive_lock(&mu1);
+int five = function_ptr(5);
+mutex_exclusive_unlock(&mu1);
+  }
+
   return 0;
 }
 

>From 13393e67525df1565a661ec96e97cae0538fbaad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 26 Sep 2023 09:57:41 +0200
Subject: [PATCH 2/3] Restrict to functions and function pointer decls

---
 clang/include/clang/Basic/Attr.td |  2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fc094c8caf23901..af3241b3169bc39 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3326,7 +3326,7 @@ def RequiresCapability : DeclOrTypeAttr {
   let LateParsed = 1;
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
-  /*let InheritEvenIfAlreadyPresent = 1;*/
+  let InheritEvenIfAlreadyPresent = 1;
   /*let Subjects = SubjectList<[Function]>;*/
   let Accessors = [Accessor<"isShared", [Clang<"requires_shared_capability", 
0>,
  Clang<"shared_locks_required", 0>]>];
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index ed0b4d29b056397..c967af7bb6914e0 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -8166,6 +8166,16 @@ static void handleRequiresCapabilityAttr(Sema &S, Decl 
*D,
   if (!AL.checkAtLeastNumArgs(S, 1))
 return;
 
+  // We allow this on function declaration as well as
+  // variable declarations of function pointer type.
+  if (!D->isFunctionPointerType() && !isa(D)) {
+// FIXME: Diagnostic should say "functions and function pointer decls" now 
I
+// guess.
+S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type)
+<< AL << AL.isRegularKeywordAttribute() << ExpectedFunction;
+return;
+  }
+
   // check that all arguments are lockable objects
   SmallVector Args;
   checkAttrArgsAreCapabilityObjs(S, D, AL, Args);

>From 2fdd4485b94df6c79e3e190d69a7dff70fe17d78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 13 Oct 2023 10:23:43 +0200
Subject: [PATCH 3/3] Add processing to SemaType.cpp

---
 clang/include/clang/Basic/Attr.td |  2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 10 --
 clang/lib/Sema/SemaType.cpp   | 30 ++
 3 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index af3241b3169bc39..15e785538709716 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3327,7 +3327,7 @@ def RequiresCapability : DeclOrTypeAttr

[clang] [clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-10-13 Thread via cfe-commits

https://github.com/mzyKi updated https://github.com/llvm/llvm-project/pull/68774

>From 99c30605aea8586fca39f3125f49b0bae04e3478 Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Wed, 11 Oct 2023 15:45:36 +0800
Subject: [PATCH] [clang][ASTImporter] Fix crash when template class static
 member imported to other translation unit. Fixes: #68769

---
 clang/docs/ReleaseNotes.rst |  4 +++
 clang/lib/AST/ASTImporter.cpp   | 11 +
 clang/unittests/AST/ASTImporterTest.cpp | 33 +
 3 files changed, 48 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..3be9e60c82a18d0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -497,6 +497,10 @@ Bug Fixes to C++ Support
   rather than prefer the non-templated constructor as specified in
   [standard.group]p3.
 
+- Fix crash when template class static member imported to other translation 
unit.
+  Fixes:
+  (`#68769 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 72e70427161bb0e..2a8add84f55dc3b 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -4475,6 +4475,17 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
 auto ToVTOrErr = import(D->getDescribedVarTemplate());
 if (!ToVTOrErr)
   return ToVTOrErr.takeError();
+  } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) 
{
+TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
+VarDecl *FromInst = D->getInstantiatedFromStaticDataMember();
+if (Expected ToInstOrErr = import(FromInst))
+  ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
+else
+  return ToInstOrErr.takeError();
+if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
+  ToVar->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+else
+  return POIOrErr.takeError();
   }
 
   if (Error Err = ImportInitializer(D, ToVar))
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 393ed44de3f1831..5c2fab0546054c5 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -1373,6 +1373,39 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportCorrectTemplatedDecl) {
   ASSERT_EQ(ToTemplated1, ToTemplated);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, 
ImportTemplateSpecializationStaticMember) {
+  auto FromCode = R"(
+  template  class Test{
+  public:
+ static const unsigned int length;
+  };
+
+  template<> const unsigned int Test::length;
+  template<> const unsigned int Test::length = 0;
+  )";
+  auto ToCode = R"(
+template  class Test
+{
+public:
+   static const unsigned int length;
+};
+template<> const unsigned int Test::length;
+
+void foo(){
+int i = 1 / Test::length;
+}
+)";
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX14);
+  auto FromDecl =
+  FirstDeclMatcher().match(FromTU, 
varDecl(hasName("length"),isDefinition()));
+  Decl *ToTu = getToTuDecl(ToCode,Lang_CXX14);
+  auto ToX = Import(FromDecl, Lang_CXX03);
+  auto ToDecl =
+  
FirstDeclMatcher().match(ToTu,varDecl(hasName("length"),isDefinition()));
+  EXPECT_TRUE(ToX);
+  EXPECT_EQ(ToX,ToDecl);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportChooseExpr) {
   // This tests the import of isConditionTrue directly to make sure the 
importer
   // gets it right.

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


[clang] [clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-10-13 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 9a8ff346bb20a684e8edd62035077aba06bea084 
67f878a270d159d5d09d1dd029f862443125b511 -- clang/lib/AST/ASTImporter.cpp 
clang/unittests/AST/ASTImporterTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 746c4f7a7658..b0cc598a369a 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -1373,8 +1373,8 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportCorrectTemplatedDecl) {
   ASSERT_EQ(ToTemplated1, ToTemplated);
 }
 
-
-TEST_P(ASTImporterOptionSpecificTestBase, 
ImportTemplateSpecializationStaticMember) {
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportTemplateSpecializationStaticMember) {
   auto FromCode = R"(
   template  class Test{
   public:
@@ -1397,14 +1397,14 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportTemplateSpecializationStaticMemb
 }
 )";
   Decl *FromTU = getTuDecl(FromCode, Lang_CXX14);
-  auto FromDecl =
-  FirstDeclMatcher().match(FromTU, 
varDecl(hasName("length"),isDefinition()));
-  Decl *ToTu = getToTuDecl(ToCode,Lang_CXX14);
+  auto FromDecl = FirstDeclMatcher().match(
+  FromTU, varDecl(hasName("length"), isDefinition()));
+  Decl *ToTu = getToTuDecl(ToCode, Lang_CXX14);
   auto ToX = Import(FromDecl, Lang_CXX03);
-  auto ToDecl =
-  
FirstDeclMatcher().match(ToTu,varDecl(hasName("length"),isDefinition()));
+  auto ToDecl = FirstDeclMatcher().match(
+  ToTu, varDecl(hasName("length"), isDefinition()));
   EXPECT_TRUE(ToX);
-  EXPECT_EQ(ToX,ToDecl);
+  EXPECT_EQ(ToX, ToDecl);
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase, ImportChooseExpr) {

``




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


[clang] [clang][Interp] Support AddOffset with 128bit offsets (PR #68679)

2023-10-13 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/68679

>From 8aae860a7079d50e8b3a657335e115c2cca9fcc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 10 Oct 2023 08:52:43 +0200
Subject: [PATCH] [clang][Interp] Support AddOffset with 128bit offsets

---
 clang/lib/AST/Interp/Boolean.h|  1 +
 clang/lib/AST/Interp/Integral.h   |  3 +++
 clang/lib/AST/Interp/IntegralAP.h |  3 +++
 clang/lib/AST/Interp/Interp.h |  4 ++--
 clang/test/AST/Interp/intap.cpp   | 10 ++
 5 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index c3ed3d61f76ca1c..336f7941dfc479d 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -42,6 +42,7 @@ class Boolean final {
   bool operator>(unsigned RHS) const { return static_cast(V) > RHS; }
 
   Boolean operator-() const { return Boolean(V); }
+  Boolean operator-(const Boolean &Other) const { return Boolean(V - Other.V); 
}
   Boolean operator~() const { return Boolean(true); }
 
   explicit operator int8_t() const { return V; }
diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 4dbe9c9bcb14b43..cc1cab8f39fb1e5 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -88,6 +88,9 @@ template  class Integral final {
   }
 
   Integral operator-() const { return Integral(-V); }
+  Integral operator-(const Integral &Other) const {
+return Integral(V - Other.V);
+  }
   Integral operator~() const { return Integral(~V); }
 
   template 
diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index f9a33bbcd7bd7fa..f17fb8e484415d2 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -59,6 +59,9 @@ template  class IntegralAP final {
   IntegralAP() : V(APSInt::getMaxValue(1024, Signed)) {}
 
   IntegralAP operator-() const { return IntegralAP(-V); }
+  IntegralAP operator-(const IntegralAP &Other) const {
+return IntegralAP(V - Other.V);
+  }
   bool operator>(IntegralAP RHS) const { return V > RHS.V; }
   bool operator>=(IntegralAP RHS) const { return V >= RHS.V; }
   bool operator<(IntegralAP RHS) const { return V < RHS.V; }
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 1ad3b8bfc7711d3..e3e6a4cec63b194 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1421,7 +1421,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T 
&Offset,
   // Get a version of the index comparable to the type.
   T Index = T::from(Ptr.getIndex(), Offset.bitWidth());
   // Compute the largest index into the array.
-  unsigned MaxIndex = Ptr.getNumElems();
+  T MaxIndex = T::from(Ptr.getNumElems(), Offset.bitWidth());
 
   // Helper to report an invalid offset, computed as APSInt.
   auto InvalidOffset = [&]() {
@@ -1437,7 +1437,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T 
&Offset,
 return false;
   };
 
-  unsigned MaxOffset = MaxIndex - Ptr.getIndex();
+  T MaxOffset = T::from(MaxIndex - Index, Offset.bitWidth());
   if constexpr (Op == ArithOp::Add) {
 // If the new offset would be negative, bail out.
 if (Offset.isNegative() && (Offset.isMin() || -Offset > Index))
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 8fe65a69a4fee8d..f9cbc698a3290d8 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -90,4 +90,14 @@ namespace i128 {
// expected-error {{must be 
initialized by a constant expression}} \
// expected-note {{is outside the 
range of representable values of type}}
 }
+
+namespace AddSubOffset {
+  constexpr __int128 A = 1;
+  constexpr int arr[] = {1,2,3};
+  constexpr const int *P = arr + A;
+  static_assert(*P == 2, "");
+  constexpr const int *P2 = P - A;
+  static_assert(*P2 == 1,"");
+}
+
 #endif

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


[clang] [clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-10-13 Thread via cfe-commits

https://github.com/mzyKi updated https://github.com/llvm/llvm-project/pull/68774

>From e45c5e2792563ee8c7d84106fd6860656bac63bc Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Wed, 11 Oct 2023 15:45:36 +0800
Subject: [PATCH] [clang][ASTImporter] Fix crash when template class static
 member imported to other translation unit. Fixes: #68769

---
 clang/docs/ReleaseNotes.rst |  4 +++
 clang/lib/AST/ASTImporter.cpp   | 11 +
 clang/unittests/AST/ASTImporterTest.cpp | 33 +
 3 files changed, 48 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..3be9e60c82a18d0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -497,6 +497,10 @@ Bug Fixes to C++ Support
   rather than prefer the non-templated constructor as specified in
   [standard.group]p3.
 
+- Fix crash when template class static member imported to other translation 
unit.
+  Fixes:
+  (`#68769 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 72e70427161bb0e..2a8add84f55dc3b 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -4475,6 +4475,17 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
 auto ToVTOrErr = import(D->getDescribedVarTemplate());
 if (!ToVTOrErr)
   return ToVTOrErr.takeError();
+  } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) 
{
+TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
+VarDecl *FromInst = D->getInstantiatedFromStaticDataMember();
+if (Expected ToInstOrErr = import(FromInst))
+  ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
+else
+  return ToInstOrErr.takeError();
+if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
+  ToVar->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+else
+  return POIOrErr.takeError();
   }
 
   if (Error Err = ImportInitializer(D, ToVar))
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 393ed44de3f1831..f08befcc1f0db7e 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -1373,6 +1373,39 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportCorrectTemplatedDecl) {
   ASSERT_EQ(ToTemplated1, ToTemplated);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, 
ImportTemplateSpecializationStaticMember) {
+  auto FromCode = R"(
+  template  class Test{
+  public:
+ static const unsigned int length;
+  };
+
+  template<> const unsigned int Test::length;
+  template<> const unsigned int Test::length = 0;
+  )";
+  auto ToCode = R"(
+template  class Test
+{
+public:
+   static const unsigned int length;
+};
+template<> const unsigned int Test::length;
+
+void foo(){
+int i = 1 / Test::length;
+}
+)";
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX14);
+  auto FromDecl = FirstDeclMatcher().match(
+  FromTU, varDecl(hasName("length"), isDefinition()));
+  Decl *ToTu = getToTuDecl(ToCode, Lang_CXX14);
+  auto ToX = Import(FromDecl, Lang_CXX03);
+  auto ToDecl = FirstDeclMatcher().match(
+  ToTu, varDecl(hasName("length"), isDefinition()));
+  EXPECT_TRUE(ToX);
+  EXPECT_EQ(ToX, ToDecl);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportChooseExpr) {
   // This tests the import of isConditionTrue directly to make sure the 
importer
   // gets it right.

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-10-13 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] [ARM] fix "+fp.dp" in multilib selection (PR #67412)

2023-10-13 Thread Dominik Wójt via cfe-commits


@@ -366,26 +366,50 @@ StringRef ARM::getArchExtFeature(StringRef ArchExt) {
 }
 
 static ARM::FPUKind findDoublePrecisionFPU(ARM::FPUKind InputFPUKind) {
+  if (InputFPUKind == ARM::FK_INVALID || InputFPUKind == ARM::FK_NONE)
+return ARM::FK_INVALID;
+
+  const ARM::FPUName &InputFPU = ARM::FPUNames[InputFPUKind];
+
+  if (ARM::isDoublePrecision(InputFPU.Restriction))
+return InputFPUKind;
+
+  // Otherwise, look for an FPU entry with all the same fields, except
+  // that it supports double precision.
+  for (const ARM::FPUName &CandidateFPU : ARM::FPUNames) {
+if (CandidateFPU.FPUVer == InputFPU.FPUVer &&
+CandidateFPU.NeonSupport == InputFPU.NeonSupport &&
+ARM::has32Regs(CandidateFPU.Restriction) ==
+ARM::has32Regs(InputFPU.Restriction) &&
+ARM::isDoublePrecision(CandidateFPU.Restriction)) {
+  return CandidateFPU.ID;
+}
+  }
+
+  // nothing found
+  return ARM::FK_INVALID;
+}
+
+static ARM::FPUKind findSinglePrecisionFPU(ARM::FPUKind InputFPUKind) {
+  if (InputFPUKind == ARM::FK_INVALID || InputFPUKind == ARM::FK_NONE)
+return ARM::FK_INVALID;
+
   const ARM::FPUName &InputFPU = ARM::FPUNames[InputFPUKind];
 
   // If the input FPU already supports double-precision, then there
   // isn't any different FPU we can return here.

domin144 wrote:

Indeed. Thanks for spotting this.

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


[PATCH] D156453: [clang][Interp] Create only globals when initializing a global variable

2023-10-13 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156453

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-13 Thread via cfe-commits

vabridgers wrote:

> Hi! This commit broke some armv8/armv7 bots: 
> https://lab.llvm.org/buildbot/#/builders/245/builds/15263 
> https://lab.llvm.org/buildbot/#/builders/187/builds/13069 Int & Void* have 
> the same size there, so no warning on bitfield-width.c:20.

I'll revert this change for now then. 

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-13 Thread via cfe-commits

https://github.com/serge-sans-paille created 
https://github.com/llvm/llvm-project/pull/68962

The _mm_cmpistri instruction can be used to quickly parse identifiers.

With this patch activated, clang pre-processes  1.8% faster, and 
sqlite3.c amalgametion 1.5% faster, based on time measurements and number of 
executed instructions as measured by valgrind.

The introduction of an extra helper function in the regular case has no impact 
on performance, see


https://llvm-compile-time-tracker.com/compare.php?from=30240e428f0ec7d4a6d1b84f9f807ce12b46cfd1&to=12bcb016cde4579ca7b75397762098c03eb4f264&stat=instructions:u

>From ccf33cafada526241a3fb1aca9c2d280444b589b Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 12 Oct 2023 22:30:30 +0200
Subject: [PATCH] [clang] Provide an SSE4.2 implementation of identifier token
 lexer

The _mm_cmpistri instruction can be used to quickly parse identifiers.

With this patch activated, clang pre-processes  1.8% faster, and
sqlite3.c amalgametion 1.5% faster, based on time measurements and
number of executed instructions as measured by valgrind.

The introduction of an extra helper function in the regular case has no
impact on performance, see


https://llvm-compile-time-tracker.com/compare.php?from=30240e428f0ec7d4a6d1b84f9f807ce12b46cfd1&to=12bcb016cde4579ca7b75397762098c03eb4f264&stat=instructions:u
---
 clang/lib/Lex/Lexer.cpp | 45 ++---
 1 file changed, 38 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index feed1b9ecd71a8d..f2d9eb3a8af4e3d 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -47,6 +47,10 @@
 #include 
 #include 
 
+#ifdef __SSE4_2__
+#include 
+#endif
+
 using namespace clang;
 
 
//===--===//
@@ -1847,19 +1851,46 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, 
uint32_t C,
   return true;
 }
 
+static const char *fastParseASCIIIdentifier(const char *CurPtr, const char* 
BufferEnd) {
+#ifdef __SSE4_2__
+  static constexpr char AsciiIdentifierRange[16] = {
+  '_', '_', 'A', 'Z', 'a', 'z', '0', '9',
+  };
+  constexpr ssize_t BytesPerRegister = 16;
+
+  while (LLVM_LIKELY(BufferEnd - CurPtr >= BytesPerRegister)) {
+__m128i AsciiIdentifierRangeV = _mm_loadu_si128((const __m128i 
*)AsciiIdentifierRange);
+
+  __m128i Cv = _mm_loadu_si128((const __m128i *)(CurPtr));
+  int Consumed =
+  _mm_cmpistri(AsciiIdentifierRangeV, Cv,
+   _SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES |
+   _SIDD_UBYTE_OPS | _SIDD_NEGATIVE_POLARITY);
+  CurPtr += Consumed;
+  if (Consumed == BytesPerRegister)
+continue;
+  return CurPtr;
+  }
+#else
+  (void)BufferEnd;
+#endif
+
+  unsigned char C = *CurPtr;
+  while (isAsciiIdentifierContinue(C))
+C = *++CurPtr;
+  return CurPtr;
+}
+
 bool Lexer::LexIdentifierContinue(Token &Result, const char *CurPtr) {
   // Match [_A-Za-z0-9]*, we have already matched an identifier start.
+
   while (true) {
-unsigned char C = *CurPtr;
-// Fast path.
-if (isAsciiIdentifierContinue(C)) {
-  ++CurPtr;
-  continue;
-}
+
+CurPtr = fastParseASCIIIdentifier(CurPtr, BufferEnd);
 
 unsigned Size;
 // Slow path: handle trigraph, unicode codepoints, UCNs.
-C = getCharAndSize(CurPtr, Size);
+unsigned char C = getCharAndSize(CurPtr, Size);
 if (isAsciiIdentifierContinue(C)) {
   CurPtr = ConsumeChar(CurPtr, Size, Result);
   continue;

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (serge-sans-paille)


Changes

The _mm_cmpistri instruction can be used to quickly parse identifiers.

With this patch activated, clang pre-processes  1.8% faster, 
and sqlite3.c amalgametion 1.5% faster, based on time measurements and number 
of executed instructions as measured by valgrind.

The introduction of an extra helper function in the regular case has no impact 
on performance, see


https://llvm-compile-time-tracker.com/compare.php?from=30240e428f0ec7d4a6d1b84f9f807ce12b46cfd1&to=12bcb016cde4579ca7b75397762098c03eb4f264&stat=instructions:u

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


1 Files Affected:

- (modified) clang/lib/Lex/Lexer.cpp (+38-7) 


``diff
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index feed1b9ecd71a8d..f2d9eb3a8af4e3d 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -47,6 +47,10 @@
 #include 
 #include 
 
+#ifdef __SSE4_2__
+#include 
+#endif
+
 using namespace clang;
 
 
//===--===//
@@ -1847,19 +1851,46 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, 
uint32_t C,
   return true;
 }
 
+static const char *fastParseASCIIIdentifier(const char *CurPtr, const char* 
BufferEnd) {
+#ifdef __SSE4_2__
+  static constexpr char AsciiIdentifierRange[16] = {
+  '_', '_', 'A', 'Z', 'a', 'z', '0', '9',
+  };
+  constexpr ssize_t BytesPerRegister = 16;
+
+  while (LLVM_LIKELY(BufferEnd - CurPtr >= BytesPerRegister)) {
+__m128i AsciiIdentifierRangeV = _mm_loadu_si128((const __m128i 
*)AsciiIdentifierRange);
+
+  __m128i Cv = _mm_loadu_si128((const __m128i *)(CurPtr));
+  int Consumed =
+  _mm_cmpistri(AsciiIdentifierRangeV, Cv,
+   _SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES |
+   _SIDD_UBYTE_OPS | _SIDD_NEGATIVE_POLARITY);
+  CurPtr += Consumed;
+  if (Consumed == BytesPerRegister)
+continue;
+  return CurPtr;
+  }
+#else
+  (void)BufferEnd;
+#endif
+
+  unsigned char C = *CurPtr;
+  while (isAsciiIdentifierContinue(C))
+C = *++CurPtr;
+  return CurPtr;
+}
+
 bool Lexer::LexIdentifierContinue(Token &Result, const char *CurPtr) {
   // Match [_A-Za-z0-9]*, we have already matched an identifier start.
+
   while (true) {
-unsigned char C = *CurPtr;
-// Fast path.
-if (isAsciiIdentifierContinue(C)) {
-  ++CurPtr;
-  continue;
-}
+
+CurPtr = fastParseASCIIIdentifier(CurPtr, BufferEnd);
 
 unsigned Size;
 // Slow path: handle trigraph, unicode codepoints, UCNs.
-C = getCharAndSize(CurPtr, Size);
+unsigned char C = getCharAndSize(CurPtr, Size);
 if (isAsciiIdentifierContinue(C)) {
   CurPtr = ConsumeChar(CurPtr, Size, Result);
   continue;

``




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


[clang] Revert "[Sema] Add check for bitfield assignments to integral types" (PR #68963)

2023-10-13 Thread via cfe-commits

https://github.com/vabridgers created 
https://github.com/llvm/llvm-project/pull/68963

This reverts commit 47e36266e93de9c34ba3028951a58124864bb2b4.

This change broke some arm8/arm7 build bots because int and void * have the 
same size.

>From d431af998d3cf677417f337842e66fa8d13692c8 Mon Sep 17 00:00:00 2001
From: einvbri 
Date: Fri, 13 Oct 2023 10:47:32 +0200
Subject: [PATCH] Revert "[Sema] Add check for bitfield assignments to integral
 types"

This reverts commit 47e36266e93de9c34ba3028951a58124864bb2b4.

This change broke some arm8/arm7 build bots because int and void * have
the same size.
---
 clang/docs/ReleaseNotes.rst   |  3 --
 clang/include/clang/Basic/DiagnosticGroups.td |  2 --
 .../clang/Basic/DiagnosticSemaKinds.td|  3 --
 clang/lib/Sema/SemaChecking.cpp   | 13 +--
 clang/test/SemaCXX/bitfield-width.c   | 34 ---
 5 files changed, 1 insertion(+), 54 deletions(-)
 delete mode 100644 clang/test/SemaCXX/bitfield-width.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 31969201a1cac8c..2d918967e7f0b02 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -185,9 +185,6 @@ New Compiler Flags
   the preprocessed text to the output. This can greatly reduce the size of the
   preprocessed output, which can be helpful when trying to reduce a test case.
 
-* ``-Wbitfield-conversion`` was added to detect assignments of integral
-  types to a bitfield that may change the value.
-
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 674eb9f4ef2e73f..0b09c002191848a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -53,7 +53,6 @@ def SingleBitBitFieldConstantConversion :
 def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion",

[SingleBitBitFieldConstantConversion]>;
 def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">;
-def BitFieldConversion : DiagGroup<"bitfield-conversion">;
 def BitFieldWidth : DiagGroup<"bitfield-width">;
 def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">;
 def CompoundTokenSplitBySpace : DiagGroup<"compound-token-split-by-space">;
@@ -934,7 +933,6 @@ def Conversion : DiagGroup<"conversion",
 ConstantConversion,
 EnumConversion,
 BitFieldEnumConversion,
-BitFieldConversion,
 FloatConversion,
 Shorten64To32,
 IntConversion,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ab7fe881976aad2..c1a6e3831127e56 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6171,9 +6171,6 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
-def warn_bitfield_too_small_for_integral_type : Warning<
-  "conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
-  InGroup, DefaultIgnore;
 def note_change_bitfield_sign : Note<
   "consider making the bitfield type %select{unsigned|signed}0">;
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index cd61459cfbb13d6..35b36db2049db09 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14298,18 +14298,6 @@ static bool AnalyzeBitFieldAssignment(Sema &S, 
FieldDecl *Bitfield, Expr *Init,
 S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
 << BitsNeeded << ED << WidthExpr->getSourceRange();
   }
-} else if (OriginalInit->getType()->isIntegralType(S.Context)) {
-  IntRange LikelySourceRange =
-  GetExprRange(S.Context, Init, S.isConstantEvaluatedContext(),
-   /*Approximate=*/true);
-
-  if (LikelySourceRange.Width > FieldWidth) {
-Expr *WidthExpr = Bitfield->getBitWidth();
-S.Diag(InitLoc, diag::warn_bitfield_too_small_for_integral_type)
-<< Bitfield << FieldWidth << OriginalInit->getType()
-<< LikelySourceRange.Width;
-S.Diag(WidthExpr->getExprLoc(), diag::note_declared_at);
-  }
 }
 
 return false;
@@ -15207,6 +15195,7 @@ static void CheckImplicitConversion(Sema &S, Expr *E, 
QualType T,
 
   if (LikelySourceRange.Width > TargetRange.Width) {
 // If the source is a constant, use a default-on diagnostic.
+// TODO: this should happen for bitfield stores, too.
 Expr::EvalResult Result;
 if (E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects,
  S.isCo

[clang] Revert "[Sema] Add check for bitfield assignments to integral types" (PR #68963)

2023-10-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (vabridgers)


Changes

This reverts commit 47e36266e93de9c34ba3028951a58124864bb2b4.

This change broke some arm8/arm7 build bots because int and void * have the 
same size.

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


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (-3) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (-2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-3) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+1-12) 
- (removed) clang/test/SemaCXX/bitfield-width.c (-34) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 31969201a1cac8c..2d918967e7f0b02 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -185,9 +185,6 @@ New Compiler Flags
   the preprocessed text to the output. This can greatly reduce the size of the
   preprocessed output, which can be helpful when trying to reduce a test case.
 
-* ``-Wbitfield-conversion`` was added to detect assignments of integral
-  types to a bitfield that may change the value.
-
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 674eb9f4ef2e73f..0b09c002191848a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -53,7 +53,6 @@ def SingleBitBitFieldConstantConversion :
 def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion",

[SingleBitBitFieldConstantConversion]>;
 def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">;
-def BitFieldConversion : DiagGroup<"bitfield-conversion">;
 def BitFieldWidth : DiagGroup<"bitfield-width">;
 def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">;
 def CompoundTokenSplitBySpace : DiagGroup<"compound-token-split-by-space">;
@@ -934,7 +933,6 @@ def Conversion : DiagGroup<"conversion",
 ConstantConversion,
 EnumConversion,
 BitFieldEnumConversion,
-BitFieldConversion,
 FloatConversion,
 Shorten64To32,
 IntConversion,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ab7fe881976aad2..c1a6e3831127e56 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6171,9 +6171,6 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
-def warn_bitfield_too_small_for_integral_type : Warning<
-  "conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
-  InGroup, DefaultIgnore;
 def note_change_bitfield_sign : Note<
   "consider making the bitfield type %select{unsigned|signed}0">;
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index cd61459cfbb13d6..35b36db2049db09 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14298,18 +14298,6 @@ static bool AnalyzeBitFieldAssignment(Sema &S, 
FieldDecl *Bitfield, Expr *Init,
 S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
 << BitsNeeded << ED << WidthExpr->getSourceRange();
   }
-} else if (OriginalInit->getType()->isIntegralType(S.Context)) {
-  IntRange LikelySourceRange =
-  GetExprRange(S.Context, Init, S.isConstantEvaluatedContext(),
-   /*Approximate=*/true);
-
-  if (LikelySourceRange.Width > FieldWidth) {
-Expr *WidthExpr = Bitfield->getBitWidth();
-S.Diag(InitLoc, diag::warn_bitfield_too_small_for_integral_type)
-<< Bitfield << FieldWidth << OriginalInit->getType()
-<< LikelySourceRange.Width;
-S.Diag(WidthExpr->getExprLoc(), diag::note_declared_at);
-  }
 }
 
 return false;
@@ -15207,6 +15195,7 @@ static void CheckImplicitConversion(Sema &S, Expr *E, 
QualType T,
 
   if (LikelySourceRange.Width > TargetRange.Width) {
 // If the source is a constant, use a default-on diagnostic.
+// TODO: this should happen for bitfield stores, too.
 Expr::EvalResult Result;
 if (E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects,
  S.isConstantEvaluatedContext())) {
diff --git a/clang/test/SemaCXX/bitfield-width.c 
b/clang/test/SemaCXX/bitfield-width.c
deleted file mode 100644
index 8219054b959e544..000
--- a/clang/test/SemaCXX/bitfield-width.c
+++ /dev/null
@@ -1,34 +0,0 @@
-// RUN: %clang_cc1 -Wconversion -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wbitfield-conversion -fsyntax-only -verify %s
-

[clang] [clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-10-13 Thread via cfe-commits

https://github.com/mzyKi updated https://github.com/llvm/llvm-project/pull/68774

>From a0e6d307436ab147bc02db5c38c9453d98379074 Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Wed, 11 Oct 2023 15:45:36 +0800
Subject: [PATCH] [clang][ASTImporter] Fix crash when template class static
 member imported to other translation unit. Fixes: #68769

---
 clang/docs/ReleaseNotes.rst |  4 +++
 clang/lib/AST/ASTImporter.cpp   | 11 
 clang/unittests/AST/ASTImporterTest.cpp | 34 +
 3 files changed, 49 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 31969201a1cac8c..bd3869bc9c010f9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -500,6 +500,10 @@ Bug Fixes to C++ Support
   rather than prefer the non-templated constructor as specified in
   [standard.group]p3.
 
+- Fix crash when template class static member imported to other translation 
unit.
+  Fixes:
+  (`#68769 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 72e70427161bb0e..2a8add84f55dc3b 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -4475,6 +4475,17 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
 auto ToVTOrErr = import(D->getDescribedVarTemplate());
 if (!ToVTOrErr)
   return ToVTOrErr.takeError();
+  } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) 
{
+TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
+VarDecl *FromInst = D->getInstantiatedFromStaticDataMember();
+if (Expected ToInstOrErr = import(FromInst))
+  ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
+else
+  return ToInstOrErr.takeError();
+if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
+  ToVar->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+else
+  return POIOrErr.takeError();
   }
 
   if (Error Err = ImportInitializer(D, ToVar))
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 393ed44de3f1831..b0cc598a369abe9 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -1373,6 +1373,40 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportCorrectTemplatedDecl) {
   ASSERT_EQ(ToTemplated1, ToTemplated);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportTemplateSpecializationStaticMember) {
+  auto FromCode = R"(
+  template  class Test{
+  public:
+ static const unsigned int length;
+  };
+
+  template<> const unsigned int Test::length;
+  template<> const unsigned int Test::length = 0;
+  )";
+  auto ToCode = R"(
+template  class Test
+{
+public:
+   static const unsigned int length;
+};
+template<> const unsigned int Test::length;
+
+void foo(){
+int i = 1 / Test::length;
+}
+)";
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX14);
+  auto FromDecl = FirstDeclMatcher().match(
+  FromTU, varDecl(hasName("length"), isDefinition()));
+  Decl *ToTu = getToTuDecl(ToCode, Lang_CXX14);
+  auto ToX = Import(FromDecl, Lang_CXX03);
+  auto ToDecl = FirstDeclMatcher().match(
+  ToTu, varDecl(hasName("length"), isDefinition()));
+  EXPECT_TRUE(ToX);
+  EXPECT_EQ(ToX, ToDecl);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportChooseExpr) {
   // This tests the import of isConditionTrue directly to make sure the 
importer
   // gets it right.

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-13 Thread via cfe-commits

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-13 Thread via cfe-commits

https://github.com/cor3ntin commented:

This is pretty neat.
I'm wondering if this change would be tested by any of our bots?

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-13 Thread via cfe-commits


@@ -1847,19 +1851,46 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, 
uint32_t C,
   return true;
 }
 
+static const char *fastParseASCIIIdentifier(const char *CurPtr, const char* 
BufferEnd) {

cor3ntin wrote:

```suggestion
static const char *fastParseASCIIIdentifier(const char *CurPtr, 
[[maybe_unused]] const char* BufferEnd) {
```

This way you can get rid of the `#else`

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-13 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 9a8ff346bb20a684e8edd62035077aba06bea084 
ccf33cafada526241a3fb1aca9c2d280444b589b -- clang/lib/Lex/Lexer.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index f2d9eb3a8af4..ff8584a9614f 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -1851,7 +1851,8 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, 
uint32_t C,
   return true;
 }
 
-static const char *fastParseASCIIIdentifier(const char *CurPtr, const char* 
BufferEnd) {
+static const char *fastParseASCIIIdentifier(const char *CurPtr,
+const char *BufferEnd) {
 #ifdef __SSE4_2__
   static constexpr char AsciiIdentifierRange[16] = {
   '_', '_', 'A', 'Z', 'a', 'z', '0', '9',
@@ -1859,17 +1860,17 @@ static const char *fastParseASCIIIdentifier(const char 
*CurPtr, const char* Buff
   constexpr ssize_t BytesPerRegister = 16;
 
   while (LLVM_LIKELY(BufferEnd - CurPtr >= BytesPerRegister)) {
-__m128i AsciiIdentifierRangeV = _mm_loadu_si128((const __m128i 
*)AsciiIdentifierRange);
-
-  __m128i Cv = _mm_loadu_si128((const __m128i *)(CurPtr));
-  int Consumed =
-  _mm_cmpistri(AsciiIdentifierRangeV, Cv,
-   _SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES |
-   _SIDD_UBYTE_OPS | _SIDD_NEGATIVE_POLARITY);
-  CurPtr += Consumed;
-  if (Consumed == BytesPerRegister)
-continue;
-  return CurPtr;
+__m128i AsciiIdentifierRangeV =
+_mm_loadu_si128((const __m128i *)AsciiIdentifierRange);
+
+__m128i Cv = _mm_loadu_si128((const __m128i *)(CurPtr));
+int Consumed = _mm_cmpistri(AsciiIdentifierRangeV, Cv,
+_SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES |
+_SIDD_UBYTE_OPS | _SIDD_NEGATIVE_POLARITY);
+CurPtr += Consumed;
+if (Consumed == BytesPerRegister)
+  continue;
+return CurPtr;
   }
 #else
   (void)BufferEnd;

``




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


[clang] Revert "[Sema] Add check for bitfield assignments to integral types" (PR #68963)

2023-10-13 Thread via cfe-commits

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


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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-13 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/66514

>From a243ff13af3fd245250f6f8bdbe6deb96e574da9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 01/12] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 .../clang/Frontend/CodeSnippetHighlighter.h   |  46 +++
 clang/include/clang/Frontend/TextDiagnostic.h |   2 +
 clang/lib/Frontend/CMakeLists.txt |   1 +
 clang/lib/Frontend/CodeSnippetHighlighter.cpp | 120 ++
 clang/lib/Frontend/TextDiagnostic.cpp |  26 
 5 files changed, 195 insertions(+)
 create mode 100644 clang/include/clang/Frontend/CodeSnippetHighlighter.h
 create mode 100644 clang/lib/Frontend/CodeSnippetHighlighter.cpp

diff --git a/clang/include/clang/Frontend/CodeSnippetHighlighter.h 
b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
new file mode 100644
index 000..776954b59e2e1a8
--- /dev/null
+++ b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
@@ -0,0 +1,46 @@
+//===--- CodeSnippetHighlighter.h - Code snippet highlighting ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+#define LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+
+struct StyleRange {
+  unsigned Start;
+  unsigned End;
+  const enum llvm::raw_ostream::Colors c;
+};
+
+class CodeSnippetHighlighter final {
+public:
+  CodeSnippetHighlighter() = default;
+
+  /// Produce StyleRanges for the given line.
+  /// The returned vector contains non-overlapping style ranges. They are 
sorted
+  /// from beginning of the line to the end.
+  std::vector highlightLine(llvm::StringRef SourceLine,
+const LangOptions &LangOpts);
+
+private:
+  bool Initialized = false;
+  /// Fills Keywords and Literals.
+  void ensureTokenData();
+
+  llvm::SmallSet Keywords;
+  llvm::SmallSet Literals;
+};
+
+} // namespace clang
+
+#endif
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..59fd4d4f9408d48 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
+#include "clang/Frontend/CodeSnippetHighlighter.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 
 namespace clang {
@@ -33,6 +34,7 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  CodeSnippetHighlighter SnippetHighlighter;
 
 public:
   TextDiagnostic(raw_ostream &OS,
diff --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 1e5f0a859dfd568..f3547f771593093 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangFrontend
   TextDiagnosticPrinter.cpp
   VerifyDiagnosticConsumer.cpp
   InterfaceStubFunctionsConsumer.cpp
+  CodeSnippetHighlighter.cpp
 
   DEPENDS
   ClangDriverOptions
diff --git a/clang/lib/Frontend/CodeSnippetHighlighter.cpp 
b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
new file mode 100644
index 000..829a533ad2692e5
--- /dev/null
+++ b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
@@ -0,0 +1,120 @@
+
+#include "clang/Frontend/CodeSnippetHighlighter.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void CodeSnippetHighlighter::ensureTokenData() {
+  if (Initialized)
+return;
+
+  // List of keywords, literals and types we want to highlight.
+  // These are best-effort, as is everything we do wrt. highlighting.
+  Keywords.insert("_Static_assert");
+  Keywords.insert("auto");
+  Keywords.insert("concept");
+  Keywords.insert("const");
+  Keywords.insert("consteval");
+  Keywords.insert("constexpr");
+  Keywords.insert("delete");
+  Keywords.insert("do");
+  Keywords.insert("else");
+  Keywords.insert("final");
+  Keywords.insert("for");
+  Keywords.insert("if");
+  Keywords.insert("m

[clang] Revert "[Sema] Add check for bitfield assignments to integral types" (PR #68963)

2023-10-13 Thread via cfe-commits

cor3ntin wrote:

Original PR - https://github.com/llvm/llvm-project/pull/68276 
FYI you do not need to make a PR to revert a change that breaks the build - 
especially your own

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-13 Thread Timm Baeder via cfe-commits


@@ -1847,19 +1851,46 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, 
uint32_t C,
   return true;
 }
 
+static const char *fastParseASCIIIdentifier(const char *CurPtr, const char* 
BufferEnd) {
+#ifdef __SSE4_2__
+  static constexpr char AsciiIdentifierRange[16] = {
+  '_', '_', 'A', 'Z', 'a', 'z', '0', '9',
+  };
+  constexpr ssize_t BytesPerRegister = 16;
+
+  while (LLVM_LIKELY(BufferEnd - CurPtr >= BytesPerRegister)) {
+__m128i AsciiIdentifierRangeV = _mm_loadu_si128((const __m128i 
*)AsciiIdentifierRange);

tbaederr wrote:

Can't you pull this out of the loop?

And can't you do an aligned load here (if you add the right `alignas()` to the 
declaration)?

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


[clang] [ARM] fix "+fp.dp" in multilib selection (PR #67412)

2023-10-13 Thread Dominik Wójt via cfe-commits


@@ -420,20 +444,35 @@ bool ARM::appendArchExtFeatures(StringRef CPU, 
ARM::ArchKind AK,
 CPU = "generic";
 
   if (ArchExt == "fp" || ArchExt == "fp.dp") {
+const ARM::FPUKind DefaultFPU = getDefaultFPU(CPU, AK);
 ARM::FPUKind FPUKind;
 if (ArchExt == "fp.dp") {
+  const bool IsDP = ArgFPUKind != ARM::FK_INVALID &&
+ArgFPUKind != ARM::FK_NONE &&
+isDoublePrecision(getFPURestriction(ArgFPUKind));

domin144 wrote:

The `appendArchExtFeatures` is called repeatedly in `DecodeARMFeatures`. There 
can be multiple FPU related extensions specified. e.g. 
`-march=armv8-m.main+nofp+fp+nofp.dp` should disable FPU, enable default 
FPU(fpv5-d16) and then switch to single precission equivalent FPU(fpv5-sp-d16).

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-13 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/66514

>From a243ff13af3fd245250f6f8bdbe6deb96e574da9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 01/13] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 .../clang/Frontend/CodeSnippetHighlighter.h   |  46 +++
 clang/include/clang/Frontend/TextDiagnostic.h |   2 +
 clang/lib/Frontend/CMakeLists.txt |   1 +
 clang/lib/Frontend/CodeSnippetHighlighter.cpp | 120 ++
 clang/lib/Frontend/TextDiagnostic.cpp |  26 
 5 files changed, 195 insertions(+)
 create mode 100644 clang/include/clang/Frontend/CodeSnippetHighlighter.h
 create mode 100644 clang/lib/Frontend/CodeSnippetHighlighter.cpp

diff --git a/clang/include/clang/Frontend/CodeSnippetHighlighter.h 
b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
new file mode 100644
index 000..776954b59e2e1a8
--- /dev/null
+++ b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
@@ -0,0 +1,46 @@
+//===--- CodeSnippetHighlighter.h - Code snippet highlighting ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+#define LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+
+struct StyleRange {
+  unsigned Start;
+  unsigned End;
+  const enum llvm::raw_ostream::Colors c;
+};
+
+class CodeSnippetHighlighter final {
+public:
+  CodeSnippetHighlighter() = default;
+
+  /// Produce StyleRanges for the given line.
+  /// The returned vector contains non-overlapping style ranges. They are 
sorted
+  /// from beginning of the line to the end.
+  std::vector highlightLine(llvm::StringRef SourceLine,
+const LangOptions &LangOpts);
+
+private:
+  bool Initialized = false;
+  /// Fills Keywords and Literals.
+  void ensureTokenData();
+
+  llvm::SmallSet Keywords;
+  llvm::SmallSet Literals;
+};
+
+} // namespace clang
+
+#endif
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..59fd4d4f9408d48 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
+#include "clang/Frontend/CodeSnippetHighlighter.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 
 namespace clang {
@@ -33,6 +34,7 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  CodeSnippetHighlighter SnippetHighlighter;
 
 public:
   TextDiagnostic(raw_ostream &OS,
diff --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 1e5f0a859dfd568..f3547f771593093 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangFrontend
   TextDiagnosticPrinter.cpp
   VerifyDiagnosticConsumer.cpp
   InterfaceStubFunctionsConsumer.cpp
+  CodeSnippetHighlighter.cpp
 
   DEPENDS
   ClangDriverOptions
diff --git a/clang/lib/Frontend/CodeSnippetHighlighter.cpp 
b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
new file mode 100644
index 000..829a533ad2692e5
--- /dev/null
+++ b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
@@ -0,0 +1,120 @@
+
+#include "clang/Frontend/CodeSnippetHighlighter.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void CodeSnippetHighlighter::ensureTokenData() {
+  if (Initialized)
+return;
+
+  // List of keywords, literals and types we want to highlight.
+  // These are best-effort, as is everything we do wrt. highlighting.
+  Keywords.insert("_Static_assert");
+  Keywords.insert("auto");
+  Keywords.insert("concept");
+  Keywords.insert("const");
+  Keywords.insert("consteval");
+  Keywords.insert("constexpr");
+  Keywords.insert("delete");
+  Keywords.insert("do");
+  Keywords.insert("else");
+  Keywords.insert("final");
+  Keywords.insert("for");
+  Keywords.insert("if

[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-13 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/66514

>From a243ff13af3fd245250f6f8bdbe6deb96e574da9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 01/13] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 .../clang/Frontend/CodeSnippetHighlighter.h   |  46 +++
 clang/include/clang/Frontend/TextDiagnostic.h |   2 +
 clang/lib/Frontend/CMakeLists.txt |   1 +
 clang/lib/Frontend/CodeSnippetHighlighter.cpp | 120 ++
 clang/lib/Frontend/TextDiagnostic.cpp |  26 
 5 files changed, 195 insertions(+)
 create mode 100644 clang/include/clang/Frontend/CodeSnippetHighlighter.h
 create mode 100644 clang/lib/Frontend/CodeSnippetHighlighter.cpp

diff --git a/clang/include/clang/Frontend/CodeSnippetHighlighter.h 
b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
new file mode 100644
index 000..776954b59e2e1a8
--- /dev/null
+++ b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
@@ -0,0 +1,46 @@
+//===--- CodeSnippetHighlighter.h - Code snippet highlighting ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+#define LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+
+struct StyleRange {
+  unsigned Start;
+  unsigned End;
+  const enum llvm::raw_ostream::Colors c;
+};
+
+class CodeSnippetHighlighter final {
+public:
+  CodeSnippetHighlighter() = default;
+
+  /// Produce StyleRanges for the given line.
+  /// The returned vector contains non-overlapping style ranges. They are 
sorted
+  /// from beginning of the line to the end.
+  std::vector highlightLine(llvm::StringRef SourceLine,
+const LangOptions &LangOpts);
+
+private:
+  bool Initialized = false;
+  /// Fills Keywords and Literals.
+  void ensureTokenData();
+
+  llvm::SmallSet Keywords;
+  llvm::SmallSet Literals;
+};
+
+} // namespace clang
+
+#endif
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..59fd4d4f9408d48 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
+#include "clang/Frontend/CodeSnippetHighlighter.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 
 namespace clang {
@@ -33,6 +34,7 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  CodeSnippetHighlighter SnippetHighlighter;
 
 public:
   TextDiagnostic(raw_ostream &OS,
diff --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 1e5f0a859dfd568..f3547f771593093 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangFrontend
   TextDiagnosticPrinter.cpp
   VerifyDiagnosticConsumer.cpp
   InterfaceStubFunctionsConsumer.cpp
+  CodeSnippetHighlighter.cpp
 
   DEPENDS
   ClangDriverOptions
diff --git a/clang/lib/Frontend/CodeSnippetHighlighter.cpp 
b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
new file mode 100644
index 000..829a533ad2692e5
--- /dev/null
+++ b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
@@ -0,0 +1,120 @@
+
+#include "clang/Frontend/CodeSnippetHighlighter.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void CodeSnippetHighlighter::ensureTokenData() {
+  if (Initialized)
+return;
+
+  // List of keywords, literals and types we want to highlight.
+  // These are best-effort, as is everything we do wrt. highlighting.
+  Keywords.insert("_Static_assert");
+  Keywords.insert("auto");
+  Keywords.insert("concept");
+  Keywords.insert("const");
+  Keywords.insert("consteval");
+  Keywords.insert("constexpr");
+  Keywords.insert("delete");
+  Keywords.insert("do");
+  Keywords.insert("else");
+  Keywords.insert("final");
+  Keywords.insert("for");
+  Keywords.insert("if

[clang] [ARM] fix "+fp.dp" in multilib selection (PR #67412)

2023-10-13 Thread Dominik Wójt via cfe-commits


@@ -420,20 +444,35 @@ bool ARM::appendArchExtFeatures(StringRef CPU, 
ARM::ArchKind AK,
 CPU = "generic";
 
   if (ArchExt == "fp" || ArchExt == "fp.dp") {
+const ARM::FPUKind DefaultFPU = getDefaultFPU(CPU, AK);
 ARM::FPUKind FPUKind;
 if (ArchExt == "fp.dp") {
+  const bool IsDP = ArgFPUKind != ARM::FK_INVALID &&
+ArgFPUKind != ARM::FK_NONE &&
+isDoublePrecision(getFPURestriction(ArgFPUKind));

domin144 wrote:

I will add a test case for this.

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


[clang] [mlir][arith] Fix canon pattern for large ints in chained arith (PR #68900)

2023-10-13 Thread Rik Huijzer via cfe-commits

https://github.com/rikhuijzer updated 
https://github.com/llvm/llvm-project/pull/68900

>From ddbde18e483d12485ba25c715e8a94480b9d6dcf Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Thu, 12 Oct 2023 16:55:22 +0200
Subject: [PATCH 1/3] [mlir][arith] Fix canon pattern for large ints in chained
 arith

---
 mlir/lib/Dialect/Arith/IR/ArithOps.cpp| 25 +++
 mlir/test/Dialect/Arith/canonicalize.mlir | 10 +
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp 
b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 0ecc288f3b07701..25578b1c52f331b 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -39,26 +39,35 @@ using namespace mlir::arith;
 static IntegerAttr
 applyToIntegerAttrs(PatternRewriter &builder, Value res, Attribute lhs,
 Attribute rhs,
-function_ref binFn) {
-  return builder.getIntegerAttr(res.getType(),
-binFn(llvm::cast(lhs).getInt(),
-  llvm::cast(rhs).getInt()));
+function_ref binFn) {
+  auto lhsVal = llvm::cast(lhs).getValue();
+  auto rhsVal = llvm::cast(rhs).getValue();
+  auto value = binFn(lhsVal, rhsVal);
+  return IntegerAttr::get(res.getType(), value);
 }
 
 static IntegerAttr addIntegerAttrs(PatternRewriter &builder, Value res,
Attribute lhs, Attribute rhs) {
-  return applyToIntegerAttrs(builder, res, lhs, rhs, std::plus());
+  auto binFn = [](APInt a, APInt& b) -> APInt {
+return std::move(a) + b;
+  };
+  return applyToIntegerAttrs(builder, res, lhs, rhs, binFn);
 }
 
 static IntegerAttr subIntegerAttrs(PatternRewriter &builder, Value res,
Attribute lhs, Attribute rhs) {
-  return applyToIntegerAttrs(builder, res, lhs, rhs, std::minus());
+  auto binFn = [](APInt a, APInt& b) -> APInt {
+return std::move(a) - b;
+  };
+  return applyToIntegerAttrs(builder, res, lhs, rhs, binFn);
 }
 
 static IntegerAttr mulIntegerAttrs(PatternRewriter &builder, Value res,
Attribute lhs, Attribute rhs) {
-  return applyToIntegerAttrs(builder, res, lhs, rhs,
- std::multiplies());
+  auto binFn = [](APInt a, APInt& b) -> APInt {
+return std::move(a) * b;
+  };
+  return applyToIntegerAttrs(builder, res, lhs, rhs, binFn);
 }
 
 /// Invert an integer comparison predicate.
diff --git a/mlir/test/Dialect/Arith/canonicalize.mlir 
b/mlir/test/Dialect/Arith/canonicalize.mlir
index 1b0547c9e8f804a..b18f5cfcb3f9a12 100644
--- a/mlir/test/Dialect/Arith/canonicalize.mlir
+++ b/mlir/test/Dialect/Arith/canonicalize.mlir
@@ -985,6 +985,16 @@ func.func @tripleMulIMulII32(%arg0: i32) -> i32 {
   return %mul2 : i32
 }
 
+// CHECK-LABEL: @tripleMulLargeInt
+//   CHECK:   return
+func.func @tripleMulLargeInt(%arg0: i256) -> i256 {
+  %0 = arith.constant 
3618502788666131213697322783095070105623107215331596699973092056135872020481 : 
i256
+  %c5 = arith.constant 5 : i256
+  %mul1 = arith.muli %arg0, %0 : i256
+  %mul2 = arith.muli %mul1, %c5 : i256
+  return %mul2 : i256
+}
+
 // CHECK-LABEL: @addiMuliToSubiRhsI32
 //  CHECK-SAME:   (%[[ARG0:.+]]: i32, %[[ARG1:.+]]: i32)
 //   CHECK:   %[[SUB:.+]] = arith.subi %[[ARG0]], %[[ARG1]] : i32

>From c0f3efe78fa6e71d1acc4d38f526ca2ec194ddf8 Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Fri, 13 Oct 2023 10:14:16 +0200
Subject: [PATCH 2/3] Apply suggestions from code review
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Markus Böck 
---
 mlir/lib/Dialect/Arith/IR/ArithOps.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp 
b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 25578b1c52f331b..b749af256e7 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -39,7 +39,7 @@ using namespace mlir::arith;
 static IntegerAttr
 applyToIntegerAttrs(PatternRewriter &builder, Value res, Attribute lhs,
 Attribute rhs,
-function_ref binFn) {
+function_ref binFn) {
   auto lhsVal = llvm::cast(lhs).getValue();
   auto rhsVal = llvm::cast(rhs).getValue();
   auto value = binFn(lhsVal, rhsVal);
@@ -49,7 +49,7 @@ applyToIntegerAttrs(PatternRewriter &builder, Value res, 
Attribute lhs,
 static IntegerAttr addIntegerAttrs(PatternRewriter &builder, Value res,
Attribute lhs, Attribute rhs) {
   auto binFn = [](APInt a, APInt& b) -> APInt {
-return std::move(a) + b;
+return a + b;
   };
   return applyToIntegerAttrs(builder, res, lhs, rhs, binFn);
 }

>From 30e1ce11d567452dcd7481e999109d1f25164065 Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Fri, 13 Oct 2023 10:49:20 +0200
Subject: [PATCH 3/3] Use `const`s and check result o

[clang] [analyzer][NFC] Simplifications in ArrayBoundV2 (PR #67572)

2023-10-13 Thread via cfe-commits

https://github.com/DonatNagyE updated 
https://github.com/llvm/llvm-project/pull/67572

>From 583b6c3bf838bf74899a1ce5ab53b3722ddb8e66 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Wed, 6 Sep 2023 13:39:27 +0200
Subject: [PATCH] [analyzer][NFC] Simplifications in ArrayBoundV2

I'm planning to improve diagnostics generation in `ArrayBoundCheckerV2`
but before that I'm refactoring the source code to clean up some
over-complicated code and an inaccurate comment.

Changes in this commit:
- Remove the `mutable std::unique_ptr` boilerplate, because
  it's no longer needed.
- Remove the code duplication between the methods `reportOOB()` and
  `reportTaintedOOB()`.
- Eliminate the class `RegionRawOffsetV2` because it's just a "reinvent
  the wheel" version of `std::pair` and it was used only once, as a
  temporary object that was immediately decomposed. (I suspect that
  `RegionRawOffset` in MemRegion.cpp could also be eliminated.)
- Flatten the code of `computeOffset()` which had contained six nested
  indentation levels before this commit.
- Ensure that `computeOffset()` returns `std::nullopt` instead of a
  `{Region, }` pair in the case when it encounters a
  `Location` that is not an `ElementRegion`. This ensures that the
  `checkLocation` callback returns early when it handles a memory access
  where it has "nothing to do" (no subscript operation or equivalent
  pointer arithmetic). (Note that this is still NFC because zero is a
  valid index everywhere, so the old logic without this shortcut
  eventually reached the same conclusion.)
- Correct a wrong explanation comment in `getSimplifiedOffsets()`.
---
 .../Checkers/ArrayBoundCheckerV2.cpp  | 221 +++---
 1 file changed, 86 insertions(+), 135 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
index db4a2fcea9b2cdd..e52eef0fe94370b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -32,15 +32,13 @@ using namespace taint;
 namespace {
 class ArrayBoundCheckerV2 :
 public Checker {
-  mutable std::unique_ptr BT;
-  mutable std::unique_ptr TaintBT;
+  BugType BT{this, "Out-of-bound access"};
+  BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
-  enum OOB_Kind { OOB_Precedes, OOB_Excedes };
+  enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-  void reportOOB(CheckerContext &C, ProgramStateRef errorState,
- OOB_Kind kind) const;
-  void reportTaintOOB(CheckerContext &C, ProgramStateRef errorState,
-  SVal TaintedSVal) const;
+  void reportOOB(CheckerContext &C, ProgramStateRef ErrorState, OOB_Kind Kind,
+ SVal TaintedSVal = UnknownVal()) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext &AC);
 
@@ -48,26 +46,58 @@ class ArrayBoundCheckerV2 :
   void checkLocation(SVal l, bool isLoad, const Stmt *S,
  CheckerContext &C) const;
 };
+} // anonymous namespace
 
-// FIXME: Eventually replace RegionRawOffset with this class.
-class RegionRawOffsetV2 {
-private:
-  const SubRegion *baseRegion;
-  NonLoc byteOffset;
+/// For a given Location that can be represented as a symbolic expression
+/// Arr[Idx] (or perhaps Arr[Idx1][Idx2] etc.), return the parent memory block
+/// Arr and the distance of Location from the beginning of Arr (expressed in a
+/// NonLoc that specifies the number of CharUnits). Returns nullopt when these
+/// cannot be determined.
+std::optional>
+computeOffset(ProgramStateRef State, SValBuilder &SVB, SVal Location) {
+  QualType T = SVB.getArrayIndexType();
+  auto Calc = [&SVB, State, T](BinaryOperatorKind Op, NonLoc LHS, NonLoc RHS) {
+// We will use this utility to add and multiply values.
+return SVB.evalBinOpNN(State, Op, LHS, RHS, T).getAs();
+  };
 
-public:
-  RegionRawOffsetV2(const SubRegion *base, NonLoc offset)
-  : baseRegion(base), byteOffset(offset) { assert(base); }
+  const auto *Region = Location.getAsRegion()->getAs();
+  std::optional Offset = std::nullopt;
+
+  while (const auto *ERegion = dyn_cast_or_null(Region)) {
+const auto Index = ERegion->getIndex().getAs();
+if (!Index)
+  return std::nullopt;
+
+QualType ElemType = ERegion->getElementType();
+// If the element is an incomplete type, go no further.
+if (ElemType->isIncompleteType())
+  return std::nullopt;
+
+// Calculate Delta = Index * sizeof(ElemType).
+NonLoc Size = SVB.makeArrayIndex(
+SVB.getContext().getTypeSizeInChars(ElemType).getQuantity());
+auto Delta = Calc(BO_Mul, *Index, Size);
+if (!Delta)
+  return std::nullopt;
+
+// Perform Offset += Delta, handling the initial nullopt as 0.
+if (!Offset) {
+  Offset = Delta;
+} else {
+  Offset = Calc(BO_Add, *Offset, *Delta);
+  if (!Offset)
+return std::nullopt;
+}
 
- 

[clang] [mlir][arith] Fix canon pattern for large ints in chained arith (PR #68900)

2023-10-13 Thread Rik Huijzer via cfe-commits

https://github.com/rikhuijzer updated 
https://github.com/llvm/llvm-project/pull/68900

>From ddbde18e483d12485ba25c715e8a94480b9d6dcf Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Thu, 12 Oct 2023 16:55:22 +0200
Subject: [PATCH 1/4] [mlir][arith] Fix canon pattern for large ints in chained
 arith

---
 mlir/lib/Dialect/Arith/IR/ArithOps.cpp| 25 +++
 mlir/test/Dialect/Arith/canonicalize.mlir | 10 +
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp 
b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 0ecc288f3b07701..25578b1c52f331b 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -39,26 +39,35 @@ using namespace mlir::arith;
 static IntegerAttr
 applyToIntegerAttrs(PatternRewriter &builder, Value res, Attribute lhs,
 Attribute rhs,
-function_ref binFn) {
-  return builder.getIntegerAttr(res.getType(),
-binFn(llvm::cast(lhs).getInt(),
-  llvm::cast(rhs).getInt()));
+function_ref binFn) {
+  auto lhsVal = llvm::cast(lhs).getValue();
+  auto rhsVal = llvm::cast(rhs).getValue();
+  auto value = binFn(lhsVal, rhsVal);
+  return IntegerAttr::get(res.getType(), value);
 }
 
 static IntegerAttr addIntegerAttrs(PatternRewriter &builder, Value res,
Attribute lhs, Attribute rhs) {
-  return applyToIntegerAttrs(builder, res, lhs, rhs, std::plus());
+  auto binFn = [](APInt a, APInt& b) -> APInt {
+return std::move(a) + b;
+  };
+  return applyToIntegerAttrs(builder, res, lhs, rhs, binFn);
 }
 
 static IntegerAttr subIntegerAttrs(PatternRewriter &builder, Value res,
Attribute lhs, Attribute rhs) {
-  return applyToIntegerAttrs(builder, res, lhs, rhs, std::minus());
+  auto binFn = [](APInt a, APInt& b) -> APInt {
+return std::move(a) - b;
+  };
+  return applyToIntegerAttrs(builder, res, lhs, rhs, binFn);
 }
 
 static IntegerAttr mulIntegerAttrs(PatternRewriter &builder, Value res,
Attribute lhs, Attribute rhs) {
-  return applyToIntegerAttrs(builder, res, lhs, rhs,
- std::multiplies());
+  auto binFn = [](APInt a, APInt& b) -> APInt {
+return std::move(a) * b;
+  };
+  return applyToIntegerAttrs(builder, res, lhs, rhs, binFn);
 }
 
 /// Invert an integer comparison predicate.
diff --git a/mlir/test/Dialect/Arith/canonicalize.mlir 
b/mlir/test/Dialect/Arith/canonicalize.mlir
index 1b0547c9e8f804a..b18f5cfcb3f9a12 100644
--- a/mlir/test/Dialect/Arith/canonicalize.mlir
+++ b/mlir/test/Dialect/Arith/canonicalize.mlir
@@ -985,6 +985,16 @@ func.func @tripleMulIMulII32(%arg0: i32) -> i32 {
   return %mul2 : i32
 }
 
+// CHECK-LABEL: @tripleMulLargeInt
+//   CHECK:   return
+func.func @tripleMulLargeInt(%arg0: i256) -> i256 {
+  %0 = arith.constant 
3618502788666131213697322783095070105623107215331596699973092056135872020481 : 
i256
+  %c5 = arith.constant 5 : i256
+  %mul1 = arith.muli %arg0, %0 : i256
+  %mul2 = arith.muli %mul1, %c5 : i256
+  return %mul2 : i256
+}
+
 // CHECK-LABEL: @addiMuliToSubiRhsI32
 //  CHECK-SAME:   (%[[ARG0:.+]]: i32, %[[ARG1:.+]]: i32)
 //   CHECK:   %[[SUB:.+]] = arith.subi %[[ARG0]], %[[ARG1]] : i32

>From c0f3efe78fa6e71d1acc4d38f526ca2ec194ddf8 Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Fri, 13 Oct 2023 10:14:16 +0200
Subject: [PATCH 2/4] Apply suggestions from code review
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Markus Böck 
---
 mlir/lib/Dialect/Arith/IR/ArithOps.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp 
b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 25578b1c52f331b..b749af256e7 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -39,7 +39,7 @@ using namespace mlir::arith;
 static IntegerAttr
 applyToIntegerAttrs(PatternRewriter &builder, Value res, Attribute lhs,
 Attribute rhs,
-function_ref binFn) {
+function_ref binFn) {
   auto lhsVal = llvm::cast(lhs).getValue();
   auto rhsVal = llvm::cast(rhs).getValue();
   auto value = binFn(lhsVal, rhsVal);
@@ -49,7 +49,7 @@ applyToIntegerAttrs(PatternRewriter &builder, Value res, 
Attribute lhs,
 static IntegerAttr addIntegerAttrs(PatternRewriter &builder, Value res,
Attribute lhs, Attribute rhs) {
   auto binFn = [](APInt a, APInt& b) -> APInt {
-return std::move(a) + b;
+return a + b;
   };
   return applyToIntegerAttrs(builder, res, lhs, rhs, binFn);
 }

>From 30e1ce11d567452dcd7481e999109d1f25164065 Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Fri, 13 Oct 2023 10:49:20 +0200
Subject: [PATCH 3/4] Use `const`s and check result o

[clang] [mlir][arith] Fix canon pattern for large ints in chained arith (PR #68900)

2023-10-13 Thread Rik Huijzer via cfe-commits


@@ -39,26 +39,29 @@ using namespace mlir::arith;
 static IntegerAttr
 applyToIntegerAttrs(PatternRewriter &builder, Value res, Attribute lhs,
 Attribute rhs,
-function_ref binFn) {
-  return builder.getIntegerAttr(res.getType(),
-binFn(llvm::cast(lhs).getInt(),
-  llvm::cast(rhs).getInt()));
+function_ref binFn) {
+  APInt lhsVal = llvm::cast(lhs).getValue();
+  APInt rhsVal = llvm::cast(rhs).getValue();
+  APInt value = binFn(lhsVal, rhsVal);
+  return IntegerAttr::get(res.getType(), value);
 }
 
 static IntegerAttr addIntegerAttrs(PatternRewriter &builder, Value res,
Attribute lhs, Attribute rhs) {
-  return applyToIntegerAttrs(builder, res, lhs, rhs, std::plus());
+  auto binFn = [](const APInt &a, const APInt &b) -> APInt { return a + b; };
+  return applyToIntegerAttrs(builder, res, lhs, rhs, binFn);

rikhuijzer wrote:

Well spotted 👍 

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


[clang] 2e955c0 - Revert "[Sema] Add check for bitfield assignments to integral types" (#68963)

2023-10-13 Thread via cfe-commits

Author: vabridgers
Date: 2023-10-13T05:03:38-05:00
New Revision: 2e955c0504d4cc529e33e0342b60183170b5c815

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

LOG: Revert "[Sema] Add check for bitfield assignments to integral types" 
(#68963)

This reverts commit 47e36266e93de9c34ba3028951a58124864bb2b4.

This change broke some arm8/arm7 build bots because int and void * have
the same size.

Co-authored-by: einvbri 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp

Removed: 
clang/test/SemaCXX/bitfield-width.c



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 31969201a1cac8c..2d918967e7f0b02 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -185,9 +185,6 @@ New Compiler Flags
   the preprocessed text to the output. This can greatly reduce the size of the
   preprocessed output, which can be helpful when trying to reduce a test case.
 
-* ``-Wbitfield-conversion`` was added to detect assignments of integral
-  types to a bitfield that may change the value.
-
 Deprecated Compiler Flags
 -
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 674eb9f4ef2e73f..0b09c002191848a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -53,7 +53,6 @@ def SingleBitBitFieldConstantConversion :
 def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion",

[SingleBitBitFieldConstantConversion]>;
 def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">;
-def BitFieldConversion : DiagGroup<"bitfield-conversion">;
 def BitFieldWidth : DiagGroup<"bitfield-width">;
 def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">;
 def CompoundTokenSplitBySpace : DiagGroup<"compound-token-split-by-space">;
@@ -934,7 +933,6 @@ def Conversion : DiagGroup<"conversion",
 ConstantConversion,
 EnumConversion,
 BitFieldEnumConversion,
-BitFieldConversion,
 FloatConversion,
 Shorten64To32,
 IntConversion,

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ab7fe881976aad2..c1a6e3831127e56 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6171,9 +6171,6 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
-def warn_bitfield_too_small_for_integral_type : Warning<
-  "conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
-  InGroup, DefaultIgnore;
 def note_change_bitfield_sign : Note<
   "consider making the bitfield type %select{unsigned|signed}0">;
 

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index cd61459cfbb13d6..35b36db2049db09 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14298,18 +14298,6 @@ static bool AnalyzeBitFieldAssignment(Sema &S, 
FieldDecl *Bitfield, Expr *Init,
 S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
 << BitsNeeded << ED << WidthExpr->getSourceRange();
   }
-} else if (OriginalInit->getType()->isIntegralType(S.Context)) {
-  IntRange LikelySourceRange =
-  GetExprRange(S.Context, Init, S.isConstantEvaluatedContext(),
-   /*Approximate=*/true);
-
-  if (LikelySourceRange.Width > FieldWidth) {
-Expr *WidthExpr = Bitfield->getBitWidth();
-S.Diag(InitLoc, diag::warn_bitfield_too_small_for_integral_type)
-<< Bitfield << FieldWidth << OriginalInit->getType()
-<< LikelySourceRange.Width;
-S.Diag(WidthExpr->getExprLoc(), diag::note_declared_at);
-  }
 }
 
 return false;
@@ -15207,6 +15195,7 @@ static void CheckImplicitConversion(Sema &S, Expr *E, 
QualType T,
 
   if (LikelySourceRange.Width > TargetRange.Width) {
 // If the source is a constant, use a default-on diagnostic.
+// TODO: this should happen for bitfield stores, too.
 Expr::EvalResult Result;
 if (E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects,
  S.isConstantEvaluatedContext())) {

diff  --git a/clang/test/SemaCXX/bitfield-width.c 
b/clang/test/SemaCXX/bitfield-width

[clang] Revert "[Sema] Add check for bitfield assignments to integral types" (PR #68963)

2023-10-13 Thread via cfe-commits

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


[clang] Revert "[Sema] Add check for bitfield assignments to integral types" (PR #68963)

2023-10-13 Thread via cfe-commits

vabridgers wrote:

> Original PR - #68276 FYI you do not need to make a PR to revert a change that 
> breaks the build - especially your own

revert is merged, thanks for the advice. Best

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-13 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/68962

>From ccf33cafada526241a3fb1aca9c2d280444b589b Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 12 Oct 2023 22:30:30 +0200
Subject: [PATCH 1/2] [clang] Provide an SSE4.2 implementation of identifier
 token lexer

The _mm_cmpistri instruction can be used to quickly parse identifiers.

With this patch activated, clang pre-processes  1.8% faster, and
sqlite3.c amalgametion 1.5% faster, based on time measurements and
number of executed instructions as measured by valgrind.

The introduction of an extra helper function in the regular case has no
impact on performance, see


https://llvm-compile-time-tracker.com/compare.php?from=30240e428f0ec7d4a6d1b84f9f807ce12b46cfd1&to=12bcb016cde4579ca7b75397762098c03eb4f264&stat=instructions:u
---
 clang/lib/Lex/Lexer.cpp | 45 ++---
 1 file changed, 38 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index feed1b9ecd71a8d..f2d9eb3a8af4e3d 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -47,6 +47,10 @@
 #include 
 #include 
 
+#ifdef __SSE4_2__
+#include 
+#endif
+
 using namespace clang;
 
 
//===--===//
@@ -1847,19 +1851,46 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, 
uint32_t C,
   return true;
 }
 
+static const char *fastParseASCIIIdentifier(const char *CurPtr, const char* 
BufferEnd) {
+#ifdef __SSE4_2__
+  static constexpr char AsciiIdentifierRange[16] = {
+  '_', '_', 'A', 'Z', 'a', 'z', '0', '9',
+  };
+  constexpr ssize_t BytesPerRegister = 16;
+
+  while (LLVM_LIKELY(BufferEnd - CurPtr >= BytesPerRegister)) {
+__m128i AsciiIdentifierRangeV = _mm_loadu_si128((const __m128i 
*)AsciiIdentifierRange);
+
+  __m128i Cv = _mm_loadu_si128((const __m128i *)(CurPtr));
+  int Consumed =
+  _mm_cmpistri(AsciiIdentifierRangeV, Cv,
+   _SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES |
+   _SIDD_UBYTE_OPS | _SIDD_NEGATIVE_POLARITY);
+  CurPtr += Consumed;
+  if (Consumed == BytesPerRegister)
+continue;
+  return CurPtr;
+  }
+#else
+  (void)BufferEnd;
+#endif
+
+  unsigned char C = *CurPtr;
+  while (isAsciiIdentifierContinue(C))
+C = *++CurPtr;
+  return CurPtr;
+}
+
 bool Lexer::LexIdentifierContinue(Token &Result, const char *CurPtr) {
   // Match [_A-Za-z0-9]*, we have already matched an identifier start.
+
   while (true) {
-unsigned char C = *CurPtr;
-// Fast path.
-if (isAsciiIdentifierContinue(C)) {
-  ++CurPtr;
-  continue;
-}
+
+CurPtr = fastParseASCIIIdentifier(CurPtr, BufferEnd);
 
 unsigned Size;
 // Slow path: handle trigraph, unicode codepoints, UCNs.
-C = getCharAndSize(CurPtr, Size);
+unsigned char C = getCharAndSize(CurPtr, Size);
 if (isAsciiIdentifierContinue(C)) {
   CurPtr = ConsumeChar(CurPtr, Size, Result);
   continue;

>From 280c93ff5e04c0acf2162a63c12bae2ecf886c92 Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Fri, 13 Oct 2023 12:06:49 +0200
Subject: [PATCH 2/2] fixup! [clang] Provide an SSE4.2 implementation of
 identifier token lexer

---
 clang/lib/Lex/Lexer.cpp | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index f2d9eb3a8af4e3d..11cc57a7a237733 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -1851,25 +1851,27 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, 
uint32_t C,
   return true;
 }
 
-static const char *fastParseASCIIIdentifier(const char *CurPtr, const char* 
BufferEnd) {
+static const char *fastParseASCIIIdentifier(const char *CurPtr,
+const char *BufferEnd) {
 #ifdef __SSE4_2__
-  static constexpr char AsciiIdentifierRange[16] = {
+  alignas(16) static constexpr char AsciiIdentifierRange[16] = {
   '_', '_', 'A', 'Z', 'a', 'z', '0', '9',
   };
   constexpr ssize_t BytesPerRegister = 16;
 
+  __m128i AsciiIdentifierRangeV =
+  _mm_load_si128((const __m128i *)AsciiIdentifierRange);
+
   while (LLVM_LIKELY(BufferEnd - CurPtr >= BytesPerRegister)) {
-__m128i AsciiIdentifierRangeV = _mm_loadu_si128((const __m128i 
*)AsciiIdentifierRange);
-
-  __m128i Cv = _mm_loadu_si128((const __m128i *)(CurPtr));
-  int Consumed =
-  _mm_cmpistri(AsciiIdentifierRangeV, Cv,
-   _SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES |
-   _SIDD_UBYTE_OPS | _SIDD_NEGATIVE_POLARITY);
-  CurPtr += Consumed;
-  if (Consumed == BytesPerRegister)
-continue;
-  return CurPtr;
+__m128i Cv = _mm_loadu_si128((const __m128i *)(CurPtr));
+
+int Consumed = _mm_cmpistri(AsciiIdentifierRangeV, Cv,
+_SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES |
+ 

[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-13 Thread via cfe-commits


@@ -1847,19 +1851,46 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, 
uint32_t C,
   return true;
 }
 
+static const char *fastParseASCIIIdentifier(const char *CurPtr, const char* 
BufferEnd) {
+#ifdef __SSE4_2__
+  static constexpr char AsciiIdentifierRange[16] = {
+  '_', '_', 'A', 'Z', 'a', 'z', '0', '9',
+  };
+  constexpr ssize_t BytesPerRegister = 16;
+
+  while (LLVM_LIKELY(BufferEnd - CurPtr >= BytesPerRegister)) {
+__m128i AsciiIdentifierRangeV = _mm_loadu_si128((const __m128i 
*)AsciiIdentifierRange);

serge-sans-paille wrote:

LICM + alignment done!

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-13 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/68962

>From ccf33cafada526241a3fb1aca9c2d280444b589b Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 12 Oct 2023 22:30:30 +0200
Subject: [PATCH 1/3] [clang] Provide an SSE4.2 implementation of identifier
 token lexer

The _mm_cmpistri instruction can be used to quickly parse identifiers.

With this patch activated, clang pre-processes  1.8% faster, and
sqlite3.c amalgametion 1.5% faster, based on time measurements and
number of executed instructions as measured by valgrind.

The introduction of an extra helper function in the regular case has no
impact on performance, see


https://llvm-compile-time-tracker.com/compare.php?from=30240e428f0ec7d4a6d1b84f9f807ce12b46cfd1&to=12bcb016cde4579ca7b75397762098c03eb4f264&stat=instructions:u
---
 clang/lib/Lex/Lexer.cpp | 45 ++---
 1 file changed, 38 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index feed1b9ecd71a8d..f2d9eb3a8af4e3d 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -47,6 +47,10 @@
 #include 
 #include 
 
+#ifdef __SSE4_2__
+#include 
+#endif
+
 using namespace clang;
 
 
//===--===//
@@ -1847,19 +1851,46 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, 
uint32_t C,
   return true;
 }
 
+static const char *fastParseASCIIIdentifier(const char *CurPtr, const char* 
BufferEnd) {
+#ifdef __SSE4_2__
+  static constexpr char AsciiIdentifierRange[16] = {
+  '_', '_', 'A', 'Z', 'a', 'z', '0', '9',
+  };
+  constexpr ssize_t BytesPerRegister = 16;
+
+  while (LLVM_LIKELY(BufferEnd - CurPtr >= BytesPerRegister)) {
+__m128i AsciiIdentifierRangeV = _mm_loadu_si128((const __m128i 
*)AsciiIdentifierRange);
+
+  __m128i Cv = _mm_loadu_si128((const __m128i *)(CurPtr));
+  int Consumed =
+  _mm_cmpistri(AsciiIdentifierRangeV, Cv,
+   _SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES |
+   _SIDD_UBYTE_OPS | _SIDD_NEGATIVE_POLARITY);
+  CurPtr += Consumed;
+  if (Consumed == BytesPerRegister)
+continue;
+  return CurPtr;
+  }
+#else
+  (void)BufferEnd;
+#endif
+
+  unsigned char C = *CurPtr;
+  while (isAsciiIdentifierContinue(C))
+C = *++CurPtr;
+  return CurPtr;
+}
+
 bool Lexer::LexIdentifierContinue(Token &Result, const char *CurPtr) {
   // Match [_A-Za-z0-9]*, we have already matched an identifier start.
+
   while (true) {
-unsigned char C = *CurPtr;
-// Fast path.
-if (isAsciiIdentifierContinue(C)) {
-  ++CurPtr;
-  continue;
-}
+
+CurPtr = fastParseASCIIIdentifier(CurPtr, BufferEnd);
 
 unsigned Size;
 // Slow path: handle trigraph, unicode codepoints, UCNs.
-C = getCharAndSize(CurPtr, Size);
+unsigned char C = getCharAndSize(CurPtr, Size);
 if (isAsciiIdentifierContinue(C)) {
   CurPtr = ConsumeChar(CurPtr, Size, Result);
   continue;

>From 280c93ff5e04c0acf2162a63c12bae2ecf886c92 Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Fri, 13 Oct 2023 12:06:49 +0200
Subject: [PATCH 2/3] fixup! [clang] Provide an SSE4.2 implementation of
 identifier token lexer

---
 clang/lib/Lex/Lexer.cpp | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index f2d9eb3a8af4e3d..11cc57a7a237733 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -1851,25 +1851,27 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, 
uint32_t C,
   return true;
 }
 
-static const char *fastParseASCIIIdentifier(const char *CurPtr, const char* 
BufferEnd) {
+static const char *fastParseASCIIIdentifier(const char *CurPtr,
+const char *BufferEnd) {
 #ifdef __SSE4_2__
-  static constexpr char AsciiIdentifierRange[16] = {
+  alignas(16) static constexpr char AsciiIdentifierRange[16] = {
   '_', '_', 'A', 'Z', 'a', 'z', '0', '9',
   };
   constexpr ssize_t BytesPerRegister = 16;
 
+  __m128i AsciiIdentifierRangeV =
+  _mm_load_si128((const __m128i *)AsciiIdentifierRange);
+
   while (LLVM_LIKELY(BufferEnd - CurPtr >= BytesPerRegister)) {
-__m128i AsciiIdentifierRangeV = _mm_loadu_si128((const __m128i 
*)AsciiIdentifierRange);
-
-  __m128i Cv = _mm_loadu_si128((const __m128i *)(CurPtr));
-  int Consumed =
-  _mm_cmpistri(AsciiIdentifierRangeV, Cv,
-   _SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES |
-   _SIDD_UBYTE_OPS | _SIDD_NEGATIVE_POLARITY);
-  CurPtr += Consumed;
-  if (Consumed == BytesPerRegister)
-continue;
-  return CurPtr;
+__m128i Cv = _mm_loadu_si128((const __m128i *)(CurPtr));
+
+int Consumed = _mm_cmpistri(AsciiIdentifierRangeV, Cv,
+_SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES |
+ 

[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-13 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/68922

>From 0c71b6bdd557ff4b9ad9a4ec4f0919e3460596b0 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 12 Oct 2023 21:35:52 +0200
Subject: [PATCH 1/3] Find opertor!= in the correct namespace

---
 clang/lib/Sema/SemaOverload.cpp   |  7 +-
 .../over.match.oper/p3-2a.cpp | 24 +++
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index ce78994e6553814..e1e0b4a888e49fa 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -960,12 +960,7 @@ static bool shouldAddReversedEqEq(Sema &S, SourceLocation 
OpLoc,
 return true;
   }
   // Otherwise the search scope is the namespace scope of which F is a member.
-  LookupResult NonMembers(S, NotEqOp, OpLoc,
-  Sema::LookupNameKind::LookupOperatorName);
-  S.LookupName(NonMembers,
-   S.getScopeForContext(EqFD->getEnclosingNamespaceContext()));
-  NonMembers.suppressAccessDiagnostics();
-  for (NamedDecl *Op : NonMembers) {
+  for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
 auto *FD = Op->getAsFunction();
 if(auto* UD = dyn_cast(Op))
   FD = UD->getUnderlyingDecl()->getAsFunction();
diff --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index 5c6804eb7726b5f..7142ed22ddb22ca 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -324,6 +324,30 @@ bool x = X() == X(); // expected-warning {{ambiguous}}
 }
 } // namespace P2468R2
 
+namespace ADL_GH68901{
+namespace A {
+struct S {};
+bool operator==(S, int); // expected-note {{no known conversion from 'int' to 
'S' for 1st argument}}
+bool operator!=(S, int);
+} // namespace A
+bool a = 0 == A::S(); // expected-error {{invalid operands to binary 
expression ('int' and 'A::S')}}
+
+namespace B {
+struct Derived {};
+struct Base : Derived {};
+
+bool operator==(Derived& a, Base& b);
+bool operator!=(Derived& a, Base& b);
+}  // namespace B
+
+void foo() {
+  // B::Base{} == B::Base{};
+  B::Base a,b;
+  bool v = a == b;
+}
+} //namespace ADL_GH68901
+
+
 #else // NO_ERRORS
 
 namespace problem_cases {

>From eb7ac047b269d71e4fc7afbbb8b8f65e857ff3a3 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 12 Oct 2023 21:48:20 +0200
Subject: [PATCH 2/3] Add release notes

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..c5b5f665ce9834c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -64,6 +64,10 @@ C/C++ Language Potentially Breaking Changes
 ``__has_c_attribute(warn_unused_result)``,  202003, 0
 ``__has_c_attribute(gnu::warn_unused_result)``, 202003, 1
 
+- Fixed a bug in finding matching `operator!=` while adding reveresed 
`operator==` as
+  outlined in "The Equality Operator You Are Looking For" (`P2468 
`_).
+  Fixes (`#68901: `_).
+
 C++ Specific Potentially Breaking Changes
 -
 - The name mangling rules for function templates has been changed to take into

>From 73d48e546775290196c5a5fbe2922d26df29f013 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Fri, 13 Oct 2023 12:28:29 +0200
Subject: [PATCH 3/3] fix a typo

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c5b5f665ce9834c..88cbf1d864da400 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -64,7 +64,7 @@ C/C++ Language Potentially Breaking Changes
 ``__has_c_attribute(warn_unused_result)``,  202003, 0
 ``__has_c_attribute(gnu::warn_unused_result)``, 202003, 1
 
-- Fixed a bug in finding matching `operator!=` while adding reveresed 
`operator==` as
+- Fixed a bug in finding matching `operator!=` while adding reversed 
`operator==` as
   outlined in "The Equality Operator You Are Looking For" (`P2468 
`_).
   Fixes (`#68901: `_).
 

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


[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-13 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

> Does this work for function-scope operator declarations?

@zygoloid I am not sure I follow. Could you please give an example. If this is 
about member operator, the search scope is class scope of the first operand.

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


[clang-tools-extra] [MLIR][Presburger] Implement matrix inverse (PR #67382)

2023-10-13 Thread Arjun P via cfe-commits


@@ -241,6 +245,32 @@ class IntMatrix : public Matrix
   /// Returns the GCD of the columns of the specified row.
   MPInt normalizeRow(unsigned row);
 
+  // Return the integer inverse of the matrix, leaving the calling object
+  // unmodified.
+  std::optional integerInverse();
+};
+
+// An inherited class for rational matrices, with no new data attributes.
+// This class is for functionality that only applies to matrices of fractions.
+class FracMatrix : public Matrix {
+public:
+  FracMatrix(unsigned rows, unsigned columns, unsigned reservedRows = 0,
+ unsigned reservedColumns = 0)
+  : Matrix(rows, columns, reservedRows, reservedColumns){};
+
+  FracMatrix(Matrix m)
+  : Matrix(m.getNumRows(), m.getNumColumns(),
+ m.getNumReservedRows(), m.getNumReservedColumns()) {
+for (unsigned i = 0; i < m.getNumRows(); i++)
+  for (unsigned j = 0; j < m.getNumColumns(); j++)
+at(i, j) = m(i, j);

Superty wrote:

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


[clang] [MLIR][Presburger] Implement matrix inverse (PR #67382)

2023-10-13 Thread Arjun P via cfe-commits


@@ -390,4 +463,83 @@ MPInt IntMatrix::normalizeRow(unsigned row, unsigned cols) 
{
 
 MPInt IntMatrix::normalizeRow(unsigned row) {
   return normalizeRow(row, getNumColumns());
+}
+
+std::optional IntMatrix::integerInverse() {
+  Fraction det = Fraction(determinant(), 1);
+  FracMatrix newMat(getNumRows(), getNumColumns());
+  for (unsigned i = 0; i < getNumRows(); i++)
+for (unsigned j = 0; j < getNumColumns(); j++)
+  newMat(i, j) = Fraction(at(i, j), 1);
+
+  std::optional fracInverse = newMat.inverse();
+
+  if (!fracInverse)
+return {};
+
+  IntMatrix intInverse(getNumRows(), getNumColumns());
+  for (unsigned i = 0; i < getNumRows(); i++)
+for (unsigned j = 0; j < getNumColumns(); j++)
+  intInverse(i, j) = ((*fracInverse)(i, j) * det).getAsInteger();
+
+  return intInverse;
+}
+
+FracMatrix FracMatrix::identity(unsigned dimension) {
+  return Matrix::identity(dimension);
+}
+
+std::optional FracMatrix::inverse() {
+  // We use Gaussian elimination on the rows of [M | I]
+  // to find the integer inverse. We proceed left-to-right,
+  // top-to-bottom. M is assumed to be a dim x dim matrix.
+
+  unsigned dim = getNumRows();
+
+  // Construct the augmented matrix [M | I]
+  FracMatrix augmented(dim, dim + dim);
+  for (unsigned i = 0; i < dim; i++) {
+augmented.fillRow(i, 0);
+for (unsigned j = 0; j < dim; j++)
+  augmented(i, j) = at(i, j);
+augmented(i, dim + i).num = 1;
+augmented(i, dim + i).den = 1;
+  }
+  Fraction a, b;
+  for (unsigned i = 0; i < dim; i++) {
+if (augmented(i, i) == Fraction(0, 1))
+  for (unsigned j = i + 1; j < dim; j++)
+if (augmented(j, i) != Fraction(0, 1)) {
+  augmented.addToRow(i, augmented.getRow(j), Fraction(1, 1));

Superty wrote:

there should be an `addRows` or something to do this directly

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


[clang-tools-extra] [MLIR][Presburger] Implement matrix inverse (PR #67382)

2023-10-13 Thread Arjun P via cfe-commits


@@ -283,12 +326,43 @@ template  bool 
Matrix::hasConsistentState() const {
   return true;
 }
 
+template 
+T Matrix::determinant() {
+  unsigned r = getNumRows();
+  unsigned c = getNumColumns();
+  if (r == 1)
+return at(0, 0);
+  if (r == 2)
+return (at(0, 0) * at(1, 1) - at(0, 1) * at(1, 0));
+
+  T sign(-1), determinant(0);
+  Matrix cofactor(r - 1, c - 1);
+
+  // Cofactor matrix consists of all columns other than the
+  // current one, and all rows except the first.
+  for (unsigned i = 0; i < c; i++) {
+sign = -sign;
+unsigned n = 0;
+for (unsigned j = 0; j < c; j++) {
+  if (j == i)
+continue;
+  for (unsigned k = 0; k < r - 1; k++)
+cofactor(k, n) = at(k + 1, j);
+  n++;
+}
+
+determinant = determinant + at(0, i) * sign * cofactor.determinant();

Superty wrote:

please don't use this exponential recursive implementation. it's going to be 
pretty slow and unbounded recursion is does not conform to LLVM standards.  do 
you need it for both integers and fractions? try to use the gaussian 
elimination for this.

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


[clang] [MLIR][Presburger] Implement matrix inverse (PR #67382)

2023-10-13 Thread Arjun P via cfe-commits

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


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


[clang-tools-extra] [MLIR][Presburger] Implement matrix inverse (PR #67382)

2023-10-13 Thread Arjun P via cfe-commits


@@ -390,4 +463,83 @@ MPInt IntMatrix::normalizeRow(unsigned row, unsigned cols) 
{
 
 MPInt IntMatrix::normalizeRow(unsigned row) {
   return normalizeRow(row, getNumColumns());
+}
+
+std::optional IntMatrix::integerInverse() {
+  Fraction det = Fraction(determinant(), 1);
+  FracMatrix newMat(getNumRows(), getNumColumns());
+  for (unsigned i = 0; i < getNumRows(); i++)
+for (unsigned j = 0; j < getNumColumns(); j++)
+  newMat(i, j) = Fraction(at(i, j), 1);
+
+  std::optional fracInverse = newMat.inverse();
+
+  if (!fracInverse)
+return {};
+
+  IntMatrix intInverse(getNumRows(), getNumColumns());
+  for (unsigned i = 0; i < getNumRows(); i++)
+for (unsigned j = 0; j < getNumColumns(); j++)
+  intInverse(i, j) = ((*fracInverse)(i, j) * det).getAsInteger();
+
+  return intInverse;
+}
+
+FracMatrix FracMatrix::identity(unsigned dimension) {
+  return Matrix::identity(dimension);
+}
+
+std::optional FracMatrix::inverse() {
+  // We use Gaussian elimination on the rows of [M | I]
+  // to find the integer inverse. We proceed left-to-right,
+  // top-to-bottom. M is assumed to be a dim x dim matrix.
+
+  unsigned dim = getNumRows();
+
+  // Construct the augmented matrix [M | I]
+  FracMatrix augmented(dim, dim + dim);
+  for (unsigned i = 0; i < dim; i++) {
+augmented.fillRow(i, 0);
+for (unsigned j = 0; j < dim; j++)
+  augmented(i, j) = at(i, j);
+augmented(i, dim + i).num = 1;
+augmented(i, dim + i).den = 1;
+  }

Superty wrote:

I think it's cleaner to just maintain a copy of `this` and the inverse as 
separate matrices. You can just assign to 1 btw. and filling 0 should be by 
default, check the constructor doc.

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


[clang] [clang] Add information about lld presence in RISCVToolchain. (PR #68904)

2023-10-13 Thread Bushev Dmitry via cfe-commits

https://github.com/dybv-sc updated 
https://github.com/llvm/llvm-project/pull/68904

>From eca69cd54e9f2f68d89787376c603164c2508da1 Mon Sep 17 00:00:00 2001
From: Dmitry Bushev 
Date: Mon, 9 Oct 2023 19:49:09 +0300
Subject: [PATCH] [clang] Add information about lld presence in RISCVToolchain.

---
 .../lib/Driver/ToolChains/RISCVToolchain.cpp  |  4 ++-
 clang/lib/Driver/ToolChains/RISCVToolchain.h  |  3 +++
 clang/test/Driver/riscv64-toolchain.c | 25 +++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index c98f43f6e05eb4b..f235d704c116744 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -49,7 +49,9 @@ bool RISCVToolChain::hasGCCToolchain(const Driver &D,
 /// RISC-V Toolchain
 RISCVToolChain::RISCVToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
-: Generic_ELF(D, Triple, Args) {
+: Generic_ELF(D, Triple, Args), 
+  UseLLD{Args.getLastArgValue(options::OPT_fuse_ld_EQ)
+ .equals_insensitive("lld")} {
   GCCInstallation.init(Triple, Args);
   if (GCCInstallation.isValid()) {
 Multilibs = GCCInstallation.getMultilibs();
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h 
b/clang/lib/Driver/ToolChains/RISCVToolchain.h
index de6960726f1cd77..afe98968ecd8616 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.h
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h
@@ -35,11 +35,14 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public 
Generic_ELF {
   addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
 
+  bool HasNativeLLVMSupport() const override { return UseLLD; }
+
 protected:
   Tool *buildLinker() const override;
 
 private:
   std::string computeSysRoot() const override;
+  bool UseLLD;
 };
 
 } // end namespace toolchains
diff --git a/clang/test/Driver/riscv64-toolchain.c 
b/clang/test/Driver/riscv64-toolchain.c
index f177bff33dd4d72..275cd8dde419218 100644
--- a/clang/test/Driver/riscv64-toolchain.c
+++ b/clang/test/Driver/riscv64-toolchain.c
@@ -121,6 +121,31 @@
 // C-RV64IMAC-BAREMETAL-MULTI-LP64: "--start-group" "-lc" "-lgloss" 
"--end-group" "-lgcc"
 // C-RV64IMAC-BAREMETAL-MULTI-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imac/lp64/crtend.o"
 
+// Check that lto works in riscv-toolchain when explicitly specified lld as 
linker.
+// RUN: env "PATH=" %clang -### %s -fuse-ld=lld -flto \
+// RUN:   --target=riscv64-unknown-elf --rtlib=platform --sysroot= \
+// RUN:   -march=rv64imac -mabi=lp64\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck -check-prefix=C-RV64IMAC-BAREMETAL-LTO-LP64 %s
+
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "{{.*}}lld"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "-m" "elf64lriscv"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/../../..{{/|}}..{{/|}}riscv64-unknown-elf/lib/crt0.o"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtbegin.o"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/../../..{{/|}}..{{/|}}riscv64-unknown-elf/lib"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "--start-group" "-lc" "-lgloss" 
"--end-group" "-lgcc"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtend.o"
+
+// Check driver error when lto is used without specified lld linker.
+// RUN: env "PATH=" %clang -### %s -flto \
+// RUN:   --target=riscv64-unknown-elf --rtlib=platform --sysroot= \
+// RUN:   -march=rv64imac -mabi=lp64\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck -check-prefix=C-RV64IMAC-BAREMETAL-LTO-FAIL-LP64 %s
+
+// C-RV64IMAC-BAREMETAL-LTO-FAIL-LP64: clang-16: error: 
'riscv64-unknown-unknown-elf': unable to pass LLVM bit-code files to linker
+
 // RUN: env "PATH=" %clang -### %s -fuse-ld=ld \
 // RUN:   --target=riscv64-unknown-elf --rtlib=platform --unwindlib=platform 
--sysroot= \
 // RUN:   -march=rv64imafdc -mabi=lp64d \

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


[clang-tools-extra] [MLIR][Presburger] Implement matrix inverse (PR #67382)

2023-10-13 Thread Arjun P via cfe-commits


@@ -390,4 +463,83 @@ MPInt IntMatrix::normalizeRow(unsigned row, unsigned cols) 
{
 
 MPInt IntMatrix::normalizeRow(unsigned row) {
   return normalizeRow(row, getNumColumns());
+}
+
+std::optional IntMatrix::integerInverse() {
+  Fraction det = Fraction(determinant(), 1);
+  FracMatrix newMat(getNumRows(), getNumColumns());
+  for (unsigned i = 0; i < getNumRows(); i++)
+for (unsigned j = 0; j < getNumColumns(); j++)
+  newMat(i, j) = Fraction(at(i, j), 1);
+
+  std::optional fracInverse = newMat.inverse();
+
+  if (!fracInverse)
+return {};
+
+  IntMatrix intInverse(getNumRows(), getNumColumns());
+  for (unsigned i = 0; i < getNumRows(); i++)
+for (unsigned j = 0; j < getNumColumns(); j++)
+  intInverse(i, j) = ((*fracInverse)(i, j) * det).getAsInteger();
+
+  return intInverse;
+}
+
+FracMatrix FracMatrix::identity(unsigned dimension) {
+  return Matrix::identity(dimension);
+}
+
+std::optional FracMatrix::inverse() {
+  // We use Gaussian elimination on the rows of [M | I]
+  // to find the integer inverse. We proceed left-to-right,
+  // top-to-bottom. M is assumed to be a dim x dim matrix.
+
+  unsigned dim = getNumRows();
+
+  // Construct the augmented matrix [M | I]
+  FracMatrix augmented(dim, dim + dim);
+  for (unsigned i = 0; i < dim; i++) {
+augmented.fillRow(i, 0);
+for (unsigned j = 0; j < dim; j++)
+  augmented(i, j) = at(i, j);
+augmented(i, dim + i).num = 1;
+augmented(i, dim + i).den = 1;
+  }
+  Fraction a, b;
+  for (unsigned i = 0; i < dim; i++) {
+if (augmented(i, i) == Fraction(0, 1))
+  for (unsigned j = i + 1; j < dim; j++)
+if (augmented(j, i) != Fraction(0, 1)) {

Superty wrote:

doesn't fraction have comparisons to int defined?

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


[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-10-13 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

> looks good - a few bits should be committed separately from this change, so 
> please do those first and then commit this change

Separate review opened up at: https://github.com/llvm/llvm-project/pull/68967

For simplicity's sake I'll keep this patch as-is, and rebase it when the other 
patch lands.

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


[clang] [clang] Add information about lld presence in RISCVToolchain. (PR #68904)

2023-10-13 Thread Bushev Dmitry via cfe-commits

https://github.com/dybv-sc updated 
https://github.com/llvm/llvm-project/pull/68904

>From 087d22970d1d2eea6dd0dd79eedd49ed69bc49c3 Mon Sep 17 00:00:00 2001
From: Dmitry Bushev 
Date: Mon, 9 Oct 2023 19:49:09 +0300
Subject: [PATCH] [clang] Add information about lld presence in RISCVToolchain.

---
 .../lib/Driver/ToolChains/RISCVToolchain.cpp  |  4 ++-
 clang/lib/Driver/ToolChains/RISCVToolchain.h  |  3 +++
 clang/test/Driver/riscv64-toolchain.c | 25 +++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index c98f43f6e05eb4b..3a784be8e06616f 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -49,7 +49,9 @@ bool RISCVToolChain::hasGCCToolchain(const Driver &D,
 /// RISC-V Toolchain
 RISCVToolChain::RISCVToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
-: Generic_ELF(D, Triple, Args) {
+: Generic_ELF(D, Triple, Args), UseLLD{Args.getLastArgValue(
+   options::OPT_fuse_ld_EQ)
+   .equals_insensitive("lld")} {
   GCCInstallation.init(Triple, Args);
   if (GCCInstallation.isValid()) {
 Multilibs = GCCInstallation.getMultilibs();
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h 
b/clang/lib/Driver/ToolChains/RISCVToolchain.h
index de6960726f1cd77..afe98968ecd8616 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.h
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h
@@ -35,11 +35,14 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public 
Generic_ELF {
   addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
 
+  bool HasNativeLLVMSupport() const override { return UseLLD; }
+
 protected:
   Tool *buildLinker() const override;
 
 private:
   std::string computeSysRoot() const override;
+  bool UseLLD;
 };
 
 } // end namespace toolchains
diff --git a/clang/test/Driver/riscv64-toolchain.c 
b/clang/test/Driver/riscv64-toolchain.c
index f177bff33dd4d72..275cd8dde419218 100644
--- a/clang/test/Driver/riscv64-toolchain.c
+++ b/clang/test/Driver/riscv64-toolchain.c
@@ -121,6 +121,31 @@
 // C-RV64IMAC-BAREMETAL-MULTI-LP64: "--start-group" "-lc" "-lgloss" 
"--end-group" "-lgcc"
 // C-RV64IMAC-BAREMETAL-MULTI-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imac/lp64/crtend.o"
 
+// Check that lto works in riscv-toolchain when explicitly specified lld as 
linker.
+// RUN: env "PATH=" %clang -### %s -fuse-ld=lld -flto \
+// RUN:   --target=riscv64-unknown-elf --rtlib=platform --sysroot= \
+// RUN:   -march=rv64imac -mabi=lp64\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck -check-prefix=C-RV64IMAC-BAREMETAL-LTO-LP64 %s
+
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "{{.*}}lld"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "-m" "elf64lriscv"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/../../..{{/|}}..{{/|}}riscv64-unknown-elf/lib/crt0.o"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtbegin.o"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/../../..{{/|}}..{{/|}}riscv64-unknown-elf/lib"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "--start-group" "-lc" "-lgloss" 
"--end-group" "-lgcc"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtend.o"
+
+// Check driver error when lto is used without specified lld linker.
+// RUN: env "PATH=" %clang -### %s -flto \
+// RUN:   --target=riscv64-unknown-elf --rtlib=platform --sysroot= \
+// RUN:   -march=rv64imac -mabi=lp64\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck -check-prefix=C-RV64IMAC-BAREMETAL-LTO-FAIL-LP64 %s
+
+// C-RV64IMAC-BAREMETAL-LTO-FAIL-LP64: clang-16: error: 
'riscv64-unknown-unknown-elf': unable to pass LLVM bit-code files to linker
+
 // RUN: env "PATH=" %clang -### %s -fuse-ld=ld \
 // RUN:   --target=riscv64-unknown-elf --rtlib=platform --unwindlib=platform 
--sysroot= \
 // RUN:   -march=rv64imafdc -mabi=lp64d \

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


[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)

2023-10-13 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> Actually no, that's not possible as config-ix modules are explicitly private 
> to their subproject and should not be used outside them. I'm going to revert 
> this change due to this layering violation.

@nikic, can you suggest a particular fix? We saw this approach was done 
elsewhere as well…

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


[clang] [clang-format][NFC] Annotate control statement r_braces (PR #68621)

2023-10-13 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks updated 
https://github.com/llvm/llvm-project/pull/68621

From a7425ee9846cd740cf491d23d7afa676767beb18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= 
Date: Mon, 9 Oct 2023 21:28:01 +0200
Subject: [PATCH] [clang-format][NFC] Annotate control statement r_braces

Annotating switch braces for the first time.

Extract the type setting into its own function.

Also in preparation of #67906.
---
 clang/lib/Format/FormatToken.h|  2 ++
 clang/lib/Format/UnwrappedLineParser.cpp  | 26 ++--
 clang/lib/Format/UnwrappedLineParser.h|  1 +
 clang/unittests/Format/TokenAnnotatorTest.cpp | 31 +++
 4 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 527f1d744a58089..606e9e790ad833b 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -52,6 +52,7 @@ namespace format {
   TYPE(ConflictStart)  
\
   /* l_brace of if/for/while */
\
   TYPE(ControlStatementLBrace) 
\
+  TYPE(ControlStatementRBrace) 
\
   TYPE(CppCastLParen)  
\
   TYPE(CSharpGenericTypeConstraint)
\
   TYPE(CSharpGenericTypeConstraintColon)   
\
@@ -67,6 +68,7 @@ namespace format {
   TYPE(DesignatedInitializerPeriod)
\
   TYPE(DictLiteral)
\
   TYPE(ElseLBrace) 
\
+  TYPE(ElseRBrace) 
\
   TYPE(EnumLBrace) 
\
   TYPE(EnumRBrace) 
\
   TYPE(FatArrow)   
\
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 3275d7b6a71aaa0..82a812fc8bcc610 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -640,6 +640,14 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   FormatTok = Tokens->setPosition(StoredPosition);
 }
 
+// Sets the token type of the directly previous right brace.
+void UnwrappedLineParser::setPreviousRBraceType(TokenType Type) {
+  if (auto Prev = FormatTok->getPreviousNonComment();
+  Prev && Prev->is(tok::r_brace)) {
+Prev->setFinalizedType(Type);
+  }
+}
+
 template 
 static inline void hash_combine(std::size_t &seed, const T &v) {
   std::hash hasher;
@@ -2756,6 +2764,7 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
 parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
/*MunchSemi=*/true, KeepIfBraces, &IfBlockKind);
+setPreviousRBraceType(TT_ControlStatementRBrace);
 if (Style.BraceWrapping.BeforeElse)
   addUnwrappedLine();
 else
@@ -2794,6 +2803,7 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
   FormatToken *IfLBrace =
   parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
  /*MunchSemi=*/true, KeepElseBraces, &ElseBlockKind);
+  setPreviousRBraceType(TT_ElseRBrace);
   if (FormatTok->is(tok::kw_else)) {
 KeepElseBraces = KeepElseBraces ||
  ElseBlockKind == IfStmtKind::IfOnly ||
@@ -3057,12 +3067,12 @@ void UnwrappedLineParser::parseLoopBody(bool 
KeepBraces, bool WrapRightBrace) {
   keepAncestorBraces();
 
   if (isBlockBegin(*FormatTok)) {
-if (!KeepBraces)
-  FormatTok->setFinalizedType(TT_ControlStatementLBrace);
+FormatTok->setFinalizedType(TT_ControlStatementLBrace);
 FormatToken *LeftBrace = FormatTok;
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
 parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
/*MunchSemi=*/true, KeepBraces);
+setPreviousRBraceType(TT_ControlStatementRBrace);
 if (!KeepBraces) {
   assert(!NestedTooDeep.empty());
   if (!NestedTooDeep.back())
@@ -3196,7 +3206,9 @@ void UnwrappedLineParser::parseSwitch() {
 
   if (FormatTok->is(tok::l_brace)) {
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
+FormatTok->setFinalizedType(TT_ControlStatementLBrace);
 parseBlock();
+setPreviousRBraceType(TT_ControlStatementRBrace);
 addUnwrappedLine();
   } else {
 addUnwrappedLine();
@@ -3713,10 +3725,7 @@ bool UnwrappedLineParser::parseEnum() {
   nextToken();
 addUnwrappedLine();
   }
- 

[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)

2023-10-13 Thread Vassil Vassilev via cfe-commits


@@ -213,6 +213,411 @@ concept helps support advanced use cases such as template 
instantiations on dema
 automatic language interoperability. It also helps static languages such as 
C/C++ become
 apt for data science.
 
+Execution Results Handling in Clang-Repl
+
+
+Execution Results Handling features discussed below help extend the Clang-Repl
+functionality by creating an interface between the execution results of a
+program and the compiled program.
+
+1. **Capture Execution Results**: This feature helps capture the execution 
results
+of a program and bring them back to the compiled program.
+
+2. **Dump Captured Execution Results**: This feature helps create a temporary 
dump
+for Value Printing/Automatic Printf, that is, to display the value and type of
+the captured data.
+
+
+1. Capture Execution Results
+
+
+In many cases, it is useful to bring back the program execution result to the
+compiled program. This result can be stored in an object of type **Value**.
+
+How Execution Results are captured (Value Synthesis):
+-
+
+The synthesizer chooses which expression to synthesize, and then it replaces
+the original expression with the synthesized expression. Depending on the
+expression type, it may choose to save an object (``LastValue``) of type 
'value'
+while allocating memory to it (``SetValueWithAlloc()``), or not (
+``SetValueNoAlloc()``).
+
+.. graphviz::
+:name: valuesynthesis
+:caption: Value Synthesis
+:alt: Shows how an object of type 'Value' is synthesized
+:align: center
+
+ digraph "valuesynthesis" {
+ rankdir="LR";
+ graph [fontname="Verdana", fontsize="12"];
+ node [fontname="Verdana", fontsize="12"];
+ edge [fontname="Sans", fontsize="9"];
+
+ start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", 
shape="note", fontcolor=white, fillcolor="#ff", style=filled];
+ assign [label=" Assign the result \n to the 'LastValue' \n (based on 
respective \n Memory Allocation \n scenario) ", shape="box"]
+ print [label=" Pretty Print \n the Value Object ", shape="Msquare", 
fillcolor="yellow", style=filled];
+ start -> assign;
+ assign -> print;
+
+   subgraph SynthesizeExpression {
+ synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, 
fillcolor="#ff", style=filled];
+ mem [label=" New Memory \n Allocation? ", shape="diamond"];
+ withaloc [label=" SetValueWithAlloc() ", shape="box"];
+ noaloc [label=" SetValueNoAlloc() ", shape="box"];
+ right [label=" 1. RValue Structure \n (a temporary value)", 
shape="box"];
+ left2 [label=" 2. LValue Structure \n (a variable with \n an 
address)", shape="box"];
+ left3 [label=" 3. Built-In Type \n (int, float, etc.)", 
shape="box"];
+ output [label=" move to 'Assign' step ", shape="box"];
+
+ synth -> mem;
+ mem -> withaloc [label="Yes"];
+ mem -> noaloc [label="No"];
+ withaloc -> right;
+ noaloc -> left2;
+ noaloc -> left3;
+ right -> output;
+ left2 -> output;
+ left3 -> output;
+  }
+output -> assign
+  }
+
+Where is the captured result stored?
+
+
+``LastValue`` holds the last result of the value printing. It is a class member
+because it can be accessed even after subsequent inputs.
+
+**Note:** If no value printing happens, then it is in an invalid state.
+
+Improving Efficiency and User Experience
+
+
+The Value object is essentially used to create a mapping between an expression
+'type' and the allocated 'memory'. Built-in types (bool, char, int,
+float, double, etc.) are copyable. Their memory allocation size is known
+and the Value object can introduce a small-buffer optimization.
+In case of objects, the ``Value`` class provides reference-counted memory
+management.
+
+The implementation maps the type as written and the Clang Type to be able to 
use
+the preprocessor to synthesize the relevant cast operations. For example,
+``X(char, Char_S)``, where ``char`` is the type from the language's type system
+and ``Char_S`` is the Clang builtin type which represents it. This mapping 
helps
+to import execution results from the interpreter in a compiled program and vice
+versa. The ``Value.h`` header file can be included at runtime and this is why 
it
+has a very low token count and was developed with strict constraints in mind.
+
+This also enables the user to receive the computed 'type' back in their code
+and then transform the type into something else (e.g., re-cast a double into
+a float). Normally, the compiler can handle these conversions transparently,
+but in interpreter mode, the c

[clang] [clang-format][NFC] Annotate control statement r_braces (PR #68621)

2023-10-13 Thread Björn Schäpers via cfe-commits


@@ -2756,6 +2756,10 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
 parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
/*MunchSemi=*/true, KeepIfBraces, &IfBlockKind);
+if (auto Prev = FormatTok->getPreviousNonComment();
+Prev && Prev->is(tok::r_brace)) {
+  Prev->setFinalizedType(TT_ControlStatementRBrace);
+}

HazardyKnusperkeks wrote:

Done.

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


[clang] [AMDGPU] Remove Code Object V3 (PR #67118)

2023-10-13 Thread Yaxun Liu via cfe-commits

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

LGTM. Thanks

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


[clang-tools-extra] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-13 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> (Was out of town...)
> 
> As mentioned at [#67360 
> (comment)](https://github.com/llvm/llvm-project/pull/67360#issuecomment-1736187374)
>  , I think a default error is probably not appropriate. A priority value <= 
> 100 may compete with a runtime `__attribute__((constructor(X)))` but more 
> often it will work. A warning is fine. GCC defaults to a warning and the 
> attribute form with a priority is an obscure feature anyway, therefore it 
> doesn't buy us much to make it an error. You can make `> 65535` an error, 
> though.

I disagree -- we decided ages ago with init_priority that using these reserved 
priorities should be an error that can be ignored for the few cases where the 
reservation does not apply. We should be designing the Ux for these features 
around the majority of users, not the majority of people who will use the 
feature. Otherwise, we should not pretend these are reserved values -- it's far 
too easy to ignore a warning IMO.

That said, I'm abandoning this work regardless. It was unplanned work I took on 
only because I noticed how deficient the implementation was regarding 
diagnostics when I went to add documentation for the attribute in the first 
place. A lot of our attributes from 2000-2012 or so are similarly problematic, 
unfortunately. So I wouldn't be surprised to see this come up again in the 
future.

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


[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-13 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> (Was out of town...)
> 
> As mentioned at [#67360 
> (comment)](https://github.com/llvm/llvm-project/pull/67360#issuecomment-1736187374)
>  , I think a default error is probably not appropriate. A priority value <= 
> 100 may compete with a runtime `__attribute__((constructor(X)))` but more 
> often it will work. A warning is fine. GCC defaults to a warning and the 
> attribute form with a priority is an obscure feature anyway, therefore it 
> doesn't buy us much to make it an error. You can make `> 65535` an error, 
> though.

I disagree -- we decided ages ago with init_priority that using these reserved 
priorities should be an error that can be ignored for the few cases where the 
reservation does not apply. We should be designing the Ux for these features 
around the majority of users, not the majority of people who will use the 
feature. Otherwise, we should not pretend these are reserved values -- it's far 
too easy to ignore a warning IMO.

That said, I'm abandoning this work regardless. It was unplanned work I took on 
only because I noticed how deficient the implementation was regarding 
diagnostics when I went to add documentation for the attribute in the first 
place. A lot of our attributes from 2000-2012 or so are similarly problematic, 
unfortunately. So I wouldn't be surprised to see this come up again in the 
future.

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


[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)

2023-10-13 Thread Aaron Ballman via cfe-commits


@@ -213,6 +213,411 @@ concept helps support advanced use cases such as template 
instantiations on dema
 automatic language interoperability. It also helps static languages such as 
C/C++ become
 apt for data science.
 
+Execution Results Handling in Clang-Repl
+
+
+Execution Results Handling features discussed below help extend the Clang-Repl
+functionality by creating an interface between the execution results of a
+program and the compiled program.
+
+1. **Capture Execution Results**: This feature helps capture the execution 
results
+of a program and bring them back to the compiled program.
+
+2. **Dump Captured Execution Results**: This feature helps create a temporary 
dump
+for Value Printing/Automatic Printf, that is, to display the value and type of
+the captured data.
+
+
+1. Capture Execution Results
+
+
+In many cases, it is useful to bring back the program execution result to the
+compiled program. This result can be stored in an object of type **Value**.
+
+How Execution Results are captured (Value Synthesis):
+-
+
+The synthesizer chooses which expression to synthesize, and then it replaces
+the original expression with the synthesized expression. Depending on the
+expression type, it may choose to save an object (``LastValue``) of type 
'value'
+while allocating memory to it (``SetValueWithAlloc()``), or not (
+``SetValueNoAlloc()``).
+
+.. graphviz::
+:name: valuesynthesis
+:caption: Value Synthesis
+:alt: Shows how an object of type 'Value' is synthesized
+:align: center
+
+ digraph "valuesynthesis" {
+ rankdir="LR";
+ graph [fontname="Verdana", fontsize="12"];
+ node [fontname="Verdana", fontsize="12"];
+ edge [fontname="Sans", fontsize="9"];
+
+ start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", 
shape="note", fontcolor=white, fillcolor="#ff", style=filled];
+ assign [label=" Assign the result \n to the 'LastValue' \n (based on 
respective \n Memory Allocation \n scenario) ", shape="box"]
+ print [label=" Pretty Print \n the Value Object ", shape="Msquare", 
fillcolor="yellow", style=filled];
+ start -> assign;
+ assign -> print;
+
+   subgraph SynthesizeExpression {
+ synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, 
fillcolor="#ff", style=filled];
+ mem [label=" New Memory \n Allocation? ", shape="diamond"];
+ withaloc [label=" SetValueWithAlloc() ", shape="box"];
+ noaloc [label=" SetValueNoAlloc() ", shape="box"];
+ right [label=" 1. RValue Structure \n (a temporary value)", 
shape="box"];
+ left2 [label=" 2. LValue Structure \n (a variable with \n an 
address)", shape="box"];
+ left3 [label=" 3. Built-In Type \n (int, float, etc.)", 
shape="box"];
+ output [label=" move to 'Assign' step ", shape="box"];
+
+ synth -> mem;
+ mem -> withaloc [label="Yes"];
+ mem -> noaloc [label="No"];
+ withaloc -> right;
+ noaloc -> left2;
+ noaloc -> left3;
+ right -> output;
+ left2 -> output;
+ left3 -> output;
+  }
+output -> assign
+  }
+
+Where is the captured result stored?
+
+
+``LastValue`` holds the last result of the value printing. It is a class member
+because it can be accessed even after subsequent inputs.
+
+**Note:** If no value printing happens, then it is in an invalid state.
+
+Improving Efficiency and User Experience
+
+
+The Value object is essentially used to create a mapping between an expression
+'type' and the allocated 'memory'. Built-in types (bool, char, int,
+float, double, etc.) are copyable. Their memory allocation size is known
+and the Value object can introduce a small-buffer optimization.
+In case of objects, the ``Value`` class provides reference-counted memory
+management.
+
+The implementation maps the type as written and the Clang Type to be able to 
use
+the preprocessor to synthesize the relevant cast operations. For example,
+``X(char, Char_S)``, where ``char`` is the type from the language's type system
+and ``Char_S`` is the Clang builtin type which represents it. This mapping 
helps
+to import execution results from the interpreter in a compiled program and vice
+versa. The ``Value.h`` header file can be included at runtime and this is why 
it
+has a very low token count and was developed with strict constraints in mind.
+
+This also enables the user to receive the computed 'type' back in their code
+and then transform the type into something else (e.g., re-cast a double into
+a float). Normally, the compiler can handle these conversions transparently,
+but in interpreter mode, the c

[clang] [ARM] fix "+fp.dp" in multilib selection (PR #67412)

2023-10-13 Thread Dominik Wójt via cfe-commits

https://github.com/domin144 updated 
https://github.com/llvm/llvm-project/pull/67412

From 4cc2328982cc8260263aa803f2b02bff7d7b4a85 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20W=C3=B3jt?= 
Date: Wed, 20 Sep 2023 16:39:27 +0200
Subject: [PATCH 1/2] [ARM] fix "+fp.dp" in multilib selection

When the FPU was selected with "+(no)fp(.dp)" extensions in "-march" or
"-mcpu" options, the FPU used for multilib selection was still the
default one for given architecture or CPU.
---
 clang/lib/Driver/ToolChains/Arch/ARM.cpp  |  5 ++
 .../test/Driver/print-multi-selection-flags.c | 10 +++
 .../llvm/TargetParser/ARMTargetParser.h   |  8 +++
 llvm/lib/TargetParser/ARMTargetParser.cpp | 69 +++
 4 files changed, 77 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index bb66db5feae8c3b..9a042d351bda0b6 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -626,6 +626,11 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
 if (!llvm::ARM::getFPUFeatures(FPUKind, Features))
   D.Diag(clang::diag::err_drv_clang_unsupported)
   << std::string("-mfpu=") + AndroidFPU;
+  } else if (ArchArgFPUKind != llvm::ARM::FK_INVALID ||
+ CPUArgFPUKind != llvm::ARM::FK_INVALID) {
+FPUKind =
+CPUArgFPUKind != llvm::ARM::FK_INVALID ? CPUArgFPUKind : 
ArchArgFPUKind;
+(void)llvm::ARM::getFPUFeatures(FPUKind, Features);
   } else {
 if (!ForAS) {
   std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
diff --git a/clang/test/Driver/print-multi-selection-flags.c 
b/clang/test/Driver/print-multi-selection-flags.c
index 819ff242ced0026..f020a22ea128aac 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -35,6 +35,16 @@
 // CHECK-MVENOFP-NOT: -march=thumbv8.1m.main{{.*}}+mve.fp{{.*}}
 // CHECK-MVENOFP: -mfpu=none
 
+// RUN: %clang -print-multi-flags-experimental --target=arm-none-eabihf 
-march=armv8.1m.main+fp.dp | FileCheck --check-prefix=CHECK-V8_1_FP_DP %s
+// CHECK-V8_1_FP_DP: -march=thumbv8.1m.main{{.*}}
+// CHECK-V8_1_FP_DP: -mfloat-abi=hard
+// CHECK-V8_1_FP_DP: -mfpu=fp-armv8-fullfp16-d16
+
+// RUN: %clang -print-multi-flags-experimental --target=arm-none-eabihf 
-mcpu=cortex-m85+nofp.dp | FileCheck --check-prefix=CHECK-M85_NO_FP_DP %s
+// CHECK-M85_NO_FP_DP: -march=thumbv8.1m.main{{.*}}
+// CHECK-M85_NO_FP_DP: -mfloat-abi=hard
+// CHECK-M85_NO_FP_DP: -mfpu=fp-armv8-fullfp16-sp-d16
+
 // RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf 
-march=armv8-a+lse | FileCheck --check-prefix=CHECK-LSE %s
 // CHECK-LSE: -march=aarch64{{.*}}+lse{{.*}}
 
diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.h 
b/llvm/include/llvm/TargetParser/ARMTargetParser.h
index b893eab1902f81b..c42d66f048fccc0 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.h
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.h
@@ -143,6 +143,14 @@ enum class FPURestriction {
   SP_D16///< Only single-precision instructions, with 16 D registers
 };
 
+inline bool isDoublePrecision(const FPURestriction restriction) {
+  return restriction != FPURestriction::SP_D16;
+}
+
+inline bool has32Regs(const FPURestriction restriction) {
+  return restriction == FPURestriction::None;
+}
+
 // An FPU name implies one of three levels of Neon support:
 enum class NeonSupportLevel {
   None = 0, ///< No Neon
diff --git a/llvm/lib/TargetParser/ARMTargetParser.cpp 
b/llvm/lib/TargetParser/ARMTargetParser.cpp
index c84928eeb07b140..524bb4e0fd0db22 100644
--- a/llvm/lib/TargetParser/ARMTargetParser.cpp
+++ b/llvm/lib/TargetParser/ARMTargetParser.cpp
@@ -366,26 +366,50 @@ StringRef ARM::getArchExtFeature(StringRef ArchExt) {
 }
 
 static ARM::FPUKind findDoublePrecisionFPU(ARM::FPUKind InputFPUKind) {
+  if (InputFPUKind == ARM::FK_INVALID || InputFPUKind == ARM::FK_NONE)
+return ARM::FK_INVALID;
+
+  const ARM::FPUName &InputFPU = ARM::FPUNames[InputFPUKind];
+
+  if (ARM::isDoublePrecision(InputFPU.Restriction))
+return InputFPUKind;
+
+  // Otherwise, look for an FPU entry with all the same fields, except
+  // that it supports double precision.
+  for (const ARM::FPUName &CandidateFPU : ARM::FPUNames) {
+if (CandidateFPU.FPUVer == InputFPU.FPUVer &&
+CandidateFPU.NeonSupport == InputFPU.NeonSupport &&
+ARM::has32Regs(CandidateFPU.Restriction) ==
+ARM::has32Regs(InputFPU.Restriction) &&
+ARM::isDoublePrecision(CandidateFPU.Restriction)) {
+  return CandidateFPU.ID;
+}
+  }
+
+  // nothing found
+  return ARM::FK_INVALID;
+}
+
+static ARM::FPUKind findSinglePrecisionFPU(ARM::FPUKind InputFPUKind) {
+  if (InputFPUKind == ARM::FK_INVALID || InputFPUKind == ARM::FK_NONE)
+return ARM::FK_INVALID;
+
   const ARM::FPUName &InputFPU = ARM::FPUNames[InputFPUKind];
 
   // If the input FPU already 

[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)

2023-10-13 Thread Nikita Popov via cfe-commits

nikic wrote:

You probably should just use find_program instead of llvm_find_program. It 
looks like llvm_find_program is used in just a single place, while we have very 
wide direct use of find_program, so I'm not sure why it is a thing in the first 
place.

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


[PATCH] D153131: [clang analysis][thread-safety] Handle return-by-reference...

2023-10-13 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

FWIW, the standard procedure for adding new functionality to existing warnings 
is (assuming that it makes the warning fire a lot, else no extra group is 
needed):

- Add it in a subgroup with its own flag
- Enable it by default

The reasoning is that people who aren't ready for the warning yet can then turn 
it off with the new flag, and everyone becomes aware of the new warning. If 
it's off-by-default, nobody will ever know about it.

(Of course, only warnings that are useful and high-signal should be added in 
the first place, so this is assuming that it's a warning with a very low false 
positive rate.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153131

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


[clang] [clang] Add information about lld presence in RISCVToolchain. (PR #68904)

2023-10-13 Thread Bushev Dmitry via cfe-commits

dybv-sc wrote:

Encountered code formatting check failure seems to be not reproducible locally:

```
$ git-clang-format --diff 7025ff6fa3dfe2ce8d3d7fcb0ec9de9a357d2c6f 
087d22970d1d2eea6dd0dd79eedd49ed69bc49c3 -- 
clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
clang/lib/Driver/ToolChains/RISCVToolchain.h 
clang/test/Driver/riscv64-toolchain.c
$ echo $?
0
```

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


[clang] [MSVC, ARM64] Add __prefetch intrinsic (PR #67174)

2023-10-13 Thread Nico Weber via cfe-commits

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

lgtm

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


[clang] [clang] Add information about lld presence in RISCVToolchain. (PR #68904)

2023-10-13 Thread Bushev Dmitry via cfe-commits

https://github.com/dybv-sc updated 
https://github.com/llvm/llvm-project/pull/68904

>From 0802a4170b6eddd1ae5bd532f90274794b0e00c4 Mon Sep 17 00:00:00 2001
From: Dmitry Bushev 
Date: Mon, 9 Oct 2023 19:49:09 +0300
Subject: [PATCH] [clang] Add information about lld presence in RISCVToolchain.

---
 .../lib/Driver/ToolChains/RISCVToolchain.cpp  |  4 ++-
 clang/lib/Driver/ToolChains/RISCVToolchain.h  |  3 +++
 clang/test/Driver/riscv64-toolchain.c | 25 +++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index c98f43f6e05eb4b..3a784be8e06616f 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -49,7 +49,9 @@ bool RISCVToolChain::hasGCCToolchain(const Driver &D,
 /// RISC-V Toolchain
 RISCVToolChain::RISCVToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
-: Generic_ELF(D, Triple, Args) {
+: Generic_ELF(D, Triple, Args), UseLLD{Args.getLastArgValue(
+   options::OPT_fuse_ld_EQ)
+   .equals_insensitive("lld")} {
   GCCInstallation.init(Triple, Args);
   if (GCCInstallation.isValid()) {
 Multilibs = GCCInstallation.getMultilibs();
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h 
b/clang/lib/Driver/ToolChains/RISCVToolchain.h
index de6960726f1cd77..afe98968ecd8616 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.h
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h
@@ -35,11 +35,14 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public 
Generic_ELF {
   addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
 
+  bool HasNativeLLVMSupport() const override { return UseLLD; }
+
 protected:
   Tool *buildLinker() const override;
 
 private:
   std::string computeSysRoot() const override;
+  bool UseLLD;
 };
 
 } // end namespace toolchains
diff --git a/clang/test/Driver/riscv64-toolchain.c 
b/clang/test/Driver/riscv64-toolchain.c
index f177bff33dd4d72..161aa9ae4207e14 100644
--- a/clang/test/Driver/riscv64-toolchain.c
+++ b/clang/test/Driver/riscv64-toolchain.c
@@ -121,6 +121,31 @@
 // C-RV64IMAC-BAREMETAL-MULTI-LP64: "--start-group" "-lc" "-lgloss" 
"--end-group" "-lgcc"
 // C-RV64IMAC-BAREMETAL-MULTI-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imac/lp64/crtend.o"
 
+// Check that lto works in riscv-toolchain when explicitly specified lld as 
linker.
+// RUN: env "PATH=" %clang -### %s -fuse-ld=lld -flto \
+// RUN:   -B%S/Inputs/lld --target=riscv64-unknown-elf --rtlib=platform 
--sysroot= \
+// RUN:   -march=rv64imac -mabi=lp64\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck -check-prefix=C-RV64IMAC-BAREMETAL-LTO-LP64 %s
+
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "{{.*}}lld"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "-m" "elf64lriscv"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/../../..{{/|}}..{{/|}}riscv64-unknown-elf/lib/crt0.o"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtbegin.o"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/../../..{{/|}}..{{/|}}riscv64-unknown-elf/lib"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "--start-group" "-lc" "-lgloss" 
"--end-group" "-lgcc"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: 
"{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtend.o"
+
+// Check driver error when lto is used without specified lld linker.
+// RUN: env "PATH=" %clang -### %s -flto \
+// RUN:   --target=riscv64-unknown-elf --rtlib=platform --sysroot= \
+// RUN:   -march=rv64imac -mabi=lp64\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck -check-prefix=C-RV64IMAC-BAREMETAL-LTO-FAIL-LP64 %s
+
+// C-RV64IMAC-BAREMETAL-LTO-FAIL-LP64: clang-16: error: 
'riscv64-unknown-unknown-elf': unable to pass LLVM bit-code files to linker
+
 // RUN: env "PATH=" %clang -### %s -fuse-ld=ld \
 // RUN:   --target=riscv64-unknown-elf --rtlib=platform --unwindlib=platform 
--sysroot= \
 // RUN:   -march=rv64imafdc -mabi=lp64d \

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


[clang] [AArch64] Stack probing for dynamic allocas in SelectionDAG (PR #66525)

2023-10-13 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 5d35273a32d239b7407338e13ed71b59174d6536 
e32ff3b92cbbf074567d6d04f7ec5c1f3b9b27a5 -- clang/lib/CodeGen/CodeGenModule.cpp 
clang/lib/Driver/ToolChains/Clang.cpp 
clang/test/CodeGen/stack-clash-protection.c llvm/lib/CodeGen/CFIFixup.cpp 
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp 
llvm/lib/Target/AArch64/AArch64FrameLowering.h 
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
llvm/lib/Target/AArch64/AArch64ISelLowering.h 
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp 
llvm/lib/Target/AArch64/AArch64InstrInfo.h 
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp 
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/CodeGen/CFIFixup.cpp b/llvm/lib/CodeGen/CFIFixup.cpp
index 7269616e3fff..964a8d56511f 100644
--- a/llvm/lib/CodeGen/CFIFixup.cpp
+++ b/llvm/lib/CodeGen/CFIFixup.cpp
@@ -100,7 +100,8 @@ static bool containsEpilogue(const MachineBasicBlock &MBB) {
 static MachineBasicBlock *
 findPrologueEnd(MachineFunction &MF, MachineBasicBlock::iterator &PrologueEnd) 
{
   MachineBasicBlock *PrologueBlock = nullptr;
-  for (auto It = po_begin(&MF.front()), End = po_end(&MF.front()); It != End; 
++It) {
+  for (auto It = po_begin(&MF.front()), End = po_end(&MF.front()); It != End;
+   ++It) {
 MachineBasicBlock *MBB = *It;
 llvm::for_each(MBB->instrs(), [&](MachineInstr &MI) {
   if (isPrologueCFIInstruction(MI)) {

``




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


[clang] 3efa479 - [clang][Interp] Support AddOffset with 128bit offsets (#68679)

2023-10-13 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-10-13T14:47:46+02:00
New Revision: 3efa4794ecd5ca6235f9f7e3fc83a8d9e59b66c9

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

LOG: [clang][Interp] Support AddOffset with 128bit offsets (#68679)

We do a similar thing a few lines above for `Index`:

```c++
  // Get a version of the index comparable to the type.
  T Index = T::from(Ptr.getIndex(), Offset.bitWidth());
```

Added: 


Modified: 
clang/lib/AST/Interp/Boolean.h
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/IntegralAP.h
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/intap.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index c3ed3d61f76ca1c..336f7941dfc479d 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -42,6 +42,7 @@ class Boolean final {
   bool operator>(unsigned RHS) const { return static_cast(V) > RHS; }
 
   Boolean operator-() const { return Boolean(V); }
+  Boolean operator-(const Boolean &Other) const { return Boolean(V - Other.V); 
}
   Boolean operator~() const { return Boolean(true); }
 
   explicit operator int8_t() const { return V; }

diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 4dbe9c9bcb14b43..cc1cab8f39fb1e5 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -88,6 +88,9 @@ template  class Integral final {
   }
 
   Integral operator-() const { return Integral(-V); }
+  Integral operator-(const Integral &Other) const {
+return Integral(V - Other.V);
+  }
   Integral operator~() const { return Integral(~V); }
 
   template 

diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index f9a33bbcd7bd7fa..f17fb8e484415d2 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -59,6 +59,9 @@ template  class IntegralAP final {
   IntegralAP() : V(APSInt::getMaxValue(1024, Signed)) {}
 
   IntegralAP operator-() const { return IntegralAP(-V); }
+  IntegralAP operator-(const IntegralAP &Other) const {
+return IntegralAP(V - Other.V);
+  }
   bool operator>(IntegralAP RHS) const { return V > RHS.V; }
   bool operator>=(IntegralAP RHS) const { return V >= RHS.V; }
   bool operator<(IntegralAP RHS) const { return V < RHS.V; }

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 1ad3b8bfc7711d3..e3e6a4cec63b194 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1421,7 +1421,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T 
&Offset,
   // Get a version of the index comparable to the type.
   T Index = T::from(Ptr.getIndex(), Offset.bitWidth());
   // Compute the largest index into the array.
-  unsigned MaxIndex = Ptr.getNumElems();
+  T MaxIndex = T::from(Ptr.getNumElems(), Offset.bitWidth());
 
   // Helper to report an invalid offset, computed as APSInt.
   auto InvalidOffset = [&]() {
@@ -1437,7 +1437,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T 
&Offset,
 return false;
   };
 
-  unsigned MaxOffset = MaxIndex - Ptr.getIndex();
+  T MaxOffset = T::from(MaxIndex - Index, Offset.bitWidth());
   if constexpr (Op == ArithOp::Add) {
 // If the new offset would be negative, bail out.
 if (Offset.isNegative() && (Offset.isMin() || -Offset > Index))

diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 8fe65a69a4fee8d..f9cbc698a3290d8 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -90,4 +90,14 @@ namespace i128 {
// expected-error {{must be 
initialized by a constant expression}} \
// expected-note {{is outside the 
range of representable values of type}}
 }
+
+namespace AddSubOffset {
+  constexpr __int128 A = 1;
+  constexpr int arr[] = {1,2,3};
+  constexpr const int *P = arr + A;
+  static_assert(*P == 2, "");
+  constexpr const int *P2 = P - A;
+  static_assert(*P2 == 1,"");
+}
+
 #endif



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


[clang] [clang][Interp] Support AddOffset with 128bit offsets (PR #68679)

2023-10-13 Thread Timm Baeder via cfe-commits

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


[clang] [ASAN] Adjust asan instrumented GlobalVariable size to not include redzone (PR #66666)

2023-10-13 Thread Mitch Phillips via cfe-commits

hctim wrote:

My assumption is that you have some driver code or preloaded DSO that 
effectively implements `copy_to_amdgpu`, which would do something with the 
symtab.

Can you just make your driver not be asan-ified (either by not building it with 
`-fsanitize=address` or using `__attribute__((no_sanitize("address")))` on the 
`copy_to_amdgpu` function? Then you'd copy the right quantity of data, and the 
access of the redzone would be ignored as there's no instrumentation there.

This seems like a more appropriate thing than making `st_other` symtab entries 
not actually the right size.

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


[clang] [AArch64] Stack probing for function prologues (PR #66524)

2023-10-13 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 8d59fc5fd1599bd7153817d2af903ae9a6103343 
7b66d75f43bfd4e52f48307e9fcc2992eefb8bdd -- clang/lib/CodeGen/CodeGenModule.cpp 
clang/lib/Driver/ToolChains/Clang.cpp 
clang/test/CodeGen/stack-clash-protection.c llvm/lib/CodeGen/CFIFixup.cpp 
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp 
llvm/lib/Target/AArch64/AArch64FrameLowering.h 
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
llvm/lib/Target/AArch64/AArch64ISelLowering.h 
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp 
llvm/lib/Target/AArch64/AArch64InstrInfo.h 
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp 
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/CodeGen/CFIFixup.cpp b/llvm/lib/CodeGen/CFIFixup.cpp
index 7269616e3fff..964a8d56511f 100644
--- a/llvm/lib/CodeGen/CFIFixup.cpp
+++ b/llvm/lib/CodeGen/CFIFixup.cpp
@@ -100,7 +100,8 @@ static bool containsEpilogue(const MachineBasicBlock &MBB) {
 static MachineBasicBlock *
 findPrologueEnd(MachineFunction &MF, MachineBasicBlock::iterator &PrologueEnd) 
{
   MachineBasicBlock *PrologueBlock = nullptr;
-  for (auto It = po_begin(&MF.front()), End = po_end(&MF.front()); It != End; 
++It) {
+  for (auto It = po_begin(&MF.front()), End = po_end(&MF.front()); It != End;
+   ++It) {
 MachineBasicBlock *MBB = *It;
 llvm::for_each(MBB->instrs(), [&](MachineInstr &MI) {
   if (isPrologueCFIInstruction(MI)) {

``




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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-13 Thread Aaron Ballman via cfe-commits
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= 
Message-ID:
In-Reply-To: 


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

LGTM!

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


[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading. (PR #68986)

2023-10-13 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev created 
https://github.com/llvm/llvm-project/pull/68986

- [DebugMetadata][DwarfDebug] Support function-local types in lexical block 
scopes (4/7)
- Clone function-local types after metadata loading.

This is a follow-up for https://reviews.llvm.org/D144006, fixing a crash 
reported in Chromium (https://reviews.llvm.org/D144006#4651955).

The very first commit is added for convenience, as it has already been accepted.
The issue with it is that when DIType nodes are loaded, they get deduplicated 
as ODR-uniqued. When two modules get merged by LTO, DISubprogram nodes for the 
same function from different modules are not uniqued, since they are marked as 
distinct, whereas their retained type are, which can violate the ownership 
relationship betweeen DISubprogram and its function-local retained type.
It is fixed by copying a function-local type referenced by one DISubprogram 
through retainedNodes and referencing another in its scope field. The scope of 
copy gets changed correspondingly.

This is meant to be committed along with https://reviews.llvm.org/D144006.


>From d61f109dcb92db45fa8f6ce7503409edcbfbce63 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Tue, 18 Jul 2023 14:22:46 +0200
Subject: [PATCH 1/2] [DebugMetadata][DwarfDebug] Support function-local types
 in lexical block scopes (4/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Similar to imported declarations, the patch tracks function-local types in
DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with
the aforementioned metadata change and provided a support of function-local
types scoped within a lexical block.

The patch assumes that DICompileUnit's 'enums field' no longer tracks local
types and DwarfDebug would assert if any locally-scoped types get placed there.

Reviewed By: jmmartinez

Differential Revision: https://reviews.llvm.org/D144006
---
 .../CodeGen/debug-info-codeview-unnamed.c |  16 +-
 clang/test/CodeGen/debug-info-unused-types.c  |  16 +-
 .../test/CodeGen/debug-info-unused-types.cpp  |  14 +-
 clang/test/CodeGenCXX/debug-info-access.cpp   |   2 +-
 .../CodeGenCXX/debug-info-anon-union-vars.cpp |  12 +-
 .../debug-info-codeview-unnamed.cpp   | 110 +++--
 .../debug-info-gline-tables-only-codeview.cpp |   4 +-
 clang/test/CodeGenCXX/debug-lambda-this.cpp   |   4 +-
 llvm/include/llvm/IR/DIBuilder.h  |   6 +-
 llvm/include/llvm/IR/DebugInfo.h  |   1 +
 llvm/lib/Bitcode/Reader/MetadataLoader.cpp|  86 ++--
 .../CodeGen/AsmPrinter/DwarfCompileUnit.cpp   |  60 ++-
 .../lib/CodeGen/AsmPrinter/DwarfCompileUnit.h |  16 +-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp|  13 +-
 llvm/lib/IR/DIBuilder.cpp |  37 +-
 llvm/lib/IR/DebugInfo.cpp |  11 +-
 llvm/lib/IR/Verifier.cpp  |   6 +-
 llvm/lib/Transforms/Utils/CloneFunction.cpp   |   7 +-
 llvm/test/Bitcode/upgrade-cu-locals.ll|  68 +--
 llvm/test/Bitcode/upgrade-cu-locals.ll.bc | Bin 2688 -> 2780 bytes
 .../DebugInfo/Generic/inlined-local-type.ll   | 128 ++
 .../Generic/lexical-block-retained-types.ll   |  55 +++
 .../DebugInfo/Generic/lexical-block-types.ll  | 425 ++
 .../Generic/verifier-invalid-disubprogram.ll  |   2 +-
 .../X86/local-type-as-template-parameter.ll   | 161 +++
 llvm/test/DebugInfo/X86/set.ll|   4 +-
 .../split-dwarf-local-import.ll   |   1 -
 .../split-dwarf-local-import2.ll  |   1 -
 .../split-dwarf-local-import3.ll  |   0
 .../Transforms/Utils/CloningTest.cpp  |  93 
 30 files changed, 1165 insertions(+), 194 deletions(-)
 create mode 100644 llvm/test/DebugInfo/Generic/inlined-local-type.ll
 create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
 create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-types.ll
 create mode 100644 llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import.ll (98%)
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import2.ll (98%)
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import3.ll (100%)

diff --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2ba..16ffb3682236f18 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DIComp

[PATCH] D156565: Diagnose use of VLAs in C++ by default

2023-10-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Ping


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

https://reviews.llvm.org/D156565

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


[clang] [clang][Interp] Only emit function_param_value_unknown in C++11 (PR #67990)

2023-10-13 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> https://reviews.llvm.org/D156565 hasn't been merged as far as I can tell and 
> it's the only test case I have for this. :(

Ah shoot, let me ping that review and see if I can get it accepted and landed 
so we can have test coverage.

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


[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading. (PR #68986)

2023-10-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vladislav Dzhidzhoev (dzhidzhoev)


Changes

- [DebugMetadata][DwarfDebug] Support function-local types in lexical block 
scopes (4/7)
- Clone function-local types after metadata loading.

This is a follow-up for https://reviews.llvm.org/D144006, fixing a crash 
reported in Chromium (https://reviews.llvm.org/D144006#4651955).

The very first commit is added for convenience, as it has already been accepted.
The issue with it is that when DIType nodes are loaded, they get deduplicated 
as ODR-uniqued. When two modules get merged by LTO, DISubprogram nodes for the 
same function from different modules are not uniqued, since they are marked as 
distinct, whereas their retained type are, which can violate the ownership 
relationship betweeen DISubprogram and its function-local retained type.
It is fixed by copying a function-local type referenced by one DISubprogram 
through retainedNodes and referencing another in its scope field. The scope of 
copy gets changed correspondingly.

This is meant to be committed along with https://reviews.llvm.org/D144006.


---

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


31 Files Affected:

- (modified) clang/test/CodeGen/debug-info-codeview-unnamed.c (+8-8) 
- (modified) clang/test/CodeGen/debug-info-unused-types.c (+9-7) 
- (modified) clang/test/CodeGen/debug-info-unused-types.cpp (+8-6) 
- (modified) clang/test/CodeGenCXX/debug-info-access.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp (+6-6) 
- (modified) clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp (+62-48) 
- (modified) clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp 
(+2-2) 
- (modified) clang/test/CodeGenCXX/debug-lambda-this.cpp (+2-2) 
- (modified) llvm/include/llvm/IR/DIBuilder.h (+3-3) 
- (modified) llvm/include/llvm/IR/DebugInfo.h (+1) 
- (modified) llvm/lib/Bitcode/Reader/MetadataLoader.cpp (+77-33) 
- (modified) llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (+40-20) 
- (modified) llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h (+8-8) 
- (modified) llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (+10-3) 
- (modified) llvm/lib/IR/DIBuilder.cpp (+27-10) 
- (modified) llvm/lib/IR/DebugInfo.cpp (+10-1) 
- (modified) llvm/lib/IR/Verifier.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Utils/CloneFunction.cpp (+6-1) 
- (added) llvm/test/Bitcode/clone-local-types.ll (+43) 
- (modified) llvm/test/Bitcode/upgrade-cu-locals.ll (+41-27) 
- (modified) llvm/test/Bitcode/upgrade-cu-locals.ll.bc () 
- (added) llvm/test/DebugInfo/Generic/inlined-local-type.ll (+128) 
- (added) llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll (+55) 
- (added) llvm/test/DebugInfo/Generic/lexical-block-types.ll (+425) 
- (modified) llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll 
(+1-1) 
- (added) llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll (+161) 
- (modified) llvm/test/DebugInfo/X86/set.ll (+2-2) 
- (renamed) llvm/test/DebugInfo/X86/split-dwarf-local-import.ll (-1) 
- (renamed) llvm/test/DebugInfo/X86/split-dwarf-local-import2.ll (-1) 
- (renamed) llvm/test/DebugInfo/X86/split-dwarf-local-import3.ll () 
- (modified) llvm/unittests/Transforms/Utils/CloningTest.cpp (+93) 


``diff
diff --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2ba..16ffb3682236f18 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE]]
+  // LINUX-SAME: )
   //
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
-  // MSVC-SAME:  )
-  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
+  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
+  // MSVC-SAME:  )
 
   return 0;
 }
diff --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 3e9f7b07658e36e..31d608d92a06b41 100644
--- a/clang/test/CodeGen/debug-info-unused-type

[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading. (PR #68986)

2023-10-13 Thread Vladislav Dzhidzhoev via cfe-commits

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


[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading. (PR #68986)

2023-10-13 Thread Vladislav Dzhidzhoev via cfe-commits

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


[PATCH] D144006: [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)

2023-10-13 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev added a comment.

In D144006#4651955 , @hans wrote:

> We're hitting an assert after this change:
>
>   llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:2331:
>   virtual void llvm::DwarfDebug::endFunctionImpl(const llvm::MachineFunction 
> *):
>   Assertion `LScopes.getAbstractScopesList().size() == NumAbstractSubprograms 
> &&
>   "getOrCreateAbstractScope() inserted an abstract subprogram scope"' failed.
>
> See https://bugs.chromium.org/p/chromium/issues/detail?id=1487910#c3 for a 
> reproducer.
>
> I'll revert until it can be investigated/fixed.

Thank you! Added a fix for that https://github.com/llvm/llvm-project/pull/68986.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144006

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


[clang] [clang][Interp] IntegralAP zero-init (PR #68081)

2023-10-13 Thread Aaron Ballman via cfe-commits


@@ -100,12 +100,13 @@ template  class IntegralAP final {
   }
   static IntegralAP from(const Boolean &B) {
 assert(false);
-return IntegralAP::zero();
+return IntegralAP::zero(1);
   }
 
-  static IntegralAP zero() {
-assert(false);
-return IntegralAP(0);
+  static IntegralAP zero(int32_t BitWidth) {
+APSInt V =
+APSInt(APInt(BitWidth, static_cast(0), Signed), !Signed);

AaronBallman wrote:

Oh wow, that's... neat. The explicit cast is also fine, but perhaps should be 
to `uint64_t` to remove one more implicit conversion step.

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


[clang] [clang][Interp] IntegralAP zero-init (PR #68081)

2023-10-13 Thread Aaron Ballman via cfe-commits


@@ -100,12 +100,13 @@ template  class IntegralAP final {
   }
   static IntegralAP from(const Boolean &B) {
 assert(false);
-return IntegralAP::zero();
+return IntegralAP::zero(1);

AaronBallman wrote:

Ah, please add FIXME comments to unimplemented stuff when you can.

(I'll be honest -- reviewing new interpreter patches is getting really 
difficult because of the interdependence between so many unrelated reviews and 
how much stuff is half-done. That's why these reviews keep getting delayed on 
my end, there's just too much to try to keep track of spread out across too 
many reviews. I wish we could find a way to improve this without impeding your 
ability to make progress. CC @Shafik @erichkeane @cor3ntin as other folks doing 
a fair number of these reviews in case this is a shared concern and folks have 
ideas on how to improve it.)

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


[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading. (PR #68986)

2023-10-13 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 3efa4794ecd5ca6235f9f7e3fc83a8d9e59b66c9 
5012fac53513949a3e1987e0d6cc4695ac5dbd69 -- 
clang/test/CodeGen/debug-info-codeview-unnamed.c 
clang/test/CodeGen/debug-info-unused-types.c 
clang/test/CodeGen/debug-info-unused-types.cpp 
clang/test/CodeGenCXX/debug-info-access.cpp 
clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp 
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp 
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp 
clang/test/CodeGenCXX/debug-lambda-this.cpp llvm/include/llvm/IR/DIBuilder.h 
llvm/include/llvm/IR/DebugInfo.h llvm/lib/Bitcode/Reader/MetadataLoader.cpp 
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp 
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h 
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp llvm/lib/IR/DIBuilder.cpp 
llvm/lib/IR/DebugInfo.cpp llvm/lib/IR/Verifier.cpp 
llvm/lib/Transforms/Utils/CloneFunction.cpp 
llvm/unittests/Transforms/Utils/CloningTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index d3e618b638fb..f9e3c3db299a 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -69,9 +69,9 @@ void DIBuilder::finalize() {
   }
 
   if (!EnumTypes.empty())
-CUNode->replaceEnumTypes(MDTuple::get(
-VMContext, SmallVector(EnumTypes.begin(),
-   EnumTypes.end(;
+CUNode->replaceEnumTypes(
+MDTuple::get(VMContext, SmallVector(EnumTypes.begin(),
+EnumTypes.end(;
 
   SmallVector RetainValues;
   // Declarations and definitions of the same type may be retained. Some

``




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


[clang] [clang][Interp] IntegralAP zero-init (PR #68081)

2023-10-13 Thread Aaron Ballman via cfe-commits

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

Aside from nits, this LGTM.

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-13 Thread Sander de Smalen via cfe-commits


@@ -9716,13 +9716,16 @@ Value *CodeGenFunction::EmitSMELdrStr(const 
SVETypeFlags &TypeFlags,
   if (Ops.size() == 3) {
 Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
 llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-llvm::Value *MulVL = Builder.CreateMul(
-CntsbCall,
-Builder.getInt64(cast(Ops[2])->getZExtValue()),
-"mulvl");
+
+llvm::Value *VecNum = Ops[2];
+if (auto *C = dyn_cast(VecNum))
+  VecNum = Builder.getInt64(C->getZExtValue());
+
+llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
 
 Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = EmitTileslice(Ops[0], Ops[2]);
+Ops[0] =
+EmitTileslice(Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true));

sdesmalen-arm wrote:

Because EmitTileSlice is defined with the operands `Value *Offset, Value 
*Base`, this is passing the operands in the wrong order. EmitTileSlice will 
then create cast to Int32Ty for you. That said, given that `EmitTileSlice` has 
only one use and is two lines of code, you can just as well inline the function 
and remove it.

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


[clang-tools-extra] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-13 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > (Was out of town...)
> > As mentioned at [#67360 
> > (comment)](https://github.com/llvm/llvm-project/pull/67360#issuecomment-1736187374)
> >  , I think a default error is probably not appropriate. A priority value <= 
> > 100 may compete with a runtime `__attribute__((constructor(X)))` but more 
> > often it will work. A warning is fine. GCC defaults to a warning and the 
> > attribute form with a priority is an obscure feature anyway, therefore it 
> > doesn't buy us much to make it an error. You can make `> 65535` an error, 
> > though.
> 
> I disagree -- we decided ages ago with init_priority that using these 
> reserved priorities should be an error that can be ignored for the few cases 
> where the reservation does not apply. We should be designing the Ux for these 
> features around the majority of users, not the majority of people who will be 
> expert user of the feature. Otherwise, we should not pretend these are 
> reserved values -- it's far too easy to ignore a warning IMO.
> 
> That said, I'm abandoning this work regardless. It was unplanned work I took 
> on only because I noticed how deficient the implementation was regarding 
> diagnostics when I went to add documentation for the attribute in the first 
> place. A lot of our attributes from 2000-2012 or so are similarly 
> problematic, unfortunately. So I wouldn't be surprised to see this come up 
> again in the future.

First, it would be a shame if you abandon this over this bit, there is plenty 
of value to this patch, even as far as the refactoring (which makes some other 
folks' patches easier to review!).  While I agree with you that the error is 
appropriate, it doesn't seem practical at the moment thanks to GCC's 
implementation.  Abandoning this patch means that those will NEVER be an error, 
so at least having this patch in gives us an opportunity to make this an error 
'someday'.

IMO, a warning/Warning-as-default-error are both appropriate (with preference 
towards the latter) 'for now', and we should fight the battle of making this a 
hard error another time.

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


[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-13 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > (Was out of town...)
> > As mentioned at [#67360 
> > (comment)](https://github.com/llvm/llvm-project/pull/67360#issuecomment-1736187374)
> >  , I think a default error is probably not appropriate. A priority value <= 
> > 100 may compete with a runtime `__attribute__((constructor(X)))` but more 
> > often it will work. A warning is fine. GCC defaults to a warning and the 
> > attribute form with a priority is an obscure feature anyway, therefore it 
> > doesn't buy us much to make it an error. You can make `> 65535` an error, 
> > though.
> 
> I disagree -- we decided ages ago with init_priority that using these 
> reserved priorities should be an error that can be ignored for the few cases 
> where the reservation does not apply. We should be designing the Ux for these 
> features around the majority of users, not the majority of people who will be 
> expert user of the feature. Otherwise, we should not pretend these are 
> reserved values -- it's far too easy to ignore a warning IMO.
> 
> That said, I'm abandoning this work regardless. It was unplanned work I took 
> on only because I noticed how deficient the implementation was regarding 
> diagnostics when I went to add documentation for the attribute in the first 
> place. A lot of our attributes from 2000-2012 or so are similarly 
> problematic, unfortunately. So I wouldn't be surprised to see this come up 
> again in the future.

First, it would be a shame if you abandon this over this bit, there is plenty 
of value to this patch, even as far as the refactoring (which makes some other 
folks' patches easier to review!).  While I agree with you that the error is 
appropriate, it doesn't seem practical at the moment thanks to GCC's 
implementation.  Abandoning this patch means that those will NEVER be an error, 
so at least having this patch in gives us an opportunity to make this an error 
'someday'.

IMO, a warning/Warning-as-default-error are both appropriate (with preference 
towards the latter) 'for now', and we should fight the battle of making this a 
hard error another time.

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


[clang] Let clang-cl support CUDA/HIP (PR #68921)

2023-10-13 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

The main objective is to make porting cmake files easier. Without it, you have 
to use clang-cl.exe to compile C++ and clang.exe to compile HIP since the 
options are not compatible. Now you can use clang-cl.exe to compile both, which 
accepts both MSVC options and clang options.

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


[clang-tools-extra] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-13 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > > (Was out of town...)
> > > As mentioned at [#67360 
> > > (comment)](https://github.com/llvm/llvm-project/pull/67360#issuecomment-1736187374)
> > >  , I think a default error is probably not appropriate. A priority value 
> > > <= 100 may compete with a runtime `__attribute__((constructor(X)))` but 
> > > more often it will work. A warning is fine. GCC defaults to a warning and 
> > > the attribute form with a priority is an obscure feature anyway, 
> > > therefore it doesn't buy us much to make it an error. You can make `> 
> > > 65535` an error, though.
> > 
> > 
> > I disagree -- we decided ages ago with init_priority that using these 
> > reserved priorities should be an error that can be ignored for the few 
> > cases where the reservation does not apply. We should be designing the Ux 
> > for these features around the majority of users, not the majority of people 
> > who will be expert user of the feature. Otherwise, we should not pretend 
> > these are reserved values -- it's far too easy to ignore a warning IMO.
> > That said, I'm abandoning this work regardless. It was unplanned work I 
> > took on only because I noticed how deficient the implementation was 
> > regarding diagnostics when I went to add documentation for the attribute in 
> > the first place. A lot of our attributes from 2000-2012 or so are similarly 
> > problematic, unfortunately. So I wouldn't be surprised to see this come up 
> > again in the future.
> 
> First, it would be a shame if you abandon this over this bit, there is plenty 
> of value to this patch, even as far as the refactoring (which makes some 
> other folks' patches easier to review!). While I agree with you that the 
> error is appropriate, it doesn't seem practical at the moment thanks to GCC's 
> implementation. Abandoning this patch means that those will NEVER be an 
> error, so at least having this patch in gives us an opportunity to make this 
> an error 'someday'.
> 
> IMO, a warning/Warning-as-default-error are both appropriate (with preference 
> towards the latter) 'for now', and we should fight the battle of making this 
> a hard error another time.

That doesn't solve the issue though -- we have `-Werror` bots for compiler-rt, 
so someone still needs to figure out how to beat CMake into shape even if we 
introduce it as a warning. I took several runs at the build system and was 
unsuccessful -- I can't repro locally on Windows and our precommit CI doesn't 
demonstrate the issue, so this requires making a number of speculative commits 
+ watch the bots for fallout and that's where I ran out of time for the 
unexpected effort. I'm totally happy if someone wants to pick this up and run 
it across the finish line, warning-as-error or warning form. I personally think 
warning-as-error form is the correct approach though; "GCC doesn't err" isn't 
really compelling logic to me because GCC attributes (especially the older 
ones) have traditionally had underwhelming diagnostic behavior -- we should 
strive to do better when possible.

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


[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-13 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > > (Was out of town...)
> > > As mentioned at [#67360 
> > > (comment)](https://github.com/llvm/llvm-project/pull/67360#issuecomment-1736187374)
> > >  , I think a default error is probably not appropriate. A priority value 
> > > <= 100 may compete with a runtime `__attribute__((constructor(X)))` but 
> > > more often it will work. A warning is fine. GCC defaults to a warning and 
> > > the attribute form with a priority is an obscure feature anyway, 
> > > therefore it doesn't buy us much to make it an error. You can make `> 
> > > 65535` an error, though.
> > 
> > 
> > I disagree -- we decided ages ago with init_priority that using these 
> > reserved priorities should be an error that can be ignored for the few 
> > cases where the reservation does not apply. We should be designing the Ux 
> > for these features around the majority of users, not the majority of people 
> > who will be expert user of the feature. Otherwise, we should not pretend 
> > these are reserved values -- it's far too easy to ignore a warning IMO.
> > That said, I'm abandoning this work regardless. It was unplanned work I 
> > took on only because I noticed how deficient the implementation was 
> > regarding diagnostics when I went to add documentation for the attribute in 
> > the first place. A lot of our attributes from 2000-2012 or so are similarly 
> > problematic, unfortunately. So I wouldn't be surprised to see this come up 
> > again in the future.
> 
> First, it would be a shame if you abandon this over this bit, there is plenty 
> of value to this patch, even as far as the refactoring (which makes some 
> other folks' patches easier to review!). While I agree with you that the 
> error is appropriate, it doesn't seem practical at the moment thanks to GCC's 
> implementation. Abandoning this patch means that those will NEVER be an 
> error, so at least having this patch in gives us an opportunity to make this 
> an error 'someday'.
> 
> IMO, a warning/Warning-as-default-error are both appropriate (with preference 
> towards the latter) 'for now', and we should fight the battle of making this 
> a hard error another time.

That doesn't solve the issue though -- we have `-Werror` bots for compiler-rt, 
so someone still needs to figure out how to beat CMake into shape even if we 
introduce it as a warning. I took several runs at the build system and was 
unsuccessful -- I can't repro locally on Windows and our precommit CI doesn't 
demonstrate the issue, so this requires making a number of speculative commits 
+ watch the bots for fallout and that's where I ran out of time for the 
unexpected effort. I'm totally happy if someone wants to pick this up and run 
it across the finish line, warning-as-error or warning form. I personally think 
warning-as-error form is the correct approach though; "GCC doesn't err" isn't 
really compelling logic to me because GCC attributes (especially the older 
ones) have traditionally had underwhelming diagnostic behavior -- we should 
strive to do better when possible.

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


[clang-tools-extra] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-13 Thread Erich Keane via cfe-commits

erichkeane wrote:

I missed the compiler-rt bit there, thats a real shame, this is a really 
valueable patch that I'd hope someone would take up.  While "GCC Doesnt Error" 
isn't particularly compelling and we SHOULD be better than that, I'd also 
prefer not throwing the baby out with the bath water.

That said, if you're unable to do the cmake work, I'm hopeful someone else can 
come along.  Is there a 'beginner commandeer' (ala-beginner-bug?) tag we could 
throw on this? 

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


[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-13 Thread Erich Keane via cfe-commits

erichkeane wrote:

I missed the compiler-rt bit there, thats a real shame, this is a really 
valueable patch that I'd hope someone would take up.  While "GCC Doesnt Error" 
isn't particularly compelling and we SHOULD be better than that, I'd also 
prefer not throwing the baby out with the bath water.

That said, if you're unable to do the cmake work, I'm hopeful someone else can 
come along.  Is there a 'beginner commandeer' (ala-beginner-bug?) tag we could 
throw on this? 

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


[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-13 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

If Aaron weren't able to fix this in several commits, I'm not sure it's a `good 
first issue`.

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


[clang] [analyzer][NFC] Simplifications in ArrayBoundV2 (PR #67572)

2023-10-13 Thread via cfe-commits

https://github.com/DonatNagyE updated 
https://github.com/llvm/llvm-project/pull/67572

>From 7bd280e2da3f2ee8fe5fd7086a4704331f21b435 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Wed, 6 Sep 2023 13:39:27 +0200
Subject: [PATCH] [analyzer][NFC] Simplifications in ArrayBoundV2

I'm planning to improve diagnostics generation in `ArrayBoundCheckerV2`
but before that I'm refactoring the source code to clean up some
over-complicated code and an inaccurate comment.

Changes in this commit:
- Remove the `mutable std::unique_ptr` boilerplate, because
  it's no longer needed.
- Remove the code duplication between the methods `reportOOB()` and
  `reportTaintedOOB()`.
- Eliminate the class `RegionRawOffsetV2` because it's just a "reinvent
  the wheel" version of `std::pair` and it was used only once, as a
  temporary object that was immediately decomposed. (I suspect that
  `RegionRawOffset` in MemRegion.cpp could also be eliminated.)
- Flatten the code of `computeOffset()` which had contained six nested
  indentation levels before this commit.
- Ensure that `computeOffset()` returns `std::nullopt` instead of a
  `{Region, }` pair in the case when it encounters a
  `Location` that is not an `ElementRegion`. This ensures that the
  `checkLocation` callback returns early when it handles a memory access
  where it has "nothing to do" (no subscript operation or equivalent
  pointer arithmetic). (Note that this is still NFC because zero is a
  valid index everywhere, so the old logic without this shortcut
  eventually reached the same conclusion.)
- Correct a wrong explanation comment in `getSimplifiedOffsets()`.
---
 .../Checkers/ArrayBoundCheckerV2.cpp  | 221 +++---
 1 file changed, 86 insertions(+), 135 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
index db4a2fcea9b2cdd..c2ffcdf5e306d1f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -32,15 +32,13 @@ using namespace taint;
 namespace {
 class ArrayBoundCheckerV2 :
 public Checker {
-  mutable std::unique_ptr BT;
-  mutable std::unique_ptr TaintBT;
+  BugType BT{this, "Out-of-bound access"};
+  BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
-  enum OOB_Kind { OOB_Precedes, OOB_Excedes };
+  enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-  void reportOOB(CheckerContext &C, ProgramStateRef errorState,
- OOB_Kind kind) const;
-  void reportTaintOOB(CheckerContext &C, ProgramStateRef errorState,
-  SVal TaintedSVal) const;
+  void reportOOB(CheckerContext &C, ProgramStateRef ErrorState, OOB_Kind Kind,
+ SVal TaintedSVal = UnknownVal()) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext &AC);
 
@@ -48,26 +46,58 @@ class ArrayBoundCheckerV2 :
   void checkLocation(SVal l, bool isLoad, const Stmt *S,
  CheckerContext &C) const;
 };
+} // anonymous namespace
 
-// FIXME: Eventually replace RegionRawOffset with this class.
-class RegionRawOffsetV2 {
-private:
-  const SubRegion *baseRegion;
-  NonLoc byteOffset;
+/// For a given Location that can be represented as a symbolic expression
+/// Arr[Idx] (or perhaps Arr[Idx1][Idx2] etc.), return the parent memory block
+/// Arr and the distance of Location from the beginning of Arr (expressed in a
+/// NonLoc that specifies the number of CharUnits). Returns nullopt when these
+/// cannot be determined.
+std::optional>
+computeOffset(ProgramStateRef State, SValBuilder &SVB, SVal Location) {
+  QualType T = SVB.getArrayIndexType();
+  auto Calc = [&SVB, State, T](BinaryOperatorKind Op, NonLoc LHS, NonLoc RHS) {
+// We will use this utility to add and multiply values.
+return SVB.evalBinOpNN(State, Op, LHS, RHS, T).getAs();
+  };
 
-public:
-  RegionRawOffsetV2(const SubRegion *base, NonLoc offset)
-  : baseRegion(base), byteOffset(offset) { assert(base); }
+  const auto *Region = dyn_cast_or_null(Location.getAsRegion());
+  std::optional Offset = std::nullopt;
+
+  while (const auto *ERegion = dyn_cast_or_null(Region)) {
+const auto Index = ERegion->getIndex().getAs();
+if (!Index)
+  return std::nullopt;
+
+QualType ElemType = ERegion->getElementType();
+// If the element is an incomplete type, go no further.
+if (ElemType->isIncompleteType())
+  return std::nullopt;
+
+// Calculate Delta = Index * sizeof(ElemType).
+NonLoc Size = SVB.makeArrayIndex(
+SVB.getContext().getTypeSizeInChars(ElemType).getQuantity());
+auto Delta = Calc(BO_Mul, *Index, Size);
+if (!Delta)
+  return std::nullopt;
+
+// Perform Offset += Delta, handling the initial nullopt as 0.
+if (!Offset) {
+  Offset = Delta;
+} else {
+  Offset = Calc(BO_Add, *Offset, *Delta);
+  if (!Offset)
+return std::nullopt;
+ 

[clang] [clang][AArch64] Pass down stack clash protection options to LLVM/Backend (PR #68993)

2023-10-13 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov created 
https://github.com/llvm/llvm-project/pull/68993

None

>From 870650ae6e2c5b7f34c4d0b1572c5f6a88b6e9b6 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Mon, 2 Oct 2023 14:46:27 +0100
Subject: [PATCH 1/2] [CFIFixup] Allow function prologues to span more than one
 basic block

The CFIFixup pass assumes a function prologue is contained in a single
basic block. This assumption is broken with upcoming support for stack
probing (`-fstack-clash-protection`) in AArch64 - the emitted probing
sequence in a prologue may contain loops, i.e. more than one basic
block. The generated CFG is not arbitrary though:
 * CFI instructions are outside of any loops
 * for any two CFI instructions of the function prologue one dominates
   and is post-dominated by the other

Thus, for the prologue CFI instructions, if one is
executed then all are executed, there is a total order of
executions, and the last instruction in that order can be considered
the end of the prologoue for the purpose of inserting the initial
`.cfi_remember_state` directive.

That last instruction is found by finding the first block in the
post-order traversal which contains prologue CFI instructions.
---
 llvm/lib/CodeGen/CFIFixup.cpp |  62 ++--
 .../cfi-fixup-multi-block-prologue.mir| 308 ++
 2 files changed, 347 insertions(+), 23 deletions(-)
 create mode 100644 llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir

diff --git a/llvm/lib/CodeGen/CFIFixup.cpp b/llvm/lib/CodeGen/CFIFixup.cpp
index 837dbd77d07361a..964a8d56511fa1b 100644
--- a/llvm/lib/CodeGen/CFIFixup.cpp
+++ b/llvm/lib/CodeGen/CFIFixup.cpp
@@ -10,20 +10,25 @@
 // This pass inserts the necessary  instructions to adjust for the 
inconsistency
 // of the call-frame information caused by final machine basic block layout.
 // The pass relies in constraints LLVM imposes on the placement of
-// save/restore points (cf. ShrinkWrap):
-// * there is a single basic block, containing the function prologue
+// save/restore points (cf. ShrinkWrap) and has certain preconditions about
+// placement of CFI instructions:
+// * for any two CFI instructions of the function prologue one dominates
+//   and is post-dominated by the other
 // * possibly multiple epilogue blocks, where each epilogue block is
 //   complete and self-contained, i.e. CSR restore instructions (and the
 //   corresponding CFI instructions are not split across two or more blocks.
-// * prologue and epilogue blocks are outside of any loops
-// Thus, during execution, at the beginning and at the end of each basic block
-// the function can be in one of two states:
+// * CFI instructions are not contained in any loops
+// Thus, during execution, at the beginning and at the end of each basic block,
+// following the prologue, the function can be in one of two states:
 //  - "has a call frame", if the function has executed the prologue, and
 //has not executed any epilogue
 //  - "does not have a call frame", if the function has not executed the
 //prologue, or has executed an epilogue
 // which can be computed by a single RPO traversal.
 
+// The location of the prologue is determined by finding the first block in the
+// post-order traversal which contains CFI instructions.
+
 // In order to accommodate backends which do not generate unwind info in
 // epilogues we compute an additional property "strong no call frame on entry",
 // which is set for the entry point of the function and for every block
@@ -85,10 +90,6 @@ static bool isPrologueCFIInstruction(const MachineInstr &MI) 
{
  MI.getFlag(MachineInstr::FrameSetup);
 }
 
-static bool containsPrologue(const MachineBasicBlock &MBB) {
-  return llvm::any_of(MBB.instrs(), isPrologueCFIInstruction);
-}
-
 static bool containsEpilogue(const MachineBasicBlock &MBB) {
   return llvm::any_of(llvm::reverse(MBB), [](const auto &MI) {
 return MI.getOpcode() == TargetOpcode::CFI_INSTRUCTION &&
@@ -96,6 +97,25 @@ static bool containsEpilogue(const MachineBasicBlock &MBB) {
   });
 }
 
+static MachineBasicBlock *
+findPrologueEnd(MachineFunction &MF, MachineBasicBlock::iterator &PrologueEnd) 
{
+  MachineBasicBlock *PrologueBlock = nullptr;
+  for (auto It = po_begin(&MF.front()), End = po_end(&MF.front()); It != End;
+   ++It) {
+MachineBasicBlock *MBB = *It;
+llvm::for_each(MBB->instrs(), [&](MachineInstr &MI) {
+  if (isPrologueCFIInstruction(MI)) {
+PrologueBlock = MBB;
+PrologueEnd = std::next(MI.getIterator());
+  }
+});
+if (PrologueBlock)
+  return PrologueBlock;
+  }
+
+  return nullptr;
+}
+
 bool CFIFixup::runOnMachineFunction(MachineFunction &MF) {
   const TargetFrameLowering &TFL = *MF.getSubtarget().getFrameLowering();
   if (!TFL.enableCFIFixup(MF))
@@ -105,6 +125,14 @@ bool CFIFixup::runOnMachineFunction(MachineFunction &MF) {
   if (NumBlocks < 2)
 return false;
 
+  // Find the prologue and the point where we can issu

  1   2   3   >