[PATCH] D127125: [clangd] Improve ObjC protocol suggestions from the index

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127125

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


[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-15 Thread Diana Picus via Phabricator via cfe-commits
rovka added inline comments.



Comment at: flang/test/Driver/linker-flags.f90:51
+! MSVC-NOT: libcmt
+! MSVC-NOT: oldnames
+! MSVC-SAME: "[[object_file]]"

awarzynski wrote:
> rovka wrote:
> > awarzynski wrote:
> > > rovka wrote:
> > > > mmuetzel wrote:
> > > > > Lines 50-51 seem to be duplicates of lines 44-45. Is this intentional?
> > > > Yes, I don't want those to appear either before or after the Fortran 
> > > > libs. I guess if we wanted to be pedantic we'd also check that they 
> > > > don't appear after the object_file, or between the libs and the 
> > > > subsystem, but that seems a bit much.
> > > Based on the [[ 
> > > https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-same-directive
> > >  | docs ]], I'd say that this would be the idiomatic way to do this:
> > > ```lang=bash
> > > ! MSVC-LABEL:
> > > ! MSVC-NOT: 
> > > ! MSVC-SAME:
> > > ```
> > > IIUC, the following would only be needed if there's a potential for 
> > > `libcmt` or `oldnames` to appear on a separate line:
> > > ```
> > > ```lang=bash
> > > ! MSVC-LABEL:
> > > ! MSVC-NOT: 
> > > ! MSVC-SAME:
> > > ! MSVC-NOT:
> > > ```
> > > But this wouldn't happen, right? (there's going to be only one linker 
> > > invocation). Also, you could just use [[ 
> > > https://llvm.org/docs/CommandGuide/FileCheck.html#options | 
> > > --implicit-check-not ]] :)
> > > Based on the [[ 
> > > https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-same-directive
> > >  | docs ]], I'd say that this would be the idiomatic way to do this:
> > > ```lang=bash
> > > ! MSVC-LABEL:
> > > ! MSVC-NOT: 
> > > ! MSVC-SAME:
> > > ```
> > 
> > Based on the same docs, I would say it shouldn't be enough to mention it 
> > just once. But that's just what I expect, the docs are completely unhelpful 
> > about the actual behaviour here. For instance, I would expect to be able to 
> > write
> > ```
> > ! MSVC-NOT: should-only-come-after-X
> > ! MSVC-SAME: X
> > ```
> > If the MSVC-NOT applies to the whole line, then lines with 'X 
> > should-come-after-X' get rejected, but imo they should be accepted (I'll 
> > admit I didn't actually verify this, and anyway the implicit-check-not 
> > makes the whole discussion moot).
> > 
> > > IIUC, the following would only be needed if there's a potential for 
> > > `libcmt` or `oldnames` to appear on a separate line:
> > > ```
> > > ```lang=bash
> > > ! MSVC-LABEL:
> > > ! MSVC-NOT: 
> > > ! MSVC-SAME:
> > > ! MSVC-NOT:
> > > ```
> > 
> > I agree that if there's no MSVC-SAME after the last MSVC-NOT, then the 
> > MSVC-NOT would apply to the following line. 
> > 
> > > But this wouldn't happen, right? (there's going to be only one linker 
> > > invocation). Also, you could just use [[ 
> > > https://llvm.org/docs/CommandGuide/FileCheck.html#options | 
> > > --implicit-check-not ]] :)
> > 
> > Wooow 😍 I didn't know about that one, I'll definitely update the test to 
> > use it, thanks! 
> > Based on the same docs, I would say it shouldn't be enough to mention it 
> > just once. 
> 
> I'm re-rereading the docs and agree. Sounds like `--implicit-check-not` is 
> the best option.
> 
> > For instance, I would expect to be able to write
> > ```
> > ! MSVC-NOT: should-only-come-after-X
> > ! MSVC-SAME: X
> > ```
> > If the MSVC-NOT applies to the whole line, then lines with 'X 
> > should-come-after-X' get rejected
> 
> I think that it //should// and //is// accepted. Example below:
> 
> **file.f90**
> ```lang=bash
> ! RUN: cat %S/test.f90 | FileCheck %s
> 
> ! CHECK-LABEL: my-label
> ! CHECK-NOT: should-only-come-after-X
> ! CHECK-SAME: X
> ! CHECK-SAME: should-only-come-after-X
> ```
> 
> **test.f90**
> ```lang=bash
> my-label X should-only-come-after-X
> ```
> I copied the above into the Driver test dir and run like this:
> ```
> $ bin/llvm-lit -va ../../flang/test/Driver/file.f90
> -- Testing: 1 tests, 1 workers --
> PASS: Flang :: Driver/file.f90 (1 of 1)
> 
> Testing Time: 0.03s
>   Passed: 1
> ```
> 
> Does this agree with your experiments?
> 
> #filecheck-is-confusing :)
Yep, that's what I was saying :)


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

https://reviews.llvm.org/D126291

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


[clang] 665da18 - [Clang] Add the `annotate_type` attribute

2022-06-15 Thread Martin Boehme via cfe-commits

Author: Martin Boehme
Date: 2022-06-15T09:47:28+02:00
New Revision: 665da187ccf338bad1560e8a960e8feaebb5c9d9

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

LOG: [Clang] Add the `annotate_type` attribute

This is an analog to the `annotate` attribute but for types. The intent is to 
allow adding arbitrary annotations to types for use in static analysis tools.

For details, see this RFC:

https://discourse.llvm.org/t/rfc-new-attribute-annotate-type-iteration-2/61378

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D111548

Added: 
clang/test/AST/attr-annotate-type.c
clang/test/CodeGenCXX/annotate-type.cpp
clang/test/Sema/annotate-type.c
clang/test/SemaCXX/annotate-type.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/TypePrinter.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaType.cpp
clang/unittests/AST/AttrTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7d84933b43bca..19ce6cb4d0d45 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -362,6 +362,9 @@ Attribute Changes in Clang
 - When the ``weak`` attribute is applied to a const qualified variable clang 
no longer
   tells the backend it is allowed to optimize based on initializer value.
 
+- Added the ``clang::annotate_type`` attribute, which can be used to add
+  annotations to types (see documentation for details).
+
 Windows Support
 ---
 

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 16384969f68e4..5f77073413fbf 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -804,6 +804,14 @@ def Annotate : InheritableParamAttr {
   let Documentation = [Undocumented];
 }
 
+def AnnotateType : TypeAttr {
+  let Spellings = [CXX11<"clang", "annotate_type">, C2x<"clang", 
"annotate_type">];
+  let Args = [StringArgument<"Annotation">, VariadicExprArgument<"Args">];
+  let HasCustomParsing = 1;
+  let AcceptsExprPack = 1;
+  let Documentation = [AnnotateTypeDocs];
+}
+
 def ARMInterrupt : InheritableAttr, TargetSpecificAttr {
   // NOTE: If you add any additional spellings, M68kInterrupt's,
   // MSP430Interrupt's, MipsInterrupt's and AnyX86Interrupt's spellings

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 59bbc80708ed5..6562e363a1ca7 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6487,6 +6487,40 @@ The full documentation is available here: 
https://docs.microsoft.com/en-us/windo
   }];
 }
 
+def AnnotateTypeDocs : Documentation {
+  let Category = DocCatType;
+  let Heading = "annotate_type";
+  let Content = [{
+This attribute is used to add annotations to types, typically for use by static
+analysis tools that are not integrated into the core Clang compiler (e.g.,
+Clang-Tidy checks or out-of-tree Clang-based tools). It is a counterpart to the
+`annotate` attribute, which serves the same purpose, but for declarations.
+
+The attribute takes a mandatory string literal argument specifying the
+annotation category and an arbitrary number of optional arguments that provide
+additional information specific to the annotation category. The optional
+arguments must be constant expressions of arbitrary type.
+
+For example:
+
+.. code-block:: c++
+
+  int* [[clang::annotate("category1", "foo", 1)]] 
f(int[[clang::annotate("category2")]] *);
+
+The attribute does not have any effect on the semantics of the type system,
+neither type checking rules, nor runtime semantics. In particular:
+
+- ``std::is_same Args);
 
+  /// ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs
+  /// (unless they are value dependent or type dependent). Returns false
+  /// and emits a diagnostic if one or more of the arguments could not be
+  /// folded into a constant.
+  bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI,
+MutableArrayRef Args);
+
   /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular
   /// declaration.
   void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI,

diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 38b5a5ab222f5..6b13d38060370 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1706,6 +1706,15 @@ void TypePrinter::printAttributedAfter(const 
AttributedType *T,
   if (T->getAttrKind() == attr::AddressSpace)
 return;
 
+  if (T->getAttrKind() == attr::AnnotateType)

[PATCH] D111548: [Clang] Add the `annotate_type` attribute

2022-06-15 Thread Martin Böhme via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
mboehme marked an inline comment as done.
Closed by commit rG665da187ccf3: [Clang] Add the `annotate_type` attribute 
(authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111548

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/attr-annotate-type.c
  clang/test/CodeGenCXX/annotate-type.cpp
  clang/test/Sema/annotate-type.c
  clang/test/SemaCXX/annotate-type.cpp
  clang/unittests/AST/AttrTest.cpp

Index: clang/unittests/AST/AttrTest.cpp
===
--- clang/unittests/AST/AttrTest.cpp
+++ clang/unittests/AST/AttrTest.cpp
@@ -7,7 +7,10 @@
 //===--===//
 
 #include "clang/AST/Attr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/AttrKinds.h"
+#include "clang/Tooling/Tooling.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -15,10 +18,154 @@
 
 namespace {
 
+using clang::ast_matchers::constantExpr;
+using clang::ast_matchers::equals;
+using clang::ast_matchers::functionDecl;
+using clang::ast_matchers::has;
+using clang::ast_matchers::hasDescendant;
+using clang::ast_matchers::hasName;
+using clang::ast_matchers::integerLiteral;
+using clang::ast_matchers::match;
+using clang::ast_matchers::selectFirst;
+using clang::ast_matchers::stringLiteral;
+using clang::ast_matchers::varDecl;
+using clang::tooling::buildASTFromCode;
+using clang::tooling::buildASTFromCodeWithArgs;
+
 TEST(Attr, Doc) {
   EXPECT_THAT(Attr::getDocumentation(attr::Used).str(),
   testing::HasSubstr("The compiler must emit the definition even "
  "if it appears to be unused"));
 }
 
+const FunctionDecl *getFunctionNode(ASTUnit *AST, const std::string &Name) {
+  auto Result =
+  match(functionDecl(hasName(Name)).bind("fn"), AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("fn");
+}
+
+const VarDecl *getVariableNode(ASTUnit *AST, const std::string &Name) {
+  auto Result = match(varDecl(hasName(Name)).bind("var"), AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("var");
+}
+
+template 
+void AssertAnnotatedAs(TypeLoc TL, llvm::StringRef annotation,
+   ModifiedTypeLoc &ModifiedTL,
+   const AnnotateTypeAttr **AnnotateOut = nullptr) {
+  const auto AttributedTL = TL.getAs();
+  ASSERT_FALSE(AttributedTL.isNull());
+  ModifiedTL = AttributedTL.getModifiedLoc().getAs();
+  ASSERT_TRUE(ModifiedTL);
+
+  ASSERT_NE(AttributedTL.getAttr(), nullptr);
+  const auto *Annotate = dyn_cast(AttributedTL.getAttr());
+  ASSERT_NE(Annotate, nullptr);
+  EXPECT_EQ(Annotate->getAnnotation(), annotation);
+  if (AnnotateOut) {
+*AnnotateOut = Annotate;
+  }
+}
+
+TEST(Attr, AnnotateType) {
+
+  // Test that the AnnotateType attribute shows up in the right places and that
+  // it stores its arguments correctly.
+
+  auto AST = buildASTFromCode(R"cpp(
+void f(int* [[clang::annotate_type("foo", "arg1", 2)]] *,
+   int [[clang::annotate_type("bar")]]);
+
+int [[clang::annotate_type("int")]] * [[clang::annotate_type("ptr")]]
+  array[10] [[clang::annotate_type("arr")]];
+
+void (* [[clang::annotate_type("funcptr")]] fp)(void);
+
+struct S { int mem; };
+int [[clang::annotate_type("int")]]
+S::* [[clang::annotate_type("ptr_to_mem")]] ptr_to_member = &S::mem;
+  )cpp");
+
+  {
+const FunctionDecl *Func = getFunctionNode(AST.get(), "f");
+
+// First parameter.
+const auto PointerTL = Func->getParamDecl(0)
+   ->getTypeSourceInfo()
+   ->getTypeLoc()
+   .getAs();
+ASSERT_FALSE(PointerTL.isNull());
+PointerTypeLoc PointerPointerTL;
+const AnnotateTypeAttr *Annotate;
+AssertAnnotatedAs(PointerTL.getPointeeLoc(), "foo", PointerPointerTL,
+  &Annotate);
+
+EXPECT_EQ(Annotate->args_size(), 2);
+const auto *StringLit = selectFirst(
+"str", match(constantExpr(hasDescendant(stringLiteral().bind("str"))),
+ *Annotate->args_begin()[0], AST->getASTContext()));
+ASSERT_NE(StringLit, nullptr);
+EXPECT_EQ(StringLit->getString(), "arg1");
+EXPECT_EQ(match(constantExpr(has(integerLiteral(equals(2)).bind("int"))),
+*Annotate->args_begin()[1], AST->getASTContext())
+  .size(),
+   

[PATCH] D127742: [analyzer][NFC] Prefer using isa<> instead getAs<> in conditions

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

In D127742#3582236 , @steakhal wrote:

> In D127742#3581874 , @martong wrote:
>
>> Why not replace all `getAs`?
>
> That's a massive change. I actually experimented with it and I see no 
> advantage with that.
>
>> I suppose you picked conditions because `isa` can have variadic parameters. 
>> If we are about to keep `getAs` then why not replace only those occurrences 
>> where we see the benefit of the variadic `isa`?
>
> I believe it reads more naturally. `getAs<>` should be used only if we care 
> about the value and don't know if it has one.

Ok, makes sense. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127742

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


[PATCH] D127306: [analyzer] Treat system globals as mutable if they are not const

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127306

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


[PATCH] D127763: [analyzer] Relax constraints on const qualified regions

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127763

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


[PATCH] D125291: Introduce @llvm.threadlocal.address intrinsic to access TLS variable

2022-06-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D125291#3581064 , @nikic wrote:

> In D125291#3548671 , @jyknight 
> wrote:
>
>> Anyhow -- I think the prototype I'm fiddling with is also along the path to 
>> the ideal long-term state, but pushing it beyond a prototype seems like 
>> it'll be a pain in the ass due to the bitcode compatibility requirement. 
>> (The bitcode upgrader would need to know how to transform all constant 
>> expressions using a TLS global into non-constant IR instructions, starting 
>> with a call to llvm.threadlocal.address -- in every function where the 
>> "constant" is referenced. For uses outside a function body, it transforms to 
>> an arbitrary address (e.g. null), instead.)
>
> I have implemented support for converting constant expressions to 
> instructions in the bitcode reader in https://reviews.llvm.org/D127729. This 
> was originally intended for constant expression removal, but I think with 
> that infrastructure in place, upgrading TLS global references to use an 
> intrinsic would be fairly simple.

Oh, it looks great! Especially in `getValueForInitializer`, we could solve the 
motivation problem given by @jyknight :

  @x = thread_local global i32 0, align 4
  @y = global i32* @x, align 8

Now we are possible to emit proper diagnostic message. The only issue is that 
the current framework of D127729  would map a 
constexpr into an instruction. But we might need to map a constexpr with TLS 
variables to multiple instructions (containing @llvm.threadaddress() 
intrinsics). But I believe this problem might be minor.

@jyknight How do you think about the status quo now?


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

https://reviews.llvm.org/D125291

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


[PATCH] D127799: [StaticAnalyzer] Remove dead code (DO NOT COMMIT)

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thanks!

What was your method to discover the unused code? Did you use an automated tool?




Comment at: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp:66
 
-  void dump() const;
   void dumpToStream(raw_ostream &os) const;

We shall not delete any `dump` or `LLVM_DUMP_METHOD` annotated function because 
they can be really useful in actual debugging, either in `gdb` or with other 
tools.



Comment at: clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp:30-33
-/// This checker documents the callback functions checkers can use to implement
-/// the custom handling of the specific events during path exploration as well
-/// as reporting bugs. Most of the callbacks are targeted at path-sensitive
-/// checking.

As the comment says, we need this to demonstrate and document what can be the 
possible callbacks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127799

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


[PATCH] D111521: [DebugInfo] Mark OpenMP generated functions as artificial

2022-06-15 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 437064.
alok added a comment.
Herald added a project: All.

Re-based and updated to include one negative testcase.
I could not find a test for VarDecl with DynamicInitKind::NoStub. There are 
constructors for other DynamicInitKind but not for NoStub. Please help me in 
case you are aware of the condition when it is produced.


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

https://reviews.llvm.org/D111521

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/OpenMP/outlined_artificial.c


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4096,7 +4096,8 @@
 Name = Name.substr(1);
 
   if (!HasDecl || D->isImplicit() || D->hasAttr() ||
-  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) 
{
+  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub) 
||
+  isa(D)) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubpr

[PATCH] D127832: [clangd] Always desugar type aliases in hover

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added subscribers: jeroen.dobbelaere, usaxena95, arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

The alias itself is already included in the definition section of the
hover (it's printed as spelled in source code). So it doesn't provide any value
when we print the aliases as-is.
Fixes https://github.com/clangd/clangd/issues/1134.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127832

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3206,6 +3206,30 @@
   ASSERT_TRUE(H);
   EXPECT_EQ(H->Definition, "int arr[]");
 }
+
+TEST(Hover, Typedefs) {
+  Annotations T(R"cpp(
+  template 
+  struct cond { using type = T; };
+  template 
+  struct cond { using type = F; };
+
+  template 
+  using type = typename cond::type;
+
+  void foo() {
+using f^oo = type;
+  }
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+
+  ASSERT_TRUE(H && H->Type);
+  EXPECT_EQ(H->Type->Type, "int");
+  EXPECT_EQ(H->Definition, "using foo = type");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -578,7 +578,7 @@
const SymbolIndex *Index,
const syntax::TokenBuffer &TB) {
   HoverInfo HI;
-  const ASTContext &Ctx = D->getASTContext();
+  ASTContext &Ctx = D->getASTContext();
 
   HI.AccessSpecifier = getAccessSpelling(D->getAccess()).str();
   HI.NamespaceScope = getNamespaceScope(D);
@@ -614,19 +614,17 @@
   if (const FunctionDecl *FD = getUnderlyingFunction(D))
 fillFunctionTypeAndParams(HI, D, FD, PP);
   else if (const auto *VD = dyn_cast(D))
-HI.Type = printType(VD->getType(), VD->getASTContext(), PP);
+HI.Type = printType(VD->getType(), Ctx, PP);
   else if (const auto *TTP = dyn_cast(D))
 HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
   else if (const auto *TTP = dyn_cast(D))
 HI.Type = printType(TTP, PP);
   else if (const auto *VT = dyn_cast(D))
-HI.Type =
-printType(VT->getTemplatedDecl()->getType(), VT->getASTContext(), PP);
+HI.Type = printType(VT->getTemplatedDecl()->getType(), Ctx, PP);
   else if (const auto *TN = dyn_cast(D))
-HI.Type = printType(TN->getUnderlyingType(), TN->getASTContext(), PP);
+HI.Type = printType(TN->getUnderlyingType().getDesugaredType(Ctx), Ctx, 
PP);
   else if (const auto *TAT = dyn_cast(D))
-HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(),
-TAT->getASTContext(), PP);
+HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
 
   // Fill in value with evaluated initializer if possible.
   if (const auto *Var = dyn_cast(D)) {


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3206,6 +3206,30 @@
   ASSERT_TRUE(H);
   EXPECT_EQ(H->Definition, "int arr[]");
 }
+
+TEST(Hover, Typedefs) {
+  Annotations T(R"cpp(
+  template 
+  struct cond { using type = T; };
+  template 
+  struct cond { using type = F; };
+
+  template 
+  using type = typename cond::type;
+
+  void foo() {
+using f^oo = type;
+  }
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+
+  ASSERT_TRUE(H && H->Type);
+  EXPECT_EQ(H->Type->Type, "int");
+  EXPECT_EQ(H->Definition, "using foo = type");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -578,7 +578,7 @@
const SymbolIndex *Index,
const syntax::TokenBuffer &TB) {
   HoverInfo HI;
-  const ASTContext &Ctx = D->getASTContext();
+  ASTContext &Ctx = D->getASTContext();
 
   HI.AccessSpecifier = getAccessSpelling(D->getAccess()).str();
   HI.NamespaceScope = getNamespaceScope(D);
@@ -614,19 +614,17 @@
   if (const FunctionDecl *FD = getUnderlyingFunction(D))
 fillFunctionTypeAndParams(HI, D, FD, PP);
   else if (const auto *VD = dyn

[PATCH] D127833: [clangd] Enable AKA type printing by default

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This has been tested on a large set of c++ developers for a long while,
without any crashes or complaints.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127833

Files:
  clang-tools-extra/clangd/Config.h


Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -129,7 +129,7 @@
   /// Configures hover feature.
   struct {
 /// Whether hover show a.k.a type.
-bool ShowAKA = false;
+bool ShowAKA = true;
   } Hover;
 
   struct {


Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -129,7 +129,7 @@
   /// Configures hover feature.
   struct {
 /// Whether hover show a.k.a type.
-bool ShowAKA = false;
+bool ShowAKA = true;
   } Hover;
 
   struct {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127629: [clang] Use correct visibility parameters when following a Using declaration

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!

do you have commit access or should i land this for you? if i should, can you 
provide an email address for attribution of the commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127629

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


[PATCH] D124690: [clangd] add inlay hints for std::forward-ed parameter packs

2022-06-15 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Finished looking through the patch; I found it nicely organized and fairly easy 
to understand (as easy as code involving the analysis of C++ variadic templates 
can be, anyways :-D)!




Comment at: clang-tools-extra/clangd/AST.cpp:682
+  if (const auto *TTPD =
+  dyn_cast(TemplateParams.back())) {
+const auto *TTPT =

I don't think there is any requirement that a pack be a trailing **template** 
parameter. For example, the following is valid:

```
template 
void foo(A, B...);

void bar() {
  foo(1, 2, 3);
}
```



Comment at: clang-tools-extra/clangd/AST.cpp:761
+  // inspects the given callee with the given args to check whether it
+  // contains Parameters, and sets FullyResolved, PartiallyResolved and
+  // NextTarget accordingly.

These names (FullyResolved, PartiallyResolved, NextTarget) sound like they 
might be leftovers from a previous implementation?



Comment at: clang-tools-extra/clangd/AST.cpp:831
+  static FunctionDecl *resolveOverload(UnresolvedLookupExpr *Lookup,
+   CallExpr *D) {
+FunctionDecl *MatchingDecl = nullptr;

nit: `D` is an odd name for a `CallExpr`, maybe `Call` or `E`?



Comment at: clang-tools-extra/clangd/AST.cpp:888
+// Split the parameters into head, pack and tail
+auto IsExpandedPack = [&](const ParmVarDecl *P) {
+  return getPackTemplateParameter(P) == TTPT;

can just capture `TTPT` here



Comment at: clang-tools-extra/clangd/AST.cpp:899
+auto HeadIt = std::copy(Head.begin(), Head.end(), Result.begin());
+auto TailIt = std::copy(Tail.rbegin(), Tail.rbegin(), Result.rbegin());
+// Recurse on pack parameters

The second argument is presumably meant to be `Tail.rend()`



Comment at: clang-tools-extra/clangd/InlayHints.cpp:515
+  if (isExpandedParameterPack(P)) {
+ParameterNames.emplace_back();
+  } else {

let's add `// will not be hinted` for clarity



Comment at: clang-tools-extra/clangd/InlayHints.cpp:541
 
+// Remove parameter names that occur multiple times completely.
+llvm::StringMap NameLastSeen;

This is an interesting approach for handling `VariadicRecursive`.

I had in mind a different approach, something like keeping a 
`std::set SeenFunctionTemplates` in 
`resolveForwardingParameters()`, populating it with 
`CurrentFunction->getPrimaryTemplate()` on each iteration, and bailing if the 
same function template is seen more than once (indicating recursion). But this 
approach seems to work too, as a parameter name can't legitimately appear twice 
in a function declaration.

That said, maybe having such a `SeenFunctionTemplates` recursion guard would be 
helpful anyways, so that e.g. in `VariadicInfinite`, we would bail after a 
single recursion rather than going until `MaxDepth`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124690

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


[PATCH] D126956: [tbaa] Handle base classes in struct tbaa

2022-06-15 Thread Bruno De Fraine via Phabricator via cfe-commits
brunodf added a comment.

Anyone?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126956

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays for stricter handling of flexible arrays

2022-06-15 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 does toward 
`-fstrict-flex-arrays=` with

- `n=0` ⇒ `-fno-strict-flex-arrays`, current state (the default)
- `n=1` ⇒ only consider `[ 0]`, `[1}` and `[ ]` as flex array member
- `n=2` ⇒ only consider `[ 0]` and `[ ]` as flex array member
- `n=3` ⇒ only consider `[ ]` as flex array member

I personnally like that approach, and I'd rather land that implementation.


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

https://reviews.llvm.org/D126864

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


[PATCH] D126907: Deferred Concept Instantiation Implementation Take 2

2022-06-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

I finally found some time to look at the crash. Although I haven't get an idea, 
I found it crash at the following one too:

  template 
  concept Constraint = true;
  
  template 
  class completion_handler_async_result {
  public:
  template 
  static void initiate(Initiation&& initiation, RawCompletionToken&& token);
  };
  
  template 
  concept Constraint2 =
  requires(float&& t) {
  completion_handler_async_result::initiate(0, 0);
  };
  
  template 
  void use(int F)
  requires Constraint2
  {}

I am not sure if they are the same problem.


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

https://reviews.llvm.org/D126907

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


[PATCH] D127460: Rename GCCBuiltin into ClangBuiltin

2022-06-15 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127460

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


[PATCH] D127833: [clangd] Enable AKA type printing by default

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa67beef3acac: [clangd] Enable AKA type printing by default 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127833

Files:
  clang-tools-extra/clangd/Config.h


Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -129,7 +129,7 @@
   /// Configures hover feature.
   struct {
 /// Whether hover show a.k.a type.
-bool ShowAKA = false;
+bool ShowAKA = true;
   } Hover;
 
   struct {


Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -129,7 +129,7 @@
   /// Configures hover feature.
   struct {
 /// Whether hover show a.k.a type.
-bool ShowAKA = false;
+bool ShowAKA = true;
   } Hover;
 
   struct {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] a67beef - [clangd] Enable AKA type printing by default

2022-06-15 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-06-15T10:43:17+02:00
New Revision: a67beef3acac4ab4fc009f492d5b3f510c48420b

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

LOG: [clangd] Enable AKA type printing by default

This has been tested on a large set of c++ developers for a long while,
without any crashes or complaints.

Differential Revision: https://reviews.llvm.org/D127833

Added: 


Modified: 
clang-tools-extra/clangd/Config.h

Removed: 




diff  --git a/clang-tools-extra/clangd/Config.h 
b/clang-tools-extra/clangd/Config.h
index ec7247121d5cd..312ca3b7af90a 100644
--- a/clang-tools-extra/clangd/Config.h
+++ b/clang-tools-extra/clangd/Config.h
@@ -129,7 +129,7 @@ struct Config {
   /// Configures hover feature.
   struct {
 /// Whether hover show a.k.a type.
-bool ShowAKA = false;
+bool ShowAKA = true;
   } Hover;
 
   struct {



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


[PATCH] D127460: Rename GCCBuiltin into ClangBuiltin

2022-06-15 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

I don't think this is really blocked on the libc team any more?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127460

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


[clang] 1784fe7 - [Clang] Fix signed-unsigned comparison warning that breaks the ppc64 build.

2022-06-15 Thread Martin Boehme via cfe-commits

Author: Martin Boehme
Date: 2022-06-15T10:53:14+02:00
New Revision: 1784fe7be782ce34bf4a06529a89f47d1ec0e6f4

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

LOG: [Clang] Fix signed-unsigned comparison warning that breaks the ppc64 build.

Added: 


Modified: 
clang/unittests/AST/AttrTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/AttrTest.cpp 
b/clang/unittests/AST/AttrTest.cpp
index d9ea1ae061f0..518f995ed104 100644
--- a/clang/unittests/AST/AttrTest.cpp
+++ b/clang/unittests/AST/AttrTest.cpp
@@ -102,13 +102,13 @@ TEST(Attr, AnnotateType) {
 AssertAnnotatedAs(PointerTL.getPointeeLoc(), "foo", PointerPointerTL,
   &Annotate);
 
-EXPECT_EQ(Annotate->args_size(), 2);
+EXPECT_EQ(Annotate->args_size(), 2u);
 const auto *StringLit = selectFirst(
 "str", match(constantExpr(hasDescendant(stringLiteral().bind("str"))),
  *Annotate->args_begin()[0], AST->getASTContext()));
 ASSERT_NE(StringLit, nullptr);
 EXPECT_EQ(StringLit->getString(), "arg1");
-EXPECT_EQ(match(constantExpr(has(integerLiteral(equals(2)).bind("int"))),
+EXPECT_EQ(match(constantExpr(has(integerLiteral(equals(2u)).bind("int"))),
 *Annotate->args_begin()[1], AST->getASTContext())
   .size(),
   1);



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


[clang] 4c2bccf - [Clang] Documentation-only: Add missing closing `>` in AttrDocs.td

2022-06-15 Thread Martin Boehme via cfe-commits

Author: Martin Boehme
Date: 2022-06-15T10:59:07+02:00
New Revision: 4c2bccfda3892ae13e97b6bfdbc99ec8cf5d095d

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

LOG: [Clang] Documentation-only: Add missing closing `>` in AttrDocs.td

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 6562e363a1ca..dbb7f695a5a2 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6510,7 +6510,7 @@ For example:
 The attribute does not have any effect on the semantics of the type system,
 neither type checking rules, nor runtime semantics. In particular:
 
-- ``std::is_same`` is true for all types
   ``T``.
 
 - It is not permissible for overloaded functions or template specializations



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


[PATCH] D126956: [tbaa] Handle base classes in struct tbaa

2022-06-15 Thread Jeroen Dobbelaere via Phabricator via cfe-commits
jeroen.dobbelaere accepted this revision.
jeroen.dobbelaere added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126956

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


[PATCH] D127836: [analyzer][NFC] Remove dead code and modernize surroundings

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: kazu, martong, xazax.hun, gamesh411.
Herald added subscribers: abrachet, manas, ASDenysPetrov, phosek, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Thanks @kazu for helping me clean these parts in D127799 
.

I'm leaving the dump methods, along with the unused visitor handlers and
the forwarding methods.

The dead parts actually helped to uncover two bugs, to which I'm going
to post separate patches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127836

Files:
  clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.h
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -352,7 +352,6 @@
 
 private:
   void storeTopLevelDecls(DeclGroupRef DG);
-  std::string getFunctionName(const Decl *D);
 
   /// Check if we should skip (not analyze) the given function.
   AnalysisMode getModeForDecl(Decl *D, AnalysisMode Mode);
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -118,18 +118,10 @@
 /// the construction context was present and contained references to these
 /// AST nodes.
 class ConstructedObjectKey {
-  typedef std::pair
-  ConstructedObjectKeyImpl;
-
+  using ConstructedObjectKeyImpl =
+  std::pair;
   const ConstructedObjectKeyImpl Impl;
 
-  const void *getAnyASTNodePtr() const {
-if (const Stmt *S = getItem().getStmtOrNull())
-  return S;
-else
-  return getItem().getCXXCtorInitializer();
-  }
-
 public:
   explicit ConstructedObjectKey(const ConstructionContextItem &Item,
const LocationContext *LC)
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -527,11 +527,6 @@
 ID.AddPointer(RegionOfInterest);
   }
 
-  void *getTag() const {
-static int Tag = 0;
-return static_cast(&Tag);
-  }
-
 private:
   /// \return Whether \c RegionOfInterest was modified at \p CurrN compared to
   /// the value it holds in \p CallExitBeginN.
Index: clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
@@ -22,27 +22,15 @@
 using namespace taint;
 
 namespace {
-class TaintTesterChecker : public Checker< check::PostStmt > {
-
-  mutable std::unique_ptr BT;
-  void initBugType() const;
-
-  /// Given a pointer argument, get the symbol of the value it contains
-  /// (points to).
-  SymbolRef getPointedToSymbol(CheckerContext &C,
-   const Expr* Arg,
-   bool IssueWarning = true) const;
+class TaintTesterChecker : public Checker> {
+  std::unique_ptr BT =
+  std::make_unique(this, "Tainted data", "General");
 
 public:
   void checkPostStmt(const Expr *E, CheckerContext &C) const;
 };
 }
 
-inline void TaintTesterChecker::initBugType() const {
-  if (!BT)
-BT.reset(new BugType(this, "Tainted data", "General"));
-}
-
 void TaintTesterChecker::checkPostStmt(const Expr *E,
CheckerContext &C) const {
   ProgramStateRef State = C.getState();
@@ -51,7 +39,6 @@
 
   if (isTainted(State, E, C.getLocationContext())) {
 if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
-  initBugType();
   auto report = std::make_unique(*BT, "tainted", N);
   report->addRange(E->getSourceRange());
   

[PATCH] D127799: [StaticAnalyzer] Remove dead code (DO NOT COMMIT)

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Thanks @kazu. I evaluated your results and made a patch as D127836 
.
I think we can abandon this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127799

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


[PATCH] D125931: [clang][dataflow] Add support for correlated branches to optional model

2022-06-15 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 437088.
sgatev marked 3 inline comments as done.
sgatev added a comment.
Herald added a subscriber: martong.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125931

Files:
  
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1861,7 +1861,26 @@
   )",
  UnorderedElementsAre(Pair("check", "safe")));
 
-  // FIXME: Add tests that call `emplace` in conditional branches.
+  // FIXME: Add tests that call `emplace` in conditional branches:
+  //  ExpectLatticeChecksFor(
+  //  R"(
+  //#include "unchecked_optional_access_test.h"
+  //
+  //void target($ns::$optional opt, bool b) {
+  //  if (b) {
+  //opt.emplace(0);
+  //  }
+  //  if (b) {
+  //opt.value();
+  ///*[[check-1]]*/
+  //  } else {
+  //opt.value();
+  ///*[[check-2]]*/
+  //  }
+  //}
+  //  )",
+  //  UnorderedElementsAre(Pair("check-1", "safe"),
+  //   Pair("check-2", "unsafe: input.cc:12:9")));
 }
 
 TEST_P(UncheckedOptionalAccessTest, Reset) {
@@ -1892,7 +1911,27 @@
   )",
   UnorderedElementsAre(Pair("check", "unsafe: input.cc:7:9")));
 
-  // FIXME: Add tests that call `reset` in conditional branches.
+  // FIXME: Add tests that call `reset` in conditional branches:
+  //  ExpectLatticeChecksFor(
+  //  R"(
+  //#include "unchecked_optional_access_test.h"
+  //
+  //void target(bool b) {
+  //  $ns::$optional opt = $ns::make_optional(0);
+  //  if (b) {
+  //opt.reset();
+  //  }
+  //  if (b) {
+  //opt.value();
+  ///*[[check-1]]*/
+  //  } else {
+  //opt.value();
+  ///*[[check-2]]*/
+  //  }
+  //}
+  //  )",
+  //  UnorderedElementsAre(Pair("check-1", "unsafe: input.cc:10:9"),
+  //   Pair("check-2", "safe")));
 }
 
 TEST_P(UncheckedOptionalAccessTest, ValueAssignment) {
@@ -2347,6 +2386,284 @@
   UnorderedElementsAre(Pair("check", "unsafe: input.cc:12:7")));
 }
 
+TEST_P(UncheckedOptionalAccessTest, CorrelatedBranches) {
+  ExpectLatticeChecksFor(R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (b || opt.has_value()) {
+if (!b) {
+  opt.value();
+  /*[[check-1]]*/
+}
+  }
+}
+  )code",
+ UnorderedElementsAre(Pair("check-1", "safe")));
+
+  ExpectLatticeChecksFor(R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (b && !opt.has_value()) return;
+  if (b) {
+opt.value();
+/*[[check-2]]*/
+  }
+}
+  )code",
+ UnorderedElementsAre(Pair("check-2", "safe")));
+
+  ExpectLatticeChecksFor(
+  R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (opt.has_value()) b = true;
+  if (b) {
+opt.value();
+/*[[check-3]]*/
+  }
+}
+  )code",
+  UnorderedElementsAre(Pair("check-3", "unsafe: input.cc:7:9")));
+
+  ExpectLatticeChecksFor(R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (b) return;
+  if (opt.has_value()) b = true;
+  if (b) {
+opt.value();
+/*[[check-4]]*/
+  }
+}
+  )code",
+ UnorderedElementsAre(Pair("check-4", "safe")));
+
+  ExpectLatticeChecksFor(R"(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (opt.has_value() == b) {
+if (b) {
+  opt.value();
+  /*[[check-5]]*/
+}
+  }
+}
+  )",
+ UnorderedElementsAre(Pair("check-5", "safe")));
+
+  ExpectLatticeChecksFor(R"(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (opt.has_value() != b) {
+if (!b) {
+  opt.value();
+  /*[[check-6]]*/
+}
+  }
+}
+  )",
+ UnorderedElementsAre(Pair("check-6", "safe")));
+
+  ExpectLatticeChecksFor(R"(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b) {
+  $ns::$optional opt1 = $ns::nullopt;
+  $ns::$optional opt2;
+  if (b) {
+opt2 = $ns

[PATCH] D125931: [clang][dataflow] Add support for correlated branches to optional model

2022-06-15 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:288
 
+bool isEngagedOptionalValue(const Value &OptionalVal, const Environment &env) {
+  auto *HasValueVal =

xazax.hun wrote:
> I wonder whether `NonEmpty` is clearer than `Engaged`. I think `Engaged` can 
> also be OK, but we probably want to have a comment somewhere to explain the 
> terminology.
Sounds good. I went with `isEmptyOptional` and `isNonEmptyOptional`.



Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:689
+  }
+  setHasValue(MergedVal, HasValueVal);
+  return true;

xazax.hun wrote:
> Would it make sense to have the converese? I.e., when both optionals are 
> empty, create an empty optional here. While currently this modeling does not 
> distinguish between unchecked and empty optionals it might be handy in the 
> future. Although I am also happy with this as is, not adding any code that 
> does not have any utility as of today.
Good idea! I think this can be useful. I added the code and a test case based 
on dead code:

```
if (b) {
  opt = std::nullopt;
} else {
  opt = std::nullopt;
}
if (opt.has_value()) {
  // unreachable
}
```



Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:174
+/// property of the optional value `OptionalVal`.
+void setHasValue(StructValue &OptionalVal, BoolValue &HasValueVal) {
+  OptionalVal.setProperty("has_value", HasValueVal);

ymandel wrote:
> sgatev wrote:
> > ymandel wrote:
> > > I believe you can relax this to `Value` because `setProperty` is no 
> > > longer specific to `StructValue`.
> > I did that intentionally because I still think it makes sense to assert 
> > that an optional is modeled as a `StructValue`. I haven't thought about 
> > where and how it'd be best to assert that though so I'll happily remove the 
> > casts for now.
> Sounds good. I had the same thought. But, it occurs to me that at this point, 
> are we using the `StructValue` at all? If not, then the only reason we expect 
> it to be a `StructValue` is because we know the optional type is a record 
> type. But, that's not an assumption of our model. So, maybe we should be 
> agnostic to the underlying representation?
Agreed. Let's not assume a `StructValue` representation unless it's necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125931

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


[PATCH] D127838: [analyzer][NFC] Remove dead field of UnixAPICheckers

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: kazu, martong.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Initially, I thought there is some fundamental bug here by not using the
bool fields, but it turns out D55425  split 
this checker into two
separate ones; making these fields dead.

Depends on D127836 , which uncovered this 
issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127838

Files:
  clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -43,8 +43,6 @@
   mutable Optional Val_O_CREAT;
 
 public:
-  bool CheckMisuse = false, CheckPortability = false;
-
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
 
   void CheckOpen(CheckerContext &C, const CallExpr *CE) const;
@@ -503,7 +501,7 @@
 mgr.registerChecker();
\
   }
\

\
-  bool ento::shouldRegister##CHECKERNAME(const CheckerManager &mgr) {  
\
+  bool ento::shouldRegister##CHECKERNAME(const CheckerManager &mgr) {  
\
 return true;   
\
   }
 


Index: clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -43,8 +43,6 @@
   mutable Optional Val_O_CREAT;
 
 public:
-  bool CheckMisuse = false, CheckPortability = false;
-
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
 
   void CheckOpen(CheckerContext &C, const CallExpr *CE) const;
@@ -503,7 +501,7 @@
 mgr.registerChecker();\
   }\
\
-  bool ento::shouldRegister##CHECKERNAME(const CheckerManager &mgr) {  \
+  bool ento::shouldRegister##CHECKERNAME(const CheckerManager &mgr) {  \
 return true;   \
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127839: [analyzer] Fix StreamErrorState hash bug

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: kazu, martong, balazske.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The `Profile` function was incorrectly implemented.
The `StreamErrorState` has an implicit `bool` conversion operator, which
will result in a different hash than faithfully hashing the raw value of
the enum.

I don't have a test for it, since it seems difficult to find one.
Even if we would have one, any change in the hashing algorithm would
have a chance of breaking it, so I don't think it would justify the
effort.

Depends on D127836 , which uncovered this 
issue by marking the related
`Profile` function dead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127839

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -146,7 +146,7 @@
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddPointer(LastOperation);
 ID.AddInteger(State);
-ID.AddInteger(ErrorState);
+ErrorState.Profile(ID);
 ID.AddBoolean(FilePositionIndeterminate);
   }
 };


Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -146,7 +146,7 @@
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddPointer(LastOperation);
 ID.AddInteger(State);
-ID.AddInteger(ErrorState);
+ErrorState.Profile(ID);
 ID.AddBoolean(FilePositionIndeterminate);
   }
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7acc88b - [OpenCL] Reword unknown extension pragma diagnostic

2022-06-15 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-06-15T10:54:46+01:00
New Revision: 7acc88be0312c721bc082ed9934e381d297f4707

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

LOG: [OpenCL] Reword unknown extension pragma diagnostic

For newer OpenCL extensions that do not require a pragma, such as
`cl_khr_subgroup_shuffle`, a user could still accidentally attempt to
use a pragma.  This would result in a warning
  "unknown OpenCL extension 'cl_khr_subgroup_shuffle' - ignoring"
which could be mistakenly interpreted as "clang does not support this
extension at all" instead of "clang does not require any pragma for
this extension".

Differential Revision: https://reviews.llvm.org/D126660

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/test/Headers/opencl-c-header.cl
clang/test/Parser/opencl-pragma.cl
clang/test/SemaOpenCL/extension-begin.cl
clang/test/SemaOpenCL/extension-version.cl

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index dd6bba720ce2..b0abe2aa517e 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1278,7 +1278,7 @@ def warn_pragma_expected_colon : Warning<
 def warn_pragma_expected_predicate : Warning<
   "expected %select{'enable', 'disable', 'begin' or 'end'|'disable'}0 - 
ignoring">, InGroup;
 def warn_pragma_unknown_extension : Warning<
-  "unknown OpenCL extension %0 - ignoring">, InGroup;
+  "OpenCL extension %0 unknown or does not require pragma - ignoring">, 
InGroup;
 def warn_pragma_unsupported_extension : Warning<
   "unsupported OpenCL extension %0 - ignoring">, InGroup;
 def warn_pragma_extension_is_core : Warning<

diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index 455842412fd0..8242798106ac 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -100,7 +100,7 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // expected-no-diagnostics
 #else //__OPENCL_C_VERSION__
-// expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - 
ignoring}}
+// expected-warning@+2{{OpenCL extension 'cl_intel_planar_yuv' unknown or does 
not require pragma - ignoring}}
 #endif //__OPENCL_C_VERSION__
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
 

diff  --git a/clang/test/Parser/opencl-pragma.cl 
b/clang/test/Parser/opencl-pragma.cl
index 02f053fb40d9..76e2cdd47442 100644
--- a/clang/test/Parser/opencl-pragma.cl
+++ b/clang/test/Parser/opencl-pragma.cl
@@ -2,7 +2,7 @@
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
-#pragma OPENCL EXTENSION cl_no_such_extension : disable /* expected-warning 
{{unknown OpenCL extension 'cl_no_such_extension' - ignoring}} */
+#pragma OPENCL EXTENSION cl_no_such_extension : disable /* expected-warning 
{{OpenCL extension 'cl_no_such_extension' unknown or does not require pragma - 
ignoring}} */
 
 #pragma OPENCL EXTENSION all : disable
 #pragma OPENCL EXTENSION all : enable /* expected-warning {{expected 'disable' 
- ignoring}} */

diff  --git a/clang/test/SemaOpenCL/extension-begin.cl 
b/clang/test/SemaOpenCL/extension-begin.cl
index 9124ceba4e2a..dc8bd769e2bd 100644
--- a/clang/test/SemaOpenCL/extension-begin.cl
+++ b/clang/test/SemaOpenCL/extension-begin.cl
@@ -18,8 +18,8 @@
 
 #pragma OPENCL EXTENSION my_ext : enable
 #ifndef IMPLICIT_INCLUDE
-// expected-warning@-2 {{unknown OpenCL extension 'my_ext' - ignoring}}
-// expected-warning@+2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+// expected-warning@-2 {{OpenCL extension 'my_ext' unknown or does not require 
pragma - ignoring}}
+// expected-warning@+2 {{OpenCL extension 'my_ext' unknown or does not require 
pragma - ignoring}}
 #endif // IMPLICIT_INCLUDE
 #pragma OPENCL EXTENSION my_ext : disable
 

diff  --git a/clang/test/SemaOpenCL/extension-version.cl 
b/clang/test/SemaOpenCL/extension-version.cl
index d135970b8b02..4d92eff6ae3a 100644
--- a/clang/test/SemaOpenCL/extension-version.cl
+++ b/clang/test/SemaOpenCL/extension-version.cl
@@ -217,51 +217,51 @@
 // Check that pragmas for the OpenCL 3.0 features are rejected.
 
 #pragma OPENCL EXTENSION __opencl_c_int64 : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_int64' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_int64' unknown or does not 
require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_3d_image_writes : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_3d_image_writes' - 
ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_3d_image_writes' unknown 
or does not requ

[PATCH] D126660: [OpenCL] Reword unknown extension pragma diagnostic

2022-06-15 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7acc88be0312: [OpenCL] Reword unknown extension pragma 
diagnostic (authored by svenvh).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126660

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/test/Headers/opencl-c-header.cl
  clang/test/Parser/opencl-pragma.cl
  clang/test/SemaOpenCL/extension-begin.cl
  clang/test/SemaOpenCL/extension-version.cl

Index: clang/test/SemaOpenCL/extension-version.cl
===
--- clang/test/SemaOpenCL/extension-version.cl
+++ clang/test/SemaOpenCL/extension-version.cl
@@ -217,51 +217,51 @@
 // Check that pragmas for the OpenCL 3.0 features are rejected.
 
 #pragma OPENCL EXTENSION __opencl_c_int64 : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_int64' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_int64' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_3d_image_writes : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_3d_image_writes' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_3d_image_writes' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_atomic_order_acq_rel : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_atomic_order_acq_rel' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_atomic_order_acq_rel' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_atomic_order_seq_cst : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_atomic_order_seq_cst' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_atomic_order_seq_cst' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_device_enqueue : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_device_enqueue' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_device_enqueue' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_fp64 : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_fp64' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_fp64' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_generic_address_space : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_generic_address_space' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_generic_address_space' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_images : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_images' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_images' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_pipes : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_pipes' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_pipes' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_program_scope_global_variables : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_program_scope_global_variables' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_program_scope_global_variables' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_read_write_images : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_read_write_images' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_read_write_images' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_subgroups : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_subgroups' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_subgroups' unknown or does not require pragma - ignoring}}
 
 #pragma OPENCL EXTENSION __opencl_c_int64 : enable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_int64' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_int64' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_3d_image_writes : enable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_3d_image_writes' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_3d_image_writes' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_atomic_order_acq_rel : enable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_atomic_order_acq_rel' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_atomic_order_acq_rel' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_atomic_order_seq_cst : enable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_

[clang] 8fcdd62 - [clang][dataflow] Add support for correlated branches to optional model

2022-06-15 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-06-15T10:00:44Z
New Revision: 8fcdd625856b2e7df2fdb3a4c57efedb35e4d7c1

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

LOG: [clang][dataflow] Add support for correlated branches to optional model

Add support for correlated branches to the std::optional dataflow model.

Differential Revision: https://reviews.llvm.org/D125931

Reviewed-by: ymandel, xazax.hun

Added: 


Modified: 

clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
index 8cc3fa73de9d..2102ed56907b 100644
--- 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
+++ 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
@@ -59,6 +59,14 @@ class UncheckedOptionalAccessModel
   void transfer(const Stmt *Stmt, SourceLocationsLattice &State,
 Environment &Env);
 
+  bool compareEquivalent(QualType Type, const Value &Val1,
+ const Environment &Env1, const Value &Val2,
+ const Environment &Env2) override;
+
+  bool merge(QualType Type, const Value &Val1, const Environment &Env1,
+ const Value &Val2, const Environment &Env2, Value &MergedVal,
+ Environment &MergedEnv) override;
+
 private:
   MatchSwitch> TransferMatchSwitch;
 };

diff  --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index 23a9d964b5b1..502974186621 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -169,11 +169,17 @@ auto isCallReturningOptional() {
   optionalOrAliasType(), referenceType(pointee(optionalOrAliasType()));
 }
 
+/// Sets `HasValueVal` as the symbolic value that represents the "has_value"
+/// property of the optional value `OptionalVal`.
+void setHasValue(Value &OptionalVal, BoolValue &HasValueVal) {
+  OptionalVal.setProperty("has_value", HasValueVal);
+}
+
 /// Creates a symbolic value for an `optional` value using `HasValueVal` as the
 /// symbolic value of its "has_value" property.
 StructValue &createOptionalValue(Environment &Env, BoolValue &HasValueVal) {
   auto OptionalVal = std::make_unique();
-  OptionalVal->setProperty("has_value", HasValueVal);
+  setHasValue(*OptionalVal, HasValueVal);
   return Env.takeOwnership(std::move(OptionalVal));
 }
 
@@ -274,11 +280,28 @@ void initializeOptionalReference(const Expr *OptionalExpr,
   if (auto *OptionalVal =
   State.Env.getValue(*OptionalExpr, SkipPast::Reference)) {
 if (OptionalVal->getProperty("has_value") == nullptr) {
-  OptionalVal->setProperty("has_value", State.Env.makeAtomicBoolValue());
+  setHasValue(*OptionalVal, State.Env.makeAtomicBoolValue());
 }
   }
 }
 
+/// Returns true if and only if `OptionalVal` is initialized and known to be
+/// empty in `Env.
+bool isEmptyOptional(const Value &OptionalVal, const Environment &Env) {
+  auto *HasValueVal =
+  cast_or_null(OptionalVal.getProperty("has_value"));
+  return HasValueVal != nullptr &&
+ Env.flowConditionImplies(Env.makeNot(*HasValueVal));
+}
+
+/// Returns true if and only if `OptionalVal` is initialized and known to be
+/// non-empty in `Env.
+bool isNonEmptyOptional(const Value &OptionalVal, const Environment &Env) {
+  auto *HasValueVal =
+  cast_or_null(OptionalVal.getProperty("has_value"));
+  return HasValueVal != nullptr && Env.flowConditionImplies(*HasValueVal);
+}
+
 void transferUnwrapCall(const Expr *UnwrapExpr, const Expr *ObjectExpr,
 LatticeTransferState &State) {
   if (auto *OptionalVal =
@@ -651,5 +674,31 @@ void UncheckedOptionalAccessModel::transfer(const Stmt *S,
   TransferMatchSwitch(*S, getASTContext(), State);
 }
 
+bool UncheckedOptionalAccessModel::compareEquivalent(QualType Type,
+ const Value &Val1,
+ const Environment &Env1,
+ const Value &Val2,
+ const Environment &Env2) {
+  return isNonEmptyOptional(Val1, Env1) == isNonEmptyOptional(Val2, Env2);
+}
+
+bool UncheckedOptionalAccessModel::merge(QualType Type, const Value &Val1,
+  

[PATCH] D125931: [clang][dataflow] Add support for correlated branches to optional model

2022-06-15 Thread Stanislav Gatev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8fcdd625856b: [clang][dataflow] Add support for correlated 
branches to optional model (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125931

Files:
  
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1861,7 +1861,26 @@
   )",
  UnorderedElementsAre(Pair("check", "safe")));
 
-  // FIXME: Add tests that call `emplace` in conditional branches.
+  // FIXME: Add tests that call `emplace` in conditional branches:
+  //  ExpectLatticeChecksFor(
+  //  R"(
+  //#include "unchecked_optional_access_test.h"
+  //
+  //void target($ns::$optional opt, bool b) {
+  //  if (b) {
+  //opt.emplace(0);
+  //  }
+  //  if (b) {
+  //opt.value();
+  ///*[[check-1]]*/
+  //  } else {
+  //opt.value();
+  ///*[[check-2]]*/
+  //  }
+  //}
+  //  )",
+  //  UnorderedElementsAre(Pair("check-1", "safe"),
+  //   Pair("check-2", "unsafe: input.cc:12:9")));
 }
 
 TEST_P(UncheckedOptionalAccessTest, Reset) {
@@ -1892,7 +1911,27 @@
   )",
   UnorderedElementsAre(Pair("check", "unsafe: input.cc:7:9")));
 
-  // FIXME: Add tests that call `reset` in conditional branches.
+  // FIXME: Add tests that call `reset` in conditional branches:
+  //  ExpectLatticeChecksFor(
+  //  R"(
+  //#include "unchecked_optional_access_test.h"
+  //
+  //void target(bool b) {
+  //  $ns::$optional opt = $ns::make_optional(0);
+  //  if (b) {
+  //opt.reset();
+  //  }
+  //  if (b) {
+  //opt.value();
+  ///*[[check-1]]*/
+  //  } else {
+  //opt.value();
+  ///*[[check-2]]*/
+  //  }
+  //}
+  //  )",
+  //  UnorderedElementsAre(Pair("check-1", "unsafe: input.cc:10:9"),
+  //   Pair("check-2", "safe")));
 }
 
 TEST_P(UncheckedOptionalAccessTest, ValueAssignment) {
@@ -2347,6 +2386,284 @@
   UnorderedElementsAre(Pair("check", "unsafe: input.cc:12:7")));
 }
 
+TEST_P(UncheckedOptionalAccessTest, CorrelatedBranches) {
+  ExpectLatticeChecksFor(R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (b || opt.has_value()) {
+if (!b) {
+  opt.value();
+  /*[[check-1]]*/
+}
+  }
+}
+  )code",
+ UnorderedElementsAre(Pair("check-1", "safe")));
+
+  ExpectLatticeChecksFor(R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (b && !opt.has_value()) return;
+  if (b) {
+opt.value();
+/*[[check-2]]*/
+  }
+}
+  )code",
+ UnorderedElementsAre(Pair("check-2", "safe")));
+
+  ExpectLatticeChecksFor(
+  R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (opt.has_value()) b = true;
+  if (b) {
+opt.value();
+/*[[check-3]]*/
+  }
+}
+  )code",
+  UnorderedElementsAre(Pair("check-3", "unsafe: input.cc:7:9")));
+
+  ExpectLatticeChecksFor(R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (b) return;
+  if (opt.has_value()) b = true;
+  if (b) {
+opt.value();
+/*[[check-4]]*/
+  }
+}
+  )code",
+ UnorderedElementsAre(Pair("check-4", "safe")));
+
+  ExpectLatticeChecksFor(R"(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (opt.has_value() == b) {
+if (b) {
+  opt.value();
+  /*[[check-5]]*/
+}
+  }
+}
+  )",
+ UnorderedElementsAre(Pair("check-5", "safe")));
+
+  ExpectLatticeChecksFor(R"(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (opt.has_value() != b) {
+if (!b) {
+  opt.value();
+  /*[[check-6]]*/
+}
+  }
+}
+  )",
+ UnorderedElementsAre(Pair("check-6", "safe")));
+
+  ExpectLatticeChecksFor(R"(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b) {
+  $ns::$o

[clang] 170ca11 - [Sema] Remove unused function after 8c7b64b5ae2a

2022-06-15 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2022-06-15T12:20:44+02:00
New Revision: 170ca11aeff25735006ca51e5ed3005b672e8f97

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

LOG: [Sema] Remove unused function after 8c7b64b5ae2a

Added: 


Modified: 
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 0c84673b3479..0015d6a870b9 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8221,19 +8221,6 @@ static void HandleLifetimeBoundAttr(TypeProcessingState 
&State,
   }
 }
 
-static bool isAddressSpaceKind(const ParsedAttr &attr) {
-  auto attrKind = attr.getKind();
-
-  return attrKind == ParsedAttr::AT_AddressSpace ||
- attrKind == ParsedAttr::AT_OpenCLPrivateAddressSpace ||
- attrKind == ParsedAttr::AT_OpenCLGlobalAddressSpace ||
- attrKind == ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace ||
- attrKind == ParsedAttr::AT_OpenCLGlobalHostAddressSpace ||
- attrKind == ParsedAttr::AT_OpenCLLocalAddressSpace ||
- attrKind == ParsedAttr::AT_OpenCLConstantAddressSpace ||
- attrKind == ParsedAttr::AT_OpenCLGenericAddressSpace;
-}
-
 static void processTypeAttrs(TypeProcessingState &state, QualType &type,
  TypeAttrLocation TAL,
  const ParsedAttributesView &attrs) {



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


[clang] 43e7ba6 - Fix signed/unsigned comparison warning

2022-06-15 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-06-15T11:53:08+01:00
New Revision: 43e7ba6495359bcc14580725468e7736e97edcc6

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

LOG: Fix signed/unsigned comparison warning

Added: 


Modified: 
clang/unittests/AST/AttrTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/AttrTest.cpp 
b/clang/unittests/AST/AttrTest.cpp
index 518f995ed104b..500e9cfa528b7 100644
--- a/clang/unittests/AST/AttrTest.cpp
+++ b/clang/unittests/AST/AttrTest.cpp
@@ -111,7 +111,7 @@ TEST(Attr, AnnotateType) {
 EXPECT_EQ(match(constantExpr(has(integerLiteral(equals(2u)).bind("int"))),
 *Annotate->args_begin()[1], AST->getASTContext())
   .size(),
-  1);
+  1u);
 
 // Second parameter.
 BuiltinTypeLoc IntTL;



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


[PATCH] D127832: [clangd] Always desugar type aliases in hover

2022-06-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM. Please take a look the NIT about landing this as two commits.




Comment at: clang-tools-extra/clangd/Hover.cpp:581
   HoverInfo HI;
-  const ASTContext &Ctx = D->getASTContext();
+  ASTContext &Ctx = D->getASTContext();
 

NIT: maybe use `auto&` here?
The name of the type is mentioned directly in the initialization.



Comment at: clang-tools-extra/clangd/Hover.cpp:625
   else if (const auto *TN = dyn_cast(D))
-HI.Type = printType(TN->getUnderlyingType(), TN->getASTContext(), PP);
+HI.Type = printType(TN->getUnderlyingType().getDesugaredType(Ctx), Ctx, 
PP);
   else if (const auto *TAT = dyn_cast(D))

NIT: could you please land the refactoring with `ASTContext` and this change 
separately?
It was a bit hard to find the relevant change for me, I suspect reading the git 
history might also be problematic in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127832

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


[PATCH] D127844: [clangd] Pull suppression logic into common path, apply for driver diagnostics

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang-tools-extra.

Fixes https://github.com/clangd/clangd/issues/1142


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127844

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/CompilerTests.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1870,6 +1870,27 @@
   "'int' to 'int *' for 1st argument; take the address of "
   "the argument with &");
 }
+
+TEST(DiagnosticsTest, DontSuppressSubcategories) {
+  Annotations Source(R"cpp(
+  /*error-ok*/
+void bar(int x) {
+  switch(x) {
+  default:
+break;
+break;
+  }
+})cpp");
+  TestTU TU;
+  TU.ExtraArgs.push_back("-Wunreachable-code-aggressive");
+  TU.Code = Source.code().str();
+  Config Cfg;
+  // This shouldn't suppress subcategory unreachable-break.
+  Cfg.Diagnostics.Suppress = {"unreachable-code"};
+  WithContextValue SuppressFilterWithCfg(Config::Key, std::move(Cfg));
+  EXPECT_THAT(*TU.build().getDiagnostics(),
+  ElementsAre(diagName("-Wunreachable-code-break")));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -284,6 +284,7 @@
 }
 
 TEST_F(ConfigCompileTests, DiagnosticSuppression) {
+  // Check that canonicalization and compilation works.
   Frag.Diagnostics.Suppress.emplace_back("bugprone-use-after-move");
   Frag.Diagnostics.Suppress.emplace_back("unreachable-code");
   Frag.Diagnostics.Suppress.emplace_back("-Wunused-variable");
@@ -296,21 +297,8 @@
"unreachable-code", "unused-variable",
"typecheck_bool_condition",
"unexpected_friend", "warn_alloca"));
-  EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
-  diag::warn_unreachable, Conf.Diagnostics.Suppress, LangOptions()));
-  // Subcategory not respected/suppressed.
-  EXPECT_FALSE(isBuiltinDiagnosticSuppressed(
-  diag::warn_unreachable_break, Conf.Diagnostics.Suppress, LangOptions()));
-  EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
-  diag::warn_unused_variable, Conf.Diagnostics.Suppress, LangOptions()));
-  EXPECT_TRUE(isBuiltinDiagnosticSuppressed(diag::err_typecheck_bool_condition,
-Conf.Diagnostics.Suppress,
-LangOptions()));
-  EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
-  diag::err_unexpected_friend, Conf.Diagnostics.Suppress, LangOptions()));
-  EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
-  diag::warn_alloca, Conf.Diagnostics.Suppress, LangOptions()));
 
+  // Check that we treat * specially.
   Frag.Diagnostics.Suppress.emplace_back("*");
   EXPECT_TRUE(compileAndApply());
   EXPECT_TRUE(Conf.Diagnostics.SuppressAll);
Index: clang-tools-extra/clangd/unittests/CompilerTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "Compiler.h"
+#include "Config.h"
+#include "Diagnostics.h"
 #include "TestTU.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/FrontendOptions.h"
@@ -113,6 +115,20 @@
   // No crash.
   EXPECT_EQ(buildCompilerInvocation(Inputs, Diags), nullptr);
 }
+
+TEST(BuildCompilerInvocation, SuppressDiags) {
+  MockFS FS;
+  StoreDiags Diags;
+  TestTU TU;
+  TU.ExtraArgs = {"-funknown-arg"};
+  auto Inputs = TU.inputs(FS);
+
+  Config Cfg;
+  Cfg.Diagnostics.Suppress = {"drv_unknown_argument"};
+  WithContextValue SuppressFilterWithCfg(Config::Key, std::move(Cfg));
+  EXPECT_NE(buildCompilerInvocation(Inputs, Diags), nullptr);
+  EXPECT_THAT(Diags.take(), IsEmpty());
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cp

[PATCH] D127844: [clangd] Pull suppression logic into common path, apply for driver diagnostics

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 437109.
kadircet added a comment.

Just pass optional directly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127844

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/CompilerTests.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1870,6 +1870,27 @@
   "'int' to 'int *' for 1st argument; take the address of "
   "the argument with &");
 }
+
+TEST(DiagnosticsTest, DontSuppressSubcategories) {
+  Annotations Source(R"cpp(
+  /*error-ok*/
+void bar(int x) {
+  switch(x) {
+  default:
+break;
+break;
+  }
+})cpp");
+  TestTU TU;
+  TU.ExtraArgs.push_back("-Wunreachable-code-aggressive");
+  TU.Code = Source.code().str();
+  Config Cfg;
+  // This shouldn't suppress subcategory unreachable-break.
+  Cfg.Diagnostics.Suppress = {"unreachable-code"};
+  WithContextValue SuppressFilterWithCfg(Config::Key, std::move(Cfg));
+  EXPECT_THAT(*TU.build().getDiagnostics(),
+  ElementsAre(diagName("-Wunreachable-code-break")));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -284,6 +284,7 @@
 }
 
 TEST_F(ConfigCompileTests, DiagnosticSuppression) {
+  // Check that canonicalization and compilation works.
   Frag.Diagnostics.Suppress.emplace_back("bugprone-use-after-move");
   Frag.Diagnostics.Suppress.emplace_back("unreachable-code");
   Frag.Diagnostics.Suppress.emplace_back("-Wunused-variable");
@@ -296,21 +297,8 @@
"unreachable-code", "unused-variable",
"typecheck_bool_condition",
"unexpected_friend", "warn_alloca"));
-  EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
-  diag::warn_unreachable, Conf.Diagnostics.Suppress, LangOptions()));
-  // Subcategory not respected/suppressed.
-  EXPECT_FALSE(isBuiltinDiagnosticSuppressed(
-  diag::warn_unreachable_break, Conf.Diagnostics.Suppress, LangOptions()));
-  EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
-  diag::warn_unused_variable, Conf.Diagnostics.Suppress, LangOptions()));
-  EXPECT_TRUE(isBuiltinDiagnosticSuppressed(diag::err_typecheck_bool_condition,
-Conf.Diagnostics.Suppress,
-LangOptions()));
-  EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
-  diag::err_unexpected_friend, Conf.Diagnostics.Suppress, LangOptions()));
-  EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
-  diag::warn_alloca, Conf.Diagnostics.Suppress, LangOptions()));
 
+  // Check that we treat * specially.
   Frag.Diagnostics.Suppress.emplace_back("*");
   EXPECT_TRUE(compileAndApply());
   EXPECT_TRUE(Conf.Diagnostics.SuppressAll);
Index: clang-tools-extra/clangd/unittests/CompilerTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "Compiler.h"
+#include "Config.h"
+#include "Diagnostics.h"
 #include "TestTU.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/FrontendOptions.h"
@@ -113,6 +115,20 @@
   // No crash.
   EXPECT_EQ(buildCompilerInvocation(Inputs, Diags), nullptr);
 }
+
+TEST(BuildCompilerInvocation, SuppressDiags) {
+  MockFS FS;
+  StoreDiags Diags;
+  TestTU TU;
+  TU.ExtraArgs = {"-funknown-arg"};
+  auto Inputs = TU.inputs(FS);
+
+  Config Cfg;
+  Cfg.Diagnostics.Suppress = {"drv_unknown_argument"};
+  WithContextValue SuppressFilterWithCfg(Config::Key, std::move(Cfg));
+  EXPECT_NE(buildCompilerInvocation(Inputs, Diags), nullptr);
+  EXPECT_THAT(Diags.take(), IsEmpty());
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -491,25 +491,20 @@
   llvm::IntrusiveRefCntPtr PreambleDiagsEngine =
   CompilerInstance::createDiagnostics(&CI.getDi

[PATCH] D127629: [clang] Use correct visibility parameters when following a Using declaration

2022-06-15 Thread Furkan via Phabricator via cfe-commits
furkanusta added a comment.

I don't think I have a commit access this is my first contribution. I 
appreciate if you can do it for me.

My mail address is:  furkanust...@gmail.com

I had my github account linked and expecting for my mail to get fetched 
automatically.
To make things easier should I sign my commits in the future or is there a 
variable that I can set in the Arcanist tool?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127629

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


[PATCH] D127836: [analyzer][NFC] Remove dead code and modernize surroundings

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:931-934
+  // void *getTag() const {
+  //   static int Tag = 0;
+  //   return static_cast(&Tag);
+  // }

Why should we keep this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127836

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


[PATCH] D127839: [analyzer] Fix StreamErrorState hash bug

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

Nice catch! LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127839

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


[PATCH] D127746: [clang][dataflow] Convert `PointeeLoc` of `PointerValue` from reference to pointer.

2022-06-15 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.
Herald added a subscriber: martong.

Overall, this seems to be an important API change, and I'm having trouble 
seeing the big picture here.  I think it would be great if you could expand (in 
the CL description) on the motivation behind the change and the thinking behind 
the particular design choices you've made here.  For example, you mentioned 
that this change supports explicit modeling of `nullptr`, but what is gained by 
this explicit modeling? Also, regarding the design choice itself: is the intent 
that native `nullptr` now represents an interpreted `nullptr`? If so, have you 
considered instead introducing an explicit `NullptrLocation` or the like and if 
so, what were the tradeoffs in this decision?




Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:332
 
-  StorageLocation &skip(StorageLocation &Loc, SkipPast SP) const;
-  const StorageLocation &skip(const StorageLocation &Loc, SkipPast SP) const;
+  StorageLocation *skip(StorageLocation &Loc, SkipPast SP) const;
+  const StorageLocation *skip(const StorageLocation &Loc, SkipPast SP) const;

Please document the conditions under which these functions return nullptr.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:348
 
 StorageLocation *Environment::getStorageLocation(const ValueDecl &D,
  SkipPast SP) const {

If I understand correctly, the `nullptr` result from this function is now 
ambiguous: either there's no entry for that storagelocation, or there is and it 
is null. But, perhaps I'm misunderstanding -- is this not a concern?



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:266-267
 
-  auto &Loc = Env.createStorageLocation(*S);
-  Env.setStorageLocation(*S, Loc);
-  Env.setValue(Loc, Env.takeOwnership(std::make_unique(
-SubExprVal->getPointeeLoc(;
+  // If PointeeLoc is null, then we are dereferencing a nullptr, skip
+  // creating a value for the dereference
+  if (auto *PointeeLoc = SubExprVal->getPointeeLoc()) {

sgatev wrote:
> Can you please add a test for this?
How does this work in practice? It seems to be an unsual case that we 
statically know a pointer is null. So, what is the use of this change and (more 
importantly) what is the impact on the framework, if any?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127746

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


[PATCH] D127838: [analyzer][NFC] Remove dead field of UnixAPICheckers

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Umm, why this can't be part of D127836  ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127838

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


[PATCH] D127163: [clang] Add -fsanitize=memtag-globals (no-op).

2022-06-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127163

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


[PATCH] D127649: [analyzer][NFC][test] Add new RUN line with support-symbolic-integer-casts=true to expr-inspection.cpp

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 437112.
martong marked an inline comment as done.
martong added a comment.

- Use template declarations


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127649

Files:
  clang/test/Analysis/expr-inspection.cpp


Index: clang/test/Analysis/expr-inspection.cpp
===
--- clang/test/Analysis/expr-inspection.cpp
+++ clang/test/Analysis/expr-inspection.cpp
@@ -1,9 +1,17 @@
-// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection 
-verify %s
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN:-analyzer-config support-symbolic-integer-casts=false \
+// RUN:-verify %s
+
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN:-analyzer-config support-symbolic-integer-casts=true \
+// RUN:-verify %s
 
 // Self-tests for the debug.ExprInspection checker.
 
-void clang_analyzer_denote(int x, const char *str);
-void clang_analyzer_express(int x);
+template 
+void clang_analyzer_denote(T x, const char *str);
+template 
+void clang_analyzer_express(T x);
 
 // Invalid declarations to test basic correctness checks.
 void clang_analyzer_denote();


Index: clang/test/Analysis/expr-inspection.cpp
===
--- clang/test/Analysis/expr-inspection.cpp
+++ clang/test/Analysis/expr-inspection.cpp
@@ -1,9 +1,17 @@
-// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN:-analyzer-config support-symbolic-integer-casts=false \
+// RUN:-verify %s
+
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN:-analyzer-config support-symbolic-integer-casts=true \
+// RUN:-verify %s
 
 // Self-tests for the debug.ExprInspection checker.
 
-void clang_analyzer_denote(int x, const char *str);
-void clang_analyzer_express(int x);
+template 
+void clang_analyzer_denote(T x, const char *str);
+template 
+void clang_analyzer_express(T x);
 
 // Invalid declarations to test basic correctness checks.
 void clang_analyzer_denote();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127649: [analyzer][NFC][test] Add new RUN line with support-symbolic-integer-casts=true to expr-inspection.cpp

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/test/Analysis/expr-inspection.cpp:11-13
 void clang_analyzer_denote(int x, const char *str);
+void clang_analyzer_denote(unsigned x, const char *str);
 void clang_analyzer_express(int x);

steakhal wrote:
> 
Ok, done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127649

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


[PATCH] D122150: [clang][analyzer] Add checker for bad use of 'errno'.

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I believe `evalAssume` would be a better fit for diagnosing such issues, but I 
can see your point that we don't have `CheckerContext` there to emit reports.
That being said, the `check::Location` is the best alternative.

Please also check the not `done` comments.




Comment at: clang/docs/analyzer/checkers.rst:2529
+Check for unsafe use of ``errno``.
+This checker can find the first read of ``errno`` after not failed standard
+function calls.

successful



Comment at: clang/docs/analyzer/checkers.rst:2538-2539
+yet supported by the checker.
+The return values for the failure cases are documented in the standard Linux 
man
+pages of the functions.
+

Maybe place a crossref for this.

Also, am I right that there is a CERT rule about this issue?
We should probably mention that, while placing a crossref too.



Comment at: clang/include/clang/StaticAnalyzer/Checkers/Checkers.td:550
+def ErrnoChecker : Checker<"Errno">,
+  HelpText<"Check not recommended uses of 'errno'">,
+  Dependencies<[ErrnoModeling]>,

antipatterns?



Comment at: clang/include/clang/StaticAnalyzer/Checkers/Checkers.td:554
+CmdLineOption, // ??
+  ]>,

balazske wrote:
> steakhal wrote:
> > I think we have 'Hidden', but not 'Hide'.
> > It means that it is a modeling checker. Any checker that emits diagnostics, 
> > should **not** be marked 'Hidden'.
> This "Hide" applies for the option, not for the checker. It was copied from 
> another place. I am not sure if it must be used here.
Quote `CheckerBase.td:39`
```
/// Marks the entry hidden. Hidden entries won't be displayed in
/// -analyzer-checker-option-help.
class HiddenEnum {
  bit Val = val;
}
def DontHide : HiddenEnum<0>;
def Hide : HiddenEnum<1>;
```

I believe, we should expose this option. Otherwise why would we introduce it in 
the first place?
The default value of this is actually `DontHide` in the `CmdLineOption<>` td 
class. So, you should be fine by simply omitting this keyword here.



Comment at: clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp:10-11
+// This defines an "errno checker" that can detect some invalid use of the
+// system-defined value 'errno'. This checker works together with the
+// ErrnoModeling checker.
+//

and the StdLibraryFunctionsChecker per D125400.



Comment at: clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp:101-102
+  break;
+default:
+  break;
+}

We should also handle `BinaryOperator` for conditional operators (EQ, NE, LT, 
LE, ...). Or at least leave a FIXME about this.
Have a test demonstrating the behavior.



Comment at: clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp:261
+  if (unsigned EState = State->get())
+return static_cast(EState);
+  return Errno_Irrelevant;

I believe you no longer need to cast enums to numbers and back for enums and 
other types.
`get()` should return the right type.
See D126801.



Comment at: clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp:280
+  BR.markNotInteresting(ErrnoR);
+  return Message.c_str();
+}




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122150

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


[clang] 3605ebc - [analyzer][NFC][test] Add new RUN lint with support-symbolic-integer-casts=true to svalbuilder-rearrange-comparisons.c

2022-06-15 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-06-15T13:52:18+02:00
New Revision: 3605ebca32fc42d01a54eea00bb4bf8049dca214

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

LOG: [analyzer][NFC][test] Add new RUN lint with 
support-symbolic-integer-casts=true to svalbuilder-rearrange-comparisons.c

Added a new run line to bolster gradual transition of handling cast operations,
see 
https://discourse.llvm.org/t/roadmap-of-modeling-symbolic-cast-operations/63107

Differential Revision: https://reviews.llvm.org/D127646

Added: 
clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp

Modified: 


Removed: 
clang/test/Analysis/svalbuilder-rearrange-comparisons.c



diff  --git a/clang/test/Analysis/svalbuilder-rearrange-comparisons.c 
b/clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
similarity index 96%
rename from clang/test/Analysis/svalbuilder-rearrange-comparisons.c
rename to clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
index 32af8dde71c92..06a5c7c41169b 100644
--- a/clang/test/Analysis/svalbuilder-rearrange-comparisons.c
+++ b/clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
@@ -1,8 +1,23 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection,core.builtin 
-analyzer-config aggressive-binary-operation-simplification=true -verify 
-analyzer-config eagerly-assume=false %s
-
-void clang_analyzer_eval(int x);
-void clang_analyzer_denote(int x, const char *literal);
-void clang_analyzer_express(int x);
+// RUN: %clang_analyze_cc1 \
+// RUN:-analyzer-checker=debug.ExprInspection,core.builtin \
+// RUN:-analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:-analyzer-config support-symbolic-integer-casts=false \
+// RUN:-analyzer-config eagerly-assume=false \
+// RUN:-verify %s
+
+// RUN: %clang_analyze_cc1 \
+// RUN:-analyzer-checker=debug.ExprInspection,core.builtin \
+// RUN:-analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:-analyzer-config support-symbolic-integer-casts=true \
+// RUN:-DSUPPORT_SYMBOLIC_INTEGER_CASTS \
+// RUN:-analyzer-config eagerly-assume=false \
+// RUN:-verify %s
+
+void clang_analyzer_eval(bool x);
+template 
+void clang_analyzer_denote(T x, const char *literal);
+template 
+void clang_analyzer_express(T x);
 
 void exit(int);
 
@@ -510,6 +525,17 @@ void 
compare_same_symbol_minus_left_minus_right_int_less(void) {
   clang_analyzer_eval(x < y); // expected-warning {{FALSE}}
 }
 
+// Rearrange should happen on signed types only (tryRearrange):
+//
+//  // Rearrange signed symbolic expressions only
+//  if (!SingleTy->isSignedIntegerOrEnumerationType())
+//return None;
+//
+// Without the symbolic casts, the SVal for `x` in `unsigned x = f()` will be
+// the signed `int`. However, with the symbolic casts it will be `unsigned`.
+// Thus, these tests are meaningful only if the cast is not emitted.
+#ifndef SUPPORT_SYMBOLIC_INTEGER_CASTS
+
 void compare_
diff erent_symbol_equal_unsigned(void) {
   unsigned x = f(), y = f();
   clang_analyzer_denote(x, "$x");
@@ -894,6 +920,10 @@ void compare_
diff erent_symbol_minus_left_minus_right_int_less_unsigned(void) {
   clang_analyzer_express(x < y); // expected-warning {{$x - $y < 1}}
 }
 
+#endif
+
+// These pass even with aggressive-binary-operation-simplification=false
+
 void compare_same_symbol_less_unsigned(void) {
   unsigned x = f(), y = x;
   clang_analyzer_denote(x, "$x");



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


[PATCH] D127646: [analyzer][NFC][test] Add new RUN lint with support-symbolic-integer-casts=true to svalbuilder-rearrange-comparisons.c

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added inline comments.



Comment at: clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp:16-17
+
+template 
+void clang_analyzer_eval(T x);
+template 

steakhal wrote:
> 
Ok, thx, done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127646

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


[PATCH] D127646: [analyzer][NFC][test] Add new RUN lint with support-symbolic-integer-casts=true to svalbuilder-rearrange-comparisons.c

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
martong marked an inline comment as done.
Closed by commit rG3605ebca32fc: [analyzer][NFC][test] Add new RUN lint with 
support-symbolic-integer-casts=true… (authored by martong).

Changed prior to commit:
  https://reviews.llvm.org/D127646?vs=436397&id=437113#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127646

Files:
  clang/test/Analysis/svalbuilder-rearrange-comparisons.c
  clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp


Index: clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
===
--- clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
+++ clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
@@ -1,8 +1,23 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection,core.builtin 
-analyzer-config aggressive-binary-operation-simplification=true -verify 
-analyzer-config eagerly-assume=false %s
-
-void clang_analyzer_eval(int x);
-void clang_analyzer_denote(int x, const char *literal);
-void clang_analyzer_express(int x);
+// RUN: %clang_analyze_cc1 \
+// RUN:-analyzer-checker=debug.ExprInspection,core.builtin \
+// RUN:-analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:-analyzer-config support-symbolic-integer-casts=false \
+// RUN:-analyzer-config eagerly-assume=false \
+// RUN:-verify %s
+
+// RUN: %clang_analyze_cc1 \
+// RUN:-analyzer-checker=debug.ExprInspection,core.builtin \
+// RUN:-analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:-analyzer-config support-symbolic-integer-casts=true \
+// RUN:-DSUPPORT_SYMBOLIC_INTEGER_CASTS \
+// RUN:-analyzer-config eagerly-assume=false \
+// RUN:-verify %s
+
+void clang_analyzer_eval(bool x);
+template 
+void clang_analyzer_denote(T x, const char *literal);
+template 
+void clang_analyzer_express(T x);
 
 void exit(int);
 
@@ -510,6 +525,17 @@
   clang_analyzer_eval(x < y); // expected-warning {{FALSE}}
 }
 
+// Rearrange should happen on signed types only (tryRearrange):
+//
+//  // Rearrange signed symbolic expressions only
+//  if (!SingleTy->isSignedIntegerOrEnumerationType())
+//return None;
+//
+// Without the symbolic casts, the SVal for `x` in `unsigned x = f()` will be
+// the signed `int`. However, with the symbolic casts it will be `unsigned`.
+// Thus, these tests are meaningful only if the cast is not emitted.
+#ifndef SUPPORT_SYMBOLIC_INTEGER_CASTS
+
 void compare_different_symbol_equal_unsigned(void) {
   unsigned x = f(), y = f();
   clang_analyzer_denote(x, "$x");
@@ -894,6 +920,10 @@
   clang_analyzer_express(x < y); // expected-warning {{$x - $y < 1}}
 }
 
+#endif
+
+// These pass even with aggressive-binary-operation-simplification=false
+
 void compare_same_symbol_less_unsigned(void) {
   unsigned x = f(), y = x;
   clang_analyzer_denote(x, "$x");


Index: clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
===
--- clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
+++ clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
@@ -1,8 +1,23 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection,core.builtin -analyzer-config aggressive-binary-operation-simplification=true -verify -analyzer-config eagerly-assume=false %s
-
-void clang_analyzer_eval(int x);
-void clang_analyzer_denote(int x, const char *literal);
-void clang_analyzer_express(int x);
+// RUN: %clang_analyze_cc1 \
+// RUN:-analyzer-checker=debug.ExprInspection,core.builtin \
+// RUN:-analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:-analyzer-config support-symbolic-integer-casts=false \
+// RUN:-analyzer-config eagerly-assume=false \
+// RUN:-verify %s
+
+// RUN: %clang_analyze_cc1 \
+// RUN:-analyzer-checker=debug.ExprInspection,core.builtin \
+// RUN:-analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:-analyzer-config support-symbolic-integer-casts=true \
+// RUN:-DSUPPORT_SYMBOLIC_INTEGER_CASTS \
+// RUN:-analyzer-config eagerly-assume=false \
+// RUN:-verify %s
+
+void clang_analyzer_eval(bool x);
+template 
+void clang_analyzer_denote(T x, const char *literal);
+template 
+void clang_analyzer_express(T x);
 
 void exit(int);
 
@@ -510,6 +525,17 @@
   clang_analyzer_eval(x < y); // expected-warning {{FALSE}}
 }
 
+// Rearrange should happen on signed types only (tryRearrange):
+//
+//  // Rearrange signed symbolic expressions only
+//  if (!SingleTy->isSignedIntegerOrEnumerationType())
+//return None;
+//
+// Without the symbolic casts, the SVal for `x` in `unsigned x = f()` will be
+// the signed `int`. However, with the symbolic casts it will be `unsigned`.
+// Thus, these 

[PATCH] D125400: [clang][Analyzer] Add errno state to standard functions modeling.

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

It looks everything fine, given that the `alpha.unix.Errno` will depend on the 
`apimodeling.StdCLibraryFunctions`.
This should do the expected errno state propagation by which the `Errno` 
checker can report diagnostics - WHILE the `StdCLibraryFunctions` still won't 
report diagnostics.
This means that the Errno part /diagnostics can be separately disabled from the 
diagnostics of `StdCLibraryFunctionArgsChecker` and other frontend checkers of 
the `StdCLibraryFunctionsChecker` modeling part.
Excellent.

Please demonstrate that indeed disabling separately `Errno` or 
`StdCLibraryFunctionArgsChecker` will make the respective reports disappear.

---

I can see that in many cases you introduced an additional `.Case()`, which will 
result in a state-split.
I'm curious what runtime implications this change introduces. Please measure 
this.

I must also admit that I haven't checked the parameters of `Case()` in all 
cases; so I would encourage you to double-check those to make sure they are in 
line with the API specification.

Given these changes are implemented, I think it's ready to land. Awesome job, 
really!
Sorry about reject, I just saw it's green and I still had some thoughts about 
this.




Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:68-69
+return "may be undefined after the call and should not be used";
+  };
+}
+





Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:444
+  DefinedOrUnknownSVal Cond =
+  SVB.evalBinOpNN(State, Op, ErrnoSVal, ZeroVal, 
SVB.getConditionType())
+  .castAs();

nit: we should not use the `NN` and other suffixed versions of this API. The 
generic one should suffice.
Actually, I plan to refactor all code and make those private.



Comment at: clang/test/Analysis/errno-stdlibraryfunctions-notes.c:15-23
+void test1() {
+  access("path", 0); // no note here
+  access("path", 0);
+  // expected-note@-1{{Assuming that function 'access' is successful, in this 
case the value 'errno' may be undefined after the call and should not be used}}
+  if (errno != 0) {
+// expected-warning@-1{{An undefined value may be read from 'errno'}}
+// expected-note@-2{{An undefined value may be read from 'errno'}}

martong wrote:
> balazske wrote:
> > steakhal wrote:
> > > I must say that I dislike that one cannot disable this warning unless 
> > > they disable the whole stdlibrarymodeling. It's getting bigger and 
> > > bigger, thus increasing the value it provides. Yet, not everybody wants 
> > > to follow SEI CERT guidelines - and I would expect plenty of users in 
> > > that category, who might be surprised that reading `errno` is a bug.
> > > 
> > > Just imagine in the example that between the two `access()` calls, you 
> > > set `errno` to zero.
> > > The code would look reasonable.
> > > 1) reset errno
> > > 2) do some syscall
> > > 3) check errno
> > > 
> > > I would expect this to be a good practice. We should at least have an 
> > > option for suppressing reports for such scenarios. IMO it should be 
> > > rather opt-in, than opt-out, but it might be my personal preference.
> > > WDYT @martong @xazax.hun 
> > The CERT rule says that there is no guarantee that `errno` is not changed 
> > if the function is successful, regardless if it was 0 or not. There are 
> > some functions (that have //in-band return value//) where it is required to 
> > set `errno` to 0, there can be another checker (or extend `ErrnoChecker`) 
> > to check this.
> > 
> > The new warning is turned on when `alpha.unix.Errno` is turned on, 
> > otherwise it should not appear.
> > I must say that I dislike that one cannot disable this warning unless they 
> > disable the whole stdlibrarymodeling. 
> 
> Yeah, good point. Perhaps we should have a new checker option that 
> enables/disables errno related reports. Should this be part of the 
> ErrnoChecker (or the StdLibraryFunctionsChecker)?
> The new warning is turned on when alpha.unix.Errno is turned on, otherwise it 
> should not appear.
Oh, I see. I might overreacted this part.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125400

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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-06-15 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 437119.
pmatos retitled this revision from "[WebAssembly] Initial support for reference 
types in clang" to "[WebAssembly] Initial support for reference type externref 
in clang".
pmatos edited the summary of this revision.
pmatos added a comment.

Update revision to be specific to externref only. 
A different revision will be opened for further work on externref builtins and 
funcref.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp

Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -304,6 +304,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
+  // pointer to opaque struct in addrspace(10)
+  static PointerType *Ty = PointerType::get(StructType::get(C), 10);
+  return Ty;
+}
+
+Type *Type::getWasm_FuncrefTy(LLVMContext &C) {
+  // pointer to i8 addrspace(20)
+  static PointerType *Ty = PointerType::get(Type::getInt8Ty(C), 20);
+  return Ty;
+}
+
 //===--===//
 //   IntegerType Implementation
 //===--===//
Index: llvm/lib/CodeGen/ValueTypes.cpp
===
--- llvm/lib/CodeGen/ValueTypes.cpp
+++ llvm/lib/CodeGen/ValueTypes.cpp
@@ -204,12 +204,8 @@
   case MVT::x86mmx:  return Type::getX86_MMXTy(Context);
   case MVT::x86amx:  return Type::getX86_AMXTy(Context);
   case MVT::i64x8:   return IntegerType::get(Context, 512);
-  case MVT::externref:
-// pointer to opaque struct in addrspace(10)
-return PointerType::get(StructType::create(Context), 10);
-  case MVT::funcref:
-// pointer to i8 addrspace(20)
-return PointerType::get(Type::getInt8Ty(Context), 20);
+  case MVT::externref: return Type::getWasm_ExternrefTy(Context);
+  case MVT::funcref: return Type::getWasm_FuncrefTy(Context);
   case MVT::v1i1:
 return FixedVectorType::get(Type::getInt1Ty(Context), 1);
   case MVT::v2i1:
Index: llvm/include/llvm/IR/Type.h
===
--- llvm/include/llvm/IR/Type.h
+++ llvm/include/llvm/IR/Type.h
@@ -468,6 +468,8 @@
   static PointerType *getInt16PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0);
+  static Type *getWasm_ExternrefTy(LLVMContext &C);
+  static Type *getWasm_FuncrefTy(LLVMContext &C);
 
   /// Return a pointer to the current type. This is equivalent to
   /// PointerType::get(Foo, AddrSpace).
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1627,6 +1627,8 @@
 #include "clang/Basic/PPCTypes.def"
 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/RISCVVTypes.def"
+#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define BUILTIN_TYPE(Id, SingletonId)
 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define UNSIGNED_

[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-06-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Some likely final coding style nits. The only thing of substance I'm waiting on 
is an answer to whether we need to update a license file in order to comply 
with the Unicode license requirements. @tstellar, any chance you can help there?




Comment at: clang/lib/Lex/Lexer.cpp:3237-3239
+  if (C != '{') {
+if (Diagnose)
+  Diag(StartPtr, diag::warn_ucn_escape_incomplete);

cor3ntin wrote:
> aaron.ballman wrote:
> > Is this a case where we might want a fixit because the user did `\N` when 
> > they meant to do `\n`?
> > 
> > (Should we look for `\N(` and fixit that to `\N{`?)
> I think if we wanted to diagnose \n we should also diagnose \U, which we 
> don't do, Maybe a follow up patch, what do you think?
> I can't imagine trying to be smart about `\N(` would be exercised  by many 
> users
Follow-up (if at all) is fine by me!



Comment at: llvm/lib/Support/UnicodeNameToCodepoint.cpp:41
+  constexpr bool isValid() const {
+return Name.size() != 0 || Value == 0x;
+  }





Comment at: llvm/lib/Support/UnicodeNameToCodepoint.cpp:45
+
+  std::string FullName() const {
+std::string s;





Comment at: llvm/lib/Support/UnicodeNameToCodepoint.cpp:120
+
+static bool StartsWith(StringRef Name, StringRef Needle, bool Strict,
+   std::size_t &Consummed, char &PreviousCharInName,





Comment at: llvm/lib/Support/UnicodeNameToCodepoint.cpp:131
+  }
+  if (Needle.size() == 0)
+return true;





Comment at: llvm/lib/Support/UnicodeNameToCodepoint.cpp:183
+BufferType &Buffer, const Node *Parent = nullptr) {
+  auto N = readNode(Offset, Parent);
+  std::size_t Consummed = 0;





Comment at: llvm/lib/Support/UnicodeNameToCodepoint.cpp:222
+// clang-format off
+constexpr const char *const hangul_syllables[][3] = {
+{ "G",  "A",   ""   },





Comment at: llvm/lib/Support/UnicodeNameToCodepoint.cpp:303
+  Name = Name.substr(findSyllable(Name, Strict, NameStart, T, 2));
+  if (L != -1 && V != -1 && T != -1 && Name.size() == 0) {
+if (!Strict) {





Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:1-3
+//===- utils/UnicodeData/UnicodeNameMappingGenerator.cpp - Unicode name data
+// generator -===//
+//-*- C++ -*-===//

Something looks amiss here -- no idea how we usually handle > 80 col file 
names, but maybe removing the `utils/UnicodeData/` prefix will suffice?



Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:31
+
+static const llvm::StringRef LETTERS =
+" _-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";





Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:56
+
+  auto Name =
+  Line.substr(FirstSemiPos + 1, SecondSemiPos - FirstSemiPos - 1);





Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:59
+
+  if (Name.size() && Name[0] == '<') {
+// Ignore ranges of characters, as their name is either absent or





Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:67
+  if (IsAliasFile) {
+auto Kind = Line.substr(SecondSemiPos + 1);
+if (Kind != "control" && Kind != "correction" && Kind != "alternate")





Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:206
+
+  assert(N->Name.size() != 0);
+  Offsets[N] = Offset;





Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:349
+
+  auto Out = fopen(argv[3], "w");
+  if (!Out) {





Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:360-361
+  for (const std::pair &Entry : Entries) {
+const auto &Codepoint = Entry.first;
+const auto &Name = Entry.second;
+// Ignore names which are not valid.





Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:379-380
+  std::pair> Data = T.serialize();
+  const auto &Dict = Data.first;
+  const auto &Tree = Data.second;
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

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


[PATCH] D127798: [AArch64] Define __ARM_FEATURE_RCPC

2022-06-15 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 added a comment.

The patch looks correct to me, but looking at 
https://github.com/ARM-software/acle/blob/main/main/acle.md where all the ACLE 
macros are defined, I'm not sure that `__ARM_FEATURE_RCPC` is there currently. 
Maybe you also want to submit a patch there, or at least explain the context of 
this change please?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127798

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


[PATCH] D127836: [analyzer][NFC] Remove dead code and modernize surroundings

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 437120.
steakhal added a comment.

remove dead code from MallocChecker


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127836

Files:
  clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.h
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -352,7 +352,6 @@
 
 private:
   void storeTopLevelDecls(DeclGroupRef DG);
-  std::string getFunctionName(const Decl *D);
 
   /// Check if we should skip (not analyze) the given function.
   AnalysisMode getModeForDecl(Decl *D, AnalysisMode Mode);
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -118,18 +118,10 @@
 /// the construction context was present and contained references to these
 /// AST nodes.
 class ConstructedObjectKey {
-  typedef std::pair
-  ConstructedObjectKeyImpl;
-
+  using ConstructedObjectKeyImpl =
+  std::pair;
   const ConstructedObjectKeyImpl Impl;
 
-  const void *getAnyASTNodePtr() const {
-if (const Stmt *S = getItem().getStmtOrNull())
-  return S;
-else
-  return getItem().getCXXCtorInitializer();
-  }
-
 public:
   explicit ConstructedObjectKey(const ConstructionContextItem &Item,
const LocationContext *LC)
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -527,11 +527,6 @@
 ID.AddPointer(RegionOfInterest);
   }
 
-  void *getTag() const {
-static int Tag = 0;
-return static_cast(&Tag);
-  }
-
 private:
   /// \return Whether \c RegionOfInterest was modified at \p CurrN compared to
   /// the value it holds in \p CallExitBeginN.
Index: clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
@@ -22,27 +22,15 @@
 using namespace taint;
 
 namespace {
-class TaintTesterChecker : public Checker< check::PostStmt > {
-
-  mutable std::unique_ptr BT;
-  void initBugType() const;
-
-  /// Given a pointer argument, get the symbol of the value it contains
-  /// (points to).
-  SymbolRef getPointedToSymbol(CheckerContext &C,
-   const Expr* Arg,
-   bool IssueWarning = true) const;
+class TaintTesterChecker : public Checker> {
+  std::unique_ptr BT =
+  std::make_unique(this, "Tainted data", "General");
 
 public:
   void checkPostStmt(const Expr *E, CheckerContext &C) const;
 };
 }
 
-inline void TaintTesterChecker::initBugType() const {
-  if (!BT)
-BT.reset(new BugType(this, "Tainted data", "General"));
-}
-
 void TaintTesterChecker::checkPostStmt(const Expr *E,
CheckerContext &C) const {
   ProgramStateRef State = C.getState();
@@ -51,7 +39,6 @@
 
   if (isTainted(State, E, C.getLocationContext())) {
 if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
-  initBugType();
   auto report = std::make_unique(*BT, "tainted", N);
   report->addRange(E->getSourceRange());
   C.emitReport(std::move(report));
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -50,7 +50,6 @@
   // Whether the checker should model for null dereferences of smart pointers.
   bool ModelSmartPtrDereference = false;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
-  void checkPreCall(const CallEvent &Call, CheckerContext &C) 

[PATCH] D127836: [analyzer][NFC] Remove dead code and modernize surroundings

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:931-934
+  // void *getTag() const {
+  //   static int Tag = 0;
+  //   return static_cast(&Tag);
+  // }

martong wrote:
> Why should we keep this?
Accident xD


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127836

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


[PATCH] D127838: [analyzer][NFC] Remove dead field of UnixAPICheckers

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D127838#3584911 , @martong wrote:

> Umm, why this can't be part of D127836  ?

It can be, but I wanted to still do this separately. The reasoning in the 
summary should nominate this to a separate discussion.
Just consider if it was a real catch. I would definitely not wanted it to be 
part of that generic refactor change.
In the end, it turned out to be not the case, but I wanted to be explicit about 
this.

That being said, I'd insist.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127838

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


[PATCH] D127454: [OpenMP] Initial parsing and sema for 'parallel masked' construct

2022-06-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127454

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


[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-06-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Lex/LiteralSupport.cpp:509-511
+if (std::max(Distance, Match.Distance) -
+std::min(Distance, Match.Distance) >
+3)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

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


[PATCH] D127593: [clang] Fix trivially copyable for copy constructor and copy assignment operator

2022-06-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D127593#3583125 , @royjacobson 
wrote:

> Thank you! LGTM. I see the CI still has those OpenMP failures - could you try 
> to rebase on main to get it green?
>
> @erichkeane is this good to go? Should I ping some ABI people about this?

I think this is probably good to go here.  The OMP failures are still there 
though, which is a touch concerning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127593

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


[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-06-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I had a discussion about the license file on IRC (but not with @tstellar) and 
the thinking there was: add the license file. It seems to either be required or 
would be harmless to add. So if we don't hear something different from 
@tstellar on this, I think you should add the contents of 
https://www.unicode.org/license.txt to the top of the generated content for 
`UnicodeNameToCodepointGenerated.cpp` so that the license information stays 
with the derived data to which it applies.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

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


[PATCH] D127803: Generate the capture for field when the field is used with implicit default.

2022-06-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Why do we need to insert new implicit DSA? Only explicit DSAs are  expected to 
be stored, implicit ones can be deduced using the rules.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

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


[PATCH] D125723: [MSVC] Add initial support for MSVC pragma optimize

2022-06-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:301
   C linkage.
+- Added support for a nonempty optimization list for MSVC's ``#pragma 
optimize``.
+  The pragma takes a list of optimizations to turn on or off which applies to





Comment at: clang/include/clang/Sema/Sema.h:761-762
 
+  /// The list of valid optimization parameters passed by \#pragma optimize.
+  std::string MSPragmaOptimizeValidParams;
+  /// The "on" or "off" argument passed by \#pragma optimize, that denotes

I think we can get rid of this since it's unused now.



Comment at: clang/lib/Sema/SemaAttr.cpp:1142
+void Sema::ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD) {
+  assert(MSPragmaOptimizeValidParams.empty());
+

I think this should also be removed, as we never assign anything into that 
variable anyway.



Comment at: clang/lib/Sema/SemaAttr.cpp:1144-1149
+  // Don't modify the function attributes if it's "on". "on" resets the
+  // optimizations to the ones listed on the command line
+  if (!MSPragmaOptimizeIsOn) {
+AddOptnoneAttributeIfNoConflicts(FD, FD->getBeginLoc());
+return;
+  }




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125723

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


[PATCH] D126907: Deferred Concept Instantiation Implementation Take 2

2022-06-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D126907#3584555 , @ChuanqiXu wrote:

> I finally found some time to look at the crash. Although I haven't get an 
> idea, I found it crash at the following one too:
>
>   template 
>   concept Constraint = true;
>   
>   template 
>   class completion_handler_async_result {
>   public:
>   template 
>   static void initiate(Initiation&& initiation, RawCompletionToken&& 
> token);
>   };
>   
>   template 
>   concept Constraint2 =
>   requires() {
>   completion_handler_async_result::initiate(0, 0);
>   };
>   
>   template 
>   void use(int F)
>   requires Constraint2
>   {}
>
> The crash log is:
>
>   clang/lib/AST/ExprConstant.cpp:15083: bool 
> clang::Expr::EvaluateAsConstantExpr(clang::Expr::EvalResult&, const 
> clang::ASTContext&, clang::Expr::ConstantExprKind) const: Assertion 
> `!isValueDependent() && "Expression evaluator can't be called on a dependent 
> expression."' failed.
>
> I am not sure if they are the same problem.

Yep, that is a different crash for the same reason (mismatched 'depth' of the 
template parameters).  I saw that a few times as well, but I believe anything 
we do to solve the first will solve this as well.  I haven't had a chance all 
week to get back to this, but hopefully will be able to work more on it by EOW.


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

https://reviews.llvm.org/D126907

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


[PATCH] D127856: [clangd] Support multiline semantic tokens

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: sammccall, nridge.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Per LSP, multiline tokens should be handled as if they end at the end
of the line starting the token (there's also a capability to enable them, but
that's an adventure for a different day).

Fixes https://github.com/clangd/clangd/issues/1145


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127856

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -944,7 +944,7 @@
   )");
   Tokens.front().Modifiers |= unsigned(HighlightingModifier::Declaration);
   Tokens.front().Modifiers |= unsigned(HighlightingModifier::Readonly);
-  auto Results = toSemanticTokens(Tokens);
+  auto Results = toSemanticTokens(Tokens, /*Code=*/"");
 
   ASSERT_THAT(Results, SizeIs(3));
   EXPECT_EQ(Results[0].tokenType, unsigned(HighlightingKind::Variable));
@@ -972,13 +972,15 @@
   auto Before = toSemanticTokens(tokens(R"(
 [[foo]] [[bar]] [[baz]]
 [[one]] [[two]] [[three]]
-  )"));
+  )"),
+ /*Code=*/"");
   EXPECT_THAT(diffTokens(Before, Before), IsEmpty());
 
   auto After = toSemanticTokens(tokens(R"(
 [[foo]] [[hello]] [[world]] [[baz]]
 [[one]] [[two]] [[three]]
-  )"));
+  )"),
+/*Code=*/"");
 
   // Replace [bar, baz] with [hello, world, baz]
   auto Diff = diffTokens(Before, After);
@@ -1000,6 +1002,23 @@
   EXPECT_EQ(3u, Diff.front().tokens[2].length);
 }
 
+TEST(SemanticHighlighting, MultilineTokens) {
+  llvm::StringRef AnnotatedCode = R"cpp(
+[[fo
+o]] [[bar]])cpp";
+  auto Toks = toSemanticTokens(tokens(AnnotatedCode),
+   Annotations(AnnotatedCode).code());
+  ASSERT_THAT(Toks, SizeIs(2));
+  // foo
+  EXPECT_EQ(Toks[0].deltaLine, 1u);
+  EXPECT_EQ(Toks[0].deltaStart, 0u);
+  EXPECT_EQ(Toks[0].length, 2u);
+
+  // bar
+  EXPECT_EQ(Toks[1].deltaLine, 1u);
+  EXPECT_EQ(Toks[1].deltaStart, 2u);
+  EXPECT_EQ(Toks[1].length, 3u);
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -21,6 +21,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHTING_H
 
 #include "Protocol.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
@@ -101,7 +102,8 @@
 // main AST.
 std::vector getSemanticHighlightings(ParsedAST &AST);
 
-std::vector toSemanticTokens(llvm::ArrayRef);
+std::vector toSemanticTokens(llvm::ArrayRef,
+llvm::StringRef Code);
 llvm::StringRef toSemanticTokenType(HighlightingKind Kind);
 llvm::StringRef toSemanticTokenModifier(HighlightingModifier Modifier);
 std::vector diffTokens(llvm::ArrayRef Before,
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -30,7 +30,9 @@
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
 #include 
 
 namespace clang {
@@ -918,7 +920,8 @@
 }
 
 std::vector
-toSemanticTokens(llvm::ArrayRef Tokens) {
+toSemanticTokens(llvm::ArrayRef Tokens,
+ llvm::StringRef Code) {
   assert(std::is_sorted(Tokens.begin(), Tokens.end()));
   std::vector Result;
   const HighlightingToken *Last = nullptr;
@@ -939,8 +942,22 @@
   Out.deltaLine = Tok.R.start.line;
   Out.deltaStart = Tok.R.start.character;
 }
-assert(Tok.R.end.line == Tok.R.start.line);
-Out.length = Tok.R.end.character - Tok.R.start.character;
+if (Tok.R.end.line == Tok.R.start.line) {
+  Out.length = Tok.R.end.character - Tok.R.start.character;
+} else {
+  // If a tokens length is past the end of the line, it should be treated as
+  // if the token ends at the end of the line and will not wrap onto the
+  // next line.
+  // This is slow, but code rarely has multiline tokens.
+  // FIXME: There's a client capability for supporting multiline tokens,
+  // resp

Re: [PATCH] D127629: [clang] Use correct visibility parameters when following a Using declaration

2022-06-15 Thread Kadir Çetinkaya via cfe-commits
thanks! you're right, it was already included in the arcanist metadata, i
was too lazy to check beforehand, sorry.

On Wed, Jun 15, 2022 at 1:30 PM Furkan via Phabricator <
revi...@reviews.llvm.org> wrote:

> furkanusta added a comment.
>
> I don't think I have a commit access this is my first contribution. I
> appreciate if you can do it for me.
>
> My mail address is:  furkanust...@gmail.com
>
> I had my github account linked and expecting for my mail to get fetched
> automatically.
> To make things easier should I sign my commits in the future or is there a
> variable that I can set in the Arcanist tool?
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D127629/new/
>
> https://reviews.llvm.org/D127629
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-06-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Aside from some minor nits and the open question about validation, I think this 
is getting pretty close. I'm curious about the next steps with this though, 
given that there are no in-tree uses for it currently. You had mentioned you 
planned to work on an adapter so that we could eventually start to remove the 
existing SARIF implementation work at: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp.
 Are you still intending to work on that, or has the work from @cjdb changed 
your plans for the next steps? (I mostly am trying to figure out whether we 
should land this now because there's enough momentum that it will start being 
used "Real Soon Now" or whether we should wait for a bit until there's a patch 
to make use of this and then land the whole patch stack.)




Comment at: clang/include/clang/Basic/Sarif.h:82
+public:
+  static SarifArtifactLocation create(const llvm::StringRef URI) {
+return SarifArtifactLocation{URI.str()};

We don't typically use top-level `const` like this (same applies elsewhere) 
unless it's on a pointee/reference.



Comment at: clang/include/clang/Basic/Sarif.h:302-305
+  const llvm::StringRef SchemaURI{
+  "https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/";
+  "sarif-schema-2.1.0.json"};
+  const llvm::StringRef SchemaVersion{"2.1.0"};

FWIW, this use of top-level `const` is fine (we do use it for data member 
variables).



Comment at: clang/include/clang/Basic/Sarif.h:162
+public:
+  static ThreadFlow create() { return {}; }
+

aaron.ballman wrote:
> One question this raises for me is whether we should be enforcing invariants 
> from the SARIF spec as part of this interface or not. Currently, you can 
> create a thread flow that has no importance or a rule without a name/id, etc. 
> That means it's pretty easy to create SARIF that won't validate properly. One 
> possible way to alleviate this would be for the `create()` methods/ctors to 
> require these be set when creating the objects. However, I can imagine there 
> will be times when that is awkward due to following the builder pattern with 
> the interface. Another option would be to have some validation methods on 
> each of the interfaces and the whole tree gets validated after construction, 
> but this could have performance impacts.
> 
> What are your thoughts?
Are you still intending to add a `validate()` interface to take care of this, 
or are you still thinking about how to enforce invariants during construction 
(or some combination of the two)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109701

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


[clang-tools-extra] 462def2 - [clang] Use correct visibility parameters when following a Using declaration

2022-06-15 Thread Kadir Cetinkaya via cfe-commits

Author: Furkan Usta
Date: 2022-06-15T15:52:59+02:00
New Revision: 462def25ec134d30aade4ffbf1ddc4185f2ec616

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

LOG: [clang] Use correct visibility parameters when following a Using 
declaration

Fixes https://github.com/clangd/clangd/issues/1137

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D127629

Added: 


Modified: 
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang/lib/Sema/SemaCodeComplete.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 316fcb6293b12..18b02af48095f 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -413,6 +413,23 @@ TEST(CompletionTest, Accessible) {
   )cpp");
   EXPECT_THAT(External.Completions,
   AllOf(has("pub"), Not(has("prot")), Not(has("priv";
+
+  auto Results = completions(R"cpp(
+  struct Foo {
+public: void pub();
+protected: void prot();
+private: void priv();
+  };
+  struct Bar : public Foo {
+private: using Foo::pub;
+  };
+  void test() {
+Bar B;
+B.^
+  }
+  )cpp");
+  EXPECT_THAT(Results.Completions,
+  AllOf(Not(has("priv")), Not(has("prot")), Not(has("pub";
 }
 
 TEST(CompletionTest, Qualifiers) {

diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index d35e9c6e42bf2..ae2e71dcd5dac 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -1095,7 +1095,9 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext 
*CurContext) {
   if (const UsingShadowDecl *Using = dyn_cast(R.Declaration)) 
{
 CodeCompletionResult Result(Using->getTargetDecl(),
 getBasePriority(Using->getTargetDecl()),
-R.Qualifier);
+R.Qualifier, false,
+(R.Availability == CXAvailability_Available ||
+ R.Availability == CXAvailability_Deprecated));
 Result.ShadowDecl = Using;
 MaybeAddResult(Result, CurContext);
 return;
@@ -1268,7 +1270,9 @@ void ResultBuilder::AddResult(Result R, DeclContext 
*CurContext,
   if (const auto *Using = dyn_cast(R.Declaration)) {
 CodeCompletionResult Result(Using->getTargetDecl(),
 getBasePriority(Using->getTargetDecl()),
-R.Qualifier);
+R.Qualifier, false,
+(R.Availability == CXAvailability_Available ||
+ R.Availability == CXAvailability_Deprecated));
 Result.ShadowDecl = Using;
 AddResult(Result, CurContext, Hiding);
 return;



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


[PATCH] D127629: [clang] Use correct visibility parameters when following a Using declaration

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG462def25ec13: [clang] Use correct visibility parameters when 
following a Using declaration (authored by furkanusta, committed by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127629

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1095,7 +1095,9 @@
   if (const UsingShadowDecl *Using = dyn_cast(R.Declaration)) 
{
 CodeCompletionResult Result(Using->getTargetDecl(),
 getBasePriority(Using->getTargetDecl()),
-R.Qualifier);
+R.Qualifier, false,
+(R.Availability == CXAvailability_Available ||
+ R.Availability == CXAvailability_Deprecated));
 Result.ShadowDecl = Using;
 MaybeAddResult(Result, CurContext);
 return;
@@ -1268,7 +1270,9 @@
   if (const auto *Using = dyn_cast(R.Declaration)) {
 CodeCompletionResult Result(Using->getTargetDecl(),
 getBasePriority(Using->getTargetDecl()),
-R.Qualifier);
+R.Qualifier, false,
+(R.Availability == CXAvailability_Available ||
+ R.Availability == CXAvailability_Deprecated));
 Result.ShadowDecl = Using;
 AddResult(Result, CurContext, Hiding);
 return;
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -413,6 +413,23 @@
   )cpp");
   EXPECT_THAT(External.Completions,
   AllOf(has("pub"), Not(has("prot")), Not(has("priv";
+
+  auto Results = completions(R"cpp(
+  struct Foo {
+public: void pub();
+protected: void prot();
+private: void priv();
+  };
+  struct Bar : public Foo {
+private: using Foo::pub;
+  };
+  void test() {
+Bar B;
+B.^
+  }
+  )cpp");
+  EXPECT_THAT(Results.Completions,
+  AllOf(Not(has("priv")), Not(has("prot")), Not(has("pub";
 }
 
 TEST(CompletionTest, Qualifiers) {


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1095,7 +1095,9 @@
   if (const UsingShadowDecl *Using = dyn_cast(R.Declaration)) {
 CodeCompletionResult Result(Using->getTargetDecl(),
 getBasePriority(Using->getTargetDecl()),
-R.Qualifier);
+R.Qualifier, false,
+(R.Availability == CXAvailability_Available ||
+ R.Availability == CXAvailability_Deprecated));
 Result.ShadowDecl = Using;
 MaybeAddResult(Result, CurContext);
 return;
@@ -1268,7 +1270,9 @@
   if (const auto *Using = dyn_cast(R.Declaration)) {
 CodeCompletionResult Result(Using->getTargetDecl(),
 getBasePriority(Using->getTargetDecl()),
-R.Qualifier);
+R.Qualifier, false,
+(R.Availability == CXAvailability_Available ||
+ R.Availability == CXAvailability_Deprecated));
 Result.ShadowDecl = Using;
 AddResult(Result, CurContext, Hiding);
 return;
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -413,6 +413,23 @@
   )cpp");
   EXPECT_THAT(External.Completions,
   AllOf(has("pub"), Not(has("prot")), Not(has("priv";
+
+  auto Results = completions(R"cpp(
+  struct Foo {
+public: void pub();
+protected: void prot();
+private: void priv();
+  };
+  struct Bar : public Foo {
+private: using Foo::pub;
+  };
+  void test() {
+Bar B;
+B.^
+  }
+  )cpp");
+  EXPECT_THAT(Results.Completions,
+  AllOf(Not(has("priv")), Not(has("prot")), Not(has("pub";
 }
 
 TEST(CompletionTest, Qualifiers) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127802: [HLSL] Support HLSL vector initializers

2022-06-15 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/test/SemaHLSL/BuiltIns/vector-constructors-erros.hlsl:8
+void entry() {
+  float2 LilVec = float2(1.0, 2.0);
+  float2 BrokenVec = float2(1.0, 2.0, 3.0); // expected-error{{excess elements 
in vector initializer}}

python3kgae wrote:
> Could we have test case for array/struct when initialize vector?
> Like
> float a[2] = {1.2, 3.2};
> float4 arrayVec = float4(a, 1.0, 2.0);
This change does not support all of HLSL's odd initialization features. It only 
supports initializing vectors from scalars and vectors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127802

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


[PATCH] D127812: [AArch64] Function multiversioning support added.

2022-06-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I'm concerned as to the design of this addition, I don't particularly 
appreciate the reasons for making 'target_clones' different, nor the purpose 
for adding a new attribute instead of using 'target' for what seems like 
exactly that?  IF the new spelling is THAT necessary, we perhaps don't need a 
whole new attribute for it either.




Comment at: clang/include/clang/AST/ASTContext.h:3090
 
+  std::vector
+  filterFunctionTargetVersionAttrs(const TargetVersionAttr *TV) const;

It is concerning that this differs from the above.  



Comment at: clang/include/clang/AST/Decl.h:1860
+  TargetClones,
+  TargetVersion
 };

I find myself immediately wondering why this isn't just 'Target'.  What 
semantically are we trying to change?



Comment at: clang/include/clang/Basic/Attr.td:2738
+  let AdditionalMembers = [{
+StringRef getTVName() const { return getNamesStr().trim(); }
+bool isDefaultVersion() const {

would probably just call this getName ?



Comment at: clang/include/clang/Basic/AttrDocs.td:2351
 
+def TargetVersionDocs : Documentation {
+  let Category = DocCatFunction;

This sounds absurdly like 'target', and I think we should instead investigate 
why enabling THAT for ARM isn't sufficient.



Comment at: clang/include/clang/Basic/AttrDocs.td:2374
 
+For AArch64 target:
+The attribute contains comma-separated strings of target features joined by "+"

This seems like an unnecessary change, we should do what we can to make this 
work as much like the non-ARM version as possible.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11483
+def warn_target_clone_no_impact_options
+: Warning<"version list contains no code impact entries">,
+  InGroup;

I'm not clear as to what this means?



Comment at: clang/include/clang/Sema/Sema.h:4471
+  bool
+  checkTargetClonesAttrString(SourceLocation LiteralLoc, StringRef Str,
+  const StringLiteral *Literal, bool &HasDefault,

This further concerns me that we're changing behavior this much... 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D127838: [analyzer][NFC] Remove dead field of UnixAPICheckers

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

Ok. LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127838

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


[PATCH] D127836: [analyzer][NFC] Remove dead code and modernize surroundings

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127836

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


[PATCH] D127638: [clang][sema] Provide better diagnostic for missing template parameters

2022-06-15 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc149fa1f5fda: [clang][sema] Provide better diagnostic for 
missing template arguments (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D127638?vs=436690&id=437145#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127638

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/test/SemaCXX/nested-name-spec.cpp


Index: clang/test/SemaCXX/nested-name-spec.cpp
===
--- clang/test/SemaCXX/nested-name-spec.cpp
+++ clang/test/SemaCXX/nested-name-spec.cpp
@@ -473,3 +473,10 @@
 x: goto x;
   }
 }
+
+template 
+struct x; // expected-note {{template is declared here}}
+
+template 
+int issue55962 = x::a; // expected-error {{use of class template 'x' requires 
template arguments}} \
+   // expected-warning {{variable templates are a C++14 
extension}}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -828,10 +828,14 @@
   }
 
   if (!Found.empty()) {
-if (TypeDecl *TD = Found.getAsSingle())
+if (TypeDecl *TD = Found.getAsSingle()) {
   Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
   << Context.getTypeDeclType(TD) << getLangOpts().CPlusPlus;
-else {
+} else if (Found.getAsSingle()) {
+  ParsedType SuggestedType;
+  DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
+  SuggestedType);
+} else {
   Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
   << IdInfo.Identifier << getLangOpts().CPlusPlus;
   if (NamedDecl *ND = Found.getAsSingle())
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -264,7 +264,9 @@
 - ``-Wshift-overflow`` will not warn for signed left shifts in C++20 mode
   (and newer), as it will always wrap and never overflow. This fixes
   `Issue 52873 `_.
-
+- When using class templates without arguments, clang now tells developers
+  that template arguments are missing in certain contexts.
+  This fixes `Issue 55962 
`_.
 
 Non-comprehensive list of changes in this release
 -


Index: clang/test/SemaCXX/nested-name-spec.cpp
===
--- clang/test/SemaCXX/nested-name-spec.cpp
+++ clang/test/SemaCXX/nested-name-spec.cpp
@@ -473,3 +473,10 @@
 x: goto x;
   }
 }
+
+template 
+struct x; // expected-note {{template is declared here}}
+
+template 
+int issue55962 = x::a; // expected-error {{use of class template 'x' requires template arguments}} \
+   // expected-warning {{variable templates are a C++14 extension}}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -828,10 +828,14 @@
   }
 
   if (!Found.empty()) {
-if (TypeDecl *TD = Found.getAsSingle())
+if (TypeDecl *TD = Found.getAsSingle()) {
   Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
   << Context.getTypeDeclType(TD) << getLangOpts().CPlusPlus;
-else {
+} else if (Found.getAsSingle()) {
+  ParsedType SuggestedType;
+  DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
+  SuggestedType);
+} else {
   Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
   << IdInfo.Identifier << getLangOpts().CPlusPlus;
   if (NamedDecl *ND = Found.getAsSingle())
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -264,7 +264,9 @@
 - ``-Wshift-overflow`` will not warn for signed left shifts in C++20 mode
   (and newer), as it will always wrap and never overflow. This fixes
   `Issue 52873 `_.
-
+- When using class templates without arguments, clang now tells developers
+  that template arguments are missing in certain contexts.
+  This fixes `Issue 55962 `_.
 
 Non-comprehensive list of changes in this release
 -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.

[clang] bce55d0 - [clang][NFC] Remove unused parameter from ActOnCXXNestedNameSpecifier

2022-06-15 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-06-15T16:06:06+02:00
New Revision: bce55d06904c2b121e8eb94c340f16a6bb020860

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

LOG: [clang][NFC] Remove unused parameter from ActOnCXXNestedNameSpecifier

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaCXXScopeSpec.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8c2a56ab282b..8a604f6c2a9f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6746,7 +6746,6 @@ class Sema final {
NestedNameSpecInfo &IdInfo,
bool EnteringContext,
CXXScopeSpec &SS,
-   bool ErrorRecoveryLookup = false,
bool *IsCorrectedToColon = nullptr,
bool OnlyNamespace = false);
 

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index c2dc71f5f875..9bd89eddb455 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -453,8 +453,8 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
   bool IsCorrectedToColon = false;
   bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon : nullptr;
   if (Actions.ActOnCXXNestedNameSpecifier(
-  getCurScope(), IdInfo, EnteringContext, SS, false,
-  CorrectionFlagPtr, OnlyNamespace)) {
+  getCurScope(), IdInfo, EnteringContext, SS, CorrectionFlagPtr,
+  OnlyNamespace)) {
 // Identifier is not recognized as a nested name, but we can have
 // mistyped '::' instead of ':'.
 if (CorrectionFlagPtr && IsCorrectedToColon) {

diff  --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 4781d71080c9..7d19a6a50dac 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -850,7 +850,6 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, 
NestedNameSpecInfo &IdInfo,
 
 bool Sema::ActOnCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo,
bool EnteringContext, CXXScopeSpec &SS,
-   bool ErrorRecoveryLookup,
bool *IsCorrectedToColon,
bool OnlyNamespace) {
   if (SS.isInvalid())



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


[clang] c149fa1 - [clang][sema] Provide better diagnostic for missing template arguments

2022-06-15 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-06-15T16:06:06+02:00
New Revision: c149fa1f5fdaf62aa1db4bc52d72a34f0a92dd4f

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

LOG: [clang][sema] Provide better diagnostic for missing template arguments

Instead of just complaining that "x is not a class, namespace or
enumeration", mention that using x requires template arguments.

Differential Revision: https://reviews.llvm.org/D127638

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/test/SemaCXX/nested-name-spec.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 19ce6cb4d0d45..2f17fbf406285 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -264,7 +264,9 @@ Improvements to Clang's diagnostics
 - ``-Wshift-overflow`` will not warn for signed left shifts in C++20 mode
   (and newer), as it will always wrap and never overflow. This fixes
   `Issue 52873 `_.
-
+- When using class templates without arguments, clang now tells developers
+  that template arguments are missing in certain contexts.
+  This fixes `Issue 55962 
`_.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 7d19a6a50dacb..97783ebd6b530 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -828,10 +828,14 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, 
NestedNameSpecInfo &IdInfo,
   }
 
   if (!Found.empty()) {
-if (TypeDecl *TD = Found.getAsSingle())
+if (TypeDecl *TD = Found.getAsSingle()) {
   Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
   << Context.getTypeDeclType(TD) << getLangOpts().CPlusPlus;
-else {
+} else if (Found.getAsSingle()) {
+  ParsedType SuggestedType;
+  DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
+  SuggestedType);
+} else {
   Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
   << IdInfo.Identifier << getLangOpts().CPlusPlus;
   if (NamedDecl *ND = Found.getAsSingle())

diff  --git a/clang/test/SemaCXX/nested-name-spec.cpp 
b/clang/test/SemaCXX/nested-name-spec.cpp
index 403bf1c0d4aa8..081ee25e7cdba 100644
--- a/clang/test/SemaCXX/nested-name-spec.cpp
+++ b/clang/test/SemaCXX/nested-name-spec.cpp
@@ -473,3 +473,10 @@ namespace DependentTemplateInTrivialNNSLoc {
 x: goto x;
   }
 }
+
+template 
+struct x; // expected-note {{template is declared here}}
+
+template 
+int issue55962 = x::a; // expected-error {{use of class template 'x' requires 
template arguments}} \
+   // expected-warning {{variable templates are a C++14 
extension}}



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


[PATCH] D127748: Adds a warning for aligned new in MSVC before C++17

2022-06-15 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google abandoned this revision.
luken-google added a comment.

Probably better to address this in the Driver. See also 
https://reviews.llvm.org/D127641. I'm going to close this for now and see if we 
want to revisit after that lands or as part of that change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127748

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


[clang] f7a38ee - [analyzer][NFC][test] Add new RUN line with support-symbolic-integer-casts=true to expr-inspection.cpp

2022-06-15 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-06-15T16:06:53+02:00
New Revision: f7a38eeccb03a8076e298fd6c0baed7d171f07b6

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

LOG: [analyzer][NFC][test] Add new RUN line with 
support-symbolic-integer-casts=true to expr-inspection.cpp

Added a new run line to bolster gradual transition of handling cast operations,
see 
https://discourse.llvm.org/t/roadmap-of-modeling-symbolic-cast-operations/63107

Differential Revision: https://reviews.llvm.org/D127649

Added: 


Modified: 
clang/test/Analysis/expr-inspection.cpp

Removed: 




diff  --git a/clang/test/Analysis/expr-inspection.cpp 
b/clang/test/Analysis/expr-inspection.cpp
index 3e6530503292..94db6e38b841 100644
--- a/clang/test/Analysis/expr-inspection.cpp
+++ b/clang/test/Analysis/expr-inspection.cpp
@@ -1,9 +1,17 @@
-// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection 
-verify %s
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN:-analyzer-config support-symbolic-integer-casts=false \
+// RUN:-verify %s
+
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN:-analyzer-config support-symbolic-integer-casts=true \
+// RUN:-verify %s
 
 // Self-tests for the debug.ExprInspection checker.
 
-void clang_analyzer_denote(int x, const char *str);
-void clang_analyzer_express(int x);
+template 
+void clang_analyzer_denote(T x, const char *str);
+template 
+void clang_analyzer_express(T x);
 
 // Invalid declarations to test basic correctness checks.
 void clang_analyzer_denote();



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


[PATCH] D127649: [analyzer][NFC][test] Add new RUN line with support-symbolic-integer-casts=true to expr-inspection.cpp

2022-06-15 Thread Gabor Marton via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf7a38eeccb03: [analyzer][NFC][test] Add new RUN line with 
support-symbolic-integer-casts=true… (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127649

Files:
  clang/test/Analysis/expr-inspection.cpp


Index: clang/test/Analysis/expr-inspection.cpp
===
--- clang/test/Analysis/expr-inspection.cpp
+++ clang/test/Analysis/expr-inspection.cpp
@@ -1,9 +1,17 @@
-// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection 
-verify %s
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN:-analyzer-config support-symbolic-integer-casts=false \
+// RUN:-verify %s
+
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN:-analyzer-config support-symbolic-integer-casts=true \
+// RUN:-verify %s
 
 // Self-tests for the debug.ExprInspection checker.
 
-void clang_analyzer_denote(int x, const char *str);
-void clang_analyzer_express(int x);
+template 
+void clang_analyzer_denote(T x, const char *str);
+template 
+void clang_analyzer_express(T x);
 
 // Invalid declarations to test basic correctness checks.
 void clang_analyzer_denote();


Index: clang/test/Analysis/expr-inspection.cpp
===
--- clang/test/Analysis/expr-inspection.cpp
+++ clang/test/Analysis/expr-inspection.cpp
@@ -1,9 +1,17 @@
-// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN:-analyzer-config support-symbolic-integer-casts=false \
+// RUN:-verify %s
+
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN:-analyzer-config support-symbolic-integer-casts=true \
+// RUN:-verify %s
 
 // Self-tests for the debug.ExprInspection checker.
 
-void clang_analyzer_denote(int x, const char *str);
-void clang_analyzer_express(int x);
+template 
+void clang_analyzer_denote(T x, const char *str);
+template 
+void clang_analyzer_express(T x);
 
 // Invalid declarations to test basic correctness checks.
 void clang_analyzer_denote();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127832: [clangd] Always desugar type aliases in hover

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 437148.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- Leave the Ctx refactoring out of the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127832

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3206,6 +3206,30 @@
   ASSERT_TRUE(H);
   EXPECT_EQ(H->Definition, "int arr[]");
 }
+
+TEST(Hover, Typedefs) {
+  Annotations T(R"cpp(
+  template 
+  struct cond { using type = T; };
+  template 
+  struct cond { using type = F; };
+
+  template 
+  using type = typename cond::type;
+
+  void foo() {
+using f^oo = type;
+  }
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+
+  ASSERT_TRUE(H && H->Type);
+  EXPECT_EQ(H->Type->Type, "int");
+  EXPECT_EQ(H->Definition, "using foo = type");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -623,7 +623,8 @@
 HI.Type =
 printType(VT->getTemplatedDecl()->getType(), VT->getASTContext(), PP);
   else if (const auto *TN = dyn_cast(D))
-HI.Type = printType(TN->getUnderlyingType(), TN->getASTContext(), PP);
+HI.Type = printType(TN->getUnderlyingType().getDesugaredType(Ctx),
+TN->getASTContext(), PP);
   else if (const auto *TAT = dyn_cast(D))
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(),
 TAT->getASTContext(), PP);


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3206,6 +3206,30 @@
   ASSERT_TRUE(H);
   EXPECT_EQ(H->Definition, "int arr[]");
 }
+
+TEST(Hover, Typedefs) {
+  Annotations T(R"cpp(
+  template 
+  struct cond { using type = T; };
+  template 
+  struct cond { using type = F; };
+
+  template 
+  using type = typename cond::type;
+
+  void foo() {
+using f^oo = type;
+  }
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+
+  ASSERT_TRUE(H && H->Type);
+  EXPECT_EQ(H->Type->Type, "int");
+  EXPECT_EQ(H->Definition, "using foo = type");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -623,7 +623,8 @@
 HI.Type =
 printType(VT->getTemplatedDecl()->getType(), VT->getASTContext(), PP);
   else if (const auto *TN = dyn_cast(D))
-HI.Type = printType(TN->getUnderlyingType(), TN->getASTContext(), PP);
+HI.Type = printType(TN->getUnderlyingType().getDesugaredType(Ctx),
+TN->getASTContext(), PP);
   else if (const auto *TAT = dyn_cast(D))
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(),
 TAT->getASTContext(), PP);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8f2ba36 - Revert "[ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records AND [NFC][Thumb] Update frame-chain codegen test to use thumbv6m"

2022-06-15 Thread Krasimir Georgiev via cfe-commits

Author: Krasimir Georgiev
Date: 2022-06-15T16:10:02+02:00
New Revision: 8f2ba3633646d0c67a1442c6508d02d93571b344

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

LOG: Revert "[ARM][Thumb] Command-line option to ensure AAPCS compliant Frame 
Records AND [NFC][Thumb] Update frame-chain codegen test to use thumbv6m"

This reverts commit 7625e01d661644a560884057755d48a0da8b77b4 and
dependent cbcce82ef6b512d97e92a319a75a03e997c844e1.

Commit 7625e01d661644a560884057755d48a0da8b77b4 causes some new codegen test
failures under asan, e.g., CodeGen/ARM/execute-only.ll:
https://lab.llvm.org/buildbot/#/builders/5/builds/24659/steps/15/logs/stdio.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Arch/ARM.cpp
llvm/lib/Target/ARM/ARM.td
llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp
llvm/lib/Target/ARM/ARMCallingConv.td
llvm/lib/Target/ARM/ARMFrameLowering.cpp
llvm/lib/Target/ARM/ARMFrameLowering.h
llvm/lib/Target/ARM/ARMMachineFunctionInfo.h
llvm/lib/Target/ARM/ARMSubtarget.h
llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
llvm/lib/Target/ARM/ThumbRegisterInfo.cpp
llvm/test/CodeGen/Thumb/frame-access.ll

Removed: 
llvm/test/CodeGen/ARM/frame-chain-reserved-fp.ll
llvm/test/CodeGen/ARM/frame-chain.ll
llvm/test/CodeGen/Thumb/frame-chain-reserved-fp.ll
llvm/test/CodeGen/Thumb/frame-chain.ll



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b40cb1167388e..5fa681f538194 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3478,9 +3478,7 @@ defm aapcs_bitfield_width : BoolOption<"f", 
"aapcs-bitfield-width",
   BothFlags<[NoXarchOption, CC1Option], " the AAPCS standard requirement 
stating that"
 " volatile bit-field width is dictated by the field container 
type. (ARM only).">>,
   Group;
-def mframe_chain : Joined<["-"], "mframe-chain=">,
-  Group, Values<"none,aapcs,aapcs+leaf">,
-  HelpText<"Select the frame chain model used to emit frame records (Arm 
only).">;
+
 def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, Group,
   HelpText<"Generate code which only uses the general purpose registers 
(AArch64/x86 only)">;
 def mfix_cmse_cve_2021_35465 : Flag<["-"], "mfix-cmse-cve-2021-35465">,

diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index b79d1f00ea48b..dc6b35e39cfdd 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -718,15 +718,6 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
 }
   }
 
-  // Propagate frame-chain model selection
-  if (Arg *A = Args.getLastArg(options::OPT_mframe_chain)) {
-StringRef FrameChainOption = A->getValue();
-if (FrameChainOption.startswith("aapcs"))
-  Features.push_back("+aapcs-frame-chain");
-if (FrameChainOption == "aapcs+leaf")
-  Features.push_back("+aapcs-frame-chain-leaf");
-  }
-
   // CMSE: Check for target 8M (for -mcmse to be applicable) is performed 
later.
   if (Args.getLastArg(options::OPT_mcmse))
 Features.push_back("+8msecext");

diff  --git a/llvm/lib/Target/ARM/ARM.td b/llvm/lib/Target/ARM/ARM.td
index 48559a89a30a0..e8970b916a5f0 100644
--- a/llvm/lib/Target/ARM/ARM.td
+++ b/llvm/lib/Target/ARM/ARM.td
@@ -546,16 +546,6 @@ def FeatureFixCortexA57AES1742098 : 
SubtargetFeature<"fix-cortex-a57-aes-1742098
   "FixCortexA57AES1742098", "true",
   "Work around Cortex-A57 Erratum 1742098 / Cortex-A72 Erratum 1655431 (AES)">;
 
-def FeatureAAPCSFrameChain : SubtargetFeature<"aapcs-frame-chain",
-  "CreateAAPCSFrameChain", "true",
-  "Create an AAPCS compliant frame 
chain">;
-
-def FeatureAAPCSFrameChainLeaf : SubtargetFeature<"aapcs-frame-chain-leaf",
-  "CreateAAPCSFrameChainLeaf", 
"true",
-  "Create an AAPCS compliant 
frame chain "
-  "for leaf functions",
-  [FeatureAAPCSFrameChain]>;
-
 
//===--===//
 // ARM architecture class
 //

diff  --git a/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp 
b/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp
index 1d0e743b94dbf..cae72e465c7bf 100644
--- a/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp
@@ -63,8 +63,12 @@ const MCPhysReg*
 ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
   const ARMSubtarget &STI = MF->getSubtarget();
   b

[clang-tools-extra] 7212977 - [clangd] Always desugar type aliases in hover

2022-06-15 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-06-15T16:10:49+02:00
New Revision: 7212977fbb41bcffaf28a33a70c2df2b40492524

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

LOG: [clangd] Always desugar type aliases in hover

The alias itself is already included in the definition section of the
hover (it's printed as spelled in source code). So it doesn't provide any value
when we print the aliases as-is.
Fixes https://github.com/clangd/clangd/issues/1134.

Differential Revision: https://reviews.llvm.org/D127832

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index fcf3af756184..07552c5869fa 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -623,7 +623,8 @@ HoverInfo getHoverContents(const NamedDecl *D, const 
PrintingPolicy &PP,
 HI.Type =
 printType(VT->getTemplatedDecl()->getType(), VT->getASTContext(), PP);
   else if (const auto *TN = dyn_cast(D))
-HI.Type = printType(TN->getUnderlyingType(), TN->getASTContext(), PP);
+HI.Type = printType(TN->getUnderlyingType().getDesugaredType(Ctx),
+TN->getASTContext(), PP);
   else if (const auto *TAT = dyn_cast(D))
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(),
 TAT->getASTContext(), PP);

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 25ce19b2c580..0f149b724296 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3206,6 +3206,30 @@ TEST(Hover, HideBigInitializers) {
   ASSERT_TRUE(H);
   EXPECT_EQ(H->Definition, "int arr[]");
 }
+
+TEST(Hover, Typedefs) {
+  Annotations T(R"cpp(
+  template 
+  struct cond { using type = T; };
+  template 
+  struct cond { using type = F; };
+
+  template 
+  using type = typename cond::type;
+
+  void foo() {
+using f^oo = type;
+  }
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+
+  ASSERT_TRUE(H && H->Type);
+  EXPECT_EQ(H->Type->Type, "int");
+  EXPECT_EQ(H->Definition, "using foo = type");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang



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


[clang-tools-extra] 0473530 - [clangd][NFC] Use the existing ASTContext from scope

2022-06-15 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-06-15T16:10:49+02:00
New Revision: 04735302814e4df1cf37caeff3406fa5523901eb

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

LOG: [clangd][NFC] Use the existing ASTContext from scope

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 07552c5869fa..26eb2574195d 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -578,7 +578,7 @@ HoverInfo getHoverContents(const NamedDecl *D, const 
PrintingPolicy &PP,
const SymbolIndex *Index,
const syntax::TokenBuffer &TB) {
   HoverInfo HI;
-  const ASTContext &Ctx = D->getASTContext();
+  auto &Ctx = D->getASTContext();
 
   HI.AccessSpecifier = getAccessSpelling(D->getAccess()).str();
   HI.NamespaceScope = getNamespaceScope(D);
@@ -614,20 +614,17 @@ HoverInfo getHoverContents(const NamedDecl *D, const 
PrintingPolicy &PP,
   if (const FunctionDecl *FD = getUnderlyingFunction(D))
 fillFunctionTypeAndParams(HI, D, FD, PP);
   else if (const auto *VD = dyn_cast(D))
-HI.Type = printType(VD->getType(), VD->getASTContext(), PP);
+HI.Type = printType(VD->getType(), Ctx, PP);
   else if (const auto *TTP = dyn_cast(D))
 HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
   else if (const auto *TTP = dyn_cast(D))
 HI.Type = printType(TTP, PP);
   else if (const auto *VT = dyn_cast(D))
-HI.Type =
-printType(VT->getTemplatedDecl()->getType(), VT->getASTContext(), PP);
+HI.Type = printType(VT->getTemplatedDecl()->getType(), Ctx, PP);
   else if (const auto *TN = dyn_cast(D))
-HI.Type = printType(TN->getUnderlyingType().getDesugaredType(Ctx),
-TN->getASTContext(), PP);
+HI.Type = printType(TN->getUnderlyingType().getDesugaredType(Ctx), Ctx, 
PP);
   else if (const auto *TAT = dyn_cast(D))
-HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(),
-TAT->getASTContext(), PP);
+HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
 
   // Fill in value with evaluated initializer if possible.
   if (const auto *Var = dyn_cast(D)) {



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


[PATCH] D127832: [clangd] Always desugar type aliases in hover

2022-06-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7212977fbb41: [clangd] Always desugar type aliases in hover 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127832

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3206,6 +3206,30 @@
   ASSERT_TRUE(H);
   EXPECT_EQ(H->Definition, "int arr[]");
 }
+
+TEST(Hover, Typedefs) {
+  Annotations T(R"cpp(
+  template 
+  struct cond { using type = T; };
+  template 
+  struct cond { using type = F; };
+
+  template 
+  using type = typename cond::type;
+
+  void foo() {
+using f^oo = type;
+  }
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+
+  ASSERT_TRUE(H && H->Type);
+  EXPECT_EQ(H->Type->Type, "int");
+  EXPECT_EQ(H->Definition, "using foo = type");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -623,7 +623,8 @@
 HI.Type =
 printType(VT->getTemplatedDecl()->getType(), VT->getASTContext(), PP);
   else if (const auto *TN = dyn_cast(D))
-HI.Type = printType(TN->getUnderlyingType(), TN->getASTContext(), PP);
+HI.Type = printType(TN->getUnderlyingType().getDesugaredType(Ctx),
+TN->getASTContext(), PP);
   else if (const auto *TAT = dyn_cast(D))
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(),
 TAT->getASTContext(), PP);


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3206,6 +3206,30 @@
   ASSERT_TRUE(H);
   EXPECT_EQ(H->Definition, "int arr[]");
 }
+
+TEST(Hover, Typedefs) {
+  Annotations T(R"cpp(
+  template 
+  struct cond { using type = T; };
+  template 
+  struct cond { using type = F; };
+
+  template 
+  using type = typename cond::type;
+
+  void foo() {
+using f^oo = type;
+  }
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+
+  ASSERT_TRUE(H && H->Type);
+  EXPECT_EQ(H->Type->Type, "int");
+  EXPECT_EQ(H->Definition, "using foo = type");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -623,7 +623,8 @@
 HI.Type =
 printType(VT->getTemplatedDecl()->getType(), VT->getASTContext(), PP);
   else if (const auto *TN = dyn_cast(D))
-HI.Type = printType(TN->getUnderlyingType(), TN->getASTContext(), PP);
+HI.Type = printType(TN->getUnderlyingType().getDesugaredType(Ctx),
+TN->getASTContext(), PP);
   else if (const auto *TAT = dyn_cast(D))
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(),
 TAT->getASTContext(), PP);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125723: [MSVC] Add initial support for MSVC pragma optimize

2022-06-15 Thread Stephen Long via Phabricator via cfe-commits
steplong updated this revision to Diff 437153.
steplong added a comment.

- Fix docs
- Clean up code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125723

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/pragma-msvc-optimize.c
  clang/test/Preprocessor/pragma_microsoft.c

Index: clang/test/Preprocessor/pragma_microsoft.c
===
--- clang/test/Preprocessor/pragma_microsoft.c
+++ clang/test/Preprocessor/pragma_microsoft.c
@@ -228,7 +228,13 @@
 #pragma optimize("g"  // expected-warning{{expected ',' in '#pragma optimize'}}
 #pragma optimize("g", // expected-warning{{missing argument to '#pragma optimize'; expected 'on' or 'off'}}
 #pragma optimize("g",xyz  // expected-warning{{unexpected argument 'xyz' to '#pragma optimize'; expected 'on' or 'off'}}
-#pragma optimize("g",on)  // expected-warning{{#pragma optimize' is not supported}}
+#pragma optimize("g",on)  // expected-warning{{unexpected argument 'g' to '#pragma optimize'; expected ""}}
+#pragma optimize("",on)  // no-warning
+#pragma optimize("", on) asdf // expected-warning{{extra tokens at end of '#pragma optimize'}}
+
+void pragma_optimize_foo() {
+#pragma optimize("", on) // expected-error {{'#pragma optimize' can only appear at file scope}}
+}
 
 #pragma execution_character_set // expected-warning {{expected '('}}
 #pragma execution_character_set(// expected-warning {{expected 'push' or 'pop'}}
Index: clang/test/CodeGen/pragma-msvc-optimize.c
===
--- /dev/null
+++ clang/test/CodeGen/pragma-msvc-optimize.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -O2 -emit-llvm -fms-extensions -o - %s | FileCheck %s
+
+#pragma optimize("", off)
+
+// CHECK: define{{.*}} void @f0(){{.*}} #[[OPTNONE:[0-9]+]]
+void f0() {}
+
+// CHECK: define{{.*}} void @f1(){{.*}} #[[OPTNONE]]
+void f1() {}
+
+#pragma optimize("", on)
+
+// CHECK: define{{.*}} void @f2(){{.*}} #[[NO_OPTNONE:[0-9]+]]
+void f2() {}
+
+// CHECK: define{{.*}} void @f3(){{.*}} #[[NO_OPTNONE]]
+void f3() {}
+
+// CHECK: attributes #[[OPTNONE]] = {{{.*}}optnone{{.*}}}
+// CHECK-NOT: attributes #[[NO_OPTNONE]] = {{{.*}}optnone{{.*}}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -10192,6 +10192,7 @@
 AddRangeBasedOptnone(NewFD);
 AddImplicitMSFunctionNoBuiltinAttr(NewFD);
 AddSectionMSAllocText(NewFD);
+ModifyFnAttributesMSPragmaOptimize(NewFD);
   }
 
   // If this is the first declaration of an extern C variable, update
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -1096,6 +1096,15 @@
 OptimizeOffPragmaLocation = PragmaLoc;
 }
 
+void Sema::ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn) {
+  if (!CurContext->getRedeclContext()->isFileContext()) {
+Diag(Loc, diag::err_pragma_expected_file_scope) << "optimize";
+return;
+  }
+
+  MSPragmaOptimizeIsOn = IsOn;
+}
+
 void Sema::ActOnPragmaMSFunction(
 SourceLocation Loc, const llvm::SmallVectorImpl &NoBuiltins) {
   if (!CurContext->getRedeclContext()->isFileContext()) {
@@ -1129,6 +1138,13 @@
   }
 }
 
+void Sema::ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD) {
+  // Don't modify the function attributes if it's "on". "on" resets the
+  // optimizations to the ones listed on the command line
+  if (!MSPragmaOptimizeIsOn)
+AddOptnoneAttributeIfNoConflicts(FD, FD->getBeginLoc());
+}
+
 void Sema::AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD,
 SourceLocation Loc) {
   // Don't add a conflicting attribute. No diagnostic is needed.
Index: clang/lib/Parse/ParsePragma.cpp
===
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -255,12 +255,6 @@
 Token &FirstToken) override;
 };
 
-struct PragmaMSOptimizeHandler : public PragmaHandler {
-  PragmaMSOptimizeHandler() : PragmaHandler("optimize") {}
-  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
-Token &FirstToken) override;
-};
-
 // "\#pragma fenv_access (on)".
 struct PragmaMSFenvAccessHandler : public PragmaHandler {
   PragmaMSFenvAccessHandler() : PragmaHandler("fenv_access") {}
@@ -449,12 +443,12 @@
 PP.AddPragmaHandler(MSFunction.get());
 MSAllocText = std::make_unique("alloc_text");
 PP.AddPragmaHandler(MSAllocText.get());
+MSOptimize = st

[clang] e180cc5 - [Driver][test] Make RISCV tests robust with PATH=

2022-06-15 Thread Shao-Ce SUN via cfe-commits

Author: Shao-Ce SUN
Date: 2022-06-15T22:25:22+08:00
New Revision: e180cc5ff1a133c533e68bb92024d2455d5e6978

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

LOG: [Driver][test] Make RISCV tests robust with PATH=

When `riscv64-unknown-linux-gnu-ld` is in the PATH, `clang -### -fuse-ld=ld 
--target=riscv64-unknown-linux-gnu` will use unknown-linux-gnu-ld first, which 
causes the error in the lit test.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D127589

Added: 


Modified: 
clang/test/Driver/riscv64-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/riscv64-toolchain.c 
b/clang/test/Driver/riscv64-toolchain.c
index ec3707412e2aa..78ce26c181284 100644
--- a/clang/test/Driver/riscv64-toolchain.c
+++ b/clang/test/Driver/riscv64-toolchain.c
@@ -15,7 +15,7 @@
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
 
-// RUN: %clang -### %s -fuse-ld= \
+// RUN: env "PATH=" %clang -### %s -fuse-ld= \
 // RUN:   --target=riscv64-unknown-elf --rtlib=platform \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
 // RUN:   --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 
-no-pie \
@@ -30,7 +30,7 @@
 // C-RV64-BAREMETAL-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc"
 // C-RV64-BAREMETAL-LP64: 
"{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
-// RUN: %clang -### %s -fuse-ld= \
+// RUN: env "PATH=" %clang -### %s -fuse-ld= \
 // RUN:   --target=riscv64-unknown-elf --rtlib=platform \
 // RUN:   --sysroot= \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 \
@@ -44,7 +44,7 @@
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "--start-group" "-lc" "-lgloss" 
"--end-group" "-lgcc"
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: 
"{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
-// RUN: %clangxx -### %s -fuse-ld= \
+// RUN: env "PATH=" %clangxx -### %s -fuse-ld= \
 // RUN:   --target=riscv64-unknown-elf -stdlib=libstdc++ --rtlib=platform \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
 // RUN:   --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 \
@@ -60,7 +60,7 @@
 // CXX-RV64-BAREMETAL-LP64: "-lstdc++" "--start-group" "-lc" "-lgloss" 
"--end-group" "-lgcc"
 // CXX-RV64-BAREMETAL-LP64: 
"{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
-// RUN: %clangxx -### %s -fuse-ld= \
+// RUN: env "PATH=" %clangxx -### %s -fuse-ld= \
 // RUN:   --target=riscv64-unknown-elf -stdlib=libstdc++ --rtlib=platform \
 // RUN:   --sysroot= \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 \
@@ -75,7 +75,7 @@
 // CXX-RV64-BAREMETAL-NOSYSROOT-LP64: "-lstdc++" "--start-group" "-lc" 
"-lgloss" "--end-group" "-lgcc"
 // CXX-RV64-BAREMETAL-NOSYSROOT-LP64: 
"{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
-// RUN: %clang -### %s -fuse-ld= -no-pie \
+// RUN: env "PATH=" %clang -### %s -fuse-ld= -no-pie \
 // RUN:   --target=riscv64-unknown-linux-gnu --rtlib=platform -mabi=lp64 \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
 // RUN:   --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
@@ -90,7 +90,7 @@
 // C-RV64-LINUX-MULTI-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/lib64/lp64"
 // C-RV64-LINUX-MULTI-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib64/lp64"
 
-// RUN: %clang -### %s -fuse-ld=ld -no-pie \
+// RUN: env "PATH=" %clang -### %s -fuse-ld=ld -no-pie \
 // RUN:   --target=riscv64-unknown-linux-gnu --rtlib=platform -march=rv64imafd 
\
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
 // RUN:   --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \



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


[PATCH] D127589: [Driver][test] Make RISCV tests robust with PATH=

2022-06-15 Thread Shao-Ce SUN via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe180cc5ff1a1: [Driver][test] Make RISCV tests robust with 
PATH= (authored by sunshaoce).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127589

Files:
  clang/test/Driver/riscv64-toolchain.c


Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -15,7 +15,7 @@
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
 
-// RUN: %clang -### %s -fuse-ld= \
+// RUN: env "PATH=" %clang -### %s -fuse-ld= \
 // RUN:   --target=riscv64-unknown-elf --rtlib=platform \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
 // RUN:   --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 
-no-pie \
@@ -30,7 +30,7 @@
 // C-RV64-BAREMETAL-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc"
 // C-RV64-BAREMETAL-LP64: 
"{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
-// RUN: %clang -### %s -fuse-ld= \
+// RUN: env "PATH=" %clang -### %s -fuse-ld= \
 // RUN:   --target=riscv64-unknown-elf --rtlib=platform \
 // RUN:   --sysroot= \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 \
@@ -44,7 +44,7 @@
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "--start-group" "-lc" "-lgloss" 
"--end-group" "-lgcc"
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: 
"{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
-// RUN: %clangxx -### %s -fuse-ld= \
+// RUN: env "PATH=" %clangxx -### %s -fuse-ld= \
 // RUN:   --target=riscv64-unknown-elf -stdlib=libstdc++ --rtlib=platform \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
 // RUN:   --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 \
@@ -60,7 +60,7 @@
 // CXX-RV64-BAREMETAL-LP64: "-lstdc++" "--start-group" "-lc" "-lgloss" 
"--end-group" "-lgcc"
 // CXX-RV64-BAREMETAL-LP64: 
"{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
-// RUN: %clangxx -### %s -fuse-ld= \
+// RUN: env "PATH=" %clangxx -### %s -fuse-ld= \
 // RUN:   --target=riscv64-unknown-elf -stdlib=libstdc++ --rtlib=platform \
 // RUN:   --sysroot= \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 \
@@ -75,7 +75,7 @@
 // CXX-RV64-BAREMETAL-NOSYSROOT-LP64: "-lstdc++" "--start-group" "-lc" 
"-lgloss" "--end-group" "-lgcc"
 // CXX-RV64-BAREMETAL-NOSYSROOT-LP64: 
"{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
-// RUN: %clang -### %s -fuse-ld= -no-pie \
+// RUN: env "PATH=" %clang -### %s -fuse-ld= -no-pie \
 // RUN:   --target=riscv64-unknown-linux-gnu --rtlib=platform -mabi=lp64 \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
 // RUN:   --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
@@ -90,7 +90,7 @@
 // C-RV64-LINUX-MULTI-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/lib64/lp64"
 // C-RV64-LINUX-MULTI-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib64/lp64"
 
-// RUN: %clang -### %s -fuse-ld=ld -no-pie \
+// RUN: env "PATH=" %clang -### %s -fuse-ld=ld -no-pie \
 // RUN:   --target=riscv64-unknown-linux-gnu --rtlib=platform -march=rv64imafd 
\
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
 // RUN:   --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \


Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -15,7 +15,7 @@
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
 
-// RUN: %clang -### %s -fuse-ld= \
+// RUN: env "PATH=" %clang -### %s -fuse-ld= \
 // RUN:   --target=riscv64-unknown-elf --rtlib=platform \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
 // RUN:   --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 -no-pie \
@@ -30,7 +30,7 @@
 // C-RV64-BAREMETAL-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc"
 // C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
-// RUN: %clang -### %s -fuse-ld= \
+// RUN: env "PATH=" %clang -### %s -fuse-ld= \
 // RUN:   --target=riscv64-unknown-elf --rtlib=platform \
 // RUN:   --sysroot= \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 \
@@ -44,7 +44,7 @@
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc"
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
-// RUN: 

[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-06-15 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 437160.
cor3ntin marked 17 inline comments as done.
cor3ntin added a comment.

Address more style issues found by Aaron


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/FixIt/fixit-unicode-named-escape-sequences.c
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Lexer/unicode.c
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c
  llvm/CMakeLists.txt
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/CMakeLists.txt
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D126540: PowerPC] Emit warning for incompatible vector types that are currently diagnosed with -fno-lax-vector-conversions

2022-06-15 Thread Maryam Moghadas via Phabricator via cfe-commits
maryammo updated this revision to Diff 437161.
maryammo added a comment.

Tune the logic to emit warning when at least one of the vectors is altivec one 
and overloading resolution is done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126540

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/Parser/cxx-altivec.cpp

Index: clang/test/Parser/cxx-altivec.cpp
===
--- clang/test/Parser/cxx-altivec.cpp
+++ clang/test/Parser/cxx-altivec.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec -fsyntax-only -verify=expected,novsx -std=c++11 %s
-// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -target-feature +vsx -fsyntax-only -verify=expected,nonaix -std=c++11 %s
-// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify=expected,novsx -std=c++11 %s
-// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +vsx -target-cpu pwr7 -fsyntax-only -verify=expected,nonaix -std=c++11 %s
-// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature -vsx -target-cpu pwr7 -fsyntax-only -verify=expected,novsx -std=c++11 %s
-// RUN: %clang_cc1 -triple=powerpc-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,aix -std=c++11 %s
-// RUN: %clang_cc1 -triple=powerpc64-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,aix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -Wno-deprecate-lax-vec-conv-all -target-feature +altivec -fsyntax-only -verify=expected,novsx -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -Wno-deprecate-lax-vec-conv-all -target-feature +altivec -target-feature +vsx -fsyntax-only -verify=expected,nonaix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -Wno-deprecate-lax-vec-conv-all -target-feature +altivec -fsyntax-only -verify=expected,novsx -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -Wno-deprecate-lax-vec-conv-all -target-feature +vsx -target-cpu pwr7 -fsyntax-only -verify=expected,nonaix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -Wno-deprecate-lax-vec-conv-all -target-feature -vsx -target-cpu pwr7 -fsyntax-only -verify=expected,novsx -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc-ibm-aix -Wno-deprecate-lax-vec-conv-all -target-feature +altivec -fsyntax-only -verify=expected,aix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64-ibm-aix -Wno-deprecate-lax-vec-conv-all -target-feature +altivec -fsyntax-only -verify=expected,aix -std=c++11 %s
 #include 
 
 __vector char vv_c;
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -1617,8 +1617,9 @@
 ///
 /// \param ICK Will be set to the vector conversion kind, if this is a vector
 /// conversion.
-static bool IsVectorConversion(Sema &S, QualType FromType,
-   QualType ToType, ImplicitConversionKind &ICK) {
+static bool IsVectorConversion(Sema &S, QualType FromType, QualType ToType,
+   ImplicitConversionKind &ICK, Expr *From,
+   bool InOverloadResolution) {
   // We need at least one of these types to be a vector type to have a vector
   // conversion.
   if (!ToType->isVectorType() && !FromType->isVectorType())
@@ -1660,6 +1661,13 @@
 if (S.Context.areCompatibleVectorTypes(FromType, ToType) ||
 (S.isLaxVectorConversion(FromType, ToType) &&
  !ToType->hasAttr(attr::ArmMveStrictPolymorphism))) {
+  if (S.isLaxVectorConversion(FromType, ToType) &&
+	  S.areAnyVectorTypesAltivec(FromType, ToType) &&
+  !S.areVectorTypesSameElmType(FromType, ToType) &&
+	  !InOverloadResolution) {
+S.Diag(From->getBeginLoc(), diag::warn_deprecated_lax_vec_conv_all)
+<< FromType << ToType;
+  }
   ICK = ICK_Vector_Conversion;
   return true;
 }
@@ -1908,7 +1916,8 @@
  InOverloadResolution, FromType)) {
 // Pointer to member conversions (4.11).
 SCS.Second = ICK_Pointer_Member;
-  } else if (IsVectorConversion(S, FromType, ToType, SecondICK)) {
+  } else if (IsVectorConversion(S, FromType, ToType, SecondICK, From,
+InOverloadResolution)) {
 SCS.Second = SecondICK;
 FromType = ToType.getUnqualifiedType();
   } else if (!S.getLangOpts().CPlusPlus &&
@@ -13014,6 +13023,7 @@
   // This shouldn't cause an infinite loop because we're giving it
   // an expression with viable lookup results, which should never
   // end up here.
+  //
   return SemaRef.BuildCallExpr(/*Scope*/ 

[PATCH] D127839: [analyzer] Fix StreamErrorState hash bug

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

This change introduces a single new report:
F23459650: image.png 

This makes me believe that this bug was not that important after all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127839

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


[PATCH] D127859: [clangd] Don't add inlay hints on std::move/forward

2022-06-15 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj created this revision.
upsj added a reviewer: nridge.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
upsj requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This removes parameter inlay hints from a few builtin functions like 
std::move/std::forward


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127859

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -555,6 +555,17 @@
ExpectedHint{"timeout_millis: ", "timeout_millis"});
 }
 
+TEST(ParameterHints, BuiltinFunctions) {
+  // This prototype of std::forward is sufficient for clang to recognize it
+  assertParameterHints(R"cpp(
+namespace std { template  T&& forward(T&); }
+void foo() {
+  int i;
+  std::forward(i);
+}
+  )cpp");
+}
+
 TEST(ParameterHints, IncludeAtNonGlobalScope) {
   Annotations FooInc(R"cpp(
 void bar() { foo(42); }
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -14,6 +14,7 @@
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/ScopeExit.h"
 
@@ -400,8 +401,9 @@
 NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
 
 // Exclude setters (i.e. functions with one argument whose name begins with
-// "set"), as their parameter name is also not likely to be interesting.
-if (isSetter(Callee, ParameterNames))
+// "set"), and builtins like std::move/forward/... as their parameter name
+// is also not likely to be interesting.
+if (isSetter(Callee, ParameterNames) || isSimpleBuiltin(Callee))
   return;
 
 for (size_t I = 0; I < ArgCount; ++I) {
@@ -440,6 +442,21 @@
 return WhatItIsSetting.equals_insensitive(ParamNames[0]);
   }
 
+  // Checks if the callee is one of the builtins
+  // addressof, as_const, forward, move(_if_noexcept)
+  static bool isSimpleBuiltin(const FunctionDecl *Callee) {
+switch (Callee->getBuiltinID()) {
+case Builtin::BIaddressof:
+case Builtin::BIas_const:
+case Builtin::BIforward:
+case Builtin::BImove:
+case Builtin::BImove_if_noexcept:
+  return true;
+default:
+  return false;
+}
+  }
+
   bool shouldHintName(const Expr *Arg, StringRef ParamName) {
 if (ParamName.empty())
   return false;


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -555,6 +555,17 @@
ExpectedHint{"timeout_millis: ", "timeout_millis"});
 }
 
+TEST(ParameterHints, BuiltinFunctions) {
+  // This prototype of std::forward is sufficient for clang to recognize it
+  assertParameterHints(R"cpp(
+namespace std { template  T&& forward(T&); }
+void foo() {
+  int i;
+  std::forward(i);
+}
+  )cpp");
+}
+
 TEST(ParameterHints, IncludeAtNonGlobalScope) {
   Annotations FooInc(R"cpp(
 void bar() { foo(42); }
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -14,6 +14,7 @@
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/ScopeExit.h"
 
@@ -400,8 +401,9 @@
 NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
 
 // Exclude setters (i.e. functions with one argument whose name begins with
-// "set"), as their parameter name is also not likely to be interesting.
-if (isSetter(Callee, ParameterNames))
+// "set"), and builtins like std::move/forward/... as their parameter name
+// is also not likely to be interesting.
+if (isSetter(Callee, ParameterNames) || isSimpleBuiltin(Callee))
   return;
 
 for (size_t I = 0; I < ArgCount; ++I) {
@@ -440,6 +442,21 @@
 return WhatItIsSetting.equals_insensitive(ParamNames[0]);
   }
 
+  // Checks if the callee is one of the builtins
+  // addressof, as_const, forward, move(_if_noexcept)
+  static bool isSimpleBuiltin(const FunctionDecl *Callee) {
+switch (Callee->getBuiltinID()) {
+case Builtin::BIaddressof:

[PATCH] D127807: [clang-tidy] Properly forward clang-tidy output when running tests

2022-06-15 Thread Nicolas van Kempen via Phabricator via cfe-commits
nicovank updated this revision to Diff 437163.
nicovank added a comment.

Looks like this causes the `misc-misleading-identifier` test to fail on the 
BuildKite Windows setup because it uses cp1252 and not utf-8. I think this is 
why the encode was added in the first place. This workaround should hopefully 
fix this, it will display unicode characters as '?' when stdout does not 
support utf-8.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127807

Files:
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -173,13 +173,13 @@
 print('Running ' + repr(args) + '...')
 clang_tidy_output = try_run(args)
 print(' clang-tidy output ---')
-print(clang_tidy_output.encode())
-
print('\n--')
+print(clang_tidy_output.encode(sys.stdout.encoding, 
errors="replace").decode(sys.stdout.encoding))
+print('--')
 
 diff_output = try_run(['diff', '-u', self.original_file_name, 
self.temp_file_name], False)
-print('-- Fixes 
-\n' +
-  diff_output +
-  
'\n--')
+print('-- Fixes -')
+print(diff_output)
+print('--')
 return clang_tidy_output
 
   def check_fixes(self):


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -173,13 +173,13 @@
 print('Running ' + repr(args) + '...')
 clang_tidy_output = try_run(args)
 print(' clang-tidy output ---')
-print(clang_tidy_output.encode())
-print('\n--')
+print(clang_tidy_output.encode(sys.stdout.encoding, errors="replace").decode(sys.stdout.encoding))
+print('--')
 
 diff_output = try_run(['diff', '-u', self.original_file_name, self.temp_file_name], False)
-print('-- Fixes -\n' +
-  diff_output +
-  '\n--')
+print('-- Fixes -')
+print(diff_output)
+print('--')
 return clang_tidy_output
 
   def check_fixes(self):
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127860: [msan] Allow KMSAN to use -fsanitize-memory-param-retval

2022-06-15 Thread Alexander Potapenko via Phabricator via cfe-commits
glider created this revision.
Herald added a project: All.
glider requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Let -fsanitize-memory-param-retval be used together with
-fsanitize=kernel-memory, so that it can be applied when building the
Linux kernel.

Also add clang/test/CodeGen/kmsan-param-retval.c to ensure that
-fsanitize-memory-param-retval eliminates shadow accesses for parameters
marked as undef.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127860

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/kmsan-param-retval.c
  clang/test/Driver/fsanitize-memory-param-retval.c


Index: clang/test/Driver/fsanitize-memory-param-retval.c
===
--- clang/test/Driver/fsanitize-memory-param-retval.c
+++ clang/test/Driver/fsanitize-memory-param-retval.c
@@ -3,6 +3,8 @@
 // RUN: %clang -target aarch64-linux-gnu %s -fsanitize=memory 
-fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
 // RUN: %clang -target riscv32-linux-gnu %s -fsanitize=memory 
-fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
 // RUN: %clang -target riscv64-linux-gnu %s -fsanitize=memory 
-fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
+// RUN: %clang -target x86_64-linux-gnu %s -fsanitize=kernel-memory 
-fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
+
 // CHECK: "-fsanitize-memory-param-retval"
 
 // RUN: %clang -target aarch64-linux-gnu -fsyntax-only %s -fsanitize=memory 
-fsanitize-memory-param-retval -c -### 2>&1 | FileCheck --check-prefix=11 %s
Index: clang/test/CodeGen/kmsan-param-retval.c
===
--- /dev/null
+++ clang/test/CodeGen/kmsan-param-retval.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -O2 
-fsanitize=kernel-memory -no-enable-noundef-analysis -o - %s | \
+// RUN: FileCheck %s --check-prefix=CLEAN
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -O2 
-fsanitize=kernel-memory -o - %s | \
+// RUN: FileCheck %s --check-prefixes=NOUNDEF,NOUNDEF_ONLY
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -O2 
-fsanitize=kernel-memory -mllvm -msan-eager-checks -o - %s | \
+// RUN: FileCheck %s --check-prefixes=NOUNDEF,EAGER
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -O2 
-fsanitize=kernel-memory -no-enable-noundef-analysis 
-fsanitize-memory-param-retval -o - %s | \
+// RUN: FileCheck %s --check-prefixes=CLEAN
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -O2 
-fsanitize=kernel-memory -fsanitize-memory-param-retval -o - %s | \
+// RUN: FileCheck %s --check-prefixes=NOUNDEF,EAGER
+
+void foo();
+
+void bar(int x) {
+  if (x)
+foo();
+}
+
+
+// CLEAN:   define dso_local void @bar(i32 %x)
+// NOUNDEF: define dso_local void @bar(i32 noundef %x)
+//
+// %param_shadow assignment gets optimized away with -O2, because it is at the 
beginning of the
+// struct returned by __msan_get_context_state(). Use %param_origin as a sign 
that the shadow of
+// the first argument is being used.
+//
+// Without noundef analysis, KMSAN emits metadata checks for the function 
parameter.
+// CLEAN:load i32, ptr %param_origin
+//
+// With noundef analysis enabled, but without eager checks, KMSAN still emits 
metadata checks,
+// although the parameter is known to be defined.
+// NOUNDEF_ONLY: load i32, ptr %param_origin
+//
+// With noundef analysis and eager checks enabled, KMSAN won't emit metadata 
checks for function
+// parameters.
+// EAGER-NOT:load i32, ptr %param_origin
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -646,6 +646,11 @@
 options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
+  } else if (AllAddedKinds & SanitizerKind::KernelMemory) {
+MsanUseAfterDtor = false;
+MsanParamRetval = Args.hasFlag(
+options::OPT_fsanitize_memory_param_retval,
+options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
   } else {
 MsanUseAfterDtor = false;
 MsanParamRetval = false;


Index: clang/test/Driver/fsanitize-memory-param-retval.c
===
--- clang/test/Driver/fsanitize-memory-param-retval.c
+++ clang/test/Driver/fsanitize-memory-param-retval.c
@@ -3,6 +3,8 @@
 // RUN: %clang -target aarch64-linux-gnu %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
 // RUN: %clang -target riscv32-linux-gnu %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
 // RUN: %clang -target riscv64-linux-gnu %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | Fi

[PATCH] D127306: [analyzer] Treat system globals as mutable if they are not const

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal marked an inline comment as done.
steakhal added a comment.

According to my measurements, this commit will change some reports, but nothing 
significant (<20) on our testset (except llvm which I did not include).
But more importantly, no taint reports disappeared nor were introduced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127306

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


[PATCH] D127579: [clang][WIP] add option to keep types of ptr args for non-kernel functions in metadata

2022-06-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

The patch seems very straight forward. I wonder though if we should always 
enable this for SPIR-V w/o  adding any flag until the untyped pointers are 
added to SPIR-V so it will become a target setting controlled instead of a flag?

Also is there anything that we don't need from the metadata that are currently 
emitted for the use case i.e. for example argument names? This could reduce the 
number of metadata emitted...

I am not sure if this is something that other languages or backends might also 
need in which case we might need to make this more universal... Ideally it 
would be nice if it was not in metadata as it is somewhat optional... but 
potentially we don't have many other alternatives?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127579

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


[PATCH] D127763: [analyzer] Relax constraints on const qualified regions

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

According to my measurements, this change has minor effects (1 new, 20 
disappeared reports).
The interesting reports had really long bug paths, so I think there were some 
default eval called functions down the line which made this patch surface this 
way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127763

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


[PATCH] D127579: [clang][WIP] add option to keep types of ptr args for non-kernel functions in metadata

2022-06-15 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

There are numerous changes floating around that boil down to "we need pointer 
types". Most are SPIR-V & DXIL related. I'm a little concerned that we are 
generally building a bunch of different approaches to tracking pointer types 
and not considering a more general solution that could meet all of the needs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127579

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


[clang] f1b18a7 - [analyzer][NFC] Remove dead code and modernize surroundings

2022-06-15 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2022-06-15T16:50:12+02:00
New Revision: f1b18a79b7f4c81ef67e83f5d1a02ded139df02d

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

LOG: [analyzer][NFC] Remove dead code and modernize surroundings

Thanks @kazu for helping me clean these parts in D127799.

I'm leaving the dump methods, along with the unused visitor handlers and
the forwarding methods.

The dead parts actually helped to uncover two bugs, to which I'm going
to post separate patches.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D127836

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
clang/lib/StaticAnalyzer/Checkers/Iterator.h
clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index b143ef93282f9..9dea945eb704e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -347,10 +347,6 @@ class CFNumberChecker : public Checker< 
check::PreStmt > {
   CFNumberChecker() : ICreate(nullptr), IGetValue(nullptr) {}
 
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
-
-private:
-  void EmitError(const TypedRegion* R, const Expr *Ex,
-uint64_t SourceSize, uint64_t TargetSize, uint64_t NumberKind);
 };
 } // end anonymous namespace
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
index 0245549e6a723..aaf8cca32b606 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
@@ -56,9 +56,6 @@ class DynamicTypePropagation:
 check::PreObjCMessage,
 check::PostObjCMessage > {
 
-  const ObjCObjectType *getObjectTypeForAllocAndNew(const ObjCMessageExpr 
*MsgE,
-CheckerContext &C) const;
-
   /// Return a better dynamic type if one can be derived from the cast.
   const ObjCObjectPointerType *getBetterObjCType(const Expr *CastE,
  CheckerContext &C) const;

diff  --git a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
index 6e4801aa8e91b..eb3b89ee6c5ca 100644
--- a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
@@ -254,9 +254,6 @@ static const ExplodedNode *getAcquireSite(const 
ExplodedNode *N, SymbolRef Sym,
 namespace {
 class FuchsiaHandleSymbolVisitor final : public SymbolVisitor {
 public:
-  FuchsiaHandleSymbolVisitor(ProgramStateRef State) : State(std::move(State)) 
{}
-  ProgramStateRef getState() const { return State; }
-
   bool VisitSymbol(SymbolRef S) override {
 if (const auto *HandleType = S->getType()->getAs())
   if (HandleType->getDecl()->getName() == HandleTypeName)
@@ -268,7 +265,6 @@ class FuchsiaHandleSymbolVisitor final : public 
SymbolVisitor {
 
 private:
   SmallVector Symbols;
-  ProgramStateRef State;
 };
 } // end anonymous namespace
 
@@ -284,7 +280,7 @@ getFuchsiaHandleSymbols(QualType QT, SVal Arg, 
ProgramStateRef State) {
   if (QT->isStructureType()) {
 // If we see a structure, see if there is any handle referenced by the
 // structure.
-FuchsiaHandleSymbolVisitor Visitor(State);
+FuchsiaHandleSymbolVisitor Visitor;
 State->scanReachableSymbols(Arg, Visitor);
 return Visitor.GetSymbols();
   }

diff  --git a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
index 7e237b471def5..23f08896d1e6f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -176,15 +176,6 @@ class ArgSet {
 
  

[PATCH] D127836: [analyzer][NFC] Remove dead code and modernize surroundings

2022-06-15 Thread Balázs Benics via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf1b18a79b7f4: [analyzer][NFC] Remove dead code and modernize 
surroundings (authored by steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127836

Files:
  clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.h
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -352,7 +352,6 @@
 
 private:
   void storeTopLevelDecls(DeclGroupRef DG);
-  std::string getFunctionName(const Decl *D);
 
   /// Check if we should skip (not analyze) the given function.
   AnalysisMode getModeForDecl(Decl *D, AnalysisMode Mode);
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -118,18 +118,10 @@
 /// the construction context was present and contained references to these
 /// AST nodes.
 class ConstructedObjectKey {
-  typedef std::pair
-  ConstructedObjectKeyImpl;
-
+  using ConstructedObjectKeyImpl =
+  std::pair;
   const ConstructedObjectKeyImpl Impl;
 
-  const void *getAnyASTNodePtr() const {
-if (const Stmt *S = getItem().getStmtOrNull())
-  return S;
-else
-  return getItem().getCXXCtorInitializer();
-  }
-
 public:
   explicit ConstructedObjectKey(const ConstructionContextItem &Item,
const LocationContext *LC)
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -527,11 +527,6 @@
 ID.AddPointer(RegionOfInterest);
   }
 
-  void *getTag() const {
-static int Tag = 0;
-return static_cast(&Tag);
-  }
-
 private:
   /// \return Whether \c RegionOfInterest was modified at \p CurrN compared to
   /// the value it holds in \p CallExitBeginN.
Index: clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
@@ -22,27 +22,15 @@
 using namespace taint;
 
 namespace {
-class TaintTesterChecker : public Checker< check::PostStmt > {
-
-  mutable std::unique_ptr BT;
-  void initBugType() const;
-
-  /// Given a pointer argument, get the symbol of the value it contains
-  /// (points to).
-  SymbolRef getPointedToSymbol(CheckerContext &C,
-   const Expr* Arg,
-   bool IssueWarning = true) const;
+class TaintTesterChecker : public Checker> {
+  std::unique_ptr BT =
+  std::make_unique(this, "Tainted data", "General");
 
 public:
   void checkPostStmt(const Expr *E, CheckerContext &C) const;
 };
 }
 
-inline void TaintTesterChecker::initBugType() const {
-  if (!BT)
-BT.reset(new BugType(this, "Tainted data", "General"));
-}
-
 void TaintTesterChecker::checkPostStmt(const Expr *E,
CheckerContext &C) const {
   ProgramStateRef State = C.getState();
@@ -51,7 +39,6 @@
 
   if (isTainted(State, E, C.getLocationContext())) {
 if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
-  initBugType();
   auto report = std::make_unique(*BT, "tainted", N);
   report->addRange(E->getSourceRange());
   C.emitReport(std::move(report));
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -50,7 +50,6 @@
   // Whether the checker should model for null dereferences of smart pointers.
   bool ModelSmartPtrDereference =

  1   2   3   >