[PATCH] D117090: Fix `readability-non-const-parameter` for parameter referenced by an lvalue

2022-01-12 Thread gehry via Phabricator via cfe-commits
Sockke created this revision.
Sockke added reviewers: danielmarjamaki, njames93, aaron.ballman, MTC.
Herald added a subscriber: carlosgalvezp.
Sockke requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The checker missed a check for a case when the parameter is referenced by an 
lvalue and this could cause build breakages.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117090

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
@@ -287,3 +287,39 @@
 }
 char foo(char *s); // 2
 // CHECK-FIXES: {{^}}char foo(const char *s); // 2{{$}}
+
+void lvalueReference(int *p) {
+  // CHECK-MESSAGES-NOT: warning:
+  int &x = *p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:32: warning: pointer parameter 'p' can be
+void constLValueReference(int *p) {
+  // CHECK-FIXES: {{^}}void constLValueReference(const int *p) {{{$}}
+  const int &x = *p;
+}
+
+void lambdaLVRef(int *p) {
+  // CHECK-MESSAGES-NOT: warning:
+  auto foo = [&]() {
+int &x = *p;
+  };
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:28: warning: pointer parameter 'p' can be
+void lambdaConstLVRef(int *p) {
+  // CHECK-FIXES: {{^}}void lambdaConstLVRef(const int *p) {{{$}}
+  auto foo = [&]() {
+const int &x = *p;
+  };
+}
+
+struct Temp1 {
+  Temp1(int &i) {
+i = 10;
+  }
+};
+void constructLVRef(int *p) {
+  // CHECK-MESSAGES-NOT: warning:
+  Temp1 t(*p);
+}
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -83,6 +83,20 @@
   for (const auto *Arg : CE->arguments()) {
 markCanNotBeConst(Arg->IgnoreParenCasts(), true);
   }
+  // Data passed by nonconst reference should not be made const.
+  unsigned ArgNr = 0U;
+  if (const auto *CD = CE->getConstructor()) {
+for (const auto *Par : CD->parameters()) {
+  if (ArgNr >= CE->getNumArgs())
+break;
+  const Expr *Arg = CE->getArg(ArgNr++);
+  // Is this a non constant reference parameter?
+  const Type *ParType = Par->getType().getTypePtr();
+  if (!ParType->isReferenceType() || Par->getType().isConstQualified())
+continue;
+  markCanNotBeConst(Arg->IgnoreParenCasts(), false);
+}
+  }
 } else if (const auto *R = dyn_cast(S)) {
   markCanNotBeConst(R->getRetValue(), true);
 } else if (const auto *U = dyn_cast(S)) {
@@ -93,6 +107,9 @@
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
 T->isArrayType())
   markCanNotBeConst(VD->getInit(), true);
+else if (T->isLValueReferenceType() &&
+ !T->getPointeeType().isConstQualified())
+  markCanNotBeConst(VD->getInit(), false);
   }
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
@@ -287,3 +287,39 @@
 }
 char foo(char *s); // 2
 // CHECK-FIXES: {{^}}char foo(const char *s); // 2{{$}}
+
+void lvalueReference(int *p) {
+  // CHECK-MESSAGES-NOT: warning:
+  int &x = *p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:32: warning: pointer parameter 'p' can be
+void constLValueReference(int *p) {
+  // CHECK-FIXES: {{^}}void constLValueReference(const int *p) {{{$}}
+  const int &x = *p;
+}
+
+void lambdaLVRef(int *p) {
+  // CHECK-MESSAGES-NOT: warning:
+  auto foo = [&]() {
+int &x = *p;
+  };
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:28: warning: pointer parameter 'p' can be
+void lambdaConstLVRef(int *p) {
+  // CHECK-FIXES: {{^}}void lambdaConstLVRef(const int *p) {{{$}}
+  auto foo = [&]() {
+const int &x = *p;
+  };
+}
+
+struct Temp1 {
+  Temp1(int &i) {
+i = 10;
+  }
+};
+void constructLVRef(int *p) {
+  // CHECK-MESSAGES-NOT: warning:
+  Temp1 t(*p);
+}
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -83,6 +83,20 @@
   for (const auto *Arg : CE->arguments()) {
 markCanNotBeConst(Arg->IgnoreParenCasts(), true);
   }
+  

[clang-tools-extra] c4db521 - [clang] Introduce support for disabling warnings in system macros

2022-01-12 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2022-01-12T08:18:19Z
New Revision: c4db521cea32fcfb714d1a622e0efce69a564a28

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

LOG: [clang] Introduce support for disabling warnings in system macros

Often we run into situations where we want to ignore
warnings from system headers, but Clang will still
give warnings about the contents of a macro defined
in a system header used in user-code.

Introduce a ShowInSystemMacro option to be able to
specify which warnings we do want to keep raising
warnings for. The current behavior is kept in this patch
(i.e. warnings from system macros are enabled by default).
The decision as to whether this should be an opt-in or opt-out
feature can be made in a separate patch.

To put the feature to test, replace duplicated code for
Wshadow and Wold-style-cast with the SuppressInSystemMacro tag.
Also disable the warning for C++20 designators, fixing #52944.

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

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang/include/clang/Basic/Diagnostic.td
clang/include/clang/Basic/DiagnosticAST.h
clang/include/clang/Basic/DiagnosticAnalysis.h
clang/include/clang/Basic/DiagnosticComment.h
clang/include/clang/Basic/DiagnosticCrossTU.h
clang/include/clang/Basic/DiagnosticDriver.h
clang/include/clang/Basic/DiagnosticFrontend.h
clang/include/clang/Basic/DiagnosticIDs.h
clang/include/clang/Basic/DiagnosticLex.h
clang/include/clang/Basic/DiagnosticParse.h
clang/include/clang/Basic/DiagnosticRefactoring.h
clang/include/clang/Basic/DiagnosticSema.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/DiagnosticSerialization.h
clang/lib/Basic/DiagnosticIDs.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/warn-sysheader-macro.cpp
clang/test/TableGen/DiagnosticBase.inc
clang/test/TableGen/deferred-diag.td
clang/tools/diagtool/DiagnosticNames.cpp
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 126f4c3e50add..f3482c14184ff 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -45,7 +45,7 @@ namespace {
 const char *getDiagnosticCode(unsigned ID) {
   switch (ID) {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROPU, SFINAE, NOWERROR,  
\
- SHOWINSYSHEADER, DEFERRABLE, CATEGORY)
\
+ SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY)
\
   case clang::diag::ENUM:  
\
 return #ENUM;
 #include "clang/Basic/DiagnosticASTKinds.inc"

diff  --git a/clang/include/clang/Basic/Diagnostic.td 
b/clang/include/clang/Basic/Diagnostic.td
index ab2c738a2acec..c932c90572786 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -84,6 +84,7 @@ class Diagnostic {
   bitAccessControl = 0;
   bitWarningNoWerror = 0;
   bitShowInSystemHeader = 0;
+  bitShowInSystemMacro = 1;
   bitDeferrable = 0;
   Severity   DefaultSeverity = defaultmapping;
   DiagGroup  Group;
@@ -108,6 +109,14 @@ class SuppressInSystemHeader {
   bit ShowInSystemHeader = 0;
 }
 
+class ShowInSystemMacro {
+  bit ShowInSystemMacro = 1;
+}
+
+class SuppressInSystemMacro {
+  bit ShowInSystemMacro = 0;
+}
+
 class Deferrable {
   bit Deferrable = 1;
 }
@@ -159,4 +168,3 @@ include "DiagnosticParseKinds.td"
 include "DiagnosticRefactoringKinds.td"
 include "DiagnosticSemaKinds.td"
 include "DiagnosticSerializationKinds.td"
-

diff  --git a/clang/include/clang/Basic/DiagnosticAST.h 
b/clang/include/clang/Basic/DiagnosticAST.h
index 76c31ad9508e7..24ef2689eac01 100644
--- a/clang/include/clang/Basic/DiagnosticAST.h
+++ b/clang/include/clang/Basic/DiagnosticAST.h
@@ -15,7 +15,7 @@ namespace clang {
 namespace diag {
 enum {
 #define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
- SHOWINSYSHEADER, DEFERRABLE, CATEGORY)
\
+ SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY)
\
   ENUM,
 #define ASTSTART
 #include "clang/Basic/DiagnosticASTKinds.inc"

diff  --git a/clang/include/clang/Basic/DiagnosticAnalysis.h 
b/clang/include/clang/Basic/DiagnosticAnalysis.h
index f9037cc8d75ab..676b58f7d6ef2 100644
--- a/clang/include/clang/Basic/DiagnosticAnalysis.h
+++ b/clang/include/clang/Basic/DiagnosticAnalysis.h
@@ -15,7 +15,7 @@ namespace clang {
 namespace diag {
 enum {
 #define DIAG(ENUM, FLAGS, DEFAULT

[PATCH] D116833: [clang] Introduce support for disabling warnings in system macros

2022-01-12 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4db521cea32: [clang] Introduce support for disabling 
warnings in system macros (authored by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116833

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang/include/clang/Basic/Diagnostic.td
  clang/include/clang/Basic/DiagnosticAST.h
  clang/include/clang/Basic/DiagnosticAnalysis.h
  clang/include/clang/Basic/DiagnosticComment.h
  clang/include/clang/Basic/DiagnosticCrossTU.h
  clang/include/clang/Basic/DiagnosticDriver.h
  clang/include/clang/Basic/DiagnosticFrontend.h
  clang/include/clang/Basic/DiagnosticIDs.h
  clang/include/clang/Basic/DiagnosticLex.h
  clang/include/clang/Basic/DiagnosticParse.h
  clang/include/clang/Basic/DiagnosticRefactoring.h
  clang/include/clang/Basic/DiagnosticSema.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/DiagnosticSerialization.h
  clang/lib/Basic/DiagnosticIDs.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/warn-sysheader-macro.cpp
  clang/test/TableGen/DiagnosticBase.inc
  clang/test/TableGen/deferred-diag.td
  clang/tools/diagtool/DiagnosticNames.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1311,6 +1311,11 @@
 else
   OS << ", false";
 
+if (R.getValueAsBit("ShowInSystemMacro"))
+  OS << ", true";
+else
+  OS << ", false";
+
 if (R.getValueAsBit("Deferrable"))
   OS << ", true";
 else
Index: clang/tools/diagtool/DiagnosticNames.cpp
===
--- clang/tools/diagtool/DiagnosticNames.cpp
+++ clang/tools/diagtool/DiagnosticNames.cpp
@@ -27,9 +27,9 @@
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
-#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,   \
- SFINAE,NOWERROR,SHOWINSYSHEADER,DEFER,CATEGORY)\
-  { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
+#define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  \
+ SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) \
+  {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
 #include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
Index: clang/test/TableGen/deferred-diag.td
===
--- clang/test/TableGen/deferred-diag.td
+++ clang/test/TableGen/deferred-diag.td
@@ -5,23 +5,23 @@
 // Test usage of Deferrable and NonDeferrable in diagnostics.
 
 def test_default : Error<"This error is non-deferrable by default">;
-// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, false, 0)
+// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, true, false, 0)
 
 def test_deferrable : Error<"This error is deferrable">, Deferrable;
-// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
 def test_non_deferrable : Error<"This error is non-deferrable">, NonDeferrable;
-// CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, false, 0)
+// CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, false, 0)
 
 let Deferrable = 1 in {
 
 def test_let : Error<"This error is deferrable by let">;
-// CHECK-DAG: DIAG(test_let, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_let, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
 // Make sure TextSubstitution is allowed in the let Deferrable block.
 def textsub : TextSubstitution<"%select{text1|text2}0">;
 
 def test_let2 : Error<"This error is deferrable by let %sub{textsub}0">;
-// CHECK-DAG: DIAG(test_let2, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_let2, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
-}
\ No newline at end of file
+}
Index: clang/test/TableGen/DiagnosticBase.inc
===
--- clang/test/TableGen/DiagnosticBase.inc
+++ clang/test/TableGen/DiagnosticBase.inc
@@ -76,6 +76,7 @@
   bitAccessControl = 0;
   bitWarningNoWerror = 0;
   bitShowInSystemHeader = 0;
+  bitShowInSystemMacro = 1;
   bitDeferrable = 0;
   Severity   Defa

[PATCH] D116833: [clang] Introduce support for disabling warnings in system macros

2022-01-12 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D116833#3236209 , @rsmith wrote:

> Thanks, this looks nice.
>
> I think we'll need to think carefully before changing the default here. It 
> seems like the choice here would depend on what token the location of the 
> diagnostic points to -- if we know that the token is directly responsible for 
> the warning, then suppressing the warning makes sense, but if some of the 
> code responsible for the warning is outside the system header (even though 
> the token at the diagnostic location is not), then we probably still want to 
> warn. I don't think we provide enough information to the diagnostic system to 
> decide this on a global basis. In any case, this change should make it really 
> easy to give the new behavior to more diagnostics.

Thanks a lot for the quick review! I agree that we should analyze it carefully 
if we want to change default behavior. For now this solves my immediate needs 
so I'll leave it at that :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116833

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


[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 399235.
pengfei marked an inline comment as done.
pengfei added a comment.

Add comments in code. @rnk, thanks for your patient review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

Files:
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/target-data.c
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/Bitcode/upgrade-datalayout3.ll
  llvm/test/CodeGen/X86/long-double-abi-align.ll
  llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
  llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
  llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Index: llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
===
--- llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
+++ llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
@@ -24,7 +24,7 @@
   EXPECT_EQ(DL1, "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64"
  "-f80:128-n8:16:32:64-S128");
   EXPECT_EQ(DL2, "e-m:w-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64"
- "-f80:32-n8:16:32-S32");
+ "-f80:128-n8:16:32-S32");
   EXPECT_EQ(DL3, "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128"
  "-n32:64-S128");
 
Index: llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
===
--- llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
+++ llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
@@ -909,8 +909,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:flds __real@5f00
 ; X86-AVX512-WIN-NEXT:xorl %edx, %edx
@@ -985,8 +985,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; X86-SSE3-WIN-NEXT:pushl %ebp
 ; X86-SSE3-WIN-NEXT:movl %esp, %ebp
-; X86-SSE3-WIN-NEXT:andl $-8, %esp
-; X86-SSE3-WIN-NEXT:subl $8, %esp
+; X86-SSE3-WIN-NEXT:andl $-16, %esp
+; X86-SSE3-WIN-NEXT:subl $16, %esp
 ; X86-SSE3-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE3-WIN-NEXT:flds __real@5f00
 ; X86-SSE3-WIN-NEXT:xorl %edx, %edx
@@ -1061,8 +1061,8 @@
 ; X86-SSE2-WIN:   # %bb.0:
 ; X86-SSE2-WIN-NEXT:pushl %ebp
 ; X86-SSE2-WIN-NEXT:movl %esp, %ebp
-; X86-SSE2-WIN-NEXT:andl $-8, %esp
-; X86-SSE2-WIN-NEXT:subl $16, %esp
+; X86-SSE2-WIN-NEXT:andl $-16, %esp
+; X86-SSE2-WIN-NEXT:subl $32, %esp
 ; X86-SSE2-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE2-WIN-NEXT:flds __real@5f00
 ; X86-SSE2-WIN-NEXT:xorl %edx, %edx
@@ -1161,8 +1161,8 @@
 ; X87-WIN:   # %bb.0:
 ; X87-WIN-NEXT:pushl %ebp
 ; X87-WIN-NEXT:movl %esp, %ebp
-; X87-WIN-NEXT:andl $-8, %esp
-; X87-WIN-NEXT:subl $16, %esp
+; X87-WIN-NEXT:andl $-16, %esp
+; X87-WIN-NEXT:subl $32, %esp
 ; X87-WIN-NEXT:fldt 8(%ebp)
 ; X87-WIN-NEXT:flds __real@5f00
 ; X87-WIN-NEXT:fucom %st(1)
@@ -1235,8 +1235,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:fisttpll (%esp)
 ; X86-AVX512-WIN-NEXT:movl (%esp), %eax
@@ -1275,8 +1275,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; X86-SSE3-WIN-NEXT:pushl %ebp
 ; X86-SSE3-WIN-NEXT:movl %esp, %ebp
-; X86-SSE3-WIN-NEXT:andl $-8, %esp
-; X86-SSE3-WIN-NEXT:subl $8, %esp
+; X86-SSE3-WIN-NEXT:andl $-16, %esp
+; X86-SSE3-WIN-NEXT:subl $16, %esp
 ; X86-SSE3-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE3-WIN-NEXT:fisttpll (%esp)
 ; X86-SSE3-WIN-NEXT:movl (%esp), %eax
@@ -1315,8 +1315,8 @@
 ; X86-SSE2-WIN:   # %bb.0:
 ; X86-SSE2-WIN-NEXT:pushl %ebp
 ; X86-SSE2-WIN-NEXT:movl %esp, %ebp
-; X86-SSE2-WIN-NEXT:andl $-8, %esp
-; X86-SSE2-WIN-NEXT:subl $16, %esp
+; X86-SSE2-WIN-NEXT:andl $-16, %esp
+; X86-SSE2-WIN-NEXT:subl $32, %esp
 ; X86-SSE2-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE2-WIN-NEXT:fnstcw {{[0-9]+}}(%esp)
 ; X86-SSE2-WIN-NEXT:movzwl {{[0-9]+}}(%esp), %eax
@@ -1379,8 +1379,8 @@
 ; X87-WIN:   # %bb.0:
 ; X87-WIN-NEXT:pushl %ebp
 ; X87-WIN-NEXT:movl %esp, %ebp
-; X87-WIN-NEXT:andl $-8, %esp
-; X87-WIN-NEXT:subl $16, %esp
+; X87-WIN-NEXT:andl $-16, %esp
+; X87-WIN-NEXT:subl $32, %esp
 ; X87-WIN-NEXT:fldt 8(%ebp)
 ; X87-WIN-NEXT:fnstcw {{[0-9]+}}(%esp)
 ; X87-WIN-NEXT:movzwl {{[0-9]+}}(%esp), %eax
Index: llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
===
--- llvm/test/CodeGen/X86/scalar-fp-to-i32

[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: llvm/lib/IR/AutoUpgrade.cpp:4583-4589
+  if (T.isArch64Bit() || !T.isWindowsMSVCEnvironment())
+return Res;
 
-  return (Groups[1] + AddrSpaces + Groups[3]).str();
+  StringRef Ref = Res;
+  auto I = Ref.find("-f80:32-");
+  if (I != StringRef::npos)
+Res = (Ref.take_front(I) + "-f80:128-" + Ref.drop_front(I + 8)).str();

rnk wrote:
> I think the early return here is not helping readability. Please add a 
> comment here about why this upgrade is being done, something like:
> ```
>   // For 32-bit MSVC targets, raise the alignment of f80 values to 16 bytes. 
> Raising the alignment is safe because Clang did not produce f80 values in the 
> MSVC environment before this upgrade was added.
>   if (T.isWindowsMSVCEnvironment() && T.isArch32Bit()) {
>
> ```
> 
That's better. Thanks for the suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

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


[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

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


[PATCH] D117090: Fix `readability-non-const-parameter` for parameter referenced by an lvalue

2022-01-12 Thread liushuai wang via Phabricator via cfe-commits
MTC added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp:86-99
+  // Data passed by nonconst reference should not be made const.
+  unsigned ArgNr = 0U;
+  if (const auto *CD = CE->getConstructor()) {
+for (const auto *Par : CD->parameters()) {
+  if (ArgNr >= CE->getNumArgs())
+break;
+  const Expr *Arg = CE->getArg(ArgNr++);

`86~99` is pretty close to `64~81`, could you please refactor it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117090

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


[PATCH] D117091: [Clang] Add attributes alloc_size and alloc_align to mm_malloc

2022-01-12 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 created this revision.
xbolva00 added reviewers: reames, rjmccall, jdoerfert.
xbolva00 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

alloc align https://clang.llvm.org/docs/AttributeReference.html#alloc-align
alloc size https://clang.llvm.org/docs/AttributeReference.html#alloc-size


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117091

Files:
  clang/lib/Headers/mm_malloc.h


Index: clang/lib/Headers/mm_malloc.h
===
--- clang/lib/Headers/mm_malloc.h
+++ clang/lib/Headers/mm_malloc.h
@@ -28,9 +28,9 @@
 
 #if !(defined(_WIN32) && defined(_mm_malloc))
 static __inline__ void *__attribute__((__always_inline__, __nodebug__,
-   __malloc__))
-_mm_malloc(size_t __size, size_t __align)
-{
+   __malloc__, alloc_size(1),
+   alloc_align(2)))
+_mm_malloc(size_t __size, size_t __align) {
   if (__align == 1) {
 return malloc(__size);
   }


Index: clang/lib/Headers/mm_malloc.h
===
--- clang/lib/Headers/mm_malloc.h
+++ clang/lib/Headers/mm_malloc.h
@@ -28,9 +28,9 @@
 
 #if !(defined(_WIN32) && defined(_mm_malloc))
 static __inline__ void *__attribute__((__always_inline__, __nodebug__,
-   __malloc__))
-_mm_malloc(size_t __size, size_t __align)
-{
+   __malloc__, alloc_size(1),
+   alloc_align(2)))
+_mm_malloc(size_t __size, size_t __align) {
   if (__align == 1) {
 return malloc(__size);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116025: [analyzer][NFC] Refactor GenericTaintChecker to use CallDescriptionMap

2022-01-12 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 399246.
gamesh411 added a comment.

Tidy things up thanks to the recommendations of @steakhal


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116025

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -38,6 +38,8 @@
 
 namespace {
 
+class GenericTaintChecker;
+
 /// Check for CWE-134: Uncontrolled Format String.
 constexpr llvm::StringLiteral MsgUncontrolledFormatString =
 "Untrusted data is used as a format string "
@@ -62,23 +64,26 @@
 "Untrusted data is passed to a user-defined sink";
 
 using ArgIdxTy = int;
-using ArgVecTy = llvm::SmallVector;
+using ArgVecTy = llvm::SmallVector;
 
-constexpr int InvalidArgIndex{-2};
 /// Denotes the return value.
-constexpr int ReturnValueIndex{-1};
+constexpr ArgIdxTy ReturnValueIndex{-1};
+
+static ArgIdxTy fromArgumentCount(unsigned Count) {
+  assert(Count <=
+ static_cast(std::numeric_limits::max()) &&
+ "ArgIdxTy is not large enough to represent the number of arguments.");
+  return Count;
+}
 
 /// Check if the region the expression evaluates to is the standard input,
 /// and thus, is tainted.
-bool isStdin(const Expr *E, CheckerContext &C) {
-  ProgramStateRef State = C.getState();
-  SVal Val = C.getSVal(E);
-
-  // stdin is a pointer, so it would be a region.
-  const MemRegion *MemReg = Val.getAsRegion();
+/// FIXME: Move this to Taint.cpp.
+bool isStdin(SVal Val, const ASTContext &ACtx) {
+  // FIXME: What if Val is NonParamVarRegion?
 
   // The region should be symbolic, we do not know it's value.
-  const auto *SymReg = dyn_cast_or_null(MemReg);
+  const auto *SymReg = dyn_cast_or_null(Val.getAsRegion());
   if (!SymReg)
 return false;
 
@@ -86,7 +91,7 @@
   const auto *Sm = dyn_cast(SymReg->getSymbol());
   if (!Sm)
 return false;
-  const auto *DeclReg = dyn_cast_or_null(Sm->getRegion());
+  const auto *DeclReg = dyn_cast(Sm->getRegion());
   if (!DeclReg)
 return false;
 
@@ -94,68 +99,58 @@
   // variable named stdin with the proper type.
   if (const auto *D = dyn_cast_or_null(DeclReg->getDecl())) {
 D = D->getCanonicalDecl();
+// FIXME: This should look for an exact match.
 if (D->getName().contains("stdin") && D->isExternC()) {
-  const auto *PtrTy = dyn_cast(D->getType().getTypePtr());
-  if (PtrTy && PtrTy->getPointeeType().getCanonicalType() ==
-   C.getASTContext().getFILEType().getCanonicalType())
-return true;
+  const QualType FILETy = ACtx.getFILEType().getCanonicalType();
+  const QualType Ty = D->getType().getCanonicalType();
+
+  if (Ty->isPointerType())
+return Ty->getPointeeType() == FILETy;
 }
   }
   return false;
 }
 
-/// Given a pointer argument, return the value it points to.
-Optional getPointeeOf(CheckerContext &C, const Expr *Arg) {
-  ProgramStateRef State = C.getState();
-  SVal AddrVal = C.getSVal(Arg->IgnoreParens());
-  if (AddrVal.isUnknownOrUndef())
-return None;
-
-  Optional AddrLoc = AddrVal.getAs();
-  if (!AddrLoc)
-return None;
-
-  QualType ArgTy = Arg->getType().getCanonicalType();
-  if (!ArgTy->isPointerType())
-return State->getSVal(*AddrLoc);
-
-  QualType ValTy = ArgTy->getPointeeType();
+SVal getPointeeOf(const CheckerContext &C, Loc LValue) {
+  const QualType ArgTy = LValue.getType(C.getASTContext());
+  if (!ArgTy->isPointerType() || !ArgTy->getPointeeType()->isVoidType())
+return C.getState()->getSVal(LValue);
 
   // Do not dereference void pointers. Treat them as byte pointers instead.
   // FIXME: we might want to consider more than just the first byte.
-  if (ValTy->isVoidType())
-ValTy = C.getASTContext().CharTy;
+  return C.getState()->getSVal(LValue, C.getASTContext().CharTy);
+}
 
-  return State->getSVal(*AddrLoc, ValTy);
+/// Given a pointer/reference argument, return the value it refers to.
+Optional getPointeeOf(const CheckerContext &C, SVal Arg) {
+  if (auto LValue = Arg.getAs())
+return getPointeeOf(C, *LValue);
+  return None;
 }
 
 /// Given a pointer, return the SVal of its pointee or if it is tainted,
 /// otherwise return the pointer's SVal if tainted.
-Optional getTaintedPointeeOrPointer(CheckerContext &C, const Expr *Arg) {
-  assert(Arg);
-  // Check for taint.
-  ProgramStateRef State = C.getState();
-  Optional PointedToSVal = getPointeeOf(C, Arg);
+/// Also considers stdin as a taint source.
+Optional getTaintedPointeeOrPointer(const CheckerContext &C, SVal Arg) {
+  const ProgramStateRef State = C.getState();
 
-  if (PointedToSVal && isTainted(State, *PointedToSVal))
- 

[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Thanks Craig!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

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


[PATCH] D117037: [clang][CodeComplete] Perform approximate member search in bases

2022-01-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 399252.
kadircet marked 5 inline comments as done.
kadircet added a comment.

- Replace clangd unittest with clang lit
- get rid of non-cxxrecorddecl handling


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117037

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp


Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -296,3 +296,18 @@
 }
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:295:17 %s -o - | 
FileCheck -check-prefix=CHECK-OVERLOAD %s
 // CHECK-OVERLOAD: [#int#]member
+
+struct Base4 {
+  Base4 base4();
+};
+
+template 
+struct Derived2 : Base4 {};
+
+template 
+void testMembersFromBasesInDependentContext() {
+  Derived2 X;
+  (void)X.base4().base4();
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | 
FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
+  // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5409,11 +5409,17 @@
 : getApproximateType(CDSME->getBase());
 if (CDSME->isArrow() && !Base.isNull())
   Base = Base->getPointeeType(); // could handle unique_ptr etc here?
-RecordDecl *RD = Base.isNull() ? nullptr : getAsRecordDecl(Base);
+auto *RD = Base.isNull()
+   ? nullptr
+   : llvm::dyn_cast(getAsRecordDecl(Base));
 if (RD && RD->isCompleteDefinition()) {
-  for (const auto *Member : RD->lookup(CDSME->getMember()))
-if (const ValueDecl *VD = llvm::dyn_cast(Member))
-  return VD->getType().getNonReferenceType();
+  // Look up member heuristically, including in bases.
+  for (const auto *Member : RD->lookupDependentName(
+   CDSME->getMember(), [](const NamedDecl *Member) {
+ return llvm::isa(Member);
+   })) {
+return llvm::cast(Member)->getType().getNonReferenceType();
+  }
 }
   }
   return Unresolved;


Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -296,3 +296,18 @@
 }
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:295:17 %s -o - | FileCheck -check-prefix=CHECK-OVERLOAD %s
 // CHECK-OVERLOAD: [#int#]member
+
+struct Base4 {
+  Base4 base4();
+};
+
+template 
+struct Derived2 : Base4 {};
+
+template 
+void testMembersFromBasesInDependentContext() {
+  Derived2 X;
+  (void)X.base4().base4();
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
+  // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5409,11 +5409,17 @@
 : getApproximateType(CDSME->getBase());
 if (CDSME->isArrow() && !Base.isNull())
   Base = Base->getPointeeType(); // could handle unique_ptr etc here?
-RecordDecl *RD = Base.isNull() ? nullptr : getAsRecordDecl(Base);
+auto *RD = Base.isNull()
+   ? nullptr
+   : llvm::dyn_cast(getAsRecordDecl(Base));
 if (RD && RD->isCompleteDefinition()) {
-  for (const auto *Member : RD->lookup(CDSME->getMember()))
-if (const ValueDecl *VD = llvm::dyn_cast(Member))
-  return VD->getType().getNonReferenceType();
+  // Look up member heuristically, including in bases.
+  for (const auto *Member : RD->lookupDependentName(
+   CDSME->getMember(), [](const NamedDecl *Member) {
+ return llvm::isa(Member);
+   })) {
+return llvm::cast(Member)->getType().getNonReferenceType();
+  }
 }
   }
   return Unresolved;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D117037: [clang][CodeComplete] Perform approximate member search in bases

2022-01-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:3459
+  const std::string Code = R"cpp(
+struct Base { Base foo(); };
+

sammccall wrote:
> does this also work if the base is dependent (Base)?
yes



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5423
+}
+  } else {
+for (const auto *Member : RD->lookup(CDSME->getMember())) {

sammccall wrote:
> This case seems very nearly dead. Technically it is possible to get a 
> CXXDependentScopeMemberExpr in C using recovery expr, but I can't find a case 
> where this is useful. Maybe drop it?
ah right, i was mostly concerned about objc records, forgetting that we only 
perform this in dependent contexts :D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117037

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


[PATCH] D116294: [CodeCompletion] (mostly) fix completion in incomplete C++ ctor initializers.

2022-01-12 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/D116294/new/

https://reviews.llvm.org/D116294

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


[clang] 1bb0caf - [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Phoebe Wang via cfe-commits

Author: Phoebe Wang
Date: 2022-01-12T17:50:37+08:00
New Revision: 1bb0caf561688681be67cc91560348c9e43fcbf3

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

LOG: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to 
match with ICC

MSVC currently doesn't support 80 bits long double. ICC supports it when
the option `/Qlong-double` is specified. Changing the alignment of f80
to 16 bytes so that we can be compatible with ICC's option.

Reviewed By: rnk, craig.topper

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

Added: 


Modified: 
clang/lib/Basic/Targets/X86.h
clang/test/CodeGen/target-data.c
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/Target/X86/X86TargetMachine.cpp
llvm/test/Bitcode/upgrade-datalayout3.ll
llvm/test/CodeGen/X86/long-double-abi-align.ll
llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index c952b8c9a3369..d1b66432e38b4 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -533,11 +533,12 @@ class LLVM_LIBRARY_VISIBILITY WindowsX86_32TargetInfo
 DoubleAlign = LongLongAlign = 64;
 bool IsWinCOFF =
 getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
-resetDataLayout(IsWinCOFF ? "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:"
-"64-i64:64-f80:32-n8:16:32-a:0:32-S32"
-  : "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:"
-"64-i64:64-f80:32-n8:16:32-a:0:32-S32",
-IsWinCOFF ? "_" : "");
+bool IsMSVC = getTriple().isWindowsMSVCEnvironment();
+std::string Layout = IsWinCOFF ? "e-m:x" : "e-m:e";
+Layout += "-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-";
+Layout += IsMSVC ? "f80:128" : "f80:32";
+Layout += "-n8:16:32-a:0:32-S32";
+resetDataLayout(Layout, IsWinCOFF ? "_" : "");
   }
 };
 

diff  --git a/clang/test/CodeGen/target-data.c 
b/clang/test/CodeGen/target-data.c
index d702f845112bd..e4150837279ce 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -8,7 +8,7 @@
 
 // RUN: %clang_cc1 -triple i686-unknown-win32 -emit-llvm -o - %s | \
 // RUN: FileCheck --check-prefix=I686-WIN32 %s
-// I686-WIN32: target datalayout = 
"e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:32-n8:16:32-a:0:32-S32"
+// I686-WIN32: target datalayout = 
"e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32-a:0:32-S32"
 
 // RUN: %clang_cc1 -triple i686-unknown-cygwin -emit-llvm -o - %s | \
 // RUN: FileCheck --check-prefix=I686-CYGWIN %s

diff  --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index a7c34caab1c3e..9b9325a2d741c 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -4569,18 +4569,29 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, 
StringRef TT) {
 return DL.empty() ? std::string("G1") : (DL + "-G1").str();
   }
 
+  std::string Res = DL.str();
   std::string AddrSpaces = "-p270:32:32-p271:32:32-p272:64:64";
   // If X86, and the datalayout matches the expected format, add pointer size
   // address spaces to the datalayout.
   if (!T.isX86() || DL.contains(AddrSpaces))
-return std::string(DL);
+return Res;
 
   SmallVector Groups;
   Regex R("(e-m:[a-z](-p:32:32)?)(-[if]64:.*$)");
-  if (!R.match(DL, &Groups))
-return std::string(DL);
+  if (R.match(DL, &Groups))
+Res = (Groups[1] + AddrSpaces + Groups[3]).str();
+
+  // For 32-bit MSVC targets, raise the alignment of f80 values to 16 bytes.
+  // Raising the alignment is safe because Clang did not produce f80 values in
+  // the MSVC environment before this upgrade was added.
+  if (T.isWindowsMSVCEnvironment() && !T.isArch64Bit()) {
+StringRef Ref = Res;
+auto I = Ref.find("-f80:32-");
+if (I != StringRef::npos)
+  Res = (Ref.take_front(I) + "-f80:128-" + Ref.drop_front(I + 8)).str();
+  }
 
-  return (Groups[1] + AddrSpaces + Groups[3]).str();
+  return Res;
 }
 
 void llvm::UpgradeAttributes(AttrBuilder &B) {

diff  --git a/llvm/lib/Target/X86/X86TargetMachine.cpp 
b/llvm/lib/Target/X86/X86TargetMachine.cpp
index 78bc5519c23ff..e3d0128dd73da 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -127,7 +127,7 @@ static std::string computeDataLayout(const Triple &TT) {
   // Some ABIs align long double to 128 bits, others to 32.
   if (TT.isOSNaCl() || TT.isOSIAMCU())
 ; // No f80
-  else if (TT.isArch64Bit() || TT.isOSDarwin())
+  else if (TT.isArch64Bit() || TT.isOSDarwin() || 
TT.isWindowsMSVCEnvironm

[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Phoebe Wang 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 rG1bb0caf56168: [X86][MS] Change the alignment of f80 to 16 
bytes on Windows 32bits to match… (authored by pengfei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

Files:
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/target-data.c
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/Bitcode/upgrade-datalayout3.ll
  llvm/test/CodeGen/X86/long-double-abi-align.ll
  llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
  llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
  llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Index: llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
===
--- llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
+++ llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
@@ -24,7 +24,7 @@
   EXPECT_EQ(DL1, "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64"
  "-f80:128-n8:16:32:64-S128");
   EXPECT_EQ(DL2, "e-m:w-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64"
- "-f80:32-n8:16:32-S32");
+ "-f80:128-n8:16:32-S32");
   EXPECT_EQ(DL3, "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128"
  "-n32:64-S128");
 
Index: llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
===
--- llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
+++ llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
@@ -909,8 +909,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:flds __real@5f00
 ; X86-AVX512-WIN-NEXT:xorl %edx, %edx
@@ -985,8 +985,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; X86-SSE3-WIN-NEXT:pushl %ebp
 ; X86-SSE3-WIN-NEXT:movl %esp, %ebp
-; X86-SSE3-WIN-NEXT:andl $-8, %esp
-; X86-SSE3-WIN-NEXT:subl $8, %esp
+; X86-SSE3-WIN-NEXT:andl $-16, %esp
+; X86-SSE3-WIN-NEXT:subl $16, %esp
 ; X86-SSE3-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE3-WIN-NEXT:flds __real@5f00
 ; X86-SSE3-WIN-NEXT:xorl %edx, %edx
@@ -1061,8 +1061,8 @@
 ; X86-SSE2-WIN:   # %bb.0:
 ; X86-SSE2-WIN-NEXT:pushl %ebp
 ; X86-SSE2-WIN-NEXT:movl %esp, %ebp
-; X86-SSE2-WIN-NEXT:andl $-8, %esp
-; X86-SSE2-WIN-NEXT:subl $16, %esp
+; X86-SSE2-WIN-NEXT:andl $-16, %esp
+; X86-SSE2-WIN-NEXT:subl $32, %esp
 ; X86-SSE2-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE2-WIN-NEXT:flds __real@5f00
 ; X86-SSE2-WIN-NEXT:xorl %edx, %edx
@@ -1161,8 +1161,8 @@
 ; X87-WIN:   # %bb.0:
 ; X87-WIN-NEXT:pushl %ebp
 ; X87-WIN-NEXT:movl %esp, %ebp
-; X87-WIN-NEXT:andl $-8, %esp
-; X87-WIN-NEXT:subl $16, %esp
+; X87-WIN-NEXT:andl $-16, %esp
+; X87-WIN-NEXT:subl $32, %esp
 ; X87-WIN-NEXT:fldt 8(%ebp)
 ; X87-WIN-NEXT:flds __real@5f00
 ; X87-WIN-NEXT:fucom %st(1)
@@ -1235,8 +1235,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:fisttpll (%esp)
 ; X86-AVX512-WIN-NEXT:movl (%esp), %eax
@@ -1275,8 +1275,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; X86-SSE3-WIN-NEXT:pushl %ebp
 ; X86-SSE3-WIN-NEXT:movl %esp, %ebp
-; X86-SSE3-WIN-NEXT:andl $-8, %esp
-; X86-SSE3-WIN-NEXT:subl $8, %esp
+; X86-SSE3-WIN-NEXT:andl $-16, %esp
+; X86-SSE3-WIN-NEXT:subl $16, %esp
 ; X86-SSE3-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE3-WIN-NEXT:fisttpll (%esp)
 ; X86-SSE3-WIN-NEXT:movl (%esp), %eax
@@ -1315,8 +1315,8 @@
 ; X86-SSE2-WIN:   # %bb.0:
 ; X86-SSE2-WIN-NEXT:pushl %ebp
 ; X86-SSE2-WIN-NEXT:movl %esp, %ebp
-; X86-SSE2-WIN-NEXT:andl $-8, %esp
-; X86-SSE2-WIN-NEXT:subl $16, %esp
+; X86-SSE2-WIN-NEXT:andl $-16, %esp
+; X86-SSE2-WIN-NEXT:subl $32, %esp
 ; X86-SSE2-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE2-WIN-NEXT:fnstcw {{[0-9]+}}(%esp)
 ; X86-SSE2-WIN-NEXT:movzwl {{[0-9]+}}(%esp), %eax
@@ -1379,8 +1379,8 @@
 ; X87-WIN:   # %bb.0:
 ; X87-WIN-NEXT:pushl %ebp
 ; X87-WIN-NEXT:movl %esp, %ebp
-; X87-WIN-NEXT:andl $-8, %esp
-; X87-WIN-NEXT:subl $16, %esp
+; X87-WIN-NEXT:andl $-16, %esp
+; X87-WIN-NEXT:subl $32, %esp
 ; X87-WIN-NEXT:fldt 8(%ebp)
 ; X87-WIN-NEXT:fnstcw {{[0-9]+}}(%esp)
 ; X87-WIN-NEXT:movzwl {{[0-9]+}}(%esp), %eax
Index: llvm/test/CodeGen/X86/scalar-fp-to-i32.ll

[clang] dfd9879 - [Clang] Make Clang copy its CMake modules into the build dir

2022-01-12 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-01-12T09:51:14Z
New Revision: dfd9879d6f43949443ba3c58cf3969ed582d7466

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

LOG: [Clang] Make Clang copy its CMake modules into the build dir

LLVM has a documented mechanism for passing configuration information to
an out of tree project using CMake. See
https://llvm.org/docs/CMake.html#embedding-llvm-in-your-project.
Similar logic applies to "standalone" builds of other sub-projects
within LLVM that depend on each other. For example, a standalone build
of Flang will use this mechanism to acquire Clang's configuration.

Currently, the relevant CMake modules for Clang will only be copied into
the installation directory. This means that in order to configure a
standalone build of Flang, one has to first build and then install
Clang. This is not required for LLVM nor for MLIR - other sub-projects
that Flang depends on (i.e. the CMake modules for LLVM and MLIR are
available in the build dir, so installation is not needed).

This change removes the need for installing Clang in order to access its
configuration. It makes sure that the required CMake modules are copied
into the build directory. This will make Clang behave consistently with
LLVM and MLIR in this respect. It will also simplify building Flang as
standalone sub-project.

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

Added: 


Modified: 
clang/cmake/modules/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/CMakeLists.txt 
b/clang/cmake/modules/CMakeLists.txt
index 3890ea14d06c6..e9cc1240dafb7 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -29,6 +29,14 @@ configure_file(
 set(CLANG_CONFIG_CMAKE_DIR)
 set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 
+# For compatibility with projects that include(ClangConfig)
+# via CMAKE_MODULE_PATH, place API modules next to it.
+file(COPY .
+  DESTINATION ${clang_cmake_builddir}
+  FILES_MATCHING PATTERN *.cmake
+  PATTERN CMakeFiles EXCLUDE
+  )
+
 # Generate ClangConfig.cmake for the install tree.
 find_prefix_from_config(CLANG_CONFIG_CODE CLANG_INSTALL_PREFIX 
"${CLANG_INSTALL_PACKAGE_DIR}")
 set(CLANG_CONFIG_CMAKE_DIR 
"\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}")



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


[PATCH] D116731: [Clang] Make Clang copy its CMake modules into the build dir

2022-01-12 Thread Andrzej Warzynski 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 rGdfd9879d6f43: [Clang] Make Clang copy its CMake modules into 
the build dir (authored by awarzynski).

Changed prior to commit:
  https://reviews.llvm.org/D116731?vs=397824&id=399259#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116731

Files:
  clang/cmake/modules/CMakeLists.txt


Index: clang/cmake/modules/CMakeLists.txt
===
--- clang/cmake/modules/CMakeLists.txt
+++ clang/cmake/modules/CMakeLists.txt
@@ -29,6 +29,14 @@
 set(CLANG_CONFIG_CMAKE_DIR)
 set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 
+# For compatibility with projects that include(ClangConfig)
+# via CMAKE_MODULE_PATH, place API modules next to it.
+file(COPY .
+  DESTINATION ${clang_cmake_builddir}
+  FILES_MATCHING PATTERN *.cmake
+  PATTERN CMakeFiles EXCLUDE
+  )
+
 # Generate ClangConfig.cmake for the install tree.
 find_prefix_from_config(CLANG_CONFIG_CODE CLANG_INSTALL_PREFIX 
"${CLANG_INSTALL_PACKAGE_DIR}")
 set(CLANG_CONFIG_CMAKE_DIR 
"\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}")


Index: clang/cmake/modules/CMakeLists.txt
===
--- clang/cmake/modules/CMakeLists.txt
+++ clang/cmake/modules/CMakeLists.txt
@@ -29,6 +29,14 @@
 set(CLANG_CONFIG_CMAKE_DIR)
 set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 
+# For compatibility with projects that include(ClangConfig)
+# via CMAKE_MODULE_PATH, place API modules next to it.
+file(COPY .
+  DESTINATION ${clang_cmake_builddir}
+  FILES_MATCHING PATTERN *.cmake
+  PATTERN CMakeFiles EXCLUDE
+  )
+
 # Generate ClangConfig.cmake for the install tree.
 find_prefix_from_config(CLANG_CONFIG_CODE CLANG_INSTALL_PREFIX "${CLANG_INSTALL_PACKAGE_DIR}")
 set(CLANG_CONFIG_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116919: [AST] Add RParen loc for decltype AutoTypeloc.

2022-01-12 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

The relanded version in rG41fbdfa4d5601cccbcdc0ded8ef35190d502f7f3 
 seems to 
be breaking some builds with PCH for me, failing asserts like this:

  clang: ../tools/clang/include/clang/Basic/SourceLocation.h:135: 
clang::SourceLocation 
clang::SourceLocation::getLocWithOffset(clang::SourceLocation::IntTy) const: 
Assertion `((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow"' 
failed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116919

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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-01-12 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence added a comment.

Ping. `Zfinx` has been ratified, could we spend some time on this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

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


[PATCH] D117037: [clang][CodeComplete] Perform approximate member search in bases

2022-01-12 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 rG612f5ed88231: [clang][CodeComplete] Perform approximate 
member search in bases (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117037

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp


Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -296,3 +296,18 @@
 }
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:295:17 %s -o - | 
FileCheck -check-prefix=CHECK-OVERLOAD %s
 // CHECK-OVERLOAD: [#int#]member
+
+struct Base4 {
+  Base4 base4();
+};
+
+template 
+struct Derived2 : Base4 {};
+
+template 
+void testMembersFromBasesInDependentContext() {
+  Derived2 X;
+  (void)X.base4().base4();
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | 
FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
+  // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5519,11 +5519,17 @@
 : getApproximateType(CDSME->getBase());
 if (CDSME->isArrow() && !Base.isNull())
   Base = Base->getPointeeType(); // could handle unique_ptr etc here?
-RecordDecl *RD = Base.isNull() ? nullptr : getAsRecordDecl(Base);
+auto *RD = Base.isNull()
+   ? nullptr
+   : llvm::dyn_cast(getAsRecordDecl(Base));
 if (RD && RD->isCompleteDefinition()) {
-  for (const auto *Member : RD->lookup(CDSME->getMember()))
-if (const ValueDecl *VD = llvm::dyn_cast(Member))
-  return VD->getType().getNonReferenceType();
+  // Look up member heuristically, including in bases.
+  for (const auto *Member : RD->lookupDependentName(
+   CDSME->getMember(), [](const NamedDecl *Member) {
+ return llvm::isa(Member);
+   })) {
+return llvm::cast(Member)->getType().getNonReferenceType();
+  }
 }
   }
   return Unresolved;


Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -296,3 +296,18 @@
 }
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:295:17 %s -o - | FileCheck -check-prefix=CHECK-OVERLOAD %s
 // CHECK-OVERLOAD: [#int#]member
+
+struct Base4 {
+  Base4 base4();
+};
+
+template 
+struct Derived2 : Base4 {};
+
+template 
+void testMembersFromBasesInDependentContext() {
+  Derived2 X;
+  (void)X.base4().base4();
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
+  // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5519,11 +5519,17 @@
 : getApproximateType(CDSME->getBase());
 if (CDSME->isArrow() && !Base.isNull())
   Base = Base->getPointeeType(); // could handle unique_ptr etc here?
-RecordDecl *RD = Base.isNull() ? nullptr : getAsRecordDecl(Base);
+auto *RD = Base.isNull()
+   ? nullptr
+   : llvm::dyn_cast(getAsRecordDecl(Base));
 if (RD && RD->isCompleteDefinition()) {
-  for (const auto *Member : RD->lookup(CDSME->getMember()))
-if (const ValueDecl *VD = llvm::dyn_cast(Member))
-  return VD->getType().getNonReferenceType();
+  // Look up member heuristically, including in bases.
+  for (const auto *Member : RD->lookupDependentName(
+   CDSME->getMember(), [](const NamedDecl *Member) {
+ return llvm::isa(Member);
+   })) {
+return llvm::cast(Member)->getType().getNonReferenceType();
+  }
 }
   }
   return Unresolved;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 612f5ed - [clang][CodeComplete] Perform approximate member search in bases

2022-01-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-01-12T10:56:06+01:00
New Revision: 612f5ed8823120b30cb3c8bbde79a7f0ae9d1761

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

LOG: [clang][CodeComplete] Perform approximate member search in bases

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

Added: 


Modified: 
clang/lib/Sema/SemaCodeComplete.cpp
clang/test/CodeCompletion/member-access.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 9266deb6699af..cc08dee266136 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -5519,11 +5519,17 @@ QualType getApproximateType(const Expr *E) {
 : getApproximateType(CDSME->getBase());
 if (CDSME->isArrow() && !Base.isNull())
   Base = Base->getPointeeType(); // could handle unique_ptr etc here?
-RecordDecl *RD = Base.isNull() ? nullptr : getAsRecordDecl(Base);
+auto *RD = Base.isNull()
+   ? nullptr
+   : llvm::dyn_cast(getAsRecordDecl(Base));
 if (RD && RD->isCompleteDefinition()) {
-  for (const auto *Member : RD->lookup(CDSME->getMember()))
-if (const ValueDecl *VD = llvm::dyn_cast(Member))
-  return VD->getType().getNonReferenceType();
+  // Look up member heuristically, including in bases.
+  for (const auto *Member : RD->lookupDependentName(
+   CDSME->getMember(), [](const NamedDecl *Member) {
+ return llvm::isa(Member);
+   })) {
+return llvm::cast(Member)->getType().getNonReferenceType();
+  }
 }
   }
   return Unresolved;

diff  --git a/clang/test/CodeCompletion/member-access.cpp 
b/clang/test/CodeCompletion/member-access.cpp
index 88129d45bccf1..2c611b4715800 100644
--- a/clang/test/CodeCompletion/member-access.cpp
+++ b/clang/test/CodeCompletion/member-access.cpp
@@ -296,3 +296,18 @@ void fooDependent(T t) {
 }
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:295:17 %s -o - | 
FileCheck -check-prefix=CHECK-OVERLOAD %s
 // CHECK-OVERLOAD: [#int#]member
+
+struct Base4 {
+  Base4 base4();
+};
+
+template 
+struct Derived2 : Base4 {};
+
+template 
+void testMembersFromBasesInDependentContext() {
+  Derived2 X;
+  (void)X.base4().base4();
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | 
FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
+  // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
+}



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


[PATCH] D116088: [compiler-rt] Implement ARM atomic operations for architectures without SMP support

2022-01-12 Thread Pavel Kosov via Phabricator via cfe-commits
kpdev42 added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116088

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


[PATCH] D112906: [PowerPC] Emit warning for ieeelongdouble on older GNU toolchain

2022-01-12 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf updated this revision to Diff 399262.
qiucf edited the summary of this revision.
qiucf added a comment.

Also check glibc version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112906

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/PPCLinux.cpp
  clang/lib/Driver/ToolChains/PPCLinux.h
  
clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/lib/gcc/powerpc64le-linux-gnu/11.2.0/.keep
  clang/test/Driver/ppc-float-abi-warning.cpp

Index: clang/test/Driver/ppc-float-abi-warning.cpp
===
--- /dev/null
+++ clang/test/Driver/ppc-float-abi-warning.cpp
@@ -0,0 +1,13 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s \
+// RUN:  --gcc-toolchain=%S/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0 \
+// RUN:  -mabi=ieeelongdouble -stdlib=libstdc++ 2>&1 | FileCheck %s
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s \
+// RUN:  -mabi=ieeelongdouble -stdlib=libc++ 2>&1 | FileCheck %s
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s\
+// RUN:  -mabi=ieeelongdouble -stdlib=libc++ -Wno-unsupported-abi 2>&1 | \
+// RUN:  FileCheck %s --check-prefix=NOWARN
+
+// CHECK: warning: float ABI 'ieeelongdouble' is not supported by current library
+// NOWARN-NOT: warning: float ABI 'ieeelongdouble' is not supported by current library
+long double foo(long double x) { return x;  }
Index: clang/lib/Driver/ToolChains/PPCLinux.h
===
--- clang/lib/Driver/ToolChains/PPCLinux.h
+++ clang/lib/Driver/ToolChains/PPCLinux.h
@@ -18,12 +18,15 @@
 class LLVM_LIBRARY_VISIBILITY PPCLinuxToolChain : public Linux {
 public:
   PPCLinuxToolChain(const Driver &D, const llvm::Triple &Triple,
-const llvm::opt::ArgList &Args)
-  : Linux(D, Triple, Args) {}
+const llvm::opt::ArgList &Args);
 
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args) const override;
+
+private:
+  void CheckFloatABI(const Driver &D, const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args) const;
 };
 
 } // end namespace toolchains
Index: clang/lib/Driver/ToolChains/PPCLinux.cpp
===
--- clang/lib/Driver/ToolChains/PPCLinux.cpp
+++ clang/lib/Driver/ToolChains/PPCLinux.cpp
@@ -8,11 +8,46 @@
 
 #include "PPCLinux.h"
 #include "clang/Driver/Driver.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
 using namespace clang::driver::toolchains;
 using namespace llvm::opt;
+using namespace llvm::sys;
+
+// Glibc older than 2.32 doesn't fully support IEEE float128. Here we check
+// glibc version by looking at dynamic linker name.
+static bool GlibcSupportsFloat128(const std::string& Linker) {
+  llvm::SmallVector Path;
+
+  // Resolve potential symlinks to linker.
+  if (fs::real_path(Linker, Path))
+return false;
+  llvm::StringRef LinkerName =
+  path::filename(llvm::StringRef(Path.data(), Path.size()));
+
+  // Since glibc 2.34, the installed .so file is not symlink anymore. But we can
+  // still safely assume it's newer than 2.32.
+  if (LinkerName.startswith("ld64.so"))
+return true;
+
+  if (!LinkerName.startswith("ld-2."))
+return false;
+  unsigned Minor = (LinkerName[5] - '0') * 10 + (LinkerName[6] - '0');
+  if (Minor < 32)
+return false;
+
+  return true;
+}
+
+PPCLinuxToolChain::PPCLinuxToolChain(const Driver &D,
+ const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args)
+: Linux(D, Triple, Args) {
+  CheckFloatABI(D, Triple, Args);
+}
 
 void PPCLinuxToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
   ArgStringList &CC1Args) const {
@@ -26,3 +61,25 @@
 
   Linux::AddClangSystemIncludeArgs(DriverArgs, CC1Args);
 }
+
+void PPCLinuxToolChain::CheckFloatABI(const Driver &D,
+  const llvm::Triple &Triple,
+  const llvm::opt::ArgList &Args) const {
+  if (!Triple.isLittleEndian() || !Triple.isPPC64() ||
+  Args.hasArg(options::OPT_nostdlib, options::OPT_nostdlibxx))
+return;
+
+  bool HasUnsupportedCXXLib =
+  ToolChain::GetCXXStdlibType(Args) == CST_Libcxx &&
+  GCCInstallation.getVersion().isOlderThan(12, 1, 0);
+  bool HasUnsupportedLibc =
+  !GlibcSupportsFloat128(Linux::getDynamicLinker(Args));
+  if (HasUnsupportedLibc || (D.CCCIsCXX() && HasUnsupportedCXXLib)) {
+if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
+  String

[clang] eadb4cf - Revert (2) "[AST] Add RParen loc for decltype AutoTypeloc."

2022-01-12 Thread Florian Hahn via cfe-commits

Author: Florian Hahn
Date: 2022-01-12T10:09:37Z
New Revision: eadb4cfeeff55678eac0c9225f095567e1564424

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

LOG: Revert (2) "[AST] Add RParen loc for decltype AutoTypeloc."

This reverts commit 41fbdfa4d5601cccbcdc0ded8ef35190d502f7f3.

The commit breaks stage 2 builds with debug info, e.g.
https://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/5088/console

Clang crashes with the following assertion when building
llvm-project/llvm/lib/Support/Timer.cpp

/usr/local/bin/sccache 
/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/host-compiler/bin/clang++
  -DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS -Ilib/Support 
-I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support
 -Iinclude 
-I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/include
 -fno-stack-protector -fno-common -Wno-profile-instr-unprofiled -fPIC 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -fmodules 
-fmodules-cache-path=/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/clang-build/Build/module.cache
 -fcxx-modules -Xclang -fmodules-local-submodule-visibility -gmodules -Wall 
-Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi 
-Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type 
-Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override 
-Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -flto=thin  
-O2 -g -DNDEBUG -isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
   -std=c++14  -fno-exceptions -fno-rtti -MD -MT 
lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -MF 
lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o.d -o 
lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -c 
/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support/Timer.cpp
Assertion failed: (((getOffset()+Offset) & MacroIDBit) == 0 && "offset 
overflow"), function getLocWithOffset, file 
/Users/buildslave/jenkins/workspace/clang-stage1-RA/llvm-project/clang/include/clang/Basic/SourceLocation.h,
 line 135.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
clang/include/clang/AST/TypeLoc.h
clang/lib/AST/TypeLoc.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/AST/ast-dump-template-decls-json.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/unittests/AST/SourceLocationTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index 2b9907d162664..d5c9fa7de811e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -285,12 +285,15 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
 return {};
   }
 
-  // If the return type is a constrained 'auto', we need to include the token
-  // after the concept. Unfortunately, the source range of an AutoTypeLoc, if 
it
-  // is constrained, does not include the 'auto'.
-  // FIXME: fix the AutoTypeLoc location in clang.
+  // If the return type is a constrained 'auto' or 'decltype(auto)', we need to
+  // include the tokens after the concept. Unfortunately, the source range of 
an
+  // AutoTypeLoc, if it is constrained, does not include the 'auto' or
+  // 'decltype(auto)'. If the return type is a plain 'decltype(...)', the
+  // source range only contains the first 'decltype' token.
   auto ATL = ReturnLoc.getAs();
-  if (ATL && ATL.isConstrained() && !ATL.isDecltypeAuto()) {
+  if ((ATL && (ATL.isConstrained() ||
+   ATL.getAutoKeyword() == AutoTypeKeyword::DecltypeAuto)) ||
+  ReturnLoc.getAs()) {
 SourceLocation End =
 expandIfMacroId(ReturnLoc.getSourceRange().getEnd(), SM);
 SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
index 914564e9ae218..3776e1c3505d1 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandAut

[PATCH] D116919: [AST] Add RParen loc for decltype AutoTypeloc.

2022-01-12 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D116919#3236899 , @mstorsjo wrote:

> The relanded version in rG41fbdfa4d5601cccbcdc0ded8ef35190d502f7f3 
>  seems 
> to be breaking some builds with PCH for me, failing asserts like this:
>
>   clang: ../tools/clang/include/clang/Basic/SourceLocation.h:135: 
> clang::SourceLocation 
> clang::SourceLocation::getLocWithOffset(clang::SourceLocation::IntTy) const: 
> Assertion `((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow"' 
> failed.

This also breaks stage2 builds with debug info, e.g. 
https://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/5088/console

Given that the bot has been red a while now, I reverted the commit eadb4cfeeff5 
 for now.

The crash should be reproducible when doing a stage2 build with debug info. It 
crashes, e.g. when building llvm-project/llvm/lib/Support/Timer.cpp

   
/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/host-compiler/bin/clang++
  -DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS -Ilib/Support 
-I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support
 -Iinclude 
-I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/include
 -fno-stack-protector -fno-common -Wno-profile-instr-unprofiled -fPIC 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -fmodules 
-fmodules-cache-path=/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/clang-build/Build/module.cache
 -fcxx-modules -Xclang -fmodules-local-submodule-visibility -gmodules -Wall 
-Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi 
-Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type 
-Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override 
-Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -flto=thin  
-O2 -g -DNDEBUG -isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
   -std=c++14  -fno-exceptions -fno-rtti -MD -MT 
lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -MF 
lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o.d -o 
lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -c 
/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support/Timer.cpp
  Assertion failed: (((getOffset()+Offset) & MacroIDBit) == 0 && "offset 
overflow"), function getLocWithOffset, file 
/Users/buildslave/jenkins/workspace/clang-stage1-RA/llvm-project/clang/include/clang/Basic/SourceLocation.h,
 line 135.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116919

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


[PATCH] D116919: [AST] Add RParen loc for decltype AutoTypeloc.

2022-01-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D116919#3236899 , @mstorsjo wrote:

> The relanded version in rG41fbdfa4d5601cccbcdc0ded8ef35190d502f7f3 
>  seems 
> to be breaking some builds with PCH for me, failing asserts like this:
>
>   clang: ../tools/clang/include/clang/Basic/SourceLocation.h:135: 
> clang::SourceLocation 
> clang::SourceLocation::getLocWithOffset(clang::SourceLocation::IntTy) const: 
> Assertion `((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow"' 
> failed.

Thanks for raising this. It would be great if you can provide a reproduce case 
and a more detailed log. A failed PCH build usually indicates something wrong 
around the ASTReader/ASTWriter code, but I didn't spot out any issue there. At 
the mean time, I will try to investigate it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116919

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


[PATCH] D115640: [OpenCL] Add support of __opencl_c_device_enqueue feature macro.

2022-01-12 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/test/Misc/opencl-c-3.0.incorrect_options.cl:21
+
 // CHECK-FP64: error: options cl_khr_fp64 and __opencl_c_fp64 are set to 
different values
 

Anastasia wrote:
> Anastasia wrote:
> > I can't remember if we have discussed this already, but could we use 
> > `-verify` for these errors?
> We should be able to remove `FileCheck` and replace `CHECK` directives with 
> something like:
> `//expected-error@*{{options cl_khr_fp64 and __opencl_c_fp64 are set to 
> different values}}`
I don't think we can test it like this because there is different output for 
each invalid combination, so we need to check them with label.



Comment at: clang/test/SemaOpenCL/invalid-device-enqueue-types-cl3.0.cl:5
+void f() {
+  clk_event_t e;
+  queue_t q;

Anastasia wrote:
> azabaznov wrote:
> > Anastasia wrote:
> > > I know that many test have prefix "invalid" but I feel we have failed to 
> > > establish the meaning for it because most of the tests in Sema are 
> > > testing some sort of invalid behavior. But also here I feel that we 
> > > should test that `enqueue_kernel` is not supported?
> > > 
> > > Do you think we chould merge this testing together with 
> > > `SemaOpenCL/cl20-device-side-enqueue.cl` with some filename renaming?
> > > 
> > > Technically we should do the same testing even for CL1.x versions...
> > I think it can. But `enqueu_kernel` is a `LangBuiltin` and still not 
> > supported yet. Support for `LangBuiltins`  is going to be added in a 
> > separate patch: with this patch all of the features that affect language 
> > built-ins are supported.
> Ok, then would it still work if we merge this functionality 
> `SemaOpenCL/cl20-device-side-enqueue.cl` and the rest can be added later on...
It's difficult to refactor that test, since it relies on the fact that device 
enqueue feature is supported and checks for incorrect constructs. We can't 
enable it for 3.0 now since language built-ins  (`enqueue_kernel` etc.) are not 
supported yet.



Comment at: clang/test/SemaOpenCL/storageclass.cl:2
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 
-cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 
-cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 
-cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 
-cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes,-__opencl_c_device_enqueue
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 
-cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes,-__opencl_c_device_enqueue

Anastasia wrote:
> Anastasia wrote:
> > These lines are getting a bit longer. Do we actually need to set 
> > `-__opencl_c_device_enqueue` for this test? Same for some other tests...
> ping
Yeah, we need that here because we are turning off generic AS and PSV in this 
test. Note that `__opencl_c_device_enqueue` is turned off with `-cl-ext=-all`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115640

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


[PATCH] D115640: [OpenCL] Add support of __opencl_c_device_enqueue feature macro.

2022-01-12 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 399269.
azabaznov added a comment.

Rebase, remove extra 'verify'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115640

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Headers/opencl-c.h
  clang/lib/Sema/Sema.cpp
  clang/test/CodeGenOpenCL/address-spaces-mangling.cl
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/blocks.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/pipe_types_mangling.cl
  clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
  clang/test/Frontend/opencl.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/invalid-block.cl
  clang/test/SemaOpenCL/invalid-device-enqueue-types-cl3.0.cl
  clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
  clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
  clang/test/SemaOpenCL/storageclass.cl
  clang/test/SemaOpenCLCXX/remove-address-space.clcpp

Index: clang/test/SemaOpenCLCXX/remove-address-space.clcpp
===
--- clang/test/SemaOpenCLCXX/remove-address-space.clcpp
+++ clang/test/SemaOpenCLCXX/remove-address-space.clcpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify
 // RUN: %clang_cc1 %s -cl-std=clc++2021 -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify
-// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_device_enqueue,-__opencl_c_generic_address_space,-__opencl_c_pipes -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify
 
 // expected-no-diagnostics
 
Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all,+__opencl_c_program_scope_global_variables
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all,+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all,+__opencl_c_program_scope_global_variables
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all,+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 static constant int G1 = 0;
 constant int G2 = 0;
 
Index: clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -1,9 +1,9 @@
 // RU

[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-01-12 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence updated this revision to Diff 399270.
achieveartificialintelligence added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

Files:
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoD.td
  llvm/lib/Target/RISCV/RISCVInstrInfoF.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td
  llvm/lib/Target/RISCV/RISCVRegisterInfo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32i-invalid.s
  llvm/test/MC/RISCV/rv32zdinx-invalid.s
  llvm/test/MC/RISCV/rv32zdinx-valid.s
  llvm/test/MC/RISCV/rv32zfinx-invalid.s
  llvm/test/MC/RISCV/rv32zfinx-valid.s
  llvm/test/MC/RISCV/rv32zhinx-invalid.s
  llvm/test/MC/RISCV/rv32zhinx-valid.s
  llvm/test/MC/RISCV/rv32zhinxmin-invalid.s
  llvm/test/MC/RISCV/rv32zhinxmin-valid.s
  llvm/test/MC/RISCV/rv64zdinx-invalid.s
  llvm/test/MC/RISCV/rv64zdinx-valid.s
  llvm/test/MC/RISCV/rv64zfinx-invalid.s
  llvm/test/MC/RISCV/rv64zfinx-valid.s
  llvm/test/MC/RISCV/rv64zhinx-invalid.s
  llvm/test/MC/RISCV/rv64zhinx-valid.s
  llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
  llvm/test/MC/RISCV/rv64zhinxmin-valid.s
  llvm/test/MC/RISCV/rvzdinx-aliases-valid.s
  llvm/test/MC/RISCV/rvzfinx-aliases-valid.s
  llvm/test/MC/RISCV/rvzhinx-aliases-valid.s

Index: llvm/test/MC/RISCV/rvzhinx-aliases-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvzhinx-aliases-valid.s
@@ -0,0 +1,82 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+zhinx -riscv-no-aliases \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+zhinx \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+zhinx -riscv-no-aliases \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+zhinx \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+zhinx -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+zhinx - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+zhinx -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+zhinx - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+
+##===--===##
+## Assembler Pseudo Instructions (User-Level ISA, Version 2.2, Chapter 20)
+##===--===##
+
+# CHECK-INST: fsgnjx.h s1, s2, s2
+# CHECK-ALIAS: fabs.h s1, s2
+fabs.h s1, s2
+# CHECK-INST: fsgnjn.h s2, s3, s3
+# CHECK-ALIAS: fneg.h s2, s3
+fneg.h s2, s3
+
+# CHECK-INST: flt.h tp, s6, s5
+# CHECK-ALIAS: flt.h tp, s6, s5
+fgt.h x4, s5, s6
+# CHECK-INST: fle.h t2, s1, s0
+# CHECK-ALIAS: fle.h t2, s1, s0
+fge.h x7, x8, x9
+
+##===--===##
+## Aliases which omit the rounding mode.
+##===--===##
+
+# CHECK-INST: fmadd.h a0, a1, a2, a3, dyn
+# CHECK-ALIAS: fmadd.h a0, a1, a2, a3
+fmadd.h x10, x11, x12, x13
+# CHECK-INST: fmsub.h a4, a5, a6, a7, dyn
+# CHECK-ALIAS: fmsub.h a4, a5, a6, a7
+fmsub.h x14, x15, x16, x17
+# CHECK-INST: fnmsub.h s2, s3, s4, s5, dyn
+# CHECK-ALIAS: fnmsub.h s2, s3, s4, s5
+fnmsub.h x18, x19, x20, x21
+# CHECK-INST: fnmadd.h s6, s7, s8, s9, dyn
+# CHECK-ALIAS: fnmadd.h s6, s7, s8, s9
+fnmadd.h x22, x23, x24, x25
+# CHECK-INST: fadd.h s10, s11, t3, dyn
+# CHECK-ALIAS: fadd.h s10, s11, t3
+fadd.h x26, x27, x28
+# CHECK-INST: fsub.h t4, t5, t6, dyn
+# CHECK-ALIAS: fsub.h t4, t5, t6
+fsub.h x29, x30, x31
+# CHECK-INST: fmul.h s0, s1, s2, dyn
+# CHECK-ALIAS: fmul.h s0, s1, s2
+fmul.h s0, s1, s2
+# CHECK-INST: fdiv.h s3, s4, s5, dyn
+# CHECK-ALIAS: fdiv.h s3, s4, s5
+fdiv.h s3, s4, s5
+# CHECK-INST: fsqrt.h s6, s7, dyn
+# CHECK-ALIAS: fsqrt.h s6, s7
+fsqrt.h s6, s7
+# CHECK-INST: fcvt.w.h a0, s5, dyn
+# CHECK-ALIAS: fcvt.w.h a0, s5
+fcvt.w.h a0, s5
+# CHECK-INST: fcvt.wu.h a1, s6, dyn
+# CHECK-ALIAS: fcvt.wu.h a1, s6
+fcvt.wu.h a1, s6
+# CHECK-INST: fcvt.h.w t6, a4, dyn
+# CHECK-ALIAS: fcvt.h.w t6, a4
+fcvt.h.w t6, a4
+# CHECK-INST: fcvt.h.wu s0, a5, dyn
+# CHECK-ALIAS: fcvt.h.wu s0, a5
+fcvt.h.wu s0, a5
Index: llvm/test/MC/RISCV/rvzfinx-aliases-valid.s

[PATCH] D116904: Fix build failure with MSVC in C++20 mode

2022-01-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks! Much nicer :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116904

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


[PATCH] D116221: [AArch64][ARM][Clang] Unaligned Access Warning Added

2022-01-12 Thread Mubashar Ahmad via Phabricator via cfe-commits
mubashar_ updated this revision to Diff 399271.
mubashar_ set the repository for this revision to rG LLVM Github Monorepo.
mubashar_ added a comment.

Windows tests are now expected to fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116221

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.h
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Sema/test-wunaligned-access.c
  clang/test/Sema/test-wunaligned-access.cpp

Index: clang/test/Sema/test-wunaligned-access.cpp
===
--- /dev/null
+++ clang/test/Sema/test-wunaligned-access.cpp
@@ -0,0 +1,297 @@
+// RUN: %clang_cc1 %s -triple=armv7-none-none-eabi -verify -Wunaligned-access -S -emit-llvm -o %t
+// REQUIRES: arm-registered-target
+//
+// This test suite tests the warning triggered by the -Wunaligned-access option.
+// The warning occurs when a struct or other type of record contains a field
+// that is itself a record. The outer record must be a packed structure, while
+// while the inner record must be unpacked. This is the fundamental condition
+// for the warning to be triggered. Some of these tests may have three layers.
+//
+// The command line option -fsyntax-only is not used as Clang needs to be
+// forced to layout the structs used in this test.
+// The triple in the command line above is used for the assumptions about
+// size and alignment of types.
+
+// Packed-Unpacked Tests (No Pragma)
+
+struct T1 {
+  char a;
+  int b;
+};
+
+struct __attribute__((packed)) U1
+{
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'U1' has an alignment greater than its parent this may be caused by 'U1' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+struct __attribute__((packed)) U2
+{
+  char a;
+  T1 b __attribute__((aligned(4)));
+  int c;
+};
+
+struct __attribute__((packed)) U3
+{
+  char a;
+  char b;
+  short c;
+  T1 d;
+};
+
+struct __attribute__((packed)) U4
+{
+  T1 a;
+  int b;
+};
+
+struct __attribute__((aligned(4), packed)) U5
+{
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'U5' has an alignment greater than its parent this may be caused by 'U5' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+struct __attribute__((aligned(4), packed)) U6
+{
+  char a;
+  char b;
+  short c;
+  T1 d;
+};
+
+// Packed-Unpacked Tests with Pragma
+
+#pragma pack(push, 1)
+
+struct __attribute__((packed)) U7
+{
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'U7' has an alignment greater than its parent this may be caused by 'U7' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+struct __attribute__((packed)) U8 {
+  char a;
+  T1 b __attribute__((aligned(4))); // expected-warning {{field b within its parent 'U8' has an alignment greater than its parent this may be caused by 'U8' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+struct __attribute__((aligned(4))) U9 {
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'U9' has an alignment greater than its parent this may be caused by 'U9' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+struct U10 {
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'U10' has an alignment greater than its parent this may be caused by 'U10' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+#pragma pack(pop)
+
+// Packed-Packed Tests
+
+struct __attribute__((packed)) T2 {
+  char a;
+  int b;
+};
+
+struct __attribute__((packed)) U11 {
+  char a;
+  T2 b;
+  int c;
+};
+
+#pragma pack(push, 1)
+struct U12
+{
+  char a;
+  T2 b;
+  int c;
+};
+#pragma pack(pop)
+
+// Unpacked-Packed Tests
+
+struct U13
+{
+  char a;
+  T2 b;
+  int c;
+};
+
+struct U14
+{
+  char a;
+  T2 b __attribute__((aligned(4)));
+  int c;
+};
+
+// Unpacked-Unpacked Test
+
+struct T3 {
+  char a;
+  int b;
+};
+
+struct U15
+{
+  char a;
+  T3 b;
+  int c;
+};
+
+// Packed-Packed-Unpacked Test (No pragma)
+
+struct __attribute__((packed)) A1 {
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'A1' has an alignment greater than its parent this may be caused by 'A1' being packed and can lead to unaligned accesses}}
+};
+
+struct __attribute__((packed)) U16
+{
+  char a;
+  A1 b;
+  int c;
+};
+
+struct __attribute__((packed)) A2
+{
+  char a;
+  T1 b __attribute__((aligned(4)));
+};
+
+struct __attribute__((packed)) U17
+{
+  char a;
+  A2 b; // expected-warning {{field b within its parent 'U17' has an alignment greater than its parent this may be caused by 'U17' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+// Packed-Unpacked-Packed tests
+
+struct A

[clang-tools-extra] 35cca45 - Misleading bidirectional detection

2022-01-12 Thread via cfe-commits

Author: serge-sans-paille
Date: 2022-01-12T11:38:36+01:00
New Revision: 35cca45b09b87cc31cda35a66fc93bf4d630f8d2

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

LOG: Misleading bidirectional detection

This patch implements detection of incomplete bidirectional sequence withing
comments and string literals within clang-tidy.

It detects the bidi part of https://www.trojansource.codes/trojan-source.pdf

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

Added: 
clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.h
clang-tools-extra/docs/clang-tidy/checks/misc-misleading-bidirectional.rst
clang-tools-extra/test/clang-tidy/checkers/misc-misleading-bidirectional.cpp

Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 22213481619c5..9c827e632cd7e 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
 add_clang_library(clangTidyMiscModule
   DefinitionsInHeadersCheck.cpp
   MiscTidyModule.cpp
+  MisleadingBidirectional.cpp
   MisleadingIdentifier.cpp
   MisplacedConstCheck.cpp
   NewDeleteOverloadsCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp 
b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
index 2defecc60741a..ef8a20683d39a 100644
--- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "DefinitionsInHeadersCheck.h"
+#include "MisleadingBidirectional.h"
 #include "MisleadingIdentifier.h"
 #include "MisplacedConstCheck.h"
 #include "NewDeleteOverloadsCheck.h"
@@ -34,6 +35,8 @@ class MiscModule : public ClangTidyModule {
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck(
 "misc-definitions-in-headers");
+CheckFactories.registerCheck(
+"misc-misleading-bidirectional");
 CheckFactories.registerCheck(
 "misc-misleading-identifier");
 CheckFactories.registerCheck("misc-misplaced-const");

diff  --git a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp 
b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
new file mode 100644
index 0..7cd6fc338695c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
@@ -0,0 +1,139 @@
+//===--- MisleadingBidirectional.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MisleadingBidirectional.h"
+
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/Support/ConvertUTF.h"
+
+using namespace clang;
+using namespace clang::tidy::misc;
+
+static bool containsMisleadingBidi(StringRef Buffer,
+   bool HonorLineBreaks = true) {
+  const char *CurPtr = Buffer.begin();
+
+  enum BidiChar {
+PS = 0x2029,
+RLO = 0x202E,
+RLE = 0x202B,
+LRO = 0x202D,
+LRE = 0x202A,
+PDF = 0x202C,
+RLI = 0x2067,
+LRI = 0x2066,
+FSI = 0x2068,
+PDI = 0x2069
+  };
+
+  SmallVector BidiContexts;
+
+  // Scan each character while maintaining a stack of opened bidi context.
+  // RLO/RLE/LRO/LRE all are closed by PDF while RLI LRI and FSI are closed by
+  // PDI. New lines reset the context count. Extra PDF / PDI are ignored.
+  //
+  // Warn if we end up with an unclosed context.
+  while (CurPtr < Buffer.end()) {
+unsigned char C = *CurPtr;
+if (isASCII(C)) {
+  ++CurPtr;
+  bool IsParagrapSep =
+  (C == 0xA || C == 0xD || (0x1C <= C && C <= 0x1E) || C == 0x85);
+  bool IsSegmentSep = (C == 0x9 || C == 0xB || C == 0x1F);
+  if (IsParagrapSep || IsSegmentSep)
+BidiContexts.clear();
+  continue;
+}
+llvm::UTF32 CodePoint;
+llvm::ConversionResult Result = llvm::convertUTF8Sequence(
+(const llvm::UTF8 **)&CurPtr, (const llvm::UTF8 *)Buffer.end(),
+&CodePoint, llvm::strictConversion);
+
+// If conversion fails, utf-8 is designed so that we can just try next 
char.
+

[PATCH] D112913: Misleading bidirectional detection

2022-01-12 Thread serge 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 rG35cca45b09b8: Misleading bidirectional detection (authored 
by serge-sans-paille).

Changed prior to commit:
  https://reviews.llvm.org/D112913?vs=398195&id=399273#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112913

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
  clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-misleading-bidirectional.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-misleading-bidirectional.cpp

Index: clang-tools-extra/docs/clang-tidy/checks/misc-misleading-bidirectional.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-misleading-bidirectional.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - misc-misleading-bidirectional
+
+misc-misleading-bidirectional
+=
+
+Warn about unterminated bidirectional unicode sequence, detecting potential attack
+as described in the `Trojan Source `_ attack.
+
+Example:
+
+.. code-block:: c++
+
+#include 
+
+int main() {
+bool isAdmin = false;
+/*‮ } ⁦if (isAdmin)⁩ ⁦ begin admins only */
+std::cout << "You are an admin.\n";
+/* end admins only ‮ { ⁦*/
+return 0;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -212,7 +212,8 @@
`llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
-   `misc-misleading-identifier `_,
+   `misc-misleading-bidirectional `_,
+   `misc-misleading-identifier `_,
`misc-misplaced-const `_,
`misc-new-delete-overloads `_,
`misc-no-recursion `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -127,6 +127,10 @@
   Reports identifiers whose names are too short. Currently checks local
   variables and function parameters only.
 
+- New :doc:`misc-misleading-bidirectional ` check.
+
+  Inspects string literal and comments for unterminated bidirectional Unicode
+  characters.
 
 New check aliases
 ^
Index: clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.h
@@ -0,0 +1,38 @@
+//===--- MisleadingBidirectionalCheck.h - clang-tidy *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISLEADINGBIDIRECTIONALCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISLEADINGBIDIRECTIONALCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+class MisleadingBidirectionalCheck : public ClangTidyCheck {
+public:
+  MisleadingBidirectionalCheck(StringRef Name, ClangTidyContext *Context);
+  ~MisleadingBidirectionalCheck();
+
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  class MisleadingBidirectionalHandler;
+  std::unique_ptr Handler;
+};
+
+} // namespace misc
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISLEADINGBIDIRECTIONALCHECK_H
Index: clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
@@ -0,0 +1,139 @@
+//===--- MisleadingBidirectional.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+/

[PATCH] D116919: [AST] Add RParen loc for decltype AutoTypeloc.

2022-01-12 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

Ok, now I managed to make a standalone reproducer: 
https://martin.st/temp/pch-preproc.hxx and 
https://martin.st/temp/main-preproc.cpp

  $ bin/clang -target x86_64-w64-mingw32 -w -x c++-header -c pch-preproc.hxx -o 
pch-preproc.hxx.pch -std=c++17 -O3
  $ bin/clang -target x86_64-w64-mingw32 -w -Xclang -include-pch -Xclang 
pch-preproc.hxx.pch -c main-preproc.cpp -std=c++17 -O3


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116919

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


[PATCH] D116659: [llvm][clang][vfs] NFC: Extract directory iteration boilerplate into macro

2022-01-12 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 399275.
jansvoboda11 added a comment.
Herald added a subscriber: hiraditya.

Replace macro with range of new iterators


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116659

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  llvm/include/llvm/Support/VirtualFileSystem.h
  llvm/lib/Support/VirtualFileSystem.cpp

Index: llvm/lib/Support/VirtualFileSystem.cpp
===
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -128,6 +128,13 @@
   return (*F)->getBuffer(Name, FileSize, RequiresNullTerminator, IsVolatile);
 }
 
+iterator_range
+FileSystem::dir_range(const Twine &Dir) {
+  std::error_code EC;
+  return {directory_iterator_error_wrapper(dir_begin(Dir, EC), EC),
+  directory_iterator_error_wrapper()};
+}
+
 std::error_code FileSystem::makeAbsolute(SmallVectorImpl &Path) const {
   if (llvm::sys::path::is_absolute(Path))
 return {};
Index: llvm/include/llvm/Support/VirtualFileSystem.h
===
--- llvm/include/llvm/Support/VirtualFileSystem.h
+++ llvm/include/llvm/Support/VirtualFileSystem.h
@@ -202,6 +202,38 @@
   }
 };
 
+/// Wrapper for directory_iterator that automatically handles error codes.
+class directory_iterator_error_wrapper {
+  directory_iterator It;
+
+public:
+  directory_iterator_error_wrapper(directory_iterator It, std::error_code &EC)
+  : It(std::move(It)) {
+if (EC)
+  It = directory_iterator();
+  }
+
+  directory_iterator_error_wrapper() = default;
+
+  directory_iterator_error_wrapper &operator++() {
+std::error_code EC;
+It.increment(EC);
+if (EC)
+  It = directory_iterator();
+return *this;
+  }
+
+  const directory_entry &operator*() const { return *It; }
+  const directory_entry *operator->() const { return &*It; }
+
+  bool operator==(const directory_iterator_error_wrapper &RHS) const {
+return It == RHS.It;
+  }
+  bool operator!=(const directory_iterator_error_wrapper &RHS) const {
+return !(*this == RHS);
+  }
+};
+
 class FileSystem;
 
 namespace detail {
@@ -274,6 +306,9 @@
   virtual directory_iterator dir_begin(const Twine &Dir,
std::error_code &EC) = 0;
 
+  /// Get a directory_iterator range for \p Dir.
+  iterator_range dir_range(const Twine &Dir);
+
   /// Set the working directory. This will affect all following operations on
   /// this file system and may propagate down for nested file systems.
   virtual std::error_code setCurrentWorkingDirectory(const Twine &Path) = 0;
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -9896,20 +9896,18 @@
 const bool isQt = Dirname.startswith("Qt") || Dirname == "ActiveQt";
 const bool ExtensionlessHeaders =
 IsSystem || isQt || Dir.endswith(".framework/Headers");
-std::error_code EC;
 unsigned Count = 0;
-for (auto It = FS.dir_begin(Dir, EC);
- !EC && It != llvm::vfs::directory_iterator(); It.increment(EC)) {
+for (const auto &Entry : FS.dir_range(Dir)) {
   if (++Count == 2500) // If we happen to hit a huge directory,
 break; // bail out early so we're not too slow.
-  StringRef Filename = llvm::sys::path::filename(It->path());
+  StringRef Filename = llvm::sys::path::filename(Entry.path());
 
   // To know whether a symlink should be treated as file or a directory, we
   // have to stat it. This should be cheap enough as there shouldn't be many
   // symlinks.
-  llvm::sys::fs::file_type Type = It->type();
+  llvm::sys::fs::file_type Type = Entry.type();
   if (Type == llvm::sys::fs::file_type::symlink_file) {
-if (auto FileStatus = FS.status(It->path()))
+if (auto FileStatus = FS.status(Entry.path()))
   Type = FileStatus->getType();
   }
   switch (Type) {
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -1057,21 +1057,16 @@
   Result->InferExportWildcard = true;
 
   // Look for subframeworks.
-  std::error_code EC;
   SmallString<128> SubframeworksDirName
 = StringRef(FrameworkDir->getName());
   llvm::sys::path::append(SubframeworksDirName, "Frameworks");
   llvm::sys::path::native(Subframewor

[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

It looks like this may be causing the following bot to fail 
https://lab.llvm.org/buildbot/#/builders/16/builds/22138 with

   TEST 'lld :: COFF/lto-lazy-reference.ll' FAILED 

  Script:
  --
  : 'RUN: at line 2';   
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc 
-mtriple=i686-pc-windows-msvc -filetype=obj -o 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference-quadruple.obj
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/COFF/Inputs/lto-lazy-reference-quadruple.ll
  : 'RUN: at line 3';   
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-as -o 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference-dummy.bc
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/COFF/Inputs/lto-lazy-reference-dummy.ll
  : 'RUN: at line 4';   rm -f 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.lib
  : 'RUN: at line 5';   llvm-ar cru 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.lib
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference-quadruple.obj
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference-dummy.bc
  : 'RUN: at line 6';   
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-as -o 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.obj
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/COFF/lto-lazy-reference.ll
  : 'RUN: at line 7';   
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/lld-link 
/out:/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.exe
 /entry:main /subsystem:console 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.obj
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.lib
  --
  Exit Code: 134
  Command Output (stderr):
  --
  + : 'RUN: at line 2'
  + /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc 
-mtriple=i686-pc-windows-msvc -filetype=obj -o 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference-quadruple.obj
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/COFF/Inputs/lto-lazy-reference-quadruple.ll
  + : 'RUN: at line 3'
  + /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-as -o 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference-dummy.bc
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/COFF/Inputs/lto-lazy-reference-dummy.ll
  + : 'RUN: at line 4'
  + rm -f 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.lib
  + : 'RUN: at line 5'
  + llvm-ar cru 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.lib
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference-quadruple.obj
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference-dummy.bc
  + : 'RUN: at line 6'
  + /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-as -o 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.obj
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/COFF/lto-lazy-reference.ll
  + : 'RUN: at line 7'
  + /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/lld-link 
/out:/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.exe
 /entry:main /subsystem:console 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.obj
 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.lib
  lld-link: 
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/lib/CodeGen/MachineFunction.cpp:207:
 void llvm::MachineFunction::init(): Assertion 
`Target.isCompatibleDataLayout(getDataLayout()) && "Can't create a 
MachineFunction using a Module with a " "Target-incompatible DataLayout 
attached\n"' failed.
  
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.script:
 line 6: 2469401 Aborted 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/lld-link 
/out:/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/Output/lto-lazy-reference.ll.tmp.exe
 /entry:main /subsystem:console 
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/COFF/O

[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Thanks @fhahn ! I saw the failure. I think it just needs to update the 
datalayout in the lit tests. I am checking on this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

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


[PATCH] D116659: [llvm][clang][vfs] NFC: Simplify directory iteration

2022-01-12 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

I agree that introducing new iterator and implementing `iterator_range<...> 
FileSystem::dir_range()` is better solution than a macro.

I'm not sure the `dir_range` function needs to take an `std::error_code` 
out-param though. The error code is only used to stop the iteration, clients 
don't use it for any other purpose. I think the new iterator could handle error 
codes completely internally (by advancing to the end), providing better 
ergonomics. WDYT?

I might create a follow-up patches for //recursive// VFS-based iteration and 
also enable range-based for loops in code using `llvm::sys::fs` instead of the 
VFS.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116659

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


[PATCH] D115501: [clang][ARM] Emit warnings when PACBTI-M is used with unsupported architectures

2022-01-12 Thread Momchil Velikov via Phabricator via cfe-commits
chill added inline comments.



Comment at: clang/lib/Basic/Targets/ARM.cpp:387
+
+  return a.isArmT32();
+}

For example Arm7-a defines the T32 instruction set, buy we still want a warning.
Maybe we need `return a.isArmT32() &&  a.isArmMClass()`.
I'm not actually sure whether the triple correctly reflects the target 
instruction set, e.g.
what are we going to get from `-target arm-eabi -march=armv7-a -mthumb`, so the 
approach with
the target triple might not be working.




Comment at: clang/lib/CodeGen/TargetInfo.cpp:6402
+ CGM.getLangOpts().hasSignReturnAddress() ||
+ CGM.getLangOpts().isSignReturnAddressScopeAll()) {
+// If the Branch Protection attribute is missing, validate the target

This condition `CGM.getLangOpts().isSignReturnAddressScopeAll()` is redundant.



Comment at: llvm/include/llvm/ADT/Triple.h:724
 
+  /// Tests whether the target is T32.
+  bool isArmT32() const {

This function does not look quite as expected.

`!isARM()` might be `isThumb()` but we're going to return false, isn't it ?

Then `isThumb()` might be true while we have, say, `armv6k`.

AFAICT, the test (and probably the whole function) ought to be

```
  switch (auto SubArch = getSubArch()) {
  case Triple::ARMSubArch_v8m_baseline,
  case Triple::ARMSubArch_v7s:
  case Triple::ARMSubArch_v7k:
  case Triple::ARMSubArch_v7ve:
  case Triple::ARMSubArch_v6:
  case Triple::ARMSubArch_v6m:
  case Triple::ARMSubArch_v6k:
  case Triple::ARMSubArch_v6t2:
  case Triple::ARMSubArch_v5:
  case Triple::ARMSubArch_v5te:
  case Triple::ARMSubArch_v4t:
return false;
  default:
  return true;
   }
```

which is pretty future-proof.





Comment at: llvm/include/llvm/ADT/Triple.h:725
+  /// Tests whether the target is T32.
+  bool isArmT32() const {
+if (!isARM())

In any case, if we're going to change the `Triple`, it should come with unit 
tests in `unittest/ADT/TripleTest.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115501

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


[PATCH] D116994: [RISCV] Add bfp and bfpw intrinsic in zbf extension

2022-01-12 Thread WangLian via Phabricator via cfe-commits
Jimerlife updated this revision to Diff 399281.
Jimerlife added a comment.
Herald added a subscriber: jacquesguan.

format code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116994

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbf.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbf.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
  llvm/test/CodeGen/RISCV/rv32zbf-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv64zbf-intrinsic.ll

Index: llvm/test/CodeGen/RISCV/rv64zbf-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rv64zbf-intrinsic.ll
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbf -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV64ZBF
+
+declare i32 @llvm.riscv.bfp.i32(i32 %a, i32 %b)
+
+define i32 @bfp32(i32 %a, i32 %b) nounwind {
+; RV64ZBF-LABEL: bfp32:
+; RV64ZBF:   # %bb.0:
+; RV64ZBF-NEXT:bfpw a0, a0, a1
+; RV64ZBF-NEXT:ret
+  %tmp = call i32 @llvm.riscv.bfp.i32(i32 %a, i32 %b)
+ ret i32 %tmp
+}
+
+declare i64 @llvm.riscv.bfp.i64(i64 %a, i64 %b)
+
+define i64 @bfp64(i64 %a, i64 %b) nounwind {
+; RV64ZBF-LABEL: bfp64:
+; RV64ZBF:   # %bb.0:
+; RV64ZBF-NEXT:bfp a0, a0, a1
+; RV64ZBF-NEXT:ret
+  %tmp = call i64 @llvm.riscv.bfp.i64(i64 %a, i64 %b)
+ ret i64 %tmp
+}
Index: llvm/test/CodeGen/RISCV/rv32zbf-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rv32zbf-intrinsic.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbf -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV32ZBF
+
+declare i32 @llvm.riscv.bfp.i32(i32 %a, i32 %b)
+
+define i32 @bfp32(i32 %a, i32 %b) nounwind {
+; RV32ZBF-LABEL: bfp32:
+; RV32ZBF:   # %bb.0:
+; RV32ZBF-NEXT:bfp a0, a0, a1
+; RV32ZBF-NEXT:ret
+  %tmp = call i32 @llvm.riscv.bfp.i32(i32 %a, i32 %b)
+ ret i32 %tmp
+}
Index: llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
@@ -43,6 +43,8 @@
 def riscv_shflw  : SDNode<"RISCVISD::SHFLW",  SDT_RISCVIntBinOpW>;
 def riscv_unshfl : SDNode<"RISCVISD::UNSHFL", SDTIntBinOp>;
 def riscv_unshflw: SDNode<"RISCVISD::UNSHFLW",SDT_RISCVIntBinOpW>;
+def riscv_bfp: SDNode<"RISCVISD::BFP",SDTIntBinOp>;
+def riscv_bfpw   : SDNode<"RISCVISD::BFPW",   SDT_RISCVIntBinOpW>;
 def riscv_bcompress: SDNode<"RISCVISD::BCOMPRESS",   SDTIntBinOp>;
 def riscv_bcompressw   : SDNode<"RISCVISD::BCOMPRESSW",  SDT_RISCVIntBinOpW>;
 def riscv_bdecompress  : SDNode<"RISCVISD::BDECOMPRESS", SDTIntBinOp>;
@@ -1127,3 +1129,9 @@
 def : PatGpr;
 def : PatGpr;
 } // Predicates = [HasStdExtZbr, IsRV64]
+
+let Predicates = [HasStdExtZbf] in
+def : PatGprGpr;
+
+let Predicates = [HasStdExtZbf, IsRV64] in
+def : PatGprGpr;
Index: llvm/lib/Target/RISCV/RISCVISelLowering.h
===
--- llvm/lib/Target/RISCV/RISCVISelLowering.h
+++ llvm/lib/Target/RISCV/RISCVISelLowering.h
@@ -120,6 +120,13 @@
   BCOMPRESSW,
   BDECOMPRESS,
   BDECOMPRESSW,
+  // The bit field place (bfp) instruction places up to XLEN/2 LSB bits from rs2
+  // into the value in rs1. The upper bits of rs2 control the length of the bit
+  // field and target position. The layout of rs2 is chosen in a way that makes
+  // it possible to construct rs2 easily using pack[h] instructions and/or
+  // andi/lui.
+  BFP,
+  BFPW,
   // Vector Extension
   // VMV_V_X_VL matches the semantics of vmv.v.x but includes an extra operand
   // for the VL value to be used for the operation.
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -4185,6 +4185,9 @@
: RISCVISD::BDECOMPRESS;
 return DAG.getNode(Opc, DL, XLenVT, Op.getOperand(1), Op.getOperand(2));
   }
+  case Intrinsic::riscv_bfp:
+return DAG.getNode(RISCVISD::BFP, DL, XLenVT, Op.getOperand(1),
+   Op.getOperand(2));
   case Intrinsic::riscv_vmv_x_s:
 assert(Op.getValueType() == XLenVT && "Unexpected VT!");
 return DAG.getNode(RISCVISD::VMV_X_S, DL, Op.getValueType(),
@@ -6275,6 +6278,17 @@
   Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Res));
   break;

[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Should be fixed by rG9b43237128da 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

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


[clang] bf5f235 - [NFC] [Coroutines] Add regression tests for symmetric transfer and coroutine elision

2022-01-12 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2022-01-12T19:39:56+08:00
New Revision: bf5f2354fa6e3f31a1acea75a229fee54359e279

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

LOG: [NFC] [Coroutines] Add regression tests for symmetric transfer and 
coroutine elision

Added: 
clang/test/CodeGenCoroutines/coro-elide.cpp
clang/test/CodeGenCoroutines/coro-symmetric-transfer-03.cpp

Modified: 
clang/test/CodeGenCoroutines/Inputs/coroutine.h

Removed: 




diff  --git a/clang/test/CodeGenCoroutines/Inputs/coroutine.h 
b/clang/test/CodeGenCoroutines/Inputs/coroutine.h
index 7c2d363f8890..4473bcc95c09 100644
--- a/clang/test/CodeGenCoroutines/Inputs/coroutine.h
+++ b/clang/test/CodeGenCoroutines/Inputs/coroutine.h
@@ -1,3 +1,4 @@
+// This is a mock file for .
 #pragma once
 
 namespace std {
@@ -52,20 +53,54 @@ template  struct coroutine_handle : 
coroutine_handle<> {
   }
 };
 
-  template 
-  bool operator==(coroutine_handle<_PromiseT> const& _Left,
-coroutine_handle<_PromiseT> const& _Right) noexcept
-  {
-return _Left.address() == _Right.address();
+template 
+bool operator==(coroutine_handle<_PromiseT> const &_Left,
+coroutine_handle<_PromiseT> const &_Right) noexcept {
+  return _Left.address() == _Right.address();
+}
+
+template 
+bool operator!=(coroutine_handle<_PromiseT> const &_Left,
+coroutine_handle<_PromiseT> const &_Right) noexcept {
+  return !(_Left == _Right);
+}
+
+struct noop_coroutine_promise {};
+
+template <>
+struct coroutine_handle {
+  operator coroutine_handle<>() const noexcept {
+return coroutine_handle<>::from_address(address());
   }
 
-  template 
-  bool operator!=(coroutine_handle<_PromiseT> const& _Left,
-coroutine_handle<_PromiseT> const& _Right) noexcept
-  {
-return !(_Left == _Right);
+  constexpr explicit operator bool() const noexcept { return true; }
+  constexpr bool done() const noexcept { return false; }
+
+  constexpr void operator()() const noexcept {}
+  constexpr void resume() const noexcept {}
+  constexpr void destroy() const noexcept {}
+
+  noop_coroutine_promise &promise() const noexcept {
+return *static_cast(
+__builtin_coro_promise(this->__handle_, 
alignof(noop_coroutine_promise), false));
   }
 
+  constexpr void *address() const noexcept { return __handle_; }
+
+private:
+  friend coroutine_handle noop_coroutine() noexcept;
+
+  coroutine_handle() noexcept {
+this->__handle_ = __builtin_coro_noop();
+  }
+
+  void *__handle_ = nullptr;
+};
+
+using noop_coroutine_handle = coroutine_handle;
+
+inline noop_coroutine_handle noop_coroutine() noexcept { return 
noop_coroutine_handle(); }
+
 struct suspend_always {
   bool await_ready() noexcept { return false; }
   void await_suspend(coroutine_handle<>) noexcept {}

diff  --git a/clang/test/CodeGenCoroutines/coro-elide.cpp 
b/clang/test/CodeGenCoroutines/coro-elide.cpp
new file mode 100644
index ..6fccff424d93
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/coro-elide.cpp
@@ -0,0 +1,63 @@
+// This tests that the coroutine elide optimization could happen succesfully.
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -O2 -emit-llvm 
%s -o - | FileCheck %s
+
+#include "Inputs/coroutine.h"
+
+struct Task {
+  struct promise_type {
+struct FinalAwaiter {
+  bool await_ready() const noexcept { return false; }
+  template 
+  std::coroutine_handle<> await_suspend(std::coroutine_handle 
h) noexcept {
+if (!h)
+  return std::noop_coroutine();
+return h.promise().continuation;
+  }
+  void await_resume() noexcept {}
+};
+Task get_return_object() noexcept {
+  return std::coroutine_handle::from_promise(*this);
+}
+std::suspend_always initial_suspend() noexcept { return {}; }
+FinalAwaiter final_suspend() noexcept { return {}; }
+void unhandled_exception() noexcept {}
+void return_value(int x) noexcept {
+  _value = x;
+}
+std::coroutine_handle<> continuation;
+int _value;
+  };
+
+  Task(std::coroutine_handle handle) : handle(handle) {}
+  ~Task() {
+if (handle)
+  handle.destroy();
+  }
+
+  struct Awaiter {
+bool await_ready() const noexcept { return false; }
+void await_suspend(std::coroutine_handle continuation) noexcept {}
+int await_resume() noexcept {
+  return 43;
+}
+  };
+
+  auto operator co_await() {
+return Awaiter{};
+  }
+
+private:
+  std::coroutine_handle handle;
+};
+
+Task task0() {
+  co_return 43;
+}
+
+Task task1() {
+  co_return co_await task0();
+}
+
+// CHECK: %_Z5task1v.Frame = type {{.*}}%_Z5task0v.Frame
+// CHECK-LABEL: define{{.*}} void @_Z5task1v.resume
+// CHECK-NOT: call{{.*}}_Znwm

diff  --git a/clang/test/CodeGenCoroutines/coro-symmetric-transfer-03.cpp 
b

[clang] 4b85800 - [OpenCL] Set external linkage for block enqueue kernels

2022-01-12 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-01-12T13:30:09Z
New Revision: 4b85800bfd6ca6c3ecedf68ffbba6c3f2bc9c8ae

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

LOG: [OpenCL] Set external linkage for block enqueue kernels

All kernels can be called from the host as per the SPIR_KERNEL calling
convention.  As such, all kernels should have external linkage, but
block enqueue kernels were created with internal linkage.

Reported-by: Pedro Olsen Ferreira

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

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 2bb68ebbfa2a4..77203aee9b6c1 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -11417,7 +11417,7 @@ 
TargetCodeGenInfo::createEnqueuedBlockKernel(CodeGenFunction &CGF,
   auto &C = CGF.getLLVMContext();
   std::string Name = Invoke->getName().str() + "_kernel";
   auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false);
-  auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, 
Name,
+  auto *F = llvm::Function::Create(FT, llvm::GlobalValue::ExternalLinkage, 
Name,
&CGF.CGM.getModule());
   auto IP = CGF.Builder.saveIP();
   auto *BB = llvm::BasicBlock::Create(C, "entry", F);

diff  --git a/clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl 
b/clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
index afae12f7d25aa..361aca85e84c9 100644
--- a/clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ b/clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -402,28 +402,28 @@ kernel void device_side_enqueue(global int *a, global int 
*b, int i) {
   size = get_kernel_sub_group_count_for_ndrange(ndrange, ^(){});
 }
 
-// COMMON: define internal spir_kernel void [[INVLK1]](i8 addrspace(4)* %0) 
#{{[0-9]+}} {
+// COMMON: define spir_kernel void [[INVLK1]](i8 addrspace(4)* %0) #{{[0-9]+}} 
{
 // COMMON: entry:
 // COMMON:  call spir_func void @__device_side_enqueue_block_invoke(i8 
addrspace(4)* %0)
 // COMMON:  ret void
 // COMMON: }
-// COMMON: define internal spir_kernel void [[INVLK2]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK1]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK2]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK3]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK4]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK5]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK6]](i8 addrspace(4)* %0, i8 
addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) #{{[0-9]+}} {
+// COMMON: define spir_kernel void [[INVLK2]](i8 addrspace(4)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK1]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK2]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK3]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK4]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK5]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK6]](i8 addrspace(4)* %0, i8 
addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) #{{[0-9]+}} {
 // COMMON: entry:
 // COMMON:  call spir_func void @__device_side_enqueue_block_invoke_9(i8 
addrspace(4)* %0, i8 addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3)
 // COMMON:  ret void
 // COMMON: }
-// COMMON: define internal spir_kernel void [[INVGK7]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK7]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
 // COMMON: define internal spir_func void [[INVG8]](i8 addrspace(4)*{{.*}})
 // COMMON: define internal spir_func void [[INVG9]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)* %{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK8]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INV_G_K]](i8 
addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVLK3]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK9]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK10]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK11]](i8 addrspace(4)*

[PATCH] D115523: [OpenCL] Set external linkage for block enqueue kernels

2022-01-12 Thread Sven van Haastregt 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 rG4b85800bfd6c: [OpenCL] Set external linkage for block 
enqueue kernels (authored by svenvh).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115523

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl


Index: clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -402,28 +402,28 @@
   size = get_kernel_sub_group_count_for_ndrange(ndrange, ^(){});
 }
 
-// COMMON: define internal spir_kernel void [[INVLK1]](i8 addrspace(4)* %0) 
#{{[0-9]+}} {
+// COMMON: define spir_kernel void [[INVLK1]](i8 addrspace(4)* %0) #{{[0-9]+}} 
{
 // COMMON: entry:
 // COMMON:  call spir_func void @__device_side_enqueue_block_invoke(i8 
addrspace(4)* %0)
 // COMMON:  ret void
 // COMMON: }
-// COMMON: define internal spir_kernel void [[INVLK2]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK1]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK2]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK3]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK4]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK5]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK6]](i8 addrspace(4)* %0, i8 
addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) #{{[0-9]+}} {
+// COMMON: define spir_kernel void [[INVLK2]](i8 addrspace(4)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK1]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK2]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK3]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK4]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK5]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK6]](i8 addrspace(4)* %0, i8 
addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) #{{[0-9]+}} {
 // COMMON: entry:
 // COMMON:  call spir_func void @__device_side_enqueue_block_invoke_9(i8 
addrspace(4)* %0, i8 addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3)
 // COMMON:  ret void
 // COMMON: }
-// COMMON: define internal spir_kernel void [[INVGK7]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK7]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
 // COMMON: define internal spir_func void [[INVG8]](i8 addrspace(4)*{{.*}})
 // COMMON: define internal spir_func void [[INVG9]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)* %{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK8]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INV_G_K]](i8 
addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVLK3]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK9]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK10]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK11]](i8 addrspace(4)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK8]](i8 addrspace(4)*{{.*}})
+// COMMON: define spir_kernel void [[INV_G_K]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVLK3]](i8 addrspace(4)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK9]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK10]](i8 addrspace(4)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK11]](i8 addrspace(4)*{{.*}})
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -11417,7 +11417,7 @@
   auto &C = CGF.getLLVMContext();
   std::string Name = Invoke->getName().str() + "_kernel";
   auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false);
-  auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, 
Name,
+  auto *F = llvm::Function::Create(FT, llvm::GlobalValue::ExternalLinkage, 
Name,
&CGF.CGM.getModule());
   auto IP = CGF.Builder.saveIP();
   auto *BB = llvm::BasicBlock::Create(C, "entry", F);


Index: clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
==

[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

2022-01-12 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

In D27800#3235066 , @efriedma wrote:

> Looks like all the review comments have been addressed.  LGTM

Thanks for the review, but unfortunately I found an issue right before 
committing, taking a look at it now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D27800

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


[PATCH] D114724: [clangd][StdSymbolMap] Prefer std::remove from algorithm

2022-01-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 399300.
kadircet marked 5 inline comments as done.
kadircet added a comment.

- Change the variant acception mechanism to work with specific variants.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114724

Files:
  clang-tools-extra/clangd/StdSymbolMap.inc
  clang-tools-extra/clangd/include-mapping/cppreference_parser.py


Index: clang-tools-extra/clangd/include-mapping/cppreference_parser.py
===
--- clang-tools-extra/clangd/include-mapping/cppreference_parser.py
+++ clang-tools-extra/clangd/include-mapping/cppreference_parser.py
@@ -103,7 +103,9 @@
 # This accidentally accepts begin/end despite the (iterator) caption: the
 # (since C++11) note is first. They are good symbols, so the bug is 
unfixed.
 caption = symbol_href.next_sibling
-variant = isinstance(caption, NavigableString) and "(" in caption
+variant = None
+if isinstance(caption, NavigableString) and "(" in caption:
+  variant = caption.text.strip(" ()")
 symbol_tt = symbol_href.find("tt")
 if symbol_tt:
   symbols.append((symbol_tt.text.rstrip("<>()"), # strip any trailing <>()
@@ -116,7 +118,7 @@
 return _ParseSymbolPage(f.read(), name)
 
 
-def _GetSymbols(pool, root_dir, index_page_name, namespace):
+def _GetSymbols(pool, root_dir, index_page_name, namespace, 
variants_to_accept):
   """Get all symbols listed in the index page. All symbols should be in the
   given namespace.
 
@@ -135,7 +137,9 @@
 for symbol_name, symbol_page_path, variant in _ParseIndexPage(f.read()):
   # Variant symbols (e.g. the std::locale version of isalpha) add 
ambiguity.
   # FIXME: use these as a fallback rather than ignoring entirely.
-  if variant:
+  variants_for_symbol = variants_to_accept.get(
+  (namespace or "") + symbol_name, ())
+  if variant and variant not in variants_for_symbol:
 continue
   path = os.path.join(root_dir, symbol_page_path)
   results.append((symbol_name,
@@ -158,6 +162,13 @@
   Args:
 parse_pages: a list of tuples (page_root_dir, index_page_name, namespace)
   """
+  # By default we prefer the non-variant versions, as they're more common. But
+  # there are some symbols, whose variant is more common. This list describes
+  # those symbols.
+  variants_to_accept = {
+  # std::remove<> has variant algorithm.
+  "std::remove": ("algorithm"),
+  }
   symbols = []
   # Run many workers to process individual symbol pages under the symbol index.
   # Don't allow workers to capture Ctrl-C.
@@ -165,7 +176,8 @@
   initializer=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN))
   try:
 for root_dir, page_name, namespace in parse_pages:
-  symbols.extend(_GetSymbols(pool, root_dir, page_name, namespace))
+  symbols.extend(_GetSymbols(pool, root_dir, page_name, namespace,
+ variants_to_accept))
   finally:
 pool.terminate()
 pool.join()
Index: clang-tools-extra/clangd/StdSymbolMap.inc
===
--- clang-tools-extra/clangd/StdSymbolMap.inc
+++ clang-tools-extra/clangd/StdSymbolMap.inc
@@ -955,7 +955,6 @@
 SYMBOL(regex_traits, std::, )
 SYMBOL(reinterpret_pointer_cast, std::, )
 SYMBOL(remainder, std::, )
-SYMBOL(remove, std::, )
 SYMBOL(remove_all_extents, std::, )
 SYMBOL(remove_all_extents_t, std::, )
 SYMBOL(remove_const, std::, )


Index: clang-tools-extra/clangd/include-mapping/cppreference_parser.py
===
--- clang-tools-extra/clangd/include-mapping/cppreference_parser.py
+++ clang-tools-extra/clangd/include-mapping/cppreference_parser.py
@@ -103,7 +103,9 @@
 # This accidentally accepts begin/end despite the (iterator) caption: the
 # (since C++11) note is first. They are good symbols, so the bug is unfixed.
 caption = symbol_href.next_sibling
-variant = isinstance(caption, NavigableString) and "(" in caption
+variant = None
+if isinstance(caption, NavigableString) and "(" in caption:
+  variant = caption.text.strip(" ()")
 symbol_tt = symbol_href.find("tt")
 if symbol_tt:
   symbols.append((symbol_tt.text.rstrip("<>()"), # strip any trailing <>()
@@ -116,7 +118,7 @@
 return _ParseSymbolPage(f.read(), name)
 
 
-def _GetSymbols(pool, root_dir, index_page_name, namespace):
+def _GetSymbols(pool, root_dir, index_page_name, namespace, variants_to_accept):
   """Get all symbols listed in the index page. All symbols should be in the
   given namespace.
 
@@ -135,7 +137,9 @@
 for symbol_name, symbol_page_path, variant in _ParseIndexPage(f.read()):
   # Variant symbols (e.g. the std::locale version of isalpha) add ambiguity.
   # FIXME: use these as a fallback rather than ignoring entirely.
-  if variant:
+  variants_for_sy

[PATCH] D117107: [clangd] Elide even more checks in SelectionTree.

2022-01-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

During pop() we convert nodes into spans of expanded syntax::Tokens.
If we precompute a range of plausible (expanded) tokens, then we can do an
extremely cheap approximate hit-test against it, because syntax::Tokens are
ordered by pointer.

This would seem not to buy anything (we don't enter nodes unless they overlap
the selection), but in fact the spans we have are for *newly* claimed ranges
(i.e. those unclaimed by any child node).

So if you have:

  { { [[2+2]]; } }

then all of the CompoundStmts pass the hit test and are pushed, but we skip
full hit-testing of the brackets during pop() as they lie outside the range.

This is ~10x average speedup for selectiontree on a bad case I've seen
(large gtest file).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117107

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -201,6 +201,13 @@
   )cpp",
   nullptr,
   },
+  {
+  R"cpp(
+#define TARGET void foo()
+[[TAR^GET{ return; }]]
+  )cpp",
+  "FunctionDecl",
+  },
   {
   R"cpp(
 struct S { S(const char*); };
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -271,6 +271,7 @@
   else
 S.Selected = SelectionTree::Partial;
 }
+ExpandedTokens = computeExpandedTokens(Buf);
   }
 
   // Test whether a consecutive range of tokens is selected.
@@ -279,6 +280,18 @@
   test(llvm::ArrayRef ExpandedTokens) const {
 if (SpelledTokens.empty())
   return NoTokens;
+// Cheap (pointer) check whether any of the tokens could touch selection.
+// In most cases, the node's overall source range touches ExpandedTokens,
+// or we would have failed mayHit(). However now we're only considering
+// the *unclaimed* spans of expanded tokens.
+// This is a significant performance improvement when a lot of nodes
+// surround the selection, including when generated by macros.
+if (ExpandedTokens.empty() ||
+&ExpandedTokens.front() > &this->ExpandedTokens.back() ||
+&ExpandedTokens.back() < &this->ExpandedTokens.front()) {
+  return SelectionTree::Unselected;
+}
+
 SelectionTree::Selection Result = NoTokens;
 while (!ExpandedTokens.empty()) {
   // Take consecutive tokens from the same context together for efficiency.
@@ -301,7 +314,7 @@
   // If it returns false, test() will return NoTokens or Unselected.
   // If it returns true, test() may return any value.
   bool mayHit(SourceRange R) const {
-if (SpelledTokens.empty())
+if (SpelledTokens.empty() || ExpandedTokens.empty())
   return false;
 auto B = offsetInSelFile(R.getBegin());
 auto E = offsetInSelFile(R.getEnd());
@@ -312,6 +325,62 @@
   }
 
 private:
+  // Plausible expanded tokens that might be affected by the selection.
+  // This is an overestimate, it may contain tokens that are not selected.
+  // The point is to allow cheap pruning in test()
+  llvm::ArrayRef
+  computeExpandedTokens(const syntax::TokenBuffer &Toks) {
+if (SpelledTokens.empty())
+  return {};
+
+bool StartInvalid = false;
+const syntax::Token *Start = llvm::partition_point(
+Toks.expandedTokens(),
+[&, First = SpelledTokens.front().Offset](const syntax::Token &Tok) {
+  // Implausible if upperbound(Tok) < First.
+  SourceLocation Loc = Tok.location();
+  auto Offset = offsetInSelFile(Loc);
+  while (Loc.isValid() && !Offset) {
+Loc = Loc.isMacroID() ? SM.getImmediateExpansionRange(Loc).getEnd()
+  : SM.getIncludeLoc(SM.getFileID(Loc));
+Offset = offsetInSelFile(Loc);
+  }
+  if (Offset)
+return *Offset < First;
+  StartInvalid = false;
+  return false;
+});
+if (StartInvalid) {
+  assert(false && "Expanded tokens could not be resolved to main file!");
+  Start = Toks.expandedTokens().begin();
+}
+
+bool EndInvalid = false;
+const syntax::Token *End = llvm::partition_point(
+Toks.expandedTokens(),
+[&, Last = SpelledTokens.back().Offset](const syntax::Token &Tok) {
+  // Plausible if lowerbound(Tok) <= Last.
+  SourceLocation Loc = Tok.locati

[PATCH] D116673: [Clang][NVPTX]Add NVPTX intrinsics and builtins for CUDA PTX cvt sm80 instructions

2022-01-12 Thread Jack Kirk via Phabricator via cfe-commits
JackAKirk marked 2 inline comments as done.
JackAKirk added a comment.

ping @tra

I thought I should let you know that I do not have commit access to land the 
patch.  I'm also happy to wait a little longer in case you think other 
interested parties might still chime in.

Thanks




Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:405
 
+TARGET_BUILTIN(__nvvm_ff2v2bf_rn, "ZUiff", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_ff2v2bf_rn_relu, "ZUiff", "", AND(SM_80,PTX70))

tra wrote:
> Nit: `ff2v2bf` is a bit hard to parse. I initially tried to interpret it as 
> "convert ff2v to bf" and was confused about  what exactly does `2v` part mean 
> -- we already have `ff` to denote two floats.
> 
> Perhaps `ff2bf16x2` would be a bit easier to read and understand. It would 
> also work consistently for `f16` and `tf32` variants below.
Thanks for the comment.  I also think your suggestion is better.  I've now 
switched to this new naming convention.



Comment at: clang/test/CodeGen/builtins-nvptx.c:760
+// CHECK-LABEL: nvvm_cvt_sm80
+__device__ void nvvm_cvt_sm80() {
+#if __CUDA_ARCH__ >= 800

tra wrote:
> Can you try compiling this test file all the way to .o so we're sure that 
> ptxas does accept the PTX we end up generating.
> 
Sure, I've attached the output ptx for the convert portion of the test file, 
along with the test: I added store operations in order for the convert 
instructions to not be optimised away. 

{F21499889}

{F21499888}

Also please be aware that there appears to be a bug in the existing 
builtins-nvptx.c test file that is apparent when trying to compile down to ptx 
using the shfl part of the test file: I get:
```
fatal error: error in backend: Cannot select: intrinsic %llvm.nvvm.shfl.idx.f32
``` 


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

https://reviews.llvm.org/D116673

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


[clang] 732ad8e - [clang][auto-init] Provide __builtin_alloca*_uninitialized variants

2022-01-12 Thread Marco Elver via cfe-commits

Author: Marco Elver
Date: 2022-01-12T15:13:10+01:00
New Revision: 732ad8ea62edc403727af57537b5d83dcfa937aa

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

LOG: [clang][auto-init] Provide __builtin_alloca*_uninitialized variants

When `-ftrivial-auto-var-init=` is enabled, allocas unconditionally
receive auto-initialization since [1].

In certain cases, it turns out, this is causing problems. For example,
when using alloca to add a random stack offset, as the Linux kernel does
on syscall entry [2]. In this case, none of the alloca'd stack memory is
ever used, and initializing it should be controllable; furthermore, it
is not always possible to safely call memset (see [2]).

Introduce `__builtin_alloca_uninitialized()` (and
`__builtin_alloca_with_align_uninitialized`), which never performs
initialization when `-ftrivial-auto-var-init=` is enabled.

[1] https://reviews.llvm.org/D60548
[2] https://lkml.kernel.org/r/ybhtkujeejzcl...@elver.google.com

Reviewed By: glider

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

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGenCXX/trivial-auto-var-init.cpp
clang/test/Sema/warn-alloca.c

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index bfaa7e9f5a9fa..c7c47cf99abac 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -641,7 +641,9 @@ BUILTIN(__builtin_unreachable, "v", "nr")
 BUILTIN(__builtin_shufflevector, "v."   , "nct")
 BUILTIN(__builtin_convertvector, "v."   , "nct")
 BUILTIN(__builtin_alloca, "v*z"   , "Fn")
+BUILTIN(__builtin_alloca_uninitialized, "v*z", "Fn")
 BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn")
+BUILTIN(__builtin_alloca_with_align_uninitialized, "v*zIz", "Fn")
 BUILTIN(__builtin_call_with_static_chain, "v.", "nt")
 
 BUILTIN(__builtin_elementwise_abs, "v.", "nct")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7b5d202afbba2..e9dd41a7daa10 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3427,6 +3427,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 
   case Builtin::BIalloca:
   case Builtin::BI_alloca:
+  case Builtin::BI__builtin_alloca_uninitialized:
   case Builtin::BI__builtin_alloca: {
 Value *Size = EmitScalarExpr(E->getArg(0));
 const TargetInfo &TI = getContext().getTargetInfo();
@@ -3437,10 +3438,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 .getAsAlign();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
 AI->setAlignment(SuitableAlignmentInBytes);
-initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
+if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
+  initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
 return RValue::get(AI);
   }
 
+  case Builtin::BI__builtin_alloca_with_align_uninitialized:
   case Builtin::BI__builtin_alloca_with_align: {
 Value *Size = EmitScalarExpr(E->getArg(0));
 Value *AlignmentInBitsValue = EmitScalarExpr(E->getArg(1));
@@ -3450,7 +3453,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getAsAlign();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
 AI->setAlignment(AlignmentInBytes);
-initializeAlloca(*this, AI, Size, AlignmentInBytes);
+if (BuiltinID != Builtin::BI__builtin_alloca_with_align_uninitialized)
+  initializeAlloca(*this, AI, Size, AlignmentInBytes);
 return RValue::get(AI);
   }
 

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 908cb78fbb0a7..d067ac31dc1e8 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1750,10 +1750,12 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   return ExprError();
 break;
   case Builtin::BI__builtin_alloca_with_align:
+  case Builtin::BI__builtin_alloca_with_align_uninitialized:
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
 LLVM_FALLTHROUGH;
   case Builtin::BI__builtin_alloca:
+  case Builtin::BI__builtin_alloca_uninitialized:
 Diag(TheCall->getBeginLoc(), diag::warn_alloca)
 << TheCall->getDirectCallee();
 break;

diff  --git a/clang/test/CodeGenCXX/trivial-auto-var-init.cpp 
b/clang/test/CodeGenCXX/trivial-auto-var-init.cpp
index 513222cb3f1d1..58fba5d96b577 100644
--- a/clang/test/CodeGenCXX/trivial-auto-var-init.cpp
+++ b/clang/test/CodeGenCXX/trivial-auto-v

[PATCH] D115440: Provide __builtin_alloca*_uninitialized variants

2022-01-12 Thread Marco Elver via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG732ad8ea62ed: [clang][auto-init] Provide 
__builtin_alloca*_uninitialized variants (authored by melver).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115440

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenCXX/trivial-auto-var-init.cpp
  clang/test/Sema/warn-alloca.c

Index: clang/test/Sema/warn-alloca.c
===
--- clang/test/Sema/warn-alloca.c
+++ clang/test/Sema/warn-alloca.c
@@ -18,3 +18,17 @@
   // expected-warning@-2 {{use of function '__builtin_alloca_with_align' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
 #endif
 }
+
+void test3(int a) {
+  __builtin_alloca_uninitialized(a);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca_uninitialized' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
+
+void test4(int a) {
+  __builtin_alloca_with_align_uninitialized(a, 32);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca_with_align_uninitialized' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
Index: clang/test/CodeGenCXX/trivial-auto-var-init.cpp
===
--- clang/test/CodeGenCXX/trivial-auto-var-init.cpp
+++ clang/test/CodeGenCXX/trivial-auto-var-init.cpp
@@ -201,6 +201,34 @@
   used(ptr);
 }
 
+// UNINIT-LABEL:  test_alloca_uninitialized(
+// ZERO-LABEL:test_alloca_uninitialized(
+// ZERO:  %[[SIZE:[a-z0-9]+]] = sext i32 %{{.*}} to i64
+// ZERO-NEXT: %[[ALLOCA:[a-z0-9]+]] = alloca i8, i64 %[[SIZE]], align [[ALIGN:[0-9]+]]
+// ZERO-NOT:  call void @llvm.memset
+// PATTERN-LABEL: test_alloca_uninitialized(
+// PATTERN:   %[[SIZE:[a-z0-9]+]] = sext i32 %{{.*}} to i64
+// PATTERN-NEXT:  %[[ALLOCA:[a-z0-9]+]] = alloca i8, i64 %[[SIZE]], align [[ALIGN:[0-9]+]]
+// PATTERN-NOT:   call void @llvm.memset
+void test_alloca_uninitialized(int size) {
+  void *ptr = __builtin_alloca_uninitialized(size);
+  used(ptr);
+}
+
+// UNINIT-LABEL:  test_alloca_with_align_uninitialized(
+// ZERO-LABEL:test_alloca_with_align_uninitialized(
+// ZERO:  %[[SIZE:[a-z0-9]+]] = sext i32 %{{.*}} to i64
+// ZERO-NEXT: %[[ALLOCA:[a-z0-9]+]] = alloca i8, i64 %[[SIZE]], align 128
+// ZERO-NOT:  call void @llvm.memset
+// PATTERN-LABEL: test_alloca_with_align_uninitialized(
+// PATTERN:   %[[SIZE:[a-z0-9]+]] = sext i32 %{{.*}} to i64
+// PATTERN-NEXT:  %[[ALLOCA:[a-z0-9]+]] = alloca i8, i64 %[[SIZE]], align 128
+// PATTERN-NOT:   call void @llvm.memset
+void test_alloca_with_align_uninitialized(int size) {
+  void *ptr = __builtin_alloca_with_align_uninitialized(size, 1024);
+  used(ptr);
+}
+
 // UNINIT-LABEL:  test_struct_vla(
 // ZERO-LABEL:test_struct_vla(
 // ZERO:  %[[SIZE:[0-9]+]] = mul nuw i64 %{{.*}}, 16
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1750,10 +1750,12 @@
   return ExprError();
 break;
   case Builtin::BI__builtin_alloca_with_align:
+  case Builtin::BI__builtin_alloca_with_align_uninitialized:
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
 LLVM_FALLTHROUGH;
   case Builtin::BI__builtin_alloca:
+  case Builtin::BI__builtin_alloca_uninitialized:
 Diag(TheCall->getBeginLoc(), diag::warn_alloca)
 << TheCall->getDirectCallee();
 break;
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3427,6 +3427,7 @@
 
   case Builtin::BIalloca:
   case Builtin::BI_alloca:
+  case Builtin::BI__builtin_alloca_uninitialized:
   case Builtin::BI__builtin_alloca: {
 Value *Size = EmitScalarExpr(E->getArg(0));
 const TargetInfo &TI = getContext().getTargetInfo();
@@ -3437,10 +3438,12 @@
 .getAsAlign();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
 AI->setAlignment(SuitableAlignmentInBytes);
-initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
+if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
+  initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
 return RValue::get(AI);
   }
 
+  case Builtin::BI__builtin_alloca_with_align_uninitialized:
   case Builtin::BI__builtin_alloca_with_align: {
 Value *Size = EmitScalarExpr(E->getArg(0));
 

[PATCH] D117112: [AArch64] Support for Ampere1 core

2022-01-12 Thread Philipp Tomsich via Phabricator via cfe-commits
philipp.tomsich created this revision.
philipp.tomsich added reviewers: kristof.beyls, jgreenhalgh.
Herald added a subscriber: hiraditya.
philipp.tomsich requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Add support for the Ampere Computing Ampere1 core.
Ampere1 implements the AArch64 state and is compatible with ARMv8.6-A.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117112

Files:
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64SchedAmpere1.td
  llvm/lib/Target/AArch64/AArch64SchedPredAmpere.td
  llvm/lib/Target/AArch64/AArch64SchedPredicates.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/test/CodeGen/AArch64/cpus.ll
  llvm/test/CodeGen/AArch64/neon-dot-product.ll
  llvm/test/CodeGen/AArch64/remat.ll
  llvm/test/MC/AArch64/armv8.2a-dotprod.s
  llvm/test/MC/AArch64/armv8.3a-rcpc.s
  llvm/test/MC/Disassembler/AArch64/armv8.3a-rcpc.txt
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1169,6 +1169,16 @@
  AArch64::AEK_SVE2 | AArch64::AEK_SVE2BITPERM |
  AArch64::AEK_BF16 | AArch64::AEK_I8MM,
  "8.5-A"),
+ARMCPUTestParams("ampere1", "armv8.6-a", "crypto-neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
+ AArch64::AEK_FP | AArch64::AEK_SIMD |
+ AArch64::AEK_FP16 | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | 
+ AArch64::AEK_DOTPROD | AArch64::AEK_RCPC |
+ AArch64::AEK_RDM | AArch64::AEK_MTE |
+ AArch64::AEK_SSBS | AArch64::AEK_SB |
+ AArch64::AEK_BF16 | AArch64::AEK_I8MM,
+ "8.6-A"),
 ARMCPUTestParams(
 "neoverse-512tvb", "armv8.4-a", "crypto-neon-fp-armv8",
 AArch64::AEK_RAS | AArch64::AEK_SVE | AArch64::AEK_SSBS |
@@ -1232,7 +1242,7 @@
  AArch64::AEK_LSE | AArch64::AEK_RDM,
  "8.2-A")));
 
-static constexpr unsigned NumAArch64CPUArchs = 52;
+static constexpr unsigned NumAArch64CPUArchs = 53;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/test/MC/Disassembler/AArch64/armv8.3a-rcpc.txt
===
--- llvm/test/MC/Disassembler/AArch64/armv8.3a-rcpc.txt
+++ llvm/test/MC/Disassembler/AArch64/armv8.3a-rcpc.txt
@@ -12,6 +12,7 @@
 # RUN: llvm-mc -triple aarch64-none-linux-gnu -mcpu=neoverse-e1 --disassemble < %s | FileCheck %s
 # RUN: llvm-mc -triple aarch64-none-linux-gnu -mcpu=neoverse-n1 --disassemble < %s | FileCheck %s
 # RUN: llvm-mc -triple aarch64-none-linux-gnu -mcpu=neoverse-n2 --disassemble < %s | FileCheck %s
+# RUN: llvm-mc -triple aarch64-none-linux-gnu -mcpu=ampere1 --disassemble < %s | FileCheck %s
 
 # CHECK: ldaprb w0, [x0]
 # CHECK: ldaprh w0, [x0]
Index: llvm/test/MC/AArch64/armv8.3a-rcpc.s
===
--- llvm/test/MC/AArch64/armv8.3a-rcpc.s
+++ llvm/test/MC/AArch64/armv8.3a-rcpc.s
@@ -6,6 +6,7 @@
 // RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mcpu=neoverse-e1 < %s 2>&1 | FileCheck %s
 // RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mcpu=neoverse-n1 < %s 2>&1 | FileCheck %s
 // RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mcpu=neoverse-n2 < %s 2>&1 | FileCheck %s
+// RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mcpu=ampere1 < %s 2>&1 | FileCheck %s
 // RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mattr=+v8.2a -mattr=+rcpc < %s 2>&1 | FileCheck %s
 // RUN: not llvm-mc -triple aarch64-none-linux-gnu -mattr=+v8.2a < %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-REQ %s < %t
Index: llvm/test/MC/AArch64/armv8.2a-dotprod.s
===
--- llvm/test/MC/AArch64/armv8.2a-dotprod.s
+++ llvm/test/MC/AArch64/armv8.2a-dotprod.s
@@ -13,6 +13,7 @@
 // RUN: llvm-mc -triple aarch64 -mcpu=tsv110 -show-encoding < %s | FileCheck %s --check-prefix=CHECK-DOTPROD
 // RUN: llvm-mc -triple aarch64 -mcpu=cortex-r82 -show-encoding < %s | FileCheck %s --check-prefix=CHECK-DOTPROD
 // RUN: llvm-mc -triple aarch64 -mattr=+v8r -show-encoding < %s | FileCheck %s --check-prefix=CHECK-DOTPROD
+// RUN: llvm-mc -triple aarch64 -mcpu=ampere1 -show-encoding < %s | FileCheck %s --check-prefix=CHECK-DOTPROD
 
 // RUN: not llvm-mc -triple aarch64 -mattr=+v8.2a -show

[clang-tools-extra] c490f8f - [clangd][StdSymbolMap] Prefer std::remove from algorithm

2022-01-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-01-12T15:25:42+01:00
New Revision: c490f8feb71e837dd7011e7a7d8a7928507c9c76

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

LOG: [clangd][StdSymbolMap] Prefer std::remove from algorithm

std::remove from algorithm is a lot more common than the overload from
the cstdio (which deletes files). This patch introduces a set of symbols
for which we should prefer the overloaded versions.

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

Added: 


Modified: 
clang-tools-extra/clangd/StdSymbolMap.inc
clang-tools-extra/clangd/include-mapping/cppreference_parser.py

Removed: 




diff  --git a/clang-tools-extra/clangd/StdSymbolMap.inc 
b/clang-tools-extra/clangd/StdSymbolMap.inc
index f1df6d313028..e78d3766bcdd 100644
--- a/clang-tools-extra/clangd/StdSymbolMap.inc
+++ b/clang-tools-extra/clangd/StdSymbolMap.inc
@@ -955,7 +955,6 @@ SYMBOL(regex_token_iterator, std::, )
 SYMBOL(regex_traits, std::, )
 SYMBOL(reinterpret_pointer_cast, std::, )
 SYMBOL(remainder, std::, )
-SYMBOL(remove, std::, )
 SYMBOL(remove_all_extents, std::, )
 SYMBOL(remove_all_extents_t, std::, )
 SYMBOL(remove_const, std::, )

diff  --git a/clang-tools-extra/clangd/include-mapping/cppreference_parser.py 
b/clang-tools-extra/clangd/include-mapping/cppreference_parser.py
index fd3b8a6837d6..e56c8a5f1331 100644
--- a/clang-tools-extra/clangd/include-mapping/cppreference_parser.py
+++ b/clang-tools-extra/clangd/include-mapping/cppreference_parser.py
@@ -103,7 +103,9 @@ def _ParseIndexPage(index_page_html):
 # This accidentally accepts begin/end despite the (iterator) caption: the
 # (since C++11) note is first. They are good symbols, so the bug is 
unfixed.
 caption = symbol_href.next_sibling
-variant = isinstance(caption, NavigableString) and "(" in caption
+variant = None
+if isinstance(caption, NavigableString) and "(" in caption:
+  variant = caption.text.strip(" ()")
 symbol_tt = symbol_href.find("tt")
 if symbol_tt:
   symbols.append((symbol_tt.text.rstrip("<>()"), # strip any trailing <>()
@@ -116,7 +118,7 @@ def _ReadSymbolPage(path, name):
 return _ParseSymbolPage(f.read(), name)
 
 
-def _GetSymbols(pool, root_dir, index_page_name, namespace):
+def _GetSymbols(pool, root_dir, index_page_name, namespace, 
variants_to_accept):
   """Get all symbols listed in the index page. All symbols should be in the
   given namespace.
 
@@ -135,7 +137,9 @@ def _GetSymbols(pool, root_dir, index_page_name, namespace):
 for symbol_name, symbol_page_path, variant in _ParseIndexPage(f.read()):
   # Variant symbols (e.g. the std::locale version of isalpha) add 
ambiguity.
   # FIXME: use these as a fallback rather than ignoring entirely.
-  if variant:
+  variants_for_symbol = variants_to_accept.get(
+  (namespace or "") + symbol_name, ())
+  if variant and variant not in variants_for_symbol:
 continue
   path = os.path.join(root_dir, symbol_page_path)
   results.append((symbol_name,
@@ -158,6 +162,13 @@ def GetSymbols(parse_pages):
   Args:
 parse_pages: a list of tuples (page_root_dir, index_page_name, namespace)
   """
+  # By default we prefer the non-variant versions, as they're more common. But
+  # there are some symbols, whose variant is more common. This list describes
+  # those symbols.
+  variants_to_accept = {
+  # std::remove<> has variant algorithm.
+  "std::remove": ("algorithm"),
+  }
   symbols = []
   # Run many workers to process individual symbol pages under the symbol index.
   # Don't allow workers to capture Ctrl-C.
@@ -165,7 +176,8 @@ def GetSymbols(parse_pages):
   initializer=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN))
   try:
 for root_dir, page_name, namespace in parse_pages:
-  symbols.extend(_GetSymbols(pool, root_dir, page_name, namespace))
+  symbols.extend(_GetSymbols(pool, root_dir, page_name, namespace,
+ variants_to_accept))
   finally:
 pool.terminate()
 pool.join()



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


[PATCH] D114724: [clangd][StdSymbolMap] Prefer std::remove from algorithm

2022-01-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc490f8feb71e: [clangd][StdSymbolMap] Prefer std::remove from 
algorithm (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114724

Files:
  clang-tools-extra/clangd/StdSymbolMap.inc
  clang-tools-extra/clangd/include-mapping/cppreference_parser.py


Index: clang-tools-extra/clangd/include-mapping/cppreference_parser.py
===
--- clang-tools-extra/clangd/include-mapping/cppreference_parser.py
+++ clang-tools-extra/clangd/include-mapping/cppreference_parser.py
@@ -103,7 +103,9 @@
 # This accidentally accepts begin/end despite the (iterator) caption: the
 # (since C++11) note is first. They are good symbols, so the bug is 
unfixed.
 caption = symbol_href.next_sibling
-variant = isinstance(caption, NavigableString) and "(" in caption
+variant = None
+if isinstance(caption, NavigableString) and "(" in caption:
+  variant = caption.text.strip(" ()")
 symbol_tt = symbol_href.find("tt")
 if symbol_tt:
   symbols.append((symbol_tt.text.rstrip("<>()"), # strip any trailing <>()
@@ -116,7 +118,7 @@
 return _ParseSymbolPage(f.read(), name)
 
 
-def _GetSymbols(pool, root_dir, index_page_name, namespace):
+def _GetSymbols(pool, root_dir, index_page_name, namespace, 
variants_to_accept):
   """Get all symbols listed in the index page. All symbols should be in the
   given namespace.
 
@@ -135,7 +137,9 @@
 for symbol_name, symbol_page_path, variant in _ParseIndexPage(f.read()):
   # Variant symbols (e.g. the std::locale version of isalpha) add 
ambiguity.
   # FIXME: use these as a fallback rather than ignoring entirely.
-  if variant:
+  variants_for_symbol = variants_to_accept.get(
+  (namespace or "") + symbol_name, ())
+  if variant and variant not in variants_for_symbol:
 continue
   path = os.path.join(root_dir, symbol_page_path)
   results.append((symbol_name,
@@ -158,6 +162,13 @@
   Args:
 parse_pages: a list of tuples (page_root_dir, index_page_name, namespace)
   """
+  # By default we prefer the non-variant versions, as they're more common. But
+  # there are some symbols, whose variant is more common. This list describes
+  # those symbols.
+  variants_to_accept = {
+  # std::remove<> has variant algorithm.
+  "std::remove": ("algorithm"),
+  }
   symbols = []
   # Run many workers to process individual symbol pages under the symbol index.
   # Don't allow workers to capture Ctrl-C.
@@ -165,7 +176,8 @@
   initializer=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN))
   try:
 for root_dir, page_name, namespace in parse_pages:
-  symbols.extend(_GetSymbols(pool, root_dir, page_name, namespace))
+  symbols.extend(_GetSymbols(pool, root_dir, page_name, namespace,
+ variants_to_accept))
   finally:
 pool.terminate()
 pool.join()
Index: clang-tools-extra/clangd/StdSymbolMap.inc
===
--- clang-tools-extra/clangd/StdSymbolMap.inc
+++ clang-tools-extra/clangd/StdSymbolMap.inc
@@ -955,7 +955,6 @@
 SYMBOL(regex_traits, std::, )
 SYMBOL(reinterpret_pointer_cast, std::, )
 SYMBOL(remainder, std::, )
-SYMBOL(remove, std::, )
 SYMBOL(remove_all_extents, std::, )
 SYMBOL(remove_all_extents_t, std::, )
 SYMBOL(remove_const, std::, )


Index: clang-tools-extra/clangd/include-mapping/cppreference_parser.py
===
--- clang-tools-extra/clangd/include-mapping/cppreference_parser.py
+++ clang-tools-extra/clangd/include-mapping/cppreference_parser.py
@@ -103,7 +103,9 @@
 # This accidentally accepts begin/end despite the (iterator) caption: the
 # (since C++11) note is first. They are good symbols, so the bug is unfixed.
 caption = symbol_href.next_sibling
-variant = isinstance(caption, NavigableString) and "(" in caption
+variant = None
+if isinstance(caption, NavigableString) and "(" in caption:
+  variant = caption.text.strip(" ()")
 symbol_tt = symbol_href.find("tt")
 if symbol_tt:
   symbols.append((symbol_tt.text.rstrip("<>()"), # strip any trailing <>()
@@ -116,7 +118,7 @@
 return _ParseSymbolPage(f.read(), name)
 
 
-def _GetSymbols(pool, root_dir, index_page_name, namespace):
+def _GetSymbols(pool, root_dir, index_page_name, namespace, variants_to_accept):
   """Get all symbols listed in the index page. All symbols should be in the
   given namespace.
 
@@ -135,7 +137,9 @@
 for symbol_name, symbol_page_path, variant in _ParseIndexPage(f.read()):
   # Variant symbols (e.g. the std::locale version of isalpha) add ambiguity.
   # FIXME: use these as a fallback rather than ignoring entirely.
-  if variant:
+  variants_for_symb

[PATCH] D115523: [OpenCL] Set external linkage for block enqueue kernels

2022-01-12 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

It is possible that block kernels are defined and invoked in static functions, 
therefore two block kernels in different TU's may have the same name. Making 
such kernels external may cause duplicate symbols.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115523

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


[PATCH] D105340: [analyzer] Produce SymbolCast symbols for integral types in SValBuilder::evalCast

2022-01-12 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

In D105340#3232671 , @NoQ wrote:

> This looks great with the option flag. Landing this patch will enable more 
> people to test the new mode and produce feedback on whether the constraint 
> solver keeps working well enough in presence of the new symbols.

Many thanks for your approval, @NoQ! The upset thing is that to get this loaded 
we also should close this parent revision D103094 
 :-(


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

https://reviews.llvm.org/D105340

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


[PATCH] D113359: [Libomptarget][WIP] Introduce VGPU Plugin

2022-01-12 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: openmp/libomptarget/DeviceRTL/CMakeLists.txt:231
+
+compileDeviceRTLLibrary(x86_64 vgpu -target x86_64-vgpu -std=c++20 
-stdlib=libc++ -I${devicertl_base_directory}/../plugins/vgpu/src)

It's not a good practice to specify include directories in CMake in this way. 
Use `include_directories` instead.



Comment at: openmp/libomptarget/DeviceRTL/src/Kernel.cpp:127
 
+#pragma omp begin declare variant match(   
\
+device = {kind(cpu)}, implementation = {extension(match_any)})

Are these code here unintentional? We don't need to specialize this function 
for vgpu IIRC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113359

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


[PATCH] D27800: [clang] Fix crash for sizeof on VLAs

2022-01-12 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 399320.
pmatos retitled this revision from "Add overload of 
TransformToPotentiallyEvaluated for TypeSourceInfo" to "[clang] Fix crash for 
sizeof on VLAs".
pmatos edited the summary of this revision.
pmatos added a comment.

Ensure that we only call transform on Unevaluated Contexts, avoids the failure 
of a couple of vla tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D27800

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/pr31042.cpp


Index: clang/test/SemaCXX/pr31042.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/pr31042.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -o - -emit-llvm -triple x86_64-unknown-linux-gnu 
-disable-free %s
+// We need to use -emit-llvm in order to trigger the error, without it 
semantic analysis
+// does not verify the used bit and there's no error.
+
+char a[1];
+
+void f1(void) {
+  int i = 0;
+  int j = sizeof(typeof(*(char(*)[i])a));
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4499,6 +4499,10 @@
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (isUnevaluatedContext() && ExprKind == UETT_SizeOf &&
+  TInfo->getType()->isVariablyModifiedType())
+TInfo = TransformToPotentiallyEvaluated(TInfo);
+
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -16601,6 +16605,16 @@
   return TransformToPE(*this).TransformExpr(E);
 }
 
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+ "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+  ExprEvalContexts[ExprEvalContexts.size() - 2].Context;
+  if (isUnevaluatedContext())
+return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(
 ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl,
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -5053,6 +5053,7 @@
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult CheckUnevaluatedOperand(Expr *E);


Index: clang/test/SemaCXX/pr31042.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/pr31042.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -o - -emit-llvm -triple x86_64-unknown-linux-gnu -disable-free %s
+// We need to use -emit-llvm in order to trigger the error, without it semantic analysis
+// does not verify the used bit and there's no error.
+
+char a[1];
+
+void f1(void) {
+  int i = 0;
+  int j = sizeof(typeof(*(char(*)[i])a));
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4499,6 +4499,10 @@
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (isUnevaluatedContext() && ExprKind == UETT_SizeOf &&
+  TInfo->getType()->isVariablyModifiedType())
+TInfo = TransformToPotentiallyEvaluated(TInfo);
+
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -16601,6 +16605,16 @@
   return TransformToPE(*this).TransformExpr(E);
 }
 
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+ "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+  ExprEvalContexts[ExprEvalContexts.size() - 2].Context;
+  if (isUnevaluatedContext())
+return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(
 ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl,
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -5053,6 +5053,7 @@
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult CheckUnevaluatedOperand(Expr *E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/

[PATCH] D27800: [clang] Fix crash for sizeof on VLAs

2022-01-12 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

In D27800#3235066 , @efriedma wrote:

> Looks like all the review comments have been addressed.  LGTM

Minor change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D27800

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


[clang] 6cbebfc - [clang-format] Fix comment. NFC.

2022-01-12 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-01-12T16:10:03+01:00
New Revision: 6cbebfc7fb3468a080b04c58bfe374f8bee33d12

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

LOG: [clang-format] Fix comment. NFC.

Added: 


Modified: 
clang/lib/Format/DefinitionBlockSeparator.cpp

Removed: 




diff  --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 504392cb61422..d09cd0bd33fbe 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -162,7 +162,7 @@ void DefinitionBlockSeparator::separateBlocks(
   // handled in another case if the line following is opening a
   // definition.
   if (!TargetToken->closesScope() && !IsPPConditional(OpeningLineIndex)) {
-// Check whether current line may be precedings of a definition line.
+// Check whether current line may precede a definition line.
 while (OpeningLineIndex + 1 < Lines.size() &&
MayPrecedeDefinition(/*Direction=*/0))
   ++OpeningLineIndex;



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


[clang] 968be05 - [clang] Fix crash for sizeof on VLAs

2022-01-12 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2022-01-12T16:10:58+01:00
New Revision: 968be05b8fdc1d23c055cc4963230a89efbc5967

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

LOG: [clang] Fix crash for sizeof on VLAs

Adds overload of TransformToPotentiallyEvaluated for TypeSourceInfo to
properly deal with VLAs in nested calls of sizeof and typeof. Fixes
PR31042 (https://github.com/llvm/llvm-project/issues/30390).

Reviewed By: efriedma

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

Added: 
clang/test/SemaCXX/pr31042.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f1e90356c8367..b4d8d1494e705 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5053,6 +5053,7 @@ class Sema final {
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult CheckUnevaluatedOperand(Expr *E);

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 229a604901244..7de43705c2b10 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4499,6 +4499,10 @@ Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo 
*TInfo,
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (isUnevaluatedContext() && ExprKind == UETT_SizeOf &&
+  TInfo->getType()->isVariablyModifiedType())
+TInfo = TransformToPotentiallyEvaluated(TInfo);
+
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -16601,6 +16605,16 @@ ExprResult Sema::TransformToPotentiallyEvaluated(Expr 
*E) {
   return TransformToPE(*this).TransformExpr(E);
 }
 
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+ "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+  ExprEvalContexts[ExprEvalContexts.size() - 2].Context;
+  if (isUnevaluatedContext())
+return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(
 ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl,

diff  --git a/clang/test/SemaCXX/pr31042.cpp b/clang/test/SemaCXX/pr31042.cpp
new file mode 100644
index 0..d4995c6e4d686
--- /dev/null
+++ b/clang/test/SemaCXX/pr31042.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -o - -emit-llvm -triple x86_64-unknown-linux-gnu 
-disable-free %s
+// We need to use -emit-llvm in order to trigger the error, without it 
semantic analysis
+// does not verify the used bit and there's no error.
+
+char a[1];
+
+void f1(void) {
+  int i = 0;
+  int j = sizeof(typeof(*(char(*)[i])a));
+}



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


[PATCH] D27800: [clang] Fix crash for sizeof on VLAs

2022-01-12 Thread Paulo Matos 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 rG968be05b8fdc: [clang] Fix crash for sizeof on VLAs (authored 
by pmatos).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D27800

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/pr31042.cpp


Index: clang/test/SemaCXX/pr31042.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/pr31042.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -o - -emit-llvm -triple x86_64-unknown-linux-gnu 
-disable-free %s
+// We need to use -emit-llvm in order to trigger the error, without it 
semantic analysis
+// does not verify the used bit and there's no error.
+
+char a[1];
+
+void f1(void) {
+  int i = 0;
+  int j = sizeof(typeof(*(char(*)[i])a));
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4499,6 +4499,10 @@
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (isUnevaluatedContext() && ExprKind == UETT_SizeOf &&
+  TInfo->getType()->isVariablyModifiedType())
+TInfo = TransformToPotentiallyEvaluated(TInfo);
+
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -16601,6 +16605,16 @@
   return TransformToPE(*this).TransformExpr(E);
 }
 
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+ "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+  ExprEvalContexts[ExprEvalContexts.size() - 2].Context;
+  if (isUnevaluatedContext())
+return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(
 ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl,
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -5053,6 +5053,7 @@
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult CheckUnevaluatedOperand(Expr *E);


Index: clang/test/SemaCXX/pr31042.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/pr31042.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -o - -emit-llvm -triple x86_64-unknown-linux-gnu -disable-free %s
+// We need to use -emit-llvm in order to trigger the error, without it semantic analysis
+// does not verify the used bit and there's no error.
+
+char a[1];
+
+void f1(void) {
+  int i = 0;
+  int j = sizeof(typeof(*(char(*)[i])a));
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4499,6 +4499,10 @@
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (isUnevaluatedContext() && ExprKind == UETT_SizeOf &&
+  TInfo->getType()->isVariablyModifiedType())
+TInfo = TransformToPotentiallyEvaluated(TInfo);
+
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -16601,6 +16605,16 @@
   return TransformToPE(*this).TransformExpr(E);
 }
 
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+ "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+  ExprEvalContexts[ExprEvalContexts.size() - 2].Context;
+  if (isUnevaluatedContext())
+return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(
 ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl,
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -5053,6 +5053,7 @@
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult CheckUnevaluatedOperand(Expr *E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] dcc2014 - [clang-tidy] UseDefaultMemberInitCheck::checkDefaultInit - Use cast<> instead of dyn_cast<> to avoid dereference of nullptr

2022-01-12 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-01-12T15:35:37Z
New Revision: dcc20143e170b912aa0831dbedb5c1de07958012

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

LOG: [clang-tidy] UseDefaultMemberInitCheck::checkDefaultInit - Use cast<> 
instead of dyn_cast<> to avoid dereference of nullptr

The pointer is always dereferenced immediately below, so assert the cast is 
correct instead of returning nullptr

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
index d57a88d668832..6f8c984da2a8f 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -247,7 +247,7 @@ void UseDefaultMemberInitCheck::checkDefaultInit(
 
   // Check whether we have multiple hand-written constructors and bomb out, as
   // it is hard to reconcile their sets of member initializers.
-  const auto *ClassDecl = dyn_cast(Field->getParent());
+  const auto *ClassDecl = cast(Field->getParent());
   if (llvm::count_if(ClassDecl->ctors(), [](const CXXConstructorDecl *Ctor) {
 return !Ctor->isCopyOrMoveConstructor();
   }) > 1)



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


[clang] 497a4b2 - CGBuiltin - Use castAs<> instead of getAs<> to avoid dereference of nullptr

2022-01-12 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-01-12T15:35:37Z
New Revision: 497a4b26c487a9640847c485f9b0c36c110a8545

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

LOG: CGBuiltin - Use castAs<> instead of getAs<> to avoid dereference of nullptr

The pointer is always dereferenced immediately below, so assert the cast is 
correct instead of returning nullptr

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e9dd41a7daa1..91284baf123a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3223,7 +3223,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 *this, E, llvm::Intrinsic::vector_reduce_xor, "rdx.xor"));
 
   case Builtin::BI__builtin_matrix_transpose: {
-const auto *MatrixTy = 
E->getArg(0)->getType()->getAs();
+auto *MatrixTy = E->getArg(0)->getType()->castAs();
 Value *MatValue = EmitScalarExpr(E->getArg(0));
 MatrixBuilder MB(Builder);
 Value *Result = MB.CreateMatrixTranspose(MatValue, MatrixTy->getNumRows(),



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


[PATCH] D116822: [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and watchOS availability

2022-01-12 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 399327.
egorzhdan added a comment.

Add a test for a diagnostic without VersionMap & fix clang-format warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116822

Files:
  clang/include/clang/Basic/DarwinSDKInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json
  clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json
  clang/test/Sema/attr-availability-tvos.c
  clang/test/Sema/attr-availability-watchos.c

Index: clang/test/Sema/attr-availability-watchos.c
===
--- clang/test/Sema/attr-availability-watchos.c
+++ clang/test/Sema/attr-availability-watchos.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 "-triple" "arm64-apple-watchos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/WatchOS7.0.sdk -fsyntax-only -verify %s
 
 void f0(int) __attribute__((availability(ios,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
 void f1(int) __attribute__((availability(ios,introduced=2.1)));
@@ -58,3 +59,19 @@
 void test_ios_correctly_map_to_watchos() {
   deprecatedAfterIntroduced(); // expected-warning {{'deprecatedAfterIntroduced' is deprecated: first deprecated in watchOS 3}}
 }
+
+#ifdef USE_VERSION_MAP
+// iOS 10.3.1 corresponds to watchOS 3.2, as indicated in 'SDKSettings.json'.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.2}}
+}
+#else
+// Without VersionMap, watchOS version is inferred incorrectly as 3.3.1.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithoutVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.3.1}}
+}
+#endif
Index: clang/test/Sema/attr-availability-tvos.c
===
--- clang/test/Sema/attr-availability-tvos.c
+++ clang/test/Sema/attr-availability-tvos.c
@@ -1,63 +1,80 @@
-// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/AppleTVOS15.0.sdk -fsyntax-only -verify %s
 
-void f0(int) __attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
-void f1(int) __attribute__((availability(tvos,introduced=2.1)));
-void f2(int) __attribute__((availability(tvos,introduced=2.0,deprecated=3.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
-void f3(int) __attribute__((availability(tvos,introduced=3.0)));
-void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
+void f0(int) __attribute__((availability(tvos,introduced=12.0,deprecated=12.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(tvos,introduced=12.1)));
+void f2(int) __attribute__((availability(tvos,introduced=12.0,deprecated=13.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(tvos,introduced=13.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=12.0,deprecated=12.1,obsoleted=13.0))); // expected-note{{explicitly marked unavailable}}
 
-void f5(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,introduced=2.0)));
+void f5(int) __attribute__((availability(tvos,introduced=12.0))) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,introduced=12.0)));
 
 void test() {
-  f0(0); // expected-warning{{'f0' is deprecated: first deprecated in tvOS 2.1}}
+  f0(0);

[PATCH] D112718: Add intrinsics and builtins for PTX atomics with semantic orders

2022-01-12 Thread Tadej Ciglarič via Phabricator via cfe-commits
t4c1 added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:1057
+
+BUILTIN(__nvvm_atom_xchg_global_i, "iiD*i", "n")
+TARGET_BUILTIN(__nvvm_atom_cta_xchg_global_i, "iiD*i", "n", SM_60)

tra wrote:
> Naghasan wrote:
> > tra wrote:
> > > t4c1 wrote:
> > > > tra wrote:
> > > > > t4c1 wrote:
> > > > > > tra wrote:
> > > > > > > We need to figure out how address-space-specific builtins are 
> > > > > > > supposed to work.
> > > > > > > Right now two competing approaches.
> > > > > > > 
> > > > > > > This patch declares builtins with generic pointer as an argument, 
> > > > > > > but, according to the test, expects to be used with the 
> > > > > > > AS-specific pointer.
> > > > > > > It probably does not catch a wrong-AS pointer passed as an 
> > > > > > > argument, either.
> > > > > > > It does happen to work, but I think it's mostly due to the fact 
> > > > > > > that LLVM intrinsics are overloaded and we happen to end up 
> > > > > > > addrspacecast'ing  things correctly if the builtin gets the right 
> > > > > > > kind of pointer.
> > > > > > > 
> > > > > > > The other approach is to declare the pointer with the expected 
> > > > > > > AS. E.g:
> > > > > > > > TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", 
> > > > > > > > AND(SM_80,PTX70))
> > > > > > > 
> > > > > > > IMO, this is the correct way to do it, but it is also rather 
> > > > > > > inconvenient to use from CUDA code as it operates on generic 
> > > > > > > pointers.
> > > > > > > 
> > > > > > > @jdoerfert - WDYT?
> > > > > > >TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", 
> > > > > > >AND(SM_80,PTX70))
> > > > > > >IMO, this is the correct way to do it, but it is also rather 
> > > > > > >inconvenient to use from CUDA code as it operates on generic 
> > > > > > >pointers.
> > > > > > 
> > > > > > I tried doing this, however it is also completely unusable from 
> > > > > > OpenCL code (which is our use case). Trying to use it gives you 
> > > > > > errors about how casting pointers to different address spaces  - 
> > > > > > for example from local to AS3 is not allowed.
> > > > > Hmm. It should've worked. It would need the same explicit cast to a 
> > > > > pointer in AS(3) as in your tests, but it would safeguard against 
> > > > > attempts to pass it a generic pointer. E.g. 
> > > > > https://godbolt.org/z/qE6oxzheM
> > > > > 
> > > > > Explicit casting to AS(X) for AS-specific variants is annoying, but 
> > > > > it's probably unavoidable at the moment regardless of whether we 
> > > > > declare the pointer argument to be AS-specific or not.  LLVM will not 
> > > > > always be able to infer that a pointer is in particular AS.
> > > > > Using specific AS in the declaration has a minor benefit of 
> > > > > safeguarding at compile time against unintentional use of generic 
> > > > > pointers.
> > > > > 
> > > > > Ideally we may want to convert generic variant of the builtin to 
> > > > > AS-specific one, if LLVM does know the AS. We currently do this for 
> > > > > loads/stores, but not for other instructions.
> > > > > 
> > > > Well, it does not work. See: https://godbolt.org/z/vM6bKncc4. Declaring 
> > > > the pointer to be in generic AS is the only way I got it to work. If 
> > > > you know a way to call a builtin declared with AS numbers in OpenCL, I 
> > > > am happy to do that instead.
> > > Could you help me understand how different address spaces are handled by 
> > > OpenCL in clang and LLVM?
> > > What exactly are `__local` or `__private` in OpenCL? Do they map to 
> > > LLVM's address spaces? 
> > > Clang does complain that we're trying to change AS, but I do not see AS 
> > > used in the IR: https://godbolt.org/z/soajoE991
> > > 
> > > AFAICT what happens is:
> > > * OpenCL does use explicit AS for pointers (`__local`, `__private` seem 
> > > to pop up in the error messages)
> > > * `__attribute__((address_space(3)))` does not match the AS of `__local` 
> > > and that leads to an error.
> > > * generic pointer argument works because we are allowed to cast any 
> > > specific AS to generic one.
> > > 
> > > In other words, having specific-AS arguemt works as intended, we just 
> > > have a mismatch between AS number used by OpenCL and AS number used by 
> > > NVPTX and we're not allowed to cast between two specific AS.
> > > 
> > > If that's indeed the case, then what we appear to be missing is the 
> > > mapping from OpenCL AS to the target-specific AS, which should, ideally, 
> > > be done by clang itself. So, if NVPTX-specific builtin operating on 
> > > shared pointer is called with a pointer in OpenCL's equivalent of CUDA's 
> > > `__shared__`, it should be mapped to AS(3).
> > > 
> > > Could you help me understand how different address spaces are handled by 
> > > OpenCL in clang and LLVM?
> > 
> > clang makes a strong distinction between language and target address spaces 
> > since ~3.6 (was more loose before). Each target in clang defines a map 

[PATCH] D117119: [clang] Remove uses of `std::vector`

2022-01-12 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: dexonsmith.
Herald added subscribers: carlosgalvezp, usaxena95, kadircet, arphaman.
jansvoboda11 requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

LLVM Programmer’s Manual strongly discourages the use of `std::vector` 
and suggests `llvm::BitVector` as a possible replacement.

This patch does just that for clang and clang-tools-extra.

Depends on D117116 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117119

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/Syntax/Tree.cpp
  clang/unittests/Lex/HeaderSearchTest.cpp

Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -302,8 +302,8 @@
   {
 Module *M2 = Search.lookupModule("M2");
 EXPECT_NE(M2, nullptr);
-EXPECT_EQ(Search.getSearchDirUsage(), (std::vector{0, 1, 0}));
-EXPECT_EQ(Search.computeUserEntryUsage(), (std::vector{0, 1, 0}));
+EXPECT_EQ(Search.getSearchDirUsage(), (llvm::BitVector{0, 1, 0}));
+EXPECT_EQ(Search.computeUserEntryUsage(), (llvm::BitVector{0, 1, 0}));
   }
 
   addSearchDir("/M1");
@@ -312,8 +312,8 @@
   {
 Module *M1 = Search.lookupModule("M1");
 EXPECT_NE(M1, nullptr);
-EXPECT_EQ(Search.getSearchDirUsage(), (std::vector{0, 1, 1, 0}));
-EXPECT_EQ(Search.computeUserEntryUsage(), (std::vector{0, 1, 0}));
+EXPECT_EQ(Search.getSearchDirUsage(), (llvm::BitVector{0, 1, 1, 0}));
+EXPECT_EQ(Search.computeUserEntryUsage(), (llvm::BitVector{0, 1, 0}));
   }
 }
 
Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
@@ -202,7 +203,7 @@
 }
 
 static void dumpNode(raw_ostream &OS, const syntax::Node *N,
- const SourceManager &SM, std::vector IndentMask) {
+ const SourceManager &SM, llvm::BitVector IndentMask) {
   auto DumpExtraInfo = [&OS](const syntax::Node *N) {
 if (N->getRole() != syntax::NodeRole::Unknown)
   OS << " " << N->getRole();
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -132,7 +132,7 @@
  sizeof(T) * v.size());
 }
 
-static std::string bytes(const std::vector &V) {
+static std::string bytes(const llvm::BitVector &V) {
   std::string Str;
   Str.reserve(V.size() / 8);
   for (unsigned I = 0, E = V.size(); I < E;) {
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -138,8 +138,8 @@
   SystemDirIdx++;
 }
 
-std::vector HeaderSearch::computeUserEntryUsage() const {
-  std::vector UserEntryUsage(HSOpts->UserEntries.size());
+llvm::BitVector HeaderSearch::computeUserEntryUsage() const {
+  llvm::BitVector UserEntryUsage(HSOpts->UserEntries.size());
   for (const DirectoryLookup *SearchDir : UsedSearchDirs) {
 if (UsedSearchDirs.contains(SearchDir)) {
   auto UserEntryIdxIt = SearchDirToHSEntry.find(SearchDir);
@@ -151,8 +151,8 @@
   return UserEntryUsage;
 }
 
-std::vector HeaderSearch::getSearchDirUsage() const {
-  std::vector SearchDirUsage(SearchDirs.size());
+llvm::BitVector HeaderSearch::getSearchDirUsage() const {
+  llvm::BitVector SearchDirUsage(SearchDirs.size());
   for (unsigned I = 0, E = SearchDirs.size(); I < E; ++I)
 if (UsedSearchDirs.contains(SearchDirs[I]))
   SearchDirUsage[I] = true;
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -18,6 +18,7 @@
 #include "FormatToken.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Format/Format.h"
+#include "llvm/ADT/BitVector.h"
 #include "llvm/Support/Regex.h"
 #include 
 #include 
@@ -220,7 +221,7 @@
 
   // We store for each line whether it must be a declaration depending on
   // whether we are in a compound state

[PATCH] D117120: [Doc] Add documentation for the clang-offload-wrapper tool (NFC)

2022-01-12 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam created this revision.
saiislam added reviewers: sdmitriev, jdoerfert, grokos, JonChesterfield, 
carlo.bertolli, vzakhari.
Herald added a subscriber: arphaman.
saiislam requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Add the missing documentation for this tool.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117120

Files:
  clang/docs/ClangOffloadWrapper.rst
  clang/docs/index.rst

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -84,6 +84,7 @@
ClangFormattedStatus
ClangNvlinkWrapper
ClangOffloadBundler
+   ClangOffloadWrapper
 
 Design Documents
 
Index: clang/docs/ClangOffloadWrapper.rst
===
--- /dev/null
+++ clang/docs/ClangOffloadWrapper.rst
@@ -0,0 +1,220 @@
+=
+Clang Offload Wrapper
+=
+
+.. contents::
+   :local:
+
+.. _clang-offload-wrapper:
+
+Introduction
+
+
+This tool is used in OpenMP offloading toolchain to embed device code objects
+(usually ELF) into a wrapper host llvm IR (bitcode) file. The wrapper host IR
+is then assembled and linked with host code objects to generate the executable
+binary. See :ref:`image-binary-embedding-execution` for more details.
+
+Usage
+=
+
+This tool can be used as follows:
+
+.. code-block:: console
+
+  $ clang-offload-wrapper -help
+  OVERVIEW: A tool to create a wrapper bitcode for offload target binaries.
+  Takes offload target binaries as input and produces bitcode file containing
+  target binaries packaged as data and initialization code which registers
+  target binaries in offload runtime.
+  USAGE: clang-offload-wrapper [options] 
+  OPTIONS:
+  Generic Options:
+--help - Display available options (--help-hidden for more)
+--help-list- Display list of available options (--help-list-hidden for more)
+--version  - Display the version of this program
+  clang-offload-wrapper options:
+-o=  - Output filename
+--target=  - Target triple for the output module
+
+Example
+===
+
+.. code-block:: console
+
+  clang-offload-wrapper -target host-triple -o host-wrapper.bc gfx90a-binary.out
+
+.. _openmp-device-binary_embedding:
+
+OpenMP Device Binary Embedding
+==
+
+Various structures and functions used in the wrapper host IR form the interface
+between the executable binary and the OpenMP runtime.
+
+Enum Types
+--
+
+:ref:`table-offloading-declare-target-flags` lists different flag for
+offloading entries.
+
+  .. table:: Offloading Declare Target Flags Enum
+:name: table-offloading-declare-target-flags
+
++-+---+--+
+|  Name   | Value | Description  |
++=+===+==+
+| OMP_DECLARE_TARGET_LINK | 0x01  | Mark the entry as having a 'link' attribute (w.r.t. link clause) |
++-+---+--+
+| OMP_DECLARE_TARGET_CTOR | 0x02  | Mark the entry as being a global constructor |
++-+---+--+
+| OMP_DECLARE_TARGET_DTOR | 0x04  | Mark the entry as being a global destructor  |
++-+---+--+
+
+Structure Types
+---
+
+:ref:`table-tgt_offload_entry`, :ref:`table-tgt_device_image`, and
+:ref:`table-tgt_bin_desc` are the structures used in the wrapper host IR.
+
+  .. table:: __tgt_offload_entry structure
+:name: table-tgt_offload_entry
+
++-+++
+|   Type  | Identifier | Description|
++=+++
+|  void*  |addr| Address of global symbol within device image (function or global)  |
++-+++
+|  char*  |name| Name of the symbol |
++-+++
+|  size_t |size| Size of 

[PATCH] D117056: [clangd] Properly compute framework-style include spelling

2022-01-12 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 399336.
dgoldman added a comment.

Run clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117056

Files:
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang/lib/Lex/HeaderSearch.cpp

Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1049,6 +1049,11 @@
 getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos));
   if (CurDir->isIndexHeaderMap())
 HFI.IndexHeaderMapHeader = 1;
+} else if (CurDir->isFramework()) {
+  size_t SlashPos = Filename.find('/');
+  if (SlashPos != StringRef::npos)
+HFI.Framework =
+getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos));
 }
 
 if (checkMSVCHeaderSearch(Diags, MSFE ? &MSFE->getFileEntry() : nullptr,
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -663,6 +663,109 @@
   QName("Cat::meow"), QName("Cat::pur")));
 }
 
+TEST_F(SymbolCollectorTest, ObjCFrameworkIncludeHeader) {
+  CollectorOpts.CollectIncludePath = true;
+  auto FrameworksPath = testPath("Frameworks/");
+  auto FrameworkHeaderPath =
+  testPath("Frameworks/Foundation.framework/Headers/NSObject.h");
+  const std::string FrameworkHeader = R"(
+__attribute((objc_root_class))
+@interface NSObject
+@end
+  )";
+  InMemoryFileSystem->addFile(
+  FrameworkHeaderPath, 0,
+  llvm::MemoryBuffer::getMemBuffer(FrameworkHeader));
+
+  const std::string Header = R"(
+#import 
+
+@interface Container : NSObject
+@end
+  )";
+  const std::string Main = "";
+  TestFileName = testPath("test.m");
+  runSymbolCollector(Header, Main, {"-F", FrameworksPath, "-xobjective-c++"});
+  EXPECT_THAT(Symbols, UnorderedElementsAre(
+   AllOf(QName("NSObject"),
+ IncludeHeader("\"Foundation/NSObject.h\"")),
+   AllOf(QName("Container";
+}
+
+TEST_F(SymbolCollectorTest, ObjCUmbrellaFrameworkIncludeHeader) {
+  CollectorOpts.CollectIncludePath = true;
+  auto FrameworksPath = testPath("Frameworks/");
+  auto UmbrellaHeaderPath =
+  testPath("Frameworks/Foundation.framework/Headers/Foundation.h");
+  const std::string UmbrellaHeader = R"(
+#import 
+  )";
+  auto FrameworkHeaderPath =
+  testPath("Frameworks/Foundation.framework/Headers/NSObject.h");
+  const std::string FrameworkHeader = R"(
+__attribute((objc_root_class))
+@interface NSObject
+@end
+  )";
+  InMemoryFileSystem->addFile(UmbrellaHeaderPath, 0,
+  llvm::MemoryBuffer::getMemBuffer(UmbrellaHeader));
+  InMemoryFileSystem->addFile(
+  FrameworkHeaderPath, 0,
+  llvm::MemoryBuffer::getMemBuffer(FrameworkHeader));
+
+  const std::string Header = R"(
+#import 
+
+@interface Container : NSObject
+@end
+  )";
+  const std::string Main = "";
+  TestFileName = testPath("test.m");
+  runSymbolCollector(Header, Main, {"-F", FrameworksPath, "-xobjective-c++"});
+  EXPECT_THAT(Symbols, UnorderedElementsAre(
+   AllOf(QName("NSObject"),
+ IncludeHeader("\"Foundation/Foundation.h\"")),
+   AllOf(QName("Container";
+}
+
+TEST_F(SymbolCollectorTest, ObjCSystemUmbrellaFrameworkIncludeHeader) {
+  CollectorOpts.CollectIncludePath = true;
+  auto FrameworksPath = testPath("Frameworks/");
+  auto UmbrellaHeaderPath =
+  testPath("Frameworks/Foundation.framework/Headers/Foundation.h");
+  const std::string UmbrellaHeader = R"(
+#import 
+  )";
+  auto FrameworkHeaderPath =
+  testPath("Frameworks/Foundation.framework/Headers/NSObject.h");
+  const std::string FrameworkHeader = R"(
+__attribute((objc_root_class))
+@interface NSObject
+@end
+  )";
+  InMemoryFileSystem->addFile(UmbrellaHeaderPath, 0,
+  llvm::MemoryBuffer::getMemBuffer(UmbrellaHeader));
+  InMemoryFileSystem->addFile(
+  FrameworkHeaderPath, 0,
+  llvm::MemoryBuffer::getMemBuffer(FrameworkHeader));
+
+  const std::string Header = R"(
+#import 
+
+@interface Container : NSObject
+@end
+  )";
+  const std::string Main = "";
+  TestFileName = testPath("test.m");
+  runSymbolCollector(
+  Header, Main,
+  {"-iframeworkwithsysroot", FrameworksPath, "-xobjective-c++"});
+  EXPECT_THAT(Symbols, UnorderedElementsAre(
+   AllOf(QName("NSObject"),
+ IncludeHeader("")),
+   AllOf(QName(

[PATCH] D115253: [C2x] Support the *_WIDTH macros in limits.h and stdint.h

2022-01-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 399337.
aaron.ballman added a comment.

Updating based on review feedback -- adds the signed versions of the __macros__ 
for consistency and uses them in limits.h.


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

https://reviews.llvm.org/D115253

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Headers/limits.h
  clang/lib/Headers/stdint.h
  clang/test/Headers/limits.cpp
  clang/test/Headers/stdint.c
  clang/test/Preprocessor/init-aarch64.c
  clang/test/Preprocessor/init.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -715,11 +715,7 @@
 
   Two's complement sign representation
   http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf";>N2412
-  
-Partial
-  Lacking width macros in limits.h and stdint.h
-
-  
+  Clang 14
 
 
   Adding the u8 character prefix
Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1520,6 +1520,7 @@
 // WEBASSEMBLY-NEXT:#define __ATOMIC_RELEASE 3
 // WEBASSEMBLY-NEXT:#define __ATOMIC_SEQ_CST 5
 // WEBASSEMBLY-NEXT:#define __BIGGEST_ALIGNMENT__ 16
+// WEBASSEMBLY-NEXT:#define __BOOL_WIDTH__ 8
 // WEBASSEMBLY-NEXT:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
 // WEBASSEMBLY-NEXT:#define __CHAR16_TYPE__ unsigned short
 // WEBASSEMBLY-NEXT:#define __CHAR32_TYPE__ unsigned int
@@ -1609,21 +1610,25 @@
 // WEBASSEMBLY-NEXT:#define __INT16_FMTi__ "hi"
 // WEBASSEMBLY-NEXT:#define __INT16_MAX__ 32767
 // WEBASSEMBLY-NEXT:#define __INT16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT16_WIDTH__ 16
 // WEBASSEMBLY-NEXT:#define __INT32_C_SUFFIX__
 // WEBASSEMBLY-NEXT:#define __INT32_FMTd__ "d"
 // WEBASSEMBLY-NEXT:#define __INT32_FMTi__ "i"
 // WEBASSEMBLY-NEXT:#define __INT32_MAX__ 2147483647
 // WEBASSEMBLY-NEXT:#define __INT32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT32_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __INT64_C_SUFFIX__ LL
 // WEBASSEMBLY-NEXT:#define __INT64_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INT64_FMTi__ "lli"
 // WEBASSEMBLY-NEXT:#define __INT64_MAX__ 9223372036854775807LL
 // WEBASSEMBLY-NEXT:#define __INT64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT64_WIDTH__ 64
 // WEBASSEMBLY-NEXT:#define __INT8_C_SUFFIX__
 // WEBASSEMBLY-NEXT:#define __INT8_FMTd__ "hhd"
 // WEBASSEMBLY-NEXT:#define __INT8_FMTi__ "hhi"
 // WEBASSEMBLY-NEXT:#define __INT8_MAX__ 127
 // WEBASSEMBLY-NEXT:#define __INT8_TYPE__ signed char
+// WEBASSEMBLY-NEXT:#define __INT8_WIDTH__ 8
 // WEBASSEMBLY-NEXT:#define __INTMAX_C_SUFFIX__ LL
 // WEBASSEMBLY-NEXT:#define __INTMAX_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INTMAX_FMTi__ "lli"
@@ -1641,35 +1646,44 @@
 // WEBASSEMBLY-NEXT:#define __INT_FAST16_FMTi__ "hi"
 // WEBASSEMBLY-NEXT:#define __INT_FAST16_MAX__ 32767
 // WEBASSEMBLY-NEXT:#define __INT_FAST16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT_FAST16_WIDTH__ 16
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_FMTd__ "d"
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_FMTi__ "i"
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_MAX__ 2147483647
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT_FAST32_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_FMTi__ "lli"
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_MAX__ 9223372036854775807LL
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT_FAST64_WIDTH__ 64
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_FMTd__ "hhd"
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_FMTi__ "hhi"
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_MAX__ 127
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_TYPE__ signed char
+// WEBASSEMBLY-NEXT:#define __INT_FAST8_WIDTH__ 8
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_FMTd__ "hd"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_FMTi__ "hi"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_MAX__ 32767
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT_LEAST16_WIDTH__ 16
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_FMTd__ "d"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_FMTi__ "i"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_MAX__ 2147483647
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT_LEAST32_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_FMTi__ "lli"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_MAX__ 9223372036854775807LL
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT_LEAST64_WIDTH__ 64
 // WEBASSEMBLY-NEXT:#define __INT_LEAST8_FMTd__ "hhd"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST8_FMTi__ "hhi"
 // WEBASSEMBLY-NEXT:#

[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

2022-01-12 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen updated this revision to Diff 399334.
steffenlarsen added a comment.

I have made the changes suggested in my previous comment. This makes 
significantly more changes to the parsing of attribute arguments as the old 
path was needed for attributes that allow both expressions and types. It also 
required some new controlling arguments for `ParseExpressionList`.

Because these changes also allow intializer lists in attribute arguments I have 
added a test case showing that `clang::annotate` parses these but will not 
accept them.

@erichkeane & @aaron.ballman - Is this in line with what you were thinking?


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

https://reviews.llvm.org/D114439

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/SemaTemplate/attributes.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1164,10 +1164,12 @@
   };
 
   class VariadicExprArgument : public VariadicArgument {
+bool AllowPack = false;
+
   public:
 VariadicExprArgument(const Record &Arg, StringRef Attr)
-  : VariadicArgument(Arg, Attr, "Expr *")
-{}
+: VariadicArgument(Arg, Attr, "Expr *"),
+  AllowPack(Arg.getValueAsBit("AllowPack")) {}
 
 void writeASTVisitorTraversal(raw_ostream &OS) const override {
   OS << "  {\n";
@@ -2264,6 +2266,47 @@
   OS << "#endif // CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST\n\n";
 }
 
+static void emitClangAttrNumArgs(RecordKeeper &Records, raw_ostream &OS) {
+  OS << "#if defined(CLANG_ATTR_NUM_ARGS)\n";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+std::vector Args = A->getValueAsListOfDefs("Args");
+forEachUniqueSpelling(*A, [&](const FlattenedSpelling &S) {
+  OS << ".Case(\"" << S.name() << "\", " << Args.size() << ")\n";
+});
+  }
+  OS << "#endif // CLANG_ATTR_NUM_ARGS\n\n";
+}
+
+static bool argSupportsParmPack(const Record *Arg) {
+  return !Arg->getSuperClasses().empty() &&
+ llvm::StringSwitch(
+ Arg->getSuperClasses().back().first->getName())
+ .Case("VariadicExprArgument", true)
+ .Default(false) &&
+ Arg->getValueAsBit("AllowPack");
+}
+
+static void emitClangAttrLastArgParmPackSupport(RecordKeeper &Records,
+raw_ostream &OS) {
+  OS << "#if defined(CLANG_ATTR_LAST_ARG_PARM_PACK_SUPPORT)\n";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+std::vector Args = A->getValueAsListOfDefs("Args");
+bool LastArgSupportsParmPack =
+!Args.empty() && argSupportsParmPack(Args.back());
+forEachUniqueSpelling(*A, [&](const FlattenedSpelling &S) {
+  OS << ".Case(\"" << S.name() << "\", " << LastArgSupportsParmPack
+ << ")\n";
+});
+  }
+  OS << "#endif // CLANG_ATTR_LAST_ARG_PARM_PACK_SUPPORT\n\n";
+}
+
+static bool isArgVariadic(const Record &R, StringRef AttrName) {
+  return createArgument(R, AttrName)->isVariadic();
+}
+
 static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
bool Header) {
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
@@ -2320,6 +2363,18 @@
 std::vector> Args;
 Args.reserve(ArgRecords.size());
 
+if (!ArgRecords.empty()) {
+  const bool LastArgSupportsPack = argSupportsParmPack(ArgRecords.back());
+  for (size_t I = 0; I < ArgRecords.size() - 1; ++I) {
+assert((!LastArgSupportsPack ||
+!isArgVariadic(*ArgRecords[I], R.getName())) &&
+   "Attributes supporting packs can only have the last "
+   "argument as variadic");
+assert(!argSupportsParmPack(ArgRecords[I]) &&
+   "Only the last argument can allow packs");
+  }
+}
+
 bool HasOptArg = false;
 bool HasFakeArg = false;
 for (const auto *ArgRecord : ArgRecords) {
@@ -3382,10 +3437,6 @@
   }
 }
 
-static bool isArgVariadic(const Record &R, StringRef AttrName) {
-  return createArgument(R, AttrName)->isVariadic();
-}
-
 static void emitArgInfo(const Record &R, raw_ostream &OS) {
   // This function will count the number of arguments specified for the
   // attribute and emit the number of required arguments followed by the
@@ -4219,6 +4270,8 @@
   emitClangAttrIdentifierArgList(Records, OS);
   emitClangAttrVariadicIdentifierArgList(Records, OS);
   emitClangAttrThisIsaIdentifierArgList(Records, OS);
+  emitClangAttrNumArgs(Records, OS);
+  emitClangAttrLastArgParmPackSupport(Records, OS);

[PATCH] D115253: [C2x] Support the *_WIDTH macros in limits.h and stdint.h

2022-01-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:900-903
+  Builder.defineMacro("__USHRT_WIDTH__", Twine(TI.getShortWidth()));
+  Builder.defineMacro("__UINT_WIDTH__", Twine(TI.getIntWidth()));
+  Builder.defineMacro("__ULONG_WIDTH__", Twine(TI.getLongWidth()));
+  Builder.defineMacro("__ULLONG_WIDTH__", Twine(TI.getLongLongWidth()));

jyknight wrote:
> aaron.ballman wrote:
> > jyknight wrote:
> > > This seems odd? We define `__LONG_LONG_MAX__` but not 
> > > `__LONG_LONG_WIDTH__`, for signed long long, and we define 
> > > `__ULLONG_WIDTH__` but not `__ULLONG_MAX__`, for unsigned long long?
> > > This seems odd?
> > 
> > Yeah, this stuff is a bit twisty.
> > 
> > > We define __LONG_LONG_MAX__ but not __LONG_LONG_WIDTH__, for signed long 
> > > long,
> > 
> > Correct.
> > 
> > > and we define __ULLONG_WIDTH__ but not __ULLONG_MAX__, for unsigned long 
> > > long?
> > 
> > Correct.
> > 
> > The basic approach I took was: for types with signed/unsigned pairs, define 
> > the `unsigned` variants with an underscore name and use them to define the 
> > `signed` variants in the header file because the width of signed and 
> > unsigned has to be the same per spec ("The macro blah_WIDTH represents the 
> > width of the type blah and shall expand to the same value as Ublah_WIDTH.") 
> > So that's why you generally only see the "unsigned" width variants added 
> > here with a double underscore name. I could expose the signed versions as 
> > well (like we do for many of the MAX macros), but that makes the 
> > preprocessor slower for no real benefit as we want the users to use the 
> > non-underscore versions of these macros whenever possible.
> 1. But, in this patch, it is exposing WIDTH for both variants of all the 
> other types. Shouldn't we consistently expose WIDTH for only one of each pair 
> (e.g. intmax_t, int_fast16_t, etc), instead of exposing both for some types, 
> and one for others?
> 
> 2. Exposing it only for unsigned seems like the wrong choice and confusing, 
> since that implies having a basically-extraneous "U" in all of the names, and 
> is inconsistent with previous practice. Can we expose only the signed 
> variants instead of the unsigned?
Ah, I see what you mean now, thanks for pushing back. Yes, I can add the signed 
variants here so we expose both the signed and unsigned versions for everything 
consistently. I'll also switch the headers to use both the signed and unsigned 
variants as appropriate -- the tests ensure these values won't get out of sync.


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

https://reviews.llvm.org/D115253

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


[PATCH] D116511: [clang-cl] Support the /HOTPATCH flag

2022-01-12 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm with comments




Comment at: clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp:13
+// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=HOTPATCH
+// ERR-HOTPATCH: error: unsupported option '/hotpatch' for target
+// HOTPATCH: S_COMPILE3 [size = [[#]]]

Does MSVC error for ARM/ARM64 too, or does it just ignore the flag?



Comment at: clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp:19
+///
+// RUN: %clang_cl --target=aarch64-pc-windows-msvc /c %s -o %t.obj
+// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=NO-HOTPATCH

nit: We still need -- before %s with clang-cl (%s could be /Users/... and get 
interpreted as a flag), and so it needs to come last. Same for the line in 
debug-info-hotpatch.cpp.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116511

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


[PATCH] D116939: [AArch64] clang support for Armv8.8/9.3 HBC

2022-01-12 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 updated this revision to Diff 399341.
tyb0807 marked an inline comment as done.
tyb0807 added a comment.

Removed checks that set HBC flag based on the target architecture and unset it
if command line explicitly disables it. This is because HBC feature does not
require any new intrinsic in the IR, so the frontend does not need to know about
whether HBC flag is set or unset in the command line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116939

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/Driver/aarch64-hbc.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1485,43 +1485,41 @@
 }
 
 TEST(TargetParserTest, AArch64ArchExtFeature) {
-  const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
-  {"crypto", "nocrypto", "+crypto", "-crypto"},
-  {"flagm", "noflagm", "+flagm", "-flagm"},
-  {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
-  {"simd", "nosimd", "+neon", "-neon"},
-  {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
-  {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
-  {"profile", "noprofile", "+spe", "-spe"},
-  {"ras", "noras", "+ras", "-ras"},
-  {"lse", "nolse", "+lse", "-lse"},
-  {"rdm", "nordm", "+rdm", "-rdm"},
-  {"sve", "nosve", "+sve", "-sve"},
-  {"sve2", "nosve2", "+sve2", "-sve2"},
-  {"sve2-aes", "nosve2-aes", "+sve2-aes",
-   "-sve2-aes"},
-  {"sve2-sm4", "nosve2-sm4", "+sve2-sm4",
-   "-sve2-sm4"},
-  {"sve2-sha3", "nosve2-sha3", "+sve2-sha3",
-   "-sve2-sha3"},
-  {"sve2-bitperm", "nosve2-bitperm",
-   "+sve2-bitperm", "-sve2-bitperm"},
-  {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
-  {"rcpc", "norcpc", "+rcpc", "-rcpc" },
-  {"rng", "norng", "+rand", "-rand"},
-  {"memtag", "nomemtag", "+mte", "-mte"},
-  {"tme", "notme", "+tme", "-tme"},
-  {"pauth", "nopauth", "+pauth", "-pauth"},
-  {"ssbs", "nossbs", "+ssbs", "-ssbs"},
-  {"sb", "nosb", "+sb", "-sb"},
-  {"predres", "nopredres", "+predres", "-predres"},
-  {"i8mm", "noi8mm", "+i8mm", "-i8mm"},
-  {"f32mm", "nof32mm", "+f32mm", "-f32mm"},
-  {"f64mm", "nof64mm", "+f64mm", "-f64mm"},
-  {"sme", "nosme", "+sme", "-sme"},
-  {"sme-f64", "nosme-f64", "+sme-f64", "-sme-f64"},
-  {"sme-i64", "nosme-i64", "+sme-i64", "-sme-i64"},
-};
+  const char *ArchExt[][4] = {
+  {"crc", "nocrc", "+crc", "-crc"},
+  {"crypto", "nocrypto", "+crypto", "-crypto"},
+  {"flagm", "noflagm", "+flagm", "-flagm"},
+  {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
+  {"simd", "nosimd", "+neon", "-neon"},
+  {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
+  {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
+  {"profile", "noprofile", "+spe", "-spe"},
+  {"ras", "noras", "+ras", "-ras"},
+  {"lse", "nolse", "+lse", "-lse"},
+  {"rdm", "nordm", "+rdm", "-rdm"},
+  {"sve", "nosve", "+sve", "-sve"},
+  {"sve2", "nosve2", "+sve2", "-sve2"},
+  {"sve2-aes", "nosve2-aes", "+sve2-aes", "-sve2-aes"},
+  {"sve2-sm4", "nosve2-sm4", "+sve2-sm4", "-sve2-sm4"},
+  {"sve2-sha3", "nosve2-sha3", "+sve2-sha3", "-sve2-sha3"},
+  {"sve2-bitperm", "nosve2-bitperm", "+sve2-bitperm", "-sve2-bitperm"},
+  {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
+  {"rcpc", "norcpc", "+rcpc", "-rcpc"},
+  {"rng", "norng", "+rand", "-rand"},
+  {"memtag", "nomemtag", "+mte", "-mte"},
+  {"tme", "notme", "+tme", "-tme"},
+  {"pauth", "nopauth", "+pauth", "-pauth"},
+  {"ssbs", "nossbs", "+ssbs", "-ssbs"},
+  {"sb", "nosb", "+sb", "-sb"},
+  {"predres", "nopredres", "+predres", "-predres"},
+  {"i8mm", "noi8mm", "+i8mm", "-i8mm

[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks for the improvement!


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

https://reviews.llvm.org/D114787

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


[PATCH] D117123: [clang][dataflow] Add transfer functions for initializers

2022-01-12 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev created this revision.
sgatev added reviewers: ymandel, xazax.hun, gribozavr2.
Herald added a subscriber: rnkovacs.
sgatev requested review of this revision.
Herald added a project: clang.

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117123

Files:
  clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1171,4 +1171,114 @@
   });
 }
 
+TEST_F(TransferTest, ConstructorInitializer) {
+  std::string Code = R"(
+struct target {
+  int Bar;
+
+  target(int Foo) : Bar(Foo) {
+int Qux = Bar;
+// [[p]]
+  }
+};
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const auto *ThisLoc = dyn_cast(
+Env.getThisPointeeStorageLocation());
+ASSERT_THAT(ThisLoc, NotNull());
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+cast(Env.getValue(*FooDecl, SkipPast::None));
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+EXPECT_EQ(Env.getValue(*QuxDecl, SkipPast::None), FooVal);
+  });
+}
+
+TEST_F(TransferTest, DefaultInitializer) {
+  std::string Code = R"(
+struct target {
+  int Bar;
+  int Baz = Bar;
+
+  target(int Foo) : Bar(Foo) {
+int Qux = Baz;
+// [[p]]
+  }
+};
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const auto *ThisLoc = dyn_cast(
+Env.getThisPointeeStorageLocation());
+ASSERT_THAT(ThisLoc, NotNull());
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+cast(Env.getValue(*FooDecl, SkipPast::None));
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+EXPECT_EQ(Env.getValue(*QuxDecl, SkipPast::None), FooVal);
+  });
+}
+
+TEST_F(TransferTest, DefaultInitializerReference) {
+  std::string Code = R"(
+struct target {
+  int &Bar;
+  int &Baz = Bar;
+
+  target(int &Foo) : Bar(Foo) {
+int &Qux = Baz;
+// [[p]]
+  }
+};
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const auto *ThisLoc = dyn_cast(
+Env.getThisPointeeStorageLocation());
+ASSERT_THAT(ThisLoc, NotNull());
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+cast(Env.getValue(*FooDecl, SkipPast::None));
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const auto *QuxVal =
+cast(Env.getValue(*QuxDecl, SkipPast::None));
+EXPECT_EQ(&QuxVal->getPointeeLoc(), &FooVal->getPointeeLoc());
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -11,15 +11,18 @@
 //
 //===--===//
 
+#include 
 #include 
 #include 
 
+#include "clang/AST/DeclCXX.h"
 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/

[PATCH] D105340: [analyzer] Produce SymbolCast symbols for integral types in SValBuilder::evalCast

2022-01-12 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D105340#3237430 , @ASDenysPetrov 
wrote:

> In D105340#3232671 , @NoQ wrote:
>
>> This looks great with the option flag. Landing this patch will enable more 
>> people to test the new mode and produce feedback on whether the constraint 
>> solver keeps working well enough in presence of the new symbols.
>
> Many thanks for your approval, @NoQ! The upset thing is that to get this 
> loaded we also should close this parent revision D103094 
>  :-(

Actually, this patch does not depend on `castTo` and thus it is independent 
from the rest of the patch stack. So we could just land it as it is. (In this 
patch, you just create the `SymbolCast`s but there is no handling of that in 
the constraint manager which needs the `castTo`.)


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

https://reviews.llvm.org/D105340

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


[PATCH] D116701: Respect -fsanitize-memory-param-retval flag.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 399345.
kda added a comment.
Herald added subscribers: Sanitizers, ormris, dexonsmith, dang.
Herald added a project: Sanitizers.

enable eager-checks in llvm via flag (-fsanitize-memory-param-retval).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116701

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/attr-noundef.cpp
  clang/test/CodeGen/indirect-noundef.cpp
  compiler-rt/test/msan/noundef_analysis.cpp

Index: compiler-rt/test/msan/noundef_analysis.cpp
===
--- compiler-rt/test/msan/noundef_analysis.cpp
+++ compiler-rt/test/msan/noundef_analysis.cpp
@@ -2,6 +2,8 @@
 // RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
 // RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan %s -fsanitize-memory-param-retval -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
 
 struct SimpleStruct {
   int md1;
Index: clang/test/CodeGen/indirect-noundef.cpp
===
--- clang/test/CodeGen/indirect-noundef.cpp
+++ clang/test/CodeGen/indirect-noundef.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -fsanitize-memory-param-retval -o - %s | FileCheck %s
 
 union u1 {
   int val;
Index: clang/test/CodeGen/attr-noundef.cpp
===
--- clang/test/CodeGen/attr-noundef.cpp
+++ clang/test/CodeGen/attr-noundef.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
 // RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
 
 // Passing structs by value
 // TODO: No structs may currently be marked noundef
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -641,10 +641,14 @@
 Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
  options::OPT_fno_sanitize_memory_use_after_dtor,
  MsanUseAfterDtor);
+MsanParamRetval = Args.hasFlag(
+options::OPT_fsanitize_memory_param_retval,
+options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   } else {
 MsanUseAfterDtor = false;
+MsanParamRetval = false;
   }
 
   if (AllAddedKinds & SanitizerKind::Thread) {
@@ -1096,6 +1100,9 @@
   if (MsanUseAfterDtor)
 CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
 
+  if (MsanParamRetval)
+CmdArgs.push_back("-fsanitize-memory-param-retval");
+
   // FIXME: Pass these parameters as function attributes, not as -llvm flags.
   if (!TsanMemoryAccess) {
 CmdArgs.push_back("-mllvm");
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1620,6 +1620,8 @@
 
   llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
StringRef Suffix);
+
+  bool NoundefAnalysisEnabled = false;
 };
 
 }  // end namespace CodeGen
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -209,6 +209,9 @@
 ModuleNameHash = (Twine(".__uniq.") +
 Twine(toString(IntHash, /* Radix = */ 10, /* Signed = */false))).str();
   }
+
+  NoundefAnalysisEnabled =
+  CodeGenOpts.EnableNoundefAttrs || CodeGenOpts.SanitizeMemoryParamRetval;
 }
 
 CodeGenModule::~CodeGenModule() {}
Index: clang/lib/CodeGen/CGCall.cpp
==

[PATCH] D116701: Respect -fsanitize-memory-param-retval flag.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 399347.
kda added a comment.

Correcting diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116701

Files:
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  compiler-rt/test/msan/noundef_analysis.cpp


Index: compiler-rt/test/msan/noundef_analysis.cpp
===
--- compiler-rt/test/msan/noundef_analysis.cpp
+++ compiler-rt/test/msan/noundef_analysis.cpp
@@ -2,6 +2,8 @@
 // RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
 // RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm 
-msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan %s -fsanitize-memory-param-retval -o %t && not %run %t 
>%t.out 2>&1
+// RUN: FileCheck %s < %t.out
 
 struct SimpleStruct {
   int md1;
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -641,10 +641,14 @@
 Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
  options::OPT_fno_sanitize_memory_use_after_dtor,
  MsanUseAfterDtor);
+MsanParamRetval = Args.hasFlag(
+options::OPT_fsanitize_memory_param_retval,
+options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   } else {
 MsanUseAfterDtor = false;
+MsanParamRetval = false;
   }
 
   if (AllAddedKinds & SanitizerKind::Thread) {
@@ -1096,6 +1100,9 @@
   if (MsanUseAfterDtor)
 CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
 
+  if (MsanParamRetval)
+CmdArgs.push_back("-fsanitize-memory-param-retval");
+
   // FIXME: Pass these parameters as function attributes, not as -llvm flags.
   if (!TsanMemoryAccess) {
 CmdArgs.push_back("-mllvm");
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -358,7 +358,8 @@
   int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins;
   bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Memory);
   PM.add(createMemorySanitizerLegacyPassPass(
-  MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
+  MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel,
+ CGOpts.SanitizeMemoryParamRetval != 0}));
 
   // MemorySanitizer inserts complex instrumentation that mostly follows
   // the logic of the original code, but operates on "shadow" values.
@@ -1163,11 +1164,11 @@
 int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
 bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
 
-MPM.addPass(
-ModuleMemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
+   CodeGenOpts.SanitizeMemoryParamRetval);
+MPM.addPass(ModuleMemorySanitizerPass(options));
 FunctionPassManager FPM;
-FPM.addPass(
-MemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+FPM.addPass(MemorySanitizerPass(options));
 if (Level != OptimizationLevel::O0) {
   // MemorySanitizer inserts complex instrumentation that mostly
   // follows the logic of the original code, but operates on
Index: clang/include/clang/Driver/SanitizerArgs.h
===
--- clang/include/clang/Driver/SanitizerArgs.h
+++ clang/include/clang/Driver/SanitizerArgs.h
@@ -33,6 +33,7 @@
   int CoverageFeatures = 0;
   int MsanTrackOrigins = 0;
   bool MsanUseAfterDtor = true;
+  bool MsanParamRetval = false;
   bool CfiCrossDso = false;
   bool CfiICallGeneralizePointers = false;
   bool CfiCanonicalJumpTables = false;


Index: compiler-rt/test/msan/noundef_analysis.cpp
===
--- compiler-rt/test/msan/noundef_analysis.cpp
+++ compiler-rt/test/msan/noundef_analysis.cpp
@@ -2,6 +2,8 @@
 // RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
 // RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan %s -fsanitize-memory-param-retval -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
 
 struct SimpleStruct {
   int md1;
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -641,10 +64

[PATCH] D116701: Respect -fsanitize-memory-param-retval flag.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda added a comment.

PTAL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116701

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


[PATCH] D115932: [Analyzer] Create and handle SymbolCast for pointer to integral conversion

2022-01-12 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thanks for the review guys.

Artem, I agree, that we should remove `LocAsInteger`. `LocaAsInteger` is a 
primitive handling of a specific cast operation (when we cast a pointer to an 
integer). The integration of  `LocaAsInteger` into the `SymExpr` hierarchy is 
problematic as both this patch and its parent shows.

For precision, we should produce a `SymbolCast` when we evaluate a cast 
operation of a pointer to an integral type. I agree with Denys, that 
`makeSymExprValNN` is probably not the best place to do that. I took Denys' 
patch D105340  and created a prototype on top 
of that to create the `SymbolCast` in 
`SValBuilder::evalCastSubKind(loc::MemRegionVal V,`.

  void test_param(int *p) {
long p_as_integer = (long)p;
clang_analyzer_dump(p);// 
expected-warning{{&SymRegion{reg_$0}}}
clang_analyzer_dump(p_as_integer); // expected-warning{{(long) (reg_$0)}}

I'd like to upload that soon.

Once we produce the `SymbolCast`s, then we can start handling them 
semantically. In my opinion, we should follow these steps:

1. Produce `SymbolCast`s. This is done in D105340 
, plus I am going to create another patch for 
pointer-to-int casts.
2. Handle `SymbolCast`s for the simplest cases. E.g. when we cast a (64bit 
width) pointer to a (64bit width unsigned) integer. This requires the 
foundation for an additional mapping in the `ProgramState` that can map a base 
symbol to cast symbols. This would be used in the constraint manager and this 
mapping must be super efficient.
3. Gradually handle more complex `SymbolCast` semantics. E.g. a widening cast.
4. Remove `LocAsInteger`. Produce the `SymbolCast`s by default and remove the 
option of `ShouldSupportSymbolicIntegerCasts`.

Point 2) and 3) are already started in D103096 
. But again, I think first we have to get the 
solid foundations with the `State` and with the `ConstraintManager` before 
getting into the more complex implementations of widening.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115932

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


[PATCH] D116511: [clang-cl] Support the /HOTPATCH flag

2022-01-12 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea marked 2 inline comments as done.
aganea added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp:13
+// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=HOTPATCH
+// ERR-HOTPATCH: error: unsupported option '/hotpatch' for target
+// HOTPATCH: S_COMPILE3 [size = [[#]]]

hans wrote:
> Does MSVC error for ARM/ARM64 too, or does it just ignore the flag?
It prints a warning:
```
D:\git\llvm-project>cl /c main.cpp /hotpatch
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30138 for ARM64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '/hotpatch'
main.cpp
```
But in our case, the issue is that `PATCHABLE_OP` isn't supported on ARM 
backend, so it ends up asserting in 
`D:/git/llvm-project/release/lib/Target/AArch64/AArch64GenMCCodeEmitter.inc` in 
`AArch64MCCodeEmitter::getBinaryCodeForInstr`. There's perhaps a (better?) way 
for shortcutting the use of `/hotpatch` on ARM, instead of erroring-out like 
today.

Should we be more clear in the message, saying that hotpatching is supported 
but we don't the flag? Or just consume and ignore it?



Comment at: clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp:19
+///
+// RUN: %clang_cl --target=aarch64-pc-windows-msvc /c %s -o %t.obj
+// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=NO-HOTPATCH

hans wrote:
> nit: We still need -- before %s with clang-cl (%s could be /Users/... and get 
> interpreted as a flag), and so it needs to come last. Same for the line in 
> debug-info-hotpatch.cpp.
Thanks will do!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116511

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


[PATCH] D105169: [Clang/Test]: Rename enable_noundef_analysis to disable-noundef-analysis and turn it off by default

2022-01-12 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

In D105169#3236484 , @hyeongyukim 
wrote:

> @nathanchance
>
> I tried to reproduce the last warning (intelfbhw_validate_mode), but I failed 
> to produce it.
> I think my reproducer is correct, but it does not make any warning.
> Can you tell me which part was wrong?
>
>   clang -O2 -flto=thin -fsanitize=integer-divide-by-zero -c -o intelfb.o 
> intelfb.i
>   ld.lld -m elf_x86_64 -r -o intelfb.lto.o --whole-archive intelfb.o
>   objtool orc generate --module --no-fp --no-unreachable --uaccess --mcount 
> intelfb.lto.o
>
> I use these commands, and I attached the `intelfb.i` file.F21595840: 
> intelfb.i 

It looks like this particular case also needs `-fsanitize-coverage=trace-pc` 
(which comes from `CONFIG_KCOV`). Once I add that with your reduced reproducer, 
I see the initial warning.

  $ clang -O2 -flto=thin -fsanitize=integer-divide-by-zero 
-fsanitize-coverage=trace-pc -c -o intelfb.{o,i}
  
  $ ld.lld -m elf_x86_64 -r -o intelfb.lto.o --whole-archive intelfb.o
  
  $ ./objtool orc generate --module --no-fp --no-unreachable --uaccess --mcount 
intelfb.lto.o
  intelfb.lto.o: warning: objtool: .text.intelfbhw_validate_mode: unexpected 
end of section


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105169

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


[PATCH] D116701: Respect -fsanitize-memory-param-retval flag.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 399352.
kda added a comment.
Herald added subscribers: luke957, s.egerton, simoncook.

add param usage test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116701

Files:
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/fsanitize-memory-param-retval.c
  compiler-rt/test/msan/noundef_analysis.cpp

Index: compiler-rt/test/msan/noundef_analysis.cpp
===
--- compiler-rt/test/msan/noundef_analysis.cpp
+++ compiler-rt/test/msan/noundef_analysis.cpp
@@ -2,6 +2,8 @@
 // RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
 // RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan %s -fsanitize-memory-param-retval -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
 
 struct SimpleStruct {
   int md1;
Index: clang/test/Driver/fsanitize-memory-param-retval.c
===
--- /dev/null
+++ clang/test/Driver/fsanitize-memory-param-retval.c
@@ -0,0 +1,12 @@
+// RUN: %clang -target i386-gnu-linux %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
+// RUN: %clang -target x86_64-linux-gnu %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
+// 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
+// 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
+// 11: "-fsanitize-memory-param-retval"
+
+// RUN: not %clang -target x86_64-linux-gnu -fsyntax-only %s -fsanitize=memory -fsanitize-memory-param-retval=1 2>&1 | FileCheck --check-prefix=EXCESS %s
+// EXCESS: error: unknown argument: '-fsanitize-memory-param-retval=
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -641,10 +641,14 @@
 Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
  options::OPT_fno_sanitize_memory_use_after_dtor,
  MsanUseAfterDtor);
+MsanParamRetval = Args.hasFlag(
+options::OPT_fsanitize_memory_param_retval,
+options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   } else {
 MsanUseAfterDtor = false;
+MsanParamRetval = false;
   }
 
   if (AllAddedKinds & SanitizerKind::Thread) {
@@ -1096,6 +1100,9 @@
   if (MsanUseAfterDtor)
 CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
 
+  if (MsanParamRetval)
+CmdArgs.push_back("-fsanitize-memory-param-retval");
+
   // FIXME: Pass these parameters as function attributes, not as -llvm flags.
   if (!TsanMemoryAccess) {
 CmdArgs.push_back("-mllvm");
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -358,7 +358,8 @@
   int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins;
   bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Memory);
   PM.add(createMemorySanitizerLegacyPassPass(
-  MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
+  MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel,
+ CGOpts.SanitizeMemoryParamRetval != 0}));
 
   // MemorySanitizer inserts complex instrumentation that mostly follows
   // the logic of the original code, but operates on "shadow" values.
@@ -1163,11 +1164,11 @@
 int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
 bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
 
-MPM.addPass(
-ModuleMemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
+   CodeGenOpts.SanitizeMemoryParamRetval);
+MPM.addPass(ModuleMemorySanitizerPass(options));
 FunctionPassManager FPM;
-FPM.addPass(
-MemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+FPM.addPass(MemorySanitizerPass(options));
 if (Level != OptimizationLevel::O0) {
   // MemorySanitiz

[PATCH] D115932: [Analyzer] Create and handle SymbolCast for pointer to integral conversion

2022-01-12 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Ah, I forgot to mention one last point:

5. Revert D115149 . We should never reach 
that problematic assertion once we produce the `SymbolCast`s.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115932

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


[clang] 118f966 - [clang][#51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-12 Thread Markus Böck via cfe-commits

Author: Markus Böck
Date: 2022-01-12T18:21:46+01:00
New Revision: 118f966b46cfb60897b56a9878e1c68fd0e2afa4

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

LOG: [clang][#51931] Enable `-Wdeclaration-after-statement` for all C versions

-Wdeclaration-after-statement currently only outputs an diagnostic if the user 
is compiling in C versions older than C99, even if the warning was explicitly 
requested by the user.
This patch makes the warning also available in later C versions. If the C 
version is C99 or later it is simply a normal warning that is disabled by 
default (as it is valid C99) and has to be enabled by users. In older versions 
it remains an extension warning, and therefore affected by -pedantic.

The above behaviour also matches GCCs behaviour.

Fixes https://bugs.llvm.org/show_bug.cgi?id=51931

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

Added: 
clang/test/Sema/warn-mixed-decls.c

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index c0642efaee4e..1bc879a68a8c 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -241,6 +241,7 @@ def Documentation : DiagGroup<"documentation",
 
 def EmptyBody : DiagGroup<"empty-body">;
 def Exceptions : DiagGroup<"exceptions">;
+def DeclarationAfterStatement : DiagGroup<"declaration-after-statement">;
 
 def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">;
 def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dfd1069096ea..19ce0ffcec51 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9861,8 +9861,11 @@ def err_constant_integer_arg_type : Error<
   "argument to %0 must be a constant integer">;
 
 def ext_mixed_decls_code : Extension<
-  "ISO C90 forbids mixing declarations and code">,
-  InGroup>;
+  "mixing declarations and code is a C99 extension">,
+  InGroup;
+def warn_mixed_decls_code : Warning<
+  "mixing declarations and code is incompatible with standards before C99">,
+  InGroup, DefaultIgnore;
 
 def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 7fe92f492b5e..ef498f9a5228 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -410,9 +410,10 @@ StmtResult Sema::ActOnCompoundStmt(SourceLocation L, 
SourceLocation R,
ArrayRef Elts, bool isStmtExpr) {
   const unsigned NumElts = Elts.size();
 
-  // If we're in C89 mode, check that we don't have any decls after stmts.  If
-  // so, emit an extension diagnostic.
-  if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) {
+  // If we're in C mode, check that we don't have any decls after stmts.  If
+  // so, emit an extension diagnostic in C89 and potentially a warning in later
+  // versions.
+  if (!getLangOpts().CPlusPlus) {
 // Note that __extension__ can be around a decl.
 unsigned i = 0;
 // Skip over all declarations.
@@ -425,7 +426,8 @@ StmtResult Sema::ActOnCompoundStmt(SourceLocation L, 
SourceLocation R,
 
 if (i != NumElts) {
   Decl *D = *cast(Elts[i])->decl_begin();
-  Diag(D->getLocation(), diag::ext_mixed_decls_code);
+  Diag(D->getLocation(), !getLangOpts().C99 ? diag::ext_mixed_decls_code
+: diag::warn_mixed_decls_code);
 }
   }
 

diff  --git a/clang/test/Sema/warn-mixed-decls.c 
b/clang/test/Sema/warn-mixed-decls.c
new file mode 100644
index ..219d64472b58
--- /dev/null
+++ b/clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,28 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 
-Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ 
-Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i;
+#if __STDC_VERSION__ < 199901L
+  /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
+#else
+  /* expected-warning@-4 {{mixing declarations and code is incompatib

[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-12 Thread Markus Böck via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG118f966b46cf: [clang][#51931] Enable 
`-Wdeclaration-after-statement` for all C versions (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114787

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/warn-mixed-decls.c


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,28 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 
-Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ 
-Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i;
+#if __STDC_VERSION__ < 199901L
+  /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
+#else
+  /* expected-warning@-4 {{mixing declarations and code is incompatible with 
standards before C99}}*/
+#endif
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -410,9 +410,10 @@
ArrayRef Elts, bool isStmtExpr) {
   const unsigned NumElts = Elts.size();
 
-  // If we're in C89 mode, check that we don't have any decls after stmts.  If
-  // so, emit an extension diagnostic.
-  if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) {
+  // If we're in C mode, check that we don't have any decls after stmts.  If
+  // so, emit an extension diagnostic in C89 and potentially a warning in later
+  // versions.
+  if (!getLangOpts().CPlusPlus) {
 // Note that __extension__ can be around a decl.
 unsigned i = 0;
 // Skip over all declarations.
@@ -425,7 +426,8 @@
 
 if (i != NumElts) {
   Decl *D = *cast(Elts[i])->decl_begin();
-  Diag(D->getLocation(), diag::ext_mixed_decls_code);
+  Diag(D->getLocation(), !getLangOpts().C99 ? diag::ext_mixed_decls_code
+: diag::warn_mixed_decls_code);
 }
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9861,8 +9861,11 @@
   "argument to %0 must be a constant integer">;
 
 def ext_mixed_decls_code : Extension<
-  "ISO C90 forbids mixing declarations and code">,
-  InGroup>;
+  "mixing declarations and code is a C99 extension">,
+  InGroup;
+def warn_mixed_decls_code : Warning<
+  "mixing declarations and code is incompatible with standards before C99">,
+  InGroup, DefaultIgnore;
 
 def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -241,6 +241,7 @@
 
 def EmptyBody : DiagGroup<"empty-body">;
 def Exceptions : DiagGroup<"exceptions">;
+def DeclarationAfterStatement : DiagGroup<"declaration-after-statement">;
 
 def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">;
 def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">;


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,28 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ -Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i;
+#if __STDC_VERSION__ < 199901L
+  /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
+#else
+  /* expected-warning@-4 {{mixing declarations and code is incompatible with standards before C99}}*/
+#endif
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===

[PATCH] D116994: [RISCV] Add bfp and bfpw intrinsic in zbf extension

2022-01-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper 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/D116994/new/

https://reviews.llvm.org/D116994

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


[PATCH] D116633: Add -fsanitize-address-param-retval to clang.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 399362.
kda added a comment.

add test to validate that flag does not conflict with enable-noundef-analysis


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116633

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/attr-noundef.cpp
  clang/test/CodeGen/indirect-noundef.cpp

Index: clang/test/CodeGen/indirect-noundef.cpp
===
--- clang/test/CodeGen/indirect-noundef.cpp
+++ clang/test/CodeGen/indirect-noundef.cpp
@@ -1,4 +1,9 @@
 // RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -fsanitize-memory-param-retval -o - %s | FileCheck %s
+
+// no-sanitize-memory-param-retval does NOT conflict with enable-noundef-analysis
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -fno-sanitize-memory-param-retval -enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -fno-sanitize-memory-param-retval -o - %s | FileCheck %s
 
 union u1 {
   int val;
Index: clang/test/CodeGen/attr-noundef.cpp
===
--- clang/test/CodeGen/attr-noundef.cpp
+++ clang/test/CodeGen/attr-noundef.cpp
@@ -1,5 +1,11 @@
 // RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
 // RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+
+// no-sanitize-memory-param-retval does NOT conflict with enable-noundef-analysis
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis -fno-sanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fno-sanitize-memory-param-retval -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
 
 // Passing structs by value
 // TODO: No structs may currently be marked noundef
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1620,6 +1620,8 @@
 
   llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
StringRef Suffix);
+
+  bool NoundefAnalysisEnabled = false;
 };
 
 }  // end namespace CodeGen
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -209,6 +209,9 @@
 ModuleNameHash = (Twine(".__uniq.") +
 Twine(toString(IntHash, /* Radix = */ 10, /* Signed = */false))).str();
   }
+
+  NoundefAnalysisEnabled =
+  CodeGenOpts.EnableNoundefAttrs || CodeGenOpts.SanitizeMemoryParamRetval;
 }
 
 CodeGenModule::~CodeGenModule() {}
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2243,7 +2243,7 @@
  getLangOpts().Sanitize.has(SanitizerKind::Return);
 
   // Determine if the return type could be partially undef
-  if (CodeGenOpts.EnableNoundefAttrs && HasStrictReturn) {
+  if (NoundefAnalysisEnabled && HasStrictReturn) {
 if (!RetTy->isVoidType() && RetAI.getKind() != ABIArgInfo::Indirect &&
 DetermineNoUndef(RetTy, getTypes(), DL, RetAI))
   RetAttrs.addAttribute(llvm::Attribute::NoUndef);
@@ -2378,7 +2378,7 @@
 
 // Decide whether the argument we're handling could be partially undef
 bool ArgNoUndef = DetermineNoUndef(ParamType, getTypes(), DL, AI);
-if (CodeGenOpts.EnableNoundefAttrs && ArgNoUndef)
+if (NoundefAnalysisEnabled && ArgNoUndef)
   Attrs.addAttribute(llvm::Attribute::NoUndef);
 
 // 'restrict' -> 'noalias' is done in EmitFunctionProlog when we
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driv

[PATCH] D116633: Add -fsanitize-address-param-retval to clang.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda added a comment.

>>> This needs a clang/test/Driver test to show that `%clang 
>>> -fsanitize-memory-param-retval` translates to CC1 
>>> `-fsanitize-memory-param-retval`.
>>
>> Could you point me to an example?
>
> `test/Driver/fpatchable-function-entry.c` `test/Driver/fbinutils-version.c` :)

I added some conflict tests here.
I added the CC1 tests to: https://reviews.llvm.org/D116701


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116633

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


[PATCH] D115253: [C2x] Support the *_WIDTH macros in limits.h and stdint.h

2022-01-12 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:900-903
+  Builder.defineMacro("__USHRT_WIDTH__", Twine(TI.getShortWidth()));
+  Builder.defineMacro("__UINT_WIDTH__", Twine(TI.getIntWidth()));
+  Builder.defineMacro("__ULONG_WIDTH__", Twine(TI.getLongWidth()));
+  Builder.defineMacro("__ULLONG_WIDTH__", Twine(TI.getLongLongWidth()));

aaron.ballman wrote:
> jyknight wrote:
> > aaron.ballman wrote:
> > > jyknight wrote:
> > > > This seems odd? We define `__LONG_LONG_MAX__` but not 
> > > > `__LONG_LONG_WIDTH__`, for signed long long, and we define 
> > > > `__ULLONG_WIDTH__` but not `__ULLONG_MAX__`, for unsigned long long?
> > > > This seems odd?
> > > 
> > > Yeah, this stuff is a bit twisty.
> > > 
> > > > We define __LONG_LONG_MAX__ but not __LONG_LONG_WIDTH__, for signed 
> > > > long long,
> > > 
> > > Correct.
> > > 
> > > > and we define __ULLONG_WIDTH__ but not __ULLONG_MAX__, for unsigned 
> > > > long long?
> > > 
> > > Correct.
> > > 
> > > The basic approach I took was: for types with signed/unsigned pairs, 
> > > define the `unsigned` variants with an underscore name and use them to 
> > > define the `signed` variants in the header file because the width of 
> > > signed and unsigned has to be the same per spec ("The macro blah_WIDTH 
> > > represents the width of the type blah and shall expand to the same value 
> > > as Ublah_WIDTH.") So that's why you generally only see the "unsigned" 
> > > width variants added here with a double underscore name. I could expose 
> > > the signed versions as well (like we do for many of the MAX macros), but 
> > > that makes the preprocessor slower for no real benefit as we want the 
> > > users to use the non-underscore versions of these macros whenever 
> > > possible.
> > 1. But, in this patch, it is exposing WIDTH for both variants of all the 
> > other types. Shouldn't we consistently expose WIDTH for only one of each 
> > pair (e.g. intmax_t, int_fast16_t, etc), instead of exposing both for some 
> > types, and one for others?
> > 
> > 2. Exposing it only for unsigned seems like the wrong choice and confusing, 
> > since that implies having a basically-extraneous "U" in all of the names, 
> > and is inconsistent with previous practice. Can we expose only the signed 
> > variants instead of the unsigned?
> Ah, I see what you mean now, thanks for pushing back. Yes, I can add the 
> signed variants here so we expose both the signed and unsigned versions for 
> everything consistently. I'll also switch the headers to use both the signed 
> and unsigned variants as appropriate -- the tests ensure these values won't 
> get out of sync.
It's not clear to me why you made that change in response to my comments.

You gave a good rationale before as to why we don't want to have both signed 
and unsigned versions of the macros, so the change I was trying to suggest in 
my last comment is to //consistently// expose only the signed variants for 
`__*_WIDTH__`, and not the unsigned variants.

For comparison, gcc 11.2, `gcc -E -dM -xc /dev/null |grep WIDTH|sort` gives:
```
#define __INT_FAST16_WIDTH__ 64
#define __INT_FAST32_WIDTH__ 64
#define __INT_FAST64_WIDTH__ 64
#define __INT_FAST8_WIDTH__ 8
#define __INT_LEAST16_WIDTH__ 16
#define __INT_LEAST32_WIDTH__ 32
#define __INT_LEAST64_WIDTH__ 64
#define __INT_LEAST8_WIDTH__ 8
#define __INTMAX_WIDTH__ 64
#define __INTPTR_WIDTH__ 64
#define __INT_WIDTH__ 32
#define __LONG_LONG_WIDTH__ 64
#define __LONG_WIDTH__ 64
#define __PTRDIFF_WIDTH__ 64
#define __SCHAR_WIDTH__ 8
#define __SHRT_WIDTH__ 16
#define __SIG_ATOMIC_WIDTH__ 32
#define __SIZE_WIDTH__ 64
#define __WCHAR_WIDTH__ 32
#define __WINT_WIDTH__ 32
```


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

https://reviews.llvm.org/D115253

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


[clang] 3a32d2e - [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and watchOS availability

2022-01-12 Thread Egor Zhdan via cfe-commits

Author: Egor Zhdan
Date: 2022-01-12T17:40:18Z
New Revision: 3a32d2e74e5c03d97a41ef7b0a01f206af62ad4f

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

LOG: [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and 
watchOS availability

This makes the mapping between iOS & tvOS/watchOS versions more accurate. For 
example, iOS 9.3 now gets correctly mapped into tvOS 9.2 and not tvOS 9.3.

Before this change, the incorrect mapping could cause excessive or missing 
warnings for code that specifies availability for iOS, but not for tvOS/watchOS.

rdar://81491680

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

Added: 
clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json
clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json

Modified: 
clang/include/clang/Basic/DarwinSDKInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/attr-availability-tvos.c
clang/test/Sema/attr-availability-watchos.c

Removed: 




diff  --git a/clang/include/clang/Basic/DarwinSDKInfo.h 
b/clang/include/clang/Basic/DarwinSDKInfo.h
index b0673dc8b3cd8..df16827debfc0 100644
--- a/clang/include/clang/Basic/DarwinSDKInfo.h
+++ b/clang/include/clang/Basic/DarwinSDKInfo.h
@@ -57,6 +57,20 @@ class DarwinSDKInfo {
llvm::Triple::MacOSX, llvm::Triple::UnknownEnvironment);
 }
 
+/// Returns the os-environment mapping pair that's used to represent the
+/// iOS -> watchOS version mapping.
+static inline constexpr OSEnvPair iOStoWatchOSPair() {
+  return OSEnvPair(llvm::Triple::IOS, llvm::Triple::UnknownEnvironment,
+   llvm::Triple::WatchOS, 
llvm::Triple::UnknownEnvironment);
+}
+
+/// Returns the os-environment mapping pair that's used to represent the
+/// iOS -> tvOS version mapping.
+static inline constexpr OSEnvPair iOStoTvOSPair() {
+  return OSEnvPair(llvm::Triple::IOS, llvm::Triple::UnknownEnvironment,
+   llvm::Triple::TvOS, llvm::Triple::UnknownEnvironment);
+}
+
   private:
 StorageType Value;
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b4d8d1494e705..b1ef02865328f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1565,8 +1565,11 @@ class Sema final {
   /// assignment.
   llvm::DenseMap RefsMinusAssignments;
 
+private:
   Optional> CachedDarwinSDKInfo;
 
+  bool WarnedDarwinSDKInfoMissing = false;
+
 public:
   Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
TranslationUnitKind TUKind = TU_Complete,
@@ -1595,8 +1598,10 @@ class Sema final {
   ASTConsumer &getASTConsumer() const { return Consumer; }
   ASTMutationListener *getASTMutationListener() const;
   ExternalSemaSource* getExternalSource() const { return ExternalSource; }
+
   DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc,
  StringRef Platform);
+  DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking();
 
   ///Registers an external source. If an external source already exists,
   /// creates a multiplex external source and appends to it.

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 60f37c17c3f18..aaa31adf2e97a 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -60,6 +60,16 @@ ModuleLoader &Sema::getModuleLoader() const { return 
PP.getModuleLoader(); }
 DarwinSDKInfo *
 Sema::getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc,
   StringRef Platform) {
+  auto *SDKInfo = getDarwinSDKInfoForAvailabilityChecking();
+  if (!SDKInfo && !WarnedDarwinSDKInfoMissing) {
+Diag(Loc, diag::warn_missing_sdksettings_for_availability_checking)
+<< Platform;
+WarnedDarwinSDKInfoMissing = true;
+  }
+  return SDKInfo;
+}
+
+DarwinSDKInfo *Sema::getDarwinSDKInfoForAvailabilityChecking() {
   if (CachedDarwinSDKInfo)
 return CachedDarwinSDKInfo->get();
   auto SDKInfo = parseDarwinSDKInfo(
@@ -71,8 +81,6 @@ Sema::getDarwinSDKInfoForAvailabilityChecking(SourceLocation 
Loc,
   }
   if (!SDKInfo)
 llvm::consumeError(SDKInfo.takeError());
-  Diag(Loc, diag::warn_missing_sdksettings_for_availability_checking)
-  << Platform;
   CachedDarwinSDKInfo = std::unique_ptr();
   return nullptr;
 }

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 642b878e02706..955f477760429 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2625,9 +2625,25 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
   NewII = &S.Context.Idents.get("watchos_app_extension");

[PATCH] D116822: [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and watchOS availability

2022-01-12 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a32d2e74e5c: [Clang][Sema] Use VersionMap from SDKSettings 
for remapping tvOS and watchOS… (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116822

Files:
  clang/include/clang/Basic/DarwinSDKInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json
  clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json
  clang/test/Sema/attr-availability-tvos.c
  clang/test/Sema/attr-availability-watchos.c

Index: clang/test/Sema/attr-availability-watchos.c
===
--- clang/test/Sema/attr-availability-watchos.c
+++ clang/test/Sema/attr-availability-watchos.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 "-triple" "arm64-apple-watchos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/WatchOS7.0.sdk -fsyntax-only -verify %s
 
 void f0(int) __attribute__((availability(ios,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
 void f1(int) __attribute__((availability(ios,introduced=2.1)));
@@ -58,3 +59,19 @@
 void test_ios_correctly_map_to_watchos() {
   deprecatedAfterIntroduced(); // expected-warning {{'deprecatedAfterIntroduced' is deprecated: first deprecated in watchOS 3}}
 }
+
+#ifdef USE_VERSION_MAP
+// iOS 10.3.1 corresponds to watchOS 3.2, as indicated in 'SDKSettings.json'.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.2}}
+}
+#else
+// Without VersionMap, watchOS version is inferred incorrectly as 3.3.1.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithoutVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.3.1}}
+}
+#endif
Index: clang/test/Sema/attr-availability-tvos.c
===
--- clang/test/Sema/attr-availability-tvos.c
+++ clang/test/Sema/attr-availability-tvos.c
@@ -1,63 +1,80 @@
-// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/AppleTVOS15.0.sdk -fsyntax-only -verify %s
 
-void f0(int) __attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
-void f1(int) __attribute__((availability(tvos,introduced=2.1)));
-void f2(int) __attribute__((availability(tvos,introduced=2.0,deprecated=3.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
-void f3(int) __attribute__((availability(tvos,introduced=3.0)));
-void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
+void f0(int) __attribute__((availability(tvos,introduced=12.0,deprecated=12.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(tvos,introduced=12.1)));
+void f2(int) __attribute__((availability(tvos,introduced=12.0,deprecated=13.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(tvos,introduced=13.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=12.0,deprecated=12.1,obsoleted=13.0))); // expected-note{{explicitly marked unavailable}}
 
-void f5(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,introduced=2.0)));
+void f5(int) __attribute__((availability(tvos,introduced=12.0))) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,introduced=12.0)));
 
 void test() {
-  f0(0); // expected-warning{{

[PATCH] D115523: [OpenCL] Set external linkage for block enqueue kernels

2022-01-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D115523#3237410 , @yaxunl wrote:

> It is possible that block kernels are defined and invoked in static 
> functions, therefore two block kernels in different TU's may have the same 
> name. Making such kernels external may cause duplicate symbols.

Potentially we should append the name of the translation unit to all kernel 
wrapper names for the enqueued blocks to resolve this? For example, global 
constructors stubs are using such a similar naming scheme taken from the 
translation unit.

But the kernel function in OpenCL has to be globally visible and many tools 
have been built with this assumption. Additionally, some toolchains might 
require the enqueued kernels to be globally visible as well in order to access 
them as an execution entry point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115523

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


[PATCH] D112718: Add intrinsics and builtins for PTX atomics with semantic orders

2022-01-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:1057
+
+BUILTIN(__nvvm_atom_xchg_global_i, "iiD*i", "n")
+TARGET_BUILTIN(__nvvm_atom_cta_xchg_global_i, "iiD*i", "n", SM_60)

t4c1 wrote:
> tra wrote:
> > Naghasan wrote:
> > > tra wrote:
> > > > t4c1 wrote:
> > > > > tra wrote:
> > > > > > t4c1 wrote:
> > > > > > > tra wrote:
> > > > > > > > We need to figure out how address-space-specific builtins are 
> > > > > > > > supposed to work.
> > > > > > > > Right now two competing approaches.
> > > > > > > > 
> > > > > > > > This patch declares builtins with generic pointer as an 
> > > > > > > > argument, but, according to the test, expects to be used with 
> > > > > > > > the AS-specific pointer.
> > > > > > > > It probably does not catch a wrong-AS pointer passed as an 
> > > > > > > > argument, either.
> > > > > > > > It does happen to work, but I think it's mostly due to the fact 
> > > > > > > > that LLVM intrinsics are overloaded and we happen to end up 
> > > > > > > > addrspacecast'ing  things correctly if the builtin gets the 
> > > > > > > > right kind of pointer.
> > > > > > > > 
> > > > > > > > The other approach is to declare the pointer with the expected 
> > > > > > > > AS. E.g:
> > > > > > > > > TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", 
> > > > > > > > > AND(SM_80,PTX70))
> > > > > > > > 
> > > > > > > > IMO, this is the correct way to do it, but it is also rather 
> > > > > > > > inconvenient to use from CUDA code as it operates on generic 
> > > > > > > > pointers.
> > > > > > > > 
> > > > > > > > @jdoerfert - WDYT?
> > > > > > > >TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", 
> > > > > > > >AND(SM_80,PTX70))
> > > > > > > >IMO, this is the correct way to do it, but it is also rather 
> > > > > > > >inconvenient to use from CUDA code as it operates on generic 
> > > > > > > >pointers.
> > > > > > > 
> > > > > > > I tried doing this, however it is also completely unusable from 
> > > > > > > OpenCL code (which is our use case). Trying to use it gives you 
> > > > > > > errors about how casting pointers to different address spaces  - 
> > > > > > > for example from local to AS3 is not allowed.
> > > > > > Hmm. It should've worked. It would need the same explicit cast to a 
> > > > > > pointer in AS(3) as in your tests, but it would safeguard against 
> > > > > > attempts to pass it a generic pointer. E.g. 
> > > > > > https://godbolt.org/z/qE6oxzheM
> > > > > > 
> > > > > > Explicit casting to AS(X) for AS-specific variants is annoying, but 
> > > > > > it's probably unavoidable at the moment regardless of whether we 
> > > > > > declare the pointer argument to be AS-specific or not.  LLVM will 
> > > > > > not always be able to infer that a pointer is in particular AS.
> > > > > > Using specific AS in the declaration has a minor benefit of 
> > > > > > safeguarding at compile time against unintentional use of generic 
> > > > > > pointers.
> > > > > > 
> > > > > > Ideally we may want to convert generic variant of the builtin to 
> > > > > > AS-specific one, if LLVM does know the AS. We currently do this for 
> > > > > > loads/stores, but not for other instructions.
> > > > > > 
> > > > > Well, it does not work. See: https://godbolt.org/z/vM6bKncc4. 
> > > > > Declaring the pointer to be in generic AS is the only way I got it to 
> > > > > work. If you know a way to call a builtin declared with AS numbers in 
> > > > > OpenCL, I am happy to do that instead.
> > > > Could you help me understand how different address spaces are handled 
> > > > by OpenCL in clang and LLVM?
> > > > What exactly are `__local` or `__private` in OpenCL? Do they map to 
> > > > LLVM's address spaces? 
> > > > Clang does complain that we're trying to change AS, but I do not see AS 
> > > > used in the IR: https://godbolt.org/z/soajoE991
> > > > 
> > > > AFAICT what happens is:
> > > > * OpenCL does use explicit AS for pointers (`__local`, `__private` seem 
> > > > to pop up in the error messages)
> > > > * `__attribute__((address_space(3)))` does not match the AS of 
> > > > `__local` and that leads to an error.
> > > > * generic pointer argument works because we are allowed to cast any 
> > > > specific AS to generic one.
> > > > 
> > > > In other words, having specific-AS arguemt works as intended, we just 
> > > > have a mismatch between AS number used by OpenCL and AS number used by 
> > > > NVPTX and we're not allowed to cast between two specific AS.
> > > > 
> > > > If that's indeed the case, then what we appear to be missing is the 
> > > > mapping from OpenCL AS to the target-specific AS, which should, 
> > > > ideally, be done by clang itself. So, if NVPTX-specific builtin 
> > > > operating on shared pointer is called with a pointer in OpenCL's 
> > > > equivalent of CUDA's `__shared__`, it should be mapped to AS(3).
> > > > 
> > > > Could you help me understand how different address spaces are handled 
> > > > by

[PATCH] D116673: [Clang][NVPTX]Add NVPTX intrinsics and builtins for CUDA PTX cvt sm80 instructions

2022-01-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D116673#3237342 , @JackAKirk wrote:

> I thought I should let you know that I do not have commit access to land the 
> patch.  I'm also happy to wait a little longer in case you think other 
> interested parties might still chime in.

I can land the patch on your behalf. Are you OK to use the name/email in this 
patch or do you prefer to use a different email for the LLVM commit?

> fatal error: error in backend: Cannot select: intrinsic 
> %llvm.nvvm.shfl.idx.f32

Thank you for letting me know. I'll take a look.


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

https://reviews.llvm.org/D116673

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


[PATCH] D116673: [Clang][NVPTX]Add NVPTX intrinsics and builtins for CUDA PTX cvt sm80 instructions

2022-01-12 Thread Jack Kirk via Phabricator via cfe-commits
JackAKirk marked 2 inline comments as done.
JackAKirk added a comment.



>> I can land the patch on your behalf. Are you OK to use the name/email in 
>> this patch or do you prefer to use a different email for the LLVM commit?
>
> Thanks very much.  Yes the name/email in the patch is fine.




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

https://reviews.llvm.org/D116673

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


[PATCH] D117098: [RISCV] update zfh and zfhmin extention to v1.0

2022-01-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/test/Preprocessor/riscv-target-features.c:207
 
 // RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv32izfhmin1p0 -x c -E -dM %s \

If it's not experimental now, do you need -menable-experimental-extensions?



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td:1
 //===-- RISCVInstrInfoFH.td - RISC-V 'FH' instructions -*- tablegen 
-*-===//
 //

While you're in here can you fix this line by replacing 'FH' with 'Zfh'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117098

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


[PATCH] D116190: Comment parsing: Don't recognize commands in single-line double quotation

2022-01-12 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/lib/AST/CommentLexer.cpp:278
+
+again:
+  size_t End =

I'd suggest refactoring to a `while (true)` if you don't mind.



Comment at: clang/lib/AST/CommentLexer.cpp:290
+if (End != StringRef::npos && *(TokenPtr + End) == '\"')
+  TokenPtr += End + 1;
+goto again;

Does Doxygen understand escaped quotes?

```
/// "@hello\"@hello"
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116190

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


[PATCH] D115253: [C2x] Support the *_WIDTH macros in limits.h and stdint.h

2022-01-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:900-903
+  Builder.defineMacro("__USHRT_WIDTH__", Twine(TI.getShortWidth()));
+  Builder.defineMacro("__UINT_WIDTH__", Twine(TI.getIntWidth()));
+  Builder.defineMacro("__ULONG_WIDTH__", Twine(TI.getLongWidth()));
+  Builder.defineMacro("__ULLONG_WIDTH__", Twine(TI.getLongLongWidth()));

jyknight wrote:
> aaron.ballman wrote:
> > jyknight wrote:
> > > aaron.ballman wrote:
> > > > jyknight wrote:
> > > > > This seems odd? We define `__LONG_LONG_MAX__` but not 
> > > > > `__LONG_LONG_WIDTH__`, for signed long long, and we define 
> > > > > `__ULLONG_WIDTH__` but not `__ULLONG_MAX__`, for unsigned long long?
> > > > > This seems odd?
> > > > 
> > > > Yeah, this stuff is a bit twisty.
> > > > 
> > > > > We define __LONG_LONG_MAX__ but not __LONG_LONG_WIDTH__, for signed 
> > > > > long long,
> > > > 
> > > > Correct.
> > > > 
> > > > > and we define __ULLONG_WIDTH__ but not __ULLONG_MAX__, for unsigned 
> > > > > long long?
> > > > 
> > > > Correct.
> > > > 
> > > > The basic approach I took was: for types with signed/unsigned pairs, 
> > > > define the `unsigned` variants with an underscore name and use them to 
> > > > define the `signed` variants in the header file because the width of 
> > > > signed and unsigned has to be the same per spec ("The macro blah_WIDTH 
> > > > represents the width of the type blah and shall expand to the same 
> > > > value as Ublah_WIDTH.") So that's why you generally only see the 
> > > > "unsigned" width variants added here with a double underscore name. I 
> > > > could expose the signed versions as well (like we do for many of the 
> > > > MAX macros), but that makes the preprocessor slower for no real benefit 
> > > > as we want the users to use the non-underscore versions of these macros 
> > > > whenever possible.
> > > 1. But, in this patch, it is exposing WIDTH for both variants of all the 
> > > other types. Shouldn't we consistently expose WIDTH for only one of each 
> > > pair (e.g. intmax_t, int_fast16_t, etc), instead of exposing both for 
> > > some types, and one for others?
> > > 
> > > 2. Exposing it only for unsigned seems like the wrong choice and 
> > > confusing, since that implies having a basically-extraneous "U" in all of 
> > > the names, and is inconsistent with previous practice. Can we expose only 
> > > the signed variants instead of the unsigned?
> > Ah, I see what you mean now, thanks for pushing back. Yes, I can add the 
> > signed variants here so we expose both the signed and unsigned versions for 
> > everything consistently. I'll also switch the headers to use both the 
> > signed and unsigned variants as appropriate -- the tests ensure these 
> > values won't get out of sync.
> It's not clear to me why you made that change in response to my comments.
> 
> You gave a good rationale before as to why we don't want to have both signed 
> and unsigned versions of the macros, so the change I was trying to suggest in 
> my last comment is to //consistently// expose only the signed variants for 
> `__*_WIDTH__`, and not the unsigned variants.
> 
> For comparison, gcc 11.2, `gcc -E -dM -xc /dev/null |grep WIDTH|sort` gives:
> ```
> #define __INT_FAST16_WIDTH__ 64
> #define __INT_FAST32_WIDTH__ 64
> #define __INT_FAST64_WIDTH__ 64
> #define __INT_FAST8_WIDTH__ 8
> #define __INT_LEAST16_WIDTH__ 16
> #define __INT_LEAST32_WIDTH__ 32
> #define __INT_LEAST64_WIDTH__ 64
> #define __INT_LEAST8_WIDTH__ 8
> #define __INTMAX_WIDTH__ 64
> #define __INTPTR_WIDTH__ 64
> #define __INT_WIDTH__ 32
> #define __LONG_LONG_WIDTH__ 64
> #define __LONG_WIDTH__ 64
> #define __PTRDIFF_WIDTH__ 64
> #define __SCHAR_WIDTH__ 8
> #define __SHRT_WIDTH__ 16
> #define __SIG_ATOMIC_WIDTH__ 32
> #define __SIZE_WIDTH__ 64
> #define __WCHAR_WIDTH__ 32
> #define __WINT_WIDTH__ 32
> ```
> It's not clear to me why you made that change in response to my comments.

I had the impression you wanted both signed and unsigned _WIDTH macros to be 
emitted for consistency with the exact-width (et al) macros. Guess it was the 
opposite, you want the exact-width and basic macros to only define the signed 
versions. However, this makes use of `DefineTypeSizeAndWidth()` within 
`DefineExactWidthIntTypeSize()` and similar kind of awkward -- that now has to 
track whether we're defining a signed vs unsigned type to decide whether to 
emit the _WIDTH macro. So I guess that'll have to be reworked.


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

https://reviews.llvm.org/D115253

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


  1   2   3   >