[PATCH] D92160: [clang] Fix wrong FDs are used for files with same name in Tooling

2022-05-03 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie added a comment.

In D92160#3485400 , @Kale wrote:

> In D92160#2449507 , @dexonsmith 
> wrote:
>
>> But it's possible we don't need this. If it's safe for us to update the 
>> tests and make `FileManager::getFileRef` always canonicalize to an absolute 
>> path, that would definitely be cleaner. `FileManager::makeAbsolute` can use 
>> whatever the FS's CWD is at the time of query... nice and clean.
>
> I've tried to fix this bug through this way but found that "making 
> `FileManager::getFileRef` always canonicalize to an absolute path" was pretty 
> hard, because there are many test cases using states stored in FileManager 
> and assuming that they are all in relative form. Besides, the assumption that 
> "the CWD won't change" indeed is correct by design and works fine for single 
> compiler execution. We might not change that unless for a strong necessity.
>
> So I personally believed that this bug is caused by libtooling's incorrect 
> use of `FileManger`. I plan to fix it by implementing a class like 
> `LibtoolingFileManager`, or `AbsoluteFileManager`, which extends the original 
> `FileManager` and using abs path as key to store the status of seen files, 
> but only used for libtooling.
>
> I will try to upload a patch later to verify the possibility.

Thanks a lot for taking over this bug. Please remember to close this patch if 
your new patch can solve this problem.
I will forward all the comments from the original author (Hao Zhang) if he has 
any suggestions for your new patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92160

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


[PATCH] D27068: Improve string::find

2022-05-03 Thread JianYongChan via Phabricator via cfe-commits
Tangmou added inline comments.
Herald added a project: All.



Comment at: libcxx/trunk/include/__string:557
+  _CharT __f2 = *__first2;
+  while (true) {
+__len1 = __last1 - __first1;

Sorry for the comment after such a long time, but I have a question about this 
patch.

Since we have already calculated `__len1` and ensured that `__len1 < __len2` 
before the loop,  can we just skip the length calculation and the comparison in 
the first loop cycle?  And thus we can replace the `while` loop with `do-while` 
or keep the `while` loop but delete the length calculation and the comparison 
before the loop?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D27068

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


[PATCH] D124807: [clang][dataflow] Only skip ExprWithCleanups when visiting terminators

2022-05-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.

Nice!! As Gabor said, thank you for the detailed explanation (on top of the 
work to get this all done in a principled manner).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124807

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


[PATCH] D124534: [clang] Add a diagnostic for line directive of a gnu extension

2022-05-03 Thread Ken Matsui via Phabricator via cfe-commits
ken-matsui added a comment.

@aaron.ballman

> If so, I think putting Diag after the call of this function would be better.

With the above change, I tried to add comments to failed tests, but there were 
over 300 files.

During my investigation, I found most tests printed warnings without file 
information strangely.

  error: 'warning' diagnostics seen but not expected: 
Line 0: this style of line directive is a GNU extension
Line 0: this style of line directive is a GNU extension
  2 errors generated.

If warnings have file information, it should be like:

  error: 'warning' diagnostics seen but not expected: 
File /tmp/llvm-project/clang/test/Preprocessor/line-directive.c Line 9: 
this style of line directive is a GNU extension
  1 error generated.

Even tests that completely do not use preprocessor directives, such as 
`clang/test/SemaCXX/matrix-type.cpp`, failed with the above strange warnings.

Thus, I suspect that the warnings without file paths have come from internally 
included SDK (I'm using macOS that includes 
`/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk`)
 or something that is not related to target test files.

What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124534

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


[clang] 46a5a80 - [OpenMP] Fix save-temps name in linker wrapper

2022-05-03 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-05-03T20:51:05-04:00
New Revision: 46a5a8029e151daf6cb97d51c9cdd1aeab59de78

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

LOG: [OpenMP] Fix save-temps name in linker wrapper

Summary:
The wrapped registration code had a typo in the save-temps version of
the name.

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 4ed303fa233f0..d9a7fecdde24f 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -1185,9 +1185,8 @@ Expected compileModule(Module ) {
 
   SmallString<128> ObjectFile;
   int FD = -1;
-  if (Error Err = createOutputFile(sys::path::filename(ExecutableName) +
-   "offload-wrapper",
-   "o", ObjectFile))
+  if (Error Err = createOutputFile(
+  sys::path::filename(ExecutableName) + "-wrapper", "o", ObjectFile))
 return std::move(Err);
   if (std::error_code EC = sys::fs::openFileForWrite(ObjectFile, FD))
 return errorCodeToError(EC);



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


[clang-tools-extra] 0e86cdd - [psuedo] Fix for unused warning by moving code into debug macro.

2022-05-03 Thread via cfe-commits

Author: Weverything
Date: 2022-05-03T16:07:59-07:00
New Revision: 0e86cddf988081018200bcdce22a96d9e91a

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

LOG: [psuedo] Fix for unused warning by moving code into debug macro.

Added: 


Modified: 
clang-tools-extra/pseudo/lib/GLR.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/GLR.cpp 
b/clang-tools-extra/pseudo/lib/GLR.cpp
index c1fdd8680ca85..771d69fb680dc 100644
--- a/clang-tools-extra/pseudo/lib/GLR.cpp
+++ b/clang-tools-extra/pseudo/lib/GLR.cpp
@@ -90,12 +90,13 @@ const ForestNode (const TokenStream ,
 });
 
   if (!PendingAccept.empty()) {
-LLVM_DEBUG(llvm::dbgs() << llvm::formatv("Accept: {0} accepted result:\n",
- PendingAccept.size()));
-for (const auto  : PendingAccept)
-  LLVM_DEBUG(llvm::dbgs()
- << "  - " << G.symbolName(Accept.Head->Payload->symbol())
- << "\n");
+LLVM_DEBUG({
+  llvm::dbgs() << llvm::formatv("Accept: {0} accepted result:\n",
+ PendingAccept.size());
+  for (const auto  : PendingAccept)
+llvm::dbgs() << "  - " << G.symbolName(Accept.Head->Payload->symbol())
+ << "\n";
+});
 assert(PendingAccept.size() == 1);
 return *PendingAccept.front().Head->Payload;
   }



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


[PATCH] D124666: In MSVC compatibility mode, handle unqualified templated base class initialization

2022-05-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:4310-4311
 
   // If no results were found, try to correct typos.
   TypoCorrection Corr;
   MemInitializerValidatorCCC CCC(ClassDecl);

rnk wrote:
> We have to make sure our MS compatibility logic fires *before* we try to 
> correct typos. It's currently a big issue that we don't. You can try 
> adjusting your test case by adding a similarly named class like `Baze` and 
> see if you still get the desired behavior.
> 
> See this old issue from 2014:
> https://github.com/llvm/llvm-project/issues/20623
What I'd like to see is just to move the MSVCCompat check up before the typo 
correction. Basically, once we start typo correction, we *must* emit an error 
diagnostic. We may attempt to recover by returning a recovery AST node, but the 
compilation should fail overall.

I think in practice, we only do typo correction if lookup is empty, and your 
code only fires if name lookup returns a single result, so it's functionally 
equivalent to reorder these codepaths. I'd prefer that structure, mostly for 
readability.


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

https://reviews.llvm.org/D124666

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


[PATCH] D124489: Deprecate LLVM_BUILD_EXTERNAL_COMPILER_RT

2022-05-03 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai resigned from this revision.
smeenai added a comment.

LGTM after changing to an error with a warning downgrade. Resigning to clear my 
queue, plus the Apple folks should get the final accept here :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124489

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


[PATCH] D124790: [HLSL] Enable half type for hlsl.

2022-05-03 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added inline comments.



Comment at: clang/lib/Basic/LangOptions.cpp:197
 
-  // OpenCL has half keyword
-  Opts.Half = Opts.OpenCL;
+  // OpenCL and HLSL have half keyword
+  Opts.Half = Opts.OpenCL || Opts.HLSL;

python3kgae wrote:
> aaron.ballman wrote:
> > python3kgae wrote:
> > > aaron.ballman wrote:
> > > > Shouldn't this be looking for HLSL 2018? Or shader model 6.2?
> > > half keyword is always available.
> > > Without enable_16bit_types, half will be like using half=float.
> > > With enable_16bit_types, half will be real half.
> > > 
> > > The check for HLSL 2018 and shader model 6.2 will be in another PR, still 
> > > WIP. I'll add FIXME about it.
> > > half keyword is always available.
> > > Without enable_16bit_types, half will be like using half=float.
> > > With enable_16bit_types, half will be real half.
> > 
> > Is there room for change here, or is this strictly required by HLSL? This 
> > strikes me as just begging to confuse users into creating ODR violations. 
> > CC @beanz 
> Here's the doc about half for dxc.
> https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types
> 
> Old doc for fxc (the old shader compiler for shader model <= 5.1) is here
> https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-scalar
> 
> Change the behavior might affect a lot of existing shaders.
More detail about half from https://github.com/tex3d.

half originally mapped to a fuzzy "partial precision" float, where some 
operations were designated as _pp, meaning the implementation was free to use 
lower-precision math for those operations (like 24-bit, but not specified for 
the language). All storage in host-visible memory would still be float. 
"partial precision" went away with DX9, eventually to be replaced with 
min-precision with a specific minimum precision an implementation was allowed 
to use. When "partial precision" went away, it simply mapped to float for DX10+.
People could have tried to use it liberally when they thought 32-bit precision 
wasn't necessary, without explicitly targeting/testing API/hardware that 
actually supported lower precision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124790

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


[PATCH] D124836: [AArch64] Add support for -fzero-call-used-regs

2022-05-03 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:752
+#undef CASE
+  }
+}

kristof.beyls wrote:
> Just a drive-by comment: I'm wondering if SVE registers should also be listed 
> here?
I'm not familiar with the SVE registers (I assume you mean the `Z#` and `P#` 
ones). Could you give an example program?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124836

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


[PATCH] D124836: [AArch64] Add support for -fzero-call-used-regs

2022-05-03 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:776-778
+  // For GPRs, we only care to clear out the 64-bit register.
+  if (MCRegister XReg = getRegisterOrZero(Reg))
+GPRsToZero.set(XReg);

nickdesaulniers wrote:
> nickdesaulniers wrote:
> > so for 32b registers, we clear the whole 64b register?
> Perhaps a more descriptive method name like `getWidestRegisterAlias` or the 
> like? Perhaps we should simply assert if we get a non GPR rather than return 
> 0, which might actually be a Register?
> 
> Also, TargetRegisterClass has some notion of sub and super register classes. 
> I wonder if have existing machinery to say, given a register class, what's 
> the equivalent/aliases super register class (if that's even what a super 
> register is).
That's what's happening with GCC. https://godbolt.org/z/W6b7zxYnK

> Perhaps we should simply assert if we get a non GPR rather than return 0, 
> which might actually be a Register?

I'm also using it for the vector registers. And 0 can't be a register. (See 
`include/llvm/MC/Register.h`.)

Might be able to use the TRC. But I see that X86 has 
`llvm::getX86SubSuperRegisterOrZero` in `X86MCTargetDesc.cpp` which has a large 
table of registers so that you can get the register of the proper size.



Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:787-792
+  for (MCRegister Reg : GPRsToZero.set_bits())
+BuildMI(MBB, MBBI, DL, TII->get(AArch64::MOVi64imm), Reg).addImm(0);
+
+  // Zero out FP/vector registers.
+  for (MCRegister Reg : FPRsToZero.set_bits())
+BuildMI(MBB, MBBI, DL, TII->get(AArch64::MOVID), Reg).addImm(0);

nickdesaulniers wrote:
> isn't it more canonical on ARM to move from the dedicated zero register XZR 
> rather than use an immediate?
GCC outputs the immediate move. I'm not familiar though with what's more 
canonical.



Comment at: llvm/lib/Target/AArch64/AArch64RegisterInfo.td:1404
+}
+def FPR32_ARG : RegisterClass<"AArch64", [f32, i32], 32, (trunc FPR32, 7)>;
+def FPR64_ARG : RegisterClass<"AArch64",

nickdesaulniers wrote:
> is `i32` correct here?
That's what FPR32 is defined to be:

```
def FPR32 : RegisterClass<"AArch64", [f32, i32], 32,(sequence "S%u", 0, 31)>;
```



Comment at: llvm/lib/Target/X86/X86RegisterInfo.cpp:659
 
-  return false;
+  return X86GenRegisterInfo::isArgumentRegister(MF, Reg);
 }

nickdesaulniers wrote:
> Does this allow us to clean up anything else in the body of this method?
> 
> Consider making this and the tablegen related patch a distinct child patch.
It's possible to simplify here, but it would take more work. I'll address that 
in a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124836

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


[PATCH] D124807: [clang][dataflow] Only skip ExprWithCleanups when visiting terminators

2022-05-03 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua updated this revision to Diff 426860.
li.zhe.hua edited the summary of this revision.
li.zhe.hua added a comment.

Expand `ignoreExprWithCleanups` comment with more context.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124807

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Transfer.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -1152,4 +1152,39 @@
   });
 }
 
+// FIXME: Remove this test once it provides no additional test coverage.
+TEST_F(FlowConditionTest, DoesNotAssertForImplicitCastToBool) {
+  std::string Code = R"(
+void target(int *Ptr) {
+  bool Foo = false;
+  if (Ptr) {
+Foo = true;
+/*[[p1]]*/
+  }
+
+  (void)0;
+  /*[[p2]]*/
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p2", _), Pair("p1", _)));
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const Environment  = Results[1].second.Env;
+auto  =
+*cast(Env1.getValue(*FooDecl, SkipPast::Reference));
+EXPECT_TRUE(Env1.flowConditionImplies(FooVal1));
+
+const Environment  = Results[0].second.Env;
+auto  =
+*cast(Env2.getValue(*FooDecl, SkipPast::Reference));
+EXPECT_FALSE(Env2.flowConditionImplies(FooVal2));
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -77,26 +77,26 @@
   : StmtToEnv(StmtToEnv), Env(Env), BlockSuccIdx(BlockSuccIdx) {}
 
   void VisitIfStmt(const IfStmt *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = ignoreExprWithCleanups(S->getCond())->IgnoreParens();
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
 
   void VisitWhileStmt(const WhileStmt *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = ignoreExprWithCleanups(S->getCond())->IgnoreParens();
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
 
   void VisitBinaryOperator(const BinaryOperator *S) {
 assert(S->getOpcode() == BO_LAnd || S->getOpcode() == BO_LOr);
-auto *LHS = S->getLHS()->IgnoreParenImpCasts();
+auto *LHS = ignoreExprWithCleanups(S->getLHS())->IgnoreParens();
 assert(LHS != nullptr);
 extendFlowCondition(*LHS);
   }
 
   void VisitConditionalOperator(const ConditionalOperator *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = ignoreExprWithCleanups(S->getCond())->IgnoreParens();
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -33,7 +33,7 @@
 namespace clang {
 namespace dataflow {
 
-static const Expr *skipExprWithCleanups(const Expr *E) {
+const Expr *ignoreExprWithCleanups(const Expr *E) {
   if (auto *C = dyn_cast_or_null(E))
 return C->getSubExpr();
   return E;
@@ -157,7 +157,7 @@
 
 // The CFG does not contain `ParenExpr` as top-level statements in basic
 // blocks, however sub-expressions can still be of that type.
-InitExpr = skipExprWithCleanups(D.getInit()->IgnoreParens());
+InitExpr = ignoreExprWithCleanups(D.getInit()->IgnoreParens());
 assert(InitExpr != nullptr);
 
 if (D.getType()->isReferenceType()) {
@@ -605,6 +605,7 @@
 
 void transfer(const StmtToEnvMap , const Stmt , Environment ) {
   assert(!isa());
+  assert(!isa());
   TransferVisitor(StmtToEnv, Env).Visit();
 }
 
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -220,8 +220,8 @@
 
 void 

[PATCH] D124638: [clang] Track how headers get included generally during lookup time

2022-05-03 Thread Cyndy Ishida via Phabricator via cfe-commits
cishida updated this revision to Diff 426858.
cishida added a comment.

Hold include name in `HeaderSearch` itself, keeping HeaderFileInfo lightweight.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124638

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/unittests/Lex/HeaderSearchTest.cpp


Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -207,6 +207,7 @@
   EXPECT_TRUE(FI);
   EXPECT_TRUE(FI->IsValid);
   EXPECT_EQ(FI->Framework.str(), "Foo");
+  EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h");
 }
 
 // Helper struct with null terminator character to make MemoryBuffer happy.
@@ -275,6 +276,7 @@
   EXPECT_TRUE(FI);
   EXPECT_TRUE(FI->IsValid);
   EXPECT_EQ(FI->Framework.str(), "Foo");
+  EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h");
 }
 
 } // namespace
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1030,8 +1030,11 @@
 
 CurDir = It;
 
+const auto FE = >getFileEntry();
+IncludeNames[FE] = Filename;
+
 // This file is a system header or C++ unfriendly if the dir is.
-HeaderFileInfo  = getFileInfo(>getFileEntry());
+HeaderFileInfo  = getFileInfo(FE);
 HFI.DirInfo = CurDir->getDirCharacteristic();
 
 // If the directory characteristic is User but this framework was
@@ -1460,6 +1463,13 @@
   return FrameworkNames.insert(Framework).first->first();
 }
 
+StringRef HeaderSearch::getIncludeNameForHeader(const FileEntry *File) const {
+  auto It = IncludeNames.find(File);
+  if (It == IncludeNames.end())
+return {};
+  return It->second;
+}
+
 bool HeaderSearch::hasModuleMap(StringRef FileName,
 const DirectoryEntry *Root,
 bool IsSystem) {
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -20,6 +20,7 @@
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
@@ -314,6 +315,9 @@
   /// whether they were valid or not.
   llvm::DenseMap LoadedModuleMaps;
 
+  // A map of discovered headers with their associated include file name.
+  llvm::DenseMap> IncludeNames;
+
   /// Uniqued set of framework names, which is used to track which
   /// headers were included as framework headers.
   llvm::StringSet FrameworkNames;
@@ -823,6 +827,13 @@
   /// Retrieve a uniqued framework name.
   StringRef getUniqueFrameworkName(StringRef Framework);
 
+  /// Retrieve the include name for the header.
+  ///
+  /// \param File The entry for a given header.
+  /// \returns The name of how the file was included when the header's location
+  /// was resolved.
+  StringRef getIncludeNameForHeader(const FileEntry *File) const;
+
   /// Suggest a path by which the specified file could be found, for use in
   /// diagnostics to suggest a #include. Returned path will only contain 
forward
   /// slashes as separators. MainFile is the absolute path of the file that we


Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -207,6 +207,7 @@
   EXPECT_TRUE(FI);
   EXPECT_TRUE(FI->IsValid);
   EXPECT_EQ(FI->Framework.str(), "Foo");
+  EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h");
 }
 
 // Helper struct with null terminator character to make MemoryBuffer happy.
@@ -275,6 +276,7 @@
   EXPECT_TRUE(FI);
   EXPECT_TRUE(FI->IsValid);
   EXPECT_EQ(FI->Framework.str(), "Foo");
+  EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h");
 }
 
 } // namespace
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1030,8 +1030,11 @@
 
 CurDir = It;
 
+const auto FE = >getFileEntry();
+IncludeNames[FE] = Filename;
+
 // This file is a system header or C++ unfriendly if the dir is.
-HeaderFileInfo  = getFileInfo(>getFileEntry());
+HeaderFileInfo  = getFileInfo(FE);
 HFI.DirInfo = CurDir->getDirCharacteristic();
 
 // If the directory characteristic is User but this framework was
@@ -1460,6 +1463,13 @@
   return FrameworkNames.insert(Framework).first->first();
 }
 
+StringRef HeaderSearch::getIncludeNameForHeader(const FileEntry *File) const {
+  auto It = 

[PATCH] D124790: [HLSL] Enable half type for hlsl.

2022-05-03 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 426854.
python3kgae added a comment.

Add option -fcgl which output clang codeGen result to avoid test dependent on 
build DirectX backend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124790

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/HLSL.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenHLSL/half.hlsl

Index: clang/test/CodeGenHLSL/half.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/half.hlsl
@@ -0,0 +1,15 @@
+// RUN: %clang_dxc -Tlib_6_7 -fcgl  -Fo - %s | FileCheck %s --check-prefix=FLOAT
+// RUN: %clang_dxc -Tlib_6_7 -enable-16bit-types -fcgl  -Fo - %s | FileCheck %s --check-prefix=HALF
+
+// Make sure use float when not enable-16bit-types.
+// FLOAT:define {{.*}}float @_Z3fooff(float{{[^,]+}}, float{{[^,)]+}})
+// FLOAT-NOT:half
+// FLOAT:ret float %
+
+// Make sure use half when enable-16bit-types.
+// HALF:define {{.*}}half @_Z3fooDhDh(half{{[^,]+}}, half{{[^,)]+}})
+// HALF-NOT:float
+// HALF:ret half %
+half foo(half a, half b) {
+  return a+b;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1509,7 +1509,13 @@
 << "_Float16";
 Result = Context.Float16Ty;
 break;
-  case DeclSpec::TST_half:Result = Context.HalfTy; break;
+  case DeclSpec::TST_half:
+// For HLSL, when not enable native half type, half will be treat as float.
+if (S.getLangOpts().HLSL && !S.getLangOpts().NativeHalfType)
+  Result = Context.FloatTy;
+else
+  Result = Context.HalfTy;
+break;
   case DeclSpec::TST_BFloat16:
 if (!S.Context.getTargetInfo().hasBFloat16Type())
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
Index: clang/lib/Driver/ToolChains/HLSL.cpp
===
--- clang/lib/Driver/ToolChains/HLSL.cpp
+++ clang/lib/Driver/ToolChains/HLSL.cpp
@@ -169,6 +169,13 @@
   if (!isLegalValidatorVersion(ValVerStr, getDriver()))
 continue;
 }
+if (A->getOption().getID() == options::OPT_fcgl) {
+  // Translate fcgl into -S -emit-llvm.
+  DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_S));
+  DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_emit_llvm));
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
   // Add default validator version if not set.
@@ -179,5 +186,7 @@
 Opts.getOption(options::OPT_dxil_validator_version),
 DefaultValidatorVer);
   }
+  // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
+  // shader model 6.2.
   return DAL;
 }
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3470,11 +3470,14 @@
 
 static void RenderHLSLOptions(const ArgList , ArgStringList ,
   types::ID InputType) {
-  const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version};
+  const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version,
+ options::OPT_S, options::OPT_emit_llvm,
+ options::OPT_fnative_half_type};
 
   for (const auto  : ForwardedArguments)
 if (const auto *A = Args.getLastArg(Arg))
   A->renderAsInput(Args, CmdArgs);
+  CmdArgs.push_back("-fallow-half-arguments-and-returns");
 }
 
 static void RenderARCMigrateToolOptions(const Driver , const ArgList ,
Index: clang/lib/Basic/Targets/DirectX.h
===
--- clang/lib/Basic/Targets/DirectX.h
+++ clang/lib/Basic/Targets/DirectX.h
@@ -58,7 +58,7 @@
 resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
 "32-f64:64-n8:16:32:64");
   }
-
+  bool useFP16ConversionIntrinsics() const override { return false; }
   void getTargetDefines(const LangOptions ,
 MacroBuilder ) const override;
 
Index: clang/lib/Basic/LangOptions.cpp
===
--- clang/lib/Basic/LangOptions.cpp
+++ clang/lib/Basic/LangOptions.cpp
@@ -194,8 +194,8 @@
   // OpenCL, C++ and C2x have bool, true, false keywords.
   Opts.Bool = Opts.OpenCL || Opts.CPlusPlus || Opts.C2x;
 
-  // OpenCL has half keyword
-  Opts.Half = Opts.OpenCL;
+  // OpenCL and HLSL have half keyword
+  Opts.Half = Opts.OpenCL || Opts.HLSL;
 }
 
 FPOptions FPOptions::defaultWithoutTrailingStorage(const LangOptions ) {
Index: 

[PATCH] D124748: [clang-format] Fix whitespace counting stuff

2022-05-03 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

Is this patch NFC?




Comment at: clang/lib/Format/FormatTokenLexer.cpp:859-867
+switch (Cur[0]) {
+case '\n':
+case '\r':
+case '\f':
+case '\v':
+case ' ':
+case '\t':

I'd replace the `switch` with `if (isspace(Cur[0])) ... else if (Cur[1] == '\n' 
...) ...`.



Comment at: clang/lib/Format/FormatTokenLexer.cpp:914
+auto LeadingWhitespace = countLeadingWhitespace(FormatTok->TokenText);
+if (!LeadingWhitespace)
+  break;





Comment at: clang/lib/Format/FormatTokenLexer.cpp:923-924
+  case '\r':
+if (i + 1 < e && Text[i + 1] == '\n')
+  break;
+LLVM_FALLTHROUGH;

`\r\n` is a newline on Windows.



Comment at: clang/lib/Format/FormatTokenLexer.cpp:930
+  FormatTok->HasUnescapedNewline = true;
+InEscape = false;
 FormatTok->LastNewlineOffset = WhitespaceLength + i + 1;





Comment at: clang/lib/Format/FormatTokenLexer.cpp:946-948
+  case '?':
+  case '/':
+InEscape = true;

Don't you need to look ahead for a `??/`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124748

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


[PATCH] D124807: [clang][dataflow] Only skip ExprWithCleanups when visiting terminators

2022-05-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:78
+/// and integers in the framework.
+static const Expr *ignoreParenImpCastsExceptToBool(const Expr *E) {
+  const Expr *LastE = nullptr;

li.zhe.hua wrote:
> sgatev wrote:
> > xazax.hun wrote:
> > > li.zhe.hua wrote:
> > > > sgatev wrote:
> > > > > I don't recall why we need to ignore implicit casts here. Can't we 
> > > > > ignore parens and rely on the built-in transfer function, possibly 
> > > > > adding handling of some missing casts there? 
> > > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L192
> > > > If we only ignore parens, a test in the optional checker tests begins 
> > > > to fail, specifically `UncheckedOptionalAccessTest.ValueOrComparison`. 
> > > > The missing "cast" is an `ExprWithCleanups`. I didn't know how to deal 
> > > > with that, so this patch just working around the assert.
> > > In general, I prefer to handle as much as possible with transfer 
> > > functions and skip as little as possible in the AST. We might skip 
> > > `ExprWithCleanups` nodes today, but we will need them tomorrow to 
> > > properly model where certain destructors are being invoked. 
> > We already have `skipExprWithCleanups` [1]. I wonder if it makes sense to 
> > replace that with a simple transfer function like the one for the `CK_NoOp` 
> > implicit cast. Would that solve the problem and remove the need for 
> > `ignoreParenImpCastsExceptToBool`? In the future we might replace that 
> > transfer function with a proper one, as Gábor suggested.
> > 
> > [1] 
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L36
> I sat down with @ymandel to get a better understanding of what was happening 
> here, which was really helpful in understanding why my random flailing was 
> making tests pass, and what I believe to be a better way forward.
> 
> So, the CFG does not emit `ParenExpr` nodes. As such, the transfer function 
> never sees them, and so when we do any kind of manual traversal (e.g. to look 
> at a sub-expression), we use `ignoreParens()` because they effectively don't 
> exist. The same thing happens with `ExprWithCleanups`. The CFG doesn't appear 
> to emit them explicitly, and so we should similarly avoid them when manually 
> traversing the AST.
> 
> Note: Their position in the AST is slightly more constrained, likely as the 
> immediate children of `*Stmt` nodes. This means we don't need to sprinkle 
> these skips as widely as `ignoreParens()`.
> 
> In terms of why adding `VisitFullExpr` "fixed" the failing test: 
> `extendFlowCondition()` [[ 
> https://github.com/llvm/llvm-project/blob/ed1b32791dbb4c02cd761742a63cdf1e9d644ae6/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp#L108
>  | manually calls ]] `transfer` on the provided `Cond` expression, which is a 
> `ExprWithCleanups` if the caller uses `ignoreParens()` instead of 
> `ignoreParenImpCasts()`.
> 
> ---
> 
> @xazax.hun:
> 
> > In general, I prefer to handle as much as possible with transfer functions 
> > and skip as little as possible in the AST. We might skip `ExprWithCleanups` 
> > nodes today, but we will need them tomorrow to properly model where certain 
> > destructors are being invoked. 
> 
> The CFG already emits calls to destructors as a result of `ExprWithCleanups` 
> ([[ https://godbolt.org/z/fo846dcEa | godbolt ]]), so skipping them will not 
> cause us to miss calls to destructors.
> 
> ---
> 
> @sgatev:
> 
> > We already have `skipExprWithCleanups` [1]. I wonder if it makes sense to 
> > replace that with a simple transfer function like the one for the `CK_NoOp` 
> > implicit cast. Would that solve the problem and remove the need for 
> > `ignoreParenImpCastsExceptToBool`? In the future we might replace that 
> > transfer function with a proper one, as Gábor suggested.
> > 
> > [1] 
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L36
> 
> I believe that `ParenExpr` and `ExprWithCleanups` are categorically the same 
> within the framework (roughly, nodes that are not emitted by the CFG) and so 
> we should handle them in the same way. The strategy right now for `ParenExpr` 
> is to skip them, so I am inclined to do so as well with `ExprWithCleanups` 
> for now. (I'm not necessarily opposed to having `ParenExpr` and 
> `ExprWithCleanups` nodes being handled in the transfer function, but there's 
> a question of how to get them in there if the CFG isn't going to emit them.)
> 
> That would mean //more// usage of `skipExprWithCleanups`, and is reflected in 
> this most recent revision.
Thanks for the detailed explanation, this sounds good to me! Could you add a 
short summary as a comment to `ignoreExprWithCleanups`?


Repository:
  rG LLVM 

[PATCH] D124874: [clang] add -fmodule-file-home-is-cwd

2022-05-03 Thread Richard Howell via Phabricator via cfe-commits
rmaz created this revision.
Herald added a project: All.
rmaz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This diff adds a new frontend flag `-fmodule-file-home-is-cwd`.
The behavior of this flag is similar to
`-fmodule-map-file-home-is-cwd` but does not require the module
map files to be modified to have inputs relative to the cwd.
Instead the output modules will have their `BaseDirectory` set
to the cwd and will try and resolve paths relative to that.

The motiviation for this change is to support relocatable pcm
files that are built on different machines with different paths
without having to alter module map files, which is sometimes not
possible as they are provided by 3rd parties.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124874

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/HeaderSearchOptions.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/module-file-home-is-cwd.m


Index: clang/test/Modules/module-file-home-is-cwd.m
===
--- /dev/null
+++ clang/test/Modules/module-file-home-is-cwd.m
@@ -0,0 +1,8 @@
+// RUN: cd %S
+// RUN: %clang_cc1 -fmodules -fno-implicit-modules -fmodule-file-home-is-cwd 
-fmodule-name=libA -emit-module Inputs/normal-module-map/module.map -o 
%t/mod.pcm
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s
+
+// CHECK:  blob data = 'Inputs/normal-module-map/a1.h'
+// CHECK:  blob data = 'Inputs/normal-module-map/a2.h'
+// CHECK:  blob data = 
'Inputs/normal-module-map/module.map'
+// CHECK-NOT: MODULE_DIRECTORY
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1223,7 +1223,15 @@
 Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name);
   }
 
-  if (WritingModule && WritingModule->Directory) {
+  if (WritingModule &&
+  PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) {
+// Use the current working directory as the base path for all inputs.
+auto *CWD =
+Context.getSourceManager().getFileManager().getDirectory(".").get();
+SmallString<128> BaseDir(CWD->getName());
+cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir);
+BaseDirectory.assign(BaseDir.begin(), BaseDir.end());
+  } else if (WritingModule && WritingModule->Directory) {
 SmallString<128> BaseDir(WritingModule->Directory->getName());
 cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir);
 
Index: clang/include/clang/Lex/HeaderSearchOptions.h
===
--- clang/include/clang/Lex/HeaderSearchOptions.h
+++ clang/include/clang/Lex/HeaderSearchOptions.h
@@ -143,6 +143,12 @@
   /// file.
   unsigned ModuleMapFileHomeIsCwd : 1;
 
+  /// Set the base path of a built module file to be the current working
+  /// directory. This is useful for sharing module files across machines
+  /// that build with different paths without having to rewrite all
+  /// modulemap files to have working directory relative paths.
+  unsigned ModuleFileHomeIsCwd : 1;
+
   /// Also search for prebuilt implicit modules in the prebuilt module cache
   /// path.
   unsigned EnablePrebuiltImplicitModules : 1;
@@ -222,9 +228,9 @@
   HeaderSearchOptions(StringRef _Sysroot = "/")
   : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
 ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false),
-EnablePrebuiltImplicitModules(false), UseBuiltinIncludes(true),
-UseStandardSystemIncludes(true), UseStandardCXXIncludes(true),
-UseLibcxx(false), Verbose(false),
+ModuleFileHomeIsCwd(false), EnablePrebuiltImplicitModules(false),
+UseBuiltinIncludes(true), UseStandardSystemIncludes(true),
+UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false),
 ModulesValidateOncePerBuildSession(false),
 ModulesValidateSystemHeaders(false),
 ValidateASTInputFilesContent(false), UseDebugInfo(false),
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5609,6 +5609,10 @@
   HelpText<"Use the current working directory as the home directory of "
"module maps specified by -fmodule-map-file=">,
   MarshallingInfoFlag>;
+def fmodule_file_home_is_cwd : Flag<["-"], "fmodule-file-home-is-cwd">,
+  HelpText<"Use the current working directory as the base directory of "
+   "compiled module files.">,
+  MarshallingInfoFlag>;
 def fmodule_feature : Separate<["-"], "fmodule-feature">,
   MetaVarName<"">,
   HelpText<"Enable  in module map requires declarations">,


Index: 

[PATCH] D124807: [clang][dataflow] Avoid assert for invalid cast to BoolValue

2022-05-03 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua marked 4 inline comments as done.
li.zhe.hua added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:78
+/// and integers in the framework.
+static const Expr *ignoreParenImpCastsExceptToBool(const Expr *E) {
+  const Expr *LastE = nullptr;

sgatev wrote:
> xazax.hun wrote:
> > li.zhe.hua wrote:
> > > sgatev wrote:
> > > > I don't recall why we need to ignore implicit casts here. Can't we 
> > > > ignore parens and rely on the built-in transfer function, possibly 
> > > > adding handling of some missing casts there? 
> > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L192
> > > If we only ignore parens, a test in the optional checker tests begins to 
> > > fail, specifically `UncheckedOptionalAccessTest.ValueOrComparison`. The 
> > > missing "cast" is an `ExprWithCleanups`. I didn't know how to deal with 
> > > that, so this patch just working around the assert.
> > In general, I prefer to handle as much as possible with transfer functions 
> > and skip as little as possible in the AST. We might skip `ExprWithCleanups` 
> > nodes today, but we will need them tomorrow to properly model where certain 
> > destructors are being invoked. 
> We already have `skipExprWithCleanups` [1]. I wonder if it makes sense to 
> replace that with a simple transfer function like the one for the `CK_NoOp` 
> implicit cast. Would that solve the problem and remove the need for 
> `ignoreParenImpCastsExceptToBool`? In the future we might replace that 
> transfer function with a proper one, as Gábor suggested.
> 
> [1] 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L36
I sat down with @ymandel to get a better understanding of what was happening 
here, which was really helpful in understanding why my random flailing was 
making tests pass, and what I believe to be a better way forward.

So, the CFG does not emit `ParenExpr` nodes. As such, the transfer function 
never sees them, and so when we do any kind of manual traversal (e.g. to look 
at a sub-expression), we use `ignoreParens()` because they effectively don't 
exist. The same thing happens with `ExprWithCleanups`. The CFG doesn't appear 
to emit them explicitly, and so we should similarly avoid them when manually 
traversing the AST.

Note: Their position in the AST is slightly more constrained, likely as the 
immediate children of `*Stmt` nodes. This means we don't need to sprinkle these 
skips as widely as `ignoreParens()`.

In terms of why adding `VisitFullExpr` "fixed" the failing test: 
`extendFlowCondition()` [[ 
https://github.com/llvm/llvm-project/blob/ed1b32791dbb4c02cd761742a63cdf1e9d644ae6/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp#L108
 | manually calls ]] `transfer` on the provided `Cond` expression, which is a 
`ExprWithCleanups` if the caller uses `ignoreParens()` instead of 
`ignoreParenImpCasts()`.

---

@xazax.hun:

> In general, I prefer to handle as much as possible with transfer functions 
> and skip as little as possible in the AST. We might skip `ExprWithCleanups` 
> nodes today, but we will need them tomorrow to properly model where certain 
> destructors are being invoked. 

The CFG already emits calls to destructors as a result of `ExprWithCleanups` 
([[ https://godbolt.org/z/fo846dcEa | godbolt ]]), so skipping them will not 
cause us to miss calls to destructors.

---

@sgatev:

> We already have `skipExprWithCleanups` [1]. I wonder if it makes sense to 
> replace that with a simple transfer function like the one for the `CK_NoOp` 
> implicit cast. Would that solve the problem and remove the need for 
> `ignoreParenImpCastsExceptToBool`? In the future we might replace that 
> transfer function with a proper one, as Gábor suggested.
> 
> [1] 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L36

I believe that `ParenExpr` and `ExprWithCleanups` are categorically the same 
within the framework (roughly, nodes that are not emitted by the CFG) and so we 
should handle them in the same way. The strategy right now for `ParenExpr` is 
to skip them, so I am inclined to do so as well with `ExprWithCleanups` for 
now. (I'm not necessarily opposed to having `ParenExpr` and `ExprWithCleanups` 
nodes being handled in the transfer function, but there's a question of how to 
get them in there if the CFG isn't going to emit them.)

That would mean //more// usage of `skipExprWithCleanups`, and is reflected in 
this most recent revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124807

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


[PATCH] D124807: [clang][dataflow] Avoid assert for invalid cast to BoolValue

2022-05-03 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua updated this revision to Diff 426823.
li.zhe.hua added a comment.

Switch from implementing in the trasfer function to skipping `ExprWithCleanups`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124807

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Transfer.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -1152,4 +1152,39 @@
   });
 }
 
+// FIXME: Remove this test once it provides no additional test coverage.
+TEST_F(FlowConditionTest, DoesNotAssertForImplicitCastToBool) {
+  std::string Code = R"(
+void target(int *Ptr) {
+  bool Foo = false;
+  if (Ptr) {
+Foo = true;
+/*[[p1]]*/
+  }
+
+  (void)0;
+  /*[[p2]]*/
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p2", _), Pair("p1", _)));
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const Environment  = Results[1].second.Env;
+auto  =
+*cast(Env1.getValue(*FooDecl, SkipPast::Reference));
+EXPECT_TRUE(Env1.flowConditionImplies(FooVal1));
+
+const Environment  = Results[0].second.Env;
+auto  =
+*cast(Env2.getValue(*FooDecl, SkipPast::Reference));
+EXPECT_FALSE(Env2.flowConditionImplies(FooVal2));
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -77,26 +77,26 @@
   : StmtToEnv(StmtToEnv), Env(Env), BlockSuccIdx(BlockSuccIdx) {}
 
   void VisitIfStmt(const IfStmt *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = ignoreExprWithCleanups(S->getCond())->IgnoreParens();
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
 
   void VisitWhileStmt(const WhileStmt *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = ignoreExprWithCleanups(S->getCond())->IgnoreParens();
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
 
   void VisitBinaryOperator(const BinaryOperator *S) {
 assert(S->getOpcode() == BO_LAnd || S->getOpcode() == BO_LOr);
-auto *LHS = S->getLHS()->IgnoreParenImpCasts();
+auto *LHS = ignoreExprWithCleanups(S->getLHS())->IgnoreParens();
 assert(LHS != nullptr);
 extendFlowCondition(*LHS);
   }
 
   void VisitConditionalOperator(const ConditionalOperator *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = ignoreExprWithCleanups(S->getCond())->IgnoreParens();
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -33,7 +33,7 @@
 namespace clang {
 namespace dataflow {
 
-static const Expr *skipExprWithCleanups(const Expr *E) {
+const Expr *ignoreExprWithCleanups(const Expr *E) {
   if (auto *C = dyn_cast_or_null(E))
 return C->getSubExpr();
   return E;
@@ -157,7 +157,7 @@
 
 // The CFG does not contain `ParenExpr` as top-level statements in basic
 // blocks, however sub-expressions can still be of that type.
-InitExpr = skipExprWithCleanups(D.getInit()->IgnoreParens());
+InitExpr = ignoreExprWithCleanups(D.getInit()->IgnoreParens());
 assert(InitExpr != nullptr);
 
 if (D.getType()->isReferenceType()) {
@@ -605,6 +605,7 @@
 
 void transfer(const StmtToEnvMap , const Stmt , Environment ) {
   assert(!isa());
+  assert(!isa());
   TransferVisitor(StmtToEnv, Env).Visit();
 }
 
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -220,8 +220,8 @@
 
 void transferUnwrapCall(const Expr 

[PATCH] D123243: [pseudo] Strip directives from a token stream

2022-05-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

would be nice to land it in some of form.




Comment at: clang-tools-extra/pseudo/unittests/DirectiveTreeTest.cpp:316
+  std::string Code = R"cpp(
+a a a
+#warning AAA

nit: cover `#include` as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123243

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


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-05-03 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D121370#3489245 , @krasimir wrote:

> In D121370#3488401 , @kwk wrote:
>
>> @krasimir could you please test this patch on your side?
>
> @kwk thank you! the new version of the patch looks good!
>
> I didn't know before about the issue you found with the `/* a comment before 
> */ #include ` (and since it's preexisting, if it's tricky to address, it 
> would be reasonable to just file a bug for it and omit fixing it by this 
> work, I think).

+1.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

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


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-05-03 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

>   Now support @ and #.Clearly support "" and <> as ell as an

`as well as`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

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


[PATCH] D124221: Reimplement `__builtin_dump_struct` in Sema.

2022-05-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:433
+
+  llvm::StringRef getFormatSpecifier(QualType T) {
+if (auto *BT = T->getAs()) {

rsmith wrote:
> aaron.ballman wrote:
> > yihanaa wrote:
> > > I think this is better maintained in "clang/AST/FormatString.h". For 
> > > example analyze_printf::PrintfSpecifier can get format specifier, what do 
> > > you all think about?
> > +1 to this suggestion -- my hope is that we could generalize it more then 
> > as I notice there are missing specifiers for things like intmax_t, size_t, 
> > ptrdiff_t, _Decimal types, etc. Plus, that will hopefully make it easier 
> > for __builtin_dump_struct to benefit when new format specifiers are added, 
> > such as ones for printing a _BitInt.
> I am somewhat uncertain: every one of these is making arbitrary choices about 
> how to format the value, so it's not clear to me that this is general logic 
> rather than something specific to `__builtin_dump_struct`. For example, using 
> `%f` rather than one of the myriad other ways of formatting `double` is 
> somewhat arbitrary. Using `%s` for any `const char*` is *extremely* arbitrary 
> and will be wrong and will cause crashes in some cases, but it may be the 
> pragmatically correct choice for a dumping utility. A general-purpose 
> mechanism would use `%p` for all kinds of pointer.
> 
> We could perhaps factor out the formatting for cases where there is a clear 
> canonical default formatting, such as for integer types and probably `%p` for 
> pointers, then call that from here with some special-casing, but without a 
> second consumer for that functionality it's really not clear to me what form 
> it should take.
I went ahead and did this, mostly to match concurrent changes to the old 
implementation. There are a few cases where our existing "guess a format 
specifier" logic does the wrong thing for dumping purposes, which I've 
explicitly handled -- things like wanting to dump a `char` / `signed char` / 
`unsigned char` member as a number rather than as a (potentially non-printable 
or whitespace) character.



Comment at: clang/lib/Sema/SemaChecking.cpp:573
+  // We don't know how to print this field. Print out its address
+  // with a format specifier that a smart tool will be able to
+  // recognize and treat specially.

aaron.ballman wrote:
> rsmith wrote:
> > yihanaa wrote:
> > > Can we generate a warning diagnostic message when we see an unsupported 
> > > type (perhaps temporarily not supported), what do you all think about?
> > We could, but I'm leaning towards thinking that we shouldn't warn by 
> > default at least. That would get in the way of the C++ use case where the 
> > type actually is supported by the printing function; I'm not sure that we 
> > can easily tell those cases apart. And it's probably not all that useful to 
> > someone who just wants whatever information we can give them while 
> > debugging. I'd be OK with adding a warning that's off by default, though. 
> > What would be the intended use case here? Would an off-by-default warning 
> > satisfy it?
> So long as we don't trigger UB, I think it's fine to not diagnose for 
> unsupported types. But the UB cases do strike me as something we might want 
> to warn about if we think they can be hit (specifically, these kinds of UB: 
> https://eel.is/c++draft/cstdarg.syn#1).
> 
> As an example, do we properly handle dumping this case:
> ```
> struct S {
>   int 
>   S(int ) : i(ref) {}
> };
> ```
> where the vararg argument is of reference type? I suppose another interesting 
> question is:
> ```
> struct S {
>   int i;
> };
> 
> void func() {
>   S s;
>   [=]() {
> __builtin_dump_struct(, ::printf);
>   };
> }
> ```
> (is S.i "an entity resulting from a lambda capture"?)
The only things we pass to the formatting function are:
* The small number of builtin types for which we have known formatting 
specifiers.
* Pointers to `void`, using `%p`.
* Pointers to `[const] char`, using `%s`.
* Pointers to user-defined types, using `*%p`.
All of these can be passed through a `...` without problems.

We can potentially introduce the following sources of UB:
* Indirection through a struct pointer that doesn't point to a struct object.
* Read of an inactive union member.
* Read of an uninitialized member.
* Printing something other than a pointer to a nul-terminated byte sequence 
with `%s`.
I'm not sure how much we should be worrying about those. It'd be nice to avoid 
them, though I don't think we can fix the fourth issue without giving up the 
`%s` formatting entirely.

Reference types aren't on our list of types with known formatting specifiers, 
so in your first example we'd call `printf("%s%s = *%p", "int &", "i", >i)`, 
producing output like `int & i = *0x1234abcd`. We could special-case that to 
also dereference the reference and include the value (`int & i = *0x1234abcd 
(5)`, 

[PATCH] D124642: [WIP] Add support for return from an SEH __finally block.

2022-05-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma updated this revision to Diff 426814.
efriedma edited the summary of this revision.
efriedma added a comment.

Switch to use llvm.seh_localunwind intrinsic.

I'd appreciate any feedback at this point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124642

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/CodeGen/AsmPrinter/WinException.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/WinEHPrepare.cpp
  llvm/lib/IR/Verifier.cpp

Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -4612,6 +4612,7 @@
 F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 ||
 F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ||
 F->getIntrinsicID() == Intrinsic::wasm_rethrow ||
+F->getIntrinsicID() == Intrinsic::seh_localunwind ||
 IsAttachedCallOperand(F, CBI, i),
 "Cannot invoke an intrinsic other than donothing, patchpoint, "
 "statepoint, coro_resume, coro_destroy or clang.arc.attachedcall",
Index: llvm/lib/CodeGen/WinEHPrepare.cpp
===
--- llvm/lib/CodeGen/WinEHPrepare.cpp
+++ llvm/lib/CodeGen/WinEHPrepare.cpp
@@ -380,6 +380,20 @@
 const Function *Filter = dyn_cast(FilterOrNull);
 assert((Filter || FilterOrNull->isNullValue()) &&
"unexpected filter value");
+// Filters named __IsLocalUnwind are treated specially: we want to catch
+// unwinds from _local_unwind, but not catchrets in the same funclet.
+// (They both need to point at the same catchswitch to pass the verifier
+// checks for nesting.) To make this work, we mess with the state
+// numbering: the "parent" of any cleanupret pointing to this catchpad is
+// actually this catchpad's parent.
+//
+// Note that _local_unwind looks for unwind table entries for the
+// catchpad; if there aren't any, it assumes the catchpad doesn't have a
+// parent.
+bool IsLocalUnwind =
+Filter && Filter->getName().startswith("__IsLocalUnwind");
+if (IsLocalUnwind)
+  Filter = nullptr;
 int TryState = addSEHExcept(FuncInfo, ParentState, Filter, CatchPadBB);
 
 // Everything in the __try block uses TryState as its parent state.
@@ -390,7 +404,7 @@
   if ((PredBlock = getEHPadFromPredecessor(PredBlock,
CatchSwitch->getParentPad(
 calculateSEHStateNumbers(FuncInfo, PredBlock->getFirstNonPHI(),
- TryState);
+ IsLocalUnwind ? ParentState : TryState);
 
 // Everything in the __except block unwinds to ParentState, just like code
 // outside the __try.
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -2937,6 +2937,41 @@
   DAG.setRoot(DAG.getNode(ISD::INTRINSIC_VOID, getCurSDLoc(), VTs, Ops));
   break;
 }
+case Intrinsic::seh_localunwind: {
+  if (!isa(EHPadBB->getTerminator())) {
+report_fatal_error("localunwind doesn't point to catchswitch");
+  }
+  auto *CatchSwitch = cast(EHPadBB->getTerminator());
+  if (CatchSwitch->getNumHandlers() == 0) {
+report_fatal_error("catchswitch with no handler");
+  }
+
+  const TargetLowering  = DAG.getTargetLoweringInfo();
+  TargetLowering::ArgListEntry SP, DestBB;
+  Type *PtrTy = PointerType::getInt8PtrTy(*DAG.getContext());
+  EVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
+  SP.Node = DAG.getNode(ISD::FRAMEADDR, getCurSDLoc(), PtrVT,
+DAG.getIntPtrConstant(0, getCurSDLoc()));
+  SP.Ty = PtrTy;
+  FuncInfo.MBBMap[*CatchSwitch->handler_begin()]->setHasAddressTaken();
+  DestBB.Node =
+  DAG.getBlockAddress(BlockAddress::get(const_cast(
+  *CatchSwitch->handler_begin())),
+  PtrVT);
+  DestBB.Ty = PtrTy;
+  TargetLowering::ArgListTy Args{SP, DestBB};
+
+  SDValue Callee = DAG.getExternalSymbol("_local_unwind", PtrVT);
+  TargetLowering::CallLoweringInfo CLI(DAG);
+  CLI.setDebugLoc(getCurSDLoc())
+  .setChain(getRoot())
+  .setCallee(CallingConv::C, Type::getVoidTy(*DAG.getContext()), Callee,
+ std::move(Args))
+  .setNoReturn();
+  CLI.CB = 
+  lowerInvokable(CLI, EHPadBB);
+  break;
+}
 }
   } else if 

[PATCH] D124831: [pseudo] Use a real language option in the parser.

2022-05-03 Thread Haojian Wu 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 rGc4546091ed29: [pseudo] Use a real language option in the 
parser. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124831

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Token.h
  clang-tools-extra/pseudo/lib/Token.cpp
  clang-tools-extra/pseudo/test/glr.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp


Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -53,8 +53,7 @@
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
 
-  clang::LangOptions LangOpts; // FIXME: use real options.
-  LangOpts.CPlusPlus = 1;
+  clang::LangOptions LangOpts = clang::pseudo::genericLangOpts();
   std::string SourceText;
   llvm::Optional RawStream;
   llvm::Optional DirectiveStructure;
Index: clang-tools-extra/pseudo/test/glr.cpp
===
--- clang-tools-extra/pseudo/test/glr.cpp
+++ clang-tools-extra/pseudo/test/glr.cpp
@@ -21,3 +21,15 @@
 // CHECK-NEXT:   │ └─ptr-declarator~IDENTIFIER := tok[7]
 // CHECK-NEXT:   └─; := tok[8]
 }
+
+bool operator<();
+// CHECK:  declaration~simple-declaration := decl-specifier-seq 
init-declarator-list ;
+// CHECK-NEXT: ├─decl-specifier-seq~BOOL
+// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator 
parameters-and-qualifiers
+// CHECK-NEXT: │ ├─noptr-declarator~operator-function-id := OPERATOR 
operator-name
+// CHECK-NEXT: │ │ ├─OPERATOR
+// CHECK-NEXT: │ │ └─operator-name~<
+// CHECK-NEXT: │ └─parameters-and-qualifiers := ( )
+// CHECK-NEXT: │   ├─(
+// CHECK-NEXT: │   └─)
+// CHECK-NEXT: └─;
Index: clang-tools-extra/pseudo/lib/Token.cpp
===
--- clang-tools-extra/pseudo/lib/Token.cpp
+++ clang-tools-extra/pseudo/lib/Token.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang-pseudo/Token.h"
+#include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -92,6 +93,28 @@
 OS << '\n';
 }
 
+clang::LangOptions genericLangOpts(clang::Language Lang,
+   clang::LangStandard::Kind Standard) {
+  clang::LangOptions Opts;
+  std::vector UnusedIncludes;
+  LangOptions::setLangDefaults(Opts, Lang, llvm::Triple(), UnusedIncludes,
+   Standard);
+
+  // Some options are "on by default", but e.g. at the driver level.
+  if (Opts.CPlusPlus)
+Opts.CXXOperatorNames = true;
+  if (Opts.CPlusPlus20)
+Opts.Coroutines = true;
+
+  // Some options are off by default, but define keywords we want to tolerate.
+  if (Opts.CPlusPlus)
+Opts.MicrosoftExt = true;  // kw__try, kw__finally
+  Opts.DeclSpecKeyword = true; // __declspec
+  Opts.WChar = true;
+
+  return Opts;
+}
+
 TokenStream stripComments(const TokenStream ) {
   TokenStream Out;
   for (const Token  : Input.tokens()) {
Index: clang-tools-extra/pseudo/include/clang-pseudo/Token.h
===
--- clang-tools-extra/pseudo/include/clang-pseudo/Token.h
+++ clang-tools-extra/pseudo/include/clang-pseudo/Token.h
@@ -29,6 +29,7 @@
 #define CLANG_PSEUDO_TOKEN_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/raw_ostream.h"
@@ -193,6 +194,10 @@
   /// The text() of such tokens will contain the raw trigrah.
   NeedsCleaning = 1 << 1,
 };
+/// A generic lang options suitable for lexing/parsing a langage.
+clang::LangOptions genericLangOpts(
+clang::Language = clang::Language::CXX,
+clang::LangStandard::Kind = clang::LangStandard::lang_unspecified);
 
 /// Derives a token stream by decoding escapes, interpreting raw_identifiers 
and
 /// splitting the greatergreater token.


Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -53,8 +53,7 @@
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
 
-  clang::LangOptions LangOpts; // FIXME: use real options.
-  LangOpts.CPlusPlus = 1;
+  clang::LangOptions LangOpts = clang::pseudo::genericLangOpts();
   std::string SourceText;
   llvm::Optional RawStream;
   llvm::Optional DirectiveStructure;
Index: clang-tools-extra/pseudo/test/glr.cpp

[clang-tools-extra] c454609 - [pseudo] Use a real language option in the parser.

2022-05-03 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-05-03T22:24:56+02:00
New Revision: c4546091ed29763df3e4649327679fec5dcb5ff6

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

LOG: [pseudo] Use a real language option in the parser.

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

Added: 


Modified: 
clang-tools-extra/pseudo/include/clang-pseudo/Token.h
clang-tools-extra/pseudo/lib/Token.cpp
clang-tools-extra/pseudo/test/glr.cpp
clang-tools-extra/pseudo/tool/ClangPseudo.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/Token.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/Token.h
index 2bbd598736e6d..31ef5eca26a2b 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/Token.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/Token.h
@@ -29,6 +29,7 @@
 #define CLANG_PSEUDO_TOKEN_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/raw_ostream.h"
@@ -193,6 +194,10 @@ enum class LexFlags : uint8_t {
   /// The text() of such tokens will contain the raw trigrah.
   NeedsCleaning = 1 << 1,
 };
+/// A generic lang options suitable for lexing/parsing a langage.
+clang::LangOptions genericLangOpts(
+clang::Language = clang::Language::CXX,
+clang::LangStandard::Kind = clang::LangStandard::lang_unspecified);
 
 /// Derives a token stream by decoding escapes, interpreting raw_identifiers 
and
 /// splitting the greatergreater token.

diff  --git a/clang-tools-extra/pseudo/lib/Token.cpp 
b/clang-tools-extra/pseudo/lib/Token.cpp
index f07c1d1b272df..b58c8e4a862e2 100644
--- a/clang-tools-extra/pseudo/lib/Token.cpp
+++ b/clang-tools-extra/pseudo/lib/Token.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang-pseudo/Token.h"
+#include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -92,6 +93,28 @@ void TokenStream::print(llvm::raw_ostream ) const {
 OS << '\n';
 }
 
+clang::LangOptions genericLangOpts(clang::Language Lang,
+   clang::LangStandard::Kind Standard) {
+  clang::LangOptions Opts;
+  std::vector UnusedIncludes;
+  LangOptions::setLangDefaults(Opts, Lang, llvm::Triple(), UnusedIncludes,
+   Standard);
+
+  // Some options are "on by default", but e.g. at the driver level.
+  if (Opts.CPlusPlus)
+Opts.CXXOperatorNames = true;
+  if (Opts.CPlusPlus20)
+Opts.Coroutines = true;
+
+  // Some options are off by default, but define keywords we want to tolerate.
+  if (Opts.CPlusPlus)
+Opts.MicrosoftExt = true;  // kw__try, kw__finally
+  Opts.DeclSpecKeyword = true; // __declspec
+  Opts.WChar = true;
+
+  return Opts;
+}
+
 TokenStream stripComments(const TokenStream ) {
   TokenStream Out;
   for (const Token  : Input.tokens()) {

diff  --git a/clang-tools-extra/pseudo/test/glr.cpp 
b/clang-tools-extra/pseudo/test/glr.cpp
index 8817462d7d83e..8f58f6f894e59 100644
--- a/clang-tools-extra/pseudo/test/glr.cpp
+++ b/clang-tools-extra/pseudo/test/glr.cpp
@@ -21,3 +21,15 @@ void foo() {
 // CHECK-NEXT:   │ └─ptr-declarator~IDENTIFIER := tok[7]
 // CHECK-NEXT:   └─; := tok[8]
 }
+
+bool operator<();
+// CHECK:  declaration~simple-declaration := decl-specifier-seq 
init-declarator-list ;
+// CHECK-NEXT: ├─decl-specifier-seq~BOOL
+// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator 
parameters-and-qualifiers
+// CHECK-NEXT: │ ├─noptr-declarator~operator-function-id := OPERATOR 
operator-name
+// CHECK-NEXT: │ │ ├─OPERATOR
+// CHECK-NEXT: │ │ └─operator-name~<
+// CHECK-NEXT: │ └─parameters-and-qualifiers := ( )
+// CHECK-NEXT: │   ├─(
+// CHECK-NEXT: │   └─)
+// CHECK-NEXT: └─;

diff  --git a/clang-tools-extra/pseudo/tool/ClangPseudo.cpp 
b/clang-tools-extra/pseudo/tool/ClangPseudo.cpp
index 71ff5b0a637a2..e55b7006c7e4f 100644
--- a/clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ b/clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -53,8 +53,7 @@ static std::string readOrDie(llvm::StringRef Path) {
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
 
-  clang::LangOptions LangOpts; // FIXME: use real options.
-  LangOpts.CPlusPlus = 1;
+  clang::LangOptions LangOpts = clang::pseudo::genericLangOpts();
   std::string SourceText;
   llvm::Optional RawStream;
   llvm::Optional DirectiveStructure;



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


[PATCH] D124676: [clang][OpenMP] Local variable alignment incorrect with align clause

2022-05-03 Thread Mike Rice via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG37471cf2c3fd: [clang][OpenMP] Local variable alignment 
incorrect with align clause (authored by ddpagan, committed by mikerice).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124676

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/align_clause_codegen.cpp

Index: clang/test/OpenMP/align_clause_codegen.cpp
===
--- clang/test/OpenMP/align_clause_codegen.cpp
+++ clang/test/OpenMP/align_clause_codegen.cpp
@@ -85,9 +85,9 @@
 // CHECK-32-NEXT:  entry:
 // CHECK-32-NEXT:[[MYALLOC:%.*]] = alloca i32, align 4
 // CHECK-32-NEXT:[[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
-// CHECK-32-NEXT:[[DOTFOO0__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 1, i32 20, i8* null)
+// CHECK-32-NEXT:[[DOTFOO0__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 20, i8* null)
 // CHECK-32-NEXT:[[DOTFOO0__ADDR:%.*]] = bitcast i8* [[DOTFOO0__VOID_ADDR]] to [5 x i32]*
-// CHECK-32-NEXT:[[DOTFOO1__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 2, i32 40, i8* inttoptr (i32 7 to i8*))
+// CHECK-32-NEXT:[[DOTFOO1__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 40, i8* inttoptr (i32 7 to i8*))
 // CHECK-32-NEXT:[[DOTFOO1__ADDR:%.*]] = bitcast i8* [[DOTFOO1__VOID_ADDR]] to [10 x i32]*
 // CHECK-32-NEXT:[[DOTFOO2__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 80, i8* inttoptr (i32 6 to i8*))
 // CHECK-32-NEXT:[[DOTFOO2__ADDR:%.*]] = bitcast i8* [[DOTFOO2__VOID_ADDR]] to [20 x i32]*
@@ -114,15 +114,15 @@
 // CHECK-32-NEXT:call void @__kmpc_free(i32 [[TMP0]], i8* [[TMP2]], i8* inttoptr (i32 8 to i8*))
 // CHECK-32-NEXT:[[TMP3:%.*]] = load i32, i32* [[MYALLOC]], align 4
 // CHECK-32-NEXT:[[CONV:%.*]] = inttoptr i32 [[TMP3]] to i8*
-// CHECK-32-NEXT:[[DOTBAR1__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 2, i32 4, i8* [[CONV]])
+// CHECK-32-NEXT:[[DOTBAR1__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 4, i8* [[CONV]])
 // CHECK-32-NEXT:[[DOTBAR1__ADDR:%.*]] = bitcast i8* [[DOTBAR1__VOID_ADDR]] to i32*
 // CHECK-32-NEXT:[[TMP4:%.*]] = load i32, i32* [[MYALLOC]], align 4
 // CHECK-32-NEXT:[[CONV1:%.*]] = inttoptr i32 [[TMP4]] to i8*
-// CHECK-32-NEXT:[[DOTBAR2__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 2, i32 40, i8* [[CONV1]])
+// CHECK-32-NEXT:[[DOTBAR2__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 40, i8* [[CONV1]])
 // CHECK-32-NEXT:[[DOTBAR2__ADDR:%.*]] = bitcast i8* [[DOTBAR2__VOID_ADDR]] to [10 x i32]*
 // CHECK-32-NEXT:[[TMP5:%.*]] = load i32, i32* [[MYALLOC]], align 4
 // CHECK-32-NEXT:[[CONV2:%.*]] = inttoptr i32 [[TMP5]] to i8*
-// CHECK-32-NEXT:[[DOTBAR3__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 2, i32 80, i8* [[CONV2]])
+// CHECK-32-NEXT:[[DOTBAR3__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 80, i8* [[CONV2]])
 // CHECK-32-NEXT:[[DOTBAR3__ADDR:%.*]] = bitcast i8* [[DOTBAR3__VOID_ADDR]] to [20 x i32]*
 // CHECK-32-NEXT:[[DOTBAR4__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i32 16, i32 4, i8* null)
 // CHECK-32-NEXT:[[DOTBAR4__ADDR:%.*]] = bitcast i8* [[DOTBAR4__VOID_ADDR]] to i32**
@@ -196,9 +196,9 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[MYALLOC:%.*]] = alloca i64, align 8
 // CHECK-NEXT:[[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
-// CHECK-NEXT:[[DOTFOO0__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i64 1, i64 32, i8* null)
+// CHECK-NEXT:[[DOTFOO0__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i64 4, i64 32, i8* null)
 // CHECK-NEXT:[[DOTFOO0__ADDR:%.*]] = bitcast i8* [[DOTFOO0__VOID_ADDR]] to [5 x i32]*
-// CHECK-NEXT:[[DOTFOO1__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i64 2, i64 48, i8* inttoptr (i64 7 to i8*))
+// CHECK-NEXT:[[DOTFOO1__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i64 4, i64 48, i8* inttoptr (i64 7 to i8*))
 // CHECK-NEXT:[[DOTFOO1__ADDR:%.*]] = bitcast i8* [[DOTFOO1__VOID_ADDR]] to [10 x i32]*
 // CHECK-NEXT:[[DOTFOO2__VOID_ADDR:%.*]] = call i8* @__kmpc_aligned_alloc(i32 [[TMP0]], i64 4, i64 80, i8* inttoptr (i64 6 to i8*))
 // CHECK-NEXT:[[DOTFOO2__ADDR:%.*]] = bitcast i8* [[DOTFOO2__VOID_ADDR]] to [20 x i32]*
@@ -225,15 +225,15 @@
 // CHECK-NEXT:call void @__kmpc_free(i32 [[TMP0]], i8* [[TMP2]], i8* inttoptr (i64 8 to i8*))
 // CHECK-NEXT:[[TMP3:%.*]] = load i64, i64* 

[clang] 37471cf - [clang][OpenMP] Local variable alignment incorrect with align clause

2022-05-03 Thread Mike Rice via cfe-commits

Author: David Pagan
Date: 2022-05-03T13:10:01-07:00
New Revision: 37471cf2c3fd02fac0b0dc6e513cfe6098f37764

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

LOG: [clang][OpenMP] Local variable alignment incorrect with align clause

If alignment specified with align clause is less than natural alignment for
list item type, the alignment should be set to the natural alignment.

See OMP5.1 specification, page 185, lines 7-10

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/align_clause_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 391245e3b54bb..aa8aa7d0bd5f8 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -12153,6 +12153,27 @@ static llvm::Value *getAllocatorVal(CodeGenFunction 
,
   return AllocVal;
 }
 
+/// Given the allocate directive list item type and align clause value,
+/// return appropriate alignment.
+static llvm::Value *getAlignmentValue(CodeGenFunction , QualType 
ListItemTy,
+  const Expr *Alignment) {
+  if (!Alignment)
+return nullptr;
+
+  unsigned UserAlign =
+  Alignment->EvaluateKnownConstInt(CGF.getContext()).getExtValue();
+  CharUnits NaturalAlign = CGF.CGM.getNaturalTypeAlignment(ListItemTy);
+
+  // OpenMP5.1 pg 185 lines 7-10
+  //   Each item in the align modifier list must be aligned to the maximum
+  //   of the specified alignment and the type's natural alignment.
+  //
+  // If no alignment specified then use the natural alignment.
+  return llvm::ConstantInt::get(
+  CGF.CGM.SizeTy,
+  std::max(UserAlign, NaturalAlign.getQuantity()));
+}
+
 Address CGOpenMPRuntime::getAddressOfLocalVariable(CodeGenFunction ,
const VarDecl *VD) {
   if (!VD)
@@ -12191,11 +12212,8 @@ Address 
CGOpenMPRuntime::getAddressOfLocalVariable(CodeGenFunction ,
 const auto *AA = CVD->getAttr();
 const Expr *Allocator = AA->getAllocator();
 llvm::Value *AllocVal = getAllocatorVal(CGF, Allocator);
-llvm::Value *Alignment =
-AA->getAlignment()
-? CGF.Builder.CreateIntCast(CGF.EmitScalarExpr(AA->getAlignment()),
-CGM.SizeTy, /*isSigned=*/false)
-: nullptr;
+llvm::Value *Alignment = getAlignmentValue(
+CGF, VD->getType().getNonReferenceType(), AA->getAlignment());
 SmallVector Args;
 Args.push_back(ThreadID);
 if (Alignment)

diff  --git a/clang/test/OpenMP/align_clause_codegen.cpp 
b/clang/test/OpenMP/align_clause_codegen.cpp
index 5ced4652aba10..b8c31d1ca9b66 100644
--- a/clang/test/OpenMP/align_clause_codegen.cpp
+++ b/clang/test/OpenMP/align_clause_codegen.cpp
@@ -85,9 +85,9 @@ int template_test() {
 // CHECK-32-NEXT:  entry:
 // CHECK-32-NEXT:[[MYALLOC:%.*]] = alloca i32, align 4
 // CHECK-32-NEXT:[[TMP0:%.*]] = call i32 
@__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
-// CHECK-32-NEXT:[[DOTFOO0__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 1, i32 20, i8* null)
+// CHECK-32-NEXT:[[DOTFOO0__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 20, i8* null)
 // CHECK-32-NEXT:[[DOTFOO0__ADDR:%.*]] = bitcast i8* 
[[DOTFOO0__VOID_ADDR]] to [5 x i32]*
-// CHECK-32-NEXT:[[DOTFOO1__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 2, i32 40, i8* inttoptr (i32 7 to i8*))
+// CHECK-32-NEXT:[[DOTFOO1__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 40, i8* inttoptr (i32 7 to i8*))
 // CHECK-32-NEXT:[[DOTFOO1__ADDR:%.*]] = bitcast i8* 
[[DOTFOO1__VOID_ADDR]] to [10 x i32]*
 // CHECK-32-NEXT:[[DOTFOO2__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 80, i8* inttoptr (i32 6 to i8*))
 // CHECK-32-NEXT:[[DOTFOO2__ADDR:%.*]] = bitcast i8* 
[[DOTFOO2__VOID_ADDR]] to [20 x i32]*
@@ -114,15 +114,15 @@ int template_test() {
 // CHECK-32-NEXT:call void @__kmpc_free(i32 [[TMP0]], i8* [[TMP2]], i8* 
inttoptr (i32 8 to i8*))
 // CHECK-32-NEXT:[[TMP3:%.*]] = load i32, i32* [[MYALLOC]], align 4
 // CHECK-32-NEXT:[[CONV:%.*]] = inttoptr i32 [[TMP3]] to i8*
-// CHECK-32-NEXT:[[DOTBAR1__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 2, i32 4, i8* [[CONV]])
+// CHECK-32-NEXT:[[DOTBAR1__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 4, i8* [[CONV]])
 // CHECK-32-NEXT:[[DOTBAR1__ADDR:%.*]] = bitcast i8* 
[[DOTBAR1__VOID_ADDR]] to i32*
 // CHECK-32-NEXT:[[TMP4:%.*]] = load i32, i32* [[MYALLOC]], align 4
 // CHECK-32-NEXT:

[PATCH] D124836: [AArch64] Add support for -fzero-call-used-regs

2022-05-03 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:776-778
+  // For GPRs, we only care to clear out the 64-bit register.
+  if (MCRegister XReg = getRegisterOrZero(Reg))
+GPRsToZero.set(XReg);

nickdesaulniers wrote:
> so for 32b registers, we clear the whole 64b register?
Perhaps a more descriptive method name like `getWidestRegisterAlias` or the 
like? Perhaps we should simply assert if we get a non GPR rather than return 0, 
which might actually be a Register?

Also, TargetRegisterClass has some notion of sub and super register classes. I 
wonder if have existing machinery to say, given a register class, what's the 
equivalent/aliases super register class (if that's even what a super register 
is).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124836

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


[PATCH] D124831: [pseudo] Use a real language option in the parser.

2022-05-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 426811.
hokein added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124831

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Token.h
  clang-tools-extra/pseudo/lib/Token.cpp
  clang-tools-extra/pseudo/test/glr.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp


Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -53,8 +53,7 @@
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
 
-  clang::LangOptions LangOpts; // FIXME: use real options.
-  LangOpts.CPlusPlus = 1;
+  clang::LangOptions LangOpts = clang::pseudo::genericLangOpts();
   std::string SourceText;
   llvm::Optional RawStream;
   llvm::Optional DirectiveStructure;
Index: clang-tools-extra/pseudo/test/glr.cpp
===
--- clang-tools-extra/pseudo/test/glr.cpp
+++ clang-tools-extra/pseudo/test/glr.cpp
@@ -21,3 +21,15 @@
 // CHECK-NEXT:   │ └─ptr-declarator~IDENTIFIER := tok[7]
 // CHECK-NEXT:   └─; := tok[8]
 }
+
+bool operator<();
+// CHECK:  declaration~simple-declaration := decl-specifier-seq 
init-declarator-list ;
+// CHECK-NEXT: ├─decl-specifier-seq~BOOL
+// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator 
parameters-and-qualifiers
+// CHECK-NEXT: │ ├─noptr-declarator~operator-function-id := OPERATOR 
operator-name
+// CHECK-NEXT: │ │ ├─OPERATOR
+// CHECK-NEXT: │ │ └─operator-name~<
+// CHECK-NEXT: │ └─parameters-and-qualifiers := ( )
+// CHECK-NEXT: │   ├─(
+// CHECK-NEXT: │   └─)
+// CHECK-NEXT: └─;
Index: clang-tools-extra/pseudo/lib/Token.cpp
===
--- clang-tools-extra/pseudo/lib/Token.cpp
+++ clang-tools-extra/pseudo/lib/Token.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang-pseudo/Token.h"
+#include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -92,6 +93,28 @@
 OS << '\n';
 }
 
+clang::LangOptions genericLangOpts(clang::Language Lang,
+   clang::LangStandard::Kind Standard) {
+  clang::LangOptions Opts;
+  std::vector UnusedIncludes;
+  LangOptions::setLangDefaults(Opts, Lang, llvm::Triple(), UnusedIncludes,
+   Standard);
+
+  // Some options are "on by default", but e.g. at the driver level.
+  if (Opts.CPlusPlus)
+Opts.CXXOperatorNames = true;
+  if (Opts.CPlusPlus20)
+Opts.Coroutines = true;
+
+  // Some options are off by default, but define keywords we want to tolerate.
+  if (Opts.CPlusPlus)
+Opts.MicrosoftExt = true;  // kw__try, kw__finally
+  Opts.DeclSpecKeyword = true; // __declspec
+  Opts.WChar = true;
+
+  return Opts;
+}
+
 TokenStream stripComments(const TokenStream ) {
   TokenStream Out;
   for (const Token  : Input.tokens()) {
Index: clang-tools-extra/pseudo/include/clang-pseudo/Token.h
===
--- clang-tools-extra/pseudo/include/clang-pseudo/Token.h
+++ clang-tools-extra/pseudo/include/clang-pseudo/Token.h
@@ -29,6 +29,7 @@
 #define CLANG_PSEUDO_TOKEN_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/raw_ostream.h"
@@ -193,6 +194,10 @@
   /// The text() of such tokens will contain the raw trigrah.
   NeedsCleaning = 1 << 1,
 };
+/// A generic lang options suitable for lexing/parsing a langage.
+clang::LangOptions genericLangOpts(
+clang::Language = clang::Language::CXX,
+clang::LangStandard::Kind = clang::LangStandard::lang_unspecified);
 
 /// Derives a token stream by decoding escapes, interpreting raw_identifiers 
and
 /// splitting the greatergreater token.


Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -53,8 +53,7 @@
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
 
-  clang::LangOptions LangOpts; // FIXME: use real options.
-  LangOpts.CPlusPlus = 1;
+  clang::LangOptions LangOpts = clang::pseudo::genericLangOpts();
   std::string SourceText;
   llvm::Optional RawStream;
   llvm::Optional DirectiveStructure;
Index: clang-tools-extra/pseudo/test/glr.cpp
===
--- clang-tools-extra/pseudo/test/glr.cpp
+++ clang-tools-extra/pseudo/test/glr.cpp
@@ -21,3 +21,15 @@
 // CHECK-NEXT:   │ 

[clang-tools-extra] ed1b327 - [pseudo] Print the GSS::Node details when the unittest fails, NFC.

2022-05-03 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-05-03T22:06:10+02:00
New Revision: ed1b32791dbb4c02cd761742a63cdf1e9d644ae6

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

LOG: [pseudo] Print the GSS::Node details when the unittest fails, NFC.

Added: 


Modified: 
clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
clang-tools-extra/pseudo/lib/GLR.cpp
clang-tools-extra/pseudo/unittests/GLRTest.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
index d66dbe5897762..f4eb424dd53fa 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
@@ -108,6 +108,7 @@ struct GSS {
   llvm::BumpPtrAllocator Arena;
   unsigned NodeCount = 0;
 };
+llvm::raw_ostream <<(llvm::raw_ostream &, const GSS::Node &);
 
 // Parameters for the GLR parsing.
 struct ParseParams {

diff  --git a/clang-tools-extra/pseudo/lib/GLR.cpp 
b/clang-tools-extra/pseudo/lib/GLR.cpp
index 542533ee801d4..c1fdd8680ca85 100644
--- a/clang-tools-extra/pseudo/lib/GLR.cpp
+++ b/clang-tools-extra/pseudo/lib/GLR.cpp
@@ -12,6 +12,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -26,6 +27,15 @@ namespace pseudo {
 
 using StateID = LRTable::StateID;
 
+llvm::raw_ostream <<(llvm::raw_ostream , const GSS::Node ) {
+  std::vector ParentStates;
+  for (const auto *Parent : N.parents())
+ParentStates.push_back(llvm::formatv("{0}", Parent->State));
+  OS << llvm::formatv("state {0}, parsed symbol {1}, parents {2}", N.State,
+  N.Payload->symbol(), llvm::join(ParentStates, ", "));
+  return OS;
+}
+
 const ForestNode (const TokenStream ,
const ParseParams ) {
   llvm::ArrayRef Terminals = Params.Forest.createTerminals(Tokens);

diff  --git a/clang-tools-extra/pseudo/unittests/GLRTest.cpp 
b/clang-tools-extra/pseudo/unittests/GLRTest.cpp
index fc19e0eec7ccc..1998c27dd90a5 100644
--- a/clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ b/clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -19,6 +19,14 @@
 
 namespace clang {
 namespace pseudo {
+
+llvm::raw_ostream <<(llvm::raw_ostream ,
+  const std::vector ) {
+  for (const auto *Head : Heads)
+OS << *Head << "\n";
+  return OS;
+}
+
 namespace {
 
 using Action = LRTable::Action;
@@ -28,16 +36,6 @@ MATCHER_P(state, StateID, "") { return arg->State == 
StateID; }
 MATCHER_P(parsedSymbol, FNode, "") { return arg->Payload == FNode; }
 MATCHER_P(parsedSymbolID, SID, "") { return arg->Payload->symbol() == SID; }
 
-
-// llvm::raw_ostream <<(llvm::raw_ostream , const NewHeadResult 
) {
-//   std::vector ParentStates;
-//   for (const auto  : R.Parents)
-// ParentStates.push_back(llvm::formatv("{0}", P->State));
-//   OS << llvm::formatv("state {0}, parsed symbol {1}, parents {2}", R.State,
-//   R.Parsed->symbol(), llvm::join(ParentStates, " "));
-//   return OS;
-// }
-
 testing::Matcher
 parents(llvm::ArrayRef Parents) {
   return testing::Property(::Node::parents,
@@ -134,7 +132,8 @@ TEST_F(GLRTest, ShiftMergingHeads) {
   AllOf(state(4), parsedSymbol(),
 parents({GSSNode1, GSSNode2})),
   AllOf(state(5), parsedSymbol(),
-parents({GSSNode3};
+parents({GSSNode3}
+  << NewHeadResults;
 }
 
 TEST_F(GLRTest, ReduceConflictsSplitting) {
@@ -161,13 +160,12 @@ TEST_F(GLRTest, ReduceConflictsSplitting) {
   {GSSNode1, Action::reduce(ruleFor("enum-name"))}};
   glrReduce(PendingReduce, {*G, Table, Arena, GSStack},
 captureNewHeads());
-  // Verify
   EXPECT_THAT(NewHeadResults,
   testing::UnorderedElementsAre(
   AllOf(state(2), parsedSymbolID(id("class-name")),
 parents({GSSNode0})),
   AllOf(state(3), parsedSymbolID(id("enum-name")),
-parents({GSSNode0};
+parents({GSSNode0} << NewHeadResults;
 }
 
 TEST_F(GLRTest, ReduceSplittingDueToMultipleBases) {
@@ -205,7 +203,7 @@ TEST_F(GLRTest, ReduceSplittingDueToMultipleBases) {
   AllOf(state(5), parsedSymbolID(id("ptr-operator")),
 parents({GSSNode2})),
   AllOf(state(6), parsedSymbolID(id("ptr-operator")),
-parents({GSSNode3};
+parents({GSSNode3} << 

[PATCH] D124842: [NFC][CUDA][HIP] rework mangling number for aux target

2022-05-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

lgtm, thanks!


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

https://reviews.llvm.org/D124842

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


[PATCH] D124493: Move Sanitizer metadata to be on-GlobalValue.

2022-05-03 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

I've always viewed the current implementation as a hack, and believed this data 
should live in debug info.

It can be convenient to get symbolized reports for global overflow bug in a 
stripped binary, but those bugs are quite rare, and "symbolization" only 
affects the global itself, not the stack trace of the bad memory access. It 
does not seem worth it to support two code paths just for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124493

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-05-03 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added subscribers: aprantl, rnk.
dblaikie added a comment.

Tried this patch on some internal targets and metrics and it seems actually 
quite reasonable.

Tested with split DWARF, on Linux, with compressed debug info in .o/.dwo files, 
uncompressed in exe/dwp files. With -O0 and -O3, roughly speaking. Testing 
Clang as well as testing a large Google binary only at -O3:
Clang:
-O0:
.o: +0.44%
.dwo: +1.55%
exe: 0.65%
dwp: 1.42%
-O3:
.o: 0.90%
.dwo: 0.26%
exe: 0.33%
dwp: 0.41%

Large Google Binary -O3:
.o: 0.32%
.dwo: 0.16%
exe: 0.19%
dwp: 0.22%

These are % of total size, not % of debug info contribution - so it's growing 
the debug info by more than that, but the total impact doesn't seem to be too 
bad.

@rnk @aprantl @probinson: this looks plausible to me to take as a general 
change to the emitted DWARF, but I'm open to ideas/suggestions if folks find 
this to be too much growth for not enough benefit & that it should be behind a 
flag?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D124868: [clang-format] Fix a bug in AlignConsecutiveAssignments

2022-05-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

Looks ok, but please let someone else have a look too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124868

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


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-05-03 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

In D121370#3488401 , @kwk wrote:

> @krasimir could you please test this patch on your side?

@kwk thank you! the new version of the patch looks good!

I didn't know before about the issue you found with the `/* a comment before */ 
#include ` (and since it's preexisting, if it's tricky to address, it 
would be reasonable to just file a bug for it and omit fixing it by this work, 
I think).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

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


[PATCH] D123009: [Sema] Enum conversion warning when one signed and other unsigned.

2022-05-03 Thread Micah Weston via Phabricator via cfe-commits
red1bluelost added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:113-114
   by unary operators.
+- ``-Wenum-conversion`` now warns on conversion of signed enum to unsigned enum
+  and unsigned enum to signed enum rather than ``-Wsign-conversion``.
 

aaron.ballman wrote:
> Minor tweak
Thanks!



Comment at: clang/test/Sema/enum-sign-conversion.c:6-8
+enum X { A,
+ B,
+ C };

aaron.ballman wrote:
> Unrelated formatting change?
Changed back.



Comment at: clang/test/Sema/enum-sign-conversion.c:14-18
+enum SE1 { N1 = -1 };
+enum SE2 { N2 = -2 };
+// Unsigned unums
+enum UE1 { P1 };
+enum UE2 { P2 };

aaron.ballman wrote:
> The second variants are unused.
Good catch, removed.



Comment at: clang/test/Sema/enum-sign-conversion.c:37-43
+unsigned f5(enum UE1 E) {
+  return E; // signed-warning {{implicit conversion changes signedness: 'enum 
UE1' to 'unsigned int'}}
+}
+
+enum UE1 f6(unsigned E) {
+  return E; // signed-warning {{implicit conversion changes signedness: 
'unsigned int' to 'enum UE1'}}
+}

aaron.ballman wrote:
> Shouldn't these not warn as well -- the underlying enum type is unsigned?
This is the case with 'win32' for the ABI. It has enum be signed as default. I 
changed the name of the verify to win32 to that it is easier to see that is the 
case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123009

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


[PATCH] D123009: [Sema] Enum conversion warning when one signed and other unsigned.

2022-05-03 Thread Micah Weston via Phabricator via cfe-commits
red1bluelost updated this revision to Diff 426804.
red1bluelost marked 4 inline comments as done.
red1bluelost added a comment.

Addresses comments to improve wording and remove unnecessary code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123009

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/enum-enum-conversion.c
  clang/test/Sema/enum-sign-conversion.c

Index: clang/test/Sema/enum-sign-conversion.c
===
--- clang/test/Sema/enum-sign-conversion.c
+++ clang/test/Sema/enum-sign-conversion.c
@@ -1,13 +1,47 @@
-// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -verify -DUNSIGNED -Wsign-conversion %s
-// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -verify -Wsign-conversion %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wsign-conversion -verify=unsigned,both %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wconversion -verify=unsigned,both %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -verify -Wsign-conversion -verify=win32,both %s
 
 // PR35200
-enum X { A,B,C};
+enum X { A, B, C };
 int f(enum X x) {
-#ifdef UNSIGNED
-  return x; // expected-warning {{implicit conversion changes signedness: 'enum X' to 'int'}}
-#else
-  // expected-no-diagnostics
-  return x;
-#endif
+  return x; // unsigned-warning {{implicit conversion changes signedness: 'enum X' to 'int'}}
+}
+
+// Signed enums
+enum SE1 { N1 = -1 };
+// Unsigned unums
+enum UE1 { P1 };
+
+// ensure no regression with enum to sign (related to enum-enum-conversion.c)
+int f1(enum UE1 E) {
+  return E; // unsigned-warning {{implicit conversion changes signedness: 'enum UE1' to 'int'}}
+}
+
+enum UE1 f2(int E) {
+  return E; // unsigned-warning {{implicit conversion changes signedness: 'int' to 'enum UE1'}}
+}
+
+int f3(enum SE1 E) {
+  return E; // shouldn't warn
+}
+
+enum SE1 f4(int E) {
+  return E; // shouldn't warn
+}
+
+unsigned f5(enum UE1 E) {
+  return E; // win32-warning {{implicit conversion changes signedness: 'enum UE1' to 'unsigned int'}}
+}
+
+enum UE1 f6(unsigned E) {
+  return E; // win32-warning {{implicit conversion changes signedness: 'unsigned int' to 'enum UE1'}}
+}
+
+unsigned f7(enum SE1 E) {
+  return E; // both-warning {{implicit conversion changes signedness: 'enum SE1' to 'unsigned int'}}
+}
+
+enum SE1 f8(unsigned E) {
+  return E; // both-warning {{implicit conversion changes signedness: 'unsigned int' to 'enum SE1'}}
 }
Index: clang/test/Sema/enum-enum-conversion.c
===
--- /dev/null
+++ clang/test/Sema/enum-enum-conversion.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wenum-conversion -verify %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wconversion -verify %s
+
+// Signed enums
+enum SE1 { N1 = -1 };
+enum SE2 { N2 = -2 };
+// Unsigned unums
+enum UE1 { P1 };
+enum UE2 { P2 };
+
+enum UE2 f1(enum UE1 E) {
+  return E; // expected-warning {{implicit conversion from enumeration type 'enum UE1' to different enumeration type 'enum UE2'}}
+}
+
+enum SE1 f2(enum UE1 E) {
+  return E; // expected-warning {{implicit conversion from enumeration type 'enum UE1' to different enumeration type 'enum SE1'}}
+}
+
+enum UE1 f3(enum SE1 E) {
+  return E; // expected-warning {{implicit conversion from enumeration type 'enum SE1' to different enumeration type 'enum UE1'}}
+}
+
+enum SE2 f4(enum SE1 E) {
+  return E; // expected-warning {{implicit conversion from enumeration type 'enum SE1' to different enumeration type 'enum SE2'}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13534,9 +13534,10 @@
 // Fall through for non-constants to give a sign conversion warning.
   }
 
-  if ((TargetRange.NonNegative && !LikelySourceRange.NonNegative) ||
-  (!TargetRange.NonNegative && LikelySourceRange.NonNegative &&
-   LikelySourceRange.Width == TargetRange.Width)) {
+  if ((!isa(Target) || !isa(Source)) &&
+  ((TargetRange.NonNegative && !LikelySourceRange.NonNegative) ||
+   (!TargetRange.NonNegative && LikelySourceRange.NonNegative &&
+LikelySourceRange.Width == TargetRange.Width))) {
 if (S.SourceMgr.isInSystemMacro(CC))
   return;
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -110,6 +110,9 @@
   `_.
 - ``-Wunused-but-set-variable`` now also warns if the variable is only used
   by unary operators.
+- ``-Wenum-conversion`` now warns on converting a signed enum of one type to an
+  unsigned enum of a different type (or 

[PATCH] D124790: [HLSL] Enable half type for hlsl.

2022-05-03 Thread Xiang Li via Phabricator via cfe-commits
python3kgae marked 2 inline comments as done.
python3kgae added inline comments.



Comment at: clang/lib/Basic/LangOptions.cpp:197
 
-  // OpenCL has half keyword
-  Opts.Half = Opts.OpenCL;
+  // OpenCL and HLSL have half keyword
+  Opts.Half = Opts.OpenCL || Opts.HLSL;

aaron.ballman wrote:
> python3kgae wrote:
> > aaron.ballman wrote:
> > > Shouldn't this be looking for HLSL 2018? Or shader model 6.2?
> > half keyword is always available.
> > Without enable_16bit_types, half will be like using half=float.
> > With enable_16bit_types, half will be real half.
> > 
> > The check for HLSL 2018 and shader model 6.2 will be in another PR, still 
> > WIP. I'll add FIXME about it.
> > half keyword is always available.
> > Without enable_16bit_types, half will be like using half=float.
> > With enable_16bit_types, half will be real half.
> 
> Is there room for change here, or is this strictly required by HLSL? This 
> strikes me as just begging to confuse users into creating ODR violations. CC 
> @beanz 
Here's the doc about half for dxc.
https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types

Old doc for fxc (the old shader compiler for shader model <= 5.1) is here
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-scalar

Change the behavior might affect a lot of existing shaders.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124790

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


[PATCH] D124702: [MSVC] Add support for pragma function

2022-05-03 Thread Stephen Long via Phabricator via cfe-commits
steplong updated this revision to Diff 426802.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124702

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/pragma-ms-function-intrinsic.c

Index: clang/test/CodeGen/pragma-ms-function-intrinsic.c
===
--- /dev/null
+++ clang/test/CodeGen/pragma-ms-function-intrinsic.c
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -emit-llvm -fms-extensions -o - %s | FileCheck %s
+
+typedef typeof(sizeof(0)) size_t;
+
+void bar(char *s);
+void *memset(void *s, int c, size_t n);
+void *memcpy(void *d, const void *s, size_t n);
+
+// CHECK: define{{.*}} void @foo1({{.*}}) #[[NO_NOBUILTIN:[0-9]+]]
+// CHECK:   call void @bar
+// CHECK:   call void @llvm.memset
+// CHECK:   call void @llvm.memcpy
+void foo1(char *s, char *d, size_t n)
+{
+bar(s);
+memset(s, 0, n);
+memcpy(d, s, n);
+}
+
+#pragma function(strlen, memset)
+
+// CHECK: define{{.*}} void @foo2({{.*}}) #[[NOBUILTIN_MEMSET:[0-9]+]]
+// CHECK:   call void @bar
+// CHECK:   {{.*}}call {{.*}} @memset
+// CHECK:   call void @llvm.memcpy
+void foo2(char *s, char *d, size_t n)
+{
+bar(s);
+memset(s, 1, n);
+memcpy(d, s, n);
+}
+
+#pragma function(memcpy)
+
+// CHECK: define{{.*}} void @foo3({{.*}}) #[[NOBUILTIN_MEMSET_MEMCPY:[0-9]+]]
+// CHECK:   call void @bar
+// CHECK:   {{.*}}call {{.*}} @memset
+// CHECK:   {{.*}}call {{.*}} @memcpy
+void foo3(char *s, char *d, size_t n)
+{
+bar(s);
+memset(s, 2, n);
+memcpy(d, s, n);
+}
+
+#pragma intrinsic(memset, strlen)
+
+// CHECK: define{{.*}} void @foo4({{.*}}) #[[NOBUILTIN_MEMCPY:[0-9]+]]
+// CHECK:   call void @bar
+// CHECK:   call void @llvm.memset
+// CHECK:   {{.*}}call {{.*}} @memcpy
+void foo4(char *s, char *d, size_t n)
+{
+bar(s);
+memset(s, 3, n);
+memcpy(d, s, n);
+}
+
+#pragma intrinsic(memcpy)
+
+// CHECK: define{{.*}} void @foo5({{.*}}) #[[NO_NOBUILTIN]]
+// CHECK:   call void @bar
+// CHECK:   call void @llvm.memset
+// CHECK:   call void @llvm.memcpy
+void foo5(char *s, char *d, size_t n)
+{
+bar(s);
+memset(s, 4, n);
+memcpy(d, s, n);
+}
+
+// CHECK-NOT: attributes #[[NO_NOBUILTIN]] = {{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK-NOT: attributes #[[NO_NOBUILTIN]] = {{{.*}}"no-builtin-memcpy"{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK: attributes #[[NOBUILTIN_MEMSET]] = {{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK-NOT: attributes #[[NOBUILTIN_MEMSET]] = {{{.*}}"no-builtin-memcpy"{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK: attributes #[[NOBUILTIN_MEMSET_MEMCPY]] = {{{.*}}"no-builtin-memcpy"{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK: attributes #[[NOBUILTIN_MEMCPY]] = {{{.*}}"no-builtin-memcpy"{{.*}}}
+// CHECK-NOT: attributes #[[NOBUILTIN_MEMCPY]] = {{{.*}}"no-builtin-memcpy"{{.*}}"no-builtin-memset"{{.*}}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -10218,10 +10218,12 @@
   // marking the function.
   AddCFAuditedAttribute(NewFD);
 
-  // If this is a function definition, check if we have to apply optnone due to
-  // a pragma.
-  if(D.isFunctionDefinition())
+  // If this is a function definition, check if we have to apply any
+  // attributes (i.e. optnone and no_builtin) due to a pragma.
+  if(D.isFunctionDefinition()) {
 AddRangeBasedOptnone(NewFD);
+AddRangeBasedNoBuiltin(NewFD);
+  }
 
   // If this is the first declaration of an extern C variable, update
   // the map of such variables.
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -1065,6 +1065,20 @@
 OptimizeOffPragmaLocation = PragmaLoc;
 }
 
+void Sema::ActOnPragmaMSIntrinsic(const std::vector ) {
+  for (auto  : Intrinsics) {
+MSFunctionNoBuiltins.erase(std::remove(MSFunctionNoBuiltins.begin(),
+   MSFunctionNoBuiltins.end(),
+   Intrinsic),
+   MSFunctionNoBuiltins.end());
+  }
+}
+
+void Sema::ActOnPragmaMSFunction(const std::vector ) {
+  MSFunctionNoBuiltins.insert(MSFunctionNoBuiltins.end(),
+  NoBuiltins.begin(), NoBuiltins.end());
+}
+
 void Sema::AddRangeBasedOptnone(FunctionDecl *FD) {
   // In the future, check other pragmas if they're implemented (e.g. pragma
   // optimize 0 will probably map to this functionality too).
@@ -1086,6 +1100,13 @@
 FD->addAttr(NoInlineAttr::CreateImplicit(Context, Loc));
 }
 
+void Sema::AddRangeBasedNoBuiltin(FunctionDecl *FD) {
+  if (!MSFunctionNoBuiltins.empty()) {
+

[PATCH] D123831: [clang][extract-api] Use relative includes

2022-05-03 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 426803.
zixuw added a comment.

- Capture whether the include is quoted in KnownFiles
- Misc: use `getInputBufferName()` instead of string literal


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123831

Files:
  clang/include/clang/ExtractAPI/FrontendActions.h
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/known_files_only_hmap.c
  clang/test/ExtractAPI/relative_include.m

Index: clang/test/ExtractAPI/relative_include.m
===
--- clang/test/ExtractAPI/relative_include.m
+++ clang/test/ExtractAPI/relative_include.m
@@ -1,13 +1,27 @@
 // RUN: rm -rf %t
 // RUN: split-file %s %t
-// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+
+// Setup framework root
+// RUN: mkdir -p %t/Frameworks/MyFramework.framework/Headers
+// RUN: cp %t/MyFramework.h %t/Frameworks/MyFramework.framework/Headers/
+// RUN: cp %t/MyHeader.h %t/Frameworks/MyFramework.framework/Headers/
+
+// RUN: sed -e "s@SRCROOT@%{/t:regex_replacement}@g" \
 // RUN: %t/reference.output.json.in >> %t/reference.output.json
-// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
-// RUN: %t/known_files_only.hmap.json.in >> %t/known_files_only.hmap.json
-// RUN: %hmaptool write %t/known_files_only.hmap.json %t/known_files_only.hmap
-// RUN: %clang -extract-api --product-name=KnownFilesOnlyHmap -target arm64-apple-macosx \
-// RUN: -I%t/known_files_only.hmap -I%t/subdir %t/subdir/subdir1/input.h \
-// RUN: %t/subdir/subdir2/known_file.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Headermap maps headers to the source root SRCROOT
+// RUN: sed -e "s@SRCROOT@%{/t:regex_replacement}@g" \
+// RUN: %t/headermap.hmap.json.in >> %t/headermap.hmap.json
+// RUN: %hmaptool write %t/headermap.hmap.json %t/headermap.hmap
+
+// Input headers use paths to the framework root/DSTROOT
+// RUN: %clang -extract-api -v --product-name=MyFramework -target arm64-apple-macosx \
+// RUN: -iquote%t -I%t/headermap.hmap -F%t/Frameworks \
+// RUN: -x objective-c-header \
+// RUN: %t/Frameworks/MyFramework.framework/Headers/MyFramework.h \
+// RUN: %t/Frameworks/MyFramework.framework/Headers/MyHeader.h \
+// RUN: %t/QuotedHeader.h \
+// RUN: -o %t/output.json 2>&1 | FileCheck -allow-empty %s
 
 // Generator version is not consistent across test runs, normalize it.
 // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
@@ -16,32 +30,33 @@
 
 // CHECK-NOT: error:
 // CHECK-NOT: warning:
-//--- known_files_only.hmap.json.in
+
+// CHECK:  :
+// CHECK-NEXT: #import 
+// CHECK-NEXT: #import 
+// CHECK-NEXT: #import "QuotedHeader.h"
+
+//--- headermap.hmap.json.in
 {
   "mappings" :
 {
- "subdir2/known_file.h" : "INPUT_DIR/subdir/subdir3/unknown.h"
+ "MyFramework/MyHeader.h" : "SRCROOT/MyHeader.h"
 }
 }
 
-//--- subdir/subdir1/input.h
-int num;
-#include "subdir2/known_file.h"
+//--- MyFramework.h
+// Umbrella for MyFramework
+#import 
 
-//--- subdir/subdir2/known_file.h
-int known_num;
+//--- MyHeader.h
+#import 
+int MyInt;
 
-//--- subdir/subdir3/unknown.h
-// Ensure that these symbols are not emitted in the Symbol Graph.
-#ifndef INPUT4_H
-#define INPUT4_H
+//--- QuotedHeader.h
+char MyChar;
 
-#define HELLO 1
-char not_emitted;
-void foo(int);
-struct Foo { int a; };
-
-#endif
+//--- Frameworks/OtherFramework.framework/Headers/OtherHeader.h
+int OtherInt;
 
 //--- reference.output.json.in
 {
@@ -54,7 +69,7 @@
 "generator": "?"
   },
   "module": {
-"name": "KnownFilesOnlyHmap",
+"name": "MyFramework",
 "platform": {
   "architecture": "arm64",
   "operatingSystem": {
@@ -84,41 +99,41 @@
 },
 {
   "kind": "identifier",
-  "spelling": "num"
+  "spelling": "MyInt"
 }
   ],
   "identifier": {
-"interfaceLanguage": "c",
-"precise": "c:@num"
+"interfaceLanguage": "objective-c",
+"precise": "c:@MyInt"
   },
   "kind": {
 "displayName": "Global Variable",
-"identifier": "c.var"
+"identifier": "objective-c.var"
   },
   "location": {
 "position": {
   "character": 5,
-  "line": 1
+  "line": 2
 },
-"uri": "file://INPUT_DIR/subdir/subdir1/input.h"
+"uri": "file://SRCROOT/MyHeader.h"
   },
   "names": {
 "navigator": [
   {
 "kind": "identifier",
-"spelling": "num"
+"spelling": "MyInt"
   }
 ],
 "subHeading": [
   {
 "kind": "identifier",
-"spelling": "num"
+"spelling": "MyInt"
   }
 ],
-"title": "num"
+"title": "MyInt"
   },
   "pathComponents": [
-"num"
+"MyInt"
   ]
 },
 {
@@ -126,8 +141,8 @@
   "declarationFragments": [
 {
   

[PATCH] D124774: [clang][ASTImporter][NFC]: Move clang::ImportError into own header and rename it .

2022-05-03 Thread Shivam Rajput via Phabricator via cfe-commits
phyBrackets added inline comments.



Comment at: clang/include/clang/AST/ASTImporterLookupTable.h:17
 
+#include "clang/AST/ASTImportError.h"
 #include "clang/AST/DeclBase.h" // lookup_result

balazske wrote:
> This include is not needed here.
Hey thanks for reviewing , I have a doubt if I remove this include it from here 
, then I need to include this header in the ASTImporterSharedState.h , now the 
ASTImporterSharedState.h and ASTImporter.h both have ASTImportError.h included 
, isn't this affect on ASTImporter.cpp file on conflicting over ASTImportError 
? Strangely it builds fine on my system tho .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124774

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


[PATCH] D124634: ExtractAPI: Use %clang_cc1 and -verify in enum.c

2022-05-03 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc1e17c7dfedd: ExtractAPI: Use %clang_cc1 and -verify in 
enum.c (authored by dexonsmith).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124634

Files:
  clang/test/ExtractAPI/enum.c


Index: clang/test/ExtractAPI/enum.c
===
--- clang/test/ExtractAPI/enum.c
+++ clang/test/ExtractAPI/enum.c
@@ -2,17 +2,14 @@
 // RUN: split-file %s %t
 // RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
 // RUN: %t/reference.output.json.in >> %t/reference.output.json
-// RUN: %clang -extract-api -target arm64-apple-macosx \
-// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c-header %t/input.h -o %t/output.json -verify
 
 // Generator version is not consistent across test runs, normalize it.
 // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
 // RUN: %t/output.json >> %t/output-normalized.json
 // RUN: diff %t/reference.output.json %t/output-normalized.json
 
-// CHECK-NOT: error:
-// CHECK-NOT: warning:
-
 //--- input.h
 /// Kinds of vehicles
 enum Vehicle {
@@ -37,6 +34,7 @@
 enum {
   OtherConstant = 2
 };
+// expected-no-diagnostics
 
 //--- reference.output.json.in
 {


Index: clang/test/ExtractAPI/enum.c
===
--- clang/test/ExtractAPI/enum.c
+++ clang/test/ExtractAPI/enum.c
@@ -2,17 +2,14 @@
 // RUN: split-file %s %t
 // RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
 // RUN: %t/reference.output.json.in >> %t/reference.output.json
-// RUN: %clang -extract-api -target arm64-apple-macosx \
-// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c-header %t/input.h -o %t/output.json -verify
 
 // Generator version is not consistent across test runs, normalize it.
 // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
 // RUN: %t/output.json >> %t/output-normalized.json
 // RUN: diff %t/reference.output.json %t/output-normalized.json
 
-// CHECK-NOT: error:
-// CHECK-NOT: warning:
-
 //--- input.h
 /// Kinds of vehicles
 enum Vehicle {
@@ -37,6 +34,7 @@
 enum {
   OtherConstant = 2
 };
+// expected-no-diagnostics
 
 //--- reference.output.json.in
 {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c1e17c7 - ExtractAPI: Use %clang_cc1 and -verify in enum.c

2022-05-03 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2022-05-03T11:57:24-07:00
New Revision: c1e17c7dfedd27b95c8c2fba2b6473c7348f0e77

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

LOG: ExtractAPI: Use %clang_cc1 and -verify in enum.c

Fix one test (enum.c) in ExtractAPI to use %clang_cc1 and -verify
instead of calling the full driver and FileCheck. This is an example for
my comment from https://reviews.llvm.org/D121873.

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

Added: 


Modified: 
clang/test/ExtractAPI/enum.c

Removed: 




diff  --git a/clang/test/ExtractAPI/enum.c b/clang/test/ExtractAPI/enum.c
index a14666a037471..8c06d850dbdaf 100644
--- a/clang/test/ExtractAPI/enum.c
+++ b/clang/test/ExtractAPI/enum.c
@@ -2,17 +2,14 @@
 // RUN: split-file %s %t
 // RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
 // RUN: %t/reference.output.json.in >> %t/reference.output.json
-// RUN: %clang -extract-api -target arm64-apple-macosx \
-// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c-header %t/input.h -o %t/output.json -verify
 
 // Generator version is not consistent across test runs, normalize it.
 // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
 // RUN: %t/output.json >> %t/output-normalized.json
 // RUN: 
diff  %t/reference.output.json %t/output-normalized.json
 
-// CHECK-NOT: error:
-// CHECK-NOT: warning:
-
 //--- input.h
 /// Kinds of vehicles
 enum Vehicle {
@@ -37,6 +34,7 @@ enum {
 enum {
   OtherConstant = 2
 };
+// expected-no-diagnostics
 
 //--- reference.output.json.in
 {



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


[PATCH] D92160: [clang] Fix wrong FDs are used for files with same name in Tooling

2022-05-03 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added reviewers: benlangmuir, bnbarham, jansvoboda11.
dexonsmith added subscribers: bnbarham, benlangmuir.
dexonsmith added a comment.

Adding @bnbarham, @jansvoboda11, and @benlangmuir, who have been looking at 
various FileManager issues recently. If you post a follow up I suggest keeping 
them in the loop!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92160

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


[PATCH] D124868: [clang-format] Fix a bug in AlignConsecutiveAssignments

2022-05-03 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124868

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18010,11 +18010,21 @@
Style);
   // clang-format on
 
-  Style = getLLVMStyleWithColumns(120);
+  Style = getLLVMStyleWithColumns(20);
   Style.AlignConsecutiveAssignments.Enabled = true;
-  Style.ContinuationIndentWidth = 4;
   Style.IndentWidth = 4;
 
+  verifyFormat("void foo() {\n"
+   "int i1 = 1;\n"
+   "int j  = 0;\n"
+   "int k  = bar(\n"
+   "argument1,\n"
+   "argument2);\n"
+   "}",
+   Style);
+
+  Style.ColumnLimit = 120;
+
   // clang-format off
   verifyFormat("void SomeFunc() {\n"
"newWatcher.maxAgeUsec = 
ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp(monitorFrequencyUsec),\n"
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -369,6 +369,8 @@
   if (Changes[i].Tok->MatchingParen &&
   Changes[i].Tok->MatchingParen->is(TT_LambdaLBrace))
 return false;
+  if (Changes[ScopeStart].NewlinesBefore > 0)
+return false;
   return Style.BinPackArguments;
 }
 


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18010,11 +18010,21 @@
Style);
   // clang-format on
 
-  Style = getLLVMStyleWithColumns(120);
+  Style = getLLVMStyleWithColumns(20);
   Style.AlignConsecutiveAssignments.Enabled = true;
-  Style.ContinuationIndentWidth = 4;
   Style.IndentWidth = 4;
 
+  verifyFormat("void foo() {\n"
+   "int i1 = 1;\n"
+   "int j  = 0;\n"
+   "int k  = bar(\n"
+   "argument1,\n"
+   "argument2);\n"
+   "}",
+   Style);
+
+  Style.ColumnLimit = 120;
+
   // clang-format off
   verifyFormat("void SomeFunc() {\n"
"newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp(monitorFrequencyUsec),\n"
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -369,6 +369,8 @@
   if (Changes[i].Tok->MatchingParen &&
   Changes[i].Tok->MatchingParen->is(TT_LambdaLBrace))
 return false;
+  if (Changes[ScopeStart].NewlinesBefore > 0)
+return false;
   return Style.BinPackArguments;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123009: [Sema] Enum conversion warning when one signed and other unsigned.

2022-05-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:113-114
   by unary operators.
+- ``-Wenum-conversion`` now warns on conversion of signed enum to unsigned enum
+  and unsigned enum to signed enum rather than ``-Wsign-conversion``.
 

Minor tweak



Comment at: clang/test/Sema/enum-sign-conversion.c:6-8
+enum X { A,
+ B,
+ C };

Unrelated formatting change?



Comment at: clang/test/Sema/enum-sign-conversion.c:14-18
+enum SE1 { N1 = -1 };
+enum SE2 { N2 = -2 };
+// Unsigned unums
+enum UE1 { P1 };
+enum UE2 { P2 };

The second variants are unused.



Comment at: clang/test/Sema/enum-sign-conversion.c:37-43
+unsigned f5(enum UE1 E) {
+  return E; // signed-warning {{implicit conversion changes signedness: 'enum 
UE1' to 'unsigned int'}}
+}
+
+enum UE1 f6(unsigned E) {
+  return E; // signed-warning {{implicit conversion changes signedness: 
'unsigned int' to 'enum UE1'}}
+}

Shouldn't these not warn as well -- the underlying enum type is unsigned?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123009

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


[PATCH] D124836: [AArch64] Add support for -fzero-call-used-regs

2022-05-03 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:682
+// The called routine is expected to preserve r19-r28
+// r29 and r30 are used as frame pointer and link register resp.
+return 0;

What happens if `-fomit-frame-pointer` is specified? Is X29 used as a GPR then?



Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:757
+MachineBasicBlock ) const {
+  const MachineFunction  = *MBB.getParent();
+

sink this closer to first use, L767



Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:776-778
+  // For GPRs, we only care to clear out the 64-bit register.
+  if (MCRegister XReg = getRegisterOrZero(Reg))
+GPRsToZero.set(XReg);

so for 32b registers, we clear the whole 64b register?



Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:787-792
+  for (MCRegister Reg : GPRsToZero.set_bits())
+BuildMI(MBB, MBBI, DL, TII->get(AArch64::MOVi64imm), Reg).addImm(0);
+
+  // Zero out FP/vector registers.
+  for (MCRegister Reg : FPRsToZero.set_bits())
+BuildMI(MBB, MBBI, DL, TII->get(AArch64::MOVID), Reg).addImm(0);

isn't it more canonical on ARM to move from the dedicated zero register XZR 
rather than use an immediate?



Comment at: llvm/lib/Target/AArch64/AArch64RegisterInfo.td:1404
+}
+def FPR32_ARG : RegisterClass<"AArch64", [f32, i32], 32, (trunc FPR32, 7)>;
+def FPR64_ARG : RegisterClass<"AArch64",

is `i32` correct here?



Comment at: llvm/lib/Target/X86/X86RegisterInfo.cpp:659
 
-  return false;
+  return X86GenRegisterInfo::isArgumentRegister(MF, Reg);
 }

Does this allow us to clean up anything else in the body of this method?

Consider making this and the tablegen related patch a distinct child patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124836

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


[clang] c7ecfad - Fix some places where PseudoObjectExpr handling assumed that a

2022-05-03 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2022-05-03T11:55:14-07:00
New Revision: c7ecfadf9beb936e5101db4362dd2935d415b04d

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

LOG: Fix some places where PseudoObjectExpr handling assumed that a
PseudoObjectExpr is only used for ObjC properties and subscripts.

For now, these assumptions are generally correct, but that's not part of
the design of PseudoObjectExpr. No functionality change intended.

Added: 


Modified: 
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index f761d79340797..bfce60221e4b9 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2457,8 +2457,12 @@ bool Expr::isReadIfDiscardedInCPlusPlus11() const {
   }
 
   // Objective-C++ extensions to the rule.
-  if (isa(E) || isa(E))
+  if (isa(E))
 return true;
+  if (const auto *POE = dyn_cast(E)) {
+if (isa(POE->getSyntacticForm()))
+  return true;
+  }
 
   return false;
 }
@@ -2708,23 +2712,35 @@ bool Expr::isUnusedResultAWarning(const Expr *, 
SourceLocation ,
   }
 
   case ObjCPropertyRefExprClass:
+  case ObjCSubscriptRefExprClass:
 WarnE = this;
 Loc = getExprLoc();
 R1 = getSourceRange();
 return true;
 
   case PseudoObjectExprClass: {
-const PseudoObjectExpr *PO = cast(this);
+const auto *POE = cast(this);
 
-// Only complain about things that have the form of a getter.
-if (isa(PO->getSyntacticForm()) ||
-isa(PO->getSyntacticForm()))
-  return false;
+// For some syntactic forms, we should always warn.
+if (isa(
+POE->getSyntacticForm())) {
+  WarnE = this;
+  Loc = getExprLoc();
+  R1 = getSourceRange();
+  return true;
+}
 
-WarnE = this;
-Loc = getExprLoc();
-R1 = getSourceRange();
-return true;
+// For others, we should never warn.
+if (auto *BO = dyn_cast(POE->getSyntacticForm()))
+  if (BO->isAssignmentOp())
+return false;
+if (auto *UO = dyn_cast(POE->getSyntacticForm()))
+  if (UO->isIncrementDecrementOp())
+return false;
+
+// Otherwise, warn if the result expression would warn.
+const Expr *Result = POE->getResultExpr();
+return Result && Result->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
   }
 
   case StmtExprClass: {

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f7ed92d43f3be..ae3ea4db233e5 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -341,7 +341,7 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned 
DiagID) {
   return DiagnoseUnusedExprResult(POE->getSemanticExpr(0), DiagID);
 if (isa(Source))
   DiagID = diag::warn_unused_container_subscript_expr;
-else
+else if (isa(Source))
   DiagID = diag::warn_unused_property_expr;
   } else if (const CXXFunctionalCastExpr *FC
= dyn_cast(E)) {



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


[PATCH] D124790: [HLSL] Enable half type for hlsl.

2022-05-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Basic/LangOptions.cpp:197
 
-  // OpenCL has half keyword
-  Opts.Half = Opts.OpenCL;
+  // OpenCL and HLSL have half keyword
+  Opts.Half = Opts.OpenCL || Opts.HLSL;

python3kgae wrote:
> aaron.ballman wrote:
> > Shouldn't this be looking for HLSL 2018? Or shader model 6.2?
> half keyword is always available.
> Without enable_16bit_types, half will be like using half=float.
> With enable_16bit_types, half will be real half.
> 
> The check for HLSL 2018 and shader model 6.2 will be in another PR, still 
> WIP. I'll add FIXME about it.
> half keyword is always available.
> Without enable_16bit_types, half will be like using half=float.
> With enable_16bit_types, half will be real half.

Is there room for change here, or is this strictly required by HLSL? This 
strikes me as just begging to confuse users into creating ODR violations. CC 
@beanz 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124790

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


[PATCH] D124701: [clang] Honor __attribute__((no_builtin("foo"))) on functions

2022-05-03 Thread Stephen Long via Phabricator via cfe-commits
steplong updated this revision to Diff 426795.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124701

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/no-builtin-2.c


Index: clang/test/CodeGen/no-builtin-2.c
===
--- /dev/null
+++ clang/test/CodeGen/no-builtin-2.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+typedef typeof(sizeof(0)) size_t;
+
+void bar(char *s);
+void *memset(void *s, int c, size_t n);
+void *memcpy(void *d, const void *s, size_t n);
+
+// CHECK: define{{.*}} void @foo1({{.*}}) #[[NO_NOBUILTIN:[0-9]+]]
+// CHECK:   call void @bar
+// CHECK:   call void @llvm.memset
+// CHECK:   call void @llvm.memcpy
+void foo1(char *s, char *d, size_t n)
+{
+bar(s);
+memset(s, 0, n);
+memcpy(d, s, n);
+}
+
+// CHECK: define{{.*}} void @foo2({{.*}}) #[[NOBUILTIN_MEMSET:[0-9]+]]
+// CHECK:   call void @bar
+// CHECK:   {{.*}}call {{.*}} @memset
+// CHECK:   call void @llvm.memcpy
+void foo2(char *s, char *d, size_t n) __attribute__((no_builtin("memset")))
+{
+bar(s);
+memset(s, 1, n);
+memcpy(d, s, n);
+}
+
+// CHECK: define{{.*}} void @foo3({{.*}}) #[[NOBUILTIN_MEMSET_MEMCPY:[0-9]+]]
+// CHECK:   call void @bar
+// CHECK:   {{.*}}call {{.*}} @memset
+// CHECK:   {{.*}}call {{.*}} @memcpy
+void foo3(char *s, char *d, size_t n) __attribute__((no_builtin("memset", 
"memcpy")))
+{
+bar(s);
+memset(s, 2, n);
+memcpy(d, s, n);
+}
+
+// CHECK-NOT: attributes #[[NO_NOBUILTIN]] = {{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK-NOT: attributes #[[NO_NOBUILTIN]] = 
{{{.*}}"no-builtin-memcpy"{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK: attributes #[[NOBUILTIN_MEMSET]] = 
{{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK: attributes #[[NOBUILTIN_MEMSET_MEMCPY]] = 
{{{.*}}"no-builtin-memcpy"{{.*}}"no-builtin-memset"{{.*}}}
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -5034,6 +5034,7 @@
   const FunctionDecl *FD = cast(GD.getDecl());
 
   if (auto builtinID = FD->getBuiltinID()) {
+std::string AttributeNoBuiltin = "no-builtin-" + FD->getName().str();
 std::string FDInlineName = (FD->getName() + ".inline").str();
 // When directing calling an inline builtin, call it through it's mangled
 // name to make it clear it's not the actual builtin.
@@ -5054,8 +5055,9 @@
 
 // Replaceable builtins provide their own implementation of a builtin. If 
we
 // are in an inline builtin implementation, avoid trivial infinite
-// recursion.
-else
+// recursion. Honor __attribute__((no_builtin("foo"))) on the current
+// function.
+else if (!CGF.CurFn->getAttributes().hasFnAttr(AttributeNoBuiltin))
   return CGCallee::forBuiltin(builtinID, FD);
   }
 


Index: clang/test/CodeGen/no-builtin-2.c
===
--- /dev/null
+++ clang/test/CodeGen/no-builtin-2.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+typedef typeof(sizeof(0)) size_t;
+
+void bar(char *s);
+void *memset(void *s, int c, size_t n);
+void *memcpy(void *d, const void *s, size_t n);
+
+// CHECK: define{{.*}} void @foo1({{.*}}) #[[NO_NOBUILTIN:[0-9]+]]
+// CHECK:   call void @bar
+// CHECK:   call void @llvm.memset
+// CHECK:   call void @llvm.memcpy
+void foo1(char *s, char *d, size_t n)
+{
+bar(s);
+memset(s, 0, n);
+memcpy(d, s, n);
+}
+
+// CHECK: define{{.*}} void @foo2({{.*}}) #[[NOBUILTIN_MEMSET:[0-9]+]]
+// CHECK:   call void @bar
+// CHECK:   {{.*}}call {{.*}} @memset
+// CHECK:   call void @llvm.memcpy
+void foo2(char *s, char *d, size_t n) __attribute__((no_builtin("memset")))
+{
+bar(s);
+memset(s, 1, n);
+memcpy(d, s, n);
+}
+
+// CHECK: define{{.*}} void @foo3({{.*}}) #[[NOBUILTIN_MEMSET_MEMCPY:[0-9]+]]
+// CHECK:   call void @bar
+// CHECK:   {{.*}}call {{.*}} @memset
+// CHECK:   {{.*}}call {{.*}} @memcpy
+void foo3(char *s, char *d, size_t n) __attribute__((no_builtin("memset", "memcpy")))
+{
+bar(s);
+memset(s, 2, n);
+memcpy(d, s, n);
+}
+
+// CHECK-NOT: attributes #[[NO_NOBUILTIN]] = {{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK-NOT: attributes #[[NO_NOBUILTIN]] = {{{.*}}"no-builtin-memcpy"{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK: attributes #[[NOBUILTIN_MEMSET]] = {{{.*}}"no-builtin-memset"{{.*}}}
+// CHECK: attributes #[[NOBUILTIN_MEMSET_MEMCPY]] = {{{.*}}"no-builtin-memcpy"{{.*}}"no-builtin-memset"{{.*}}}
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -5034,6 +5034,7 @@
   const FunctionDecl *FD = cast(GD.getDecl());
 
   if (auto builtinID = FD->getBuiltinID()) {
+std::string AttributeNoBuiltin = "no-builtin-" 

[PATCH] D124866: [CUDA][HIP] support __noinline__ as keyword

2022-05-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 426794.
yaxunl added a comment.

add feature cuda_noinline_keyword to facilitate CUDA/HIP headers removing 
__noinline__ macro


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

https://reviews.llvm.org/D124866

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/test/CodeGenCUDA/noinline.cu
  clang/test/Lexer/has_feature.cu
  clang/test/SemaCUDA/noinline.cu

Index: clang/test/SemaCUDA/noinline.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/noinline.cu
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=cuda %s
+// RUN: %clang_cc1 -fsyntax-only -verify=cpp -x c++ %s
+
+// cuda-no-diagnostics
+
+__noinline__ void fun1() { } // cpp-error {{unknown type name '__noinline__'}}
+__attribute__((noinline)) void fun2() { }
+__attribute__((__noinline__)) void fun3() { }
Index: clang/test/Lexer/has_feature.cu
===
--- /dev/null
+++ clang/test/Lexer/has_feature.cu
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -E -triple x86_64-linux-gnu %s -o - | FileCheck %s
+
+// CHECK: has_noinline_keyword
+#if __has_feature(cuda_noinline_keyword)
+int has_noinline_keyword();
+#else
+int no_noinine_keyword();
+#endif
Index: clang/test/CodeGenCUDA/noinline.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/noinline.cu
@@ -0,0 +1,27 @@
+// optimization is needed, otherwise by default all functions have noinline.
+
+// RUN: %clang_cc1 -triple nvptx-nvidia-cuda -fcuda-is-device \
+// RUN: -O2 -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device \
+// RUN: -O2 -emit-llvm -o - -x hip %s | FileCheck %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-gnu-linux \
+// RUN: -O2 -emit-llvm -o - %s | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+__noinline__ __device__ __host__ void fun1() {}
+
+__attribute__((noinline)) __device__ __host__ void fun2() {}
+
+__attribute__((__noinline__)) __device__ __host__ void fun3() {}
+
+__device__ __host__ void fun4() {}
+
+// CHECK: define{{.*}}@_Z4fun1v{{.*}}#[[ATTR1:[0-9]*]]
+// CHECK: define{{.*}}@_Z4fun2v{{.*}}#[[ATTR1:[0-9]*]]
+// CHECK: define{{.*}}@_Z4fun3v{{.*}}#[[ATTR1:[0-9]*]]
+// CHECK: define{{.*}}@_Z4fun4v{{.*}}#[[ATTR2:[0-9]*]]
+// CHECK: attributes #[[ATTR1]] = {{.*}}noinline
+// CHECK-NOT: attributes #[[ATTR2]] = {{.*}}noinline
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -897,6 +897,15 @@
   }
 }
 
+void Parser::ParseCUDAFunctionAttributes(ParsedAttributes ) {
+  while (Tok.is(tok::kw___noinline__)) {
+IdentifierInfo *AttrName = Tok.getIdentifierInfo();
+SourceLocation AttrNameLoc = ConsumeToken();
+attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
+ ParsedAttr::AS_Keyword);
+  }
+}
+
 void Parser::ParseOpenCLQualifiers(ParsedAttributes ) {
   IdentifierInfo *AttrName = Tok.getIdentifierInfo();
   SourceLocation AttrNameLoc = Tok.getLocation();
@@ -3690,6 +3699,11 @@
   ParseOpenCLKernelAttributes(DS.getAttributes());
   continue;
 
+// CUDA/HIP single token adornments.
+case tok::kw___noinline__:
+  ParseCUDAFunctionAttributes(DS.getAttributes());
+  continue;
+
 // Nullability type specifiers.
 case tok::kw__Nonnull:
 case tok::kw__Nullable:
Index: clang/lib/Basic/IdentifierTable.cpp
===
--- clang/lib/Basic/IdentifierTable.cpp
+++ clang/lib/Basic/IdentifierTable.cpp
@@ -108,6 +108,7 @@
 KEYOPENCLCXX  = 0x40,
 KEYMSCOMPAT   = 0x80,
 KEYSYCL   = 0x100,
+KEYCUDA   = 0x200,
 KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
 KEYALL = (0x1ff & ~KEYNOMS18 &
   ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
@@ -158,6 +159,8 @@
 return KS_Future;
   if (LangOpts.isSYCL() && (Flags & KEYSYCL))
 return KS_Enabled;
+  if (LangOpts.CUDA && (Flags & KEYCUDA))
+return KS_Enabled;
   return KS_Disabled;
 }
 
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2824,6 +2824,7 @@
   void ParseOpenCLKernelAttributes(ParsedAttributes );
   void ParseOpenCLQualifiers(ParsedAttributes );
   void ParseNullabilityTypeSpecifiers(ParsedAttributes );
+  void ParseCUDAFunctionAttributes(ParsedAttributes );
 
   VersionTuple ParseVersionTuple(SourceRange );
   void ParseAvailabilityAttribute(IdentifierInfo ,
Index: 

[PATCH] D124818: [clang-format][NFC] Clean up tryToParseLambdaIntroducer()

2022-05-03 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG397188036d4c: [clang-format][NFC] Clean up 
tryToParseLambdaIntroducer() (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124818

Files:
  clang/lib/Format/UnwrappedLineParser.cpp


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1931,11 +1931,11 @@
 }
 
 bool UnwrappedLineParser::tryToParseLambda() {
+  assert(FormatTok->is(tok::l_square));
   if (!Style.isCpp()) {
 nextToken();
 return false;
   }
-  assert(FormatTok->is(tok::l_square));
   FormatToken  = *FormatTok;
   if (!tryToParseLambdaIntroducer())
 return false;
@@ -2037,20 +2037,20 @@
 
 bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
   const FormatToken *Previous = FormatTok->Previous;
+  const FormatToken *LeftSquare = FormatTok;
+  nextToken();
   if (Previous &&
   (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
  tok::kw_delete, tok::l_square) ||
-   FormatTok->isCppStructuredBinding(Style) || Previous->closesScope() ||
+   LeftSquare->isCppStructuredBinding(Style) || Previous->closesScope() ||
Previous->isSimpleTypeSpecifier())) {
-nextToken();
 return false;
   }
-  nextToken();
   if (FormatTok->is(tok::l_square))
 return false;
   if (FormatTok->is(tok::r_square)) {
 const FormatToken *Next = Tokens->peekNextToken();
-if (Next && Next->is(tok::greater))
+if (Next->is(tok::greater))
   return false;
   }
   parseSquare(/*LambdaIntroducer=*/true);


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1931,11 +1931,11 @@
 }
 
 bool UnwrappedLineParser::tryToParseLambda() {
+  assert(FormatTok->is(tok::l_square));
   if (!Style.isCpp()) {
 nextToken();
 return false;
   }
-  assert(FormatTok->is(tok::l_square));
   FormatToken  = *FormatTok;
   if (!tryToParseLambdaIntroducer())
 return false;
@@ -2037,20 +2037,20 @@
 
 bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
   const FormatToken *Previous = FormatTok->Previous;
+  const FormatToken *LeftSquare = FormatTok;
+  nextToken();
   if (Previous &&
   (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
  tok::kw_delete, tok::l_square) ||
-   FormatTok->isCppStructuredBinding(Style) || Previous->closesScope() ||
+   LeftSquare->isCppStructuredBinding(Style) || Previous->closesScope() ||
Previous->isSimpleTypeSpecifier())) {
-nextToken();
 return false;
   }
-  nextToken();
   if (FormatTok->is(tok::l_square))
 return false;
   if (FormatTok->is(tok::r_square)) {
 const FormatToken *Next = Tokens->peekNextToken();
-if (Next && Next->is(tok::greater))
+if (Next->is(tok::greater))
   return false;
   }
   parseSquare(/*LambdaIntroducer=*/true);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3971880 - [clang-format][NFC] Clean up tryToParseLambdaIntroducer()

2022-05-03 Thread via cfe-commits

Author: owenca
Date: 2022-05-03T11:36:38-07:00
New Revision: 397188036d4cdec7c3bc9236b4a5197232283413

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

LOG: [clang-format][NFC] Clean up tryToParseLambdaIntroducer()

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 520f73ac15eeb..52ce0fff251c2 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1931,11 +1931,11 @@ bool UnwrappedLineParser::tryToParsePropertyAccessor() {
 }
 
 bool UnwrappedLineParser::tryToParseLambda() {
+  assert(FormatTok->is(tok::l_square));
   if (!Style.isCpp()) {
 nextToken();
 return false;
   }
-  assert(FormatTok->is(tok::l_square));
   FormatToken  = *FormatTok;
   if (!tryToParseLambdaIntroducer())
 return false;
@@ -2037,20 +2037,20 @@ bool UnwrappedLineParser::tryToParseLambda() {
 
 bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
   const FormatToken *Previous = FormatTok->Previous;
+  const FormatToken *LeftSquare = FormatTok;
+  nextToken();
   if (Previous &&
   (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
  tok::kw_delete, tok::l_square) ||
-   FormatTok->isCppStructuredBinding(Style) || Previous->closesScope() ||
+   LeftSquare->isCppStructuredBinding(Style) || Previous->closesScope() ||
Previous->isSimpleTypeSpecifier())) {
-nextToken();
 return false;
   }
-  nextToken();
   if (FormatTok->is(tok::l_square))
 return false;
   if (FormatTok->is(tok::r_square)) {
 const FormatToken *Next = Tokens->peekNextToken();
-if (Next && Next->is(tok::greater))
+if (Next->is(tok::greater))
   return false;
   }
   parseSquare(/*LambdaIntroducer=*/true);



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


[clang-tools-extra] 9f38da2 - [pseudo] Implement the GLR parsing algorithm.

2022-05-03 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-05-03T20:25:23+02:00
New Revision: 9f38da258ea75874808e6da756bac831cada180f

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

LOG: [pseudo] Implement the GLR parsing algorithm.

This patch implements a standard GLR parsing algorithm, the
core piece of the pseudoparser.

- it parses preprocessed C++ code, currently it supports correct code
  only and parse them as a translation-unit;
- it produces a forest which stores all possible trees in an efficient
  manner (only a single node being build for per (SymbolID, Token Range));
  no disambiguation yet;

Reland with a fix for g++'s -fpermissive error on previous declaration `GSS& 
GSS;`.

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

Added: 
clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
clang-tools-extra/pseudo/lib/GLR.cpp
clang-tools-extra/pseudo/test/glr.cpp
clang-tools-extra/pseudo/unittests/GLRTest.cpp

Modified: 
clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
clang-tools-extra/pseudo/lib/CMakeLists.txt
clang-tools-extra/pseudo/tool/ClangPseudo.cpp
clang-tools-extra/pseudo/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
index 2b22fd564f742..39b35597ed5e3 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
@@ -157,6 +157,10 @@ class ForestArena {
 return create(ForestNode::Opaque, SID, Start, 0, {});
   }
 
+  ForestNode (tok::TokenKind TK, Token::Index Start) {
+return create(ForestNode::Terminal, tokenSymbol(TK), Start, 0, {});
+  }
+
   size_t nodeCount() const { return NodeCount; }
   size_t bytes() const { return Arena.getBytesAllocated() + sizeof(this); }
 

diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
new file mode 100644
index 0..d66dbe5897762
--- /dev/null
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
@@ -0,0 +1,164 @@
+//===--- GLR.h - Implement a GLR parsing algorithm ---*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This implements a standard Generalized LR (GLR) parsing algorithm.
+//
+// The GLR parser behaves as a normal LR parser until it encounters a conflict.
+// To handle a conflict (where there are multiple actions could perform), the
+// parser will simulate nondeterminism by doing a breadth-first search
+// over all the possibilities.
+//
+// Basic mechanisims of the GLR parser:
+//  - A number of processes are operated in parallel.
+//  - Each process has its own parsing stack and behaves as a standard
+//determinism LR parser.
+//  - When a process encounters a conflict, it will be fork (one for each
+//avaiable action).
+//  - When a process encounters an error, it is abandoned.
+//  - All process are synchronized by the lookahead token: they perfrom shift
+//action at the same time, which means some processes need wait until other
+//processes have performed all reduce actions.
+//
+//===--===//
+
+#ifndef CLANG_PSEUDO_GLR_H
+#define CLANG_PSEUDO_GLR_H
+
+#include "clang-pseudo/Forest.h"
+#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/LRTable.h"
+#include "llvm/Support/Allocator.h"
+#include 
+
+namespace clang {
+namespace pseudo {
+
+// A Graph-Structured Stack efficiently represents all parse stacks of a GLR
+// parser.
+//
+// Each node stores a parse state, the last parsed ForestNode, and the parent
+// node. There may be several heads (top of stack), and the parser operates by:
+// - shift: pushing terminal symbols on top of the stack
+// - reduce: replace N symbols on top of the stack with one nonterminal
+//
+// The structure is a DAG rather than a linear stack:
+// - GLR allows multiple actions (conflicts) on the same head, producing forks
+//   where several nodes have the same parent
+// - The parser merges nodes with the same (state, ForestNode), producing joins
+//   where one node has multiple parents
+//
+// The parser is responsible for creating nodes and keeping track of the set of
+// heads. The GSS class is mostly an arena for them.
+struct GSS {
+  // A node represents a partial parse of the input up to some point.
+  //
+  // It is the equivalent of a frame in an LR parse stack.
+  // Like such a frame, it has an LR parse state and a 

[PATCH] D124866: [CUDA][HIP] support __noinline__ as keyword

2022-05-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added a reviewer: aaron.ballman.
Herald added subscribers: mattd, carlosgalvezp, dexonsmith.
Herald added a project: All.
yaxunl requested review of this revision.

CUDA/HIP programs use `__noinline__` like a keyword e.g.
`__noinline__ void foo() {}` since `__noinline__` is defined
as a macro `__attribute__((noinline))` in CUDA/HIP runtime
header files.

However, gcc and clang supports `__attribute__((__noinline__))`
the same as `__attribute__((noinline))`. Some C++ libraries
use `__attribute__((__noinline__))` in their header files.
When CUDA/HIP programs include such header files,
clang will emit error about invalid attributes.

This patch fixes this issue by supporting `__noinline__` as
a keyword, so that CUDA/HIP runtime could remove
the macro definition.


https://reviews.llvm.org/D124866

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/test/CodeGenCUDA/noinline.cu
  clang/test/SemaCUDA/noinline.cu

Index: clang/test/SemaCUDA/noinline.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/noinline.cu
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=cuda %s
+// RUN: %clang_cc1 -fsyntax-only -verify=cpp -x c++ %s
+
+// cuda-no-diagnostics
+
+__noinline__ void fun1() { } // cpp-error {{unknown type name '__noinline__'}}
+__attribute__((noinline)) void fun2() { }
+__attribute__((__noinline__)) void fun3() { }
Index: clang/test/CodeGenCUDA/noinline.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/noinline.cu
@@ -0,0 +1,27 @@
+// optimization is needed, otherwise by default all functions have noinline.
+
+// RUN: %clang_cc1 -triple nvptx-nvidia-cuda -fcuda-is-device \
+// RUN: -O2 -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device \
+// RUN: -O2 -emit-llvm -o - -x hip %s | FileCheck %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-gnu-linux \
+// RUN: -O2 -emit-llvm -o - %s | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+__noinline__ __device__ __host__ void fun1() {}
+
+__attribute__((noinline)) __device__ __host__ void fun2() {}
+
+__attribute__((__noinline__)) __device__ __host__ void fun3() {}
+
+__device__ __host__ void fun4() {}
+
+// CHECK: define{{.*}}@_Z4fun1v{{.*}}#[[ATTR1:[0-9]*]]
+// CHECK: define{{.*}}@_Z4fun2v{{.*}}#[[ATTR1:[0-9]*]]
+// CHECK: define{{.*}}@_Z4fun3v{{.*}}#[[ATTR1:[0-9]*]]
+// CHECK: define{{.*}}@_Z4fun4v{{.*}}#[[ATTR2:[0-9]*]]
+// CHECK: attributes #[[ATTR1]] = {{.*}}noinline
+// CHECK-NOT: attributes #[[ATTR2]] = {{.*}}noinline
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -897,6 +897,15 @@
   }
 }
 
+void Parser::ParseCUDAFunctionAttributes(ParsedAttributes ) {
+  while (Tok.is(tok::kw___noinline__)) {
+IdentifierInfo *AttrName = Tok.getIdentifierInfo();
+SourceLocation AttrNameLoc = ConsumeToken();
+attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
+ ParsedAttr::AS_Keyword);
+  }
+}
+
 void Parser::ParseOpenCLQualifiers(ParsedAttributes ) {
   IdentifierInfo *AttrName = Tok.getIdentifierInfo();
   SourceLocation AttrNameLoc = Tok.getLocation();
@@ -3690,6 +3699,11 @@
   ParseOpenCLKernelAttributes(DS.getAttributes());
   continue;
 
+// CUDA/HIP single token adornments.
+case tok::kw___noinline__:
+  ParseCUDAFunctionAttributes(DS.getAttributes());
+  continue;
+
 // Nullability type specifiers.
 case tok::kw__Nonnull:
 case tok::kw__Nullable:
Index: clang/lib/Basic/IdentifierTable.cpp
===
--- clang/lib/Basic/IdentifierTable.cpp
+++ clang/lib/Basic/IdentifierTable.cpp
@@ -108,6 +108,7 @@
 KEYOPENCLCXX  = 0x40,
 KEYMSCOMPAT   = 0x80,
 KEYSYCL   = 0x100,
+KEYCUDA   = 0x200,
 KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
 KEYALL = (0x1ff & ~KEYNOMS18 &
   ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
@@ -158,6 +159,8 @@
 return KS_Future;
   if (LangOpts.isSYCL() && (Flags & KEYSYCL))
 return KS_Enabled;
+  if (LangOpts.CUDA && (Flags & KEYCUDA))
+return KS_Enabled;
   return KS_Disabled;
 }
 
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2824,6 +2824,7 @@
   void ParseOpenCLKernelAttributes(ParsedAttributes );
   void ParseOpenCLQualifiers(ParsedAttributes );
   void ParseNullabilityTypeSpecifiers(ParsedAttributes );
+  void ParseCUDAFunctionAttributes(ParsedAttributes );
 
   

[PATCH] D124694: [randstruct] Move initializer check to be more effective

2022-05-03 Thread Bill Wendling via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf2639cf3fe46: [randstruct] Move initializer check to be more 
effective (authored by void).

Changed prior to commit:
  https://reviews.llvm.org/D124694?vs=426149=426788#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124694

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/init-randomized-struct.c


Index: clang/test/Sema/init-randomized-struct.c
===
--- clang/test/Sema/init-randomized-struct.c
+++ clang/test/Sema/init-randomized-struct.c
@@ -1,6 +1,13 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-linux 
-frandomize-layout-seed=1234567890abcdef \
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux 
-frandomize-layout-seed=1234567890abcded \
 // RUN:  -verify -fsyntax-only -Werror %s
 
+// NOTE: The current seed (1234567890abcded) is specifically chosen because it
+// uncovered a bug in diagnostics. With it the randomization of "t9" places the
+// "a" element at the end of the record. When that happens, the clang complains
+// about excessive initializers, which is confusing, because there aren't
+// excessive initializers. It should instead complain about using a
+// non-designated initializer on a raqndomized struct.
+
 // Initializing a randomized structure requires a designated initializer,
 // otherwise the element ordering will be off. The only exceptions to this rule
 // are:
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2170,11 +2170,6 @@
   continue;
 }
 
-if (Field == FieldEnd) {
-  // We've run out of fields. We're done.
-  break;
-}
-
 // Check if this is an initializer of forms:
 //
 //   struct foo f = {};
@@ -2204,6 +2199,11 @@
   break;
 }
 
+if (Field == FieldEnd) {
+  // We've run out of fields. We're done.
+  break;
+}
+
 // We've already initialized a member of a union. We're done.
 if (InitializedSomething && DeclType->isUnionType())
   break;


Index: clang/test/Sema/init-randomized-struct.c
===
--- clang/test/Sema/init-randomized-struct.c
+++ clang/test/Sema/init-randomized-struct.c
@@ -1,6 +1,13 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-linux -frandomize-layout-seed=1234567890abcdef \
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -frandomize-layout-seed=1234567890abcded \
 // RUN:  -verify -fsyntax-only -Werror %s
 
+// NOTE: The current seed (1234567890abcded) is specifically chosen because it
+// uncovered a bug in diagnostics. With it the randomization of "t9" places the
+// "a" element at the end of the record. When that happens, the clang complains
+// about excessive initializers, which is confusing, because there aren't
+// excessive initializers. It should instead complain about using a
+// non-designated initializer on a raqndomized struct.
+
 // Initializing a randomized structure requires a designated initializer,
 // otherwise the element ordering will be off. The only exceptions to this rule
 // are:
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2170,11 +2170,6 @@
   continue;
 }
 
-if (Field == FieldEnd) {
-  // We've run out of fields. We're done.
-  break;
-}
-
 // Check if this is an initializer of forms:
 //
 //   struct foo f = {};
@@ -2204,6 +2199,11 @@
   break;
 }
 
+if (Field == FieldEnd) {
+  // We've run out of fields. We're done.
+  break;
+}
+
 // We've already initialized a member of a union. We're done.
 if (InitializedSomething && DeclType->isUnionType())
   break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f2639cf - [randstruct] Move initializer check to be more effective

2022-05-03 Thread Bill Wendling via cfe-commits

Author: Bill Wendling
Date: 2022-05-03T11:23:12-07:00
New Revision: f2639cf3fe46c30ad450cc2533c81eacd4788c33

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

LOG: [randstruct] Move initializer check to be more effective

If a randomized structure has an initializer with a dedicated
initializer in it, the field initialzed by that dedicated initializer
may end up at the end of the RecordDecl. This however may skip the
random layout initization check.

  struct t {
 int a, b, c, d, e;
  } x = { .a = 2, 4, 5, 6 };

Let's say that "a" is lands as the last field after randomization. The
call to CheckDesignatedInitializer sets the iterator to the end of the
initializer list. During the next iteration of the initializer list
check, it detects that and fails to issue the error about initializing
a randomized struct with non-designated initializer. Instead, it issues
an error about "excess elements in struct initializer", which is
confusing under these circumstances.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/Sema/init-randomized-struct.c

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 79c92bde3b770..016ff5ded25fb 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2170,11 +2170,6 @@ void InitListChecker::CheckStructUnionTypes(
   continue;
 }
 
-if (Field == FieldEnd) {
-  // We've run out of fields. We're done.
-  break;
-}
-
 // Check if this is an initializer of forms:
 //
 //   struct foo f = {};
@@ -2204,6 +2199,11 @@ void InitListChecker::CheckStructUnionTypes(
   break;
 }
 
+if (Field == FieldEnd) {
+  // We've run out of fields. We're done.
+  break;
+}
+
 // We've already initialized a member of a union. We're done.
 if (InitializedSomething && DeclType->isUnionType())
   break;

diff  --git a/clang/test/Sema/init-randomized-struct.c 
b/clang/test/Sema/init-randomized-struct.c
index a708d6a0cfd05..d421597fa522f 100644
--- a/clang/test/Sema/init-randomized-struct.c
+++ b/clang/test/Sema/init-randomized-struct.c
@@ -1,6 +1,13 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-linux 
-frandomize-layout-seed=1234567890abcdef \
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux 
-frandomize-layout-seed=1234567890abcded \
 // RUN:  -verify -fsyntax-only -Werror %s
 
+// NOTE: The current seed (1234567890abcded) is specifically chosen because it
+// uncovered a bug in diagnostics. With it the randomization of "t9" places the
+// "a" element at the end of the record. When that happens, the clang complains
+// about excessive initializers, which is confusing, because there aren't
+// excessive initializers. It should instead complain about using a
+// non-designated initializer on a raqndomized struct.
+
 // Initializing a randomized structure requires a designated initializer,
 // otherwise the element ordering will be off. The only exceptions to this rule
 // are:



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


[PATCH] D123009: [Sema] Enum conversion warning when one signed and other unsigned.

2022-05-03 Thread Micah Weston via Phabricator via cfe-commits
red1bluelost updated this revision to Diff 426786.
red1bluelost added a comment.

Adds regression tests for enum to int sign conversion warnings and notes the
changes in the release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123009

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/enum-enum-conversion.c
  clang/test/Sema/enum-sign-conversion.c

Index: clang/test/Sema/enum-sign-conversion.c
===
--- clang/test/Sema/enum-sign-conversion.c
+++ clang/test/Sema/enum-sign-conversion.c
@@ -1,13 +1,51 @@
-// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -verify -DUNSIGNED -Wsign-conversion %s
-// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -verify -Wsign-conversion %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wsign-conversion -verify=unsigned,both %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wconversion -verify=unsigned,both %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -verify -Wsign-conversion -verify=signed,both %s
 
 // PR35200
-enum X { A,B,C};
+enum X { A,
+ B,
+ C };
 int f(enum X x) {
-#ifdef UNSIGNED
-  return x; // expected-warning {{implicit conversion changes signedness: 'enum X' to 'int'}}
-#else
-  // expected-no-diagnostics
-  return x;
-#endif
+  return x; // unsigned-warning {{implicit conversion changes signedness: 'enum X' to 'int'}}
+}
+
+// Signed enums
+enum SE1 { N1 = -1 };
+enum SE2 { N2 = -2 };
+// Unsigned unums
+enum UE1 { P1 };
+enum UE2 { P2 };
+
+// ensure no regression with enum to sign (related to enum-enum-conversion.c)
+int f1(enum UE1 E) {
+  return E; // unsigned-warning {{implicit conversion changes signedness: 'enum UE1' to 'int'}}
+}
+
+enum UE1 f2(int E) {
+  return E; // unsigned-warning {{implicit conversion changes signedness: 'int' to 'enum UE1'}}
+}
+
+int f3(enum SE1 E) {
+  return E; // shouldn't warn
+}
+
+enum SE1 f4(int E) {
+  return E; // shouldn't warn
+}
+
+unsigned f5(enum UE1 E) {
+  return E; // signed-warning {{implicit conversion changes signedness: 'enum UE1' to 'unsigned int'}}
+}
+
+enum UE1 f6(unsigned E) {
+  return E; // signed-warning {{implicit conversion changes signedness: 'unsigned int' to 'enum UE1'}}
+}
+
+unsigned f7(enum SE1 E) {
+  return E; // both-warning {{implicit conversion changes signedness: 'enum SE1' to 'unsigned int'}}
+}
+
+enum SE1 f8(unsigned E) {
+  return E; // both-warning {{implicit conversion changes signedness: 'unsigned int' to 'enum SE1'}}
 }
Index: clang/test/Sema/enum-enum-conversion.c
===
--- /dev/null
+++ clang/test/Sema/enum-enum-conversion.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wenum-conversion -verify %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wconversion -verify %s
+
+// Signed enums
+enum SE1 { N1 = -1 };
+enum SE2 { N2 = -2 };
+// Unsigned unums
+enum UE1 { P1 };
+enum UE2 { P2 };
+
+enum UE2 f1(enum UE1 E) {
+  return E; // expected-warning {{implicit conversion from enumeration type 'enum UE1' to different enumeration type 'enum UE2'}}
+}
+
+enum SE1 f2(enum UE1 E) {
+  return E; // expected-warning {{implicit conversion from enumeration type 'enum UE1' to different enumeration type 'enum SE1'}}
+}
+
+enum UE1 f3(enum SE1 E) {
+  return E; // expected-warning {{implicit conversion from enumeration type 'enum SE1' to different enumeration type 'enum UE1'}}
+}
+
+enum SE2 f4(enum SE1 E) {
+  return E; // expected-warning {{implicit conversion from enumeration type 'enum SE1' to different enumeration type 'enum SE2'}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13534,9 +13534,10 @@
 // Fall through for non-constants to give a sign conversion warning.
   }
 
-  if ((TargetRange.NonNegative && !LikelySourceRange.NonNegative) ||
-  (!TargetRange.NonNegative && LikelySourceRange.NonNegative &&
-   LikelySourceRange.Width == TargetRange.Width)) {
+  if ((!isa(Target) || !isa(Source)) &&
+  ((TargetRange.NonNegative && !LikelySourceRange.NonNegative) ||
+   (!TargetRange.NonNegative && LikelySourceRange.NonNegative &&
+LikelySourceRange.Width == TargetRange.Width))) {
 if (S.SourceMgr.isInSystemMacro(CC))
   return;
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -110,6 +110,8 @@
   `_.
 - ``-Wunused-but-set-variable`` now also warns if the variable is only used
   by unary operators.
+- ``-Wenum-conversion`` now warns on conversion of signed enum to 

[PATCH] D124674: [analyzer] Indicate if a parent state is infeasible

2022-05-03 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 426785.
martong added a comment.

- Add LLVM_UNLIKELY


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124674

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/ProgramState.cpp
  clang/test/Analysis/infeasible-sink.c

Index: clang/test/Analysis/infeasible-sink.c
===
--- /dev/null
+++ clang/test/Analysis/infeasible-sink.c
@@ -0,0 +1,80 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -verify
+
+// Here we test that if it turns out that the parent state is infeasible then
+// both children States (more precisely the ExplodedNodes) are marked as a
+// Sink.
+// We rely on existing defects of the underlying constraint solver. However,
+// in the future we might strengthen the solver to discover the infeasibility
+// right when we create the parent state. At that point some of these tests
+// will fail, and either we shall find another solver weakness to have the test
+// case functioning, or we shall simply remove that.
+
+void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(int);
+
+void test1(int x) {
+  if (x * x != 4)
+return;
+  if (x < 0 || x > 1)
+return;
+
+  // { x^2 == 4 and x:[0,1] }
+  // This state is already infeasible.
+
+  // Perfectly constraining 'x' will trigger constant folding,
+  // when we realize we were already infeasible.
+  // The same happens for the 'else' branch.
+  if (x == 0) {
+clang_analyzer_warnIfReached(); // no-warning
+  } else {
+clang_analyzer_warnIfReached(); // no-warning
+  }
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x;
+}
+
+int a, b, c, d, e;
+void test2() {
+
+  if (a == 0)
+return;
+
+  if (e != c)
+return;
+
+  d = e - c;
+  b = d;
+  a -= d;
+
+  if (a != 0)
+return;
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+
+  /* The BASELINE passes these checks ('wrning' is used to avoid lit to match)
+  // The parent state is already infeasible, look at this contradiction:
+  clang_analyzer_eval(b > 0);  // expected-wrning{{FALSE}}
+  clang_analyzer_eval(b <= 0); // expected-wrning{{FALSE}}
+  // Crashes with expensive checks.
+  if (b > 0) {
+clang_analyzer_warnIfReached(); // no-warning, OK
+return;
+  }
+  // Should not be reachable.
+  clang_analyzer_warnIfReached(); // expected-wrning{{REACHABLE}}
+  */
+
+  // The parent state is already infeasible, but we realize that only if b is
+  // constrained.
+  clang_analyzer_eval(b > 0);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b <= 0); // expected-warning{{UNKNOWN}}
+  if (b > 0) {
+clang_analyzer_warnIfReached(); // no-warning
+return;
+  }
+  clang_analyzer_warnIfReached(); // no-warning
+}
Index: clang/lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ clang/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -55,7 +55,7 @@
 
 ProgramState::ProgramState(const ProgramState )
 : stateMgr(RHS.stateMgr), Env(RHS.Env), store(RHS.store), GDM(RHS.GDM),
-  refCount(0) {
+  Infeasible(RHS.Infeasible), refCount(0) {
   stateMgr->getStoreManager().incrementReferenceCount(store);
 }
 
@@ -429,6 +429,12 @@
   return getStateManager().getPersistentState(NewSt);
 }
 
+ProgramStateRef ProgramState::cloneAsInfeasible() const {
+  ProgramState NewSt(*this);
+  NewSt.Infeasible = true;
+  return getStateManager().getPersistentState(NewSt);
+}
+
 void ProgramState::setStore(const StoreRef ) {
   Store newStoreStore = newStore.getStore();
   if (newStoreStore)
Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -41,3 +41,32 @@
 return ConditionTruthVal(true);
   return {};
 }
+
+ConstraintManager::ProgramStatePair
+ConstraintManager::assumeDual(ProgramStateRef State, DefinedSVal Cond) {
+  ProgramStateRef StTrue = assume(State, Cond, true);
+
+  if (!StTrue) {
+ProgramStateRef StFalse = assume(State, Cond, false);
+if (LLVM_UNLIKELY(!StFalse)) { // both infeasible
+  ProgramStateRef StInfeasible = State->cloneAsInfeasible();
+  assert(StInfeasible->isInfeasible());
+  // Checkers might rely on the API contract that both returned states
+  // cannot be null. Thus, we return StInfeasible for both branches because
+  // it might 

[PATCH] D124842: [NFC][CUDA][HIP] rework mangling number for aux target

2022-05-03 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: clang/lib/AST/ASTContext.cpp:11770-11778
+  if (!LangOpts.CUDA || LangOpts.CUDAIsDevice) {
+assert(!ForAuxTarget && "Only CUDA/HIP host compilation supports mangling "
+"number for aux target");
 return Res;
+  }
 
   // CUDA/HIP host compilation encodes host and device mangling numbers

Nit: I'd rephrase it as :
```
if (LangOpts.CUDA && !LangOpts.CUDAIsDevice) {
Res = ForAuxTarget ? Res >> 16 : Res & 0x; 
} else {
assert(!ForAuxTarget && "Only CUDA/HIP host compilation supports mangling 
number for aux target");
}
return Res > 1 ? Res : 1;
```


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

https://reviews.llvm.org/D124842

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


[PATCH] D124807: [clang][dataflow] Avoid assert for invalid cast to BoolValue

2022-05-03 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua updated this revision to Diff 426783.
li.zhe.hua added a comment.

Handle FullExprs in the transfer function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124807

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

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -1152,4 +1152,39 @@
   });
 }
 
+// FIXME: Remove this test once it provides no additional test coverage.
+TEST_F(FlowConditionTest, DoesNotAssertForImplicitCastToBool) {
+  std::string Code = R"(
+void target(int *Ptr) {
+  bool Foo = false;
+  if (Ptr) {
+Foo = true;
+/*[[p1]]*/
+  }
+
+  (void)0;
+  /*[[p2]]*/
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p2", _), Pair("p1", _)));
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const Environment  = Results[1].second.Env;
+auto  =
+*cast(Env1.getValue(*FooDecl, SkipPast::Reference));
+EXPECT_TRUE(Env1.flowConditionImplies(FooVal1));
+
+const Environment  = Results[0].second.Env;
+auto  =
+*cast(Env2.getValue(*FooDecl, SkipPast::Reference));
+EXPECT_FALSE(Env2.flowConditionImplies(FooVal2));
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -77,26 +77,26 @@
   : StmtToEnv(StmtToEnv), Env(Env), BlockSuccIdx(BlockSuccIdx) {}
 
   void VisitIfStmt(const IfStmt *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = S->getCond()->IgnoreParens();
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
 
   void VisitWhileStmt(const WhileStmt *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = S->getCond()->IgnoreParens();
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
 
   void VisitBinaryOperator(const BinaryOperator *S) {
 assert(S->getOpcode() == BO_LAnd || S->getOpcode() == BO_LOr);
-auto *LHS = S->getLHS()->IgnoreParenImpCasts();
+auto *LHS = S->getLHS()->IgnoreParens();
 assert(LHS != nullptr);
 extendFlowCondition(*LHS);
   }
 
   void VisitConditionalOperator(const ConditionalOperator *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = S->getCond()->IgnoreParens();
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -251,6 +251,18 @@
 }
   }
 
+  void VisitFullExpr(const FullExpr *S) {
+assert(S->getSubExpr() != nullptr);
+const Expr *SubExpr = S->getSubExpr()->IgnoreParens();
+assert(SubExpr != nullptr);
+
+auto *SubExprLoc = Env.getStorageLocation(*SubExpr, SkipPast::None);
+if (SubExprLoc == nullptr)
+  return;
+
+Env.setStorageLocation(*S, *SubExprLoc);
+  }
+
   void VisitUnaryOperator(const UnaryOperator *S) {
 // The CFG does not contain `ParenExpr` as top-level statements in basic
 // blocks, however sub-expressions can still be of that type.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119147: [AIX][clang][driver] Check the command string to the linker for exportlist opts and

2022-05-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:196
+const char *CreateExportListExec = Args.MakeArgString(
+llvm::sys::path::parent_path(ToolChain.getDriver().ClangExecutable) +
+"/llvm-nm");

Use sys::path::append



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:200
+
+auto CreateExportListPath =
+C.getDriver().GetTemporaryPath("CreateExportList", "exp");

https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:205
+
+for (const auto  : Inputs) {
+  if (II.isFilename())

omit braces



Comment at: clang/test/Driver/aix-ld.c:611
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:-shared \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \

You may pack more options on one line.
The current style may make the file unnecessarily long.



Comment at: clang/test/Driver/aix-ld.c:985
+// CHECK-LD64-SHARED-EXPFULL: "-bM:SRE"
+// CHECK-LD64-SHARED-EXPFULL: "-bnoentry"
+// CHECK-LD64-SHARED-EXPFULL: "-b64"

If these options are actually adjacent, check them on the same line to make the 
test more strict: you can catch issues if new options are somehow inserted in 
between.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119147

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


[PATCH] D124674: [analyzer] Indicate if a parent state is infeasible

2022-05-03 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp:51
+ProgramStateRef StFalse = assume(State, Cond, false);
+if (!StFalse) { // both infeasible
+  ProgramStateRef Infeasible = State->cloneAsInfeasible();

martong wrote:
> martong wrote:
> > martong wrote:
> > > steakhal wrote:
> > > > Should we mark this `LLVM_UNLIKELY(cond)`?
> > > > I would expect this function to be quite hot, and infeasible states 
> > > > rare.
> > > > 
> > > > Could we measure this one?
> > > Yes, it could be.
> > > 
> > > Let me come back with some measurement results soon. I am going to use 
> > > llvm statistics macros to measure this, but that makes sense on top of 
> > > D124758
> > This is what I use for the measurement, stay tuned for the results.
> > ```
> > diff --git a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp 
> > b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
> > index ef98ed7d36e9..82097d67ec0f 100644
> > --- a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
> > +++ b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
> > @@ -16,10 +16,16 @@
> >  #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
> >  #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
> >  #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
> > +#include "llvm/ADT/Statistic.h"
> > 
> >  using namespace clang;
> >  using namespace ento;
> > 
> > +#define DEBUG_TYPE "CoreEngine"
> > +
> > +STATISTIC(NumInfeasible, "The # of infeasible states");
> > +STATISTIC(NumFeasible, "The # of feasible states");
> > +
> >  ConstraintManager::~ConstraintManager() = default;
> > 
> >  static DefinedSVal getLocFromSymbol(const ProgramStateRef ,
> > @@ -51,16 +57,20 @@ ConstraintManager::assumeDual(ProgramStateRef State, 
> > DefinedSVal Cond) {
> >  if (!StFalse) { // both infeasible
> >ProgramStateRef Infeasible = State->cloneAsInfeasible();
> >assert(Infeasible->isInfeasible());
> > +  ++NumInfeasible;
> >return ProgramStatePair(Infeasible, Infeasible);
> >  }
> > +++NumFeasible;
> >  return ProgramStatePair(nullptr, StFalse);
> >}
> > 
> >ProgramStateRef StFalse = assumeInternal(State, Cond, false);
> >if (!StFalse) {
> > +++NumFeasible;
> >  return ProgramStatePair(StTrue, nullptr);
> >}
> > 
> > +  ++NumFeasible;
> >return ProgramStatePair(StTrue, StFalse);
> >  }
> > ```
> Ups, the purpose of the measure is to determine if UNLIKELY is justified, so 
> this diff seems better, restarted the measurement with it.
> ```
> --- a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
> +++ b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
> @@ -16,10 +16,16 @@
>  #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
>  #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
>  #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
> +#include "llvm/ADT/Statistic.h"
> 
>  using namespace clang;
>  using namespace ento;
> 
> +#define DEBUG_TYPE "CoreEngine"
> +
> +STATISTIC(NumInfeasible, "The # of infeasible states");
> +STATISTIC(NumFeasible, "The # of feasible states");
> +
>  ConstraintManager::~ConstraintManager() = default;
> 
>  static DefinedSVal getLocFromSymbol(const ProgramStateRef ,
> @@ -51,8 +57,10 @@ ConstraintManager::assumeDual(ProgramStateRef State, 
> DefinedSVal Cond) {
>  if (!StFalse) { // both infeasible
>ProgramStateRef Infeasible = State->cloneAsInfeasible();
>assert(Infeasible->isInfeasible());
> +  ++NumInfeasible;
>return ProgramStatePair(Infeasible, Infeasible);
>  }
> +++NumFeasible;
>  return ProgramStatePair(nullptr, StFalse);
>}
> 
> ```
This is indeed UNLIKELY. Seems like a good upper-bound for the ratio's order of 
magnitude is around 1000 / 10 million i.e. 0.0001.
{F22964634}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124674

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


[PATCH] D124807: [clang][dataflow] Avoid assert for invalid cast to BoolValue

2022-05-03 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:78
+/// and integers in the framework.
+static const Expr *ignoreParenImpCastsExceptToBool(const Expr *E) {
+  const Expr *LastE = nullptr;

xazax.hun wrote:
> li.zhe.hua wrote:
> > sgatev wrote:
> > > I don't recall why we need to ignore implicit casts here. Can't we ignore 
> > > parens and rely on the built-in transfer function, possibly adding 
> > > handling of some missing casts there? 
> > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L192
> > If we only ignore parens, a test in the optional checker tests begins to 
> > fail, specifically `UncheckedOptionalAccessTest.ValueOrComparison`. The 
> > missing "cast" is an `ExprWithCleanups`. I didn't know how to deal with 
> > that, so this patch just working around the assert.
> In general, I prefer to handle as much as possible with transfer functions 
> and skip as little as possible in the AST. We might skip `ExprWithCleanups` 
> nodes today, but we will need them tomorrow to properly model where certain 
> destructors are being invoked. 
We already have `skipExprWithCleanups` [1]. I wonder if it makes sense to 
replace that with a simple transfer function like the one for the `CK_NoOp` 
implicit cast. Would that solve the problem and remove the need for 
`ignoreParenImpCastsExceptToBool`? In the future we might replace that transfer 
function with a proper one, as Gábor suggested.

[1] 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L36


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124807

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


[PATCH] D122424: [clang] [Driver] Add clang's relative `../lib` path only when in build tree

2022-05-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay commandeered this revision.
MaskRay edited reviewers, added: mgorny; removed: MaskRay.
MaskRay added a comment.

Obsoleted by D122444  (Hope I am not mistaken)


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

https://reviews.llvm.org/D122424

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


[PATCH] D124736: [CodeGen] Use ABI alignment for placement new

2022-05-03 Thread Daniel Bertalan via Phabricator via cfe-commits
BertalanD added a comment.

In D124736#3485128 , @rjmccall wrote:

> It should probably be the ABI alignment in all cases; I think the preferred 
> alignment is just supposed to be used to opportunistically over-align things 
> like e.g. local variables, which doesn't seem relevant for the ABI code 
> involving a call to `operator new`.

Right, that makes sense. I'll update this patch tomorrow. Thanks for the review 
:)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124736

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


[PATCH] D124211: Add __builtin_kcfi_call_unchecked

2022-05-03 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen abandoned this revision.
samitolvanen added a comment.

OK, I confirmed that we won't need this after all. I'll abandon this patch and 
revisit if it becomes necessary in future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124211

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


[PATCH] D124534: [clang] Add a diagnostic for line directive of a gnu extension

2022-05-03 Thread Ken Matsui via Phabricator via cfe-commits
ken-matsui added inline comments.



Comment at: clang/lib/Lex/PPDirectives.cpp:1356
+
+PP.Diag(FlagTok, diag::ext_pp_gnu_line_directive);
   } else if (FlagVal == 2) {

aaron.ballman wrote:
> ken-matsui wrote:
> > aaron.ballman wrote:
> > > ken-matsui wrote:
> > > > aaron.ballman wrote:
> > > > > I speculate that this change is wrong.
> > > > > 
> > > > > The goal here is to diagnose any time there's a GNU line marker and 
> > > > > now we're only trigging the diagnostic when the line marker's value 
> > > > > is 1; that misses diagnostics when the marker value is something else.
> > > > > 
> > > > > That's why I suggested warning each place we return `false` from this 
> > > > > function -- those are the situations when the line marker is 
> > > > > syntactically correct and we're going to make use of it in the 
> > > > > caller. (We don't want to warn about use of a line marker when we're 
> > > > > going to generate an error anyway.)
> > > > @aaron.ballman 
> > > > 
> > > > Thank you!
> > > > 
> > > > Just to confirm, do I need to remove the call of `Diag` after 
> > > > `GetLineValue` and put `Diag`s into all branches of returning `false` 
> > > > in this function?
> > > > If so, I think putting `Diag` after the call of this function would be 
> > > > better.
> > > > If so, I think putting Diag after the call of this function would be 
> > > > better.
> > > 
> > > You are correct and I agree, good suggestion!
> > @aaron.ballman 
> > Thank you for your response!
> > 
> > I've updated the code as mentioned, but a bunch of other tests with the 
> > `-pedantic` option failed as the following warnings:
> > 
> > ```
> >  TEST 'Clang :: CXX/expr/expr.const/p2-0x.cpp' FAILED 
> > 
> > Script:
> > --
> > : 'RUN: at line 1';   /tmp/llvm/llvm-project/build/bin/clang -cc1 
> > -internal-isystem /tmp/llvm/llvm-project/build/lib/clang/15.0.0/include 
> > -nostdsysteminc -fsyntax-only -std=c++11 -pedantic -verify=expected,cxx11 
> > -fcxx-exceptions 
> > /tmp/llvm/llvm-project/clang/test/CXX/expr/expr.const/p2-0x.cpp 
> > -fconstexpr-depth 128 -triple i686-pc-linux-gnu
> > : 'RUN: at line 2';   /tmp/llvm/llvm-project/build/bin/clang -cc1 
> > -internal-isystem /tmp/llvm/llvm-project/build/lib/clang/15.0.0/include 
> > -nostdsysteminc -fsyntax-only -std=c++2a -pedantic -verify=expected,cxx20 
> > -fcxx-exceptions 
> > /tmp/llvm/llvm-project/clang/test/CXX/expr/expr.const/p2-0x.cpp 
> > -fconstexpr-depth 128 -triple i686-pc-linux-gnu
> > --
> > Exit Code: 1
> > 
> > Command Output (stderr):
> > --
> > error: 'warning' diagnostics seen but not expected: 
> >   Line 0: this style of line directive is a GNU extension
> >   Line 0: this style of line directive is a GNU extension
> > 2 errors generated.
> > 
> > ...
> > ```
> > 
> > I personally think it would be preferable if the only change of tests would 
> > be `line-directive.c`.
> > So, how about reducing `Diag` calls until the warning doesn't spill over 
> > into other tests?
> > I personally think it would be preferable if the only change of tests would 
> > be line-directive.c.
> > So, how about reducing Diag calls until the warning doesn't spill over into 
> > other tests?
> 
> No, this is expected. We're adding a diagnostic where there wasn't one 
> previously, so some files are going to get caught by that. You can either add 
> the `// expected-warning {{}}` comments to those lines, or if the test has a 
> lot of those lines but isn't really specific to line markers (it just happens 
> to use them to test other functionality) you can disable the diagnostic for 
> that test with `-Wno-gnu-line-marker`.
Ah, I see. I'm going to work on it. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124534

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


[PATCH] D124666: In MSVC compatibility mode, handle unqualified templated base class initialization

2022-05-03 Thread Fred Tingaud via Phabricator via cfe-commits
frederic-tingaud-sonarsource updated this revision to Diff 426759.
frederic-tingaud-sonarsource added a comment.

Added two similar names in the tests, to try to trick the typo correction.


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

https://reviews.llvm.org/D124666

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaTemplate/ms-unqualified-base-class.cpp

Index: clang/test/SemaTemplate/ms-unqualified-base-class.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/ms-unqualified-base-class.cpp
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -std=c++17 -fms-compatibility -fsyntax-only -verify=before,expected %s
+// RUN: %clang_cc1 -std=c++17 -fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify=before,expected %s
+// RUN: %clang_cc1 -std=c++20 -fms-compatibility -fsyntax-only -verify=after,expected %s
+// RUN: %clang_cc1 -std=c++20 -fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify=after,expected %s
+
+template 
+class Base {
+};
+
+template 
+class Based {}; // Trying to trick the typo detection
+
+template 
+class Derived : public Base {
+public:
+  // after-error@+1 {{member initializer 'Base' does not name a non-static data member or base class}}
+  Derived() : Base() {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
+private:
+  int Baze; // Trying to trick the typo detection
+};
+
+template  struct AggregateBase {
+  T i;
+};
+
+template 
+struct AggregateDerived : public AggregateBase {
+  int i;
+
+  // after-error@+1 {{member initializer 'AggregateBase' does not name a non-static data member or base class}}
+  AggregateDerived(T j) : AggregateBase{4}, i{j} {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
+  int f() {
+return i + AggregateBase::i; // expected-warning {{use of undeclared identifier 'AggregateBase'; unqualified lookup into dependent bases of class template 'AggregateDerived' is a Microsoft extension}}
+  }
+};
+
+template  struct MultiTypesBase {
+};
+
+template 
+struct MultiTypesDerived : public MultiTypesBase {
+  // after-error@+1 {{member initializer 'MultiTypesBase' does not name a non-static data member or base class}}
+  MultiTypesDerived() : MultiTypesBase{} {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
+};
+
+template  struct IntegerBase {
+};
+
+template 
+struct IntegerDerived : public IntegerBase {
+  // after-error@+1 {{member initializer 'IntegerBase' does not name a non-static data member or base class}}
+  IntegerDerived() : IntegerBase{} {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
+};
+
+template  struct ConformingBase {
+  T i;
+};
+
+template 
+struct ConformingDerived : public ConformingBase {
+  int i;
+
+  ConformingDerived(T j) : ConformingBase{4}, i{j} {}
+  int f() {
+return i + ConformingBase::i;
+  }
+};
+
+int main() {
+  int I;
+  Derived t;
+
+  AggregateDerived AD{2};
+  AD.AggregateBase::i = 3;
+  I = AD.f();
+
+  MultiTypesDerived MTD;
+
+  IntegerDerived<4> ID;
+
+  ConformingDerived CD{2};
+  I = CD.f();
+
+  return I;
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -4345,6 +4345,15 @@
 }
   }
 
+  if (getLangOpts().MSVCCompat && !getLangOpts().CPlusPlus20) {
+auto UnqualifiedBase = R.getAsSingle();
+if (UnqualifiedBase) {
+  Diag(IdLoc, diag::ext_unqualified_base_class)
+  << SourceRange(IdLoc, Init->getSourceRange().getEnd());
+  BaseType = UnqualifiedBase->getInjectedClassNameSpecialization();
+}
+  }
+
   if (!TyD && BaseType.isNull()) {
 Diag(IdLoc, diag::err_mem_init_not_member_or_class)
   << MemberOrBase << SourceRange(IdLoc,Init->getSourceRange().getEnd());
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5508,6 +5508,9 @@
 def ext_found_later_in_class : ExtWarn<
   "use of member %0 before its declaration is a Microsoft extension">,
   InGroup;
+def ext_unqualified_base_class : ExtWarn<
+  "unqualified base initializer of class templates is a Microsoft extension">,
+  InGroup;
 def note_dependent_member_use : Note<
   "must qualify identifier to find this declaration in dependent base class">;
 def err_not_found_by_two_phase_lookup : Error<"call to function %0 that is neither "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119147: [AIX][clang][driver] Check the command string to the linker for exportlist opts and

2022-05-03 Thread Steven Wan via Phabricator via cfe-commits
stevewan accepted this revision.
stevewan added a comment.
This revision is now accepted and ready to land.

LGTM other than some nits.




Comment at: clang/lib/Driver/Job.cpp:361
+
+  if (!RedirectFiles.empty()) {
+std::vector> RedirectFilesOptional;





Comment at: clang/test/Driver/aix-ld.c:675-676
+// CHECK-LD32-SHARED-EXPORTS-NOT: "{{.*}}llvm-nm"
+// CHECK-LD32-SHARED-EXPORTS-NOT: "-X"
+// CHECK-LD32-SHARED-EXPORTS-NOT: "32"
+// CHECK-LD32-SHARED-EXPORTS: "{{.*}}ld{{(.exe)?}}"

And please keep this consistent across the tests.



Comment at: clang/test/Driver/aix-ld.c:776-777
+// CHECK-LD64-SHARED-EXPORTS-NOT: "{{.*}}llvm-nm"
+// CHECK-LD64-SHARED-EXPORTS-NOT: "-X"
+// CHECK-LD64-SHARED-EXPORTS-NOT: "64"
+// CHECK-LD64-SHARED-EXPORTS: "{{.*}}ld{{(.exe)?}}"

Ditto.



Comment at: clang/test/Driver/aix-ld.c:826-827
+// CHECK-LD64-SHARED-EXPORTS-ALT-NOT: "{{.*}}llvm-nm"
+// CHECK-LD64-SHARED-EXPORTS-ALT-NOT: "-X"
+// CHECK-LD64-SHARED-EXPORTS-ALT-NOT: "64"
+// CHECK-LD64-SHARED-EXPORTS-ALT: "{{.*}}ld{{(.exe)?}}"

Ditto.



Comment at: clang/test/Driver/aix-ld.c:903-904
+// CHECK-LD64-SHARED-EXPALL-NOT: "{{.*}}llvm-nm"
+// CHECK-LD64-SHARED-EXPALL-NOT: "-X"
+// CHECK-LD64-SHARED-EXPALL-NOT: "64"
+// CHECK-LD64-SHARED-EXPALL: "{{.*}}ld{{(.exe)?}}"

Ditto.



Comment at: clang/test/Driver/aix-ld.c:981-982
+// CHECK-LD64-SHARED-EXPFULL-NOT: "{{.*}}llvm-nm"
+// CHECK-LD64-SHARED-EXPFULL-NOT: "-X"
+// CHECK-LD64-SHARED-EXPFULL-NOT: "64"
+// CHECK-LD64-SHARED-EXPFULL: "{{.*}}ld{{(.exe)?}}"

Ditto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119147

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


[PATCH] D124790: [HLSL] Enable half type for hlsl.

2022-05-03 Thread Xiang Li via Phabricator via cfe-commits
python3kgae marked 3 inline comments as done.
python3kgae added inline comments.



Comment at: clang/lib/Basic/LangOptions.cpp:197
 
-  // OpenCL has half keyword
-  Opts.Half = Opts.OpenCL;
+  // OpenCL and HLSL have half keyword
+  Opts.Half = Opts.OpenCL || Opts.HLSL;

aaron.ballman wrote:
> Shouldn't this be looking for HLSL 2018? Or shader model 6.2?
half keyword is always available.
Without enable_16bit_types, half will be like using half=float.
With enable_16bit_types, half will be real half.

The check for HLSL 2018 and shader model 6.2 will be in another PR, still WIP. 
I'll add FIXME about it.



Comment at: clang/lib/Basic/Targets/DirectX.h:61
   }
-
+  bool useFP16ConversionIntrinsics() const override { return false; }
   void getTargetDefines(const LangOptions ,

aaron.ballman wrote:
> Should this be tied to the `Half` language option?
We don't want to conversion FP16, with or without enable_16bit_types.
With enable_16bit_types, it is half, don't need conversion.
Without enable_16bit_types, it will be a float, don't need conversion either.



Comment at: clang/lib/Sema/SemaType.cpp:1514
+// For HLSL, when not enable native half type, half will be treat as float.
+if (S.getLangOpts().HLSL && !S.getLangOpts().NativeHalfType)
+  Result = Context.FloatTy;

aaron.ballman wrote:
> This change seems wrong to me -- if the half type isn't supported, how does 
> the user spell the type such that we can even get here?
Half keyword is always available for hlsl.
When enable_16bit_types, NativeHalfType will be true, half will be a real half.
When not enable_16bit_types, NativeHalfType will be false, half will be float.




Comment at: clang/test/CodeGenHLSL/half.hlsl:15
+  return a+b;
+}

aaron.ballman wrote:
> FWIW, this test seems to be failing precommit CI.
> 
> We should also have tests for the new driver flag and Sema tests showing that 
> you can't spell `half` in unsupported HLSL modes.
I think the issue is this test require build DirectX backend target.
I'll change it to work without DirectX backend target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124790

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


[PATCH] D124807: [clang][dataflow] Avoid assert for invalid cast to BoolValue

2022-05-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:78
+/// and integers in the framework.
+static const Expr *ignoreParenImpCastsExceptToBool(const Expr *E) {
+  const Expr *LastE = nullptr;

li.zhe.hua wrote:
> sgatev wrote:
> > I don't recall why we need to ignore implicit casts here. Can't we ignore 
> > parens and rely on the built-in transfer function, possibly adding handling 
> > of some missing casts there? 
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L192
> If we only ignore parens, a test in the optional checker tests begins to 
> fail, specifically `UncheckedOptionalAccessTest.ValueOrComparison`. The 
> missing "cast" is an `ExprWithCleanups`. I didn't know how to deal with that, 
> so this patch just working around the assert.
In general, I prefer to handle as much as possible with transfer functions and 
skip as little as possible in the AST. We might skip `ExprWithCleanups` nodes 
today, but we will need them tomorrow to properly model where certain 
destructors are being invoked. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124807

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


[PATCH] D124666: In MSVC compatibility mode, handle unqualified templated base class initialization

2022-05-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk requested changes to this revision.
rnk added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:4310-4311
 
   // If no results were found, try to correct typos.
   TypoCorrection Corr;
   MemInitializerValidatorCCC CCC(ClassDecl);

We have to make sure our MS compatibility logic fires *before* we try to 
correct typos. It's currently a big issue that we don't. You can try adjusting 
your test case by adding a similarly named class like `Baze` and see if you 
still get the desired behavior.

See this old issue from 2014:
https://github.com/llvm/llvm-project/issues/20623


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

https://reviews.llvm.org/D124666

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


[PATCH] D120495: [clang][dataflow] Add transfer functions for structured bindings

2022-05-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:80
+///
+/// FIXME: Consider adding support for structured bindings to the CFG builder.
+class DecompositionVisitor : public ConstStmtVisitor {

sgatev wrote:
> xazax.hun wrote:
> > Did you look into how hard would it be to add structured bindings to the 
> > CFG builder? If the effort is comparable to this patch (and not 
> > significantly bigger), it might be better to do that work instead of 
> > spending effort on some temporary workaround. What do you think?
> Circling back to this after a while. I believe we explored changing the CFG 
> briefly, but don't have a fully fleshed out proposal for it. I recently 
> noticed 
> https://discourse.llvm.org/t/implement-support-for-c-17-structured-bindings-in-the-clang-static-analyzer/60588.
>  It seems that part of the project is exploring necessary changes to the CFG. 
> What do you think about submitting this patch with local pattern matching and 
> revisiting that once the GSoC project completes?
Officially, there is no candidate accepted for that project yet, so there is no 
guarantee that we will have someone working on this. That being said, the CSA 
devs started to discuss what would be the best way to represent structured 
bindings in the CFG, and it is possible that for many of the cases we do not 
actually need to change the CFG, because the AST nodes have rich information. 
But of course, none of this is final, but we do not need to block this patch on 
that. So I'm fine adding this for now.

The AST for the supported case looks like:
```
   `-DeclStmt 0x5599ad9de6b0 
  `-DecompositionDecl 0x5599ad9de310  col:13 used 'A &' cinit
|-DeclRefExpr 0x5599ad9de388  'A' lvalue Var 0x5599ad9ddb80 
'Baz' 'A'
|-BindingDecl 0x5599ad9de280  col:14 BoundFooRef 'int'
| `-MemberExpr 0x5599ad9de630  'int' lvalue .Foo 0x5599ad9dd970
|   `-DeclRefExpr 0x5599ad9de610  'A':'A' lvalue Decomposition 
0x5599ad9de310 '' 'A &'
`-BindingDecl 0x5599ad9de2c8  col:27 BoundBarRef 'int'
  `-MemberExpr 0x5599ad9de680  'int' lvalue .Bar 0x5599ad9dd9d8
`-DeclRefExpr 0x5599ad9de660  'A':'A' lvalue Decomposition 
0x5599ad9de310 '' 'A &'
``` 

So each `BindingDecl` is like:
```
`-BindingDecl 0x5599ad9de2c8  col:27 BoundBarRef 'int'
  `-MemberExpr 0x5599ad9de680  'int' lvalue .Bar 0x5599ad9dd9d8
`-DeclRefExpr 0x5599ad9de660  'A':'A' lvalue Decomposition 
0x5599ad9de310 '' 'A &'
```

Is there a case where the `BindingDecl` would have a different shape? If we do 
not expect that happening, I feel like an `StmtVisitor` is a bit of an overkill 
for this and we could handle the supported case more directly. What do you 
think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120495

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


[PATCH] D124807: [clang][dataflow] Avoid assert for invalid cast to BoolValue

2022-05-03 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:78
+/// and integers in the framework.
+static const Expr *ignoreParenImpCastsExceptToBool(const Expr *E) {
+  const Expr *LastE = nullptr;

sgatev wrote:
> I don't recall why we need to ignore implicit casts here. Can't we ignore 
> parens and rely on the built-in transfer function, possibly adding handling 
> of some missing casts there? 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L192
If we only ignore parens, a test in the optional checker tests begins to fail, 
specifically `UncheckedOptionalAccessTest.ValueOrComparison`. The missing 
"cast" is an `ExprWithCleanups`. I didn't know how to deal with that, so this 
patch just working around the assert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124807

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


[PATCH] D124860: [clang][AArch64][SVE] Implicit conversions for vector-scalar operations

2022-05-03 Thread David Truby via Phabricator via cfe-commits
DavidTruby created this revision.
Herald added subscribers: ctetreau, psnobl, kristof.beyls, tschuett.
Herald added a reviewer: efriedma.
Herald added a project: All.
DavidTruby requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch allows the same implicit conversions for vector-scalar
operations in SVE that are allowed for NEON.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124860

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/aarch64-sve-vector-arith-ops.c
  clang/test/Sema/aarch64-sve-vector-arith-ops.c
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp

Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -213,23 +213,6 @@
   local_int8 &_int8;  // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
 
-  local_int8 + 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 - 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 * 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 / 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 % 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 & 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 | 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 ^ 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 < 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 <= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 == 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 != 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 >= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 > 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 && 0; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
-  local_int8 || 0; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
-
   if (local_int8) { // expected-error {{not contextually convertible to 'bool'}}
   }
   while (local_int8) { // expected-error {{not contextually convertible to 'bool'}}
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -201,23 +201,6 @@
   local_int8 &_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}}
 
-  local_int8 + 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 - 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 * 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 / 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 % 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 & 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 | 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 ^ 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 < 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 <= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 == 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 != 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 >= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 > 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 && 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 || 0; // expected-error {{invalid operands to binary expression}}
-
   if (local_int8) { // expected-error {{statement requires expression of scalar type}}
   }
   while (local_int8) { // expected-error {{statement requires expression of scalar type}}
Index: clang/test/Sema/aarch64-sve-vector-arith-ops.c
===
--- clang/test/Sema/aarch64-sve-vector-arith-ops.c
+++ clang/test/Sema/aarch64-sve-vector-arith-ops.c
@@ -20,12 +20,6 @@
   (void)(i8 + f16); // expected-error{{invalid operands to binary expression}}
   (void)(i8 + f32); // expected-error{{invalid operands to binary expression}}
   (void)(i8 + f64); // expected-error{{invalid operands to 

[PATCH] D124669: [flang][driver] Add support for -save-temps

2022-05-03 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 426747.
awarzynski added a comment.

Fix failing test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124669

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/fno-integrated-as.f90
  flang/test/Driver/save-temps.f90

Index: flang/test/Driver/save-temps.f90
===
--- /dev/null
+++ flang/test/Driver/save-temps.f90
@@ -0,0 +1,53 @@
+! Tests for the `-save-temps` flag. As `flang` does not implement `-fc1as` (i.e. a driver for the intergrated assembly), we need to
+! use `-fno-integrated-as` here.
+
+!--
+! Basic case: `-save-temps`
+!--
+! RUN: %flang -save-temps -fno-integrated-as %s -### 2>&1 | FileCheck %s
+! CHECK: "-o" "save-temps.i"
+! CHECK-NEXT: "-o" "save-temps.bc"
+! CHECK-NEXT: "-o" "save-temps.s"
+! CHECK-NEXT: "-o" "save-temps.o"
+! CHECK-NEXT: "-o" "a.out"
+
+!--
+! `-save-temps=cwd`
+!--
+! This should work the same as -save-temps above
+
+! RUN: %flang -save-temps=cwd -fno-integrated-as  %s -### 2>&1 | FileCheck %s -check-prefix=CWD
+! CWD: "-o" "save-temps.i"
+! CWD-NEXT: "-o" "save-temps.bc"
+! CWD-NEXT: "-o" "save-temps.s"
+! CWD-NEXT: "-o" "save-temps.o"
+! CWD-NEXT: "-o" "a.out"
+
+!--
+! `-save-temps=obj`
+!--
+! Check that temp files are saved in the same directory as the output file
+! regardless of whether -o is specified.
+
+! RUN: %flang -save-temps=obj -fno-integrated-as -o obj/dir/a.out %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-OBJ
+! CHECK-OBJ: "-o" "obj/dir/save-temps.i"
+! CHECK-OBJ-NEXT: "-o" "obj/dir/save-temps.bc"
+! CHECK-OBJ-NEXT: "-o" "obj/dir/save-temps.s"
+! CHECK-OBJ-NEXT: "-o" "obj/dir/save-temps.o"
+! CHECK-OBJ-NEXT: "-o" "obj/dir/a.out"
+
+! RUN: %flang -save-temps=obj -fno-integrated-as %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-OBJ-NOO
+! CHECK-OBJ-NOO: "-o" "save-temps.i"
+! CHECK-OBJ-NOO-NEXT: "-o" "save-temps.bc"
+! CHECK-OBJ-NOO-NEXT: "-o" "save-temps.s"
+! CHECK-OBJ-NOO-NEXT: "-o" "save-temps.o"
+! CHECK-OBJ-NOO-NEXT: "-o" "a.out"
+
+!--
+! `-S` without `-save-temps`
+!--
+! Check for a single `flang -fc1` invocation when NOT using -save-temps.
+! RUN: %flang -S %s -### 2>&1 | FileCheck %s -check-prefix=NO-TEMPS
+! NO-TEMPS: "-fc1"
+! NO-TEMPS-SAME: "-S"
+! NO-TEMPS-SAME: "-o" "save-temps.s"
Index: flang/test/Driver/fno-integrated-as.f90
===
--- /dev/null
+++ flang/test/Driver/fno-integrated-as.f90
@@ -0,0 +1,18 @@
+! Tests for the `-fno-integrated-as` flag.
+
+!--
+! With `-fno-integrated-as`
+!--
+! Verify that there _is_ a seperate line with an assembler invocation
+! RUN: %flang -c -fno-integrated-as %s -### 2>&1 | FileCheck %s
+! CHECK-LABEL: "-fc1"
+! CHECK-SAME: "-o" "[[assembly_file:.*]].s"
+! CHECK-NEXT: "-o" "fno-integrated-as.o" "[[assembly_file:.*]].s"
+
+!-
+! Without `-fno-integrated-as`
+!-
+! Verify that there _is no_ seperate line with an assembler invocation
+! RUN: %flang -c %s -### 2>&1 | FileCheck %s -check-prefix=DEFAULT
+! DEFAULT-LABEL: "-fc1"
+! DEFAULT-SAME: "-o" "fno-integrated-as.o" "{{.*}}fno-integrated-as.f90"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -42,6 +42,7 @@
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! HELP-NEXT: -fno-color-diagnostics  Disable colors in diagnostics
+! HELP-NEXT: -fno-integrated-as  Disable the integrated assembler
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
@@ -56,6 +57,8 @@
 ! HELP-NEXT: -print-effective-triple Print the effective target triple
 ! HELP-NEXT: -print-target-triplePrint the normalized target triple
 ! HELP-NEXT: -P Disable linemarker output in -E mode
+! HELP-NEXT: -save-temps=Save intermediate compilation results.
+! HELP-NEXT: -save-tempsSave intermediate compilation results
 ! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -S Only run preprocess and compilation steps
 ! HELP-NEXT: --target=   Generate code for the given target
Index: 

[PATCH] D123009: [Sema] Enum conversion warning when one signed and other unsigned.

2022-05-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Also, before we land this, you should add a release note to 
clang/docs/ReleaseNotes.rst about the bugfix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123009

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


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-05-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

I found another problem with both regular expressions (pre mine and mine): They 
cannot find

  /* a comment before */ #include 

Is this a known problem @MyDeveloperDay @owenpan @krasimir ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

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


[PATCH] D124669: [flang][driver] Add support for -save-temps

2022-05-03 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 426739.
awarzynski added a comment.

Add a test, restore white-space in Options.td


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124669

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/fno-integrated-as.f90
  flang/test/Driver/save-temps.f90

Index: flang/test/Driver/save-temps.f90
===
--- /dev/null
+++ flang/test/Driver/save-temps.f90
@@ -0,0 +1,53 @@
+! Tests for the `-save-temps` flag. As `flang` does not implement `-fc1as` (i.e. a driver for the intergrated assembly), we need to
+! use `-fno-integrated-as` here.
+
+!--
+! Basic case: `-save-temps`
+!--
+! RUN: %flang -save-temps -fno-integrated-as %s -### 2>&1 | FileCheck %s
+! CHECK: "-o" "save-temps.i"
+! CHECK-NEXT: "-o" "save-temps.bc"
+! CHECK-NEXT: "-o" "save-temps.s"
+! CHECK-NEXT: "-o" "save-temps.o"
+! CHECK-NEXT: "-o" "a.out"
+
+!--
+! `-save-temps=cwd`
+!--
+! This should work the same as -save-temps above
+
+! RUN: %flang -save-temps=cwd -fno-integrated-as  %s -### 2>&1 | FileCheck %s -check-prefix=CWD
+! CWD: "-o" "save-temps.i"
+! CWD-NEXT: "-o" "save-temps.bc"
+! CWD-NEXT: "-o" "save-temps.s"
+! CWD-NEXT: "-o" "save-temps.o"
+! CWD-NEXT: "-o" "a.out"
+
+!--
+! `-save-temps=obj`
+!--
+! Check that temp files are saved in the same directory as the output file
+! regardless of whether -o is specified.
+
+! RUN: %flang -save-temps=obj -fno-integrated-as -o obj/dir/a.out %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-OBJ
+! CHECK-OBJ: "-o" "obj/dir/save-temps.i"
+! CHECK-OBJ-NEXT: "-o" "obj/dir/save-temps.bc"
+! CHECK-OBJ-NEXT: "-o" "obj/dir/save-temps.s"
+! CHECK-OBJ-NEXT: "-o" "obj/dir/save-temps.o"
+! CHECK-OBJ-NEXT: "-o" "obj/dir/a.out"
+
+! RUN: %flang -save-temps=obj -fno-integrated-as %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-OBJ-NOO
+! CHECK-OBJ-NOO: "-o" "save-temps.i"
+! CHECK-OBJ-NOO-NEXT: "-o" "save-temps.bc"
+! CHECK-OBJ-NOO-NEXT: "-o" "save-temps.s"
+! CHECK-OBJ-NOO-NEXT: "-o" "save-temps.o"
+! CHECK-OBJ-NOO-NEXT: "-o" "a.out"
+
+!--
+! `-S` without `-save-temps`
+!--
+! Check for a single `flang -fc1` invocation when NOT using -save-temps.
+! RUN: %flang -S %s -### 2>&1 | FileCheck %s -check-prefix=NO-TEMPS
+! NO-TEMPS: "-fc1"
+! NO-TEMPS-SAME: "-S"
+! NO-TEMPS-SAME: "-o" "save-temps.s"
Index: flang/test/Driver/fno-integrated-as.f90
===
--- /dev/null
+++ flang/test/Driver/fno-integrated-as.f90
@@ -0,0 +1,18 @@
+! Tests for the `-fno-integrated-as` flag.
+
+!--
+! With `-fno-integrated-as`
+!--
+! Verify that there _is_ a seperate line with an assembler invocation
+! RUN: %flang -c -fno-integrated-as %s -### 2>&1 | FileCheck %s
+! CHECK-LABEL: "-fc1"
+! CHECK-SAME: "-o" "[[assembly_file:.*]].s"
+! CHECK-NEXT: "-o" "fno-integrated-as.o" "[[assembly_file:.*]].s"
+
+!-
+! Without `-fno-integrated-as`
+!-
+! Verify that there _is no_ seperate line with an assembler invocation
+! RUN: %flang -c %s -### 2>&1 | FileCheck %s -check-prefix=DEFAULT
+! DEFAULT-LABEL: "-fc1"
+! DEFAULT-SAME: "-o" "fno-integrated-as.o" "[[assembly_file:.*]].s"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -42,6 +42,7 @@
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! HELP-NEXT: -fno-color-diagnostics  Disable colors in diagnostics
+! HELP-NEXT: -fno-integrated-as  Disable the integrated assembler
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
@@ -56,6 +57,8 @@
 ! HELP-NEXT: -print-effective-triple Print the effective target triple
 ! HELP-NEXT: -print-target-triplePrint the normalized target triple
 ! HELP-NEXT: -P Disable linemarker output in -E mode
+! HELP-NEXT: -save-temps=Save intermediate compilation results.
+! HELP-NEXT: -save-tempsSave intermediate compilation results
 ! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -S Only run preprocess and compilation steps
 ! HELP-NEXT: --target=   Generate code for the given target

[PATCH] D124840: [RFC] Add and sort decl to maintain order instead of inserting in order

2022-05-03 Thread Ivan Murashko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2deebc0048f9: [RFC] Add and sort decl to maintain order 
instead of inserting in order (authored by kuganv, committed by ivanmurashko).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124840

Files:
  clang/lib/Serialization/ASTWriter.cpp


Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -3114,6 +3114,7 @@
   for (auto  : SortedFileDeclIDs) {
 DeclIDInFileInfo  = *FileDeclEntry.second;
 Info.FirstDeclIndex = FileGroupedDeclIDs.size();
+llvm::stable_sort(Info.DeclIDs);
 for (auto  : Info.DeclIDs)
   FileGroupedDeclIDs.push_back(LocDeclEntry.second);
   }
@@ -5462,16 +5463,7 @@
 
   std::pair LocDecl(Offset, ID);
   LocDeclIDsTy  = Info->DeclIDs;
-
-  if (Decls.empty() || Decls.back().first <= Offset) {
-Decls.push_back(LocDecl);
-return;
-  }
-
-  LocDeclIDsTy::iterator I =
-  llvm::upper_bound(Decls, LocDecl, llvm::less_first());
-
-  Decls.insert(I, LocDecl);
+  Decls.push_back(LocDecl);
 }
 
 unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) {


Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -3114,6 +3114,7 @@
   for (auto  : SortedFileDeclIDs) {
 DeclIDInFileInfo  = *FileDeclEntry.second;
 Info.FirstDeclIndex = FileGroupedDeclIDs.size();
+llvm::stable_sort(Info.DeclIDs);
 for (auto  : Info.DeclIDs)
   FileGroupedDeclIDs.push_back(LocDeclEntry.second);
   }
@@ -5462,16 +5463,7 @@
 
   std::pair LocDecl(Offset, ID);
   LocDeclIDsTy  = Info->DeclIDs;
-
-  if (Decls.empty() || Decls.back().first <= Offset) {
-Decls.push_back(LocDecl);
-return;
-  }
-
-  LocDeclIDsTy::iterator I =
-  llvm::upper_bound(Decls, LocDecl, llvm::less_first());
-
-  Decls.insert(I, LocDecl);
+  Decls.push_back(LocDecl);
 }
 
 unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2deebc0 - [RFC] Add and sort decl to maintain order instead of inserting in order

2022-05-03 Thread Ivan Murashko via cfe-commits

Author: Kugan Vivekanandarajah
Date: 2022-05-03T17:06:22+01:00
New Revision: 2deebc0048f92811dc92c7e41d357683b84febf7

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

LOG: [RFC] Add and sort decl to maintain order instead of inserting in order

ASTWriter::associateDeclWithFile shows a lot in clangd perf profile due to 
O(n^2) behaviour in insertion of DeclIDs in SortedFileDeclIDs. Instead of doing 
that, this patch just appends it to the DeclIDs vector and sorts them at the 
end.

Reviewed By: akyrtzi

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

Added: 


Modified: 
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 189d1a914ec31..228bd9aa08db4 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -3114,6 +3114,7 @@ void ASTWriter::WriteFileDeclIDsMap() {
   for (auto  : SortedFileDeclIDs) {
 DeclIDInFileInfo  = *FileDeclEntry.second;
 Info.FirstDeclIndex = FileGroupedDeclIDs.size();
+llvm::stable_sort(Info.DeclIDs);
 for (auto  : Info.DeclIDs)
   FileGroupedDeclIDs.push_back(LocDeclEntry.second);
   }
@@ -5462,16 +5463,7 @@ void ASTWriter::associateDeclWithFile(const Decl *D, 
DeclID ID) {
 
   std::pair LocDecl(Offset, ID);
   LocDeclIDsTy  = Info->DeclIDs;
-
-  if (Decls.empty() || Decls.back().first <= Offset) {
-Decls.push_back(LocDecl);
-return;
-  }
-
-  LocDeclIDsTy::iterator I =
-  llvm::upper_bound(Decls, LocDecl, llvm::less_first());
-
-  Decls.insert(I, LocDecl);
+  Decls.push_back(LocDecl);
 }
 
 unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) {



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


[PATCH] D123952: [FPEnv] Allow CompoundStmt to keep FP options

2022-05-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for working on this! One thing that's not clear to me is what bugs this 
is solving -- the test coverage only shows a change to textual AST dumping 
behavior. Is this otherwise expected to be an NFC change, or should there be 
some codegen tests that show a difference in behavior?




Comment at: clang/include/clang/AST/Stmt.h:134
+/// floating-point features.
+unsigned HasFPFeatures : 1;
+

I don't think this is a bad approach, but it does further reduce the number of 
statements we support in a compound statement.

There's a part of me that wonders if the approach is to introduce a new AST 
node for a stateful compound statement; I suspect if we dig around, we'll find 
other pragmas that want to behave similar to floating-point feature pragmas 
(the idea of a pragma scoped to a block is not really new). Having something 
more general means we're less likely to keep stealing bits here.



Comment at: clang/include/clang/Sema/ScopeInfo.h:77-78
 
-  CompoundScopeInfo(bool IsStmtExpr) : IsStmtExpr(IsStmtExpr) {}
+  /// FP options at the beginning of the compound statement, prior to
+  /// any pragma.
+  FPOptions FPFeatures;

So these are the initial FPOptions inherited by the scope from its surrounding 
context? And it's never updated by a pragma?



Comment at: clang/lib/AST/TextNodeDumper.cpp:2372-2376
+void TextNodeDumper::VisitCompoundStmt(const CompoundStmt *S) {
+  VisitStmt(S);
+  if (S->hasStoredFPFeatures())
+printFPOptions(S->getStoredFPFeatures());
+}

Should we have a similar change for the JSON node dumper?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123952

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


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-05-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk planned changes to this revision.
kwk added a comment.

Some thing that doesn't work at the moment is ordering an include like this:

  #include /*some include*/ "wontwork.h"

I wonder if it worked before. Let's see. Yes it worked. Grrr. I guess I need to 
do more...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

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


[PATCH] D123831: [clang][extract-api] Use relative includes

2022-05-03 Thread Daniel Grumberg via Phabricator via cfe-commits
dang accepted this revision.
dang added a comment.
This revision is now accepted and ready to land.

Minor comment LGTM otherwise




Comment at: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:203
+// Try to reduce the include name the same way we tried to include it.
+if (auto IncludeName = getRelativeIncludeName(CI, FileName))
+  if (llvm::find(KnownFiles, *IncludeName) != KnownFiles.end()) {

Should we be tracking if the include was quoted or not? In principle, that 
could mean a different redirect in header search and therefore potentially 
mapping to different content.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123831

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


[PATCH] D124807: [clang][dataflow] Avoid assert for invalid cast to BoolValue

2022-05-03 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:78
+/// and integers in the framework.
+static const Expr *ignoreParenImpCastsExceptToBool(const Expr *E) {
+  const Expr *LastE = nullptr;

I don't recall why we need to ignore implicit casts here. Can't we ignore 
parens and rely on the built-in transfer function, possibly adding handling of 
some missing casts there? 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L192


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124807

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


[PATCH] D124674: [analyzer] Indicate if a parent state is infeasible

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



Comment at: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp:51
+ProgramStateRef StFalse = assume(State, Cond, false);
+if (!StFalse) { // both infeasible
+  ProgramStateRef Infeasible = State->cloneAsInfeasible();

martong wrote:
> martong wrote:
> > steakhal wrote:
> > > Should we mark this `LLVM_UNLIKELY(cond)`?
> > > I would expect this function to be quite hot, and infeasible states rare.
> > > 
> > > Could we measure this one?
> > Yes, it could be.
> > 
> > Let me come back with some measurement results soon. I am going to use llvm 
> > statistics macros to measure this, but that makes sense on top of D124758
> This is what I use for the measurement, stay tuned for the results.
> ```
> diff --git a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp 
> b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
> index ef98ed7d36e9..82097d67ec0f 100644
> --- a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
> +++ b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
> @@ -16,10 +16,16 @@
>  #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
>  #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
>  #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
> +#include "llvm/ADT/Statistic.h"
> 
>  using namespace clang;
>  using namespace ento;
> 
> +#define DEBUG_TYPE "CoreEngine"
> +
> +STATISTIC(NumInfeasible, "The # of infeasible states");
> +STATISTIC(NumFeasible, "The # of feasible states");
> +
>  ConstraintManager::~ConstraintManager() = default;
> 
>  static DefinedSVal getLocFromSymbol(const ProgramStateRef ,
> @@ -51,16 +57,20 @@ ConstraintManager::assumeDual(ProgramStateRef State, 
> DefinedSVal Cond) {
>  if (!StFalse) { // both infeasible
>ProgramStateRef Infeasible = State->cloneAsInfeasible();
>assert(Infeasible->isInfeasible());
> +  ++NumInfeasible;
>return ProgramStatePair(Infeasible, Infeasible);
>  }
> +++NumFeasible;
>  return ProgramStatePair(nullptr, StFalse);
>}
> 
>ProgramStateRef StFalse = assumeInternal(State, Cond, false);
>if (!StFalse) {
> +++NumFeasible;
>  return ProgramStatePair(StTrue, nullptr);
>}
> 
> +  ++NumFeasible;
>return ProgramStatePair(StTrue, StFalse);
>  }
> ```
Ups, the purpose of the measure is to determine if UNLIKELY is justified, so 
this diff seems better, restarted the measurement with it.
```
--- a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -16,10 +16,16 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
+#include "llvm/ADT/Statistic.h"

 using namespace clang;
 using namespace ento;

+#define DEBUG_TYPE "CoreEngine"
+
+STATISTIC(NumInfeasible, "The # of infeasible states");
+STATISTIC(NumFeasible, "The # of feasible states");
+
 ConstraintManager::~ConstraintManager() = default;

 static DefinedSVal getLocFromSymbol(const ProgramStateRef ,
@@ -51,8 +57,10 @@ ConstraintManager::assumeDual(ProgramStateRef State, 
DefinedSVal Cond) {
 if (!StFalse) { // both infeasible
   ProgramStateRef Infeasible = State->cloneAsInfeasible();
   assert(Infeasible->isInfeasible());
+  ++NumInfeasible;
   return ProgramStatePair(Infeasible, Infeasible);
 }
+++NumFeasible;
 return ProgramStatePair(nullptr, StFalse);
   }

```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124674

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


[PATCH] D124724: [Clang][OpenMP] Add the support for floating-point variables for specific atomic clauses

2022-05-03 Thread Shilei Tian 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 rG9c1085c7e20b: [Clang][OpenMP] Add the support for 
floating-point variables for specific… (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124724

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/atomic_capture_codegen.cpp
  clang/test/OpenMP/atomic_update_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen.cpp
  clang/test/OpenMP/parallel_reduction_codegen.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/sections_reduction_codegen.cpp

Index: clang/test/OpenMP/sections_reduction_codegen.cpp
===
--- clang/test/OpenMP/sections_reduction_codegen.cpp
+++ clang/test/OpenMP/sections_reduction_codegen.cpp
@@ -268,11 +268,9 @@
 // CHECK1-NEXT:[[T_VAR15:%.*]] = alloca float, align 4
 // CHECK1-NEXT:[[DOTOMP_REDUCTION_RED_LIST:%.*]] = alloca [4 x i8*], align 8
 // CHECK1-NEXT:[[REF_TMP:%.*]] = alloca [[STRUCT_S]], align 4
+// CHECK1-NEXT:[[REF_TMP16:%.*]] = alloca [[STRUCT_S]], align 4
 // CHECK1-NEXT:[[ATOMIC_TEMP:%.*]] = alloca float, align 4
 // CHECK1-NEXT:[[TMP:%.*]] = alloca float, align 4
-// CHECK1-NEXT:[[REF_TMP17:%.*]] = alloca [[STRUCT_S]], align 4
-// CHECK1-NEXT:[[ATOMIC_TEMP27:%.*]] = alloca float, align 4
-// CHECK1-NEXT:[[_TMP28:%.*]] = alloca float, align 4
 // CHECK1-NEXT:store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8
 // CHECK1-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8
 // CHECK1-NEXT:store float* [[T_VAR]], float** [[T_VAR_ADDR]], align 8
@@ -401,77 +399,59 @@
 // CHECK1-NEXT:br label [[DOTOMP_REDUCTION_DEFAULT]]
 // CHECK1:   .omp.reduction.case2:
 // CHECK1-NEXT:[[TMP43:%.*]] = load float, float* [[T_VAR2]], align 4
-// CHECK1-NEXT:[[TMP44:%.*]] = bitcast float* [[TMP0]] to i32*
-// CHECK1-NEXT:[[ATOMIC_LOAD:%.*]] = load atomic i32, i32* [[TMP44]] monotonic, align 4
-// CHECK1-NEXT:br label [[ATOMIC_CONT:%.*]]
-// CHECK1:   atomic_cont:
-// CHECK1-NEXT:[[TMP45:%.*]] = phi i32 [ [[ATOMIC_LOAD]], [[DOTOMP_REDUCTION_CASE2]] ], [ [[TMP53:%.*]], [[ATOMIC_CONT]] ]
-// CHECK1-NEXT:[[TMP46:%.*]] = bitcast float* [[ATOMIC_TEMP]] to i32*
-// CHECK1-NEXT:[[TMP47:%.*]] = bitcast i32 [[TMP45]] to float
-// CHECK1-NEXT:store float [[TMP47]], float* [[TMP]], align 4
-// CHECK1-NEXT:[[TMP48:%.*]] = load float, float* [[TMP]], align 4
-// CHECK1-NEXT:[[TMP49:%.*]] = load float, float* [[T_VAR2]], align 4
-// CHECK1-NEXT:[[ADD15:%.*]] = fadd float [[TMP48]], [[TMP49]]
-// CHECK1-NEXT:store float [[ADD15]], float* [[ATOMIC_TEMP]], align 4
-// CHECK1-NEXT:[[TMP50:%.*]] = load i32, i32* [[TMP46]], align 4
-// CHECK1-NEXT:[[TMP51:%.*]] = bitcast float* [[TMP0]] to i32*
-// CHECK1-NEXT:[[TMP52:%.*]] = cmpxchg i32* [[TMP51]], i32 [[TMP45]], i32 [[TMP50]] monotonic monotonic, align 4
-// CHECK1-NEXT:[[TMP53]] = extractvalue { i32, i1 } [[TMP52]], 0
-// CHECK1-NEXT:[[TMP54:%.*]] = extractvalue { i32, i1 } [[TMP52]], 1
-// CHECK1-NEXT:br i1 [[TMP54]], label [[ATOMIC_EXIT:%.*]], label [[ATOMIC_CONT]]
-// CHECK1:   atomic_exit:
+// CHECK1-NEXT:[[TMP44:%.*]] = atomicrmw fadd float* [[TMP0]], float [[TMP43]] monotonic, align 4
 // CHECK1-NEXT:call void @__kmpc_critical(%struct.ident_t* @[[GLOB3]], i32 [[TMP7]], [8 x i32]* @.gomp_critical_user_.atomic_reduction.var)
-// CHECK1-NEXT:[[CALL16:%.*]] = call noundef nonnull align 4 dereferenceable(4) %struct.S* @_ZN1SIfEanERKS0_(%struct.S* noundef nonnull align 4 dereferenceable(4) [[TMP1]], %struct.S* noundef nonnull align 4 dereferenceable(4) [[VAR3]])
-// CHECK1-NEXT:[[TMP55:%.*]] = bitcast %struct.S* [[TMP1]] to i8*
-// CHECK1-NEXT:[[TMP56:%.*]] = bitcast %struct.S* [[CALL16]] to i8*
-// CHECK1-NEXT:call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[TMP55]], i8* align 4 [[TMP56]], i64 4, i1 false)
+// CHECK1-NEXT:[[CALL15:%.*]] = call noundef nonnull align 4 dereferenceable(4) %struct.S* @_ZN1SIfEanERKS0_(%struct.S* noundef nonnull align 4 dereferenceable(4) [[TMP1]], %struct.S* noundef nonnull align 4 dereferenceable(4) [[VAR3]])
+// CHECK1-NEXT:[[TMP45:%.*]] = bitcast %struct.S* [[TMP1]] to i8*
+// CHECK1-NEXT:[[TMP46:%.*]] = bitcast %struct.S* [[CALL15]] to i8*
+// CHECK1-NEXT:call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[TMP45]], i8* align 4 [[TMP46]], i64 4, i1 false)
 // CHECK1-NEXT:call void @__kmpc_end_critical(%struct.ident_t* @[[GLOB3]], i32 [[TMP7]], [8 x i32]* @.gomp_critical_user_.atomic_reduction.var)
 // CHECK1-NEXT:call void @__kmpc_critical(%struct.ident_t* @[[GLOB3]], i32 [[TMP7]], [8 x i32]* @.gomp_critical_user_.atomic_reduction.var)
-// CHECK1-NEXT:

[clang] 9c1085c - [Clang][OpenMP] Add the support for floating-point variables for specific atomic clauses

2022-05-03 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2022-05-03T11:30:54-04:00
New Revision: 9c1085c7e20bdd7c4a487f50313ebeeb2b6683b8

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

LOG: [Clang][OpenMP] Add the support for floating-point variables for specific 
atomic clauses

Currently when using `atomic update` with floating-point variables, if
the operation is add or sub, `cmpxchg`, instead of `atomicrmw` is emitted, as
shown in [1].  In fact, about three years ago, llvm-svn: 351850 added the
support for FP operations. This patch adds the support in OpenMP as well.

[1] https://godbolt.org/z/M7b4ba9na

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/atomic_capture_codegen.cpp
clang/test/OpenMP/atomic_update_codegen.cpp
clang/test/OpenMP/for_reduction_codegen.cpp
clang/test/OpenMP/parallel_reduction_codegen.cpp
clang/test/OpenMP/reduction_implicit_map.cpp
clang/test/OpenMP/sections_reduction_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index fc8156a78d6a7..5e75e8884bb49 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5838,25 +5838,38 @@ static std::pair 
emitOMPAtomicRMW(CodeGenFunction , LValue X,
   // Allow atomicrmw only if 'x' and 'update' are integer values, lvalue for 
'x'
   // expression is simple and atomic is allowed for the given type for the
   // target platform.
-  if (BO == BO_Comma || !Update.isScalar() ||
-  !Update.getScalarVal()->getType()->isIntegerTy() || !X.isSimple() ||
+  if (BO == BO_Comma || !Update.isScalar() || !X.isSimple() ||
   (!isa(Update.getScalarVal()) &&
(Update.getScalarVal()->getType() !=
 X.getAddress(CGF).getElementType())) ||
-  !X.getAddress(CGF).getElementType()->isIntegerTy() ||
   !Context.getTargetInfo().hasBuiltinAtomic(
   Context.getTypeSize(X.getType()), Context.toBits(X.getAlignment(
 return std::make_pair(false, RValue::get(nullptr));
 
+  auto & = [](llvm::Type *T, BinaryOperatorKind BO) {
+if (T->isIntegerTy())
+  return true;
+
+if (T->isFloatingPointTy() && (BO == BO_Add || BO == BO_Sub))
+  return llvm::isPowerOf2_64(CGF.CGM.getDataLayout().getTypeStoreSize(T));
+
+return false;
+  };
+
+  if (!CheckAtomicSupport(Update.getScalarVal()->getType(), BO) ||
+  !CheckAtomicSupport(X.getAddress(CGF).getElementType(), BO))
+return std::make_pair(false, RValue::get(nullptr));
+
+  bool IsInteger = X.getAddress(CGF).getElementType()->isIntegerTy();
   llvm::AtomicRMWInst::BinOp RMWOp;
   switch (BO) {
   case BO_Add:
-RMWOp = llvm::AtomicRMWInst::Add;
+RMWOp = IsInteger ? llvm::AtomicRMWInst::Add : llvm::AtomicRMWInst::FAdd;
 break;
   case BO_Sub:
 if (!IsXLHSInRHSPart)
   return std::make_pair(false, RValue::get(nullptr));
-RMWOp = llvm::AtomicRMWInst::Sub;
+RMWOp = IsInteger ? llvm::AtomicRMWInst::Sub : llvm::AtomicRMWInst::FSub;
 break;
   case BO_And:
 RMWOp = llvm::AtomicRMWInst::And;
@@ -5914,9 +5927,13 @@ static std::pair 
emitOMPAtomicRMW(CodeGenFunction , LValue X,
   }
   llvm::Value *UpdateVal = Update.getScalarVal();
   if (auto *IC = dyn_cast(UpdateVal)) {
-UpdateVal = CGF.Builder.CreateIntCast(
-IC, X.getAddress(CGF).getElementType(),
-X.getType()->hasSignedIntegerRepresentation());
+if (IsInteger)
+  UpdateVal = CGF.Builder.CreateIntCast(
+  IC, X.getAddress(CGF).getElementType(),
+  X.getType()->hasSignedIntegerRepresentation());
+else
+  UpdateVal = CGF.Builder.CreateCast(llvm::Instruction::CastOps::UIToFP, 
IC,
+ X.getAddress(CGF).getElementType());
   }
   llvm::Value *Res =
   CGF.Builder.CreateAtomicRMW(RMWOp, X.getPointer(CGF), UpdateVal, AO);

diff  --git a/clang/test/OpenMP/atomic_capture_codegen.cpp 
b/clang/test/OpenMP/atomic_capture_codegen.cpp
index c5f45a39232c0..95509df9ba935 100644
--- a/clang/test/OpenMP/atomic_capture_codegen.cpp
+++ b/clang/test/OpenMP/atomic_capture_codegen.cpp
@@ -216,20 +216,8 @@ int main(void) {
 #pragma omp atomic capture
   llv = ullx |= ullv;
 // CHECK: [[EXPR:%.+]] = load float, float* @{{.+}},
-// CHECK: [[X:%.+]] = load atomic i32, i32*  bitcast (float* [[X_ADDR:@.+]] to 
i32*) monotonic, align 4
-// CHECK: br label %[[CONT:.+]]
-// CHECK: [[CONT]]
-// CHECK: [[EXPECTED:%.+]] = phi i32 [ [[X]], %{{.+}} ], [ [[OLD_X:%.+]], 
%[[CONT]] ]
-// CHECK: [[TEMP_I:%.+]] = bitcast float* [[TEMP:%.+]] to i32*
-// CHECK: [[OLD:%.+]] = bitcast i32 [[EXPECTED]] to float
+// CHECK: [[OLD:%.+]] = atomicrmw fadd float* @{{.+}}, float [[EXPR]] 
monotonic, align 4
 

[PATCH] D124674: [analyzer] Indicate if a parent state is infeasible

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



Comment at: clang/test/Analysis/sink-infeasible.c:37-48
+  /* The BASELINE passes these checks ('wrning' is used to avoid lit to match)
+  // The parent state is already infeasible, look at this contradiction:
+  clang_analyzer_eval(b > 0);  // expected-wrning{{FALSE}}
+  clang_analyzer_eval(b <= 0); // expected-wrning{{FALSE}}
+  // Crashes with expensive checks.
+  if (b > 0) {
+clang_analyzer_warnIfReached(); // no-warning, OK

steakhal wrote:
> martong wrote:
> > steakhal wrote:
> > > You could use a non-default check prefix.
> > No I can't, because this test code in the comment is meaningful only in the 
> > baseline, I cannot run both clang versions from lit.
> > 
> > So, actually there is no RUN line for these, it is here only to demonstrate 
> > what happens in the baseline.
> Okay, why don't we drop these if these are only applicable to the baseline?
> Should we really introduce 'stale' comments?
Ok, I can remove them if you insist, but I thought it might make it easier to 
understand what is changed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124674

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


[PATCH] D124724: [Clang][OpenMP] Add the support for floating-point variables for specific atomic clauses

2022-05-03 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 426725.
tianshilei1992 added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124724

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/atomic_capture_codegen.cpp
  clang/test/OpenMP/atomic_update_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen.cpp
  clang/test/OpenMP/parallel_reduction_codegen.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/sections_reduction_codegen.cpp

Index: clang/test/OpenMP/sections_reduction_codegen.cpp
===
--- clang/test/OpenMP/sections_reduction_codegen.cpp
+++ clang/test/OpenMP/sections_reduction_codegen.cpp
@@ -268,11 +268,9 @@
 // CHECK1-NEXT:[[T_VAR15:%.*]] = alloca float, align 4
 // CHECK1-NEXT:[[DOTOMP_REDUCTION_RED_LIST:%.*]] = alloca [4 x i8*], align 8
 // CHECK1-NEXT:[[REF_TMP:%.*]] = alloca [[STRUCT_S]], align 4
+// CHECK1-NEXT:[[REF_TMP16:%.*]] = alloca [[STRUCT_S]], align 4
 // CHECK1-NEXT:[[ATOMIC_TEMP:%.*]] = alloca float, align 4
 // CHECK1-NEXT:[[TMP:%.*]] = alloca float, align 4
-// CHECK1-NEXT:[[REF_TMP17:%.*]] = alloca [[STRUCT_S]], align 4
-// CHECK1-NEXT:[[ATOMIC_TEMP27:%.*]] = alloca float, align 4
-// CHECK1-NEXT:[[_TMP28:%.*]] = alloca float, align 4
 // CHECK1-NEXT:store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8
 // CHECK1-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8
 // CHECK1-NEXT:store float* [[T_VAR]], float** [[T_VAR_ADDR]], align 8
@@ -401,77 +399,59 @@
 // CHECK1-NEXT:br label [[DOTOMP_REDUCTION_DEFAULT]]
 // CHECK1:   .omp.reduction.case2:
 // CHECK1-NEXT:[[TMP43:%.*]] = load float, float* [[T_VAR2]], align 4
-// CHECK1-NEXT:[[TMP44:%.*]] = bitcast float* [[TMP0]] to i32*
-// CHECK1-NEXT:[[ATOMIC_LOAD:%.*]] = load atomic i32, i32* [[TMP44]] monotonic, align 4
+// CHECK1-NEXT:[[TMP44:%.*]] = atomicrmw fadd float* [[TMP0]], float [[TMP43]] monotonic, align 4
+// CHECK1-NEXT:call void @__kmpc_critical(%struct.ident_t* @[[GLOB3]], i32 [[TMP7]], [8 x i32]* @.gomp_critical_user_.atomic_reduction.var)
+// CHECK1-NEXT:[[CALL15:%.*]] = call noundef nonnull align 4 dereferenceable(4) %struct.S* @_ZN1SIfEanERKS0_(%struct.S* noundef nonnull align 4 dereferenceable(4) [[TMP1]], %struct.S* noundef nonnull align 4 dereferenceable(4) [[VAR3]])
+// CHECK1-NEXT:[[TMP45:%.*]] = bitcast %struct.S* [[TMP1]] to i8*
+// CHECK1-NEXT:[[TMP46:%.*]] = bitcast %struct.S* [[CALL15]] to i8*
+// CHECK1-NEXT:call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[TMP45]], i8* align 4 [[TMP46]], i64 4, i1 false)
+// CHECK1-NEXT:call void @__kmpc_end_critical(%struct.ident_t* @[[GLOB3]], i32 [[TMP7]], [8 x i32]* @.gomp_critical_user_.atomic_reduction.var)
+// CHECK1-NEXT:call void @__kmpc_critical(%struct.ident_t* @[[GLOB3]], i32 [[TMP7]], [8 x i32]* @.gomp_critical_user_.atomic_reduction.var)
+// CHECK1-NEXT:[[CALL17:%.*]] = call noundef float @_ZN1SIfEcvfEv(%struct.S* noundef nonnull align 4 dereferenceable(4) [[TMP2]])
+// CHECK1-NEXT:[[TOBOOL18:%.*]] = fcmp une float [[CALL17]], 0.00e+00
+// CHECK1-NEXT:br i1 [[TOBOOL18]], label [[LAND_RHS19:%.*]], label [[LAND_END22:%.*]]
+// CHECK1:   land.rhs19:
+// CHECK1-NEXT:[[CALL20:%.*]] = call noundef float @_ZN1SIfEcvfEv(%struct.S* noundef nonnull align 4 dereferenceable(4) [[VAR14]])
+// CHECK1-NEXT:[[TOBOOL21:%.*]] = fcmp une float [[CALL20]], 0.00e+00
+// CHECK1-NEXT:br label [[LAND_END22]]
+// CHECK1:   land.end22:
+// CHECK1-NEXT:[[TMP47:%.*]] = phi i1 [ false, [[DOTOMP_REDUCTION_CASE2]] ], [ [[TOBOOL21]], [[LAND_RHS19]] ]
+// CHECK1-NEXT:[[CONV23:%.*]] = uitofp i1 [[TMP47]] to float
+// CHECK1-NEXT:call void @_ZN1SIfEC1Ef(%struct.S* noundef nonnull align 4 dereferenceable(4) [[REF_TMP16]], float noundef [[CONV23]])
+// CHECK1-NEXT:[[TMP48:%.*]] = bitcast %struct.S* [[TMP2]] to i8*
+// CHECK1-NEXT:[[TMP49:%.*]] = bitcast %struct.S* [[REF_TMP16]] to i8*
+// CHECK1-NEXT:call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[TMP48]], i8* align 4 [[TMP49]], i64 4, i1 false)
+// CHECK1-NEXT:call void @_ZN1SIfED1Ev(%struct.S* noundef nonnull align 4 dereferenceable(4) [[REF_TMP16]]) #[[ATTR4]]
+// CHECK1-NEXT:call void @__kmpc_end_critical(%struct.ident_t* @[[GLOB3]], i32 [[TMP7]], [8 x i32]* @.gomp_critical_user_.atomic_reduction.var)
+// CHECK1-NEXT:[[TMP50:%.*]] = load float, float* [[T_VAR15]], align 4
+// CHECK1-NEXT:[[TMP51:%.*]] = bitcast float* [[TMP3]] to i32*
+// CHECK1-NEXT:[[ATOMIC_LOAD:%.*]] = load atomic i32, i32* [[TMP51]] monotonic, align 4
 // CHECK1-NEXT:br label [[ATOMIC_CONT:%.*]]
 // CHECK1:   atomic_cont:
-// CHECK1-NEXT:[[TMP45:%.*]] = phi i32 [ [[ATOMIC_LOAD]], [[DOTOMP_REDUCTION_CASE2]] ], [ [[TMP53:%.*]], [[ATOMIC_CONT]] ]

[PATCH] D124432: Fix issues with using clangd with C++ modules

2022-05-03 Thread Kugan Vivekanandarajah via Phabricator via cfe-commits
kuganv updated this revision to Diff 426724.

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

https://reviews.llvm.org/D124432

Files:
  clang-tools-extra/clangd/test/modules-options-compatablity-test/A.h
  clang-tools-extra/clangd/test/modules-options-compatablity-test/B.h
  
clang-tools-extra/clangd/test/modules-options-compatablity-test/compile_commands.json
  
clang-tools-extra/clangd/test/modules-options-compatablity-test/definition.jsonrpc
  
clang-tools-extra/clangd/test/modules-options-compatablity-test/module.modulemap
  clang-tools-extra/clangd/test/modules-options-compatablity-test/use.c
  clang-tools-extra/clangd/test/modules-options-compatablity.test
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Serialization/ASTReader.cpp

Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3077,6 +3077,10 @@
   return Err;
 if (llvm::Error Err = ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID))
   return Err;
+if (PP.getPreprocessorOpts().GeneratePreamble &&
+!PP.getPreprocessorOpts().WriteCommentListToPCH) {
+  break;
+}
 CommentsCursors.push_back(std::make_pair(C, ));
 break;
   }
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -387,7 +387,7 @@
 
 LANGOPT(XLPragmaPack, 1, 0, "IBM XL #pragma pack handling")
 
-LANGOPT(RetainCommentsFromSystemHeaders, 1, 0, "retain documentation comments from system headers in the AST")
+COMPATIBLE_LANGOPT(RetainCommentsFromSystemHeaders, 1, 0, "retain documentation comments from system headers in the AST")
 
 LANGOPT(SanitizeAddressFieldPadding, 2, 0, "controls how aggressive is ASan "
"field padding (0: none, 1:least "
Index: clang-tools-extra/clangd/test/modules-options-compatablity.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/modules-options-compatablity.test
@@ -0,0 +1,10 @@
+
+# RUN: rm -rf %t && mkdir -p %t
+# RUN: cp -r %S/modules-options-compatablity-test/* %t
+# RUN: mkdir -p %t/prebuilt
+# RUN: sed -i -e "s|DIRECTORY|%t|g" %t/definition.jsonrpc
+# RUN: sed -i -e "s|DIRECTORY|%t|g" %t/compile_commands.json
+# RUN: %clang -cc1 -emit-module -o %t/prebuilt/A.pcm -fmodules %t/module.modulemap -fmodule-name=A
+# RUN: %clang -cc1 -fretain-comments-from-system-headers -emit-module -o %t/prebuilt/B.pcm -fmodules %t/module.modulemap -fmodule-name=B -fprebuilt-module-path=%t/prebuilt
+# RUN: rm %t/*.h
+# RUN: clangd -background-index -lit-test < %t/definition.jsonrpc
Index: clang-tools-extra/clangd/test/modules-options-compatablity-test/use.c
===
--- /dev/null
+++ clang-tools-extra/clangd/test/modules-options-compatablity-test/use.c
@@ -0,0 +1,5 @@
+/* use */
+#include 
+#include 
+
+void use() { a(); }
Index: clang-tools-extra/clangd/test/modules-options-compatablity-test/module.modulemap
===
--- /dev/null
+++ clang-tools-extra/clangd/test/modules-options-compatablity-test/module.modulemap
@@ -0,0 +1,8 @@
+/* module.modulemap */
+module A {
+  header "A.h"
+}
+module B {
+  header "B.h"
+  export *
+}
Index: clang-tools-extra/clangd/test/modules-options-compatablity-test/definition.jsonrpc
===
--- /dev/null
+++ clang-tools-extra/clangd/test/modules-options-compatablity-test/definition.jsonrpc
@@ -0,0 +1,28 @@
+{
+  "jsonrpc": "2.0",
+"id": 0,
+"method": "initialize",
+"params": {
+  "processId": 123,
+  "rootPath": "clangd",
+  "capabilities": { "window": { "workDoneProgress": true, "implicitWorkDoneProgressCreate": true} },
+  "trace": "off"
+}
+}
+---
+{
+  "jsonrpc": "2.0",
+"method": "textDocument/didOpen",
+"params": {
+  "textDocument": {
+"uri": "file://DIRECTORY/use.c",
+"languageId": "cpp",
+"version": 1,
+"text": "#include \"B.h\"\nvoid use(){\na();\n}"
+  }
+}
+}
+---
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/test/modules-options-compatablity-test/compile_commands.json
===
--- /dev/null
+++ clang-tools-extra/clangd/test/modules-options-compatablity-test/compile_commands.json
@@ -0,0 +1,8 @@
+[{
+  "directory" : ".",
+  "command" : "clang -emit-obj DIRECTORY/use.c -fno-modules-global -fmodules "
+  "-fmodules-cache-path=/DOES/NOT/EXIST  -fno-builtin-module-map "
+  "-fno-implicit-modules  

[PATCH] D123009: [Sema] Enum conversion warning when one signed and other unsigned.

2022-05-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for the updates! I think this is getting somewhat close, but I'd like to 
see some additional test cases to ensure we're not regressing behavior we care 
about (I think we may be losing warnings about sign conversion).

  // Signed enums
  enum SE1 { N1 = -1 };
  enum SE2 { N2 = -2 };
  // Unsigned unums
  enum UE1 { P1 };
  enum UE2 { P2 };
  
  int f1(enum UE1 E) {
return E; // warning about sign conversion
  }
  
  int f2(enum UE1 E) {
return E; // warning about sign conversion
  }
  
  int f3(enum SE1 E) {
return E; // shouldn't warn
  }
  
  int f4(enum SE1 E) {
return E; // shouldn't warn
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123009

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


[PATCH] D124674: [analyzer] Indicate if a parent state is infeasible

2022-05-03 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp:51
+ProgramStateRef StFalse = assume(State, Cond, false);
+if (!StFalse) { // both infeasible
+  ProgramStateRef Infeasible = State->cloneAsInfeasible();

martong wrote:
> steakhal wrote:
> > Should we mark this `LLVM_UNLIKELY(cond)`?
> > I would expect this function to be quite hot, and infeasible states rare.
> > 
> > Could we measure this one?
> Yes, it could be.
> 
> Let me come back with some measurement results soon. I am going to use llvm 
> statistics macros to measure this, but that makes sense on top of D124758
This is what I use for the measurement, stay tuned for the results.
```
diff --git a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
index ef98ed7d36e9..82097d67ec0f 100644
--- a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -16,10 +16,16 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
+#include "llvm/ADT/Statistic.h"

 using namespace clang;
 using namespace ento;

+#define DEBUG_TYPE "CoreEngine"
+
+STATISTIC(NumInfeasible, "The # of infeasible states");
+STATISTIC(NumFeasible, "The # of feasible states");
+
 ConstraintManager::~ConstraintManager() = default;

 static DefinedSVal getLocFromSymbol(const ProgramStateRef ,
@@ -51,16 +57,20 @@ ConstraintManager::assumeDual(ProgramStateRef State, 
DefinedSVal Cond) {
 if (!StFalse) { // both infeasible
   ProgramStateRef Infeasible = State->cloneAsInfeasible();
   assert(Infeasible->isInfeasible());
+  ++NumInfeasible;
   return ProgramStatePair(Infeasible, Infeasible);
 }
+++NumFeasible;
 return ProgramStatePair(nullptr, StFalse);
   }

   ProgramStateRef StFalse = assumeInternal(State, Cond, false);
   if (!StFalse) {
+++NumFeasible;
 return ProgramStatePair(StTrue, nullptr);
   }

+  ++NumFeasible;
   return ProgramStatePair(StTrue, StFalse);
 }
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124674

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


[PATCH] D122663: Mark identifier prefixes as substitutable

2022-05-03 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added inline comments.



Comment at: clang/lib/AST/ItaniumMangle.cpp:6031
+bool CXXNameMangler::mangleSubstitution(NestedNameSpecifier *NNS) {
+  NNS = Context.getASTContext().getCanonicalNestedNameSpecifier(NNS);
+  return mangleSubstitution(reinterpret_cast(NNS));

hvdijk wrote:
> urnathan wrote:
> > hvdijk wrote:
> > > rsmith wrote:
> > > > This seems a little error-prone to me: calling this on a type NNS would 
> > > > do the wrong thing (those are supposed to share a substitution number 
> > > > with the type, rather than have a substitution of their own).
> > > > 
> > > > We could handle the various cases here and dispatch to the right forms 
> > > > of `mangleSubstitution` depending on the kind of NNS, but that code 
> > > > would all be unreachable / untested. So maybe we should just make this 
> > > > assert that `NNS->getKind() == NestedNameSpecifier::Identifier`. (And 
> > > > optionally we could give this a more specific name, eg 
> > > > `mangleSubstitutionForIdentifierNNS`?)
> > > I have added the assert that you suggested. I would actually have 
> > > preferred for this function to be used for other NNS substitutions as 
> > > well to better align with how the spec says substitutions should be 
> > > handled (it's a rule of ``, not any component within) but that 
> > > seemed like an unnecessarily more invasive change. If you are okay with 
> > > it I would like to keep the function named just `mangleSubstitution` to 
> > > keep that open as option for a possible future clean-up.
> > One could name it `mangleSubstitutionForIdentifierNNS` now and rename it in 
> > the future, if your unification dream comes true?  That names it for what 
> > it does now.
> > 
> > Just a thought, not a requirement.
> Sorry, that comment came after I pushed it already. I have some more things 
> to look into when I have some more time (including @erichkeane's comment 
> about the test), will see if it makes sense to include with that, or perhaps 
> to just make that NFC change to allow it to be used more generally.
no worries, I failed to notice it'd already landed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122663

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


[PATCH] D124674: [analyzer] Indicate if a parent state is infeasible

2022-05-03 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 426715.
martong added a comment.

- Add a simpler test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124674

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/ProgramState.cpp
  clang/test/Analysis/infeasible-sink.c

Index: clang/test/Analysis/infeasible-sink.c
===
--- /dev/null
+++ clang/test/Analysis/infeasible-sink.c
@@ -0,0 +1,80 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -verify
+
+// Here we test that if it turns out that the parent state is infeasible then
+// both children States (more precisely the ExplodedNodes) are marked as a
+// Sink.
+// We rely on existing defects of the underlying constraint solver. However,
+// in the future we might strengthen the solver to discover the infeasibility
+// right when we create the parent state. At that point some of these tests
+// will fail, and either we shall find another solver weakness to have the test
+// case functioning, or we shall simply remove that.
+
+void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(int);
+
+void test1(int x) {
+  if (x * x != 4)
+return;
+  if (x < 0 || x > 1)
+return;
+
+  // { x^2 == 4 and x:[0,1] }
+  // This state is already infeasible.
+
+  // Perfectly constraining 'x' will trigger constant folding,
+  // when we realize we were already infeasible.
+  // The same happens for the 'else' branch.
+  if (x == 0) {
+clang_analyzer_warnIfReached(); // no-warning
+  } else {
+clang_analyzer_warnIfReached(); // no-warning
+  }
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x;
+}
+
+int a, b, c, d, e;
+void test2() {
+
+  if (a == 0)
+return;
+
+  if (e != c)
+return;
+
+  d = e - c;
+  b = d;
+  a -= d;
+
+  if (a != 0)
+return;
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+
+  /* The BASELINE passes these checks ('wrning' is used to avoid lit to match)
+  // The parent state is already infeasible, look at this contradiction:
+  clang_analyzer_eval(b > 0);  // expected-wrning{{FALSE}}
+  clang_analyzer_eval(b <= 0); // expected-wrning{{FALSE}}
+  // Crashes with expensive checks.
+  if (b > 0) {
+clang_analyzer_warnIfReached(); // no-warning, OK
+return;
+  }
+  // Should not be reachable.
+  clang_analyzer_warnIfReached(); // expected-wrning{{REACHABLE}}
+  */
+
+  // The parent state is already infeasible, but we realize that only if b is
+  // constrained.
+  clang_analyzer_eval(b > 0);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b <= 0); // expected-warning{{UNKNOWN}}
+  if (b > 0) {
+clang_analyzer_warnIfReached(); // no-warning
+return;
+  }
+  clang_analyzer_warnIfReached(); // no-warning
+}
Index: clang/lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ clang/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -55,7 +55,7 @@
 
 ProgramState::ProgramState(const ProgramState )
 : stateMgr(RHS.stateMgr), Env(RHS.Env), store(RHS.store), GDM(RHS.GDM),
-  refCount(0) {
+  Infeasible(RHS.Infeasible), refCount(0) {
   stateMgr->getStoreManager().incrementReferenceCount(store);
 }
 
@@ -429,6 +429,12 @@
   return getStateManager().getPersistentState(NewSt);
 }
 
+ProgramStateRef ProgramState::cloneAsInfeasible() const {
+  ProgramState NewSt(*this);
+  NewSt.Infeasible = true;
+  return getStateManager().getPersistentState(NewSt);
+}
+
 void ProgramState::setStore(const StoreRef ) {
   Store newStoreStore = newStore.getStore();
   if (newStoreStore)
Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -41,3 +41,32 @@
 return ConditionTruthVal(true);
   return {};
 }
+
+ConstraintManager::ProgramStatePair
+ConstraintManager::assumeDual(ProgramStateRef State, DefinedSVal Cond) {
+  ProgramStateRef StTrue = assume(State, Cond, true);
+
+  if (!StTrue) {
+ProgramStateRef StFalse = assume(State, Cond, false);
+if (!StFalse) { // both infeasible
+  ProgramStateRef StInfeasible = State->cloneAsInfeasible();
+  assert(StInfeasible->isInfeasible());
+  // Checkers might rely on the API contract that both returned states
+  // cannot be null. Thus, we return StInfeasible for both branches because
+  // it might happen 

[PATCH] D124807: [clang][dataflow] Avoid assert for invalid cast to BoolValue

2022-05-03 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua updated this revision to Diff 426711.
li.zhe.hua added a comment.

Update test to treat the PointerToBool conversion as an opaque boolean 
expression, and test it as such.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124807

Files:
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -1152,4 +1152,39 @@
   });
 }
 
+// FIXME: Remove this test once it provides no additional test coverage.
+TEST_F(FlowConditionTest, DoesNotAssertForImplicitCastToBool) {
+  std::string Code = R"(
+void target(int *Ptr) {
+  bool Foo = false;
+  if (Ptr) {
+Foo = true;
+/*[[p1]]*/
+  }
+
+  (void)0;
+  /*[[p2]]*/
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p2", _), Pair("p1", _)));
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const Environment  = Results[1].second.Env;
+auto  =
+*cast(Env1.getValue(*FooDecl, SkipPast::Reference));
+EXPECT_TRUE(Env1.flowConditionImplies(FooVal1));
+
+const Environment  = Results[0].second.Env;
+auto  =
+*cast(Env2.getValue(*FooDecl, SkipPast::Reference));
+EXPECT_FALSE(Env2.flowConditionImplies(FooVal2));
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -17,6 +17,7 @@
 #include 
 
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/IgnoreExpr.h"
 #include "clang/AST/OperationKinds.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
@@ -68,6 +69,28 @@
   return BlockPos - Pred.succ_begin();
 }
 
+/// Skips past any parentheses and implicit casts for `E`, except if they would
+/// perform a type conversion to bool.
+///
+/// FIXME: Its hard to tell if this is a principled solution or workaround to an
+/// issue. Re-evaluate the necessity for this function after we model pointers
+/// and integers in the framework.
+static const Expr *ignoreParenImpCastsExceptToBool(const Expr *E) {
+  const Expr *LastE = nullptr;
+  while (E != LastE) {
+LastE = E;
+E = IgnoreParensSingleStep(const_cast(E));
+
+bool WasBool = E->getType()->isBooleanType();
+auto *Unwrapped = IgnoreImplicitCastsExtraSingleStep(const_cast(E));
+if (WasBool && !Unwrapped->getType()->isBooleanType())
+  return E;
+
+E = Unwrapped;
+  }
+  return E;
+}
+
 /// Extends the flow condition of an environment based on a terminator
 /// statement.
 class TerminatorVisitor : public ConstStmtVisitor {
@@ -77,26 +100,26 @@
   : StmtToEnv(StmtToEnv), Env(Env), BlockSuccIdx(BlockSuccIdx) {}
 
   void VisitIfStmt(const IfStmt *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = ignoreParenImpCastsExceptToBool(S->getCond());
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
 
   void VisitWhileStmt(const WhileStmt *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = ignoreParenImpCastsExceptToBool(S->getCond());
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
 
   void VisitBinaryOperator(const BinaryOperator *S) {
 assert(S->getOpcode() == BO_LAnd || S->getOpcode() == BO_LOr);
-auto *LHS = S->getLHS()->IgnoreParenImpCasts();
+auto *LHS = ignoreParenImpCastsExceptToBool(S->getLHS());
 assert(LHS != nullptr);
 extendFlowCondition(*LHS);
   }
 
   void VisitConditionalOperator(const ConditionalOperator *S) {
-auto *Cond = S->getCond()->IgnoreParenImpCasts();
+auto *Cond = ignoreParenImpCastsExceptToBool(S->getCond());
 assert(Cond != nullptr);
 extendFlowCondition(*Cond);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-05-03 Thread Dave Green 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 rG64816e68f441: [AArch64] Support for Ampere1 core (authored 
by philipp.tomsich, committed by dmgreen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117112

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

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

[clang] 64816e6 - [AArch64] Support for Ampere1 core

2022-05-03 Thread David Green via cfe-commits

Author: Philipp Tomsich
Date: 2022-05-03T15:54:02+01:00
New Revision: 64816e68f4419a9e14c23be8aa96fa412bed7e12

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

LOG: [AArch64] Support for Ampere1 core

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

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

Added: 
llvm/lib/Target/AArch64/AArch64SchedAmpere1.td
llvm/lib/Target/AArch64/AArch64SchedPredAmpere.td

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

Removed: 




diff  --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index b240eb1428f78..7c7e7e326cf15 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, cortex-x1c, 
cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, apple-a12, 
apple-a13, apple-a14, apple-m1, apple-s4, apple-s5, exynos-m3, exynos-m4, 
exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, 
thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, cortex-x1c, 
cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, apple-a12, 
apple-a13, apple-a14, apple-m1, apple-s4, apple-s5, exynos-m3, exynos-m4, 
exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, 
thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, 
neoverse-v1, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-m1, apple-s4, apple-s5, exynos-m3, 
exynos-m4, exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, 
thunderx, thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel{{$}}
+// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, 
neoverse-v1, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-m1, apple-s4, apple-s5, exynos-m3, 
exynos-m4, exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, 
thunderx, thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel, 
ampere1{{$}}
 
 // RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix X86
 // X86: error: unknown target CPU 'not-a-cpu'

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.def 
b/llvm/include/llvm/Support/AArch64TargetParser.def
index 

  1   2   >