[PATCH] D139745: Use poison instead of undef where its used as placeholder[NFC]

2022-12-10 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

The struct/insertvalue changes here are fine (no change in semantics). Can't 
comment on the vector/insertelement changes, you might want to split them out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139745

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


[clang] d9bef74 - [Driver] -fstack-size-section: pass -stack-size-section to backend for LTO

2022-12-10 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-12-10T10:15:29Z
New Revision: d9bef74a212b502271eb8fa6a0a8714126e88b2b

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

LOG: [Driver] -fstack-size-section: pass -stack-size-section to backend for LTO

The option does not change IR but affect object file generation. Without a
backend option the option is a no-op for in-process ThinLTO.

The problem is known and there are many options similar to -fstack-size-section.
That said, -fstack-size-section has relatively wider adoption, so it probably
makes sense to have custom code for it.

Close https://github.com/llvm/llvm-project/issues/59424

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/stack-size-section.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 6f975ef5b9222..47f5ff2429eef 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -773,6 +773,11 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
   D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
   }
 
+  if (Args.hasFlag(options::OPT_fstack_size_section,
+   options::OPT_fno_stack_size_section, false))
+CmdArgs.push_back(
+Args.MakeArgString(Twine(PluginOptPrefix) + "-stack-size-section"));
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())

diff  --git a/clang/test/Driver/stack-size-section.c 
b/clang/test/Driver/stack-size-section.c
index b99b1409bef45..71b9f85692b99 100644
--- a/clang/test/Driver/stack-size-section.c
+++ b/clang/test/Driver/stack-size-section.c
@@ -12,4 +12,10 @@
 // RUN: %clang -target x86_64-unknown -fno-stack-size-section 
-fstack-size-section %s -### 2>&1 \
 // RUN: | FileCheck %s --check-prefix=CHECK-PRESENT
 
+// RUN: %clang -### --target=x86_64-linux-gnu -flto -fstack-size-section %s 
2>&1 | FileCheck %s --check-prefix=LTO
+// RUN: %clang -### --target=x86_64-linux-gnu -flto -fstack-size-section 
-fno-stack-size-section %s 2>&1 | FileCheck %s --check-prefix=LTO-NO
+
+// LTO: "-plugin-opt=-stack-size-section"
+// LTO-NO-NOT: "-plugin-opt=-stack-size-section"
+
 int foo() { return 42; }



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


[clang] 91b5d50 - Revert "[clang-format] Link the braces of a block in UnwrappedLineParser"

2022-12-10 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2022-12-10T02:31:53-08:00
New Revision: 91b5d508e350a26028b7fc1397f21334e49dda5d

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

LOG: Revert "[clang-format] Link the braces of a block in UnwrappedLineParser"

This reverts commit e33243c950ac40d027ad8facbf7ccf0624604a16 but
keeps the added test case and also adds another test case.

Fixes #59417.

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/BracesRemoverTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index df8cff6748b17..3be4ef7ca6a1a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -934,9 +934,6 @@ FormatToken *UnwrappedLineParser::parseBlock(
 return IfLBrace;
   }
 
-  Tok->MatchingParen = FormatTok;
-  FormatTok->MatchingParen = Tok;
-
   const bool IsFunctionRBrace =
   FormatTok->is(tok::r_brace) && Tok->is(TT_FunctionLBrace);
 
@@ -970,7 +967,10 @@ FormatToken *UnwrappedLineParser::parseBlock(
 }
 return mightFitOnOneLine((*CurrentLines)[Index], Tok);
   };
-  Tok->Optional = RemoveBraces();
+  if (RemoveBraces()) {
+Tok->MatchingParen = FormatTok;
+FormatTok->MatchingParen = Tok;
+  }
 
   size_t PPEndHash = computePPHash();
 
@@ -2707,20 +2707,10 @@ static void markOptionalBraces(FormatToken *LeftBrace) {
 
   assert(RightBrace->is(tok::r_brace));
   assert(RightBrace->MatchingParen == LeftBrace);
+  assert(LeftBrace->Optional == RightBrace->Optional);
 
-  RightBrace->Optional = LeftBrace->Optional;
-}
-
-static void resetOptional(FormatToken *LeftBrace) {
-  if (!LeftBrace)
-return;
-
-  const auto *RightBrace = LeftBrace->MatchingParen;
-  const bool IsOptionalRightBrace = RightBrace && RightBrace->Optional;
-  assert(LeftBrace->Optional || !IsOptionalRightBrace);
-
-  if (!IsOptionalRightBrace)
-LeftBrace->Optional = false;
+  LeftBrace->Optional = true;
+  RightBrace->Optional = true;
 }
 
 void UnwrappedLineParser::handleAttributes() {
@@ -2788,7 +2778,8 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 
   if (Style.RemoveBracesLLVM) {
 assert(!NestedTooDeep.empty());
-KeepIfBraces = KeepIfBraces || (IfLeftBrace && !IfLeftBrace->Optional) ||
+KeepIfBraces = KeepIfBraces ||
+   (IfLeftBrace && !IfLeftBrace->MatchingParen) ||
NestedTooDeep.back() || IfBlockKind == IfStmtKind::IfOnly ||
IfBlockKind == IfStmtKind::IfElseIf;
   }
@@ -2819,9 +2810,8 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
  ElseBlockKind == IfStmtKind::IfElseIf;
   } else if (FollowedByIf && IfLBrace && !IfLBrace->Optional) {
 KeepElseBraces = true;
-assert(ElseLeftBrace->Optional);
 assert(ElseLeftBrace->MatchingParen);
-ElseLeftBrace->MatchingParen->Optional = true;
+markOptionalBraces(ElseLeftBrace);
   }
   addUnwrappedLine();
 } else if (FormatTok->is(tok::kw_if)) {
@@ -2856,7 +2846,7 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 
   assert(!NestedTooDeep.empty());
   KeepElseBraces = KeepElseBraces ||
-   (ElseLeftBrace && !ElseLeftBrace->Optional) ||
+   (ElseLeftBrace && !ElseLeftBrace->MatchingParen) ||
NestedTooDeep.back();
 
   NestedTooDeep.pop_back();
@@ -2864,11 +2854,17 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
   if (!KeepIfBraces && !KeepElseBraces) {
 markOptionalBraces(IfLeftBrace);
 markOptionalBraces(ElseLeftBrace);
+  } else if (IfLeftBrace) {
+FormatToken *IfRightBrace = IfLeftBrace->MatchingParen;
+if (IfRightBrace) {
+  assert(IfRightBrace->MatchingParen == IfLeftBrace);
+  assert(!IfLeftBrace->Optional);
+  assert(!IfRightBrace->Optional);
+  IfLeftBrace->MatchingParen = nullptr;
+  IfRightBrace->MatchingParen = nullptr;
+}
   }
 
-  resetOptional(IfLeftBrace);
-  resetOptional(ElseLeftBrace);
-
   if (IfKind)
 *IfKind = Kind;
 
@@ -3083,7 +3079,6 @@ void UnwrappedLineParser::parseLoopBody(bool KeepBraces, 
bool WrapRightBrace) {
   if (!NestedTooDeep.back())
 markOptionalBraces(LeftBrace);
 }
-resetOptional(LeftBrace);
 if (WrapRightBrace)
   addUnwrappedLine();
   } else {

diff  --git a/clang/unittests/Format/BracesRemoverTest.cpp 
b/clang/unittests/Format/BracesRemoverTest.cpp
index dea551c979397..57cf40d4c9e95 100644
--- a/clang/unittests/Format/BracesRemoverTest.cpp
+++ b/clang/unittests/Format/BracesRemoverTest.cpp
@@ -683,6 +683,41 @@ TEST_F(BracesRem

[PATCH] D139760: Revert "[clang-format] Link the braces of a block in UnwrappedLineParser"

2022-12-10 Thread Owen Pan 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 rG91b5d508e350: Revert "[clang-format] Link the braces of 
a block in UnwrappedLineParser" (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139760

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/BracesRemoverTest.cpp

Index: clang/unittests/Format/BracesRemoverTest.cpp
===
--- clang/unittests/Format/BracesRemoverTest.cpp
+++ clang/unittests/Format/BracesRemoverTest.cpp
@@ -683,6 +683,41 @@
"return a;",
Style);
 
+  verifyFormat("if (a)\n"
+   "#ifdef FOO\n"
+   "  if (b)\n"
+   "bar = c;\n"
+   "  else\n"
+   "#endif\n"
+   "  {\n"
+   "foo = d;\n"
+   "#ifdef FOO\n"
+   "bar = e;\n"
+   "#else\n"
+   "  bar = f;\n" // FIXME: should be indented 1 more level.
+   "#endif\n"
+   "  }\n"
+   "else\n"
+   "  bar = g;",
+   "if (a)\n"
+   "#ifdef FOO\n"
+   "  if (b)\n"
+   "bar = c;\n"
+   "  else\n"
+   "#endif\n"
+   "  {\n"
+   "foo = d;\n"
+   "#ifdef FOO\n"
+   "bar = e;\n"
+   "#else\n"
+   "bar = f;\n"
+   "#endif\n"
+   "  }\n"
+   "else {\n"
+   "  bar = g;\n"
+   "}",
+   Style);
+
   Style.ColumnLimit = 65;
   verifyFormat("if (condition) {\n"
"  ff(Indices,\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -934,9 +934,6 @@
 return IfLBrace;
   }
 
-  Tok->MatchingParen = FormatTok;
-  FormatTok->MatchingParen = Tok;
-
   const bool IsFunctionRBrace =
   FormatTok->is(tok::r_brace) && Tok->is(TT_FunctionLBrace);
 
@@ -970,7 +967,10 @@
 }
 return mightFitOnOneLine((*CurrentLines)[Index], Tok);
   };
-  Tok->Optional = RemoveBraces();
+  if (RemoveBraces()) {
+Tok->MatchingParen = FormatTok;
+FormatTok->MatchingParen = Tok;
+  }
 
   size_t PPEndHash = computePPHash();
 
@@ -2707,20 +2707,10 @@
 
   assert(RightBrace->is(tok::r_brace));
   assert(RightBrace->MatchingParen == LeftBrace);
+  assert(LeftBrace->Optional == RightBrace->Optional);
 
-  RightBrace->Optional = LeftBrace->Optional;
-}
-
-static void resetOptional(FormatToken *LeftBrace) {
-  if (!LeftBrace)
-return;
-
-  const auto *RightBrace = LeftBrace->MatchingParen;
-  const bool IsOptionalRightBrace = RightBrace && RightBrace->Optional;
-  assert(LeftBrace->Optional || !IsOptionalRightBrace);
-
-  if (!IsOptionalRightBrace)
-LeftBrace->Optional = false;
+  LeftBrace->Optional = true;
+  RightBrace->Optional = true;
 }
 
 void UnwrappedLineParser::handleAttributes() {
@@ -2788,7 +2778,8 @@
 
   if (Style.RemoveBracesLLVM) {
 assert(!NestedTooDeep.empty());
-KeepIfBraces = KeepIfBraces || (IfLeftBrace && !IfLeftBrace->Optional) ||
+KeepIfBraces = KeepIfBraces ||
+   (IfLeftBrace && !IfLeftBrace->MatchingParen) ||
NestedTooDeep.back() || IfBlockKind == IfStmtKind::IfOnly ||
IfBlockKind == IfStmtKind::IfElseIf;
   }
@@ -2819,9 +2810,8 @@
  ElseBlockKind == IfStmtKind::IfElseIf;
   } else if (FollowedByIf && IfLBrace && !IfLBrace->Optional) {
 KeepElseBraces = true;
-assert(ElseLeftBrace->Optional);
 assert(ElseLeftBrace->MatchingParen);
-ElseLeftBrace->MatchingParen->Optional = true;
+markOptionalBraces(ElseLeftBrace);
   }
   addUnwrappedLine();
 } else if (FormatTok->is(tok::kw_if)) {
@@ -2856,7 +2846,7 @@
 
   assert(!NestedTooDeep.empty());
   KeepElseBraces = KeepElseBraces ||
-   (ElseLeftBrace && !ElseLeftBrace->Optional) ||
+   (ElseLeftBrace && !ElseLeftBrace->MatchingParen) ||
NestedTooDeep.back();
 
   NestedTooDeep.pop_back();
@@ -2864,11 +2854,17 @@
   if (!KeepIfBraces && !KeepElseBraces) {
 markOptionalBraces(IfLeftBrace);
 markOptionalBraces(ElseLeftBrace);
+  } else if (IfLeftBrace) {
+FormatToken *IfRightBrace = IfLeftBrace->MatchingParen;
+if (IfRightBrace) {
+  assert(IfRightBrace->MatchingParen == IfLeftBrace);
+  assert(!IfLeftBrace->Optional);
+  assert(!IfRightBrace->Optional);
+  IfLeftBrace->MatchingParen = nullptr;
+  IfRightBrace->MatchingParen = nullptr;
+}
   }
 
-  resetOptional(IfLe

[PATCH] D138042: [libc++] Trigger both Clang and libc++ CI when there are changes to both

2022-12-10 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

Sorry I overlooked this review. Based on the CI output it only runs the Clang 
CI right.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138042

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


[PATCH] D137343: [clang] add -Wvla-stack-allocation

2022-12-10 Thread Tao Liang via Phabricator via cfe-commits
Origami404 added a comment.

>   int foo(void);
>   
>   void bar(int a, int b[*]); // variable length array used, correct
>   void bar(int a, int b[a]) { variable length array used, correct
> int x[foo()]; // variable length array that may require stack allocation 
> used, correct
>   
> (void)sizeof(int[foo()]); // variable length array that may require stack 
> allocation used, incorrect and the diagnostic triggers twice
>   
> int (*y)[foo()]; // variable length array that may require stack 
> allocation used, incorrect, this is a pointer to a VLA
>   }

Thanks to ballman's example here, it remains me that when non-LCE appears as an 
array index in a variable declaration, it is still possible to be a part of a 
pointer/function prototype instead of a VLA. Classifying different VLA usages 
requires more information about the declaration.

The old VLA checking implements just insert checking for the location in array 
type construction when a non-ICE is used as the array's length. And it assumes 
that only one error or warning could be produced by one VLA usage. So the old 
method seems hard to be extended to support the new checking on VLAs.

I plan to throw away the old method here, trying to use "eval functions" on AST 
of declarations or LLVM IR to classify different kinds of VLAs.

Since I am preparing for several final examinations next week, I will try to 
give a new implementation in about a week. And in advance, sorry for my late 
response next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137343

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


Re: [clang] 91b5d50 - Revert "[clang-format] Link the braces of a block in UnwrappedLineParser"

2022-12-10 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert in the
commit message.

On Sat, Dec 10, 2022 at 1:32 PM Owen Pan via cfe-commits
 wrote:
>
>
> Author: Owen Pan
> Date: 2022-12-10T02:31:53-08:00
> New Revision: 91b5d508e350a26028b7fc1397f21334e49dda5d
>
> URL: 
> https://github.com/llvm/llvm-project/commit/91b5d508e350a26028b7fc1397f21334e49dda5d
> DIFF: 
> https://github.com/llvm/llvm-project/commit/91b5d508e350a26028b7fc1397f21334e49dda5d.diff
>
> LOG: Revert "[clang-format] Link the braces of a block in UnwrappedLineParser"
>
> This reverts commit e33243c950ac40d027ad8facbf7ccf0624604a16 but
> keeps the added test case and also adds another test case.
>
> Fixes #59417.
>
> Differential Revision: https://reviews.llvm.org/D139760
>
> Added:
>
>
> Modified:
> clang/lib/Format/UnwrappedLineParser.cpp
> clang/unittests/Format/BracesRemoverTest.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
> b/clang/lib/Format/UnwrappedLineParser.cpp
> index df8cff6748b17..3be4ef7ca6a1a 100644
> --- a/clang/lib/Format/UnwrappedLineParser.cpp
> +++ b/clang/lib/Format/UnwrappedLineParser.cpp
> @@ -934,9 +934,6 @@ FormatToken *UnwrappedLineParser::parseBlock(
>  return IfLBrace;
>}
>
> -  Tok->MatchingParen = FormatTok;
> -  FormatTok->MatchingParen = Tok;
> -
>const bool IsFunctionRBrace =
>FormatTok->is(tok::r_brace) && Tok->is(TT_FunctionLBrace);
>
> @@ -970,7 +967,10 @@ FormatToken *UnwrappedLineParser::parseBlock(
>  }
>  return mightFitOnOneLine((*CurrentLines)[Index], Tok);
>};
> -  Tok->Optional = RemoveBraces();
> +  if (RemoveBraces()) {
> +Tok->MatchingParen = FormatTok;
> +FormatTok->MatchingParen = Tok;
> +  }
>
>size_t PPEndHash = computePPHash();
>
> @@ -2707,20 +2707,10 @@ static void markOptionalBraces(FormatToken 
> *LeftBrace) {
>
>assert(RightBrace->is(tok::r_brace));
>assert(RightBrace->MatchingParen == LeftBrace);
> +  assert(LeftBrace->Optional == RightBrace->Optional);
>
> -  RightBrace->Optional = LeftBrace->Optional;
> -}
> -
> -static void resetOptional(FormatToken *LeftBrace) {
> -  if (!LeftBrace)
> -return;
> -
> -  const auto *RightBrace = LeftBrace->MatchingParen;
> -  const bool IsOptionalRightBrace = RightBrace && RightBrace->Optional;
> -  assert(LeftBrace->Optional || !IsOptionalRightBrace);
> -
> -  if (!IsOptionalRightBrace)
> -LeftBrace->Optional = false;
> +  LeftBrace->Optional = true;
> +  RightBrace->Optional = true;
>  }
>
>  void UnwrappedLineParser::handleAttributes() {
> @@ -2788,7 +2778,8 @@ FormatToken 
> *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
>
>if (Style.RemoveBracesLLVM) {
>  assert(!NestedTooDeep.empty());
> -KeepIfBraces = KeepIfBraces || (IfLeftBrace && !IfLeftBrace->Optional) ||
> +KeepIfBraces = KeepIfBraces ||
> +   (IfLeftBrace && !IfLeftBrace->MatchingParen) ||
> NestedTooDeep.back() || IfBlockKind == IfStmtKind::IfOnly 
> ||
> IfBlockKind == IfStmtKind::IfElseIf;
>}
> @@ -2819,9 +2810,8 @@ FormatToken 
> *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
>   ElseBlockKind == IfStmtKind::IfElseIf;
>} else if (FollowedByIf && IfLBrace && !IfLBrace->Optional) {
>  KeepElseBraces = true;
> -assert(ElseLeftBrace->Optional);
>  assert(ElseLeftBrace->MatchingParen);
> -ElseLeftBrace->MatchingParen->Optional = true;
> +markOptionalBraces(ElseLeftBrace);
>}
>addUnwrappedLine();
>  } else if (FormatTok->is(tok::kw_if)) {
> @@ -2856,7 +2846,7 @@ FormatToken 
> *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
>
>assert(!NestedTooDeep.empty());
>KeepElseBraces = KeepElseBraces ||
> -   (ElseLeftBrace && !ElseLeftBrace->Optional) ||
> +   (ElseLeftBrace && !ElseLeftBrace->MatchingParen) ||
> NestedTooDeep.back();
>
>NestedTooDeep.pop_back();
> @@ -2864,11 +2854,17 @@ FormatToken 
> *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
>if (!KeepIfBraces && !KeepElseBraces) {
>  markOptionalBraces(IfLeftBrace);
>  markOptionalBraces(ElseLeftBrace);
> +  } else if (IfLeftBrace) {
> +FormatToken *IfRightBrace = IfLeftBrace->MatchingParen;
> +if (IfRightBrace) {
> +  assert(IfRightBrace->MatchingParen == IfLeftBrace);
> +  assert(!IfLeftBrace->Optional);
> +  assert(!IfRightBrace->Optional);
> +  IfLeftBrace->MatchingParen = nullptr;
> +  IfRightBrace->MatchingParen = nullptr;
> +}
>}
>
> -  resetOptional(IfLeftBrace);
> -  resetOptional(ElseLeftBrace);
> -
>if (IfKind)
>  *IfKind = Kind;
>
> @@ -3083,7 +3079,6 @@ void UnwrappedLineParser::parseLoopBody(bool 
> KeepBraces, bool WrapRightBrace) {
>if (!NestedTooDeep.back())
>  markOptionalBraces(LeftBrace);

[PATCH] D136554: Implement CWG2631

2022-12-10 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 481850.
cor3ntin added a comment.

- Make sure cleanups expressions are created in the correct evaluation context. 
This simplifies and reduce the numbers of nested evaluation contexts we create, 
notably to make sure the creation of the initialier and cleanup expressions are 
done in the same context

- Add tests for calls to source location builtin in dependant initializers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/UsedDeclVisitor.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CXX/class/class.local/p1-0x.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
  clang/test/CodeGenCXX/meminit-initializers-odr.cpp
  clang/test/PCH/default-argument-with-immediate-calls.cpp
  clang/test/SemaCXX/cxx11-default-member-initializers.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/source_location.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15593,7 +15593,7 @@
 https://wg21.link/cwg2631";>2631
 DR
 Immediate function evaluations in default arguments
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2632";>2632
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
 
 #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
@@ -8,15 +9,22 @@
 template 
 struct Printer;
 
+#ifdef USE_CONSTEVAL
+#define SOURCE_LOC_EVAL_KIND consteval
+#else
+#define SOURCE_LOC_EVAL_KIND constexpr
+#endif
+
 namespace std {
 class source_location {
   struct __impl;
 
 public:
-  static constexpr source_location current(const __impl *__p = __builtin_source_location()) noexcept {
-source_location __loc;
-__loc.__m_impl = __p;
-return __loc;
+  static SOURCE_LOC_EVAL_KIND source_location
+current(const __impl *__p = __builtin_source_location()) noexcept {
+  source_location __loc;
+  __loc.__m_impl = __p;
+  return __loc;
   }
   constexpr source_location() = default;
   constexpr source_location(source_location const &) = default;
@@ -593,3 +601,73 @@
   }
   static_assert(test());
 }
+
+namespace Lambda {
+#line 8000 "TestLambda.cpp"
+constexpr int nested_lambda(int l = []{
+  return SL::current().line();
+}()) {
+  return l;
+}
+static_assert(nested_lambda() == __LINE__ - 4);
+
+constexpr int lambda_param(int l = [](int l = SL::current().line()) {
+  return l;
+}()) {
+  return l;
+}
+static_assert(lambda_param() == __LINE__);
+
+
+}
+
+constexpr int compound_literal_fun(int a =
+  (int){ SL::current().line() }
+) { return a ;}
+static_assert(compound_literal_fun() == __LINE__);
+
+struct CompoundLiteral {
+  int a = (int){ SL::current().line() };
+};
+static_assert(CompoundLiteral{}.a == __LINE__);
+
+
+// FIXME
+// Init captures are subexpressions of the lambda expression
+// so according to the standard immediate invocations in init captures
+// should be evaluated at the call site.
+// However Clang does not yet implement this as it would introduce
+// a fair bit of complexity.
+// We intend to implement that functionality once we find real world
+// use cases that require it.
+constexpr int test_init_capture(int a =
+[b = SL::current().line()] { return b; }()) {
+  return a;
+}
+#ifdef USE_CONSTEVAL
+static_assert(test_init_capture() == __LINE__ - 4);
+#else
+static_assert(test_init_capture() == __LINE__ );
+#endif
+
+namespace check_immediate_invocations_in_templates {
+
+template 
+struct G {
+T line = __builtin_LINE();
+};
+template 
+struct S {
+int i = G{}.line;
+};
+static_assert(S{}.i != // intentional new line
+  S{}.i);
+
+template 
+constexpr int f(int i = G{}.line) {
+return i;
+}
+
+static_assert(f() != // intentional new line
+  f());
+}
Index: clang/test/SemaCXX/cxx2a-constev

[PATCH] D136554: Implement CWG2631

2022-12-10 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@aeubanks I think i got it. Were you having this issue with an open source 
project by any chance?  Maybe i could try it locally before commiting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D131830: [OpenMP] Clang Support for taskwait nowait clause

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

In D131830#3985449 , @koops wrote:

> Martin Storsjö (or anybody who works on windows) I have uploaded a new patch 
> which has __kmpc_omp_taskwait_51 in dllexports. Can you please check the 
> patch on windows?

Thanks, now this seems to work fine for me! (There seems to be another 
unrelated regression at the same time though, regarding the symbol 
`__kmpc_fork_call_if`.)


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

https://reviews.llvm.org/D131830

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


[PATCH] D139148: Fix nullptr dereference found by Coverity static analysis tool

2022-12-10 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:5966
  (Context.hasSameUnqualifiedType(SourceType, DestType) ||
-  S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType
+  (Initilializer &&
+   S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, 
DestType)

Typo.


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

https://reviews.llvm.org/D139148

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


[PATCH] D139113: [clang-tidy] Fix a couple additional cases in misc-use-anonymous-namespace

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

Friendly ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139113

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


[PATCH] D136913: [HLSL] support RWByteAddressBuffer.

2022-12-10 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 481858.
python3kgae added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136913

Files:
  clang/include/clang/Sema/HLSLExternalSemaSource.h
  clang/lib/Sema/HLSLExternalSemaSource.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/AST/HLSL/RWByteAddressBuffer.hlsl
  clang/test/SemaHLSL/BuiltIns/RWByteAddressBuffer.hlsl

Index: clang/test/SemaHLSL/BuiltIns/RWByteAddressBuffer.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/BuiltIns/RWByteAddressBuffer.hlsl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only -verify %s
+
+typedef vector float3;
+
+RWByteAddressBuffer Buffer;
+
+[numthreads(1,1,1)]
+void main() {
+  (void)Buffer.h; // expected-error {{'h' is a private member of 'hlsl::RWByteAddressBuffer'}}
+  // expected-note@* {{implicitly declared private here}}
+  Buffer.Load(0);
+}
Index: clang/test/AST/HLSL/RWByteAddressBuffer.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/RWByteAddressBuffer.hlsl
@@ -0,0 +1,104 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -fsyntax-only -ast-dump %s | FileCheck %s
+
+RWByteAddressBuffer U;
+typedef unsigned int uint;
+typedef vector float2;
+
+// CHECK:CXXRecordDecl 0x{{[0-9a-f]+}} <>  implicit referenced  class RWByteAddressBuffer definition
+// CHECK:FinalAttr 0x{{[0-9a-f]+}} <> Implicit final
+// CHECK-NEXT:HLSLResourceAttr 0x{{[0-9a-f]+}} <> Implicit UAV RawBuffer
+// CHECK-NEXT:-FieldDecl 0x[[HDL:[0-9a-f]+]] <>  implicit referenced h 'void *'
+// CHECK-NEXT:CXXConstructorDecl 0x{{[0-9a-f]+}} <>  used RWByteAddressBuffer 'void ()' inline
+// CHECK-NEXT:CompoundStmt 0x{{[0-9a-f]+}} <>
+// CHECK-NEXT:BinaryOperator 0x{{[0-9a-f]+}} <> 'void *' lvalue '='
+// CHECK-NEXT:MemberExpr 0x{{[0-9a-f]+}} <> 'void *' lvalue ->h 0x[[HDL]]
+// CHECK-NEXT:-CXXThisExpr 0x{{[0-9a-f]+}} <> 'hlsl::RWByteAddressBuffer *' implicit this
+// CHECK-NEXT:CallExpr 0x{{[0-9a-f]+}} <> 'void *'
+// CHECK-NEXT:-DeclRefExpr 0x{{[0-9a-f]+}} <> 'void *(unsigned char) throw()' Function 0x{{[0-9a-f]+}} '__builtin_hlsl_create_handle' 'void *(unsigned char) throw()'
+// CHECK-NEXT:-IntegerLiteral 0x{{[0-9a-f]+}} <> 'unsigned char' 1
+// CHECK-NEXT:FunctionTemplateDecl 0x{{[0-9a-f]+}} <>  Load
+// CHECK-NEXT:TemplateTypeParmDecl 0x{{[0-9a-f]+}} <>  class depth 0 index 0 T
+// CHECK-NEXT:CXXMethodDecl 0x{{[0-9a-f]+}} <>  Load 'T (unsigned int)'
+// CHECK-NEXT:ParmVarDecl 0x[[LOAD_PARAM:[0-9a-f]+]] <>  ByteAddress 'unsigned int'
+// CHECK-NEXT:CompoundStmt 0x{{[0-9a-f]+}} <>
+// CHECK-NEXT:ReturnStmt 0x{{[0-9a-f]+}} <>
+// CHECK-NEXT:ImplicitCastExpr 0x{{[0-9a-f]+}} <> 'T' 
+// CHECK-NEXT:UnaryOperator 0x{{[0-9a-f]+}} <> 'T' lvalue prefix '*' cannot overflow
+// CHECK-NEXT:CStyleCastExpr 0x{{[0-9a-f]+}} <> 'T *' lvalue 
+// CHECK-NEXT:inaryOperator 0x{{[0-9a-f]+}} <> 'unsigned char *' '+'
+// CHECK-NEXT:ImplicitCastExpr 0x{{[0-9a-f]+}} <> 'unsigned char *' 
+// CHECK-NEXT:CStyleCastExpr 0x{{[0-9a-f]+}} <> 'unsigned char *' lvalue 
+// CHECK-NEXT:MemberExpr 0x{{[0-9a-f]+}} <> 'void *' lvalue ->h 0x[[HDL]]
+// CHECK-NEXT:CXXThisExpr 0x{{[0-9a-f]+}} <> 'hlsl::RWByteAddressBuffer *' implicit this
+// CHECK-NEXT:DeclRefExpr 0x{{[0-9a-f]+}} <> 'unsigned int' ParmVar 0x[[LOAD_PARAM]] 'ByteAddress' 'unsigned int'
+
+// CHECK:CXXMethodDecl 0x[[LOAD_F:[0-9a-f]+]] <>  used Load 'float (unsigned int)'
+// CHECK-NEXT:TemplateArgument type 'float'
+// CHECK-NEXT:BuiltinType 0x{{[0-9a-f]+}} 'float'
+
+// CHECK:CXXMethodDecl 0x[[LOAD_F2:[0-9a-f]+]] <>  used Load 'float (unsigned int) __attribute__((ext_vector_type(2)))'
+// CHECK-NEXT:TemplateArgument type 'float __attribute__((ext_vector_type(2)))'
+// CHECK-NEXT:ExtVectorType 0x{{[0-9a-f]+}} 'float __attribute__((ext_vector_type(2)))' 2
+// CHECK-NEXT:BuiltinType 0x{{[0-9a-f]+}} 'float'
+
+// CHECK:CXXMethodDecl 0x[[LOAD_S:[0-9a-f]+]] <>  used Load 'S (unsigned int)'
+// CHECK-NEXT:TemplateArgument type 'S'
+// CHECK-NEXT:-RecordType 0x{{[0-9a-f]+}} 'S'
+// CHECK-NEXT:CXXRecord 0x[[RECORD:[0-9a-f]+]] 'S'
+
+// CHECK:VarDecl 0x[[BUF:[0-9a-f]+]] <{{.+}}:1, col:21> col:21 used U 'RWByteAddressBuffer':'hlsl::RWByteAddressBuffer'
+
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:{{[0-9]+}}:7 foo 'float (uint)'
+// CHECK-NEXT:ParmVarDecl 0x[[FOO_PARAM:[0-9a-f]+]]  col:16 used i 'uint':'unsigned int'
+// CHECK-NEXT:CompoundStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT:ReturnStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT:CXXMemberCallExpr 0x{{[0-9a-f]+}}  'float':'float'
+// CHECK-NEXT:MemberExpr 0x{{[0-9a-f]+}}  '' .Load 0x[[LOAD_F]]
+// CHECK-NEXT:DeclRefExpr 0x{{[0-9a-f]+}}  'RWByteAddressBuffer':'hlsl::RWByteAddressBuffer' lvalue Var 0x[[BUF]] 'U' 'RWByteAddressBuffer':'hlsl::RWByteAddressBuffer'
+// CHECK-NEXT:ImplicitCastE

[clang] 9ddc8af - [Checkers] Use std::optional in BasicObjCFoundationChecks.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T07:58:36-08:00
New Revision: 9ddc8af97f7ccc4a8090a2ac870c79f3e172c8b9

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

LOG: [Checkers] Use std::optional in BasicObjCFoundationChecks.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index 81b1575f3dbb..5e90e974f83f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -33,6 +33,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 using namespace clang;
 using namespace ento;
@@ -742,7 +743,7 @@ void VariadicMethodTypeChecker::checkPreObjCMessage(const 
ObjCMethodCall &msg,
 return;
 
   // Verify that all arguments have Objective-C types.
-  Optional errorNode;
+  std::optional errorNode;
 
   for (unsigned I = variadicArgsBegin; I != variadicArgsEnd; ++I) {
 QualType ArgTy = msg.getArgExpr(I)->getType();



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


[PATCH] D136743: [HLSL] support ConstantBuffer

2022-12-10 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 481861.
python3kgae added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136743

Files:
  clang/lib/Sema/HLSLExternalSemaSource.cpp
  clang/test/AST/HLSL/CBV.hlsl
  clang/test/SemaHLSL/BuiltIns/CBV.hlsl

Index: clang/test/SemaHLSL/BuiltIns/CBV.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/BuiltIns/CBV.hlsl
@@ -0,0 +1,8 @@
+// RUN: not %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -fsyntax-only -verify %s 2>&1 | FileCheck %s
+
+// CHECK:error: 'error' diagnostics seen but not expected:
+// CHECK-NEXT:  (frontend): base specifier must name a class
+// CHECK:1 error generated
+
+// expected-note@+1 {{in instantiation of template class 'hlsl::ConstantBuffer' requested here}}
+ConstantBuffer CB;
Index: clang/test/AST/HLSL/CBV.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/CBV.hlsl
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -fsyntax-only -ast-dump %s | FileCheck %s
+
+// CHECK:-ClassTemplateDecl 0x{{[0-9a-f]+}} <>  implicit ConstantBuffer
+// CHECK-NEXT:-TemplateTypeParmDecl 0x{{[0-9a-f]+}} <>  class depth 0 index 0 element_type
+// CHECK-NEXT:-CXXRecordDecl 0x{{[0-9a-f]+}} <>  implicit class ConstantBuffer definition
+// CHECK:-public 'element_type'
+// CHECK-NEXT:-FinalAttr 0x{{[0-9a-f]+}} <> Implicit final
+// CHECK-NEXT:-HLSLResourceAttr 0x{{[0-9a-f]+}} <> Implicit CBuffer CBufferKind
+
+// CHECK:-CXXRecordDecl 0x{{[0-9a-f]+}}  col:8 implicit struct S
+// CHECK-NEXT:-FieldDecl 0x[[A:[0-9a-f]+]]  col:11 referenced a 'float'
+struct S {
+float a;
+};
+
+// CHECK:VarDecl 0x[[CB:[0-9a-f]+]]  col:19 used CB 'ConstantBuffer':'hlsl::ConstantBuffer'
+ConstantBuffer CB;
+
+float foo() {
+// CHECK:ReturnStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT:-ImplicitCastExpr 0x{{[0-9a-f]+}}  'float' 
+// CHECK-NEXT:-MemberExpr 0x{{[0-9a-f]+}}  'float' lvalue .a 0x[[A]]
+// CHECK-NEXT:-ImplicitCastExpr 0x{{[0-9a-f]+}}  'S' lvalue 
+// CHECK-NEXT:-DeclRefExpr 0x{{[0-9a-f]+}}  'ConstantBuffer':'hlsl::ConstantBuffer' lvalue Var 0x[[CB]] 'CB' 'ConstantBuffer':'hlsl::ConstantBuffer'
+return CB.a;
+}
Index: clang/lib/Sema/HLSLExternalSemaSource.cpp
===
--- clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -34,6 +34,7 @@
   ClassTemplateDecl *PrevTemplate = nullptr;
   NamespaceDecl *HLSLNamespace = nullptr;
   llvm::StringMap Fields;
+  llvm::SmallVector Bases;
 
   BuiltinTypeDeclBuilder(CXXRecordDecl *R) : Record(R) {
 Record->startDefinition();
@@ -306,6 +307,30 @@
 return *this;
   }
 
+  BuiltinTypeDeclBuilder &addBase(TypeDecl *Parent) {
+if (Record->isCompleteDefinition())
+  return *this;
+TypeSourceInfo *TInfo =
+HLSLNamespace->getASTContext().getTrivialTypeSourceInfo(
+QualType(Parent->getTypeForDecl(), 0));
+CXXBaseSpecifier Base(SourceRange(), false, false,
+  AccessSpecifier::AS_public, TInfo, SourceLocation());
+Bases.emplace_back(Base);
+return *this;
+  }
+
+  BuiltinTypeDeclBuilder &setBases() {
+if (Record->isCompleteDefinition())
+  return *this;
+
+llvm::SmallVector BasesData;
+for (auto &Base : Bases)
+  BasesData.emplace_back(&Base);
+Record->setBases(BasesData.data(), BasesData.size());
+Bases.clear();
+return *this;
+  }
+
   TemplateParameterListBuilder addTemplateArgumentList();
 };
 
@@ -336,6 +361,13 @@
 return *this;
   }
 
+  TemplateParameterListBuilder &addTypeParameterAsBase(uint32_t I) {
+if (Params.size() <= I)
+  return *this;
+Builder.addBase(cast(Params[I]));
+return *this;
+  }
+
   BuiltinTypeDeclBuilder &finalizeTemplateArgs() {
 if (Params.empty())
   return Builder;
@@ -466,6 +498,20 @@
  .addHandleMember(AccessSpecifier::AS_public)
  .completeDefinition()
  .Record;
+  // Add CBV as
+  // template
+  // struct ConstantBuffer : T {
+  // };
+  BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ConstantBuffer")
+  .startDefinition()
+  .addTemplateArgumentList()
+  .addTypeParameter("element_type")
+  .addTypeParameterAsBase(0)
+  .finalizeTemplateArgs()
+  .setBases()
+  .annotateResourceClass(HLSLResourceAttr::CBuffer,
+ HLSLResourceAttr::CBufferKind)
+  .completeDefinition();
 }
 
 void HLSLExternalSemaSource::forwardDeclareHLSLTypes() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6c8b8a6 - [Checkers] Use std::optional in GenericTaintChecker.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T08:00:24-08:00
New Revision: 6c8b8a6a2a52143d91af883dea30d8549e38cada

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

LOG: [Checkers] Use std::optional in GenericTaintChecker.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
index 863d82c87125..0f7973e74099 100644
--- a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -30,6 +30,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #define DEBUG_TYPE "taint-checker"
@@ -360,8 +361,8 @@ class GenericTaintChecker : public Checker {
   // TODO: Remove separation to simplify matching logic once CallDescriptions
   // are more expressive.
 
-  mutable Optional StaticTaintRules;
-  mutable Optional DynamicTaintRules;
+  mutable std::optional StaticTaintRules;
+  mutable std::optional DynamicTaintRules;
 };
 } // end of anonymous namespace
 



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


[clang] 02c905c - [Checkers] Use std::optional in MallocChecker.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T08:04:28-08:00
New Revision: 02c905cd4d4411a7b97a618101f59e54d779f336

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

LOG: [Checkers] Use std::optional in MallocChecker.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 2162933bfcd8..8cd87853de20 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -86,6 +86,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -443,14 +444,14 @@ class MallocChecker
   bool isMemCall(const CallEvent &Call) const;
 
   // TODO: Remove mutable by moving the initializtaion to the registry 
function.
-  mutable Optional KernelZeroFlagVal;
+  mutable std::optional KernelZeroFlagVal;
 
   using KernelZeroSizePtrValueTy = Optional;
   /// Store the value of macro called `ZERO_SIZE_PTR`.
   /// The value is initialized at first use, before first use the outer
   /// Optional is empty, afterwards it contains another Optional that indicates
   /// if the macro value could be determined, and if yes the value itself.
-  mutable Optional KernelZeroSizePtrValue;
+  mutable std::optional KernelZeroSizePtrValue;
 
   /// Process C++ operator new()'s allocation, which is the part of C++
   /// new-expression that goes before the constructor.
@@ -2247,7 +2248,7 @@ void MallocChecker::HandleNonHeapDealloc(CheckerContext 
&C, SVal ArgVal,
 void MallocChecker::HandleFreeAlloca(CheckerContext &C, SVal ArgVal,
  SourceRange Range) const {
 
-  Optional CheckKind;
+  std::optional CheckKind;
 
   if (ChecksEnabled[CK_MallocChecker])
 CheckKind = CK_MallocChecker;



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


[clang] b5716de - [RetainCountChecker] Use std::optional in RetainCountDiagnostics.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T08:07:12-08:00
New Revision: b5716decbd4a4be3dba2318799871b062f3859d2

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

LOG: [RetainCountChecker] Use std::optional in RetainCountDiagnostics.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index 9133b66fec7c..3afaf622aab4 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -15,6 +15,7 @@
 #include "RetainCountChecker.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
+#include 
 
 using namespace clang;
 using namespace ento;
@@ -166,10 +167,10 @@ static bool shouldGenerateNote(llvm::raw_string_ostream 
&os,
 /// Finds argument index of the out paramter in the call @c S
 /// corresponding to the symbol @c Sym.
 /// If none found, returns std::nullopt.
-static Optional findArgIdxOfSymbol(ProgramStateRef CurrSt,
- const LocationContext *LCtx,
- SymbolRef &Sym,
- Optional> CE) {
+static std::optional findArgIdxOfSymbol(ProgramStateRef CurrSt,
+  const LocationContext *LCtx,
+  SymbolRef &Sym,
+  Optional> CE) 
{
   if (!CE)
 return std::nullopt;
 
@@ -182,7 +183,7 @@ static Optional 
findArgIdxOfSymbol(ProgramStateRef CurrSt,
   return std::nullopt;
 }
 
-static Optional findMetaClassAlloc(const Expr *Callee) {
+static std::optional findMetaClassAlloc(const Expr *Callee) {
   if (const auto *ME = dyn_cast(Callee)) {
 if (ME->getMemberDecl()->getNameAsString() != "alloc")
   return std::nullopt;



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


[clang] b5fdd53 - [Checkers] Use std::optional in StdLibraryFunctionsChecker.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T08:09:00-08:00
New Revision: b5fdd533e5c8ed9726bfaaf961272010cbde6c75

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

LOG: [Checkers] Use std::optional in StdLibraryFunctionsChecker.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d7befdc553e3..2535bf5a368f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -52,6 +52,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 
+#include 
 #include 
 
 using namespace clang;
@@ -296,13 +297,13 @@ class StdLibraryFunctionsChecker
   //   // Here, ptr is the buffer, and its minimum size is `size * nmemb`.
   class BufferSizeConstraint : public ValueConstraint {
 // The concrete value which is the minimum size for the buffer.
-llvm::Optional ConcreteSize;
+std::optional ConcreteSize;
 // The argument which holds the size of the buffer.
-llvm::Optional SizeArgN;
+std::optional SizeArgN;
 // The argument which is a multiplier to size. This is set in case of
 // `fread` like functions where the size is computed as a multiplication of
 // two arguments.
-llvm::Optional SizeMultiplierArgN;
+std::optional SizeMultiplierArgN;
 // The operator we use in apply. This is negated in negate().
 BinaryOperator::Opcode Op = BO_LE;
 



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


[clang] 628556b - [Checkers] Use std::optional in UnixAPIChecker.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T08:10:24-08:00
New Revision: 628556b1c53b53946ae0ee39a7a090e5bbdd6aec

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

LOG: [Checkers] Use std::optional in UnixAPIChecker.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


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

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
index aa3f4524798a..c7a64f391516 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -22,6 +22,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 using namespace clang;
 using namespace ento;
@@ -40,7 +41,7 @@ namespace {
 
 class UnixAPIMisuseChecker : public Checker< check::PreStmt > {
   mutable std::unique_ptr BT_open, BT_pthreadOnce;
-  mutable Optional Val_O_CREAT;
+  mutable std::optional Val_O_CREAT;
 
 public:
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;



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


[PATCH] D139496: [CMake] Add perf profiling for clang-bolt

2022-12-10 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

Could we add the `perf` related logic to 
https://github.com/llvm/llvm-project/blob/ba3d808feedaa7f31750d8bc02754e15b372c868/clang/utils/perf-training/perf-helper.py?
 I think that's a better place since we eventually want to replace the use of 
`ExternalProject_Add` with 
https://github.com/llvm/llvm-project/tree/main/clang/utils/perf-training so we 
should try to keep the amount of logic in CMake down to minimum.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139496

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


[PATCH] D131830: [OpenMP] Clang Support for taskwait nowait clause

2022-12-10 Thread Sunil K via Phabricator via cfe-commits
koops added a comment.

> (There seems to be another unrelated regression at the same time though, 
> regarding the symbol __kmpc_fork_call_if.)

I do not know about this regression. I have not touched this function.


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

https://reviews.llvm.org/D131830

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


[PATCH] D131830: [OpenMP] Clang Support for taskwait nowait clause

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

In D131830#3986436 , @koops wrote:

>> (There seems to be another unrelated regression at the same time though, 
>> regarding the symbol __kmpc_fork_call_if.)
>
> I do not know about this regression. I have not touched this function.

Yeah, that one should be separate, I guess it stems from D138495 
.

This updated patch should be ok with me to recommit.


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

https://reviews.llvm.org/D131830

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


[PATCH] D139496: [CMake] Add perf profiling for clang-bolt

2022-12-10 Thread Amir Ayupov via Phabricator via cfe-commits
Amir added a comment.

In D139496#3986435 , @phosek wrote:

> Could we add the `perf` related logic to 
> https://github.com/llvm/llvm-project/blob/ba3d808feedaa7f31750d8bc02754e15b372c868/clang/utils/perf-training/perf-helper.py?
>  I think that's a better place since we eventually want to replace the use of 
> `ExternalProject_Add` with 
> https://github.com/llvm/llvm-project/tree/main/clang/utils/perf-training so 
> we should try to keep the amount of logic in CMake down to minimum.

Sure! I didn't realize perf-helper had dtrace functionality in place. Adding 
Linux perf functions would be logical.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139496

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


[PATCH] D139759: [analyzer] Fix assertion in getAPSIntType

2022-12-10 Thread Balázs Benics via Phabricator via cfe-commits
steakhal requested changes to this revision.
steakhal added a comment.
This revision now requires changes to proceed.

Nice catch.

I had a look at 
https://lists.llvm.org/pipermail/llvm-dev/2021-March/149216.html, and 
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf.
Your change makes sense to me.

However, I'm a bit worried that other parts of the analyzer might suffer from 
the same phenomenon. When I grepped for `isIntegralOrEnumerationType()`, there 
were like 45 mentions.
I guess, you will worry about it more than I do, but I'd recommend you to have 
a look at them. You might be able to craft even more crashes.

PS: I was a bit shocked that we don't have any tests mentioning `_Accum` and 
`_Fract`.




Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:155-156
 
-assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
+assert(T->isIntegralOrEnumerationType() || T->isFixedPointType() ||
+   Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),

I was thinking of using `isFixedPointOrIntegerType()`. However, that would not 
accept //scoped enums//.
```lang=c++
inline bool Type::isFixedPointOrIntegerType() const {
  return isFixedPointType() || isIntegerType();
}

inline bool Type::isIntegerType() const {
  if (const auto *BT = dyn_cast(CanonicalType))
return BT->getKind() >= BuiltinType::Bool &&
   BT->getKind() <= BuiltinType::Int128;
  if (const EnumType *ET = dyn_cast(CanonicalType)) {
// Incomplete enum types are not treated as integer types.
// FIXME: In C++, enum types are never integer types.
return IsEnumDeclComplete(ET->getDecl()) &&
  !IsEnumDeclScoped(ET->getDecl()); // < rejects scoped 
enums :(
  }
  return isBitIntType();
}

inline bool Type::isIntegralOrEnumerationType() const {
  if (const auto *BT = dyn_cast(CanonicalType))
return BT->getKind() >= BuiltinType::Bool &&
   BT->getKind() <= BuiltinType::Int128;

  // Check for a complete enum type; incomplete enum types are not properly an
  // enumeration type in the sense required here.
  if (const auto *ET = dyn_cast(CanonicalType))
return IsEnumDeclComplete(ET->getDecl()); // < accepts scoped 
enums!

  return isBitIntType();
}
```

It looked so neat at first. Ah. I just had to share this.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:157-158
+   Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }

I don't think you are supposed to call `isSignedIntegerOrEnumerationType()` if 
you have a //fixed-point// type.
```lang=C++
inline bool Type::isSignedFixedPointType() const {
  if (const auto *BT = dyn_cast(CanonicalType)) {
return ((BT->getKind() >= BuiltinType::ShortAccum &&
 BT->getKind() <= BuiltinType::LongAccum) ||
(BT->getKind() >= BuiltinType::ShortFract &&
 BT->getKind() <= BuiltinType::LongFract) ||
(BT->getKind() >= BuiltinType::SatShortAccum &&
 BT->getKind() <= BuiltinType::SatLongAccum) ||
(BT->getKind() >= BuiltinType::SatShortFract &&
 BT->getKind() <= BuiltinType::SatLongFract));
  }
  return false;
}
```
By looking at the implementation of this, I don't think you could substitute 
that with `isSignedIntegerOrEnumerationType()`.
Am I wrong about this?

Please demonstrate this by tests.



Comment at: clang/test/Analysis/fixed-point.c:6-9
+long a(int c) {
   
+  (long _Accum) c >> 4;
+  return c;
+}  

It had a few extra spaces. And by casting it to void we could eliminate 
`-Wno-unused` as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139759

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


[clang-tools-extra] f7dffc2 - Don't include None.h (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T11:24:26-08:00
New Revision: f7dffc28b3f82e25a0e283d2b11ffb9c6a129340

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

LOG: Don't include None.h (NFC)

I've converted all known uses of None to std::nullopt, so we no longer
need to include None.h.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/support/ThreadsafeFS.h
clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang/include/clang/AST/DeclObjC.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/ExprObjC.h
clang/include/clang/AST/Type.h
clang/include/clang/Frontend/ASTUnit.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Sema/Overload.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/DeclObjC.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/AST/Type.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
clang/utils/TableGen/NeonEmitter.cpp
libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp
lldb/source/Core/Debugger.cpp
lldb/source/Core/ThreadedCommunication.cpp

lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.cpp
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleSaver.cpp
llvm/include/llvm/ADT/ArrayRef.h
llvm/include/llvm/ADT/BreadthFirstIterator.h
llvm/include/llvm/ADT/DepthFirstIterator.h
llvm/include/llvm/ADT/Optional.h
llvm/include/llvm/ADT/SmallSet.h
llvm/include/llvm/ADT/TinyPtrVector.h
llvm/include/llvm/BinaryFormat/AMDGPUMetadataVerifier.h
llvm/include/llvm/CodeGen/LiveRangeEdit.h
llvm/include/llvm/CodeGen/MIRParser/MIRParser.h
llvm/include/llvm/CodeGen/MachineTraceMetrics.h
llvm/include/llvm/CodeGen/TargetInstrInfo.h
llvm/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h
llvm/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
llvm/include/llvm/IR/Constants.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/include/llvm/IR/GCStrategy.h
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/InstrTypes.h
llvm/include/llvm/IR/Instruction.h
llvm/include/llvm/IR/Instructions.h
llvm/include/llvm/IR/Intrinsics.h
llvm/include/llvm/IR/Metadata.h
llvm/include/llvm/IR/Operator.h
llvm/include/llvm/IR/ValueMap.h
llvm/include/llvm/MC/MCParser/MCAsmParser.h
llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/include/llvm/Support/CommandLine.h
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/lib/Analysis/BlockFrequencyInfo.cpp
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/ImplicitNullChecks.cpp
llvm/lib/CodeGen/MIRParser/MIParser.cpp
llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
llvm/lib/CodeGen/SplitKit.cpp
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/ConstantsContext.h
llvm/lib/IR/Function.cpp
llvm/lib/IR/IRBuilder.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/lib/MC/MCParser/MasmP

[clang] 29041bc - [APInt] Convert GetMostSignificantDifferentBit to std::optional

2022-12-10 Thread Krzysztof Parzyszek via cfe-commits

Author: Krzysztof Parzyszek
Date: 2022-12-10T14:03:29-06:00
New Revision: 29041bc0507f2b04d116ee3150bfd61ea01c5565

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

LOG: [APInt] Convert GetMostSignificantDifferentBit to std::optional

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
llvm/include/llvm/ADT/APInt.h
llvm/lib/IR/ConstantRange.cpp
llvm/lib/Support/APInt.cpp
llvm/unittests/ADT/APIntTest.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index e10ee4ae7a145..5815742d57ac7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_ANALYZER_WEBKIT_PTRTYPESEMANTICS_H
 
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/Optional.h"
 
 namespace clang {
 class CXXBaseSpecifier;

diff  --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index c8ca617360c89..15e696ef91935 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -31,7 +31,6 @@ class raw_ostream;
 
 template  class SmallVectorImpl;
 template  class ArrayRef;
-template  class Optional;
 template  struct DenseMapInfo;
 
 class APInt;
@@ -2254,8 +2253,8 @@ std::optional SolveQuadraticEquationWrap(APInt A, 
APInt B, APInt C,
 
 /// Compare two values, and if they are 
diff erent, return the position of the
 /// most significant bit that is 
diff erent in the values.
-Optional GetMostSignificantDifferentBit(const APInt &A,
-  const APInt &B);
+std::optional GetMostSignificantDifferentBit(const APInt &A,
+   const APInt &B);
 
 /// Splat/Merge neighboring bits to widen/narrow the bitmask represented
 /// by \param A to \param NewBitWidth bits.

diff  --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index bae1e550a6a3d..2f0d3d1e3a5ac 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace llvm;
 
@@ -85,7 +86,7 @@ KnownBits ConstantRange::toKnownBits() const {
   APInt Min = getUnsignedMin();
   APInt Max = getUnsignedMax();
   KnownBits Known = KnownBits::makeConstant(Min);
-  if (Optional DifferentBit =
+  if (std::optional DifferentBit =
   APIntOps::GetMostSignificantDifferentBit(Min, Max)) {
 Known.Zero.clearLowBits(*DifferentBit + 1);
 Known.One.clearLowBits(*DifferentBit + 1);

diff  --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index b19de75a68f43..db55fd02396d6 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -2961,7 +2961,7 @@ llvm::APIntOps::SolveQuadraticEquationWrap(APInt A, APInt 
B, APInt C,
   return X;
 }
 
-Optional
+std::optional
 llvm::APIntOps::GetMostSignificantDifferentBit(const APInt &A, const APInt &B) 
{
   assert(A.getBitWidth() == B.getBitWidth() && "Must have the same bitwidth");
   if (A == B)

diff  --git a/llvm/unittests/ADT/APIntTest.cpp 
b/llvm/unittests/ADT/APIntTest.cpp
index b306a6d370645..3055581c7dd30 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/Twine.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 
 using namespace llvm;
 
@@ -2956,7 +2957,7 @@ TEST(APIntTest, GetMostSignificantDifferentBit) {
 
 TEST(APIntTest, GetMostSignificantDifferentBitExaustive) {
   auto GetHighestDifferentBitBruteforce =
-  [](const APInt &V0, const APInt &V1) -> llvm::Optional {
+  [](const APInt &V0, const APInt &V1) -> std::optional {
 assert(V0.getBitWidth() == V1.getBitWidth() && "Must have same bitwidth");
 if (V0 == V1)
   return std::nullopt; // Bitwise identical.



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


[PATCH] D139774: [libclang] Add API to set temporary directory location

2022-12-10 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy created this revision.
vedgy added a reviewer: aaron.ballman.
Herald added subscribers: arphaman, hiraditya.
Herald added a project: All.
vedgy requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139774

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/libclang.map
  llvm/include/llvm/Support/Path.h
  llvm/lib/Support/Unix/Path.inc
  llvm/lib/Support/Windows/Path.inc
  llvm/unittests/Support/Path.cpp

Index: llvm/unittests/Support/Path.cpp
===
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -591,6 +591,26 @@
   EXPECT_TRUE(!TempDir.empty());
 }
 
+TEST(Support, SetTempDirectory) {
+  SmallString<64> DefaultTempDir;
+  path::system_temp_directory(true, DefaultTempDir);
+  EXPECT_TRUE(!DefaultTempDir.empty());
+
+  auto CustomTempDir = DefaultTempDir;
+  path::append(CustomTempDir, "/llvm/test_temp_dir");
+  path::native(CustomTempDir);
+  path::set_system_temp_directory_erased_on_reboot(CustomTempDir.c_str());
+
+  SmallString<64> TempDir;
+  path::system_temp_directory(true, TempDir);
+  EXPECT_EQ(CustomTempDir, TempDir);
+
+  path::set_system_temp_directory_erased_on_reboot(nullptr);
+  TempDir.clear();
+  path::system_temp_directory(true, TempDir);
+  EXPECT_EQ(DefaultTempDir, TempDir);
+}
+
 #ifdef _WIN32
 static std::string path2regex(std::string Path) {
   size_t Pos = 0;
Index: llvm/lib/Support/Windows/Path.inc
===
--- llvm/lib/Support/Windows/Path.inc
+++ llvm/lib/Support/Windows/Path.inc
@@ -1468,15 +1468,22 @@
   return false;
 }
 
+static const char *tempDirErasedOnRebootUtf8 = nullptr;
+
 void system_temp_directory(bool ErasedOnReboot, SmallVectorImpl &Result) {
   (void)ErasedOnReboot;
   Result.clear();
 
+  if (tempDirErasedOnRebootUtf8) {
+const auto len = strlen(tempDirErasedOnRebootUtf8);
+Result.append(tempDirErasedOnRebootUtf8, tempDirErasedOnRebootUtf8 + len);
+  }
+
   // Check whether the temporary directory is specified by an environment var.
   // This matches GetTempPath logic to some degree. GetTempPath is not used
   // directly as it cannot handle evn var longer than 130 chars on Windows 7
   // (fixed on Windows 8).
-  if (getTempDirEnvVar(Result)) {
+  if (!Result.empty() || getTempDirEnvVar(Result)) {
 assert(!Result.empty() && "Unexpected empty path");
 native(Result); // Some Unix-like shells use Unix path separator in $TMP.
 fs::make_absolute(Result); // Make it absolute if not already.
@@ -1488,6 +1495,10 @@
   Result.append(DefaultResult, DefaultResult + strlen(DefaultResult));
   llvm::sys::path::make_preferred(Result);
 }
+
+void set_system_temp_directory_erased_on_reboot(const char *tempDirUtf8) {
+  tempDirErasedOnRebootUtf8 = tempDirUtf8;
+}
 } // end namespace path
 
 namespace windows {
Index: llvm/lib/Support/Unix/Path.inc
===
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -1447,12 +1447,17 @@
   return "/var/tmp";
 }
 
+static const char *tempDirErasedOnRebootUtf8 = nullptr;
+
 void system_temp_directory(bool ErasedOnReboot, SmallVectorImpl &Result) {
   Result.clear();
 
   if (ErasedOnReboot) {
+const char *RequestedDir = tempDirErasedOnRebootUtf8;
 // There is no env variable for the cache directory.
-if (const char *RequestedDir = getEnvTempDir()) {
+if (!RequestedDir)
+  RequestedDir = getEnvTempDir();
+if (RequestedDir) {
   Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
   return;
 }
@@ -1465,6 +1470,10 @@
   Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
 }
 
+void set_system_temp_directory_erased_on_reboot(const char *tempDirUtf8) {
+  tempDirErasedOnRebootUtf8 = tempDirUtf8;
+}
+
 } // end namespace path
 
 namespace fs {
Index: llvm/include/llvm/Support/Path.h
===
--- llvm/include/llvm/Support/Path.h
+++ llvm/include/llvm/Support/Path.h
@@ -412,6 +412,16 @@
 /// @param result Holds the resulting path name.
 void system_temp_directory(bool erasedOnReboot, SmallVectorImpl &result);
 
+/// Override the temporary directory path returned by
+/// system_temp_directory(true, result).
+///
+/// @param tempDirUtf8 UTF-8-encoded path to the desired temporary directory.
+/// The pointer is owned by the caller and must be always valid. Pass nullptr to
+/// this function in order to reset the temporary directory to the default value
+/// from the environment. Such a resetting should be done before deleting a
+/// tempDirUtf8 pointer previously passed to this function.
+void set_system_temp_dire

[clang] 1cb7fba - [StaticAnalyzer] Don't use Optional::create (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T12:35:03-08:00
New Revision: 1cb7fba3e57d6c31f05c7a2bda1634da49dd1d18

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

LOG: [StaticAnalyzer] Don't use Optional::create (NFC)

std::optional does not have an equivalent method.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/RegionStore.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index f5959b26dd92..db8a5c5c38c8 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -263,11 +263,13 @@ class RegionBindingsRef : public 
llvm::ImmutableMapRef RegionBindingsRef::getDirectBinding(const MemRegion *R) const {
-  return Optional::create(lookup(R, BindingKey::Direct));
+  const SVal *V = lookup(R, BindingKey::Direct);
+  return V ? Optional(*V) : std::nullopt;
 }
 
 Optional RegionBindingsRef::getDefaultBinding(const MemRegion *R) const {
-  return Optional::create(lookup(R, BindingKey::Default));
+  const SVal *V = lookup(R, BindingKey::Default);
+  return V ? Optional(*V) : std::nullopt;
 }
 
 RegionBindingsRef RegionBindingsRef::addBinding(BindingKey K, SVal V) const {



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


[PATCH] D139759: [analyzer] Fix assertion in getAPSIntType

2022-12-10 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thanks for the comments. I assumed git-clang-format cleaned up the cruft, but 
it didn't - that's disappointing. I'll try these things and update the review. 
Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139759

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


[PATCH] D139759: [analyzer] Fix assertion in getAPSIntType

2022-12-10 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 481882.
vabridgers edited the summary of this revision.
vabridgers added a comment.

correct formatting of test case and expand test cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139759

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/test/Analysis/fixed-point.c


Index: clang/test/Analysis/fixed-point.c
===
--- /dev/null
+++ clang/test/Analysis/fixed-point.c
@@ -0,0 +1,65 @@
+// RUN: %clang_analyze_cc1 -ffixed-point \
+// RUN:   -analyzer-checker=core,debug.ExprInspection -verify %s
+
+// expected-no-diagnostics
+
+// Check that getAPSIntType does not crash
+// when using fixed point types.
+
+enum en_t { en_0 = 1 };
+
+void _enum(int c) {
+  (void)((enum en_t) c >> 4);
+}
+
+void _inttype(int c) {
+  (void)(c >> 4);
+}
+
+void _accum(int c) {
+  (void)((_Accum) c >> 4);
+}
+
+void _fract(int c) {
+  (void)((_Fract) c >> 4);
+}
+
+void _long_fract(int c) {
+  (void)((long _Fract) c >> 4);
+}
+
+void _unsigned_accum(int c) {
+  (void)((unsigned _Accum) c >> 4);
+}
+
+void _short_unsigned_accum(int c) {
+  (void)((short unsigned _Accum) c >> 4);
+}
+
+void _unsigned_fract(int c) {
+  (void)((unsigned _Fract) c >> 4);
+}
+
+void sat_accum(int c) {
+  (void)((_Sat _Accum) c >> 4);
+}
+
+void sat_fract(int c) {
+  (void)((_Sat _Fract) c >> 4);
+}
+
+void sat_long_fract(int c) {
+  (void)((_Sat long _Fract) c >> 4);
+}
+
+void sat_unsigned_accum(int c) {
+  (void)((_Sat unsigned _Accum) c >> 4);
+}
+
+void sat_short_unsigned_accum(int c) {
+  (void)((_Sat short unsigned _Accum) c >> 4);
+}
+
+void sat_unsigned_fract(int c) {
+  (void)((_Sat unsigned _Fract) c >> 4);
+}
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -152,7 +152,8 @@
   T = AT->getValueType();
 }
 
-assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
+assert(T->isIntegralOrEnumerationType() || T->isFixedPointType() ||
+   Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }


Index: clang/test/Analysis/fixed-point.c
===
--- /dev/null
+++ clang/test/Analysis/fixed-point.c
@@ -0,0 +1,65 @@
+// RUN: %clang_analyze_cc1 -ffixed-point \
+// RUN:   -analyzer-checker=core,debug.ExprInspection -verify %s
+
+// expected-no-diagnostics
+
+// Check that getAPSIntType does not crash
+// when using fixed point types.
+
+enum en_t { en_0 = 1 };
+
+void _enum(int c) {
+  (void)((enum en_t) c >> 4);
+}
+
+void _inttype(int c) {
+  (void)(c >> 4);
+}
+
+void _accum(int c) {
+  (void)((_Accum) c >> 4);
+}
+
+void _fract(int c) {
+  (void)((_Fract) c >> 4);
+}
+
+void _long_fract(int c) {
+  (void)((long _Fract) c >> 4);
+}
+
+void _unsigned_accum(int c) {
+  (void)((unsigned _Accum) c >> 4);
+}
+
+void _short_unsigned_accum(int c) {
+  (void)((short unsigned _Accum) c >> 4);
+}
+
+void _unsigned_fract(int c) {
+  (void)((unsigned _Fract) c >> 4);
+}
+
+void sat_accum(int c) {
+  (void)((_Sat _Accum) c >> 4);
+}
+
+void sat_fract(int c) {
+  (void)((_Sat _Fract) c >> 4);
+}
+
+void sat_long_fract(int c) {
+  (void)((_Sat long _Fract) c >> 4);
+}
+
+void sat_unsigned_accum(int c) {
+  (void)((_Sat unsigned _Accum) c >> 4);
+}
+
+void sat_short_unsigned_accum(int c) {
+  (void)((_Sat short unsigned _Accum) c >> 4);
+}
+
+void sat_unsigned_fract(int c) {
+  (void)((_Sat unsigned _Fract) c >> 4);
+}
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -152,7 +152,8 @@
   T = AT->getValueType();
 }
 
-assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
+assert(T->isIntegralOrEnumerationType() || T->isFixedPointType() ||
+   Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139759: [analyzer] Fix assertion in getAPSIntType

2022-12-10 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked 2 inline comments as done.
vabridgers added a comment.

Thanks Balazs, I think the comments have been addressed. Let me know if there's 
anything else to do, or if this is ready to land.

Best!




Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:157-158
+   Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }

steakhal wrote:
> I don't think you are supposed to call `isSignedIntegerOrEnumerationType()` 
> if you have a //fixed-point// type.
> ```lang=C++
> inline bool Type::isSignedFixedPointType() const {
>   if (const auto *BT = dyn_cast(CanonicalType)) {
> return ((BT->getKind() >= BuiltinType::ShortAccum &&
>  BT->getKind() <= BuiltinType::LongAccum) ||
> (BT->getKind() >= BuiltinType::ShortFract &&
>  BT->getKind() <= BuiltinType::LongFract) ||
> (BT->getKind() >= BuiltinType::SatShortAccum &&
>  BT->getKind() <= BuiltinType::SatLongAccum) ||
> (BT->getKind() >= BuiltinType::SatShortFract &&
>  BT->getKind() <= BuiltinType::SatLongFract));
>   }
>   return false;
> }
> ```
> By looking at the implementation of this, I don't think you could substitute 
> that with `isSignedIntegerOrEnumerationType()`.
> Am I wrong about this?
> 
> Please demonstrate this by tests.
I tried using isSignedIntegerOrEnumerationType() instead of 
(T->isIntegralOrEnumerationType() || T->isFixedPointType() ... ), but got the 
same assert :/  

I corrected the formatting and expanded the test cases. 



Comment at: clang/test/Analysis/fixed-point.c:6-9
+long a(int c) {
   
+  (long _Accum) c >> 4;
+  return c;
+}  

steakhal wrote:
> It had a few extra spaces. And by casting it to void we could eliminate 
> `-Wno-unused` as well.
Dang, I used git-clang-format to try cleaning the patch thinking it would clean 
up formatting, but I guess it didn't :/ 

I cleaned up the test case and removed the -Wno-unused option. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139759

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


[clang-tools-extra] c824db4 - [clang-tools-extra] Use std::optional instead of None in comments (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T16:59:22-08:00
New Revision: c824db46d4bc0e34cd365b94a5262145757080a9

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

LOG: [clang-tools-extra] Use std::optional instead of None in comments (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
clang-tools-extra/clang-tidy/abseil/DurationRewriter.h
clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
clang-tools-extra/clangd/Hover.h
clang-tools-extra/clangd/ParsedAST.h
clang-tools-extra/pseudo/lib/DirectiveTree.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
index 86a5fc4c2ae7d..e5d98b0196f58 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -154,7 +154,7 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 ///
 /// Reads the option with the check-local name \p LocalName from the
 /// ``CheckOptions``. If the corresponding key is not present, return
-/// ``None``.
+/// ``std::nullopt``.
 llvm::Optional get(StringRef LocalName) const;
 
 /// Read a named option from the ``Context``.

diff  --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp 
b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
index 1e5ce5331f081..ba7dc70b2f606 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
@@ -46,7 +46,7 @@ static double getValue(const IntegerLiteral *IntLit,
 
 // Given the scale of a duration and a `Multiplier`, determine if `Multiplier`
 // would produce a new scale.  If so, return a tuple containing the new scale
-// and a suitable Multiplier for that scale, otherwise `None`.
+// and a suitable Multiplier for that scale, otherwise `std::nullopt`.
 static llvm::Optional>
 getNewScaleSingleStep(DurationScale OldScale, double Multiplier) {
   switch (OldScale) {

diff  --git a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h 
b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h
index 14126072a12ea..d8b0acf63cfd5 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h
+++ b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h
@@ -42,7 +42,7 @@ bool isLiteralZero(const 
ast_matchers::MatchFinder::MatchResult &Result,
 /// Possibly strip a floating point cast expression.
 ///
 /// If `Node` represents an explicit cast to a floating point type, return
-/// the textual context of the cast argument, otherwise `None`.
+/// the textual context of the cast argument, otherwise `std::nullopt`.
 llvm::Optional
 stripFloatCast(const ast_matchers::MatchFinder::MatchResult &Result,
const Expr &Node);

diff  --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
index d00afecd495de..327d98fc0485f 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
@@ -123,13 +123,14 @@ class RenamerClangTidyCheck : public ClangTidyCheck {
 
 protected:
   /// Overridden by derived classes, returns information about if and how a 
Decl
-  /// failed the check. A 'None' result means the Decl did not fail the check.
+  /// failed the check. A 'std::nullopt' result means the Decl did not fail the
+  /// check.
   virtual llvm::Optional
   getDeclFailureInfo(const NamedDecl *Decl, const SourceManager &SM) const = 0;
 
   /// Overridden by derived classes, returns information about if and how a
-  /// macro failed the check. A 'None' result means the macro did not fail the
-  /// check.
+  /// macro failed the check. A 'std::nullopt' result means the macro did not
+  /// fail the check.
   virtual llvm::Optional
   getMacroFailureInfo(const Token &MacroNameTok,
   const SourceManager &SM) const = 0;

diff  --git a/clang-tools-extra/clangd/Hover.h 
b/clang-tools-extra/clangd/Hover.h
index 1a46ff5ad772b..f9d83f64f142b 100644
--- a/clang-tools-extra/clangd/Hover.h
+++ b/clang-tools-extra/clangd/Hover.h
@@ -42,11 +42,11 @@ struct HoverInfo {
   /// - template  class Foo {};
   struct Param {
 /// The printable parameter type, e.g. "int", or "typename" (in
-/// TemplateParameters), might be None for macro parameters.
+/// TemplateParameters), might be std::nullopt for macro parameters.
 llvm::Optional Type;
- 

RE: [clang-tools-extra] f7dffc2 - Don't include None.h (NFC)

2022-12-10 Thread Yung, Douglas via cfe-commits
Hi Kazu,

Your change caused the build of cross-project-tests to fail, can you take a 
look?

https://lab.llvm.org/buildbot/#/builders/139/builds/32528
https://lab.llvm.org/buildbot/#/builders/216/builds/14213

Douglas Yung

-Original Message-
From: cfe-commits  On Behalf Of Kazu Hirata 
via cfe-commits
Sent: Saturday, December 10, 2022 11:25
To: cfe-commits@lists.llvm.org
Subject: [clang-tools-extra] f7dffc2 - Don't include None.h (NFC)


Author: Kazu Hirata
Date: 2022-12-10T11:24:26-08:00
New Revision: f7dffc28b3f82e25a0e283d2b11ffb9c6a129340

URL: 
https://urldefense.com/v3/__https://github.com/llvm/llvm-project/commit/f7dffc28b3f82e25a0e283d2b11ffb9c6a129340__;!!JmoZiZGBv3RvKRSx!-wSCRml8NKZ6L_rFklXVIa3eZ-9Oj9ghkmY_pDw3qu_F5kgPjlairS6IxzEhDrh1PHN6EmJeDNagyNtcXt744ldc21A$
 
DIFF: 
https://urldefense.com/v3/__https://github.com/llvm/llvm-project/commit/f7dffc28b3f82e25a0e283d2b11ffb9c6a129340.diff__;!!JmoZiZGBv3RvKRSx!-wSCRml8NKZ6L_rFklXVIa3eZ-9Oj9ghkmY_pDw3qu_F5kgPjlairS6IxzEhDrh1PHN6EmJeDNagyNtcXt74E--JnXY$
 

LOG: Don't include None.h (NFC)

I've converted all known uses of None to std::nullopt, so we no longer
need to include None.h.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://urldefense.com/v3/__https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716__;!!JmoZiZGBv3RvKRSx!-wSCRml8NKZ6L_rFklXVIa3eZ-9Oj9ghkmY_pDw3qu_F5kgPjlairS6IxzEhDrh1PHN6EmJeDNagyNtcXt74QT09naM$
 

Added: 


Modified: 
clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/support/ThreadsafeFS.h
clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang/include/clang/AST/DeclObjC.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/ExprObjC.h
clang/include/clang/AST/Type.h
clang/include/clang/Frontend/ASTUnit.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Sema/Overload.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/DeclObjC.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/AST/Type.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
clang/utils/TableGen/NeonEmitter.cpp
libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp
lldb/source/Core/Debugger.cpp
lldb/source/Core/ThreadedCommunication.cpp

lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.cpp
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleSaver.cpp
llvm/include/llvm/ADT/ArrayRef.h
llvm/include/llvm/ADT/BreadthFirstIterator.h
llvm/include/llvm/ADT/DepthFirstIterator.h
llvm/include/llvm/ADT/Optional.h
llvm/include/llvm/ADT/SmallSet.h
llvm/include/llvm/ADT/TinyPtrVector.h
llvm/include/llvm/BinaryFormat/AMDGPUMetadataVerifier.h
llvm/include/llvm/CodeGen/LiveRangeEdit.h
llvm/include/llvm/CodeGen/MIRParser/MIRParser.h
llvm/include/llvm/CodeGen/MachineTraceMetrics.h
llvm/include/llvm/CodeGen/TargetInstrInfo.h
llvm/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h
llvm/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
llvm/include/llvm/IR/Constants.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/include/llvm/IR/GCStrategy.h
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/InstrTypes.h
llvm/include/llvm/IR/Instruction.h
llvm/include/llvm/IR/Instructions.h
llvm/include/llvm/IR/Intrinsics.h
llvm/include/llvm/IR/Metadata.h
llvm/include/llvm/IR/Operator.h
llvm/include/llvm/IR/ValueMap.h
llvm/include/llvm/MC/MCParser/MCAsmParser.h
llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/include/llvm/Support/CommandLine.h
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/lib/Analysis/BlockFrequencyInfo.cpp
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/Bitcod

[clang] e55cc7d - Remove using llvm::None

2022-12-10 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-12-11T02:47:19Z
New Revision: e55cc7d11881f232ac19041b28fa46627c276577

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

LOG: Remove using llvm::None

Added: 


Modified: 
clang/include/clang/Basic/LLVM.h
mlir/include/mlir/Support/LLVM.h

Removed: 




diff  --git a/clang/include/clang/Basic/LLVM.h 
b/clang/include/clang/Basic/LLVM.h
index 955299504ece7..6375bd05fb5c3 100644
--- a/clang/include/clang/Basic/LLVM.h
+++ b/clang/include/clang/Basic/LLVM.h
@@ -69,7 +69,6 @@ namespace clang {
   // ADT's.
   using llvm::ArrayRef;
   using llvm::MutableArrayRef;
-  using llvm::None;
   using llvm::Optional;
   using llvm::OwningArrayRef;
   using llvm::SaveAndRestore;

diff  --git a/mlir/include/mlir/Support/LLVM.h 
b/mlir/include/mlir/Support/LLVM.h
index e442ca51a33bf..a389392301a00 100644
--- a/mlir/include/mlir/Support/LLVM.h
+++ b/mlir/include/mlir/Support/LLVM.h
@@ -129,7 +129,6 @@ using SetVector = llvm::SetVector;
 template 
 using StringSet = llvm::StringSet;
 using llvm::MutableArrayRef;
-using llvm::None;
 using llvm::Optional;
 using llvm::PointerUnion;
 using llvm::SmallPtrSet;



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


[PATCH] D136554: Implement CWG2631

2022-12-10 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

yes, it was chrome
I went ahead and tried the latest patch, it successfully compiles the file that 
crashed before. I built all of chrome, and now I'm getting one last linker 
error, I'll try to get some more info about that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[clang] ec94a5b - [StaticAnalyzer] Use std::optional in BugReporter.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T20:54:38-08:00
New Revision: ec94a5b71685d7d1d384fae5f6aa51b0c3d41037

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

LOG: [StaticAnalyzer] Use std::optional in BugReporter.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/BugReporter.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 70ec6face951b..d1624a82663e3 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -221,7 +221,7 @@ class PathDiagnosticBuilder : public BugReporterContext {
   /// Find a non-invalidated report for a given equivalence class,  and returns
   /// a PathDiagnosticBuilder able to construct bug reports for 
diff erent
   /// consumers. Returns std::nullopt if no valid report is found.
-  static Optional
+  static std::optional
   findValidReport(ArrayRef &bugReports,
   PathSensitiveBugReporter &Reporter);
 
@@ -2821,7 +2821,7 @@ generateVisitorsDiagnostics(PathSensitiveBugReport *R,
   return Notes;
 }
 
-Optional PathDiagnosticBuilder::findValidReport(
+std::optional PathDiagnosticBuilder::findValidReport(
 ArrayRef &bugReports,
 PathSensitiveBugReporter &Reporter) {
 
@@ -2880,7 +2880,7 @@ PathSensitiveBugReporter::generatePathDiagnostics(
 
   auto Out = std::make_unique();
 
-  Optional PDB =
+  std::optional PDB =
   PathDiagnosticBuilder::findValidReport(bugReports, *this);
 
   if (PDB) {



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


[clang] a67a115 - [StaticAnalyzer] Use std::optional in BugReporterVisitors.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T21:11:31-08:00
New Revision: a67a11536e1cfaec0e02a740b5a77f0db4e1481a

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

LOG: [StaticAnalyzer] Use std::optional in BugReporterVisitors.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 811fd036e307..e36716fe2aac 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -205,8 +205,8 @@ static bool hasVisibleUpdate(const ExplodedNode *LeftNode, 
SVal LeftVal,
 RLCV->getStore() == RightNode->getState()->getStore();
 }
 
-static Optional getSValForVar(const Expr *CondVarExpr,
-const ExplodedNode *N) {
+static std::optional getSValForVar(const Expr *CondVarExpr,
+ const ExplodedNode *N) {
   ProgramStateRef State = N->getState();
   const LocationContext *LCtx = N->getLocationContext();
 
@@ -229,10 +229,10 @@ static Optional getSValForVar(const Expr 
*CondVarExpr,
   return std::nullopt;
 }
 
-static Optional
+static std::optional
 getConcreteIntegerValue(const Expr *CondVarExpr, const ExplodedNode *N) {
 
-  if (Optional V = getSValForVar(CondVarExpr, N))
+  if (std::optional V = getSValForVar(CondVarExpr, N))
 if (auto CI = V->getAs())
   return &CI->getValue();
   return std::nullopt;
@@ -247,7 +247,7 @@ static bool isVarAnInterestingCondition(const Expr 
*CondVarExpr,
   if (!B->getErrorNode()->getStackFrame()->isParentOf(N->getStackFrame()))
 return false;
 
-  if (Optional V = getSValForVar(CondVarExpr, N))
+  if (std::optional V = getSValForVar(CondVarExpr, N))
 if (Optional K = B->getInterestingnessKind(*V))
   return *K == bugreporter::TrackingKind::Condition;
 
@@ -256,7 +256,7 @@ static bool isVarAnInterestingCondition(const Expr 
*CondVarExpr,
 
 static bool isInterestingExpr(const Expr *E, const ExplodedNode *N,
   const PathSensitiveBugReport *B) {
-  if (Optional V = getSValForVar(E, N))
+  if (std::optional V = getSValForVar(E, N))
 return B->getInterestingnessKind(*V).has_value();
   return false;
 }
@@ -3244,7 +3244,7 @@ bool ConditionBRVisitor::printValue(const Expr 
*CondVarExpr, raw_ostream &Out,
   if (!Ty->isIntegralOrEnumerationType())
 return false;
 
-  Optional IntValue;
+  std::optional IntValue;
   if (!IsAssuming)
 IntValue = getConcreteIntegerValue(CondVarExpr, N);
 



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


[clang] 602af71 - [StaticAnalyzer] Use std::optional in BugReporter.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T21:11:29-08:00
New Revision: 602af71c29a7553b68368443e6d938827a1dce8f

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

LOG: [StaticAnalyzer] Use std::optional in BugReporter.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/BugReporter.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index d1624a82663e..513de15cab69 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -1569,8 +1569,8 @@ static void simplifySimpleBranches(PathPieces &pieces) {
 /// std::nullopt.
 ///
 /// Note that this does not do a precise user-visible character or column 
count.
-static Optional getLengthOnSingleLine(const SourceManager &SM,
-  SourceRange Range) {
+static std::optional getLengthOnSingleLine(const SourceManager &SM,
+   SourceRange Range) {
   SourceRange ExpansionRange(SM.getExpansionLoc(Range.getBegin()),
  SM.getExpansionRange(Range.getEnd()).getEnd());
 
@@ -1598,8 +1598,8 @@ static Optional getLengthOnSingleLine(const 
SourceManager &SM,
 }
 
 /// \sa getLengthOnSingleLine(SourceManager, SourceRange)
-static Optional getLengthOnSingleLine(const SourceManager &SM,
-  const Stmt *S) {
+static std::optional getLengthOnSingleLine(const SourceManager &SM,
+   const Stmt *S) {
   return getLengthOnSingleLine(SM, S->getSourceRange());
 }
 
@@ -1658,9 +1658,9 @@ static void removeContextCycles(PathPieces &Path, const 
SourceManager &SM) {
 
 if (s1Start && s2Start && s1Start == s2End && s2Start == s1End) {
   const size_t MAX_SHORT_LINE_LENGTH = 80;
-  Optional s1Length = getLengthOnSingleLine(SM, s1Start);
+  std::optional s1Length = getLengthOnSingleLine(SM, s1Start);
   if (s1Length && *s1Length <= MAX_SHORT_LINE_LENGTH) {
-Optional s2Length = getLengthOnSingleLine(SM, s2Start);
+std::optional s2Length = getLengthOnSingleLine(SM, s2Start);
 if (s2Length && *s2Length <= MAX_SHORT_LINE_LENGTH) {
   Path.erase(I);
   I = Path.erase(NextI);
@@ -1719,7 +1719,7 @@ static void removePunyEdges(PathPieces &path, const 
SourceManager &SM,
   std::swap(SecondLoc, FirstLoc);
 
 SourceRange EdgeRange(FirstLoc, SecondLoc);
-Optional ByteWidth = getLengthOnSingleLine(SM, EdgeRange);
+std::optional ByteWidth = getLengthOnSingleLine(SM, EdgeRange);
 
 // If the statements are on 
diff erent lines, continue.
 if (!ByteWidth)



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


[clang] 3e57273 - [StaticAnalyzer] Use std::optional in RetainCountDiagnostics.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T21:15:44-08:00
New Revision: 3e572733d9d8eba90cfc5812c70e0d2df02f72b2

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

LOG: [StaticAnalyzer] Use std::optional in RetainCountDiagnostics.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index 3afaf622aab40..4583b2191bf2b 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -603,7 +603,7 @@ RefCountReportVisitor::VisitNode(const ExplodedNode *N, 
BugReporterContext &BRC,
   return std::move(P);
 }
 
-static Optional describeRegion(const MemRegion *MR) {
+static std::optional describeRegion(const MemRegion *MR) {
   if (const auto *VR = dyn_cast_or_null(MR))
 return std::string(VR->getDecl()->getName());
   // Once we support more storage locations for bindings,
@@ -772,7 +772,7 @@ RefLeakReportVisitor::getEndPath(BugReporterContext &BRC,
 
   os << "Object leaked: ";
 
-  Optional RegionDescription = describeRegion(LastBinding);
+  std::optional RegionDescription = describeRegion(LastBinding);
   if (RegionDescription) {
 os << "object allocated and stored into '" << *RegionDescription << '\'';
   } else {
@@ -918,7 +918,7 @@ void RefLeakReport::createDescription(CheckerContext &Ctx) {
   llvm::raw_string_ostream os(Description);
   os << "Potential leak of an object";
 
-  Optional RegionDescription =
+  std::optional RegionDescription =
   describeRegion(AllocBindingToReport);
   if (RegionDescription) {
 os << " stored into '" << *RegionDescription << '\'';



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


[clang] eacf7c8 - [StaticAnalyzer] Use std::optional in MallocChecker.cpp (NFC)

2022-12-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-10T21:15:43-08:00
New Revision: eacf7c874b1e17818742b0c1d4fd325e3459cfa1

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

LOG: [StaticAnalyzer] Use std::optional in MallocChecker.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 8cd87853de208..a26c4f3389129 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1644,7 +1644,7 @@ static bool isKnownDeallocObjCMethodName(const 
ObjCMethodCall &Call) {
  FirstSlot == "initWithCharactersNoCopy";
 }
 
-static Optional getFreeWhenDoneArg(const ObjCMethodCall &Call) {
+static std::optional getFreeWhenDoneArg(const ObjCMethodCall &Call) {
   Selector S = Call.getSelector();
 
   // FIXME: We should not rely on fully-constrained symbols being folded.
@@ -1663,7 +1663,7 @@ void MallocChecker::checkPostObjCMessage(const 
ObjCMethodCall &Call,
   if (!isKnownDeallocObjCMethodName(Call))
 return;
 
-  if (Optional FreeWhenDone = getFreeWhenDoneArg(Call))
+  if (std::optional FreeWhenDone = getFreeWhenDoneArg(Call))
 if (!*FreeWhenDone)
   return;
 
@@ -3141,7 +3141,7 @@ bool 
MallocChecker::mayFreeAnyEscapedMemoryOrIsModeledExplicitly(
 // about, we can't be sure that the object will use free() to deallocate 
the
 // memory, so we can't model it explicitly. The best we can do is use it to
 // decide whether the pointer escapes.
-if (Optional FreeWhenDone = getFreeWhenDoneArg(*Msg))
+if (std::optional FreeWhenDone = getFreeWhenDoneArg(*Msg))
   return *FreeWhenDone;
 
 // If the first selector piece ends with "NoCopy", and there is no



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


[PATCH] D139759: [analyzer] Fix assertion in getAPSIntType

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



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:157-158
+   Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }

vabridgers wrote:
> steakhal wrote:
> > I don't think you are supposed to call `isSignedIntegerOrEnumerationType()` 
> > if you have a //fixed-point// type.
> > ```lang=C++
> > inline bool Type::isSignedFixedPointType() const {
> >   if (const auto *BT = dyn_cast(CanonicalType)) {
> > return ((BT->getKind() >= BuiltinType::ShortAccum &&
> >  BT->getKind() <= BuiltinType::LongAccum) ||
> > (BT->getKind() >= BuiltinType::ShortFract &&
> >  BT->getKind() <= BuiltinType::LongFract) ||
> > (BT->getKind() >= BuiltinType::SatShortAccum &&
> >  BT->getKind() <= BuiltinType::SatLongAccum) ||
> > (BT->getKind() >= BuiltinType::SatShortFract &&
> >  BT->getKind() <= BuiltinType::SatLongFract));
> >   }
> >   return false;
> > }
> > ```
> > By looking at the implementation of this, I don't think you could 
> > substitute that with `isSignedIntegerOrEnumerationType()`.
> > Am I wrong about this?
> > 
> > Please demonstrate this by tests.
> I tried using isSignedIntegerOrEnumerationType() instead of 
> (T->isIntegralOrEnumerationType() || T->isFixedPointType() ... ), but got the 
> same assert :/  
> 
> I corrected the formatting and expanded the test cases. 
Is hould have clarified, sorry.

My point is that for constructing the APSIntType, we calculate the bitwidth and 
the signedness.

My problem is that the calculation is wrong for the signedness in case we have 
a signed fixedpointtype.
It is wrong because we reach `isSignedIntegerOrEnumerationType()` with a 
fixedpoint type. For that even though its signed, it will return false!

And in the end we will have an APSIntType with the wrong signednss.

So my point is that we should probably handle fixedpoint types separately to 
have a distict return statement for it.
But im jumping to the solution, what I originally wanted to highlight was this.
That was why I requested changes.
And this is what I wanted to see some how intests, but I wont insist if its too 
difficult to craft.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139759

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