[PATCH] D46131: Add Microsoft Mangling for OpenCL Half Type

2018-04-26 Thread Vince Bridgers via Phabricator via cfe-commits
vbridgers created this revision.
vbridgers added reviewers: rnk, Anastasia, erichkeane.
vbridgers added a project: clang.
Herald added subscribers: cfe-commits, yaxunl.

Half-type mangling is accomplished following the method introduced by Erich 
Keane for mangling _Float16. Updated the half.cl LIT test to cover this 
particular case.


Repository:
  rC Clang

https://reviews.llvm.org/D46131

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenOpenCL/half.cl


Index: test/CodeGenOpenCL/half.cl
===
--- test/CodeGenOpenCL/half.cl
+++ test/CodeGenOpenCL/half.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck 
%s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-pc-win32 | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -1922,8 +1922,11 @@
 mangleArtificalTagType(TTK_Struct, "_Float16", {"__clang"});
 break;
 
-  case BuiltinType::Float128:
-  case BuiltinType::Half: {
+  case BuiltinType::Half:
+mangleArtificalTagType(TTK_Struct, "_Half", {"__clang"});
+break;
+
+  case BuiltinType::Float128: {
 DiagnosticsEngine &Diags = Context.getDiags();
 unsigned DiagID = Diags.getCustomDiagID(
 DiagnosticsEngine::Error, "cannot mangle this built-in %0 type yet");


Index: test/CodeGenOpenCL/half.cl
===
--- test/CodeGenOpenCL/half.cl
+++ test/CodeGenOpenCL/half.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-pc-win32 | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -1922,8 +1922,11 @@
 mangleArtificalTagType(TTK_Struct, "_Float16", {"__clang"});
 break;
 
-  case BuiltinType::Float128:
-  case BuiltinType::Half: {
+  case BuiltinType::Half:
+mangleArtificalTagType(TTK_Struct, "_Half", {"__clang"});
+break;
+
+  case BuiltinType::Float128: {
 DiagnosticsEngine &Diags = Context.getDiags();
 unsigned DiagID = Diags.getCustomDiagID(
 DiagnosticsEngine::Error, "cannot mangle this built-in %0 type yet");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80903: [analyzer] Ignore calculated indices of <= 0 in VLASizeChecker

2020-05-31 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: balazske, NoQ, martong, baloghadamsoftware, 
Szelethus, gamesh411.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, xazax.hun.
Herald added a project: clang.
vabridgers added a comment.

Not sure this is "correct", but it passes LITs with the new case, and it will 
at least get the discussion started :)


See https://bugs.llvm.org/show_bug.cgi?id=46128. The checker does not
yet comprehend constraints involving multiple symbols, so it's possible
to calculate a VLA size that's negative or 0. A LIT is added to catch
regressions, and this change simply bails if a VLA size of 0 or less is
calculated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80903

Files:
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/test/Analysis/vla.c


Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -137,3 +137,17 @@
   clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * 
sizeof(int));
   // expected-warning@-1{{TRUE}}
 }
+
+// https://bugs.llvm.org/show_bug.cgi?id=46128
+// analyzer doesn't handle more than simple sybolic expressions.
+// Just don't crash.
+extern void foo(void);
+int a;
+void b() {
+  int c = a + 1;
+  for (;;) {
+int d[c];
+for (; 0 < c;)
+  foo();
+  }
+} // no-crash
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -126,6 +126,11 @@
   // Size overflow check does not work with symbolic expressions because a
   // overflow situation can not be detected easily.
   uint64_t IndexL = IndexLVal->getZExtValue();
+  // constraints are not solved for expressions with multiple
+  // symbols, so just bail on invalid indices at this point.
+  if (IndexL <= 0)
+return nullptr;
+
   assert(IndexL > 0 && "Index length should have been checked for zero.");
   if (KnownSize <= SizeMax / IndexL) {
 KnownSize *= IndexL;


Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -137,3 +137,17 @@
   clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * sizeof(int));
   // expected-warning@-1{{TRUE}}
 }
+
+// https://bugs.llvm.org/show_bug.cgi?id=46128
+// analyzer doesn't handle more than simple sybolic expressions.
+// Just don't crash.
+extern void foo(void);
+int a;
+void b() {
+  int c = a + 1;
+  for (;;) {
+int d[c];
+for (; 0 < c;)
+  foo();
+  }
+} // no-crash
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -126,6 +126,11 @@
   // Size overflow check does not work with symbolic expressions because a
   // overflow situation can not be detected easily.
   uint64_t IndexL = IndexLVal->getZExtValue();
+  // constraints are not solved for expressions with multiple
+  // symbols, so just bail on invalid indices at this point.
+  if (IndexL <= 0)
+return nullptr;
+
   assert(IndexL > 0 && "Index length should have been checked for zero.");
   if (KnownSize <= SizeMax / IndexL) {
 KnownSize *= IndexL;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80903: [analyzer] Ignore calculated indices of <= 0 in VLASizeChecker

2020-05-31 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Not sure this is "correct", but it passes LITs with the new case, and it will 
at least get the discussion started :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80903



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


[PATCH] D80903: [analyzer] Ignore calculated indices of <= 0 in VLASizeChecker

2020-05-31 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 267534.
vabridgers added a comment.

Address some typos


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80903

Files:
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/test/Analysis/vla.c


Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -137,3 +137,17 @@
   clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * 
sizeof(int));
   // expected-warning@-1{{TRUE}}
 }
+
+// https://bugs.llvm.org/show_bug.cgi?id=46128
+// analyzer doesn't handle more than simple symbolic expressions.
+// Just don't crash.
+extern void foo(void);
+int a;
+void b() {
+  int c = a + 1;
+  for (;;) {
+int d[c];
+for (; 0 < c;)
+  foo();
+  }
+} // no-crash
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -126,6 +126,11 @@
   // Size overflow check does not work with symbolic expressions because a
   // overflow situation can not be detected easily.
   uint64_t IndexL = IndexLVal->getZExtValue();
+  // constraints are not solved for expressions with multiple
+  // symbols, so just bail on invalid indices at this point.
+  if (IndexL <= 0)
+return nullptr;
+
   assert(IndexL > 0 && "Index length should have been checked for zero.");
   if (KnownSize <= SizeMax / IndexL) {
 KnownSize *= IndexL;


Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -137,3 +137,17 @@
   clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * sizeof(int));
   // expected-warning@-1{{TRUE}}
 }
+
+// https://bugs.llvm.org/show_bug.cgi?id=46128
+// analyzer doesn't handle more than simple symbolic expressions.
+// Just don't crash.
+extern void foo(void);
+int a;
+void b() {
+  int c = a + 1;
+  for (;;) {
+int d[c];
+for (; 0 < c;)
+  foo();
+  }
+} // no-crash
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -126,6 +126,11 @@
   // Size overflow check does not work with symbolic expressions because a
   // overflow situation can not be detected easily.
   uint64_t IndexL = IndexLVal->getZExtValue();
+  // constraints are not solved for expressions with multiple
+  // symbols, so just bail on invalid indices at this point.
+  if (IndexL <= 0)
+return nullptr;
+
   assert(IndexL > 0 && "Index length should have been checked for zero.");
   if (KnownSize <= SizeMax / IndexL) {
 KnownSize *= IndexL;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80903: [analyzer] Ignore calculated indices of <= 0 in VLASizeChecker

2020-06-01 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp:114-115
 // Convert the array length to size_t.
 NonLoc IndexLength =
 SVB.evalCast(SizeD, SizeTy, SizeE->getType()).castAs();
 // Multiply the array length by the element size.

NoQ wrote:
> Do i understand correctly that this cast is the only difference between the 
> value that has been checked and the value on which the assertion is asserted?
Yes, looks that way to me. Let's see if Balasz, Gabor, Adam or Kristof responds 
in the next day or two? Thanks Artem!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80903



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


[PATCH] D80903: [analyzer] Ignore calculated indices of <= 0 in VLASizeChecker

2020-06-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 267882.
vabridgers added a comment.

Address comments from Artem and Balazs. This change just avoids the crash for 
now until a proper fix can be made.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80903

Files:
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/test/Analysis/vla.c


Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -137,3 +137,17 @@
   clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * 
sizeof(int));
   // expected-warning@-1{{TRUE}}
 }
+
+// https://bugs.llvm.org/show_bug.cgi?id=46128
+// analyzer doesn't handle more than simple symbolic expressions.
+// Just don't crash.
+extern void foo(void);
+int a;
+void b() {
+  int c = a + 1;
+  for (;;) {
+int d[c];
+for (; 0 < c;)
+  foo();
+  }
+} // no-crash
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -126,7 +126,12 @@
   // Size overflow check does not work with symbolic expressions because a
   // overflow situation can not be detected easily.
   uint64_t IndexL = IndexLVal->getZExtValue();
-  assert(IndexL > 0 && "Index length should have been checked for zero.");
+  // FIXME: See https://reviews.llvm.org/D80903 for discussion of
+  // some difference in assume and getKnownValue that leads to
+  // unexpected behavior. Just bail on IndexL == 0 at this point.
+  if (IndexL == 0)
+return nullptr;
+
   if (KnownSize <= SizeMax / IndexL) {
 KnownSize *= IndexL;
   } else {


Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -137,3 +137,17 @@
   clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * sizeof(int));
   // expected-warning@-1{{TRUE}}
 }
+
+// https://bugs.llvm.org/show_bug.cgi?id=46128
+// analyzer doesn't handle more than simple symbolic expressions.
+// Just don't crash.
+extern void foo(void);
+int a;
+void b() {
+  int c = a + 1;
+  for (;;) {
+int d[c];
+for (; 0 < c;)
+  foo();
+  }
+} // no-crash
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -126,7 +126,12 @@
   // Size overflow check does not work with symbolic expressions because a
   // overflow situation can not be detected easily.
   uint64_t IndexL = IndexLVal->getZExtValue();
-  assert(IndexL > 0 && "Index length should have been checked for zero.");
+  // FIXME: See https://reviews.llvm.org/D80903 for discussion of
+  // some difference in assume and getKnownValue that leads to
+  // unexpected behavior. Just bail on IndexL == 0 at this point.
+  if (IndexL == 0)
+return nullptr;
+
   if (KnownSize <= SizeMax / IndexL) {
 KnownSize *= IndexL;
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83970: [ASTImporter] Refactor ASTImporter to support custom downstream tests

2020-07-16 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added a reviewer: martong.
Herald added subscribers: cfe-commits, teemperor, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: clang.

The purpose of this change is to do a small refactoring of code in
ASTImporterTest.cpp by moving it to ASTImporterFixtures.h in order to
support tests of downstream custom types and minimize the "living
downstream burden" of frequent integrations from community to a
downstream repo that implements custom AST import tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83970

Files:
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -18,7 +18,6 @@
 #include "gtest/gtest.h"
 
 #include "ASTImporterFixtures.h"
-#include "MatchVerifier.h"
 
 namespace clang {
 namespace ast_matchers {
@@ -27,230 +26,6 @@
 using internal::BindableMatcher;
 using llvm::StringMap;
 
-// Base class for those tests which use the family of `testImport` functions.
-class TestImportBase
-: public CompilerOptionSpecificTest,
-  public ::testing::WithParamInterface> {
-
-  template 
-  llvm::Expected importNode(ASTUnit *From, ASTUnit *To,
-  ASTImporter &Importer, NodeType Node) {
-ASTContext &ToCtx = To->getASTContext();
-
-// Add 'From' file to virtual file system so importer can 'find' it
-// while importing SourceLocations. It is safe to add same file multiple
-// times - it just isn't replaced.
-StringRef FromFileName = From->getMainFileName();
-createVirtualFileIfNeeded(To, FromFileName,
-  From->getBufferForFile(FromFileName));
-
-auto Imported = Importer.Import(Node);
-
-if (Imported) {
-  // This should dump source locations and assert if some source locations
-  // were not imported.
-  SmallString<1024> ImportChecker;
-  llvm::raw_svector_ostream ToNothing(ImportChecker);
-  ToCtx.getTranslationUnitDecl()->print(ToNothing);
-
-  // This traverses the AST to catch certain bugs like poorly or not
-  // implemented subtrees.
-  (*Imported)->dump(ToNothing);
-}
-
-return Imported;
-  }
-
-  template 
-  testing::AssertionResult
-  testImport(const std::string &FromCode,
- const std::vector &FromArgs,
- const std::string &ToCode, const std::vector &ToArgs,
- MatchVerifier &Verifier,
- const BindableMatcher &SearchMatcher,
- const BindableMatcher &VerificationMatcher) {
-const char *const InputFileName = "input.cc";
-const char *const OutputFileName = "output.cc";
-
-std::unique_ptr FromAST = tooling::buildASTFromCodeWithArgs(
- FromCode, FromArgs, InputFileName),
- ToAST = tooling::buildASTFromCodeWithArgs(
- ToCode, ToArgs, OutputFileName);
-
-ASTContext &FromCtx = FromAST->getASTContext(),
-   &ToCtx = ToAST->getASTContext();
-
-ASTImporter Importer(ToCtx, ToAST->getFileManager(), FromCtx,
- FromAST->getFileManager(), false);
-
-auto FoundNodes = match(SearchMatcher, FromCtx);
-if (FoundNodes.size() != 1)
-  return testing::AssertionFailure()
- << "Multiple potential nodes were found!";
-
-auto ToImport = selectFirst(DeclToImportID, FoundNodes);
-if (!ToImport)
-  return testing::AssertionFailure() << "Node type mismatch!";
-
-// Sanity check: the node being imported should match in the same way as
-// the result node.
-BindableMatcher WrapperMatcher(VerificationMatcher);
-EXPECT_TRUE(Verifier.match(ToImport, WrapperMatcher));
-
-auto Imported = importNode(FromAST.get(), ToAST.get(), Importer, ToImport);
-if (!Imported) {
-  std::string ErrorText;
-  handleAllErrors(
-  Imported.takeError(),
-  [&ErrorText](const ImportError &Err) { ErrorText = Err.message(); });
-  return testing::AssertionFailure()
- << "Import failed, error: \"" << ErrorText << "\"!";
-}
-
-return Verifier.match(*Imported, WrapperMatcher);
-  }
-
-  template 
-  testing::AssertionResult
-  testImport(const std::string &FromCode,
- const std::vector &FromArgs,
- const std::string &ToCode, const std::vector &ToArgs,
- MatchVerifier &Verifier,
- const BindableMatcher &VerificationMatcher) {
-return testImport(
-FromCode, FromArgs, ToCode, ToArgs, Verifier,
-translationUnitDecl(
-has(namedDecl(hasName(DeclToImportID)).bind(DeclToImportID))),
-VerificationMatcher);
-  }
-
-protected:
-  std::vector getExtraArgs() const override { return GetP

[PATCH] D83970: [ASTImporter] Refactor ASTImporter to support custom downstream tests

2020-07-16 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

@shafik, Thanks! I'll wait 'til Gabor gets a chance to review before landing. 
Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83970



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


[PATCH] D83992: [ASTImporter] Add Visitor for TypedefNameDecl's

2020-07-16 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added a reviewer: martong.
Herald added subscribers: cfe-commits, teemperor, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a project: clang.

We found a case where Typedef Name Declarations were not being added
correctly when importing builtin types. This exposed the need for a
TypedefNameDecl visitor so these types can be added by RecordDecl and
fields.

This code is covered by the ASTImporterTest cases that use the implicit
struct __NSConstantString_tag definitions.

Thanks to @martong for the debugging assist!

Depends on D83970 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83992

Files:
  clang/lib/AST/ASTImporterLookupTable.cpp


Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -22,6 +22,20 @@
 struct Builder : RecursiveASTVisitor {
   ASTImporterLookupTable <
   Builder(ASTImporterLookupTable <) : LT(LT) {}
+
+  bool VisitTypedefNameDecl(TypedefNameDecl *D) {
+QualType Ty = D->getUnderlyingType();
+Ty = Ty.getCanonicalType();
+if (const auto *RTy = dyn_cast(Ty)) {
+  LT.add(RTy->getAsRecordDecl());
+  // iterate over the field decls, adding them
+  for (auto it : RTy->getAsRecordDecl()->fields()) {
+LT.add(it);
+  }
+}
+return true;
+  }
+
   bool VisitNamedDecl(NamedDecl *D) {
 LT.add(D);
 return true;


Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -22,6 +22,20 @@
 struct Builder : RecursiveASTVisitor {
   ASTImporterLookupTable <
   Builder(ASTImporterLookupTable <) : LT(LT) {}
+
+  bool VisitTypedefNameDecl(TypedefNameDecl *D) {
+QualType Ty = D->getUnderlyingType();
+Ty = Ty.getCanonicalType();
+if (const auto *RTy = dyn_cast(Ty)) {
+  LT.add(RTy->getAsRecordDecl());
+  // iterate over the field decls, adding them
+  for (auto it : RTy->getAsRecordDecl()->fields()) {
+LT.add(it);
+  }
+}
+return true;
+  }
+
   bool VisitNamedDecl(NamedDecl *D) {
 LT.add(D);
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83992: [ASTImporter] Add Visitor for TypedefNameDecl's

2020-07-16 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 278630.
vabridgers added a comment.

Fix lint pre-merge check


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83992

Files:
  clang/lib/AST/ASTImporterLookupTable.cpp


Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -22,6 +22,20 @@
 struct Builder : RecursiveASTVisitor {
   ASTImporterLookupTable <
   Builder(ASTImporterLookupTable <) : LT(LT) {}
+
+  bool VisitTypedefNameDecl(TypedefNameDecl *D) {
+QualType Ty = D->getUnderlyingType();
+Ty = Ty.getCanonicalType();
+if (const auto *RTy = dyn_cast(Ty)) {
+  LT.add(RTy->getAsRecordDecl());
+  // iterate over the field decls, adding them
+  for (auto *it : RTy->getAsRecordDecl()->fields()) {
+LT.add(it);
+  }
+}
+return true;
+  }
+
   bool VisitNamedDecl(NamedDecl *D) {
 LT.add(D);
 return true;


Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -22,6 +22,20 @@
 struct Builder : RecursiveASTVisitor {
   ASTImporterLookupTable <
   Builder(ASTImporterLookupTable <) : LT(LT) {}
+
+  bool VisitTypedefNameDecl(TypedefNameDecl *D) {
+QualType Ty = D->getUnderlyingType();
+Ty = Ty.getCanonicalType();
+if (const auto *RTy = dyn_cast(Ty)) {
+  LT.add(RTy->getAsRecordDecl());
+  // iterate over the field decls, adding them
+  for (auto *it : RTy->getAsRecordDecl()->fields()) {
+LT.add(it);
+  }
+}
+return true;
+  }
+
   bool VisitNamedDecl(NamedDecl *D) {
 LT.add(D);
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83992: [ASTImporter] Add Visitor for TypedefNameDecl's

2020-07-21 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I discussed with Gabor. We don't feel comfortable landing this without a 
covering negative test case, so I'll work on that a little more, see what I can 
come up with. Thanks Gabor!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83992



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


[PATCH] D83970: [ASTImporter] Refactor ASTImporter to support custom downstream tests

2020-07-21 Thread Vince Bridgers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG20157410862d: [ASTImporter] Refactor ASTImporter to support 
custom downstream tests (authored by vabridgers, committed by einvbri 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83970

Files:
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -18,7 +18,6 @@
 #include "gtest/gtest.h"
 
 #include "ASTImporterFixtures.h"
-#include "MatchVerifier.h"
 
 namespace clang {
 namespace ast_matchers {
@@ -27,230 +26,6 @@
 using internal::BindableMatcher;
 using llvm::StringMap;
 
-// Base class for those tests which use the family of `testImport` functions.
-class TestImportBase
-: public CompilerOptionSpecificTest,
-  public ::testing::WithParamInterface> {
-
-  template 
-  llvm::Expected importNode(ASTUnit *From, ASTUnit *To,
-  ASTImporter &Importer, NodeType Node) {
-ASTContext &ToCtx = To->getASTContext();
-
-// Add 'From' file to virtual file system so importer can 'find' it
-// while importing SourceLocations. It is safe to add same file multiple
-// times - it just isn't replaced.
-StringRef FromFileName = From->getMainFileName();
-createVirtualFileIfNeeded(To, FromFileName,
-  From->getBufferForFile(FromFileName));
-
-auto Imported = Importer.Import(Node);
-
-if (Imported) {
-  // This should dump source locations and assert if some source locations
-  // were not imported.
-  SmallString<1024> ImportChecker;
-  llvm::raw_svector_ostream ToNothing(ImportChecker);
-  ToCtx.getTranslationUnitDecl()->print(ToNothing);
-
-  // This traverses the AST to catch certain bugs like poorly or not
-  // implemented subtrees.
-  (*Imported)->dump(ToNothing);
-}
-
-return Imported;
-  }
-
-  template 
-  testing::AssertionResult
-  testImport(const std::string &FromCode,
- const std::vector &FromArgs,
- const std::string &ToCode, const std::vector &ToArgs,
- MatchVerifier &Verifier,
- const BindableMatcher &SearchMatcher,
- const BindableMatcher &VerificationMatcher) {
-const char *const InputFileName = "input.cc";
-const char *const OutputFileName = "output.cc";
-
-std::unique_ptr FromAST = tooling::buildASTFromCodeWithArgs(
- FromCode, FromArgs, InputFileName),
- ToAST = tooling::buildASTFromCodeWithArgs(
- ToCode, ToArgs, OutputFileName);
-
-ASTContext &FromCtx = FromAST->getASTContext(),
-   &ToCtx = ToAST->getASTContext();
-
-ASTImporter Importer(ToCtx, ToAST->getFileManager(), FromCtx,
- FromAST->getFileManager(), false);
-
-auto FoundNodes = match(SearchMatcher, FromCtx);
-if (FoundNodes.size() != 1)
-  return testing::AssertionFailure()
- << "Multiple potential nodes were found!";
-
-auto ToImport = selectFirst(DeclToImportID, FoundNodes);
-if (!ToImport)
-  return testing::AssertionFailure() << "Node type mismatch!";
-
-// Sanity check: the node being imported should match in the same way as
-// the result node.
-BindableMatcher WrapperMatcher(VerificationMatcher);
-EXPECT_TRUE(Verifier.match(ToImport, WrapperMatcher));
-
-auto Imported = importNode(FromAST.get(), ToAST.get(), Importer, ToImport);
-if (!Imported) {
-  std::string ErrorText;
-  handleAllErrors(
-  Imported.takeError(),
-  [&ErrorText](const ImportError &Err) { ErrorText = Err.message(); });
-  return testing::AssertionFailure()
- << "Import failed, error: \"" << ErrorText << "\"!";
-}
-
-return Verifier.match(*Imported, WrapperMatcher);
-  }
-
-  template 
-  testing::AssertionResult
-  testImport(const std::string &FromCode,
- const std::vector &FromArgs,
- const std::string &ToCode, const std::vector &ToArgs,
- MatchVerifier &Verifier,
- const BindableMatcher &VerificationMatcher) {
-return testImport(
-FromCode, FromArgs, ToCode, ToArgs, Verifier,
-translationUnitDecl(
-has(namedDecl(hasName(DeclToImportID)).bind(DeclToImportID))),
-VerificationMatcher);
-  }
-
-protected:
-  std::vector getExtraArgs() const override { return GetParam(); }
-
-public:
-
-  /// Test how AST node named "declToImport" located in the translation unit
-  /// of "FromCode" virtual file is imported to "ToCode" virtual file.
-  /// The verification is done by running AMatcher over the

[PATCH] D83992: [ASTImporter] Add Visitor for TypedefNameDecl's

2020-07-25 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 280700.
vabridgers added a comment.

Adding negative test case that exposes the original problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83992

Files:
  clang/lib/AST/ASTImporterLookupTable.cpp
  clang/test/Analysis/Inputs/ctu-import.c
  clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
  clang/test/Analysis/ctu-implicit.c


Index: clang/test/Analysis/ctu-implicit.c
===
--- /dev/null
+++ clang/test/Analysis/ctu-implicit.c
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir2
+// RUN: %clang_cc1  \
+// RUN:   -emit-pch -o %t/ctudir2/ctu-import.c.ast %S/Inputs/ctu-import.c
+// RUN: cp %S/Inputs/ctu-import.c.externalDefMap.ast-dump.txt 
%t/ctudir2/externalDefMap.txt
+// RUN: %clang_cc1 -analyze \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config  display-ctu-progress=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir2 \
+// RUN:   -verify %s
+
+void clang_analyzer_eval(int);
+
+int testStaticImplicit(void);
+int func(void) {
+  int ret = testStaticImplicit();
+  clang_analyzer_eval(ret == 4); // expected-warning{{TRUE}}
+  return testStaticImplicit();
+}
Index: clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
@@ -0,0 +1 @@
+c:@F@testStaticImplicit ctu-import.c.ast
Index: clang/test/Analysis/Inputs/ctu-import.c
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-import.c
@@ -0,0 +1,15 @@
+
+// Use an internal, implicitly defined type, called by
+// a function imported for CTU. This should not crash.
+int foo(void);
+int foobar(int skip) {
+  __NSConstantString str = {.flags = 1};
+
+  if (str.flags >= 0)
+str.flags = 0;
+  return 4;
+}
+
+int testStaticImplicit(void) {
+  return foobar(3);
+}
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -22,6 +22,20 @@
 struct Builder : RecursiveASTVisitor {
   ASTImporterLookupTable <
   Builder(ASTImporterLookupTable <) : LT(LT) {}
+
+  bool VisitTypedefNameDecl(TypedefNameDecl *D) {
+QualType Ty = D->getUnderlyingType();
+Ty = Ty.getCanonicalType();
+if (const auto *RTy = dyn_cast(Ty)) {
+  LT.add(RTy->getAsRecordDecl());
+  // iterate over the field decls, adding them
+  for (auto *it : RTy->getAsRecordDecl()->fields()) {
+LT.add(it);
+  }
+}
+return true;
+  }
+
   bool VisitNamedDecl(NamedDecl *D) {
 LT.add(D);
 return true;


Index: clang/test/Analysis/ctu-implicit.c
===
--- /dev/null
+++ clang/test/Analysis/ctu-implicit.c
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir2
+// RUN: %clang_cc1  \
+// RUN:   -emit-pch -o %t/ctudir2/ctu-import.c.ast %S/Inputs/ctu-import.c
+// RUN: cp %S/Inputs/ctu-import.c.externalDefMap.ast-dump.txt %t/ctudir2/externalDefMap.txt
+// RUN: %clang_cc1 -analyze \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config  display-ctu-progress=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir2 \
+// RUN:   -verify %s
+
+void clang_analyzer_eval(int);
+
+int testStaticImplicit(void);
+int func(void) {
+  int ret = testStaticImplicit();
+  clang_analyzer_eval(ret == 4); // expected-warning{{TRUE}}
+  return testStaticImplicit();
+}
Index: clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
@@ -0,0 +1 @@
+c:@F@testStaticImplicit ctu-import.c.ast
Index: clang/test/Analysis/Inputs/ctu-import.c
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-import.c
@@ -0,0 +1,15 @@
+
+// Use an internal, implicitly defined type, called by
+// a function imported for CTU. This should not crash.
+int foo(void);
+int foobar(int skip) {
+  __NSConstantString str = {.flags = 1};
+
+  if (str.flags >= 0)
+str.flags = 0;
+  return 4;
+}
+
+int testStaticImplicit(void) {
+  return foobar(3);
+}
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -22,6 +22,20 @@
 struct Builder : RecursiveASTVisito

[PATCH] D84898: clang-tidy] Add new checker for complex conditions with no meaning

2020-07-29 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
Herald added subscribers: cfe-commits, phosek, Charusso, mgorny.
Herald added a project: clang.
vabridgers requested review of this revision.

This checker finds cases where relational expressions have no meaning.
For example, (x <= y <= z) has no meaning, but just happens to parse to
something deterministic. (x <= y <= z) is parsed to ((x <= y) <= z).
The (x<=y) returns a boolean value which is promoted to an integral
context, 0 (for false) or 1 (for true). So when (x <= y) the expression
becomes (1 <= z) and when (x > y) the expression becomes (0 <= z). When
asked to give all warnings, gcc warns about this. While this may be the
intention in some programming contexts, it may not have been what the
programmer really wanted in all contexts. So it's best to implement this as a
tidy check to start with, get some experience using it, then perhaps promote
this check to a diagnostic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84898

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/ComplexConditionsCheck.cpp
  clang-tools-extra/clang-tidy/misc/ComplexConditionsCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-complex-conditions.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-complex-conditions.c

Index: clang-tools-extra/test/clang-tidy/checkers/misc-complex-conditions.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-complex-conditions.c
@@ -0,0 +1,118 @@
+// RUN: %check_clang_tidy %s misc-complex-conditions %t
+
+int case1(int p1, int p2, int p3) {
+  if (p1 < p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case2(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2 < p3))
+return 1;
+  return 0;
+}
+
+int case3(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2))
+return 1;
+  return 0;
+}
+
+int case4(int p1, int p2, int p3) {
+  // no warning
+  if ((p1) && (p3 < p2))
+return 1;
+  return 0;
+}
+
+int case5(int p1, int p2, int p3) {
+  while (p1 < p3 < p2)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case6(int p1, int p2, int p3) {
+  // should not warn
+  while (p1 && p3 < p2)
+return 1;
+  return 0;
+}
+
+int case7(int p1, int p2, int p3) {
+  // should not warn
+  while ((p1 < p3) < p2)
+return 1;
+  return 0;
+}
+
+int case8(int p1, int p2, int p3) {
+  int ret = p1 < p2 < p3;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+  return ret;
+}
+
+int case9(int p1, int p2, int p3) {
+  int ret = (p1 < p2) < p3 < p1;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+  return ret;
+}
+
+int case10(int p1, int p2, int p3) {
+  if (p1 <= p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case11(int p1, int p2, int p3) {
+  if (p1 < p2 <= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case12(int p1, int p2, int p3) {
+  if (p1 <= p2 <= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case13(int p1, int p2, int p3) {
+  if (p1 > p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case14(int p1, int p2, int p3) {
+  if (p1 > p2 > p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case15(int p1, int p2, int p3) {
+  if (p1 >= p2 > p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case16(int p1, int p2, int p3) {
+  if (p1 >= p2 >= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case17(int p1, int p2, int p3) {
+  // should not warn
+  if (p1 >= p2 || p3)
+return 1;
+  return 0;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc-complex-conditions.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-complex-conditions.rst
@@ -0,0 +1,46 @@
+.. title:: clang-tidy

[PATCH] D84898: clang-tidy] Add new checker for complex conditions with no meaning

2020-07-29 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 281769.
vabridgers added a comment.

Correct some simple mistakes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/ComplexConditionsCheck.cpp
  clang-tools-extra/clang-tidy/misc/ComplexConditionsCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-complex-conditions.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-complex-conditions.c

Index: clang-tools-extra/test/clang-tidy/checkers/misc-complex-conditions.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-complex-conditions.c
@@ -0,0 +1,118 @@
+// RUN: %check_clang_tidy %s misc-complex-conditions %t
+
+int case1(int p1, int p2, int p3) {
+  if (p1 < p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case2(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2 < p3))
+return 1;
+  return 0;
+}
+
+int case3(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2))
+return 1;
+  return 0;
+}
+
+int case4(int p1, int p2, int p3) {
+  // no warning
+  if ((p1) && (p3 < p2))
+return 1;
+  return 0;
+}
+
+int case5(int p1, int p2, int p3) {
+  while (p1 < p3 < p2)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case6(int p1, int p2, int p3) {
+  // should not warn
+  while (p1 && p3 < p2)
+return 1;
+  return 0;
+}
+
+int case7(int p1, int p2, int p3) {
+  // should not warn
+  while ((p1 < p3) < p2)
+return 1;
+  return 0;
+}
+
+int case8(int p1, int p2, int p3) {
+  int ret = p1 < p2 < p3;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+  return ret;
+}
+
+int case9(int p1, int p2, int p3) {
+  int ret = (p1 < p2) < p3 < p1;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+  return ret;
+}
+
+int case10(int p1, int p2, int p3) {
+  if (p1 <= p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case11(int p1, int p2, int p3) {
+  if (p1 < p2 <= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case12(int p1, int p2, int p3) {
+  if (p1 <= p2 <= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case13(int p1, int p2, int p3) {
+  if (p1 > p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case14(int p1, int p2, int p3) {
+  if (p1 > p2 > p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case15(int p1, int p2, int p3) {
+  if (p1 >= p2 > p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case16(int p1, int p2, int p3) {
+  if (p1 >= p2 >= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case17(int p1, int p2, int p3) {
+  // should not warn
+  if (p1 >= p2 || p3)
+return 1;
+  return 0;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc-complex-conditions.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-complex-conditions.rst
@@ -0,0 +1,46 @@
+.. title:: clang-tidy - misc-complex-conditions
+
+misc-complex-conditions
+===
+
+Detects conditions that have no mathematical meaing.
+
+It's possible to write an expression as (x <= y <= z), which has no meaning.
+This expression is parsed as ((x <= y) x<= z). A compare returns a boolean
+value when used in an integral context, is promoted to 0 (for false) or 1
+(for true). So when x <= y the expression becomes (1 <= z) and when (x > y)
+the expression becomes (0 <= z).
+
+While it's possible this is precisely what the programmer wanted, it's also
+possible this was a programming mistake, so this is appropriately flagged as
+a warning when explicitly enabled.
+
+Example cases warned include:
+
+.. code-block:: c
+
+   int a = p1 < p2 < p3;
+

[PATCH] D84898: clang-tidy] Add new checker for complex conditions with no meaning

2020-07-29 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 281770.
vabridgers added a comment.

Another update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/ComplexConditionsCheck.cpp
  clang-tools-extra/clang-tidy/misc/ComplexConditionsCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-complex-conditions.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-complex-conditions.c

Index: clang-tools-extra/test/clang-tidy/checkers/misc-complex-conditions.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-complex-conditions.c
@@ -0,0 +1,118 @@
+// RUN: %check_clang_tidy %s misc-complex-conditions %t
+
+int case1(int p1, int p2, int p3) {
+  if (p1 < p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case2(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2 < p3))
+return 1;
+  return 0;
+}
+
+int case3(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2))
+return 1;
+  return 0;
+}
+
+int case4(int p1, int p2, int p3) {
+  // no warning
+  if ((p1) && (p3 < p2))
+return 1;
+  return 0;
+}
+
+int case5(int p1, int p2, int p3) {
+  while (p1 < p3 < p2)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case6(int p1, int p2, int p3) {
+  // should not warn
+  while (p1 && p3 < p2)
+return 1;
+  return 0;
+}
+
+int case7(int p1, int p2, int p3) {
+  // should not warn
+  while ((p1 < p3) < p2)
+return 1;
+  return 0;
+}
+
+int case8(int p1, int p2, int p3) {
+  int ret = p1 < p2 < p3;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+  return ret;
+}
+
+int case9(int p1, int p2, int p3) {
+  int ret = (p1 < p2) < p3 < p1;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+  return ret;
+}
+
+int case10(int p1, int p2, int p3) {
+  if (p1 <= p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case11(int p1, int p2, int p3) {
+  if (p1 < p2 <= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case12(int p1, int p2, int p3) {
+  if (p1 <= p2 <= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case13(int p1, int p2, int p3) {
+  if (p1 > p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case14(int p1, int p2, int p3) {
+  if (p1 > p2 > p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case15(int p1, int p2, int p3) {
+  if (p1 >= p2 > p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case16(int p1, int p2, int p3) {
+  if (p1 >= p2 >= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [misc-complex-conditions]
+}
+
+int case17(int p1, int p2, int p3) {
+  // should not warn
+  if (p1 >= p2 || p3)
+return 1;
+  return 0;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc-complex-conditions.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-complex-conditions.rst
@@ -0,0 +1,46 @@
+.. title:: clang-tidy - misc-complex-conditions
+
+misc-complex-conditions
+===
+
+Detects conditions that have no mathematical meaing.
+
+It's possible to write an expression as (x <= y <= z), which has no meaning.
+This expression is parsed as ((x <= y) x<= z). A compare returns a boolean
+value when used in an integral context, is promoted to 0 (for false) or 1
+(for true). So when x <= y the expression becomes (1 <= z) and when (x > y)
+the expression becomes (0 <= z).
+
+While it's possible this is precisely what the programmer wanted, it's also
+possible this was a programming mistake, so this is appropriately flagged as
+a warning when explicitly enabled.
+
+Example cases warned include:
+
+.. code-block:: c
+
+   int a = p1 < p2 < p3;
+
+   int b = (

[PATCH] D84898: clang-tidy] Add new checker for complex conditions with no meaning

2020-07-29 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I believe this is ready for review. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

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


[PATCH] D84898: [clang-tidy] Add new checker for complex conditions with no meaning

2020-07-30 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thanks all for the prompt and actionable comments. I will address all comments 
directly and 1-1, but would like to bottom out on one point before driving this 
forward. @lebedev.ri commented this should be in the Clang front end rather 
than a tidy check. Can we reach a consensus on that comment before I proceed 
with either a tidy check renamed to bugprone (comment from @Eugene.Zelenko ) or 
implement this check in the front end, enabled only when all warnings are 
enabled? I had considered both approaches when I started this, and thought the 
tidy checker was the best first step.

Also, @njames93, I take your point the expression does have a mathematical 
meaning. I was following the gcc warning message for the same expression, but 
we can cast the warning however we like :) Do you have a suggestion about the 
warning? I like the general idea of a suggestion to use parenthesis to remove 
the ambiguity.

Thanks! - Vince


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

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


[PATCH] D84898: [clang-tidy] Add new checker for complex conditions with no meaning

2020-07-30 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 281937.
vabridgers marked 6 inline comments as done.
vabridgers added a comment.

Address most review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/ComplexConditionsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ComplexConditionsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-complex-conditions.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-complex-conditions.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-complex-conditions.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-complex-conditions.c
@@ -0,0 +1,118 @@
+// RUN: %check_clang_tidy %s bugprone-complex-conditions %t
+
+int case1(int p1, int p2, int p3) {
+  if (p1 < p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case2(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2 < p3))
+return 1;
+  return 0;
+}
+
+int case3(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2))
+return 1;
+  return 0;
+}
+
+int case4(int p1, int p2, int p3) {
+  // no warning
+  if ((p1) && (p3 < p2))
+return 1;
+  return 0;
+}
+
+int case5(int p1, int p2, int p3) {
+  while (p1 < p3 < p2)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case6(int p1, int p2, int p3) {
+  // should not warn
+  while (p1 && p3 < p2)
+return 1;
+  return 0;
+}
+
+int case7(int p1, int p2, int p3) {
+  // should not warn
+  while ((p1 < p3) < p2)
+return 1;
+  return 0;
+}
+
+int case8(int p1, int p2, int p3) {
+  int ret = p1 < p2 < p3;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+  return ret;
+}
+
+int case9(int p1, int p2, int p3) {
+  int ret = (p1 < p2) < p3 < p1;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+  return ret;
+}
+
+int case10(int p1, int p2, int p3) {
+  if (p1 <= p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case11(int p1, int p2, int p3) {
+  if (p1 < p2 <= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case12(int p1, int p2, int p3) {
+  if (p1 <= p2 <= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case13(int p1, int p2, int p3) {
+  if (p1 > p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case14(int p1, int p2, int p3) {
+  if (p1 > p2 > p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case15(int p1, int p2, int p3) {
+  if (p1 >= p2 > p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case16(int p1, int p2, int p3) {
+  if (p1 >= p2 >= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case17(int p1, int p2, int p3) {
+  // should not warn
+  if (p1 >= p2 || p3)
+return 1;
+  return 0;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -51,6 +51,7 @@
`bugprone-bad-signal-to-kill-thread `_,
`bugprone-bool-pointer-implicit-conversion `_, "Yes"
`bugprone-branch-clone `_,
+   `bugprone-complex-conditions `_,
`bugprone-copy-constructor-init `_, "Yes"
`bugprone-dangling-handle `_,
`bugprone-dynamic-static-initializers `_,
@@ -70,7 +71,7 @@
`bugprone-misplaced-widening-cast `_,
`bugprone-move-forwarding-reference `_, "Yes"
`bugprone-multiple-statement-macro `_,
-   `bugprone-no-escape `_, "Yes"
+   `bugprone-no-escape `_,
`bugprone-not-null-terminated-result `_, "Yes"
`bugprone-parent-virtual-call `_, "Yes"
`bugprone-posix-return `_, "Yes"

[PATCH] D84898: [clang-tidy] Add new checker for complex conditions with no meaning

2020-07-30 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I believe all review comments have been address, except for the discussion on 
implementing this in the CFE or as a tidy check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

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


[PATCH] D84898: [clang-tidy] Add new checker for complex conditions with no meaning

2020-07-30 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 281943.
vabridgers added a comment.

Address backticks in rst files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/ComplexConditionsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ComplexConditionsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-complex-conditions.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-complex-conditions.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-complex-conditions.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-complex-conditions.c
@@ -0,0 +1,118 @@
+// RUN: %check_clang_tidy %s bugprone-complex-conditions %t
+
+int case1(int p1, int p2, int p3) {
+  if (p1 < p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case2(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2 < p3))
+return 1;
+  return 0;
+}
+
+int case3(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2))
+return 1;
+  return 0;
+}
+
+int case4(int p1, int p2, int p3) {
+  // no warning
+  if ((p1) && (p3 < p2))
+return 1;
+  return 0;
+}
+
+int case5(int p1, int p2, int p3) {
+  while (p1 < p3 < p2)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case6(int p1, int p2, int p3) {
+  // should not warn
+  while (p1 && p3 < p2)
+return 1;
+  return 0;
+}
+
+int case7(int p1, int p2, int p3) {
+  // should not warn
+  while ((p1 < p3) < p2)
+return 1;
+  return 0;
+}
+
+int case8(int p1, int p2, int p3) {
+  int ret = p1 < p2 < p3;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+  return ret;
+}
+
+int case9(int p1, int p2, int p3) {
+  int ret = (p1 < p2) < p3 < p1;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+  return ret;
+}
+
+int case10(int p1, int p2, int p3) {
+  if (p1 <= p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case11(int p1, int p2, int p3) {
+  if (p1 < p2 <= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case12(int p1, int p2, int p3) {
+  if (p1 <= p2 <= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case13(int p1, int p2, int p3) {
+  if (p1 > p2 < p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case14(int p1, int p2, int p3) {
+  if (p1 > p2 > p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case15(int p1, int p2, int p3) {
+  if (p1 >= p2 > p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case16(int p1, int p2, int p3) {
+  if (p1 >= p2 >= p3)
+return 1;
+  return 0;
+  // CHECK-MESSAGES: warning: comparisons like `X<=Y<=Z` have no mathematical meaning [bugprone-complex-conditions]
+}
+
+int case17(int p1, int p2, int p3) {
+  // should not warn
+  if (p1 >= p2 || p3)
+return 1;
+  return 0;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -51,6 +51,7 @@
`bugprone-bad-signal-to-kill-thread `_,
`bugprone-bool-pointer-implicit-conversion `_, "Yes"
`bugprone-branch-clone `_,
+   `bugprone-complex-conditions `_,
`bugprone-copy-constructor-init `_, "Yes"
`bugprone-dangling-handle `_,
`bugprone-dynamic-static-initializers `_,
@@ -70,7 +71,7 @@
`bugprone-misplaced-widening-cast `_,
`bugprone-move-forwarding-reference `_, "Yes"
`bugprone-multiple-statement-macro `_,
-   `bugprone-no-escape `_, "Yes"
+   `bugprone-no-escape `_,
`bugprone-not-null-terminated-result `_, "Yes"
`bugprone-parent-virtual-call `_, "Yes"
`bugprone-posix-return `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/che

[PATCH] D84898: [clang-tidy] Add new checker for complex conditions with no meaning

2020-07-30 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked 2 inline comments as done.
vabridgers added a comment.

Thanks Eugene, I think the backtick issue has been addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

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


[PATCH] D77507: [clangd] Fix HitMapping assertion in Tokens.cpp

2020-04-05 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: ilya-biryukov, sammccall.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay.
Herald added a project: clang.

Extend test cases for tokens, and remove assertion that is unneeded and
hitting in Tokens.cpp.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77507

Files:
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -484,6 +484,57 @@
 ['EMPTY'_9, 'EMPTY_FUNC'_10) => [''_0, ''_0)
 ['EMPTY_FUNC'_10, ''_18) => [''_0, ''_0)
 )"},
+  // Baseline case, bugz: https://bugs.llvm.org/show_bug.cgi?id=45428
+  {R"cpp(
+#define NUM 42
+#define M2(a1,...) {__VA_ARGS__;}
+#define M1(a2,...) M2(a2,__VA_ARGS__)
+void foo(void) { M1(0, NUM); }
+)cpp",
+   R"(expanded tokens:
+  void foo ( void ) { { 42 ; } ; }
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define M2 ( a1 , ... ) { __VA_ARGS__ ; } # define M1 ( 
a2 , ... ) M2 ( a2 , __VA_ARGS__ ) void foo ( void ) { M1 ( 0 , NUM ) ; }
+  mappings:
+['#'_0, 'void'_30) => ['void'_0, 'void'_0)
+['M1'_36, ';'_42) => ['{'_6, ';'_10)
+)"},
+  // Reproducer, bugz: https://bugs.llvm.org/show_bug.cgi?id=45428.
+  // Causes mapping miss when invoking tryConsumeSpelledUntil
+  {R"cpp(
+#define NUM 42
+#define M2(a1,...) {__VA_ARGS__;}
+#define M1(a2,...) M2(a2,__VA_ARGS__)
+#define M0 M1 
+void foo(void) { M0(0, NUM); }
+)cpp",
+   R"(expanded tokens:
+  void foo ( void ) { { 42 ; } ; }
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define M2 ( a1 , ... ) { __VA_ARGS__ ; } # define M1 ( 
a2 , ... ) M2 ( a2 , __VA_ARGS__ ) # define M0 M1 void foo ( void ) { M0 ( 0 , 
NUM ) ; }
+  mappings:
+['#'_0, 'void'_34) => ['void'_0, 'void'_0)
+['M0'_40, 'NUM'_44) => ['{'_6, ';'_10)
+['NUM'_44, ')'_45) => [';'_10, ';'_10)
+[')'_45, ';'_46) => [';'_10, ';'_10)
+)"},
+  // Simplified version of new issue
+  {R"cpp(
+#define N 42 
+#define M0(a1) foo(a1)
+M0(N);
+)cpp",
+   R"(expanded tokens:
+  foo ( 42 ) ;
+file './input.cpp'
+  spelled tokens:
+# define N 42 # define M0 ( a1 ) foo ( a1 ) M0 ( N ) ;
+  mappings:
+['#'_0, 'M0'_14) => ['foo'_0, 'foo'_0)
+['M0'_14, ';'_18) => ['foo'_0, ';'_4)
+)"},
   // File ends with a macro replacement.
   {R"cpp(
 #define FOO 10+10;
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -614,10 +614,7 @@
 unsigned MappingBegin = SpelledIndex;
 ++SpelledIndex;
 
-bool HitMapping =
-tryConsumeSpelledUntil(File, EndOffset + 1, SpelledIndex).hasValue();
-(void)HitMapping;
-assert(!HitMapping && "recursive macro expansion?");
+(void)tryConsumeSpelledUntil(File, EndOffset + 1, SpelledIndex).hasValue();
 
 TokenBuffer::Mapping M;
 M.BeginExpanded = BeginExpanded;


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -484,6 +484,57 @@
 ['EMPTY'_9, 'EMPTY_FUNC'_10) => [''_0, ''_0)
 ['EMPTY_FUNC'_10, ''_18) => [''_0, ''_0)
 )"},
+  // Baseline case, bugz: https://bugs.llvm.org/show_bug.cgi?id=45428
+  {R"cpp(
+#define NUM 42
+#define M2(a1,...) {__VA_ARGS__;}
+#define M1(a2,...) M2(a2,__VA_ARGS__)
+void foo(void) { M1(0, NUM); }
+)cpp",
+   R"(expanded tokens:
+  void foo ( void ) { { 42 ; } ; }
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define M2 ( a1 , ... ) { __VA_ARGS__ ; } # define M1 ( a2 , ... ) M2 ( a2 , __VA_ARGS__ ) void foo ( void ) { M1 ( 0 , NUM ) ; }
+  mappings:
+['#'_0, 'void'_30) => ['void'_0, 'void'_0)
+['M1'_36, ';'_42) => ['{'_6, ';'_10)
+)"},
+  // Reproducer, bugz: https://bugs.llvm.org/show_bug.cgi?id=45428.
+  // Causes mapping miss when invoking tryConsumeSpelledUntil
+  {R"cpp(
+#define NUM 42
+#define M2(a1,...) {__VA_ARGS__;}
+#define M1(a2,...) M2(a2,__VA_ARGS__)
+#define M0 M1 
+void foo(void) { M0(0, NUM); }
+)cpp",
+   R"(expanded tokens:
+  void foo ( void ) { { 42 ; } ; }
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define M2 ( a1 , ... ) { __VA_ARGS__ ; } # define M1 ( a2 , ... ) M2 ( a2 , __VA_ARGS__ ) # define M0 M1 void foo ( void ) { M0 ( 0 , NUM ) ; }
+  mappings:
+['#'_0, 'void'_34) => ['void'_0, 'void'_0)
+['M0'_40, 'NUM'_44) => ['{'_6, ';'_10)

[PATCH] D77507: [clangd] Fix HitMapping assertion in Tokens.cpp

2020-04-05 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 255193.
vabridgers added a comment.

Remove extraneous test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77507

Files:
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -484,6 +484,42 @@
 ['EMPTY'_9, 'EMPTY_FUNC'_10) => [''_0, ''_0)
 ['EMPTY_FUNC'_10, ''_18) => [''_0, ''_0)
 )"},
+  // Baseline case, bugz: https://bugs.llvm.org/show_bug.cgi?id=45428
+  {R"cpp(
+#define NUM 42
+#define M2(a1,...) {__VA_ARGS__;}
+#define M1(a2,...) M2(a2,__VA_ARGS__)
+void foo(void) { M1(0, NUM); }
+)cpp",
+   R"(expanded tokens:
+  void foo ( void ) { { 42 ; } ; }
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define M2 ( a1 , ... ) { __VA_ARGS__ ; } # define M1 ( 
a2 , ... ) M2 ( a2 , __VA_ARGS__ ) void foo ( void ) { M1 ( 0 , NUM ) ; }
+  mappings:
+['#'_0, 'void'_30) => ['void'_0, 'void'_0)
+['M1'_36, ';'_42) => ['{'_6, ';'_10)
+)"},
+  // Reproducer, bugz: https://bugs.llvm.org/show_bug.cgi?id=45428.
+  // Causes mapping miss when invoking tryConsumeSpelledUntil
+  {R"cpp(
+#define NUM 42
+#define M2(a1,...) {__VA_ARGS__;}
+#define M1(a2,...) M2(a2,__VA_ARGS__)
+#define M0 M1 
+void foo(void) { M0(0, NUM); }
+)cpp",
+   R"(expanded tokens:
+  void foo ( void ) { { 42 ; } ; }
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define M2 ( a1 , ... ) { __VA_ARGS__ ; } # define M1 ( 
a2 , ... ) M2 ( a2 , __VA_ARGS__ ) # define M0 M1 void foo ( void ) { M0 ( 0 , 
NUM ) ; }
+  mappings:
+['#'_0, 'void'_34) => ['void'_0, 'void'_0)
+['M0'_40, 'NUM'_44) => ['{'_6, ';'_10)
+['NUM'_44, ')'_45) => [';'_10, ';'_10)
+[')'_45, ';'_46) => [';'_10, ';'_10)
+)"},
   // File ends with a macro replacement.
   {R"cpp(
 #define FOO 10+10;
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -614,10 +614,7 @@
 unsigned MappingBegin = SpelledIndex;
 ++SpelledIndex;
 
-bool HitMapping =
-tryConsumeSpelledUntil(File, EndOffset + 1, SpelledIndex).hasValue();
-(void)HitMapping;
-assert(!HitMapping && "recursive macro expansion?");
+(void)tryConsumeSpelledUntil(File, EndOffset + 1, SpelledIndex).hasValue();
 
 TokenBuffer::Mapping M;
 M.BeginExpanded = BeginExpanded;


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -484,6 +484,42 @@
 ['EMPTY'_9, 'EMPTY_FUNC'_10) => [''_0, ''_0)
 ['EMPTY_FUNC'_10, ''_18) => [''_0, ''_0)
 )"},
+  // Baseline case, bugz: https://bugs.llvm.org/show_bug.cgi?id=45428
+  {R"cpp(
+#define NUM 42
+#define M2(a1,...) {__VA_ARGS__;}
+#define M1(a2,...) M2(a2,__VA_ARGS__)
+void foo(void) { M1(0, NUM); }
+)cpp",
+   R"(expanded tokens:
+  void foo ( void ) { { 42 ; } ; }
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define M2 ( a1 , ... ) { __VA_ARGS__ ; } # define M1 ( a2 , ... ) M2 ( a2 , __VA_ARGS__ ) void foo ( void ) { M1 ( 0 , NUM ) ; }
+  mappings:
+['#'_0, 'void'_30) => ['void'_0, 'void'_0)
+['M1'_36, ';'_42) => ['{'_6, ';'_10)
+)"},
+  // Reproducer, bugz: https://bugs.llvm.org/show_bug.cgi?id=45428.
+  // Causes mapping miss when invoking tryConsumeSpelledUntil
+  {R"cpp(
+#define NUM 42
+#define M2(a1,...) {__VA_ARGS__;}
+#define M1(a2,...) M2(a2,__VA_ARGS__)
+#define M0 M1 
+void foo(void) { M0(0, NUM); }
+)cpp",
+   R"(expanded tokens:
+  void foo ( void ) { { 42 ; } ; }
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define M2 ( a1 , ... ) { __VA_ARGS__ ; } # define M1 ( a2 , ... ) M2 ( a2 , __VA_ARGS__ ) # define M0 M1 void foo ( void ) { M0 ( 0 , NUM ) ; }
+  mappings:
+['#'_0, 'void'_34) => ['void'_0, 'void'_0)
+['M0'_40, 'NUM'_44) => ['{'_6, ';'_10)
+['NUM'_44, ')'_45) => [';'_10, ';'_10)
+[')'_45, ';'_46) => [';'_10, ';'_10)
+)"},
   // File ends with a macro replacement.
   {R"cpp(
 #define FOO 10+10;
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -614,10 +614,7 @@
 unsigned MappingBegin = SpelledIndex;
 ++SpelledIndex;
 
-bool HitMapping =
-tryConsumeSpelledUntil(File, EndOffset + 1, SpelledIndex).hasValue();
-(void)H

[PATCH] D77507: [clangd] Fix HitMapping assertion in Tokens.cpp

2020-04-06 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thank you for the comments. I'll keep looking at this to find a proper fix, but 
any hints you may have would be greatly appreciated (debugging tips, 
strategies, areas of code to focus on). This code is new to me, so I may not be 
as efficient at tracking this down as yourself or Ilya. Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77507



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


[PATCH] D77507: [clangd] Fix HitMapping assertion in Tokens.cpp

2020-04-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

ayup, no problem and thanks for the fix. I'll abandon this change. Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77507



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


[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-08 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Landing this change depends on  https://reviews.llvm.org/D57226 to be pushed. 
Please review for now, and I'll be sure to push this only after 
https://reviews.llvm.org/D57226 is pushed. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721



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


[PATCH] D57226: [Fixed Point] [AST] Add an AST serialization code for fixed-point literals.

2020-04-08 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

https://reviews.llvm.org/D77721 depends on this serialization change for fixed 
point literals.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57226



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


[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-08 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: martong, leonardchan, ebevhan.
Herald added subscribers: cfe-commits, teemperor, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: clang.
vabridgers added a comment.

Landing this change depends on  https://reviews.llvm.org/D57226 to be pushed. 
Please review for now, and I'll be sure to push this only after 
https://reviews.llvm.org/D57226 is pushed. Thanks!


This patch adds support for importing fixed point literals, following
up to https://reviews.llvm.org/D46915 specifically for importing AST.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77721

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -986,6 +986,19 @@
   EXPECT_EQ(To, nullptr);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportFixedPointLiteralExpr) {
+  Decl *FromTU =
+  getTuDecl("void declToImport() { (void)1.0k; }", Lang_C, "input.c");
+  auto *From = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("declToImport")));
+  ASSERT_TRUE(From);
+  auto *To = Import(From, Lang_C);
+  ASSERT_TRUE(To);
+  EXPECT_TRUE(MatchVerifier().match(
+  To, functionDecl(hasName("declToImport"),
+   hasDescendant(fixedPointLiteral();
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportRecordDeclInFuncFromMacro) {
   Decl *FromTU = getTuDecl(
   "#define NONAME_SIZEOF(type) sizeof(struct{type *dummy;}) \n"
@@ -5938,7 +5951,7 @@
 DefaultTestValuesForRunOptions, );
 
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterOptionSpecificTestBase,
-DefaultTestValuesForRunOptions, );
+::testing::Values(ArgVector{"-ffixed-point"}), );
 
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ErrorHandlingTest,
 DefaultTestValuesForRunOptions, );
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -804,6 +804,8 @@
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher floatLiteral;
 const internal::VariadicDynCastAllOfMatcher imaginaryLiteral;
+const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -588,6 +588,7 @@
 ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
 ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
 ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
+ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
 ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
 ExpectedStmt VisitStringLiteral(StringLiteral *E);
 ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -6503,6 +6504,20 @@
   *ToSubExprOrErr, *ToTypeOrErr);
 }
 
+ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) {
+  auto ToTypeOrErr = import(E->getType());
+  if (!ToTypeOrErr)
+return ToTypeOrErr.takeError();
+
+  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
+  if (!ToLocationOrErr)
+return ToLocationOrErr.takeError();
+
+  return new (Importer.getToContext()) FixedPointLiteral(
+  Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
+  Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
+}
+
 ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) {
   ExpectedType ToTypeOrErr = import(E->getType());
   if (!ToTypeOrErr)
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2271,6 +2271,10 @@
 extern const internal::VariadicDynCastAllOfMatcher
 imaginaryLiteral;
 
+/// Matches fixed point literals
+extern const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
+
 /// Matches user defined literal operator call.
 ///
 /// Example match: "foo"_suffix
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -1491,7 +1491,6 @@
  public:
   FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
   

[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-08 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

@balazske, Thank you for the comments. I'll address and repost the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721



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


[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-08 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 256133.
vabridgers added a comment.

Remove extraneous code :/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -255,6 +255,7 @@
 struct ImportExpr : TestImportBase {};
 struct ImportType : TestImportBase {};
 struct ImportDecl : TestImportBase {};
+struct ImportFixedPointExpr : ImportExpr {};
 
 struct CanonicalRedeclChain : ASTImporterOptionSpecificTestBase {};
 
@@ -527,6 +528,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportFixedPointExpr, ImportFixedPointerLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport("void declToImport() { (void)1.0k; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+  testImport("void declToImport() { (void)0.75r; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+}
+
 TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -5931,6 +5940,9 @@
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportExpr,
 DefaultTestValuesForRunOptions, );
 
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFixedPointExpr,
+::testing::Values(ArgVector{"-ffixed-point"}), );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -804,6 +804,8 @@
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher floatLiteral;
 const internal::VariadicDynCastAllOfMatcher imaginaryLiteral;
+const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -588,6 +588,7 @@
 ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
 ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
 ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
+ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
 ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
 ExpectedStmt VisitStringLiteral(StringLiteral *E);
 ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -6503,6 +6504,20 @@
   *ToSubExprOrErr, *ToTypeOrErr);
 }
 
+ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) {
+  auto ToTypeOrErr = import(E->getType());
+  if (!ToTypeOrErr)
+return ToTypeOrErr.takeError();
+
+  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
+  if (!ToLocationOrErr)
+return ToLocationOrErr.takeError();
+
+  return new (Importer.getToContext()) FixedPointLiteral(
+  Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
+  Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
+}
+
 ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) {
   ExpectedType ToTypeOrErr = import(E->getType());
   if (!ToTypeOrErr)
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2271,6 +2271,10 @@
 extern const internal::VariadicDynCastAllOfMatcher
 imaginaryLiteral;
 
+/// Matches fixed point literals
+extern const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
+
 /// Matches user defined literal operator call.
 ///
 /// Example match: "foo"_suffix
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -1491,7 +1491,6 @@
  public:
   FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
 SourceLocation l, unsigned Scale);
-
   // Store the int as is without any bit shifting.
   static FixedPointLiteral *CreateFromRawInt(const ASTContext &C,
  const llvm::APInt &V,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llv

[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-08 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 256131.
vabridgers added a comment.

Addressed comments from @balazske.
Thanks for the tips and useful starting point from @martong


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -255,6 +255,7 @@
 struct ImportExpr : TestImportBase {};
 struct ImportType : TestImportBase {};
 struct ImportDecl : TestImportBase {};
+struct ImportFixedPointExpr : ImportExpr {};
 
 struct CanonicalRedeclChain : ASTImporterOptionSpecificTestBase {};
 
@@ -527,6 +528,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportFixedPointExpr, ImportFixedPointerLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport("void declToImport() { (void)1.0k; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+  testImport("void declToImport() { (void)0.75r; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+}
+
 TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -985,7 +994,20 @@
   auto *To = Import(From, Lang_C);
   EXPECT_EQ(To, nullptr);
 }
-
+#if 0
+TEST_P(ASTImporterOptionSpecificTestBase, ImportFixedPointLiteralExpr) {
+  Decl *FromTU =
+  getTuDecl("void declToImport() { (void)1.0k; }", Lang_C, "input.c");
+  auto *From = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("declToImport")));
+  ASSERT_TRUE(From);
+  auto *To = Import(From, Lang_C);
+  ASSERT_TRUE(To);
+  EXPECT_TRUE(MatchVerifier().match(
+  To, functionDecl(hasName("declToImport"),
+   hasDescendant(fixedPointLiteral();
+}
+#endif
 TEST_P(ASTImporterOptionSpecificTestBase, ImportRecordDeclInFuncFromMacro) {
   Decl *FromTU = getTuDecl(
   "#define NONAME_SIZEOF(type) sizeof(struct{type *dummy;}) \n"
@@ -5931,6 +5953,9 @@
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportExpr,
 DefaultTestValuesForRunOptions, );
 
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFixedPointExpr,
+::testing::Values(ArgVector{"-ffixed-point"}), );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -804,6 +804,8 @@
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher floatLiteral;
 const internal::VariadicDynCastAllOfMatcher imaginaryLiteral;
+const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -588,6 +588,7 @@
 ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
 ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
 ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
+ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
 ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
 ExpectedStmt VisitStringLiteral(StringLiteral *E);
 ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -6503,6 +6504,20 @@
   *ToSubExprOrErr, *ToTypeOrErr);
 }
 
+ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) {
+  auto ToTypeOrErr = import(E->getType());
+  if (!ToTypeOrErr)
+return ToTypeOrErr.takeError();
+
+  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
+  if (!ToLocationOrErr)
+return ToLocationOrErr.takeError();
+
+  return new (Importer.getToContext()) FixedPointLiteral(
+  Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
+  Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
+}
+
 ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) {
   ExpectedType ToTypeOrErr = import(E->getType());
   if (!ToTypeOrErr)
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2271,6 +2271,10 @@
 extern const internal::VariadicDynCastAllOfMatcher
 imaginaryLiteral;
 
+//

[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 256234.
vabridgers added a comment.

Address comment from @balazske


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -255,6 +255,7 @@
 struct ImportExpr : TestImportBase {};
 struct ImportType : TestImportBase {};
 struct ImportDecl : TestImportBase {};
+struct ImportFixedPointExpr : ImportExpr {};
 
 struct CanonicalRedeclChain : ASTImporterOptionSpecificTestBase {};
 
@@ -527,6 +528,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportFixedPointExpr, ImportFixedPointerLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport("void declToImport() { (void)1.0k; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+  testImport("void declToImport() { (void)0.75r; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+}
+
 TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -5931,6 +5940,9 @@
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportExpr,
 DefaultTestValuesForRunOptions, );
 
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFixedPointExpr,
+::testing::Values(ArgVector{"-ffixed-point"}), );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -804,6 +804,8 @@
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher 
floatLiteral;
 const internal::VariadicDynCastAllOfMatcher 
imaginaryLiteral;
+const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -588,6 +588,7 @@
 ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
 ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
 ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
+ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
 ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
 ExpectedStmt VisitStringLiteral(StringLiteral *E);
 ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -6503,6 +6504,20 @@
   *ToSubExprOrErr, *ToTypeOrErr);
 }
 
+ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) {
+  auto ToTypeOrErr = import(E->getType());
+  if (!ToTypeOrErr)
+return ToTypeOrErr.takeError();
+
+  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
+  if (!ToLocationOrErr)
+return ToLocationOrErr.takeError();
+
+  return new (Importer.getToContext()) FixedPointLiteral(
+  Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
+  Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
+}
+
 ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) {
   ExpectedType ToTypeOrErr = import(E->getType());
   if (!ToTypeOrErr)
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2271,6 +2271,10 @@
 extern const internal::VariadicDynCastAllOfMatcher
 imaginaryLiteral;
 
+/// Matches fixed point literals
+extern const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
+
 /// Matches user defined literal operator call.
 ///
 /// Example match: "foo"_suffix


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -255,6 +255,7 @@
 struct ImportExpr : TestImportBase {};
 struct ImportType : TestImportBase {};
 struct ImportDecl : TestImportBase {};
+struct ImportFixedPointExpr : ImportExpr {};
 
 struct CanonicalRedeclChain : ASTImporterOptionSpecificTestBase {};
 
@@ -527,6 +528,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportFixedPointExpr, ImportFixedPointerLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport("void d

[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked an inline comment as done.
vabridgers added a comment.

Ahhh yes, I see. I can get this done while we're waiting on 
https://reviews.llvm.org/D57226 to land. Thanks Gabor!!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721



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


[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 256339.
vabridgers added a comment.

Incorporate Gabor's suggestion for improving test coverage


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -255,6 +255,7 @@
 struct ImportExpr : TestImportBase {};
 struct ImportType : TestImportBase {};
 struct ImportDecl : TestImportBase {};
+struct ImportFixedPointExpr : ImportExpr {};
 
 struct CanonicalRedeclChain : ASTImporterOptionSpecificTestBase {};
 
@@ -527,6 +528,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportFixedPointExpr, ImportFixedPointerLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport("void declToImport() { (void)1.0k; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+  testImport("void declToImport() { (void)0.75r; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+}
+
 TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -5922,6 +5931,17 @@
   EXPECT_TRUE(ToA);
 }
 
+template 
+auto ExtendWithOptions(const T &Values, const ArgVector &Args) {
+  auto Copy = Values;
+  for (ArgVector &ArgV : Copy) {
+for (const std::string &Arg : Args) {
+  ArgV.push_back(Arg);
+}
+  }
+  return ::testing::ValuesIn(Copy);
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
@@ -5931,6 +5951,10 @@
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportExpr,
 DefaultTestValuesForRunOptions, );
 
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFixedPointExpr,
+ExtendWithOptions(DefaultTestArrayForRunOptions,
+  ArgVector{"-ffixed-point"}), );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
 DefaultTestValuesForRunOptions, );
 
Index: clang/unittests/AST/ASTImporterFixtures.h
===
--- clang/unittests/AST/ASTImporterFixtures.h
+++ clang/unittests/AST/ASTImporterFixtures.h
@@ -66,10 +66,13 @@
   }
 };
 
-const auto DefaultTestValuesForRunOptions = ::testing::Values(
+const auto DefaultTestArrayForRunOptions = std::array{
 ArgVector(), ArgVector{"-fdelayed-template-parsing"},
 ArgVector{"-fms-compatibility"},
-ArgVector{"-fdelayed-template-parsing", "-fms-compatibility"});
+ArgVector{"-fdelayed-template-parsing", "-fms-compatibility"}};
+
+const auto DefaultTestValuesForRunOptions =
+::testing::ValuesIn(DefaultTestArrayForRunOptions);
 
 // This class provides generic methods to write tests which can check internal
 // attributes of AST nodes like getPreviousDecl(), isVirtual(), etc. Also,
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -804,6 +804,8 @@
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher floatLiteral;
 const internal::VariadicDynCastAllOfMatcher imaginaryLiteral;
+const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -588,6 +588,7 @@
 ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
 ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
 ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
+ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
 ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
 ExpectedStmt VisitStringLiteral(StringLiteral *E);
 ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -6503,6 +6504,20 @@
   *ToSubExprOrErr, *ToTypeOrErr);
 }
 
+ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) {
+  auto ToTypeOrErr = import(E->getType());
+  if (!ToTypeOrErr)
+return ToTypeOrErr.takeError();
+
+  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
+  if (!ToLocationOrErr)
+return ToLocationOrErr.takeError();
+
+  return new (Importer.getToContext()) FixedPointLiteral(
+  Importer.getToContext(), E->getValue(), *T

[PATCH] D50256: [Analyzer] Basic support for multiplication and division in the constraint manager (for == and != only)

2020-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

ping! Any chance of this patch being accepted? This patch can help some SA 
false positives.


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

https://reviews.llvm.org/D50256



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


[PATCH] D49074: [Analyzer] Basic support for multiplication and division in the constraint manager

2020-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

ping! Any chance of this patch being accepted? This patch can help some SA 
false positives.


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

https://reviews.llvm.org/D49074



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


[PATCH] D57226: [Fixed Point] [AST] Add an AST serialization code for fixed-point literals.

2020-04-13 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 257183.
vabridgers added a comment.

Address comments from rjmccall


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57226

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Expr.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/PCH/Inputs/fixed-point-literal.h
  clang/test/PCH/fixed-point-literal.c

Index: clang/test/PCH/fixed-point-literal.c
===
--- /dev/null
+++ clang/test/PCH/fixed-point-literal.c
@@ -0,0 +1,15 @@
+
+// Test this without pch.
+// RUN: %clang_cc1 -ffixed-point -include %S/Inputs/fixed-point-literal.h -fsyntax-only -ast-print -o - %s | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -ffixed-point -emit-pch -o %t %S/Inputs/fixed-point-literal.h
+// RUN: %clang_cc1 -ffixed-point -include-pch %t -fsyntax-only -ast-print -o - %s | FileCheck %s
+
+// CHECK: const short _Fract sf = -0.25r;
+// CHECK: const _Fract f = 0.75r;
+// CHECK: const long _Accum la = 25.25lk;
+
+short _Fract sf2 = sf;
+_Fract f2 = f;
+long _Accum la2 = la;
Index: clang/test/PCH/Inputs/fixed-point-literal.h
===
--- /dev/null
+++ clang/test/PCH/Inputs/fixed-point-literal.h
@@ -0,0 +1,5 @@
+// Header for PCH test fixed-point-literal.c
+
+const short _Fract sf = -0.25r;
+const _Fract f = 0.75r;
+const long _Accum la = 25.25lk;
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -629,8 +629,9 @@
 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
   VisitExpr(E);
   Record.AddSourceLocation(E->getLocation());
+  Record.push_back(E->getScale());
   Record.AddAPInt(E->getValue());
-  Code = serialization::EXPR_INTEGER_LITERAL;
+  Code = serialization::EXPR_FIXEDPOINT_LITERAL;
 }
 
 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -571,6 +571,7 @@
   RECORD(EXPR_PREDEFINED);
   RECORD(EXPR_DECL_REF);
   RECORD(EXPR_INTEGER_LITERAL);
+  RECORD(EXPR_FIXEDPOINT_LITERAL);
   RECORD(EXPR_FLOATING_LITERAL);
   RECORD(EXPR_IMAGINARY_LITERAL);
   RECORD(EXPR_STRING_LITERAL);
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -605,6 +605,7 @@
 void ASTStmtReader::VisitFixedPointLiteral(FixedPointLiteral *E) {
   VisitExpr(E);
   E->setLocation(readSourceLocation());
+  E->setScale(Record.readInt());
   E->setValue(Record.getContext(), Record.readAPInt());
 }
 
@@ -2857,6 +2858,10 @@
   S = IntegerLiteral::Create(Context, Empty);
   break;
 
+case EXPR_FIXEDPOINT_LITERAL:
+  S = FixedPointLiteral::Create(Context, Empty);
+  break;
+
 case EXPR_FLOATING_LITERAL:
   S = FloatingLiteral::Create(Context, Empty);
   break;
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -913,6 +913,11 @@
   return new (C) FixedPointLiteral(C, V, type, l, Scale);
 }
 
+FixedPointLiteral *FixedPointLiteral::Create(const ASTContext &C,
+ EmptyShell Empty) {
+  return new (C) FixedPointLiteral(Empty);
+}
+
 std::string FixedPointLiteral::getValueAsString(unsigned Radix) const {
   // Currently the longest decimal number that can be printed is the max for an
   // unsigned long _Accum: 4294967295.976716935634613037109375
Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serialization/ASTBitCodes.h
+++ clang/include/clang/Serialization/ASTBitCodes.h
@@ -1762,21 +1762,21 @@
   /// A CXXBoolLiteralExpr record.
   EXPR_CXX_BOOL_LITERAL,
 
-  EXPR_CXX_NULL_PTR_LITERAL,  // CXXNullPtrLiteralExpr
-  EXPR_CXX_TYPEID_EXPR,   // CXXTypeidExpr (of expr).
-  EXPR_CXX_TYPEID_TYPE,   // CXXTypeidExpr (of type).
-  EXPR_CXX_THIS,  // CXXThisExpr
-  EXPR_CXX_THROW, // CXXThrowExpr
-  EXPR_CXX_DEFAULT_ARG,   // CXXDefaultArgExpr
-  EXPR_CXX_DEFAULT_INIT,  // CXXDefaultInitExpr
-  EXPR_CXX_BIND_TEMPORARY,// CXXBindTemporaryExpr
+  EXPR_CXX_NULL_PTR_LITERAL, // CXXNullPtrLiteralExpr
+  EXPR_CXX_TYPEID_EXPR,  // CXXTypeidExpr (of expr).
+  EXPR_CXX_TYPEID_TYPE,

[PATCH] D57226: [Fixed Point] [AST] Add an AST serialization code for fixed-point literals.

2020-04-14 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thank you for the comments. Please do let me know when this patch is ready to 
land. Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57226



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


[PATCH] D57226: [Fixed Point] [AST] Add an AST serialization code for fixed-point literals.

2020-04-14 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 257287.
vabridgers added a comment.

update based on comments from rjmccall


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57226

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Expr.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/PCH/Inputs/fixed-point-literal.h
  clang/test/PCH/fixed-point-literal.c

Index: clang/test/PCH/fixed-point-literal.c
===
--- /dev/null
+++ clang/test/PCH/fixed-point-literal.c
@@ -0,0 +1,15 @@
+
+// Test this without pch.
+// RUN: %clang_cc1 -ffixed-point -include %S/Inputs/fixed-point-literal.h -fsyntax-only -ast-print -o - %s | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -ffixed-point -emit-pch -o %t %S/Inputs/fixed-point-literal.h
+// RUN: %clang_cc1 -ffixed-point -include-pch %t -fsyntax-only -ast-print -o - %s | FileCheck %s
+
+// CHECK: const short _Fract sf = -0.25r;
+// CHECK: const _Fract f = 0.75r;
+// CHECK: const long _Accum la = 25.25lk;
+
+short _Fract sf2 = sf;
+_Fract f2 = f;
+long _Accum la2 = la;
Index: clang/test/PCH/Inputs/fixed-point-literal.h
===
--- /dev/null
+++ clang/test/PCH/Inputs/fixed-point-literal.h
@@ -0,0 +1,5 @@
+// Header for PCH test fixed-point-literal.c
+
+const short _Fract sf = -0.25r;
+const _Fract f = 0.75r;
+const long _Accum la = 25.25lk;
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -629,8 +629,9 @@
 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
   VisitExpr(E);
   Record.AddSourceLocation(E->getLocation());
+  Record.push_back(E->getScale());
   Record.AddAPInt(E->getValue());
-  Code = serialization::EXPR_INTEGER_LITERAL;
+  Code = serialization::EXPR_FIXEDPOINT_LITERAL;
 }
 
 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -571,6 +571,7 @@
   RECORD(EXPR_PREDEFINED);
   RECORD(EXPR_DECL_REF);
   RECORD(EXPR_INTEGER_LITERAL);
+  RECORD(EXPR_FIXEDPOINT_LITERAL);
   RECORD(EXPR_FLOATING_LITERAL);
   RECORD(EXPR_IMAGINARY_LITERAL);
   RECORD(EXPR_STRING_LITERAL);
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -605,6 +605,7 @@
 void ASTStmtReader::VisitFixedPointLiteral(FixedPointLiteral *E) {
   VisitExpr(E);
   E->setLocation(readSourceLocation());
+  E->setScale(Record.readInt());
   E->setValue(Record.getContext(), Record.readAPInt());
 }
 
@@ -2857,6 +2858,10 @@
   S = IntegerLiteral::Create(Context, Empty);
   break;
 
+case EXPR_FIXEDPOINT_LITERAL:
+  S = FixedPointLiteral::Create(Context, Empty);
+  break;
+
 case EXPR_FLOATING_LITERAL:
   S = FloatingLiteral::Create(Context, Empty);
   break;
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -913,6 +913,11 @@
   return new (C) FixedPointLiteral(C, V, type, l, Scale);
 }
 
+FixedPointLiteral *FixedPointLiteral::Create(const ASTContext &C,
+ EmptyShell Empty) {
+  return new (C) FixedPointLiteral(Empty);
+}
+
 std::string FixedPointLiteral::getValueAsString(unsigned Radix) const {
   // Currently the longest decimal number that can be printed is the max for an
   // unsigned long _Accum: 4294967295.976716935634613037109375
Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serialization/ASTBitCodes.h
+++ clang/include/clang/Serialization/ASTBitCodes.h
@@ -1887,6 +1887,9 @@
   EXPR_COAWAIT,
   EXPR_COYIELD,
   EXPR_DEPENDENT_COAWAIT,
+
+  // FixedPointLiteral
+  EXPR_FIXEDPOINT_LITERAL,
 };
 
 /// The kinds of designators that can occur in a
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -1484,7 +1484,7 @@
   SourceLocation Loc;
   unsigned Scale;
 
-  /// \brief Construct an empty integer literal.
+  /// \brief Construct an empty fixed-point literal.
   explicit FixedPointLiteral(EmptyShell Empty)
   : Expr(FixedPointLiteralClass, Empty) {}
 
@@ -1498,6 +1498,9 @@
 

[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-14 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Do these changes look ok to land? https://reviews.llvm.org/D57226 is pushed. 
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721



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


[PATCH] D57226: [Fixed Point] [AST] Add an AST serialization code for fixed-point literals.

2020-04-14 Thread Vince Bridgers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG161fc1d9118f: [Fixed Point] [AST] Add an AST serialization 
code for fixed-point literals. (authored by vabridgers, committed by einvbri 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57226

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Expr.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/PCH/Inputs/fixed-point-literal.h
  clang/test/PCH/fixed-point-literal.c

Index: clang/test/PCH/fixed-point-literal.c
===
--- /dev/null
+++ clang/test/PCH/fixed-point-literal.c
@@ -0,0 +1,15 @@
+
+// Test this without pch.
+// RUN: %clang_cc1 -ffixed-point -include %S/Inputs/fixed-point-literal.h -fsyntax-only -ast-print -o - %s | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -ffixed-point -emit-pch -o %t %S/Inputs/fixed-point-literal.h
+// RUN: %clang_cc1 -ffixed-point -include-pch %t -fsyntax-only -ast-print -o - %s | FileCheck %s
+
+// CHECK: const short _Fract sf = -0.25r;
+// CHECK: const _Fract f = 0.75r;
+// CHECK: const long _Accum la = 25.25lk;
+
+short _Fract sf2 = sf;
+_Fract f2 = f;
+long _Accum la2 = la;
Index: clang/test/PCH/Inputs/fixed-point-literal.h
===
--- /dev/null
+++ clang/test/PCH/Inputs/fixed-point-literal.h
@@ -0,0 +1,5 @@
+// Header for PCH test fixed-point-literal.c
+
+const short _Fract sf = -0.25r;
+const _Fract f = 0.75r;
+const long _Accum la = 25.25lk;
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -629,8 +629,9 @@
 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
   VisitExpr(E);
   Record.AddSourceLocation(E->getLocation());
+  Record.push_back(E->getScale());
   Record.AddAPInt(E->getValue());
-  Code = serialization::EXPR_INTEGER_LITERAL;
+  Code = serialization::EXPR_FIXEDPOINT_LITERAL;
 }
 
 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -571,6 +571,7 @@
   RECORD(EXPR_PREDEFINED);
   RECORD(EXPR_DECL_REF);
   RECORD(EXPR_INTEGER_LITERAL);
+  RECORD(EXPR_FIXEDPOINT_LITERAL);
   RECORD(EXPR_FLOATING_LITERAL);
   RECORD(EXPR_IMAGINARY_LITERAL);
   RECORD(EXPR_STRING_LITERAL);
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -605,6 +605,7 @@
 void ASTStmtReader::VisitFixedPointLiteral(FixedPointLiteral *E) {
   VisitExpr(E);
   E->setLocation(readSourceLocation());
+  E->setScale(Record.readInt());
   E->setValue(Record.getContext(), Record.readAPInt());
 }
 
@@ -2857,6 +2858,10 @@
   S = IntegerLiteral::Create(Context, Empty);
   break;
 
+case EXPR_FIXEDPOINT_LITERAL:
+  S = FixedPointLiteral::Create(Context, Empty);
+  break;
+
 case EXPR_FLOATING_LITERAL:
   S = FloatingLiteral::Create(Context, Empty);
   break;
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -913,6 +913,11 @@
   return new (C) FixedPointLiteral(C, V, type, l, Scale);
 }
 
+FixedPointLiteral *FixedPointLiteral::Create(const ASTContext &C,
+ EmptyShell Empty) {
+  return new (C) FixedPointLiteral(Empty);
+}
+
 std::string FixedPointLiteral::getValueAsString(unsigned Radix) const {
   // Currently the longest decimal number that can be printed is the max for an
   // unsigned long _Accum: 4294967295.976716935634613037109375
Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serialization/ASTBitCodes.h
+++ clang/include/clang/Serialization/ASTBitCodes.h
@@ -1887,6 +1887,9 @@
   EXPR_COAWAIT,
   EXPR_COYIELD,
   EXPR_DEPENDENT_COAWAIT,
+
+  // FixedPointLiteral
+  EXPR_FIXEDPOINT_LITERAL,
 };
 
 /// The kinds of designators that can occur in a
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -1484,7 +1484,7 @@
   SourceLocation Loc;
   unsigned Scale;
 
-  /// \brief Construct an empty integer literal.
+  /// \brief Construct an empty fix

[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-15 Thread Vince Bridgers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG789215dc0db1: [ASTImporter] Add support for importing fixed 
point literals (authored by vabridgers, committed by einvbri 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -255,6 +255,7 @@
 struct ImportExpr : TestImportBase {};
 struct ImportType : TestImportBase {};
 struct ImportDecl : TestImportBase {};
+struct ImportFixedPointExpr : ImportExpr {};
 
 struct CanonicalRedeclChain : ASTImporterOptionSpecificTestBase {};
 
@@ -527,6 +528,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportFixedPointExpr, ImportFixedPointerLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport("void declToImport() { (void)1.0k; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+  testImport("void declToImport() { (void)0.75r; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+}
+
 TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -5922,6 +5931,17 @@
   EXPECT_TRUE(ToA);
 }
 
+template 
+auto ExtendWithOptions(const T &Values, const ArgVector &Args) {
+  auto Copy = Values;
+  for (ArgVector &ArgV : Copy) {
+for (const std::string &Arg : Args) {
+  ArgV.push_back(Arg);
+}
+  }
+  return ::testing::ValuesIn(Copy);
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
@@ -5931,6 +5951,10 @@
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportExpr,
 DefaultTestValuesForRunOptions, );
 
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFixedPointExpr,
+ExtendWithOptions(DefaultTestArrayForRunOptions,
+  ArgVector{"-ffixed-point"}), );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
 DefaultTestValuesForRunOptions, );
 
Index: clang/unittests/AST/ASTImporterFixtures.h
===
--- clang/unittests/AST/ASTImporterFixtures.h
+++ clang/unittests/AST/ASTImporterFixtures.h
@@ -66,10 +66,13 @@
   }
 };
 
-const auto DefaultTestValuesForRunOptions = ::testing::Values(
+const auto DefaultTestArrayForRunOptions = std::array{
 ArgVector(), ArgVector{"-fdelayed-template-parsing"},
 ArgVector{"-fms-compatibility"},
-ArgVector{"-fdelayed-template-parsing", "-fms-compatibility"});
+ArgVector{"-fdelayed-template-parsing", "-fms-compatibility"}};
+
+const auto DefaultTestValuesForRunOptions =
+::testing::ValuesIn(DefaultTestArrayForRunOptions);
 
 // This class provides generic methods to write tests which can check internal
 // attributes of AST nodes like getPreviousDecl(), isVirtual(), etc. Also,
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -804,6 +804,8 @@
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher floatLiteral;
 const internal::VariadicDynCastAllOfMatcher imaginaryLiteral;
+const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -588,6 +588,7 @@
 ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
 ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
 ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
+ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
 ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
 ExpectedStmt VisitStringLiteral(StringLiteral *E);
 ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -6503,6 +6504,20 @@
   *ToSubExprOrErr, *ToTypeOrErr);
 }
 
+ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) {
+  auto ToTypeOrErr = import(E->getType());
+  if (!ToTypeOrErr)
+return ToTypeOrErr.takeError();
+
+  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
+  if (!ToLocationOrErr)
+return ToLocationOrErr.takeError()

[PATCH] D80903: [analyzer] Ignore calculated indices of <= 0 in VLASizeChecker

2020-06-04 Thread Vince Bridgers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbd425825411a: [analyzer] Ignore calculated indices of <= 
0 in VLASizeChecker (authored by vabridgers, committed by einvbri 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80903

Files:
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/test/Analysis/vla.c


Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -137,3 +137,17 @@
   clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * 
sizeof(int));
   // expected-warning@-1{{TRUE}}
 }
+
+// https://bugs.llvm.org/show_bug.cgi?id=46128
+// analyzer doesn't handle more than simple symbolic expressions.
+// Just don't crash.
+extern void foo(void);
+int a;
+void b() {
+  int c = a + 1;
+  for (;;) {
+int d[c];
+for (; 0 < c;)
+  foo();
+  }
+} // no-crash
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -126,7 +126,12 @@
   // Size overflow check does not work with symbolic expressions because a
   // overflow situation can not be detected easily.
   uint64_t IndexL = IndexLVal->getZExtValue();
-  assert(IndexL > 0 && "Index length should have been checked for zero.");
+  // FIXME: See https://reviews.llvm.org/D80903 for discussion of
+  // some difference in assume and getKnownValue that leads to
+  // unexpected behavior. Just bail on IndexL == 0 at this point.
+  if (IndexL == 0)
+return nullptr;
+
   if (KnownSize <= SizeMax / IndexL) {
 KnownSize *= IndexL;
   } else {


Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -137,3 +137,17 @@
   clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * sizeof(int));
   // expected-warning@-1{{TRUE}}
 }
+
+// https://bugs.llvm.org/show_bug.cgi?id=46128
+// analyzer doesn't handle more than simple symbolic expressions.
+// Just don't crash.
+extern void foo(void);
+int a;
+void b() {
+  int c = a + 1;
+  for (;;) {
+int d[c];
+for (; 0 < c;)
+  foo();
+  }
+} // no-crash
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -126,7 +126,12 @@
   // Size overflow check does not work with symbolic expressions because a
   // overflow situation can not be detected easily.
   uint64_t IndexL = IndexLVal->getZExtValue();
-  assert(IndexL > 0 && "Index length should have been checked for zero.");
+  // FIXME: See https://reviews.llvm.org/D80903 for discussion of
+  // some difference in assume and getKnownValue that leads to
+  // unexpected behavior. Just bail on IndexL == 0 at this point.
+  if (IndexL == 0)
+return nullptr;
+
   if (KnownSize <= SizeMax / IndexL) {
 KnownSize *= IndexL;
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82940: [ASTReader][ASTWriter][PCH][Modules] Fix (de)serialization of SwitchCases

2020-07-01 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

This patch addresses a crash we started seeing in our CTU analysis runs as a 
result of 05843dc6ab97a00cbde7aa4f08bf3692eb83109d 
. Gabor, 
maybe I can generate a regression test for the problems that 
05843dc6ab97a00cbde7aa4f08bf3692eb83109d 
 caused as 
a follow up for whatever is committed here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82940



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


[PATCH] D83006: [ASTImporter] Add unittest case for friend decl import

2020-07-01 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added a reviewer: martong.
Herald added subscribers: cfe-commits, teemperor, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: clang.
vabridgers updated this revision to Diff 274945.
vabridgers added a comment.

Updated commit header.


This change adds a matching test case for the recent bug fix to
VisitFriendDecl in ASTImporterLookup.cpp.

See https://reviews.llvm.org/D82882 for details.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83006

Files:
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3417,6 +3417,29 @@
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
+   ClassTemplateFriendDecl) {
+  auto Code =
+  R"(
+  template  class X {  friend T; };
+  struct Y {};
+  template class X;
+)";
+  Decl *ToTU = getToTuDecl(Code, Lang_CXX11);
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromSpec =
+  FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+  auto *ToSpec =
+  FirstDeclMatcher().match(
+  ToTU, classTemplateSpecializationDecl());
+
+  auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+  EXPECT_EQ(ImportedSpec, ToSpec);
+  EXPECT_EQ(1u, DeclCounter().match(
+ToTU, classTemplateSpecializationDecl()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase,
ClassTemplatePartialSpecializationsShouldNotBeDuplicated) {
   auto Code =
   R"(


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3417,6 +3417,29 @@
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
+   ClassTemplateFriendDecl) {
+  auto Code =
+  R"(
+  template  class X {  friend T; };
+  struct Y {};
+  template class X;
+)";
+  Decl *ToTU = getToTuDecl(Code, Lang_CXX11);
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromSpec =
+  FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+  auto *ToSpec =
+  FirstDeclMatcher().match(
+  ToTU, classTemplateSpecializationDecl());
+
+  auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+  EXPECT_EQ(ImportedSpec, ToSpec);
+  EXPECT_EQ(1u, DeclCounter().match(
+ToTU, classTemplateSpecializationDecl()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase,
ClassTemplatePartialSpecializationsShouldNotBeDuplicated) {
   auto Code =
   R"(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83006: [ASTImporter] Add unittest case for friend decl import

2020-07-01 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 274945.
vabridgers added a comment.

Updated commit header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83006

Files:
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3417,6 +3417,29 @@
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
+   ClassTemplateFriendDecl) {
+  auto Code =
+  R"(
+  template  class X {  friend T; };
+  struct Y {};
+  template class X;
+)";
+  Decl *ToTU = getToTuDecl(Code, Lang_CXX11);
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromSpec =
+  FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+  auto *ToSpec =
+  FirstDeclMatcher().match(
+  ToTU, classTemplateSpecializationDecl());
+
+  auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+  EXPECT_EQ(ImportedSpec, ToSpec);
+  EXPECT_EQ(1u, DeclCounter().match(
+ToTU, classTemplateSpecializationDecl()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase,
ClassTemplatePartialSpecializationsShouldNotBeDuplicated) {
   auto Code =
   R"(


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3417,6 +3417,29 @@
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
+   ClassTemplateFriendDecl) {
+  auto Code =
+  R"(
+  template  class X {  friend T; };
+  struct Y {};
+  template class X;
+)";
+  Decl *ToTU = getToTuDecl(Code, Lang_CXX11);
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromSpec =
+  FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+  auto *ToSpec =
+  FirstDeclMatcher().match(
+  ToTU, classTemplateSpecializationDecl());
+
+  auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+  EXPECT_EQ(ImportedSpec, ToSpec);
+  EXPECT_EQ(1u, DeclCounter().match(
+ToTU, classTemplateSpecializationDecl()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase,
ClassTemplatePartialSpecializationsShouldNotBeDuplicated) {
   auto Code =
   R"(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83006: [ASTImporter] Add unittest case for friend decl import

2020-07-01 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I confirmed that a crash was seen when the change for 
https://reviews.llvm.org/D82882 was reverted, then the unittests pass with the 
change associated with https://reviews.llvm.org/D82882.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83006



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


[PATCH] D83006: [ASTImporter] Add unittest case for friend decl import

2020-07-01 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 274961.
vabridgers added a comment.

update for pre-merge lint checks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83006

Files:
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3416,6 +3416,26 @@
   EXPECT_TRUE(ToCtor->hasBody());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ClassTemplateFriendDecl) {
+  const auto *Code =
+  R"(
+  template  class X {  friend T; };
+  struct Y {};
+  template class X;
+)";
+  Decl *ToTU = getToTuDecl(Code, Lang_CXX11);
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+  auto *ToSpec = FirstDeclMatcher().match(
+  ToTU, classTemplateSpecializationDecl());
+
+  auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+  EXPECT_EQ(ImportedSpec, ToSpec);
+  EXPECT_EQ(1u, DeclCounter().match(
+ToTU, classTemplateSpecializationDecl()));
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ClassTemplatePartialSpecializationsShouldNotBeDuplicated) {
   auto Code =


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3416,6 +3416,26 @@
   EXPECT_TRUE(ToCtor->hasBody());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ClassTemplateFriendDecl) {
+  const auto *Code =
+  R"(
+  template  class X {  friend T; };
+  struct Y {};
+  template class X;
+)";
+  Decl *ToTU = getToTuDecl(Code, Lang_CXX11);
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+  auto *ToSpec = FirstDeclMatcher().match(
+  ToTU, classTemplateSpecializationDecl());
+
+  auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+  EXPECT_EQ(ImportedSpec, ToSpec);
+  EXPECT_EQ(1u, DeclCounter().match(
+ToTU, classTemplateSpecializationDecl()));
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ClassTemplatePartialSpecializationsShouldNotBeDuplicated) {
   auto Code =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83009: [clang][Serialization] Don't duplicate the body of LambdaExpr during deserialization

2020-07-01 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I cherry picked this change and retried the case that was failing. This change 
addresses the issue I was seeing. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83009



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


[PATCH] D83006: [ASTImporter] Add unittest case for friend decl import

2020-07-02 Thread Vince Bridgers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG59f1bf46f8c2: [ASTImporter] Add unittest case for friend 
decl import (authored by vabridgers, committed by einvbri 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83006

Files:
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3416,6 +3416,26 @@
   EXPECT_TRUE(ToCtor->hasBody());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ClassTemplateFriendDecl) {
+  const auto *Code =
+  R"(
+  template  class X {  friend T; };
+  struct Y {};
+  template class X;
+)";
+  Decl *ToTU = getToTuDecl(Code, Lang_CXX11);
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+  auto *ToSpec = FirstDeclMatcher().match(
+  ToTU, classTemplateSpecializationDecl());
+
+  auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+  EXPECT_EQ(ImportedSpec, ToSpec);
+  EXPECT_EQ(1u, DeclCounter().match(
+ToTU, classTemplateSpecializationDecl()));
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ClassTemplatePartialSpecializationsShouldNotBeDuplicated) {
   auto Code =


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3416,6 +3416,26 @@
   EXPECT_TRUE(ToCtor->hasBody());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ClassTemplateFriendDecl) {
+  const auto *Code =
+  R"(
+  template  class X {  friend T; };
+  struct Y {};
+  template class X;
+)";
+  Decl *ToTU = getToTuDecl(Code, Lang_CXX11);
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+  auto *ToSpec = FirstDeclMatcher().match(
+  ToTU, classTemplateSpecializationDecl());
+
+  auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+  EXPECT_EQ(ImportedSpec, ToSpec);
+  EXPECT_EQ(1u, DeclCounter().match(
+ToTU, classTemplateSpecializationDecl()));
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ClassTemplatePartialSpecializationsShouldNotBeDuplicated) {
   auto Code =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82882: [ASTImporter] Fix AST import crash for a friend decl

2020-06-30 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added a reviewer: martong.
Herald added subscribers: cfe-commits, teemperor, rnkovacs, kristof.beyls.
Herald added a reviewer: a.sidorin.
Herald added a project: clang.

Running CTU testing, we found that VisitFriendDecl in
ASTImporterLookup.cpp was not handling a particular non-dependent case,
so we reached the llvm_unreachable case.

The FriendDecl and QualType not handled were:

(gdb) p D->dump()
FriendDecl 0x75cf1958
< <>, 'nlohmann::basic_json, bool, long long, unsigned long long, double,
  std::allocator, adl_serializer, std::vector>>':'nlohmann::basic_json, bool, long long, unsigned long
  long, double, std::allocator, adl_serializer, std::vector>>'

(gdb) p Ty->dump()
SubstTemplateTypeParmType 0x75cf0df0 'class
nlohmann::basic_json, _Bool, long long, unsigned long long, double,
  std::allocator, adl_serializer, class std::vector > >' sugar

| -TemplateTypeParmType 0x7643ea40 'BasicJsonType' dependent depth 0 |
|

index 0

| `-TemplateTypeParm 0x7643e9e8 'BasicJsonType' |
|

`-RecordType 0x1012ad20 'class nlohmann::basic_json, _Bool, long long, unsigned
long long, double, std::allocator, adl_serializer, class
std::vector > >'

  `-ClassTemplateSpecialization 0x1012ab68 'basic_json'


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82882

Files:
  clang/lib/AST/ASTImporterLookupTable.cpp


Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -45,7 +45,10 @@
   LT.add(RTy->getAsCXXRecordDecl());
 else if (const auto *SpecTy = dyn_cast(Ty))
   LT.add(SpecTy->getAsCXXRecordDecl());
-else if (isa(Ty)) {
+else if (const auto *SubstTy = 
dyn_cast(Ty)) {
+  if (SubstTy->getAsCXXRecordDecl())
+  LT.add(SubstTy->getAsCXXRecordDecl());
+} else if (isa(Ty)) {
   // We do not put friend typedefs to the lookup table because
   // ASTImporter does not organize typedefs into redecl chains.
 } else {


Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -45,7 +45,10 @@
   LT.add(RTy->getAsCXXRecordDecl());
 else if (const auto *SpecTy = dyn_cast(Ty))
   LT.add(SpecTy->getAsCXXRecordDecl());
-else if (isa(Ty)) {
+else if (const auto *SubstTy = dyn_cast(Ty)) {
+  if (SubstTy->getAsCXXRecordDecl())
+  LT.add(SubstTy->getAsCXXRecordDecl());
+} else if (isa(Ty)) {
   // We do not put friend typedefs to the lookup table because
   // ASTImporter does not organize typedefs into redecl chains.
 } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82882: [ASTImporter] Fix AST import crash for a friend decl

2020-06-30 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 274542.
vabridgers added a comment.

fix pre-merge checks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82882

Files:
  clang/lib/AST/ASTImporterLookupTable.cpp


Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -45,7 +45,11 @@
   LT.add(RTy->getAsCXXRecordDecl());
 else if (const auto *SpecTy = dyn_cast(Ty))
   LT.add(SpecTy->getAsCXXRecordDecl());
-else if (isa(Ty)) {
+else if (const auto *SubstTy =
+ dyn_cast(Ty)) {
+  if (SubstTy->getAsCXXRecordDecl())
+LT.add(SubstTy->getAsCXXRecordDecl());
+} else if (isa(Ty)) {
   // We do not put friend typedefs to the lookup table because
   // ASTImporter does not organize typedefs into redecl chains.
 } else {


Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -45,7 +45,11 @@
   LT.add(RTy->getAsCXXRecordDecl());
 else if (const auto *SpecTy = dyn_cast(Ty))
   LT.add(SpecTy->getAsCXXRecordDecl());
-else if (isa(Ty)) {
+else if (const auto *SubstTy =
+ dyn_cast(Ty)) {
+  if (SubstTy->getAsCXXRecordDecl())
+LT.add(SubstTy->getAsCXXRecordDecl());
+} else if (isa(Ty)) {
   // We do not put friend typedefs to the lookup table because
   // ASTImporter does not organize typedefs into redecl chains.
 } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82882: [ASTImporter] Fix AST import crash for a friend decl

2020-06-30 Thread Vince Bridgers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGecae672ac2ac: [ASTImporter] Fix AST import crash for a 
friend decl (authored by vabridgers, committed by einvbri 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82882

Files:
  clang/lib/AST/ASTImporterLookupTable.cpp


Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -45,7 +45,11 @@
   LT.add(RTy->getAsCXXRecordDecl());
 else if (const auto *SpecTy = dyn_cast(Ty))
   LT.add(SpecTy->getAsCXXRecordDecl());
-else if (isa(Ty)) {
+else if (const auto *SubstTy =
+ dyn_cast(Ty)) {
+  if (SubstTy->getAsCXXRecordDecl())
+LT.add(SubstTy->getAsCXXRecordDecl());
+} else if (isa(Ty)) {
   // We do not put friend typedefs to the lookup table because
   // ASTImporter does not organize typedefs into redecl chains.
 } else {


Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -45,7 +45,11 @@
   LT.add(RTy->getAsCXXRecordDecl());
 else if (const auto *SpecTy = dyn_cast(Ty))
   LT.add(SpecTy->getAsCXXRecordDecl());
-else if (isa(Ty)) {
+else if (const auto *SubstTy =
+ dyn_cast(Ty)) {
+  if (SubstTy->getAsCXXRecordDecl())
+LT.add(SubstTy->getAsCXXRecordDecl());
+} else if (isa(Ty)) {
   // We do not put friend typedefs to the lookup table because
   // ASTImporter does not organize typedefs into redecl chains.
 } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84898: [clang-tidy] Add new checker for complex conditions with no meaning

2020-08-01 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

@njames93, I'll take a crack at implementing a cfe diagnostic for this, see how 
far I get. Cheers :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

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


[PATCH] D84898: [clang-tidy] Add new checker for complex conditions with no meaning

2020-08-01 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Looks like this can be implemented as a warning in the cfe (as @lebedev.ri 
suggested). I'll probably abandon this review, but will keep it active until I 
have the alternative cfe warning patch prepared.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
vabridgers requested review of this revision.

This changes add a new warning named -Wcompare-op-parentheses that's
part of the -Wparentheses diagnostic group. This diagnostic produces a
warning when a pattern like 'x<=y<=z' is found. When this pattern is not
qualified by parentheses, it's equivalent to '(x<=y ? 1 : 0) <= z',
which is a different interpretation from that of ordinary mathematical
notation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85097

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/warn-compare-op-parentheses.c

Index: clang/test/Sema/warn-compare-op-parentheses.c
===
--- /dev/null
+++ clang/test/Sema/warn-compare-op-parentheses.c
@@ -0,0 +1,129 @@
+// RUN: %clang_cc1 -fsyntax-only -Wcompare-op-parentheses -verify %s
+
+int case1(int p1, int p2, int p3) {
+  if (p1 < p2 < p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+}
+
+int case2(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2 < p3))
+return 1;
+  return 0;
+}
+
+int case3(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2))
+return 1;
+  return 0;
+}
+
+int case4(int p1, int p2, int p3) {
+  // no warning
+  if ((p1) && (p3 < p2))
+return 1;
+  return 0;
+}
+
+int case5(int p1, int p2, int p3) {
+  while (p1 < p3 < p2)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+}
+
+int case6(int p1, int p2, int p3) {
+  // should not warn
+  while (p1 && p3 < p2)
+return 1;
+  return 0;
+}
+
+int case7(int p1, int p2, int p3) {
+  // should not warn
+  while ((p1 < p3) < p2)
+return 1;
+  return 0;
+}
+
+int case8(int p1, int p2, int p3) {
+  int ret = p1 < p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  return ret;
+}
+
+int case9(int p1, int p2, int p3) {
+  int ret = (p1 < p2) < p3 < p1;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  return ret;
+}
+
+int case10(int p1, int p2, int p3) {
+  if (p1 <= p2 < p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<=' expression to silence this warning}}
+}
+
+int case11(int p1, int p2, int p3) {
+  if (p1 < p2 <= p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+}
+
+int case12(int p1, int p2, int p3) {
+  if (p1 <= p2 <= p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<=' expression to silence this warning}}
+}
+
+int case13(int p1, int p2, int p3) {
+  if (p1 > p2 < p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>' expression to silence this warning}}
+}
+
+int case14(int p1, int p2, int p3) {
+  if (p1 > p2 > p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>' expression to silence this warning}}
+}
+
+int case15(int p1, int p2, int p3) {
+  if (p1 >= p2 > p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>=' expression to silence this warning}}
+}
+
+int case16(int p1, int p2, int p3) {
+  if (p1 >= p2 >= p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>=' expression to silence this warning}}
+}
+
+int case17(int p1, int p2, int p3) {
+  // should not warn
+  if (p1 >= p2 || p3)
+return 1;
+  return 0;
+}
Index: clang/test/Misc/warning-wall.c
===

[PATCH] D84898: [clang-tidy] Add new checker for complex conditions with no meaning

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I've posted https://reviews.llvm.org/D85097 to replace this review. 
https://reviews.llvm.org/D85097 implements this check in the CFE instead of as 
a tidy check per recommendation from @lebedev.ri . If acceptable, I'll abandon 
this review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84898

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

This is an implementation in the CFE, after submitting and getting comments on 
https://reviews.llvm.org/D84898.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thank you for the comments @lebedev.ri and @Quuxplusone. I'll abandon the tidy 
approach (https://reviews.llvm.org/D84898) and work towards satisfying these 
review comments (and any others), driving towards acceptance. Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 282471.
vabridgers marked 2 inline comments as done.
vabridgers added a comment.

Address simpler issues brought up during review so far.
Tests to be refactored, and a fixit added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/warn-compare-op-parentheses.c

Index: clang/test/Sema/warn-compare-op-parentheses.c
===
--- /dev/null
+++ clang/test/Sema/warn-compare-op-parentheses.c
@@ -0,0 +1,129 @@
+// RUN: %clang_cc1 -fsyntax-only -Wcompare-op-parentheses -verify %s
+
+int case1(int p1, int p2, int p3) {
+  if (p1 < p2 < p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+}
+
+int case2(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2 < p3))
+return 1;
+  return 0;
+}
+
+int case3(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2))
+return 1;
+  return 0;
+}
+
+int case4(int p1, int p2, int p3) {
+  // no warning
+  if ((p1) && (p3 < p2))
+return 1;
+  return 0;
+}
+
+int case5(int p1, int p2, int p3) {
+  while (p1 < p3 < p2)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+}
+
+int case6(int p1, int p2, int p3) {
+  // should not warn
+  while (p1 && p3 < p2)
+return 1;
+  return 0;
+}
+
+int case7(int p1, int p2, int p3) {
+  // should not warn
+  while ((p1 < p3) < p2)
+return 1;
+  return 0;
+}
+
+int case8(int p1, int p2, int p3) {
+  int ret = p1 < p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  return ret;
+}
+
+int case9(int p1, int p2, int p3) {
+  int ret = (p1 < p2) < p3 < p1;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  return ret;
+}
+
+int case10(int p1, int p2, int p3) {
+  if (p1 <= p2 < p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<=' expression to silence this warning}}
+}
+
+int case11(int p1, int p2, int p3) {
+  if (p1 < p2 <= p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+}
+
+int case12(int p1, int p2, int p3) {
+  if (p1 <= p2 <= p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<=' expression to silence this warning}}
+}
+
+int case13(int p1, int p2, int p3) {
+  if (p1 > p2 < p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>' expression to silence this warning}}
+}
+
+int case14(int p1, int p2, int p3) {
+  if (p1 > p2 > p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>' expression to silence this warning}}
+}
+
+int case15(int p1, int p2, int p3) {
+  if (p1 >= p2 > p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>=' expression to silence this warning}}
+}
+
+int case16(int p1, int p2, int p3) {
+  if (p1 >= p2 >= p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>=' expression to silence this warning}}
+}
+
+int case17(int p1, int p2, int p3) {
+  // should not warn
+  if (p1 >= p2 || p3)
+return 1;
+  return 0;
+}
Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -1,99 +1,9 @@
-RUN: diagtool tree -Wall > %t 2>&1
-RUN: FileCheck --input-file=%t %s
+RUN : diag

[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thanks for the comments. I posted an update for the simpler issues, working on 
refactoring the test cases and creating a fixit. Thanks for the good and 
actionable review comments!




Comment at: clang/docs/DiagnosticsReference.rst:2853
 
+-Wcompare-no-parentheses
+

Quuxplusone wrote:
> s/-no-/-op-/
fixed, thank you!



Comment at: clang/docs/DiagnosticsReference.rst:9885
 
-Also controls `-Wbitwise-conditional-parentheses`_, 
`-Wbitwise-op-parentheses`_, `-Wdangling-else`_, `-Wlogical-not-parentheses`_, 
`-Wlogical-op-parentheses`_, `-Woverloaded-shift-op-parentheses`_, 
`-Wparentheses-equality`_, `-Wshift-op-parentheses`_.
+Also controls `-Wbitwise-conditional-parentheses`_, 
`-Wbitwise-op-parentheses`_, `-Wcompare-no-parentheses`, `-Wdangling-else`_, 
`-Wlogical-not-parentheses`_, `-Wlogical-op-parentheses`_, 
`-Woverloaded-shift-op-parentheses`_, `-Wparentheses-equality`_, 
`-Wshift-op-parentheses`_.
 

Quuxplusone wrote:
> s/-no-/-op-/
> And what's going on with all these trailing underscores? If they're 
> important, you're missing one.
missed that, thank you!



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6135
+  "comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'">,
+  InGroup, DefaultIgnore;
+

Quuxplusone wrote:
> Why is this `x<=y<=z` instead of the simpler `x "half-open range" common case)?
> IMHO you should mention the name "chained comparisons" here, since I think 
> that's what people coming from such languages will understand.
Thanks Arthur. I modeled the warning message after gcc's warning message. We 
found internally that while gcc detected this, clang did not. See 
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options ...

-Wparentheses
Warn if parentheses are omitted in certain contexts, such as when there is an 
assignment in a context where a truth value is expected, or when operators are 
nested whose precedence people often get confused about.

Also warn if a comparison like x<=y<=z appears; this is equivalent to (x<=y ? 1 
: 0) <= z, which is a different interpretation from that of ordinary 
mathematical notation.
...

While this is the gcc documentation, we can craft whatever message we see fit 
at this point in time :)  I'll add "chained" comparison for this next update, 
we can tailor the message as we see fit. Thanks!




Comment at: clang/lib/Sema/SemaExpr.cpp:14010
+  << Bop->getSourceRange() << OpLoc;
+  SuggestParentheses(Self, Bop->getOperatorLoc(),
+ Self.PDiag(diag::note_precedence_silence)

lebedev.ri wrote:
> Should we also suggest the fix to rewrite into what user likely intended?
> `(x op1 y) && (y op2 z)`
I'll work on this, post in a next update. Thank you!



Comment at: clang/test/Sema/warn-compare-op-parentheses.c:1
+// RUN: %clang_cc1 -fsyntax-only -Wcompare-op-parentheses -verify %s
+

Quuxplusone wrote:
> These are some great test cases, but I think they would benefit from being 
> exhaustive.
> 
> ```
> int tests(int p1, int p2, int p3) {
> bool b;
> b = (p1 < p2 < p3);  // expected-warning{{comparisons like 'x interpreted}} expected-note{{place parentheses}}
> b = (p1 < p2 <= p3);  // expected-warning{{comparisons like 'x interpreted}} expected-note{{place parentheses}}
> b = (p1 < p2 > p3);  // expected-warning{{comparisons like 'x interpreted}} expected-note{{place parentheses}}
> b = (p1 < p2 >= p3);  // expected-warning{{comparisons like 'x interpreted}} expected-note{{place parentheses}}
> b = (p1 <= p2 < p3);  // expected-warning{{comparisons like 'x interpreted}} expected-note{{place parentheses}}
> b = (p1 <= p2 <= p3);  // expected-warning{{comparisons like 'x interpreted}} expected-note{{place parentheses}}
> ```
> 
> etc. etc.
> I don't see any downside to being systematic here.
I'll address in a future update. Thank you!



Comment at: clang/test/Sema/warn-compare-op-parentheses.c:129
+  return 0;
+}

Quuxplusone wrote:
> I would like to see explicit (and preferably exhaustive or at least 
> systematic) test cases for the "no warning intended" case:
> 
> if ((p1 < p2) < p3)
> if (p1 < (p2 < p3))
> if (0 <= (p1 < p2))  // this should already trigger a 
> constant-comparison-result warning, yes?
> 
> I would like to see explicit (and preferably exhaustive or at least 
> systematic) test cases for mixed relational and equality comparisons:
> 
> if (p1 == p2 < p3)  // maybe intentional, but definitely deserving of a 
> warning
> if (p1 == p2 == p3)  // definitely buggy and deserving of a warning
> if (p1 != p2 != p3)  // definitely buggy and deserving of a warning
> if (p1 < p2 == p3 < p4)  // maybe intentional, but definitely deserving 
> of a warning
> if (p1 == 

[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added inline comments.



Comment at: clang/test/Misc/warning-wall.c:6
+   
  CHECK -
+   
  NEXT : -Wchar - subscripts CHECK - NEXT : -Wcomment CHECK - NEXT : -Wdelete - 
non - virtual - dtor CHECK - NEXT : -Wdelete - non - abstract - non - virtual - 
dtor CHECK - NEXT : -Wdelete - abstract - non - virtual - dtor CHECK - NEXT : 
-Wformat CHECK - NEXT : -Wformat - extra - args CHECK - NEXT : -Wformat - zero 
- length CHECK - NEXT : -Wnonnull CHECK - NEXT : -Wformat - security CHECK - 
NEXT : -Wformat - y2k CHECK - NEXT : -Wformat - invalid - specifier CHECK - 
NEXT : -Wfor - loop - analysis CHECK - NEXT : -Wframe - address CHECK - NEXT : 
-Wimplicit CHECK - NEXT : -Wimplicit - function - declaration CHECK - NEXT : 
-Wimplicit - int CHECK - NEXT : -Winfinite - recursion CHECK - NEXT : -Wint - 
in - bool - context CHECK - NEXT : -Wmismatched - tags CHECK - NEXT : -Wmissing 
- braces CHECK - NEXT : -Wmove CHECK - NEXT : -Wpessimizing - move CHECK - NEXT 
: -Wredundant - move CHECK - NEXT : -Wreturn - std - move CHECK - NEXT : -Wself 
- move CHECK - NEXT : -Wmultichar CHECK - NEXT : -Wrange - loop - construct 
CHECK - NEXT : -Wreorder CHECK - NEXT : -Wreorder - ctor CHECK - NEXT : 
-Wreorder - init - list CHECK - NEXT : -Wreturn - type CHECK - NEXT : -Wreturn 
- type - c - linkage CHECK - NEXT : -Wself - assign CHECK - NEXT : -Wself - 
assign - overloaded CHECK - NEXT : -Wself - assign - field CHECK - NEXT : 
-Wself - move CHECK - NEXT : -Wsizeof - array - argument CHECK - NEXT : 
-Wsizeof - array - decay CHECK - NEXT : -Wstring - plus - int CHECK - NEXT : 
-Wtautological - compare CHECK - NEXT : -Wtautological - constant - compare 
CHECK - NEXT : -Wtautological - constant - out - of - range - compare CHECK - 
NEXT : -Wtautological - pointer - compare CHECK - NEXT : -Wtautological - 
overlap - compare CHECK - NEXT : -Wtautological - bitwise - compare CHECK - 
NEXT : -Wtautological - undefined - compare CHECK - NEXT : -Wtautological - 
objc - bool - compare CHECK - NEXT : -Wtrigraphs CHECK - NEXT : -Wuninitialized 
CHECK - NEXT : -Wsometimes - uninitialized CHECK - NEXT : -Wstatic - self - 
init CHECK - NEXT : -Wuninitialized - const - reference CHECK - NEXT : 
-Wunknown - pragmas CHECK - NEXT : -Wunused CHECK - NEXT : -Wunused - argument 
CHECK - NEXT : -Wunused - function CHECK - NEXT : -Wunneeded - internal - 
declaration CHECK - NEXT : -Wunused - label CHECK - NEXT : -Wunused - private - 
field CHECK - NEXT : -Wunused - lambda - capture CHECK - NEXT : -Wunused - 
local - typedef CHECK - NEXT : -Wunused - value CHECK - NEXT : -Wunused - 
comparison CHECK - NEXT : -Wunused - result CHECK - NEXT : -Wunevaluated - 
expression CHECK - NEXT : -Wpotentially - evaluated - expression CHECK - NEXT : 
-Wunused - variable CHECK - NEXT : -Wunused - const - variable CHECK - NEXT : 
-Wunused - property - ivar CHECK - NEXT : -Wvolatile - register - var CHECK - 
NEXT : -Wobjc - missing - super - calls CHECK - NEXT : -Wobjc - designated - 
initializers CHECK - NEXT : -Wobjc - flexible - array CHECK - NEXT : 
-Woverloaded - virtual CHECK - NEXT : -Wprivate - extern CHECK - NEXT : -Wcast 
- of - sel - type CHECK - NEXT : -Wextern - c - compat CHECK - NEXT : -Wuser - 
defined - warnings CHECK - NEXT : -Wparentheses CHECK - NEXT : -Wcompare - op - 
parentheses CHECK - NEXT : -Wlogical - op - parentheses CHECK - NEXT : 
-Wlogical - not -parentheses CHECK - NEXT : -Wbitwise - conditional - 
parentheses CHECK - NEXT : -Wbitwise - op - parentheses CHECK - NEXT : -Wshift 
- op - parentheses CHECK - NEXT : -Woverloaded - shift - op - parentheses CHECK 
- NEXT : -Wparentheses - equality CHECK - NEXT : -Wdangling - else CHECK - NEXT 
: -Wswitch CHECK - NEXT : -Wswitch - bool CHECK - NEXT : -Wmisleading - 
indentation
 

oh my, I didn't intend for this to happen. I'll address.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 282475.
vabridgers added a comment.

back out last unwanted changes from clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/warn-compare-op-parentheses.c

Index: clang/test/Sema/warn-compare-op-parentheses.c
===
--- /dev/null
+++ clang/test/Sema/warn-compare-op-parentheses.c
@@ -0,0 +1,129 @@
+// RUN: %clang_cc1 -fsyntax-only -Wcompare-op-parentheses -verify %s
+
+int case1(int p1, int p2, int p3) {
+  if (p1 < p2 < p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+}
+
+int case2(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2 < p3))
+return 1;
+  return 0;
+}
+
+int case3(int p1, int p2, int p3) {
+  // no warning
+  if ((p1 < p2) && (p2))
+return 1;
+  return 0;
+}
+
+int case4(int p1, int p2, int p3) {
+  // no warning
+  if ((p1) && (p3 < p2))
+return 1;
+  return 0;
+}
+
+int case5(int p1, int p2, int p3) {
+  while (p1 < p3 < p2)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+}
+
+int case6(int p1, int p2, int p3) {
+  // should not warn
+  while (p1 && p3 < p2)
+return 1;
+  return 0;
+}
+
+int case7(int p1, int p2, int p3) {
+  // should not warn
+  while ((p1 < p3) < p2)
+return 1;
+  return 0;
+}
+
+int case8(int p1, int p2, int p3) {
+  int ret = p1 < p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  return ret;
+}
+
+int case9(int p1, int p2, int p3) {
+  int ret = (p1 < p2) < p3 < p1;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  return ret;
+}
+
+int case10(int p1, int p2, int p3) {
+  if (p1 <= p2 < p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<=' expression to silence this warning}}
+}
+
+int case11(int p1, int p2, int p3) {
+  if (p1 < p2 <= p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+}
+
+int case12(int p1, int p2, int p3) {
+  if (p1 <= p2 <= p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<=' expression to silence this warning}}
+}
+
+int case13(int p1, int p2, int p3) {
+  if (p1 > p2 < p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>' expression to silence this warning}}
+}
+
+int case14(int p1, int p2, int p3) {
+  if (p1 > p2 > p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>' expression to silence this warning}}
+}
+
+int case15(int p1, int p2, int p3) {
+  if (p1 >= p2 > p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>=' expression to silence this warning}}
+}
+
+int case16(int p1, int p2, int p3) {
+  if (p1 >= p2 >= p3)
+return 1;
+  return 0;
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '>=' expression to silence this warning}}
+}
+
+int case17(int p1, int p2, int p3) {
+  // should not warn
+  if (p1 >= p2 || p3)
+return 1;
+  return 0;
+}
Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -83,6 +83,7 @@
 CHECK-NEXT:-Wextern-c-compat
 CHECK-NEXT:-Wuser-defined-warnings
 CHECK-NEXT:  -Wparentheses
+CHECK-NEXT:-Wcompare-op-parentheses
 CHECK-NEXT:-Wlogical-op-pare

[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:14010
+  << Bop->getSourceRange() << OpLoc;
+  SuggestParentheses(Self, Bop->getOperatorLoc(),
+ Self.PDiag(diag::note_precedence_silence)

vabridgers wrote:
> lebedev.ri wrote:
> > Should we also suggest the fix to rewrite into what user likely intended?
> > `(x op1 y) && (y op2 z)`
> I'll work on this, post in a next update. Thank you!
Hi @lebedev.ri , the warning emits a note that says "place parentheses around 
the '' expression to silence this warning" (see the test cases below). Is 
this sufficient, or are you looking for something else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 282484.
vabridgers added a comment.

refactor test cases per comment from Arthur


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/warn-compare-op-parentheses.c

Index: clang/test/Sema/warn-compare-op-parentheses.c
===
--- /dev/null
+++ clang/test/Sema/warn-compare-op-parentheses.c
@@ -0,0 +1,179 @@
+// RUN: %clang_cc1 -fsyntax-only -Wcompare-op-parentheses -verify %s
+
+int tests(int p1, int p2, int p3, int p4, int p5, int p6) {
+  int b = 0;
+  b = p1 < p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  b = p1 < p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  b = p1 <= p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+  b = p1 <= p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+  
+  b = p1 > p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 > p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 >= p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+  b = p1 >= p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+  
+  b = p1 > p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 < p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  
+  b = p1 > p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 < p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  
+  b = p1 >= p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+  b = p1 <= p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+  
+  b = p1 >= p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+  b = p1 <= p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+ 
+  b = p1 < p2 < p3 < p4;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+  b = (p1 < p2) < p3 < p4;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  b = p1 < (p2 < p3) < p4;

[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-02 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I believe I've addressed all comments so far. Looks like Arthur suggested some 
particular cases that are not currently covered, and are not covered by this 
change since I think addressing those issues are our of scope of my original 
intent. If this patch is otherwise acceptable, would the reviewers be ok 
accepting this patch on the condition of creating a bugzilla report to track 
those issues?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

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


[PATCH] D85157: [Sema] Add casting check for integer to fixed point conversions

2020-08-03 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
vabridgers requested review of this revision.

This change squelches the warning for a cast from integer to fixed point
conversions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85157

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/warn-bad-function-cast.c


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-DFIXED_POINT -ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -43,5 +44,9 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to 
non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 
'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of 
type 'int *' to non-matching type 'long'}} */
+
+#ifdef FIXED_POINT
+  (void)(_Fract) if1(); // no warning
+#endif
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isIntegerType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -DFIXED_POINT -ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -43,5 +44,9 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */
+
+#ifdef FIXED_POINT
+  (void)(_Fract) if1(); // no warning
+#endif
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isIntegerType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85157: [Sema] Add casting check for integer to fixed point conversions

2020-08-03 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 282775.
vabridgers added a comment.

improve the commit message detail


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85157

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/warn-bad-function-cast.c


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-DFIXED_POINT -ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -43,5 +43,7 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to 
non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 
'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of 
type 'int *' to non-matching type 'long'}} */
+
+  (void)(_Fract) if1(); // no warning
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isIntegerType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -DFIXED_POINT -ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -43,5 +43,7 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */
+
+  (void)(_Fract) if1(); // no warning
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isIntegerType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85157: [Sema] Add casting check for integer to fixed point conversions

2020-08-03 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked 5 inline comments as done.
vabridgers added a comment.

I updated the commit header with more details since the first submission was 
obviously too terse. @bjope, I believe the update should address your comments.




Comment at: clang/lib/Sema/SemaCast.cpp:2660
 return;
+  if (SrcType->isIntegerType() && DestType->isFixedPointType())
+return;

bjope wrote:
> Is this really the intention with the patch?
> 
> It does match the "summary" above, but isn't the warning well deserved for 
> int->fixed cast.
> 
> I also base that question on the you referred to this patch from our 
> bugtracker at Ericsson, which was about conversions from `long __fixed` to 
> `long __fixed`. So I kind of expected to find `(SrcType->isFixedPointType() 
> && DestType->isFixedPointType())` here (similar to the checks above that 
> avoids warning when SrcType equals the DestType).
> 
> The test case I expected (related to our downstream bug report) would look 
> like this:
> 
> ```
> _Fract ff1(void);
> 
> void
> foo(void)
> {
>   (_Fract)ff1();  // No warning expected.
> }
> ```
> 
I improve the commit message detail. Please read and let me know if the intent 
is still not clear. 



Comment at: clang/test/Sema/warn-bad-function-cast.c:2
 // RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-DFIXED_POINT -ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192

bjope wrote:
> I doubt it is worth running the whole test twice just to test both with and 
> without `-ffixed-point`, specially since there are no differences in the 
> earlier tests when enabling `-ffixed-point`. So just adding `-ffixed-point` 
> to the pre-existing RUN-line would save us from running this test case a 
> humongous number of extra times during the next decade.
Well, I had a few choices, seems I picked the red pill compared to what you 
want :)   Look at the change, see if you're happy with that. Of course, the 
owner will need to agree.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85157

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


[PATCH] D85157: [Sema] Add casting check for integer to fixed point conversions

2020-08-03 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 282776.
vabridgers marked 2 inline comments as done.
vabridgers added a comment.

remove -DFIXED_POINT from lit test, since it's not needed in this casting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85157

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/warn-bad-function-cast.c


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -43,5 +43,7 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to 
non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 
'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of 
type 'int *' to non-matching type 'long'}} */
+
+  (void)(_Fract) if1(); // no warning
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isIntegerType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -43,5 +43,7 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */
+
+  (void)(_Fract) if1(); // no warning
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isIntegerType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85157: [Sema] Add casting check for integer to fixed point conversions

2020-08-03 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added inline comments.



Comment at: clang/test/Sema/warn-bad-function-cast.c:49
+#ifdef FIXED_POINT
+  (void)(_Fract) if1(); // no warning
+#endif

bjope wrote:
> bjope wrote:
> > bjope wrote:
> > > This should be added before the line saying `/* All following casts issue 
> > > warning */`.
> > Is the `(void)` needed/relevant here?
> As questioned earlier, shouldn't we expect a warning for this scenario?
> 
> There is however a problem that we get the warning for _Fract to _Fract 
> conversion. And it would be nice with a more complete set of tests involving 
> both FixedPoint->FixedPoint, FixedPoint->Integer and Integer->FixedPoint 
> casts.
If you have any *specific* suggestions for test cases, I'm open to that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85157

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-04 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 282852.
vabridgers added a comment.

isRelationalOp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/warn-compare-op-parentheses.c

Index: clang/test/Sema/warn-compare-op-parentheses.c
===
--- /dev/null
+++ clang/test/Sema/warn-compare-op-parentheses.c
@@ -0,0 +1,176 @@
+// RUN: %clang_cc1 -fsyntax-only -Wcompare-op-parentheses -verify %s
+
+int tests(int p1, int p2, int p3, int p4, int p5, int p6) {
+  int b = 0;
+  b = p1 < p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  b = p1 < p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  b = p1 <= p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+  b = p1 <= p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+
+  b = p1 > p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 > p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 >= p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+  b = p1 >= p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+
+  b = p1 > p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+
+  b = p1 > p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 < p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+
+  b = p1 >= p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+  b = p1 <= p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+
+  b = p1 >= p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+  b = p1 <= p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+
+  b = p1 < p2 < p3 < p4;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+  b = (p1 < p2) < p3 < p4;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  b = p1 < (p2 < p3) < p4;
+  // expected-warning@-1 {{comparisons like '

[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-04 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 282854.
vabridgers added a comment.

fix misc test formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/warn-compare-op-parentheses.c

Index: clang/test/Sema/warn-compare-op-parentheses.c
===
--- /dev/null
+++ clang/test/Sema/warn-compare-op-parentheses.c
@@ -0,0 +1,176 @@
+// RUN: %clang_cc1 -fsyntax-only -Wcompare-op-parentheses -verify %s
+
+int tests(int p1, int p2, int p3, int p4, int p5, int p6) {
+  int b = 0;
+  b = p1 < p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  b = p1 < p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  b = p1 <= p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+  b = p1 <= p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+
+  b = p1 > p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 > p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 >= p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+  b = p1 >= p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+
+  b = p1 > p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+
+  b = p1 > p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  b = p1 < p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+
+  b = p1 >= p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+  b = p1 <= p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+
+  b = p1 >= p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' expression to silence this warning}}
+  b = p1 <= p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' expression to silence this warning}}
+
+  b = p1 < p2 < p3 < p4;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  // expected-warning@-3 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-4 {{place parentheses around the '<' expression to silence this warning}}
+  b = (p1 < p2) < p3 < p4;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  b = p1 < (p2 < p3) < p4;
+  // expected-warning@-1 {{comparis

[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-04 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked 2 inline comments as done.
vabridgers added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:14047
 
+static bool isComparisonOpSamePrecedence(BinaryOperatorKind Opc) {
+  switch (Opc) {

njames93 wrote:
> Quuxplusone wrote:
> > Same precedence as what?
> > I think this should just be called `isRelationalOperator`, and I would bet 
> > money that such a classifier function already exists somewhere in the 
> > codebase.
> `isRelationalOp` and its a member function of `BinaryOperator` so there is no 
> need to even access the OperatorKind.
Fixed, thanks



Comment at: clang/lib/Sema/SemaExpr.cpp:14047
 
+static bool isComparisonOpSamePrecedence(BinaryOperatorKind Opc) {
+  switch (Opc) {

vabridgers wrote:
> njames93 wrote:
> > Quuxplusone wrote:
> > > Same precedence as what?
> > > I think this should just be called `isRelationalOperator`, and I would 
> > > bet money that such a classifier function already exists somewhere in the 
> > > codebase.
> > `isRelationalOp` and its a member function of `BinaryOperator` so there is 
> > no need to even access the OperatorKind.
> Fixed, thanks
Fixed, thanks



Comment at: clang/lib/Sema/SemaExpr.cpp:14010
+  << Bop->getSourceRange() << OpLoc;
+  SuggestParentheses(Self, Bop->getOperatorLoc(),
+ Self.PDiag(diag::note_precedence_silence)

njames93 wrote:
> Quuxplusone wrote:
> > vabridgers wrote:
> > > vabridgers wrote:
> > > > lebedev.ri wrote:
> > > > > Should we also suggest the fix to rewrite into what user likely 
> > > > > intended?
> > > > > `(x op1 y) && (y op2 z)`
> > > > I'll work on this, post in a next update. Thank you!
> > > Hi @lebedev.ri , the warning emits a note that says "place parentheses 
> > > around the '' expression to silence this warning" (see the test cases 
> > > below). Is this sufficient, or are you looking for something else?
> > https://godbolt.org/z/d1dG1o
> > For the very similar situation `(x & 1 == 0)`, Clang suggests //two 
> > different fixits//, and I believe Roman was suggesting that you should do 
> > the same kind of thing here.
> > ```
> > :3:16: warning: & has lower precedence than ==; == will be 
> > evaluated first [-Wparentheses]
> > int y = (x & 1 == 0);
> >^~~~
> > :3:16: note: place parentheses around the '==' expression to 
> > silence this warning
> > int y = (x & 1 == 0);
> >^
> >  ( )
> > :3:16: note: place parentheses around the & expression to evaluate 
> > it first
> > int y = (x & 1 == 0);
> >^
> >  ()
> > ```
> > For our situation here it would be something like
> > ```
> > :3:16: warning: chained comparisons like 'x<=y<=z' are interpreted 
> > as '(x<=y ? 1 : 0) <= z' [-Wcompare-op-parentheses]
> > int w = (x < y < z);
> >^~~~
> > :3:16: note: place parentheses around the first '<' expression to 
> > silence this warning
> > int w = (x < y < z);
> >  ^
> >  ()
> > :3:16: note: separate the expression into two clauses to give it 
> > the mathematical meaning
> > int y = (x < y < z);
> >^
> >  () && (y)
> > ```
> > Watch out that you don't suggest a wrong fixit for `(0 <= sideeffect() < 
> > 10)`, though. I seem to recall another warning that recently had a lot of 
> > trouble phrasing its fixit in a way that wouldn't invoke UB or change the 
> > behavior of the code in corner cases, but I forget the details.
> Surely you'd just need to check `y` for side effects before creating the 
> fix-it.
Still working on these, thanks



Comment at: clang/lib/Sema/SemaExpr.cpp:14010
+  << Bop->getSourceRange() << OpLoc;
+  SuggestParentheses(Self, Bop->getOperatorLoc(),
+ Self.PDiag(diag::note_precedence_silence)

vabridgers wrote:
> njames93 wrote:
> > Quuxplusone wrote:
> > > vabridgers wrote:
> > > > vabridgers wrote:
> > > > > lebedev.ri wrote:
> > > > > > Should we also suggest the fix to rewrite into what user likely 
> > > > > > intended?
> > > > > > `(x op1 y) && (y op2 z)`
> > > > > I'll work on this, post in a next update. Thank you!
> > > > Hi @lebedev.ri , the warning emits a note that says "place parentheses 
> > > > around the '' expression to silence this warning" (see the test 
> > > > cases below). Is this sufficient, or are you looking for something else?
> > > https://godbolt.org/z/d1dG1o
> > > For the very similar situation `(x & 1 == 0)`, Clang suggests //two 
> > > different fixits//, and I believe Roman was suggesting that you should do 
> > > the same kind of thing here.
> > > ```
> > > :3:16: warning: & has lower precedence than ==; == will be 
> > > evaluated first [-Wparentheses]
> > > int y = (x & 1 == 0);
> > >^~~~
> > > :3:16: note: place parentheses around the '==' expressi

[PATCH] D85157: [Sema] Add casting check for fixed to fixed point conversions

2020-08-04 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 282902.
vabridgers edited the summary of this revision.
vabridgers added a comment.

ok, I think it's all sorted out now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85157

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/warn-bad-function-cast.c


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -12,6 +12,7 @@
 _Bool bf(void);
 char *pf1(void);
 int *pf2(void);
+_Fract ff1(void);
 
 void
 foo(void)
@@ -43,5 +44,10 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to 
non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 
'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of 
type 'int *' to non-matching type 'long'}} */
+
+  (_Fract) if1(); /* expected-warning{{cast from function call of type 'int' 
to non-matching type '_Fract'}} */
+  ff1();  /* no warning */ 
+  (_Fract)ff1();  /* no warning */ 
+  (int)ff1();  /* expected-warning{{cast from function call of type '_Fract' 
to non-matching type 'int'}} */ 
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isFixedPointType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -12,6 +12,7 @@
 _Bool bf(void);
 char *pf1(void);
 int *pf2(void);
+_Fract ff1(void);
 
 void
 foo(void)
@@ -43,5 +44,10 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */
+
+  (_Fract) if1(); /* expected-warning{{cast from function call of type 'int' to non-matching type '_Fract'}} */
+  ff1();  /* no warning */ 
+  (_Fract)ff1();  /* no warning */ 
+  (int)ff1();  /* expected-warning{{cast from function call of type '_Fract' to non-matching type 'int'}} */ 
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isFixedPointType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85157: [Sema] Add casting check for fixed to fixed point conversions

2020-08-04 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a subscriber: bevinh.
vabridgers added a comment.

ok, I think it's all sorted out now. Thanks @bevinh for the desk review. Let's 
start at the beginning again :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85157

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-05 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 283447.
vabridgers added a comment.

added prototype fixits for review.
added additional RUN test case.
filed https://bugs.llvm.org/show_bug.cgi?id=47010 for other 
warnings improvement post landing of this patch, after lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/warn-compare-op-parentheses.c

Index: clang/test/Sema/warn-compare-op-parentheses.c
===
--- /dev/null
+++ clang/test/Sema/warn-compare-op-parentheses.c
@@ -0,0 +1,245 @@
+// RUN: %clang_cc1 -fsyntax-only -Wcompare-op-parentheses -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wparentheses -verify %s
+
+int tests(int p1, int p2, int p3, int p4, int p5, int p6) {
+  int b = 0;
+  b = p1 < p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '<' comparison to silence this warning}}
+  // expected-note@-4 {{seperate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 < p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '<=' comparison to silence this warning}}
+  // expected-note@-4 {{seperate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 <= p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '<=' comparison to silence this warning}}
+  // expected-note@-4 {{seperate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 <= p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '<' comparison to silence this warning}}
+  // expected-note@-4 {{seperate the expression into two clauses to give it the intended mathematical meaning}}
+
+  b = p1 > p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '>' comparison to silence this warning}}
+  // expected-note@-4 {{seperate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 > p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '>=' comparison to silence this warning}}
+  // expected-note@-4 {{seperate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 >= p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '>=' comparison to silence this warning}}
+  // expected-note@-4 {{seperate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 >= p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '>' comparison to silence this warning}}
+  // expected-note@-4 {{seperate the expression into two clauses to give it the intended mathematical meaning}}
+
+  b = p1 > p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '<' comparison to silence this warning}}
+  // expected-note@-4 {{seperate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}

[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-05 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I added prototype fixits per request by Roman, updated the LIT test, and added 
an additional RUN line (one for -Wparentheses and one for 
-Wcompare-op-parentheses). Also filed 
https://bugs.llvm.org/show_bug.cgi?id=47010 to follow up on the FIXME cases at 
the bottom of the LIT since they are out of scope for this change. Thanks for 
the feedback and comments so far, I look forward to driving this change to 
completion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-06 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:14034
+  << FixItHint::CreateInsertion(LHSExpr->getEndLoc(), ") && ")
+  << FixItHint::CreateInsertion(LHSBO->getRHS()->getBeginLoc(), "(y ")
+  << FixItHint::CreateInsertion(RHSExpr->getEndLoc(), ")");

njames93 wrote:
> You don't want to insert `y` but the source code for `y`
Gotcha, I'll address.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

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


[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-06 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 283780.
vabridgers added a comment.

use source from expression in fixit
s/seperate/separate/
address some chained comparison ambiguities outside of original scope of changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/warn-compare-op-parentheses.c

Index: clang/test/Sema/warn-compare-op-parentheses.c
===
--- /dev/null
+++ clang/test/Sema/warn-compare-op-parentheses.c
@@ -0,0 +1,263 @@
+// RUN: %clang_cc1 -fsyntax-only -Wcompare-op-parentheses -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wparentheses -verify %s
+
+int tests(int p1, int p2, int p3, int p4, int p5, int p6) {
+  int b = 0;
+  b = p1 < p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '<' comparison to silence this warning}}
+  // expected-note@-4 {{separate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 < p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '<=' comparison to silence this warning}}
+  // expected-note@-4 {{separate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 <= p2 <= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '<=' comparison to silence this warning}}
+  // expected-note@-4 {{separate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 <= p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '<=' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '<' comparison to silence this warning}}
+  // expected-note@-4 {{separate the expression into two clauses to give it the intended mathematical meaning}}
+
+  b = p1 > p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '>' comparison to silence this warning}}
+  // expected-note@-4 {{separate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 > p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '>=' comparison to silence this warning}}
+  // expected-note@-4 {{separate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 >= p2 >= p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '>=' comparison to silence this warning}}
+  // expected-note@-4 {{separate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 >= p2 > p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>=' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '>' comparison to silence this warning}}
+  // expected-note@-4 {{separate the expression into two clauses to give it the intended mathematical meaning}}
+
+  b = p1 > p2 < p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses around the '>' comparison to silence this warning}}
+  // expected-note@-3 {{place parentheses around the '<' comparison to silence this warning}}
+  // expected-note@-4 {{separate the expression into two clauses to give it the intended mathematical meaning}}
+  b = p1 p3;
+  // expected-warning@-1 {{comparisons like 'x<=y<=z' are interpreted as '(x<=y ? 1 : 0) <= z'}}
+  // expected-note@-2 {{place parentheses aroun

[PATCH] D85097: [Sema] add warning for comparisons like 'x<=y<=z'

2020-08-06 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thanks for the recent comments. I just pushed a few improvements over the last 
patch that didn't comprehend latest comments from @rsmith and @Quuxplusone. 
I'll read through those carefully and address those.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85097

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


[PATCH] D85157: [Sema] Add casting check for fixed to fixed point conversions

2020-08-06 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Ping! Ok to land?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85157

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


[PATCH] D85157: [Sema] Add casting check for fixed to fixed point conversions

2020-08-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 283858.
vabridgers added a comment.

address Bjorn's comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85157

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/warn-bad-function-cast.c


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -12,15 +12,20 @@
 _Bool bf(void);
 char *pf1(void);
 int *pf2(void);
+_Fract ff1(void);
 
 void
 foo(void)
 {
+
+  /* default, no cast, should always be ok */ 
+  ff1();
   /* Casts to void types are always OK.  */
   (void)vf();
   (void)if1();
   (void)cf();
   (const void)bf();
+  (void)ff1();
   /* Casts to the same type or similar types are OK.  */
   (int)if1();
   (long)if2();
@@ -32,6 +37,7 @@
   (_Bool)bf();
   (void *)pf1();
   (char *)pf2();
+  (_Fract) ff1();
   /* All following casts issue warning */
   (float)if1(); /* expected-warning {{cast from function call of type 'int' to 
non-matching type 'float'}} */
   (double)if2(); /* expected-warning {{cast from function call of type 'char' 
to non-matching type 'double'}} */
@@ -43,5 +49,7 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to 
non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 
'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of 
type 'int *' to non-matching type 'long'}} */
+  (_Fract) if1(); /* expected-warning{{cast from function call of type 'int' 
to non-matching type '_Fract'}} */
+  (int)ff1(); /* expected-warning{{cast from function call of type 
'_Fract' to non-matching type 'int'}} */
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isFixedPointType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -12,15 +12,20 @@
 _Bool bf(void);
 char *pf1(void);
 int *pf2(void);
+_Fract ff1(void);
 
 void
 foo(void)
 {
+
+  /* default, no cast, should always be ok */ 
+  ff1();
   /* Casts to void types are always OK.  */
   (void)vf();
   (void)if1();
   (void)cf();
   (const void)bf();
+  (void)ff1();
   /* Casts to the same type or similar types are OK.  */
   (int)if1();
   (long)if2();
@@ -32,6 +37,7 @@
   (_Bool)bf();
   (void *)pf1();
   (char *)pf2();
+  (_Fract) ff1();
   /* All following casts issue warning */
   (float)if1(); /* expected-warning {{cast from function call of type 'int' to non-matching type 'float'}} */
   (double)if2(); /* expected-warning {{cast from function call of type 'char' to non-matching type 'double'}} */
@@ -43,5 +49,7 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */
+  (_Fract) if1(); /* expected-warning{{cast from function call of type 'int' to non-matching type '_Fract'}} */
+  (int)ff1(); /* expected-warning{{cast from function call of type '_Fract' to non-matching type 'int'}} */
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isFixedPointType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)
__

[PATCH] D85157: [Sema] Add casting check for fixed to fixed point conversions

2020-08-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked an inline comment as done.
vabridgers added inline comments.



Comment at: clang/test/Sema/warn-bad-function-cast.c:49
+#ifdef FIXED_POINT
+  (void)(_Fract) if1(); // no warning
+#endif

bjope wrote:
> bjope wrote:
> > vabridgers wrote:
> > > bjope wrote:
> > > > bjope wrote:
> > > > > bjope wrote:
> > > > > > This should be added before the line saying `/* All following casts 
> > > > > > issue warning */`.
> > > > > Is the `(void)` needed/relevant here?
> > > > As questioned earlier, shouldn't we expect a warning for this scenario?
> > > > 
> > > > There is however a problem that we get the warning for _Fract to _Fract 
> > > > conversion. And it would be nice with a more complete set of tests 
> > > > involving both FixedPoint->FixedPoint, FixedPoint->Integer and 
> > > > Integer->FixedPoint casts.
> > > If you have any *specific* suggestions for test cases, I'm open to that.
> > Add:
> > 
> > ```
> > _Fract ff1(void);
> > ```
> > 
> > And inside foo add these three tests (you'll need to add appropriate 
> > expects):
> > ```
> > (_Fract)ff1();  // No warning expected.
> > (_Fract)if1();  // Warning expected.
> > (int)ff1();  // Warning expected.
> > ```
> I still think it would be nice not to break the structure of this test. Tests 
> seem to be divided into three categories:
> 
> /* Casts to void types are always OK.  */
> 
>   /* Casts to the same type or similar types are OK.  */
> 
> /* All following casts issue warning */
> 
> And you have currently inserted all new tests in the last section.
> 
When I've seen bew



Comment at: clang/test/Sema/warn-bad-function-cast.c:49
+#ifdef FIXED_POINT
+  (void)(_Fract) if1(); // no warning
+#endif

vabridgers wrote:
> bjope wrote:
> > bjope wrote:
> > > vabridgers wrote:
> > > > bjope wrote:
> > > > > bjope wrote:
> > > > > > bjope wrote:
> > > > > > > This should be added before the line saying `/* All following 
> > > > > > > casts issue warning */`.
> > > > > > Is the `(void)` needed/relevant here?
> > > > > As questioned earlier, shouldn't we expect a warning for this 
> > > > > scenario?
> > > > > 
> > > > > There is however a problem that we get the warning for _Fract to 
> > > > > _Fract conversion. And it would be nice with a more complete set of 
> > > > > tests involving both FixedPoint->FixedPoint, FixedPoint->Integer and 
> > > > > Integer->FixedPoint casts.
> > > > If you have any *specific* suggestions for test cases, I'm open to that.
> > > Add:
> > > 
> > > ```
> > > _Fract ff1(void);
> > > ```
> > > 
> > > And inside foo add these three tests (you'll need to add appropriate 
> > > expects):
> > > ```
> > > (_Fract)ff1();  // No warning expected.
> > > (_Fract)if1();  // Warning expected.
> > > (int)ff1();  // Warning expected.
> > > ```
> > I still think it would be nice not to break the structure of this test. 
> > Tests seem to be divided into three categories:
> > 
> > /* Casts to void types are always OK.  */
> > 
> >   /* Casts to the same type or similar types are OK.  */
> > 
> > /* All following casts issue warning */
> > 
> > And you have currently inserted all new tests in the last section.
> > 
> When I've seen bew
Done. ok to land?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85157

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


[PATCH] D85157: [Sema] Add casting check for fixed to fixed point conversions

2020-08-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked 4 inline comments as done.
vabridgers added a comment.

All comments marked as done. ok to land?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85157

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


[PATCH] D129269: [analyzer] Fix use of length in CStringChecker

2022-07-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: martong, steakhal.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

CStringChecker is using getByteLength to get the length of a string
literal. For targets where a "char" is 8-bits, getByteLength() and
getLength() will be equal for a C string, but for targets where a "char"
is 16-bits getByteLength() returns the size in octets.

This is verified in our downstream target, but we have no way to add a
test case for this case since there is no target supporting 16-bit
"char" upstream. Since this cannot have a test case, I'm asserted this
change is "correct by construction", and visually inspected to be
correct by way of the following example where this was found.

The case that shows this fails using a target with 16-bit chars is here.
getByteLength() for the string literal returns 4, which fails when
checked against "char x[4]". With the change, the string literal is
evaluated to a size of 2 which is a correct number of "char"'s for a
16-bit target.

void strcpy_no_overflow_2(char *y) {

  char x[4];
  strcpy(x, "12"); // with getByteLength(), returns 4 using 16-bit chars

}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129269

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


Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,7 @@
 SValBuilder &svalBuilder = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+return svalBuilder.makeIntVal(strLit->getLength(), sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:


Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,7 @@
 SValBuilder &svalBuilder = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+return svalBuilder.makeIntVal(strLit->getLength(), sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129269: [analyzer] Fix use of length in CStringChecker

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

Thanks Balazs, you mean something like this correct?

void strcpy_no_overflow_2(char *y) {

  char x[3];
  strcpy(x, "12\0"); // this produces a warning, but should not. 

}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129269

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


[PATCH] D129269: [analyzer] Fix use of length in CStringChecker

2022-07-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 443101.
vabridgers added a comment.

a proposal to handle embedded null case caught by @steakhal


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129269

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/string.c


Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -1652,3 +1652,8 @@
   __builtin___memset_chk(&x, 0, sizeof(x), __builtin_object_size(&x, 0));
   clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
 }
+
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  strcpy(x, "12\0");
+}
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,15 @@
 SValBuilder &svalBuilder = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+unsigned countx = 0;
+// get the number of string literal characters by the target's "code unit"
+// size, checking for an embedded literal of 0 up to the string literal's
+// length.
+for (countx = 0;
+ countx < strLit->getLength() && (strLit->getCodeUnit(countx) != 0);
+ countx++)
+  ;
+return svalBuilder.makeIntVal(countx, sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:


Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -1652,3 +1652,8 @@
   __builtin___memset_chk(&x, 0, sizeof(x), __builtin_object_size(&x, 0));
   clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
 }
+
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  strcpy(x, "12\0");
+}
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,15 @@
 SValBuilder &svalBuilder = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+unsigned countx = 0;
+// get the number of string literal characters by the target's "code unit"
+// size, checking for an embedded literal of 0 up to the string literal's
+// length.
+for (countx = 0;
+ countx < strLit->getLength() && (strLit->getCodeUnit(countx) != 0);
+ countx++)
+  ;
+return svalBuilder.makeIntVal(countx, sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122513: [analyzer] Fix "RhsLoc and LhsLoc bitwidth must be same"

2022-03-25 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: NoQ, steakhal, martong.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

clang: /clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:727:
void assertEqualBitWidths(clang::ento::ProgramStateRef,

  clang::ento::Loc, clang::ento::Loc): Assertion `RhsBitwidth ==
  LhsBitwidth && "RhsLoc and LhsLoc bitwidth must be same!"'

This change adjusts the bitwidth of the smaller operand for an evalBinOp
as a result of a comparison operation. This can occur in the specific
case represented by the test cases for a target with different pointer
sizes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122513

Files:
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/addrspace-null.c


Index: clang/test/Analysis/addrspace-null.c
===
--- /dev/null
+++ clang/test/Analysis/addrspace-null.c
@@ -0,0 +1,47 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DAMDGCN_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+//
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DDEFAULT_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+
+// expected-no-diagnostics
+
+#define DEVICE __attribute__((address_space(3)))
+
+#if defined(AMDGCN)
+// this crashes
+int fn1() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (void *)0;
+}
+
+// does not crash
+int fn2() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+
+// this crashes
+int fn3() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+#endif
+
+// does not crash
+int fn4() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (void *)0;
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -792,8 +792,27 @@
 
 // If both operands are constants, just perform the operation.
 if (Optional rInt = rhs.getAs()) {
-  SVal ResultVal =
-  lhs.castAs().evalBinOp(BasicVals, op, *rInt);
+  // Need a big enough type to compare both values.
+  //
+  // In the case of something like this for targets with different
+  // pointer sizes based on address space, need to find the largest
+  // bitwidth to use for the evalBinOp
+  //
+  // int fn1() {
+  //   int val = 0;
+  //   __attribute__((address_space(3))) int *dptr = val;
+  //   return dptr == (void *)0;
+  // }
+  llvm::APSInt LHSValue = lhs.castAs().getValue();
+  llvm::APSInt RHSValue = rhs.castAs().getValue();
+  APSIntType OpType = std::max(APSIntType(LHSValue), APSIntType(RHSValue));
+
+  OpType.apply(LHSValue);
+  OpType.apply(RHSValue);
+  loc::ConcreteInt ciLHS = loc::ConcreteInt(LHSValue);
+  loc::ConcreteInt ciRHS = loc::ConcreteInt(RHSValue);
+  SVal ResultVal = ciLHS.evalBinOp(BasicVals, op, ciRHS);
+
   if (Optional Result = ResultVal.getAs())
 return evalCast(*Result, resultTy, QualType{});
 


Index: clang/test/Analysis/addrspace-null.c
===
--- /dev/null
+++ clang/test/Analysis/addrspace-null.c
@@ -0,0 +1,47 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DAMDGCN_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+//
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DDEFAULT_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+
+// expected-no-diagnostics
+
+#define DEVICE __attribute__((address_space(3)))
+
+#if defined(AMDGCN)
+// this crashes
+int fn1() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (void *)0;
+}
+
+// does not crash
+int fn2() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+
+// this crashes
+int fn3

[PATCH] D122513: [analyzer] Fix "RhsLoc and LhsLoc bitwidth must be same"

2022-03-26 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Hi @NoQ, good question :) When I looked into the existing SimpleSValBuilder.cpp 
code, I found a few places that did width modifications so I concluded this was 
the correct and accepted way to handle this. A few notes to help decide if my 
suggestion is correct or is there's a different concrete way to move forward. 
Looks like we get address space information in the AST, and it's up to the AST 
client to do the needful (whatever that is). We do get warnings and/or errors 
in some cases, but it seems this is a case where it's implied that the "void *" 
cast is same address space as the LHS of the comparison. I'll check the 
Embedded C Spec to see what it says about this.

The Sample function looks like this:

  int fn1() {
int val = 0;
__attribute__((address_space(3))) int *dptr = val;
return dptr == (void *)0;
  }

The AST for the return statement "return dptr == (void *)0;" looks like this:

  `-ReturnStmt 0x118f2078 
`-BinaryOperator 0x118f2058  'int' '=='
  |-ImplicitCastExpr 0x118f2028  '__attribute__((address_space(3))) 
int *' 
  | `-DeclRefExpr 0x118f1fa8  '__attribute__((address_space(3))) 
int *' lvalue Var 0x118f1af0 'dptr' '__attribute__((address_space(3))) int *'
  `-ImplicitCastExpr 0x118f2040  
'__attribute__((address_space(3))) int *' 
`-CStyleCastExpr 0x118f2000  'void *' 
  `-IntegerLiteral 0x118f1fc8  'int' 0


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122513

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


[PATCH] D122513: [analyzer] Fix "RhsLoc and LhsLoc bitwidth must be same"

2022-03-26 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Apparently, it's up to an implementation to determine the specific relations 
that can be computed between different address spaces. Perhaps a better way to 
deal with this for now, to avoid crashes, is follow the DereferenceChecker 
model. That checker punts on checking relations with any pointers that have a 
address space. If a downstream compiler wants to compute relations between 
pointers with address spaces, they are certainly free to do that - but I get 
the instinct this might not be best to push upstream :/

Ideas? Best!

Here's the snippet, and comment, from 
clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp

  ...
  112 static bool suppressReport(const Expr *E) {
  113   // Do not report dereferences on memory in non-default address spaces.
  114   return E->getType().hasAddressSpace();
  115 }
  ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122513

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


[PATCH] D122513: [analyzer] Fix "RhsLoc and LhsLoc bitwidth must be same"

2022-03-28 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Ahhh, gotcha. I'll run that down and report back. Thanks !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122513

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


[PATCH] D122513: [analyzer] Fix "RhsLoc and LhsLoc bitwidth must be same"

2022-03-28 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I think I got it, looks like we're losing the width information at line 685, 
686 below.

Looks like I need to adjust the bitwidth of V before returning.

clang/lib/StaticAnalyzer/Core/SValBuilder.cpp

  671 SVal SValBuilder::evalCastSubKind(loc::ConcreteInt V, QualType CastTy,
  672   QualType OriginalTy) {
  673   // Pointer to bool.
  674   if (CastTy->isBooleanType())
  675 return makeTruthVal(V.getValue().getBoolValue(), CastTy);
  676 
  677   // Pointer to integer.
  678   if (CastTy->isIntegralOrEnumerationType()) {
  679 llvm::APSInt Value = V.getValue();
  680 BasicVals.getAPSIntType(CastTy).apply(Value);
  681 return makeIntVal(Value);
  682   }
  683 
  684   // Pointer to any pointer.
  685   if (Loc::isLocType(CastTy))
  686 return V;
  687 
  688   // Pointer to whatever else.
  689   return UnknownVal();
  690 }



  Breakpoint 8, clang::ento::SValBuilder::evalCastSubKind (this=0xff34500, 
V=..., CastTy=..., OriginalTy=...)
  at  /clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:674
  674 if (CastTy->isBooleanType())
  (gdb) next
  678 if (CastTy->isIntegralOrEnumerationType()) {
  (gdb) 
  685 if (Loc::isLocType(CastTy))
  (gdb) p V
  $25 = { = { = 
{ = { = {Data = 
0xff37cf0, 
Kind = 2}, }, }, }, 
}
  (gdb) p V.dump()
  0 (Loc)$26 = void
  (gdb) p CastTy.dump()
  PointerType 0xfede460 '__attribute__((address_space(3))) int *'
  `-QualType 0xfede418 '__attribute__((address_space(3))) int' 
__attribute__((address_space(3)))
`-BuiltinType 0xfedd640 'int'
  $27 = void


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122513

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


[PATCH] D122513: [analyzer] Fix "RhsLoc and LhsLoc bitwidth must be same"

2022-03-28 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 418749.
vabridgers added a comment.

Come up with a more principaled fix, thanks @NoQ :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122513

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/addrspace-null.c


Index: clang/test/Analysis/addrspace-null.c
===
--- /dev/null
+++ clang/test/Analysis/addrspace-null.c
@@ -0,0 +1,47 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DAMDGCN_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+//
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DDEFAULT_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+
+// expected-no-diagnostics
+
+#define DEVICE __attribute__((address_space(3)))
+
+#if defined(AMDGCN)
+// this crashes
+int fn1() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (void *)0;
+}
+
+// does not crash
+int fn2() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+
+// this crashes
+int fn3() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+#endif
+
+// does not crash
+int fn4() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (void *)0;
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -682,8 +682,11 @@
   }
 
   // Pointer to any pointer.
-  if (Loc::isLocType(CastTy))
-return V;
+  if (Loc::isLocType(CastTy)) {
+llvm::APSInt Value = V.getValue();
+BasicVals.getAPSIntType(CastTy).apply(Value);
+return loc::ConcreteInt(BasicVals.getValue(Value));
+  }
 
   // Pointer to whatever else.
   return UnknownVal();


Index: clang/test/Analysis/addrspace-null.c
===
--- /dev/null
+++ clang/test/Analysis/addrspace-null.c
@@ -0,0 +1,47 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DAMDGCN_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+//
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DDEFAULT_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+
+// expected-no-diagnostics
+
+#define DEVICE __attribute__((address_space(3)))
+
+#if defined(AMDGCN)
+// this crashes
+int fn1() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (void *)0;
+}
+
+// does not crash
+int fn2() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+
+// this crashes
+int fn3() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+#endif
+
+// does not crash
+int fn4() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (void *)0;
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -682,8 +682,11 @@
   }
 
   // Pointer to any pointer.
-  if (Loc::isLocType(CastTy))
-return V;
+  if (Loc::isLocType(CastTy)) {
+llvm::APSInt Value = V.getValue();
+BasicVals.getAPSIntType(CastTy).apply(Value);
+return loc::ConcreteInt(BasicVals.getValue(Value));
+  }
 
   // Pointer to whatever else.
   return UnknownVal();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122513: [analyzer] Fix "RhsLoc and LhsLoc bitwidth must be same"

2022-03-29 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 418996.
vabridgers added a comment.

fix typo in test - ready to land


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122513

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/addrspace-null.c


Index: clang/test/Analysis/addrspace-null.c
===
--- /dev/null
+++ clang/test/Analysis/addrspace-null.c
@@ -0,0 +1,47 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DAMDGCN_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+//
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DDEFAULT_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+
+// expected-no-diagnostics
+
+#define DEVICE __attribute__((address_space(3)))
+
+#if defined(AMDGCN_TRIPLE)
+// this crashes
+int fn1() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (void *)0;
+}
+
+// does not crash
+int fn2() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+
+// this crashes
+int fn3() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+#endif
+
+// does not crash
+int fn4() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (void *)0;
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -682,8 +682,11 @@
   }
 
   // Pointer to any pointer.
-  if (Loc::isLocType(CastTy))
-return V;
+  if (Loc::isLocType(CastTy)) {
+llvm::APSInt Value = V.getValue();
+BasicVals.getAPSIntType(CastTy).apply(Value);
+return loc::ConcreteInt(BasicVals.getValue(Value));
+  }
 
   // Pointer to whatever else.
   return UnknownVal();


Index: clang/test/Analysis/addrspace-null.c
===
--- /dev/null
+++ clang/test/Analysis/addrspace-null.c
@@ -0,0 +1,47 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DAMDGCN_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+//
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DDEFAULT_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+
+// expected-no-diagnostics
+
+#define DEVICE __attribute__((address_space(3)))
+
+#if defined(AMDGCN_TRIPLE)
+// this crashes
+int fn1() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (void *)0;
+}
+
+// does not crash
+int fn2() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+
+// this crashes
+int fn3() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+#endif
+
+// does not crash
+int fn4() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (void *)0;
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -682,8 +682,11 @@
   }
 
   // Pointer to any pointer.
-  if (Loc::isLocType(CastTy))
-return V;
+  if (Loc::isLocType(CastTy)) {
+llvm::APSInt Value = V.getValue();
+BasicVals.getAPSIntType(CastTy).apply(Value);
+return loc::ConcreteInt(BasicVals.getValue(Value));
+  }
 
   // Pointer to whatever else.
   return UnknownVal();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122513: [analyzer] Fix "RhsLoc and LhsLoc bitwidth must be same"

2022-03-29 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked an inline comment as done.
vabridgers added inline comments.



Comment at: clang/test/Analysis/addrspace-null.c:19
+
+#if defined(AMDGCN)
+// this crashes

NoQ wrote:
> Shouldn't this be `AMDGCN_TRIPLE`?
fixed, thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122513

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


[PATCH] D118050: [analyzer] Different address spaces cannot overlap

2022-03-29 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 419013.
vabridgers added a comment.
Herald added a project: All.

rebase, check ci


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118050

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/cstring-addrspace.c

Index: clang/test/Analysis/cstring-addrspace.c
===
--- /dev/null
+++ clang/test/Analysis/cstring-addrspace.c
@@ -0,0 +1,64 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core,alpha.unix.cstring \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -analyzer-config crosscheck-with-z3=true -verify %s \
+// RUN: -Wno-incompatible-library-redeclaration
+// REQUIRES: z3
+
+void clang_analyzer_warnIfReached();
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+#define DEVICE __attribute__((address_space(3)))
+_Static_assert(sizeof(int *) == 8, "");
+_Static_assert(sizeof(DEVICE int *) == 4, "");
+_Static_assert(sizeof(void *) == 8, "");
+_Static_assert(sizeof(DEVICE void *) == 4, "");
+
+// Copy from host to device memory. Note this is specialized
+// since one of the parameters is assigned an address space such
+// that the sizeof the the pointer is different than the other.
+//
+// Some downstream implementations may have specialized memcpy
+// routines that copy from one address space to another. In cases
+// like that, the address spaces are assumed to not overlap, so the
+// cstring overlap check is not needed. When a static analysis report
+// is generated in as case like this, SMTConv may attempt to create
+// a refutation to Z3 with different bitwidth pointers which lead to
+// a crash. This is not common in directly used upstream compiler builds,
+// but can be seen in specialized downstrean implementations. This case
+// covers those specific instances found and debugged.
+//
+// Since memcpy is a builtin, a specialized builtin instance named like
+// 'memcpy_special' will hit in cstring, triggering this behavior. The
+// best we can do for an upstream test is use the same memcpy function name.
+DEVICE void *memcpy(DEVICE void *dst, const void *src, unsigned long len);
+
+void top1(DEVICE void *dst, void *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top2(DEVICE int *dst, void *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top3(DEVICE int *dst, int *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top4() {
+  memcpy((DEVICE void *)1, (const void *)1, 1);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -715,11 +715,35 @@
   llvm_unreachable("Fields not found in parent record's definition");
 }
 
+static bool assertEqualBitWidths(ProgramStateRef State, Loc RhsLoc,
+ Loc LhsLoc) {
+  // Implements a "best effort" check for RhsLoc and LhsLoc bit widths
+  ASTContext &Ctx = State->getStateManager().getContext();
+  uint64_t RhsBitwidth =
+  RhsLoc.getType(Ctx).isNull() ? 0 : Ctx.getTypeSize(RhsLoc.getType(Ctx));
+  uint64_t LhsBitwidth =
+  LhsLoc.getType(Ctx).isNull() ? 0 : Ctx.getTypeSize(LhsLoc.getType(Ctx));
+  if (RhsBitwidth && LhsBitwidth &&
+  (LhsLoc.getSubKind() == RhsLoc.getSubKind())) {
+assert(RhsBitwidth == LhsBitwidth &&
+   "RhsLoc and LhsLoc bitwidth must be same!");
+return RhsBitwidth == LhsBitwidth;
+  }
+  return false;
+}
+
 // FIXME: all this logic will change if/when we have MemRegion::getLocation().
 SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state,
   BinaryOperator::Opcode op,
   Loc lhs, Loc rhs,
   QualType resultTy) {
+
+  // Assert that bitwidth of lhs and rhs are the same.
+  // This can happen if two different address spaces are used,
+  // and the bitwidths of the address spaces are different.
+  // See LIT case clang/test/Analysis/cstring-checker-addressspace.c
+  assertEqualBitWidths(state, rhs, lhs);
+
   // Only comparisons and subtractions are valid o

[PATCH] D118050: [analyzer] Different address spaces cannot overlap

2022-03-31 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 419438.
vabridgers added a comment.

add NDEBUG around assert


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118050

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/cstring-addrspace.c

Index: clang/test/Analysis/cstring-addrspace.c
===
--- /dev/null
+++ clang/test/Analysis/cstring-addrspace.c
@@ -0,0 +1,64 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core,alpha.unix.cstring \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -analyzer-config crosscheck-with-z3=true -verify %s \
+// RUN: -Wno-incompatible-library-redeclaration
+// REQUIRES: z3
+
+void clang_analyzer_warnIfReached();
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+#define DEVICE __attribute__((address_space(3)))
+_Static_assert(sizeof(int *) == 8, "");
+_Static_assert(sizeof(DEVICE int *) == 4, "");
+_Static_assert(sizeof(void *) == 8, "");
+_Static_assert(sizeof(DEVICE void *) == 4, "");
+
+// Copy from host to device memory. Note this is specialized
+// since one of the parameters is assigned an address space such
+// that the sizeof the the pointer is different than the other.
+//
+// Some downstream implementations may have specialized memcpy
+// routines that copy from one address space to another. In cases
+// like that, the address spaces are assumed to not overlap, so the
+// cstring overlap check is not needed. When a static analysis report
+// is generated in as case like this, SMTConv may attempt to create
+// a refutation to Z3 with different bitwidth pointers which lead to
+// a crash. This is not common in directly used upstream compiler builds,
+// but can be seen in specialized downstrean implementations. This case
+// covers those specific instances found and debugged.
+//
+// Since memcpy is a builtin, a specialized builtin instance named like
+// 'memcpy_special' will hit in cstring, triggering this behavior. The
+// best we can do for an upstream test is use the same memcpy function name.
+DEVICE void *memcpy(DEVICE void *dst, const void *src, unsigned long len);
+
+void top1(DEVICE void *dst, void *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top2(DEVICE int *dst, void *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top3(DEVICE int *dst, int *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top4() {
+  memcpy((DEVICE void *)1, (const void *)1, 1);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -715,11 +715,47 @@
   llvm_unreachable("Fields not found in parent record's definition");
 }
 
+#ifndef NDEBUG
+// This is used in debug builds only for now because some downstream users
+// may hit this assert in their subsequent merges.
+// There are still places in the analyzer where equal bitwidth Locs
+// are compared, and need to be found and corrected. Recent previous fixes have
+// addressed the known problems of making NULLs with specific bitwidths
+// for Loc comparisons along with deprecation of APIs for the same purpose.
+//
+static bool assertEqualBitWidths(ProgramStateRef State, Loc RhsLoc,
+ Loc LhsLoc) {
+  // Implements a "best effort" check for RhsLoc and LhsLoc bit widths
+  ASTContext &Ctx = State->getStateManager().getContext();
+  uint64_t RhsBitwidth =
+  RhsLoc.getType(Ctx).isNull() ? 0 : Ctx.getTypeSize(RhsLoc.getType(Ctx));
+  uint64_t LhsBitwidth =
+  LhsLoc.getType(Ctx).isNull() ? 0 : Ctx.getTypeSize(LhsLoc.getType(Ctx));
+  if (RhsBitwidth && LhsBitwidth &&
+  (LhsLoc.getSubKind() == RhsLoc.getSubKind())) {
+assert(RhsBitwidth == LhsBitwidth &&
+   "RhsLoc and LhsLoc bitwidth must be same!");
+return RhsBitwidth == LhsBitwidth;
+  }
+  return false;
+}
+#endif
+
 // FIXME: all this logic will change if/when we have MemRegion::getLocation().
 SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state,
   BinaryOperator::Opcode op,
  

[PATCH] D118050: [analyzer] Different address spaces cannot overlap

2022-03-31 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I added #ifndef NDEBUG around the assert since I'm not sure if downstream 
consumers that use different pointer sizes by address space will hit this 
assert. Our downstream target causes this assert to fire, so I will be 
continuing to find and fix these issues, submitting test cases as I can. Heck, 
we may even have to submit a mock target to properly suss these out :)

Thanks for the support for sorting these out. Best


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118050

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


  1   2   3   >