[clang] [Clang][NFCI] Slightly refactor getTemplateInstantiationArgs() (PR #102922)

2024-08-31 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Superseded by https://github.com/llvm/llvm-project/pull/106585.

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


[clang] [Clang][NFCI] Slightly refactor getTemplateInstantiationArgs() (PR #102922)

2024-08-31 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] [NFC][clang-tidy] fix tests of deleted functions for missing-std-forward (PR #106861)

2024-08-31 Thread via cfe-commits

llvmbot wrote:




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

Author: Julian Schmidt (5chmidti)


Changes

Since #87832, unnamed identifiers are excluded from being diagnosed. As
a result, the tests that were supposed to test that deleted functions
are correctly ignored are ignored because of the unnamed identifiers
instead of the deleted function. This change simply introduces names for
the parameters of the deleted functions.


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


1 Files Affected:

- (modified) 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 (+3-3) 


``diff
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
index 8116db58c937d4..98c592db7ce226 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
@@ -187,14 +187,14 @@ void lambda_value_reference_auxiliary_var(T&& t) {
 namespace deleted_functions {
 
 template 
-void f(T &&) = delete;
+void f(T &&t) = delete;
 
 struct S {
 template 
-S(T &&) = delete;
+S(T &&t) = delete;
 
 template 
-void operator&(T &&) = delete;
+void operator&(T &&t) = delete;
 };
 
 } // namespace deleted_functions

``




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


[clang] [clang][ASTImporter] New fix for default template parameter values. (PR #101836)

2024-08-31 Thread Matheus Izvekov via cfe-commits
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 



@@ -5968,11 +5962,21 @@ 
ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   }
 
   if (D->hasDefaultArgument()) {
+// Default argument can be "inherited" when it has a reference to the
+// previous declaration (of the default argument) which is stored only 
once.
+// Here we import the default argument in any case, and the inherited state
+// is updated later after the parent template was created. If the
+// inherited-from object would be imported here it causes more difficulties
+// (parent template may not be created yet and import loops can occur).
 Expected ToDefaultArgOrErr =
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
+// The just called import process can trigger import of the parent template
+// which can update the default argument value to "inherited". This should
+// not be changed.
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);

mizvekov wrote:

Thanks. I think this moved in a better direction.

At least this way, the AST is correct for simple reserialization, whereas as 
before it was incorrect for that as well.

The new problems are related to merging of definitions. We ought to implement a 
mechanism to merge default argument definitions here the same way we merge 
function definitions and such.

For your first example: `template  struct X;` Here is one idea: this 
should be treated as a definition and merged, and any differences would be an 
ODR violation.

In particular, merging two modules each containing:
```C++
template  struct X;
```
and
```C++
template  struct X;
```
Because the declaration containing a default argument definition differs, this 
would be an ODR violation.

I'd be happy to leave solving that problem for a future patch.

For your second example, `X` would already be merged, so I am not sure there is 
a problem there. So we may end up with getInheritedFrom pointing to a 
definition which was not chosen as the merged definition, but I believe we keep 
track of the merged definitions in the ASTContext, so we can make sense of the 
situation.

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


[clang] [llvm] [HLSL] AST support for WaveSize attribute. (PR #101240)

2024-08-31 Thread Xiang Li via cfe-commits

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


[clang] [HLSL][Docs] Update function calls docs (PR #106860)

2024-08-31 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang

Author: Chris B (llvm-beanz)


Changes

Update the function calls documentation to match the newly landed 
implementation.

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


1 Files Affected:

- (modified) clang/docs/HLSL/FunctionCalls.rst (+60-35) 


``diff
diff --git a/clang/docs/HLSL/FunctionCalls.rst 
b/clang/docs/HLSL/FunctionCalls.rst
index 6d65fe6e3fb20b..ea6dc2ad8a4df8 100644
--- a/clang/docs/HLSL/FunctionCalls.rst
+++ b/clang/docs/HLSL/FunctionCalls.rst
@@ -248,13 +248,14 @@ which is a term made up for HLSL. A cx-value is a 
temporary value which may be
 the result of a cast, and stores its value back to an lvalue when the value
 expires.
 
-To represent this concept in Clang we introduce a new ``HLSLOutParamExpr``. An
-``HLSLOutParamExpr`` has two forms, one with a single sub-expression and one
-with two sub-expressions.
+To represent this concept in Clang we introduce a new ``HLSLOutArgExpr``. An
+``HLSLOutArgExpr`` has three sub-expressions:
 
-The single sub-expression form is used when the argument expression and the
-function parameter are the same type, so no cast is required. As in this
-example:
+* An OpaqueValueExpr of the argument lvalue expression.
+* An OpaqueValueExpr of the copy-initialized parameter temporary.
+* A BinaryOpExpr assigning the first with the value of the second.
+
+Given this example:
 
 .. code-block:: c++
 
@@ -267,23 +268,36 @@ example:
 Init(V);
   }
 
-The expected AST formulation for this code would be something like:
+The expected AST formulation for this code would be something like the example
+below. Due to the nature of OpaqueValueExpr nodes, the nodes repeat in the AST
+dump. The fake addresses ``0xSOURCE`` and ``0xTEMPORARY`` denote the source
+lvalue and argument temporary lvalue expressions.
 
 .. code-block:: text
 
   CallExpr 'void'
   |-ImplicitCastExpr 'void (*)(int &)' 
   | `-DeclRefExpr 'void (int &)' lvalue Function  'Init' 'void (int &)'
-  |-HLSLOutParamExpr 'int' lvalue inout
-`-DeclRefExpr 'int' lvalue Var 'V' 'int'
-
-The ``HLSLOutParamExpr`` captures that the value is ``inout`` vs ``out`` to
-denote whether or not the temporary is initialized from the sub-expression. If
-no casting is required the sub-expression denotes the lvalue expression that 
the
-cx-value will be copied to when the value expires.
-
-The two sub-expression form of the AST node is required when the argument type
-is not the same as the parameter type. Given this example:
+  `-HLSLOutArgExpr  'int' lvalue inout
+|-OpaqueValueExpr 0xSOURCE  'int' lvalue
+| `-DeclRefExpr  'int' lvalue Var 'V' 'int'
+|-OpaqueValueExpr 0xTEMPORARY  'int' lvalue
+| `-ImplicitCastExpr  'int' 
+|   `-OpaqueValueExpr 0xSOURCE  'int' lvalue
+| `-DeclRefExpr  'int' lvalue Var 'V' 'int'
+`-BinaryOperator  'int' lvalue '='
+  |-OpaqueValueExpr 0xSOURCE  'int' lvalue
+  | `-DeclRefExpr  'int' lvalue Var 'V' 'int'
+  `-ImplicitCastExpr  'int' 
+`-OpaqueValueExpr 0xTEMPORARY  'int' lvalue
+  `-ImplicitCastExpr  'int' 
+`-OpaqueValueExpr 0xSOURCE  'int' lvalue
+  `-DeclRefExpr  'int' lvalue Var 'V' 'int'
+
+The ``HLSLOutArgExpr`` captures that the value is ``inout`` vs ``out`` to
+denote whether or not the temporary is initialized from the sub-expression.
+
+The example below demonstrates argument casting:
 
 .. code-block:: c++
 
@@ -295,7 +309,7 @@ is not the same as the parameter type. Given this example:
 Trunc(F);
   }
 
-For this case the ``HLSLOutParamExpr`` will have sub-expressions to record both
+For this case the ``HLSLOutArgExpr`` will have sub-expressions to record both
 casting expression sequences for the initialization and write back:
 
 .. code-block:: text
@@ -303,20 +317,31 @@ casting expression sequences for the initialization and 
write back:
   -CallExpr 'void'
 |-ImplicitCastExpr 'void (*)(int3 &)' 
 | `-DeclRefExpr 'void (int3 &)' lvalue Function 'inc_i32' 'void (int3 &)'
-`-HLSLOutParamExpr 'int3' lvalue inout
-  |-ImplicitCastExpr 'float3' 
-  | `-ImplicitCastExpr 'int3' 
-  |   `-OpaqueValueExpr 'int3' lvalue
-  `-ImplicitCastExpr 'int3' 
-`-ImplicitCastExpr 'float3' 
-  `-DeclRefExpr 'float3' lvalue 'F' 'float3'
-
-In this formation the write-back casts are captured as the first sub-expression
-and they cast from an ``OpaqueValueExpr``. In IR generation we can use the
-``OpaqueValueExpr`` as a placeholder for the ``HLSLOutParamExpr``'s temporary
-value on function return.
-
-In code generation this can be implemented with some targeted extensions to the
-Objective-C write-back support. Specifically extending CGCall.cpp's
-``EmitWriteback`` function to support casting expressions and emission of
-aggregate lvalues.
+`-HLSLOutArgExpr  'int3':'vector' lvalue inout
+  |-OpaqueValueExpr 0xSOURCE  'float3':'vector' lvalue
+  | `

[clang] [Clang][Parser] Fix name lookup of template parameters for out-of-line specializations (PR #101020)

2024-08-31 Thread via cfe-commits

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

LGTM

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


[clang] [Clang][Sema] Refactor collection of multi-level template argument lists (PR #106585)

2024-08-31 Thread Younan Zhang via cfe-commits


@@ -33,11 +33,12 @@ class D{}; // expected-note{{previous definition is here}}
 template
 class D{}; // expected-error{{class template partial specialization does 
not specialize any template argument; to define the primary template, remove 
the template argument list}} expected-error{{redefinition of 'D'}}
 
-template requires C1 // expected-note{{previous template 
declaration is here}}
-class E{};
+template requires C1
+class E{}; // expected-note{{previous definition is here}}
 
-template // expected-error{{requires clause differs in template 
redeclaration}}
+template

zyn0217 wrote:

Hmm, it looks like only we would diagnose an additional `requires clause 
differs` error.

https://gcc.godbolt.org/z/6doaeMEr3

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


[clang] [Clang][Parser] Fix name lookup of template parameters for out-of-line specializations (PR #101020)

2024-08-31 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Thanks for the review :)

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


[clang] 4f4bd41 - [NFC] Fix typos (#106817)

2024-08-31 Thread via cfe-commits

Author: c8ef
Date: 2024-08-31T19:12:57-07:00
New Revision: 4f4bd41f7098af51c3ba2e62cc635e3c45c294d4

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

LOG: [NFC] Fix typos (#106817)

Fixes #106761.

Added: 


Modified: 
clang/lib/Tooling/Refactoring/AtomicChange.cpp
clang/tools/clang-format/ClangFormat.cpp
clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py
llvm/examples/ExceptionDemo/ExceptionDemo.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Refactoring/AtomicChange.cpp 
b/clang/lib/Tooling/Refactoring/AtomicChange.cpp
index dfc98355c6642b..5bafe43aa92d6f 100644
--- a/clang/lib/Tooling/Refactoring/AtomicChange.cpp
+++ b/clang/lib/Tooling/Refactoring/AtomicChange.cpp
@@ -104,9 +104,9 @@ bool violatesColumnLimit(llvm::StringRef Code, unsigned 
ColumnLimit,
 }
 
 std::vector
-getRangesForFormating(llvm::StringRef Code, unsigned ColumnLimit,
-  ApplyChangesSpec::FormatOption Format,
-  const clang::tooling::Replacements &Replaces) {
+getRangesForFormatting(llvm::StringRef Code, unsigned ColumnLimit,
+   ApplyChangesSpec::FormatOption Format,
+   const clang::tooling::Replacements &Replaces) {
   // kNone suppresses formatting entirely.
   if (Format == ApplyChangesSpec::kNone)
 return {};
@@ -352,7 +352,7 @@ applyAtomicChanges(llvm::StringRef FilePath, 
llvm::StringRef Code,
 
   AllReplaces = AllReplaces.merge(HeaderSortingReplacements);
 
-  std::vector FormatRanges = getRangesForFormating(
+  std::vector FormatRanges = getRangesForFormatting(
   *ChangedCode, Spec.Style.ColumnLimit, Spec.Format, AllReplaces);
   if (!FormatRanges.empty()) {
 Replacements FormatReplacements =

diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 54b1dacbbe854a..6aed46328f3469 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -703,7 +703,7 @@ int main(int argc, const char **argv) {
   FileNames.push_back(Line);
   LineNo++;
 }
-errs() << "Clang-formating " << LineNo << " files\n";
+errs() << "Clang-formatting " << LineNo << " files\n";
   }
 
   if (FileNames.empty())

diff  --git 
a/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py 
b/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py
index 1675be3dc963d5..03f0da4ac6de30 100644
--- a/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py
+++ b/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py
@@ -121,7 +121,7 @@ def test_append_to_existing_cdb(self):
 self.assertEqual(5, self.count_entries(result))
 
 
-class ResultFormatingTest(unittest.TestCase):
+class ResultFormattingTest(unittest.TestCase):
 @staticmethod
 def run_intercept(tmpdir, command):
 result = os.path.join(tmpdir, "cdb.json")

diff  --git a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp 
b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
index 27acb9a155ecd8..58367a2319981d 100644
--- a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
+++ b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
@@ -879,7 +879,6 @@ void generateStringPrint(llvm::LLVMContext &context,
   builder.CreateCall(printFunct, cast);
 }
 
-
 /// Generates code to print given runtime integer according to constant
 /// string format, and a given print function.
 /// @param context llvm context
@@ -887,7 +886,7 @@ void generateStringPrint(llvm::LLVMContext &context,
 /// @param builder builder instance
 /// @param printFunct function used to "print" integer
 /// @param toPrint string to print
-/// @param format printf like formating string for print
+/// @param format printf like formatting string for print
 /// @param useGlobal A value of true (default) indicates a GlobalValue is
 ///generated, and is used to hold the constant string. A value of
 ///false indicates that the constant string will be stored on the



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


[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-31 Thread Balazs Benics via cfe-commits

https://github.com/steakhal commented:

Looks really good. I only had some notes w.r.t. note tags.

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


[clang] [clang] function template non-call partial ordering fixes (PR #106829)

2024-08-31 Thread via cfe-commits


@@ -5635,123 +5627,95 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
 
   assert(Proto1 && Proto2 && "Function templates must have prototypes");
   TemplateParameterList *TemplateParams = FT2->getTemplateParameters();
-  SmallVector Deduced;
-  Deduced.resize(TemplateParams->size());
+  SmallVector Deduced(TemplateParams->size());
 
-  // C++0x [temp.deduct.partial]p3:
-  //   The types used to determine the ordering depend on the context in which
-  //   the partial ordering is done:
   TemplateDeductionInfo Info(Loc);
-  switch (TPOC) {
-  case TPOC_Call: {
-llvm::SmallBitVector HasDeducedParam(Args2.size());
-if (DeduceTemplateArguments(
-S, TemplateParams, Args2.data(), Args2.size(), Args1.data(),
-Args1.size(), Info, Deduced, TDF_None, /*PartialOrdering=*/true,
-/*HasDeducedAnyParam=*/nullptr,
-&HasDeducedParam) != TemplateDeductionResult::Success)
-  return false;
+  if (TPOC == TPOC_Other) {
+// We wouldn't be partial ordering these candidates if these didn't match.
+assert(Proto2->getMethodQuals() == Proto1->getMethodQuals());
+assert(Proto2->getRefQualifier() == Proto1->getRefQualifier());
+assert(Proto2->isVariadic() == Proto1->isVariadic());
 
-SmallVector DeducedArgs(Deduced.begin(),
- Deduced.end());
-Sema::InstantiatingTemplate Inst(
-S, Info.getLocation(), FT2, DeducedArgs,
-Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
-if (Inst.isInvalid())
-  return false;
-
-bool AtLeastAsSpecialized = true;
-S.runWithSufficientStackSpace(Info.getLocation(), [&] {
-  AtLeastAsSpecialized =
-  ::FinishTemplateArgumentDeduction(
-  S, FT2, Deduced, Info,
-  [&](Sema &S, FunctionTemplateDecl *FTD,
-  ArrayRef DeducedArgs) {
-return ::DeduceForEachType(
-S, TemplateParams, Args2.data(), Args2.size(), 
Args1.data(),
-Args1.size(), Info, Deduced,
-/*PartialOrdering=*/true, /*FinishingDeduction=*/true,
-[&](Sema &S, TemplateParameterList *, int ParamIdx,
-int ArgIdx, QualType P, QualType A,
-TemplateDeductionInfo &Info,
-SmallVectorImpl &Deduced,
-bool) {
-  // As a provisional fix for a core issue that does not
-  // exist yet, only check the consistency of parameters
-  // which participated in deduction. We still try to
-  // substitute them though.
-  return ::CheckDeductionConsistency(
-  S, FTD, ArgIdx, P, A, DeducedArgs,
-  HasDeducedParam[ParamIdx]);
-});
-  }) == TemplateDeductionResult::Success;
-});
-if (!AtLeastAsSpecialized)
-  return false;
-  } break;
-  case TPOC_Conversion:
-  case TPOC_Other: {
-//   - In the context of a call to a conversion operator, the return types
-// of the conversion function templates are used.
-//   - In other contexts (14.6.6.2) the function template's function type
-// is used.
-auto [A, P, TDF] = TPOC == TPOC_Other
-   ? std::make_tuple(FD1->getType(), FD2->getType(),
- TDF_AllowCompatibleFunctionType)
-   : std::make_tuple(Proto1->getReturnType(),
- Proto2->getReturnType(), 
TDF_None);
+assert(Args1.empty() && Args2.empty());
+Args1 = Proto1->getParamTypes();
+Args2 = Proto2->getParamTypes();

cor3ntin wrote:

Can you add a comment explaining that we don't have arguments when taking the 
address of a function template. I'm not sure it would be immediately obvious

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


[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
2f4232db0b72635b89c2356c8a2c0504b075a0ab...3945829650ac41f587c161cd6fb505225efba379
 clang-tools-extra/clang-tidy/add_new_check.py
``





View the diff from darker here.


``diff
--- add_new_check.py2024-08-31 17:40:17.00 +
+++ add_new_check.py2024-08-31 17:44:12.662214 +
@@ -13,10 +13,11 @@
 import itertools
 import os
 import re
 import sys
 import textwrap
+
 # FIXME Python 3.9: Replace typing.Tuple with builtins.tuple.
 from typing import Optional, Tuple
 
 
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new

``




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


[clang] [llvm] [Chore] Fix `formating` typos. NFC. (PR #106817)

2024-08-31 Thread via cfe-commits

c8ef wrote:

Hi, could you please take a look? @owenca 

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


[clang] [analyzer] [MallocChecker] suspect all release functions as candite for supression (PR #104599)

2024-08-31 Thread Pavel Skripkin via cfe-commits

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


[clang-tools-extra] [NFC][clang-tidy] reword diagnostic note in definitions-in-headers (PR #106862)

2024-08-31 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/106862

>From 46704590d3a90518c7b58ce03ac29c3e65c26676 Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 31 Aug 2024 18:44:37 +0200
Subject: [PATCH 1/3] [NFC][clang-tidy] reword diagnostic note in
 definitions-in-headers

`make as inline` made little sense here, so I changed the `make` to `mark`
and added `the definition` as well.
---
 clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index 21008bc144b91a..ee869256898989 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -102,7 +102,7 @@ void DefinitionsInHeadersCheck::check(const 
MatchFinder::MatchResult &Result) {
 // inline is not allowed for main function.
 if (FD->isMain())
   return;
-diag(FD->getLocation(), /*Description=*/"make as 'inline'",
+diag(FD->getLocation(), "mark the definition as 'inline'",
  DiagnosticIDs::Note)
 << FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
   } else if (const auto *VD = dyn_cast(ND)) {

>From 06ceb5c03be3e0d0b8886b075cbc1761093178ae Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 31 Aug 2024 20:45:58 +0200
Subject: [PATCH 2/3] update tests

---
 .../test/clang-tidy/checkers/misc/definitions-in-headers.hpp| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
index 4cf07077a230a5..9c91cb7033087d 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
@@ -2,7 +2,7 @@
 
 int f() {
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f' defined in a header 
file; function definitions in header files can lead to ODR violations 
[misc-definitions-in-headers]
-// CHECK-MESSAGES: :[[@LINE-2]]:5: note: make as 'inline'
+// CHECK-MESSAGES: :[[@LINE-2]]:5: note: mark the definition as 'inline'
 // CHECK-FIXES: inline int f() {
   return 1;
 }

>From b3f8dc2e7396e086155045b3c98c1411bfc0368c Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 31 Aug 2024 20:48:13 +0200
Subject: [PATCH 3/3] add release note entry

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

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b001a6ad446695..a4cdfa3c1175d0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -104,6 +104,10 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`misc-definitions-in-headers
+  ` check by rewording the
+  diagnostic note that suggests adding ``inline``.
+
 - Improved :doc:`modernize-use-std-format
   ` check to support replacing
   member function calls too.

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


[clang] [analyzer] [MallocChecker] suspect all release functions as candite for supression (PR #104599)

2024-08-31 Thread Pavel Skripkin via cfe-commits

https://github.com/pskrgag updated 
https://github.com/llvm/llvm-project/pull/104599

>From 913036ab795d6b91d6bb74d82aa2d329fe689535 Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Fri, 16 Aug 2024 17:45:57 +0300
Subject: [PATCH 1/3] clang/csa: suspect all functions as those that may do
 refcount release

---
 .../StaticAnalyzer/Checkers/MallocChecker.cpp | 57 ++---
 clang/test/Analysis/malloc-refcounted.c   | 80 +++
 2 files changed, 110 insertions(+), 27 deletions(-)
 create mode 100644 clang/test/Analysis/malloc-refcounted.c

diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 3ddcb7e94ae5d6..77b9913a904700 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -904,16 +904,16 @@ class MallocBugVisitor final : public BugReporterVisitor {
   // A symbol from when the primary region should have been reallocated.
   SymbolRef FailedReallocSymbol;
 
-  // A C++ destructor stack frame in which memory was released. Used for
+  // A release function stack frame in which memory was released. Used for
   // miscellaneous false positive suppression.
-  const StackFrameContext *ReleaseDestructorLC;
+  const StackFrameContext *ReleaseFunctionLC;
 
   bool IsLeak;
 
 public:
   MallocBugVisitor(SymbolRef S, bool isLeak = false)
   : Sym(S), Mode(Normal), FailedReallocSymbol(nullptr),
-ReleaseDestructorLC(nullptr), IsLeak(isLeak) {}
+ReleaseFunctionLC(nullptr), IsLeak(isLeak) {}
 
   static void *getTag() {
 static int Tag = 0;
@@ -3558,8 +3558,8 @@ PathDiagnosticPieceRef MallocBugVisitor::VisitNode(const 
ExplodedNode *N,
   // original reference count is positive, we should not report use-after-frees
   // on objects deleted in such destructors. This can probably be improved
   // through better shared pointer modeling.
-  if (ReleaseDestructorLC && (ReleaseDestructorLC == CurrentLC ||
-  ReleaseDestructorLC->isParentOf(CurrentLC))) {
+  if (ReleaseFunctionLC && (ReleaseFunctionLC == CurrentLC ||
+ReleaseFunctionLC->isParentOf(CurrentLC))) {
 if (const auto *AE = dyn_cast(S)) {
   // Check for manual use of atomic builtins.
   AtomicExpr::AtomicOp Op = AE->getOp();
@@ -3648,35 +3648,38 @@ PathDiagnosticPieceRef 
MallocBugVisitor::VisitNode(const ExplodedNode *N,
   return nullptr;
 }
 
-  // See if we're releasing memory while inlining a destructor
-  // (or one of its callees). This turns on various common
-  // false positive suppressions.
-  bool FoundAnyDestructor = false;
-  for (const LocationContext *LC = CurrentLC; LC; LC = LC->getParent()) {
-if (const auto *DD = dyn_cast(LC->getDecl())) {
-  if (isReferenceCountingPointerDestructor(DD)) {
-// This immediately looks like a reference-counting destructor.
-// We're bad at guessing the original reference count of the 
object,
-// so suppress the report for now.
-BR.markInvalid(getTag(), DD);
-  } else if (!FoundAnyDestructor) {
-assert(!ReleaseDestructorLC &&
+// See if we're releasing memory while inlining a destructor or
+// functions that decrement reference counters (or one of its callees).
+// This turns on various common false positive suppressions.
+bool FoundAnyReleaseFunction = false;
+for (const LocationContext *LC = CurrentLC; LC; LC = LC->getParent()) {
+  if (const auto *DD = dyn_cast(LC->getDecl())) {
+if (isReferenceCountingPointerDestructor(DD)) {
+  // This immediately looks like a reference-counting destructor.
+  // We're bad at guessing the original reference count of the
+  // object, so suppress the report for now.
+  BR.markInvalid(getTag(), DD);
+  continue;
+}
+  }
+
+  if (!FoundAnyReleaseFunction) {
+assert(!ReleaseFunctionLC &&
"There can be only one release point!");
-// Suspect that it's a reference counting pointer destructor.
-// On one of the next nodes might find out that it has atomic
-// reference counting operations within it (see the code above),
-// and if so, we'd conclude that it likely is a reference counting
-// pointer destructor.
-ReleaseDestructorLC = LC->getStackFrame();
+// Suspect that it's a reference counting pointer
+// destructor/function. On one of the next nodes might find out 
that
+// it has atomic reference counting operations within it (see the
+// code above), and if so, we'd conclude that it likely is a
+// reference counting pointer destructor.
+ReleaseFunctionLC = LC->getStackFrame();
   

[clang] [clang][ASTImporter] New fix for default template parameter values. (PR #101836)

2024-08-31 Thread Matheus Izvekov via cfe-commits
=?utf-8?q?Bal=C3=A1zs_K=C3=A9ri?= ,
=?utf-8?q?Bal=C3=A1zs_K=C3=A9ri?= 
Message-ID:
In-Reply-To: 


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

LGTM

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


[clang-tools-extra] [NFC][clang-tidy] fix tests of deleted functions for missing-std-forward (PR #106861)

2024-08-31 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] [NFC][clang-tidy] reword diagnostic note in definitions-in-headers (PR #106862)

2024-08-31 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/106862

>From 46704590d3a90518c7b58ce03ac29c3e65c26676 Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 31 Aug 2024 18:44:37 +0200
Subject: [PATCH 1/2] [NFC][clang-tidy] reword diagnostic note in
 definitions-in-headers

`make as inline` made little sense here, so I changed the `make` to `mark`
and added `the definition` as well.
---
 clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index 21008bc144b91a..ee869256898989 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -102,7 +102,7 @@ void DefinitionsInHeadersCheck::check(const 
MatchFinder::MatchResult &Result) {
 // inline is not allowed for main function.
 if (FD->isMain())
   return;
-diag(FD->getLocation(), /*Description=*/"make as 'inline'",
+diag(FD->getLocation(), "mark the definition as 'inline'",
  DiagnosticIDs::Note)
 << FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
   } else if (const auto *VD = dyn_cast(ND)) {

>From 06ceb5c03be3e0d0b8886b075cbc1761093178ae Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 31 Aug 2024 20:45:58 +0200
Subject: [PATCH 2/2] update tests

---
 .../test/clang-tidy/checkers/misc/definitions-in-headers.hpp| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
index 4cf07077a230a5..9c91cb7033087d 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
@@ -2,7 +2,7 @@
 
 int f() {
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f' defined in a header 
file; function definitions in header files can lead to ODR violations 
[misc-definitions-in-headers]
-// CHECK-MESSAGES: :[[@LINE-2]]:5: note: make as 'inline'
+// CHECK-MESSAGES: :[[@LINE-2]]:5: note: mark the definition as 'inline'
 // CHECK-FIXES: inline int f() {
   return 1;
 }

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


[clang] [llvm] [Chore] Fix `formating` typos. NFC. (PR #106817)

2024-08-31 Thread Owen Pan via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread Nicolas van Kempen via cfe-commits

nicovank wrote:

Thanks for review! Addressed comments.

I have no commit access, if/when this looks good to go you can go ahead and 
click merge.

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


[clang] [Clang][Concepts] Fix a constraint comparison regression for out-of-line ClassTemplateDecls (PR #102587)

2024-08-31 Thread Younan Zhang via cfe-commits

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


[clang] [HLSL][Docs] Update function calls docs (PR #106860)

2024-08-31 Thread Chris B via cfe-commits

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

Update the function calls documentation to match the newly landed 
implementation.

>From f3ee9f197eced0f7496c611f09dd684d84325f26 Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Sat, 31 Aug 2024 11:16:28 -0500
Subject: [PATCH] [HLSL][Docs] Update function calls docs

Update the function calls documentation to match the newly landed
implementation.
---
 clang/docs/HLSL/FunctionCalls.rst | 95 +++
 1 file changed, 60 insertions(+), 35 deletions(-)

diff --git a/clang/docs/HLSL/FunctionCalls.rst 
b/clang/docs/HLSL/FunctionCalls.rst
index 6d65fe6e3fb20b..ea6dc2ad8a4df8 100644
--- a/clang/docs/HLSL/FunctionCalls.rst
+++ b/clang/docs/HLSL/FunctionCalls.rst
@@ -248,13 +248,14 @@ which is a term made up for HLSL. A cx-value is a 
temporary value which may be
 the result of a cast, and stores its value back to an lvalue when the value
 expires.
 
-To represent this concept in Clang we introduce a new ``HLSLOutParamExpr``. An
-``HLSLOutParamExpr`` has two forms, one with a single sub-expression and one
-with two sub-expressions.
+To represent this concept in Clang we introduce a new ``HLSLOutArgExpr``. An
+``HLSLOutArgExpr`` has three sub-expressions:
 
-The single sub-expression form is used when the argument expression and the
-function parameter are the same type, so no cast is required. As in this
-example:
+* An OpaqueValueExpr of the argument lvalue expression.
+* An OpaqueValueExpr of the copy-initialized parameter temporary.
+* A BinaryOpExpr assigning the first with the value of the second.
+
+Given this example:
 
 .. code-block:: c++
 
@@ -267,23 +268,36 @@ example:
 Init(V);
   }
 
-The expected AST formulation for this code would be something like:
+The expected AST formulation for this code would be something like the example
+below. Due to the nature of OpaqueValueExpr nodes, the nodes repeat in the AST
+dump. The fake addresses ``0xSOURCE`` and ``0xTEMPORARY`` denote the source
+lvalue and argument temporary lvalue expressions.
 
 .. code-block:: text
 
   CallExpr 'void'
   |-ImplicitCastExpr 'void (*)(int &)' 
   | `-DeclRefExpr 'void (int &)' lvalue Function  'Init' 'void (int &)'
-  |-HLSLOutParamExpr 'int' lvalue inout
-`-DeclRefExpr 'int' lvalue Var 'V' 'int'
-
-The ``HLSLOutParamExpr`` captures that the value is ``inout`` vs ``out`` to
-denote whether or not the temporary is initialized from the sub-expression. If
-no casting is required the sub-expression denotes the lvalue expression that 
the
-cx-value will be copied to when the value expires.
-
-The two sub-expression form of the AST node is required when the argument type
-is not the same as the parameter type. Given this example:
+  `-HLSLOutArgExpr  'int' lvalue inout
+|-OpaqueValueExpr 0xSOURCE  'int' lvalue
+| `-DeclRefExpr  'int' lvalue Var 'V' 'int'
+|-OpaqueValueExpr 0xTEMPORARY  'int' lvalue
+| `-ImplicitCastExpr  'int' 
+|   `-OpaqueValueExpr 0xSOURCE  'int' lvalue
+| `-DeclRefExpr  'int' lvalue Var 'V' 'int'
+`-BinaryOperator  'int' lvalue '='
+  |-OpaqueValueExpr 0xSOURCE  'int' lvalue
+  | `-DeclRefExpr  'int' lvalue Var 'V' 'int'
+  `-ImplicitCastExpr  'int' 
+`-OpaqueValueExpr 0xTEMPORARY  'int' lvalue
+  `-ImplicitCastExpr  'int' 
+`-OpaqueValueExpr 0xSOURCE  'int' lvalue
+  `-DeclRefExpr  'int' lvalue Var 'V' 'int'
+
+The ``HLSLOutArgExpr`` captures that the value is ``inout`` vs ``out`` to
+denote whether or not the temporary is initialized from the sub-expression.
+
+The example below demonstrates argument casting:
 
 .. code-block:: c++
 
@@ -295,7 +309,7 @@ is not the same as the parameter type. Given this example:
 Trunc(F);
   }
 
-For this case the ``HLSLOutParamExpr`` will have sub-expressions to record both
+For this case the ``HLSLOutArgExpr`` will have sub-expressions to record both
 casting expression sequences for the initialization and write back:
 
 .. code-block:: text
@@ -303,20 +317,31 @@ casting expression sequences for the initialization and 
write back:
   -CallExpr 'void'
 |-ImplicitCastExpr 'void (*)(int3 &)' 
 | `-DeclRefExpr 'void (int3 &)' lvalue Function 'inc_i32' 'void (int3 &)'
-`-HLSLOutParamExpr 'int3' lvalue inout
-  |-ImplicitCastExpr 'float3' 
-  | `-ImplicitCastExpr 'int3' 
-  |   `-OpaqueValueExpr 'int3' lvalue
-  `-ImplicitCastExpr 'int3' 
-`-ImplicitCastExpr 'float3' 
-  `-DeclRefExpr 'float3' lvalue 'F' 'float3'
-
-In this formation the write-back casts are captured as the first sub-expression
-and they cast from an ``OpaqueValueExpr``. In IR generation we can use the
-``OpaqueValueExpr`` as a placeholder for the ``HLSLOutParamExpr``'s temporary
-value on function return.
-
-In code generation this can be implemented with some targeted extensions to the
-Objective-C write-back support. Specifically extending CGCall.cpp's
-``Em

[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank updated 
https://github.com/llvm/llvm-project/pull/106801

>From 3945829650ac41f587c161cd6fb505225efba379 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Sat, 31 Aug 2024 13:40:14 -0400
Subject: [PATCH] [clang-tidy] Add type annotations to add_new_check.py, fix
 minor bug

```
> python3 -m mypy --strict clang-tools-extra/clang-tidy/add_new_check.py
Success: no issues found in 1 source file
```

Also fix a bug when `--standard` is not provided on the command line: the
generated test case has a `None` causing issues:
```
> python3 clang-tools-extra/clang-tidy/add_new_check.py performance XXX
Updating clang-tools-extra/clang-tidy/performance/CMakeLists.txt...
Creating clang-tools-extra/clang-tidy/performance/XxxCheck.h...
Creating clang-tools-extra/clang-tidy/performance/XxxCheck.cpp...
Updating clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp...
Updating clang-tools-extra/docs/ReleaseNotes.rst...
Creating clang-tools-extra/test/clang-tidy/checkers/performance/XXX.cpp...
Creating clang-tools-extra/docs/clang-tidy/checks/performance/XXX.rst...
Updating clang-tools-extra/docs/clang-tidy/checks/list.rst...
Done. Now it's your turn!

> head -n 1 clang-tools-extra/test/clang-tidy/checkers/performance/XXX.cpp
// RUN: %check_clang_tidy None%s performance-XXX %t
```
---
 clang-tools-extra/clang-tidy/add_new_check.py | 90 +++
 1 file changed, 52 insertions(+), 38 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index bd69bddcc68256..ce32b5de4192f8 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -8,9 +8,6 @@
 #
 # 
===---===#
 
-from __future__ import print_function
-from __future__ import unicode_literals
-
 import argparse
 import io
 import itertools
@@ -18,11 +15,13 @@
 import re
 import sys
 import textwrap
+# FIXME Python 3.9: Replace typing.Tuple with builtins.tuple.
+from typing import Optional, Tuple
 
 
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new
 # entry and 'False' if the entry already existed.
-def adapt_cmake(module_path, check_name_camel):
+def adapt_cmake(module_path: str, check_name_camel: str) -> bool:
 filename = os.path.join(module_path, "CMakeLists.txt")
 
 # The documentation files are encoded using UTF-8, however on Windows the
@@ -57,14 +56,14 @@ def adapt_cmake(module_path, check_name_camel):
 
 # Adds a header for the new check.
 def write_header(
-module_path,
-module,
-namespace,
-check_name,
-check_name_camel,
-description,
-lang_restrict,
-):
+module_path: str,
+module: str,
+namespace: str,
+check_name: str,
+check_name_camel: str,
+description: str,
+lang_restrict: str,
+) -> None:
 wrapped_desc = "\n".join(
 textwrap.wrap(
 description, width=80, initial_indent="/// ", 
subsequent_indent="/// "
@@ -139,7 +138,9 @@ class %(check_name_camel)s : public ClangTidyCheck {
 
 
 # Adds the implementation of the new check.
-def write_implementation(module_path, module, namespace, check_name_camel):
+def write_implementation(
+module_path: str, module: str, namespace: str, check_name_camel: str
+) -> None:
 filename = os.path.join(module_path, check_name_camel) + ".cpp"
 print("Creating %s..." % filename)
 with io.open(filename, "w", encoding="utf8", newline="\n") as f:
@@ -187,7 +188,7 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 
 
 # Returns the source filename that implements the module.
-def get_module_filename(module_path, module):
+def get_module_filename(module_path: str, module: str) -> str:
 modulecpp = list(
 filter(
 lambda p: p.lower() == module.lower() + "tidymodule.cpp",
@@ -198,7 +199,9 @@ def get_module_filename(module_path, module):
 
 
 # Modifies the module to include the new check.
-def adapt_module(module_path, module, check_name, check_name_camel):
+def adapt_module(
+module_path: str, module: str, check_name: str, check_name_camel: str
+) -> None:
 filename = get_module_filename(module_path, module)
 with io.open(filename, "r", encoding="utf8") as f:
 lines = f.readlines()
@@ -217,10 +220,10 @@ def adapt_module(module_path, module, check_name, 
check_name_camel):
 + '");\n'
 )
 
-lines = iter(lines)
+lines_iter = iter(lines)
 try:
 while True:
-line = next(lines)
+line = next(lines_iter)
 if not header_added:
 match = re.search('#include "(.*)"', line)
 if match:
@@ -247,10 +250,11 @@ def adapt_module(module_path, module, check_name, 
check_name_camel):
 # If we didn't find the check name on this 
line, look on the

[clang] [clang] The ms-extension __noop should return zero in a constexpr context. (PR #106849)

2024-08-31 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/106849

>From 6ce4604725d36afaea17cf533d422a978c4389ff Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Fri, 30 Aug 2024 15:34:34 +
Subject: [PATCH 1/3] fix cast

---
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/AST/atomic-expr.c   | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/atomic-expr.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e8a4d1d3c74102..0571771e2a7e7d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14458,7 +14458,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
   case CK_ZeroToOCLOpaqueType:
-  case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
   case CK_FloatingToFixedPoint:
@@ -14482,6 +14481,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_UserDefinedConversion:
   case CK_LValueToRValue:
   case CK_AtomicToNonAtomic:
+  case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_LValueToRValueBitCast:
   case CK_HLSLArrayRValue:
diff --git a/clang/test/AST/atomic-expr.c b/clang/test/AST/atomic-expr.c
new file mode 100644
index 00..0826a6491e8a6a
--- /dev/null
+++ b/clang/test/AST/atomic-expr.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// expected-no-diagnostics
+
+typedef _Atomic char atomic_char;
+
+atomic_char counter;
+
+char load_plus_one() {
+  return ({ counter; }) + 1;
+}
\ No newline at end of file

>From f0957df83597a2c43a8510a83619ef67c918c7d6 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 31 Aug 2024 21:19:46 +0800
Subject: [PATCH 2/3] __noop should return 0

---
 clang/lib/AST/ExprConstant.cpp  | 4 ++--
 clang/test/SemaCXX/builtins.cpp | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0571771e2a7e7d..69d2707aed9171 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12720,8 +12720,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   }
 
   case Builtin::BI__noop:
-  // __noop always evaluates successfully
-return true;
+// __noop always evaluates successfully
+return false;
 
   case Builtin::BI__builtin_is_constant_evaluated: {
 const auto *Callee = Info.CurrentCall->getCallee();
diff --git a/clang/test/SemaCXX/builtins.cpp b/clang/test/SemaCXX/builtins.cpp
index c6fbb8b514d671..78344c45092a79 100644
--- a/clang/test/SemaCXX/builtins.cpp
+++ b/clang/test/SemaCXX/builtins.cpp
@@ -178,4 +178,5 @@ static void __builtin_cpu_init(); // expected-error 
{{static declaration of '__b
 
 #ifdef _MSC_VER
 constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics
+static_assert([] { return __noop; }() == 0);
 #endif

>From a53cbbb4f3aaf65d0ebb49602f76d7f648e80410 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 31 Aug 2024 21:22:47 +0800
Subject: [PATCH 3/3] Revert "fix cast"

This reverts commit 6ce4604725d36afaea17cf533d422a978c4389ff.
---
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/AST/atomic-expr.c   | 10 --
 2 files changed, 1 insertion(+), 11 deletions(-)
 delete mode 100644 clang/test/AST/atomic-expr.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 69d2707aed9171..57040043f74193 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14458,6 +14458,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
   case CK_ZeroToOCLOpaqueType:
+  case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
   case CK_FloatingToFixedPoint:
@@ -14481,7 +14482,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_UserDefinedConversion:
   case CK_LValueToRValue:
   case CK_AtomicToNonAtomic:
-  case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_LValueToRValueBitCast:
   case CK_HLSLArrayRValue:
diff --git a/clang/test/AST/atomic-expr.c b/clang/test/AST/atomic-expr.c
deleted file mode 100644
index 0826a6491e8a6a..00
--- a/clang/test/AST/atomic-expr.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only %s -verify
-// expected-no-diagnostics
-
-typedef _Atomic char atomic_char;
-
-atomic_char counter;
-
-char load_plus_one() {
-  return ({ counter; }) + 1;
-}
\ No newline at end of file

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


[clang] [clang] function template non-call partial ordering fixes (PR #106829)

2024-08-31 Thread via cfe-commits


@@ -5635,123 +5627,95 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
 
   assert(Proto1 && Proto2 && "Function templates must have prototypes");
   TemplateParameterList *TemplateParams = FT2->getTemplateParameters();
-  SmallVector Deduced;
-  Deduced.resize(TemplateParams->size());
+  SmallVector Deduced(TemplateParams->size());
 
-  // C++0x [temp.deduct.partial]p3:
-  //   The types used to determine the ordering depend on the context in which
-  //   the partial ordering is done:
   TemplateDeductionInfo Info(Loc);
-  switch (TPOC) {
-  case TPOC_Call: {
-llvm::SmallBitVector HasDeducedParam(Args2.size());
-if (DeduceTemplateArguments(
-S, TemplateParams, Args2.data(), Args2.size(), Args1.data(),
-Args1.size(), Info, Deduced, TDF_None, /*PartialOrdering=*/true,
-/*HasDeducedAnyParam=*/nullptr,
-&HasDeducedParam) != TemplateDeductionResult::Success)
-  return false;
+  if (TPOC == TPOC_Other) {
+// We wouldn't be partial ordering these candidates if these didn't match.
+assert(Proto2->getMethodQuals() == Proto1->getMethodQuals());
+assert(Proto2->getRefQualifier() == Proto1->getRefQualifier());
+assert(Proto2->isVariadic() == Proto1->isVariadic());
 
-SmallVector DeducedArgs(Deduced.begin(),
- Deduced.end());
-Sema::InstantiatingTemplate Inst(
-S, Info.getLocation(), FT2, DeducedArgs,
-Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
-if (Inst.isInvalid())
-  return false;
-
-bool AtLeastAsSpecialized = true;
-S.runWithSufficientStackSpace(Info.getLocation(), [&] {
-  AtLeastAsSpecialized =
-  ::FinishTemplateArgumentDeduction(
-  S, FT2, Deduced, Info,
-  [&](Sema &S, FunctionTemplateDecl *FTD,
-  ArrayRef DeducedArgs) {
-return ::DeduceForEachType(
-S, TemplateParams, Args2.data(), Args2.size(), 
Args1.data(),
-Args1.size(), Info, Deduced,
-/*PartialOrdering=*/true, /*FinishingDeduction=*/true,
-[&](Sema &S, TemplateParameterList *, int ParamIdx,
-int ArgIdx, QualType P, QualType A,
-TemplateDeductionInfo &Info,
-SmallVectorImpl &Deduced,
-bool) {
-  // As a provisional fix for a core issue that does not
-  // exist yet, only check the consistency of parameters
-  // which participated in deduction. We still try to
-  // substitute them though.
-  return ::CheckDeductionConsistency(
-  S, FTD, ArgIdx, P, A, DeducedArgs,
-  HasDeducedParam[ParamIdx]);
-});
-  }) == TemplateDeductionResult::Success;
-});
-if (!AtLeastAsSpecialized)
-  return false;
-  } break;
-  case TPOC_Conversion:
-  case TPOC_Other: {
-//   - In the context of a call to a conversion operator, the return types
-// of the conversion function templates are used.
-//   - In other contexts (14.6.6.2) the function template's function type
-// is used.
-auto [A, P, TDF] = TPOC == TPOC_Other
-   ? std::make_tuple(FD1->getType(), FD2->getType(),
- TDF_AllowCompatibleFunctionType)
-   : std::make_tuple(Proto1->getReturnType(),
- Proto2->getReturnType(), 
TDF_None);
+assert(Args1.empty() && Args2.empty());
+Args1 = Proto1->getParamTypes();
+Args2 = Proto2->getParamTypes();

cor3ntin wrote:

Actually, the code above should be under the comment below

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


[clang] [clang] The ms-extension __noop should return zero in a constexpr context. (PR #106849)

2024-08-31 Thread via cfe-commits

https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/106849

Fixes #106713.

>From 6ce4604725d36afaea17cf533d422a978c4389ff Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Fri, 30 Aug 2024 15:34:34 +
Subject: [PATCH 1/2] fix cast

---
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/AST/atomic-expr.c   | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/atomic-expr.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e8a4d1d3c74102..0571771e2a7e7d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14458,7 +14458,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
   case CK_ZeroToOCLOpaqueType:
-  case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
   case CK_FloatingToFixedPoint:
@@ -14482,6 +14481,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_UserDefinedConversion:
   case CK_LValueToRValue:
   case CK_AtomicToNonAtomic:
+  case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_LValueToRValueBitCast:
   case CK_HLSLArrayRValue:
diff --git a/clang/test/AST/atomic-expr.c b/clang/test/AST/atomic-expr.c
new file mode 100644
index 00..0826a6491e8a6a
--- /dev/null
+++ b/clang/test/AST/atomic-expr.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// expected-no-diagnostics
+
+typedef _Atomic char atomic_char;
+
+atomic_char counter;
+
+char load_plus_one() {
+  return ({ counter; }) + 1;
+}
\ No newline at end of file

>From f0957df83597a2c43a8510a83619ef67c918c7d6 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 31 Aug 2024 21:19:46 +0800
Subject: [PATCH 2/2] __noop should return 0

---
 clang/lib/AST/ExprConstant.cpp  | 4 ++--
 clang/test/SemaCXX/builtins.cpp | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0571771e2a7e7d..69d2707aed9171 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12720,8 +12720,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   }
 
   case Builtin::BI__noop:
-  // __noop always evaluates successfully
-return true;
+// __noop always evaluates successfully
+return false;
 
   case Builtin::BI__builtin_is_constant_evaluated: {
 const auto *Callee = Info.CurrentCall->getCallee();
diff --git a/clang/test/SemaCXX/builtins.cpp b/clang/test/SemaCXX/builtins.cpp
index c6fbb8b514d671..78344c45092a79 100644
--- a/clang/test/SemaCXX/builtins.cpp
+++ b/clang/test/SemaCXX/builtins.cpp
@@ -178,4 +178,5 @@ static void __builtin_cpu_init(); // expected-error 
{{static declaration of '__b
 
 #ifdef _MSC_VER
 constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics
+static_assert([] { return __noop; }() == 0);
 #endif

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


[clang] [Clang][RISCV] Recognize unsupport target feature by supporting isValidFeatureName (PR #106495)

2024-08-31 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/106495

>From e8f472674e0d1e70adcd1d29b8c902f4cd80f188 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Wed, 28 Aug 2024 21:15:57 -0700
Subject: [PATCH 1/3] [Clang][RISCV] Recognize unsupport feature by supporting
 isValidFeatureName

---
 clang/lib/Basic/Targets/RISCV.cpp   |  7 +++
 clang/lib/Basic/Targets/RISCV.h |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp | 15 +++
 clang/test/Sema/attr-target-riscv.c |  9 +
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index b89109e7725d44..9abef57d007468 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -478,3 +478,10 @@ bool RISCVTargetInfo::validateCpuSupports(StringRef 
Feature) const {
   // __riscv_feature_bits structure.
   return -1 != llvm::RISCVISAInfo::getRISCVFeaturesBitsInfo(Feature).second;
 }
+
+bool RISCVTargetInfo::isValidFeatureName(StringRef Name) const {
+  if (Name == "__RISCV_TargetAttrNeedOverride")
+return true;
+
+  return llvm::RISCVISAInfo::isSupportedExtensionFeature(Name);
+}
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 626274b8fc437c..b808ccc8e9cfe9 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -130,6 +130,7 @@ class RISCVTargetInfo : public TargetInfo {
   bool supportsCpuSupports() const override { return getTriple().isOSLinux(); }
   bool supportsCpuInit() const override { return getTriple().isOSLinux(); }
   bool validateCpuSupports(StringRef Feature) const override;
+  bool isValidFeatureName(StringRef Name) const override;
 };
 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
 public:
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1e074298ac5289..81cff8d7362ad5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2993,10 +2993,17 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, 
StringRef AttrStr) {
 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
<< Unknown << Tune << ParsedAttrs.Tune << Target;
 
-  if (Context.getTargetInfo().getTriple().isRISCV() &&
-  ParsedAttrs.Duplicate != "")
-return Diag(LiteralLoc, diag::err_duplicate_target_attribute)
-   << Duplicate << None << ParsedAttrs.Duplicate << Target;
+  if (Context.getTargetInfo().getTriple().isRISCV()) {
+if (ParsedAttrs.Duplicate != "")
+  return Diag(LiteralLoc, diag::err_duplicate_target_attribute)
+ << Duplicate << None << ParsedAttrs.Duplicate << Target;
+for (const auto &Feature : ParsedAttrs.Features) {
+  auto CurFeature = StringRef(Feature);
+  if (!CurFeature.starts_with("+") && !CurFeature.starts_with("-"))
+return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
+   << Unsupported << None << AttrStr << Target;
+}
+  }
 
   if (ParsedAttrs.Duplicate != "")
 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
diff --git a/clang/test/Sema/attr-target-riscv.c 
b/clang/test/Sema/attr-target-riscv.c
index ed4e2915d6c6ef..01d928c1d78e48 100644
--- a/clang/test/Sema/attr-target-riscv.c
+++ b/clang/test/Sema/attr-target-riscv.c
@@ -4,3 +4,12 @@
 int __attribute__((target("arch=rv64g"))) foo(void) { return 0; }
 //expected-error@+1 {{redefinition of 'foo'}}
 int __attribute__((target("arch=rv64gc"))) foo(void) { return 0; }
+
+//expected-warning@+1 {{unsupported 'notafeature' in the 'target' attribute 
string; 'target' attribute ignored}}
+int __attribute__((target("arch=+notafeature"))) UnsupportFeature(void) { 
return 0; }
+
+//expected-warning@+1 {{unsupported 'arch=+zba,zbb' in the 'target' attribute 
string; 'target' attribute ignored}}
+int __attribute__((target("arch=+zba,zbb"))) WithoutAddSigned(void) { return 
0; }
+
+//expected-warning@+1 {{unsupported 'arch=zba' in the 'target' attribute 
string; 'target' attribute ignored}}
+int __attribute__((target("arch=zba"))) WithoutAddSigned2(void) { return 0; }

>From ad95a3112c5349ea125d9c8d79cfa2f5e3d1d0a4 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Thu, 29 Aug 2024 00:39:08 -0700
Subject: [PATCH 2/3] Merge handleFullArchString logic, parseArchString will
 check whether start with "rv"

---
 clang/lib/Basic/Targets/RISCV.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 9abef57d007468..1ab9f19ab7a30c 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -388,7 +388,7 @@ static void handleFullArchString(StringRef FullArchStr,
   FullArchStr, /* EnableExperimentalExtension */ true);
   if (llvm::errorToBool(RII.takeError())) {
 // Forward the invalid FullArchStr.
-Features.push_back("+" + FullArchStr.str());
+Features.push_bac

[clang] [HLSL] Implement output parameter (PR #101083)

2024-08-31 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-sve-vls` 
running on `linaro-g3-02` while building `clang` at step 7 "ninja check 1".

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


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

```
Step 7 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clangd :: crash-parse.test' FAILED 

Exit Code: 1

Command Output (stdout):
--
Content-Length: 3402

{
  "id": 0,
  "jsonrpc": "2.0",
  "result": {
"capabilities": {
  "astProvider": true,
  "callHierarchyProvider": true,
  "clangdInlayHintsProvider": true,
  "codeActionProvider": true,
  "compilationDatabase": {
"automaticReload": true
  },
  "completionProvider": {
"resolveProvider": false,
"triggerCharacters": [
  ".",
  "<",
  ">",
  ":",
  "\"",
  "/",
  "*"
]
  },
  "declarationProvider": true,
  "definitionProvider": true,
  "documentFormattingProvider": true,
  "documentHighlightProvider": true,
  "documentLinkProvider": {
"resolveProvider": false
  },
  "documentOnTypeFormattingProvider": {
"firstTriggerCharacter": "\n",
"moreTriggerCharacter": []
  },
  "documentRangeFormattingProvider": true,
  "documentSymbolProvider": true,
  "executeCommandProvider": {
"commands": [
  "clangd.applyFix",
  "clangd.applyRename",
  "clangd.applyTweak"
]
...

```



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


[clang] [clang] function template non-call partial ordering fixes (PR #106829)

2024-08-31 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
PASS: SanitizerCommon-msan-powerpc64le-Linux :: Linux/signal_name.c (2343 of 
2489)
PASS: ThreadSanitizer-powerpc64le :: ignore_lib3.cpp (2344 of 2489)
PASS: ScudoStandalone-Unit :: ./ScudoUnitTest-powerpc64le-Test/78/277 (2345 of 
2489)
PASS: ThreadSanitizer-powerpc64le :: simple_race.c (2346 of 2489)
PASS: MemorySanitizer-POWERPC64LE :: select.cpp (2347 of 2489)
PASS: ThreadSanitizer-powerpc64le :: mutexset2.cpp (2348 of 2489)
PASS: ThreadSanitizer-powerpc64le :: mutexset6.cpp (2349 of 2489)
PASS: ScudoStandalone-Unit :: ./ScudoUnitTest-powerpc64le-Test/84/277 (2350 of 
2489)
PASS: ThreadSanitizer-powerpc64le :: stack_race.cpp (2351 of 2489)
PASS: ThreadSanitizer-powerpc64le :: race_on_fputs.cpp (2352 of 2489)
FAIL: ThreadSanitizer-powerpc64le :: signal_block.cpp (2353 of 2489)
 TEST 'ThreadSanitizer-powerpc64le :: signal_block.cpp' 
FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/./bin/clang
  -fsanitize=thread -Wall  -m64 -fno-function-sections   -gline-tables-only 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/../
 -O1 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
 -o 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
 &&  
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
 2>&1 | FileCheck 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
+ 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/./bin/clang
 -fsanitize=thread -Wall -m64 -fno-function-sections -gline-tables-only 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/../
 -O1 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
 -o 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
+ 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
+ FileCheck 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:59:15:
 error: CHECK-NOT: excluded string found in input
// CHECK-NOT: WARNING: ThreadSanitizer:
  ^
:2:1: note: found here
WARNING: ThreadSanitizer: signal handler spoils errno (pid=198827)
^

Input file: 
Check file: 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp

-dump-input=help explains the following input dump.

Input was:
<<
1: == 
2: WARNING: ThreadSanitizer: signal handler spoils errno (pid=198827) 
not:59 !   
error: no match expected
3:  Signal 10 handler invoked at: 
4:  #0 handler(int) 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:13
 (signal_block.cpp.tmp+0xff160) 
5:  #1 thread(void*) 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:25:5
 (signal_block.cpp.tmp+0xff2b0) 
6:  
7: SUMMARY: ThreadSanitizer: signal handler spoils errno 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:13
 in h

[clang] [llvm] [HLSL] AST support for WaveSize attribute. (PR #101240)

2024-08-31 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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


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

```
Step 7 (Add check check-offload) failure: test (failure)
...
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug53727.cpp (867 
of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug50022.cpp (868 
of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/test_libc.cpp (869 
of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/wtime.c (870 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu :: offloading/bug49021.cpp (871 of 
876)
PASS: libomptarget :: x86_64-pc-linux-gnu :: 
offloading/std_complex_arithmetic.cpp (872 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: 
offloading/complex_reduction.cpp (873 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug49021.cpp (874 
of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: 
offloading/std_complex_arithmetic.cpp (875 of 876)
TIMEOUT: libomptarget :: amdgcn-amd-amdhsa :: offloading/ctor_dtor.cpp (876 of 
876)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
offloading/ctor_dtor.cpp' FAILED 
Exit Code: -9
Timeout: Reached timeout of 100 seconds

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang++ 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
 -fopenmp-targets=amdgcn-amd-amdhsa 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/ctor_dtor.cpp
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/ctor_dtor.cpp.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
 && 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/ctor_dtor.cpp.tmp
 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/ctor_dtor.cpp
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang++ 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
-fopenmp-targets=amdgcn-amd-amdhsa 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/ctor_dtor.cpp
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/ctor_dtor.cpp.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/ctor_dtor.cpp.tmp
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/ctor_dtor.cpp
# note: command had no output on stdout or stderr
# RUN: at line 2
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang++

[clang-tools-extra] [clang-tidy] fix nullptr dereference in bugprone-forwarding-reference (PR #106856)

2024-08-31 Thread via cfe-commits

llvmbot wrote:




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

Author: Julian Schmidt (5chmidti)


Changes

Previously, when checking if a `TemplateSpecializationType` is either
`enable_if` or `enable_if_t`, the AST matcher would call
`getTemplateName`, `getASTemplateDecl` and `getTemplatedDecl` in
succession to check the `NamedDecl` returned from `getTemplatedDecl` is
`std::enable_if[_t]`.
In the linked issue, the pointer returned by `getTemplatedDecl` is a
`nullptr` that is unconditionally accessed, resulting in a crash.
Instead, the checking is done on the `TemplateDecl` returned by
`getASTemplateDecl`.

Fixes #106333


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


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp 
(+7-8) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
 (+6) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index c87b3ea7e26163..00e8f7e514368b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -9,7 +9,6 @@
 #include "ForwardingReferenceOverloadCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include 
 
 using namespace clang::ast_matchers;
 
@@ -19,14 +18,14 @@ namespace {
 // Check if the given type is related to std::enable_if.
 AST_MATCHER(QualType, isEnableIf) {
   auto CheckTemplate = [](const TemplateSpecializationType *Spec) {
-if (!Spec || !Spec->getTemplateName().getAsTemplateDecl()) {
+if (!Spec)
   return false;
-}
-const NamedDecl *TypeDecl =
-Spec->getTemplateName().getAsTemplateDecl()->getTemplatedDecl();
-return TypeDecl->isInStdNamespace() &&
-   (TypeDecl->getName() == "enable_if" ||
-TypeDecl->getName() == "enable_if_t");
+
+const TemplateDecl *TDecl = Spec->getTemplateName().getAsTemplateDecl();
+
+return TDecl && TDecl->isInStdNamespace() &&
+   (TDecl->getName() == "enable_if" ||
+TDecl->getName() == "enable_if_t");
   };
   const Type *BaseType = Node.getTypePtr();
   // Case: pointer or reference to enable_if.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b001a6ad446695..c2fdc7dc689fc1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -104,6 +104,10 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`bugprone-forwarding-reference-overload
+  ` check by fixing
+  a crash when determining if an ``enable_if[_t]`` was found.
+
 - Improved :doc:`modernize-use-std-format
   ` check to support replacing
   member function calls too.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
index 92dfb718bb51b7..27315199c7ebae 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
@@ -261,3 +261,9 @@ class Test11 {
   Test11(const Test11 &) = default;
   Test11(Test11 &&) = default;
 };
+
+template  typename T, typename U>
+struct gh106333
+{
+gh106333(U && arg1, T arg2) {}
+};

``




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


[clang-tools-extra] [NFC][clang-tidy] reword diagnostic note in definitions-in-headers (PR #106862)

2024-08-31 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti created 
https://github.com/llvm/llvm-project/pull/106862

`make as inline` made little sense here, so I changed the `make` to `mark`
and added `the definition` as well.


>From 46704590d3a90518c7b58ce03ac29c3e65c26676 Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 31 Aug 2024 18:44:37 +0200
Subject: [PATCH] [NFC][clang-tidy] reword diagnostic note in
 definitions-in-headers

`make as inline` made little sense here, so I changed the `make` to `mark`
and added `the definition` as well.
---
 clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index 21008bc144b91a..ee869256898989 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -102,7 +102,7 @@ void DefinitionsInHeadersCheck::check(const 
MatchFinder::MatchResult &Result) {
 // inline is not allowed for main function.
 if (FD->isMain())
   return;
-diag(FD->getLocation(), /*Description=*/"make as 'inline'",
+diag(FD->getLocation(), "mark the definition as 'inline'",
  DiagnosticIDs::Note)
 << FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
   } else if (const auto *VD = dyn_cast(ND)) {

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


[clang-tools-extra] [NFC][clang-tidy] fix tests of deleted functions for missing-std-forward (PR #106861)

2024-08-31 Thread Nicolas van Kempen via cfe-commits

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


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


[clang] [Clang][RISCV] Recognize unsupport target feature by supporting isValidFeatureName (PR #106495)

2024-08-31 Thread Piyou Chen via cfe-commits

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


[clang] 89fb849 - [HLSL] Implement output parameter (#101083)

2024-08-31 Thread via cfe-commits

Author: Chris B
Date: 2024-08-31T10:59:08-05:00
New Revision: 89fb8490a99e612f7a574e8678b21a90f689f5b4

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

LOG: [HLSL] Implement output parameter (#101083)

HLSL output parameters are denoted with the `inout` and `out` keywords
in the function declaration. When an argument to an output parameter is
constructed a temporary value is constructed for the argument.

For `inout` pamameters the argument is initialized via copy-initialization
from the argument lvalue expression to the parameter type. For `out`
parameters the argument is not initialized before the call.

In both cases on return of the function the temporary value is written
back to the argument lvalue expression through an implicit assignment
binary operator with casting as required.

This change introduces a new HLSLOutArgExpr ast node which represents
the output argument behavior. The OutArgExpr has three defined children:
- An OpaqueValueExpr of the argument lvalue expression.
- An OpaqueValueExpr of the copy-initialized parameter.
- A BinaryOpExpr assigning the first with the value of the second.

Fixes #87526

-

Co-authored-by: Damyan Pepper 
Co-authored-by: John McCall 

Added: 
clang/test/AST/HLSL/OutArgExpr.hlsl
clang/test/CodeGenHLSL/BasicFeatures/OutputArguments.hlsl
clang/test/SemaHLSL/Language/OutputParameters.hlsl
clang/test/SemaHLSL/Language/TemplateOutArg.hlsl

Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Attr.h
clang/include/clang/AST/Expr.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/TextNodeDumper.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/Specifiers.h
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Sema/SemaHLSL.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGCall.h
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaHLSL.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaSwift.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/SemaHLSL/parameter_modifiers.hlsl
clang/test/SemaHLSL/parameter_modifiers_ast.hlsl
clang/tools/libclang/CXCursor.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 8156d283f8fe21..3c43892b6ff719 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1381,6 +1381,14 @@ class ASTContext : public RefCountedBase {
   /// in the return type and parameter types.
   bool hasSameFunctionTypeIgnoringPtrSizes(QualType T, QualType U);
 
+  /// Get or construct a function type that is equivalent to the input type
+  /// except that the parameter ABI annotations are stripped.
+  QualType getFunctionTypeWithoutParamABIs(QualType T) const;
+
+  /// Determine if two function types are the same, ignoring parameter ABI
+  /// annotations.
+  bool hasSameFunctionTypeIgnoringParamABI(QualType T, QualType U) const;
+
   /// Return the uniqued reference to the type for a complex
   /// number with the specified element type.
   QualType getComplexType(QualType T) const;

diff  --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index bd1851a26ce2e1..ac44e9fdd7c4e9 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -224,20 +224,7 @@ class ParameterABIAttr : public InheritableParamAttr {
  InheritEvenIfAlreadyPresent) {}
 
 public:
-  ParameterABI getABI() const {
-switch (getKind()) {
-case attr::SwiftContext:
-  return ParameterABI::SwiftContext;
-case attr::SwiftAsyncContext:
-  return ParameterABI::SwiftAsyncContext;
-case attr::SwiftErrorResult:
-  return ParameterABI::SwiftErrorResult;
-case attr::SwiftIndirectResult:
-  return ParameterABI::SwiftIndirectResult;
-default:
-  llvm_unreachable("bad parameter ABI a

[clang] [Clang][RISCV] Recognize unsupport target feature by supporting isValidFeatureName (PR #106495)

2024-08-31 Thread Piyou Chen via cfe-commits

BeMg wrote:

Rebase with https://github.com/llvm/llvm-project/pull/106680 and drop the 
`__RISCV_TargetAttrNeedOverride` relate code section.

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


[clang] [CIR] Build out AST consumer patterns to reach the entry point into CIRGen (PR #91007)

2024-08-31 Thread Shoaib Meenai via cfe-commits


@@ -2900,7 +2900,7 @@ defm clangir : BoolFOption<"clangir",
   PosFlag,
   NegFlag LLVM 
pipeline to compile">,
   BothFlags<[], [ClangOption, CC1Option], "">>;
-def emit_cir : Flag<["-"], "emit-cir">, Visibility<[CC1Option]>,
+def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,

smeenai wrote:

Fangrui is out for a few weeks: 
https://github.com/llvm/llvm-project/pull/104899#pullrequestreview-2248433784

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


[clang] [clang] function template non-call partial ordering fixes (PR #106829)

2024-08-31 Thread Matheus Izvekov via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank updated 
https://github.com/llvm/llvm-project/pull/106801

>From 17f4b4a4320ded64b4d6ea673508e3d2f470d0aa Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Sat, 31 Aug 2024 13:46:52 -0400
Subject: [PATCH] [clang-tidy] Add type annotations to add_new_check.py, fix
 minor bug

```
> python3 -m mypy --strict clang-tools-extra/clang-tidy/add_new_check.py
Success: no issues found in 1 source file
```

Also fix a bug when `--standard` is not provided on the command line: the
generated test case has a `None` causing issues:
```
> python3 clang-tools-extra/clang-tidy/add_new_check.py performance XXX
Updating clang-tools-extra/clang-tidy/performance/CMakeLists.txt...
Creating clang-tools-extra/clang-tidy/performance/XxxCheck.h...
Creating clang-tools-extra/clang-tidy/performance/XxxCheck.cpp...
Updating clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp...
Updating clang-tools-extra/docs/ReleaseNotes.rst...
Creating clang-tools-extra/test/clang-tidy/checkers/performance/XXX.cpp...
Creating clang-tools-extra/docs/clang-tidy/checks/performance/XXX.rst...
Updating clang-tools-extra/docs/clang-tidy/checks/list.rst...
Done. Now it's your turn!

> head -n 1 clang-tools-extra/test/clang-tidy/checkers/performance/XXX.cpp
// RUN: %check_clang_tidy None%s performance-XXX %t
```
---
 clang-tools-extra/clang-tidy/add_new_check.py | 91 +++
 1 file changed, 53 insertions(+), 38 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index bd69bddcc68256..d384dbae28abbc 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -8,9 +8,6 @@
 #
 # 
===---===#
 
-from __future__ import print_function
-from __future__ import unicode_literals
-
 import argparse
 import io
 import itertools
@@ -19,10 +16,13 @@
 import sys
 import textwrap
 
+# FIXME Python 3.9: Replace typing.Tuple with builtins.tuple.
+from typing import Optional, Tuple
+
 
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new
 # entry and 'False' if the entry already existed.
-def adapt_cmake(module_path, check_name_camel):
+def adapt_cmake(module_path: str, check_name_camel: str) -> bool:
 filename = os.path.join(module_path, "CMakeLists.txt")
 
 # The documentation files are encoded using UTF-8, however on Windows the
@@ -57,14 +57,14 @@ def adapt_cmake(module_path, check_name_camel):
 
 # Adds a header for the new check.
 def write_header(
-module_path,
-module,
-namespace,
-check_name,
-check_name_camel,
-description,
-lang_restrict,
-):
+module_path: str,
+module: str,
+namespace: str,
+check_name: str,
+check_name_camel: str,
+description: str,
+lang_restrict: str,
+) -> None:
 wrapped_desc = "\n".join(
 textwrap.wrap(
 description, width=80, initial_indent="/// ", 
subsequent_indent="/// "
@@ -139,7 +139,9 @@ class %(check_name_camel)s : public ClangTidyCheck {
 
 
 # Adds the implementation of the new check.
-def write_implementation(module_path, module, namespace, check_name_camel):
+def write_implementation(
+module_path: str, module: str, namespace: str, check_name_camel: str
+) -> None:
 filename = os.path.join(module_path, check_name_camel) + ".cpp"
 print("Creating %s..." % filename)
 with io.open(filename, "w", encoding="utf8", newline="\n") as f:
@@ -187,7 +189,7 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 
 
 # Returns the source filename that implements the module.
-def get_module_filename(module_path, module):
+def get_module_filename(module_path: str, module: str) -> str:
 modulecpp = list(
 filter(
 lambda p: p.lower() == module.lower() + "tidymodule.cpp",
@@ -198,7 +200,9 @@ def get_module_filename(module_path, module):
 
 
 # Modifies the module to include the new check.
-def adapt_module(module_path, module, check_name, check_name_camel):
+def adapt_module(
+module_path: str, module: str, check_name: str, check_name_camel: str
+) -> None:
 filename = get_module_filename(module_path, module)
 with io.open(filename, "r", encoding="utf8") as f:
 lines = f.readlines()
@@ -217,10 +221,10 @@ def adapt_module(module_path, module, check_name, 
check_name_camel):
 + '");\n'
 )
 
-lines = iter(lines)
+lines_iter = iter(lines)
 try:
 while True:
-line = next(lines)
+line = next(lines_iter)
 if not header_added:
 match = re.search('#include "(.*)"', line)
 if match:
@@ -247,10 +251,11 @@ def adapt_module(module_path, module, check_name, 
check_name_camel):
 # If we didn't find the check name on this 
line, look on the

[clang] [clang] fix range of empty enumeration without fixed underlying type (PR #106841)

2024-08-31 Thread via cfe-commits

keinflue wrote:

I just realized too late that this would be for the most part a revert of 
aea82d4551139.  So I am not sure how to proceed.

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


[clang] b0276ec - [RISCV][NFC] Reimplementation of target attribute override mechanism (#106680)

2024-08-31 Thread via cfe-commits

Author: Piyou Chen
Date: 2024-08-31T20:02:46+08:00
New Revision: b0276ec6b74cd65b765234f42b8e0e32597d3642

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

LOG: [RISCV][NFC] Reimplementation of target attribute override mechanism 
(#106680)

This patch aims to replace the target attribute override mechanism based
on `__RISCV_TargetAttrNeedOverride` with the insertion of several
negative target features

When the target attribute uses the full architecture string
("arch=rv64gc") or specifies the CPU ("cpu=rocket-rv64") as the version,
it will override the module-level target feature. Currently, this
mechanism is implemented by inserting `__RISCV_TargetAttrNeedOverride`
as a dummy target feature immediately before the target attribute's
feature.

```
module target features + __RISCV_TargetAttrNeedOverride + target attribute's 
feature
```

The RISCVTargetInfo::initFeatureMap function will remove the "module
target features" and use only the "target attribute's features".

This patch changes the process as follows:

```
module target features + negative target feature for all supported extension + 
target attribute's feature
```

The `module target features` will be disable by `negative target feature
for all supported extension` in `TargetInfo::initFeatureMap`

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 1f8a8cd1462c9d..b89109e7725d44 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -255,25 +255,6 @@ bool RISCVTargetInfo::initFeatureMap(
 Features["32bit"] = true;
   }
 
-  // If a target attribute specified a full arch string, override all the ISA
-  // extension target features.
-  const auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
-  if (I != FeaturesVec.end()) {
-std::vector OverrideFeatures(std::next(I), FeaturesVec.end());
-
-// Add back any non ISA extension features, e.g. +relax.
-auto IsNonISAExtFeature = [](StringRef Feature) {
-  assert(Feature.size() > 1 && (Feature[0] == '+' || Feature[0] == '-'));
-  StringRef Ext = Feature.substr(1); // drop the +/-
-  return !llvm::RISCVISAInfo::isSupportedExtensionFeature(Ext);
-};
-llvm::copy_if(llvm::make_range(FeaturesVec.begin(), I),
-  std::back_inserter(OverrideFeatures), IsNonISAExtFeature);
-
-return TargetInfo::initFeatureMap(Features, Diags, CPU, OverrideFeatures);
-  }
-
-  // Otherwise, parse the features and add any implied extensions.
   std::vector AllFeatures = FeaturesVec;
   auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, FeaturesVec);
   if (!ParseResult) {
@@ -389,9 +370,20 @@ void RISCVTargetInfo::fillValidTuneCPUList(
   llvm::RISCV::fillValidTuneCPUArchList(Values, Is64Bit);
 }
 
+static void populateNegativeRISCVFeatures(std::vector &Features) {
+  auto RII = llvm::RISCVISAInfo::parseArchString(
+  "rv64i", /* EnableExperimentalExtension */ true);
+
+  if (llvm::errorToBool(RII.takeError()))
+llvm_unreachable("unsupport rv64i");
+
+  std::vector FeatStrings =
+  (*RII)->toFeatures(/* AddAllExtensions */ true);
+  Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end());
+}
+
 static void handleFullArchString(StringRef FullArchStr,
  std::vector &Features) {
-  Features.push_back("__RISCV_TargetAttrNeedOverride");
   auto RII = llvm::RISCVISAInfo::parseArchString(
   FullArchStr, /* EnableExperimentalExtension */ true);
   if (llvm::errorToBool(RII.takeError())) {
@@ -400,6 +392,7 @@ static void handleFullArchString(StringRef FullArchStr,
   } else {
 // Append a full list of features, including any negative extensions so 
that
 // we override the CPU's features.
+populateNegativeRISCVFeatures(Features);
 std::vector FeatStrings =
 (*RII)->toFeatures(/* AddAllExtensions */ true);
 Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end());



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


[clang] [clang] The ms-extension __noop should return zero in a constexpr context. (PR #106849)

2024-08-31 Thread via cfe-commits


@@ -177,5 +177,21 @@ static void __builtin_cpu_init(); // expected-error 
{{static declaration of '__b
 #endif
 
 #ifdef _MSC_VER
-constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics
+constexpr int x = [] {
+  __noop;
+  return 0;
+}(); // expected-no-diagnostics
+static_assert([] { return __noop; }() == 0);
+static_assert([] { return __noop(4); }() == 0);
+extern int not_accessed;
+void not_called();
+static_assert([] { return __noop(not_accessed *= 6); }() == 0);
+static_assert([] { return __noop(not_called()); }() == 0);
+static_assert([] { return __noop(throw ""); }() == 0);
+static_assert([] { return __noop(throw "", throw ""); }() == 0);
+static_assert([] {
+  int a = 5;
+  __noop(++a);
+  return a;
+}() == 5);

c8ef wrote:

> Could you also add tests that calling it returns zero and doesn't evaluate 
> its arguments:
> 
> ```c++
> static_assert([]{ return __noop(4); }() == 0);
> extern int not_accessed;
> void not_called();
> static_assert([]{ return __noop(not_accessed *= 6); }() == 0);
> static_assert([]{ return __noop(not_called()); }() == 0);
> static_assert([]{ return __noop(throw ""); }() == 0);
> static_assert([]{ return __noop(throw "", throw ""); }() == 0);
> static_assert([]{ int a = 5; __noop(++a); return a; }() == 5);
> ```
> 
> This passes on MSVC (https://godbolt.org/z/nvxr3GxT4) but currently crashes 
> Clang.

Done.

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


[clang] [analyzer] [MallocChecker] suspect all release functions as candite for supression (PR #104599)

2024-08-31 Thread Pavel Skripkin via cfe-commits


@@ -3648,35 +3648,38 @@ PathDiagnosticPieceRef 
MallocBugVisitor::VisitNode(const ExplodedNode *N,
   return nullptr;
 }
 
-  // See if we're releasing memory while inlining a destructor
-  // (or one of its callees). This turns on various common
-  // false positive suppressions.
-  bool FoundAnyDestructor = false;
-  for (const LocationContext *LC = CurrentLC; LC; LC = LC->getParent()) {
-if (const auto *DD = dyn_cast(LC->getDecl())) {
-  if (isReferenceCountingPointerDestructor(DD)) {
-// This immediately looks like a reference-counting destructor.
-// We're bad at guessing the original reference count of the 
object,
-// so suppress the report for now.
-BR.markInvalid(getTag(), DD);
-  } else if (!FoundAnyDestructor) {
-assert(!ReleaseDestructorLC &&
+// See if we're releasing memory while inlining a destructor or
+// functions that decrement reference counters (or one of its callees).
+// This turns on various common false positive suppressions.
+bool FoundAnyReleaseFunction = false;
+for (const LocationContext *LC = CurrentLC; LC; LC = LC->getParent()) {
+  if (const auto *DD = dyn_cast(LC->getDecl())) {
+if (isReferenceCountingPointerDestructor(DD)) {
+  // This immediately looks like a reference-counting destructor.
+  // We're bad at guessing the original reference count of the
+  // object, so suppress the report for now.
+  BR.markInvalid(getTag(), DD);
+  continue;
+}
+  }
+
+  if (!FoundAnyReleaseFunction) {

pskrgag wrote:

So, based on my local testings:

Following does not produce warnings before and after this PR

```cpp
template  class DifferentlyNamedWithInlineRef {
  T *Ptr;
  _Atomic int refs;

public:
  DifferentlyNamedWithInlineRef(T *Ptr) : Ptr(Ptr), refs(1) {}

  DifferentlyNamedWithInlineRef(const DifferentlyNamedWithInlineRef &Other)
  : Ptr(Other.Ptr),
refs(__c11_atomic_fetch_add(&refs, 1, memory_order_relaxed) + 1) {}

  void releasePtr() { delete Ptr; }

  ~DifferentlyNamedWithInlineRef() {
if (__c11_atomic_fetch_sub(&refs, 1, memory_order_relaxed) == 1)
  releasePtr();
  }

  T *getPtr() const { return Ptr; } // no-warning
};

```

but following gives regression

```cpp
template 
class DifferentlyNamedOutlineRelease {
  T *Ptr;

public:
  DifferentlyNamedOutlineRelease(T *Ptr) : Ptr(Ptr) {
Ptr->incRef();
  }

  DifferentlyNamedOutlineRelease(const DifferentlyNamedOutlineRelease &Other) : 
Ptr(Other.Ptr) {
Ptr->incRef();
  }

  void releasePtr(void) {
  delete Ptr;
  }

  ~DifferentlyNamedOutlineRelease() {
if (Ptr->decRef() == 1)
  releasePtr();
  }

  T *getPtr() const { return Ptr; } // Warning here
};

```

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


[clang] [Clang][RISCV] Recognize unsupport target feature by supporting isValidFeatureName (PR #106495)

2024-08-31 Thread Piyou Chen via cfe-commits

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


[clang] [Clang][Parser] Fix name lookup of template parameters for out-of-line specializations (PR #101020)

2024-08-31 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/101020

>From 420705203a72c82446bd491b5766dde5fef116ff Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 29 Jul 2024 22:10:19 +0800
Subject: [PATCH 1/3] [Clang][Parser] Fix name lookup of template parameters
 for out-of-line specializations

Since the implementation of DR458 (d1446017), we have had an algorithm
that template parameters would take precedence over its parent scopes at
the name lookup. However, we failed to handle the following case where
the member function declaration is not yet deferral parsed:

```cpp
namespace NS {
  int CC;
  template  struct C;
}

template 
struct NS::C {
  void foo(CC);
};
```

When parsing the parameter of the function declaration `void foo(CC)`,
we used to perform a name lookup following such a Scope chain:

FunctionScope foo (failed)
RecordScope C (failed)
NamespaceScope NS (found `int CC`)

This doesn't seem right because according to "[temp.local]", a template
parameter scope should be searched before its parent scope to which the
parameter appertains. This patch corrects the search scopes by setting
a lookup Entity for template parameter Scopes so that we can bail out
in CppNameLookup() when reaching the RecordScope. Afterward, the
search chain would be like:

FunctionScope foo (failed)
RecordScope C (failed)
TemplateParameterScope of C (found CC)
---
 clang/lib/Sema/SemaTemplate.cpp   | 24 +++
 .../test/CXX/temp/temp.res/temp.local/p8.cpp  | 22 +
 2 files changed, 46 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 87b1f98bbe5ac9..a4ab9f99269927 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1876,6 +1876,27 @@ DeclResult Sema::CheckClassTemplate(
   if (Previous.isAmbiguous())
 return true;
 
+  // Let the template parameter scope enter the lookup chain of the current
+  // class template. For example, given
+  //
+  //  namespace ns {
+  //template  bool Param = false;
+  //template  struct N;
+  //  }
+  //
+  //  template  struct ns::N { void foo(Param); };
+  //
+  // When we reference Param inside the function parameter list, our name 
lookup
+  // chain for it should be like:
+  //  FunctionScope foo
+  //  -> RecordScope N
+  //  -> TemplateParamScope (where we will find Param)
+  //  -> NamespaceScope ns
+  //
+  // See also CppLookupName().
+  if (S->isTemplateParamScope())
+EnterTemplatedContext(S, SemanticContext);
+
   NamedDecl *PrevDecl = nullptr;
   if (Previous.begin() != Previous.end())
 PrevDecl = (*Previous.begin())->getUnderlyingDecl();
@@ -8085,6 +8106,9 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
 return true;
   }
 
+  if (S->isTemplateParamScope())
+EnterTemplatedContext(S, ClassTemplate->getTemplatedDecl());
+
   bool isMemberSpecialization = false;
   bool isPartialSpecialization = false;
 
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p8.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p8.cpp
index 6b2071eb12ce0f..7404c14118c76d 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p8.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p8.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
 namespace N { 
   enum { C };
@@ -151,4 +152,25 @@ namespace SearchClassBetweenTemplateParameterLists {
   void A::B::k(V) { // expected-error {{does not match}}
 BB bb; // expected-error {{incomplete type}}
   }
+
+  int CC;
+  template  struct C;
+#if __cplusplus >= 202003L
+  template  struct D;
+  template  concept True = true;
+#endif
 }
+
+template 
+struct SearchClassBetweenTemplateParameterLists::C {
+  void foo(CC) {} // This should find the template type parameter.
+};
+
+#if __cplusplus >= 202003L
+
+template 
+struct SearchClassBetweenTemplateParameterLists::D {
+  void foo(CC);
+};
+
+#endif

>From 91e0c068b35358a7d64d8bd87ebadbf92ece74d1 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sat, 31 Aug 2024 16:39:22 +0800
Subject: [PATCH 2/3] Add more tests & a release note

---
 .../test/CXX/temp/temp.res/temp.local/p8.cpp  | 27 ++-
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/clang/test/CXX/temp/temp.res/temp.local/p8.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p8.cpp
index 7404c14118c76d..56599985da06e9 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p8.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p8.cpp
@@ -155,21 +155,34 @@ namespace SearchClassBetweenTemplateParameterLists {
 
   int CC;
   template  struct C;
-#if __cplusplus >= 202003L
-  template  struct D;
-  template  concept True = true;
+  template  typename> struct D;
+#if __cplusplus >= 202002L
+  template  requires (CC) struct E;
+  template  struct F;
+  template  concept True = true;
 #endif
 }
 
 template 
 struct SearchClassBetweenTemplateParameterLists::C {
-  void foo(CC) {} // This should 

[clang] [Clang][RISCV] Recognize unsupport target feature by supporting isValidFeatureName (PR #106495)

2024-08-31 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/106495

>From e8f472674e0d1e70adcd1d29b8c902f4cd80f188 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Wed, 28 Aug 2024 21:15:57 -0700
Subject: [PATCH 1/4] [Clang][RISCV] Recognize unsupport feature by supporting
 isValidFeatureName

---
 clang/lib/Basic/Targets/RISCV.cpp   |  7 +++
 clang/lib/Basic/Targets/RISCV.h |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp | 15 +++
 clang/test/Sema/attr-target-riscv.c |  9 +
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index b89109e7725d44..9abef57d007468 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -478,3 +478,10 @@ bool RISCVTargetInfo::validateCpuSupports(StringRef 
Feature) const {
   // __riscv_feature_bits structure.
   return -1 != llvm::RISCVISAInfo::getRISCVFeaturesBitsInfo(Feature).second;
 }
+
+bool RISCVTargetInfo::isValidFeatureName(StringRef Name) const {
+  if (Name == "__RISCV_TargetAttrNeedOverride")
+return true;
+
+  return llvm::RISCVISAInfo::isSupportedExtensionFeature(Name);
+}
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 626274b8fc437c..b808ccc8e9cfe9 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -130,6 +130,7 @@ class RISCVTargetInfo : public TargetInfo {
   bool supportsCpuSupports() const override { return getTriple().isOSLinux(); }
   bool supportsCpuInit() const override { return getTriple().isOSLinux(); }
   bool validateCpuSupports(StringRef Feature) const override;
+  bool isValidFeatureName(StringRef Name) const override;
 };
 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
 public:
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1e074298ac5289..81cff8d7362ad5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2993,10 +2993,17 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, 
StringRef AttrStr) {
 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
<< Unknown << Tune << ParsedAttrs.Tune << Target;
 
-  if (Context.getTargetInfo().getTriple().isRISCV() &&
-  ParsedAttrs.Duplicate != "")
-return Diag(LiteralLoc, diag::err_duplicate_target_attribute)
-   << Duplicate << None << ParsedAttrs.Duplicate << Target;
+  if (Context.getTargetInfo().getTriple().isRISCV()) {
+if (ParsedAttrs.Duplicate != "")
+  return Diag(LiteralLoc, diag::err_duplicate_target_attribute)
+ << Duplicate << None << ParsedAttrs.Duplicate << Target;
+for (const auto &Feature : ParsedAttrs.Features) {
+  auto CurFeature = StringRef(Feature);
+  if (!CurFeature.starts_with("+") && !CurFeature.starts_with("-"))
+return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
+   << Unsupported << None << AttrStr << Target;
+}
+  }
 
   if (ParsedAttrs.Duplicate != "")
 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
diff --git a/clang/test/Sema/attr-target-riscv.c 
b/clang/test/Sema/attr-target-riscv.c
index ed4e2915d6c6ef..01d928c1d78e48 100644
--- a/clang/test/Sema/attr-target-riscv.c
+++ b/clang/test/Sema/attr-target-riscv.c
@@ -4,3 +4,12 @@
 int __attribute__((target("arch=rv64g"))) foo(void) { return 0; }
 //expected-error@+1 {{redefinition of 'foo'}}
 int __attribute__((target("arch=rv64gc"))) foo(void) { return 0; }
+
+//expected-warning@+1 {{unsupported 'notafeature' in the 'target' attribute 
string; 'target' attribute ignored}}
+int __attribute__((target("arch=+notafeature"))) UnsupportFeature(void) { 
return 0; }
+
+//expected-warning@+1 {{unsupported 'arch=+zba,zbb' in the 'target' attribute 
string; 'target' attribute ignored}}
+int __attribute__((target("arch=+zba,zbb"))) WithoutAddSigned(void) { return 
0; }
+
+//expected-warning@+1 {{unsupported 'arch=zba' in the 'target' attribute 
string; 'target' attribute ignored}}
+int __attribute__((target("arch=zba"))) WithoutAddSigned2(void) { return 0; }

>From ad95a3112c5349ea125d9c8d79cfa2f5e3d1d0a4 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Thu, 29 Aug 2024 00:39:08 -0700
Subject: [PATCH 2/4] Merge handleFullArchString logic, parseArchString will
 check whether start with "rv"

---
 clang/lib/Basic/Targets/RISCV.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 9abef57d007468..1ab9f19ab7a30c 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -388,7 +388,7 @@ static void handleFullArchString(StringRef FullArchStr,
   FullArchStr, /* EnableExperimentalExtension */ true);
   if (llvm::errorToBool(RII.takeError())) {
 // Forward the invalid FullArchStr.
-Features.push_back("+" + FullArchStr.str());
+Features.push_bac

[clang] 5b0bcec - [Clang][Parser] Fix name lookup of template parameters for out-of-line specializations (#101020)

2024-08-31 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-08-31T17:35:51+08:00
New Revision: 5b0bcec93dbc2e5bec049c452b157548334c5e28

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

LOG: [Clang][Parser] Fix name lookup of template parameters for out-of-line 
specializations (#101020)

Since the implementation of DR458 (d1446017), we have had an algorithm
that template parameters would take precedence over its parent scopes at
the name lookup. However, we failed to handle the following case where
the member function declaration is not yet deferral parsed (This is
where the patch of DR458 applies):

```cpp
namespace NS {
  int CC;
  template  struct C;
}

template 
struct NS::C {
  void foo(CC);
};
```

When parsing the parameter of the function declaration `void foo(CC)`,
we used to perform a name lookup following such a Scope chain:
```
FunctionScope foo (failed)
RecordScope C (failed)
NamespaceScope NS (found `int CC`)
(If failed)
TemplateParameterScope of C
```
This doesn't seem right because according to `[temp.local]`, a template
parameter scope should be searched before its parent scope to which the
parameter appertains. This patch corrects the search scopes by setting a
lookup Entity for template parameter Scopes so that we can bail out in
CppNameLookup() when reaching the RecordScope. Afterward, the search
chain would be like:
```
FunctionScope foo (failed)
RecordScope C (failed)
TemplateParameterScope of C (found CC)
(If failed)
NamespaceScope NS
```

Fixes https://github.com/llvm/llvm-project/issues/64082

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.res/temp.local/p8.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0ac3b65820b05..98fb0174d4a37e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -336,6 +336,8 @@ Bug Fixes to C++ Support
 - Mangle placeholders for deduced types as a template-prefix, such that 
mangling
   of template template parameters uses the correct production. (#GH106182)
 - Fixed an assertion failure when converting vectors to int/float with invalid 
expressions. (#GH105486)
+- Template parameter names are considered in the name lookup of out-of-line 
class template
+  specialization right before its declaration context. (#GH64082)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f8f41d0bafffc3..bf6b53700d90eb 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1873,6 +1873,27 @@ DeclResult Sema::CheckClassTemplate(
   if (Previous.isAmbiguous())
 return true;
 
+  // Let the template parameter scope enter the lookup chain of the current
+  // class template. For example, given
+  //
+  //  namespace ns {
+  //template  bool Param = false;
+  //template  struct N;
+  //  }
+  //
+  //  template  struct ns::N { void foo(Param); };
+  //
+  // When we reference Param inside the function parameter list, our name 
lookup
+  // chain for it should be like:
+  //  FunctionScope foo
+  //  -> RecordScope N
+  //  -> TemplateParamScope (where we will find Param)
+  //  -> NamespaceScope ns
+  //
+  // See also CppLookupName().
+  if (S->isTemplateParamScope())
+EnterTemplatedContext(S, SemanticContext);
+
   NamedDecl *PrevDecl = nullptr;
   if (Previous.begin() != Previous.end())
 PrevDecl = (*Previous.begin())->getUnderlyingDecl();
@@ -8089,6 +8110,9 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
 return true;
   }
 
+  if (S->isTemplateParamScope())
+EnterTemplatedContext(S, ClassTemplate->getTemplatedDecl());
+
   DeclContext *DC = ClassTemplate->getDeclContext();
 
   bool isMemberSpecialization = false;

diff  --git a/clang/test/CXX/temp/temp.res/temp.local/p8.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p8.cpp
index 6b2071eb12ce0f..56599985da06e9 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p8.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p8.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
 namespace N { 
   enum { C };
@@ -151,4 +152,38 @@ namespace SearchClassBetweenTemplateParameterLists {
   void A::B::k(V) { // expected-error {{does not match}}
 BB bb; // expected-error {{incomplete type}}
   }
+
+  int CC;
+  template  struct C;
+  template  typename> struct D;
+#if __cplusplus >= 202002L
+  template  requires (CC) struct E;
+  template  struct F;
+  template  concept True = true;
+#endif
 }
+
+template 
+struct SearchClassBetweenTemplateParameterLists::C {
+  void foo(CC); // This should find the template type parameter.
+};
+
+template  typename CC>
+struct SearchClassBe

[clang] [clang] function template non-call partial ordering fixes (PR #106829)

2024-08-31 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` 
running on `sanitizer-buildbot1` while building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[379/384] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[380/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[381/384] Generating Msan-x86_64-with-call-Test
[382/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[383/384] Generating Msan-x86_64-Test
[383/384] Running compiler_rt regression tests
llvm-lit: 
/home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 10229 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
TIMEOUT: SanitizerCommon-hwasan-x86_64-Linux :: Posix/fork_threaded.c (10229 of 
10229)
 TEST 'SanitizerCommon-hwasan-x86_64-Linux :: 
Posix/fork_threaded.c' FAILED 
Exit Code: -9
Timeout: Reached timeout of 900 seconds

Command Output (stderr):
--
RUN: at line 1: /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang  
-gline-tables-only -fsanitize=hwaddress -fuse-ld=lld 
-fsanitize-hwaddress-experimental-aliasing  -m64 -funwind-tables  
-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O0 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
 -o 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp
 && env HWASAN_OPTIONS=die_after_fork=0  
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp
+ /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang 
-gline-tables-only -fsanitize=hwaddress -fuse-ld=lld 
-fsanitize-hwaddress-experimental-aliasing -m64 -funwind-tables 
-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O0 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
 -o 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp
+ env HWASAN_OPTIONS=die_after_fork=0 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp

=
==56054==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 472 byte(s) in 15 object(s) allocated from:
#0 0x61eda0824945 in aligned_alloc 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:58:3
#1 0x61eda09140df in llvm::allocate_buffer(unsigned long, unsigned long) 
llvm-link

SUMMARY: HWAddressSanitizer: 472 byte(s) leaked in 15 allocation(s).

=
==56054==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 64 byte(s) in 1 object(s) allocated from:
==56054==ERROR: HWAddressSanitizer: tag-mismatch on address 0x581600b0 at 
pc 0x61eda0830bc7
READ of size 160 at 0x581600b0 tags: 07/06(65) (ptr/mem) in thread T2

=
==55996==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1760 byte(s) in 42 object(s) allocated from:
#0 0x61eda0824945 in aligned_alloc 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:58:3
#1 0x61eda09140df in llvm::allocate_buffer(unsigned long, unsigned long) 
llvm-link

Direct leak of 780 byte(s) in 1 object(s) allocated from:
#0 0x61eda0824ef9 in calloc 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:127:3
#1 0x61eda09067f5 in llvm::safe_calloc(unsigned long, unsigned long) 
llvm-link

Direct leak of 728 byte(s) in 4 object(s) allocated from:
#0 0x61eda0825374 in malloc 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:151:3
Step 9 (test compiler-rt symbolizer) failure: test compiler-rt symbolizer 
(failure)
...
[379/384] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[380/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[381/384] Generating Msan-x86_64-with-call-

[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread Julian Schmidt via cfe-commits

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


[clang] [clang] fix range of empty enumeration without fixed underlying type (PR #106841)

2024-08-31 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang-tools-extra] [NFC][clang-tidy] reword diagnostic note in definitions-in-headers (PR #106862)

2024-08-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Julian Schmidt (5chmidti)


Changes

`make as inline` made little sense here, so I changed the `make` to `mark`
and added `the definition` as well.


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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp 
(+1-1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index 21008bc144b91a..ee869256898989 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -102,7 +102,7 @@ void DefinitionsInHeadersCheck::check(const 
MatchFinder::MatchResult &Result) {
 // inline is not allowed for main function.
 if (FD->isMain())
   return;
-diag(FD->getLocation(), /*Description=*/"make as 'inline'",
+diag(FD->getLocation(), "mark the definition as 'inline'",
  DiagnosticIDs::Note)
 << FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
   } else if (const auto *VD = dyn_cast(ND)) {

``




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


[clang] [Clang][Parser] Fix name lookup of template parameters for out-of-line specializations (PR #101020)

2024-08-31 Thread Younan Zhang via cfe-commits

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


[clang] [clang-tools-extra] Add function check for windows platform (PR #106581)

2024-08-31 Thread via cfe-commits

https://github.com/fawdlstty updated 
https://github.com/llvm/llvm-project/pull/106581

>From f169f3c57a0a55c1a0dbb8f965bc17a87ceb98d7 Mon Sep 17 00:00:00 2001
From: fawdlstty 
Date: Fri, 30 Aug 2024 00:23:39 +0800
Subject: [PATCH 1/3] add check for windows platforms api

---
 .../bugprone/NotNullTerminatedResultCheck.cpp |  2 +-
 clang/docs/analyzer/checkers.rst  |  2 +-
 clang/include/clang/Basic/Builtins.td | 22 +++
 .../Checkers/CStringChecker.cpp   |  6 +
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
index 977241e91b9a93..e2cf96c88b90bd 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -106,7 +106,7 @@ static const CallExpr *getStrlenExpr(const 
MatchFinder::MatchResult &Result) {
 if (const Decl *D = StrlenExpr->getCalleeDecl())
   if (const FunctionDecl *FD = D->getAsFunction())
 if (const IdentifierInfo *II = FD->getIdentifier())
-  if (II->isStr("strlen") || II->isStr("wcslen"))
+  if (II->isStr("strlen") || II->isStr("lstrlen") || 
II->isStr("wcslen"))
 return StrlenExpr;
 
   return nullptr;
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 89a1018e14c0e6..ca675ae37929fe 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1582,7 +1582,7 @@ Check the size argument passed into C string functions 
for common erroneous patt
 unix.cstring.NullArg (C)
 
 Check for null pointers being passed as arguments to C string functions:
-``strlen, strnlen, strcpy, strncpy, strcat, strncat, strcmp, strncmp, 
strcasecmp, strncasecmp, wcslen, wcsnlen``.
+``strlen, lstrlen, strnlen, strcpy, lstrcpy, strncpy, strcat, lstrcat, 
strncat, strcmp, strncmp, strcasecmp, strncasecmp, wcslen, wcsnlen``.
 
 .. code-block:: c
 
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8668b25661dec8..cbc5fc52326ad2 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4788,3 +4788,25 @@ def ArithmeticFence : LangBuiltin<"ALL_LANGUAGES"> {
   let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
+
+// Windows - WinBase.h
+def LStrLen : LibBuiltin<"WinBase.h"> {
+  let Spellings = ["lstrlen"];
+  let Attributes = [NoThrow, Constexpr];
+  let Prototype = "int(LPCTSTR)";
+  let AddBuiltinPrefixedAlias = 1;
+}
+
+def LStrCpy : LibBuiltin<"WinBase.h"> {
+  let Spellings = ["lstrcpy"];
+  let Attributes = [NoThrow];
+  let Prototype = "LPCTSTR(LPTSTR, LPCTSTR)";
+  let AddBuiltinPrefixedAlias = 1;
+}
+
+def LStrCat : LibBuiltin<"WinBase.h"> {
+  let Spellings = ["lstrcat"];
+  let Attributes = [NoThrow];
+  let Prototype = "LPTSTR(LPTSTR, LPCTSTR)";
+  let AddBuiltinPrefixedAlias = 1;
+}
diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 8dd08f14b2728b..2adf538486176d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -150,6 +150,8 @@ class CStringChecker : public Checker< eval::Call,
   // FIXME: C23 introduces 'memset_explicit', maybe also model that
   {{CDM::CLibraryMaybeHardened, {"strcpy"}, 2},
&CStringChecker::evalStrcpy},
+  {{CDM::CLibraryMaybeHardened, {"lstrcpy"}, 2},
+   &CStringChecker::evalStrcpy},
   {{CDM::CLibraryMaybeHardened, {"strncpy"}, 3},
&CStringChecker::evalStrncpy},
   {{CDM::CLibraryMaybeHardened, {"stpcpy"}, 2},
@@ -158,12 +160,16 @@ class CStringChecker : public Checker< eval::Call,
&CStringChecker::evalStrlcpy},
   {{CDM::CLibraryMaybeHardened, {"strcat"}, 2},
&CStringChecker::evalStrcat},
+  {{CDM::CLibraryMaybeHardened, {"lstrcat"}, 2},
+   &CStringChecker::evalStrcat},
   {{CDM::CLibraryMaybeHardened, {"strncat"}, 3},
&CStringChecker::evalStrncat},
   {{CDM::CLibraryMaybeHardened, {"strlcat"}, 3},
&CStringChecker::evalStrlcat},
   {{CDM::CLibraryMaybeHardened, {"strlen"}, 1},
&CStringChecker::evalstrLength},
+  {{CDM::CLibraryMaybeHardened, {"lstrlen"}, 1},
+   &CStringChecker::evalstrLength},
   {{CDM::CLibrary, {"wcslen"}, 1}, &CStringChecker::evalstrLength},
   {{CDM::CLibraryMaybeHardened, {"strnlen"}, 2},
&CStringChecker::evalstrnLength},

>From 52d40b558e14948c38c8c5f75245c5ba08bd3fea Mon Sep 17 00:00:00 2001
From: fawdlstty 
Date: Fri, 30 Aug 2024 00:33:22 +0800
Subject: [PATCH 2/3] add to insecureAPI

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

diff --git a/clang/docs/analyzer/checkers.rst 

[clang] [clang] Fix crash in code with StmtExpr and atomic char load in Expr::EvaluateAsRValue. (PR #106751)

2024-08-31 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/106751

>From 6ce4604725d36afaea17cf533d422a978c4389ff Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Fri, 30 Aug 2024 15:34:34 +
Subject: [PATCH] fix cast

---
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/AST/atomic-expr.c   | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/atomic-expr.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e8a4d1d3c74102..0571771e2a7e7d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14458,7 +14458,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
   case CK_ZeroToOCLOpaqueType:
-  case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
   case CK_FloatingToFixedPoint:
@@ -14482,6 +14481,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_UserDefinedConversion:
   case CK_LValueToRValue:
   case CK_AtomicToNonAtomic:
+  case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_LValueToRValueBitCast:
   case CK_HLSLArrayRValue:
diff --git a/clang/test/AST/atomic-expr.c b/clang/test/AST/atomic-expr.c
new file mode 100644
index 00..0826a6491e8a6a
--- /dev/null
+++ b/clang/test/AST/atomic-expr.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// expected-no-diagnostics
+
+typedef _Atomic char atomic_char;
+
+atomic_char counter;
+
+char load_plus_one() {
+  return ({ counter; }) + 1;
+}
\ No newline at end of file

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


[clang] [clang] NFCI: don't check deduced constraints when partial ordering (PR #106882)

2024-08-31 Thread Younan Zhang via cfe-commits

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

LGTM, but please wait for others' opinions before merging.

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


[clang-tools-extra] [clang-tidy] Suggest using reinterpret_cast in bugprone-casting-thro… (PR #106784)

2024-08-31 Thread Julian Schmidt via cfe-commits

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


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


[clang] [clang] [docs] Clarify the issue with compiler-rt on Windows/MSVC (PR #106875)

2024-08-31 Thread Martin Storsjö via cfe-commits

https://github.com/mstorsjo created 
https://github.com/llvm/llvm-project/pull/106875

Compiler-rt does support Windows just fine, even if outdated docs pages didn't 
list it as one of the supported OSes, this is being rectified in 
https://github.com/llvm/llvm-project/pull/106874.

MinGW is another environment configuration on Windows, where compiler-rt or 
libgcc is linked in automatically, so there's no issue with having such 
builtins functions available.

For MSVC style environments, compiler-rt builtins do work just fine, but Clang 
doesn't automatically link them in. See e.g. 
https://discourse.llvm.org/t/improve-autolinking-of-compiler-rt-and-libc-on-windows-with-lld-link/71392
 for a discussion on how to improve this situation. But none of that issue is 
that compiler-rt itself wouldn't support Windows.

From 9ff3b1526e8b43b4d5856983340b8641b74ba3cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Sun, 1 Sep 2024 00:55:25 +0300
Subject: [PATCH] [clang] [docs] Clarify the issue with compiler-rt on
 Windows/MSVC

Compiler-rt does support Windows just fine, even if outdated docs
pages didn't list it as one of the supported OSes, this is being
rectified in https://github.com/llvm/llvm-project/pull/106874.

MinGW is another environment configuration on Windows, where
compiler-rt or libgcc is linked in automatically, so there's no
issue with having such builtins functions available.

For MSVC style environments, compiler-rt builtins do work just fine,
but Clang doesn't automatically link them in. See e.g.
https://discourse.llvm.org/t/improve-autolinking-of-compiler-rt-and-libc-on-windows-with-lld-link/71392
for a discussion on how to improve this situation. But none of that
issue is that compiler-rt itself wouldn't support Windows.
---
 clang/www/c_status.html | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index 91638331be877a..255690cd6d34e2 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -1057,8 +1057,8 @@ C99 implementation status
   conformance to Annex G.
   
   _Complex support requires an underlying support library
-  such as compiler-rt to provide functions like __divsc3,
-  but compiler-rt is not supported on Windows.
+  such as compiler-rt to provide functions like __divsc3.
+  Compiler-rt isn't linked in automatically in MSVC style environments.
 
   
 

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


[clang] [clang][bytecode] Fix diagnosting reads from temporaries (PR #106868)

2024-08-31 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/106868

Fix the DeclID not being set in global temporaries and use the same strategy 
for deciding if a temporary is readable as the current interpreter.

>From 21f0a354dad22ac9fa540413cd859a5d6bd0904c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 31 Aug 2024 19:26:45 +0200
Subject: [PATCH] [clang][bytecode] Fix diagnosting reads from temporaries

Fix the DeclID not being set in global temporaries and use the same
strategy for deciding if a temporary is readable as the current
interpreter.
---
 clang/lib/AST/ByteCode/Compiler.cpp|  3 ++-
 clang/lib/AST/ByteCode/Interp.cpp  | 21 +
 clang/test/AST/ByteCode/references.cpp | 13 +++--
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index dced9ea3493732..1ddaa5bd41df75 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -3772,7 +3772,6 @@ VarCreationState Compiler::visitVarDecl(const 
VarDecl *VD,
 
 auto initGlobal = [&](unsigned GlobalIndex) -> bool {
   assert(Init);
-  DeclScope LocalScope(this, VD);
 
   if (VarT) {
 if (!this->visit(Init))
@@ -3796,6 +3795,8 @@ VarCreationState Compiler::visitVarDecl(const 
VarDecl *VD,
   return this->emitPopPtr(Init);
 };
 
+DeclScope LocalScope(this, VD);
+
 // We've already seen and initialized this global.
 if (std::optional GlobalIndex = P.getGlobal(VD)) {
   if (P.getPtrGlobal(*GlobalIndex).isInitialized())
diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 42012767c22332..3d75f2ce7183a6 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -181,16 +181,21 @@ static bool CheckTemporary(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
 if (!Ptr.isStaticTemporary())
   return true;
 
-if (Ptr.getDeclDesc()->getType().isConstQualified())
+const auto *MTE = dyn_cast_if_present(
+Ptr.getDeclDesc()->asExpr());
+if (!MTE)
   return true;
 
-if (S.P.getCurrentDecl() == ID)
-  return true;
-
-const SourceInfo &E = S.Current->getSource(OpPC);
-S.FFDiag(E, diag::note_constexpr_access_static_temporary, 1) << AK;
-S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here);
-return false;
+// FIXME(perf): Since we do this check on every Load from a static
+// temporary, it might make sense to cache the value of the
+// isUsableInConstantExpressions call.
+if (!MTE->isUsableInConstantExpressions(S.getASTContext()) &&
+Ptr.block()->getEvalID() != S.Ctx.getEvalID()) {
+  const SourceInfo &E = S.Current->getSource(OpPC);
+  S.FFDiag(E, diag::note_constexpr_access_static_temporary, 1) << AK;
+  S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here);
+  return false;
+}
   }
   return true;
 }
diff --git a/clang/test/AST/ByteCode/references.cpp 
b/clang/test/AST/ByteCode/references.cpp
index 9a790dc75d7308..7c1dccb1f9e341 100644
--- a/clang/test/AST/ByteCode/references.cpp
+++ b/clang/test/AST/ByteCode/references.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
-// RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=expected,both %s
+// RUN: %clang_cc1 -verify=ref,both %s
 
 
 constexpr int a = 10;
@@ -135,3 +135,12 @@ static_assert(nonextended_string_ref[2] == '\0', "");
 /// but taking its address is.
 int &&A = 12;
 int arr[!&A];
+
+namespace Temporaries {
+  struct A { int n; };
+  struct B { const A &a; };
+  const B j = {{1}}; // both-note {{temporary created here}}
+
+  static_assert(j.a.n == 1, "");  // both-error {{not an integral constant 
expression}} \
+  // both-note {{read of temporary is not 
allowed in a constant expression outside the expression that created the 
temporary}}
+}

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


[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread Julian Schmidt via cfe-commits


@@ -754,7 +765,7 @@ def main():
 language_restrict = (
 f"%(lang)s.{cpp_language_to_requirements.get(args.standard, 
'CPlusPlus')}"
 )
-elif language in ["objc", "objc++"]:
+else:  # "objc" or "objc++"
 language_restrict = "%(lang)s.ObjC"

5chmidti wrote:

This change would result in any language string that is not supported setting 
the language restriction to `ObjC` (e.g., `--language CUDA`).
I'd say keep the `elif` and do a
```c++
if language_restrict is None:
print(f"Unsupported language '{language}' was specified")
```
afterward

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


[clang] cfe331b - [clang] function template non-call partial ordering fixes (#106829)

2024-08-31 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-08-31T16:07:42-03:00
New Revision: cfe331b853003cea868b84295552cecea63ab153

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

LOG: [clang] function template non-call partial ordering fixes (#106829)

This applies to function template non-call partial ordering the same
provisional wording change applied in the call context: Don't perform
the consistency check on return type and parameters which didn't have
any template parameters deduced from.

Fixes regression introduced in #100692, which was reported on the PR.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaTemplate/GH18291.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 78c22a7dae7725..11bc9f2d1e7484 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -1187,9 +1187,8 @@ class PackDeductionScope {
 
 template 
 static TemplateDeductionResult DeduceForEachType(
-Sema &S, TemplateParameterList *TemplateParams, const QualType *Params,
-unsigned NumParams, const QualType *Args, unsigned NumArgs,
-TemplateDeductionInfo &Info,
+Sema &S, TemplateParameterList *TemplateParams, ArrayRef Params,
+ArrayRef Args, TemplateDeductionInfo &Info,
 SmallVectorImpl &Deduced, bool PartialOrdering,
 bool FinishingDeduction, T &&DeductFunc) {
   // C++0x [temp.deduct.type]p10:
@@ -1198,7 +1197,7 @@ static TemplateDeductionResult DeduceForEachType(
   //   corresponding parameter type Ai of the corresponding parameter-type-list
   //   of A. [...]
   unsigned ArgIdx = 0, ParamIdx = 0;
-  for (; ParamIdx != NumParams; ++ParamIdx) {
+  for (; ParamIdx != Params.size(); ++ParamIdx) {
 // Check argument types.
 const PackExpansionType *Expansion
 = 
dyn_cast(Params[ParamIdx]);
@@ -1206,7 +1205,7 @@ static TemplateDeductionResult DeduceForEachType(
   // Simple case: compare the parameter and argument types at this point.
 
   // Make sure we have an argument.
-  if (ArgIdx >= NumArgs)
+  if (ArgIdx >= Args.size())
 return TemplateDeductionResult::MiscellaneousDeductionFailure;
 
   if (isa(Args[ArgIdx])) {
@@ -1243,8 +1242,8 @@ static TemplateDeductionResult DeduceForEachType(
 
 // A pack scope with fixed arity is not really a pack any more, so is not
 // a non-deduced context.
-if (ParamIdx + 1 == NumParams || PackScope.hasFixedArity()) {
-  for (; ArgIdx < NumArgs && PackScope.hasNextElement(); ++ArgIdx) {
+if (ParamIdx + 1 == Params.size() || PackScope.hasFixedArity()) {
+  for (; ArgIdx < Args.size() && PackScope.hasNextElement(); ++ArgIdx) {
 // Deduce template arguments from the pattern.
 if (TemplateDeductionResult Result = DeductFunc(
 S, TemplateParams, ParamIdx, ArgIdx,
@@ -1274,7 +1273,7 @@ static TemplateDeductionResult DeduceForEachType(
   // by the expansion.
   std::optional NumExpansions = Expansion->getNumExpansions();
   if (NumExpansions && !PackScope.isPartiallyExpanded()) {
-for (unsigned I = 0; I != *NumExpansions && ArgIdx < NumArgs;
+for (unsigned I = 0; I != *NumExpansions && ArgIdx < Args.size();
  ++I, ++ArgIdx)
   PackScope.nextPackElement();
   }
@@ -1293,12 +1292,12 @@ static TemplateDeductionResult DeduceForEachType(
   // During partial ordering, if Ai was originally a function parameter pack:
   // - if P does not contain a function parameter type corresponding to Ai then
   //   Ai is ignored;
-  if (PartialOrdering && ArgIdx + 1 == NumArgs &&
+  if (PartialOrdering && ArgIdx + 1 == Args.size() &&
   isa(Args[ArgIdx]))
 return TemplateDeductionResult::Success;
 
   // Make sure we don't have any extra arguments.
-  if (ArgIdx < NumArgs)
+  if (ArgIdx < Args.size())
 return TemplateDeductionResult::MiscellaneousDeductionFailure;
 
   return TemplateDeductionResult::Success;
@@ -1314,12 +1313,8 @@ static TemplateDeductionResult DeduceForEachType(
 ///
 /// \param Params The list of parameter types
 ///
-/// \param NumParams The number of types in \c Params
-///
 /// \param Args The list of argument types
 ///
-/// \param NumArgs The number of types in \c Args
-///
 /// \param Info information about the template argument deduction itself
 ///
 /// \param Deduced the deduced template arguments
@@ -1341,15 +1336,14 @@ static TemplateDeductionResult DeduceForEachType(
 /// "success" result means that template argument deduction has not yet failed,
 /// but it may still fail, later, for other reasons.
 static TemplateDeductionResult DeduceTemplateArguments(
-Sema &S, TemplateParameterList *TemplateParams, const Qua

[clang] [RISCV][NFC] Reimplementation of target attribute override mechanism (PR #106680)

2024-08-31 Thread Piyou Chen via cfe-commits

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


[clang] [clang] fix range of empty enumeration without fixed underlying type (PR #106841)

2024-08-31 Thread via cfe-commits

https://github.com/keinflue updated 
https://github.com/llvm/llvm-project/pull/106841

>From 69ea0e56fcf84ca5951e73f89e3a1e02e303af91 Mon Sep 17 00:00:00 2001
From: keinflue <80230456+keinf...@users.noreply.github.com>
Date: Sat, 31 Aug 2024 11:27:57 +0200
Subject: [PATCH] [clang] fix range of empty enumeration without fixed
 underlying type

In C++ enumerations without fixed underlying type which have either no
enumerator or only enumerators with value 0 have a value set containing
only 0, instead of 0 and 1. See [decl.enum]/8.

Fixes #106815
---
 clang/lib/Sema/SemaChecking.cpp  |  1 -
 clang/lib/Sema/SemaDecl.cpp  | 11 +--
 clang/test/AST/ByteCode/cxx11.cpp|  8 ++--
 clang/test/CodeGenCXX/pr12251.cpp|  4 ++--
 clang/test/SemaCXX/constant-expression-cxx11.cpp |  8 ++--
 5 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b021e27209cf1b..5a092279ea12b0 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10284,7 +10284,6 @@ static bool AnalyzeBitFieldAssignment(Sema &S, 
FieldDecl *Bitfield, Expr *Init,
 // inconsistency by storing this as a signed type.
 if (S.getLangOpts().CPlusPlus11 &&
 !BitfieldEnumDecl->getIntegerTypeSourceInfo() &&
-BitfieldEnumDecl->getNumPositiveBits() > 0 &&
 BitfieldEnumDecl->getNumNegativeBits() == 0) {
   S.Diag(InitLoc, 
diag::warn_no_underlying_type_specified_for_enum_bitfield)
   << BitfieldEnumDecl;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6327ae9b99aa4c..3efd01673f40fa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19903,23 +19903,14 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, 
SourceRange BraceRange,
 
 // Keep track of the size of positive and negative values.
 if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
-  // If the enumerator is zero that should still be counted as a positive
-  // bit since we need a bit to store the value zero.
   unsigned ActiveBits = InitVal.getActiveBits();
-  NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
+  NumPositiveBits = std::max(NumPositiveBits, ActiveBits);
 } else {
   NumNegativeBits =
   std::max(NumNegativeBits, (unsigned)InitVal.getSignificantBits());
 }
   }
 
-  // If we have an empty set of enumerators we still need one bit.
-  // From [dcl.enum]p8
-  // If the enumerator-list is empty, the values of the enumeration are as if
-  // the enumeration had a single enumerator with value 0
-  if (!NumPositiveBits && !NumNegativeBits)
-NumPositiveBits = 1;
-
   // Figure out the type that should be used for this enum.
   QualType BestType;
   unsigned BestWidth;
diff --git a/clang/test/AST/ByteCode/cxx11.cpp 
b/clang/test/AST/ByteCode/cxx11.cpp
index 481e3da9289efa..ead47faffcf7a6 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -115,15 +115,19 @@ void testValueInRangeOfEnumerationValues() {
 
   constexpr E4 x11 = static_cast(0);
   constexpr E4 x12 = static_cast(1);
+  // both-error@-1 {{constexpr variable 'x12' must be initialized by a 
constant expression}}
+  // both-note@-2 {{integer value 1 is outside the valid range of values [0, 
0] for the enumeration type 'E4'}}
   constexpr E4 x13 = static_cast(2);
   // both-error@-1 {{constexpr variable 'x13' must be initialized by a 
constant expression}}
-  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
1] for the enumeration type 'E4'}}
+  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
0] for the enumeration type 'E4'}}
 
   constexpr EEmpty x14 = static_cast(0);
   constexpr EEmpty x15 = static_cast(1);
+  // both-error@-1 {{constexpr variable 'x15' must be initialized by a 
constant expression}}
+  // both-note@-2 {{integer value 1 is outside the valid range of values [0, 
0] for the enumeration type 'EEmpty'}}
   constexpr EEmpty x16 = static_cast(2);
   // both-error@-1 {{constexpr variable 'x16' must be initialized by a 
constant expression}}
-  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
1] for the enumeration type 'EEmpty'}}
+  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
0] for the enumeration type 'EEmpty'}}
 
   constexpr EFixed x17 = static_cast(100);
   constexpr EScoped x18 = static_cast(100);
diff --git a/clang/test/CodeGenCXX/pr12251.cpp 
b/clang/test/CodeGenCXX/pr12251.cpp
index bd5c85b83f2caf..5d0afb639d668d 100644
--- a/clang/test/CodeGenCXX/pr12251.cpp
+++ b/clang/test/CodeGenCXX/pr12251.cpp
@@ -18,14 +18,14 @@ e1 g1(e1 *x) {
   return *x;
 }
 // CHECK-LABEL: define{{.*}} i32 @_Z2g1P2e1
-// CHECK: ret i32 %0
+// CHECK: ret i32 0
 
 enum e2 { e2_a = 0 };
 e2 g2(e2 *x) {
   return *x;
 }
 // CHECK-LABEL: define{{.*}

[clang-tools-extra] [clang-tidy] fix nullptr dereference in bugprone-forwarding-reference (PR #106856)

2024-08-31 Thread Julian Schmidt via cfe-commits

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


[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-31 Thread Pavel Skripkin via cfe-commits

pskrgag wrote:

gentle ping

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


[clang] [clang] The ms-extension __noop should return zero in a constexpr context. (PR #106849)

2024-08-31 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/106849

>From 6ce4604725d36afaea17cf533d422a978c4389ff Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Fri, 30 Aug 2024 15:34:34 +
Subject: [PATCH 1/4] fix cast

---
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/AST/atomic-expr.c   | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/atomic-expr.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e8a4d1d3c74102..0571771e2a7e7d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14458,7 +14458,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
   case CK_ZeroToOCLOpaqueType:
-  case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
   case CK_FloatingToFixedPoint:
@@ -14482,6 +14481,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_UserDefinedConversion:
   case CK_LValueToRValue:
   case CK_AtomicToNonAtomic:
+  case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_LValueToRValueBitCast:
   case CK_HLSLArrayRValue:
diff --git a/clang/test/AST/atomic-expr.c b/clang/test/AST/atomic-expr.c
new file mode 100644
index 00..0826a6491e8a6a
--- /dev/null
+++ b/clang/test/AST/atomic-expr.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// expected-no-diagnostics
+
+typedef _Atomic char atomic_char;
+
+atomic_char counter;
+
+char load_plus_one() {
+  return ({ counter; }) + 1;
+}
\ No newline at end of file

>From f0957df83597a2c43a8510a83619ef67c918c7d6 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 31 Aug 2024 21:19:46 +0800
Subject: [PATCH 2/4] __noop should return 0

---
 clang/lib/AST/ExprConstant.cpp  | 4 ++--
 clang/test/SemaCXX/builtins.cpp | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0571771e2a7e7d..69d2707aed9171 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12720,8 +12720,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   }
 
   case Builtin::BI__noop:
-  // __noop always evaluates successfully
-return true;
+// __noop always evaluates successfully
+return false;
 
   case Builtin::BI__builtin_is_constant_evaluated: {
 const auto *Callee = Info.CurrentCall->getCallee();
diff --git a/clang/test/SemaCXX/builtins.cpp b/clang/test/SemaCXX/builtins.cpp
index c6fbb8b514d671..78344c45092a79 100644
--- a/clang/test/SemaCXX/builtins.cpp
+++ b/clang/test/SemaCXX/builtins.cpp
@@ -178,4 +178,5 @@ static void __builtin_cpu_init(); // expected-error 
{{static declaration of '__b
 
 #ifdef _MSC_VER
 constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics
+static_assert([] { return __noop; }() == 0);
 #endif

>From a53cbbb4f3aaf65d0ebb49602f76d7f648e80410 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 31 Aug 2024 21:22:47 +0800
Subject: [PATCH 3/4] Revert "fix cast"

This reverts commit 6ce4604725d36afaea17cf533d422a978c4389ff.
---
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/AST/atomic-expr.c   | 10 --
 2 files changed, 1 insertion(+), 11 deletions(-)
 delete mode 100644 clang/test/AST/atomic-expr.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 69d2707aed9171..57040043f74193 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14458,6 +14458,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
   case CK_ZeroToOCLOpaqueType:
+  case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
   case CK_FloatingToFixedPoint:
@@ -14481,7 +14482,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_UserDefinedConversion:
   case CK_LValueToRValue:
   case CK_AtomicToNonAtomic:
-  case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_LValueToRValueBitCast:
   case CK_HLSLArrayRValue:
diff --git a/clang/test/AST/atomic-expr.c b/clang/test/AST/atomic-expr.c
deleted file mode 100644
index 0826a6491e8a6a..00
--- a/clang/test/AST/atomic-expr.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only %s -verify
-// expected-no-diagnostics
-
-typedef _Atomic char atomic_char;
-
-atomic_char counter;
-
-char load_plus_one() {
-  return ({ counter; }) + 1;
-}
\ No newline at end of file

>From a3727d3ab517a78b85792378b473f3d531e8532c Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 31 Aug 2024 22:11:24 +0800
Subject: [PATCH 4/4] __noop should return 0

---
 clang/lib/AST/ExprConstant.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 57040043f74193..55b51c2d25f7f6 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b

[clang] [HLSL] Implement output parameter (PR #101083)

2024-08-31 Thread Chris B via cfe-commits

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


[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-31 Thread Balazs Benics via cfe-commits


@@ -50,6 +118,75 @@ class BuiltinFunctionChecker : public Checker {
 
 } // namespace
 
+std::pair
+BuiltinFunctionChecker::checkOverflow(CheckerContext &C, SVal RetVal,
+  QualType Res) const {
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  ASTContext &ACtx = C.getASTContext();
+
+  // Calling a builtin with a non-integer type result produces compiler error.
+  assert(Res->isIntegerType());
+
+  unsigned BitWidth = ACtx.getIntWidth(Res);
+  auto MinVal =
+  llvm::APSInt::getMinValue(BitWidth, Res->isUnsignedIntegerType());
+  auto MaxVal =
+  llvm::APSInt::getMaxValue(BitWidth, Res->isUnsignedIntegerType());
+
+  SVal IsLeMax =
+  SVB.evalBinOp(State, BO_LE, RetVal, nonloc::ConcreteInt(MaxVal), Res);
+  SVal IsGeMin =
+  SVB.evalBinOp(State, BO_GE, RetVal, nonloc::ConcreteInt(MinVal), Res);
+
+  auto [MayNotOverflow, MayOverflow] =
+  State->assume(IsLeMax.castAs());
+  auto [MayNotUnderflow, MayUnderflow] =
+  State->assume(IsGeMin.castAs());
+
+  return {MayOverflow || MayUnderflow, MayNotOverflow && MayNotUnderflow};
+}
+
+void BuiltinFunctionChecker::handleOverflowBuiltin(const CallEvent &Call,
+   CheckerContext &C,
+   BinaryOperator::Opcode Op,
+   QualType ResultType) const {
+  // Calling a builtin with an incorrect argument count produces compiler 
error.
+  assert(Call.getNumArgs() == 3);
+
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  const Expr *CE = Call.getOriginExpr();
+
+  SVal Arg1 = Call.getArgSVal(0);
+  SVal Arg2 = Call.getArgSVal(1);
+
+  SVal RetValMax = SVB.evalBinOp(State, Op, Arg1, Arg2,
+ getSufficientTypeForOverflowOp(C, 
ResultType));
+  SVal RetVal = SVB.evalBinOp(State, Op, Arg1, Arg2, ResultType);
+
+  auto [Overflow, NotOverflow] = checkOverflow(C, RetValMax, ResultType);
+  if (NotOverflow) {
+ProgramStateRef StateNoOverflow =
+State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(false));
+
+if (auto L = Call.getArgSVal(2).getAs()) {
+  StateNoOverflow =
+  StateNoOverflow->bindLoc(*L, RetVal, C.getLocationContext());
+
+  // Propagate taint if any of the argumets were tainted
+  if (isTainted(State, Arg1) || isTainted(State, Arg2))
+StateNoOverflow = addTaint(StateNoOverflow, *L);
+}
+
+C.addTransition(StateNoOverflow);

steakhal wrote:

This transition should add a NoteTag highlighting that we assumed to have no 
overflow iff the StateOverflow was also valid. In that case, it should probably 
also call trackExpressionValue on both or some of the operands that played a 
role in that decision.
@NagyDonat is usually against trackExprVal, so I'm tagging him.

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


[clang] [clang] NFCI: don't check deduced constraints when partial ordering (PR #106882)

2024-08-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/106882

We were incorrectly applying [temp.deduct]p5 to partial ordering.

Marked as NFCI as I don't think the difference is actually observable in 
practice.
During partial ordering, the deduced arguments will mostly be dependent and 
thus cannot be checked.
Otherwise, later during overload resolution, if deduction succeeds in both 
directions,
we will perform subsumption check for the constraints ([temp.func.order]p6).

>From 5670a0baba65ba31da082d3fb373b9c2a85a73c3 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 31 Aug 2024 23:13:50 -0300
Subject: [PATCH] [clang] NFCI: don't check deduced constraints when partial
 ordering

We were incorrectly applying [temp.deduct]p5 to partial ordering.

Marked as NFCI as I don't think the difference is actually observable
in practice. During partial ordering, the deduced arguments will
mostly be dependent and thus cannot be checked. Otherwise, later
during overload resolution, if deduction succeeds in both directions,
we will perform subsumption check for the constraints ([temp.func.order]p6).
---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 36 ++--
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 11bc9f2d1e7484..01f18e5a325197 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3313,10 +3313,12 @@ FinishTemplateArgumentDeduction(
   if (Trap.hasErrorOccurred())
 return TemplateDeductionResult::SubstitutionFailure;
 
-  if (auto Result = CheckDeducedArgumentConstraints(S, Partial, SugaredBuilder,
-CanonicalBuilder, Info);
-  Result != TemplateDeductionResult::Success)
-return Result;
+  if (!IsPartialOrdering) {
+if (auto Result = CheckDeducedArgumentConstraints(
+S, Partial, SugaredBuilder, CanonicalBuilder, Info);
+Result != TemplateDeductionResult::Success)
+  return Result;
+  }
 
   return TemplateDeductionResult::Success;
 }
@@ -3364,13 +3366,16 @@ static TemplateDeductionResult 
FinishTemplateArgumentDeduction(
   if (Trap.hasErrorOccurred())
 return TemplateDeductionResult::SubstitutionFailure;
 
-  if (auto Result = CheckDeducedArgumentConstraints(S, Template, 
SugaredBuilder,
-CanonicalBuilder, Info);
-  Result != TemplateDeductionResult::Success)
-return Result;
+  if (!PartialOrdering) {
+if (auto Result = CheckDeducedArgumentConstraints(
+S, Template, SugaredBuilder, CanonicalBuilder, Info);
+Result != TemplateDeductionResult::Success)
+  return Result;
+  }
 
   return TemplateDeductionResult::Success;
 }
+
 /// Complete template argument deduction for DeduceTemplateArgumentsFromType.
 /// FIXME: this is mostly duplicated with the above two versions. Deduplicate
 /// the three implementations.
@@ -5595,19 +5600,8 @@ static TemplateDeductionResult 
FinishTemplateArgumentDeduction(
   TDR != TemplateDeductionResult::Success)
 return TDR;
 
-  // C++20 [temp.deduct]p5 - Only check constraints when all parameters have
-  // been deduced.
-  if (!IsIncomplete) {
-if (auto Result = CheckDeducedArgumentConstraints(S, FTD, SugaredBuilder,
-  CanonicalBuilder, Info);
-Result != TemplateDeductionResult::Success)
-  return Result;
-  }
-
-  if (Trap.hasErrorOccurred())
-return TemplateDeductionResult::SubstitutionFailure;
-
-  return TemplateDeductionResult::Success;
+  return Trap.hasErrorOccurred() ? TemplateDeductionResult::SubstitutionFailure
+ : TemplateDeductionResult::Success;
 }
 
 /// Determine whether the function template \p FT1 is at least as

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


[clang] [clang] [docs] Clarify the issue with compiler-rt on Windows/MSVC (PR #106875)

2024-08-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Martin Storsjö (mstorsjo)


Changes

Compiler-rt does support Windows just fine, even if outdated docs pages didn't 
list it as one of the supported OSes, this is being rectified in 
https://github.com/llvm/llvm-project/pull/106874.

MinGW is another environment configuration on Windows, where compiler-rt or 
libgcc is linked in automatically, so there's no issue with having such 
builtins functions available.

For MSVC style environments, compiler-rt builtins do work just fine, but Clang 
doesn't automatically link them in. See e.g. 
https://discourse.llvm.org/t/improve-autolinking-of-compiler-rt-and-libc-on-windows-with-lld-link/71392
 for a discussion on how to improve this situation. But none of that issue is 
that compiler-rt itself wouldn't support Windows.

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


1 Files Affected:

- (modified) clang/www/c_status.html (+2-2) 


``diff
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index 91638331be877a..255690cd6d34e2 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -1057,8 +1057,8 @@ C99 implementation status
   conformance to Annex G.
   
   _Complex support requires an underlying support library
-  such as compiler-rt to provide functions like __divsc3,
-  but compiler-rt is not supported on Windows.
+  such as compiler-rt to provide functions like __divsc3.
+  Compiler-rt isn't linked in automatically in MSVC style environments.
 
   
 

``




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


[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2024-08-31 Thread via cfe-commits

https://github.com/dmasloff updated 
https://github.com/llvm/llvm-project/pull/106145

>From 568c99faf02964e278161bf1d8a469229e228758 Mon Sep 17 00:00:00 2001
From: dmasloff 
Date: Mon, 26 Aug 2024 22:11:05 +0300
Subject: [PATCH] [clang-format] Add new option: WrapNamespaceBodyWithNewlines

---
 clang/docs/ClangFormatStyleOptions.rst  |  42 
 clang/include/clang/Format/Format.h |  40 +++-
 clang/lib/Format/Format.cpp |  16 +-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  45 +
 clang/unittests/Format/FormatTest.cpp   | 205 
 5 files changed, 346 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index a427d7cd40fcdd..06ac88fc337983 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6652,6 +6652,48 @@ the configuration (without a prefix: ``Auto``).
 
   For example: BOOST_PP_STRINGIZE
 
+.. _WrapNamespaceBodyWithEmptyLines:
+
+**WrapNamespaceBodyWithEmptyLines** (``WrapNamespaceBodyWithEmptyLinesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Controls number of empty lines at the begging and at the end of
+  namespace definition.
+
+  Possible values:
+
+  * ``WNBWELS_Never`` (in configuration: ``Never``)
+Removes all empty lines at the beginning and at the end of
+namespace definition.
+
+.. code-block:: c++
+
+  namespace N1 {
+  namespace N2
+function();
+  }
+  }
+
+  * ``WNBWELS_Always`` (in configuration: ``Always``)
+Always adds an empty line at the beginning and at the end of
+namespace definition. MaxEmptyLinesToKeep is also applied, but
+empty lines between consecutive namespace declarations are
+always removed.
+
+.. code-block:: c++
+
+  namespace N1 {
+  namespace N2 {
+
+function();
+
+  }
+  }
+
+  * ``WNBWELS_Leave`` (in configuration: ``Leave``)
+Keeps existing newlines at the beginning and at the end of
+namespace definition using MaxEmptyLinesToKeep for formatting.
+
+
+
 .. END_FORMAT_STYLE_OPTIONS
 
 Adding additional style options
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index d8b62c7652a0f6..963c7cbe1f8809 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5057,6 +5057,43 @@ struct FormatStyle {
   /// \version 11
   std::vector WhitespaceSensitiveMacros;
 
+  /// Different styles for modify number of empty lines in
+  /// the beginning and at the of end of namespaces.
+  enum WrapNamespaceBodyWithEmptyLinesStyle : int8_t {
+/// Removes all empty lines at the beginning and at the end of
+/// namespace definition.
+/// \code
+///   namespace N1 {
+///   namespace N2
+/// function();
+///   }
+///   }
+/// \endcode
+WNBWELS_Never,
+/// Always adds an empty line at the beginning and at the end of
+/// namespace definition. MaxEmptyLinesToKeep is also applied, but
+/// empty lines between consecutive namespace declarations are
+/// always removed.
+/// \code
+///   namespace N1 {
+///   namespace N2 {
+///
+/// function();
+///
+///   }
+///   }
+/// \endcode
+WNBWELS_Always,
+/// Keeps existing newlines at the beginning and at the end of
+/// namespace definition using MaxEmptyLinesToKeep for formatting.
+WNBWELS_Leave
+  };
+
+  /// Controls number of empty lines at the begging and at the end of
+  /// namespace definition.
+  /// \version 19
+  WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines;
+
   bool operator==(const FormatStyle &R) const {
 return AccessModifierOffset == R.AccessModifierOffset &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
@@ -5234,7 +5271,8 @@ struct FormatStyle {
TypenameMacros == R.TypenameMacros && UseTab == R.UseTab &&
VerilogBreakBetweenInstancePorts ==
R.VerilogBreakBetweenInstancePorts &&
-   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros;
+   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
+   WrapNamespaceBodyWithEmptyLines == 
R.WrapNamespaceBodyWithEmptyLines;
   }
 
   std::optional GetLanguageStyle(LanguageKind Language) const;
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d2463b892fbb96..a0cbb888498b68 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -829,7 +829,18 @@ template <> struct 
ScalarEnumerationTraits {
   }
 };
 
-template <> struct MappingTraits {
+template <> struct 
ScalarEnumerationTraits {
+  static void
+  enumeration(IO &IO,
+  FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &Value) {
+IO.enumCase(Value, "Never", FormatStyle::WNBWELS_Never);
+IO.enumCase(Value, "Always", FormatStyle::WNBWELS_Always);
+IO.enumCase(Value, "Leave", FormatStyle::

[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2024-08-31 Thread Owen Pan via cfe-commits

owenca wrote:

Please run `git clang-format HEAD~` and `ninja clang-format-check-format` 
before pushing.

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


[clang-tools-extra] [clang-tidy] fix nullptr dereference in bugprone-forwarding-reference (PR #106856)

2024-08-31 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti created 
https://github.com/llvm/llvm-project/pull/106856

Previously, when checking if a `TemplateSpecializationType` is either
`enable_if` or `enable_if_t`, the AST matcher would call
`getTemplateName`, `getASTemplateDecl` and `getTemplatedDecl` in
succession to check the `NamedDecl` returned from `getTemplatedDecl` is
`std::enable_if[_t]`.
In the linked issue, the poitner returned by `getTemplatedDecl` is a
`nullptr` that is unconditionally accessed, resulting in a crash.
Instead, the checking is done on the `TemplateDecl` returned by
`getASTemplateDecl`.

Fixes #106333


>From b0ab3117e85aa7c4b8f91c94ee5392e2383bd67e Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 31 Aug 2024 16:56:54 +0200
Subject: [PATCH] [clang-tidy] fix nullptr dereference in
 bugprone-forwarding-reference

Previously, when checking if a `TemplateSpecializationType` is either
`enable_if` or `enable_if_t`, the AST matcher would call
`getTemplateName`, `getASTemplateDecl` and `getTemplatedDecl` in
succession to check the `NamedDecl` returned from `getTemplatedDecl` is
`std::enable_if[_t]`.
In the linked issue, the poitner returned by `getTemplatedDecl` is a
`nullptr` that is unconditionally accessed, resulting in a crash.
Instead, the checking is done on the `TemplateDecl` returned by
`getASTemplateDecl`.

Fixes #106333
---
 .../bugprone/ForwardingReferenceOverloadCheck.cpp | 15 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../bugprone/forwarding-reference-overload.cpp|  6 ++
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index c87b3ea7e26163..00e8f7e514368b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -9,7 +9,6 @@
 #include "ForwardingReferenceOverloadCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include 
 
 using namespace clang::ast_matchers;
 
@@ -19,14 +18,14 @@ namespace {
 // Check if the given type is related to std::enable_if.
 AST_MATCHER(QualType, isEnableIf) {
   auto CheckTemplate = [](const TemplateSpecializationType *Spec) {
-if (!Spec || !Spec->getTemplateName().getAsTemplateDecl()) {
+if (!Spec)
   return false;
-}
-const NamedDecl *TypeDecl =
-Spec->getTemplateName().getAsTemplateDecl()->getTemplatedDecl();
-return TypeDecl->isInStdNamespace() &&
-   (TypeDecl->getName() == "enable_if" ||
-TypeDecl->getName() == "enable_if_t");
+
+const TemplateDecl *TDecl = Spec->getTemplateName().getAsTemplateDecl();
+
+return TDecl && TDecl->isInStdNamespace() &&
+   (TDecl->getName() == "enable_if" ||
+TDecl->getName() == "enable_if_t");
   };
   const Type *BaseType = Node.getTypePtr();
   // Case: pointer or reference to enable_if.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b001a6ad446695..c2fdc7dc689fc1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -104,6 +104,10 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`bugprone-forwarding-reference-overload
+  ` check by fixing
+  a crash when determining if an ``enable_if[_t]`` was found.
+
 - Improved :doc:`modernize-use-std-format
   ` check to support replacing
   member function calls too.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
index 92dfb718bb51b7..27315199c7ebae 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
@@ -261,3 +261,9 @@ class Test11 {
   Test11(const Test11 &) = default;
   Test11(Test11 &&) = default;
 };
+
+template  typename T, typename U>
+struct gh106333
+{
+gh106333(U && arg1, T arg2) {}
+};

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


[clang] [clang] The ms-extension __noop should return zero in a constexpr context. (PR #106849)

2024-08-31 Thread via cfe-commits

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


[clang] [clang] function template non-call partial ordering fixes (PR #106829)

2024-08-31 Thread via cfe-commits

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


[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-31 Thread Balazs Benics via cfe-commits


@@ -0,0 +1,157 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -verify %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection
+
+#define __UINT_MAX__ (__INT_MAX__ * 2U + 1U)
+#define __INT_MIN__  (-__INT_MAX__ - 1)
+
+void clang_analyzer_dump_int(int);
+void clang_analyzer_dump_long(long);
+void clang_analyzer_eval(int);
+void clang_analyzer_warnIfReached(void);
+
+void test_add_nooverflow(void)
+{
+   int res;
+
+   if (__builtin_add_overflow(10, 20, &res)) {
+ clang_analyzer_warnIfReached();
+ return;
+   }
+
+   clang_analyzer_dump_int(res); //expected-warning{{30 S32b}}
+}
+
+void test_add_overflow(void)
+{
+   int res;
+
+   if (__builtin_add_overflow(__INT_MAX__, 1, &res)) {
+ clang_analyzer_dump_int(res); //expected-warning{{1st function call 
argument is an uninitialized value}}
+ return;
+   }
+
+   clang_analyzer_warnIfReached();
+}
+
+void test_add_underoverflow(void)
+{
+   int res;
+
+   if (__builtin_add_overflow(__INT_MIN__, -1, &res)) {
+ clang_analyzer_dump_int(res); //expected-warning{{1st function call 
argument is an uninitialized value}}
+ return;
+   }
+
+   clang_analyzer_warnIfReached();
+}
+
+void test_sub_underflow(void)
+{
+   int res;
+
+   if (__builtin_sub_overflow(__INT_MIN__, 10, &res)) {
+ return;
+   }
+
+   clang_analyzer_warnIfReached();
+}
+
+void test_sub_overflow(void)
+{
+   int res;
+
+   if (__builtin_sub_overflow(__INT_MAX__, -1, &res)) {
+ return;
+   }
+
+   clang_analyzer_warnIfReached();
+}
+
+void test_sub_nooverflow(void)
+{
+   int res;
+
+   if (__builtin_sub_overflow(__INT_MAX__, 1, &res)) {
+ clang_analyzer_warnIfReached();
+ return;
+   }
+
+   clang_analyzer_dump_int(res); //expected-warning{{2147483646 S32b}}
+}
+
+void test_mul_overrflow(void)
+{
+   int res;
+
+   if (__builtin_mul_overflow(__INT_MAX__, 2, &res)) {
+ return;
+   }
+
+   clang_analyzer_warnIfReached();
+}
+
+void test_mul_underrflow(void)
+{
+   int res;
+
+   if (__builtin_mul_overflow(__INT_MIN__, -2, &res)) {
+ return;
+   }
+
+   clang_analyzer_warnIfReached();
+}
+
+void test_mul_nooverflow(void)
+{
+   int res;
+
+   if (__builtin_mul_overflow(10, -2, &res)) {
+ clang_analyzer_warnIfReached();
+ return;
+   }
+
+   clang_analyzer_dump_int(res); //expected-warning{{-20 S32b}}
+}
+
+void test_nooverflow_diff_types(void)
+{
+   long res;
+
+   // This is not an overflow, since result type is long.
+   if (__builtin_add_overflow(__INT_MAX__, 1, &res)) {
+ clang_analyzer_warnIfReached();
+ return;
+   }
+
+   clang_analyzer_dump_long(res); //expected-warning{{2147483648 S64b}}
+}
+
+void test_uaddll_overflow_contraints(unsigned long a, unsigned long b)
+{
+   unsigned long long res;
+
+   if (a != 10)
+ return;
+   if (b != 10)

steakhal wrote:

Such constraints we call "perfect constraints" as they narrow down the value 
domain to a single value. After this, the engine will fold all uses of this 
into a concreteInt, eliminating the symbolic value.

Consequently, perfect constraints are different to common constraints. They 
should have separate tests.

That said, two symbolic values with half side constraints are missing. x>=(int 
max -2, y>= 10 for instance.

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


[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-31 Thread Balazs Benics via cfe-commits

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


[clang] [clang] fix range of empty enumeration without fixed underlying type (PR #106841)

2024-08-31 Thread via cfe-commits

https://github.com/keinflue created 
https://github.com/llvm/llvm-project/pull/106841

In C++ enumerations without fixed underlying type which have either no 
enumerator or only enumerators with value 0 have a value set containing only 0, 
instead of 0 and 1. See [decl.enum]/8.

This PR affects casts in C++ constant expressions, where casting a value of 1 
to such an enumeration type is now no longer permitted. It also affects code 
generation in C++ mode with `-fstrict-enums` which may now assume that loading 
from such enumeration types will always produce 0.

Fixes #106815

>From 4f6d2107fffe0ab15157c095f29fd3c45ddca889 Mon Sep 17 00:00:00 2001
From: keinflue <80230456+keinf...@users.noreply.github.com>
Date: Sat, 31 Aug 2024 11:27:57 +0200
Subject: [PATCH] [clang] fix range of empty enumeration without fixed
 underlying type

In C++ enumerations without fixed underlying type which have either no
enumerator or only enumerators with value 0 have a value set containing
only 0, instead of 0 and 1. See [decl.enum]/8.

Fixes #106815
---
 clang/lib/Sema/SemaChecking.cpp  |  1 -
 clang/lib/Sema/SemaDecl.cpp  | 11 +--
 clang/test/AST/ByteCode/cxx11.cpp|  8 ++--
 clang/test/CodeGenCXX/pr12251.cpp|  4 ++--
 clang/test/SemaCXX/constant-expression-cxx11.cpp |  8 ++--
 5 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b021e27209cf1b..5a092279ea12b0 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10284,7 +10284,6 @@ static bool AnalyzeBitFieldAssignment(Sema &S, 
FieldDecl *Bitfield, Expr *Init,
 // inconsistency by storing this as a signed type.
 if (S.getLangOpts().CPlusPlus11 &&
 !BitfieldEnumDecl->getIntegerTypeSourceInfo() &&
-BitfieldEnumDecl->getNumPositiveBits() > 0 &&
 BitfieldEnumDecl->getNumNegativeBits() == 0) {
   S.Diag(InitLoc, 
diag::warn_no_underlying_type_specified_for_enum_bitfield)
   << BitfieldEnumDecl;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6327ae9b99aa4c..3efd01673f40fa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19903,23 +19903,14 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, 
SourceRange BraceRange,
 
 // Keep track of the size of positive and negative values.
 if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
-  // If the enumerator is zero that should still be counted as a positive
-  // bit since we need a bit to store the value zero.
   unsigned ActiveBits = InitVal.getActiveBits();
-  NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
+  NumPositiveBits = std::max(NumPositiveBits, ActiveBits);
 } else {
   NumNegativeBits =
   std::max(NumNegativeBits, (unsigned)InitVal.getSignificantBits());
 }
   }
 
-  // If we have an empty set of enumerators we still need one bit.
-  // From [dcl.enum]p8
-  // If the enumerator-list is empty, the values of the enumeration are as if
-  // the enumeration had a single enumerator with value 0
-  if (!NumPositiveBits && !NumNegativeBits)
-NumPositiveBits = 1;
-
   // Figure out the type that should be used for this enum.
   QualType BestType;
   unsigned BestWidth;
diff --git a/clang/test/AST/ByteCode/cxx11.cpp 
b/clang/test/AST/ByteCode/cxx11.cpp
index 481e3da9289efa..ead47faffcf7a6 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -115,15 +115,19 @@ void testValueInRangeOfEnumerationValues() {
 
   constexpr E4 x11 = static_cast(0);
   constexpr E4 x12 = static_cast(1);
+  // both-error@-1 {{constexpr variable 'x12' must be initialized by a 
constant expression}}
+  // both-note@-2 {{integer value 1 is outside the valid range of values [0, 
0] for the enumeration type 'E4'}}
   constexpr E4 x13 = static_cast(2);
   // both-error@-1 {{constexpr variable 'x13' must be initialized by a 
constant expression}}
-  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
1] for the enumeration type 'E4'}}
+  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
0] for the enumeration type 'E4'}}
 
   constexpr EEmpty x14 = static_cast(0);
   constexpr EEmpty x15 = static_cast(1);
+  // both-error@-1 {{constexpr variable 'x15' must be initialized by a 
constant expression}}
+  // both-note@-2 {{integer value 1 is outside the valid range of values [0, 
0] for the enumeration type 'EEmpty'}}
   constexpr EEmpty x16 = static_cast(2);
   // both-error@-1 {{constexpr variable 'x16' must be initialized by a 
constant expression}}
-  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
1] for the enumeration type 'EEmpty'}}
+  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
0] for the enumeration type 'EEmpty'}}
 
   constexpr EFixed x17 = 

[clang] [analyzer] [MallocChecker] suspect all release functions as candite for supression (PR #104599)

2024-08-31 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 f0df4fbd0c7b6bb369ceaa1fd6f9e0c88d781ae5 
0ab7a5a7ee72a60b3a478a7c508779458348f993 --extensions cpp,c -- 
clang/test/Analysis/malloc-refcounted.c 
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
clang/test/Analysis/NewDelete-atomics.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index f1194eb20f..1f2dd42ed9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -3552,8 +3552,8 @@ PathDiagnosticPieceRef MallocBugVisitor::VisitNode(const 
ExplodedNode *N,
   const LocationContext *CurrentLC = N->getLocationContext();
 
   // If we find an atomic fetch_add or fetch_sub within the function in which
-  // the pointer was released (before the release), this is likely a release 
point
-  // of reference-counted object (like shared pointer).
+  // the pointer was released (before the release), this is likely a release
+  // point of reference-counted object (like shared pointer).
   //
   // Because we don't model atomics, and also because we don't know that the
   // original reference count is positive, we should not report use-after-frees
@@ -3567,7 +3567,8 @@ PathDiagnosticPieceRef MallocBugVisitor::VisitNode(const 
ExplodedNode *N,
   if (Op == AtomicExpr::AO__c11_atomic_fetch_add ||
   Op == AtomicExpr::AO__c11_atomic_fetch_sub) {
 BR.markInvalid(getTag(), S);
-// After report is considered invalid there is no need to proceed 
futher.
+// After report is considered invalid there is no need to proceed
+// futher.
 return nullptr;
   }
 } else if (const auto *CE = dyn_cast(S)) {
@@ -3666,14 +3667,16 @@ PathDiagnosticPieceRef 
MallocBugVisitor::VisitNode(const ExplodedNode *N,
   // object, so suppress the report for now.
   BR.markInvalid(getTag(), DD);
 
-  // After report is considered invalid there is no need to 
proceed futher.
+  // After report is considered invalid there is no need to proceed
+  // futher.
   return nullptr;
 }
 
 // Switch suspection to outer destructor to catch patterns like:
 //
 // SmartPointr::~SmartPointr() {
-//  if (__c11_atomic_fetch_sub(refcount, 1, memory_order_relaxed) 
== 1)
+//  if (__c11_atomic_fetch_sub(refcount, 1, memory_order_relaxed) 
==
+//  1)
 //release_resources();
 // }
 // void SmartPointr::release_resources() {
@@ -3683,15 +3686,15 @@ PathDiagnosticPieceRef 
MallocBugVisitor::VisitNode(const ExplodedNode *N,
 // This way ReleaseFunctionLC will point to outermost destructor 
and
 // it would be possible to catch wider range of FP.
 //
-// NOTE: it would be great to support smth like that in C, since 
currently
-// patterns like following won't be supressed:
-   //
-   // void doFree(struct Data *data) { free(data); }
-   // void putData(struct Data *data)
-   // {
-   //   if (refPut(data))
-   // doFree(data);
-   // }
+// NOTE: it would be great to support smth like that in C, since
+// currently patterns like following won't be supressed:
+//
+// void doFree(struct Data *data) { free(data); }
+// void putData(struct Data *data)
+// {
+//   if (refPut(data))
+// doFree(data);
+// }
 ReleaseFunctionLC = LC->getStackFrame();
   }
 }

``




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


[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread Nicolas van Kempen via cfe-commits


@@ -754,7 +765,7 @@ def main():
 language_restrict = (
 f"%(lang)s.{cpp_language_to_requirements.get(args.standard, 
'CPlusPlus')}"
 )
-elif language in ["objc", "objc++"]:
+else:  # "objc" or "objc++"
 language_restrict = "%(lang)s.ObjC"

nicovank wrote:

Other languages technically can not get to this point because of `choices = 
language_to_extension.keys()` which only contains `["c", "c++", "objc", 
"objc++"]`, but I agree keeping the condition is more robust in case this lists 
change.

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


[clang] [llvm] [Chore] Fix `formating` typos. NFC. (PR #106817)

2024-08-31 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/106817

>From dc9e84136e33c6ab35b1263382b740ff9a9dcd68 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 31 Aug 2024 09:30:49 +0800
Subject: [PATCH] fix formating typo

---
 clang/lib/Tooling/Refactoring/AtomicChange.cpp| 8 
 clang/tools/clang-format/ClangFormat.cpp  | 2 +-
 .../tests/functional/cases/test_create_cdb.py | 2 +-
 llvm/examples/ExceptionDemo/ExceptionDemo.cpp | 3 +--
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Tooling/Refactoring/AtomicChange.cpp 
b/clang/lib/Tooling/Refactoring/AtomicChange.cpp
index dfc98355c6642b..5bafe43aa92d6f 100644
--- a/clang/lib/Tooling/Refactoring/AtomicChange.cpp
+++ b/clang/lib/Tooling/Refactoring/AtomicChange.cpp
@@ -104,9 +104,9 @@ bool violatesColumnLimit(llvm::StringRef Code, unsigned 
ColumnLimit,
 }
 
 std::vector
-getRangesForFormating(llvm::StringRef Code, unsigned ColumnLimit,
-  ApplyChangesSpec::FormatOption Format,
-  const clang::tooling::Replacements &Replaces) {
+getRangesForFormatting(llvm::StringRef Code, unsigned ColumnLimit,
+   ApplyChangesSpec::FormatOption Format,
+   const clang::tooling::Replacements &Replaces) {
   // kNone suppresses formatting entirely.
   if (Format == ApplyChangesSpec::kNone)
 return {};
@@ -352,7 +352,7 @@ applyAtomicChanges(llvm::StringRef FilePath, 
llvm::StringRef Code,
 
   AllReplaces = AllReplaces.merge(HeaderSortingReplacements);
 
-  std::vector FormatRanges = getRangesForFormating(
+  std::vector FormatRanges = getRangesForFormatting(
   *ChangedCode, Spec.Style.ColumnLimit, Spec.Format, AllReplaces);
   if (!FormatRanges.empty()) {
 Replacements FormatReplacements =
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 54b1dacbbe854a..6aed46328f3469 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -703,7 +703,7 @@ int main(int argc, const char **argv) {
   FileNames.push_back(Line);
   LineNo++;
 }
-errs() << "Clang-formating " << LineNo << " files\n";
+errs() << "Clang-formatting " << LineNo << " files\n";
   }
 
   if (FileNames.empty())
diff --git 
a/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py 
b/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py
index 1675be3dc963d5..03f0da4ac6de30 100644
--- a/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py
+++ b/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py
@@ -121,7 +121,7 @@ def test_append_to_existing_cdb(self):
 self.assertEqual(5, self.count_entries(result))
 
 
-class ResultFormatingTest(unittest.TestCase):
+class ResultFormattingTest(unittest.TestCase):
 @staticmethod
 def run_intercept(tmpdir, command):
 result = os.path.join(tmpdir, "cdb.json")
diff --git a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp 
b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
index 27acb9a155ecd8..58367a2319981d 100644
--- a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
+++ b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
@@ -879,7 +879,6 @@ void generateStringPrint(llvm::LLVMContext &context,
   builder.CreateCall(printFunct, cast);
 }
 
-
 /// Generates code to print given runtime integer according to constant
 /// string format, and a given print function.
 /// @param context llvm context
@@ -887,7 +886,7 @@ void generateStringPrint(llvm::LLVMContext &context,
 /// @param builder builder instance
 /// @param printFunct function used to "print" integer
 /// @param toPrint string to print
-/// @param format printf like formating string for print
+/// @param format printf like formatting string for print
 /// @param useGlobal A value of true (default) indicates a GlobalValue is
 ///generated, and is used to hold the constant string. A value of
 ///false indicates that the constant string will be stored on the

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


[clang] [clang] fix range of empty enumeration without fixed underlying type (PR #106841)

2024-08-31 Thread via cfe-commits

https://github.com/keinflue updated 
https://github.com/llvm/llvm-project/pull/106841

>From 533f32f7be161bfec45ee93cef3fbd78fc55e721 Mon Sep 17 00:00:00 2001
From: keinflue <80230456+keinf...@users.noreply.github.com>
Date: Sat, 31 Aug 2024 11:27:57 +0200
Subject: [PATCH] [clang] fix range of empty enumeration without fixed
 underlying type

In C++ enumerations without fixed underlying type which have either no
enumerator or only enumerators with value 0 have a value set containing
only 0, instead of 0 and 1. See [decl.enum]/8.

Fixes #106815
---
 clang/lib/Sema/SemaChecking.cpp  |  1 -
 clang/lib/Sema/SemaDecl.cpp  | 11 +--
 clang/test/AST/ByteCode/cxx11.cpp|  8 ++--
 clang/test/CodeGenCXX/pr12251.cpp|  4 ++--
 clang/test/SemaCXX/constant-expression-cxx11.cpp |  8 ++--
 5 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b021e27209cf1b..5a092279ea12b0 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10284,7 +10284,6 @@ static bool AnalyzeBitFieldAssignment(Sema &S, 
FieldDecl *Bitfield, Expr *Init,
 // inconsistency by storing this as a signed type.
 if (S.getLangOpts().CPlusPlus11 &&
 !BitfieldEnumDecl->getIntegerTypeSourceInfo() &&
-BitfieldEnumDecl->getNumPositiveBits() > 0 &&
 BitfieldEnumDecl->getNumNegativeBits() == 0) {
   S.Diag(InitLoc, 
diag::warn_no_underlying_type_specified_for_enum_bitfield)
   << BitfieldEnumDecl;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6327ae9b99aa4c..3efd01673f40fa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19903,23 +19903,14 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, 
SourceRange BraceRange,
 
 // Keep track of the size of positive and negative values.
 if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
-  // If the enumerator is zero that should still be counted as a positive
-  // bit since we need a bit to store the value zero.
   unsigned ActiveBits = InitVal.getActiveBits();
-  NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
+  NumPositiveBits = std::max(NumPositiveBits, ActiveBits);
 } else {
   NumNegativeBits =
   std::max(NumNegativeBits, (unsigned)InitVal.getSignificantBits());
 }
   }
 
-  // If we have an empty set of enumerators we still need one bit.
-  // From [dcl.enum]p8
-  // If the enumerator-list is empty, the values of the enumeration are as if
-  // the enumeration had a single enumerator with value 0
-  if (!NumPositiveBits && !NumNegativeBits)
-NumPositiveBits = 1;
-
   // Figure out the type that should be used for this enum.
   QualType BestType;
   unsigned BestWidth;
diff --git a/clang/test/AST/ByteCode/cxx11.cpp 
b/clang/test/AST/ByteCode/cxx11.cpp
index 481e3da9289efa..ead47faffcf7a6 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -115,15 +115,19 @@ void testValueInRangeOfEnumerationValues() {
 
   constexpr E4 x11 = static_cast(0);
   constexpr E4 x12 = static_cast(1);
+  // both-error@-1 {{constexpr variable 'x12' must be initialized by a 
constant expression}}
+  // both-note@-2 {{integer value 1 is outside the valid range of values [0, 
0] for the enumeration type 'E4'}}
   constexpr E4 x13 = static_cast(2);
   // both-error@-1 {{constexpr variable 'x13' must be initialized by a 
constant expression}}
-  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
1] for the enumeration type 'E4'}}
+  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
0] for the enumeration type 'E4'}}
 
   constexpr EEmpty x14 = static_cast(0);
   constexpr EEmpty x15 = static_cast(1);
+  // both-error@-1 {{constexpr variable 'x15' must be initialized by a 
constant expression}}
+  // both-note@-2 {{integer value 1 is outside the valid range of values [0, 
0] for the enumeration type 'EEmpty'}}
   constexpr EEmpty x16 = static_cast(2);
   // both-error@-1 {{constexpr variable 'x16' must be initialized by a 
constant expression}}
-  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
1] for the enumeration type 'EEmpty'}}
+  // both-note@-2 {{integer value 2 is outside the valid range of values [0, 
0] for the enumeration type 'EEmpty'}}
 
   constexpr EFixed x17 = static_cast(100);
   constexpr EScoped x18 = static_cast(100);
diff --git a/clang/test/CodeGenCXX/pr12251.cpp 
b/clang/test/CodeGenCXX/pr12251.cpp
index bd5c85b83f2caf..5d0afb639d668d 100644
--- a/clang/test/CodeGenCXX/pr12251.cpp
+++ b/clang/test/CodeGenCXX/pr12251.cpp
@@ -18,14 +18,14 @@ e1 g1(e1 *x) {
   return *x;
 }
 // CHECK-LABEL: define{{.*}} i32 @_Z2g1P2e1
-// CHECK: ret i32 %0
+// CHECK: ret i32 0
 
 enum e2 { e2_a = 0 };
 e2 g2(e2 *x) {
   return *x;
 }
 // CHECK-LABEL: define{{.*}

[clang] [clang] function template non-call partial ordering fixes (PR #106829)

2024-08-31 Thread via cfe-commits


@@ -5635,123 +5627,95 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
 
   assert(Proto1 && Proto2 && "Function templates must have prototypes");
   TemplateParameterList *TemplateParams = FT2->getTemplateParameters();
-  SmallVector Deduced;
-  Deduced.resize(TemplateParams->size());
+  SmallVector Deduced(TemplateParams->size());
 
-  // C++0x [temp.deduct.partial]p3:
-  //   The types used to determine the ordering depend on the context in which
-  //   the partial ordering is done:
   TemplateDeductionInfo Info(Loc);
-  switch (TPOC) {
-  case TPOC_Call: {
-llvm::SmallBitVector HasDeducedParam(Args2.size());
-if (DeduceTemplateArguments(
-S, TemplateParams, Args2.data(), Args2.size(), Args1.data(),
-Args1.size(), Info, Deduced, TDF_None, /*PartialOrdering=*/true,
-/*HasDeducedAnyParam=*/nullptr,
-&HasDeducedParam) != TemplateDeductionResult::Success)
-  return false;
+  if (TPOC == TPOC_Other) {
+// We wouldn't be partial ordering these candidates if these didn't match.
+assert(Proto2->getMethodQuals() == Proto1->getMethodQuals());
+assert(Proto2->getRefQualifier() == Proto1->getRefQualifier());
+assert(Proto2->isVariadic() == Proto1->isVariadic());
 
-SmallVector DeducedArgs(Deduced.begin(),
- Deduced.end());
-Sema::InstantiatingTemplate Inst(
-S, Info.getLocation(), FT2, DeducedArgs,
-Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
-if (Inst.isInvalid())
-  return false;
-
-bool AtLeastAsSpecialized = true;
-S.runWithSufficientStackSpace(Info.getLocation(), [&] {
-  AtLeastAsSpecialized =
-  ::FinishTemplateArgumentDeduction(
-  S, FT2, Deduced, Info,
-  [&](Sema &S, FunctionTemplateDecl *FTD,
-  ArrayRef DeducedArgs) {
-return ::DeduceForEachType(
-S, TemplateParams, Args2.data(), Args2.size(), 
Args1.data(),
-Args1.size(), Info, Deduced,
-/*PartialOrdering=*/true, /*FinishingDeduction=*/true,
-[&](Sema &S, TemplateParameterList *, int ParamIdx,
-int ArgIdx, QualType P, QualType A,
-TemplateDeductionInfo &Info,
-SmallVectorImpl &Deduced,
-bool) {
-  // As a provisional fix for a core issue that does not
-  // exist yet, only check the consistency of parameters
-  // which participated in deduction. We still try to
-  // substitute them though.
-  return ::CheckDeductionConsistency(
-  S, FTD, ArgIdx, P, A, DeducedArgs,
-  HasDeducedParam[ParamIdx]);
-});
-  }) == TemplateDeductionResult::Success;
-});
-if (!AtLeastAsSpecialized)
-  return false;
-  } break;
-  case TPOC_Conversion:
-  case TPOC_Other: {
-//   - In the context of a call to a conversion operator, the return types
-// of the conversion function templates are used.
-//   - In other contexts (14.6.6.2) the function template's function type
-// is used.
-auto [A, P, TDF] = TPOC == TPOC_Other
-   ? std::make_tuple(FD1->getType(), FD2->getType(),
- TDF_AllowCompatibleFunctionType)
-   : std::make_tuple(Proto1->getReturnType(),
- Proto2->getReturnType(), 
TDF_None);
+assert(Args1.empty() && Args2.empty());
+Args1 = Proto1->getParamTypes();
+Args2 = Proto2->getParamTypes();
+  }
+  // C++26 [temp.deduct.partial]p3:
+  //   The types used to determine the ordering depend on the context in which
+  //   the partial ordering is done:
+  //   - In the context of a function call, the types used are those function
+  // parameter types for which the function call has arguments.
+  //   - In the context of a call to a conversion operator, the return types
+  // of the conversion function templates are used.
+  //   - In other contexts (14.6.6.2) the function template's function type
+  // is used.
+  bool HasDeducedAnyParamFromReturnType = false;
+  if (TPOC != TPOC_Call) {
 if (DeduceTemplateArgumentsByTypeMatch(
-S, TemplateParams, P, A, Info, Deduced, TDF,
+S, TemplateParams, Proto2->getReturnType(), 
Proto1->getReturnType(),
+Info, Deduced, TDF_None,
 /*PartialOrdering=*/true, /*DeducedFromArrayBound=*/false,
-/*HasDeducedAnyParam=*/nullptr) != 
TemplateDeductionResult::Success)
+&HasDeducedAnyParamFromReturnType) !=
+TemplateDeductionResult::Success)
   return false;
+  }
 
-SmallVector DeducedArgs(Deduced.begin(),
-  

[clang] [clang] The ms-extension __noop should return zero in a constexpr context. (PR #106849)

2024-08-31 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/106849

>From 6ce4604725d36afaea17cf533d422a978c4389ff Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Fri, 30 Aug 2024 15:34:34 +
Subject: [PATCH 1/5] fix cast

---
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/AST/atomic-expr.c   | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/atomic-expr.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e8a4d1d3c74102..0571771e2a7e7d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14458,7 +14458,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
   case CK_ZeroToOCLOpaqueType:
-  case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
   case CK_FloatingToFixedPoint:
@@ -14482,6 +14481,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_UserDefinedConversion:
   case CK_LValueToRValue:
   case CK_AtomicToNonAtomic:
+  case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_LValueToRValueBitCast:
   case CK_HLSLArrayRValue:
diff --git a/clang/test/AST/atomic-expr.c b/clang/test/AST/atomic-expr.c
new file mode 100644
index 00..0826a6491e8a6a
--- /dev/null
+++ b/clang/test/AST/atomic-expr.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// expected-no-diagnostics
+
+typedef _Atomic char atomic_char;
+
+atomic_char counter;
+
+char load_plus_one() {
+  return ({ counter; }) + 1;
+}
\ No newline at end of file

>From f0957df83597a2c43a8510a83619ef67c918c7d6 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 31 Aug 2024 21:19:46 +0800
Subject: [PATCH 2/5] __noop should return 0

---
 clang/lib/AST/ExprConstant.cpp  | 4 ++--
 clang/test/SemaCXX/builtins.cpp | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0571771e2a7e7d..69d2707aed9171 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12720,8 +12720,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   }
 
   case Builtin::BI__noop:
-  // __noop always evaluates successfully
-return true;
+// __noop always evaluates successfully
+return false;
 
   case Builtin::BI__builtin_is_constant_evaluated: {
 const auto *Callee = Info.CurrentCall->getCallee();
diff --git a/clang/test/SemaCXX/builtins.cpp b/clang/test/SemaCXX/builtins.cpp
index c6fbb8b514d671..78344c45092a79 100644
--- a/clang/test/SemaCXX/builtins.cpp
+++ b/clang/test/SemaCXX/builtins.cpp
@@ -178,4 +178,5 @@ static void __builtin_cpu_init(); // expected-error 
{{static declaration of '__b
 
 #ifdef _MSC_VER
 constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics
+static_assert([] { return __noop; }() == 0);
 #endif

>From a53cbbb4f3aaf65d0ebb49602f76d7f648e80410 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 31 Aug 2024 21:22:47 +0800
Subject: [PATCH 3/5] Revert "fix cast"

This reverts commit 6ce4604725d36afaea17cf533d422a978c4389ff.
---
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/AST/atomic-expr.c   | 10 --
 2 files changed, 1 insertion(+), 11 deletions(-)
 delete mode 100644 clang/test/AST/atomic-expr.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 69d2707aed9171..57040043f74193 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14458,6 +14458,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
   case CK_ZeroToOCLOpaqueType:
+  case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
   case CK_FloatingToFixedPoint:
@@ -14481,7 +14482,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
   case CK_UserDefinedConversion:
   case CK_LValueToRValue:
   case CK_AtomicToNonAtomic:
-  case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_LValueToRValueBitCast:
   case CK_HLSLArrayRValue:
diff --git a/clang/test/AST/atomic-expr.c b/clang/test/AST/atomic-expr.c
deleted file mode 100644
index 0826a6491e8a6a..00
--- a/clang/test/AST/atomic-expr.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only %s -verify
-// expected-no-diagnostics
-
-typedef _Atomic char atomic_char;
-
-atomic_char counter;
-
-char load_plus_one() {
-  return ({ counter; }) + 1;
-}
\ No newline at end of file

>From a3727d3ab517a78b85792378b473f3d531e8532c Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 31 Aug 2024 22:11:24 +0800
Subject: [PATCH 4/5] __noop should return 0

---
 clang/lib/AST/ExprConstant.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 57040043f74193..55b51c2d25f7f6 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b

[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread Julian Schmidt via cfe-commits


@@ -8,21 +8,19 @@
 #
 # 
===---===#
 
-from __future__ import print_function
-from __future__ import unicode_literals
-
 import argparse
 import io
 import itertools
 import os
 import re
 import sys
 import textwrap
+from typing import Optional, Tuple

5chmidti wrote:

Please add a note here about `typings.Tuple` being deprecated in Python 3.9 and 
forward, but it looks like LLVM is still on Python >=3.8 
(https://llvm.org/docs/GettingStarted.html#software) and the new way to write 
parameterized tuples is only available in 3.9+ 
(https://docs.python.org/3/library/typing.html#typing.Tuple)

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


[clang] [clang] fix range of empty enumeration without fixed underlying type (PR #106841)

2024-08-31 Thread via cfe-commits

cor3ntin wrote:

@shafik 

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


[clang] [llvm] Remove support for 3DNow!, both intrinsics and builtins. (PR #96246)

2024-08-31 Thread James Y Knight via cfe-commits

jyknight wrote:

I think we can just switch it to be a textual header; it no longer has any 
decls.

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


[clang] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)

2024-08-31 Thread Oleksandr T. via cfe-commits


@@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager 
&SourceMgr,
   return false;
 }
 
+static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) {

a-tarasyuk wrote:

@AaronBallman Thanks. Just to confirm, are future attribute names valid in 
previous versions? For instance, can `C++11` use the `deprecated` attribute 
from `C++14`?

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


[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank updated 
https://github.com/llvm/llvm-project/pull/106801

>From 17f4b4a4320ded64b4d6ea673508e3d2f470d0aa Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Sat, 31 Aug 2024 13:46:52 -0400
Subject: [PATCH] [clang-tidy] Add type annotations to add_new_check.py, fix
 minor bug

```
> python3 -m mypy --strict clang-tools-extra/clang-tidy/add_new_check.py
Success: no issues found in 1 source file
```

Also fix a bug when `--standard` is not provided on the command line: the
generated test case has a `None` causing issues:
```
> python3 clang-tools-extra/clang-tidy/add_new_check.py performance XXX
Updating clang-tools-extra/clang-tidy/performance/CMakeLists.txt...
Creating clang-tools-extra/clang-tidy/performance/XxxCheck.h...
Creating clang-tools-extra/clang-tidy/performance/XxxCheck.cpp...
Updating clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp...
Updating clang-tools-extra/docs/ReleaseNotes.rst...
Creating clang-tools-extra/test/clang-tidy/checkers/performance/XXX.cpp...
Creating clang-tools-extra/docs/clang-tidy/checks/performance/XXX.rst...
Updating clang-tools-extra/docs/clang-tidy/checks/list.rst...
Done. Now it's your turn!

> head -n 1 clang-tools-extra/test/clang-tidy/checkers/performance/XXX.cpp
// RUN: %check_clang_tidy None%s performance-XXX %t
```
---
 clang-tools-extra/clang-tidy/add_new_check.py | 91 +++
 1 file changed, 53 insertions(+), 38 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index bd69bddcc68256..d384dbae28abbc 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -8,9 +8,6 @@
 #
 # 
===---===#
 
-from __future__ import print_function
-from __future__ import unicode_literals
-
 import argparse
 import io
 import itertools
@@ -19,10 +16,13 @@
 import sys
 import textwrap
 
+# FIXME Python 3.9: Replace typing.Tuple with builtins.tuple.
+from typing import Optional, Tuple
+
 
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new
 # entry and 'False' if the entry already existed.
-def adapt_cmake(module_path, check_name_camel):
+def adapt_cmake(module_path: str, check_name_camel: str) -> bool:
 filename = os.path.join(module_path, "CMakeLists.txt")
 
 # The documentation files are encoded using UTF-8, however on Windows the
@@ -57,14 +57,14 @@ def adapt_cmake(module_path, check_name_camel):
 
 # Adds a header for the new check.
 def write_header(
-module_path,
-module,
-namespace,
-check_name,
-check_name_camel,
-description,
-lang_restrict,
-):
+module_path: str,
+module: str,
+namespace: str,
+check_name: str,
+check_name_camel: str,
+description: str,
+lang_restrict: str,
+) -> None:
 wrapped_desc = "\n".join(
 textwrap.wrap(
 description, width=80, initial_indent="/// ", 
subsequent_indent="/// "
@@ -139,7 +139,9 @@ class %(check_name_camel)s : public ClangTidyCheck {
 
 
 # Adds the implementation of the new check.
-def write_implementation(module_path, module, namespace, check_name_camel):
+def write_implementation(
+module_path: str, module: str, namespace: str, check_name_camel: str
+) -> None:
 filename = os.path.join(module_path, check_name_camel) + ".cpp"
 print("Creating %s..." % filename)
 with io.open(filename, "w", encoding="utf8", newline="\n") as f:
@@ -187,7 +189,7 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 
 
 # Returns the source filename that implements the module.
-def get_module_filename(module_path, module):
+def get_module_filename(module_path: str, module: str) -> str:
 modulecpp = list(
 filter(
 lambda p: p.lower() == module.lower() + "tidymodule.cpp",
@@ -198,7 +200,9 @@ def get_module_filename(module_path, module):
 
 
 # Modifies the module to include the new check.
-def adapt_module(module_path, module, check_name, check_name_camel):
+def adapt_module(
+module_path: str, module: str, check_name: str, check_name_camel: str
+) -> None:
 filename = get_module_filename(module_path, module)
 with io.open(filename, "r", encoding="utf8") as f:
 lines = f.readlines()
@@ -217,10 +221,10 @@ def adapt_module(module_path, module, check_name, 
check_name_camel):
 + '");\n'
 )
 
-lines = iter(lines)
+lines_iter = iter(lines)
 try:
 while True:
-line = next(lines)
+line = next(lines_iter)
 if not header_added:
 match = re.search('#include "(.*)"', line)
 if match:
@@ -247,10 +251,11 @@ def adapt_module(module_path, module, check_name, 
check_name_camel):
 # If we didn't find the check name on this 
line, look on the

[clang-tools-extra] [NFC][clang-tidy] reword diagnostic note in definitions-in-headers (PR #106862)

2024-08-31 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

I suppose it doesn't hurt to mention it. Don't tests need to be updated too?

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


[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread Nicolas van Kempen via cfe-commits

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


[clang] [clang] NFCI: don't check deduced constraints when partial ordering (PR #106882)

2024-08-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

We were incorrectly applying [temp.deduct]p5 to partial ordering.

Marked as NFCI as I don't think the difference is actually observable in 
practice.
During partial ordering, the deduced arguments will mostly be dependent and 
thus cannot be checked.
Otherwise, later during overload resolution, if deduction succeeds in both 
directions,
we will perform subsumption check for the constraints ([temp.func.order]p6).

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+15-21) 


``diff
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 11bc9f2d1e7484..01f18e5a325197 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3313,10 +3313,12 @@ FinishTemplateArgumentDeduction(
   if (Trap.hasErrorOccurred())
 return TemplateDeductionResult::SubstitutionFailure;
 
-  if (auto Result = CheckDeducedArgumentConstraints(S, Partial, SugaredBuilder,
-CanonicalBuilder, Info);
-  Result != TemplateDeductionResult::Success)
-return Result;
+  if (!IsPartialOrdering) {
+if (auto Result = CheckDeducedArgumentConstraints(
+S, Partial, SugaredBuilder, CanonicalBuilder, Info);
+Result != TemplateDeductionResult::Success)
+  return Result;
+  }
 
   return TemplateDeductionResult::Success;
 }
@@ -3364,13 +3366,16 @@ static TemplateDeductionResult 
FinishTemplateArgumentDeduction(
   if (Trap.hasErrorOccurred())
 return TemplateDeductionResult::SubstitutionFailure;
 
-  if (auto Result = CheckDeducedArgumentConstraints(S, Template, 
SugaredBuilder,
-CanonicalBuilder, Info);
-  Result != TemplateDeductionResult::Success)
-return Result;
+  if (!PartialOrdering) {
+if (auto Result = CheckDeducedArgumentConstraints(
+S, Template, SugaredBuilder, CanonicalBuilder, Info);
+Result != TemplateDeductionResult::Success)
+  return Result;
+  }
 
   return TemplateDeductionResult::Success;
 }
+
 /// Complete template argument deduction for DeduceTemplateArgumentsFromType.
 /// FIXME: this is mostly duplicated with the above two versions. Deduplicate
 /// the three implementations.
@@ -5595,19 +5600,8 @@ static TemplateDeductionResult 
FinishTemplateArgumentDeduction(
   TDR != TemplateDeductionResult::Success)
 return TDR;
 
-  // C++20 [temp.deduct]p5 - Only check constraints when all parameters have
-  // been deduced.
-  if (!IsIncomplete) {
-if (auto Result = CheckDeducedArgumentConstraints(S, FTD, SugaredBuilder,
-  CanonicalBuilder, Info);
-Result != TemplateDeductionResult::Success)
-  return Result;
-  }
-
-  if (Trap.hasErrorOccurred())
-return TemplateDeductionResult::SubstitutionFailure;
-
-  return TemplateDeductionResult::Success;
+  return Trap.hasErrorOccurred() ? TemplateDeductionResult::SubstitutionFailure
+ : TemplateDeductionResult::Success;
 }
 
 /// Determine whether the function template \p FT1 is at least as

``




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


[clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] [polly] [NFC] Add explicit #include llvm-config.h where its macros are used. (PR #106810)

2024-08-31 Thread Daniil Fukalov via cfe-commits

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


[clang-tools-extra] [clang-tidy] fix nullptr dereference in bugprone-forwarding-reference (PR #106856)

2024-08-31 Thread Julian Schmidt via cfe-commits

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


[clang] [clang] fix range of empty enumeration without fixed underlying type (PR #106841)

2024-08-31 Thread via cfe-commits

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


[clang] [clang-tools-extra] Add function check for windows platform (PR #106581)

2024-08-31 Thread via cfe-commits

https://github.com/fawdlstty updated 
https://github.com/llvm/llvm-project/pull/106581

>From f169f3c57a0a55c1a0dbb8f965bc17a87ceb98d7 Mon Sep 17 00:00:00 2001
From: fawdlstty 
Date: Fri, 30 Aug 2024 00:23:39 +0800
Subject: [PATCH 1/5] add check for windows platforms api

---
 .../bugprone/NotNullTerminatedResultCheck.cpp |  2 +-
 clang/docs/analyzer/checkers.rst  |  2 +-
 clang/include/clang/Basic/Builtins.td | 22 +++
 .../Checkers/CStringChecker.cpp   |  6 +
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
index 977241e91b9a93..e2cf96c88b90bd 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -106,7 +106,7 @@ static const CallExpr *getStrlenExpr(const 
MatchFinder::MatchResult &Result) {
 if (const Decl *D = StrlenExpr->getCalleeDecl())
   if (const FunctionDecl *FD = D->getAsFunction())
 if (const IdentifierInfo *II = FD->getIdentifier())
-  if (II->isStr("strlen") || II->isStr("wcslen"))
+  if (II->isStr("strlen") || II->isStr("lstrlen") || 
II->isStr("wcslen"))
 return StrlenExpr;
 
   return nullptr;
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 89a1018e14c0e6..ca675ae37929fe 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1582,7 +1582,7 @@ Check the size argument passed into C string functions 
for common erroneous patt
 unix.cstring.NullArg (C)
 
 Check for null pointers being passed as arguments to C string functions:
-``strlen, strnlen, strcpy, strncpy, strcat, strncat, strcmp, strncmp, 
strcasecmp, strncasecmp, wcslen, wcsnlen``.
+``strlen, lstrlen, strnlen, strcpy, lstrcpy, strncpy, strcat, lstrcat, 
strncat, strcmp, strncmp, strcasecmp, strncasecmp, wcslen, wcsnlen``.
 
 .. code-block:: c
 
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8668b25661dec8..cbc5fc52326ad2 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4788,3 +4788,25 @@ def ArithmeticFence : LangBuiltin<"ALL_LANGUAGES"> {
   let Attributes = [CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
+
+// Windows - WinBase.h
+def LStrLen : LibBuiltin<"WinBase.h"> {
+  let Spellings = ["lstrlen"];
+  let Attributes = [NoThrow, Constexpr];
+  let Prototype = "int(LPCTSTR)";
+  let AddBuiltinPrefixedAlias = 1;
+}
+
+def LStrCpy : LibBuiltin<"WinBase.h"> {
+  let Spellings = ["lstrcpy"];
+  let Attributes = [NoThrow];
+  let Prototype = "LPCTSTR(LPTSTR, LPCTSTR)";
+  let AddBuiltinPrefixedAlias = 1;
+}
+
+def LStrCat : LibBuiltin<"WinBase.h"> {
+  let Spellings = ["lstrcat"];
+  let Attributes = [NoThrow];
+  let Prototype = "LPTSTR(LPTSTR, LPCTSTR)";
+  let AddBuiltinPrefixedAlias = 1;
+}
diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 8dd08f14b2728b..2adf538486176d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -150,6 +150,8 @@ class CStringChecker : public Checker< eval::Call,
   // FIXME: C23 introduces 'memset_explicit', maybe also model that
   {{CDM::CLibraryMaybeHardened, {"strcpy"}, 2},
&CStringChecker::evalStrcpy},
+  {{CDM::CLibraryMaybeHardened, {"lstrcpy"}, 2},
+   &CStringChecker::evalStrcpy},
   {{CDM::CLibraryMaybeHardened, {"strncpy"}, 3},
&CStringChecker::evalStrncpy},
   {{CDM::CLibraryMaybeHardened, {"stpcpy"}, 2},
@@ -158,12 +160,16 @@ class CStringChecker : public Checker< eval::Call,
&CStringChecker::evalStrlcpy},
   {{CDM::CLibraryMaybeHardened, {"strcat"}, 2},
&CStringChecker::evalStrcat},
+  {{CDM::CLibraryMaybeHardened, {"lstrcat"}, 2},
+   &CStringChecker::evalStrcat},
   {{CDM::CLibraryMaybeHardened, {"strncat"}, 3},
&CStringChecker::evalStrncat},
   {{CDM::CLibraryMaybeHardened, {"strlcat"}, 3},
&CStringChecker::evalStrlcat},
   {{CDM::CLibraryMaybeHardened, {"strlen"}, 1},
&CStringChecker::evalstrLength},
+  {{CDM::CLibraryMaybeHardened, {"lstrlen"}, 1},
+   &CStringChecker::evalstrLength},
   {{CDM::CLibrary, {"wcslen"}, 1}, &CStringChecker::evalstrLength},
   {{CDM::CLibraryMaybeHardened, {"strnlen"}, 2},
&CStringChecker::evalstrnLength},

>From 52d40b558e14948c38c8c5f75245c5ba08bd3fea Mon Sep 17 00:00:00 2001
From: fawdlstty 
Date: Fri, 30 Aug 2024 00:33:22 +0800
Subject: [PATCH 2/5] add to insecureAPI

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

diff --git a/clang/docs/analyzer/checkers.rst 

[clang] [clang][bytecode] Fix diagnosing reads from temporaries (PR #106868)

2024-08-31 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` 
running on `sanitizer-buildbot1` while building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[378/384] Generating Fuzzer-x86_64-Test
[379/384] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[380/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[381/384] Generating Msan-x86_64-with-call-Test
[382/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[383/384] Generating Msan-x86_64-Test
[383/384] Running compiler_rt regression tests
llvm-lit: 
/home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 4592 of 10298 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.
FAIL: SanitizerCommon-lsan-i386-Linux :: Linux/soft_rss_limit_mb_test.cpp (3032 
of 4592)
 TEST 'SanitizerCommon-lsan-i386-Linux :: 
Linux/soft_rss_limit_mb_test.cpp' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang  
--driver-mode=g++ -gline-tables-only -fsanitize=leak  -m32 -funwind-tables  
-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -o 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
+ /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang 
--driver-mode=g++ -gline-tables-only -fsanitize=leak -m32 -funwind-tables 
-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -o 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
RUN: at line 5: env 
LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1
  
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
 2>&1 | FileCheck 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -check-prefix=CHECK_MAY_RETURN_1
+ env 
LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1
 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
+ FileCheck 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -check-prefix=CHECK_MAY_RETURN_1
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp:68:24:
 error: CHECK_MAY_RETURN_1: expected string not found in input
// CHECK_MAY_RETURN_1: allocating 512 times
   ^
:52:44: note: scanning from here
Some of the malloc calls returned non-null: 256
   ^
:53:14: note: possible intended match here
==1969073==LeakSanitizer: soft rss limit unexhausted (220Mb vs 34Mb)
 ^

Input file: 
Check file: 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp

-dump-input=help explains the following input dump.

Input was:
<<
.
.
.
   47:  [256] 
   48:  [320] 
   49:  [384] 
   50:  [448] 
   51: Some of the malloc calls returned null: 256 
   52: Some of the malloc calls returned non-null: 256 
check:68'0X error: no match 
found
   53: ==1969073==LeakSanitizer: soft rss limit unexhausted (220Mb vs 
34Mb) 
Step 11 (test compiler-rt debug) failure: test compiler-rt debug (failure)
...
[378/384] Generating Fuzzer-x86_64-Test
[379/384] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[380/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[381/384] Generating Msan-x86_64-with-call-Test
[382/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[383/384] Generating Msan-x86_64-T

[clang-tools-extra] [NFC][clang-tidy] reword diagnostic note in definitions-in-headers (PR #106862)

2024-08-31 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

I don't think this would need a release note, but it is user-facing. WDYT?

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


[clang-tools-extra] [clang-tidy] Add type annotations to add_new_check.py, fix minor bug (PR #106801)

2024-08-31 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank updated 
https://github.com/llvm/llvm-project/pull/106801

>From 3945829650ac41f587c161cd6fb505225efba379 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Sat, 31 Aug 2024 13:40:14 -0400
Subject: [PATCH] [clang-tidy] Add type annotations to add_new_check.py, fix
 minor bug

```
> python3 -m mypy --strict clang-tools-extra/clang-tidy/add_new_check.py
Success: no issues found in 1 source file
```

Also fix a bug when `--standard` is not provided on the command line: the
generated test case has a `None` causing issues:
```
> python3 clang-tools-extra/clang-tidy/add_new_check.py performance XXX
Updating clang-tools-extra/clang-tidy/performance/CMakeLists.txt...
Creating clang-tools-extra/clang-tidy/performance/XxxCheck.h...
Creating clang-tools-extra/clang-tidy/performance/XxxCheck.cpp...
Updating clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp...
Updating clang-tools-extra/docs/ReleaseNotes.rst...
Creating clang-tools-extra/test/clang-tidy/checkers/performance/XXX.cpp...
Creating clang-tools-extra/docs/clang-tidy/checks/performance/XXX.rst...
Updating clang-tools-extra/docs/clang-tidy/checks/list.rst...
Done. Now it's your turn!

> head -n 1 clang-tools-extra/test/clang-tidy/checkers/performance/XXX.cpp
// RUN: %check_clang_tidy None%s performance-XXX %t
```
---
 clang-tools-extra/clang-tidy/add_new_check.py | 90 +++
 1 file changed, 52 insertions(+), 38 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index bd69bddcc68256..ce32b5de4192f8 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -8,9 +8,6 @@
 #
 # 
===---===#
 
-from __future__ import print_function
-from __future__ import unicode_literals
-
 import argparse
 import io
 import itertools
@@ -18,11 +15,13 @@
 import re
 import sys
 import textwrap
+# FIXME Python 3.9: Replace typing.Tuple with builtins.tuple.
+from typing import Optional, Tuple
 
 
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new
 # entry and 'False' if the entry already existed.
-def adapt_cmake(module_path, check_name_camel):
+def adapt_cmake(module_path: str, check_name_camel: str) -> bool:
 filename = os.path.join(module_path, "CMakeLists.txt")
 
 # The documentation files are encoded using UTF-8, however on Windows the
@@ -57,14 +56,14 @@ def adapt_cmake(module_path, check_name_camel):
 
 # Adds a header for the new check.
 def write_header(
-module_path,
-module,
-namespace,
-check_name,
-check_name_camel,
-description,
-lang_restrict,
-):
+module_path: str,
+module: str,
+namespace: str,
+check_name: str,
+check_name_camel: str,
+description: str,
+lang_restrict: str,
+) -> None:
 wrapped_desc = "\n".join(
 textwrap.wrap(
 description, width=80, initial_indent="/// ", 
subsequent_indent="/// "
@@ -139,7 +138,9 @@ class %(check_name_camel)s : public ClangTidyCheck {
 
 
 # Adds the implementation of the new check.
-def write_implementation(module_path, module, namespace, check_name_camel):
+def write_implementation(
+module_path: str, module: str, namespace: str, check_name_camel: str
+) -> None:
 filename = os.path.join(module_path, check_name_camel) + ".cpp"
 print("Creating %s..." % filename)
 with io.open(filename, "w", encoding="utf8", newline="\n") as f:
@@ -187,7 +188,7 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 
 
 # Returns the source filename that implements the module.
-def get_module_filename(module_path, module):
+def get_module_filename(module_path: str, module: str) -> str:
 modulecpp = list(
 filter(
 lambda p: p.lower() == module.lower() + "tidymodule.cpp",
@@ -198,7 +199,9 @@ def get_module_filename(module_path, module):
 
 
 # Modifies the module to include the new check.
-def adapt_module(module_path, module, check_name, check_name_camel):
+def adapt_module(
+module_path: str, module: str, check_name: str, check_name_camel: str
+) -> None:
 filename = get_module_filename(module_path, module)
 with io.open(filename, "r", encoding="utf8") as f:
 lines = f.readlines()
@@ -217,10 +220,10 @@ def adapt_module(module_path, module, check_name, 
check_name_camel):
 + '");\n'
 )
 
-lines = iter(lines)
+lines_iter = iter(lines)
 try:
 while True:
-line = next(lines)
+line = next(lines_iter)
 if not header_added:
 match = re.search('#include "(.*)"', line)
 if match:
@@ -247,10 +250,11 @@ def adapt_module(module_path, module, check_name, 
check_name_camel):
 # If we didn't find the check name on this 
line, look on the

  1   2   >